summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2018-05-31 17:14:57 +0100
committerCaolán McNamara <caolanm@redhat.com>2018-06-01 09:58:01 +0200
commitc0c9c9d5f21d65f582de163566c46242d21dc506 (patch)
tree72ad6df5d7d50d107baba98fe5914a2cb10afd84 /sw
parent2ded7acd61cf01a7c50d770b17605252738ed684 (diff)
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@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/view.hxx13
-rw-r--r--sw/source/uibase/uiview/view.cxx31
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();