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_ELEMENTEXPORT_HXX_
25 #define _XMLOFF_ELEMENTEXPORT_HXX_
26 
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/container/XIndexAccess.hpp>
29 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
30 #include "propertyexport.hxx"
31 #include "callbacks.hxx"
32 #include "controlelement.hxx"
33 #include "valueproperties.hxx"
34 
35 class SvXMLElementExport;
36 //.........................................................................
37 namespace xmloff
38 {
39 //.........................................................................
40 
41 	//=====================================================================
42 	//= OElementExport
43 	//=====================================================================
44 	class OElementExport : public OPropertyExport
45 	{
46 	protected:
47 		::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >
48 								m_aEvents;
49 
50 		SvXMLElementExport*		m_pXMLElement;			// XML element doing the concrete startElement etc.
51 
52 	public:
53 		OElementExport(IFormsExportContext& _rContext,
54 			const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxProps,
55 			const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rEvents);
56 		virtual ~OElementExport();
57 
58 		void doExport();
59 
60 	protected:
61 		/// get the name of the XML element
62 		virtual const sal_Char* getXMLElementName() const = 0;
63 		/// examine the element we're exporting
64 		virtual void examine();
65 		/// export the attributes
66 		virtual void exportAttributes();
67 		/// export any sub tags
68 		virtual void exportSubTags();
69 
70 		/** exports the events (as script:events tag)
71 		*/
72 		void exportEvents();
73 
74 		/** add the service-name attribute to the export context
75 		*/
76 		virtual void exportServiceNameAttribute();
77 
78 		/// start the XML element
79 		virtual void implStartElement(const sal_Char* _pName);
80 
81 		/// ends the XML element
82 		virtual void implEndElement();
83 	};
84 
85 	//=====================================================================
86 	//= OControlExport
87 	//=====================================================================
88 	/** Helper class for handling xml elements representing a form control
89 	*/
90 	class OControlExport
91 				:public OControlElement
92 				,public OValuePropertiesMetaData
93 				,public OElementExport
94 	{
95 	protected:
96 		DECLARE_STL_STDKEY_SET(sal_Int16, Int16Set);
97 			// used below
98 
99 		::rtl::OUString			m_sControlId;			// the control id to use when exporting
100 		::rtl::OUString			m_sReferringControls;	// list of referring controls (i.e. their id's)
101 		sal_Int16				m_nClassId;				// class id of the control we're representing
102 		ElementType				m_eType;				// (XML) type of the control we're representing
103 		sal_Int32				m_nIncludeCommon;		// common control attributes to include
104 		sal_Int32				m_nIncludeDatabase;		// common database attributes to include
105 		sal_Int32				m_nIncludeSpecial;		// special attributes to include
106 		sal_Int32				m_nIncludeEvents;		// events to include
107 		sal_Int32               m_nIncludeBindings;	    // binding attributes to include
108 
109 		SvXMLElementExport*		m_pOuterElement;		// XML element doing the concrete startElement etc. for the outer element
110 
111 	public:
112 		/** constructs an object capable of exporting controls
113 
114 			<p>You need at least two pre-requisites from outside: The control to be exported needs to have a class id
115 			assigned, and you need the list control-ids of all the controls referring to this one as LabelControl.<br/>
116 			This information can't be collected when known only the control itself and not it's complete context.</p>
117 
118 			@param _rControlId
119 				the control id to use when exporting the control
120 			@param _rReferringControls
121 				the comma-separated list of control-ids of all the controls referring to this one as LabelControl
122 		*/
123 		OControlExport(IFormsExportContext& _rContext,
124 			const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl,
125 			const ::rtl::OUString& _rControlId,
126 			const ::rtl::OUString& _rReferringControls,
127 			const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rxEvents);
128 		~OControlExport();
129 
130 	protected:
131 		/// start the XML element
132 		virtual void implStartElement(const sal_Char* _pName);
133 
134 		/// ends the XML element
135 		virtual void implEndElement();
136 
137 		/// get the name of the outer XML element
138 		virtual const sal_Char* getOuterXMLElementName() const;
139 
140 		// get the name of the XML element
141 		virtual const sal_Char* getXMLElementName() const;
142 
143 		/** examine the control. Some kind of CtorImpl.
144 		*/
145 		virtual void examine();
146 
147 		/// exports the attributes for the outer element
148 		void exportOuterAttributes();
149 
150 		/// exports the attributes for the inner element
151 		void exportInnerAttributes();
152 
153 		/// export the attributes
154 		virtual void exportAttributes();
155 
156 		/** writes everything which needs to be represented as sub tag
157 		*/
158 		void exportSubTags() throw (::com::sun::star::uno::Exception);
159 
160         /** adds the attributes which are handled via generic IPropertyHandlers
161 
162             <p>In the future, this really should be *all* attributes, instead of this shitload of
163             hand-crafted code we have currently ...</p>
164         */
165         void exportGenericHandlerAttributes();
166 
167 		/**	adds common control attributes to the XMLExport context given
168 
169 			<p>The attribute list of the context is not cleared initially, this is the responsibility of the caller.</p>
170 		*/
171 		void exportCommonControlAttributes();
172 
173 		/**	adds database attributes to the XMLExport context given
174 
175 			<p>The attribute list of the context is not cleared initially, this is the responsibility of the caller.</p>
176 		*/
177 		void exportDatabaseAttributes();
178 
179 		/**	adds the XML attributes which are related to binding controls to
180             external values and/or list sources
181 		*/
182 		void exportBindingAtributes();
183 
184 		/** adds attributes which are special to a control type to the export context's attribute list
185 		*/
186 		void exportSpecialAttributes();
187 
188 		/** exports the ListSource property of a control as attribute
189 
190 			The ListSource property may be exported in different ways: For a ComboBox, it is an attribute
191 			of the form:combobox element.
192 
193 			For a ListBox, it's an attribute if the ListSourceType states that the ListBox does <em>not</em>
194 			display a value list. In case of a value list, the ListSource is not exported, and the pairs of
195 			StringItem/ValueItem are exported as sub-elements.
196 
197 			This method does the attribute part: It exports the ListSource property as attribute, not caring
198 			about whether the object is a ComboBox or a ListBox.
199 		*/
200 		void exportListSourceAsAttribute();
201 
202 		/** exports the ListSource property of a control as XML elements
203 
204 			@see exportListSourceAsAttribute
205 		*/
206 		void exportListSourceAsElements();
207 
208 		/** get's a Sequence&lt; sal_Int16 &gt; property value as set of sal_Int16's
209 			@param _rPropertyName
210 				the property name to use
211 			@param _rOut
212 				out parameter. The set of integers.
213 		*/
214 		void getSequenceInt16PropertyAsSet(const ::rtl::OUString& _rPropertyName, Int16Set& _rOut);
215 
216         /** exports the attribute which descrives a cell value binding of a control
217             in a spreadsheet document
218         */
219         void exportCellBindingAttributes( bool _bIncludeListLinkageType );
220 
221         /** exports the attribute(s) which bind this control to XForms */
222         void exportXFormsBindAttributes();
223 
224         /** exports the attribute(s) which bind the list of a list
225             control to XForms */
226         void exportXFormsListAttributes();
227 
228         /** exports the attribute(s) for an XForms submission */
229         void exportXFormsSubmissionAttributes();
230 
231         /** exports the attribute which descrives a cell range which acts as list source for
232             a list-like control
233         */
234         void exportCellListSourceRange( );
235 
236         /** exports the attribut(s) for the ImagePosition property
237         */
238         void exportImagePositionAttributes();
239 
240         /** determines whether the control we're exporting has an active data binding.
241 
242             Bindings which count here are:
243             <ul><li>an established connection to a database field</li>
244                 <li>a binding to an external value supplier (<type scope="com::sun::star::form::binding">XValueBinding</type>)</li>
245             </ul>
246         */
247         bool controlHasActiveDataBinding() const;
248 
249         /** retrieves the string specifying the ListSource of a list or combo box
250         */
251         ::rtl::OUString getScalarListSourceValue() const;
252 
253         /** determines whether the list entries (of a combo or list box) are supplied by the user
254 
255             List entries may be
256             <ul><li>specified by the user</li>
257                 <li>specified by an external list source (<type scope="com::sun::star::form::binding">XListEntrySource</type>)</li>
258                 <li>obtained from a database query (in various ways)</li>
259             </ul>
260 
261             In the latter two cases, this method will return <FALSE/>
262         */
263         bool controlHasUserSuppliedListEntries() const;
264 	};
265 
266 	//=====================================================================
267 	//= OColumnExport
268 	//=====================================================================
269 	/** Helper class for exporting a grid column
270 	*/
271 	class OColumnExport : public OControlExport
272 	{
273 	public:
274 		/** ctor
275 			@see OColumnExport::OColumnExport
276 		*/
277 		OColumnExport(IFormsExportContext& _rContext,
278 			const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl,
279             const ::rtl::OUString& _rControlId,
280 			const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rxEvents);
281 
282 		~OColumnExport();
283 
284 	protected:
285 		// OControlExport overridables
286 		virtual const sal_Char* getOuterXMLElementName() const;
287 		virtual void exportServiceNameAttribute();
288 		virtual void exportAttributes();
289 
290 		// OElementExport overridables
291 		virtual void examine();
292 	};
293 
294 	//=====================================================================
295 	//= OFormExport
296 	//=====================================================================
297 	/** Helper class for handling xml elements representing a form
298 
299 		<p>In opposite to the class <type>OControlExport</type>, OFormExport is unable to export a <em>complete</em>
300 		form. Instead the client has to care for sub elements of the form itself.</p>
301 	*/
302 	class OFormExport
303 				:public OControlElement
304 				,public OElementExport
305 	{
306 		sal_Bool m_bCreateConnectionResourceElement;
307 	public:
308 		/** constructs an object capable of exporting controls
309 		*/
310 		OFormExport(IFormsExportContext& _rContext,
311 			const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxForm,
312 			const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rxEvents
313 			);
314 
315 	protected:
316 		virtual const sal_Char* getXMLElementName() const;
317 		virtual void exportSubTags();
318 		virtual void exportAttributes();
319 	};
320 //.........................................................................
321 }	// namespace xmloff
322 //.........................................................................
323 
324 #endif // _XMLOFF_ELEMENTEXPORT_HXX_
325 
326