Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "formattributes.hxx"
31 : :
32 : : #include <sax/tools/converter.hxx>
33 : :
34 : : #include "xmloff/xmlnmspe.hxx"
35 : : #include <xmloff/xmluconv.hxx>
36 : : #include <rtl/ustrbuf.hxx>
37 : : #include <rtl/logfile.hxx>
38 : : //.........................................................................
39 : : namespace xmloff
40 : : {
41 : : //.........................................................................
42 : :
43 : : using namespace ::com::sun::star::uno;
44 : : using namespace ::com::sun::star::lang;
45 : : using namespace ::com::sun::star::beans;
46 : :
47 : :
48 : : //=====================================================================
49 : : //= OAttributeMetaData
50 : : //=====================================================================
51 : : //---------------------------------------------------------------------
52 : 6785 : const sal_Char* OAttributeMetaData::getCommonControlAttributeName(sal_Int32 _nId)
53 : : {
54 [ + - + + : 6785 : switch (_nId)
+ + - + -
+ + + + +
+ + + + +
+ + + + +
- ]
55 : : {
56 : 354 : case CCA_NAME: return "name";
57 : 0 : case CCA_SERVICE_NAME: return "control-implementation";
58 : 354 : case CCA_BUTTON_TYPE: return "button-type";
59 : : // disabled(AddAttributeIdLegacy) case CCA_CONTROL_ID: return "id";
60 : 355 : case CCA_CURRENT_SELECTED: return "current-selected";
61 : 8 : case CCA_CURRENT_VALUE: return "current-value";
62 : 354 : case CCA_DISABLED: return "disabled";
63 : 0 : case CCA_ENABLEVISIBLE: return "visible";
64 : 354 : case CCA_DROPDOWN: return "dropdown";
65 : 0 : case CCA_FOR: return "for";
66 : 359 : case CCA_IMAGE_DATA: return "image-data";
67 : 354 : case CCA_LABEL: return "label";
68 : 354 : case CCA_MAX_LENGTH: return "max-length";
69 : 354 : case CCA_PRINTABLE: return "printable";
70 : 354 : case CCA_READONLY: return "readonly";
71 : 355 : case CCA_SELECTED: return "selected";
72 : 354 : case CCA_SIZE: return "size";
73 : 354 : case CCA_TAB_INDEX: return "tab-index";
74 : 385 : case CCA_TARGET_FRAME: return "target-frame";
75 : 359 : case CCA_TARGET_LOCATION: return "href"; // the only special thing here: TargetLocation is represented by an xlink:href attribute
76 : 354 : case CCA_TAB_STOP: return "tab-stop";
77 : 354 : case CCA_TITLE: return "title";
78 : 8 : case CCA_VALUE: return "value";
79 : 354 : case CCA_ORIENTATION: return "orientation";
80 : 354 : case CCA_VISUAL_EFFECT: return "visual-effect";
81 : : default:
82 : : OSL_FAIL("OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
83 : : }
84 : 6785 : return "";
85 : : }
86 : :
87 : : //---------------------------------------------------------------------
88 : 0 : sal_uInt16 OAttributeMetaData::getCommonControlAttributeNamespace(sal_Int32 _nId)
89 : : {
90 [ # # ]: 0 : if (CCA_TARGET_LOCATION == _nId)
91 : 0 : return XML_NAMESPACE_XLINK;
92 : :
93 [ # # ]: 0 : if (CCA_TARGET_FRAME == _nId)
94 : 0 : return XML_NAMESPACE_OFFICE;
95 : :
96 : 0 : return XML_NAMESPACE_FORM;
97 : : }
98 : :
99 : : //---------------------------------------------------------------------
100 : 5326 : const sal_Char* OAttributeMetaData::getFormAttributeName(FormAttributes _eAttrib)
101 : : {
102 [ - - - + : 5326 : switch (_eAttrib)
+ - + + +
+ + + + +
- + + + +
+ + + - ]
103 : : {
104 : 0 : case faName: return "name";
105 : 0 : case faServiceName: return "service-name";
106 : 0 : case faAction: return "href"; // the only special thing here: Action is represented by an xlink:href attribute
107 : 354 : case faEnctype: return "enctype";
108 : 354 : case faMethod: return "method";
109 : 0 : case faTargetFrame: return "target-frame";
110 : 354 : case faAllowDeletes: return "allow-deletes";
111 : 354 : case faAllowInserts: return "allow-inserts";
112 : 354 : case faAllowUpdates: return "allow-updates";
113 : 354 : case faApplyFilter: return "apply-filter";
114 : 354 : case faCommand: return "command";
115 : 354 : case faCommandType: return "command-type";
116 : 354 : case faEscapeProcessing: return "escape-processing";
117 : 354 : case faDatasource: return "datasource";
118 : 0 : case faConnectionResource: return "connection-resource";
119 : 8 : case faDetailFiels: return "detail-fields";
120 : 354 : case faFilter: return "filter";
121 : 354 : case faIgnoreResult: return "ignore-result";
122 : 8 : case faMasterFields: return "master-fields";
123 : 354 : case faNavigationMode: return "navigation-mode";
124 : 354 : case faOrder: return "order";
125 : 354 : case faTabbingCycle: return "tab-cycle";
126 : : default:
127 : : OSL_FAIL("OAttributeMetaData::getFormAttributeName: invalid id!");
128 : : }
129 : 5326 : return "";
130 : : }
131 : :
132 : : //---------------------------------------------------------------------
133 : 0 : sal_uInt16 OAttributeMetaData::getFormAttributeNamespace(FormAttributes _eAttrib)
134 : : {
135 [ # # ]: 0 : if (faAction == _eAttrib)
136 : 0 : return XML_NAMESPACE_XLINK;
137 : :
138 [ # # ]: 0 : if (faTargetFrame == _eAttrib)
139 : 0 : return XML_NAMESPACE_OFFICE;
140 : :
141 : 0 : return XML_NAMESPACE_FORM;
142 : : }
143 : :
144 : : //---------------------------------------------------------------------
145 : 1778 : const sal_Char* OAttributeMetaData::getDatabaseAttributeName(sal_Int32 _nId)
146 : : {
147 [ + + + - : 1778 : switch (_nId)
+ + - ]
148 : : {
149 : 354 : case DA_BOUND_COLUMN: return "bound-column";
150 : 362 : case DA_CONVERT_EMPTY: return "convert-empty-to-null";
151 : 354 : case DA_DATA_FIELD: return "data-field";
152 : 0 : case DA_LIST_SOURCE: return "list-source";
153 : 354 : case DA_LIST_SOURCE_TYPE: return "list-source-type";
154 : 354 : case DA_INPUT_REQUIRED: return "input-required";
155 : : default:
156 : : OSL_FAIL("OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
157 : : }
158 : 1778 : return "";
159 : : }
160 : :
161 : : //---------------------------------------------------------------------
162 : 0 : sal_uInt16 OAttributeMetaData::getDatabaseAttributeNamespace(sal_Int32 /*_nId*/)
163 : : {
164 : : // nothing special here
165 : 0 : return XML_NAMESPACE_FORM;
166 : : }
167 : :
168 : : //---------------------------------------------------------------------
169 : 8 : const sal_Char* OAttributeMetaData::getBindingAttributeName(sal_Int32 _nId)
170 : : {
171 [ + - - - ]: 8 : switch (_nId)
172 : : {
173 : 8 : case BA_LINKED_CELL: return "linked-cell";
174 : 0 : case BA_LIST_LINKING_TYPE: return "list-linkage-type";
175 : 0 : case BA_LIST_CELL_RANGE: return "source-cell-range";
176 : : default:
177 : : OSL_FAIL("OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
178 : : }
179 : 8 : return "";
180 : : }
181 : :
182 : : //---------------------------------------------------------------------
183 : 0 : sal_uInt16 OAttributeMetaData::getBindingAttributeNamespace(sal_Int32)
184 : : {
185 : : // nothing special here
186 : 0 : return XML_NAMESPACE_FORM;
187 : : }
188 : :
189 : : //---------------------------------------------------------------------
190 : 4272 : const sal_Char* OAttributeMetaData::getSpecialAttributeName(sal_Int32 _nId)
191 : : {
192 [ - + + + : 4272 : switch (_nId)
+ + + + +
+ + + - -
+ + + +
- ]
193 : : {
194 : 0 : case SCA_ECHO_CHAR: return "echo-char";
195 : 8 : case SCA_MAX_VALUE: return "max-value";
196 : 8 : case SCA_MIN_VALUE: return "min-value";
197 : 354 : case SCA_VALIDATION: return "validation";
198 : 354 : case SCA_GROUP_NAME: return "group-name";
199 : 354 : case SCA_MULTI_LINE: return "multi-line";
200 : 354 : case SCA_AUTOMATIC_COMPLETION: return "auto-complete";
201 : 354 : case SCA_MULTIPLE: return "multiple";
202 : 354 : case SCA_DEFAULT_BUTTON: return "default-button";
203 : 354 : case SCA_CURRENT_STATE: return "current-state";
204 : 354 : case SCA_IS_TRISTATE: return "is-tristate";
205 : 354 : case SCA_STATE: return "state";
206 : 0 : case SCA_COLUMN_STYLE_NAME: return "text-style-name";
207 : 0 : case SCA_STEP_SIZE: return "step-size";
208 : 354 : case SCA_PAGE_STEP_SIZE: return "page-step-size";
209 : 8 : case SCA_REPEAT_DELAY: return "delay-for-repeat";
210 : 354 : case SCA_TOGGLE: return "toggle";
211 : 354 : case SCA_FOCUS_ON_CLICK: return "focus-on-click";
212 : : default:
213 : : OSL_FAIL("OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
214 : : }
215 : 4272 : return "";
216 : : }
217 : :
218 : : //---------------------------------------------------------------------
219 : 0 : sal_uInt16 OAttributeMetaData::getSpecialAttributeNamespace(sal_Int32 _nId)
220 : : {
221 [ # # ]: 0 : switch( _nId )
222 : : {
223 : 0 : case SCA_GROUP_NAME: return XML_NAMESPACE_FORMX;
224 : : }
225 : 0 : return XML_NAMESPACE_FORM;
226 : : }
227 : :
228 : : //---------------------------------------------------------------------
229 : 80 : const sal_Char* OAttributeMetaData::getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib)
230 : : {
231 [ + + - ]: 80 : switch (_eAttrib)
232 : : {
233 : 40 : case ofaAutomaticFocus: return "automatic-focus";
234 : 40 : case ofaApplyDesignMode: return "apply-design-mode";
235 : : default:
236 : : OSL_FAIL("OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
237 : : }
238 : 80 : return "";
239 : : }
240 : :
241 : : //---------------------------------------------------------------------
242 : 80 : sal_uInt16 OAttributeMetaData::getOfficeFormsAttributeNamespace(OfficeFormsAttributes /* _eAttrib */)
243 : : {
244 : : // nothing special here
245 : 80 : return XML_NAMESPACE_FORM;
246 : : }
247 : :
248 : : //=====================================================================
249 : : //= OAttribute2Property
250 : : //=====================================================================
251 : : //---------------------------------------------------------------------
252 : 354 : OAttribute2Property::OAttribute2Property()
253 : : {
254 : 354 : }
255 : :
256 : : //---------------------------------------------------------------------
257 : 354 : OAttribute2Property::~OAttribute2Property()
258 : : {
259 [ - + ]: 354 : }
260 : :
261 : : //---------------------------------------------------------------------
262 : 140 : const OAttribute2Property::AttributeAssignment* OAttribute2Property::getAttributeTranslation(
263 : : const ::rtl::OUString& _rAttribName)
264 : : {
265 [ + - ]: 140 : ConstAttributeAssignmentsIterator aPos = m_aKnownProperties.find(_rAttribName);
266 [ + + ]: 140 : if (m_aKnownProperties.end() != aPos)
267 : 137 : return &aPos->second;
268 : 140 : return NULL;
269 : : }
270 : :
271 : : //---------------------------------------------------------------------
272 : 4248 : void OAttribute2Property::addStringProperty(
273 : : const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
274 : : const sal_Char* _pAttributeDefault)
275 : : {
276 [ + - ]: 4248 : implAdd(_pAttributeName, _rPropertyName, ::getCppuType( static_cast< ::rtl::OUString* >(NULL) ),
277 [ + + ][ + - ]: 8496 : _pAttributeDefault ? ::rtl::OUString::createFromAscii(_pAttributeDefault) : ::rtl::OUString());
278 : 4248 : }
279 : :
280 : : //---------------------------------------------------------------------
281 : 8142 : void OAttribute2Property::addBooleanProperty(
282 : : const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
283 : : const sal_Bool _bAttributeDefault, const sal_Bool _bInverseSemantics)
284 : : {
285 : 8142 : ::rtl::OUStringBuffer aDefault;
286 [ + - ]: 8142 : ::sax::Converter::convertBool(aDefault, _bAttributeDefault);
287 [ + - ][ + - ]: 8142 : AttributeAssignment& aAssignment = implAdd(_pAttributeName, _rPropertyName, ::getBooleanCppuType(), aDefault.makeStringAndClear());
[ + - ]
288 : 8142 : aAssignment.bInverseSemantics = _bInverseSemantics;
289 : 8142 : }
290 : :
291 : : //---------------------------------------------------------------------
292 : 1416 : void OAttribute2Property::addInt16Property(
293 : : const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
294 : : const sal_Int16 _nAttributeDefault)
295 : : {
296 : 1416 : ::rtl::OUStringBuffer aDefault;
297 [ + - ]: 1416 : ::sax::Converter::convertNumber(aDefault, (sal_Int32)_nAttributeDefault);
298 [ + - ][ + - ]: 1416 : implAdd(_pAttributeName, _rPropertyName, ::getCppuType( static_cast< sal_Int16* >(NULL) ), aDefault.makeStringAndClear());
[ + - ]
299 : 1416 : }
300 : :
301 : : //---------------------------------------------------------------------
302 : 354 : void OAttribute2Property::addInt32Property(
303 : : const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
304 : : const sal_Int32 _nAttributeDefault)
305 : : {
306 : 354 : ::rtl::OUStringBuffer aDefault;
307 [ + - ]: 354 : ::sax::Converter::convertNumber( aDefault, _nAttributeDefault );
308 [ + - ][ + - ]: 354 : implAdd( _pAttributeName, _rPropertyName, ::getCppuType( static_cast< sal_Int32* >(NULL) ), aDefault.makeStringAndClear() );
[ + - ]
309 : 354 : }
310 : :
311 : : //---------------------------------------------------------------------
312 : 3894 : void OAttribute2Property::addEnumProperty(
313 : : const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
314 : : const sal_uInt16 _nAttributeDefault, const SvXMLEnumMapEntry* _pValueMap,
315 : : const ::com::sun::star::uno::Type* _pType)
316 : : {
317 : 3894 : ::rtl::OUStringBuffer aDefault;
318 [ + - ]: 3894 : SvXMLUnitConverter::convertEnum(aDefault, _nAttributeDefault, _pValueMap);
319 : : AttributeAssignment& aAssignment = implAdd(_pAttributeName, _rPropertyName,
320 : : _pType ? *_pType : ::getCppuType( static_cast< sal_Int32* >(NULL) ),
321 : : // this assumes that the setPropertyValue for enums can handle int32's ....
322 [ + - ][ + + ]: 3894 : aDefault.makeStringAndClear());
[ + - ][ + - ]
323 : 3894 : aAssignment.pEnumMap = _pValueMap;
324 : 3894 : }
325 : :
326 : : //---------------------------------------------------------------------
327 : 18054 : OAttribute2Property::AttributeAssignment& OAttribute2Property::implAdd(
328 : : const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
329 : : const ::com::sun::star::uno::Type& _rType, const ::rtl::OUString& /*_rDefaultString*/)
330 : : {
331 : : OSL_ENSURE(m_aKnownProperties.end() == m_aKnownProperties.find(::rtl::OUString::createFromAscii(_pAttributeName)),
332 : : "OAttribute2Property::implAdd: already have this attribute!");
333 : :
334 : 18054 : ::rtl::OUString sAttributeName = ::rtl::OUString::createFromAscii(_pAttributeName);
335 : :
336 : 18054 : AttributeAssignment aAssignment;
337 : 18054 : aAssignment.sAttributeName = sAttributeName;
338 : 18054 : aAssignment.sPropertyName = _rPropertyName;
339 : 18054 : aAssignment.aPropertyType = _rType;
340 : :
341 : : // redundance, the accessor is stored in aAssignment.sAttributeName, too
342 [ + - ]: 18054 : return m_aKnownProperties[sAttributeName] = aAssignment;
343 : : }
344 : :
345 : : //.........................................................................
346 : : } // namespace xmloff
347 : : //.........................................................................
348 : :
349 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|