LibreOffice Module xmloff (master)  1
formattributes.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_XMLOFF_SOURCE_FORMS_FORMATTRIBUTES_HXX
21 #define INCLUDED_XMLOFF_SOURCE_FORMS_FORMATTRIBUTES_HXX
22 
23 #include <sal/config.h>
24 
25 #include <map>
26 
27 #include <com/sun/star/uno/Type.hxx>
28 #include <rtl/ustring.hxx>
29 #include <sal/types.h>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <o3tl/typed_flags_set.hxx>
33 
34 template<typename EnumT>
35 struct SvXMLEnumMapEntry;
36 
37  // flags for common control attributes
38 enum class CCAFlags {
39  NONE = 0x00000000,
40  Name = 0x00000001,
41  ServiceName = 0x00000002,
42  ButtonType = 0x00000004,
43  ControlId = 0x00000008,
44  CurrentSelected = 0x00000010,
45  CurrentValue = 0x00000020,
46  Disabled = 0x00000040,
47  Dropdown = 0x00000080,
48  For = 0x00000100,
49  ImageData = 0x00000200,
50  Label = 0x00000400,
51  MaxLength = 0x00000800,
52  Printable = 0x00001000,
53  ReadOnly = 0x00002000,
54  Selected = 0x00004000,
55  Size = 0x00008000,
56  TabIndex = 0x00010000,
57  TargetFrame = 0x00020000,
58  TargetLocation = 0x00040000,
59  TabStop = 0x00080000,
60  Title = 0x00100000,
61  Value = 0x00200000,
62  Orientation = 0x00400000,
63  VisualEffect = 0x00800000,
64  EnableVisible = 0x01000000,
65 };
66 namespace o3tl {
67  template<> struct typed_flags<CCAFlags> : is_typed_flags<CCAFlags, 0x01ffffff> {};
68 }
69 
70  // flags for database control attributes
71 enum class DAFlags {
72  NONE = 0x0000,
73  BoundColumn = 0x0001,
74  ConvertEmpty = 0x0002,
75  DataField = 0x0004,
76  ListSource = 0x0008,
77  ListSource_TYPE = 0x0010,
78  InputRequired = 0x0020,
79 };
80 namespace o3tl {
81  template<> struct typed_flags<DAFlags> : is_typed_flags<DAFlags, 0x003f> {};
82 }
83 
84  // flags for binding related control attributes
85 enum class BAFlags {
86  NONE = 0x0000,
87  LinkedCell = 0x0001,
88  ListLinkingType = 0x0002,
89  ListCellRange = 0x0004,
90  XFormsBind = 0x0008,
91  XFormsListBind = 0x0010,
92  XFormsSubmission = 0x0020
93 };
94 namespace o3tl {
95  template<> struct typed_flags<BAFlags> : is_typed_flags<BAFlags, 0x003f> {};
96 }
97 
98  // flags for event attributes
99 enum class EAFlags {
100  NONE = 0x0000,
101  ControlEvents = 0x0001,
102  OnChange = 0x0002,
103  OnClick = 0x0004,
104  OnDoubleClick = 0x0008,
105  OnSelect = 0x0010
106 };
107 namespace o3tl {
108  template<> struct typed_flags<EAFlags> : is_typed_flags<EAFlags, 0x001f> {};
109 }
110 
111  // any other attributes, which are special to some control types
112 enum class SCAFlags {
113  NONE = 0x000000,
114  EchoChar = 0x000001,
115  MaxValue = 0x000002,
116  MinValue = 0x000004,
117  Validation = 0x000008,
118  GroupName = 0x000010,
119  MultiLine = 0x000020,
120  AutoCompletion = 0x000080,
121  Multiple = 0x000100,
122  DefaultButton = 0x000200,
123  CurrentState = 0x000400,
124  IsTristate = 0x000800,
125  State = 0x001000,
126  ColumnStyleName = 0x002000,
127  StepSize = 0x004000,
128  PageStepSize = 0x008000,
129  RepeatDelay = 0x010000,
130  Toggle = 0x020000,
131  FocusOnClick = 0x040000,
132  ImagePosition = 0x080000
133 };
134 namespace o3tl {
135  template<> struct typed_flags<SCAFlags> : is_typed_flags<SCAFlags, 0x0fffbf> {};
136 }
137 
138 
139 namespace xmloff
140 {
141 
144  {
164  };
165 
166  // attributes of the office:forms element
168  {
171  };
172 
173  //= OAttributeMetaData
180  {
181  public:
186  static const char* getCommonControlAttributeName(CCAFlags _nId);
187 
192  static sal_Int32 getCommonControlAttributeToken(CCAFlags _nId);
193 
198  static sal_uInt16 getCommonControlAttributeNamespace(CCAFlags _nId);
199 
204  static const char* getFormAttributeName(FormAttributes _eAttrib);
205 
210  static sal_Int32 getFormAttributeToken(FormAttributes _eAttrib);
211 
216  static sal_uInt16 getFormAttributeNamespace(FormAttributes _eAttrib);
217 
222  static const char* getDatabaseAttributeName(DAFlags _nId);
223 
228  static sal_Int32 getDatabaseAttributeToken(DAFlags _nId);
229 
234  static sal_uInt16 getDatabaseAttributeNamespace()
235  {
236  // nothing special here
237  return XML_NAMESPACE_FORM;
238  }
239 
244  static const char* getSpecialAttributeName(SCAFlags _nId);
245 
250  static sal_Int32 getSpecialAttributeToken(SCAFlags _nId);
251 
256  static const char* getBindingAttributeName(BAFlags _nId);
257 
262  static sal_Int32 getBindingAttributeToken(BAFlags _nId);
263 
268  static sal_uInt16 getBindingAttributeNamespace()
269  {
270  // nothing special here
271  return XML_NAMESPACE_FORM;
272  }
273 
278  static sal_uInt16 getSpecialAttributeNamespace(SCAFlags _nId);
279 
284  static const char* getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib);
286 
292  { // nothing special here
293  return XML_NAMESPACE_FORM;
294  }
295  };
296 
297  //= OAttribute2Property
305  {
306  public:
307  // TODO: maybe the following struct should be used for exports, too. In this case we would not need to
308  // store it's instances in a map, but in a vector for faster access.
310  {
311  OUString sPropertyName; // the property name
312  css::uno::Type aPropertyType; // the property type
313 
314  // entries which are special to some value types
316  pEnumMap; // the enum map, if applicable
317  bool bInverseSemantics; // for booleans: attribute and property value have the same or an inverse semantics?
318 
319  AttributeAssignment() : pEnumMap(nullptr), bInverseSemantics(false) { }
320  };
321 
322  private:
323  std::map<sal_Int32, AttributeAssignment> m_aKnownProperties;
324 
325  public:
328 
335  const AttributeAssignment* getAttributeTranslation(sal_Int32 nAttributeToken);
336 
343  void addStringProperty(
344  sal_Int32 nAttributeToken, const OUString& _rPropertyName);
345 
358  void addBooleanProperty(
359  sal_Int32 nAttributeToken, const OUString& _rPropertyName,
360  const bool _bAttributeDefault, const bool _bInverseSemantics = false);
361 
369  void addInt16Property(
370  sal_Int32 nAttributeToken, const OUString& _rPropertyName);
371 
379  void addInt32Property(
380  sal_Int32 nAttributeToken, const OUString& _rPropertyName );
381 
393  template<typename EnumT>
395  sal_Int32 nAttributeToken, const OUString& _rPropertyName,
396  const SvXMLEnumMapEntry<EnumT>* _pValueMap,
397  const css::uno::Type* _pType = nullptr)
398  {
399  addEnumPropertyImpl(nAttributeToken, _rPropertyName,
400  reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(_pValueMap), _pType);
401  }
402 
403  private:
404  void addEnumPropertyImpl(
405  sal_Int32 nAttributeToken, const OUString& _rPropertyName,
406  const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
407  const css::uno::Type* _pType);
409  AttributeAssignment& implAdd(
410  sal_Int32 nAttributeToken, const OUString& _rPropertyName,
411  const css::uno::Type& _rType);
412  };
413 } // namespace xmloff
414 
415 #endif // INCLUDED_XMLOFF_SOURCE_FORMS_FORMATTRIBUTES_HXX
416 
417 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
BAFlags
static sal_uInt16 getCommonControlAttributeNamespace(CCAFlags _nId)
calculates the xml namespace key to use for a common control attribute
DAFlags
static const char * getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib)
calculates the xml attribute representation of an attribute of the office:forms element ...
const SvXMLEnumMapEntry< sal_uInt16 > * pEnumMap
static const char * getBindingAttributeName(BAFlags _nId)
calculates the xml attribute representation of a binding attribute.
void addEnumPropertyImpl(sal_Int32 nAttributeToken, const OUString &_rPropertyName, const SvXMLEnumMapEntry< sal_uInt16 > *_pValueMap, const css::uno::Type *_pType)
some kind of opposite to the OAttributeMetaData class.
SCAFlags
static const char * getCommonControlAttributeName(CCAFlags _nId)
calculates the xml attribute representation of a common control attribute.
static xmloff::token::XMLTokenEnum getOfficeFormsAttributeToken(OfficeFormsAttributes _eAttrib)
allows the translation of attribute ids into strings.
static sal_Int32 getDatabaseAttributeToken(DAFlags _nId)
calculates the xml attribute representation of a database attribute.
FormAttributes
attributes in the xml tag representing a form
static sal_Int32 getBindingAttributeToken(BAFlags _nId)
calculates the xml attribute representation of a binding attribute.
void addBooleanProperty(sal_Int32 nAttributeToken, const OUString &_rPropertyName, const bool _bAttributeDefault, const bool _bInverseSemantics=false)
add an attribute assignment referring to a boolean property to the map
ButtonType
static sal_Int32 getSpecialAttributeToken(SCAFlags _nId)
calculates the xml attribute representation of a special attribute.
constexpr sal_uInt16 XML_NAMESPACE_FORM
static sal_Int32 getFormAttributeToken(FormAttributes _eAttrib)
retrieves the name of an attribute of a form xml representation
std::map< sal_Int32, AttributeAssignment > m_aKnownProperties
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:49
CCAFlags
void addInt16Property(sal_Int32 nAttributeToken, const OUString &_rPropertyName)
add an attribute assignment referring to an int16 property to the map
Orientation
static const char * getSpecialAttributeName(SCAFlags _nId)
calculates the xml attribute representation of a special attribute.
static sal_uInt16 getOfficeFormsAttributeNamespace()
calculates the xml namedspace key of an attribute of the office:forms element
AttributeAssignment & implAdd(sal_Int32 nAttributeToken, const OUString &_rPropertyName, const css::uno::Type &_rType)
some common code for the various add*Property methods
static const char * getDatabaseAttributeName(DAFlags _nId)
calculates the xml attribute representation of a database attribute.
const AttributeAssignment * getAttributeTranslation(sal_Int32 nAttributeToken)
return the AttributeAssignment which corresponds to the given attribute
void addInt32Property(sal_Int32 nAttributeToken, const OUString &_rPropertyName)
add an attribute assignment referring to an int32 property to the map
static sal_uInt16 getDatabaseAttributeNamespace()
calculates the xml namespace key to use for a database attribute.
Map an XMLTokenEnum to an enum value.
Definition: ximpshap.hxx:40
static sal_uInt16 getBindingAttributeNamespace()
calculates the xml namespace key to use for a binding attribute.
State
static sal_Int32 getCommonControlAttributeToken(CCAFlags _nId)
calculates the xml attribute representation of a common control attribute.
void addStringProperty(sal_Int32 nAttributeToken, const OUString &_rPropertyName)
add an attribute assignment referring to a string property to the map
static sal_uInt16 getSpecialAttributeNamespace(SCAFlags _nId)
calculates the xml namespace key to use for a special attribute.
void addEnumProperty(sal_Int32 nAttributeToken, const OUString &_rPropertyName, const SvXMLEnumMapEntry< EnumT > *_pValueMap, const css::uno::Type *_pType=nullptr)
add an attribute assignment referring to an enum property to the map
EAFlags
static const char * getFormAttributeName(FormAttributes _eAttrib)
retrieves the name of an attribute of a form xml representation
static sal_uInt16 getFormAttributeNamespace(FormAttributes _eAttrib)
calculates the xml namespace key to use for an attribute of a form xml representation ...