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