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