1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_XMLOFF_XMLSTYLE_HXX
21 #define INCLUDED_XMLOFF_XMLSTYLE_HXX
22 
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>
29 #include <memory>
30 
31 class SvXMLStylesContext_Impl;
32 class SvXMLImportPropertyMapper;
33 class SvXMLTokenMap;
34 
35 namespace com::sun::star {
36 namespace container { class XNameContainer; }
37 namespace style { class XAutoStyleFamily; }
38 }
39 
40 class XMLOFF_DLLPUBLIC SvXMLStyleContext : public SvXMLImportContext
41 {
42     OUString     maName;
43     OUString     maDisplayName;
44     OUString     maAutoName;
45     OUString     maParentName;// Will be moved to XMLPropStyle soon!!!!
46     OUString     maFollow;    // Will be moved to XMLPropStyle soon!!!!
47     bool         mbHidden;
48 
49     XmlStyleFamily mnFamily;
50 
51     bool         mbValid : 1; // Set this to false in CreateAndInsert
52                               // if the style shouldn't be processed
53                               // by Finish() or si somehow invalid.
54     bool         mbNew : 1;   // Set this to false in CreateAnsInsert
55                               // if the style is already existing.
56     bool         mbDefaultStyle : 1;
57 
58 protected:
59 
60     virtual void SetAttribute( sal_Int32 nElement, const OUString& rValue );
61 
SetFamily(XmlStyleFamily nSet)62     void SetFamily( XmlStyleFamily nSet ) { mnFamily = nSet; }
SetAutoName(const OUString & rName)63     void SetAutoName( const OUString& rName ) { maAutoName = rName; }
64 
65 public:
66 
67     SvXMLStyleContext( SvXMLImport& rImport,
68               XmlStyleFamily nFamily=XmlStyleFamily::DATA_STYLE,
69               bool bDefaultStyle = false );
70 
71     virtual ~SvXMLStyleContext() override;
72 
73     virtual void SAL_CALL startFastElement(
74             sal_Int32 nElement,
75             const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override;
76 
GetName() const77     const OUString&  GetName() const { return maName; }
GetDisplayName() const78     const OUString&  GetDisplayName() const { return maDisplayName.getLength() ? maDisplayName : maName; }
GetAutoName() const79     const OUString&  GetAutoName() const { return maAutoName; }
GetParentName() const80     const OUString&  GetParentName() const { return maParentName; }
GetFollow() const81     const OUString&  GetFollow() const { return maFollow; }
82 
GetFamily() const83     XmlStyleFamily GetFamily() const { return mnFamily; }
84 
IsValid() const85     bool IsValid() const { return mbValid; }
SetValid(bool b)86     void SetValid( bool b ) { mbValid = b; }
87 
IsNew() const88     bool IsNew() const { return mbNew; }
SetNew(bool b)89     void SetNew( bool b ) { mbNew = b; }
90 
IsHidden() const91     bool IsHidden() const { return mbHidden; }
92 
93     // This method is called for every default style
94     virtual void SetDefaults();
95 
96     // This method is called for every style. It must create it and insert
97     // it into the document.
98     virtual void CreateAndInsert( bool bOverwrite );
99 
100     // This method is called for every style. It must create it and insert
101     // it into the document if this hasn't happened already in CreateAndInsert().
102     virtual void CreateAndInsertLate( bool bOverwrite );
103 
104     // This method is called for every style after all styles have been
105     // inserted into the document.
106     virtual void Finish( bool bOverwrite );
107 
IsDefaultStyle() const108     bool IsDefaultStyle() const { return mbDefaultStyle; }
109 
110     /** if this method returns true, its parent styles context
111         should not add it to its container.<br>
112         Transient styles can't be accessed from its
113         parent SvXMLStylesContext after they are imported and
114         the methods CreateAndInsert(), CreateAndInsertLate()
115         and Finish() will not be called.
116         The default return value is false
117     */
118     virtual bool IsTransient() const;
119 };
120 
121 class XMLOFF_DLLPUBLIC SvXMLStylesContext : public SvXMLImportContext
122 {
123     std::unique_ptr<SvXMLStylesContext_Impl> mpImpl;
124 
125 
126     css::uno::Reference< css::container::XNameContainer > mxParaStyles;
127 
128     css::uno::Reference< css::container::XNameContainer > mxTextStyles;
129 
130     css::uno::Reference< css::style::XAutoStyleFamily > mxParaAutoStyles;
131 
132     css::uno::Reference< css::style::XAutoStyleFamily > mxTextAutoStyles;
133 
134     rtl::Reference < SvXMLImportPropertyMapper > mxParaImpPropMapper;
135     rtl::Reference < SvXMLImportPropertyMapper > mxTextImpPropMapper;
136     rtl::Reference < SvXMLImportPropertyMapper > mxShapeImpPropMapper;
137     mutable rtl::Reference < SvXMLImportPropertyMapper > mxChartImpPropMapper;
138     mutable rtl::Reference < SvXMLImportPropertyMapper > mxPageImpPropMapper;
139 
140     SvXMLStylesContext(SvXMLStylesContext const &) = delete;
141     SvXMLStylesContext& operator =(SvXMLStylesContext const &) = delete;
142 
143 protected:
144 
145     sal_uInt32 GetStyleCount() const;
146     SvXMLStyleContext *GetStyle( sal_uInt32 i );
147     const SvXMLStyleContext *GetStyle( sal_uInt32 i ) const;
148 
149     virtual SvXMLStyleContext *CreateStyleChildContext(
150         sal_Int32 nElement,
151         const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList );
152 
153     virtual SvXMLStyleContext *CreateStyleStyleChildContext( XmlStyleFamily nFamily,
154         sal_Int32 nElement,
155         const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
156 
157     virtual SvXMLStyleContext *CreateDefaultStyleStyleChildContext(
158         XmlStyleFamily nFamily, sal_Int32 nElement,
159         const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
160 
161     virtual bool InsertStyleFamily( XmlStyleFamily nFamily ) const;
162 
163 public:
164 
165     SvXMLStylesContext( SvXMLImport& rImport,
166         bool bAutomatic = false );
167 
168     virtual ~SvXMLStylesContext() override;
169 
170     // Create child element.
171     virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
172         sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
173 
174     // This allows to add an SvXMLStyleContext to this context from extern
175     void AddStyle(SvXMLStyleContext& rNew);
176 
177     const SvXMLStyleContext *FindStyleChildContext(
178                                       XmlStyleFamily nFamily,
179                                       const OUString& rName,
180                                       bool bCreateIndex = false ) const;
181     static XmlStyleFamily GetFamily( std::u16string_view rFamily );
182     virtual rtl::Reference < SvXMLImportPropertyMapper > GetImportPropertyMapper(
183                         XmlStyleFamily nFamily ) const;
184 
185     virtual css::uno::Reference< css::container::XNameContainer >
186         GetStylesContainer( XmlStyleFamily nFamily ) const;
187     virtual OUString GetServiceName( XmlStyleFamily nFamily ) const;
188 
189     css::uno::Reference< css::style::XAutoStyleFamily >
190         GetAutoStyles( XmlStyleFamily nFamily ) const;
191     void CopyAutoStylesToDoc();
192     void CopyStylesToDoc( bool bOverwrite, bool bFinish = true );
193     void FinishStyles( bool bOverwrite );
194 
195     // This method must be called to release the references to all styles
196     // that are stored in the context.
197     void dispose();
198     bool IsAutomaticStyle() const;
199 };
200 
201 #endif // INCLUDED_XMLOFF_XMLSTYLE_HXX
202 
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
204