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