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