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