bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / xmlaustp.cxx
blob0a8e22e1f2f548093194c9f77a9fdd0ace41c4bf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/debug.hxx>
22 #include "impastpl.hxx"
23 #include <xmloff/xmlaustp.hxx>
24 #include <xmloff/families.hxx>
25 #include <xmloff/xmlnmspe.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlexp.hxx>
28 #include <xmloff/xmlprhdl.hxx>
29 #include <xmloff/XMLTextListAutoStylePool.hxx>
31 #include <xmloff/PageMasterStyleMap.hxx>
32 #include "PageMasterExportPropMapper.hxx"
33 #include "XMLBackgroundImageExport.hxx"
36 using namespace ::std;
38 using namespace ::com::sun::star;
39 using namespace ::xmloff::token;
42 namespace
44 static void lcl_exportDataStyle( SvXMLExport& _rExport, const rtl::Reference< XMLPropertySetMapper >& _rxMapper,
45 const XMLPropertyState& _rProperty )
47 assert(_rxMapper.is());
48 // obtain the data style name
49 OUString sDataStyleName;
50 _rProperty.maValue >>= sDataStyleName;
51 assert(!sDataStyleName.isEmpty() && "xmloff::lcl_exportDataStyle: invalid property value for the data style name!");
53 // add the attribute
54 _rExport.AddAttribute(
55 _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
56 _rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
57 sDataStyleName );
61 void SvXMLAutoStylePoolP::exportStyleAttributes(
62 SvXMLAttributeList&,
63 sal_Int32 nFamily,
64 const vector< XMLPropertyState >& rProperties,
65 const SvXMLExportPropertyMapper& rPropExp,
66 const SvXMLUnitConverter&,
67 const SvXMLNamespaceMap&
68 ) const
70 if ( XML_STYLE_FAMILY_CONTROL_ID == nFamily )
71 { // it's a control-related style
72 rtl::Reference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
74 for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
75 pProp != rProperties.end();
76 ++pProp
79 if ( ( pProp->mnIndex > -1 )
80 && ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( pProp->mnIndex ) )
82 { // it's the data-style for a grid column
83 lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
88 if( (XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily) || (XML_STYLE_FAMILY_SD_PRESENTATION_ID == nFamily) )
89 { // it's a graphics style
90 rtl::Reference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
91 assert(aPropertyMapper.is());
93 bool bFoundControlShapeDataStyle = false;
94 bool bFoundNumberingRulesName = false;
96 for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
97 pProp != rProperties.end();
98 ++pProp
101 if (pProp->mnIndex > -1)
102 { // it's a valid property
103 switch( aPropertyMapper->GetEntryContextId(pProp->mnIndex) )
105 case CTF_SD_CONTROL_SHAPE_DATA_STYLE:
106 { // it's the control shape data style property
108 if (bFoundControlShapeDataStyle)
110 OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
111 // already added the attribute for the first occurrence
112 break;
115 lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
117 // check if there is another property with the special context id we're handling here
118 bFoundControlShapeDataStyle = true;
119 break;
121 case CTF_SD_NUMBERINGRULES_NAME:
123 if (bFoundNumberingRulesName)
125 OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!");
126 // already added the attribute for the first occurrence
127 break;
130 uno::Reference< container::XIndexReplace > xNumRule;
131 pProp->maValue >>= xNumRule;
132 if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
134 const OUString sName(const_cast<XMLTextListAutoStylePool*>(&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
136 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) );
139 bFoundNumberingRulesName = true;
140 break;
147 if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
149 for( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin(); pProp != rProperties.end(); ++pProp )
151 if (pProp->mnIndex > -1)
153 rtl::Reference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
154 sal_Int32 nIndex = pProp->mnIndex;
155 sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
156 switch( nContextID )
158 case CTF_PM_PAGEUSAGE:
160 OUString sValue;
161 const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex );
162 if( pPropHdl &&
163 pPropHdl->exportXML( sValue, pProp->maValue,
164 GetExport().GetMM100UnitConverter() ) &&
165 ( ! IsXMLToken( sValue, XML_ALL ) ) )
167 GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
170 break;
177 void SvXMLAutoStylePoolP::exportStyleContent(
178 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
179 sal_Int32 nFamily,
180 const vector< XMLPropertyState >& rProperties,
181 const SvXMLExportPropertyMapper& rPropExp,
182 const SvXMLUnitConverter&,
183 const SvXMLNamespaceMap&
184 ) const
186 if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
188 sal_Int32 nHeaderStartIndex(-1);
189 sal_Int32 nHeaderEndIndex(-1);
190 sal_Int32 nFooterStartIndex(-1);
191 sal_Int32 nFooterEndIndex(-1);
192 bool bHeaderStartIndex(false);
193 bool bHeaderEndIndex(false);
194 bool bFooterStartIndex(false);
195 bool bFooterEndIndex(false);
197 rtl::Reference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
199 sal_Int32 nIndex(0);
200 while(nIndex < aPropMapper->GetEntryCount())
202 switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
204 case CTF_PM_HEADERFLAG:
206 if (!bHeaderStartIndex)
208 nHeaderStartIndex = nIndex;
209 bHeaderStartIndex = true;
211 if (bFooterStartIndex && !bFooterEndIndex)
213 nFooterEndIndex = nIndex;
214 bFooterEndIndex = true;
217 break;
218 case CTF_PM_FOOTERFLAG:
220 if (!bFooterStartIndex)
222 nFooterStartIndex = nIndex;
223 bFooterStartIndex = true;
225 if (bHeaderStartIndex && !bHeaderEndIndex)
227 nHeaderEndIndex = nIndex;
228 bHeaderEndIndex = true;
231 break;
233 nIndex++;
235 if (!bHeaderEndIndex)
236 nHeaderEndIndex = nIndex;
237 if (!bFooterEndIndex)
238 nFooterEndIndex = nIndex;
240 // export header style element
242 SvXMLElementExport aElem(
243 GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE,
244 true, true );
246 rPropExp.exportXML(
247 GetExport(), rProperties,
248 nHeaderStartIndex, nHeaderEndIndex, SvXmlExportFlags::IGN_WS);
251 // export footer style
253 SvXMLElementExport aElem(
254 GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE,
255 true, true );
257 rPropExp.exportXML(
258 GetExport(), rProperties,
259 nFooterStartIndex, nFooterEndIndex, SvXmlExportFlags::IGN_WS);
264 SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport )
266 pImpl = new SvXMLAutoStylePoolP_Impl( rExport );
269 SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
271 delete pImpl;
274 SvXMLExport& SvXMLAutoStylePoolP::GetExport() const
276 return pImpl->GetExport();
279 // TODO: romove this
280 void SvXMLAutoStylePoolP::AddFamily(
281 sal_Int32 nFamily,
282 const OUString& rStrName,
283 SvXMLExportPropertyMapper* pMapper,
284 const OUString& aStrPrefix,
285 bool bAsFamily )
287 rtl::Reference <SvXMLExportPropertyMapper> xTmp = pMapper;
288 AddFamily( nFamily, rStrName, xTmp, aStrPrefix, bAsFamily );
291 void SvXMLAutoStylePoolP::AddFamily(
292 sal_Int32 nFamily,
293 const OUString& rStrName,
294 const rtl::Reference < SvXMLExportPropertyMapper > & rMapper,
295 const OUString& rStrPrefix,
296 bool bAsFamily )
298 pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
301 void SvXMLAutoStylePoolP::SetFamilyPropSetMapper(
302 sal_Int32 nFamily,
303 const rtl::Reference < SvXMLExportPropertyMapper > & rMapper )
305 pImpl->SetFamilyPropSetMapper( nFamily, rMapper );
308 void SvXMLAutoStylePoolP::RegisterName( sal_Int32 nFamily,
309 const OUString& rName )
311 pImpl->RegisterName( nFamily, rName );
314 void SvXMLAutoStylePoolP::GetRegisteredNames(
315 uno::Sequence<sal_Int32>& rFamilies,
316 uno::Sequence<OUString>& rNames )
318 pImpl->GetRegisteredNames( rFamilies, rNames );
321 void SvXMLAutoStylePoolP::RegisterNames(
322 uno::Sequence<sal_Int32>& aFamilies,
323 uno::Sequence<OUString>& aNames )
325 assert(aFamilies.getLength() == aNames.getLength());
327 // iterate over sequence(s) and call RegisterName(..) for each pair
328 const sal_Int32* pFamilies = aFamilies.getConstArray();
329 const OUString* pNames = aNames.getConstArray();
330 sal_Int32 nCount = min( aFamilies.getLength(), aNames.getLength() );
331 for( sal_Int32 n = 0; n < nCount; n++ )
332 RegisterName( pFamilies[n], pNames[n] );
335 OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
336 const vector< XMLPropertyState >& rProperties )
338 OUString sEmpty;
339 OUString sName;
340 pImpl->Add(sName, nFamily, sEmpty, rProperties );
341 return sName;
344 OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
345 const OUString& rParent,
346 const vector< XMLPropertyState >& rProperties, bool bDontSeek )
348 OUString sName;
349 pImpl->Add(sName, nFamily, rParent, rProperties, bDontSeek);
350 return sName;
353 bool SvXMLAutoStylePoolP::Add(OUString& rName, sal_Int32 nFamily, const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties )
355 return pImpl->Add(rName, nFamily, rParent, rProperties);
358 bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, sal_Int32 nFamily, const OUString& rParent,
359 const ::std::vector< XMLPropertyState >& rProperties )
362 return pImpl->AddNamed(rName, nFamily, rParent, rProperties);
365 OUString SvXMLAutoStylePoolP::Find( sal_Int32 nFamily,
366 const OUString& rParent,
367 const vector< XMLPropertyState >& rProperties ) const
369 return pImpl->Find( nFamily, rParent, rProperties );
372 void SvXMLAutoStylePoolP::exportXML( sal_Int32 nFamily,
373 const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
374 const SvXMLUnitConverter&,
375 const SvXMLNamespaceMap&
376 ) const
378 pImpl->exportXML( nFamily,
379 GetExport().GetDocHandler(),
380 GetExport().GetMM100UnitConverter(),
381 GetExport().GetNamespaceMap(),
382 this);
385 void SvXMLAutoStylePoolP::ClearEntries()
387 pImpl->ClearEntries();
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */