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 .
20 #ifndef INCLUDED_SW_SOURCE_FILTER_XML_XMLIMP_HXX
21 #define INCLUDED_SW_SOURCE_FILTER_XML_XMLIMP_HXX
23 #include <sal/config.h>
28 #include <com/sun/star/document/XDocumentProperties.hpp>
30 #include <xmloff/xmlictxt.hxx>
31 #include <xmloff/xmlimp.hxx>
33 #include "xmlitmap.hxx"
34 #include <o3tl/typed_flags_set.hxx>
35 #include <ndindex.hxx>
38 class SvXMLUnitConverter
;
40 class SvXMLImportItemMapper
;
42 class XMLTextImportHelper
;
43 class SvXMLGraphicHelper
;
44 class SvXMLEmbeddedObjectHelper
;
45 enum class SfxStyleFamily
;
47 // define, how many steps ( = paragraphs ) the progress bar should advance
48 // for styles, autostyles and settings + meta
49 #define PROGRESS_BAR_STEP 20
51 // we only need this scoped enum to be flags here, in sw
54 template<> struct typed_flags
<SfxStyleFamily
> : is_typed_flags
<SfxStyleFamily
, 0xffff> {};
57 class SwXMLImport
: public SvXMLImport
59 std::optional
<SwNodeIndex
> m_oSttNdIdx
;
61 std::unique_ptr
<SvXMLUnitConverter
> m_pTwipUnitConv
;
62 std::unique_ptr
<SvXMLImportItemMapper
> m_pTableItemMapper
;// paragraph item import
64 rtl::Reference
<SvXMLGraphicHelper
> m_xGraphicStorageHandler
;
66 rtl::Reference
<SvXMLEmbeddedObjectHelper
> m_xEmbeddedResolver
;
68 SvXMLItemMapEntriesRef m_xTableItemMap
;
69 SvXMLItemMapEntriesRef m_xTableColItemMap
;
70 SvXMLItemMapEntriesRef m_xTableRowItemMap
;
71 SvXMLItemMapEntriesRef m_xTableCellItemMap
;
72 css::uno::Reference
< css::container::XNameContainer
>
75 SfxStyleFamily m_nStyleFamilyMask
;// Mask of styles to load
76 bool m_bLoadDoc
: 1; // Load doc or styles only
77 bool m_bInsert
: 1; // Insert mode. If styles are
78 // loaded only false means that
79 // existing styles will be
81 bool m_bBlock
: 1; // Load text block
82 bool m_bOrganizerMode
: 1;
83 bool m_bInititedXForms
: 1;
85 SwDoc
* m_pDoc
; // cached for getDoc()
87 // Optimization for new table name lookup
88 OUString m_sDefTableName
; // See STR_TABLE_DEFNAME
89 std::map
<OUString
, sal_uInt32
> m_aTableNameMap
; // Last used indices for duplicating table names
91 void InitItemImport();
92 void FinitItemImport();
93 void UpdateTextCollConditions( SwDoc
*pDoc
);
95 void setTextInsertMode(
96 const css::uno::Reference
< css::text::XTextRange
> & rInsertPos
);
97 void setStyleInsertMode( SfxStyleFamily nFamilies
,
102 virtual SvXMLImportContext
*CreateFastContext( sal_Int32 nElement
,
103 const ::css::uno::Reference
< ::css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
105 virtual XMLTextImportHelper
* CreateTextImport() override
;
107 virtual XMLShapeImportHelper
* CreateShapeImport() override
;
111 const css::uno::Reference
< css::uno::XComponentContext
>& rContext
,
112 OUString
const & implementationName
, SvXMLImportFlags nImportFlags
);
114 virtual ~SwXMLImport() noexcept override
;
116 // css::xml::sax::XDocumentHandler
117 virtual void SAL_CALL
startDocument() override
;
118 virtual void SAL_CALL
endDocument() override
;
121 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
123 void InsertStyles( bool bAuto
);
128 // NB: in contrast to other CreateFooContexts, this particular one handles
129 // the root element (i.e. office:document-meta)
130 SvXMLImportContext
*CreateMetaContext( const sal_Int32 nElement
);
131 SvXMLImportContext
*CreateScriptContext();
132 SvXMLImportContext
*CreateStylesContext( bool bAuto
);
133 SvXMLImportContext
*CreateMasterStylesContext();
134 SvXMLImportContext
*CreateFontDeclsContext();
135 SvXMLImportContext
*CreateBodyContentContext();
136 SfxStyleFamily
GetStyleFamilyMask() const { return m_nStyleFamilyMask
; }
137 bool IsInsertMode() const { return m_bInsert
; }
138 bool IsStylesOnlyMode() const { return !m_bLoadDoc
; }
139 bool IsBlockMode() const { return m_bBlock
; }
141 inline const SvXMLImportItemMapper
& GetTableItemMapper() const;
142 inline SvXMLImportItemMapper
& GetTableItemMapper();
143 SvXMLImportContext
*CreateTableItemImportContext( sal_Int32 nElement
,
144 const css::uno::Reference
< css::xml::sax::XFastAttributeList
> & xAttrList
,
145 XmlStyleFamily nSubFamily
, SfxItemSet
& rItemSet
);
147 bool FindAutomaticStyle( XmlStyleFamily nFamily
,
148 const OUString
& rName
,
149 const SfxItemSet
**ppItemSet
) const;
150 void MergeListsAtDocumentInsertPosition(SwDoc
*pDoc
);
152 virtual void SetStatistics(
153 const css::uno::Sequence
< css::beans::NamedValue
> & i_rStats
) override
;
154 virtual void SetViewSettings(const css::uno::Sequence
<css::beans::PropertyValue
>& aViewProps
) override
;
155 virtual void SetConfigurationSettings(const css::uno::Sequence
<css::beans::PropertyValue
>& aConfigProps
) override
;
156 virtual void SetDocumentSpecificSettings(const OUString
& _rSettingsGroupName
,
157 const css::uno::Sequence
<css::beans::PropertyValue
>& _rSettings
) override
;
160 virtual void initXForms() override
;
162 // get the document properties, but only if they actually need importing
163 css::uno::Reference
<css::document::XDocumentProperties
>
164 GetDocumentProperties() const;
166 virtual void NotifyContainsEmbeddedFont() override
;
168 const SwDoc
* getDoc() const;
171 const OUString
& GetDefTableName() { return m_sDefTableName
; }
172 std::map
<OUString
, sal_uInt32
>& GetTableNameMap() { return m_aTableNameMap
; }
175 inline const SvXMLImportItemMapper
& SwXMLImport::GetTableItemMapper() const
177 return *m_pTableItemMapper
;
180 inline SvXMLImportItemMapper
& SwXMLImport::GetTableItemMapper()
182 return *m_pTableItemMapper
;
185 #endif // _XMLIMP_HXX
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */