tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / forms / layerexport.hxx
blobd1296cd07e35e493f170d8b1127db3f017f26876
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 #pragma once
22 #include <sal/config.h>
24 #include <unordered_map>
26 #include <com/sun/star/container/XIndexAccess.hpp>
27 #include <com/sun/star/drawing/XDrawPage.hpp>
28 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
29 #include <com/sun/star/util/XNumberFormats.hpp>
30 #include <com/sun/star/awt/XControlModel.hpp>
31 #include "callbacks.hxx"
32 #include <rtl/ref.hxx>
33 #include <o3tl/sorted_vector.hxx>
35 class SvXMLExport;
36 class SvXMLNumFmtExport;
37 class XMLPropertyHandlerFactory;
38 class SvXMLExportPropertyMapper;
40 namespace xmloff
43 typedef o3tl::sorted_vector< css::uno::Reference< css::beans::XPropertySet > > PropertySetBag;
45 // maps objects (property sets) to strings, e.g. control ids.
46 typedef ::std::unordered_map < css::uno::Reference< css::beans::XPropertySet >
47 , OUString
48 > MapPropertySet2String;
50 // map pages to maps (of property sets to strings)
51 typedef ::std::unordered_map < css::uno::Reference< css::drawing::XDrawPage >
52 , MapPropertySet2String
53 > MapPropertySet2Map;
55 //= OFormLayerXMLExport_Impl
56 /** the implementation class for OFormLayerXMLExport
58 class OFormLayerXMLExport_Impl
59 :public IFormsExportContext
61 friend class OFormLayerXMLExport;
63 SvXMLExport& m_rContext;
64 std::unique_ptr<SvXMLNumFmtExport> m_pControlNumberStyles;
66 // ignore list for control models
67 PropertySetBag m_aIgnoreList;
69 // style handling
70 ::rtl::Reference< XMLPropertyHandlerFactory > m_xPropertyHandlerFactory;
71 ::rtl::Reference< SvXMLExportPropertyMapper > m_xStyleExportMapper;
73 // we need our own number formats supplier:
74 // Controls which have a number formats do not work with the formats supplier of the document they reside
75 // in, instead they use the formats of the data source their form is associated with. If there is no
76 // such form or no such data source, they work with an own formatter.
77 // Even more, time and date fields do not work with a central formatter at all, they have their own one
78 // (which is shared internally, but this is a (hidden) implementation detail.)
80 // To not contaminate the global (document) number formats supplier (which could be obtained from the context),
81 // we have an own one.
82 // (Contaminate means: If a user adds a user-defined format to a formatted field, this format is stored in
83 // in the data source's formats supplier. To export this _and_ reuse existing structures, we would need to
84 // add this format to the global (document) formats supplier.
85 // In case of an export we could do some cleanup afterwards, but in case of an import, there is no such
86 // chance, as (if other user-defined formats exist in the document as well) we can't distinguish
87 // between user-defined formats really needed for the doc (i.e. in a calc cell) and formats only added
88 // to the supplier because the controls needed it.
89 css::uno::Reference< css::util::XNumberFormats >
90 m_xControlNumberFormats;
92 MapPropertySet2Map m_aControlIds;
93 // the control ids of all controls on all pages we ever examined
95 MapPropertySet2Map m_aReferringControls;
96 // for a given page (iter->first), and a given control (iter->second->first), this is the comma-separated
97 // lists of ids of the controls referring to the control given.
99 MapPropertySet2Map::iterator
100 m_aCurrentPageIds;
101 // the iterator for the control id map for the page being handled
102 MapPropertySet2Map::iterator
103 m_aCurrentPageReferring;
104 // the same for the map of referring controls
106 // TODO: To avoid this construct above, and to have a cleaner implementation, a class encapsulating the
107 // export of a single page should be introduced.
109 typedef std::unordered_map<css::uno::Reference<css::beans::XPropertySet>, sal_Int32> MapPropertySet2Int;
110 MapPropertySet2Int m_aControlNumberFormats;
111 // maps controls to format keys, which are relative to our own formats supplier
113 MapPropertySet2String m_aGridColumnStyles;
114 // style names of grid columns
116 public:
117 explicit OFormLayerXMLExport_Impl(SvXMLExport& _rContext);
118 virtual ~OFormLayerXMLExport_Impl();
120 private:
121 /** exports one single grid column
123 void exportGridColumn(
124 const css::uno::Reference< css::beans::XPropertySet >& _rxColumn,
125 const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rEvents
128 /** exports one single control
130 void exportControl(
131 const css::uno::Reference< css::beans::XPropertySet >& _rxControl,
132 const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rEvents
135 /** exports one single form
137 void exportForm(const css::uno::Reference< css::beans::XPropertySet >& _rxProps,
138 const css::uno::Sequence< css::script::ScriptEventDescriptor >& _rEvents
141 /** seek to the page given.
143 <p>This must be called before you can retrieve any ids for controls on the page.</p>
145 @see
146 getControlId
148 bool seekPage(
149 const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage);
151 /** get the id of the given control.
153 <p>You must have sought to the page of the control before calling this.</p>
155 OUString
156 getControlId(const css::uno::Reference< css::beans::XPropertySet >& _rxControl);
158 /** retrieves the style name for the control's number style.
160 <p>For performance reasons, this method is allowed to be called for any controls, even those which
161 do not have a number style. In this case, an empty string is returned.</p>
163 OUString
164 getControlNumberStyle( const css::uno::Reference< css::beans::XPropertySet >& _rxControl );
166 // IFormsExportContext
167 virtual void exportCollectionElements(const css::uno::Reference< css::container::XIndexAccess >& _rxCollection) override;
168 virtual SvXMLExport& getGlobalContext() override;
169 virtual OUString getObjectStyleName(
170 const css::uno::Reference< css::beans::XPropertySet >& _rxObject ) override;
171 virtual ::rtl::Reference< SvXMLExportPropertyMapper > getStylePropertyMapper() override;
173 /** clear any structures which have been build in the recent <method>examine</method> calls.
175 void clear();
177 /** examine a forms collection.
179 <p>The method will collect control ids and add styles to the export context as necessary.</p>
181 <p>Every control in the object hierarchy given will be assigned to a unique id, which is stored for later
182 use.</p>
184 <p>In addition, any references the controls may have between each other, are collected and stored for
185 later use.</p>
187 <p>Upon calling this method, the id map will be cleared before collecting the new ids, so any ids
188 you collected previously will be lost</p>
190 @param _rxDrawPage
191 the draw page which's forms collection should be examined
193 @see getControlId
194 @see exportControl
195 @see exportForms
197 void examineForms(
198 const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage);
200 /** export a forms collection of a draw page
202 <p>The method will obtain the forms collection of the page and call
203 <method>exportCollectionElements</method>.</p>
205 void exportForms(
206 const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage);
208 /** exports the XForms model data
210 void exportXForms() const;
212 /** determines whether the given page contains logical forms
214 static bool pageContainsForms( const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage );
216 /** determines whether the given page contains XForm instances
218 bool documentContainsXForms() const;
220 /** exports the automatic control number styles
222 void exportAutoControlNumberStyles();
224 /** exports the auto-styles collected during the examineForms calls
226 void exportAutoStyles();
228 static bool impl_isFormPageContainingForms(
229 const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage,
230 css::uno::Reference< css::container::XIndexAccess >& _rxForms);
232 /** moves the m_aCurrentPage* members to the positions specifying the given page.
234 @return <TRUE/> if there already were structures for the given page
236 bool implMoveIterators(
237 const css::uno::Reference< css::drawing::XDrawPage >& _rxDrawPage,
238 bool _bClear);
240 /** check the object given if it's a control, if so, examine it.
241 @return <TRUE/> if the object has been handled
243 bool checkExamineControl(const css::uno::Reference< css::beans::XPropertySet >& _rxObject);
245 /** examines the control's number format, so later the format style can be referred
247 <p>remembers the format key for the control, so it can later be asked for in getControlNumberStyle</p>
249 void examineControlNumberFormat(const css::uno::Reference< css::beans::XPropertySet >& _rxControl);
251 /** examines the control's number format, so later the format style can be referred
253 <p>does not remember the information returned in any way</p>
255 sal_Int32 implExamineControlNumberFormat( const css::uno::Reference< css::beans::XPropertySet >& _rxObject );
257 /** collects AutoStyles for grid columns
259 void collectGridColumnStylesAndIds( const css::uno::Reference< css::beans::XPropertySet >& _rxControl );
261 /** ensures that the number format of the given control exist in our own formats supplier.
263 <p>The given control is examined for its format (i.e. it's FormatKey/FormatsSupplier properties),
264 and the format is added (if necessary) to m_xControlNumberFormats</p>.
266 @return
267 the format key of the control's format relative to our own formats supplier
270 sal_Int32 ensureTranslateFormat(const css::uno::Reference< css::beans::XPropertySet >& _rxFormattedControl);
272 /// returns the instance exporting our control's number styles
273 SvXMLNumFmtExport* getControlNumberStyleExport();
275 /// ensures that the instance exporting our control's number styles exists
276 void ensureControlNumberStyleExport();
278 /** determines the number format style for the given object without remembering it
280 OUString
281 getImmediateNumberStyle( const css::uno::Reference< css::beans::XPropertySet >& _rxObject );
283 /** returns the prefix to be used for control number styles
285 static const OUString& getControlNumberStyleNamePrefix();
287 /** exclude the given control (model) from export.
289 <p>If your document contains form controls which are not to be exported for whatever reason,
290 you need to announce the models of these controls (can be retrieved from XControlShape::getControl)
291 to the form layer exporter.<br/>
292 Of course you have to do this before calling <member>exportForms</member></p>
294 void excludeFromExport( const css::uno::Reference< css::awt::XControlModel >& _rxControl );
297 } // namespace xmloff
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */