1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cdouthdl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <cdouthdl.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include <rtl/ustrbuf.hxx>
38 #ifndef _COM_SUN_STAR_AWT_FONTSTRIKEOUT_HPP
39 #include <com/sun/star/awt/FontStrikeout.hpp>
41 #include <com/sun/star/uno/Any.hxx>
43 #ifndef _XMLOFF_XMLEMENT_HXX
44 #include <xmloff/xmlelement.hxx>
47 using ::rtl::OUString
;
48 using ::rtl::OUStringBuffer
;
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::awt
;
52 using namespace ::xmloff::token
;
54 SvXMLEnumMapEntry pXML_CrossedoutType_Enum
[] =
56 { XML_NONE
, FontStrikeout::NONE
},
57 { XML_SINGLE
, FontStrikeout::SINGLE
},
58 { XML_DOUBLE
, FontStrikeout::DOUBLE
},
59 { XML_SINGLE
, FontStrikeout::BOLD
},
60 { XML_SINGLE
, FontStrikeout::SLASH
},
61 { XML_SINGLE
, FontStrikeout::X
},
62 { XML_TOKEN_INVALID
, 0 }
65 SvXMLEnumMapEntry pXML_CrossedoutStyle_Enum
[] =
67 { XML_NONE
, FontStrikeout::NONE
},
68 { XML_SOLID
, FontStrikeout::SINGLE
},
69 { XML_SOLID
, FontStrikeout::DOUBLE
},
70 { XML_SOLID
, FontStrikeout::BOLD
},
71 { XML_SOLID
, FontStrikeout::SLASH
},
72 { XML_SOLID
, FontStrikeout::X
},
73 { XML_DOTTED
, FontStrikeout::SINGLE
},
74 { XML_DASH
, FontStrikeout::SINGLE
},
75 { XML_LONG_DASH
, FontStrikeout::SINGLE
},
76 { XML_DOT_DASH
, FontStrikeout::SINGLE
},
77 { XML_DOT_DOT_DASH
, FontStrikeout::SINGLE
},
78 { XML_WAVE
, FontStrikeout::SINGLE
},
79 { XML_TOKEN_INVALID
, 0 }
82 SvXMLEnumMapEntry pXML_CrossedoutWidth_Enum
[] =
84 { XML_AUTO
, FontStrikeout::NONE
},
85 { XML_AUTO
, FontStrikeout::SINGLE
},
86 { XML_AUTO
, FontStrikeout::DOUBLE
},
87 { XML_BOLD
, FontStrikeout::BOLD
},
88 { XML_AUTO
, FontStrikeout::SLASH
},
89 { XML_AUTO
, FontStrikeout::X
},
90 { XML_THIN
, FontStrikeout::NONE
},
91 { XML_MEDIUM
, FontStrikeout::NONE
},
92 { XML_THICK
, FontStrikeout::NONE
},
93 { XML_TOKEN_INVALID
, 0 }
96 ///////////////////////////////////////////////////////////////////////////////
98 // class XMLCrossedOutTypePropHdl
101 XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl()
106 sal_Bool
XMLCrossedOutTypePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
108 sal_uInt16 eNewStrikeout
;
109 sal_Bool bRet
= SvXMLUnitConverter::convertEnum(
110 eNewStrikeout
, rStrImpValue
, pXML_CrossedoutType_Enum
);
113 // multi property: style and width might be set already.
114 // If the old value is NONE, the new is used unchanged.
115 sal_Int16 eStrikeout
= sal_Int16();
116 if( (rValue
>>= eStrikeout
) && FontStrikeout::NONE
!=eStrikeout
)
118 switch( eNewStrikeout
)
120 case FontStrikeout::NONE
:
121 case FontStrikeout::SINGLE
:
122 // keep existing line style
123 eNewStrikeout
= eStrikeout
;
125 case FontStrikeout::DOUBLE
:
126 // A double line style has priority over a solid or a bold
128 // but not about any other line style
131 case FontStrikeout::SINGLE
:
132 case FontStrikeout::BOLD
:
135 // If a double line style is not supported for the existing
136 // value, keep the new one
137 eNewStrikeout
= eStrikeout
;
142 OSL_ENSURE( bRet
, "unexpected line type value" );
145 if( eNewStrikeout
!= eStrikeout
)
146 rValue
<<= (sal_Int16
)eNewStrikeout
;
150 rValue
<<= (sal_Int16
)eNewStrikeout
;
157 sal_Bool
XMLCrossedOutTypePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
159 sal_Bool bRet
= sal_False
;
160 sal_Int16 nValue
= sal_Int16();
163 if( (rValue
>>= nValue
) && FontStrikeout::DOUBLE
==nValue
)
165 bRet
= SvXMLUnitConverter::convertEnum(
166 aOut
, (sal_uInt16
)nValue
, pXML_CrossedoutType_Enum
);
168 rStrExpValue
= aOut
.makeStringAndClear();
174 ///////////////////////////////////////////////////////////////////////////////
176 // class XMLCrossedOutStylePropHdl
179 XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl()
184 sal_Bool
XMLCrossedOutStylePropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
186 sal_uInt16 eNewStrikeout
;
187 sal_Bool bRet
= SvXMLUnitConverter::convertEnum(
188 eNewStrikeout
, rStrImpValue
, pXML_CrossedoutStyle_Enum
);
191 // multi property: style and width might be set already.
192 // If the old value is NONE, the new is used unchanged.
193 sal_Int16 eStrikeout
= sal_Int16();
194 if( (rValue
>>= eStrikeout
) && FontStrikeout::NONE
!=eStrikeout
)
196 // one NONE a SINGLE are possible new values. For both, the
197 // existing value is kept.
201 rValue
<<= (sal_Int16
)eNewStrikeout
;
208 sal_Bool
XMLCrossedOutStylePropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
210 sal_Bool bRet
= sal_False
;
211 sal_Int16 nValue
= sal_Int16();
214 if( rValue
>>= nValue
)
216 bRet
= SvXMLUnitConverter::convertEnum(
217 aOut
, (sal_uInt16
)nValue
, pXML_CrossedoutStyle_Enum
);
219 rStrExpValue
= aOut
.makeStringAndClear();
225 ///////////////////////////////////////////////////////////////////////////////
227 // class XMLCrossedOutWidthPropHdl
230 XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl()
235 sal_Bool
XMLCrossedOutWidthPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
237 sal_uInt16 eNewStrikeout
;
238 sal_Bool bRet
= SvXMLUnitConverter::convertEnum(
239 eNewStrikeout
, rStrImpValue
, pXML_CrossedoutWidth_Enum
);
242 // multi property: style and width might be set already.
243 // If the old value is NONE, the new is used unchanged.
244 sal_Int16 eStrikeout
= sal_Int16();
245 if( (rValue
>>= eStrikeout
) && FontStrikeout::NONE
!=eStrikeout
)
247 switch( eNewStrikeout
)
249 case FontStrikeout::NONE
:
250 // keep existing line style
251 eNewStrikeout
= eStrikeout
;
253 case FontStrikeout::BOLD
:
256 case FontStrikeout::SINGLE
:
259 // If a double line style is not supported for the existing
260 // value, keep the new one
261 eNewStrikeout
= eStrikeout
;
265 OSL_ENSURE( bRet
, "unexpected line type value" );
268 if( eNewStrikeout
!= eStrikeout
)
269 rValue
<<= (sal_Int16
)eNewStrikeout
;
273 rValue
<<= (sal_Int16
)eNewStrikeout
;
280 sal_Bool
XMLCrossedOutWidthPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
282 sal_Bool bRet
= sal_False
;
283 sal_Int16 nValue
= sal_Int16();
286 if( (rValue
>>= nValue
) && (FontStrikeout::BOLD
== nValue
) )
288 bRet
= SvXMLUnitConverter::convertEnum(
289 aOut
, (sal_uInt16
)nValue
, pXML_CrossedoutWidth_Enum
);
291 rStrExpValue
= aOut
.makeStringAndClear();
297 ///////////////////////////////////////////////////////////////////////////////
299 // class XMLCrossedOutTextPropHdl
302 XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl()
307 sal_Bool
XMLCrossedOutTextPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
309 sal_Bool bRet
= sal_False
;
311 if( rStrImpValue
.getLength() )
313 sal_Int16 eStrikeout
= ('/' == rStrImpValue
[0]
314 ? FontStrikeout::SLASH
316 rValue
<<= (sal_Int16
)eStrikeout
;
323 sal_Bool
XMLCrossedOutTextPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
325 sal_Bool bRet
= sal_False
;
326 sal_Int16 nValue
= sal_Int16();
328 if( (rValue
>>= nValue
) &&
329 (FontStrikeout::SLASH
== nValue
|| FontStrikeout::X
== nValue
) )
331 rStrExpValue
= OUString::valueOf(
332 static_cast< sal_Unicode
>( FontStrikeout::SLASH
== nValue
? '/'