Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/container/XIndexReplace.hpp>
30 : : #include <tools/debug.hxx>
31 : : #include "impastpl.hxx"
32 : : #include <xmloff/xmlaustp.hxx>
33 : : #include <xmloff/families.hxx>
34 : : #include "xmloff/xmlnmspe.hxx"
35 : : #include <xmloff/xmltoken.hxx>
36 : : #include <xmloff/xmlexp.hxx>
37 : : #include "xmloff/XMLTextListAutoStylePool.hxx"
38 : :
39 : : #include <xmloff/PageMasterStyleMap.hxx>
40 : : #include "PageMasterExportPropMapper.hxx"
41 : : #include "XMLBackgroundImageExport.hxx"
42 : :
43 : :
44 : : using namespace ::std;
45 : : using ::rtl::OUString;
46 : : using ::rtl::OUStringBuffer;
47 : :
48 : : using namespace ::com::sun::star;
49 : : using namespace ::xmloff::token;
50 : :
51 : :
52 : : namespace
53 : : {
54 : 0 : static void lcl_exportDataStyle( SvXMLExport& _rExport, const UniReference< XMLPropertySetMapper >& _rxMapper,
55 : : const XMLPropertyState& _rProperty )
56 : : {
57 : : DBG_ASSERT( _rxMapper.is(), "xmloff::lcl_exportDataStyle: invalid property mapper!" );
58 : : // obtain the data style name
59 : 0 : ::rtl::OUString sDataStyleName;
60 : 0 : _rProperty.maValue >>= sDataStyleName;
61 : : DBG_ASSERT( !sDataStyleName.isEmpty(), "xmloff::lcl_exportDataStyle: invalid property value for the data style name!" );
62 : :
63 : : // add the attribute
64 : : _rExport.AddAttribute(
65 [ # # ][ # # ]: 0 : _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
66 [ # # ][ # # ]: 0 : _rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
67 [ # # ]: 0 : sDataStyleName );
68 : 0 : }
69 : : }
70 : :
71 : 250 : void SvXMLAutoStylePoolP::exportStyleAttributes(
72 : : SvXMLAttributeList&,
73 : : sal_Int32 nFamily,
74 : : const vector< XMLPropertyState >& rProperties,
75 : : const SvXMLExportPropertyMapper& rPropExp,
76 : : const SvXMLUnitConverter&,
77 : : const SvXMLNamespaceMap&
78 : : ) const
79 : : {
80 [ - + ]: 250 : if ( XML_STYLE_FAMILY_CONTROL_ID == nFamily )
81 : : { // it's a control-related style
82 [ # # ]: 0 : UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
83 : :
84 [ # # ][ # # ]: 0 : for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
85 : 0 : pProp != rProperties.end();
86 : : ++pProp
87 : : )
88 : : {
89 [ # # ][ # # ]: 0 : if ( ( pProp->mnIndex > -1 )
[ # # ]
90 [ # # ][ # # ]: 0 : && ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( pProp->mnIndex ) )
91 : : )
92 : : { // it's the data-style for a grid column
93 [ # # ][ # # ]: 0 : lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
94 : : }
95 [ # # ]: 0 : }
96 : : }
97 : :
98 [ + + ][ + + ]: 250 : if( (XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily) || (XML_STYLE_FAMILY_SD_PRESENTATION_ID == nFamily) )
99 : : { // it's a graphics style
100 [ + - ]: 36 : UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
101 : : DBG_ASSERT(aPropertyMapper.is(), "SvXMLAutoStylePoolP::exportStyleAttributes: invalid property set mapper!");
102 : :
103 : 36 : sal_Bool bFoundControlShapeDataStyle = sal_False;
104 : 36 : sal_Bool bFoundNumberingRulesName = sal_False;
105 : :
106 [ + - ][ + + ]: 536 : for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
107 : 268 : pProp != rProperties.end();
108 : : ++pProp
109 : : )
110 : : {
111 [ + + ]: 232 : if (pProp->mnIndex > -1)
112 : : { // it's a valid property
113 [ + - ][ + - ]: 132 : switch( aPropertyMapper->GetEntryContextId(pProp->mnIndex) )
[ - - + ]
114 : : {
115 : : case CTF_SD_CONTROL_SHAPE_DATA_STYLE:
116 : : { // it's the control shape data style property
117 : :
118 [ # # ]: 0 : if (bFoundControlShapeDataStyle)
119 : : {
120 : : OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
121 : : // already added the attribute for the first occurrence
122 : 0 : break;
123 : : }
124 : :
125 [ # # ][ # # ]: 0 : lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
126 : :
127 : : // check if there is another property with the special context id we're handling here
128 : 0 : bFoundControlShapeDataStyle = sal_True;
129 : 0 : break;
130 : : }
131 : : case CTF_SD_NUMBERINGRULES_NAME:
132 : : {
133 [ # # ]: 0 : if (bFoundNumberingRulesName)
134 : : {
135 : : OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!");
136 : : // already added the attribute for the first occurrence
137 : : break;
138 : : }
139 : :
140 : 0 : uno::Reference< container::XIndexReplace > xNumRule;
141 [ # # ]: 0 : pProp->maValue >>= xNumRule;
142 [ # # ][ # # ]: 0 : if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
[ # # ][ # # ]
[ # # ]
143 : : {
144 [ # # ][ # # ]: 0 : const OUString sName(((XMLTextListAutoStylePool*)&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
[ # # ][ # # ]
[ # # ]
145 : :
146 [ # # ][ # # ]: 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) );
[ # # ][ # # ]
147 : : }
148 : :
149 : 0 : bFoundNumberingRulesName = sal_True;
150 : 132 : break;
151 : : }
152 : : }
153 : : }
154 [ + - ]: 36 : }
155 : : }
156 : :
157 [ + + ]: 250 : if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
158 : : {
159 [ + - ][ + + ]: 848 : for( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin(); pProp != rProperties.end(); ++pProp )
160 : : {
161 [ + + ]: 816 : if (pProp->mnIndex > -1)
162 : : {
163 [ + - ]: 661 : UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
164 : 661 : sal_Int32 nIndex = pProp->mnIndex;
165 [ + - ][ + - ]: 661 : sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
166 [ + + ]: 661 : switch( nContextID )
167 : : {
168 : : case CTF_PM_PAGEUSAGE:
169 : : {
170 : 24 : OUString sValue;
171 [ + - ][ + - ]: 24 : const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex );
172 [ + - ][ + - ]: 72 : if( pPropHdl &&
[ + - ][ + - ]
173 : 24 : pPropHdl->exportXML( sValue, pProp->maValue,
174 [ + - ][ + - ]: 48 : GetExport().GetMM100UnitConverter() ) &&
175 [ + - ]: 24 : ( ! IsXMLToken( sValue, XML_ALL ) ) )
176 : : {
177 [ + - ][ + - ]: 24 : GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
[ + - ][ + - ]
[ + - ][ + - ]
178 : 24 : }
179 : : }
180 : 24 : break;
181 [ + - ]: 661 : }
182 : : }
183 : : }
184 : : }
185 : 250 : }
186 : :
187 : 250 : void SvXMLAutoStylePoolP::exportStyleContent(
188 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
189 : : sal_Int32 nFamily,
190 : : const vector< XMLPropertyState >& rProperties,
191 : : const SvXMLExportPropertyMapper& rPropExp,
192 : : const SvXMLUnitConverter&,
193 : : const SvXMLNamespaceMap&
194 : : ) const
195 : : {
196 [ + + ]: 250 : if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
197 : : {
198 [ + - ]: 32 : OUString sWS( GetXMLToken(XML_WS) );
199 : :
200 : 32 : sal_Int32 nHeaderStartIndex(-1);
201 : 32 : sal_Int32 nHeaderEndIndex(-1);
202 : 32 : sal_Int32 nFooterStartIndex(-1);
203 : 32 : sal_Int32 nFooterEndIndex(-1);
204 : 32 : sal_Bool bHeaderStartIndex(sal_False);
205 : 32 : sal_Bool bHeaderEndIndex(sal_False);
206 : 32 : sal_Bool bFooterStartIndex(sal_False);
207 : 32 : sal_Bool bFooterEndIndex(sal_False);
208 : :
209 [ + - ]: 32 : UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
210 : :
211 : 32 : sal_Int32 nIndex(0);
212 [ + - ][ + + ]: 4256 : while(nIndex < aPropMapper->GetEntryCount())
213 : : {
214 [ + - ][ + - ]: 4224 : switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
[ + + + ]
215 : : {
216 : : case CTF_PM_HEADERFLAG:
217 : : {
218 [ + + ]: 928 : if (!bHeaderStartIndex)
219 : : {
220 : 32 : nHeaderStartIndex = nIndex;
221 : 32 : bHeaderStartIndex = sal_True;
222 : : }
223 [ - + ][ # # ]: 928 : if (bFooterStartIndex && !bFooterEndIndex)
224 : : {
225 : 0 : nFooterEndIndex = nIndex;
226 : 0 : bFooterEndIndex = sal_True;
227 : : }
228 : : }
229 : 928 : break;
230 : : case CTF_PM_FOOTERFLAG:
231 : : {
232 [ + + ]: 928 : if (!bFooterStartIndex)
233 : : {
234 : 32 : nFooterStartIndex = nIndex;
235 : 32 : bFooterStartIndex = sal_True;
236 : : }
237 [ + - ][ + + ]: 928 : if (bHeaderStartIndex && !bHeaderEndIndex)
238 : : {
239 : 32 : nHeaderEndIndex = nIndex;
240 : 32 : bHeaderEndIndex = sal_True;
241 : : }
242 : : }
243 : 928 : break;
244 : : }
245 : 4224 : nIndex++;
246 : : }
247 [ - + ]: 32 : if (!bHeaderEndIndex)
248 : 0 : nHeaderEndIndex = nIndex;
249 [ + - ]: 32 : if (!bFooterEndIndex)
250 : 32 : nFooterEndIndex = nIndex;
251 : :
252 : : // export header style element
253 : : {
254 : : SvXMLElementExport aElem(
255 [ + - ]: 32 : GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE,
256 [ + - ]: 32 : sal_True, sal_True );
257 : :
258 : : rPropExp.exportXML(
259 [ + - ]: 32 : GetExport(), rProperties,
260 [ + - ][ + - ]: 32 : nHeaderStartIndex, nHeaderEndIndex, XML_EXPORT_FLAG_IGN_WS);
261 : : }
262 : :
263 : : // export footer style
264 : : {
265 : : SvXMLElementExport aElem(
266 [ + - ]: 32 : GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE,
267 [ + - ]: 32 : sal_True, sal_True );
268 : :
269 : : rPropExp.exportXML(
270 [ + - ]: 32 : GetExport(), rProperties,
271 [ + - ][ + - ]: 32 : nFooterStartIndex, nFooterEndIndex, XML_EXPORT_FLAG_IGN_WS);
272 [ + - ]: 32 : }
273 : : }
274 : 250 : }
275 : :
276 : 496 : SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport )
277 : : {
278 [ + - ][ + - ]: 496 : pImpl = new SvXMLAutoStylePoolP_Impl( rExport );
279 : 496 : }
280 : :
281 : 496 : SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
282 : : {
283 [ + - ][ + - ]: 496 : delete pImpl;
284 [ - + ]: 553 : }
285 : :
286 : 4414 : SvXMLExport& SvXMLAutoStylePoolP::GetExport() const
287 : : {
288 : 4414 : return pImpl->GetExport();
289 : : }
290 : :
291 : : // TODO: romove this
292 : 2038 : void SvXMLAutoStylePoolP::AddFamily(
293 : : sal_Int32 nFamily,
294 : : const OUString& rStrName,
295 : : SvXMLExportPropertyMapper* pMapper,
296 : : OUString aStrPrefix,
297 : : sal_Bool bAsFamily )
298 : : {
299 [ + - ]: 2038 : UniReference <SvXMLExportPropertyMapper> xTmp = pMapper;
300 [ + - ][ + - ]: 2038 : AddFamily( nFamily, rStrName, xTmp, aStrPrefix, bAsFamily );
301 : 2038 : }
302 : :
303 : 2750 : void SvXMLAutoStylePoolP::AddFamily(
304 : : sal_Int32 nFamily,
305 : : const OUString& rStrName,
306 : : const UniReference < SvXMLExportPropertyMapper > & rMapper,
307 : : const OUString& rStrPrefix,
308 : : sal_Bool bAsFamily )
309 : : {
310 : 2750 : pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
311 : 2750 : }
312 : :
313 : 0 : void SvXMLAutoStylePoolP::SetFamilyPropSetMapper(
314 : : sal_Int32 nFamily,
315 : : const UniReference < SvXMLExportPropertyMapper > & rMapper )
316 : : {
317 : 0 : pImpl->SetFamilyPropSetMapper( nFamily, rMapper );
318 : 0 : }
319 : :
320 : 7748 : void SvXMLAutoStylePoolP::RegisterName( sal_Int32 nFamily,
321 : : const OUString& rName )
322 : : {
323 : 7748 : pImpl->RegisterName( nFamily, rName );
324 : 7748 : }
325 : :
326 : 33 : void SvXMLAutoStylePoolP::GetRegisteredNames(
327 : : uno::Sequence<sal_Int32>& rFamilies,
328 : : uno::Sequence<OUString>& rNames )
329 : : {
330 : 33 : pImpl->GetRegisteredNames( rFamilies, rNames );
331 : 33 : }
332 : :
333 : 33 : void SvXMLAutoStylePoolP::RegisterNames(
334 : : uno::Sequence<sal_Int32>& aFamilies,
335 : : uno::Sequence<OUString>& aNames )
336 : : {
337 : : DBG_ASSERT( aFamilies.getLength() == aNames.getLength(),
338 : : "aFamilies != aNames" );
339 : :
340 : : // iterate over sequence(s) and call RegisterName(..) for each pair
341 : 33 : const sal_Int32* pFamilies = aFamilies.getConstArray();
342 : 33 : const OUString* pNames = aNames.getConstArray();
343 [ + - ]: 33 : sal_Int32 nCount = min( aFamilies.getLength(), aNames.getLength() );
344 [ + + ]: 3805 : for( sal_Int32 n = 0; n < nCount; n++ )
345 : 3772 : RegisterName( pFamilies[n], pNames[n] );
346 : 33 : }
347 : :
348 : 109 : OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
349 : : const vector< XMLPropertyState >& rProperties )
350 : : {
351 : 109 : OUString sEmpty;
352 : 109 : OUString sName;
353 [ + - ]: 109 : pImpl->Add(sName, nFamily, sEmpty, rProperties );
354 : 109 : return sName;
355 : : }
356 : :
357 : 181 : OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
358 : : const OUString& rParent,
359 : : const vector< XMLPropertyState >& rProperties, bool bDontSeek )
360 : : {
361 : 181 : OUString sName;
362 [ + - ]: 181 : pImpl->Add(sName, nFamily, rParent, rProperties, sal_False, bDontSeek );
363 : 181 : return sName;
364 : : }
365 : :
366 : 12 : sal_Bool SvXMLAutoStylePoolP::Add(OUString& rName, sal_Int32 nFamily, const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties )
367 : : {
368 : 12 : return pImpl->Add(rName, nFamily, rParent, rProperties);
369 : : }
370 : :
371 : 0 : sal_Bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, sal_Int32 nFamily, const OUString& rParent,
372 : : const ::std::vector< XMLPropertyState >& rProperties )
373 : :
374 : : {
375 : 0 : return pImpl->AddNamed(rName, nFamily, rParent, rProperties);
376 : : }
377 : :
378 : 333 : OUString SvXMLAutoStylePoolP::Find( sal_Int32 nFamily,
379 : : const OUString& rParent,
380 : : const vector< XMLPropertyState >& rProperties ) const
381 : : {
382 : 333 : return pImpl->Find( nFamily, rParent, rProperties );
383 : : }
384 : :
385 : 1408 : void SvXMLAutoStylePoolP::exportXML( sal_Int32 nFamily,
386 : : const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
387 : : const SvXMLUnitConverter&,
388 : : const SvXMLNamespaceMap&
389 : : ) const
390 : : {
391 : : pImpl->exportXML( nFamily,
392 : 1408 : GetExport().GetDocHandler(),
393 : 1408 : GetExport().GetMM100UnitConverter(),
394 : 1408 : GetExport().GetNamespaceMap(),
395 : 1408 : this);
396 : 1408 : }
397 : :
398 : 4 : void SvXMLAutoStylePoolP::ClearEntries()
399 : : {
400 : 4 : pImpl->ClearEntries();
401 : 4 : }
402 : :
403 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|