Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <undlihdl.hxx>
21 : #include <xmloff/xmltoken.hxx>
22 : #include <xmloff/xmluconv.hxx>
23 : #include <rtl/ustrbuf.hxx>
24 :
25 :
26 : #include <com/sun/star/uno/Any.hxx>
27 : #include <com/sun/star/awt/FontUnderline.hpp>
28 :
29 :
30 : using namespace ::com::sun::star;
31 : using namespace ::com::sun::star::awt;
32 : using namespace ::xmloff::token;
33 :
34 : SvXMLEnumMapEntry const pXML_UnderlineType_Enum[] =
35 : {
36 : { XML_NONE, awt::FontUnderline::NONE },
37 : { XML_SINGLE, awt::FontUnderline::SINGLE },
38 : { XML_DOUBLE, awt::FontUnderline::DOUBLE },
39 : { XML_SINGLE, awt::FontUnderline::DOTTED },
40 : { XML_SINGLE, awt::FontUnderline::DASH },
41 : { XML_SINGLE, awt::FontUnderline::LONGDASH },
42 : { XML_SINGLE, awt::FontUnderline::DASHDOT },
43 : { XML_SINGLE, awt::FontUnderline::DASHDOTDOT },
44 : { XML_SINGLE, awt::FontUnderline::WAVE },
45 : { XML_SINGLE, awt::FontUnderline::BOLD },
46 : { XML_SINGLE, awt::FontUnderline::BOLDDOTTED },
47 : { XML_SINGLE, awt::FontUnderline::BOLDDASH },
48 : { XML_SINGLE, awt::FontUnderline::BOLDLONGDASH },
49 : { XML_SINGLE, awt::FontUnderline::BOLDDASHDOT },
50 : { XML_SINGLE, awt::FontUnderline::BOLDDASHDOTDOT },
51 : { XML_SINGLE, awt::FontUnderline::BOLDWAVE },
52 : { XML_DOUBLE, awt::FontUnderline::DOUBLEWAVE },
53 : { XML_SINGLE, awt::FontUnderline::SMALLWAVE },
54 : { XML_TOKEN_INVALID, 0 }
55 : };
56 :
57 : SvXMLEnumMapEntry const pXML_UnderlineStyle_Enum[] =
58 : {
59 : { XML_NONE, awt::FontUnderline::NONE },
60 : { XML_SOLID, awt::FontUnderline::SINGLE },
61 : { XML_SOLID, awt::FontUnderline::DOUBLE },
62 : { XML_DOTTED, awt::FontUnderline::DOTTED },
63 : { XML_DASH, awt::FontUnderline::DASH },
64 : { XML_LONG_DASH, awt::FontUnderline::LONGDASH },
65 : { XML_DOT_DASH, awt::FontUnderline::DASHDOT },
66 : { XML_DOT_DOT_DASH, awt::FontUnderline::DASHDOTDOT },
67 : { XML_WAVE, awt::FontUnderline::WAVE },
68 : { XML_SOLID, awt::FontUnderline::BOLD },
69 : { XML_DOTTED, awt::FontUnderline::BOLDDOTTED },
70 : { XML_DASH, awt::FontUnderline::BOLDDASH },
71 : { XML_LONG_DASH, awt::FontUnderline::BOLDLONGDASH },
72 : { XML_DOT_DASH, awt::FontUnderline::BOLDDASHDOT },
73 : { XML_DOT_DOT_DASH, awt::FontUnderline::BOLDDASHDOTDOT },
74 : { XML_WAVE, awt::FontUnderline::BOLDWAVE },
75 : { XML_WAVE, awt::FontUnderline::DOUBLEWAVE },
76 : { XML_SMALL_WAVE, awt::FontUnderline::SMALLWAVE },
77 : { XML_TOKEN_INVALID, 0 }
78 : };
79 :
80 : SvXMLEnumMapEntry const pXML_UnderlineWidth_Enum[] =
81 : {
82 : { XML_AUTO, awt::FontUnderline::NONE },
83 : { XML_AUTO, awt::FontUnderline::SINGLE },
84 : { XML_AUTO, awt::FontUnderline::DOUBLE },
85 : { XML_AUTO, awt::FontUnderline::DOTTED },
86 : { XML_AUTO, awt::FontUnderline::DASH },
87 : { XML_AUTO, awt::FontUnderline::LONGDASH },
88 : { XML_AUTO, awt::FontUnderline::DASHDOT },
89 : { XML_AUTO, awt::FontUnderline::DASHDOTDOT },
90 : { XML_AUTO, awt::FontUnderline::WAVE },
91 : { XML_BOLD, awt::FontUnderline::BOLD },
92 : { XML_BOLD, awt::FontUnderline::BOLDDOTTED },
93 : { XML_BOLD, awt::FontUnderline::BOLDDASH },
94 : { XML_BOLD, awt::FontUnderline::BOLDLONGDASH },
95 : { XML_BOLD, awt::FontUnderline::BOLDDASHDOT },
96 : { XML_BOLD, awt::FontUnderline::BOLDDASHDOTDOT },
97 : { XML_BOLD, awt::FontUnderline::BOLDWAVE },
98 : { XML_AUTO, awt::FontUnderline::DOUBLEWAVE },
99 : { XML_THIN, awt::FontUnderline::NONE },
100 : { XML_MEDIUM, awt::FontUnderline::NONE },
101 : { XML_THICK, awt::FontUnderline::BOLD},
102 : { XML_TOKEN_INVALID, 0 }
103 : };
104 :
105 :
106 :
107 : ///////////////////////////////////////////////////////////////////////////////
108 : //
109 : // class XMLUnderlineTypePropHdl
110 : //
111 :
112 8154 : XMLUnderlineTypePropHdl::~XMLUnderlineTypePropHdl()
113 : {
114 : // nothing to do
115 8154 : }
116 :
117 1 : sal_Bool XMLUnderlineTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
118 : {
119 : sal_uInt16 eNewUnderline;
120 : sal_Bool bRet = SvXMLUnitConverter::convertEnum(
121 1 : eNewUnderline, rStrImpValue, pXML_UnderlineType_Enum );
122 1 : if( bRet )
123 : {
124 : // multi property: style and width might be set already.
125 : // If the old value is NONE, the new is used unchanged.
126 1 : sal_Int16 eUnderline = sal_Int16();
127 1 : if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline )
128 : {
129 1 : switch( eNewUnderline )
130 : {
131 : case awt::FontUnderline::NONE:
132 : case awt::FontUnderline::SINGLE:
133 : // keep existing line style
134 0 : eNewUnderline = eUnderline;
135 0 : break;
136 : case awt::FontUnderline::DOUBLE:
137 : // A double line style has priority over a bold line style,
138 : // but not over the line style itself.
139 1 : switch( eUnderline )
140 : {
141 : case awt::FontUnderline::SINGLE:
142 : case awt::FontUnderline::BOLD:
143 1 : break;
144 : case awt::FontUnderline::WAVE:
145 : case awt::FontUnderline::BOLDWAVE:
146 0 : eNewUnderline = awt::FontUnderline::DOUBLEWAVE;
147 0 : break;
148 : default:
149 : // If a double line style is not supported for the existing
150 : // value, keep the new one
151 0 : eNewUnderline = eUnderline;
152 0 : break;
153 : }
154 1 : break;
155 : default:
156 : OSL_ENSURE( bRet, "unexpected line type value" );
157 0 : break;
158 : }
159 1 : if( eNewUnderline != eUnderline )
160 1 : rValue <<= (sal_Int16)eNewUnderline;
161 : }
162 : else
163 : {
164 0 : rValue <<= (sal_Int16)eNewUnderline;
165 : }
166 : }
167 :
168 1 : return bRet;
169 : }
170 :
171 38 : sal_Bool XMLUnderlineTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
172 : {
173 38 : sal_Bool bRet = sal_False;
174 38 : sal_Int16 nValue = sal_Int16();
175 38 : OUStringBuffer aOut;
176 :
177 76 : if( (rValue >>= nValue) &&
178 76 : (awt::FontUnderline::DOUBLE == nValue ||
179 38 : awt::FontUnderline::DOUBLEWAVE == nValue) )
180 : {
181 : bRet = SvXMLUnitConverter::convertEnum(
182 0 : aOut, (sal_uInt16)nValue, pXML_UnderlineType_Enum );
183 0 : if( bRet )
184 0 : rStrExpValue = aOut.makeStringAndClear();
185 : }
186 :
187 38 : return bRet;
188 : }
189 :
190 : ///////////////////////////////////////////////////////////////////////////////
191 : //
192 : // class XMLUnderlineStylePropHdl
193 : //
194 :
195 8154 : XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl()
196 : {
197 : // nothing to do
198 8154 : }
199 :
200 160 : sal_Bool XMLUnderlineStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
201 : {
202 : sal_uInt16 eNewUnderline;
203 : sal_Bool bRet = SvXMLUnitConverter::convertEnum(
204 160 : eNewUnderline, rStrImpValue, pXML_UnderlineStyle_Enum );
205 160 : if( bRet )
206 : {
207 : // multi property: style and width might be set already.
208 : // If the old value is NONE, the new is used unchanged.
209 160 : sal_Int16 eUnderline = sal_Int16();
210 160 : if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline )
211 : {
212 0 : switch( eNewUnderline )
213 : {
214 : case awt::FontUnderline::NONE:
215 : case awt::FontUnderline::SINGLE:
216 : // keep double or bold line style
217 0 : eNewUnderline = eUnderline;
218 : case awt::FontUnderline::DOTTED:
219 : // The line style has priority over a double type.
220 0 : if( awt::FontUnderline::BOLD == eUnderline )
221 0 : eNewUnderline = awt::FontUnderline::BOLDDOTTED;
222 0 : break;
223 : case awt::FontUnderline::DASH:
224 0 : if( awt::FontUnderline::BOLD == eUnderline )
225 0 : eNewUnderline = awt::FontUnderline::BOLDDASH;
226 0 : break;
227 : case awt::FontUnderline::LONGDASH:
228 0 : if( awt::FontUnderline::BOLD == eUnderline )
229 0 : eNewUnderline = awt::FontUnderline::BOLDLONGDASH;
230 0 : break;
231 : case awt::FontUnderline::DASHDOT:
232 0 : if( awt::FontUnderline::BOLD == eUnderline )
233 0 : eNewUnderline = awt::FontUnderline::BOLDDASHDOT;
234 0 : break;
235 : case awt::FontUnderline::DASHDOTDOT:
236 0 : if( awt::FontUnderline::BOLD == eUnderline )
237 0 : eNewUnderline = awt::FontUnderline::BOLDDASHDOTDOT;
238 0 : break;
239 : case awt::FontUnderline::WAVE:
240 0 : if( awt::FontUnderline::BOLD == eUnderline )
241 0 : eNewUnderline = awt::FontUnderline::BOLDWAVE;
242 0 : break;
243 : case awt::FontUnderline::SMALLWAVE:
244 : // SMALLWAVE is not used
245 : default:
246 : OSL_ENSURE( bRet, "unexpected line style value" );
247 0 : break;
248 : }
249 0 : if( eNewUnderline != eUnderline )
250 0 : rValue <<= (sal_Int16)eNewUnderline;
251 : }
252 : else
253 : {
254 160 : rValue <<= (sal_Int16)eNewUnderline;
255 : }
256 : }
257 :
258 160 : return bRet;
259 : }
260 :
261 38 : sal_Bool XMLUnderlineStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
262 : {
263 38 : sal_Bool bRet = sal_False;
264 38 : sal_Int16 nValue = sal_Int16();
265 38 : OUStringBuffer aOut;
266 :
267 38 : if( rValue >>= nValue )
268 : {
269 : bRet = SvXMLUnitConverter::convertEnum(
270 38 : aOut, (sal_uInt16)nValue, pXML_UnderlineStyle_Enum );
271 38 : if( bRet )
272 38 : rStrExpValue = aOut.makeStringAndClear();
273 : }
274 :
275 38 : return bRet;
276 : }
277 :
278 : ///////////////////////////////////////////////////////////////////////////////
279 : //
280 : // class XMLUnderlineWidthPropHdl
281 : //
282 :
283 8154 : XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl()
284 : {
285 : // nothing to do
286 8154 : }
287 :
288 81 : sal_Bool XMLUnderlineWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
289 : {
290 : sal_uInt16 eNewUnderline;
291 : sal_Bool bRet = SvXMLUnitConverter::convertEnum(
292 81 : eNewUnderline, rStrImpValue, pXML_UnderlineWidth_Enum );
293 81 : if( bRet )
294 : {
295 : // multi property: style and width might be set already.
296 : // If the old value is NONE, the new is used unchanged.
297 81 : sal_Int16 eUnderline = sal_Int16();
298 81 : if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline )
299 : {
300 81 : switch( eNewUnderline )
301 : {
302 : case awt::FontUnderline::NONE:
303 : // keep existing line style
304 81 : eNewUnderline = eUnderline;
305 81 : break;
306 : case awt::FontUnderline::BOLD:
307 : // A double line style has priority over a bold line style,
308 : // but not over the line style itself.
309 0 : switch( eUnderline )
310 : {
311 : case awt::FontUnderline::SINGLE:
312 0 : break;
313 : case awt::FontUnderline::DOTTED:
314 0 : eNewUnderline = awt::FontUnderline::BOLDDOTTED;
315 0 : break;
316 : case awt::FontUnderline::DASH:
317 0 : eNewUnderline = awt::FontUnderline::BOLDDASH;
318 0 : break;
319 : case awt::FontUnderline::LONGDASH:
320 0 : eNewUnderline = awt::FontUnderline::BOLDLONGDASH;
321 0 : break;
322 : case awt::FontUnderline::DASHDOT:
323 0 : eNewUnderline = awt::FontUnderline::BOLDDASHDOT;
324 0 : break;
325 : case awt::FontUnderline::DASHDOTDOT:
326 0 : eNewUnderline = awt::FontUnderline::BOLDDASHDOTDOT;
327 0 : break;
328 : case awt::FontUnderline::WAVE:
329 0 : eNewUnderline = awt::FontUnderline::BOLDWAVE;
330 0 : break;
331 : default:
332 : // a doube line style overwrites a bold one
333 0 : eNewUnderline = eUnderline;
334 0 : break;
335 : }
336 0 : break;
337 : default:
338 : OSL_ENSURE( bRet, "unexpected line width value" );
339 0 : break;
340 : }
341 81 : if( eNewUnderline != eUnderline )
342 0 : rValue <<= (sal_Int16)eNewUnderline;
343 : }
344 : else
345 : {
346 0 : rValue <<= (sal_Int16)eNewUnderline;
347 : }
348 : }
349 :
350 81 : return bRet;
351 : }
352 :
353 38 : sal_Bool XMLUnderlineWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
354 : {
355 38 : sal_Bool bRet = sal_False;
356 38 : sal_Int16 nValue = sal_Int16();
357 38 : OUStringBuffer aOut;
358 :
359 38 : if( (rValue >>= nValue) && (awt::FontUnderline::NONE != nValue) )
360 : {
361 : bRet = SvXMLUnitConverter::convertEnum(
362 8 : aOut, (sal_uInt16)nValue, pXML_UnderlineWidth_Enum );
363 8 : if( bRet )
364 8 : rStrExpValue = aOut.makeStringAndClear();
365 : }
366 :
367 38 : return bRet;
368 : }
369 :
370 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|