Bump for 3.6-28
[LibreOffice.git] / xmloff / source / style / undlihdl.cxx
blobdd7183d88e45cc63ff19454874a26b85d42ff07d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <undlihdl.hxx>
30 #include <xmloff/xmltoken.hxx>
31 #include <xmloff/xmluconv.hxx>
32 #include <rtl/ustrbuf.hxx>
35 #include <com/sun/star/uno/Any.hxx>
36 #include <com/sun/star/awt/FontUnderline.hpp>
38 using ::rtl::OUString;
39 using ::rtl::OUStringBuffer;
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::awt;
43 using namespace ::xmloff::token;
45 SvXMLEnumMapEntry const pXML_UnderlineType_Enum[] =
47 { XML_NONE, FontUnderline::NONE },
48 { XML_SINGLE, FontUnderline::SINGLE },
49 { XML_DOUBLE, FontUnderline::DOUBLE },
50 { XML_SINGLE, FontUnderline::DOTTED },
51 { XML_SINGLE, FontUnderline::DASH },
52 { XML_SINGLE, FontUnderline::LONGDASH },
53 { XML_SINGLE, FontUnderline::DASHDOT },
54 { XML_SINGLE, FontUnderline::DASHDOTDOT },
55 { XML_SINGLE, FontUnderline::WAVE },
56 { XML_SINGLE, FontUnderline::BOLD },
57 { XML_SINGLE, FontUnderline::BOLDDOTTED },
58 { XML_SINGLE, FontUnderline::BOLDDASH },
59 { XML_SINGLE, FontUnderline::BOLDLONGDASH },
60 { XML_SINGLE, FontUnderline::BOLDDASHDOT },
61 { XML_SINGLE, FontUnderline::BOLDDASHDOTDOT },
62 { XML_SINGLE, FontUnderline::BOLDWAVE },
63 { XML_DOUBLE, FontUnderline::DOUBLEWAVE },
64 { XML_SINGLE, FontUnderline::SMALLWAVE },
65 { XML_TOKEN_INVALID, 0 }
68 SvXMLEnumMapEntry const pXML_UnderlineStyle_Enum[] =
70 { XML_NONE, FontUnderline::NONE },
71 { XML_SOLID, FontUnderline::SINGLE },
72 { XML_SOLID, FontUnderline::DOUBLE },
73 { XML_DOTTED, FontUnderline::DOTTED },
74 { XML_DASH, FontUnderline::DASH },
75 { XML_LONG_DASH, FontUnderline::LONGDASH },
76 { XML_DOT_DASH, FontUnderline::DASHDOT },
77 { XML_DOT_DOT_DASH, FontUnderline::DASHDOTDOT },
78 { XML_WAVE, FontUnderline::WAVE },
79 { XML_SOLID, FontUnderline::BOLD },
80 { XML_DOTTED, FontUnderline::BOLDDOTTED },
81 { XML_DASH, FontUnderline::BOLDDASH },
82 { XML_LONG_DASH, FontUnderline::BOLDLONGDASH },
83 { XML_DOT_DASH, FontUnderline::BOLDDASHDOT },
84 { XML_DOT_DOT_DASH, FontUnderline::BOLDDASHDOTDOT },
85 { XML_WAVE, FontUnderline::BOLDWAVE },
86 { XML_WAVE, FontUnderline::DOUBLEWAVE },
87 { XML_SMALL_WAVE, FontUnderline::SMALLWAVE },
88 { XML_TOKEN_INVALID, 0 }
91 SvXMLEnumMapEntry const pXML_UnderlineWidth_Enum[] =
93 { XML_AUTO, FontUnderline::NONE },
94 { XML_AUTO, FontUnderline::SINGLE },
95 { XML_AUTO, FontUnderline::DOUBLE },
96 { XML_AUTO, FontUnderline::DOTTED },
97 { XML_AUTO, FontUnderline::DASH },
98 { XML_AUTO, FontUnderline::LONGDASH },
99 { XML_AUTO, FontUnderline::DASHDOT },
100 { XML_AUTO, FontUnderline::DASHDOTDOT },
101 { XML_AUTO, FontUnderline::WAVE },
102 { XML_BOLD, FontUnderline::BOLD },
103 { XML_BOLD, FontUnderline::BOLDDOTTED },
104 { XML_BOLD, FontUnderline::BOLDDASH },
105 { XML_BOLD, FontUnderline::BOLDLONGDASH },
106 { XML_BOLD, FontUnderline::BOLDDASHDOT },
107 { XML_BOLD, FontUnderline::BOLDDASHDOTDOT },
108 { XML_BOLD, FontUnderline::BOLDWAVE },
109 { XML_AUTO, FontUnderline::DOUBLEWAVE },
110 { XML_THIN, FontUnderline::NONE },
111 { XML_MEDIUM, FontUnderline::NONE },
112 { XML_THICK, FontUnderline::BOLD},
113 { XML_TOKEN_INVALID, 0 }
118 ///////////////////////////////////////////////////////////////////////////////
120 // class XMLUnderlineTypePropHdl
123 XMLUnderlineTypePropHdl::~XMLUnderlineTypePropHdl()
125 // nothing to do
128 sal_Bool XMLUnderlineTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
130 sal_uInt16 eNewUnderline;
131 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
132 eNewUnderline, rStrImpValue, pXML_UnderlineType_Enum );
133 if( bRet )
135 // multi property: style and width might be set already.
136 // If the old value is NONE, the new is used unchanged.
137 sal_Int16 eUnderline = sal_Int16();
138 if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline )
140 switch( eNewUnderline )
142 case FontUnderline::NONE:
143 case FontUnderline::SINGLE:
144 // keep existing line style
145 eNewUnderline = eUnderline;
146 break;
147 case FontUnderline::DOUBLE:
148 // A double line style has priority over a bold line style,
149 // but not over the line style itself.
150 switch( eUnderline )
152 case FontUnderline::SINGLE:
153 case FontUnderline::BOLD:
154 break;
155 case FontUnderline::WAVE:
156 case FontUnderline::BOLDWAVE:
157 eNewUnderline = FontUnderline::DOUBLEWAVE;
158 break;
159 default:
160 // If a double line style is not supported for the existing
161 // value, keep the new one
162 eNewUnderline = eUnderline;
163 break;
165 break;
166 default:
167 OSL_ENSURE( bRet, "unexpected line type value" );
168 break;
170 if( eNewUnderline != eUnderline )
171 rValue <<= (sal_Int16)eNewUnderline;
173 else
175 rValue <<= (sal_Int16)eNewUnderline;
179 return bRet;
182 sal_Bool XMLUnderlineTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
184 sal_Bool bRet = sal_False;
185 sal_Int16 nValue = sal_Int16();
186 OUStringBuffer aOut;
188 if( (rValue >>= nValue) &&
189 (FontUnderline::DOUBLE == nValue ||
190 FontUnderline::DOUBLEWAVE == nValue) )
192 bRet = SvXMLUnitConverter::convertEnum(
193 aOut, (sal_uInt16)nValue, pXML_UnderlineType_Enum );
194 if( bRet )
195 rStrExpValue = aOut.makeStringAndClear();
198 return bRet;
201 ///////////////////////////////////////////////////////////////////////////////
203 // class XMLUnderlineStylePropHdl
206 XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl()
208 // nothing to do
211 sal_Bool XMLUnderlineStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
213 sal_uInt16 eNewUnderline;
214 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
215 eNewUnderline, rStrImpValue, pXML_UnderlineStyle_Enum );
216 if( bRet )
218 // multi property: style and width might be set already.
219 // If the old value is NONE, the new is used unchanged.
220 sal_Int16 eUnderline = sal_Int16();
221 if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline )
223 switch( eNewUnderline )
225 case FontUnderline::NONE:
226 case FontUnderline::SINGLE:
227 // keep double or bold line style
228 eNewUnderline = eUnderline;
229 case FontUnderline::DOTTED:
230 // The line style has priority over a double type.
231 if( FontUnderline::BOLD == eUnderline )
232 eNewUnderline = FontUnderline::BOLDDOTTED;
233 break;
234 case FontUnderline::DASH:
235 if( FontUnderline::BOLD == eUnderline )
236 eNewUnderline = FontUnderline::BOLDDASH;
237 break;
238 case FontUnderline::LONGDASH:
239 if( FontUnderline::BOLD == eUnderline )
240 eNewUnderline = FontUnderline::BOLDLONGDASH;
241 break;
242 case FontUnderline::DASHDOT:
243 if( FontUnderline::BOLD == eUnderline )
244 eNewUnderline = FontUnderline::BOLDDASHDOT;
245 break;
246 case FontUnderline::DASHDOTDOT:
247 if( FontUnderline::BOLD == eUnderline )
248 eNewUnderline = FontUnderline::BOLDDASHDOTDOT;
249 break;
250 case FontUnderline::WAVE:
251 if( FontUnderline::BOLD == eUnderline )
252 eNewUnderline = FontUnderline::BOLDWAVE;
253 break;
254 case FontUnderline::SMALLWAVE:
255 // SMALLWAVE is not used
256 default:
257 OSL_ENSURE( bRet, "unexpected line style value" );
258 break;
260 if( eNewUnderline != eUnderline )
261 rValue <<= (sal_Int16)eNewUnderline;
263 else
265 rValue <<= (sal_Int16)eNewUnderline;
269 return bRet;
272 sal_Bool XMLUnderlineStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
274 sal_Bool bRet = sal_False;
275 sal_Int16 nValue = sal_Int16();
276 OUStringBuffer aOut;
278 if( rValue >>= nValue )
280 bRet = SvXMLUnitConverter::convertEnum(
281 aOut, (sal_uInt16)nValue, pXML_UnderlineStyle_Enum );
282 if( bRet )
283 rStrExpValue = aOut.makeStringAndClear();
286 return bRet;
289 ///////////////////////////////////////////////////////////////////////////////
291 // class XMLUnderlineWidthPropHdl
294 XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl()
296 // nothing to do
299 sal_Bool XMLUnderlineWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
301 sal_uInt16 eNewUnderline;
302 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
303 eNewUnderline, rStrImpValue, pXML_UnderlineWidth_Enum );
304 if( bRet )
306 // multi property: style and width might be set already.
307 // If the old value is NONE, the new is used unchanged.
308 sal_Int16 eUnderline = sal_Int16();
309 if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline )
311 switch( eNewUnderline )
313 case FontUnderline::NONE:
314 // keep existing line style
315 eNewUnderline = eUnderline;
316 break;
317 case FontUnderline::BOLD:
318 // A double line style has priority over a bold line style,
319 // but not over the line style itself.
320 switch( eUnderline )
322 case FontUnderline::SINGLE:
323 break;
324 case FontUnderline::DOTTED:
325 eNewUnderline = FontUnderline::BOLDDOTTED;
326 break;
327 case FontUnderline::DASH:
328 eNewUnderline = FontUnderline::BOLDDASH;
329 break;
330 case FontUnderline::LONGDASH:
331 eNewUnderline = FontUnderline::BOLDLONGDASH;
332 break;
333 case FontUnderline::DASHDOT:
334 eNewUnderline = FontUnderline::BOLDDASHDOT;
335 break;
336 case FontUnderline::DASHDOTDOT:
337 eNewUnderline = FontUnderline::BOLDDASHDOTDOT;
338 break;
339 case FontUnderline::WAVE:
340 eNewUnderline = FontUnderline::BOLDWAVE;
341 break;
342 default:
343 // a doube line style overwrites a bold one
344 eNewUnderline = eUnderline;
345 break;
347 break;
348 default:
349 OSL_ENSURE( bRet, "unexpected line width value" );
350 break;
352 if( eNewUnderline != eUnderline )
353 rValue <<= (sal_Int16)eNewUnderline;
355 else
357 rValue <<= (sal_Int16)eNewUnderline;
361 return bRet;
364 sal_Bool XMLUnderlineWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
366 sal_Bool bRet = sal_False;
367 sal_Int16 nValue = sal_Int16();
368 OUStringBuffer aOut;
370 if( (rValue >>= nValue) && (FontUnderline::NONE != nValue) )
372 bRet = SvXMLUnitConverter::convertEnum(
373 aOut, (sal_uInt16)nValue, pXML_UnderlineWidth_Enum );
374 if( bRet )
375 rStrExpValue = aOut.makeStringAndClear();
378 return bRet;
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */