tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / filter / xml / celltextparacontext.cxx
blob26293e7d8db9e007a2d6895f5bec635af2790616
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "celltextparacontext.hxx"
11 #include "xmlimprt.hxx"
12 #include "xmlcelli.hxx"
14 #include <comphelper/string.hxx>
15 #include <xmloff/xmlnamespace.hxx>
16 #include <xmloff/xmltoken.hxx>
18 using namespace com::sun::star;
19 using namespace xmloff::token;
21 ScXMLCellTextParaContext::ScXMLCellTextParaContext(
22 ScXMLImport& rImport, ScXMLTableRowCellContext& rParent) :
23 ScXMLImportContext(rImport),
24 mrParentCxt(rParent)
28 void SAL_CALL ScXMLCellTextParaContext::endFastElement( sal_Int32 /*nElement*/ )
30 if (!maContent.isEmpty())
31 mrParentCxt.PushParagraphSpan(maContent, OUString());
33 mrParentCxt.PushParagraphEnd();
36 void SAL_CALL ScXMLCellTextParaContext::characters( const OUString& rChars )
38 maContent += rChars;
41 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextParaContext::createFastChildContext(
42 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
44 if (!maContent.isEmpty())
46 mrParentCxt.PushParagraphSpan(maContent, OUString());
47 maContent.clear();
50 switch (nElement)
52 case XML_ELEMENT( TEXT, XML_S ):
53 return new ScXMLCellFieldSContext(GetScImport(), *this);
54 case XML_ELEMENT( TEXT, XML_SPAN ):
55 return new ScXMLCellTextSpanContext(GetScImport(), *this);
56 case XML_ELEMENT( TEXT, XML_SHEET_NAME ):
57 return new ScXMLCellFieldSheetNameContext(GetScImport(), *this);
58 case XML_ELEMENT( TEXT, XML_DATE ):
59 return new ScXMLCellFieldDateContext(GetScImport(), *this);
60 case XML_ELEMENT( TEXT, XML_TITLE ):
61 return new ScXMLCellFieldTitleContext(GetScImport(), *this);
62 case XML_ELEMENT( TEXT, XML_A ):
63 return new ScXMLCellFieldURLContext(GetScImport(), *this);
64 case XML_ELEMENT( TEXT, XML_RUBY ):
65 return new ScXMLCellTextRubyContext(GetScImport(), *this);
66 case XML_ELEMENT(TEXT, XML_TAB):
67 maContent += "\t";
68 break;
69 case XML_ELEMENT(TEXT, XML_LINE_BREAK):
70 maContent += "\x0a";
71 break;
72 case XML_ELEMENT(TEXT, XML_BOOKMARK):
73 case XML_ELEMENT(TEXT, XML_BOOKMARK_START):
74 case XML_ELEMENT(TEXT, XML_BOOKMARK_END):
75 // TODO: ooo95423-1 [file.ods] and tdf#116079-3 have these bookmarks.
76 // Is this valid, and how can we prevent losing these?
77 break;
78 default:
79 SAL_WARN("sc","unknown text element["<<nElement<<"]["<<SvXMLImport::getNameFromToken(nElement )<<"] lost");
82 return nullptr;
85 void ScXMLCellTextParaContext::PushSpan(std::u16string_view aSpan, const OUString& rStyleName)
87 mrParentCxt.PushParagraphSpan(aSpan, rStyleName);
90 void ScXMLCellTextParaContext::PushFieldSheetName(const OUString& rStyleName)
92 mrParentCxt.PushParagraphFieldSheetName(rStyleName);
95 void ScXMLCellTextParaContext::PushFieldDate(const OUString& rStyleName)
97 mrParentCxt.PushParagraphFieldDate(rStyleName);
100 void ScXMLCellTextParaContext::PushFieldTitle(const OUString& rStyleName)
102 mrParentCxt.PushParagraphFieldDocTitle(rStyleName);
105 void ScXMLCellTextParaContext::PushFieldURL(
106 const OUString& rURL, const OUString& rRep, const OUString& rStyleName, const OUString& rTargetFrame)
108 mrParentCxt.PushParagraphFieldURL(rURL, rRep, rStyleName, rTargetFrame);
111 ScXMLCellTextSpanContext::ScXMLCellTextSpanContext(
112 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
113 ScXMLImportContext(rImport),
114 mrParentCxt(rParent)
118 void SAL_CALL ScXMLCellTextSpanContext::startFastElement( sal_Int32 /*nElement*/,
119 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
121 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
123 switch (aIter.getToken())
125 case XML_ELEMENT( TEXT, XML_STYLE_NAME ):
126 maStyleName = aIter.toString();
127 break;
128 default:
134 void SAL_CALL ScXMLCellTextSpanContext::endFastElement( sal_Int32 /*nElement*/ )
136 submitContentAndClear();
139 void SAL_CALL ScXMLCellTextSpanContext::characters( const OUString& rChars )
141 maContent += rChars;
144 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextSpanContext::createFastChildContext(
145 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
147 submitContentAndClear();
149 switch (nElement)
151 case XML_ELEMENT( TEXT, XML_SHEET_NAME ):
153 ScXMLCellFieldSheetNameContext* p = new ScXMLCellFieldSheetNameContext(GetScImport(), mrParentCxt);
154 p->SetStyleName(maStyleName);
155 return p;
157 case XML_ELEMENT( TEXT, XML_DATE ):
159 ScXMLCellFieldDateContext* p = new ScXMLCellFieldDateContext(GetScImport(), mrParentCxt);
160 p->SetStyleName(maStyleName);
161 return p;
163 case XML_ELEMENT( TEXT, XML_TITLE ):
165 ScXMLCellFieldTitleContext* p = new ScXMLCellFieldTitleContext(GetScImport(), mrParentCxt);
166 p->SetStyleName(maStyleName);
167 return p;
169 case XML_ELEMENT( TEXT, XML_A ):
171 ScXMLCellFieldURLContext* p = new ScXMLCellFieldURLContext(GetScImport(), mrParentCxt);
172 p->SetStyleName(maStyleName);
173 return p;
175 case XML_ELEMENT( TEXT, XML_S ):
177 ScXMLCellFieldSContext* p = new ScXMLCellFieldSContext(GetScImport(), mrParentCxt);
178 p->SetStyleName(maStyleName);
179 return p;
181 default:
185 return nullptr;
188 void ScXMLCellTextSpanContext::submitContentAndClear()
190 if (!maContent.isEmpty())
192 mrParentCxt.PushSpan(maContent, maStyleName);
193 maContent.clear();
197 ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext(
198 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
199 ScXMLImportContext(rImport),
200 mrParentCxt(rParent)
204 void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString& rStyleName)
206 maStyleName = rStyleName;
209 void SAL_CALL ScXMLCellFieldSheetNameContext::endFastElement( sal_Int32 /*nElement*/ )
211 mrParentCxt.PushFieldSheetName(maStyleName);
214 ScXMLCellFieldDateContext::ScXMLCellFieldDateContext(
215 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
216 ScXMLImportContext(rImport),
217 mrParentCxt(rParent)
221 void ScXMLCellFieldDateContext::SetStyleName(const OUString& rStyleName)
223 maStyleName = rStyleName;
226 void SAL_CALL ScXMLCellFieldDateContext::endFastElement( sal_Int32 /*nElement*/ )
228 mrParentCxt.PushFieldDate(maStyleName);
231 ScXMLCellFieldTitleContext::ScXMLCellFieldTitleContext(
232 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
233 ScXMLImportContext(rImport),
234 mrParentCxt(rParent)
238 void ScXMLCellFieldTitleContext::SetStyleName(const OUString& rStyleName)
240 maStyleName = rStyleName;
243 void SAL_CALL ScXMLCellFieldTitleContext::endFastElement( sal_Int32 /*nElement*/ )
245 mrParentCxt.PushFieldTitle(maStyleName);
248 ScXMLCellFieldURLContext::ScXMLCellFieldURLContext(
249 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
250 ScXMLImportContext(rImport),
251 mrParentCxt(rParent)
255 void ScXMLCellFieldURLContext::SetStyleName(const OUString& rStyleName)
257 maStyleName = rStyleName;
260 void SAL_CALL ScXMLCellFieldURLContext::startFastElement( sal_Int32 /*nElement*/,
261 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
263 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
265 switch (aIter.getToken())
267 case XML_ELEMENT( XLINK, XML_HREF ):
268 maURL = aIter.toString();
269 break;
270 case XML_ELEMENT( XLINK, XML_TYPE ):
271 // Ignored for now.
272 break;
273 case XML_ELEMENT( OFFICE, XML_TARGET_FRAME_NAME ):
274 maTargetFrame = aIter.toString();
275 break;
276 default:
282 void SAL_CALL ScXMLCellFieldURLContext::endFastElement( sal_Int32 /*nElement*/ )
284 mrParentCxt.PushFieldURL(maURL, maRep, maStyleName, maTargetFrame);
287 void SAL_CALL ScXMLCellFieldURLContext::characters( const OUString& rChars )
289 maRep += rChars;
292 ScXMLCellFieldSContext::ScXMLCellFieldSContext(
293 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
294 ScXMLImportContext(rImport),
295 mrParentCxt(rParent),
296 mnCount(1)
300 void ScXMLCellFieldSContext::SetStyleName(const OUString& rStyleName)
302 maStyleName = rStyleName;
305 void SAL_CALL ScXMLCellFieldSContext::startFastElement( sal_Int32 /*nElement*/,
306 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
308 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
310 switch (aIter.getToken())
312 case XML_ELEMENT( TEXT, XML_C ):
313 mnCount = aIter.toInt32();
314 if (mnCount <= 0)
315 mnCount = 1; // worth a warning?
316 break;
317 default:
323 void SAL_CALL ScXMLCellFieldSContext::endFastElement( sal_Int32 /*nElement*/ )
325 if (mnCount)
326 PushSpaces();
329 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellFieldSContext::createFastChildContext(
330 sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
332 // <text:s> does not have child elements, but ...
333 if (mnCount)
335 PushSpaces();
336 mnCount = 0;
339 return nullptr;
342 void ScXMLCellFieldSContext::PushSpaces()
344 if (mnCount > 0)
346 if (mnCount == 1)
347 mrParentCxt.PushSpan(u" ", maStyleName);
348 else
350 OUStringBuffer aBuf( mnCount);
351 comphelper::string::padToLength( aBuf, mnCount, ' ');
352 mrParentCxt.PushSpan( aBuf.makeStringAndClear(), maStyleName);
357 ScXMLCellTextRubyContext::ScXMLCellTextRubyContext(
358 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
359 ScXMLImportContext(rImport),
360 mrParentCxt(rParent)
364 void SAL_CALL ScXMLCellTextRubyContext::startFastElement( sal_Int32 /*nElement*/,
365 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
367 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
369 switch (aIter.getToken())
371 case XML_ELEMENT( TEXT, XML_STYLE_NAME ):
372 // This is ruby style instead of text style.
373 break;
374 default:
380 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextRubyContext::createFastChildContext(
381 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
384 switch (nElement)
386 case XML_ELEMENT( TEXT, XML_RUBY_BASE ):
388 ScXMLCellRubyBaseContext* p = new ScXMLCellRubyBaseContext(GetScImport(), mrParentCxt);
389 return p;
391 case XML_ELEMENT( TEXT, XML_RUBY_TEXT ):
393 ScXMLCellRubyTextContext* p = new ScXMLCellRubyTextContext(GetScImport(), maRubyText, maRubyTextStyle);
394 return p;
396 default:
400 return nullptr;
403 ScXMLCellRubyBaseContext::ScXMLCellRubyBaseContext(
404 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
405 ScXMLCellTextSpanContext( rImport, rParent),
406 mrParentCxt(rParent)
410 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellRubyBaseContext::createFastChildContext(
411 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
413 submitContentAndClear();
415 switch (nElement)
417 case XML_ELEMENT( TEXT, XML_SPAN ):
418 return new ScXMLCellTextSpanContext(GetScImport(), mrParentCxt);
419 default:
422 return nullptr;
425 ScXMLCellRubyTextContext::ScXMLCellRubyTextContext(
426 ScXMLImport& rImport, OUString& rRubyText, OUString& rRubyTextStyle) :
427 ScXMLImportContext(rImport),
428 mrRubyText(rRubyText),
429 mrRubyTextStyle(rRubyTextStyle)
433 void SAL_CALL ScXMLCellRubyTextContext::startFastElement( sal_Int32 /*nElement*/,
434 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
436 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
438 switch (aIter.getToken())
440 case XML_ELEMENT( TEXT, XML_STYLE_NAME ):
441 mrRubyTextStyle = aIter.toString();
442 break;
443 default:
449 void SAL_CALL ScXMLCellRubyTextContext::characters( const OUString& rChars )
451 mrRubyText+= rChars;
454 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */