Blame SOURCES/0007-tdf-137982-m_xFrame-is-already-disposed.patch

eac0b7
From 7efe51c401ee469ae4835994e5f11b158fd354b9 Mon Sep 17 00:00:00 2001
eac0b7
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
eac0b7
Date: Wed, 4 Nov 2020 13:01:53 +0000
eac0b7
Subject: [PATCH 7/8] tdf#137982 m_xFrame is already disposed
eac0b7
eac0b7
move the frame cleanup into a helper that listens to see if it got
eac0b7
disposed by the preview itself
eac0b7
eac0b7
Change-Id: I523285268118300f18b0f0f0a10fab7a9cced9c6
eac0b7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105221
eac0b7
Tested-by: Jenkins
eac0b7
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
eac0b7
(cherry picked from commit a986db4b2d24669e502e447036851e118cc23036)
eac0b7
---
eac0b7
 sw/source/ui/dbui/dbtablepreviewdialog.cxx | 53 ++++++++++++++++++----
eac0b7
 sw/source/ui/dbui/dbtablepreviewdialog.hxx |  4 +-
eac0b7
 2 files changed, 46 insertions(+), 11 deletions(-)
eac0b7
eac0b7
diff --git a/sw/source/ui/dbui/dbtablepreviewdialog.cxx b/sw/source/ui/dbui/dbtablepreviewdialog.cxx
eac0b7
index 23e7984623d8..8f2d92b1c7d5 100644
eac0b7
--- a/sw/source/ui/dbui/dbtablepreviewdialog.cxx
eac0b7
+++ b/sw/source/ui/dbui/dbtablepreviewdialog.cxx
eac0b7
@@ -20,6 +20,8 @@
eac0b7
 #include <swtypes.hxx>
eac0b7
 #include "dbtablepreviewdialog.hxx"
eac0b7
 #include <comphelper/processfactory.hxx>
eac0b7
+#include <cppuhelper/implbase.hxx>
eac0b7
+#include <com/sun/star/document/XEventListener.hpp>
eac0b7
 #include <com/sun/star/frame/Frame.hpp>
eac0b7
 #include <toolkit/helper/vclunohelper.hxx>
eac0b7
 
eac0b7
@@ -32,6 +34,34 @@ using namespace ::com::sun::star::beans;
eac0b7
 using namespace ::com::sun::star::lang;
eac0b7
 using namespace ::com::sun::star::util;
eac0b7
 
eac0b7
+class DBTablePreviewFrame
eac0b7
+    : public cppu::WeakImplHelper<lang::XEventListener>
eac0b7
+{
eac0b7
+private:
eac0b7
+    css::uno::Reference<css::frame::XFrame2> m_xFrame;
eac0b7
+
eac0b7
+    virtual void SAL_CALL disposing(const lang::EventObject& /*Source*/) override
eac0b7
+    {
eac0b7
+        m_xFrame.clear();
eac0b7
+    }
eac0b7
+
eac0b7
+public:
eac0b7
+    DBTablePreviewFrame(css::uno::Reference<css::frame::XFrame2>& rFrame)
eac0b7
+        : m_xFrame(rFrame)
eac0b7
+    {
eac0b7
+    }
eac0b7
+
eac0b7
+    void cleanup()
eac0b7
+    {
eac0b7
+        if (m_xFrame.is())
eac0b7
+        {
eac0b7
+            m_xFrame->setComponent(nullptr, nullptr);
eac0b7
+            m_xFrame->dispose();
eac0b7
+            m_xFrame.clear();
eac0b7
+        }
eac0b7
+    }
eac0b7
+};
eac0b7
+
eac0b7
 SwDBTablePreviewDialog::SwDBTablePreviewDialog(weld::Window* pParent, uno::Sequence< beans::PropertyValue> const & rValues)
eac0b7
     : SfxDialogController(pParent, "modules/swriter/ui/tablepreviewdialog.ui", "TablePreviewDialog")
eac0b7
     , m_xDescriptionFI(m_xBuilder->weld_label("description"))
eac0b7
@@ -51,22 +81,26 @@ SwDBTablePreviewDialog::SwDBTablePreviewDialog(weld::Window* pParent, uno::Seque
eac0b7
         m_xDescriptionFI->set_label(sDescription.replaceFirst("%1", sTemp));
eac0b7
     }
eac0b7
 
eac0b7
+    css::uno::Reference<css::frame::XFrame2> xFrame;
eac0b7
     try
eac0b7
     {
eac0b7
         // create a frame wrapper for myself
eac0b7
-        m_xFrame = frame::Frame::create( comphelper::getProcessComponentContext() );
eac0b7
-        m_xFrame->initialize(m_xBeamerWIN->CreateChildFrame());
eac0b7
+        xFrame = frame::Frame::create( comphelper::getProcessComponentContext() );
eac0b7
+        xFrame->initialize(m_xBeamerWIN->CreateChildFrame());
eac0b7
     }
eac0b7
     catch (uno::Exception const &)
eac0b7
     {
eac0b7
-        m_xFrame.clear();
eac0b7
+        xFrame.clear();
eac0b7
     }
eac0b7
-    if (m_xFrame.is())
eac0b7
+    if (xFrame.is())
eac0b7
     {
eac0b7
+        m_xFrameListener.set(new DBTablePreviewFrame(xFrame));
eac0b7
+        xFrame->addEventListener(m_xFrameListener.get());
eac0b7
+
eac0b7
         util::URL aURL;
eac0b7
         aURL.Complete = ".component:DB/DataSourceBrowser";
eac0b7
-        uno::Reference<frame::XDispatch> xD = m_xFrame->queryDispatch(aURL, "", 0x0C);
eac0b7
-        if(xD.is())
eac0b7
+        uno::Reference<frame::XDispatch> xD = xFrame->queryDispatch(aURL, "", 0x0C);
eac0b7
+        if (xD.is())
eac0b7
         {
eac0b7
             xD->dispatch(aURL, rValues);
eac0b7
             m_xBeamerWIN->show();
eac0b7
@@ -76,11 +110,10 @@ SwDBTablePreviewDialog::SwDBTablePreviewDialog(weld::Window* pParent, uno::Seque
eac0b7
 
eac0b7
 SwDBTablePreviewDialog::~SwDBTablePreviewDialog()
eac0b7
 {
eac0b7
-    if(m_xFrame.is())
eac0b7
+    if (m_xFrameListener)
eac0b7
     {
eac0b7
-        m_xFrame->setComponent(nullptr, nullptr);
eac0b7
-        m_xFrame->dispose();
eac0b7
-        m_xFrame.clear();
eac0b7
+        m_xFrameListener->cleanup();
eac0b7
+        m_xFrameListener.clear();
eac0b7
     }
eac0b7
 }
eac0b7
 
eac0b7
diff --git a/sw/source/ui/dbui/dbtablepreviewdialog.hxx b/sw/source/ui/dbui/dbtablepreviewdialog.hxx
eac0b7
index ec2c58d92bf3..27e6e83d39ca 100644
eac0b7
--- a/sw/source/ui/dbui/dbtablepreviewdialog.hxx
eac0b7
+++ b/sw/source/ui/dbui/dbtablepreviewdialog.hxx
eac0b7
@@ -27,12 +27,14 @@ namespace com{ namespace sun{ namespace star{
eac0b7
     namespace frame{ class XFrame2;     }
eac0b7
     }}}
eac0b7
 
eac0b7
+class DBTablePreviewFrame;
eac0b7
+
eac0b7
 class SwDBTablePreviewDialog : public SfxDialogController
eac0b7
 {
eac0b7
     std::unique_ptr<weld::Label> m_xDescriptionFI;
eac0b7
     std::unique_ptr<weld::Container> m_xBeamerWIN;
eac0b7
 
eac0b7
-    css::uno::Reference< css::frame::XFrame2 >         m_xFrame;
eac0b7
+    rtl::Reference<DBTablePreviewFrame> m_xFrameListener;
eac0b7
 public:
eac0b7
     SwDBTablePreviewDialog(weld::Window* pParent,
eac0b7
             css::uno::Sequence< css::beans::PropertyValue> const & rValues  );
eac0b7
-- 
eac0b7
2.28.0
eac0b7