1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include "xmlbahdl.hxx"
21 
22 #include <XMLNumberWithAutoForVoidPropHdl.hxx>
23 #include <sal/log.hxx>
24 #include <o3tl/any.hxx>
25 #include <o3tl/safeint.hxx>
26 #include <sax/tools/converter.hxx>
27 #include <xmloff/xmluconv.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <xmloff/xmltoken.hxx>
30 
31 #include <limits.h>
32 
33 using namespace ::com::sun::star::uno;
34 using namespace ::xmloff::token;
35 
lcl_xmloff_setAny(Any & rValue,sal_Int32 nValue,sal_Int8 nBytes)36 static void lcl_xmloff_setAny( Any& rValue, sal_Int32 nValue, sal_Int8 nBytes )
37 {
38     switch( nBytes )
39     {
40     case 1:
41         if( nValue < SCHAR_MIN )
42             nValue = SCHAR_MIN;
43         else if( nValue > SCHAR_MAX )
44             nValue = SCHAR_MAX;
45         rValue <<= static_cast<sal_Int8>(nValue);
46         break;
47     case 2:
48         if( nValue < SHRT_MIN )
49             nValue = SHRT_MIN;
50         else if( nValue > SHRT_MAX )
51             nValue = SHRT_MAX;
52         rValue <<= static_cast<sal_Int16>(nValue);
53         break;
54     case 4:
55         rValue <<= nValue;
56         break;
57     }
58 }
59 
lcl_xmloff_getAny(const Any & rValue,sal_Int32 & nValue,sal_Int8 nBytes)60 static bool lcl_xmloff_getAny( const Any& rValue, sal_Int32& nValue,
61                             sal_Int8 nBytes )
62 {
63     bool bRet = false;
64 
65     switch( nBytes )
66     {
67     case 1:
68         {
69             sal_Int8 nValue8 = 0;
70             bRet = rValue >>= nValue8;
71             nValue = nValue8;
72         }
73         break;
74     case 2:
75         {
76             sal_Int16 nValue16 = 0;
77             bRet = rValue >>= nValue16;
78             nValue = nValue16;
79         }
80         break;
81     case 4:
82         bRet = rValue >>= nValue;
83         break;
84     }
85 
86     return bRet;
87 }
88 
89 
~XMLNumberPropHdl()90 XMLNumberPropHdl::~XMLNumberPropHdl()
91 {
92     // nothing to do
93 }
94 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const95 bool XMLNumberPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
96 {
97     sal_Int32 nValue = 0;
98     bool bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
99     lcl_xmloff_setAny( rValue, nValue, nBytes );
100 
101     return bRet;
102 }
103 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const104 bool XMLNumberPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
105 {
106     bool bRet = false;
107     sal_Int32 nValue;
108 
109     if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
110     {
111         rStrExpValue = OUString::number( nValue );
112 
113         bRet = true;
114     }
115 
116     return bRet;
117 }
118 
119 
XMLNumberNonePropHdl(sal_Int8 nB)120 XMLNumberNonePropHdl::XMLNumberNonePropHdl( sal_Int8 nB ) :
121     sZeroStr( GetXMLToken(XML_NO_LIMIT) ),
122     nBytes( nB )
123 {
124 }
125 
XMLNumberNonePropHdl(enum XMLTokenEnum eZeroString,sal_Int8 nB)126 XMLNumberNonePropHdl::XMLNumberNonePropHdl( enum XMLTokenEnum eZeroString, sal_Int8 nB ) :
127     sZeroStr( GetXMLToken( eZeroString ) ),
128     nBytes( nB )
129 {
130 }
131 
~XMLNumberNonePropHdl()132 XMLNumberNonePropHdl::~XMLNumberNonePropHdl()
133 {
134     // nothing to do
135 }
136 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const137 bool XMLNumberNonePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
138 {
139     bool bRet = false;
140 
141     sal_Int32 nValue = 0;
142     if( rStrImpValue == sZeroStr )
143     {
144         bRet = true;
145     }
146     else
147     {
148         bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
149     }
150     lcl_xmloff_setAny( rValue, nValue, nBytes );
151 
152     return bRet;
153 }
154 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const155 bool XMLNumberNonePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
156 {
157     bool bRet = false;
158     sal_Int32 nValue;
159 
160     if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
161     {
162         if( nValue == 0 )
163         {
164             rStrExpValue = sZeroStr;
165         }
166         else
167         {
168             rStrExpValue = OUString::number( nValue );
169         }
170 
171         bRet = true;
172     }
173 
174     return bRet;
175 }
176 
177 
~XMLMeasurePropHdl()178 XMLMeasurePropHdl::~XMLMeasurePropHdl()
179 {
180     // nothing to do
181 }
182 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter & rUnitConverter) const183 bool XMLMeasurePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
184 {
185     sal_Int32 nValue = 0;
186     bool bRet = rUnitConverter.convertMeasureToCore( nValue, rStrImpValue );
187     lcl_xmloff_setAny( rValue, nValue, nBytes );
188     return bRet;
189 }
190 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter & rUnitConverter) const191 bool XMLMeasurePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
192 {
193     bool bRet = false;
194     sal_Int32 nValue;
195 
196     if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
197     {
198         OUStringBuffer aOut;
199         rUnitConverter.convertMeasureToXML( aOut, nValue );
200         rStrExpValue = aOut.makeStringAndClear();
201 
202         bRet = true;
203     }
204 
205     return bRet;
206 }
207 
208 
~XMLBoolFalsePropHdl()209 XMLBoolFalsePropHdl::~XMLBoolFalsePropHdl()
210 {
211     // nothing to do
212 }
213 
importXML(const OUString &,Any &,const SvXMLUnitConverter &) const214 bool XMLBoolFalsePropHdl::importXML( const OUString&, Any&, const SvXMLUnitConverter& ) const
215 {
216     return false;
217 }
218 
exportXML(OUString & rStrExpValue,const Any &,const SvXMLUnitConverter & rCnv) const219 bool XMLBoolFalsePropHdl::exportXML( OUString& rStrExpValue, const Any& /*rValue*/, const SvXMLUnitConverter& rCnv) const
220 {
221     return XMLBoolPropHdl::exportXML( rStrExpValue, makeAny( false ), rCnv );
222 }
223 
224 
~XMLBoolPropHdl()225 XMLBoolPropHdl::~XMLBoolPropHdl()
226 {
227     // nothing to do
228 }
229 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const230 bool XMLBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
231 {
232     bool bValue(false);
233     bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
234     rValue <<= bValue;
235 
236     return bRet;
237 }
238 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const239 bool XMLBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
240 {
241     bool bRet = false;
242     bool bValue;
243 
244     if (rValue >>= bValue)
245     {
246         OUStringBuffer aOut;
247         ::sax::Converter::convertBool( aOut, bValue );
248         rStrExpValue = aOut.makeStringAndClear();
249 
250         bRet = true;
251     }
252 
253     return bRet;
254 }
255 
256 
~XMLNBoolPropHdl()257 XMLNBoolPropHdl::~XMLNBoolPropHdl()
258 {
259     // nothing to do
260 }
261 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const262 bool XMLNBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
263 {
264     bool bValue(false);
265     bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
266     rValue <<= !bValue;
267 
268     return bRet;
269 }
270 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const271 bool XMLNBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
272 {
273     bool bRet = false;
274     bool bValue;
275 
276     if (rValue >>= bValue)
277     {
278         OUStringBuffer aOut;
279         ::sax::Converter::convertBool( aOut, !bValue );
280         rStrExpValue = aOut.makeStringAndClear();
281 
282         bRet = true;
283     }
284 
285     return bRet;
286 }
287 
288 
~XMLPercentPropHdl()289 XMLPercentPropHdl::~XMLPercentPropHdl()
290 {
291     // nothing to do
292 }
293 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const294 bool XMLPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
295 {
296     sal_Int32 nValue = 0;
297     bool const bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
298     lcl_xmloff_setAny( rValue, nValue, nBytes );
299 
300     return bRet;
301 }
302 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const303 bool XMLPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
304 {
305     bool bRet = false;
306     sal_Int32 nValue;
307 
308     if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
309     {
310         OUStringBuffer aOut;
311         ::sax::Converter::convertPercent( aOut, nValue );
312         rStrExpValue = aOut.makeStringAndClear();
313 
314         bRet = true;
315     }
316 
317     return bRet;
318 }
319 
320 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const321 bool XMLDoublePercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
322 {
323     bool bRet = false;
324 
325     double fValue = 1.0;
326 
327     if( rStrImpValue.indexOf( '%' ) == -1 )
328     {
329         fValue = rStrImpValue.toDouble();
330     }
331     else
332     {
333         sal_Int32 nValue = 0;
334         bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
335         fValue = static_cast<double>(nValue) / 100.0;
336     }
337     rValue <<= fValue;
338 
339     return bRet;
340 }
341 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const342 bool XMLDoublePercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
343 {
344     bool bRet = false;
345     double fValue = 0;
346 
347     if( rValue >>= fValue )
348     {
349         fValue *= 100.0;
350         if( fValue > 0 ) fValue += 0.5; else    fValue -= 0.5;
351 
352         sal_Int32 nValue = static_cast<sal_Int32>(fValue);
353 
354         OUStringBuffer aOut;
355         ::sax::Converter::convertPercent( aOut, nValue );
356         rStrExpValue = aOut.makeStringAndClear();
357 
358         bRet = true;
359     }
360 
361     return bRet;
362 }
363 
364 
~XMLNegPercentPropHdl()365 XMLNegPercentPropHdl::~XMLNegPercentPropHdl()
366 {
367     // nothing to do
368 }
369 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const370 bool XMLNegPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
371 {
372     sal_Int32 nValue = 0;
373     bool bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
374     if (bRet)
375         bRet = !o3tl::checked_sub<sal_Int32>(100, nValue, nValue);
376     if (bRet)
377         lcl_xmloff_setAny( rValue, nValue, nBytes );
378     return bRet;
379 }
380 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const381 bool XMLNegPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
382 {
383     bool bRet = false;
384     sal_Int32 nValue;
385 
386     if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
387     {
388         OUStringBuffer aOut;
389         ::sax::Converter::convertPercent( aOut, 100-nValue );
390         rStrExpValue = aOut.makeStringAndClear();
391 
392         bRet = true;
393     }
394 
395     return bRet;
396 }
397 
~XMLMeasurePxPropHdl()398 XMLMeasurePxPropHdl::~XMLMeasurePxPropHdl()
399 {
400     // nothing to do
401 }
402 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const403 bool XMLMeasurePxPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
404 {
405     sal_Int32 nValue = 0;
406     bool bRet = ::sax::Converter::convertMeasurePx( nValue, rStrImpValue );
407     lcl_xmloff_setAny( rValue, nValue, nBytes );
408     return bRet;
409 }
410 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const411 bool XMLMeasurePxPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
412 {
413     bool bRet = false;
414     sal_Int32 nValue;
415 
416     if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
417     {
418         OUStringBuffer aOut;
419         ::sax::Converter::convertMeasurePx( aOut, nValue );
420         rStrExpValue = aOut.makeStringAndClear();
421 
422         bRet = true;
423     }
424 
425     return bRet;
426 }
427 
428 
~XMLColorPropHdl()429 XMLColorPropHdl::~XMLColorPropHdl()
430 {
431     // Nothing to do
432 }
433 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const434 bool XMLColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
435 {
436     bool bRet = false;
437 
438     if( rStrImpValue.matchIgnoreAsciiCase( "hsl" ) )
439     {
440         sal_Int32 nOpen = rStrImpValue.indexOf( '(' );
441         sal_Int32 nClose = rStrImpValue.lastIndexOf( ')' );
442 
443         if( (nOpen != -1) && (nClose > nOpen) )
444         {
445             const OUString aTmp( rStrImpValue.copy( nOpen+1, nClose - nOpen-1) );
446 
447             sal_Int32 nIndex = 0;
448 
449             Sequence< double > aHSL
450             {
451                 aTmp.getToken( 0, ',', nIndex ).toDouble(),
452                 aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0,
453                 aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0
454             };
455             rValue <<= aHSL;
456             bRet = true;
457         }
458     }
459     else
460     {
461         sal_Int32 nColor(0);
462         bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
463         rValue <<= nColor;
464     }
465 
466     return bRet;
467 }
468 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const469 bool XMLColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
470 {
471     bool bRet = false;
472     sal_Int32 nColor = 0;
473 
474     OUStringBuffer aOut;
475     if( rValue >>= nColor )
476     {
477         ::sax::Converter::convertColor( aOut, nColor );
478         rStrExpValue = aOut.makeStringAndClear();
479 
480         bRet = true;
481     }
482     else
483     {
484         Sequence< double > aHSL;
485         if( (rValue >>= aHSL) && (aHSL.getLength() == 3) )
486         {
487             rStrExpValue = "hsl(" + OUString::number(aHSL[0]) + "," +
488                     OUString::number(aHSL[1] * 100.0) +  "%," +
489                     OUString::number(aHSL[2] * 100.0) + "%)";
490 
491             bRet = true;
492         }
493     }
494 
495     return bRet;
496 }
497 
498 
~XMLHexPropHdl()499 XMLHexPropHdl::~XMLHexPropHdl()
500 {
501     // Nothing to do
502 }
503 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const504 bool XMLHexPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
505 {
506     sal_uInt32 nRsid;
507     bool bRet = SvXMLUnitConverter::convertHex( nRsid, rStrImpValue );
508     rValue <<= nRsid;
509 
510     return bRet;
511 }
512 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const513 bool XMLHexPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
514 {
515     bool bRet = false;
516     sal_uInt32 nRsid = 0;
517 
518     if( rValue >>= nRsid )
519     {
520         OUStringBuffer aOut;
521         SvXMLUnitConverter::convertHex( aOut, nRsid );
522         rStrExpValue = aOut.makeStringAndClear();
523 
524         bRet = true;
525     }
526     else
527     {
528         bRet = false;
529     }
530 
531     return bRet;
532 }
533 
534 
~XMLStringPropHdl()535 XMLStringPropHdl::~XMLStringPropHdl()
536 {
537     // Nothing to do
538 }
539 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const540 bool XMLStringPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
541 {
542     rValue <<= rStrImpValue;
543     return true;
544 }
545 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const546 bool XMLStringPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
547 {
548     bool bRet = false;
549 
550     if( rValue >>= rStrExpValue )
551         bRet = true;
552 
553     return bRet;
554 }
555 
556 
~XMLStyleNamePropHdl()557 XMLStyleNamePropHdl::~XMLStyleNamePropHdl()
558 {
559     // Nothing to do
560 }
561 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter & rUnitConverter) const562 bool XMLStyleNamePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
563 {
564     bool bRet = false;
565 
566     if( rValue >>= rStrExpValue )
567     {
568         rStrExpValue = rUnitConverter.encodeStyleName( rStrExpValue );
569         bRet = true;
570     }
571 
572     return bRet;
573 }
574 
575 
~XMLDoublePropHdl()576 XMLDoublePropHdl::~XMLDoublePropHdl()
577 {
578     // Nothing to do
579 }
580 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const581 bool XMLDoublePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
582 {
583     double fDblValue(0.0);
584     bool const bRet = ::sax::Converter::convertDouble(fDblValue, rStrImpValue);
585     rValue <<= fDblValue;
586     return bRet;
587 }
588 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const589 bool XMLDoublePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
590 {
591     bool bRet = false;
592 
593     double fValue = 0;
594 
595     if( rValue >>= fValue )
596     {
597         OUStringBuffer aOut;
598         ::sax::Converter::convertDouble( aOut, fValue );
599         rStrExpValue = aOut.makeStringAndClear();
600         bRet = true;
601     }
602 
603     return bRet;
604 }
605 
606 
XMLColorTransparentPropHdl(enum XMLTokenEnum eTransparent)607 XMLColorTransparentPropHdl::XMLColorTransparentPropHdl(
608     enum XMLTokenEnum eTransparent ) :
609     sTransparent( GetXMLToken(
610         eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) )
611 {
612     // Nothing to do
613 }
614 
~XMLColorTransparentPropHdl()615 XMLColorTransparentPropHdl::~XMLColorTransparentPropHdl()
616 {
617     // Nothing to do
618 }
619 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const620 bool XMLColorTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
621 {
622     bool bRet = false;
623 
624     if( rStrImpValue != sTransparent )
625     {
626         sal_Int32 nColor(0);
627         bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
628         rValue <<= nColor;
629     }
630 
631     return bRet;
632 }
633 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const634 bool XMLColorTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
635 {
636     bool bRet = false;
637     sal_Int32 nColor = 0;
638 
639     if( rStrExpValue == sTransparent )
640         bRet = false;
641     else if( rValue >>= nColor )
642     {
643         OUStringBuffer aOut;
644         ::sax::Converter::convertColor( aOut, nColor );
645         rStrExpValue = aOut.makeStringAndClear();
646 
647         bRet = true;
648     }
649 
650     return bRet;
651 }
652 
653 
XMLIsTransparentPropHdl(enum XMLTokenEnum eTransparent,bool bTransPropVal)654 XMLIsTransparentPropHdl::XMLIsTransparentPropHdl(
655     enum XMLTokenEnum eTransparent, bool bTransPropVal ) :
656     sTransparent( GetXMLToken(
657         eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) ),
658     bTransPropValue( bTransPropVal )
659 {
660 }
661 
~XMLIsTransparentPropHdl()662 XMLIsTransparentPropHdl::~XMLIsTransparentPropHdl()
663 {
664     // Nothing to do
665 }
666 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const667 bool XMLIsTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
668 {
669     bool bValue = ( (rStrImpValue == sTransparent) == bTransPropValue);
670     rValue <<= bValue;
671 
672     return true;
673 }
674 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const675 bool XMLIsTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
676 {
677     bool bRet = false;
678 
679     // MIB: This looks a bit strange, because bTransPropValue == bValue should
680     // do the same, but this only applies if 'true' is represented by the same
681     // 8 bit value in bValue and bTransPropValue. Who will ensure this?
682     bool bValue = *o3tl::doAccess<bool>(rValue);
683     bool bIsTrans = bTransPropValue ? bValue : !bValue;
684 
685     if( bIsTrans )
686     {
687         rStrExpValue = sTransparent;
688         bRet = true;
689     }
690 
691     return bRet;
692 }
693 
694 
XMLColorAutoPropHdl()695 XMLColorAutoPropHdl::XMLColorAutoPropHdl()
696 {
697     // Nothing to do
698 }
699 
~XMLColorAutoPropHdl()700 XMLColorAutoPropHdl::~XMLColorAutoPropHdl()
701 {
702     // Nothing to do
703 }
704 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const705 bool XMLColorAutoPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
706 {
707     bool bRet = false;
708 
709     // This is a multi property: the value might be set to AUTO_COLOR
710     // already by the XMLIsAutoColorPropHdl!
711     sal_Int32 nColor = 0;
712     if( !(rValue >>= nColor) || -1 != nColor )
713     {
714         bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
715         if( bRet )
716             rValue <<= nColor;
717     }
718 
719     return bRet;
720 }
721 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const722 bool XMLColorAutoPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
723 {
724     bool bRet = false;
725 
726     sal_Int32 nColor = 0;
727     if( (rValue >>= nColor) && -1 != nColor )
728     {
729         OUStringBuffer aOut;
730         ::sax::Converter::convertColor( aOut, nColor );
731         rStrExpValue = aOut.makeStringAndClear();
732 
733         bRet = true;
734     }
735 
736     return bRet;
737 }
738 
739 
XMLIsAutoColorPropHdl()740 XMLIsAutoColorPropHdl::XMLIsAutoColorPropHdl()
741 {
742 }
743 
~XMLIsAutoColorPropHdl()744 XMLIsAutoColorPropHdl::~XMLIsAutoColorPropHdl()
745 {
746     // Nothing to do
747 }
748 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const749 bool XMLIsAutoColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
750 {
751     // An auto color overrides any other color set!
752     bool bValue;
753     bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
754     if( bRet && bValue )
755         rValue <<= sal_Int32(-1);
756 
757     return true;
758 }
759 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const760 bool XMLIsAutoColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
761 {
762     bool bRet = false;
763     sal_Int32 nColor = 0;
764 
765     if( (rValue >>= nColor) && -1 == nColor )
766     {
767         OUStringBuffer aOut;
768         ::sax::Converter::convertBool( aOut, true );
769         rStrExpValue = aOut.makeStringAndClear();
770 
771         bRet = true;
772     }
773 
774     return bRet;
775 }
776 
777 
~XMLCompareOnlyPropHdl()778 XMLCompareOnlyPropHdl::~XMLCompareOnlyPropHdl()
779 {
780     // Nothing to do
781 }
782 
importXML(const OUString &,Any &,const SvXMLUnitConverter &) const783 bool XMLCompareOnlyPropHdl::importXML( const OUString&, Any&, const SvXMLUnitConverter& ) const
784 {
785     SAL_WARN( "xmloff", "importXML called for compare-only-property" );
786     return false;
787 }
788 
exportXML(OUString &,const Any &,const SvXMLUnitConverter &) const789 bool XMLCompareOnlyPropHdl::exportXML( OUString&, const Any&, const SvXMLUnitConverter& ) const
790 {
791     SAL_WARN( "xmloff", "exportXML called for compare-only-property" );
792     return false;
793 }
794 
795 
XMLNumberWithoutZeroPropHdl(sal_Int8 nB)796 XMLNumberWithoutZeroPropHdl::XMLNumberWithoutZeroPropHdl( sal_Int8 nB ) :
797     nBytes( nB )
798 {
799 }
800 
~XMLNumberWithoutZeroPropHdl()801 XMLNumberWithoutZeroPropHdl::~XMLNumberWithoutZeroPropHdl()
802 {
803 }
804 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const805 bool XMLNumberWithoutZeroPropHdl::importXML(
806     const OUString& rStrImpValue,
807     Any& rValue,
808     const SvXMLUnitConverter& ) const
809 {
810     sal_Int32 nValue = 0;
811     bool const bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
812     if( bRet )
813         lcl_xmloff_setAny( rValue, nValue, nBytes );
814     return bRet;
815 }
816 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const817 bool XMLNumberWithoutZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
818 {
819 
820     sal_Int32 nValue = 0;
821     bool bRet = lcl_xmloff_getAny( rValue, nValue, nBytes );
822     bRet &= nValue != 0;
823 
824     if( bRet )
825     {
826         rStrExpValue = OUString::number(nValue);
827     }
828 
829     return bRet;
830 }
831 
832 
~XMLNumberWithAutoForVoidPropHdl()833 XMLNumberWithAutoForVoidPropHdl::~XMLNumberWithAutoForVoidPropHdl()
834 {
835 }
836 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const837 bool XMLNumberWithAutoForVoidPropHdl::importXML(
838     const OUString& rStrImpValue,
839     Any& rValue,
840     const SvXMLUnitConverter& ) const
841 {
842     sal_Int32 nValue = 0;
843     bool bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
844     if( bRet )
845         lcl_xmloff_setAny( rValue, nValue, 2 );
846     else if( rStrImpValue == GetXMLToken( XML_AUTO ) )
847     {
848         rValue.clear(); // void
849         bRet = true;
850     }
851     return bRet;
852 }
853 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const854 bool XMLNumberWithAutoForVoidPropHdl::exportXML(
855         OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter&) const
856 {
857 
858     sal_Int32 nValue = 0;
859     bool bRet = lcl_xmloff_getAny( rValue, nValue, 2 );
860 
861     // note: 0 is a valid value here, see CTF_PAGENUMBEROFFSET for when it isn't
862 
863     if (!bRet)
864         rStrExpValue = GetXMLToken( XML_AUTO );
865     else
866     {
867         rStrExpValue = OUString::number(nValue);
868     }
869 
870     return true;
871 }
872 
873 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
874