bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / style / PageMasterImportPropMapper.cxx
blob056b80cf8bba27818d795e2fff752764ec2fa62a
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 .
21 #include "PageMasterImportPropMapper.hxx"
22 #include "PageMasterPropMapper.hxx"
23 #include <xmloff/PageMasterStyleMap.hxx>
24 #include <xmloff/maptype.hxx>
25 #include <com/sun/star/table/BorderLine2.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <xmloff/xmlimp.hxx>
29 #define XML_LINE_LEFT 0
30 #define XML_LINE_RIGHT 1
31 #define XML_LINE_TOP 2
32 #define XML_LINE_BOTTOM 3
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::container;
38 PageMasterImportPropertyMapper::PageMasterImportPropertyMapper(
39 const UniReference< XMLPropertySetMapper >& rMapper,
40 SvXMLImport& rImp ) :
41 SvXMLImportPropertyMapper( rMapper, rImp ),
42 rImport( rImp )
46 PageMasterImportPropertyMapper::~PageMasterImportPropertyMapper()
50 bool PageMasterImportPropertyMapper::handleSpecialItem(
51 XMLPropertyState& rProperty,
52 ::std::vector< XMLPropertyState >& rProperties,
53 const OUString& rValue,
54 const SvXMLUnitConverter& rUnitConverter,
55 const SvXMLNamespaceMap& rNamespaceMap ) const
57 sal_Bool bRet = sal_False;
58 sal_Int16 nContextID =
59 getPropertySetMapper()->GetEntryContextId(rProperty.mnIndex);
61 if( CTF_PM_REGISTER_STYLE==nContextID )
63 OUString sDisplayName( rImport.GetStyleDisplayName(
64 XML_STYLE_FAMILY_TEXT_PARAGRAPH, rValue ) );
65 Reference < XNameContainer > xParaStyles =
66 rImport.GetTextImport()->GetParaStyles();
67 if( xParaStyles.is() && xParaStyles->hasByName( sDisplayName ) )
69 rProperty.maValue <<= sDisplayName;
70 bRet = sal_True;
73 else
75 bRet = SvXMLImportPropertyMapper::handleSpecialItem(
76 rProperty, rProperties, rValue,
77 rUnitConverter, rNamespaceMap );
80 return bRet;
84 void PageMasterImportPropertyMapper::finished(::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
86 SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex);
87 XMLPropertyState* pAllPaddingProperty = NULL;
88 XMLPropertyState* pPadding[4] = { NULL, NULL, NULL, NULL };
89 XMLPropertyState* pNewPadding[4] = { NULL, NULL, NULL, NULL };
90 XMLPropertyState* pAllBorderProperty = NULL;
91 XMLPropertyState* pBorders[4] = { NULL, NULL, NULL, NULL };
92 XMLPropertyState* pNewBorders[4] = { NULL, NULL, NULL, NULL };
93 XMLPropertyState* pAllBorderWidthProperty = NULL;
94 XMLPropertyState* pBorderWidths[4] = { NULL, NULL, NULL, NULL };
95 XMLPropertyState* pAllHeaderPaddingProperty = NULL;
96 XMLPropertyState* pHeaderPadding[4] = { NULL, NULL, NULL, NULL };
97 XMLPropertyState* pHeaderNewPadding[4] = { NULL, NULL, NULL, NULL };
98 XMLPropertyState* pAllHeaderBorderProperty = NULL;
99 XMLPropertyState* pHeaderBorders[4] = { NULL, NULL, NULL, NULL };
100 XMLPropertyState* pHeaderNewBorders[4] = { NULL, NULL, NULL, NULL };
101 XMLPropertyState* pAllHeaderBorderWidthProperty = NULL;
102 XMLPropertyState* pHeaderBorderWidths[4] = { NULL, NULL, NULL, NULL };
103 XMLPropertyState* pAllFooterPaddingProperty = NULL;
104 XMLPropertyState* pFooterPadding[4] = { NULL, NULL, NULL, NULL };
105 XMLPropertyState* pFooterNewPadding[4] = { NULL, NULL, NULL, NULL };
106 XMLPropertyState* pAllFooterBorderProperty = NULL;
107 XMLPropertyState* pFooterBorders[4] = { NULL, NULL, NULL, NULL };
108 XMLPropertyState* pFooterNewBorders[4] = { NULL, NULL, NULL, NULL };
109 XMLPropertyState* pAllFooterBorderWidthProperty = NULL;
110 XMLPropertyState* pFooterBorderWidths[4] = { NULL, NULL, NULL, NULL };
111 XMLPropertyState* pHeaderHeight = NULL;
112 XMLPropertyState* pHeaderMinHeight = NULL;
113 XMLPropertyState* pHeaderDynamic = NULL;
114 XMLPropertyState* pFooterHeight = NULL;
115 XMLPropertyState* pFooterMinHeight = NULL;
116 XMLPropertyState* pFooterDynamic = NULL;
117 XMLPropertyState* pAllMarginProperty = NULL;
118 XMLPropertyState* pMargins[4] = { NULL, NULL, NULL, NULL };
119 SAL_WNODEPRECATED_DECLARATIONS_PUSH
120 ::std::auto_ptr<XMLPropertyState> pNewMargins[4];
121 SAL_WNODEPRECATED_DECLARATIONS_POP
122 XMLPropertyState* pAllHeaderMarginProperty = NULL;
123 XMLPropertyState* pHeaderMargins[4] = { NULL, NULL, NULL, NULL };
124 SAL_WNODEPRECATED_DECLARATIONS_PUSH
125 ::std::auto_ptr<XMLPropertyState> pNewHeaderMargins[4];
126 SAL_WNODEPRECATED_DECLARATIONS_POP
127 XMLPropertyState* pAllFooterMarginProperty = NULL;
128 XMLPropertyState* pFooterMargins[4] = { NULL, NULL, NULL, NULL };
129 SAL_WNODEPRECATED_DECLARATIONS_PUSH
130 ::std::auto_ptr<XMLPropertyState> pNewFooterMargins[4];
131 SAL_WNODEPRECATED_DECLARATIONS_POP
133 ::std::vector< XMLPropertyState >::iterator aEnd = rProperties.end();
134 for (::std::vector< XMLPropertyState >::iterator aIter = rProperties.begin(); aIter != aEnd; ++aIter)
136 XMLPropertyState *property = &(*aIter);
137 sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex);
138 if (property->mnIndex >= nStartIndex && property->mnIndex < nEndIndex)
140 switch (nContextID)
142 case CTF_PM_PADDINGALL : pAllPaddingProperty = property; break;
143 case CTF_PM_PADDINGLEFT : pPadding[XML_LINE_LEFT] = property; break;
144 case CTF_PM_PADDINGRIGHT : pPadding[XML_LINE_RIGHT] = property; break;
145 case CTF_PM_PADDINGTOP : pPadding[XML_LINE_TOP] = property; break;
146 case CTF_PM_PADDINGBOTTOM : pPadding[XML_LINE_BOTTOM] = property; break;
147 case CTF_PM_BORDERALL : pAllBorderProperty = property; break;
148 case CTF_PM_BORDERLEFT : pBorders[XML_LINE_LEFT] = property; break;
149 case CTF_PM_BORDERRIGHT : pBorders[XML_LINE_RIGHT] = property; break;
150 case CTF_PM_BORDERTOP : pBorders[XML_LINE_TOP] = property; break;
151 case CTF_PM_BORDERBOTTOM : pBorders[XML_LINE_BOTTOM] = property; break;
152 case CTF_PM_BORDERWIDTHALL : pAllBorderWidthProperty = property; break;
153 case CTF_PM_BORDERWIDTHLEFT : pBorderWidths[XML_LINE_LEFT] = property; break;
154 case CTF_PM_BORDERWIDTHRIGHT : pBorderWidths[XML_LINE_RIGHT] = property; break;
155 case CTF_PM_BORDERWIDTHTOP : pBorderWidths[XML_LINE_TOP] = property; break;
156 case CTF_PM_BORDERWIDTHBOTTOM : pBorderWidths[XML_LINE_BOTTOM] = property; break;
157 case CTF_PM_HEADERPADDINGALL : pAllHeaderPaddingProperty = property; break;
158 case CTF_PM_HEADERPADDINGLEFT : pHeaderPadding[XML_LINE_LEFT] = property; break;
159 case CTF_PM_HEADERPADDINGRIGHT : pHeaderPadding[XML_LINE_RIGHT] = property; break;
160 case CTF_PM_HEADERPADDINGTOP : pHeaderPadding[XML_LINE_TOP] = property; break;
161 case CTF_PM_HEADERPADDINGBOTTOM : pHeaderPadding[XML_LINE_BOTTOM] = property; break;
162 case CTF_PM_HEADERBORDERALL : pAllHeaderBorderProperty = property; break;
163 case CTF_PM_HEADERBORDERLEFT : pHeaderBorders[XML_LINE_LEFT] = property; break;
164 case CTF_PM_HEADERBORDERRIGHT : pHeaderBorders[XML_LINE_RIGHT] = property; break;
165 case CTF_PM_HEADERBORDERTOP : pHeaderBorders[XML_LINE_TOP] = property; break;
166 case CTF_PM_HEADERBORDERBOTTOM : pHeaderBorders[XML_LINE_BOTTOM] = property; break;
167 case CTF_PM_HEADERBORDERWIDTHALL : pAllHeaderBorderWidthProperty = property; break;
168 case CTF_PM_HEADERBORDERWIDTHLEFT : pHeaderBorderWidths[XML_LINE_LEFT] = property; break;
169 case CTF_PM_HEADERBORDERWIDTHRIGHT : pHeaderBorderWidths[XML_LINE_RIGHT] = property; break;
170 case CTF_PM_HEADERBORDERWIDTHTOP : pHeaderBorderWidths[XML_LINE_TOP] = property; break;
171 case CTF_PM_HEADERBORDERWIDTHBOTTOM : pHeaderBorderWidths[XML_LINE_BOTTOM] = property; break;
172 case CTF_PM_FOOTERPADDINGALL : pAllFooterPaddingProperty = property; break;
173 case CTF_PM_FOOTERPADDINGLEFT : pFooterPadding[XML_LINE_LEFT] = property; break;
174 case CTF_PM_FOOTERPADDINGRIGHT : pFooterPadding[XML_LINE_RIGHT] = property; break;
175 case CTF_PM_FOOTERPADDINGTOP : pFooterPadding[XML_LINE_TOP] = property; break;
176 case CTF_PM_FOOTERPADDINGBOTTOM : pFooterPadding[XML_LINE_BOTTOM] = property; break;
177 case CTF_PM_FOOTERBORDERALL : pAllFooterBorderProperty = property; break;
178 case CTF_PM_FOOTERBORDERLEFT : pFooterBorders[XML_LINE_LEFT] = property; break;
179 case CTF_PM_FOOTERBORDERRIGHT : pFooterBorders[XML_LINE_RIGHT] = property; break;
180 case CTF_PM_FOOTERBORDERTOP : pFooterBorders[XML_LINE_TOP] = property; break;
181 case CTF_PM_FOOTERBORDERBOTTOM : pFooterBorders[XML_LINE_BOTTOM] = property; break;
182 case CTF_PM_FOOTERBORDERWIDTHALL : pAllFooterBorderWidthProperty = property; break;
183 case CTF_PM_FOOTERBORDERWIDTHLEFT : pFooterBorderWidths[XML_LINE_LEFT] = property; break;
184 case CTF_PM_FOOTERBORDERWIDTHRIGHT : pFooterBorderWidths[XML_LINE_RIGHT] = property; break;
185 case CTF_PM_FOOTERBORDERWIDTHTOP : pFooterBorderWidths[XML_LINE_TOP] = property; break;
186 case CTF_PM_FOOTERBORDERWIDTHBOTTOM : pFooterBorderWidths[XML_LINE_BOTTOM] = property; break;
187 case CTF_PM_HEADERHEIGHT : pHeaderHeight = property; break;
188 case CTF_PM_HEADERMINHEIGHT : pHeaderMinHeight = property; break;
189 case CTF_PM_FOOTERHEIGHT : pFooterHeight = property; break;
190 case CTF_PM_FOOTERMINHEIGHT : pFooterMinHeight = property; break;
191 case CTF_PM_MARGINALL :
192 pAllMarginProperty = property; break;
193 case CTF_PM_MARGINTOP :
194 pMargins[XML_LINE_TOP] = property; break;
195 case CTF_PM_MARGINBOTTOM:
196 pMargins[XML_LINE_BOTTOM] = property; break;
197 case CTF_PM_MARGINLEFT :
198 pMargins[XML_LINE_LEFT] = property; break;
199 case CTF_PM_MARGINRIGHT :
200 pMargins[XML_LINE_RIGHT] = property; break;
201 case CTF_PM_HEADERMARGINALL :
202 pAllHeaderMarginProperty = property; break;
203 case CTF_PM_HEADERMARGINTOP :
204 pHeaderMargins[XML_LINE_TOP] = property; break;
205 case CTF_PM_HEADERMARGINBOTTOM:
206 pHeaderMargins[XML_LINE_BOTTOM] = property; break;
207 case CTF_PM_HEADERMARGINLEFT :
208 pHeaderMargins[XML_LINE_LEFT] = property; break;
209 case CTF_PM_HEADERMARGINRIGHT :
210 pHeaderMargins[XML_LINE_RIGHT] = property; break;
211 case CTF_PM_FOOTERMARGINALL :
212 pAllFooterMarginProperty = property; break;
213 case CTF_PM_FOOTERMARGINTOP :
214 pFooterMargins[XML_LINE_TOP] = property; break;
215 case CTF_PM_FOOTERMARGINBOTTOM:
216 pFooterMargins[XML_LINE_BOTTOM] = property; break;
217 case CTF_PM_FOOTERMARGINLEFT :
218 pFooterMargins[XML_LINE_LEFT] = property; break;
219 case CTF_PM_FOOTERMARGINRIGHT :
220 pFooterMargins[XML_LINE_RIGHT] = property; break;
225 for (sal_uInt16 i = 0; i < 4; i++)
227 if (pAllMarginProperty && !pMargins[i])
229 pNewMargins[i].reset(new XMLPropertyState(
230 pAllMarginProperty->mnIndex + 1 + i,
231 pAllMarginProperty->maValue));
233 if (pAllHeaderMarginProperty && !pHeaderMargins[i])
235 pNewHeaderMargins[i].reset(new XMLPropertyState(
236 pAllHeaderMarginProperty->mnIndex + 1 + i,
237 pAllHeaderMarginProperty->maValue));
239 if (pAllFooterMarginProperty && !pFooterMargins[i])
241 pNewFooterMargins[i].reset(new XMLPropertyState(
242 pAllFooterMarginProperty->mnIndex + 1 + i,
243 pAllFooterMarginProperty->maValue));
245 if (pAllPaddingProperty && !pPadding[i])
246 pNewPadding[i] = new XMLPropertyState(pAllPaddingProperty->mnIndex + 1 + i, pAllPaddingProperty->maValue);
247 if (pAllBorderProperty && !pBorders[i])
249 pNewBorders[i] = new XMLPropertyState(pAllBorderProperty->mnIndex + 1 + i, pAllBorderProperty->maValue);
250 pBorders[i] = pNewBorders[i];
252 if( !pBorderWidths[i] )
253 pBorderWidths[i] = pAllBorderWidthProperty;
254 else
255 pBorderWidths[i]->mnIndex = -1;
256 if( pBorders[i] )
258 table::BorderLine2 aBorderLine;
259 pBorders[i]->maValue >>= aBorderLine;
260 if( pBorderWidths[i] )
262 table::BorderLine2 aBorderLineWidth;
263 pBorderWidths[i]->maValue >>= aBorderLineWidth;
264 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
265 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
266 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
267 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
268 pBorders[i]->maValue <<= aBorderLine;
271 if (pAllHeaderPaddingProperty && !pHeaderPadding[i])
272 pHeaderNewPadding[i] = new XMLPropertyState(pAllHeaderPaddingProperty->mnIndex + 1 + i, pAllHeaderPaddingProperty->maValue);
273 if (pAllHeaderBorderProperty && !pHeaderBorders[i])
274 pHeaderNewBorders[i] = new XMLPropertyState(pAllHeaderBorderProperty->mnIndex + 1 + i, pAllHeaderBorderProperty->maValue);
275 if( !pHeaderBorderWidths[i] )
276 pHeaderBorderWidths[i] = pAllHeaderBorderWidthProperty;
277 else
278 pHeaderBorderWidths[i]->mnIndex = -1;
279 if( pHeaderBorders[i] )
281 table::BorderLine2 aBorderLine;
282 pHeaderBorders[i]->maValue >>= aBorderLine;
283 if( pHeaderBorderWidths[i] )
285 table::BorderLine2 aBorderLineWidth;
286 pHeaderBorderWidths[i]->maValue >>= aBorderLineWidth;
287 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
288 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
289 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
290 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
291 pHeaderBorders[i]->maValue <<= aBorderLine;
294 if (pAllFooterPaddingProperty && !pFooterPadding[i])
295 pFooterNewPadding[i] = new XMLPropertyState(pAllFooterPaddingProperty->mnIndex + 1 + i, pAllFooterPaddingProperty->maValue);
296 if (pAllFooterBorderProperty && !pFooterBorders[i])
297 pFooterNewBorders[i] = new XMLPropertyState(pAllFooterBorderProperty->mnIndex + 1 + i, pAllFooterBorderProperty->maValue);
298 if( !pFooterBorderWidths[i] )
299 pFooterBorderWidths[i] = pAllFooterBorderWidthProperty;
300 else
301 pFooterBorderWidths[i]->mnIndex = -1;
302 if( pFooterBorders[i] )
304 table::BorderLine2 aBorderLine;
305 pFooterBorders[i]->maValue >>= aBorderLine;
306 if( pFooterBorderWidths[i] )
308 table::BorderLine2 aBorderLineWidth;
309 pFooterBorderWidths[i]->maValue >>= aBorderLineWidth;
310 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
311 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
312 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
313 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
314 pFooterBorders[i]->maValue <<= aBorderLine;
319 if (pHeaderHeight)
321 sal_Bool bValue(sal_False);
322 uno::Any aAny;
323 aAny.setValue( &bValue, ::getBooleanCppuType() );
324 pHeaderDynamic = new XMLPropertyState(pHeaderHeight->mnIndex + 2, aAny);
326 if (pHeaderMinHeight)
328 sal_Bool bValue(sal_True);
329 uno::Any aAny;
330 aAny.setValue( &bValue, ::getBooleanCppuType() );
331 pHeaderDynamic = new XMLPropertyState(pHeaderMinHeight->mnIndex + 1, aAny);
333 if (pFooterHeight)
335 sal_Bool bValue(sal_False);
336 uno::Any aAny;
337 aAny.setValue( &bValue, ::getBooleanCppuType() );
338 pFooterDynamic = new XMLPropertyState(pFooterHeight->mnIndex + 2, aAny);
340 if (pFooterMinHeight)
342 sal_Bool bValue(sal_True);
343 uno::Any aAny;
344 aAny.setValue( &bValue, ::getBooleanCppuType() );
345 pFooterDynamic = new XMLPropertyState(pFooterMinHeight->mnIndex + 1, aAny);
348 // fdo#38056: nerf the various AllFoo properties so they do not override
349 // the individual Foo properties later on
350 if (pAllPaddingProperty)
352 pAllPaddingProperty->mnIndex = -1;
354 if (pAllBorderProperty)
356 pAllBorderProperty->mnIndex = -1;
358 if (pAllBorderWidthProperty)
360 pAllBorderWidthProperty->mnIndex = -1;
362 if (pAllHeaderPaddingProperty)
364 pAllHeaderPaddingProperty->mnIndex = -1;
366 if (pAllHeaderBorderProperty)
368 pAllHeaderBorderProperty->mnIndex = -1;
370 if (pAllHeaderBorderWidthProperty)
372 pAllHeaderBorderWidthProperty->mnIndex = -1;
374 if (pAllFooterPaddingProperty)
376 pAllFooterPaddingProperty->mnIndex = -1;
378 if (pAllFooterBorderProperty)
380 pAllFooterBorderProperty->mnIndex = -1;
382 if (pAllFooterBorderWidthProperty)
384 pAllFooterBorderWidthProperty->mnIndex = -1;
386 if (pAllMarginProperty)
388 pAllMarginProperty->mnIndex = -1;
390 if (pAllHeaderMarginProperty)
392 pAllHeaderMarginProperty->mnIndex = -1;
394 if (pAllFooterMarginProperty)
396 pAllFooterMarginProperty->mnIndex = -1;
399 for (sal_uInt16 i = 0; i < 4; i++)
401 if (pNewMargins[i].get())
403 rProperties.push_back(*pNewMargins[i]);
405 if (pNewHeaderMargins[i].get())
407 rProperties.push_back(*pNewHeaderMargins[i]);
409 if (pNewFooterMargins[i].get())
411 rProperties.push_back(*pNewFooterMargins[i]);
413 if (pNewPadding[i])
415 rProperties.push_back(*pNewPadding[i]);
416 delete pNewPadding[i];
418 if (pNewBorders[i])
420 rProperties.push_back(*pNewBorders[i]);
421 delete pNewBorders[i];
423 if (pHeaderNewPadding[i])
425 rProperties.push_back(*pHeaderNewPadding[i]);
426 delete pHeaderNewPadding[i];
428 if (pHeaderNewBorders[i])
430 rProperties.push_back(*pHeaderNewBorders[i]);
431 delete pHeaderNewBorders[i];
433 if (pFooterNewPadding[i])
435 rProperties.push_back(*pFooterNewPadding[i]);
436 delete pFooterNewPadding[i];
438 if (pFooterNewBorders[i])
440 rProperties.push_back(*pFooterNewBorders[i]);
441 delete pFooterNewBorders[i];
444 if(pHeaderDynamic)
446 rProperties.push_back(*pHeaderDynamic);
447 delete pHeaderDynamic;
449 if(pFooterDynamic)
451 rProperties.push_back(*pFooterDynamic);
452 delete pFooterDynamic;
456 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */