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 .
22 #include <sal/config.h>
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
40 ServiceName
= 0x00000002,
41 ButtonType
= 0x00000004,
42 ControlId
= 0x00000008,
43 CurrentSelected
= 0x00000010,
44 CurrentValue
= 0x00000020,
45 Disabled
= 0x00000040,
46 Dropdown
= 0x00000080,
48 ImageData
= 0x00000200,
50 MaxLength
= 0x00000800,
51 Printable
= 0x00001000,
52 ReadOnly
= 0x00002000,
53 Selected
= 0x00004000,
55 TabIndex
= 0x00010000,
56 TargetFrame
= 0x00020000,
57 TargetLocation
= 0x00040000,
61 Orientation
= 0x00400000,
62 VisualEffect
= 0x00800000,
63 EnableVisible
= 0x01000000,
66 template<> struct typed_flags
<CCAFlags
> : is_typed_flags
<CCAFlags
, 0x01ffffff> {};
69 // flags for database control attributes
73 ConvertEmpty
= 0x0002,
76 ListSource_TYPE
= 0x0010,
77 InputRequired
= 0x0020,
80 template<> struct typed_flags
<DAFlags
> : is_typed_flags
<DAFlags
, 0x003f> {};
83 // flags for binding related control attributes
87 ListLinkingType
= 0x0002,
88 ListCellRange
= 0x0004,
90 XFormsListBind
= 0x0010,
91 XFormsSubmission
= 0x0020
94 template<> struct typed_flags
<BAFlags
> : is_typed_flags
<BAFlags
, 0x003f> {};
97 // flags for event attributes
100 ControlEvents
= 0x0001,
103 OnDoubleClick
= 0x0008,
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
{
116 Validation
= 0x000008,
117 GroupName
= 0x000010,
118 MultiLine
= 0x000020,
119 AutoCompletion
= 0x000080,
121 DefaultButton
= 0x000200,
122 CurrentState
= 0x000400,
123 IsTristate
= 0x000800,
125 ColumnStyleName
= 0x002000,
127 PageStepSize
= 0x008000,
128 RepeatDelay
= 0x010000,
130 FocusOnClick
= 0x040000,
131 ImagePosition
= 0x080000
134 template<> struct typed_flags
<SCAFlags
> : is_typed_flags
<SCAFlags
, 0x0fffbf> {};
141 /// attributes in the xml tag representing a form
165 // attributes of the office:forms element
166 enum OfficeFormsAttributes
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
181 /** calculates the xml attribute representation of a common control attribute.
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.
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
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
201 enum value specifying the attribute
203 static OUString
getFormAttributeName(FormAttributes _eAttrib
);
205 /** retrieves the name of an attribute of a form xml representation
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
213 enum value specifying the attribute
215 static sal_uInt16
getFormAttributeNamespace(FormAttributes _eAttrib
);
217 /** calculates the xml attribute representation of a database attribute.
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.
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.
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.
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.
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.
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.
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.
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.
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
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
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
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) { }
322 std::map
<sal_Int32
, AttributeAssignment
> m_aKnownProperties
;
325 OAttribute2Property();
326 ~OAttribute2Property();
328 /** return the AttributeAssignment which corresponds to the given attribute
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
388 the map to translate strings into enum values
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
);
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: */