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

Generated by: LCOV version 1.10