update credits
[LibreOffice.git] / xmloff / source / style / xmlaustp.cxx
blobef4718b309a98d70a2a470d38ab38c9f8208c244
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/XMLTextListAutoStylePool.hxx"
30 #include <xmloff/PageMasterStyleMap.hxx>
31 #include "PageMasterExportPropMapper.hxx"
32 #include "XMLBackgroundImageExport.hxx"
35 using namespace ::std;
37 using namespace ::com::sun::star;
38 using namespace ::xmloff::token;
41 namespace
43 static void lcl_exportDataStyle( SvXMLExport& _rExport, const UniReference< XMLPropertySetMapper >& _rxMapper,
44 const XMLPropertyState& _rProperty )
46 DBG_ASSERT( _rxMapper.is(), "xmloff::lcl_exportDataStyle: invalid property mapper!" );
47 // obtain the data style name
48 OUString sDataStyleName;
49 _rProperty.maValue >>= sDataStyleName;
50 DBG_ASSERT( !sDataStyleName.isEmpty(), "xmloff::lcl_exportDataStyle: invalid property value for the data style name!" );
52 // add the attribute
53 _rExport.AddAttribute(
54 _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
55 _rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
56 sDataStyleName );
60 void SvXMLAutoStylePoolP::exportStyleAttributes(
61 SvXMLAttributeList&,
62 sal_Int32 nFamily,
63 const vector< XMLPropertyState >& rProperties,
64 const SvXMLExportPropertyMapper& rPropExp,
65 const SvXMLUnitConverter&,
66 const SvXMLNamespaceMap&
67 ) const
69 if ( XML_STYLE_FAMILY_CONTROL_ID == nFamily )
70 { // it's a control-related style
71 UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
73 for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
74 pProp != rProperties.end();
75 ++pProp
78 if ( ( pProp->mnIndex > -1 )
79 && ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( pProp->mnIndex ) )
81 { // it's the data-style for a grid column
82 lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
87 if( (XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily) || (XML_STYLE_FAMILY_SD_PRESENTATION_ID == nFamily) )
88 { // it's a graphics style
89 UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
90 DBG_ASSERT(aPropertyMapper.is(), "SvXMLAutoStylePoolP::exportStyleAttributes: invalid property set mapper!");
92 sal_Bool bFoundControlShapeDataStyle = sal_False;
93 sal_Bool bFoundNumberingRulesName = sal_False;
95 for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
96 pProp != rProperties.end();
97 ++pProp
100 if (pProp->mnIndex > -1)
101 { // it's a valid property
102 switch( aPropertyMapper->GetEntryContextId(pProp->mnIndex) )
104 case CTF_SD_CONTROL_SHAPE_DATA_STYLE:
105 { // it's the control shape data style property
107 if (bFoundControlShapeDataStyle)
109 OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
110 // already added the attribute for the first occurrence
111 break;
114 lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
116 // check if there is another property with the special context id we're handling here
117 bFoundControlShapeDataStyle = sal_True;
118 break;
120 case CTF_SD_NUMBERINGRULES_NAME:
122 if (bFoundNumberingRulesName)
124 OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!");
125 // already added the attribute for the first occurrence
126 break;
129 uno::Reference< container::XIndexReplace > xNumRule;
130 pProp->maValue >>= xNumRule;
131 if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
133 const OUString sName(((XMLTextListAutoStylePool*)&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
135 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) );
138 bFoundNumberingRulesName = sal_True;
139 break;
146 if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
148 for( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin(); pProp != rProperties.end(); ++pProp )
150 if (pProp->mnIndex > -1)
152 UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
153 sal_Int32 nIndex = pProp->mnIndex;
154 sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
155 switch( nContextID )
157 case CTF_PM_PAGEUSAGE:
159 OUString sValue;
160 const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex );
161 if( pPropHdl &&
162 pPropHdl->exportXML( sValue, pProp->maValue,
163 GetExport().GetMM100UnitConverter() ) &&
164 ( ! IsXMLToken( sValue, XML_ALL ) ) )
166 GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
169 break;
176 void SvXMLAutoStylePoolP::exportStyleContent(
177 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
178 sal_Int32 nFamily,
179 const vector< XMLPropertyState >& rProperties,
180 const SvXMLExportPropertyMapper& rPropExp,
181 const SvXMLUnitConverter&,
182 const SvXMLNamespaceMap&
183 ) const
185 if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
187 sal_Int32 nHeaderStartIndex(-1);
188 sal_Int32 nHeaderEndIndex(-1);
189 sal_Int32 nFooterStartIndex(-1);
190 sal_Int32 nFooterEndIndex(-1);
191 sal_Bool bHeaderStartIndex(sal_False);
192 sal_Bool bHeaderEndIndex(sal_False);
193 sal_Bool bFooterStartIndex(sal_False);
194 sal_Bool bFooterEndIndex(sal_False);
196 UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
198 sal_Int32 nIndex(0);
199 while(nIndex < aPropMapper->GetEntryCount())
201 switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
203 case CTF_PM_HEADERFLAG:
205 if (!bHeaderStartIndex)
207 nHeaderStartIndex = nIndex;
208 bHeaderStartIndex = sal_True;
210 if (bFooterStartIndex && !bFooterEndIndex)
212 nFooterEndIndex = nIndex;
213 bFooterEndIndex = sal_True;
216 break;
217 case CTF_PM_FOOTERFLAG:
219 if (!bFooterStartIndex)
221 nFooterStartIndex = nIndex;
222 bFooterStartIndex = sal_True;
224 if (bHeaderStartIndex && !bHeaderEndIndex)
226 nHeaderEndIndex = nIndex;
227 bHeaderEndIndex = sal_True;
230 break;
232 nIndex++;
234 if (!bHeaderEndIndex)
235 nHeaderEndIndex = nIndex;
236 if (!bFooterEndIndex)
237 nFooterEndIndex = nIndex;
239 // export header style element
241 SvXMLElementExport aElem(
242 GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE,
243 sal_True, sal_True );
245 rPropExp.exportXML(
246 GetExport(), rProperties,
247 nHeaderStartIndex, nHeaderEndIndex, XML_EXPORT_FLAG_IGN_WS);
250 // export footer style
252 SvXMLElementExport aElem(
253 GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE,
254 sal_True, sal_True );
256 rPropExp.exportXML(
257 GetExport(), rProperties,
258 nFooterStartIndex, nFooterEndIndex, XML_EXPORT_FLAG_IGN_WS);
263 SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport )
265 pImpl = new SvXMLAutoStylePoolP_Impl( rExport );
268 SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
270 delete pImpl;
273 SvXMLExport& SvXMLAutoStylePoolP::GetExport() const
275 return pImpl->GetExport();
278 // TODO: romove this
279 void SvXMLAutoStylePoolP::AddFamily(
280 sal_Int32 nFamily,
281 const OUString& rStrName,
282 SvXMLExportPropertyMapper* pMapper,
283 OUString aStrPrefix,
284 sal_Bool bAsFamily )
286 UniReference <SvXMLExportPropertyMapper> xTmp = pMapper;
287 AddFamily( nFamily, rStrName, xTmp, aStrPrefix, bAsFamily );
290 void SvXMLAutoStylePoolP::AddFamily(
291 sal_Int32 nFamily,
292 const OUString& rStrName,
293 const UniReference < SvXMLExportPropertyMapper > & rMapper,
294 const OUString& rStrPrefix,
295 sal_Bool bAsFamily )
297 pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
300 void SvXMLAutoStylePoolP::SetFamilyPropSetMapper(
301 sal_Int32 nFamily,
302 const UniReference < SvXMLExportPropertyMapper > & rMapper )
304 pImpl->SetFamilyPropSetMapper( nFamily, rMapper );
307 void SvXMLAutoStylePoolP::RegisterName( sal_Int32 nFamily,
308 const OUString& rName )
310 pImpl->RegisterName( nFamily, rName );
313 void SvXMLAutoStylePoolP::GetRegisteredNames(
314 uno::Sequence<sal_Int32>& rFamilies,
315 uno::Sequence<OUString>& rNames )
317 pImpl->GetRegisteredNames( rFamilies, rNames );
320 void SvXMLAutoStylePoolP::RegisterNames(
321 uno::Sequence<sal_Int32>& aFamilies,
322 uno::Sequence<OUString>& aNames )
324 DBG_ASSERT( aFamilies.getLength() == aNames.getLength(),
325 "aFamilies != aNames" );
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, sal_False, bDontSeek );
350 return sName;
353 sal_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 sal_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: */