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

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