Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "PageMasterPropHdl.hxx"
31 : :
32 : : #include <sax/tools/converter.hxx>
33 : :
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>
43 : :
44 : : using ::rtl::OUString;
45 : : using ::rtl::OUStringBuffer;
46 : :
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;
52 : :
53 : :
54 : : //______________________________________________________________________________
55 : :
56 : : #define DEFAULT_PAPERTRAY (sal_Int32(-1))
57 : :
58 : :
59 : : //______________________________________________________________________________
60 : : // property handler for style:page-usage (style::PageStyleLayout)
61 : :
62 : 254 : XMLPMPropHdl_PageStyleLayout::~XMLPMPropHdl_PageStyleLayout()
63 : : {
64 [ - + ]: 441 : }
65 : :
66 : 6 : bool XMLPMPropHdl_PageStyleLayout::equals( const Any& rAny1, const Any& rAny2 ) const
67 : : {
68 : : style::PageStyleLayout eLayout1, eLayout2;
69 [ + - ][ + - ]: 6 : return ((rAny1 >>= eLayout1) && (rAny2 >>= eLayout2)) ? (eLayout1 == eLayout2) : sal_False;
[ + - ][ + - ]
[ + - ]
70 : : }
71 : :
72 : 67 : sal_Bool XMLPMPropHdl_PageStyleLayout::importXML(
73 : : const OUString& rStrImpValue,
74 : : Any& rValue,
75 : : const SvXMLUnitConverter& ) const
76 : : {
77 : 67 : sal_Bool bRet = sal_True;
78 : :
79 [ - + ]: 67 : if( IsXMLToken( rStrImpValue, XML_ALL ) )
80 [ # # ]: 0 : rValue <<= PageStyleLayout_ALL;
81 [ + + ]: 67 : else if( IsXMLToken( rStrImpValue, XML_LEFT ) )
82 [ + - ]: 3 : rValue <<= PageStyleLayout_LEFT;
83 [ + + ]: 64 : else if( IsXMLToken( rStrImpValue, XML_RIGHT ) )
84 [ + - ]: 3 : rValue <<= PageStyleLayout_RIGHT;
85 [ + - ]: 61 : else if( IsXMLToken( rStrImpValue, XML_MIRRORED ) )
86 [ + - ]: 61 : rValue <<= PageStyleLayout_MIRRORED;
87 : : else
88 : 0 : bRet = sal_False;
89 : :
90 : 67 : return bRet;
91 : : }
92 : :
93 : 24 : sal_Bool XMLPMPropHdl_PageStyleLayout::exportXML(
94 : : OUString& rStrExpValue,
95 : : const Any& rValue,
96 : : const SvXMLUnitConverter& ) const
97 : : {
98 : 24 : sal_Bool bRet = sal_False;
99 : : PageStyleLayout eLayout;
100 : :
101 [ + - ][ + - ]: 24 : if( rValue >>= eLayout )
102 : : {
103 : 24 : bRet = sal_True;
104 [ - - - + : 24 : switch( eLayout )
- ]
105 : : {
106 : : case PageStyleLayout_ALL:
107 [ # # ]: 0 : rStrExpValue = GetXMLToken( XML_ALL );
108 : 0 : break;
109 : : case PageStyleLayout_LEFT:
110 [ # # ]: 0 : rStrExpValue = GetXMLToken( XML_LEFT );
111 : 0 : break;
112 : : case PageStyleLayout_RIGHT:
113 [ # # ]: 0 : rStrExpValue = GetXMLToken( XML_RIGHT );
114 : 0 : break;
115 : : case PageStyleLayout_MIRRORED:
116 [ + - ]: 24 : rStrExpValue = GetXMLToken( XML_MIRRORED );
117 : 24 : break;
118 : : default:
119 : 24 : bRet = sal_False;
120 : : }
121 : : }
122 : :
123 : 24 : return bRet;
124 : : }
125 : :
126 : :
127 : : //______________________________________________________________________________
128 : : // property handler for style:num-format (style::NumberingType)
129 : :
130 : 187 : XMLPMPropHdl_NumFormat::~XMLPMPropHdl_NumFormat()
131 : : {
132 [ - + ]: 374 : }
133 : :
134 : 105 : sal_Bool XMLPMPropHdl_NumFormat::importXML(
135 : : const OUString& rStrImpValue,
136 : : Any& rValue,
137 : : const SvXMLUnitConverter& rUnitConverter ) const
138 : : {
139 : 105 : sal_Int16 nSync = sal_Int16();
140 : 105 : sal_Int16 nNumType = NumberingType::NUMBER_NONE;
141 : : rUnitConverter.convertNumFormat( nNumType, rStrImpValue, OUString(),
142 [ + - ]: 105 : sal_True );
143 : :
144 [ + - ]: 105 : if( !(rValue >>= nSync) )
145 : 105 : nSync = NumberingType::NUMBER_NONE;
146 : :
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 [ - + ]: 105 : if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
151 : : {
152 [ # # # ]: 0 : switch( nNumType )
153 : : {
154 : : case NumberingType::CHARS_LOWER_LETTER:
155 : 0 : nNumType = NumberingType::CHARS_LOWER_LETTER_N;
156 : 0 : break;
157 : : case NumberingType::CHARS_UPPER_LETTER:
158 : 0 : nNumType = NumberingType::CHARS_UPPER_LETTER_N;
159 : 0 : break;
160 : : }
161 : : }
162 [ + - ]: 105 : rValue <<= nNumType;
163 : :
164 : 105 : return sal_True;
165 : : }
166 : :
167 : 24 : sal_Bool XMLPMPropHdl_NumFormat::exportXML(
168 : : OUString& rStrExpValue,
169 : : const Any& rValue,
170 : : const SvXMLUnitConverter& rUnitConverter ) const
171 : : {
172 : 24 : sal_Bool bRet = sal_False;
173 : 24 : sal_Int16 nNumType = sal_Int16();
174 : :
175 [ + - ]: 24 : if( rValue >>= nNumType )
176 : : {
177 : 24 : OUStringBuffer aBuffer( 10 );
178 [ + - ]: 24 : rUnitConverter.convertNumFormat( aBuffer, nNumType );
179 [ + - ]: 24 : rStrExpValue = aBuffer.makeStringAndClear();
180 : 24 : bRet = sal_True;
181 : : }
182 : 24 : return bRet;
183 : : }
184 : :
185 : :
186 : : //______________________________________________________________________________
187 : : // property handler for style:num-letter-sync (style::NumberingType)
188 : :
189 : 187 : XMLPMPropHdl_NumLetterSync::~XMLPMPropHdl_NumLetterSync()
190 : : {
191 [ - + ]: 374 : }
192 : :
193 : 0 : sal_Bool XMLPMPropHdl_NumLetterSync::importXML(
194 : : const OUString& rStrImpValue,
195 : : Any& rValue,
196 : : const SvXMLUnitConverter& rUnitConverter ) const
197 : : {
198 : : sal_Int16 nNumType;
199 : 0 : sal_Int16 nSync = NumberingType::NUMBER_NONE;
200 : : rUnitConverter.convertNumFormat( nSync, rStrImpValue,
201 [ # # ][ # # ]: 0 : GetXMLToken( XML_A ), sal_True );
202 : :
203 [ # # ]: 0 : if( !(rValue >>= nNumType) )
204 : 0 : nNumType = NumberingType::NUMBER_NONE;
205 : :
206 [ # # ]: 0 : if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
207 : : {
208 [ # # # ]: 0 : switch( nNumType )
209 : : {
210 : : case NumberingType::CHARS_LOWER_LETTER:
211 : 0 : nNumType = NumberingType::CHARS_LOWER_LETTER_N;
212 : 0 : break;
213 : : case NumberingType::CHARS_UPPER_LETTER:
214 : 0 : nNumType = NumberingType::CHARS_UPPER_LETTER_N;
215 : 0 : break;
216 : : }
217 : : }
218 [ # # ]: 0 : rValue <<= nNumType;
219 : :
220 : 0 : return sal_True;
221 : : }
222 : :
223 : 24 : sal_Bool XMLPMPropHdl_NumLetterSync::exportXML(
224 : : OUString& rStrExpValue,
225 : : const Any& rValue,
226 : : const SvXMLUnitConverter& rUnitConverter ) const
227 : : {
228 : 24 : sal_Bool bRet = sal_False;
229 : 24 : sal_Int16 nNumType = sal_Int16();
230 : :
231 [ + - ]: 24 : if( rValue >>= nNumType )
232 : : {
233 : 24 : OUStringBuffer aBuffer( 5 );
234 [ + - ]: 24 : rUnitConverter.convertNumLetterSync( aBuffer, nNumType );
235 [ + - ]: 24 : rStrExpValue = aBuffer.makeStringAndClear();
236 : 24 : bRet = !rStrExpValue.isEmpty();
237 : : }
238 : 24 : return bRet;
239 : : }
240 : :
241 : :
242 : : //______________________________________________________________________________
243 : : // property handler for style:paper-tray-number
244 : :
245 : 0 : XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber()
246 : : {
247 [ # # ]: 0 : }
248 : :
249 : 0 : sal_Bool XMLPMPropHdl_PaperTrayNumber::importXML(
250 : : const OUString& rStrImpValue,
251 : : Any& rValue,
252 : : const SvXMLUnitConverter& ) const
253 : : {
254 : 0 : sal_Bool bRet = sal_False;
255 : :
256 [ # # ]: 0 : if( IsXMLToken( rStrImpValue, XML_DEFAULT ) )
257 : : {
258 [ # # ]: 0 : rValue <<= DEFAULT_PAPERTRAY;
259 : 0 : bRet = sal_True;
260 : : }
261 : : else
262 : : {
263 : : sal_Int32 nPaperTray;
264 [ # # ][ # # ]: 0 : if (::sax::Converter::convertNumber( nPaperTray, rStrImpValue, 0 ))
265 : : {
266 [ # # ]: 0 : rValue <<= nPaperTray;
267 : 0 : bRet = sal_True;
268 : : }
269 : : }
270 : :
271 : 0 : return bRet;
272 : : }
273 : :
274 : 0 : sal_Bool XMLPMPropHdl_PaperTrayNumber::exportXML(
275 : : OUString& rStrExpValue,
276 : : const Any& rValue,
277 : : const SvXMLUnitConverter& ) const
278 : : {
279 : 0 : sal_Bool bRet = sal_False;
280 : 0 : sal_Int32 nPaperTray = 0;
281 : :
282 [ # # ]: 0 : if( rValue >>= nPaperTray )
283 : : {
284 [ # # ]: 0 : if( nPaperTray == DEFAULT_PAPERTRAY )
285 [ # # ]: 0 : rStrExpValue = GetXMLToken( XML_DEFAULT );
286 : : else
287 : : {
288 : 0 : OUStringBuffer aBuffer;
289 [ # # ]: 0 : ::sax::Converter::convertNumber( aBuffer, nPaperTray );
290 [ # # ]: 0 : rStrExpValue = aBuffer.makeStringAndClear();
291 : : }
292 : 0 : bRet = sal_True;
293 : : }
294 : 0 : return bRet;
295 : : }
296 : :
297 : :
298 : : //______________________________________________________________________________
299 : : // property handler for style:print
300 : :
301 : 1496 : XMLPMPropHdl_Print::XMLPMPropHdl_Print( enum XMLTokenEnum eValue ) :
302 [ + - ]: 1496 : sAttrValue( GetXMLToken( eValue ) )
303 : : {
304 : 1496 : }
305 : :
306 : 1496 : XMLPMPropHdl_Print::~XMLPMPropHdl_Print()
307 : : {
308 [ - + ]: 2992 : }
309 : :
310 : 40 : sal_Bool XMLPMPropHdl_Print::importXML(
311 : : const OUString& rStrImpValue,
312 : : Any& rValue,
313 : : const SvXMLUnitConverter& ) const
314 : : {
315 : 40 : sal_Unicode cToken = ' ';
316 : 40 : sal_Int32 nTokenIndex = 0;
317 : 40 : sal_Bool bFound = sal_False;
318 : :
319 [ + + ][ + + ]: 150 : do
[ + + ]
320 : : {
321 : 150 : bFound = (sAttrValue == rStrImpValue.getToken( 0, cToken, nTokenIndex ));
322 : : }
323 : : while ( (nTokenIndex >= 0) && !bFound );
324 : :
325 [ + - ]: 40 : setBOOL( rValue, bFound );
326 : 40 : return sal_True;
327 : : }
328 : :
329 : 0 : sal_Bool XMLPMPropHdl_Print::exportXML(
330 : : OUString& rStrExpValue,
331 : : const Any& rValue,
332 : : const SvXMLUnitConverter& ) const
333 : : {
334 [ # # ]: 0 : if( getBOOL( rValue ) )
335 : : {
336 [ # # ]: 0 : if( !rStrExpValue.isEmpty() )
337 : 0 : rStrExpValue += OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) );
338 : 0 : rStrExpValue += sAttrValue;
339 : : }
340 : :
341 : 0 : return sal_True;
342 : : }
343 : :
344 : : //______________________________________________________________________________
345 : : // property handler for style:table-centering
346 : :
347 : 187 : XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal()
348 : : {
349 [ - + ]: 374 : }
350 : :
351 : 0 : sal_Bool XMLPMPropHdl_CenterHorizontal::importXML(
352 : : const OUString& rStrImpValue,
353 : : Any& rValue,
354 : : const SvXMLUnitConverter& ) const
355 : : {
356 : 0 : sal_Bool bRet = sal_False;
357 : :
358 [ # # ]: 0 : if (!rStrImpValue.isEmpty())
359 [ # # # # ]: 0 : if (IsXMLToken( rStrImpValue, XML_BOTH) ||
[ # # ]
360 : 0 : IsXMLToken( rStrImpValue, XML_HORIZONTAL))
361 : : {
362 : 0 : rValue = ::cppu::bool2any(sal_True);
363 : 0 : bRet = sal_True;
364 : : }
365 : :
366 : :
367 : 0 : return bRet;
368 : : }
369 : :
370 : 0 : sal_Bool XMLPMPropHdl_CenterHorizontal::exportXML(
371 : : OUString& rStrExpValue,
372 : : const Any& rValue,
373 : : const SvXMLUnitConverter& ) const
374 : : {
375 : 0 : sal_Bool bRet = sal_False;
376 : :
377 [ # # ]: 0 : if ( ::cppu::any2bool( rValue ) )
378 : : {
379 : 0 : bRet = sal_True;
380 [ # # ]: 0 : if (!rStrExpValue.isEmpty())
381 : 0 : rStrExpValue = GetXMLToken(XML_BOTH);
382 : : else
383 : 0 : rStrExpValue = GetXMLToken(XML_HORIZONTAL);
384 : : }
385 : :
386 : 0 : return bRet;
387 : : }
388 : :
389 : 187 : XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical()
390 : : {
391 [ - + ]: 374 : }
392 : :
393 : 0 : sal_Bool XMLPMPropHdl_CenterVertical::importXML(
394 : : const OUString& rStrImpValue,
395 : : Any& rValue,
396 : : const SvXMLUnitConverter& ) const
397 : : {
398 : 0 : sal_Bool bRet = sal_False;
399 : :
400 [ # # ]: 0 : if (!rStrImpValue.isEmpty())
401 [ # # # # ]: 0 : if (IsXMLToken(rStrImpValue, XML_BOTH) ||
[ # # ]
402 : 0 : IsXMLToken(rStrImpValue, XML_VERTICAL) )
403 : : {
404 : 0 : rValue = ::cppu::bool2any(sal_True);
405 : 0 : bRet = sal_True;
406 : : }
407 : :
408 : 0 : return bRet;
409 : : }
410 : :
411 : 0 : sal_Bool XMLPMPropHdl_CenterVertical::exportXML(
412 : : OUString& rStrExpValue,
413 : : const Any& rValue,
414 : : const SvXMLUnitConverter& ) const
415 : : {
416 : 0 : sal_Bool bRet = sal_False;
417 : :
418 [ # # ]: 0 : if ( ::cppu::any2bool( rValue ) )
419 : : {
420 : 0 : bRet = sal_True;
421 [ # # ]: 0 : if (!rStrExpValue.isEmpty())
422 : 0 : rStrExpValue = GetXMLToken(XML_BOTH);
423 : : else
424 : 0 : rStrExpValue = GetXMLToken(XML_VERTICAL);
425 : : }
426 : :
427 : 0 : return bRet;
428 : : }
429 : :
430 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|