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 #include <com/sun/star/container/XIndexReplace.hpp>
21 #include "impastpl.hxx"
22 #include <xmloff/xmlaustp.hxx>
23 #include <xmloff/families.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlexp.hxx>
27 #include <xmloff/xmlprhdl.hxx>
28 #include <xmloff/xmlprmap.hxx>
29 #include <xmloff/XMLTextListAutoStylePool.hxx>
31 #include <PageMasterStyleMap.hxx>
32 #include <osl/diagnose.h>
35 using namespace ::std
;
37 using namespace ::com::sun::star
;
38 using namespace ::xmloff::token
;
43 void lcl_exportDataStyle( SvXMLExport
& _rExport
, const rtl::Reference
< XMLPropertySetMapper
>& _rxMapper
,
44 const XMLPropertyState
& _rProperty
)
46 assert(_rxMapper
.is());
47 // obtain the data style name
48 OUString sDataStyleName
;
49 _rProperty
.maValue
>>= sDataStyleName
;
50 assert(!sDataStyleName
.isEmpty() && "xmloff::lcl_exportDataStyle: invalid property value for the data style name!");
53 _rExport
.AddAttribute(
54 _rxMapper
->GetEntryNameSpace( _rProperty
.mnIndex
),
55 _rxMapper
->GetEntryXMLName( _rProperty
.mnIndex
),
60 void SvXMLAutoStylePoolP::exportStyleAttributes(
62 XmlStyleFamily nFamily
,
63 const vector
< XMLPropertyState
>& rProperties
,
64 const SvXMLExportPropertyMapper
& rPropExp
,
65 const SvXMLUnitConverter
&,
66 const SvXMLNamespaceMap
&
69 if ( XmlStyleFamily::CONTROL_ID
== nFamily
)
70 { // it's a control-related style
71 const rtl::Reference
< XMLPropertySetMapper
>& aPropertyMapper
= rPropExp
.getPropertySetMapper();
73 for (const auto& rProp
: rProperties
)
75 if ( ( rProp
.mnIndex
> -1 )
76 && ( CTF_FORMS_DATA_STYLE
== aPropertyMapper
->GetEntryContextId( rProp
.mnIndex
) )
78 { // it's the data-style for a grid column
79 lcl_exportDataStyle( GetExport(), aPropertyMapper
, rProp
);
84 if( (XmlStyleFamily::SD_GRAPHICS_ID
== nFamily
) || (XmlStyleFamily::SD_PRESENTATION_ID
== nFamily
) )
85 { // it's a graphics style
86 const rtl::Reference
< XMLPropertySetMapper
>& aPropertyMapper
= rPropExp
.getPropertySetMapper();
87 assert(aPropertyMapper
.is());
89 bool bFoundControlShapeDataStyle
= false;
90 bool bFoundNumberingRulesName
= false;
92 for (const auto& rProp
: rProperties
)
94 if (rProp
.mnIndex
> -1)
95 { // it's a valid property
96 switch( aPropertyMapper
->GetEntryContextId(rProp
.mnIndex
) )
98 case CTF_SD_CONTROL_SHAPE_DATA_STYLE
:
99 { // it's the control shape data style property
101 if (bFoundControlShapeDataStyle
)
103 OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
104 // already added the attribute for the first occurrence
108 lcl_exportDataStyle( GetExport(), aPropertyMapper
, rProp
);
110 // check if there is another property with the special context id we're handling here
111 bFoundControlShapeDataStyle
= true;
114 case CTF_SD_NUMBERINGRULES_NAME
:
116 if (bFoundNumberingRulesName
)
118 OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!");
119 // already added the attribute for the first occurrence
123 uno::Reference
< container::XIndexReplace
> xNumRule
;
124 rProp
.maValue
>>= xNumRule
;
125 if( xNumRule
.is() && (xNumRule
->getCount() > 0 ) )
127 const OUString
sName(const_cast<XMLTextListAutoStylePool
*>(&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule
));
129 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_LIST_STYLE_NAME
, GetExport().EncodeStyleName( sName
) );
132 bFoundNumberingRulesName
= true;
140 if( nFamily
!= XmlStyleFamily::PAGE_MASTER
)
143 for( const auto& rProp
: rProperties
)
145 if (rProp
.mnIndex
> -1)
147 const rtl::Reference
< XMLPropertySetMapper
>& aPropMapper
= rPropExp
.getPropertySetMapper();
148 sal_Int32 nIndex
= rProp
.mnIndex
;
149 sal_Int16 nContextID
= aPropMapper
->GetEntryContextId( nIndex
);
152 case CTF_PM_PAGEUSAGE
:
155 const XMLPropertyHandler
* pPropHdl
= aPropMapper
->GetPropertyHandler( nIndex
);
157 pPropHdl
->exportXML( sValue
, rProp
.maValue
,
158 GetExport().GetMM100UnitConverter() ) &&
159 ( ! IsXMLToken( sValue
, XML_ALL
) ) )
161 GetExport().AddAttribute( aPropMapper
->GetEntryNameSpace( nIndex
), aPropMapper
->GetEntryXMLName( nIndex
), sValue
);
170 void SvXMLAutoStylePoolP::exportStyleContent(
171 const css::uno::Reference
< css::xml::sax::XDocumentHandler
> &,
172 XmlStyleFamily nFamily
,
173 const vector
< XMLPropertyState
>& rProperties
,
174 const SvXMLExportPropertyMapper
& rPropExp
,
175 const SvXMLUnitConverter
&,
176 const SvXMLNamespaceMap
&
179 if( nFamily
!= XmlStyleFamily::PAGE_MASTER
)
182 sal_Int32
nHeaderStartIndex(-1);
183 sal_Int32
nHeaderEndIndex(-1);
184 sal_Int32
nFooterStartIndex(-1);
185 sal_Int32
nFooterEndIndex(-1);
186 bool bHeaderStartIndex(false);
187 bool bHeaderEndIndex(false);
188 bool bFooterStartIndex(false);
189 bool bFooterEndIndex(false);
191 const rtl::Reference
< XMLPropertySetMapper
>& aPropMapper
= rPropExp
.getPropertySetMapper();
194 while(nIndex
< aPropMapper
->GetEntryCount())
196 switch( aPropMapper
->GetEntryContextId( nIndex
) & CTF_PM_FLAGMASK
)
198 case CTF_PM_HEADERFLAG
:
200 if (!bHeaderStartIndex
)
202 nHeaderStartIndex
= nIndex
;
203 bHeaderStartIndex
= true;
205 if (bFooterStartIndex
&& !bFooterEndIndex
)
207 nFooterEndIndex
= nIndex
;
208 bFooterEndIndex
= true;
212 case CTF_PM_FOOTERFLAG
:
214 if (!bFooterStartIndex
)
216 nFooterStartIndex
= nIndex
;
217 bFooterStartIndex
= true;
219 if (bHeaderStartIndex
&& !bHeaderEndIndex
)
221 nHeaderEndIndex
= nIndex
;
222 bHeaderEndIndex
= true;
229 if (!bHeaderEndIndex
)
230 nHeaderEndIndex
= nIndex
;
231 if (!bFooterEndIndex
)
232 nFooterEndIndex
= nIndex
;
234 // export header style element
236 SvXMLElementExport
aElem(
237 GetExport(), XML_NAMESPACE_STYLE
, XML_HEADER_STYLE
,
241 GetExport(), rProperties
,
242 nHeaderStartIndex
, nHeaderEndIndex
, SvXmlExportFlags::IGN_WS
);
245 // export footer style
247 SvXMLElementExport
aElem(
248 GetExport(), XML_NAMESPACE_STYLE
, XML_FOOTER_STYLE
,
252 GetExport(), rProperties
,
253 nFooterStartIndex
, nFooterEndIndex
, SvXmlExportFlags::IGN_WS
);
258 SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport
& rExport
)
259 : pImpl( new SvXMLAutoStylePoolP_Impl( rExport
) )
263 SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
267 SvXMLExport
& SvXMLAutoStylePoolP::GetExport() const
269 return pImpl
->GetExport();
273 void SvXMLAutoStylePoolP::AddFamily(
274 XmlStyleFamily nFamily
,
275 const OUString
& rStrName
,
276 SvXMLExportPropertyMapper
* pMapper
,
277 const OUString
& aStrPrefix
)
279 rtl::Reference
<SvXMLExportPropertyMapper
> xTmp
= pMapper
;
280 AddFamily( nFamily
, rStrName
, xTmp
, aStrPrefix
);
283 void SvXMLAutoStylePoolP::AddFamily(
284 XmlStyleFamily nFamily
,
285 const OUString
& rStrName
,
286 const rtl::Reference
< SvXMLExportPropertyMapper
> & rMapper
,
287 const OUString
& rStrPrefix
,
290 pImpl
->AddFamily( nFamily
, rStrName
, rMapper
, rStrPrefix
, bAsFamily
);
293 void SvXMLAutoStylePoolP::SetFamilyPropSetMapper(
294 XmlStyleFamily nFamily
,
295 const rtl::Reference
< SvXMLExportPropertyMapper
> & rMapper
)
297 pImpl
->SetFamilyPropSetMapper( nFamily
, rMapper
);
300 void SvXMLAutoStylePoolP::RegisterName( XmlStyleFamily nFamily
,
301 const OUString
& rName
)
303 pImpl
->RegisterName( nFamily
, rName
);
306 void SvXMLAutoStylePoolP::RegisterDefinedName( XmlStyleFamily nFamily
,
307 const OUString
& rName
)
309 pImpl
->RegisterDefinedName( nFamily
, rName
);
312 void SvXMLAutoStylePoolP::GetRegisteredNames(
313 uno::Sequence
<sal_Int32
>& rFamilies
,
314 uno::Sequence
<OUString
>& rNames
)
316 pImpl
->GetRegisteredNames( rFamilies
, rNames
);
319 void SvXMLAutoStylePoolP::RegisterNames(
320 uno::Sequence
<sal_Int32
> const & aFamilies
,
321 uno::Sequence
<OUString
> const & aNames
)
323 assert(aFamilies
.getLength() == aNames
.getLength());
325 // iterate over sequence(s) and call RegisterName(..) for each pair
326 const sal_Int32
* pFamilies
= aFamilies
.getConstArray();
327 const OUString
* pNames
= aNames
.getConstArray();
328 sal_Int32 nCount
= min( aFamilies
.getLength(), aNames
.getLength() );
329 for( sal_Int32 n
= 0; n
< nCount
; n
++ )
330 RegisterName( static_cast<XmlStyleFamily
>(pFamilies
[n
]), pNames
[n
] );
333 OUString
SvXMLAutoStylePoolP::Add( XmlStyleFamily nFamily
,
334 const vector
< XMLPropertyState
>& rProperties
)
337 pImpl
->Add(sName
, nFamily
, "", rProperties
);
341 OUString
SvXMLAutoStylePoolP::Add( XmlStyleFamily nFamily
,
342 const OUString
& rParent
,
343 const vector
< XMLPropertyState
>& rProperties
, bool bDontSeek
)
346 pImpl
->Add(sName
, nFamily
, rParent
, rProperties
, bDontSeek
);
350 bool SvXMLAutoStylePoolP::Add(OUString
& rName
, XmlStyleFamily nFamily
, const OUString
& rParent
, const ::std::vector
< XMLPropertyState
>& rProperties
)
352 return pImpl
->Add(rName
, nFamily
, rParent
, rProperties
);
355 bool SvXMLAutoStylePoolP::AddNamed( const OUString
& rName
, XmlStyleFamily nFamily
, const OUString
& rParent
,
356 const ::std::vector
< XMLPropertyState
>& rProperties
)
359 return pImpl
->AddNamed(rName
, nFamily
, rParent
, rProperties
);
362 OUString
SvXMLAutoStylePoolP::Find( XmlStyleFamily nFamily
,
363 const OUString
& rParent
,
364 const vector
< XMLPropertyState
>& rProperties
) const
366 return pImpl
->Find( nFamily
, rParent
, rProperties
);
369 void SvXMLAutoStylePoolP::exportXML( XmlStyleFamily nFamily
) const
371 pImpl
->exportXML( nFamily
, this );
374 void SvXMLAutoStylePoolP::ClearEntries()
376 pImpl
->ClearEntries();
379 std::vector
<xmloff::AutoStyleEntry
> SvXMLAutoStylePoolP::GetAutoStyleEntries() const
381 return pImpl
->GetAutoStyleEntries();
384 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */