tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / forms / formattributes.hxx
blobae36fd65dcd612e623e119bf209b829dbe90b595
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 #pragma once
22 #include <sal/config.h>
24 #include <map>
26 #include <com/sun/star/uno/Type.hxx>
27 #include <rtl/ustring.hxx>
28 #include <sal/types.h>
29 #include <xmloff/xmlnamespace.hxx>
30 #include <xmloff/xmltoken.hxx>
31 #include <o3tl/typed_flags_set.hxx>
33 template<typename EnumT>
34 struct SvXMLEnumMapEntry;
36 // flags for common control attributes
37 enum class CCAFlags {
38 NONE = 0x00000000,
39 Name = 0x00000001,
40 ServiceName = 0x00000002,
41 ButtonType = 0x00000004,
42 ControlId = 0x00000008,
43 CurrentSelected = 0x00000010,
44 CurrentValue = 0x00000020,
45 Disabled = 0x00000040,
46 Dropdown = 0x00000080,
47 For = 0x00000100,
48 ImageData = 0x00000200,
49 Label = 0x00000400,
50 MaxLength = 0x00000800,
51 Printable = 0x00001000,
52 ReadOnly = 0x00002000,
53 Selected = 0x00004000,
54 Size = 0x00008000,
55 TabIndex = 0x00010000,
56 TargetFrame = 0x00020000,
57 TargetLocation = 0x00040000,
58 TabStop = 0x00080000,
59 Title = 0x00100000,
60 Value = 0x00200000,
61 Orientation = 0x00400000,
62 VisualEffect = 0x00800000,
63 EnableVisible = 0x01000000,
65 namespace o3tl {
66 template<> struct typed_flags<CCAFlags> : is_typed_flags<CCAFlags, 0x01ffffff> {};
69 // flags for database control attributes
70 enum class DAFlags {
71 NONE = 0x0000,
72 BoundColumn = 0x0001,
73 ConvertEmpty = 0x0002,
74 DataField = 0x0004,
75 ListSource = 0x0008,
76 ListSource_TYPE = 0x0010,
77 InputRequired = 0x0020,
79 namespace o3tl {
80 template<> struct typed_flags<DAFlags> : is_typed_flags<DAFlags, 0x003f> {};
83 // flags for binding related control attributes
84 enum class BAFlags {
85 NONE = 0x0000,
86 LinkedCell = 0x0001,
87 ListLinkingType = 0x0002,
88 ListCellRange = 0x0004,
89 XFormsBind = 0x0008,
90 XFormsListBind = 0x0010,
91 XFormsSubmission = 0x0020
93 namespace o3tl {
94 template<> struct typed_flags<BAFlags> : is_typed_flags<BAFlags, 0x003f> {};
97 // flags for event attributes
98 enum class EAFlags {
99 NONE = 0x0000,
100 ControlEvents = 0x0001,
101 OnChange = 0x0002,
102 OnClick = 0x0004,
103 OnDoubleClick = 0x0008,
104 OnSelect = 0x0010
106 namespace o3tl {
107 template<> struct typed_flags<EAFlags> : is_typed_flags<EAFlags, 0x001f> {};
110 // any other attributes, which are special to some control types
111 enum class SCAFlags {
112 NONE = 0x000000,
113 EchoChar = 0x000001,
114 MaxValue = 0x000002,
115 MinValue = 0x000004,
116 Validation = 0x000008,
117 GroupName = 0x000010,
118 MultiLine = 0x000020,
119 AutoCompletion = 0x000080,
120 Multiple = 0x000100,
121 DefaultButton = 0x000200,
122 CurrentState = 0x000400,
123 IsTristate = 0x000800,
124 State = 0x001000,
125 ColumnStyleName = 0x002000,
126 StepSize = 0x004000,
127 PageStepSize = 0x008000,
128 RepeatDelay = 0x010000,
129 Toggle = 0x020000,
130 FocusOnClick = 0x040000,
131 ImagePosition = 0x080000
133 namespace o3tl {
134 template<> struct typed_flags<SCAFlags> : is_typed_flags<SCAFlags, 0x0fffbf> {};
138 namespace xmloff
141 /// attributes in the xml tag representing a form
142 enum FormAttributes
144 faName,
145 faAction,
146 faEnctype,
147 faMethod,
148 faAllowDeletes,
149 faAllowInserts,
150 faAllowUpdates,
151 faApplyFilter,
152 faCommand,
153 faCommandType,
154 faEscapeProcessing,
155 faDatasource,
156 faDetailFields,
157 faFilter,
158 faIgnoreResult,
159 faMasterFields,
160 faNavigationMode,
161 faOrder,
162 faTabbingCycle
165 // attributes of the office:forms element
166 enum OfficeFormsAttributes
168 ofaAutomaticFocus,
169 ofaApplyDesignMode
172 //= OAttributeMetaData
173 /** allows the translation of attribute ids into strings.
175 <p>This class does not allow to connect xml attributes to property names or
176 something like that, it only deals with the xml side</p>
178 class OAttributeMetaData
180 public:
181 /** calculates the xml attribute representation of a common control attribute.
182 @param _nId
183 the id of the attribute. Has to be one of the CCA_* constants.
185 static OUString getCommonControlAttributeName(CCAFlags _nId);
187 /** calculates the xml attribute representation of a common control attribute.
188 @param _nId
189 the id of the attribute. Has to be one of the CCA_* constants.
191 static sal_Int32 getCommonControlAttributeToken(CCAFlags _nId);
193 /** calculates the xml namespace key to use for a common control attribute
194 @param _nId
195 the id of the attribute. Has to be one of the CCA_* constants.
197 static sal_uInt16 getCommonControlAttributeNamespace(CCAFlags _nId);
199 /** retrieves the name of an attribute of a form xml representation
200 @param _eAttrib
201 enum value specifying the attribute
203 static OUString getFormAttributeName(FormAttributes _eAttrib);
205 /** retrieves the name of an attribute of a form xml representation
206 @param _eAttrib
207 enum value specifying the attribute
209 static sal_Int32 getFormAttributeToken(FormAttributes _eAttrib);
211 /** calculates the xml namespace key to use for an attribute of a form xml representation
212 @param _eAttrib
213 enum value specifying the attribute
215 static sal_uInt16 getFormAttributeNamespace(FormAttributes _eAttrib);
217 /** calculates the xml attribute representation of a database attribute.
218 @param _nId
219 the id of the attribute. Has to be one of the DA_* constants.
221 static OUString getDatabaseAttributeName(DAFlags _nId);
223 /** calculates the xml attribute representation of a database attribute.
224 @param _nId
225 the id of the attribute. Has to be one of the DA_* constants.
227 static sal_Int32 getDatabaseAttributeToken(DAFlags _nId);
229 /** calculates the xml namespace key to use for a database attribute.
230 @param _nId
231 the id of the attribute. Has to be one of the DA_* constants.
233 static sal_uInt16 getDatabaseAttributeNamespace()
235 // nothing special here
236 return XML_NAMESPACE_FORM;
239 /** calculates the xml attribute representation of a special attribute.
240 @param _nId
241 the id of the attribute. Has to be one of the SCA_* constants.
243 static OUString getSpecialAttributeName(SCAFlags _nId);
245 /** calculates the xml attribute representation of a special attribute.
246 @param _nId
247 the id of the attribute. Has to be one of the SCA_* constants.
249 static sal_Int32 getSpecialAttributeToken(SCAFlags _nId);
251 /** calculates the xml attribute representation of a binding attribute.
252 @param _nId
253 the id of the attribute. Has to be one of the BA_* constants.
255 static OUString getBindingAttributeName(BAFlags _nId);
257 /** calculates the xml attribute representation of a binding attribute.
258 @param _nId
259 the id of the attribute. Has to be one of the BA_* constants.
261 static sal_Int32 getBindingAttributeToken(BAFlags _nId);
263 /** calculates the xml namespace key to use for a binding attribute.
264 @param _nId
265 the id of the attribute. Has to be one of the BA_* constants.
267 static sal_uInt16 getBindingAttributeNamespace()
269 // nothing special here
270 return XML_NAMESPACE_FORM;
273 /** calculates the xml namespace key to use for a special attribute.
274 @param _nId
275 the id of the attribute. Has to be one of the SCA_* constants.
277 static sal_uInt16 getSpecialAttributeNamespace(SCAFlags _nId);
279 /** calculates the xml attribute representation of an attribute of the office:forms element
280 @param _nId
281 the id of the attribute
283 static OUString getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib);
284 static xmloff::token::XMLTokenEnum getOfficeFormsAttributeToken(OfficeFormsAttributes _eAttrib);
286 /** calculates the xml namedspace key of an attribute of the office:forms element
287 @param _nId
288 the id of the attribute
290 static sal_uInt16 getOfficeFormsAttributeNamespace()
291 { // nothing special here
292 return XML_NAMESPACE_FORM;
296 //= OAttribute2Property
297 /** some kind of opposite to the OAttributeMetaData class. Able to translate
298 attributes into property names/types
300 <p>The construction of this class is rather expensive (or at least it's initialization from outside),
301 so it should be shared</p>
303 class OAttribute2Property final
305 public:
306 // TODO: maybe the following struct should be used for exports, too. In this case we would not need to
307 // store it's instances in a map, but in a vector for faster access.
308 struct AttributeAssignment
310 OUString sPropertyName; // the property name
311 css::uno::Type aPropertyType; // the property type
313 // entries which are special to some value types
314 const SvXMLEnumMapEntry<sal_uInt16>*
315 pEnumMap; // the enum map, if applicable
316 bool bInverseSemantics; // for booleans: attribute and property value have the same or an inverse semantics?
318 AttributeAssignment() : pEnumMap(nullptr), bInverseSemantics(false) { }
321 private:
322 std::map<sal_Int32, AttributeAssignment> m_aKnownProperties;
324 public:
325 OAttribute2Property();
326 ~OAttribute2Property();
328 /** return the AttributeAssignment which corresponds to the given attribute
330 @return
331 a pointer to the <type>AttributeAssignment</type> structure as requested, NULL if the attribute
332 does not represent a property.
334 const AttributeAssignment* getAttributeTranslation(sal_Int32 nAttributeToken);
336 /** add an attribute assignment referring to a string property to the map
337 @param _pAttributeName
338 the name of the attribute
339 @param _rPropertyName
340 the name of the property assigned to the attribute
342 void addStringProperty(
343 sal_Int32 nAttributeToken, const OUString& _rPropertyName);
345 /** add an attribute assignment referring to a boolean property to the map
347 @param _pAttributeName
348 the name of the attribute
349 @param _rPropertyName
350 the name of the property assigned to the attribute
351 @param _bAttributeDefault
352 the default value for the attribute.
353 @param _bInverseSemantics
354 if <TRUE/>, an attribute value of <TRUE/> means a property value of <FALSE/> and vice verse.<br/>
355 if <FALSE/>, the attribute value is used as property value directly
357 void addBooleanProperty(
358 sal_Int32 nAttributeToken, const OUString& _rPropertyName,
359 const bool _bAttributeDefault, const bool _bInverseSemantics = false);
361 /** add an attribute assignment referring to an int16 property to the map
363 @param _pAttributeName
364 the name of the attribute
365 @param _rPropertyName
366 the name of the property assigned to the attribute
368 void addInt16Property(
369 sal_Int32 nAttributeToken, const OUString& _rPropertyName);
371 /** add an attribute assignment referring to an int32 property to the map
373 @param _pAttributeName
374 the name of the attribute
375 @param _rPropertyName
376 the name of the property assigned to the attribute
378 void addInt32Property(
379 sal_Int32 nAttributeToken, const OUString& _rPropertyName );
381 /** add an attribute assignment referring to an enum property to the map
383 @param _pAttributeName
384 the name of the attribute
385 @param _rPropertyName
386 the name of the property assigned to the attribute
387 @param _pValueMap
388 the map to translate strings into enum values
389 @param _pType
390 the type of the property. May be NULL, in this case 32bit integer is assumed.
392 template<typename EnumT>
393 void addEnumProperty(
394 sal_Int32 nAttributeToken, const OUString& _rPropertyName,
395 const SvXMLEnumMapEntry<EnumT>* _pValueMap,
396 const css::uno::Type* _pType = nullptr)
398 addEnumPropertyImpl(nAttributeToken, _rPropertyName,
399 reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(_pValueMap), _pType);
402 private:
403 void addEnumPropertyImpl(
404 sal_Int32 nAttributeToken, const OUString& _rPropertyName,
405 const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
406 const css::uno::Type* _pType);
407 /// some common code for the various add*Property methods
408 AttributeAssignment& implAdd(
409 sal_Int32 nAttributeToken, const OUString& _rPropertyName,
410 const css::uno::Type& _rType);
412 } // namespace xmloff
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */