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