diff options
Diffstat (limited to 'dbaccess/source/ui/app')
-rw-r--r-- | dbaccess/source/ui/app/AppController.cxx | 194 | ||||
-rw-r--r-- | dbaccess/source/ui/app/AppController.hxx | 24 | ||||
-rw-r--r-- | dbaccess/source/ui/app/AppControllerDnD.cxx | 2 | ||||
-rw-r--r-- | dbaccess/source/ui/app/AppControllerGen.cxx | 82 | ||||
-rw-r--r-- | dbaccess/source/ui/app/AppDetailPageHelper.cxx | 14 | ||||
-rw-r--r-- | dbaccess/source/ui/app/subcomponentmanager.cxx | 271 | ||||
-rw-r--r-- | dbaccess/source/ui/app/subcomponentmanager.hxx | 25 |
7 files changed, 405 insertions, 207 deletions
diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 81f8d1168948..ecc39c7aa169 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -75,8 +75,8 @@ #include <com/sun/star/sdb/application/DatabaseObject.hpp> #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp> #include <com/sun/star/document/XDocumentEventBroadcaster.hpp> +#include <com/sun/star/container/XHierarchicalName.hpp> /** === end UNO includes === **/ - #include <tools/debug.hxx> #include <tools/diagnose_ex.h> #include <tools/string.hxx> @@ -342,8 +342,8 @@ OApplicationController::~OApplicationController() osl_incrementInterlockedCount( &m_refCount ); dispose(); } - ::std::auto_ptr< Window> aTemp(m_pView); - m_pView = NULL; + ::std::auto_ptr< Window> aTemp( getView() ); + clearView(); DBG_DTOR(OApplicationController,NULL); } @@ -442,7 +442,8 @@ void SAL_CALL OApplicationController::disposing() } } - m_aModelConnector.clear(); + m_xModel->disconnectController( this ); + m_xModel.clear(); } } @@ -451,15 +452,15 @@ void SAL_CALL OApplicationController::disposing() DBG_UNHANDLED_EXCEPTION(); } - m_pView = NULL; + clearView(); OApplicationController_CBASE::disposing(); // here the m_refCount must be equal 5 } //-------------------------------------------------------------------- sal_Bool OApplicationController::Construct(Window* _pParent) { - m_pView = new OApplicationView( _pParent, getORB(), *this, m_ePreviewMode ); - m_pView->SetUniqueId(UID_APP_VIEW); + setView( * new OApplicationView( _pParent, getORB(), *this, m_ePreviewMode ) ); + getView()->SetUniqueId(UID_APP_VIEW); // late construction sal_Bool bSuccess = sal_False; @@ -478,8 +479,8 @@ sal_Bool OApplicationController::Construct(Window* _pParent) if ( !bSuccess ) { - ::std::auto_ptr< Window> aTemp(m_pView); - m_pView = NULL; + ::std::auto_ptr< Window> aTemp( getView() ); + clearView(); return sal_False; } @@ -508,8 +509,8 @@ void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) thr Reference<XConnection> xCon(_rSource.Source, UNO_QUERY); if ( xCon.is() ) { - DBG_ASSERT( ( m_xDataSourceConnection == xCon ) && getContainer() && ( getContainer()->getElementType() == E_TABLE ), - "OApplicationController::disposing: the below code will ignore this call - why?" ); + DBG_ASSERT( m_xDataSourceConnection == xCon, + "OApplicationController::disposing: which connection does this come from?" ); if ( getContainer() && getContainer()->getElementType() == E_TABLE ) getContainer()->clearPages(); @@ -522,7 +523,6 @@ void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) thr else if ( _rSource.Source == m_xModel ) { m_xModel.clear(); - m_aModelConnector.clear(); } else if ( _rSource.Source == m_xDataSource ) { @@ -1242,7 +1242,7 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa { ElementType eType = E_TABLE; sal_Bool bAutoPilot = sal_False; - sal_Bool bSQLView = sal_False; + ::comphelper::NamedValueCollection aCreationArgs; switch( _nId ) { @@ -1265,10 +1265,10 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa bAutoPilot = sal_True; eType = E_QUERY; break; - case ID_NEW_QUERY_SQL: - bSQLView = sal_True; - // run through case ID_NEW_QUERY_DESIGN: + aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, sal_True ); + // run through + case ID_NEW_QUERY_SQL: eType = E_QUERY; break; case ID_NEW_TABLE_DESIGN_AUTO_PILOT: @@ -1282,7 +1282,10 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa if ( bAutoPilot ) getContainer()->PostUserEvent( LINK( this, OApplicationController, OnCreateWithPilot ), reinterpret_cast< void* >( eType ) ); else - newElement( eType, bSQLView ); + { + Reference< XComponent > xDocDefinition; + newElement( eType, aCreationArgs, xDocDefinition ); + } } break; case SID_APP_NEW_FOLDER: @@ -1298,10 +1301,13 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa SharedConnection xConnection( ensureConnection() ); if ( xConnection.is() ) { - QueryDesigner aDesigner( getORB(), this, getFrame(), true, SID_DB_NEW_VIEW_SQL == _nId ); + QueryDesigner aDesigner( getORB(), this, getFrame(), true ); + + ::comphelper::NamedValueCollection aCreationArgs; + aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, ID_NEW_VIEW_DESIGN == _nId ); Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); - Reference< XComponent > xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY ); + Reference< XComponent > xComponent( aDesigner.createNew( xDataSource, aCreationArgs ), UNO_QUERY ); onDocumentOpened( ::rtl::OUString(), E_QUERY, E_OPEN_DESIGN, xComponent, NULL ); } } @@ -1840,14 +1846,17 @@ Reference< XComponent > OApplicationController::openElementWithArguments( const case E_REPORT: case E_FORM: { - ::std::auto_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType ); - if ( !aHelper->isConnected() ) - break; + if ( !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode ) ) + { + ::std::auto_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType ); + if ( !aHelper->isConnected() ) + break; - Reference< XComponent > xDefinition; - xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments ); + Reference< XComponent > xDefinition; + xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments ); - onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition ); + onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition ); + } } break; @@ -1866,20 +1875,33 @@ Reference< XComponent > OApplicationController::openElementWithArguments( const Any aDataSource; if ( _eOpenMode == E_OPEN_DESIGN ) { - sal_Bool bQuerySQLMode =( _nInstigatorCommand == SID_DB_APP_EDIT_SQL_VIEW ); + bool bAddViewTypeArg = false; if ( _eType == E_TABLE ) { if ( impl_isAlterableView_nothrow( _sName ) ) - pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true, bQuerySQLMode ) ); + { + pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true ) ); + bAddViewTypeArg = true; + } else + { pDesigner.reset( new TableDesigner( getORB(), this, m_aCurrentFrame.getFrame() ) ); + } } else if ( _eType == E_QUERY ) { - pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false, bQuerySQLMode ) ); + pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false ) ); + bAddViewTypeArg = true; } aDataSource <<= m_xDataSource; + + if ( bAddViewTypeArg ) + { + const bool bQueryGraphicalMode =( _nInstigatorCommand != SID_DB_APP_EDIT_SQL_VIEW ); + aArguments.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, bQueryGraphicalMode ); + } + } else { @@ -1891,7 +1913,7 @@ Reference< XComponent > OApplicationController::openElementWithArguments( const aDataSource <<= getDatabaseName(); } - xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments.getPropertyValues() ) ); + xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments ) ); onDocumentOpened( _sName, _eType, _eOpenMode, xRet, NULL ); } } @@ -1932,14 +1954,11 @@ void OApplicationController::newElementWithPilot( ElementType _eType ) if ( aHelper->isConnected() ) { sal_Int32 nCommandType = -1; - const ::rtl::OUString sName(getCurrentlySelectedName(nCommandType)); - Reference< XComponent > xComponent,xDefinition; + const ::rtl::OUString sCurrentSelected( getCurrentlySelectedName( nCommandType ) ); if ( E_REPORT == _eType ) - xComponent = aHelper->newReportWithPilot(xDefinition,nCommandType,sName); + aHelper->newReportWithPilot( nCommandType, sCurrentSelected ); else - xComponent = aHelper->newFormWithPilot(xDefinition,nCommandType,sName); - - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition ); + aHelper->newFormWithPilot( nCommandType, sCurrentSelected ); } } break; @@ -1949,68 +1968,76 @@ void OApplicationController::newElementWithPilot( ElementType _eType ) ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType); if ( aHelper->isConnected() ) { - Reference< XComponent > xComponent; if ( E_QUERY == _eType ) - xComponent = aHelper->newQueryWithPilot(); + aHelper->newQueryWithPilot(); else - xComponent = aHelper->newTableWithPilot(); - - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, NULL ); + aHelper->newTableWithPilot(); } } break; case E_NONE: break; } + + // no need for onDocumentOpened, the table wizard opens the created table by using + // XDatabaseDocumentUI::loadComponent method. } // ----------------------------------------------------------------------------- -void OApplicationController::newElement( ElementType _eType, sal_Bool _bSQLView ) +Reference< XComponent > OApplicationController::newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments, + Reference< XComponent >& o_rDocumentDefinition ) { OSL_ENSURE(getContainer(),"View is NULL! -> GPF"); + Reference< XComponent > xComponent; + o_rDocumentDefinition.clear(); + switch ( _eType ) { case E_FORM: case E_REPORT: - { - ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType); - if ( aHelper->isConnected() ) - { - Reference< XComponent > xComponent,xDefinition; - sal_Int32 nCommandType = -1; - const ::rtl::OUString sName(getCurrentlySelectedName(nCommandType)); - xComponent = aHelper->newDocument(_eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT,xDefinition,nCommandType,sName); - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition ); - } - } - break; + { + ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess( _eType ); + if ( !aHelper->isConnected() ) + break; + + xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT, i_rAdditionalArguments, o_rDocumentDefinition ); + } + break; + case E_QUERY: case E_TABLE: - { - ::std::auto_ptr< DatabaseObjectView > pDesigner; - SharedConnection xConnection( ensureConnection() ); - if ( xConnection.is() ) - { - if ( _eType == E_TABLE ) - { - pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) ); - } - else if ( _eType == E_QUERY ) - { - pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false, _bSQLView ) ); - } + { + ::std::auto_ptr< DatabaseObjectView > pDesigner; + SharedConnection xConnection( ensureConnection() ); + if ( !xConnection.is() ) + break; - Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); - Reference< XComponent > xComponent( pDesigner->createNew( xDataSource ), UNO_QUERY ); - onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, NULL ); - } + if ( _eType == E_TABLE ) + { + pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) ); } - break; + else if ( _eType == E_QUERY ) + { + pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false ) ); + } + + Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY ); + xComponent.set( pDesigner->createNew( xDataSource, i_rAdditionalArguments ), UNO_QUERY ); + } + break; + default: + OSL_ENSURE( false, "OApplicationController::newElement: illegal type!" ); break; } + + if ( xComponent.is() ) + onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, o_rDocumentDefinition ); + + return xComponent; } + // ----------------------------------------------------------------------------- void OApplicationController::addContainerListener(const Reference<XNameAccess>& _xCollection) { @@ -2583,7 +2610,7 @@ Reference< XModel > SAL_CALL OApplicationController::getModel(void) throw( Runt } // ----------------------------------------------------------------------------- -void OApplicationController::onConnectedModel() +void OApplicationController::onAttachedFrame() { sal_Int32 nConnectedControllers( 0 ); try @@ -2612,9 +2639,15 @@ void OApplicationController::onConnectedModel() // ----------------------------------------------------------------------------- IMPL_LINK( OApplicationController, OnFirstControllerConnected, void*, /**/ ) { + ::osl::MutexGuard aGuard( getMutex() ); + + if ( !m_xModel.is() ) + { + OSL_ENSURE( false, "OApplicationController::OnFirstControllerConnected: too late!" ); + } + // if we have forms or reports which contain macros/scripts, then show a warning // which suggests the user to migrate them to the database document - Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY ); if ( xDocumentScripts.is() ) { @@ -2660,6 +2693,14 @@ IMPL_LINK( OApplicationController, OnFirstControllerConnected, void*, /**/ ) } // ----------------------------------------------------------------------------- +void SAL_CALL OApplicationController::attachFrame( const Reference< XFrame > & i_rxFrame ) throw( RuntimeException ) +{ + OApplicationController_CBASE::attachFrame( i_rxFrame ); + if ( getFrame().is() ) + onAttachedFrame(); +} + +// ----------------------------------------------------------------------------- sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > & _rxModel) throw( RuntimeException ) { ::osl::MutexGuard aGuard( getMutex() ); @@ -2675,16 +2716,13 @@ sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > // at least: remove as property change listener from the old model/data source m_xModel = _rxModel; - if ( _rxModel.is() ) + if ( m_xModel.is() ) { m_xDocumentModify.set( m_xModel, UNO_QUERY_THROW ); - m_aModelConnector.connect( _rxModel, this ); - onConnectedModel(); } else { m_xDocumentModify.clear(); - m_aModelConnector.clear(); } m_xDataSource.set(xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference<XDataSource>(),UNO_QUERY); @@ -2760,7 +2798,7 @@ void OApplicationController::containerFound( const Reference< XContainer >& _xCo try { sName = getContainer()->getQualifiedName( NULL ); - OSL_ENSURE( sName.getLength(), "OApplicationController::newElementWithPilot: no name given!" ); + OSL_ENSURE( sName.getLength(), "OApplicationController::getCurrentlySelectedName: no name given!" ); } catch( const Exception& ) { diff --git a/dbaccess/source/ui/app/AppController.hxx b/dbaccess/source/ui/app/AppController.hxx index 5ab129e38f5a..1edda1d44758 100644 --- a/dbaccess/source/ui/app/AppController.hxx +++ b/dbaccess/source/ui/app/AppController.hxx @@ -32,7 +32,6 @@ #include "AppElementType.hxx" #include "callbacks.hxx" #include "commontypes.hxx" -#include "documentcontroller.hxx" #include "dsntypes.hxx" #include "genericcontroller.hxx" #include "linkeddocuments.hxx" @@ -120,8 +119,6 @@ namespace dbaui ::cppu::OInterfaceContainerHelper m_aContextMenuInterceptors; - ModelControllerConnector - m_aModelConnector; TContainerVector m_aCurrentContainers; // the containers where we are listener on ::rtl::Reference< SubComponentManager > m_pSubComponentManager; @@ -197,10 +194,15 @@ namespace dbaui /** opens a new frame for creation or auto pilot @param _eType Defines the type to open - @param _bSQLView - If <TRUE/> the query design will be opened in SQL view, otherwise not. + @param i_rAdditionalArguments + Additional arguments to pass when creating the component */ - void newElement( ElementType _eType , sal_Bool _bSQLView ); + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > + newElement( + ElementType _eType, + const ::comphelper::NamedValueCollection& i_rAdditionalArguments, + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_rDocumentDefinition + ); /** creates a new database object, using an auto pilot @param _eType @@ -384,12 +386,12 @@ namespace dbaui */ void showPreviewFor( const ElementType _eType,const ::rtl::OUString& _sName ); - /** called when we just connected to a new, non-NULL model + /** called we were attached to a frame In particular, this is called *after* the controller has been announced to the model (XModel::connectController) */ - void onConnectedModel(); + void onAttachedFrame(); /// determines whether the given table name denotes a view which can be altered bool impl_isAlterableView_nothrow( const ::rtl::OUString& _rTableOrViewName ) const; @@ -402,7 +404,7 @@ namespace dbaui /** verifies the object type denotes a valid DatabaseObject, and the object name denotes an existing object of this type. Throws if not. */ - void impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::rtl::OUString& _rObjectName ); + void impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::boost::optional< ::rtl::OUString >& i_rObjectName ); protected: // ---------------------------------------------------------------- @@ -443,6 +445,7 @@ namespace dbaui SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); // ::com::sun::star::frame::XController + virtual void SAL_CALL attachFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > & xFrame) throw( ::com::sun::star::uno::RuntimeException ); virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException ); virtual sal_Bool SAL_CALL attachModel(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xModel) throw( ::com::sun::star::uno::RuntimeException ); virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SAL_CALL getModel(void) throw( ::com::sun::star::uno::RuntimeException ); @@ -462,9 +465,12 @@ namespace dbaui virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > > SAL_CALL getSubComponents() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL isConnected( ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL connect( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::beans::Pair< ::sal_Int32, ::rtl::OUString > SAL_CALL identifySubComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& SubComponent ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL closeSubComponents( ) throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponent( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponentWithArguments( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL createComponent( ::sal_Int32 ObjectType, ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_DocumentDefinition ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL createComponentWithArguments( ::sal_Int32 ObjectType, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments, ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& o_DocumentDefinition ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); // XContextMenuInterception virtual void SAL_CALL registerContextMenuInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XContextMenuInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException); diff --git a/dbaccess/source/ui/app/AppControllerDnD.cxx b/dbaccess/source/ui/app/AppControllerDnD.cxx index 760ab1c0a4e2..6bc1789b0006 100644 --- a/dbaccess/source/ui/app/AppControllerDnD.cxx +++ b/dbaccess/source/ui/app/AppControllerDnD.cxx @@ -610,7 +610,7 @@ void OApplicationController::getSelectionElementNames(::std::vector< ::rtl::OUSt } ::std::auto_ptr< OLinkedDocumentsAccess > pDocuments( new OLinkedDocumentsAccess( - getView(), m_aCurrentFrame.getFrame(), getORB(), xDocContainer, xConnection, getDatabaseName() + getView(), this, getORB(), xDocContainer, xConnection, getDatabaseName() ) ); return pDocuments; } diff --git a/dbaccess/source/ui/app/AppControllerGen.cxx b/dbaccess/source/ui/app/AppControllerGen.cxx index 2791021a6159..435c6ff25fef 100644 --- a/dbaccess/source/ui/app/AppControllerGen.cxx +++ b/dbaccess/source/ui/app/AppControllerGen.cxx @@ -87,6 +87,7 @@ namespace dbaui using namespace ::dbtools; using namespace ::connectivity; using namespace ::svx; +using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::awt; using namespace ::com::sun::star::util; @@ -104,6 +105,7 @@ using namespace ::com::sun::star::ucb; using ::com::sun::star::util::XCloseable; using ::com::sun::star::ui::XContextMenuInterceptor; /** === end UNO using === **/ + namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; namespace ErrorCondition = ::com::sun::star::sdb::ErrorCondition; @@ -325,15 +327,22 @@ void SAL_CALL OApplicationController::propertyChange( const PropertyChangeEvent& ::rtl::OUString sOldName,sNewName; evt.OldValue >>= sOldName; evt.NewValue >>= sNewName; - Reference<XChild> xChild(evt.Source,UNO_QUERY); - if ( xChild.is() ) + + // if the old name is empty, then this is a newly inserted content. We're notified of it via the + // elementInserted method, so there's no need to handle it here. + + if ( sOldName.getLength() ) { - Reference<XContent> xContent(xChild->getParent(),UNO_QUERY); - if ( xContent.is() ) - sOldName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sOldName; - } + Reference<XChild> xChild(evt.Source,UNO_QUERY); + if ( xChild.is() ) + { + Reference<XContent> xContent(xChild->getParent(),UNO_QUERY); + if ( xContent.is() ) + sOldName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sOldName; + } - getContainer()->elementReplaced( eType , sOldName, sNewName ); + getContainer()->elementReplaced( eType , sOldName, sNewName ); + } } } @@ -362,6 +371,7 @@ Reference< XWindow > SAL_CALL OApplicationController::getApplicationMainWindow() // ----------------------------------------------------------------------------- Sequence< Reference< XComponent > > SAL_CALL OApplicationController::getSubComponents() throw (RuntimeException) { + ::osl::MutexGuard aGuard( getMutex() ); return m_pSubComponentManager->getSubComponents(); } @@ -382,6 +392,9 @@ Reference< XConnection > SAL_CALL OApplicationController::getActiveConnection() // ----------------------------------------------------------------------------- void SAL_CALL OApplicationController::connect( ) throw (SQLException, RuntimeException) { + ::vos::OGuard aSolarGuard(Application::GetSolarMutex()); + ::osl::MutexGuard aGuard( getMutex() ); + SQLExceptionInfo aError; SharedConnection xConnection = ensureConnection( &aError ); if ( !xConnection.is() ) @@ -397,8 +410,29 @@ void SAL_CALL OApplicationController::connect( ) throw (SQLException, RuntimeEx } // ----------------------------------------------------------------------------- +beans::Pair< ::sal_Int32, ::rtl::OUString > SAL_CALL OApplicationController::identifySubComponent( const Reference< XComponent >& i_rSubComponent ) throw (IllegalArgumentException, RuntimeException) +{ + ::osl::MutexGuard aGuard( getMutex() ); + + sal_Int32 nType = -1; + ::rtl::OUString sName; + + if ( !m_pSubComponentManager->lookupSubComponent( i_rSubComponent, sName, nType ) ) + throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); + + if ( nType == SID_DB_APP_DSRELDESIGN ) + // this is somewhat hacky ... we're expected to return a DatabaseObject value. However, there is no such + // value for the relation design. /me thinks we should change the API definition here ... + nType = -1; + + return beans::Pair< ::sal_Int32, ::rtl::OUString >( nType, sName ); +} + +// ----------------------------------------------------------------------------- ::sal_Bool SAL_CALL OApplicationController::closeSubComponents( ) throw (RuntimeException) { + ::vos::OGuard aSolarGuard(Application::GetSolarMutex()); + ::osl::MutexGuard aGuard( getMutex() ); return m_pSubComponentManager->closeSubComponents(); } @@ -424,7 +458,7 @@ namespace } // ----------------------------------------------------------------------------- -void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::rtl::OUString& _rObjectName ) +void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::boost::optional< ::rtl::OUString >& i_rObjectName ) { // ensure we're connected if ( !isConnected() ) @@ -441,6 +475,9 @@ void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int ) throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); + if ( !i_rObjectName ) + return; + // ensure an existing object Reference< XNameAccess > xContainer( getElements( lcl_objectType2ElementType( _nObjectType ) ) ); if ( !xContainer.is() ) @@ -453,19 +490,19 @@ void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int { case DatabaseObject::TABLE: case DatabaseObject::QUERY: - bExistentObject = xContainer->hasByName( _rObjectName ); + bExistentObject = xContainer->hasByName( *i_rObjectName ); break; case DatabaseObject::FORM: case DatabaseObject::REPORT: { Reference< XHierarchicalNameAccess > xHierarchy( xContainer, UNO_QUERY_THROW ); - bExistentObject = xHierarchy->hasByHierarchicalName( _rObjectName ); + bExistentObject = xHierarchy->hasByHierarchicalName( *i_rObjectName ); } break; } if ( !bExistentObject ) - throw NoSuchElementException( _rObjectName, *this ); + throw NoSuchElementException( *i_rObjectName, *this ); } // ----------------------------------------------------------------------------- @@ -496,6 +533,29 @@ Reference< XComponent > SAL_CALL OApplicationController::loadComponentWithArgume } // ----------------------------------------------------------------------------- +Reference< XComponent > SAL_CALL OApplicationController::createComponent( ::sal_Int32 i_nObjectType, Reference< XComponent >& o_DocumentDefinition ) throw (IllegalArgumentException, SQLException, RuntimeException) +{ + return createComponentWithArguments( i_nObjectType, Sequence< PropertyValue >(), o_DocumentDefinition ); +} + +// ----------------------------------------------------------------------------- +Reference< XComponent > SAL_CALL OApplicationController::createComponentWithArguments( ::sal_Int32 i_nObjectType, const Sequence< PropertyValue >& i_rArguments, Reference< XComponent >& o_DocumentDefinition ) throw (IllegalArgumentException, SQLException, RuntimeException) +{ + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( getMutex() ); + + impl_validateObjectTypeAndName_throw( i_nObjectType, ::boost::optional< ::rtl::OUString >() ); + + Reference< XComponent > xComponent( newElement( + lcl_objectType2ElementType( i_nObjectType ), + ::comphelper::NamedValueCollection( i_rArguments ), + o_DocumentDefinition + ) ); + + return xComponent; +} + +// ----------------------------------------------------------------------------- void SAL_CALL OApplicationController::registerContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException) { if ( _Interceptor.is() ) diff --git a/dbaccess/source/ui/app/AppDetailPageHelper.cxx b/dbaccess/source/ui/app/AppDetailPageHelper.cxx index 13ed83af38ea..afad4e3a2d7c 100644 --- a/dbaccess/source/ui/app/AppDetailPageHelper.cxx +++ b/dbaccess/source/ui/app/AppDetailPageHelper.cxx @@ -1286,15 +1286,11 @@ void OAppDetailPageHelper::showPreview( const ::rtl::OUString& _sDataSourceName, ) ); pDispatcher->setTargetFrame( m_xFrame ); - Sequence < PropertyValue > aArgs( 4 ); - aArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Preview")); - aArgs[0].Value <<= sal_True; - aArgs[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")); - aArgs[1].Value <<= sal_True; - aArgs[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AsTemplate")); - aArgs[2].Value <<= sal_False; - aArgs[3].Name = PROPERTY_SHOWMENU; - aArgs[3].Value <<= sal_False; + ::comphelper::NamedValueCollection aArgs; + aArgs.put( "Preview", sal_True ); + aArgs.put( "ReadOnly", sal_True ); + aArgs.put( "AsTemplate", sal_False ); + aArgs.put( (::rtl::OUString)PROPERTY_SHOWMENU, sal_False ); Reference< XController > xPreview( pDispatcher->openExisting( makeAny( _sDataSourceName ), _sName, aArgs ), UNO_QUERY ); sal_Bool bClearPreview = !xPreview.is(); diff --git a/dbaccess/source/ui/app/subcomponentmanager.cxx b/dbaccess/source/ui/app/subcomponentmanager.cxx index 3db2b37336d2..56fbc30f46e7 100644 --- a/dbaccess/source/ui/app/subcomponentmanager.cxx +++ b/dbaccess/source/ui/app/subcomponentmanager.cxx @@ -26,6 +26,7 @@ #include "subcomponentmanager.hxx" #include "AppController.hxx" +#include "dbustrings.hrc" /** === begin UNO includes === **/ #include <com/sun/star/frame/XFrame.hpp> @@ -36,6 +37,7 @@ #include <com/sun/star/embed/XComponentSupplier.hpp> #include <com/sun/star/ucb/XCommandProcessor.hpp> #include <com/sun/star/document/XDocumentEventBroadcaster.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> /** === end UNO includes === **/ #include <tools/diagnose_ex.h> @@ -46,10 +48,10 @@ #include <algorithm> #include <functional> -//........................................................................ +//...................................................................................................................... namespace dbaui { -//........................................................................ +//...................................................................................................................... /** === begin UNO using === **/ using ::com::sun::star::uno::Reference; @@ -76,40 +78,61 @@ namespace dbaui using ::com::sun::star::ucb::XCommandProcessor; using ::com::sun::star::ucb::Command; using ::com::sun::star::document::XDocumentEventBroadcaster; + using ::com::sun::star::beans::XPropertySet; + using ::com::sun::star::beans::PropertyChangeEvent; /** === end UNO using === **/ - //============================================================================== + //================================================================================================================== //= helper structs - //============================================================================== + //================================================================================================================== namespace { + //.............................................................................................................. struct SubComponentDescriptor { + /// the name of the sub component, empty if it is yet unsaved + ::rtl::OUString sName; + /// type of the component - an ElementType value, except for relation design + sal_Int32 nComponentType; + /// the mode in which the sub component has been opened + ElementOpenMode eOpenMode; /// the frame which the component resides in. Must not be <NULL/> Reference< XFrame > xFrame; /// the controller of the sub component. Must not be <NULL/> Reference< XController > xController; /// the model of the sub component. Might be <NULL/> Reference< XModel > xModel; - /// the document definition which holds the component, if any - Reference< XCommandProcessor > xComponentCommandProcessor; + /// the document definition which holds the component, if any; as CommandProcessor + Reference< XCommandProcessor > xComponentCommandProcessor; + /// the document definition which holds the component, if any; as PropertySet + Reference< XPropertySet > xDocumentDefinitionProperties; SubComponentDescriptor() - :xFrame() + :sName() + ,nComponentType( -1 ) + ,eOpenMode( E_OPEN_NORMAL ) + ,xFrame() ,xController() ,xModel() { } - SubComponentDescriptor( const Reference< XComponent >& _rxComponent ) + SubComponentDescriptor( const ::rtl::OUString& i_rName, const sal_Int32 i_nComponentType, + const ElementOpenMode i_eOpenMode, const Reference< XComponent >& i_rComponent ) + :sName( i_rName ) + ,nComponentType( i_nComponentType ) + ,eOpenMode( i_eOpenMode ) { - if ( !impl_constructFrom( _rxComponent ) ) + if ( !impl_constructFrom( i_rComponent ) ) { - Reference< XComponentSupplier > xCompSupp( _rxComponent, UNO_QUERY_THROW ); + // i_rComponent is neither a model, nor a controller, nor a frame + // => it must be a css.sdb.DocumentDefinition + Reference< XComponentSupplier > xCompSupp( i_rComponent, UNO_QUERY_THROW ); Reference< XComponent > xComponent( xCompSupp->getComponent(), UNO_QUERY_THROW ); if ( !impl_constructFrom( xComponent ) ) throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Illegal component type." ) ), NULL ); - xComponentCommandProcessor.set( _rxComponent, UNO_QUERY_THROW ); + xComponentCommandProcessor.set( i_rComponent, UNO_QUERY_THROW ); + xDocumentDefinitionProperties.set( i_rComponent, UNO_QUERY_THROW ); } } @@ -153,6 +176,7 @@ namespace dbaui } }; + //.............................................................................................................. struct SelectSubComponent : public ::std::unary_function< SubComponentDescriptor, Reference< XComponent > > { Reference< XComponent > operator()( const SubComponentDescriptor _desc ) const @@ -164,55 +188,37 @@ namespace dbaui } }; - struct SubComponentAccessor - { - /// the name of the sub component - ::rtl::OUString sName; - /// type of the component - usually an ElementType value - sal_Int32 nComponentType; - /// the mode in which the sub component has been opened - ElementOpenMode eOpenMode; + //.............................................................................................................. + typedef ::std::vector< SubComponentDescriptor > SubComponents; - SubComponentAccessor() - :sName() - ,nComponentType( sal_Int32( E_NONE ) ) - ,eOpenMode( E_OPEN_NORMAL ) - { - } - - SubComponentAccessor( const ::rtl::OUString& _rName, const sal_Int32 _nCompType, const ElementOpenMode _eMode ) - :sName( _rName ) - ,nComponentType( _nCompType ) - ,eOpenMode( _eMode ) - { - } - }; - - struct SubComponentAccessorHash : public ::std::unary_function< SubComponentAccessor, size_t > + //.............................................................................................................. + struct SubComponentMatch : public ::std::unary_function< SubComponentDescriptor, bool > { - size_t operator()( const SubComponentAccessor& _lhs ) const + public: + SubComponentMatch( const ::rtl::OUString& i_rName, const sal_Int32 i_nComponentType, + const ElementOpenMode i_eOpenMode ) + :m_sName( i_rName ) + ,m_nComponentType( i_nComponentType ) + ,m_eOpenMode( i_eOpenMode ) { - return _lhs.sName.hashCode() + _lhs.nComponentType + size_t( _lhs.eOpenMode ); } - }; - struct SubComponentAccessorEqual : public ::std::binary_function< SubComponentAccessor, SubComponentAccessor, bool > - { - bool operator()( const SubComponentAccessor& _lhs, const SubComponentAccessor& _rhs ) const + + bool operator()( const SubComponentDescriptor& i_rCompareWith ) const { - return ( _lhs.sName == _rhs.sName ) - && ( _lhs.nComponentType == _rhs.nComponentType ) - && ( _lhs.eOpenMode == _rhs.eOpenMode ); + return ( m_sName == i_rCompareWith.sName ) + && ( m_nComponentType == i_rCompareWith.nComponentType ) + && ( m_eOpenMode == i_rCompareWith.eOpenMode ); } + private: + const ::rtl::OUString m_sName; + const sal_Int32 m_nComponentType; + const ElementOpenMode m_eOpenMode; }; - - typedef ::std::hash_map< SubComponentAccessor, SubComponentDescriptor, SubComponentAccessorHash, SubComponentAccessorEqual > - SubComponentMap; - } - //============================================================================== + //================================================================================================================== //= SubComponentManager_Data - //============================================================================== + //================================================================================================================== struct SubComponentManager_Data { SubComponentManager_Data( OApplicationController& _rController, const ::comphelper::SharedMutex& _rMutex ) @@ -223,35 +229,36 @@ namespace dbaui OApplicationController& m_rController; mutable ::comphelper::SharedMutex m_aMutex; - SubComponentMap m_aComponents; + SubComponents m_aComponents; ::osl::Mutex& getMutex() const { return m_aMutex; } }; - //==================================================================== + //================================================================================================================== //= SubComponentManager - //==================================================================== - //-------------------------------------------------------------------- + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ SubComponentManager::SubComponentManager( OApplicationController& _rController, const ::comphelper::SharedMutex& _rMutex ) :m_pData( new SubComponentManager_Data( _rController, _rMutex ) ) { } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ SubComponentManager::~SubComponentManager() { } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ void SubComponentManager::disposing() { ::osl::MutexGuard aGuard( m_pData->getMutex() ); m_pData->m_aComponents.clear(); } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ namespace { + //.............................................................................................................. bool lcl_fallbackToAnotherController( SubComponentDescriptor& _rCompDesc ) { Reference< XController > xFallback; @@ -289,7 +296,7 @@ namespace dbaui return false; } - //---------------------------------------------------------------- + //.............................................................................................................. bool lcl_closeComponent( const Reference< XCommandProcessor >& _rxCommandProcessor ) { bool bSuccess = false; @@ -310,7 +317,7 @@ namespace dbaui return bSuccess; } - //---------------------------------------------------------------- + //.............................................................................................................. bool lcl_closeComponent( const SubComponentDescriptor& _rComponent ) { if ( _rComponent.xComponentCommandProcessor.is() ) @@ -338,7 +345,7 @@ namespace dbaui return bSuccess; } - // ----------------------------------------------------------------------------- + //.............................................................................................................. void lcl_notifySubComponentEvent( const SubComponentManager_Data& _rData, const sal_Char* _pAsciiEventName, const SubComponentDescriptor& _rComponent ) { @@ -358,43 +365,74 @@ namespace dbaui } } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ + void SAL_CALL SubComponentManager::propertyChange( const PropertyChangeEvent& i_rEvent ) throw (RuntimeException) + { + if ( i_rEvent.PropertyName != PROPERTY_NAME ) + // by definition, it's allowed to broadcast more than what we've registered for + return; + + // find the sub component whose name changed + for ( SubComponents::iterator comp = m_pData->m_aComponents.begin(); + comp != m_pData->m_aComponents.end(); + ++comp + ) + { + if ( comp->xDocumentDefinitionProperties != i_rEvent.Source ) + continue; + + ::rtl::OUString sNewName; + OSL_VERIFY( i_rEvent.NewValue >>= sNewName ); + + #if OSL_DEBUG_LEVEL > 0 + ::rtl::OUString sOldKnownName( comp->sName ); + ::rtl::OUString sOldName; + OSL_VERIFY( i_rEvent.OldValue >>= sOldName ); + OSL_ENSURE( sOldName == sOldKnownName, "SubComponentManager::propertyChange: inconsistency in the old names!" ); + #endif + + comp->sName = sNewName; + break; + } + } + + //------------------------------------------------------------------------------------------------------------------ void SAL_CALL SubComponentManager::disposing( const EventObject& _rSource ) throw (RuntimeException) { ::osl::ClearableMutexGuard aGuard( m_pData->getMutex() ); SubComponentDescriptor aClosedComponent; - for ( SubComponentMap::iterator comp = m_pData->m_aComponents.begin(); + for ( SubComponents::iterator comp = m_pData->m_aComponents.begin(); comp != m_pData->m_aComponents.end(); ++comp ) { bool bRemove = false; - if ( comp->second.xController == _rSource.Source ) + if ( comp->xController == _rSource.Source ) { - if ( !comp->second.xModel.is() ) + if ( !comp->xModel.is() ) { bRemove = true; } else { // maybe this is just one view to the sub document, and only this view is closed - if ( !lcl_fallbackToAnotherController( comp->second ) ) + if ( !lcl_fallbackToAnotherController( *comp ) ) { bRemove = true; } } } - else if ( comp->second.xModel == _rSource.Source ) + else if ( comp->xModel == _rSource.Source ) { bRemove = true; } if ( bRemove ) { - aClosedComponent = comp->second; + aClosedComponent = *comp; m_pData->m_aComponents.erase( comp ); break; } @@ -407,7 +445,7 @@ namespace dbaui } } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ Sequence< Reference< XComponent> > SubComponentManager::getSubComponents() const { ::osl::MutexGuard aGuard( m_pData->getMutex() ); @@ -417,12 +455,12 @@ namespace dbaui m_pData->m_aComponents.begin(), m_pData->m_aComponents.end(), aComponents.getArray(), - ::std::compose1( SelectSubComponent(), ::std::select2nd< SubComponentMap::value_type >() ) + SelectSubComponent() ); return aComponents; } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ sal_Bool SubComponentManager::closeSubComponents() { ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); @@ -430,16 +468,13 @@ namespace dbaui try { - typedef ::std::vector< SubComponentAccessor > ComponentAccessors; - ComponentAccessors aClosedComponents; - - SubComponentMap aComponents( m_pData->m_aComponents ); - for ( SubComponentMap::const_iterator comp = aComponents.begin(); - comp != aComponents.end(); + SubComponents aWorkingCopy( m_pData->m_aComponents ); + for ( SubComponents::const_iterator comp = aWorkingCopy.begin(); + comp != aWorkingCopy.end(); ++comp ) { - lcl_closeComponent( comp->second ); + lcl_closeComponent( *comp ); } } catch ( const Exception& ) @@ -450,78 +485,120 @@ namespace dbaui return empty(); } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ bool SubComponentManager::empty() const { ::osl::MutexGuard aGuard( m_pData->getMutex() ); return m_pData->m_aComponents.empty(); } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ void SubComponentManager::onSubComponentOpened( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType, const ElementOpenMode _eOpenMode, const Reference< XComponent >& _rxComponent ) { ::osl::ClearableMutexGuard aGuard( m_pData->getMutex() ); - // put into map - SubComponentAccessor aKey( _rName, _nComponentType, _eOpenMode ); - SubComponentDescriptor aElement( _rxComponent ); +#if OSL_DEBUG_LEVEL > 0 + if ( _rName.getLength() ) + { + // check there does not already exist such a component + SubComponents::const_iterator existentPos = ::std::find_if( + m_pData->m_aComponents.begin(), + m_pData->m_aComponents.end(), + SubComponentMatch( _rName, _nComponentType, _eOpenMode ) + ); + OSL_ENSURE( existentPos == m_pData->m_aComponents.end(), "already existent!" ); + } +#endif + SubComponentDescriptor aElement( _rName, _nComponentType, _eOpenMode, _rxComponent ); ENSURE_OR_THROW( aElement.xModel.is() || aElement.xController.is(), "illegal component" ); - m_pData->m_aComponents.insert( SubComponentMap::value_type( - aKey, aElement - ) ) ; + m_pData->m_aComponents.push_back( aElement ); // add as listener if ( aElement.xController.is() ) aElement.xController->addEventListener( this ); if ( aElement.xModel.is() ) aElement.xModel->addEventListener( this ); + if ( aElement.xDocumentDefinitionProperties.is() ) + aElement.xDocumentDefinitionProperties->addPropertyChangeListener( PROPERTY_NAME, this ); // notify this to interested parties aGuard.clear(); lcl_notifySubComponentEvent( *m_pData, "OnSubComponentOpened", aElement ); } - // ----------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ bool SubComponentManager::activateSubFrame( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType, const ElementOpenMode _eOpenMode ) const { ::osl::MutexGuard aGuard( m_pData->getMutex() ); - SubComponentAccessor aKey( _rName, _nComponentType, _eOpenMode ); - SubComponentMap::const_iterator pos = m_pData->m_aComponents.find( aKey ); + SubComponents::const_iterator pos = ::std::find_if( + m_pData->m_aComponents.begin(), + m_pData->m_aComponents.end(), + SubComponentMatch( _rName, _nComponentType, _eOpenMode ) + ); if ( pos == m_pData->m_aComponents.end() ) // no component with this name/type/open mode return false; - const Reference< XFrame > xFrame( pos->second.xFrame, UNO_SET_THROW ); + const Reference< XFrame > xFrame( pos->xFrame, UNO_SET_THROW ); const Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW ); xTopWindow->toFront(); return true; } - // ----------------------------------------------------------------------------- - bool SubComponentManager::closeSubFrames( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType ) + //------------------------------------------------------------------------------------------------------------------ + bool SubComponentManager::closeSubFrames( const ::rtl::OUString& i_rName, const sal_Int32 _nComponentType ) { ::osl::MutexGuard aGuard( m_pData->getMutex() ); + ENSURE_OR_RETURN_FALSE( i_rName.getLength(), "SubComponentManager::closeSubFrames: illegal name!" ); - SubComponentMap aWorkingCopy( m_pData->m_aComponents ); - for ( SubComponentMap::const_iterator comp = aWorkingCopy.begin(); + SubComponents aWorkingCopy( m_pData->m_aComponents ); + for ( SubComponents::const_iterator comp = aWorkingCopy.begin(); comp != aWorkingCopy.end(); ++comp ) { - if ( ( comp->first.sName != _rName ) || ( comp->first.nComponentType != _nComponentType ) ) + if ( ( comp->sName != i_rName ) || ( comp->nComponentType != _nComponentType ) ) continue; - if ( !lcl_closeComponent( comp->second ) ) + if ( !lcl_closeComponent( *comp ) ) return false; } return true; } -//........................................................................ + //------------------------------------------------------------------------------------------------------------------ + bool SubComponentManager::lookupSubComponent( const Reference< XComponent >& i_rComponent, + ::rtl::OUString& o_rName, sal_Int32& o_rComponentType ) + { + for ( SubComponents::const_iterator comp = m_pData->m_aComponents.begin(); + comp != m_pData->m_aComponents.end(); + ++comp + ) + { + if ( ( comp->xModel.is() + && ( comp->xModel == i_rComponent ) + ) + || ( comp->xController.is() + && ( comp->xController == i_rComponent ) + ) + || ( comp->xFrame.is() + && ( comp->xFrame == i_rComponent ) + ) + ) + { + o_rName = comp->sName; + o_rComponentType = comp->nComponentType; + return true; + } + } + return false; + } + +//...................................................................................................................... } // namespace dbaui -//........................................................................ +//...................................................................................................................... diff --git a/dbaccess/source/ui/app/subcomponentmanager.hxx b/dbaccess/source/ui/app/subcomponentmanager.hxx index 43afc8d3403f..f7f93ab6a53b 100644 --- a/dbaccess/source/ui/app/subcomponentmanager.hxx +++ b/dbaccess/source/ui/app/subcomponentmanager.hxx @@ -30,7 +30,7 @@ #include "AppElementType.hxx" /** === begin UNO includes === **/ -#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/beans/XPropertyChangeListener.hpp> #include <com/sun/star/frame/XController.hpp> /** === end UNO includes === **/ @@ -50,7 +50,7 @@ namespace dbaui //==================================================================== //= SubComponentManager //==================================================================== - typedef ::cppu::WeakImplHelper1 < ::com::sun::star::lang::XEventListener + typedef ::cppu::WeakImplHelper1 < ::com::sun::star::beans::XPropertyChangeListener > SubComponentManager_Base; class SubComponentManager : public SubComponentManager_Base { @@ -60,6 +60,9 @@ namespace dbaui void disposing(); + // XPropertyChangeListener + virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException); + // XEventListener virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); @@ -103,6 +106,24 @@ namespace dbaui const ::rtl::OUString& _rName, const sal_Int32 _nComponentType ); + + /** searches for the given sub component + + @param i_rComponent + the sub component to look up + @param o_rName + contains, upon successful return, the name of the sub component + @param o_nComponentType + contains, upon successful return, the type of the sub component + @return + <TRUE/> if and only if the component was found + */ + bool lookupSubComponent( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& i_rComponent, + ::rtl::OUString& o_rName, + sal_Int32& o_rComponentType + ); + private: ::std::auto_ptr< SubComponentManager_Data > m_pData; }; |