xref: /trunk/main/xmloff/source/style/cdouthdl.cxx (revision 63bba73c)
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 <cdouthdl.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <rtl/ustrbuf.hxx>
30 
31 #include <com/sun/star/awt/FontStrikeout.hpp>
32 #include <com/sun/star/uno/Any.hxx>
33 
34 using ::rtl::OUString;
35 using ::rtl::OUStringBuffer;
36 
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::awt;
39 using namespace ::xmloff::token;
40 
41 SvXMLEnumMapEntry pXML_CrossedoutType_Enum[] =
42 {
43 	{ XML_NONE,					FontStrikeout::NONE },
44 	{ XML_SINGLE,	FontStrikeout::SINGLE },
45 	{ XML_DOUBLE,				FontStrikeout::DOUBLE },
46 	{ XML_SINGLE,    FontStrikeout::BOLD },
47 	{ XML_SINGLE,    FontStrikeout::SLASH },
48 	{ XML_SINGLE,    FontStrikeout::X },
49 	{ XML_TOKEN_INVALID,				0 }
50 };
51 
52 SvXMLEnumMapEntry pXML_CrossedoutStyle_Enum[] =
53 {
54 	{ XML_NONE,							FontStrikeout::NONE },
55 	{ XML_SOLID,						FontStrikeout::SINGLE },
56 	{ XML_SOLID,						FontStrikeout::DOUBLE },
57 	{ XML_SOLID,			    		FontStrikeout::BOLD },
58 	{ XML_SOLID,			    		FontStrikeout::SLASH },
59 	{ XML_SOLID,			    		FontStrikeout::X },
60 	{ XML_DOTTED,		        FontStrikeout::SINGLE },
61 	{ XML_DASH,				FontStrikeout::SINGLE },
62 	{ XML_LONG_DASH,			FontStrikeout::SINGLE },
63 	{ XML_DOT_DASH,			FontStrikeout::SINGLE },
64 	{ XML_DOT_DOT_DASH,		FontStrikeout::SINGLE },
65 	{ XML_WAVE,				FontStrikeout::SINGLE },
66 	{ XML_TOKEN_INVALID,				0 }
67 };
68 
69 SvXMLEnumMapEntry pXML_CrossedoutWidth_Enum[] =
70 {
71 	{ XML_AUTO,					FontStrikeout::NONE },
72 	{ XML_AUTO,					FontStrikeout::SINGLE },
73 	{ XML_AUTO,					FontStrikeout::DOUBLE },
74 	{ XML_BOLD,	    FontStrikeout::BOLD },
75 	{ XML_AUTO,	    			FontStrikeout::SLASH },
76 	{ XML_AUTO,	    			FontStrikeout::X },
77 	{ XML_THIN,	    			FontStrikeout::NONE },
78 	{ XML_MEDIUM,	    		FontStrikeout::NONE },
79 	{ XML_THICK,	    		FontStrikeout::NONE },
80 	{ XML_TOKEN_INVALID,				0 }
81 };
82 
83 ///////////////////////////////////////////////////////////////////////////////
84 //
85 // class XMLCrossedOutTypePropHdl
86 //
87 
~XMLCrossedOutTypePropHdl()88 XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl()
89 {
90 	// nothing to do
91 }
92 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const93 sal_Bool XMLCrossedOutTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
94 {
95 	sal_uInt16 eNewStrikeout;
96 	sal_Bool bRet = SvXMLUnitConverter::convertEnum(
97         eNewStrikeout, rStrImpValue, pXML_CrossedoutType_Enum );
98 	if( bRet )
99 	{
100 		// multi property: style and width might be set already.
101 		// If the old value is NONE, the new is used unchanged.
102 		sal_Int16 eStrikeout = sal_Int16();
103 		if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout )
104 		{
105 			switch( eNewStrikeout )
106 			{
107 			case FontStrikeout::NONE:
108 			case FontStrikeout::SINGLE:
109 				// keep existing line style
110 				eNewStrikeout = eStrikeout;
111 				break;
112 			case FontStrikeout::DOUBLE:
113 				// A double line style has priority over a solid or a bold
114 				// line style,
115 				// but not about any other line style
116 				switch( eStrikeout )
117 				{
118 				case FontStrikeout::SINGLE:
119 				case FontStrikeout::BOLD:
120 					break;
121 				default:
122 					// If a double line style is not supported for the existing
123 					// value, keep the new one
124 					eNewStrikeout = eStrikeout;
125 					break;
126 				}
127 				break;
128 			default:
129 				OSL_ENSURE( bRet, "unexpected line type value" );
130 				break;
131 			}
132 			if( eNewStrikeout != eStrikeout )
133 				rValue <<= (sal_Int16)eNewStrikeout;
134 		}
135 		else
136 		{
137 			rValue <<= (sal_Int16)eNewStrikeout;
138 		}
139 	}
140 
141 	return bRet;
142 }
143 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const144 sal_Bool XMLCrossedOutTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
145 {
146 	sal_Bool bRet = sal_False;
147 	sal_Int16 nValue = sal_Int16();
148 	OUStringBuffer aOut;
149 
150 	if( (rValue >>= nValue) && FontStrikeout::DOUBLE==nValue )
151 	{
152         bRet = SvXMLUnitConverter::convertEnum(
153             aOut, (sal_uInt16)nValue, pXML_CrossedoutType_Enum );
154 		if( bRet )
155 			rStrExpValue = aOut.makeStringAndClear();
156 	}
157 
158 	return bRet;
159 }
160 
161 ///////////////////////////////////////////////////////////////////////////////
162 //
163 // class XMLCrossedOutStylePropHdl
164 //
165 
~XMLCrossedOutStylePropHdl()166 XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl()
167 {
168 	// nothing to do
169 }
170 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const171 sal_Bool XMLCrossedOutStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
172 {
173 	sal_uInt16 eNewStrikeout;
174 	sal_Bool bRet = SvXMLUnitConverter::convertEnum(
175         eNewStrikeout, rStrImpValue, pXML_CrossedoutStyle_Enum );
176 	if( bRet )
177 	{
178 		// multi property: style and width might be set already.
179 		// If the old value is NONE, the new is used unchanged.
180 		sal_Int16 eStrikeout = sal_Int16();
181 		if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout )
182 		{
183 			// one NONE a SINGLE are possible new values. For both, the
184 			// existing value is kept.
185 		}
186 		else
187 		{
188 			rValue <<= (sal_Int16)eNewStrikeout;
189 		}
190 	}
191 
192 	return bRet;
193 }
194 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const195 sal_Bool XMLCrossedOutStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
196 {
197 	sal_Bool bRet = sal_False;
198 	sal_Int16 nValue = sal_Int16();
199 	OUStringBuffer aOut;
200 
201 	if( rValue >>= nValue )
202 	{
203         bRet = SvXMLUnitConverter::convertEnum(
204             aOut, (sal_uInt16)nValue, pXML_CrossedoutStyle_Enum );
205 		if( bRet )
206 			rStrExpValue = aOut.makeStringAndClear();
207 	}
208 
209 	return bRet;
210 }
211 
212 ///////////////////////////////////////////////////////////////////////////////
213 //
214 // class XMLCrossedOutWidthPropHdl
215 //
216 
~XMLCrossedOutWidthPropHdl()217 XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl()
218 {
219 	// nothing to do
220 }
221 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const222 sal_Bool XMLCrossedOutWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
223 {
224 	sal_uInt16 eNewStrikeout;
225 	sal_Bool bRet = SvXMLUnitConverter::convertEnum(
226         eNewStrikeout, rStrImpValue, pXML_CrossedoutWidth_Enum );
227 	if( bRet )
228 	{
229 		// multi property: style and width might be set already.
230 		// If the old value is NONE, the new is used unchanged.
231 		sal_Int16 eStrikeout = sal_Int16();
232 		if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout )
233 		{
234 			switch( eNewStrikeout )
235 			{
236 			case FontStrikeout::NONE:
237 				// keep existing line style
238 				eNewStrikeout = eStrikeout;
239 				break;
240 			case FontStrikeout::BOLD:
241 				switch( eStrikeout )
242 				{
243 				case FontStrikeout::SINGLE:
244 					break;
245 				default:
246 					// If a double line style is not supported for the existing
247 					// value, keep the new one
248 					eNewStrikeout = eStrikeout;
249 					break;
250 				}
251 			default:
252 				OSL_ENSURE( bRet, "unexpected line type value" );
253 				break;
254 			}
255 			if( eNewStrikeout != eStrikeout )
256 				rValue <<= (sal_Int16)eNewStrikeout;
257 		}
258 		else
259 		{
260 			rValue <<= (sal_Int16)eNewStrikeout;
261 		}
262 	}
263 
264 	return bRet;
265 }
266 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const267 sal_Bool XMLCrossedOutWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
268 {
269 	sal_Bool bRet = sal_False;
270 	sal_Int16 nValue = sal_Int16();
271 	OUStringBuffer aOut;
272 
273 	if( (rValue >>= nValue) && (FontStrikeout::BOLD == nValue) )
274 	{
275         bRet = SvXMLUnitConverter::convertEnum(
276             aOut, (sal_uInt16)nValue, pXML_CrossedoutWidth_Enum );
277 		if( bRet )
278 			rStrExpValue = aOut.makeStringAndClear();
279 	}
280 
281 	return bRet;
282 }
283 
284 ///////////////////////////////////////////////////////////////////////////////
285 //
286 // class XMLCrossedOutTextPropHdl
287 //
288 
~XMLCrossedOutTextPropHdl()289 XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl()
290 {
291 	// nothing to do
292 }
293 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const294 sal_Bool XMLCrossedOutTextPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
295 {
296 	sal_Bool bRet = sal_False;
297 
298 	if( rStrImpValue.getLength() )
299 	{
300 		sal_Int16 eStrikeout = ('/' == rStrImpValue[0]
301 										? FontStrikeout::SLASH
302 										: FontStrikeout::X);
303 		rValue <<= (sal_Int16)eStrikeout;
304 		bRet = sal_True;
305 	}
306 
307 	return bRet;
308 }
309 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const310 sal_Bool XMLCrossedOutTextPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
311 {
312 	sal_Bool bRet = sal_False;
313 	sal_Int16 nValue = sal_Int16();
314 
315 	if( (rValue >>= nValue) &&
316 		(FontStrikeout::SLASH == nValue || FontStrikeout::X == nValue) )
317 	{
318 		rStrExpValue = OUString::valueOf(
319 			static_cast< sal_Unicode>( FontStrikeout::SLASH == nValue ? '/'
320 																	  : 'X' ) );
321 		bRet = sal_True;
322 	}
323 
324 	return bRet;
325 }
326 
327