diff options
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/view.hxx | 13 | ||||
-rw-r--r-- | sw/source/uibase/uiview/view.cxx | 31 |
2 files changed, 34 insertions, 10 deletions
diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx index eca967473ae6..a3eddaedf991 100644 --- a/sw/inc/view.hxx +++ b/sw/inc/view.hxx @@ -128,6 +128,18 @@ struct SwApplyTemplate } }; +class SwView; + +// manage connection and disconnection of SwView and SwDocShell +class SwViewGlueDocShell +{ +private: + SwView& m_rView; +public: + SwViewGlueDocShell(SwView& rView, SwDocShell& rDocSh); + ~SwViewGlueDocShell(); +}; + // view of a document class SW_DLLPUBLIC SwView: public SfxViewShell { @@ -167,6 +179,7 @@ class SW_DLLPUBLIC SwView: public SfxViewShell VclPtr<SwEditWin> m_pEditWin; std::unique_ptr<SwWrtShell> m_pWrtShell; + std::unique_ptr<SwViewGlueDocShell> m_xGlueDocShell; SfxShell *m_pShell; // current SubShell at the dispatcher FmFormShell *m_pFormShell; // DB-FormShell diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx index 8d5703a0bfcf..17de503f2082 100644 --- a/sw/source/uibase/uiview/view.cxx +++ b/sw/source/uibase/uiview/view.cxx @@ -920,13 +920,11 @@ SwView::SwView( SfxViewFrame *_pFrame, SfxViewShell* pOldSh ) eMetric = pUsrPref->GetVScrollMetric(); m_pVRuler->SetUnit( eMetric ); - m_pHRuler->SetCharWidth( 371 ); // default character width - m_pVRuler->SetLineHeight( 551 ); // default line height + m_pHRuler->SetCharWidth( 371 ); // default character width + m_pVRuler->SetLineHeight( 551 ); // default line height // Set DocShell - rDocSh.SetView(this); - SW_MOD()->SetView( this ); - + m_xGlueDocShell.reset(new SwViewGlueDocShell(*this, rDocSh)); m_pPostItMgr = new SwPostItMgr(this); // Check and process the DocSize. Via the handler, the shell could not @@ -1047,6 +1045,23 @@ SwView::SwView( SfxViewFrame *_pFrame, SfxViewShell* pOldSh ) GetViewFrame()->GetWindow().AddChildEventListener( LINK( this, SwView, WindowChildEventListener ) ); } +SwViewGlueDocShell::SwViewGlueDocShell(SwView& rView, SwDocShell& rDocSh) + : m_rView(rView) +{ + // Set DocShell + rDocSh.SetView(&m_rView); + SW_MOD()->SetView(&m_rView); +} + +SwViewGlueDocShell::~SwViewGlueDocShell() +{ + SwDocShell* pDocSh = m_rView.GetDocShell(); + if (pDocSh && pDocSh->GetView() == &m_rView) + pDocSh->SetView(nullptr); + if (SW_MOD()->GetView() == &m_rView) + SW_MOD()->SetView(nullptr); +} + SwView::~SwView() { // Notify other LOK views that we are going away. @@ -1062,11 +1077,7 @@ SwView::~SwView() m_pEditWin->Hide(); // prevent problems with painting // Set pointer in SwDocShell to the view again - SwDocShell* pDocSh = GetDocShell(); - if( pDocSh && pDocSh->GetView() == this ) - pDocSh->SetView( nullptr ); - if ( SW_MOD()->GetView() == this ) - SW_MOD()->SetView( nullptr ); + m_xGlueDocShell.reset(); if( m_aTimer.IsActive() && m_bAttrChgNotifiedWithRegistrations ) GetViewFrame()->GetBindings().LEAVEREGISTRATIONS(); |