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

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