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