bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / PageMasterImportPropMapper.cxx
blobde381ceaff65ea415b9816fb3caa89781ef01b0c
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>
28 #include <boost/scoped_ptr.hpp>
30 #define XML_LINE_LEFT 0
31 #define XML_LINE_RIGHT 1
32 #define XML_LINE_TOP 2
33 #define XML_LINE_BOTTOM 3
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::container;
39 PageMasterImportPropertyMapper::PageMasterImportPropertyMapper(
40 const rtl::Reference< XMLPropertySetMapper >& rMapper,
41 SvXMLImport& rImp ) :
42 SvXMLImportPropertyMapper( rMapper, rImp ),
43 rImport( rImp )
47 PageMasterImportPropertyMapper::~PageMasterImportPropertyMapper()
51 bool PageMasterImportPropertyMapper::handleSpecialItem(
52 XMLPropertyState& rProperty,
53 ::std::vector< XMLPropertyState >& rProperties,
54 const OUString& rValue,
55 const SvXMLUnitConverter& rUnitConverter,
56 const SvXMLNamespaceMap& rNamespaceMap ) const
58 bool bRet = false;
59 sal_Int16 nContextID =
60 getPropertySetMapper()->GetEntryContextId(rProperty.mnIndex);
62 if( CTF_PM_REGISTER_STYLE==nContextID )
64 OUString sDisplayName( rImport.GetStyleDisplayName(
65 XML_STYLE_FAMILY_TEXT_PARAGRAPH, rValue ) );
66 Reference < XNameContainer > xParaStyles =
67 rImport.GetTextImport()->GetParaStyles();
68 if( xParaStyles.is() && xParaStyles->hasByName( sDisplayName ) )
70 rProperty.maValue <<= sDisplayName;
71 bRet = true;
74 else
76 bRet = SvXMLImportPropertyMapper::handleSpecialItem(
77 rProperty, rProperties, rValue,
78 rUnitConverter, rNamespaceMap );
81 return bRet;
85 void PageMasterImportPropertyMapper::finished(::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
87 SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex);
88 XMLPropertyState* pAllPaddingProperty = NULL;
89 XMLPropertyState* pPadding[4] = { NULL, NULL, NULL, NULL };
90 XMLPropertyState* pNewPadding[4] = { NULL, NULL, NULL, NULL };
91 XMLPropertyState* pAllBorderProperty = NULL;
92 XMLPropertyState* pBorders[4] = { NULL, NULL, NULL, NULL };
93 XMLPropertyState* pNewBorders[4] = { NULL, NULL, NULL, NULL };
94 XMLPropertyState* pAllBorderWidthProperty = NULL;
95 XMLPropertyState* pBorderWidths[4] = { NULL, NULL, NULL, NULL };
96 XMLPropertyState* pAllHeaderPaddingProperty = NULL;
97 XMLPropertyState* pHeaderPadding[4] = { NULL, NULL, NULL, NULL };
98 XMLPropertyState* pHeaderNewPadding[4] = { NULL, NULL, NULL, NULL };
99 XMLPropertyState* pAllHeaderBorderProperty = NULL;
100 XMLPropertyState* pHeaderBorders[4] = { NULL, NULL, NULL, NULL };
101 XMLPropertyState* pHeaderNewBorders[4] = { NULL, NULL, NULL, NULL };
102 XMLPropertyState* pAllHeaderBorderWidthProperty = NULL;
103 XMLPropertyState* pHeaderBorderWidths[4] = { NULL, NULL, NULL, NULL };
104 XMLPropertyState* pAllFooterPaddingProperty = NULL;
105 XMLPropertyState* pFooterPadding[4] = { NULL, NULL, NULL, NULL };
106 XMLPropertyState* pFooterNewPadding[4] = { NULL, NULL, NULL, NULL };
107 XMLPropertyState* pAllFooterBorderProperty = NULL;
108 XMLPropertyState* pFooterBorders[4] = { NULL, NULL, NULL, NULL };
109 XMLPropertyState* pFooterNewBorders[4] = { NULL, NULL, NULL, NULL };
110 XMLPropertyState* pAllFooterBorderWidthProperty = NULL;
111 XMLPropertyState* pFooterBorderWidths[4] = { NULL, NULL, NULL, NULL };
112 XMLPropertyState* pHeaderHeight = NULL;
113 XMLPropertyState* pHeaderMinHeight = NULL;
114 boost::scoped_ptr<XMLPropertyState> xHeaderDynamic;
115 XMLPropertyState* pFooterHeight = NULL;
116 XMLPropertyState* pFooterMinHeight = NULL;
117 boost::scoped_ptr<XMLPropertyState> xFooterDynamic;
118 XMLPropertyState* pAllMarginProperty = NULL;
119 XMLPropertyState* pMargins[4] = { NULL, NULL, NULL, NULL };
120 ::std::unique_ptr<XMLPropertyState> pNewMargins[4];
121 XMLPropertyState* pAllHeaderMarginProperty = NULL;
122 XMLPropertyState* pHeaderMargins[4] = { NULL, NULL, NULL, NULL };
123 ::std::unique_ptr<XMLPropertyState> pNewHeaderMargins[4];
124 XMLPropertyState* pAllFooterMarginProperty = NULL;
125 XMLPropertyState* pFooterMargins[4] = { NULL, NULL, NULL, NULL };
126 ::std::unique_ptr<XMLPropertyState> pNewFooterMargins[4];
128 ::std::vector< XMLPropertyState >::iterator aEnd = rProperties.end();
129 for (::std::vector< XMLPropertyState >::iterator aIter = rProperties.begin(); aIter != aEnd; ++aIter)
131 XMLPropertyState *property = &(*aIter);
132 sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex);
133 if (property->mnIndex >= nStartIndex && property->mnIndex < nEndIndex)
135 switch (nContextID)
137 case CTF_PM_PADDINGALL : pAllPaddingProperty = property; break;
138 case CTF_PM_PADDINGLEFT : pPadding[XML_LINE_LEFT] = property; break;
139 case CTF_PM_PADDINGRIGHT : pPadding[XML_LINE_RIGHT] = property; break;
140 case CTF_PM_PADDINGTOP : pPadding[XML_LINE_TOP] = property; break;
141 case CTF_PM_PADDINGBOTTOM : pPadding[XML_LINE_BOTTOM] = property; break;
142 case CTF_PM_BORDERALL : pAllBorderProperty = property; break;
143 case CTF_PM_BORDERLEFT : pBorders[XML_LINE_LEFT] = property; break;
144 case CTF_PM_BORDERRIGHT : pBorders[XML_LINE_RIGHT] = property; break;
145 case CTF_PM_BORDERTOP : pBorders[XML_LINE_TOP] = property; break;
146 case CTF_PM_BORDERBOTTOM : pBorders[XML_LINE_BOTTOM] = property; break;
147 case CTF_PM_BORDERWIDTHALL : pAllBorderWidthProperty = property; break;
148 case CTF_PM_BORDERWIDTHLEFT : pBorderWidths[XML_LINE_LEFT] = property; break;
149 case CTF_PM_BORDERWIDTHRIGHT : pBorderWidths[XML_LINE_RIGHT] = property; break;
150 case CTF_PM_BORDERWIDTHTOP : pBorderWidths[XML_LINE_TOP] = property; break;
151 case CTF_PM_BORDERWIDTHBOTTOM : pBorderWidths[XML_LINE_BOTTOM] = property; break;
152 case CTF_PM_HEADERPADDINGALL : pAllHeaderPaddingProperty = property; break;
153 case CTF_PM_HEADERPADDINGLEFT : pHeaderPadding[XML_LINE_LEFT] = property; break;
154 case CTF_PM_HEADERPADDINGRIGHT : pHeaderPadding[XML_LINE_RIGHT] = property; break;
155 case CTF_PM_HEADERPADDINGTOP : pHeaderPadding[XML_LINE_TOP] = property; break;
156 case CTF_PM_HEADERPADDINGBOTTOM : pHeaderPadding[XML_LINE_BOTTOM] = property; break;
157 case CTF_PM_HEADERBORDERALL : pAllHeaderBorderProperty = property; break;
158 case CTF_PM_HEADERBORDERLEFT : pHeaderBorders[XML_LINE_LEFT] = property; break;
159 case CTF_PM_HEADERBORDERRIGHT : pHeaderBorders[XML_LINE_RIGHT] = property; break;
160 case CTF_PM_HEADERBORDERTOP : pHeaderBorders[XML_LINE_TOP] = property; break;
161 case CTF_PM_HEADERBORDERBOTTOM : pHeaderBorders[XML_LINE_BOTTOM] = property; break;
162 case CTF_PM_HEADERBORDERWIDTHALL : pAllHeaderBorderWidthProperty = property; break;
163 case CTF_PM_HEADERBORDERWIDTHLEFT : pHeaderBorderWidths[XML_LINE_LEFT] = property; break;
164 case CTF_PM_HEADERBORDERWIDTHRIGHT : pHeaderBorderWidths[XML_LINE_RIGHT] = property; break;
165 case CTF_PM_HEADERBORDERWIDTHTOP : pHeaderBorderWidths[XML_LINE_TOP] = property; break;
166 case CTF_PM_HEADERBORDERWIDTHBOTTOM : pHeaderBorderWidths[XML_LINE_BOTTOM] = property; break;
167 case CTF_PM_FOOTERPADDINGALL : pAllFooterPaddingProperty = property; break;
168 case CTF_PM_FOOTERPADDINGLEFT : pFooterPadding[XML_LINE_LEFT] = property; break;
169 case CTF_PM_FOOTERPADDINGRIGHT : pFooterPadding[XML_LINE_RIGHT] = property; break;
170 case CTF_PM_FOOTERPADDINGTOP : pFooterPadding[XML_LINE_TOP] = property; break;
171 case CTF_PM_FOOTERPADDINGBOTTOM : pFooterPadding[XML_LINE_BOTTOM] = property; break;
172 case CTF_PM_FOOTERBORDERALL : pAllFooterBorderProperty = property; break;
173 case CTF_PM_FOOTERBORDERLEFT : pFooterBorders[XML_LINE_LEFT] = property; break;
174 case CTF_PM_FOOTERBORDERRIGHT : pFooterBorders[XML_LINE_RIGHT] = property; break;
175 case CTF_PM_FOOTERBORDERTOP : pFooterBorders[XML_LINE_TOP] = property; break;
176 case CTF_PM_FOOTERBORDERBOTTOM : pFooterBorders[XML_LINE_BOTTOM] = property; break;
177 case CTF_PM_FOOTERBORDERWIDTHALL : pAllFooterBorderWidthProperty = property; break;
178 case CTF_PM_FOOTERBORDERWIDTHLEFT : pFooterBorderWidths[XML_LINE_LEFT] = property; break;
179 case CTF_PM_FOOTERBORDERWIDTHRIGHT : pFooterBorderWidths[XML_LINE_RIGHT] = property; break;
180 case CTF_PM_FOOTERBORDERWIDTHTOP : pFooterBorderWidths[XML_LINE_TOP] = property; break;
181 case CTF_PM_FOOTERBORDERWIDTHBOTTOM : pFooterBorderWidths[XML_LINE_BOTTOM] = property; break;
182 case CTF_PM_HEADERHEIGHT : pHeaderHeight = property; break;
183 case CTF_PM_HEADERMINHEIGHT : pHeaderMinHeight = property; break;
184 case CTF_PM_FOOTERHEIGHT : pFooterHeight = property; break;
185 case CTF_PM_FOOTERMINHEIGHT : pFooterMinHeight = property; break;
186 case CTF_PM_MARGINALL :
187 pAllMarginProperty = property; break;
188 case CTF_PM_MARGINTOP :
189 pMargins[XML_LINE_TOP] = property; break;
190 case CTF_PM_MARGINBOTTOM:
191 pMargins[XML_LINE_BOTTOM] = property; break;
192 case CTF_PM_MARGINLEFT :
193 pMargins[XML_LINE_LEFT] = property; break;
194 case CTF_PM_MARGINRIGHT :
195 pMargins[XML_LINE_RIGHT] = property; break;
196 case CTF_PM_HEADERMARGINALL :
197 pAllHeaderMarginProperty = property; break;
198 case CTF_PM_HEADERMARGINTOP :
199 pHeaderMargins[XML_LINE_TOP] = property; break;
200 case CTF_PM_HEADERMARGINBOTTOM:
201 pHeaderMargins[XML_LINE_BOTTOM] = property; break;
202 case CTF_PM_HEADERMARGINLEFT :
203 pHeaderMargins[XML_LINE_LEFT] = property; break;
204 case CTF_PM_HEADERMARGINRIGHT :
205 pHeaderMargins[XML_LINE_RIGHT] = property; break;
206 case CTF_PM_FOOTERMARGINALL :
207 pAllFooterMarginProperty = property; break;
208 case CTF_PM_FOOTERMARGINTOP :
209 pFooterMargins[XML_LINE_TOP] = property; break;
210 case CTF_PM_FOOTERMARGINBOTTOM:
211 pFooterMargins[XML_LINE_BOTTOM] = property; break;
212 case CTF_PM_FOOTERMARGINLEFT :
213 pFooterMargins[XML_LINE_LEFT] = property; break;
214 case CTF_PM_FOOTERMARGINRIGHT :
215 pFooterMargins[XML_LINE_RIGHT] = property; break;
220 for (sal_uInt16 i = 0; i < 4; i++)
222 if (pAllMarginProperty && !pMargins[i])
224 pNewMargins[i].reset(new XMLPropertyState(
225 pAllMarginProperty->mnIndex + 1 + i,
226 pAllMarginProperty->maValue));
228 if (pAllHeaderMarginProperty && !pHeaderMargins[i])
230 pNewHeaderMargins[i].reset(new XMLPropertyState(
231 pAllHeaderMarginProperty->mnIndex + 1 + i,
232 pAllHeaderMarginProperty->maValue));
234 if (pAllFooterMarginProperty && !pFooterMargins[i])
236 pNewFooterMargins[i].reset(new XMLPropertyState(
237 pAllFooterMarginProperty->mnIndex + 1 + i,
238 pAllFooterMarginProperty->maValue));
240 if (pAllPaddingProperty && !pPadding[i])
241 pNewPadding[i] = new XMLPropertyState(pAllPaddingProperty->mnIndex + 1 + i, pAllPaddingProperty->maValue);
242 if (pAllBorderProperty && !pBorders[i])
244 pNewBorders[i] = new XMLPropertyState(pAllBorderProperty->mnIndex + 1 + i, pAllBorderProperty->maValue);
245 pBorders[i] = pNewBorders[i];
247 if( !pBorderWidths[i] )
248 pBorderWidths[i] = pAllBorderWidthProperty;
249 else
250 pBorderWidths[i]->mnIndex = -1;
251 if( pBorders[i] )
253 table::BorderLine2 aBorderLine;
254 pBorders[i]->maValue >>= aBorderLine;
255 if( pBorderWidths[i] )
257 table::BorderLine2 aBorderLineWidth;
258 pBorderWidths[i]->maValue >>= aBorderLineWidth;
259 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
260 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
261 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
262 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
263 pBorders[i]->maValue <<= aBorderLine;
266 if (pAllHeaderPaddingProperty && !pHeaderPadding[i])
267 pHeaderNewPadding[i] = new XMLPropertyState(pAllHeaderPaddingProperty->mnIndex + 1 + i, pAllHeaderPaddingProperty->maValue);
268 if (pAllHeaderBorderProperty && !pHeaderBorders[i])
269 pHeaderNewBorders[i] = new XMLPropertyState(pAllHeaderBorderProperty->mnIndex + 1 + i, pAllHeaderBorderProperty->maValue);
270 if( !pHeaderBorderWidths[i] )
271 pHeaderBorderWidths[i] = pAllHeaderBorderWidthProperty;
272 else
273 pHeaderBorderWidths[i]->mnIndex = -1;
274 if( pHeaderBorders[i] )
276 table::BorderLine2 aBorderLine;
277 pHeaderBorders[i]->maValue >>= aBorderLine;
278 if( pHeaderBorderWidths[i] )
280 table::BorderLine2 aBorderLineWidth;
281 pHeaderBorderWidths[i]->maValue >>= aBorderLineWidth;
282 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
283 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
284 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
285 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
286 pHeaderBorders[i]->maValue <<= aBorderLine;
289 if (pAllFooterPaddingProperty && !pFooterPadding[i])
290 pFooterNewPadding[i] = new XMLPropertyState(pAllFooterPaddingProperty->mnIndex + 1 + i, pAllFooterPaddingProperty->maValue);
291 if (pAllFooterBorderProperty && !pFooterBorders[i])
292 pFooterNewBorders[i] = new XMLPropertyState(pAllFooterBorderProperty->mnIndex + 1 + i, pAllFooterBorderProperty->maValue);
293 if( !pFooterBorderWidths[i] )
294 pFooterBorderWidths[i] = pAllFooterBorderWidthProperty;
295 else
296 pFooterBorderWidths[i]->mnIndex = -1;
297 if( pFooterBorders[i] )
299 table::BorderLine2 aBorderLine;
300 pFooterBorders[i]->maValue >>= aBorderLine;
301 if( pFooterBorderWidths[i] )
303 table::BorderLine2 aBorderLineWidth;
304 pFooterBorderWidths[i]->maValue >>= aBorderLineWidth;
305 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
306 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
307 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
308 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
309 pFooterBorders[i]->maValue <<= aBorderLine;
314 if (pHeaderHeight)
316 sal_Bool bValue(sal_False);
317 uno::Any aAny;
318 aAny.setValue( &bValue, cppu::UnoType<bool>::get() );
319 xHeaderDynamic.reset(new XMLPropertyState(pHeaderHeight->mnIndex + 2, aAny));
321 if (pHeaderMinHeight)
323 sal_Bool bValue(sal_True);
324 uno::Any aAny;
325 aAny.setValue( &bValue, cppu::UnoType<bool>::get() );
326 xHeaderDynamic.reset(new XMLPropertyState(pHeaderMinHeight->mnIndex + 1, aAny));
328 if (pFooterHeight)
330 sal_Bool bValue(sal_False);
331 uno::Any aAny;
332 aAny.setValue( &bValue, cppu::UnoType<bool>::get() );
333 xFooterDynamic.reset(new XMLPropertyState(pFooterHeight->mnIndex + 2, aAny));
335 if (pFooterMinHeight)
337 sal_Bool bValue(sal_True);
338 uno::Any aAny;
339 aAny.setValue( &bValue, cppu::UnoType<bool>::get() );
340 xFooterDynamic.reset(new XMLPropertyState(pFooterMinHeight->mnIndex + 1, aAny));
343 // fdo#38056: nerf the various AllFoo properties so they do not override
344 // the individual Foo properties later on
345 if (pAllPaddingProperty)
347 pAllPaddingProperty->mnIndex = -1;
349 if (pAllBorderProperty)
351 pAllBorderProperty->mnIndex = -1;
353 if (pAllBorderWidthProperty)
355 pAllBorderWidthProperty->mnIndex = -1;
357 if (pAllHeaderPaddingProperty)
359 pAllHeaderPaddingProperty->mnIndex = -1;
361 if (pAllHeaderBorderProperty)
363 pAllHeaderBorderProperty->mnIndex = -1;
365 if (pAllHeaderBorderWidthProperty)
367 pAllHeaderBorderWidthProperty->mnIndex = -1;
369 if (pAllFooterPaddingProperty)
371 pAllFooterPaddingProperty->mnIndex = -1;
373 if (pAllFooterBorderProperty)
375 pAllFooterBorderProperty->mnIndex = -1;
377 if (pAllFooterBorderWidthProperty)
379 pAllFooterBorderWidthProperty->mnIndex = -1;
381 if (pAllMarginProperty)
383 pAllMarginProperty->mnIndex = -1;
385 if (pAllHeaderMarginProperty)
387 pAllHeaderMarginProperty->mnIndex = -1;
389 if (pAllFooterMarginProperty)
391 pAllFooterMarginProperty->mnIndex = -1;
394 for (sal_uInt16 i = 0; i < 4; i++)
396 if (pNewMargins[i].get())
398 rProperties.push_back(*pNewMargins[i]);
400 if (pNewHeaderMargins[i].get())
402 rProperties.push_back(*pNewHeaderMargins[i]);
404 if (pNewFooterMargins[i].get())
406 rProperties.push_back(*pNewFooterMargins[i]);
408 if (pNewPadding[i])
410 rProperties.push_back(*pNewPadding[i]);
411 delete pNewPadding[i];
413 if (pNewBorders[i])
415 rProperties.push_back(*pNewBorders[i]);
416 delete pNewBorders[i];
418 if (pHeaderNewPadding[i])
420 rProperties.push_back(*pHeaderNewPadding[i]);
421 delete pHeaderNewPadding[i];
423 if (pHeaderNewBorders[i])
425 rProperties.push_back(*pHeaderNewBorders[i]);
426 delete pHeaderNewBorders[i];
428 if (pFooterNewPadding[i])
430 rProperties.push_back(*pFooterNewPadding[i]);
431 delete pFooterNewPadding[i];
433 if (pFooterNewBorders[i])
435 rProperties.push_back(*pFooterNewBorders[i]);
436 delete pFooterNewBorders[i];
439 if(xHeaderDynamic)
441 rProperties.push_back(*xHeaderDynamic);
442 xHeaderDynamic.reset();
444 if(xFooterDynamic)
446 rProperties.push_back(*xFooterDynamic);
447 xFooterDynamic.reset();
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */