Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / forms / layerexport.hxx
blob0577a801a095641aaaf1c5012df41488be7aa8e5
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 INCLUDED_XMLOFF_SOURCE_FORMS_LAYEREXPORT_HXX
21 #define INCLUDED_XMLOFF_SOURCE_FORMS_LAYEREXPORT_HXX
23 #include <sal/config.h>
25 #include <map>
26 #include <set>
28 #include <com/sun/star/container/XIndexAccess.hpp>
29 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
30 #include <com/sun/star/util/XNumberFormats.hpp>
31 #include <com/sun/star/awt/XControlModel.hpp>
32 #include "callbacks.hxx"
33 #include "ifacecompare.hxx"
34 #include <rtl/ref.hxx>
36 class SvXMLExport;
37 class SvXMLNumFmtExport;
38 class XMLPropertyHandlerFactory;
39 class SvXMLExportPropertyMapper;
41 namespace xmloff
44 typedef ::std::set < css::uno::Reference< css::beans::XPropertySet >
45 , OPropertySetCompare
46 > PropertySetBag;
48 // maps objects (property sets) to strings, e.g. control ids.
49 typedef ::std::map < css::uno::Reference< css::beans::XPropertySet >
50 , OUString
51 , OPropertySetCompare
52 > MapPropertySet2String;
54 // map pages to maps (of property sets to strings)
55 typedef ::std::map < css::uno::Reference< css::drawing::XDrawPage >
56 , MapPropertySet2String
57 , ODrawPageCompare
58 > MapPropertySet2Map;
60 //= OFormLayerXMLExport_Impl
61 /** the implementation class for OFormLayerXMLExport
63 class OFormLayerXMLExport_Impl
64 :public IFormsExportContext
66 friend class OFormLayerXMLExport;
68 protected:
69 SvXMLExport& m_rContext;
70 SvXMLNumFmtExport* m_pControlNumberStyles;
72 // ignore list for control models
73 PropertySetBag m_aIgnoreList;
75 // style handling
76 ::rtl::Reference< XMLPropertyHandlerFactory > m_xPropertyHandlerFactory;
77 ::rtl::Reference< SvXMLExportPropertyMapper > m_xStyleExportMapper;
79 // we need our own number formats supplier:
80 // Controls which have a number formats do not work with the formats supplier of the document they reside
81 // in, instead they use the formats of the data source their form is associated with. If there is no
82 // such form or no such data source, they work with an own formatter.
83 // Even more, time and date fields do not work with a central formatter at all, they have their own one
84 // (which is shared internally, but this is a (hidden) implementation detail.)
86 // To not contaminate the global (document) number formats supplier (which could be obtained from the context),
87 // we have an own one.
88 // (Contaminate means: If a user adds a user-defined format to a formatted field, this format is stored in
89 // in the data source's formats supplier. To export this _and_ reuse existing structures, we would need to
90 // add this format to the global (document) formats supplier.
91 // In case of an export we could do some cleanup afterwards, but in case of an import, there is no such
92 // chance, as (if other user-defined formats exist in the document as well) we can't distinguish
93 // between user-defined formats really needed for the doc (i.e. in a calc cell) and formats only added
94 // to the supplier because the controls needed it.
95 css::uno::Reference< css::util::XNumberFormats >
96 m_xControlNumberFormats;
98 MapPropertySet2Map m_aControlIds;
99 // the control ids of all controls on all pages we ever examined
101 MapPropertySet2Map m_aReferringControls;
102 // for a given page (iter->first), and a given control (iter->second->first), this is the comma-separated
103 // lists of ids of the controls referring to the control given.
105 MapPropertySet2Map::iterator
106 m_aCurrentPageIds;
107 // the iterator for the control id map for the page being handled
108 MapPropertySet2Map::iterator
109 m_aCurrentPageReferring;
110 // the same for the map of referring controls
112 // TODO: To avoid this construct above, and to have a cleaner implementation, an class encapsulating the
113 // export of a single page should be introduced.
115 typedef std::map<css::uno::Reference<css::beans::XPropertySet>, sal_Int32, OPropertySetCompare> MapPropertySet2Int;
116 MapPropertySet2Int m_aControlNumberFormats;
117 // maps controls to format keys, which are relative to our own formats supplier
119 MapPropertySet2String m_aGridColumnStyles;
120 // style names of grid columns
122 public:
123 explicit OFormLayerXMLExport_Impl(SvXMLExport& _rContext);
124 virtual ~OFormLayerXMLExport_Impl();
126 protected:
127 /** exports one single grid column
129 void exportGridColumn(
130 const css::uno::Reference< css::beans::XPropertySet >& _rxColumn,
131 const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rEvents
134 /** exports one single control
136 void exportControl(
137 const css::uno::Reference< css::beans::XPropertySet >& _rxControl,
138 const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rEvents
141 /** exports one single form
143 void exportForm(const css::uno::Reference< css::beans::XPropertySet >& _rxProps,
144 const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rEvents
147 /** seek to the page given.
149 <p>This must be called before you can retrieve any ids for controls on the page.</p>
151 @see
152 getControlId
154 bool seekPage(
155 const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage);
157 /** get the id of the given control.
159 <p>You must have sought to the page of the control before calling this.</p>
161 OUString
162 getControlId(const css::uno::Reference< css::beans::XPropertySet >& _rxControl);
164 /** retrieves the style name for the control's number style.
166 <p>For performance reasons, this method is allowed to be called for any controls, even those which
167 do not have a number style. In this case, an empty string is returned.</p>
169 OUString
170 getControlNumberStyle( const css::uno::Reference< css::beans::XPropertySet >& _rxControl );
172 // IFormsExportContext
173 virtual void exportCollectionElements(const css::uno::Reference< css::container::XIndexAccess >& _rxCollection) override;
174 virtual SvXMLExport& getGlobalContext() override;
175 virtual OUString getObjectStyleName(
176 const css::uno::Reference< css::beans::XPropertySet >& _rxObject ) override;
177 virtual ::rtl::Reference< SvXMLExportPropertyMapper > getStylePropertyMapper() override;
179 /** clear any structures which have been build in the recent <method>examine</method> calls.
181 void clear();
183 /** examine a forms collection.
185 <p>The method will collect control ids and add styles to the export context as necessary.</p>
187 <p>Every control in the object hierarchy given will be assigned to a unique id, which is stored for later
188 use.</p>
190 <p>In addition, any references the controls may have between each other, are collected and stored for
191 later use.</p>
193 <p>Upon calling this method, the id map will be cleared before collecting the new ids, so any ids
194 you collected previously will be lost</p>
196 @param _rxDrawPage
197 the draw page which's forms collection should be examined
199 @see getControlId
200 @see exportControl
201 @see exportForms
203 void examineForms(
204 const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage);
206 /** export a forms collection of a draw page
208 <p>The method will obtain the forms collection of the page and call
209 <method>exportCollectionElements</method>.</p>
211 void exportForms(
212 const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage);
214 /** exports the XForms model data
216 void exportXForms() const;
218 /** determines whether the given page contains logical forms
220 static bool pageContainsForms( const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage );
222 /** determines whether the given page contains XForm instances
224 bool documentContainsXForms() const;
226 /** exports the automatic control number styles
228 void exportAutoControlNumberStyles();
230 /** exports the auto-styles collected during the examineForms calls
232 void exportAutoStyles();
234 protected:
235 static bool impl_isFormPageContainingForms(
236 const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage,
237 css::uno::Reference< css::container::XIndexAccess >& _rxForms);
239 /** moves the m_aCurrentPage* members to the positions specifying the given page.
241 @return <TRUE/> if there already were structures for the given page
243 bool implMoveIterators(
244 const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage,
245 bool _bClear);
247 /** check the object given if it's a control, if so, examine it.
248 @return <TRUE/> if the object has been handled
250 bool checkExamineControl(const css::uno::Reference< css::beans::XPropertySet >& _rxObject);
252 /** examines the control's number format, so later the format style can be referred
254 <p>remembers the format key for the control, so it can later be asked for in getControlNumberStyle</p>
256 void examineControlNumberFormat(const css::uno::Reference< css::beans::XPropertySet >& _rxControl);
258 /** examines the control's number format, so later the format style can be referred
260 <p>does not remember the information returned in any way</p>
262 sal_Int32 implExamineControlNumberFormat( const css::uno::Reference< css::beans::XPropertySet >& _rxObject );
264 /** collects AutoStyles for grid columns
266 void collectGridColumnStylesAndIds( const css::uno::Reference< css::beans::XPropertySet >& _rxControl );
268 /** ensures that the number format of the given control exist in our own formats supplier.
270 <p>The given control is examined for its format (i.e. it's FormatKey/FormatsSupplier properties),
271 and the format is added (if necessary) to m_xControlNumberFormats</p>.
273 @return
274 the format key of the control's format relative to our own formats supplier
277 sal_Int32 ensureTranslateFormat(const css::uno::Reference< css::beans::XPropertySet >& _rxFormattedControl);
279 /// returns the instance exporting our control's number styles
280 SvXMLNumFmtExport* getControlNumberStyleExport();
282 /// ensures that the instance exporting our control's number styles exists
283 void ensureControlNumberStyleExport();
285 /** determines the number format style for the given object without remembering it
287 OUString
288 getImmediateNumberStyle( const css::uno::Reference< css::beans::XPropertySet >& _rxObject );
290 /** returns the prefix to be used for control number styles
292 static const OUString& getControlNumberStyleNamePrefix();
294 /** exclude the given control (model) from export.
296 <p>If your document contains form controls which are not to be exported for whatever reason,
297 you need to announce the models of these controls (can be retrieved from XControlShape::getControl)
298 to the form layer exporter.<br/>
299 Of course you have to do this before calling <member>exportForms</member></p>
301 void excludeFromExport( const css::uno::Reference< css::awt::XControlModel >& _rxControl );
304 } // namespace xmloff
306 #endif // INCLUDED_XMLOFF_SOURCE_FORMS_LAYEREXPORT_HXX
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */