tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / style / prhdlfac.cxx
blobfd6dae604bf8b79675a4659fecc2a409b317b3fe
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>
25 #include <com/sun/star/text/VertOrientation.hpp>
28 #include <sal/log.hxx>
29 #include <xmloff/xmlement.hxx>
30 #include <xmloff/xmltypes.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/xmlprhdl.hxx>
33 #include <xmlbahdl.hxx>
34 #include <xmloff/NamedBoolPropertyHdl.hxx>
35 #include <xmloff/XMLConstantsPropertyHandler.hxx>
36 #include "cdouthdl.hxx"
37 #include "csmaphdl.hxx"
38 #include "fonthdl.hxx"
39 #include "kernihdl.hxx"
40 #include "postuhdl.hxx"
41 #include "shadwhdl.hxx"
42 #include "shdwdhdl.hxx"
43 #include "undlihdl.hxx"
44 #include "weighhdl.hxx"
45 #include "breakhdl.hxx"
46 #include "adjushdl.hxx"
47 #include "escphdl.hxx"
48 #include "chrhghdl.hxx"
49 #include "chrlohdl.hxx"
50 #include "lspachdl.hxx"
51 #include "bordrhdl.hxx"
52 #include "tabsthdl.hxx"
53 #include <xmloff/EnumPropertyHdl.hxx>
54 #include <AttributeContainerHandler.hxx>
55 #include "durationhdl.hxx"
56 #include <XMLRectangleMembersHandler.hxx>
57 #include <XMLNumberWithAutoForVoidPropHdl.hxx>
58 #include "DrawAspectHdl.hxx"
59 #include <xmloff/XMLComplexColorHandler.hxx>
61 #include <map>
63 using namespace ::com::sun::star;
64 using namespace ::xmloff::token;
66 SvXMLEnumMapEntry<drawing::ColorMode> const aXML_ColorMode_EnumMap[] =
68 { XML_GREYSCALE, drawing::ColorMode_GREYS },
69 { XML_MONO, drawing::ColorMode_MONO },
70 { XML_WATERMARK, drawing::ColorMode_WATERMARK },
71 { XML_STANDARD, drawing::ColorMode_STANDARD },
72 { XML_TOKEN_INVALID, drawing::ColorMode(0) }
75 SvXMLEnumMapEntry<text::HorizontalAdjust> const aXML_HorizontalAdjust_Enum[] =
77 { XML_LEFT, text::HorizontalAdjust_LEFT },
78 { XML_CENTER, text::HorizontalAdjust_CENTER },
79 { XML_RIGHT, text::HorizontalAdjust_RIGHT },
80 { XML_TOKEN_INVALID, text::HorizontalAdjust(0) }
83 // aXML_WritingDirection_Enum is used with and without 'page'
84 // attribute, so you'll find uses of aXML_WritingDirection_Enum
85 // directly, as well as &(aXML_WritingDirection_Enum[1])
86 SvXMLEnumMapEntry<sal_uInt16> const aXML_WritingDirection_Enum[] =
88 // aXML_WritingDirection_Enum
89 { XML_PAGE, text::WritingMode2::PAGE },
91 // &(aXML_WritingDirection_Enum[1])
92 { XML_LR_TB, text::WritingMode2::LR_TB },
93 { XML_RL_TB, text::WritingMode2::RL_TB },
94 { XML_TB_RL, text::WritingMode2::TB_RL },
95 { XML_TB_LR, text::WritingMode2::TB_LR },
96 { XML_BT_LR, text::WritingMode2::BT_LR },
98 // alternative names of the above, as accepted by XSL
99 { XML_LR, text::WritingMode2::LR_TB },
100 { XML_RL, text::WritingMode2::RL_TB },
101 { XML_TB, text::WritingMode2::TB_RL },
103 // vertical as clockwise 90deg rotation, for OOXML vert="vert"
104 { XML_TB_RL90, text::WritingMode2::TB_RL90 },
106 { XML_TOKEN_INVALID, 0 }
109 SvXMLEnumMapEntry<sal_uInt16> const pXML_VertPos_Enum[] =
111 { XML_FROM_TOP, text::VertOrientation::NONE },
112 { XML_TOP, text::VertOrientation::TOP },
113 { XML_TOP, text::VertOrientation::CHAR_TOP }, // export only
114 { XML_TOP, text::VertOrientation::LINE_TOP }, // export only
115 { XML_MIDDLE, text::VertOrientation::CENTER },
116 { XML_MIDDLE, text::VertOrientation::CHAR_CENTER }, // export only
117 { XML_MIDDLE, text::VertOrientation::LINE_CENTER }, // export only
118 { XML_BOTTOM, text::VertOrientation::BOTTOM },
119 { XML_BOTTOM, text::VertOrientation::CHAR_BOTTOM }, // export only
120 { XML_BOTTOM, text::VertOrientation::LINE_BOTTOM }, // export only
121 { XML_BELOW, text::VertOrientation::CHAR_BOTTOM }, // import only
122 { XML_TOKEN_INVALID, 0 }
125 typedef std::map<sal_Int32, const XMLPropertyHandler*> CacheMap;
127 struct XMLPropertyHandlerFactory::Impl
129 mutable CacheMap maHandlerCache;
132 XMLPropertyHandlerFactory::XMLPropertyHandlerFactory() :
133 mpImpl(new Impl) {}
135 XMLPropertyHandlerFactory::~XMLPropertyHandlerFactory()
137 for( const auto& rCacheEntry : mpImpl->maHandlerCache )
138 delete rCacheEntry.second;
141 // Interface
142 const XMLPropertyHandler* XMLPropertyHandlerFactory::GetPropertyHandler( sal_Int32 nType ) const
144 SAL_WARN_IF( (nType & ~(sal_uInt32(MID_FLAG_MASK))) != 0, "xmloff",
145 "GetPropertyHandler called with flags in type" );
146 return GetBasicHandler( nType );
149 // Helper-methods to create and cache PropertyHandler
150 const XMLPropertyHandler* XMLPropertyHandlerFactory::GetHdlCache( sal_Int32 nType ) const
152 const XMLPropertyHandler* pRet = nullptr;
154 if( mpImpl->maHandlerCache.find( nType ) != mpImpl->maHandlerCache.end() )
155 pRet = mpImpl->maHandlerCache.find( nType )->second;
157 return pRet;
160 void XMLPropertyHandlerFactory::PutHdlCache( sal_Int32 nType, const XMLPropertyHandler* pHdl ) const
162 mpImpl->maHandlerCache[nType] = pHdl;
165 const XMLPropertyHandler* XMLPropertyHandlerFactory::GetBasicHandler( sal_Int32 nType ) const
167 const XMLPropertyHandler* pPropHdl = GetHdlCache( nType );
168 if( pPropHdl )
169 return pPropHdl;
171 std::unique_ptr<XMLPropertyHandler> pNewPropHdl = CreatePropertyHandler( nType );
172 if( pNewPropHdl )
173 PutHdlCache( nType, pNewPropHdl.get() );
174 return pNewPropHdl.release();
177 std::unique_ptr<XMLPropertyHandler> XMLPropertyHandlerFactory::CreatePropertyHandler( sal_Int32 nType )
179 std::unique_ptr<XMLPropertyHandler> pPropHdl;
181 switch( nType )
183 case XML_TYPE_BOOL :
184 pPropHdl.reset(new XMLBoolPropHdl);
185 break;
186 case XML_TYPE_BOOL_FALSE :
187 pPropHdl.reset(new XMLBoolFalsePropHdl);
188 break;
189 case XML_TYPE_MEASURE :
190 pPropHdl.reset(new XMLMeasurePropHdl( 4 ));
191 break;
192 case XML_TYPE_MEASURE8 :
193 pPropHdl.reset(new XMLMeasurePropHdl( 1 ));
194 break;
195 case XML_TYPE_MEASURE16:
196 pPropHdl.reset(new XMLMeasurePropHdl( 2 ));
197 break;
198 case XML_TYPE_UNIT_MEASURE:
199 pPropHdl = std::make_unique<XMLUnitMeasurePropHdl>();
200 break;
201 case XML_TYPE_PERCENT :
202 pPropHdl.reset(new XMLPercentPropHdl( 4 ));
203 break;
204 case XML_TYPE_PERCENT8 :
205 pPropHdl.reset(new XMLPercentPropHdl( 1 ));
206 break;
207 case XML_TYPE_PERCENT16 :
208 pPropHdl.reset(new XMLPercentPropHdl( 2 ));
209 break;
210 case XML_TYPE_PERCENT100:
211 pPropHdl.reset(new XML100thPercentPropHdl);
212 break;
213 case XML_TYPE_DOUBLE_PERCENT :
214 pPropHdl.reset(new XMLDoublePercentPropHdl);
215 break;
216 case XML_TYPE_NEG_PERCENT :
217 pPropHdl.reset(new XMLNegPercentPropHdl( 4 ));
218 break;
219 case XML_TYPE_NEG_PERCENT8 :
220 pPropHdl.reset(new XMLNegPercentPropHdl( 1 ));
221 break;
222 case XML_TYPE_NEG_PERCENT16 :
223 pPropHdl.reset(new XMLNegPercentPropHdl( 2 ));
224 break;
225 case XML_TYPE_MEASURE_PX :
226 pPropHdl.reset(new XMLMeasurePxPropHdl( 4 ));
227 break;
228 case XML_TYPE_STRING :
229 pPropHdl.reset(new XMLStringPropHdl);
230 break;
231 case XML_TYPE_COLOR :
232 pPropHdl.reset(new XMLColorPropHdl);
233 break;
234 case XML_TYPE_HEX :
235 pPropHdl.reset(new XMLHexPropHdl);
236 break;
237 case XML_TYPE_NUMBER :
238 pPropHdl.reset(new XMLNumberPropHdl( 4 ));
239 break;
240 case XML_TYPE_NUMBER8 :
241 pPropHdl.reset(new XMLNumberPropHdl( 1 ));
242 break;
243 case XML_TYPE_NUMBER16:
244 pPropHdl.reset(new XMLNumberPropHdl( 2 ));
245 break;
246 case XML_TYPE_NUMBER_NONE :
247 pPropHdl.reset(new XMLNumberNonePropHdl);
248 break;
249 case XML_TYPE_NUMBER8_NONE :
250 pPropHdl.reset(new XMLNumberNonePropHdl( 1 ));
251 break;
252 case XML_TYPE_NUMBER16_NONE :
253 pPropHdl.reset(new XMLNumberNonePropHdl( 2 ));
254 break;
255 case XML_TYPE_DOUBLE :
256 pPropHdl.reset(new XMLDoublePropHdl);
257 break;
258 case XML_TYPE_NBOOL :
259 pPropHdl.reset(new XMLNBoolPropHdl);
260 break;
261 case XML_TYPE_COLORTRANSPARENT :
262 pPropHdl.reset(new XMLColorTransparentPropHdl);
263 break;
264 case XML_TYPE_ISTRANSPARENT :
265 pPropHdl.reset(new XMLIsTransparentPropHdl);
266 break;
267 case XML_TYPE_COLORAUTO :
268 pPropHdl.reset(new XMLColorAutoPropHdl);
269 break;
270 case XML_TYPE_ISAUTOCOLOR :
271 pPropHdl.reset(new XMLIsAutoColorPropHdl);
272 break;
273 case XML_TYPE_BUILDIN_CMP_ONLY :
274 pPropHdl.reset(new XMLCompareOnlyPropHdl);
275 break;
277 case XML_TYPE_RECTANGLE_LEFT :
278 case XML_TYPE_RECTANGLE_TOP :
279 case XML_TYPE_RECTANGLE_WIDTH :
280 case XML_TYPE_RECTANGLE_HEIGHT :
281 pPropHdl.reset(new XMLRectangleMembersHdl( nType ));
282 break;
284 case XML_TYPE_TEXT_CROSSEDOUT_TYPE:
285 pPropHdl.reset(new XMLCrossedOutTypePropHdl) ;
286 break;
287 case XML_TYPE_TEXT_CROSSEDOUT_STYLE:
288 pPropHdl.reset(new XMLCrossedOutStylePropHdl) ;
289 break;
290 case XML_TYPE_TEXT_CROSSEDOUT_WIDTH:
291 pPropHdl.reset(new XMLCrossedOutWidthPropHdl) ;
292 break;
293 case XML_TYPE_TEXT_CROSSEDOUT_TEXT:
294 pPropHdl.reset(new XMLCrossedOutTextPropHdl) ;
295 break;
296 case XML_TYPE_TEXT_BOOLCROSSEDOUT:
297 pPropHdl.reset(new XMLNamedBoolPropertyHdl(
298 GetXMLToken(XML_SOLID),
299 GetXMLToken(XML_NONE) ));
300 break;
301 case XML_TYPE_TEXT_ESCAPEMENT:
302 pPropHdl.reset(new XMLEscapementPropHdl);
303 break;
304 case XML_TYPE_TEXT_ESCAPEMENT_HEIGHT:
305 pPropHdl.reset(new XMLEscapementHeightPropHdl);
306 break;
307 case XML_TYPE_TEXT_CASEMAP:
308 pPropHdl.reset(new XMLCaseMapPropHdl);
309 break;
310 case XML_TYPE_TEXT_CASEMAP_VAR:
311 pPropHdl.reset(new XMLCaseMapVariantHdl);
312 break;
313 case XML_TYPE_TEXT_FONTFAMILYNAME:
314 pPropHdl.reset(new XMLFontFamilyNamePropHdl);
315 break;
316 case XML_TYPE_TEXT_FONTFAMILY:
317 pPropHdl.reset(new XMLFontFamilyPropHdl);
318 break;
319 case XML_TYPE_TEXT_FONTENCODING:
320 pPropHdl.reset(new XMLFontEncodingPropHdl);
321 break;
322 case XML_TYPE_TEXT_FONTPITCH:
323 pPropHdl.reset(new XMLFontPitchPropHdl);
324 break;
325 case XML_TYPE_TEXT_KERNING:
326 pPropHdl.reset(new XMLKerningPropHdl);
327 break;
328 case XML_TYPE_TEXT_POSTURE:
329 pPropHdl.reset(new XMLPosturePropHdl);
330 break;
331 case XML_TYPE_TEXT_SHADOWED:
332 pPropHdl.reset(new XMLShadowedPropHdl);
333 break;
334 case XML_TYPE_TEXT_UNDERLINE_TYPE:
335 pPropHdl.reset(new XMLUnderlineTypePropHdl);
336 break;
337 case XML_TYPE_TEXT_UNDERLINE_STYLE:
338 pPropHdl.reset(new XMLUnderlineStylePropHdl);
339 break;
340 case XML_TYPE_TEXT_UNDERLINE_WIDTH:
341 pPropHdl.reset(new XMLUnderlineWidthPropHdl);
342 break;
343 case XML_TYPE_TEXT_UNDERLINE_COLOR:
344 pPropHdl.reset(new XMLColorTransparentPropHdl( XML_FONT_COLOR ));
345 break;
346 case XML_TYPE_TEXT_UNDERLINE_HASCOLOR:
347 pPropHdl.reset(new XMLIsTransparentPropHdl( XML_FONT_COLOR,
348 false ));
349 break;
350 case XML_TYPE_TEXT_OVERLINE_TYPE:
351 pPropHdl.reset(new XMLUnderlineTypePropHdl);
352 break;
353 case XML_TYPE_TEXT_OVERLINE_STYLE:
354 pPropHdl.reset(new XMLUnderlineStylePropHdl);
355 break;
356 case XML_TYPE_TEXT_OVERLINE_WIDTH:
357 pPropHdl.reset(new XMLUnderlineWidthPropHdl);
358 break;
359 case XML_TYPE_TEXT_OVERLINE_COLOR:
360 pPropHdl.reset(new XMLColorTransparentPropHdl( XML_FONT_COLOR ));
361 break;
362 case XML_TYPE_TEXT_OVERLINE_HASCOLOR:
363 pPropHdl.reset(new XMLIsTransparentPropHdl( XML_FONT_COLOR,
364 false ));
365 break;
366 case XML_TYPE_TEXT_WEIGHT:
367 pPropHdl.reset(new XMLFontWeightPropHdl);
368 break;
369 case XML_TYPE_TEXT_SPLIT:
370 pPropHdl.reset(new XMLNamedBoolPropertyHdl(
371 GetXMLToken(XML_AUTO),
372 GetXMLToken(XML_ALWAYS) ));
373 break;
374 case XML_TYPE_TEXT_BREAKBEFORE:
375 pPropHdl.reset(new XMLFmtBreakBeforePropHdl);
376 break;
377 case XML_TYPE_TEXT_BREAKAFTER:
378 pPropHdl.reset(new XMLFmtBreakAfterPropHdl);
379 break;
380 case XML_TYPE_TEXT_SHADOW:
381 pPropHdl.reset(new XMLShadowPropHdl);
382 break;
383 case XML_TYPE_TEXT_ADJUST:
384 pPropHdl.reset(new XMLParaAdjustPropHdl);
385 break;
386 case XML_TYPE_TEXT_ADJUSTLAST:
387 pPropHdl.reset(new XMLLastLineAdjustPropHdl);
388 break;
389 case XML_TYPE_CHAR_HEIGHT:
390 pPropHdl.reset(new XMLCharHeightHdl);
391 break;
392 case XML_TYPE_CHAR_HEIGHT_PROP:
393 pPropHdl.reset(new XMLCharHeightPropHdl);
394 break;
395 case XML_TYPE_CHAR_HEIGHT_DIFF:
396 pPropHdl.reset(new XMLCharHeightDiffHdl);
397 break;
398 case XML_TYPE_CHAR_RFC_LANGUAGE_TAG:
399 pPropHdl.reset(new XMLCharRfcLanguageTagHdl);
400 break;
401 case XML_TYPE_CHAR_LANGUAGE:
402 pPropHdl.reset(new XMLCharLanguageHdl);
403 break;
404 case XML_TYPE_CHAR_SCRIPT:
405 pPropHdl.reset(new XMLCharScriptHdl);
406 break;
407 case XML_TYPE_CHAR_COUNTRY:
408 pPropHdl.reset(new XMLCharCountryHdl);
409 break;
410 case XML_TYPE_LINE_SPACE_FIXED:
411 pPropHdl.reset(new XMLLineHeightHdl);
412 break;
413 case XML_TYPE_LINE_SPACE_MINIMUM:
414 pPropHdl.reset(new XMLLineHeightAtLeastHdl);
415 break;
416 case XML_TYPE_LINE_SPACE_DISTANCE:
417 pPropHdl.reset(new XMLLineSpacingHdl);
418 break;
419 case XML_TYPE_BORDER_WIDTH:
420 pPropHdl.reset(new XMLBorderWidthHdl);
421 break;
422 case XML_TYPE_BORDER:
423 pPropHdl.reset(new XMLBorderHdl);
424 break;
425 case XML_TYPE_TEXT_TABSTOP:
426 pPropHdl.reset(new XMLTabStopPropHdl);
427 break;
428 case XML_TYPE_ATTRIBUTE_CONTAINER:
429 pPropHdl.reset(new XMLAttributeContainerHandler);
430 break;
431 case XML_TYPE_COLOR_MODE:
432 pPropHdl.reset(new XMLEnumPropertyHdl(aXML_ColorMode_EnumMap));
433 break;
434 case XML_TYPE_DURATION16_MS:
435 pPropHdl.reset(new XMLDurationMS16PropHdl_Impl);
436 break;
437 case XML_TYPE_TEXT_HORIZONTAL_ADJUST:
438 pPropHdl.reset(new XMLEnumPropertyHdl(aXML_HorizontalAdjust_Enum));
439 break;
440 case XML_TYPE_TEXT_DRAW_ASPECT:
441 pPropHdl.reset(new DrawAspectHdl);
442 break;
443 case XML_TYPE_TEXT_WRITING_MODE:
444 pPropHdl.reset(new XMLConstantsPropertyHandler(
445 &(aXML_WritingDirection_Enum[1]),
446 XML_LR_TB));
447 break;
448 case XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT:
449 pPropHdl.reset(new XMLConstantsPropertyHandler(
450 aXML_WritingDirection_Enum,
451 XML_PAGE));
452 break;
453 case XML_TYPE_TEXT_HIDDEN_AS_DISPLAY:
454 pPropHdl.reset(new XMLNamedBoolPropertyHdl(
455 GetXMLToken(XML_NONE),
456 GetXMLToken(XML_TRUE) ));
457 break;
458 case XML_TYPE_STYLENAME :
459 pPropHdl.reset(new XMLStyleNamePropHdl);
460 break;
461 case XML_TYPE_NUMBER_NO_ZERO:
462 pPropHdl.reset(new XMLNumberWithoutZeroPropHdl( 4 ));
463 break;
464 case XML_TYPE_NUMBER8_NO_ZERO:
465 pPropHdl.reset(new XMLNumberWithoutZeroPropHdl( 1 ));
466 break;
467 case XML_TYPE_NUMBER16_NO_ZERO:
468 pPropHdl.reset(new XMLNumberWithoutZeroPropHdl( 2 ));
469 break;
470 case XML_TYPE_NUMBER16_AUTO:
471 pPropHdl.reset(new XMLNumberWithAutoForVoidPropHdl);
472 break;
473 case XML_TYPE_TEXT_VERTICAL_POS:
474 pPropHdl.reset(new XMLConstantsPropertyHandler( pXML_VertPos_Enum, XML_TOKEN_INVALID ));
475 break;
476 case XML_TYPE_TEXT_OVERFLOW_BEHAVIOR:
477 // auto-create-new-frame isn't properly implemented yet. It just means don't clip.
478 pPropHdl.reset(new XMLNamedBoolPropertyHdl(GetXMLToken(XML_CLIP),
479 GetXMLToken(XML_AUTO_CREATE_NEW_FRAME)));
480 break;
481 case XML_TYPE_COMPLEX_COLOR:
482 pPropHdl.reset(new XMLComplexColorHandler);
483 break;
486 return pPropHdl;
489 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */