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