Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / forms / formattributes.hxx
blobd0a2405ce605216488080b5d28e1efc0345a91f4
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 #ifndef INCLUDED_XMLOFF_SOURCE_FORMS_FORMATTRIBUTES_HXX
21 #define INCLUDED_XMLOFF_SOURCE_FORMS_FORMATTRIBUTES_HXX
23 #include <sal/config.h>
25 #include <map>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <sal/types.h>
29 #include <salhelper/simplereferenceobject.hxx>
30 #include <xmloff/xmlnmspe.hxx>
31 #include <o3tl/typed_flags_set.hxx>
33 struct SvXMLEnumMapEntry;
35 // flags for common control attributes
36 enum class CCAFlags {
37 NONE = 0x00000000,
38 Name = 0x00000001,
39 ServiceName = 0x00000002,
40 ButtonType = 0x00000004,
41 ControlId = 0x00000008,
42 CurrentSelected = 0x00000010,
43 CurrentValue = 0x00000020,
44 Disabled = 0x00000040,
45 Dropdown = 0x00000080,
46 For = 0x00000100,
47 ImageData = 0x00000200,
48 Label = 0x00000400,
49 MaxLength = 0x00000800,
50 Printable = 0x00001000,
51 ReadOnly = 0x00002000,
52 Selected = 0x00004000,
53 Size = 0x00008000,
54 TabIndex = 0x00010000,
55 TargetFrame = 0x00020000,
56 TargetLocation = 0x00040000,
57 TabStop = 0x00080000,
58 Title = 0x00100000,
59 Value = 0x00200000,
60 Orientation = 0x00400000,
61 VisualEffect = 0x00800000,
62 EnableVisible = 0x01000000,
64 namespace o3tl {
65 template<> struct typed_flags<CCAFlags> : is_typed_flags<CCAFlags, 0x01ffffff> {};
68 // flags for database control attributes
69 enum class DAFlags {
70 NONE = 0x0000,
71 BoundColumn = 0x0001,
72 ConvertEmpty = 0x0002,
73 DataField = 0x0004,
74 ListSource = 0x0008,
75 ListSource_TYPE = 0x0010,
76 InputRequired = 0x0020,
78 namespace o3tl {
79 template<> struct typed_flags<DAFlags> : is_typed_flags<DAFlags, 0x003f> {};
82 // flags for binding related control attributes
83 enum class BAFlags {
84 NONE = 0x0000,
85 LinkedCell = 0x0001,
86 ListLinkingType = 0x0002,
87 ListCellRange = 0x0004,
88 XFormsBind = 0x0008,
89 XFormsListBind = 0x0010,
90 XFormsSubmission = 0x0020
92 namespace o3tl {
93 template<> struct typed_flags<BAFlags> : is_typed_flags<BAFlags, 0x003f> {};
96 // flags for event attributes
97 enum class EAFlags {
98 NONE = 0x0000,
99 ControlEvents = 0x0001,
100 OnChange = 0x0002,
101 OnClick = 0x0004,
102 OnDoubleClick = 0x0008,
103 OnSelect = 0x0010
105 namespace o3tl {
106 template<> struct typed_flags<EAFlags> : is_typed_flags<EAFlags, 0x001f> {};
109 // any other attributes, which are special to some control types
110 enum class SCAFlags {
111 NONE = 0x000000,
112 EchoChar = 0x000001,
113 MaxValue = 0x000002,
114 MinValue = 0x000004,
115 Validation = 0x000008,
116 GroupName = 0x000010,
117 MultiLine = 0x000020,
118 AutoCompletion = 0x000080,
119 Multiple = 0x000100,
120 DefaultButton = 0x000200,
121 CurrentState = 0x000400,
122 IsTristate = 0x000800,
123 State = 0x001000,
124 ColumnStyleName = 0x002000,
125 StepSize = 0x004000,
126 PageStepSize = 0x008000,
127 RepeatDelay = 0x010000,
128 Toggle = 0x020000,
129 FocusOnClick = 0x040000,
130 ImagePosition = 0x080000
132 namespace o3tl {
133 template<> struct typed_flags<SCAFlags> : is_typed_flags<SCAFlags, 0x0fffff> {};
137 namespace xmloff
140 /// attributes in the xml tag representing a form
141 enum FormAttributes
143 faName,
144 faServiceName,
145 faAction,
146 faEnctype,
147 faMethod,
148 faTargetFrame,
149 faAllowDeletes,
150 faAllowInserts,
151 faAllowUpdates,
152 faApplyFilter,
153 faCommand,
154 faCommandType,
155 faEscapeProcessing,
156 faDatasource,
157 faConnectionResource,
158 faDetailFiels,
159 faFilter,
160 faIgnoreResult,
161 faMasterFields,
162 faNavigationMode,
163 faOrder,
164 faTabbingCycle
167 // attributes of the office:forms element
168 enum OfficeFormsAttributes
170 ofaAutomaticFocus,
171 ofaApplyDesignMode
174 //= OAttributeMetaData
175 /** allows the translation of attribute ids into strings.
177 <p>This class does not allow to connect xml attributes to property names or
178 something like that, it only deals with the xml side</p>
180 class OAttributeMetaData
182 public:
183 /** calculates the xml attribute representation of a common control attribute.
184 @param _nId
185 the id of the attribute. Has to be one of the CCA_* constants.
187 static const sal_Char* getCommonControlAttributeName(CCAFlags _nId);
189 /** calculates the xml namespace key to use for a common control attribute
190 @param _nId
191 the id of the attribute. Has to be one of the CCA_* constants.
193 static sal_uInt16 getCommonControlAttributeNamespace(CCAFlags _nId);
195 /** retrieves the name of an attribute of a form xml representation
196 @param _eAttrib
197 enum value specifying the attribute
199 static const sal_Char* getFormAttributeName(FormAttributes _eAttrib);
201 /** calculates the xml namespace key to use for a attribute of a form xml representation
202 @param _eAttrib
203 enum value specifying the attribute
205 static sal_uInt16 getFormAttributeNamespace(FormAttributes _eAttrib);
207 /** calculates the xml attribute representation of a database attribute.
208 @param _nId
209 the id of the attribute. Has to be one of the DA_* constants.
211 static const sal_Char* getDatabaseAttributeName(DAFlags _nId);
213 /** calculates the xml namespace key to use for a database attribute.
214 @param _nId
215 the id of the attribute. Has to be one of the DA_* constants.
217 static inline sal_uInt16 getDatabaseAttributeNamespace(DAFlags )
219 // nothing special here
220 return XML_NAMESPACE_FORM;
223 /** calculates the xml attribute representation of a special attribute.
224 @param _nId
225 the id of the attribute. Has to be one of the SCA_* constants.
227 static const sal_Char* getSpecialAttributeName(SCAFlags _nId);
229 /** calculates the xml attribute representation of a binding attribute.
230 @param _nId
231 the id of the attribute. Has to be one of the BA_* constants.
233 static const sal_Char* getBindingAttributeName(BAFlags _nId);
235 /** calculates the xml namespace key to use for a binding attribute.
236 @param _nId
237 the id of the attribute. Has to be one of the BA_* constants.
239 static inline sal_uInt16 getBindingAttributeNamespace(BAFlags )
241 // nothing special here
242 return XML_NAMESPACE_FORM;
245 /** calculates the xml namespace key to use for a special attribute.
246 @param _nId
247 the id of the attribute. Has to be one of the SCA_* constants.
249 static sal_uInt16 getSpecialAttributeNamespace(SCAFlags _nId);
251 /** calculates the xml attribute representation of a attribute of the office:forms element
252 @param _nId
253 the id of the attribute
255 static const sal_Char* getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib);
257 /** calculates the xml namedspace key of a attribute of the office:forms element
258 @param _nId
259 the id of the attribute
261 static inline sal_uInt16 getOfficeFormsAttributeNamespace(OfficeFormsAttributes )
262 { // nothing special here
263 return XML_NAMESPACE_FORM;
267 //= OAttribute2Property
268 /** some kind of opposite to the OAttributeMetaData class. Able to translate
269 attributes into property names/types
271 <p>The construction of this class is rather expensive (or at least it's initialization from outside),
272 so it should be shared</p>
274 class OAttribute2Property
276 public:
277 // TODO: maybe the following struct should be used for exports, too. In this case we would not need to
278 // store it's instances in a map, but in a vector for faster access.
279 struct AttributeAssignment
281 OUString sAttributeName; // the attribute name
282 OUString sPropertyName; // the property name
283 css::uno::Type aPropertyType; // the property type
285 // entries which are special to some value types
286 const SvXMLEnumMapEntry* pEnumMap; // the enum map, if appliable
287 bool bInverseSemantics; // for booleans: attribute and property value have the same or an inverse semantics?
289 AttributeAssignment() : pEnumMap(nullptr), bInverseSemantics(false) { }
292 protected:
293 typedef std::map<OUString, AttributeAssignment> AttributeAssignments;
294 AttributeAssignments m_aKnownProperties;
296 public:
297 OAttribute2Property();
298 virtual ~OAttribute2Property();
300 /** return the AttributeAssignment which corresponds to the given attribute
302 @param _rAttribName
303 the name of the attrribute
304 @return
305 a pointer to the <type>AttributeAssignment</type> structure as requested, NULL if the attribute
306 does not represent a property.
308 const AttributeAssignment* getAttributeTranslation(
309 const OUString& _rAttribName);
311 /** add a attribute assignment referring to a string property to the map
312 @param _pAttributeName
313 the name of the attrribute
314 @param _rPropertyName
315 the name of the property assigned to the attribute
316 @param _pAttributeDefault
317 the default value for the attribute, if any. May be NULL, in this case the default is assumed to be
318 an empty string.
320 void addStringProperty(
321 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
322 const sal_Char* _pAttributeDefault = nullptr);
324 /** add a attribute assignment referring to a boolean property to the map
326 @param _pAttributeName
327 the name of the attrribute
328 @param _rPropertyName
329 the name of the property assigned to the attribute
330 @param _bAttributeDefault
331 the default value for the attribute.
332 @param _bInverseSemantics
333 if <TRUE/>, a attribute value of <TRUE/> means a property value of <FALSE/> and vice verse.<br/>
334 if <FALSE/>, the attribute value is used as property value directly
336 void addBooleanProperty(
337 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
338 const bool _bAttributeDefault, const bool _bInverseSemantics = false);
340 /** add a attribute assignment referring to an int16 property to the map
342 @param _pAttributeName
343 the name of the attrribute
344 @param _rPropertyName
345 the name of the property assigned to the attribute
346 @param _nAttributeDefault
347 the default value for the attribute.
349 void addInt16Property(
350 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
351 const sal_Int16 _nAttributeDefault);
353 /** add a attribute assignment referring to an int32 property to the map
355 @param _pAttributeName
356 the name of the attrribute
357 @param _rPropertyName
358 the name of the property assigned to the attribute
359 @param _nAttributeDefault
360 the default value for the attribute.
362 void addInt32Property(
363 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
364 const sal_Int32 _nAttributeDefault );
366 /** add a attribute assignment referring to an enum property to the map
368 @param _pAttributeName
369 the name of the attrribute
370 @param _rPropertyName
371 the name of the property assigned to the attribute
372 @param _nAttributeDefault
373 the default value for the attribute, as (32bit) integer
374 @param _pValueMap
375 the map to translate strings into enum values
376 @param _pType
377 the type of the property. May be NULL, in this case 32bit integer is assumed.
379 void addEnumProperty(
380 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
381 const sal_uInt16 _nAttributeDefault, const SvXMLEnumMapEntry* _pValueMap,
382 const css::uno::Type* _pType = nullptr);
384 protected:
385 /// some common code for the various add*Property methods
386 AttributeAssignment& implAdd(
387 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
388 const css::uno::Type& _rType, const OUString& _rDefaultString);
390 } // namespace xmloff
392 #endif // INCLUDED_XMLOFF_SOURCE_FORMS_FORMATTRIBUTES_HXX
394 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */