Kaydet (Commit) 678980ce authored tarafından Caolán McNamara's avatar Caolán McNamara

add get_widget_for_response support

Change-Id: I49abb5e6621dbfe2fc92ef9c2a47568c62c372c2
Reviewed-on: https://gerrit.libreoffice.org/51709Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 625f341d
...@@ -178,6 +178,7 @@ public: ...@@ -178,6 +178,7 @@ public:
void add_button(PushButton* pButton, int nResponse, bool bTransferOwnership); void add_button(PushButton* pButton, int nResponse, bool bTransferOwnership);
void set_default_response(int nResponse); void set_default_response(int nResponse);
vcl::Window* get_widget_for_response(int nResponse);
}; };
class VCL_DLLPUBLIC ModelessDialog : public Dialog class VCL_DLLPUBLIC ModelessDialog : public Dialog
......
...@@ -124,6 +124,8 @@ public: ...@@ -124,6 +124,8 @@ public:
~WaitObject() { m_pWindow->set_busy_cursor(false); } ~WaitObject() { m_pWindow->set_busy_cursor(false); }
}; };
class Button;
class VCL_DLLPUBLIC Dialog : virtual public Window class VCL_DLLPUBLIC Dialog : virtual public Window
{ {
private: private:
...@@ -138,6 +140,7 @@ public: ...@@ -138,6 +140,7 @@ public:
virtual void add_button(const OUString& rText, int response, const OString& rHelpId = OString()) virtual void add_button(const OUString& rText, int response, const OString& rHelpId = OString())
= 0; = 0;
virtual void set_default_response(int response) = 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 class VCL_DLLPUBLIC MessageDialog : virtual public Dialog
......
...@@ -478,6 +478,8 @@ public: ...@@ -478,6 +478,8 @@ public:
m_xDialog->add_button(xButton, nResponse, true); 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 virtual void set_default_response(int nResponse) override
{ {
m_xDialog->set_default_response(nResponse); m_xDialog->set_default_response(nResponse);
...@@ -665,6 +667,12 @@ IMPL_LINK(SalInstanceButton, ClickHdl, ::Button*, pButton, void) ...@@ -665,6 +667,12 @@ IMPL_LINK(SalInstanceButton, ClickHdl, ::Button*, pButton, void)
signal_clicked(); 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 class SalInstanceRadioButton : public SalInstanceButton, public virtual weld::RadioButton
{ {
private: private:
......
...@@ -1355,6 +1355,42 @@ void Dialog::add_button(PushButton* pButton, int response, bool bTransferOwnersh ...@@ -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) void Dialog::set_default_response(int response)
{ {
//copy explicit responses //copy explicit responses
......
...@@ -1647,6 +1647,8 @@ public: ...@@ -1647,6 +1647,8 @@ public:
gtk_dialog_set_default_response(m_pDialog, VclToGtk(nResponse)); gtk_dialog_set_default_response(m_pDialog, VclToGtk(nResponse));
} }
virtual weld::Button* get_widget_for_response(int nResponse) override;
virtual ~GtkInstanceDialog() override virtual ~GtkInstanceDialog() override
{ {
g_signal_handler_disconnect(m_pDialog, m_nCloseSignalId); g_signal_handler_disconnect(m_pDialog, m_nCloseSignalId);
...@@ -1857,6 +1859,14 @@ public: ...@@ -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 class GtkInstanceToggleButton : public GtkInstanceButton, public virtual weld::ToggleButton
{ {
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment