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