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