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