bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / style / cdouthdl.cxx
blobc92b30b04016bcba6264bf8393d1f6188ec88ddc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cdouthdl.hxx>
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmluconv.hxx>
23 #include <rtl/ustrbuf.hxx>
25 #include <com/sun/star/awt/FontStrikeout.hpp>
26 #include <com/sun/star/uno/Any.hxx>
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::awt;
31 using namespace ::xmloff::token;
33 SvXMLEnumMapEntry pXML_CrossedoutType_Enum[] =
35 { XML_NONE, awt::FontStrikeout::NONE },
36 { XML_SINGLE, awt::FontStrikeout::SINGLE },
37 { XML_DOUBLE, awt::FontStrikeout::DOUBLE },
38 { XML_SINGLE, awt::FontStrikeout::BOLD },
39 { XML_SINGLE, awt::FontStrikeout::SLASH },
40 { XML_SINGLE, awt::FontStrikeout::X },
41 { XML_TOKEN_INVALID, 0 }
44 SvXMLEnumMapEntry pXML_CrossedoutStyle_Enum[] =
46 { XML_NONE, awt::FontStrikeout::NONE },
47 { XML_SOLID, awt::FontStrikeout::SINGLE },
48 { XML_SOLID, awt::FontStrikeout::DOUBLE },
49 { XML_SOLID, awt::FontStrikeout::BOLD },
50 { XML_SOLID, awt::FontStrikeout::SLASH },
51 { XML_SOLID, awt::FontStrikeout::X },
52 { XML_DOTTED, awt::FontStrikeout::SINGLE },
53 { XML_DASH, awt::FontStrikeout::SINGLE },
54 { XML_LONG_DASH, awt::FontStrikeout::SINGLE },
55 { XML_DOT_DASH, awt::FontStrikeout::SINGLE },
56 { XML_DOT_DOT_DASH, awt::FontStrikeout::SINGLE },
57 { XML_WAVE, awt::FontStrikeout::SINGLE },
58 { XML_TOKEN_INVALID, 0 }
61 SvXMLEnumMapEntry pXML_CrossedoutWidth_Enum[] =
63 { XML_AUTO, awt::FontStrikeout::NONE },
64 { XML_AUTO, awt::FontStrikeout::SINGLE },
65 { XML_AUTO, awt::FontStrikeout::DOUBLE },
66 { XML_BOLD, awt::FontStrikeout::BOLD },
67 { XML_AUTO, awt::FontStrikeout::SLASH },
68 { XML_AUTO, awt::FontStrikeout::X },
69 { XML_THIN, awt::FontStrikeout::NONE },
70 { XML_MEDIUM, awt::FontStrikeout::NONE },
71 { XML_THICK, awt::FontStrikeout::NONE },
72 { XML_TOKEN_INVALID, 0 }
75 ///////////////////////////////////////////////////////////////////////////////
77 // class XMLCrossedOutTypePropHdl
80 XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl()
82 // nothing to do
85 sal_Bool XMLCrossedOutTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
87 sal_uInt16 eNewStrikeout;
88 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
89 eNewStrikeout, rStrImpValue, pXML_CrossedoutType_Enum );
90 if( bRet )
92 // multi property: style and width might be set already.
93 // If the old value is NONE, the new is used unchanged.
94 sal_Int16 eStrikeout = sal_Int16();
95 if( (rValue >>= eStrikeout) && awt::FontStrikeout::NONE!=eStrikeout )
97 switch( eNewStrikeout )
99 case awt::FontStrikeout::NONE:
100 case awt::FontStrikeout::SINGLE:
101 // keep existing line style
102 eNewStrikeout = eStrikeout;
103 break;
104 case awt::FontStrikeout::DOUBLE:
105 // A double line style has priority over a solid or a bold
106 // line style,
107 // but not about any other line style
108 switch( eStrikeout )
110 case awt::FontStrikeout::SINGLE:
111 case awt::FontStrikeout::BOLD:
112 break;
113 default:
114 // If a double line style is not supported for the existing
115 // value, keep the new one
116 eNewStrikeout = eStrikeout;
117 break;
119 break;
120 default:
121 OSL_ENSURE( bRet, "unexpected line type value" );
122 break;
124 if( eNewStrikeout != eStrikeout )
125 rValue <<= (sal_Int16)eNewStrikeout;
127 else
129 rValue <<= (sal_Int16)eNewStrikeout;
133 return bRet;
136 sal_Bool XMLCrossedOutTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
138 sal_Bool bRet = sal_False;
139 sal_Int16 nValue = sal_Int16();
140 OUStringBuffer aOut;
142 if( (rValue >>= nValue) && awt::FontStrikeout::DOUBLE==nValue )
144 bRet = SvXMLUnitConverter::convertEnum(
145 aOut, (sal_uInt16)nValue, pXML_CrossedoutType_Enum );
146 if( bRet )
147 rStrExpValue = aOut.makeStringAndClear();
150 return bRet;
153 ///////////////////////////////////////////////////////////////////////////////
155 // class XMLCrossedOutStylePropHdl
158 XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl()
160 // nothing to do
163 sal_Bool XMLCrossedOutStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
165 sal_uInt16 eNewStrikeout;
166 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
167 eNewStrikeout, rStrImpValue, pXML_CrossedoutStyle_Enum );
168 if( bRet )
170 // multi property: style and width might be set already.
171 // If the old value is NONE, the new is used unchanged.
172 sal_Int16 eStrikeout = sal_Int16();
173 if( (rValue >>= eStrikeout) && awt::FontStrikeout::NONE!=eStrikeout )
175 // one NONE a SINGLE are possible new values. For both, the
176 // existing value is kept.
178 else
180 rValue <<= (sal_Int16)eNewStrikeout;
184 return bRet;
187 sal_Bool XMLCrossedOutStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
189 sal_Bool bRet = sal_False;
190 sal_Int16 nValue = sal_Int16();
191 OUStringBuffer aOut;
193 if( rValue >>= nValue )
195 bRet = SvXMLUnitConverter::convertEnum(
196 aOut, (sal_uInt16)nValue, pXML_CrossedoutStyle_Enum );
197 if( bRet )
198 rStrExpValue = aOut.makeStringAndClear();
201 return bRet;
204 ///////////////////////////////////////////////////////////////////////////////
206 // class XMLCrossedOutWidthPropHdl
209 XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl()
211 // nothing to do
214 sal_Bool XMLCrossedOutWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
216 sal_uInt16 eNewStrikeout;
217 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
218 eNewStrikeout, rStrImpValue, pXML_CrossedoutWidth_Enum );
219 if( bRet )
221 // multi property: style and width might be set already.
222 // If the old value is NONE, the new is used unchanged.
223 sal_Int16 eStrikeout = sal_Int16();
224 if( (rValue >>= eStrikeout) && awt::FontStrikeout::NONE!=eStrikeout )
226 switch( eNewStrikeout )
228 case awt::FontStrikeout::NONE:
229 // keep existing line style
230 eNewStrikeout = eStrikeout;
231 break;
232 case awt::FontStrikeout::BOLD:
233 switch( eStrikeout )
235 case awt::FontStrikeout::SINGLE:
236 break;
237 default:
238 // If a double line style is not supported for the existing
239 // value, keep the new one
240 eNewStrikeout = eStrikeout;
241 break;
243 default:
244 OSL_ENSURE( bRet, "unexpected line type value" );
245 break;
247 if( eNewStrikeout != eStrikeout )
248 rValue <<= (sal_Int16)eNewStrikeout;
250 else
252 rValue <<= (sal_Int16)eNewStrikeout;
256 return bRet;
259 sal_Bool XMLCrossedOutWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
261 sal_Bool bRet = sal_False;
262 sal_Int16 nValue = sal_Int16();
263 OUStringBuffer aOut;
265 if( (rValue >>= nValue) && (awt::FontStrikeout::BOLD == nValue) )
267 bRet = SvXMLUnitConverter::convertEnum(
268 aOut, (sal_uInt16)nValue, pXML_CrossedoutWidth_Enum );
269 if( bRet )
270 rStrExpValue = aOut.makeStringAndClear();
273 return bRet;
276 ///////////////////////////////////////////////////////////////////////////////
278 // class XMLCrossedOutTextPropHdl
281 XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl()
283 // nothing to do
286 sal_Bool XMLCrossedOutTextPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
288 sal_Bool bRet = sal_False;
290 if( !rStrImpValue.isEmpty() )
292 sal_Int16 eStrikeout = ('/' == rStrImpValue[0]
293 ? awt::FontStrikeout::SLASH
294 : awt::FontStrikeout::X);
295 rValue <<= (sal_Int16)eStrikeout;
296 bRet = sal_True;
299 return bRet;
302 sal_Bool XMLCrossedOutTextPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
304 sal_Bool bRet = sal_False;
305 sal_Int16 nValue = sal_Int16();
307 if( (rValue >>= nValue) &&
308 (awt::FontStrikeout::SLASH == nValue || awt::FontStrikeout::X == nValue) )
310 rStrExpValue = OUString::valueOf(
311 static_cast< sal_Unicode>( awt::FontStrikeout::SLASH == nValue ? '/'
312 : 'X' ) );
313 bRet = sal_True;
316 return bRet;
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */