xref: /trunk/main/xmloff/source/forms/layerexport.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <stdio.h>
32*cdf0e10cSrcweir #include "layerexport.hxx"
33*cdf0e10cSrcweir #include "strings.hxx"
34*cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
35*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
36*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
37*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
38*cdf0e10cSrcweir #include <xmloff/xmlprmap.hxx>
39*cdf0e10cSrcweir #include <xmloff/prhdlfac.hxx>
40*cdf0e10cSrcweir #include "elementexport.hxx"
41*cdf0e10cSrcweir #include <xmloff/families.hxx>
42*cdf0e10cSrcweir #include <xmloff/contextid.hxx>
43*cdf0e10cSrcweir #include <xmloff/controlpropertyhdl.hxx>
44*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
45*cdf0e10cSrcweir #include "controlpropertymap.hxx"
46*cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/form/XFormsSupplier2.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/xforms/XFormsSupplier.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/script/XEventAttacherManager.hpp>
53*cdf0e10cSrcweir #include "eventexport.hxx"
54*cdf0e10cSrcweir #include <xmloff/XMLEventExport.hxx>
55*cdf0e10cSrcweir #include "formevents.hxx"
56*cdf0e10cSrcweir #include <xmloff/xmlnumfe.hxx>
57*cdf0e10cSrcweir #include "xmloff/xformsexport.hxx"
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir /** === begin UNO includes === **/
60*cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
61*cdf0e10cSrcweir /** === end UNO includes === **/
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #include <numeric>
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir //.........................................................................
66*cdf0e10cSrcweir namespace xmloff
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir //.........................................................................
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
71*cdf0e10cSrcweir     using namespace ::com::sun::star::awt;
72*cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
73*cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
74*cdf0e10cSrcweir     using namespace ::com::sun::star::container;
75*cdf0e10cSrcweir     using namespace ::com::sun::star::drawing;
76*cdf0e10cSrcweir     using namespace ::com::sun::star::form;
77*cdf0e10cSrcweir     using namespace ::com::sun::star::script;
78*cdf0e10cSrcweir     using namespace ::com::sun::star::util;
79*cdf0e10cSrcweir     using namespace ::com::sun::star::text;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     typedef ::com::sun::star::xforms::XFormsSupplier XXFormsSupplier;
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     //=====================================================================
84*cdf0e10cSrcweir     //= OFormLayerXMLExport_Impl
85*cdf0e10cSrcweir     //=====================================================================
86*cdf0e10cSrcweir     //---------------------------------------------------------------------
87*cdf0e10cSrcweir     const ::rtl::OUString& OFormLayerXMLExport_Impl::getControlNumberStyleNamePrefix()
88*cdf0e10cSrcweir     {
89*cdf0e10cSrcweir         static const ::rtl::OUString s_sControlNumberStyleNamePrefix = ::rtl::OUString::createFromAscii("C");
90*cdf0e10cSrcweir         return s_sControlNumberStyleNamePrefix;
91*cdf0e10cSrcweir     }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     //---------------------------------------------------------------------
94*cdf0e10cSrcweir     OFormLayerXMLExport_Impl::OFormLayerXMLExport_Impl(SvXMLExport& _rContext)
95*cdf0e10cSrcweir         :m_rContext(_rContext)
96*cdf0e10cSrcweir         ,m_pControlNumberStyles(NULL)
97*cdf0e10cSrcweir     {
98*cdf0e10cSrcweir         initializePropertyMaps();
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir         // add our style family to the export context's style pool
101*cdf0e10cSrcweir         m_xPropertyHandlerFactory = new OControlPropertyHandlerFactory();
102*cdf0e10cSrcweir         ::vos::ORef< XMLPropertySetMapper > xStylePropertiesMapper = new XMLPropertySetMapper( getControlStylePropertyMap(), m_xPropertyHandlerFactory.getBodyPtr() );
103*cdf0e10cSrcweir         m_xStyleExportMapper = new OFormComponentStyleExportMapper( xStylePropertiesMapper.getBodyPtr() );
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         // our style family
106*cdf0e10cSrcweir         m_rContext.GetAutoStylePool()->AddFamily(
107*cdf0e10cSrcweir             XML_STYLE_FAMILY_CONTROL_ID, token::GetXMLToken(token::XML_PARAGRAPH),
108*cdf0e10cSrcweir             m_xStyleExportMapper.getBodyPtr(),
109*cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_CONTROL_PREFIX) )
110*cdf0e10cSrcweir         );
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir         // add our event translation table
113*cdf0e10cSrcweir         m_rContext.GetEventExport().AddTranslationTable(g_pFormsEventTranslation);
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir         clear();
116*cdf0e10cSrcweir     }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     OFormLayerXMLExport_Impl::~OFormLayerXMLExport_Impl()
119*cdf0e10cSrcweir     {
120*cdf0e10cSrcweir     }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     //---------------------------------------------------------------------
123*cdf0e10cSrcweir     sal_Bool OFormLayerXMLExport_Impl::impl_isFormPageContainingForms(const Reference< XDrawPage >& _rxDrawPage, Reference< XIndexAccess >& _rxForms)
124*cdf0e10cSrcweir     {
125*cdf0e10cSrcweir         Reference< XFormsSupplier2 > xFormsSupp(_rxDrawPage, UNO_QUERY);
126*cdf0e10cSrcweir         OSL_ENSURE(xFormsSupp.is(), "OFormLayerXMLExport_Impl::impl_isFormPageContainingForms: invalid draw page (no XFormsSupplier)! Doin' nothing!");
127*cdf0e10cSrcweir         if (!xFormsSupp.is())
128*cdf0e10cSrcweir             return sal_False;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir         if ( !xFormsSupp->hasForms() )
131*cdf0e10cSrcweir             // nothing to do at all
132*cdf0e10cSrcweir             return sal_False;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir         _rxForms = Reference< XIndexAccess >(xFormsSupp->getForms(), UNO_QUERY);
135*cdf0e10cSrcweir         Reference< XServiceInfo > xSI(_rxForms, UNO_QUERY); // order is important!
136*cdf0e10cSrcweir         OSL_ENSURE(xSI.is(), "OFormLayerXMLExport_Impl::impl_isFormPageContainingForms: invalid collection (must not be NULL and must have a ServiceInfo)!");
137*cdf0e10cSrcweir         if (!xSI.is())
138*cdf0e10cSrcweir             return sal_False;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         if (!xSI->supportsService(SERVICE_FORMSCOLLECTION))
141*cdf0e10cSrcweir         {
142*cdf0e10cSrcweir             OSL_ENSURE(sal_False, "OFormLayerXMLExport_Impl::impl_isFormPageContainingForms: invalid collection (is no com.sun.star.form.Forms)!");
143*cdf0e10cSrcweir             // nothing to do
144*cdf0e10cSrcweir             return sal_False;
145*cdf0e10cSrcweir         }
146*cdf0e10cSrcweir         return sal_True;
147*cdf0e10cSrcweir     }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     //---------------------------------------------------------------------
150*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::exportGridColumn(const Reference< XPropertySet >& _rxColumn,
151*cdf0e10cSrcweir         const Sequence< ScriptEventDescriptor >& _rEvents)
152*cdf0e10cSrcweir     {
153*cdf0e10cSrcweir         // do the exporting
154*cdf0e10cSrcweir         OColumnExport aExportImpl(*this, _rxColumn, getControlId( _rxColumn ), _rEvents);
155*cdf0e10cSrcweir         aExportImpl.doExport();
156*cdf0e10cSrcweir     }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     //---------------------------------------------------------------------
159*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::exportControl(const Reference< XPropertySet >& _rxControl,
160*cdf0e10cSrcweir         const Sequence< ScriptEventDescriptor >& _rEvents)
161*cdf0e10cSrcweir     {
162*cdf0e10cSrcweir         // the list of the referring controls
163*cdf0e10cSrcweir         ::rtl::OUString sReferringControls;
164*cdf0e10cSrcweir         MapPropertySet2String::const_iterator aReferring = m_aCurrentPageReferring->second.find(_rxControl);
165*cdf0e10cSrcweir         if (aReferring != m_aCurrentPageReferring->second.end())
166*cdf0e10cSrcweir             sReferringControls = aReferring->second;
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir         // the control id (should already have been created in examineForms)
169*cdf0e10cSrcweir         ::rtl::OUString sControlId( getControlId( _rxControl ) );
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir         // do the exporting
172*cdf0e10cSrcweir         OControlExport aExportImpl(*this, _rxControl, sControlId, sReferringControls, _rEvents);
173*cdf0e10cSrcweir         aExportImpl.doExport();
174*cdf0e10cSrcweir     }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     //---------------------------------------------------------------------
177*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::exportForm(const Reference< XPropertySet >& _rxProps,
178*cdf0e10cSrcweir         const Sequence< ScriptEventDescriptor >& _rEvents)
179*cdf0e10cSrcweir     {
180*cdf0e10cSrcweir         OSL_ENSURE(_rxProps.is(), "OFormLayerXMLExport_Impl::exportForm: invalid property set!");
181*cdf0e10cSrcweir         OFormExport aAttributeHandler(*this, _rxProps, _rEvents);
182*cdf0e10cSrcweir         aAttributeHandler.doExport();
183*cdf0e10cSrcweir     }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     //---------------------------------------------------------------------
186*cdf0e10cSrcweir     ::vos::ORef< SvXMLExportPropertyMapper > OFormLayerXMLExport_Impl::getStylePropertyMapper()
187*cdf0e10cSrcweir     {
188*cdf0e10cSrcweir         return m_xStyleExportMapper;
189*cdf0e10cSrcweir     }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     //---------------------------------------------------------------------
192*cdf0e10cSrcweir     SvXMLExport& OFormLayerXMLExport_Impl::getGlobalContext()
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir         return m_rContext;
195*cdf0e10cSrcweir     }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir     //---------------------------------------------------------------------
198*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::exportCollectionElements(const Reference< XIndexAccess >& _rxCollection)
199*cdf0e10cSrcweir     {
200*cdf0e10cSrcweir         // step through all the elements of the collection
201*cdf0e10cSrcweir         sal_Int32 nElements = _rxCollection->getCount();
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir         Reference< XEventAttacherManager > xElementEventManager(_rxCollection, UNO_QUERY);
204*cdf0e10cSrcweir         Sequence< ScriptEventDescriptor > aElementEvents;
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir         Reference< XPropertySetInfo > xPropsInfo;
207*cdf0e10cSrcweir         Reference< XIndexAccess > xCurrentContainer;
208*cdf0e10cSrcweir         for (sal_Int32 i=0; i<nElements; ++i)
209*cdf0e10cSrcweir         {
210*cdf0e10cSrcweir             try
211*cdf0e10cSrcweir             {
212*cdf0e10cSrcweir                 // extract the current element
213*cdf0e10cSrcweir                 Reference< XPropertySet > xCurrentProps( _rxCollection->getByIndex(i), UNO_QUERY );
214*cdf0e10cSrcweir                 OSL_ENSURE(xCurrentProps.is(), "OFormLayerXMLExport_Impl::exportCollectionElements: invalid child element, skipping!");
215*cdf0e10cSrcweir                 if (!xCurrentProps.is())
216*cdf0e10cSrcweir                     continue;
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir                 // check if there is a ClassId property on the current element. If so, we assume it to be a control
219*cdf0e10cSrcweir                 xPropsInfo = xCurrentProps->getPropertySetInfo();
220*cdf0e10cSrcweir                 OSL_ENSURE(xPropsInfo.is(), "OFormLayerXMLExport_Impl::exportCollectionElements: no property set info!");
221*cdf0e10cSrcweir                 if (!xPropsInfo.is())
222*cdf0e10cSrcweir                     // without this, a lot of stuff in the export routines may fail
223*cdf0e10cSrcweir                     continue;
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir                 // if the element is part of a ignore list, we are not allowed to export it
226*cdf0e10cSrcweir                 if ( m_aIgnoreList.end() != m_aIgnoreList.find( xCurrentProps ) )
227*cdf0e10cSrcweir                     continue;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir                 if (xElementEventManager.is())
230*cdf0e10cSrcweir                     aElementEvents = xElementEventManager->getScriptEvents(i);
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir                 if (xPropsInfo->hasPropertyByName(PROPERTY_COLUMNSERVICENAME))
233*cdf0e10cSrcweir                 {
234*cdf0e10cSrcweir                     exportGridColumn(xCurrentProps, aElementEvents);
235*cdf0e10cSrcweir                 }
236*cdf0e10cSrcweir                 else if (xPropsInfo->hasPropertyByName(PROPERTY_CLASSID))
237*cdf0e10cSrcweir                 {
238*cdf0e10cSrcweir                     exportControl(xCurrentProps, aElementEvents);
239*cdf0e10cSrcweir                 }
240*cdf0e10cSrcweir                 else
241*cdf0e10cSrcweir                 {
242*cdf0e10cSrcweir                     exportForm(xCurrentProps, aElementEvents);
243*cdf0e10cSrcweir                 }
244*cdf0e10cSrcweir             }
245*cdf0e10cSrcweir             catch(Exception&)
246*cdf0e10cSrcweir             {
247*cdf0e10cSrcweir                 OSL_ENSURE(sal_False, "OFormLayerXMLExport_Impl::exportCollectionElements: caught an exception ... skipping the current element!");
248*cdf0e10cSrcweir                 continue;
249*cdf0e10cSrcweir             }
250*cdf0e10cSrcweir         }
251*cdf0e10cSrcweir     }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     //---------------------------------------------------------------------
254*cdf0e10cSrcweir     ::rtl::OUString OFormLayerXMLExport_Impl::getObjectStyleName( const Reference< XPropertySet >& _rxObject )
255*cdf0e10cSrcweir     {
256*cdf0e10cSrcweir         ::rtl::OUString aObjectStyle;
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir         MapPropertySet2String::const_iterator aObjectStylePos = m_aGridColumnStyles.find( _rxObject );
259*cdf0e10cSrcweir         if ( m_aGridColumnStyles.end() != aObjectStylePos )
260*cdf0e10cSrcweir             aObjectStyle = aObjectStylePos->second;
261*cdf0e10cSrcweir         return aObjectStyle;
262*cdf0e10cSrcweir     }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     //---------------------------------------------------------------------
265*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::clear()
266*cdf0e10cSrcweir     {
267*cdf0e10cSrcweir         m_aControlIds.clear();
268*cdf0e10cSrcweir         m_aReferringControls.clear();
269*cdf0e10cSrcweir         m_aCurrentPageIds = m_aControlIds.end();
270*cdf0e10cSrcweir         m_aCurrentPageReferring = m_aReferringControls.end();
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir         m_aControlNumberFormats.clear();
273*cdf0e10cSrcweir         m_aGridColumnStyles.clear();
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir         m_aIgnoreList.clear();
276*cdf0e10cSrcweir     }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     //---------------------------------------------------------------------
279*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::exportControlNumberStyles()
280*cdf0e10cSrcweir     {
281*cdf0e10cSrcweir         if (m_pControlNumberStyles)
282*cdf0e10cSrcweir             m_pControlNumberStyles->Export(sal_False);
283*cdf0e10cSrcweir     }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir     //---------------------------------------------------------------------
286*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::exportAutoControlNumberStyles()
287*cdf0e10cSrcweir     {
288*cdf0e10cSrcweir         if ( m_pControlNumberStyles )
289*cdf0e10cSrcweir             m_pControlNumberStyles->Export( sal_True );
290*cdf0e10cSrcweir     }
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     //---------------------------------------------------------------------
293*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::exportAutoStyles()
294*cdf0e10cSrcweir     {
295*cdf0e10cSrcweir         m_rContext.GetAutoStylePool()->exportXML(
296*cdf0e10cSrcweir             XML_STYLE_FAMILY_CONTROL_ID,
297*cdf0e10cSrcweir             m_rContext.GetDocHandler(),
298*cdf0e10cSrcweir             m_rContext.GetMM100UnitConverter(),
299*cdf0e10cSrcweir             m_rContext.GetNamespaceMap()
300*cdf0e10cSrcweir         );
301*cdf0e10cSrcweir     }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir     //---------------------------------------------------------------------
304*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::exportForms(const Reference< XDrawPage >& _rxDrawPage)
305*cdf0e10cSrcweir     {
306*cdf0e10cSrcweir         // get the forms collection of the page
307*cdf0e10cSrcweir         Reference< XIndexAccess > xCollectionIndex;
308*cdf0e10cSrcweir         if (!impl_isFormPageContainingForms(_rxDrawPage, xCollectionIndex))
309*cdf0e10cSrcweir             return;
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
312*cdf0e10cSrcweir         sal_Bool bPageIsKnown =
313*cdf0e10cSrcweir #endif
314*cdf0e10cSrcweir             implMoveIterators(_rxDrawPage, sal_False);
315*cdf0e10cSrcweir         OSL_ENSURE(bPageIsKnown, "OFormLayerXMLExport_Impl::exportForms: exporting a page which has not been examined!");
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir         // export forms collection
318*cdf0e10cSrcweir         exportCollectionElements(xCollectionIndex);
319*cdf0e10cSrcweir     }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     //---------------------------------------------------------------------
322*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::exportXForms() const
323*cdf0e10cSrcweir     {
324*cdf0e10cSrcweir         // export XForms models
325*cdf0e10cSrcweir         ::exportXForms( m_rContext );
326*cdf0e10cSrcweir     }
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     //---------------------------------------------------------------------
329*cdf0e10cSrcweir     bool OFormLayerXMLExport_Impl::pageContainsForms( const Reference< XDrawPage >& _rxDrawPage ) const
330*cdf0e10cSrcweir     {
331*cdf0e10cSrcweir         Reference< XFormsSupplier2 > xFormsSupp( _rxDrawPage, UNO_QUERY );
332*cdf0e10cSrcweir         DBG_ASSERT( xFormsSupp.is(), "OFormLayerXMLExport_Impl::pageContainsForms: no XFormsSupplier2!" );
333*cdf0e10cSrcweir         return xFormsSupp.is() && xFormsSupp->hasForms();
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     //---------------------------------------------------------------------
337*cdf0e10cSrcweir     bool OFormLayerXMLExport_Impl::documentContainsXForms() const
338*cdf0e10cSrcweir     {
339*cdf0e10cSrcweir         Reference< XXFormsSupplier > xXFormSupp( m_rContext.GetModel(), UNO_QUERY );
340*cdf0e10cSrcweir         Reference< XNameContainer > xForms;
341*cdf0e10cSrcweir         if ( xXFormSupp.is() )
342*cdf0e10cSrcweir             xForms = xXFormSupp->getXForms();
343*cdf0e10cSrcweir         return xForms.is() && xForms->hasElements();
344*cdf0e10cSrcweir     }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     //---------------------------------------------------------------------
347*cdf0e10cSrcweir     sal_Bool OFormLayerXMLExport_Impl::implMoveIterators(const Reference< XDrawPage >& _rxDrawPage, sal_Bool _bClear)
348*cdf0e10cSrcweir     {
349*cdf0e10cSrcweir         sal_Bool bKnownPage = sal_False;
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir         // the one for the ids
352*cdf0e10cSrcweir         m_aCurrentPageIds = m_aControlIds.find(_rxDrawPage);
353*cdf0e10cSrcweir         if (m_aControlIds.end() == m_aCurrentPageIds)
354*cdf0e10cSrcweir         {
355*cdf0e10cSrcweir             m_aControlIds[_rxDrawPage] = MapPropertySet2String();
356*cdf0e10cSrcweir             m_aCurrentPageIds = m_aControlIds.find(_rxDrawPage);
357*cdf0e10cSrcweir         }
358*cdf0e10cSrcweir         else
359*cdf0e10cSrcweir         {
360*cdf0e10cSrcweir             bKnownPage = sal_True;
361*cdf0e10cSrcweir             if (_bClear && !m_aCurrentPageIds->second.empty() )
362*cdf0e10cSrcweir                 m_aCurrentPageIds->second.clear();
363*cdf0e10cSrcweir         }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir         // the one for the ids of the referring controls
366*cdf0e10cSrcweir         m_aCurrentPageReferring = m_aReferringControls.find(_rxDrawPage);
367*cdf0e10cSrcweir         if (m_aReferringControls.end() == m_aCurrentPageReferring)
368*cdf0e10cSrcweir         {
369*cdf0e10cSrcweir             m_aReferringControls[_rxDrawPage] = MapPropertySet2String();
370*cdf0e10cSrcweir             m_aCurrentPageReferring = m_aReferringControls.find(_rxDrawPage);
371*cdf0e10cSrcweir         }
372*cdf0e10cSrcweir         else
373*cdf0e10cSrcweir         {
374*cdf0e10cSrcweir             bKnownPage = sal_True;
375*cdf0e10cSrcweir             if (_bClear && !m_aCurrentPageReferring->second.empty() )
376*cdf0e10cSrcweir                 m_aCurrentPageReferring->second.clear();
377*cdf0e10cSrcweir         }
378*cdf0e10cSrcweir         return bKnownPage;
379*cdf0e10cSrcweir     }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir     //---------------------------------------------------------------------
382*cdf0e10cSrcweir     sal_Bool OFormLayerXMLExport_Impl::seekPage(const Reference< XDrawPage >& _rxDrawPage)
383*cdf0e10cSrcweir     {
384*cdf0e10cSrcweir         sal_Bool bKnownPage = implMoveIterators( _rxDrawPage, sal_False );
385*cdf0e10cSrcweir         if ( bKnownPage )
386*cdf0e10cSrcweir             return sal_True;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir         // if the page is not yet known, this does not automatically mean that it has
389*cdf0e10cSrcweir         // not been examined. Instead, examineForms returns silently and successfully
390*cdf0e10cSrcweir         // if a page is a XFormsPageSupplier2, but does not have a forms collection
391*cdf0e10cSrcweir         // (This behaviour of examineForms is a performance optimization, to not force
392*cdf0e10cSrcweir         // the page to create a forms container just to see that it's empty.)
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir         // So, in such a case, seekPage is considered to be successfull, too, though the
395*cdf0e10cSrcweir         // page was not yet known
396*cdf0e10cSrcweir         Reference< XFormsSupplier2 > xFormsSupp( _rxDrawPage, UNO_QUERY );
397*cdf0e10cSrcweir         if ( xFormsSupp.is() && !xFormsSupp->hasForms() )
398*cdf0e10cSrcweir             return sal_True;
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir         // anything else means that the page has not been examined before, or it's no
401*cdf0e10cSrcweir         // valid form page. Both cases are Bad (TM).
402*cdf0e10cSrcweir         return sal_False;
403*cdf0e10cSrcweir     }
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir     //---------------------------------------------------------------------
406*cdf0e10cSrcweir     ::rtl::OUString OFormLayerXMLExport_Impl::getControlId(const Reference< XPropertySet >& _rxControl)
407*cdf0e10cSrcweir     {
408*cdf0e10cSrcweir         OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLExport_Impl::getControlId: invalid current page!");
409*cdf0e10cSrcweir         OSL_ENSURE(m_aCurrentPageIds->second.end() != m_aCurrentPageIds->second.find(_rxControl),
410*cdf0e10cSrcweir             "OFormLayerXMLExport_Impl::getControlId: can not find the control!");
411*cdf0e10cSrcweir         return m_aCurrentPageIds->second[_rxControl];
412*cdf0e10cSrcweir     }
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir     //---------------------------------------------------------------------
415*cdf0e10cSrcweir     ::rtl::OUString OFormLayerXMLExport_Impl::getImmediateNumberStyle( const Reference< XPropertySet >& _rxObject )
416*cdf0e10cSrcweir     {
417*cdf0e10cSrcweir         ::rtl::OUString sNumberStyle;
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir         sal_Int32 nOwnFormatKey = implExamineControlNumberFormat( _rxObject );
420*cdf0e10cSrcweir         if ( -1 != nOwnFormatKey )
421*cdf0e10cSrcweir             sNumberStyle = getControlNumberStyleExport()->GetStyleName( nOwnFormatKey );
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir         return sNumberStyle;
424*cdf0e10cSrcweir     }
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir     //---------------------------------------------------------------------
427*cdf0e10cSrcweir     ::rtl::OUString OFormLayerXMLExport_Impl::getControlNumberStyle( const Reference< XPropertySet >& _rxControl )
428*cdf0e10cSrcweir     {
429*cdf0e10cSrcweir         ::rtl::OUString sNumberStyle;
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir         ConstMapPropertySet2IntIterator aControlFormatPos = m_aControlNumberFormats.find(_rxControl);
432*cdf0e10cSrcweir         if (m_aControlNumberFormats.end() != aControlFormatPos)
433*cdf0e10cSrcweir         {
434*cdf0e10cSrcweir             OSL_ENSURE(m_pControlNumberStyles, "OFormLayerXMLExport_Impl::getControlNumberStyle: have a control which has a format style, but no style exporter!");
435*cdf0e10cSrcweir             sNumberStyle = getControlNumberStyleExport()->GetStyleName(aControlFormatPos->second);
436*cdf0e10cSrcweir         }
437*cdf0e10cSrcweir         // it's allowed to ask for a control which does not have format information.
438*cdf0e10cSrcweir         // (This is for performance reasons)
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir         return sNumberStyle;
441*cdf0e10cSrcweir     }
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir     //---------------------------------------------------------------------
444*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::examineForms(const Reference< XDrawPage >& _rxDrawPage)
445*cdf0e10cSrcweir     {
446*cdf0e10cSrcweir         // get the forms collection of the page
447*cdf0e10cSrcweir         Reference< XIndexAccess > xCollectionIndex;
448*cdf0e10cSrcweir         if (!impl_isFormPageContainingForms(_rxDrawPage, xCollectionIndex))
449*cdf0e10cSrcweir             return;
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir         // move the iterator which specify the currently handled page
452*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
453*cdf0e10cSrcweir         sal_Bool bPageIsKnown =
454*cdf0e10cSrcweir #endif
455*cdf0e10cSrcweir             implMoveIterators(_rxDrawPage, sal_True);
456*cdf0e10cSrcweir         OSL_ENSURE(!bPageIsKnown, "OFormLayerXMLExport_Impl::examineForms: examining a page twice!");
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir         ::std::stack< Reference< XIndexAccess > >   aContainerHistory;
459*cdf0e10cSrcweir         ::std::stack< sal_Int32 >                   aIndexHistory;
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir         Reference< XIndexAccess > xLoop = xCollectionIndex;
462*cdf0e10cSrcweir         sal_Int32 nChildPos = 0;
463*cdf0e10cSrcweir         do
464*cdf0e10cSrcweir         {
465*cdf0e10cSrcweir             if (nChildPos < xLoop->getCount())
466*cdf0e10cSrcweir             {
467*cdf0e10cSrcweir                 Reference< XPropertySet > xCurrent( xLoop->getByIndex( nChildPos ), UNO_QUERY );
468*cdf0e10cSrcweir                 OSL_ENSURE(xCurrent.is(), "OFormLayerXMLExport_Impl::examineForms: invalid child object");
469*cdf0e10cSrcweir                 if (!xCurrent.is())
470*cdf0e10cSrcweir                     continue;
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir                 if (!checkExamineControl(xCurrent))
473*cdf0e10cSrcweir                 {
474*cdf0e10cSrcweir                     // step down
475*cdf0e10cSrcweir                     Reference< XIndexAccess > xNextContainer(xCurrent, UNO_QUERY);
476*cdf0e10cSrcweir                     OSL_ENSURE(xNextContainer.is(), "OFormLayerXMLExport_Impl::examineForms: what the heck is this ... no control, no container?");
477*cdf0e10cSrcweir                     aContainerHistory.push(xLoop);
478*cdf0e10cSrcweir                     aIndexHistory.push(nChildPos);
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir                     xLoop = xNextContainer;
481*cdf0e10cSrcweir                     nChildPos = -1; // will be incremented below
482*cdf0e10cSrcweir                 }
483*cdf0e10cSrcweir                 ++nChildPos;
484*cdf0e10cSrcweir             }
485*cdf0e10cSrcweir             else
486*cdf0e10cSrcweir             {
487*cdf0e10cSrcweir                 // step up
488*cdf0e10cSrcweir                 while ((nChildPos >= xLoop->getCount()) && !aContainerHistory.empty() )
489*cdf0e10cSrcweir                 {
490*cdf0e10cSrcweir                     xLoop = aContainerHistory.top();
491*cdf0e10cSrcweir                     aContainerHistory.pop();
492*cdf0e10cSrcweir                     nChildPos = aIndexHistory.top();
493*cdf0e10cSrcweir                     aIndexHistory.pop();
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir                     ++nChildPos;
496*cdf0e10cSrcweir                 }
497*cdf0e10cSrcweir                 if (nChildPos >= xLoop->getCount())
498*cdf0e10cSrcweir                     // exited the loop above because we have no history anymore (0 == aContainerHistory.size()),
499*cdf0e10cSrcweir                     // and on the current level there are no more children
500*cdf0e10cSrcweir                     // -> leave
501*cdf0e10cSrcweir                     break;
502*cdf0e10cSrcweir             }
503*cdf0e10cSrcweir         }
504*cdf0e10cSrcweir         while (xLoop.is());
505*cdf0e10cSrcweir     }
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir     //---------------------------------------------------------------------
508*cdf0e10cSrcweir     namespace
509*cdf0e10cSrcweir     {
510*cdf0e10cSrcweir         struct AccumulateSize : public ::std::binary_function< size_t, MapPropertySet2Map::value_type, size_t >
511*cdf0e10cSrcweir         {
512*cdf0e10cSrcweir             size_t operator()( size_t _size, const MapPropertySet2Map::value_type& _map ) const
513*cdf0e10cSrcweir             {
514*cdf0e10cSrcweir                 return _size + _map.second.size();
515*cdf0e10cSrcweir             }
516*cdf0e10cSrcweir         };
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir         ::rtl::OUString lcl_findFreeControlId( const MapPropertySet2Map& _rAllPagesControlIds )
519*cdf0e10cSrcweir         {
520*cdf0e10cSrcweir             static const ::rtl::OUString sControlIdBase( RTL_CONSTASCII_USTRINGPARAM( "control" ) );
521*cdf0e10cSrcweir             ::rtl::OUString sControlId = sControlIdBase;
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir             size_t nKnownControlCount = ::std::accumulate( _rAllPagesControlIds.begin(), _rAllPagesControlIds.end(), (size_t)0, AccumulateSize() );
524*cdf0e10cSrcweir             sControlId += ::rtl::OUString::valueOf( (sal_Int32)nKnownControlCount + 1 );
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir         #ifdef DBG_UTIL
527*cdf0e10cSrcweir             // Check if the id is already used. It shouldn't, as we currently have no mechanism for removing entries
528*cdf0e10cSrcweir             // from the map, so the approach used above (take the accumulated map size) should be sufficient. But if
529*cdf0e10cSrcweir             // somebody changes this (e.g. allows removing entries from the map), the assertion below probably will fail.
530*cdf0e10cSrcweir             for (   MapPropertySet2Map::const_iterator outer = _rAllPagesControlIds.begin();
531*cdf0e10cSrcweir                     outer != _rAllPagesControlIds.end();
532*cdf0e10cSrcweir                     ++outer
533*cdf0e10cSrcweir                 )
534*cdf0e10cSrcweir                 for (   MapPropertySet2String::const_iterator inner = outer->second.begin();
535*cdf0e10cSrcweir                         inner != outer->second.end();
536*cdf0e10cSrcweir                         ++inner
537*cdf0e10cSrcweir                     )
538*cdf0e10cSrcweir                 {
539*cdf0e10cSrcweir                     OSL_ENSURE( inner->second != sControlId,
540*cdf0e10cSrcweir                         "lcl_findFreeControlId: auto-generated control ID is already used!" );
541*cdf0e10cSrcweir                 }
542*cdf0e10cSrcweir         #endif
543*cdf0e10cSrcweir             return sControlId;
544*cdf0e10cSrcweir         }
545*cdf0e10cSrcweir     }
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir     //---------------------------------------------------------------------
548*cdf0e10cSrcweir     sal_Bool OFormLayerXMLExport_Impl::checkExamineControl(const Reference< XPropertySet >& _rxObject)
549*cdf0e10cSrcweir     {
550*cdf0e10cSrcweir         Reference< XPropertySetInfo > xCurrentInfo = _rxObject->getPropertySetInfo();
551*cdf0e10cSrcweir         OSL_ENSURE(xCurrentInfo.is(), "OFormLayerXMLExport_Impl::checkExamineControl: no property set info");
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir         sal_Bool bIsControl = xCurrentInfo->hasPropertyByName( PROPERTY_CLASSID );
554*cdf0e10cSrcweir         if (bIsControl)
555*cdf0e10cSrcweir         {
556*cdf0e10cSrcweir             // ----------------------------------
557*cdf0e10cSrcweir             // generate a new control id
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir             // find a free id
560*cdf0e10cSrcweir             ::rtl::OUString sCurrentId = lcl_findFreeControlId( m_aControlIds );
561*cdf0e10cSrcweir             // add it to the map
562*cdf0e10cSrcweir             m_aCurrentPageIds->second[_rxObject] = sCurrentId;
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir             // ----------------------------------
565*cdf0e10cSrcweir             // check if this control has a "LabelControl" property referring another control
566*cdf0e10cSrcweir             if ( xCurrentInfo->hasPropertyByName( PROPERTY_CONTROLLABEL ) )
567*cdf0e10cSrcweir             {
568*cdf0e10cSrcweir                 Reference< XPropertySet > xCurrentReference( _rxObject->getPropertyValue( PROPERTY_CONTROLLABEL ), UNO_QUERY );
569*cdf0e10cSrcweir                 if (xCurrentReference.is())
570*cdf0e10cSrcweir                 {
571*cdf0e10cSrcweir                     ::rtl::OUString& sReferencedBy = m_aCurrentPageReferring->second[xCurrentReference];
572*cdf0e10cSrcweir                     if (sReferencedBy.getLength())
573*cdf0e10cSrcweir                         // it's not the first _rxObject referring to the xCurrentReference
574*cdf0e10cSrcweir                         // -> separate the id
575*cdf0e10cSrcweir                         sReferencedBy += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
576*cdf0e10cSrcweir                     sReferencedBy += sCurrentId;
577*cdf0e10cSrcweir                 }
578*cdf0e10cSrcweir             }
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir             // ----------------------------------
581*cdf0e10cSrcweir             // check if the control needs a number format style
582*cdf0e10cSrcweir             if ( xCurrentInfo->hasPropertyByName( PROPERTY_FORMATKEY ) )
583*cdf0e10cSrcweir             {
584*cdf0e10cSrcweir                 examineControlNumberFormat(_rxObject);
585*cdf0e10cSrcweir             }
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir             // ----------------------------------
588*cdf0e10cSrcweir             // check if it's a control providing text
589*cdf0e10cSrcweir             Reference< XText > xControlText( _rxObject, UNO_QUERY );
590*cdf0e10cSrcweir             if ( xControlText.is() )
591*cdf0e10cSrcweir             {
592*cdf0e10cSrcweir                 m_rContext.GetTextParagraphExport()->collectTextAutoStyles( xControlText );
593*cdf0e10cSrcweir             }
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir             // ----------------------------------
596*cdf0e10cSrcweir             // check if it is a grid control - in this case, we need special handling for the columns
597*cdf0e10cSrcweir             sal_Int16 nControlType = FormComponentType::CONTROL;
598*cdf0e10cSrcweir             _rxObject->getPropertyValue( PROPERTY_CLASSID ) >>= nControlType;
599*cdf0e10cSrcweir             if ( FormComponentType::GRIDCONTROL == nControlType )
600*cdf0e10cSrcweir             {
601*cdf0e10cSrcweir                 collectGridColumnStylesAndIds( _rxObject );
602*cdf0e10cSrcweir             }
603*cdf0e10cSrcweir         }
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir         return bIsControl;
606*cdf0e10cSrcweir     }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir     //---------------------------------------------------------------------
609*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::collectGridColumnStylesAndIds( const Reference< XPropertySet >& _rxControl )
610*cdf0e10cSrcweir     {
611*cdf0e10cSrcweir         // loop through all columns of the grid
612*cdf0e10cSrcweir         try
613*cdf0e10cSrcweir         {
614*cdf0e10cSrcweir             Reference< XIndexAccess > xContainer( _rxControl, UNO_QUERY );
615*cdf0e10cSrcweir             OSL_ENSURE( xContainer.is(), "OFormLayerXMLExport_Impl::collectGridColumnStylesAndIds: grid control not being a container?!" );
616*cdf0e10cSrcweir             if ( !xContainer.is() )
617*cdf0e10cSrcweir                 return;
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir             Reference< XPropertySetInfo > xColumnPropertiesMeta;
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir             sal_Int32 nCount = xContainer->getCount();
622*cdf0e10cSrcweir             for ( sal_Int32 i=0; i<nCount; ++i )
623*cdf0e10cSrcweir             {
624*cdf0e10cSrcweir                 Reference< XPropertySet > xColumnProperties( xContainer->getByIndex( i ), UNO_QUERY );
625*cdf0e10cSrcweir                 OSL_ENSURE( xColumnProperties.is(), "OFormLayerXMLExport_Impl::collectGridColumnStylesAndIds: invalid grid column encountered!" );
626*cdf0e10cSrcweir                 if ( !xColumnProperties.is() )
627*cdf0e10cSrcweir                     continue;
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir                 // ----------------------------------
630*cdf0e10cSrcweir                 // generate a new control id
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir                 // find a free id
633*cdf0e10cSrcweir                 ::rtl::OUString sCurrentId = lcl_findFreeControlId( m_aControlIds );
634*cdf0e10cSrcweir                 // add it to the map
635*cdf0e10cSrcweir                 m_aCurrentPageIds->second[ xColumnProperties ] = sCurrentId;
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir                 // ----------------------------------
638*cdf0e10cSrcweir                 // determine a number style, if needed
639*cdf0e10cSrcweir                 xColumnPropertiesMeta = xColumnProperties->getPropertySetInfo();
640*cdf0e10cSrcweir                 // get the styles of the column
641*cdf0e10cSrcweir                 ::std::vector< XMLPropertyState > aPropertyStates = m_xStyleExportMapper->Filter( xColumnProperties );
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir                 // care for the number format, additionally
644*cdf0e10cSrcweir                 ::rtl::OUString sColumnNumberStyle;
645*cdf0e10cSrcweir                 if ( xColumnPropertiesMeta.is() && xColumnPropertiesMeta->hasPropertyByName( PROPERTY_FORMATKEY ) )
646*cdf0e10cSrcweir                     sColumnNumberStyle = getImmediateNumberStyle( xColumnProperties );
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir                 if ( sColumnNumberStyle.getLength() )
649*cdf0e10cSrcweir                 {   // the column indeed has a formatting
650*cdf0e10cSrcweir                     sal_Int32 nStyleMapIndex = m_xStyleExportMapper->getPropertySetMapper()->FindEntryIndex( CTF_FORMS_DATA_STYLE );
651*cdf0e10cSrcweir                         // TODO: move this to the ctor
652*cdf0e10cSrcweir                     OSL_ENSURE ( -1 != nStyleMapIndex, "XMLShapeExport::collectShapeAutoStyles: could not obtain the index for our context id!");
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir                     XMLPropertyState aNumberStyleState( nStyleMapIndex, makeAny( sColumnNumberStyle ) );
655*cdf0e10cSrcweir                     aPropertyStates.push_back( aNumberStyleState );
656*cdf0e10cSrcweir                 }
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
659*cdf0e10cSrcweir                 ::std::vector< XMLPropertyState >::const_iterator aHaveALook = aPropertyStates.begin();
660*cdf0e10cSrcweir                 for ( ; aHaveALook != aPropertyStates.end(); ++aHaveALook )
661*cdf0e10cSrcweir                 {
662*cdf0e10cSrcweir                     (void)aHaveALook;
663*cdf0e10cSrcweir                 }
664*cdf0e10cSrcweir #endif
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir                 // ----------------------------------
667*cdf0e10cSrcweir                 // determine the column style
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir                 if ( !aPropertyStates.empty() )
670*cdf0e10cSrcweir                 {   // add to the style pool
671*cdf0e10cSrcweir                     ::rtl::OUString sColumnStyleName = m_rContext.GetAutoStylePool()->Add( XML_STYLE_FAMILY_CONTROL_ID, aPropertyStates );
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir                     OSL_ENSURE( m_aGridColumnStyles.end() == m_aGridColumnStyles.find( xColumnProperties ),
674*cdf0e10cSrcweir                         "OFormLayerXMLExport_Impl::collectGridColumnStylesAndIds: already have a style for this column!" );
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir                     m_aGridColumnStyles.insert( MapPropertySet2String::value_type( xColumnProperties, sColumnStyleName ) );
677*cdf0e10cSrcweir                 }
678*cdf0e10cSrcweir             }
679*cdf0e10cSrcweir         }
680*cdf0e10cSrcweir         catch( const Exception& )
681*cdf0e10cSrcweir         {
682*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
683*cdf0e10cSrcweir         }
684*cdf0e10cSrcweir     }
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir     //---------------------------------------------------------------------
687*cdf0e10cSrcweir     sal_Int32 OFormLayerXMLExport_Impl::implExamineControlNumberFormat( const Reference< XPropertySet >& _rxObject )
688*cdf0e10cSrcweir     {
689*cdf0e10cSrcweir         // get the format key relative to our own formats supplier
690*cdf0e10cSrcweir         sal_Int32 nOwnFormatKey = ensureTranslateFormat( _rxObject );
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir         if ( -1 != nOwnFormatKey )
693*cdf0e10cSrcweir             // tell the exporter that we used this format
694*cdf0e10cSrcweir             getControlNumberStyleExport()->SetUsed( nOwnFormatKey );
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir         return nOwnFormatKey;
697*cdf0e10cSrcweir     }
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir     //---------------------------------------------------------------------
700*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::examineControlNumberFormat( const Reference< XPropertySet >& _rxControl )
701*cdf0e10cSrcweir     {
702*cdf0e10cSrcweir         sal_Int32 nOwnFormatKey = implExamineControlNumberFormat( _rxControl );
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir         if ( -1 == nOwnFormatKey )
705*cdf0e10cSrcweir             // nothing to do, the number format of this control is void
706*cdf0e10cSrcweir             return;
707*cdf0e10cSrcweir 
708*cdf0e10cSrcweir         // remember the format key for this control (we'll be asked in getControlNumberStyle for this)
709*cdf0e10cSrcweir         OSL_ENSURE(m_aControlNumberFormats.end() == m_aControlNumberFormats.find(_rxControl),
710*cdf0e10cSrcweir             "OFormLayerXMLExport_Impl::examineControlNumberFormat: already handled this control!");
711*cdf0e10cSrcweir         m_aControlNumberFormats[_rxControl] = nOwnFormatKey;
712*cdf0e10cSrcweir     }
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir     //---------------------------------------------------------------------
715*cdf0e10cSrcweir     sal_Int32 OFormLayerXMLExport_Impl::ensureTranslateFormat(const Reference< XPropertySet >& _rxFormattedControl)
716*cdf0e10cSrcweir     {
717*cdf0e10cSrcweir         ensureControlNumberStyleExport();
718*cdf0e10cSrcweir         OSL_ENSURE(m_xControlNumberFormats.is(), "OFormLayerXMLExport_Impl::ensureTranslateFormat: no own formats supplier!");
719*cdf0e10cSrcweir             // (should have been created in ensureControlNumberStyleExport)
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir         sal_Int32 nOwnFormatKey = -1;
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir         // the format key (relative to the control's supplier)
724*cdf0e10cSrcweir         sal_Int32 nControlFormatKey = -1;
725*cdf0e10cSrcweir         Any aControlFormatKey = _rxFormattedControl->getPropertyValue(PROPERTY_FORMATKEY);
726*cdf0e10cSrcweir         if (aControlFormatKey >>= nControlFormatKey)
727*cdf0e10cSrcweir         {
728*cdf0e10cSrcweir             // the control's number format
729*cdf0e10cSrcweir             Reference< XNumberFormatsSupplier > xControlFormatsSupplier;
730*cdf0e10cSrcweir             _rxFormattedControl->getPropertyValue(PROPERTY_FORMATSSUPPLIER) >>= xControlFormatsSupplier;
731*cdf0e10cSrcweir             Reference< XNumberFormats > xControlFormats;
732*cdf0e10cSrcweir             if (xControlFormatsSupplier.is())
733*cdf0e10cSrcweir                 xControlFormats = xControlFormatsSupplier->getNumberFormats();
734*cdf0e10cSrcweir             OSL_ENSURE(xControlFormats.is(), "OFormLayerXMLExport_Impl::ensureTranslateFormat: formatted control without supplier!");
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir             // obtain the persistent (does not depend on the formats supplier) representation of the control's format
737*cdf0e10cSrcweir             Locale aFormatLocale;
738*cdf0e10cSrcweir             ::rtl::OUString sFormatDescription;
739*cdf0e10cSrcweir             if (xControlFormats.is())
740*cdf0e10cSrcweir             {
741*cdf0e10cSrcweir                 Reference< XPropertySet > xControlFormat = xControlFormats->getByKey(nControlFormatKey);
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir                 xControlFormat->getPropertyValue(PROPERTY_LOCALE)       >>= aFormatLocale;
744*cdf0e10cSrcweir                 xControlFormat->getPropertyValue(PROPERTY_FORMATSTRING) >>= sFormatDescription;
745*cdf0e10cSrcweir             }
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir             // check if our own formats collection already knows the format
748*cdf0e10cSrcweir             nOwnFormatKey = m_xControlNumberFormats->queryKey(sFormatDescription, aFormatLocale, sal_False);
749*cdf0e10cSrcweir             if (-1 == nOwnFormatKey)
750*cdf0e10cSrcweir             {   // no, we don't
751*cdf0e10cSrcweir                 // -> create a new format
752*cdf0e10cSrcweir                 nOwnFormatKey = m_xControlNumberFormats->addNew(sFormatDescription, aFormatLocale);
753*cdf0e10cSrcweir             }
754*cdf0e10cSrcweir             OSL_ENSURE(-1 != nOwnFormatKey, "OFormLayerXMLExport_Impl::ensureTranslateFormat: could not translate the controls format key!");
755*cdf0e10cSrcweir         }
756*cdf0e10cSrcweir         else
757*cdf0e10cSrcweir             OSL_ENSURE(!aControlFormatKey.hasValue(), "OFormLayerXMLExport_Impl::ensureTranslateFormat: invalid number format property value!");
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir         return nOwnFormatKey;
760*cdf0e10cSrcweir     }
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir     //---------------------------------------------------------------------
763*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::ensureControlNumberStyleExport()
764*cdf0e10cSrcweir     {
765*cdf0e10cSrcweir         if (!m_pControlNumberStyles)
766*cdf0e10cSrcweir         {
767*cdf0e10cSrcweir             // create our number formats supplier (if necessary)
768*cdf0e10cSrcweir             Reference< XNumberFormatsSupplier > xFormatsSupplier;
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir             OSL_ENSURE(!m_xControlNumberFormats.is(), "OFormLayerXMLExport_Impl::getControlNumberStyleExport: inconsistence!");
771*cdf0e10cSrcweir                 // the m_xControlNumberFormats and m_pControlNumberStyles should be maintained together
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir             try
774*cdf0e10cSrcweir             {
775*cdf0e10cSrcweir                 // create it for en-US (does not really matter, as we will specify a locale for every
776*cdf0e10cSrcweir                 // concrete language to use)
777*cdf0e10cSrcweir                 Sequence< Any > aSupplierArgs(1);
778*cdf0e10cSrcweir                 aSupplierArgs[0] <<= Locale (   ::rtl::OUString::createFromAscii("en"),
779*cdf0e10cSrcweir                                                 ::rtl::OUString::createFromAscii("US"),
780*cdf0e10cSrcweir                                                 ::rtl::OUString()
781*cdf0e10cSrcweir                                             );
782*cdf0e10cSrcweir                 // #110680#
783*cdf0e10cSrcweir                 //Reference< XInterface > xFormatsSupplierUntyped =
784*cdf0e10cSrcweir                 //  ::comphelper::getProcessServiceFactory()->createInstanceWithArguments(
785*cdf0e10cSrcweir                 //      SERVICE_NUMBERFORMATSSUPPLIER,
786*cdf0e10cSrcweir                 //      aSupplierArgs
787*cdf0e10cSrcweir                 //  );
788*cdf0e10cSrcweir                 Reference< XInterface > xFormatsSupplierUntyped =
789*cdf0e10cSrcweir                     m_rContext.getServiceFactory()->createInstanceWithArguments(
790*cdf0e10cSrcweir                         SERVICE_NUMBERFORMATSSUPPLIER,
791*cdf0e10cSrcweir                         aSupplierArgs
792*cdf0e10cSrcweir                     );
793*cdf0e10cSrcweir                 OSL_ENSURE(xFormatsSupplierUntyped.is(), "OFormLayerXMLExport_Impl::getControlNumberStyleExport: could not instantiate a number formats supplier!");
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir                 xFormatsSupplier = Reference< XNumberFormatsSupplier >(xFormatsSupplierUntyped, UNO_QUERY);
796*cdf0e10cSrcweir                 if (xFormatsSupplier.is())
797*cdf0e10cSrcweir                     m_xControlNumberFormats = xFormatsSupplier->getNumberFormats();
798*cdf0e10cSrcweir             }
799*cdf0e10cSrcweir             catch(const Exception&)
800*cdf0e10cSrcweir             {
801*cdf0e10cSrcweir             }
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir             OSL_ENSURE(m_xControlNumberFormats.is(), "OFormLayerXMLExport_Impl::getControlNumberStyleExport: could not obtain my default number formats!");
804*cdf0e10cSrcweir 
805*cdf0e10cSrcweir             // create the exporter
806*cdf0e10cSrcweir             m_pControlNumberStyles = new SvXMLNumFmtExport(m_rContext, xFormatsSupplier, getControlNumberStyleNamePrefix());
807*cdf0e10cSrcweir         }
808*cdf0e10cSrcweir     }
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir     //---------------------------------------------------------------------
811*cdf0e10cSrcweir     SvXMLNumFmtExport* OFormLayerXMLExport_Impl::getControlNumberStyleExport()
812*cdf0e10cSrcweir     {
813*cdf0e10cSrcweir         ensureControlNumberStyleExport();
814*cdf0e10cSrcweir         return m_pControlNumberStyles;
815*cdf0e10cSrcweir     }
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir     //---------------------------------------------------------------------
818*cdf0e10cSrcweir     void OFormLayerXMLExport_Impl::excludeFromExport( const Reference< XControlModel > _rxControl )
819*cdf0e10cSrcweir     {
820*cdf0e10cSrcweir         Reference< XPropertySet > xProps( _rxControl, UNO_QUERY );
821*cdf0e10cSrcweir         OSL_ENSURE( xProps.is(), "OFormLayerXMLExport_Impl::excludeFromExport: invalid control model!" );
822*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
823*cdf0e10cSrcweir         ::std::pair< PropertySetBag::iterator, bool > aPos =
824*cdf0e10cSrcweir #endif
825*cdf0e10cSrcweir         m_aIgnoreList.insert( xProps );
826*cdf0e10cSrcweir         OSL_ENSURE( aPos.second, "OFormLayerXMLExport_Impl::excludeFromExport: element already exists in the ignore list!" );
827*cdf0e10cSrcweir     }
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir //.........................................................................
830*cdf0e10cSrcweir }   // namespace xmloff
831*cdf0e10cSrcweir //.........................................................................
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir 
834