Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <xmloff/controlpropertyhdl.hxx>
31 : :
32 : : #include <com/sun/star/util/MeasureUnit.hpp>
33 : : #include <com/sun/star/awt/TextAlign.hpp>
34 : : #include <com/sun/star/awt/FontWidth.hpp>
35 : : #include <com/sun/star/awt/FontEmphasisMark.hpp>
36 : :
37 : : #include <sax/tools/converter.hxx>
38 : :
39 : : #include <xmloff/xmltypes.hxx>
40 : : #include "xmloff/NamedBoolPropertyHdl.hxx"
41 : : #include "formenums.hxx"
42 : : #include <xmloff/xmluconv.hxx>
43 : : #include <xmloff/xmltoken.hxx>
44 : : #include <rtl/ustrbuf.hxx>
45 : : #include <osl/diagnose.h>
46 : : #include "callbacks.hxx"
47 : : #include <xmloff/XMLConstantsPropertyHandler.hxx>
48 : :
49 : : //.........................................................................
50 : : namespace xmloff
51 : : {
52 : : //.........................................................................
53 : :
54 : : using namespace ::com::sun::star;
55 : : using namespace ::com::sun::star::uno;
56 : : using namespace ::com::sun::star::awt;
57 : : using namespace ::com::sun::star::beans;
58 : : using namespace ::xmloff::token;
59 : :
60 : : //=====================================================================
61 : : //= OControlPropertyHandlerFactory
62 : : //=====================================================================
63 : : //---------------------------------------------------------------------
64 : 1459 : OControlPropertyHandlerFactory::OControlPropertyHandlerFactory()
65 : : :m_pTextAlignHandler(NULL)
66 : : ,m_pControlBorderStyleHandler(NULL)
67 : : ,m_pControlBorderColorHandler(NULL)
68 : : ,m_pRotationAngleHandler(NULL)
69 : : ,m_pFontWidthHandler(NULL)
70 : : ,m_pFontEmphasisHandler(NULL)
71 : 1459 : ,m_pFontReliefHandler(NULL)
72 : : {
73 : 1459 : }
74 : :
75 : : //---------------------------------------------------------------------
76 : 1459 : OControlPropertyHandlerFactory::~OControlPropertyHandlerFactory()
77 : : {
78 [ + + ][ + - ]: 1459 : delete m_pTextAlignHandler;
79 [ + + ][ + - ]: 1459 : delete m_pControlBorderStyleHandler;
80 [ + + ][ + - ]: 1459 : delete m_pControlBorderColorHandler;
81 [ + + ][ + - ]: 1459 : delete m_pRotationAngleHandler;
82 [ + + ][ + - ]: 1459 : delete m_pFontWidthHandler;
83 [ + + ][ + - ]: 1459 : delete m_pFontEmphasisHandler;
84 [ + + ][ + - ]: 1459 : delete m_pFontReliefHandler;
85 [ - + ]: 2210 : }
86 : :
87 : : //---------------------------------------------------------------------
88 : 12078 : const XMLPropertyHandler* OControlPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType) const
89 : : {
90 : 12078 : const XMLPropertyHandler* pHandler = NULL;
91 : :
92 [ + + + + : 12078 : switch (_nType)
+ + + +
+ ]
93 : : {
94 : : case XML_TYPE_TEXT_ALIGN:
95 [ + - ]: 403 : if (!m_pTextAlignHandler)
96 [ + - ]: 403 : m_pTextAlignHandler = new XMLConstantsPropertyHandler(OEnumMapper::getEnumMap(OEnumMapper::epTextAlign), XML_TOKEN_INVALID );
97 : 403 : pHandler = m_pTextAlignHandler;
98 : 403 : break;
99 : :
100 : : case XML_TYPE_CONTROL_BORDER:
101 [ + - ]: 43 : if (!m_pControlBorderStyleHandler)
102 [ + - ]: 43 : m_pControlBorderStyleHandler = new OControlBorderHandler( OControlBorderHandler::STYLE );
103 : 43 : pHandler = m_pControlBorderStyleHandler;
104 : 43 : break;
105 : :
106 : : case XML_TYPE_CONTROL_BORDER_COLOR:
107 [ + - ]: 43 : if ( !m_pControlBorderColorHandler )
108 [ + - ]: 43 : m_pControlBorderColorHandler = new OControlBorderHandler( OControlBorderHandler::COLOR );
109 : 43 : pHandler = m_pControlBorderColorHandler;
110 : 43 : break;
111 : :
112 : : case XML_TYPE_ROTATION_ANGLE:
113 [ + - ]: 403 : if (!m_pRotationAngleHandler)
114 [ + - ]: 403 : m_pRotationAngleHandler = new ORotationAngleHandler;
115 : 403 : pHandler = m_pRotationAngleHandler;
116 : 403 : break;
117 : :
118 : : case XML_TYPE_FONT_WIDTH:
119 [ + - ]: 403 : if (!m_pFontWidthHandler)
120 [ + - ]: 403 : m_pFontWidthHandler = new OFontWidthHandler;
121 : 403 : pHandler = m_pFontWidthHandler;
122 : 403 : break;
123 : :
124 : : case XML_TYPE_CONTROL_TEXT_EMPHASIZE:
125 [ + - ]: 403 : if (!m_pFontEmphasisHandler)
126 [ + - ]: 403 : m_pFontEmphasisHandler = new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis), XML_NONE );
127 : 403 : pHandler = m_pFontEmphasisHandler;
128 : 403 : break;
129 : :
130 : : case XML_TYPE_TEXT_FONT_RELIEF:
131 [ + - ]: 403 : if (!m_pFontReliefHandler)
132 [ + - ]: 403 : m_pFontReliefHandler = new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontRelief), XML_NONE );
133 : 403 : pHandler = m_pFontReliefHandler;
134 : 403 : break;
135 : : case XML_TYPE_TEXT_LINE_MODE:
136 : : pHandler = new XMLNamedBoolPropertyHdl(
137 : : ::xmloff::token::XML_SKIP_WHITE_SPACE,
138 [ + - ]: 360 : ::xmloff::token::XML_CONTINUOUS);
139 : 360 : break;
140 : : }
141 : :
142 [ + + ]: 12078 : if (!pHandler)
143 : 9617 : pHandler = XMLPropertyHandlerFactory::GetPropertyHandler(_nType);
144 : 12078 : return pHandler;
145 : : }
146 : :
147 : : //=====================================================================
148 : : //= OControlTextEmphasisHandler
149 : : //=====================================================================
150 : 744 : OControlTextEmphasisHandler::OControlTextEmphasisHandler()
151 : : {
152 : 744 : }
153 : :
154 : : //---------------------------------------------------------------------
155 : 0 : sal_Bool OControlTextEmphasisHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
156 : : {
157 : 0 : ::rtl::OUStringBuffer aReturn;
158 : 0 : sal_Bool bSuccess = sal_False;
159 : 0 : sal_Int16 nFontEmphasis = sal_Int16();
160 [ # # ]: 0 : if (_rValue >>= nFontEmphasis)
161 : : {
162 : : // the type
163 : 0 : sal_Int16 nType = nFontEmphasis & ~(FontEmphasisMark::ABOVE | FontEmphasisMark::BELOW);
164 : : // the position of the mark
165 : 0 : sal_Bool bBelow = 0 != (nFontEmphasis & FontEmphasisMark::BELOW);
166 : :
167 : : // convert
168 [ # # ][ # # ]: 0 : bSuccess = SvXMLUnitConverter::convertEnum(aReturn, nType, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis), XML_NONE);
169 [ # # ]: 0 : if (bSuccess)
170 : : {
171 [ # # ]: 0 : aReturn.append( (sal_Unicode)' ' );
172 [ # # ][ # # ]: 0 : aReturn.append( GetXMLToken(bBelow ? XML_BELOW : XML_ABOVE) );
[ # # ]
173 : :
174 [ # # ]: 0 : _rStrExpValue = aReturn.makeStringAndClear();
175 : : }
176 : : }
177 : :
178 : 0 : return bSuccess;
179 : : }
180 : :
181 : : //---------------------------------------------------------------------
182 : 0 : sal_Bool OControlTextEmphasisHandler::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
183 : : {
184 : 0 : sal_Bool bSuccess = sal_True;
185 : 0 : sal_uInt16 nEmphasis = FontEmphasisMark::NONE;
186 : :
187 : 0 : sal_Bool bBelow = sal_False;
188 : 0 : sal_Bool bHasPos = sal_False, bHasType = sal_False;
189 : :
190 : 0 : ::rtl::OUString sToken;
191 [ # # ]: 0 : SvXMLTokenEnumerator aTokenEnum(_rStrImpValue);
192 [ # # ][ # # ]: 0 : while (aTokenEnum.getNextToken(sToken))
193 : : {
194 [ # # ]: 0 : if (!bHasPos)
195 : : {
196 [ # # ][ # # ]: 0 : if (IsXMLToken(sToken, XML_ABOVE))
197 : : {
198 : 0 : bBelow = sal_False;
199 : 0 : bHasPos = sal_True;
200 : : }
201 [ # # ][ # # ]: 0 : else if (IsXMLToken(sToken, XML_BELOW))
202 : : {
203 : 0 : bBelow = sal_True;
204 : 0 : bHasPos = sal_True;
205 : : }
206 : : }
207 [ # # ]: 0 : if (!bHasType)
208 : : {
209 [ # # ][ # # ]: 0 : if (SvXMLUnitConverter::convertEnum(nEmphasis, sToken, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis)))
[ # # ]
210 : : {
211 : 0 : bHasType = sal_True;
212 : : }
213 : : else
214 : : {
215 : 0 : bSuccess = sal_False;
216 : 0 : break;
217 : : }
218 : : }
219 : : }
220 : :
221 [ # # ]: 0 : if (bSuccess)
222 : : {
223 [ # # ]: 0 : nEmphasis |= bBelow ? FontEmphasisMark::BELOW : FontEmphasisMark::ABOVE;
224 [ # # ]: 0 : _rValue <<= (sal_Int16)nEmphasis;
225 : : }
226 : :
227 : 0 : return bSuccess;
228 : : }
229 : :
230 : : //=====================================================================
231 : : //= OControlBorderHandlerBase
232 : : //=====================================================================
233 : : //---------------------------------------------------------------------
234 : 1574 : OControlBorderHandler::OControlBorderHandler( const OControlBorderHandler::BorderFacet _eFacet )
235 : 1574 : :m_eFacet( _eFacet )
236 : : {
237 : 1574 : }
238 : :
239 : : //---------------------------------------------------------------------
240 : 4 : sal_Bool OControlBorderHandler::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
241 : : {
242 : 4 : ::rtl::OUString sToken;
243 [ + - ]: 4 : SvXMLTokenEnumerator aTokens(_rStrImpValue);
244 : :
245 : 4 : sal_uInt16 nStyle = 1;
246 : :
247 [ + - ]: 20 : while ( aTokens.getNextToken(sToken) // have a new token
[ + - + - ]
[ + - ]
248 : 10 : && (!sToken.isEmpty()) // really have a new token
249 : : )
250 : : {
251 : : // try interpreting the token as border style
252 [ + + ]: 10 : if ( m_eFacet == STYLE )
253 : : {
254 : : // is it a valid enum value?
255 [ + - ][ + - ]: 4 : if ( SvXMLUnitConverter::convertEnum( nStyle, sToken, OEnumMapper::getEnumMap( OEnumMapper::epBorderWidth ) ) )
[ + + ]
256 : : {
257 [ + - ]: 2 : _rValue <<= nStyle;
258 : 2 : return sal_True;
259 : : }
260 : : }
261 : :
262 : : // try interpreting it as color value
263 [ + + ]: 8 : if ( m_eFacet == COLOR )
264 : : {
265 : 6 : sal_Int32 nColor(0);
266 [ + - ][ + + ]: 6 : if (::sax::Converter::convertColor( nColor, sToken ))
267 : : {
268 [ + - ]: 2 : _rValue <<= nColor;
269 : 6 : return sal_True;
270 : : }
271 : : }
272 : : }
273 : :
274 : 4 : return sal_False;
275 : : }
276 : :
277 : : //---------------------------------------------------------------------
278 : 0 : sal_Bool OControlBorderHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
279 : : {
280 : 0 : sal_Bool bSuccess = sal_False;
281 : :
282 : 0 : ::rtl::OUStringBuffer aOut;
283 [ # # # ]: 0 : switch ( m_eFacet )
284 : : {
285 : : case STYLE:
286 : : {
287 : 0 : sal_Int16 nBorder = 0;
288 : 0 : bSuccess = (_rValue >>= nBorder)
289 [ # # ][ # # ]: 0 : && SvXMLUnitConverter::convertEnum( aOut, nBorder, OEnumMapper::getEnumMap( OEnumMapper::epBorderWidth ) );
[ # # ][ # # ]
290 : : }
291 : 0 : break;
292 : : case COLOR:
293 : : {
294 : 0 : sal_Int32 nBorderColor = 0;
295 [ # # ]: 0 : if ( _rValue >>= nBorderColor )
296 : : {
297 [ # # ]: 0 : ::sax::Converter::convertColor(aOut, nBorderColor);
298 : 0 : bSuccess = sal_True;
299 : : }
300 : : }
301 : 0 : break;
302 : : } // switch ( m_eFacet )
303 : :
304 [ # # ]: 0 : if ( !bSuccess )
305 : 0 : return sal_False;
306 : :
307 [ # # ]: 0 : if ( !_rStrExpValue.isEmpty() )
308 [ # # ]: 0 : _rStrExpValue += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) );
309 [ # # ]: 0 : _rStrExpValue += aOut.makeStringAndClear();
310 : :
311 : 0 : return sal_True;
312 : : }
313 : :
314 : : //=====================================================================
315 : : //= OFontWidthHandler
316 : : //=====================================================================
317 : : //---------------------------------------------------------------------
318 : 403 : OFontWidthHandler::OFontWidthHandler()
319 : : {
320 : 403 : }
321 : :
322 : : //---------------------------------------------------------------------
323 : 0 : sal_Bool OFontWidthHandler::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
324 : : {
325 : 0 : sal_Int32 nWidth = 0;
326 : : bool const bSuccess = ::sax::Converter::convertMeasure(
327 [ # # ]: 0 : nWidth, _rStrImpValue, util::MeasureUnit::POINT);
328 [ # # ]: 0 : if (bSuccess)
329 [ # # ]: 0 : _rValue <<= (sal_Int16)nWidth;
330 : :
331 : 0 : return bSuccess;
332 : : }
333 : :
334 : : //---------------------------------------------------------------------
335 : 0 : sal_Bool OFontWidthHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
336 : : {
337 : 0 : sal_Int16 nWidth = 0;
338 : 0 : ::rtl::OUStringBuffer aResult;
339 [ # # ]: 0 : if (_rValue >>= nWidth)
340 : : {
341 : : ::sax::Converter::convertMeasure(aResult, nWidth,
342 [ # # ]: 0 : util::MeasureUnit::POINT, util::MeasureUnit::POINT);
343 : : }
344 [ # # ]: 0 : _rStrExpValue = aResult.makeStringAndClear();
345 : :
346 : 0 : return !_rStrExpValue.isEmpty();
347 : : }
348 : :
349 : : //=====================================================================
350 : : //= ORotationAngleHandler
351 : : //=====================================================================
352 : : //---------------------------------------------------------------------
353 : 403 : ORotationAngleHandler::ORotationAngleHandler()
354 : : {
355 : 403 : }
356 : :
357 : : //---------------------------------------------------------------------
358 : 0 : sal_Bool ORotationAngleHandler::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
359 : : {
360 : : double fValue;
361 : : bool const bSucces =
362 [ # # ]: 0 : ::sax::Converter::convertDouble(fValue, _rStrImpValue);
363 [ # # ]: 0 : if (bSucces)
364 : : {
365 : 0 : fValue *= 10;
366 [ # # ]: 0 : _rValue <<= (float)fValue;
367 : : }
368 : :
369 : 0 : return bSucces;
370 : : }
371 : :
372 : : //---------------------------------------------------------------------
373 : 0 : sal_Bool ORotationAngleHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
374 : : {
375 : 0 : float fAngle = 0;
376 : 0 : sal_Bool bSuccess = (_rValue >>= fAngle);
377 : :
378 [ # # ]: 0 : if (bSuccess)
379 : : {
380 : 0 : rtl::OUStringBuffer sValue;
381 [ # # ]: 0 : ::sax::Converter::convertDouble(sValue, ((double)fAngle) / 10);
382 [ # # ]: 0 : _rStrExpValue = sValue.makeStringAndClear();
383 : : }
384 : :
385 : 0 : return bSuccess;
386 : : }
387 : :
388 : : //=====================================================================
389 : : //= ImageScaleModeHandler
390 : : //=====================================================================
391 : : //---------------------------------------------------------------------
392 : 744 : ImageScaleModeHandler::ImageScaleModeHandler()
393 : 744 : :XMLConstantsPropertyHandler( OEnumMapper::getEnumMap( OEnumMapper::epImageScaleMode ), XML_STRETCH )
394 : : {
395 : 744 : }
396 : :
397 : : //.........................................................................
398 : : } // namespace xmloff
399 : : //.........................................................................
400 : :
401 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|