Update ooo320-m1
[ooovba.git] / xmloff / source / style / xmlaustp.cxx
blob4ed59fd0924171906602f177a94225dd66b020ea
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlaustp.cxx,v $
10 * $Revision: 1.26 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include <com/sun/star/container/XIndexReplace.hpp>
36 #include <tools/debug.hxx>
37 #include "impastpl.hxx"
38 #include <xmloff/xmlaustp.hxx>
39 #include <xmloff/families.hxx>
40 #include "xmlnmspe.hxx"
41 #include <xmloff/xmltoken.hxx>
42 #include <xmloff/xmlexp.hxx>
43 #include "XMLTextListAutoStylePool.hxx"
45 #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX
46 #include <xmloff/PageMasterStyleMap.hxx>
47 #endif
48 #include "PageMasterExportPropMapper.hxx"
49 #include "XMLBackgroundImageExport.hxx"
52 using namespace ::std;
53 using ::rtl::OUString;
54 using ::rtl::OUStringBuffer;
56 using namespace ::com::sun::star;
57 using namespace ::xmloff::token;
60 namespace
62 static void lcl_exportDataStyle( SvXMLExport& _rExport, const UniReference< XMLPropertySetMapper >& _rxMapper,
63 const XMLPropertyState& _rProperty )
65 DBG_ASSERT( _rxMapper.is(), "xmloff::lcl_exportDataStyle: invalid property mapper!" );
66 // obtain the data style name
67 ::rtl::OUString sDataStyleName;
68 _rProperty.maValue >>= sDataStyleName;
69 DBG_ASSERT( sDataStyleName.getLength(), "xmloff::lcl_exportDataStyle: invalid property value for the data style name!" );
71 // add the attribute
72 _rExport.AddAttribute(
73 _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
74 _rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
75 sDataStyleName );
79 void SvXMLAutoStylePoolP::exportStyleAttributes(
80 SvXMLAttributeList&,
81 sal_Int32 nFamily,
82 const vector< XMLPropertyState >& rProperties,
83 const SvXMLExportPropertyMapper& rPropExp,
84 const SvXMLUnitConverter&,
85 const SvXMLNamespaceMap&
86 ) const
88 if ( XML_STYLE_FAMILY_CONTROL_ID == nFamily )
89 { // it's a control-related style
90 UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
92 for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
93 pProp != rProperties.end();
94 ++pProp
97 if ( ( pProp->mnIndex > -1 )
98 && ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( pProp->mnIndex ) )
100 { // it's the data-style for a grid column
101 lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
106 if( (XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily) || (XML_STYLE_FAMILY_SD_PRESENTATION_ID == nFamily) )
107 { // it's a graphics style
108 UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
109 DBG_ASSERT(aPropertyMapper.is(), "SvXMLAutoStylePoolP::exportStyleAttributes: invalid property set mapper!");
111 sal_Bool bFoundControlShapeDataStyle = sal_False;
112 sal_Bool bFoundNumberingRulesName = sal_False;
114 for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
115 pProp != rProperties.end();
116 ++pProp
119 if (pProp->mnIndex > -1)
120 { // it's a valid property
121 switch( aPropertyMapper->GetEntryContextId(pProp->mnIndex) )
123 case CTF_SD_CONTROL_SHAPE_DATA_STYLE:
124 { // it's the control shape data style property
126 if (bFoundControlShapeDataStyle)
128 DBG_ERROR("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
129 // already added the attribute for the first occurence
130 break;
133 lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
135 // check if there is another property with the special context id we're handling here
136 bFoundControlShapeDataStyle = sal_True;
137 break;
139 case CTF_SD_NUMBERINGRULES_NAME:
141 if (bFoundNumberingRulesName)
143 DBG_ERROR("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!");
144 // already added the attribute for the first occurence
145 break;
148 uno::Reference< container::XIndexReplace > xNumRule;
149 pProp->maValue >>= xNumRule;
150 if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
152 const OUString sName(((XMLTextListAutoStylePool*)&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
154 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) );
157 bFoundNumberingRulesName = sal_True;
158 break;
165 if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
167 for( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin(); pProp != rProperties.end(); pProp++ )
169 if (pProp->mnIndex > -1)
171 UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
172 sal_Int32 nIndex = pProp->mnIndex;
173 sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
174 switch( nContextID )
176 case CTF_PM_PAGEUSAGE:
178 OUString sValue;
179 const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex );
180 if( pPropHdl &&
181 pPropHdl->exportXML( sValue, pProp->maValue,
182 GetExport().GetMM100UnitConverter() ) &&
183 ( ! IsXMLToken( sValue, XML_ALL ) ) )
185 GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
188 break;
195 void SvXMLAutoStylePoolP::exportStyleContent(
196 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
197 sal_Int32 nFamily,
198 const vector< XMLPropertyState >& rProperties,
199 const SvXMLExportPropertyMapper& rPropExp,
200 const SvXMLUnitConverter&,
201 const SvXMLNamespaceMap&
202 ) const
204 if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
206 OUString sWS( GetXMLToken(XML_WS) );
208 sal_Int32 nHeaderStartIndex(-1);
209 sal_Int32 nHeaderEndIndex(-1);
210 sal_Int32 nFooterStartIndex(-1);
211 sal_Int32 nFooterEndIndex(-1);
212 sal_Bool bHeaderStartIndex(sal_False);
213 sal_Bool bHeaderEndIndex(sal_False);
214 sal_Bool bFooterStartIndex(sal_False);
215 sal_Bool bFooterEndIndex(sal_False);
217 UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
219 sal_Int32 nIndex(0);
220 while(nIndex < aPropMapper->GetEntryCount())
222 switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
224 case CTF_PM_HEADERFLAG:
226 if (!bHeaderStartIndex)
228 nHeaderStartIndex = nIndex;
229 bHeaderStartIndex = sal_True;
231 if (bFooterStartIndex && !bFooterEndIndex)
233 nFooterEndIndex = nIndex;
234 bFooterEndIndex = sal_True;
237 break;
238 case CTF_PM_FOOTERFLAG:
240 if (!bFooterStartIndex)
242 nFooterStartIndex = nIndex;
243 bFooterStartIndex = sal_True;
245 if (bHeaderStartIndex && !bHeaderEndIndex)
247 nHeaderEndIndex = nIndex;
248 bHeaderEndIndex = sal_True;
251 break;
253 nIndex++;
255 if (!bHeaderEndIndex)
256 nHeaderEndIndex = nIndex;
257 if (!bFooterEndIndex)
258 nFooterEndIndex = nIndex;
260 // export header style element
262 SvXMLElementExport aElem(
263 GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE,
264 sal_True, sal_True );
266 rPropExp.exportXML(
267 GetExport(), rProperties,
268 nHeaderStartIndex, nHeaderEndIndex, XML_EXPORT_FLAG_IGN_WS);
271 // export footer style
273 SvXMLElementExport aElem(
274 GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE,
275 sal_True, sal_True );
277 rPropExp.exportXML(
278 GetExport(), rProperties,
279 nFooterStartIndex, nFooterEndIndex, XML_EXPORT_FLAG_IGN_WS);
284 SvXMLAutoStylePoolP::SvXMLAutoStylePoolP()
286 DBG_ERROR("This constuctor is obsoleted and should not be used!");
287 pImpl = NULL;
290 SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport )
292 pImpl = new SvXMLAutoStylePoolP_Impl( rExport );
295 SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
297 delete pImpl;
300 SvXMLExport& SvXMLAutoStylePoolP::GetExport() const
302 return pImpl->GetExport();
305 // TODO: romove this
306 void SvXMLAutoStylePoolP::AddFamily(
307 sal_Int32 nFamily,
308 const OUString& rStrName,
309 SvXMLExportPropertyMapper* pMapper,
310 OUString aStrPrefix,
311 sal_Bool bAsFamily )
313 UniReference <SvXMLExportPropertyMapper> xTmp = pMapper;
314 AddFamily( nFamily, rStrName, xTmp, aStrPrefix, bAsFamily );
317 void SvXMLAutoStylePoolP::AddFamily(
318 sal_Int32 nFamily,
319 const OUString& rStrName,
320 const UniReference < SvXMLExportPropertyMapper > & rMapper,
321 const OUString& rStrPrefix,
322 sal_Bool bAsFamily )
324 pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
327 void SvXMLAutoStylePoolP::RegisterName( sal_Int32 nFamily,
328 const OUString& rName )
330 pImpl->RegisterName( nFamily, rName );
333 void SvXMLAutoStylePoolP::GetRegisteredNames(
334 uno::Sequence<sal_Int32>& rFamilies,
335 uno::Sequence<OUString>& rNames )
337 pImpl->GetRegisteredNames( rFamilies, rNames );
340 void SvXMLAutoStylePoolP::RegisterNames(
341 uno::Sequence<sal_Int32>& aFamilies,
342 uno::Sequence<OUString>& aNames )
344 DBG_ASSERT( aFamilies.getLength() == aNames.getLength(),
345 "aFamilies != aNames" );
347 // iterate over sequence(s) and call RegisterName(..) for each pair
348 const sal_Int32* pFamilies = aFamilies.getConstArray();
349 const OUString* pNames = aNames.getConstArray();
350 sal_Int32 nCount = min( aFamilies.getLength(), aNames.getLength() );
351 for( sal_Int32 n = 0; n < nCount; n++ )
352 RegisterName( pFamilies[n], pNames[n] );
355 OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
356 const vector< XMLPropertyState >& rProperties )
358 OUString sEmpty;
359 OUString sName;
360 pImpl->Add(sName, nFamily, sEmpty, rProperties );
361 return sName;
364 OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
365 const OUString& rParent,
366 const vector< XMLPropertyState >& rProperties, bool bDontSeek )
368 OUString sName;
369 pImpl->Add(sName, nFamily, rParent, rProperties, sal_False, bDontSeek );
370 return sName;
373 sal_Bool SvXMLAutoStylePoolP::Add(OUString& rName, sal_Int32 nFamily, const ::std::vector< XMLPropertyState >& rProperties )
375 OUString sEmpty;
376 return pImpl->Add(rName, nFamily, sEmpty, rProperties);
379 sal_Bool SvXMLAutoStylePoolP::Add(OUString& rName, sal_Int32 nFamily, const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties )
381 return pImpl->Add(rName, nFamily, rParent, rProperties);
384 sal_Bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, sal_Int32 nFamily, const OUString& rParent,
385 const ::std::vector< XMLPropertyState >& rProperties )
388 return pImpl->AddNamed(rName, nFamily, rParent, rProperties);
391 OUString SvXMLAutoStylePoolP::AddAndCache( sal_Int32 nFamily,
392 const vector< XMLPropertyState >& rProperties )
394 OUString sEmpty;
395 OUString sName;
396 pImpl->Add(sName, nFamily, sEmpty, rProperties, sal_True );
397 return sName;
400 OUString SvXMLAutoStylePoolP::AddAndCache( sal_Int32 nFamily,
401 const OUString& rParent,
402 const vector< XMLPropertyState >& rProperties )
404 OUString sName;
405 pImpl->Add(sName, nFamily, rParent, rProperties, sal_True );
406 return sName;
409 OUString SvXMLAutoStylePoolP::AddAndCache( sal_Int32 nFamily,
410 const OUString& rParent )
412 return pImpl->AddToCache( nFamily, rParent );
415 OUString SvXMLAutoStylePoolP::Find( sal_Int32 nFamily,
416 const vector< XMLPropertyState >& rProperties ) const
418 OUString sEmpty;
419 return pImpl->Find( nFamily, sEmpty, rProperties );
422 OUString SvXMLAutoStylePoolP::Find( sal_Int32 nFamily,
423 const OUString& rParent,
424 const vector< XMLPropertyState >& rProperties ) const
426 return pImpl->Find( nFamily, rParent, rProperties );
429 OUString SvXMLAutoStylePoolP::FindAndRemoveCached( sal_Int32 nFamily ) const
431 return pImpl->FindAndRemoveCached( nFamily );
435 void SvXMLAutoStylePoolP::exportXML( sal_Int32 nFamily,
436 const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
437 const SvXMLUnitConverter&,
438 const SvXMLNamespaceMap&
439 ) const
441 pImpl->exportXML( nFamily,
442 GetExport().GetDocHandler(),
443 GetExport().GetMM100UnitConverter(),
444 GetExport().GetNamespaceMap(),
445 this);
448 void SvXMLAutoStylePoolP::ClearEntries()
450 pImpl->ClearEntries();