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
;
45 OUString maParentName
;// Will be moved to XMLPropStyle soon!!!!
46 OUString maFollow
; // Will be moved to XMLPropStyle soon!!!!
49 XmlStyleFamily mnFamily
;
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;
60 virtual void SetAttribute( sal_Int32 nElement
, const OUString
& rValue
);
62 void SetFamily( XmlStyleFamily nSet
) { mnFamily
= nSet
; }
63 void SetAutoName( const OUString
& rName
) { maAutoName
= rName
; }
67 SvXMLStyleContext( SvXMLImport
& rImport
,
68 XmlStyleFamily nFamily
=XmlStyleFamily::DATA_STYLE
,
69 bool bDefaultStyle
= false );
71 virtual ~SvXMLStyleContext() override
;
73 virtual void SAL_CALL
startFastElement(
75 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& ) override
;
77 const OUString
& GetName() const { return maName
; }
78 const OUString
& GetDisplayName() const { return maDisplayName
.getLength() ? maDisplayName
: maName
; }
79 const OUString
& GetAutoName() const { return maAutoName
; }
80 const OUString
& GetParentName() const { return maParentName
; }
81 const OUString
& GetFollow() const { return maFollow
; }
83 XmlStyleFamily
GetFamily() const { return mnFamily
; }
85 bool IsValid() const { return mbValid
; }
86 void SetValid( bool b
) { mbValid
= b
; }
88 bool IsNew() const { return mbNew
; }
89 void SetNew( bool b
) { mbNew
= b
; }
91 bool IsHidden() const { return mbHidden
; }
93 // This method is called for every default style
94 virtual void SetDefaults();
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
);
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
);
104 // This method is called for every style after all styles have been
105 // inserted into the document.
106 virtual void Finish( bool bOverwrite
);
108 bool IsDefaultStyle() const { return mbDefaultStyle
; }
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
118 virtual bool IsTransient() const;
121 class XMLOFF_DLLPUBLIC SvXMLStylesContext
: public SvXMLImportContext
123 std::unique_ptr
<SvXMLStylesContext_Impl
> mpImpl
;
126 css::uno::Reference
< css::container::XNameContainer
> mxParaStyles
;
128 css::uno::Reference
< css::container::XNameContainer
> mxTextStyles
;
130 css::uno::Reference
< css::style::XAutoStyleFamily
> mxParaAutoStyles
;
132 css::uno::Reference
< css::style::XAutoStyleFamily
> mxTextAutoStyles
;
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
;
140 SvXMLStylesContext(SvXMLStylesContext
const &) = delete;
141 SvXMLStylesContext
& operator =(SvXMLStylesContext
const &) = delete;
145 sal_uInt32
GetStyleCount() const;
146 SvXMLStyleContext
*GetStyle( sal_uInt32 i
);
147 const SvXMLStyleContext
*GetStyle( sal_uInt32 i
) const;
149 virtual SvXMLStyleContext
*CreateStyleChildContext(
151 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
);
153 virtual SvXMLStyleContext
*CreateStyleStyleChildContext( XmlStyleFamily nFamily
,
155 const css::uno::Reference
< css::xml::sax::XFastAttributeList
> & xAttrList
);
157 virtual SvXMLStyleContext
*CreateDefaultStyleStyleChildContext(
158 XmlStyleFamily nFamily
, sal_Int32 nElement
,
159 const css::uno::Reference
< css::xml::sax::XFastAttributeList
> & xAttrList
);
161 virtual bool InsertStyleFamily( XmlStyleFamily nFamily
) const;
165 SvXMLStylesContext( SvXMLImport
& rImport
,
166 bool bAutomatic
= false );
168 virtual ~SvXMLStylesContext() override
;
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
;
174 // This allows to add an SvXMLStyleContext to this context from extern
175 void AddStyle(SvXMLStyleContext
& rNew
);
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;
185 virtual css::uno::Reference
< css::container::XNameContainer
>
186 GetStylesContainer( XmlStyleFamily nFamily
) const;
187 virtual OUString
GetServiceName( XmlStyleFamily nFamily
) const;
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
);
195 // This method must be called to release the references to all styles
196 // that are stored in the context.
198 bool IsAutomaticStyle() const;
201 #endif // INCLUDED_XMLOFF_XMLSTYLE_HXX
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */