tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / forms / layerimport.cxx
blob9f1c079f7e1fbc6fea52f34f5893d4a7dcc6e37f
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/form/NavigationBarMode.hpp>
35 #include <com/sun/star/form/TabulatorCycle.hpp>
36 #include <com/sun/star/form/FormButtonType.hpp>
37 #include <com/sun/star/form/ListSourceType.hpp>
38 #include "formevents.hxx"
39 #include "formcellbinding.hxx"
40 #include <xmloff/xformsimport.hxx>
41 #include <xmloff/xmltoken.hxx>
42 #include <xmloff/xmlnamespace.hxx>
43 #include <rtl/strbuf.hxx>
44 #include <comphelper/diagnose_ex.hxx>
46 namespace xmloff
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::container;
52 using namespace ::com::sun::star::drawing;
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::util;
55 using namespace ::com::sun::star::form;
56 using namespace token;
58 //= OFormLayerXMLImport_Impl
59 OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl(SvXMLImport& _rImporter)
60 :m_rImporter(_rImporter)
62 // build the attribute2property map
63 // string properties which are exported as attributes
64 m_aAttributeMetaData.addStringProperty(
65 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Name), PROPERTY_NAME);
66 m_aAttributeMetaData.addStringProperty(
67 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::GroupName), PROPERTY_GROUP_NAME);
68 m_aAttributeMetaData.addStringProperty(
69 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Label), PROPERTY_LABEL);
70 m_aAttributeMetaData.addStringProperty(
71 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TargetLocation), PROPERTY_TARGETURL);
72 m_aAttributeMetaData.addStringProperty(
73 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Title), PROPERTY_TITLE);
74 m_aAttributeMetaData.addStringProperty(
75 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TargetFrame), PROPERTY_TARGETFRAME);
76 m_aAttributeMetaData.addStringProperty(
77 OAttributeMetaData::getDatabaseAttributeToken(DAFlags::DataField), PROPERTY_DATAFIELD);
78 m_aAttributeMetaData.addStringProperty(
79 OAttributeMetaData::getFormAttributeToken(faCommand), PROPERTY_COMMAND);
80 m_aAttributeMetaData.addStringProperty(
81 OAttributeMetaData::getFormAttributeToken(faDatasource), PROPERTY_DATASOURCENAME);
82 m_aAttributeMetaData.addStringProperty(
83 OAttributeMetaData::getFormAttributeToken(faFilter), PROPERTY_FILTER);
84 m_aAttributeMetaData.addStringProperty(
85 OAttributeMetaData::getFormAttributeToken(faOrder), PROPERTY_ORDER);
87 // properties not added because they're already present in another form
88 OSL_ENSURE(
89 OAttributeMetaData::getCommonControlAttributeName(CCAFlags::TargetLocation).equals(
90 OAttributeMetaData::getFormAttributeName(faAction)),
91 "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (1)!");
92 // if this fails, we would have to add a translation from faAction->PROPERTY_TARGETURL
93 // We did not because we already have one CCAFlags::TargetLocation->PROPERTY_TARGETURL,
94 // and CCAFlags::TargetLocation and faAction should be represented by the same attribute
96 OSL_ENSURE(
97 OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Name).equals(
98 OAttributeMetaData::getFormAttributeName(faName)),
99 "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (2)!");
100 // the same for faName, CCAFlags::Name and PROPERTY_NAME
102 // boolean properties which are exported as attributes
103 m_aAttributeMetaData.addBooleanProperty(
104 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::CurrentSelected), PROPERTY_STATE, false);
105 m_aAttributeMetaData.addBooleanProperty(
106 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Disabled), PROPERTY_ENABLED, false, true);
107 m_aAttributeMetaData.addBooleanProperty(
108 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Dropdown), PROPERTY_DROPDOWN, false);
109 m_aAttributeMetaData.addBooleanProperty(
110 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Printable), PROPERTY_PRINTABLE, true);
111 m_aAttributeMetaData.addBooleanProperty(
112 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::ReadOnly), PROPERTY_READONLY, false);
113 m_aAttributeMetaData.addBooleanProperty(
114 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Selected), PROPERTY_DEFAULT_STATE, false);
115 m_aAttributeMetaData.addBooleanProperty(
116 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TabStop), PROPERTY_TABSTOP, true);
117 m_aAttributeMetaData.addBooleanProperty(
118 OAttributeMetaData::getDatabaseAttributeToken(DAFlags::ConvertEmpty), PROPERTY_EMPTY_IS_NULL, false);
119 m_aAttributeMetaData.addBooleanProperty(
120 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::Validation), PROPERTY_STRICTFORMAT, false);
121 m_aAttributeMetaData.addBooleanProperty(
122 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::MultiLine), PROPERTY_MULTILINE, false);
123 m_aAttributeMetaData.addBooleanProperty(
124 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::AutoCompletion), PROPERTY_AUTOCOMPLETE, false);
125 m_aAttributeMetaData.addBooleanProperty(
126 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::Multiple), PROPERTY_MULTISELECTION, false);
127 m_aAttributeMetaData.addBooleanProperty(
128 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::DefaultButton), PROPERTY_DEFAULTBUTTON, false);
129 m_aAttributeMetaData.addBooleanProperty(
130 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::IsTristate), PROPERTY_TRISTATE, false);
131 m_aAttributeMetaData.addBooleanProperty(
132 OAttributeMetaData::getFormAttributeToken(faAllowDeletes), PROPERTY_ALLOWDELETES, true);
133 m_aAttributeMetaData.addBooleanProperty(
134 OAttributeMetaData::getFormAttributeToken(faAllowInserts), PROPERTY_ALLOWINSERTS, true);
135 m_aAttributeMetaData.addBooleanProperty(
136 OAttributeMetaData::getFormAttributeToken(faAllowUpdates), PROPERTY_ALLOWUPDATES, true);
137 m_aAttributeMetaData.addBooleanProperty(
138 OAttributeMetaData::getFormAttributeToken(faApplyFilter), PROPERTY_APPLYFILTER, false);
139 m_aAttributeMetaData.addBooleanProperty(
140 OAttributeMetaData::getFormAttributeToken(faEscapeProcessing), PROPERTY_ESCAPEPROCESSING, true);
141 m_aAttributeMetaData.addBooleanProperty(
142 OAttributeMetaData::getFormAttributeToken(faIgnoreResult), PROPERTY_IGNORERESULT, false);
143 m_aAttributeMetaData.addBooleanProperty(
144 OAttributeMetaData::getSpecialAttributeToken( SCAFlags::Toggle ), PROPERTY_TOGGLE, false );
145 m_aAttributeMetaData.addBooleanProperty(
146 OAttributeMetaData::getSpecialAttributeToken( SCAFlags::FocusOnClick ), PROPERTY_FOCUS_ON_CLICK, true );
147 m_aAttributeMetaData.addBooleanProperty(
148 OAttributeMetaData::getDatabaseAttributeToken( DAFlags::InputRequired ), PROPERTY_INPUT_REQUIRED, false );
150 // the int16 attributes
151 m_aAttributeMetaData.addInt16Property(
152 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::MaxLength), PROPERTY_MAXTEXTLENGTH);
153 m_aAttributeMetaData.addInt16Property(
154 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::Size), PROPERTY_LINECOUNT);
155 m_aAttributeMetaData.addInt16Property(
156 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::TabIndex), PROPERTY_TABINDEX);
157 m_aAttributeMetaData.addInt16Property(
158 OAttributeMetaData::getDatabaseAttributeToken(DAFlags::BoundColumn), PROPERTY_BOUNDCOLUMN);
160 // the int32 attributes
161 m_aAttributeMetaData.addInt32Property(
162 OAttributeMetaData::getSpecialAttributeToken( SCAFlags::PageStepSize ), PROPERTY_BLOCK_INCREMENT );
164 // the enum attributes
165 m_aAttributeMetaData.addEnumProperty(
166 OAttributeMetaData::getCommonControlAttributeToken( CCAFlags::VisualEffect ), PROPERTY_VISUAL_EFFECT,
167 aVisualEffectMap,
168 &::cppu::UnoType<sal_Int16>::get() );
169 m_aAttributeMetaData.addEnumProperty(
170 OAttributeMetaData::getCommonControlAttributeToken( CCAFlags::Orientation ), PROPERTY_ORIENTATION,
171 aOrientationMap,
172 &::cppu::UnoType<sal_Int32>::get() );
173 m_aAttributeMetaData.addEnumProperty(
174 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags::ButtonType), PROPERTY_BUTTONTYPE,
175 aFormButtonTypeMap,
176 &::cppu::UnoType<FormButtonType>::get());
177 m_aAttributeMetaData.addEnumProperty(
178 OAttributeMetaData::getDatabaseAttributeToken(DAFlags::ListSource_TYPE), PROPERTY_LISTSOURCETYPE,
179 aListSourceTypeMap,
180 &::cppu::UnoType<ListSourceType>::get());
181 m_aAttributeMetaData.addEnumProperty(
182 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::State), PROPERTY_DEFAULT_STATE,
183 aCheckStateMap,
184 &::cppu::UnoType<sal_Int16>::get());
185 m_aAttributeMetaData.addEnumProperty(
186 OAttributeMetaData::getSpecialAttributeToken(SCAFlags::CurrentState), PROPERTY_STATE,
187 aCheckStateMap,
188 &::cppu::UnoType<sal_Int16>::get());
189 m_aAttributeMetaData.addEnumProperty(
190 OAttributeMetaData::getFormAttributeToken(faEnctype), PROPERTY_SUBMIT_ENCODING,
191 aSubmitEncodingMap,
192 &::cppu::UnoType<FormSubmitEncoding>::get());
193 m_aAttributeMetaData.addEnumProperty(
194 OAttributeMetaData::getFormAttributeToken(faMethod), PROPERTY_SUBMIT_METHOD,
195 aSubmitMethodMap,
196 &::cppu::UnoType<FormSubmitMethod>::get());
197 m_aAttributeMetaData.addEnumProperty(
198 OAttributeMetaData::getFormAttributeToken(faCommandType), PROPERTY_COMMAND_TYPE,
199 aCommandTypeMap);
200 m_aAttributeMetaData.addEnumProperty(
201 OAttributeMetaData::getFormAttributeToken(faNavigationMode), PROPERTY_NAVIGATION,
202 aNavigationTypeMap,
203 &::cppu::UnoType<NavigationBarMode>::get());
204 m_aAttributeMetaData.addEnumProperty(
205 OAttributeMetaData::getFormAttributeToken(faTabbingCycle), PROPERTY_CYCLE,
206 aTabulatorCycleMap,
207 &::cppu::UnoType<TabulatorCycle>::get());
209 // 'initialize'
210 m_aCurrentPageIds = m_aControlIds.end();
213 OFormLayerXMLImport_Impl::~OFormLayerXMLImport_Impl()
216 void OFormLayerXMLImport_Impl::setAutoStyleContext(SvXMLStylesContext* _pNewContext)
218 OSL_ENSURE(!m_xAutoStyles.is(), "OFormLayerXMLImport_Impl::setAutoStyleContext: not to be called twice!");
219 m_xAutoStyles.set(_pNewContext);
222 void OFormLayerXMLImport_Impl::applyControlNumberStyle(const Reference< XPropertySet >& _rxControlModel, const OUString& _rControlNumberStyleName)
224 OSL_ENSURE(_rxControlModel.is() && (!_rControlNumberStyleName.isEmpty()),
225 "OFormLayerXMLImport_Impl::applyControlNumberStyle: invalid arguments (this will crash)!");
227 OSL_ENSURE(m_xAutoStyles.is(), "OFormLayerXMLImport_Impl::applyControlNumberStyle: have no auto style context!");
228 if (!m_xAutoStyles.is())
230 m_xAutoStyles.set(m_rImporter.GetShapeImport()->GetAutoStylesContext());
233 if (!m_xAutoStyles.is())
234 return;
236 const SvXMLStyleContext* pStyle = m_xAutoStyles->FindStyleChildContext(XmlStyleFamily::DATA_STYLE, _rControlNumberStyleName);
237 if (pStyle)
239 const SvXMLNumFormatContext* pDataStyle = static_cast<const SvXMLNumFormatContext*>(pStyle);
241 // set this format at the control model
244 // the models number format supplier and formats
245 Reference< XNumberFormatsSupplier > xFormatsSupplier;
246 _rxControlModel->getPropertyValue(PROPERTY_FORMATSSUPPLIER) >>= xFormatsSupplier;
247 Reference< XNumberFormats > xFormats;
248 if (xFormatsSupplier.is())
249 xFormats = xFormatsSupplier->getNumberFormats();
250 OSL_ENSURE(xFormats.is(), "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain the controls number formats!");
252 // obtain a key
253 if (xFormats.is())
255 sal_Int32 nFormatKey = const_cast<SvXMLNumFormatContext*>(pDataStyle)->CreateAndInsert( xFormatsSupplier );
256 OSL_ENSURE(-1 != nFormatKey, "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain a format key!");
258 // set the format on the control model
259 _rxControlModel->setPropertyValue(PROPERTY_FORMATKEY, Any(nFormatKey));
262 catch(const Exception&)
264 OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: couldn't set the format!");
267 else
268 OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: did not find the style with the given name!");
271 void OFormLayerXMLImport_Impl::registerCellValueBinding( const Reference< XPropertySet >& _rxControlModel, const OUString& _rCellAddress )
273 OSL_ENSURE( _rxControlModel.is() && !_rCellAddress.isEmpty(),
274 "OFormLayerXMLImport_Impl::registerCellValueBinding: invalid arguments!" );
275 m_aCellValueBindings.emplace_back( _rxControlModel, _rCellAddress );
278 void OFormLayerXMLImport_Impl::registerXFormsValueBinding(
279 const Reference< XPropertySet >& _rxControlModel,
280 const OUString& _rBindingID )
282 // TODO: is an empty binding name allowed?
283 OSL_ENSURE( _rxControlModel.is(), "need model" );
285 m_aXFormsValueBindings.emplace_back( _rxControlModel, _rBindingID );
288 void OFormLayerXMLImport_Impl::registerXFormsListBinding(
289 const Reference< XPropertySet >& _rxControlModel,
290 const OUString& _rBindingID )
292 // TODO: is an empty binding name allowed?
293 OSL_ENSURE( _rxControlModel.is(), "need model" );
295 m_aXFormsListBindings.emplace_back( _rxControlModel, _rBindingID );
298 void OFormLayerXMLImport_Impl::registerXFormsSubmission(
299 const Reference< XPropertySet >& _rxControlModel,
300 const OUString& _rSubmissionID )
302 // TODO: is an empty binding name allowed?
303 OSL_ENSURE( _rxControlModel.is(), "need model" );
305 m_aXFormsSubmissions.emplace_back( _rxControlModel, _rSubmissionID );
308 void OFormLayerXMLImport_Impl::registerCellRangeListSource( const Reference< XPropertySet >& _rxControlModel, const OUString& _rCellRangeAddress )
310 OSL_ENSURE( _rxControlModel.is() && !_rCellRangeAddress.isEmpty(),
311 "OFormLayerXMLImport_Impl::registerCellRangeListSource: invalid arguments!" );
312 m_aCellRangeListSources.emplace_back( _rxControlModel, _rCellRangeAddress );
314 const SvXMLStyleContext* OFormLayerXMLImport_Impl::getStyleElement(const OUString& _rStyleName) const
316 OSL_ENSURE( m_xAutoStyles.is(), "OFormLayerXMLImport_Impl::getStyleElement: have no auto style context!" );
317 // did you use setAutoStyleContext?
319 const SvXMLStyleContext* pControlStyle =
320 m_xAutoStyles.is() ? m_xAutoStyles->FindStyleChildContext( XmlStyleFamily::TEXT_PARAGRAPH, _rStyleName ) : nullptr;
321 OSL_ENSURE( pControlStyle || !m_xAutoStyles.is(),
322 OStringBuffer("OFormLayerXMLImport_Impl::getStyleElement: did not find the style named \"" +
323 OUStringToOString(_rStyleName, RTL_TEXTENCODING_ASCII_US) +
324 "\"!").getStr() );
325 return pControlStyle;
328 void OFormLayerXMLImport_Impl::enterEventContext()
330 // install our own translation table. We need to disable the other tables because of name conflicts.
331 m_rImporter.GetEventImport().PushTranslationTable();
332 m_rImporter.GetEventImport().AddTranslationTable(g_pFormsEventTranslation);
335 void OFormLayerXMLImport_Impl::leaveEventContext()
337 // install the original event tables.
338 m_rImporter.GetEventImport().PopTranslationTable();
341 void OFormLayerXMLImport_Impl::registerControlId(const Reference< XPropertySet >& _rxControl, const OUString& _rId)
343 OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::registerControlId: no current page!");
344 OSL_ENSURE(!_rId.isEmpty(), "OFormLayerXMLImport_Impl::registerControlId: invalid (empty) control id!");
346 OSL_ENSURE(m_aCurrentPageIds->second.end() == m_aCurrentPageIds->second.find(_rId), "OFormLayerXMLImport_Impl::registerControlId: control id already used!");
347 m_aCurrentPageIds->second[_rId] = _rxControl;
350 void OFormLayerXMLImport_Impl::registerControlReferences(const Reference< XPropertySet >& _rxControl, const OUString& _rReferringControls)
352 OSL_ENSURE(!_rReferringControls.isEmpty(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (empty) control id list!");
353 OSL_ENSURE(_rxControl.is(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (NULL) control!");
354 m_aControlReferences.emplace_back( _rxControl, _rReferringControls );
357 void OFormLayerXMLImport_Impl::startPage(const Reference< XDrawPage >& _rxDrawPage)
359 m_xCurrentPageFormsSupp.clear();
361 OSL_ENSURE(_rxDrawPage.is(), "OFormLayerXMLImport_Impl::startPage: NULL page!");
362 m_xCurrentPageFormsSupp.set(_rxDrawPage, css::uno::UNO_QUERY);
363 OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::startPage: invalid draw page (no XFormsSupplier)!" );
364 if ( !m_xCurrentPageFormsSupp.is() )
365 return;
367 // add a new entry to our page map
368 ::std::pair< MapDrawPage2Map::iterator, bool > aPagePosition = m_aControlIds.emplace(_rxDrawPage, MapString2PropertySet());
369 OSL_ENSURE(aPagePosition.second, "OFormLayerXMLImport_Impl::startPage: already imported this page!");
370 m_aCurrentPageIds = aPagePosition.first;
373 void OFormLayerXMLImport_Impl::endPage()
375 OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::endPage: sure you called startPage before?" );
377 // do some knittings for the controls which are referring to each other
380 static const sal_Unicode s_nSeparator = ',';
381 OUString sCurrentReferring;
382 OUString sSeparator(&s_nSeparator, 1);
383 Reference< XPropertySet > xCurrentReferring;
384 sal_Int32 nSeparator, nPrevSep;
385 for ( const auto& rReferences : m_aControlReferences )
387 // the list of control ids is comma separated
389 // in a list of n ids there are only n-1 separators ... have to catch this last id
390 // -> normalize the list
391 OUString sReferring = rReferences.second + sSeparator;
393 nPrevSep = -1;
394 while (-1 != (nSeparator = sReferring.indexOf(s_nSeparator, nPrevSep + 1)))
396 sCurrentReferring = sReferring.copy(nPrevSep + 1, nSeparator - nPrevSep - 1);
397 xCurrentReferring = lookupControlId(sCurrentReferring);
398 if (xCurrentReferring.is())
399 // if this condition fails, this is an error, but lookupControlId should have asserted this ...
400 xCurrentReferring->setPropertyValue( PROPERTY_CONTROLLABEL, Any( rReferences.first ) );
402 nPrevSep = nSeparator;
406 catch(Exception&)
408 TOOLS_WARN_EXCEPTION("xmloff.forms",
409 "unable to knit the control references (caught an exception)!");
412 // now that we have all children of the forms collection, attach the events
413 Reference< XIndexAccess > xIndexContainer;
414 if ( m_xCurrentPageFormsSupp.is() && m_xCurrentPageFormsSupp->hasForms() )
415 xIndexContainer.set(m_xCurrentPageFormsSupp->getForms(), css::uno::UNO_QUERY);
416 if ( xIndexContainer.is() )
417 ODefaultEventAttacherManager::setEvents( xIndexContainer );
419 // clear the structures for the control references.
420 m_aControlReferences.clear();
422 // and no we have no current page anymore
423 m_aCurrentPageIds = m_aControlIds.end();
426 Reference< XPropertySet > OFormLayerXMLImport_Impl::lookupControlId(const OUString& _rControlId)
428 OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::lookupControlId: no current page!");
429 Reference< XPropertySet > xReturn;
430 if (m_aCurrentPageIds != m_aControlIds.end())
432 MapString2PropertySet::const_iterator aPos = m_aCurrentPageIds->second.find(_rControlId);
433 if (m_aCurrentPageIds->second.end() != aPos)
434 xReturn = aPos->second;
435 else
436 SAL_WARN("xmloff", "unknown control id " << _rControlId);
438 return xReturn;
441 SvXMLImportContext* OFormLayerXMLImport_Impl::createOfficeFormsContext(
442 SvXMLImport& _rImport)
444 return new OFormsRootImport( _rImport );
447 SvXMLImportContext* OFormLayerXMLImport_Impl::createContext(
448 sal_Int32 nElement,
449 const Reference< xml::sax::XFastAttributeList >&)
451 SvXMLImportContext* pContext = nullptr;
452 if ( (nElement & TOKEN_MASK) == XML_FORM )
454 if ( m_xCurrentPageFormsSupp.is() )
455 pContext = new OFormImport(*this, *this, m_xCurrentPageFormsSupp->getForms() );
457 else if ( nElement == XML_ELEMENT(XFORMS, XML_MODEL) )
459 pContext = createXFormsModelContext( m_rImporter );
461 else
462 SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
464 return pContext;
467 void OFormLayerXMLImport_Impl::documentDone( )
469 SvXMLImport& rImport = getGlobalContext();
470 if ( !( rImport.getImportFlags() & SvXMLImportFlags::CONTENT ) )
471 return;
473 // create (and bind) the spreadsheet cell bindings
474 if ( !m_aCellValueBindings.empty()
475 && FormCellBindingHelper::isCellBindingAllowed( rImport.GetModel() )
478 for ( const auto& rCellBindings : m_aCellValueBindings )
482 FormCellBindingHelper aHelper( rCellBindings.first, rImport.GetModel() );
483 OSL_ENSURE( aHelper.isCellBindingAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
484 if ( aHelper.isCellBindingAllowed() )
486 // There are special bindings for listboxes. See
487 // OListAndComboImport::doRegisterCellValueBinding for a comment on this HACK.
488 OUString sBoundCellAddress( rCellBindings.second );
489 sal_Int32 nIndicator = sBoundCellAddress.lastIndexOf( ":index" );
491 bool bUseIndexBinding = false;
492 if ( nIndicator != -1 )
494 sBoundCellAddress = sBoundCellAddress.copy( 0, nIndicator );
495 bUseIndexBinding = true;
498 aHelper.setBinding( aHelper.createCellBindingFromStringAddress( sBoundCellAddress, bUseIndexBinding ) );
501 catch( const Exception& )
503 TOOLS_WARN_EXCEPTION("xmloff.forms",
504 "caught an exception while binding to a cell!");
507 m_aCellValueBindings.clear();
510 // the same for the spreadsheet cell range list sources
511 if ( !m_aCellRangeListSources.empty()
512 && FormCellBindingHelper::isListCellRangeAllowed( rImport.GetModel() )
515 for ( const auto& rRangeBindings : m_aCellRangeListSources )
519 FormCellBindingHelper aHelper( rRangeBindings.first, rImport.GetModel() );
520 OSL_ENSURE( aHelper.isListCellRangeAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
521 if ( aHelper.isListCellRangeAllowed() )
523 aHelper.setListSource( aHelper.createCellListSourceFromStringAddress( rRangeBindings.second ) );
526 catch( const Exception& )
528 TOOLS_WARN_EXCEPTION("xmloff.forms",
529 "caught an exception while binding to a cell range!");
532 m_aCellRangeListSources.clear();
535 // process XForms-bindings; call registerXFormsValueBinding for each
536 for (const auto& aXFormsValueBinding : m_aXFormsValueBindings)
537 bindXFormsValueBinding(rImport.GetModel(), aXFormsValueBinding);
538 // same for list bindings
539 for (const auto& aXFormsListBindings : m_aXFormsListBindings)
540 bindXFormsListBinding(rImport.GetModel(), aXFormsListBindings);
541 // same for submissions
542 for (const auto& aXFormsSubmission : m_aXFormsSubmissions)
543 bindXFormsSubmission(rImport.GetModel(), aXFormsSubmission);
546 } // namespace xmloff
548 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */