include/vcl/builderbase.hxx   |    1 +
 vcl/qt5/QtBuilder.cxx         |    7 ++++++-
 vcl/source/window/builder.cxx |   20 ++++++++++++++++++++
 vcl/source/window/layout.cxx  |   19 +------------------
 4 files changed, 28 insertions(+), 19 deletions(-)

New commits:
commit 91bdb8e30e855b916c1b7ef9e299e63b43d7b793
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Feb 15 20:56:58 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Feb 16 11:13:25 2025 +0100

    tdf#130857 qt weld: Add standard message dialog buttons defined in .ui
    
    When processing a .ui file in QtBuilder, also evaluate the
    GtkMessageDialog:buttons property [1] and add the corresponding
    buttons to the QMessageBox.
    
    This is needed e.g. for the dialog that can be triggered
    as follows, for which support will be declared in an upcoming commit:
    
    * start Math
    * "Format" -> "Font Size"
    * click the "Default" button in the dialog
    
    (Without this commit, the dialog would only have a
    single "OK" instead of a "Yes" and a "No" button.)
    
    [1] https://docs.gtk.org/gtk3/property.MessageDialog.buttons.html
    
    Change-Id: I69c9e736b5080a4a824ffeb5f364492402e406c8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181726
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index a0ee0c4c9ded..b3c4cb9e25ec 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -826,7 +826,12 @@ void QtBuilder::setMessageDialogProperties(QMessageBox& 
rMessageBox, stringmap&
 {
     for (auto const & [ rKey, rValue ] : rProps)
     {
-        if (rKey == u"text")
+        if (rKey == u"buttons")
+        {
+            const VclButtonsType eButtons = 
BuilderBase::mapGtkToVclButtonsType(rValue);
+            QtInstanceMessageDialog::addStandardButtons(rMessageBox, eButtons);
+        }
+        else if (rKey == u"text")
         {
             rMessageBox.setText(toQString(rValue));
         }
commit d0ccde777ce83a27ac46290254c3d1102f962f7c
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Feb 15 20:14:31 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Feb 16 11:13:17 2025 +0100

    vcl: Switch SAL_WARN about button types to assert
    
    The
    
        git grep '"buttons"'
    
    output suggests that there's no case of any unknown value being
    used. Switch the existing SAL_WARN to an assert to notice more
    easily if that ever changes.
    
    Change-Id: I015de3da46056bdb5cbbe6dd8d88c39c128fad72
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181725
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index f7c6915e5f08..6163eafc3bb7 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -3581,7 +3581,7 @@ VclButtonsType 
BuilderBase::mapGtkToVclButtonsType(std::u16string_view sGtkButto
     else if (sGtkButtons == u"ok-cancel")
         return VclButtonsType::OkCancel;
 
-    SAL_WARN("vcl.layout", "unknown buttons type mode" << 
OUString(sGtkButtons));
+    assert(false && "unknown buttons type mode");
     return VclButtonsType::NONE;
 }
 
commit 07fe29fb7a601e899ff92298af799c216588736a
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Feb 15 20:10:38 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Feb 16 11:13:10 2025 +0100

    tdf#130857 vcl: Extract helper to map GTK to VCL buttons type
    
    Extract the existing logic to map the various possible values
    for the GtkMessageDialog:buttons property [1] to the VCL
    equivalent from MessageDialog::set_property to a new static helper
    method BuilderBase::mapGtkToVclButtonsType, for reuse in QtBuilder
    in an upcoming commit.
    
    [1] https://docs.gtk.org/gtk3/property.MessageDialog.buttons.html
    
    Change-Id: I7eee72cde7e162733d551dc4c19936c7b837baa5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181724
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/builderbase.hxx b/include/vcl/builderbase.hxx
index 7e892b387aac..50f416395c50 100644
--- a/include/vcl/builderbase.hxx
+++ b/include/vcl/builderbase.hxx
@@ -48,6 +48,7 @@ public:
     static OUString extractActionName(stringmap& rMap);
     static sal_Int32 extractActive(stringmap& rMap);
     static bool extractResizable(stringmap& rMap);
+    static VclButtonsType mapGtkToVclButtonsType(std::u16string_view 
sGtkButtons);
 
 protected:
     BuilderBase(std::u16string_view sUIDir, const OUString& rUIFile, bool 
bLegacy);
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 41f95fe286ca..f7c6915e5f08 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -3565,6 +3565,26 @@ void 
BuilderBase::collectAccelerator(xmlreader::XmlReader& reader, accelmap& rMa
     }
 }
 
+
+VclButtonsType BuilderBase::mapGtkToVclButtonsType(std::u16string_view 
sGtkButtons)
+{
+    if (sGtkButtons == u"none")
+        return VclButtonsType::NONE;
+    if (sGtkButtons == u"ok")
+        return VclButtonsType::Ok;
+    if (sGtkButtons == u"cancel")
+        return VclButtonsType::Cancel;
+    if (sGtkButtons == u"close")
+        return VclButtonsType::Close;
+    else if (sGtkButtons == u"yes-no")
+        return VclButtonsType::YesNo;
+    else if (sGtkButtons == u"ok-cancel")
+        return VclButtonsType::OkCancel;
+
+    SAL_WARN("vcl.layout", "unknown buttons type mode" << 
OUString(sGtkButtons));
+    return VclButtonsType::NONE;
+}
+
 bool BuilderBase::isToolbarItemClass(std::u16string_view sClass)
 {
     return sClass == u"GtkToolButton" || sClass == u"GtkMenuToolButton"
diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx
index 9d0dc28b4f91..9fce7dc8f2ea 100644
--- a/vcl/source/window/layout.cxx
+++ b/vcl/source/window/layout.cxx
@@ -2649,24 +2649,7 @@ bool MessageDialog::set_property(const OUString &rKey, 
const OUString &rValue)
     }
     else if (rKey == "buttons")
     {
-        VclButtonsType eMode = VclButtonsType::NONE;
-        if (rValue == "none")
-            eMode = VclButtonsType::NONE;
-        else if (rValue == "ok")
-            eMode = VclButtonsType::Ok;
-        else if (rValue == "cancel")
-            eMode = VclButtonsType::Cancel;
-        else if (rValue == "close")
-            eMode = VclButtonsType::Close;
-        else if (rValue == "yes-no")
-            eMode = VclButtonsType::YesNo;
-        else if (rValue == "ok-cancel")
-            eMode = VclButtonsType::OkCancel;
-        else
-        {
-            SAL_WARN("vcl.layout", "unknown buttons type mode" << rValue);
-        }
-        m_eButtonsType = eMode;
+        m_eButtonsType = BuilderBase::mapGtkToVclButtonsType(rValue);
     }
     else
         return Dialog::set_property(rKey, rValue);

Reply via email to