Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
30 :
31 : #include <xmloff/PageMasterStyleMap.hxx>
32 : #include "PageMasterExportPropMapper.hxx"
33 : #include "XMLBackgroundImageExport.hxx"
34 :
35 :
36 : using namespace ::std;
37 :
38 : using namespace ::com::sun::star;
39 : using namespace ::xmloff::token;
40 :
41 :
42 : namespace
43 : {
44 0 : static void lcl_exportDataStyle( SvXMLExport& _rExport, const rtl::Reference< XMLPropertySetMapper >& _rxMapper,
45 : const XMLPropertyState& _rProperty )
46 : {
47 : assert(_rxMapper.is());
48 : // obtain the data style name
49 0 : OUString sDataStyleName;
50 0 : _rProperty.maValue >>= sDataStyleName;
51 : assert(!sDataStyleName.isEmpty() && "xmloff::lcl_exportDataStyle: invalid property value for the data style name!");
52 :
53 : // add the attribute
54 : _rExport.AddAttribute(
55 0 : _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
56 0 : _rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
57 0 : sDataStyleName );
58 0 : }
59 : }
60 :
61 4087 : 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
69 : {
70 4087 : if ( XML_STYLE_FAMILY_CONTROL_ID == nFamily )
71 : { // it's a control-related style
72 0 : rtl::Reference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
73 :
74 0 : for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
75 0 : pProp != rProperties.end();
76 : ++pProp
77 : )
78 : {
79 0 : if ( ( pProp->mnIndex > -1 )
80 0 : && ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( pProp->mnIndex ) )
81 : )
82 : { // it's the data-style for a grid column
83 0 : lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
84 : }
85 0 : }
86 : }
87 :
88 4087 : if( (XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily) || (XML_STYLE_FAMILY_SD_PRESENTATION_ID == nFamily) )
89 : { // it's a graphics style
90 99 : rtl::Reference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
91 : assert(aPropertyMapper.is());
92 :
93 99 : bool bFoundControlShapeDataStyle = false;
94 99 : bool bFoundNumberingRulesName = false;
95 :
96 3888 : for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
97 2592 : pProp != rProperties.end();
98 : ++pProp
99 : )
100 : {
101 1197 : if (pProp->mnIndex > -1)
102 : { // it's a valid property
103 752 : switch( aPropertyMapper->GetEntryContextId(pProp->mnIndex) )
104 : {
105 : case CTF_SD_CONTROL_SHAPE_DATA_STYLE:
106 : { // it's the control shape data style property
107 :
108 0 : if (bFoundControlShapeDataStyle)
109 : {
110 : OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
111 : // already added the attribute for the first occurrence
112 0 : break;
113 : }
114 :
115 0 : lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
116 :
117 : // check if there is another property with the special context id we're handling here
118 0 : bFoundControlShapeDataStyle = true;
119 0 : break;
120 : }
121 : case CTF_SD_NUMBERINGRULES_NAME:
122 : {
123 0 : if (bFoundNumberingRulesName)
124 : {
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 0 : break;
128 : }
129 :
130 0 : uno::Reference< container::XIndexReplace > xNumRule;
131 0 : pProp->maValue >>= xNumRule;
132 0 : if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
133 : {
134 0 : const OUString sName(const_cast<XMLTextListAutoStylePool*>(&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
135 :
136 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) );
137 : }
138 :
139 0 : bFoundNumberingRulesName = true;
140 0 : break;
141 : }
142 : }
143 : }
144 99 : }
145 : }
146 :
147 4087 : if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
148 : {
149 4337 : for( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin(); pProp != rProperties.end(); ++pProp )
150 : {
151 4189 : if (pProp->mnIndex > -1)
152 : {
153 2919 : rtl::Reference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
154 2919 : sal_Int32 nIndex = pProp->mnIndex;
155 2919 : sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
156 2919 : switch( nContextID )
157 : {
158 : case CTF_PM_PAGEUSAGE:
159 : {
160 88 : OUString sValue;
161 88 : const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex );
162 176 : if( pPropHdl &&
163 88 : pPropHdl->exportXML( sValue, pProp->maValue,
164 264 : GetExport().GetMM100UnitConverter() ) &&
165 88 : ( ! IsXMLToken( sValue, XML_ALL ) ) )
166 : {
167 10 : GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
168 88 : }
169 : }
170 88 : break;
171 2919 : }
172 : }
173 : }
174 : }
175 4087 : }
176 :
177 4087 : 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
185 : {
186 4087 : if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
187 : {
188 148 : sal_Int32 nHeaderStartIndex(-1);
189 148 : sal_Int32 nHeaderEndIndex(-1);
190 148 : sal_Int32 nFooterStartIndex(-1);
191 148 : sal_Int32 nFooterEndIndex(-1);
192 148 : bool bHeaderStartIndex(false);
193 148 : bool bHeaderEndIndex(false);
194 148 : bool bFooterStartIndex(false);
195 148 : bool bFooterEndIndex(false);
196 :
197 148 : rtl::Reference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
198 :
199 148 : sal_Int32 nIndex(0);
200 28564 : while(nIndex < aPropMapper->GetEntryCount())
201 : {
202 28268 : switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
203 : {
204 : case CTF_PM_HEADERFLAG:
205 : {
206 7252 : if (!bHeaderStartIndex)
207 : {
208 148 : nHeaderStartIndex = nIndex;
209 148 : bHeaderStartIndex = true;
210 : }
211 7252 : if (bFooterStartIndex && !bFooterEndIndex)
212 : {
213 0 : nFooterEndIndex = nIndex;
214 0 : bFooterEndIndex = true;
215 : }
216 : }
217 7252 : break;
218 : case CTF_PM_FOOTERFLAG:
219 : {
220 7252 : if (!bFooterStartIndex)
221 : {
222 148 : nFooterStartIndex = nIndex;
223 148 : bFooterStartIndex = true;
224 : }
225 7252 : if (bHeaderStartIndex && !bHeaderEndIndex)
226 : {
227 148 : nHeaderEndIndex = nIndex;
228 148 : bHeaderEndIndex = true;
229 : }
230 : }
231 7252 : break;
232 : }
233 28268 : nIndex++;
234 : }
235 148 : if (!bHeaderEndIndex)
236 0 : nHeaderEndIndex = nIndex;
237 148 : if (!bFooterEndIndex)
238 148 : nFooterEndIndex = nIndex;
239 :
240 : // export header style element
241 : {
242 : SvXMLElementExport aElem(
243 148 : GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE,
244 148 : true, true );
245 :
246 : rPropExp.exportXML(
247 148 : GetExport(), rProperties,
248 148 : nHeaderStartIndex, nHeaderEndIndex, SvXmlExportFlags::IGN_WS);
249 : }
250 :
251 : // export footer style
252 : {
253 : SvXMLElementExport aElem(
254 148 : GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE,
255 148 : true, true );
256 :
257 : rPropExp.exportXML(
258 148 : GetExport(), rProperties,
259 148 : nFooterStartIndex, nFooterEndIndex, SvXmlExportFlags::IGN_WS);
260 148 : }
261 : }
262 4087 : }
263 :
264 2109 : SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport )
265 : {
266 2109 : pImpl = new SvXMLAutoStylePoolP_Impl( rExport );
267 2109 : }
268 :
269 5076 : SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
270 : {
271 2109 : delete pImpl;
272 2967 : }
273 :
274 14440 : SvXMLExport& SvXMLAutoStylePoolP::GetExport() const
275 : {
276 14440 : return pImpl->GetExport();
277 : }
278 :
279 : // TODO: romove this
280 5875 : void SvXMLAutoStylePoolP::AddFamily(
281 : sal_Int32 nFamily,
282 : const OUString& rStrName,
283 : SvXMLExportPropertyMapper* pMapper,
284 : const OUString& aStrPrefix,
285 : bool bAsFamily )
286 : {
287 5875 : rtl::Reference <SvXMLExportPropertyMapper> xTmp = pMapper;
288 5875 : AddFamily( nFamily, rStrName, xTmp, aStrPrefix, bAsFamily );
289 5875 : }
290 :
291 12734 : void SvXMLAutoStylePoolP::AddFamily(
292 : sal_Int32 nFamily,
293 : const OUString& rStrName,
294 : const rtl::Reference < SvXMLExportPropertyMapper > & rMapper,
295 : const OUString& rStrPrefix,
296 : bool bAsFamily )
297 : {
298 12734 : pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
299 12734 : }
300 :
301 2 : void SvXMLAutoStylePoolP::SetFamilyPropSetMapper(
302 : sal_Int32 nFamily,
303 : const rtl::Reference < SvXMLExportPropertyMapper > & rMapper )
304 : {
305 2 : pImpl->SetFamilyPropSetMapper( nFamily, rMapper );
306 2 : }
307 :
308 25091 : void SvXMLAutoStylePoolP::RegisterName( sal_Int32 nFamily,
309 : const OUString& rName )
310 : {
311 25091 : pImpl->RegisterName( nFamily, rName );
312 25091 : }
313 :
314 113 : void SvXMLAutoStylePoolP::GetRegisteredNames(
315 : uno::Sequence<sal_Int32>& rFamilies,
316 : uno::Sequence<OUString>& rNames )
317 : {
318 113 : pImpl->GetRegisteredNames( rFamilies, rNames );
319 113 : }
320 :
321 113 : void SvXMLAutoStylePoolP::RegisterNames(
322 : uno::Sequence<sal_Int32>& aFamilies,
323 : uno::Sequence<OUString>& aNames )
324 : {
325 : assert(aFamilies.getLength() == aNames.getLength());
326 :
327 : // iterate over sequence(s) and call RegisterName(..) for each pair
328 113 : const sal_Int32* pFamilies = aFamilies.getConstArray();
329 113 : const OUString* pNames = aNames.getConstArray();
330 113 : sal_Int32 nCount = min( aFamilies.getLength(), aNames.getLength() );
331 12371 : for( sal_Int32 n = 0; n < nCount; n++ )
332 12258 : RegisterName( pFamilies[n], pNames[n] );
333 113 : }
334 :
335 3545 : OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
336 : const vector< XMLPropertyState >& rProperties )
337 : {
338 3545 : OUString sEmpty;
339 3545 : OUString sName;
340 3545 : pImpl->Add(sName, nFamily, sEmpty, rProperties );
341 3545 : return sName;
342 : }
343 :
344 889 : OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
345 : const OUString& rParent,
346 : const vector< XMLPropertyState >& rProperties, bool bDontSeek )
347 : {
348 889 : OUString sName;
349 889 : pImpl->Add(sName, nFamily, rParent, rProperties, bDontSeek);
350 889 : return sName;
351 : }
352 :
353 185 : bool SvXMLAutoStylePoolP::Add(OUString& rName, sal_Int32 nFamily, const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties )
354 : {
355 185 : return pImpl->Add(rName, nFamily, rParent, rProperties);
356 : }
357 :
358 0 : bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, sal_Int32 nFamily, const OUString& rParent,
359 : const ::std::vector< XMLPropertyState >& rProperties )
360 :
361 : {
362 0 : return pImpl->AddNamed(rName, nFamily, rParent, rProperties);
363 : }
364 :
365 1643 : OUString SvXMLAutoStylePoolP::Find( sal_Int32 nFamily,
366 : const OUString& rParent,
367 : const vector< XMLPropertyState >& rProperties ) const
368 : {
369 1643 : return pImpl->Find( nFamily, rParent, rProperties );
370 : }
371 :
372 4535 : void SvXMLAutoStylePoolP::exportXML( sal_Int32 nFamily,
373 : const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
374 : const SvXMLUnitConverter&,
375 : const SvXMLNamespaceMap&
376 : ) const
377 : {
378 : pImpl->exportXML( nFamily,
379 4535 : GetExport().GetDocHandler(),
380 4535 : GetExport().GetMM100UnitConverter(),
381 4535 : GetExport().GetNamespaceMap(),
382 4535 : this);
383 4535 : }
384 :
385 5 : void SvXMLAutoStylePoolP::ClearEntries()
386 : {
387 5 : pImpl->ClearEntries();
388 5 : }
389 :
390 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|