bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / undlihdl.cxx
blob2832d113519a9ed035341ff5443ce9175bc4a5bd
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 <undlihdl.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/uno/Any.hxx>
27 #include <com/sun/star/awt/FontUnderline.hpp>
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::awt;
31 using namespace ::xmloff::token;
33 SvXMLEnumMapEntry const pXML_UnderlineType_Enum[] =
35 { XML_NONE, awt::FontUnderline::NONE },
36 { XML_SINGLE, awt::FontUnderline::SINGLE },
37 { XML_DOUBLE, awt::FontUnderline::DOUBLE },
38 { XML_SINGLE, awt::FontUnderline::DOTTED },
39 { XML_SINGLE, awt::FontUnderline::DASH },
40 { XML_SINGLE, awt::FontUnderline::LONGDASH },
41 { XML_SINGLE, awt::FontUnderline::DASHDOT },
42 { XML_SINGLE, awt::FontUnderline::DASHDOTDOT },
43 { XML_SINGLE, awt::FontUnderline::WAVE },
44 { XML_SINGLE, awt::FontUnderline::BOLD },
45 { XML_SINGLE, awt::FontUnderline::BOLDDOTTED },
46 { XML_SINGLE, awt::FontUnderline::BOLDDASH },
47 { XML_SINGLE, awt::FontUnderline::BOLDLONGDASH },
48 { XML_SINGLE, awt::FontUnderline::BOLDDASHDOT },
49 { XML_SINGLE, awt::FontUnderline::BOLDDASHDOTDOT },
50 { XML_SINGLE, awt::FontUnderline::BOLDWAVE },
51 { XML_DOUBLE, awt::FontUnderline::DOUBLEWAVE },
52 { XML_SINGLE, awt::FontUnderline::SMALLWAVE },
53 { XML_TOKEN_INVALID, 0 }
56 SvXMLEnumMapEntry const pXML_UnderlineStyle_Enum[] =
58 { XML_NONE, awt::FontUnderline::NONE },
59 { XML_SOLID, awt::FontUnderline::SINGLE },
60 { XML_SOLID, awt::FontUnderline::DOUBLE },
61 { XML_DOTTED, awt::FontUnderline::DOTTED },
62 { XML_DASH, awt::FontUnderline::DASH },
63 { XML_LONG_DASH, awt::FontUnderline::LONGDASH },
64 { XML_DOT_DASH, awt::FontUnderline::DASHDOT },
65 { XML_DOT_DOT_DASH, awt::FontUnderline::DASHDOTDOT },
66 { XML_WAVE, awt::FontUnderline::WAVE },
67 { XML_SOLID, awt::FontUnderline::BOLD },
68 { XML_DOTTED, awt::FontUnderline::BOLDDOTTED },
69 { XML_DASH, awt::FontUnderline::BOLDDASH },
70 { XML_LONG_DASH, awt::FontUnderline::BOLDLONGDASH },
71 { XML_DOT_DASH, awt::FontUnderline::BOLDDASHDOT },
72 { XML_DOT_DOT_DASH, awt::FontUnderline::BOLDDASHDOTDOT },
73 { XML_WAVE, awt::FontUnderline::BOLDWAVE },
74 { XML_WAVE, awt::FontUnderline::DOUBLEWAVE },
75 { XML_SMALL_WAVE, awt::FontUnderline::SMALLWAVE },
76 { XML_TOKEN_INVALID, 0 }
79 SvXMLEnumMapEntry const pXML_UnderlineWidth_Enum[] =
81 { XML_AUTO, awt::FontUnderline::NONE },
82 { XML_AUTO, awt::FontUnderline::SINGLE },
83 { XML_AUTO, awt::FontUnderline::DOUBLE },
84 { XML_AUTO, awt::FontUnderline::DOTTED },
85 { XML_AUTO, awt::FontUnderline::DASH },
86 { XML_AUTO, awt::FontUnderline::LONGDASH },
87 { XML_AUTO, awt::FontUnderline::DASHDOT },
88 { XML_AUTO, awt::FontUnderline::DASHDOTDOT },
89 { XML_AUTO, awt::FontUnderline::WAVE },
90 { XML_BOLD, awt::FontUnderline::BOLD },
91 { XML_BOLD, awt::FontUnderline::BOLDDOTTED },
92 { XML_BOLD, awt::FontUnderline::BOLDDASH },
93 { XML_BOLD, awt::FontUnderline::BOLDLONGDASH },
94 { XML_BOLD, awt::FontUnderline::BOLDDASHDOT },
95 { XML_BOLD, awt::FontUnderline::BOLDDASHDOTDOT },
96 { XML_BOLD, awt::FontUnderline::BOLDWAVE },
97 { XML_AUTO, awt::FontUnderline::DOUBLEWAVE },
98 { XML_THIN, awt::FontUnderline::NONE },
99 { XML_MEDIUM, awt::FontUnderline::NONE },
100 { XML_THICK, awt::FontUnderline::BOLD},
101 { XML_TOKEN_INVALID, 0 }
105 // class XMLUnderlineTypePropHdl
108 XMLUnderlineTypePropHdl::~XMLUnderlineTypePropHdl()
110 // nothing to do
113 bool XMLUnderlineTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
115 sal_uInt16 eNewUnderline;
116 bool bRet = SvXMLUnitConverter::convertEnum(
117 eNewUnderline, rStrImpValue, pXML_UnderlineType_Enum );
118 if( bRet )
120 // multi property: style and width might be set already.
121 // If the old value is NONE, the new is used unchanged.
122 sal_Int16 eUnderline = sal_Int16();
123 if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline )
125 switch( eNewUnderline )
127 case awt::FontUnderline::NONE:
128 case awt::FontUnderline::SINGLE:
129 // keep existing line style
130 eNewUnderline = eUnderline;
131 break;
132 case awt::FontUnderline::DOUBLE:
133 // A double line style has priority over a bold line style,
134 // but not over the line style itself.
135 switch( eUnderline )
137 case awt::FontUnderline::SINGLE:
138 case awt::FontUnderline::BOLD:
139 break;
140 case awt::FontUnderline::WAVE:
141 case awt::FontUnderline::BOLDWAVE:
142 eNewUnderline = awt::FontUnderline::DOUBLEWAVE;
143 break;
144 default:
145 // If a double line style is not supported for the existing
146 // value, keep the new one
147 eNewUnderline = eUnderline;
148 break;
150 break;
151 default:
152 OSL_ENSURE( bRet, "unexpected line type value" );
153 break;
155 if( eNewUnderline != eUnderline )
156 rValue <<= (sal_Int16)eNewUnderline;
158 else
160 rValue <<= (sal_Int16)eNewUnderline;
164 return bRet;
167 bool XMLUnderlineTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
169 bool bRet = false;
170 sal_Int16 nValue = sal_Int16();
171 OUStringBuffer aOut;
173 if( (rValue >>= nValue) &&
174 (awt::FontUnderline::DOUBLE == nValue ||
175 awt::FontUnderline::DOUBLEWAVE == nValue) )
177 bRet = SvXMLUnitConverter::convertEnum(
178 aOut, (sal_uInt16)nValue, pXML_UnderlineType_Enum );
179 if( bRet )
180 rStrExpValue = aOut.makeStringAndClear();
183 return bRet;
187 // class XMLUnderlineStylePropHdl
190 XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl()
192 // nothing to do
195 bool XMLUnderlineStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
197 sal_uInt16 eNewUnderline;
198 bool bRet = SvXMLUnitConverter::convertEnum(
199 eNewUnderline, rStrImpValue, pXML_UnderlineStyle_Enum );
200 if( bRet )
202 // multi property: style and width might be set already.
203 // If the old value is NONE, the new is used unchanged.
204 sal_Int16 eUnderline = sal_Int16();
205 if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline )
207 switch( eNewUnderline )
209 case awt::FontUnderline::NONE:
210 case awt::FontUnderline::SINGLE:
211 // keep double or bold line style
212 eNewUnderline = eUnderline;
213 break;
214 case awt::FontUnderline::DOTTED:
215 // The line style has priority over a double type.
216 if( awt::FontUnderline::BOLD == eUnderline )
217 eNewUnderline = awt::FontUnderline::BOLDDOTTED;
218 break;
219 case awt::FontUnderline::DASH:
220 if( awt::FontUnderline::BOLD == eUnderline )
221 eNewUnderline = awt::FontUnderline::BOLDDASH;
222 break;
223 case awt::FontUnderline::LONGDASH:
224 if( awt::FontUnderline::BOLD == eUnderline )
225 eNewUnderline = awt::FontUnderline::BOLDLONGDASH;
226 break;
227 case awt::FontUnderline::DASHDOT:
228 if( awt::FontUnderline::BOLD == eUnderline )
229 eNewUnderline = awt::FontUnderline::BOLDDASHDOT;
230 break;
231 case awt::FontUnderline::DASHDOTDOT:
232 if( awt::FontUnderline::BOLD == eUnderline )
233 eNewUnderline = awt::FontUnderline::BOLDDASHDOTDOT;
234 break;
235 case awt::FontUnderline::WAVE:
236 if( awt::FontUnderline::DOUBLE == eUnderline )
237 eNewUnderline = awt::FontUnderline::DOUBLEWAVE;
238 else if( awt::FontUnderline::BOLD == eUnderline )
239 eNewUnderline = awt::FontUnderline::BOLDWAVE;
240 break;
241 case awt::FontUnderline::SMALLWAVE:
242 // SMALLWAVE is not used
243 default:
244 OSL_ENSURE( bRet, "unexpected line style value" );
245 break;
247 if( eNewUnderline != eUnderline )
248 rValue <<= (sal_Int16)eNewUnderline;
250 else
252 rValue <<= (sal_Int16)eNewUnderline;
256 return bRet;
259 bool XMLUnderlineStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
261 bool bRet = false;
262 sal_Int16 nValue = sal_Int16();
263 OUStringBuffer aOut;
265 if( rValue >>= nValue )
267 bRet = SvXMLUnitConverter::convertEnum(
268 aOut, (sal_uInt16)nValue, pXML_UnderlineStyle_Enum );
269 if( bRet )
270 rStrExpValue = aOut.makeStringAndClear();
273 return bRet;
277 // class XMLUnderlineWidthPropHdl
280 XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl()
282 // nothing to do
285 bool XMLUnderlineWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
287 sal_uInt16 eNewUnderline;
288 bool bRet = SvXMLUnitConverter::convertEnum(
289 eNewUnderline, rStrImpValue, pXML_UnderlineWidth_Enum );
290 if( bRet )
292 // multi property: style and width might be set already.
293 // If the old value is NONE, the new is used unchanged.
294 sal_Int16 eUnderline = sal_Int16();
295 if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline )
297 switch( eNewUnderline )
299 case awt::FontUnderline::NONE:
300 // keep existing line style
301 eNewUnderline = eUnderline;
302 break;
303 case awt::FontUnderline::BOLD:
304 // A double line style has priority over a bold line style,
305 // but not over the line style itself.
306 switch( eUnderline )
308 case awt::FontUnderline::SINGLE:
309 break;
310 case awt::FontUnderline::DOTTED:
311 eNewUnderline = awt::FontUnderline::BOLDDOTTED;
312 break;
313 case awt::FontUnderline::DASH:
314 eNewUnderline = awt::FontUnderline::BOLDDASH;
315 break;
316 case awt::FontUnderline::LONGDASH:
317 eNewUnderline = awt::FontUnderline::BOLDLONGDASH;
318 break;
319 case awt::FontUnderline::DASHDOT:
320 eNewUnderline = awt::FontUnderline::BOLDDASHDOT;
321 break;
322 case awt::FontUnderline::DASHDOTDOT:
323 eNewUnderline = awt::FontUnderline::BOLDDASHDOTDOT;
324 break;
325 case awt::FontUnderline::WAVE:
326 eNewUnderline = awt::FontUnderline::BOLDWAVE;
327 break;
328 default:
329 // a doube line style overwrites a bold one
330 eNewUnderline = eUnderline;
331 break;
333 break;
334 default:
335 OSL_ENSURE( bRet, "unexpected line width value" );
336 break;
338 if( eNewUnderline != eUnderline )
339 rValue <<= (sal_Int16)eNewUnderline;
341 else
343 rValue <<= (sal_Int16)eNewUnderline;
347 return bRet;
350 bool XMLUnderlineWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
352 bool bRet = false;
353 sal_Int16 nValue = sal_Int16();
354 OUStringBuffer aOut;
356 if( (rValue >>= nValue) && (awt::FontUnderline::NONE != nValue) )
358 bRet = SvXMLUnitConverter::convertEnum(
359 aOut, (sal_uInt16)nValue, pXML_UnderlineWidth_Enum );
360 if( bRet )
361 rStrExpValue = aOut.makeStringAndClear();
364 return bRet;
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */