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 :
21 : #include "componenttools.hxx"
22 : #include "DatabaseForm.hxx"
23 : #include "EventThread.hxx"
24 : #include "frm_module.hxx"
25 : #include "frm_resource.hrc"
26 : #include "frm_resource.hxx"
27 : #include "GroupManager.hxx"
28 : #include "property.hrc"
29 : #include "property.hxx"
30 : #include "services.hxx"
31 :
32 : #include <com/sun/star/awt/XControlContainer.hpp>
33 : #include <com/sun/star/awt/XTextComponent.hpp>
34 : #include <com/sun/star/form/DataSelectionType.hpp>
35 : #include <com/sun/star/form/FormComponentType.hpp>
36 : #include <com/sun/star/form/TabulatorCycle.hpp>
37 : #include <com/sun/star/frame/FrameSearchFlag.hpp>
38 : #include <com/sun/star/frame/XDispatch.hpp>
39 : #include <com/sun/star/frame/XDispatchProvider.hpp>
40 : #include <com/sun/star/frame/XModel.hpp>
41 : #include <com/sun/star/io/XObjectInputStream.hpp>
42 : #include <com/sun/star/io/XObjectOutputStream.hpp>
43 : #include <com/sun/star/sdb/CommandType.hpp>
44 : #include <com/sun/star/sdb/RowSetVetoException.hpp>
45 : #include <com/sun/star/sdb/SQLContext.hpp>
46 : #include <com/sun/star/sdb/XColumnUpdate.hpp>
47 : #include <com/sun/star/sdbc/DataType.hpp>
48 : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
49 : #include <com/sun/star/sdbc/ResultSetType.hpp>
50 : #include <com/sun/star/sdbc/XRowSet.hpp>
51 : #include <com/sun/star/sdbcx/Privilege.hpp>
52 : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
53 : #include <com/sun/star/util/XCancellable.hpp>
54 : #include <com/sun/star/util/URLTransformer.hpp>
55 : #include <com/sun/star/util/XURLTransformer.hpp>
56 : #include <com/sun/star/util/XModifiable2.hpp>
57 :
58 : #include <comphelper/basicio.hxx>
59 : #include <comphelper/container.hxx>
60 : #include <comphelper/enumhelper.hxx>
61 : #include <comphelper/extract.hxx>
62 : #include <comphelper/processfactory.hxx>
63 : #include <comphelper/seqstream.hxx>
64 : #include <comphelper/sequence.hxx>
65 : #include <comphelper/stl_types.hxx>
66 : #include <comphelper/uno3.hxx>
67 : #include <connectivity/dbtools.hxx>
68 : #include <cppuhelper/exc_hlp.hxx>
69 : #include <cppuhelper/implbase2.hxx>
70 : #include <rtl/math.hxx>
71 : #include <rtl/tencinfo.h>
72 : #include <svl/inettype.hxx>
73 : #include <tools/debug.hxx>
74 : #include <tools/diagnose_ex.h>
75 : #include <tools/inetmsg.hxx>
76 : #include <tools/inetstrm.hxx>
77 : #include <tools/urlobj.hxx>
78 : #include <unotools/ucblockbytes.hxx>
79 : #include <unotools/ucbstreamhelper.hxx>
80 : #include <vcl/svapp.hxx>
81 : #include <vcl/timer.hxx>
82 : #include <osl/mutex.hxx>
83 :
84 : #include <ctype.h>
85 : #include <boost/unordered_map.hpp>
86 :
87 : // compatiblity: DatabaseCursorType is dead, but for compatiblity reasons we still have to write it ...
88 : namespace com {
89 : namespace sun {
90 : namespace star {
91 : namespace data {
92 :
93 : enum DatabaseCursorType
94 : {
95 : DatabaseCursorType_FORWARD = 0,
96 : DatabaseCursorType_SNAPSHOT = 1,
97 : DatabaseCursorType_KEYSET = 2,
98 : DatabaseCursorType_DYNAMIC = 3,
99 : DatabaseCursorType_MAKE_FIXED_SIZE = SAL_MAX_ENUM
100 : };
101 :
102 : } } } }
103 :
104 : using namespace ::dbtools;
105 : using namespace ::comphelper;
106 : using namespace ::com::sun::star::uno;
107 : using namespace ::com::sun::star::sdb;
108 : using namespace ::com::sun::star::sdbc;
109 : using namespace ::com::sun::star::sdbcx;
110 : using namespace ::com::sun::star::beans;
111 : using namespace ::com::sun::star::container;
112 : using namespace ::com::sun::star::task;
113 : using namespace ::com::sun::star::frame;
114 : using namespace ::com::sun::star::form;
115 : using namespace ::com::sun::star::awt;
116 : using namespace ::com::sun::star::io;
117 : using namespace ::com::sun::star::lang;
118 : using namespace ::com::sun::star::data;
119 : using namespace ::com::sun::star::util;
120 :
121 : //--------------------------------------------------------------------------
122 15 : extern "C" void SAL_CALL createRegistryInfo_ODatabaseForm()
123 : {
124 15 : static ::frm::OMultiInstanceAutoRegistration< ::frm::ODatabaseForm > aAutoRegistration;
125 15 : }
126 :
127 : //.........................................................................
128 : namespace frm
129 : {
130 : //.........................................................................
131 :
132 : //==================================================================
133 : //= DocumentModifyGuard
134 : //==================================================================
135 : class DocumentModifyGuard
136 : {
137 : public:
138 0 : DocumentModifyGuard( const Reference< XInterface >& _rxFormComponent )
139 0 : :m_xDocumentModify( getXModel( _rxFormComponent ), UNO_QUERY )
140 : {
141 0 : impl_changeModifiableFlag_nothrow( false );
142 0 : }
143 0 : ~DocumentModifyGuard()
144 0 : {
145 0 : impl_changeModifiableFlag_nothrow( true );
146 0 : }
147 :
148 : private:
149 0 : void impl_changeModifiableFlag_nothrow( const bool _enable )
150 : {
151 : try
152 : {
153 0 : if ( m_xDocumentModify.is() )
154 0 : _enable ? m_xDocumentModify->enableSetModified() : m_xDocumentModify->disableSetModified();
155 : }
156 0 : catch(const Exception&)
157 : {
158 : DBG_UNHANDLED_EXCEPTION();
159 : }
160 0 : }
161 :
162 : private:
163 : Reference< XModifiable2 > m_xDocumentModify;
164 : };
165 :
166 : //==================================================================
167 : //= OFormSubmitResetThread
168 : //=-----------------------------------------------------------------
169 : //= submitting and resetting html-forms asynchronously
170 : //==================================================================
171 :
172 : //------------------------------------------------------------------
173 0 : class OFormSubmitResetThread: public OComponentEventThread
174 : {
175 : protected:
176 :
177 : // duplicate an event with respect to it's type
178 : virtual EventObject *cloneEvent( const EventObject *pEvt ) const;
179 :
180 : // process an event. while processing the mutex isn't locked, and pCompImpl
181 : // is made sure to remain valid
182 : virtual void processEvent( ::cppu::OComponentHelper* _pCompImpl,
183 : const EventObject* _pEvt,
184 : const Reference<XControl>& _rControl,
185 : sal_Bool _bSubmit);
186 :
187 : public:
188 :
189 0 : OFormSubmitResetThread(ODatabaseForm* pControl) : OComponentEventThread(pControl) { }
190 : };
191 :
192 : //------------------------------------------------------------------
193 0 : EventObject* OFormSubmitResetThread::cloneEvent(
194 : const EventObject *pEvt ) const
195 : {
196 0 : return new ::com::sun::star::awt::MouseEvent( *(::com::sun::star::awt::MouseEvent *)pEvt );
197 : }
198 :
199 : //------------------------------------------------------------------
200 0 : void OFormSubmitResetThread::processEvent(
201 : ::cppu::OComponentHelper* pCompImpl,
202 : const EventObject *_pEvt,
203 : const Reference<XControl>& _rControl,
204 : sal_Bool _bSubmit)
205 : {
206 0 : if (_bSubmit)
207 0 : ((ODatabaseForm *)pCompImpl)->submit_impl(_rControl, *static_cast<const ::com::sun::star::awt::MouseEvent*>(_pEvt), true);
208 : else
209 0 : ((ODatabaseForm *)pCompImpl)->reset_impl(true);
210 0 : }
211 :
212 : //==================================================================
213 : //= ODatabaseForm
214 : //==================================================================
215 :
216 : //------------------------------------------------------------------
217 169 : Reference< XInterface > SAL_CALL ODatabaseForm::Create( const Reference< XMultiServiceFactory >& _rxFactory )
218 : {
219 169 : return *( new ODatabaseForm( comphelper::getComponentContext(_rxFactory) ) );
220 : }
221 :
222 : //------------------------------------------------------------------------------
223 0 : Sequence<sal_Int8> SAL_CALL ODatabaseForm::getImplementationId() throw(RuntimeException)
224 : {
225 0 : return OImplementationIds::getImplementationId(getTypes());
226 : }
227 :
228 : //------------------------------------------------------------------
229 0 : Sequence<Type> SAL_CALL ODatabaseForm::getTypes() throw(RuntimeException)
230 : {
231 : // ask the aggregate
232 0 : Sequence<Type> aAggregateTypes;
233 0 : Reference<XTypeProvider> xAggregateTypes;
234 0 : if (query_aggregation(m_xAggregate, xAggregateTypes))
235 0 : aAggregateTypes = xAggregateTypes->getTypes();
236 :
237 : Sequence< Type > aRet = concatSequences(
238 : aAggregateTypes, ODatabaseForm_BASE1::getTypes(), OFormComponents::getTypes()
239 0 : );
240 0 : aRet = concatSequences( aRet, ODatabaseForm_BASE2::getTypes(), ODatabaseForm_BASE3::getTypes() );
241 0 : return concatSequences( aRet, OPropertySetAggregationHelper::getTypes() );
242 : }
243 :
244 : //------------------------------------------------------------------
245 20321 : Any SAL_CALL ODatabaseForm::queryAggregation(const Type& _rType) throw(RuntimeException)
246 : {
247 20321 : Any aReturn = ODatabaseForm_BASE1::queryInterface(_rType);
248 : // our own interfaces
249 20321 : if (!aReturn.hasValue())
250 : {
251 7906 : aReturn = ODatabaseForm_BASE2::queryInterface(_rType);
252 : // property set related interfaces
253 7906 : if (!aReturn.hasValue())
254 : {
255 7895 : aReturn = OPropertySetAggregationHelper::queryInterface(_rType);
256 :
257 : // form component collection related interfaces
258 7895 : if (!aReturn.hasValue())
259 : {
260 5630 : aReturn = OFormComponents::queryAggregation(_rType);
261 :
262 : // interfaces already present in the aggregate which we want to reroute
263 : // only available if we could create the aggregate
264 5630 : if (!aReturn.hasValue() && m_xAggregateAsRowSet.is())
265 1500 : aReturn = ODatabaseForm_BASE3::queryInterface(_rType);
266 :
267 : // aggregate interfaces
268 : // (ask the aggregated object _after_ the OComponentHelper (base of OFormComponents),
269 : // so calls to the XComponent interface reach us and not the aggreagtion)
270 5630 : if (!aReturn.hasValue() && m_xAggregate.is())
271 1134 : aReturn = m_xAggregate->queryAggregation(_rType);
272 : }
273 : }
274 : }
275 :
276 20321 : return aReturn;
277 : }
278 :
279 : DBG_NAME(ODatabaseForm);
280 : //------------------------------------------------------------------
281 169 : ODatabaseForm::ODatabaseForm(const Reference<XComponentContext>& _rxContext)
282 : :OFormComponents(_rxContext)
283 : ,OPropertySetAggregationHelper(OComponentHelper::rBHelper)
284 : ,OPropertyChangeListener(m_aMutex)
285 : ,m_aLoadListeners(m_aMutex)
286 : ,m_aRowSetApproveListeners(m_aMutex)
287 : ,m_aRowSetListeners(m_aMutex)
288 : ,m_aSubmitListeners(m_aMutex)
289 : ,m_aErrorListeners(m_aMutex)
290 : ,m_aResetListeners( *this, m_aMutex )
291 : ,m_aPropertyBagHelper( *this )
292 : ,m_pAggregatePropertyMultiplexer(NULL)
293 : ,m_pGroupManager( NULL )
294 : ,m_aParameterManager( m_aMutex, _rxContext )
295 : ,m_aFilterManager()
296 : ,m_pLoadTimer(NULL)
297 : ,m_pThread(NULL)
298 : ,m_nResetsPending(0)
299 : ,m_nPrivileges(0)
300 : ,m_bInsertOnly( sal_False )
301 : ,m_eSubmitMethod(FormSubmitMethod_GET)
302 : ,m_eSubmitEncoding(FormSubmitEncoding_URL)
303 : ,m_eNavigation(NavigationBarMode_CURRENT)
304 : ,m_bAllowInsert(sal_True)
305 : ,m_bAllowUpdate(sal_True)
306 : ,m_bAllowDelete(sal_True)
307 : ,m_bLoaded(sal_False)
308 : ,m_bSubForm(sal_False)
309 : ,m_bForwardingConnection(sal_False)
310 179 : ,m_bSharingConnection( sal_False )
311 : {
312 : DBG_CTOR( ODatabaseForm, NULL );
313 169 : impl_construct();
314 159 : }
315 :
316 : //------------------------------------------------------------------
317 0 : ODatabaseForm::ODatabaseForm( const ODatabaseForm& _cloneSource )
318 : :OFormComponents( _cloneSource )
319 : ,OPropertySetAggregationHelper( OComponentHelper::rBHelper )
320 : ,OPropertyChangeListener( m_aMutex )
321 : ,ODatabaseForm_BASE1()
322 : ,ODatabaseForm_BASE2()
323 : ,ODatabaseForm_BASE3()
324 : ,IPropertyBagHelperContext()
325 : ,m_aLoadListeners( m_aMutex )
326 : ,m_aRowSetApproveListeners( m_aMutex )
327 : ,m_aRowSetListeners( m_aMutex )
328 : ,m_aSubmitListeners( m_aMutex )
329 : ,m_aErrorListeners( m_aMutex )
330 : ,m_aResetListeners( *this, m_aMutex )
331 : ,m_aPropertyBagHelper( *this )
332 : ,m_pAggregatePropertyMultiplexer( NULL )
333 : ,m_pGroupManager( NULL )
334 : ,m_aParameterManager( m_aMutex, _cloneSource.m_xContext )
335 : ,m_aFilterManager()
336 : ,m_pLoadTimer( NULL )
337 : ,m_pThread( NULL )
338 : ,m_nResetsPending( 0 )
339 : ,m_nPrivileges( 0 )
340 : ,m_bInsertOnly( _cloneSource.m_bInsertOnly )
341 : ,m_aControlBorderColorFocus( _cloneSource.m_aControlBorderColorFocus )
342 : ,m_aControlBorderColorMouse( _cloneSource.m_aControlBorderColorMouse )
343 : ,m_aControlBorderColorInvalid( _cloneSource.m_aControlBorderColorInvalid )
344 : ,m_aDynamicControlBorder( _cloneSource.m_aDynamicControlBorder )
345 : ,m_sName( _cloneSource.m_sName )
346 : ,m_aTargetURL( _cloneSource.m_aTargetURL )
347 : ,m_aTargetFrame( _cloneSource.m_aTargetFrame )
348 : ,m_eSubmitMethod( _cloneSource.m_eSubmitMethod )
349 : ,m_eSubmitEncoding( _cloneSource.m_eSubmitEncoding )
350 : ,m_eNavigation( _cloneSource.m_eNavigation )
351 : ,m_bAllowInsert( _cloneSource.m_bAllowInsert )
352 : ,m_bAllowUpdate( _cloneSource.m_bAllowUpdate )
353 : ,m_bAllowDelete( _cloneSource.m_bAllowDelete )
354 : ,m_bLoaded( sal_False )
355 : ,m_bSubForm( sal_False )
356 : ,m_bForwardingConnection( sal_False )
357 0 : ,m_bSharingConnection( sal_False )
358 : {
359 : DBG_CTOR( ODatabaseForm, NULL );
360 :
361 0 : impl_construct();
362 :
363 0 : osl_atomic_increment( &m_refCount );
364 : {
365 : // our aggregated rowset itself is not cloneable, so simply copy the properties
366 0 : ::comphelper::copyProperties( _cloneSource.m_xAggregateSet, m_xAggregateSet );
367 :
368 : // also care for the dynamic properties: If the clone source has properties which we do not have,
369 : // then add them
370 : try
371 : {
372 : Reference< XPropertySet > xSourceProps( const_cast< ODatabaseForm& >( _cloneSource ).queryAggregation(
373 0 : XPropertySet::static_type() ), UNO_QUERY_THROW );
374 0 : Reference< XPropertySetInfo > xSourcePSI( xSourceProps->getPropertySetInfo(), UNO_SET_THROW );
375 0 : Reference< XPropertyState > xSourcePropState( xSourceProps, UNO_QUERY );
376 :
377 0 : Reference< XPropertySetInfo > xDestPSI( getPropertySetInfo(), UNO_QUERY_THROW );
378 :
379 0 : Sequence< Property > aSourceProperties( xSourcePSI->getProperties() );
380 0 : for ( const Property* pSourceProperty = aSourceProperties.getConstArray();
381 0 : pSourceProperty != aSourceProperties.getConstArray() + aSourceProperties.getLength();
382 : ++pSourceProperty
383 : )
384 : {
385 0 : if ( xDestPSI->hasPropertyByName( pSourceProperty->Name ) )
386 0 : continue;
387 :
388 : // the initial value passed to XPropertyContainer is also used as default, usually. So, try
389 : // to retrieve the default of the source property
390 0 : Any aInitialValue;
391 0 : if ( xSourcePropState.is() )
392 : {
393 0 : aInitialValue = xSourcePropState->getPropertyDefault( pSourceProperty->Name );
394 : }
395 : else
396 : {
397 0 : aInitialValue = xSourceProps->getPropertyValue( pSourceProperty->Name );
398 : }
399 0 : addProperty( pSourceProperty->Name, pSourceProperty->Attributes, aInitialValue );
400 0 : setPropertyValue( pSourceProperty->Name, xSourceProps->getPropertyValue( pSourceProperty->Name ) );
401 0 : }
402 : }
403 0 : catch(const Exception&)
404 : {
405 : throw WrappedTargetException(
406 : OUString( "Could not clone the given database form." ),
407 : *const_cast< ODatabaseForm* >( &_cloneSource ),
408 : ::cppu::getCaughtException()
409 0 : );
410 : }
411 : }
412 0 : osl_atomic_decrement( &m_refCount );
413 0 : }
414 :
415 : //------------------------------------------------------------------
416 169 : void ODatabaseForm::impl_construct()
417 : {
418 : // aggregate a row set
419 169 : increment(m_refCount);
420 : {
421 169 : m_xAggregate = Reference< XAggregation >( m_xContext->getServiceManager()->createInstanceWithContext(SRV_SDB_ROWSET, m_xContext), UNO_QUERY_THROW );
422 159 : m_xAggregateAsRowSet.set( m_xAggregate, UNO_QUERY_THROW );
423 159 : setAggregation( m_xAggregate );
424 : }
425 :
426 : // listen for the properties, important for Parameters
427 159 : if ( m_xAggregateSet.is() )
428 : {
429 159 : m_pAggregatePropertyMultiplexer = new OPropertyChangeMultiplexer(this, m_xAggregateSet, sal_False);
430 159 : m_pAggregatePropertyMultiplexer->acquire();
431 159 : m_pAggregatePropertyMultiplexer->addProperty(PROPERTY_COMMAND);
432 159 : m_pAggregatePropertyMultiplexer->addProperty(PROPERTY_ACTIVE_CONNECTION);
433 : }
434 :
435 : {
436 159 : Reference< XWarningsSupplier > xRowSetWarnings( m_xAggregate, UNO_QUERY );
437 159 : m_aWarnings.setExternalWarnings( xRowSetWarnings );
438 : }
439 :
440 159 : if ( m_xAggregate.is() )
441 : {
442 159 : m_xAggregate->setDelegator( static_cast< XWeak* >( this ) );
443 : }
444 :
445 : {
446 159 : m_aFilterManager.initialize( m_xAggregateSet );
447 159 : m_aParameterManager.initialize( this, m_xAggregate );
448 :
449 159 : declareForwardedProperty( PROPERTY_ID_ACTIVE_CONNECTION );
450 : }
451 159 : decrement( m_refCount );
452 :
453 159 : m_pGroupManager = new OGroupManager( this );
454 159 : m_pGroupManager->acquire();
455 159 : }
456 :
457 : //------------------------------------------------------------------
458 468 : ODatabaseForm::~ODatabaseForm()
459 : {
460 : DBG_DTOR(ODatabaseForm,NULL);
461 :
462 156 : m_pGroupManager->release();
463 156 : m_pGroupManager = NULL;
464 :
465 156 : if (m_xAggregate.is())
466 156 : m_xAggregate->setDelegator( NULL );
467 :
468 156 : m_aWarnings.setExternalWarnings( NULL );
469 :
470 156 : if (m_pAggregatePropertyMultiplexer)
471 : {
472 156 : m_pAggregatePropertyMultiplexer->dispose();
473 156 : m_pAggregatePropertyMultiplexer->release();
474 156 : m_pAggregatePropertyMultiplexer = NULL;
475 : }
476 312 : }
477 :
478 : //==============================================================================
479 : // html tools
480 : //------------------------------------------------------------------------
481 0 : OUString ODatabaseForm::GetDataURLEncoded(const Reference<XControl>& SubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt)
482 : {
483 0 : return GetDataEncoded(true,SubmitButton,MouseEvt);
484 : }
485 : // -----------------------------------------------------------------------------
486 0 : OUString ODatabaseForm::GetDataEncoded(bool _bURLEncoded,const Reference<XControl>& SubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt)
487 : {
488 : // Fill List of successful Controls
489 0 : HtmlSuccessfulObjList aSuccObjList;
490 0 : FillSuccessfulList( aSuccObjList, SubmitButton, MouseEvt );
491 :
492 :
493 : // Aggregate Liste to OUString
494 0 : OUStringBuffer aResult;
495 0 : OUString aName;
496 0 : OUString aValue;
497 :
498 0 : for ( HtmlSuccessfulObjListIterator pSuccObj = aSuccObjList.begin();
499 0 : pSuccObj < aSuccObjList.end();
500 : ++pSuccObj
501 : )
502 : {
503 0 : aName = pSuccObj->aName;
504 0 : aValue = pSuccObj->aValue;
505 0 : if( pSuccObj->nRepresentation == SUCCESSFUL_REPRESENT_FILE && !aValue.isEmpty() )
506 : {
507 : // For File URLs we transfer the file name and not a URL, because Netscape does it like that
508 0 : INetURLObject aURL;
509 0 : aURL.SetSmartProtocol(INET_PROT_FILE);
510 0 : aURL.SetSmartURL(aValue);
511 0 : if( INET_PROT_FILE == aURL.GetProtocol() )
512 0 : aValue = INetURLObject::decode(aURL.PathToFileName(), '%', INetURLObject::DECODE_UNAMBIGUOUS);
513 : }
514 0 : Encode( aName );
515 0 : Encode( aValue );
516 :
517 0 : aResult.append(aName);
518 0 : aResult.append(sal_Unicode('='));
519 0 : aResult.append(aValue);
520 :
521 0 : if (pSuccObj < aSuccObjList.end() - 1)
522 : {
523 0 : if ( _bURLEncoded )
524 0 : aResult.append(sal_Unicode('&'));
525 : else
526 0 : aResult.appendAscii("\r\n");
527 : }
528 : }
529 :
530 :
531 0 : aSuccObjList.clear();
532 :
533 0 : return aResult.makeStringAndClear();
534 : }
535 :
536 : //==============================================================================
537 : // html tools
538 : //------------------------------------------------------------------------
539 0 : OUString ODatabaseForm::GetDataTextEncoded(const Reference<XControl>& SubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt)
540 : {
541 0 : return GetDataEncoded(false,SubmitButton,MouseEvt);
542 : }
543 :
544 : //------------------------------------------------------------------------
545 0 : Sequence<sal_Int8> ODatabaseForm::GetDataMultiPartEncoded(const Reference<XControl>& SubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt, OUString& rContentType)
546 : {
547 :
548 : // Create Parent
549 0 : INetMIMEMessage aParent;
550 0 : aParent.EnableAttachChild( INETMSG_MULTIPART_FORM_DATA );
551 :
552 :
553 : // Fill List of successful Controls
554 0 : HtmlSuccessfulObjList aSuccObjList;
555 0 : FillSuccessfulList( aSuccObjList, SubmitButton, MouseEvt );
556 :
557 :
558 : // Aggregate Liste to OUString
559 0 : for ( HtmlSuccessfulObjListIterator pSuccObj = aSuccObjList.begin();
560 0 : pSuccObj < aSuccObjList.end();
561 : ++pSuccObj
562 : )
563 : {
564 0 : if( pSuccObj->nRepresentation == SUCCESSFUL_REPRESENT_TEXT )
565 0 : InsertTextPart( aParent, pSuccObj->aName, pSuccObj->aValue );
566 0 : else if( pSuccObj->nRepresentation == SUCCESSFUL_REPRESENT_FILE )
567 0 : InsertFilePart( aParent, pSuccObj->aName, pSuccObj->aValue );
568 : }
569 :
570 :
571 : // Delete List
572 0 : aSuccObjList.clear();
573 :
574 : // Create MessageStream for parent
575 0 : INetMIMEMessageStream aMessStream;
576 0 : aMessStream.SetSourceMessage( &aParent );
577 0 : aMessStream.GenerateHeader( sal_False );
578 :
579 : // Copy MessageStream to SvStream
580 0 : SvMemoryStream aMemStream;
581 0 : char* pBuf = new char[1025];
582 : int nRead;
583 0 : while( (nRead = aMessStream.Read(pBuf, 1024)) > 0 )
584 0 : aMemStream.Write( pBuf, nRead );
585 0 : delete[] pBuf;
586 :
587 0 : aMemStream.Flush();
588 0 : aMemStream.Seek( 0 );
589 0 : void* pData = (void*)aMemStream.GetData();
590 0 : sal_Int32 nLen = aMemStream.Seek(STREAM_SEEK_TO_END);
591 :
592 0 : rContentType = aParent.GetContentType();
593 0 : return Sequence<sal_Int8>((sal_Int8*)pData, nLen);
594 : }
595 :
596 : //------------------------------------------------------------------------
597 : namespace
598 : {
599 0 : static void appendDigits( sal_Int32 _nNumber, sal_Int8 nDigits, OUStringBuffer& _rOut )
600 : {
601 0 : sal_Int32 nCurLen = _rOut.getLength();
602 0 : _rOut.append( _nNumber );
603 0 : while ( _rOut.getLength() - nCurLen < nDigits )
604 0 : _rOut.insert( nCurLen, (sal_Unicode)'0' );
605 0 : }
606 : }
607 :
608 : //------------------------------------------------------------------------
609 0 : void ODatabaseForm::AppendComponent(HtmlSuccessfulObjList& rList, const Reference<XPropertySet>& xComponentSet, const OUString& rNamePrefix,
610 : const Reference<XControl>& rxSubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt)
611 : {
612 0 : if (!xComponentSet.is())
613 0 : return;
614 :
615 : // MIB 25.6.98: Catch nested Forms; or would we need to submit them?
616 0 : if (!hasProperty(PROPERTY_CLASSID, xComponentSet))
617 0 : return;
618 :
619 : // Get names
620 0 : if (!hasProperty(PROPERTY_NAME, xComponentSet))
621 0 : return;
622 :
623 0 : sal_Int16 nClassId = 0;
624 0 : xComponentSet->getPropertyValue(PROPERTY_CLASSID) >>= nClassId;
625 0 : OUString aName;
626 0 : xComponentSet->getPropertyValue( PROPERTY_NAME ) >>= aName;
627 0 : if( aName.isEmpty() && nClassId != FormComponentType::IMAGEBUTTON)
628 0 : return;
629 : else // Extend name with the prefix
630 0 : aName = rNamePrefix + aName;
631 :
632 0 : switch( nClassId )
633 : {
634 : // Buttons
635 : case FormComponentType::COMMANDBUTTON:
636 : {
637 : // We only evaluate the pressed Submit button
638 : // MIB: If one is passed at all
639 0 : if( rxSubmitButton.is() )
640 : {
641 0 : Reference<XPropertySet> xSubmitButtonComponent(rxSubmitButton->getModel(), UNO_QUERY);
642 0 : if (xSubmitButtonComponent == xComponentSet && hasProperty(PROPERTY_LABEL, xComponentSet))
643 : {
644 : // <name>=<label>
645 0 : OUString aLabel;
646 0 : xComponentSet->getPropertyValue( PROPERTY_LABEL ) >>= aLabel;
647 0 : rList.push_back( HtmlSuccessfulObj(aName, aLabel) );
648 0 : }
649 : }
650 0 : } break;
651 :
652 : // ImageButtons
653 : case FormComponentType::IMAGEBUTTON:
654 : {
655 : // We only evaluate the pressed Submit button
656 : // MIB: If one is passed at all
657 0 : if( rxSubmitButton.is() )
658 : {
659 0 : Reference<XPropertySet> xSubmitButtonComponent(rxSubmitButton->getModel(), UNO_QUERY);
660 0 : if (xSubmitButtonComponent == xComponentSet)
661 : {
662 : // <name>.x=<pos.X>&<name>.y=<pos.Y>
663 0 : OUString aRhs = OUString::valueOf( MouseEvt.X );
664 :
665 : // Only if a name is available we have a name.x
666 0 : OUStringBuffer aLhs(aName);
667 0 : if (!aName.isEmpty())
668 0 : aLhs.append(".x");
669 : else
670 0 : aLhs.append("x");
671 0 : rList.push_back( HtmlSuccessfulObj(aLhs.makeStringAndClear(), aRhs) );
672 :
673 0 : aLhs.append(aName);
674 0 : aRhs = OUString::valueOf( MouseEvt.Y );
675 0 : if (!aName.isEmpty())
676 0 : aLhs.append(".y");
677 : else
678 0 : aLhs.append("y");
679 0 : rList.push_back( HtmlSuccessfulObj(aLhs.makeStringAndClear(), aRhs) );
680 0 : }
681 : }
682 0 : } break;
683 :
684 : // CheckBoxen / RadioButtons
685 : case FormComponentType::CHECKBOX:
686 : case FormComponentType::RADIOBUTTON:
687 : {
688 : // <name>=<refValue>
689 0 : if( !hasProperty(PROPERTY_STATE, xComponentSet) )
690 0 : break;
691 0 : sal_Int16 nChecked = 0;
692 0 : xComponentSet->getPropertyValue( PROPERTY_STATE ) >>= nChecked;
693 0 : if( nChecked != 1 )
694 0 : break;
695 :
696 0 : OUString aStrValue;
697 0 : if( hasProperty(PROPERTY_REFVALUE, xComponentSet) )
698 0 : xComponentSet->getPropertyValue( PROPERTY_REFVALUE ) >>= aStrValue;
699 :
700 0 : rList.push_back( HtmlSuccessfulObj(aName, aStrValue) );
701 0 : } break;
702 :
703 : // Edit
704 : case FormComponentType::TEXTFIELD:
705 : {
706 : // <name>=<text>
707 0 : if( !hasProperty(PROPERTY_TEXT, xComponentSet) )
708 0 : break;
709 :
710 : // MIB: Special treatment for multiline edit only if we have a control for it
711 0 : Any aTmp = xComponentSet->getPropertyValue( PROPERTY_MULTILINE );
712 0 : sal_Bool bMulti = rxSubmitButton.is()
713 0 : && (aTmp.getValueType().getTypeClass() == TypeClass_BOOLEAN)
714 0 : && getBOOL(aTmp);
715 0 : OUString sText;
716 0 : if ( bMulti ) // For multiline edit, get the text at the control
717 : {
718 :
719 0 : Reference<XControlContainer> xControlContainer(rxSubmitButton->getContext(), UNO_QUERY);
720 0 : if( !xControlContainer.is() ) break;
721 :
722 0 : Sequence<Reference<XControl> > aControlSeq = xControlContainer->getControls();
723 0 : Reference<XControl> xControl;
724 0 : Reference<XFormComponent> xControlComponent;
725 :
726 : // Find the right control
727 : sal_Int32 i;
728 0 : for( i=0; i<aControlSeq.getLength(); i++ )
729 : {
730 0 : xControl = aControlSeq.getConstArray()[i];
731 0 : Reference<XPropertySet> xModel(xControl->getModel(), UNO_QUERY);
732 0 : if (xModel == xComponentSet)
733 : {
734 0 : Reference<XTextComponent> xTextComponent(xControl, UNO_QUERY);
735 0 : if( xTextComponent.is() )
736 0 : sText = xTextComponent->getText();
737 0 : break;
738 : }
739 0 : }
740 : // Couldn't find control or it does not exist (edit in the grid)
741 0 : if (i == aControlSeq.getLength())
742 0 : xComponentSet->getPropertyValue( PROPERTY_TEXT ) >>= sText;
743 : }
744 : else
745 0 : xComponentSet->getPropertyValue( PROPERTY_TEXT ) >>= sText;
746 :
747 0 : rList.push_back( HtmlSuccessfulObj(aName, sText) );
748 0 : } break;
749 :
750 : // ComboBox, Patternfield
751 : case FormComponentType::COMBOBOX:
752 : case FormComponentType::PATTERNFIELD:
753 : {
754 : // <name>=<text>
755 0 : if( hasProperty(PROPERTY_TEXT, xComponentSet) )
756 : {
757 0 : OUString aText;
758 0 : xComponentSet->getPropertyValue( PROPERTY_TEXT ) >>= aText;
759 0 : rList.push_back( HtmlSuccessfulObj(aName, aText) );
760 : }
761 0 : } break;
762 : case FormComponentType::CURRENCYFIELD:
763 : case FormComponentType::NUMERICFIELD:
764 : {
765 : // <name>=<wert> // Value is a double with dot as decimal delimiter
766 : // no value (NULL) means empty value
767 0 : if( hasProperty(PROPERTY_VALUE, xComponentSet) )
768 : {
769 0 : OUString aText;
770 0 : Any aVal = xComponentSet->getPropertyValue( PROPERTY_VALUE );
771 :
772 0 : double aDoubleVal = 0;
773 0 : if (aVal >>= aDoubleVal)
774 : {
775 0 : sal_Int16 nScale = 0;
776 0 : xComponentSet->getPropertyValue( PROPERTY_DECIMAL_ACCURACY ) >>= nScale;
777 0 : aText = ::rtl::math::doubleToUString(aDoubleVal, rtl_math_StringFormat_F, nScale, '.', sal_True);
778 : }
779 0 : rList.push_back( HtmlSuccessfulObj(aName, aText) );
780 : }
781 0 : } break;
782 : case FormComponentType::DATEFIELD:
783 : {
784 : // <name>=<wert> // Value is a Date with the format MM-DD-YYYY
785 : // no value (NULL) means empty value
786 0 : if( hasProperty(PROPERTY_DATE, xComponentSet) )
787 : {
788 0 : OUString aText;
789 0 : Any aVal = xComponentSet->getPropertyValue( PROPERTY_DATE );
790 0 : sal_Int32 nInt32Val = 0;
791 0 : if (aVal >>= nInt32Val)
792 : {
793 0 : ::Date aDate( nInt32Val );
794 0 : OUStringBuffer aBuffer;
795 0 : appendDigits( aDate.GetMonth(), 2, aBuffer );
796 0 : aBuffer.append( (sal_Unicode)'-' );
797 0 : appendDigits( aDate.GetDay(), 2, aBuffer );
798 0 : aBuffer.append( (sal_Unicode)'-' );
799 0 : appendDigits( aDate.GetYear(), 4, aBuffer );
800 0 : aText = aBuffer.makeStringAndClear();
801 : }
802 0 : rList.push_back( HtmlSuccessfulObj(aName, aText) );
803 : }
804 0 : } break;
805 : case FormComponentType::TIMEFIELD:
806 : {
807 : // <name>=<wert> // Value is a Time with the format HH:MM:SS
808 : // no value (NULL) means empty value
809 0 : if( hasProperty(PROPERTY_TIME, xComponentSet) )
810 : {
811 0 : OUString aText;
812 0 : Any aVal = xComponentSet->getPropertyValue( PROPERTY_TIME );
813 0 : sal_Int32 nInt32Val = 0;
814 0 : if (aVal >>= nInt32Val)
815 : {
816 0 : ::Time aTime(nInt32Val);
817 0 : OUStringBuffer aBuffer;
818 0 : appendDigits( aTime.GetHour(), 2, aBuffer );
819 0 : aBuffer.append( (sal_Unicode)'-' );
820 0 : appendDigits( aTime.GetMin(), 2, aBuffer );
821 0 : aBuffer.append( (sal_Unicode)'-' );
822 0 : appendDigits( aTime.GetSec(), 2, aBuffer );
823 0 : aText = aBuffer.makeStringAndClear();
824 : }
825 0 : rList.push_back( HtmlSuccessfulObj(aName, aText) );
826 : }
827 0 : } break;
828 :
829 : // starform
830 : case FormComponentType::HIDDENCONTROL:
831 : {
832 :
833 : // <name>=<value>
834 0 : if( hasProperty(PROPERTY_HIDDEN_VALUE, xComponentSet) )
835 : {
836 0 : OUString aText;
837 0 : xComponentSet->getPropertyValue( PROPERTY_HIDDEN_VALUE ) >>= aText;
838 0 : rList.push_back( HtmlSuccessfulObj(aName, aText) );
839 : }
840 0 : } break;
841 :
842 : // starform
843 : case FormComponentType::FILECONTROL:
844 : {
845 : // <name>=<text>
846 0 : if( hasProperty(PROPERTY_TEXT, xComponentSet) )
847 : {
848 :
849 0 : OUString aText;
850 0 : xComponentSet->getPropertyValue( PROPERTY_TEXT ) >>= aText;
851 0 : rList.push_back( HtmlSuccessfulObj(aName, aText, SUCCESSFUL_REPRESENT_FILE) );
852 : }
853 0 : } break;
854 :
855 : // starform
856 : case FormComponentType::LISTBOX:
857 : {
858 :
859 : // <name>=<Token0>&<name>=<Token1>&...&<name>=<TokenN> (multiple selection)
860 0 : if (!hasProperty(PROPERTY_SELECT_SEQ, xComponentSet) ||
861 0 : !hasProperty(PROPERTY_STRINGITEMLIST, xComponentSet))
862 0 : break;
863 :
864 : // Displayed values
865 0 : Sequence< OUString > aVisibleList;
866 0 : xComponentSet->getPropertyValue( PROPERTY_STRINGITEMLIST ) >>= aVisibleList;
867 0 : sal_Int32 nStringCnt = aVisibleList.getLength();
868 0 : const OUString* pStrings = aVisibleList.getConstArray();
869 :
870 : // Value list
871 0 : Sequence< OUString > aValueList;
872 0 : xComponentSet->getPropertyValue( PROPERTY_VALUE_SEQ ) >>= aValueList;
873 0 : sal_Int32 nValCnt = aValueList.getLength();
874 0 : const OUString* pVals = aValueList.getConstArray();
875 :
876 : // Selection
877 0 : Sequence<sal_Int16> aSelectList;
878 0 : xComponentSet->getPropertyValue( PROPERTY_SELECT_SEQ ) >>= aSelectList;
879 0 : sal_Int32 nSelCount = aSelectList.getLength();
880 0 : const sal_Int16* pSels = aSelectList.getConstArray();
881 :
882 : // Simple or multiple selection
883 : // For simple selections MT only accounts for the list's first entry.
884 0 : if (nSelCount > 1 && !getBOOL(xComponentSet->getPropertyValue(PROPERTY_MULTISELECTION)))
885 0 : nSelCount = 1;
886 :
887 : // The indices in the selection list can also be invalid, so we first have to
888 : // find the valid ones to determine the length of the new list.
889 0 : sal_Int32 nCurCnt = 0;
890 : sal_Int32 i;
891 0 : for( i=0; i<nSelCount; ++i )
892 : {
893 0 : if( pSels[i] < nStringCnt )
894 0 : ++nCurCnt;
895 : }
896 :
897 0 : OUString aSubValue;
898 0 : for(i=0; i<nCurCnt; ++i )
899 : {
900 0 : sal_Int16 nSelPos = pSels[i];
901 0 : if (nSelPos < nValCnt && !pVals[nSelPos].isEmpty())
902 : {
903 0 : aSubValue = pVals[nSelPos];
904 : }
905 : else
906 : {
907 0 : aSubValue = pStrings[nSelPos];
908 : }
909 0 : rList.push_back( HtmlSuccessfulObj(aName, aSubValue) );
910 0 : }
911 0 : } break;
912 : case FormComponentType::GRIDCONTROL:
913 : {
914 : // Each of the column values is sent;
915 : // the name is extended by the grid's prefix.
916 0 : Reference<XIndexAccess> xContainer(xComponentSet, UNO_QUERY);
917 0 : if (!xContainer.is())
918 0 : break;
919 :
920 0 : aName += OUString(static_cast<sal_Unicode>('.'));
921 :
922 0 : Reference<XPropertySet> xSet;
923 0 : sal_Int32 nCount = xContainer->getCount();
924 : // we know already how many objects should be appended,
925 : // so why not allocate the space for them
926 0 : rList.reserve( nCount + rList.capacity() ); // not size()
927 0 : for (sal_Int32 i = 0; i < nCount; ++i)
928 : {
929 0 : xContainer->getByIndex(i) >>= xSet;
930 0 : if (xSet.is())
931 0 : AppendComponent(rList, xSet, aName, rxSubmitButton, MouseEvt);
932 0 : }
933 : }
934 0 : }
935 : }
936 :
937 : //------------------------------------------------------------------------
938 0 : void ODatabaseForm::FillSuccessfulList( HtmlSuccessfulObjList& rList,
939 : const Reference<XControl>& rxSubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt )
940 : {
941 : // Delete list
942 0 : rList.clear();
943 : // Iterate over Components
944 0 : Reference<XPropertySet> xComponentSet;
945 0 : OUString aPrefix;
946 :
947 : // we know already how many objects should be appended,
948 : // so why not allocate the space for them
949 0 : rList.reserve( getCount() );
950 0 : for( sal_Int32 nIndex=0; nIndex < getCount(); nIndex++ )
951 : {
952 0 : getByIndex( nIndex ) >>= xComponentSet;
953 0 : AppendComponent(rList, xComponentSet, aPrefix, rxSubmitButton, MouseEvt);
954 0 : }
955 0 : }
956 :
957 : //------------------------------------------------------------------------
958 0 : void ODatabaseForm::Encode( OUString& rString ) const
959 : {
960 0 : OUStringBuffer aResult;
961 :
962 : // Line endings are represented as CR
963 0 : rString = convertLineEnd(rString, LINEEND_CR);
964 :
965 : // Check each character
966 0 : sal_Int32 nStrLen = rString.getLength();
967 : sal_Unicode nCharCode;
968 0 : for( sal_Int32 nCurPos=0; nCurPos < nStrLen; ++nCurPos )
969 : {
970 0 : nCharCode = rString[nCurPos];
971 :
972 : // Handle chars, which are not an alphanumeric character and character codes > 127
973 0 : if( (!isalnum(nCharCode) && nCharCode != (sal_Unicode)' ') || nCharCode > 127 )
974 : {
975 0 : switch( nCharCode )
976 : {
977 : case 13: // CR
978 0 : aResult.append("%0D%0A"); // CR LF in hex
979 0 : break;
980 :
981 :
982 : // Special treatment for Netscape
983 : case 42: // '*'
984 : case 45: // '-'
985 : case 46: // '.'
986 : case 64: // '@'
987 : case 95: // '_'
988 0 : aResult.append(nCharCode);
989 0 : break;
990 :
991 : default:
992 : {
993 : // Convert to hex
994 0 : short nHi = ((sal_Int16)nCharCode) / 16;
995 0 : short nLo = ((sal_Int16)nCharCode) - (nHi*16);
996 0 : if( nHi > 9 ) nHi += (int)'A'-10; else nHi += (int)'0';
997 0 : if( nLo > 9 ) nLo += (int)'A'-10; else nLo += (int)'0';
998 0 : aResult.append('%');
999 0 : aResult.append((sal_Unicode)nHi);
1000 0 : aResult.append((sal_Unicode)nLo);
1001 : }
1002 0 : }
1003 : }
1004 : else
1005 0 : aResult.append(nCharCode);
1006 : }
1007 :
1008 : // Replace spaces with '+'
1009 0 : rString = aResult.makeStringAndClear().replace(' ', '+');
1010 0 : }
1011 :
1012 : //------------------------------------------------------------------------
1013 0 : void ODatabaseForm::InsertTextPart( INetMIMEMessage& rParent, const OUString& rName,
1014 : const OUString& rData )
1015 : {
1016 :
1017 : // Create part as MessageChild
1018 0 : INetMIMEMessage* pChild = new INetMIMEMessage();
1019 :
1020 :
1021 : // Header
1022 0 : OUStringBuffer aContentDisp;
1023 0 : aContentDisp.append("form-data; name=\"");
1024 0 : aContentDisp.append(rName);
1025 0 : aContentDisp.append('\"');
1026 0 : pChild->SetContentDisposition(aContentDisp.makeStringAndClear());
1027 0 : pChild->SetContentType(OUString("text/plain"));
1028 :
1029 0 : rtl_TextEncoding eSystemEncoding = osl_getThreadTextEncoding();
1030 0 : const sal_Char* pBestMatchingEncoding = rtl_getBestMimeCharsetFromTextEncoding( eSystemEncoding );
1031 0 : OUString aBestMatchingEncoding = OUString::createFromAscii(pBestMatchingEncoding);
1032 0 : pChild->SetContentTransferEncoding(aBestMatchingEncoding);
1033 :
1034 : // Body
1035 0 : SvMemoryStream* pStream = new SvMemoryStream;
1036 0 : pStream->WriteLine( OUStringToOString(rData, rtl_getTextEncodingFromMimeCharset(pBestMatchingEncoding)) );
1037 0 : pStream->Flush();
1038 0 : pStream->Seek( 0 );
1039 0 : pChild->SetDocumentLB( new SvLockBytes(pStream, sal_True) );
1040 0 : rParent.AttachChild( *pChild );
1041 0 : }
1042 :
1043 : //------------------------------------------------------------------------
1044 0 : sal_Bool ODatabaseForm::InsertFilePart( INetMIMEMessage& rParent, const OUString& rName,
1045 : const OUString& rFileName )
1046 : {
1047 0 : OUString aFileName(rFileName);
1048 0 : OUString aContentType(CONTENT_TYPE_STR_TEXT_PLAIN);
1049 0 : SvStream *pStream = 0;
1050 :
1051 0 : if (!aFileName.isEmpty())
1052 : {
1053 : // We can only process File URLs yet
1054 0 : INetURLObject aURL;
1055 0 : aURL.SetSmartProtocol(INET_PROT_FILE);
1056 0 : aURL.SetSmartURL(rFileName);
1057 0 : if( INET_PROT_FILE == aURL.GetProtocol() )
1058 : {
1059 0 : aFileName = INetURLObject::decode(aURL.PathToFileName(), '%', INetURLObject::DECODE_UNAMBIGUOUS);
1060 0 : pStream = ::utl::UcbStreamHelper::CreateStream(aFileName, STREAM_READ);
1061 0 : if (!pStream || (pStream->GetError() != ERRCODE_NONE))
1062 : {
1063 0 : delete pStream;
1064 0 : pStream = 0;
1065 : }
1066 0 : sal_Int32 nSepInd = aFileName.lastIndexOf('.');
1067 0 : OUString aExtension = aFileName.copy( nSepInd + 1, aFileName.getLength() - nSepInd - 1 );
1068 0 : INetContentType eContentType = INetContentTypes::GetContentType4Extension( aExtension );
1069 0 : if (eContentType != CONTENT_TYPE_UNKNOWN)
1070 0 : aContentType = INetContentTypes::GetContentType(eContentType);
1071 0 : }
1072 : }
1073 :
1074 : // If something didn't work, we create an empty MemoryStream
1075 0 : if( !pStream )
1076 0 : pStream = new SvMemoryStream;
1077 :
1078 :
1079 : // Create part as MessageChild
1080 0 : INetMIMEMessage* pChild = new INetMIMEMessage;
1081 :
1082 :
1083 : // Header
1084 0 : OUStringBuffer aContentDisp;
1085 0 : aContentDisp.append("form-data; name=\"");
1086 0 : aContentDisp.append(rName);
1087 0 : aContentDisp.append('\"');
1088 0 : aContentDisp.append("; filename=\"");
1089 0 : aContentDisp.append(aFileName);
1090 0 : aContentDisp.append('\"');
1091 0 : pChild->SetContentDisposition(aContentDisp.makeStringAndClear());
1092 0 : pChild->SetContentType( aContentType );
1093 0 : pChild->SetContentTransferEncoding(OUString("8bit"));
1094 :
1095 :
1096 : // Body
1097 0 : pChild->SetDocumentLB( new SvLockBytes(pStream, sal_True) );
1098 0 : rParent.AttachChild( *pChild );
1099 :
1100 0 : return sal_True;
1101 : }
1102 :
1103 : //==============================================================================
1104 : // internals
1105 : //------------------------------------------------------------------------------
1106 0 : void ODatabaseForm::onError( const SQLErrorEvent& _rEvent )
1107 : {
1108 0 : m_aErrorListeners.notifyEach( &XSQLErrorListener::errorOccured, _rEvent );
1109 0 : }
1110 :
1111 : //------------------------------------------------------------------------------
1112 11 : void ODatabaseForm::onError( const SQLException& _rException, const OUString& _rContextDescription )
1113 : {
1114 11 : if ( !m_aErrorListeners.getLength() )
1115 22 : return;
1116 :
1117 0 : SQLErrorEvent aEvent( *this, makeAny( prependErrorInfo( _rException, *this, _rContextDescription ) ) );
1118 0 : onError( aEvent );
1119 : }
1120 :
1121 : //------------------------------------------------------------------------------
1122 12 : void ODatabaseForm::updateParameterInfo()
1123 : {
1124 12 : m_aParameterManager.updateParameterInfo( m_aFilterManager );
1125 12 : }
1126 :
1127 : //------------------------------------------------------------------------------
1128 0 : bool ODatabaseForm::hasValidParent() const
1129 : {
1130 : // do we have to fill the parameters again?
1131 0 : if (m_bSubForm)
1132 : {
1133 0 : Reference<XResultSet> xResultSet(m_xParent, UNO_QUERY);
1134 0 : if (!xResultSet.is())
1135 : {
1136 : OSL_FAIL("ODatabaseForm::hasValidParent() : no parent resultset !");
1137 0 : return false;
1138 : }
1139 : try
1140 : {
1141 0 : Reference< XPropertySet > xSet( m_xParent, UNO_QUERY );
1142 0 : Reference< XLoadable > xLoad( m_xParent, UNO_QUERY );
1143 0 : if ( xLoad->isLoaded()
1144 0 : && ( xResultSet->isBeforeFirst()
1145 0 : || xResultSet->isAfterLast()
1146 0 : || getBOOL( xSet->getPropertyValue( PROPERTY_ISNEW ) )
1147 : )
1148 : )
1149 : // the parent form is loaded and on a "virtual" row -> not valid
1150 0 : return false;
1151 : }
1152 0 : catch(const Exception&)
1153 : {
1154 : // parent could be forwardonly?
1155 0 : return false;
1156 0 : }
1157 : }
1158 0 : return true;
1159 : }
1160 :
1161 : //------------------------------------------------------------------------------
1162 12 : bool ODatabaseForm::fillParameters( ::osl::ResettableMutexGuard& _rClearForNotifies, const Reference< XInteractionHandler >& _rxCompletionHandler )
1163 : {
1164 : // do we have to fill the parameters again?
1165 12 : if ( !m_aParameterManager.isUpToDate() )
1166 12 : updateParameterInfo();
1167 :
1168 : // is there a valid parent?
1169 12 : if ( m_bSubForm && !hasValidParent() )
1170 0 : return true;
1171 :
1172 : // ensure we're connected
1173 12 : if ( !implEnsureConnection() )
1174 0 : return false;
1175 :
1176 12 : if ( m_aParameterManager.isUpToDate() )
1177 12 : return m_aParameterManager.fillParameterValues( _rxCompletionHandler, _rClearForNotifies );
1178 :
1179 0 : return true;
1180 : }
1181 :
1182 : //------------------------------------------------------------------------------
1183 0 : void ODatabaseForm::saveInsertOnlyState( )
1184 : {
1185 : OSL_ENSURE( !m_aIgnoreResult.hasValue(), "ODatabaseForm::saveInsertOnlyState: overriding old value!" );
1186 0 : m_aIgnoreResult = m_xAggregateSet->getPropertyValue( PROPERTY_INSERTONLY );
1187 0 : }
1188 :
1189 : //------------------------------------------------------------------------------
1190 24 : void ODatabaseForm::restoreInsertOnlyState( )
1191 : {
1192 24 : if ( m_aIgnoreResult.hasValue() )
1193 : {
1194 0 : m_xAggregateSet->setPropertyValue( PROPERTY_INSERTONLY, m_aIgnoreResult );
1195 0 : m_aIgnoreResult = Any();
1196 : }
1197 24 : }
1198 :
1199 : //------------------------------------------------------------------------------
1200 12 : sal_Bool ODatabaseForm::executeRowSet(::osl::ResettableMutexGuard& _rClearForNotifies, sal_Bool bMoveToFirst, const Reference< XInteractionHandler >& _rxCompletionHandler)
1201 : {
1202 12 : if (!m_xAggregateAsRowSet.is())
1203 0 : return sal_False;
1204 :
1205 12 : if (!fillParameters(_rClearForNotifies, _rxCompletionHandler))
1206 0 : return sal_False;
1207 :
1208 12 : restoreInsertOnlyState( );
1209 :
1210 : // ensure the aggregated row set has the correct properties
1211 12 : sal_Int32 nConcurrency = ResultSetConcurrency::READ_ONLY;
1212 :
1213 : // if we have a parent, who is not positioned on a valid row
1214 : // we can't be updatable!
1215 12 : if (m_bSubForm && !hasValidParent())
1216 : {
1217 0 : nConcurrency = ResultSetConcurrency::READ_ONLY;
1218 :
1219 : // don't use any parameters if we don't have a valid parent
1220 0 : m_aParameterManager.setAllParametersNull();
1221 :
1222 : // switch to "insert only" mode
1223 0 : saveInsertOnlyState( );
1224 0 : m_xAggregateSet->setPropertyValue( PROPERTY_INSERTONLY, makeAny( sal_True ) );
1225 : }
1226 12 : else if (m_bAllowInsert || m_bAllowUpdate || m_bAllowDelete)
1227 12 : nConcurrency = ResultSetConcurrency::UPDATABLE;
1228 : else
1229 0 : nConcurrency = ResultSetConcurrency::READ_ONLY;
1230 :
1231 12 : m_xAggregateSet->setPropertyValue( PROPERTY_RESULTSET_CONCURRENCY, makeAny( (sal_Int32)nConcurrency ) );
1232 12 : m_xAggregateSet->setPropertyValue( PROPERTY_RESULTSET_TYPE, makeAny( (sal_Int32)ResultSetType::SCROLL_SENSITIVE ) );
1233 :
1234 12 : sal_Bool bSuccess = sal_False;
1235 : try
1236 : {
1237 12 : m_xAggregateAsRowSet->execute();
1238 1 : bSuccess = sal_True;
1239 : }
1240 0 : catch(const RowSetVetoException&)
1241 : {
1242 : }
1243 22 : catch(const SQLException& eDb)
1244 : {
1245 11 : _rClearForNotifies.clear();
1246 11 : if (!m_sCurrentErrorContext.isEmpty())
1247 11 : onError(eDb, m_sCurrentErrorContext);
1248 : else
1249 0 : onError(eDb, FRM_RES_STRING(RID_STR_READERROR));
1250 11 : _rClearForNotifies.reset();
1251 :
1252 11 : restoreInsertOnlyState( );
1253 : }
1254 :
1255 12 : if (bSuccess)
1256 : {
1257 : // adjust the privilege property
1258 : // m_nPrivileges;
1259 1 : m_xAggregateSet->getPropertyValue(PROPERTY_PRIVILEGES) >>= m_nPrivileges;
1260 1 : if (!m_bAllowInsert)
1261 0 : m_nPrivileges &= ~Privilege::INSERT;
1262 1 : if (!m_bAllowUpdate)
1263 0 : m_nPrivileges &= ~Privilege::UPDATE;
1264 1 : if (!m_bAllowDelete)
1265 0 : m_nPrivileges &= ~Privilege::DELETE;
1266 :
1267 1 : if (bMoveToFirst)
1268 : {
1269 : // the row set is positioned _before_ the first row (per definitionem), so move the set ...
1270 : try
1271 : {
1272 : // if we have an insert only rowset we move to the insert row
1273 1 : next();
1274 2 : if (((m_nPrivileges & Privilege::INSERT) == Privilege::INSERT)
1275 1 : && isAfterLast())
1276 : {
1277 : // move on the insert row of set
1278 : // resetting must be done later, after the load events have been posted
1279 : // see :moveToInsertRow and load , reload
1280 0 : Reference<XResultSetUpdate> xUpdate;
1281 0 : if (query_aggregation( m_xAggregate, xUpdate))
1282 0 : xUpdate->moveToInsertRow();
1283 : }
1284 : }
1285 0 : catch(const SQLException& eDB)
1286 : {
1287 0 : _rClearForNotifies.clear();
1288 0 : if (!m_sCurrentErrorContext.isEmpty())
1289 0 : onError(eDB, m_sCurrentErrorContext);
1290 : else
1291 0 : onError(eDB, FRM_RES_STRING(RID_STR_READERROR));
1292 0 : _rClearForNotifies.reset();
1293 0 : bSuccess = sal_False;
1294 : }
1295 : }
1296 : }
1297 12 : return bSuccess;
1298 : }
1299 :
1300 : //------------------------------------------------------------------
1301 158 : void ODatabaseForm::disposing()
1302 : {
1303 158 : if (m_pAggregatePropertyMultiplexer)
1304 158 : m_pAggregatePropertyMultiplexer->dispose();
1305 :
1306 158 : if (m_bLoaded)
1307 1 : unload();
1308 :
1309 : // cancel the submit/reset-thread
1310 : {
1311 158 : ::osl::MutexGuard aGuard( m_aMutex );
1312 158 : if (m_pThread)
1313 : {
1314 0 : m_pThread->release();
1315 0 : m_pThread = NULL;
1316 158 : }
1317 : }
1318 :
1319 158 : EventObject aEvt(static_cast<XWeak*>(this));
1320 158 : m_aLoadListeners.disposeAndClear(aEvt);
1321 158 : m_aRowSetApproveListeners.disposeAndClear(aEvt);
1322 158 : m_aParameterManager.disposing( aEvt );
1323 158 : m_aResetListeners.disposing();
1324 158 : m_aSubmitListeners.disposeAndClear(aEvt);
1325 158 : m_aErrorListeners.disposeAndClear(aEvt);
1326 :
1327 158 : m_aParameterManager.dispose(); // (to free any references it may have to me)
1328 158 : m_aFilterManager.dispose(); // (dito)
1329 :
1330 158 : OFormComponents::disposing();
1331 158 : OPropertySetAggregationHelper::disposing();
1332 :
1333 : // stop listening on the aggregate
1334 158 : if (m_xAggregateAsRowSet.is())
1335 158 : m_xAggregateAsRowSet->removeRowSetListener(this);
1336 :
1337 : // dispose the active connection
1338 316 : Reference<XComponent> xAggregationComponent;
1339 158 : if (query_aggregation(m_xAggregate, xAggregationComponent))
1340 158 : xAggregationComponent->dispose();
1341 :
1342 316 : m_aPropertyBagHelper.dispose();
1343 158 : }
1344 :
1345 : //------------------------------------------------------------------------------
1346 25 : Reference< XConnection > ODatabaseForm::getConnection()
1347 : {
1348 25 : Reference< XConnection > xConn;
1349 25 : m_xAggregateSet->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xConn;
1350 25 : return xConn;
1351 : }
1352 :
1353 : //------------------------------------------------------------------------------
1354 158 : ::osl::Mutex& ODatabaseForm::getMutex()
1355 : {
1356 158 : return m_aMutex;
1357 : }
1358 :
1359 : //==============================================================================
1360 : // property handling
1361 : //------------------------------------------------------------------------------
1362 158 : void ODatabaseForm::describeFixedAndAggregateProperties(
1363 : Sequence< Property >& _rProps,
1364 : Sequence< Property >& _rAggregateProps ) const
1365 : {
1366 158 : BEGIN_DESCRIBE_AGGREGATION_PROPERTIES(22, m_xAggregateSet)
1367 : // we want to "override" the privileges, since we have additional "AllowInsert" etc. properties
1368 158 : RemoveProperty( _rAggregateProps, PROPERTY_PRIVILEGES );
1369 :
1370 : // InsertOnly is also to be overridden, since we sometimes change it ourself
1371 158 : RemoveProperty( _rAggregateProps, PROPERTY_INSERTONLY );
1372 :
1373 : // we remove and re-declare the DataSourceName property, 'cause we want it to be constrained, and the
1374 : // original property of our aggregate isn't
1375 158 : RemoveProperty( _rAggregateProps, PROPERTY_DATASOURCE );
1376 :
1377 : // for connection sharing, we need to override the ActiveConnection property, too
1378 158 : RemoveProperty( _rAggregateProps, PROPERTY_ACTIVE_CONNECTION );
1379 :
1380 : // the Filter property is also overwritten, since we have some implicit filters
1381 : // (e.g. the ones which result from linking master fields to detail fields
1382 : // via column names instead of parameters)
1383 158 : RemoveProperty( _rAggregateProps, PROPERTY_FILTER );
1384 158 : RemoveProperty( _rAggregateProps, PROPERTY_APPLYFILTER );
1385 :
1386 158 : DECL_IFACE_PROP4(ACTIVE_CONNECTION, XConnection, BOUND, TRANSIENT, MAYBEVOID, CONSTRAINED);
1387 158 : DECL_BOOL_PROP2 ( APPLYFILTER, BOUND, MAYBEDEFAULT );
1388 158 : DECL_PROP1 ( NAME, OUString, BOUND );
1389 158 : DECL_PROP1 ( MASTERFIELDS, Sequence< OUString >, BOUND );
1390 158 : DECL_PROP1 ( DETAILFIELDS, Sequence< OUString >, BOUND );
1391 158 : DECL_PROP2 ( DATASOURCE, OUString, BOUND, CONSTRAINED );
1392 158 : DECL_PROP3 ( CYCLE, TabulatorCycle, BOUND, MAYBEVOID, MAYBEDEFAULT );
1393 158 : DECL_PROP2 ( FILTER, OUString, BOUND, MAYBEDEFAULT );
1394 158 : DECL_BOOL_PROP2 ( INSERTONLY, BOUND, MAYBEDEFAULT );
1395 158 : DECL_PROP1 ( NAVIGATION, NavigationBarMode, BOUND );
1396 158 : DECL_BOOL_PROP1 ( ALLOWADDITIONS, BOUND );
1397 158 : DECL_BOOL_PROP1 ( ALLOWEDITS, BOUND );
1398 158 : DECL_BOOL_PROP1 ( ALLOWDELETIONS, BOUND );
1399 158 : DECL_PROP2 ( PRIVILEGES, sal_Int32, TRANSIENT, READONLY );
1400 158 : DECL_PROP1 ( TARGET_URL, OUString, BOUND );
1401 158 : DECL_PROP1 ( TARGET_FRAME, OUString, BOUND );
1402 158 : DECL_PROP1 ( SUBMIT_METHOD, FormSubmitMethod, BOUND );
1403 158 : DECL_PROP1 ( SUBMIT_ENCODING, FormSubmitEncoding, BOUND );
1404 158 : DECL_BOOL_PROP3 ( DYNAMIC_CONTROL_BORDER, BOUND, MAYBEVOID, MAYBEDEFAULT );
1405 158 : DECL_PROP3 ( CONTROL_BORDER_COLOR_FOCUS, sal_Int32, BOUND, MAYBEVOID, MAYBEDEFAULT );
1406 158 : DECL_PROP3 ( CONTROL_BORDER_COLOR_MOUSE, sal_Int32, BOUND, MAYBEVOID, MAYBEDEFAULT );
1407 158 : DECL_PROP3 ( CONTROL_BORDER_COLOR_INVALID, sal_Int32, BOUND, MAYBEVOID, MAYBEDEFAULT );
1408 : END_DESCRIBE_PROPERTIES();
1409 158 : }
1410 :
1411 : //------------------------------------------------------------------------------
1412 0 : Reference< XMultiPropertySet > ODatabaseForm::getPropertiesInterface()
1413 : {
1414 0 : return Reference< XMultiPropertySet >( *this, UNO_QUERY );
1415 : }
1416 :
1417 : //------------------------------------------------------------------------------
1418 9214 : ::cppu::IPropertyArrayHelper& ODatabaseForm::getInfoHelper()
1419 : {
1420 9214 : return m_aPropertyBagHelper.getInfoHelper();
1421 : }
1422 :
1423 : //------------------------------------------------------------------------------
1424 661 : Reference< XPropertySetInfo > ODatabaseForm::getPropertySetInfo() throw( RuntimeException )
1425 : {
1426 661 : return createPropertySetInfo( getInfoHelper() );
1427 : }
1428 :
1429 : //--------------------------------------------------------------------
1430 0 : void SAL_CALL ODatabaseForm::addProperty( const OUString& _rName, ::sal_Int16 _nAttributes, const Any& _rInitialValue ) throw (PropertyExistException, IllegalTypeException, IllegalArgumentException, RuntimeException)
1431 : {
1432 0 : m_aPropertyBagHelper.addProperty( _rName, _nAttributes, _rInitialValue );
1433 0 : }
1434 :
1435 : //--------------------------------------------------------------------
1436 0 : void SAL_CALL ODatabaseForm::removeProperty( const OUString& _rName ) throw (UnknownPropertyException, NotRemoveableException, RuntimeException)
1437 : {
1438 0 : m_aPropertyBagHelper.removeProperty( _rName );
1439 0 : }
1440 :
1441 : //--------------------------------------------------------------------
1442 0 : Sequence< PropertyValue > SAL_CALL ODatabaseForm::getPropertyValues() throw (RuntimeException)
1443 : {
1444 0 : return m_aPropertyBagHelper.getPropertyValues();
1445 : }
1446 :
1447 : //--------------------------------------------------------------------
1448 0 : void SAL_CALL ODatabaseForm::setPropertyValues( const Sequence< PropertyValue >& _rProps ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
1449 : {
1450 0 : m_aPropertyBagHelper.setPropertyValues( _rProps );
1451 0 : }
1452 :
1453 : //------------------------------------------------------------------------------
1454 2 : Any SAL_CALL ODatabaseForm::getWarnings( ) throw (SQLException, RuntimeException)
1455 : {
1456 2 : return m_aWarnings.getWarnings();
1457 : }
1458 :
1459 : //------------------------------------------------------------------------------
1460 2 : void SAL_CALL ODatabaseForm::clearWarnings( ) throw (SQLException, RuntimeException)
1461 : {
1462 2 : m_aWarnings.clearWarnings();
1463 2 : }
1464 :
1465 : //------------------------------------------------------------------------------
1466 0 : Reference< XCloneable > SAL_CALL ODatabaseForm::createClone( ) throw (RuntimeException)
1467 : {
1468 0 : ODatabaseForm* pClone = new ODatabaseForm( *this );
1469 0 : osl_atomic_increment( &pClone->m_refCount );
1470 0 : pClone->clonedFrom( *this );
1471 0 : osl_atomic_decrement( &pClone->m_refCount );
1472 0 : return pClone;
1473 : }
1474 :
1475 : //------------------------------------------------------------------------------
1476 12 : void ODatabaseForm::fire( sal_Int32* pnHandles, const Any* pNewValues, const Any* pOldValues, sal_Int32 nCount, sal_Bool bVetoable )
1477 : {
1478 : // same as in getFastPropertyValue(sal_Int32) : if we're resetting currently don't fire any changes of the
1479 : // IsModified property from sal_False to sal_True, as this is only temporary 'til the reset is done
1480 12 : if (m_nResetsPending > 0)
1481 : {
1482 : // look for the PROPERTY_ID_ISMODIFIED
1483 0 : sal_Int32 nPos = 0;
1484 0 : for (nPos=0; nPos<nCount; ++nPos)
1485 0 : if (pnHandles[nPos] == PROPERTY_ID_ISMODIFIED)
1486 0 : break;
1487 :
1488 0 : if ((nPos < nCount) && (pNewValues[nPos].getValueType().getTypeClass() == TypeClass_BOOLEAN) && getBOOL(pNewValues[nPos]))
1489 : { // yeah, we found it, and it changed to TRUE
1490 0 : if (nPos == 0)
1491 : { // just cut the first element
1492 0 : ++pnHandles;
1493 0 : ++pNewValues;
1494 0 : ++pOldValues;
1495 0 : --nCount;
1496 : }
1497 0 : else if (nPos == nCount - 1)
1498 : // just cut the last element
1499 0 : --nCount;
1500 : else
1501 : { // split into two base class calls
1502 0 : OPropertySetAggregationHelper::fire(pnHandles, pNewValues, pOldValues, nPos, bVetoable);
1503 0 : ++nPos;
1504 0 : OPropertySetAggregationHelper::fire(pnHandles + nPos, pNewValues + nPos, pOldValues + nPos, nCount - nPos, bVetoable);
1505 12 : return;
1506 : }
1507 : }
1508 : }
1509 :
1510 12 : OPropertySetAggregationHelper::fire(pnHandles, pNewValues, pOldValues, nCount, bVetoable);
1511 : }
1512 :
1513 : //------------------------------------------------------------------------------
1514 1213 : Any SAL_CALL ODatabaseForm::getFastPropertyValue( sal_Int32 nHandle )
1515 : throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1516 : {
1517 1213 : if ((nHandle == PROPERTY_ID_ISMODIFIED) && (m_nResetsPending > 0))
1518 0 : return ::cppu::bool2any((sal_False));
1519 : // don't allow the aggregate which is currently being reset to return a (temporary) "yes"
1520 : else
1521 1213 : return OPropertySetAggregationHelper::getFastPropertyValue(nHandle);
1522 : }
1523 :
1524 : //------------------------------------------------------------------------------
1525 1075 : void ODatabaseForm::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
1526 : {
1527 1075 : switch (nHandle)
1528 : {
1529 : case PROPERTY_ID_INSERTONLY:
1530 1 : rValue <<= m_bInsertOnly;
1531 1 : break;
1532 :
1533 : case PROPERTY_ID_FILTER:
1534 16 : rValue <<= m_aFilterManager.getFilterComponent( FilterManager::fcPublicFilter );
1535 16 : break;
1536 :
1537 : case PROPERTY_ID_APPLYFILTER:
1538 13 : rValue <<= m_aFilterManager.isApplyPublicFilter();
1539 13 : break;
1540 :
1541 : case PROPERTY_ID_DATASOURCE:
1542 122 : rValue = m_xAggregateSet->getPropertyValue( PROPERTY_DATASOURCE );
1543 122 : break;
1544 :
1545 : case PROPERTY_ID_TARGET_URL:
1546 1 : rValue <<= m_aTargetURL;
1547 1 : break;
1548 : case PROPERTY_ID_TARGET_FRAME:
1549 1 : rValue <<= m_aTargetFrame;
1550 1 : break;
1551 : case PROPERTY_ID_SUBMIT_METHOD:
1552 1 : rValue <<= m_eSubmitMethod;
1553 1 : break;
1554 : case PROPERTY_ID_SUBMIT_ENCODING:
1555 1 : rValue <<= m_eSubmitEncoding;
1556 1 : break;
1557 : case PROPERTY_ID_NAME:
1558 177 : rValue <<= m_sName;
1559 177 : break;
1560 : case PROPERTY_ID_MASTERFIELDS:
1561 13 : rValue <<= m_aMasterFields;
1562 13 : break;
1563 : case PROPERTY_ID_DETAILFIELDS:
1564 13 : rValue <<= m_aDetailFields;
1565 13 : break;
1566 : case PROPERTY_ID_CYCLE:
1567 1 : rValue = m_aCycle;
1568 1 : break;
1569 : case PROPERTY_ID_NAVIGATION:
1570 1 : rValue <<= m_eNavigation;
1571 1 : break;
1572 : case PROPERTY_ID_ALLOWADDITIONS:
1573 7 : rValue <<= (sal_Bool)m_bAllowInsert;
1574 7 : break;
1575 : case PROPERTY_ID_ALLOWEDITS:
1576 4 : rValue <<= (sal_Bool)m_bAllowUpdate;
1577 4 : break;
1578 : case PROPERTY_ID_ALLOWDELETIONS:
1579 7 : rValue <<= (sal_Bool)m_bAllowDelete;
1580 7 : break;
1581 : case PROPERTY_ID_PRIVILEGES:
1582 6 : rValue <<= (sal_Int32)m_nPrivileges;
1583 6 : break;
1584 : case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1585 72 : rValue = m_aDynamicControlBorder;
1586 72 : break;
1587 : case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1588 72 : rValue = m_aControlBorderColorFocus;
1589 72 : break;
1590 : case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1591 72 : rValue = m_aControlBorderColorMouse;
1592 72 : break;
1593 : case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1594 72 : rValue = m_aControlBorderColorInvalid;
1595 72 : break;
1596 : default:
1597 402 : if ( m_aPropertyBagHelper.hasDynamicPropertyByHandle( nHandle ) )
1598 0 : m_aPropertyBagHelper.getDynamicFastPropertyValue( nHandle, rValue );
1599 : else
1600 402 : OPropertySetAggregationHelper::getFastPropertyValue( rValue, nHandle );
1601 402 : break;
1602 : }
1603 1075 : }
1604 :
1605 : //------------------------------------------------------------------------------
1606 550 : sal_Bool ODatabaseForm::convertFastPropertyValue( Any& rConvertedValue, Any& rOldValue,
1607 : sal_Int32 nHandle, const Any& rValue ) throw( IllegalArgumentException )
1608 : {
1609 550 : sal_Bool bModified(sal_False);
1610 550 : switch (nHandle)
1611 : {
1612 : case PROPERTY_ID_INSERTONLY:
1613 0 : bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_bInsertOnly );
1614 0 : break;
1615 :
1616 : case PROPERTY_ID_FILTER:
1617 1 : bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aFilterManager.getFilterComponent( FilterManager::fcPublicFilter ) );
1618 1 : break;
1619 :
1620 : case PROPERTY_ID_APPLYFILTER:
1621 4 : bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aFilterManager.isApplyPublicFilter() );
1622 4 : break;
1623 :
1624 : case PROPERTY_ID_DATASOURCE:
1625 : {
1626 77 : Any aAggregateProperty;
1627 77 : getFastPropertyValue(aAggregateProperty, PROPERTY_ID_DATASOURCE);
1628 77 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, aAggregateProperty, ::getCppuType(static_cast<const OUString*>(NULL)));
1629 : }
1630 77 : break;
1631 : case PROPERTY_ID_TARGET_URL:
1632 8 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aTargetURL);
1633 8 : break;
1634 : case PROPERTY_ID_TARGET_FRAME:
1635 8 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aTargetFrame);
1636 8 : break;
1637 : case PROPERTY_ID_SUBMIT_METHOD:
1638 0 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_eSubmitMethod);
1639 0 : break;
1640 : case PROPERTY_ID_SUBMIT_ENCODING:
1641 0 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_eSubmitEncoding);
1642 0 : break;
1643 : case PROPERTY_ID_NAME:
1644 279 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sName);
1645 279 : break;
1646 : case PROPERTY_ID_MASTERFIELDS:
1647 0 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aMasterFields);
1648 0 : break;
1649 : case PROPERTY_ID_DETAILFIELDS:
1650 0 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aDetailFields);
1651 0 : break;
1652 : case PROPERTY_ID_CYCLE:
1653 0 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aCycle, ::getCppuType(static_cast<const TabulatorCycle*>(NULL)));
1654 0 : break;
1655 : case PROPERTY_ID_NAVIGATION:
1656 0 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_eNavigation);
1657 0 : break;
1658 : case PROPERTY_ID_ALLOWADDITIONS:
1659 0 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAllowInsert);
1660 0 : break;
1661 : case PROPERTY_ID_ALLOWEDITS:
1662 0 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAllowUpdate);
1663 0 : break;
1664 : case PROPERTY_ID_ALLOWDELETIONS:
1665 0 : bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAllowDelete);
1666 0 : break;
1667 : case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1668 0 : bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aDynamicControlBorder, ::getBooleanCppuType() );
1669 0 : break;
1670 : case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1671 0 : bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aControlBorderColorFocus, getCppuType( static_cast< sal_Int32* >( NULL ) ) );
1672 0 : break;
1673 : case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1674 0 : bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aControlBorderColorMouse, getCppuType( static_cast< sal_Int32* >( NULL ) ) );
1675 0 : break;
1676 : case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1677 0 : bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aControlBorderColorInvalid, getCppuType( static_cast< sal_Int32* >( NULL ) ) );
1678 0 : break;
1679 : default:
1680 173 : if ( m_aPropertyBagHelper.hasDynamicPropertyByHandle ( nHandle ) )
1681 0 : bModified = m_aPropertyBagHelper.convertDynamicFastPropertyValue( nHandle, rValue, rConvertedValue, rOldValue );
1682 : else
1683 173 : bModified = OPropertySetAggregationHelper::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
1684 173 : break;
1685 : }
1686 550 : return bModified;
1687 : }
1688 :
1689 : //------------------------------------------------------------------------------
1690 396 : void ODatabaseForm::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw( Exception )
1691 : {
1692 396 : switch (nHandle)
1693 : {
1694 : case PROPERTY_ID_INSERTONLY:
1695 0 : rValue >>= m_bInsertOnly;
1696 0 : if ( m_aIgnoreResult.hasValue() )
1697 0 : m_aIgnoreResult <<= m_bInsertOnly;
1698 : else
1699 0 : m_xAggregateSet->setPropertyValue( PROPERTY_INSERTONLY, makeAny( m_bInsertOnly ) );
1700 0 : break;
1701 :
1702 : case PROPERTY_ID_FILTER:
1703 : {
1704 0 : OUString sNewFilter;
1705 0 : rValue >>= sNewFilter;
1706 0 : m_aFilterManager.setFilterComponent( FilterManager::fcPublicFilter, sNewFilter );
1707 : }
1708 0 : break;
1709 :
1710 : case PROPERTY_ID_APPLYFILTER:
1711 : {
1712 1 : sal_Bool bApply = sal_True;
1713 1 : rValue >>= bApply;
1714 1 : m_aFilterManager.setApplyPublicFilter( bApply );
1715 : }
1716 1 : break;
1717 :
1718 : case PROPERTY_ID_DATASOURCE:
1719 : {
1720 77 : Reference< XConnection > xSomeConnection;
1721 77 : if ( ::dbtools::isEmbeddedInDatabase( getParent(), xSomeConnection ) )
1722 0 : throw PropertyVetoException();
1723 :
1724 : try
1725 : {
1726 77 : m_xAggregateSet->setPropertyValue(PROPERTY_DATASOURCE, rValue);
1727 : }
1728 0 : catch(const Exception&)
1729 : {
1730 77 : }
1731 : }
1732 77 : break;
1733 : case PROPERTY_ID_TARGET_URL:
1734 0 : rValue >>= m_aTargetURL;
1735 0 : break;
1736 : case PROPERTY_ID_TARGET_FRAME:
1737 0 : rValue >>= m_aTargetFrame;
1738 0 : break;
1739 : case PROPERTY_ID_SUBMIT_METHOD:
1740 0 : rValue >>= m_eSubmitMethod;
1741 0 : break;
1742 : case PROPERTY_ID_SUBMIT_ENCODING:
1743 0 : rValue >>= m_eSubmitEncoding;
1744 0 : break;
1745 : case PROPERTY_ID_NAME:
1746 157 : rValue >>= m_sName;
1747 157 : break;
1748 : case PROPERTY_ID_MASTERFIELDS:
1749 0 : rValue >>= m_aMasterFields;
1750 0 : invlidateParameters();
1751 0 : break;
1752 : case PROPERTY_ID_DETAILFIELDS:
1753 0 : rValue >>= m_aDetailFields;
1754 0 : invlidateParameters();
1755 0 : break;
1756 : case PROPERTY_ID_CYCLE:
1757 0 : m_aCycle = rValue;
1758 0 : break;
1759 : case PROPERTY_ID_NAVIGATION:
1760 0 : rValue >>= m_eNavigation;
1761 0 : break;
1762 : case PROPERTY_ID_ALLOWADDITIONS:
1763 0 : m_bAllowInsert = getBOOL(rValue);
1764 0 : break;
1765 : case PROPERTY_ID_ALLOWEDITS:
1766 0 : m_bAllowUpdate = getBOOL(rValue);
1767 0 : break;
1768 : case PROPERTY_ID_ALLOWDELETIONS:
1769 0 : m_bAllowDelete = getBOOL(rValue);
1770 0 : break;
1771 : case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1772 0 : m_aDynamicControlBorder = rValue;
1773 0 : break;
1774 : case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1775 0 : m_aControlBorderColorFocus = rValue;
1776 0 : break;
1777 : case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1778 0 : m_aControlBorderColorMouse = rValue;
1779 0 : break;
1780 : case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1781 0 : m_aControlBorderColorInvalid = rValue;
1782 0 : break;
1783 :
1784 : case PROPERTY_ID_ACTIVE_CONNECTION:
1785 : {
1786 161 : Reference< XConnection > xOuterConnection;
1787 161 : if ( ::dbtools::isEmbeddedInDatabase( getParent(), xOuterConnection ) )
1788 : {
1789 0 : if ( xOuterConnection != Reference< XConnection >( rValue, UNO_QUERY ) )
1790 : // somebody's trying to set a connection which is not equal the connection
1791 : // implied by the database we're embedded in
1792 0 : throw PropertyVetoException();
1793 : }
1794 161 : OPropertySetAggregationHelper::setFastPropertyValue_NoBroadcast( nHandle, rValue );
1795 161 : break;
1796 : }
1797 :
1798 : default:
1799 0 : if ( m_aPropertyBagHelper.hasDynamicPropertyByHandle( nHandle ) )
1800 0 : m_aPropertyBagHelper.setDynamicFastPropertyValue( nHandle, rValue );
1801 : else
1802 0 : OPropertySetAggregationHelper::setFastPropertyValue_NoBroadcast( nHandle, rValue );
1803 0 : break;
1804 : }
1805 396 : }
1806 :
1807 : //------------------------------------------------------------------
1808 161 : void SAL_CALL ODatabaseForm::forwardingPropertyValue( sal_Int32 _nHandle )
1809 : {
1810 : OSL_ENSURE( _nHandle == PROPERTY_ID_ACTIVE_CONNECTION, "ODatabaseForm::forwardingPropertyValue: unexpected property!" );
1811 161 : if ( _nHandle == PROPERTY_ID_ACTIVE_CONNECTION )
1812 : {
1813 161 : if ( m_bSharingConnection )
1814 0 : stopSharingConnection( );
1815 161 : m_bForwardingConnection = sal_True;
1816 : }
1817 161 : }
1818 :
1819 : //------------------------------------------------------------------
1820 161 : void SAL_CALL ODatabaseForm::forwardedPropertyValue( sal_Int32 _nHandle, bool /*_bSuccess*/ )
1821 : {
1822 : OSL_ENSURE( _nHandle == PROPERTY_ID_ACTIVE_CONNECTION, "ODatabaseForm::forwardedPropertyValue: unexpected property!" );
1823 161 : if ( _nHandle == PROPERTY_ID_ACTIVE_CONNECTION )
1824 : {
1825 161 : m_bForwardingConnection = sal_False;
1826 : }
1827 161 : }
1828 :
1829 : //==============================================================================
1830 : // com::sun::star::beans::XPropertyState
1831 : //------------------------------------------------------------------
1832 0 : PropertyState ODatabaseForm::getPropertyStateByHandle(sal_Int32 nHandle)
1833 : {
1834 : PropertyState eState;
1835 0 : switch (nHandle)
1836 : {
1837 : case PROPERTY_ID_NAVIGATION:
1838 0 : return (NavigationBarMode_CURRENT == m_eNavigation) ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE;
1839 :
1840 : case PROPERTY_ID_CYCLE:
1841 0 : eState = m_aCycle.hasValue() ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1842 0 : break;
1843 :
1844 : case PROPERTY_ID_INSERTONLY:
1845 0 : eState = m_bInsertOnly ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1846 0 : break;
1847 :
1848 : case PROPERTY_ID_FILTER:
1849 0 : if ( m_aFilterManager.getFilterComponent( FilterManager::fcPublicFilter ).isEmpty() )
1850 0 : eState = PropertyState_DEFAULT_VALUE;
1851 : else
1852 0 : eState = PropertyState_DIRECT_VALUE;
1853 0 : break;
1854 :
1855 : case PROPERTY_ID_APPLYFILTER:
1856 0 : eState = m_aFilterManager.isApplyPublicFilter() ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE;
1857 0 : break;
1858 :
1859 : case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1860 0 : eState = m_aDynamicControlBorder.hasValue() ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1861 0 : break;
1862 :
1863 : case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1864 0 : eState = m_aControlBorderColorFocus.hasValue() ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1865 0 : break;
1866 :
1867 : case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1868 0 : eState = m_aControlBorderColorMouse.hasValue() ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1869 0 : break;
1870 :
1871 : case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1872 0 : eState = m_aControlBorderColorInvalid.hasValue() ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1873 0 : break;
1874 :
1875 : default:
1876 0 : eState = OPropertySetAggregationHelper::getPropertyStateByHandle(nHandle);
1877 : }
1878 0 : return eState;
1879 : }
1880 :
1881 : //------------------------------------------------------------------
1882 0 : void ODatabaseForm::setPropertyToDefaultByHandle(sal_Int32 nHandle)
1883 : {
1884 0 : switch (nHandle)
1885 : {
1886 : case PROPERTY_ID_INSERTONLY:
1887 : case PROPERTY_ID_FILTER:
1888 : case PROPERTY_ID_APPLYFILTER:
1889 : case PROPERTY_ID_NAVIGATION:
1890 : case PROPERTY_ID_CYCLE:
1891 : case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1892 : case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1893 : case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1894 : case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1895 0 : setFastPropertyValue( nHandle, getPropertyDefaultByHandle( nHandle ) );
1896 0 : break;
1897 :
1898 : default:
1899 0 : OPropertySetAggregationHelper::setPropertyToDefaultByHandle(nHandle);
1900 : }
1901 0 : }
1902 :
1903 : //------------------------------------------------------------------
1904 0 : Any ODatabaseForm::getPropertyDefaultByHandle( sal_Int32 nHandle ) const
1905 : {
1906 0 : Any aReturn;
1907 0 : switch (nHandle)
1908 : {
1909 : case PROPERTY_ID_INSERTONLY:
1910 : case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1911 0 : aReturn <<= sal_False;
1912 0 : break;
1913 :
1914 : case PROPERTY_ID_FILTER:
1915 0 : aReturn <<= OUString();
1916 0 : break;
1917 :
1918 : case PROPERTY_ID_APPLYFILTER:
1919 0 : aReturn <<= sal_True;
1920 0 : break;
1921 :
1922 : case PROPERTY_ID_NAVIGATION:
1923 0 : aReturn = makeAny(NavigationBarMode_CURRENT);
1924 0 : break;
1925 :
1926 : case PROPERTY_ID_CYCLE:
1927 : case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1928 : case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1929 : case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1930 0 : break;
1931 :
1932 : default:
1933 0 : if ( m_aPropertyBagHelper.hasDynamicPropertyByHandle( nHandle ) )
1934 0 : m_aPropertyBagHelper.getDynamicPropertyDefaultByHandle( nHandle, aReturn );
1935 : else
1936 0 : aReturn = OPropertySetAggregationHelper::getPropertyDefaultByHandle( nHandle );
1937 0 : break;
1938 : }
1939 0 : return aReturn;
1940 : }
1941 :
1942 : //==============================================================================
1943 : // com::sun::star::form::XReset
1944 : //------------------------------------------------------------------------------
1945 0 : void SAL_CALL ODatabaseForm::reset() throw( RuntimeException )
1946 : {
1947 0 : ::osl::ResettableMutexGuard aGuard(m_aMutex);
1948 :
1949 0 : if (isLoaded())
1950 : {
1951 0 : ::osl::MutexGuard aResetGuard(m_aResetSafety);
1952 0 : ++m_nResetsPending;
1953 0 : reset_impl(true);
1954 0 : return;
1955 : }
1956 :
1957 0 : if ( !m_aResetListeners.empty() )
1958 : {
1959 0 : ::osl::MutexGuard aResetGuard(m_aResetSafety);
1960 0 : ++m_nResetsPending;
1961 : // create an own thread if we have (approve-)reset-listeners (so the listeners can't do that much damage
1962 : // to this thread which is probably the main one)
1963 0 : if (!m_pThread)
1964 : {
1965 0 : m_pThread = new OFormSubmitResetThread(this);
1966 0 : m_pThread->acquire();
1967 0 : m_pThread->create();
1968 : }
1969 0 : EventObject aEvt;
1970 0 : m_pThread->addEvent(&aEvt, sal_False);
1971 : }
1972 : else
1973 : {
1974 : // direct call without any approving by the listeners
1975 0 : aGuard.clear();
1976 :
1977 0 : ::osl::MutexGuard aResetGuard(m_aResetSafety);
1978 0 : ++m_nResetsPending;
1979 0 : reset_impl(false);
1980 0 : }
1981 : }
1982 :
1983 : //-----------------------------------------------------------------------------
1984 0 : void ODatabaseForm::reset_impl(bool _bAproveByListeners)
1985 : {
1986 0 : if ( _bAproveByListeners )
1987 0 : if ( !m_aResetListeners.approveReset() )
1988 0 : return;
1989 :
1990 0 : ::osl::ResettableMutexGuard aResetGuard(m_aResetSafety);
1991 : // do we have a database connected form and stay on the insert row
1992 0 : sal_Bool bInsertRow = sal_False;
1993 0 : if (m_xAggregateSet.is())
1994 0 : bInsertRow = getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_ISNEW));
1995 0 : if (bInsertRow)
1996 : {
1997 : try
1998 : {
1999 : // Iterate through all columns and set the default value
2000 0 : Reference< XColumnsSupplier > xColsSuppl( m_xAggregateSet, UNO_QUERY );
2001 0 : Reference< XIndexAccess > xIndexCols( xColsSuppl->getColumns(), UNO_QUERY );
2002 0 : for (sal_Int32 i = 0; i < xIndexCols->getCount(); ++i)
2003 : {
2004 0 : Reference< XPropertySet > xColProps;
2005 0 : xIndexCols->getByIndex(i) >>= xColProps;
2006 :
2007 0 : Reference< XColumnUpdate > xColUpdate( xColProps, UNO_QUERY );
2008 0 : if ( !xColUpdate.is() )
2009 0 : continue;
2010 :
2011 0 : Reference< XPropertySetInfo > xPSI;
2012 0 : if ( xColProps.is() )
2013 0 : xPSI = xColProps->getPropertySetInfo( );
2014 :
2015 0 : static const OUString PROPERTY_CONTROLDEFAULT( "ControlDefault" );
2016 0 : if ( xPSI.is() && xPSI->hasPropertyByName( PROPERTY_CONTROLDEFAULT ) )
2017 : {
2018 0 : Any aDefault = xColProps->getPropertyValue( PROPERTY_CONTROLDEFAULT );
2019 :
2020 0 : sal_Bool bReadOnly = sal_False;
2021 0 : if ( xPSI->hasPropertyByName( PROPERTY_ISREADONLY ) )
2022 0 : xColProps->getPropertyValue( PROPERTY_ISREADONLY ) >>= bReadOnly;
2023 :
2024 0 : if ( !bReadOnly )
2025 : {
2026 : try
2027 : {
2028 0 : if ( aDefault.hasValue() )
2029 0 : xColUpdate->updateObject( aDefault );
2030 : }
2031 0 : catch(const Exception&)
2032 : {
2033 : DBG_UNHANDLED_EXCEPTION();
2034 : }
2035 0 : }
2036 : }
2037 0 : }
2038 : }
2039 0 : catch(const Exception&)
2040 : {
2041 : }
2042 :
2043 0 : if (m_bSubForm)
2044 : {
2045 0 : Reference< XColumnsSupplier > xParentColSupp( m_xParent, UNO_QUERY );
2046 0 : Reference< XNameAccess > xParentCols;
2047 0 : if ( xParentColSupp.is() )
2048 0 : xParentCols = xParentColSupp->getColumns();
2049 :
2050 0 : if ( xParentCols.is() && xParentCols->hasElements() && m_aMasterFields.getLength() )
2051 : {
2052 : try
2053 : {
2054 : // analyze our parameters
2055 0 : if ( !m_aParameterManager.isUpToDate() )
2056 0 : updateParameterInfo();
2057 :
2058 0 : m_aParameterManager.resetParameterValues( );
2059 : }
2060 0 : catch(const Exception&)
2061 : {
2062 : OSL_FAIL("ODatabaseForm::reset_impl: could not initialize the master-detail-driven parameters!");
2063 : }
2064 0 : }
2065 : }
2066 : }
2067 :
2068 0 : aResetGuard.clear();
2069 : // iterate through all components. don't use an XIndexAccess as this will cause massive
2070 : // problems with the count.
2071 0 : Reference<XEnumeration> xIter = createEnumeration();
2072 0 : while (xIter->hasMoreElements())
2073 : {
2074 0 : Reference<XReset> xReset;
2075 0 : xIter->nextElement() >>= xReset;
2076 0 : if (xReset.is())
2077 : {
2078 : // TODO : all reset-methods have to be thread-safe
2079 0 : xReset->reset();
2080 : }
2081 0 : }
2082 :
2083 0 : aResetGuard.reset();
2084 : // ensure that the row isn't modified
2085 : // (do this _before_ the listeners are notified ! their reaction (maybe asynchronous) may depend
2086 : // on the modified state of the row)
2087 0 : if (bInsertRow)
2088 0 : m_xAggregateSet->setPropertyValue(PROPERTY_ISMODIFIED, ::cppu::bool2any(sal_Bool(sal_False)));
2089 :
2090 0 : aResetGuard.clear();
2091 : {
2092 0 : m_aResetListeners.resetted();
2093 : }
2094 :
2095 0 : aResetGuard.reset();
2096 : // and again : ensure the row isn't modified
2097 : // we already did this after we (and maybe our dependents) resetted the values, but the listeners may have changed the row, too
2098 0 : if (bInsertRow)
2099 0 : m_xAggregateSet->setPropertyValue(PROPERTY_ISMODIFIED, ::cppu::bool2any((sal_False)));
2100 :
2101 0 : --m_nResetsPending;
2102 : }
2103 :
2104 : //-----------------------------------------------------------------------------
2105 1 : void SAL_CALL ODatabaseForm::addResetListener(const Reference<XResetListener>& _rListener) throw( RuntimeException )
2106 : {
2107 1 : m_aResetListeners.addTypedListener( _rListener );
2108 1 : }
2109 :
2110 : //-----------------------------------------------------------------------------
2111 0 : void SAL_CALL ODatabaseForm::removeResetListener(const Reference<XResetListener>& _rListener) throw( RuntimeException )
2112 : {
2113 0 : m_aResetListeners.removeTypedListener( _rListener );
2114 0 : }
2115 :
2116 : //==============================================================================
2117 : // com::sun::star::form::XSubmit
2118 : //------------------------------------------------------------------------------
2119 0 : void SAL_CALL ODatabaseForm::submit( const Reference<XControl>& Control,
2120 : const ::com::sun::star::awt::MouseEvent& MouseEvt ) throw( RuntimeException )
2121 : {
2122 : {
2123 0 : ::osl::MutexGuard aGuard(m_aMutex);
2124 : // Do we have controls and a Submit URL?
2125 0 : if( !getCount() || m_aTargetURL.isEmpty() )
2126 0 : return;
2127 : }
2128 :
2129 0 : ::osl::ClearableMutexGuard aGuard(m_aMutex);
2130 0 : if (m_aSubmitListeners.getLength())
2131 : {
2132 : // create an own thread if we have (approve-)submit-listeners (so the listeners can't do that much damage
2133 : // to this thread which is probably the main one)
2134 0 : if (!m_pThread)
2135 : {
2136 0 : m_pThread = new OFormSubmitResetThread(this);
2137 0 : m_pThread->acquire();
2138 0 : m_pThread->create();
2139 : }
2140 0 : m_pThread->addEvent(&MouseEvt, Control, sal_True);
2141 : }
2142 : else
2143 : {
2144 : // direct call without any approving by the listeners
2145 0 : aGuard.clear();
2146 0 : submit_impl( Control, MouseEvt, true );
2147 0 : }
2148 : }
2149 : // -----------------------------------------------------------------------------
2150 0 : void lcl_dispatch(const Reference< XFrame >& xFrame,const Reference<XURLTransformer>& xTransformer,const OUString& aURLStr,const OUString& aReferer,const OUString& aTargetName
2151 : ,const OUString& aData,rtl_TextEncoding _eEncoding)
2152 : {
2153 0 : URL aURL;
2154 0 : aURL.Complete = aURLStr;
2155 0 : xTransformer->parseStrict(aURL);
2156 :
2157 0 : Reference< XDispatch > xDisp = Reference< XDispatchProvider > (xFrame,UNO_QUERY)->queryDispatch(aURL, aTargetName,
2158 : FrameSearchFlag::SELF | FrameSearchFlag::PARENT | FrameSearchFlag::CHILDREN |
2159 0 : FrameSearchFlag::SIBLINGS | FrameSearchFlag::CREATE | FrameSearchFlag::TASKS);
2160 :
2161 0 : if (xDisp.is())
2162 : {
2163 0 : Sequence<PropertyValue> aArgs(2);
2164 0 : aArgs.getArray()[0].Name = OUString("Referer");
2165 0 : aArgs.getArray()[0].Value <<= aReferer;
2166 :
2167 : // build a sequence from the to-be-submitted string
2168 0 : OString a8BitData(OUStringToOString(aData, _eEncoding));
2169 : // always ANSI #58641
2170 0 : Sequence< sal_Int8 > aPostData((const sal_Int8*)a8BitData.getStr(), a8BitData.getLength());
2171 0 : Reference< XInputStream > xPostData = new SequenceInputStream(aPostData);
2172 :
2173 0 : aArgs.getArray()[1].Name = OUString("PostData");
2174 0 : aArgs.getArray()[1].Value <<= xPostData;
2175 :
2176 0 : xDisp->dispatch(aURL, aArgs);
2177 0 : } // if (xDisp.is())
2178 0 : }
2179 : //------------------------------------------------------------------------------
2180 0 : void ODatabaseForm::submit_impl(const Reference<XControl>& Control, const ::com::sun::star::awt::MouseEvent& MouseEvt, bool _bAproveByListeners)
2181 : {
2182 :
2183 0 : if (_bAproveByListeners)
2184 : {
2185 0 : ::cppu::OInterfaceIteratorHelper aIter(m_aSubmitListeners);
2186 0 : EventObject aEvt(static_cast<XWeak*>(this));
2187 0 : sal_Bool bCanceled = sal_False;
2188 0 : while (aIter.hasMoreElements() && !bCanceled)
2189 : {
2190 0 : if (!((XSubmitListener*)aIter.next())->approveSubmit(aEvt))
2191 0 : bCanceled = sal_True;
2192 : }
2193 :
2194 0 : if (bCanceled)
2195 0 : return;
2196 : }
2197 :
2198 : FormSubmitEncoding eSubmitEncoding;
2199 : FormSubmitMethod eSubmitMethod;
2200 0 : OUString aURLStr;
2201 0 : OUString aReferer;
2202 0 : OUString aTargetName;
2203 0 : Reference< XModel > xModel;
2204 : {
2205 0 : SolarMutexGuard aGuard;
2206 : // starform->Forms
2207 :
2208 0 : Reference<XChild> xParent(m_xParent, UNO_QUERY);
2209 :
2210 0 : if (xParent.is())
2211 0 : xModel = getXModel(xParent->getParent());
2212 :
2213 0 : if (xModel.is())
2214 0 : aReferer = xModel->getURL();
2215 :
2216 : // TargetItem
2217 0 : aTargetName = m_aTargetFrame;
2218 :
2219 0 : eSubmitEncoding = m_eSubmitEncoding;
2220 0 : eSubmitMethod = m_eSubmitMethod;
2221 0 : aURLStr = m_aTargetURL;
2222 : }
2223 :
2224 0 : if (!xModel.is())
2225 0 : return;
2226 0 : Reference< XFrame > xFrame = xModel->getCurrentController()->getFrame();
2227 0 : if (!xFrame.is())
2228 0 : return;
2229 :
2230 0 : Reference<XURLTransformer> xTransformer(URLTransformer::create(m_xContext));
2231 :
2232 : // URL encoding
2233 0 : if( eSubmitEncoding == FormSubmitEncoding_URL )
2234 : {
2235 0 : OUString aData;
2236 : {
2237 0 : SolarMutexGuard aGuard;
2238 0 : aData = GetDataURLEncoded( Control, MouseEvt );
2239 : }
2240 :
2241 0 : URL aURL;
2242 : // FormMethod GET
2243 0 : if( eSubmitMethod == FormSubmitMethod_GET )
2244 : {
2245 0 : INetURLObject aUrlObj( aURLStr, INetURLObject::WAS_ENCODED );
2246 0 : aUrlObj.SetParam( aData, INetURLObject::ENCODE_ALL );
2247 0 : aURL.Complete = aUrlObj.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
2248 0 : if (xTransformer.is())
2249 0 : xTransformer->parseStrict(aURL);
2250 :
2251 0 : Reference< XDispatch > xDisp = Reference< XDispatchProvider > (xFrame,UNO_QUERY)->queryDispatch(aURL, aTargetName,
2252 : FrameSearchFlag::SELF | FrameSearchFlag::PARENT | FrameSearchFlag::CHILDREN |
2253 0 : FrameSearchFlag::SIBLINGS | FrameSearchFlag::CREATE | FrameSearchFlag::TASKS);
2254 :
2255 0 : if (xDisp.is())
2256 : {
2257 0 : Sequence<PropertyValue> aArgs(1);
2258 0 : aArgs.getArray()->Name = OUString("Referer");
2259 0 : aArgs.getArray()->Value <<= aReferer;
2260 0 : xDisp->dispatch(aURL, aArgs);
2261 0 : }
2262 : }
2263 : // FormMethod POST
2264 0 : else if( eSubmitMethod == FormSubmitMethod_POST )
2265 : {
2266 0 : lcl_dispatch(xFrame,xTransformer,aURLStr,aReferer,aTargetName,aData,RTL_TEXTENCODING_MS_1252);
2267 0 : }
2268 : }
2269 0 : else if( eSubmitEncoding == FormSubmitEncoding_MULTIPART )
2270 : {
2271 0 : URL aURL;
2272 0 : aURL.Complete = aURLStr;
2273 0 : xTransformer->parseStrict(aURL);
2274 :
2275 0 : Reference< XDispatch > xDisp = Reference< XDispatchProvider > (xFrame,UNO_QUERY)->queryDispatch(aURL, aTargetName,
2276 : FrameSearchFlag::SELF | FrameSearchFlag::PARENT | FrameSearchFlag::CHILDREN |
2277 0 : FrameSearchFlag::SIBLINGS | FrameSearchFlag::CREATE | FrameSearchFlag::TASKS);
2278 :
2279 0 : if (xDisp.is())
2280 : {
2281 0 : OUString aContentType;
2282 0 : Sequence<sal_Int8> aData;
2283 : {
2284 0 : SolarMutexGuard aGuard;
2285 0 : aData = GetDataMultiPartEncoded(Control, MouseEvt, aContentType);
2286 : }
2287 0 : if (!aData.getLength())
2288 0 : return;
2289 :
2290 0 : Sequence<PropertyValue> aArgs(3);
2291 0 : aArgs.getArray()[0].Name = OUString("Referer");
2292 0 : aArgs.getArray()[0].Value <<= aReferer;
2293 0 : aArgs.getArray()[1].Name = OUString("ContentType");
2294 0 : aArgs.getArray()[1].Value <<= aContentType;
2295 :
2296 : // build a sequence from the to-be-submitted string
2297 0 : Reference< XInputStream > xPostData = new SequenceInputStream(aData);
2298 :
2299 0 : aArgs.getArray()[2].Name = OUString("PostData");
2300 0 : aArgs.getArray()[2].Value <<= xPostData;
2301 :
2302 0 : xDisp->dispatch(aURL, aArgs);
2303 0 : }
2304 : }
2305 0 : else if( eSubmitEncoding == FormSubmitEncoding_TEXT )
2306 : {
2307 0 : OUString aData;
2308 : {
2309 0 : SolarMutexGuard aGuard;
2310 0 : aData = GetDataTextEncoded( Reference<XControl> (), MouseEvt );
2311 : }
2312 :
2313 0 : lcl_dispatch(xFrame,xTransformer,aURLStr,aReferer,aTargetName,aData,osl_getThreadTextEncoding());
2314 : }
2315 : else {
2316 : OSL_FAIL("ODatabaseForm::submit_Impl : wrong encoding !");
2317 0 : }
2318 :
2319 : }
2320 :
2321 : // XSubmit
2322 : //------------------------------------------------------------------------------
2323 0 : void SAL_CALL ODatabaseForm::addSubmitListener(const Reference<XSubmitListener>& _rListener) throw( RuntimeException )
2324 : {
2325 0 : m_aSubmitListeners.addInterface(_rListener);
2326 0 : }
2327 :
2328 : //------------------------------------------------------------------------------
2329 0 : void SAL_CALL ODatabaseForm::removeSubmitListener(const Reference<XSubmitListener>& _rListener) throw( RuntimeException )
2330 : {
2331 0 : m_aSubmitListeners.removeInterface(_rListener);
2332 0 : }
2333 :
2334 : //==============================================================================
2335 : // com::sun::star::sdbc::XSQLErrorBroadcaster
2336 : //------------------------------------------------------------------------------
2337 72 : void SAL_CALL ODatabaseForm::addSQLErrorListener(const Reference<XSQLErrorListener>& _rListener) throw( RuntimeException )
2338 : {
2339 72 : m_aErrorListeners.addInterface(_rListener);
2340 72 : }
2341 :
2342 : //------------------------------------------------------------------------------
2343 72 : void SAL_CALL ODatabaseForm::removeSQLErrorListener(const Reference<XSQLErrorListener>& _rListener) throw( RuntimeException )
2344 : {
2345 72 : m_aErrorListeners.removeInterface(_rListener);
2346 72 : }
2347 :
2348 : //------------------------------------------------------------------------------
2349 228 : void ODatabaseForm::invlidateParameters()
2350 : {
2351 228 : ::osl::MutexGuard aGuard(m_aMutex);
2352 228 : m_aParameterManager.clearAllParameterInformation();
2353 228 : }
2354 :
2355 : //==============================================================================
2356 : // OChangeListener
2357 : //------------------------------------------------------------------------------
2358 239 : void ODatabaseForm::_propertyChanged(const PropertyChangeEvent& evt) throw( RuntimeException )
2359 : {
2360 239 : if (evt.PropertyName == PROPERTY_ACTIVE_CONNECTION && !m_bForwardingConnection)
2361 : {
2362 : // the rowset changed its active connection itself (without interaction from our side), so
2363 : // we need to fire this event, too
2364 12 : sal_Int32 nHandle = PROPERTY_ID_ACTIVE_CONNECTION;
2365 12 : fire(&nHandle, &evt.NewValue, &evt.OldValue, 1, sal_False);
2366 : }
2367 : else // it was one of the statement relevant props
2368 : {
2369 : // if the statement has changed we have to delete the parameter info
2370 227 : invlidateParameters();
2371 : }
2372 239 : }
2373 :
2374 : //==============================================================================
2375 : // smartXChild
2376 : //------------------------------------------------------------------------------
2377 157 : void SAL_CALL ODatabaseForm::setParent(const InterfaceRef& Parent) throw ( ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException)
2378 : {
2379 : // SYNCHRONIZED ----->
2380 157 : ::osl::ResettableMutexGuard aGuard(m_aMutex);
2381 :
2382 314 : Reference<XForm> xParentForm(getParent(), UNO_QUERY);
2383 157 : if (xParentForm.is())
2384 : {
2385 : try
2386 : {
2387 0 : Reference< XRowSetApproveBroadcaster > xParentApprBroadcast( xParentForm, UNO_QUERY_THROW );
2388 0 : xParentApprBroadcast->removeRowSetApproveListener( this );
2389 :
2390 0 : Reference< XLoadable > xParentLoadable( xParentForm, UNO_QUERY_THROW );
2391 0 : xParentLoadable->removeLoadListener( this );
2392 :
2393 0 : Reference< XPropertySet > xParentProperties( xParentForm, UNO_QUERY_THROW );
2394 0 : xParentProperties->removePropertyChangeListener( PROPERTY_ISNEW, this );
2395 : }
2396 0 : catch(const Exception&)
2397 : {
2398 : DBG_UNHANDLED_EXCEPTION();
2399 : }
2400 : }
2401 :
2402 157 : OFormComponents::setParent(Parent);
2403 :
2404 157 : xParentForm.set(getParent(), UNO_QUERY);
2405 157 : if ( xParentForm.is() )
2406 : {
2407 : try
2408 : {
2409 0 : Reference< XRowSetApproveBroadcaster > xParentApprBroadcast( xParentForm, UNO_QUERY_THROW );
2410 0 : xParentApprBroadcast->addRowSetApproveListener( this );
2411 :
2412 0 : Reference< XLoadable > xParentLoadable( xParentForm, UNO_QUERY_THROW );
2413 0 : xParentLoadable->addLoadListener( this );
2414 :
2415 0 : Reference< XPropertySet > xParentProperties( xParentForm, UNO_QUERY_THROW );
2416 0 : xParentProperties->addPropertyChangeListener( PROPERTY_ISNEW, this );
2417 : }
2418 0 : catch(const Exception&)
2419 : {
2420 : DBG_UNHANDLED_EXCEPTION();
2421 : }
2422 : }
2423 :
2424 314 : Reference< XPropertySet > xAggregateProperties( m_xAggregateSet );
2425 157 : aGuard.clear();
2426 : // <----- SYNCHRONIZED
2427 :
2428 314 : Reference< XConnection > xOuterConnection;
2429 157 : sal_Bool bIsEmbedded = ::dbtools::isEmbeddedInDatabase( Parent, xOuterConnection );
2430 :
2431 157 : if ( bIsEmbedded )
2432 157 : xAggregateProperties->setPropertyValue( PROPERTY_DATASOURCE, makeAny( OUString() ) );
2433 157 : }
2434 :
2435 : //==============================================================================
2436 : // smartXTabControllerModel
2437 : //------------------------------------------------------------------------------
2438 123 : sal_Bool SAL_CALL ODatabaseForm::getGroupControl() throw(com::sun::star::uno::RuntimeException)
2439 : {
2440 123 : ::osl::ResettableMutexGuard aGuard(m_aMutex);
2441 :
2442 : // Should controls be combined into a TabOrder group?
2443 123 : if (m_aCycle.hasValue())
2444 : {
2445 0 : sal_Int32 nCycle = 0;
2446 0 : ::cppu::enum2int(nCycle, m_aCycle);
2447 0 : return nCycle != TabulatorCycle_PAGE;
2448 : }
2449 :
2450 123 : if (isLoaded() && getConnection().is())
2451 0 : return sal_True;
2452 :
2453 123 : return sal_False;
2454 : }
2455 :
2456 : //------------------------------------------------------------------------------
2457 1 : void SAL_CALL ODatabaseForm::setControlModels(const Sequence<Reference<XControlModel> >& rControls) throw( RuntimeException )
2458 : {
2459 1 : ::osl::ResettableMutexGuard aGuard(m_aMutex);
2460 :
2461 : // Set TabIndex in the order of the sequence
2462 1 : const Reference<XControlModel>* pControls = rControls.getConstArray();
2463 1 : sal_Int32 nCount = getCount();
2464 1 : sal_Int32 nNewCount = rControls.getLength();
2465 :
2466 : // HiddenControls and forms are not listed
2467 1 : if (nNewCount <= nCount)
2468 : {
2469 1 : Any aElement;
2470 1 : sal_Int16 nTabIndex = 1;
2471 2 : for (sal_Int32 i=0; i < nNewCount; ++i, ++pControls)
2472 : {
2473 1 : Reference<XFormComponent> xComp(*pControls, UNO_QUERY);
2474 1 : if (xComp.is())
2475 : {
2476 : // Find component in the list
2477 1 : for (sal_Int32 j = 0; j < nCount; ++j)
2478 : {
2479 1 : Reference<XFormComponent> xElement;
2480 1 : ::cppu::extractInterface(xElement, getByIndex(j));
2481 1 : if (xComp == xElement)
2482 : {
2483 1 : Reference<XPropertySet> xSet(xComp, UNO_QUERY);
2484 1 : if (xSet.is() && hasProperty(PROPERTY_TABINDEX, xSet))
2485 1 : xSet->setPropertyValue( PROPERTY_TABINDEX, makeAny(nTabIndex++) );
2486 1 : break;
2487 : }
2488 0 : }
2489 : }
2490 2 : }
2491 1 : }
2492 1 : }
2493 :
2494 : //------------------------------------------------------------------------------
2495 227 : Sequence<Reference<XControlModel> > SAL_CALL ODatabaseForm::getControlModels() throw( RuntimeException )
2496 : {
2497 227 : ::osl::MutexGuard aGuard(m_aMutex);
2498 227 : return m_pGroupManager->getControlModels();
2499 : }
2500 :
2501 : //------------------------------------------------------------------------------
2502 0 : void SAL_CALL ODatabaseForm::setGroup( const Sequence<Reference<XControlModel> >& _rGroup, const OUString& Name ) throw( RuntimeException )
2503 : {
2504 0 : ::osl::MutexGuard aGuard(m_aMutex);
2505 :
2506 : // The controls are grouped by adjusting their names to the name of the
2507 : // first control of the sequence
2508 0 : const Reference<XControlModel>* pControls = _rGroup.getConstArray();
2509 0 : Reference< XPropertySet > xSet;
2510 0 : OUString sGroupName( Name );
2511 :
2512 0 : for( sal_Int32 i=0; i<_rGroup.getLength(); ++i, ++pControls )
2513 : {
2514 0 : xSet = xSet.query( *pControls );
2515 0 : if ( !xSet.is() )
2516 : {
2517 : // can't throw an exception other than a RuntimeException (which would not be appropriate),
2518 : // so we ignore (and only assert) this
2519 : OSL_FAIL( "ODatabaseForm::setGroup: invalid arguments!" );
2520 0 : continue;
2521 : }
2522 :
2523 0 : if (sGroupName.isEmpty())
2524 0 : xSet->getPropertyValue(PROPERTY_NAME) >>= sGroupName;
2525 : else
2526 0 : xSet->setPropertyValue(PROPERTY_NAME, makeAny(sGroupName));
2527 0 : }
2528 0 : }
2529 :
2530 : //------------------------------------------------------------------------------
2531 123 : sal_Int32 SAL_CALL ODatabaseForm::getGroupCount() throw( RuntimeException )
2532 : {
2533 123 : ::osl::MutexGuard aGuard(m_aMutex);
2534 123 : return m_pGroupManager->getGroupCount();
2535 : }
2536 :
2537 : //------------------------------------------------------------------------------
2538 8 : void SAL_CALL ODatabaseForm::getGroup( sal_Int32 nGroup, Sequence<Reference<XControlModel> >& _rGroup, OUString& _rName ) throw( RuntimeException )
2539 : {
2540 8 : ::osl::MutexGuard aGuard(m_aMutex);
2541 8 : _rGroup.realloc(0);
2542 8 : _rName = OUString();
2543 :
2544 8 : if ((nGroup < 0) || (nGroup >= m_pGroupManager->getGroupCount()))
2545 8 : return;
2546 8 : m_pGroupManager->getGroup( nGroup, _rGroup, _rName );
2547 : }
2548 :
2549 : //------------------------------------------------------------------------------
2550 0 : void SAL_CALL ODatabaseForm::getGroupByName(const OUString& Name, Sequence< Reference<XControlModel> >& _rGroup) throw( RuntimeException )
2551 : {
2552 0 : ::osl::MutexGuard aGuard(m_aMutex);
2553 0 : _rGroup.realloc(0);
2554 0 : m_pGroupManager->getGroupByName( Name, _rGroup );
2555 0 : }
2556 :
2557 : //==============================================================================
2558 : // com::sun::star::lang::XEventListener
2559 : //------------------------------------------------------------------------------
2560 36 : void SAL_CALL ODatabaseForm::disposing(const EventObject& Source) throw( RuntimeException )
2561 : {
2562 : // does the call come from the connection which we are sharing with our parent?
2563 36 : if ( isSharingConnection() )
2564 : {
2565 0 : Reference< XConnection > xConnSource( Source.Source, UNO_QUERY );
2566 0 : if ( xConnSource.is() )
2567 : {
2568 : #if OSL_DEBUG_LEVEL > 0
2569 : Reference< XConnection > xActiveConn;
2570 : m_xAggregateSet->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xActiveConn;
2571 : OSL_ENSURE( xActiveConn.get() == xConnSource.get(), "ODatabaseForm::disposing: where did this come from?" );
2572 : // there should be exactly one XConnection object we're listening at - our aggregate connection
2573 : #endif
2574 0 : disposingSharedConnection( xConnSource );
2575 0 : }
2576 : }
2577 :
2578 36 : OInterfaceContainer::disposing(Source);
2579 :
2580 : // does the disposing come from the aggregate ?
2581 36 : if (m_xAggregate.is())
2582 : { // no -> forward it
2583 36 : com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xListener;
2584 36 : if (query_aggregation(m_xAggregate, xListener))
2585 36 : xListener->disposing(Source);
2586 : }
2587 36 : }
2588 :
2589 : //------------------------------------------------------------------------------
2590 0 : void ODatabaseForm::impl_createLoadTimer()
2591 : {
2592 : OSL_PRECOND( m_pLoadTimer == NULL, "ODatabaseForm::impl_createLoadTimer: timer already exists!" );
2593 0 : m_pLoadTimer = new Timer();
2594 0 : m_pLoadTimer->SetTimeout(100);
2595 0 : m_pLoadTimer->SetTimeoutHdl(LINK(this,ODatabaseForm,OnTimeout));
2596 0 : }
2597 :
2598 : //==============================================================================
2599 : // com::sun::star::form::XLoadListener
2600 : //------------------------------------------------------------------------------
2601 0 : void SAL_CALL ODatabaseForm::loaded(const EventObject& /*aEvent*/) throw( RuntimeException )
2602 : {
2603 : {
2604 0 : ::osl::MutexGuard aGuard( m_aMutex );
2605 0 : Reference< XRowSet > xParentRowSet( m_xParent, UNO_QUERY_THROW );
2606 0 : xParentRowSet->addRowSetListener( this );
2607 :
2608 0 : impl_createLoadTimer();
2609 : }
2610 :
2611 0 : load_impl( sal_True );
2612 0 : }
2613 :
2614 : //------------------------------------------------------------------------------
2615 0 : void SAL_CALL ODatabaseForm::unloading(const EventObject& /*aEvent*/) throw( RuntimeException )
2616 : {
2617 : {
2618 : // now stop the rowset listening if we are a subform
2619 0 : ::osl::MutexGuard aGuard( m_aMutex );
2620 :
2621 0 : if ( m_pLoadTimer && m_pLoadTimer->IsActive() )
2622 0 : m_pLoadTimer->Stop();
2623 0 : DELETEZ( m_pLoadTimer );
2624 :
2625 0 : Reference< XRowSet > xParentRowSet( m_xParent, UNO_QUERY_THROW );
2626 0 : xParentRowSet->removeRowSetListener( this );
2627 : }
2628 :
2629 0 : unload();
2630 0 : }
2631 :
2632 : //------------------------------------------------------------------------------
2633 0 : void SAL_CALL ODatabaseForm::unloaded(const EventObject& /*aEvent*/) throw( RuntimeException )
2634 : {
2635 : // nothing to do
2636 0 : }
2637 :
2638 : //------------------------------------------------------------------------------
2639 0 : void SAL_CALL ODatabaseForm::reloading(const EventObject& /*aEvent*/) throw( RuntimeException )
2640 : {
2641 : // now stop the rowset listening if we are a subform
2642 0 : ::osl::MutexGuard aGuard(m_aMutex);
2643 0 : Reference<XRowSet> xParentRowSet(m_xParent, UNO_QUERY);
2644 0 : if (xParentRowSet.is())
2645 0 : xParentRowSet->removeRowSetListener(this);
2646 :
2647 0 : if (m_pLoadTimer && m_pLoadTimer->IsActive())
2648 0 : m_pLoadTimer->Stop();
2649 0 : }
2650 :
2651 : //------------------------------------------------------------------------------
2652 0 : void SAL_CALL ODatabaseForm::reloaded(const EventObject& /*aEvent*/) throw( RuntimeException )
2653 : {
2654 0 : reload_impl(sal_True);
2655 : {
2656 0 : ::osl::MutexGuard aGuard(m_aMutex);
2657 0 : Reference<XRowSet> xParentRowSet(m_xParent, UNO_QUERY);
2658 0 : if (xParentRowSet.is())
2659 0 : xParentRowSet->addRowSetListener(this);
2660 : }
2661 0 : }
2662 :
2663 : //------------------------------------------------------------------------------
2664 0 : IMPL_LINK_NOARG(ODatabaseForm, OnTimeout)
2665 : {
2666 0 : reload_impl(sal_True);
2667 0 : return 1;
2668 : }
2669 :
2670 : //==============================================================================
2671 : // com::sun::star::form::XLoadable
2672 : //------------------------------------------------------------------------------
2673 13 : void SAL_CALL ODatabaseForm::load() throw( RuntimeException )
2674 : {
2675 13 : load_impl(sal_False);
2676 13 : }
2677 :
2678 : //------------------------------------------------------------------------------
2679 0 : sal_Bool ODatabaseForm::canShareConnection( const Reference< XPropertySet >& _rxParentProps )
2680 : {
2681 : // our own data source
2682 0 : OUString sOwnDatasource;
2683 0 : m_xAggregateSet->getPropertyValue( PROPERTY_DATASOURCE ) >>= sOwnDatasource;
2684 :
2685 : // our parents data source
2686 0 : OUString sParentDataSource;
2687 : OSL_ENSURE( _rxParentProps.is() && _rxParentProps->getPropertySetInfo().is() && _rxParentProps->getPropertySetInfo()->hasPropertyByName( PROPERTY_DATASOURCE ),
2688 : "ODatabaseForm::doShareConnection: invalid parent form!" );
2689 0 : if ( _rxParentProps.is() )
2690 0 : _rxParentProps->getPropertyValue( PROPERTY_DATASOURCE ) >>= sParentDataSource;
2691 :
2692 0 : sal_Bool bCanShareConnection = sal_False;
2693 :
2694 : // both rowsets share are connected to the same data source
2695 0 : if ( sParentDataSource == sOwnDatasource )
2696 : {
2697 0 : if ( !sParentDataSource.isEmpty() )
2698 : // and it's really a data source name (not empty)
2699 0 : bCanShareConnection = sal_True;
2700 : else
2701 : { // the data source name is empty
2702 : // -> ook for the URL
2703 0 : OUString sParentURL;
2704 0 : OUString sMyURL;
2705 0 : _rxParentProps->getPropertyValue( PROPERTY_URL ) >>= sParentURL;
2706 0 : m_xAggregateSet->getPropertyValue( PROPERTY_URL ) >>= sMyURL;
2707 :
2708 0 : bCanShareConnection = (sParentURL == sMyURL);
2709 : }
2710 : }
2711 :
2712 0 : if ( bCanShareConnection )
2713 : {
2714 : // check for the user/password
2715 :
2716 : // take the user property on the rowset (if any) into account
2717 0 : OUString sParentUser, sParentPwd;
2718 0 : _rxParentProps->getPropertyValue( PROPERTY_USER ) >>= sParentUser;
2719 0 : _rxParentProps->getPropertyValue( PROPERTY_PASSWORD ) >>= sParentPwd;
2720 :
2721 0 : OUString sMyUser, sMyPwd;
2722 0 : m_xAggregateSet->getPropertyValue( PROPERTY_USER ) >>= sMyUser;
2723 0 : m_xAggregateSet->getPropertyValue( PROPERTY_PASSWORD ) >>= sMyPwd;
2724 :
2725 : bCanShareConnection =
2726 0 : ( sParentUser == sMyUser )
2727 0 : && ( sParentPwd == sMyPwd );
2728 : }
2729 :
2730 0 : return bCanShareConnection;
2731 : }
2732 :
2733 : //------------------------------------------------------------------------------
2734 0 : void ODatabaseForm::doShareConnection( const Reference< XPropertySet >& _rxParentProps )
2735 : {
2736 : // get the conneciton of the parent
2737 0 : Reference< XConnection > xParentConn;
2738 0 : _rxParentProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xParentConn;
2739 : OSL_ENSURE( xParentConn.is(), "ODatabaseForm::doShareConnection: we're a valid sub-form, but the parent has no connection?!" );
2740 :
2741 0 : if ( xParentConn.is() )
2742 : {
2743 : // add as dispose listener to the connection
2744 0 : Reference< XComponent > xParentConnComp( xParentConn, UNO_QUERY );
2745 : OSL_ENSURE( xParentConnComp.is(), "ODatabaseForm::doShareConnection: invalid connection!" );
2746 0 : xParentConnComp->addEventListener( static_cast< XLoadListener* >( this ) );
2747 :
2748 : // forward the connection to our own aggreagte
2749 0 : m_bForwardingConnection = sal_True;
2750 0 : m_xAggregateSet->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( xParentConn ) );
2751 0 : m_bForwardingConnection = sal_False;
2752 :
2753 0 : m_bSharingConnection = sal_True;
2754 : }
2755 : else
2756 0 : m_bSharingConnection = sal_False;
2757 0 : }
2758 :
2759 : //------------------------------------------------------------------------------
2760 0 : void ODatabaseForm::disposingSharedConnection( const Reference< XConnection >& /*_rxConn*/ )
2761 : {
2762 0 : stopSharingConnection();
2763 :
2764 : // TODO: we could think about whether or not to re-connect.
2765 0 : unload( );
2766 0 : }
2767 :
2768 : //------------------------------------------------------------------------------
2769 0 : void ODatabaseForm::stopSharingConnection( )
2770 : {
2771 : OSL_ENSURE( m_bSharingConnection, "ODatabaseForm::stopSharingConnection: invalid call!" );
2772 :
2773 0 : if ( m_bSharingConnection )
2774 : {
2775 : // get the connection
2776 0 : Reference< XConnection > xSharedConn;
2777 0 : m_xAggregateSet->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xSharedConn;
2778 : OSL_ENSURE( xSharedConn.is(), "ODatabaseForm::stopSharingConnection: there's no conn!" );
2779 :
2780 : // remove ourself as event listener
2781 0 : Reference< XComponent > xSharedConnComp( xSharedConn, UNO_QUERY );
2782 0 : if ( xSharedConnComp.is() )
2783 0 : xSharedConnComp->removeEventListener( static_cast< XLoadListener* >( this ) );
2784 :
2785 : // no need to dispose the conn: we're not the owner, this is our parent
2786 : // (in addition, this method may be called if the connection is beeing disposed while we use it)
2787 :
2788 : // reset the property
2789 0 : xSharedConn.clear();
2790 0 : m_bForwardingConnection = sal_True;
2791 0 : m_xAggregateSet->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( xSharedConn ) );
2792 0 : m_bForwardingConnection = sal_False;
2793 :
2794 : // reset the flag
2795 0 : m_bSharingConnection = sal_False;
2796 : }
2797 0 : }
2798 :
2799 : //------------------------------------------------------------------------------
2800 25 : sal_Bool ODatabaseForm::implEnsureConnection()
2801 : {
2802 : try
2803 : {
2804 25 : if ( getConnection( ).is() )
2805 : // if our aggregate already has a connection, nothing needs to be done about it
2806 38 : return sal_True;
2807 :
2808 : // see whether we're an embedded form
2809 12 : Reference< XConnection > xOuterConnection;
2810 12 : if ( ::dbtools::isEmbeddedInDatabase( getParent(), xOuterConnection ) )
2811 : {
2812 0 : m_xAggregateSet->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( xOuterConnection ) );
2813 0 : return xOuterConnection.is();
2814 : }
2815 :
2816 12 : m_bSharingConnection = sal_False;
2817 :
2818 : // if we're a sub form, we try to re-use the connection of our parent
2819 12 : if (m_bSubForm)
2820 : {
2821 : OSL_ENSURE( Reference< XForm >( getParent(), UNO_QUERY ).is(),
2822 : "ODatabaseForm::implEnsureConnection: m_bSubForm is TRUE, but the parent is no form?" );
2823 :
2824 0 : Reference< XPropertySet > xParentProps( getParent(), UNO_QUERY );
2825 :
2826 : // can we re-use (aka share) the connection of the parent?
2827 0 : if ( canShareConnection( xParentProps ) )
2828 : {
2829 : // yep -> do it
2830 0 : doShareConnection( xParentProps );
2831 : // success?
2832 0 : if ( m_bSharingConnection )
2833 : // yes -> outta here
2834 0 : return sal_True;
2835 0 : }
2836 : }
2837 :
2838 12 : if (m_xAggregateSet.is())
2839 : {
2840 : Reference< XConnection > xConnection = connectRowset(
2841 : Reference<XRowSet> (m_xAggregate, UNO_QUERY),
2842 : m_xContext,
2843 : sal_True // set a calculated connection as ActiveConnection
2844 12 : );
2845 12 : return xConnection.is();
2846 0 : }
2847 : }
2848 0 : catch(const SQLException& eDB)
2849 : {
2850 0 : onError(eDB, FRM_RES_STRING(RID_STR_CONNECTERROR));
2851 : }
2852 0 : catch(const Exception&)
2853 : {
2854 : DBG_UNHANDLED_EXCEPTION();
2855 : }
2856 :
2857 0 : return sal_False;
2858 : }
2859 :
2860 : //------------------------------------------------------------------------------
2861 13 : void ODatabaseForm::load_impl(sal_Bool bCausedByParentForm, sal_Bool bMoveToFirst, const Reference< XInteractionHandler >& _rxCompletionHandler ) throw( RuntimeException )
2862 : {
2863 13 : ::osl::ResettableMutexGuard aGuard(m_aMutex);
2864 :
2865 : // are we already loaded?
2866 13 : if (isLoaded())
2867 13 : return;
2868 :
2869 13 : m_bSubForm = bCausedByParentForm;
2870 :
2871 : // if we don't have a connection, we are not intended to be a database form or the aggregate was not able
2872 : // to establish a connection
2873 13 : sal_Bool bConnected = implEnsureConnection();
2874 :
2875 : // we don't have to execute if we do not have a command to execute
2876 13 : sal_Bool bExecute = bConnected && m_xAggregateSet.is() && !getString(m_xAggregateSet->getPropertyValue(PROPERTY_COMMAND)).isEmpty();
2877 :
2878 : // a database form always uses caching
2879 : // we use starting fetchsize with at least 10 rows
2880 13 : if (bConnected)
2881 12 : m_xAggregateSet->setPropertyValue(PROPERTY_FETCHSIZE, makeAny((sal_Int32)40));
2882 :
2883 : // if we're loaded as sub form we got a "rowSetChanged" from the parent rowset _before_ we got the "loaded"
2884 : // so we don't need to execute the statement again, this was already done
2885 : // (and there were no relevant changes between these two listener calls, the "load" of a form is quite an
2886 : // atomic operation.)
2887 :
2888 13 : sal_Bool bSuccess = sal_False;
2889 13 : if (bExecute)
2890 : {
2891 12 : m_sCurrentErrorContext = FRM_RES_STRING(RID_ERR_LOADING_FORM);
2892 12 : bSuccess = executeRowSet(aGuard, bMoveToFirst, _rxCompletionHandler);
2893 : }
2894 :
2895 13 : if (bSuccess)
2896 : {
2897 1 : m_bLoaded = sal_True;
2898 1 : aGuard.clear();
2899 1 : EventObject aEvt(static_cast<XWeak*>(this));
2900 1 : m_aLoadListeners.notifyEach( &XLoadListener::loaded, aEvt );
2901 :
2902 : // if we are on the insert row, we have to reset all controls
2903 : // to set the default values
2904 1 : if (bExecute && getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_ISNEW)))
2905 0 : reset();
2906 13 : }
2907 : }
2908 :
2909 : //------------------------------------------------------------------------------
2910 12 : void SAL_CALL ODatabaseForm::unload() throw( RuntimeException )
2911 : {
2912 12 : ::osl::ResettableMutexGuard aGuard(m_aMutex);
2913 12 : if (!isLoaded())
2914 23 : return;
2915 :
2916 1 : DELETEZ(m_pLoadTimer);
2917 :
2918 1 : aGuard.clear();
2919 2 : EventObject aEvt(static_cast<XWeak*>(this));
2920 1 : m_aLoadListeners.notifyEach( &XLoadListener::unloading, aEvt );
2921 :
2922 1 : if (m_xAggregateAsRowSet.is())
2923 : {
2924 : // we may have reset the InsertOnly property on the aggregate - restore it
2925 1 : restoreInsertOnlyState( );
2926 :
2927 : // clear the parameters if there are any
2928 1 : invlidateParameters();
2929 :
2930 : try
2931 : {
2932 : // close the aggregate
2933 1 : Reference<XCloseable> xCloseable;
2934 1 : query_aggregation( m_xAggregate, xCloseable);
2935 1 : aGuard.clear();
2936 1 : if (xCloseable.is())
2937 1 : xCloseable->close();
2938 : }
2939 0 : catch(const SQLException&)
2940 : {
2941 : }
2942 1 : aGuard.reset();
2943 : }
2944 :
2945 1 : m_bLoaded = sal_False;
2946 :
2947 : // if the connection we used while we were loaded is only shared with our parent, we
2948 : // reset it
2949 1 : if ( isSharingConnection() )
2950 0 : stopSharingConnection();
2951 :
2952 1 : aGuard.clear();
2953 2 : m_aLoadListeners.notifyEach( &XLoadListener::unloaded, aEvt );
2954 : }
2955 :
2956 : //------------------------------------------------------------------------------
2957 0 : void SAL_CALL ODatabaseForm::reload() throw( RuntimeException )
2958 : {
2959 0 : reload_impl(sal_True);
2960 0 : }
2961 :
2962 : //------------------------------------------------------------------------------
2963 0 : void ODatabaseForm::reload_impl(sal_Bool bMoveToFirst, const Reference< XInteractionHandler >& _rxCompletionHandler ) throw( RuntimeException )
2964 : {
2965 0 : ::osl::ResettableMutexGuard aGuard(m_aMutex);
2966 0 : if (!isLoaded())
2967 0 : return;
2968 :
2969 0 : DocumentModifyGuard aModifyGuard( *this );
2970 : // ensures the document is not marked as "modified" just because we change some control's content during
2971 : // reloading ...
2972 :
2973 0 : EventObject aEvent(static_cast<XWeak*>(this));
2974 : {
2975 : // only if there is no approve listener we can post the event at this time
2976 : // otherwise see approveRowsetChange
2977 : // the aprrovement is done by the aggregate
2978 0 : if (!m_aRowSetApproveListeners.getLength())
2979 : {
2980 0 : ::cppu::OInterfaceIteratorHelper aIter(m_aLoadListeners);
2981 0 : aGuard.clear();
2982 :
2983 0 : while (aIter.hasMoreElements())
2984 0 : ((XLoadListener*)aIter.next())->reloading(aEvent);
2985 :
2986 0 : aGuard.reset();
2987 : }
2988 : }
2989 :
2990 0 : sal_Bool bSuccess = sal_True;
2991 : try
2992 : {
2993 0 : m_sCurrentErrorContext = FRM_RES_STRING(RID_ERR_REFRESHING_FORM);
2994 0 : bSuccess = executeRowSet(aGuard, bMoveToFirst, _rxCompletionHandler);
2995 : }
2996 0 : catch(const SQLException&)
2997 : {
2998 : OSL_FAIL("ODatabaseForm::reload_impl : shouldn't executeRowSet catch this exception?");
2999 : }
3000 :
3001 0 : if (bSuccess)
3002 : {
3003 0 : ::cppu::OInterfaceIteratorHelper aIter(m_aLoadListeners);
3004 0 : aGuard.clear();
3005 0 : while (aIter.hasMoreElements())
3006 0 : ((XLoadListener*)aIter.next())->reloaded(aEvent);
3007 :
3008 : // if we are on the insert row, we have to reset all controls
3009 : // to set the default values
3010 0 : if (getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_ISNEW)))
3011 0 : reset();
3012 : }
3013 : else
3014 0 : m_bLoaded = sal_False;
3015 : }
3016 :
3017 : //------------------------------------------------------------------------------
3018 630 : sal_Bool SAL_CALL ODatabaseForm::isLoaded() throw( RuntimeException )
3019 : {
3020 630 : return m_bLoaded;
3021 : }
3022 :
3023 : //------------------------------------------------------------------------------
3024 277 : void SAL_CALL ODatabaseForm::addLoadListener(const Reference<XLoadListener>& aListener) throw( RuntimeException )
3025 : {
3026 277 : m_aLoadListeners.addInterface(aListener);
3027 277 : }
3028 :
3029 : //------------------------------------------------------------------------------
3030 219 : void SAL_CALL ODatabaseForm::removeLoadListener(const Reference<XLoadListener>& aListener) throw( RuntimeException )
3031 : {
3032 219 : m_aLoadListeners.removeInterface(aListener);
3033 219 : }
3034 :
3035 : //==============================================================================
3036 : // com::sun::star::sdbc::XCloseable
3037 : //==============================================================================
3038 0 : void SAL_CALL ODatabaseForm::close() throw( SQLException, RuntimeException )
3039 : {
3040 : // unload will close the aggregate
3041 0 : unload();
3042 0 : }
3043 :
3044 : //==============================================================================
3045 : // com::sun::star::sdbc::XRowSetListener
3046 : //------------------------------------------------------------------------------
3047 0 : void SAL_CALL ODatabaseForm::cursorMoved(const EventObject& /*event*/) throw( RuntimeException )
3048 : {
3049 : // reload the subform with the new parameters of the parent
3050 : // do this handling delayed to provide of execute too many SQL Statements
3051 0 : ::osl::ResettableMutexGuard aGuard(m_aMutex);
3052 :
3053 : DBG_ASSERT( m_pLoadTimer, "ODatabaseForm::cursorMoved: how can this happen?!" );
3054 0 : if ( !m_pLoadTimer )
3055 0 : impl_createLoadTimer();
3056 :
3057 0 : if ( m_pLoadTimer->IsActive() )
3058 0 : m_pLoadTimer->Stop();
3059 :
3060 : // and start the timer again
3061 0 : m_pLoadTimer->Start();
3062 0 : }
3063 :
3064 : //------------------------------------------------------------------------------
3065 0 : void SAL_CALL ODatabaseForm::rowChanged(const EventObject& /*event*/) throw( RuntimeException )
3066 : {
3067 : // ignore it
3068 0 : }
3069 :
3070 : //------------------------------------------------------------------------------
3071 0 : void SAL_CALL ODatabaseForm::rowSetChanged(const EventObject& /*event*/) throw( RuntimeException )
3072 : {
3073 : // not interested in :
3074 : // if our parent is an ODatabaseForm, too, then after this rowSetChanged we'll get a "reloaded"
3075 : // or a "loaded" event.
3076 : // If somebody gave us another parent which is an XRowSet but doesn't handle an execute as
3077 : // "load" respectivly "reload" ... can't do anything ....
3078 0 : }
3079 :
3080 : //------------------------------------------------------------------------------
3081 0 : bool ODatabaseForm::impl_approveRowChange_throw( const EventObject& _rEvent, const bool _bAllowSQLException,
3082 : ::osl::ClearableMutexGuard& _rGuard )
3083 : {
3084 0 : ::cppu::OInterfaceIteratorHelper aIter( m_aRowSetApproveListeners );
3085 0 : _rGuard.clear();
3086 0 : while ( aIter.hasMoreElements() )
3087 : {
3088 0 : Reference< XRowSetApproveListener > xListener( static_cast< XRowSetApproveListener* >( aIter.next() ) );
3089 0 : if ( !xListener.is() )
3090 0 : continue;
3091 :
3092 : try
3093 : {
3094 0 : if ( !xListener->approveRowSetChange( _rEvent ) )
3095 0 : return false;
3096 : }
3097 0 : catch (const DisposedException& e)
3098 : {
3099 0 : if ( e.Context == xListener )
3100 0 : aIter.remove();
3101 : }
3102 0 : catch (const RuntimeException&)
3103 : {
3104 0 : throw;
3105 : }
3106 0 : catch (const SQLException&)
3107 : {
3108 0 : if ( _bAllowSQLException )
3109 0 : throw;
3110 : DBG_UNHANDLED_EXCEPTION();
3111 : }
3112 0 : catch (const Exception&)
3113 : {
3114 : DBG_UNHANDLED_EXCEPTION();
3115 : }
3116 0 : }
3117 0 : return true;
3118 : }
3119 :
3120 : //------------------------------------------------------------------------------
3121 0 : sal_Bool SAL_CALL ODatabaseForm::approveCursorMove(const EventObject& event) throw( RuntimeException )
3122 : {
3123 : // is our aggregate calling?
3124 0 : if (event.Source == InterfaceRef(static_cast<XWeak*>(this)))
3125 : {
3126 : // Our aggregate doesn't have any ApproveRowSetListeners (expect ourself), as we re-routed the queryInterface
3127 : // for XRowSetApproveBroadcaster-interface.
3128 : // So we have to multiplex this approve request.
3129 0 : ::cppu::OInterfaceIteratorHelper aIter( m_aRowSetApproveListeners );
3130 0 : while ( aIter.hasMoreElements() )
3131 : {
3132 0 : Reference< XRowSetApproveListener > xListener( static_cast< XRowSetApproveListener* >( aIter.next() ) );
3133 0 : if ( !xListener.is() )
3134 0 : continue;
3135 :
3136 : try
3137 : {
3138 0 : if ( !xListener->approveCursorMove( event ) )
3139 0 : return sal_False;
3140 : }
3141 0 : catch (const DisposedException& e)
3142 : {
3143 0 : if ( e.Context == xListener )
3144 0 : aIter.remove();
3145 : }
3146 0 : catch (const RuntimeException&)
3147 : {
3148 0 : throw;
3149 : }
3150 0 : catch (const Exception&)
3151 : {
3152 : DBG_UNHANDLED_EXCEPTION();
3153 : }
3154 0 : }
3155 0 : return true;
3156 : }
3157 : else
3158 : {
3159 : // this is a call from our parent ...
3160 : // a parent's cursor move will result in a re-execute of our own row-set, so we have to
3161 : // ask our own RowSetChangesListeners, too
3162 0 : ::osl::ClearableMutexGuard aGuard( m_aMutex );
3163 0 : if ( !impl_approveRowChange_throw( event, false, aGuard ) )
3164 0 : return sal_False;
3165 : }
3166 0 : return sal_True;
3167 : }
3168 :
3169 : //------------------------------------------------------------------------------
3170 0 : sal_Bool SAL_CALL ODatabaseForm::approveRowChange(const RowChangeEvent& event) throw( RuntimeException )
3171 : {
3172 : // is our aggregate calling?
3173 0 : if (event.Source == InterfaceRef(static_cast<XWeak*>(this)))
3174 : {
3175 : // Our aggregate doesn't have any ApproveRowSetListeners (expect ourself), as we re-routed the queryInterface
3176 : // for XRowSetApproveBroadcaster-interface.
3177 : // So we have to multiplex this approve request.
3178 0 : ::cppu::OInterfaceIteratorHelper aIter( m_aRowSetApproveListeners );
3179 0 : while ( aIter.hasMoreElements() )
3180 : {
3181 0 : Reference< XRowSetApproveListener > xListener( static_cast< XRowSetApproveListener* >( aIter.next() ) );
3182 0 : if ( !xListener.is() )
3183 0 : continue;
3184 :
3185 : try
3186 : {
3187 0 : if ( !xListener->approveRowChange( event ) )
3188 0 : return false;
3189 : }
3190 0 : catch (const DisposedException& e)
3191 : {
3192 0 : if ( e.Context == xListener )
3193 0 : aIter.remove();
3194 : }
3195 0 : catch (const RuntimeException&)
3196 : {
3197 0 : throw;
3198 : }
3199 0 : catch (const Exception&)
3200 : {
3201 : DBG_UNHANDLED_EXCEPTION();
3202 : }
3203 0 : }
3204 0 : return true;
3205 : }
3206 0 : return sal_True;
3207 : }
3208 :
3209 : //------------------------------------------------------------------------------
3210 0 : sal_Bool SAL_CALL ODatabaseForm::approveRowSetChange(const EventObject& event) throw( RuntimeException )
3211 : {
3212 0 : if (event.Source == InterfaceRef(static_cast<XWeak*>(this))) // ignore our aggregate as we handle this approve ourself
3213 : {
3214 0 : ::osl::ClearableMutexGuard aGuard( m_aMutex );
3215 0 : bool bWasLoaded = isLoaded();
3216 0 : if ( !impl_approveRowChange_throw( event, false, aGuard ) )
3217 0 : return sal_False;
3218 :
3219 0 : if ( bWasLoaded )
3220 : {
3221 0 : m_aLoadListeners.notifyEach( &XLoadListener::reloading, event );
3222 0 : }
3223 : }
3224 : else
3225 : {
3226 : // this is a call from our parent ...
3227 : // a parent's cursor move will result in a re-execute of our own row-set, so we have to
3228 : // ask our own RowSetChangesListeners, too
3229 0 : ::osl::ClearableMutexGuard aGuard( m_aMutex );
3230 0 : if ( !impl_approveRowChange_throw( event, false, aGuard ) )
3231 0 : return sal_False;
3232 : }
3233 0 : return sal_True;
3234 : }
3235 :
3236 : //==============================================================================
3237 : // com::sun::star::sdb::XRowSetApproveBroadcaster
3238 : //------------------------------------------------------------------------------
3239 0 : void SAL_CALL ODatabaseForm::addRowSetApproveListener(const Reference<XRowSetApproveListener>& _rListener) throw( RuntimeException )
3240 : {
3241 0 : ::osl::ResettableMutexGuard aGuard(m_aMutex);
3242 0 : m_aRowSetApproveListeners.addInterface(_rListener);
3243 :
3244 : // do we have to multiplex ?
3245 0 : if (m_aRowSetApproveListeners.getLength() == 1)
3246 : {
3247 0 : Reference<XRowSetApproveBroadcaster> xBroadcaster;
3248 0 : if (query_aggregation( m_xAggregate, xBroadcaster))
3249 : {
3250 0 : Reference<XRowSetApproveListener> xListener((XRowSetApproveListener*)this);
3251 0 : xBroadcaster->addRowSetApproveListener(xListener);
3252 0 : }
3253 0 : }
3254 0 : }
3255 :
3256 : //------------------------------------------------------------------------------
3257 0 : void SAL_CALL ODatabaseForm::removeRowSetApproveListener(const Reference<XRowSetApproveListener>& _rListener) throw( RuntimeException )
3258 : {
3259 0 : ::osl::ResettableMutexGuard aGuard(m_aMutex);
3260 : // do we have to remove the multiplex ?
3261 0 : m_aRowSetApproveListeners.removeInterface(_rListener);
3262 0 : if ( m_aRowSetApproveListeners.getLength() == 0 )
3263 : {
3264 0 : Reference<XRowSetApproveBroadcaster> xBroadcaster;
3265 0 : if (query_aggregation( m_xAggregate, xBroadcaster))
3266 : {
3267 0 : Reference<XRowSetApproveListener> xListener((XRowSetApproveListener*)this);
3268 0 : xBroadcaster->removeRowSetApproveListener(xListener);
3269 0 : }
3270 0 : }
3271 0 : }
3272 :
3273 : //==============================================================================
3274 : // com::sun:star::form::XDatabaseParameterBroadcaster
3275 : //------------------------------------------------------------------------------
3276 72 : void SAL_CALL ODatabaseForm::addDatabaseParameterListener(const Reference<XDatabaseParameterListener>& _rListener) throw( RuntimeException )
3277 : {
3278 72 : m_aParameterManager.addParameterListener( _rListener );
3279 72 : }
3280 : //------------------------------------------------------------------------------
3281 72 : void SAL_CALL ODatabaseForm::removeDatabaseParameterListener(const Reference<XDatabaseParameterListener>& _rListener) throw( RuntimeException )
3282 : {
3283 72 : m_aParameterManager.removeParameterListener( _rListener );
3284 72 : }
3285 :
3286 : //------------------------------------------------------------------------------
3287 72 : void SAL_CALL ODatabaseForm::addParameterListener(const Reference<XDatabaseParameterListener>& _rListener) throw( RuntimeException )
3288 : {
3289 72 : ODatabaseForm::addDatabaseParameterListener( _rListener );
3290 72 : }
3291 :
3292 : //------------------------------------------------------------------------------
3293 72 : void SAL_CALL ODatabaseForm::removeParameterListener(const Reference<XDatabaseParameterListener>& _rListener) throw( RuntimeException )
3294 : {
3295 72 : ODatabaseForm::removeDatabaseParameterListener( _rListener );
3296 72 : }
3297 :
3298 : //==============================================================================
3299 : // com::sun::star::sdb::XCompletedExecution
3300 : //------------------------------------------------------------------------------
3301 0 : void SAL_CALL ODatabaseForm::executeWithCompletion( const Reference< XInteractionHandler >& _rxHandler ) throw(SQLException, RuntimeException)
3302 : {
3303 0 : ::osl::ClearableMutexGuard aGuard(m_aMutex);
3304 : // the difference between execute and load is, that we position on the first row in case of load
3305 : // after execute we remain before the first row
3306 0 : if (!isLoaded())
3307 : {
3308 0 : aGuard.clear();
3309 0 : load_impl(sal_False, sal_False, _rxHandler);
3310 : }
3311 : else
3312 : {
3313 0 : EventObject event(static_cast< XWeak* >(this));
3314 0 : if ( !impl_approveRowChange_throw( event, true, aGuard ) )
3315 0 : return;
3316 :
3317 : // we're loaded and somebody want's to execute ourself -> this means a reload
3318 0 : reload_impl(sal_False, _rxHandler);
3319 0 : }
3320 : }
3321 :
3322 : //==============================================================================
3323 : // com::sun::star::sdbc::XRowSet
3324 : //------------------------------------------------------------------------------
3325 0 : void SAL_CALL ODatabaseForm::execute() throw( SQLException, RuntimeException )
3326 : {
3327 0 : ::osl::ResettableMutexGuard aGuard(m_aMutex);
3328 : // if somebody calls an execute and we're not loaded we reroute this call to our load method.
3329 :
3330 : // the difference between execute and load is, that we position on the first row in case of load
3331 : // after execute we remain before the first row
3332 0 : if (!isLoaded())
3333 : {
3334 0 : aGuard.clear();
3335 0 : load_impl(sal_False, sal_False);
3336 : }
3337 : else
3338 : {
3339 0 : EventObject event(static_cast< XWeak* >(this));
3340 0 : if ( !impl_approveRowChange_throw( event, true, aGuard ) )
3341 0 : return;
3342 :
3343 : // we're loaded and somebody want's to execute ourself -> this means a reload
3344 0 : reload_impl(sal_False);
3345 0 : }
3346 : }
3347 :
3348 : //------------------------------------------------------------------------------
3349 84 : void SAL_CALL ODatabaseForm::addRowSetListener(const Reference<XRowSetListener>& _rListener) throw( RuntimeException )
3350 : {
3351 84 : if (m_xAggregateAsRowSet.is())
3352 84 : m_xAggregateAsRowSet->addRowSetListener(_rListener);
3353 84 : }
3354 :
3355 : //------------------------------------------------------------------------------
3356 83 : void SAL_CALL ODatabaseForm::removeRowSetListener(const Reference<XRowSetListener>& _rListener) throw( RuntimeException )
3357 : {
3358 83 : if (m_xAggregateAsRowSet.is())
3359 83 : m_xAggregateAsRowSet->removeRowSetListener(_rListener);
3360 83 : }
3361 :
3362 : //==============================================================================
3363 : // com::sun::star::sdbc::XResultSet
3364 : //------------------------------------------------------------------------------
3365 1 : sal_Bool SAL_CALL ODatabaseForm::next() throw( SQLException, RuntimeException )
3366 : {
3367 1 : return m_xAggregateAsRowSet->next();
3368 : }
3369 :
3370 : //------------------------------------------------------------------------------
3371 252 : sal_Bool SAL_CALL ODatabaseForm::isBeforeFirst() throw( SQLException, RuntimeException )
3372 : {
3373 252 : return m_xAggregateAsRowSet->isBeforeFirst();
3374 : }
3375 :
3376 : //------------------------------------------------------------------------------
3377 253 : sal_Bool SAL_CALL ODatabaseForm::isAfterLast() throw( SQLException, RuntimeException )
3378 : {
3379 253 : return m_xAggregateAsRowSet->isAfterLast();
3380 : }
3381 :
3382 : //------------------------------------------------------------------------------
3383 0 : sal_Bool SAL_CALL ODatabaseForm::isFirst() throw( SQLException, RuntimeException )
3384 : {
3385 0 : return m_xAggregateAsRowSet->isFirst();
3386 : }
3387 :
3388 : //------------------------------------------------------------------------------
3389 0 : sal_Bool SAL_CALL ODatabaseForm::isLast() throw( SQLException, RuntimeException )
3390 : {
3391 0 : return m_xAggregateAsRowSet->isLast();
3392 : }
3393 :
3394 : //------------------------------------------------------------------------------
3395 0 : void SAL_CALL ODatabaseForm::beforeFirst() throw( SQLException, RuntimeException )
3396 : {
3397 0 : m_xAggregateAsRowSet->beforeFirst();
3398 0 : }
3399 :
3400 : //------------------------------------------------------------------------------
3401 0 : void SAL_CALL ODatabaseForm::afterLast() throw( SQLException, RuntimeException )
3402 : {
3403 0 : m_xAggregateAsRowSet->afterLast();
3404 0 : }
3405 :
3406 : //------------------------------------------------------------------------------
3407 0 : sal_Bool SAL_CALL ODatabaseForm::first() throw( SQLException, RuntimeException )
3408 : {
3409 0 : return m_xAggregateAsRowSet->first();
3410 : }
3411 :
3412 : //------------------------------------------------------------------------------
3413 0 : sal_Bool SAL_CALL ODatabaseForm::last() throw( SQLException, RuntimeException )
3414 : {
3415 0 : return m_xAggregateAsRowSet->last();
3416 : }
3417 :
3418 : //------------------------------------------------------------------------------
3419 0 : sal_Int32 SAL_CALL ODatabaseForm::getRow() throw( SQLException, RuntimeException )
3420 : {
3421 0 : return m_xAggregateAsRowSet->getRow();
3422 : }
3423 :
3424 : //------------------------------------------------------------------------------
3425 0 : sal_Bool SAL_CALL ODatabaseForm::absolute(sal_Int32 row) throw( SQLException, RuntimeException )
3426 : {
3427 0 : return m_xAggregateAsRowSet->absolute(row);
3428 : }
3429 :
3430 : //------------------------------------------------------------------------------
3431 0 : sal_Bool SAL_CALL ODatabaseForm::relative(sal_Int32 rows) throw( SQLException, RuntimeException )
3432 : {
3433 0 : return m_xAggregateAsRowSet->relative(rows);
3434 : }
3435 :
3436 : //------------------------------------------------------------------------------
3437 0 : sal_Bool SAL_CALL ODatabaseForm::previous() throw( SQLException, RuntimeException )
3438 : {
3439 0 : return m_xAggregateAsRowSet->previous();
3440 : }
3441 :
3442 : //------------------------------------------------------------------------------
3443 0 : void SAL_CALL ODatabaseForm::refreshRow() throw( SQLException, RuntimeException )
3444 : {
3445 0 : m_xAggregateAsRowSet->refreshRow();
3446 0 : }
3447 :
3448 : //------------------------------------------------------------------------------
3449 0 : sal_Bool SAL_CALL ODatabaseForm::rowUpdated() throw( SQLException, RuntimeException )
3450 : {
3451 0 : return m_xAggregateAsRowSet->rowUpdated();
3452 : }
3453 :
3454 : //------------------------------------------------------------------------------
3455 0 : sal_Bool SAL_CALL ODatabaseForm::rowInserted() throw( SQLException, RuntimeException )
3456 : {
3457 0 : return m_xAggregateAsRowSet->rowInserted();
3458 : }
3459 :
3460 : //------------------------------------------------------------------------------
3461 14 : sal_Bool SAL_CALL ODatabaseForm::rowDeleted() throw( SQLException, RuntimeException )
3462 : {
3463 14 : return m_xAggregateAsRowSet->rowDeleted();
3464 : }
3465 :
3466 : //------------------------------------------------------------------------------
3467 0 : InterfaceRef SAL_CALL ODatabaseForm::getStatement() throw( SQLException, RuntimeException )
3468 : {
3469 0 : return m_xAggregateAsRowSet->getStatement();
3470 : }
3471 :
3472 : // com::sun::star::sdbc::XResultSetUpdate
3473 : // exceptions during insert update and delete will be forwarded to the errorlistener
3474 : //------------------------------------------------------------------------------
3475 0 : void SAL_CALL ODatabaseForm::insertRow() throw( SQLException, RuntimeException )
3476 : {
3477 : try
3478 : {
3479 0 : Reference<XResultSetUpdate> xUpdate;
3480 0 : if (query_aggregation( m_xAggregate, xUpdate))
3481 0 : xUpdate->insertRow();
3482 : }
3483 0 : catch(const RowSetVetoException&)
3484 : {
3485 0 : throw;
3486 : }
3487 0 : catch(const SQLException& eDb)
3488 : {
3489 0 : onError(eDb, FRM_RES_STRING(RID_STR_ERR_INSERTRECORD));
3490 0 : throw;
3491 : }
3492 0 : }
3493 :
3494 : //------------------------------------------------------------------------------
3495 0 : void SAL_CALL ODatabaseForm::updateRow() throw( SQLException, RuntimeException )
3496 : {
3497 : try
3498 : {
3499 0 : Reference<XResultSetUpdate> xUpdate;
3500 0 : if (query_aggregation( m_xAggregate, xUpdate))
3501 0 : xUpdate->updateRow();
3502 : }
3503 0 : catch(const RowSetVetoException&)
3504 : {
3505 0 : throw;
3506 : }
3507 0 : catch(const SQLException& eDb)
3508 : {
3509 0 : onError(eDb, FRM_RES_STRING(RID_STR_ERR_UPDATERECORD));
3510 0 : throw;
3511 : }
3512 0 : }
3513 :
3514 : //------------------------------------------------------------------------------
3515 0 : void SAL_CALL ODatabaseForm::deleteRow() throw( SQLException, RuntimeException )
3516 : {
3517 : try
3518 : {
3519 0 : Reference<XResultSetUpdate> xUpdate;
3520 0 : if (query_aggregation( m_xAggregate, xUpdate))
3521 0 : xUpdate->deleteRow();
3522 : }
3523 0 : catch(const RowSetVetoException&)
3524 : {
3525 0 : throw;
3526 : }
3527 0 : catch(const SQLException& eDb)
3528 : {
3529 0 : onError(eDb, FRM_RES_STRING(RID_STR_ERR_DELETERECORD));
3530 0 : throw;
3531 : }
3532 0 : }
3533 :
3534 : //------------------------------------------------------------------------------
3535 0 : void SAL_CALL ODatabaseForm::cancelRowUpdates() throw( SQLException, RuntimeException )
3536 : {
3537 : try
3538 : {
3539 0 : Reference<XResultSetUpdate> xUpdate;
3540 0 : if (query_aggregation( m_xAggregate, xUpdate))
3541 0 : xUpdate->cancelRowUpdates();
3542 : }
3543 0 : catch(const RowSetVetoException&)
3544 : {
3545 0 : throw;
3546 : }
3547 0 : catch(const SQLException& eDb)
3548 : {
3549 0 : onError(eDb, FRM_RES_STRING(RID_STR_ERR_INSERTRECORD));
3550 0 : throw;
3551 : }
3552 0 : }
3553 :
3554 : //------------------------------------------------------------------------------
3555 0 : void SAL_CALL ODatabaseForm::moveToInsertRow() throw( SQLException, RuntimeException )
3556 : {
3557 0 : Reference<XResultSetUpdate> xUpdate;
3558 0 : if (query_aggregation( m_xAggregate, xUpdate))
3559 : {
3560 : // _always_ move to the insert row
3561 : //
3562 : // Formerly, the following line was conditioned with a "not is new", means we did not move the aggregate
3563 : // to the insert row if it was already positioned there.
3564 : //
3565 : // This prevented the RowSet implementation from resetting it's column values. We, ourself, formerly
3566 : // did this reset of columns in reset_impl, where we set every column to the ControlDefault, or, if this
3567 : // was not present, to NULL. However, the problem with setting to NULL was #88888#, the problem with
3568 : // _not_ setting to NULL (which was the original fix for #88888#) was #97955#.
3569 : //
3570 : // So now we
3571 : // * move our aggregate to the insert row
3572 : // * in reset_impl
3573 : // - set the control defaults into the columns if not void
3574 : // - do _not_ set the columns to NULL if no control default is set
3575 : //
3576 : // Still, there is #72756#. During fixing this bug, DG introduced not calling the aggregate here. So
3577 : // in theory, we re-introduced #72756#. But the bug described therein does not happen anymore, as the
3578 : // preliminaries for it changed (no display of guessed values for new records with autoinc fields)
3579 : //
3580 : // BTW: the public Issuezilla bug is #i2815#
3581 : //
3582 0 : xUpdate->moveToInsertRow();
3583 :
3584 : // then set the default values and the parameters given from the parent
3585 0 : reset();
3586 0 : }
3587 0 : }
3588 :
3589 : //------------------------------------------------------------------------------
3590 0 : void SAL_CALL ODatabaseForm::moveToCurrentRow() throw( SQLException, RuntimeException )
3591 : {
3592 0 : Reference<XResultSetUpdate> xUpdate;
3593 0 : if (query_aggregation( m_xAggregate, xUpdate))
3594 0 : xUpdate->moveToCurrentRow();
3595 0 : }
3596 :
3597 : // com::sun::star::sdbcx::XDeleteRows
3598 : //------------------------------------------------------------------------------
3599 0 : Sequence<sal_Int32> SAL_CALL ODatabaseForm::deleteRows(const Sequence<Any>& rows) throw( SQLException, RuntimeException )
3600 : {
3601 : try
3602 : {
3603 0 : Reference<XDeleteRows> xDelete;
3604 0 : if (query_aggregation( m_xAggregate, xDelete))
3605 0 : return xDelete->deleteRows(rows);
3606 : }
3607 0 : catch(const RowSetVetoException&)
3608 : {
3609 0 : throw;
3610 : }
3611 0 : catch(const SQLException& eDb)
3612 : {
3613 0 : onError(eDb, FRM_RES_STRING(RID_STR_ERR_DELETERECORDS));
3614 0 : throw;
3615 : }
3616 :
3617 0 : return Sequence< sal_Int32 >();
3618 : }
3619 :
3620 : // com::sun::star::sdbc::XParameters
3621 : //------------------------------------------------------------------------------
3622 0 : void SAL_CALL ODatabaseForm::setNull(sal_Int32 parameterIndex, sal_Int32 sqlType) throw( SQLException, RuntimeException )
3623 : {
3624 0 : m_aParameterManager.setNull(parameterIndex, sqlType);
3625 0 : }
3626 :
3627 : //------------------------------------------------------------------------------
3628 0 : void SAL_CALL ODatabaseForm::setObjectNull(sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName) throw( SQLException, RuntimeException )
3629 : {
3630 0 : m_aParameterManager.setObjectNull(parameterIndex, sqlType, typeName);
3631 0 : }
3632 :
3633 : //------------------------------------------------------------------------------
3634 0 : void SAL_CALL ODatabaseForm::setBoolean(sal_Int32 parameterIndex, sal_Bool x) throw( SQLException, RuntimeException )
3635 : {
3636 0 : m_aParameterManager.setBoolean(parameterIndex, x);
3637 0 : }
3638 :
3639 : //------------------------------------------------------------------------------
3640 0 : void SAL_CALL ODatabaseForm::setByte(sal_Int32 parameterIndex, sal_Int8 x) throw( SQLException, RuntimeException )
3641 : {
3642 0 : m_aParameterManager.setByte(parameterIndex, x);
3643 0 : }
3644 :
3645 : //------------------------------------------------------------------------------
3646 0 : void SAL_CALL ODatabaseForm::setShort(sal_Int32 parameterIndex, sal_Int16 x) throw( SQLException, RuntimeException )
3647 : {
3648 0 : m_aParameterManager.setShort(parameterIndex, x);
3649 0 : }
3650 :
3651 : //------------------------------------------------------------------------------
3652 0 : void SAL_CALL ODatabaseForm::setInt(sal_Int32 parameterIndex, sal_Int32 x) throw( SQLException, RuntimeException )
3653 : {
3654 0 : m_aParameterManager.setInt(parameterIndex, x);
3655 0 : }
3656 :
3657 : //------------------------------------------------------------------------------
3658 0 : void SAL_CALL ODatabaseForm::setLong(sal_Int32 parameterIndex, sal_Int64 x) throw( SQLException, RuntimeException )
3659 : {
3660 0 : m_aParameterManager.setLong(parameterIndex, x);
3661 0 : }
3662 :
3663 : //------------------------------------------------------------------------------
3664 0 : void SAL_CALL ODatabaseForm::setFloat(sal_Int32 parameterIndex, float x) throw( SQLException, RuntimeException )
3665 : {
3666 0 : m_aParameterManager.setFloat(parameterIndex, x);
3667 0 : }
3668 :
3669 : //------------------------------------------------------------------------------
3670 0 : void SAL_CALL ODatabaseForm::setDouble(sal_Int32 parameterIndex, double x) throw( SQLException, RuntimeException )
3671 : {
3672 0 : m_aParameterManager.setDouble(parameterIndex, x);
3673 0 : }
3674 :
3675 : //------------------------------------------------------------------------------
3676 0 : void SAL_CALL ODatabaseForm::setString(sal_Int32 parameterIndex, const OUString& x) throw( SQLException, RuntimeException )
3677 : {
3678 0 : m_aParameterManager.setString(parameterIndex, x);
3679 0 : }
3680 :
3681 : //------------------------------------------------------------------------------
3682 0 : void SAL_CALL ODatabaseForm::setBytes(sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x) throw( SQLException, RuntimeException )
3683 : {
3684 0 : m_aParameterManager.setBytes(parameterIndex, x);
3685 0 : }
3686 :
3687 : //------------------------------------------------------------------------------
3688 0 : void SAL_CALL ODatabaseForm::setDate(sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x) throw( SQLException, RuntimeException )
3689 : {
3690 0 : m_aParameterManager.setDate(parameterIndex, x);
3691 0 : }
3692 :
3693 : //------------------------------------------------------------------------------
3694 0 : void SAL_CALL ODatabaseForm::setTime(sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x) throw( SQLException, RuntimeException )
3695 : {
3696 0 : m_aParameterManager.setTime(parameterIndex, x);
3697 0 : }
3698 :
3699 : //------------------------------------------------------------------------------
3700 0 : void SAL_CALL ODatabaseForm::setTimestamp(sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x) throw( SQLException, RuntimeException )
3701 : {
3702 0 : m_aParameterManager.setTimestamp(parameterIndex, x);
3703 0 : }
3704 :
3705 : //------------------------------------------------------------------------------
3706 0 : void SAL_CALL ODatabaseForm::setBinaryStream(sal_Int32 parameterIndex, const Reference<XInputStream>& x, sal_Int32 length) throw( SQLException, RuntimeException )
3707 : {
3708 0 : m_aParameterManager.setBinaryStream(parameterIndex, x, length);
3709 0 : }
3710 :
3711 : //------------------------------------------------------------------------------
3712 0 : void SAL_CALL ODatabaseForm::setCharacterStream(sal_Int32 parameterIndex, const Reference<XInputStream>& x, sal_Int32 length) throw( SQLException, RuntimeException )
3713 : {
3714 0 : m_aParameterManager.setCharacterStream(parameterIndex, x, length);
3715 0 : }
3716 :
3717 : //------------------------------------------------------------------------------
3718 0 : void SAL_CALL ODatabaseForm::setObjectWithInfo(sal_Int32 parameterIndex, const Any& x, sal_Int32 targetSqlType, sal_Int32 scale) throw( SQLException, RuntimeException )
3719 : {
3720 0 : m_aParameterManager.setObjectWithInfo(parameterIndex, x, targetSqlType, scale);
3721 0 : }
3722 :
3723 : //------------------------------------------------------------------------------
3724 0 : void SAL_CALL ODatabaseForm::setObject(sal_Int32 parameterIndex, const Any& x) throw( SQLException, RuntimeException )
3725 : {
3726 0 : m_aParameterManager.setObject(parameterIndex, x);
3727 0 : }
3728 :
3729 : //------------------------------------------------------------------------------
3730 0 : void SAL_CALL ODatabaseForm::setRef(sal_Int32 parameterIndex, const Reference<XRef>& x) throw( SQLException, RuntimeException )
3731 : {
3732 0 : m_aParameterManager.setRef(parameterIndex, x);
3733 0 : }
3734 :
3735 : //------------------------------------------------------------------------------
3736 0 : void SAL_CALL ODatabaseForm::setBlob(sal_Int32 parameterIndex, const Reference<XBlob>& x) throw( SQLException, RuntimeException )
3737 : {
3738 0 : m_aParameterManager.setBlob(parameterIndex, x);
3739 0 : }
3740 :
3741 : //------------------------------------------------------------------------------
3742 0 : void SAL_CALL ODatabaseForm::setClob(sal_Int32 parameterIndex, const Reference<XClob>& x) throw( SQLException, RuntimeException )
3743 : {
3744 0 : m_aParameterManager.setClob(parameterIndex, x);
3745 0 : }
3746 :
3747 : //------------------------------------------------------------------------------
3748 0 : void SAL_CALL ODatabaseForm::setArray(sal_Int32 parameterIndex, const Reference<XArray>& x) throw( SQLException, RuntimeException )
3749 : {
3750 0 : m_aParameterManager.setArray(parameterIndex, x);
3751 0 : }
3752 :
3753 : //------------------------------------------------------------------------------
3754 0 : void SAL_CALL ODatabaseForm::clearParameters() throw( SQLException, RuntimeException )
3755 : {
3756 0 : m_aParameterManager.clearParameters();
3757 0 : }
3758 :
3759 : //------------------------------------------------------------------------------
3760 231 : void SAL_CALL ODatabaseForm::propertyChange( const PropertyChangeEvent& evt ) throw (RuntimeException)
3761 : {
3762 231 : if ( evt.Source == m_xParent )
3763 : {
3764 0 : if ( evt.PropertyName == PROPERTY_ISNEW )
3765 : {
3766 0 : sal_Bool bCurrentIsNew( sal_False );
3767 0 : OSL_VERIFY( evt.NewValue >>= bCurrentIsNew );
3768 0 : if ( !bCurrentIsNew )
3769 0 : reload_impl( sal_True );
3770 : }
3771 231 : return;
3772 : }
3773 231 : OFormComponents::propertyChange( evt );
3774 : }
3775 :
3776 : // com::sun::star::lang::XServiceInfo
3777 : //------------------------------------------------------------------------------
3778 30 : OUString SAL_CALL ODatabaseForm::getImplementationName_Static()
3779 : {
3780 30 : return OUString( "com.sun.star.comp.forms.ODatabaseForm" );
3781 : }
3782 :
3783 : //------------------------------------------------------------------------------
3784 15 : Sequence< OUString > SAL_CALL ODatabaseForm::getCompatibleServiceNames_Static()
3785 : {
3786 15 : Sequence< OUString > aServices( 1 );
3787 15 : OUString* pServices = aServices.getArray();
3788 :
3789 15 : *pServices++ = FRM_COMPONENT_FORM;
3790 :
3791 15 : return aServices;
3792 : }
3793 :
3794 : //------------------------------------------------------------------------------
3795 15 : Sequence< OUString > SAL_CALL ODatabaseForm::getCurrentServiceNames_Static()
3796 : {
3797 15 : Sequence< OUString > aServices( 5 );
3798 15 : OUString* pServices = aServices.getArray();
3799 :
3800 15 : *pServices++ = FRM_SUN_FORMCOMPONENT;
3801 15 : *pServices++ = OUString("com.sun.star.form.FormComponents");
3802 15 : *pServices++ = FRM_SUN_COMPONENT_FORM;
3803 15 : *pServices++ = FRM_SUN_COMPONENT_HTMLFORM;
3804 15 : *pServices++ = FRM_SUN_COMPONENT_DATAFORM;
3805 :
3806 15 : return aServices;
3807 : }
3808 :
3809 : //------------------------------------------------------------------------------
3810 15 : Sequence< OUString > SAL_CALL ODatabaseForm::getSupportedServiceNames_Static()
3811 : {
3812 : return ::comphelper::concatSequences(
3813 : getCurrentServiceNames_Static(),
3814 : getCompatibleServiceNames_Static()
3815 15 : );
3816 : }
3817 :
3818 : //------------------------------------------------------------------------------
3819 0 : OUString SAL_CALL ODatabaseForm::getImplementationName() throw( RuntimeException )
3820 : {
3821 0 : return getImplementationName_Static();
3822 : }
3823 :
3824 : //------------------------------------------------------------------------------
3825 0 : Sequence< OUString > SAL_CALL ODatabaseForm::getSupportedServiceNames() throw( RuntimeException )
3826 : {
3827 : // the services of our aggregate
3828 0 : Sequence< OUString > aServices;
3829 0 : Reference< XServiceInfo > xInfo;
3830 0 : if (query_aggregation(m_xAggregate, xInfo))
3831 0 : aServices = xInfo->getSupportedServiceNames();
3832 :
3833 : // concat with out own services
3834 : return ::comphelper::concatSequences(
3835 : getCurrentServiceNames_Static(),
3836 : aServices
3837 0 : );
3838 : // use getCurrentXXX instead of getSupportedXXX, because at runtime, we do not want to have
3839 : // the compatible names
3840 : // This is maily to be consistent with the implementation before fixing #97083#, though the
3841 : // better solution _may_ be to return the compatible names at runtime, too
3842 : }
3843 :
3844 : //------------------------------------------------------------------------------
3845 0 : sal_Bool SAL_CALL ODatabaseForm::supportsService(const OUString& ServiceName) throw( RuntimeException )
3846 : {
3847 0 : Sequence< OUString > aSupported( getSupportedServiceNames() );
3848 0 : const OUString* pArray = aSupported.getConstArray();
3849 0 : for( sal_Int32 i = 0; i < aSupported.getLength(); ++i, ++pArray )
3850 0 : if( pArray->equals( ServiceName ) )
3851 0 : return sal_True;
3852 0 : return sal_False;
3853 : }
3854 :
3855 : //==============================================================================
3856 : // com::sun::star::io::XPersistObject
3857 : //------------------------------------------------------------------------------
3858 :
3859 : const sal_uInt16 CYCLE = 0x0001;
3860 : const sal_uInt16 DONTAPPLYFILTER = 0x0002;
3861 :
3862 : //------------------------------------------------------------------------------
3863 0 : OUString ODatabaseForm::getServiceName() throw( RuntimeException )
3864 : {
3865 0 : return OUString(FRM_COMPONENT_FORM); // old (non-sun) name for compatibility !
3866 : }
3867 :
3868 : //------------------------------------------------------------------------------
3869 0 : void SAL_CALL ODatabaseForm::write(const Reference<XObjectOutputStream>& _rxOutStream) throw( IOException, RuntimeException )
3870 : {
3871 : DBG_ASSERT(m_xAggregateSet.is(), "ODatabaseForm::write : only to be called if the aggregate exists !");
3872 :
3873 : // all children
3874 0 : OFormComponents::write(_rxOutStream);
3875 :
3876 : // version
3877 0 : _rxOutStream->writeShort(0x0003);
3878 :
3879 : // Name
3880 0 : _rxOutStream << m_sName;
3881 :
3882 0 : OUString sDataSource;
3883 0 : if (m_xAggregateSet.is())
3884 0 : m_xAggregateSet->getPropertyValue(PROPERTY_DATASOURCE) >>= sDataSource;
3885 0 : _rxOutStream << sDataSource;
3886 :
3887 : // former CursorSource
3888 0 : OUString sCommand;
3889 0 : if (m_xAggregateSet.is())
3890 0 : m_xAggregateSet->getPropertyValue(PROPERTY_COMMAND) >>= sCommand;
3891 0 : _rxOutStream << sCommand;
3892 :
3893 : // former MasterFields
3894 0 : _rxOutStream << m_aMasterFields;
3895 : // former DetailFields
3896 0 : _rxOutStream << m_aDetailFields;
3897 :
3898 : // former DataSelectionType
3899 0 : DataSelectionType eTranslated = DataSelectionType_TABLE;
3900 0 : if (m_xAggregateSet.is())
3901 : {
3902 0 : sal_Int32 nCommandType = 0;
3903 0 : m_xAggregateSet->getPropertyValue(PROPERTY_COMMANDTYPE) >>= nCommandType;
3904 0 : switch (nCommandType)
3905 : {
3906 0 : case CommandType::TABLE : eTranslated = DataSelectionType_TABLE; break;
3907 0 : case CommandType::QUERY : eTranslated = DataSelectionType_QUERY; break;
3908 : case CommandType::COMMAND:
3909 : {
3910 0 : sal_Bool bEscapeProcessing = getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING));
3911 0 : eTranslated = bEscapeProcessing ? DataSelectionType_SQL : DataSelectionType_SQLPASSTHROUGH;
3912 : }
3913 0 : break;
3914 : default : OSL_FAIL("ODatabaseForm::write : wrong CommandType !");
3915 : }
3916 : }
3917 0 : _rxOutStream->writeShort((sal_Int16)eTranslated); // former DataSelectionType
3918 :
3919 : // very old versions expect a CursorType here
3920 0 : _rxOutStream->writeShort(DatabaseCursorType_KEYSET);
3921 :
3922 0 : _rxOutStream->writeBoolean(m_eNavigation != NavigationBarMode_NONE);
3923 :
3924 : // former DataEntry
3925 0 : if (m_xAggregateSet.is())
3926 0 : _rxOutStream->writeBoolean(getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_INSERTONLY)));
3927 : else
3928 0 : _rxOutStream->writeBoolean(sal_False);
3929 :
3930 0 : _rxOutStream->writeBoolean(m_bAllowInsert);
3931 0 : _rxOutStream->writeBoolean(m_bAllowUpdate);
3932 0 : _rxOutStream->writeBoolean(m_bAllowDelete);
3933 :
3934 : // html form stuff
3935 0 : OUString sTmp = INetURLObject::decode( m_aTargetURL, '%', INetURLObject::DECODE_UNAMBIGUOUS);
3936 0 : _rxOutStream << sTmp;
3937 0 : _rxOutStream->writeShort( (sal_Int16)m_eSubmitMethod );
3938 0 : _rxOutStream->writeShort( (sal_Int16)m_eSubmitEncoding );
3939 0 : _rxOutStream << m_aTargetFrame;
3940 :
3941 : // version 2 didn't know some options and the "default" state
3942 0 : sal_Int32 nCycle = TabulatorCycle_RECORDS;
3943 0 : if (m_aCycle.hasValue())
3944 : {
3945 0 : ::cppu::enum2int(nCycle, m_aCycle);
3946 0 : if (m_aCycle == TabulatorCycle_PAGE)
3947 : // unknown in earlier versions
3948 0 : nCycle = TabulatorCycle_RECORDS;
3949 : }
3950 0 : _rxOutStream->writeShort((sal_Int16) nCycle);
3951 :
3952 0 : _rxOutStream->writeShort((sal_Int16)m_eNavigation);
3953 :
3954 0 : OUString sFilter;
3955 0 : OUString sOrder;
3956 0 : if (m_xAggregateSet.is())
3957 : {
3958 0 : m_xAggregateSet->getPropertyValue(PROPERTY_FILTER) >>= sFilter;
3959 0 : m_xAggregateSet->getPropertyValue(PROPERTY_SORT) >>= sOrder;
3960 : }
3961 0 : _rxOutStream << sFilter;
3962 0 : _rxOutStream << sOrder;
3963 :
3964 :
3965 : // version 3
3966 0 : sal_uInt16 nAnyMask = 0;
3967 0 : if (m_aCycle.hasValue())
3968 0 : nAnyMask |= CYCLE;
3969 :
3970 0 : if (m_xAggregateSet.is() && !getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_APPLYFILTER)))
3971 0 : nAnyMask |= DONTAPPLYFILTER;
3972 :
3973 0 : _rxOutStream->writeShort(nAnyMask);
3974 :
3975 0 : if (nAnyMask & CYCLE)
3976 : {
3977 0 : sal_Int32 nRealCycle = 0;
3978 0 : ::cppu::enum2int(nRealCycle, m_aCycle);
3979 0 : _rxOutStream->writeShort((sal_Int16)nRealCycle);
3980 0 : }
3981 0 : }
3982 :
3983 : //------------------------------------------------------------------------------
3984 0 : void SAL_CALL ODatabaseForm::read(const Reference<XObjectInputStream>& _rxInStream) throw( IOException, RuntimeException )
3985 : {
3986 : DBG_ASSERT(m_xAggregateSet.is(), "ODatabaseForm::read : only to be called if the aggregate exists !");
3987 :
3988 0 : OFormComponents::read(_rxInStream);
3989 :
3990 : // version
3991 0 : sal_uInt16 nVersion = _rxInStream->readShort();
3992 :
3993 0 : _rxInStream >> m_sName;
3994 :
3995 0 : OUString sAggregateProp;
3996 0 : _rxInStream >> sAggregateProp;
3997 0 : if (m_xAggregateSet.is())
3998 0 : m_xAggregateSet->setPropertyValue(PROPERTY_DATASOURCE, makeAny(sAggregateProp));
3999 0 : _rxInStream >> sAggregateProp;
4000 0 : if (m_xAggregateSet.is())
4001 0 : m_xAggregateSet->setPropertyValue(PROPERTY_COMMAND, makeAny(sAggregateProp));
4002 :
4003 0 : _rxInStream >> m_aMasterFields;
4004 0 : _rxInStream >> m_aDetailFields;
4005 :
4006 0 : sal_Int16 nCursorSourceType = _rxInStream->readShort();
4007 0 : sal_Int32 nCommandType = 0;
4008 0 : switch ((DataSelectionType)nCursorSourceType)
4009 : {
4010 0 : case DataSelectionType_TABLE : nCommandType = CommandType::TABLE; break;
4011 0 : case DataSelectionType_QUERY : nCommandType = CommandType::QUERY; break;
4012 : case DataSelectionType_SQL:
4013 : case DataSelectionType_SQLPASSTHROUGH:
4014 : {
4015 0 : nCommandType = CommandType::COMMAND;
4016 0 : sal_Bool bEscapeProcessing = ((DataSelectionType)nCursorSourceType) != DataSelectionType_SQLPASSTHROUGH;
4017 0 : m_xAggregateSet->setPropertyValue(PROPERTY_ESCAPE_PROCESSING, makeAny((sal_Bool)bEscapeProcessing));
4018 : }
4019 0 : break;
4020 : default : OSL_FAIL("ODatabaseForm::read : wrong CommandType !");
4021 : }
4022 0 : if (m_xAggregateSet.is())
4023 0 : m_xAggregateSet->setPropertyValue(PROPERTY_COMMANDTYPE, makeAny(nCommandType));
4024 :
4025 : // obsolete
4026 0 : _rxInStream->readShort();
4027 :
4028 : // navigation mode was a boolean in version 1
4029 : // was a sal_Bool in version 1
4030 0 : sal_Bool bNavigation = _rxInStream->readBoolean();
4031 0 : if (nVersion == 1)
4032 0 : m_eNavigation = bNavigation ? NavigationBarMode_CURRENT : NavigationBarMode_NONE;
4033 :
4034 0 : sal_Bool bInsertOnly = _rxInStream->readBoolean();
4035 0 : if (m_xAggregateSet.is())
4036 0 : m_xAggregateSet->setPropertyValue(PROPERTY_INSERTONLY, makeAny(bInsertOnly));
4037 :
4038 0 : m_bAllowInsert = _rxInStream->readBoolean();
4039 0 : m_bAllowUpdate = _rxInStream->readBoolean();
4040 0 : m_bAllowDelete = _rxInStream->readBoolean();
4041 :
4042 : // html stuff
4043 0 : OUString sTmp;
4044 0 : _rxInStream >> sTmp;
4045 0 : m_aTargetURL = INetURLObject::decode( sTmp, '%', INetURLObject::DECODE_UNAMBIGUOUS);
4046 0 : m_eSubmitMethod = (FormSubmitMethod)_rxInStream->readShort();
4047 0 : m_eSubmitEncoding = (FormSubmitEncoding)_rxInStream->readShort();
4048 0 : _rxInStream >> m_aTargetFrame;
4049 :
4050 0 : if (nVersion > 1)
4051 : {
4052 0 : sal_Int32 nCycle = _rxInStream->readShort();
4053 0 : m_aCycle = ::cppu::int2enum(nCycle, ::getCppuType(static_cast<const TabulatorCycle*>(NULL)));
4054 0 : m_eNavigation = (NavigationBarMode)_rxInStream->readShort();
4055 :
4056 0 : _rxInStream >> sAggregateProp;
4057 0 : setPropertyValue(PROPERTY_FILTER, makeAny(sAggregateProp));
4058 :
4059 0 : _rxInStream >> sAggregateProp;
4060 0 : if (m_xAggregateSet.is())
4061 0 : m_xAggregateSet->setPropertyValue(PROPERTY_SORT, makeAny(sAggregateProp));
4062 : }
4063 :
4064 0 : sal_uInt16 nAnyMask = 0;
4065 0 : if (nVersion > 2)
4066 : {
4067 0 : nAnyMask = _rxInStream->readShort();
4068 0 : if (nAnyMask & CYCLE)
4069 : {
4070 0 : sal_Int32 nCycle = _rxInStream->readShort();
4071 0 : m_aCycle = ::cppu::int2enum(nCycle, ::getCppuType(static_cast<const TabulatorCycle*>(NULL)));
4072 : }
4073 : else
4074 0 : m_aCycle.clear();
4075 : }
4076 0 : if (m_xAggregateSet.is())
4077 0 : m_xAggregateSet->setPropertyValue(PROPERTY_APPLYFILTER, makeAny((sal_Bool)((nAnyMask & DONTAPPLYFILTER) == 0)));
4078 0 : }
4079 :
4080 : //------------------------------------------------------------------------------
4081 300 : void ODatabaseForm::implInserted( const ElementDescription* _pElement )
4082 : {
4083 300 : OFormComponents::implInserted( _pElement );
4084 :
4085 300 : Reference< XSQLErrorBroadcaster > xBroadcaster( _pElement->xInterface, UNO_QUERY );
4086 600 : Reference< XForm > xForm ( _pElement->xInterface, UNO_QUERY );
4087 :
4088 300 : if ( xBroadcaster.is() && !xForm.is() )
4089 : { // the object is an error broadcaster, but no form itself -> add ourself as listener
4090 26 : xBroadcaster->addSQLErrorListener( this );
4091 300 : }
4092 300 : }
4093 :
4094 : //------------------------------------------------------------------------------
4095 220 : void ODatabaseForm::implRemoved(const InterfaceRef& _rxObject)
4096 : {
4097 220 : OFormComponents::implRemoved( _rxObject );
4098 :
4099 220 : Reference<XSQLErrorBroadcaster> xBroadcaster(_rxObject, UNO_QUERY);
4100 440 : Reference<XForm> xForm(_rxObject, UNO_QUERY);
4101 220 : if (xBroadcaster.is() && !xForm.is())
4102 : { // the object is an error broadcaster, but no form itself -> remove ourself as listener
4103 20 : xBroadcaster->removeSQLErrorListener(this);
4104 220 : }
4105 220 : }
4106 :
4107 : //------------------------------------------------------------------------------
4108 0 : void SAL_CALL ODatabaseForm::errorOccured(const SQLErrorEvent& _rEvent) throw( RuntimeException )
4109 : {
4110 : // give it to my own error listener
4111 0 : onError(_rEvent);
4112 : // TODO : think about extending the chain with an SQLContext object saying
4113 : // "this was an error of one of my children"
4114 0 : }
4115 :
4116 : // com::sun::star::container::XNamed
4117 : //------------------------------------------------------------------------------
4118 19 : OUString SAL_CALL ODatabaseForm::getName() throw( RuntimeException )
4119 : {
4120 19 : OUString sReturn;
4121 19 : OPropertySetHelper::getFastPropertyValue(PROPERTY_ID_NAME) >>= sReturn;
4122 19 : return sReturn;
4123 : }
4124 :
4125 : //------------------------------------------------------------------------------
4126 0 : void SAL_CALL ODatabaseForm::setName(const OUString& aName) throw( RuntimeException )
4127 : {
4128 0 : setFastPropertyValue(PROPERTY_ID_NAME, makeAny(aName));
4129 0 : }
4130 :
4131 : //.........................................................................
4132 72 : } // namespace frm
4133 : //.........................................................................
4134 :
4135 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|