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/prhdlfac.hxx>
22 #include <com/sun/star/drawing/ColorMode.hpp>
23 #include <com/sun/star/text/HorizontalAdjust.hpp>
24 #include <com/sun/star/text/WritingMode2.hpp>
26 #include <tools/debug.hxx>
28 #include <xmloff/xmltypes.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmlprhdl.hxx>
31 #include "xmlbahdl.hxx"
32 #include <xmloff/NamedBoolPropertyHdl.hxx>
33 #include <xmloff/XMLConstantsPropertyHandler.hxx>
34 #include "cdouthdl.hxx"
35 #include "csmaphdl.hxx"
36 #include "fonthdl.hxx"
37 #include "kernihdl.hxx"
38 #include <postuhdl.hxx>
39 #include "shadwhdl.hxx"
40 #include "shdwdhdl.hxx"
41 #include "undlihdl.hxx"
42 #include "weighhdl.hxx"
43 #include "breakhdl.hxx"
44 #include <adjushdl.hxx>
45 #include <escphdl.hxx>
46 #include <chrhghdl.hxx>
47 #include <chrlohdl.hxx>
48 #include <lspachdl.hxx>
49 #include <bordrhdl.hxx>
50 #include <tabsthdl.hxx>
51 #include <xmloff/EnumPropertyHdl.hxx>
52 #include "AttributeContainerHandler.hxx"
53 #include "durationhdl.hxx"
54 #include "XMLRectangleMembersHandler.hxx"
55 #include "DrawAspectHdl.hxx"
59 using namespace ::com::sun::star
;
60 using namespace ::xmloff::token
;
62 static SvXMLEnumMapEntry
const aXML_ColorMode_EnumMap
[] =
64 { XML_GREYSCALE
, drawing::ColorMode_GREYS
},
65 { XML_MONO
, drawing::ColorMode_MONO
},
66 { XML_WATERMARK
, drawing::ColorMode_WATERMARK
},
67 { XML_STANDARD
, drawing::ColorMode_STANDARD
},
68 { XML_TOKEN_INVALID
, 0 }
71 static SvXMLEnumMapEntry
const aXML_HorizontalAdjust_Enum
[] =
73 { XML_LEFT
, text::HorizontalAdjust_LEFT
},
74 { XML_CENTER
, text::HorizontalAdjust_CENTER
},
75 { XML_RIGHT
, text::HorizontalAdjust_RIGHT
},
76 { XML_TOKEN_INVALID
, 0 }
79 // aXML_WritingDirection_Enum is used with and without 'page'
80 // attribute, so you'll find uses of aXML_WritingDirection_Enum
81 // directly, as well as &(aXML_WritingDirection_Enum[1])
82 static SvXMLEnumMapEntry
const aXML_WritingDirection_Enum
[] =
84 // aXML_WritingDirection_Enum
85 { XML_PAGE
, text::WritingMode2::PAGE
},
87 // &(aXML_WritingDirection_Enum[1])
88 { XML_LR_TB
, text::WritingMode2::LR_TB
},
89 { XML_RL_TB
, text::WritingMode2::RL_TB
},
90 { XML_TB_RL
, text::WritingMode2::TB_RL
},
91 { XML_TB_LR
, text::WritingMode2::TB_LR
},
93 // alternative names of the above, as accepted by XSL
94 { XML_LR
, text::WritingMode2::LR_TB
},
95 { XML_RL
, text::WritingMode2::RL_TB
},
96 { XML_TB
, text::WritingMode2::TB_RL
},
98 { XML_TOKEN_INVALID
, 0 }
101 typedef std::map
<sal_Int32
, const XMLPropertyHandler
*> CacheMap
;
103 struct XMLPropertyHandlerFactory::Impl
105 mutable CacheMap maHandlerCache
;
108 XMLPropertyHandlerFactory::XMLPropertyHandlerFactory() :
111 XMLPropertyHandlerFactory::~XMLPropertyHandlerFactory()
113 for( CacheMap::iterator pPos
= mpImpl
->maHandlerCache
.begin(); pPos
!= mpImpl
->maHandlerCache
.end(); ++pPos
)
120 const XMLPropertyHandler
* XMLPropertyHandlerFactory::GetPropertyHandler( sal_Int32 nType
) const
122 DBG_ASSERT( (nType
& ~((sal_uInt32
)MID_FLAG_MASK
)) == 0,
123 "GetPropertyHandler called with flags in type" );
124 return GetBasicHandler( nType
);
127 // Helper-methods to create and cache PropertyHandler
128 const XMLPropertyHandler
* XMLPropertyHandlerFactory::GetHdlCache( sal_Int32 nType
) const
130 const XMLPropertyHandler
* pRet
= NULL
;
132 if( mpImpl
->maHandlerCache
.find( nType
) != mpImpl
->maHandlerCache
.end() )
133 pRet
= mpImpl
->maHandlerCache
.find( nType
)->second
;
138 void XMLPropertyHandlerFactory::PutHdlCache( sal_Int32 nType
, const XMLPropertyHandler
* pHdl
) const
140 mpImpl
->maHandlerCache
[nType
] = pHdl
;
143 const XMLPropertyHandler
* XMLPropertyHandlerFactory::GetBasicHandler( sal_Int32 nType
) const
145 const XMLPropertyHandler
* pPropHdl
= GetHdlCache( nType
);
149 pPropHdl
= CreatePropertyHandler( nType
);
152 PutHdlCache( nType
, pPropHdl
);
158 const XMLPropertyHandler
* XMLPropertyHandlerFactory::CreatePropertyHandler( sal_Int32 nType
)
160 XMLPropertyHandler
* pPropHdl
= NULL
;
165 pPropHdl
= new XMLBoolPropHdl
;
167 case XML_TYPE_BOOL_FALSE
:
168 pPropHdl
= new XMLBoolFalsePropHdl
;
170 case XML_TYPE_MEASURE
:
171 pPropHdl
= new XMLMeasurePropHdl( 4 );
173 case XML_TYPE_MEASURE8
:
174 pPropHdl
= new XMLMeasurePropHdl( 1 );
176 case XML_TYPE_MEASURE16
:
177 pPropHdl
= new XMLMeasurePropHdl( 2 );
179 case XML_TYPE_PERCENT
:
180 pPropHdl
= new XMLPercentPropHdl( 4 );
182 case XML_TYPE_PERCENT8
:
183 pPropHdl
= new XMLPercentPropHdl( 1 );
185 case XML_TYPE_PERCENT16
:
186 pPropHdl
= new XMLPercentPropHdl( 2 );
188 case XML_TYPE_DOUBLE_PERCENT
:
189 pPropHdl
= new XMLDoublePercentPropHdl();
191 case XML_TYPE_NEG_PERCENT
:
192 pPropHdl
= new XMLNegPercentPropHdl( 4 );
194 case XML_TYPE_NEG_PERCENT8
:
195 pPropHdl
= new XMLNegPercentPropHdl( 1 );
197 case XML_TYPE_NEG_PERCENT16
:
198 pPropHdl
= new XMLNegPercentPropHdl( 2 );
200 case XML_TYPE_MEASURE_PX
:
201 pPropHdl
= new XMLMeasurePxPropHdl( 4 );
203 case XML_TYPE_STRING
:
204 pPropHdl
= new XMLStringPropHdl
;
206 case XML_TYPE_COLOR
:
207 pPropHdl
= new XMLColorPropHdl
;
210 pPropHdl
= new XMLHexPropHdl
;
212 case XML_TYPE_NUMBER
:
213 pPropHdl
= new XMLNumberPropHdl( 4 );
215 case XML_TYPE_NUMBER8
:
216 pPropHdl
= new XMLNumberPropHdl( 1 );
218 case XML_TYPE_NUMBER16
:
219 pPropHdl
= new XMLNumberPropHdl( 2 );
221 case XML_TYPE_NUMBER_NONE
:
222 pPropHdl
= new XMLNumberNonePropHdl
;
224 case XML_TYPE_NUMBER8_NONE
:
225 pPropHdl
= new XMLNumberNonePropHdl( 1 );
227 case XML_TYPE_NUMBER16_NONE
:
228 pPropHdl
= new XMLNumberNonePropHdl( 2 );
230 case XML_TYPE_DOUBLE
:
231 pPropHdl
= new XMLDoublePropHdl
;
233 case XML_TYPE_NBOOL
:
234 pPropHdl
= new XMLNBoolPropHdl
;
236 case XML_TYPE_COLORTRANSPARENT
:
237 pPropHdl
= new XMLColorTransparentPropHdl
;
239 case XML_TYPE_ISTRANSPARENT
:
240 pPropHdl
= new XMLIsTransparentPropHdl
;
242 case XML_TYPE_COLORAUTO
:
243 pPropHdl
= new XMLColorAutoPropHdl
;
245 case XML_TYPE_ISAUTOCOLOR
:
246 pPropHdl
= new XMLIsAutoColorPropHdl
;
248 case XML_TYPE_BUILDIN_CMP_ONLY
:
249 pPropHdl
= new XMLCompareOnlyPropHdl
;
252 case XML_TYPE_RECTANGLE_LEFT
:
253 case XML_TYPE_RECTANGLE_TOP
:
254 case XML_TYPE_RECTANGLE_WIDTH
:
255 case XML_TYPE_RECTANGLE_HEIGHT
:
256 pPropHdl
= new XMLRectangleMembersHdl( nType
);
259 case XML_TYPE_TEXT_CROSSEDOUT_TYPE
:
260 pPropHdl
= new XMLCrossedOutTypePropHdl
;
262 case XML_TYPE_TEXT_CROSSEDOUT_STYLE
:
263 pPropHdl
= new XMLCrossedOutStylePropHdl
;
265 case XML_TYPE_TEXT_CROSSEDOUT_WIDTH
:
266 pPropHdl
= new XMLCrossedOutWidthPropHdl
;
268 case XML_TYPE_TEXT_CROSSEDOUT_TEXT
:
269 pPropHdl
= new XMLCrossedOutTextPropHdl
;
271 case XML_TYPE_TEXT_BOOLCROSSEDOUT
:
272 pPropHdl
= new XMLNamedBoolPropertyHdl(
273 GetXMLToken(XML_SOLID
),
274 GetXMLToken(XML_NONE
) );
276 case XML_TYPE_TEXT_ESCAPEMENT
:
277 pPropHdl
= new XMLEscapementPropHdl
;
279 case XML_TYPE_TEXT_ESCAPEMENT_HEIGHT
:
280 pPropHdl
= new XMLEscapementHeightPropHdl
;
282 case XML_TYPE_TEXT_CASEMAP
:
283 pPropHdl
= new XMLCaseMapPropHdl
;
285 case XML_TYPE_TEXT_CASEMAP_VAR
:
286 pPropHdl
= new XMLCaseMapVariantHdl
;
288 case XML_TYPE_TEXT_FONTFAMILYNAME
:
289 pPropHdl
= new XMLFontFamilyNamePropHdl
;
291 case XML_TYPE_TEXT_FONTFAMILY
:
292 pPropHdl
= new XMLFontFamilyPropHdl
;
294 case XML_TYPE_TEXT_FONTENCODING
:
295 pPropHdl
= new XMLFontEncodingPropHdl
;
297 case XML_TYPE_TEXT_FONTPITCH
:
298 pPropHdl
= new XMLFontPitchPropHdl
;
300 case XML_TYPE_TEXT_KERNING
:
301 pPropHdl
= new XMLKerningPropHdl
;
303 case XML_TYPE_TEXT_POSTURE
:
304 pPropHdl
= new XMLPosturePropHdl
;
306 case XML_TYPE_TEXT_SHADOWED
:
307 pPropHdl
= new XMLShadowedPropHdl
;
309 case XML_TYPE_TEXT_UNDERLINE_TYPE
:
310 pPropHdl
= new XMLUnderlineTypePropHdl
;
312 case XML_TYPE_TEXT_UNDERLINE_STYLE
:
313 pPropHdl
= new XMLUnderlineStylePropHdl
;
315 case XML_TYPE_TEXT_UNDERLINE_WIDTH
:
316 pPropHdl
= new XMLUnderlineWidthPropHdl
;
318 case XML_TYPE_TEXT_UNDERLINE_COLOR
:
319 pPropHdl
= new XMLColorTransparentPropHdl( XML_FONT_COLOR
);
321 case XML_TYPE_TEXT_UNDERLINE_HASCOLOR
:
322 pPropHdl
= new XMLIsTransparentPropHdl( XML_FONT_COLOR
,
325 case XML_TYPE_TEXT_OVERLINE_TYPE
:
326 pPropHdl
= new XMLUnderlineTypePropHdl
;
328 case XML_TYPE_TEXT_OVERLINE_STYLE
:
329 pPropHdl
= new XMLUnderlineStylePropHdl
;
331 case XML_TYPE_TEXT_OVERLINE_WIDTH
:
332 pPropHdl
= new XMLUnderlineWidthPropHdl
;
334 case XML_TYPE_TEXT_OVERLINE_COLOR
:
335 pPropHdl
= new XMLColorTransparentPropHdl( XML_FONT_COLOR
);
337 case XML_TYPE_TEXT_OVERLINE_HASCOLOR
:
338 pPropHdl
= new XMLIsTransparentPropHdl( XML_FONT_COLOR
,
341 case XML_TYPE_TEXT_WEIGHT
:
342 pPropHdl
= new XMLFontWeightPropHdl
;
344 case XML_TYPE_TEXT_SPLIT
:
345 pPropHdl
= new XMLNamedBoolPropertyHdl(
346 GetXMLToken(XML_AUTO
),
347 GetXMLToken(XML_ALWAYS
) );
349 case XML_TYPE_TEXT_BREAKBEFORE
:
350 pPropHdl
= new XMLFmtBreakBeforePropHdl
;
352 case XML_TYPE_TEXT_BREAKAFTER
:
353 pPropHdl
= new XMLFmtBreakAfterPropHdl
;
355 case XML_TYPE_TEXT_SHADOW
:
356 pPropHdl
= new XMLShadowPropHdl
;
358 case XML_TYPE_TEXT_ADJUST
:
359 pPropHdl
= new XMLParaAdjustPropHdl
;
361 case XML_TYPE_TEXT_ADJUSTLAST
:
362 pPropHdl
= new XMLLastLineAdjustPropHdl
;
364 case XML_TYPE_CHAR_HEIGHT
:
365 pPropHdl
= new XMLCharHeightHdl
;
367 case XML_TYPE_CHAR_HEIGHT_PROP
:
368 pPropHdl
= new XMLCharHeightPropHdl
;
370 case XML_TYPE_CHAR_HEIGHT_DIFF
:
371 pPropHdl
= new XMLCharHeightDiffHdl
;
373 case XML_TYPE_CHAR_RFC_LANGUAGE_TAG
:
374 pPropHdl
= new XMLCharRfcLanguageTagHdl
;
376 case XML_TYPE_CHAR_LANGUAGE
:
377 pPropHdl
= new XMLCharLanguageHdl
;
379 case XML_TYPE_CHAR_SCRIPT
:
380 pPropHdl
= new XMLCharScriptHdl
;
382 case XML_TYPE_CHAR_COUNTRY
:
383 pPropHdl
= new XMLCharCountryHdl
;
385 case XML_TYPE_LINE_SPACE_FIXED
:
386 pPropHdl
= new XMLLineHeightHdl
;
388 case XML_TYPE_LINE_SPACE_MINIMUM
:
389 pPropHdl
= new XMLLineHeightAtLeastHdl
;
391 case XML_TYPE_LINE_SPACE_DISTANCE
:
392 pPropHdl
= new XMLLineSpacingHdl
;
394 case XML_TYPE_BORDER_WIDTH
:
395 pPropHdl
= new XMLBorderWidthHdl
;
397 case XML_TYPE_BORDER
:
398 pPropHdl
= new XMLBorderHdl
;
400 case XML_TYPE_TEXT_TABSTOP
:
401 pPropHdl
= new XMLTabStopPropHdl
;
403 case XML_TYPE_ATTRIBUTE_CONTAINER
:
404 pPropHdl
= new XMLAttributeContainerHandler
;
406 case XML_TYPE_COLOR_MODE
:
407 pPropHdl
= new XMLEnumPropertyHdl( aXML_ColorMode_EnumMap
,
408 cppu::UnoType
<drawing::ColorMode
>::get());
410 case XML_TYPE_DURATION16_MS
:
411 pPropHdl
= new XMLDurationMS16PropHdl_Impl
;
413 case XML_TYPE_TEXT_HORIZONTAL_ADJUST
:
414 pPropHdl
= new XMLEnumPropertyHdl(
415 aXML_HorizontalAdjust_Enum
,
416 cppu::UnoType
<text::HorizontalAdjust
>::get());
418 case XML_TYPE_TEXT_DRAW_ASPECT
:
419 pPropHdl
= new DrawAspectHdl
;
421 case XML_TYPE_TEXT_WRITING_MODE
:
422 pPropHdl
= new XMLConstantsPropertyHandler(
423 &(aXML_WritingDirection_Enum
[1]),
426 case XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT
:
427 pPropHdl
= new XMLConstantsPropertyHandler(
428 aXML_WritingDirection_Enum
,
431 case XML_TYPE_TEXT_HIDDEN_AS_DISPLAY
:
432 pPropHdl
= new XMLNamedBoolPropertyHdl(
433 GetXMLToken(XML_NONE
),
434 GetXMLToken(XML_TRUE
) );
436 case XML_TYPE_STYLENAME
:
437 pPropHdl
= new XMLStyleNamePropHdl
;
439 case XML_TYPE_NUMBER_NO_ZERO
:
440 pPropHdl
= new XMLNumberWithoutZeroPropHdl( 4 );
442 case XML_TYPE_NUMBER8_NO_ZERO
:
443 pPropHdl
= new XMLNumberWithoutZeroPropHdl( 1 );
445 case XML_TYPE_NUMBER16_NO_ZERO
:
446 pPropHdl
= new XMLNumberWithoutZeroPropHdl( 2 );
448 case XML_TYPE_NUMBER16_AUTO
:
449 pPropHdl
= new XMLNumberWithAutoInsteadZeroPropHdl();
456 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */