xref: /aoo41x/main/xmloff/source/style/shadwhdl.cxx (revision 63bba73c)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "shadwhdl.hxx"
27cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
28cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir // --
31cdf0e10cSrcweir #include <com/sun/star/table/ShadowFormat.hpp>
32cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
33cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using ::rtl::OUString;
36cdf0e10cSrcweir using ::rtl::OUStringBuffer;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using namespace ::com::sun::star;
39cdf0e10cSrcweir using namespace ::xmloff::token;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
42cdf0e10cSrcweir //
43cdf0e10cSrcweir // class XMLMeasurePropHdl
44cdf0e10cSrcweir //
45cdf0e10cSrcweir 
~XMLShadowPropHdl()46cdf0e10cSrcweir XMLShadowPropHdl::~XMLShadowPropHdl()
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	// nothing to do
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const51cdf0e10cSrcweir sal_Bool XMLShadowPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
54cdf0e10cSrcweir 	table::ShadowFormat aShadow;
55cdf0e10cSrcweir 	aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	sal_Bool bColorFound = sal_False;
58cdf0e10cSrcweir 	sal_Bool bOffsetFound = sal_False;
59cdf0e10cSrcweir 	SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
60cdf0e10cSrcweir 	Color aColor( 128,128, 128 );
61cdf0e10cSrcweir 	OUString aToken;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	while( aTokenEnum.getNextToken( aToken ) )
64cdf0e10cSrcweir 	{
65cdf0e10cSrcweir 		if( IsXMLToken( aToken, XML_NONE ) )
66cdf0e10cSrcweir 		{
67cdf0e10cSrcweir 			aShadow.Location = table::ShadowLocation_NONE;
68cdf0e10cSrcweir 			bRet = sal_True;
69cdf0e10cSrcweir 			break;
70cdf0e10cSrcweir 		}
71cdf0e10cSrcweir 		else if( !bColorFound && aToken.compareToAscii( "#", 1 ) == 0 )
72cdf0e10cSrcweir 		{
73cdf0e10cSrcweir 			bRet = rUnitConverter.convertColor( aColor, aToken );
74cdf0e10cSrcweir 			if( !bRet )
75cdf0e10cSrcweir 				return sal_False;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 			bColorFound = sal_True;
78cdf0e10cSrcweir 		}
79cdf0e10cSrcweir 		else if( !bOffsetFound )
80cdf0e10cSrcweir 		{
81cdf0e10cSrcweir 			sal_Int32 nX = 0, nY = 0;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 			bRet = rUnitConverter.convertMeasure( nX, aToken );
84cdf0e10cSrcweir 			if( bRet && aTokenEnum.getNextToken( aToken ) )
85cdf0e10cSrcweir 				bRet = rUnitConverter.convertMeasure( nY, aToken );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 			if( bRet )
88cdf0e10cSrcweir 			{
89cdf0e10cSrcweir 				if( nX < 0 )
90cdf0e10cSrcweir 				{
91cdf0e10cSrcweir 					if( nY < 0 )
92cdf0e10cSrcweir 						aShadow.Location = table::ShadowLocation_TOP_LEFT;
93cdf0e10cSrcweir 					else
94cdf0e10cSrcweir 						aShadow.Location = table::ShadowLocation_BOTTOM_LEFT;
95cdf0e10cSrcweir 				}
96cdf0e10cSrcweir 				else
97cdf0e10cSrcweir 				{
98cdf0e10cSrcweir 					if( nY < 0 )
99cdf0e10cSrcweir 						aShadow.Location = table::ShadowLocation_TOP_RIGHT;
100cdf0e10cSrcweir 					else
101cdf0e10cSrcweir 						aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
102cdf0e10cSrcweir 				}
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 				if( nX < 0 ) nX *= -1;
105cdf0e10cSrcweir 				if( nY < 0 ) nY *= -1;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 				aShadow.ShadowWidth = sal::static_int_cast< sal_Int16 >(
108cdf0e10cSrcweir                     (nX + nY) >> 1);
109cdf0e10cSrcweir 			}
110cdf0e10cSrcweir 		}
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	if( bRet && ( bColorFound || bOffsetFound ) )
114cdf0e10cSrcweir 	{
115cdf0e10cSrcweir 		aShadow.IsTransparent = aColor.GetTransparency() > 0;
116cdf0e10cSrcweir 		aShadow.Color = aColor.GetColor();
117cdf0e10cSrcweir 		bRet = sal_True;
118cdf0e10cSrcweir 	}
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	rValue <<= aShadow;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	return bRet;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const125cdf0e10cSrcweir sal_Bool XMLShadowPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
128cdf0e10cSrcweir   	OUStringBuffer aOut;
129cdf0e10cSrcweir 	table::ShadowFormat aShadow;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	if( rValue >>= aShadow )
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 		sal_Int32 nX = 1, nY = 1;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 		switch( aShadow.Location )
136cdf0e10cSrcweir 		{
137cdf0e10cSrcweir 			case table::ShadowLocation_TOP_LEFT:
138cdf0e10cSrcweir 				nX = -1;
139cdf0e10cSrcweir 				nY = -1;
140cdf0e10cSrcweir 				break;
141cdf0e10cSrcweir 			case table::ShadowLocation_TOP_RIGHT:
142cdf0e10cSrcweir 				nY = -1;
143cdf0e10cSrcweir 				break;
144cdf0e10cSrcweir 			case table::ShadowLocation_BOTTOM_LEFT:
145cdf0e10cSrcweir 				nX = -1;
146cdf0e10cSrcweir 				break;
147cdf0e10cSrcweir 			case table::ShadowLocation_BOTTOM_RIGHT:
148cdf0e10cSrcweir 				break;
149cdf0e10cSrcweir 			case table::ShadowLocation_NONE:
150cdf0e10cSrcweir 			default:
151cdf0e10cSrcweir 				rStrExpValue = GetXMLToken(XML_NONE);
152cdf0e10cSrcweir 				return sal_True;
153cdf0e10cSrcweir 		}
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 		nX *= aShadow.ShadowWidth;
156cdf0e10cSrcweir 		nY *= aShadow.ShadowWidth;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 		rUnitConverter.convertColor( aOut, aShadow.Color );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 		aOut.append( sal_Unicode(' ') );
161cdf0e10cSrcweir 		rUnitConverter.convertMeasure( aOut, nX );
162cdf0e10cSrcweir 		aOut.append( sal_Unicode(' ') );
163cdf0e10cSrcweir 		rUnitConverter.convertMeasure( aOut, nY );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 		rStrExpValue = aOut.makeStringAndClear();
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 		bRet = sal_True;
168cdf0e10cSrcweir 	}
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	return bRet;
171cdf0e10cSrcweir }
172