LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/browser - genericcontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 364 674 54.0 %
Date: 2013-07-09 Functions: 60 108 55.6 %
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 <dbaccess/genericcontroller.hxx>
      21             : #include <comphelper/uno3.hxx>
      22             : #include <toolkit/awt/vclxwindow.hxx>
      23             : #include "browserids.hxx"
      24             : #include <vcl/svapp.hxx>
      25             : #include <toolkit/helper/vclunohelper.hxx>
      26             : #include <dbaccess/dataview.hxx>
      27             : #include <tools/diagnose_ex.h>
      28             : #include <osl/diagnose.h>
      29             : #include "dbustrings.hrc"
      30             : #include <vcl/stdtext.hxx>
      31             : #include <comphelper/processfactory.hxx>
      32             : #include <cppuhelper/typeprovider.hxx>
      33             : #include <framework/titlehelper.hxx>
      34             : #include <comphelper/sequence.hxx>
      35             : #include <comphelper/extract.hxx>
      36             : #include <com/sun/star/sdbc/XDataSource.hpp>
      37             : #include <com/sun/star/sdb/DatabaseContext.hpp>
      38             : #include <com/sun/star/sdb/SQLContext.hpp>
      39             : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      40             : #include <com/sun/star/beans/XPropertySet.hpp>
      41             : #include <com/sun/star/task/XInteractionHandler.hpp>
      42             : #include <com/sun/star/util/URLTransformer.hpp>
      43             : #include <com/sun/star/util/XCloseable.hpp>
      44             : #include "UITools.hxx"
      45             : #include "commontypes.hxx"
      46             : 
      47             : #include <vcl/waitobj.hxx>
      48             : #include <svl/urihelper.hxx>
      49             : #include "datasourceconnector.hxx"
      50             : #include <unotools/moduleoptions.hxx>
      51             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      52             : #include <com/sun/star/frame/status/Visibility.hpp>
      53             : #include <com/sun/star/util/XModifiable.hpp>
      54             : #include <rtl/ustring.hxx>
      55             : #include <algorithm>
      56             : #include <o3tl/compat_functional.hxx>
      57             : #include <boost/unordered_map.hpp>
      58             : #include <cppuhelper/implbase1.hxx>
      59             : #include <limits>
      60             : 
      61             : using namespace ::com::sun::star;
      62             : using namespace ::com::sun::star::uno;
      63             : using namespace ::com::sun::star::beans;
      64             : using namespace ::com::sun::star::frame;
      65             : using namespace ::com::sun::star::frame::status;
      66             : using namespace ::com::sun::star::util;
      67             : using namespace ::com::sun::star::lang;
      68             : using namespace ::com::sun::star::container;
      69             : using namespace ::com::sun::star::sdbc;
      70             : using namespace ::com::sun::star::sdb;
      71             : using namespace ::com::sun::star::task;
      72             : using namespace ::com::sun::star::awt;
      73             : using namespace ::dbtools;
      74             : using namespace ::comphelper;
      75             : 
      76             : // -------------------------------------------------------------------------
      77             : #define ALL_FEATURES                -1
      78             : #define FIRST_USER_DEFINED_FEATURE  ( ::std::numeric_limits< sal_uInt16 >::max() - 1000 )
      79             : #define LAST_USER_DEFINED_FEATURE   ( ::std::numeric_limits< sal_uInt16 >::max()        )
      80             : 
      81             : // -------------------------------------------------------------------------
      82             : typedef ::boost::unordered_map< sal_Int16, sal_Int16 > CommandHashMap;
      83             : typedef ::std::list< DispatchInformation > DispatchInfoList;
      84             : 
      85             : 
      86             : // -------------------------------------------------------------------------
      87          30 : const OUString& getConfirmDeletionURL()
      88             : {
      89          30 :     static const OUString sConfirmDeletionURL(  ".uno:FormSlots/ConfirmDeletion" );
      90          30 :     return sConfirmDeletionURL;
      91             : }
      92             : 
      93             : namespace dbaui
      94             : {
      95             : 
      96             : //==========================================================================
      97             : //= UserDefinedFeatures
      98             : //==========================================================================
      99           1 : class UserDefinedFeatures
     100             : {
     101             : public:
     102             :     UserDefinedFeatures( const Reference< XController >& _rxController );
     103             : 
     104             :     FeatureState    getState( const URL& _rFeatureURL );
     105             :     void            execute( const URL& _rFeatureURL, const Sequence< PropertyValue>& _rArgs );
     106             : 
     107             : private:
     108             :     ::com::sun::star::uno::WeakReference< XController > m_aController;
     109             : };
     110             : 
     111             : //--------------------------------------------------------------------------
     112           1 : UserDefinedFeatures::UserDefinedFeatures( const Reference< XController >& _rxController )
     113           1 :     :m_aController( _rxController )
     114             : {
     115           1 : }
     116             : 
     117             : //--------------------------------------------------------------------------
     118           6 : FeatureState UserDefinedFeatures::getState( const URL& /*_rFeatureURL*/ )
     119             : {
     120             :     // for now, enable all the time
     121             :     // TODO: we should ask the dispatcher. However, this is laborious, since you cannot ask a dispatcher
     122             :     // directly, but need to add a status listener.
     123           6 :     FeatureState aState;
     124           6 :     aState.bEnabled = sal_True;
     125           6 :     return aState;
     126             : }
     127             : 
     128             : //--------------------------------------------------------------------------
     129           0 : void UserDefinedFeatures::execute( const URL& _rFeatureURL, const Sequence< PropertyValue>& _rArgs )
     130             : {
     131             :     try
     132             :     {
     133           0 :         Reference< XController > xController( (Reference< XController >)m_aController, UNO_SET_THROW );
     134           0 :         Reference< XDispatchProvider > xDispatchProvider( xController->getFrame(), UNO_QUERY_THROW );
     135           0 :         Reference< XDispatch > xDispatch( xDispatchProvider->queryDispatch(
     136             :             _rFeatureURL,
     137             :             OUString( "_self" ),
     138             :             FrameSearchFlag::AUTO
     139           0 :         ) );
     140             : 
     141           0 :         if ( xDispatch == xController )
     142             :         {
     143             :             SAL_WARN("dbaccess.ui", "UserDefinedFeatures::execute: the controller shouldn't be the dispatcher here!" );
     144           0 :             xDispatch.clear();
     145             :         }
     146             : 
     147           0 :         if ( xDispatch.is() )
     148           0 :             xDispatch->dispatch( _rFeatureURL, _rArgs );
     149             :     }
     150           0 :     catch( const Exception& )
     151             :     {
     152             :         DBG_UNHANDLED_EXCEPTION();
     153             :     }
     154           0 : }
     155             : 
     156             : //==========================================================================
     157             : //= OGenericUnoController_Data
     158             : //==========================================================================
     159           1 : struct OGenericUnoController_Data
     160             : {
     161             :     ::sfx2::UserInputInterception   m_aUserInputInterception;
     162             :     UserDefinedFeatures             m_aUserDefinedFeatures;
     163             : 
     164           1 :     OGenericUnoController_Data( OGenericUnoController& _rController, ::osl::Mutex& _rMutex )
     165             :         :m_aUserInputInterception( _rController, _rMutex )
     166           1 :         ,m_aUserDefinedFeatures( _rController.getXController() )
     167             :     {
     168           1 :     }
     169             : };
     170             : 
     171             : //==========================================================================
     172             : //= OGenericUnoController
     173             : //==========================================================================
     174             : DBG_NAME(OGenericUnoController)
     175             : // -------------------------------------------------------------------------
     176           1 : OGenericUnoController::OGenericUnoController(const Reference< XComponentContext >& _rM)
     177           1 :     :OGenericUnoController_Base( getMutex() )
     178             :     ,m_pView(NULL)
     179             : #ifdef DBG_UTIL
     180             :     ,m_bDescribingSupportedFeatures( false )
     181             : #endif
     182             :     ,m_aAsyncInvalidateAll(LINK(this, OGenericUnoController, OnAsyncInvalidateAll))
     183             :     ,m_aAsyncCloseTask(LINK(this, OGenericUnoController, OnAsyncCloseTask))
     184             :     ,m_xContext(_rM)
     185             :     ,m_aCurrentFrame( *this )
     186             :     ,m_bPreview(sal_False)
     187             :     ,m_bReadOnly(sal_False)
     188             :     ,m_bCurrentlyModified(sal_False)
     189           2 :     ,m_bExternalTitle(sal_False)
     190             : {
     191           1 :     osl_atomic_increment( &m_refCount );
     192             :     {
     193           1 :         m_pData.reset( new OGenericUnoController_Data( *this, getMutex() ) );
     194             :     }
     195           1 :     osl_atomic_decrement( &m_refCount );
     196             : 
     197             :     DBG_CTOR(OGenericUnoController,NULL);
     198             : 
     199             :     try
     200             :     {
     201           1 :         m_xUrlTransformer = URLTransformer::create(_rM);
     202             :     }
     203           0 :     catch(Exception&)
     204             :     {
     205             :         DBG_UNHANDLED_EXCEPTION();
     206             :     }
     207           1 : }
     208             : 
     209             : #ifdef _MSC_VER
     210             : 
     211             : #pragma warning(push)
     212             : #pragma warning(disable:4702)
     213             : 
     214             : OGenericUnoController::OGenericUnoController()
     215             :     :OGenericUnoController_Base( getMutex() )
     216             :     ,m_pView(NULL)
     217             : #ifdef DBG_UTIL
     218             :     ,m_bDescribingSupportedFeatures( false )
     219             : #endif
     220             :     ,m_aAsyncInvalidateAll(LINK(this, OGenericUnoController, OnAsyncInvalidateAll))
     221             :     ,m_aAsyncCloseTask(LINK(this, OGenericUnoController, OnAsyncCloseTask))
     222             :     ,m_aCurrentFrame( *this )
     223             :     ,m_bPreview(sal_False)
     224             :     ,m_bReadOnly(sal_False)
     225             :     ,m_bCurrentlyModified(sal_False)
     226             : {
     227             :     SAL_WARN("dbaccess.ui", "OGenericUnoController::OGenericUnoController: illegal call!" );
     228             :     // This ctor only exists because the MSVC compiler complained about an unresolved external
     229             :     // symbol. It should not be used at all. Since using it yields strange runtime problems,
     230             :     // we simply abort here.
     231             :     abort();
     232             : }
     233             : 
     234             : #pragma warning(pop)
     235             : 
     236             : #endif
     237             : 
     238             : // -----------------------------------------------------------------------------
     239           1 : OGenericUnoController::~OGenericUnoController()
     240             : {
     241             : 
     242             :     DBG_DTOR(OGenericUnoController,NULL);
     243           1 : }
     244             : 
     245             : // -----------------------------------------------------------------------------
     246           1 : sal_Bool OGenericUnoController::Construct(Window* /*pParent*/)
     247             : {
     248             :     OSL_ENSURE( getView(), "the view is NULL!" );
     249             : 
     250           1 :     if ( getView() )
     251             :     {
     252           1 :         getView()->Construct();
     253           1 :         getView()->Show();
     254             :     }
     255             : 
     256           1 :     m_aSupportedFeatures.clear();
     257           1 :     fillSupportedFeatures();
     258             : 
     259             :     // create the database context
     260             :     OSL_ENSURE(getORB().is(), "OGenericUnoController::Construct need a service factory!");
     261             :     try
     262             :     {
     263           1 :         m_xDatabaseContext = DatabaseContext::create(getORB());
     264             :     }
     265           0 :     catch(const Exception&)
     266             :     {
     267             :         SAL_WARN("dbaccess.ui","OGenericUnoController::Construct: could not create (or start listening at) the database context!");
     268             :         // at least notify the user. Though the whole component does not make any sense without the database context ...
     269           0 :         ShowServiceNotAvailableError(getView(), OUString("com.sun.star.sdb.DatabaseContext"), sal_True);
     270             :     }
     271             : 
     272           1 :     return sal_True;
     273             : }
     274             : //------------------------------------------------------------------------------
     275          12 : IMPL_LINK_NOARG(OGenericUnoController, OnAsyncInvalidateAll)
     276             : {
     277           6 :     if ( !OGenericUnoController_Base::rBHelper.bInDispose && !OGenericUnoController_Base::rBHelper.bDisposed )
     278           6 :         InvalidateFeature_Impl();
     279           6 :     return 0L;
     280             : }
     281             : // -----------------------------------------------------------------------------
     282           1 : void OGenericUnoController::impl_initialize()
     283             : {
     284           1 : }
     285             : // -------------------------------------------------------------------------
     286           1 : void SAL_CALL OGenericUnoController::initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException)
     287             : {
     288           1 :     SolarMutexGuard aSolarGuard;
     289           2 :     ::osl::MutexGuard aGuard( getMutex() );
     290             : 
     291           2 :     Reference< XWindow >        xParent;
     292           2 :     Reference< XFrame > xFrame;
     293             : 
     294           2 :     PropertyValue aValue;
     295           1 :     const Any* pIter    = aArguments.getConstArray();
     296           1 :     const Any* pEnd     = pIter + aArguments.getLength();
     297             : 
     298           9 :     for ( ; pIter != pEnd; ++pIter )
     299             :     {
     300           8 :         if ( ( *pIter >>= aValue ) && ( 0 == aValue.Name.compareToAscii( "Frame" ) ) )
     301             :         {
     302           1 :             xFrame.set(aValue.Value,UNO_QUERY_THROW);
     303             :         }
     304           7 :         else if ( ( *pIter >>= aValue ) && ( 0 == aValue.Name.compareToAscii( "Preview" ) ) )
     305             :         {
     306           0 :             aValue.Value >>= m_bPreview;
     307           0 :             m_bReadOnly = sal_True;
     308             :         }
     309             :     }
     310             :     try
     311             :     {
     312           1 :         if ( !xFrame.is() )
     313           0 :             throw IllegalArgumentException("need a frame", *this, 1 );
     314             : 
     315           1 :         xParent = xFrame->getContainerWindow();
     316           1 :         VCLXWindow* pParentComponent = VCLXWindow::GetImplementation(xParent);
     317           1 :         Window* pParentWin = pParentComponent ? pParentComponent->GetWindow() : NULL;
     318           1 :         if (!pParentWin)
     319             :         {
     320           0 :             throw IllegalArgumentException("Parent window is null", *this, 1 );
     321             :         }
     322             : 
     323           1 :         m_aInitParameters.assign( aArguments );
     324           1 :         Construct( pParentWin );
     325             : 
     326           1 :         ODataView* pView = getView();
     327           1 :         if ( !pView )
     328           0 :             throw RuntimeException("unable to create a view", *this );
     329             : 
     330           1 :         if ( m_bReadOnly || m_bPreview )
     331           0 :             pView->EnableInput( sal_False );
     332             : 
     333           1 :         impl_initialize();
     334             :     }
     335           0 :     catch(Exception&)
     336             :     {
     337             :         // no one clears my view if I won't
     338           0 :         ::std::auto_ptr<Window> aTemp(m_pView);
     339           0 :         m_pView = NULL;
     340           0 :         throw;
     341           1 :     }
     342           1 : }
     343             : 
     344             : //------------------------------------------------------------------------------
     345        1409 : void SAL_CALL OGenericUnoController::acquire(  ) throw ()
     346             : {
     347        1409 :     OGenericUnoController_Base::acquire();
     348        1409 : }
     349             : 
     350             : //------------------------------------------------------------------------------
     351        1409 : void SAL_CALL OGenericUnoController::release(  ) throw ()
     352             : {
     353        1409 :     OGenericUnoController_Base::release();
     354        1409 : }
     355             : 
     356             : // -------------------------------------------------------------------------
     357           1 : void OGenericUnoController::startFrameListening( const Reference< XFrame >& _rxFrame )
     358             : {
     359           1 :     if ( _rxFrame.is() )
     360           1 :         _rxFrame->addFrameActionListener( this );
     361           1 : }
     362             : 
     363             : // -------------------------------------------------------------------------
     364           2 : void OGenericUnoController::stopFrameListening( const Reference< XFrame >& _rxFrame )
     365             : {
     366           2 :     if ( _rxFrame.is() )
     367           1 :         _rxFrame->removeFrameActionListener( this );
     368           2 : }
     369             : 
     370             : // -------------------------------------------------------------------------
     371           1 : void OGenericUnoController::disposing(const EventObject& Source) throw( RuntimeException )
     372             : {
     373             :     // our frame ?
     374           1 :     if ( Source.Source == getFrame() )
     375           0 :         stopFrameListening( getFrame() );
     376           1 : }
     377             : //------------------------------------------------------------------------
     378           0 : void OGenericUnoController::modified(const EventObject& aEvent) throw( RuntimeException )
     379             : {
     380           0 :     ::osl::MutexGuard aGuard( getMutex() );
     381           0 :     if ( !isDataSourceReadOnly() )
     382             :     {
     383           0 :         Reference<XModifiable> xModi(aEvent.Source,UNO_QUERY);
     384           0 :         if ( xModi.is() )
     385           0 :             m_bCurrentlyModified = xModi->isModified(); // can only be reset by save
     386             :         else
     387           0 :             m_bCurrentlyModified = sal_True;
     388             :     }
     389           0 :     InvalidateFeature(ID_BROWSER_SAVEDOC);
     390           0 :     InvalidateFeature(ID_BROWSER_UNDO);
     391           0 : }
     392             : // -----------------------------------------------------------------------
     393           1 : Reference< XWindow > SAL_CALL OGenericUnoController::getComponentWindow() throw (RuntimeException)
     394             : {
     395           1 :     return VCLUnoHelper::GetInterface( getView() );
     396             : }
     397             : 
     398             : // -----------------------------------------------------------------------
     399           0 : OUString SAL_CALL OGenericUnoController::getViewControllerName() throw (::com::sun::star::uno::RuntimeException)
     400             : {
     401           0 :     return OUString( "Default" );
     402             : }
     403             : 
     404             : // -----------------------------------------------------------------------
     405           0 : Sequence< PropertyValue > SAL_CALL OGenericUnoController::getCreationArguments() throw (RuntimeException)
     406             : {
     407             :     // currently we do not support any creation args, so anything passed to XModel2::createViewController would be
     408             :     // lost, so we can equally return an empty sequence here
     409           0 :     return Sequence< PropertyValue >();
     410             : }
     411             : 
     412             : // -----------------------------------------------------------------------
     413           1 : void OGenericUnoController::attachFrame( const Reference< XFrame >& _rxFrame ) throw( RuntimeException )
     414             : {
     415           1 :     SolarMutexGuard aSolarGuard;
     416           2 :     ::osl::MutexGuard aGuard( getMutex() );
     417             : 
     418           1 :     stopFrameListening( m_aCurrentFrame.getFrame() );
     419           2 :     Reference< XFrame > xFrame = m_aCurrentFrame.attachFrame( _rxFrame );
     420           1 :     startFrameListening( xFrame );
     421             : 
     422           1 :     loadMenu( xFrame );
     423             : 
     424           1 :     if ( getView() )
     425           2 :         getView()->attachFrame( xFrame );
     426           1 : }
     427             : 
     428             : // -----------------------------------------------------------------------------
     429             : struct CommandCollector : public ::std::unary_function< SupportedFeatures::value_type, void>
     430             : {
     431             :     sal_uInt16  m_nFeature;
     432             :     StringBag&  m_rFeatureCommands;
     433         141 :     CommandCollector( sal_uInt16 _nFeature, StringBag& _rFeatureCommands )
     434             :         :m_nFeature        ( _nFeature         )
     435         141 :         ,m_rFeatureCommands( _rFeatureCommands )
     436             :     {
     437         141 :     }
     438             : 
     439        4935 :     void operator() ( const SupportedFeatures::value_type& lhs )
     440             :     {
     441        4935 :         if ( lhs.second.nFeatureId == m_nFeature )
     442         245 :             m_rFeatureCommands.insert( lhs.first );
     443        4935 :     }
     444             : };
     445             : 
     446             : // -----------------------------------------------------------------------
     447             : namespace
     448             : {
     449             :     typedef ::std::vector< Any >    States;
     450             : 
     451             :     // ...................................................................
     452         147 :     void    lcl_notifyMultipleStates( XStatusListener& _rListener, FeatureStateEvent& _rEvent, const States& _rStates )
     453             :     {
     454         882 :         for (   States::const_iterator state = _rStates.begin();
     455         588 :                 state != _rStates.end();
     456             :                 ++state
     457             :             )
     458             :         {
     459         147 :             _rEvent.State = *state;
     460         147 :             _rListener.statusChanged( _rEvent );
     461             :         }
     462         147 :     }
     463             : 
     464             :     // ...................................................................
     465         162 :     void    lcl_collectStates( const FeatureState& _rFeatureState, States& _out_rStates )
     466             :     {
     467             :         // order matters, due to a bug in framework which resets the check state when any non-boolean event
     468             :         // arrives
     469             :         // #i68215# is the bug to (re-)introduce this "ordered" notification here
     470             :         // #i67882# is the bug which was caused by the real fix which we did in framework
     471             :         // #i68216# is the bug which requests to fix the code in Draw which relies on
     472             :         //          framework's implementation details
     473         162 :         if ( !!_rFeatureState.sTitle )
     474          25 :             _out_rStates.push_back( makeAny( *_rFeatureState.sTitle ) );
     475         162 :         if ( !!_rFeatureState.bChecked )
     476          11 :             _out_rStates.push_back( makeAny( (sal_Bool)*_rFeatureState.bChecked ) );
     477         162 :         if ( !!_rFeatureState.bInvisible )
     478           0 :             _out_rStates.push_back( makeAny( Visibility( !*_rFeatureState.bInvisible ) ) );
     479         162 :         if ( _rFeatureState.aValue.hasValue() )
     480           0 :             _out_rStates.push_back( _rFeatureState.aValue );
     481         162 :         if ( _out_rStates.empty() )
     482         126 :             _out_rStates.push_back( Any() );
     483         162 :     }
     484             : }
     485             : 
     486             : // -----------------------------------------------------------------------
     487         204 : void OGenericUnoController::ImplBroadcastFeatureState(const OUString& _rFeature, const Reference< XStatusListener > & xListener, sal_Bool _bIgnoreCache)
     488             : {
     489         204 :     sal_uInt16 nFeat = m_aSupportedFeatures[ _rFeature ].nFeatureId;
     490         204 :     FeatureState aFeatState( GetState( nFeat ) );
     491             : 
     492         204 :     FeatureState& rCachedState = m_aStateCache[nFeat];  // creates if necessary
     493         204 :     if ( !_bIgnoreCache )
     494             :     {
     495             :         // check if we really need to notify the listeners : this method may be called much more often than needed, so check
     496             :         // the cached state of the feature
     497          43 :         sal_Bool bAlreadyCached = ( m_aStateCache.find(nFeat) != m_aStateCache.end() );
     498          43 :         if ( bAlreadyCached )
     499          86 :             if  (   ( rCachedState.bEnabled == aFeatState.bEnabled )
     500          42 :                 &&  ( rCachedState.bChecked == aFeatState.bChecked )
     501          42 :                 &&  ( rCachedState.bInvisible == aFeatState.bInvisible )
     502          85 :                 &&  ( rCachedState.sTitle == aFeatState.sTitle )
     503             :                 )
     504         246 :             return;
     505             :     }
     506         162 :     rCachedState = aFeatState;
     507             : 
     508         324 :     FeatureStateEvent aEvent;
     509         162 :     aEvent.FeatureURL.Complete = _rFeature;
     510         162 :     if (m_xUrlTransformer.is())
     511         162 :         m_xUrlTransformer->parseStrict(aEvent.FeatureURL);
     512         162 :     aEvent.Source       = (XDispatch*)this;
     513         162 :     aEvent.IsEnabled    = aFeatState.bEnabled;
     514             : 
     515             :     // collect all states to be notified
     516         324 :     States aStates;
     517         162 :     lcl_collectStates( aFeatState, aStates );
     518             : 
     519             :     // a special listener ?
     520         162 :     if ( xListener.is() )
     521          21 :         lcl_notifyMultipleStates( *xListener.get(), aEvent, aStates );
     522             :     else
     523             :     {   // no -> iterate through all listeners responsible for the URL
     524         141 :         StringBag aFeatureCommands;
     525             :         ::std::for_each(
     526             :             m_aSupportedFeatures.begin(),
     527             :             m_aSupportedFeatures.end(),
     528             :             CommandCollector( nFeat, aFeatureCommands )
     529         141 :         );
     530             : 
     531             :         // it is possible that listeners are registered or revoked while
     532             :         // we are notifying them, so we must use a copy of m_arrStatusListener, not
     533             :         // m_arrStatusListener itself
     534         282 :         Dispatch aNotifyLoop( m_arrStatusListener );
     535         141 :         DispatchIterator iterSearch = aNotifyLoop.begin();
     536         141 :         DispatchIterator iterEnd = aNotifyLoop.end();
     537             : 
     538        3208 :         while (iterSearch != iterEnd)
     539             :         {
     540        2926 :             DispatchTarget& rCurrent = *iterSearch;
     541        2926 :             if ( aFeatureCommands.find( rCurrent.aURL.Complete ) != aFeatureCommands.end() )
     542             :             {
     543         126 :                 aEvent.FeatureURL = rCurrent.aURL;
     544         126 :                 lcl_notifyMultipleStates( *rCurrent.xListener.get(), aEvent, aStates );
     545             :             }
     546        2926 :             ++iterSearch;
     547         141 :         }
     548         162 :     }
     549             : 
     550             : }
     551             : 
     552             : //------------------------------------------------------------------------------
     553           0 : sal_Bool OGenericUnoController::isFeatureSupported( sal_Int32 _nId )
     554             : {
     555             :     SupportedFeatures::iterator aFeaturePos = ::std::find_if(
     556             :         m_aSupportedFeatures.begin(),
     557             :         m_aSupportedFeatures.end(),
     558             :         ::std::bind2nd( CompareFeatureById(), _nId )
     559           0 :     );
     560             : 
     561           0 :     return ( m_aSupportedFeatures.end() != aFeaturePos && !aFeaturePos->first.isEmpty());
     562             : }
     563             : 
     564             : // -----------------------------------------------------------------------
     565           0 : void OGenericUnoController::InvalidateFeature(const OUString& _rURLPath, const Reference< XStatusListener > & _xListener, sal_Bool _bForceBroadcast)
     566             : {
     567           0 :     ImplInvalidateFeature( m_aSupportedFeatures[ _rURLPath ].nFeatureId, _xListener, _bForceBroadcast );
     568           0 : }
     569             : 
     570             : // -----------------------------------------------------------------------------
     571           6 : void OGenericUnoController::InvalidateFeature_Impl()
     572             : {
     573             : #ifdef DBG_UTIL
     574             :     static sal_Int32 s_nRecursions = 0;
     575             :     ++s_nRecursions;
     576             : #endif
     577             : 
     578           6 :     sal_Bool bEmpty = sal_True;
     579           6 :     FeatureListener aNextFeature;
     580             :     {
     581           6 :         ::osl::MutexGuard aGuard( m_aFeatureMutex);
     582           6 :         bEmpty = m_aFeaturesToInvalidate.empty();
     583           6 :         if (!bEmpty)
     584           6 :             aNextFeature = m_aFeaturesToInvalidate.front();
     585             :     }
     586          55 :     while(!bEmpty)
     587             :     {
     588          47 :         if ( ALL_FEATURES == aNextFeature.nId )
     589             :         {
     590           4 :             InvalidateAll_Impl();
     591           8 :             break;
     592             :         }
     593             :         else
     594             :         {
     595             :             SupportedFeatures::iterator aFeaturePos = ::std::find_if(
     596             :                 m_aSupportedFeatures.begin(),
     597             :                 m_aSupportedFeatures.end(),
     598             :                 ::std::bind2nd( CompareFeatureById(), aNextFeature.nId )
     599          43 :             );
     600             : 
     601             : #if OSL_DEBUG_LEVEL > 0
     602             :             if ( m_aSupportedFeatures.end() == aFeaturePos )
     603             :             {
     604             :                 OString sMessage( "OGenericUnoController::InvalidateFeature_Impl: feature id " );
     605             :                 sMessage += OString::valueOf( aNextFeature.nId );
     606             :                 sMessage += OString( " has been invalidated, but is not supported!" );
     607             :                 SAL_WARN("dbaccess.ui", sMessage.getStr() );
     608             :             }
     609             : #endif
     610          43 :             if ( m_aSupportedFeatures.end() != aFeaturePos )
     611             :                 // we really know this feature
     612          43 :                 ImplBroadcastFeatureState( aFeaturePos->first, aNextFeature.xListener, aNextFeature.bForceBroadcast );
     613             :         }
     614             : 
     615          43 :         ::osl::MutexGuard aGuard( m_aFeatureMutex);
     616          43 :         m_aFeaturesToInvalidate.pop_front();
     617          43 :         bEmpty = m_aFeaturesToInvalidate.empty();
     618          43 :         if (!bEmpty)
     619          41 :             aNextFeature = m_aFeaturesToInvalidate.front();
     620          49 :     }
     621             : 
     622             : #ifdef DBG_UTIL
     623             :     --s_nRecursions;
     624             : #endif
     625           6 : }
     626             : 
     627             : // -----------------------------------------------------------------------
     628          53 : void OGenericUnoController::ImplInvalidateFeature( sal_Int32 _nId, const Reference< XStatusListener >& _xListener, sal_Bool _bForceBroadcast )
     629             : {
     630             : #if OSL_DEBUG_LEVEL > 0
     631             :     if ( _nId != -1 )
     632             :     {
     633             :         SupportedFeatures::iterator aFeaturePos = ::std::find_if(
     634             :             m_aSupportedFeatures.begin(),
     635             :             m_aSupportedFeatures.end(),
     636             :             ::std::bind2nd( CompareFeatureById(), _nId )
     637             :         );
     638             :         OSL_ENSURE( aFeaturePos != m_aSupportedFeatures.end(), "OGenericUnoController::ImplInvalidateFeature: invalidating an unsupported feature is suspicious, at least!" );
     639             :     }
     640             : #endif
     641             : 
     642          53 :     FeatureListener aListener;
     643          53 :     aListener.nId               = _nId;
     644          53 :     aListener.xListener         = _xListener;
     645          53 :     aListener.bForceBroadcast   = _bForceBroadcast;
     646             : 
     647             :     sal_Bool bWasEmpty;
     648             :     {
     649          53 :         ::osl::MutexGuard aGuard( m_aFeatureMutex );
     650          53 :         bWasEmpty = m_aFeaturesToInvalidate.empty();
     651          53 :         m_aFeaturesToInvalidate.push_back( aListener );
     652             :     }
     653             : 
     654          53 :     if ( bWasEmpty )
     655           4 :         m_aAsyncInvalidateAll.Call();
     656          53 : }
     657             : 
     658             : // -----------------------------------------------------------------------
     659          49 : void OGenericUnoController::InvalidateFeature(sal_uInt16 _nId, const Reference< XStatusListener > & _xListener, sal_Bool _bForceBroadcast)
     660             : {
     661          49 :     ImplInvalidateFeature( _nId, _xListener, _bForceBroadcast );
     662          49 : }
     663             : 
     664             : // -----------------------------------------------------------------------
     665           4 : void OGenericUnoController::InvalidateAll()
     666             : {
     667           4 :     ImplInvalidateFeature( ALL_FEATURES, NULL, sal_True );
     668           4 : }
     669             : 
     670             : // -----------------------------------------------------------------------------
     671           4 : void OGenericUnoController::InvalidateAll_Impl()
     672             : {
     673             :     // ---------------------------------
     674             :     // invalidate all supported features
     675             : 
     676         432 :     for (   SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.begin();
     677         288 :             aIter != m_aSupportedFeatures.end();
     678             :             ++aIter
     679             :         )
     680         140 :         ImplBroadcastFeatureState( aIter->first, NULL, sal_True );
     681             : 
     682             :     {
     683           4 :         ::osl::MutexGuard aGuard( m_aFeatureMutex);
     684             :         OSL_ENSURE(m_aFeaturesToInvalidate.size(), "OGenericUnoController::InvalidateAll_Impl: to be called from within InvalidateFeature_Impl only!");
     685           4 :         m_aFeaturesToInvalidate.pop_front();
     686           4 :         if(!m_aFeaturesToInvalidate.empty())
     687           3 :             m_aAsyncInvalidateAll.Call();
     688             :     }
     689           4 : }
     690             : 
     691             : // -----------------------------------------------------------------------
     692          30 : Reference< XDispatch >  OGenericUnoController::queryDispatch(const URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException )
     693             : {
     694          30 :     Reference< XDispatch > xReturn;
     695             : 
     696             :     OSL_PRECOND( !m_aSupportedFeatures.empty(), "OGenericUnoController::queryDispatch: shouldn't this be filled at construction time?" );
     697          30 :     if ( m_aSupportedFeatures.empty() )
     698           0 :         fillSupportedFeatures();
     699             : 
     700             :     // URL's we can handle ourself?
     701          90 :     if  (   aURL.Complete.equals( getConfirmDeletionURL() )
     702         141 :         ||  (   ( m_aSupportedFeatures.find( aURL.Complete ) != m_aSupportedFeatures.end() )
     703          21 :             &&  !isUserDefinedFeature( aURL.Complete )
     704             :             )
     705             :         )
     706             :     {
     707          21 :         xReturn = this;
     708             :     }
     709             :     // no? -> ask the slave dispatcher
     710           9 :     else if ( m_xSlaveDispatcher.is() )
     711             :     {
     712           9 :         xReturn = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
     713             :     }
     714             : 
     715             :     // outta here
     716          30 :     return xReturn;
     717             : }
     718             : 
     719             : // -----------------------------------------------------------------------
     720           0 : Sequence< Reference< XDispatch > > OGenericUnoController::queryDispatches(const Sequence< DispatchDescriptor >& aDescripts) throw( RuntimeException )
     721             : {
     722           0 :     Sequence< Reference< XDispatch > > aReturn;
     723           0 :     sal_Int32 nLen = aDescripts.getLength();
     724           0 :     if ( nLen )
     725             :     {
     726           0 :         aReturn.realloc( nLen );
     727           0 :                 Reference< XDispatch >* pReturn     = aReturn.getArray();
     728           0 :         const   Reference< XDispatch >* pReturnEnd  = aReturn.getArray() + nLen;
     729           0 :         const   DispatchDescriptor*     pDescripts  = aDescripts.getConstArray();
     730             : 
     731           0 :         for ( ; pReturn != pReturnEnd; ++ pReturn, ++pDescripts )
     732             :         {
     733           0 :             *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
     734             :         }
     735             :     }
     736             : 
     737           0 :     return aReturn;
     738             : }
     739             : 
     740             : // -----------------------------------------------------------------------
     741           2 : Reference< XDispatchProvider >  OGenericUnoController::getSlaveDispatchProvider(void) throw( RuntimeException )
     742             : {
     743           2 :     return m_xSlaveDispatcher;
     744             : }
     745             : 
     746             : // -----------------------------------------------------------------------
     747           2 : void OGenericUnoController::setSlaveDispatchProvider(const Reference< XDispatchProvider > & _xNewProvider) throw( RuntimeException )
     748             : {
     749           2 :     m_xSlaveDispatcher = _xNewProvider;
     750           2 : }
     751             : 
     752             : // -----------------------------------------------------------------------
     753           1 : Reference< XDispatchProvider >  OGenericUnoController::getMasterDispatchProvider(void) throw( RuntimeException )
     754             : {
     755           1 :     return m_xMasterDispatcher;
     756             : }
     757             : 
     758             : // -----------------------------------------------------------------------
     759           2 : void OGenericUnoController::setMasterDispatchProvider(const Reference< XDispatchProvider > & _xNewProvider) throw( RuntimeException )
     760             : {
     761           2 :     m_xMasterDispatcher = _xNewProvider;
     762           2 : }
     763             : 
     764             : // -----------------------------------------------------------------------
     765           0 : void OGenericUnoController::dispatch(const URL& _aURL, const Sequence< PropertyValue >& aArgs) throw(RuntimeException)
     766             : {
     767           0 :     SolarMutexGuard aSolarGuard;
     768             :     // The SolarMutex is not locked anymore when the framework calls into
     769             :     // here. So, lock it ourself. The real solution would be to lock it only in the places
     770             :     // where it's needed, but a) this might turn out difficult, since we then also need to care
     771             :     // for locking in the proper order (SolarMutex and m_aMutex), and b) this would be too many places
     772             :     // for the time frame of the fix.
     773             :     // #i52602#
     774             : 
     775             : #ifdef TIMELOG
     776             :     OString sLog( "OGenericUnoController::dispatch( '" );
     777             :     sLog += OString( _aURL.Main.getStr(), _aURL.Main.getLength(), osl_getThreadTextEncoding() );
     778             :     sLog += OString( "' )" );
     779             :     SAL_INFO("dbaccess.ui", "dbaccess frank.schoenheit@sun.com" << sLog.getStr() );
     780             : #endif
     781             : 
     782           0 :     executeChecked(_aURL,aArgs);
     783           0 : }
     784             : 
     785             : // -----------------------------------------------------------------------
     786          21 : void OGenericUnoController::addStatusListener(const Reference< XStatusListener > & aListener, const URL& _rURL) throw(RuntimeException)
     787             : {
     788             :     // parse the ULR now and here, this saves later parsing in each notification round
     789          21 :     URL aParsedURL( _rURL );
     790          21 :     if ( m_xUrlTransformer.is() )
     791          21 :         m_xUrlTransformer->parseStrict( aParsedURL );
     792             : 
     793             :     // remember the listener together with the URL
     794          21 :     m_arrStatusListener.insert( m_arrStatusListener.end(), DispatchTarget( aParsedURL, aListener ) );
     795             : 
     796             :     // initially broadcast the state
     797          21 :     ImplBroadcastFeatureState( aParsedURL.Complete, aListener, sal_True );
     798             :         // force the new state to be broadcast to the new listener
     799          21 : }
     800             : 
     801             : // -----------------------------------------------------------------------
     802          21 : void OGenericUnoController::removeStatusListener(const Reference< XStatusListener > & aListener, const URL& _rURL) throw(RuntimeException)
     803             : {
     804          21 :     DispatchIterator iterSearch = m_arrStatusListener.begin();
     805             : 
     806          21 :     sal_Bool bRemoveForAll = _rURL.Complete.isEmpty();
     807         232 :     while ( iterSearch != m_arrStatusListener.end() )
     808             :     {
     809         211 :         DispatchTarget& rCurrent = *iterSearch;
     810         422 :         if  (   (rCurrent.xListener == aListener)
     811         232 :             &&  (   bRemoveForAll
     812          21 :                 ||  (rCurrent.aURL.Complete.equals(_rURL.Complete))
     813             :                 )
     814             :             )
     815             :         {
     816          21 :             m_arrStatusListener.erase( iterSearch++ );
     817          21 :             if (!bRemoveForAll)
     818             :                 // remove the listener only for the given URL, so we can exit the loop after deletion
     819          21 :                 break;
     820             :         }
     821             :         else
     822         190 :             ++iterSearch;
     823             :     }
     824             : 
     825             :     OSL_PRECOND( !m_aSupportedFeatures.empty(), "OGenericUnoController::removeStatusListener: shouldn't this be filled at construction time?" );
     826          21 :     if ( m_aSupportedFeatures.empty() )
     827           0 :         fillSupportedFeatures();
     828             : 
     829          21 :     SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find(_rURL.Complete);
     830          21 :     if (aIter != m_aSupportedFeatures.end())
     831             :     {   // clear the cache for that feature
     832          21 :         StateCacheIterator aCachePos = m_aStateCache.find( aIter->second.nFeatureId );
     833          21 :         if ( aCachePos != m_aStateCache.end() )
     834          20 :             m_aStateCache.erase( aCachePos );
     835             :     }
     836             : 
     837             :     // now remove the listener from the deque
     838          21 :     ::osl::MutexGuard aGuard( m_aFeatureMutex );
     839             :     m_aFeaturesToInvalidate.erase(
     840             :         ::std::remove_if(   m_aFeaturesToInvalidate.begin(),
     841             :                             m_aFeaturesToInvalidate.end(),
     842             :                             ::std::bind2nd(FindFeatureListener(),aListener))
     843          21 :         ,m_aFeaturesToInvalidate.end());
     844          21 : }
     845             : // -----------------------------------------------------------------------------
     846           1 : void OGenericUnoController::releaseNumberForComponent()
     847             : {
     848             :     try
     849             :     {
     850           1 :         Reference< XUntitledNumbers > xUntitledProvider(getPrivateModel(), UNO_QUERY      );
     851           1 :         if ( xUntitledProvider.is() )
     852           0 :             xUntitledProvider->releaseNumberForComponent(static_cast<XWeak*>(this));
     853             :     }
     854           0 :     catch( const Exception& )
     855             :     {
     856             :         // NII
     857             :     }
     858           1 : }
     859             : // -----------------------------------------------------------------------
     860           1 : void OGenericUnoController::disposing()
     861             : {
     862             :     {
     863           1 :         EventObject aDisposeEvent;
     864           1 :         aDisposeEvent.Source = static_cast<XWeak*>(this);
     865           2 :         Dispatch aStatusListener = m_arrStatusListener;
     866           1 :         Dispatch::iterator aEnd = aStatusListener.end();
     867           2 :         for (Dispatch::iterator aIter = aStatusListener.begin(); aIter != aEnd; ++aIter)
     868             :         {
     869           1 :             aIter->xListener->disposing(aDisposeEvent);
     870             :         }
     871           2 :         m_arrStatusListener.clear();
     872             :     }
     873             : 
     874           1 :     m_xDatabaseContext = NULL;
     875             :     {
     876           1 :         ::osl::MutexGuard aGuard( m_aFeatureMutex);
     877           1 :         m_aAsyncInvalidateAll.CancelCall();
     878           1 :         m_aFeaturesToInvalidate.clear();
     879             :     }
     880             : 
     881           1 :     releaseNumberForComponent();
     882             : 
     883             :     // check out from all the objects we are listening
     884             :     // the frame
     885           1 :     stopFrameListening( m_aCurrentFrame.getFrame() );
     886           1 :     m_aCurrentFrame.attachFrame( NULL );
     887             : 
     888           1 :     m_xMasterDispatcher = NULL;
     889           1 :     m_xSlaveDispatcher = NULL;
     890           1 :     m_xTitleHelper.clear();
     891           1 :     m_xUrlTransformer.clear();
     892           1 :     m_aInitParameters.clear();
     893           1 : }
     894             : 
     895             : // -----------------------------------------------------------------------------
     896           0 : void SAL_CALL OGenericUnoController::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException)
     897             : {
     898             :     // disambiguate
     899           0 :     OGenericUnoController_Base::WeakComponentImplHelperBase::addEventListener( xListener );
     900           0 : }
     901             : 
     902             : // -----------------------------------------------------------------------------
     903           0 : void SAL_CALL OGenericUnoController::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException)
     904             : {
     905             :     // disambiguate
     906           0 :     OGenericUnoController_Base::WeakComponentImplHelperBase::removeEventListener( xListener );
     907           0 : }
     908             : 
     909             : //------------------------------------------------------------------------------
     910           1 : void OGenericUnoController::frameAction(const FrameActionEvent& aEvent) throw( RuntimeException )
     911             : {
     912           1 :     ::osl::MutexGuard aGuard( getMutex() );
     913           1 :     if ( aEvent.Frame == m_aCurrentFrame.getFrame() )
     914           1 :         m_aCurrentFrame.frameAction( aEvent.Action );
     915           1 : }
     916             : 
     917             : //------------------------------------------------------------------------------
     918          35 : void OGenericUnoController::implDescribeSupportedFeature( const sal_Char* _pAsciiCommandURL,
     919             :         sal_uInt16 _nFeatureId, sal_Int16 _nCommandGroup )
     920             : {
     921             : #ifdef DBG_UTIL
     922             :     OSL_ENSURE( m_bDescribingSupportedFeatures, "OGenericUnoController::implDescribeSupportedFeature: bad timing for this call!" );
     923             : #endif
     924             :     OSL_PRECOND( _nFeatureId < FIRST_USER_DEFINED_FEATURE, "OGenericUnoController::implDescribeSupportedFeature: invalid feature id!" );
     925             : 
     926          35 :     ControllerFeature aFeature;
     927          35 :     aFeature.Command = OUString::createFromAscii( _pAsciiCommandURL );
     928          35 :     aFeature.nFeatureId = _nFeatureId;
     929          35 :     aFeature.GroupId = _nCommandGroup;
     930             : 
     931             : #if OSL_DEBUG_LEVEL > 0
     932             :     OSL_ENSURE( m_aSupportedFeatures.find( aFeature.Command ) == m_aSupportedFeatures.end(),
     933             :         "OGenericUnoController::implDescribeSupportedFeature: this feature is already there!" );
     934             : #endif
     935          35 :     m_aSupportedFeatures[ aFeature.Command ] = aFeature;
     936          35 : }
     937             : 
     938             : //------------------------------------------------------------------------------
     939           1 : void OGenericUnoController::describeSupportedFeatures()
     940             : {
     941             :     // add all supported features
     942           1 :     implDescribeSupportedFeature( ".uno:Copy", ID_BROWSER_COPY, CommandGroup::EDIT );
     943           1 :     implDescribeSupportedFeature( ".uno:Cut", ID_BROWSER_CUT, CommandGroup::EDIT );
     944           1 :     implDescribeSupportedFeature( ".uno:Paste", ID_BROWSER_PASTE, CommandGroup::EDIT );
     945           1 :     implDescribeSupportedFeature( ".uno:ClipboardFormatItems", ID_BROWSER_CLIPBOARD_FORMAT_ITEMS );
     946           1 :     implDescribeSupportedFeature( ".uno:DSBEditDoc", ID_BROWSER_EDITDOC, CommandGroup::DOCUMENT );
     947           1 : }
     948             : 
     949             : //------------------------------------------------------------------------------
     950           6 : FeatureState OGenericUnoController::GetState( sal_uInt16 _nId ) const
     951             : {
     952           6 :     FeatureState aReturn;
     953             :         // (disabled automatically)
     954             : 
     955           6 :     switch ( _nId )
     956             :     {
     957             :         case ID_BROWSER_UNDO:
     958             :         case ID_BROWSER_SAVEDOC:
     959           0 :             aReturn.bEnabled = sal_True;
     960           0 :             break;
     961             :         default:
     962           6 :             aReturn = m_pData->m_aUserDefinedFeatures.getState( getURLForId( _nId ) );
     963           6 :             break;
     964             :     }
     965             : 
     966           6 :     return aReturn;
     967             : }
     968             : 
     969             : //------------------------------------------------------------------------------
     970           0 : void OGenericUnoController::Execute( sal_uInt16 _nId, const Sequence< PropertyValue>& _rArgs )
     971             : {
     972             :     OSL_ENSURE( isUserDefinedFeature( _nId ),
     973             :         "OGenericUnoController::Execute: responsible for user defined features only!" );
     974             : 
     975             :     // user defined features can be handled by dispatch interceptors resp. protocol handlers only.
     976             :     // So, we need to do a queryDispatch, and dispatch the URL
     977           0 :     m_pData->m_aUserDefinedFeatures.execute( getURLForId( _nId ), _rArgs );
     978           0 : }
     979             : 
     980             : //------------------------------------------------------------------------------
     981           6 : URL OGenericUnoController::getURLForId(sal_Int32 _nId) const
     982             : {
     983           6 :     URL aReturn;
     984           6 :     if ( m_xUrlTransformer.is() )
     985             :     {
     986             :         SupportedFeatures::const_iterator aIter = ::std::find_if(
     987             :             m_aSupportedFeatures.begin(),
     988             :             m_aSupportedFeatures.end(),
     989             :             ::std::bind2nd( CompareFeatureById(), _nId )
     990           6 :         );
     991             : 
     992           6 :         if ( m_aSupportedFeatures.end() != aIter && !aIter->first.isEmpty() )
     993             :         {
     994           6 :             aReturn.Complete = aIter->first;
     995           6 :             m_xUrlTransformer->parseStrict( aReturn );
     996             :         }
     997             :     }
     998           6 :     return aReturn;
     999             : }
    1000             : 
    1001             : //-------------------------------------------------------------------------
    1002          21 : bool OGenericUnoController::isUserDefinedFeature( const sal_uInt16 _nFeatureId ) const
    1003             : {
    1004          21 :     return ( _nFeatureId >= FIRST_USER_DEFINED_FEATURE ) && ( _nFeatureId < LAST_USER_DEFINED_FEATURE );
    1005             : }
    1006             : 
    1007             : //-------------------------------------------------------------------------
    1008          21 : bool OGenericUnoController::isUserDefinedFeature( const OUString& _rFeatureURL ) const
    1009             : {
    1010          21 :     SupportedFeatures::const_iterator pos = m_aSupportedFeatures.find( _rFeatureURL );
    1011             :     OSL_PRECOND( pos != m_aSupportedFeatures.end(),
    1012             :         "OGenericUnoController::isUserDefinedFeature: this is no supported feature at all!" );
    1013             : 
    1014          21 :     return ( pos != m_aSupportedFeatures.end() ) ? isUserDefinedFeature( pos->second.nFeatureId ) : false;
    1015             : }
    1016             : 
    1017             : //-------------------------------------------------------------------------
    1018           0 : sal_Bool SAL_CALL OGenericUnoController::supportsService(const OUString& ServiceName) throw(RuntimeException)
    1019             : {
    1020           0 :     Sequence< OUString > aSupported(getSupportedServiceNames());
    1021             : 
    1022           0 :     const OUString* pArray = aSupported.getConstArray();
    1023           0 :     const OUString* pArrayEnd = aSupported.getConstArray() + aSupported.getLength();
    1024             : 
    1025           0 :     for ( ;( pArray != pArrayEnd ) && !pArray->equals( ServiceName ); ++pArray )
    1026             :         ;
    1027           0 :     return pArray != pArrayEnd;
    1028             : }
    1029             : 
    1030             : // -----------------------------------------------------------------------------
    1031           1 : void OGenericUnoController::startConnectionListening(const Reference< XConnection >& _rxConnection)
    1032             : {
    1033             :     // we have to remove ourself before dispoing the connection
    1034           1 :     Reference< XComponent >  xComponent(_rxConnection, UNO_QUERY);
    1035           1 :     if (xComponent.is())
    1036           1 :         xComponent->addEventListener(static_cast<XFrameActionListener*>(this));
    1037           1 : }
    1038             : 
    1039             : // -----------------------------------------------------------------------------
    1040           0 : void OGenericUnoController::stopConnectionListening(const Reference< XConnection >& _rxConnection)
    1041             : {
    1042             :     // we have to remove ourself before dispoing the connection
    1043           0 :     Reference< XComponent >  xComponent(_rxConnection, UNO_QUERY);
    1044           0 :     if (xComponent.is())
    1045           0 :         xComponent->removeEventListener(static_cast<XFrameActionListener*>(this));
    1046           0 : }
    1047             : // -----------------------------------------------------------------------------
    1048           0 : Reference< XConnection > OGenericUnoController::connect( const Reference< XDataSource>& _xDataSource,
    1049             :     ::dbtools::SQLExceptionInfo* _pErrorInfo )
    1050             : {
    1051           0 :     WaitObject aWaitCursor( getView() );
    1052             : 
    1053           0 :     ODatasourceConnector aConnector( getORB(), getView(), OUString() );
    1054           0 :     Reference< XConnection > xConnection = aConnector.connect( _xDataSource, _pErrorInfo );
    1055           0 :     startConnectionListening( xConnection );
    1056             : 
    1057           0 :     return xConnection;
    1058             : }
    1059             : // -----------------------------------------------------------------------------
    1060           1 : Reference< XConnection > OGenericUnoController::connect( const OUString& _rDataSourceName,
    1061             :     const OUString& _rContextInformation, ::dbtools::SQLExceptionInfo* _pErrorInfo )
    1062             : {
    1063           1 :     WaitObject aWaitCursor( getView() );
    1064             : 
    1065           2 :     ODatasourceConnector aConnector( getORB(), getView(), _rContextInformation );
    1066           1 :     Reference<XConnection> xConnection = aConnector.connect( _rDataSourceName, _pErrorInfo );
    1067           1 :     startConnectionListening( xConnection );
    1068             : 
    1069           2 :     return xConnection;
    1070             : }
    1071             : 
    1072             : // -----------------------------------------------------------------------------
    1073           0 : void OGenericUnoController::showError(const SQLExceptionInfo& _rInfo)
    1074             : {
    1075           0 :     ::dbaui::showError(_rInfo,getView(),getORB());
    1076           0 : }
    1077             : // -----------------------------------------------------------------------------
    1078           1 : Reference< XLayoutManager > OGenericUnoController::getLayoutManager(const Reference< XFrame >& _xFrame) const
    1079             : {
    1080           1 :     Reference< XPropertySet > xPropSet( _xFrame, UNO_QUERY );
    1081           1 :     Reference< XLayoutManager > xLayoutManager;
    1082           1 :     if ( xPropSet.is() )
    1083             :     {
    1084             :         try
    1085             :         {
    1086           1 :             xLayoutManager.set(xPropSet->getPropertyValue("LayoutManager"),UNO_QUERY);
    1087             :         }
    1088           0 :         catch ( Exception& )
    1089             :         {
    1090             :         }
    1091             :     }
    1092           1 :     return xLayoutManager;
    1093             : }
    1094             : // -----------------------------------------------------------------------------
    1095           0 : void OGenericUnoController::loadMenu(const Reference< XFrame >& _xFrame)
    1096             : {
    1097           0 :     Reference< XLayoutManager > xLayoutManager = getLayoutManager(_xFrame);
    1098           0 :     if ( xLayoutManager.is() )
    1099             :     {
    1100           0 :         xLayoutManager->lock();
    1101           0 :         xLayoutManager->createElement( OUString( "private:resource/menubar/menubar" ));
    1102           0 :         xLayoutManager->createElement( OUString( "private:resource/toolbar/toolbar" ));
    1103           0 :         xLayoutManager->unlock();
    1104           0 :         xLayoutManager->doLayout();
    1105             :     }
    1106             : 
    1107           0 :     onLoadedMenu( xLayoutManager );
    1108           0 : }
    1109             : 
    1110             : // -----------------------------------------------------------------------------
    1111           1 : void OGenericUnoController::onLoadedMenu(const Reference< XLayoutManager >& /*_xLayoutManager*/)
    1112             : {
    1113             :     // not interested in
    1114           1 : }
    1115             : 
    1116             : // -----------------------------------------------------------------------------
    1117           0 : void OGenericUnoController::closeTask()
    1118             : {
    1119           0 :     m_aAsyncCloseTask.Call();
    1120           0 : }
    1121             : // -----------------------------------------------------------------------------
    1122           0 : IMPL_LINK_NOARG(OGenericUnoController, OnAsyncCloseTask)
    1123             : {
    1124           0 :     if ( !OGenericUnoController_Base::rBHelper.bInDispose )
    1125             :     {
    1126             :         try
    1127             :         {
    1128           0 :             Reference< util::XCloseable > xCloseable( m_aCurrentFrame.getFrame(), UNO_QUERY_THROW );
    1129           0 :             xCloseable->close( sal_False ); // false - holds the owner ship for this frame inside this object!
    1130             :         }
    1131           0 :         catch( const Exception& )
    1132             :         {
    1133             :             DBG_UNHANDLED_EXCEPTION();
    1134             :         }
    1135             :     }
    1136           0 :     return 0L;
    1137             : }
    1138             : // -----------------------------------------------------------------------------
    1139           0 : Any SAL_CALL OGenericUnoController::getViewData(void) throw( RuntimeException )
    1140             : {
    1141           0 :     return Any();
    1142             : }
    1143             : // -----------------------------------------------------------------------------
    1144           0 : void SAL_CALL OGenericUnoController::restoreViewData(const Any& /*Data*/) throw( RuntimeException )
    1145             : {
    1146           0 : }
    1147             : 
    1148             : // -----------------------------------------------------------------------------
    1149          39 : Reference< XModel > SAL_CALL OGenericUnoController::getModel(void) throw( RuntimeException )
    1150             : {
    1151          39 :     return Reference< XModel >();
    1152             : }
    1153             : 
    1154             : // -----------------------------------------------------------------------------
    1155           4 : Reference< XFrame > SAL_CALL OGenericUnoController::getFrame(void) throw( RuntimeException )
    1156             : {
    1157           4 :     ::osl::MutexGuard aGuard( getMutex() );
    1158           4 :     return m_aCurrentFrame.getFrame();
    1159             : }
    1160             : 
    1161             : // -----------------------------------------------------------------------------
    1162           0 : sal_Bool SAL_CALL OGenericUnoController::attachModel(const Reference< XModel > & /*xModel*/) throw( RuntimeException )
    1163             : {
    1164             :     SAL_WARN("dbaccess.ui", "OGenericUnoController::attachModel: not supported!" );
    1165           0 :     return sal_False;
    1166             : }
    1167             : 
    1168             : // -----------------------------------------------------------------------------
    1169           0 : void OGenericUnoController::executeUnChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue >& aArgs)
    1170             : {
    1171           0 :     Execute(_nCommandId, aArgs);
    1172           0 : }
    1173             : // -----------------------------------------------------------------------------
    1174           0 : void OGenericUnoController::executeUnChecked(const util::URL& _rCommand, const Sequence< PropertyValue >& aArgs)
    1175             : {
    1176             :     OSL_PRECOND( !m_aSupportedFeatures.empty(), "OGenericUnoController::executeUnChecked: shouldn't this be filled at construction time?" );
    1177           0 :     if ( m_aSupportedFeatures.empty() )
    1178           0 :         fillSupportedFeatures();
    1179             : 
    1180           0 :     SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( _rCommand.Complete );
    1181           0 :     if (aIter != m_aSupportedFeatures.end())
    1182           0 :         Execute( aIter->second.nFeatureId, aArgs );
    1183           0 : }
    1184             : // -----------------------------------------------------------------------------
    1185           0 : void OGenericUnoController::executeChecked(const util::URL& _rCommand, const Sequence< PropertyValue >& aArgs)
    1186             : {
    1187             :     OSL_PRECOND( !m_aSupportedFeatures.empty(), "OGenericUnoController::executeChecked: shouldn't this be filled at construction time?" );
    1188           0 :     if ( m_aSupportedFeatures.empty() )
    1189           0 :         fillSupportedFeatures();
    1190             : 
    1191           0 :     SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( _rCommand.Complete );
    1192           0 :     if ( aIter != m_aSupportedFeatures.end() )
    1193             :     {
    1194           0 :         sal_uInt16 nFeatureId = aIter->second.nFeatureId;
    1195           0 :         if ( GetState( nFeatureId ).bEnabled )
    1196           0 :             Execute( nFeatureId, aArgs );
    1197             :     }
    1198           0 : }
    1199             : // -----------------------------------------------------------------------------
    1200             : //------------------------------------------------------------------------------
    1201             : namespace
    1202             : {
    1203           0 :     OUString lcl_getModuleHelpModuleName( const Reference< XFrame >& _rxFrame )
    1204             :     {
    1205           0 :         const sal_Char* pReturn = NULL;
    1206             : 
    1207             :         try
    1208             :         {
    1209             :             // get the model of the document in the given frame
    1210           0 :             Reference< XController > xController;
    1211           0 :             if ( _rxFrame.is() )
    1212           0 :                 xController = _rxFrame->getController();
    1213           0 :             Reference< XModel > xModel;
    1214           0 :             if ( xController.is() )
    1215           0 :                 xModel = xController->getModel();
    1216           0 :             Reference< XServiceInfo > xSI( xModel, UNO_QUERY );
    1217             : 
    1218           0 :             if ( !xSI.is() )
    1219             :             {   // try to go up the frame hierarchy
    1220             : 
    1221           0 :                 Reference< XFrame > xParentFrame;
    1222           0 :                 if ( _rxFrame.is() )
    1223           0 :                     xParentFrame = xParentFrame.query( _rxFrame->getCreator() );
    1224             :                 // did we find a parent frame? Which is no top-level frame?
    1225           0 :                 if ( xParentFrame.is() && !_rxFrame->isTop() )
    1226             :                     // TODO: to prevent framework assertions, re-insert this "isTop" once 98303 is fixed
    1227           0 :                     return lcl_getModuleHelpModuleName( xParentFrame );
    1228             :             }
    1229             :             else
    1230             :             {
    1231             : #if OSL_DEBUG_LEVEL > 0
    1232             :                 Sequence< OUString > sServiceNames = xSI->getSupportedServiceNames();
    1233             :                 const OUString* pLoop = sServiceNames.getConstArray();
    1234             :                 for ( sal_Int32 i=0; i<sServiceNames.getLength(); ++i, ++pLoop )
    1235             :                 {
    1236             :                     sal_Int32 nDummy = 0;
    1237             :                     (void)nDummy;
    1238             :                 }
    1239             : #endif
    1240             : 
    1241             :                 // check which service we know ....
    1242             :                 static const sal_Char* pTransTable[] = {
    1243             :                     "com.sun.star.sdb.OfficeDatabaseDocument","sdatabase",
    1244             :                     "com.sun.star.report.ReportDefinition","sdatabase",
    1245             :                     "com.sun.star.text.TextDocument",   "swriter",
    1246             :                     "com.sun.star.sheet.SpreadsheetDocument", "scalc",
    1247             :                     "com.sun.star.presentation.PresentationDocument", "simpress",
    1248             :                     "com.sun.star.drawing.DrawingDocument", "sdraw",
    1249             :                     "com.sun.star.formula.FormularProperties", "smath",
    1250             :                     "com.sun.star.chart.ChartDocument", "schart"
    1251             :                 };
    1252             :                 OSL_ENSURE( ( sizeof( pTransTable ) / sizeof( pTransTable[0] ) ) % 2 == 0,
    1253             :                     "lcl_getModuleHelpModuleName: odd size of translation table!" );
    1254             : 
    1255             :                 // loop through the table
    1256           0 :                 sal_Int32 nTableEntries = ( sizeof( pTransTable ) / sizeof( pTransTable[0] ) ) / 2;
    1257           0 :                 const sal_Char** pDocumentService = pTransTable;
    1258           0 :                 const sal_Char** pHelpModuleName = pTransTable + 1;
    1259           0 :                 for ( sal_Int32 j=0; j<nTableEntries; ++j )
    1260             :                 {
    1261           0 :                     if ( xSI->supportsService( OUString::createFromAscii( *pDocumentService ) ) )
    1262             :                     {   // found a table entry which matches the model's services
    1263           0 :                         pReturn = *pHelpModuleName;
    1264           0 :                         break;
    1265             :                     }
    1266             : 
    1267           0 :                     ++pDocumentService; ++pDocumentService;
    1268           0 :                     ++pHelpModuleName; ++pHelpModuleName;
    1269             :                 }
    1270             :             }
    1271             : 
    1272           0 :             if ( !pReturn )
    1273             :             {
    1274             :                 // could not determine the document type we're living in
    1275             :                 // ->fallback
    1276           0 :                 SvtModuleOptions aModOpt;
    1277           0 :                 if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
    1278           0 :                     pReturn = "swriter";
    1279           0 :                 else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
    1280           0 :                     pReturn = "sdatabase";
    1281           0 :                 else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
    1282           0 :                     pReturn = "scalc";
    1283           0 :                 else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
    1284           0 :                     pReturn = "simpress";
    1285           0 :                 else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
    1286           0 :                     pReturn = "sdraw";
    1287           0 :                 else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
    1288           0 :                     pReturn = "smath";
    1289           0 :                 else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SCHART ) )
    1290           0 :                     pReturn = "schart";
    1291           0 :                 else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SBASIC ) )
    1292           0 :                     pReturn = "sbasic";
    1293             :                 else
    1294             :                 {
    1295             :                     SAL_WARN("dbaccess.ui", "lcl_getModuleHelpModuleName: no installed module found" );
    1296           0 :                 }
    1297           0 :             }
    1298             :         }
    1299           0 :         catch( const Exception& )
    1300             :         {
    1301             :             DBG_UNHANDLED_EXCEPTION();
    1302             :         }
    1303             : 
    1304           0 :         if ( !pReturn )
    1305           0 :             pReturn = "swriter";
    1306             : 
    1307           0 :         return OUString::createFromAscii( pReturn );
    1308             :     }
    1309             : }
    1310             : 
    1311             : // -----------------------------------------------------------------------------
    1312             : 
    1313           0 : void OGenericUnoController::openHelpAgent(OUString const& _suHelpStringURL )
    1314             : {
    1315           0 :     OUString suURL(_suHelpStringURL);
    1316           0 :     OUString sLanguage( "Language=" );
    1317           0 :     if (suURL.indexOf(sLanguage) == -1)
    1318             :     {
    1319           0 :         AppendConfigToken(suURL, sal_False /* sal_False := add '&' */ );
    1320             :     }
    1321           0 :     URL aURL;
    1322           0 :     aURL.Complete = suURL;
    1323             : 
    1324           0 :     openHelpAgent( aURL );
    1325           0 : }
    1326             : 
    1327           0 : void OGenericUnoController::openHelpAgent(const OString& _sHelpId)
    1328             : {
    1329           0 :     openHelpAgent( createHelpAgentURL( lcl_getModuleHelpModuleName( getFrame() ), _sHelpId ) );
    1330           0 : }
    1331             : 
    1332           0 : void OGenericUnoController::openHelpAgent( const URL& _rURL )
    1333             : {
    1334             :     try
    1335             :     {
    1336           0 :         URL aURL( _rURL );
    1337             : 
    1338           0 :         if ( m_xUrlTransformer.is() )
    1339           0 :             m_xUrlTransformer->parseStrict(aURL);
    1340             : 
    1341           0 :         Reference< XDispatchProvider > xDispProv( m_aCurrentFrame.getFrame(), UNO_QUERY );
    1342           0 :         Reference< XDispatch > xHelpDispatch;
    1343           0 :         if ( xDispProv.is() )
    1344           0 :             xHelpDispatch = xDispProv->queryDispatch(aURL, OUString( "_helpagent" ), FrameSearchFlag::PARENT | FrameSearchFlag::SELF);
    1345             :         OSL_ENSURE(xHelpDispatch.is(), "SbaTableQueryBrowser::openHelpAgent: could not get a dispatcher!");
    1346           0 :         if (xHelpDispatch.is())
    1347             :         {
    1348           0 :             xHelpDispatch->dispatch(aURL, Sequence< PropertyValue >());
    1349           0 :         }
    1350             :     }
    1351           0 :     catch( const Exception& )
    1352             :     {
    1353             :         DBG_UNHANDLED_EXCEPTION();
    1354             :     }
    1355           0 : }
    1356             : // -----------------------------------------------------------------------------
    1357           0 : Reference< awt::XWindow> OGenericUnoController::getTopMostContainerWindow() const
    1358             : {
    1359           0 :     Reference< ::com::sun::star::awt::XWindow> xWindow;
    1360             : 
    1361             :     // get the top most window
    1362           0 :     Reference< XFrame > xFrame( m_aCurrentFrame.getFrame() );
    1363           0 :     if ( xFrame.is() )
    1364             :     {
    1365           0 :         xWindow = xFrame->getContainerWindow();
    1366             : 
    1367           0 :         while ( xFrame.is() && !xFrame->isTop() )
    1368             :         {
    1369           0 :             xFrame.set( xFrame->getCreator(), UNO_QUERY );
    1370             :         }
    1371           0 :         if ( xFrame.is() )
    1372           0 :             xWindow = xFrame->getContainerWindow();
    1373             :     }
    1374           0 :     return xWindow;
    1375             : }
    1376             : // -----------------------------------------------------------------------------
    1377           3 : Reference< XTitle > OGenericUnoController::impl_getTitleHelper_throw()
    1378             : {
    1379           3 :     SolarMutexGuard aSolarGuard;
    1380           6 :     ::osl::MutexGuard aGuard( getMutex() );
    1381             : 
    1382           3 :     if ( ! m_xTitleHelper.is ())
    1383             :     {
    1384           1 :         Reference< XUntitledNumbers > xUntitledProvider(getPrivateModel(), UNO_QUERY      );
    1385           2 :         Reference< XController >      xThis(static_cast< XController* >(this), UNO_QUERY_THROW);
    1386             : 
    1387           1 :         ::framework::TitleHelper* pHelper = new ::framework::TitleHelper( m_xContext );
    1388           1 :         m_xTitleHelper.set( static_cast< ::cppu::OWeakObject* >(pHelper), UNO_QUERY_THROW);
    1389             : 
    1390           1 :         pHelper->setOwner                   (xThis            );
    1391           2 :         pHelper->connectWithUntitledNumbers (xUntitledProvider);
    1392             :     }
    1393             : 
    1394           6 :     return m_xTitleHelper;
    1395             : }
    1396             : 
    1397             : //=============================================================================
    1398             : // XTitle
    1399           2 : OUString SAL_CALL OGenericUnoController::getTitle()
    1400             :     throw (RuntimeException)
    1401             : {
    1402           2 :     ::osl::MutexGuard aGuard( getMutex() );
    1403           2 :     if ( m_bExternalTitle )
    1404           0 :         return impl_getTitleHelper_throw()->getTitle ();
    1405           2 :     return getPrivateTitle() + impl_getTitleHelper_throw()->getTitle ();
    1406             : }
    1407             : 
    1408             : //=============================================================================
    1409             : // XTitle
    1410           0 : void SAL_CALL OGenericUnoController::setTitle(const OUString& sTitle)
    1411             :     throw (RuntimeException)
    1412             : {
    1413           0 :     SolarMutexGuard aSolarGuard;
    1414           0 :     ::osl::MutexGuard aGuard( getMutex() );
    1415           0 :     m_bExternalTitle = sal_True;
    1416           0 :     impl_getTitleHelper_throw()->setTitle (sTitle);
    1417           0 : }
    1418             : 
    1419             : //=============================================================================
    1420             : // XTitleChangeBroadcaster
    1421           1 : void SAL_CALL OGenericUnoController::addTitleChangeListener(const Reference< XTitleChangeListener >& xListener)
    1422             :     throw (RuntimeException)
    1423             : {
    1424           1 :     Reference< XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper_throw(), UNO_QUERY);
    1425           1 :     if (xBroadcaster.is ())
    1426           1 :         xBroadcaster->addTitleChangeListener (xListener);
    1427           1 : }
    1428             : 
    1429             : // -----------------------------------------------------------------------------
    1430           0 : void SAL_CALL OGenericUnoController::removeTitleChangeListener(const Reference< XTitleChangeListener >& xListener)
    1431             :     throw (RuntimeException)
    1432             : {
    1433           0 :     Reference< XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper_throw(), UNO_QUERY);
    1434           0 :     if (xBroadcaster.is ())
    1435           0 :         xBroadcaster->removeTitleChangeListener (xListener);
    1436           0 : }
    1437             : 
    1438             : // =============================================================================
    1439             : // XUserInputInterception
    1440             : // -----------------------------------------------------------------------------
    1441           0 : void SAL_CALL OGenericUnoController::addKeyHandler( const Reference< XKeyHandler >& _rxHandler ) throw (RuntimeException)
    1442             : {
    1443           0 :     if ( _rxHandler.is() )
    1444           0 :         m_pData->m_aUserInputInterception.addKeyHandler( _rxHandler );
    1445           0 : }
    1446             : 
    1447             : // -----------------------------------------------------------------------------
    1448           0 : void SAL_CALL OGenericUnoController::removeKeyHandler( const Reference< XKeyHandler >& _rxHandler ) throw (RuntimeException)
    1449             : {
    1450           0 :     m_pData->m_aUserInputInterception.removeKeyHandler( _rxHandler );
    1451           0 : }
    1452             : 
    1453             : // -----------------------------------------------------------------------------
    1454           0 : void SAL_CALL OGenericUnoController::addMouseClickHandler( const Reference< XMouseClickHandler >& _rxHandler ) throw (RuntimeException)
    1455             : {
    1456           0 :     if ( _rxHandler.is() )
    1457           0 :         m_pData->m_aUserInputInterception.addMouseClickHandler( _rxHandler );
    1458           0 : }
    1459             : 
    1460             : // -----------------------------------------------------------------------------
    1461           0 : void SAL_CALL OGenericUnoController::removeMouseClickHandler( const Reference< XMouseClickHandler >& _rxHandler ) throw (RuntimeException)
    1462             : {
    1463           0 :     m_pData->m_aUserInputInterception.removeMouseClickHandler( _rxHandler );
    1464           0 : }
    1465             : 
    1466             : // =============================================================================
    1467             : // -----------------------------------------------------------------------------
    1468           0 : void OGenericUnoController::executeChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue >& aArgs)
    1469             : {
    1470           0 :     if ( isCommandEnabled(_nCommandId) )
    1471           0 :         Execute(_nCommandId, aArgs);
    1472           0 : }
    1473             : 
    1474             : // -----------------------------------------------------------------------------
    1475           0 : sal_Bool OGenericUnoController::isCommandEnabled(sal_uInt16 _nCommandId) const
    1476             : {
    1477           0 :     return GetState( _nCommandId ).bEnabled;
    1478             : }
    1479             : 
    1480             : // -----------------------------------------------------------------------------
    1481           0 : sal_uInt16 OGenericUnoController::registerCommandURL( const OUString& _rCompleteCommandURL )
    1482             : {
    1483           0 :     if ( _rCompleteCommandURL.isEmpty() )
    1484           0 :         return 0;
    1485             : 
    1486           0 :     SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( _rCompleteCommandURL );
    1487           0 :     if ( aIter != m_aSupportedFeatures.end() )
    1488           0 :         return aIter->second.nFeatureId;
    1489             : 
    1490             :     // this is a previously unkwnon command
    1491           0 :     sal_uInt16 nFeatureId = FIRST_USER_DEFINED_FEATURE;
    1492           0 :     while ( isFeatureSupported( nFeatureId ) && ( nFeatureId < LAST_USER_DEFINED_FEATURE ) )
    1493           0 :         ++nFeatureId;
    1494           0 :     if ( nFeatureId == LAST_USER_DEFINED_FEATURE )
    1495             :     {
    1496             :         SAL_WARN("dbaccess.ui", "OGenericUnoController::registerCommandURL: no more space for user defined features!" );
    1497           0 :         return 0L;
    1498             :     }
    1499             : 
    1500           0 :     ControllerFeature aFeature;
    1501           0 :     aFeature.Command = _rCompleteCommandURL;
    1502           0 :     aFeature.nFeatureId = nFeatureId;
    1503           0 :     aFeature.GroupId = CommandGroup::INTERNAL;
    1504           0 :     m_aSupportedFeatures[ aFeature.Command ] = aFeature;
    1505             : 
    1506           0 :     return nFeatureId;
    1507             : }
    1508             : 
    1509             : // -----------------------------------------------------------------------------
    1510           0 : void OGenericUnoController::notifyHiContrastChanged()
    1511             : {
    1512           0 : }
    1513             : 
    1514             : // -----------------------------------------------------------------------------
    1515           0 : sal_Bool OGenericUnoController::isDataSourceReadOnly() const
    1516             : {
    1517           0 :     return sal_False;
    1518             : }
    1519             : 
    1520             : // -----------------------------------------------------------------------------
    1521           4 : Reference< XController > OGenericUnoController::getXController() throw( RuntimeException )
    1522             : {
    1523           4 :     return this;
    1524             : }
    1525             : 
    1526             : // -----------------------------------------------------------------------------
    1527           0 : bool OGenericUnoController::interceptUserInput( const NotifyEvent& _rEvent )
    1528             : {
    1529           0 :     return m_pData->m_aUserInputInterception.handleNotifyEvent( _rEvent );
    1530             : }
    1531             : 
    1532             : // -----------------------------------------------------------------------------
    1533           0 : sal_Bool OGenericUnoController::isCommandChecked(sal_uInt16 _nCommandId) const
    1534             : {
    1535           0 :     FeatureState aState = GetState( _nCommandId );
    1536             : 
    1537           0 :     return aState.bChecked && (sal_Bool)*aState.bChecked;
    1538             : }
    1539             : // -----------------------------------------------------------------------------
    1540           0 : sal_Bool OGenericUnoController::isCommandEnabled( const OUString& _rCompleteCommandURL ) const
    1541             : {
    1542             :     OSL_ENSURE( !_rCompleteCommandURL.isEmpty(), "OGenericUnoController::isCommandEnabled: Empty command url!" );
    1543             : 
    1544           0 :     sal_Bool bIsEnabled = sal_False;
    1545           0 :     SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( _rCompleteCommandURL );
    1546           0 :     if ( aIter != m_aSupportedFeatures.end() )
    1547           0 :         bIsEnabled = isCommandEnabled( aIter->second.nFeatureId );
    1548             : 
    1549           0 :     return bIsEnabled;
    1550             : }
    1551             : 
    1552             : // -----------------------------------------------------------------------------
    1553           0 : Sequence< ::sal_Int16 > SAL_CALL OGenericUnoController::getSupportedCommandGroups() throw (RuntimeException)
    1554             : {
    1555           0 :     CommandHashMap aCmdHashMap;
    1556           0 :     for (   SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.begin();
    1557           0 :             aIter != m_aSupportedFeatures.end();
    1558             :             ++aIter
    1559             :         )
    1560           0 :         if ( aIter->second.GroupId != CommandGroup::INTERNAL )
    1561           0 :             aCmdHashMap.insert( CommandHashMap::value_type( aIter->second.GroupId, 0 ));
    1562             : 
    1563           0 :     Sequence< sal_Int16 > aCommandGroups( aCmdHashMap.size() );
    1564             :     ::std::transform( aCmdHashMap.begin(),
    1565             :         aCmdHashMap.end(),
    1566             :         aCommandGroups.getArray(),
    1567             :         ::o3tl::select1st< CommandHashMap::value_type >()
    1568           0 :     );
    1569             : 
    1570           0 :     return aCommandGroups;
    1571             : }
    1572             : 
    1573             : namespace
    1574             : {
    1575             :     //Current c++0x draft (apparently) has std::identity, but not operator()
    1576             :     template<typename T> struct SGI_identity : public std::unary_function<T,T>
    1577             :     {
    1578           0 :         T& operator()(T& x) const { return x; }
    1579             :         const T& operator()(const T& x) const { return x; }
    1580             :     };
    1581             : }
    1582             : 
    1583             : // -----------------------------------------------------------------------------
    1584           0 : Sequence< DispatchInformation > SAL_CALL OGenericUnoController::getConfigurableDispatchInformation( ::sal_Int16 CommandGroup ) throw (RuntimeException)
    1585             : {
    1586           0 :     DispatchInfoList    aInformationList;
    1587           0 :     DispatchInformation aDispatchInfo;
    1588           0 :     for (   SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.begin();
    1589           0 :             aIter != m_aSupportedFeatures.end();
    1590             :             ++aIter
    1591             :         )
    1592             :     {
    1593           0 :         if ( sal_Int16( aIter->second.GroupId ) == CommandGroup )
    1594             :         {
    1595           0 :             aDispatchInfo = aIter->second;
    1596           0 :             aInformationList.push_back( aDispatchInfo );
    1597             :         }
    1598             :     }
    1599             : 
    1600           0 :     Sequence< DispatchInformation > aInformation( aInformationList.size() );
    1601             :     ::std::transform( aInformationList.begin(),
    1602             :         aInformationList.end(),
    1603             :         aInformation.getArray(),
    1604             :         SGI_identity< DispatchInformation >()
    1605           0 :     );
    1606             : 
    1607           0 :     return aInformation;
    1608             : }
    1609             : // -----------------------------------------------------------------------------
    1610           1 : void OGenericUnoController::fillSupportedFeatures()
    1611             : {
    1612             : #ifdef DBG_UTIL
    1613             :     m_bDescribingSupportedFeatures = true;
    1614             : #endif
    1615           1 :     describeSupportedFeatures();
    1616             : // -----------------------------------------------------------------------------
    1617             : #ifdef DBG_UTIL
    1618             :     m_bDescribingSupportedFeatures = false;
    1619             : #endif
    1620           1 : }
    1621             : 
    1622             : 
    1623           1 : void SAL_CALL OGenericUnoController::dispose() throw(::com::sun::star::uno::RuntimeException)
    1624             : {
    1625           1 :     SolarMutexGuard aSolarGuard;
    1626           1 :     OGenericUnoController_Base::dispose();
    1627           1 : }
    1628          12 : }   // namespace dbaui
    1629             : 
    1630             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10