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 #include <tools/debug.hxx>
27 #include <xmlbahdl.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <com/sun/star/uno/Any.hxx>
30 #include <xmloff/xmltoken.hxx>
31
32 using ::rtl::OUString;
33 using ::rtl::OUStringBuffer;
34
35 using namespace ::com::sun::star::uno;
36 using namespace ::xmloff::token;
37
lcl_xmloff_setAny(Any & rValue,sal_Int32 nValue,sal_Int8 nBytes)38 void lcl_xmloff_setAny( Any& rValue, sal_Int32 nValue, sal_Int8 nBytes )
39 {
40 switch( nBytes )
41 {
42 case 1:
43 if( nValue < SCHAR_MIN )
44 nValue = SCHAR_MIN;
45 else if( nValue > SCHAR_MAX )
46 nValue = SCHAR_MAX;
47 rValue <<= (sal_Int8)nValue;
48 break;
49 case 2:
50 if( nValue < SHRT_MIN )
51 nValue = SHRT_MIN;
52 else if( nValue > SHRT_MAX )
53 nValue = SHRT_MAX;
54 rValue <<= (sal_Int16)nValue;
55 break;
56 case 4:
57 rValue <<= nValue;
58 break;
59 }
60 }
61
lcl_xmloff_getAny(const Any & rValue,sal_Int32 & nValue,sal_Int8 nBytes)62 sal_Bool lcl_xmloff_getAny( const Any& rValue, sal_Int32& nValue,
63 sal_Int8 nBytes )
64 {
65 sal_Bool bRet = sal_False;
66
67 switch( nBytes )
68 {
69 case 1:
70 {
71 sal_Int8 nValue8 = 0;
72 bRet = rValue >>= nValue8;
73 nValue = nValue8;
74 }
75 break;
76 case 2:
77 {
78 sal_Int16 nValue16 = 0;
79 bRet = rValue >>= nValue16;
80 nValue = nValue16;
81 }
82 break;
83 case 4:
84 bRet = rValue >>= nValue;
85 break;
86 }
87
88 return bRet;
89 }
90
91 ///////////////////////////////////////////////////////////////////////////////
92 //
93 // class XMLNumberPropHdl
94 //
95
~XMLNumberPropHdl()96 XMLNumberPropHdl::~XMLNumberPropHdl()
97 {
98 // nothing to do
99 }
100
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const101 sal_Bool XMLNumberPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
102 {
103 sal_Bool bRet = sal_False;
104
105 sal_Int32 nValue = 0;
106 bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue );
107 lcl_xmloff_setAny( rValue, nValue, nBytes );
108
109 return bRet;
110 }
111
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const112 sal_Bool XMLNumberPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
113 {
114 sal_Bool bRet = sal_False;
115 sal_Int32 nValue;
116 OUStringBuffer aOut;
117
118 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
119 {
120 SvXMLUnitConverter::convertNumber( aOut, nValue );
121 rStrExpValue = aOut.makeStringAndClear();
122
123 bRet = sal_True;
124 }
125
126 return bRet;
127 }
128
129 ///////////////////////////////////////////////////////////////////////////////
130 // class XMLNumberNonePropHdl
131 //
132
XMLNumberNonePropHdl(sal_Int8 nB)133 XMLNumberNonePropHdl::XMLNumberNonePropHdl( sal_Int8 nB ) :
134 sZeroStr( GetXMLToken(XML_NO_LIMIT) ),
135 nBytes( nB )
136 {
137 }
138
XMLNumberNonePropHdl(enum XMLTokenEnum eZeroString,sal_Int8 nB)139 XMLNumberNonePropHdl::XMLNumberNonePropHdl( enum XMLTokenEnum eZeroString, sal_Int8 nB ) :
140 sZeroStr( GetXMLToken( eZeroString ) ),
141 nBytes( nB )
142 {
143 }
144
~XMLNumberNonePropHdl()145 XMLNumberNonePropHdl::~XMLNumberNonePropHdl()
146 {
147 // nothing to do
148 }
149
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const150 sal_Bool XMLNumberNonePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
151 {
152 sal_Bool bRet = sal_False;
153
154 sal_Int32 nValue = 0;
155 if( rStrImpValue == sZeroStr )
156 {
157 bRet = sal_True;
158 }
159 else
160 {
161 bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue );
162 }
163 lcl_xmloff_setAny( rValue, nValue, nBytes );
164
165 return bRet;
166 }
167
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const168 sal_Bool XMLNumberNonePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
169 {
170 sal_Bool bRet = sal_False;
171 sal_Int32 nValue;
172
173 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
174 {
175 OUStringBuffer aOut;
176
177 if( nValue == 0 )
178 {
179 aOut.append( sZeroStr );
180 }
181 else
182 {
183 SvXMLUnitConverter::convertNumber( aOut, nValue );
184 }
185
186 rStrExpValue = aOut.makeStringAndClear();
187
188 bRet = sal_True;
189 }
190
191 return bRet;
192 }
193
194 ///////////////////////////////////////////////////////////////////////////////
195 //
196 // class XMLMeasurePropHdl
197 //
198
~XMLMeasurePropHdl()199 XMLMeasurePropHdl::~XMLMeasurePropHdl()
200 {
201 // nothing to do
202 }
203
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter & rUnitConverter) const204 sal_Bool XMLMeasurePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
205 {
206 sal_Bool bRet = sal_False;
207
208 sal_Int32 nValue = 0;
209 bRet = rUnitConverter.convertMeasure( nValue, rStrImpValue );
210 lcl_xmloff_setAny( rValue, nValue, nBytes );
211
212 return bRet;
213 }
214
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter & rUnitConverter) const215 sal_Bool XMLMeasurePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
216 {
217 sal_Bool bRet = sal_False;
218 sal_Int32 nValue;
219 OUStringBuffer aOut;
220
221 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
222 {
223 rUnitConverter.convertMeasure( aOut, nValue );
224 rStrExpValue = aOut.makeStringAndClear();
225
226 bRet = sal_True;
227 }
228
229 return bRet;
230 }
231
232 ///////////////////////////////////////////////////////////////////////////////
233 //
234 // class XMLBoolPropHdl
235 //
236
~XMLBoolPropHdl()237 XMLBoolPropHdl::~XMLBoolPropHdl()
238 {
239 // nothing to do
240 }
241
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const242 sal_Bool XMLBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
243 {
244 sal_Bool bRet = sal_False;
245
246 sal_Bool bValue;
247 bRet = SvXMLUnitConverter::convertBool( bValue, rStrImpValue );
248 rValue <<= sal_Bool(bValue);
249
250 return bRet;
251 }
252
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const253 sal_Bool XMLBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
254 {
255 sal_Bool bRet = sal_False;
256 OUStringBuffer aOut;
257 sal_Bool bValue = sal_Bool();
258
259 if (rValue >>= bValue)
260 {
261 SvXMLUnitConverter::convertBool( aOut, bValue );
262 rStrExpValue = aOut.makeStringAndClear();
263
264 bRet = sal_True;
265 }
266
267 return bRet;
268 }
269
270 ///////////////////////////////////////////////////////////////////////////////
271 //
272 // class XMLNBoolPropHdl
273 //
274
~XMLNBoolPropHdl()275 XMLNBoolPropHdl::~XMLNBoolPropHdl()
276 {
277 // nothing to do
278 }
279
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const280 sal_Bool XMLNBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
281 {
282 sal_Bool bRet = sal_False;
283
284 sal_Bool bValue;
285 bRet = SvXMLUnitConverter::convertBool( bValue, rStrImpValue );
286 rValue <<= sal_Bool(!bValue);
287
288 return bRet;
289 }
290
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const291 sal_Bool XMLNBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
292 {
293 sal_Bool bRet = sal_False;
294 OUStringBuffer aOut;
295 sal_Bool bValue = sal_Bool();
296
297 if (rValue >>= bValue)
298 {
299 SvXMLUnitConverter::convertBool( aOut, !bValue );
300 rStrExpValue = aOut.makeStringAndClear();
301
302 bRet = sal_True;
303 }
304
305 return bRet;
306 }
307
308 ///////////////////////////////////////////////////////////////////////////////
309 //
310 // class XMLPercentPropHdl
311 //
312
~XMLPercentPropHdl()313 XMLPercentPropHdl::~XMLPercentPropHdl()
314 {
315 // nothing to do
316 }
317
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const318 sal_Bool XMLPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
319 {
320 sal_Bool bRet = sal_False;
321
322 sal_Int32 nValue = 0;
323 bRet = SvXMLUnitConverter::convertPercent( nValue, rStrImpValue );
324 lcl_xmloff_setAny( rValue, nValue, nBytes );
325
326 return bRet;
327 }
328
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const329 sal_Bool XMLPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
330 {
331 sal_Bool bRet = sal_False;
332 sal_Int32 nValue;
333 OUStringBuffer aOut;
334
335 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
336 {
337 SvXMLUnitConverter::convertPercent( aOut, nValue );
338 rStrExpValue = aOut.makeStringAndClear();
339
340 bRet = sal_True;
341 }
342
343 return bRet;
344 }
345
346 ///////////////////////////////////////////////////////////////////////////////
347 //
348 // class XMLDoublePercentPropHdl
349 //
350
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const351 sal_Bool XMLDoublePercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
352 {
353 sal_Bool bRet = sal_False;
354
355 double fValue = 1.0;
356
357 if( rStrImpValue.indexOf( (sal_Unicode)'%' ) == -1 )
358 {
359 fValue = rStrImpValue.toDouble();
360 }
361 else
362 {
363 sal_Int32 nValue = 0;
364 bRet = SvXMLUnitConverter::convertPercent( nValue, rStrImpValue );
365 fValue = ((double)nValue) / 100.0;
366 }
367 rValue <<= fValue;
368
369 return bRet;
370 }
371
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const372 sal_Bool XMLDoublePercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
373 {
374 sal_Bool bRet = sal_False;
375 double fValue = 0;
376
377 if( rValue >>= fValue )
378 {
379 fValue *= 100.0;
380 if( fValue > 0 ) fValue += 0.5; else fValue -= 0.5;
381
382 sal_Int32 nValue = (sal_Int32)fValue;
383
384 OUStringBuffer aOut;
385 SvXMLUnitConverter::convertPercent( aOut, nValue );
386 rStrExpValue = aOut.makeStringAndClear();
387
388 bRet = sal_True;
389 }
390
391 return bRet;
392 }
393
394
395 ///////////////////////////////////////////////////////////////////////////////
396 //
397 // class XMLNegPercentPropHdl
398 //
399
~XMLNegPercentPropHdl()400 XMLNegPercentPropHdl::~XMLNegPercentPropHdl()
401 {
402 // nothing to do
403 }
404
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const405 sal_Bool XMLNegPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
406 {
407 sal_Bool bRet = sal_False;
408
409 sal_Int32 nValue = 0;
410 bRet = SvXMLUnitConverter::convertPercent( nValue, rStrImpValue );
411 lcl_xmloff_setAny( rValue, 100-nValue, nBytes );
412
413 return bRet;
414 }
415
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const416 sal_Bool XMLNegPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
417 {
418 sal_Bool bRet = sal_False;
419 sal_Int32 nValue;
420 OUStringBuffer aOut;
421
422 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
423 {
424 if( nBytes == 2 )
425 {
426 if( nValue < 0 )
427 nValue = 0;
428 else if( nValue > 100 )
429 nValue = 100;
430 }
431 SvXMLUnitConverter::convertPercent( aOut, 100-nValue );
432 rStrExpValue = aOut.makeStringAndClear();
433
434 bRet = sal_True;
435 }
436
437 return bRet;
438 }
439
440
441 ///////////////////////////////////////////////////////////////////////////////
442 //
443 // class XMLMeasurePxPropHdl
444 //
445
~XMLMeasurePxPropHdl()446 XMLMeasurePxPropHdl::~XMLMeasurePxPropHdl()
447 {
448 // nothing to do
449 }
450
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const451 sal_Bool XMLMeasurePxPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
452 {
453 sal_Bool bRet = sal_False;
454
455 sal_Int32 nValue = 0;
456 bRet = SvXMLUnitConverter::convertMeasurePx( nValue, rStrImpValue );
457 lcl_xmloff_setAny( rValue, nValue, nBytes );
458
459 return bRet;
460 }
461
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const462 sal_Bool XMLMeasurePxPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
463 {
464 sal_Bool bRet = sal_False;
465 sal_Int32 nValue;
466 OUStringBuffer aOut;
467
468 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
469 {
470 SvXMLUnitConverter::convertMeasurePx( aOut, nValue );
471 rStrExpValue = aOut.makeStringAndClear();
472
473 bRet = sal_True;
474 }
475
476 return bRet;
477 }
478
479 ///////////////////////////////////////////////////////////////////////////////
480 //
481 // class XMLColorPropHdl
482 //
483
~XMLColorPropHdl()484 XMLColorPropHdl::~XMLColorPropHdl()
485 {
486 // Nothing to do
487 }
488
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const489 sal_Bool XMLColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
490 {
491 sal_Bool bRet = sal_False;
492 Color aColor;
493
494 const OUString astrHSL( RTL_CONSTASCII_USTRINGPARAM( "hsl" ) );
495 if( rStrImpValue.matchIgnoreAsciiCase( astrHSL ) )
496 {
497 sal_Int32 nOpen = rStrImpValue.indexOf( '(' );
498 sal_Int32 nClose = rStrImpValue.lastIndexOf( ')' );
499
500 if( (nOpen != -1) && (nClose > nOpen) )
501 {
502 const OUString aTmp( rStrImpValue.copy( nOpen+1, nClose - nOpen-1) );
503
504 sal_Int32 nIndex = 0;
505
506 Sequence< double > aHSL(3);
507 aHSL[0] = aTmp.getToken( 0, ',', nIndex ).toDouble();
508 aHSL[1] = aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0;
509 aHSL[2] = aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0;
510 rValue <<= aHSL;
511 bRet = true;
512 }
513 }
514 else
515 {
516 bRet = SvXMLUnitConverter::convertColor( aColor, rStrImpValue );
517 rValue <<= (sal_Int32)( aColor.GetColor() );
518 }
519
520 return bRet;
521 }
522
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const523 sal_Bool XMLColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
524 {
525 sal_Bool bRet = sal_False;
526 Color aColor;
527 sal_Int32 nColor = 0;
528
529 OUStringBuffer aOut;
530 if( rValue >>= nColor )
531 {
532 aColor.SetColor( nColor );
533
534 SvXMLUnitConverter::convertColor( aOut, aColor );
535 rStrExpValue = aOut.makeStringAndClear();
536
537 bRet = sal_True;
538 }
539 else
540 {
541 Sequence< double > aHSL;
542 if( (rValue >>= aHSL) && (aHSL.getLength() == 3) )
543 {
544 aOut.append( OUString::createFromAscii("hsl(") );
545 aOut.append( aHSL[0] );
546 aOut.append( OUString::createFromAscii(",") );
547 aOut.append( aHSL[1] * 100.0 );
548 aOut.append( OUString::createFromAscii("%,") );
549 aOut.append( aHSL[2] * 100.0 );
550 aOut.append( OUString::createFromAscii("%)") );
551 rStrExpValue = aOut.makeStringAndClear();
552
553 bRet = sal_True;
554 }
555 }
556
557 return bRet;
558 }
559
560 ///////////////////////////////////////////////////////////////////////////////
561 //
562 // class XMLStringPropHdl
563 //
564
~XMLStringPropHdl()565 XMLStringPropHdl::~XMLStringPropHdl()
566 {
567 // Nothing to do
568 }
569
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const570 sal_Bool XMLStringPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
571 {
572 sal_Bool bRet = sal_False;
573
574 rValue <<= rStrImpValue;
575 bRet = sal_True;
576
577 return bRet;
578 }
579
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const580 sal_Bool XMLStringPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
581 {
582 sal_Bool bRet = sal_False;
583
584 if( rValue >>= rStrExpValue )
585 bRet = sal_True;
586
587 return bRet;
588 }
589
590 ///////////////////////////////////////////////////////////////////////////////
591 //
592 // class XMLStyleNamePropHdl
593 //
594
~XMLStyleNamePropHdl()595 XMLStyleNamePropHdl::~XMLStyleNamePropHdl()
596 {
597 // Nothing to do
598 }
599
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter & rUnitConverter) const600 sal_Bool XMLStyleNamePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
601 {
602 sal_Bool bRet = sal_False;
603
604 if( rValue >>= rStrExpValue )
605 {
606 rStrExpValue = rUnitConverter.encodeStyleName( rStrExpValue );
607 bRet = sal_True;
608 }
609
610 return bRet;
611 }
612
613
614 ///////////////////////////////////////////////////////////////////////////////
615 //
616 // class XMLDoublePropHdl
617 //
618
~XMLDoublePropHdl()619 XMLDoublePropHdl::~XMLDoublePropHdl()
620 {
621 // Nothing to do
622 }
623
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const624 sal_Bool XMLDoublePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
625 {
626 double fDblValue;
627 sal_Bool bRet = SvXMLUnitConverter::convertDouble( fDblValue, rStrImpValue );
628 rValue <<= fDblValue;
629 return bRet;
630 }
631
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const632 sal_Bool XMLDoublePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
633 {
634 sal_Bool bRet = sal_False;
635
636 double fValue = 0;
637
638 if( rValue >>= fValue )
639 {
640 OUStringBuffer aOut;
641 SvXMLUnitConverter::convertDouble( aOut, fValue );
642 rStrExpValue = aOut.makeStringAndClear();
643 bRet = sal_True;
644 }
645
646 return bRet;
647 }
648
649 ///////////////////////////////////////////////////////////////////////////////
650 //
651 // class XMLColorTransparentPropHdl
652 //
653
XMLColorTransparentPropHdl(enum XMLTokenEnum eTransparent)654 XMLColorTransparentPropHdl::XMLColorTransparentPropHdl(
655 enum XMLTokenEnum eTransparent ) :
656 sTransparent( GetXMLToken(
657 eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) )
658 {
659 // Nothing to do
660 }
661
~XMLColorTransparentPropHdl()662 XMLColorTransparentPropHdl::~XMLColorTransparentPropHdl()
663 {
664 // Nothing to do
665 }
666
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const667 sal_Bool XMLColorTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
668 {
669 sal_Bool bRet = sal_False;
670
671 if( rStrImpValue != sTransparent )
672 {
673 Color aColor;
674 bRet = SvXMLUnitConverter::convertColor( aColor, rStrImpValue );
675 rValue <<= (sal_Int32)( aColor.GetColor() );
676 }
677
678 return bRet;
679 }
680
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const681 sal_Bool XMLColorTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
682 {
683 sal_Bool bRet = sal_False;
684 sal_Int32 nColor = 0;
685
686 if( rStrExpValue == sTransparent )
687 bRet = sal_False;
688 else if( rValue >>= nColor )
689 {
690 Color aColor( nColor );
691 OUStringBuffer aOut;
692 SvXMLUnitConverter::convertColor( aOut, aColor );
693 rStrExpValue = aOut.makeStringAndClear();
694
695 bRet = sal_True;
696 }
697
698 return bRet;
699 }
700
701
702 ///////////////////////////////////////////////////////////////////////////////
703 //
704 // class XMLIsTransparentPropHdl
705 //
706
XMLIsTransparentPropHdl(enum XMLTokenEnum eTransparent,sal_Bool bTransPropVal)707 XMLIsTransparentPropHdl::XMLIsTransparentPropHdl(
708 enum XMLTokenEnum eTransparent, sal_Bool bTransPropVal ) :
709 sTransparent( GetXMLToken(
710 eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) ),
711 bTransPropValue( bTransPropVal )
712 {
713 }
714
~XMLIsTransparentPropHdl()715 XMLIsTransparentPropHdl::~XMLIsTransparentPropHdl()
716 {
717 // Nothing to do
718 }
719
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const720 sal_Bool XMLIsTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
721 {
722 sal_Bool bValue = ( (rStrImpValue == sTransparent) == bTransPropValue);
723 rValue.setValue( &bValue, ::getBooleanCppuType() );
724
725 return sal_True;
726 }
727
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const728 sal_Bool XMLIsTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
729 {
730 sal_Bool bRet = sal_False;
731
732 // MIB: This looks a bit strange, because bTransPropValue == bValue should
733 // do the same, but this only applies if 'true' is represented by the same
734 // 8 bit value in bValue and bTransPropValue. Who will ensure this?
735 sal_Bool bValue = *(sal_Bool *)rValue.getValue();
736 sal_Bool bIsTrans = bTransPropValue ? bValue : !bValue;
737
738 if( bIsTrans )
739 {
740 rStrExpValue = sTransparent;
741 bRet = sal_True;
742 }
743
744 return bRet;
745 }
746
747 ///////////////////////////////////////////////////////////////////////////////
748 //
749 // class XMLColorAutoPropHdl
750 //
751
XMLColorAutoPropHdl()752 XMLColorAutoPropHdl::XMLColorAutoPropHdl()
753 {
754 // Nothing to do
755 }
756
~XMLColorAutoPropHdl()757 XMLColorAutoPropHdl::~XMLColorAutoPropHdl()
758 {
759 // Nothing to do
760 }
761
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const762 sal_Bool XMLColorAutoPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
763 {
764 sal_Bool bRet = sal_False;
765
766 // This is a multi property: the value might be set to AUTO_COLOR
767 // already by the XMLIsAutoColorPropHdl!
768 sal_Int32 nColor = 0;
769 if( !(rValue >>= nColor) || -1 != nColor )
770 {
771 Color aColor;
772 bRet = SvXMLUnitConverter::convertColor( aColor, rStrImpValue );
773 if( bRet )
774 rValue <<= (sal_Int32)( aColor.GetColor() );
775 }
776
777 return bRet;
778 }
779
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const780 sal_Bool XMLColorAutoPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
781 {
782 sal_Bool bRet = sal_False;
783
784 sal_Int32 nColor = 0;
785 if( (rValue >>= nColor) && -1 != nColor )
786 {
787 Color aColor( nColor );
788 OUStringBuffer aOut;
789 SvXMLUnitConverter::convertColor( aOut, aColor );
790 rStrExpValue = aOut.makeStringAndClear();
791
792 bRet = sal_True;
793 }
794
795 return bRet;
796 }
797
798 ///////////////////////////////////////////////////////////////////////////////
799 //
800 // class XMLIsAutoColorPropHdl
801 //
802
XMLIsAutoColorPropHdl()803 XMLIsAutoColorPropHdl::XMLIsAutoColorPropHdl()
804 {
805 }
806
~XMLIsAutoColorPropHdl()807 XMLIsAutoColorPropHdl::~XMLIsAutoColorPropHdl()
808 {
809 // Nothing to do
810 }
811
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const812 sal_Bool XMLIsAutoColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
813 {
814 sal_Bool bValue;
815
816 // An auto color overrides any other color set!
817 sal_Bool bRet = SvXMLUnitConverter::convertBool( bValue, rStrImpValue );
818 if( bRet && bValue )
819 rValue <<= (sal_Int32)-1;
820
821 return sal_True;
822 }
823
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const824 sal_Bool XMLIsAutoColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
825 {
826 sal_Bool bRet = sal_False;
827 sal_Int32 nColor = 0;
828
829 if( (rValue >>= nColor) && -1 == nColor )
830 {
831 OUStringBuffer aOut;
832 SvXMLUnitConverter::convertBool( aOut, sal_True );
833 rStrExpValue = aOut.makeStringAndClear();
834
835 bRet = sal_True;
836 }
837
838 return bRet;
839 }
840
841 ///////////////////////////////////////////////////////////////////////////////
842 //
843 // class XMLCompareOnlyPropHdl
844 //
845
~XMLCompareOnlyPropHdl()846 XMLCompareOnlyPropHdl::~XMLCompareOnlyPropHdl()
847 {
848 // Nothing to do
849 }
850
importXML(const OUString &,Any &,const SvXMLUnitConverter &) const851 sal_Bool XMLCompareOnlyPropHdl::importXML( const OUString&, Any&, const SvXMLUnitConverter& ) const
852 {
853 DBG_ASSERT( sal_False, "importXML called for compare-only-property" );
854 return sal_False;
855 }
856
exportXML(OUString &,const Any &,const SvXMLUnitConverter &) const857 sal_Bool XMLCompareOnlyPropHdl::exportXML( OUString&, const Any&, const SvXMLUnitConverter& ) const
858 {
859 DBG_ASSERT( sal_False, "exportXML called for compare-only-property" );
860 return sal_False;
861 }
862
863 ///////////////////////////////////////////////////////////////////////////////
864 // class XMLNumberWithoutZeroPropHdl
865 //
866
XMLNumberWithoutZeroPropHdl(sal_Int8 nB)867 XMLNumberWithoutZeroPropHdl::XMLNumberWithoutZeroPropHdl( sal_Int8 nB ) :
868 nBytes( nB )
869 {
870 }
871
~XMLNumberWithoutZeroPropHdl()872 XMLNumberWithoutZeroPropHdl::~XMLNumberWithoutZeroPropHdl()
873 {
874 }
875
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const876 sal_Bool XMLNumberWithoutZeroPropHdl::importXML(
877 const OUString& rStrImpValue,
878 Any& rValue,
879 const SvXMLUnitConverter& ) const
880 {
881 sal_Int32 nValue = 0;
882 sal_Bool bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue );
883 if( bRet )
884 lcl_xmloff_setAny( rValue, nValue, nBytes );
885 return bRet;
886 }
887
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const888 sal_Bool XMLNumberWithoutZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
889 {
890
891 sal_Int32 nValue = 0;
892 sal_Bool bRet = lcl_xmloff_getAny( rValue, nValue, nBytes );
893 bRet &= nValue != 0;
894
895 if( bRet )
896 {
897 OUStringBuffer aBuffer;
898 SvXMLUnitConverter::convertNumber( aBuffer, nValue );
899 rStrExpValue = aBuffer.makeStringAndClear();
900 }
901
902 return bRet;
903 }
904
905 ///////////////////////////////////////////////////////////////////////////////
906 // class XMLNumberWithAutoInsteadZeroPropHdl
907 //
908
~XMLNumberWithAutoInsteadZeroPropHdl()909 XMLNumberWithAutoInsteadZeroPropHdl::~XMLNumberWithAutoInsteadZeroPropHdl()
910 {
911 }
912
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const913 sal_Bool XMLNumberWithAutoInsteadZeroPropHdl::importXML(
914 const OUString& rStrImpValue,
915 Any& rValue,
916 const SvXMLUnitConverter& ) const
917 {
918 sal_Int32 nValue = 0;
919 sal_Bool bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue );
920 if( bRet )
921 lcl_xmloff_setAny( rValue, nValue, 2 );
922 else if( rStrImpValue == GetXMLToken( XML_AUTO ) )
923 {
924 rValue <<= (sal_Int16)nValue;
925 bRet = sal_True;
926 }
927 return bRet;
928 }
929
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const930 sal_Bool XMLNumberWithAutoInsteadZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
931 {
932
933 sal_Int32 nValue = 0;
934 lcl_xmloff_getAny( rValue, nValue, 2 );
935
936 if( 0 == nValue )
937 rStrExpValue = GetXMLToken( XML_AUTO );
938 else
939 {
940 OUStringBuffer aBuffer;
941 SvXMLUnitConverter::convertNumber( aBuffer, nValue );
942 rStrExpValue = aBuffer.makeStringAndClear();
943 }
944
945 return sal_True;
946 }
947