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