1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
39 ServiceName
= 0x00000002,
40 ButtonType
= 0x00000004,
41 ControlId
= 0x00000008,
42 CurrentSelected
= 0x00000010,
43 CurrentValue
= 0x00000020,
44 Disabled
= 0x00000040,
45 Dropdown
= 0x00000080,
47 ImageData
= 0x00000200,
49 MaxLength
= 0x00000800,
50 Printable
= 0x00001000,
51 ReadOnly
= 0x00002000,
52 Selected
= 0x00004000,
54 TabIndex
= 0x00010000,
55 TargetFrame
= 0x00020000,
56 TargetLocation
= 0x00040000,
60 Orientation
= 0x00400000,
61 VisualEffect
= 0x00800000,
62 EnableVisible
= 0x01000000,
65 template<> struct typed_flags
<CCAFlags
> : is_typed_flags
<CCAFlags
, 0x01ffffff> {};
68 // flags for database control attributes
72 ConvertEmpty
= 0x0002,
75 ListSource_TYPE
= 0x0010,
76 InputRequired
= 0x0020,
79 template<> struct typed_flags
<DAFlags
> : is_typed_flags
<DAFlags
, 0x003f> {};
82 // flags for binding related control attributes
86 ListLinkingType
= 0x0002,
87 ListCellRange
= 0x0004,
89 XFormsListBind
= 0x0010,
90 XFormsSubmission
= 0x0020
93 template<> struct typed_flags
<BAFlags
> : is_typed_flags
<BAFlags
, 0x003f> {};
96 // flags for event attributes
99 ControlEvents
= 0x0001,
102 OnDoubleClick
= 0x0008,
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
{
115 Validation
= 0x000008,
116 GroupName
= 0x000010,
117 MultiLine
= 0x000020,
118 AutoCompletion
= 0x000080,
120 DefaultButton
= 0x000200,
121 CurrentState
= 0x000400,
122 IsTristate
= 0x000800,
124 ColumnStyleName
= 0x002000,
126 PageStepSize
= 0x008000,
127 RepeatDelay
= 0x010000,
129 FocusOnClick
= 0x040000,
130 ImagePosition
= 0x080000
133 template<> struct typed_flags
<SCAFlags
> : is_typed_flags
<SCAFlags
, 0x0fffff> {};
140 /// attributes in the xml tag representing a form
157 faConnectionResource
,
167 // attributes of the office:forms element
168 enum OfficeFormsAttributes
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
183 /** calculates the xml attribute representation of a common control attribute.
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
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
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
203 enum value specifying the attribute
205 static sal_uInt16
getFormAttributeNamespace(FormAttributes _eAttrib
);
207 /** calculates the xml attribute representation of a database attribute.
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.
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.
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.
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.
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.
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
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
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
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) { }
293 typedef std::map
<OUString
, AttributeAssignment
> AttributeAssignments
;
294 AttributeAssignments m_aKnownProperties
;
297 OAttribute2Property();
298 virtual ~OAttribute2Property();
300 /** return the AttributeAssignment which corresponds to the given attribute
303 the name of the attrribute
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
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
375 the map to translate strings into enum values
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);
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: */