bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / prhdlfac.cxx
blobb60119da716432ede34b532b5b44d531e343ff9d
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/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"
57 #include <map>
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() :
109 mpImpl(new Impl) {}
111 XMLPropertyHandlerFactory::~XMLPropertyHandlerFactory()
113 for( CacheMap::iterator pPos = mpImpl->maHandlerCache.begin(); pPos != mpImpl->maHandlerCache.end(); ++pPos )
114 delete pPos->second;
116 delete mpImpl;
119 // Interface
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;
135 return pRet;
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 );
147 if( !pPropHdl )
149 pPropHdl = CreatePropertyHandler( nType );
151 if( pPropHdl )
152 PutHdlCache( nType, pPropHdl );
155 return pPropHdl;
158 const XMLPropertyHandler* XMLPropertyHandlerFactory::CreatePropertyHandler( sal_Int32 nType )
160 XMLPropertyHandler* pPropHdl = NULL;
162 switch( nType )
164 case XML_TYPE_BOOL :
165 pPropHdl = new XMLBoolPropHdl;
166 break;
167 case XML_TYPE_BOOL_FALSE :
168 pPropHdl = new XMLBoolFalsePropHdl;
169 break;
170 case XML_TYPE_MEASURE :
171 pPropHdl = new XMLMeasurePropHdl( 4 );
172 break;
173 case XML_TYPE_MEASURE8 :
174 pPropHdl = new XMLMeasurePropHdl( 1 );
175 break;
176 case XML_TYPE_MEASURE16:
177 pPropHdl = new XMLMeasurePropHdl( 2 );
178 break;
179 case XML_TYPE_PERCENT :
180 pPropHdl = new XMLPercentPropHdl( 4 );
181 break;
182 case XML_TYPE_PERCENT8 :
183 pPropHdl = new XMLPercentPropHdl( 1 );
184 break;
185 case XML_TYPE_PERCENT16 :
186 pPropHdl = new XMLPercentPropHdl( 2 );
187 break;
188 case XML_TYPE_DOUBLE_PERCENT :
189 pPropHdl = new XMLDoublePercentPropHdl();
190 break;
191 case XML_TYPE_NEG_PERCENT :
192 pPropHdl = new XMLNegPercentPropHdl( 4 );
193 break;
194 case XML_TYPE_NEG_PERCENT8 :
195 pPropHdl = new XMLNegPercentPropHdl( 1 );
196 break;
197 case XML_TYPE_NEG_PERCENT16 :
198 pPropHdl = new XMLNegPercentPropHdl( 2 );
199 break;
200 case XML_TYPE_MEASURE_PX :
201 pPropHdl = new XMLMeasurePxPropHdl( 4 );
202 break;
203 case XML_TYPE_STRING :
204 pPropHdl = new XMLStringPropHdl;
205 break;
206 case XML_TYPE_COLOR :
207 pPropHdl = new XMLColorPropHdl;
208 break;
209 case XML_TYPE_HEX :
210 pPropHdl = new XMLHexPropHdl;
211 break;
212 case XML_TYPE_NUMBER :
213 pPropHdl = new XMLNumberPropHdl( 4 );
214 break;
215 case XML_TYPE_NUMBER8 :
216 pPropHdl = new XMLNumberPropHdl( 1 );
217 break;
218 case XML_TYPE_NUMBER16:
219 pPropHdl = new XMLNumberPropHdl( 2 );
220 break;
221 case XML_TYPE_NUMBER_NONE :
222 pPropHdl = new XMLNumberNonePropHdl;
223 break;
224 case XML_TYPE_NUMBER8_NONE :
225 pPropHdl = new XMLNumberNonePropHdl( 1 );
226 break;
227 case XML_TYPE_NUMBER16_NONE :
228 pPropHdl = new XMLNumberNonePropHdl( 2 );
229 break;
230 case XML_TYPE_DOUBLE :
231 pPropHdl = new XMLDoublePropHdl;
232 break;
233 case XML_TYPE_NBOOL :
234 pPropHdl = new XMLNBoolPropHdl;
235 break;
236 case XML_TYPE_COLORTRANSPARENT :
237 pPropHdl = new XMLColorTransparentPropHdl;
238 break;
239 case XML_TYPE_ISTRANSPARENT :
240 pPropHdl = new XMLIsTransparentPropHdl;
241 break;
242 case XML_TYPE_COLORAUTO :
243 pPropHdl = new XMLColorAutoPropHdl;
244 break;
245 case XML_TYPE_ISAUTOCOLOR :
246 pPropHdl = new XMLIsAutoColorPropHdl;
247 break;
248 case XML_TYPE_BUILDIN_CMP_ONLY :
249 pPropHdl = new XMLCompareOnlyPropHdl;
250 break;
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 );
257 break;
259 case XML_TYPE_TEXT_CROSSEDOUT_TYPE:
260 pPropHdl = new XMLCrossedOutTypePropHdl ;
261 break;
262 case XML_TYPE_TEXT_CROSSEDOUT_STYLE:
263 pPropHdl = new XMLCrossedOutStylePropHdl ;
264 break;
265 case XML_TYPE_TEXT_CROSSEDOUT_WIDTH:
266 pPropHdl = new XMLCrossedOutWidthPropHdl ;
267 break;
268 case XML_TYPE_TEXT_CROSSEDOUT_TEXT:
269 pPropHdl = new XMLCrossedOutTextPropHdl ;
270 break;
271 case XML_TYPE_TEXT_BOOLCROSSEDOUT:
272 pPropHdl = new XMLNamedBoolPropertyHdl(
273 GetXMLToken(XML_SOLID),
274 GetXMLToken(XML_NONE) );
275 break;
276 case XML_TYPE_TEXT_ESCAPEMENT:
277 pPropHdl = new XMLEscapementPropHdl;
278 break;
279 case XML_TYPE_TEXT_ESCAPEMENT_HEIGHT:
280 pPropHdl = new XMLEscapementHeightPropHdl;
281 break;
282 case XML_TYPE_TEXT_CASEMAP:
283 pPropHdl = new XMLCaseMapPropHdl;
284 break;
285 case XML_TYPE_TEXT_CASEMAP_VAR:
286 pPropHdl = new XMLCaseMapVariantHdl;
287 break;
288 case XML_TYPE_TEXT_FONTFAMILYNAME:
289 pPropHdl = new XMLFontFamilyNamePropHdl;
290 break;
291 case XML_TYPE_TEXT_FONTFAMILY:
292 pPropHdl = new XMLFontFamilyPropHdl;
293 break;
294 case XML_TYPE_TEXT_FONTENCODING:
295 pPropHdl = new XMLFontEncodingPropHdl;
296 break;
297 case XML_TYPE_TEXT_FONTPITCH:
298 pPropHdl = new XMLFontPitchPropHdl;
299 break;
300 case XML_TYPE_TEXT_KERNING:
301 pPropHdl = new XMLKerningPropHdl;
302 break;
303 case XML_TYPE_TEXT_POSTURE:
304 pPropHdl = new XMLPosturePropHdl;
305 break;
306 case XML_TYPE_TEXT_SHADOWED:
307 pPropHdl = new XMLShadowedPropHdl;
308 break;
309 case XML_TYPE_TEXT_UNDERLINE_TYPE:
310 pPropHdl = new XMLUnderlineTypePropHdl;
311 break;
312 case XML_TYPE_TEXT_UNDERLINE_STYLE:
313 pPropHdl = new XMLUnderlineStylePropHdl;
314 break;
315 case XML_TYPE_TEXT_UNDERLINE_WIDTH:
316 pPropHdl = new XMLUnderlineWidthPropHdl;
317 break;
318 case XML_TYPE_TEXT_UNDERLINE_COLOR:
319 pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR );
320 break;
321 case XML_TYPE_TEXT_UNDERLINE_HASCOLOR:
322 pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR,
323 false );
324 break;
325 case XML_TYPE_TEXT_OVERLINE_TYPE:
326 pPropHdl = new XMLUnderlineTypePropHdl;
327 break;
328 case XML_TYPE_TEXT_OVERLINE_STYLE:
329 pPropHdl = new XMLUnderlineStylePropHdl;
330 break;
331 case XML_TYPE_TEXT_OVERLINE_WIDTH:
332 pPropHdl = new XMLUnderlineWidthPropHdl;
333 break;
334 case XML_TYPE_TEXT_OVERLINE_COLOR:
335 pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR );
336 break;
337 case XML_TYPE_TEXT_OVERLINE_HASCOLOR:
338 pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR,
339 false );
340 break;
341 case XML_TYPE_TEXT_WEIGHT:
342 pPropHdl = new XMLFontWeightPropHdl;
343 break;
344 case XML_TYPE_TEXT_SPLIT:
345 pPropHdl = new XMLNamedBoolPropertyHdl(
346 GetXMLToken(XML_AUTO),
347 GetXMLToken(XML_ALWAYS) );
348 break;
349 case XML_TYPE_TEXT_BREAKBEFORE:
350 pPropHdl = new XMLFmtBreakBeforePropHdl;
351 break;
352 case XML_TYPE_TEXT_BREAKAFTER:
353 pPropHdl = new XMLFmtBreakAfterPropHdl;
354 break;
355 case XML_TYPE_TEXT_SHADOW:
356 pPropHdl = new XMLShadowPropHdl;
357 break;
358 case XML_TYPE_TEXT_ADJUST:
359 pPropHdl = new XMLParaAdjustPropHdl;
360 break;
361 case XML_TYPE_TEXT_ADJUSTLAST:
362 pPropHdl = new XMLLastLineAdjustPropHdl;
363 break;
364 case XML_TYPE_CHAR_HEIGHT:
365 pPropHdl = new XMLCharHeightHdl;
366 break;
367 case XML_TYPE_CHAR_HEIGHT_PROP:
368 pPropHdl = new XMLCharHeightPropHdl;
369 break;
370 case XML_TYPE_CHAR_HEIGHT_DIFF:
371 pPropHdl = new XMLCharHeightDiffHdl;
372 break;
373 case XML_TYPE_CHAR_RFC_LANGUAGE_TAG:
374 pPropHdl = new XMLCharRfcLanguageTagHdl;
375 break;
376 case XML_TYPE_CHAR_LANGUAGE:
377 pPropHdl = new XMLCharLanguageHdl;
378 break;
379 case XML_TYPE_CHAR_SCRIPT:
380 pPropHdl = new XMLCharScriptHdl;
381 break;
382 case XML_TYPE_CHAR_COUNTRY:
383 pPropHdl = new XMLCharCountryHdl;
384 break;
385 case XML_TYPE_LINE_SPACE_FIXED:
386 pPropHdl = new XMLLineHeightHdl;
387 break;
388 case XML_TYPE_LINE_SPACE_MINIMUM:
389 pPropHdl = new XMLLineHeightAtLeastHdl;
390 break;
391 case XML_TYPE_LINE_SPACE_DISTANCE:
392 pPropHdl = new XMLLineSpacingHdl;
393 break;
394 case XML_TYPE_BORDER_WIDTH:
395 pPropHdl = new XMLBorderWidthHdl;
396 break;
397 case XML_TYPE_BORDER:
398 pPropHdl = new XMLBorderHdl;
399 break;
400 case XML_TYPE_TEXT_TABSTOP:
401 pPropHdl = new XMLTabStopPropHdl;
402 break;
403 case XML_TYPE_ATTRIBUTE_CONTAINER:
404 pPropHdl = new XMLAttributeContainerHandler;
405 break;
406 case XML_TYPE_COLOR_MODE:
407 pPropHdl = new XMLEnumPropertyHdl( aXML_ColorMode_EnumMap,
408 cppu::UnoType<drawing::ColorMode>::get());
409 break;
410 case XML_TYPE_DURATION16_MS:
411 pPropHdl = new XMLDurationMS16PropHdl_Impl;
412 break;
413 case XML_TYPE_TEXT_HORIZONTAL_ADJUST:
414 pPropHdl = new XMLEnumPropertyHdl(
415 aXML_HorizontalAdjust_Enum,
416 cppu::UnoType<text::HorizontalAdjust>::get());
417 break;
418 case XML_TYPE_TEXT_DRAW_ASPECT:
419 pPropHdl = new DrawAspectHdl;
420 break;
421 case XML_TYPE_TEXT_WRITING_MODE:
422 pPropHdl = new XMLConstantsPropertyHandler(
423 &(aXML_WritingDirection_Enum[1]),
424 XML_LR_TB);
425 break;
426 case XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT:
427 pPropHdl = new XMLConstantsPropertyHandler(
428 aXML_WritingDirection_Enum,
429 XML_PAGE);
430 break;
431 case XML_TYPE_TEXT_HIDDEN_AS_DISPLAY:
432 pPropHdl = new XMLNamedBoolPropertyHdl(
433 GetXMLToken(XML_NONE),
434 GetXMLToken(XML_TRUE) );
435 break;
436 case XML_TYPE_STYLENAME :
437 pPropHdl = new XMLStyleNamePropHdl;
438 break;
439 case XML_TYPE_NUMBER_NO_ZERO:
440 pPropHdl = new XMLNumberWithoutZeroPropHdl( 4 );
441 break;
442 case XML_TYPE_NUMBER8_NO_ZERO:
443 pPropHdl = new XMLNumberWithoutZeroPropHdl( 1 );
444 break;
445 case XML_TYPE_NUMBER16_NO_ZERO:
446 pPropHdl = new XMLNumberWithoutZeroPropHdl( 2 );
447 break;
448 case XML_TYPE_NUMBER16_AUTO:
449 pPropHdl = new XMLNumberWithAutoInsteadZeroPropHdl();
450 break;
453 return pPropHdl;
456 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */