tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / forms / controlpropertyhdl.cxx
blobeceb9e67aab38fb2bd5b712e5fe61202c4b780df
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/FontEmphasisMark.hpp>
25 #include <sax/tools/converter.hxx>
27 #include <xmloff/xmltypes.hxx>
28 #include <xmloff/NamedBoolPropertyHdl.hxx>
29 #include "formenums.hxx"
30 #include <xmloff/xmluconv.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <rtl/ustrbuf.hxx>
33 #include <xmloff/XMLConstantsPropertyHandler.hxx>
35 namespace xmloff
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::awt;
41 using namespace ::com::sun::star::beans;
42 using namespace ::xmloff::token;
44 //= OControlPropertyHandlerFactory
45 OControlPropertyHandlerFactory::OControlPropertyHandlerFactory()
49 const XMLPropertyHandler* OControlPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType) const
51 const XMLPropertyHandler* pHandler = nullptr;
53 switch (_nType)
55 case XML_TYPE_TEXT_ALIGN:
56 if (!m_pTextAlignHandler)
57 m_pTextAlignHandler = std::make_unique<XMLConstantsPropertyHandler>(aTextAlignMap, XML_TOKEN_INVALID );
58 pHandler = m_pTextAlignHandler.get();
59 break;
61 case XML_TYPE_CONTROL_BORDER:
62 if (!m_pControlBorderStyleHandler)
63 m_pControlBorderStyleHandler = std::make_unique<OControlBorderHandler>( OControlBorderHandler::STYLE );
64 pHandler = m_pControlBorderStyleHandler.get();
65 break;
67 case XML_TYPE_CONTROL_BORDER_COLOR:
68 if ( !m_pControlBorderColorHandler )
69 m_pControlBorderColorHandler = std::make_unique<OControlBorderHandler>( OControlBorderHandler::COLOR );
70 pHandler = m_pControlBorderColorHandler.get();
71 break;
73 case XML_TYPE_ROTATION_ANGLE:
74 if (!m_pRotationAngleHandler)
75 m_pRotationAngleHandler = std::make_unique<ORotationAngleHandler>();
76 pHandler = m_pRotationAngleHandler.get();
77 break;
79 case XML_TYPE_FONT_WIDTH:
80 if (!m_pFontWidthHandler)
81 m_pFontWidthHandler = std::make_unique<OFontWidthHandler>();
82 pHandler = m_pFontWidthHandler.get();
83 break;
85 case XML_TYPE_CONTROL_TEXT_EMPHASIZE:
86 if (!m_pFontEmphasisHandler)
87 m_pFontEmphasisHandler = std::make_unique<XMLConstantsPropertyHandler>( aFontEmphasisMap, XML_NONE );
88 pHandler = m_pFontEmphasisHandler.get();
89 break;
91 case XML_TYPE_TEXT_FONT_RELIEF:
92 if (!m_pFontReliefHandler)
93 m_pFontReliefHandler = std::make_unique<XMLConstantsPropertyHandler>( aFontReliefMap, XML_NONE );
94 pHandler = m_pFontReliefHandler.get();
95 break;
96 case XML_TYPE_TEXT_LINE_MODE:
97 if (!m_pTextLineModeHandler)
99 m_pTextLineModeHandler = std::make_unique<XMLNamedBoolPropertyHdl>(
100 ::xmloff::token::XML_SKIP_WHITE_SPACE,
101 ::xmloff::token::XML_CONTINUOUS);
103 pHandler = m_pTextLineModeHandler.get();
104 break;
107 if (!pHandler)
108 pHandler = XMLPropertyHandlerFactory::GetPropertyHandler(_nType);
109 return pHandler;
112 //= OControlTextEmphasisHandler
113 OControlTextEmphasisHandler::OControlTextEmphasisHandler()
117 bool OControlTextEmphasisHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
119 bool bSuccess = false;
120 sal_Int16 nFontEmphasis = sal_Int16();
121 if (_rValue >>= nFontEmphasis)
123 // the type
124 sal_uInt16 nType = nFontEmphasis & ~(awt::FontEmphasisMark::ABOVE | awt::FontEmphasisMark::BELOW);
125 // the position of the mark
126 bool bBelow = 0 != (nFontEmphasis & awt::FontEmphasisMark::BELOW);
128 // convert
129 OUStringBuffer aReturn;
130 bSuccess = SvXMLUnitConverter::convertEnum(aReturn, nType, aFontEmphasisMap, XML_NONE);
131 if (bSuccess)
133 aReturn.append( ' ' );
134 aReturn.append( GetXMLToken(bBelow ? XML_BELOW : XML_ABOVE) );
136 _rStrExpValue = aReturn.makeStringAndClear();
140 return bSuccess;
143 bool OControlTextEmphasisHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
145 bool bSuccess = true;
146 sal_uInt16 nEmphasis = awt::FontEmphasisMark::NONE;
148 bool bBelow = false;
149 bool bHasPos = false, bHasType = false;
151 std::u16string_view sToken;
152 SvXMLTokenEnumerator aTokenEnum(_rStrImpValue);
153 while (aTokenEnum.getNextToken(sToken))
155 if (!bHasPos)
157 if (IsXMLToken(sToken, XML_ABOVE))
159 bBelow = false;
160 bHasPos = true;
162 else if (IsXMLToken(sToken, XML_BELOW))
164 bBelow = true;
165 bHasPos = true;
168 if (!bHasType)
170 if (SvXMLUnitConverter::convertEnum(nEmphasis, sToken, aFontEmphasisMap))
172 bHasType = true;
174 else
176 bSuccess = false;
177 break;
182 if (bSuccess)
184 nEmphasis |= bBelow ? awt::FontEmphasisMark::BELOW : awt::FontEmphasisMark::ABOVE;
185 _rValue <<= nEmphasis;
188 return bSuccess;
191 //= OControlBorderHandlerBase
192 OControlBorderHandler::OControlBorderHandler( const OControlBorderHandler::BorderFacet _eFacet )
193 :m_eFacet( _eFacet )
197 bool OControlBorderHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
199 std::u16string_view sToken;
200 SvXMLTokenEnumerator aTokens(_rStrImpValue);
202 sal_uInt16 nStyle = 1;
204 while ( aTokens.getNextToken(sToken) // have a new token
205 && (!sToken.empty()) // really have a new token
208 // try interpreting the token as border style
209 if ( m_eFacet == STYLE )
211 // is it a valid enum value?
212 if ( SvXMLUnitConverter::convertEnum( nStyle, sToken, aBorderTypeMap ) )
214 _rValue <<= nStyle;
216 else
218 // The internal LO default is flat, which deviates from the import default of 3d
219 _rValue <<= sal_uInt16(1);
221 return true;
224 // try interpreting it as color value
225 if ( m_eFacet == COLOR )
227 sal_Int32 nColor(0);
228 if (::sax::Converter::convertColor( nColor, sToken ))
230 _rValue <<= nColor;
231 return true;
236 return false;
239 bool OControlBorderHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
241 bool bSuccess = false;
243 OUStringBuffer aOut;
244 switch ( m_eFacet )
246 case STYLE:
248 sal_uInt16 nBorder = 0;
249 bSuccess = (_rValue >>= nBorder)
250 && SvXMLUnitConverter::convertEnum( aOut, nBorder, aBorderTypeMap );
252 break;
253 case COLOR:
255 sal_Int32 nBorderColor = 0;
256 if ( _rValue >>= nBorderColor )
258 ::sax::Converter::convertColor(aOut, nBorderColor);
259 bSuccess = true;
262 break;
263 } // switch ( m_eFacet )
265 if ( !bSuccess )
266 return false;
268 if ( !_rStrExpValue.isEmpty() )
269 _rStrExpValue += " ";
270 _rStrExpValue += aOut;
272 return true;
275 //= OFontWidthHandler
276 OFontWidthHandler::OFontWidthHandler()
280 bool OFontWidthHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
282 sal_Int32 nWidth = 0;
283 bool const bSuccess = ::sax::Converter::convertMeasure(
284 nWidth, _rStrImpValue, util::MeasureUnit::POINT);
285 if (bSuccess)
286 _rValue <<= static_cast<sal_Int16>(nWidth);
288 return bSuccess;
291 bool OFontWidthHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
293 sal_Int16 nWidth = 0;
294 OUStringBuffer aResult;
295 if (_rValue >>= nWidth)
297 ::sax::Converter::convertMeasure(aResult, nWidth,
298 util::MeasureUnit::POINT, util::MeasureUnit::POINT);
300 _rStrExpValue = aResult.makeStringAndClear();
302 return !_rStrExpValue.isEmpty();
305 //= ORotationAngleHandler
306 ORotationAngleHandler::ORotationAngleHandler()
310 bool ORotationAngleHandler::importXML( const OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
312 double fValue;
313 bool const bSucces =
314 ::sax::Converter::convertDouble(fValue, _rStrImpValue);
315 if (bSucces)
317 fValue *= 10;
318 _rValue <<= static_cast<float>(fValue);
321 return bSucces;
324 bool ORotationAngleHandler::exportXML( OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
326 float fAngle = 0;
327 bool bSuccess = (_rValue >>= fAngle);
329 if (bSuccess)
331 OUStringBuffer sValue;
332 ::sax::Converter::convertDouble(sValue, static_cast<double>(fAngle) / 10);
333 _rStrExpValue = sValue.makeStringAndClear();
336 return bSuccess;
339 //= ImageScaleModeHandler
340 ImageScaleModeHandler::ImageScaleModeHandler()
341 :XMLConstantsPropertyHandler( aScaleModeMap, XML_STRETCH )
345 } // namespace xmloff
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */