bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / cdouthdl.cxx
blobc2443007d613103248838a233b64fabf84308654
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>
24 #include <osl/diagnose.h>
26 #include <com/sun/star/awt/FontStrikeout.hpp>
27 #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 // class XMLCrossedOutTypePropHdl
77 XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl()
79 // nothing to do
82 bool XMLCrossedOutTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
84 sal_uInt16 eNewStrikeout;
85 bool bRet = SvXMLUnitConverter::convertEnum(
86 eNewStrikeout, rStrImpValue, pXML_CrossedoutType_Enum );
87 if( bRet )
89 // multi property: style and width might be set already.
90 // If the old value is NONE, the new is used unchanged.
91 sal_Int16 eStrikeout = sal_Int16();
92 if( (rValue >>= eStrikeout) && awt::FontStrikeout::NONE!=eStrikeout )
94 switch( eNewStrikeout )
96 case awt::FontStrikeout::NONE:
97 case awt::FontStrikeout::SINGLE:
98 // keep existing line style
99 eNewStrikeout = eStrikeout;
100 break;
101 case awt::FontStrikeout::DOUBLE:
102 // A double line style has priority over a solid or a bold
103 // line style,
104 // but not about any other line style
105 switch( eStrikeout )
107 case awt::FontStrikeout::SINGLE:
108 case awt::FontStrikeout::BOLD:
109 break;
110 default:
111 // If a double line style is not supported for the existing
112 // value, keep the new one
113 eNewStrikeout = eStrikeout;
114 break;
116 break;
117 default:
118 OSL_ENSURE( bRet, "unexpected line type value" );
119 break;
121 if( eNewStrikeout != eStrikeout )
122 rValue <<= (sal_Int16)eNewStrikeout;
124 else
126 rValue <<= (sal_Int16)eNewStrikeout;
130 return bRet;
133 bool XMLCrossedOutTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
135 bool bRet = false;
136 sal_Int16 nValue = sal_Int16();
137 OUStringBuffer aOut;
139 if (rValue >>= nValue)
141 bRet = SvXMLUnitConverter::convertEnum(
142 aOut, (sal_uInt16)nValue, pXML_CrossedoutType_Enum );
143 if( bRet )
144 rStrExpValue = aOut.makeStringAndClear();
147 return bRet;
150 // class XMLCrossedOutStylePropHdl
152 XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl()
154 // nothing to do
157 bool XMLCrossedOutStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
159 sal_uInt16 eNewStrikeout;
160 bool bRet = SvXMLUnitConverter::convertEnum(
161 eNewStrikeout, rStrImpValue, pXML_CrossedoutStyle_Enum );
162 if( bRet )
164 // multi property: style and width might be set already.
165 // If the old value is NONE, the new is used unchanged.
166 sal_Int16 eStrikeout = sal_Int16();
167 if( (rValue >>= eStrikeout) && awt::FontStrikeout::NONE!=eStrikeout )
169 // one NONE a SINGLE are possible new values. For both, the
170 // existing value is kept.
172 else
174 rValue <<= (sal_Int16)eNewStrikeout;
178 return bRet;
181 bool XMLCrossedOutStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
183 bool bRet = false;
184 sal_Int16 nValue = sal_Int16();
185 OUStringBuffer aOut;
187 if( rValue >>= nValue )
189 bRet = SvXMLUnitConverter::convertEnum(
190 aOut, (sal_uInt16)nValue, pXML_CrossedoutStyle_Enum );
191 if( bRet )
192 rStrExpValue = aOut.makeStringAndClear();
195 return bRet;
198 // class XMLCrossedOutWidthPropHdl
200 XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl()
202 // nothing to do
205 bool XMLCrossedOutWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
207 sal_uInt16 eNewStrikeout;
208 bool bRet = SvXMLUnitConverter::convertEnum(
209 eNewStrikeout, rStrImpValue, pXML_CrossedoutWidth_Enum );
210 if( bRet )
212 // multi property: style and width might be set already.
213 // If the old value is NONE, the new is used unchanged.
214 sal_Int16 eStrikeout = sal_Int16();
215 if( (rValue >>= eStrikeout) && awt::FontStrikeout::NONE!=eStrikeout )
217 switch( eNewStrikeout )
219 case awt::FontStrikeout::NONE:
220 // keep existing line style
221 eNewStrikeout = eStrikeout;
222 break;
223 case awt::FontStrikeout::BOLD:
224 switch( eStrikeout )
226 case awt::FontStrikeout::SINGLE:
227 break;
228 default:
229 // If a double line style is not supported for the existing
230 // value, keep the new one
231 eNewStrikeout = eStrikeout;
232 break;
234 break;
235 default:
236 OSL_ENSURE( bRet, "unexpected line type value" );
237 break;
239 if( eNewStrikeout != eStrikeout )
240 rValue <<= (sal_Int16)eNewStrikeout;
242 else
244 rValue <<= (sal_Int16)eNewStrikeout;
248 return bRet;
251 bool XMLCrossedOutWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
253 bool bRet = false;
254 sal_Int16 nValue = sal_Int16();
255 OUStringBuffer aOut;
257 if( (rValue >>= nValue) && (awt::FontStrikeout::BOLD == nValue) )
259 bRet = SvXMLUnitConverter::convertEnum(
260 aOut, (sal_uInt16)nValue, pXML_CrossedoutWidth_Enum );
261 if( bRet )
262 rStrExpValue = aOut.makeStringAndClear();
265 return bRet;
268 // class XMLCrossedOutTextPropHdl
270 XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl()
272 // nothing to do
275 bool XMLCrossedOutTextPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
277 bool bRet = false;
279 if( !rStrImpValue.isEmpty() )
281 sal_Int16 eStrikeout = ('/' == rStrImpValue[0]
282 ? awt::FontStrikeout::SLASH
283 : awt::FontStrikeout::X);
284 rValue <<= (sal_Int16)eStrikeout;
285 bRet = true;
288 return bRet;
291 bool XMLCrossedOutTextPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
293 bool bRet = false;
294 sal_Int16 nValue = sal_Int16();
296 if( (rValue >>= nValue) &&
297 (awt::FontStrikeout::SLASH == nValue || awt::FontStrikeout::X == nValue) )
299 rStrExpValue = OUString(
300 static_cast< sal_Unicode>( awt::FontStrikeout::SLASH == nValue ? '/'
301 : 'X' ) );
302 bRet = true;
305 return bRet;
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */