Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <undlihdl.hxx>
30 : : #include <xmloff/xmltoken.hxx>
31 : : #include <xmloff/xmluconv.hxx>
32 : : #include <rtl/ustrbuf.hxx>
33 : :
34 : :
35 : : #include <com/sun/star/uno/Any.hxx>
36 : : #include <com/sun/star/awt/FontUnderline.hpp>
37 : :
38 : : using ::rtl::OUString;
39 : : using ::rtl::OUStringBuffer;
40 : :
41 : : using namespace ::com::sun::star;
42 : : using namespace ::com::sun::star::awt;
43 : : using namespace ::xmloff::token;
44 : :
45 : : SvXMLEnumMapEntry const pXML_UnderlineType_Enum[] =
46 : : {
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 }
66 : : };
67 : :
68 : : SvXMLEnumMapEntry const pXML_UnderlineStyle_Enum[] =
69 : : {
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 }
89 : : };
90 : :
91 : : SvXMLEnumMapEntry const pXML_UnderlineWidth_Enum[] =
92 : : {
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 }
114 : : };
115 : :
116 : :
117 : :
118 : : ///////////////////////////////////////////////////////////////////////////////
119 : : //
120 : : // class XMLUnderlineTypePropHdl
121 : : //
122 : :
123 : 4973 : XMLUnderlineTypePropHdl::~XMLUnderlineTypePropHdl()
124 : : {
125 : : // nothing to do
126 [ - + ]: 9946 : }
127 : :
128 : 0 : sal_Bool XMLUnderlineTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
129 : : {
130 : : sal_uInt16 eNewUnderline;
131 : : sal_Bool bRet = SvXMLUnitConverter::convertEnum(
132 [ # # ]: 0 : eNewUnderline, rStrImpValue, pXML_UnderlineType_Enum );
133 [ # # ]: 0 : if( bRet )
134 : : {
135 : : // multi property: style and width might be set already.
136 : : // If the old value is NONE, the new is used unchanged.
137 : 0 : sal_Int16 eUnderline = sal_Int16();
138 [ # # ][ # # ]: 0 : if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline )
[ # # ]
139 : : {
140 [ # # # ]: 0 : switch( eNewUnderline )
141 : : {
142 : : case FontUnderline::NONE:
143 : : case FontUnderline::SINGLE:
144 : : // keep existing line style
145 : 0 : eNewUnderline = eUnderline;
146 : 0 : 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 [ # # # ]: 0 : switch( eUnderline )
151 : : {
152 : : case FontUnderline::SINGLE:
153 : : case FontUnderline::BOLD:
154 : 0 : break;
155 : : case FontUnderline::WAVE:
156 : : case FontUnderline::BOLDWAVE:
157 : 0 : eNewUnderline = FontUnderline::DOUBLEWAVE;
158 : 0 : break;
159 : : default:
160 : : // If a double line style is not supported for the existing
161 : : // value, keep the new one
162 : 0 : eNewUnderline = eUnderline;
163 : 0 : break;
164 : : }
165 : 0 : break;
166 : : default:
167 : : OSL_ENSURE( bRet, "unexpected line type value" );
168 : 0 : break;
169 : : }
170 [ # # ]: 0 : if( eNewUnderline != eUnderline )
171 [ # # ]: 0 : rValue <<= (sal_Int16)eNewUnderline;
172 : : }
173 : : else
174 : : {
175 [ # # ]: 0 : rValue <<= (sal_Int16)eNewUnderline;
176 : : }
177 : : }
178 : :
179 : 0 : return bRet;
180 : : }
181 : :
182 : 62 : sal_Bool XMLUnderlineTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
183 : : {
184 : 62 : sal_Bool bRet = sal_False;
185 : 62 : sal_Int16 nValue = sal_Int16();
186 : 62 : OUStringBuffer aOut;
187 : :
188 [ + - ][ - + ]: 62 : if( (rValue >>= nValue) &&
[ - + ][ + - ]
189 : : (FontUnderline::DOUBLE == nValue ||
190 : : FontUnderline::DOUBLEWAVE == nValue) )
191 : : {
192 : : bRet = SvXMLUnitConverter::convertEnum(
193 [ # # ]: 0 : aOut, (sal_uInt16)nValue, pXML_UnderlineType_Enum );
194 [ # # ]: 0 : if( bRet )
195 [ # # ]: 0 : rStrExpValue = aOut.makeStringAndClear();
196 : : }
197 : :
198 : 62 : return bRet;
199 : : }
200 : :
201 : : ///////////////////////////////////////////////////////////////////////////////
202 : : //
203 : : // class XMLUnderlineStylePropHdl
204 : : //
205 : :
206 : 4973 : XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl()
207 : : {
208 : : // nothing to do
209 [ - + ]: 9946 : }
210 : :
211 : 192 : sal_Bool XMLUnderlineStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
212 : : {
213 : : sal_uInt16 eNewUnderline;
214 : : sal_Bool bRet = SvXMLUnitConverter::convertEnum(
215 [ + - ]: 192 : eNewUnderline, rStrImpValue, pXML_UnderlineStyle_Enum );
216 [ + - ]: 192 : if( bRet )
217 : : {
218 : : // multi property: style and width might be set already.
219 : : // If the old value is NONE, the new is used unchanged.
220 : 192 : sal_Int16 eUnderline = sal_Int16();
221 [ - + ][ # # ]: 192 : if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline )
[ - + ]
222 : : {
223 [ # # # # : 0 : switch( eNewUnderline )
# # # # ]
224 : : {
225 : : case FontUnderline::NONE:
226 : : case FontUnderline::SINGLE:
227 : : // keep double or bold line style
228 : 0 : eNewUnderline = eUnderline;
229 : : case FontUnderline::DOTTED:
230 : : // The line style has priority over a double type.
231 [ # # ]: 0 : if( FontUnderline::BOLD == eUnderline )
232 : 0 : eNewUnderline = FontUnderline::BOLDDOTTED;
233 : 0 : break;
234 : : case FontUnderline::DASH:
235 [ # # ]: 0 : if( FontUnderline::BOLD == eUnderline )
236 : 0 : eNewUnderline = FontUnderline::BOLDDASH;
237 : 0 : break;
238 : : case FontUnderline::LONGDASH:
239 [ # # ]: 0 : if( FontUnderline::BOLD == eUnderline )
240 : 0 : eNewUnderline = FontUnderline::BOLDLONGDASH;
241 : 0 : break;
242 : : case FontUnderline::DASHDOT:
243 [ # # ]: 0 : if( FontUnderline::BOLD == eUnderline )
244 : 0 : eNewUnderline = FontUnderline::BOLDDASHDOT;
245 : 0 : break;
246 : : case FontUnderline::DASHDOTDOT:
247 [ # # ]: 0 : if( FontUnderline::BOLD == eUnderline )
248 : 0 : eNewUnderline = FontUnderline::BOLDDASHDOTDOT;
249 : 0 : break;
250 : : case FontUnderline::WAVE:
251 [ # # ]: 0 : if( FontUnderline::BOLD == eUnderline )
252 : 0 : eNewUnderline = FontUnderline::BOLDWAVE;
253 : 0 : break;
254 : : case FontUnderline::SMALLWAVE:
255 : : // SMALLWAVE is not used
256 : : default:
257 : : OSL_ENSURE( bRet, "unexpected line style value" );
258 : 0 : break;
259 : : }
260 [ # # ]: 0 : if( eNewUnderline != eUnderline )
261 [ # # ]: 0 : rValue <<= (sal_Int16)eNewUnderline;
262 : : }
263 : : else
264 : : {
265 [ + - ]: 192 : rValue <<= (sal_Int16)eNewUnderline;
266 : : }
267 : : }
268 : :
269 : 192 : return bRet;
270 : : }
271 : :
272 : 62 : sal_Bool XMLUnderlineStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
273 : : {
274 : 62 : sal_Bool bRet = sal_False;
275 : 62 : sal_Int16 nValue = sal_Int16();
276 : 62 : OUStringBuffer aOut;
277 : :
278 [ + - ]: 62 : if( rValue >>= nValue )
279 : : {
280 : : bRet = SvXMLUnitConverter::convertEnum(
281 [ + - ]: 62 : aOut, (sal_uInt16)nValue, pXML_UnderlineStyle_Enum );
282 [ + - ]: 62 : if( bRet )
283 [ + - ]: 62 : rStrExpValue = aOut.makeStringAndClear();
284 : : }
285 : :
286 : 62 : return bRet;
287 : : }
288 : :
289 : : ///////////////////////////////////////////////////////////////////////////////
290 : : //
291 : : // class XMLUnderlineWidthPropHdl
292 : : //
293 : :
294 : 4973 : XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl()
295 : : {
296 : : // nothing to do
297 [ - + ]: 9946 : }
298 : :
299 : 104 : sal_Bool XMLUnderlineWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
300 : : {
301 : : sal_uInt16 eNewUnderline;
302 : : sal_Bool bRet = SvXMLUnitConverter::convertEnum(
303 [ + - ]: 104 : eNewUnderline, rStrImpValue, pXML_UnderlineWidth_Enum );
304 [ + - ]: 104 : if( bRet )
305 : : {
306 : : // multi property: style and width might be set already.
307 : : // If the old value is NONE, the new is used unchanged.
308 : 104 : sal_Int16 eUnderline = sal_Int16();
309 [ + - ][ + - ]: 104 : if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline )
[ + - ]
310 : : {
311 [ + - - ]: 104 : switch( eNewUnderline )
312 : : {
313 : : case FontUnderline::NONE:
314 : : // keep existing line style
315 : 104 : eNewUnderline = eUnderline;
316 : 104 : 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 [ # # # # : 0 : switch( eUnderline )
# # # # ]
321 : : {
322 : : case FontUnderline::SINGLE:
323 : 0 : break;
324 : : case FontUnderline::DOTTED:
325 : 0 : eNewUnderline = FontUnderline::BOLDDOTTED;
326 : 0 : break;
327 : : case FontUnderline::DASH:
328 : 0 : eNewUnderline = FontUnderline::BOLDDASH;
329 : 0 : break;
330 : : case FontUnderline::LONGDASH:
331 : 0 : eNewUnderline = FontUnderline::BOLDLONGDASH;
332 : 0 : break;
333 : : case FontUnderline::DASHDOT:
334 : 0 : eNewUnderline = FontUnderline::BOLDDASHDOT;
335 : 0 : break;
336 : : case FontUnderline::DASHDOTDOT:
337 : 0 : eNewUnderline = FontUnderline::BOLDDASHDOTDOT;
338 : 0 : break;
339 : : case FontUnderline::WAVE:
340 : 0 : eNewUnderline = FontUnderline::BOLDWAVE;
341 : 0 : break;
342 : : default:
343 : : // a doube line style overwrites a bold one
344 : 0 : eNewUnderline = eUnderline;
345 : 0 : break;
346 : : }
347 : 0 : break;
348 : : default:
349 : : OSL_ENSURE( bRet, "unexpected line width value" );
350 : 0 : break;
351 : : }
352 [ - + ]: 104 : if( eNewUnderline != eUnderline )
353 [ # # ]: 0 : rValue <<= (sal_Int16)eNewUnderline;
354 : : }
355 : : else
356 : : {
357 [ # # ]: 104 : rValue <<= (sal_Int16)eNewUnderline;
358 : : }
359 : : }
360 : :
361 : 104 : return bRet;
362 : : }
363 : :
364 : 62 : sal_Bool XMLUnderlineWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
365 : : {
366 : 62 : sal_Bool bRet = sal_False;
367 : 62 : sal_Int16 nValue = sal_Int16();
368 : 62 : OUStringBuffer aOut;
369 : :
370 [ + + ][ + + ]: 62 : if( (rValue >>= nValue) && (FontUnderline::NONE != nValue) )
[ + - ]
371 : : {
372 : : bRet = SvXMLUnitConverter::convertEnum(
373 [ + - ]: 4 : aOut, (sal_uInt16)nValue, pXML_UnderlineWidth_Enum );
374 [ + - ]: 4 : if( bRet )
375 [ + - ]: 4 : rStrExpValue = aOut.makeStringAndClear();
376 : : }
377 : :
378 : 62 : return bRet;
379 : : }
380 : :
381 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|