update dev300-m58
[ooovba.git] / xmloff / source / style / shadwhdl.cxx
blobec728a3ac309611e21804cd53fe1e1e4bcfcaddc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shadwhdl.cxx,v $
10 * $Revision: 1.8 $
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>
37 // --
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()
55 // nothing to do
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 );
68 OUString aToken;
70 while( aTokenEnum.getNextToken( aToken ) )
72 if( IsXMLToken( aToken, XML_NONE ) )
74 aShadow.Location = table::ShadowLocation_NONE;
75 bRet = sal_True;
76 break;
78 else if( !bColorFound && aToken.compareToAscii( "#", 1 ) == 0 )
80 bRet = rUnitConverter.convertColor( aColor, aToken );
81 if( !bRet )
82 return sal_False;
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 );
94 if( bRet )
96 if( nX < 0 )
98 if( nY < 0 )
99 aShadow.Location = table::ShadowLocation_TOP_LEFT;
100 else
101 aShadow.Location = table::ShadowLocation_BOTTOM_LEFT;
103 else
105 if( nY < 0 )
106 aShadow.Location = table::ShadowLocation_TOP_RIGHT;
107 else
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 >(
115 (nX + nY) >> 1);
120 if( bRet && ( bColorFound || bOffsetFound ) )
122 aShadow.IsTransparent = aColor.GetTransparency() > 0;
123 aShadow.Color = aColor.GetColor();
124 bRet = sal_True;
127 rValue <<= aShadow;
129 return bRet;
132 sal_Bool XMLShadowPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
134 sal_Bool bRet = sal_False;
135 OUStringBuffer aOut;
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:
145 nX = -1;
146 nY = -1;
147 break;
148 case table::ShadowLocation_TOP_RIGHT:
149 nY = -1;
150 break;
151 case table::ShadowLocation_BOTTOM_LEFT:
152 nX = -1;
153 break;
154 case table::ShadowLocation_BOTTOM_RIGHT:
155 break;
156 case table::ShadowLocation_NONE:
157 default:
158 rStrExpValue = GetXMLToken(XML_NONE);
159 return sal_True;
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();
174 bRet = sal_True;
177 return bRet;