xref: /aoo42x/main/xmloff/source/style/prhdlfac.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 #include <com/sun/star/drawing/ColorMode.hpp>
32 #include <com/sun/star/text/HorizontalAdjust.hpp>
33 #include <com/sun/star/text/WritingMode2.hpp>
34 
35 #include <tools/debug.hxx>
36 
37 #include <xmloff/prhdlfac.hxx>
38 #include <xmloff/xmltypes.hxx>
39 #include <xmloff/xmltoken.hxx>
40 #include "xmlbahdl.hxx"
41 #include <xmloff/NamedBoolPropertyHdl.hxx>
42 #include <xmloff/XMLConstantsPropertyHandler.hxx>
43 #include "cdouthdl.hxx"
44 #include "csmaphdl.hxx"
45 #include "fonthdl.hxx"
46 #include "kernihdl.hxx"
47 #include <postuhdl.hxx>
48 #include "shadwhdl.hxx"
49 #include "shdwdhdl.hxx"
50 #include "undlihdl.hxx"
51 #include "weighhdl.hxx"
52 #include "breakhdl.hxx"
53 #include <adjushdl.hxx>
54 #include <escphdl.hxx>
55 #include <chrhghdl.hxx>
56 #include <chrlohdl.hxx>
57 #include <lspachdl.hxx>
58 #include <bordrhdl.hxx>
59 #include <tabsthdl.hxx>
60 #include <xmloff/EnumPropertyHdl.hxx>
61 #include "AttributeContainerHandler.hxx"
62 #include "durationhdl.hxx"
63 #include "XMLRectangleMembersHandler.hxx"
64 #include "DrawAspectHdl.hxx"
65 
66 using namespace ::com::sun::star;
67 using namespace ::xmloff::token;
68 
69 SvXMLEnumMapEntry aXML_ColorMode_EnumMap[] =
70 {
71 	{ XML_GREYSCALE,    drawing::ColorMode_GREYS },
72 	{ XML_MONO,	        drawing::ColorMode_MONO },
73 	{ XML_WATERMARK,    drawing::ColorMode_WATERMARK },
74 	{ XML_STANDARD,     drawing::ColorMode_STANDARD },
75 	{ XML_TOKEN_INVALID, 0 }
76 };
77 
78 SvXMLEnumMapEntry __READONLY_DATA aXML_HorizontalAdjust_Enum[] =
79 {
80 	{ XML_LEFT,	    text::HorizontalAdjust_LEFT },
81 	{ XML_CENTER,	text::HorizontalAdjust_CENTER },
82 	{ XML_RIGHT,	text::HorizontalAdjust_RIGHT },
83 	{ XML_TOKEN_INVALID, 0 }
84 };
85 
86 // aXML_WritingDirection_Enum is used with and without 'page'
87 // attribute, so you'll find uses of aXML_WritingDirection_Enum
88 // directly, as well as &(aXML_WritingDirection_Enum[1])
89 SvXMLEnumMapEntry __READONLY_DATA aXML_WritingDirection_Enum[] =
90 {
91     // aXML_WritingDirection_Enum
92     { XML_PAGE,     text::WritingMode2::PAGE },
93 
94     // &(aXML_WritingDirection_Enum[1])
95     { XML_LR_TB,    text::WritingMode2::LR_TB },
96     { XML_RL_TB,    text::WritingMode2::RL_TB },
97     { XML_TB_RL,    text::WritingMode2::TB_RL },
98     { XML_TB_LR,    text::WritingMode2::TB_LR },
99 
100     // alternative names of the above, as accepted by XSL
101     { XML_LR,       text::WritingMode2::LR_TB },
102     { XML_RL,       text::WritingMode2::RL_TB },
103     { XML_TB,       text::WritingMode2::TB_RL },
104 
105     { XML_TOKEN_INVALID, 0 }
106 };
107 
108 
109 ///////////////////////////////////////////////////////////////////////////
110 //
111 // Dtor
112 //
113 XMLPropertyHandlerFactory::~XMLPropertyHandlerFactory()
114 {
115 	for( CacheMap::iterator pPos = maHandlerCache.begin(); pPos != maHandlerCache.end(); pPos++ )
116 		delete pPos->second;
117 }
118 
119 ///////////////////////////////////////////////////////////////////////////
120 //
121 // Interface
122 //
123 const XMLPropertyHandler* XMLPropertyHandlerFactory::GetPropertyHandler( sal_Int32 nType ) const
124 {
125 	DBG_ASSERT( (nType & ~((sal_uInt32)MID_FLAG_MASK)) == 0,
126 				"GetPropertyHandler called with flags in type" );
127 	return GetBasicHandler( nType );
128 }
129 
130 ///////////////////////////////////////////////////////////////////////////
131 //
132 // Helper-methods to create and cache PropertyHandler
133 //
134 XMLPropertyHandler* XMLPropertyHandlerFactory::GetHdlCache( sal_Int32 nType ) const
135 {
136 	XMLPropertyHandler* pRet = NULL;
137 
138 	if( maHandlerCache.find( nType ) != maHandlerCache.end() )
139 		pRet = maHandlerCache.find( nType )->second;
140 
141 	return pRet;
142 }
143 
144 void XMLPropertyHandlerFactory::PutHdlCache( sal_Int32 nType, const XMLPropertyHandler* pHdl ) const
145 {
146 	// Don't be wondered about the following construct. The  sense is to be able to provide a const-
147 	// method as class-interface.
148 	((XMLPropertyHandlerFactory*)this)->maHandlerCache[ nType ] = (XMLPropertyHandler*)pHdl;
149 }
150 
151 const XMLPropertyHandler* XMLPropertyHandlerFactory::GetBasicHandler( sal_Int32 nType ) const
152 {
153 	const XMLPropertyHandler* pPropHdl = GetHdlCache( nType );
154 
155 	if( !pPropHdl )
156 	{
157         pPropHdl = CreatePropertyHandler( nType );
158 
159 		if( pPropHdl )
160 			PutHdlCache( nType, pPropHdl );
161 	}
162 
163 	return pPropHdl;
164 }
165 
166 const XMLPropertyHandler* XMLPropertyHandlerFactory::CreatePropertyHandler( sal_Int32 nType )
167 {
168     XMLPropertyHandler* pPropHdl = NULL;
169 
170     switch( nType )
171     {
172         case XML_TYPE_BOOL :
173             pPropHdl = new XMLBoolPropHdl;
174             break;
175         case XML_TYPE_MEASURE :
176             pPropHdl = new XMLMeasurePropHdl( 4 );
177             break;
178         case XML_TYPE_MEASURE8 :
179             pPropHdl = new XMLMeasurePropHdl( 1 );
180             break;
181 		case XML_TYPE_MEASURE16:
182 			pPropHdl = new XMLMeasurePropHdl( 2 );
183 			break;
184 		case XML_TYPE_PERCENT :
185 			pPropHdl = new XMLPercentPropHdl( 4 );
186 			break;
187 		case XML_TYPE_PERCENT8 :
188 			pPropHdl = new XMLPercentPropHdl( 1 );
189 			break;
190 		case XML_TYPE_PERCENT16 :
191 			pPropHdl = new XMLPercentPropHdl( 2 );
192 			break;
193 		case XML_TYPE_DOUBLE_PERCENT :
194 			pPropHdl = new XMLDoublePercentPropHdl();
195 			break;
196 		case XML_TYPE_NEG_PERCENT :
197 			pPropHdl = new XMLNegPercentPropHdl( 4 );
198 			break;
199 		case XML_TYPE_NEG_PERCENT8 :
200 			pPropHdl = new XMLNegPercentPropHdl( 1 );
201 			break;
202 		case XML_TYPE_NEG_PERCENT16 :
203 			pPropHdl = new XMLNegPercentPropHdl( 2 );
204 			break;
205 		case XML_TYPE_MEASURE_PX :
206 			pPropHdl = new XMLMeasurePxPropHdl( 4 );
207 			break;
208 		case XML_TYPE_STRING :
209 			pPropHdl = new XMLStringPropHdl;
210 			break;
211 		case XML_TYPE_COLOR :
212 			pPropHdl = new XMLColorPropHdl;
213 			break;
214 		case XML_TYPE_NUMBER :
215 			pPropHdl = new XMLNumberPropHdl( 4 );
216 			break;
217 		case XML_TYPE_NUMBER8 :
218 			pPropHdl = new XMLNumberPropHdl( 1 );
219 			break;
220 		case XML_TYPE_NUMBER16:
221 			pPropHdl = new XMLNumberPropHdl( 2 );
222 			break;
223 		case XML_TYPE_NUMBER_NONE :
224 			pPropHdl = new XMLNumberNonePropHdl;
225 			break;
226 		case XML_TYPE_NUMBER8_NONE :
227 			pPropHdl = new XMLNumberNonePropHdl( 1 );
228 			break;
229 		case XML_TYPE_NUMBER16_NONE :
230 			pPropHdl = new XMLNumberNonePropHdl( 2 );
231 			break;
232 		case XML_TYPE_DOUBLE :
233 			pPropHdl = new XMLDoublePropHdl;
234 			break;
235 		case XML_TYPE_NBOOL :
236 			pPropHdl = new XMLNBoolPropHdl;
237 			break;
238 		case XML_TYPE_COLORTRANSPARENT :
239 			pPropHdl = new XMLColorTransparentPropHdl;
240 			break;
241 		case XML_TYPE_ISTRANSPARENT :
242 			pPropHdl = new XMLIsTransparentPropHdl;
243 			break;
244 		case XML_TYPE_COLORAUTO :
245 			pPropHdl = new XMLColorAutoPropHdl;
246 			break;
247 		case XML_TYPE_ISAUTOCOLOR :
248 			pPropHdl = new XMLIsAutoColorPropHdl;
249 			break;
250 		case XML_TYPE_BUILDIN_CMP_ONLY :
251 			pPropHdl = new XMLCompareOnlyPropHdl;
252 			break;
253 
254 		case XML_TYPE_RECTANGLE_LEFT :
255 		case XML_TYPE_RECTANGLE_TOP :
256 		case XML_TYPE_RECTANGLE_WIDTH :
257 		case XML_TYPE_RECTANGLE_HEIGHT :
258 			pPropHdl = new XMLRectangleMembersHdl( nType );
259 			break;
260 
261 		case XML_TYPE_TEXT_CROSSEDOUT_TYPE:
262 			pPropHdl = new XMLCrossedOutTypePropHdl ;
263 			break;
264 		case XML_TYPE_TEXT_CROSSEDOUT_STYLE:
265 			pPropHdl = new XMLCrossedOutStylePropHdl ;
266 			break;
267 		case XML_TYPE_TEXT_CROSSEDOUT_WIDTH:
268 			pPropHdl = new XMLCrossedOutWidthPropHdl ;
269 			break;
270 		case XML_TYPE_TEXT_CROSSEDOUT_TEXT:
271 			pPropHdl = new XMLCrossedOutTextPropHdl ;
272 			break;
273 		case XML_TYPE_TEXT_BOOLCROSSEDOUT:
274             pPropHdl = new XMLNamedBoolPropertyHdl(
275                 GetXMLToken(XML_SOLID),
276                 GetXMLToken(XML_NONE) );
277 			break;
278 		case XML_TYPE_TEXT_ESCAPEMENT:
279 			pPropHdl = new XMLEscapementPropHdl;
280 			break;
281 		case XML_TYPE_TEXT_ESCAPEMENT_HEIGHT:
282 			pPropHdl = new XMLEscapementHeightPropHdl;
283 			break;
284 		case XML_TYPE_TEXT_CASEMAP:
285 			pPropHdl = new XMLCaseMapPropHdl;
286 			break;
287 		case XML_TYPE_TEXT_CASEMAP_VAR:
288 			pPropHdl = new XMLCaseMapVariantHdl;
289 			break;
290 		case XML_TYPE_TEXT_FONTFAMILYNAME:
291 			pPropHdl = new XMLFontFamilyNamePropHdl;
292 			break;
293 		case XML_TYPE_TEXT_FONTFAMILY:
294 			pPropHdl = new XMLFontFamilyPropHdl;
295 			break;
296 		case XML_TYPE_TEXT_FONTENCODING:
297 			pPropHdl = new XMLFontEncodingPropHdl;
298 			break;
299 		case XML_TYPE_TEXT_FONTPITCH:
300 			pPropHdl = new XMLFontPitchPropHdl;
301 			break;
302 		case XML_TYPE_TEXT_KERNING:
303 			pPropHdl = new XMLKerningPropHdl;
304 			break;
305 		case XML_TYPE_TEXT_POSTURE:
306 			pPropHdl = new XMLPosturePropHdl;
307 			break;
308 		case XML_TYPE_TEXT_SHADOWED:
309 			pPropHdl = new XMLShadowedPropHdl;
310 			break;
311 		case XML_TYPE_TEXT_UNDERLINE_TYPE:
312 			pPropHdl = new XMLUnderlineTypePropHdl;
313 			break;
314 		case XML_TYPE_TEXT_UNDERLINE_STYLE:
315 			pPropHdl = new XMLUnderlineStylePropHdl;
316 			break;
317 		case XML_TYPE_TEXT_UNDERLINE_WIDTH:
318 			pPropHdl = new XMLUnderlineWidthPropHdl;
319 			break;
320 		case XML_TYPE_TEXT_UNDERLINE_COLOR:
321 			pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR );
322 			break;
323 		case XML_TYPE_TEXT_UNDERLINE_HASCOLOR:
324 			pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR,
325 												 	sal_False );
326 			break;
327 		case XML_TYPE_TEXT_OVERLINE_TYPE:
328 			pPropHdl = new XMLUnderlineTypePropHdl;
329 			break;
330 		case XML_TYPE_TEXT_OVERLINE_STYLE:
331 			pPropHdl = new XMLUnderlineStylePropHdl;
332 			break;
333 		case XML_TYPE_TEXT_OVERLINE_WIDTH:
334 			pPropHdl = new XMLUnderlineWidthPropHdl;
335 			break;
336 		case XML_TYPE_TEXT_OVERLINE_COLOR:
337 			pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR );
338 			break;
339 		case XML_TYPE_TEXT_OVERLINE_HASCOLOR:
340 			pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR,
341 												 	sal_False );
342 			break;
343 		case XML_TYPE_TEXT_WEIGHT:
344 			pPropHdl = new XMLFontWeightPropHdl;
345 			break;
346 		case XML_TYPE_TEXT_SPLIT:
347             pPropHdl = new XMLNamedBoolPropertyHdl(
348                 GetXMLToken(XML_AUTO),
349                 GetXMLToken(XML_ALWAYS) );
350 			break;
351 		case XML_TYPE_TEXT_BREAKBEFORE:
352 			pPropHdl = new XMLFmtBreakBeforePropHdl;
353 			break;
354 		case XML_TYPE_TEXT_BREAKAFTER:
355 			pPropHdl = new XMLFmtBreakAfterPropHdl;
356 			break;
357 		case XML_TYPE_TEXT_SHADOW:
358 			pPropHdl = new XMLShadowPropHdl;
359 			break;
360 		case XML_TYPE_TEXT_ADJUST:
361 			pPropHdl = new XMLParaAdjustPropHdl;
362 			break;
363 		case XML_TYPE_TEXT_ADJUSTLAST:
364 			pPropHdl = new XMLLastLineAdjustPropHdl;
365 			break;
366 		case XML_TYPE_CHAR_HEIGHT:
367 			pPropHdl = new XMLCharHeightHdl;
368 			break;
369 		case XML_TYPE_CHAR_HEIGHT_PROP:
370 			pPropHdl = new XMLCharHeightPropHdl;
371 			break;
372 		case XML_TYPE_CHAR_HEIGHT_DIFF:
373 			pPropHdl = new XMLCharHeightDiffHdl;
374 			break;
375 		case XML_TYPE_CHAR_LANGUAGE:
376 			pPropHdl = new XMLCharLanguageHdl;
377 			break;
378 		case XML_TYPE_CHAR_COUNTRY:
379 			pPropHdl = new XMLCharCountryHdl;
380 			break;
381 		case XML_TYPE_LINE_SPACE_FIXED:
382 			pPropHdl = new XMLLineHeightHdl;
383 			break;
384 		case XML_TYPE_LINE_SPACE_MINIMUM:
385 			pPropHdl = new XMLLineHeightAtLeastHdl;
386 			break;
387 		case XML_TYPE_LINE_SPACE_DISTANCE:
388 			pPropHdl = new XMLLineSpacingHdl;
389 			break;
390 		case XML_TYPE_BORDER_WIDTH:
391 			pPropHdl = new XMLBorderWidthHdl;
392 			break;
393 		case XML_TYPE_BORDER:
394 			pPropHdl = new XMLBorderHdl;
395 			break;
396 		case XML_TYPE_TEXT_TABSTOP:
397 			pPropHdl = new XMLTabStopPropHdl;
398 			break;
399 		case XML_TYPE_ATTRIBUTE_CONTAINER:
400 			pPropHdl = new XMLAttributeContainerHandler;
401 			break;
402 		case XML_TYPE_COLOR_MODE:
403 			pPropHdl = new XMLEnumPropertyHdl( aXML_ColorMode_EnumMap,
404 							::getCppuType((const drawing::ColorMode*)0) );
405 			break;
406 		case XML_TYPE_DURATION16_MS:
407 			pPropHdl = new XMLDurationMS16PropHdl_Impl;
408 			break;
409 		case XML_TYPE_TEXT_HORIZONTAL_ADJUST:
410 			pPropHdl = new XMLEnumPropertyHdl(
411 				aXML_HorizontalAdjust_Enum,
412 				::getCppuType((const text::HorizontalAdjust*)0) );
413 			break;
414 		case XML_TYPE_TEXT_DRAW_ASPECT:
415 			pPropHdl = new DrawAspectHdl;
416 			break;
417         case XML_TYPE_TEXT_WRITING_MODE:
418             pPropHdl = new XMLConstantsPropertyHandler(
419                 &(aXML_WritingDirection_Enum[1]),
420                 XML_LR_TB);
421             break;
422         case XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT:
423             pPropHdl = new XMLConstantsPropertyHandler(
424                 aXML_WritingDirection_Enum,
425                 XML_PAGE);
426             break;
427         case XML_TYPE_TEXT_HIDDEN_AS_DISPLAY:
428             pPropHdl = new XMLNamedBoolPropertyHdl(
429                 GetXMLToken(XML_NONE),
430                 GetXMLToken(XML_TRUE) );
431 			break;
432 		case XML_TYPE_STYLENAME :
433 			pPropHdl = new XMLStyleNamePropHdl;
434 			break;
435         case XML_TYPE_NUMBER_NO_ZERO:
436             pPropHdl = new XMLNumberWithoutZeroPropHdl( 4 );
437             break;
438         case XML_TYPE_NUMBER8_NO_ZERO:
439             pPropHdl = new XMLNumberWithoutZeroPropHdl( 1 );
440             break;
441 		case XML_TYPE_NUMBER16_NO_ZERO:
442             pPropHdl = new XMLNumberWithoutZeroPropHdl( 2 );
443             break;
444 		case XML_TYPE_NUMBER16_AUTO:
445             pPropHdl = new XMLNumberWithAutoInsteadZeroPropHdl();
446             break;
447 	}
448 
449     return pPropHdl;
450 }
451