Bump for 3.6-28
[LibreOffice.git] / xmloff / source / style / PageMasterExportPropMapper.cxx
blobeedb4a4a9396958a81a00384aa457aede5469f9e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "PageMasterExportPropMapper.hxx"
30 #include <xmloff/xmltoken.hxx>
31 #include <comphelper/types.hxx>
32 #include <com/sun/star/table/BorderLine2.hpp>
33 #include <xmloff/PageMasterStyleMap.hxx>
34 #include <tools/debug.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include <comphelper/extract.hxx>
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::comphelper;
42 using namespace ::xmloff::token;
45 //______________________________________________________________________________
47 inline sal_Bool lcl_HasSameLineWidth( const table::BorderLine2& rLine1, const table::BorderLine2& rLine2 )
49 return (rLine1.InnerLineWidth == rLine2.InnerLineWidth) &&
50 (rLine1.OuterLineWidth == rLine2.OuterLineWidth) &&
51 (rLine1.LineDistance == rLine2.LineDistance) &&
52 (rLine1.LineWidth == rLine2.LineWidth);
55 inline sal_Bool operator==( const table::BorderLine2& rLine1, const table::BorderLine2& rLine2 )
57 return (rLine1.Color == rLine2.Color) &&
58 lcl_HasSameLineWidth( rLine1, rLine2 ) &&
59 ( rLine1.LineStyle == rLine2.LineStyle );
62 inline void lcl_RemoveState( XMLPropertyState* pState )
64 pState->mnIndex = -1;
65 pState->maValue.clear();
68 void lcl_RemoveStateIfZero16( XMLPropertyState* pState )
70 sal_Int16 nValue = sal_Int16();
71 if( (pState->maValue >>= nValue) && !nValue )
72 lcl_RemoveState( pState );
75 void lcl_AddState(::std::vector< XMLPropertyState >& rPropState, sal_Int32 nIndex, const rtl::OUString& rProperty, uno::Reference< beans::XPropertySet >& xProps)
77 if(::cppu::any2bool(xProps->getPropertyValue(rProperty)))
78 rPropState.push_back(XMLPropertyState (nIndex, cppu::bool2any(sal_True)));
81 //______________________________________________________________________________
82 // helper struct to handle equal XMLPropertyState's for page, header and footer
84 struct XMLPropertyStateBuffer
86 XMLPropertyState* pPMMarginAll;
87 XMLPropertyState* pPMMarginTop;
88 XMLPropertyState* pPMMarginBottom;
89 XMLPropertyState* pPMMarginLeft;
90 XMLPropertyState* pPMMarginRight;
92 XMLPropertyState* pPMBorderAll;
93 XMLPropertyState* pPMBorderTop;
94 XMLPropertyState* pPMBorderBottom;
95 XMLPropertyState* pPMBorderLeft;
96 XMLPropertyState* pPMBorderRight;
98 XMLPropertyState* pPMBorderWidthAll;
99 XMLPropertyState* pPMBorderWidthTop;
100 XMLPropertyState* pPMBorderWidthBottom;
101 XMLPropertyState* pPMBorderWidthLeft;
102 XMLPropertyState* pPMBorderWidthRight;
104 XMLPropertyState* pPMPaddingAll;
105 XMLPropertyState* pPMPaddingTop;
106 XMLPropertyState* pPMPaddingBottom;
107 XMLPropertyState* pPMPaddingLeft;
108 XMLPropertyState* pPMPaddingRight;
110 XMLPropertyStateBuffer();
111 void ContextFilter( ::std::vector< XMLPropertyState >& rPropState );
114 XMLPropertyStateBuffer::XMLPropertyStateBuffer()
115 : pPMMarginAll( NULL )
116 , pPMMarginTop( NULL )
117 , pPMMarginBottom( NULL )
118 , pPMMarginLeft( NULL )
119 , pPMMarginRight( NULL )
121 pPMBorderAll( NULL ),
122 pPMBorderTop( NULL ),
123 pPMBorderBottom( NULL ),
124 pPMBorderLeft( NULL ),
125 pPMBorderRight( NULL ),
127 pPMBorderWidthAll( NULL ),
128 pPMBorderWidthTop( NULL ),
129 pPMBorderWidthBottom( NULL ),
130 pPMBorderWidthLeft( NULL ),
131 pPMBorderWidthRight( NULL ),
133 pPMPaddingAll( NULL ),
134 pPMPaddingTop( NULL ),
135 pPMPaddingBottom( NULL ),
136 pPMPaddingLeft( NULL ),
137 pPMPaddingRight( NULL )
141 void XMLPropertyStateBuffer::ContextFilter( ::std::vector< XMLPropertyState >& )
143 if (pPMMarginAll)
145 if (pPMMarginTop && pPMMarginBottom && pPMMarginLeft && pPMMarginRight)
147 sal_Int32 nTop = 0, nBottom = 0, nLeft = 0, nRight = 0;
149 pPMMarginTop->maValue >>= nTop;
150 pPMMarginBottom->maValue >>= nBottom;
151 pPMMarginLeft->maValue >>= nLeft;
152 pPMMarginRight->maValue >>= nRight;
154 // Don't remove the Margin Left,Right,Top,Bottom for backward compatibility
155 if ((nTop != nBottom) || (nBottom != nLeft) || (nLeft != nRight))
156 lcl_RemoveState( pPMMarginAll );
158 else
159 lcl_RemoveState( pPMMarginAll );
162 if( pPMBorderAll )
164 if( pPMBorderTop && pPMBorderBottom && pPMBorderLeft && pPMBorderRight )
166 table::BorderLine2 aLineTop, aLineBottom, aLineLeft, aLineRight;
168 pPMBorderTop->maValue >>= aLineTop;
169 pPMBorderBottom->maValue >>= aLineBottom;
170 pPMBorderLeft->maValue >>= aLineLeft;
171 pPMBorderRight->maValue >>= aLineRight;
173 if( (aLineTop == aLineBottom) && (aLineBottom == aLineLeft) && (aLineLeft == aLineRight) )
175 lcl_RemoveState( pPMBorderTop );
176 lcl_RemoveState( pPMBorderBottom );
177 lcl_RemoveState( pPMBorderLeft );
178 lcl_RemoveState( pPMBorderRight );
180 else
181 lcl_RemoveState( pPMBorderAll );
183 else
184 lcl_RemoveState( pPMBorderAll );
187 if( pPMBorderWidthAll )
189 if( pPMBorderWidthTop && pPMBorderWidthBottom && pPMBorderWidthLeft && pPMBorderWidthRight )
191 table::BorderLine2 aLineTop, aLineBottom, aLineLeft, aLineRight;
193 pPMBorderWidthTop->maValue >>= aLineTop;
194 pPMBorderWidthBottom->maValue >>= aLineBottom;
195 pPMBorderWidthLeft->maValue >>= aLineLeft;
196 pPMBorderWidthRight->maValue >>= aLineRight;
198 if( lcl_HasSameLineWidth( aLineTop, aLineBottom ) &&
199 lcl_HasSameLineWidth( aLineBottom, aLineLeft ) &&
200 lcl_HasSameLineWidth( aLineLeft, aLineRight ) )
202 lcl_RemoveState( pPMBorderWidthTop );
203 lcl_RemoveState( pPMBorderWidthBottom );
204 lcl_RemoveState( pPMBorderWidthLeft );
205 lcl_RemoveState( pPMBorderWidthRight );
207 else
208 lcl_RemoveState( pPMBorderWidthAll );
210 else
211 lcl_RemoveState( pPMBorderWidthAll );
214 if( pPMPaddingAll )
216 if( pPMPaddingTop && pPMPaddingBottom && pPMPaddingLeft && pPMPaddingRight )
218 sal_Int32 nTop = 0, nBottom = 0, nLeft = 0, nRight = 0;
220 pPMPaddingTop->maValue >>= nTop;
221 pPMPaddingBottom->maValue >>= nBottom;
222 pPMPaddingLeft->maValue >>= nLeft;
223 pPMPaddingRight->maValue >>= nRight;
225 if( (nTop == nBottom) && (nBottom == nLeft) && (nLeft == nRight) )
227 lcl_RemoveState( pPMPaddingTop );
228 lcl_RemoveState( pPMPaddingBottom );
229 lcl_RemoveState( pPMPaddingLeft );
230 lcl_RemoveState( pPMPaddingRight );
232 else
233 lcl_RemoveState( pPMPaddingAll );
235 else
236 lcl_RemoveState( pPMPaddingAll );
240 //______________________________________________________________________________
242 XMLPageMasterExportPropMapper::XMLPageMasterExportPropMapper(
243 const UniReference< XMLPropertySetMapper >& rMapper,
244 SvXMLExport& rExport ) :
245 SvXMLExportPropertyMapper( rMapper ),
246 aBackgroundImageExport( rExport ),
247 aTextColumnsExport( rExport ),
248 aFootnoteSeparatorExport( rExport )
252 XMLPageMasterExportPropMapper::~XMLPageMasterExportPropMapper()
256 void XMLPageMasterExportPropMapper::handleElementItem(
257 SvXMLExport&,
258 const XMLPropertyState& rProperty,
259 sal_uInt16 /*nFlags*/,
260 const ::std::vector< XMLPropertyState >* pProperties,
261 sal_uInt32 nIdx ) const
263 XMLPageMasterExportPropMapper* pThis = (XMLPageMasterExportPropMapper*) this;
265 sal_uInt32 nContextId = getPropertySetMapper()->GetEntryContextId( rProperty.mnIndex );
266 switch( nContextId )
268 case CTF_PM_GRAPHICURL:
269 case CTF_PM_HEADERGRAPHICURL:
270 case CTF_PM_FOOTERGRAPHICURL:
272 DBG_ASSERT( pProperties && (nIdx >= 2), "property vector missing" );
273 sal_Int32 nPos;
274 sal_Int32 nFilter;
275 switch( nContextId )
277 case CTF_PM_GRAPHICURL:
278 nPos = CTF_PM_GRAPHICPOSITION;
279 nFilter = CTF_PM_GRAPHICFILTER;
280 break;
281 case CTF_PM_HEADERGRAPHICURL:
282 nPos = CTF_PM_HEADERGRAPHICPOSITION;
283 nFilter = CTF_PM_HEADERGRAPHICFILTER;
284 break;
285 case CTF_PM_FOOTERGRAPHICURL:
286 nPos = CTF_PM_FOOTERGRAPHICPOSITION;
287 nFilter = CTF_PM_FOOTERGRAPHICFILTER;
288 break;
289 default:
290 nPos = 0; // TODO What values should this be?
291 nFilter = 0;
293 const Any* pPos = NULL;
294 const Any* pFilter = NULL;
295 if( pProperties && (nIdx >= 2) )
297 const XMLPropertyState& rPos = (*pProperties)[nIdx - 2];
298 DBG_ASSERT( getPropertySetMapper()->GetEntryContextId( rPos.mnIndex ) == nPos,
299 "invalid property map: pos expected" );
300 if( getPropertySetMapper()->GetEntryContextId( rPos.mnIndex ) == nPos )
301 pPos = &rPos.maValue;
303 const XMLPropertyState& rFilter = (*pProperties)[nIdx - 1];
304 DBG_ASSERT( getPropertySetMapper()->GetEntryContextId( rFilter.mnIndex ) == nFilter,
305 "invalid property map: filter expected" );
306 if( getPropertySetMapper()->GetEntryContextId( rFilter.mnIndex ) == nFilter )
307 pFilter = &rFilter.maValue;
309 sal_uInt32 nPropIndex = rProperty.mnIndex;
310 pThis->aBackgroundImageExport.exportXML( rProperty.maValue, pPos, pFilter, NULL,
311 getPropertySetMapper()->GetEntryNameSpace( nPropIndex ),
312 getPropertySetMapper()->GetEntryXMLName( nPropIndex ) );
314 break;
315 case CTF_PM_TEXTCOLUMNS:
316 pThis->aTextColumnsExport.exportXML( rProperty.maValue );
317 break;
318 case CTF_PM_FTN_LINE_WEIGTH:
319 pThis->aFootnoteSeparatorExport.exportXML( pProperties, nIdx,
320 getPropertySetMapper());
321 break;
325 void XMLPageMasterExportPropMapper::handleSpecialItem(
326 SvXMLAttributeList&,
327 const XMLPropertyState&,
328 const SvXMLUnitConverter&,
329 const SvXMLNamespaceMap&,
330 const ::std::vector< XMLPropertyState >*,
331 sal_uInt32 /*nIdx*/) const
335 void XMLPageMasterExportPropMapper::ContextFilter(
336 ::std::vector< XMLPropertyState >& rPropState,
337 Reference< XPropertySet > rPropSet ) const
339 XMLPropertyStateBuffer aPageBuffer;
340 XMLPropertyStateBuffer aHeaderBuffer;
341 XMLPropertyStateBuffer aFooterBuffer;
343 XMLPropertyState* pPMHeaderHeight = NULL;
344 XMLPropertyState* pPMHeaderMinHeight = NULL;
345 XMLPropertyState* pPMHeaderDynamic = NULL;
347 XMLPropertyState* pPMFooterHeight = NULL;
348 XMLPropertyState* pPMFooterMinHeight = NULL;
349 XMLPropertyState* pPMFooterDynamic = NULL;
351 XMLPropertyState* pPMScaleTo = NULL;
352 XMLPropertyState* pPMScaleToPages = NULL;
353 XMLPropertyState* pPMScaleToX = NULL;
354 XMLPropertyState* pPMScaleToY = NULL;
355 XMLPropertyState* pPMStandardMode = NULL;
356 XMLPropertyState* pPMGridBaseWidth = NULL;
357 // same as pPMGridSnapTo but for backward compatibility only
358 XMLPropertyState* pPMGridSnapToChars = NULL;
359 XMLPropertyState* pPMGridSnapTo = NULL;
361 XMLPropertyState* pPrint = NULL;
363 UniReference < XMLPropertySetMapper > aPropMapper(getPropertySetMapper());
365 for( ::std::vector< XMLPropertyState >::iterator aIter = rPropState.begin(); aIter != rPropState.end(); ++aIter )
367 XMLPropertyState *pProp = &(*aIter);
368 sal_Int16 nContextId = aPropMapper->GetEntryContextId( pProp->mnIndex );
369 sal_Int16 nFlag = nContextId & CTF_PM_FLAGMASK;
370 sal_Int16 nSimpleId = nContextId & (~CTF_PM_FLAGMASK | XML_PM_CTF_START);
371 sal_Int16 nPrintId = nContextId & CTF_PM_PRINTMASK;
373 XMLPropertyStateBuffer* pBuffer;
374 switch( nFlag )
376 case CTF_PM_HEADERFLAG: pBuffer = &aHeaderBuffer; break;
377 case CTF_PM_FOOTERFLAG: pBuffer = &aFooterBuffer; break;
378 default: pBuffer = &aPageBuffer; break;
381 switch( nSimpleId )
383 case CTF_PM_MARGINALL: pBuffer->pPMMarginAll = pProp; break;
384 case CTF_PM_MARGINTOP: pBuffer->pPMMarginTop = pProp; break;
385 case CTF_PM_MARGINBOTTOM: pBuffer->pPMMarginBottom = pProp; break;
386 case CTF_PM_MARGINLEFT: pBuffer->pPMMarginLeft = pProp; break;
387 case CTF_PM_MARGINRIGHT: pBuffer->pPMMarginRight = pProp; break;
388 case CTF_PM_BORDERALL: pBuffer->pPMBorderAll = pProp; break;
389 case CTF_PM_BORDERTOP: pBuffer->pPMBorderTop = pProp; break;
390 case CTF_PM_BORDERBOTTOM: pBuffer->pPMBorderBottom = pProp; break;
391 case CTF_PM_BORDERLEFT: pBuffer->pPMBorderLeft = pProp; break;
392 case CTF_PM_BORDERRIGHT: pBuffer->pPMBorderRight = pProp; break;
393 case CTF_PM_BORDERWIDTHALL: pBuffer->pPMBorderWidthAll = pProp; break;
394 case CTF_PM_BORDERWIDTHTOP: pBuffer->pPMBorderWidthTop = pProp; break;
395 case CTF_PM_BORDERWIDTHBOTTOM: pBuffer->pPMBorderWidthBottom = pProp; break;
396 case CTF_PM_BORDERWIDTHLEFT: pBuffer->pPMBorderWidthLeft = pProp; break;
397 case CTF_PM_BORDERWIDTHRIGHT: pBuffer->pPMBorderWidthRight = pProp; break;
398 case CTF_PM_PADDINGALL: pBuffer->pPMPaddingAll = pProp; break;
399 case CTF_PM_PADDINGTOP: pBuffer->pPMPaddingTop = pProp; break;
400 case CTF_PM_PADDINGBOTTOM: pBuffer->pPMPaddingBottom = pProp; break;
401 case CTF_PM_PADDINGLEFT: pBuffer->pPMPaddingLeft = pProp; break;
402 case CTF_PM_PADDINGRIGHT: pBuffer->pPMPaddingRight = pProp; break;
405 switch( nContextId )
407 case CTF_PM_HEADERHEIGHT: pPMHeaderHeight = pProp; break;
408 case CTF_PM_HEADERMINHEIGHT: pPMHeaderMinHeight = pProp; break;
409 case CTF_PM_HEADERDYNAMIC: pPMHeaderDynamic = pProp; break;
410 case CTF_PM_FOOTERHEIGHT: pPMFooterHeight = pProp; break;
411 case CTF_PM_FOOTERMINHEIGHT: pPMFooterMinHeight = pProp; break;
412 case CTF_PM_FOOTERDYNAMIC: pPMFooterDynamic = pProp; break;
413 case CTF_PM_SCALETO: pPMScaleTo = pProp; break;
414 case CTF_PM_SCALETOPAGES: pPMScaleToPages = pProp; break;
415 case CTF_PM_SCALETOX: pPMScaleToX = pProp; break;
416 case CTF_PM_SCALETOY: pPMScaleToY = pProp; break;
417 case CTF_PM_STANDARD_MODE: pPMStandardMode = pProp; break;
418 case CTP_PM_GRID_BASE_WIDTH: pPMGridBaseWidth = pProp; break;
419 case CTP_PM_GRID_SNAP_TO_CHARS: pPMGridSnapToChars = pProp; break;
420 case CTP_PM_GRID_SNAP_TO: pPMGridSnapTo = pProp; break;
422 if (nPrintId == CTF_PM_PRINTMASK)
424 pPrint = pProp;
425 lcl_RemoveState(pPrint);
429 if( pPMStandardMode && !getBOOL(pPMStandardMode->maValue) )
431 lcl_RemoveState(pPMStandardMode);
432 if( pPMGridBaseWidth )
433 lcl_RemoveState(pPMGridBaseWidth);
434 if( pPMGridSnapToChars )
435 lcl_RemoveState(pPMGridSnapToChars);
436 if (pPMGridSnapTo)
438 lcl_RemoveState(pPMGridSnapTo);
442 if( pPMGridBaseWidth && pPMStandardMode )
443 lcl_RemoveState(pPMStandardMode);
445 aPageBuffer.ContextFilter( rPropState );
446 aHeaderBuffer.ContextFilter( rPropState );
447 aFooterBuffer.ContextFilter( rPropState );
449 if( pPMHeaderHeight && (!pPMHeaderDynamic || (pPMHeaderDynamic && getBOOL( pPMHeaderDynamic->maValue ))) )
450 lcl_RemoveState( pPMHeaderHeight );
451 if( pPMHeaderMinHeight && pPMHeaderDynamic && !getBOOL( pPMHeaderDynamic->maValue ) )
452 lcl_RemoveState( pPMHeaderMinHeight );
453 if( pPMHeaderDynamic )
454 lcl_RemoveState( pPMHeaderDynamic );
456 if( pPMFooterHeight && (!pPMFooterDynamic || (pPMFooterDynamic && getBOOL( pPMFooterDynamic->maValue ))) )
457 lcl_RemoveState( pPMFooterHeight );
458 if( pPMFooterMinHeight && pPMFooterDynamic && !getBOOL( pPMFooterDynamic->maValue ) )
459 lcl_RemoveState( pPMFooterMinHeight );
460 if( pPMFooterDynamic )
461 lcl_RemoveState( pPMFooterDynamic );
463 if( pPMScaleTo )
464 lcl_RemoveStateIfZero16( pPMScaleTo );
465 if( pPMScaleToPages )
466 lcl_RemoveStateIfZero16( pPMScaleToPages );
467 if( pPMScaleToX )
468 lcl_RemoveStateIfZero16( pPMScaleToX );
469 if( pPMScaleToY )
470 lcl_RemoveStateIfZero16( pPMScaleToY );
472 if (pPrint)
474 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_ANNOTATIONS), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintAnnotations")), rPropSet);
475 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_CHARTS), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintCharts")), rPropSet);
476 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_DRAWING), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintDrawing")), rPropSet);
477 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_FORMULAS), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintFormulas")), rPropSet);
478 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_GRID), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintGrid")), rPropSet);
479 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_HEADERS), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintHeaders")), rPropSet);
480 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_OBJECTS), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintObjects")), rPropSet);
481 lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_ZEROVALUES), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintZeroValues")), rPropSet);
484 SvXMLExportPropertyMapper::ContextFilter(rPropState,rPropSet);
487 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */