Update ooo320-m1
[ooovba.git] / xmloff / source / forms / formattributes.cxx
blob795cf4a714bc7ddfa698574430cf675183fe9135
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: formattributes.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "formattributes.hxx"
34 #include "xmlnmspe.hxx"
35 #include <xmloff/xmluconv.hxx>
36 #include <rtl/ustrbuf.hxx>
37 #include <rtl/logfile.hxx>
38 //.........................................................................
39 namespace xmloff
41 //.........................................................................
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::beans;
48 //=====================================================================
49 //= OAttributeMetaData
50 //=====================================================================
51 //---------------------------------------------------------------------
52 const sal_Char* OAttributeMetaData::getCommonControlAttributeName(sal_Int32 _nId)
54 switch (_nId)
56 case CCA_NAME: return "name";
57 case CCA_SERVICE_NAME: return "control-implementation";
58 case CCA_BUTTON_TYPE: return "button-type";
59 case CCA_CONTROL_ID: return "id";
60 case CCA_CURRENT_SELECTED: return "current-selected";
61 case CCA_CURRENT_VALUE: return "current-value";
62 case CCA_DISABLED: return "disabled";
63 case CCA_ENABLEVISIBLE: return "visible";
64 case CCA_DROPDOWN: return "dropdown";
65 case CCA_FOR: return "for";
66 case CCA_IMAGE_DATA: return "image-data";
67 case CCA_LABEL: return "label";
68 case CCA_MAX_LENGTH: return "max-length";
69 case CCA_PRINTABLE: return "printable";
70 case CCA_READONLY: return "readonly";
71 case CCA_SELECTED: return "selected";
72 case CCA_SIZE: return "size";
73 case CCA_TAB_INDEX: return "tab-index";
74 case CCA_TARGET_FRAME: return "target-frame";
75 case CCA_TARGET_LOCATION: return "href"; // the only special thing here: TargetLocation is represented by an xlink:href attribute
76 case CCA_TAB_STOP: return "tab-stop";
77 case CCA_TITLE: return "title";
78 case CCA_VALUE: return "value";
79 case CCA_ORIENTATION: return "orientation";
80 case CCA_VISUAL_EFFECT: return "visual-effect";
81 default:
82 OSL_ENSURE(sal_False, "OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
84 return "";
87 //---------------------------------------------------------------------
88 sal_uInt16 OAttributeMetaData::getCommonControlAttributeNamespace(sal_Int32 _nId)
90 if (CCA_TARGET_LOCATION == _nId)
91 return XML_NAMESPACE_XLINK;
93 if (CCA_TARGET_FRAME == _nId)
94 return XML_NAMESPACE_OFFICE;
96 return XML_NAMESPACE_FORM;
99 //---------------------------------------------------------------------
100 const sal_Char* OAttributeMetaData::getFormAttributeName(FormAttributes _eAttrib)
102 switch (_eAttrib)
104 case faName: return "name";
105 case faServiceName: return "service-name";
106 case faAction: return "href"; // the only special thing here: Action is represented by an xlink:href attribute
107 case faEnctype: return "enctype";
108 case faMethod: return "method";
109 case faTargetFrame: return "target-frame";
110 case faAllowDeletes: return "allow-deletes";
111 case faAllowInserts: return "allow-inserts";
112 case faAllowUpdates: return "allow-updates";
113 case faApplyFilter: return "apply-filter";
114 case faCommand: return "command";
115 case faCommandType: return "command-type";
116 case faEscapeProcessing: return "escape-processing";
117 case faDatasource: return "datasource";
118 case faConnectionResource: return "connection-resource";
119 case faDetailFiels: return "detail-fields";
120 case faFilter: return "filter";
121 case faIgnoreResult: return "ignore-result";
122 case faMasterFields: return "master-fields";
123 case faNavigationMode: return "navigation-mode";
124 case faOrder: return "order";
125 case faTabbingCycle: return "tab-cycle";
126 default:
127 OSL_ENSURE(sal_False, "OAttributeMetaData::getFormAttributeName: invalid id!");
129 return "";
132 //---------------------------------------------------------------------
133 sal_uInt16 OAttributeMetaData::getFormAttributeNamespace(FormAttributes _eAttrib)
135 if (faAction == _eAttrib)
136 return XML_NAMESPACE_XLINK;
138 if (faTargetFrame == _eAttrib)
139 return XML_NAMESPACE_OFFICE;
141 return XML_NAMESPACE_FORM;
144 //---------------------------------------------------------------------
145 const sal_Char* OAttributeMetaData::getDatabaseAttributeName(sal_Int32 _nId)
147 switch (_nId)
149 case DA_BOUND_COLUMN: return "bound-column";
150 case DA_CONVERT_EMPTY: return "convert-empty-to-null";
151 case DA_DATA_FIELD: return "data-field";
152 case DA_LIST_SOURCE: return "list-source";
153 case DA_LIST_SOURCE_TYPE: return "list-source-type";
154 case DA_INPUT_REQUIRED: return "input-required";
155 default:
156 OSL_ENSURE(sal_False, "OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
158 return "";
161 //---------------------------------------------------------------------
162 sal_uInt16 OAttributeMetaData::getDatabaseAttributeNamespace(sal_Int32 /*_nId*/)
164 // nothing special here
165 return XML_NAMESPACE_FORM;
168 //---------------------------------------------------------------------
169 const sal_Char* OAttributeMetaData::getBindingAttributeName(sal_Int32 _nId)
171 switch (_nId)
173 case BA_LINKED_CELL: return "linked-cell";
174 case BA_LIST_LINKING_TYPE: return "list-linkage-type";
175 case BA_LIST_CELL_RANGE: return "source-cell-range";
176 default:
177 OSL_ENSURE(sal_False, "OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
179 return "";
182 //---------------------------------------------------------------------
183 sal_uInt16 OAttributeMetaData::getBindingAttributeNamespace(sal_Int32)
185 // nothing special here
186 return XML_NAMESPACE_FORM;
189 //---------------------------------------------------------------------
190 const sal_Char* OAttributeMetaData::getSpecialAttributeName(sal_Int32 _nId)
192 switch (_nId)
194 case SCA_ECHO_CHAR: return "echo-char";
195 case SCA_MAX_VALUE: return "max-value";
196 case SCA_MIN_VALUE: return "min-value";
197 case SCA_VALIDATION: return "validation";
198 case SCA_GROUP_NAME: return "group-name";
199 case SCA_MULTI_LINE: return "multi-line";
200 case SCA_AUTOMATIC_COMPLETION: return "auto-complete";
201 case SCA_MULTIPLE: return "multiple";
202 case SCA_DEFAULT_BUTTON: return "default-button";
203 case SCA_CURRENT_STATE: return "current-state";
204 case SCA_IS_TRISTATE: return "is-tristate";
205 case SCA_STATE: return "state";
206 case SCA_COLUMN_STYLE_NAME: return "text-style-name";
207 case SCA_STEP_SIZE: return "step-size";
208 case SCA_PAGE_STEP_SIZE: return "page-step-size";
209 case SCA_REPEAT_DELAY: return "delay-for-repeat";
210 case SCA_TOGGLE: return "toggle";
211 case SCA_FOCUS_ON_CLICK: return "focus-on-click";
212 default:
213 OSL_ENSURE(sal_False, "OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
215 return "";
218 //---------------------------------------------------------------------
219 sal_uInt16 OAttributeMetaData::getSpecialAttributeNamespace(sal_Int32 _nId)
221 switch( _nId )
223 case SCA_GROUP_NAME: return XML_NAMESPACE_FORMX;
225 return XML_NAMESPACE_FORM;
228 //---------------------------------------------------------------------
229 const sal_Char* OAttributeMetaData::getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib)
231 switch (_eAttrib)
233 case ofaAutomaticFocus: return "automatic-focus";
234 case ofaApplyDesignMode: return "apply-design-mode";
235 default:
236 OSL_ENSURE(sal_False, "OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
238 return "";
241 //---------------------------------------------------------------------
242 sal_uInt16 OAttributeMetaData::getOfficeFormsAttributeNamespace(OfficeFormsAttributes /* _eAttrib */)
244 // nothing special here
245 return XML_NAMESPACE_FORM;
248 //=====================================================================
249 //= OAttribute2Property
250 //=====================================================================
251 //---------------------------------------------------------------------
252 OAttribute2Property::OAttribute2Property()
256 //---------------------------------------------------------------------
257 OAttribute2Property::~OAttribute2Property()
261 //---------------------------------------------------------------------
262 const OAttribute2Property::AttributeAssignment* OAttribute2Property::getAttributeTranslation(
263 const ::rtl::OUString& _rAttribName)
265 ConstAttributeAssignmentsIterator aPos = m_aKnownProperties.find(_rAttribName);
266 if (m_aKnownProperties.end() != aPos)
267 return &aPos->second;
268 return NULL;
271 //---------------------------------------------------------------------
272 void OAttribute2Property::addStringProperty(
273 const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
274 const sal_Char* _pAttributeDefault)
276 implAdd(_pAttributeName, _rPropertyName, ::getCppuType( static_cast< ::rtl::OUString* >(NULL) ),
277 _pAttributeDefault ? ::rtl::OUString::createFromAscii(_pAttributeDefault) : ::rtl::OUString());
280 //---------------------------------------------------------------------
281 void OAttribute2Property::addBooleanProperty(
282 const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
283 const sal_Bool _bAttributeDefault, const sal_Bool _bInverseSemantics)
285 ::rtl::OUStringBuffer aDefault;
286 SvXMLUnitConverter::convertBool(aDefault, _bAttributeDefault);
287 AttributeAssignment& aAssignment = implAdd(_pAttributeName, _rPropertyName, ::getBooleanCppuType(), aDefault.makeStringAndClear());
288 aAssignment.bInverseSemantics = _bInverseSemantics;
291 //---------------------------------------------------------------------
292 void OAttribute2Property::addInt16Property(
293 const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
294 const sal_Int16 _nAttributeDefault)
296 ::rtl::OUStringBuffer aDefault;
297 SvXMLUnitConverter::convertNumber(aDefault, (sal_Int32)_nAttributeDefault);
298 implAdd(_pAttributeName, _rPropertyName, ::getCppuType( static_cast< sal_Int16* >(NULL) ), aDefault.makeStringAndClear());
301 //---------------------------------------------------------------------
302 void OAttribute2Property::addInt32Property(
303 const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
304 const sal_Int32 _nAttributeDefault)
306 ::rtl::OUStringBuffer aDefault;
307 SvXMLUnitConverter::convertNumber( aDefault, _nAttributeDefault );
308 implAdd( _pAttributeName, _rPropertyName, ::getCppuType( static_cast< sal_Int32* >(NULL) ), aDefault.makeStringAndClear() );
311 //---------------------------------------------------------------------
312 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)
317 ::rtl::OUStringBuffer aDefault;
318 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 aDefault.makeStringAndClear());
323 aAssignment.pEnumMap = _pValueMap;
326 //---------------------------------------------------------------------
327 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*/)
331 OSL_ENSURE(m_aKnownProperties.end() == m_aKnownProperties.find(::rtl::OUString::createFromAscii(_pAttributeName)),
332 "OAttribute2Property::implAdd: already have this attribute!");
334 ::rtl::OUString sAttributeName = ::rtl::OUString::createFromAscii(_pAttributeName);
336 AttributeAssignment aAssignment;
337 aAssignment.sAttributeName = sAttributeName;
338 aAssignment.sPropertyName = _rPropertyName;
339 aAssignment.aPropertyType = _rType;
341 // redundance, the accessor is stored in aAssignment.sAttributeName, too
342 return m_aKnownProperties[sAttributeName] = aAssignment;
345 //.........................................................................
346 } // namespace xmloff
347 //.........................................................................