1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #include <osl/diagnose.h>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <com/sun/star/awt/FontUnderline.hpp>
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::awt
;
31 using namespace ::xmloff::token
;
33 SvXMLEnumMapEntry
const pXML_UnderlineType_Enum
[] =
35 { XML_NONE
, awt::FontUnderline::NONE
},
36 { XML_SINGLE
, awt::FontUnderline::SINGLE
},
37 { XML_DOUBLE
, awt::FontUnderline::DOUBLE
},
38 { XML_SINGLE
, awt::FontUnderline::DOTTED
},
39 { XML_SINGLE
, awt::FontUnderline::DASH
},
40 { XML_SINGLE
, awt::FontUnderline::LONGDASH
},
41 { XML_SINGLE
, awt::FontUnderline::DASHDOT
},
42 { XML_SINGLE
, awt::FontUnderline::DASHDOTDOT
},
43 { XML_SINGLE
, awt::FontUnderline::WAVE
},
44 { XML_SINGLE
, awt::FontUnderline::BOLD
},
45 { XML_SINGLE
, awt::FontUnderline::BOLDDOTTED
},
46 { XML_SINGLE
, awt::FontUnderline::BOLDDASH
},
47 { XML_SINGLE
, awt::FontUnderline::BOLDLONGDASH
},
48 { XML_SINGLE
, awt::FontUnderline::BOLDDASHDOT
},
49 { XML_SINGLE
, awt::FontUnderline::BOLDDASHDOTDOT
},
50 { XML_SINGLE
, awt::FontUnderline::BOLDWAVE
},
51 { XML_DOUBLE
, awt::FontUnderline::DOUBLEWAVE
},
52 { XML_SINGLE
, awt::FontUnderline::SMALLWAVE
},
53 { XML_TOKEN_INVALID
, 0 }
56 SvXMLEnumMapEntry
const pXML_UnderlineStyle_Enum
[] =
58 { XML_NONE
, awt::FontUnderline::NONE
},
59 { XML_SOLID
, awt::FontUnderline::SINGLE
},
60 { XML_SOLID
, awt::FontUnderline::DOUBLE
},
61 { XML_DOTTED
, awt::FontUnderline::DOTTED
},
62 { XML_DASH
, awt::FontUnderline::DASH
},
63 { XML_LONG_DASH
, awt::FontUnderline::LONGDASH
},
64 { XML_DOT_DASH
, awt::FontUnderline::DASHDOT
},
65 { XML_DOT_DOT_DASH
, awt::FontUnderline::DASHDOTDOT
},
66 { XML_WAVE
, awt::FontUnderline::WAVE
},
67 { XML_SOLID
, awt::FontUnderline::BOLD
},
68 { XML_DOTTED
, awt::FontUnderline::BOLDDOTTED
},
69 { XML_DASH
, awt::FontUnderline::BOLDDASH
},
70 { XML_LONG_DASH
, awt::FontUnderline::BOLDLONGDASH
},
71 { XML_DOT_DASH
, awt::FontUnderline::BOLDDASHDOT
},
72 { XML_DOT_DOT_DASH
, awt::FontUnderline::BOLDDASHDOTDOT
},
73 { XML_WAVE
, awt::FontUnderline::BOLDWAVE
},
74 { XML_WAVE
, awt::FontUnderline::DOUBLEWAVE
},
75 { XML_SMALL_WAVE
, awt::FontUnderline::SMALLWAVE
},
76 { XML_TOKEN_INVALID
, 0 }
79 SvXMLEnumMapEntry
const pXML_UnderlineWidth_Enum
[] =
81 { XML_AUTO
, awt::FontUnderline::NONE
},
82 { XML_AUTO
, awt::FontUnderline::SINGLE
},
83 { XML_AUTO
, awt::FontUnderline::DOUBLE
},
84 { XML_AUTO
, awt::FontUnderline::DOTTED
},
85 { XML_AUTO
, awt::FontUnderline::DASH
},
86 { XML_AUTO
, awt::FontUnderline::LONGDASH
},
87 { XML_AUTO
, awt::FontUnderline::DASHDOT
},
88 { XML_AUTO
, awt::FontUnderline::DASHDOTDOT
},
89 { XML_AUTO
, awt::FontUnderline::WAVE
},
90 { XML_BOLD
, awt::FontUnderline::BOLD
},
91 { XML_BOLD
, awt::FontUnderline::BOLDDOTTED
},
92 { XML_BOLD
, awt::FontUnderline::BOLDDASH
},
93 { XML_BOLD
, awt::FontUnderline::BOLDLONGDASH
},
94 { XML_BOLD
, awt::FontUnderline::BOLDDASHDOT
},
95 { XML_BOLD
, awt::FontUnderline::BOLDDASHDOTDOT
},
96 { XML_BOLD
, awt::FontUnderline::BOLDWAVE
},
97 { XML_AUTO
, awt::FontUnderline::DOUBLEWAVE
},
98 { XML_THIN
, awt::FontUnderline::NONE
},
99 { XML_MEDIUM
, awt::FontUnderline::NONE
},
100 { XML_THICK
, awt::FontUnderline::BOLD
},
101 { XML_TOKEN_INVALID
, 0 }
105 // class XMLUnderlineTypePropHdl
108 XMLUnderlineTypePropHdl::~XMLUnderlineTypePropHdl()
113 bool XMLUnderlineTypePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
115 sal_uInt16 eNewUnderline
;
116 bool bRet
= SvXMLUnitConverter::convertEnum(
117 eNewUnderline
, rStrImpValue
, pXML_UnderlineType_Enum
);
120 // multi property: style and width might be set already.
121 // If the old value is NONE, the new is used unchanged.
122 sal_Int16 eUnderline
= sal_Int16();
123 if( (rValue
>>= eUnderline
) && awt::FontUnderline::NONE
!=eUnderline
)
125 switch( eNewUnderline
)
127 case awt::FontUnderline::NONE
:
128 case awt::FontUnderline::SINGLE
:
129 // keep existing line style
130 eNewUnderline
= eUnderline
;
132 case awt::FontUnderline::DOUBLE
:
133 // A double line style has priority over a bold line style,
134 // but not over the line style itself.
137 case awt::FontUnderline::SINGLE
:
138 case awt::FontUnderline::BOLD
:
140 case awt::FontUnderline::WAVE
:
141 case awt::FontUnderline::BOLDWAVE
:
142 eNewUnderline
= awt::FontUnderline::DOUBLEWAVE
;
145 // If a double line style is not supported for the existing
146 // value, keep the new one
147 eNewUnderline
= eUnderline
;
152 OSL_ENSURE( bRet
, "unexpected line type value" );
155 if( eNewUnderline
!= eUnderline
)
156 rValue
<<= (sal_Int16
)eNewUnderline
;
160 rValue
<<= (sal_Int16
)eNewUnderline
;
167 bool XMLUnderlineTypePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
170 sal_Int16 nValue
= sal_Int16();
173 if( (rValue
>>= nValue
) &&
174 (awt::FontUnderline::DOUBLE
== nValue
||
175 awt::FontUnderline::DOUBLEWAVE
== nValue
) )
177 bRet
= SvXMLUnitConverter::convertEnum(
178 aOut
, (sal_uInt16
)nValue
, pXML_UnderlineType_Enum
);
180 rStrExpValue
= aOut
.makeStringAndClear();
187 // class XMLUnderlineStylePropHdl
190 XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl()
195 bool XMLUnderlineStylePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
197 sal_uInt16 eNewUnderline
;
198 bool bRet
= SvXMLUnitConverter::convertEnum(
199 eNewUnderline
, rStrImpValue
, pXML_UnderlineStyle_Enum
);
202 // multi property: style and width might be set already.
203 // If the old value is NONE, the new is used unchanged.
204 sal_Int16 eUnderline
= sal_Int16();
205 if( (rValue
>>= eUnderline
) && awt::FontUnderline::NONE
!=eUnderline
)
207 switch( eNewUnderline
)
209 case awt::FontUnderline::NONE
:
210 case awt::FontUnderline::SINGLE
:
211 // keep double or bold line style
212 eNewUnderline
= eUnderline
;
214 case awt::FontUnderline::DOTTED
:
215 // The line style has priority over a double type.
216 if( awt::FontUnderline::BOLD
== eUnderline
)
217 eNewUnderline
= awt::FontUnderline::BOLDDOTTED
;
219 case awt::FontUnderline::DASH
:
220 if( awt::FontUnderline::BOLD
== eUnderline
)
221 eNewUnderline
= awt::FontUnderline::BOLDDASH
;
223 case awt::FontUnderline::LONGDASH
:
224 if( awt::FontUnderline::BOLD
== eUnderline
)
225 eNewUnderline
= awt::FontUnderline::BOLDLONGDASH
;
227 case awt::FontUnderline::DASHDOT
:
228 if( awt::FontUnderline::BOLD
== eUnderline
)
229 eNewUnderline
= awt::FontUnderline::BOLDDASHDOT
;
231 case awt::FontUnderline::DASHDOTDOT
:
232 if( awt::FontUnderline::BOLD
== eUnderline
)
233 eNewUnderline
= awt::FontUnderline::BOLDDASHDOTDOT
;
235 case awt::FontUnderline::WAVE
:
236 if( awt::FontUnderline::DOUBLE
== eUnderline
)
237 eNewUnderline
= awt::FontUnderline::DOUBLEWAVE
;
238 else if( awt::FontUnderline::BOLD
== eUnderline
)
239 eNewUnderline
= awt::FontUnderline::BOLDWAVE
;
241 case awt::FontUnderline::SMALLWAVE
:
242 // SMALLWAVE is not used
244 OSL_ENSURE( bRet
, "unexpected line style value" );
247 if( eNewUnderline
!= eUnderline
)
248 rValue
<<= (sal_Int16
)eNewUnderline
;
252 rValue
<<= (sal_Int16
)eNewUnderline
;
259 bool XMLUnderlineStylePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
262 sal_Int16 nValue
= sal_Int16();
265 if( rValue
>>= nValue
)
267 bRet
= SvXMLUnitConverter::convertEnum(
268 aOut
, (sal_uInt16
)nValue
, pXML_UnderlineStyle_Enum
);
270 rStrExpValue
= aOut
.makeStringAndClear();
277 // class XMLUnderlineWidthPropHdl
280 XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl()
285 bool XMLUnderlineWidthPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
287 sal_uInt16 eNewUnderline
;
288 bool bRet
= SvXMLUnitConverter::convertEnum(
289 eNewUnderline
, rStrImpValue
, pXML_UnderlineWidth_Enum
);
292 // multi property: style and width might be set already.
293 // If the old value is NONE, the new is used unchanged.
294 sal_Int16 eUnderline
= sal_Int16();
295 if( (rValue
>>= eUnderline
) && awt::FontUnderline::NONE
!=eUnderline
)
297 switch( eNewUnderline
)
299 case awt::FontUnderline::NONE
:
300 // keep existing line style
301 eNewUnderline
= eUnderline
;
303 case awt::FontUnderline::BOLD
:
304 // A double line style has priority over a bold line style,
305 // but not over the line style itself.
308 case awt::FontUnderline::SINGLE
:
310 case awt::FontUnderline::DOTTED
:
311 eNewUnderline
= awt::FontUnderline::BOLDDOTTED
;
313 case awt::FontUnderline::DASH
:
314 eNewUnderline
= awt::FontUnderline::BOLDDASH
;
316 case awt::FontUnderline::LONGDASH
:
317 eNewUnderline
= awt::FontUnderline::BOLDLONGDASH
;
319 case awt::FontUnderline::DASHDOT
:
320 eNewUnderline
= awt::FontUnderline::BOLDDASHDOT
;
322 case awt::FontUnderline::DASHDOTDOT
:
323 eNewUnderline
= awt::FontUnderline::BOLDDASHDOTDOT
;
325 case awt::FontUnderline::WAVE
:
326 eNewUnderline
= awt::FontUnderline::BOLDWAVE
;
329 // a doube line style overwrites a bold one
330 eNewUnderline
= eUnderline
;
335 OSL_ENSURE( bRet
, "unexpected line width value" );
338 if( eNewUnderline
!= eUnderline
)
339 rValue
<<= (sal_Int16
)eNewUnderline
;
343 rValue
<<= (sal_Int16
)eNewUnderline
;
350 bool XMLUnderlineWidthPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
353 sal_Int16 nValue
= sal_Int16();
356 if( (rValue
>>= nValue
) && (awt::FontUnderline::NONE
!= nValue
) )
358 bRet
= SvXMLUnitConverter::convertEnum(
359 aOut
, (sal_uInt16
)nValue
, pXML_UnderlineWidth_Enum
);
361 rStrExpValue
= aOut
.makeStringAndClear();
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */