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
23#include <xmloff/xmluconv.hxx>
24#include <xmloff/xmlimp.hxx>
25#include <osl/diagnose.h>
26
27using namespace xmloff::token;
28
29namespace xmloff
30{
31
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::beans;
35
36 //= OAttributeMetaData
38 {
39 switch (_nId)
40 {
41 case CCAFlags::Name: return "name";
42 case CCAFlags::ServiceName: return "control-implementation";
43 case CCAFlags::ButtonType: return "button-type";
44// disabled(AddAttributeIdLegacy) case CCAFlags::ControlId: return "id";
45 case CCAFlags::CurrentSelected: return "current-selected";
46 case CCAFlags::CurrentValue: return "current-value";
47 case CCAFlags::Disabled: return "disabled";
48 case CCAFlags::EnableVisible: return "visible";
49 case CCAFlags::Dropdown: return "dropdown";
50 case CCAFlags::For: return "for";
51 case CCAFlags::ImageData: return "image-data";
52 case CCAFlags::Label: return "label";
53 case CCAFlags::MaxLength: return "max-length";
54 case CCAFlags::Printable: return "printable";
55 case CCAFlags::ReadOnly: return "readonly";
56 case CCAFlags::Selected: return "selected";
57 case CCAFlags::Size: return "size";
58 case CCAFlags::TabIndex: return "tab-index";
59 case CCAFlags::TargetFrame: return "target-frame";
60 case CCAFlags::TargetLocation: return "href"; // the only special thing here: TargetLocation is represented by an xlink:href attribute
61 case CCAFlags::TabStop: return "tab-stop";
62 case CCAFlags::Title: return "title";
63 case CCAFlags::Value: return "value";
64 case CCAFlags::Orientation: return "orientation";
65 case CCAFlags::VisualEffect: return "visual-effect";
66 default:
67 OSL_FAIL("OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
68 }
69 return "";
70 }
71
73 {
74 switch (_nId)
75 {
76 case CCAFlags::Name: return XML_NAME;
79// disabled(AddAttributeIdLegacy) case CCAFlags::ControlId: return "id";
85 case CCAFlags::For: return XML_FOR;
87 case CCAFlags::Label: return XML_LABEL;
92 case CCAFlags::Size: return XML_SIZE;
95 case CCAFlags::TargetLocation: return XML_HREF; // the only special thing here: TargetLocation is represented by an xlink:href attribute
97 case CCAFlags::Title: return XML_TITLE;
98 case CCAFlags::Value: return XML_VALUE;
101 default:
102 assert(false && "OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
103 }
104 return XML_UNKNOWN;
105 }
106
108 {
109 if (CCAFlags::TargetLocation == _nId)
110 return XML_NAMESPACE_XLINK;
111
112 if (CCAFlags::TargetFrame == _nId)
114
115 return XML_NAMESPACE_FORM;
116 }
117
119 {
120 switch (_eAttrib)
121 {
122 case faName: return "name";
123 case faAction: return "href"; // the only special thing here: Action is represented by an xlink:href attribute
124 case faEnctype: return "enctype";
125 case faMethod: return "method";
126 case faAllowDeletes: return "allow-deletes";
127 case faAllowInserts: return "allow-inserts";
128 case faAllowUpdates: return "allow-updates";
129 case faApplyFilter: return "apply-filter";
130 case faCommand: return "command";
131 case faCommandType: return "command-type";
132 case faEscapeProcessing: return "escape-processing";
133 case faDatasource: return "datasource";
134 case faDetailFields: return "detail-fields";
135 case faFilter: return "filter";
136 case faIgnoreResult: return "ignore-result";
137 case faMasterFields: return "master-fields";
138 case faNavigationMode: return "navigation-mode";
139 case faOrder: return "order";
140 case faTabbingCycle: return "tab-cycle";
141 default:
142 OSL_FAIL("OAttributeMetaData::getFormAttributeName: invalid id!");
143 }
144 return "";
145 }
146
148 {
149 switch (_eAttrib)
150 {
151 case faName: return XML_NAME;
152 case faAction: return XML_HREF; // the only special thing here: Action is represented by an xlink:href attribute
153 case faEnctype: return XML_ENCTYPE;
154 case faMethod: return XML_METHOD;
158 case faApplyFilter: return XML_APPLY_FILTER;
159 case faCommand: return XML_COMMAND;
160 case faCommandType: return XML_COMMAND_TYPE;
162 case faDatasource: return XML_DATASOURCE;
164 case faFilter: return XML_FILTER;
168 case faOrder: return XML_ORDER;
169 case faTabbingCycle: return XML_TAB_CYCLE;
170 default:
171 assert(false && "OAttributeMetaData::getFormAttributeName: invalid id!");
172 }
173 return XML_NONE;
174 }
175
177 {
178 if (faAction == _eAttrib)
179 return XML_NAMESPACE_XLINK;
180
181 return XML_NAMESPACE_FORM;
182 }
183
185 {
186 switch (_nId)
187 {
188 case DAFlags::BoundColumn: return "bound-column";
189 case DAFlags::ConvertEmpty: return "convert-empty-to-null";
190 case DAFlags::DataField: return "data-field";
191 case DAFlags::ListSource: return "list-source";
192 case DAFlags::ListSource_TYPE: return "list-source-type";
193 case DAFlags::InputRequired: return "input-required";
194 default:
195 OSL_FAIL("OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
196 }
197 return "";
198 }
199
201 {
202 switch (_nId)
203 {
210 default:
211 assert(false && "OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
212 }
213 return XML_NONE;
214 }
215
217 {
218 switch (_nId)
219 {
220 case BAFlags::LinkedCell: return "linked-cell";
221 case BAFlags::ListLinkingType: return "list-linkage-type";
222 case BAFlags::ListCellRange: return "source-cell-range";
223 default:
224 OSL_FAIL("OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
225 }
226 return "";
227 }
228
230 {
231 switch (_nId)
232 {
236 default:
237 assert(false && "OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
238 }
239 return XML_UNKNOWN;
240 }
241
243 {
244 switch (_nId)
245 {
246 case SCAFlags::EchoChar: return "echo-char";
247 case SCAFlags::MaxValue: return "max-value";
248 case SCAFlags::MinValue: return "min-value";
249 case SCAFlags::Validation: return "validation";
250 case SCAFlags::GroupName: return "group-name";
251 case SCAFlags::MultiLine: return "multi-line";
252 case SCAFlags::AutoCompletion: return "auto-complete";
253 case SCAFlags::Multiple: return "multiple";
254 case SCAFlags::DefaultButton: return "default-button";
255 case SCAFlags::CurrentState: return "current-state";
256 case SCAFlags::IsTristate: return "is-tristate";
257 case SCAFlags::State: return "state";
258 case SCAFlags::ColumnStyleName: return "text-style-name";
259 case SCAFlags::StepSize: return "step-size";
260 case SCAFlags::PageStepSize: return "page-step-size";
261 case SCAFlags::RepeatDelay: return "delay-for-repeat";
262 case SCAFlags::Toggle: return "toggle";
263 case SCAFlags::FocusOnClick: return "focus-on-click";
264 default:
265 OSL_FAIL("OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
266 }
267 return "";
268 }
269
271 {
272 switch (_nId)
273 {
281 case SCAFlags::Multiple: return XML_MULTIPLE;
285 case SCAFlags::State: return XML_STATE;
290 case SCAFlags::Toggle: return XML_TOGGLE;
292 default:
293 assert(false && "OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
294 }
295 return XML_UNKNOWN;
296 }
297
299 {
300 switch( _nId )
301 {
303 default: break;
304 }
305 return XML_NAMESPACE_FORM;
306 }
307
309 {
310 switch (_eAttrib)
311 {
312 case ofaAutomaticFocus: return "automatic-focus";
313 case ofaApplyDesignMode: return "apply-design-mode";
314 default:
315 OSL_FAIL("OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
316 }
317 return "";
318 }
319
321 {
322 switch (_eAttrib)
323 {
326 default:
327 assert(false && "OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
328 }
329 return token::XML_NONE;
330 }
331
332 //= OAttribute2Property
334 {
335 }
336
338 {
339 }
340
342 sal_Int32 nAttributeToken)
343 {
344 auto aPos = m_aKnownProperties.find(nAttributeToken & TOKEN_MASK);
345 if (m_aKnownProperties.end() != aPos)
346 return &aPos->second;
347 return nullptr;
348 }
349
351 sal_Int32 nAttributeToken, const OUString& _rPropertyName)
352 {
353 implAdd(nAttributeToken, _rPropertyName, ::cppu::UnoType<OUString>::get());
354 }
355
357 sal_Int32 nAttributeToken, const OUString& _rPropertyName,
358 const bool /*_bAttributeDefault*/, const bool _bInverseSemantics)
359 {
360 AttributeAssignment& aAssignment = implAdd(nAttributeToken, _rPropertyName, cppu::UnoType<bool>::get());
361 aAssignment.bInverseSemantics = _bInverseSemantics;
362 }
363
365 sal_Int32 nAttributeToken, const OUString& _rPropertyName)
366 {
367 implAdd(nAttributeToken, _rPropertyName, ::cppu::UnoType<sal_Int16>::get());
368 }
369
371 sal_Int32 nAttributeToken, const OUString& _rPropertyName)
372 {
373 implAdd( nAttributeToken, _rPropertyName, ::cppu::UnoType<sal_Int32>::get() );
374 }
375
377 sal_Int32 nAttributeToken, const OUString& _rPropertyName,
378 const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
379 const css::uno::Type* _pType)
380 {
381 AttributeAssignment& aAssignment = implAdd(nAttributeToken, _rPropertyName,
382 _pType ? *_pType : ::cppu::UnoType<sal_Int32>::get());
383 aAssignment.pEnumMap = _pValueMap;
384 }
385
387 sal_Int32 nAttributeToken, const OUString& _rPropertyName,
388 const css::uno::Type& _rType)
389 {
390 nAttributeToken &= TOKEN_MASK;
391 OSL_ENSURE(m_aKnownProperties.end() == m_aKnownProperties.find(nAttributeToken),
392 "OAttribute2Property::implAdd: already have this attribute!");
393
394 AttributeAssignment aAssignment;
395 aAssignment.sPropertyName = _rPropertyName;
396 aAssignment.aPropertyType = _rType;
397
398 // redundance, the accessor is stored in aAssignment.sAttributeName, too
399 m_aKnownProperties[nAttributeToken] = aAssignment;
400 return m_aKnownProperties[nAttributeToken];
401 }
402
403} // namespace xmloff
404
405/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void addInt16Property(sal_Int32 nAttributeToken, const OUString &_rPropertyName)
add an attribute assignment referring to an int16 property to the map
void addStringProperty(sal_Int32 nAttributeToken, const OUString &_rPropertyName)
add an attribute assignment referring to a string property to the map
AttributeAssignment & implAdd(sal_Int32 nAttributeToken, const OUString &_rPropertyName, const css::uno::Type &_rType)
some common code for the various add*Property methods
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
void addInt32Property(sal_Int32 nAttributeToken, const OUString &_rPropertyName)
add an attribute assignment referring to an int32 property to the map
std::map< sal_Int32, AttributeAssignment > m_aKnownProperties
void addEnumPropertyImpl(sal_Int32 nAttributeToken, const OUString &_rPropertyName, const SvXMLEnumMapEntry< sal_uInt16 > *_pValueMap, const css::uno::Type *_pType)
const AttributeAssignment * getAttributeTranslation(sal_Int32 nAttributeToken)
return the AttributeAssignment which corresponds to the given attribute
static OUString getBindingAttributeName(BAFlags _nId)
calculates the xml attribute representation of a binding attribute.
static OUString getFormAttributeName(FormAttributes _eAttrib)
retrieves the name of an attribute of a form xml representation
static sal_uInt16 getSpecialAttributeNamespace(SCAFlags _nId)
calculates the xml namespace key to use for a special attribute.
static OUString getSpecialAttributeName(SCAFlags _nId)
calculates the xml attribute representation of a special attribute.
static sal_uInt16 getFormAttributeNamespace(FormAttributes _eAttrib)
calculates the xml namespace key to use for an attribute of a form xml representation
static sal_Int32 getFormAttributeToken(FormAttributes _eAttrib)
retrieves the name of an attribute of a form xml representation
static xmloff::token::XMLTokenEnum getOfficeFormsAttributeToken(OfficeFormsAttributes _eAttrib)
static OUString getCommonControlAttributeName(CCAFlags _nId)
calculates the xml attribute representation of a common control attribute.
static sal_Int32 getCommonControlAttributeToken(CCAFlags _nId)
calculates the xml attribute representation of a common control attribute.
static OUString getDatabaseAttributeName(DAFlags _nId)
calculates the xml attribute representation of a database attribute.
static OUString getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib)
calculates the xml attribute representation of an attribute of the office:forms element
static sal_Int32 getDatabaseAttributeToken(DAFlags _nId)
calculates the xml attribute representation of a database attribute.
static sal_Int32 getSpecialAttributeToken(SCAFlags _nId)
calculates the xml attribute representation of a special attribute.
static sal_Int32 getBindingAttributeToken(BAFlags _nId)
calculates the xml attribute representation of a binding attribute.
static sal_uInt16 getCommonControlAttributeNamespace(CCAFlags _nId)
calculates the xml namespace key to use for a common control attribute
SCAFlags
@ ColumnStyleName
@ AutoCompletion
DAFlags
@ ListSource_TYPE
@ ConvertEmpty
@ InputRequired
BAFlags
@ ListLinkingType
@ ListCellRange
CCAFlags
@ TargetLocation
@ CurrentSelected
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
@ XML_DELAY_FOR_REPEAT
Definition: xmltoken.hxx:657
@ XML_APPLY_DESIGN_MODE
Definition: xmltoken.hxx:268
@ XML_CONVERT_EMPTY_TO_NULL
Definition: xmltoken.hxx:520
@ XML_CONTROL_IMPLEMENTATION
Definition: xmltoken.hxx:2748
@ ofaApplyDesignMode
FormAttributes
attributes in the xml tag representing a form
@ faEscapeProcessing
const SvXMLEnumMapEntry< sal_uInt16 > * pEnumMap
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:94
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_FORM
constexpr sal_uInt16 XML_NAMESPACE_FORMX
constexpr sal_uInt16 XML_NAMESPACE_OFFICE