bump product version to 7.6.3.2-android
[LibreOffice.git] / xmloff / source / forms / layerimport.cxx
blob494f77ab50b70e6af028575c86fa5e82d6814abf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "layerimport.hxx"
21 #include "formenums.hxx"
22 #include "elementimport.hxx"
23 #include "officeforms.hxx"
24 #include "strings.hxx"
25 #include <xmloff/xmlictxt.hxx>
26 #include <xmloff/xmlstyle.hxx>
27 #include <xmloff/families.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <XMLEventImportHelper.hxx>
30 #include <xmloff/xmlnumfi.hxx>
31 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
32 #include <com/sun/star/form/FormSubmitEncoding.hpp>
33 #include <com/sun/star/form/FormSubmitMethod.hpp>
34 #include <com/sun/star/sdb/CommandType.hpp>
35 #include <com/sun/star/form/NavigationBarMode.hpp>
36 #include <com/sun/star/form/TabulatorCycle.hpp>
37 #include <com/sun/star/form/FormButtonType.hpp>
38 #include <com/sun/star/form/ListSourceType.hpp>
39 #include "formevents.hxx"
40 #include "formcellbinding.hxx"
41 #include <xmloff/xformsimport.hxx>
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmlnamespace.hxx>
44 #include <rtl/strbuf.hxx>
45 #include <comphelper/diagnose_ex.hxx>
46 #include <algorithm>
48 namespace xmloff
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::awt;
53 using namespace ::com::sun::star::lang;
54 using namespace ::com::sun::star::beans;
55 using namespace ::com::sun::star::container;
56 using namespace ::com::sun::star::drawing;
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::util;
59 using namespace ::com::sun::star::form;
60 using namespace ::com::sun::star::sdb;
61 using namespace token;
63 //= OFormLayerXMLImport_Impl
64 OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl(SvXMLImport& _rImporter)
65 :m_rImporter(_rImporter)
67 // build the attribute2property map
68 // string properties which are exported as attributes
69 m_aAttributeMetaData.addStringProperty(
70 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Name), PROPERTY_NAME);
71 m_aAttributeMetaData.addStringProperty(
72 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::GroupName), PROPERTY_GROUP_NAME);
73 m_aAttributeMetaData.addStringProperty(
74 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Label), PROPERTY_LABEL);
75 m_aAttributeMetaData.addStringProperty(
76 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TargetLocation), PROPERTY_TARGETURL);
77 m_aAttributeMetaData.addStringProperty(
78 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Title), PROPERTY_TITLE);
79 m_aAttributeMetaData.addStringProperty(
80 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TargetFrame), PROPERTY_TARGETFRAME);
81 m_aAttributeMetaData.addStringProperty(
82 OAttributeMetaData::getDatabaseAttributeToken(DAFlags::DataField), PROPERTY_DATAFIELD);
83 m_aAttributeMetaData.addStringProperty(
84 OAttributeMetaData::getFormAttributeToken(faCommand), PROPERTY_COMMAND);
85 m_aAttributeMetaData.addStringProperty(
86 OAttributeMetaData::getFormAttributeToken(faDatasource), PROPERTY_DATASOURCENAME);
87 m_aAttributeMetaData.addStringProperty(
88 OAttributeMetaData::getFormAttributeToken(faFilter), PROPERTY_FILTER);
89 m_aAttributeMetaData.addStringProperty(
90 OAttributeMetaData::getFormAttributeToken(faOrder), PROPERTY_ORDER);
92 // properties not added because they're already present in another form
93 OSL_ENSURE(
94 OAttributeMetaData::getCommonControlAttributeName(CCAFlags::TargetLocation).equals(
95 OAttributeMetaData::getFormAttributeName(faAction)),
96 "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (1)!");
97 // if this fails, we would have to add a translation from faAction->PROPERTY_TARGETURL
98 // We did not because we already have one CCAFlags::TargetLocation->PROPERTY_TARGETURL,
99 // and CCAFlags::TargetLocation and faAction should be represented by the same attribute
101 OSL_ENSURE(
102 OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Name).equals(
103 OAttributeMetaData::getFormAttributeName(faName)),
104 "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (2)!");
105 // the same for faName, CCAFlags::Name and PROPERTY_NAME
107 // boolean properties which are exported as attributes
108 m_aAttributeMetaData.addBooleanProperty(
109 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::CurrentSelected), PROPERTY_STATE, false);
110 m_aAttributeMetaData.addBooleanProperty(
111 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Disabled), PROPERTY_ENABLED, false, true);
112 m_aAttributeMetaData.addBooleanProperty(
113 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Dropdown), PROPERTY_DROPDOWN, false);
114 m_aAttributeMetaData.addBooleanProperty(
115 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Printable), PROPERTY_PRINTABLE, true);
116 m_aAttributeMetaData.addBooleanProperty(
117 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::ReadOnly), PROPERTY_READONLY, false);
118 m_aAttributeMetaData.addBooleanProperty(
119 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Selected), PROPERTY_DEFAULT_STATE, false);
120 m_aAttributeMetaData.addBooleanProperty(
121 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TabStop), PROPERTY_TABSTOP, true);
122 m_aAttributeMetaData.addBooleanProperty(
123 OAttributeMetaData::getDatabaseAttributeToken(DAFlags::ConvertEmpty), PROPERTY_EMPTY_IS_NULL, false);
124 m_aAttributeMetaData.addBooleanProperty(
125 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::Validation), PROPERTY_STRICTFORMAT, false);
126 m_aAttributeMetaData.addBooleanProperty(
127 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::MultiLine), PROPERTY_MULTILINE, false);
128 m_aAttributeMetaData.addBooleanProperty(
129 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::AutoCompletion), PROPERTY_AUTOCOMPLETE, false);
130 m_aAttributeMetaData.addBooleanProperty(
131 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::Multiple), PROPERTY_MULTISELECTION, false);
132 m_aAttributeMetaData.addBooleanProperty(
133 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::DefaultButton), PROPERTY_DEFAULTBUTTON, false);
134 m_aAttributeMetaData.addBooleanProperty(
135 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::IsTristate), PROPERTY_TRISTATE, false);
136 m_aAttributeMetaData.addBooleanProperty(
137 OAttributeMetaData::getFormAttributeToken(faAllowDeletes), PROPERTY_ALLOWDELETES, true);
138 m_aAttributeMetaData.addBooleanProperty(
139 OAttributeMetaData::getFormAttributeToken(faAllowInserts), PROPERTY_ALLOWINSERTS, true);
140 m_aAttributeMetaData.addBooleanProperty(
141 OAttributeMetaData::getFormAttributeToken(faAllowUpdates), PROPERTY_ALLOWUPDATES, true);
142 m_aAttributeMetaData.addBooleanProperty(
143 OAttributeMetaData::getFormAttributeToken(faApplyFilter), PROPERTY_APPLYFILTER, false);
144 m_aAttributeMetaData.addBooleanProperty(
145 OAttributeMetaData::getFormAttributeToken(faEscapeProcessing), PROPERTY_ESCAPEPROCESSING, true);
146 m_aAttributeMetaData.addBooleanProperty(
147 OAttributeMetaData::getFormAttributeToken(faIgnoreResult), PROPERTY_IGNORERESULT, false);
148 m_aAttributeMetaData.addBooleanProperty(
149 OAttributeMetaData::getSpecialAttributeToken( SCAFlags::Toggle ), PROPERTY_TOGGLE, false );
150 m_aAttributeMetaData.addBooleanProperty(
151 OAttributeMetaData::getSpecialAttributeToken( SCAFlags::FocusOnClick ), PROPERTY_FOCUS_ON_CLICK, true );
152 m_aAttributeMetaData.addBooleanProperty(
153 OAttributeMetaData::getDatabaseAttributeToken( DAFlags::InputRequired ), PROPERTY_INPUT_REQUIRED, false );
155 // the int16 attributes
156 m_aAttributeMetaData.addInt16Property(
157 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::MaxLength), PROPERTY_MAXTEXTLENGTH);
158 m_aAttributeMetaData.addInt16Property(
159 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Size), PROPERTY_LINECOUNT);
160 m_aAttributeMetaData.addInt16Property(
161 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TabIndex), PROPERTY_TABINDEX);
162 m_aAttributeMetaData.addInt16Property(
163 OAttributeMetaData::getDatabaseAttributeToken(DAFlags::BoundColumn), PROPERTY_BOUNDCOLUMN);
165 // the int32 attributes
166 m_aAttributeMetaData.addInt32Property(
167 OAttributeMetaData::getSpecialAttributeToken( SCAFlags::PageStepSize ), PROPERTY_BLOCK_INCREMENT );
169 // the enum attributes
170 m_aAttributeMetaData.addEnumProperty(
171 OAttributeMetaData::getCommonControlAttributeToken( CCAFlags::VisualEffect ), PROPERTY_VISUAL_EFFECT,
172 aVisualEffectMap,
173 &::cppu::UnoType<sal_Int16>::get() );
174 m_aAttributeMetaData.addEnumProperty(
175 OAttributeMetaData::getCommonControlAttributeToken( CCAFlags::Orientation ), PROPERTY_ORIENTATION,
176 aOrientationMap,
177 &::cppu::UnoType<sal_Int32>::get() );
178 m_aAttributeMetaData.addEnumProperty(
179 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::ButtonType), PROPERTY_BUTTONTYPE,
180 aFormButtonTypeMap,
181 &::cppu::UnoType<FormButtonType>::get());
182 m_aAttributeMetaData.addEnumProperty(
183 OAttributeMetaData::getDatabaseAttributeToken(DAFlags::ListSource_TYPE), PROPERTY_LISTSOURCETYPE,
184 aListSourceTypeMap,
185 &::cppu::UnoType<ListSourceType>::get());
186 m_aAttributeMetaData.addEnumProperty(
187 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::State), PROPERTY_DEFAULT_STATE,
188 aCheckStateMap,
189 &::cppu::UnoType<sal_Int16>::get());
190 m_aAttributeMetaData.addEnumProperty(
191 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::CurrentState), PROPERTY_STATE,
192 aCheckStateMap,
193 &::cppu::UnoType<sal_Int16>::get());
194 m_aAttributeMetaData.addEnumProperty(
195 OAttributeMetaData::getFormAttributeToken(faEnctype), PROPERTY_SUBMIT_ENCODING,
196 aSubmitEncodingMap,
197 &::cppu::UnoType<FormSubmitEncoding>::get());
198 m_aAttributeMetaData.addEnumProperty(
199 OAttributeMetaData::getFormAttributeToken(faMethod), PROPERTY_SUBMIT_METHOD,
200 aSubmitMethodMap,
201 &::cppu::UnoType<FormSubmitMethod>::get());
202 m_aAttributeMetaData.addEnumProperty(
203 OAttributeMetaData::getFormAttributeToken(faCommandType), PROPERTY_COMMAND_TYPE,
204 aCommandTypeMap);
205 m_aAttributeMetaData.addEnumProperty(
206 OAttributeMetaData::getFormAttributeToken(faNavigationMode), PROPERTY_NAVIGATION,
207 aNavigationTypeMap,
208 &::cppu::UnoType<NavigationBarMode>::get());
209 m_aAttributeMetaData.addEnumProperty(
210 OAttributeMetaData::getFormAttributeToken(faTabbingCycle), PROPERTY_CYCLE,
211 aTabulatorCycleMap,
212 &::cppu::UnoType<TabulatorCycle>::get());
214 // 'initialize'
215 m_aCurrentPageIds = m_aControlIds.end();
218 OFormLayerXMLImport_Impl::~OFormLayerXMLImport_Impl()
221 void OFormLayerXMLImport_Impl::setAutoStyleContext(SvXMLStylesContext* _pNewContext)
223 OSL_ENSURE(!m_xAutoStyles.is(), "OFormLayerXMLImport_Impl::setAutoStyleContext: not to be called twice!");
224 m_xAutoStyles.set(_pNewContext);
227 void OFormLayerXMLImport_Impl::applyControlNumberStyle(const Reference< XPropertySet >& _rxControlModel, const OUString& _rControlNumberStyleName)
229 OSL_ENSURE(_rxControlModel.is() && (!_rControlNumberStyleName.isEmpty()),
230 "OFormLayerXMLImport_Impl::applyControlNumberStyle: invalid arguments (this will crash)!");
232 OSL_ENSURE(m_xAutoStyles.is(), "OFormLayerXMLImport_Impl::applyControlNumberStyle: have no auto style context!");
233 if (!m_xAutoStyles.is())
235 m_xAutoStyles.set(m_rImporter.GetShapeImport()->GetAutoStylesContext());
238 if (!m_xAutoStyles.is())
239 return;
241 const SvXMLStyleContext* pStyle = m_xAutoStyles->FindStyleChildContext(XmlStyleFamily::DATA_STYLE, _rControlNumberStyleName);
242 if (pStyle)
244 const SvXMLNumFormatContext* pDataStyle = static_cast<const SvXMLNumFormatContext*>(pStyle);
246 // set this format at the control model
249 // the models number format supplier and formats
250 Reference< XNumberFormatsSupplier > xFormatsSupplier;
251 _rxControlModel->getPropertyValue(PROPERTY_FORMATSSUPPLIER) >>= xFormatsSupplier;
252 Reference< XNumberFormats > xFormats;
253 if (xFormatsSupplier.is())
254 xFormats = xFormatsSupplier->getNumberFormats();
255 OSL_ENSURE(xFormats.is(), "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain the controls number formats!");
257 // obtain a key
258 if (xFormats.is())
260 sal_Int32 nFormatKey = const_cast<SvXMLNumFormatContext*>(pDataStyle)->CreateAndInsert( xFormatsSupplier );
261 OSL_ENSURE(-1 != nFormatKey, "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain a format key!");
263 // set the format on the control model
264 _rxControlModel->setPropertyValue(PROPERTY_FORMATKEY, Any(nFormatKey));
267 catch(const Exception&)
269 OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: couldn't set the format!");
272 else
273 OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: did not find the style with the given name!");
276 void OFormLayerXMLImport_Impl::registerCellValueBinding( const Reference< XPropertySet >& _rxControlModel, const OUString& _rCellAddress )
278 OSL_ENSURE( _rxControlModel.is() && !_rCellAddress.isEmpty(),
279 "OFormLayerXMLImport_Impl::registerCellValueBinding: invalid arguments!" );
280 m_aCellValueBindings.emplace_back( _rxControlModel, _rCellAddress );
283 void OFormLayerXMLImport_Impl::registerXFormsValueBinding(
284 const Reference< XPropertySet >& _rxControlModel,
285 const OUString& _rBindingID )
287 // TODO: is an empty binding name allowed?
288 OSL_ENSURE( _rxControlModel.is(), "need model" );
290 m_aXFormsValueBindings.emplace_back( _rxControlModel, _rBindingID );
293 void OFormLayerXMLImport_Impl::registerXFormsListBinding(
294 const Reference< XPropertySet >& _rxControlModel,
295 const OUString& _rBindingID )
297 // TODO: is an empty binding name allowed?
298 OSL_ENSURE( _rxControlModel.is(), "need model" );
300 m_aXFormsListBindings.emplace_back( _rxControlModel, _rBindingID );
303 void OFormLayerXMLImport_Impl::registerXFormsSubmission(
304 const Reference< XPropertySet >& _rxControlModel,
305 const OUString& _rSubmissionID )
307 // TODO: is an empty binding name allowed?
308 OSL_ENSURE( _rxControlModel.is(), "need model" );
310 m_aXFormsSubmissions.emplace_back( _rxControlModel, _rSubmissionID );
313 void OFormLayerXMLImport_Impl::registerCellRangeListSource( const Reference< XPropertySet >& _rxControlModel, const OUString& _rCellRangeAddress )
315 OSL_ENSURE( _rxControlModel.is() && !_rCellRangeAddress.isEmpty(),
316 "OFormLayerXMLImport_Impl::registerCellRangeListSource: invalid arguments!" );
317 m_aCellRangeListSources.emplace_back( _rxControlModel, _rCellRangeAddress );
319 const SvXMLStyleContext* OFormLayerXMLImport_Impl::getStyleElement(const OUString& _rStyleName) const
321 OSL_ENSURE( m_xAutoStyles.is(), "OFormLayerXMLImport_Impl::getStyleElement: have no auto style context!" );
322 // did you use setAutoStyleContext?
324 const SvXMLStyleContext* pControlStyle =
325 m_xAutoStyles.is() ? m_xAutoStyles->FindStyleChildContext( XmlStyleFamily::TEXT_PARAGRAPH, _rStyleName ) : nullptr;
326 OSL_ENSURE( pControlStyle || !m_xAutoStyles.is(),
327 OStringBuffer("OFormLayerXMLImport_Impl::getStyleElement: did not find the style named \"" +
328 OUStringToOString(_rStyleName, RTL_TEXTENCODING_ASCII_US) +
329 "\"!").getStr() );
330 return pControlStyle;
333 void OFormLayerXMLImport_Impl::enterEventContext()
335 // install our own translation table. We need to disable the other tables because of name conflicts.
336 m_rImporter.GetEventImport().PushTranslationTable();
337 m_rImporter.GetEventImport().AddTranslationTable(g_pFormsEventTranslation);
340 void OFormLayerXMLImport_Impl::leaveEventContext()
342 // install the original event tables.
343 m_rImporter.GetEventImport().PopTranslationTable();
346 void OFormLayerXMLImport_Impl::registerControlId(const Reference< XPropertySet >& _rxControl, const OUString& _rId)
348 OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::registerControlId: no current page!");
349 OSL_ENSURE(!_rId.isEmpty(), "OFormLayerXMLImport_Impl::registerControlId: invalid (empty) control id!");
351 OSL_ENSURE(m_aCurrentPageIds->second.end() == m_aCurrentPageIds->second.find(_rId), "OFormLayerXMLImport_Impl::registerControlId: control id already used!");
352 m_aCurrentPageIds->second[_rId] = _rxControl;
355 void OFormLayerXMLImport_Impl::registerControlReferences(const Reference< XPropertySet >& _rxControl, const OUString& _rReferringControls)
357 OSL_ENSURE(!_rReferringControls.isEmpty(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (empty) control id list!");
358 OSL_ENSURE(_rxControl.is(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (NULL) control!");
359 m_aControlReferences.emplace_back( _rxControl, _rReferringControls );
362 void OFormLayerXMLImport_Impl::startPage(const Reference< XDrawPage >& _rxDrawPage)
364 m_xCurrentPageFormsSupp.clear();
366 OSL_ENSURE(_rxDrawPage.is(), "OFormLayerXMLImport_Impl::startPage: NULL page!");
367 m_xCurrentPageFormsSupp.set(_rxDrawPage, css::uno::UNO_QUERY);
368 OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::startPage: invalid draw page (no XFormsSupplier)!" );
369 if ( !m_xCurrentPageFormsSupp.is() )
370 return;
372 // add a new entry to our page map
373 ::std::pair< MapDrawPage2Map::iterator, bool > aPagePosition = m_aControlIds.emplace(_rxDrawPage, MapString2PropertySet());
374 OSL_ENSURE(aPagePosition.second, "OFormLayerXMLImport_Impl::startPage: already imported this page!");
375 m_aCurrentPageIds = aPagePosition.first;
378 void OFormLayerXMLImport_Impl::endPage()
380 OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::endPage: sure you called startPage before?" );
382 // do some knittings for the controls which are referring to each other
385 static const sal_Unicode s_nSeparator = ',';
386 OUString sCurrentReferring;
387 OUString sSeparator(&s_nSeparator, 1);
388 Reference< XPropertySet > xCurrentReferring;
389 sal_Int32 nSeparator, nPrevSep;
390 for ( const auto& rReferences : m_aControlReferences )
392 // the list of control ids is comma separated
394 // in a list of n ids there are only n-1 separators ... have to catch this last id
395 // -> normalize the list
396 OUString sReferring = rReferences.second + sSeparator;
398 nPrevSep = -1;
399 while (-1 != (nSeparator = sReferring.indexOf(s_nSeparator, nPrevSep + 1)))
401 sCurrentReferring = sReferring.copy(nPrevSep + 1, nSeparator - nPrevSep - 1);
402 xCurrentReferring = lookupControlId(sCurrentReferring);
403 if (xCurrentReferring.is())
404 // if this condition fails, this is an error, but lookupControlId should have asserted this ...
405 xCurrentReferring->setPropertyValue( PROPERTY_CONTROLLABEL, Any( rReferences.first ) );
407 nPrevSep = nSeparator;
411 catch(Exception&)
413 TOOLS_WARN_EXCEPTION("xmloff.forms",
414 "unable to knit the control references (caught an exception)!");
417 // now that we have all children of the forms collection, attach the events
418 Reference< XIndexAccess > xIndexContainer;
419 if ( m_xCurrentPageFormsSupp.is() && m_xCurrentPageFormsSupp->hasForms() )
420 xIndexContainer.set(m_xCurrentPageFormsSupp->getForms(), css::uno::UNO_QUERY);
421 if ( xIndexContainer.is() )
422 ODefaultEventAttacherManager::setEvents( xIndexContainer );
424 // clear the structures for the control references.
425 m_aControlReferences.clear();
427 // and no we have no current page anymore
428 m_aCurrentPageIds = m_aControlIds.end();
431 Reference< XPropertySet > OFormLayerXMLImport_Impl::lookupControlId(const OUString& _rControlId)
433 OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::lookupControlId: no current page!");
434 Reference< XPropertySet > xReturn;
435 if (m_aCurrentPageIds != m_aControlIds.end())
437 MapString2PropertySet::const_iterator aPos = m_aCurrentPageIds->second.find(_rControlId);
438 if (m_aCurrentPageIds->second.end() != aPos)
439 xReturn = aPos->second;
440 else
441 SAL_WARN("xmloff", "unknown control id " << _rControlId);
443 return xReturn;
446 SvXMLImportContext* OFormLayerXMLImport_Impl::createOfficeFormsContext(
447 SvXMLImport& _rImport)
449 return new OFormsRootImport( _rImport );
452 SvXMLImportContext* OFormLayerXMLImport_Impl::createContext(
453 sal_Int32 nElement,
454 const Reference< xml::sax::XFastAttributeList >&)
456 SvXMLImportContext* pContext = nullptr;
457 if ( (nElement & TOKEN_MASK) == XML_FORM )
459 if ( m_xCurrentPageFormsSupp.is() )
460 pContext = new OFormImport(*this, *this, m_xCurrentPageFormsSupp->getForms() );
462 else if ( nElement == XML_ELEMENT(XFORMS, XML_MODEL) )
464 pContext = createXFormsModelContext( m_rImporter );
466 else
467 SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
469 return pContext;
472 void OFormLayerXMLImport_Impl::documentDone( )
474 SvXMLImport& rImport = getGlobalContext();
475 if ( !( rImport.getImportFlags() & SvXMLImportFlags::CONTENT ) )
476 return;
478 // create (and bind) the spreadsheet cell bindings
479 if ( !m_aCellValueBindings.empty()
480 && FormCellBindingHelper::isCellBindingAllowed( rImport.GetModel() )
483 for ( const auto& rCellBindings : m_aCellValueBindings )
487 FormCellBindingHelper aHelper( rCellBindings.first, rImport.GetModel() );
488 OSL_ENSURE( aHelper.isCellBindingAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
489 if ( aHelper.isCellBindingAllowed() )
491 // There are special bindings for listboxes. See
492 // OListAndComboImport::doRegisterCellValueBinding for a comment on this HACK.
493 OUString sBoundCellAddress( rCellBindings.second );
494 sal_Int32 nIndicator = sBoundCellAddress.lastIndexOf( ":index" );
496 bool bUseIndexBinding = false;
497 if ( nIndicator != -1 )
499 sBoundCellAddress = sBoundCellAddress.copy( 0, nIndicator );
500 bUseIndexBinding = true;
503 aHelper.setBinding( aHelper.createCellBindingFromStringAddress( sBoundCellAddress, bUseIndexBinding ) );
506 catch( const Exception& )
508 TOOLS_WARN_EXCEPTION("xmloff.forms",
509 "caught an exception while binding to a cell!");
512 m_aCellValueBindings.clear();
515 // the same for the spreadsheet cell range list sources
516 if ( !m_aCellRangeListSources.empty()
517 && FormCellBindingHelper::isListCellRangeAllowed( rImport.GetModel() )
520 for ( const auto& rRangeBindings : m_aCellRangeListSources )
524 FormCellBindingHelper aHelper( rRangeBindings.first, rImport.GetModel() );
525 OSL_ENSURE( aHelper.isListCellRangeAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
526 if ( aHelper.isListCellRangeAllowed() )
528 aHelper.setListSource( aHelper.createCellListSourceFromStringAddress( rRangeBindings.second ) );
531 catch( const Exception& )
533 TOOLS_WARN_EXCEPTION("xmloff.forms",
534 "caught an exception while binding to a cell range!");
537 m_aCellRangeListSources.clear();
540 // process XForms-bindings; call registerXFormsValueBinding for each
541 for (const auto& aXFormsValueBinding : m_aXFormsValueBindings)
542 bindXFormsValueBinding(rImport.GetModel(), aXFormsValueBinding);
543 // same for list bindings
544 for (const auto& aXFormsListBindings : m_aXFormsListBindings)
545 bindXFormsListBinding(rImport.GetModel(), aXFormsListBindings);
546 // same for submissions
547 for (const auto& aXFormsSubmission : m_aXFormsSubmissions)
548 bindXFormsSubmission(rImport.GetModel(), aXFormsSubmission);
551 } // namespace xmloff
553 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */