LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/app - subcomponentmanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 213 0.0 %
Date: 2012-12-27 Functions: 0 32 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 "subcomponentmanager.hxx"
      21             : #include "AppController.hxx"
      22             : #include "dbustrings.hrc"
      23             : 
      24             : #include <com/sun/star/frame/XFrame.hpp>
      25             : #include <com/sun/star/frame/XModel.hpp>
      26             : #include <com/sun/star/frame/XModel2.hpp>
      27             : #include <com/sun/star/util/XCloseable.hpp>
      28             : #include <com/sun/star/awt/XTopWindow.hpp>
      29             : #include <com/sun/star/embed/XComponentSupplier.hpp>
      30             : #include <com/sun/star/ucb/XCommandProcessor.hpp>
      31             : #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
      32             : #include <com/sun/star/beans/XPropertySet.hpp>
      33             : 
      34             : #include <tools/diagnose_ex.h>
      35             : #include <vcl/svapp.hxx>
      36             : #include <osl/mutex.hxx>
      37             : 
      38             : #include <algorithm>
      39             : #include <functional>
      40             : 
      41             : //......................................................................................................................
      42             : namespace dbaui
      43             : {
      44             : //......................................................................................................................
      45             : 
      46             :     /** === begin UNO using === **/
      47             :     using ::com::sun::star::uno::Reference;
      48             :     using ::com::sun::star::uno::XInterface;
      49             :     using ::com::sun::star::uno::UNO_QUERY;
      50             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      51             :     using ::com::sun::star::uno::UNO_SET_THROW;
      52             :     using ::com::sun::star::uno::Exception;
      53             :     using ::com::sun::star::uno::RuntimeException;
      54             :     using ::com::sun::star::uno::Any;
      55             :     using ::com::sun::star::uno::makeAny;
      56             :     using ::com::sun::star::uno::Sequence;
      57             :     using ::com::sun::star::uno::Type;
      58             :     using ::com::sun::star::frame::XFrame;
      59             :     using ::com::sun::star::frame::XController;
      60             :     using ::com::sun::star::frame::XModel;
      61             :     using ::com::sun::star::lang::EventObject;
      62             :     using ::com::sun::star::lang::XComponent;
      63             :     using ::com::sun::star::frame::XModel2;
      64             :     using ::com::sun::star::container::XEnumeration;
      65             :     using ::com::sun::star::util::XCloseable;
      66             :     using ::com::sun::star::awt::XTopWindow;
      67             :     using ::com::sun::star::embed::XComponentSupplier;
      68             :     using ::com::sun::star::ucb::XCommandProcessor;
      69             :     using ::com::sun::star::ucb::Command;
      70             :     using ::com::sun::star::document::XDocumentEventBroadcaster;
      71             :     using ::com::sun::star::beans::XPropertySet;
      72             :     using ::com::sun::star::beans::PropertyChangeEvent;
      73             :     /** === end UNO using === **/
      74             : 
      75             :     //==================================================================================================================
      76             :     //= helper structs
      77             :     //==================================================================================================================
      78             :     namespace
      79             :     {
      80             :         //..............................................................................................................
      81           0 :         struct SubComponentDescriptor
      82             :         {
      83             :             /// the name of the sub component, empty if it is yet unsaved
      84             :             ::rtl::OUString sName;
      85             :             /// type of the component - an ElementType value, except for relation design
      86             :             sal_Int32       nComponentType;
      87             :             /// the mode in which the sub component has been opened
      88             :             ElementOpenMode eOpenMode;
      89             :             /// the frame which the component resides in. Must not be <NULL/>
      90             :             Reference< XFrame >             xFrame;
      91             :             /// the controller of the sub component. Must not be <NULL/>
      92             :             Reference< XController >        xController;
      93             :             /// the model of the sub component. Might be <NULL/>
      94             :             Reference< XModel >             xModel;
      95             :             /// the document definition which holds the component, if any; as CommandProcessor
      96             :             Reference< XCommandProcessor >  xComponentCommandProcessor;
      97             :             /// the document definition which holds the component, if any; as PropertySet
      98             :             Reference< XPropertySet >       xDocumentDefinitionProperties;
      99             : 
     100           0 :             SubComponentDescriptor()
     101             :                 :sName()
     102             :                 ,nComponentType( -1 )
     103             :                 ,eOpenMode( E_OPEN_NORMAL )
     104             :                 ,xFrame()
     105             :                 ,xController()
     106           0 :                 ,xModel()
     107             :             {
     108           0 :             }
     109             : 
     110           0 :             SubComponentDescriptor( const ::rtl::OUString& i_rName, const sal_Int32 i_nComponentType,
     111             :                     const ElementOpenMode i_eOpenMode, const Reference< XComponent >& i_rComponent )
     112             :                 :sName( i_rName )
     113             :                 ,nComponentType( i_nComponentType )
     114           0 :                 ,eOpenMode( i_eOpenMode )
     115             :             {
     116           0 :                 if ( !impl_constructFrom( i_rComponent ) )
     117             :                 {
     118             :                     // i_rComponent is neither a model, nor a controller, nor a frame
     119             :                     // => it must be a css.sdb.DocumentDefinition
     120           0 :                     Reference< XComponentSupplier > xCompSupp( i_rComponent, UNO_QUERY_THROW );
     121           0 :                     Reference< XComponent > xComponent( xCompSupp->getComponent(), UNO_QUERY_THROW );
     122           0 :                     if ( !impl_constructFrom( xComponent ) )
     123           0 :                         throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Illegal component type." ) ), NULL );
     124           0 :                     xComponentCommandProcessor.set( i_rComponent, UNO_QUERY_THROW );
     125           0 :                     xDocumentDefinitionProperties.set( i_rComponent, UNO_QUERY_THROW );
     126             :                 }
     127           0 :             }
     128             : 
     129           0 :             inline bool is() const { return xFrame.is(); }
     130             : 
     131             :         private:
     132           0 :             bool impl_constructFrom( const Reference< XComponent >& _rxComponent )
     133             :             {
     134             :                 // is it a model?
     135           0 :                 xModel.set( _rxComponent, UNO_QUERY );
     136           0 :                 if ( xModel.is() )
     137             :                 {
     138           0 :                     xController.set( xModel->getCurrentController() );
     139           0 :                     if ( xController.is() )
     140           0 :                         xFrame.set( xController->getFrame(), UNO_SET_THROW );
     141             :                 }
     142             :                 else
     143             :                 {
     144             :                     // is it a controller?
     145           0 :                     xController.set( _rxComponent, UNO_QUERY );
     146           0 :                     if ( xController.is() )
     147             :                     {
     148           0 :                         xFrame.set( xController->getFrame(), UNO_SET_THROW );
     149             :                     }
     150             :                     else
     151             :                     {
     152             :                         // is it a frame?
     153           0 :                         xFrame.set( _rxComponent, UNO_QUERY );
     154           0 :                         if ( !xFrame.is() )
     155           0 :                             return false;
     156             : 
     157             :                         // ensure we have a controller
     158           0 :                         xController.set( xFrame->getController(), UNO_SET_THROW );
     159             :                     }
     160             : 
     161             :                     // check whether there is a model (not required)
     162           0 :                     xModel.set( xController->getModel() );
     163             :                 }
     164             : 
     165           0 :                 return true;
     166             :             }
     167             :         };
     168             : 
     169             :         //..............................................................................................................
     170             :         struct SelectSubComponent : public ::std::unary_function< SubComponentDescriptor, Reference< XComponent > >
     171             :         {
     172           0 :             Reference< XComponent > operator()( const SubComponentDescriptor &_desc ) const
     173             :             {
     174           0 :                 if ( _desc.xModel.is() )
     175           0 :                     return _desc.xModel.get();
     176             :                 OSL_ENSURE( _desc.xController.is(), "SelectSubComponent::operator(): illegal component!" );
     177           0 :                 return _desc.xController.get();
     178             :             }
     179             :         };
     180             : 
     181             :         //..............................................................................................................
     182             :         typedef ::std::vector< SubComponentDescriptor > SubComponents;
     183             : 
     184             :         //..............................................................................................................
     185           0 :         struct SubComponentMatch : public ::std::unary_function< SubComponentDescriptor, bool >
     186             :         {
     187             :         public:
     188           0 :             SubComponentMatch( const ::rtl::OUString& i_rName, const sal_Int32 i_nComponentType,
     189             :                     const ElementOpenMode i_eOpenMode )
     190             :                 :m_sName( i_rName )
     191             :                 ,m_nComponentType( i_nComponentType )
     192           0 :                 ,m_eOpenMode( i_eOpenMode )
     193             :             {
     194           0 :             }
     195             : 
     196           0 :             bool operator()( const SubComponentDescriptor& i_rCompareWith ) const
     197             :             {
     198           0 :                 return  (   m_sName             ==  i_rCompareWith.sName          )
     199             :                     &&  (   m_nComponentType    ==  i_rCompareWith.nComponentType )
     200           0 :                     &&  (   m_eOpenMode         ==  i_rCompareWith.eOpenMode      );
     201             :             }
     202             :         private:
     203             :             const ::rtl::OUString   m_sName;
     204             :             const sal_Int32         m_nComponentType;
     205             :             const ElementOpenMode   m_eOpenMode;
     206             :         };
     207             :     }
     208             : 
     209             :     //==================================================================================================================
     210             :     //= SubComponentManager_Data
     211             :     //==================================================================================================================
     212           0 :     struct SubComponentManager_Data
     213             :     {
     214           0 :         SubComponentManager_Data( OApplicationController& _rController, const ::comphelper::SharedMutex& _rMutex )
     215             :             :m_rController( _rController )
     216           0 :             ,m_aMutex( _rMutex )
     217             :         {
     218           0 :         }
     219             : 
     220             :         OApplicationController&             m_rController;
     221             :         mutable ::comphelper::SharedMutex   m_aMutex;
     222             :         SubComponents                       m_aComponents;
     223             : 
     224           0 :         ::osl::Mutex&   getMutex() const { return m_aMutex; }
     225             :     };
     226             : 
     227             :     //==================================================================================================================
     228             :     //= SubComponentManager
     229             :     //==================================================================================================================
     230             :     //------------------------------------------------------------------------------------------------------------------
     231           0 :     SubComponentManager::SubComponentManager( OApplicationController& _rController, const ::comphelper::SharedMutex& _rMutex )
     232           0 :         :m_pData( new SubComponentManager_Data( _rController, _rMutex ) )
     233             :     {
     234           0 :     }
     235             : 
     236             :     //------------------------------------------------------------------------------------------------------------------
     237           0 :     SubComponentManager::~SubComponentManager()
     238             :     {
     239           0 :     }
     240             : 
     241             :     //------------------------------------------------------------------------------------------------------------------
     242           0 :     void SubComponentManager::disposing()
     243             :     {
     244           0 :         ::osl::MutexGuard aGuard( m_pData->getMutex() );
     245           0 :         m_pData->m_aComponents.clear();
     246           0 :     }
     247             : 
     248             :     //------------------------------------------------------------------------------------------------------------------
     249             :     namespace
     250             :     {
     251             :         //..............................................................................................................
     252           0 :         bool lcl_fallbackToAnotherController( SubComponentDescriptor& _rCompDesc )
     253             :         {
     254           0 :             Reference< XController > xFallback;
     255             :             OSL_PRECOND( _rCompDesc.xModel.is(), "lcl_fallbackToAnotherController: illegal call!" );
     256           0 :             if ( !_rCompDesc.xModel.is() )
     257           0 :                 return false;
     258             : 
     259           0 :             xFallback.set( _rCompDesc.xModel->getCurrentController() );
     260           0 :             if ( xFallback == _rCompDesc.xController )
     261             :                 // don't accept the very same controller as fallback
     262           0 :                 xFallback.clear();
     263             : 
     264           0 :             if ( !xFallback.is() )
     265             :             {
     266             :                 // perhaps XModel2 can be of help here
     267           0 :                 Reference< XModel2 > xModel2( _rCompDesc.xModel, UNO_QUERY );
     268           0 :                 Reference< XEnumeration > xControllerEnum;
     269           0 :                 if ( xModel2.is() )
     270           0 :                     xControllerEnum = xModel2->getControllers();
     271           0 :                 while ( xControllerEnum.is() && xControllerEnum->hasMoreElements() )
     272             :                 {
     273           0 :                     xFallback.set( xControllerEnum->nextElement(), UNO_QUERY );
     274           0 :                     if ( xFallback == _rCompDesc.xController )
     275           0 :                         xFallback.clear();
     276           0 :                 }
     277             :             }
     278             : 
     279           0 :             if ( xFallback.is() )
     280             :             {
     281           0 :                 _rCompDesc.xController = xFallback;
     282           0 :                 _rCompDesc.xFrame.set( xFallback->getFrame(), UNO_SET_THROW );
     283           0 :                 return true;
     284             :             }
     285             : 
     286           0 :             return false;
     287             :         }
     288             : 
     289             :         //..............................................................................................................
     290           0 :         bool lcl_closeComponent( const Reference< XCommandProcessor >& _rxCommandProcessor )
     291             :         {
     292           0 :             bool bSuccess = false;
     293             :             try
     294             :             {
     295           0 :                 Reference< XCommandProcessor > xCommandProcessor( _rxCommandProcessor, UNO_SET_THROW );
     296           0 :                 sal_Int32 nCommandIdentifier = xCommandProcessor->createCommandIdentifier();
     297             : 
     298           0 :                 Command aCommand;
     299           0 :                 aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "close" ) );
     300           0 :                 xCommandProcessor->execute( aCommand, nCommandIdentifier, NULL );
     301           0 :                 bSuccess = true;
     302             :             }
     303           0 :             catch( const Exception& )
     304             :             {
     305             :                 DBG_UNHANDLED_EXCEPTION();
     306             :             }
     307           0 :             return bSuccess;
     308             :         }
     309             : 
     310             :         //..............................................................................................................
     311           0 :         bool lcl_closeComponent( const SubComponentDescriptor& _rComponent )
     312             :         {
     313           0 :             if ( _rComponent.xComponentCommandProcessor.is() )
     314           0 :                 return lcl_closeComponent( _rComponent.xComponentCommandProcessor );
     315             : 
     316           0 :             Reference< XController > xController( _rComponent.xController );
     317             :             OSL_ENSURE( xController.is(), "lcl_closeComponent: invalid controller!" );
     318             : 
     319             :             // suspend the controller in the document
     320           0 :             if ( xController.is() )
     321           0 :                 if ( !xController->suspend( sal_True ) )
     322           0 :                     return false;
     323             : 
     324           0 :             bool bSuccess = false;
     325             :             try
     326             :             {
     327           0 :                 Reference< XCloseable > xCloseable( _rComponent.xFrame, UNO_QUERY_THROW );
     328           0 :                 xCloseable->close( sal_True );
     329           0 :                 bSuccess = true;
     330             :             }
     331           0 :             catch( const Exception& )
     332             :             {
     333             :                 DBG_UNHANDLED_EXCEPTION();
     334             :             }
     335           0 :             return bSuccess;
     336             :         }
     337             : 
     338             :         //..............................................................................................................
     339           0 :         void lcl_notifySubComponentEvent( const SubComponentManager_Data& _rData, const sal_Char* _pAsciiEventName,
     340             :                 const SubComponentDescriptor& _rComponent )
     341             :         {
     342             :             try
     343             :             {
     344           0 :                 Reference< XDocumentEventBroadcaster > xBroadcaster( _rData.m_rController.getModel(), UNO_QUERY_THROW );
     345           0 :                 xBroadcaster->notifyDocumentEvent(
     346             :                     ::rtl::OUString::createFromAscii( _pAsciiEventName ),
     347             :                     &_rData.m_rController,
     348             :                     makeAny( _rComponent.xFrame )
     349           0 :                 );
     350             :             }
     351           0 :             catch( const Exception& )
     352             :             {
     353             :                 DBG_UNHANDLED_EXCEPTION();
     354             :             }
     355           0 :         }
     356             :     }
     357             : 
     358             :     //------------------------------------------------------------------------------------------------------------------
     359           0 :     void SAL_CALL SubComponentManager::propertyChange( const PropertyChangeEvent& i_rEvent ) throw (RuntimeException)
     360             :     {
     361           0 :         if ( i_rEvent.PropertyName != PROPERTY_NAME )
     362             :             // by definition, it's allowed to broadcast more than what we've registered for
     363           0 :             return;
     364             : 
     365             :         // find the sub component whose name changed
     366           0 :         for (   SubComponents::iterator comp = m_pData->m_aComponents.begin();
     367           0 :                 comp != m_pData->m_aComponents.end();
     368             :                 ++comp
     369             :             )
     370             :         {
     371           0 :             if ( comp->xDocumentDefinitionProperties != i_rEvent.Source )
     372           0 :                 continue;
     373             : 
     374           0 :             ::rtl::OUString sNewName;
     375           0 :             OSL_VERIFY( i_rEvent.NewValue >>= sNewName );
     376             : 
     377             :         #if OSL_DEBUG_LEVEL > 0
     378             :             ::rtl::OUString sOldKnownName( comp->sName );
     379             :             ::rtl::OUString sOldName;
     380             :             OSL_VERIFY( i_rEvent.OldValue >>= sOldName );
     381             :             OSL_ENSURE( sOldName == sOldKnownName, "SubComponentManager::propertyChange: inconsistency in the old names!" );
     382             :         #endif
     383             : 
     384           0 :             comp->sName = sNewName;
     385             :             break;
     386           0 :         }
     387             :     }
     388             : 
     389             :     //------------------------------------------------------------------------------------------------------------------
     390           0 :     void SAL_CALL SubComponentManager::disposing( const EventObject& _rSource ) throw (RuntimeException)
     391             :     {
     392           0 :         ::osl::ClearableMutexGuard aGuard( m_pData->getMutex() );
     393             : 
     394           0 :         SubComponentDescriptor aClosedComponent;
     395             : 
     396           0 :         for (   SubComponents::iterator comp = m_pData->m_aComponents.begin();
     397           0 :                 comp != m_pData->m_aComponents.end();
     398             :                 ++comp
     399             :             )
     400             :         {
     401           0 :             bool bRemove = false;
     402             : 
     403           0 :             if ( comp->xController == _rSource.Source )
     404             :             {
     405           0 :                 if ( !comp->xModel.is() )
     406             :                 {
     407           0 :                     bRemove = true;
     408             :                 }
     409             :                 else
     410             :                 {
     411             :                     // maybe this is just one view to the sub document, and only this view is closed
     412           0 :                     if ( !lcl_fallbackToAnotherController( *comp ) )
     413             :                     {
     414           0 :                         bRemove = true;
     415             :                     }
     416             :                 }
     417             :             }
     418           0 :             else if ( comp->xModel == _rSource.Source )
     419             :             {
     420           0 :                 bRemove = true;
     421             :             }
     422             : 
     423           0 :             if ( bRemove )
     424             :             {
     425           0 :                 aClosedComponent = *comp;
     426           0 :                 m_pData->m_aComponents.erase( comp );
     427           0 :                 break;
     428             :             }
     429             :         }
     430             : 
     431           0 :         if ( aClosedComponent.is() )
     432             :         {
     433           0 :             aGuard.clear();
     434           0 :             lcl_notifySubComponentEvent( *m_pData, "OnSubComponentClosed", aClosedComponent );
     435           0 :         }
     436           0 :     }
     437             : 
     438             :     //------------------------------------------------------------------------------------------------------------------
     439           0 :     Sequence< Reference< XComponent> > SubComponentManager::getSubComponents() const
     440             :     {
     441           0 :         ::osl::MutexGuard aGuard( m_pData->getMutex() );
     442             : 
     443           0 :         Sequence< Reference< XComponent > > aComponents( m_pData->m_aComponents.size() );
     444             :         ::std::transform(
     445           0 :             m_pData->m_aComponents.begin(),
     446           0 :             m_pData->m_aComponents.end(),
     447             :             aComponents.getArray(),
     448             :             SelectSubComponent()
     449           0 :         );
     450           0 :         return aComponents;
     451             :     }
     452             : 
     453             :     //------------------------------------------------------------------------------------------------------------------
     454           0 :     sal_Bool SubComponentManager::closeSubComponents()
     455             :     {
     456           0 :         SolarMutexGuard aSolarGuard;
     457           0 :         ::osl::MutexGuard aGuard( m_pData->getMutex() );
     458             : 
     459             :         try
     460             :         {
     461           0 :             SubComponents aWorkingCopy( m_pData->m_aComponents );
     462           0 :             for (   SubComponents::const_iterator comp = aWorkingCopy.begin();
     463           0 :                     comp != aWorkingCopy.end();
     464             :                     ++comp
     465             :                 )
     466             :             {
     467           0 :                 lcl_closeComponent( *comp );
     468           0 :             }
     469             :         }
     470           0 :         catch ( const Exception& )
     471             :         {
     472             :             DBG_UNHANDLED_EXCEPTION();
     473             :         }
     474             : 
     475           0 :         return empty();
     476             :     }
     477             : 
     478             :     //------------------------------------------------------------------------------------------------------------------
     479           0 :     bool SubComponentManager::empty() const
     480             :     {
     481           0 :         ::osl::MutexGuard aGuard( m_pData->getMutex() );
     482           0 :         return m_pData->m_aComponents.empty();
     483             :     }
     484             : 
     485             :     //------------------------------------------------------------------------------------------------------------------
     486           0 :     void SubComponentManager::onSubComponentOpened( const ::rtl::OUString&  _rName, const sal_Int32 _nComponentType,
     487             :         const ElementOpenMode _eOpenMode, const Reference< XComponent >& _rxComponent )
     488             :     {
     489           0 :         ::osl::ClearableMutexGuard aGuard( m_pData->getMutex() );
     490             : 
     491             : #if OSL_DEBUG_LEVEL > 0
     492             :         if ( !_rName.isEmpty() )
     493             :         {
     494             :             // check there does not already exist such a component
     495             :             SubComponents::const_iterator existentPos = ::std::find_if(
     496             :                 m_pData->m_aComponents.begin(),
     497             :                 m_pData->m_aComponents.end(),
     498             :                 SubComponentMatch( _rName, _nComponentType, _eOpenMode )
     499             :             );
     500             :             OSL_ENSURE( existentPos == m_pData->m_aComponents.end(), "already existent!" );
     501             :         }
     502             : #endif
     503           0 :         SubComponentDescriptor aElement( _rName, _nComponentType, _eOpenMode, _rxComponent );
     504           0 :         ENSURE_OR_THROW( aElement.xModel.is() || aElement.xController.is(), "illegal component" );
     505             : 
     506           0 :         m_pData->m_aComponents.push_back( aElement );
     507             : 
     508             :         // add as listener
     509           0 :         if ( aElement.xController.is() )
     510           0 :             aElement.xController->addEventListener( this );
     511           0 :         if ( aElement.xModel.is() )
     512           0 :             aElement.xModel->addEventListener( this );
     513           0 :         if ( aElement.xDocumentDefinitionProperties.is() )
     514           0 :             aElement.xDocumentDefinitionProperties->addPropertyChangeListener( PROPERTY_NAME, this );
     515             : 
     516             :         // notify this to interested parties
     517           0 :         aGuard.clear();
     518           0 :         lcl_notifySubComponentEvent( *m_pData, "OnSubComponentOpened", aElement );
     519           0 :     }
     520             : 
     521             :     //------------------------------------------------------------------------------------------------------------------
     522           0 :     bool SubComponentManager::activateSubFrame( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType,
     523             :         const ElementOpenMode _eOpenMode, Reference< XComponent >& o_rComponent ) const
     524             :     {
     525           0 :         ::osl::MutexGuard aGuard( m_pData->getMutex() );
     526             : 
     527             :         SubComponents::const_iterator pos = ::std::find_if(
     528           0 :             m_pData->m_aComponents.begin(),
     529           0 :             m_pData->m_aComponents.end(),
     530             :             SubComponentMatch( _rName, _nComponentType, _eOpenMode )
     531           0 :         );
     532           0 :         if ( pos == m_pData->m_aComponents.end() )
     533             :             // no component with this name/type/open mode
     534           0 :             return false;
     535             : 
     536           0 :         const Reference< XFrame > xFrame( pos->xFrame, UNO_SET_THROW );
     537           0 :         const Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
     538           0 :         xTopWindow->toFront();
     539             : 
     540           0 :         if ( pos->xModel.is() )
     541           0 :             o_rComponent = pos->xModel.get();
     542           0 :         else if ( pos->xController.is() )
     543           0 :             o_rComponent = pos->xController.get();
     544             :         else
     545           0 :             o_rComponent = pos->xFrame.get();
     546             : 
     547           0 :         return true;
     548             :     }
     549             : 
     550             :     //------------------------------------------------------------------------------------------------------------------
     551           0 :     bool SubComponentManager::closeSubFrames( const ::rtl::OUString& i_rName, const sal_Int32 _nComponentType )
     552             :     {
     553           0 :         ::osl::MutexGuard aGuard( m_pData->getMutex() );
     554           0 :         ENSURE_OR_RETURN_FALSE( !i_rName.isEmpty(), "SubComponentManager::closeSubFrames: illegal name!" );
     555             : 
     556           0 :         SubComponents aWorkingCopy( m_pData->m_aComponents );
     557           0 :         for (   SubComponents::const_iterator comp = aWorkingCopy.begin();
     558           0 :                 comp != aWorkingCopy.end();
     559             :                 ++comp
     560             :             )
     561             :         {
     562           0 :             if ( ( comp->sName != i_rName ) || ( comp->nComponentType != _nComponentType ) )
     563           0 :                 continue;
     564             : 
     565           0 :             if ( !lcl_closeComponent( *comp ) )
     566           0 :                 return false;
     567             :         }
     568             : 
     569           0 :         return true;
     570             :     }
     571             : 
     572             :     //------------------------------------------------------------------------------------------------------------------
     573           0 :     bool SubComponentManager::lookupSubComponent( const Reference< XComponent >& i_rComponent,
     574             :             ::rtl::OUString& o_rName, sal_Int32& o_rComponentType )
     575             :     {
     576           0 :         for (   SubComponents::const_iterator comp = m_pData->m_aComponents.begin();
     577           0 :                 comp != m_pData->m_aComponents.end();
     578             :                 ++comp
     579             :             )
     580             :         {
     581           0 :             if  (   (   comp->xModel.is()
     582           0 :                     &&  ( comp->xModel == i_rComponent )
     583             :                     )
     584           0 :                 ||  (   comp->xController.is()
     585           0 :                     &&  ( comp->xController == i_rComponent )
     586             :                     )
     587           0 :                 ||  (   comp->xFrame.is()
     588           0 :                     &&  ( comp->xFrame == i_rComponent )
     589             :                     )
     590             :                 )
     591             :             {
     592           0 :                 o_rName = comp->sName;
     593           0 :                 o_rComponentType = comp->nComponentType;
     594           0 :                 return true;
     595             :             }
     596             :         }
     597           0 :         return false;
     598             :     }
     599             : 
     600             : //......................................................................................................................
     601             : } // namespace dbaui
     602             : //......................................................................................................................
     603             : 
     604             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10