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

Generated by: LCOV version 1.10