merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / forms / layerexport.hxx
blob6d3a318bfd353223b829f59a8d7d72ace8a4a77c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: layerexport.hxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _XMLOFF_FORMS_LAYEREXPORT_HXX_
32 #define _XMLOFF_FORMS_LAYEREXPORT_HXX_
34 #include <com/sun/star/container/XIndexAccess.hpp>
35 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
36 #include <com/sun/star/util/XNumberFormats.hpp>
37 #include <com/sun/star/awt/XControlModel.hpp>
38 #include "callbacks.hxx"
39 #include "ifacecompare.hxx"
40 #include <vos/ref.hxx>
42 class SvXMLExport;
43 class SvXMLNumFmtExport;
44 class XMLPropertyHandlerFactory;
45 class SvXMLExportPropertyMapper;
47 //.........................................................................
48 namespace xmloff
50 //.........................................................................
52 typedef ::std::set < ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
53 , OPropertySetCompare
54 > PropertySetBag;
56 // maps objects (property sets) to strings, e.g. control ids.
57 typedef ::std::map < ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
58 , ::rtl::OUString
59 , OPropertySetCompare
60 > MapPropertySet2String;
62 // map pages to maps (of property sets to strings)
63 typedef ::std::map < ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >
64 , MapPropertySet2String
65 , ODrawPageCompare
66 > MapPropertySet2Map;
68 //=====================================================================
69 //= OFormLayerXMLExport_Impl
70 //=====================================================================
71 /** the implementation class for OFormLayerXMLExport
73 class OFormLayerXMLExport_Impl
74 :public IFormsExportContext
76 friend class OFormLayerXMLExport;
78 protected:
79 SvXMLExport& m_rContext;
80 SvXMLNumFmtExport* m_pControlNumberStyles;
82 // ignore list for control models
83 PropertySetBag m_aIgnoreList;
85 // style handling
86 ::vos::ORef< XMLPropertyHandlerFactory > m_xPropertyHandlerFactory;
87 ::vos::ORef< SvXMLExportPropertyMapper > m_xStyleExportMapper;
89 // we need our own number formats supplier:
90 // Controls which have a number formats do not work with the formats supplier of the document they reside
91 // in, instead they use the formats of the data source their form is associated with. If there is no
92 // such form or no such data source, they work with an own formatter.
93 // Even more, time and date fields do not work with a central formatter at all, they have their own one
94 // (which is shared internally, but this is a (hidden) implementation detail.)
96 // To not contaminate the global (document) number formats supplier (which could be obtained from the context),
97 // we have an own one.
98 // (Contaminate means: If a user adds a user-defined format to a formatted field, this format is stored in
99 // in the data source's formats supplier. To export this _and_ reuse existing structures, we would need to
100 // add this format to the global (document) formats supplier.
101 // In case of an export we could do some cleanup afterwards, but in case of an import, there is no such
102 // chance, as (if other user-defined formats exist in the document as well) we can't distinguish
103 // between user-defined formats really needed for the doc (i.e. in a calc cell) and formats only added
104 // to the supplier because the controls needed it.
105 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >
106 m_xControlNumberFormats;
108 MapPropertySet2Map m_aControlIds;
109 // the control ids of all controls on all pages we ever examined
111 MapPropertySet2Map m_aReferringControls;
112 // for a given page (iter->first), and a given control (iter->second->first), this is the comma-separated
113 // lists of ids of the controls refering to the control given.
115 MapPropertySet2Map::iterator
116 m_aCurrentPageIds;
117 // the iterator for the control id map for the page beeing handled
118 MapPropertySet2Map::iterator
119 m_aCurrentPageReferring;
120 // the same for the map of referring controls
122 // TODO: To avoid this construct above, and to have a cleaner implementation, an class encapsulating the
123 // export of a single page should be introduced.
125 DECLARE_STL_MAP( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >, sal_Int32, OPropertySetCompare, MapPropertySet2Int);
126 MapPropertySet2Int m_aControlNumberFormats;
127 // maps controls to format keys, which are relative to our own formats supplier
129 MapPropertySet2String m_aGridColumnStyles;
130 // style names of grid columns
132 public:
133 OFormLayerXMLExport_Impl(SvXMLExport& _rContext);
134 virtual ~OFormLayerXMLExport_Impl();
136 protected:
137 /** exports one single grid column
139 void exportGridColumn(
140 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn,
141 const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rEvents
144 /** exports one single control
146 void exportControl(
147 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl,
148 const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rEvents
151 /** exports one single form
153 void exportForm(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxProps,
154 const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rEvents
157 /** seek to the page given.
159 <p>This must be called before you can retrieve any ids for controls on the page.</p>
161 @see
162 getControlId
164 sal_Bool seekPage(
165 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage);
167 /** get the id of the given control.
169 <p>You must have sought to the page of the control before calling this.</p>
171 ::rtl::OUString
172 getControlId(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl);
174 /** retrieves the style name for the control's number style.
176 <p>For performance reasons, this method is allowed to be called for any controls, even those which
177 do not have a number style. In this case, an empty string is returned.</p>
179 ::rtl::OUString
180 getControlNumberStyle( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl );
182 // IFormsExportContext
183 virtual void exportCollectionElements(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxCollection);
184 virtual SvXMLExport& getGlobalContext();
185 virtual ::rtl::OUString getObjectStyleName(
186 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject );
187 virtual ::vos::ORef< SvXMLExportPropertyMapper > getStylePropertyMapper();
189 /** clear any structures which have been build in the recent <method>examine</method> calls.
191 void clear();
193 /** examine a forms collection.
195 <p>The method will collect control ids and add styles to the export context as necessary.</p>
197 <p>Every control in the object hierarchy given will be assigned to a unique id, which is stored for later
198 use.</p>
200 <p>In addition, any references the controls may have between each other, are collected and stored for
201 later use.</p>
203 <p>Upon calling this method, the id map will be cleared before collecting the new ids, so any ids
204 you collected previously will be lost</p>
206 @param _rxDrawPage
207 the draw page which's forms collection should be examined
209 @see getControlId
210 @see exportControl
211 @see exportForms
213 void examineForms(
214 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage);
216 /** export a forms collection of a draw page
218 <p>The method will obtain the forms collection of the page and call
219 <method>exportCollectionElements</method>.</p>
221 void exportForms(
222 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage);
224 /** exports the XForms model data
226 void exportXForms() const;
228 /** determines whether the given page contains logical forms
230 bool pageContainsForms( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage ) const;
232 /** determines whether the given page contains XForm instances
234 bool documentContainsXForms() const;
236 /** exports the controls number styles
238 void exportControlNumberStyles();
240 /** exports the automatic control number styles
242 void exportAutoControlNumberStyles();
244 /** exports the auto-styles collected during the examineForms calls
246 void exportAutoStyles();
248 protected:
249 sal_Bool impl_isFormPageContainingForms(
250 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage,
251 ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxForms);
253 /** moves the m_aCurrentPage* members to the positions specifying the given page.
255 @return <TRUE/> if there already were structures for the given page
257 sal_Bool implMoveIterators(
258 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage,
259 sal_Bool _bClear);
261 /** check the object given if it's a control, if so, examine it.
262 @return <TRUE/> if the object has been handled
264 sal_Bool checkExamineControl(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject);
266 /** examines the control's number format, so later the format style can be referred
268 <p>remembers the format key for the control, so it can later be asked for in getControlNumberStyle</p>
270 void examineControlNumberFormat(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl);
272 /** examines the control's number format, so later the format style can be referred
274 <p>does not remember the information returned in any way</p>
276 sal_Int32 implExamineControlNumberFormat( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject );
278 /** collects AutoStyles for grid columns
280 void collectGridColumnStylesAndIds( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl );
282 /** ensures that the number format of the given control exist in our own formats supplier.
284 <p>The given control is examined for it's format (i.e. it's FormatKey/FormatsSupplier properties),
285 and the format is added (if necessary) to m_xControlNumberFormats</p>.
287 @return
288 the format key of the control's format relative to our own formats supplier
291 sal_Int32 ensureTranslateFormat(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormattedControl);
293 /// returns the instance exporting our control's number styles
294 SvXMLNumFmtExport* getControlNumberStyleExport();
296 /// ensures that the instance exporting our control's number styles exists
297 void ensureControlNumberStyleExport();
299 /** determines the number format style for the given object without remembering it
301 ::rtl::OUString
302 getImmediateNumberStyle( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject );
304 /** returns the prefix to be used for control number styles
306 static const ::rtl::OUString& getControlNumberStyleNamePrefix();
308 /** exclude the given control (model) from export.
310 <p>If your document contains form controls which are not to be exported for whatever reason,
311 you need to announce the models of these controls (can be retrieved from XControlShape::getControl)
312 to the form layer exporter.<br/>
313 Of course you have to do this before calling <member>exportForms</member></p>
315 void excludeFromExport( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > _rxControl );
318 //.........................................................................
319 } // namespace xmloff
320 //.........................................................................
322 #endif // _XMLOFF_FORMS_LAYEREXPORT_HXX_