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