LibreOffice Module xmloff (master)  1
formattributes.cxx
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 #include "formattributes.hxx"
21 
22 #include <xmloff/xmlnmspe.hxx>
23 #include <xmloff/xmluconv.hxx>
24 #include <osl/diagnose.h>
25 
26 
27 namespace xmloff
28 {
29 
30  using namespace ::com::sun::star::uno;
31  using namespace ::com::sun::star::lang;
32  using namespace ::com::sun::star::beans;
33 
34  //= OAttributeMetaData
36  {
37  switch (_nId)
38  {
39  case CCAFlags::Name: return "name";
40  case CCAFlags::ServiceName: return "control-implementation";
41  case CCAFlags::ButtonType: return "button-type";
42 // disabled(AddAttributeIdLegacy) case CCAFlags::ControlId: return "id";
43  case CCAFlags::CurrentSelected: return "current-selected";
44  case CCAFlags::CurrentValue: return "current-value";
45  case CCAFlags::Disabled: return "disabled";
46  case CCAFlags::EnableVisible: return "visible";
47  case CCAFlags::Dropdown: return "dropdown";
48  case CCAFlags::For: return "for";
49  case CCAFlags::ImageData: return "image-data";
50  case CCAFlags::Label: return "label";
51  case CCAFlags::MaxLength: return "max-length";
52  case CCAFlags::Printable: return "printable";
53  case CCAFlags::ReadOnly: return "readonly";
54  case CCAFlags::Selected: return "selected";
55  case CCAFlags::Size: return "size";
56  case CCAFlags::TabIndex: return "tab-index";
57  case CCAFlags::TargetFrame: return "target-frame";
58  case CCAFlags::TargetLocation: return "href"; // the only special thing here: TargetLocation is represented by an xlink:href attribute
59  case CCAFlags::TabStop: return "tab-stop";
60  case CCAFlags::Title: return "title";
61  case CCAFlags::Value: return "value";
62  case CCAFlags::Orientation: return "orientation";
63  case CCAFlags::VisualEffect: return "visual-effect";
64  default:
65  OSL_FAIL("OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
66  }
67  return "";
68  }
69 
71  {
72  if (CCAFlags::TargetLocation == _nId)
73  return XML_NAMESPACE_XLINK;
74 
75  if (CCAFlags::TargetFrame == _nId)
76  return XML_NAMESPACE_OFFICE;
77 
78  return XML_NAMESPACE_FORM;
79  }
80 
82  {
83  switch (_eAttrib)
84  {
85  case faName: return "name";
86  case faAction: return "href"; // the only special thing here: Action is represented by an xlink:href attribute
87  case faEnctype: return "enctype";
88  case faMethod: return "method";
89  case faAllowDeletes: return "allow-deletes";
90  case faAllowInserts: return "allow-inserts";
91  case faAllowUpdates: return "allow-updates";
92  case faApplyFilter: return "apply-filter";
93  case faCommand: return "command";
94  case faCommandType: return "command-type";
95  case faEscapeProcessing: return "escape-processing";
96  case faDatasource: return "datasource";
97  case faDetailFiels: return "detail-fields";
98  case faFilter: return "filter";
99  case faIgnoreResult: return "ignore-result";
100  case faMasterFields: return "master-fields";
101  case faNavigationMode: return "navigation-mode";
102  case faOrder: return "order";
103  case faTabbingCycle: return "tab-cycle";
104  default:
105  OSL_FAIL("OAttributeMetaData::getFormAttributeName: invalid id!");
106  }
107  return "";
108  }
109 
111  {
112  if (faAction == _eAttrib)
113  return XML_NAMESPACE_XLINK;
114 
115  return XML_NAMESPACE_FORM;
116  }
117 
119  {
120  switch (_nId)
121  {
122  case DAFlags::BoundColumn: return "bound-column";
123  case DAFlags::ConvertEmpty: return "convert-empty-to-null";
124  case DAFlags::DataField: return "data-field";
125  case DAFlags::ListSource: return "list-source";
126  case DAFlags::ListSource_TYPE: return "list-source-type";
127  case DAFlags::InputRequired: return "input-required";
128  default:
129  OSL_FAIL("OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
130  }
131  return "";
132  }
133 
135  {
136  switch (_nId)
137  {
138  case BAFlags::LinkedCell: return "linked-cell";
139  case BAFlags::ListLinkingType: return "list-linkage-type";
140  case BAFlags::ListCellRange: return "source-cell-range";
141  default:
142  OSL_FAIL("OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
143  }
144  return "";
145  }
146 
148  {
149  switch (_nId)
150  {
151  case SCAFlags::EchoChar: return "echo-char";
152  case SCAFlags::MaxValue: return "max-value";
153  case SCAFlags::MinValue: return "min-value";
154  case SCAFlags::Validation: return "validation";
155  case SCAFlags::GroupName: return "group-name";
156  case SCAFlags::MultiLine: return "multi-line";
157  case SCAFlags::AutoCompletion: return "auto-complete";
158  case SCAFlags::Multiple: return "multiple";
159  case SCAFlags::DefaultButton: return "default-button";
160  case SCAFlags::CurrentState: return "current-state";
161  case SCAFlags::IsTristate: return "is-tristate";
162  case SCAFlags::State: return "state";
163  case SCAFlags::ColumnStyleName: return "text-style-name";
164  case SCAFlags::StepSize: return "step-size";
165  case SCAFlags::PageStepSize: return "page-step-size";
166  case SCAFlags::RepeatDelay: return "delay-for-repeat";
167  case SCAFlags::Toggle: return "toggle";
168  case SCAFlags::FocusOnClick: return "focus-on-click";
169  default:
170  OSL_FAIL("OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
171  }
172  return "";
173  }
174 
176  {
177  switch( _nId )
178  {
180  default: break;
181  }
182  return XML_NAMESPACE_FORM;
183  }
184 
186  {
187  switch (_eAttrib)
188  {
189  case ofaAutomaticFocus: return "automatic-focus";
190  case ofaApplyDesignMode: return "apply-design-mode";
191  default:
192  OSL_FAIL("OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
193  }
194  return "";
195  }
196 
197  //= OAttribute2Property
199  {
200  }
201 
203  {
204  }
205 
207  const OUString& _rAttribName)
208  {
209  AttributeAssignments::const_iterator aPos = m_aKnownProperties.find(_rAttribName);
210  if (m_aKnownProperties.end() != aPos)
211  return &aPos->second;
212  return nullptr;
213  }
214 
216  const char* _pAttributeName, const OUString& _rPropertyName)
217  {
218  implAdd(_pAttributeName, _rPropertyName, ::cppu::UnoType<OUString>::get());
219  }
220 
222  const char* _pAttributeName, const OUString& _rPropertyName,
223  const bool /*_bAttributeDefault*/, const bool _bInverseSemantics)
224  {
225  AttributeAssignment& aAssignment = implAdd(_pAttributeName, _rPropertyName, cppu::UnoType<bool>::get());
226  aAssignment.bInverseSemantics = _bInverseSemantics;
227  }
228 
230  const char* _pAttributeName, const OUString& _rPropertyName)
231  {
232  implAdd(_pAttributeName, _rPropertyName, ::cppu::UnoType<sal_Int16>::get());
233  }
234 
236  const char* _pAttributeName, const OUString& _rPropertyName)
237  {
238  implAdd( _pAttributeName, _rPropertyName, ::cppu::UnoType<sal_Int32>::get() );
239  }
240 
242  const char* _pAttributeName, const OUString& _rPropertyName,
243  const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
244  const css::uno::Type* _pType)
245  {
246  AttributeAssignment& aAssignment = implAdd(_pAttributeName, _rPropertyName,
247  _pType ? *_pType : ::cppu::UnoType<sal_Int32>::get());
248  aAssignment.pEnumMap = _pValueMap;
249  }
250 
252  const char* _pAttributeName, const OUString& _rPropertyName,
253  const css::uno::Type& _rType)
254  {
255  OSL_ENSURE(m_aKnownProperties.end() == m_aKnownProperties.find(OUString::createFromAscii(_pAttributeName)),
256  "OAttribute2Property::implAdd: already have this attribute!");
257 
258  OUString sAttributeName = OUString::createFromAscii(_pAttributeName);
259 
260  AttributeAssignment aAssignment;
261  aAssignment.sPropertyName = _rPropertyName;
262  aAssignment.aPropertyType = _rType;
263 
264  // redundance, the accessor is stored in aAssignment.sAttributeName, too
265  m_aKnownProperties[sAttributeName] = aAssignment;
266  return m_aKnownProperties[sAttributeName];
267  }
268 
269 } // namespace xmloff
270 
271 /* 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.
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.
FormAttributes
attributes in the xml tag representing a form
void addInt32Property(const char *_pAttributeName, const OUString &_rPropertyName)
add an attribute assignment referring to an int32 property to the map
CCAFlags
constexpr sal_uInt16 XML_NAMESPACE_FORMX
Definition: xmlnmspe.hxx:85
AttributeAssignments m_aKnownProperties
static const char * getSpecialAttributeName(SCAFlags _nId)
calculates the xml attribute representation of a special attribute.
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
constexpr sal_uInt16 XML_NAMESPACE_XLINK
Definition: xmlnmspe.hxx:35
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.
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 ...
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
Definition: xmlnmspe.hxx:29
void addInt16Property(const char *_pAttributeName, const OUString &_rPropertyName)
add an attribute assignment referring to an int16 property to the map