bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / forms / layerexport.hxx
blobbd25986b478e47f1d072401a09940ed0c43a6d64
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _XMLOFF_FORMS_LAYEREXPORT_HXX_
21 #define _XMLOFF_FORMS_LAYEREXPORT_HXX_
23 #include <com/sun/star/container/XIndexAccess.hpp>
24 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
25 #include <com/sun/star/util/XNumberFormats.hpp>
26 #include <com/sun/star/awt/XControlModel.hpp>
27 #include "callbacks.hxx"
28 #include "ifacecompare.hxx"
29 #include <rtl/ref.hxx>
31 class SvXMLExport;
32 class SvXMLNumFmtExport;
33 class XMLPropertyHandlerFactory;
34 class SvXMLExportPropertyMapper;
36 //.........................................................................
37 namespace xmloff
39 //.........................................................................
41 typedef ::std::set < ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
42 , OPropertySetCompare
43 > PropertySetBag;
45 // maps objects (property sets) to strings, e.g. control ids.
46 typedef ::std::map < ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
47 , OUString
48 , OPropertySetCompare
49 > MapPropertySet2String;
51 // map pages to maps (of property sets to strings)
52 typedef ::std::map < ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >
53 , MapPropertySet2String
54 , ODrawPageCompare
55 > MapPropertySet2Map;
57 //=====================================================================
58 //= OFormLayerXMLExport_Impl
59 //=====================================================================
60 /** the implementation class for OFormLayerXMLExport
62 class OFormLayerXMLExport_Impl
63 :public IFormsExportContext
65 friend class OFormLayerXMLExport;
67 protected:
68 SvXMLExport& m_rContext;
69 SvXMLNumFmtExport* m_pControlNumberStyles;
71 // ignore list for control models
72 PropertySetBag m_aIgnoreList;
74 // style handling
75 ::rtl::Reference< XMLPropertyHandlerFactory > m_xPropertyHandlerFactory;
76 ::rtl::Reference< SvXMLExportPropertyMapper > m_xStyleExportMapper;
78 // we need our own number formats supplier:
79 // Controls which have a number formats do not work with the formats supplier of the document they reside
80 // in, instead they use the formats of the data source their form is associated with. If there is no
81 // such form or no such data source, they work with an own formatter.
82 // Even more, time and date fields do not work with a central formatter at all, they have their own one
83 // (which is shared internally, but this is a (hidden) implementation detail.)
85 // To not contaminate the global (document) number formats supplier (which could be obtained from the context),
86 // we have an own one.
87 // (Contaminate means: If a user adds a user-defined format to a formatted field, this format is stored in
88 // in the data source's formats supplier. To export this _and_ reuse existing structures, we would need to
89 // add this format to the global (document) formats supplier.
90 // In case of an export we could do some cleanup afterwards, but in case of an import, there is no such
91 // chance, as (if other user-defined formats exist in the document as well) we can't distinguish
92 // between user-defined formats really needed for the doc (i.e. in a calc cell) and formats only added
93 // to the supplier because the controls needed it.
94 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >
95 m_xControlNumberFormats;
97 MapPropertySet2Map m_aControlIds;
98 // the control ids of all controls on all pages we ever examined
100 MapPropertySet2Map m_aReferringControls;
101 // for a given page (iter->first), and a given control (iter->second->first), this is the comma-separated
102 // lists of ids of the controls refering to the control given.
104 MapPropertySet2Map::iterator
105 m_aCurrentPageIds;
106 // the iterator for the control id map for the page beeing handled
107 MapPropertySet2Map::iterator
108 m_aCurrentPageReferring;
109 // the same for the map of referring controls
111 // TODO: To avoid this construct above, and to have a cleaner implementation, an class encapsulating the
112 // export of a single page should be introduced.
114 DECLARE_STL_MAP( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >, sal_Int32, OPropertySetCompare, MapPropertySet2Int);
115 MapPropertySet2Int m_aControlNumberFormats;
116 // maps controls to format keys, which are relative to our own formats supplier
118 MapPropertySet2String m_aGridColumnStyles;
119 // style names of grid columns
121 public:
122 OFormLayerXMLExport_Impl(SvXMLExport& _rContext);
123 virtual ~OFormLayerXMLExport_Impl();
125 protected:
126 /** exports one single grid column
128 void exportGridColumn(
129 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn,
130 const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rEvents
133 /** exports one single control
135 void exportControl(
136 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl,
137 const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rEvents
140 /** exports one single form
142 void exportForm(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxProps,
143 const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _rEvents
146 /** seek to the page given.
148 <p>This must be called before you can retrieve any ids for controls on the page.</p>
150 @see
151 getControlId
153 sal_Bool seekPage(
154 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage);
156 /** get the id of the given control.
158 <p>You must have sought to the page of the control before calling this.</p>
160 OUString
161 getControlId(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl);
163 /** retrieves the style name for the control's number style.
165 <p>For performance reasons, this method is allowed to be called for any controls, even those which
166 do not have a number style. In this case, an empty string is returned.</p>
168 OUString
169 getControlNumberStyle( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl );
171 // IFormsExportContext
172 virtual void exportCollectionElements(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxCollection);
173 virtual SvXMLExport& getGlobalContext();
174 virtual OUString getObjectStyleName(
175 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject );
176 virtual ::rtl::Reference< SvXMLExportPropertyMapper > getStylePropertyMapper();
178 /** clear any structures which have been build in the recent <method>examine</method> calls.
180 void clear();
182 /** examine a forms collection.
184 <p>The method will collect control ids and add styles to the export context as necessary.</p>
186 <p>Every control in the object hierarchy given will be assigned to a unique id, which is stored for later
187 use.</p>
189 <p>In addition, any references the controls may have between each other, are collected and stored for
190 later use.</p>
192 <p>Upon calling this method, the id map will be cleared before collecting the new ids, so any ids
193 you collected previously will be lost</p>
195 @param _rxDrawPage
196 the draw page which's forms collection should be examined
198 @see getControlId
199 @see exportControl
200 @see exportForms
202 void examineForms(
203 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage);
205 /** export a forms collection of a draw page
207 <p>The method will obtain the forms collection of the page and call
208 <method>exportCollectionElements</method>.</p>
210 void exportForms(
211 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage);
213 /** exports the XForms model data
215 void exportXForms() const;
217 /** determines whether the given page contains logical forms
219 bool pageContainsForms( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage ) const;
221 /** determines whether the given page contains XForm instances
223 bool documentContainsXForms() const;
225 /** exports the automatic control number styles
227 void exportAutoControlNumberStyles();
229 /** exports the auto-styles collected during the examineForms calls
231 void exportAutoStyles();
233 protected:
234 sal_Bool impl_isFormPageContainingForms(
235 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage,
236 ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxForms);
238 /** moves the m_aCurrentPage* members to the positions specifying the given page.
240 @return <TRUE/> if there already were structures for the given page
242 sal_Bool implMoveIterators(
243 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& _rxDrawPage,
244 sal_Bool _bClear);
246 /** check the object given if it's a control, if so, examine it.
247 @return <TRUE/> if the object has been handled
249 sal_Bool checkExamineControl(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject);
251 /** examines the control's number format, so later the format style can be referred
253 <p>remembers the format key for the control, so it can later be asked for in getControlNumberStyle</p>
255 void examineControlNumberFormat(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl);
257 /** examines the control's number format, so later the format style can be referred
259 <p>does not remember the information returned in any way</p>
261 sal_Int32 implExamineControlNumberFormat( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject );
263 /** collects AutoStyles for grid columns
265 void collectGridColumnStylesAndIds( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControl );
267 /** ensures that the number format of the given control exist in our own formats supplier.
269 <p>The given control is examined for it's format (i.e. it's FormatKey/FormatsSupplier properties),
270 and the format is added (if necessary) to m_xControlNumberFormats</p>.
272 @return
273 the format key of the control's format relative to our own formats supplier
276 sal_Int32 ensureTranslateFormat(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormattedControl);
278 /// returns the instance exporting our control's number styles
279 SvXMLNumFmtExport* getControlNumberStyleExport();
281 /// ensures that the instance exporting our control's number styles exists
282 void ensureControlNumberStyleExport();
284 /** determines the number format style for the given object without remembering it
286 OUString
287 getImmediateNumberStyle( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject );
289 /** returns the prefix to be used for control number styles
291 static const OUString& getControlNumberStyleNamePrefix();
293 /** exclude the given control (model) from export.
295 <p>If your document contains form controls which are not to be exported for whatever reason,
296 you need to announce the models of these controls (can be retrieved from XControlShape::getControl)
297 to the form layer exporter.<br/>
298 Of course you have to do this before calling <member>exportForms</member></p>
300 void excludeFromExport( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > _rxControl );
303 //.........................................................................
304 } // namespace xmloff
305 //.........................................................................
307 #endif // _XMLOFF_FORMS_LAYEREXPORT_HXX_
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */