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 <sax/tools/converter.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/xmluconv.hxx>
26 #include <rtl/ustrbuf.hxx>
27 #include <osl/diagnose.h>
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::beans
;
37 //= OAttributeMetaData
38 const sal_Char
* OAttributeMetaData::getCommonControlAttributeName(CCAFlags _nId
)
42 case CCAFlags::Name
: return "name";
43 case CCAFlags::ServiceName
: return "control-implementation";
44 case CCAFlags::ButtonType
: return "button-type";
45 // disabled(AddAttributeIdLegacy) case CCAFlags::ControlId: return "id";
46 case CCAFlags::CurrentSelected
: return "current-selected";
47 case CCAFlags::CurrentValue
: return "current-value";
48 case CCAFlags::Disabled
: return "disabled";
49 case CCAFlags::EnableVisible
: return "visible";
50 case CCAFlags::Dropdown
: return "dropdown";
51 case CCAFlags::For
: return "for";
52 case CCAFlags::ImageData
: return "image-data";
53 case CCAFlags::Label
: return "label";
54 case CCAFlags::MaxLength
: return "max-length";
55 case CCAFlags::Printable
: return "printable";
56 case CCAFlags::ReadOnly
: return "readonly";
57 case CCAFlags::Selected
: return "selected";
58 case CCAFlags::Size
: return "size";
59 case CCAFlags::TabIndex
: return "tab-index";
60 case CCAFlags::TargetFrame
: return "target-frame";
61 case CCAFlags::TargetLocation
: return "href"; // the only special thing here: TargetLocation is represented by an xlink:href attribute
62 case CCAFlags::TabStop
: return "tab-stop";
63 case CCAFlags::Title
: return "title";
64 case CCAFlags::Value
: return "value";
65 case CCAFlags::Orientation
: return "orientation";
66 case CCAFlags::VisualEffect
: return "visual-effect";
68 OSL_FAIL("OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
73 sal_uInt16
OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags _nId
)
75 if (CCAFlags::TargetLocation
== _nId
)
76 return XML_NAMESPACE_XLINK
;
78 if (CCAFlags::TargetFrame
== _nId
)
79 return XML_NAMESPACE_OFFICE
;
81 return XML_NAMESPACE_FORM
;
84 const sal_Char
* OAttributeMetaData::getFormAttributeName(FormAttributes _eAttrib
)
88 case faName
: return "name";
89 case faServiceName
: return "service-name";
90 case faAction
: return "href"; // the only special thing here: Action is represented by an xlink:href attribute
91 case faEnctype
: return "enctype";
92 case faMethod
: return "method";
93 case faTargetFrame
: return "target-frame";
94 case faAllowDeletes
: return "allow-deletes";
95 case faAllowInserts
: return "allow-inserts";
96 case faAllowUpdates
: return "allow-updates";
97 case faApplyFilter
: return "apply-filter";
98 case faCommand
: return "command";
99 case faCommandType
: return "command-type";
100 case faEscapeProcessing
: return "escape-processing";
101 case faDatasource
: return "datasource";
102 case faConnectionResource
: return "connection-resource";
103 case faDetailFiels
: return "detail-fields";
104 case faFilter
: return "filter";
105 case faIgnoreResult
: return "ignore-result";
106 case faMasterFields
: return "master-fields";
107 case faNavigationMode
: return "navigation-mode";
108 case faOrder
: return "order";
109 case faTabbingCycle
: return "tab-cycle";
111 OSL_FAIL("OAttributeMetaData::getFormAttributeName: invalid id!");
116 sal_uInt16
OAttributeMetaData::getFormAttributeNamespace(FormAttributes _eAttrib
)
118 if (faAction
== _eAttrib
)
119 return XML_NAMESPACE_XLINK
;
121 if (faTargetFrame
== _eAttrib
)
122 return XML_NAMESPACE_OFFICE
;
124 return XML_NAMESPACE_FORM
;
127 const sal_Char
* OAttributeMetaData::getDatabaseAttributeName(DAFlags _nId
)
131 case DAFlags::BoundColumn
: return "bound-column";
132 case DAFlags::ConvertEmpty
: return "convert-empty-to-null";
133 case DAFlags::DataField
: return "data-field";
134 case DAFlags::ListSource
: return "list-source";
135 case DAFlags::ListSource_TYPE
: return "list-source-type";
136 case DAFlags::InputRequired
: return "input-required";
138 OSL_FAIL("OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
143 const sal_Char
* OAttributeMetaData::getBindingAttributeName(BAFlags _nId
)
147 case BAFlags::LinkedCell
: return "linked-cell";
148 case BAFlags::ListLinkingType
: return "list-linkage-type";
149 case BAFlags::ListCellRange
: return "source-cell-range";
151 OSL_FAIL("OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
156 const sal_Char
* OAttributeMetaData::getSpecialAttributeName(SCAFlags _nId
)
160 case SCAFlags::EchoChar
: return "echo-char";
161 case SCAFlags::MaxValue
: return "max-value";
162 case SCAFlags::MinValue
: return "min-value";
163 case SCAFlags::Validation
: return "validation";
164 case SCAFlags::GroupName
: return "group-name";
165 case SCAFlags::MultiLine
: return "multi-line";
166 case SCAFlags::AutoCompletion
: return "auto-complete";
167 case SCAFlags::Multiple
: return "multiple";
168 case SCAFlags::DefaultButton
: return "default-button";
169 case SCAFlags::CurrentState
: return "current-state";
170 case SCAFlags::IsTristate
: return "is-tristate";
171 case SCAFlags::State
: return "state";
172 case SCAFlags::ColumnStyleName
: return "text-style-name";
173 case SCAFlags::StepSize
: return "step-size";
174 case SCAFlags::PageStepSize
: return "page-step-size";
175 case SCAFlags::RepeatDelay
: return "delay-for-repeat";
176 case SCAFlags::Toggle
: return "toggle";
177 case SCAFlags::FocusOnClick
: return "focus-on-click";
179 OSL_FAIL("OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
184 sal_uInt16
OAttributeMetaData::getSpecialAttributeNamespace(SCAFlags _nId
)
188 case SCAFlags::GroupName
: return XML_NAMESPACE_FORMX
;
191 return XML_NAMESPACE_FORM
;
194 const sal_Char
* OAttributeMetaData::getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib
)
198 case ofaAutomaticFocus
: return "automatic-focus";
199 case ofaApplyDesignMode
: return "apply-design-mode";
201 OSL_FAIL("OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
206 //= OAttribute2Property
207 OAttribute2Property::OAttribute2Property()
211 OAttribute2Property::~OAttribute2Property()
215 const OAttribute2Property::AttributeAssignment
* OAttribute2Property::getAttributeTranslation(
216 const OUString
& _rAttribName
)
218 AttributeAssignments::const_iterator aPos
= m_aKnownProperties
.find(_rAttribName
);
219 if (m_aKnownProperties
.end() != aPos
)
220 return &aPos
->second
;
224 void OAttribute2Property::addStringProperty(
225 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
226 const sal_Char
* _pAttributeDefault
)
228 implAdd(_pAttributeName
, _rPropertyName
, ::cppu::UnoType
<OUString
>::get(),
229 _pAttributeDefault
? OUString::createFromAscii(_pAttributeDefault
) : OUString());
232 void OAttribute2Property::addBooleanProperty(
233 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
234 const bool _bAttributeDefault
, const bool _bInverseSemantics
)
236 OUStringBuffer aDefault
;
237 ::sax::Converter::convertBool(aDefault
, _bAttributeDefault
);
238 AttributeAssignment
& aAssignment
= implAdd(_pAttributeName
, _rPropertyName
, cppu::UnoType
<bool>::get(), aDefault
.makeStringAndClear());
239 aAssignment
.bInverseSemantics
= _bInverseSemantics
;
242 void OAttribute2Property::addInt16Property(
243 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
244 const sal_Int16 _nAttributeDefault
)
246 OUStringBuffer aDefault
;
247 ::sax::Converter::convertNumber(aDefault
, (sal_Int32
)_nAttributeDefault
);
248 implAdd(_pAttributeName
, _rPropertyName
, ::cppu::UnoType
<sal_Int16
>::get(), aDefault
.makeStringAndClear());
251 void OAttribute2Property::addInt32Property(
252 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
253 const sal_Int32 _nAttributeDefault
)
255 OUStringBuffer aDefault
;
256 ::sax::Converter::convertNumber( aDefault
, _nAttributeDefault
);
257 implAdd( _pAttributeName
, _rPropertyName
, ::cppu::UnoType
<sal_Int32
>::get(), aDefault
.makeStringAndClear() );
260 void OAttribute2Property::addEnumProperty(
261 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
262 const sal_uInt16 _nAttributeDefault
, const SvXMLEnumMapEntry
* _pValueMap
,
263 const css::uno::Type
* _pType
)
265 OUStringBuffer aDefault
;
266 SvXMLUnitConverter::convertEnum(aDefault
, _nAttributeDefault
, _pValueMap
);
267 AttributeAssignment
& aAssignment
= implAdd(_pAttributeName
, _rPropertyName
,
268 _pType
? *_pType
: ::cppu::UnoType
<sal_Int32
>::get(),
269 // this assumes that the setPropertyValue for enums can handle int32's ....
270 aDefault
.makeStringAndClear());
271 aAssignment
.pEnumMap
= _pValueMap
;
274 OAttribute2Property::AttributeAssignment
& OAttribute2Property::implAdd(
275 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
276 const css::uno::Type
& _rType
, const OUString
& /*_rDefaultString*/)
278 OSL_ENSURE(m_aKnownProperties
.end() == m_aKnownProperties
.find(OUString::createFromAscii(_pAttributeName
)),
279 "OAttribute2Property::implAdd: already have this attribute!");
281 OUString sAttributeName
= OUString::createFromAscii(_pAttributeName
);
283 AttributeAssignment aAssignment
;
284 aAssignment
.sAttributeName
= sAttributeName
;
285 aAssignment
.sPropertyName
= _rPropertyName
;
286 aAssignment
.aPropertyType
= _rType
;
288 // redundance, the accessor is stored in aAssignment.sAttributeName, too
289 return m_aKnownProperties
[sAttributeName
] = aAssignment
;
292 } // namespace xmloff
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */