bump product version to 7.6.3.2-android
[LibreOffice.git] / xmloff / source / forms / controlpropertyhdl.cxx
blobcb3badee22b7e1688b43c9eee530447409ab3441
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/FontEmphasisMark.hpp>
26 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmltypes.hxx>
29 #include <xmloff/NamedBoolPropertyHdl.hxx>
30 #include "formenums.hxx"
31 #include <xmloff/xmluconv.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <rtl/ustrbuf.hxx>
34 #include <xmloff/XMLConstantsPropertyHandler.hxx>
36 namespace xmloff
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::awt;
42 using namespace ::com::sun::star::beans;
43 using namespace ::xmloff::token;
45 //= OControlPropertyHandlerFactory
46 OControlPropertyHandlerFactory::OControlPropertyHandlerFactory()
50 const XMLPropertyHandler* OControlPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType) const
52 const XMLPropertyHandler* pHandler = nullptr;
54 switch (_nType)
56 case XML_TYPE_TEXT_ALIGN:
57 if (!m_pTextAlignHandler)
58 m_pTextAlignHandler = std::make_unique<XMLConstantsPropertyHandler>(aTextAlignMap, XML_TOKEN_INVALID );
59 pHandler = m_pTextAlignHandler.get();
60 break;
62 case XML_TYPE_CONTROL_BORDER:
63 if (!m_pControlBorderStyleHandler)
64 m_pControlBorderStyleHandler = std::make_unique<OControlBorderHandler>( OControlBorderHandler::STYLE );
65 pHandler = m_pControlBorderStyleHandler.get();
66 break;
68 case XML_TYPE_CONTROL_BORDER_COLOR:
69 if ( !m_pControlBorderColorHandler )
70 m_pControlBorderColorHandler = std::make_unique<OControlBorderHandler>( OControlBorderHandler::COLOR );
71 pHandler = m_pControlBorderColorHandler.get();
72 break;
74 case XML_TYPE_ROTATION_ANGLE:
75 if (!m_pRotationAngleHandler)
76 m_pRotationAngleHandler = std::make_unique<ORotationAngleHandler>();
77 pHandler = m_pRotationAngleHandler.get();
78 break;
80 case XML_TYPE_FONT_WIDTH:
81 if (!m_pFontWidthHandler)
82 m_pFontWidthHandler = std::make_unique<OFontWidthHandler>();
83 pHandler = m_pFontWidthHandler.get();
84 break;
86 case XML_TYPE_CONTROL_TEXT_EMPHASIZE:
87 if (!m_pFontEmphasisHandler)
88 m_pFontEmphasisHandler = std::make_unique<XMLConstantsPropertyHandler>( aFontEmphasisMap, XML_NONE );
89 pHandler = m_pFontEmphasisHandler.get();
90 break;
92 case XML_TYPE_TEXT_FONT_RELIEF:
93 if (!m_pFontReliefHandler)
94 m_pFontReliefHandler = std::make_unique<XMLConstantsPropertyHandler>( aFontReliefMap, XML_NONE );
95 pHandler = m_pFontReliefHandler.get();
96 break;
97 case XML_TYPE_TEXT_LINE_MODE:
98 if (!m_pTextLineModeHandler)
100 m_pTextLineModeHandler = std::make_unique<XMLNamedBoolPropertyHdl>(
101 ::xmloff::token::XML_SKIP_WHITE_SPACE,
102 ::xmloff::token::XML_CONTINUOUS);
104 pHandler = m_pTextLineModeHandler.get();
105 break;
108 if (!pHandler)
109 pHandler = XMLPropertyHandlerFactory::GetPropertyHandler(_nType);
110 return pHandler;
113 //= OControlTextEmphasisHandler
114 OControlTextEmphasisHandler::OControlTextEmphasisHandler()
118 bool OControlTextEmphasisHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
120 bool bSuccess = false;
121 sal_Int16 nFontEmphasis = sal_Int16();
122 if (_rValue >>= nFontEmphasis)
124 // the type
125 sal_uInt16 nType = nFontEmphasis & ~(awt::FontEmphasisMark::ABOVE | awt::FontEmphasisMark::BELOW);
126 // the position of the mark
127 bool bBelow = 0 != (nFontEmphasis & awt::FontEmphasisMark::BELOW);
129 // convert
130 OUStringBuffer aReturn;
131 bSuccess = SvXMLUnitConverter::convertEnum(aReturn, nType, aFontEmphasisMap, XML_NONE);
132 if (bSuccess)
134 aReturn.append( ' ' );
135 aReturn.append( GetXMLToken(bBelow ? XML_BELOW : XML_ABOVE) );
137 _rStrExpValue = aReturn.makeStringAndClear();
141 return bSuccess;
144 bool OControlTextEmphasisHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
146 bool bSuccess = true;
147 sal_uInt16 nEmphasis = awt::FontEmphasisMark::NONE;
149 bool bBelow = false;
150 bool bHasPos = false, bHasType = false;
152 std::u16string_view sToken;
153 SvXMLTokenEnumerator aTokenEnum(_rStrImpValue);
154 while (aTokenEnum.getNextToken(sToken))
156 if (!bHasPos)
158 if (IsXMLToken(sToken, XML_ABOVE))
160 bBelow = false;
161 bHasPos = true;
163 else if (IsXMLToken(sToken, XML_BELOW))
165 bBelow = true;
166 bHasPos = true;
169 if (!bHasType)
171 if (SvXMLUnitConverter::convertEnum(nEmphasis, sToken, aFontEmphasisMap))
173 bHasType = true;
175 else
177 bSuccess = false;
178 break;
183 if (bSuccess)
185 nEmphasis |= bBelow ? awt::FontEmphasisMark::BELOW : awt::FontEmphasisMark::ABOVE;
186 _rValue <<= nEmphasis;
189 return bSuccess;
192 //= OControlBorderHandlerBase
193 OControlBorderHandler::OControlBorderHandler( const OControlBorderHandler::BorderFacet _eFacet )
194 :m_eFacet( _eFacet )
198 bool OControlBorderHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
200 std::u16string_view sToken;
201 SvXMLTokenEnumerator aTokens(_rStrImpValue);
203 sal_uInt16 nStyle = 1;
205 while ( aTokens.getNextToken(sToken) // have a new token
206 && (!sToken.empty()) // really have a new token
209 // try interpreting the token as border style
210 if ( m_eFacet == STYLE )
212 // is it a valid enum value?
213 if ( SvXMLUnitConverter::convertEnum( nStyle, sToken, aBorderTypeMap ) )
215 _rValue <<= nStyle;
216 return true;
220 // try interpreting it as color value
221 if ( m_eFacet == COLOR )
223 sal_Int32 nColor(0);
224 if (::sax::Converter::convertColor( nColor, sToken ))
226 _rValue <<= nColor;
227 return true;
232 return false;
235 bool OControlBorderHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
237 bool bSuccess = false;
239 OUStringBuffer aOut;
240 switch ( m_eFacet )
242 case STYLE:
244 sal_uInt16 nBorder = 0;
245 bSuccess = (_rValue >>= nBorder)
246 && SvXMLUnitConverter::convertEnum( aOut, nBorder, aBorderTypeMap );
248 break;
249 case COLOR:
251 sal_Int32 nBorderColor = 0;
252 if ( _rValue >>= nBorderColor )
254 ::sax::Converter::convertColor(aOut, nBorderColor);
255 bSuccess = true;
258 break;
259 } // switch ( m_eFacet )
261 if ( !bSuccess )
262 return false;
264 if ( !_rStrExpValue.isEmpty() )
265 _rStrExpValue += " ";
266 _rStrExpValue += aOut;
268 return true;
271 //= OFontWidthHandler
272 OFontWidthHandler::OFontWidthHandler()
276 bool OFontWidthHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
278 sal_Int32 nWidth = 0;
279 bool const bSuccess = ::sax::Converter::convertMeasure(
280 nWidth, _rStrImpValue, util::MeasureUnit::POINT);
281 if (bSuccess)
282 _rValue <<= static_cast<sal_Int16>(nWidth);
284 return bSuccess;
287 bool OFontWidthHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
289 sal_Int16 nWidth = 0;
290 OUStringBuffer aResult;
291 if (_rValue >>= nWidth)
293 ::sax::Converter::convertMeasure(aResult, nWidth,
294 util::MeasureUnit::POINT, util::MeasureUnit::POINT);
296 _rStrExpValue = aResult.makeStringAndClear();
298 return !_rStrExpValue.isEmpty();
301 //= ORotationAngleHandler
302 ORotationAngleHandler::ORotationAngleHandler()
306 bool ORotationAngleHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
308 double fValue;
309 bool const bSucces =
310 ::sax::Converter::convertDouble(fValue, _rStrImpValue);
311 if (bSucces)
313 fValue *= 10;
314 _rValue <<= static_cast<float>(fValue);
317 return bSucces;
320 bool ORotationAngleHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
322 float fAngle = 0;
323 bool bSuccess = (_rValue >>= fAngle);
325 if (bSuccess)
327 OUStringBuffer sValue;
328 ::sax::Converter::convertDouble(sValue, static_cast<double>(fAngle) / 10);
329 _rStrExpValue = sValue.makeStringAndClear();
332 return bSuccess;
335 //= ImageScaleModeHandler
336 ImageScaleModeHandler::ImageScaleModeHandler()
337 :XMLConstantsPropertyHandler( aScaleModeMap, XML_STRETCH )
341 } // namespace xmloff
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */