1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: undlihdl.cxx,v $
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>
44 #ifndef _XMLOFF_XMLEMENT_HXX
45 #include <xmloff/xmlelement.hxx>
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()
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
);
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
;
157 case FontUnderline::DOUBLE
:
158 // A double line style has priority over a bold line style,
159 // but not over the line style itself.
162 case FontUnderline::SINGLE
:
163 case FontUnderline::BOLD
:
165 case FontUnderline::WAVE
:
166 case FontUnderline::BOLDWAVE
:
167 eNewUnderline
= FontUnderline::DOUBLEWAVE
;
170 // If a double line style is not supported for the existing
171 // value, keep the new one
172 eNewUnderline
= eUnderline
;
177 OSL_ENSURE( bRet
, "unexpected line type value" );
180 if( eNewUnderline
!= eUnderline
)
181 rValue
<<= (sal_Int16
)eNewUnderline
;
185 rValue
<<= (sal_Int16
)eNewUnderline
;
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();
198 if( (rValue
>>= nValue
) &&
199 (FontUnderline::DOUBLE
== nValue
||
200 FontUnderline::DOUBLEWAVE
== nValue
) )
202 bRet
= SvXMLUnitConverter::convertEnum(
203 aOut
, (sal_uInt16
)nValue
, pXML_UnderlineType_Enum
);
205 rStrExpValue
= aOut
.makeStringAndClear();
211 ///////////////////////////////////////////////////////////////////////////////
213 // class XMLUnderlineStylePropHdl
216 XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl()
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
);
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
;
244 case FontUnderline::DASH
:
245 if( FontUnderline::BOLD
== eUnderline
)
246 eNewUnderline
= FontUnderline::BOLDDASH
;
248 case FontUnderline::LONGDASH
:
249 if( FontUnderline::BOLD
== eUnderline
)
250 eNewUnderline
= FontUnderline::BOLDLONGDASH
;
252 case FontUnderline::DASHDOT
:
253 if( FontUnderline::BOLD
== eUnderline
)
254 eNewUnderline
= FontUnderline::BOLDDASHDOT
;
256 case FontUnderline::DASHDOTDOT
:
257 if( FontUnderline::BOLD
== eUnderline
)
258 eNewUnderline
= FontUnderline::BOLDDASHDOTDOT
;
260 case FontUnderline::WAVE
:
261 if( FontUnderline::BOLD
== eUnderline
)
262 eNewUnderline
= FontUnderline::BOLDWAVE
;
264 case FontUnderline::SMALLWAVE
:
265 // SMALLWAVE is not used
267 OSL_ENSURE( bRet
, "unexpected line style value" );
270 if( eNewUnderline
!= eUnderline
)
271 rValue
<<= (sal_Int16
)eNewUnderline
;
275 rValue
<<= (sal_Int16
)eNewUnderline
;
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();
288 if( rValue
>>= nValue
)
290 bRet
= SvXMLUnitConverter::convertEnum(
291 aOut
, (sal_uInt16
)nValue
, pXML_UnderlineStyle_Enum
);
293 rStrExpValue
= aOut
.makeStringAndClear();
299 ///////////////////////////////////////////////////////////////////////////////
301 // class XMLUnderlineWidthPropHdl
304 XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl()
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
);
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
;
327 case FontUnderline::BOLD
:
328 // A double line style has priority over a bold line style,
329 // but not over the line style itself.
332 case FontUnderline::SINGLE
:
334 case FontUnderline::DOTTED
:
335 eNewUnderline
= FontUnderline::BOLDDOTTED
;
337 case FontUnderline::DASH
:
338 eNewUnderline
= FontUnderline::BOLDDASH
;
340 case FontUnderline::LONGDASH
:
341 eNewUnderline
= FontUnderline::BOLDLONGDASH
;
343 case FontUnderline::DASHDOT
:
344 eNewUnderline
= FontUnderline::BOLDDASHDOT
;
346 case FontUnderline::DASHDOTDOT
:
347 eNewUnderline
= FontUnderline::BOLDDASHDOTDOT
;
349 case FontUnderline::WAVE
:
350 eNewUnderline
= FontUnderline::BOLDWAVE
;
353 // a doube line style overwrites a bold one
354 eNewUnderline
= eUnderline
;
359 OSL_ENSURE( bRet
, "unexpected line width value" );
362 if( eNewUnderline
!= eUnderline
)
363 rValue
<<= (sal_Int16
)eNewUnderline
;
367 rValue
<<= (sal_Int16
)eNewUnderline
;
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();
380 if( (rValue
>>= nValue
) && (FontUnderline::NONE
!= nValue
) )
382 bRet
= SvXMLUnitConverter::convertEnum(
383 aOut
, (sal_uInt16
)nValue
, pXML_UnderlineWidth_Enum
);
385 rStrExpValue
= aOut
.makeStringAndClear();