xref: /trunk/main/xmloff/source/forms/layerexport.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1ecfe53c5SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ecfe53c5SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ecfe53c5SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ecfe53c5SAndrew Rist  * distributed with this work for additional information
6ecfe53c5SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ecfe53c5SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ecfe53c5SAndrew Rist  * "License"); you may not use this file except in compliance
9ecfe53c5SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11ecfe53c5SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13ecfe53c5SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ecfe53c5SAndrew Rist  * software distributed under the License is distributed on an
15ecfe53c5SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ecfe53c5SAndrew Rist  * KIND, either express or implied.  See the License for the
17ecfe53c5SAndrew Rist  * specific language governing permissions and limitations
18ecfe53c5SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20ecfe53c5SAndrew Rist  *************************************************************/
21ecfe53c5SAndrew Rist 
22ecfe53c5SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _XMLOFF_FORMS_LAYEREXPORT_HXX_
25cdf0e10cSrcweir #define _XMLOFF_FORMS_LAYEREXPORT_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
28cdf0e10cSrcweir #include <com/sun/star/script/ScriptEventDescriptor.hpp>
29cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormats.hpp>
30cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp>
31cdf0e10cSrcweir #include "callbacks.hxx"
32cdf0e10cSrcweir #include "ifacecompare.hxx"
33cdf0e10cSrcweir #include <vos/ref.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir class SvXMLExport;
36cdf0e10cSrcweir class SvXMLNumFmtExport;
37cdf0e10cSrcweir class XMLPropertyHandlerFactory;
38cdf0e10cSrcweir class SvXMLExportPropertyMapper;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //.........................................................................
41cdf0e10cSrcweir namespace xmloff
42cdf0e10cSrcweir {
43cdf0e10cSrcweir //.........................................................................
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     typedef ::std::set  <   ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
46cdf0e10cSrcweir                         ,   OPropertySetCompare
47cdf0e10cSrcweir                         >   PropertySetBag;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     // maps objects (property sets) to strings, e.g. control ids.
50cdf0e10cSrcweir     typedef ::std::map  <   ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
51cdf0e10cSrcweir                         ,   ::rtl::OUString
52cdf0e10cSrcweir                         ,   OPropertySetCompare
53cdf0e10cSrcweir                         >   MapPropertySet2String;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     // map pages to maps (of property sets to strings)
56cdf0e10cSrcweir     typedef ::std::map  <   ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >
57cdf0e10cSrcweir                         ,   MapPropertySet2String
58cdf0e10cSrcweir                         ,   ODrawPageCompare
59cdf0e10cSrcweir                         >   MapPropertySet2Map;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     //=====================================================================
62cdf0e10cSrcweir     //= OFormLayerXMLExport_Impl
63cdf0e10cSrcweir     //=====================================================================
64cdf0e10cSrcweir     /** the implementation class for OFormLayerXMLExport
65cdf0e10cSrcweir     */
66cdf0e10cSrcweir     class OFormLayerXMLExport_Impl
67cdf0e10cSrcweir                 :public IFormsExportContext
68cdf0e10cSrcweir     {
69cdf0e10cSrcweir         friend class OFormLayerXMLExport;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     protected:
72cdf0e10cSrcweir         SvXMLExport&        m_rContext;
73cdf0e10cSrcweir         SvXMLNumFmtExport*  m_pControlNumberStyles;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         // ignore list for control models
76cdf0e10cSrcweir         PropertySetBag      m_aIgnoreList;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         // style handling
79cdf0e10cSrcweir         ::vos::ORef< XMLPropertyHandlerFactory >    m_xPropertyHandlerFactory;
80cdf0e10cSrcweir         ::vos::ORef< SvXMLExportPropertyMapper >    m_xStyleExportMapper;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         // we need our own number formats supplier:
83cdf0e10cSrcweir         // Controls which have a number formats do not work with the formats supplier of the document they reside
84cdf0e10cSrcweir         // in, instead they use the formats of the data source their form is associated with. If there is no
85cdf0e10cSrcweir         // such form or no such data source, they work with an own formatter.
86cdf0e10cSrcweir         // Even more, time and date fields do not work with a central formatter at all, they have their own one
87cdf0e10cSrcweir         // (which is shared internally, but this is a (hidden) implementation detail.)
88cdf0e10cSrcweir         //
89cdf0e10cSrcweir         // To not contaminate the global (document) number formats supplier (which could be obtained from the context),
90cdf0e10cSrcweir         // we have an own one.
91cdf0e10cSrcweir         // (Contaminate means: If a user adds a user-defined format to a formatted field, this format is stored in
92cdf0e10cSrcweir         // in the data source's formats supplier. To export this _and_ reuse existing structures, we would need to
93cdf0e10cSrcweir         // add this format to the global (document) formats supplier.
94cdf0e10cSrcweir         // In case of an export we could do some cleanup afterwards, but in case of an import, there is no such
95cdf0e10cSrcweir         // chance, as (if other user-defined formats exist in the document as well) we can't distinguish
96cdf0e10cSrcweir         // between user-defined formats really needed for the doc (i.e. in a calc cell) and formats only added
97cdf0e10cSrcweir         // to the supplier because the controls needed it.
98cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >
99cdf0e10cSrcweir                                                     m_xControlNumberFormats;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         MapPropertySet2Map  m_aControlIds;
102cdf0e10cSrcweir             // the control ids of all controls on all pages we ever examined
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         MapPropertySet2Map  m_aReferringControls;
105cdf0e10cSrcweir             // for a given page (iter->first), and a given control (iter->second->first), this is the comma-separated
10686e1cf34SPedro Giffuni             // lists of ids of the controls referring to the control given.
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         MapPropertySet2Map::iterator
109cdf0e10cSrcweir                             m_aCurrentPageIds;
110*2df387e6Smseidel             // the iterator for the control id map for the page being handled
111cdf0e10cSrcweir         MapPropertySet2Map::iterator
112cdf0e10cSrcweir                             m_aCurrentPageReferring;
113cdf0e10cSrcweir             // the same for the map of referring controls
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         // TODO: To avoid this construct above, and to have a cleaner implementation, an class encapsulating the
116cdf0e10cSrcweir         // export of a single page should be introduced.
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         DECLARE_STL_MAP( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >, sal_Int32, OPropertySetCompare, MapPropertySet2Int);
119cdf0e10cSrcweir         MapPropertySet2Int  m_aControlNumberFormats;
120cdf0e10cSrcweir             // maps controls to format keys, which are relative to our own formats supplier
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         MapPropertySet2String   m_aGridColumnStyles;
123cdf0e10cSrcweir             // style names of grid columns
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     public:
126cdf0e10cSrcweir         OFormLayerXMLExport_Impl(SvXMLExport& _rContext);
127cdf0e10cSrcweir         virtual ~OFormLayerXMLExport_Impl();
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     protected:
130cdf0e10cSrcweir         /** exports one single grid column
131cdf0e10cSrcweir         */
132cdf0e10cSrcweir         void    exportGridColumn(
133cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn,
134cdf0e10cSrcweir             const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rEvents
135cdf0e10cSrcweir             );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir         /** exports one single control
138cdf0e10cSrcweir         */
139cdf0e10cSrcweir         void    exportControl(
140cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl,
141cdf0e10cSrcweir             const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rEvents
142cdf0e10cSrcweir             );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         /** exports one single form
145cdf0e10cSrcweir         */
146cdf0e10cSrcweir         void    exportForm(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxProps,
147cdf0e10cSrcweir             const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rEvents
148cdf0e10cSrcweir             );
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         /** seek to the page given.
151cdf0e10cSrcweir 
152cdf0e10cSrcweir             <p>This must be called before you can retrieve any ids for controls on the page.</p>
153cdf0e10cSrcweir 
154cdf0e10cSrcweir             @see
155cdf0e10cSrcweir                 getControlId
156cdf0e10cSrcweir         */
157cdf0e10cSrcweir         sal_Bool    seekPage(
158cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage);
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         /** get the id of the given control.
161cdf0e10cSrcweir 
162cdf0e10cSrcweir             <p>You must have sought to the page of the control before calling this.</p>
163cdf0e10cSrcweir         */
164cdf0e10cSrcweir         ::rtl::OUString
165cdf0e10cSrcweir                 getControlId(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl);
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         /** retrieves the style name for the control's number style.
168cdf0e10cSrcweir 
169cdf0e10cSrcweir             <p>For performance reasons, this method is allowed to be called for any controls, even those which
170cdf0e10cSrcweir             do not have a number style. In this case, an empty string is returned.</p>
171cdf0e10cSrcweir         */
172cdf0e10cSrcweir         ::rtl::OUString
173cdf0e10cSrcweir                 getControlNumberStyle( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         // IFormsExportContext
176cdf0e10cSrcweir         virtual void                                        exportCollectionElements(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxCollection);
177cdf0e10cSrcweir         virtual SvXMLExport&                                getGlobalContext();
178cdf0e10cSrcweir         virtual ::rtl::OUString                             getObjectStyleName(
179cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject );
180cdf0e10cSrcweir         virtual ::vos::ORef< SvXMLExportPropertyMapper >    getStylePropertyMapper();
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         /** clear any structures which have been build in the recent <method>examine</method> calls.
183cdf0e10cSrcweir         */
184cdf0e10cSrcweir         void clear();
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         /** examine a forms collection.
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             <p>The method will collect control ids and add styles to the export context as necessary.</p>
189cdf0e10cSrcweir 
190cdf0e10cSrcweir             <p>Every control in the object hierarchy given will be assigned to a unique id, which is stored for later
191cdf0e10cSrcweir             use.</p>
192cdf0e10cSrcweir 
193cdf0e10cSrcweir             <p>In addition, any references the controls may have between each other, are collected and stored for
194cdf0e10cSrcweir             later use.</p>
195cdf0e10cSrcweir 
196cdf0e10cSrcweir             <p>Upon calling this method, the id map will be cleared before collecting the new ids, so any ids
197cdf0e10cSrcweir             you collected previously will be lost</p>
198cdf0e10cSrcweir 
199cdf0e10cSrcweir             @param _rxDrawPage
200cdf0e10cSrcweir                 the draw page which's forms collection should be examined
201cdf0e10cSrcweir 
202cdf0e10cSrcweir             @see getControlId
203cdf0e10cSrcweir             @see exportControl
204cdf0e10cSrcweir             @see exportForms
205cdf0e10cSrcweir         */
206cdf0e10cSrcweir         void examineForms(
207cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage);
208cdf0e10cSrcweir 
209cdf0e10cSrcweir         /** export a forms collection of a draw page
210cdf0e10cSrcweir 
211cdf0e10cSrcweir             <p>The method will obtain the forms collection of the page and call
212cdf0e10cSrcweir             <method>exportCollectionElements</method>.</p>
213cdf0e10cSrcweir         */
214cdf0e10cSrcweir         void exportForms(
215cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage);
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         /** exports the XForms model data
218cdf0e10cSrcweir         */
219cdf0e10cSrcweir         void exportXForms() const;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir         /** determines whether the given page contains logical forms
222cdf0e10cSrcweir         */
223cdf0e10cSrcweir         bool pageContainsForms( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage ) const;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         /** determines whether the given page contains XForm instances
226cdf0e10cSrcweir         */
227cdf0e10cSrcweir         bool documentContainsXForms() const;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir         /** exports the controls number styles
230cdf0e10cSrcweir         */
231cdf0e10cSrcweir         void    exportControlNumberStyles();
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         /** exports the automatic control number styles
234cdf0e10cSrcweir         */
235cdf0e10cSrcweir         void    exportAutoControlNumberStyles();
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         /** exports the auto-styles collected during the examineForms calls
238cdf0e10cSrcweir         */
239cdf0e10cSrcweir         void exportAutoStyles();
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     protected:
242cdf0e10cSrcweir         sal_Bool impl_isFormPageContainingForms(
243cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage,
244cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxForms);
245cdf0e10cSrcweir 
246cdf0e10cSrcweir         /** moves the m_aCurrentPage* members to the positions specifying the given page.
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             @return <TRUE/> if there already were structures for the given page
249cdf0e10cSrcweir         */
250cdf0e10cSrcweir         sal_Bool implMoveIterators(
251cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage,
252cdf0e10cSrcweir             sal_Bool _bClear);
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         /** check the object given if it's a control, if so, examine it.
255cdf0e10cSrcweir             @return <TRUE/> if the object has been handled
256cdf0e10cSrcweir         */
257cdf0e10cSrcweir         sal_Bool checkExamineControl(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject);
258cdf0e10cSrcweir 
259cdf0e10cSrcweir         /** examines the control's number format, so later the format style can be referred
260cdf0e10cSrcweir 
261cdf0e10cSrcweir             <p>remembers the format key for the control, so it can later be asked for in getControlNumberStyle</p>
262cdf0e10cSrcweir         */
263cdf0e10cSrcweir         void examineControlNumberFormat(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl);
264cdf0e10cSrcweir 
265cdf0e10cSrcweir         /** examines the control's number format, so later the format style can be referred
266cdf0e10cSrcweir 
267cdf0e10cSrcweir             <p>does not remember the information returned in any way</p>
268cdf0e10cSrcweir         */
269cdf0e10cSrcweir         sal_Int32 implExamineControlNumberFormat( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         /** collects AutoStyles for grid columns
272cdf0e10cSrcweir         */
273cdf0e10cSrcweir         void collectGridColumnStylesAndIds( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl );
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         /** ensures that the number format of the given control exist in our own formats supplier.
276cdf0e10cSrcweir 
277cdf0e10cSrcweir             <p>The given control is examined for it's format (i.e. it's FormatKey/FormatsSupplier properties),
278cdf0e10cSrcweir             and the format is added (if necessary) to m_xControlNumberFormats</p>.
279cdf0e10cSrcweir 
280cdf0e10cSrcweir             @return
281cdf0e10cSrcweir                 the format key of the control's format relative to our own formats supplier
282cdf0e10cSrcweir 
283cdf0e10cSrcweir         */
284cdf0e10cSrcweir         sal_Int32   ensureTranslateFormat(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormattedControl);
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         /// returns the instance exporting our control's number styles
287cdf0e10cSrcweir         SvXMLNumFmtExport*  getControlNumberStyleExport();
288cdf0e10cSrcweir 
289cdf0e10cSrcweir         /// ensures that the instance exporting our control's number styles exists
290cdf0e10cSrcweir         void                ensureControlNumberStyleExport();
291cdf0e10cSrcweir 
292cdf0e10cSrcweir         /** determines the number format style for the given object without remembering it
293cdf0e10cSrcweir         */
294cdf0e10cSrcweir         ::rtl::OUString
295cdf0e10cSrcweir                 getImmediateNumberStyle( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject );
296cdf0e10cSrcweir 
297cdf0e10cSrcweir         /** returns the prefix to be used for control number styles
298cdf0e10cSrcweir         */
299cdf0e10cSrcweir         static const ::rtl::OUString& getControlNumberStyleNamePrefix();
300cdf0e10cSrcweir 
301cdf0e10cSrcweir         /** exclude the given control (model) from export.
302cdf0e10cSrcweir 
303cdf0e10cSrcweir             <p>If your document contains form controls which are not to be exported for whatever reason,
304cdf0e10cSrcweir             you need to announce the models of these controls (can be retrieved from XControlShape::getControl)
305cdf0e10cSrcweir             to the form layer exporter.<br/>
306cdf0e10cSrcweir             Of course you have to do this before calling <member>exportForms</member></p>
307cdf0e10cSrcweir         */
308cdf0e10cSrcweir         void excludeFromExport( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > _rxControl );
309cdf0e10cSrcweir     };
310cdf0e10cSrcweir 
311cdf0e10cSrcweir //.........................................................................
312cdf0e10cSrcweir }   // namespace xmloff
313cdf0e10cSrcweir //.........................................................................
314cdf0e10cSrcweir 
315cdf0e10cSrcweir #endif // _XMLOFF_FORMS_LAYEREXPORT_HXX_
316