xref: /trunk/main/xmloff/source/style/cdouthdl.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include <cdouthdl.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <rtl/ustrbuf.hxx>
34 
35 #include <com/sun/star/awt/FontStrikeout.hpp>
36 #include <com/sun/star/uno/Any.hxx>
37 
38 using ::rtl::OUString;
39 using ::rtl::OUStringBuffer;
40 
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::awt;
43 using namespace ::xmloff::token;
44 
45 SvXMLEnumMapEntry pXML_CrossedoutType_Enum[] =
46 {
47 	{ XML_NONE,					FontStrikeout::NONE },
48 	{ XML_SINGLE,	FontStrikeout::SINGLE },
49 	{ XML_DOUBLE,				FontStrikeout::DOUBLE },
50 	{ XML_SINGLE,    FontStrikeout::BOLD },
51 	{ XML_SINGLE,    FontStrikeout::SLASH },
52 	{ XML_SINGLE,    FontStrikeout::X },
53 	{ XML_TOKEN_INVALID,				0 }
54 };
55 
56 SvXMLEnumMapEntry pXML_CrossedoutStyle_Enum[] =
57 {
58 	{ XML_NONE,							FontStrikeout::NONE },
59 	{ XML_SOLID,						FontStrikeout::SINGLE },
60 	{ XML_SOLID,						FontStrikeout::DOUBLE },
61 	{ XML_SOLID,			    		FontStrikeout::BOLD },
62 	{ XML_SOLID,			    		FontStrikeout::SLASH },
63 	{ XML_SOLID,			    		FontStrikeout::X },
64 	{ XML_DOTTED,		        FontStrikeout::SINGLE },
65 	{ XML_DASH,				FontStrikeout::SINGLE },
66 	{ XML_LONG_DASH,			FontStrikeout::SINGLE },
67 	{ XML_DOT_DASH,			FontStrikeout::SINGLE },
68 	{ XML_DOT_DOT_DASH,		FontStrikeout::SINGLE },
69 	{ XML_WAVE,				FontStrikeout::SINGLE },
70 	{ XML_TOKEN_INVALID,				0 }
71 };
72 
73 SvXMLEnumMapEntry pXML_CrossedoutWidth_Enum[] =
74 {
75 	{ XML_AUTO,					FontStrikeout::NONE },
76 	{ XML_AUTO,					FontStrikeout::SINGLE },
77 	{ XML_AUTO,					FontStrikeout::DOUBLE },
78 	{ XML_BOLD,	    FontStrikeout::BOLD },
79 	{ XML_AUTO,	    			FontStrikeout::SLASH },
80 	{ XML_AUTO,	    			FontStrikeout::X },
81 	{ XML_THIN,	    			FontStrikeout::NONE },
82 	{ XML_MEDIUM,	    		FontStrikeout::NONE },
83 	{ XML_THICK,	    		FontStrikeout::NONE },
84 	{ XML_TOKEN_INVALID,				0 }
85 };
86 
87 ///////////////////////////////////////////////////////////////////////////////
88 //
89 // class XMLCrossedOutTypePropHdl
90 //
91 
92 XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl()
93 {
94 	// nothing to do
95 }
96 
97 sal_Bool XMLCrossedOutTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
98 {
99 	sal_uInt16 eNewStrikeout;
100 	sal_Bool bRet = SvXMLUnitConverter::convertEnum(
101         eNewStrikeout, rStrImpValue, pXML_CrossedoutType_Enum );
102 	if( bRet )
103 	{
104 		// multi property: style and width might be set already.
105 		// If the old value is NONE, the new is used unchanged.
106 		sal_Int16 eStrikeout = sal_Int16();
107 		if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout )
108 		{
109 			switch( eNewStrikeout )
110 			{
111 			case FontStrikeout::NONE:
112 			case FontStrikeout::SINGLE:
113 				// keep existing line style
114 				eNewStrikeout = eStrikeout;
115 				break;
116 			case FontStrikeout::DOUBLE:
117 				// A double line style has priority over a solid or a bold
118 				// line style,
119 				// but not about any other line style
120 				switch( eStrikeout )
121 				{
122 				case FontStrikeout::SINGLE:
123 				case FontStrikeout::BOLD:
124 					break;
125 				default:
126 					// If a double line style is not supported for the existing
127 					// value, keep the new one
128 					eNewStrikeout = eStrikeout;
129 					break;
130 				}
131 				break;
132 			default:
133 				OSL_ENSURE( bRet, "unexpected line type value" );
134 				break;
135 			}
136 			if( eNewStrikeout != eStrikeout )
137 				rValue <<= (sal_Int16)eNewStrikeout;
138 		}
139 		else
140 		{
141 			rValue <<= (sal_Int16)eNewStrikeout;
142 		}
143 	}
144 
145 	return bRet;
146 }
147 
148 sal_Bool XMLCrossedOutTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
149 {
150 	sal_Bool bRet = sal_False;
151 	sal_Int16 nValue = sal_Int16();
152 	OUStringBuffer aOut;
153 
154 	if( (rValue >>= nValue) && FontStrikeout::DOUBLE==nValue )
155 	{
156         bRet = SvXMLUnitConverter::convertEnum(
157             aOut, (sal_uInt16)nValue, pXML_CrossedoutType_Enum );
158 		if( bRet )
159 			rStrExpValue = aOut.makeStringAndClear();
160 	}
161 
162 	return bRet;
163 }
164 
165 ///////////////////////////////////////////////////////////////////////////////
166 //
167 // class XMLCrossedOutStylePropHdl
168 //
169 
170 XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl()
171 {
172 	// nothing to do
173 }
174 
175 sal_Bool XMLCrossedOutStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
176 {
177 	sal_uInt16 eNewStrikeout;
178 	sal_Bool bRet = SvXMLUnitConverter::convertEnum(
179         eNewStrikeout, rStrImpValue, pXML_CrossedoutStyle_Enum );
180 	if( bRet )
181 	{
182 		// multi property: style and width might be set already.
183 		// If the old value is NONE, the new is used unchanged.
184 		sal_Int16 eStrikeout = sal_Int16();
185 		if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout )
186 		{
187 			// one NONE a SINGLE are possible new values. For both, the
188 			// existing value is kept.
189 		}
190 		else
191 		{
192 			rValue <<= (sal_Int16)eNewStrikeout;
193 		}
194 	}
195 
196 	return bRet;
197 }
198 
199 sal_Bool XMLCrossedOutStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
200 {
201 	sal_Bool bRet = sal_False;
202 	sal_Int16 nValue = sal_Int16();
203 	OUStringBuffer aOut;
204 
205 	if( rValue >>= nValue )
206 	{
207         bRet = SvXMLUnitConverter::convertEnum(
208             aOut, (sal_uInt16)nValue, pXML_CrossedoutStyle_Enum );
209 		if( bRet )
210 			rStrExpValue = aOut.makeStringAndClear();
211 	}
212 
213 	return bRet;
214 }
215 
216 ///////////////////////////////////////////////////////////////////////////////
217 //
218 // class XMLCrossedOutWidthPropHdl
219 //
220 
221 XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl()
222 {
223 	// nothing to do
224 }
225 
226 sal_Bool XMLCrossedOutWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
227 {
228 	sal_uInt16 eNewStrikeout;
229 	sal_Bool bRet = SvXMLUnitConverter::convertEnum(
230         eNewStrikeout, rStrImpValue, pXML_CrossedoutWidth_Enum );
231 	if( bRet )
232 	{
233 		// multi property: style and width might be set already.
234 		// If the old value is NONE, the new is used unchanged.
235 		sal_Int16 eStrikeout = sal_Int16();
236 		if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout )
237 		{
238 			switch( eNewStrikeout )
239 			{
240 			case FontStrikeout::NONE:
241 				// keep existing line style
242 				eNewStrikeout = eStrikeout;
243 				break;
244 			case FontStrikeout::BOLD:
245 				switch( eStrikeout )
246 				{
247 				case FontStrikeout::SINGLE:
248 					break;
249 				default:
250 					// If a double line style is not supported for the existing
251 					// value, keep the new one
252 					eNewStrikeout = eStrikeout;
253 					break;
254 				}
255 			default:
256 				OSL_ENSURE( bRet, "unexpected line type value" );
257 				break;
258 			}
259 			if( eNewStrikeout != eStrikeout )
260 				rValue <<= (sal_Int16)eNewStrikeout;
261 		}
262 		else
263 		{
264 			rValue <<= (sal_Int16)eNewStrikeout;
265 		}
266 	}
267 
268 	return bRet;
269 }
270 
271 sal_Bool XMLCrossedOutWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
272 {
273 	sal_Bool bRet = sal_False;
274 	sal_Int16 nValue = sal_Int16();
275 	OUStringBuffer aOut;
276 
277 	if( (rValue >>= nValue) && (FontStrikeout::BOLD == nValue) )
278 	{
279         bRet = SvXMLUnitConverter::convertEnum(
280             aOut, (sal_uInt16)nValue, pXML_CrossedoutWidth_Enum );
281 		if( bRet )
282 			rStrExpValue = aOut.makeStringAndClear();
283 	}
284 
285 	return bRet;
286 }
287 
288 ///////////////////////////////////////////////////////////////////////////////
289 //
290 // class XMLCrossedOutTextPropHdl
291 //
292 
293 XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl()
294 {
295 	// nothing to do
296 }
297 
298 sal_Bool XMLCrossedOutTextPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
299 {
300 	sal_Bool bRet = sal_False;
301 
302 	if( rStrImpValue.getLength() )
303 	{
304 		sal_Int16 eStrikeout = ('/' == rStrImpValue[0]
305 										? FontStrikeout::SLASH
306 										: FontStrikeout::X);
307 		rValue <<= (sal_Int16)eStrikeout;
308 		bRet = sal_True;
309 	}
310 
311 	return bRet;
312 }
313 
314 sal_Bool XMLCrossedOutTextPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
315 {
316 	sal_Bool bRet = sal_False;
317 	sal_Int16 nValue = sal_Int16();
318 
319 	if( (rValue >>= nValue) &&
320 		(FontStrikeout::SLASH == nValue || FontStrikeout::X == nValue) )
321 	{
322 		rStrExpValue = OUString::valueOf(
323 			static_cast< sal_Unicode>( FontStrikeout::SLASH == nValue ? '/'
324 																	  : 'X' ) );
325 		bRet = sal_True;
326 	}
327 
328 	return bRet;
329 }
330 
331