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 #include "layerimport.hxx"
31*cdf0e10cSrcweir #include "formenums.hxx"
32*cdf0e10cSrcweir #include "elementimport.hxx"
33*cdf0e10cSrcweir #include "officeforms.hxx"
34*cdf0e10cSrcweir #include "strings.hxx"
35*cdf0e10cSrcweir #include "formstyles.hxx"
36*cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx>
37*cdf0e10cSrcweir #include <xmloff/xmlstyle.hxx>
38*cdf0e10cSrcweir #include <xmloff/families.hxx>
39*cdf0e10cSrcweir #include <xmloff/xmlprmap.hxx>
40*cdf0e10cSrcweir #include <xmloff/prstylei.hxx>
41*cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
42*cdf0e10cSrcweir #include "XMLEventImportHelper.hxx"
43*cdf0e10cSrcweir #include <xmloff/xmlimppr.hxx>
44*cdf0e10cSrcweir #include <xmloff/xmlnumfi.hxx>
45*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/form/FormSubmitEncoding.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/form/FormSubmitMethod.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/form/NavigationBarMode.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/form/TabulatorCycle.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/form/FormButtonType.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/awt/ScrollBarOrientation.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/awt/VisualEffect.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/form/ListSourceType.hpp>
55*cdf0e10cSrcweir #include <tools/wintypes.hxx>		// for check states
56*cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
57*cdf0e10cSrcweir #include <xmloff/controlpropertyhdl.hxx>
58*cdf0e10cSrcweir #include "controlpropertymap.hxx"
59*cdf0e10cSrcweir #include "formevents.hxx"
60*cdf0e10cSrcweir #include "formcellbinding.hxx"
61*cdf0e10cSrcweir #include "xmloff/xformsimport.hxx"
62*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
63*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
64*cdf0e10cSrcweir #include <rtl/logfile.hxx>
65*cdf0e10cSrcweir #include <algorithm>
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir SV_IMPL_REF( SvXMLStylesContext );
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir //.........................................................................
70*cdf0e10cSrcweir namespace xmloff
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir //.........................................................................
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
75*cdf0e10cSrcweir using namespace ::com::sun::star::awt;
76*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
77*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
78*cdf0e10cSrcweir using namespace ::com::sun::star::container;
79*cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
80*cdf0e10cSrcweir using namespace ::com::sun::star::xml;
81*cdf0e10cSrcweir using namespace ::com::sun::star::util;
82*cdf0e10cSrcweir using namespace ::com::sun::star::form;
83*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir //=====================================================================
86*cdf0e10cSrcweir //= OFormLayerXMLImport_Impl
87*cdf0e10cSrcweir //=====================================================================
88*cdf0e10cSrcweir //---------------------------------------------------------------------
89*cdf0e10cSrcweir OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl(SvXMLImport& _rImporter)
90*cdf0e10cSrcweir 	:m_rImporter(_rImporter)
91*cdf0e10cSrcweir 	,m_pAutoStyles(NULL)
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir 	// build the attribute2property map
94*cdf0e10cSrcweir 	// string properties which are exported as attributes
95*cdf0e10cSrcweir 	m_aAttributeMetaData.addStringProperty(
96*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_NAME), PROPERTY_NAME);
97*cdf0e10cSrcweir 	m_aAttributeMetaData.addStringProperty(
98*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_IMAGE_DATA), PROPERTY_IMAGEURL);
99*cdf0e10cSrcweir 	m_aAttributeMetaData.addStringProperty(
100*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_LABEL), PROPERTY_LABEL);
101*cdf0e10cSrcweir 	m_aAttributeMetaData.addStringProperty(
102*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_LOCATION), PROPERTY_TARGETURL);
103*cdf0e10cSrcweir 	m_aAttributeMetaData.addStringProperty(
104*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_TITLE), PROPERTY_TITLE);
105*cdf0e10cSrcweir 	m_aAttributeMetaData.addStringProperty(
106*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME), PROPERTY_TARGETFRAME, "_blank");
107*cdf0e10cSrcweir 	m_aAttributeMetaData.addStringProperty(
108*cdf0e10cSrcweir 		OAttributeMetaData::getDatabaseAttributeName(DA_DATA_FIELD), PROPERTY_DATAFIELD);
109*cdf0e10cSrcweir 	m_aAttributeMetaData.addStringProperty(
110*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faCommand), PROPERTY_COMMAND);
111*cdf0e10cSrcweir 	m_aAttributeMetaData.addStringProperty(
112*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faDatasource), PROPERTY_DATASOURCENAME);
113*cdf0e10cSrcweir 	m_aAttributeMetaData.addStringProperty(
114*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faFilter), PROPERTY_FILTER);
115*cdf0e10cSrcweir 	m_aAttributeMetaData.addStringProperty(
116*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faOrder), PROPERTY_ORDER);
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	// properties not added because they're already present in another form
119*cdf0e10cSrcweir 	OSL_ENSURE(
120*cdf0e10cSrcweir 		0 == ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_LOCATION)).compareToAscii(
121*cdf0e10cSrcweir 			OAttributeMetaData::getFormAttributeName(faAction)),
122*cdf0e10cSrcweir 		"OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (1)!");
123*cdf0e10cSrcweir 		// if this fails, we would have to add a translation from faAction->PROPERTY_TARGETURL
124*cdf0e10cSrcweir 		// We did not because we already have one CCA_TARGET_LOCATION->PROPERTY_TARGETURL,
125*cdf0e10cSrcweir 		// and CCA_TARGET_LOCATION and faAction should be represented by the same attribute
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 	OSL_ENSURE(
128*cdf0e10cSrcweir 		0 == ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_NAME)).compareToAscii(
129*cdf0e10cSrcweir 			OAttributeMetaData::getFormAttributeName(faName)),
130*cdf0e10cSrcweir 		"OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (2)!");
131*cdf0e10cSrcweir 		// the same for faName, CCA_NAME and PROPERTY_NAME
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	// boolean properties which are exported as attributes
134*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
135*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_SELECTED), PROPERTY_STATE, sal_False);
136*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
137*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_DISABLED), PROPERTY_ENABLED, sal_False, sal_True);
138*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
139*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_DROPDOWN), PROPERTY_DROPDOWN, sal_False);
140*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
141*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_PRINTABLE), PROPERTY_PRINTABLE, sal_True);
142*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
143*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_READONLY), PROPERTY_READONLY, sal_False);
144*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
145*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_SELECTED), PROPERTY_DEFAULT_STATE, sal_False);
146*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
147*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_TAB_STOP), PROPERTY_TABSTOP, sal_True);
148*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
149*cdf0e10cSrcweir 		OAttributeMetaData::getDatabaseAttributeName(DA_CONVERT_EMPTY), PROPERTY_EMPTY_IS_NULL, sal_False);
150*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
151*cdf0e10cSrcweir 		OAttributeMetaData::getSpecialAttributeName(SCA_VALIDATION), PROPERTY_STRICTFORMAT, sal_False);
152*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
153*cdf0e10cSrcweir 		OAttributeMetaData::getSpecialAttributeName(SCA_MULTI_LINE), PROPERTY_MULTILINE, sal_False);
154*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
155*cdf0e10cSrcweir 		OAttributeMetaData::getSpecialAttributeName(SCA_AUTOMATIC_COMPLETION), PROPERTY_AUTOCOMPLETE, sal_False);
156*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
157*cdf0e10cSrcweir 		OAttributeMetaData::getSpecialAttributeName(SCA_MULTIPLE), PROPERTY_MULTISELECTION, sal_False);
158*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
159*cdf0e10cSrcweir 		OAttributeMetaData::getSpecialAttributeName(SCA_DEFAULT_BUTTON), PROPERTY_DEFAULTBUTTON, sal_False);
160*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
161*cdf0e10cSrcweir 		OAttributeMetaData::getSpecialAttributeName(SCA_IS_TRISTATE), PROPERTY_TRISTATE, sal_False);
162*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
163*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faAllowDeletes), PROPERTY_ALLOWDELETES, sal_True);
164*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
165*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faAllowInserts), PROPERTY_ALLOWINSERTS, sal_True);
166*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
167*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faAllowUpdates), PROPERTY_ALLOWUPDATES, sal_True);
168*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
169*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faApplyFilter), PROPERTY_APPLYFILTER, sal_False);
170*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
171*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faEscapeProcessing), PROPERTY_ESCAPEPROCESSING, sal_True);
172*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
173*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faIgnoreResult), PROPERTY_IGNORERESULT, sal_False);
174*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
175*cdf0e10cSrcweir 		OAttributeMetaData::getSpecialAttributeName( SCA_TOGGLE ), PROPERTY_TOGGLE, sal_False );
176*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
177*cdf0e10cSrcweir 		OAttributeMetaData::getSpecialAttributeName( SCA_FOCUS_ON_CLICK ), PROPERTY_FOCUS_ON_CLICK, sal_True );
178*cdf0e10cSrcweir 	m_aAttributeMetaData.addBooleanProperty(
179*cdf0e10cSrcweir 		OAttributeMetaData::getDatabaseAttributeName( DA_INPUT_REQUIRED ), PROPERTY_INPUT_REQUIRED, sal_False );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	// the int16 attributes
182*cdf0e10cSrcweir 	m_aAttributeMetaData.addInt16Property(
183*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_MAX_LENGTH), PROPERTY_MAXTEXTLENGTH, 0);
184*cdf0e10cSrcweir 	m_aAttributeMetaData.addInt16Property(
185*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_SIZE), PROPERTY_LINECOUNT, 5);
186*cdf0e10cSrcweir 	m_aAttributeMetaData.addInt16Property(
187*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_TAB_INDEX), PROPERTY_TABINDEX, 0);
188*cdf0e10cSrcweir 	m_aAttributeMetaData.addInt16Property(
189*cdf0e10cSrcweir 		OAttributeMetaData::getDatabaseAttributeName(DA_BOUND_COLUMN), PROPERTY_BOUNDCOLUMN, 0);
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	// the int32 attributes
192*cdf0e10cSrcweir 	m_aAttributeMetaData.addInt32Property(
193*cdf0e10cSrcweir 		OAttributeMetaData::getSpecialAttributeName( SCA_PAGE_STEP_SIZE ), PROPERTY_BLOCK_INCREMENT, 10 );
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	// the enum attributes
196*cdf0e10cSrcweir 	m_aAttributeMetaData.addEnumProperty(
197*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName( CCA_VISUAL_EFFECT ), PROPERTY_VISUAL_EFFECT,
198*cdf0e10cSrcweir 		VisualEffect::LOOK3D, OEnumMapper::getEnumMap( OEnumMapper::epVisualEffect ),
199*cdf0e10cSrcweir 		&::getCppuType( static_cast< sal_Int16* >( NULL ) ) );
200*cdf0e10cSrcweir 	m_aAttributeMetaData.addEnumProperty(
201*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName( CCA_ORIENTATION ), PROPERTY_ORIENTATION,
202*cdf0e10cSrcweir 		ScrollBarOrientation::HORIZONTAL, OEnumMapper::getEnumMap( OEnumMapper::epOrientation ),
203*cdf0e10cSrcweir 		&::getCppuType( static_cast< sal_Int32* >( NULL ) ) );
204*cdf0e10cSrcweir 	m_aAttributeMetaData.addEnumProperty(
205*cdf0e10cSrcweir 		OAttributeMetaData::getCommonControlAttributeName(CCA_BUTTON_TYPE), PROPERTY_BUTTONTYPE,
206*cdf0e10cSrcweir 		FormButtonType_PUSH, OEnumMapper::getEnumMap(OEnumMapper::epButtonType),
207*cdf0e10cSrcweir 		&::getCppuType( static_cast<FormButtonType*>(NULL) ));
208*cdf0e10cSrcweir 	m_aAttributeMetaData.addEnumProperty(
209*cdf0e10cSrcweir 		OAttributeMetaData::getDatabaseAttributeName(DA_LIST_SOURCE_TYPE), PROPERTY_LISTSOURCETYPE,
210*cdf0e10cSrcweir 		ListSourceType_VALUELIST, OEnumMapper::getEnumMap(OEnumMapper::epListSourceType),
211*cdf0e10cSrcweir 		&::getCppuType( static_cast<ListSourceType*>(NULL) ));
212*cdf0e10cSrcweir 	m_aAttributeMetaData.addEnumProperty(
213*cdf0e10cSrcweir 		OAttributeMetaData::getSpecialAttributeName(SCA_STATE), PROPERTY_DEFAULT_STATE, STATE_NOCHECK,
214*cdf0e10cSrcweir 		OEnumMapper::getEnumMap(OEnumMapper::epCheckState),
215*cdf0e10cSrcweir 		&::getCppuType( static_cast< sal_Int16* >(NULL)));
216*cdf0e10cSrcweir 	m_aAttributeMetaData.addEnumProperty(
217*cdf0e10cSrcweir 		OAttributeMetaData::getSpecialAttributeName(SCA_CURRENT_STATE), PROPERTY_STATE, STATE_NOCHECK,
218*cdf0e10cSrcweir 		OEnumMapper::getEnumMap(OEnumMapper::epCheckState),
219*cdf0e10cSrcweir 		&::getCppuType( static_cast< sal_Int16* >(NULL)));
220*cdf0e10cSrcweir 	m_aAttributeMetaData.addEnumProperty(
221*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faEnctype), PROPERTY_SUBMIT_ENCODING,
222*cdf0e10cSrcweir 		FormSubmitEncoding_URL, OEnumMapper::getEnumMap(OEnumMapper::epSubmitEncoding),
223*cdf0e10cSrcweir 		&::getCppuType( static_cast<FormSubmitEncoding*>(NULL) ));
224*cdf0e10cSrcweir 	m_aAttributeMetaData.addEnumProperty(
225*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faMethod), PROPERTY_SUBMIT_METHOD,
226*cdf0e10cSrcweir 		FormSubmitMethod_GET, OEnumMapper::getEnumMap(OEnumMapper::epSubmitMethod),
227*cdf0e10cSrcweir 		&::getCppuType( static_cast<FormSubmitMethod*>(NULL) ));
228*cdf0e10cSrcweir 	m_aAttributeMetaData.addEnumProperty(
229*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faCommandType), PROPERTY_COMMAND_TYPE,
230*cdf0e10cSrcweir 		CommandType::COMMAND, OEnumMapper::getEnumMap(OEnumMapper::epCommandType));
231*cdf0e10cSrcweir 	m_aAttributeMetaData.addEnumProperty(
232*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faNavigationMode), PROPERTY_NAVIGATION,
233*cdf0e10cSrcweir 		NavigationBarMode_NONE, OEnumMapper::getEnumMap(OEnumMapper::epNavigationType),
234*cdf0e10cSrcweir 		&::getCppuType( static_cast<NavigationBarMode*>(NULL) ));
235*cdf0e10cSrcweir 	m_aAttributeMetaData.addEnumProperty(
236*cdf0e10cSrcweir 		OAttributeMetaData::getFormAttributeName(faTabbingCycle), PROPERTY_CYCLE,
237*cdf0e10cSrcweir 		TabulatorCycle_RECORDS, OEnumMapper::getEnumMap(OEnumMapper::epTabCyle),
238*cdf0e10cSrcweir 		&::getCppuType( static_cast<TabulatorCycle*>(NULL) ));
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 	// 'initialize'
241*cdf0e10cSrcweir 	m_aCurrentPageIds = m_aControlIds.end();
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir //---------------------------------------------------------------------
245*cdf0e10cSrcweir OFormLayerXMLImport_Impl::~OFormLayerXMLImport_Impl()
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir 	// outlined to allow forward declaration of OAttribute2Property in the header
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 	if (m_pAutoStyles)
250*cdf0e10cSrcweir 		m_pAutoStyles->ReleaseRef();
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir //---------------------------------------------------------------------
254*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::setAutoStyleContext(SvXMLStylesContext* _pNewContext)
255*cdf0e10cSrcweir {
256*cdf0e10cSrcweir 	OSL_ENSURE(!m_pAutoStyles, "OFormLayerXMLImport_Impl::setAutoStyleContext: not to be called twice!");
257*cdf0e10cSrcweir 	m_pAutoStyles = _pNewContext;
258*cdf0e10cSrcweir 	if (m_pAutoStyles)
259*cdf0e10cSrcweir 		m_pAutoStyles->AddRef();
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir //---------------------------------------------------------------------
263*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::applyControlNumberStyle(const Reference< XPropertySet >& _rxControlModel, const ::rtl::OUString& _rControlNumerStyleName)
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir 	OSL_ENSURE(_rxControlModel.is() && (0 != _rControlNumerStyleName.getLength()),
266*cdf0e10cSrcweir 		"OFormLayerXMLImport_Impl::applyControlNumberStyle: invalid arguments (this will crash)!");
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 	OSL_ENSURE(m_pAutoStyles, "OFormLayerXMLImport_Impl::applyControlNumberStyle: have no auto style context!");
269*cdf0e10cSrcweir 	if (!m_pAutoStyles)
270*cdf0e10cSrcweir 	{
271*cdf0e10cSrcweir 		m_pAutoStyles = m_rImporter.GetShapeImport()->GetAutoStylesContext();
272*cdf0e10cSrcweir 		if (m_pAutoStyles)
273*cdf0e10cSrcweir 			m_pAutoStyles->AddRef();
274*cdf0e10cSrcweir 	}
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 	if (m_pAutoStyles)
277*cdf0e10cSrcweir 	{
278*cdf0e10cSrcweir 		const SvXMLStyleContext* pStyle = m_pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, _rControlNumerStyleName);
279*cdf0e10cSrcweir 		if (pStyle)
280*cdf0e10cSrcweir 		{
281*cdf0e10cSrcweir 			const SvXMLNumFormatContext* pDataStyle = static_cast<const SvXMLNumFormatContext*>(pStyle);
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir 			// set this format at the control model
284*cdf0e10cSrcweir 			try
285*cdf0e10cSrcweir 			{
286*cdf0e10cSrcweir 				// the models number format supplier and formats
287*cdf0e10cSrcweir 				Reference< XNumberFormatsSupplier > xFormatsSupplier;
288*cdf0e10cSrcweir 				_rxControlModel->getPropertyValue(PROPERTY_FORMATSSUPPLIER) >>= xFormatsSupplier;
289*cdf0e10cSrcweir 				Reference< XNumberFormats > xFormats;
290*cdf0e10cSrcweir 				if (xFormatsSupplier.is())
291*cdf0e10cSrcweir 					xFormats = xFormatsSupplier->getNumberFormats();
292*cdf0e10cSrcweir 				OSL_ENSURE(xFormats.is(), "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain the controls number formats!");
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 				// obtain a key
295*cdf0e10cSrcweir 				if (xFormats.is())
296*cdf0e10cSrcweir 				{
297*cdf0e10cSrcweir 			        sal_Int32 nFormatKey = const_cast<SvXMLNumFormatContext*>(pDataStyle)->CreateAndInsert( xFormatsSupplier );
298*cdf0e10cSrcweir 					OSL_ENSURE(-1 != nFormatKey, "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain a format key!");
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir                     // set the format on the control model
301*cdf0e10cSrcweir 					_rxControlModel->setPropertyValue(PROPERTY_FORMATKEY, makeAny(nFormatKey));
302*cdf0e10cSrcweir 				}
303*cdf0e10cSrcweir 			}
304*cdf0e10cSrcweir 			catch(const Exception&)
305*cdf0e10cSrcweir 			{
306*cdf0e10cSrcweir 				OSL_ENSURE(sal_False, "OFormLayerXMLImport_Impl::applyControlNumberStyle: couldn't set the format!");
307*cdf0e10cSrcweir 			}
308*cdf0e10cSrcweir 		}
309*cdf0e10cSrcweir 		else
310*cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "OFormLayerXMLImport_Impl::applyControlNumberStyle: did not find the style with the given name!");
311*cdf0e10cSrcweir 	}
312*cdf0e10cSrcweir }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir //---------------------------------------------------------------------
315*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::registerCellValueBinding( const Reference< XPropertySet >& _rxControlModel, const ::rtl::OUString& _rCellAddress )
316*cdf0e10cSrcweir {
317*cdf0e10cSrcweir     OSL_ENSURE( _rxControlModel.is() && _rCellAddress.getLength(),
318*cdf0e10cSrcweir         "OFormLayerXMLImport_Impl::registerCellValueBinding: invalid arguments!" );
319*cdf0e10cSrcweir     m_aCellValueBindings.push_back( ModelStringPair( _rxControlModel, _rCellAddress ) );
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir //---------------------------------------------------------------------
323*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::registerXFormsValueBinding(
324*cdf0e10cSrcweir     const Reference< XPropertySet >& _rxControlModel,
325*cdf0e10cSrcweir     const ::rtl::OUString& _rBindingID )
326*cdf0e10cSrcweir {
327*cdf0e10cSrcweir     // TODO: is an empty binding name allowed?
328*cdf0e10cSrcweir     OSL_ENSURE( _rxControlModel.is(), "need  model" );
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     m_aXFormsValueBindings.push_back(
331*cdf0e10cSrcweir         ModelStringPair( _rxControlModel, _rBindingID ) );
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir //---------------------------------------------------------------------
335*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::registerXFormsListBinding(
336*cdf0e10cSrcweir     const Reference< XPropertySet >& _rxControlModel,
337*cdf0e10cSrcweir     const ::rtl::OUString& _rBindingID )
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir     // TODO: is an empty binding name allowed?
340*cdf0e10cSrcweir     OSL_ENSURE( _rxControlModel.is(), "need  model" );
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir     m_aXFormsListBindings.push_back(
343*cdf0e10cSrcweir         ModelStringPair( _rxControlModel, _rBindingID ) );
344*cdf0e10cSrcweir }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir //---------------------------------------------------------------------
347*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::registerXFormsSubmission(
348*cdf0e10cSrcweir     const Reference< XPropertySet >& _rxControlModel,
349*cdf0e10cSrcweir     const ::rtl::OUString& _rSubmissionID )
350*cdf0e10cSrcweir {
351*cdf0e10cSrcweir     // TODO: is an empty binding name allowed?
352*cdf0e10cSrcweir     OSL_ENSURE( _rxControlModel.is(), "need  model" );
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir     m_aXFormsSubmissions.push_back(
355*cdf0e10cSrcweir         ModelStringPair( _rxControlModel, _rSubmissionID ) );
356*cdf0e10cSrcweir }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir //---------------------------------------------------------------------
359*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::registerCellRangeListSource( const Reference< XPropertySet >& _rxControlModel, const ::rtl::OUString& _rCellRangeAddress )
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir     OSL_ENSURE( _rxControlModel.is() && _rCellRangeAddress.getLength(),
362*cdf0e10cSrcweir         "OFormLayerXMLImport_Impl::registerCellRangeListSource: invalid arguments!" );
363*cdf0e10cSrcweir     m_aCellRangeListSources.push_back( ModelStringPair( _rxControlModel, _rCellRangeAddress ) );
364*cdf0e10cSrcweir }
365*cdf0e10cSrcweir //---------------------------------------------------------------------
366*cdf0e10cSrcweir const SvXMLStyleContext* OFormLayerXMLImport_Impl::getStyleElement(const ::rtl::OUString& _rStyleName) const
367*cdf0e10cSrcweir {
368*cdf0e10cSrcweir 	OSL_ENSURE( m_pAutoStyles, "OFormLayerXMLImport_Impl::getStyleElement: have no auto style context!" );
369*cdf0e10cSrcweir 		// did you use setAutoStyleContext?
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 	const SvXMLStyleContext* pControlStyle =
372*cdf0e10cSrcweir 		m_pAutoStyles ? m_pAutoStyles->FindStyleChildContext( XML_STYLE_FAMILY_TEXT_PARAGRAPH, _rStyleName ) : NULL;
373*cdf0e10cSrcweir 	OSL_ENSURE( pControlStyle || !m_pAutoStyles,
374*cdf0e10cSrcweir 				::rtl::OString( "OFormLayerXMLImport_Impl::getStyleElement: did not find the style named \"" )
375*cdf0e10cSrcweir 			+=	::rtl::OString( _rStyleName.getStr(), _rStyleName.getLength(), RTL_TEXTENCODING_ASCII_US )
376*cdf0e10cSrcweir 			+=	::rtl::OString( "\"!" ) );
377*cdf0e10cSrcweir 	return pControlStyle;
378*cdf0e10cSrcweir }
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir //---------------------------------------------------------------------
381*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::enterEventContext()
382*cdf0e10cSrcweir {
383*cdf0e10cSrcweir 	// install our own translation table. We need to disable the other tables because of name conflicts.
384*cdf0e10cSrcweir 	m_rImporter.GetEventImport().PushTranslationTable();
385*cdf0e10cSrcweir 	m_rImporter.GetEventImport().AddTranslationTable(g_pFormsEventTranslation);
386*cdf0e10cSrcweir }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir //---------------------------------------------------------------------
389*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::leaveEventContext()
390*cdf0e10cSrcweir {
391*cdf0e10cSrcweir 	// install the original event tables.
392*cdf0e10cSrcweir 	m_rImporter.GetEventImport().PopTranslationTable();
393*cdf0e10cSrcweir }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir //---------------------------------------------------------------------
396*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::registerControlId(const Reference< XPropertySet >& _rxControl, const ::rtl::OUString& _rId)
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir 	OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::registerControlId: no current page!");
399*cdf0e10cSrcweir 	OSL_ENSURE(_rId.getLength(), "OFormLayerXMLImport_Impl::registerControlId: invalid (empty) control id!");
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 	OSL_ENSURE(m_aCurrentPageIds->second.end() == m_aCurrentPageIds->second.find(_rId), "OFormLayerXMLImport_Impl::registerControlId: control id already used!");
402*cdf0e10cSrcweir 	m_aCurrentPageIds->second[_rId] = _rxControl;
403*cdf0e10cSrcweir }
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir //---------------------------------------------------------------------
406*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::registerControlReferences(const Reference< XPropertySet >& _rxControl, const ::rtl::OUString& _rReferringControls)
407*cdf0e10cSrcweir {
408*cdf0e10cSrcweir 	OSL_ENSURE(_rReferringControls.getLength(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (empty) control id list!");
409*cdf0e10cSrcweir 	OSL_ENSURE(_rxControl.is(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (NULL) control!");
410*cdf0e10cSrcweir 	m_aControlReferences.push_back( ModelStringPair( _rxControl, _rReferringControls ) );
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir //---------------------------------------------------------------------
414*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::startPage(const Reference< XDrawPage >& _rxDrawPage)
415*cdf0e10cSrcweir {
416*cdf0e10cSrcweir 	m_xCurrentPageFormsSupp.clear();
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 	OSL_ENSURE(_rxDrawPage.is(), "OFormLayerXMLImport_Impl::startPage: NULL page!");
419*cdf0e10cSrcweir 	m_xCurrentPageFormsSupp = m_xCurrentPageFormsSupp.query( _rxDrawPage );
420*cdf0e10cSrcweir 	OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::startPage: invalid draw page (no XFormsSupplier)!" );
421*cdf0e10cSrcweir 	if ( !m_xCurrentPageFormsSupp.is() )
422*cdf0e10cSrcweir 		return;
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir 	// add a new entry to our page map
425*cdf0e10cSrcweir 	::std::pair< MapDrawPage2MapIterator, bool > aPagePosition;
426*cdf0e10cSrcweir 	aPagePosition =
427*cdf0e10cSrcweir 		m_aControlIds.insert(MapDrawPage2Map::value_type(_rxDrawPage, MapString2PropertySet()));
428*cdf0e10cSrcweir 	OSL_ENSURE(aPagePosition.second, "OFormLayerXMLImport_Impl::startPage: already imported this page!");
429*cdf0e10cSrcweir 	m_aCurrentPageIds = aPagePosition.first;
430*cdf0e10cSrcweir }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir //---------------------------------------------------------------------
433*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::endPage()
434*cdf0e10cSrcweir {
435*cdf0e10cSrcweir 	OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::endPage: sure you called startPage before?" );
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir 	// do some knittings for the controls which are referring to each other
438*cdf0e10cSrcweir 	try
439*cdf0e10cSrcweir 	{
440*cdf0e10cSrcweir 		static const sal_Unicode s_nSeparator = ',';
441*cdf0e10cSrcweir 		::rtl::OUString sReferring;
442*cdf0e10cSrcweir 		::rtl::OUString sCurrentReferring;
443*cdf0e10cSrcweir 		::rtl::OUString sSeparator(&s_nSeparator, 1);
444*cdf0e10cSrcweir 		Reference< XPropertySet > xCurrentReferring;
445*cdf0e10cSrcweir 		sal_Int32 nSeparator, nPrevSep;
446*cdf0e10cSrcweir         ::std::vector< ModelStringPair >::const_iterator aEnd = m_aControlReferences.end();
447*cdf0e10cSrcweir         for	(	::std::vector< ModelStringPair >::const_iterator aReferences = m_aControlReferences.begin();
448*cdf0e10cSrcweir 				aReferences != aEnd;
449*cdf0e10cSrcweir 				++aReferences
450*cdf0e10cSrcweir 			)
451*cdf0e10cSrcweir 		{
452*cdf0e10cSrcweir 			// the list of control ids is comma separated
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir 			// in a list of n ids there are only n-1 separators ... have to catch this last id
455*cdf0e10cSrcweir 			// -> normalize the list
456*cdf0e10cSrcweir 			sReferring = aReferences->second;
457*cdf0e10cSrcweir 			sReferring += sSeparator;
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir 			nPrevSep = -1;
460*cdf0e10cSrcweir 			while (-1 != (nSeparator = sReferring.indexOf(s_nSeparator, nPrevSep + 1)))
461*cdf0e10cSrcweir 			{
462*cdf0e10cSrcweir 				sCurrentReferring = sReferring.copy(nPrevSep + 1, nSeparator - nPrevSep - 1);
463*cdf0e10cSrcweir 				xCurrentReferring = lookupControlId(sCurrentReferring);
464*cdf0e10cSrcweir 				if (xCurrentReferring.is())
465*cdf0e10cSrcweir 					// if this condition fails, this is an error, but lookupControlId should have asserted this ...
466*cdf0e10cSrcweir 					xCurrentReferring->setPropertyValue( PROPERTY_CONTROLLABEL, makeAny( aReferences->first ) );
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir 				nPrevSep = nSeparator;
469*cdf0e10cSrcweir 			}
470*cdf0e10cSrcweir 		}
471*cdf0e10cSrcweir 	}
472*cdf0e10cSrcweir 	catch(Exception&)
473*cdf0e10cSrcweir 	{
474*cdf0e10cSrcweir 		OSL_ENSURE(sal_False, "OFormLayerXMLImport_Impl::endPage: unable to knit the control references (caught an exception)!");
475*cdf0e10cSrcweir 	}
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir 	// now that we have all children of the forms collection, attach the events
478*cdf0e10cSrcweir 	Reference< XIndexAccess > xIndexContainer;
479*cdf0e10cSrcweir     if ( m_xCurrentPageFormsSupp.is() && m_xCurrentPageFormsSupp->hasForms() )
480*cdf0e10cSrcweir         xIndexContainer = xIndexContainer.query( m_xCurrentPageFormsSupp->getForms() );
481*cdf0e10cSrcweir 	if ( xIndexContainer.is() )
482*cdf0e10cSrcweir 		ODefaultEventAttacherManager::setEvents( xIndexContainer );
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir 	// clear the structures for the control references.
485*cdf0e10cSrcweir 	m_aControlReferences.clear();
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 	// and no we have no current page anymore
488*cdf0e10cSrcweir 	m_aCurrentPageIds = m_aControlIds.end();
489*cdf0e10cSrcweir }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir //---------------------------------------------------------------------
492*cdf0e10cSrcweir Reference< XPropertySet > OFormLayerXMLImport_Impl::lookupControlId(const ::rtl::OUString& _rControlId)
493*cdf0e10cSrcweir {
494*cdf0e10cSrcweir 	OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::lookupControlId: no current page!");
495*cdf0e10cSrcweir 	Reference< XPropertySet > xReturn;
496*cdf0e10cSrcweir 	if (m_aCurrentPageIds != m_aControlIds.end())
497*cdf0e10cSrcweir 	{
498*cdf0e10cSrcweir 		ConstMapString2PropertySetIterator aPos = m_aCurrentPageIds->second.find(_rControlId);
499*cdf0e10cSrcweir 		if (m_aCurrentPageIds->second.end() != aPos)
500*cdf0e10cSrcweir 			xReturn = aPos->second;
501*cdf0e10cSrcweir 		else
502*cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "OFormLayerXMLImport_Impl::lookupControlId: invalid control id (did not find it)!");
503*cdf0e10cSrcweir 	}
504*cdf0e10cSrcweir 	return xReturn;
505*cdf0e10cSrcweir }
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir //---------------------------------------------------------------------
508*cdf0e10cSrcweir SvXMLImportContext* OFormLayerXMLImport_Impl::createOfficeFormsContext(
509*cdf0e10cSrcweir 	SvXMLImport& _rImport,
510*cdf0e10cSrcweir 	sal_uInt16 _nPrefix,
511*cdf0e10cSrcweir 	const rtl::OUString& _rLocalName)
512*cdf0e10cSrcweir {
513*cdf0e10cSrcweir 	return new OFormsRootImport( _rImport, _nPrefix, _rLocalName );
514*cdf0e10cSrcweir }
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir //---------------------------------------------------------------------
517*cdf0e10cSrcweir SvXMLImportContext* OFormLayerXMLImport_Impl::createContext(const sal_uInt16 _nPrefix, const rtl::OUString& _rLocalName,
518*cdf0e10cSrcweir 	const Reference< sax::XAttributeList >&)
519*cdf0e10cSrcweir {
520*cdf0e10cSrcweir     SvXMLImportContext* pContext = NULL;
521*cdf0e10cSrcweir     if ( 0 == _rLocalName.compareToAscii( "form" ) )
522*cdf0e10cSrcweir     {
523*cdf0e10cSrcweir         if ( m_xCurrentPageFormsSupp.is() )
524*cdf0e10cSrcweir             pContext = new OFormImport(*this, *this, _nPrefix, _rLocalName, m_xCurrentPageFormsSupp->getForms() );
525*cdf0e10cSrcweir     }
526*cdf0e10cSrcweir     else if (  ( _nPrefix == XML_NAMESPACE_XFORMS
527*cdf0e10cSrcweir             && ( xmloff::token::IsXMLToken( _rLocalName, xmloff::token::XML_MODEL ) ) )
528*cdf0e10cSrcweir             )
529*cdf0e10cSrcweir     {
530*cdf0e10cSrcweir         pContext = createXFormsModelContext( m_rImporter, _nPrefix, _rLocalName );
531*cdf0e10cSrcweir     }
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir     if ( !pContext )
534*cdf0e10cSrcweir     {
535*cdf0e10cSrcweir         OSL_ENSURE( false, "unknown element" );
536*cdf0e10cSrcweir         pContext =
537*cdf0e10cSrcweir             new SvXMLImportContext(m_rImporter, _nPrefix, _rLocalName);
538*cdf0e10cSrcweir     }
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir 	return pContext;
541*cdf0e10cSrcweir }
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir //---------------------------------------------------------------------
544*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::seekPage(const Reference< XDrawPage >& _rxDrawPage)
545*cdf0e10cSrcweir {
546*cdf0e10cSrcweir 	OSL_ENSURE(m_aCurrentPageIds == m_aControlIds.end(), "OFormLayerXMLImport_Impl::seekPage: importing another page currently! This will smash your import!");
547*cdf0e10cSrcweir 	m_aCurrentPageIds = m_aControlIds.find(_rxDrawPage);
548*cdf0e10cSrcweir 	OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::seekPage: did not find the given page (perhaps it has not been imported, yet?)!");
549*cdf0e10cSrcweir }
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir //---------------------------------------------------------------------
552*cdf0e10cSrcweir void OFormLayerXMLImport_Impl::documentDone( )
553*cdf0e10cSrcweir {
554*cdf0e10cSrcweir     SvXMLImport& rImport = getGlobalContext();
555*cdf0e10cSrcweir     if ( ( rImport.getImportFlags() & IMPORT_CONTENT ) == 0 )
556*cdf0e10cSrcweir         return;
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir     // create (and bind) the spreadsheet cell bindings
559*cdf0e10cSrcweir     if  (   !m_aCellValueBindings.empty()
560*cdf0e10cSrcweir         &&  FormCellBindingHelper::isCellBindingAllowed( rImport.GetModel() )
561*cdf0e10cSrcweir         )
562*cdf0e10cSrcweir     {
563*cdf0e10cSrcweir         static ::rtl::OUString s_sIndex( RTL_CONSTASCII_USTRINGPARAM( ":index" ) );
564*cdf0e10cSrcweir         ::std::vector< ModelStringPair >::const_iterator aEnd = m_aCellValueBindings.end();
565*cdf0e10cSrcweir         for (   ::std::vector< ModelStringPair >::const_iterator aCellBindings = m_aCellValueBindings.begin();
566*cdf0e10cSrcweir                 aCellBindings != aEnd;
567*cdf0e10cSrcweir                 ++aCellBindings
568*cdf0e10cSrcweir             )
569*cdf0e10cSrcweir         {
570*cdf0e10cSrcweir             try
571*cdf0e10cSrcweir             {
572*cdf0e10cSrcweir                 FormCellBindingHelper aHelper( aCellBindings->first, rImport.GetModel() );
573*cdf0e10cSrcweir                 OSL_ENSURE( aHelper.isCellBindingAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
574*cdf0e10cSrcweir                 if ( aHelper.isCellBindingAllowed() )
575*cdf0e10cSrcweir                 {
576*cdf0e10cSrcweir                     // There are special bindings for listboxes. See
577*cdf0e10cSrcweir                     // OListAndComboImport::doRegisterCellValueBinding for a comment on this HACK.
578*cdf0e10cSrcweir                     ::rtl::OUString sBoundCellAddress( aCellBindings->second );
579*cdf0e10cSrcweir                     sal_Int32 nIndicator = sBoundCellAddress.lastIndexOf( s_sIndex );
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir                     bool bUseIndexBinding = false;
582*cdf0e10cSrcweir                     if ( nIndicator != -1 )
583*cdf0e10cSrcweir                     {
584*cdf0e10cSrcweir                         sBoundCellAddress = sBoundCellAddress.copy( 0, nIndicator );
585*cdf0e10cSrcweir                         bUseIndexBinding = true;
586*cdf0e10cSrcweir                     }
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir                     aHelper.setBinding( aHelper.createCellBindingFromStringAddress( sBoundCellAddress, bUseIndexBinding ) );
589*cdf0e10cSrcweir                 }
590*cdf0e10cSrcweir             }
591*cdf0e10cSrcweir             catch( const Exception& )
592*cdf0e10cSrcweir             {
593*cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell!" );
594*cdf0e10cSrcweir             }
595*cdf0e10cSrcweir         }
596*cdf0e10cSrcweir         m_aCellValueBindings.clear();
597*cdf0e10cSrcweir     }
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir     // the same for the spreadsheet cell range list sources
600*cdf0e10cSrcweir     if  (   !m_aCellRangeListSources.empty()
601*cdf0e10cSrcweir         &&  FormCellBindingHelper::isListCellRangeAllowed( rImport.GetModel() )
602*cdf0e10cSrcweir         )
603*cdf0e10cSrcweir     {
604*cdf0e10cSrcweir         for (   ::std::vector< ModelStringPair >::const_iterator aRangeBindings = m_aCellRangeListSources.begin();
605*cdf0e10cSrcweir                 aRangeBindings != m_aCellRangeListSources.end();
606*cdf0e10cSrcweir                 ++aRangeBindings
607*cdf0e10cSrcweir             )
608*cdf0e10cSrcweir         {
609*cdf0e10cSrcweir             try
610*cdf0e10cSrcweir             {
611*cdf0e10cSrcweir                 FormCellBindingHelper aHelper( aRangeBindings->first, rImport.GetModel() );
612*cdf0e10cSrcweir                 OSL_ENSURE( aHelper.isListCellRangeAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
613*cdf0e10cSrcweir                 if ( aHelper.isListCellRangeAllowed() )
614*cdf0e10cSrcweir                 {
615*cdf0e10cSrcweir                     aHelper.setListSource( aHelper.createCellListSourceFromStringAddress( aRangeBindings->second ) );
616*cdf0e10cSrcweir                 }
617*cdf0e10cSrcweir             }
618*cdf0e10cSrcweir             catch( const Exception& )
619*cdf0e10cSrcweir             {
620*cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell range!" );
621*cdf0e10cSrcweir             }
622*cdf0e10cSrcweir         }
623*cdf0e10cSrcweir         m_aCellRangeListSources.clear();
624*cdf0e10cSrcweir     }
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir     // process XForms-bindings; call registerXFormsValueBinding for each
627*cdf0e10cSrcweir     std::for_each( m_aXFormsValueBindings.begin(),
628*cdf0e10cSrcweir                    m_aXFormsValueBindings.end(),
629*cdf0e10cSrcweir                    bind1st( ptr_fun( bindXFormsValueBinding ),
630*cdf0e10cSrcweir                             rImport.GetModel() ) );
631*cdf0e10cSrcweir     // same for list bindings
632*cdf0e10cSrcweir     std::for_each( m_aXFormsListBindings.begin(),
633*cdf0e10cSrcweir                    m_aXFormsListBindings.end(),
634*cdf0e10cSrcweir                    bind1st( ptr_fun( bindXFormsListBinding ),
635*cdf0e10cSrcweir                             rImport.GetModel() ) );
636*cdf0e10cSrcweir     // same for submissions
637*cdf0e10cSrcweir     std::for_each( m_aXFormsSubmissions.begin(),
638*cdf0e10cSrcweir                    m_aXFormsSubmissions.end(),
639*cdf0e10cSrcweir                    bind1st( ptr_fun( bindXFormsSubmission ),
640*cdf0e10cSrcweir                             rImport.GetModel() ) );
641*cdf0e10cSrcweir }
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir //.........................................................................
644*cdf0e10cSrcweir }	// namespace xmloff
645*cdf0e10cSrcweir //.........................................................................
646*cdf0e10cSrcweir 
647