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 #ifndef _XMLOFF_FORMATTRIBUTES_HXX_
25 #define _XMLOFF_FORMATTRIBUTES_HXX_
26 
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <sal/types.h>
29 #include <vos/refernce.hxx>
30 #include <comphelper/stl_types.hxx>
31 
32 class SvXMLExport;
33 struct SvXMLEnumMapEntry;
34 
35 //.........................................................................
36 namespace xmloff
37 {
38 //.........................................................................
39 
40 	// flags for common control attributes
41 	#define CCA_NAME					0x00000001
42 	#define CCA_SERVICE_NAME			0x00000002
43 	#define CCA_BUTTON_TYPE				0x00000004
44 	#define CCA_CONTROL_ID				0x00000008
45 	#define CCA_CURRENT_SELECTED		0x00000010
46 	#define CCA_CURRENT_VALUE			0x00000020
47 	#define CCA_DISABLED				0x00000040
48 	#define CCA_DROPDOWN				0x00000080
49 	#define CCA_FOR						0x00000100
50 	#define CCA_IMAGE_DATA				0x00000200
51 	#define CCA_LABEL					0x00000400
52 	#define CCA_MAX_LENGTH				0x00000800
53 	#define CCA_PRINTABLE				0x00001000
54 	#define CCA_READONLY				0x00002000
55 	#define CCA_SELECTED				0x00004000
56 	#define CCA_SIZE					0x00008000
57 	#define CCA_TAB_INDEX				0x00010000
58 	#define CCA_TARGET_FRAME			0x00020000
59 	#define CCA_TARGET_LOCATION			0x00040000
60 	#define CCA_TAB_STOP				0x00080000
61 	#define CCA_TITLE					0x00100000
62 	#define CCA_VALUE					0x00200000
63     #define CCA_ORIENTATION             0x00400000
64     #define CCA_VISUAL_EFFECT           0x00800000
65     #define CCA_ENABLEVISIBLE                 0x01000000
66 
67 	// flags for database control atttributes
68 	#define DA_BOUND_COLUMN				0x00000001
69 	#define DA_CONVERT_EMPTY			0x00000002
70 	#define DA_DATA_FIELD				0x00000004
71 	#define DA_LIST_SOURCE				0x00000008
72 	#define DA_LIST_SOURCE_TYPE			0x00000010
73 	#define DA_INPUT_REQUIRED           0x00000020
74 
75     // flags for binding related control attributes
76     #define BA_LINKED_CELL              0x00000001
77     #define BA_LIST_LINKING_TYPE        0x00000002
78     #define BA_LIST_CELL_RANGE          0x00000004
79     #define BA_XFORMS_BIND              0x00000008
80     #define BA_XFORMS_LISTBIND          0x00000010
81     #define BA_XFORMS_SUBMISSION        0x00000020
82 
83 	// flags for event attributes
84 	#define EA_CONTROL_EVENTS			0x00000001
85 	#define EA_ON_CHANGE				0x00000002
86 	#define EA_ON_CLICK					0x00000004
87 	#define EA_ON_DBLCLICK				0x00000008
88 	#define EA_ON_SELECT				0x00000010
89 
90 	/// attributes in the xml tag representing a form
91 	enum FormAttributes
92 	{
93 		faName,
94 		faServiceName,
95 		faAction,
96 		faEnctype,
97 		faMethod,
98 		faTargetFrame,
99 		faAllowDeletes,
100 		faAllowInserts,
101 		faAllowUpdates,
102 		faApplyFilter,
103 		faCommand,
104 		faCommandType,
105 		faEscapeProcessing,
106 		faDatasource,
107 		faConnectionResource,
108 		faDetailFiels,
109 		faFilter,
110 		faIgnoreResult,
111 		faMasterFields,
112 		faNavigationMode,
113 		faOrder,
114 		faTabbingCycle
115 	};
116 
117 	// any other attributes, which are special to some control types
118 	#define SCA_ECHO_CHAR				0x00000001
119 	#define SCA_MAX_VALUE				0x00000002
120 	#define SCA_MIN_VALUE				0x00000004
121 	#define SCA_VALIDATION				0x00000008
122 	#define SCA_MULTI_LINE				0x00000020
123 	#define SCA_AUTOMATIC_COMPLETION	0x00000080
124 	#define SCA_MULTIPLE				0x00000100
125 	#define SCA_DEFAULT_BUTTON			0x00000200
126 	#define SCA_CURRENT_STATE			0x00000400
127 	#define SCA_IS_TRISTATE				0x00000800
128 	#define SCA_STATE					0x00001000
129 	#define SCA_COLUMN_STYLE_NAME		0x00002000
130 	#define SCA_STEP_SIZE               0x00004000
131 	#define SCA_PAGE_STEP_SIZE          0x00008000
132 	#define SCA_REPEAT_DELAY            0x00010000
133     #define SCA_TOGGLE                  0x00020000
134     #define SCA_FOCUS_ON_CLICK          0x00040000
135     #define SCA_IMAGE_POSITION          0x00080000
136 
137 	// attributes of the office:forms element
138 	enum OfficeFormsAttributes
139 	{
140 		ofaAutomaticFocus,
141 		ofaApplyDesignMode
142 	};
143 
144 	//=====================================================================
145 	//= OAttributeMetaData
146 	//=====================================================================
147 	/** allows the translation of attribute ids into strings.
148 
149 		<p>This class does not allow to connect xml attributes to property names or
150 		something like that, it only deals with the xml side</p>
151 	*/
152 	class OAttributeMetaData
153 	{
154 	public:
155 		/** calculates the xml attribute representation of a common control attribute.
156 			@param _nId
157 				the id of the attribute. Has to be one of the CCA_* constants.
158 		*/
159 		static const sal_Char* getCommonControlAttributeName(sal_Int32 _nId);
160 
161 		/** calculates the xml namespace key to use for a common control attribute
162 			@param _nId
163 				the id of the attribute. Has to be one of the CCA_* constants.
164 		*/
165 		static sal_uInt16 getCommonControlAttributeNamespace(sal_Int32 _nId);
166 
167 		/** retrieves the name of an attribute of a form xml representation
168 			@param	_eAttrib
169 				enum value specifying the attribute
170 		*/
171 		static const sal_Char* getFormAttributeName(FormAttributes _eAttrib);
172 
173 		/** calculates the xml namespace key to use for a attribute of a form xml representation
174 			@param	_eAttrib
175 				enum value specifying the attribute
176 		*/
177 		static sal_uInt16 getFormAttributeNamespace(FormAttributes _eAttrib);
178 
179 		/** calculates the xml attribute representation of a database attribute.
180 			@param _nId
181 				the id of the attribute. Has to be one of the DA_* constants.
182 		*/
183 		static const sal_Char* getDatabaseAttributeName(sal_Int32 _nId);
184 
185 		/** calculates the xml namespace key to use for a database attribute.
186 			@param _nId
187 				the id of the attribute. Has to be one of the DA_* constants.
188 		*/
189 		static sal_uInt16 getDatabaseAttributeNamespace(sal_Int32 _nId);
190 
191 		/** calculates the xml attribute representation of a special attribute.
192 			@param _nId
193 				the id of the attribute. Has to be one of the SCA_* constants.
194 		*/
195 		static const sal_Char* getSpecialAttributeName(sal_Int32 _nId);
196 
197 		/** calculates the xml attribute representation of a binding attribute.
198 			@param _nId
199 				the id of the attribute. Has to be one of the BA_* constants.
200 		*/
201 		static const sal_Char* getBindingAttributeName(sal_Int32 _nId);
202 
203         /** calculates the xml namespace key to use for a binding attribute.
204 			@param _nId
205 				the id of the attribute. Has to be one of the BA_* constants.
206 		*/
207 		static sal_uInt16 getBindingAttributeNamespace(sal_Int32 _nId);
208 
209         /** calculates the xml namespace key to use for a special attribute.
210 			@param _nId
211 				the id of the attribute. Has to be one of the SCA_* constants.
212 		*/
213 		static sal_uInt16 getSpecialAttributeNamespace(sal_Int32 _nId);
214 
215 		/** calculates the xml attribute representation of a attribute of the office:forms element
216 			@param _nId
217 				the id of the attribute
218 		*/
219 		static const sal_Char* getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib);
220 
221 		/** calculates the xml namedspace key of a attribute of the office:forms element
222 			@param _nId
223 				the id of the attribute
224 		*/
225 		static sal_uInt16 getOfficeFormsAttributeNamespace(OfficeFormsAttributes _eAttrib);
226 	};
227 
228 	//=====================================================================
229 	//= OAttribute2Property
230 	//=====================================================================
231 	/** some kind of opposite to the OAttributeMetaData class. Able to translate
232 		attributes into property names/types
233 
234 		<p>The construction of this class is rather expensive (or at least it's initialization from outside),
235 		so it should be shared</p>
236 	*/
237 	class OAttribute2Property
238 	{
239 	public:
240 		// TODO: maybe the following struct should be used for exports, too. In this case we would not need to
241 		// store it's instances in a map, but in a vector for faster access.
242 		struct AttributeAssignment
243 		{
244 			::rtl::OUString					sAttributeName;			// the attribute name
245 			::rtl::OUString					sPropertyName;			// the property name
246 			::com::sun::star::uno::Type		aPropertyType;			// the property type
247 			::rtl::OUString					sAttributeDefault;		// the default if the attribute is not present
248 
249 			// entries which are special to some value types
250 			const SvXMLEnumMapEntry*		pEnumMap;				// the enum map, if appliable
251 			sal_Bool						bInverseSemantics;		// for booleanss: attribute and property value have the same or an inverse semantics?
252 
AttributeAssignmentxmloff::OAttribute2Property::AttributeAssignment253 			AttributeAssignment() : pEnumMap(NULL), bInverseSemantics(sal_False) { }
254 		};
255 
256 	protected:
257 		DECLARE_STL_USTRINGACCESS_MAP( AttributeAssignment, AttributeAssignments );
258 		AttributeAssignments		m_aKnownProperties;
259 
260 	public:
261 		OAttribute2Property();
262 		virtual ~OAttribute2Property();
263 
264 		/** return the AttributeAssignment which corresponds to the given attribute
265 
266 			@param _rAttribName
267 				the name of the attribute
268 			@return
269 				a pointer to the <type>AttributeAssignment</type> structure as requested, NULL if the attribute
270 				does not represent a property.
271 		*/
272 		const AttributeAssignment* getAttributeTranslation(
273 			const ::rtl::OUString& _rAttribName);
274 
275 		/** add a attribute assignment referring to a string property to the map
276 			@param _pAttributeName
277 				the name of the attribute
278 			@param _rPropertyName
279 				the name of the property assigned to the attribute
280 			@param _pAttributeDefault
281 				the default value for the attribute, if any. May be NULL, in this case the default is assumed to be
282 				an empty string.
283 		*/
284 		void	addStringProperty(
285 			const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
286 			const sal_Char* _pAttributeDefault = NULL);
287 
288 		/** add a attribute assignment referring to a boolean property to the map
289 
290 			@param _pAttributeName
291 				the name of the attribute
292 			@param _rPropertyName
293 				the name of the property assigned to the attribute
294 			@param _bAttributeDefault
295 				the default value for the attribute.
296 			@param _bInverseSemantics
297 				if <TRUE/>, a attribute value of <TRUE/> means a property value of <FALSE/> and vice verse.<br/>
298 				if <FALSE/>, the attribute value is used as property value directly
299 		*/
300 		void	addBooleanProperty(
301 			const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
302 			const sal_Bool _bAttributeDefault, const sal_Bool _bInverseSemantics = sal_False);
303 
304 		/** add a attribute assignment referring to an int16 property to the map
305 
306 			@param _pAttributeName
307 				the name of the attribute
308 			@param _rPropertyName
309 				the name of the property assigned to the attribute
310 			@param _nAttributeDefault
311 				the default value for the attribute.
312 		*/
313 		void	addInt16Property(
314 			const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
315 			const sal_Int16 _nAttributeDefault);
316 
317 		/** add a attribute assignment referring to an int32 property to the map
318 
319 			@param _pAttributeName
320 				the name of the attribute
321 			@param _rPropertyName
322 				the name of the property assigned to the attribute
323 			@param _nAttributeDefault
324 				the default value for the attribute.
325 		*/
326 		void	addInt32Property(
327 			const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
328 			const sal_Int32 _nAttributeDefault );
329 
330 		/** add a attribute assignment referring to an enum property to the map
331 
332 			@param _pAttributeName
333 				the name of the attribute
334 			@param _rPropertyName
335 				the name of the property assigned to the attribute
336 			@param _nAttributeDefault
337 				the default value for the attribute, as (32bit) integer
338 			@param _pValueMap
339 				the map to translate strings into enum values
340 			@param _pType
341 				the type of the property. May be NULL, in this case 32bit integer is assumed.
342 		*/
343 		void	addEnumProperty(
344 			const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
345 			const sal_uInt16 _nAttributeDefault, const SvXMLEnumMapEntry* _pValueMap,
346 			const ::com::sun::star::uno::Type* _pType = NULL);
347 
348 	protected:
349 		/// some common code for the various add*Property methods
350 		AttributeAssignment& implAdd(
351 			const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName,
352 			const ::com::sun::star::uno::Type& _rType, const ::rtl::OUString& _rDefaultString);
353 	};
354 //.........................................................................
355 }	// namespace xmloff
356 //.........................................................................
357 
358 #endif // _XMLOFF_FORMATTRIBUTES_HXX_
359 
360