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 SvXMLUnitConverter::convertPercent( aOut, 100-nValue );
425 rStrExpValue = aOut.makeStringAndClear();
426
427 bRet = sal_True;
428 }
429
430 return bRet;
431 }
432
433
434 ///////////////////////////////////////////////////////////////////////////////
435 //
436 // class XMLMeasurePxPropHdl
437 //
438
~XMLMeasurePxPropHdl()439 XMLMeasurePxPropHdl::~XMLMeasurePxPropHdl()
440 {
441 // nothing to do
442 }
443
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const444 sal_Bool XMLMeasurePxPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
445 {
446 sal_Bool bRet = sal_False;
447
448 sal_Int32 nValue = 0;
449 bRet = SvXMLUnitConverter::convertMeasurePx( nValue, rStrImpValue );
450 lcl_xmloff_setAny( rValue, nValue, nBytes );
451
452 return bRet;
453 }
454
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const455 sal_Bool XMLMeasurePxPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
456 {
457 sal_Bool bRet = sal_False;
458 sal_Int32 nValue;
459 OUStringBuffer aOut;
460
461 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
462 {
463 SvXMLUnitConverter::convertMeasurePx( aOut, nValue );
464 rStrExpValue = aOut.makeStringAndClear();
465
466 bRet = sal_True;
467 }
468
469 return bRet;
470 }
471
472 ///////////////////////////////////////////////////////////////////////////////
473 //
474 // class XMLColorPropHdl
475 //
476
~XMLColorPropHdl()477 XMLColorPropHdl::~XMLColorPropHdl()
478 {
479 // Nothing to do
480 }
481
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const482 sal_Bool XMLColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
483 {
484 sal_Bool bRet = sal_False;
485 Color aColor;
486
487 const OUString astrHSL( RTL_CONSTASCII_USTRINGPARAM( "hsl" ) );
488 if( rStrImpValue.matchIgnoreAsciiCase( astrHSL ) )
489 {
490 sal_Int32 nOpen = rStrImpValue.indexOf( '(' );
491 sal_Int32 nClose = rStrImpValue.lastIndexOf( ')' );
492
493 if( (nOpen != -1) && (nClose > nOpen) )
494 {
495 const OUString aTmp( rStrImpValue.copy( nOpen+1, nClose - nOpen-1) );
496
497 sal_Int32 nIndex = 0;
498
499 Sequence< double > aHSL(3);
500 aHSL[0] = aTmp.getToken( 0, ',', nIndex ).toDouble();
501 aHSL[1] = aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0;
502 aHSL[2] = aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0;
503 rValue <<= aHSL;
504 bRet = true;
505 }
506 }
507 else
508 {
509 bRet = SvXMLUnitConverter::convertColor( aColor, rStrImpValue );
510 rValue <<= (sal_Int32)( aColor.GetColor() );
511 }
512
513 return bRet;
514 }
515
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const516 sal_Bool XMLColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
517 {
518 sal_Bool bRet = sal_False;
519 Color aColor;
520 sal_Int32 nColor = 0;
521
522 OUStringBuffer aOut;
523 if( rValue >>= nColor )
524 {
525 aColor.SetColor( nColor );
526
527 SvXMLUnitConverter::convertColor( aOut, aColor );
528 rStrExpValue = aOut.makeStringAndClear();
529
530 bRet = sal_True;
531 }
532 else
533 {
534 Sequence< double > aHSL;
535 if( (rValue >>= aHSL) && (aHSL.getLength() == 3) )
536 {
537 aOut.append( OUString::createFromAscii("hsl(") );
538 aOut.append( aHSL[0] );
539 aOut.append( OUString::createFromAscii(",") );
540 aOut.append( aHSL[1] * 100.0 );
541 aOut.append( OUString::createFromAscii("%,") );
542 aOut.append( aHSL[2] * 100.0 );
543 aOut.append( OUString::createFromAscii("%)") );
544 rStrExpValue = aOut.makeStringAndClear();
545
546 bRet = sal_True;
547 }
548 }
549
550 return bRet;
551 }
552
553 ///////////////////////////////////////////////////////////////////////////////
554 //
555 // class XMLStringPropHdl
556 //
557
~XMLStringPropHdl()558 XMLStringPropHdl::~XMLStringPropHdl()
559 {
560 // Nothing to do
561 }
562
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const563 sal_Bool XMLStringPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
564 {
565 sal_Bool bRet = sal_False;
566
567 rValue <<= rStrImpValue;
568 bRet = sal_True;
569
570 return bRet;
571 }
572
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const573 sal_Bool XMLStringPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
574 {
575 sal_Bool bRet = sal_False;
576
577 if( rValue >>= rStrExpValue )
578 bRet = sal_True;
579
580 return bRet;
581 }
582
583 ///////////////////////////////////////////////////////////////////////////////
584 //
585 // class XMLStyleNamePropHdl
586 //
587
~XMLStyleNamePropHdl()588 XMLStyleNamePropHdl::~XMLStyleNamePropHdl()
589 {
590 // Nothing to do
591 }
592
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter & rUnitConverter) const593 sal_Bool XMLStyleNamePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
594 {
595 sal_Bool bRet = sal_False;
596
597 if( rValue >>= rStrExpValue )
598 {
599 rStrExpValue = rUnitConverter.encodeStyleName( rStrExpValue );
600 bRet = sal_True;
601 }
602
603 return bRet;
604 }
605
606
607 ///////////////////////////////////////////////////////////////////////////////
608 //
609 // class XMLDoublePropHdl
610 //
611
~XMLDoublePropHdl()612 XMLDoublePropHdl::~XMLDoublePropHdl()
613 {
614 // Nothing to do
615 }
616
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const617 sal_Bool XMLDoublePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
618 {
619 double fDblValue;
620 sal_Bool bRet = SvXMLUnitConverter::convertDouble( fDblValue, rStrImpValue );
621 rValue <<= fDblValue;
622 return bRet;
623 }
624
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const625 sal_Bool XMLDoublePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
626 {
627 sal_Bool bRet = sal_False;
628
629 double fValue = 0;
630
631 if( rValue >>= fValue )
632 {
633 OUStringBuffer aOut;
634 SvXMLUnitConverter::convertDouble( aOut, fValue );
635 rStrExpValue = aOut.makeStringAndClear();
636 bRet = sal_True;
637 }
638
639 return bRet;
640 }
641
642 ///////////////////////////////////////////////////////////////////////////////
643 //
644 // class XMLColorTransparentPropHdl
645 //
646
XMLColorTransparentPropHdl(enum XMLTokenEnum eTransparent)647 XMLColorTransparentPropHdl::XMLColorTransparentPropHdl(
648 enum XMLTokenEnum eTransparent ) :
649 sTransparent( GetXMLToken(
650 eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) )
651 {
652 // Nothing to do
653 }
654
~XMLColorTransparentPropHdl()655 XMLColorTransparentPropHdl::~XMLColorTransparentPropHdl()
656 {
657 // Nothing to do
658 }
659
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const660 sal_Bool XMLColorTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
661 {
662 sal_Bool bRet = sal_False;
663
664 if( rStrImpValue != sTransparent )
665 {
666 Color aColor;
667 bRet = SvXMLUnitConverter::convertColor( aColor, rStrImpValue );
668 rValue <<= (sal_Int32)( aColor.GetColor() );
669 }
670
671 return bRet;
672 }
673
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const674 sal_Bool XMLColorTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
675 {
676 sal_Bool bRet = sal_False;
677 sal_Int32 nColor = 0;
678
679 if( rStrExpValue == sTransparent )
680 bRet = sal_False;
681 else if( rValue >>= nColor )
682 {
683 Color aColor( nColor );
684 OUStringBuffer aOut;
685 SvXMLUnitConverter::convertColor( aOut, aColor );
686 rStrExpValue = aOut.makeStringAndClear();
687
688 bRet = sal_True;
689 }
690
691 return bRet;
692 }
693
694
695 ///////////////////////////////////////////////////////////////////////////////
696 //
697 // class XMLIsTransparentPropHdl
698 //
699
XMLIsTransparentPropHdl(enum XMLTokenEnum eTransparent,sal_Bool bTransPropVal)700 XMLIsTransparentPropHdl::XMLIsTransparentPropHdl(
701 enum XMLTokenEnum eTransparent, sal_Bool bTransPropVal ) :
702 sTransparent( GetXMLToken(
703 eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) ),
704 bTransPropValue( bTransPropVal )
705 {
706 }
707
~XMLIsTransparentPropHdl()708 XMLIsTransparentPropHdl::~XMLIsTransparentPropHdl()
709 {
710 // Nothing to do
711 }
712
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const713 sal_Bool XMLIsTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
714 {
715 sal_Bool bValue = ( (rStrImpValue == sTransparent) == bTransPropValue);
716 rValue.setValue( &bValue, ::getBooleanCppuType() );
717
718 return sal_True;
719 }
720
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const721 sal_Bool XMLIsTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
722 {
723 sal_Bool bRet = sal_False;
724
725 // MIB: This looks a bit strange, because bTransPropValue == bValue should
726 // do the same, but this only applies if 'true' is represented by the same
727 // 8 bit value in bValue and bTransPropValue. Who will ensure this?
728 sal_Bool bValue = *(sal_Bool *)rValue.getValue();
729 sal_Bool bIsTrans = bTransPropValue ? bValue : !bValue;
730
731 if( bIsTrans )
732 {
733 rStrExpValue = sTransparent;
734 bRet = sal_True;
735 }
736
737 return bRet;
738 }
739
740 ///////////////////////////////////////////////////////////////////////////////
741 //
742 // class XMLColorAutoPropHdl
743 //
744
XMLColorAutoPropHdl()745 XMLColorAutoPropHdl::XMLColorAutoPropHdl()
746 {
747 // Nothing to do
748 }
749
~XMLColorAutoPropHdl()750 XMLColorAutoPropHdl::~XMLColorAutoPropHdl()
751 {
752 // Nothing to do
753 }
754
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const755 sal_Bool XMLColorAutoPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
756 {
757 sal_Bool bRet = sal_False;
758
759 // This is a multi property: the value might be set to AUTO_COLOR
760 // already by the XMLIsAutoColorPropHdl!
761 sal_Int32 nColor = 0;
762 if( !(rValue >>= nColor) || -1 != nColor )
763 {
764 Color aColor;
765 bRet = SvXMLUnitConverter::convertColor( aColor, rStrImpValue );
766 if( bRet )
767 rValue <<= (sal_Int32)( aColor.GetColor() );
768 }
769
770 return bRet;
771 }
772
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const773 sal_Bool XMLColorAutoPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
774 {
775 sal_Bool bRet = sal_False;
776
777 sal_Int32 nColor = 0;
778 if( (rValue >>= nColor) && -1 != nColor )
779 {
780 Color aColor( nColor );
781 OUStringBuffer aOut;
782 SvXMLUnitConverter::convertColor( aOut, aColor );
783 rStrExpValue = aOut.makeStringAndClear();
784
785 bRet = sal_True;
786 }
787
788 return bRet;
789 }
790
791 ///////////////////////////////////////////////////////////////////////////////
792 //
793 // class XMLIsAutoColorPropHdl
794 //
795
XMLIsAutoColorPropHdl()796 XMLIsAutoColorPropHdl::XMLIsAutoColorPropHdl()
797 {
798 }
799
~XMLIsAutoColorPropHdl()800 XMLIsAutoColorPropHdl::~XMLIsAutoColorPropHdl()
801 {
802 // Nothing to do
803 }
804
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const805 sal_Bool XMLIsAutoColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
806 {
807 sal_Bool bValue;
808
809 // An auto color overrides any other color set!
810 sal_Bool bRet = SvXMLUnitConverter::convertBool( bValue, rStrImpValue );
811 if( bRet && bValue )
812 rValue <<= (sal_Int32)-1;
813
814 return sal_True;
815 }
816
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const817 sal_Bool XMLIsAutoColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
818 {
819 sal_Bool bRet = sal_False;
820 sal_Int32 nColor = 0;
821
822 if( (rValue >>= nColor) && -1 == nColor )
823 {
824 OUStringBuffer aOut;
825 SvXMLUnitConverter::convertBool( aOut, sal_True );
826 rStrExpValue = aOut.makeStringAndClear();
827
828 bRet = sal_True;
829 }
830
831 return bRet;
832 }
833
834 ///////////////////////////////////////////////////////////////////////////////
835 //
836 // class XMLCompareOnlyPropHdl
837 //
838
~XMLCompareOnlyPropHdl()839 XMLCompareOnlyPropHdl::~XMLCompareOnlyPropHdl()
840 {
841 // Nothing to do
842 }
843
importXML(const OUString &,Any &,const SvXMLUnitConverter &) const844 sal_Bool XMLCompareOnlyPropHdl::importXML( const OUString&, Any&, const SvXMLUnitConverter& ) const
845 {
846 DBG_ASSERT( sal_False, "importXML called for compare-only-property" );
847 return sal_False;
848 }
849
exportXML(OUString &,const Any &,const SvXMLUnitConverter &) const850 sal_Bool XMLCompareOnlyPropHdl::exportXML( OUString&, const Any&, const SvXMLUnitConverter& ) const
851 {
852 DBG_ASSERT( sal_False, "exportXML called for compare-only-property" );
853 return sal_False;
854 }
855
856 ///////////////////////////////////////////////////////////////////////////////
857 // class XMLNumberWithoutZeroPropHdl
858 //
859
XMLNumberWithoutZeroPropHdl(sal_Int8 nB)860 XMLNumberWithoutZeroPropHdl::XMLNumberWithoutZeroPropHdl( sal_Int8 nB ) :
861 nBytes( nB )
862 {
863 }
864
~XMLNumberWithoutZeroPropHdl()865 XMLNumberWithoutZeroPropHdl::~XMLNumberWithoutZeroPropHdl()
866 {
867 }
868
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const869 sal_Bool XMLNumberWithoutZeroPropHdl::importXML(
870 const OUString& rStrImpValue,
871 Any& rValue,
872 const SvXMLUnitConverter& ) const
873 {
874 sal_Int32 nValue = 0;
875 sal_Bool bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue );
876 if( bRet )
877 lcl_xmloff_setAny( rValue, nValue, nBytes );
878 return bRet;
879 }
880
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const881 sal_Bool XMLNumberWithoutZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
882 {
883
884 sal_Int32 nValue = 0;
885 sal_Bool bRet = lcl_xmloff_getAny( rValue, nValue, nBytes );
886 bRet &= nValue != 0;
887
888 if( bRet )
889 {
890 OUStringBuffer aBuffer;
891 SvXMLUnitConverter::convertNumber( aBuffer, nValue );
892 rStrExpValue = aBuffer.makeStringAndClear();
893 }
894
895 return bRet;
896 }
897
898 ///////////////////////////////////////////////////////////////////////////////
899 // class XMLNumberWithAutoInsteadZeroPropHdl
900 //
901
~XMLNumberWithAutoInsteadZeroPropHdl()902 XMLNumberWithAutoInsteadZeroPropHdl::~XMLNumberWithAutoInsteadZeroPropHdl()
903 {
904 }
905
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const906 sal_Bool XMLNumberWithAutoInsteadZeroPropHdl::importXML(
907 const OUString& rStrImpValue,
908 Any& rValue,
909 const SvXMLUnitConverter& ) const
910 {
911 sal_Int32 nValue = 0;
912 sal_Bool bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue );
913 if( bRet )
914 lcl_xmloff_setAny( rValue, nValue, 2 );
915 else if( rStrImpValue == GetXMLToken( XML_AUTO ) )
916 {
917 rValue <<= (sal_Int16)nValue;
918 bRet = sal_True;
919 }
920 return bRet;
921 }
922
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const923 sal_Bool XMLNumberWithAutoInsteadZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
924 {
925
926 sal_Int32 nValue = 0;
927 lcl_xmloff_getAny( rValue, nValue, 2 );
928
929 if( 0 == nValue )
930 rStrExpValue = GetXMLToken( XML_AUTO );
931 else
932 {
933 OUStringBuffer aBuffer;
934 SvXMLUnitConverter::convertNumber( aBuffer, nValue );
935 rStrExpValue = aBuffer.makeStringAndClear();
936 }
937
938 return sal_True;
939 }
940
941