[Libreoffice-commits] core.git: include/vcl vcl/source vcl/unx

Caolán McNamara caolanm at redhat.com
Wed Mar 21 20:43:58 UTC 2018


 include/vcl/dialog.hxx        |    1 +
 include/vcl/weld.hxx          |    3 +++
 vcl/source/app/salvtables.cxx |    8 ++++++++
 vcl/source/window/dialog.cxx  |   36 ++++++++++++++++++++++++++++++++++++
 vcl/unx/gtk3/gtk3gtkinst.cxx  |   10 ++++++++++
 5 files changed, 58 insertions(+)

New commits:
commit 678980ceaebd47916a4aafb448a3bfcfd5d3ca25
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Mar 21 14:33:59 2018 +0000

    add get_widget_for_response support
    
    Change-Id: I49abb5e6621dbfe2fc92ef9c2a47568c62c372c2
    Reviewed-on: https://gerrit.libreoffice.org/51709
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/vcl/dialog.hxx b/include/vcl/dialog.hxx
index 0b98901e32bb..6104def06236 100644
--- a/include/vcl/dialog.hxx
+++ b/include/vcl/dialog.hxx
@@ -178,6 +178,7 @@ public:
 
     void            add_button(PushButton* pButton, int nResponse, bool bTransferOwnership);
     void            set_default_response(int nResponse);
+    vcl::Window*    get_widget_for_response(int nResponse);
 };
 
 class VCL_DLLPUBLIC ModelessDialog : public Dialog
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 58b0ddd80284..88c53b7e2336 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -124,6 +124,8 @@ public:
     ~WaitObject() { m_pWindow->set_busy_cursor(false); }
 };
 
+class Button;
+
 class VCL_DLLPUBLIC Dialog : virtual public Window
 {
 private:
@@ -138,6 +140,7 @@ public:
     virtual void add_button(const OUString& rText, int response, const OString& rHelpId = OString())
         = 0;
     virtual void set_default_response(int response) = 0;
+    virtual Button* get_widget_for_response(int response) = 0;
 };
 
 class VCL_DLLPUBLIC MessageDialog : virtual public Dialog
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 52ff2baf67a7..27a0c288c593 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -478,6 +478,8 @@ public:
         m_xDialog->add_button(xButton, nResponse, true);
     }
 
+    virtual weld::Button* get_widget_for_response(int nResponse) override;
+
     virtual void set_default_response(int nResponse) override
     {
         m_xDialog->set_default_response(nResponse);
@@ -665,6 +667,12 @@ IMPL_LINK(SalInstanceButton, ClickHdl, ::Button*, pButton, void)
     signal_clicked();
 }
 
+weld::Button* SalInstanceDialog::get_widget_for_response(int nResponse)
+{
+    PushButton* pButton = dynamic_cast<PushButton*>(m_xDialog->get_widget_for_response(nResponse));
+    return pButton ? new SalInstanceButton(pButton, false) : nullptr;
+}
+
 class SalInstanceRadioButton : public SalInstanceButton, public virtual weld::RadioButton
 {
 private:
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index 36d77298d767..a5450b582870 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -1355,6 +1355,42 @@ void Dialog::add_button(PushButton* pButton, int response, bool bTransferOwnersh
     }
 }
 
+vcl::Window* Dialog::get_widget_for_response(int response)
+{
+    //copy explicit responses
+    std::map<VclPtr<vcl::Window>, short> aResponses(mpDialogImpl->maResponses);
+
+    //add implicit responses
+    for (vcl::Window* pChild = mpActionArea->GetWindow(GetWindowType::FirstChild); pChild;
+         pChild = pChild->GetWindow(GetWindowType::Next))
+    {
+        if (aResponses.find(pChild) != aResponses.end())
+            continue;
+        switch (pChild->GetType())
+        {
+            case WindowType::OKBUTTON:
+                aResponses[pChild] = RET_OK;
+                break;
+            case WindowType::CANCELBUTTON:
+                aResponses[pChild] = RET_CANCEL;
+                break;
+            case WindowType::HELPBUTTON:
+                aResponses[pChild] = RET_HELP;
+                break;
+            default:
+                break;
+        }
+    }
+
+    for (auto& a : aResponses)
+    {
+        if (a.second == response)
+           return a.first;
+    }
+
+    return nullptr;
+}
+
 void Dialog::set_default_response(int response)
 {
     //copy explicit responses
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 49581bb180e8..1c635bfec584 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -1647,6 +1647,8 @@ public:
         gtk_dialog_set_default_response(m_pDialog, VclToGtk(nResponse));
     }
 
+    virtual weld::Button* get_widget_for_response(int nResponse) override;
+
     virtual ~GtkInstanceDialog() override
     {
         g_signal_handler_disconnect(m_pDialog, m_nCloseSignalId);
@@ -1857,6 +1859,14 @@ public:
     }
 };
 
+weld::Button* GtkInstanceDialog::get_widget_for_response(int nResponse)
+{
+    GtkButton* pButton = GTK_BUTTON(gtk_dialog_get_widget_for_response(m_pDialog, nResponse));
+    if (!pButton)
+        return nullptr;
+    return new GtkInstanceButton(pButton, false);
+}
+
 class GtkInstanceToggleButton : public GtkInstanceButton, public virtual weld::ToggleButton
 {
 private:


More information about the Libreoffice-commits mailing list