1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PageMasterExportPropMapper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "PageMasterExportPropMapper.hxx"
34 #include <xmloff/xmltoken.hxx>
35 #include <comphelper/types.hxx>
36 #include <com/sun/star/table/BorderLine.hpp>
37 #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX
38 #include <xmloff/PageMasterStyleMap.hxx>
40 #include <tools/debug.hxx>
41 #include <rtl/ustrbuf.hxx>
42 #include <comphelper/extract.hxx>
44 using namespace ::com::sun::star
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::beans
;
47 using namespace ::comphelper
;
48 using namespace ::xmloff::token
;
51 //______________________________________________________________________________
53 inline sal_Bool
lcl_HasSameLineWidth( const table::BorderLine
& rLine1
, const table::BorderLine
& rLine2
)
55 return (rLine1
.InnerLineWidth
== rLine2
.InnerLineWidth
) &&
56 (rLine1
.OuterLineWidth
== rLine2
.OuterLineWidth
) &&
57 (rLine1
.LineDistance
== rLine2
.LineDistance
);
60 inline sal_Bool
operator==( const table::BorderLine
& rLine1
, const table::BorderLine
& rLine2
)
62 return (rLine1
.Color
== rLine2
.Color
) &&
63 lcl_HasSameLineWidth( rLine1
, rLine2
);
66 inline void lcl_RemoveState( XMLPropertyState
* pState
)
69 pState
->maValue
.clear();
72 void lcl_RemoveStateIfZero16( XMLPropertyState
* pState
)
74 sal_Int16 nValue
= sal_Int16();
75 if( (pState
->maValue
>>= nValue
) && !nValue
)
76 lcl_RemoveState( pState
);
79 void lcl_AddState(::std::vector
< XMLPropertyState
>& rPropState
, sal_Int32 nIndex
, const rtl::OUString
& rProperty
, uno::Reference
< beans::XPropertySet
>& xProps
)
81 if(::cppu::any2bool(xProps
->getPropertyValue(rProperty
)))
82 rPropState
.push_back(XMLPropertyState (nIndex
, cppu::bool2any(sal_True
)));
85 //______________________________________________________________________________
86 // helper struct to handle equal XMLPropertyState's for page, header and footer
88 struct XMLPropertyStateBuffer
90 XMLPropertyState
* pPMBorderAll
;
91 XMLPropertyState
* pPMBorderTop
;
92 XMLPropertyState
* pPMBorderBottom
;
93 XMLPropertyState
* pPMBorderLeft
;
94 XMLPropertyState
* pPMBorderRight
;
96 XMLPropertyState
* pPMBorderWidthAll
;
97 XMLPropertyState
* pPMBorderWidthTop
;
98 XMLPropertyState
* pPMBorderWidthBottom
;
99 XMLPropertyState
* pPMBorderWidthLeft
;
100 XMLPropertyState
* pPMBorderWidthRight
;
102 XMLPropertyState
* pPMPaddingAll
;
103 XMLPropertyState
* pPMPaddingTop
;
104 XMLPropertyState
* pPMPaddingBottom
;
105 XMLPropertyState
* pPMPaddingLeft
;
106 XMLPropertyState
* pPMPaddingRight
;
108 XMLPropertyStateBuffer();
109 void ContextFilter( ::std::vector
< XMLPropertyState
>& rPropState
);
112 XMLPropertyStateBuffer::XMLPropertyStateBuffer() :
113 pPMBorderAll( NULL
),
114 pPMBorderTop( NULL
),
115 pPMBorderBottom( NULL
),
116 pPMBorderLeft( NULL
),
117 pPMBorderRight( NULL
),
119 pPMBorderWidthAll( NULL
),
120 pPMBorderWidthTop( NULL
),
121 pPMBorderWidthBottom( NULL
),
122 pPMBorderWidthLeft( NULL
),
123 pPMBorderWidthRight( NULL
),
125 pPMPaddingAll( NULL
),
126 pPMPaddingTop( NULL
),
127 pPMPaddingBottom( NULL
),
128 pPMPaddingLeft( NULL
),
129 pPMPaddingRight( NULL
)
133 void XMLPropertyStateBuffer::ContextFilter( ::std::vector
< XMLPropertyState
>& )
137 if( pPMBorderTop
&& pPMBorderBottom
&& pPMBorderLeft
&& pPMBorderRight
)
139 table::BorderLine aLineTop
, aLineBottom
, aLineLeft
, aLineRight
;
141 pPMBorderTop
->maValue
>>= aLineTop
;
142 pPMBorderBottom
->maValue
>>= aLineBottom
;
143 pPMBorderLeft
->maValue
>>= aLineLeft
;
144 pPMBorderRight
->maValue
>>= aLineRight
;
146 if( (aLineTop
== aLineBottom
) && (aLineBottom
== aLineLeft
) && (aLineLeft
== aLineRight
) )
148 lcl_RemoveState( pPMBorderTop
);
149 lcl_RemoveState( pPMBorderBottom
);
150 lcl_RemoveState( pPMBorderLeft
);
151 lcl_RemoveState( pPMBorderRight
);
154 lcl_RemoveState( pPMBorderAll
);
157 lcl_RemoveState( pPMBorderAll
);
160 if( pPMBorderWidthAll
)
162 if( pPMBorderWidthTop
&& pPMBorderWidthBottom
&& pPMBorderWidthLeft
&& pPMBorderWidthRight
)
164 table::BorderLine aLineTop
, aLineBottom
, aLineLeft
, aLineRight
;
166 pPMBorderWidthTop
->maValue
>>= aLineTop
;
167 pPMBorderWidthBottom
->maValue
>>= aLineBottom
;
168 pPMBorderWidthLeft
->maValue
>>= aLineLeft
;
169 pPMBorderWidthRight
->maValue
>>= aLineRight
;
171 if( lcl_HasSameLineWidth( aLineTop
, aLineBottom
) &&
172 lcl_HasSameLineWidth( aLineBottom
, aLineLeft
) &&
173 lcl_HasSameLineWidth( aLineLeft
, aLineRight
) )
175 lcl_RemoveState( pPMBorderWidthTop
);
176 lcl_RemoveState( pPMBorderWidthBottom
);
177 lcl_RemoveState( pPMBorderWidthLeft
);
178 lcl_RemoveState( pPMBorderWidthRight
);
181 lcl_RemoveState( pPMBorderWidthAll
);
184 lcl_RemoveState( pPMBorderWidthAll
);
189 if( pPMPaddingTop
&& pPMPaddingBottom
&& pPMPaddingLeft
&& pPMPaddingRight
)
191 sal_Int32 nTop
= 0, nBottom
= 0, nLeft
= 0, nRight
= 0;
193 pPMPaddingTop
->maValue
>>= nTop
;
194 pPMPaddingBottom
->maValue
>>= nBottom
;
195 pPMPaddingLeft
->maValue
>>= nLeft
;
196 pPMPaddingRight
->maValue
>>= nRight
;
198 if( (nTop
== nBottom
) && (nBottom
== nLeft
) && (nLeft
== nRight
) )
200 lcl_RemoveState( pPMPaddingTop
);
201 lcl_RemoveState( pPMPaddingBottom
);
202 lcl_RemoveState( pPMPaddingLeft
);
203 lcl_RemoveState( pPMPaddingRight
);
206 lcl_RemoveState( pPMPaddingAll
);
209 lcl_RemoveState( pPMPaddingAll
);
213 //______________________________________________________________________________
215 XMLPageMasterExportPropMapper::XMLPageMasterExportPropMapper(
216 const UniReference
< XMLPropertySetMapper
>& rMapper
,
217 SvXMLExport
& rExport
) :
218 SvXMLExportPropertyMapper( rMapper
),
219 aBackgroundImageExport( rExport
),
220 aTextColumnsExport( rExport
),
221 aFootnoteSeparatorExport( rExport
)
225 XMLPageMasterExportPropMapper::~XMLPageMasterExportPropMapper()
229 void XMLPageMasterExportPropMapper::handleElementItem(
231 const XMLPropertyState
& rProperty
,
232 sal_uInt16
/*nFlags*/,
233 const ::std::vector
< XMLPropertyState
>* pProperties
,
234 sal_uInt32 nIdx
) const
236 XMLPageMasterExportPropMapper
* pThis
= (XMLPageMasterExportPropMapper
*) this;
238 sal_uInt32 nContextId
= getPropertySetMapper()->GetEntryContextId( rProperty
.mnIndex
);
241 case CTF_PM_GRAPHICURL
:
242 case CTF_PM_HEADERGRAPHICURL
:
243 case CTF_PM_FOOTERGRAPHICURL
:
245 DBG_ASSERT( pProperties
&& (nIdx
>= 2), "property vector missing" );
250 case CTF_PM_GRAPHICURL
:
251 nPos
= CTF_PM_GRAPHICPOSITION
;
252 nFilter
= CTF_PM_GRAPHICFILTER
;
254 case CTF_PM_HEADERGRAPHICURL
:
255 nPos
= CTF_PM_HEADERGRAPHICPOSITION
;
256 nFilter
= CTF_PM_HEADERGRAPHICFILTER
;
258 case CTF_PM_FOOTERGRAPHICURL
:
259 nPos
= CTF_PM_FOOTERGRAPHICPOSITION
;
260 nFilter
= CTF_PM_FOOTERGRAPHICFILTER
;
263 nPos
= 0; // TODO What values should this be?
266 const Any
* pPos
= NULL
;
267 const Any
* pFilter
= NULL
;
268 if( pProperties
&& (nIdx
>= 2) )
270 const XMLPropertyState
& rPos
= (*pProperties
)[nIdx
- 2];
271 DBG_ASSERT( getPropertySetMapper()->GetEntryContextId( rPos
.mnIndex
) == nPos
,
272 "invalid property map: pos expected" );
273 if( getPropertySetMapper()->GetEntryContextId( rPos
.mnIndex
) == nPos
)
274 pPos
= &rPos
.maValue
;
276 const XMLPropertyState
& rFilter
= (*pProperties
)[nIdx
- 1];
277 DBG_ASSERT( getPropertySetMapper()->GetEntryContextId( rFilter
.mnIndex
) == nFilter
,
278 "invalid property map: filter expected" );
279 if( getPropertySetMapper()->GetEntryContextId( rFilter
.mnIndex
) == nFilter
)
280 pFilter
= &rFilter
.maValue
;
282 sal_uInt32 nPropIndex
= rProperty
.mnIndex
;
283 pThis
->aBackgroundImageExport
.exportXML( rProperty
.maValue
, pPos
, pFilter
, NULL
,
284 getPropertySetMapper()->GetEntryNameSpace( nPropIndex
),
285 getPropertySetMapper()->GetEntryXMLName( nPropIndex
) );
288 case CTF_PM_TEXTCOLUMNS
:
289 pThis
->aTextColumnsExport
.exportXML( rProperty
.maValue
);
291 case CTF_PM_FTN_LINE_WEIGTH
:
292 pThis
->aFootnoteSeparatorExport
.exportXML( pProperties
, nIdx
,
293 getPropertySetMapper());
298 void XMLPageMasterExportPropMapper::handleSpecialItem(
300 const XMLPropertyState
&,
301 const SvXMLUnitConverter
&,
302 const SvXMLNamespaceMap
&,
303 const ::std::vector
< XMLPropertyState
>*,
304 sal_uInt32
/*nIdx*/) const
308 void XMLPageMasterExportPropMapper::ContextFilter(
309 ::std::vector
< XMLPropertyState
>& rPropState
,
310 Reference
< XPropertySet
> rPropSet
) const
312 XMLPropertyStateBuffer aPageBuffer
;
313 XMLPropertyStateBuffer aHeaderBuffer
;
314 XMLPropertyStateBuffer aFooterBuffer
;
316 XMLPropertyState
* pPMHeaderHeight
= NULL
;
317 XMLPropertyState
* pPMHeaderMinHeight
= NULL
;
318 XMLPropertyState
* pPMHeaderDynamic
= NULL
;
320 XMLPropertyState
* pPMFooterHeight
= NULL
;
321 XMLPropertyState
* pPMFooterMinHeight
= NULL
;
322 XMLPropertyState
* pPMFooterDynamic
= NULL
;
324 XMLPropertyState
* pPMScaleTo
= NULL
;
325 XMLPropertyState
* pPMScaleToPages
= NULL
;
326 XMLPropertyState
* pPMScaleToX
= NULL
;
327 XMLPropertyState
* pPMScaleToY
= NULL
;
328 XMLPropertyState
* pPMStandardMode
= NULL
;
329 XMLPropertyState
* pPMGridBaseWidth
= NULL
;
330 XMLPropertyState
* pPMGridSnapToChars
= NULL
;
332 XMLPropertyState
* pPrint
= NULL
;
334 UniReference
< XMLPropertySetMapper
> aPropMapper(getPropertySetMapper());
336 for( ::std::vector
< XMLPropertyState
>::iterator aIter
= rPropState
.begin(); aIter
!= rPropState
.end(); ++aIter
)
338 XMLPropertyState
*pProp
= &(*aIter
);
339 sal_Int16 nContextId
= aPropMapper
->GetEntryContextId( pProp
->mnIndex
);
340 sal_Int16 nFlag
= nContextId
& CTF_PM_FLAGMASK
;
341 sal_Int16 nSimpleId
= nContextId
& (~CTF_PM_FLAGMASK
| XML_PM_CTF_START
);
342 sal_Int16 nPrintId
= nContextId
& CTF_PM_PRINTMASK
;
344 XMLPropertyStateBuffer
* pBuffer
;
347 case CTF_PM_HEADERFLAG
: pBuffer
= &aHeaderBuffer
; break;
348 case CTF_PM_FOOTERFLAG
: pBuffer
= &aFooterBuffer
; break;
349 default: pBuffer
= &aPageBuffer
; break;
354 case CTF_PM_BORDERALL
: pBuffer
->pPMBorderAll
= pProp
; break;
355 case CTF_PM_BORDERTOP
: pBuffer
->pPMBorderTop
= pProp
; break;
356 case CTF_PM_BORDERBOTTOM
: pBuffer
->pPMBorderBottom
= pProp
; break;
357 case CTF_PM_BORDERLEFT
: pBuffer
->pPMBorderLeft
= pProp
; break;
358 case CTF_PM_BORDERRIGHT
: pBuffer
->pPMBorderRight
= pProp
; break;
359 case CTF_PM_BORDERWIDTHALL
: pBuffer
->pPMBorderWidthAll
= pProp
; break;
360 case CTF_PM_BORDERWIDTHTOP
: pBuffer
->pPMBorderWidthTop
= pProp
; break;
361 case CTF_PM_BORDERWIDTHBOTTOM
: pBuffer
->pPMBorderWidthBottom
= pProp
; break;
362 case CTF_PM_BORDERWIDTHLEFT
: pBuffer
->pPMBorderWidthLeft
= pProp
; break;
363 case CTF_PM_BORDERWIDTHRIGHT
: pBuffer
->pPMBorderWidthRight
= pProp
; break;
364 case CTF_PM_PADDINGALL
: pBuffer
->pPMPaddingAll
= pProp
; break;
365 case CTF_PM_PADDINGTOP
: pBuffer
->pPMPaddingTop
= pProp
; break;
366 case CTF_PM_PADDINGBOTTOM
: pBuffer
->pPMPaddingBottom
= pProp
; break;
367 case CTF_PM_PADDINGLEFT
: pBuffer
->pPMPaddingLeft
= pProp
; break;
368 case CTF_PM_PADDINGRIGHT
: pBuffer
->pPMPaddingRight
= pProp
; break;
373 case CTF_PM_HEADERHEIGHT
: pPMHeaderHeight
= pProp
; break;
374 case CTF_PM_HEADERMINHEIGHT
: pPMHeaderMinHeight
= pProp
; break;
375 case CTF_PM_HEADERDYNAMIC
: pPMHeaderDynamic
= pProp
; break;
376 case CTF_PM_FOOTERHEIGHT
: pPMFooterHeight
= pProp
; break;
377 case CTF_PM_FOOTERMINHEIGHT
: pPMFooterMinHeight
= pProp
; break;
378 case CTF_PM_FOOTERDYNAMIC
: pPMFooterDynamic
= pProp
; break;
379 case CTF_PM_SCALETO
: pPMScaleTo
= pProp
; break;
380 case CTF_PM_SCALETOPAGES
: pPMScaleToPages
= pProp
; break;
381 case CTF_PM_SCALETOX
: pPMScaleToX
= pProp
; break;
382 case CTF_PM_SCALETOY
: pPMScaleToY
= pProp
; break;
383 case CTF_PM_STANDARD_MODE
: pPMStandardMode
= pProp
; break;
384 case CTP_PM_GRID_BASE_WIDTH
: pPMGridBaseWidth
= pProp
; break;
385 case CTP_PM_GRID_SNAP_TO_CHARS
: pPMGridSnapToChars
= pProp
; break;
387 if (nPrintId
== CTF_PM_PRINTMASK
)
390 lcl_RemoveState(pPrint
);
394 if( pPMStandardMode
&& !getBOOL(pPMStandardMode
->maValue
) )
396 lcl_RemoveState(pPMStandardMode
);
397 if( pPMGridBaseWidth
)
398 lcl_RemoveState(pPMGridBaseWidth
);
399 if( pPMGridSnapToChars
)
400 lcl_RemoveState(pPMGridSnapToChars
);
403 if( pPMGridBaseWidth
&& pPMStandardMode
)
404 lcl_RemoveState(pPMStandardMode
);
406 aPageBuffer
.ContextFilter( rPropState
);
407 aHeaderBuffer
.ContextFilter( rPropState
);
408 aFooterBuffer
.ContextFilter( rPropState
);
410 if( pPMHeaderHeight
&& (!pPMHeaderDynamic
|| (pPMHeaderDynamic
&& getBOOL( pPMHeaderDynamic
->maValue
))) )
411 lcl_RemoveState( pPMHeaderHeight
);
412 if( pPMHeaderMinHeight
&& pPMHeaderDynamic
&& !getBOOL( pPMHeaderDynamic
->maValue
) )
413 lcl_RemoveState( pPMHeaderMinHeight
);
414 if( pPMHeaderDynamic
)
415 lcl_RemoveState( pPMHeaderDynamic
);
417 if( pPMFooterHeight
&& (!pPMFooterDynamic
|| (pPMFooterDynamic
&& getBOOL( pPMFooterDynamic
->maValue
))) )
418 lcl_RemoveState( pPMFooterHeight
);
419 if( pPMFooterMinHeight
&& pPMFooterDynamic
&& !getBOOL( pPMFooterDynamic
->maValue
) )
420 lcl_RemoveState( pPMFooterMinHeight
);
421 if( pPMFooterDynamic
)
422 lcl_RemoveState( pPMFooterDynamic
);
425 lcl_RemoveStateIfZero16( pPMScaleTo
);
426 if( pPMScaleToPages
)
427 lcl_RemoveStateIfZero16( pPMScaleToPages
);
429 lcl_RemoveStateIfZero16( pPMScaleToX
);
431 lcl_RemoveStateIfZero16( pPMScaleToY
);
435 lcl_AddState(rPropState
, aPropMapper
->FindEntryIndex(CTF_PM_PRINT_ANNOTATIONS
), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintAnnotations")), rPropSet
);
436 lcl_AddState(rPropState
, aPropMapper
->FindEntryIndex(CTF_PM_PRINT_CHARTS
), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintCharts")), rPropSet
);
437 lcl_AddState(rPropState
, aPropMapper
->FindEntryIndex(CTF_PM_PRINT_DRAWING
), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintDrawing")), rPropSet
);
438 lcl_AddState(rPropState
, aPropMapper
->FindEntryIndex(CTF_PM_PRINT_FORMULAS
), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintFormulas")), rPropSet
);
439 lcl_AddState(rPropState
, aPropMapper
->FindEntryIndex(CTF_PM_PRINT_GRID
), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintGrid")), rPropSet
);
440 lcl_AddState(rPropState
, aPropMapper
->FindEntryIndex(CTF_PM_PRINT_HEADERS
), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintHeaders")), rPropSet
);
441 lcl_AddState(rPropState
, aPropMapper
->FindEntryIndex(CTF_PM_PRINT_OBJECTS
), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintObjects")), rPropSet
);
442 lcl_AddState(rPropState
, aPropMapper
->FindEntryIndex(CTF_PM_PRINT_ZEROVALUES
), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintZeroValues")), rPropSet
);
445 SvXMLExportPropertyMapper::ContextFilter(rPropState
,rPropSet
);