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

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