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: controlpropertyhdl.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 <xmloff/controlpropertyhdl.hxx>
34 #include <com/sun/star/awt/TextAlign.hpp>
35 #include <com/sun/star/awt/FontWidth.hpp>
36 #include <com/sun/star/awt/FontEmphasisMark.hpp>
37 #include <xmloff/xmltypes.hxx>
38 #include "xmloff/NamedBoolPropertyHdl.hxx"
39 #include "formenums.hxx"
40 #include <xmloff/xmluconv.hxx>
41 #include <xmloff/xmltoken.hxx>
42 #include <rtl/ustrbuf.hxx>
43 #include <osl/diagnose.h>
44 #include "callbacks.hxx"
45 #include <xmloff/XMLConstantsPropertyHandler.hxx>
47 //.........................................................................
50 //.........................................................................
52 using namespace ::com::sun::star::uno
;
53 using namespace ::com::sun::star::awt
;
54 using namespace ::com::sun::star::beans
;
55 using namespace ::xmloff::token
;
57 //=====================================================================
58 //= OControlPropertyHandlerFactory
59 //=====================================================================
60 //---------------------------------------------------------------------
61 OControlPropertyHandlerFactory::OControlPropertyHandlerFactory()
62 :m_pTextAlignHandler(NULL
)
63 ,m_pControlBorderStyleHandler(NULL
)
64 ,m_pControlBorderColorHandler(NULL
)
65 ,m_pRotationAngleHandler(NULL
)
66 ,m_pFontWidthHandler(NULL
)
67 ,m_pFontEmphasisHandler(NULL
)
68 ,m_pFontReliefHandler(NULL
)
72 //---------------------------------------------------------------------
73 OControlPropertyHandlerFactory::~OControlPropertyHandlerFactory()
75 delete m_pTextAlignHandler
;
76 delete m_pControlBorderStyleHandler
;
77 delete m_pControlBorderColorHandler
;
78 delete m_pRotationAngleHandler
;
79 delete m_pFontWidthHandler
;
80 delete m_pFontEmphasisHandler
;
81 delete m_pFontReliefHandler
;
84 //---------------------------------------------------------------------
85 const XMLPropertyHandler
* OControlPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType
) const
87 const XMLPropertyHandler
* pHandler
= NULL
;
91 case XML_TYPE_TEXT_ALIGN
:
92 if (!m_pTextAlignHandler
)
93 m_pTextAlignHandler
= new XMLConstantsPropertyHandler(OEnumMapper::getEnumMap(OEnumMapper::epTextAlign
), XML_TOKEN_INVALID
);
94 pHandler
= m_pTextAlignHandler
;
97 case XML_TYPE_CONTROL_BORDER
:
98 if (!m_pControlBorderStyleHandler
)
99 m_pControlBorderStyleHandler
= new OControlBorderHandler( OControlBorderHandler::STYLE
);
100 pHandler
= m_pControlBorderStyleHandler
;
103 case XML_TYPE_CONTROL_BORDER_COLOR
:
104 if ( !m_pControlBorderColorHandler
)
105 m_pControlBorderColorHandler
= new OControlBorderHandler( OControlBorderHandler::COLOR
);
106 pHandler
= m_pControlBorderColorHandler
;
109 case XML_TYPE_ROTATION_ANGLE
:
110 if (!m_pRotationAngleHandler
)
111 m_pRotationAngleHandler
= new ORotationAngleHandler
;
112 pHandler
= m_pRotationAngleHandler
;
115 case XML_TYPE_FONT_WIDTH
:
116 if (!m_pFontWidthHandler
)
117 m_pFontWidthHandler
= new OFontWidthHandler
;
118 pHandler
= m_pFontWidthHandler
;
121 case XML_TYPE_CONTROL_TEXT_EMPHASIZE
:
122 if (!m_pFontEmphasisHandler
)
123 m_pFontEmphasisHandler
= new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis
), XML_NONE
);
124 pHandler
= m_pFontEmphasisHandler
;
127 case XML_TYPE_TEXT_FONT_RELIEF
:
128 if (!m_pFontReliefHandler
)
129 m_pFontReliefHandler
= new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontRelief
), XML_NONE
);
130 pHandler
= m_pFontReliefHandler
;
132 case XML_TYPE_TEXT_LINE_MODE
:
133 pHandler
= new XMLNamedBoolPropertyHdl(
134 ::xmloff::token::XML_SKIP_WHITE_SPACE
,
135 ::xmloff::token::XML_CONTINUOUS
);
140 pHandler
= XMLPropertyHandlerFactory::GetPropertyHandler(_nType
);
144 //=====================================================================
145 //= OControlTextEmphasisHandler
146 //=====================================================================
147 OControlTextEmphasisHandler::OControlTextEmphasisHandler()
151 //---------------------------------------------------------------------
152 sal_Bool
OControlTextEmphasisHandler::exportXML( ::rtl::OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
154 ::rtl::OUStringBuffer aReturn
;
155 sal_Bool bSuccess
= sal_False
;
156 sal_Int16 nFontEmphasis
= sal_Int16();
157 if (_rValue
>>= nFontEmphasis
)
160 sal_Int16 nType
= nFontEmphasis
& ~(FontEmphasisMark::ABOVE
| FontEmphasisMark::BELOW
);
161 // the position of the mark
162 sal_Bool bBelow
= 0 != (nFontEmphasis
& FontEmphasisMark::BELOW
);
165 bSuccess
= SvXMLUnitConverter::convertEnum(aReturn
, nType
, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis
), XML_NONE
);
168 aReturn
.append( (sal_Unicode
)' ' );
169 aReturn
.append( GetXMLToken(bBelow
? XML_BELOW
: XML_ABOVE
) );
171 _rStrExpValue
= aReturn
.makeStringAndClear();
178 //---------------------------------------------------------------------
179 sal_Bool
OControlTextEmphasisHandler::importXML( const ::rtl::OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
181 sal_Bool bSuccess
= sal_True
;
182 sal_uInt16 nEmphasis
= FontEmphasisMark::NONE
;
184 sal_Bool bBelow
= sal_False
;
185 sal_Bool bHasPos
= sal_False
, bHasType
= sal_False
;
187 ::rtl::OUString sToken
;
188 SvXMLTokenEnumerator
aTokenEnum(_rStrImpValue
);
189 while (aTokenEnum
.getNextToken(sToken
))
193 if (IsXMLToken(sToken
, XML_ABOVE
))
198 else if (IsXMLToken(sToken
, XML_BELOW
))
206 if (SvXMLUnitConverter::convertEnum(nEmphasis
, sToken
, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis
)))
212 bSuccess
= sal_False
;
220 nEmphasis
|= bBelow
? FontEmphasisMark::BELOW
: FontEmphasisMark::ABOVE
;
221 _rValue
<<= (sal_Int16
)nEmphasis
;
227 //=====================================================================
228 //= OControlBorderHandlerBase
229 //=====================================================================
230 //---------------------------------------------------------------------
231 OControlBorderHandler::OControlBorderHandler( const OControlBorderHandler::BorderFacet _eFacet
)
236 //---------------------------------------------------------------------
237 sal_Bool
OControlBorderHandler::importXML( const ::rtl::OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
239 ::rtl::OUString sToken
;
240 SvXMLTokenEnumerator
aTokens(_rStrImpValue
);
242 sal_uInt16 nStyle
= 1;
245 while ( aTokens
.getNextToken(sToken
) // have a new token
246 && (0 != sToken
.getLength()) // really have a new token
249 // try interpreting the token as border style
250 if ( m_eFacet
== STYLE
)
252 // is it a valid enum value?
253 if ( SvXMLUnitConverter::convertEnum( nStyle
, sToken
, OEnumMapper::getEnumMap( OEnumMapper::epBorderWidth
) ) )
260 // try interpreting it as color value
261 if ( m_eFacet
== COLOR
)
263 if ( SvXMLUnitConverter::convertColor( aColor
, sToken
) )
265 _rValue
<<= (sal_Int32
)aColor
.GetColor();
274 //---------------------------------------------------------------------
275 sal_Bool
OControlBorderHandler::exportXML( ::rtl::OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
277 sal_Bool bSuccess
= sal_False
;
279 ::rtl::OUStringBuffer aOut
;
284 sal_Int16 nBorder
= 0;
285 bSuccess
= (_rValue
>>= nBorder
)
286 && SvXMLUnitConverter::convertEnum( aOut
, nBorder
, OEnumMapper::getEnumMap( OEnumMapper::epBorderWidth
) );
291 sal_Int32 nBorderColor
= 0;
292 if ( _rValue
>>= nBorderColor
)
294 SvXMLUnitConverter::convertColor( aOut
, Color( nBorderColor
) );
299 } // switch ( m_eFacet )
304 if ( _rStrExpValue
.getLength() )
305 _rStrExpValue
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) );
306 _rStrExpValue
+= aOut
.makeStringAndClear();
311 //=====================================================================
312 //= OFontWidthHandler
313 //=====================================================================
314 //---------------------------------------------------------------------
315 OFontWidthHandler::OFontWidthHandler()
319 //---------------------------------------------------------------------
320 sal_Bool
OFontWidthHandler::importXML( const ::rtl::OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
322 sal_Int32 nWidth
= 0;
323 sal_Bool bSuccess
= SvXMLUnitConverter::convertMeasure(nWidth
, _rStrImpValue
, MAP_POINT
);
325 _rValue
<<= (sal_Int16
)nWidth
;
330 //---------------------------------------------------------------------
331 sal_Bool
OFontWidthHandler::exportXML( ::rtl::OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
333 sal_Int16 nWidth
= 0;
334 ::rtl::OUStringBuffer aResult
;
335 if (_rValue
>>= nWidth
)
336 SvXMLUnitConverter::convertMeasure(aResult
, nWidth
, MAP_POINT
, MAP_POINT
);
337 _rStrExpValue
= aResult
.makeStringAndClear();
339 return _rStrExpValue
.getLength() != 0;
342 //=====================================================================
343 //= ORotationAngleHandler
344 //=====================================================================
345 //---------------------------------------------------------------------
346 ORotationAngleHandler::ORotationAngleHandler()
350 //---------------------------------------------------------------------
351 sal_Bool
ORotationAngleHandler::importXML( const ::rtl::OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
355 SvXMLUnitConverter::convertDouble(fValue
, _rStrImpValue
);
359 _rValue
<<= (float)fValue
;
365 //---------------------------------------------------------------------
366 sal_Bool
ORotationAngleHandler::exportXML( ::rtl::OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
369 sal_Bool bSuccess
= (_rValue
>>= fAngle
);
373 rtl::OUStringBuffer sValue
;
374 SvXMLUnitConverter::convertDouble(sValue
, ((double)fAngle
) / 10);
375 _rStrExpValue
= sValue
.makeStringAndClear();
381 //=====================================================================
382 //= ImageScaleModeHandler
383 //=====================================================================
384 //---------------------------------------------------------------------
385 ImageScaleModeHandler::ImageScaleModeHandler()
386 :XMLConstantsPropertyHandler( OEnumMapper::getEnumMap( OEnumMapper::epImageScaleMode
), XML_STRETCH
)
390 //.........................................................................
391 } // namespace xmloff
392 //.........................................................................