1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shadwhdl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "shadwhdl.hxx"
34 #include <com/sun/star/uno/Any.hxx>
35 #include <rtl/ustrbuf.hxx>
38 #include <com/sun/star/table/ShadowFormat.hpp>
39 #include <xmloff/xmluconv.hxx>
40 #include <xmloff/xmltoken.hxx>
42 using ::rtl::OUString
;
43 using ::rtl::OUStringBuffer
;
45 using namespace ::com::sun::star
;
46 using namespace ::xmloff::token
;
48 ///////////////////////////////////////////////////////////////////////////////
50 // class XMLMeasurePropHdl
53 XMLShadowPropHdl::~XMLShadowPropHdl()
58 sal_Bool
XMLShadowPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
60 sal_Bool bRet
= sal_False
;
61 table::ShadowFormat aShadow
;
62 aShadow
.Location
= table::ShadowLocation_BOTTOM_RIGHT
;
64 sal_Bool bColorFound
= sal_False
;
65 sal_Bool bOffsetFound
= sal_False
;
66 SvXMLTokenEnumerator
aTokenEnum( rStrImpValue
);
67 Color
aColor( 128,128, 128 );
70 while( aTokenEnum
.getNextToken( aToken
) )
72 if( IsXMLToken( aToken
, XML_NONE
) )
74 aShadow
.Location
= table::ShadowLocation_NONE
;
78 else if( !bColorFound
&& aToken
.compareToAscii( "#", 1 ) == 0 )
80 bRet
= rUnitConverter
.convertColor( aColor
, aToken
);
84 bColorFound
= sal_True
;
86 else if( !bOffsetFound
)
88 sal_Int32 nX
= 0, nY
= 0;
90 bRet
= rUnitConverter
.convertMeasure( nX
, aToken
);
91 if( bRet
&& aTokenEnum
.getNextToken( aToken
) )
92 bRet
= rUnitConverter
.convertMeasure( nY
, aToken
);
99 aShadow
.Location
= table::ShadowLocation_TOP_LEFT
;
101 aShadow
.Location
= table::ShadowLocation_BOTTOM_LEFT
;
106 aShadow
.Location
= table::ShadowLocation_TOP_RIGHT
;
108 aShadow
.Location
= table::ShadowLocation_BOTTOM_RIGHT
;
111 if( nX
< 0 ) nX
*= -1;
112 if( nY
< 0 ) nY
*= -1;
114 aShadow
.ShadowWidth
= sal::static_int_cast
< sal_Int16
>(
120 if( bRet
&& ( bColorFound
|| bOffsetFound
) )
122 aShadow
.IsTransparent
= aColor
.GetTransparency() > 0;
123 aShadow
.Color
= aColor
.GetColor();
132 sal_Bool
XMLShadowPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
134 sal_Bool bRet
= sal_False
;
136 table::ShadowFormat aShadow
;
138 if( rValue
>>= aShadow
)
140 sal_Int32 nX
= 1, nY
= 1;
142 switch( aShadow
.Location
)
144 case table::ShadowLocation_TOP_LEFT
:
148 case table::ShadowLocation_TOP_RIGHT
:
151 case table::ShadowLocation_BOTTOM_LEFT
:
154 case table::ShadowLocation_BOTTOM_RIGHT
:
156 case table::ShadowLocation_NONE
:
158 rStrExpValue
= GetXMLToken(XML_NONE
);
162 nX
*= aShadow
.ShadowWidth
;
163 nY
*= aShadow
.ShadowWidth
;
165 rUnitConverter
.convertColor( aOut
, aShadow
.Color
);
167 aOut
.append( sal_Unicode(' ') );
168 rUnitConverter
.convertMeasure( aOut
, nX
);
169 aOut
.append( sal_Unicode(' ') );
170 rUnitConverter
.convertMeasure( aOut
, nY
);
172 rStrExpValue
= aOut
.makeStringAndClear();