1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include <cdouthdl.hxx>
27cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
28cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
29cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <com/sun/star/awt/FontStrikeout.hpp>
32cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir using ::rtl::OUString;
35cdf0e10cSrcweir using ::rtl::OUStringBuffer;
36cdf0e10cSrcweir
37cdf0e10cSrcweir using namespace ::com::sun::star;
38cdf0e10cSrcweir using namespace ::com::sun::star::awt;
39cdf0e10cSrcweir using namespace ::xmloff::token;
40cdf0e10cSrcweir
41cdf0e10cSrcweir SvXMLEnumMapEntry pXML_CrossedoutType_Enum[] =
42cdf0e10cSrcweir {
43cdf0e10cSrcweir { XML_NONE, FontStrikeout::NONE },
44cdf0e10cSrcweir { XML_SINGLE, FontStrikeout::SINGLE },
45cdf0e10cSrcweir { XML_DOUBLE, FontStrikeout::DOUBLE },
46cdf0e10cSrcweir { XML_SINGLE, FontStrikeout::BOLD },
47cdf0e10cSrcweir { XML_SINGLE, FontStrikeout::SLASH },
48cdf0e10cSrcweir { XML_SINGLE, FontStrikeout::X },
49cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 }
50cdf0e10cSrcweir };
51cdf0e10cSrcweir
52cdf0e10cSrcweir SvXMLEnumMapEntry pXML_CrossedoutStyle_Enum[] =
53cdf0e10cSrcweir {
54cdf0e10cSrcweir { XML_NONE, FontStrikeout::NONE },
55cdf0e10cSrcweir { XML_SOLID, FontStrikeout::SINGLE },
56cdf0e10cSrcweir { XML_SOLID, FontStrikeout::DOUBLE },
57cdf0e10cSrcweir { XML_SOLID, FontStrikeout::BOLD },
58cdf0e10cSrcweir { XML_SOLID, FontStrikeout::SLASH },
59cdf0e10cSrcweir { XML_SOLID, FontStrikeout::X },
60cdf0e10cSrcweir { XML_DOTTED, FontStrikeout::SINGLE },
61cdf0e10cSrcweir { XML_DASH, FontStrikeout::SINGLE },
62cdf0e10cSrcweir { XML_LONG_DASH, FontStrikeout::SINGLE },
63cdf0e10cSrcweir { XML_DOT_DASH, FontStrikeout::SINGLE },
64cdf0e10cSrcweir { XML_DOT_DOT_DASH, FontStrikeout::SINGLE },
65cdf0e10cSrcweir { XML_WAVE, FontStrikeout::SINGLE },
66cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 }
67cdf0e10cSrcweir };
68cdf0e10cSrcweir
69cdf0e10cSrcweir SvXMLEnumMapEntry pXML_CrossedoutWidth_Enum[] =
70cdf0e10cSrcweir {
71cdf0e10cSrcweir { XML_AUTO, FontStrikeout::NONE },
72cdf0e10cSrcweir { XML_AUTO, FontStrikeout::SINGLE },
73cdf0e10cSrcweir { XML_AUTO, FontStrikeout::DOUBLE },
74cdf0e10cSrcweir { XML_BOLD, FontStrikeout::BOLD },
75cdf0e10cSrcweir { XML_AUTO, FontStrikeout::SLASH },
76cdf0e10cSrcweir { XML_AUTO, FontStrikeout::X },
77cdf0e10cSrcweir { XML_THIN, FontStrikeout::NONE },
78cdf0e10cSrcweir { XML_MEDIUM, FontStrikeout::NONE },
79cdf0e10cSrcweir { XML_THICK, FontStrikeout::NONE },
80cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 }
81cdf0e10cSrcweir };
82cdf0e10cSrcweir
83cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
84cdf0e10cSrcweir //
85cdf0e10cSrcweir // class XMLCrossedOutTypePropHdl
86cdf0e10cSrcweir //
87cdf0e10cSrcweir
~XMLCrossedOutTypePropHdl()88cdf0e10cSrcweir XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl()
89cdf0e10cSrcweir {
90cdf0e10cSrcweir // nothing to do
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const93cdf0e10cSrcweir sal_Bool XMLCrossedOutTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
94cdf0e10cSrcweir {
95cdf0e10cSrcweir sal_uInt16 eNewStrikeout;
96cdf0e10cSrcweir sal_Bool bRet = SvXMLUnitConverter::convertEnum(
97cdf0e10cSrcweir eNewStrikeout, rStrImpValue, pXML_CrossedoutType_Enum );
98cdf0e10cSrcweir if( bRet )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir // multi property: style and width might be set already.
101cdf0e10cSrcweir // If the old value is NONE, the new is used unchanged.
102cdf0e10cSrcweir sal_Int16 eStrikeout = sal_Int16();
103cdf0e10cSrcweir if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir switch( eNewStrikeout )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir case FontStrikeout::NONE:
108cdf0e10cSrcweir case FontStrikeout::SINGLE:
109cdf0e10cSrcweir // keep existing line style
110cdf0e10cSrcweir eNewStrikeout = eStrikeout;
111cdf0e10cSrcweir break;
112cdf0e10cSrcweir case FontStrikeout::DOUBLE:
113cdf0e10cSrcweir // A double line style has priority over a solid or a bold
114cdf0e10cSrcweir // line style,
115cdf0e10cSrcweir // but not about any other line style
116cdf0e10cSrcweir switch( eStrikeout )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir case FontStrikeout::SINGLE:
119cdf0e10cSrcweir case FontStrikeout::BOLD:
120cdf0e10cSrcweir break;
121cdf0e10cSrcweir default:
122cdf0e10cSrcweir // If a double line style is not supported for the existing
123cdf0e10cSrcweir // value, keep the new one
124cdf0e10cSrcweir eNewStrikeout = eStrikeout;
125cdf0e10cSrcweir break;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir break;
128cdf0e10cSrcweir default:
129cdf0e10cSrcweir OSL_ENSURE( bRet, "unexpected line type value" );
130cdf0e10cSrcweir break;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir if( eNewStrikeout != eStrikeout )
133cdf0e10cSrcweir rValue <<= (sal_Int16)eNewStrikeout;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir else
136cdf0e10cSrcweir {
137cdf0e10cSrcweir rValue <<= (sal_Int16)eNewStrikeout;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir return bRet;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const144cdf0e10cSrcweir sal_Bool XMLCrossedOutTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
145cdf0e10cSrcweir {
146cdf0e10cSrcweir sal_Bool bRet = sal_False;
147cdf0e10cSrcweir sal_Int16 nValue = sal_Int16();
148cdf0e10cSrcweir OUStringBuffer aOut;
149cdf0e10cSrcweir
150cdf0e10cSrcweir if( (rValue >>= nValue) && FontStrikeout::DOUBLE==nValue )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir bRet = SvXMLUnitConverter::convertEnum(
153cdf0e10cSrcweir aOut, (sal_uInt16)nValue, pXML_CrossedoutType_Enum );
154cdf0e10cSrcweir if( bRet )
155cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear();
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
158cdf0e10cSrcweir return bRet;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
162cdf0e10cSrcweir //
163cdf0e10cSrcweir // class XMLCrossedOutStylePropHdl
164cdf0e10cSrcweir //
165cdf0e10cSrcweir
~XMLCrossedOutStylePropHdl()166cdf0e10cSrcweir XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir // nothing to do
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const171cdf0e10cSrcweir sal_Bool XMLCrossedOutStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
172cdf0e10cSrcweir {
173cdf0e10cSrcweir sal_uInt16 eNewStrikeout;
174cdf0e10cSrcweir sal_Bool bRet = SvXMLUnitConverter::convertEnum(
175cdf0e10cSrcweir eNewStrikeout, rStrImpValue, pXML_CrossedoutStyle_Enum );
176cdf0e10cSrcweir if( bRet )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir // multi property: style and width might be set already.
179cdf0e10cSrcweir // If the old value is NONE, the new is used unchanged.
180cdf0e10cSrcweir sal_Int16 eStrikeout = sal_Int16();
181cdf0e10cSrcweir if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir // one NONE a SINGLE are possible new values. For both, the
184cdf0e10cSrcweir // existing value is kept.
185cdf0e10cSrcweir }
186cdf0e10cSrcweir else
187cdf0e10cSrcweir {
188cdf0e10cSrcweir rValue <<= (sal_Int16)eNewStrikeout;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir return bRet;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const195cdf0e10cSrcweir sal_Bool XMLCrossedOutStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
196cdf0e10cSrcweir {
197cdf0e10cSrcweir sal_Bool bRet = sal_False;
198cdf0e10cSrcweir sal_Int16 nValue = sal_Int16();
199cdf0e10cSrcweir OUStringBuffer aOut;
200cdf0e10cSrcweir
201cdf0e10cSrcweir if( rValue >>= nValue )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir bRet = SvXMLUnitConverter::convertEnum(
204cdf0e10cSrcweir aOut, (sal_uInt16)nValue, pXML_CrossedoutStyle_Enum );
205cdf0e10cSrcweir if( bRet )
206cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear();
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir return bRet;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
212cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
213cdf0e10cSrcweir //
214cdf0e10cSrcweir // class XMLCrossedOutWidthPropHdl
215cdf0e10cSrcweir //
216cdf0e10cSrcweir
~XMLCrossedOutWidthPropHdl()217cdf0e10cSrcweir XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl()
218cdf0e10cSrcweir {
219cdf0e10cSrcweir // nothing to do
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const222cdf0e10cSrcweir sal_Bool XMLCrossedOutWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
223cdf0e10cSrcweir {
224cdf0e10cSrcweir sal_uInt16 eNewStrikeout;
225cdf0e10cSrcweir sal_Bool bRet = SvXMLUnitConverter::convertEnum(
226cdf0e10cSrcweir eNewStrikeout, rStrImpValue, pXML_CrossedoutWidth_Enum );
227cdf0e10cSrcweir if( bRet )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir // multi property: style and width might be set already.
230cdf0e10cSrcweir // If the old value is NONE, the new is used unchanged.
231cdf0e10cSrcweir sal_Int16 eStrikeout = sal_Int16();
232cdf0e10cSrcweir if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir switch( eNewStrikeout )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir case FontStrikeout::NONE:
237cdf0e10cSrcweir // keep existing line style
238cdf0e10cSrcweir eNewStrikeout = eStrikeout;
239cdf0e10cSrcweir break;
240cdf0e10cSrcweir case FontStrikeout::BOLD:
241cdf0e10cSrcweir switch( eStrikeout )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir case FontStrikeout::SINGLE:
244cdf0e10cSrcweir break;
245cdf0e10cSrcweir default:
246cdf0e10cSrcweir // If a double line style is not supported for the existing
247cdf0e10cSrcweir // value, keep the new one
248cdf0e10cSrcweir eNewStrikeout = eStrikeout;
249cdf0e10cSrcweir break;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir default:
252cdf0e10cSrcweir OSL_ENSURE( bRet, "unexpected line type value" );
253cdf0e10cSrcweir break;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir if( eNewStrikeout != eStrikeout )
256cdf0e10cSrcweir rValue <<= (sal_Int16)eNewStrikeout;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir else
259cdf0e10cSrcweir {
260cdf0e10cSrcweir rValue <<= (sal_Int16)eNewStrikeout;
261cdf0e10cSrcweir }
262cdf0e10cSrcweir }
263cdf0e10cSrcweir
264cdf0e10cSrcweir return bRet;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const267cdf0e10cSrcweir sal_Bool XMLCrossedOutWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
268cdf0e10cSrcweir {
269cdf0e10cSrcweir sal_Bool bRet = sal_False;
270cdf0e10cSrcweir sal_Int16 nValue = sal_Int16();
271cdf0e10cSrcweir OUStringBuffer aOut;
272cdf0e10cSrcweir
273cdf0e10cSrcweir if( (rValue >>= nValue) && (FontStrikeout::BOLD == nValue) )
274cdf0e10cSrcweir {
275cdf0e10cSrcweir bRet = SvXMLUnitConverter::convertEnum(
276cdf0e10cSrcweir aOut, (sal_uInt16)nValue, pXML_CrossedoutWidth_Enum );
277cdf0e10cSrcweir if( bRet )
278cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear();
279cdf0e10cSrcweir }
280cdf0e10cSrcweir
281cdf0e10cSrcweir return bRet;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
284cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
285cdf0e10cSrcweir //
286cdf0e10cSrcweir // class XMLCrossedOutTextPropHdl
287cdf0e10cSrcweir //
288cdf0e10cSrcweir
~XMLCrossedOutTextPropHdl()289cdf0e10cSrcweir XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl()
290cdf0e10cSrcweir {
291cdf0e10cSrcweir // nothing to do
292cdf0e10cSrcweir }
293cdf0e10cSrcweir
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const294cdf0e10cSrcweir sal_Bool XMLCrossedOutTextPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
295cdf0e10cSrcweir {
296cdf0e10cSrcweir sal_Bool bRet = sal_False;
297cdf0e10cSrcweir
298cdf0e10cSrcweir if( rStrImpValue.getLength() )
299cdf0e10cSrcweir {
300cdf0e10cSrcweir sal_Int16 eStrikeout = ('/' == rStrImpValue[0]
301cdf0e10cSrcweir ? FontStrikeout::SLASH
302cdf0e10cSrcweir : FontStrikeout::X);
303cdf0e10cSrcweir rValue <<= (sal_Int16)eStrikeout;
304cdf0e10cSrcweir bRet = sal_True;
305cdf0e10cSrcweir }
306cdf0e10cSrcweir
307cdf0e10cSrcweir return bRet;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const310cdf0e10cSrcweir sal_Bool XMLCrossedOutTextPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
311cdf0e10cSrcweir {
312cdf0e10cSrcweir sal_Bool bRet = sal_False;
313cdf0e10cSrcweir sal_Int16 nValue = sal_Int16();
314cdf0e10cSrcweir
315cdf0e10cSrcweir if( (rValue >>= nValue) &&
316cdf0e10cSrcweir (FontStrikeout::SLASH == nValue || FontStrikeout::X == nValue) )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir rStrExpValue = OUString::valueOf(
319cdf0e10cSrcweir static_cast< sal_Unicode>( FontStrikeout::SLASH == nValue ? '/'
320cdf0e10cSrcweir : 'X' ) );
321cdf0e10cSrcweir bRet = sal_True;
322cdf0e10cSrcweir }
323cdf0e10cSrcweir
324cdf0e10cSrcweir return bRet;
325cdf0e10cSrcweir }
326cdf0e10cSrcweir
327