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