sw/inc/colwd.hxx                    |    7 +++++--
 sw/inc/swabstdlg.hxx                |    3 +--
 sw/source/ui/dialog/swdlgfact.cxx   |    4 ++--
 sw/source/ui/dialog/swdlgfact.hxx   |    2 +-
 sw/source/ui/table/colwd.cxx        |   27 +++++++++++++++------------
 sw/source/uibase/inc/tablemgr.hxx   |    1 -
 sw/source/uibase/shells/tabsh.cxx   |   13 +++++++++++--
 sw/source/uibase/table/tablemgr.cxx |   16 ----------------
 8 files changed, 35 insertions(+), 38 deletions(-)

New commits:
commit 0fa363faaba5dc9c57cf7fd1d4aa0dd300310682
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Apr 16 15:08:33 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Apr 16 18:34:09 2024 +0200

    tdf#160632 TABLE: Crash when using column width dialog
    
    regression from
        commit a08110be32a6958f27ce9ddb1e2cb2227265dfe1
        Author: Noel Grandin <noel.gran...@collabora.co.uk>
        Date:   Tue Jan 30 12:24:47 2024 +0200
        convert table width dialog to async
    
    we were referencing an object that had already been destroyed by the
    time the dialog completed
    
    Change-Id: I2a06dd99129b53c558d6f5f3f96fc16dcc04f754
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166147
    Tested-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/colwd.hxx b/sw/inc/colwd.hxx
index ab511ee118c0..63d8813b72c2 100644
--- a/sw/inc/colwd.hxx
+++ b/sw/inc/colwd.hxx
@@ -20,13 +20,15 @@
 #define INCLUDED_SW_INC_COLWD_HXX
 
 #include <vcl/weld.hxx>
+#include <memory>
 
 class SwTableFUNC;
+class SwWrtShell;
 
 class SwTableWidthDlg final : public weld::GenericDialogController
 {
 private:
-    SwTableFUNC& m_rFnc;
+    std::unique_ptr<SwTableFUNC> m_xFnc;
 
     std::unique_ptr<weld::SpinButton> m_xColNF;
     std::unique_ptr<weld::MetricSpinButton> m_xWidthMF;
@@ -34,7 +36,8 @@ private:
     DECL_LINK(LoseFocusHdl, weld::SpinButton&, void);
 
 public:
-    SwTableWidthDlg(weld::Window* pParent, SwTableFUNC& rFnc);
+    SwTableWidthDlg(weld::Window* pParent, SwWrtShell* pShell);
+    ~SwTableWidthDlg();
     void Apply();
 };
 
diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index fac76ae5c571..1d205f18624f 100644
--- a/sw/inc/swabstdlg.hxx
+++ b/sw/inc/swabstdlg.hxx
@@ -51,7 +51,6 @@ class SwSectionData;
 struct SwDBData;
 class Printer;
 class SwLabItem;
-class SwTableFUNC;
 class SwChildWinWrapper;
 struct SfxChildWinInfo;
 class SwTOXMark;
@@ -540,7 +539,7 @@ public:
     virtual VclPtr<SfxAbstractDialog> CreateSwBorderDlg(weld::Window* pParent, 
SfxItemSet& rSet, SwBorderModes nType) = 0;
     virtual VclPtr<SfxAbstractDialog> CreateSwWrapDlg(weld::Window* pParent, 
const SfxItemSet& rSet, SwWrtShell* pSh) = 0;
 
-    virtual VclPtr<AbstractSwTableWidthDlg> CreateSwTableWidthDlg(weld::Window 
*pParent, SwTableFUNC &rFnc) = 0;
+    virtual VclPtr<AbstractSwTableWidthDlg> CreateSwTableWidthDlg(weld::Window 
*pParent, SwWrtShell *pShell) = 0;
     virtual VclPtr<SfxAbstractTabDialog> CreateSwTableTabDlg(weld::Window* 
pParent,
         const SfxItemSet* pItemSet, SwWrtShell* pSh) = 0;
 
diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index 415bf658b3c3..42a46be6858f 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -1223,9 +1223,9 @@ VclPtr<SfxAbstractDialog> 
SwAbstractDialogFactory_Impl::CreateSwWrapDlg(weld::Wi
     return 
VclPtr<SwAbstractSfxController_Impl>::Create(std::make_unique<SwWrapDlg>(pParent,
 rSet, pSh, true/*bDrawMode*/));
 }
 
-VclPtr<AbstractSwTableWidthDlg> 
SwAbstractDialogFactory_Impl::CreateSwTableWidthDlg(weld::Window *pParent, 
SwTableFUNC &rFnc)
+VclPtr<AbstractSwTableWidthDlg> 
SwAbstractDialogFactory_Impl::CreateSwTableWidthDlg(weld::Window *pParent, 
SwWrtShell *pShell)
 {
-    return 
VclPtr<AbstractSwTableWidthDlg_Impl>::Create(std::make_unique<SwTableWidthDlg>(pParent,
 rFnc));
+    return 
VclPtr<AbstractSwTableWidthDlg_Impl>::Create(std::make_unique<SwTableWidthDlg>(pParent,
 pShell));
 }
 
 VclPtr<SfxAbstractTabDialog> 
SwAbstractDialogFactory_Impl::CreateSwTableTabDlg(weld::Window* pParent,
diff --git a/sw/source/ui/dialog/swdlgfact.hxx 
b/sw/source/ui/dialog/swdlgfact.hxx
index f94342e23b31..4fc2cea421a3 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -832,7 +832,7 @@ public:
     virtual VclPtr<SfxAbstractDialog> CreateSwBorderDlg(weld::Window* pParent, 
SfxItemSet& rSet, SwBorderModes nType) override;
 
     virtual VclPtr<SfxAbstractDialog> CreateSwWrapDlg(weld::Window* pParent, 
const SfxItemSet& rSet, SwWrtShell* pSh) override;
-    virtual VclPtr<AbstractSwTableWidthDlg> CreateSwTableWidthDlg(weld::Window 
*pParent, SwTableFUNC &rFnc) override;
+    virtual VclPtr<AbstractSwTableWidthDlg> CreateSwTableWidthDlg(weld::Window 
*pParent, SwWrtShell *pShell) override;
     virtual VclPtr<SfxAbstractTabDialog> CreateSwTableTabDlg(weld::Window* 
pParent,
         const SfxItemSet* pItemSet, SwWrtShell* pSh) override;
     virtual VclPtr<AbstractSwFieldDlg> CreateSwFieldDlg(SfxBindings* pB, 
SwChildWinWrapper* pCW, weld::Window *pParent) override;
diff --git a/sw/source/ui/table/colwd.cxx b/sw/source/ui/table/colwd.cxx
index 70e47e19c9ed..65d225050555 100644
--- a/sw/source/ui/table/colwd.cxx
+++ b/sw/source/ui/table/colwd.cxx
@@ -29,38 +29,41 @@
 IMPL_LINK_NOARG(SwTableWidthDlg, LoseFocusHdl, weld::SpinButton&, void)
 {
     sal_uInt16 nId = o3tl::narrowing<sal_uInt16>(m_xColNF->get_value()) - 1;
-    const SwTwips lWidth = m_rFnc.GetColWidth(nId);
-    m_xWidthMF->set_max(m_xWidthMF->normalize(m_rFnc.GetMaxColWidth(nId)), 
FieldUnit::TWIP);
+    const SwTwips lWidth = m_xFnc->GetColWidth(nId);
+    m_xWidthMF->set_max(m_xWidthMF->normalize(m_xFnc->GetMaxColWidth(nId)), 
FieldUnit::TWIP);
     m_xWidthMF->set_value(m_xWidthMF->normalize(lWidth), FieldUnit::TWIP);
 }
 
-SwTableWidthDlg::SwTableWidthDlg(weld::Window *pParent, SwTableFUNC &rTableFnc)
+SwTableWidthDlg::SwTableWidthDlg(weld::Window *pParent, SwWrtShell *pShell)
     : GenericDialogController(pParent, "modules/swriter/ui/columnwidth.ui", 
"ColumnWidthDialog")
-    , m_rFnc(rTableFnc)
+    , m_xFnc(new SwTableFUNC(pShell))
     , m_xColNF(m_xBuilder->weld_spin_button("column"))
     , m_xWidthMF(m_xBuilder->weld_metric_spin_button("width", FieldUnit::CM))
 {
-    bool bIsWeb = rTableFnc.GetShell()
+    m_xFnc->InitTabCols();
+    bool bIsWeb = m_xFnc->GetShell()
                   && (dynamic_cast< const SwWebDocShell* >(
-                                     
rTableFnc.GetShell()->GetView().GetDocShell()) != nullptr );
+                                     
m_xFnc->GetShell()->GetView().GetDocShell()) != nullptr );
     FieldUnit eFieldUnit = SW_MOD()->GetUsrPref( bIsWeb )->GetMetric();
     ::SetFieldUnit(*m_xWidthMF, eFieldUnit);
 
-    m_xColNF->set_max(m_rFnc.GetColCount() + 1);
-    m_xColNF->set_value(m_rFnc.GetCurColNum() + 1);
+    m_xColNF->set_max(m_xFnc->GetColCount() + 1);
+    m_xColNF->set_value(m_xFnc->GetCurColNum() + 1);
 
-    if (m_rFnc.GetColCount() == 0)
-        m_xWidthMF->set_min(m_xWidthMF->normalize(m_rFnc.GetColWidth(0)), 
FieldUnit::TWIP);
+    if (m_xFnc->GetColCount() == 0)
+        m_xWidthMF->set_min(m_xWidthMF->normalize(m_xFnc->GetColWidth(0)), 
FieldUnit::TWIP);
     else
         m_xWidthMF->set_min(m_xWidthMF->normalize(MINLAY), FieldUnit::TWIP);
     m_xColNF->connect_value_changed(LINK(this, SwTableWidthDlg, LoseFocusHdl));
     LoseFocusHdl(*m_xColNF);
 }
 
+SwTableWidthDlg::~SwTableWidthDlg() {}
+
 void SwTableWidthDlg::Apply()
 {
-    m_rFnc.InitTabCols();
-    m_rFnc.SetColWidth(o3tl::narrowing<sal_uInt16>(m_xColNF->get_value() - 1),
+    m_xFnc->InitTabCols();
+    m_xFnc->SetColWidth(o3tl::narrowing<sal_uInt16>(m_xColNF->get_value() - 1),
                        
o3tl::narrowing<sal_uInt16>(m_xWidthMF->denormalize(m_xWidthMF->get_value(FieldUnit::TWIP))));
 }
 
diff --git a/sw/source/uibase/inc/tablemgr.hxx 
b/sw/source/uibase/inc/tablemgr.hxx
index d382d29b6c6e..96b1c34f350b 100644
--- a/sw/source/uibase/inc/tablemgr.hxx
+++ b/sw/source/uibase/inc/tablemgr.hxx
@@ -53,7 +53,6 @@ public:
            ~SwTableFUNC();
 
     void    InitTabCols();
-    void    ColWidthDlg(weld::Window *pParent);
     SwTwips GetColWidth(sal_uInt16 nNum) const;
     SwTwips GetMaxColWidth(sal_uInt16 nNum) const;
     void    SetColWidth(sal_uInt16 nNum, SwTwips nWidth );
diff --git a/sw/source/uibase/shells/tabsh.cxx 
b/sw/source/uibase/shells/tabsh.cxx
index 4d390e6a6a19..63857cfea12f 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -1349,8 +1349,17 @@ void SwTableShell::Execute(SfxRequest &rReq)
         // The last case branch which needs a table manager!!
         case FN_TABLE_SET_COL_WIDTH:
         {
-            SwTableFUNC aMgr( &rSh );
-            aMgr.ColWidthDlg(GetView().GetFrameWeld());
+            // Adjust line height (dialogue)
+            SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
+            VclPtr<AbstractSwTableWidthDlg> 
pDlg(pFact->CreateSwTableWidthDlg(GetView().GetFrameWeld(), &rSh));
+            pDlg->StartExecuteAsync(
+                [pDlg] (sal_Int32 nResult)->void
+                {
+                    if (nResult == RET_OK)
+                        pDlg->Apply();
+                    pDlg->disposeOnce();
+                }
+            );
             break;
         }
         case SID_TABLE_VERT_NONE:
diff --git a/sw/source/uibase/table/tablemgr.cxx 
b/sw/source/uibase/table/tablemgr.cxx
index 852d9d5585f2..ea2983279736 100644
--- a/sw/source/uibase/table/tablemgr.cxx
+++ b/sw/source/uibase/table/tablemgr.cxx
@@ -45,22 +45,6 @@
 
 using namespace ::com::sun::star;
 
-// Adjust line height (dialogue)
-void SwTableFUNC::ColWidthDlg(weld::Window *pParent)
-{
-    InitTabCols();
-    SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
-    VclPtr<AbstractSwTableWidthDlg> pDlg(pFact->CreateSwTableWidthDlg(pParent, 
*this));
-    pDlg->StartExecuteAsync(
-        [pDlg] (sal_Int32 nResult)->void
-        {
-            if (nResult == RET_OK)
-                pDlg->Apply();
-            pDlg->disposeOnce();
-        }
-    );
-}
-
 // Determine the width
 SwTwips SwTableFUNC::GetColWidth(sal_uInt16 nNum) const
 {

Reply via email to