diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2009-12-03 09:29:45 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2009-12-03 09:29:45 +0100 |
commit | 5b4f0e7f834b27ddb0bdfece3786ced33c3917dd (patch) | |
tree | ba6c6196d3ba4e2d390d73a7547086768a3b744b /sfx2/source/view | |
parent | 11e41fb8dde36b188c579fd440bfc32b3fc63673 (diff) |
[CWS autorecovery] initial implementation of XModel2::createViewController
Diffstat (limited to 'sfx2/source/view')
-rw-r--r-- | sfx2/source/view/sfxbasecontroller.cxx | 159 | ||||
-rw-r--r-- | sfx2/source/view/topfrm.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/view/viewfrm.cxx | 66 | ||||
-rw-r--r-- | sfx2/source/view/viewsh.cxx | 19 |
4 files changed, 86 insertions, 160 deletions
diff --git a/sfx2/source/view/sfxbasecontroller.cxx b/sfx2/source/view/sfxbasecontroller.cxx index 8c5968efe399..388cca5145f8 100644 --- a/sfx2/source/view/sfxbasecontroller.cxx +++ b/sfx2/source/view/sfxbasecontroller.cxx @@ -56,6 +56,7 @@ #include <com/sun/star/frame/CommandGroup.hpp> #include <com/sun/star/frame/XFrame.hpp> #include <com/sun/star/frame/XBorderResizeListener.hpp> +#include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/lang/EventObject.hpp> #include <com/sun/star/lang/XEventListener.hpp> #include <com/sun/star/lang/XComponent.hpp> @@ -113,6 +114,13 @@ #define TIMEOUT_START_RESCHEDULE 10L /* 10th s */ using namespace ::com::sun::star; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::RuntimeException; +using ::com::sun::star::uno::UNO_QUERY_THROW; +using ::com::sun::star::lang::DisposedException; +using ::com::sun::star::awt::XWindow; +using ::com::sun::star::frame::XController; +using ::com::sun::star::frame::XDispatchProvider; namespace css = ::com::sun::star; struct GroupIDToCommandGroup @@ -224,7 +232,7 @@ void reschedule() class SfxStatusIndicator : public ::cppu::WeakImplHelper2< ::com::sun::star::task::XStatusIndicator, ::com::sun::star::lang::XEventListener > { friend class SfxBaseController; - ::com::sun::star::uno::Reference < XCONTROLLER > xOwner; + ::com::sun::star::uno::Reference < XController > xOwner; ::com::sun::star::uno::Reference < ::com::sun::star::task::XStatusIndicator > xProgress; SfxWorkWindow* pWorkWindow; sal_Int32 _nRange; @@ -517,8 +525,7 @@ void SAL_CALL IMPL_SfxBaseController_ListenerHelper::disposing( const EVENTOBJEC //________________________________________________________________________________________________________ DBG_NAME(sfx2_SfxBaseController) SfxBaseController::SfxBaseController( SfxViewShell* pViewShell ) - : IMPL_SfxBaseController_MutexContainer ( ) - , m_pData ( new IMPL_SfxBaseController_DataContainer( m_aMutex, pViewShell, this )) + : m_pData ( new IMPL_SfxBaseController_DataContainer( m_aMutex, pViewShell, this )) { DBG_CTOR(sfx2_SfxBaseController,NULL); m_pData->m_pViewShell->SetController( this ); @@ -535,138 +542,40 @@ SfxBaseController::~SfxBaseController() } //________________________________________________________________________________________________________ -// SfxBaseController -> XInterface +// SfxBaseController -> XController2 //________________________________________________________________________________________________________ -ANY SAL_CALL SfxBaseController::queryInterface( const UNOTYPE& rType ) throw( RUNTIMEEXCEPTION ) -{ - // Attention: - // Don't use mutex or guard in this method!!! Is a method of XInterface. - - // Ask for my own supported interfaces ... - ANY aReturn( ::cppu::queryInterface( rType , - static_cast< XTYPEPROVIDER* > ( this ) , - static_cast< XCOMPONENT* > ( this ) , - static_cast< XCONTROLLER* > ( this ) , - static_cast< XCONTROLLERBORDER* > ( this ) , - static_cast< XUSERINPUTINTERCEPTION* > ( this ) , - static_cast< XSTATUSINDICATORSUPPLIER* > ( this ) , - static_cast< XCONTEXTMENUINTERCEPTION* > ( this ) , - static_cast< XDISPATCHPROVIDER* > ( this ), - static_cast< XTITLE* > ( this ), - static_cast< XTITLECHANGEBROADCASTER* > ( this ), - static_cast< XDISPATCHINFORMATIONPROVIDER* > ( this ) ) ) ; - - // If searched interface supported by this class ... - if ( aReturn.hasValue() == sal_True ) - { - // ... return this information. - return aReturn ; - } - else - { - // Else; ... ask baseclass for interfaces! - return OWeakObject::queryInterface( rType ) ; - } -} -//________________________________________________________________________________________________________ -// SfxBaseController -> XInterface -//________________________________________________________________________________________________________ - -void SAL_CALL SfxBaseController::acquire() throw() +Reference< XWindow > SAL_CALL SfxBaseController::getComponentWindow() throw (RuntimeException) { - // Attention: - // Don't use mutex or guard in this method!!! Is a method of XInterface. - - // Forward to baseclass - OWeakObject::acquire() ; -} - -//________________________________________________________________________________________________________ -// SfxBaseController -> XInterface -//________________________________________________________________________________________________________ - -void SAL_CALL SfxBaseController::release() throw() -{ - // Attention: - // Don't use mutex or guard in this method!!! Is a method of XInterface. + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + if ( !m_pData->m_pViewShell ) + throw DisposedException(); - // Forward to baseclass - OWeakObject::release() ; + return Reference< XWindow >( GetViewFrame_Impl()->GetFrame()->GetWindow().GetComponentInterface(), UNO_QUERY_THROW ); } -//________________________________________________________________________________________________________ -// SfxBaseController -> XTypeProvider -//________________________________________________________________________________________________________ - -SEQUENCE< UNOTYPE > SAL_CALL SfxBaseController::getTypes() throw( RUNTIMEEXCEPTION ) +::rtl::OUString SAL_CALL SfxBaseController::getViewControllerName() throw (RuntimeException) { - // Optimize this method ! - // We initialize a static variable only one time. And we don't must use a mutex at every call! - // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! - static OTYPECOLLECTION* pTypeCollection = NULL ; - - if ( pTypeCollection == NULL ) - { - // Ready for multithreading; get global mutex for first call of this method only! see before - MUTEXGUARD aGuard( MUTEX::getGlobalMutex() ) ; - - // Control these pointer again ... it can be, that another instance will be faster then these! - if ( pTypeCollection == NULL ) - { - // Create a static typecollection ... - static OTYPECOLLECTION aTypeCollection( ::getCppuType(( const REFERENCE< XTYPEPROVIDER >*)NULL ) , - ::getCppuType(( const REFERENCE< XCONTROLLER >*)NULL ) , - ::getCppuType(( const REFERENCE< XCONTROLLERBORDER >*)NULL ) , - ::getCppuType(( const REFERENCE< XDISPATCHPROVIDER >*)NULL ) , - ::getCppuType(( const REFERENCE< XSTATUSINDICATORSUPPLIER >*)NULL ) , - ::getCppuType(( const REFERENCE< XCONTEXTMENUINTERCEPTION >*)NULL ) , - ::getCppuType(( const REFERENCE< XUSERINPUTINTERCEPTION >*)NULL ) , - ::getCppuType(( const REFERENCE< XTITLE >*)NULL ) , - ::getCppuType(( const REFERENCE< XTITLECHANGEBROADCASTER >*)NULL ) , - ::getCppuType(( const REFERENCE< XDISPATCHINFORMATIONPROVIDER >*)NULL ) ); - // ... and set his address to static pointer! - pTypeCollection = &aTypeCollection ; - } - } + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + if ( !m_pData->m_pViewShell ) + throw DisposedException(); - return pTypeCollection->getTypes() ; + ::rtl::OUStringBuffer sViewName; + sViewName.appendAscii( "view" ); + sViewName.append( sal_Int32( GetViewFrame_Impl()->GetCurViewId() ) ); + return sViewName.makeStringAndClear(); } -//________________________________________________________________________________________________________ -// SfxBaseController -> XTypeProvider -//________________________________________________________________________________________________________ - -SEQUENCE< sal_Int8 > SAL_CALL SfxBaseController::getImplementationId() throw( RUNTIMEEXCEPTION ) +SfxViewFrame* SfxBaseController::GetViewFrame_Impl() const { - // Create one Id for all instances of this class. - // Use ethernet address to do this! (sal_True) - - // Optimize this method - // We initialize a static variable only one time. And we don't must use a mutex at every call! - // For the first call; pID is NULL - for the second call pID is different from NULL! - static OIMPLEMENTATIONID* pID = NULL ; - - if ( pID == NULL ) - { - // Ready for multithreading; get global mutex for first call of this method only! see before - MUTEXGUARD aGuard( MUTEX::getGlobalMutex() ) ; - - // Control these pointer again ... it can be, that another instance will be faster then these! - if ( pID == NULL ) - { - // Create a new static ID ... - static OIMPLEMENTATIONID aID( sal_False ) ; - // ... and set his address to static pointer! - pID = &aID ; - } - } - - return pID->getImplementationId() ; + ENSURE_OR_THROW( m_pData->m_pViewShell, "not to be called without a view shell" ); + SfxViewFrame* pActFrame = m_pData->m_pViewShell->GetFrame(); + ENSURE_OR_THROW( pActFrame, "a view shell without a view frame is pretty pathological" ); + return pActFrame; } //________________________________________________________________________________________________________ -// SfxBaseController -> XController +// SfxBaseController -> XController2 -> XController //________________________________________________________________________________________________________ void SAL_CALL SfxBaseController::attachFrame( const REFERENCE< XFRAME >& xFrame ) throw( ::com::sun::star::uno::RuntimeException ) @@ -856,7 +765,7 @@ REFERENCE< XDISPATCH > SAL_CALL SfxBaseController::queryDispatch( const UNOU if ( xFrame.is() ) xFrame->setName( sTargetFrameName ); - REFERENCE < XDISPATCHPROVIDER > xProv( xFrame, ::com::sun::star::uno::UNO_QUERY ); + Reference< XDispatchProvider > xProv( xFrame, ::com::sun::star::uno::UNO_QUERY ); if ( xProv.is() ) return xProv->queryDispatch( aURL, sTargetFrameName, ::com::sun::star::frame::FrameSearchFlag::SELF ); } @@ -1089,11 +998,11 @@ void SfxBaseController::BorderWidthsChanged_Impl() void SAL_CALL SfxBaseController::dispose() throw( ::com::sun::star::uno::RuntimeException ) { ::vos::OGuard aGuard( Application::GetSolarMutex() ); - REFERENCE < XCONTROLLER > xTmp( this ); + Reference< XController > xTmp( this ); m_pData->m_bDisposing = sal_True ; EVENTOBJECT aEventObject; - aEventObject.Source = (XCONTROLLER*)this ; + aEventObject.Source = *this ; m_pData->m_aListenerContainer.disposeAndClear( aEventObject ) ; if ( m_pData->m_pController && m_pData->m_pController->getFrame().is() ) @@ -1110,7 +1019,7 @@ void SAL_CALL SfxBaseController::dispose() throw( ::com::sun::star::uno::Runtime if ( pFrame ) { EVENTOBJECT aObject; - aObject.Source = (OWEAKOBJECT*)this ; + aObject.Source = *this ; SfxObjectShell* pDoc = pFrame->GetObjectShell() ; SfxViewFrame *pView = SfxViewFrame::GetFirst(pDoc); diff --git a/sfx2/source/view/topfrm.cxx b/sfx2/source/view/topfrm.cxx index 4bd01d3a2667..76b6b12346ad 100644 --- a/sfx2/source/view/topfrm.cxx +++ b/sfx2/source/view/topfrm.cxx @@ -792,7 +792,7 @@ sal_Bool SfxFrame::InsertDocument_Impl( SfxObjectShell& rDoc, const SfxItemSet& OSL_ENSURE( ( rDoc.Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ) == SFX_LOADED_MAINDOCUMENT, "SfxFrame::InsertDocument_Impl: so this code wasn't dead?" ); // Before CWS autorecovery, there was code which postponed setting the ViewData/Mark to a later time - // (SfxObjectShell::PositionView_Impl), but it seems this branch was never used, since loads this method + // (SfxObjectShell::PositionView_Impl), but it seems this branch was never used, since this method // here is never called before the load process finished. if ( pViewDataItem ) { diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 77b0840e349e..6867f90b3603 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -66,7 +66,7 @@ #include <com/sun/star/frame/XFramesSupplier.hpp> #include <com/sun/star/awt/XWindow.hpp> #include <com/sun/star/frame/XController.hpp> -#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/frame/XModel2.hpp> #include <com/sun/star/util/XURLTransformer.hpp> #include <com/sun/star/util/XCloseable.hpp> #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp> @@ -1328,12 +1328,15 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) break; } - case SFX_HINT_DYING: case SFX_HINT_DEINITIALIZING: - // when the Object is being deleted, destroy the view too GetFrame()->DoClose(); + break; + case SFX_HINT_DYING: + // when the Object is being deleted, destroy the view too if ( xObjSh.Is() ) ReleaseObjectShell_Impl(); + else + GetFrame()->DoClose(); break; } @@ -2019,43 +2022,37 @@ SfxViewShell* SfxViewFrame::LoadNewView_Impl( const USHORT i_nNewViewNo, SfxView OSL_PRECOND( GetViewShell() == NULL, "SfxViewFrame::LoadNewView_Impl: not allowed to be called with an exsiting view shell!" ); OSL_PRECOND( GetObjectShell() != NULL, "SfxViewFrame::LoadNewView_Impl: no document -> no loading!" ); - // our UNO doc - const Reference < XModel > xModel( GetObjectShell()->GetModel(), UNO_QUERY_THROW ); + const Reference < XFrame > xFrame( GetFrame()->GetFrameInterface() ); + const Reference < XModel2 > xModel( GetObjectShell()->GetModel(), UNO_QUERY_THROW ); - // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - // >>> to be moved into a UNO view factory implementation - SfxObjectFactory& rDocumentFactory = GetObjectShell()->GetFactory(); + const USHORT nViewId = GetObjectShell()->GetFactory().GetViewFactory( i_nNewViewNo ).GetOrdinal(); + ::rtl::OUStringBuffer sViewName; + sViewName.appendAscii( "view" ); + sViewName.append( sal_Int32( nViewId ) ); + // TODO: extende the SfxViewFactory with support for speaking view names - // remember ViewID - pImp->nCurViewId = rDocumentFactory.GetViewFactory( i_nNewViewNo ).GetOrdinal(); - // TODO: shouldn't this be done in success case only? + // let the model create a new controller + ::comphelper::NamedValueCollection aViewCreationArgs; + if ( i_pOldShell != NULL ) + aViewCreationArgs.put( "PreviousView", i_pOldShell->GetController() ); - SfxViewFactory& rViewFactory = rDocumentFactory.GetViewFactory( i_nNewViewNo ); + const Reference< XController2 > xController( xModel->createViewController( + sViewName.makeStringAndClear(), + aViewCreationArgs.getPropertyValues(), + xFrame + ) ); + SfxViewShell* pViewShell = SfxViewShell::Get( xController.get() ); + ENSURE_OR_THROW( pViewShell, "invalid controller returned by view factory" ); - SfxViewShell* pViewShell = rViewFactory.CreateInstance( this, i_pOldShell ); - ENSURE_OR_THROW( pViewShell, "invalid view shell provided by factory" ); - - // by setting the ViewShell it is prevented that disposing the Controller will destroy this ViewFrame also - GetDispatcher()->SetDisableFlags( 0 ); - SetViewShell_Impl( pViewShell ); - - // ensure a default controller, if the view shell did not provide an own implementation - if ( !pViewShell->GetController().is() ) - pViewShell->SetController( new SfxBaseController( pViewShell ) ); - - // <<< to be moved into a UNO view factory implementation - // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + // remember ViewID + pImp->nCurViewId = nViewId; // introduce model/view/controller to each other - Reference < XWindow > xWindow( GetFrame()->GetWindow().GetComponentInterface(), UNO_QUERY ); - Reference < XFrame > xFrame( GetFrame()->GetFrameInterface() ); - Reference < XController > xController( pViewShell->GetController() ); - - xController->attachModel( xModel ); - xModel->connectController( xController ); - xFrame->setComponent( xWindow, xController ); + xController->attachModel( xModel.get() ); + xModel->connectController( xController.get() ); + xFrame->setComponent( xController->getComponentWindow(), xController.get() ); xController->attachFrame( xFrame ); - xModel->setCurrentController( xController ); + xModel->setCurrentController( xController.get() ); return pViewShell; } @@ -2141,7 +2138,8 @@ sal_Bool SfxViewFrame::SwitchToViewShell_Impl { // the SfxCode is not able to cope with exceptions thrown while creating views // the code will crash in the stack unwinding procedure, so we shouldn't let exceptions go through here - DBG_ERROR("Exception in SwitchToViewShell_Impl - urgent issue. Please contact development!"); + DBG_UNHANDLED_EXCEPTION(); + return sal_False; } DBG_ASSERT( SFX_APP()->GetViewFrames_Impl().Count() == SFX_APP()->GetViewShells_Impl().Count(), "Inconsistent view arrays!" ); diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 75ee988e29fd..48cd21452699 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -1360,6 +1360,25 @@ SfxViewShell* SfxViewShell::Current() //-------------------------------------------------------------------- +SfxViewShell* SfxViewShell::Get( const Reference< XController>& i_rController ) +{ + if ( !i_rController.is() ) + return NULL; + + SfxViewShell* pViewShell = NULL; + for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst( NULL, FALSE ); + pViewShell; + pViewShell = SfxViewShell::GetNext( *pViewShell, NULL, FALSE ) + ) + { + if ( pViewShell->GetController() == i_rController ) + return pViewShell; + } + return NULL; +} + +//-------------------------------------------------------------------- + SdrView* SfxViewShell::GetDrawView() const /* [Beschreibung] |