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 <cdouthdl.hxx>
21 : #include <xmloff/xmltoken.hxx>
22 : #include <xmloff/xmluconv.hxx>
23 : #include <rtl/ustrbuf.hxx>
24 :
25 : #include <com/sun/star/awt/FontStrikeout.hpp>
26 : #include <com/sun/star/uno/Any.hxx>
27 :
28 :
29 : using namespace ::com::sun::star;
30 : using namespace ::com::sun::star::awt;
31 : using namespace ::xmloff::token;
32 :
33 : SvXMLEnumMapEntry pXML_CrossedoutType_Enum[] =
34 : {
35 : { XML_NONE, awt::FontStrikeout::NONE },
36 : { XML_SINGLE, awt::FontStrikeout::SINGLE },
37 : { XML_DOUBLE, awt::FontStrikeout::DOUBLE },
38 : { XML_SINGLE, awt::FontStrikeout::BOLD },
39 : { XML_SINGLE, awt::FontStrikeout::SLASH },
40 : { XML_SINGLE, awt::FontStrikeout::X },
41 : { XML_TOKEN_INVALID, 0 }
42 : };
43 :
44 : SvXMLEnumMapEntry pXML_CrossedoutStyle_Enum[] =
45 : {
46 : { XML_NONE, awt::FontStrikeout::NONE },
47 : { XML_SOLID, awt::FontStrikeout::SINGLE },
48 : { XML_SOLID, awt::FontStrikeout::DOUBLE },
49 : { XML_SOLID, awt::FontStrikeout::BOLD },
50 : { XML_SOLID, awt::FontStrikeout::SLASH },
51 : { XML_SOLID, awt::FontStrikeout::X },
52 : { XML_DOTTED, awt::FontStrikeout::SINGLE },
53 : { XML_DASH, awt::FontStrikeout::SINGLE },
54 : { XML_LONG_DASH, awt::FontStrikeout::SINGLE },
55 : { XML_DOT_DASH, awt::FontStrikeout::SINGLE },
56 : { XML_DOT_DOT_DASH, awt::FontStrikeout::SINGLE },
57 : { XML_WAVE, awt::FontStrikeout::SINGLE },
58 : { XML_TOKEN_INVALID, 0 }
59 : };
60 :
61 : SvXMLEnumMapEntry pXML_CrossedoutWidth_Enum[] =
62 : {
63 : { XML_AUTO, awt::FontStrikeout::NONE },
64 : { XML_AUTO, awt::FontStrikeout::SINGLE },
65 : { XML_AUTO, awt::FontStrikeout::DOUBLE },
66 : { XML_BOLD, awt::FontStrikeout::BOLD },
67 : { XML_AUTO, awt::FontStrikeout::SLASH },
68 : { XML_AUTO, awt::FontStrikeout::X },
69 : { XML_THIN, awt::FontStrikeout::NONE },
70 : { XML_MEDIUM, awt::FontStrikeout::NONE },
71 : { XML_THICK, awt::FontStrikeout::NONE },
72 : { XML_TOKEN_INVALID, 0 }
73 : };
74 :
75 : ///////////////////////////////////////////////////////////////////////////////
76 : //
77 : // class XMLCrossedOutTypePropHdl
78 : //
79 :
80 4292 : XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl()
81 : {
82 : // nothing to do
83 4292 : }
84 :
85 2 : sal_Bool XMLCrossedOutTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
86 : {
87 : sal_uInt16 eNewStrikeout;
88 : sal_Bool bRet = SvXMLUnitConverter::convertEnum(
89 2 : eNewStrikeout, rStrImpValue, pXML_CrossedoutType_Enum );
90 2 : if( bRet )
91 : {
92 : // multi property: style and width might be set already.
93 : // If the old value is NONE, the new is used unchanged.
94 2 : sal_Int16 eStrikeout = sal_Int16();
95 2 : if( (rValue >>= eStrikeout) && awt::FontStrikeout::NONE!=eStrikeout )
96 : {
97 2 : switch( eNewStrikeout )
98 : {
99 : case awt::FontStrikeout::NONE:
100 : case awt::FontStrikeout::SINGLE:
101 : // keep existing line style
102 0 : eNewStrikeout = eStrikeout;
103 0 : break;
104 : case awt::FontStrikeout::DOUBLE:
105 : // A double line style has priority over a solid or a bold
106 : // line style,
107 : // but not about any other line style
108 2 : switch( eStrikeout )
109 : {
110 : case awt::FontStrikeout::SINGLE:
111 : case awt::FontStrikeout::BOLD:
112 2 : break;
113 : default:
114 : // If a double line style is not supported for the existing
115 : // value, keep the new one
116 0 : eNewStrikeout = eStrikeout;
117 0 : break;
118 : }
119 2 : break;
120 : default:
121 : OSL_ENSURE( bRet, "unexpected line type value" );
122 0 : break;
123 : }
124 2 : if( eNewStrikeout != eStrikeout )
125 2 : rValue <<= (sal_Int16)eNewStrikeout;
126 : }
127 : else
128 : {
129 0 : rValue <<= (sal_Int16)eNewStrikeout;
130 : }
131 : }
132 :
133 2 : return bRet;
134 : }
135 :
136 15 : sal_Bool XMLCrossedOutTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
137 : {
138 15 : sal_Bool bRet = sal_False;
139 15 : sal_Int16 nValue = sal_Int16();
140 15 : OUStringBuffer aOut;
141 :
142 15 : if( (rValue >>= nValue) && awt::FontStrikeout::DOUBLE==nValue )
143 : {
144 : bRet = SvXMLUnitConverter::convertEnum(
145 0 : aOut, (sal_uInt16)nValue, pXML_CrossedoutType_Enum );
146 0 : if( bRet )
147 0 : rStrExpValue = aOut.makeStringAndClear();
148 : }
149 :
150 15 : return bRet;
151 : }
152 :
153 : ///////////////////////////////////////////////////////////////////////////////
154 : //
155 : // class XMLCrossedOutStylePropHdl
156 : //
157 :
158 4292 : XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl()
159 : {
160 : // nothing to do
161 4292 : }
162 :
163 48 : sal_Bool XMLCrossedOutStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
164 : {
165 : sal_uInt16 eNewStrikeout;
166 : sal_Bool bRet = SvXMLUnitConverter::convertEnum(
167 48 : eNewStrikeout, rStrImpValue, pXML_CrossedoutStyle_Enum );
168 48 : if( bRet )
169 : {
170 : // multi property: style and width might be set already.
171 : // If the old value is NONE, the new is used unchanged.
172 48 : sal_Int16 eStrikeout = sal_Int16();
173 48 : if( (rValue >>= eStrikeout) && awt::FontStrikeout::NONE!=eStrikeout )
174 : {
175 : // one NONE a SINGLE are possible new values. For both, the
176 : // existing value is kept.
177 : }
178 : else
179 : {
180 48 : rValue <<= (sal_Int16)eNewStrikeout;
181 : }
182 : }
183 :
184 48 : return bRet;
185 : }
186 :
187 15 : sal_Bool XMLCrossedOutStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
188 : {
189 15 : sal_Bool bRet = sal_False;
190 15 : sal_Int16 nValue = sal_Int16();
191 15 : OUStringBuffer aOut;
192 :
193 15 : if( rValue >>= nValue )
194 : {
195 : bRet = SvXMLUnitConverter::convertEnum(
196 15 : aOut, (sal_uInt16)nValue, pXML_CrossedoutStyle_Enum );
197 15 : if( bRet )
198 15 : rStrExpValue = aOut.makeStringAndClear();
199 : }
200 :
201 15 : return bRet;
202 : }
203 :
204 : ///////////////////////////////////////////////////////////////////////////////
205 : //
206 : // class XMLCrossedOutWidthPropHdl
207 : //
208 :
209 4292 : XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl()
210 : {
211 : // nothing to do
212 4292 : }
213 :
214 0 : sal_Bool XMLCrossedOutWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
215 : {
216 : sal_uInt16 eNewStrikeout;
217 : sal_Bool bRet = SvXMLUnitConverter::convertEnum(
218 0 : eNewStrikeout, rStrImpValue, pXML_CrossedoutWidth_Enum );
219 0 : if( bRet )
220 : {
221 : // multi property: style and width might be set already.
222 : // If the old value is NONE, the new is used unchanged.
223 0 : sal_Int16 eStrikeout = sal_Int16();
224 0 : if( (rValue >>= eStrikeout) && awt::FontStrikeout::NONE!=eStrikeout )
225 : {
226 0 : switch( eNewStrikeout )
227 : {
228 : case awt::FontStrikeout::NONE:
229 : // keep existing line style
230 0 : eNewStrikeout = eStrikeout;
231 0 : break;
232 : case awt::FontStrikeout::BOLD:
233 0 : switch( eStrikeout )
234 : {
235 : case awt::FontStrikeout::SINGLE:
236 0 : break;
237 : default:
238 : // If a double line style is not supported for the existing
239 : // value, keep the new one
240 0 : eNewStrikeout = eStrikeout;
241 0 : break;
242 : }
243 : default:
244 : OSL_ENSURE( bRet, "unexpected line type value" );
245 0 : break;
246 : }
247 0 : if( eNewStrikeout != eStrikeout )
248 0 : rValue <<= (sal_Int16)eNewStrikeout;
249 : }
250 : else
251 : {
252 0 : rValue <<= (sal_Int16)eNewStrikeout;
253 : }
254 : }
255 :
256 0 : return bRet;
257 : }
258 :
259 15 : sal_Bool XMLCrossedOutWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
260 : {
261 15 : sal_Bool bRet = sal_False;
262 15 : sal_Int16 nValue = sal_Int16();
263 15 : OUStringBuffer aOut;
264 :
265 15 : if( (rValue >>= nValue) && (awt::FontStrikeout::BOLD == nValue) )
266 : {
267 : bRet = SvXMLUnitConverter::convertEnum(
268 0 : aOut, (sal_uInt16)nValue, pXML_CrossedoutWidth_Enum );
269 0 : if( bRet )
270 0 : rStrExpValue = aOut.makeStringAndClear();
271 : }
272 :
273 15 : return bRet;
274 : }
275 :
276 : ///////////////////////////////////////////////////////////////////////////////
277 : //
278 : // class XMLCrossedOutTextPropHdl
279 : //
280 :
281 4292 : XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl()
282 : {
283 : // nothing to do
284 4292 : }
285 :
286 0 : sal_Bool XMLCrossedOutTextPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
287 : {
288 0 : sal_Bool bRet = sal_False;
289 :
290 0 : if( !rStrImpValue.isEmpty() )
291 : {
292 0 : sal_Int16 eStrikeout = ('/' == rStrImpValue[0]
293 : ? awt::FontStrikeout::SLASH
294 0 : : awt::FontStrikeout::X);
295 0 : rValue <<= (sal_Int16)eStrikeout;
296 0 : bRet = sal_True;
297 : }
298 :
299 0 : return bRet;
300 : }
301 :
302 15 : sal_Bool XMLCrossedOutTextPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
303 : {
304 15 : sal_Bool bRet = sal_False;
305 15 : sal_Int16 nValue = sal_Int16();
306 :
307 30 : if( (rValue >>= nValue) &&
308 30 : (awt::FontStrikeout::SLASH == nValue || awt::FontStrikeout::X == nValue) )
309 : {
310 0 : rStrExpValue = OUString::valueOf(
311 0 : static_cast< sal_Unicode>( awt::FontStrikeout::SLASH == nValue ? '/'
312 0 : : 'X' ) );
313 0 : bRet = sal_True;
314 : }
315 :
316 15 : return bRet;
317 : }
318 :
319 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|