bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / forms / formattributes.cxx
blobe63d89c6d2dcca5b1ece28ecd8f4aab331bf1fe8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
30 namespace xmloff
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(sal_Int32 _nId)
40 switch (_nId)
42 case CCA_NAME: return "name";
43 case CCA_SERVICE_NAME: return "control-implementation";
44 case CCA_BUTTON_TYPE: return "button-type";
45 // disabled(AddAttributeIdLegacy) case CCA_CONTROL_ID: return "id";
46 case CCA_CURRENT_SELECTED: return "current-selected";
47 case CCA_CURRENT_VALUE: return "current-value";
48 case CCA_DISABLED: return "disabled";
49 case CCA_ENABLEVISIBLE: return "visible";
50 case CCA_DROPDOWN: return "dropdown";
51 case CCA_FOR: return "for";
52 case CCA_IMAGE_DATA: return "image-data";
53 case CCA_LABEL: return "label";
54 case CCA_MAX_LENGTH: return "max-length";
55 case CCA_PRINTABLE: return "printable";
56 case CCA_READONLY: return "readonly";
57 case CCA_SELECTED: return "selected";
58 case CCA_SIZE: return "size";
59 case CCA_TAB_INDEX: return "tab-index";
60 case CCA_TARGET_FRAME: return "target-frame";
61 case CCA_TARGET_LOCATION: return "href"; // the only special thing here: TargetLocation is represented by an xlink:href attribute
62 case CCA_TAB_STOP: return "tab-stop";
63 case CCA_TITLE: return "title";
64 case CCA_VALUE: return "value";
65 case CCA_ORIENTATION: return "orientation";
66 case CCA_VISUAL_EFFECT: return "visual-effect";
67 default:
68 OSL_FAIL("OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
70 return "";
73 sal_uInt16 OAttributeMetaData::getCommonControlAttributeNamespace(sal_Int32 _nId)
75 if (CCA_TARGET_LOCATION == _nId)
76 return XML_NAMESPACE_XLINK;
78 if (CCA_TARGET_FRAME == _nId)
79 return XML_NAMESPACE_OFFICE;
81 return XML_NAMESPACE_FORM;
84 const sal_Char* OAttributeMetaData::getFormAttributeName(FormAttributes _eAttrib)
86 switch (_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";
110 default:
111 OSL_FAIL("OAttributeMetaData::getFormAttributeName: invalid id!");
113 return "";
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(sal_Int32 _nId)
129 switch (_nId)
131 case DA_BOUND_COLUMN: return "bound-column";
132 case DA_CONVERT_EMPTY: return "convert-empty-to-null";
133 case DA_DATA_FIELD: return "data-field";
134 case DA_LIST_SOURCE: return "list-source";
135 case DA_LIST_SOURCE_TYPE: return "list-source-type";
136 case DA_INPUT_REQUIRED: return "input-required";
137 default:
138 OSL_FAIL("OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
140 return "";
143 const sal_Char* OAttributeMetaData::getBindingAttributeName(sal_Int32 _nId)
145 switch (_nId)
147 case BA_LINKED_CELL: return "linked-cell";
148 case BA_LIST_LINKING_TYPE: return "list-linkage-type";
149 case BA_LIST_CELL_RANGE: return "source-cell-range";
150 default:
151 OSL_FAIL("OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
153 return "";
156 const sal_Char* OAttributeMetaData::getSpecialAttributeName(sal_Int32 _nId)
158 switch (_nId)
160 case SCA_ECHO_CHAR: return "echo-char";
161 case SCA_MAX_VALUE: return "max-value";
162 case SCA_MIN_VALUE: return "min-value";
163 case SCA_VALIDATION: return "validation";
164 case SCA_GROUP_NAME: return "group-name";
165 case SCA_MULTI_LINE: return "multi-line";
166 case SCA_AUTOMATIC_COMPLETION: return "auto-complete";
167 case SCA_MULTIPLE: return "multiple";
168 case SCA_DEFAULT_BUTTON: return "default-button";
169 case SCA_CURRENT_STATE: return "current-state";
170 case SCA_IS_TRISTATE: return "is-tristate";
171 case SCA_STATE: return "state";
172 case SCA_COLUMN_STYLE_NAME: return "text-style-name";
173 case SCA_STEP_SIZE: return "step-size";
174 case SCA_PAGE_STEP_SIZE: return "page-step-size";
175 case SCA_REPEAT_DELAY: return "delay-for-repeat";
176 case SCA_TOGGLE: return "toggle";
177 case SCA_FOCUS_ON_CLICK: return "focus-on-click";
178 default:
179 OSL_FAIL("OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
181 return "";
184 sal_uInt16 OAttributeMetaData::getSpecialAttributeNamespace(sal_Int32 _nId)
186 switch( _nId )
188 case SCA_GROUP_NAME: return XML_NAMESPACE_FORMX;
190 return XML_NAMESPACE_FORM;
193 const sal_Char* OAttributeMetaData::getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib)
195 switch (_eAttrib)
197 case ofaAutomaticFocus: return "automatic-focus";
198 case ofaApplyDesignMode: return "apply-design-mode";
199 default:
200 OSL_FAIL("OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
202 return "";
205 //= OAttribute2Property
206 OAttribute2Property::OAttribute2Property()
210 OAttribute2Property::~OAttribute2Property()
214 const OAttribute2Property::AttributeAssignment* OAttribute2Property::getAttributeTranslation(
215 const OUString& _rAttribName)
217 AttributeAssignments::const_iterator aPos = m_aKnownProperties.find(_rAttribName);
218 if (m_aKnownProperties.end() != aPos)
219 return &aPos->second;
220 return NULL;
223 void OAttribute2Property::addStringProperty(
224 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
225 const sal_Char* _pAttributeDefault)
227 implAdd(_pAttributeName, _rPropertyName, ::cppu::UnoType<OUString>::get(),
228 _pAttributeDefault ? OUString::createFromAscii(_pAttributeDefault) : OUString());
231 void OAttribute2Property::addBooleanProperty(
232 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
233 const bool _bAttributeDefault, const bool _bInverseSemantics)
235 OUStringBuffer aDefault;
236 ::sax::Converter::convertBool(aDefault, _bAttributeDefault);
237 AttributeAssignment& aAssignment = implAdd(_pAttributeName, _rPropertyName, cppu::UnoType<bool>::get(), aDefault.makeStringAndClear());
238 aAssignment.bInverseSemantics = _bInverseSemantics;
241 void OAttribute2Property::addInt16Property(
242 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
243 const sal_Int16 _nAttributeDefault)
245 OUStringBuffer aDefault;
246 ::sax::Converter::convertNumber(aDefault, (sal_Int32)_nAttributeDefault);
247 implAdd(_pAttributeName, _rPropertyName, ::cppu::UnoType<sal_Int16>::get(), aDefault.makeStringAndClear());
250 void OAttribute2Property::addInt32Property(
251 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
252 const sal_Int32 _nAttributeDefault)
254 OUStringBuffer aDefault;
255 ::sax::Converter::convertNumber( aDefault, _nAttributeDefault );
256 implAdd( _pAttributeName, _rPropertyName, ::cppu::UnoType<sal_Int32>::get(), aDefault.makeStringAndClear() );
259 void OAttribute2Property::addEnumProperty(
260 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
261 const sal_uInt16 _nAttributeDefault, const SvXMLEnumMapEntry* _pValueMap,
262 const ::com::sun::star::uno::Type* _pType)
264 OUStringBuffer aDefault;
265 SvXMLUnitConverter::convertEnum(aDefault, _nAttributeDefault, _pValueMap);
266 AttributeAssignment& aAssignment = implAdd(_pAttributeName, _rPropertyName,
267 _pType ? *_pType : ::cppu::UnoType<sal_Int32>::get(),
268 // this assumes that the setPropertyValue for enums can handle int32's ....
269 aDefault.makeStringAndClear());
270 aAssignment.pEnumMap = _pValueMap;
273 OAttribute2Property::AttributeAssignment& OAttribute2Property::implAdd(
274 const sal_Char* _pAttributeName, const OUString& _rPropertyName,
275 const ::com::sun::star::uno::Type& _rType, const OUString& /*_rDefaultString*/)
277 OSL_ENSURE(m_aKnownProperties.end() == m_aKnownProperties.find(OUString::createFromAscii(_pAttributeName)),
278 "OAttribute2Property::implAdd: already have this attribute!");
280 OUString sAttributeName = OUString::createFromAscii(_pAttributeName);
282 AttributeAssignment aAssignment;
283 aAssignment.sAttributeName = sAttributeName;
284 aAssignment.sPropertyName = _rPropertyName;
285 aAssignment.aPropertyType = _rType;
287 // redundance, the accessor is stored in aAssignment.sAttributeName, too
288 return m_aKnownProperties[sAttributeName] = aAssignment;
291 } // namespace xmloff
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */