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 .
21 #include "formattributes.hxx"
23 #include <sax/tools/converter.hxx>
25 #include "xmloff/xmlnmspe.hxx"
26 #include <xmloff/xmluconv.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include <rtl/logfile.hxx>
29 //.........................................................................
32 //.........................................................................
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::lang
;
36 using namespace ::com::sun::star::beans
;
39 //=====================================================================
40 //= OAttributeMetaData
41 //=====================================================================
42 //---------------------------------------------------------------------
43 const sal_Char
* OAttributeMetaData::getCommonControlAttributeName(sal_Int32 _nId
)
47 case CCA_NAME
: return "name";
48 case CCA_SERVICE_NAME
: return "control-implementation";
49 case CCA_BUTTON_TYPE
: return "button-type";
50 // disabled(AddAttributeIdLegacy) case CCA_CONTROL_ID: return "id";
51 case CCA_CURRENT_SELECTED
: return "current-selected";
52 case CCA_CURRENT_VALUE
: return "current-value";
53 case CCA_DISABLED
: return "disabled";
54 case CCA_ENABLEVISIBLE
: return "visible";
55 case CCA_DROPDOWN
: return "dropdown";
56 case CCA_FOR
: return "for";
57 case CCA_IMAGE_DATA
: return "image-data";
58 case CCA_LABEL
: return "label";
59 case CCA_MAX_LENGTH
: return "max-length";
60 case CCA_PRINTABLE
: return "printable";
61 case CCA_READONLY
: return "readonly";
62 case CCA_SELECTED
: return "selected";
63 case CCA_SIZE
: return "size";
64 case CCA_TAB_INDEX
: return "tab-index";
65 case CCA_TARGET_FRAME
: return "target-frame";
66 case CCA_TARGET_LOCATION
: return "href"; // the only special thing here: TargetLocation is represented by an xlink:href attribute
67 case CCA_TAB_STOP
: return "tab-stop";
68 case CCA_TITLE
: return "title";
69 case CCA_VALUE
: return "value";
70 case CCA_ORIENTATION
: return "orientation";
71 case CCA_VISUAL_EFFECT
: return "visual-effect";
73 OSL_FAIL("OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
78 //---------------------------------------------------------------------
79 sal_uInt16
OAttributeMetaData::getCommonControlAttributeNamespace(sal_Int32 _nId
)
81 if (CCA_TARGET_LOCATION
== _nId
)
82 return XML_NAMESPACE_XLINK
;
84 if (CCA_TARGET_FRAME
== _nId
)
85 return XML_NAMESPACE_OFFICE
;
87 return XML_NAMESPACE_FORM
;
90 //---------------------------------------------------------------------
91 const sal_Char
* OAttributeMetaData::getFormAttributeName(FormAttributes _eAttrib
)
95 case faName
: return "name";
96 case faServiceName
: return "service-name";
97 case faAction
: return "href"; // the only special thing here: Action is represented by an xlink:href attribute
98 case faEnctype
: return "enctype";
99 case faMethod
: return "method";
100 case faTargetFrame
: return "target-frame";
101 case faAllowDeletes
: return "allow-deletes";
102 case faAllowInserts
: return "allow-inserts";
103 case faAllowUpdates
: return "allow-updates";
104 case faApplyFilter
: return "apply-filter";
105 case faCommand
: return "command";
106 case faCommandType
: return "command-type";
107 case faEscapeProcessing
: return "escape-processing";
108 case faDatasource
: return "datasource";
109 case faConnectionResource
: return "connection-resource";
110 case faDetailFiels
: return "detail-fields";
111 case faFilter
: return "filter";
112 case faIgnoreResult
: return "ignore-result";
113 case faMasterFields
: return "master-fields";
114 case faNavigationMode
: return "navigation-mode";
115 case faOrder
: return "order";
116 case faTabbingCycle
: return "tab-cycle";
118 OSL_FAIL("OAttributeMetaData::getFormAttributeName: invalid id!");
123 //---------------------------------------------------------------------
124 sal_uInt16
OAttributeMetaData::getFormAttributeNamespace(FormAttributes _eAttrib
)
126 if (faAction
== _eAttrib
)
127 return XML_NAMESPACE_XLINK
;
129 if (faTargetFrame
== _eAttrib
)
130 return XML_NAMESPACE_OFFICE
;
132 return XML_NAMESPACE_FORM
;
135 //---------------------------------------------------------------------
136 const sal_Char
* OAttributeMetaData::getDatabaseAttributeName(sal_Int32 _nId
)
140 case DA_BOUND_COLUMN
: return "bound-column";
141 case DA_CONVERT_EMPTY
: return "convert-empty-to-null";
142 case DA_DATA_FIELD
: return "data-field";
143 case DA_LIST_SOURCE
: return "list-source";
144 case DA_LIST_SOURCE_TYPE
: return "list-source-type";
145 case DA_INPUT_REQUIRED
: return "input-required";
147 OSL_FAIL("OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
152 //---------------------------------------------------------------------
153 sal_uInt16
OAttributeMetaData::getDatabaseAttributeNamespace(sal_Int32
/*_nId*/)
155 // nothing special here
156 return XML_NAMESPACE_FORM
;
159 //---------------------------------------------------------------------
160 const sal_Char
* OAttributeMetaData::getBindingAttributeName(sal_Int32 _nId
)
164 case BA_LINKED_CELL
: return "linked-cell";
165 case BA_LIST_LINKING_TYPE
: return "list-linkage-type";
166 case BA_LIST_CELL_RANGE
: return "source-cell-range";
168 OSL_FAIL("OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
173 //---------------------------------------------------------------------
174 sal_uInt16
OAttributeMetaData::getBindingAttributeNamespace(sal_Int32
)
176 // nothing special here
177 return XML_NAMESPACE_FORM
;
180 //---------------------------------------------------------------------
181 const sal_Char
* OAttributeMetaData::getSpecialAttributeName(sal_Int32 _nId
)
185 case SCA_ECHO_CHAR
: return "echo-char";
186 case SCA_MAX_VALUE
: return "max-value";
187 case SCA_MIN_VALUE
: return "min-value";
188 case SCA_VALIDATION
: return "validation";
189 case SCA_GROUP_NAME
: return "group-name";
190 case SCA_MULTI_LINE
: return "multi-line";
191 case SCA_AUTOMATIC_COMPLETION
: return "auto-complete";
192 case SCA_MULTIPLE
: return "multiple";
193 case SCA_DEFAULT_BUTTON
: return "default-button";
194 case SCA_CURRENT_STATE
: return "current-state";
195 case SCA_IS_TRISTATE
: return "is-tristate";
196 case SCA_STATE
: return "state";
197 case SCA_COLUMN_STYLE_NAME
: return "text-style-name";
198 case SCA_STEP_SIZE
: return "step-size";
199 case SCA_PAGE_STEP_SIZE
: return "page-step-size";
200 case SCA_REPEAT_DELAY
: return "delay-for-repeat";
201 case SCA_TOGGLE
: return "toggle";
202 case SCA_FOCUS_ON_CLICK
: return "focus-on-click";
204 OSL_FAIL("OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
209 //---------------------------------------------------------------------
210 sal_uInt16
OAttributeMetaData::getSpecialAttributeNamespace(sal_Int32 _nId
)
214 case SCA_GROUP_NAME
: return XML_NAMESPACE_FORMX
;
216 return XML_NAMESPACE_FORM
;
219 //---------------------------------------------------------------------
220 const sal_Char
* OAttributeMetaData::getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib
)
224 case ofaAutomaticFocus
: return "automatic-focus";
225 case ofaApplyDesignMode
: return "apply-design-mode";
227 OSL_FAIL("OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
232 //---------------------------------------------------------------------
233 sal_uInt16
OAttributeMetaData::getOfficeFormsAttributeNamespace(OfficeFormsAttributes
/* _eAttrib */)
235 // nothing special here
236 return XML_NAMESPACE_FORM
;
239 //=====================================================================
240 //= OAttribute2Property
241 //=====================================================================
242 //---------------------------------------------------------------------
243 OAttribute2Property::OAttribute2Property()
247 //---------------------------------------------------------------------
248 OAttribute2Property::~OAttribute2Property()
252 //---------------------------------------------------------------------
253 const OAttribute2Property::AttributeAssignment
* OAttribute2Property::getAttributeTranslation(
254 const OUString
& _rAttribName
)
256 ConstAttributeAssignmentsIterator aPos
= m_aKnownProperties
.find(_rAttribName
);
257 if (m_aKnownProperties
.end() != aPos
)
258 return &aPos
->second
;
262 //---------------------------------------------------------------------
263 void OAttribute2Property::addStringProperty(
264 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
265 const sal_Char
* _pAttributeDefault
)
267 implAdd(_pAttributeName
, _rPropertyName
, ::getCppuType( static_cast< OUString
* >(NULL
) ),
268 _pAttributeDefault
? OUString::createFromAscii(_pAttributeDefault
) : OUString());
271 //---------------------------------------------------------------------
272 void OAttribute2Property::addBooleanProperty(
273 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
274 const sal_Bool _bAttributeDefault
, const sal_Bool _bInverseSemantics
)
276 OUStringBuffer aDefault
;
277 ::sax::Converter::convertBool(aDefault
, _bAttributeDefault
);
278 AttributeAssignment
& aAssignment
= implAdd(_pAttributeName
, _rPropertyName
, ::getBooleanCppuType(), aDefault
.makeStringAndClear());
279 aAssignment
.bInverseSemantics
= _bInverseSemantics
;
282 //---------------------------------------------------------------------
283 void OAttribute2Property::addInt16Property(
284 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
285 const sal_Int16 _nAttributeDefault
)
287 OUStringBuffer aDefault
;
288 ::sax::Converter::convertNumber(aDefault
, (sal_Int32
)_nAttributeDefault
);
289 implAdd(_pAttributeName
, _rPropertyName
, ::getCppuType( static_cast< sal_Int16
* >(NULL
) ), aDefault
.makeStringAndClear());
292 //---------------------------------------------------------------------
293 void OAttribute2Property::addInt32Property(
294 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
295 const sal_Int32 _nAttributeDefault
)
297 OUStringBuffer aDefault
;
298 ::sax::Converter::convertNumber( aDefault
, _nAttributeDefault
);
299 implAdd( _pAttributeName
, _rPropertyName
, ::getCppuType( static_cast< sal_Int32
* >(NULL
) ), aDefault
.makeStringAndClear() );
302 //---------------------------------------------------------------------
303 void OAttribute2Property::addEnumProperty(
304 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
305 const sal_uInt16 _nAttributeDefault
, const SvXMLEnumMapEntry
* _pValueMap
,
306 const ::com::sun::star::uno::Type
* _pType
)
308 OUStringBuffer aDefault
;
309 SvXMLUnitConverter::convertEnum(aDefault
, _nAttributeDefault
, _pValueMap
);
310 AttributeAssignment
& aAssignment
= implAdd(_pAttributeName
, _rPropertyName
,
311 _pType
? *_pType
: ::getCppuType( static_cast< sal_Int32
* >(NULL
) ),
312 // this assumes that the setPropertyValue for enums can handle int32's ....
313 aDefault
.makeStringAndClear());
314 aAssignment
.pEnumMap
= _pValueMap
;
317 //---------------------------------------------------------------------
318 OAttribute2Property::AttributeAssignment
& OAttribute2Property::implAdd(
319 const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
,
320 const ::com::sun::star::uno::Type
& _rType
, const OUString
& /*_rDefaultString*/)
322 OSL_ENSURE(m_aKnownProperties
.end() == m_aKnownProperties
.find(OUString::createFromAscii(_pAttributeName
)),
323 "OAttribute2Property::implAdd: already have this attribute!");
325 OUString sAttributeName
= OUString::createFromAscii(_pAttributeName
);
327 AttributeAssignment aAssignment
;
328 aAssignment
.sAttributeName
= sAttributeName
;
329 aAssignment
.sPropertyName
= _rPropertyName
;
330 aAssignment
.aPropertyType
= _rType
;
332 // redundance, the accessor is stored in aAssignment.sAttributeName, too
333 return m_aKnownProperties
[sAttributeName
] = aAssignment
;
336 //.........................................................................
337 } // namespace xmloff
338 //.........................................................................
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */