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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
25 #include <com/sun/star/container/XEnumerationAccess.hpp>
26 #include <com/sun/star/frame/XModel.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
29 #include <com/sun/star/text/ReferenceFieldSource.hpp>
30 #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
31 #include <com/sun/star/text/XTextFrame.hpp>
32 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
33 #include <com/sun/star/text/XTextFramesSupplier.hpp>
34 #include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
35 #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
36 #include <com/sun/star/text/XFormField.hpp>
37 #include <com/sun/star/ucb/XAnyCompare.hpp>
38 #include <com/sun/star/container/XNamed.hpp>
39 #include <com/sun/star/style/XStyle.hpp>
40 #include <xmloff/xmlnamespace.hxx>
41 #include <xmloff/txtstyli.hxx>
42 #include <xmloff/xmlnumi.hxx>
43 #include <xmloff/maptype.hxx>
45 #include <sal/log.hxx>
46 #include "txtparai.hxx"
47 #include <xmloff/txtprmap.hxx>
48 #include <xmloff/txtimppr.hxx>
49 #include <xmloff/xmlimp.hxx>
50 #include <txtvfldi.hxx>
51 #include <xmloff/i18nmap.hxx>
52 #include "XMLTextListItemContext.hxx"
53 #include "XMLTextListBlockContext.hxx"
54 #include "XMLTextFrameContext.hxx"
55 #include "XMLTextFrameHyperlinkContext.hxx"
56 #include "XMLSectionImportContext.hxx"
57 #include "XMLIndexTOCContext.hxx"
58 #include <xmloff/XMLEventsImportContext.hxx>
59 #include "XMLTrackedChangesImportContext.hxx"
60 #include "XMLChangeImportContext.hxx"
61 #include "XMLAutoMarkFileContext.hxx"
62 #include <xmloff/ProgressBarHelper.hxx>
64 #include "XMLCalculationSettingsContext.hxx"
65 #include <XMLNumberStylesImport.hxx>
66 #include <PageMasterStyleMap.hxx>
67 #include <PageMasterPropHdlFactory.hxx>
68 // XML import: reconstruction of assignment of paragraph style to outline levels (#i69629#)
69 #include <com/sun/star/beans/XPropertyState.hpp>
70 #include <txtlists.hxx>
71 #include <xmloff/odffields.hxx>
73 using ::com::sun::star::ucb::XAnyCompare
;
75 using namespace ::com::sun::star
;
76 using namespace ::com::sun::star::uno
;
77 using namespace ::com::sun::star::beans
;
78 using namespace ::com::sun::star::text
;
79 using namespace ::com::sun::star::frame
;
80 using namespace ::com::sun::star::style
;
81 using namespace ::com::sun::star::container
;
82 using namespace ::com::sun::star::drawing
;
83 using namespace ::com::sun::star::xml::sax
;
84 using namespace ::com::sun::star::lang
;
85 using namespace ::xmloff::token
;
86 using namespace ::com::sun::star::ucb
;
89 // maximum allowed length of combined characters field
90 #define MAX_COMBINED_CHARACTERS 6
92 struct XMLTextImportHelper::Impl
94 std::optional
< std::vector
<OUString
> > m_xPrevFrmNames
;
95 std::optional
< std::vector
<OUString
> > m_xNextFrmNames
;
96 std::unique_ptr
<XMLTextListsHelper
> m_xTextListsHelper
;
98 rtl::Reference
<SvXMLStylesContext
> m_xAutoStyles
;
100 rtl::Reference
< SvXMLImportPropertyMapper
> m_xParaImpPrMap
;
101 rtl::Reference
< SvXMLImportPropertyMapper
> m_xTextImpPrMap
;
102 rtl::Reference
< SvXMLImportPropertyMapper
> m_xFrameImpPrMap
;
103 rtl::Reference
< SvXMLImportPropertyMapper
> m_xSectionImpPrMap
;
104 rtl::Reference
< SvXMLImportPropertyMapper
> m_xRubyImpPrMap
;
106 std::unique_ptr
<SvI18NMap
> m_xRenameMap
;
108 /* Change and extend data structure:
109 - data structure contains candidates of paragraph styles, which
110 will be assigned to the outline style
111 - data structure contains more than one candidate for each list level
112 of the outline style (#i69629#)
114 std::unique_ptr
< std::vector
< OUString
> []>
115 m_xOutlineStylesCandidates
;
117 // start range, xml:id, RDFa stuff
119 uno::Reference
<text::XTextRange
>, OUString
,
120 std::shared_ptr
< ::xmloff::ParsedRDFaAttributes
> >
122 /// start ranges for open bookmarks
123 std::map
< OUString
, BookmarkMapEntry_t
> m_BookmarkStartRanges
;
125 std::vector
< OUString
> m_BookmarkVector
;
127 /// name of the last 'open' redline that started between paragraphs
128 OUString m_sOpenRedlineIdentifier
;
130 // Used for frame deduplication, the name of the last frame imported directly before the current one
131 OUString msLastImportedFrameName
;
133 std::map
< OUString
, bool > m_bBookmarkHidden
;
134 std::map
< OUString
, OUString
> m_sBookmarkCondition
;
136 uno::Reference
<text::XText
> m_xText
;
137 uno::Reference
<text::XTextCursor
> m_xCursor
;
138 uno::Reference
<text::XTextRange
> m_xCursorAsRange
;
139 uno::Reference
<container::XNameContainer
> m_xParaStyles
;
140 uno::Reference
<container::XNameContainer
> m_xTextStyles
;
141 uno::Reference
<container::XNameContainer
> m_xNumStyles
;
142 uno::Reference
<container::XNameContainer
> m_xFrameStyles
;
143 uno::Reference
<container::XNameContainer
> m_xPageStyles
;
144 uno::Reference
<container::XNameContainer
> m_xCellStyles
;
145 uno::Reference
<container::XIndexReplace
> m_xChapterNumbering
;
146 uno::Reference
<container::XNameAccess
> m_xTextFrames
;
147 uno::Reference
<container::XNameAccess
> m_xGraphics
;
148 uno::Reference
<container::XNameAccess
> m_xObjects
;
149 uno::Reference
<lang::XMultiServiceFactory
> m_xServiceFactory
;
151 SvXMLImport
& m_rSvXMLImport
;
153 bool m_bInsertMode
: 1;
154 bool m_bStylesOnlyMode
: 1;
155 bool m_bBlockMode
: 1;
156 bool m_bProgress
: 1;
157 bool m_bOrganizerMode
: 1;
158 bool m_bBodyContentStarted
: 1;
160 /// Are we inside a <text:deletion> element (deleted redline section)
161 bool m_bInsideDeleteContext
: 1;
163 typedef ::std::pair
< OUString
, OUString
> field_name_type_t
;
164 typedef ::std::pair
< OUString
, OUString
> field_param_t
;
165 typedef ::std::vector
< field_param_t
> field_params_t
;
166 typedef ::std::tuple
<field_name_type_t
, field_params_t
, uno::Reference
<text::XFormField
>, uno::Reference
<text::XTextRange
>> field_stack_item_t
;
167 typedef ::std::stack
< field_stack_item_t
> field_stack_t
;
169 field_stack_t m_FieldStack
;
171 OUString m_sCellParaStyleDefault
;
173 std::optional
<std::map
<OUString
, OUString
>> m_xCrossRefHeadingBookmarkMap
;
175 Impl( uno::Reference
<frame::XModel
> const& rModel
,
176 SvXMLImport
& rImport
,
177 bool const bInsertMode
, bool const bStylesOnlyMode
,
178 bool const bProgress
, bool const bBlockMode
,
179 bool const bOrganizerMode
)
180 : m_xTextListsHelper( new XMLTextListsHelper() )
181 // XML import: reconstruction of assignment of paragraph style to outline levels (#i69629#)
182 , m_xServiceFactory( rModel
, UNO_QUERY
)
183 , m_rSvXMLImport( rImport
)
184 , m_bInsertMode( bInsertMode
)
185 , m_bStylesOnlyMode( bStylesOnlyMode
)
186 , m_bBlockMode( bBlockMode
)
187 , m_bProgress( bProgress
)
188 , m_bOrganizerMode( bOrganizerMode
)
189 , m_bBodyContentStarted( true )
190 , m_bInsideDeleteContext( false )
193 Impl(const Impl
&) = delete;
194 Impl
& operator=(const Impl
&) = delete;
196 void InitOutlineStylesCandidates()
198 if (!m_xOutlineStylesCandidates
)
200 size_t const size(m_xChapterNumbering
->getCount());
201 m_xOutlineStylesCandidates
.reset(
202 new ::std::vector
< OUString
>[size
] );
209 uno::Reference
< text::XText
> & XMLTextImportHelper::GetText()
211 return m_xImpl
->m_xText
;
214 uno::Reference
< text::XTextCursor
> & XMLTextImportHelper::GetCursor()
216 return m_xImpl
->m_xCursor
;
219 uno::Reference
< text::XTextRange
> & XMLTextImportHelper::GetCursorAsRange()
221 return m_xImpl
->m_xCursorAsRange
;
224 bool XMLTextImportHelper::IsInsertMode() const
226 return m_xImpl
->m_bInsertMode
;
229 bool XMLTextImportHelper::IsStylesOnlyMode() const
231 return m_xImpl
->m_bStylesOnlyMode
;
234 bool XMLTextImportHelper::IsBlockMode() const
236 return m_xImpl
->m_bBlockMode
;
239 bool XMLTextImportHelper::IsOrganizerMode() const
241 return m_xImpl
->m_bOrganizerMode
;
244 bool XMLTextImportHelper::IsProgress() const
246 return m_xImpl
->m_bProgress
;
249 uno::Reference
<container::XNameContainer
> const&
250 XMLTextImportHelper::GetParaStyles() const
252 return m_xImpl
->m_xParaStyles
;
255 uno::Reference
<container::XNameContainer
> const&
256 XMLTextImportHelper::GetTextStyles() const
258 return m_xImpl
->m_xTextStyles
;
261 uno::Reference
<container::XNameContainer
> const&
262 XMLTextImportHelper::GetNumberingStyles() const
264 return m_xImpl
->m_xNumStyles
;
267 uno::Reference
<container::XNameContainer
> const&
268 XMLTextImportHelper::GetFrameStyles() const
270 return m_xImpl
->m_xFrameStyles
;
273 uno::Reference
<container::XNameContainer
> const&
274 XMLTextImportHelper::GetPageStyles() const
276 return m_xImpl
->m_xPageStyles
;
279 uno::Reference
<container::XNameContainer
> const&
280 XMLTextImportHelper::GetCellStyles() const
282 return m_xImpl
->m_xCellStyles
;
285 uno::Reference
<container::XIndexReplace
> const&
286 XMLTextImportHelper::GetChapterNumbering() const
288 return m_xImpl
->m_xChapterNumbering
;
291 rtl::Reference
< SvXMLImportPropertyMapper
> const&
292 XMLTextImportHelper::GetParaImportPropertySetMapper() const
294 return m_xImpl
->m_xParaImpPrMap
;
297 rtl::Reference
< SvXMLImportPropertyMapper
> const&
298 XMLTextImportHelper::GetTextImportPropertySetMapper() const
300 return m_xImpl
->m_xTextImpPrMap
;
303 rtl::Reference
< SvXMLImportPropertyMapper
> const&
304 XMLTextImportHelper::GetSectionImportPropertySetMapper() const
306 return m_xImpl
->m_xSectionImpPrMap
;
309 rtl::Reference
< SvXMLImportPropertyMapper
> const&
310 XMLTextImportHelper::GetRubyImportPropertySetMapper() const
312 return m_xImpl
->m_xRubyImpPrMap
;
315 void XMLTextImportHelper::SetInsideDeleteContext(bool const bNew
)
317 m_xImpl
->m_bInsideDeleteContext
= bNew
;
320 bool XMLTextImportHelper::IsInsideDeleteContext() const
322 return m_xImpl
->m_bInsideDeleteContext
;
325 SvXMLImport
& XMLTextImportHelper::GetXMLImport()
327 return m_xImpl
->m_rSvXMLImport
;
330 XMLTextListsHelper
& XMLTextImportHelper::GetTextListHelper()
332 return *m_xImpl
->m_xTextListsHelper
;
337 class FieldParamImporter
340 typedef std::pair
<OUString
,OUString
> field_param_t
;
341 typedef std::vector
<field_param_t
> field_params_t
;
342 FieldParamImporter(const field_params_t
* const pInParams
, Reference
<XNameContainer
> const & xOutParams
)
343 : m_pInParams(pInParams
)
344 , m_xOutParams(xOutParams
)
349 const field_params_t
* const m_pInParams
;
350 Reference
<XNameContainer
> m_xOutParams
;
353 void FieldParamImporter::Import()
355 ::std::vector
<OUString
> vListEntries
;
356 ::std::map
<OUString
, Any
> vOutParams
;
357 for(const auto& rCurrent
: *m_pInParams
)
359 if(rCurrent
.first
== ODF_FORMDROPDOWN_RESULT
)
362 vOutParams
[rCurrent
.first
] <<= rCurrent
.second
.toInt32();
364 else if(rCurrent
.first
== ODF_FORMCHECKBOX_RESULT
)
367 vOutParams
[rCurrent
.first
] <<= rCurrent
.second
.toBoolean();
369 else if(rCurrent
.first
== ODF_FORMDROPDOWN_LISTENTRY
)
372 vListEntries
.push_back(rCurrent
.second
);
375 vOutParams
[rCurrent
.first
] <<= rCurrent
.second
;
377 if(!vListEntries
.empty())
379 Sequence
<OUString
> vListEntriesSeq(vListEntries
.size());
380 copy(vListEntries
.begin(), vListEntries
.end(), vListEntriesSeq
.getArray());
381 vOutParams
[ODF_FORMDROPDOWN_LISTENTRY
] <<= vListEntriesSeq
;
383 for(const auto& rCurrent
: vOutParams
)
387 m_xOutParams
->insertByName(rCurrent
.first
, rCurrent
.second
);
389 catch(const ElementExistException
&)
391 SAL_INFO("xmloff.text", "duplicate fieldmark param");
397 XMLTextImportHelper::XMLTextImportHelper(
398 uno::Reference
<frame::XModel
> const& rModel
,
399 SvXMLImport
& rImport
,
400 bool const bInsertMode
, bool const bStylesOnlyMode
,
401 bool const bProgress
, bool const bBlockMode
,
402 bool const bOrganizerMode
)
403 : m_xImpl( new Impl(rModel
, rImport
, bInsertMode
, bStylesOnlyMode
,
404 bProgress
, bBlockMode
, bOrganizerMode
) )
405 , m_xBackpatcherImpl( MakeBackpatcherImpl() )
407 static constexpr OUString s_PropNameDefaultListId
= u
"DefaultListId"_ustr
;
409 Reference
< XChapterNumberingSupplier
> xCNSupplier( rModel
, UNO_QUERY
);
411 if (xCNSupplier
.is())
413 // note: m_xChapterNumbering is accessed to import some fields
414 m_xImpl
->m_xChapterNumbering
= xCNSupplier
->getChapterNumberingRules();
415 // the AutoCorrect document doesn't have a proper outline numbering
416 if (!IsBlockMode() && m_xImpl
->m_xChapterNumbering
.is())
418 Reference
< XPropertySet
> const xNumRuleProps(
419 m_xImpl
->m_xChapterNumbering
, UNO_QUERY
);
420 if ( xNumRuleProps
.is() )
422 Reference
< XPropertySetInfo
> xNumRulePropSetInfo(
423 xNumRuleProps
->getPropertySetInfo());
424 if (xNumRulePropSetInfo
.is() &&
425 xNumRulePropSetInfo
->hasPropertyByName(
426 s_PropNameDefaultListId
))
429 xNumRuleProps
->getPropertyValue(s_PropNameDefaultListId
)
431 assert( !sListId
.isEmpty() &&
432 "no default list id found at chapter numbering rules instance. Serious defect." );
433 if ( !sListId
.isEmpty() )
435 Reference
< XNamed
> const xChapterNumNamed(
436 m_xImpl
->m_xChapterNumbering
, UNO_QUERY
);
437 if ( xChapterNumNamed
.is() )
439 m_xImpl
->m_xTextListsHelper
->KeepListAsProcessed(
441 xChapterNumNamed
->getName(),
450 Reference
< XStyleFamiliesSupplier
> xFamiliesSupp( rModel
, UNO_QUERY
);
451 // SAL_WARN_IF( !xFamiliesSupp.is(), "xmloff", "no chapter numbering supplier" ); for clipboard there may be documents without styles
453 if( xFamiliesSupp
.is() )
455 Reference
< XNameAccess
> xFamilies(xFamiliesSupp
->getStyleFamilies());
457 static constexpr OUString
aParaStyles(u
"ParagraphStyles"_ustr
);
458 if( xFamilies
->hasByName( aParaStyles
) )
460 m_xImpl
->m_xParaStyles
.set(xFamilies
->getByName(aParaStyles
),
464 static constexpr OUString
aCharStyles(u
"CharacterStyles"_ustr
);
465 if( xFamilies
->hasByName( aCharStyles
) )
467 m_xImpl
->m_xTextStyles
.set(xFamilies
->getByName(aCharStyles
),
471 static constexpr OUString
aNumStyles(u
"NumberingStyles"_ustr
);
472 if( xFamilies
->hasByName( aNumStyles
) )
474 m_xImpl
->m_xNumStyles
.set(xFamilies
->getByName(aNumStyles
),
478 static constexpr OUString
aFrameStyles(u
"FrameStyles"_ustr
);
479 if( xFamilies
->hasByName( aFrameStyles
) )
481 m_xImpl
->m_xFrameStyles
.set(xFamilies
->getByName(aFrameStyles
),
485 static constexpr OUString
aPageStyles(u
"PageStyles"_ustr
);
486 if( xFamilies
->hasByName( aPageStyles
) )
488 m_xImpl
->m_xPageStyles
.set(xFamilies
->getByName(aPageStyles
),
492 static constexpr OUString
aCellStyles(u
"CellStyles"_ustr
);
493 if( xFamilies
->hasByName( aCellStyles
) )
495 m_xImpl
->m_xCellStyles
.set(xFamilies
->getByName(aCellStyles
),
500 Reference
< XTextFramesSupplier
> xTFS( rModel
, UNO_QUERY
);
503 m_xImpl
->m_xTextFrames
.set(xTFS
->getTextFrames());
506 Reference
< XTextGraphicObjectsSupplier
> xTGOS( rModel
, UNO_QUERY
);
509 m_xImpl
->m_xGraphics
.set(xTGOS
->getGraphicObjects());
512 Reference
< XTextEmbeddedObjectsSupplier
> xTEOS( rModel
, UNO_QUERY
);
515 m_xImpl
->m_xObjects
.set(xTEOS
->getEmbeddedObjects());
518 XMLPropertySetMapper
*pPropMapper
=
519 new XMLTextPropertySetMapper( TextPropMap::PARA
, false );
520 m_xImpl
->m_xParaImpPrMap
=
521 new XMLTextImportPropertyMapper( pPropMapper
, rImport
);
523 pPropMapper
= new XMLTextPropertySetMapper( TextPropMap::TEXT
, false );
524 m_xImpl
->m_xTextImpPrMap
=
525 new XMLTextImportPropertyMapper( pPropMapper
, rImport
);
527 pPropMapper
= new XMLTextPropertySetMapper( TextPropMap::FRAME
, false );
528 m_xImpl
->m_xFrameImpPrMap
=
529 new XMLTextImportPropertyMapper( pPropMapper
, rImport
);
531 pPropMapper
= new XMLTextPropertySetMapper( TextPropMap::SECTION
, false );
532 m_xImpl
->m_xSectionImpPrMap
=
533 new XMLTextImportPropertyMapper( pPropMapper
, rImport
);
535 pPropMapper
= new XMLTextPropertySetMapper( TextPropMap::RUBY
, false );
536 m_xImpl
->m_xRubyImpPrMap
=
537 new SvXMLImportPropertyMapper( pPropMapper
, rImport
);
540 XMLTextImportHelper::~XMLTextImportHelper()
544 void XMLTextImportHelper::dispose()
546 if (m_xImpl
->m_xAutoStyles
)
547 m_xImpl
->m_xAutoStyles
->dispose();
550 SvXMLImportPropertyMapper
*XMLTextImportHelper::CreateShapeExtPropMapper(SvXMLImport
& rImport
)
552 XMLPropertySetMapper
*pPropMapper
=
553 new XMLTextPropertySetMapper( TextPropMap::FRAME
, false );
554 return new XMLTextImportPropertyMapper( pPropMapper
, rImport
);
557 SvXMLImportPropertyMapper
*XMLTextImportHelper::CreateParaExtPropMapper(SvXMLImport
& rImport
)
559 XMLPropertySetMapper
*pPropMapper
=
560 new XMLTextPropertySetMapper( TextPropMap::SHAPE_PARA
, false );
561 return new XMLTextImportPropertyMapper( pPropMapper
, rImport
);
564 SvXMLImportPropertyMapper
*XMLTextImportHelper::CreateParaDefaultExtPropMapper(SvXMLImport
& rImport
)
566 XMLPropertySetMapper
* pPropMapper
=
567 new XMLTextPropertySetMapper( TextPropMap::SHAPE_PARA
, false );
568 SvXMLImportPropertyMapper
* pImportMapper
= new XMLTextImportPropertyMapper( pPropMapper
, rImport
);
571 new XMLTextPropertySetMapper( TextPropMap::TEXT_ADDITIONAL_DEFAULTS
, false );
572 pImportMapper
->ChainImportMapper( new XMLTextImportPropertyMapper( pPropMapper
, rImport
) );
574 return pImportMapper
;
577 SvXMLImportPropertyMapper
*
578 XMLTextImportHelper::CreateTableDefaultExtPropMapper(
579 SvXMLImport
& rImport
)
581 XMLPropertySetMapper
*pPropMapper
=
582 new XMLTextPropertySetMapper( TextPropMap::TABLE_DEFAULTS
, false );
583 return new SvXMLImportPropertyMapper( pPropMapper
, rImport
);
586 SvXMLImportPropertyMapper
*
587 XMLTextImportHelper::CreateTableRowDefaultExtPropMapper(
588 SvXMLImport
& rImport
)
590 XMLPropertySetMapper
*pPropMapper
=
591 new XMLTextPropertySetMapper( TextPropMap::TABLE_ROW_DEFAULTS
, false );
592 return new SvXMLImportPropertyMapper( pPropMapper
, rImport
);
595 SvXMLImportPropertyMapper
*
596 XMLTextImportHelper::CreateTableCellExtPropMapper(
597 SvXMLImport
& rImport
)
599 XMLPropertySetMapper
*pPropMapper
=
600 new XMLTextPropertySetMapper( TextPropMap::CELL
, false );
601 return new XMLTextImportPropertyMapper( pPropMapper
, rImport
);
604 SvXMLImportPropertyMapper
*
605 XMLTextImportHelper::CreateDrawingPageExtPropMapper(SvXMLImport
& rImport
)
607 rtl::Reference
<XMLPropertyHandlerFactory
> const pFactory(new XMLPageMasterPropHdlFactory
);
608 XMLPropertySetMapper
*const pPropMapper(
609 new XMLPropertySetMapper(g_XMLPageMasterDrawingPageStyleMap
, pFactory
, false));
610 return new SvXMLImportPropertyMapper(pPropMapper
, rImport
);
613 void XMLTextImportHelper::SetCursor( const Reference
< XTextCursor
> & rCursor
)
615 m_xImpl
->m_xCursor
.set(rCursor
);
616 m_xImpl
->m_xText
.set(rCursor
->getText());
617 m_xImpl
->m_xCursorAsRange
= rCursor
;
620 void XMLTextImportHelper::ResetCursor()
622 m_xImpl
->m_xCursor
.clear();
623 m_xImpl
->m_xText
.clear();
624 m_xImpl
->m_xCursorAsRange
.clear();
628 bool XMLTextImportHelper::HasFrameByName( const OUString
& rName
) const
630 return (m_xImpl
->m_xTextFrames
.is() &&
631 m_xImpl
->m_xTextFrames
->hasByName(rName
))
632 || (m_xImpl
->m_xGraphics
.is() &&
633 m_xImpl
->m_xGraphics
->hasByName(rName
))
634 || (m_xImpl
->m_xObjects
.is() &&
635 m_xImpl
->m_xObjects
->hasByName(rName
));
638 bool XMLTextImportHelper::IsDuplicateFrame(const OUString
& sName
, sal_Int32 nX
, sal_Int32 nY
, sal_Int32 nWidth
, sal_Int32 nHeight
) const
640 if (HasFrameByName(sName
))
642 uno::Reference
<beans::XPropertySet
> xOtherFrame
;
643 if(m_xImpl
->m_xTextFrames
.is() && m_xImpl
->m_xTextFrames
->hasByName(sName
))
644 xOtherFrame
.set(m_xImpl
->m_xTextFrames
->getByName(sName
), uno::UNO_QUERY
);
645 else if(m_xImpl
->m_xGraphics
.is() && m_xImpl
->m_xGraphics
->hasByName(sName
))
646 xOtherFrame
.set(m_xImpl
->m_xGraphics
->getByName(sName
), uno::UNO_QUERY
);
647 else if (m_xImpl
->m_xObjects
.is() && m_xImpl
->m_xObjects
->hasByName(sName
))
648 xOtherFrame
.set(m_xImpl
->m_xObjects
->getByName(sName
), uno::UNO_QUERY
);
650 Reference
< XPropertySetInfo
> xPropSetInfo
= xOtherFrame
->getPropertySetInfo();
651 if(xPropSetInfo
->hasPropertyByName(u
"Width"_ustr
))
653 sal_Int32 nOtherWidth
= 0;
654 xOtherFrame
->getPropertyValue(u
"Width"_ustr
) >>= nOtherWidth
;
655 if(nWidth
!= nOtherWidth
)
659 if (xPropSetInfo
->hasPropertyByName(u
"Height"_ustr
))
661 sal_Int32 nOtherHeight
= 0;
662 xOtherFrame
->getPropertyValue(u
"Height"_ustr
) >>= nOtherHeight
;
663 if (nHeight
!= nOtherHeight
)
667 if (xPropSetInfo
->hasPropertyByName(u
"HoriOrientPosition"_ustr
))
669 sal_Int32 nOtherX
= 0;
670 xOtherFrame
->getPropertyValue(u
"HoriOrientPosition"_ustr
) >>= nOtherX
;
675 if (xPropSetInfo
->hasPropertyByName(u
"VertOrientPosition"_ustr
))
677 sal_Int32 nOtherY
= 0;
678 xOtherFrame
->getPropertyValue(u
"VertOrientPosition"_ustr
) >>= nOtherY
;
683 // In some case, position is not defined for frames, so check whether the two frames follow each other (are anchored to the same position)
684 return m_xImpl
->msLastImportedFrameName
== sName
;
689 void XMLTextImportHelper::StoreLastImportedFrameName(const OUString
& rName
)
691 m_xImpl
->msLastImportedFrameName
= rName
;
694 void XMLTextImportHelper::ClearLastImportedTextFrameName()
696 m_xImpl
->msLastImportedFrameName
.clear();
699 void XMLTextImportHelper::InsertString( const OUString
& rChars
)
701 assert(m_xImpl
->m_xText
.is());
702 assert(m_xImpl
->m_xCursorAsRange
.is());
703 if (m_xImpl
->m_xText
.is())
705 m_xImpl
->m_xText
->insertString(m_xImpl
->m_xCursorAsRange
,
710 void XMLTextImportHelper::InsertString( std::u16string_view rChars
,
711 bool& rIgnoreLeadingSpace
)
713 assert(m_xImpl
->m_xText
.is());
714 assert(m_xImpl
->m_xCursorAsRange
.is());
715 if (!m_xImpl
->m_xText
.is())
718 sal_Int32 nLen
= rChars
.size();
719 OUStringBuffer
sChars( nLen
);
721 for( sal_Int32 i
=0; i
< nLen
; i
++ )
723 sal_Unicode c
= rChars
[i
];
730 if( !rIgnoreLeadingSpace
)
731 sChars
.append( u
' ' );
732 rIgnoreLeadingSpace
= true;
735 rIgnoreLeadingSpace
= false;
740 m_xImpl
->m_xText
->insertString(m_xImpl
->m_xCursorAsRange
,
741 sChars
.makeStringAndClear(), false);
744 void XMLTextImportHelper::InsertControlCharacter( sal_Int16 nControl
)
746 assert(m_xImpl
->m_xText
.is());
747 assert(m_xImpl
->m_xCursorAsRange
.is());
748 if (m_xImpl
->m_xText
.is())
750 m_xImpl
->m_xText
->insertControlCharacter(
751 m_xImpl
->m_xCursorAsRange
, nControl
, false);
755 void XMLTextImportHelper::InsertTextContent(
756 Reference
< XTextContent
> const & xContent
)
758 assert(m_xImpl
->m_xText
.is());
759 assert(m_xImpl
->m_xCursorAsRange
.is());
760 if (m_xImpl
->m_xText
.is())
762 // note: this may throw IllegalArgumentException and callers handle it
763 m_xImpl
->m_xText
->insertTextContent( m_xImpl
->m_xCursorAsRange
, xContent
, false);
767 void XMLTextImportHelper::DeleteParagraph()
769 assert(m_xImpl
->m_xText
.is());
770 assert(m_xImpl
->m_xCursor
.is());
771 assert(m_xImpl
->m_xCursorAsRange
.is());
774 Reference
< XEnumerationAccess
> const xEnumAccess(
775 m_xImpl
->m_xCursor
, UNO_QUERY
);
776 if( xEnumAccess
.is() )
778 Reference
< XEnumeration
> xEnum(xEnumAccess
->createEnumeration());
779 SAL_WARN_IF(!xEnum
->hasMoreElements(), "xmloff.text",
780 "empty text enumeration");
781 if( xEnum
->hasMoreElements() )
783 Reference
< XComponent
> xComp( xEnum
->nextElement(), UNO_QUERY
);
794 if (m_xImpl
->m_xCursor
->goLeft( 1, true ))
796 m_xImpl
->m_xText
->insertString(m_xImpl
->m_xCursorAsRange
,
802 OUString
XMLTextImportHelper::ConvertStarFonts( const OUString
& rChars
,
803 const OUString
& rStyleName
,
806 SvXMLImport
& rImport
) const
808 OUStringBuffer
sChars( rChars
);
809 bool bConverted
= false;
810 for( sal_Int32 j
=0; j
<rChars
.getLength(); j
++ )
812 sal_Unicode c
= rChars
[j
];
813 if( c
>= 0xf000 && c
<= 0xf0ff )
815 if( (rFlags
& CONV_STAR_FONT_FLAGS_VALID
) == 0 )
817 XMLTextStyleContext
*pStyle
= nullptr;
818 XmlStyleFamily nFamily
= bPara
? XmlStyleFamily::TEXT_PARAGRAPH
819 : XmlStyleFamily::TEXT_TEXT
;
820 if (!rStyleName
.isEmpty() && m_xImpl
->m_xAutoStyles
.is())
822 const SvXMLStyleContext
* pTempStyle
=
823 m_xImpl
->m_xAutoStyles
->
824 FindStyleChildContext( nFamily
, rStyleName
,
826 pStyle
= const_cast<XMLTextStyleContext
*>( dynamic_cast< const XMLTextStyleContext
* >(pTempStyle
));
831 sal_Int32 nCount
= pStyle
->GetProperties_().size();
834 rtl::Reference
< SvXMLImportPropertyMapper
> xImpPrMap
=
835 m_xImpl
->m_xAutoStyles
->GetImportPropertyMapper(nFamily
);
838 rtl::Reference
<XMLPropertySetMapper
> rPropMapper
=
839 xImpPrMap
->getPropertySetMapper();
840 for( sal_Int32 i
=0; i
< nCount
; i
++ )
842 const XMLPropertyState
& rProp
= pStyle
->GetProperties_()[i
];
843 sal_Int32 nIdx
= rProp
.mnIndex
;
844 sal_uInt32 nContextId
= rPropMapper
->GetEntryContextId(nIdx
);
845 if( CTF_FONTFAMILYNAME
== nContextId
)
847 rFlags
&= ~(CONV_FROM_STAR_BATS
|CONV_FROM_STAR_MATH
);
849 rProp
.maValue
>>= sFontName
;
850 if( sFontName
.equalsIgnoreAsciiCase( "StarBats" ) )
851 rFlags
|= CONV_FROM_STAR_BATS
;
852 else if( sFontName
.equalsIgnoreAsciiCase( "StarMath" ) )
853 rFlags
|= CONV_FROM_STAR_MATH
;
862 rFlags
|= CONV_STAR_FONT_FLAGS_VALID
;
864 if( (rFlags
& CONV_FROM_STAR_BATS
) != 0 )
866 sChars
[j
] = rImport
.ConvStarBatsCharToStarSymbol( c
);
869 else if( (rFlags
& CONV_FROM_STAR_MATH
) != 0 )
871 sChars
[j
] = rImport
.ConvStarMathCharToStarSymbol( c
);
877 return bConverted
? sChars
.makeStringAndClear() : rChars
;
880 /* Helper method to determine, if a paragraph style has a list style (inclusive
881 an empty one) inherits a list style (inclusive an empty one) from one of its parents (#i69629#)
883 /* Apply special case, that found list style equals the chapter numbering, also
884 to the found list styles of the parent styles. (#i73973#)
886 static bool lcl_HasListStyle( const OUString
& sStyleName
,
887 const Reference
< XNameContainer
>& xParaStyles
,
888 SvXMLImport
const & rImport
,
889 const OUString
& sNumberingStyleName
,
890 std::u16string_view sOutlineStyleName
)
894 if ( !xParaStyles
->hasByName( sStyleName
) )
900 Reference
< XPropertyState
> xPropState( xParaStyles
->getByName( sStyleName
),
902 if ( !xPropState
.is() )
908 if ( xPropState
->getPropertyState( sNumberingStyleName
) == PropertyState_DIRECT_VALUE
)
912 // special case: the set list style equals the chapter numbering
913 Reference
< XPropertySet
> xPropSet( xPropState
, UNO_QUERY
);
917 xPropSet
->getPropertyValue( sNumberingStyleName
) >>= sListStyle
;
918 if ( !sListStyle
.isEmpty() &&
919 sListStyle
== sOutlineStyleName
)
927 // Tools.Outline settings lost on Save (#i77708#)
929 sal_Int32
nBuild( 0 );
930 // Don't use UPD for versioning: xmloff/source/text/txtstyli.cxx and txtimp.cxx (#i86058#)
931 const bool bBuildIdFound
= rImport
.getBuildIds( nUPD
, nBuild
);
932 // search list style at parent
933 Reference
<XStyle
> xStyle( xPropState
, UNO_QUERY
);
934 while ( xStyle
.is() )
936 OUString
aParentStyle( xStyle
->getParentStyle() );
937 if ( !aParentStyle
.isEmpty() )
940 rImport
.GetStyleDisplayName( XmlStyleFamily::TEXT_PARAGRAPH
,
943 if ( aParentStyle
.isEmpty() || !xParaStyles
->hasByName( aParentStyle
) )
945 // no list style found
950 xPropState
.set( xParaStyles
->getByName( aParentStyle
),
952 if ( !xPropState
.is() )
957 if ( xPropState
->getPropertyState( sNumberingStyleName
) == PropertyState_DIRECT_VALUE
)
961 // Special case: the found list style equals the chapter numbering (#i73973#)
962 Reference
< XPropertySet
> xPropSet( xPropState
, UNO_QUERY
);
966 xPropSet
->getPropertyValue( sNumberingStyleName
) >>= sListStyle
;
967 if ( !sListStyle
.isEmpty() &&
968 sListStyle
== sOutlineStyleName
)
972 // Special handling for text documents from OOo version prior OOo 2.4 (#i77708#)
973 /* Check explicitly on certain versions and on import of
974 text documents in OpenOffice.org file format (#i86058#)
976 else if ( sListStyle
.isEmpty() &&
977 ( rImport
.IsTextDocInOOoFileFormat() ||
979 ( ( nUPD
== 641 ) || ( nUPD
== 645 ) || // prior OOo 2.0
980 ( nUPD
== 680 && nBuild
<= 9238 ) ) ) ) ) // OOo 2.0 - OOo 2.3.1
989 // search list style at parent
990 Reference
<XStyle
> xParentStyle(xPropState
, UNO_QUERY
);
991 if (xStyle
== xParentStyle
)
996 xStyle
= std::move(xParentStyle
);
1005 OUString
XMLTextImportHelper::SetStyleAndAttrs(
1006 SvXMLImport
& rImport
,
1007 const Reference
< XTextCursor
>& rCursor
,
1008 const OUString
& rStyleName
,
1010 bool bOutlineLevelAttrFound
,
1011 sal_Int8 nOutlineLevel
,
1012 // Numberings/Bullets in table not visible after save/reload (#i80724#)
1014 bool bOutlineContentVisible
)
1016 static constexpr OUString s_NumberingRules
= u
"NumberingRules"_ustr
;
1017 static constexpr OUString s_NumberingIsNumber
= u
"NumberingIsNumber"_ustr
;
1018 static constexpr OUString s_NumberingLevel
= u
"NumberingLevel"_ustr
;
1019 static constexpr OUString s_ParaIsNumberingRestart
= u
"ParaIsNumberingRestart"_ustr
;
1020 static constexpr OUString s_NumberingStartValue
= u
"NumberingStartValue"_ustr
;
1021 static constexpr OUString s_PropNameListId
= u
"ListId"_ustr
;
1022 static constexpr OUString s_PageDescName
= u
"PageDescName"_ustr
;
1023 static constexpr OUString s_OutlineLevel
= u
"OutlineLevel"_ustr
;
1025 const XmlStyleFamily nFamily
= bPara
? XmlStyleFamily::TEXT_PARAGRAPH
1026 : XmlStyleFamily::TEXT_TEXT
;
1027 XMLTextStyleContext
*pStyle
= nullptr;
1028 OUString
sStyleName( rStyleName
);
1029 if (!sStyleName
.isEmpty() && m_xImpl
->m_xAutoStyles
.is())
1031 const SvXMLStyleContext
* pTempStyle
=
1032 m_xImpl
->m_xAutoStyles
->FindStyleChildContext( nFamily
, sStyleName
, true );
1033 pStyle
= const_cast<XMLTextStyleContext
*>(dynamic_cast< const XMLTextStyleContext
* >(pTempStyle
));
1036 sStyleName
= pStyle
->GetParentName();
1038 Reference
< XPropertySet
> xPropSet( rCursor
, UNO_QUERY
);
1039 Reference
< XPropertySetInfo
> xPropSetInfo(
1040 xPropSet
->getPropertySetInfo());
1043 if( !sStyleName
.isEmpty() )
1045 sStyleName
= rImport
.GetStyleDisplayName( nFamily
, sStyleName
);
1046 const OUString rPropName
= bPara
? u
"ParaStyleName"_ustr
: u
"CharStyleName"_ustr
;
1047 const Reference
< XNameContainer
> & rStyles
= bPara
1048 ? m_xImpl
->m_xParaStyles
1049 : m_xImpl
->m_xTextStyles
;
1051 xPropSetInfo
->hasPropertyByName( rPropName
) &&
1052 rStyles
->hasByName( sStyleName
) )
1054 xPropSet
->setPropertyValue( rPropName
, Any(sStyleName
) );
1060 /* The outline level needs to be only applied as list level, if the heading
1061 is not inside a list and if it by default applies the outline style. (#i70748#)
1063 bool bApplyOutlineLevelAsListLevel( false );
1064 // Numberings/Bullets in table not visible after save/reload (#i80724#)
1065 if (bSetListAttrs
&& bPara
1066 && xPropSetInfo
->hasPropertyByName( s_NumberingRules
))
1068 // Set numbering rules
1069 Reference
< XIndexReplace
> const xNumRules(
1070 xPropSet
->getPropertyValue(s_NumberingRules
), UNO_QUERY
);
1072 XMLTextListBlockContext
* pListBlock(nullptr);
1073 XMLTextListItemContext
* pListItem(nullptr);
1074 XMLNumberedParaContext
* pNumberedParagraph(nullptr);
1075 GetTextListHelper().ListContextTop(
1076 pListBlock
, pListItem
, pNumberedParagraph
);
1078 assert(!(pListBlock
&& pNumberedParagraph
) && "XMLTextImportHelper::"
1079 "SetStyleAndAttrs: both list and numbered-paragraph???");
1081 Reference
< XIndexReplace
> xNewNumRules
;
1082 sal_Int8
nLevel(-1);
1084 sal_Int16
nStartValue(-1);
1085 bool bNumberingIsNumber(true);
1086 // Assure that list style of automatic paragraph style is applied at paragraph. (#i101349#)
1087 bool bApplyNumRules(pStyle
&& pStyle
->IsListStyleSet());
1092 bNumberingIsNumber
= false; // list-header
1095 // consider text:style-override property of <text:list-item>
1097 (pListItem
!= nullptr && pListItem
->HasNumRulesOverride())
1098 ? pListItem
->GetNumRulesOverride()
1099 : pListBlock
->GetNumRules() );
1100 nLevel
= static_cast<sal_Int8
>(pListBlock
->GetLevel());
1102 if ( pListItem
&& pListItem
->HasStartValue() ) {
1103 nStartValue
= pListItem
->GetStartValue();
1106 // Inconsistent behavior regarding lists (#i92811#)
1107 sListId
= m_xImpl
->m_xTextListsHelper
->GetListIdForListBlock(
1110 else if (pNumberedParagraph
)
1112 xNewNumRules
.set(pNumberedParagraph
->GetNumRules());
1113 nLevel
= static_cast<sal_Int8
>(pNumberedParagraph
->GetLevel());
1114 sListId
= pNumberedParagraph
->GetListId();
1115 nStartValue
= pNumberedParagraph
->GetStartValue();
1119 if (pListBlock
|| pNumberedParagraph
)
1121 if (!bApplyNumRules
)
1123 bool bSameNumRules
= xNewNumRules
== xNumRules
;
1124 if( !bSameNumRules
&& xNewNumRules
.is() && xNumRules
.is() )
1126 // If the interface pointers are different, then this does
1127 // not mean that the num rules are different. Further tests
1128 // are required then. However, if only one num rule is
1129 // set, no tests are required of course.
1130 Reference
< XNamed
> xNewNamed( xNewNumRules
, UNO_QUERY
);
1131 Reference
< XNamed
> xNamed( xNumRules
, UNO_QUERY
);
1132 if( xNewNamed
.is() && xNamed
.is() )
1134 bSameNumRules
= xNewNamed
->getName() == xNamed
->getName();
1138 Reference
< XAnyCompare
> xNumRuleCompare( xNumRules
, UNO_QUERY
);
1139 if( xNumRuleCompare
.is() )
1141 bSameNumRules
= (xNumRuleCompare
->compare( Any(xNumRules
), Any(xNewNumRules
) ) == 0);
1145 bApplyNumRules
= !bSameNumRules
;
1148 if ( bApplyNumRules
)
1150 // #102607# This may except when xNewNumRules contains
1151 // a Writer-NumRule-Implementation bug gets applied to
1152 // a shape. Since this may occur inside a document
1153 // (e.g. when edited), this must be handled
1157 xPropSet
->setPropertyValue(
1158 s_NumberingRules
, Any(xNewNumRules
) );
1160 catch(const Exception
&)
1162 ; // I would really like to use a warning here,
1163 // but I can't access the XMLErrorHandler from
1168 if (!bNumberingIsNumber
&&
1169 xPropSetInfo
->hasPropertyByName(s_NumberingIsNumber
))
1171 xPropSet
->setPropertyValue(s_NumberingIsNumber
, Any(false));
1174 xPropSet
->setPropertyValue( s_NumberingLevel
, Any(nLevel
) );
1176 if( pListBlock
&& pListBlock
->IsRestartNumbering() )
1178 // TODO: property missing
1179 if (xPropSetInfo
->hasPropertyByName(s_ParaIsNumberingRestart
))
1181 xPropSet
->setPropertyValue(s_ParaIsNumberingRestart
,
1184 pListBlock
->ResetRestartNumbering();
1187 if ( 0 <= nStartValue
&&
1188 xPropSetInfo
->hasPropertyByName(s_NumberingStartValue
))
1190 xPropSet
->setPropertyValue(s_NumberingStartValue
,
1194 if (xPropSetInfo
->hasPropertyByName(s_PropNameListId
))
1196 if (!sListId
.isEmpty()) {
1197 xPropSet
->setPropertyValue(s_PropNameListId
,
1202 GetTextListHelper().SetListItem( nullptr );
1206 /* If the paragraph is not in a list but its style, remove it from
1207 the list. Do not remove it, if the list of the style is
1208 the chapter numbering rule.
1210 if( xNumRules
.is() )
1212 bool bRemove( true );
1213 // Special handling for document from OOo 2.x (#i70748#)
1214 sal_Int32
nUPD( 0 );
1215 sal_Int32
nBuild( 0 );
1216 const bool bBuildIdFound
= rImport
.getBuildIds( nUPD
, nBuild
);
1217 if ( ( bBuildIdFound
&& nUPD
== 680 ) ||
1218 !pStyle
|| !pStyle
->IsListStyleSet() )
1220 if (m_xImpl
->m_xChapterNumbering
.is())
1222 Reference
< XNamed
> xNumNamed( xNumRules
, UNO_QUERY
);
1223 Reference
< XNamed
> const xChapterNumNamed (
1224 m_xImpl
->m_xChapterNumbering
, UNO_QUERY
);
1225 if ( xNumNamed
.is() && xChapterNumNamed
.is() &&
1226 xNumNamed
->getName() == xChapterNumNamed
->getName() )
1229 // RFE: inserting headings into text documents (#i70748#)
1230 bApplyOutlineLevelAsListLevel
= true;
1236 SAL_INFO_IF(!pStyle
->GetListStyle().isEmpty(),
1238 "automatic paragraph style with list style name, but paragraph not in list???");
1242 xPropSet
->setPropertyValue( s_NumberingRules
, Any() );
1248 // hard paragraph properties
1251 pStyle
->FillPropertySet( xPropSet
);
1252 if( bPara
&& pStyle
->HasMasterPageName() &&
1253 xPropSetInfo
->hasPropertyByName(s_PageDescName
))
1255 OUString
sDisplayName(
1256 rImport
.GetStyleDisplayName(
1257 XmlStyleFamily::MASTER_PAGE
,
1258 pStyle
->GetMasterPageName()) );
1259 if( sDisplayName
.isEmpty() ||
1260 (m_xImpl
->m_xPageStyles
.is() &&
1261 m_xImpl
->m_xPageStyles
->hasByName( sDisplayName
)))
1263 xPropSet
->setPropertyValue(s_PageDescName
,
1267 if( bPara
&& !pStyle
->GetDropCapStyleName().isEmpty() &&
1268 m_xImpl
->m_xTextStyles
.is())
1270 OUString
sDisplayName(
1271 rImport
.GetStyleDisplayName(
1272 XmlStyleFamily::TEXT_TEXT
,
1273 pStyle
->GetDropCapStyleName()) );
1274 if (m_xImpl
->m_xTextStyles
->hasByName(sDisplayName
) &&
1275 xPropSetInfo
->hasPropertyByName(u
"DropCapCharStyleName"_ustr
))
1277 xPropSet
->setPropertyValue(u
"DropCapCharStyleName"_ustr
, Any(sDisplayName
));
1281 // combined characters special treatment
1282 if (!bPara
&& pStyle
->HasCombinedCharactersLetter())
1284 // insert combined characters text field
1285 if (m_xImpl
->m_xServiceFactory
.is())
1287 uno::Reference
<beans::XPropertySet
> const xTmp(
1288 m_xImpl
->m_xServiceFactory
->createInstance(
1289 u
"com.sun.star.text.TextField.CombinedCharacters"_ustr
), UNO_QUERY
);
1292 // fix cursor if larger than possible for
1293 // combined characters field
1294 if (rCursor
->getString().getLength() >
1295 MAX_COMBINED_CHARACTERS
)
1297 rCursor
->gotoRange(rCursor
->getStart(), false);
1298 rCursor
->goRight(MAX_COMBINED_CHARACTERS
, true);
1301 // set field value (the combined character string)
1302 xTmp
->setPropertyValue(u
"Content"_ustr
,
1303 Any(rCursor
->getString()));
1305 // insert the field over it's original text
1306 Reference
<XTextContent
> xTextContent(xTmp
, UNO_QUERY
);
1307 if (m_xImpl
->m_xText
.is() && rCursor
.is())
1309 // #i107225# the combined characters need to be inserted first
1310 // the selected text has to be removed afterwards
1311 m_xImpl
->m_xText
->insertTextContent( rCursor
->getStart(), xTextContent
, true );
1313 if( !rCursor
->getString().isEmpty() )
1317 uno::Reference
< text::XTextCursor
> xCrsr
= rCursor
->getText()->createTextCursorByRange( rCursor
->getStart() );
1318 xCrsr
->goLeft( 1, true );
1319 uno::Reference
< beans::XPropertySet
> xCrsrProperties( xCrsr
, uno::UNO_QUERY_THROW
);
1320 //the hard properties of the removed text need to be applied to the combined characters field
1321 pStyle
->FillPropertySet( xCrsrProperties
);
1322 xCrsr
->collapseToEnd();
1323 xCrsr
->gotoRange( rCursor
->getEnd(), true );
1324 xCrsr
->setString( OUString() );
1326 catch(const uno::Exception
&)
1336 // outline level; set after list style has been set
1337 // Complete re-worked and corrected: (#i53198#)
1338 // - set outline level at paragraph
1339 // - set numbering level at paragraph, if none is already set
1340 // - assure that style is marked as an outline style for the corresponding
1342 // - DO NOT set type of numbering rule to outline.
1343 // - DO NOT set numbering rule directly at the paragraph.
1345 // Some minor rework and adjust access to paragraph styles (#i70748#)
1348 // Headings not numbered anymore in 3.1 (#i103817#)
1349 sal_Int16 nCurrentOutlineLevelInheritedFromParagraphStyle
= 0;
1350 const bool bHasOutlineLevelProp(
1351 xPropSetInfo
->hasPropertyByName(s_OutlineLevel
));
1352 if ( bHasOutlineLevelProp
)
1354 xPropSet
->getPropertyValue(s_OutlineLevel
)
1355 >>= nCurrentOutlineLevelInheritedFromParagraphStyle
;
1357 if ( nOutlineLevel
> 0 )
1359 if ( bHasOutlineLevelProp
)
1361 // In case that the value equals the value of its paragraph style
1362 // attribute outline level, the paragraph attribute value is left unset
1363 if ( nCurrentOutlineLevelInheritedFromParagraphStyle
!= nOutlineLevel
)
1365 xPropSet
->setPropertyValue( s_OutlineLevel
,
1366 Any( static_cast<sal_Int16
>(nOutlineLevel
) ) );
1369 if (!bOutlineContentVisible
)
1371 uno::Sequence
<beans::PropertyValue
> aGrabBag
;
1372 xPropSet
->getPropertyValue(u
"ParaInteropGrabBag"_ustr
) >>= aGrabBag
;
1373 sal_Int32 length
= aGrabBag
.getLength();
1374 aGrabBag
.realloc(length
+ 1);
1375 auto pGrabBag
= aGrabBag
.getArray();
1376 pGrabBag
[length
].Name
= "OutlineContentVisibleAttr";
1377 pGrabBag
[length
].Value
<<= bool(bOutlineContentVisible
);
1378 xPropSet
->setPropertyValue(u
"ParaInteropGrabBag"_ustr
, uno::Any(aGrabBag
));
1380 // RFE: inserting headings into text documents (#i70748#)
1381 if ( bApplyOutlineLevelAsListLevel
)
1383 sal_Int16 nNumLevel
= -1;
1384 xPropSet
->getPropertyValue( s_NumberingLevel
) >>= nNumLevel
;
1385 if ( nNumLevel
== -1 ||
1386 nNumLevel
!= (nOutlineLevel
- 1) )
1388 xPropSet
->setPropertyValue( s_NumberingLevel
,
1389 Any( static_cast<sal_Int8
>(nOutlineLevel
- 1) ) );
1392 /* Correction: (#i69629#)
1393 - for text document from version OOo 2.0.4/SO 8 PU4 and earlier
1394 the paragraph style of a heading should be assigned to the
1395 corresponding list level of the outline style.
1396 - for other text documents the paragraph style of a heading is only
1397 a candidate for an assignment to the list level of the outline
1398 style, if it has no direct list style property and (if exists) the
1399 automatic paragraph style has also no direct list style set.
1401 if (m_xImpl
->m_xParaStyles
.is() && m_xImpl
->m_xParaStyles
->hasByName(sStyleName
))
1403 bool bOutlineStyleCandidate( false );
1405 sal_Int32
nUPD( 0 );
1406 sal_Int32
nBuild( 0 );
1407 const bool bBuildIdFound
= rImport
.getBuildIds( nUPD
, nBuild
);
1408 // Lost outline numbering in master document (#i73509#)
1409 // Check explicitly on certain versions (#i86058#)
1410 if ( rImport
.IsTextDocInOOoFileFormat() ||
1412 ( nUPD
== 645 || nUPD
== 641 ) ) )
1414 bOutlineStyleCandidate
= true;
1416 else if ( nUPD
== 680 && nBuild
<= 9073 ) /* BuildId of OOo 2.0.4/SO8 PU4 */
1418 bOutlineStyleCandidate
= bOutlineLevelAttrFound
;
1420 if ( bOutlineStyleCandidate
)
1422 AddOutlineStyleCandidate( nOutlineLevel
, sStyleName
);
1424 // Assure that heading applies the outline style (#i103817#)
1425 if ( ( !pStyle
|| !pStyle
->IsListStyleSet() ) &&
1426 !bOutlineStyleCandidate
&&
1427 m_xImpl
->m_xChapterNumbering
.is())
1429 if ( !lcl_HasListStyle( sStyleName
,
1430 m_xImpl
->m_xParaStyles
, GetXMLImport(),
1431 u
"NumberingStyleName"_ustr
,
1434 // heading not in a list --> apply outline style
1435 xPropSet
->setPropertyValue( s_NumberingRules
,
1436 Any(m_xImpl
->m_xChapterNumbering
) );
1437 xPropSet
->setPropertyValue( s_NumberingLevel
,
1438 Any(static_cast<sal_Int8
>(nOutlineLevel
- 1)));
1443 //handle for text:p,if the paragraphstyle outlinelevel is set to[1~10]
1444 else if( bHasOutlineLevelProp
)
1446 if ( nCurrentOutlineLevelInheritedFromParagraphStyle
!= 0 )
1448 xPropSet
->setPropertyValue(s_OutlineLevel
,
1449 Any( sal_Int16(0) ));
1457 void XMLTextImportHelper::FindOutlineStyleName( OUString
& rStyleName
,
1458 sal_Int8 nOutlineLevel
)
1460 // style name empty?
1461 if( !rStyleName
.isEmpty() )
1464 // Empty? Then we need o do stuff. Let's do error checking first.
1465 if (m_xImpl
->m_xChapterNumbering
.is() &&
1466 ( nOutlineLevel
> 0 ) &&
1467 (nOutlineLevel
<= m_xImpl
->m_xChapterNumbering
->getCount()))
1469 nOutlineLevel
--; // for the remainder, the level's are 0-based
1471 // empty style name: look-up previously used name
1473 // if we don't have a previously used name, we'll use the default
1474 m_xImpl
->InitOutlineStylesCandidates();
1475 if (m_xImpl
->m_xOutlineStylesCandidates
[nOutlineLevel
].empty())
1477 // no other name used previously? Then use default
1479 // iterate over property value sequence to find the style name
1480 Sequence
<PropertyValue
> aProperties
;
1481 m_xImpl
->m_xChapterNumbering
->getByIndex( nOutlineLevel
)
1483 auto pProp
= std::find_if(std::cbegin(aProperties
), std::cend(aProperties
),
1484 [](const PropertyValue
& rProp
) { return rProp
.Name
== "HeadingStyleName"; });
1485 if (pProp
!= std::cend(aProperties
))
1487 OUString aOutlineStyle
;
1488 pProp
->Value
>>= aOutlineStyle
;
1489 m_xImpl
->m_xOutlineStylesCandidates
[nOutlineLevel
]
1490 .push_back( aOutlineStyle
);
1494 // finally, we'll use the previously used style name for this
1495 // format (or the default we've just put into that style)
1496 // take last added one (#i71249#)
1498 m_xImpl
->m_xOutlineStylesCandidates
[nOutlineLevel
].back();
1500 // else: nothing we can do, so we'll leave it empty
1501 // else: we already had a style name, so we let it pass.
1504 void XMLTextImportHelper::AddOutlineStyleCandidate( const sal_Int8 nOutlineLevel
,
1505 const OUString
& rStyleName
)
1507 if (!rStyleName
.isEmpty()
1508 && m_xImpl
->m_xChapterNumbering
.is()
1509 && (nOutlineLevel
> 0)
1510 && (nOutlineLevel
<= m_xImpl
->m_xChapterNumbering
->getCount()))
1512 m_xImpl
->InitOutlineStylesCandidates();
1513 m_xImpl
->m_xOutlineStylesCandidates
[nOutlineLevel
-1].push_back(
1518 void XMLTextImportHelper::SetOutlineStyles( bool bSetEmptyLevels
)
1520 if (!(m_xImpl
->m_xOutlineStylesCandidates
!= nullptr || bSetEmptyLevels
) ||
1521 !m_xImpl
->m_xChapterNumbering
.is() ||
1525 bool bChooseLastOne( false );
1527 if ( GetXMLImport().IsTextDocInOOoFileFormat() )
1529 bChooseLastOne
= true;
1533 sal_Int32
nUPD( 0 );
1534 sal_Int32
nBuild( 0 );
1535 if ( GetXMLImport().getBuildIds( nUPD
, nBuild
) )
1537 // check explicitly on certain versions
1538 bChooseLastOne
= ( nUPD
== 641 ) || ( nUPD
== 645 ) || // prior OOo 2.0
1539 ( nUPD
== 680 && nBuild
<= 9073 ); // OOo 2.0 - OOo 2.0.4
1544 OUString sOutlineStyleName
;
1546 Reference
<XPropertySet
> xChapterNumRule(
1547 m_xImpl
->m_xChapterNumbering
, UNO_QUERY
);
1548 xChapterNumRule
->getPropertyValue(u
"Name"_ustr
) >>= sOutlineStyleName
;
1551 const sal_Int32 nCount
= m_xImpl
->m_xChapterNumbering
->getCount();
1552 /* First collect all paragraph styles chosen for assignment to each
1553 list level of the outline style, then perform the intrinsic assignment.
1554 Reason: The assignment of a certain paragraph style to a list level
1555 of the outline style causes side effects on the children
1556 paragraph styles in Writer. (#i106218#)
1558 ::std::vector
<OUString
> sChosenStyles(nCount
);
1559 for( sal_Int32 i
=0; i
< nCount
; ++i
)
1561 if ( bSetEmptyLevels
||
1562 (m_xImpl
->m_xOutlineStylesCandidates
&&
1563 !m_xImpl
->m_xOutlineStylesCandidates
[i
].empty()))
1565 // determine, which candidate is one to be assigned to the list
1566 // level of the outline style
1567 if (m_xImpl
->m_xOutlineStylesCandidates
&&
1568 !m_xImpl
->m_xOutlineStylesCandidates
[i
].empty())
1570 if ( bChooseLastOne
)
1573 m_xImpl
->m_xOutlineStylesCandidates
[i
].back();
1578 j
< m_xImpl
->m_xOutlineStylesCandidates
[i
].size();
1581 if (!lcl_HasListStyle(
1582 m_xImpl
->m_xOutlineStylesCandidates
[i
][j
],
1583 m_xImpl
->m_xParaStyles
,
1585 u
"NumberingStyleName"_ustr
,
1589 m_xImpl
->m_xOutlineStylesCandidates
[i
][j
];
1597 // Trashed outline numbering in ODF 1.1 text document created by OOo 3.x (#i106218#)
1598 Sequence
< PropertyValue
> aProps( 1 );
1599 PropertyValue
*pProps
= aProps
.getArray();
1600 pProps
->Name
= "HeadingStyleName";
1601 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
1603 // Paragraph style assignments in Outline of template lost from second level on (#i107610#)
1604 if ( bSetEmptyLevels
|| !sChosenStyles
[i
].isEmpty() )
1606 pProps
->Value
<<= sChosenStyles
[i
];
1607 m_xImpl
->m_xChapterNumbering
->replaceByIndex(i
,
1614 void XMLTextImportHelper::SetHyperlink(
1615 SvXMLImport
const & rImport
,
1616 const Reference
< XTextCursor
>& rCursor
,
1617 const OUString
& rHRef
,
1618 const OUString
& rName
,
1619 const OUString
& rTargetFrameName
,
1620 const OUString
& rStyleName
,
1621 const OUString
& rVisitedStyleName
,
1622 XMLEventsImportContext
* pEvents
)
1624 static constexpr OUString s_HyperLinkURL
= u
"HyperLinkURL"_ustr
;
1625 static constexpr OUString s_HyperLinkName
= u
"HyperLinkName"_ustr
;
1626 static constexpr OUString s_HyperLinkTarget
= u
"HyperLinkTarget"_ustr
;
1627 static constexpr OUString s_UnvisitedCharStyleName
= u
"UnvisitedCharStyleName"_ustr
;
1628 static constexpr OUString s_VisitedCharStyleName
= u
"VisitedCharStyleName"_ustr
;
1629 static constexpr OUString s_HyperLinkEvents
= u
"HyperLinkEvents"_ustr
;
1631 Reference
< XPropertySet
> xPropSet( rCursor
, UNO_QUERY
);
1632 Reference
< XPropertySetInfo
> xPropSetInfo(
1633 xPropSet
->getPropertySetInfo());
1634 if (!xPropSetInfo
.is() || !xPropSetInfo
->hasPropertyByName(s_HyperLinkURL
))
1637 xPropSet
->setPropertyValue(s_HyperLinkURL
, Any(rHRef
));
1639 if (xPropSetInfo
->hasPropertyByName(s_HyperLinkName
))
1641 xPropSet
->setPropertyValue(s_HyperLinkName
, Any(rName
));
1644 if (xPropSetInfo
->hasPropertyByName(s_HyperLinkTarget
))
1646 xPropSet
->setPropertyValue(s_HyperLinkTarget
,
1647 Any(rTargetFrameName
));
1650 if ( (pEvents
!= nullptr) &&
1651 xPropSetInfo
->hasPropertyByName(s_HyperLinkEvents
))
1653 // The API treats events at hyperlinks differently from most
1654 // other properties: You have to set a name replace with the
1655 // events in it. The easiest way to do this is to 1) get
1656 // events, 2) set new ones, and 3) then put events back.
1657 uno::Reference
<XNameReplace
> const xReplace(
1658 xPropSet
->getPropertyValue(s_HyperLinkEvents
), UNO_QUERY
);
1662 pEvents
->SetEvents(xReplace
);
1665 xPropSet
->setPropertyValue(s_HyperLinkEvents
, Any(xReplace
));
1669 if (!m_xImpl
->m_xTextStyles
.is())
1672 OUString
sDisplayName(
1673 rImport
.GetStyleDisplayName(
1674 XmlStyleFamily::TEXT_TEXT
, rStyleName
) );
1675 if( !sDisplayName
.isEmpty() &&
1676 xPropSetInfo
->hasPropertyByName(s_UnvisitedCharStyleName
) &&
1677 m_xImpl
->m_xTextStyles
->hasByName(sDisplayName
))
1679 xPropSet
->setPropertyValue(s_UnvisitedCharStyleName
,
1684 rImport
.GetStyleDisplayName(
1685 XmlStyleFamily::TEXT_TEXT
, rVisitedStyleName
);
1686 if( !sDisplayName
.isEmpty() &&
1687 xPropSetInfo
->hasPropertyByName(s_VisitedCharStyleName
) &&
1688 m_xImpl
->m_xTextStyles
->hasByName(sDisplayName
))
1690 xPropSet
->setPropertyValue(s_VisitedCharStyleName
,
1695 void XMLTextImportHelper::SetRuby(
1696 SvXMLImport
const & rImport
,
1697 const Reference
< XTextCursor
>& rCursor
,
1698 const OUString
& rStyleName
,
1699 const OUString
& rTextStyleName
,
1700 const OUString
& rText
)
1702 Reference
<XPropertySet
> xPropSet(rCursor
, UNO_QUERY
);
1704 OUString
sRubyText(u
"RubyText"_ustr
);
1706 // if we have one Ruby property, we assume all of them are present
1707 if (!xPropSet
.is() ||
1708 !xPropSet
->getPropertySetInfo()->hasPropertyByName( sRubyText
))
1712 xPropSet
->setPropertyValue(sRubyText
, Any(rText
));
1714 // the ruby style (ruby-adjust)
1715 if (!rStyleName
.isEmpty() && m_xImpl
->m_xAutoStyles
.is())
1717 const SvXMLStyleContext
* pTempStyle
=
1718 m_xImpl
->m_xAutoStyles
->FindStyleChildContext( XmlStyleFamily::TEXT_RUBY
,
1720 XMLPropStyleContext
*pStyle
= const_cast<XMLPropStyleContext
*>(dynamic_cast< const XMLPropStyleContext
* >(pTempStyle
));
1722 if (nullptr != pStyle
)
1723 pStyle
->FillPropertySet( xPropSet
);
1726 // the ruby text character style
1727 if (m_xImpl
->m_xTextStyles
.is())
1729 OUString
sDisplayName(
1730 rImport
.GetStyleDisplayName(
1731 XmlStyleFamily::TEXT_TEXT
, rTextStyleName
) );
1732 if( (!sDisplayName
.isEmpty()) &&
1733 m_xImpl
->m_xTextStyles
->hasByName( sDisplayName
))
1735 xPropSet
->setPropertyValue(u
"RubyCharStyleName"_ustr
, Any(sDisplayName
));
1740 void XMLTextImportHelper::SetAutoStyles( SvXMLStylesContext
*pStyles
)
1742 m_xImpl
->m_xAutoStyles
= pStyles
;
1745 SvXMLImportContext
*XMLTextImportHelper::CreateTextChildContext(
1746 SvXMLImport
& rImport
,
1748 const Reference
< XFastAttributeList
> & xAttrList
,
1751 SvXMLImportContext
*pContext
= nullptr;
1753 bool bContent
= true;
1756 case XML_ELEMENT(TEXT
, XML_H
):
1757 case XML_ELEMENT(TEXT
, XML_P
):
1758 case XML_ELEMENT(LO_EXT
, XML_P
):
1759 pContext
= new XMLParaContext( rImport
,
1762 if (m_xImpl
->m_bProgress
&& XMLTextType::Shape
!= eType
)
1764 rImport
.GetProgressBarHelper()->Increment();
1768 case XML_ELEMENT(TEXT
, XML_NUMBERED_PARAGRAPH
):
1769 pContext
= new XMLNumberedParaContext(
1770 rImport
, nElement
, xAttrList
);
1772 case XML_ELEMENT(TEXT
, XML_LIST
):
1773 pContext
= new XMLTextListBlockContext( rImport
, *this,
1776 case XML_ELEMENT(TABLE
,XML_TABLE
):
1777 case XML_ELEMENT(LO_EXT
, XML_TABLE
):
1778 if( XMLTextType::Body
== eType
||
1779 XMLTextType::TextBox
== eType
||
1780 XMLTextType::Section
== eType
||
1781 XMLTextType::HeaderFooter
== eType
||
1782 XMLTextType::ChangedRegion
== eType
||
1783 XMLTextType::Cell
== eType
)
1784 pContext
= CreateTableChildContext( rImport
, nElement
, xAttrList
);
1786 case XML_ELEMENT(TEXT
, XML_SEQUENCE_DECLS
):
1787 if ((XMLTextType::Body
== eType
&& m_xImpl
->m_bBodyContentStarted
) ||
1788 XMLTextType::HeaderFooter
== eType
)
1790 pContext
= new XMLVariableDeclsImportContext(
1791 rImport
, *this, VarTypeSequence
);
1795 case XML_ELEMENT(TEXT
, XML_VARIABLE_DECLS
):
1796 if ((XMLTextType::Body
== eType
&& m_xImpl
->m_bBodyContentStarted
) ||
1797 XMLTextType::HeaderFooter
== eType
)
1799 pContext
= new XMLVariableDeclsImportContext(
1800 rImport
, *this, VarTypeSimple
);
1804 case XML_ELEMENT(TEXT
, XML_USER_FIELD_DECLS
):
1805 if ((XMLTextType::Body
== eType
&& m_xImpl
->m_bBodyContentStarted
)||
1806 XMLTextType::HeaderFooter
== eType
)
1808 pContext
= new XMLVariableDeclsImportContext(
1809 rImport
, *this, VarTypeUserField
);
1813 case XML_ELEMENT(TEXT
, XML_DDE_CONNECTION_DECLS
):
1814 if ((XMLTextType::Body
== eType
&& m_xImpl
->m_bBodyContentStarted
) ||
1815 XMLTextType::HeaderFooter
== eType
)
1817 pContext
= new XMLDdeFieldDeclsImportContext(rImport
);
1821 case XML_ELEMENT(DRAW
, XML_FRAME
):
1822 if ((XMLTextType::Body
== eType
&& m_xImpl
->m_bBodyContentStarted
) ||
1823 XMLTextType::TextBox
== eType
||
1824 XMLTextType::ChangedRegion
== eType
)
1826 TextContentAnchorType eAnchorType
=
1827 XMLTextType::TextBox
== eType
? TextContentAnchorType_AT_FRAME
1828 : TextContentAnchorType_AT_PAGE
;
1829 pContext
= new XMLTextFrameContext( rImport
, xAttrList
,
1834 case XML_ELEMENT(DRAW
, XML_A
):
1835 if ((XMLTextType::Body
== eType
&& m_xImpl
->m_bBodyContentStarted
) ||
1836 XMLTextType::TextBox
== eType
||
1837 XMLTextType::ChangedRegion
== eType
)
1839 TextContentAnchorType eAnchorType
=
1840 XMLTextType::TextBox
== eType
? TextContentAnchorType_AT_FRAME
1841 : TextContentAnchorType_AT_PAGE
;
1842 pContext
= new XMLTextFrameHyperlinkContext( rImport
, nElement
,
1848 case XML_ELEMENT(TEXT
, XML_INDEX_TITLE
):
1849 case XML_ELEMENT(TEXT
, XML_SECTION
):
1850 pContext
= new XMLSectionImportContext( rImport
);
1852 case XML_ELEMENT(TEXT
, XML_TABLE_OF_CONTENT
):
1853 case XML_ELEMENT(TEXT
, XML_OBJECT_INDEX
):
1854 case XML_ELEMENT(TEXT
, XML_TABLE_INDEX
):
1855 case XML_ELEMENT(TEXT
, XML_ILLUSTRATION_INDEX
):
1856 case XML_ELEMENT(TEXT
, XML_USER_INDEX
):
1857 case XML_ELEMENT(TEXT
, XML_ALPHABETICAL_INDEX
):
1858 case XML_ELEMENT(TEXT
, XML_BIBLIOGRAPHY
):
1859 if( XMLTextType::Shape
!= eType
)
1860 pContext
= new XMLIndexTOCContext( rImport
, nElement
);
1862 case XML_ELEMENT(TEXT
, XML_TRACKED_CHANGES
):
1863 pContext
= new XMLTrackedChangesImportContext( rImport
);
1866 case XML_ELEMENT(TEXT
, XML_CHANGE
):
1867 case XML_ELEMENT(TEXT
, XML_CHANGE_START
):
1868 case XML_ELEMENT(TEXT
, XML_CHANGE_END
):
1869 pContext
= new XMLChangeImportContext(
1871 ((nElement
== XML_ELEMENT(TEXT
, XML_CHANGE_END
))
1872 ? XMLChangeImportContext::Element::END
1873 : (nElement
== XML_ELEMENT(TEXT
, XML_CHANGE_START
))
1874 ? XMLChangeImportContext::Element::START
1875 : XMLChangeImportContext::Element::POINT
),
1878 case XML_ELEMENT(OFFICE
, XML_FORMS
):
1879 pContext
= xmloff::OFormLayerXMLImport::createOfficeFormsContext(rImport
);
1882 case XML_ELEMENT(TEXT
, XML_ALPHABETICAL_INDEX_AUTO_MARK_FILE
):
1883 if( XMLTextType::Body
== eType
)
1885 pContext
= new XMLAutoMarkFileContext(rImport
);
1889 case XML_ELEMENT(TABLE
, XML_CALCULATION_SETTINGS
):
1890 pContext
= new XMLCalculationSettingsContext ( rImport
, nElement
, xAttrList
);
1895 if ((XMLTextType::Body
== eType
&& m_xImpl
->m_bBodyContentStarted
) ||
1896 XMLTextType::TextBox
== eType
||
1897 XMLTextType::ChangedRegion
== eType
)
1899 Reference
< XShapes
> xShapes
;
1900 pContext
= XMLShapeImportHelper::CreateGroupChildContext(
1901 rImport
, nElement
, xAttrList
, xShapes
);
1906 // handle open redlines
1907 if ( (XML_ELEMENT(TEXT
, XML_CHANGE
) != nElement
) &&
1908 (XML_ELEMENT(TEXT
, XML_CHANGE_END
) != nElement
) &&
1909 (XML_ELEMENT(TEXT
, XML_CHANGE_START
) != nElement
) )
1911 // ResetOpenRedlineId();
1914 if( XMLTextType::Body
== eType
&& bContent
)
1916 m_xImpl
->m_bBodyContentStarted
= false;
1919 if( nElement
!= XML_ELEMENT(DRAW
, XML_FRAME
) )
1920 ClearLastImportedTextFrameName();
1923 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement
);
1928 SvXMLImportContext
*XMLTextImportHelper::CreateTableChildContext(
1930 sal_Int32
/*nElement*/,
1931 const Reference
< XFastAttributeList
> & )
1936 /// get data style key for use with NumberFormat property
1937 sal_Int32
XMLTextImportHelper::GetDataStyleKey(const OUString
& sStyleName
,
1938 bool* pIsSystemLanguage
)
1940 if (!m_xImpl
->m_xAutoStyles
.is())
1943 const SvXMLStyleContext
* pStyle
=
1944 m_xImpl
->m_xAutoStyles
->FindStyleChildContext( XmlStyleFamily::DATA_STYLE
,
1947 // get appropriate context
1950 // first check if it's an Impress and draw only number format
1951 // this is needed since it's also a SvXMLNumFormatContext,
1952 // that was needed to support them for controls in impress/draw also
1953 const SdXMLNumberFormatImportContext
* pSdNumStyle
= dynamic_cast<const SdXMLNumberFormatImportContext
*>( pStyle
);
1956 return pSdNumStyle
->GetDrawKey();
1960 SvXMLNumFormatContext
* pNumStyle
= const_cast<SvXMLNumFormatContext
*>(dynamic_cast<const SvXMLNumFormatContext
*>( pStyle
) );
1963 if( pIsSystemLanguage
!= nullptr )
1964 *pIsSystemLanguage
= pNumStyle
->IsSystemLanguage();
1967 return pNumStyle
->GetKey();
1973 const SvxXMLListStyleContext
*XMLTextImportHelper::FindAutoListStyle( const OUString
& rName
) const
1975 const SvxXMLListStyleContext
*pStyle
= nullptr;
1976 if (m_xImpl
->m_xAutoStyles
.is())
1978 const SvXMLStyleContext
* pTempStyle
=
1979 m_xImpl
->m_xAutoStyles
->FindStyleChildContext( XmlStyleFamily::TEXT_LIST
, rName
,
1981 pStyle
= dynamic_cast< const SvxXMLListStyleContext
* >(pTempStyle
);
1987 XMLPropStyleContext
*XMLTextImportHelper::FindAutoFrameStyle( const OUString
& rName
) const
1989 XMLPropStyleContext
*pStyle
= nullptr;
1990 if (m_xImpl
->m_xAutoStyles
.is())
1992 const SvXMLStyleContext
* pTempStyle
=
1993 m_xImpl
->m_xAutoStyles
->FindStyleChildContext( XmlStyleFamily::SD_GRAPHICS_ID
, rName
,
1995 pStyle
= const_cast<XMLPropStyleContext
*>(dynamic_cast< const XMLPropStyleContext
* >(pTempStyle
));
2001 XMLPropStyleContext
* XMLTextImportHelper::FindSectionStyle(
2002 const OUString
& rName
) const
2004 XMLPropStyleContext
* pStyle
= nullptr;
2005 if (m_xImpl
->m_xAutoStyles
.is())
2007 const SvXMLStyleContext
* pTempStyle
=
2008 m_xImpl
->m_xAutoStyles
->FindStyleChildContext(
2009 XmlStyleFamily::TEXT_SECTION
,
2011 pStyle
= const_cast<XMLPropStyleContext
*>(dynamic_cast< const XMLPropStyleContext
* >(pTempStyle
));
2017 XMLPropStyleContext
* XMLTextImportHelper::FindPageMaster(
2018 const OUString
& rName
) const
2020 XMLPropStyleContext
* pStyle
= nullptr;
2021 if (m_xImpl
->m_xAutoStyles
.is())
2023 const SvXMLStyleContext
* pTempStyle
=
2024 m_xImpl
->m_xAutoStyles
->FindStyleChildContext(
2025 XmlStyleFamily::PAGE_MASTER
,
2027 pStyle
= const_cast<XMLPropStyleContext
*>(dynamic_cast< const XMLPropStyleContext
* >(pTempStyle
));
2033 XMLPropStyleContext
* XMLTextImportHelper::FindAutoCharStyle(const OUString
& rName
) const
2035 if (!m_xImpl
->m_xAutoStyles
)
2038 = m_xImpl
->m_xAutoStyles
->FindStyleChildContext(XmlStyleFamily::TEXT_TEXT
, rName
, true);
2039 return dynamic_cast<XMLPropStyleContext
*>(const_cast<SvXMLStyleContext
*>(pStyle
));
2042 XMLPropStyleContext
* XMLTextImportHelper::FindDrawingPage(OUString
const& rName
) const
2044 if (!m_xImpl
->m_xAutoStyles
.is())
2048 SvXMLStyleContext
const* pStyle(
2049 m_xImpl
->m_xAutoStyles
->FindStyleChildContext(
2050 XmlStyleFamily::SD_DRAWINGPAGE_ID
, rName
, true));
2051 assert(pStyle
== nullptr || dynamic_cast<XMLPropStyleContext
const*>(pStyle
) != nullptr);
2052 return const_cast<XMLPropStyleContext
*>(static_cast<XMLPropStyleContext
const*>(pStyle
));
2055 void XMLTextImportHelper::PushListContext()
2057 GetTextListHelper().PushListContext(static_cast<XMLTextListBlockContext
*>(nullptr));
2060 void XMLTextImportHelper::PopListContext()
2062 GetTextListHelper().PopListContext();
2066 SvI18NMap
& XMLTextImportHelper::GetRenameMap()
2068 if (!m_xImpl
->m_xRenameMap
)
2070 m_xImpl
->m_xRenameMap
.reset( new SvI18NMap
);
2072 return *m_xImpl
->m_xRenameMap
;
2075 void XMLTextImportHelper::InsertBookmarkStartRange(
2076 const OUString
& sName
,
2077 const Reference
<XTextRange
> & rRange
,
2078 OUString
const& i_rXmlId
,
2079 std::shared_ptr
< ::xmloff::ParsedRDFaAttributes
> & i_rpRDFaAttributes
)
2081 m_xImpl
->m_BookmarkStartRanges
[sName
] =
2082 std::make_tuple(rRange
, i_rXmlId
, i_rpRDFaAttributes
);
2083 m_xImpl
->m_BookmarkVector
.push_back(sName
);
2086 bool XMLTextImportHelper::FindAndRemoveBookmarkStartRange(
2087 const OUString
& sName
,
2088 Reference
<XTextRange
> & o_rRange
,
2089 OUString
& o_rXmlId
,
2090 std::shared_ptr
< ::xmloff::ParsedRDFaAttributes
> & o_rpRDFaAttributes
)
2092 if (m_xImpl
->m_BookmarkStartRanges
.count(sName
))
2094 Impl::BookmarkMapEntry_t
& rEntry
=
2095 (*m_xImpl
->m_BookmarkStartRanges
.find(sName
)).second
;
2096 o_rRange
.set(std::get
<0>(rEntry
));
2097 o_rXmlId
= std::get
<1>(rEntry
);
2098 o_rpRDFaAttributes
= std::get
<2>(rEntry
);
2099 m_xImpl
->m_BookmarkStartRanges
.erase(sName
);
2100 auto it
= std::find(m_xImpl
->m_BookmarkVector
.begin(), m_xImpl
->m_BookmarkVector
.end(), sName
);
2101 if (it
!=m_xImpl
->m_BookmarkVector
.end())
2103 m_xImpl
->m_BookmarkVector
.erase(it
);
2113 void XMLTextImportHelper::pushFieldCtx( const OUString
& name
, const OUString
& type
)
2115 m_xImpl
->m_FieldStack
.push(Impl::field_stack_item_t(
2116 Impl::field_name_type_t(name
, type
), Impl::field_params_t(), uno::Reference
<text::XFormField
>{}, GetCursor()->getStart()));
2119 uno::Reference
<text::XFormField
>
2120 XMLTextImportHelper::popFieldCtx()
2122 uno::Reference
<text::XFormField
> xRet
;
2123 if ( !m_xImpl
->m_FieldStack
.empty() )
2125 xRet
= std::get
<2>(m_xImpl
->m_FieldStack
.top());
2126 m_xImpl
->m_FieldStack
.pop();
2130 SAL_INFO("xmloff.text", "unexpected fieldmark end");
2135 void XMLTextImportHelper::addFieldParam( const OUString
& name
, const OUString
& value
)
2137 assert(!m_xImpl
->m_FieldStack
.empty());
2138 Impl::field_stack_item_t
& FieldStackItem(m_xImpl
->m_FieldStack
.top());
2139 std::get
<1>(FieldStackItem
).emplace_back( name
, value
);
2142 ::std::pair
<OUString
, OUString
> XMLTextImportHelper::getCurrentFieldType() const
2144 assert(!m_xImpl
->m_FieldStack
.empty());
2145 return std::get
<0>(m_xImpl
->m_FieldStack
.top());
2148 uno::Reference
<text::XTextRange
> XMLTextImportHelper::getCurrentFieldStart() const
2150 assert(!m_xImpl
->m_FieldStack
.empty());
2151 return std::get
<3>(m_xImpl
->m_FieldStack
.top());
2154 bool XMLTextImportHelper::hasCurrentFieldSeparator() const
2156 assert(!m_xImpl
->m_FieldStack
.empty());
2157 return std::get
<2>(m_xImpl
->m_FieldStack
.top()).is();
2160 bool XMLTextImportHelper::hasCurrentFieldCtx() const
2162 return !m_xImpl
->m_FieldStack
.empty();
2165 void XMLTextImportHelper::setCurrentFieldParamsTo(css::uno::Reference
< css::text::XFormField
> const &xFormField
)
2167 assert(!m_xImpl
->m_FieldStack
.empty());
2168 if (xFormField
.is())
2170 FieldParamImporter(&std::get
<1>(m_xImpl
->m_FieldStack
.top()),
2171 xFormField
->getParameters()).Import();
2172 std::get
<2>(m_xImpl
->m_FieldStack
.top()) = xFormField
;
2177 void XMLTextImportHelper::ConnectFrameChains(
2178 const OUString
& rFrmName
,
2179 const OUString
& rNextFrmName
,
2180 const Reference
< XPropertySet
>& rFrmPropSet
)
2182 if( rFrmName
.isEmpty() )
2185 if( !rNextFrmName
.isEmpty() )
2187 OUString
sNextFrmName(GetRenameMap().Get( XML_TEXT_RENAME_TYPE_FRAME
,
2189 if (m_xImpl
->m_xTextFrames
.is()
2190 && m_xImpl
->m_xTextFrames
->hasByName(sNextFrmName
))
2192 rFrmPropSet
->setPropertyValue(u
"ChainNextName"_ustr
,
2197 if (!m_xImpl
->m_xPrevFrmNames
)
2199 m_xImpl
->m_xPrevFrmNames
.emplace();
2200 m_xImpl
->m_xNextFrmNames
.emplace();
2202 m_xImpl
->m_xPrevFrmNames
->push_back(rFrmName
);
2203 m_xImpl
->m_xNextFrmNames
->push_back(sNextFrmName
);
2206 if (!m_xImpl
->m_xPrevFrmNames
|| m_xImpl
->m_xPrevFrmNames
->empty())
2209 for(std::vector
<OUString
>::iterator i
= m_xImpl
->m_xPrevFrmNames
->begin(), j
= m_xImpl
->m_xNextFrmNames
->begin(); i
!= m_xImpl
->m_xPrevFrmNames
->end() && j
!= m_xImpl
->m_xNextFrmNames
->end(); ++i
, ++j
)
2211 if((*j
) == rFrmName
)
2213 // The previous frame must exist, because it existing than
2214 // inserting the entry
2215 rFrmPropSet
->setPropertyValue(u
"ChainPrevName"_ustr
, Any(*i
));
2217 i
= m_xImpl
->m_xPrevFrmNames
->erase(i
);
2218 j
= m_xImpl
->m_xNextFrmNames
->erase(j
);
2220 // There cannot be more than one previous frames
2226 bool XMLTextImportHelper::IsInFrame() const
2228 static constexpr OUString s_TextFrame
= u
"TextFrame"_ustr
;
2230 bool bIsInFrame
= false;
2232 // are we currently in a text frame? yes, if the cursor has a
2233 // TextFrame property and it's non-NULL
2234 Reference
<XPropertySet
> xPropSet(const_cast<XMLTextImportHelper
*>(this)->GetCursor(), UNO_QUERY
);
2237 if (xPropSet
->getPropertySetInfo()->hasPropertyByName(s_TextFrame
))
2239 uno::Reference
<XTextFrame
> const xFrame(
2240 xPropSet
->getPropertyValue(s_TextFrame
), UNO_QUERY
);
2252 bool XMLTextImportHelper::IsInHeaderFooter() const
2257 Reference
< XPropertySet
> XMLTextImportHelper::createAndInsertOLEObject(
2259 const OUString
& /*rHRef*/,
2260 const OUString
& /*rStyleName*/,
2261 const OUString
& /*rTblName*/,
2262 sal_Int32
/*nWidth*/, sal_Int32
/*nHeight*/ )
2264 Reference
< XPropertySet
> xPropSet
;
2268 Reference
< XPropertySet
> XMLTextImportHelper::createAndInsertOOoLink(
2270 const OUString
& /*rHRef*/,
2271 const OUString
& /*rStyleName*/,
2272 const OUString
& /*rTblName*/,
2273 sal_Int32
/*nWidth*/, sal_Int32
/*nHeight*/ )
2275 Reference
< XPropertySet
> xPropSet
;
2279 Reference
< XPropertySet
> XMLTextImportHelper::createAndInsertApplet(
2280 const OUString
& /*rCode*/,
2281 const OUString
& /*rName*/,
2282 bool /*bMayScript*/,
2283 const OUString
& /*rHRef*/,
2284 sal_Int32
/*nWidth*/, sal_Int32
/*nHeight*/ )
2286 Reference
< XPropertySet
> xPropSet
;
2289 Reference
< XPropertySet
> XMLTextImportHelper::createAndInsertPlugin(
2290 const OUString
& /*rMimeType*/,
2291 const OUString
& /*rHRef*/,
2292 sal_Int32
/*nWidth*/, sal_Int32
/*nHeight*/ )
2294 Reference
< XPropertySet
> xPropSet
;
2297 Reference
< XPropertySet
> XMLTextImportHelper::createAndInsertFloatingFrame(
2298 const OUString
& /*rName*/,
2299 const OUString
& /*rHRef*/,
2300 const OUString
& /*rStyleName*/,
2301 sal_Int32
/*nWidth*/, sal_Int32
/*nHeight*/ )
2303 Reference
< XPropertySet
> xPropSet
;
2307 void XMLTextImportHelper::endAppletOrPlugin(
2308 const Reference
< XPropertySet
> &,
2309 std::map
< const OUString
, OUString
> &)
2312 // redline helper: dummy implementation to be overridden in sw/filter/xml
2313 void XMLTextImportHelper::RedlineAdd( const OUString
& /*rType*/,
2314 const OUString
& /*rId*/,
2315 const OUString
& /*rAuthor*/,
2316 const OUString
& /*rComment*/,
2317 const util::DateTime
& /*rDateTime*/,
2318 const OUString
& /*rMovedID*/,
2319 bool /*bMergeLastPara*/)
2321 // dummy implementation: do nothing
2324 Reference
<XTextCursor
> XMLTextImportHelper::RedlineCreateText(
2325 Reference
<XTextCursor
> & /*rOldCursor*/,
2326 const OUString
& /*rId*/)
2328 // dummy implementation: do nothing
2329 Reference
<XTextCursor
> xRet
;
2333 void XMLTextImportHelper::RedlineSetCursor(
2334 const OUString
& /*rId*/,
2336 bool /*bIsOutsideOfParagraph*/)
2338 // dummy implementation: do nothing
2341 void XMLTextImportHelper::RedlineAdjustStartNodeCursor()
2343 // dummy implementation: do nothing
2346 void XMLTextImportHelper::SetShowChanges( bool )
2348 // dummy implementation: do nothing
2351 void XMLTextImportHelper::SetRecordChanges( bool )
2353 // dummy implementation: do nothing
2355 void XMLTextImportHelper::SetChangesProtectionKey(const Sequence
<sal_Int8
> &)
2357 // dummy implementation: do nothing
2361 OUString
const & XMLTextImportHelper::GetOpenRedlineId() const
2363 return m_xImpl
->m_sOpenRedlineIdentifier
;
2366 void XMLTextImportHelper::SetOpenRedlineId( OUString
const & rId
)
2368 m_xImpl
->m_sOpenRedlineIdentifier
= rId
;
2371 void XMLTextImportHelper::ResetOpenRedlineId()
2373 SetOpenRedlineId(u
""_ustr
);
2377 XMLTextImportHelper::SetCellParaStyleDefault(OUString
const& rNewValue
)
2379 m_xImpl
->m_sCellParaStyleDefault
= rNewValue
;
2382 OUString
const& XMLTextImportHelper::GetCellParaStyleDefault() const
2384 return m_xImpl
->m_sCellParaStyleDefault
;
2387 void XMLTextImportHelper::AddCrossRefHeadingMapping(OUString
const& rFrom
, OUString
const& rTo
)
2389 if (!m_xImpl
->m_xCrossRefHeadingBookmarkMap
)
2391 m_xImpl
->m_xCrossRefHeadingBookmarkMap
.emplace();
2393 m_xImpl
->m_xCrossRefHeadingBookmarkMap
->insert(std::make_pair(rFrom
, rTo
));
2396 // tdf#94804: hack to map cross reference fields that reference duplicate marks
2397 // note that we can't really check meta:generator for this since the file might
2398 // be round-tripped by different versions preserving duplicates => always map
2399 void XMLTextImportHelper::MapCrossRefHeadingFieldsHorribly()
2401 if (!m_xImpl
->m_xCrossRefHeadingBookmarkMap
)
2406 uno::Reference
<text::XTextFieldsSupplier
> const xFieldsSupplier(
2407 m_xImpl
->m_rSvXMLImport
.GetModel(), uno::UNO_QUERY
);
2408 if (!xFieldsSupplier
.is())
2412 uno::Reference
<container::XEnumerationAccess
> const xFieldsEA(
2413 xFieldsSupplier
->getTextFields());
2414 uno::Reference
<container::XEnumeration
> const xFields(
2415 xFieldsEA
->createEnumeration());
2416 while (xFields
->hasMoreElements())
2418 uno::Reference
<lang::XServiceInfo
> const xFieldInfo(
2419 xFields
->nextElement(), uno::UNO_QUERY
);
2420 if (!xFieldInfo
->supportsService(u
"com.sun.star.text.textfield.GetReference"_ustr
))
2424 uno::Reference
<beans::XPropertySet
> const xField(
2425 xFieldInfo
, uno::UNO_QUERY
);
2426 sal_uInt16
nType(0);
2427 xField
->getPropertyValue(u
"ReferenceFieldSource"_ustr
) >>= nType
;
2428 if (text::ReferenceFieldSource::BOOKMARK
!= nType
)
2433 xField
->getPropertyValue(u
"SourceName"_ustr
) >>= name
;
2434 auto const iter(m_xImpl
->m_xCrossRefHeadingBookmarkMap
->find(name
));
2435 if (iter
== m_xImpl
->m_xCrossRefHeadingBookmarkMap
->end())
2439 xField
->setPropertyValue(u
"SourceName"_ustr
, uno::Any(iter
->second
));
2443 void XMLTextImportHelper::setBookmarkAttributes(OUString
const& bookmark
, bool hidden
, OUString
const& condition
)
2445 m_xImpl
->m_bBookmarkHidden
[bookmark
] = hidden
;
2446 m_xImpl
->m_sBookmarkCondition
[bookmark
] = condition
;
2449 bool XMLTextImportHelper::getBookmarkHidden(OUString
const& bookmark
) const
2451 return m_xImpl
->m_bBookmarkHidden
[bookmark
];
2454 const OUString
& XMLTextImportHelper::getBookmarkCondition(OUString
const& bookmark
) const
2456 return m_xImpl
->m_sBookmarkCondition
[bookmark
];
2459 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */