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