1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 
27 #include "PageMasterImportPropMapper.hxx"
28 #include "PageMasterPropMapper.hxx"
29 #include <xmloff/PageMasterStyleMap.hxx>
30 #include <xmloff/maptype.hxx>
31 #include <com/sun/star/table/BorderLine.hpp>
32 #include <com/sun/star/container/XNameContainer.hpp>
33 #include <xmloff/xmlimp.hxx>
34 
35 #define XML_LINE_LEFT 0
36 #define XML_LINE_RIGHT 1
37 #define XML_LINE_TOP 2
38 #define XML_LINE_BOTTOM 3
39 
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::container;
43 
PageMasterImportPropertyMapper(const UniReference<XMLPropertySetMapper> & rMapper,SvXMLImport & rImp)44 PageMasterImportPropertyMapper::PageMasterImportPropertyMapper(
45 		const UniReference< XMLPropertySetMapper >& rMapper,
46 		SvXMLImport& rImp ) :
47 	SvXMLImportPropertyMapper( rMapper, rImp ),
48 	rImport( rImp )
49 {
50 }
51 
~PageMasterImportPropertyMapper()52 PageMasterImportPropertyMapper::~PageMasterImportPropertyMapper()
53 {
54 }
55 
handleSpecialItem(XMLPropertyState & rProperty,::std::vector<XMLPropertyState> & rProperties,const::rtl::OUString & rValue,const SvXMLUnitConverter & rUnitConverter,const SvXMLNamespaceMap & rNamespaceMap) const56 sal_Bool PageMasterImportPropertyMapper::handleSpecialItem(
57 		XMLPropertyState& rProperty,
58 		::std::vector< XMLPropertyState >& rProperties,
59 		const ::rtl::OUString& rValue,
60 		const SvXMLUnitConverter& rUnitConverter,
61 		const SvXMLNamespaceMap& rNamespaceMap ) const
62 {
63 	sal_Bool bRet = sal_False;
64 	sal_Int16 nContextID =
65 			getPropertySetMapper()->GetEntryContextId(rProperty.mnIndex);
66 
67 	if( CTF_PM_REGISTER_STYLE==nContextID )
68 	{
69 		::rtl::OUString sDisplayName( rImport.GetStyleDisplayName(
70 					XML_STYLE_FAMILY_TEXT_PARAGRAPH, rValue ) );
71 		Reference < XNameContainer > xParaStyles =
72 			rImport.GetTextImport()->GetParaStyles();
73 		if( xParaStyles.is() && xParaStyles->hasByName( sDisplayName ) )
74 		{
75 			rProperty.maValue <<= sDisplayName;
76 			bRet = sal_True;
77 		}
78 	}
79 	else
80 	{
81 		bRet = SvXMLImportPropertyMapper::handleSpecialItem(
82 					rProperty, rProperties, rValue,
83 					rUnitConverter, rNamespaceMap );
84 	}
85 
86 	return bRet;
87 }
88 
89 
finished(::std::vector<XMLPropertyState> & rProperties,sal_Int32 nStartIndex,sal_Int32 nEndIndex) const90 void PageMasterImportPropertyMapper::finished(::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
91 {
92 	SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex);
93 	XMLPropertyState* pAllPaddingProperty = NULL;
94 	XMLPropertyState* pPadding[4] = { NULL, NULL, NULL, NULL };
95 	XMLPropertyState* pNewPadding[4] = { NULL, NULL, NULL, NULL };
96 	XMLPropertyState* pAllBorderProperty = NULL;
97 	XMLPropertyState* pBorders[4] = { NULL, NULL, NULL, NULL };
98 	XMLPropertyState* pNewBorders[4] = { NULL, NULL, NULL, NULL };
99 	XMLPropertyState* pAllBorderWidthProperty = NULL;
100 	XMLPropertyState* pBorderWidths[4] = { NULL, NULL, NULL, NULL };
101 	XMLPropertyState* pAllHeaderPaddingProperty = NULL;
102 	XMLPropertyState* pHeaderPadding[4] = { NULL, NULL, NULL, NULL };
103 	XMLPropertyState* pHeaderNewPadding[4] = { NULL, NULL, NULL, NULL };
104 	XMLPropertyState* pAllHeaderBorderProperty = NULL;
105 	XMLPropertyState* pHeaderBorders[4] = { NULL, NULL, NULL, NULL };
106 	XMLPropertyState* pHeaderNewBorders[4] = { NULL, NULL, NULL, NULL };
107 	XMLPropertyState* pAllHeaderBorderWidthProperty = NULL;
108 	XMLPropertyState* pHeaderBorderWidths[4] = { NULL, NULL, NULL, NULL };
109 	XMLPropertyState* pAllFooterPaddingProperty = NULL;
110 	XMLPropertyState* pFooterPadding[4] = { NULL, NULL, NULL, NULL };
111 	XMLPropertyState* pFooterNewPadding[4] = { NULL, NULL, NULL, NULL };
112 	XMLPropertyState* pAllFooterBorderProperty = NULL;
113 	XMLPropertyState* pFooterBorders[4] = { NULL, NULL, NULL, NULL };
114 	XMLPropertyState* pFooterNewBorders[4] = { NULL, NULL, NULL, NULL };
115 	XMLPropertyState* pAllFooterBorderWidthProperty = NULL;
116 	XMLPropertyState* pFooterBorderWidths[4] = { NULL, NULL, NULL, NULL };
117 	XMLPropertyState* pHeaderHeight = NULL;
118 	XMLPropertyState* pHeaderMinHeight = NULL;
119 	XMLPropertyState* pHeaderDynamic = NULL;
120 	XMLPropertyState* pFooterHeight = NULL;
121 	XMLPropertyState* pFooterMinHeight = NULL;
122 	XMLPropertyState* pFooterDynamic = NULL;
123     XMLPropertyState* pAllMarginProperty = NULL;
124     XMLPropertyState* pMargins[4] = { NULL, NULL, NULL, NULL };
125     ::std::auto_ptr<XMLPropertyState> pNewMargins[4];
126     XMLPropertyState* pAllHeaderMarginProperty = NULL;
127     XMLPropertyState* pHeaderMargins[4] = { NULL, NULL, NULL, NULL };
128     ::std::auto_ptr<XMLPropertyState> pNewHeaderMargins[4];
129     XMLPropertyState* pAllFooterMarginProperty = NULL;
130     XMLPropertyState* pFooterMargins[4] = { NULL, NULL, NULL, NULL };
131     ::std::auto_ptr<XMLPropertyState> pNewFooterMargins[4];
132 
133 	::std::vector< XMLPropertyState >::iterator aEnd = rProperties.end();
134 	for (::std::vector< XMLPropertyState >::iterator aIter = rProperties.begin(); aIter != aEnd; ++aIter)
135 	{
136 		XMLPropertyState *property = &(*aIter);
137 		sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex);
138 		if (property->mnIndex >= nStartIndex && property->mnIndex < nEndIndex)
139 		{
140 			switch (nContextID)
141 			{
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;
221 			}
222 		}
223 	}
224 
225 	for (sal_uInt16 i = 0; i < 4; i++)
226 	{
227         if (pAllMarginProperty && !pMargins[i])
228         {
229             pNewMargins[i].reset(new XMLPropertyState(
230                 pAllMarginProperty->mnIndex + 1 + i,
231                 pAllMarginProperty->maValue));
232         }
233         if (pAllHeaderMarginProperty && !pHeaderMargins[i])
234         {
235             pNewHeaderMargins[i].reset(new XMLPropertyState(
236                 pAllHeaderMarginProperty->mnIndex + 1 + i,
237                 pAllHeaderMarginProperty->maValue));
238         }
239         if (pAllFooterMarginProperty && !pFooterMargins[i])
240         {
241             pNewFooterMargins[i].reset(new XMLPropertyState(
242                 pAllFooterMarginProperty->mnIndex + 1 + i,
243                 pAllFooterMarginProperty->maValue));
244         }
245 		if (pAllPaddingProperty && !pPadding[i])
246 			pNewPadding[i] = new XMLPropertyState(pAllPaddingProperty->mnIndex + 1 + i, pAllPaddingProperty->maValue);
247 		if (pAllBorderProperty && !pBorders[i])
248 		{
249 			pNewBorders[i] = new XMLPropertyState(pAllBorderProperty->mnIndex + 1 + i, pAllBorderProperty->maValue);
250 			pBorders[i] = pNewBorders[i];
251 		}
252 		if( !pBorderWidths[i] )
253 			pBorderWidths[i] = pAllBorderWidthProperty;
254 		else
255 			pBorderWidths[i]->mnIndex = -1;
256 		if( pBorders[i] )
257 		{
258 			table::BorderLine aBorderLine;
259 			pBorders[i]->maValue >>= aBorderLine;
260  			if( pBorderWidths[i] )
261 			{
262 				table::BorderLine aBorderLineWidth;
263 				pBorderWidths[i]->maValue >>= aBorderLineWidth;
264 				aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
265 				aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
266 				aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
267 				pBorders[i]->maValue <<= aBorderLine;
268 			}
269 		}
270 		if (pAllHeaderPaddingProperty && !pHeaderPadding[i])
271 			pHeaderNewPadding[i] = new XMLPropertyState(pAllHeaderPaddingProperty->mnIndex + 1 + i, pAllHeaderPaddingProperty->maValue);
272 		if (pAllHeaderBorderProperty && !pHeaderBorders[i])
273 			pHeaderNewBorders[i] = new XMLPropertyState(pAllHeaderBorderProperty->mnIndex + 1 + i, pAllHeaderBorderProperty->maValue);
274 		if( !pHeaderBorderWidths[i] )
275 			pHeaderBorderWidths[i] = pAllHeaderBorderWidthProperty;
276 		else
277 			pHeaderBorderWidths[i]->mnIndex = -1;
278 		if( pHeaderBorders[i] )
279 		{
280 			table::BorderLine aBorderLine;
281 			pHeaderBorders[i]->maValue >>= aBorderLine;
282  			if( pHeaderBorderWidths[i] )
283 			{
284 				table::BorderLine aBorderLineWidth;
285 				pHeaderBorderWidths[i]->maValue >>= aBorderLineWidth;
286 				aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
287 				aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
288 				aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
289 				pHeaderBorders[i]->maValue <<= aBorderLine;
290 			}
291 		}
292 		if (pAllFooterPaddingProperty && !pFooterPadding[i])
293 			pFooterNewPadding[i] = new XMLPropertyState(pAllFooterPaddingProperty->mnIndex + 1 + i, pAllFooterPaddingProperty->maValue);
294 		if (pAllFooterBorderProperty && !pFooterBorders[i])
295 			pFooterNewBorders[i] = new XMLPropertyState(pAllFooterBorderProperty->mnIndex + 1 + i, pAllFooterBorderProperty->maValue);
296 		if( !pFooterBorderWidths[i] )
297 			pFooterBorderWidths[i] = pAllFooterBorderWidthProperty;
298 		else
299 			pFooterBorderWidths[i]->mnIndex = -1;
300 		if( pFooterBorders[i] )
301 		{
302 			table::BorderLine aBorderLine;
303 			pFooterBorders[i]->maValue >>= aBorderLine;
304  			if( pFooterBorderWidths[i] )
305 			{
306 				table::BorderLine aBorderLineWidth;
307 				pFooterBorderWidths[i]->maValue >>= aBorderLineWidth;
308 				aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
309 				aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
310 				aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
311 				pFooterBorders[i]->maValue <<= aBorderLine;
312 			}
313 		}
314 	}
315 
316 	if (pHeaderHeight)
317 	{
318 		sal_Bool bValue(sal_False);
319 		uno::Any aAny;
320 		aAny.setValue( &bValue, ::getBooleanCppuType() );
321 		pHeaderDynamic = new XMLPropertyState(pHeaderHeight->mnIndex + 2, aAny);
322 	}
323 	if (pHeaderMinHeight)
324 	{
325 		sal_Bool bValue(sal_True);
326 		uno::Any aAny;
327 		aAny.setValue( &bValue, ::getBooleanCppuType() );
328 		pHeaderDynamic = new XMLPropertyState(pHeaderMinHeight->mnIndex + 1, aAny);
329 	}
330 	if (pFooterHeight)
331 	{
332 		sal_Bool bValue(sal_False);
333 		uno::Any aAny;
334 		aAny.setValue( &bValue, ::getBooleanCppuType() );
335 		pFooterDynamic = new XMLPropertyState(pFooterHeight->mnIndex + 2, aAny);
336 	}
337 	if (pFooterMinHeight)
338 	{
339 		sal_Bool bValue(sal_True);
340 		uno::Any aAny;
341 		aAny.setValue( &bValue, ::getBooleanCppuType() );
342 		pFooterDynamic = new XMLPropertyState(pFooterMinHeight->mnIndex + 1, aAny);
343 	}
344     for (sal_uInt16 i = 0; i < 4; i++)
345     {
346         if (pNewMargins[i].get())
347         {
348             rProperties.push_back(*pNewMargins[i]);
349         }
350         if (pNewHeaderMargins[i].get())
351         {
352             rProperties.push_back(*pNewHeaderMargins[i]);
353         }
354         if (pNewFooterMargins[i].get())
355         {
356             rProperties.push_back(*pNewFooterMargins[i]);
357         }
358 		if (pNewPadding[i])
359 		{
360 			rProperties.push_back(*pNewPadding[i]);
361 			delete pNewPadding[i];
362 		}
363 		if (pNewBorders[i])
364 		{
365 			rProperties.push_back(*pNewBorders[i]);
366 			delete pNewBorders[i];
367 		}
368 		if (pHeaderNewPadding[i])
369 		{
370 			rProperties.push_back(*pHeaderNewPadding[i]);
371 			delete pHeaderNewPadding[i];
372 		}
373 		if (pHeaderNewBorders[i])
374 		{
375 			rProperties.push_back(*pHeaderNewBorders[i]);
376 			delete pHeaderNewBorders[i];
377 		}
378 		if (pFooterNewPadding[i])
379 		{
380 			rProperties.push_back(*pFooterNewPadding[i]);
381 			delete pFooterNewPadding[i];
382 		}
383 		if (pFooterNewBorders[i])
384 		{
385 			rProperties.push_back(*pFooterNewBorders[i]);
386 			delete pFooterNewBorders[i];
387 		}
388 	}
389 	if(pHeaderDynamic)
390 	{
391 		rProperties.push_back(*pHeaderDynamic);
392 		delete pHeaderDynamic;
393 	}
394 	if(pFooterDynamic)
395 	{
396 		rProperties.push_back(*pFooterDynamic);
397 		delete pFooterDynamic;
398 	}
399 }
400 
401