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