nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / filter / xml / celltextparacontext.cxx
blobce7f906516457e4a9b731c49cfb3a147af6898e1
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>
17 using namespace com::sun::star;
18 using namespace xmloff::token;
20 ScXMLCellTextParaContext::ScXMLCellTextParaContext(
21 ScXMLImport& rImport, ScXMLTableRowCellContext& rParent) :
22 ScXMLImportContext(rImport),
23 mrParentCxt(rParent)
27 void SAL_CALL ScXMLCellTextParaContext::endFastElement( sal_Int32 /*nElement*/ )
29 if (!maContent.isEmpty())
30 mrParentCxt.PushParagraphSpan(maContent, OUString());
32 mrParentCxt.PushParagraphEnd();
35 void SAL_CALL ScXMLCellTextParaContext::characters( const OUString& rChars )
37 maContent += rChars;
40 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextParaContext::createFastChildContext(
41 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
43 if (!maContent.isEmpty())
45 mrParentCxt.PushParagraphSpan(maContent, OUString());
46 maContent.clear();
49 switch (nElement)
51 case XML_ELEMENT( TEXT, XML_S ):
52 return new ScXMLCellFieldSContext(GetScImport(), *this);
53 case XML_ELEMENT( TEXT, XML_SPAN ):
54 return new ScXMLCellTextSpanContext(GetScImport(), *this);
55 case XML_ELEMENT( TEXT, XML_SHEET_NAME ):
56 return new ScXMLCellFieldSheetNameContext(GetScImport(), *this);
57 case XML_ELEMENT( TEXT, XML_DATE ):
58 return new ScXMLCellFieldDateContext(GetScImport(), *this);
59 case XML_ELEMENT( TEXT, XML_TITLE ):
60 return new ScXMLCellFieldTitleContext(GetScImport(), *this);
61 case XML_ELEMENT( TEXT, XML_A ):
62 return new ScXMLCellFieldURLContext(GetScImport(), *this);
63 case XML_ELEMENT( TEXT, XML_RUBY ):
64 return new ScXMLCellTextRubyContext(GetScImport(), *this);
65 default:
69 return nullptr;
72 void ScXMLCellTextParaContext::PushSpan(const OUString& rSpan, const OUString& rStyleName)
74 mrParentCxt.PushParagraphSpan(rSpan, rStyleName);
77 void ScXMLCellTextParaContext::PushFieldSheetName(const OUString& rStyleName)
79 mrParentCxt.PushParagraphFieldSheetName(rStyleName);
82 void ScXMLCellTextParaContext::PushFieldDate(const OUString& rStyleName)
84 mrParentCxt.PushParagraphFieldDate(rStyleName);
87 void ScXMLCellTextParaContext::PushFieldTitle(const OUString& rStyleName)
89 mrParentCxt.PushParagraphFieldDocTitle(rStyleName);
92 void ScXMLCellTextParaContext::PushFieldURL(
93 const OUString& rURL, const OUString& rRep, const OUString& rStyleName, const OUString& rTargetFrame)
95 mrParentCxt.PushParagraphFieldURL(rURL, rRep, rStyleName, rTargetFrame);
98 ScXMLCellTextSpanContext::ScXMLCellTextSpanContext(
99 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
100 ScXMLImportContext(rImport),
101 mrParentCxt(rParent)
105 void SAL_CALL ScXMLCellTextSpanContext::startFastElement( sal_Int32 /*nElement*/,
106 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
108 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
110 switch (aIter.getToken())
112 case XML_ELEMENT( TEXT, XML_STYLE_NAME ):
113 maStyleName = aIter.toString();
114 break;
115 default:
121 void SAL_CALL ScXMLCellTextSpanContext::endFastElement( sal_Int32 /*nElement*/ )
123 submitContentAndClear();
126 void SAL_CALL ScXMLCellTextSpanContext::characters( const OUString& rChars )
128 maContent += rChars;
131 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextSpanContext::createFastChildContext(
132 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
134 submitContentAndClear();
136 switch (nElement)
138 case XML_ELEMENT( TEXT, XML_SHEET_NAME ):
140 ScXMLCellFieldSheetNameContext* p = new ScXMLCellFieldSheetNameContext(GetScImport(), mrParentCxt);
141 p->SetStyleName(maStyleName);
142 return p;
144 case XML_ELEMENT( TEXT, XML_DATE ):
146 ScXMLCellFieldDateContext* p = new ScXMLCellFieldDateContext(GetScImport(), mrParentCxt);
147 p->SetStyleName(maStyleName);
148 return p;
150 case XML_ELEMENT( TEXT, XML_TITLE ):
152 ScXMLCellFieldTitleContext* p = new ScXMLCellFieldTitleContext(GetScImport(), mrParentCxt);
153 p->SetStyleName(maStyleName);
154 return p;
156 case XML_ELEMENT( TEXT, XML_A ):
158 ScXMLCellFieldURLContext* p = new ScXMLCellFieldURLContext(GetScImport(), mrParentCxt);
159 p->SetStyleName(maStyleName);
160 return p;
162 case XML_ELEMENT( TEXT, XML_S ):
164 ScXMLCellFieldSContext* p = new ScXMLCellFieldSContext(GetScImport(), mrParentCxt);
165 p->SetStyleName(maStyleName);
166 return p;
168 default:
172 return nullptr;
175 void ScXMLCellTextSpanContext::submitContentAndClear()
177 if (!maContent.isEmpty())
179 mrParentCxt.PushSpan(maContent, maStyleName);
180 maContent.clear();
184 ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext(
185 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
186 ScXMLImportContext(rImport),
187 mrParentCxt(rParent)
191 void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString& rStyleName)
193 maStyleName = rStyleName;
196 void SAL_CALL ScXMLCellFieldSheetNameContext::endFastElement( sal_Int32 /*nElement*/ )
198 mrParentCxt.PushFieldSheetName(maStyleName);
201 ScXMLCellFieldDateContext::ScXMLCellFieldDateContext(
202 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
203 ScXMLImportContext(rImport),
204 mrParentCxt(rParent)
208 void ScXMLCellFieldDateContext::SetStyleName(const OUString& rStyleName)
210 maStyleName = rStyleName;
213 void SAL_CALL ScXMLCellFieldDateContext::endFastElement( sal_Int32 /*nElement*/ )
215 mrParentCxt.PushFieldDate(maStyleName);
218 ScXMLCellFieldTitleContext::ScXMLCellFieldTitleContext(
219 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
220 ScXMLImportContext(rImport),
221 mrParentCxt(rParent)
225 void ScXMLCellFieldTitleContext::SetStyleName(const OUString& rStyleName)
227 maStyleName = rStyleName;
230 void SAL_CALL ScXMLCellFieldTitleContext::endFastElement( sal_Int32 /*nElement*/ )
232 mrParentCxt.PushFieldTitle(maStyleName);
235 ScXMLCellFieldURLContext::ScXMLCellFieldURLContext(
236 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
237 ScXMLImportContext(rImport),
238 mrParentCxt(rParent)
242 void ScXMLCellFieldURLContext::SetStyleName(const OUString& rStyleName)
244 maStyleName = rStyleName;
247 void SAL_CALL ScXMLCellFieldURLContext::startFastElement( sal_Int32 /*nElement*/,
248 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
250 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
252 switch (aIter.getToken())
254 case XML_ELEMENT( XLINK, XML_HREF ):
255 maURL = aIter.toString();
256 break;
257 case XML_ELEMENT( XLINK, XML_TYPE ):
258 // Ignored for now.
259 break;
260 case XML_ELEMENT( OFFICE, XML_TARGET_FRAME_NAME ):
261 maTargetFrame = aIter.toString();
262 break;
263 default:
269 void SAL_CALL ScXMLCellFieldURLContext::endFastElement( sal_Int32 /*nElement*/ )
271 mrParentCxt.PushFieldURL(maURL, maRep, maStyleName, maTargetFrame);
274 void SAL_CALL ScXMLCellFieldURLContext::characters( const OUString& rChars )
276 maRep += rChars;
279 ScXMLCellFieldSContext::ScXMLCellFieldSContext(
280 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
281 ScXMLImportContext(rImport),
282 mrParentCxt(rParent),
283 mnCount(1)
287 void ScXMLCellFieldSContext::SetStyleName(const OUString& rStyleName)
289 maStyleName = rStyleName;
292 void SAL_CALL ScXMLCellFieldSContext::startFastElement( sal_Int32 /*nElement*/,
293 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
295 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
297 switch (aIter.getToken())
299 case XML_ELEMENT( TEXT, XML_C ):
300 mnCount = aIter.toInt32();
301 if (mnCount <= 0)
302 mnCount = 1; // worth a warning?
303 break;
304 default:
310 void SAL_CALL ScXMLCellFieldSContext::endFastElement( sal_Int32 /*nElement*/ )
312 if (mnCount)
313 PushSpaces();
316 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellFieldSContext::createFastChildContext(
317 sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
319 // <text:s> does not have child elements, but ...
320 if (mnCount)
322 PushSpaces();
323 mnCount = 0;
326 return nullptr;
329 void ScXMLCellFieldSContext::PushSpaces()
331 if (mnCount > 0)
333 if (mnCount == 1)
334 mrParentCxt.PushSpan(" ", maStyleName);
335 else
337 OUStringBuffer aBuf( mnCount);
338 comphelper::string::padToLength( aBuf, mnCount, ' ');
339 mrParentCxt.PushSpan( aBuf.makeStringAndClear(), maStyleName);
344 ScXMLCellTextRubyContext::ScXMLCellTextRubyContext(
345 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
346 ScXMLImportContext(rImport),
347 mrParentCxt(rParent)
351 void SAL_CALL ScXMLCellTextRubyContext::startFastElement( sal_Int32 /*nElement*/,
352 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
354 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
356 switch (aIter.getToken())
358 case XML_ELEMENT( TEXT, XML_STYLE_NAME ):
359 // This is ruby style instead of text style.
360 maRubyStyleName = aIter.toString();
361 break;
362 default:
368 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextRubyContext::createFastChildContext(
369 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
372 switch (nElement)
374 case XML_ELEMENT( TEXT, XML_RUBY_BASE ):
376 ScXMLCellRubyBaseContext* p = new ScXMLCellRubyBaseContext(GetScImport(), mrParentCxt);
377 return p;
379 case XML_ELEMENT( TEXT, XML_RUBY_TEXT ):
381 ScXMLCellRubyTextContext* p = new ScXMLCellRubyTextContext(GetScImport(), maRubyText, maRubyTextStyle);
382 return p;
384 default:
388 return nullptr;
391 ScXMLCellRubyBaseContext::ScXMLCellRubyBaseContext(
392 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
393 ScXMLCellTextSpanContext( rImport, rParent),
394 mrParentCxt(rParent)
398 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellRubyBaseContext::createFastChildContext(
399 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
401 submitContentAndClear();
403 switch (nElement)
405 case XML_ELEMENT( TEXT, XML_SPAN ):
406 return new ScXMLCellTextSpanContext(GetScImport(), mrParentCxt);
407 default:
410 return nullptr;
413 ScXMLCellRubyTextContext::ScXMLCellRubyTextContext(
414 ScXMLImport& rImport, OUString& rRubyText, OUString& rRubyTextStyle) :
415 ScXMLImportContext(rImport),
416 mrRubyText(rRubyText),
417 mrRubyTextStyle(rRubyTextStyle)
421 void SAL_CALL ScXMLCellRubyTextContext::startFastElement( sal_Int32 /*nElement*/,
422 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
424 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
426 switch (aIter.getToken())
428 case XML_ELEMENT( TEXT, XML_STYLE_NAME ):
429 mrRubyTextStyle = aIter.toString();
430 break;
431 default:
437 void SAL_CALL ScXMLCellRubyTextContext::characters( const OUString& rChars )
439 mrRubyText+= rChars;
442 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */