/src/libreoffice/xmloff/source/style/undlihdl.cxx
Line | Count | Source |
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 <xmloff/xmlement.hxx> |
24 | | #include <rtl/ustrbuf.hxx> |
25 | | #include <osl/diagnose.h> |
26 | | |
27 | | #include <com/sun/star/uno/Any.hxx> |
28 | | #include <com/sun/star/awt/FontUnderline.hpp> |
29 | | |
30 | | using namespace ::com::sun::star; |
31 | | using namespace ::com::sun::star::awt; |
32 | | using namespace ::xmloff::token; |
33 | | |
34 | | SvXMLEnumMapEntry<sal_uInt16> 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<sal_uInt16> 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<sal_uInt16> 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 | | XMLUnderlineTypePropHdl::~XMLUnderlineTypePropHdl() |
109 | 164k | { |
110 | | // nothing to do |
111 | 164k | } |
112 | | |
113 | | bool XMLUnderlineTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const |
114 | 415 | { |
115 | 415 | sal_uInt16 eNewUnderline(0); |
116 | 415 | bool bRet = SvXMLUnitConverter::convertEnum( |
117 | 415 | eNewUnderline, rStrImpValue, pXML_UnderlineType_Enum ); |
118 | 415 | if( bRet ) |
119 | 415 | { |
120 | | // multi property: style and width might be set already. |
121 | | // If the old value is NONE, the new is used unchanged. |
122 | 415 | sal_Int16 eUnderline = sal_Int16(); |
123 | 415 | if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline ) |
124 | 0 | { |
125 | 0 | switch( eNewUnderline ) |
126 | 0 | { |
127 | 0 | case awt::FontUnderline::NONE: |
128 | 0 | case awt::FontUnderline::SINGLE: |
129 | | // keep existing line style |
130 | 0 | eNewUnderline = eUnderline; |
131 | 0 | break; |
132 | 0 | case awt::FontUnderline::DOUBLE: |
133 | | // A double line style has priority over a bold line style, |
134 | | // but not over the line style itself. |
135 | 0 | switch( eUnderline ) |
136 | 0 | { |
137 | 0 | case awt::FontUnderline::SINGLE: |
138 | 0 | case awt::FontUnderline::BOLD: |
139 | 0 | break; |
140 | 0 | case awt::FontUnderline::WAVE: |
141 | 0 | case awt::FontUnderline::BOLDWAVE: |
142 | 0 | eNewUnderline = awt::FontUnderline::DOUBLEWAVE; |
143 | 0 | break; |
144 | 0 | default: |
145 | | // If a double line style is not supported for the existing |
146 | | // value, keep the new one |
147 | 0 | eNewUnderline = eUnderline; |
148 | 0 | break; |
149 | 0 | } |
150 | 0 | break; |
151 | 0 | default: |
152 | 0 | OSL_ENSURE( bRet, "unexpected line type value" ); |
153 | 0 | break; |
154 | 0 | } |
155 | 0 | if( eNewUnderline != eUnderline ) |
156 | 0 | rValue <<= static_cast<sal_Int16>(eNewUnderline); |
157 | 0 | } |
158 | 415 | else |
159 | 415 | { |
160 | 415 | rValue <<= static_cast<sal_Int16>(eNewUnderline); |
161 | 415 | } |
162 | 415 | } |
163 | | |
164 | 415 | return bRet; |
165 | 415 | } |
166 | | |
167 | | bool XMLUnderlineTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const |
168 | 1.09k | { |
169 | 1.09k | bool bRet = false; |
170 | 1.09k | sal_uInt16 nValue = sal_uInt16(); |
171 | | |
172 | 1.09k | if( (rValue >>= nValue) && |
173 | 1.09k | (awt::FontUnderline::DOUBLE == nValue || |
174 | 1.09k | awt::FontUnderline::DOUBLEWAVE == nValue) ) |
175 | 0 | { |
176 | 0 | OUStringBuffer aOut; |
177 | 0 | bRet = SvXMLUnitConverter::convertEnum( |
178 | 0 | aOut, nValue, pXML_UnderlineType_Enum ); |
179 | 0 | if( bRet ) |
180 | 0 | rStrExpValue = aOut.makeStringAndClear(); |
181 | 0 | } |
182 | | |
183 | 1.09k | return bRet; |
184 | 1.09k | } |
185 | | |
186 | | |
187 | | |
188 | | |
189 | | XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl() |
190 | 164k | { |
191 | | // nothing to do |
192 | 164k | } |
193 | | |
194 | | bool XMLUnderlineStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const |
195 | 1.61k | { |
196 | 1.61k | sal_uInt16 eNewUnderline(0); |
197 | 1.61k | bool bRet = SvXMLUnitConverter::convertEnum( |
198 | 1.61k | eNewUnderline, rStrImpValue, pXML_UnderlineStyle_Enum ); |
199 | 1.61k | if( bRet ) |
200 | 1.58k | { |
201 | | // multi property: style and width might be set already. |
202 | | // If the old value is NONE, the new is used unchanged. |
203 | 1.58k | sal_Int16 eUnderline = sal_Int16(); |
204 | 1.58k | if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline ) |
205 | 0 | { |
206 | 0 | switch( eNewUnderline ) |
207 | 0 | { |
208 | 0 | case awt::FontUnderline::NONE: |
209 | 0 | case awt::FontUnderline::SINGLE: |
210 | | // keep double or bold line style |
211 | 0 | eNewUnderline = eUnderline; |
212 | 0 | break; |
213 | 0 | case awt::FontUnderline::DOTTED: |
214 | | // The line style has priority over a double type. |
215 | 0 | if( awt::FontUnderline::BOLD == eUnderline ) |
216 | 0 | eNewUnderline = awt::FontUnderline::BOLDDOTTED; |
217 | 0 | break; |
218 | 0 | case awt::FontUnderline::DASH: |
219 | 0 | if( awt::FontUnderline::BOLD == eUnderline ) |
220 | 0 | eNewUnderline = awt::FontUnderline::BOLDDASH; |
221 | 0 | break; |
222 | 0 | case awt::FontUnderline::LONGDASH: |
223 | 0 | if( awt::FontUnderline::BOLD == eUnderline ) |
224 | 0 | eNewUnderline = awt::FontUnderline::BOLDLONGDASH; |
225 | 0 | break; |
226 | 0 | case awt::FontUnderline::DASHDOT: |
227 | 0 | if( awt::FontUnderline::BOLD == eUnderline ) |
228 | 0 | eNewUnderline = awt::FontUnderline::BOLDDASHDOT; |
229 | 0 | break; |
230 | 0 | case awt::FontUnderline::DASHDOTDOT: |
231 | 0 | if( awt::FontUnderline::BOLD == eUnderline ) |
232 | 0 | eNewUnderline = awt::FontUnderline::BOLDDASHDOTDOT; |
233 | 0 | break; |
234 | 0 | case awt::FontUnderline::WAVE: |
235 | 0 | if( awt::FontUnderline::DOUBLE == eUnderline ) |
236 | 0 | eNewUnderline = awt::FontUnderline::DOUBLEWAVE; |
237 | 0 | else if( awt::FontUnderline::BOLD == eUnderline ) |
238 | 0 | eNewUnderline = awt::FontUnderline::BOLDWAVE; |
239 | 0 | break; |
240 | 0 | case awt::FontUnderline::SMALLWAVE: |
241 | | // SMALLWAVE is not used |
242 | 0 | default: |
243 | 0 | OSL_ENSURE( bRet, "unexpected line style value" ); |
244 | 0 | break; |
245 | 0 | } |
246 | 0 | if( eNewUnderline != eUnderline ) |
247 | 0 | rValue <<= static_cast<sal_Int16>(eNewUnderline); |
248 | 0 | } |
249 | 1.58k | else |
250 | 1.58k | { |
251 | 1.58k | rValue <<= static_cast<sal_Int16>(eNewUnderline); |
252 | 1.58k | } |
253 | 1.58k | } |
254 | | |
255 | 1.61k | return bRet; |
256 | 1.61k | } |
257 | | |
258 | | bool XMLUnderlineStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const |
259 | 1.09k | { |
260 | 1.09k | bool bRet = false; |
261 | 1.09k | sal_uInt16 nValue = sal_uInt16(); |
262 | | |
263 | 1.09k | if( rValue >>= nValue ) |
264 | 1.09k | { |
265 | 1.09k | OUStringBuffer aOut; |
266 | 1.09k | bRet = SvXMLUnitConverter::convertEnum( |
267 | 1.09k | aOut, nValue, pXML_UnderlineStyle_Enum ); |
268 | 1.09k | if( bRet ) |
269 | 1.09k | rStrExpValue = aOut.makeStringAndClear(); |
270 | 1.09k | } |
271 | | |
272 | 1.09k | return bRet; |
273 | 1.09k | } |
274 | | |
275 | | |
276 | | |
277 | | |
278 | | XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl() |
279 | 164k | { |
280 | | // nothing to do |
281 | 164k | } |
282 | | |
283 | | bool XMLUnderlineWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const |
284 | 446 | { |
285 | 446 | sal_uInt16 eNewUnderline(0); |
286 | 446 | bool bRet = SvXMLUnitConverter::convertEnum( |
287 | 446 | eNewUnderline, rStrImpValue, pXML_UnderlineWidth_Enum ); |
288 | 446 | if( bRet ) |
289 | 443 | { |
290 | | // multi property: style and width might be set already. |
291 | | // If the old value is NONE, the new is used unchanged. |
292 | 443 | sal_Int16 eUnderline = sal_Int16(); |
293 | 443 | if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline ) |
294 | 429 | { |
295 | 429 | switch( eNewUnderline ) |
296 | 429 | { |
297 | 429 | case awt::FontUnderline::NONE: |
298 | | // keep existing line style |
299 | 429 | eNewUnderline = eUnderline; |
300 | 429 | break; |
301 | 0 | case awt::FontUnderline::BOLD: |
302 | | // A double line style has priority over a bold line style, |
303 | | // but not over the line style itself. |
304 | 0 | switch( eUnderline ) |
305 | 0 | { |
306 | 0 | case awt::FontUnderline::SINGLE: |
307 | 0 | break; |
308 | 0 | case awt::FontUnderline::DOTTED: |
309 | 0 | eNewUnderline = awt::FontUnderline::BOLDDOTTED; |
310 | 0 | break; |
311 | 0 | case awt::FontUnderline::DASH: |
312 | 0 | eNewUnderline = awt::FontUnderline::BOLDDASH; |
313 | 0 | break; |
314 | 0 | case awt::FontUnderline::LONGDASH: |
315 | 0 | eNewUnderline = awt::FontUnderline::BOLDLONGDASH; |
316 | 0 | break; |
317 | 0 | case awt::FontUnderline::DASHDOT: |
318 | 0 | eNewUnderline = awt::FontUnderline::BOLDDASHDOT; |
319 | 0 | break; |
320 | 0 | case awt::FontUnderline::DASHDOTDOT: |
321 | 0 | eNewUnderline = awt::FontUnderline::BOLDDASHDOTDOT; |
322 | 0 | break; |
323 | 0 | case awt::FontUnderline::WAVE: |
324 | 0 | eNewUnderline = awt::FontUnderline::BOLDWAVE; |
325 | 0 | break; |
326 | 0 | default: |
327 | | // a double line style overwrites a bold one |
328 | 0 | eNewUnderline = eUnderline; |
329 | 0 | break; |
330 | 0 | } |
331 | 0 | break; |
332 | 0 | default: |
333 | 0 | OSL_ENSURE( bRet, "unexpected line width value" ); |
334 | 0 | break; |
335 | 429 | } |
336 | 429 | if( eNewUnderline != eUnderline ) |
337 | 0 | rValue <<= static_cast<sal_Int16>(eNewUnderline); |
338 | 429 | } |
339 | 14 | else |
340 | 14 | { |
341 | 14 | rValue <<= static_cast<sal_Int16>(eNewUnderline); |
342 | 14 | } |
343 | 443 | } |
344 | | |
345 | 446 | return bRet; |
346 | 446 | } |
347 | | |
348 | | bool XMLUnderlineWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const |
349 | 1.09k | { |
350 | 1.09k | bool bRet = false; |
351 | 1.09k | sal_uInt16 nValue = sal_uInt16(); |
352 | | |
353 | 1.09k | if( (rValue >>= nValue) && (awt::FontUnderline::NONE != nValue) ) |
354 | 0 | { |
355 | 0 | OUStringBuffer aOut; |
356 | 0 | bRet = SvXMLUnitConverter::convertEnum( |
357 | 0 | aOut, nValue, pXML_UnderlineWidth_Enum ); |
358 | 0 | if( bRet ) |
359 | 0 | rStrExpValue = aOut.makeStringAndClear(); |
360 | 0 | } |
361 | | |
362 | 1.09k | return bRet; |
363 | 1.09k | } |
364 | | |
365 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |