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>
24 #include <osl/diagnose.h>
26 #include <com/sun/star/awt/FontStrikeout.hpp>
27 #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 // class XMLCrossedOutTypePropHdl
77 XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl()
82 bool XMLCrossedOutTypePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
84 sal_uInt16 eNewStrikeout
;
85 bool bRet
= SvXMLUnitConverter::convertEnum(
86 eNewStrikeout
, rStrImpValue
, pXML_CrossedoutType_Enum
);
89 // multi property: style and width might be set already.
90 // If the old value is NONE, the new is used unchanged.
91 sal_Int16 eStrikeout
= sal_Int16();
92 if( (rValue
>>= eStrikeout
) && awt::FontStrikeout::NONE
!=eStrikeout
)
94 switch( eNewStrikeout
)
96 case awt::FontStrikeout::NONE
:
97 case awt::FontStrikeout::SINGLE
:
98 // keep existing line style
99 eNewStrikeout
= eStrikeout
;
101 case awt::FontStrikeout::DOUBLE
:
102 // A double line style has priority over a solid or a bold
104 // but not about any other line style
107 case awt::FontStrikeout::SINGLE
:
108 case awt::FontStrikeout::BOLD
:
111 // If a double line style is not supported for the existing
112 // value, keep the new one
113 eNewStrikeout
= eStrikeout
;
118 OSL_ENSURE( bRet
, "unexpected line type value" );
121 if( eNewStrikeout
!= eStrikeout
)
122 rValue
<<= (sal_Int16
)eNewStrikeout
;
126 rValue
<<= (sal_Int16
)eNewStrikeout
;
133 bool XMLCrossedOutTypePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
136 sal_Int16 nValue
= sal_Int16();
139 if (rValue
>>= nValue
)
141 bRet
= SvXMLUnitConverter::convertEnum(
142 aOut
, (sal_uInt16
)nValue
, pXML_CrossedoutType_Enum
);
144 rStrExpValue
= aOut
.makeStringAndClear();
150 // class XMLCrossedOutStylePropHdl
152 XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl()
157 bool XMLCrossedOutStylePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
159 sal_uInt16 eNewStrikeout
;
160 bool bRet
= SvXMLUnitConverter::convertEnum(
161 eNewStrikeout
, rStrImpValue
, pXML_CrossedoutStyle_Enum
);
164 // multi property: style and width might be set already.
165 // If the old value is NONE, the new is used unchanged.
166 sal_Int16 eStrikeout
= sal_Int16();
167 if( (rValue
>>= eStrikeout
) && awt::FontStrikeout::NONE
!=eStrikeout
)
169 // one NONE a SINGLE are possible new values. For both, the
170 // existing value is kept.
174 rValue
<<= (sal_Int16
)eNewStrikeout
;
181 bool XMLCrossedOutStylePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
184 sal_Int16 nValue
= sal_Int16();
187 if( rValue
>>= nValue
)
189 bRet
= SvXMLUnitConverter::convertEnum(
190 aOut
, (sal_uInt16
)nValue
, pXML_CrossedoutStyle_Enum
);
192 rStrExpValue
= aOut
.makeStringAndClear();
198 // class XMLCrossedOutWidthPropHdl
200 XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl()
205 bool XMLCrossedOutWidthPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
207 sal_uInt16 eNewStrikeout
;
208 bool bRet
= SvXMLUnitConverter::convertEnum(
209 eNewStrikeout
, rStrImpValue
, pXML_CrossedoutWidth_Enum
);
212 // multi property: style and width might be set already.
213 // If the old value is NONE, the new is used unchanged.
214 sal_Int16 eStrikeout
= sal_Int16();
215 if( (rValue
>>= eStrikeout
) && awt::FontStrikeout::NONE
!=eStrikeout
)
217 switch( eNewStrikeout
)
219 case awt::FontStrikeout::NONE
:
220 // keep existing line style
221 eNewStrikeout
= eStrikeout
;
223 case awt::FontStrikeout::BOLD
:
226 case awt::FontStrikeout::SINGLE
:
229 // If a double line style is not supported for the existing
230 // value, keep the new one
231 eNewStrikeout
= eStrikeout
;
236 OSL_ENSURE( bRet
, "unexpected line type value" );
239 if( eNewStrikeout
!= eStrikeout
)
240 rValue
<<= (sal_Int16
)eNewStrikeout
;
244 rValue
<<= (sal_Int16
)eNewStrikeout
;
251 bool XMLCrossedOutWidthPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
254 sal_Int16 nValue
= sal_Int16();
257 if( (rValue
>>= nValue
) && (awt::FontStrikeout::BOLD
== nValue
) )
259 bRet
= SvXMLUnitConverter::convertEnum(
260 aOut
, (sal_uInt16
)nValue
, pXML_CrossedoutWidth_Enum
);
262 rStrExpValue
= aOut
.makeStringAndClear();
268 // class XMLCrossedOutTextPropHdl
270 XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl()
275 bool XMLCrossedOutTextPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
279 if( !rStrImpValue
.isEmpty() )
281 sal_Int16 eStrikeout
= ('/' == rStrImpValue
[0]
282 ? awt::FontStrikeout::SLASH
283 : awt::FontStrikeout::X
);
284 rValue
<<= (sal_Int16
)eStrikeout
;
291 bool XMLCrossedOutTextPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
294 sal_Int16 nValue
= sal_Int16();
296 if( (rValue
>>= nValue
) &&
297 (awt::FontStrikeout::SLASH
== nValue
|| awt::FontStrikeout::X
== nValue
) )
299 rStrExpValue
= OUString(
300 static_cast< sal_Unicode
>( awt::FontStrikeout::SLASH
== nValue
? '/'
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */