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