Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "formattributes.hxx"
21 :
22 : #include <sax/tools/converter.hxx>
23 :
24 : #include <xmloff/xmlnmspe.hxx>
25 : #include <xmloff/xmluconv.hxx>
26 : #include <rtl/ustrbuf.hxx>
27 : namespace xmloff
28 : {
29 :
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::lang;
32 : using namespace ::com::sun::star::beans;
33 :
34 : //= OAttributeMetaData
35 33220 : const sal_Char* OAttributeMetaData::getCommonControlAttributeName(sal_Int32 _nId)
36 : {
37 33220 : switch (_nId)
38 : {
39 1744 : case CCA_NAME: return "name";
40 0 : case CCA_SERVICE_NAME: return "control-implementation";
41 1744 : case CCA_BUTTON_TYPE: return "button-type";
42 : // disabled(AddAttributeIdLegacy) case CCA_CONTROL_ID: return "id";
43 1746 : case CCA_CURRENT_SELECTED: return "current-selected";
44 10 : case CCA_CURRENT_VALUE: return "current-value";
45 1744 : case CCA_DISABLED: return "disabled";
46 0 : case CCA_ENABLEVISIBLE: return "visible";
47 1744 : case CCA_DROPDOWN: return "dropdown";
48 0 : case CCA_FOR: return "for";
49 1752 : case CCA_IMAGE_DATA: return "image-data";
50 1744 : case CCA_LABEL: return "label";
51 1744 : case CCA_MAX_LENGTH: return "max-length";
52 1744 : case CCA_PRINTABLE: return "printable";
53 1744 : case CCA_READONLY: return "readonly";
54 1746 : case CCA_SELECTED: return "selected";
55 1744 : case CCA_SIZE: return "size";
56 1744 : case CCA_TAB_INDEX: return "tab-index";
57 1788 : case CCA_TARGET_FRAME: return "target-frame";
58 1752 : case CCA_TARGET_LOCATION: return "href"; // the only special thing here: TargetLocation is represented by an xlink:href attribute
59 1744 : case CCA_TAB_STOP: return "tab-stop";
60 1744 : case CCA_TITLE: return "title";
61 10 : case CCA_VALUE: return "value";
62 1744 : case CCA_ORIENTATION: return "orientation";
63 1744 : case CCA_VISUAL_EFFECT: return "visual-effect";
64 : default:
65 : OSL_FAIL("OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
66 : }
67 0 : return "";
68 : }
69 :
70 0 : sal_uInt16 OAttributeMetaData::getCommonControlAttributeNamespace(sal_Int32 _nId)
71 : {
72 0 : if (CCA_TARGET_LOCATION == _nId)
73 0 : return XML_NAMESPACE_XLINK;
74 :
75 0 : if (CCA_TARGET_FRAME == _nId)
76 0 : return XML_NAMESPACE_OFFICE;
77 :
78 0 : return XML_NAMESPACE_FORM;
79 : }
80 :
81 26180 : const sal_Char* OAttributeMetaData::getFormAttributeName(FormAttributes _eAttrib)
82 : {
83 26180 : switch (_eAttrib)
84 : {
85 0 : case faName: return "name";
86 0 : case faServiceName: return "service-name";
87 0 : case faAction: return "href"; // the only special thing here: Action is represented by an xlink:href attribute
88 1744 : case faEnctype: return "enctype";
89 1744 : case faMethod: return "method";
90 0 : case faTargetFrame: return "target-frame";
91 1744 : case faAllowDeletes: return "allow-deletes";
92 1744 : case faAllowInserts: return "allow-inserts";
93 1744 : case faAllowUpdates: return "allow-updates";
94 1744 : case faApplyFilter: return "apply-filter";
95 1744 : case faCommand: return "command";
96 1744 : case faCommandType: return "command-type";
97 1744 : case faEscapeProcessing: return "escape-processing";
98 1744 : case faDatasource: return "datasource";
99 0 : case faConnectionResource: return "connection-resource";
100 10 : case faDetailFiels: return "detail-fields";
101 1744 : case faFilter: return "filter";
102 1744 : case faIgnoreResult: return "ignore-result";
103 10 : case faMasterFields: return "master-fields";
104 1744 : case faNavigationMode: return "navigation-mode";
105 1744 : case faOrder: return "order";
106 1744 : case faTabbingCycle: return "tab-cycle";
107 : default:
108 : OSL_FAIL("OAttributeMetaData::getFormAttributeName: invalid id!");
109 : }
110 0 : return "";
111 : }
112 :
113 0 : sal_uInt16 OAttributeMetaData::getFormAttributeNamespace(FormAttributes _eAttrib)
114 : {
115 0 : if (faAction == _eAttrib)
116 0 : return XML_NAMESPACE_XLINK;
117 :
118 0 : if (faTargetFrame == _eAttrib)
119 0 : return XML_NAMESPACE_OFFICE;
120 :
121 0 : return XML_NAMESPACE_FORM;
122 : }
123 :
124 8732 : const sal_Char* OAttributeMetaData::getDatabaseAttributeName(sal_Int32 _nId)
125 : {
126 8732 : switch (_nId)
127 : {
128 1744 : case DA_BOUND_COLUMN: return "bound-column";
129 1756 : case DA_CONVERT_EMPTY: return "convert-empty-to-null";
130 1744 : case DA_DATA_FIELD: return "data-field";
131 0 : case DA_LIST_SOURCE: return "list-source";
132 1744 : case DA_LIST_SOURCE_TYPE: return "list-source-type";
133 1744 : case DA_INPUT_REQUIRED: return "input-required";
134 : default:
135 : OSL_FAIL("OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
136 : }
137 0 : return "";
138 : }
139 :
140 0 : sal_uInt16 OAttributeMetaData::getDatabaseAttributeNamespace(sal_Int32 /*_nId*/)
141 : {
142 : // nothing special here
143 0 : return XML_NAMESPACE_FORM;
144 : }
145 :
146 10 : const sal_Char* OAttributeMetaData::getBindingAttributeName(sal_Int32 _nId)
147 : {
148 10 : switch (_nId)
149 : {
150 10 : case BA_LINKED_CELL: return "linked-cell";
151 0 : case BA_LIST_LINKING_TYPE: return "list-linkage-type";
152 0 : case BA_LIST_CELL_RANGE: return "source-cell-range";
153 : default:
154 : OSL_FAIL("OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
155 : }
156 0 : return "";
157 : }
158 :
159 0 : sal_uInt16 OAttributeMetaData::getBindingAttributeNamespace(sal_Int32)
160 : {
161 : // nothing special here
162 0 : return XML_NAMESPACE_FORM;
163 : }
164 :
165 20958 : const sal_Char* OAttributeMetaData::getSpecialAttributeName(sal_Int32 _nId)
166 : {
167 20958 : switch (_nId)
168 : {
169 0 : case SCA_ECHO_CHAR: return "echo-char";
170 10 : case SCA_MAX_VALUE: return "max-value";
171 10 : case SCA_MIN_VALUE: return "min-value";
172 1744 : case SCA_VALIDATION: return "validation";
173 1744 : case SCA_GROUP_NAME: return "group-name";
174 1744 : case SCA_MULTI_LINE: return "multi-line";
175 1744 : case SCA_AUTOMATIC_COMPLETION: return "auto-complete";
176 1744 : case SCA_MULTIPLE: return "multiple";
177 1744 : case SCA_DEFAULT_BUTTON: return "default-button";
178 1744 : case SCA_CURRENT_STATE: return "current-state";
179 1744 : case SCA_IS_TRISTATE: return "is-tristate";
180 1744 : case SCA_STATE: return "state";
181 0 : case SCA_COLUMN_STYLE_NAME: return "text-style-name";
182 0 : case SCA_STEP_SIZE: return "step-size";
183 1744 : case SCA_PAGE_STEP_SIZE: return "page-step-size";
184 10 : case SCA_REPEAT_DELAY: return "delay-for-repeat";
185 1744 : case SCA_TOGGLE: return "toggle";
186 1744 : case SCA_FOCUS_ON_CLICK: return "focus-on-click";
187 : default:
188 : OSL_FAIL("OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
189 : }
190 0 : return "";
191 : }
192 :
193 0 : sal_uInt16 OAttributeMetaData::getSpecialAttributeNamespace(sal_Int32 _nId)
194 : {
195 0 : switch( _nId )
196 : {
197 0 : case SCA_GROUP_NAME: return XML_NAMESPACE_FORMX;
198 : }
199 0 : return XML_NAMESPACE_FORM;
200 : }
201 :
202 216 : const sal_Char* OAttributeMetaData::getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib)
203 : {
204 216 : switch (_eAttrib)
205 : {
206 108 : case ofaAutomaticFocus: return "automatic-focus";
207 108 : case ofaApplyDesignMode: return "apply-design-mode";
208 : default:
209 : OSL_FAIL("OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
210 : }
211 0 : return "";
212 : }
213 :
214 216 : sal_uInt16 OAttributeMetaData::getOfficeFormsAttributeNamespace(OfficeFormsAttributes /* _eAttrib */)
215 : {
216 : // nothing special here
217 216 : return XML_NAMESPACE_FORM;
218 : }
219 :
220 : //= OAttribute2Property
221 1744 : OAttribute2Property::OAttribute2Property()
222 : {
223 1744 : }
224 :
225 1744 : OAttribute2Property::~OAttribute2Property()
226 : {
227 1744 : }
228 :
229 204 : const OAttribute2Property::AttributeAssignment* OAttribute2Property::getAttributeTranslation(
230 : const OUString& _rAttribName)
231 : {
232 204 : AttributeAssignments::const_iterator aPos = m_aKnownProperties.find(_rAttribName);
233 204 : if (m_aKnownProperties.end() != aPos)
234 198 : return &aPos->second;
235 6 : return NULL;
236 : }
237 :
238 20928 : void OAttribute2Property::addStringProperty(
239 : const sal_Char* _pAttributeName, const OUString& _rPropertyName,
240 : const sal_Char* _pAttributeDefault)
241 : {
242 20928 : implAdd(_pAttributeName, _rPropertyName, ::cppu::UnoType<OUString>::get(),
243 41856 : _pAttributeDefault ? OUString::createFromAscii(_pAttributeDefault) : OUString());
244 20928 : }
245 :
246 40112 : void OAttribute2Property::addBooleanProperty(
247 : const sal_Char* _pAttributeName, const OUString& _rPropertyName,
248 : const bool _bAttributeDefault, const bool _bInverseSemantics)
249 : {
250 40112 : OUStringBuffer aDefault;
251 40112 : ::sax::Converter::convertBool(aDefault, _bAttributeDefault);
252 40112 : AttributeAssignment& aAssignment = implAdd(_pAttributeName, _rPropertyName, ::getBooleanCppuType(), aDefault.makeStringAndClear());
253 40112 : aAssignment.bInverseSemantics = _bInverseSemantics;
254 40112 : }
255 :
256 6976 : void OAttribute2Property::addInt16Property(
257 : const sal_Char* _pAttributeName, const OUString& _rPropertyName,
258 : const sal_Int16 _nAttributeDefault)
259 : {
260 6976 : OUStringBuffer aDefault;
261 6976 : ::sax::Converter::convertNumber(aDefault, (sal_Int32)_nAttributeDefault);
262 6976 : implAdd(_pAttributeName, _rPropertyName, ::cppu::UnoType<sal_Int16>::get(), aDefault.makeStringAndClear());
263 6976 : }
264 :
265 1744 : void OAttribute2Property::addInt32Property(
266 : const sal_Char* _pAttributeName, const OUString& _rPropertyName,
267 : const sal_Int32 _nAttributeDefault)
268 : {
269 1744 : OUStringBuffer aDefault;
270 1744 : ::sax::Converter::convertNumber( aDefault, _nAttributeDefault );
271 1744 : implAdd( _pAttributeName, _rPropertyName, ::cppu::UnoType<sal_Int32>::get(), aDefault.makeStringAndClear() );
272 1744 : }
273 :
274 19184 : void OAttribute2Property::addEnumProperty(
275 : const sal_Char* _pAttributeName, const OUString& _rPropertyName,
276 : const sal_uInt16 _nAttributeDefault, const SvXMLEnumMapEntry* _pValueMap,
277 : const ::com::sun::star::uno::Type* _pType)
278 : {
279 19184 : OUStringBuffer aDefault;
280 19184 : SvXMLUnitConverter::convertEnum(aDefault, _nAttributeDefault, _pValueMap);
281 : AttributeAssignment& aAssignment = implAdd(_pAttributeName, _rPropertyName,
282 : _pType ? *_pType : ::cppu::UnoType<sal_Int32>::get(),
283 : // this assumes that the setPropertyValue for enums can handle int32's ....
284 19184 : aDefault.makeStringAndClear());
285 19184 : aAssignment.pEnumMap = _pValueMap;
286 19184 : }
287 :
288 88944 : OAttribute2Property::AttributeAssignment& OAttribute2Property::implAdd(
289 : const sal_Char* _pAttributeName, const OUString& _rPropertyName,
290 : const ::com::sun::star::uno::Type& _rType, const OUString& /*_rDefaultString*/)
291 : {
292 : OSL_ENSURE(m_aKnownProperties.end() == m_aKnownProperties.find(OUString::createFromAscii(_pAttributeName)),
293 : "OAttribute2Property::implAdd: already have this attribute!");
294 :
295 88944 : OUString sAttributeName = OUString::createFromAscii(_pAttributeName);
296 :
297 177888 : AttributeAssignment aAssignment;
298 88944 : aAssignment.sAttributeName = sAttributeName;
299 88944 : aAssignment.sPropertyName = _rPropertyName;
300 88944 : aAssignment.aPropertyType = _rType;
301 :
302 : // redundance, the accessor is stored in aAssignment.sAttributeName, too
303 177888 : return m_aKnownProperties[sAttributeName] = aAssignment;
304 : }
305 :
306 : } // namespace xmloff
307 :
308 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|