update dev300-m58
[ooovba.git] / xmloff / source / style / undlihdl.cxx
blob4560c9c5168072c4a6564f93767f31d9da8bfea5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: undlihdl.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <undlihdl.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include <rtl/ustrbuf.hxx>
39 #include <com/sun/star/uno/Any.hxx>
40 #ifndef _COM_SUN_STAR_AWT_FONTUNDERLINE_HPP
41 #include <com/sun/star/awt/FontUnderline.hpp>
42 #endif
44 #ifndef _XMLOFF_XMLEMENT_HXX
45 #include <xmloff/xmlelement.hxx>
46 #endif
48 using ::rtl::OUString;
49 using ::rtl::OUStringBuffer;
51 using namespace ::com::sun::star;
52 using namespace ::com::sun::star::awt;
53 using namespace ::xmloff::token;
55 SvXMLEnumMapEntry __READONLY_DATA pXML_UnderlineType_Enum[] =
57 { XML_NONE, FontUnderline::NONE },
58 { XML_SINGLE, FontUnderline::SINGLE },
59 { XML_DOUBLE, FontUnderline::DOUBLE },
60 { XML_SINGLE, FontUnderline::DOTTED },
61 { XML_SINGLE, FontUnderline::DASH },
62 { XML_SINGLE, FontUnderline::LONGDASH },
63 { XML_SINGLE, FontUnderline::DASHDOT },
64 { XML_SINGLE, FontUnderline::DASHDOTDOT },
65 { XML_SINGLE, FontUnderline::WAVE },
66 { XML_SINGLE, FontUnderline::BOLD },
67 { XML_SINGLE, FontUnderline::BOLDDOTTED },
68 { XML_SINGLE, FontUnderline::BOLDDASH },
69 { XML_SINGLE, FontUnderline::BOLDLONGDASH },
70 { XML_SINGLE, FontUnderline::BOLDDASHDOT },
71 { XML_SINGLE, FontUnderline::BOLDDASHDOTDOT },
72 { XML_SINGLE, FontUnderline::BOLDWAVE },
73 { XML_DOUBLE, FontUnderline::DOUBLEWAVE },
74 { XML_SINGLE, FontUnderline::SMALLWAVE },
75 { XML_TOKEN_INVALID, 0 }
78 SvXMLEnumMapEntry __READONLY_DATA pXML_UnderlineStyle_Enum[] =
80 { XML_NONE, FontUnderline::NONE },
81 { XML_SOLID, FontUnderline::SINGLE },
82 { XML_SOLID, FontUnderline::DOUBLE },
83 { XML_DOTTED, FontUnderline::DOTTED },
84 { XML_DASH, FontUnderline::DASH },
85 { XML_LONG_DASH, FontUnderline::LONGDASH },
86 { XML_DOT_DASH, FontUnderline::DASHDOT },
87 { XML_DOT_DOT_DASH, FontUnderline::DASHDOTDOT },
88 { XML_WAVE, FontUnderline::WAVE },
89 { XML_SOLID, FontUnderline::BOLD },
90 { XML_DOTTED, FontUnderline::BOLDDOTTED },
91 { XML_DASH, FontUnderline::BOLDDASH },
92 { XML_LONG_DASH, FontUnderline::BOLDLONGDASH },
93 { XML_DOT_DASH, FontUnderline::BOLDDASHDOT },
94 { XML_DOT_DOT_DASH, FontUnderline::BOLDDASHDOTDOT },
95 { XML_WAVE, FontUnderline::BOLDWAVE },
96 { XML_WAVE, FontUnderline::DOUBLEWAVE },
97 { XML_SMALL_WAVE, FontUnderline::SMALLWAVE },
98 { XML_TOKEN_INVALID, 0 }
101 SvXMLEnumMapEntry __READONLY_DATA pXML_UnderlineWidth_Enum[] =
103 { XML_AUTO, FontUnderline::NONE },
104 { XML_AUTO, FontUnderline::SINGLE },
105 { XML_AUTO, FontUnderline::DOUBLE },
106 { XML_AUTO, FontUnderline::DOTTED },
107 { XML_AUTO, FontUnderline::DASH },
108 { XML_AUTO, FontUnderline::LONGDASH },
109 { XML_AUTO, FontUnderline::DASHDOT },
110 { XML_AUTO, FontUnderline::DASHDOTDOT },
111 { XML_AUTO, FontUnderline::WAVE },
112 { XML_BOLD, FontUnderline::BOLD },
113 { XML_BOLD, FontUnderline::BOLDDOTTED },
114 { XML_BOLD, FontUnderline::BOLDDASH },
115 { XML_BOLD, FontUnderline::BOLDLONGDASH },
116 { XML_BOLD, FontUnderline::BOLDDASHDOT },
117 { XML_BOLD, FontUnderline::BOLDDASHDOTDOT },
118 { XML_BOLD, FontUnderline::BOLDWAVE },
119 { XML_AUTO, FontUnderline::DOUBLEWAVE },
120 { XML_THIN, FontUnderline::NONE },
121 { XML_MEDIUM, FontUnderline::NONE },
122 { XML_THICK, FontUnderline::BOLD},
123 { XML_TOKEN_INVALID, 0 }
128 ///////////////////////////////////////////////////////////////////////////////
130 // class XMLUnderlineTypePropHdl
133 XMLUnderlineTypePropHdl::~XMLUnderlineTypePropHdl()
135 // nothing to do
138 sal_Bool XMLUnderlineTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
140 sal_uInt16 eNewUnderline;
141 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
142 eNewUnderline, rStrImpValue, pXML_UnderlineType_Enum );
143 if( bRet )
145 // multi property: style and width might be set already.
146 // If the old value is NONE, the new is used unchanged.
147 sal_Int16 eUnderline = sal_Int16();
148 if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline )
150 switch( eNewUnderline )
152 case FontUnderline::NONE:
153 case FontUnderline::SINGLE:
154 // keep existing line style
155 eNewUnderline = eUnderline;
156 break;
157 case FontUnderline::DOUBLE:
158 // A double line style has priority over a bold line style,
159 // but not over the line style itself.
160 switch( eUnderline )
162 case FontUnderline::SINGLE:
163 case FontUnderline::BOLD:
164 break;
165 case FontUnderline::WAVE:
166 case FontUnderline::BOLDWAVE:
167 eNewUnderline = FontUnderline::DOUBLEWAVE;
168 break;
169 default:
170 // If a double line style is not supported for the existing
171 // value, keep the new one
172 eNewUnderline = eUnderline;
173 break;
175 break;
176 default:
177 OSL_ENSURE( bRet, "unexpected line type value" );
178 break;
180 if( eNewUnderline != eUnderline )
181 rValue <<= (sal_Int16)eNewUnderline;
183 else
185 rValue <<= (sal_Int16)eNewUnderline;
189 return bRet;
192 sal_Bool XMLUnderlineTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
194 sal_Bool bRet = sal_False;
195 sal_Int16 nValue = sal_Int16();
196 OUStringBuffer aOut;
198 if( (rValue >>= nValue) &&
199 (FontUnderline::DOUBLE == nValue ||
200 FontUnderline::DOUBLEWAVE == nValue) )
202 bRet = SvXMLUnitConverter::convertEnum(
203 aOut, (sal_uInt16)nValue, pXML_UnderlineType_Enum );
204 if( bRet )
205 rStrExpValue = aOut.makeStringAndClear();
208 return bRet;
211 ///////////////////////////////////////////////////////////////////////////////
213 // class XMLUnderlineStylePropHdl
216 XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl()
218 // nothing to do
221 sal_Bool XMLUnderlineStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
223 sal_uInt16 eNewUnderline;
224 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
225 eNewUnderline, rStrImpValue, pXML_UnderlineStyle_Enum );
226 if( bRet )
228 // multi property: style and width might be set already.
229 // If the old value is NONE, the new is used unchanged.
230 sal_Int16 eUnderline = sal_Int16();
231 if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline )
233 switch( eNewUnderline )
235 case FontUnderline::NONE:
236 case FontUnderline::SINGLE:
237 // keep double or bold line style
238 eNewUnderline = eUnderline;
239 case FontUnderline::DOTTED:
240 // The line style has priority over a double type.
241 if( FontUnderline::BOLD == eUnderline )
242 eNewUnderline = FontUnderline::BOLDDOTTED;
243 break;
244 case FontUnderline::DASH:
245 if( FontUnderline::BOLD == eUnderline )
246 eNewUnderline = FontUnderline::BOLDDASH;
247 break;
248 case FontUnderline::LONGDASH:
249 if( FontUnderline::BOLD == eUnderline )
250 eNewUnderline = FontUnderline::BOLDLONGDASH;
251 break;
252 case FontUnderline::DASHDOT:
253 if( FontUnderline::BOLD == eUnderline )
254 eNewUnderline = FontUnderline::BOLDDASHDOT;
255 break;
256 case FontUnderline::DASHDOTDOT:
257 if( FontUnderline::BOLD == eUnderline )
258 eNewUnderline = FontUnderline::BOLDDASHDOTDOT;
259 break;
260 case FontUnderline::WAVE:
261 if( FontUnderline::BOLD == eUnderline )
262 eNewUnderline = FontUnderline::BOLDWAVE;
263 break;
264 case FontUnderline::SMALLWAVE:
265 // SMALLWAVE is not used
266 default:
267 OSL_ENSURE( bRet, "unexpected line style value" );
268 break;
270 if( eNewUnderline != eUnderline )
271 rValue <<= (sal_Int16)eNewUnderline;
273 else
275 rValue <<= (sal_Int16)eNewUnderline;
279 return bRet;
282 sal_Bool XMLUnderlineStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
284 sal_Bool bRet = sal_False;
285 sal_Int16 nValue = sal_Int16();
286 OUStringBuffer aOut;
288 if( rValue >>= nValue )
290 bRet = SvXMLUnitConverter::convertEnum(
291 aOut, (sal_uInt16)nValue, pXML_UnderlineStyle_Enum );
292 if( bRet )
293 rStrExpValue = aOut.makeStringAndClear();
296 return bRet;
299 ///////////////////////////////////////////////////////////////////////////////
301 // class XMLUnderlineWidthPropHdl
304 XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl()
306 // nothing to do
309 sal_Bool XMLUnderlineWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
311 sal_uInt16 eNewUnderline;
312 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
313 eNewUnderline, rStrImpValue, pXML_UnderlineWidth_Enum );
314 if( bRet )
316 // multi property: style and width might be set already.
317 // If the old value is NONE, the new is used unchanged.
318 sal_Int16 eUnderline = sal_Int16();
319 if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline )
321 switch( eNewUnderline )
323 case FontUnderline::NONE:
324 // keep existing line style
325 eNewUnderline = eUnderline;
326 break;
327 case FontUnderline::BOLD:
328 // A double line style has priority over a bold line style,
329 // but not over the line style itself.
330 switch( eUnderline )
332 case FontUnderline::SINGLE:
333 break;
334 case FontUnderline::DOTTED:
335 eNewUnderline = FontUnderline::BOLDDOTTED;
336 break;
337 case FontUnderline::DASH:
338 eNewUnderline = FontUnderline::BOLDDASH;
339 break;
340 case FontUnderline::LONGDASH:
341 eNewUnderline = FontUnderline::BOLDLONGDASH;
342 break;
343 case FontUnderline::DASHDOT:
344 eNewUnderline = FontUnderline::BOLDDASHDOT;
345 break;
346 case FontUnderline::DASHDOTDOT:
347 eNewUnderline = FontUnderline::BOLDDASHDOTDOT;
348 break;
349 case FontUnderline::WAVE:
350 eNewUnderline = FontUnderline::BOLDWAVE;
351 break;
352 default:
353 // a doube line style overwrites a bold one
354 eNewUnderline = eUnderline;
355 break;
357 break;
358 default:
359 OSL_ENSURE( bRet, "unexpected line width value" );
360 break;
362 if( eNewUnderline != eUnderline )
363 rValue <<= (sal_Int16)eNewUnderline;
365 else
367 rValue <<= (sal_Int16)eNewUnderline;
371 return bRet;
374 sal_Bool XMLUnderlineWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
376 sal_Bool bRet = sal_False;
377 sal_Int16 nValue = sal_Int16();
378 OUStringBuffer aOut;
380 if( (rValue >>= nValue) && (FontUnderline::NONE != nValue) )
382 bRet = SvXMLUnitConverter::convertEnum(
383 aOut, (sal_uInt16)nValue, pXML_UnderlineWidth_Enum );
384 if( bRet )
385 rStrExpValue = aOut.makeStringAndClear();
388 return bRet;