1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
),
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
)
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());
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);
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
),
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();
121 void SAL_CALL
ScXMLCellTextSpanContext::endFastElement( sal_Int32
/*nElement*/ )
123 submitContentAndClear();
126 void SAL_CALL
ScXMLCellTextSpanContext::characters( const OUString
& rChars
)
131 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLCellTextSpanContext::createFastChildContext(
132 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
134 submitContentAndClear();
138 case XML_ELEMENT( TEXT
, XML_SHEET_NAME
):
140 ScXMLCellFieldSheetNameContext
* p
= new ScXMLCellFieldSheetNameContext(GetScImport(), mrParentCxt
);
141 p
->SetStyleName(maStyleName
);
144 case XML_ELEMENT( TEXT
, XML_DATE
):
146 ScXMLCellFieldDateContext
* p
= new ScXMLCellFieldDateContext(GetScImport(), mrParentCxt
);
147 p
->SetStyleName(maStyleName
);
150 case XML_ELEMENT( TEXT
, XML_TITLE
):
152 ScXMLCellFieldTitleContext
* p
= new ScXMLCellFieldTitleContext(GetScImport(), mrParentCxt
);
153 p
->SetStyleName(maStyleName
);
156 case XML_ELEMENT( TEXT
, XML_A
):
158 ScXMLCellFieldURLContext
* p
= new ScXMLCellFieldURLContext(GetScImport(), mrParentCxt
);
159 p
->SetStyleName(maStyleName
);
162 case XML_ELEMENT( TEXT
, XML_S
):
164 ScXMLCellFieldSContext
* p
= new ScXMLCellFieldSContext(GetScImport(), mrParentCxt
);
165 p
->SetStyleName(maStyleName
);
175 void ScXMLCellTextSpanContext::submitContentAndClear()
177 if (!maContent
.isEmpty())
179 mrParentCxt
.PushSpan(maContent
, maStyleName
);
184 ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext(
185 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
186 ScXMLImportContext(rImport
),
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
),
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
),
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
),
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();
257 case XML_ELEMENT( XLINK
, XML_TYPE
):
260 case XML_ELEMENT( OFFICE
, XML_TARGET_FRAME_NAME
):
261 maTargetFrame
= aIter
.toString();
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
)
279 ScXMLCellFieldSContext::ScXMLCellFieldSContext(
280 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
281 ScXMLImportContext(rImport
),
282 mrParentCxt(rParent
),
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();
302 mnCount
= 1; // worth a warning?
310 void SAL_CALL
ScXMLCellFieldSContext::endFastElement( sal_Int32
/*nElement*/ )
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 ...
329 void ScXMLCellFieldSContext::PushSpaces()
334 mrParentCxt
.PushSpan(" ", maStyleName
);
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
),
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();
368 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLCellTextRubyContext::createFastChildContext(
369 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
374 case XML_ELEMENT( TEXT
, XML_RUBY_BASE
):
376 ScXMLCellRubyBaseContext
* p
= new ScXMLCellRubyBaseContext(GetScImport(), mrParentCxt
);
379 case XML_ELEMENT( TEXT
, XML_RUBY_TEXT
):
381 ScXMLCellRubyTextContext
* p
= new ScXMLCellRubyTextContext(GetScImport(), maRubyText
, maRubyTextStyle
);
391 ScXMLCellRubyBaseContext::ScXMLCellRubyBaseContext(
392 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
393 ScXMLCellTextSpanContext( rImport
, rParent
),
398 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLCellRubyBaseContext::createFastChildContext(
399 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
401 submitContentAndClear();
405 case XML_ELEMENT( TEXT
, XML_SPAN
):
406 return new ScXMLCellTextSpanContext(GetScImport(), mrParentCxt
);
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();
437 void SAL_CALL
ScXMLCellRubyTextContext::characters( const OUString
& rChars
)
442 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */