tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / style / undlihdl.cxx
blob4d6482c4f4be7b3618143b672a4fc6c8a941aa8a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <xmloff/xmlement.hxx>
24 #include <rtl/ustrbuf.hxx>
25 #include <osl/diagnose.h>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/awt/FontUnderline.hpp>
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::awt;
32 using namespace ::xmloff::token;
34 SvXMLEnumMapEntry<sal_uInt16> const pXML_UnderlineType_Enum[] =
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 }
57 SvXMLEnumMapEntry<sal_uInt16> const pXML_UnderlineStyle_Enum[] =
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 }
80 SvXMLEnumMapEntry<sal_uInt16> const pXML_UnderlineWidth_Enum[] =
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 }
108 XMLUnderlineTypePropHdl::~XMLUnderlineTypePropHdl()
110 // nothing to do
113 bool XMLUnderlineTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
115 sal_uInt16 eNewUnderline(0);
116 bool bRet = SvXMLUnitConverter::convertEnum(
117 eNewUnderline, rStrImpValue, pXML_UnderlineType_Enum );
118 if( bRet )
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;
131 break;
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.
135 switch( eUnderline )
137 case awt::FontUnderline::SINGLE:
138 case awt::FontUnderline::BOLD:
139 break;
140 case awt::FontUnderline::WAVE:
141 case awt::FontUnderline::BOLDWAVE:
142 eNewUnderline = awt::FontUnderline::DOUBLEWAVE;
143 break;
144 default:
145 // If a double line style is not supported for the existing
146 // value, keep the new one
147 eNewUnderline = eUnderline;
148 break;
150 break;
151 default:
152 OSL_ENSURE( bRet, "unexpected line type value" );
153 break;
155 if( eNewUnderline != eUnderline )
156 rValue <<= static_cast<sal_Int16>(eNewUnderline);
158 else
160 rValue <<= static_cast<sal_Int16>(eNewUnderline);
164 return bRet;
167 bool XMLUnderlineTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
169 bool bRet = false;
170 sal_uInt16 nValue = sal_uInt16();
172 if( (rValue >>= nValue) &&
173 (awt::FontUnderline::DOUBLE == nValue ||
174 awt::FontUnderline::DOUBLEWAVE == nValue) )
176 OUStringBuffer aOut;
177 bRet = SvXMLUnitConverter::convertEnum(
178 aOut, nValue, pXML_UnderlineType_Enum );
179 if( bRet )
180 rStrExpValue = aOut.makeStringAndClear();
183 return bRet;
189 XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl()
191 // nothing to do
194 bool XMLUnderlineStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
196 sal_uInt16 eNewUnderline(0);
197 bool bRet = SvXMLUnitConverter::convertEnum(
198 eNewUnderline, rStrImpValue, pXML_UnderlineStyle_Enum );
199 if( bRet )
201 // multi property: style and width might be set already.
202 // If the old value is NONE, the new is used unchanged.
203 sal_Int16 eUnderline = sal_Int16();
204 if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline )
206 switch( eNewUnderline )
208 case awt::FontUnderline::NONE:
209 case awt::FontUnderline::SINGLE:
210 // keep double or bold line style
211 eNewUnderline = eUnderline;
212 break;
213 case awt::FontUnderline::DOTTED:
214 // The line style has priority over a double type.
215 if( awt::FontUnderline::BOLD == eUnderline )
216 eNewUnderline = awt::FontUnderline::BOLDDOTTED;
217 break;
218 case awt::FontUnderline::DASH:
219 if( awt::FontUnderline::BOLD == eUnderline )
220 eNewUnderline = awt::FontUnderline::BOLDDASH;
221 break;
222 case awt::FontUnderline::LONGDASH:
223 if( awt::FontUnderline::BOLD == eUnderline )
224 eNewUnderline = awt::FontUnderline::BOLDLONGDASH;
225 break;
226 case awt::FontUnderline::DASHDOT:
227 if( awt::FontUnderline::BOLD == eUnderline )
228 eNewUnderline = awt::FontUnderline::BOLDDASHDOT;
229 break;
230 case awt::FontUnderline::DASHDOTDOT:
231 if( awt::FontUnderline::BOLD == eUnderline )
232 eNewUnderline = awt::FontUnderline::BOLDDASHDOTDOT;
233 break;
234 case awt::FontUnderline::WAVE:
235 if( awt::FontUnderline::DOUBLE == eUnderline )
236 eNewUnderline = awt::FontUnderline::DOUBLEWAVE;
237 else if( awt::FontUnderline::BOLD == eUnderline )
238 eNewUnderline = awt::FontUnderline::BOLDWAVE;
239 break;
240 case awt::FontUnderline::SMALLWAVE:
241 // SMALLWAVE is not used
242 default:
243 OSL_ENSURE( bRet, "unexpected line style value" );
244 break;
246 if( eNewUnderline != eUnderline )
247 rValue <<= static_cast<sal_Int16>(eNewUnderline);
249 else
251 rValue <<= static_cast<sal_Int16>(eNewUnderline);
255 return bRet;
258 bool XMLUnderlineStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
260 bool bRet = false;
261 sal_uInt16 nValue = sal_uInt16();
263 if( rValue >>= nValue )
265 OUStringBuffer aOut;
266 bRet = SvXMLUnitConverter::convertEnum(
267 aOut, nValue, pXML_UnderlineStyle_Enum );
268 if( bRet )
269 rStrExpValue = aOut.makeStringAndClear();
272 return bRet;
278 XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl()
280 // nothing to do
283 bool XMLUnderlineWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
285 sal_uInt16 eNewUnderline(0);
286 bool bRet = SvXMLUnitConverter::convertEnum(
287 eNewUnderline, rStrImpValue, pXML_UnderlineWidth_Enum );
288 if( bRet )
290 // multi property: style and width might be set already.
291 // If the old value is NONE, the new is used unchanged.
292 sal_Int16 eUnderline = sal_Int16();
293 if( (rValue >>= eUnderline) && awt::FontUnderline::NONE!=eUnderline )
295 switch( eNewUnderline )
297 case awt::FontUnderline::NONE:
298 // keep existing line style
299 eNewUnderline = eUnderline;
300 break;
301 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 switch( eUnderline )
306 case awt::FontUnderline::SINGLE:
307 break;
308 case awt::FontUnderline::DOTTED:
309 eNewUnderline = awt::FontUnderline::BOLDDOTTED;
310 break;
311 case awt::FontUnderline::DASH:
312 eNewUnderline = awt::FontUnderline::BOLDDASH;
313 break;
314 case awt::FontUnderline::LONGDASH:
315 eNewUnderline = awt::FontUnderline::BOLDLONGDASH;
316 break;
317 case awt::FontUnderline::DASHDOT:
318 eNewUnderline = awt::FontUnderline::BOLDDASHDOT;
319 break;
320 case awt::FontUnderline::DASHDOTDOT:
321 eNewUnderline = awt::FontUnderline::BOLDDASHDOTDOT;
322 break;
323 case awt::FontUnderline::WAVE:
324 eNewUnderline = awt::FontUnderline::BOLDWAVE;
325 break;
326 default:
327 // a double line style overwrites a bold one
328 eNewUnderline = eUnderline;
329 break;
331 break;
332 default:
333 OSL_ENSURE( bRet, "unexpected line width value" );
334 break;
336 if( eNewUnderline != eUnderline )
337 rValue <<= static_cast<sal_Int16>(eNewUnderline);
339 else
341 rValue <<= static_cast<sal_Int16>(eNewUnderline);
345 return bRet;
348 bool XMLUnderlineWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
350 bool bRet = false;
351 sal_uInt16 nValue = sal_uInt16();
353 if( (rValue >>= nValue) && (awt::FontUnderline::NONE != nValue) )
355 OUStringBuffer aOut;
356 bRet = SvXMLUnitConverter::convertEnum(
357 aOut, nValue, pXML_UnderlineWidth_Enum );
358 if( bRet )
359 rStrExpValue = aOut.makeStringAndClear();
362 return bRet;
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */