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 <xmloff/controlpropertyhdl.hxx>
22 #include <com/sun/star/util/MeasureUnit.hpp>
23 #include <com/sun/star/awt/TextAlign.hpp>
24 #include <com/sun/star/awt/FontWidth.hpp>
25 #include <com/sun/star/awt/FontEmphasisMark.hpp>
27 #include <sax/tools/converter.hxx>
29 #include <xmloff/xmltypes.hxx>
30 #include <xmloff/NamedBoolPropertyHdl.hxx>
31 #include "formenums.hxx"
32 #include <xmloff/xmluconv.hxx>
33 #include <xmloff/xmltoken.hxx>
34 #include <rtl/ustrbuf.hxx>
35 #include <osl/diagnose.h>
36 #include "callbacks.hxx"
37 #include <xmloff/XMLConstantsPropertyHandler.hxx>
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::awt
;
45 using namespace ::com::sun::star::beans
;
46 using namespace ::xmloff::token
;
48 //= OControlPropertyHandlerFactory
49 OControlPropertyHandlerFactory::OControlPropertyHandlerFactory()
50 :m_pTextAlignHandler(nullptr)
51 ,m_pControlBorderStyleHandler(nullptr)
52 ,m_pControlBorderColorHandler(nullptr)
53 ,m_pRotationAngleHandler(nullptr)
54 ,m_pFontWidthHandler(nullptr)
55 ,m_pFontEmphasisHandler(nullptr)
56 ,m_pFontReliefHandler(nullptr)
60 OControlPropertyHandlerFactory::~OControlPropertyHandlerFactory()
62 delete m_pTextAlignHandler
;
63 delete m_pControlBorderStyleHandler
;
64 delete m_pControlBorderColorHandler
;
65 delete m_pRotationAngleHandler
;
66 delete m_pFontWidthHandler
;
67 delete m_pFontEmphasisHandler
;
68 delete m_pFontReliefHandler
;
71 const XMLPropertyHandler
* OControlPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType
) const
73 const XMLPropertyHandler
* pHandler
= nullptr;
77 case XML_TYPE_TEXT_ALIGN
:
78 if (!m_pTextAlignHandler
)
79 m_pTextAlignHandler
= new XMLConstantsPropertyHandler(OEnumMapper::getEnumMap(OEnumMapper::epTextAlign
), XML_TOKEN_INVALID
);
80 pHandler
= m_pTextAlignHandler
;
83 case XML_TYPE_CONTROL_BORDER
:
84 if (!m_pControlBorderStyleHandler
)
85 m_pControlBorderStyleHandler
= new OControlBorderHandler( OControlBorderHandler::STYLE
);
86 pHandler
= m_pControlBorderStyleHandler
;
89 case XML_TYPE_CONTROL_BORDER_COLOR
:
90 if ( !m_pControlBorderColorHandler
)
91 m_pControlBorderColorHandler
= new OControlBorderHandler( OControlBorderHandler::COLOR
);
92 pHandler
= m_pControlBorderColorHandler
;
95 case XML_TYPE_ROTATION_ANGLE
:
96 if (!m_pRotationAngleHandler
)
97 m_pRotationAngleHandler
= new ORotationAngleHandler
;
98 pHandler
= m_pRotationAngleHandler
;
101 case XML_TYPE_FONT_WIDTH
:
102 if (!m_pFontWidthHandler
)
103 m_pFontWidthHandler
= new OFontWidthHandler
;
104 pHandler
= m_pFontWidthHandler
;
107 case XML_TYPE_CONTROL_TEXT_EMPHASIZE
:
108 if (!m_pFontEmphasisHandler
)
109 m_pFontEmphasisHandler
= new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis
), XML_NONE
);
110 pHandler
= m_pFontEmphasisHandler
;
113 case XML_TYPE_TEXT_FONT_RELIEF
:
114 if (!m_pFontReliefHandler
)
115 m_pFontReliefHandler
= new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontRelief
), XML_NONE
);
116 pHandler
= m_pFontReliefHandler
;
118 case XML_TYPE_TEXT_LINE_MODE
:
119 pHandler
= new XMLNamedBoolPropertyHdl(
120 ::xmloff::token::XML_SKIP_WHITE_SPACE
,
121 ::xmloff::token::XML_CONTINUOUS
);
126 pHandler
= XMLPropertyHandlerFactory::GetPropertyHandler(_nType
);
130 //= OControlTextEmphasisHandler
131 OControlTextEmphasisHandler::OControlTextEmphasisHandler()
135 bool OControlTextEmphasisHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
137 OUStringBuffer aReturn
;
138 bool bSuccess
= false;
139 sal_Int16 nFontEmphasis
= sal_Int16();
140 if (_rValue
>>= nFontEmphasis
)
143 sal_Int16 nType
= nFontEmphasis
& ~(awt::FontEmphasisMark::ABOVE
| awt::FontEmphasisMark::BELOW
);
144 // the position of the mark
145 bool bBelow
= 0 != (nFontEmphasis
& awt::FontEmphasisMark::BELOW
);
148 bSuccess
= SvXMLUnitConverter::convertEnum(aReturn
, nType
, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis
), XML_NONE
);
151 aReturn
.append( ' ' );
152 aReturn
.append( GetXMLToken(bBelow
? XML_BELOW
: XML_ABOVE
) );
154 _rStrExpValue
= aReturn
.makeStringAndClear();
161 bool OControlTextEmphasisHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
163 bool bSuccess
= true;
164 sal_uInt16 nEmphasis
= awt::FontEmphasisMark::NONE
;
167 bool bHasPos
= false, bHasType
= false;
170 SvXMLTokenEnumerator
aTokenEnum(_rStrImpValue
);
171 while (aTokenEnum
.getNextToken(sToken
))
175 if (IsXMLToken(sToken
, XML_ABOVE
))
180 else if (IsXMLToken(sToken
, XML_BELOW
))
188 if (SvXMLUnitConverter::convertEnum(nEmphasis
, sToken
, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis
)))
202 nEmphasis
|= bBelow
? awt::FontEmphasisMark::BELOW
: awt::FontEmphasisMark::ABOVE
;
203 _rValue
<<= (sal_Int16
)nEmphasis
;
209 //= OControlBorderHandlerBase
210 OControlBorderHandler::OControlBorderHandler( const OControlBorderHandler::BorderFacet _eFacet
)
215 bool OControlBorderHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
218 SvXMLTokenEnumerator
aTokens(_rStrImpValue
);
220 sal_uInt16 nStyle
= 1;
222 while ( aTokens
.getNextToken(sToken
) // have a new token
223 && (!sToken
.isEmpty()) // really have a new token
226 // try interpreting the token as border style
227 if ( m_eFacet
== STYLE
)
229 // is it a valid enum value?
230 if ( SvXMLUnitConverter::convertEnum( nStyle
, sToken
, OEnumMapper::getEnumMap( OEnumMapper::epBorderWidth
) ) )
237 // try interpreting it as color value
238 if ( m_eFacet
== COLOR
)
241 if (::sax::Converter::convertColor( nColor
, sToken
))
252 bool OControlBorderHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
254 bool bSuccess
= false;
261 sal_Int16 nBorder
= 0;
262 bSuccess
= (_rValue
>>= nBorder
)
263 && SvXMLUnitConverter::convertEnum( aOut
, nBorder
, OEnumMapper::getEnumMap( OEnumMapper::epBorderWidth
) );
268 sal_Int32 nBorderColor
= 0;
269 if ( _rValue
>>= nBorderColor
)
271 ::sax::Converter::convertColor(aOut
, nBorderColor
);
276 } // switch ( m_eFacet )
281 if ( !_rStrExpValue
.isEmpty() )
282 _rStrExpValue
+= " ";
283 _rStrExpValue
+= aOut
.makeStringAndClear();
288 //= OFontWidthHandler
289 OFontWidthHandler::OFontWidthHandler()
293 bool OFontWidthHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
295 sal_Int32 nWidth
= 0;
296 bool const bSuccess
= ::sax::Converter::convertMeasure(
297 nWidth
, _rStrImpValue
, util::MeasureUnit::POINT
);
299 _rValue
<<= (sal_Int16
)nWidth
;
304 bool OFontWidthHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
306 sal_Int16 nWidth
= 0;
307 OUStringBuffer aResult
;
308 if (_rValue
>>= nWidth
)
310 ::sax::Converter::convertMeasure(aResult
, nWidth
,
311 util::MeasureUnit::POINT
, util::MeasureUnit::POINT
);
313 _rStrExpValue
= aResult
.makeStringAndClear();
315 return !_rStrExpValue
.isEmpty();
318 //= ORotationAngleHandler
319 ORotationAngleHandler::ORotationAngleHandler()
323 bool ORotationAngleHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
327 ::sax::Converter::convertDouble(fValue
, _rStrImpValue
);
331 _rValue
<<= (float)fValue
;
337 bool ORotationAngleHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
340 bool bSuccess
= (_rValue
>>= fAngle
);
344 OUStringBuffer sValue
;
345 ::sax::Converter::convertDouble(sValue
, ((double)fAngle
) / 10);
346 _rStrExpValue
= sValue
.makeStringAndClear();
352 //= ImageScaleModeHandler
353 ImageScaleModeHandler::ImageScaleModeHandler()
354 :XMLConstantsPropertyHandler( OEnumMapper::getEnumMap( OEnumMapper::epImageScaleMode
), XML_STRETCH
)
358 } // namespace xmloff
360 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */