[Libreoffice-commits] core.git: sw/inc sw/source
Caolán McNamara
caolanm at redhat.com
Fri Jun 1 07:58:26 UTC 2018
sw/inc/view.hxx | 13 +++++++++++++
sw/source/uibase/uiview/view.cxx | 31 +++++++++++++++++++++----------
2 files changed, 34 insertions(+), 10 deletions(-)
New commits:
commit c0c9c9d5f21d65f582de163566c46242d21dc506
Author: Caolán McNamara <caolanm at redhat.com>
Date: Thu May 31 17:14:57 2018 +0100
forcepoint#44 raii for connection and disconnection of SwView and SwDocShell
Change-Id: I11ce25e6fc043e37d4410359438744567cac37f6
Reviewed-on: https://gerrit.libreoffice.org/55146
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
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();
More information about the Libreoffice-commits
mailing list