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_XMLOFF_XMLSTYLE_HXX
21 #define INCLUDED_XMLOFF_XMLSTYLE_HXX
23 #include <rtl/ref.hxx>
24 #include <sal/config.h>
25 #include <xmloff/dllapi.h>
26 #include <sal/types.h>
27 #include <xmloff/xmlictxt.hxx>
28 #include <xmloff/families.hxx>
31 class SvXMLStylesContext_Impl
;
32 class SvXMLImportPropertyMapper
;
35 namespace com::sun::star
{
36 namespace container
{ class XNameContainer
; }
37 namespace style
{ class XAutoStyleFamily
; }
40 class XMLOFF_DLLPUBLIC SvXMLStyleContext
: public SvXMLImportContext
43 OUString maDisplayName
;
44 css::uno::Any maAutoName
;
45 OUString maParentName
;// Will be moved to XMLPropStyle soon!!!!
46 OUString maFollow
; // Will be moved to XMLPropStyle soon!!!!
50 XmlStyleFamily mnFamily
;
52 bool mbValid
: 1; // Set this to false in CreateAndInsert
53 // if the style shouldn't be processed
54 // by Finish() or is somehow invalid.
55 bool mbNew
: 1; // Set this to false in CreateAnsInsert
56 // if the style is already existing.
57 bool mbDefaultStyle
: 1;
61 virtual void SetAttribute( sal_Int32 nElement
, const OUString
& rValue
);
63 void SetFamily( XmlStyleFamily nSet
) { mnFamily
= nSet
; }
64 void SetAutoName( const css::uno::Any
& rName
) { maAutoName
= rName
; }
68 SvXMLStyleContext( SvXMLImport
& rImport
,
69 XmlStyleFamily nFamily
=XmlStyleFamily::DATA_STYLE
,
70 bool bDefaultStyle
= false );
72 virtual ~SvXMLStyleContext() override
;
74 virtual void SAL_CALL
startFastElement(
76 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& ) override
;
78 const OUString
& GetName() const { return maName
; }
79 const OUString
& GetDisplayName() const { return maDisplayName
.getLength() ? maDisplayName
: maName
; }
80 const css::uno::Any
& GetAutoName() const { return maAutoName
; }
81 const OUString
& GetParentName() const { return maParentName
; }
82 const OUString
& GetFollow() const { return maFollow
; }
83 const OUString
& GetLinked() const { return maLinked
; }
85 XmlStyleFamily
GetFamily() const { return mnFamily
; }
87 bool IsValid() const { return mbValid
; }
88 void SetValid( bool b
) { mbValid
= b
; }
90 bool IsNew() const { return mbNew
; }
91 void SetNew( bool b
) { mbNew
= b
; }
93 bool IsHidden() const { return mbHidden
; }
95 // This method is called for every default style
96 virtual void SetDefaults();
98 // This method is called for every style. It must create it and insert
99 // it into the document.
100 virtual void CreateAndInsert( bool bOverwrite
);
102 // This method is called for every style. It must create it and insert
103 // it into the document if this hasn't happened already in CreateAndInsert().
104 virtual void CreateAndInsertLate( bool bOverwrite
);
106 // This method is called for every style after all styles have been
107 // inserted into the document.
108 virtual void Finish( bool bOverwrite
);
110 bool IsDefaultStyle() const { return mbDefaultStyle
; }
112 /** if this method returns true, its parent styles context
113 should not add it to its container.<br>
114 Transient styles can't be accessed from its
115 parent SvXMLStylesContext after they are imported and
116 the methods CreateAndInsert(), CreateAndInsertLate()
117 and Finish() will not be called.
118 The default return value is false
120 virtual bool IsTransient() const;
123 class XMLOFF_DLLPUBLIC SvXMLStylesContext
: public SvXMLImportContext
125 std::unique_ptr
<SvXMLStylesContext_Impl
> mpImpl
;
128 css::uno::Reference
< css::container::XNameContainer
> mxParaStyles
;
130 css::uno::Reference
< css::container::XNameContainer
> mxTextStyles
;
132 css::uno::Reference
< css::style::XAutoStyleFamily
> mxParaAutoStyles
;
134 css::uno::Reference
< css::style::XAutoStyleFamily
> mxTextAutoStyles
;
136 rtl::Reference
< SvXMLImportPropertyMapper
> mxParaImpPropMapper
;
137 rtl::Reference
< SvXMLImportPropertyMapper
> mxTextImpPropMapper
;
138 rtl::Reference
< SvXMLImportPropertyMapper
> mxShapeImpPropMapper
;
139 mutable rtl::Reference
< SvXMLImportPropertyMapper
> mxChartImpPropMapper
;
140 mutable rtl::Reference
< SvXMLImportPropertyMapper
> mxPageImpPropMapper
;
142 SvXMLStylesContext(SvXMLStylesContext
const &) = delete;
143 SvXMLStylesContext
& operator =(SvXMLStylesContext
const &) = delete;
147 sal_uInt32
GetStyleCount() const;
148 SvXMLStyleContext
*GetStyle( sal_uInt32 i
);
149 const SvXMLStyleContext
*GetStyle( sal_uInt32 i
) const;
151 virtual SvXMLStyleContext
*CreateStyleChildContext(
153 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
);
155 virtual SvXMLStyleContext
*CreateStyleStyleChildContext( XmlStyleFamily nFamily
,
157 const css::uno::Reference
< css::xml::sax::XFastAttributeList
> & xAttrList
);
159 virtual SvXMLStyleContext
*CreateDefaultStyleStyleChildContext(
160 XmlStyleFamily nFamily
, sal_Int32 nElement
,
161 const css::uno::Reference
< css::xml::sax::XFastAttributeList
> & xAttrList
);
163 virtual bool InsertStyleFamily( XmlStyleFamily nFamily
) const;
167 SvXMLStylesContext( SvXMLImport
& rImport
,
168 bool bAutomatic
= false );
170 virtual ~SvXMLStylesContext() override
;
172 // Create child element.
173 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
174 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& AttrList
) override
;
176 // This allows to add an SvXMLStyleContext to this context from extern
177 void AddStyle(SvXMLStyleContext
& rNew
);
179 const SvXMLStyleContext
*FindStyleChildContext(
180 XmlStyleFamily nFamily
,
181 const OUString
& rName
,
182 bool bCreateIndex
= false ) const;
183 static XmlStyleFamily
GetFamily( std::u16string_view rFamily
);
184 virtual rtl::Reference
< SvXMLImportPropertyMapper
> GetImportPropertyMapper(
185 XmlStyleFamily nFamily
) const;
187 virtual css::uno::Reference
< css::container::XNameContainer
>
188 GetStylesContainer( XmlStyleFamily nFamily
) const;
189 virtual OUString
GetServiceName( XmlStyleFamily nFamily
) const;
191 css::uno::Reference
< css::style::XAutoStyleFamily
>
192 GetAutoStyles( XmlStyleFamily nFamily
) const;
193 void CopyAutoStylesToDoc();
194 void CopyStylesToDoc( bool bOverwrite
, bool bFinish
= true );
195 void FinishStyles( bool bOverwrite
);
197 // This method must be called to release the references to all styles
198 // that are stored in the context.
200 bool IsAutomaticStyle() const;
203 #endif // INCLUDED_XMLOFF_XMLSTYLE_HXX
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */