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 <xmloff/xmlement.hxx>
24 #include <rtl/ustrbuf.hxx>
25 #include <osl/diagnose.h>
27 #include <com/sun/star/awt/FontStrikeout.hpp>
28 #include <com/sun/star/uno/Any.hxx>
30 using namespace ::com::sun::star
;
31 using namespace ::com::sun::star::awt
;
32 using namespace ::xmloff::token
;
34 SvXMLEnumMapEntry
<sal_uInt16
> const pXML_CrossedoutType_Enum
[] =
36 { XML_NONE
, awt::FontStrikeout::NONE
},
37 { XML_SINGLE
, awt::FontStrikeout::SINGLE
},
38 { XML_DOUBLE
, awt::FontStrikeout::DOUBLE
},
39 { XML_SINGLE
, awt::FontStrikeout::BOLD
},
40 { XML_SINGLE
, awt::FontStrikeout::SLASH
},
41 { XML_SINGLE
, awt::FontStrikeout::X
},
42 { XML_TOKEN_INVALID
, 0 }
45 SvXMLEnumMapEntry
<sal_uInt16
> const pXML_CrossedoutStyle_Enum
[] =
47 { XML_NONE
, awt::FontStrikeout::NONE
},
48 { XML_SOLID
, awt::FontStrikeout::SINGLE
},
49 { XML_SOLID
, awt::FontStrikeout::DOUBLE
},
50 { XML_SOLID
, awt::FontStrikeout::BOLD
},
51 { XML_SOLID
, awt::FontStrikeout::SLASH
},
52 { XML_SOLID
, awt::FontStrikeout::X
},
53 { XML_DOTTED
, awt::FontStrikeout::SINGLE
},
54 { XML_DASH
, awt::FontStrikeout::SINGLE
},
55 { XML_LONG_DASH
, awt::FontStrikeout::SINGLE
},
56 { XML_DOT_DASH
, awt::FontStrikeout::SINGLE
},
57 { XML_DOT_DOT_DASH
, awt::FontStrikeout::SINGLE
},
58 { XML_WAVE
, awt::FontStrikeout::SINGLE
},
59 { XML_TOKEN_INVALID
, 0 }
62 SvXMLEnumMapEntry
<sal_uInt16
> const pXML_CrossedoutWidth_Enum
[] =
64 { XML_AUTO
, awt::FontStrikeout::NONE
},
65 { XML_AUTO
, awt::FontStrikeout::SINGLE
},
66 { XML_AUTO
, awt::FontStrikeout::DOUBLE
},
67 { XML_BOLD
, awt::FontStrikeout::BOLD
},
68 { XML_AUTO
, awt::FontStrikeout::SLASH
},
69 { XML_AUTO
, awt::FontStrikeout::X
},
70 { XML_THIN
, awt::FontStrikeout::NONE
},
71 { XML_MEDIUM
, awt::FontStrikeout::NONE
},
72 { XML_THICK
, awt::FontStrikeout::NONE
},
73 { XML_TOKEN_INVALID
, 0 }
77 XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl()
82 bool XMLCrossedOutTypePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
84 sal_uInt16 eNewStrikeout
= 0;
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
<<= static_cast<sal_Int16
>(eNewStrikeout
);
126 rValue
<<= static_cast<sal_Int16
>(eNewStrikeout
);
133 bool XMLCrossedOutTypePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
136 sal_uInt16 nValue
= sal_uInt16();
138 if (rValue
>>= nValue
)
141 bRet
= SvXMLUnitConverter::convertEnum(
142 aOut
, nValue
, pXML_CrossedoutType_Enum
);
144 rStrExpValue
= aOut
.makeStringAndClear();
151 XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl()
156 bool XMLCrossedOutStylePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
158 sal_uInt16
eNewStrikeout(0);
159 bool bRet
= SvXMLUnitConverter::convertEnum(
160 eNewStrikeout
, rStrImpValue
, pXML_CrossedoutStyle_Enum
);
163 // multi property: style and width might be set already.
164 // If the old value is NONE, the new is used unchanged.
165 sal_Int16 eStrikeout
= sal_Int16();
166 if( (rValue
>>= eStrikeout
) && awt::FontStrikeout::NONE
!=eStrikeout
)
168 // one NONE a SINGLE are possible new values. For both, the
169 // existing value is kept.
173 rValue
<<= static_cast<sal_Int16
>(eNewStrikeout
);
180 bool XMLCrossedOutStylePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
183 sal_uInt16 nValue
= sal_uInt16();
185 if( rValue
>>= nValue
)
188 bRet
= SvXMLUnitConverter::convertEnum(
189 aOut
, nValue
, pXML_CrossedoutStyle_Enum
);
191 rStrExpValue
= aOut
.makeStringAndClear();
198 XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl()
203 bool XMLCrossedOutWidthPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
205 sal_uInt16 eNewStrikeout
= 0;
206 bool bRet
= SvXMLUnitConverter::convertEnum(
207 eNewStrikeout
, rStrImpValue
, pXML_CrossedoutWidth_Enum
);
210 // multi property: style and width might be set already.
211 // If the old value is NONE, the new is used unchanged.
212 sal_Int16 eStrikeout
= sal_Int16();
213 if( (rValue
>>= eStrikeout
) && awt::FontStrikeout::NONE
!=eStrikeout
)
215 switch( eNewStrikeout
)
217 case awt::FontStrikeout::NONE
:
218 // keep existing line style
219 eNewStrikeout
= eStrikeout
;
221 case awt::FontStrikeout::BOLD
:
224 case awt::FontStrikeout::SINGLE
:
227 // If a double line style is not supported for the existing
228 // value, keep the new one
229 eNewStrikeout
= eStrikeout
;
234 OSL_ENSURE( bRet
, "unexpected line type value" );
237 if( eNewStrikeout
!= eStrikeout
)
238 rValue
<<= static_cast<sal_Int16
>(eNewStrikeout
);
242 rValue
<<= static_cast<sal_Int16
>(eNewStrikeout
);
249 bool XMLCrossedOutWidthPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
252 sal_uInt16 nValue
= sal_uInt16();
254 if( (rValue
>>= nValue
) && (awt::FontStrikeout::BOLD
== nValue
) )
257 bRet
= SvXMLUnitConverter::convertEnum(
258 aOut
, nValue
, pXML_CrossedoutWidth_Enum
);
260 rStrExpValue
= aOut
.makeStringAndClear();
267 XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl()
272 bool XMLCrossedOutTextPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
276 if( !rStrImpValue
.isEmpty() )
278 sal_Int16 eStrikeout
= ('/' == rStrImpValue
[0]
279 ? awt::FontStrikeout::SLASH
280 : awt::FontStrikeout::X
);
281 rValue
<<= eStrikeout
;
288 bool XMLCrossedOutTextPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
291 sal_Int16 nValue
= sal_Int16();
293 if( (rValue
>>= nValue
) &&
294 (awt::FontStrikeout::SLASH
== nValue
|| awt::FontStrikeout::X
== nValue
) )
296 rStrExpValue
= OUString(
297 static_cast< sal_Unicode
>( awt::FontStrikeout::SLASH
== nValue
? '/'
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */