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: PageMasterPropHdl.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 "PageMasterPropHdl.hxx"
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include <xmloff/xmlnumi.hxx>
37 #include <xmloff/xmlnume.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <com/sun/star/uno/Any.hxx>
40 #include <com/sun/star/style/PageStyleLayout.hpp>
41 #include <comphelper/types.hxx>
42 #include <comphelper/extract.hxx>
44 using ::rtl::OUString
;
45 using ::rtl::OUStringBuffer
;
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::style
;
50 using namespace ::comphelper
;
51 using namespace ::xmloff::token
;
54 //______________________________________________________________________________
56 #define DEFAULT_PAPERTRAY (sal_Int32(-1))
59 //______________________________________________________________________________
60 // property handler for style:page-usage (style::PageStyleLayout)
62 XMLPMPropHdl_PageStyleLayout::~XMLPMPropHdl_PageStyleLayout()
66 bool XMLPMPropHdl_PageStyleLayout::equals( const Any
& rAny1
, const Any
& rAny2
) const
68 style::PageStyleLayout eLayout1
, eLayout2
;
69 return ((rAny1
>>= eLayout1
) && (rAny2
>>= eLayout2
)) ? (eLayout1
== eLayout2
) : sal_False
;
72 sal_Bool
XMLPMPropHdl_PageStyleLayout::importXML(
73 const OUString
& rStrImpValue
,
75 const SvXMLUnitConverter
& ) const
77 sal_Bool bRet
= sal_True
;
79 if( IsXMLToken( rStrImpValue
, XML_ALL
) )
80 rValue
<<= PageStyleLayout_ALL
;
81 else if( IsXMLToken( rStrImpValue
, XML_LEFT
) )
82 rValue
<<= PageStyleLayout_LEFT
;
83 else if( IsXMLToken( rStrImpValue
, XML_RIGHT
) )
84 rValue
<<= PageStyleLayout_RIGHT
;
85 else if( IsXMLToken( rStrImpValue
, XML_MIRRORED
) )
86 rValue
<<= PageStyleLayout_MIRRORED
;
93 sal_Bool
XMLPMPropHdl_PageStyleLayout::exportXML(
94 OUString
& rStrExpValue
,
96 const SvXMLUnitConverter
& ) const
98 sal_Bool bRet
= sal_False
;
99 PageStyleLayout eLayout
;
101 if( rValue
>>= eLayout
)
106 case PageStyleLayout_ALL
:
107 rStrExpValue
= GetXMLToken( XML_ALL
);
109 case PageStyleLayout_LEFT
:
110 rStrExpValue
= GetXMLToken( XML_LEFT
);
112 case PageStyleLayout_RIGHT
:
113 rStrExpValue
= GetXMLToken( XML_RIGHT
);
115 case PageStyleLayout_MIRRORED
:
116 rStrExpValue
= GetXMLToken( XML_MIRRORED
);
127 //______________________________________________________________________________
128 // property handler for style:num-format (style::NumberingType)
130 XMLPMPropHdl_NumFormat::~XMLPMPropHdl_NumFormat()
134 sal_Bool
XMLPMPropHdl_NumFormat::importXML(
135 const OUString
& rStrImpValue
,
137 const SvXMLUnitConverter
& rUnitConverter
) const
139 sal_Int16 nSync
= sal_Int16();
140 sal_Int16 nNumType
= NumberingType::NUMBER_NONE
;
141 rUnitConverter
.convertNumFormat( nNumType
, rStrImpValue
, OUString(),
144 if( !(rValue
>>= nSync
) )
145 nSync
= NumberingType::NUMBER_NONE
;
147 // if num-letter-sync appears before num-format, the function
148 // XMLPMPropHdl_NumLetterSync::importXML() sets the value
149 // NumberingType::CHARS_LOWER_LETTER_N
150 if( nSync
== NumberingType::CHARS_LOWER_LETTER_N
)
154 case NumberingType::CHARS_LOWER_LETTER
:
155 nNumType
= NumberingType::CHARS_LOWER_LETTER_N
;
157 case NumberingType::CHARS_UPPER_LETTER
:
158 nNumType
= NumberingType::CHARS_UPPER_LETTER_N
;
167 sal_Bool
XMLPMPropHdl_NumFormat::exportXML(
168 OUString
& rStrExpValue
,
170 const SvXMLUnitConverter
& rUnitConverter
) const
172 sal_Bool bRet
= sal_False
;
173 sal_Int16 nNumType
= sal_Int16();
175 if( rValue
>>= nNumType
)
177 OUStringBuffer
aBuffer( 10 );
178 rUnitConverter
.convertNumFormat( aBuffer
, nNumType
);
179 rStrExpValue
= aBuffer
.makeStringAndClear();
186 //______________________________________________________________________________
187 // property handler for style:num-letter-sync (style::NumberingType)
189 XMLPMPropHdl_NumLetterSync::~XMLPMPropHdl_NumLetterSync()
193 sal_Bool
XMLPMPropHdl_NumLetterSync::importXML(
194 const OUString
& rStrImpValue
,
196 const SvXMLUnitConverter
& rUnitConverter
) const
199 sal_Int16 nSync
= NumberingType::NUMBER_NONE
;
200 rUnitConverter
.convertNumFormat( nSync
, rStrImpValue
,
201 GetXMLToken( XML_A
), sal_True
);
203 if( !(rValue
>>= nNumType
) )
204 nNumType
= NumberingType::NUMBER_NONE
;
206 if( nSync
== NumberingType::CHARS_LOWER_LETTER_N
)
210 case NumberingType::CHARS_LOWER_LETTER
:
211 nNumType
= NumberingType::CHARS_LOWER_LETTER_N
;
213 case NumberingType::CHARS_UPPER_LETTER
:
214 nNumType
= NumberingType::CHARS_UPPER_LETTER_N
;
223 sal_Bool
XMLPMPropHdl_NumLetterSync::exportXML(
224 OUString
& rStrExpValue
,
226 const SvXMLUnitConverter
& rUnitConverter
) const
228 sal_Bool bRet
= sal_False
;
229 sal_Int16 nNumType
= sal_Int16();
231 if( rValue
>>= nNumType
)
233 OUStringBuffer
aBuffer( 5 );
234 rUnitConverter
.convertNumLetterSync( aBuffer
, nNumType
);
235 rStrExpValue
= aBuffer
.makeStringAndClear();
236 bRet
= rStrExpValue
.getLength() > 0;
242 //______________________________________________________________________________
243 // property handler for style:paper-tray-number
245 XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber()
249 sal_Bool
XMLPMPropHdl_PaperTrayNumber::importXML(
250 const OUString
& rStrImpValue
,
252 const SvXMLUnitConverter
& ) const
254 sal_Bool bRet
= sal_False
;
256 if( IsXMLToken( rStrImpValue
, XML_DEFAULT
) )
258 rValue
<<= DEFAULT_PAPERTRAY
;
263 sal_Int32 nPaperTray
;
264 if( SvXMLUnitConverter::convertNumber( nPaperTray
, rStrImpValue
, 0 ) )
266 rValue
<<= nPaperTray
;
274 sal_Bool
XMLPMPropHdl_PaperTrayNumber::exportXML(
275 OUString
& rStrExpValue
,
277 const SvXMLUnitConverter
& ) const
279 sal_Bool bRet
= sal_False
;
280 sal_Int32 nPaperTray
= 0;
282 if( rValue
>>= nPaperTray
)
284 if( nPaperTray
== DEFAULT_PAPERTRAY
)
285 rStrExpValue
= GetXMLToken( XML_DEFAULT
);
288 OUStringBuffer aBuffer
;
289 SvXMLUnitConverter::convertNumber( aBuffer
, nPaperTray
);
290 rStrExpValue
= aBuffer
.makeStringAndClear();
298 //______________________________________________________________________________
299 // property handler for style:print
301 XMLPMPropHdl_Print::XMLPMPropHdl_Print( enum XMLTokenEnum eValue
) :
302 sAttrValue( GetXMLToken( eValue
) )
306 XMLPMPropHdl_Print::~XMLPMPropHdl_Print()
310 sal_Bool
XMLPMPropHdl_Print::importXML(
311 const OUString
& rStrImpValue
,
313 const SvXMLUnitConverter
& ) const
315 sal_Unicode cToken
= ' ';
316 sal_Int32 nTokenIndex
= 0;
317 sal_Bool bFound
= sal_False
;
321 bFound
= (sAttrValue
== rStrImpValue
.getToken( 0, cToken
, nTokenIndex
));
323 while ( (nTokenIndex
>= 0) && !bFound
);
325 setBOOL( rValue
, bFound
);
329 sal_Bool
XMLPMPropHdl_Print::exportXML(
330 OUString
& rStrExpValue
,
332 const SvXMLUnitConverter
& ) const
334 if( getBOOL( rValue
) )
336 if( rStrExpValue
.getLength() )
337 rStrExpValue
+= OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) );
338 rStrExpValue
+= sAttrValue
;
344 //______________________________________________________________________________
345 // property handler for style:table-centering
347 XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal()
351 sal_Bool
XMLPMPropHdl_CenterHorizontal::importXML(
352 const OUString
& rStrImpValue
,
354 const SvXMLUnitConverter
& ) const
356 sal_Bool bRet
= sal_False
;
358 if (rStrImpValue
.getLength())
359 if (IsXMLToken( rStrImpValue
, XML_BOTH
) ||
360 IsXMLToken( rStrImpValue
, XML_HORIZONTAL
))
362 rValue
= ::cppu::bool2any(sal_True
);
370 sal_Bool
XMLPMPropHdl_CenterHorizontal::exportXML(
371 OUString
& rStrExpValue
,
373 const SvXMLUnitConverter
& ) const
375 sal_Bool bRet
= sal_False
;
377 if ( ::cppu::any2bool( rValue
) )
380 if (rStrExpValue
.getLength())
381 rStrExpValue
= GetXMLToken(XML_BOTH
);
383 rStrExpValue
= GetXMLToken(XML_HORIZONTAL
);
389 XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical()
393 sal_Bool
XMLPMPropHdl_CenterVertical::importXML(
394 const OUString
& rStrImpValue
,
396 const SvXMLUnitConverter
& ) const
398 sal_Bool bRet
= sal_False
;
400 if (rStrImpValue
.getLength())
401 if (IsXMLToken(rStrImpValue
, XML_BOTH
) ||
402 IsXMLToken(rStrImpValue
, XML_VERTICAL
) )
404 rValue
= ::cppu::bool2any(sal_True
);
411 sal_Bool
XMLPMPropHdl_CenterVertical::exportXML(
412 OUString
& rStrExpValue
,
414 const SvXMLUnitConverter
& ) const
416 sal_Bool bRet
= sal_False
;
418 if ( ::cppu::any2bool( rValue
) )
421 if (rStrExpValue
.getLength())
422 rStrExpValue
= GetXMLToken(XML_BOTH
);
424 rStrExpValue
= GetXMLToken(XML_VERTICAL
);