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