cid#1640468 Dereference after null check
[LibreOffice.git] / xmloff / source / style / cdouthdl.cxx
blob0b484dcf047a9dc9f1efc3bab64ab97ee5432849
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 <xmloff/xmlement.hxx>
24 #include <rtl/ustrbuf.hxx>
25 #include <osl/diagnose.h>
27 #include <com/sun/star/awt/FontStrikeout.hpp>
28 #include <com/sun/star/uno/Any.hxx>
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::awt;
32 using namespace ::xmloff::token;
34 SvXMLEnumMapEntry<sal_uInt16> const pXML_CrossedoutType_Enum[] =
36 { XML_NONE, awt::FontStrikeout::NONE },
37 { XML_SINGLE, awt::FontStrikeout::SINGLE },
38 { XML_DOUBLE, awt::FontStrikeout::DOUBLE },
39 { XML_SINGLE, awt::FontStrikeout::BOLD },
40 { XML_SINGLE, awt::FontStrikeout::SLASH },
41 { XML_SINGLE, awt::FontStrikeout::X },
42 { XML_TOKEN_INVALID, 0 }
45 SvXMLEnumMapEntry<sal_uInt16> const pXML_CrossedoutStyle_Enum[] =
47 { XML_NONE, awt::FontStrikeout::NONE },
48 { XML_SOLID, awt::FontStrikeout::SINGLE },
49 { XML_SOLID, awt::FontStrikeout::DOUBLE },
50 { XML_SOLID, awt::FontStrikeout::BOLD },
51 { XML_SOLID, awt::FontStrikeout::SLASH },
52 { XML_SOLID, awt::FontStrikeout::X },
53 { XML_DOTTED, awt::FontStrikeout::SINGLE },
54 { XML_DASH, awt::FontStrikeout::SINGLE },
55 { XML_LONG_DASH, awt::FontStrikeout::SINGLE },
56 { XML_DOT_DASH, awt::FontStrikeout::SINGLE },
57 { XML_DOT_DOT_DASH, awt::FontStrikeout::SINGLE },
58 { XML_WAVE, awt::FontStrikeout::SINGLE },
59 { XML_TOKEN_INVALID, 0 }
62 SvXMLEnumMapEntry<sal_uInt16> const pXML_CrossedoutWidth_Enum[] =
64 { XML_AUTO, awt::FontStrikeout::NONE },
65 { XML_AUTO, awt::FontStrikeout::SINGLE },
66 { XML_AUTO, awt::FontStrikeout::DOUBLE },
67 { XML_BOLD, awt::FontStrikeout::BOLD },
68 { XML_AUTO, awt::FontStrikeout::SLASH },
69 { XML_AUTO, awt::FontStrikeout::X },
70 { XML_THIN, awt::FontStrikeout::NONE },
71 { XML_MEDIUM, awt::FontStrikeout::NONE },
72 { XML_THICK, awt::FontStrikeout::NONE },
73 { XML_TOKEN_INVALID, 0 }
77 XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl()
79 // nothing to do
82 bool XMLCrossedOutTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
84 sal_uInt16 eNewStrikeout = 0;
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 <<= static_cast<sal_Int16>(eNewStrikeout);
124 else
126 rValue <<= static_cast<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_uInt16 nValue = sal_uInt16();
138 if (rValue >>= nValue)
140 OUStringBuffer aOut;
141 bRet = SvXMLUnitConverter::convertEnum(
142 aOut, nValue, pXML_CrossedoutType_Enum );
143 if( bRet )
144 rStrExpValue = aOut.makeStringAndClear();
147 return bRet;
151 XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl()
153 // nothing to do
156 bool XMLCrossedOutStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
158 sal_uInt16 eNewStrikeout(0);
159 bool bRet = SvXMLUnitConverter::convertEnum(
160 eNewStrikeout, rStrImpValue, pXML_CrossedoutStyle_Enum );
161 if( bRet )
163 // multi property: style and width might be set already.
164 // If the old value is NONE, the new is used unchanged.
165 sal_Int16 eStrikeout = sal_Int16();
166 if( (rValue >>= eStrikeout) && awt::FontStrikeout::NONE!=eStrikeout )
168 // one NONE a SINGLE are possible new values. For both, the
169 // existing value is kept.
171 else
173 rValue <<= static_cast<sal_Int16>(eNewStrikeout);
177 return bRet;
180 bool XMLCrossedOutStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
182 bool bRet = false;
183 sal_uInt16 nValue = sal_uInt16();
185 if( rValue >>= nValue )
187 OUStringBuffer aOut;
188 bRet = SvXMLUnitConverter::convertEnum(
189 aOut, nValue, pXML_CrossedoutStyle_Enum );
190 if( bRet )
191 rStrExpValue = aOut.makeStringAndClear();
194 return bRet;
198 XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl()
200 // nothing to do
203 bool XMLCrossedOutWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
205 sal_uInt16 eNewStrikeout = 0;
206 bool bRet = SvXMLUnitConverter::convertEnum(
207 eNewStrikeout, rStrImpValue, pXML_CrossedoutWidth_Enum );
208 if( bRet )
210 // multi property: style and width might be set already.
211 // If the old value is NONE, the new is used unchanged.
212 sal_Int16 eStrikeout = sal_Int16();
213 if( (rValue >>= eStrikeout) && awt::FontStrikeout::NONE!=eStrikeout )
215 switch( eNewStrikeout )
217 case awt::FontStrikeout::NONE:
218 // keep existing line style
219 eNewStrikeout = eStrikeout;
220 break;
221 case awt::FontStrikeout::BOLD:
222 switch( eStrikeout )
224 case awt::FontStrikeout::SINGLE:
225 break;
226 default:
227 // If a double line style is not supported for the existing
228 // value, keep the new one
229 eNewStrikeout = eStrikeout;
230 break;
232 break;
233 default:
234 OSL_ENSURE( bRet, "unexpected line type value" );
235 break;
237 if( eNewStrikeout != eStrikeout )
238 rValue <<= static_cast<sal_Int16>(eNewStrikeout);
240 else
242 rValue <<= static_cast<sal_Int16>(eNewStrikeout);
246 return bRet;
249 bool XMLCrossedOutWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
251 bool bRet = false;
252 sal_uInt16 nValue = sal_uInt16();
254 if( (rValue >>= nValue) && (awt::FontStrikeout::BOLD == nValue) )
256 OUStringBuffer aOut;
257 bRet = SvXMLUnitConverter::convertEnum(
258 aOut, nValue, pXML_CrossedoutWidth_Enum );
259 if( bRet )
260 rStrExpValue = aOut.makeStringAndClear();
263 return bRet;
267 XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl()
269 // nothing to do
272 bool XMLCrossedOutTextPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
274 bool bRet = false;
276 if( !rStrImpValue.isEmpty() )
278 sal_Int16 eStrikeout = ('/' == rStrImpValue[0]
279 ? awt::FontStrikeout::SLASH
280 : awt::FontStrikeout::X);
281 rValue <<= eStrikeout;
282 bRet = true;
285 return bRet;
288 bool XMLCrossedOutTextPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
290 bool bRet = false;
291 sal_Int16 nValue = sal_Int16();
293 if( (rValue >>= nValue) &&
294 (awt::FontStrikeout::SLASH == nValue || awt::FontStrikeout::X == nValue) )
296 rStrExpValue = OUString(
297 static_cast< sal_Unicode>( awt::FontStrikeout::SLASH == nValue ? '/'
298 : 'X' ) );
299 bRet = true;
302 return bRet;
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */