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()
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
);
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
;
147 case FontUnderline::DOUBLE
:
148 // A double line style has priority over a bold line style,
149 // but not over the line style itself.
152 case FontUnderline::SINGLE
:
153 case FontUnderline::BOLD
:
155 case FontUnderline::WAVE
:
156 case FontUnderline::BOLDWAVE
:
157 eNewUnderline
= FontUnderline::DOUBLEWAVE
;
160 // If a double line style is not supported for the existing
161 // value, keep the new one
162 eNewUnderline
= eUnderline
;
167 OSL_ENSURE( bRet
, "unexpected line type value" );
170 if( eNewUnderline
!= eUnderline
)
171 rValue
<<= (sal_Int16
)eNewUnderline
;
175 rValue
<<= (sal_Int16
)eNewUnderline
;
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();
188 if( (rValue
>>= nValue
) &&
189 (FontUnderline::DOUBLE
== nValue
||
190 FontUnderline::DOUBLEWAVE
== nValue
) )
192 bRet
= SvXMLUnitConverter::convertEnum(
193 aOut
, (sal_uInt16
)nValue
, pXML_UnderlineType_Enum
);
195 rStrExpValue
= aOut
.makeStringAndClear();
201 ///////////////////////////////////////////////////////////////////////////////
203 // class XMLUnderlineStylePropHdl
206 XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl()
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
);
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
;
234 case FontUnderline::DASH
:
235 if( FontUnderline::BOLD
== eUnderline
)
236 eNewUnderline
= FontUnderline::BOLDDASH
;
238 case FontUnderline::LONGDASH
:
239 if( FontUnderline::BOLD
== eUnderline
)
240 eNewUnderline
= FontUnderline::BOLDLONGDASH
;
242 case FontUnderline::DASHDOT
:
243 if( FontUnderline::BOLD
== eUnderline
)
244 eNewUnderline
= FontUnderline::BOLDDASHDOT
;
246 case FontUnderline::DASHDOTDOT
:
247 if( FontUnderline::BOLD
== eUnderline
)
248 eNewUnderline
= FontUnderline::BOLDDASHDOTDOT
;
250 case FontUnderline::WAVE
:
251 if( FontUnderline::BOLD
== eUnderline
)
252 eNewUnderline
= FontUnderline::BOLDWAVE
;
254 case FontUnderline::SMALLWAVE
:
255 // SMALLWAVE is not used
257 OSL_ENSURE( bRet
, "unexpected line style value" );
260 if( eNewUnderline
!= eUnderline
)
261 rValue
<<= (sal_Int16
)eNewUnderline
;
265 rValue
<<= (sal_Int16
)eNewUnderline
;
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();
278 if( rValue
>>= nValue
)
280 bRet
= SvXMLUnitConverter::convertEnum(
281 aOut
, (sal_uInt16
)nValue
, pXML_UnderlineStyle_Enum
);
283 rStrExpValue
= aOut
.makeStringAndClear();
289 ///////////////////////////////////////////////////////////////////////////////
291 // class XMLUnderlineWidthPropHdl
294 XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl()
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
);
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
;
317 case FontUnderline::BOLD
:
318 // A double line style has priority over a bold line style,
319 // but not over the line style itself.
322 case FontUnderline::SINGLE
:
324 case FontUnderline::DOTTED
:
325 eNewUnderline
= FontUnderline::BOLDDOTTED
;
327 case FontUnderline::DASH
:
328 eNewUnderline
= FontUnderline::BOLDDASH
;
330 case FontUnderline::LONGDASH
:
331 eNewUnderline
= FontUnderline::BOLDLONGDASH
;
333 case FontUnderline::DASHDOT
:
334 eNewUnderline
= FontUnderline::BOLDDASHDOT
;
336 case FontUnderline::DASHDOTDOT
:
337 eNewUnderline
= FontUnderline::BOLDDASHDOTDOT
;
339 case FontUnderline::WAVE
:
340 eNewUnderline
= FontUnderline::BOLDWAVE
;
343 // a doube line style overwrites a bold one
344 eNewUnderline
= eUnderline
;
349 OSL_ENSURE( bRet
, "unexpected line width value" );
352 if( eNewUnderline
!= eUnderline
)
353 rValue
<<= (sal_Int16
)eNewUnderline
;
357 rValue
<<= (sal_Int16
)eNewUnderline
;
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();
370 if( (rValue
>>= nValue
) && (FontUnderline::NONE
!= nValue
) )
372 bRet
= SvXMLUnitConverter::convertEnum(
373 aOut
, (sal_uInt16
)nValue
, pXML_UnderlineWidth_Enum
);
375 rStrExpValue
= aOut
.makeStringAndClear();
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */