sc/source/ui/formdlg/formula.cxx   |    4 --
 sc/source/ui/inc/anyrefdg.hxx      |    3 -
 sc/source/ui/miscdlgs/anyrefdg.cxx |   21 ++++++-------
 vcl/inc/qt5/QtInstanceDialog.hxx   |    5 ++-
 vcl/qt5/QtInstanceBuilder.cxx      |    1 
 vcl/qt5/QtInstanceDialog.cxx       |   56 +++++++++++++++++++++++++++++++++++--
 6 files changed, 70 insertions(+), 20 deletions(-)

New commits:
commit 134176972ebb92dc94f34b1c17e71eaa0da09bbe
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Aug 11 12:02:21 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Mon Aug 11 23:04:11 2025 +0200

    sc: Pass ScFormulaReferenceHelper's dialog in ctor
    
    ... instead of having a separate setter that gets
    called separately after the ScFormulaReferenceHelper
    was constructed.
    
    Change-Id: I38c4b39454d1cba1496bd9f89b6b2fecd5d7122b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189358
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/sc/source/ui/formdlg/formula.cxx b/sc/source/ui/formdlg/formula.cxx
index 1fee98e14e46..72e8e064a147 100644
--- a/sc/source/ui/formdlg/formula.cxx
+++ b/sc/source/ui/formdlg/formula.cxx
@@ -59,10 +59,9 @@ using namespace com::sun::star;
 ScFormulaDlg::ScFormulaDlg(SfxBindings* pB, SfxChildWindow* pCW,
                            weld::Window* pParent, const ScViewData& rViewData, 
const formula::IFunctionManager* _pFunctionMgr)
     : formula::FormulaDlg(pB, pCW, pParent, _pFunctionMgr, this)
-    , m_aHelper(this,pB)
+    , m_aHelper(this, pB, m_xDialog.get())
     , m_pViewShell( nullptr )
 {
-    m_aHelper.SetDialog(m_xDialog.get());
     ScModule* pScMod = ScModule::get();
     pScMod->InputEnterHandler();
     m_pViewShell = nullptr;
@@ -172,7 +171,6 @@ ScFormulaDlg::ScFormulaDlg(SfxBindings* pB, SfxChildWindow* 
pCW,
     OUString rStrExp = GetMeText();
 
     Update(rStrExp);
-
 }
 
 void ScFormulaDlg::notifyChange()
diff --git a/sc/source/ui/inc/anyrefdg.hxx b/sc/source/ui/inc/anyrefdg.hxx
index 2dbced0743d7..0d424e123f77 100644
--- a/sc/source/ui/inc/anyrefdg.hxx
+++ b/sc/source/ui/inc/anyrefdg.hxx
@@ -48,7 +48,7 @@ class ScFormulaReferenceHelper
     DECL_LINK( ActivateHdl, weld::Widget&, bool );
 
 public:
-    ScFormulaReferenceHelper(IAnyRefDialog* _pDlg, SfxBindings* _pBindings);
+    ScFormulaReferenceHelper(IAnyRefDialog* _pDlg, SfxBindings* _pBindings, 
weld::Dialog* pDialog);
     ~ScFormulaReferenceHelper();
     void dispose();
 
@@ -64,7 +64,6 @@ public:
     void                RefInputDone( bool bForced );
     void                ToggleCollapsed( formula::RefEdit* pEdit, 
formula::RefButton* pButton );
 
-    void                SetDialog(weld::Dialog* pDialog) { m_pDialog = 
pDialog; }
     void                DoClose( sal_uInt16 nId );
     void                SetDispatcherLock( bool bLock );
     static void         EnableSpreadsheets( bool bFlag = true );
diff --git a/sc/source/ui/miscdlgs/anyrefdg.cxx 
b/sc/source/ui/miscdlgs/anyrefdg.cxx
index cdf6c1866eae..b409626ac778 100644
--- a/sc/source/ui/miscdlgs/anyrefdg.cxx
+++ b/sc/source/ui/miscdlgs/anyrefdg.cxx
@@ -44,14 +44,15 @@
 
 #include <memory>
 
-ScFormulaReferenceHelper::ScFormulaReferenceHelper(IAnyRefDialog* 
_pDlg,SfxBindings* _pBindings)
- : m_pDlg(_pDlg)
- , m_pRefEdit (nullptr)
- , m_pRefBtn (nullptr)
- , m_pDialog(nullptr)
- , m_pBindings(_pBindings)
- , m_nRefTab(0)
- , m_bHighlightRef(false)
+ScFormulaReferenceHelper::ScFormulaReferenceHelper(IAnyRefDialog* _pDlg, 
SfxBindings* _pBindings,
+                                                   weld::Dialog* pDialog)
+    : m_pDlg(_pDlg)
+    , m_pRefEdit(nullptr)
+    , m_pRefBtn(nullptr)
+    , m_pDialog(pDialog)
+    , m_pBindings(_pBindings)
+    , m_nRefTab(0)
+    , m_bHighlightRef(false)
 {
     ScInputOptions aInputOption = ScModule::get()->GetInputOptions();
     m_bEnableColorRef=aInputOption.GetRangeFinder();
@@ -575,11 +576,9 @@ static void lcl_HideAllReferences()
 ScRefHandler::ScRefHandler(SfxDialogController& rController, SfxBindings* pB, 
bool bBindRef)
     : m_pController(&rController)
     , m_bInRefMode(false)
-    , m_aHelper(this, pB)
+    , m_aHelper(this, pB, rController.getDialog())
     , m_pMyBindings(pB)
 {
-    m_aHelper.SetDialog(rController.getDialog());
-
     if( bBindRef ) EnterRefMode();
 }
 
commit 8f1223d4c8833dc012da22ef02e0d307f5db1d06
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Aug 11 11:46:42 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Mon Aug 11 23:04:05 2025 +0200

    tdf#130857 qt weld: Support sc "Define Range" dialog
    
    This means that native Qt widgets are used for that dialog
    now when using the qt5 or qt6 VCL plugin and starting LO with
    environment variable SAL_VCL_QT_USE_WELDED_WIDGETS=1 set.
    
    This dialog makes use of the logic newly implemented
    for QtInstanceDialog in previous commit
    
        Change-Id: I47362242a918c2a0d7b7c8658b376b4cf28567db
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Mon Aug 11 11:40:53 2025 +0200
    
            tdf#130857 qt weld: Implement QtInstanceDialog::{,undo_}collapse
    
    To trigger that code path:
    
    * start Calc
    * select some cells
    * "Data" -> "Define Range"
    * type "foobar" into the name field
    * click on the "Shrink" button
    * select some range in the document
    * click the "Expand" button
    
    Other than for the gtk3 or gen/VCL implementations, the "Range"
    label of the corresponding "GtkFrame" object defined in the
    UI file (sc/uiconfig/scalc/ui/definedatabaserangedialog.ui)
    remains visible when the dialog gets collapsed, because the
    text is set in the QGroupBox that is used for the "GtkFrame"
    object in the Qt weld implementation and which is the parent
    of the edit that remains visible together with all of its parents,
    while for the GTK and VCL implementations, the label is a separate
    widget, and therefore not a parent widget of any of the widgets
    that should remain visible.
    
    Change-Id: If1ceb6a744f267f69325c7ef8df5907dc98a9554
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189357
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index 1e51273205f6..baef19a835ae 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -124,6 +124,7 @@ bool QtInstanceBuilder::IsUIFileSupported(const OUString& 
rUIFile, const weld::W
         u"filter/ui/xsltfilterdialog.ui"_ustr,
         u"modules/BasicIDE/ui/gotolinedialog.ui"_ustr,
         u"modules/BasicIDE/ui/newlibdialog.ui"_ustr,
+        u"modules/scalc/ui/definedatabaserangedialog.ui"_ustr,
         u"modules/scalc/ui/gotosheetdialog.ui"_ustr,
         u"modules/scalc/ui/groupbydate.ui"_ustr,
         u"modules/scalc/ui/inputstringdialog.ui"_ustr,
commit 9755596200cb080b39575f1c6f3281aaa6dfba6b
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Aug 11 11:40:53 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Mon Aug 11 23:03:58 2025 +0200

    tdf#130857 qt weld: Implement QtInstanceDialog::{,undo_}collapse
    
    Implement the weld::Dialog::collapse and
    weld::Dialog::undo_collapse API that can be used
    to temporarily hide all dialog widgets except for
    one or two, and restore previous visibilibty of
    all widgets in weld::Dialog::undo_collapse.
    
    This is used e.g. in Calc's "Data" -> "Define Range"
    dialog, for which support will be declared in an
    upcoming commit.
    
    Change-Id: I47362242a918c2a0d7b7c8658b376b4cf28567db
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189356
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/qt5/QtInstanceDialog.hxx b/vcl/inc/qt5/QtInstanceDialog.hxx
index aa183cf18efb..4d9757ad0e10 100644
--- a/vcl/inc/qt5/QtInstanceDialog.hxx
+++ b/vcl/inc/qt5/QtInstanceDialog.hxx
@@ -27,6 +27,9 @@ class QtInstanceDialog : public QtInstanceWindow, public 
virtual weld::Dialog
     std::shared_ptr<weld::Dialog> m_xRunAsyncDialog;
     std::function<void(sal_Int32)> m_aRunAsyncFunc;
 
+    // widgets visible before collapse() was called, should be visible again 
after undo_collapse()
+    std::vector<QWidget*> m_aVisibleWidgetsBeforeCollapsing;
+
 public:
     QtInstanceDialog(QDialog* pDialog);
     ~QtInstanceDialog();
@@ -37,7 +40,7 @@ public:
     virtual bool runAsync(std::shared_ptr<Dialog> const& rxSelf,
                           const std::function<void(sal_Int32)>& func) override;
 
-    virtual void collapse(weld::Widget&, weld::Widget*) override;
+    virtual void collapse(weld::Widget& rEdit, weld::Widget* pButton) override;
 
     virtual void undo_collapse() override;
 
diff --git a/vcl/qt5/QtInstanceDialog.cxx b/vcl/qt5/QtInstanceDialog.cxx
index b449f6d20ab5..cfece22acbf3 100644
--- a/vcl/qt5/QtInstanceDialog.cxx
+++ b/vcl/qt5/QtInstanceDialog.cxx
@@ -80,12 +80,62 @@ bool QtInstanceDialog::runAsync(std::shared_ptr<Dialog> 
const& rxSelf,
     return true;
 }
 
-void QtInstanceDialog::collapse(weld::Widget&, weld::Widget*)
+void QtInstanceDialog::collapse(weld::Widget& rEdit, weld::Widget* pButton)
 {
-    assert(false && "Not implemented yet");
+    SolarMutexGuard g;
+
+    assert(m_aVisibleWidgetsBeforeCollapsing.empty() && "Dialog already 
collapsed?");
+
+    GetQtInstance().RunInMainThread([&] {
+#if QT_VERSION_CHECK(6, 3, 0)
+        const QList<QWidget*> m_pChildren = 
m_pDialog->findChildren<QWidget*>();
+#else
+        const QList<QWidget*> m_pChildren = 
m_pDialog->findChildren<QWidget*>(QLatin1String(""));
+#endif
+        // hide all widgets
+        for (QWidget* pChild : m_pChildren)
+        {
+            if (!pChild->isHidden())
+            {
+                m_aVisibleWidgetsBeforeCollapsing.push_back(pChild);
+                pChild->hide();
+            }
+        }
+
+        // make the given widgets (and their ancestors) visible again
+        QtInstanceWidget& rQtEdit = dynamic_cast<QtInstanceWidget&>(rEdit);
+        QWidget* pEditWidget = rQtEdit.getQWidget();
+        assert(pEditWidget);
+        QtInstanceWidget* pQtButton = dynamic_cast<QtInstanceWidget*>(pButton);
+        QWidget* pButtonWidget = pQtButton ? pQtButton->getQWidget() : nullptr;
+
+        for (QWidget* pVisibleWidget : { pEditWidget, pButtonWidget })
+        {
+            QWidget* pWidget = pVisibleWidget;
+            while (pWidget)
+            {
+                pWidget->setVisible(true);
+                pWidget = pWidget->parentWidget();
+            }
+        }
+
+        resize_to_request();
+    });
 }
 
-void QtInstanceDialog::undo_collapse() { assert(false && "Not implemented 
yet"); }
+void QtInstanceDialog::undo_collapse()
+{
+    SolarMutexGuard g;
+
+    GetQtInstance().RunInMainThread([&] {
+        for (QWidget* pWidget : m_aVisibleWidgetsBeforeCollapsing)
+            pWidget->show();
+
+        m_aVisibleWidgetsBeforeCollapsing.clear();
+
+        resize_to_request();
+    });
+}
 
 void QtInstanceDialog::SetInstallLOKNotifierHdl(const Link<void*, 
vcl::ILibreOfficeKitNotifier*>&)
 {

Reply via email to