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