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