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 .
21 #include <xmloff/controlpropertyhdl.hxx>
23 #include <com/sun/star/util/MeasureUnit.hpp>
24 #include <com/sun/star/awt/TextAlign.hpp>
25 #include <com/sun/star/awt/FontWidth.hpp>
26 #include <com/sun/star/awt/FontEmphasisMark.hpp>
28 #include <sax/tools/converter.hxx>
30 #include <xmloff/xmltypes.hxx>
31 #include "xmloff/NamedBoolPropertyHdl.hxx"
32 #include "formenums.hxx"
33 #include <xmloff/xmluconv.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include <osl/diagnose.h>
37 #include "callbacks.hxx"
38 #include <xmloff/XMLConstantsPropertyHandler.hxx>
40 //.........................................................................
43 //.........................................................................
45 using namespace ::com::sun::star
;
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::awt
;
48 using namespace ::com::sun::star::beans
;
49 using namespace ::xmloff::token
;
51 //=====================================================================
52 //= OControlPropertyHandlerFactory
53 //=====================================================================
54 //---------------------------------------------------------------------
55 OControlPropertyHandlerFactory::OControlPropertyHandlerFactory()
56 :m_pTextAlignHandler(NULL
)
57 ,m_pControlBorderStyleHandler(NULL
)
58 ,m_pControlBorderColorHandler(NULL
)
59 ,m_pRotationAngleHandler(NULL
)
60 ,m_pFontWidthHandler(NULL
)
61 ,m_pFontEmphasisHandler(NULL
)
62 ,m_pFontReliefHandler(NULL
)
66 //---------------------------------------------------------------------
67 OControlPropertyHandlerFactory::~OControlPropertyHandlerFactory()
69 delete m_pTextAlignHandler
;
70 delete m_pControlBorderStyleHandler
;
71 delete m_pControlBorderColorHandler
;
72 delete m_pRotationAngleHandler
;
73 delete m_pFontWidthHandler
;
74 delete m_pFontEmphasisHandler
;
75 delete m_pFontReliefHandler
;
78 //---------------------------------------------------------------------
79 const XMLPropertyHandler
* OControlPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType
) const
81 const XMLPropertyHandler
* pHandler
= NULL
;
85 case XML_TYPE_TEXT_ALIGN
:
86 if (!m_pTextAlignHandler
)
87 m_pTextAlignHandler
= new XMLConstantsPropertyHandler(OEnumMapper::getEnumMap(OEnumMapper::epTextAlign
), XML_TOKEN_INVALID
);
88 pHandler
= m_pTextAlignHandler
;
91 case XML_TYPE_CONTROL_BORDER
:
92 if (!m_pControlBorderStyleHandler
)
93 m_pControlBorderStyleHandler
= new OControlBorderHandler( OControlBorderHandler::STYLE
);
94 pHandler
= m_pControlBorderStyleHandler
;
97 case XML_TYPE_CONTROL_BORDER_COLOR
:
98 if ( !m_pControlBorderColorHandler
)
99 m_pControlBorderColorHandler
= new OControlBorderHandler( OControlBorderHandler::COLOR
);
100 pHandler
= m_pControlBorderColorHandler
;
103 case XML_TYPE_ROTATION_ANGLE
:
104 if (!m_pRotationAngleHandler
)
105 m_pRotationAngleHandler
= new ORotationAngleHandler
;
106 pHandler
= m_pRotationAngleHandler
;
109 case XML_TYPE_FONT_WIDTH
:
110 if (!m_pFontWidthHandler
)
111 m_pFontWidthHandler
= new OFontWidthHandler
;
112 pHandler
= m_pFontWidthHandler
;
115 case XML_TYPE_CONTROL_TEXT_EMPHASIZE
:
116 if (!m_pFontEmphasisHandler
)
117 m_pFontEmphasisHandler
= new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis
), XML_NONE
);
118 pHandler
= m_pFontEmphasisHandler
;
121 case XML_TYPE_TEXT_FONT_RELIEF
:
122 if (!m_pFontReliefHandler
)
123 m_pFontReliefHandler
= new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontRelief
), XML_NONE
);
124 pHandler
= m_pFontReliefHandler
;
126 case XML_TYPE_TEXT_LINE_MODE
:
127 pHandler
= new XMLNamedBoolPropertyHdl(
128 ::xmloff::token::XML_SKIP_WHITE_SPACE
,
129 ::xmloff::token::XML_CONTINUOUS
);
134 pHandler
= XMLPropertyHandlerFactory::GetPropertyHandler(_nType
);
138 //=====================================================================
139 //= OControlTextEmphasisHandler
140 //=====================================================================
141 OControlTextEmphasisHandler::OControlTextEmphasisHandler()
145 //---------------------------------------------------------------------
146 sal_Bool
OControlTextEmphasisHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
148 OUStringBuffer aReturn
;
149 sal_Bool bSuccess
= sal_False
;
150 sal_Int16 nFontEmphasis
= sal_Int16();
151 if (_rValue
>>= nFontEmphasis
)
154 sal_Int16 nType
= nFontEmphasis
& ~(awt::FontEmphasisMark::ABOVE
| awt::FontEmphasisMark::BELOW
);
155 // the position of the mark
156 sal_Bool bBelow
= 0 != (nFontEmphasis
& awt::FontEmphasisMark::BELOW
);
159 bSuccess
= SvXMLUnitConverter::convertEnum(aReturn
, nType
, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis
), XML_NONE
);
162 aReturn
.append( (sal_Unicode
)' ' );
163 aReturn
.append( GetXMLToken(bBelow
? XML_BELOW
: XML_ABOVE
) );
165 _rStrExpValue
= aReturn
.makeStringAndClear();
172 //---------------------------------------------------------------------
173 sal_Bool
OControlTextEmphasisHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
175 sal_Bool bSuccess
= sal_True
;
176 sal_uInt16 nEmphasis
= awt::FontEmphasisMark::NONE
;
178 sal_Bool bBelow
= sal_False
;
179 sal_Bool bHasPos
= sal_False
, bHasType
= sal_False
;
182 SvXMLTokenEnumerator
aTokenEnum(_rStrImpValue
);
183 while (aTokenEnum
.getNextToken(sToken
))
187 if (IsXMLToken(sToken
, XML_ABOVE
))
192 else if (IsXMLToken(sToken
, XML_BELOW
))
200 if (SvXMLUnitConverter::convertEnum(nEmphasis
, sToken
, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis
)))
206 bSuccess
= sal_False
;
214 nEmphasis
|= bBelow
? awt::FontEmphasisMark::BELOW
: awt::FontEmphasisMark::ABOVE
;
215 _rValue
<<= (sal_Int16
)nEmphasis
;
221 //=====================================================================
222 //= OControlBorderHandlerBase
223 //=====================================================================
224 //---------------------------------------------------------------------
225 OControlBorderHandler::OControlBorderHandler( const OControlBorderHandler::BorderFacet _eFacet
)
230 //---------------------------------------------------------------------
231 sal_Bool
OControlBorderHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
234 SvXMLTokenEnumerator
aTokens(_rStrImpValue
);
236 sal_uInt16 nStyle
= 1;
238 while ( aTokens
.getNextToken(sToken
) // have a new token
239 && (!sToken
.isEmpty()) // really have a new token
242 // try interpreting the token as border style
243 if ( m_eFacet
== STYLE
)
245 // is it a valid enum value?
246 if ( SvXMLUnitConverter::convertEnum( nStyle
, sToken
, OEnumMapper::getEnumMap( OEnumMapper::epBorderWidth
) ) )
253 // try interpreting it as color value
254 if ( m_eFacet
== COLOR
)
257 if (::sax::Converter::convertColor( nColor
, sToken
))
268 //---------------------------------------------------------------------
269 sal_Bool
OControlBorderHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
271 sal_Bool bSuccess
= sal_False
;
278 sal_Int16 nBorder
= 0;
279 bSuccess
= (_rValue
>>= nBorder
)
280 && SvXMLUnitConverter::convertEnum( aOut
, nBorder
, OEnumMapper::getEnumMap( OEnumMapper::epBorderWidth
) );
285 sal_Int32 nBorderColor
= 0;
286 if ( _rValue
>>= nBorderColor
)
288 ::sax::Converter::convertColor(aOut
, nBorderColor
);
293 } // switch ( m_eFacet )
298 if ( !_rStrExpValue
.isEmpty() )
299 _rStrExpValue
+= " ";
300 _rStrExpValue
+= aOut
.makeStringAndClear();
305 //=====================================================================
306 //= OFontWidthHandler
307 //=====================================================================
308 //---------------------------------------------------------------------
309 OFontWidthHandler::OFontWidthHandler()
313 //---------------------------------------------------------------------
314 sal_Bool
OFontWidthHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
316 sal_Int32 nWidth
= 0;
317 bool const bSuccess
= ::sax::Converter::convertMeasure(
318 nWidth
, _rStrImpValue
, util::MeasureUnit::POINT
);
320 _rValue
<<= (sal_Int16
)nWidth
;
325 //---------------------------------------------------------------------
326 sal_Bool
OFontWidthHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
328 sal_Int16 nWidth
= 0;
329 OUStringBuffer aResult
;
330 if (_rValue
>>= nWidth
)
332 ::sax::Converter::convertMeasure(aResult
, nWidth
,
333 util::MeasureUnit::POINT
, util::MeasureUnit::POINT
);
335 _rStrExpValue
= aResult
.makeStringAndClear();
337 return !_rStrExpValue
.isEmpty();
340 //=====================================================================
341 //= ORotationAngleHandler
342 //=====================================================================
343 //---------------------------------------------------------------------
344 ORotationAngleHandler::ORotationAngleHandler()
348 //---------------------------------------------------------------------
349 sal_Bool
ORotationAngleHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
353 ::sax::Converter::convertDouble(fValue
, _rStrImpValue
);
357 _rValue
<<= (float)fValue
;
363 //---------------------------------------------------------------------
364 sal_Bool
ORotationAngleHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
367 sal_Bool bSuccess
= (_rValue
>>= fAngle
);
371 OUStringBuffer sValue
;
372 ::sax::Converter::convertDouble(sValue
, ((double)fAngle
) / 10);
373 _rStrExpValue
= sValue
.makeStringAndClear();
379 //=====================================================================
380 //= ImageScaleModeHandler
381 //=====================================================================
382 //---------------------------------------------------------------------
383 ImageScaleModeHandler::ImageScaleModeHandler()
384 :XMLConstantsPropertyHandler( OEnumMapper::getEnumMap( OEnumMapper::epImageScaleMode
), XML_STRETCH
)
388 //.........................................................................
389 } // namespace xmloff
390 //.........................................................................
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */