Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / xml / celltextparacontext.cxx
blob2f7cc12397cbeff524f4d63e331a1bcc79d8aa8c
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/xmlnmspe.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 default:
67 return new SvXMLImportContext(GetImport());
70 void ScXMLCellTextParaContext::PushSpan(const OUString& rSpan, const OUString& rStyleName)
72 mrParentCxt.PushParagraphSpan(rSpan, rStyleName);
75 void ScXMLCellTextParaContext::PushFieldSheetName(const OUString& rStyleName)
77 mrParentCxt.PushParagraphFieldSheetName(rStyleName);
80 void ScXMLCellTextParaContext::PushFieldDate(const OUString& rStyleName)
82 mrParentCxt.PushParagraphFieldDate(rStyleName);
85 void ScXMLCellTextParaContext::PushFieldTitle(const OUString& rStyleName)
87 mrParentCxt.PushParagraphFieldDocTitle(rStyleName);
90 void ScXMLCellTextParaContext::PushFieldURL(
91 const OUString& rURL, const OUString& rRep, const OUString& rStyleName, const OUString& rTargetFrame)
93 mrParentCxt.PushParagraphFieldURL(rURL, rRep, rStyleName, rTargetFrame);
96 ScXMLCellTextSpanContext::ScXMLCellTextSpanContext(
97 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
98 ScXMLImportContext(rImport),
99 mrParentCxt(rParent)
103 void SAL_CALL ScXMLCellTextSpanContext::startFastElement( sal_Int32 /*nElement*/,
104 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
106 if ( xAttrList.is() )
108 sax_fastparser::FastAttributeList *pAttribList =
109 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
111 for (auto &aIter : *pAttribList)
113 switch (aIter.getToken())
115 case XML_ELEMENT( TEXT, XML_STYLE_NAME ):
116 maStyleName = aIter.toString();
117 break;
118 default:
125 void SAL_CALL ScXMLCellTextSpanContext::endFastElement( sal_Int32 /*nElement*/ )
127 if (!maContent.isEmpty())
129 mrParentCxt.PushSpan(maContent, maStyleName);
133 void SAL_CALL ScXMLCellTextSpanContext::characters( const OUString& rChars )
135 maContent += rChars;
138 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellTextSpanContext::createFastChildContext(
139 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
141 if (!maContent.isEmpty())
143 mrParentCxt.PushSpan(maContent, maStyleName);
144 maContent.clear();
147 switch (nElement)
149 case XML_ELEMENT( TEXT, XML_SHEET_NAME ):
151 ScXMLCellFieldSheetNameContext* p = new ScXMLCellFieldSheetNameContext(GetScImport(), mrParentCxt);
152 p->SetStyleName(maStyleName);
153 return p;
155 case XML_ELEMENT( TEXT, XML_DATE ):
157 ScXMLCellFieldDateContext* p = new ScXMLCellFieldDateContext(GetScImport(), mrParentCxt);
158 p->SetStyleName(maStyleName);
159 return p;
161 case XML_ELEMENT( TEXT, XML_TITLE ):
163 ScXMLCellFieldTitleContext* p = new ScXMLCellFieldTitleContext(GetScImport(), mrParentCxt);
164 p->SetStyleName(maStyleName);
165 return p;
167 case XML_ELEMENT( TEXT, XML_A ):
169 ScXMLCellFieldURLContext* p = new ScXMLCellFieldURLContext(GetScImport(), mrParentCxt);
170 p->SetStyleName(maStyleName);
171 return p;
173 case XML_ELEMENT( TEXT, XML_S ):
175 ScXMLCellFieldSContext* p = new ScXMLCellFieldSContext(GetScImport(), mrParentCxt);
176 p->SetStyleName(maStyleName);
177 return p;
179 default:
183 return new SvXMLImportContext(GetImport());
186 ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext(
187 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
188 ScXMLImportContext(rImport),
189 mrParentCxt(rParent)
193 void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString& rStyleName)
195 maStyleName = rStyleName;
198 void SAL_CALL ScXMLCellFieldSheetNameContext::startFastElement( sal_Int32 /*nElement*/,
199 const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
201 // <text:sheet-name> has no attributes (that I'm aware of).
204 void SAL_CALL ScXMLCellFieldSheetNameContext::endFastElement( sal_Int32 /*nElement*/ )
206 mrParentCxt.PushFieldSheetName(maStyleName);
209 ScXMLCellFieldDateContext::ScXMLCellFieldDateContext(
210 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
211 ScXMLImportContext(rImport),
212 mrParentCxt(rParent)
216 void ScXMLCellFieldDateContext::SetStyleName(const OUString& rStyleName)
218 maStyleName = rStyleName;
221 void SAL_CALL ScXMLCellFieldDateContext::endFastElement( sal_Int32 /*nElement*/ )
223 mrParentCxt.PushFieldDate(maStyleName);
226 ScXMLCellFieldTitleContext::ScXMLCellFieldTitleContext(
227 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
228 ScXMLImportContext(rImport),
229 mrParentCxt(rParent)
233 void ScXMLCellFieldTitleContext::SetStyleName(const OUString& rStyleName)
235 maStyleName = rStyleName;
238 void SAL_CALL ScXMLCellFieldTitleContext::endFastElement( sal_Int32 /*nElement*/ )
240 mrParentCxt.PushFieldTitle(maStyleName);
243 ScXMLCellFieldURLContext::ScXMLCellFieldURLContext(
244 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
245 ScXMLImportContext(rImport),
246 mrParentCxt(rParent)
250 void ScXMLCellFieldURLContext::SetStyleName(const OUString& rStyleName)
252 maStyleName = rStyleName;
255 void SAL_CALL ScXMLCellFieldURLContext::startFastElement( sal_Int32 /*nElement*/,
256 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
258 if ( xAttrList.is() )
260 sax_fastparser::FastAttributeList *pAttribList =
261 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
263 for (auto &aIter : *pAttribList)
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:
283 void SAL_CALL ScXMLCellFieldURLContext::endFastElement( sal_Int32 /*nElement*/ )
285 mrParentCxt.PushFieldURL(maURL, maRep, maStyleName, maTargetFrame);
288 void SAL_CALL ScXMLCellFieldURLContext::characters( const OUString& rChars )
290 maRep += rChars;
293 ScXMLCellFieldSContext::ScXMLCellFieldSContext(
294 ScXMLImport& rImport, ScXMLCellTextParaContext& rParent) :
295 ScXMLImportContext(rImport),
296 mrParentCxt(rParent),
297 mnCount(1)
301 void ScXMLCellFieldSContext::SetStyleName(const OUString& rStyleName)
303 maStyleName = rStyleName;
306 void SAL_CALL ScXMLCellFieldSContext::startFastElement( sal_Int32 /*nElement*/,
307 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
309 if ( xAttrList.is() )
311 sax_fastparser::FastAttributeList *pAttribList =
312 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
314 for (auto &aIter : *pAttribList)
316 switch (aIter.getToken())
318 case XML_ELEMENT( TEXT, XML_C ):
319 mnCount = aIter.toInt32();
320 if (mnCount <= 0)
321 mnCount = 1; // worth a warning?
322 break;
323 default:
330 void SAL_CALL ScXMLCellFieldSContext::endFastElement( sal_Int32 /*nElement*/ )
332 if (mnCount)
333 PushSpaces();
336 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCellFieldSContext::createFastChildContext(
337 sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
339 // <text:s> does not have child elements, but ...
340 if (mnCount)
342 PushSpaces();
343 mnCount = 0;
346 return new SvXMLImportContext(GetImport());
349 void ScXMLCellFieldSContext::PushSpaces()
351 if (mnCount > 0)
353 if (mnCount == 1)
354 mrParentCxt.PushSpan(" ", maStyleName);
355 else
357 OUStringBuffer aBuf( mnCount);
358 comphelper::string::padToLength( aBuf, mnCount, ' ');
359 mrParentCxt.PushSpan( aBuf.makeStringAndClear(), maStyleName);
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */