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/xmluconv.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <osl/diagnose.h>
27 using namespace xmloff::token
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::lang
;
34 using namespace ::com::sun::star::beans
;
36 //= OAttributeMetaData
37 OUString
OAttributeMetaData::getCommonControlAttributeName(CCAFlags _nId
)
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";
67 OSL_FAIL("OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
72 sal_Int32
OAttributeMetaData::getCommonControlAttributeToken(CCAFlags _nId
)
76 case CCAFlags::Name
: return XML_NAME
;
77 case CCAFlags::ServiceName
: return XML_CONTROL_IMPLEMENTATION
;
78 case CCAFlags::ButtonType
: return XML_BUTTON_TYPE
;
79 // disabled(AddAttributeIdLegacy) case CCAFlags::ControlId: return "id";
80 case CCAFlags::CurrentSelected
: return XML_CURRENT_SELECTED
;
81 case CCAFlags::CurrentValue
: return XML_CURRENT_VALUE
;
82 case CCAFlags::Disabled
: return XML_DISABLED
;
83 case CCAFlags::EnableVisible
: return XML_VISIBLE
;
84 case CCAFlags::Dropdown
: return XML_DROPDOWN
;
85 case CCAFlags::For
: return XML_FOR
;
86 case CCAFlags::ImageData
: return XML_IMAGE_DATA
;
87 case CCAFlags::Label
: return XML_LABEL
;
88 case CCAFlags::MaxLength
: return XML_MAX_LENGTH
;
89 case CCAFlags::Printable
: return XML_PRINTABLE
;
90 case CCAFlags::ReadOnly
: return XML_READONLY
;
91 case CCAFlags::Selected
: return XML_SELECTED
;
92 case CCAFlags::Size
: return XML_SIZE
;
93 case CCAFlags::TabIndex
: return XML_TAB_INDEX
;
94 case CCAFlags::TargetFrame
: return XML_TARGET_FRAME
;
95 case CCAFlags::TargetLocation
: return XML_HREF
; // the only special thing here: TargetLocation is represented by an xlink:href attribute
96 case CCAFlags::TabStop
: return XML_TAB_STOP
;
97 case CCAFlags::Title
: return XML_TITLE
;
98 case CCAFlags::Value
: return XML_VALUE
;
99 case CCAFlags::Orientation
: return XML_ORIENTATION
;
100 case CCAFlags::VisualEffect
: return XML_VISUAL_EFFECT
;
102 assert(false && "OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
107 sal_uInt16
OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags _nId
)
109 if (CCAFlags::TargetLocation
== _nId
)
110 return XML_NAMESPACE_XLINK
;
112 if (CCAFlags::TargetFrame
== _nId
)
113 return XML_NAMESPACE_OFFICE
;
115 return XML_NAMESPACE_FORM
;
118 OUString
OAttributeMetaData::getFormAttributeName(FormAttributes _eAttrib
)
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";
142 OSL_FAIL("OAttributeMetaData::getFormAttributeName: invalid id!");
147 sal_Int32
OAttributeMetaData::getFormAttributeToken(FormAttributes _eAttrib
)
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
;
155 case faAllowDeletes
: return XML_ALLOW_DELETES
;
156 case faAllowInserts
: return XML_ALLOW_INSERTS
;
157 case faAllowUpdates
: return XML_ALLOW_UPDATES
;
158 case faApplyFilter
: return XML_APPLY_FILTER
;
159 case faCommand
: return XML_COMMAND
;
160 case faCommandType
: return XML_COMMAND_TYPE
;
161 case faEscapeProcessing
: return XML_ESCAPE_PROCESSING
;
162 case faDatasource
: return XML_DATASOURCE
;
163 case faDetailFields
: return XML_DETAIL_FIELDS
;
164 case faFilter
: return XML_FILTER
;
165 case faIgnoreResult
: return XML_IGNORE_RESULT
;
166 case faMasterFields
: return XML_MASTER_FIELDS
;
167 case faNavigationMode
: return XML_NAVIGATION_MODE
;
168 case faOrder
: return XML_ORDER
;
169 case faTabbingCycle
: return XML_TAB_CYCLE
;
171 assert(false && "OAttributeMetaData::getFormAttributeName: invalid id!");
176 sal_uInt16
OAttributeMetaData::getFormAttributeNamespace(FormAttributes _eAttrib
)
178 if (faAction
== _eAttrib
)
179 return XML_NAMESPACE_XLINK
;
181 return XML_NAMESPACE_FORM
;
184 OUString
OAttributeMetaData::getDatabaseAttributeName(DAFlags _nId
)
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";
195 OSL_FAIL("OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
200 sal_Int32
OAttributeMetaData::getDatabaseAttributeToken(DAFlags _nId
)
204 case DAFlags::BoundColumn
: return XML_BOUND_COLUMN
;
205 case DAFlags::ConvertEmpty
: return XML_CONVERT_EMPTY_TO_NULL
;
206 case DAFlags::DataField
: return XML_DATA_FIELD
;
207 case DAFlags::ListSource
: return XML_LIST_SOURCE
;
208 case DAFlags::ListSource_TYPE
: return XML_LIST_SOURCE_TYPE
;
209 case DAFlags::InputRequired
: return XML_INPUT_REQUIRED
;
211 assert(false && "OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
216 OUString
OAttributeMetaData::getBindingAttributeName(BAFlags _nId
)
220 case BAFlags::LinkedCell
: return "linked-cell";
221 case BAFlags::ListLinkingType
: return "list-linkage-type";
222 case BAFlags::ListCellRange
: return "source-cell-range";
224 OSL_FAIL("OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
229 sal_Int32
OAttributeMetaData::getBindingAttributeToken(BAFlags _nId
)
233 case BAFlags::LinkedCell
: return XML_LINKED_CELL
;
234 case BAFlags::ListLinkingType
: return XML_LIST_LINKAGE_TYPE
;
235 case BAFlags::ListCellRange
: return XML_SOURCE_CELL_RANGE
;
237 assert(false && "OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
242 OUString
OAttributeMetaData::getSpecialAttributeName(SCAFlags _nId
)
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";
265 OSL_FAIL("OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
270 sal_Int32
OAttributeMetaData::getSpecialAttributeToken(SCAFlags _nId
)
274 case SCAFlags::EchoChar
: return XML_ECHO_CHAR
;
275 case SCAFlags::MaxValue
: return XML_MAX_VALUE
;
276 case SCAFlags::MinValue
: return XML_MIN_VALUE
;
277 case SCAFlags::Validation
: return XML_VALIDATION
;
278 case SCAFlags::GroupName
: return XML_GROUP_NAME
;
279 case SCAFlags::MultiLine
: return XML_MULTI_LINE
;
280 case SCAFlags::AutoCompletion
: return XML_AUTO_COMPLETE
;
281 case SCAFlags::Multiple
: return XML_MULTIPLE
;
282 case SCAFlags::DefaultButton
: return XML_DEFAULT_BUTTON
;
283 case SCAFlags::CurrentState
: return XML_CURRENT_STATE
;
284 case SCAFlags::IsTristate
: return XML_IS_TRISTATE
;
285 case SCAFlags::State
: return XML_STATE
;
286 case SCAFlags::ColumnStyleName
: return XML_TEXT_STYLE_NAME
;
287 case SCAFlags::StepSize
: return XML_STEP_SIZE
;
288 case SCAFlags::PageStepSize
: return XML_PAGE_STEP_SIZE
;
289 case SCAFlags::RepeatDelay
: return XML_DELAY_FOR_REPEAT
;
290 case SCAFlags::Toggle
: return XML_TOGGLE
;
291 case SCAFlags::FocusOnClick
: return XML_FOCUS_ON_CLICK
;
293 assert(false && "OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
298 sal_uInt16
OAttributeMetaData::getSpecialAttributeNamespace(SCAFlags _nId
)
302 case SCAFlags::GroupName
: return XML_NAMESPACE_FORMX
;
305 return XML_NAMESPACE_FORM
;
308 OUString
OAttributeMetaData::getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib
)
312 case ofaAutomaticFocus
: return "automatic-focus";
313 case ofaApplyDesignMode
: return "apply-design-mode";
315 OSL_FAIL("OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
320 xmloff::token::XMLTokenEnum
OAttributeMetaData::getOfficeFormsAttributeToken(OfficeFormsAttributes _eAttrib
)
324 case ofaAutomaticFocus
: return token::XML_AUTOMATIC_FOCUS
;
325 case ofaApplyDesignMode
: return token::XML_APPLY_DESIGN_MODE
;
327 assert(false && "OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
329 return token::XML_NONE
;
332 //= OAttribute2Property
333 OAttribute2Property::OAttribute2Property()
337 OAttribute2Property::~OAttribute2Property()
341 const OAttribute2Property::AttributeAssignment
* OAttribute2Property::getAttributeTranslation(
342 sal_Int32 nAttributeToken
)
344 auto aPos
= m_aKnownProperties
.find(nAttributeToken
& TOKEN_MASK
);
345 if (m_aKnownProperties
.end() != aPos
)
346 return &aPos
->second
;
350 void OAttribute2Property::addStringProperty(
351 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
)
353 implAdd(nAttributeToken
, _rPropertyName
, ::cppu::UnoType
<OUString
>::get());
356 void OAttribute2Property::addBooleanProperty(
357 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
,
358 const bool /*_bAttributeDefault*/, const bool _bInverseSemantics
)
360 AttributeAssignment
& aAssignment
= implAdd(nAttributeToken
, _rPropertyName
, cppu::UnoType
<bool>::get());
361 aAssignment
.bInverseSemantics
= _bInverseSemantics
;
364 void OAttribute2Property::addInt16Property(
365 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
)
367 implAdd(nAttributeToken
, _rPropertyName
, ::cppu::UnoType
<sal_Int16
>::get());
370 void OAttribute2Property::addInt32Property(
371 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
)
373 implAdd( nAttributeToken
, _rPropertyName
, ::cppu::UnoType
<sal_Int32
>::get() );
376 void OAttribute2Property::addEnumPropertyImpl(
377 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
,
378 const SvXMLEnumMapEntry
<sal_uInt16
>* _pValueMap
,
379 const css::uno::Type
* _pType
)
381 AttributeAssignment
& aAssignment
= implAdd(nAttributeToken
, _rPropertyName
,
382 _pType
? *_pType
: ::cppu::UnoType
<sal_Int32
>::get());
383 aAssignment
.pEnumMap
= _pValueMap
;
386 OAttribute2Property::AttributeAssignment
& OAttribute2Property::implAdd(
387 sal_Int32 nAttributeToken
, const OUString
& _rPropertyName
,
388 const css::uno::Type
& _rType
)
390 nAttributeToken
&= TOKEN_MASK
;
391 OSL_ENSURE(m_aKnownProperties
.end() == m_aKnownProperties
.find(nAttributeToken
),
392 "OAttribute2Property::implAdd: already have this attribute!");
394 AttributeAssignment aAssignment
;
395 aAssignment
.sPropertyName
= _rPropertyName
;
396 aAssignment
.aPropertyType
= _rType
;
398 // redundance, the accessor is stored in aAssignment.sAttributeName, too
399 m_aKnownProperties
[nAttributeToken
] = aAssignment
;
400 return m_aKnownProperties
[nAttributeToken
];
403 } // namespace xmloff
405 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */