LCOV - code coverage report
Current view: top level - forms/source/component - DatabaseForm.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 494 1910 25.9 %
Date: 2014-11-03 Functions: 66 187 35.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10