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/xmlnmspe.hxx>
31 #include <o3tl/typed_flags_set.hxx>
32 
33 template<typename EnumT>
34 struct SvXMLEnumMapEntry;
35 
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,
64 };
65 namespace o3tl {
66  template<> struct typed_flags<CCAFlags> : is_typed_flags<CCAFlags, 0x01ffffff> {};
67 }
68 
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,
78 };
79 namespace o3tl {
80  template<> struct typed_flags<DAFlags> : is_typed_flags<DAFlags, 0x003f> {};
81 }
82 
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
92 };
93 namespace o3tl {
94  template<> struct typed_flags<BAFlags> : is_typed_flags<BAFlags, 0x003f> {};
95 }
96 
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
105 };
106 namespace o3tl {
107  template<> struct typed_flags<EAFlags> : is_typed_flags<EAFlags, 0x001f> {};
108 }
109 
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
132 };
133 namespace o3tl {
134  template<> struct typed_flags<SCAFlags> : is_typed_flags<SCAFlags, 0x0fffbf> {};
135 }
136 
137 
138 namespace xmloff
139 {
140 
143  {
163  };
164 
165  // attributes of the office:forms element
167  {
170  };
171 
172  //= OAttributeMetaData
179  {
180  public:
185  static const char* getCommonControlAttributeName(CCAFlags _nId);
186 
191  static sal_uInt16 getCommonControlAttributeNamespace(CCAFlags _nId);
192 
197  static const char* getFormAttributeName(FormAttributes _eAttrib);
198 
203  static sal_uInt16 getFormAttributeNamespace(FormAttributes _eAttrib);
204 
209  static const char* getDatabaseAttributeName(DAFlags _nId);
210 
215  static sal_uInt16 getDatabaseAttributeNamespace()
216  {
217  // nothing special here
218  return XML_NAMESPACE_FORM;
219  }
220 
225  static const char* getSpecialAttributeName(SCAFlags _nId);
226 
231  static const char* getBindingAttributeName(BAFlags _nId);
232 
237  static sal_uInt16 getBindingAttributeNamespace()
238  {
239  // nothing special here
240  return XML_NAMESPACE_FORM;
241  }
242 
247  static sal_uInt16 getSpecialAttributeNamespace(SCAFlags _nId);
248 
253  static const char* getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib);
254 
260  { // nothing special here
261  return XML_NAMESPACE_FORM;
262  }
263  };
264 
265  //= OAttribute2Property
273  {
274  public:
275  // TODO: maybe the following struct should be used for exports, too. In this case we would not need to
276  // store it's instances in a map, but in a vector for faster access.
278  {
279  OUString sPropertyName; // the property name
280  css::uno::Type aPropertyType; // the property type
281 
282  // entries which are special to some value types
284  pEnumMap; // the enum map, if applicable
285  bool bInverseSemantics; // for booleans: attribute and property value have the same or an inverse semantics?
286 
287  AttributeAssignment() : pEnumMap(nullptr), bInverseSemantics(false) { }
288  };
289 
290  private:
291  typedef std::map<OUString, AttributeAssignment> AttributeAssignments;
292  AttributeAssignments m_aKnownProperties;
293 
294  public:
297 
307  const OUString& _rAttribName);
308 
315  void addStringProperty(
316  const char* _pAttributeName, const OUString& _rPropertyName);
317 
330  void addBooleanProperty(
331  const char* _pAttributeName, const OUString& _rPropertyName,
332  const bool _bAttributeDefault, const bool _bInverseSemantics = false);
333 
341  void addInt16Property(
342  const char* _pAttributeName, const OUString& _rPropertyName);
343 
351  void addInt32Property(
352  const char* _pAttributeName, const OUString& _rPropertyName );
353 
365  template<typename EnumT>
367  const char* _pAttributeName, const OUString& _rPropertyName,
368  const SvXMLEnumMapEntry<EnumT>* _pValueMap,
369  const css::uno::Type* _pType = nullptr)
370  {
371  addEnumPropertyImpl(_pAttributeName, _rPropertyName,
372  reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(_pValueMap), _pType);
373  }
374 
375  private:
376  void addEnumPropertyImpl(
377  const char* _pAttributeName, const OUString& _rPropertyName,
378  const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
379  const css::uno::Type* _pType);
381  AttributeAssignment& implAdd(
382  const char* _pAttributeName, const OUString& _rPropertyName,
383  const css::uno::Type& _rType);
384  };
385 } // namespace xmloff
386 
387 #endif // INCLUDED_XMLOFF_SOURCE_FORMS_FORMATTRIBUTES_HXX
388 
389 /* 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 addEnumProperty(const char *_pAttributeName, 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
some kind of opposite to the OAttributeMetaData class.
const AttributeAssignment * getAttributeTranslation(const OUString &_rAttribName)
return the AttributeAssignment which corresponds to the given attribute
SCAFlags
static const char * getCommonControlAttributeName(CCAFlags _nId)
calculates the xml attribute representation of a common control attribute.
std::map< OUString, AttributeAssignment > AttributeAssignments
allows the translation of attribute ids into strings.
FormAttributes
attributes in the xml tag representing a form
ButtonType
void addInt32Property(const char *_pAttributeName, const OUString &_rPropertyName)
add an attribute assignment referring to an int32 property to the map
CCAFlags
AttributeAssignments m_aKnownProperties
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
void addEnumPropertyImpl(const char *_pAttributeName, const OUString &_rPropertyName, const SvXMLEnumMapEntry< sal_uInt16 > *_pValueMap, const css::uno::Type *_pType)
static const char * getDatabaseAttributeName(DAFlags _nId)
calculates the xml attribute representation of a database attribute.
constexpr sal_uInt16 XML_NAMESPACE_FORM
Definition: xmlnmspe.hxx:44
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
AttributeAssignment & implAdd(const char *_pAttributeName, const OUString &_rPropertyName, const css::uno::Type &_rType)
some common code for the various add*Property methods
void addStringProperty(const char *_pAttributeName, const OUString &_rPropertyName)
add an attribute assignment referring to a string property to the map
void addBooleanProperty(const char *_pAttributeName, const OUString &_rPropertyName, const bool _bAttributeDefault, const bool _bInverseSemantics=false)
add an attribute assignment referring to a boolean property to the map
static sal_uInt16 getSpecialAttributeNamespace(SCAFlags _nId)
calculates the xml namespace key to use for a special attribute.
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 ...
void addInt16Property(const char *_pAttributeName, const OUString &_rPropertyName)
add an attribute assignment referring to an int16 property to the map