nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / style / PageMasterImportPropMapper.cxx
blobae80775aac8b5db4c79426699c95a3e0e6934c37
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 <PageMasterStyleMap.hxx>
23 #include <xmloff/maptype.hxx>
24 #include <com/sun/star/table/BorderLine2.hpp>
25 #include <com/sun/star/container/XNameContainer.hpp>
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/xmlprmap.hxx>
28 #include <memory>
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 XmlStyleFamily::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 = nullptr;
89 XMLPropertyState* pPadding[4] = { nullptr, nullptr, nullptr, nullptr };
90 XMLPropertyState* pNewPadding[4] = { nullptr, nullptr, nullptr, nullptr };
91 XMLPropertyState* pAllBorderProperty = nullptr;
92 XMLPropertyState* pBorders[4] = { nullptr, nullptr, nullptr, nullptr };
93 XMLPropertyState* pNewBorders[4] = { nullptr, nullptr, nullptr, nullptr };
94 XMLPropertyState* pAllBorderWidthProperty = nullptr;
95 XMLPropertyState* pBorderWidths[4] = { nullptr, nullptr, nullptr, nullptr };
96 XMLPropertyState* pAllHeaderPaddingProperty = nullptr;
97 XMLPropertyState* pHeaderPadding[4] = { nullptr, nullptr, nullptr, nullptr };
98 XMLPropertyState* pHeaderNewPadding[4] = { nullptr, nullptr, nullptr, nullptr };
99 XMLPropertyState* pAllHeaderBorderProperty = nullptr;
100 XMLPropertyState* pHeaderBorders[4] = { nullptr, nullptr, nullptr, nullptr };
101 XMLPropertyState* pHeaderNewBorders[4] = { nullptr, nullptr, nullptr, nullptr };
102 XMLPropertyState* pAllHeaderBorderWidthProperty = nullptr;
103 XMLPropertyState* pHeaderBorderWidths[4] = { nullptr, nullptr, nullptr, nullptr };
104 XMLPropertyState* pAllFooterPaddingProperty = nullptr;
105 XMLPropertyState* pFooterPadding[4] = { nullptr, nullptr, nullptr, nullptr };
106 XMLPropertyState* pFooterNewPadding[4] = { nullptr, nullptr, nullptr, nullptr };
107 XMLPropertyState* pAllFooterBorderProperty = nullptr;
108 XMLPropertyState* pFooterBorders[4] = { nullptr, nullptr, nullptr, nullptr };
109 XMLPropertyState* pFooterNewBorders[4] = { nullptr, nullptr, nullptr, nullptr };
110 XMLPropertyState* pAllFooterBorderWidthProperty = nullptr;
111 XMLPropertyState* pFooterBorderWidths[4] = { nullptr, nullptr, nullptr, nullptr };
112 XMLPropertyState* pHeaderHeight = nullptr;
113 XMLPropertyState* pHeaderMinHeight = nullptr;
114 std::unique_ptr<XMLPropertyState> xHeaderDynamic;
115 XMLPropertyState* pFooterHeight = nullptr;
116 XMLPropertyState* pFooterMinHeight = nullptr;
117 std::unique_ptr<XMLPropertyState> xFooterDynamic;
118 XMLPropertyState* pAllMarginProperty = nullptr;
119 XMLPropertyState* pMargins[4] = { nullptr, nullptr, nullptr, nullptr };
120 std::unique_ptr<XMLPropertyState> pNewMargins[4];
121 XMLPropertyState* pAllHeaderMarginProperty = nullptr;
122 XMLPropertyState* pHeaderMargins[4] = { nullptr, nullptr, nullptr, nullptr };
123 std::unique_ptr<XMLPropertyState> pNewHeaderMargins[4];
124 XMLPropertyState* pAllFooterMarginProperty = nullptr;
125 XMLPropertyState* pFooterMargins[4] = { nullptr, nullptr, nullptr, nullptr };
126 std::unique_ptr<XMLPropertyState> pNewFooterMargins[4];
128 for (auto& rProp : rProperties)
130 XMLPropertyState *property = &rProp;
131 sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex);
132 if (property->mnIndex >= nStartIndex && property->mnIndex < nEndIndex)
134 switch (nContextID)
136 case CTF_PM_PADDINGALL : pAllPaddingProperty = property; break;
137 case CTF_PM_PADDINGLEFT : pPadding[XML_LINE_LEFT] = property; break;
138 case CTF_PM_PADDINGRIGHT : pPadding[XML_LINE_RIGHT] = property; break;
139 case CTF_PM_PADDINGTOP : pPadding[XML_LINE_TOP] = property; break;
140 case CTF_PM_PADDINGBOTTOM : pPadding[XML_LINE_BOTTOM] = property; break;
141 case CTF_PM_BORDERALL : pAllBorderProperty = property; break;
142 case CTF_PM_BORDERLEFT : pBorders[XML_LINE_LEFT] = property; break;
143 case CTF_PM_BORDERRIGHT : pBorders[XML_LINE_RIGHT] = property; break;
144 case CTF_PM_BORDERTOP : pBorders[XML_LINE_TOP] = property; break;
145 case CTF_PM_BORDERBOTTOM : pBorders[XML_LINE_BOTTOM] = property; break;
146 case CTF_PM_BORDERWIDTHALL : pAllBorderWidthProperty = property; break;
147 case CTF_PM_BORDERWIDTHLEFT : pBorderWidths[XML_LINE_LEFT] = property; break;
148 case CTF_PM_BORDERWIDTHRIGHT : pBorderWidths[XML_LINE_RIGHT] = property; break;
149 case CTF_PM_BORDERWIDTHTOP : pBorderWidths[XML_LINE_TOP] = property; break;
150 case CTF_PM_BORDERWIDTHBOTTOM : pBorderWidths[XML_LINE_BOTTOM] = property; break;
151 case CTF_PM_HEADERPADDINGALL : pAllHeaderPaddingProperty = property; break;
152 case CTF_PM_HEADERPADDINGLEFT : pHeaderPadding[XML_LINE_LEFT] = property; break;
153 case CTF_PM_HEADERPADDINGRIGHT : pHeaderPadding[XML_LINE_RIGHT] = property; break;
154 case CTF_PM_HEADERPADDINGTOP : pHeaderPadding[XML_LINE_TOP] = property; break;
155 case CTF_PM_HEADERPADDINGBOTTOM : pHeaderPadding[XML_LINE_BOTTOM] = property; break;
156 case CTF_PM_HEADERBORDERALL : pAllHeaderBorderProperty = property; break;
157 case CTF_PM_HEADERBORDERLEFT : pHeaderBorders[XML_LINE_LEFT] = property; break;
158 case CTF_PM_HEADERBORDERRIGHT : pHeaderBorders[XML_LINE_RIGHT] = property; break;
159 case CTF_PM_HEADERBORDERTOP : pHeaderBorders[XML_LINE_TOP] = property; break;
160 case CTF_PM_HEADERBORDERBOTTOM : pHeaderBorders[XML_LINE_BOTTOM] = property; break;
161 case CTF_PM_HEADERBORDERWIDTHALL : pAllHeaderBorderWidthProperty = property; break;
162 case CTF_PM_HEADERBORDERWIDTHLEFT : pHeaderBorderWidths[XML_LINE_LEFT] = property; break;
163 case CTF_PM_HEADERBORDERWIDTHRIGHT : pHeaderBorderWidths[XML_LINE_RIGHT] = property; break;
164 case CTF_PM_HEADERBORDERWIDTHTOP : pHeaderBorderWidths[XML_LINE_TOP] = property; break;
165 case CTF_PM_HEADERBORDERWIDTHBOTTOM : pHeaderBorderWidths[XML_LINE_BOTTOM] = property; break;
166 case CTF_PM_FOOTERPADDINGALL : pAllFooterPaddingProperty = property; break;
167 case CTF_PM_FOOTERPADDINGLEFT : pFooterPadding[XML_LINE_LEFT] = property; break;
168 case CTF_PM_FOOTERPADDINGRIGHT : pFooterPadding[XML_LINE_RIGHT] = property; break;
169 case CTF_PM_FOOTERPADDINGTOP : pFooterPadding[XML_LINE_TOP] = property; break;
170 case CTF_PM_FOOTERPADDINGBOTTOM : pFooterPadding[XML_LINE_BOTTOM] = property; break;
171 case CTF_PM_FOOTERBORDERALL : pAllFooterBorderProperty = property; break;
172 case CTF_PM_FOOTERBORDERLEFT : pFooterBorders[XML_LINE_LEFT] = property; break;
173 case CTF_PM_FOOTERBORDERRIGHT : pFooterBorders[XML_LINE_RIGHT] = property; break;
174 case CTF_PM_FOOTERBORDERTOP : pFooterBorders[XML_LINE_TOP] = property; break;
175 case CTF_PM_FOOTERBORDERBOTTOM : pFooterBorders[XML_LINE_BOTTOM] = property; break;
176 case CTF_PM_FOOTERBORDERWIDTHALL : pAllFooterBorderWidthProperty = property; break;
177 case CTF_PM_FOOTERBORDERWIDTHLEFT : pFooterBorderWidths[XML_LINE_LEFT] = property; break;
178 case CTF_PM_FOOTERBORDERWIDTHRIGHT : pFooterBorderWidths[XML_LINE_RIGHT] = property; break;
179 case CTF_PM_FOOTERBORDERWIDTHTOP : pFooterBorderWidths[XML_LINE_TOP] = property; break;
180 case CTF_PM_FOOTERBORDERWIDTHBOTTOM : pFooterBorderWidths[XML_LINE_BOTTOM] = property; break;
181 case CTF_PM_HEADERHEIGHT : pHeaderHeight = property; break;
182 case CTF_PM_HEADERMINHEIGHT : pHeaderMinHeight = property; break;
183 case CTF_PM_FOOTERHEIGHT : pFooterHeight = property; break;
184 case CTF_PM_FOOTERMINHEIGHT : pFooterMinHeight = property; break;
185 case CTF_PM_MARGINALL :
186 pAllMarginProperty = property; break;
187 case CTF_PM_MARGINTOP :
188 pMargins[XML_LINE_TOP] = property; break;
189 case CTF_PM_MARGINBOTTOM:
190 pMargins[XML_LINE_BOTTOM] = property; break;
191 case CTF_PM_MARGINLEFT :
192 pMargins[XML_LINE_LEFT] = property; break;
193 case CTF_PM_MARGINRIGHT :
194 pMargins[XML_LINE_RIGHT] = property; break;
195 case CTF_PM_HEADERMARGINALL :
196 pAllHeaderMarginProperty = property; break;
197 case CTF_PM_HEADERMARGINTOP :
198 pHeaderMargins[XML_LINE_TOP] = property; break;
199 case CTF_PM_HEADERMARGINBOTTOM:
200 pHeaderMargins[XML_LINE_BOTTOM] = property; break;
201 case CTF_PM_HEADERMARGINLEFT :
202 pHeaderMargins[XML_LINE_LEFT] = property; break;
203 case CTF_PM_HEADERMARGINRIGHT :
204 pHeaderMargins[XML_LINE_RIGHT] = property; break;
205 case CTF_PM_FOOTERMARGINALL :
206 pAllFooterMarginProperty = property; break;
207 case CTF_PM_FOOTERMARGINTOP :
208 pFooterMargins[XML_LINE_TOP] = property; break;
209 case CTF_PM_FOOTERMARGINBOTTOM:
210 pFooterMargins[XML_LINE_BOTTOM] = property; break;
211 case CTF_PM_FOOTERMARGINLEFT :
212 pFooterMargins[XML_LINE_LEFT] = property; break;
213 case CTF_PM_FOOTERMARGINRIGHT :
214 pFooterMargins[XML_LINE_RIGHT] = property; break;
219 for (sal_uInt16 i = 0; i < 4; i++)
221 if (pAllMarginProperty && !pMargins[i])
223 pNewMargins[i].reset(new XMLPropertyState(
224 pAllMarginProperty->mnIndex + 1 + i,
225 pAllMarginProperty->maValue));
227 if (pAllHeaderMarginProperty && !pHeaderMargins[i])
229 pNewHeaderMargins[i].reset(new XMLPropertyState(
230 pAllHeaderMarginProperty->mnIndex + 1 + i,
231 pAllHeaderMarginProperty->maValue));
233 if (pAllFooterMarginProperty && !pFooterMargins[i])
235 pNewFooterMargins[i].reset(new XMLPropertyState(
236 pAllFooterMarginProperty->mnIndex + 1 + i,
237 pAllFooterMarginProperty->maValue));
239 if (pAllPaddingProperty && !pPadding[i])
240 pNewPadding[i] = new XMLPropertyState(pAllPaddingProperty->mnIndex + 1 + i, pAllPaddingProperty->maValue);
241 if (pAllBorderProperty && !pBorders[i])
243 pNewBorders[i] = new XMLPropertyState(pAllBorderProperty->mnIndex + 1 + i, pAllBorderProperty->maValue);
244 pBorders[i] = pNewBorders[i];
246 if( !pBorderWidths[i] )
247 pBorderWidths[i] = pAllBorderWidthProperty;
248 else
249 pBorderWidths[i]->mnIndex = -1;
250 if( pBorders[i] )
252 table::BorderLine2 aBorderLine;
253 pBorders[i]->maValue >>= aBorderLine;
254 if( pBorderWidths[i] )
256 table::BorderLine2 aBorderLineWidth;
257 pBorderWidths[i]->maValue >>= aBorderLineWidth;
258 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
259 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
260 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
261 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
262 pBorders[i]->maValue <<= aBorderLine;
265 if (pAllHeaderPaddingProperty && !pHeaderPadding[i])
266 pHeaderNewPadding[i] = new XMLPropertyState(pAllHeaderPaddingProperty->mnIndex + 1 + i, pAllHeaderPaddingProperty->maValue);
267 if (pAllHeaderBorderProperty && !pHeaderBorders[i])
268 pHeaderNewBorders[i] = new XMLPropertyState(pAllHeaderBorderProperty->mnIndex + 1 + i, pAllHeaderBorderProperty->maValue);
269 if( !pHeaderBorderWidths[i] )
270 pHeaderBorderWidths[i] = pAllHeaderBorderWidthProperty;
271 else
272 pHeaderBorderWidths[i]->mnIndex = -1;
273 if( pHeaderBorders[i] )
275 table::BorderLine2 aBorderLine;
276 pHeaderBorders[i]->maValue >>= aBorderLine;
277 if( pHeaderBorderWidths[i] )
279 table::BorderLine2 aBorderLineWidth;
280 pHeaderBorderWidths[i]->maValue >>= aBorderLineWidth;
281 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
282 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
283 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
284 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
285 pHeaderBorders[i]->maValue <<= aBorderLine;
288 if (pAllFooterPaddingProperty && !pFooterPadding[i])
289 pFooterNewPadding[i] = new XMLPropertyState(pAllFooterPaddingProperty->mnIndex + 1 + i, pAllFooterPaddingProperty->maValue);
290 if (pAllFooterBorderProperty && !pFooterBorders[i])
291 pFooterNewBorders[i] = new XMLPropertyState(pAllFooterBorderProperty->mnIndex + 1 + i, pAllFooterBorderProperty->maValue);
292 if( !pFooterBorderWidths[i] )
293 pFooterBorderWidths[i] = pAllFooterBorderWidthProperty;
294 else
295 pFooterBorderWidths[i]->mnIndex = -1;
296 if( pFooterBorders[i] )
298 table::BorderLine2 aBorderLine;
299 pFooterBorders[i]->maValue >>= aBorderLine;
300 if( pFooterBorderWidths[i] )
302 table::BorderLine2 aBorderLineWidth;
303 pFooterBorderWidths[i]->maValue >>= aBorderLineWidth;
304 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
305 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
306 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
307 aBorderLine.LineWidth = aBorderLineWidth.LineWidth;
308 pFooterBorders[i]->maValue <<= aBorderLine;
313 if (pHeaderHeight)
315 xHeaderDynamic.reset(new XMLPropertyState(pHeaderHeight->mnIndex + 2, Any(false)));
317 if (pHeaderMinHeight)
319 xHeaderDynamic.reset(new XMLPropertyState(pHeaderMinHeight->mnIndex + 1, Any(true)));
321 if (pFooterHeight)
323 xFooterDynamic.reset(new XMLPropertyState(pFooterHeight->mnIndex + 2, Any(false)));
325 if (pFooterMinHeight)
327 xFooterDynamic.reset(new XMLPropertyState(pFooterMinHeight->mnIndex + 1, Any(true)));
330 // fdo#38056: nerf the various AllFoo properties so they do not override
331 // the individual Foo properties later on
332 if (pAllPaddingProperty)
334 pAllPaddingProperty->mnIndex = -1;
336 if (pAllBorderProperty)
338 pAllBorderProperty->mnIndex = -1;
340 if (pAllBorderWidthProperty)
342 pAllBorderWidthProperty->mnIndex = -1;
344 if (pAllHeaderPaddingProperty)
346 pAllHeaderPaddingProperty->mnIndex = -1;
348 if (pAllHeaderBorderProperty)
350 pAllHeaderBorderProperty->mnIndex = -1;
352 if (pAllHeaderBorderWidthProperty)
354 pAllHeaderBorderWidthProperty->mnIndex = -1;
356 if (pAllFooterPaddingProperty)
358 pAllFooterPaddingProperty->mnIndex = -1;
360 if (pAllFooterBorderProperty)
362 pAllFooterBorderProperty->mnIndex = -1;
364 if (pAllFooterBorderWidthProperty)
366 pAllFooterBorderWidthProperty->mnIndex = -1;
368 if (pAllMarginProperty)
370 pAllMarginProperty->mnIndex = -1;
372 if (pAllHeaderMarginProperty)
374 pAllHeaderMarginProperty->mnIndex = -1;
376 if (pAllFooterMarginProperty)
378 pAllFooterMarginProperty->mnIndex = -1;
381 for (sal_uInt16 i = 0; i < 4; i++)
383 if (pNewMargins[i])
385 rProperties.push_back(*pNewMargins[i]);
387 if (pNewHeaderMargins[i])
389 rProperties.push_back(*pNewHeaderMargins[i]);
391 if (pNewFooterMargins[i])
393 rProperties.push_back(*pNewFooterMargins[i]);
395 if (pNewPadding[i])
397 rProperties.push_back(*pNewPadding[i]);
398 delete pNewPadding[i];
400 if (pNewBorders[i])
402 rProperties.push_back(*pNewBorders[i]);
403 delete pNewBorders[i];
405 if (pHeaderNewPadding[i])
407 rProperties.push_back(*pHeaderNewPadding[i]);
408 delete pHeaderNewPadding[i];
410 if (pHeaderNewBorders[i])
412 rProperties.push_back(*pHeaderNewBorders[i]);
413 delete pHeaderNewBorders[i];
415 if (pFooterNewPadding[i])
417 rProperties.push_back(*pFooterNewPadding[i]);
418 delete pFooterNewPadding[i];
420 if (pFooterNewBorders[i])
422 rProperties.push_back(*pFooterNewBorders[i]);
423 delete pFooterNewBorders[i];
426 if(xHeaderDynamic)
428 rProperties.push_back(*xHeaderDynamic);
429 xHeaderDynamic.reset();
431 if(xFooterDynamic)
433 rProperties.push_back(*xFooterDynamic);
434 xFooterDynamic.reset();
438 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */