bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / style / undlihdl.cxx
blobb238491958de4e8c01f15f45e6bba72de88fff34
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>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <com/sun/star/awt/FontUnderline.hpp>
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::awt;
32 using namespace ::xmloff::token;
34 SvXMLEnumMapEntry const pXML_UnderlineType_Enum[] =
36 { XML_NONE, awt::FontUnderline::NONE },
37 { XML_SINGLE, awt::FontUnderline::SINGLE },
38 { XML_DOUBLE, awt::FontUnderline::DOUBLE },
39 { XML_SINGLE, awt::FontUnderline::DOTTED },
40 { XML_SINGLE, awt::FontUnderline::DASH },
41 { XML_SINGLE, awt::FontUnderline::LONGDASH },
42 { XML_SINGLE, awt::FontUnderline::DASHDOT },
43 { XML_SINGLE, awt::FontUnderline::DASHDOTDOT },
44 { XML_SINGLE, awt::FontUnderline::WAVE },
45 { XML_SINGLE, awt::FontUnderline::BOLD },
46 { XML_SINGLE, awt::FontUnderline::BOLDDOTTED },
47 { XML_SINGLE, awt::FontUnderline::BOLDDASH },
48 { XML_SINGLE, awt::FontUnderline::BOLDLONGDASH },
49 { XML_SINGLE, awt::FontUnderline::BOLDDASHDOT },
50 { XML_SINGLE, awt::FontUnderline::BOLDDASHDOTDOT },
51 { XML_SINGLE, awt::FontUnderline::BOLDWAVE },
52 { XML_DOUBLE, awt::FontUnderline::DOUBLEWAVE },
53 { XML_SINGLE, awt::FontUnderline::SMALLWAVE },
54 { XML_TOKEN_INVALID, 0 }
57 SvXMLEnumMapEntry const pXML_UnderlineStyle_Enum[] =
59 { XML_NONE, awt::FontUnderline::NONE },
60 { XML_SOLID, awt::FontUnderline::SINGLE },
61 { XML_SOLID, awt::FontUnderline::DOUBLE },
62 { XML_DOTTED, awt::FontUnderline::DOTTED },
63 { XML_DASH, awt::FontUnderline::DASH },
64 { XML_LONG_DASH, awt::FontUnderline::LONGDASH },
65 { XML_DOT_DASH, awt::FontUnderline::DASHDOT },
66 { XML_DOT_DOT_DASH, awt::FontUnderline::DASHDOTDOT },
67 { XML_WAVE, awt::FontUnderline::WAVE },
68 { XML_SOLID, awt::FontUnderline::BOLD },
69 { XML_DOTTED, awt::FontUnderline::BOLDDOTTED },
70 { XML_DASH, awt::FontUnderline::BOLDDASH },
71 { XML_LONG_DASH, awt::FontUnderline::BOLDLONGDASH },
72 { XML_DOT_DASH, awt::FontUnderline::BOLDDASHDOT },
73 { XML_DOT_DOT_DASH, awt::FontUnderline::BOLDDASHDOTDOT },
74 { XML_WAVE, awt::FontUnderline::BOLDWAVE },
75 { XML_WAVE, awt::FontUnderline::DOUBLEWAVE },
76 { XML_SMALL_WAVE, awt::FontUnderline::SMALLWAVE },
77 { XML_TOKEN_INVALID, 0 }
80 SvXMLEnumMapEntry const pXML_UnderlineWidth_Enum[] =
82 { XML_AUTO, awt::FontUnderline::NONE },
83 { XML_AUTO, awt::FontUnderline::SINGLE },
84 { XML_AUTO, awt::FontUnderline::DOUBLE },
85 { XML_AUTO, awt::FontUnderline::DOTTED },
86 { XML_AUTO, awt::FontUnderline::DASH },
87 { XML_AUTO, awt::FontUnderline::LONGDASH },
88 { XML_AUTO, awt::FontUnderline::DASHDOT },
89 { XML_AUTO, awt::FontUnderline::DASHDOTDOT },
90 { XML_AUTO, awt::FontUnderline::WAVE },
91 { XML_BOLD, awt::FontUnderline::BOLD },
92 { XML_BOLD, awt::FontUnderline::BOLDDOTTED },
93 { XML_BOLD, awt::FontUnderline::BOLDDASH },
94 { XML_BOLD, awt::FontUnderline::BOLDLONGDASH },
95 { XML_BOLD, awt::FontUnderline::BOLDDASHDOT },
96 { XML_BOLD, awt::FontUnderline::BOLDDASHDOTDOT },
97 { XML_BOLD, awt::FontUnderline::BOLDWAVE },
98 { XML_AUTO, awt::FontUnderline::DOUBLEWAVE },
99 { XML_THIN, awt::FontUnderline::NONE },
100 { XML_MEDIUM, awt::FontUnderline::NONE },
101 { XML_THICK, awt::FontUnderline::BOLD},
102 { XML_TOKEN_INVALID, 0 }
107 ///////////////////////////////////////////////////////////////////////////////
109 // class XMLUnderlineTypePropHdl
112 XMLUnderlineTypePropHdl::~XMLUnderlineTypePropHdl()
114 // nothing to do
117 sal_Bool XMLUnderlineTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
119 sal_uInt16 eNewUnderline;
120 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
121 eNewUnderline, rStrImpValue, pXML_UnderlineType_Enum );
122 if( bRet )
124 // multi property: style and width might be set already.
125 // If the old value is NONE, the new is used unchanged.
126 sal_Int16 eUnderline = sal_Int16();
127 if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline )
129 switch( eNewUnderline )
131 case awt::FontUnderline::NONE:
132 case awt::FontUnderline::SINGLE:
133 // keep existing line style
134 eNewUnderline = eUnderline;
135 break;
136 case awt::FontUnderline::DOUBLE:
137 // A double line style has priority over a bold line style,
138 // but not over the line style itself.
139 switch( eUnderline )
141 case awt::FontUnderline::SINGLE:
142 case awt::FontUnderline::BOLD:
143 break;
144 case awt::FontUnderline::WAVE:
145 case awt::FontUnderline::BOLDWAVE:
146 eNewUnderline = awt::FontUnderline::DOUBLEWAVE;
147 break;
148 default:
149 // If a double line style is not supported for the existing
150 // value, keep the new one
151 eNewUnderline = eUnderline;
152 break;
154 break;
155 default:
156 OSL_ENSURE( bRet, "unexpected line type value" );
157 break;
159 if( eNewUnderline != eUnderline )
160 rValue <<= (sal_Int16)eNewUnderline;
162 else
164 rValue <<= (sal_Int16)eNewUnderline;
168 return bRet;
171 sal_Bool XMLUnderlineTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
173 sal_Bool bRet = sal_False;
174 sal_Int16 nValue = sal_Int16();
175 OUStringBuffer aOut;
177 if( (rValue >>= nValue) &&
178 (awt::FontUnderline::DOUBLE == nValue ||
179 awt::FontUnderline::DOUBLEWAVE == nValue) )
181 bRet = SvXMLUnitConverter::convertEnum(
182 aOut, (sal_uInt16)nValue, pXML_UnderlineType_Enum );
183 if( bRet )
184 rStrExpValue = aOut.makeStringAndClear();
187 return bRet;
190 ///////////////////////////////////////////////////////////////////////////////
192 // class XMLUnderlineStylePropHdl
195 XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl()
197 // nothing to do
200 sal_Bool XMLUnderlineStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
202 sal_uInt16 eNewUnderline;
203 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
204 eNewUnderline, rStrImpValue, pXML_UnderlineStyle_Enum );
205 if( bRet )
207 // multi property: style and width might be set already.
208 // If the old value is NONE, the new is used unchanged.
209 sal_Int16 eUnderline = sal_Int16();
210 if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline )
212 switch( eNewUnderline )
214 case awt::FontUnderline::NONE:
215 case awt::FontUnderline::SINGLE:
216 // keep double or bold line style
217 eNewUnderline = eUnderline;
218 case awt::FontUnderline::DOTTED:
219 // The line style has priority over a double type.
220 if( awt::FontUnderline::BOLD == eUnderline )
221 eNewUnderline = awt::FontUnderline::BOLDDOTTED;
222 break;
223 case awt::FontUnderline::DASH:
224 if( awt::FontUnderline::BOLD == eUnderline )
225 eNewUnderline = awt::FontUnderline::BOLDDASH;
226 break;
227 case awt::FontUnderline::LONGDASH:
228 if( awt::FontUnderline::BOLD == eUnderline )
229 eNewUnderline = awt::FontUnderline::BOLDLONGDASH;
230 break;
231 case awt::FontUnderline::DASHDOT:
232 if( awt::FontUnderline::BOLD == eUnderline )
233 eNewUnderline = awt::FontUnderline::BOLDDASHDOT;
234 break;
235 case awt::FontUnderline::DASHDOTDOT:
236 if( awt::FontUnderline::BOLD == eUnderline )
237 eNewUnderline = awt::FontUnderline::BOLDDASHDOTDOT;
238 break;
239 case awt::FontUnderline::WAVE:
240 if( awt::FontUnderline::BOLD == eUnderline )
241 eNewUnderline = awt::FontUnderline::BOLDWAVE;
242 break;
243 case awt::FontUnderline::SMALLWAVE:
244 // SMALLWAVE is not used
245 default:
246 OSL_ENSURE( bRet, "unexpected line style value" );
247 break;
249 if( eNewUnderline != eUnderline )
250 rValue <<= (sal_Int16)eNewUnderline;
252 else
254 rValue <<= (sal_Int16)eNewUnderline;
258 return bRet;
261 sal_Bool XMLUnderlineStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
263 sal_Bool bRet = sal_False;
264 sal_Int16 nValue = sal_Int16();
265 OUStringBuffer aOut;
267 if( rValue >>= nValue )
269 bRet = SvXMLUnitConverter::convertEnum(
270 aOut, (sal_uInt16)nValue, pXML_UnderlineStyle_Enum );
271 if( bRet )
272 rStrExpValue = aOut.makeStringAndClear();
275 return bRet;
278 ///////////////////////////////////////////////////////////////////////////////
280 // class XMLUnderlineWidthPropHdl
283 XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl()
285 // nothing to do
288 sal_Bool XMLUnderlineWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
290 sal_uInt16 eNewUnderline;
291 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
292 eNewUnderline, rStrImpValue, pXML_UnderlineWidth_Enum );
293 if( bRet )
295 // multi property: style and width might be set already.
296 // If the old value is NONE, the new is used unchanged.
297 sal_Int16 eUnderline = sal_Int16();
298 if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline )
300 switch( eNewUnderline )
302 case awt::FontUnderline::NONE:
303 // keep existing line style
304 eNewUnderline = eUnderline;
305 break;
306 case awt::FontUnderline::BOLD:
307 // A double line style has priority over a bold line style,
308 // but not over the line style itself.
309 switch( eUnderline )
311 case awt::FontUnderline::SINGLE:
312 break;
313 case awt::FontUnderline::DOTTED:
314 eNewUnderline = awt::FontUnderline::BOLDDOTTED;
315 break;
316 case awt::FontUnderline::DASH:
317 eNewUnderline = awt::FontUnderline::BOLDDASH;
318 break;
319 case awt::FontUnderline::LONGDASH:
320 eNewUnderline = awt::FontUnderline::BOLDLONGDASH;
321 break;
322 case awt::FontUnderline::DASHDOT:
323 eNewUnderline = awt::FontUnderline::BOLDDASHDOT;
324 break;
325 case awt::FontUnderline::DASHDOTDOT:
326 eNewUnderline = awt::FontUnderline::BOLDDASHDOTDOT;
327 break;
328 case awt::FontUnderline::WAVE:
329 eNewUnderline = awt::FontUnderline::BOLDWAVE;
330 break;
331 default:
332 // a doube line style overwrites a bold one
333 eNewUnderline = eUnderline;
334 break;
336 break;
337 default:
338 OSL_ENSURE( bRet, "unexpected line width value" );
339 break;
341 if( eNewUnderline != eUnderline )
342 rValue <<= (sal_Int16)eNewUnderline;
344 else
346 rValue <<= (sal_Int16)eNewUnderline;
350 return bRet;
353 sal_Bool XMLUnderlineWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
355 sal_Bool bRet = sal_False;
356 sal_Int16 nValue = sal_Int16();
357 OUStringBuffer aOut;
359 if( (rValue >>= nValue) && (awt::FontUnderline::NONE != nValue) )
361 bRet = SvXMLUnitConverter::convertEnum(
362 aOut, (sal_uInt16)nValue, pXML_UnderlineWidth_Enum );
363 if( bRet )
364 rStrExpValue = aOut.makeStringAndClear();
367 return bRet;
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */