fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / xml / celltextparacontext.cxx
blob3f6c64b53a18ab6aa12449758ce9fd3fa0d9a500
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 <xmloff/nmspmap.hxx>
15 #include <comphelper/string.hxx>
17 #include <com/sun/star/xml/sax/XAttributeList.hpp>
19 using namespace com::sun::star;
21 ScXMLCellTextParaContext::ScXMLCellTextParaContext(
22 ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLTableRowCellContext& rParent) :
23 ScXMLImportContext(rImport, nPrefix, rLName),
24 mrParentCxt(rParent)
28 void ScXMLCellTextParaContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
32 void ScXMLCellTextParaContext::EndElement()
34 if (!maContent.isEmpty())
35 mrParentCxt.PushParagraphSpan(maContent, OUString());
37 mrParentCxt.PushParagraphEnd();
40 void ScXMLCellTextParaContext::Characters(const OUString& rChars)
42 maContent += rChars;
45 SvXMLImportContext* ScXMLCellTextParaContext::CreateChildContext(
46 sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
48 if (!maContent.isEmpty())
50 mrParentCxt.PushParagraphSpan(maContent, OUString());
51 maContent.clear();
54 const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextParaElemTokenMap();
55 switch (rTokenMap.Get(nPrefix, rLocalName))
57 case XML_TOK_CELL_TEXT_S:
58 return new ScXMLCellFieldSContext(GetScImport(), nPrefix, rLocalName, *this);
59 case XML_TOK_CELL_TEXT_SPAN:
60 return new ScXMLCellTextSpanContext(GetScImport(), nPrefix, rLocalName, *this);
61 case XML_TOK_CELL_TEXT_SHEET_NAME:
62 return new ScXMLCellFieldSheetNameContext(GetScImport(), nPrefix, rLocalName, *this);
63 case XML_TOK_CELL_TEXT_DATE:
64 return new ScXMLCellFieldDateContext(GetScImport(), nPrefix, rLocalName, *this);
65 case XML_TOK_CELL_TEXT_TITLE:
66 return new ScXMLCellFieldTitleContext(GetScImport(), nPrefix, rLocalName, *this);
67 case XML_TOK_CELL_TEXT_URL:
68 return new ScXMLCellFieldURLContext(GetScImport(), nPrefix, rLocalName, *this);
69 default:
73 return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
76 void ScXMLCellTextParaContext::PushSpan(const OUString& rSpan, const OUString& rStyleName)
78 mrParentCxt.PushParagraphSpan(rSpan, rStyleName);
81 void ScXMLCellTextParaContext::PushFieldSheetName(const OUString& rStyleName)
83 mrParentCxt.PushParagraphFieldSheetName(rStyleName);
86 void ScXMLCellTextParaContext::PushFieldDate(const OUString& rStyleName)
88 mrParentCxt.PushParagraphFieldDate(rStyleName);
91 void ScXMLCellTextParaContext::PushFieldTitle(const OUString& rStyleName)
93 mrParentCxt.PushParagraphFieldDocTitle(rStyleName);
96 void ScXMLCellTextParaContext::PushFieldURL(
97 const OUString& rURL, const OUString& rRep, const OUString& rStyleName)
99 mrParentCxt.PushParagraphFieldURL(rURL, rRep, rStyleName);
102 ScXMLCellTextSpanContext::ScXMLCellTextSpanContext(
103 ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
104 ScXMLImportContext(rImport, nPrefix, rLName),
105 mrParentCxt(rParent)
109 void ScXMLCellTextSpanContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
111 if (!xAttrList.is())
112 return;
114 OUString aLocalName;
115 sal_Int16 nAttrCount = xAttrList->getLength();
117 const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextSpanAttrTokenMap();
118 for (sal_Int16 i = 0; i < nAttrCount; ++i)
120 sal_uInt16 nAttrPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
121 xAttrList->getNameByIndex(i), &aLocalName);
123 const OUString& rAttrValue = xAttrList->getValueByIndex(i);
124 sal_uInt16 nToken = rTokenMap.Get(nAttrPrefix, aLocalName);
125 switch (nToken)
127 case XML_TOK_CELL_TEXT_SPAN_ATTR_STYLE_NAME:
128 maStyleName = rAttrValue;
129 break;
130 default:
136 void ScXMLCellTextSpanContext::EndElement()
138 if (!maContent.isEmpty())
140 mrParentCxt.PushSpan(maContent, maStyleName);
144 void ScXMLCellTextSpanContext::Characters(const OUString& rChars)
146 maContent += rChars;
149 SvXMLImportContext* ScXMLCellTextSpanContext::CreateChildContext(
150 sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
152 if (!maContent.isEmpty())
154 mrParentCxt.PushSpan(maContent, maStyleName);
155 maContent.clear();
158 const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextSpanElemTokenMap();
159 switch (rTokenMap.Get(nPrefix, rLocalName))
161 case XML_TOK_CELL_TEXT_SPAN_ELEM_SHEET_NAME:
163 ScXMLCellFieldSheetNameContext* p = new ScXMLCellFieldSheetNameContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
164 p->SetStyleName(maStyleName);
165 return p;
167 case XML_TOK_CELL_TEXT_SPAN_ELEM_DATE:
169 ScXMLCellFieldDateContext* p = new ScXMLCellFieldDateContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
170 p->SetStyleName(maStyleName);
171 return p;
173 case XML_TOK_CELL_TEXT_SPAN_ELEM_TITLE:
175 ScXMLCellFieldTitleContext* p = new ScXMLCellFieldTitleContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
176 p->SetStyleName(maStyleName);
177 return p;
179 case XML_TOK_CELL_TEXT_SPAN_ELEM_URL:
181 ScXMLCellFieldURLContext* p = new ScXMLCellFieldURLContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
182 p->SetStyleName(maStyleName);
183 return p;
185 case XML_TOK_CELL_TEXT_SPAN_ELEM_S:
187 ScXMLCellFieldSContext* p = new ScXMLCellFieldSContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
188 p->SetStyleName(maStyleName);
189 return p;
191 default:
195 return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
198 ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext(
199 ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
200 ScXMLImportContext(rImport, nPrefix, rLName),
201 mrParentCxt(rParent)
205 void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString& rStyleName)
207 maStyleName = rStyleName;
210 void ScXMLCellFieldSheetNameContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
212 // <text:sheet-name> has no attributes (that I'm aware of).
215 void ScXMLCellFieldSheetNameContext::EndElement()
217 mrParentCxt.PushFieldSheetName(maStyleName);
220 void ScXMLCellFieldSheetNameContext::Characters(const OUString& /*rChars*/)
224 SvXMLImportContext* ScXMLCellFieldSheetNameContext::CreateChildContext(
225 sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
227 return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
230 ScXMLCellFieldDateContext::ScXMLCellFieldDateContext(
231 ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
232 ScXMLImportContext(rImport, nPrefix, rLName),
233 mrParentCxt(rParent)
237 void ScXMLCellFieldDateContext::SetStyleName(const OUString& rStyleName)
239 maStyleName = rStyleName;
242 void ScXMLCellFieldDateContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
246 void ScXMLCellFieldDateContext::EndElement()
248 mrParentCxt.PushFieldDate(maStyleName);
251 void ScXMLCellFieldDateContext::Characters(const OUString& /*rChars*/)
255 SvXMLImportContext* ScXMLCellFieldDateContext::CreateChildContext(
256 sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
258 return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
261 ScXMLCellFieldTitleContext::ScXMLCellFieldTitleContext(
262 ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
263 ScXMLImportContext(rImport, nPrefix, rLName),
264 mrParentCxt(rParent)
268 void ScXMLCellFieldTitleContext::SetStyleName(const OUString& rStyleName)
270 maStyleName = rStyleName;
273 void ScXMLCellFieldTitleContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
277 void ScXMLCellFieldTitleContext::EndElement()
279 mrParentCxt.PushFieldTitle(maStyleName);
282 void ScXMLCellFieldTitleContext::Characters(const OUString& /*rChars*/)
286 SvXMLImportContext* ScXMLCellFieldTitleContext::CreateChildContext(
287 sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
289 return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
292 ScXMLCellFieldURLContext::ScXMLCellFieldURLContext(
293 ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
294 ScXMLImportContext(rImport, nPrefix, rLName),
295 mrParentCxt(rParent)
299 void ScXMLCellFieldURLContext::SetStyleName(const OUString& rStyleName)
301 maStyleName = rStyleName;
304 void ScXMLCellFieldURLContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
306 if (!xAttrList.is())
307 return;
309 OUString aLocalName;
310 sal_Int16 nAttrCount = xAttrList->getLength();
312 const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextURLAttrTokenMap();
313 for (sal_Int16 i = 0; i < nAttrCount; ++i)
315 sal_uInt16 nAttrPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
316 xAttrList->getNameByIndex(i), &aLocalName);
318 const OUString& rAttrValue = xAttrList->getValueByIndex(i);
319 sal_uInt16 nToken = rTokenMap.Get(nAttrPrefix, aLocalName);
320 switch (nToken)
322 case XML_TOK_CELL_TEXT_URL_ATTR_UREF:
323 maURL = rAttrValue;
324 break;
325 case XML_TOK_CELL_TEXT_URL_ATTR_TYPE:
326 // Ignored for now.
327 break;
328 default:
334 void ScXMLCellFieldURLContext::EndElement()
336 mrParentCxt.PushFieldURL(maURL, maRep, maStyleName);
339 void ScXMLCellFieldURLContext::Characters(const OUString& rChars)
341 maRep += rChars;
344 SvXMLImportContext* ScXMLCellFieldURLContext::CreateChildContext(
345 sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
347 return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
350 ScXMLCellFieldSContext::ScXMLCellFieldSContext(
351 ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
352 ScXMLImportContext(rImport, nPrefix, rLName),
353 mrParentCxt(rParent),
354 mnCount(1)
358 void ScXMLCellFieldSContext::SetStyleName(const OUString& rStyleName)
360 maStyleName = rStyleName;
363 void ScXMLCellFieldSContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
365 if (!xAttrList.is())
366 return;
368 OUString aLocalName;
369 sal_Int16 nAttrCount = xAttrList->getLength();
371 const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextSAttrTokenMap();
372 for (sal_Int16 i = 0; i < nAttrCount; ++i)
374 sal_uInt16 nAttrPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
375 xAttrList->getNameByIndex(i), &aLocalName);
377 const OUString& rAttrValue = xAttrList->getValueByIndex(i);
378 sal_uInt16 nToken = rTokenMap.Get(nAttrPrefix, aLocalName);
379 switch (nToken)
381 case XML_TOK_CELL_TEXT_S_ATTR_C:
382 mnCount = rAttrValue.toInt32();
383 if (mnCount <= 0)
384 mnCount = 1; // worth a warning?
385 break;
386 default:
392 void ScXMLCellFieldSContext::EndElement()
394 if (mnCount)
395 PushSpaces();
398 SvXMLImportContext* ScXMLCellFieldSContext::CreateChildContext(
399 sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
401 // <text:s> does not have child elements, but ...
402 if (mnCount)
404 PushSpaces();
405 mnCount = 0;
408 return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
411 void ScXMLCellFieldSContext::PushSpaces()
413 if (mnCount > 0)
415 if (mnCount == 1)
416 mrParentCxt.PushSpan(" ", maStyleName);
417 else
419 OUStringBuffer aBuf( mnCount);
420 comphelper::string::padToLength( aBuf, mnCount, ' ');
421 mrParentCxt.PushSpan( aBuf.makeStringAndClear(), maStyleName);
426 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */