1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <cdouthdl.hxx>
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmluconv.hxx>
23 #include <rtl/ustrbuf.hxx>
25 #include <com/sun/star/awt/FontStrikeout.hpp>
26 #include <com/sun/star/uno/Any.hxx>
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::awt
;
31 using namespace ::xmloff::token
;
33 SvXMLEnumMapEntry pXML_CrossedoutType_Enum
[] =
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 }
44 SvXMLEnumMapEntry pXML_CrossedoutStyle_Enum
[] =
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 }
61 SvXMLEnumMapEntry pXML_CrossedoutWidth_Enum
[] =
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 }
75 ///////////////////////////////////////////////////////////////////////////////
77 // class XMLCrossedOutTypePropHdl
80 XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl()
85 sal_Bool
XMLCrossedOutTypePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
87 sal_uInt16 eNewStrikeout
;
88 sal_Bool bRet
= SvXMLUnitConverter::convertEnum(
89 eNewStrikeout
, rStrImpValue
, pXML_CrossedoutType_Enum
);
92 // multi property: style and width might be set already.
93 // If the old value is NONE, the new is used unchanged.
94 sal_Int16 eStrikeout
= sal_Int16();
95 if( (rValue
>>= eStrikeout
) && awt::FontStrikeout::NONE
!=eStrikeout
)
97 switch( eNewStrikeout
)
99 case awt::FontStrikeout::NONE
:
100 case awt::FontStrikeout::SINGLE
:
101 // keep existing line style
102 eNewStrikeout
= eStrikeout
;
104 case awt::FontStrikeout::DOUBLE
:
105 // A double line style has priority over a solid or a bold
107 // but not about any other line style
110 case awt::FontStrikeout::SINGLE
:
111 case awt::FontStrikeout::BOLD
:
114 // If a double line style is not supported for the existing
115 // value, keep the new one
116 eNewStrikeout
= eStrikeout
;
121 OSL_ENSURE( bRet
, "unexpected line type value" );
124 if( eNewStrikeout
!= eStrikeout
)
125 rValue
<<= (sal_Int16
)eNewStrikeout
;
129 rValue
<<= (sal_Int16
)eNewStrikeout
;
136 sal_Bool
XMLCrossedOutTypePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
138 sal_Bool bRet
= sal_False
;
139 sal_Int16 nValue
= sal_Int16();
142 if( (rValue
>>= nValue
) && awt::FontStrikeout::DOUBLE
==nValue
)
144 bRet
= SvXMLUnitConverter::convertEnum(
145 aOut
, (sal_uInt16
)nValue
, pXML_CrossedoutType_Enum
);
147 rStrExpValue
= aOut
.makeStringAndClear();
153 ///////////////////////////////////////////////////////////////////////////////
155 // class XMLCrossedOutStylePropHdl
158 XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl()
163 sal_Bool
XMLCrossedOutStylePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
165 sal_uInt16 eNewStrikeout
;
166 sal_Bool bRet
= SvXMLUnitConverter::convertEnum(
167 eNewStrikeout
, rStrImpValue
, pXML_CrossedoutStyle_Enum
);
170 // multi property: style and width might be set already.
171 // If the old value is NONE, the new is used unchanged.
172 sal_Int16 eStrikeout
= sal_Int16();
173 if( (rValue
>>= eStrikeout
) && awt::FontStrikeout::NONE
!=eStrikeout
)
175 // one NONE a SINGLE are possible new values. For both, the
176 // existing value is kept.
180 rValue
<<= (sal_Int16
)eNewStrikeout
;
187 sal_Bool
XMLCrossedOutStylePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
189 sal_Bool bRet
= sal_False
;
190 sal_Int16 nValue
= sal_Int16();
193 if( rValue
>>= nValue
)
195 bRet
= SvXMLUnitConverter::convertEnum(
196 aOut
, (sal_uInt16
)nValue
, pXML_CrossedoutStyle_Enum
);
198 rStrExpValue
= aOut
.makeStringAndClear();
204 ///////////////////////////////////////////////////////////////////////////////
206 // class XMLCrossedOutWidthPropHdl
209 XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl()
214 sal_Bool
XMLCrossedOutWidthPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
216 sal_uInt16 eNewStrikeout
;
217 sal_Bool bRet
= SvXMLUnitConverter::convertEnum(
218 eNewStrikeout
, rStrImpValue
, pXML_CrossedoutWidth_Enum
);
221 // multi property: style and width might be set already.
222 // If the old value is NONE, the new is used unchanged.
223 sal_Int16 eStrikeout
= sal_Int16();
224 if( (rValue
>>= eStrikeout
) && awt::FontStrikeout::NONE
!=eStrikeout
)
226 switch( eNewStrikeout
)
228 case awt::FontStrikeout::NONE
:
229 // keep existing line style
230 eNewStrikeout
= eStrikeout
;
232 case awt::FontStrikeout::BOLD
:
235 case awt::FontStrikeout::SINGLE
:
238 // If a double line style is not supported for the existing
239 // value, keep the new one
240 eNewStrikeout
= eStrikeout
;
244 OSL_ENSURE( bRet
, "unexpected line type value" );
247 if( eNewStrikeout
!= eStrikeout
)
248 rValue
<<= (sal_Int16
)eNewStrikeout
;
252 rValue
<<= (sal_Int16
)eNewStrikeout
;
259 sal_Bool
XMLCrossedOutWidthPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
261 sal_Bool bRet
= sal_False
;
262 sal_Int16 nValue
= sal_Int16();
265 if( (rValue
>>= nValue
) && (awt::FontStrikeout::BOLD
== nValue
) )
267 bRet
= SvXMLUnitConverter::convertEnum(
268 aOut
, (sal_uInt16
)nValue
, pXML_CrossedoutWidth_Enum
);
270 rStrExpValue
= aOut
.makeStringAndClear();
276 ///////////////////////////////////////////////////////////////////////////////
278 // class XMLCrossedOutTextPropHdl
281 XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl()
286 sal_Bool
XMLCrossedOutTextPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
288 sal_Bool bRet
= sal_False
;
290 if( !rStrImpValue
.isEmpty() )
292 sal_Int16 eStrikeout
= ('/' == rStrImpValue
[0]
293 ? awt::FontStrikeout::SLASH
294 : awt::FontStrikeout::X
);
295 rValue
<<= (sal_Int16
)eStrikeout
;
302 sal_Bool
XMLCrossedOutTextPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
304 sal_Bool bRet
= sal_False
;
305 sal_Int16 nValue
= sal_Int16();
307 if( (rValue
>>= nValue
) &&
308 (awt::FontStrikeout::SLASH
== nValue
|| awt::FontStrikeout::X
== nValue
) )
310 rStrExpValue
= OUString::valueOf(
311 static_cast< sal_Unicode
>( awt::FontStrikeout::SLASH
== nValue
? '/'
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */