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 .
20 #include "formattributes.hxx"
22 #include <xmloff/xmlnamespace.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <osl/diagnose.h>
26 using namespace xmloff::token
;
31 using namespace ::com::sun::star::uno
;
33 //= OAttributeMetaData
34 OUString
OAttributeMetaData::getCommonControlAttributeName(CCAFlags _nId
)
38 case CCAFlags::Name
: return u
"name"_ustr
;
39 case CCAFlags::ServiceName
: return u
"control-implementation"_ustr
;
40 case CCAFlags::ButtonType
: return u
"button-type"_ustr
;
41 // disabled(AddAttributeIdLegacy) case CCAFlags::ControlId: return "id";
42 case CCAFlags::CurrentSelected
: return u
"current-selected"_ustr
;
43 case CCAFlags::CurrentValue
: return u
"current-value"_ustr
;
44 case CCAFlags::Disabled
: return u
"disabled"_ustr
;
45 case CCAFlags::EnableVisible
: return u
"visible"_ustr
;
46 case CCAFlags::Dropdown
: return u
"dropdown"_ustr
;
47 case CCAFlags::For
: return u
"for"_ustr
;
48 case CCAFlags::ImageData
: return u
"image-data"_ustr
;
49 case CCAFlags::Label
: return u
"label"_ustr
;
50 case CCAFlags::MaxLength
: return u
"max-length"_ustr
;
51 case CCAFlags::Printable
: return u
"printable"_ustr
;
52 case CCAFlags::ReadOnly
: return u
"readonly"_ustr
;
53 case CCAFlags::Selected
: return u
"selected"_ustr
;
54 case CCAFlags::Size
: return u
"size"_ustr
;
55 case CCAFlags::TabIndex
: return u
"tab-index"_ustr
;
56 case CCAFlags::TargetFrame
: return u
"target-frame"_ustr
;
57 case CCAFlags::TargetLocation
: return u
"href"_ustr
; // the only special thing here: TargetLocation is represented by an xlink:href attribute
58 case CCAFlags::TabStop
: return u
"tab-stop"_ustr
;
59 case CCAFlags::Title
: return u
"title"_ustr
;
60 case CCAFlags::Value
: return u
"value"_ustr
;
61 case CCAFlags::Orientation
: return u
"orientation"_ustr
;
62 case CCAFlags::VisualEffect
: return u
"visual-effect"_ustr
;
64 OSL_FAIL("OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
69 sal_Int32
OAttributeMetaData::getCommonControlAttributeToken(CCAFlags _nId
)
73 case CCAFlags::Name
: return XML_NAME
;
74 case CCAFlags::ServiceName
: return XML_CONTROL_IMPLEMENTATION
;
75 case CCAFlags::ButtonType
: return XML_BUTTON_TYPE
;
76 // disabled(AddAttributeIdLegacy) case CCAFlags::ControlId: return "id";
77 case CCAFlags::CurrentSelected
: return XML_CURRENT_SELECTED
;
78 case CCAFlags::CurrentValue
: return XML_CURRENT_VALUE
;
79 case CCAFlags::Disabled
: return XML_DISABLED
;
80 case CCAFlags::EnableVisible
: return XML_VISIBLE
;
81 case CCAFlags::Dropdown
: return XML_DROPDOWN
;
82 case CCAFlags::For
: return XML_FOR
;
83 case CCAFlags::ImageData
: return XML_IMAGE_DATA
;
84 case CCAFlags::Label
: return XML_LABEL
;
85 case CCAFlags::MaxLength
: return XML_MAX_LENGTH
;
86 case CCAFlags::Printable
: return XML_PRINTABLE
;
87 case CCAFlags::ReadOnly
: return XML_READONLY
;
88 case CCAFlags::Selected
: return XML_SELECTED
;
89 case CCAFlags::Size
: return XML_SIZE
;
90 case CCAFlags::TabIndex
: return XML_TAB_INDEX
;
91 case CCAFlags::TargetFrame
: return XML_TARGET_FRAME
;
92 case CCAFlags::TargetLocation
: return XML_HREF
; // the only special thing here: TargetLocation is represented by an xlink:href attribute
93 case CCAFlags::TabStop
: return XML_TAB_STOP
;
94 case CCAFlags::Title
: return XML_TITLE
;
95 case CCAFlags::Value
: return XML_VALUE
;
96 case CCAFlags::Orientation
: return XML_ORIENTATION
;
97 case CCAFlags::VisualEffect
: return XML_VISUAL_EFFECT
;
99 assert(false && "OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
104 sal_uInt16
OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags _nId
)
106 if (CCAFlags::TargetLocation
== _nId
)
107 return XML_NAMESPACE_XLINK
;
109 if (CCAFlags::TargetFrame
== _nId
)
110 return XML_NAMESPACE_OFFICE
;
112 return XML_NAMESPACE_FORM
;
115 OUString
OAttributeMetaData::getFormAttributeName(FormAttributes _eAttrib
)
119 case faName
: return u
"name"_ustr
;
120 case faAction
: return u
"href"_ustr
; // the only special thing here: Action is represented by an xlink:href attribute
121 case faEnctype
: return u
"enctype"_ustr
;
122 case faMethod
: return u
"method"_ustr
;
123 case faAllowDeletes
: return u
"allow-deletes"_ustr
;
124 case faAllowInserts
: return u
"allow-inserts"_ustr
;
125 case faAllowUpdates
: return u
"allow-updates"_ustr
;
126 case faApplyFilter
: return u
"apply-filter"_ustr
;
127 case faCommand
: return u
"command"_ustr
;
128 case faCommandType
: return u
"command-type"_ustr
;
129 case faEscapeProcessing
: return u
"escape-processing"_ustr
;
130 case faDatasource
: return u
"datasource"_ustr
;
131 case faDetailFields
: return u
"detail-fields"_ustr
;
132 case faFilter
: return u
"filter"_ustr
;
133 case faIgnoreResult
: return u
"ignore-result"_ustr
;
134 case faMasterFields
: return u
"master-fields"_ustr
;
135 case faNavigationMode
: return u
"navigation-mode"_ustr
;
136 case faOrder
: return u
"order"_ustr
;
137 case faTabbingCycle
: return u
"tab-cycle"_ustr
;
139 OSL_FAIL("OAttributeMetaData::getFormAttributeName: invalid id!");
144 sal_Int32
OAttributeMetaData::getFormAttributeToken(FormAttributes _eAttrib
)
148 case faName
: return XML_NAME
;
149 case faAction
: return XML_HREF
; // the only special thing here: Action is represented by an xlink:href attribute
150 case faEnctype
: return XML_ENCTYPE
;
151 case faMethod
: return XML_METHOD
;
152 case faAllowDeletes
: return XML_ALLOW_DELETES
;
153 case faAllowInserts
: return XML_ALLOW_INSERTS
;
154 case faAllowUpdates
: return XML_ALLOW_UPDATES
;
155 case faApplyFilter
: return XML_APPLY_FILTER
;
156 case faCommand
: return XML_COMMAND
;
157 case faCommandType
: return XML_COMMAND_TYPE
;
158 case faEscapeProcessing
: return XML_ESCAPE_PROCESSING
;
159 case faDatasource
: return XML_DATASOURCE
;
160 case faDetailFields
: return XML_DETAIL_FIELDS
;
161 case faFilter
: return XML_FILTER
;
162 case faIgnoreResult
: return XML_IGNORE_RESULT
;
163 case faMasterFields
: return XML_MASTER_FIELDS
;
164 case faNavigationMode
: return XML_NAVIGATION_MODE
;
165 case faOrder
: return XML_ORDER
;
166 case faTabbingCycle
: return XML_TAB_CYCLE
;
168 assert(false && "OAttributeMetaData::getFormAttributeName: invalid id!");
173 sal_uInt16
OAttributeMetaData::getFormAttributeNamespace(FormAttributes _eAttrib
)
175 if (faAction
== _eAttrib
)
176 return XML_NAMESPACE_XLINK
;
178 return XML_NAMESPACE_FORM
;
181 OUString
OAttributeMetaData::getDatabaseAttributeName(DAFlags _nId
)
185 case DAFlags::BoundColumn
: return u
"bound-column"_ustr
;
186 case DAFlags::ConvertEmpty
: return u
"convert-empty-to-null"_ustr
;
187 case DAFlags::DataField
: return u
"data-field"_ustr
;
188 case DAFlags::ListSource
: return u
"list-source"_ustr
;
189 case DAFlags::ListSource_TYPE
: return u
"list-source-type"_ustr
;
190 case DAFlags::InputRequired
: return u
"input-required"_ustr
;
192 OSL_FAIL("OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
197 sal_Int32
OAttributeMetaData::getDatabaseAttributeToken(DAFlags _nId
)
201 case DAFlags::BoundColumn
: return XML_BOUND_COLUMN
;
202 case DAFlags::ConvertEmpty
: return XML_CONVERT_EMPTY_TO_NULL
;
203 case DAFlags::DataField
: return XML_DATA_FIELD
;
204 case DAFlags::ListSource
: return XML_LIST_SOURCE
;
205 case DAFlags::ListSource_TYPE
: return XML_LIST_SOURCE_TYPE
;
206 case DAFlags::InputRequired
: return XML_INPUT_REQUIRED
;
208 assert(false && "OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
213 OUString
OAttributeMetaData::getBindingAttributeName(BAFlags _nId
)
217 case BAFlags::LinkedCell
: return u
"linked-cell"_ustr
;
218 case BAFlags::ListLinkingType
: return u
"list-linkage-type"_ustr
;
219 case BAFlags::ListCellRange
: return u
"source-cell-range"_ustr
;
221 OSL_FAIL("OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
226 sal_Int32
OAttributeMetaData::getBindingAttributeToken(BAFlags _nId
)
230 case BAFlags::LinkedCell
: return XML_LINKED_CELL
;
231 case BAFlags::ListLinkingType
: return XML_LIST_LINKAGE_TYPE
;
232 case BAFlags::ListCellRange
: return XML_SOURCE_CELL_RANGE
;
234 assert(false && "OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
239 OUString
OAttributeMetaData::getSpecialAttributeName(SCAFlags _nId
)
243 case SCAFlags::EchoChar
: return u
"echo-char"_ustr
;
244 case SCAFlags::MaxValue
: return u
"max-value"_ustr
;
245 case SCAFlags::MinValue
: return u
"min-value"_ustr
;
246 case SCAFlags::Validation
: return u
"validation"_ustr
;
247 case SCAFlags::GroupName
: return u
"group-name"_ustr
;
248 case SCAFlags::MultiLine
: return u
"multi-line"_ustr
;
249 case SCAFlags::AutoCompletion
: return u
"auto-complete"_ustr
;
250 case SCAFlags::Multiple
: return u
"multiple"_ustr
;
251 case SCAFlags::DefaultButton
: return u
"default-button"_ustr
;
252 case SCAFlags::CurrentState
: return u
"current-state"_ustr
;
253 case SCAFlags::IsTristate
: return u
"is-tristate"_ustr
;
254 case SCAFlags::State
: return u
"state"_ustr
;
255 case SCAFlags::ColumnStyleName
: return u
"text-style-name"_ustr
;
256 case SCAFlags::StepSize
: return u
"step-size"_ustr
;
257 case SCAFlags::PageStepSize
: return u
"page-step-size"_ustr
;
258 case SCAFlags::RepeatDelay
: return u
"delay-for-repeat"_ustr
;
259 case SCAFlags::Toggle
: return u
"toggle"_ustr
;
260 case SCAFlags::FocusOnClick
: return u
"focus-on-click"_ustr
;
262 OSL_FAIL("OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
267 sal_Int32
OAttributeMetaData::getSpecialAttributeToken(SCAFlags _nId
)
271 case SCAFlags::EchoChar
: return XML_ECHO_CHAR
;
272 case SCAFlags::MaxValue
: return XML_MAX_VALUE
;
273 case SCAFlags::MinValue
: return XML_MIN_VALUE
;
274 case SCAFlags::Validation
: return XML_VALIDATION
;
275 case SCAFlags::GroupName
: return XML_GROUP_NAME
;
276 case SCAFlags::MultiLine
: return XML_MULTI_LINE
;
277 case SCAFlags::AutoCompletion
: return XML_AUTO_COMPLETE
;
278 case SCAFlags::Multiple
: return XML_MULTIPLE
;
279 case SCAFlags::DefaultButton
: return XML_DEFAULT_BUTTON
;
280 case SCAFlags::CurrentState
: return XML_CURRENT_STATE
;
281 case SCAFlags::IsTristate
: return XML_IS_TRISTATE
;
282 case SCAFlags::State
: return XML_STATE
;
283 case SCAFlags::ColumnStyleName
: return XML_TEXT_STYLE_NAME
;
284 case SCAFlags::StepSize
: return XML_STEP_SIZE
;
285 case SCAFlags::PageStepSize
: return XML_PAGE_STEP_SIZE
;
286 case SCAFlags::RepeatDelay
: return XML_DELAY_FOR_REPEAT
;
287 case SCAFlags::Toggle
: return XML_TOGGLE
;
288 case SCAFlags::FocusOnClick
: return XML_FOCUS_ON_CLICK
;
290 assert(false && "OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
295 sal_uInt16
OAttributeMetaData::getSpecialAttributeNamespace(SCAFlags _nId
)
299 case SCAFlags::GroupName
: return XML_NAMESPACE_FORMX
;
302 return XML_NAMESPACE_FORM
;
305 OUString
OAttributeMetaData::getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib
)
309 case ofaAutomaticFocus
: return u
"automatic-focus"_ustr
;
310 case ofaApplyDesignMode
: return u
"apply-design-mode"_ustr
;
312 OSL_FAIL("OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
317 xmloff::token::XMLTokenEnum
OAttributeMetaData::getOfficeFormsAttributeToken(OfficeFormsAttributes _eAttrib
)
321 case ofaAutomaticFocus
: return token::XML_AUTOMATIC_FOCUS
;
322 case ofaApplyDesignMode
: return token::XML_APPLY_DESIGN_MODE
;
324 assert(false && "OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
326 return token::XML_NONE
;
329 //= OAttribute2Property
330 OAttribute2Property::OAttribute2Property()
334 OAttribute2Property::~OAttribute2Property()
338 const OAttribute2Property::AttributeAssignment
* OAttribute2Property::getAttributeTranslation(
339 sal_Int32 nAttributeToken
)
341 auto aPos
= m_aKnownProperties
.find(nAttributeToken
& TOKEN_MASK
);
342 if (m_aKnownProperties
.end() != aPos
)
343 return &aPos
->second
;
347 void OAttribute2Property::addStringProperty(
348 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
)
350 implAdd(nAttributeToken
, _rPropertyName
, ::cppu::UnoType
<OUString
>::get());
353 void OAttribute2Property::addBooleanProperty(
354 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
,
355 const bool /*_bAttributeDefault*/, const bool _bInverseSemantics
)
357 AttributeAssignment
& aAssignment
= implAdd(nAttributeToken
, _rPropertyName
, cppu::UnoType
<bool>::get());
358 aAssignment
.bInverseSemantics
= _bInverseSemantics
;
361 void OAttribute2Property::addInt16Property(
362 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
)
364 implAdd(nAttributeToken
, _rPropertyName
, ::cppu::UnoType
<sal_Int16
>::get());
367 void OAttribute2Property::addInt32Property(
368 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
)
370 implAdd( nAttributeToken
, _rPropertyName
, ::cppu::UnoType
<sal_Int32
>::get() );
373 void OAttribute2Property::addEnumPropertyImpl(
374 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
,
375 const SvXMLEnumMapEntry
<sal_uInt16
>* _pValueMap
,
376 const css::uno::Type
* _pType
)
378 AttributeAssignment
& aAssignment
= implAdd(nAttributeToken
, _rPropertyName
,
379 _pType
? *_pType
: ::cppu::UnoType
<sal_Int32
>::get());
380 aAssignment
.pEnumMap
= _pValueMap
;
383 OAttribute2Property::AttributeAssignment
& OAttribute2Property::implAdd(
384 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
,
385 const css::uno::Type
& _rType
)
387 nAttributeToken
&= TOKEN_MASK
;
388 OSL_ENSURE(m_aKnownProperties
.end() == m_aKnownProperties
.find(nAttributeToken
),
389 "OAttribute2Property::implAdd: already have this attribute!");
391 AttributeAssignment aAssignment
;
392 aAssignment
.sPropertyName
= _rPropertyName
;
393 aAssignment
.aPropertyType
= _rType
;
395 // redundance, the accessor is stored in aAssignment.sAttributeName, too
396 m_aKnownProperties
[nAttributeToken
] = std::move(aAssignment
);
397 return m_aKnownProperties
[nAttributeToken
];
400 } // namespace xmloff
402 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */