sw/inc/swabstdlg.hxx                 |    2 -
 sw/source/ui/dialog/swdlgfact.cxx    |    7 +++++-
 sw/source/ui/dialog/swdlgfact.hxx    |    7 +++---
 sw/source/ui/frmdlg/wrap.cxx         |    5 ++--
 sw/source/uibase/inc/drwbassh.hxx    |    2 -
 sw/source/uibase/inc/wrap.hxx        |    7 +++++-
 sw/source/uibase/shells/drwbassh.cxx |   39 +++++++++++++++++++++--------------
 7 files changed, 45 insertions(+), 24 deletions(-)

New commits:
commit 630494adc98a245feadd573aa8463f46b15c7787
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Jan 25 15:40:51 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jan 25 21:41:05 2024 +0100

    make wrap dialog async
    
    Change-Id: I7179209396b2c10d1f8b58d4ec5bbffe4856c53b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162581
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index a9ceb855b337..690b20c6ea3b 100644
--- a/sw/inc/swabstdlg.hxx
+++ b/sw/inc/swabstdlg.hxx
@@ -486,7 +486,7 @@ public:
                                                                   bool 
bSetAutoFormat = true,
                                                                   const 
SwTableAutoFormat* pSelFormat = nullptr ) = 0;
     virtual VclPtr<SfxAbstractDialog> CreateSwBorderDlg(weld::Window* pParent, 
SfxItemSet& rSet, SwBorderModes nType) = 0;
-    virtual VclPtr<SfxAbstractDialog> CreateSwWrapDlg(weld::Window* pParent, 
SfxItemSet& rSet, SwWrtShell* pSh) = 0;
+    virtual VclPtr<SfxAbstractDialog> CreateSwWrapDlg(weld::Window* pParent, 
const SfxItemSet& rSet, SwWrtShell* pSh) = 0;
 
     virtual VclPtr<VclAbstractDialog> CreateSwTableWidthDlg(weld::Window 
*pParent, SwTableFUNC &rFnc) = 0;
     virtual VclPtr<SfxAbstractTabDialog> CreateSwTableTabDlg(weld::Window* 
pParent,
diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index 30e41e4edaf4..412e3682a910 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -112,6 +112,11 @@ short SwAbstractSfxController_Impl::Execute()
     return m_xDlg->run();
 }
 
+bool SwAbstractSfxController_Impl::StartExecuteAsync(AsyncContext &rCtx)
+{
+    return weld::GenericDialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
+}
+
 short AbstractNumFormatDlg_Impl::Execute()
 {
     return m_xDlg->run();
@@ -1126,7 +1131,7 @@ VclPtr<SfxAbstractDialog> 
SwAbstractDialogFactory_Impl::CreateSwBorderDlg(weld::
     return 
VclPtr<SwAbstractSfxController_Impl>::Create(std::make_unique<SwBorderDlg>(pParent,
 rSet, nType));
 }
 
-VclPtr<SfxAbstractDialog> 
SwAbstractDialogFactory_Impl::CreateSwWrapDlg(weld::Window* pParent, 
SfxItemSet& rSet, SwWrtShell* pSh)
+VclPtr<SfxAbstractDialog> 
SwAbstractDialogFactory_Impl::CreateSwWrapDlg(weld::Window* pParent, const 
SfxItemSet& rSet, SwWrtShell* pSh)
 {
     return 
VclPtr<SwAbstractSfxController_Impl>::Create(std::make_unique<SwWrapDlg>(pParent,
 rSet, pSh, true/*bDrawMode*/));
 }
diff --git a/sw/source/ui/dialog/swdlgfact.hxx 
b/sw/source/ui/dialog/swdlgfact.hxx
index c2c043bb3eb6..ac79f2652ddc 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -116,13 +116,14 @@ public:
 
 class SwAbstractSfxController_Impl : public SfxAbstractDialog
 {
-    std::unique_ptr<SfxSingleTabDialogController> m_xDlg;
+    std::shared_ptr<SfxSingleTabDialogController> m_xDlg;
 public:
-    explicit 
SwAbstractSfxController_Impl(std::unique_ptr<SfxSingleTabDialogController> p)
+    explicit 
SwAbstractSfxController_Impl(std::shared_ptr<SfxSingleTabDialogController> p)
         : m_xDlg(std::move(p))
     {
     }
     virtual short Execute() override;
+    virtual bool StartExecuteAsync(AsyncContext &rCtx) override;
     virtual const SfxItemSet* GetOutputItemSet() const override;
     virtual void SetText(const OUString& rStr) override;
 };
@@ -793,7 +794,7 @@ public:
                                                                   const 
SwTableAutoFormat* pSelFormat = nullptr) override;
     virtual VclPtr<SfxAbstractDialog> CreateSwBorderDlg(weld::Window* pParent, 
SfxItemSet& rSet, SwBorderModes nType) override;
 
-    virtual VclPtr<SfxAbstractDialog> CreateSwWrapDlg(weld::Window* pParent, 
SfxItemSet& rSet, SwWrtShell* pSh) override;
+    virtual VclPtr<SfxAbstractDialog> CreateSwWrapDlg(weld::Window* pParent, 
const SfxItemSet& rSet, SwWrtShell* pSh) override;
     virtual VclPtr<VclAbstractDialog> CreateSwTableWidthDlg(weld::Window 
*pParent, SwTableFUNC &rFnc) override;
     virtual VclPtr<SfxAbstractTabDialog> CreateSwTableTabDlg(weld::Window* 
pParent,
         const SfxItemSet* pItemSet, SwWrtShell* pSh) override;
diff --git a/sw/source/ui/frmdlg/wrap.cxx b/sw/source/ui/frmdlg/wrap.cxx
index 684fe38b22bb..a6ebfec47619 100644
--- a/sw/source/ui/frmdlg/wrap.cxx
+++ b/sw/source/ui/frmdlg/wrap.cxx
@@ -51,10 +51,11 @@ const WhichRangesContainer 
SwWrapTabPage::s_aWrapPageRg(svl::Items<
 >);
 
 SwWrapDlg::SwWrapDlg(weld::Window* pParent, const SfxItemSet& rSet, 
SwWrtShell* pWrtShell, bool bDrawMode)
-    : SfxSingleTabDialogController(pParent, &rSet, 
"modules/swriter/ui/wrapdialog.ui", "WrapDialog")
+    : SwWrapDlgBase{rSet}, // this is an async dialog, so we need to store a 
copy of the rSet
+      SfxSingleTabDialogController(pParent, &maInputSet, 
"modules/swriter/ui/wrapdialog.ui", "WrapDialog")
 {
     // create TabPage
-    auto xNewPage = SwWrapTabPage::Create(get_content_area(), this, &rSet);
+    auto xNewPage = SwWrapTabPage::Create(get_content_area(), this, 
&maInputSet);
     SwWrapTabPage* pWrapPage = static_cast<SwWrapTabPage*>(xNewPage.get());
     pWrapPage->SetFormatUsed(false, bDrawMode);
     pWrapPage->SetShell(pWrtShell);
diff --git a/sw/source/uibase/inc/drwbassh.hxx 
b/sw/source/uibase/inc/drwbassh.hxx
index e75576dec2a0..16b273bdef8b 100644
--- a/sw/source/uibase/inc/drwbassh.hxx
+++ b/sw/source/uibase/inc/drwbassh.hxx
@@ -43,7 +43,7 @@ private:
     static void InitInterface_Impl();
 
 public:
-    void        Execute(SfxRequest const &);
+    void        Execute(SfxRequest&);
     void        GetState(SfxItemSet &);
     void        GetDrawAttrStateForIFBX( SfxItemSet& rSet );
     void        DisableState(SfxItemSet &rSet);
diff --git a/sw/source/uibase/inc/wrap.hxx b/sw/source/uibase/inc/wrap.hxx
index c249b0233c81..f9ee8a69131f 100644
--- a/sw/source/uibase/inc/wrap.hxx
+++ b/sw/source/uibase/inc/wrap.hxx
@@ -26,7 +26,12 @@
 class SfxItemSet;
 class SwWrtShell;
 
-class SwWrapDlg final : public SfxSingleTabDialogController
+struct SwWrapDlgBase
+{
+    SfxItemSet maInputSet;
+};
+
+class SwWrapDlg final : private SwWrapDlgBase, public 
SfxSingleTabDialogController
 {
 public:
     SwWrapDlg(weld::Window* pParent, const SfxItemSet& rSet, SwWrtShell* pSh, 
bool bDrawMode);
diff --git a/sw/source/uibase/shells/drwbassh.cxx 
b/sw/source/uibase/shells/drwbassh.cxx
index d4f169992534..2e09143e0335 100644
--- a/sw/source/uibase/shells/drwbassh.cxx
+++ b/sw/source/uibase/shells/drwbassh.cxx
@@ -95,7 +95,7 @@ SwDrawBaseShell::~SwDrawBaseShell()
     SwTransferable::ClearSelection( GetShell() );
 }
 
-void SwDrawBaseShell::Execute(SfxRequest const &rReq)
+void SwDrawBaseShell::Execute(SfxRequest& rReq)
 {
     SwWrtShell *pSh = &GetShell();
     SdrView*    pSdrView = pSh->GetDrawView();
@@ -139,23 +139,32 @@ void SwDrawBaseShell::Execute(SfxRequest const &rReq)
                         aSet.Put(SfxInt16Item(FN_DRAW_WRAP_DLG, 
pSh->GetLayerId().get()));
 
                         pSh->GetObjAttr(aSet);
-                        SwAbstractDialogFactory* pFact = 
SwAbstractDialogFactory::Create();
-                        ScopedVclPtr<SfxAbstractDialog> 
pDlg(pFact->CreateSwWrapDlg(GetView().GetFrameWeld(), aSet, pSh));
 
-                        if (pDlg->Execute() == RET_OK)
-                        {
-                            const SfxItemSet* pOutSet = 
pDlg->GetOutputItemSet();
-                            if(const SfxInt16Item* pWrapItem = 
pOutSet->GetItemIfSet(FN_DRAW_WRAP_DLG, false))
+                        auto xRequest = std::make_shared<SfxRequest>(rReq);
+                        rReq.Ignore(); // the 'old' request is not relevant 
any more
+                        SwAbstractDialogFactory* pFact = 
SwAbstractDialogFactory::Create();
+                        VclPtr<SfxAbstractDialog> 
pDlg(pFact->CreateSwWrapDlg(GetView().GetFrameWeld(), aSet, pSh));
+                        pDlg->StartExecuteAsync(
+                            [pDlg, pSh, xRequest] (sal_Int32 nResult)->void
                             {
-                                short nLayer = pWrapItem->GetValue();
-                                if (nLayer == 1)
-                                    pSh->SelectionToHeaven();
-                                else
-                                    pSh->SelectionToHell();
-                            }
+                                if (nResult == RET_OK)
+                                {
+                                    const SfxItemSet* pOutSet = 
pDlg->GetOutputItemSet();
+                                    if(const SfxInt16Item* pWrapItem = 
pOutSet->GetItemIfSet(FN_DRAW_WRAP_DLG, false))
+                                    {
+                                        short nLayer = pWrapItem->GetValue();
+                                        if (nLayer == 1)
+                                            pSh->SelectionToHeaven();
+                                        else
+                                            pSh->SelectionToHell();
+                                    }
 
-                            pSh->SetObjAttr(*pOutSet);
-                        }
+                                    pSh->SetObjAttr(*pOutSet);
+                                }
+                                pDlg->disposeOnce();
+                                xRequest->Done();
+                            }
+                        );
                     }
                 }
             }

Reply via email to