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>
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
),
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
)
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());
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
):
69 case XML_ELEMENT(TEXT
, XML_LINE_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?
79 SAL_WARN("sc","unknown text element["<<nElement
<<"]["<<SvXMLImport::getNameFromToken(nElement
)<<"] lost");
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
),
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();
134 void SAL_CALL
ScXMLCellTextSpanContext::endFastElement( sal_Int32
/*nElement*/ )
136 submitContentAndClear();
139 void SAL_CALL
ScXMLCellTextSpanContext::characters( const OUString
& rChars
)
144 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLCellTextSpanContext::createFastChildContext(
145 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
147 submitContentAndClear();
151 case XML_ELEMENT( TEXT
, XML_SHEET_NAME
):
153 ScXMLCellFieldSheetNameContext
* p
= new ScXMLCellFieldSheetNameContext(GetScImport(), mrParentCxt
);
154 p
->SetStyleName(maStyleName
);
157 case XML_ELEMENT( TEXT
, XML_DATE
):
159 ScXMLCellFieldDateContext
* p
= new ScXMLCellFieldDateContext(GetScImport(), mrParentCxt
);
160 p
->SetStyleName(maStyleName
);
163 case XML_ELEMENT( TEXT
, XML_TITLE
):
165 ScXMLCellFieldTitleContext
* p
= new ScXMLCellFieldTitleContext(GetScImport(), mrParentCxt
);
166 p
->SetStyleName(maStyleName
);
169 case XML_ELEMENT( TEXT
, XML_A
):
171 ScXMLCellFieldURLContext
* p
= new ScXMLCellFieldURLContext(GetScImport(), mrParentCxt
);
172 p
->SetStyleName(maStyleName
);
175 case XML_ELEMENT( TEXT
, XML_S
):
177 ScXMLCellFieldSContext
* p
= new ScXMLCellFieldSContext(GetScImport(), mrParentCxt
);
178 p
->SetStyleName(maStyleName
);
188 void ScXMLCellTextSpanContext::submitContentAndClear()
190 if (!maContent
.isEmpty())
192 mrParentCxt
.PushSpan(maContent
, maStyleName
);
197 ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext(
198 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
199 ScXMLImportContext(rImport
),
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
),
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
),
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
),
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();
270 case XML_ELEMENT( XLINK
, XML_TYPE
):
273 case XML_ELEMENT( OFFICE
, XML_TARGET_FRAME_NAME
):
274 maTargetFrame
= aIter
.toString();
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
)
292 ScXMLCellFieldSContext::ScXMLCellFieldSContext(
293 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
294 ScXMLImportContext(rImport
),
295 mrParentCxt(rParent
),
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();
315 mnCount
= 1; // worth a warning?
323 void SAL_CALL
ScXMLCellFieldSContext::endFastElement( sal_Int32
/*nElement*/ )
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 ...
342 void ScXMLCellFieldSContext::PushSpaces()
347 mrParentCxt
.PushSpan(u
" ", maStyleName
);
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
),
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.
380 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLCellTextRubyContext::createFastChildContext(
381 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
386 case XML_ELEMENT( TEXT
, XML_RUBY_BASE
):
388 ScXMLCellRubyBaseContext
* p
= new ScXMLCellRubyBaseContext(GetScImport(), mrParentCxt
);
391 case XML_ELEMENT( TEXT
, XML_RUBY_TEXT
):
393 ScXMLCellRubyTextContext
* p
= new ScXMLCellRubyTextContext(GetScImport(), maRubyText
, maRubyTextStyle
);
403 ScXMLCellRubyBaseContext::ScXMLCellRubyBaseContext(
404 ScXMLImport
& rImport
, ScXMLCellTextParaContext
& rParent
) :
405 ScXMLCellTextSpanContext( rImport
, rParent
),
410 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLCellRubyBaseContext::createFastChildContext(
411 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
413 submitContentAndClear();
417 case XML_ELEMENT( TEXT
, XML_SPAN
):
418 return new ScXMLCellTextSpanContext(GetScImport(), mrParentCxt
);
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();
449 void SAL_CALL
ScXMLCellRubyTextContext::characters( const OUString
& rChars
)
454 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */