LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/browser - brwctrlr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 492 1242 39.6 %
Date: 2013-07-09 Functions: 52 149 34.9 %
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             : #include "browserids.hxx"
      21             : #include "brwctrlr.hxx"
      22             : #include "brwview.hxx"
      23             : #include "dbu_brw.hrc"
      24             : #include "dbustrings.hrc"
      25             : #include "queryfilter.hxx"
      26             : #include "queryorder.hxx"
      27             : #include "sqlmessage.hxx"
      28             : 
      29             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      30             : #include <com/sun/star/container/XNameContainer.hpp>
      31             : #include <com/sun/star/container/XNamed.hpp>
      32             : #include <com/sun/star/form/FormButtonType.hpp>
      33             : #include <com/sun/star/form/FormSubmitEncoding.hpp>
      34             : #include <com/sun/star/form/FormSubmitMethod.hpp>
      35             : #include <com/sun/star/form/XApproveActionBroadcaster.hpp>
      36             : #include <com/sun/star/form/XBoundControl.hpp>
      37             : #include <com/sun/star/form/XChangeBroadcaster.hpp>
      38             : #include <com/sun/star/form/XChangeListener.hpp>
      39             : #include <com/sun/star/form/XDatabaseParameterBroadcaster.hpp>
      40             : #include <com/sun/star/form/XLoadable.hpp>
      41             : #include <com/sun/star/form/XReset.hpp>
      42             : #include <com/sun/star/form/XResetListener.hpp>
      43             : #include <com/sun/star/form/XSubmit.hpp>
      44             : #include <com/sun/star/form/XSubmitListener.hpp>
      45             : #include <com/sun/star/form/runtime/XFormController.hpp>
      46             : #include <com/sun/star/sdb/CommandType.hpp>
      47             : #include <com/sun/star/sdb/ErrorCondition.hpp>
      48             : #include <com/sun/star/sdb/ParametersRequest.hpp>
      49             : #include <com/sun/star/sdb/SQLContext.hpp>
      50             : #include <com/sun/star/sdb/XInteractionSupplyParameters.hpp>
      51             : #include <com/sun/star/sdb/XSQLErrorBroadcaster.hpp>
      52             : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      53             : #include <com/sun/star/sdb/SQLFilterOperator.hpp>
      54             : #include <com/sun/star/sdbc/XConnection.hpp>
      55             : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
      56             : #include <com/sun/star/sdbc/XRowSetListener.hpp>
      57             : #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
      58             : #include <com/sun/star/sdbcx/Privilege.hpp>
      59             : #include <com/sun/star/sdbcx/XRowLocate.hpp>
      60             : #include <com/sun/star/task/InteractionHandler.hpp>
      61             : #include <com/sun/star/uno/TypeClass.hpp>
      62             : #include <com/sun/star/util/NumberFormatter.hpp>
      63             : #include <com/sun/star/util/XCancellable.hpp>
      64             : 
      65             : #include <comphelper/enumhelper.hxx>
      66             : #include <comphelper/extract.hxx>
      67             : #include <comphelper/interaction.hxx>
      68             : #include <comphelper/processfactory.hxx>
      69             : #include <comphelper/sequence.hxx>
      70             : #include <comphelper/string.hxx>
      71             : #include <connectivity/dbexception.hxx>
      72             : #include <connectivity/dbtools.hxx>
      73             : #include <connectivity/sqlerror.hxx>
      74             : #include <cppuhelper/exc_hlp.hxx>
      75             : #include <cppuhelper/implbase2.hxx>
      76             : #include <cppuhelper/typeprovider.hxx>
      77             : #include <osl/mutex.hxx>
      78             : #include <sfx2/app.hxx>
      79             : #include <sfx2/sfx.hrc>
      80             : #include <svx/fmsearch.hxx>
      81             : #include <svx/svxdlg.hxx>
      82             : #include <tools/diagnose_ex.h>
      83             : #include <osl/diagnose.h>
      84             : #include <vcl/msgbox.hxx>
      85             : #include <vcl/waitobj.hxx>
      86             : 
      87             : using namespace ::com::sun::star;
      88             : using namespace ::com::sun::star::uno;
      89             : using namespace ::com::sun::star::awt;
      90             : using namespace ::com::sun::star::sdb;
      91             : using namespace ::com::sun::star::sdbc;
      92             : using namespace ::com::sun::star::sdbcx;
      93             : using namespace ::com::sun::star::task;
      94             : using namespace ::com::sun::star::beans;
      95             : using namespace ::com::sun::star::frame;
      96             : using namespace ::com::sun::star::form;
      97             : using namespace ::com::sun::star::util;
      98             : using namespace ::com::sun::star::lang;
      99             : using namespace ::com::sun::star::container;
     100             : using namespace ::dbtools;
     101             : using namespace ::comphelper;
     102             : using namespace ::svt;
     103             : 
     104             : #define HANDLE_SQL_ERRORS( action, successflag, context, message )          \
     105             :     try                                                                     \
     106             :     {                                                                       \
     107             :         successflag = sal_False;                                            \
     108             :         action;                                                             \
     109             :         successflag = sal_True;                                             \
     110             :     }                                                                       \
     111             :     catch(SQLException& e)                                                  \
     112             :     {                                                                       \
     113             :         SQLException aError = ::dbtools::prependErrorInfo(e, *this, context); \
     114             :         ::com::sun::star::sdb::SQLErrorEvent aEvent;                        \
     115             :         aEvent.Reason <<= aError;                                           \
     116             :         errorOccured(aEvent);                                               \
     117             :     }                                                                       \
     118             :     catch(Exception&)                                                       \
     119             :     {                                                                       \
     120             :         DBG_UNHANDLED_EXCEPTION();                                          \
     121             :     }                                                                       \
     122             : 
     123             : #define DO_SAFE( action, message ) try { action; } catch(Exception&) { SAL_WARN("dbaccess.ui",message); } ;
     124             : 
     125             : //..................................................................
     126             : namespace dbaui
     127             : {
     128             : //..................................................................
     129             : 
     130             : //==================================================================
     131             : // OParameterContinuation
     132             : //==================================================================
     133           0 : class OParameterContinuation : public OInteraction< XInteractionSupplyParameters >
     134             : {
     135             :     Sequence< PropertyValue >       m_aValues;
     136             : 
     137             : public:
     138           0 :     OParameterContinuation() { }
     139             : 
     140           0 :     Sequence< PropertyValue >   getValues() const { return m_aValues; }
     141             : 
     142             : // XInteractionSupplyParameters
     143             :     virtual void SAL_CALL setParameters( const Sequence< PropertyValue >& _rValues ) throw(RuntimeException);
     144             : };
     145             : 
     146             : //------------------------------------------------------------------
     147           0 : void SAL_CALL OParameterContinuation::setParameters( const Sequence< PropertyValue >& _rValues ) throw(RuntimeException)
     148             : {
     149           0 :     m_aValues = _rValues;
     150           0 : }
     151             : 
     152             : 
     153             : //==============================================================================
     154             : // a helper class implementing a runtime::XFormController, will be aggregated by SbaXDataBrowserController
     155             : // (we can't derive from XFormController as it's base class is XTabController and the XTabController::getModel collides
     156             : // with the XController::getModel implemented in our base class SbaXDataBrowserController)
     157             : class SbaXDataBrowserController::FormControllerImpl
     158             :     : public ::cppu::WeakAggImplHelper2< ::com::sun::star::form::runtime::XFormController,
     159             :                                          ::com::sun::star::frame::XFrameActionListener >
     160             : {
     161             :     friend class SbaXDataBrowserController;
     162             :     ::cppu::OInterfaceContainerHelper   m_aActivateListeners;
     163             :     SbaXDataBrowserController*          m_pOwner;
     164             : 
     165             : public:
     166             :     FormControllerImpl(SbaXDataBrowserController* pOwner);
     167             : 
     168             :     // XFormController
     169             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations > SAL_CALL getFormOperations() throw (::com::sun::star::uno::RuntimeException);
     170             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >  SAL_CALL getCurrentControl(void) throw( ::com::sun::star::uno::RuntimeException );
     171             :     virtual void SAL_CALL addActivateListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( ::com::sun::star::uno::RuntimeException );
     172             :     virtual void SAL_CALL removeActivateListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( ::com::sun::star::uno::RuntimeException );
     173             :     virtual void SAL_CALL addChildController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _ChildController ) throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException );
     174             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormControllerContext > SAL_CALL getContext() throw (::com::sun::star::uno::RuntimeException);
     175             :     virtual void SAL_CALL setContext( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormControllerContext >& _context ) throw (::com::sun::star::uno::RuntimeException);
     176             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > SAL_CALL getInteractionHandler() throw (::com::sun::star::uno::RuntimeException);
     177             :     virtual void SAL_CALL setInteractionHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _interactionHandler ) throw (::com::sun::star::uno::RuntimeException);
     178             : 
     179             :     // XChild, base of XFormController
     180             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent(  ) throw (::com::sun::star::uno::RuntimeException);
     181             :     virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Parent ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
     182             : 
     183             :     // XComponent, base of XFormController
     184             :     virtual void SAL_CALL dispose(  ) throw (::com::sun::star::uno::RuntimeException);
     185             :     virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
     186             :     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
     187             : 
     188             :     // XIndexAccess, base of XFormController
     189             :     virtual ::sal_Int32 SAL_CALL getCount(  ) throw (::com::sun::star::uno::RuntimeException);
     190             :     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
     191             : 
     192             :     // XElementAccess, base of XIndexAccess
     193             :     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException);
     194             :     virtual ::sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException);
     195             : 
     196             :     // XEnumerationAccess, base of XElementAccess
     197             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  ) throw (::com::sun::star::uno::RuntimeException);
     198             : 
     199             :     // XModifyBroadcaster, base of XFormController
     200             :     virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
     201             :     virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
     202             : 
     203             :     // XConfirmDeleteBroadcaster, base of XFormController
     204             :     virtual void SAL_CALL addConfirmDeleteListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XConfirmDeleteListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
     205             :     virtual void SAL_CALL removeConfirmDeleteListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XConfirmDeleteListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
     206             : 
     207             :     // XSQLErrorBroadcaster, base of XFormController
     208             :     virtual void SAL_CALL addSQLErrorListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLErrorListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
     209             :     virtual void SAL_CALL removeSQLErrorListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLErrorListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
     210             : 
     211             :     // XRowSetApproveBroadcaster, base of XFormController
     212             :     virtual void SAL_CALL addRowSetApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XRowSetApproveListener >& listener ) throw (::com::sun::star::uno::RuntimeException);
     213             :     virtual void SAL_CALL removeRowSetApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XRowSetApproveListener >& listener ) throw (::com::sun::star::uno::RuntimeException);
     214             : 
     215             :     // XDatabaseParameterBroadcaster2, base of XFormController
     216             :     virtual void SAL_CALL addDatabaseParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
     217             :     virtual void SAL_CALL removeDatabaseParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
     218             : 
     219             :     // XDatabaseParameterBroadcaster, base of XDatabaseParameterBroadcaster2
     220             :     virtual void SAL_CALL addParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
     221             :     virtual void SAL_CALL removeParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
     222             : 
     223             :     // XModeSelector, base of XFormController
     224             :     virtual void SAL_CALL setMode( const OUString& aMode ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
     225             :     virtual OUString SAL_CALL getMode(  ) throw (::com::sun::star::uno::RuntimeException);
     226             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedModes(  ) throw (::com::sun::star::uno::RuntimeException);
     227             :     virtual ::sal_Bool SAL_CALL supportsMode( const OUString& aMode ) throw (::com::sun::star::uno::RuntimeException);
     228             : 
     229             :     // XTabController, base of XFormController
     230             :     virtual void SAL_CALL setModel(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabControllerModel > & Model) throw( ::com::sun::star::uno::RuntimeException );
     231             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabControllerModel >  SAL_CALL getModel(void) throw( ::com::sun::star::uno::RuntimeException );
     232             :     virtual void SAL_CALL setContainer(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > & _Container) throw( ::com::sun::star::uno::RuntimeException );
     233             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer >  SAL_CALL getContainer(void) throw( ::com::sun::star::uno::RuntimeException );
     234             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >  > SAL_CALL getControls(void) throw( ::com::sun::star::uno::RuntimeException );
     235             :     virtual void SAL_CALL autoTabOrder(void) throw( ::com::sun::star::uno::RuntimeException );
     236             :     virtual void SAL_CALL activateTabOrder(void) throw( ::com::sun::star::uno::RuntimeException );
     237             :     virtual void SAL_CALL activateFirst(void) throw( ::com::sun::star::uno::RuntimeException );
     238             :     virtual void SAL_CALL activateLast(void) throw( ::com::sun::star::uno::RuntimeException );
     239             : 
     240             :     // XFrameActionListener
     241             :     virtual void SAL_CALL frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException );
     242             : 
     243             :     // XEventListener
     244             :     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
     245             : 
     246             : protected:
     247             :     ~FormControllerImpl();
     248             : };
     249             : 
     250             : 
     251             : DBG_NAME(FormControllerImpl)
     252             : //------------------------------------------------------------------
     253           1 : SbaXDataBrowserController::FormControllerImpl::FormControllerImpl(SbaXDataBrowserController* _pOwner)
     254           1 :     :m_aActivateListeners(_pOwner->getMutex())
     255           2 :     ,m_pOwner(_pOwner)
     256             : {
     257             :     DBG_CTOR(FormControllerImpl,NULL);
     258             : 
     259             :     OSL_ENSURE(m_pOwner, "SbaXDataBrowserController::FormControllerImpl::FormControllerImpl : invalid Owner !");
     260           1 : }
     261             : 
     262             : //------------------------------------------------------------------
     263           2 : SbaXDataBrowserController::FormControllerImpl::~FormControllerImpl()
     264             : {
     265             : 
     266             :     DBG_DTOR(FormControllerImpl,NULL);
     267           2 : }
     268             : 
     269             : //------------------------------------------------------------------
     270           0 : Reference< runtime::XFormOperations > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getFormOperations() throw (RuntimeException)
     271             : {
     272             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::getFormOperations: not supported!" );
     273           0 :     return NULL;
     274             : }
     275             : 
     276             : //------------------------------------------------------------------
     277           0 : Reference< ::com::sun::star::awt::XControl >  SbaXDataBrowserController::FormControllerImpl::getCurrentControl(void) throw( RuntimeException )
     278             : {
     279           0 :     return m_pOwner->getBrowserView() ? m_pOwner->getBrowserView()->getGridControl() : Reference< ::com::sun::star::awt::XControl > ();
     280             : }
     281             : 
     282             : //------------------------------------------------------------------
     283           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addActivateListener(const Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( RuntimeException )
     284             : {
     285           0 :     m_aActivateListeners.addInterface(l);
     286           0 : }
     287             : 
     288             : //------------------------------------------------------------------
     289           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeActivateListener(const Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( RuntimeException )
     290             : {
     291           0 :     m_aActivateListeners.removeInterface(l);
     292           0 : }
     293             : 
     294             : //------------------------------------------------------------------
     295           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addChildController( const Reference< runtime::XFormController >& /*_ChildController*/ ) throw( RuntimeException, IllegalArgumentException )
     296             : {
     297             :     // not supported
     298           0 :     throw IllegalArgumentException( OUString(), *this, 1 );
     299             : }
     300             : 
     301             : //------------------------------------------------------------------
     302           0 : Reference< runtime::XFormControllerContext > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getContext() throw (RuntimeException)
     303             : {
     304             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::getContext: no support!!" );
     305           0 :     return NULL;
     306             : }
     307             : 
     308             : //------------------------------------------------------------------
     309           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setContext( const Reference< runtime::XFormControllerContext >& /*_context*/ ) throw (RuntimeException)
     310             : {
     311             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::setContext: no support!!" );
     312           0 : }
     313             : 
     314             : //------------------------------------------------------------------
     315           0 : Reference< XInteractionHandler > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getInteractionHandler() throw (RuntimeException)
     316             : {
     317             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::getInteractionHandler: no support!!" );
     318           0 :     return NULL;
     319             : }
     320             : 
     321             : //------------------------------------------------------------------
     322           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setInteractionHandler( const Reference< XInteractionHandler >& /*_interactionHandler*/ ) throw (RuntimeException)
     323             : {
     324             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::setInteractionHandler: no support!!" );
     325           0 : }
     326             : 
     327             : //------------------------------------------------------------------
     328           0 : Reference< XInterface > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getParent(  ) throw (RuntimeException)
     329             : {
     330             :     // don't have any parent form controllers
     331           0 :     return NULL;
     332             : }
     333             : 
     334             : //------------------------------------------------------------------
     335           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setParent( const Reference< XInterface >& /*Parent*/ ) throw (NoSupportException, RuntimeException)
     336             : {
     337           0 :     throw NoSupportException( OUString(), *this );
     338             : }
     339             : 
     340             : //------------------------------------------------------------------
     341           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::dispose(  ) throw (RuntimeException)
     342             : {
     343             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::dispose: no, you do *not* want to do this!" );
     344           0 : }
     345             : 
     346             : //------------------------------------------------------------------
     347           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addEventListener( const Reference< XEventListener >& /*xListener*/ ) throw (RuntimeException)
     348             : {
     349             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addEventListener: no support!!" );
     350           0 : }
     351             : 
     352             : //------------------------------------------------------------------
     353           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeEventListener( const Reference< XEventListener >& /*aListener*/ ) throw (RuntimeException)
     354             : {
     355             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeEventListener: no support!!" );
     356           0 : }
     357             : 
     358             : //------------------------------------------------------------------
     359           0 : ::sal_Int32 SAL_CALL SbaXDataBrowserController::FormControllerImpl::getCount(  ) throw (RuntimeException)
     360             : {
     361             :     // no sub controllers, never
     362           0 :     return 0;
     363             : }
     364             : 
     365             : //------------------------------------------------------------------
     366           0 : Any SAL_CALL SbaXDataBrowserController::FormControllerImpl::getByIndex( ::sal_Int32 /*Index*/ ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
     367             : {
     368             :     // no sub controllers, never
     369           0 :     throw IndexOutOfBoundsException( OUString(), *this );
     370             : }
     371             : 
     372             : //------------------------------------------------------------------
     373           0 : Type SAL_CALL SbaXDataBrowserController::FormControllerImpl::getElementType(  ) throw (RuntimeException)
     374             : {
     375           0 :     return ::cppu::UnoType< runtime::XFormController >::get();
     376             : }
     377             : 
     378             : //------------------------------------------------------------------
     379           0 : ::sal_Bool SAL_CALL SbaXDataBrowserController::FormControllerImpl::hasElements(  ) throw (RuntimeException)
     380             : {
     381             :     // no sub controllers, never
     382           0 :     return false;
     383             : }
     384             : 
     385             : //------------------------------------------------------------------
     386           0 : Reference< XEnumeration > SAL_CALL SbaXDataBrowserController::FormControllerImpl::createEnumeration(  ) throw (RuntimeException)
     387             : {
     388           0 :     return new ::comphelper::OEnumerationByIndex( this );
     389             : }
     390             : 
     391             : //------------------------------------------------------------------
     392           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addModifyListener( const Reference< XModifyListener >& /*_Listener*/ ) throw (RuntimeException)
     393             : {
     394             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addModifyListener: no support!" );
     395           0 : }
     396             : 
     397             : //------------------------------------------------------------------
     398           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeModifyListener( const Reference< XModifyListener >& /*_Listener*/ ) throw (RuntimeException)
     399             : {
     400             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeModifyListener: no support!" );
     401           0 : }
     402             : 
     403             : //------------------------------------------------------------------
     404           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addConfirmDeleteListener( const Reference< XConfirmDeleteListener >& /*_Listener*/ ) throw (RuntimeException)
     405             : {
     406             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addConfirmDeleteListener: no support!" );
     407           0 : }
     408             : 
     409             : //------------------------------------------------------------------
     410           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeConfirmDeleteListener( const Reference< XConfirmDeleteListener >& /*_Listener*/ ) throw (RuntimeException)
     411             : {
     412             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeConfirmDeleteListener: no support!" );
     413           0 : }
     414             : 
     415             : //------------------------------------------------------------------
     416           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addSQLErrorListener( const Reference< XSQLErrorListener >& /*_Listener*/ ) throw (RuntimeException)
     417             : {
     418             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addSQLErrorListener: no support!" );
     419           0 : }
     420             : 
     421             : //------------------------------------------------------------------
     422           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeSQLErrorListener( const Reference< XSQLErrorListener >& /*_Listener*/ ) throw (RuntimeException)
     423             : {
     424             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeSQLErrorListener: no support!" );
     425           0 : }
     426             : 
     427             : //------------------------------------------------------------------
     428           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addRowSetApproveListener( const Reference< XRowSetApproveListener >& /*_Listener*/ ) throw (RuntimeException)
     429             : {
     430             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addRowSetApproveListener: no support!" );
     431           0 : }
     432             : 
     433             : //------------------------------------------------------------------
     434           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeRowSetApproveListener( const Reference< XRowSetApproveListener >& /*_Listener*/ ) throw (RuntimeException)
     435             : {
     436             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeRowSetApproveListener: no support!" );
     437           0 : }
     438             : 
     439             : //------------------------------------------------------------------
     440           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addDatabaseParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException)
     441             : {
     442             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addDatabaseParameterListener: no support!" );
     443           0 : }
     444             : 
     445             : //------------------------------------------------------------------
     446           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeDatabaseParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException)
     447             : {
     448             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeDatabaseParameterListener: no support!" );
     449           0 : }
     450             : 
     451             : //------------------------------------------------------------------
     452           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException)
     453             : {
     454             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addParameterListener: no support!" );
     455           0 : }
     456             : 
     457             : //------------------------------------------------------------------
     458           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException)
     459             : {
     460             :     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeParameterListener: no support!" );
     461           0 : }
     462             : 
     463             : //------------------------------------------------------------------
     464           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setMode( const OUString& _rMode ) throw (NoSupportException, RuntimeException)
     465             : {
     466           0 :     if ( !supportsMode( _rMode ) )
     467           0 :         throw NoSupportException();
     468           0 : }
     469             : 
     470             : //------------------------------------------------------------------
     471           0 : OUString SAL_CALL SbaXDataBrowserController::FormControllerImpl::getMode(  ) throw (RuntimeException)
     472             : {
     473           0 :     return OUString( "DataMode" );
     474             : }
     475             : 
     476             : //------------------------------------------------------------------
     477           0 : Sequence< OUString > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getSupportedModes(  ) throw (RuntimeException)
     478             : {
     479           0 :     Sequence< OUString > aModes(1);
     480           0 :     aModes[1] = OUString( "DataMode" );
     481           0 :     return aModes;
     482             : }
     483             : 
     484             : //------------------------------------------------------------------
     485           0 : ::sal_Bool SAL_CALL SbaXDataBrowserController::FormControllerImpl::supportsMode( const OUString& aMode ) throw (RuntimeException)
     486             : {
     487           0 :     return aMode.compareToAscii( "DataMode" ) == 0;
     488             : }
     489             : 
     490             : //------------------------------------------------------------------
     491           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setModel(const Reference< ::com::sun::star::awt::XTabControllerModel > & /*Model*/) throw( RuntimeException )
     492             : {
     493             :     SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::setModel : invalid call, can't change my model !");
     494           0 : }
     495             : 
     496             : //------------------------------------------------------------------
     497           0 : Reference< ::com::sun::star::awt::XTabControllerModel >  SAL_CALL SbaXDataBrowserController::FormControllerImpl::getModel(void) throw( RuntimeException )
     498             : {
     499           0 :     return Reference< XTabControllerModel >(m_pOwner->getRowSet(), UNO_QUERY);
     500             : }
     501             : 
     502             : //------------------------------------------------------------------
     503           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setContainer(const Reference< ::com::sun::star::awt::XControlContainer > & /*_Container*/) throw( RuntimeException )
     504             : {
     505             :     SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::setContainer : invalid call, can't change my container !");
     506           0 : }
     507             : 
     508             : //------------------------------------------------------------------
     509           0 : Reference< ::com::sun::star::awt::XControlContainer >  SAL_CALL SbaXDataBrowserController::FormControllerImpl::getContainer(void) throw( RuntimeException )
     510             : {
     511           0 :     if (m_pOwner->getBrowserView())
     512           0 :         return m_pOwner->getBrowserView()->getContainer();
     513           0 :     return Reference< ::com::sun::star::awt::XControlContainer > ();
     514             : }
     515             : 
     516             : //------------------------------------------------------------------
     517           0 : Sequence< Reference< ::com::sun::star::awt::XControl > > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getControls(void) throw( RuntimeException )
     518             : {
     519           0 :     if (m_pOwner->getBrowserView())
     520             :     {
     521           0 :         Reference< ::com::sun::star::awt::XControl >  xGrid = m_pOwner->getBrowserView()->getGridControl();
     522           0 :         return Sequence< Reference< ::com::sun::star::awt::XControl > >(&xGrid, 1);
     523             :     }
     524           0 :     return Sequence< Reference< ::com::sun::star::awt::XControl > >();
     525             : }
     526             : 
     527             : //------------------------------------------------------------------
     528           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::autoTabOrder(void) throw( RuntimeException )
     529             : {
     530             :     SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::autoTabOrder : nothing to do (always have only one control) !");
     531           0 : }
     532             : 
     533             : //------------------------------------------------------------------
     534           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateTabOrder(void) throw( RuntimeException )
     535             : {
     536             :     SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::activateTabOrder : nothing to do (always have only one control) !");
     537           0 : }
     538             : 
     539             : //------------------------------------------------------------------
     540           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateFirst(void) throw( RuntimeException )
     541             : {
     542           0 :     if (m_pOwner->getBrowserView())
     543           0 :         m_pOwner->getBrowserView()->getVclControl()->ActivateCell();
     544           0 : }
     545             : 
     546             : //------------------------------------------------------------------
     547           0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateLast(void) throw( RuntimeException )
     548             : {
     549           0 :     if (m_pOwner->getBrowserView())
     550           0 :         m_pOwner->getBrowserView()->getVclControl()->ActivateCell();
     551           0 : }
     552             : 
     553             : //------------------------------------------------------------------
     554           1 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::frameAction(const ::com::sun::star::frame::FrameActionEvent& /*aEvent*/) throw( RuntimeException )
     555             : {
     556           1 : }
     557             : 
     558             : //------------------------------------------------------------------
     559           1 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::disposing(const ::com::sun::star::lang::EventObject& /*Source*/) throw( RuntimeException )
     560             : {
     561             :     // nothing to do
     562             :     // we don't add ourself as listener to any broadcasters, so we are not resposible for removing us
     563           1 : }
     564             : 
     565             : //==================================================================
     566             : //= SbaXDataBrowserController
     567             : //==================================================================
     568             : //------------------------------------------------------------------
     569           0 : Sequence< Type > SAL_CALL SbaXDataBrowserController::getTypes(  ) throw (RuntimeException)
     570             : {
     571             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::getTypes" );
     572             :     return ::comphelper::concatSequences(
     573             :         SbaXDataBrowserController_Base::getTypes(),
     574           0 :         m_pFormControllerImpl->getTypes()
     575           0 :     );
     576             : }
     577             : 
     578             : //------------------------------------------------------------------
     579           0 : Sequence< sal_Int8 > SAL_CALL SbaXDataBrowserController::getImplementationId(  ) throw (RuntimeException)
     580             : {
     581             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::getImplementationId" );
     582             :     static ::cppu::OImplementationId * pId = 0;
     583           0 :     if (! pId)
     584             :     {
     585           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     586           0 :         if (! pId)
     587             :         {
     588           0 :             static ::cppu::OImplementationId aId;
     589           0 :             pId = &aId;
     590           0 :         }
     591             :     }
     592           0 :     return pId->getImplementationId();
     593             : }
     594             : 
     595             : //------------------------------------------------------------------
     596         113 : Any SAL_CALL SbaXDataBrowserController::queryInterface(const Type& _rType) throw (RuntimeException)
     597             : {
     598             :     // check for our additional interfaces
     599         113 :     Any aRet = SbaXDataBrowserController_Base::queryInterface(_rType);
     600             : 
     601             :     // check for our aggregate (implementing the XFormController)
     602         113 :     if (!aRet.hasValue())
     603          10 :         aRet = m_xFormControllerImpl->queryAggregation(_rType);
     604             : 
     605             :     // no more to offer
     606         113 :     return aRet;
     607             : }
     608             : 
     609             : DBG_NAME(SbaXDataBrowserController)
     610             : //------------------------------------------------------------------------------
     611           1 : SbaXDataBrowserController::SbaXDataBrowserController(const Reference< ::com::sun::star::uno::XComponentContext >& _rM)
     612             :     :SbaXDataBrowserController_Base(_rM)
     613             :     ,m_nRowSetPrivileges(0)
     614             :     ,m_pClipbordNotifier( NULL )
     615             :     ,m_aAsyncGetCellFocus(LINK(this, SbaXDataBrowserController, OnAsyncGetCellFocus))
     616             :     ,m_aAsyncDisplayError( LINK( this, SbaXDataBrowserController, OnAsyncDisplayError ) )
     617             :     ,m_sStateSaveRecord(ModuleRes(RID_STR_SAVE_CURRENT_RECORD))
     618             :     ,m_sStateUndoRecord(ModuleRes(RID_STR_UNDO_MODIFY_RECORD))
     619             :     ,m_sModuleIdentifier( OUString( "com.sun.star.sdb.DataSourceBrowser" ) )
     620             :     ,m_pFormControllerImpl(NULL)
     621             :     ,m_nFormActionNestingLevel(0)
     622             :     ,m_bLoadCanceled( sal_False )
     623           1 :     ,m_bCannotSelectUnfiltered( true )
     624             : {
     625             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::SbaXDataBrowserController" );
     626             :     DBG_CTOR(SbaXDataBrowserController,NULL);
     627             : 
     628             :     // create the form controller aggregate
     629           1 :     ::comphelper::increment(m_refCount);
     630             :     {
     631           1 :         m_pFormControllerImpl = new FormControllerImpl(this);
     632           1 :         m_xFormControllerImpl = m_pFormControllerImpl;
     633           1 :         m_xFormControllerImpl->setDelegator(*this);
     634             :     }
     635           1 :     ::comphelper::decrement(m_refCount);
     636             : 
     637           1 :     m_aInvalidateClipboard.SetTimeoutHdl(LINK(this, SbaXDataBrowserController, OnInvalidateClipboard));
     638           1 :     m_aInvalidateClipboard.SetTimeout(300);
     639           1 : }
     640             : 
     641             : //------------------------------------------------------------------------------
     642           2 : SbaXDataBrowserController::~SbaXDataBrowserController()
     643             : {
     644             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::~SbaXDataBrowserController" );
     645             :     //  deleteView();
     646             :     // release the aggregated form controller
     647           1 :     if (m_xFormControllerImpl.is())
     648             :     {
     649           1 :         Reference< XInterface >  xEmpty;
     650           1 :         m_xFormControllerImpl->setDelegator(xEmpty);
     651             :     }
     652             : 
     653             :     DBG_DTOR(SbaXDataBrowserController,NULL);
     654           1 : }
     655             : 
     656             : // -----------------------------------------------------------------------
     657           1 : void SbaXDataBrowserController::startFrameListening( const Reference< XFrame >& _rxFrame )
     658             : {
     659             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::startFrameListening" );
     660           1 :     SbaXDataBrowserController_Base::startFrameListening( _rxFrame );
     661             : 
     662           1 :     Reference< XFrameActionListener >   xAggListener;
     663           1 :     if ( m_xFormControllerImpl.is() )
     664           1 :         m_xFormControllerImpl->queryAggregation( XFrameActionListener::static_type() ) >>= xAggListener;
     665             : 
     666           1 :     if ( _rxFrame.is() && xAggListener.is() )
     667           1 :         _rxFrame->addFrameActionListener( xAggListener );
     668           1 : }
     669             : 
     670             : // -----------------------------------------------------------------------
     671           2 : void SbaXDataBrowserController::stopFrameListening( const Reference< XFrame >& _rxFrame )
     672             : {
     673             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::stopFrameListening" );
     674           2 :     SbaXDataBrowserController_Base::stopFrameListening( _rxFrame );
     675             : 
     676           2 :     Reference< XFrameActionListener >   xAggListener;
     677           2 :     if ( m_xFormControllerImpl.is() )
     678           2 :         m_xFormControllerImpl->queryAggregation( XFrameActionListener::static_type() ) >>= xAggListener;
     679             : 
     680           2 :     if ( _rxFrame.is() && xAggListener.is() )
     681           1 :         _rxFrame->removeFrameActionListener( xAggListener );
     682           2 : }
     683             : 
     684             : // -----------------------------------------------------------------------------
     685           2 : void SbaXDataBrowserController::onStartLoading( const Reference< XLoadable >& _rxLoadable )
     686             : {
     687           2 :     m_bLoadCanceled = sal_False;
     688           2 :     m_bCannotSelectUnfiltered = false;
     689             : 
     690           2 :     Reference< XWarningsSupplier > xWarnings( _rxLoadable, UNO_QUERY );
     691           2 :     if ( xWarnings.is() )
     692           2 :         xWarnings->clearWarnings();
     693           2 : }
     694             : 
     695             : // -----------------------------------------------------------------------------
     696           0 : void SbaXDataBrowserController::impl_checkForCannotSelectUnfiltered( const SQLExceptionInfo& _rError )
     697             : {
     698           0 :     ::connectivity::SQLError aError( getORB() );
     699           0 :     ::connectivity::ErrorCode nErrorCode( aError.getErrorCode( ErrorCondition::DATA_CANNOT_SELECT_UNFILTERED ) );
     700           0 :     if ( ((const SQLException*)_rError)->ErrorCode == nErrorCode )
     701             :     {
     702           0 :         m_bCannotSelectUnfiltered = true;
     703           0 :         InvalidateFeature( ID_BROWSER_FILTERCRIT );
     704           0 :     }
     705           0 : }
     706             : 
     707             : // -----------------------------------------------------------------------------
     708           2 : sal_Bool SbaXDataBrowserController::reloadForm( const Reference< XLoadable >& _rxLoadable )
     709             : {
     710             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::reloadForm" );
     711           2 :     WaitObject aWO(getBrowserView());
     712             : 
     713           2 :     onStartLoading( _rxLoadable );
     714             : 
     715           4 :     FormErrorHelper aReportError(this);
     716           2 :     if (_rxLoadable->isLoaded())
     717           0 :         _rxLoadable->reload();
     718             :     else
     719           2 :         _rxLoadable->load();
     720             : 
     721           2 :     m_xParser.clear();
     722           4 :     const Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
     723           2 :     if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)))
     724           2 :         xFormSet->getPropertyValue(PROPERTY_SINGLESELECTQUERYCOMPOSER) >>= m_xParser;
     725             : #if 0
     726             :     {
     727             :         const Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY );
     728             :         const Reference< XSingleSelectQueryAnalyzer > xAnalyzer( xRowSetProps->getPropertyValue( PROPERTY_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY );
     729             :         if ( xAnalyzer.is() )
     730             :         {
     731             :             const Reference< XIndexAccess > xOrderColumns( xAnalyzer->getOrderColumns(), UNO_SET_THROW );
     732             :             const sal_Int32 nOrderColumns( xOrderColumns->getCount() );
     733             :             for ( sal_Int32 c=0; c<nOrderColumns; ++c )
     734             :             {
     735             :                 const Reference< XPropertySet > xOrderColumn( xOrderColumns->getByIndex(c), UNO_QUERY_THROW );
     736             :                 OUString sColumnName;
     737             :                 OSL_VERIFY( xOrderColumn->getPropertyValue( PROPERTY_NAME ) >>= sColumnName);
     738             :                 OUString sTableName;
     739             :                 OSL_VERIFY( xOrderColumn->getPropertyValue( PROPERTY_TABLENAME ) >>= sTableName);
     740             :                 (void)sColumnName;
     741             :                 (void)sTableName;
     742             :             }
     743             :         }
     744             :     }
     745             : #endif
     746             : 
     747           4 :     Reference< XWarningsSupplier > xWarnings( _rxLoadable, UNO_QUERY );
     748           2 :     if ( xWarnings.is() )
     749             :     {
     750             :         try
     751             :         {
     752           2 :             SQLExceptionInfo aInfo( xWarnings->getWarnings() );
     753           2 :             if ( aInfo.isValid() )
     754             :             {
     755           0 :                 showError( aInfo );
     756           0 :                 impl_checkForCannotSelectUnfiltered( aInfo );
     757           2 :             }
     758             :         }
     759           0 :         catch(const SQLException& e)
     760             :         {
     761             :             (void)e;
     762             :         }
     763             :     }
     764             : 
     765           4 :     return _rxLoadable->isLoaded();
     766             : }
     767             : 
     768             : // -----------------------------------------------------------------------------
     769           2 : void SbaXDataBrowserController::initFormatter()
     770             : {
     771             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::initFormatter" );
     772             :     // ---------------------------------------------------------------
     773             :     // create a formatter working with the connections format supplier
     774           2 :     Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xSupplier(::dbtools::getNumberFormats(::dbtools::getConnection(m_xRowSet), sal_True, getORB()));
     775             : 
     776           2 :     if(xSupplier.is())
     777             :     {
     778             :         // create a new formatter
     779           4 :         m_xFormatter = Reference< util::XNumberFormatter > (
     780           2 :             util::NumberFormatter::create(getORB()), UNO_QUERY_THROW);
     781           2 :         m_xFormatter->attachNumberFormatsSupplier(xSupplier);
     782             :     }
     783             :     else // clear the formatter
     784           0 :         m_xFormatter = NULL;
     785           2 : }
     786             : // -----------------------------------------------------------------------------
     787           1 : void SbaXDataBrowserController::describeSupportedFeatures()
     788             : {
     789             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::describeSupportedFeatures" );
     790           1 :     SbaXDataBrowserController_Base::describeSupportedFeatures();
     791           1 :     implDescribeSupportedFeature( ".uno:FormSlots/undoRecord",      ID_BROWSER_UNDORECORD,  CommandGroup::CONTROLS );
     792           1 :     implDescribeSupportedFeature( ".uno:FormController/undoRecord", ID_BROWSER_UNDORECORD,  CommandGroup::CONTROLS );
     793           1 :     implDescribeSupportedFeature( ".uno:RecUndo",                   ID_BROWSER_UNDORECORD,  CommandGroup::CONTROLS );
     794           1 :     implDescribeSupportedFeature( ".uno:FormSlots/saveRecord",      ID_BROWSER_SAVERECORD,  CommandGroup::CONTROLS );
     795           1 :     implDescribeSupportedFeature( ".uno:FormController/saveRecord", ID_BROWSER_SAVERECORD,  CommandGroup::CONTROLS );
     796           1 :     implDescribeSupportedFeature( ".uno:RecSave",                   ID_BROWSER_SAVERECORD,  CommandGroup::CONTROLS );
     797           1 :     implDescribeSupportedFeature( ".uno:Save",                      ID_BROWSER_SAVERECORD,  CommandGroup::DOCUMENT );
     798           1 :     implDescribeSupportedFeature( ".uno:RecSearch",                 SID_FM_SEARCH,          CommandGroup::CONTROLS );
     799           1 :     implDescribeSupportedFeature( ".uno:AutoFilter",                SID_FM_AUTOFILTER,      CommandGroup::CONTROLS );
     800           1 :     implDescribeSupportedFeature( ".uno:Refresh",                   SID_FM_REFRESH,         CommandGroup::CONTROLS );
     801           1 :     implDescribeSupportedFeature( ".uno:OrderCrit",                 SID_FM_ORDERCRIT,       CommandGroup::CONTROLS );
     802           1 :     implDescribeSupportedFeature( ".uno:RemoveFilterSort",          SID_FM_REMOVE_FILTER_SORT,CommandGroup::CONTROLS );
     803           1 :     implDescribeSupportedFeature( ".uno:FormFiltered",              SID_FM_FORM_FILTERED,   CommandGroup::CONTROLS );
     804           1 :     implDescribeSupportedFeature( ".uno:FilterCrit",                SID_FM_FILTERCRIT,      CommandGroup::CONTROLS );
     805           1 :     implDescribeSupportedFeature( ".uno:Sortup",                    ID_BROWSER_SORTUP,      CommandGroup::CONTROLS );
     806           1 :     implDescribeSupportedFeature( ".uno:SortDown",                  ID_BROWSER_SORTDOWN,    CommandGroup::CONTROLS );
     807           1 :     implDescribeSupportedFeature( ".uno:FormSlots/deleteRecord",    SID_FM_DELETEROWS,      CommandGroup::EDIT );
     808           1 :     implDescribeSupportedFeature( ".uno:FormSlots/insertRecord",    ID_BROWSER_INSERT_ROW,  CommandGroup::INSERT );
     809           1 : }
     810             : //------------------------------------------------------------------------------
     811           1 : sal_Bool SbaXDataBrowserController::Construct(Window* pParent)
     812             : {
     813             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::Construct" );
     814             :     // ---------------------------------------------
     815             :     // create/initialize the form and the grid model
     816           1 :     m_xRowSet = CreateForm();
     817           1 :     if (!m_xRowSet.is())
     818           0 :         return sal_False;
     819             : 
     820           1 :     m_xColumnsSupplier.set(m_xRowSet,UNO_QUERY);
     821           1 :     m_xLoadable.set(m_xRowSet,UNO_QUERY);
     822             : 
     823           1 :     Reference< XPropertySet > xFormProperties( m_xRowSet, UNO_QUERY );
     824           1 :     if ( !InitializeForm( xFormProperties ) )
     825           0 :         return sal_False;
     826             : 
     827           1 :     m_xGridModel = CreateGridModel();
     828           1 :     if (!m_xGridModel.is())
     829           0 :         return sal_False;
     830             : 
     831             :     // set the formatter if available
     832           1 :     initFormatter();
     833             :     // ---------------------------------------------------------------
     834             : 
     835             :     // we want to have a grid with a "flat" border
     836           2 :     Reference< XPropertySet >  xGridSet(m_xGridModel, UNO_QUERY);
     837           1 :     if ( xGridSet.is() )
     838           1 :         xGridSet->setPropertyValue(PROPERTY_BORDER, makeAny((sal_Int16)2));
     839             : 
     840             :     // ----------
     841             :     // marry them
     842           2 :     Reference< ::com::sun::star::container::XNameContainer >  xNameCont(m_xRowSet, UNO_QUERY);
     843             :     {
     844           1 :         OUString sText(ModuleRes(STR_DATASOURCE_GRIDCONTROL_NAME));
     845           1 :         xNameCont->insertByName(OUString(sText), makeAny(m_xGridModel));
     846             :     }
     847             : 
     848             :     // ---------------
     849             :     // create the view
     850           1 :     setView( * new UnoDataBrowserView( pParent, *this, getORB() ) );
     851           1 :     if (!getBrowserView())
     852           0 :         return sal_False;
     853             : 
     854             :     // late construction
     855           1 :     sal_Bool bSuccess = sal_False;
     856             :     try
     857             :     {
     858           1 :         getBrowserView()->Construct(getControlModel());
     859           1 :         bSuccess = sal_True;
     860             :     }
     861           0 :     catch(SQLException&)
     862             :     {
     863             :     }
     864           0 :     catch(Exception&)
     865             :     {
     866             :         SAL_WARN("dbaccess.ui","SbaXDataBrowserController::Construct : the construction of UnoDataBrowserView failed !");
     867             :     }
     868             : 
     869           1 :     if (!bSuccess)
     870             :     {
     871             :         //  deleteView();
     872           0 :         return sal_False;
     873             :     }
     874             : 
     875             :     // now that we have a view we can create the clipboard listener
     876           1 :     m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() );
     877           1 :     m_aSystemClipboard.StartClipboardListening( );
     878             : 
     879           1 :     m_pClipbordNotifier = new TransferableClipboardListener( LINK( this, SbaXDataBrowserController, OnClipboardChanged ) );
     880           1 :     m_pClipbordNotifier->acquire();
     881           1 :     m_pClipbordNotifier->AddRemoveListener( getView(), sal_True );
     882             : 
     883             :     // this call create the toolbox
     884           1 :     SbaXDataBrowserController_Base::Construct(pParent);
     885             : 
     886           1 :     getBrowserView()->Show();
     887             : 
     888             :     // set the callbacks for the grid control
     889           1 :     SbaGridControl* pVclGrid = getBrowserView()->getVclControl();
     890             :     OSL_ENSURE(pVclGrid, "SbaXDataBrowserController::Construct : have no VCL control !");
     891           1 :     pVclGrid->SetMasterListener(this);
     892             : 
     893             :     // --------------------------
     894             :     // add listeners ...
     895             : 
     896             :     // ... to the form model
     897           2 :     Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
     898           1 :     if (xFormSet.is())
     899             :     {
     900           1 :         xFormSet->addPropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
     901           1 :         xFormSet->addPropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
     902           1 :         xFormSet->addPropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
     903           1 :         xFormSet->addPropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
     904           1 :         xFormSet->addPropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
     905           1 :         xFormSet->addPropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
     906           1 :         xFormSet->addPropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
     907           1 :         xFormSet->addPropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
     908             :     }
     909           2 :     Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster >  xFormError(getRowSet(), UNO_QUERY);
     910           1 :     if (xFormError.is())
     911           1 :         xFormError->addSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
     912             : 
     913           1 :     if (m_xLoadable.is())
     914           1 :         m_xLoadable->addLoadListener(this);
     915             : 
     916           2 :     Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster >  xFormParameter(getRowSet(), UNO_QUERY);
     917           1 :     if (xFormParameter.is())
     918           1 :         xFormParameter->addParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this);
     919             : 
     920           1 :     addModelListeners(getControlModel());
     921           1 :     addControlListeners(getBrowserView()->getGridControl());
     922             : 
     923             :     // -------------
     924             :     // load the form
     925           2 :     return LoadForm();
     926             : }
     927             : 
     928             : //------------------------------------------------------------------------------
     929           1 : sal_Bool SbaXDataBrowserController::LoadForm()
     930             : {
     931             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::LoadForm" );
     932           1 :     reloadForm( m_xLoadable );
     933           1 :     return sal_True;
     934             : }
     935             : //------------------------------------------------------------------------------
     936          31 : void SbaXDataBrowserController::AddColumnListener(const Reference< XPropertySet > & /*xCol*/)
     937             : {
     938             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::AddColumnListener" );
     939             :     // we're not interested in any column properties ...
     940          31 : }
     941             : 
     942             : //------------------------------------------------------------------------------
     943          31 : void SbaXDataBrowserController::RemoveColumnListener(const Reference< XPropertySet > & /*xCol*/)
     944             : {
     945             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::RemoveColumnListener" );
     946          31 : }
     947             : //------------------------------------------------------------------------------
     948           1 : Reference< XRowSet >  SbaXDataBrowserController::CreateForm()
     949             : {
     950             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::CreateForm" );
     951             :     return Reference< XRowSet > (
     952           2 :       getORB()->getServiceManager()->createInstanceWithContext("com.sun.star.form.component.Form", getORB()),
     953           2 :       UNO_QUERY);
     954             : }
     955             : 
     956             : //------------------------------------------------------------------------------
     957           1 : Reference< ::com::sun::star::form::XFormComponent >  SbaXDataBrowserController::CreateGridModel()
     958             : {
     959             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::CreateGridModel" );
     960             :     return Reference< ::com::sun::star::form::XFormComponent > (
     961           2 :       getORB()->getServiceManager()->createInstanceWithContext("com.sun.star.form.component.GridControl", getORB()),
     962           2 :       UNO_QUERY);
     963             : }
     964             : 
     965             : // -------------------------------------------------------------------------
     966           1 : void SbaXDataBrowserController::addModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
     967             : {
     968             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::addModelListeners" );
     969             :     // ... all the grid columns
     970           1 :     addColumnListeners(_xGridControlModel);
     971             : 
     972             :     // (we are interested in all columns the grid has (and only in these) so we have to listen to the container, too)
     973           1 :     Reference< ::com::sun::star::container::XContainer >  xColContainer(_xGridControlModel, UNO_QUERY);
     974           1 :     if (xColContainer.is())
     975           1 :         xColContainer->addContainerListener((::com::sun::star::container::XContainerListener*)this);
     976             : 
     977           2 :     Reference< ::com::sun::star::form::XReset >  xReset(_xGridControlModel, UNO_QUERY);
     978           1 :     if (xReset.is())
     979           2 :         xReset->addResetListener((::com::sun::star::form::XResetListener*)this);
     980           1 : }
     981             : 
     982             : // -------------------------------------------------------------------------
     983           1 : void SbaXDataBrowserController::removeModelListeners(const Reference< XControlModel > & _xGridControlModel)
     984             : {
     985             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::removeModelListeners" );
     986             :     // every single column model
     987           1 :     Reference< XIndexContainer >  xColumns(_xGridControlModel, UNO_QUERY);
     988           1 :     if (xColumns.is())
     989             :     {
     990           1 :         sal_Int32 nCount = xColumns->getCount();
     991          32 :         for (sal_uInt16 i=0; i < nCount; ++i)
     992             :         {
     993          31 :             Reference< XPropertySet >  xCol(xColumns->getByIndex(i),UNO_QUERY);
     994          31 :             RemoveColumnListener(xCol);
     995          31 :         }
     996             :     }
     997             : 
     998           2 :     Reference< XContainer >  xColContainer(_xGridControlModel, UNO_QUERY);
     999           1 :     if (xColContainer.is())
    1000           1 :         xColContainer->removeContainerListener( this );
    1001             : 
    1002           2 :     Reference< XReset >  xReset(_xGridControlModel, UNO_QUERY);
    1003           1 :     if (xReset.is())
    1004           2 :         xReset->removeResetListener( this );
    1005           1 : }
    1006             : 
    1007             : // -------------------------------------------------------------------------
    1008           1 : void SbaXDataBrowserController::addControlListeners(const Reference< ::com::sun::star::awt::XControl > & _xGridControl)
    1009             : {
    1010             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::addControlListeners" );
    1011             :     // to ge the 'modified' for the current cell
    1012           1 :     Reference< XModifyBroadcaster >  xBroadcaster(getBrowserView()->getGridControl(), UNO_QUERY);
    1013           1 :     if (xBroadcaster.is())
    1014           1 :         xBroadcaster->addModifyListener(static_cast<XModifyListener*>(this));
    1015             : 
    1016             :     // introduce ourself as dispatch provider for the grid
    1017           2 :     Reference< XDispatchProviderInterception >  xInterception(getBrowserView()->getGridControl(), UNO_QUERY);
    1018           1 :     if (xInterception.is())
    1019           1 :         xInterception->registerDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
    1020             : 
    1021             :     // add as focus listener to the control (needed for the form controller functionality)
    1022           2 :     Reference< XWindow >  xWindow(_xGridControl, UNO_QUERY);
    1023           1 :     if (xWindow.is())
    1024           2 :         xWindow->addFocusListener(this);
    1025           1 : }
    1026             : 
    1027             : // -------------------------------------------------------------------------
    1028           1 : void SbaXDataBrowserController::removeControlListeners(const Reference< ::com::sun::star::awt::XControl > & _xGridControl)
    1029             : {
    1030             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::removeControlListeners" );
    1031           1 :     Reference< XModifyBroadcaster >  xBroadcaster(_xGridControl, UNO_QUERY);
    1032           1 :     if (xBroadcaster.is())
    1033           1 :         xBroadcaster->removeModifyListener(static_cast<XModifyListener*>(this));
    1034             : 
    1035           2 :     Reference< XDispatchProviderInterception >  xInterception(_xGridControl, UNO_QUERY);
    1036           1 :     if (xInterception.is())
    1037           1 :         xInterception->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
    1038             : 
    1039           2 :     Reference< XWindow >  xWindow(_xGridControl, UNO_QUERY);
    1040           1 :     if (xWindow.is())
    1041           2 :         xWindow->removeFocusListener(this);
    1042           1 : }
    1043             : 
    1044             : //------------------------------------------------------------------
    1045           0 : void SAL_CALL SbaXDataBrowserController::focusGained(const FocusEvent& /*e*/) throw( RuntimeException )
    1046             : {
    1047             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::focusGained" );
    1048             :     // notify our activate listeners (registered on the form controller aggregate)
    1049           0 :     EventObject aEvt(*this);
    1050           0 :     ::cppu::OInterfaceIteratorHelper aIter(m_pFormControllerImpl->m_aActivateListeners);
    1051           0 :     while (aIter.hasMoreElements())
    1052           0 :         static_cast<XFormControllerListener*>(aIter.next())->formActivated(aEvt);
    1053           0 : }
    1054             : 
    1055             : //------------------------------------------------------------------
    1056           0 : void SAL_CALL SbaXDataBrowserController::focusLost(const FocusEvent& e) throw( RuntimeException )
    1057             : {
    1058             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::focusLost" );
    1059             :     // some general checks
    1060           0 :     if (!getBrowserView() || !getBrowserView()->getGridControl().is())
    1061           0 :         return;
    1062           0 :     Reference< XVclWindowPeer >  xMyGridPeer(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
    1063           0 :     if (!xMyGridPeer.is())
    1064           0 :         return;
    1065           0 :     Reference< XWindowPeer >  xNextControlPeer(e.NextFocus, UNO_QUERY);
    1066           0 :     if (!xNextControlPeer.is())
    1067           0 :         return;
    1068             : 
    1069             :     // don't do a notification if it remains in the family (i.e. a child of the grid control gets the focus)
    1070           0 :     if (xMyGridPeer->isChild(xNextControlPeer))
    1071           0 :         return;
    1072             : 
    1073           0 :     if (xMyGridPeer == xNextControlPeer)
    1074           0 :         return;
    1075             : 
    1076             :     // notify the listeners that the "form" we represent has been deactivated
    1077           0 :     EventObject aEvt(*this);
    1078           0 :     ::cppu::OInterfaceIteratorHelper aIter(m_pFormControllerImpl->m_aActivateListeners);
    1079           0 :     while (aIter.hasMoreElements())
    1080           0 :         static_cast<XFormControllerListener*>(aIter.next())->formDeactivated(aEvt);
    1081             : 
    1082             :     // commit the changes of the grid control (as we're deactivated)
    1083           0 :     Reference< XBoundComponent >  xCommitable(getBrowserView()->getGridControl(), UNO_QUERY);
    1084           0 :     if (xCommitable.is())
    1085           0 :         xCommitable->commit();
    1086             :     else
    1087           0 :         SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::focusLost : why is my control not commitable ?");
    1088             : }
    1089             : 
    1090             : // -------------------------------------------------------------------------
    1091           0 : void SbaXDataBrowserController::disposingGridControl(const ::com::sun::star::lang::EventObject& /*Source*/)
    1092             : {
    1093             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::disposingGridControl" );
    1094           0 :     removeControlListeners(getBrowserView()->getGridControl());
    1095           0 : }
    1096             : 
    1097             : // -------------------------------------------------------------------------
    1098           0 : void SbaXDataBrowserController::disposingGridModel(const ::com::sun::star::lang::EventObject& /*Source*/)
    1099             : {
    1100             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::disposingGridModel" );
    1101           0 :     removeModelListeners(getControlModel());
    1102           0 : }
    1103             : 
    1104             : // -------------------------------------------------------------------------
    1105           0 : void SbaXDataBrowserController::disposingFormModel(const ::com::sun::star::lang::EventObject& Source)
    1106             : {
    1107             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::disposingFormModel" );
    1108           0 :     Reference< XPropertySet >  xSourceSet(Source.Source, UNO_QUERY);
    1109           0 :     if (xSourceSet.is())
    1110             :     {
    1111           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
    1112           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
    1113           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
    1114           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
    1115           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
    1116           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
    1117           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
    1118           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
    1119             :     }
    1120             : 
    1121           0 :     Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster >  xFormError(Source.Source, UNO_QUERY);
    1122           0 :     if (xFormError.is())
    1123           0 :         xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
    1124             : 
    1125           0 :     if (m_xLoadable.is())
    1126           0 :         m_xLoadable->removeLoadListener(this);
    1127             : 
    1128           0 :     Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster >  xFormParameter(Source.Source, UNO_QUERY);
    1129           0 :     if (xFormParameter.is())
    1130           0 :         xFormParameter->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this);
    1131           0 : }
    1132             : 
    1133             : // -------------------------------------------------------------------------
    1134           0 : void SbaXDataBrowserController::disposingColumnModel(const ::com::sun::star::lang::EventObject& Source)
    1135             : {
    1136             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::disposingColumnModel" );
    1137           0 :     RemoveColumnListener(Reference< XPropertySet > (Source.Source, UNO_QUERY));
    1138           0 : }
    1139             : 
    1140             : // -------------------------------------------------------------------------
    1141           1 : void SbaXDataBrowserController::disposing(const EventObject& Source) throw( RuntimeException )
    1142             : {
    1143             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::disposing" );
    1144             :     // if it's a component other than our aggregate, forward it to the aggregate
    1145           1 :     if ( m_xFormControllerImpl != Source.Source )
    1146             :     {
    1147           1 :         Reference< XEventListener > xAggListener;
    1148           1 :         m_xFormControllerImpl->queryAggregation( ::getCppuType( &xAggListener ) ) >>= xAggListener;
    1149           1 :         if ( xAggListener.is( ))
    1150           1 :             xAggListener->disposing( Source );
    1151             :     }
    1152             : 
    1153             :     // is it the grid control ?
    1154           1 :     if (getBrowserView())
    1155             :     {
    1156           1 :         Reference< ::com::sun::star::awt::XControl >  xSourceControl(Source.Source, UNO_QUERY);
    1157           1 :         if (xSourceControl == getBrowserView()->getGridControl())
    1158           0 :             disposingGridControl(Source);
    1159             :     }
    1160             : 
    1161             :     // it's model (the container of the columns) ?
    1162           1 :     if (getControlModel() == Source.Source)
    1163           0 :         disposingGridModel(Source);
    1164             : 
    1165             :     // the form's model ?
    1166           1 :     if ((getRowSet() == Source.Source))
    1167           0 :         disposingFormModel(Source);
    1168             : 
    1169             :     // from a single column model ?
    1170           1 :     Reference< XPropertySet >  xSourceSet(Source.Source, UNO_QUERY);
    1171           1 :     if (xSourceSet.is())
    1172             :     {
    1173           0 :         Reference< XPropertySetInfo >  xInfo = xSourceSet->getPropertySetInfo();
    1174             :         // we assume that columns have a Width property and all other sets we are listening to don't have
    1175           0 :         if (xInfo->hasPropertyByName(PROPERTY_WIDTH))
    1176           0 :             disposingColumnModel(Source);
    1177             :     }
    1178           1 :     SbaXDataBrowserController_Base::OGenericUnoController::disposing( Source );
    1179           1 : }
    1180             : 
    1181             : // -----------------------------------------------------------------------
    1182           0 : void SAL_CALL SbaXDataBrowserController::setIdentifier( const OUString& _Identifier ) throw (RuntimeException)
    1183             : {
    1184             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::setIdentifier" );
    1185           0 :     ::osl::MutexGuard aGuard( getMutex() );
    1186           0 :     m_sModuleIdentifier = _Identifier;
    1187           0 : }
    1188             : 
    1189             : // -----------------------------------------------------------------------
    1190           8 : OUString SAL_CALL SbaXDataBrowserController::getIdentifier(  ) throw (RuntimeException)
    1191             : {
    1192             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::getIdentifier" );
    1193           8 :     ::osl::MutexGuard aGuard( getMutex() );
    1194           8 :     return m_sModuleIdentifier;
    1195             : }
    1196             : 
    1197             : // -----------------------------------------------------------------------
    1198           4 : void SbaXDataBrowserController::propertyChange(const PropertyChangeEvent& evt) throw ( RuntimeException )
    1199             : {
    1200             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::propertyChange" );
    1201           4 :     Reference< XPropertySet >  xSource(evt.Source, UNO_QUERY);
    1202           4 :     if (!xSource.is())
    1203           4 :         return;
    1204             : 
    1205           8 :     SolarMutexGuard aGuard;
    1206             :     // the IsModified changed to sal_False ?
    1207          12 :     if  (   (evt.PropertyName.equals(PROPERTY_ISMODIFIED))
    1208          12 :         &&  (::comphelper::getBOOL(evt.NewValue) == sal_False)
    1209             :         )
    1210             :     {   // -> the current field isn't modified anymore, too
    1211           0 :         setCurrentModified( sal_False );
    1212             :     }
    1213             : 
    1214             :     // switching to a new record ?
    1215          12 :     if  (   (evt.PropertyName.equals(PROPERTY_ISNEW))
    1216          12 :         &&  (::comphelper::getBOOL(evt.NewValue) == sal_True)
    1217             :         )
    1218             :     {
    1219           0 :         if (::comphelper::getINT32(xSource->getPropertyValue(PROPERTY_ROWCOUNT)) == 0)
    1220             :             // if we're switching to a new record and didn't have any records before we need to invalidate
    1221             :             // all slots (as the cursor was invalid before the mode change and so the slots were disabled)
    1222           0 :             InvalidateAll();
    1223             :     }
    1224             : 
    1225             : 
    1226           4 :     if (evt.PropertyName.equals(PROPERTY_FILTER))
    1227             :     {
    1228           0 :         InvalidateFeature(ID_BROWSER_REMOVEFILTER);
    1229             :     }
    1230           4 :     else if (evt.PropertyName.equals(PROPERTY_HAVING_CLAUSE))
    1231             :     {
    1232           0 :         InvalidateFeature(ID_BROWSER_REMOVEFILTER);
    1233             :     }
    1234           4 :     else if (evt.PropertyName.equals(PROPERTY_ORDER))
    1235             :     {
    1236           1 :         InvalidateFeature(ID_BROWSER_REMOVEFILTER);
    1237             :     }
    1238             : 
    1239             :     // a new record count ? -> may be our search availability has changed
    1240           4 :     if (evt.PropertyName.equals(PROPERTY_ROWCOUNT))
    1241             :     {
    1242           1 :         sal_Int32 nNewValue = 0, nOldValue = 0;
    1243           1 :         evt.NewValue >>= nNewValue;
    1244           1 :         evt.OldValue >>= nOldValue;
    1245           1 :         if((nOldValue == 0 && nNewValue != 0) || (nOldValue != 0 && nNewValue == 0))
    1246           1 :             InvalidateAll();
    1247           4 :     }
    1248             : }
    1249             : 
    1250             : //------------------------------------------------------------------------
    1251           0 : void SbaXDataBrowserController::modified(const ::com::sun::star::lang::EventObject& /*aEvent*/) throw( RuntimeException )
    1252             : {
    1253             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::modified" );
    1254           0 :     setCurrentModified( sal_True );
    1255           0 : }
    1256             : 
    1257             : // -----------------------------------------------------------------------
    1258          31 : void SbaXDataBrowserController::elementInserted(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException )
    1259             : {
    1260             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::elementInserted" );
    1261             :     OSL_ENSURE(Reference< XInterface >(evt.Source, UNO_QUERY).get() == Reference< XInterface >(getControlModel(), UNO_QUERY).get(),
    1262             :         "SbaXDataBrowserController::elementInserted: where did this come from (not from the grid model)?!");
    1263          31 :     Reference< XPropertySet >  xNewColumn(evt.Element,UNO_QUERY);
    1264          31 :     if ( xNewColumn.is() )
    1265          31 :         AddColumnListener(xNewColumn);
    1266          31 : }
    1267             : 
    1268             : // -----------------------------------------------------------------------
    1269           0 : void SbaXDataBrowserController::elementRemoved(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException )
    1270             : {
    1271             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::elementRemoved" );
    1272             :     OSL_ENSURE(Reference< XInterface >(evt.Source, UNO_QUERY).get() == Reference< XInterface >(getControlModel(), UNO_QUERY).get(),
    1273             :         "SbaXDataBrowserController::elementRemoved: where did this come from (not from the grid model)?!");
    1274           0 :     Reference< XPropertySet >  xOldColumn(evt.Element,UNO_QUERY);
    1275           0 :     if ( xOldColumn.is() )
    1276           0 :         RemoveColumnListener(xOldColumn);
    1277           0 : }
    1278             : 
    1279             : // -----------------------------------------------------------------------
    1280           0 : void SbaXDataBrowserController::elementReplaced(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException )
    1281             : {
    1282             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::elementReplaced" );
    1283             :     OSL_ENSURE(Reference< XInterface >(evt.Source, UNO_QUERY).get() == Reference< XInterface >(getControlModel(), UNO_QUERY).get(),
    1284             :         "SbaXDataBrowserController::elementReplaced: where did this come from (not from the grid model)?!");
    1285           0 :     Reference< XPropertySet >  xOldColumn(evt.ReplacedElement,UNO_QUERY);
    1286           0 :     if ( xOldColumn.is() )
    1287           0 :         RemoveColumnListener(xOldColumn);
    1288             : 
    1289           0 :     Reference< XPropertySet >  xNewColumn(evt.Element,UNO_QUERY);
    1290           0 :     if ( xNewColumn.is() )
    1291           0 :         AddColumnListener(xNewColumn);
    1292           0 : }
    1293             : 
    1294             : // -----------------------------------------------------------------------
    1295           0 : sal_Bool SbaXDataBrowserController::suspend(sal_Bool /*bSuspend*/) throw( RuntimeException )
    1296             : {
    1297             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::suspend" );
    1298             : 
    1299           0 :     m_aAsyncGetCellFocus.CancelCall();
    1300           0 :     m_aAsyncDisplayError.CancelCall();
    1301           0 :     m_aAsyncInvalidateAll.CancelCall();
    1302             : 
    1303           0 :     sal_Bool bSuccess = SaveModified();
    1304           0 :     return bSuccess;
    1305             : }
    1306             : // -----------------------------------------------------------------------
    1307           1 : void SbaXDataBrowserController::disposing()
    1308             : {
    1309             :     // the base class
    1310           1 :     SbaXDataBrowserController_Base::OGenericUnoController::disposing();
    1311             : 
    1312             :     // the data source
    1313           1 :     Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
    1314           1 :     if (xFormSet.is())
    1315             :     {
    1316           1 :         xFormSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
    1317           1 :         xFormSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
    1318           1 :         xFormSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
    1319           1 :         xFormSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
    1320           1 :         xFormSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
    1321           1 :         xFormSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
    1322           1 :         xFormSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
    1323           1 :         xFormSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
    1324             :     }
    1325             : 
    1326           2 :     Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster >  xFormError(getRowSet(), UNO_QUERY);
    1327           1 :     if (xFormError.is())
    1328           1 :         xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
    1329             : 
    1330           1 :     if (m_xLoadable.is())
    1331           1 :         m_xLoadable->removeLoadListener(this);
    1332             : 
    1333           2 :     Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster >  xFormParameter(getRowSet(), UNO_QUERY);
    1334           1 :     if (xFormParameter.is())
    1335           1 :         xFormParameter->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this);
    1336             : 
    1337           1 :     removeModelListeners(getControlModel());
    1338             : 
    1339           1 :     if ( getView() && m_pClipbordNotifier  )
    1340             :     {
    1341           1 :         m_pClipbordNotifier->ClearCallbackLink();
    1342           1 :         m_pClipbordNotifier->AddRemoveListener( getView(), sal_False );
    1343           1 :         m_pClipbordNotifier->release();
    1344           1 :         m_pClipbordNotifier = NULL;
    1345             :     }
    1346             : 
    1347           1 :     if (getBrowserView())
    1348             :     {
    1349           1 :         removeControlListeners(getBrowserView()->getGridControl());
    1350             :         // don't delete explicitly, this is done by the owner (and user) of this controller (me hopes ...)
    1351           1 :         clearView();
    1352             :     }
    1353             : 
    1354           1 :     if(m_aInvalidateClipboard.IsActive())
    1355           1 :         m_aInvalidateClipboard.Stop();
    1356             : 
    1357             :     // dispose the row set
    1358             :     try
    1359             :     {
    1360           1 :         ::comphelper::disposeComponent(m_xRowSet);
    1361             : 
    1362           1 :         m_xRowSet           = NULL;
    1363           1 :         m_xColumnsSupplier  = NULL;
    1364           1 :         m_xLoadable         = NULL;
    1365             :     }
    1366           0 :     catch(Exception&)
    1367             :     {
    1368             :         DBG_UNHANDLED_EXCEPTION();
    1369             :     }
    1370           2 :     m_xParser.clear();
    1371             :         // don't dispose, just reset - it's owned by the RowSet
    1372           1 : }
    1373             : //------------------------------------------------------------------------------
    1374           1 : void SbaXDataBrowserController::frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( RuntimeException )
    1375             : {
    1376             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::frameAction" );
    1377           1 :     ::osl::MutexGuard aGuard( getMutex() );
    1378             : 
    1379           1 :     SbaXDataBrowserController_Base::frameAction( aEvent );
    1380             : 
    1381           1 :     if ( aEvent.Source == getFrame() )
    1382           1 :         switch ( aEvent.Action )
    1383             :         {
    1384             :             case FrameAction_FRAME_ACTIVATED:
    1385             :             case FrameAction_FRAME_UI_ACTIVATED:
    1386             :                 // ensure that the active cell (if any) has the focus
    1387           0 :                 m_aAsyncGetCellFocus.Call();
    1388             :                 // start the clipboard timer
    1389           0 :                 if (getBrowserView() && getBrowserView()->getVclControl() && !m_aInvalidateClipboard.IsActive())
    1390             :                 {
    1391           0 :                     m_aInvalidateClipboard.Start();
    1392           0 :                     OnInvalidateClipboard( NULL );
    1393             :                 }
    1394           0 :                 break;
    1395             :             case FrameAction_FRAME_DEACTIVATING:
    1396             :             case FrameAction_FRAME_UI_DEACTIVATING:
    1397             :                 // stop the clipboard invalidator
    1398           0 :                 if (getBrowserView() && getBrowserView()->getVclControl() && m_aInvalidateClipboard.IsActive())
    1399             :                 {
    1400           0 :                     m_aInvalidateClipboard.Stop();
    1401           0 :                     OnInvalidateClipboard( NULL );
    1402             :                 }
    1403             :                 // remove the "get cell focus"-event
    1404           0 :                 m_aAsyncGetCellFocus.CancelCall();
    1405           0 :                 break;
    1406             :             default:
    1407           1 :                 break;
    1408           1 :         }
    1409           1 : }
    1410             : 
    1411             : //------------------------------------------------------------------------------
    1412           0 : IMPL_LINK( SbaXDataBrowserController, OnAsyncDisplayError, void*, /* _pNotInterestedIn */ )
    1413             : {
    1414           0 :     if ( m_aCurrentError.isValid() )
    1415             :     {
    1416           0 :         OSQLMessageBox aDlg( getBrowserView(), m_aCurrentError );
    1417           0 :         aDlg.Execute();
    1418             :     }
    1419           0 :     return 0L;
    1420             : }
    1421             : 
    1422             : //------------------------------------------------------------------------------
    1423           0 : void SbaXDataBrowserController::errorOccured(const ::com::sun::star::sdb::SQLErrorEvent& aEvent) throw( RuntimeException )
    1424             : {
    1425             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::errorOccurred" );
    1426           0 :     ::osl::MutexGuard aGuard( getMutex() );
    1427             : 
    1428           0 :     SQLExceptionInfo aInfo( aEvent.Reason );
    1429           0 :     if ( !aInfo.isValid() )
    1430           0 :         return;
    1431             : 
    1432           0 :     if ( m_nFormActionNestingLevel )
    1433             :     {
    1434             :         OSL_ENSURE( !m_aCurrentError.isValid(), "SbaXDataBrowserController::errorOccurred: can handle one error per transaction only!" );
    1435           0 :         m_aCurrentError = aInfo;
    1436             :     }
    1437             :     else
    1438             :     {
    1439           0 :         m_aCurrentError = aInfo;
    1440           0 :         m_aAsyncDisplayError.Call();
    1441           0 :     }
    1442             : }
    1443             : 
    1444             : //------------------------------------------------------------------------------
    1445           0 : sal_Bool SbaXDataBrowserController::approveParameter(const ::com::sun::star::form::DatabaseParameterEvent& aEvent) throw( RuntimeException )
    1446             : {
    1447             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::approveParameter" );
    1448           0 :     if (aEvent.Source != getRowSet())
    1449             :     {
    1450             :         // not my data source -> allow anything
    1451             :         SAL_WARN("dbaccess.ui","SbaXDataBrowserController::approveParameter : invalid event source !");
    1452           0 :         return sal_True;
    1453             :     }
    1454             : 
    1455           0 :     Reference< ::com::sun::star::container::XIndexAccess >  xParameters = aEvent.Parameters;
    1456           0 :     SolarMutexGuard aSolarGuard;
    1457             : 
    1458             :     // default handling: instantiate an interaction handler and let it handle the parameter request
    1459             :     try
    1460             :     {
    1461             :         // two continuations allowed: OK and Cancel
    1462           0 :         OParameterContinuation* pParamValues = new OParameterContinuation;
    1463           0 :         OInteractionAbort* pAbort = new OInteractionAbort;
    1464             :         // the request
    1465           0 :         ParametersRequest aRequest;
    1466           0 :         aRequest.Parameters = xParameters;
    1467           0 :         aRequest.Connection = getConnection(Reference< XRowSet >(aEvent.Source, UNO_QUERY));
    1468           0 :         OInteractionRequest* pParamRequest = new OInteractionRequest(makeAny(aRequest));
    1469           0 :         Reference< XInteractionRequest > xParamRequest(pParamRequest);
    1470             :         // some knittings
    1471           0 :         pParamRequest->addContinuation(pParamValues);
    1472           0 :         pParamRequest->addContinuation(pAbort);
    1473             : 
    1474             :         // create the handler, let it handle the request
    1475           0 :         Reference< XInteractionHandler2 > xHandler( InteractionHandler::createWithParent(getORB(), 0) );
    1476           0 :         xHandler->handle(xParamRequest);
    1477             : 
    1478           0 :         if (!pParamValues->wasSelected())
    1479             :         {   // canceled
    1480           0 :             setLoadingCancelled();
    1481           0 :             return sal_False;
    1482             :         }
    1483             : 
    1484             :         // transfer the values into the parameter supplier
    1485           0 :         Sequence< PropertyValue > aFinalValues = pParamValues->getValues();
    1486           0 :         if (aFinalValues.getLength() != aRequest.Parameters->getCount())
    1487             :         {
    1488             :             SAL_WARN("dbaccess.ui","SbaXDataBrowserController::approveParameter: the InteractionHandler returned nonsense!");
    1489           0 :             setLoadingCancelled();
    1490           0 :             return sal_False;
    1491             :         }
    1492           0 :         const PropertyValue* pFinalValues = aFinalValues.getConstArray();
    1493           0 :         for (sal_Int32 i=0; i<aFinalValues.getLength(); ++i, ++pFinalValues)
    1494             :         {
    1495           0 :             Reference< XPropertySet > xParam;
    1496           0 :             ::cppu::extractInterface(xParam, aRequest.Parameters->getByIndex(i));
    1497             :             OSL_ENSURE(xParam.is(), "SbaXDataBrowserController::approveParameter: one of the parameters is no property set!");
    1498           0 :             if (xParam.is())
    1499             :             {
    1500             : #ifdef DBG_UTIL
    1501             :                 OUString sName;
    1502             :                 xParam->getPropertyValue(PROPERTY_NAME) >>= sName;
    1503             :                 OSL_ENSURE(sName.equals(pFinalValues->Name), "SbaXDataBrowserController::approveParameter: suspicious value names!");
    1504             : #endif
    1505           0 :                 try { xParam->setPropertyValue(PROPERTY_VALUE, pFinalValues->Value); }
    1506           0 :                 catch(Exception&)
    1507             :                 {
    1508             :                     SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::approveParameter: setting one of the properties failed!");
    1509             :                 }
    1510             :             }
    1511           0 :         }
    1512             :     }
    1513           0 :     catch( const Exception& )
    1514             :     {
    1515             :         DBG_UNHANDLED_EXCEPTION();
    1516             :     }
    1517             : 
    1518           0 :     return sal_True;
    1519             : }
    1520             : 
    1521             : 
    1522             : //------------------------------------------------------------------------------
    1523           0 : sal_Bool SbaXDataBrowserController::approveReset(const ::com::sun::star::lang::EventObject& /*rEvent*/) throw( RuntimeException )
    1524             : {
    1525             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::approveReset" );
    1526           0 :     return sal_True;
    1527             : }
    1528             : 
    1529             : //------------------------------------------------------------------------------
    1530           0 : void SbaXDataBrowserController::resetted(const ::com::sun::star::lang::EventObject& rEvent) throw( RuntimeException )
    1531             : {
    1532             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::resetted" );
    1533             :     OSL_ENSURE(rEvent.Source == getControlModel(), "SbaXDataBrowserController::resetted : where did this come from ?");
    1534             :     (void)rEvent;
    1535           0 :     setCurrentModified( sal_False );
    1536           0 : }
    1537             : 
    1538             : //------------------------------------------------------------------------------
    1539           0 : sal_Bool SbaXDataBrowserController::confirmDelete(const ::com::sun::star::sdb::RowChangeEvent& /*aEvent*/) throw( RuntimeException )
    1540             : {
    1541             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::confirmDelete" );
    1542           0 :     if (QueryBox(getBrowserView(), ModuleRes(QUERY_BRW_DELETE_ROWS)).Execute() != RET_YES)
    1543           0 :         return sal_False;
    1544             : 
    1545           0 :     return sal_True;
    1546             : }
    1547             : //------------------------------------------------------------------------------
    1548          93 : FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const
    1549             : {
    1550             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::GetState" );
    1551          93 :     FeatureState aReturn;
    1552             :         // (disabled automatically)
    1553             : 
    1554             :     try
    1555             :     {
    1556             :         // no chance without a view
    1557          93 :         if (!getBrowserView() || !getBrowserView()->getVclControl())
    1558           0 :             return aReturn;
    1559             : 
    1560          93 :         switch (nId)
    1561             :         {
    1562             :             case ID_BROWSER_REMOVEFILTER:
    1563           7 :                 if (!m_xParser.is())
    1564             :                 {
    1565           2 :                     aReturn.bEnabled = false;
    1566           2 :                     return aReturn;
    1567             :                 }
    1568             :                 // any filter or sort order set ?
    1569           5 :                 aReturn.bEnabled = m_xParser->getFilter().getLength() || m_xParser->getHavingClause().getLength() || m_xParser->getOrder().getLength();
    1570           5 :                 return aReturn;
    1571             :         }
    1572             :         // no chance without valid models
    1573          86 :         if (isValid() && !isValidCursor())
    1574           0 :             return aReturn;
    1575             : 
    1576          86 :         switch (nId)
    1577             :         {
    1578             :             case ID_BROWSER_SEARCH:
    1579             :             {
    1580           3 :                 Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
    1581           3 :                 sal_Int32 nCount = ::comphelper::getINT32(xFormSet->getPropertyValue(PROPERTY_ROWCOUNT));
    1582           3 :                 aReturn.bEnabled = nCount != 0;
    1583             :             }
    1584           3 :             break;
    1585             :             case ID_BROWSER_INSERT_ROW:
    1586             :                 {
    1587             :                     // check if it is available
    1588           3 :                     sal_Bool bInsertPrivilege = ( m_nRowSetPrivileges & Privilege::INSERT) != 0;
    1589           3 :                     sal_Bool bAllowInsertions = sal_True;
    1590             :                     try
    1591             :                     {
    1592           3 :                         Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
    1593           3 :                         OSL_VERIFY( xRowSetProps->getPropertyValue("AllowInserts") >>= bAllowInsertions );
    1594             :                     }
    1595           0 :                     catch( const Exception& )
    1596             :                     {
    1597             :                         DBG_UNHANDLED_EXCEPTION();
    1598             :                     }
    1599           3 :                     aReturn.bEnabled = bInsertPrivilege && bAllowInsertions;
    1600             :                 }
    1601           3 :                 break;
    1602             :             case SID_FM_DELETEROWS:
    1603             :                 {
    1604             :                     // check if it is available
    1605           3 :                     sal_Bool bDeletePrivilege = ( m_nRowSetPrivileges & Privilege::INSERT) != 0;
    1606           3 :                     sal_Bool bAllowDeletions = sal_True;
    1607           3 :                     sal_Int32 nRowCount = 0;
    1608           3 :                     sal_Bool bInsertionRow = sal_False;
    1609             :                     try
    1610             :                     {
    1611           3 :                         Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
    1612           3 :                         OSL_VERIFY( xRowSetProps->getPropertyValue("AllowDeletes") >>= bAllowDeletions );
    1613           3 :                         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ROWCOUNT ) >>= nRowCount );
    1614           3 :                         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ISNEW ) >>= bInsertionRow );
    1615             :                     }
    1616           0 :                     catch( const Exception& )
    1617             :                     {
    1618             :                         DBG_UNHANDLED_EXCEPTION();
    1619             :                     }
    1620           3 :                     aReturn.bEnabled = bDeletePrivilege && bAllowDeletions && ( nRowCount != 0 ) && !bInsertionRow;
    1621             :                 }
    1622           3 :                 break;
    1623             : 
    1624             :             case ID_BROWSER_COPY:
    1625           0 :                 if ( getBrowserView()->getVclControl()->GetSelectRowCount() )
    1626             :                 {
    1627           0 :                     aReturn.bEnabled = m_aCurrentFrame.isActive();
    1628           0 :                     break;
    1629             :                 }
    1630             :                 // run through
    1631             :             case ID_BROWSER_PASTE:
    1632             :             case ID_BROWSER_CUT:
    1633             :             {
    1634          19 :                 CellControllerRef xCurrentController = getBrowserView()->getVclControl()->Controller();
    1635          19 :                 if (xCurrentController.Is() && xCurrentController->ISA(EditCellController))
    1636             :                 {
    1637           0 :                     Edit& rEdit = (Edit&)xCurrentController->GetWindow();
    1638           0 :                     sal_Bool bHasLen = (rEdit.GetSelection().Len() != 0);
    1639           0 :                     sal_Bool bIsReadOnly = rEdit.IsReadOnly();
    1640           0 :                     switch (nId)
    1641             :                     {
    1642           0 :                         case ID_BROWSER_CUT:    aReturn.bEnabled = m_aCurrentFrame.isActive() && bHasLen && !bIsReadOnly; break;
    1643           0 :                         case SID_COPY   :       aReturn.bEnabled = m_aCurrentFrame.isActive() && bHasLen; break;
    1644             :                         case ID_BROWSER_PASTE:
    1645           0 :                             aReturn.bEnabled = m_aCurrentFrame.isActive() && !bIsReadOnly;
    1646           0 :                             if(aReturn.bEnabled)
    1647             :                             {
    1648           0 :                                 aReturn.bEnabled = aReturn.bEnabled && IsFormatSupported( m_aSystemClipboard.GetDataFlavorExVector(), FORMAT_STRING );
    1649             :                             }
    1650           0 :                             break;
    1651             :                     }
    1652          19 :                 }
    1653             :             }
    1654          19 :             break;
    1655             : 
    1656             :             case ID_BROWSER_SORTUP:
    1657             :             case ID_BROWSER_SORTDOWN:
    1658             :             case ID_BROWSER_AUTOFILTER:
    1659             :             {
    1660             :                 // a native statement can't be filtered or sorted
    1661          12 :                 const Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
    1662          12 :                 if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() )
    1663           0 :                     break;
    1664             : 
    1665          24 :                 Reference< XPropertySet >  xCurrentField = getBoundField();
    1666          12 :                 if (!xCurrentField.is())
    1667           0 :                     break;
    1668             : 
    1669          12 :                 aReturn.bEnabled = ::comphelper::getBOOL(xCurrentField->getPropertyValue(PROPERTY_ISSEARCHABLE));
    1670          24 :                 const Reference< XRowSet > xRow = getRowSet();
    1671             :                 aReturn.bEnabled =  aReturn.bEnabled
    1672          12 :                                 &&  xRow.is()
    1673          12 :                                 &&  !xRow->isBeforeFirst()
    1674          12 :                                 &&  !xRow->isAfterLast()
    1675          12 :                                 &&  !xRow->rowDeleted()
    1676          36 :                                 &&  ( ::comphelper::getINT32( xFormSet->getPropertyValue( PROPERTY_ROWCOUNT ) ) != 0 );
    1677             :             }
    1678          12 :             break;
    1679             : 
    1680             :             case ID_BROWSER_FILTERCRIT:
    1681           4 :                 if ( m_bCannotSelectUnfiltered && m_xParser.is() )
    1682             :                 {
    1683           0 :                     aReturn.bEnabled = sal_True;
    1684           0 :                     break;
    1685             :                 }
    1686             :                 // no break
    1687             :             case ID_BROWSER_ORDERCRIT:
    1688             :                 {
    1689           8 :                     const Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
    1690           8 :                     if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() )
    1691           0 :                         break;
    1692             : 
    1693          32 :                     aReturn.bEnabled =  getRowSet().is()
    1694          32 :                                     &&  ( ::comphelper::getINT32( xFormSet->getPropertyValue( PROPERTY_ROWCOUNT ) ) != 0 );
    1695             :                 }
    1696           8 :                 break;
    1697             : 
    1698             :             case ID_BROWSER_REFRESH:
    1699           0 :                 aReturn.bEnabled = sal_True;
    1700           0 :                 break;
    1701             : 
    1702             :             case ID_BROWSER_REDO:
    1703           0 :                 aReturn.bEnabled = sal_False;   // simply forget it ;). no redo possible.
    1704           0 :                 break;
    1705             : 
    1706             :             case ID_BROWSER_UNDORECORD:
    1707             :             case ID_BROWSER_SAVERECORD:
    1708             :             {
    1709          26 :                 if (!m_bCurrentlyModified)
    1710             :                 {
    1711          26 :                     Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
    1712          26 :                     if (xFormSet.is())
    1713          26 :                         aReturn.bEnabled = ::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISMODIFIED));
    1714             :                 }
    1715             :                 else
    1716           0 :                     aReturn.bEnabled = sal_True;
    1717             : 
    1718          26 :                 aReturn.sTitle = (ID_BROWSER_UNDORECORD == nId) ? m_sStateUndoRecord : m_sStateSaveRecord;
    1719             :             }
    1720          26 :             break;
    1721             :             case ID_BROWSER_EDITDOC:
    1722             :             {
    1723             :                 // check if it is available
    1724           3 :                 Reference< XPropertySet >  xDataSourceSet(getRowSet(), UNO_QUERY);
    1725           3 :                 if (!xDataSourceSet.is())
    1726           0 :                     break;  // no datasource -> no edit mode
    1727             : 
    1728           3 :                 sal_Int32 nDataSourcePrivileges = ::comphelper::getINT32(xDataSourceSet->getPropertyValue(PROPERTY_PRIVILEGES));
    1729           3 :                 sal_Bool bInsertAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::INSERT) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowInserts"));
    1730           3 :                 sal_Bool bUpdateAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::UPDATE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowUpdates"));
    1731           3 :                 sal_Bool bDeleteAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::DELETE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowDeletes"));
    1732           3 :                 if (!bInsertAllowedAndPossible && !bUpdateAllowedAndPossible && !bDeleteAllowedAndPossible)
    1733           0 :                     break;  // no insert/update/delete -> no edit mode
    1734             : 
    1735           3 :                 if (!isValidCursor() || !isLoaded())
    1736           0 :                     break;  // no cursor -> no edit mode
    1737             : 
    1738           3 :                 aReturn.bEnabled = sal_True;
    1739             : 
    1740           3 :                 sal_Int16 nGridMode = getBrowserView()->getVclControl()->GetOptions();
    1741           3 :                 aReturn.bChecked = nGridMode > DbGridControl::OPT_READONLY;
    1742             :             }
    1743           3 :             break;
    1744             :             case ID_BROWSER_FILTERED:
    1745             :             {
    1746           3 :                 aReturn.bEnabled = sal_False;
    1747           3 :                 Reference< XPropertySet >  xActiveSet(getRowSet(), UNO_QUERY);
    1748           6 :                 OUString aFilter = ::comphelper::getString(xActiveSet->getPropertyValue(PROPERTY_FILTER));
    1749           6 :                 OUString aHaving = ::comphelper::getString(xActiveSet->getPropertyValue(PROPERTY_HAVING_CLAUSE));
    1750           3 :                 if ( !(aFilter.isEmpty() && aHaving.isEmpty()) )
    1751             :                 {
    1752           0 :                     xActiveSet->getPropertyValue( PROPERTY_APPLYFILTER ) >>= aReturn.bChecked;
    1753           0 :                     aReturn.bEnabled = sal_True;
    1754             :                 }
    1755             :                 else
    1756             :                 {
    1757           3 :                     aReturn.bChecked = sal_False;
    1758           3 :                     aReturn.bEnabled = sal_False;
    1759           3 :                 }
    1760             :             }
    1761           3 :             break;
    1762             :             default:
    1763           6 :                 return SbaXDataBrowserController_Base::GetState(nId);
    1764             :         }
    1765             :     }
    1766           0 :     catch(const Exception& )
    1767             :     {
    1768             :         DBG_UNHANDLED_EXCEPTION();
    1769             :     }
    1770             : 
    1771          80 :     return aReturn;
    1772             : }
    1773             : 
    1774             : //------------------------------------------------------------------------------
    1775           0 : void SbaXDataBrowserController::applyParserOrder(const OUString& _rOldOrder,const Reference< XSingleSelectQueryComposer >& _xParser)
    1776             : {
    1777             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::applyParserOrder" );
    1778           0 :     Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
    1779           0 :     if (!m_xLoadable.is())
    1780             :     {
    1781             :         SAL_WARN("dbaccess.ui","SbaXDataBrowserController::applyParserOrder: invalid row set!");
    1782           0 :         return;
    1783             :     }
    1784             : 
    1785           0 :     sal_uInt16 nPos = getCurrentColumnPosition();
    1786           0 :     sal_Bool bSuccess = sal_False;
    1787             :     try
    1788             :     {
    1789           0 :         xFormSet->setPropertyValue(PROPERTY_ORDER, makeAny(_xParser->getOrder()));
    1790           0 :         bSuccess = reloadForm(m_xLoadable);
    1791             :     }
    1792           0 :     catch(Exception&)
    1793             :     {
    1794             :     }
    1795             : 
    1796           0 :     if (!bSuccess)
    1797             :     {
    1798           0 :         xFormSet->setPropertyValue(PROPERTY_ORDER, makeAny(_rOldOrder));
    1799             : 
    1800             :         try
    1801             :         {
    1802           0 :             if (loadingCancelled() || !reloadForm(m_xLoadable))
    1803           0 :                 criticalFail();
    1804             :         }
    1805           0 :         catch(Exception&)
    1806             :         {
    1807           0 :             criticalFail();
    1808             :         }
    1809           0 :         InvalidateAll();
    1810             :     }
    1811           0 :     InvalidateFeature(ID_BROWSER_REMOVEFILTER);
    1812             : 
    1813           0 :     setCurrentColumnPosition(nPos);
    1814             : }
    1815             : 
    1816             : //------------------------------------------------------------------------------
    1817           0 : void SbaXDataBrowserController::applyParserFilter(const OUString& _rOldFilter, sal_Bool _bOldFilterApplied,const ::OUString& _sOldHaving,const Reference< XSingleSelectQueryComposer >& _xParser)
    1818             : {
    1819             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::applyParserFilter" );
    1820           0 :     Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
    1821           0 :     if (!m_xLoadable.is())
    1822             :     {
    1823             :         SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::applyParserFilter: invalid row set!");
    1824           0 :         return;
    1825             :     }
    1826             : 
    1827           0 :     sal_uInt16 nPos = getCurrentColumnPosition();
    1828             : 
    1829           0 :     sal_Bool bSuccess = sal_False;
    1830             :     try
    1831             :     {
    1832           0 :         FormErrorHelper aError(this);
    1833           0 :         xFormSet->setPropertyValue(PROPERTY_FILTER, makeAny(_xParser->getFilter()));
    1834           0 :         xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, makeAny(_xParser->getHavingClause()));
    1835           0 :         xFormSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(sal_Bool(sal_True)));
    1836             : 
    1837           0 :         bSuccess = reloadForm(m_xLoadable);
    1838             :     }
    1839           0 :     catch(Exception&)
    1840             :     {
    1841             :     }
    1842             : 
    1843           0 :     if (!bSuccess)
    1844             :     {
    1845           0 :         xFormSet->setPropertyValue(PROPERTY_FILTER, makeAny(_rOldFilter));
    1846           0 :         xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, makeAny(_sOldHaving));
    1847           0 :         xFormSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(_bOldFilterApplied));
    1848             : 
    1849             :         try
    1850             :         {
    1851           0 :             if (loadingCancelled() || !reloadForm(m_xLoadable))
    1852           0 :                 criticalFail();
    1853             :         }
    1854           0 :         catch(Exception&)
    1855             :         {
    1856           0 :             criticalFail();
    1857             :         }
    1858           0 :         InvalidateAll();
    1859             :     }
    1860           0 :     InvalidateFeature(ID_BROWSER_REMOVEFILTER);
    1861             : 
    1862           0 :     setCurrentColumnPosition(nPos);
    1863             : }
    1864             : 
    1865             : //------------------------------------------------------------------------------
    1866           1 : Reference< XSingleSelectQueryComposer > SbaXDataBrowserController::createParser_nothrow()
    1867             : {
    1868           1 :     Reference< XSingleSelectQueryComposer > xComposer;
    1869             :     try
    1870             :     {
    1871           1 :         const Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
    1872             :         const Reference< XMultiServiceFactory > xFactory(
    1873           2 :             xRowSetProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ), UNO_QUERY_THROW );
    1874           1 :         xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
    1875             : 
    1876           2 :         OUString sActiveCommand;
    1877           1 :         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ACTIVECOMMAND ) >>= sActiveCommand );
    1878           1 :         if ( !sActiveCommand.isEmpty() )
    1879             :         {
    1880           0 :             xComposer->setElementaryQuery( sActiveCommand );
    1881             :         }
    1882             :         else
    1883             :         {
    1884           1 :             OUString sCommand;
    1885           1 :             OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
    1886           1 :             sal_Int32 nCommandType = CommandType::COMMAND;
    1887           1 :             OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMAND_TYPE ) >>= nCommandType );
    1888           1 :             xComposer->setCommand( sCommand, nCommandType );
    1889             :         }
    1890             : 
    1891           2 :         OUString sFilter;
    1892           1 :         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_FILTER ) >>= sFilter );
    1893           1 :         xComposer->setFilter( sFilter );
    1894             : 
    1895           2 :         OUString sHavingClause;
    1896           1 :         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_HAVING_CLAUSE ) >>= sHavingClause );
    1897           1 :         xComposer->setHavingClause( sHavingClause );
    1898             : 
    1899           2 :         OUString sOrder;
    1900           1 :         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ORDER ) >>= sOrder );
    1901           2 :         xComposer->setOrder( sOrder );
    1902             :     }
    1903           0 :     catch ( const Exception& )
    1904             :     {
    1905             :         DBG_UNHANDLED_EXCEPTION();
    1906             :     }
    1907           1 :     return xComposer;
    1908             : }
    1909             : //------------------------------------------------------------------------------
    1910           0 : void SbaXDataBrowserController::ExecuteFilterSortCrit(sal_Bool bFilter)
    1911             : {
    1912             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::ExecuteFilterSortCrit" );
    1913           0 :     if (!SaveModified())
    1914           0 :         return;
    1915             : 
    1916           0 :     Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
    1917             : 
    1918           0 :     const OUString sOldVal = bFilter ? m_xParser->getFilter() : m_xParser->getOrder();
    1919           0 :     const OUString sOldHaving = m_xParser->getHavingClause();
    1920           0 :     Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
    1921             :     try
    1922             :     {
    1923           0 :         Reference< ::com::sun::star::sdbcx::XColumnsSupplier> xSup = getColumnsSupplier();
    1924           0 :         Reference< XConnection> xCon(xFormSet->getPropertyValue(PROPERTY_ACTIVE_CONNECTION),UNO_QUERY);
    1925           0 :         if(bFilter)
    1926             :         {
    1927           0 :             DlgFilterCrit aDlg( getBrowserView(), getORB(), xCon, xParser, xSup->getColumns() );
    1928           0 :             if ( !aDlg.Execute() )
    1929           0 :                 return; // if so we don't need to update the grid
    1930           0 :             aDlg.BuildWherePart();
    1931             :         }
    1932             :         else
    1933             :         {
    1934           0 :             DlgOrderCrit aDlg( getBrowserView(),xCon,xParser,xSup->getColumns() );
    1935           0 :             if(!aDlg.Execute())
    1936             :             {
    1937           0 :                 return; // if so we don't need to actualize the grid
    1938             :             }
    1939           0 :             aDlg.BuildOrderPart();
    1940           0 :         }
    1941             :     }
    1942           0 :     catch(const SQLException& )
    1943             :     {
    1944           0 :         SQLExceptionInfo aError( ::cppu::getCaughtException() );
    1945           0 :         showError( aError );
    1946           0 :         return;
    1947             :     }
    1948           0 :     catch(Exception&)
    1949             :     {
    1950           0 :         return;
    1951             :     }
    1952             : 
    1953           0 :     OUString sNewVal = bFilter ? xParser->getFilter() : xParser->getOrder();
    1954           0 :     sal_Bool bOldFilterApplied(sal_False);
    1955           0 :     if (bFilter)
    1956             :     {
    1957           0 :         try { bOldFilterApplied = ::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_APPLYFILTER)); } catch(Exception&) { } ;
    1958             :     }
    1959             : 
    1960           0 :     OUString sNewHaving = xParser->getHavingClause();
    1961           0 :     if ( sOldVal.equals(sNewVal) && (!bFilter || sOldHaving.equals(sNewHaving)) )
    1962             :         // nothing to be done
    1963           0 :         return;
    1964             : 
    1965           0 :     if (bFilter)
    1966           0 :         applyParserFilter(sOldVal, bOldFilterApplied,sOldHaving,xParser);
    1967             :     else
    1968           0 :         applyParserOrder(sOldVal,xParser);
    1969             : 
    1970           0 :     ::comphelper::disposeComponent(xParser);
    1971             : }
    1972             : 
    1973             : //------------------------------------------------------------------------------
    1974           0 : void SbaXDataBrowserController::ExecuteSearch()
    1975             : {
    1976             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::ExecuteSearch" );
    1977             :     // calculate the control source of the active field
    1978           0 :     Reference< ::com::sun::star::form::XGrid >  xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
    1979             :     OSL_ENSURE(xGrid.is(), "SbaXDataBrowserController::ExecuteSearch : the control should have an ::com::sun::star::form::XGrid interface !");
    1980             : 
    1981           0 :     Reference< ::com::sun::star::form::XGridPeer >  xGridPeer(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
    1982           0 :     Reference< ::com::sun::star::container::XIndexContainer >  xColumns = xGridPeer->getColumns();
    1983             :     OSL_ENSURE(xGridPeer.is() && xColumns.is(), "SbaXDataBrowserController::ExecuteSearch : invalid peer !");
    1984             : 
    1985           0 :     sal_Int16 nViewCol = xGrid->getCurrentColumnPosition();
    1986           0 :     sal_Int16 nModelCol = getBrowserView()->View2ModelPos(nViewCol);
    1987             : 
    1988           0 :     Reference< XPropertySet >  xCurrentCol(xColumns->getByIndex(nModelCol),UNO_QUERY);
    1989           0 :     OUString sActiveField = ::comphelper::getString(xCurrentCol->getPropertyValue(PROPERTY_CONTROLSOURCE));
    1990             : 
    1991             :     // the text within the current cell
    1992           0 :     OUString sInitialText;
    1993           0 :     Reference< ::com::sun::star::container::XIndexAccess >  xColControls(xGridPeer, UNO_QUERY);
    1994           0 :     Reference< XInterface >  xCurControl(xColControls->getByIndex(nViewCol),UNO_QUERY);
    1995           0 :     OUString aInitialText;
    1996           0 :     if (IsSearchableControl(xCurControl, &aInitialText))
    1997           0 :         sInitialText = aInitialText;
    1998             : 
    1999             :     // prohibit the synchronization of the grid's display with the cursor's position
    2000           0 :     Reference< XPropertySet >  xModelSet(getControlModel(), UNO_QUERY);
    2001             :     OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::ExecuteSearch : no model set ?!");
    2002           0 :     xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(sal_Bool(sal_False)));
    2003           0 :     xModelSet->setPropertyValue("AlwaysShowCursor", ::comphelper::makeBoolAny(sal_Bool(sal_True)));
    2004           0 :     xModelSet->setPropertyValue("CursorColor", makeAny(sal_Int32(COL_LIGHTRED)));
    2005             : 
    2006           0 :     Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xNFS(::dbtools::getNumberFormats(::dbtools::getConnection(m_xRowSet), sal_True, getORB()));
    2007             : 
    2008           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    2009           0 :     AbstractFmSearchDialog* pDialog = NULL;
    2010           0 :     if ( pFact )
    2011             :     {
    2012           0 :         ::std::vector< OUString > aContextNames;
    2013           0 :         aContextNames.push_back( OUString("Standard") );
    2014           0 :         pDialog = pFact->CreateFmSearchDialog(getBrowserView(), sInitialText, aContextNames, 0, LINK(this, SbaXDataBrowserController, OnSearchContextRequest));
    2015             :     }
    2016             :     OSL_ENSURE( pDialog, "SbaXDataBrowserController::ExecuteSearch: could not get the search dialog!" );
    2017           0 :     if ( pDialog )
    2018             :     {
    2019           0 :         pDialog->SetActiveField( sActiveField );
    2020           0 :         pDialog->SetFoundHandler( LINK( this, SbaXDataBrowserController, OnFoundData ) );
    2021           0 :         pDialog->SetCanceledNotFoundHdl( LINK( this, SbaXDataBrowserController, OnCanceledNotFound ) );
    2022           0 :         pDialog->Execute();
    2023           0 :         delete pDialog;
    2024             :     }
    2025             : 
    2026             :     // restore the grid's normal operating state
    2027           0 :     xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(sal_Bool(sal_True)));
    2028           0 :     xModelSet->setPropertyValue("AlwaysShowCursor", ::comphelper::makeBoolAny(sal_Bool(sal_False)));
    2029           0 :     xModelSet->setPropertyValue("CursorColor", Any());
    2030           0 : }
    2031             : 
    2032             : //------------------------------------------------------------------------------
    2033           0 : void SbaXDataBrowserController::Execute(sal_uInt16 nId, const Sequence< PropertyValue >& _rArgs)
    2034             : {
    2035             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::Execute" );
    2036           0 :     sal_Bool bSortUp = sal_True;
    2037             : 
    2038           0 :     switch (nId)
    2039             :     {
    2040             :         default:
    2041           0 :             SbaXDataBrowserController_Base::Execute( nId, _rArgs );
    2042           0 :             return;
    2043             : 
    2044             :         case ID_BROWSER_INSERT_ROW:
    2045             :             try
    2046             :             {
    2047           0 :                 if (SaveModified())
    2048             :                 {
    2049           0 :                     getRowSet()->afterLast();
    2050             :                     // check if it is available
    2051           0 :                     Reference< XResultSetUpdate >  xUpdateCursor(getRowSet(), UNO_QUERY_THROW);
    2052           0 :                     xUpdateCursor->moveToInsertRow();
    2053             :                 }
    2054             :             }
    2055           0 :             catch(Exception&)
    2056             :             {
    2057             :                 SAL_WARN("dbaccess.ui", "Exception caught!");
    2058             :             }
    2059           0 :             break;
    2060             :         case SID_FM_DELETEROWS:
    2061             : 
    2062           0 :             if (SaveModified())
    2063             :             {
    2064           0 :                 SbaGridControl* pVclGrid = getBrowserView()->getVclControl();
    2065           0 :                 if ( pVclGrid )
    2066             :                 {
    2067           0 :                     if( !pVclGrid->GetSelectRowCount() )
    2068             :                     {
    2069           0 :                         pVclGrid->DeactivateCell();
    2070           0 :                         pVclGrid->SelectRow(pVclGrid->GetCurRow());
    2071             :                     }
    2072           0 :                     pVclGrid->DeleteSelectedRows();
    2073             :                 }
    2074             :             }
    2075           0 :             break;
    2076             : 
    2077             :         case ID_BROWSER_FILTERED:
    2078           0 :             if (SaveModified())
    2079             :             {
    2080           0 :                 Reference< XPropertySet >  xActiveSet(getRowSet(), UNO_QUERY);
    2081           0 :                 sal_Bool bApplied = ::comphelper::getBOOL(xActiveSet->getPropertyValue(PROPERTY_APPLYFILTER));
    2082           0 :                 xActiveSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(sal_Bool(!bApplied)));
    2083           0 :                 reloadForm(m_xLoadable);
    2084             :             }
    2085           0 :             InvalidateFeature(ID_BROWSER_FILTERED);
    2086           0 :             break;
    2087             :         case ID_BROWSER_EDITDOC:
    2088             :         {
    2089           0 :             sal_Int16 nGridMode = getBrowserView()->getVclControl()->GetOptions();
    2090           0 :             if (nGridMode == DbGridControl::OPT_READONLY)
    2091           0 :                 getBrowserView()->getVclControl()->SetOptions(DbGridControl::OPT_UPDATE | DbGridControl::OPT_INSERT | DbGridControl::OPT_DELETE);
    2092             :                     // the options not supported by the data source will be removed automatically
    2093             :             else
    2094             :             {
    2095           0 :                 if ( !SaveModified( ) )
    2096             :                     // give the user a chance to save the current record (if necessary)
    2097           0 :                     break;
    2098             : 
    2099             :                 // maybe the user wanted to reject the modified record ?
    2100           0 :                 if (GetState(ID_BROWSER_UNDORECORD).bEnabled)
    2101           0 :                     Execute(ID_BROWSER_UNDORECORD,Sequence<PropertyValue>());
    2102             : 
    2103           0 :                 getBrowserView()->getVclControl()->SetOptions(DbGridControl::OPT_READONLY);
    2104             :             }
    2105           0 :             InvalidateFeature(ID_BROWSER_EDITDOC);
    2106             :         }
    2107           0 :         break;
    2108             : 
    2109             :         case ID_BROWSER_SEARCH:
    2110           0 :             if ( SaveModified( ) )
    2111           0 :                 ExecuteSearch();
    2112           0 :             break;
    2113             : 
    2114             :         case ID_BROWSER_COPY:
    2115           0 :             if ( getBrowserView()->getVclControl()->GetSelectRowCount() > 0 )
    2116             :             {
    2117           0 :                 getBrowserView()->getVclControl()->CopySelectedRowsToClipboard();
    2118           0 :                 break;
    2119             :             }
    2120             :             // run through
    2121             :         case ID_BROWSER_CUT:
    2122             :         case ID_BROWSER_PASTE:
    2123             :         {
    2124           0 :             CellControllerRef xCurrentController = getBrowserView()->getVclControl()->Controller();
    2125           0 :             if (!xCurrentController.Is())
    2126             :                 // should be intercepted by GetState. Normally.
    2127             :                 // Unfortunately ID_BROWSER_PASTE is a 'fast call' slot, which means it may be executed without checking if it is
    2128             :                 // enabled. This would be really deadly herein if the current cell has no controller ...
    2129           0 :                 return;
    2130             : 
    2131           0 :             Edit& rEdit = (Edit&)xCurrentController->GetWindow();
    2132           0 :             switch (nId)
    2133             :             {
    2134           0 :                 case ID_BROWSER_CUT :       rEdit.Cut();    break;
    2135           0 :                 case SID_COPY   :           rEdit.Copy();   break;
    2136           0 :                 case ID_BROWSER_PASTE   :   rEdit.Paste();  break;
    2137             :             }
    2138           0 :             if (ID_BROWSER_CUT == nId || ID_BROWSER_PASTE == nId)
    2139             :             {
    2140           0 :                 xCurrentController->SetModified();
    2141           0 :                 rEdit.Modify();
    2142           0 :             }
    2143             :         }
    2144           0 :         break;
    2145             : 
    2146             :         case ID_BROWSER_SORTDOWN:
    2147           0 :             bSortUp = sal_False;
    2148             :             // DON'T break
    2149             :         case ID_BROWSER_SORTUP:
    2150             :         {
    2151           0 :             if (!SaveModified())
    2152           0 :                 break;
    2153             : 
    2154           0 :             if (!isValidCursor())
    2155           0 :                 break;
    2156             : 
    2157             :             // only one sort order
    2158           0 :             Reference< XPropertySet >  xField(getBoundField(), UNO_QUERY);
    2159           0 :             if (!xField.is())
    2160           0 :                 break;
    2161             : 
    2162           0 :             Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
    2163           0 :             const OUString sOldSort = xParser->getOrder();
    2164           0 :             sal_Bool bParserSuccess = sal_False;
    2165           0 :             HANDLE_SQL_ERRORS(
    2166             :                 xParser->setOrder(OUString()); xParser->appendOrderByColumn(xField, bSortUp),
    2167             :                 bParserSuccess,
    2168             :                 ModuleRes(SBA_BROWSER_SETTING_ORDER).toString(),
    2169             :                 "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
    2170             :             )
    2171             : 
    2172           0 :             if (bParserSuccess)
    2173           0 :                 applyParserOrder(sOldSort,xParser);
    2174             :         }
    2175           0 :         break;
    2176             : 
    2177             :         case ID_BROWSER_AUTOFILTER:
    2178             :         {
    2179           0 :             if (!SaveModified())
    2180           0 :                 break;
    2181             : 
    2182           0 :             if (!isValidCursor())
    2183           0 :                 break;
    2184             : 
    2185           0 :             Reference< XPropertySet >  xField(getBoundField(), UNO_QUERY);
    2186           0 :             if (!xField.is())
    2187           0 :                 break;
    2188             : 
    2189             :             // check if the column is a aggregate function
    2190           0 :             sal_Bool bHaving = sal_False;
    2191           0 :             OUString sName;
    2192           0 :             xField->getPropertyValue(PROPERTY_NAME) >>= sName;
    2193           0 :             Reference< XColumnsSupplier > xColumnsSupplier(m_xParser, UNO_QUERY);
    2194           0 :             Reference< ::com::sun::star::container::XNameAccess >  xCols = xColumnsSupplier.is() ? xColumnsSupplier->getColumns() : Reference< ::com::sun::star::container::XNameAccess > ();
    2195           0 :             if ( xCols.is() && xCols->hasByName(sName) )
    2196             :             {
    2197           0 :                 Reference<XPropertySet> xProp(xCols->getByName(sName),UNO_QUERY);
    2198           0 :                 static OUString sAgg("AggregateFunction");
    2199           0 :                 if ( xProp->getPropertySetInfo()->hasPropertyByName(sAgg) )
    2200           0 :                     xProp->getPropertyValue(sAgg) >>= bHaving;
    2201             :             }
    2202             : 
    2203           0 :             Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
    2204           0 :             const OUString sOldFilter = xParser->getFilter();
    2205           0 :             const OUString sOldHaving = xParser->getHavingClause();
    2206             : 
    2207           0 :             Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
    2208           0 :             sal_Bool bApplied = ::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_APPLYFILTER));
    2209             :             // do we have a filter but it's not applied ?
    2210             :             // -> completely overwrite it, else append one
    2211           0 :             if (!bApplied)
    2212             :             {
    2213           0 :                 DO_SAFE( (bHaving ? xParser->setHavingClause(OUString()) : xParser->setFilter(::OUString())), "SbaXDataBrowserController::Execute : caught an exception while resetting the new filter !" );
    2214             :             }
    2215             : 
    2216           0 :             sal_Bool bParserSuccess = sal_False;
    2217             : 
    2218           0 :             const sal_Int32 nOp = SQLFilterOperator::EQUAL;
    2219             : 
    2220           0 :             if ( bHaving )
    2221             :             {
    2222           0 :                 HANDLE_SQL_ERRORS(
    2223             :                     xParser->appendHavingClauseByColumn(xField,sal_True,nOp),
    2224             :                     bParserSuccess,
    2225             :                     ModuleRes(SBA_BROWSER_SETTING_FILTER).toString(),
    2226             :                     "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
    2227             :                 )
    2228             :             }
    2229             :             else
    2230             :             {
    2231           0 :                 HANDLE_SQL_ERRORS(
    2232             :                     xParser->appendFilterByColumn(xField,sal_True,nOp),
    2233             :                     bParserSuccess,
    2234             :                     ModuleRes(SBA_BROWSER_SETTING_FILTER).toString(),
    2235             :                     "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
    2236             :                 )
    2237             :             }
    2238             : 
    2239           0 :             if (bParserSuccess)
    2240           0 :                 applyParserFilter(sOldFilter, bApplied,sOldHaving,xParser);
    2241             : 
    2242           0 :             InvalidateFeature(ID_BROWSER_REMOVEFILTER);
    2243           0 :             InvalidateFeature(ID_BROWSER_FILTERED);
    2244             :         }
    2245           0 :         break;
    2246             : 
    2247             :         case ID_BROWSER_ORDERCRIT:
    2248           0 :             ExecuteFilterSortCrit(sal_False);
    2249           0 :             break;
    2250             : 
    2251             :         case ID_BROWSER_FILTERCRIT:
    2252           0 :             ExecuteFilterSortCrit(sal_True);
    2253           0 :             InvalidateFeature(ID_BROWSER_FILTERED);
    2254           0 :             break;
    2255             : 
    2256             :         case ID_BROWSER_REMOVEFILTER:
    2257             :         {
    2258           0 :             if (!SaveModified())
    2259           0 :                 break;
    2260             : 
    2261           0 :             sal_Bool bNeedPostReload = preReloadForm();
    2262             :             // reset the filter and the sort property simutaneously so only _one_ new statement has to be
    2263             :             // sent
    2264           0 :             Reference< XPropertySet >  xSet(getRowSet(), UNO_QUERY);
    2265           0 :             if ( xSet.is() )
    2266             :             {
    2267           0 :                 xSet->setPropertyValue(PROPERTY_FILTER,makeAny(OUString()));
    2268           0 :                 xSet->setPropertyValue(PROPERTY_HAVING_CLAUSE,makeAny(OUString()));
    2269           0 :                 xSet->setPropertyValue(PROPERTY_ORDER,makeAny(OUString()));
    2270             :             }
    2271             :             try
    2272             :             {
    2273           0 :                 reloadForm(m_xLoadable);
    2274           0 :                 if ( bNeedPostReload )
    2275           0 :                     postReloadForm();
    2276             :             }
    2277           0 :             catch(Exception&)
    2278             :             {
    2279             :             }
    2280           0 :             InvalidateFeature(ID_BROWSER_REMOVEFILTER);
    2281           0 :             InvalidateFeature(ID_BROWSER_FILTERED);
    2282             :         }
    2283           0 :         break;
    2284             : 
    2285             :         case ID_BROWSER_REFRESH:
    2286           0 :             if ( SaveModified( ) )
    2287             :             {
    2288           0 :                 if (!reloadForm(m_xLoadable))
    2289           0 :                     criticalFail();
    2290             :             }
    2291           0 :             break;
    2292             : 
    2293             :         case ID_BROWSER_SAVERECORD:
    2294           0 :             if ( SaveModified( sal_False ) )
    2295           0 :                 setCurrentModified( sal_False );
    2296           0 :             break;
    2297             : 
    2298             :         case ID_BROWSER_UNDORECORD:
    2299             :         {
    2300             :             try
    2301             :             {
    2302             :                 // restore the cursor state
    2303           0 :                 Reference< XResultSetUpdate >  xCursor(getRowSet(), UNO_QUERY);
    2304           0 :                 Reference< XPropertySet >  xSet(xCursor, UNO_QUERY);
    2305           0 :                 Any aVal = xSet->getPropertyValue(PROPERTY_ISNEW);
    2306           0 :                 if (aVal.hasValue() && ::comphelper::getBOOL(aVal))
    2307             :                 {
    2308           0 :                     xCursor->moveToInsertRow();
    2309             :                     // no need to reset the grid model after we moved to the insert row, this is done implicitly by the
    2310             :                     // form
    2311             :                     // (and in some cases it may be deadly to do the reset explicitly after the form did it implicitly,
    2312             :                     // cause the form's reset may be async, and this leads to some nice deadlock scenarios ....)
    2313             :                 }
    2314             :                 else
    2315             :                 {
    2316           0 :                     xCursor->cancelRowUpdates();
    2317             : 
    2318             :                     // restore the grids state
    2319           0 :                     Reference< ::com::sun::star::form::XReset >  xReset(getControlModel(), UNO_QUERY);
    2320           0 :                     if (xReset.is())
    2321           0 :                         xReset->reset();
    2322           0 :                 }
    2323             :             }
    2324           0 :             catch(SQLException&)
    2325             :             {
    2326             :             }
    2327             : 
    2328           0 :             setCurrentModified( sal_False );
    2329             :         }
    2330             :     }
    2331             : }
    2332             : 
    2333             : //------------------------------------------------------------------------------
    2334           0 : sal_Bool SbaXDataBrowserController::SaveModified(sal_Bool bAskFor)
    2335             : {
    2336             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::SaveModified" );
    2337           0 :     if ( bAskFor && GetState(ID_BROWSER_SAVERECORD).bEnabled )
    2338             :     {
    2339           0 :         getBrowserView()->getVclControl()->GrabFocus();
    2340             : 
    2341           0 :         QueryBox aQry(getBrowserView()->getVclControl(), ModuleRes(QUERY_BRW_SAVEMODIFIED));
    2342             : 
    2343           0 :         switch (aQry.Execute())
    2344             :         {
    2345             :             case RET_NO:
    2346           0 :                 Execute(ID_BROWSER_UNDORECORD,Sequence<PropertyValue>());
    2347           0 :                 return sal_True;
    2348             :             case RET_CANCEL:
    2349           0 :                 return sal_False;
    2350           0 :         }
    2351             :     }
    2352             : 
    2353           0 :     if ( !CommitCurrent() ) // das aktuelle Control committen lassen
    2354           0 :         return sal_False;
    2355             : 
    2356           0 :     Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
    2357           0 :     sal_Bool bResult = sal_False;
    2358             :     try
    2359             :     {
    2360           0 :         if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISMODIFIED)))
    2361             :         {
    2362           0 :             Reference< XResultSetUpdate >  xCursor(getRowSet(), UNO_QUERY);
    2363           0 :             if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISNEW)))
    2364           0 :                 xCursor->insertRow();
    2365             :             else
    2366           0 :                 xCursor->updateRow();
    2367             :         }
    2368           0 :         bResult = sal_True;
    2369             :     }
    2370           0 :     catch(SQLException&)
    2371             :     {
    2372             :     }
    2373           0 :     catch(Exception&)
    2374             :     {
    2375             :         SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::SaveModified : could not save the current record !");
    2376           0 :         bResult = sal_False;
    2377             :     }
    2378             : 
    2379           0 :     InvalidateFeature(ID_BROWSER_SAVERECORD);
    2380           0 :     InvalidateFeature(ID_BROWSER_UNDORECORD);
    2381           0 :     return bResult;
    2382             : }
    2383             : 
    2384             : //------------------------------------------------------------------------------
    2385           0 : sal_Bool SbaXDataBrowserController::CommitCurrent()
    2386             : {
    2387             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::CommitCurrent" );
    2388           0 :     if (!getBrowserView())
    2389           0 :         return sal_True;
    2390             : 
    2391           0 :     Reference< ::com::sun::star::awt::XControl >  xActiveControl(getBrowserView()->getGridControl());
    2392           0 :     Reference< ::com::sun::star::form::XBoundControl >  xLockingTest(xActiveControl, UNO_QUERY);
    2393           0 :     sal_Bool bControlIsLocked = xLockingTest.is() && xLockingTest->getLock();
    2394           0 :     if (xActiveControl.is() && !bControlIsLocked)
    2395             :     {
    2396             :         // zunaechst das Control fragen ob es das IFace unterstuetzt
    2397           0 :         Reference< ::com::sun::star::form::XBoundComponent >  xBoundControl(xActiveControl, UNO_QUERY);
    2398           0 :         if (!xBoundControl.is())
    2399           0 :             xBoundControl  = Reference< ::com::sun::star::form::XBoundComponent > (xActiveControl->getModel(), UNO_QUERY);
    2400           0 :         if (xBoundControl.is() && !xBoundControl->commit())
    2401           0 :             return sal_False;
    2402             :     }
    2403           0 :     return sal_True;
    2404             : }
    2405             : 
    2406             : //------------------------------------------------------------------------------
    2407           3 : void SbaXDataBrowserController::setCurrentModified( sal_Bool _bSet )
    2408             : {
    2409             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::setCurrentModified" );
    2410           3 :     m_bCurrentlyModified = _bSet;
    2411           3 :     InvalidateFeature( ID_BROWSER_SAVERECORD );
    2412           3 :     InvalidateFeature( ID_BROWSER_UNDORECORD );
    2413           3 : }
    2414             : 
    2415             : //------------------------------------------------------------------------------
    2416           2 : void SbaXDataBrowserController::RowChanged()
    2417             : {
    2418             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::RowChanged" );
    2419           2 :     setCurrentModified( sal_False );
    2420           2 : }
    2421             : 
    2422             : //------------------------------------------------------------------------------
    2423           1 : void SbaXDataBrowserController::ColumnChanged()
    2424             : {
    2425             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::ColumnChanged" );
    2426           1 :     InvalidateFeature(ID_BROWSER_SORTUP);
    2427           1 :     InvalidateFeature(ID_BROWSER_SORTDOWN);
    2428           1 :     InvalidateFeature(ID_BROWSER_ORDERCRIT);
    2429           1 :     InvalidateFeature(ID_BROWSER_FILTERCRIT);
    2430           1 :     InvalidateFeature(ID_BROWSER_AUTOFILTER);
    2431           1 :     InvalidateFeature(ID_BROWSER_REMOVEFILTER);
    2432             : 
    2433           1 :     setCurrentModified( sal_False );
    2434           1 : }
    2435             : 
    2436             : //------------------------------------------------------------------------------
    2437           0 : void SbaXDataBrowserController::SelectionChanged()
    2438             : {
    2439             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::SelectionChanged" );
    2440             :     // not interested in
    2441           0 : }
    2442             : 
    2443             : //------------------------------------------------------------------------------
    2444           5 : void SbaXDataBrowserController::CellActivated()
    2445             : {
    2446             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::CellActivated" );
    2447           5 :     m_aInvalidateClipboard.Start();
    2448           5 :     OnInvalidateClipboard( NULL );
    2449           5 : }
    2450             : 
    2451             : //------------------------------------------------------------------------------
    2452           2 : void SbaXDataBrowserController::CellDeactivated()
    2453             : {
    2454             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::CellDeactivated" );
    2455           2 :     m_aInvalidateClipboard.Stop();
    2456           2 :     OnInvalidateClipboard( NULL );
    2457           2 : }
    2458             : 
    2459             : //------------------------------------------------------------------------------
    2460           0 : IMPL_LINK_NOARG(SbaXDataBrowserController, OnClipboardChanged)
    2461             : {
    2462           0 :     SolarMutexGuard aGuard;
    2463           0 :     return OnInvalidateClipboard( NULL );
    2464             : }
    2465             : 
    2466             : //------------------------------------------------------------------------------
    2467           9 : IMPL_LINK(SbaXDataBrowserController, OnInvalidateClipboard, AutoTimer*, _pTimer)
    2468             : {
    2469           8 :     InvalidateFeature(ID_BROWSER_CUT);
    2470           8 :     InvalidateFeature(ID_BROWSER_COPY);
    2471             : 
    2472             :     // if the invalidation was triggered by the timer, we do not need to invalidate PASTE.
    2473             :     // The timer is only for checking the CUT/COPY slots regulariry, which depend on the
    2474             :     // selection state of the active cell
    2475             :     // TODO: get a callback at the Edit which allows to be notified when the selection
    2476             :     // changes. This would be much better than this cycle-eating polling mechanism here ....
    2477           8 :     if ( _pTimer != &m_aInvalidateClipboard )
    2478           7 :         InvalidateFeature(ID_BROWSER_PASTE);
    2479             : 
    2480           8 :     return 0L;
    2481             : }
    2482             : 
    2483             : // -------------------------------------------------------------------------
    2484          12 : Reference< XPropertySet >  SbaXDataBrowserController::getBoundField(sal_uInt16 nViewPos) const
    2485             : {
    2486             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::SaveData" );
    2487          12 :     Reference< XPropertySet >  xEmptyReturn;
    2488             : 
    2489             :     // get the current column from the grid
    2490          12 :     if (nViewPos == (sal_uInt16)-1)
    2491             :     {
    2492          12 :         Reference< ::com::sun::star::form::XGrid >  xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
    2493          12 :         if (!xGrid.is())
    2494           0 :             return xEmptyReturn;
    2495          12 :         nViewPos = xGrid->getCurrentColumnPosition();
    2496             :     }
    2497          12 :     sal_uInt16 nCurrentCol = getBrowserView()->View2ModelPos(nViewPos);
    2498          12 :     if (nCurrentCol == (sal_uInt16)-1)
    2499           0 :         return xEmptyReturn;
    2500             : 
    2501             :     // get the according column from the model
    2502          24 :     Reference< ::com::sun::star::container::XIndexContainer >  xCols(getControlModel(), UNO_QUERY);
    2503          24 :     Reference< XPropertySet >  xCurrentCol(xCols->getByIndex(nCurrentCol),UNO_QUERY);
    2504          12 :     if (!xCurrentCol.is())
    2505           0 :         return xEmptyReturn;
    2506             : 
    2507          12 :     xEmptyReturn.set(xCurrentCol->getPropertyValue(PROPERTY_BOUNDFIELD) ,UNO_QUERY);
    2508          12 :     return xEmptyReturn;
    2509             : }
    2510             : 
    2511             : //------------------------------------------------------------------------------
    2512           0 : IMPL_LINK(SbaXDataBrowserController, OnSearchContextRequest, FmSearchContext*, pContext)
    2513             : {
    2514           0 :     Reference< ::com::sun::star::container::XIndexAccess >  xPeerContainer(getBrowserView()->getGridControl(), UNO_QUERY);
    2515             : 
    2516             :     // check all grid columns for their control source
    2517           0 :     Reference< ::com::sun::star::container::XIndexAccess >  xModelColumns(getFormComponent(), UNO_QUERY);
    2518             :     OSL_ENSURE(xModelColumns.is(), "SbaXDataBrowserController::OnSearchContextRequest : there is a grid control without columns !");
    2519             :         // the case 'no columns' should be indicated with an empty container, I think ...
    2520             :     OSL_ENSURE(xModelColumns->getCount() >= xPeerContainer->getCount(), "SbaXDataBrowserController::OnSearchContextRequest : impossible : have more view than model columns !");
    2521             : 
    2522           0 :     OUString sFieldList;
    2523           0 :     for (sal_Int32 nViewPos=0; nViewPos<xPeerContainer->getCount(); ++nViewPos)
    2524             :     {
    2525           0 :         Reference< XInterface >  xCurrentColumn(xPeerContainer->getByIndex(nViewPos),UNO_QUERY);
    2526           0 :         if (!xCurrentColumn.is())
    2527           0 :             continue;
    2528             : 
    2529             :         // can we use this column control for searching ?
    2530           0 :         if (!IsSearchableControl(xCurrentColumn))
    2531           0 :             continue;
    2532             : 
    2533           0 :         sal_uInt16 nModelPos = getBrowserView()->View2ModelPos((sal_uInt16)nViewPos);
    2534           0 :         Reference< XPropertySet >  xCurrentColModel(xModelColumns->getByIndex(nModelPos),UNO_QUERY);
    2535           0 :         OUString aName = ::comphelper::getString(xCurrentColModel->getPropertyValue(PROPERTY_CONTROLSOURCE));
    2536             : 
    2537           0 :         sFieldList += aName + ";";
    2538             : 
    2539           0 :         pContext->arrFields.push_back(xCurrentColumn);
    2540           0 :     }
    2541           0 :     sFieldList = comphelper::string::stripEnd(sFieldList, ';');
    2542             : 
    2543           0 :     pContext->xCursor.set(getRowSet(),UNO_QUERY);
    2544           0 :     pContext->strUsedFields = sFieldList;
    2545             : 
    2546             :     // if the cursor is in a mode other than STANDARD -> reset
    2547           0 :     Reference< XPropertySet >  xCursorSet(pContext->xCursor, UNO_QUERY);
    2548             :     OSL_ENSURE(xCursorSet.is() && !::comphelper::getBOOL(xCursorSet->getPropertyValue(PROPERTY_ISMODIFIED)),
    2549             :         "SbaXDataBrowserController::OnSearchContextRequest : please do not call for cursors with modified rows !");
    2550           0 :     if (xCursorSet.is() && ::comphelper::getBOOL(xCursorSet->getPropertyValue(PROPERTY_ISNEW)))
    2551             :     {
    2552           0 :         Reference< XResultSetUpdate >  xUpdateCursor(pContext->xCursor, UNO_QUERY);
    2553           0 :         xUpdateCursor->moveToCurrentRow();
    2554             :     }
    2555           0 :     return pContext->arrFields.size();
    2556             : }
    2557             : 
    2558             : //------------------------------------------------------------------------------
    2559           0 : IMPL_LINK(SbaXDataBrowserController, OnFoundData, FmFoundRecordInformation*, pInfo)
    2560             : {
    2561           0 :     Reference< ::com::sun::star::sdbcx::XRowLocate >  xCursor(getRowSet(), UNO_QUERY);
    2562             :     OSL_ENSURE(xCursor.is(), "SbaXDataBrowserController::OnFoundData : xCursor is empty");
    2563             : 
    2564             :     // move the cursor
    2565           0 :     xCursor->moveToBookmark(pInfo->aPosition);
    2566             : 
    2567             :     // let the grid snyc it's display with the cursor
    2568           0 :     Reference< XPropertySet >  xModelSet(getControlModel(), UNO_QUERY);
    2569             :     OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::OnFoundData : no model set ?!");
    2570           0 :     Any aOld = xModelSet->getPropertyValue("DisplayIsSynchron");
    2571           0 :     xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(sal_Bool(sal_True)));
    2572           0 :     xModelSet->setPropertyValue("DisplayIsSynchron", aOld);
    2573             : 
    2574             :     // and move to the field
    2575           0 :     Reference< ::com::sun::star::container::XIndexAccess >  aColumnControls(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
    2576             :     sal_uInt16 nViewPos;
    2577             : 
    2578           0 :     for ( nViewPos = 0; nViewPos < aColumnControls->getCount(); ++nViewPos )
    2579             :     {
    2580           0 :         Reference< XInterface >  xCurrent(aColumnControls->getByIndex(nViewPos),UNO_QUERY);
    2581           0 :         if (IsSearchableControl(xCurrent))
    2582             :         {
    2583           0 :             if (pInfo->nFieldPos)
    2584           0 :                 --pInfo->nFieldPos;
    2585             :             else
    2586           0 :                 break;
    2587             :         }
    2588           0 :     }
    2589             : 
    2590           0 :     Reference< ::com::sun::star::form::XGrid >  xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
    2591           0 :     xGrid->setCurrentColumnPosition(nViewPos);
    2592             : 
    2593           0 :     return 0;
    2594             : }
    2595             : 
    2596             : //------------------------------------------------------------------------------
    2597           0 : IMPL_LINK(SbaXDataBrowserController, OnCanceledNotFound, FmFoundRecordInformation*, pInfo)
    2598             : {
    2599           0 :     Reference< ::com::sun::star::sdbcx::XRowLocate >  xCursor(getRowSet(), UNO_QUERY);
    2600             : 
    2601             :     try
    2602             :     {
    2603             :         OSL_ENSURE(xCursor.is(), "SbaXDataBrowserController::OnCanceledNotFound : xCursor is empty");
    2604             :         // move the cursor
    2605           0 :         xCursor->moveToBookmark(pInfo->aPosition);
    2606             :     }
    2607           0 :     catch( const Exception& )
    2608             :     {
    2609             :         DBG_UNHANDLED_EXCEPTION();
    2610             :     }
    2611             : 
    2612             :     try
    2613             :     {
    2614             :         // let the grid snyc its display with the cursor
    2615           0 :         Reference< XPropertySet >  xModelSet(getControlModel(), UNO_QUERY);
    2616             :         OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::OnCanceledNotFound : no model set ?!");
    2617           0 :         Any aOld = xModelSet->getPropertyValue("DisplayIsSynchron");
    2618           0 :         xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(sal_Bool(sal_True)));
    2619           0 :         xModelSet->setPropertyValue("DisplayIsSynchron", aOld);
    2620             :     }
    2621           0 :     catch( const Exception& )
    2622             :     {
    2623             :         DBG_UNHANDLED_EXCEPTION();
    2624             :     }
    2625             : 
    2626           0 :     return 0L;
    2627             : }
    2628             : 
    2629             : //------------------------------------------------------------------------------
    2630           2 : IMPL_LINK_NOARG(SbaXDataBrowserController, OnAsyncGetCellFocus)
    2631             : {
    2632           1 :     SbaGridControl* pVclGrid = getBrowserView() ? getBrowserView()->getVclControl() : NULL;
    2633             :     // if we have a controller, but the window for the controller doesn't have the focus, we correct this
    2634           1 :     if(pVclGrid)
    2635             :     {
    2636           1 :         if (!pVclGrid->IsEditing())
    2637           1 :             return 0L;
    2638             : 
    2639           0 :         if (pVclGrid->HasChildPathFocus())
    2640           0 :             pVclGrid->Controller()->GetWindow().GrabFocus();
    2641             :     }
    2642             : 
    2643           0 :     return 0L;
    2644             : }
    2645             : 
    2646             : //------------------------------------------------------------------------------
    2647           0 : void SbaXDataBrowserController::criticalFail()
    2648             : {
    2649             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::criticalFail" );
    2650           0 :     InvalidateAll();
    2651           0 :     m_nRowSetPrivileges = 0;
    2652           0 : }
    2653             : 
    2654             : //------------------------------------------------------------------------------
    2655           1 : void SbaXDataBrowserController::LoadFinished(sal_Bool /*bWasSynch*/)
    2656             : {
    2657             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::LoadFinished" );
    2658           1 :     m_nRowSetPrivileges = 0;
    2659             : 
    2660           1 :     if (isValid() && !loadingCancelled())
    2661             :     {
    2662             :         // obtain cached values
    2663             :         try
    2664             :         {
    2665           1 :             Reference< XPropertySet > xFormProps( m_xLoadable, UNO_QUERY_THROW );
    2666           1 :             OSL_VERIFY( xFormProps->getPropertyValue( PROPERTY_PRIVILEGES ) >>= m_nRowSetPrivileges );
    2667             :         }
    2668           0 :         catch( const Exception& )
    2669             :         {
    2670             :             DBG_UNHANDLED_EXCEPTION();
    2671             :         }
    2672             : 
    2673             :         // --------------------------------
    2674             :         // switch the control to alive mode
    2675           1 :         getBrowserView()->getGridControl()->setDesignMode(sal_False);
    2676             : 
    2677             :         // -------------------------------
    2678           1 :         initializeParser();
    2679             : 
    2680             :         // -------------------------------
    2681           1 :         InvalidateAll();
    2682             : 
    2683           1 :         m_aAsyncGetCellFocus.Call();
    2684             :     }
    2685           1 : }
    2686             : // -----------------------------------------------------------------------------
    2687           1 : void SbaXDataBrowserController::initializeParser() const
    2688             : {
    2689             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::initializeParser" );
    2690           1 :     if ( !m_xParser.is() )
    2691             :     {
    2692             :         // ----------------------------------------------
    2693             :         // create a parser (needed for filtering/sorting)
    2694             :         try
    2695             :         {
    2696           0 :             const Reference< XPropertySet >  xFormSet(getRowSet(), UNO_QUERY);
    2697           0 :             if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)))
    2698             :             {   // (only if the statement isn't native)
    2699             :                 // (it is allowed to use the PROPERTY_ISPASSTHROUGH : _after_ loading a form it is valid)
    2700           0 :                 xFormSet->getPropertyValue(PROPERTY_SINGLESELECTQUERYCOMPOSER) >>= m_xParser;
    2701           0 :             }
    2702             :         }
    2703           0 :         catch(Exception&)
    2704             :         {
    2705             :             DBG_UNHANDLED_EXCEPTION();
    2706           0 :             m_xParser = NULL;
    2707             :             // no further handling, we ignore the error
    2708             :         }
    2709             :     }
    2710           1 : }
    2711             : //------------------------------------------------------------------------------
    2712           1 : void SbaXDataBrowserController::loaded(const EventObject& /*aEvent*/) throw( RuntimeException )
    2713             : {
    2714             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::loaded" );
    2715             :     // not interested in
    2716             :     // we're loading within an separate thread and have a handling  for it's "finished event"
    2717           1 : }
    2718             : 
    2719             : //------------------------------------------------------------------------------
    2720           0 : void SbaXDataBrowserController::unloading(const EventObject& /*aEvent*/) throw( RuntimeException )
    2721             : {
    2722             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::unloading" );
    2723             :     // not interested in
    2724           0 : }
    2725             : 
    2726             : //------------------------------------------------------------------------------
    2727           0 : void SbaXDataBrowserController::unloaded(const EventObject& /*aEvent*/) throw( RuntimeException )
    2728             : {
    2729             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::unloaded" );
    2730           0 :     m_xParser.clear();
    2731           0 :     InvalidateAll();
    2732             :         // do this asynchronously, there are other listeners reacting on this message ...
    2733             :         // (it's a little hack : the grid columns are listening to this event, too, and their bound field may
    2734             :         // change as a reaction on that event. as we have no chance to be notified of this change (which is
    2735             :         // the one we're interested in) we give them time to do what they want to before invalidating our
    2736             :         // bound-field-dependent slots ....
    2737           0 : }
    2738             : 
    2739             : //------------------------------------------------------------------------------
    2740           0 : void SbaXDataBrowserController::reloading(const EventObject& /*aEvent*/) throw( RuntimeException )
    2741             : {
    2742             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::reloading" );
    2743             :     // not interested in
    2744           0 : }
    2745             : 
    2746             : //------------------------------------------------------------------------------
    2747           0 : void SbaXDataBrowserController::reloaded(const EventObject& /*aEvent*/) throw( RuntimeException )
    2748             : {
    2749             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::reloaded" );
    2750           0 :     InvalidateAll();
    2751             :         // do this asynchronously, there are other listeners reacting on this message ...
    2752             :         // (it's a little hack : the grid columns are listening to this event, too, and their bound field may
    2753             :         // change as a reaction on that event. as we have no chance to be notified of this change (which is
    2754             :         // the one we're interested in) we give them time to do what they want to before invalidating our
    2755             :         // bound-field-dependent slots ....
    2756           0 : }
    2757             : //------------------------------------------------------------------------------
    2758           3 : void SbaXDataBrowserController::enterFormAction()
    2759             : {
    2760           3 :     if ( !m_nFormActionNestingLevel )
    2761             :         // first action -> reset
    2762           2 :         m_aCurrentError.clear();
    2763             : 
    2764           3 :     ++m_nFormActionNestingLevel;
    2765           3 : }
    2766             : 
    2767             : //------------------------------------------------------------------------------
    2768           3 : void SbaXDataBrowserController::leaveFormAction()
    2769             : {
    2770             :     OSL_ENSURE( m_nFormActionNestingLevel > 0, "SbaXDataBrowserController::leaveFormAction : invalid call !" );
    2771           3 :     if ( --m_nFormActionNestingLevel > 0 )
    2772           1 :         return;
    2773             : 
    2774           2 :     if ( !m_aCurrentError.isValid() )
    2775           2 :         return;
    2776             : 
    2777           0 :     m_aAsyncDisplayError.Call();
    2778             : }
    2779             : 
    2780             : // -------------------------------------------------------------------------
    2781         189 : sal_Bool SbaXDataBrowserController::isLoaded() const
    2782             : {
    2783             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::isLoaded" );
    2784         189 :     return m_xLoadable.is() && m_xLoadable->isLoaded();
    2785             : }
    2786             : 
    2787             : // -------------------------------------------------------------------------
    2788         208 : sal_Bool SbaXDataBrowserController::isValidCursor() const
    2789             : {
    2790             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::isValidCursor" );
    2791         208 :     if (!m_xColumnsSupplier.is())
    2792           0 :         return sal_False;
    2793         208 :     Reference< ::com::sun::star::container::XNameAccess >  xCols = m_xColumnsSupplier->getColumns();
    2794         208 :     if (!xCols.is() || !xCols->hasElements())
    2795           0 :         return sal_False;
    2796             : 
    2797         208 :     sal_Bool bIsValid = !(m_xRowSet->isBeforeFirst() || m_xRowSet->isAfterLast());
    2798         208 :     if ( !bIsValid )
    2799             :     {
    2800           0 :         Reference<XPropertySet> xProp(m_xRowSet,UNO_QUERY);
    2801           0 :         bIsValid = ::cppu::any2bool(xProp->getPropertyValue(PROPERTY_ISNEW));
    2802           0 :         if ( !bIsValid )
    2803             :         {
    2804           0 :             bIsValid = m_xParser.is();
    2805           0 :         }
    2806             :     }
    2807         208 :     return bIsValid;
    2808             : }
    2809             : 
    2810             : // -----------------------------------------------------------------------------
    2811           0 : sal_Int16 SbaXDataBrowserController::getCurrentColumnPosition()
    2812             : {
    2813             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::getCurrentColumnPosition" );
    2814           0 :     Reference< ::com::sun::star::form::XGrid >  xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
    2815           0 :     sal_Int16 nViewPos = -1;
    2816             :     try
    2817             :     {
    2818           0 :         if ( xGrid.is() )
    2819           0 :             nViewPos = xGrid->getCurrentColumnPosition();
    2820             :     }
    2821           0 :     catch(Exception&) {}
    2822           0 :     return nViewPos;
    2823             : }
    2824             : // -----------------------------------------------------------------------------
    2825           0 : void SbaXDataBrowserController::setCurrentColumnPosition( sal_Int16 _nPos )
    2826             : {
    2827             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::setCurrentColumnPosition" );
    2828           0 :     Reference< ::com::sun::star::form::XGrid >  xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
    2829             :     try
    2830             :     {
    2831           0 :         if ( -1 != _nPos )
    2832           0 :             xGrid->setCurrentColumnPosition(_nPos);
    2833             :     }
    2834           0 :     catch(Exception&) {}
    2835           0 : }
    2836             : // -----------------------------------------------------------------------------
    2837           0 : void SbaXDataBrowserController::BeforeDrop()
    2838             : {
    2839             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::BeforeDrop" );
    2840           0 :     Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster >  xFormError(getRowSet(), UNO_QUERY);
    2841           0 :     if (xFormError.is())
    2842           0 :         xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
    2843           0 : }
    2844             : // -----------------------------------------------------------------------------
    2845           0 : void SbaXDataBrowserController::AfterDrop()
    2846             : {
    2847             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::AfterDrop" );
    2848           0 :     Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster >  xFormError(getRowSet(), UNO_QUERY);
    2849           0 :     if (xFormError.is())
    2850           0 :         xFormError->addSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
    2851           0 : }
    2852             : // -----------------------------------------------------------------------------
    2853           1 : void SbaXDataBrowserController::addColumnListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
    2854             : {
    2855             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::addColumnListeners" );
    2856             : // ... all the grid columns
    2857           1 :     Reference< ::com::sun::star::container::XIndexContainer >  xColumns(_xGridControlModel, UNO_QUERY);
    2858           1 :     if (xColumns.is())
    2859             :     {
    2860           1 :         sal_Int32 nCount = xColumns->getCount();
    2861           1 :         for (sal_uInt16 i=0; i < nCount; ++i)
    2862             :         {
    2863           0 :             Reference< XPropertySet >  xCol(xColumns->getByIndex(i),UNO_QUERY);
    2864           0 :             AddColumnListener(xCol);
    2865           0 :         }
    2866           1 :     }
    2867           1 : }
    2868             : // -----------------------------------------------------------------------------
    2869           0 : sal_Bool SbaXDataBrowserController::InitializeGridModel(const Reference< ::com::sun::star::form::XFormComponent > & /*xGrid*/)
    2870             : {
    2871             :     SAL_INFO("dbaccess.ui", "SbaXDataBrowserController::InitializeGridModel" );
    2872           0 :     return sal_True;
    2873             : }
    2874             : //..................................................................
    2875          12 : }   // namespace dbaui
    2876             : //..................................................................
    2877             : 
    2878             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10