[gtkmm] Dialog demo: Add a non-modal dialog
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] Dialog demo: Add a non-modal dialog
- Date: Mon, 22 Aug 2022 16:25:15 +0000 (UTC)
commit 14ef6f16b3300d04c5c177a3397e6f5ec82700f4
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Mon Aug 22 18:23:55 2022 +0200
Dialog demo: Add a non-modal dialog
Fixes #123
demos/gtk-demo/example_dialog.cc | 40 +++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
---
diff --git a/demos/gtk-demo/example_dialog.cc b/demos/gtk-demo/example_dialog.cc
index d1eee62c..ad026c4d 100644
--- a/demos/gtk-demo/example_dialog.cc
+++ b/demos/gtk-demo/example_dialog.cc
@@ -4,8 +4,6 @@
*/
#include <gtkmm.h>
-#include <gtk/gtk.h>
-#include <stdio.h>
class Dialog_Interactive;
@@ -19,14 +17,18 @@ protected:
//Signal handlers:
void on_button_message();
void on_button_interactive();
+ void on_button_non_modal();
void on_message_response(int response_id, Gtk::MessageDialog* dialog);
void on_interactive_response(int response_id, Dialog_Interactive* dialog);
+ void on_non_modal_response(int response_id, Gtk::MessageDialog* dialog);
//Member widgets:
Gtk::Frame m_Frame;
Gtk::Box m_VBox, m_VBox2;
Gtk::Box m_HBox, m_HBox2;
- Gtk::Button m_Button_Message, m_Button_Interactive;
+ Gtk::Button m_Button_Message;
+ Gtk::Button m_Button_Interactive;
+ Gtk::Button m_Button_NonModal;
Gtk::Grid m_Grid;
Gtk::Label m_Label1, m_Label2;
Gtk::Entry m_Entry1, m_Entry2;
@@ -66,6 +68,7 @@ Example_Dialog::Example_Dialog()
m_HBox2(Gtk::Orientation::HORIZONTAL, 8),
m_Button_Message("_Message Dialog", true),
m_Button_Interactive("_Interactive Dialog", true),
+ m_Button_NonModal("_Non-modal Dialog", true),
m_Label1("_Entry 1", true),
m_Label2("E_ntry 2", true)
{
@@ -79,20 +82,18 @@ Example_Dialog::Example_Dialog()
m_VBox.set_margin(8);
m_Frame.set_child(m_VBox);
-
/* Standard message dialog */
m_VBox.append(m_HBox);
m_Button_Message.signal_clicked().connect(sigc::mem_fun(*this, &Example_Dialog::on_button_message));
m_HBox.append(m_Button_Message);
m_VBox.append(*Gtk::make_managed<Gtk::Separator>(Gtk::Orientation::HORIZONTAL));
-
/* Interactive dialog*/
m_VBox.append(m_HBox2);
m_Button_Interactive.signal_clicked().connect(sigc::mem_fun(*this,
&Example_Dialog::on_button_interactive));
m_HBox2.append(m_VBox2);
m_VBox2.append(m_Button_Interactive);
-
+ m_VBox.append(*Gtk::make_managed<Gtk::Separator>(Gtk::Orientation::HORIZONTAL));
m_Grid.set_row_spacing(4);
m_Grid.set_column_spacing(4);
@@ -105,6 +106,12 @@ Example_Dialog::Example_Dialog()
m_Grid.attach(m_Label2, 0, 1);
m_Grid.attach(m_Entry2, 1, 1);
m_Label2.set_mnemonic_widget(m_Entry2);
+
+ // Non-modal message dialog,
+ // i.e. a dialog that does not freeze the rest of the application.
+ m_VBox.append(m_Button_NonModal);
+ m_Button_NonModal.signal_clicked().connect(sigc::mem_fun(
+ *this, &Example_Dialog::on_button_non_modal));
}
Example_Dialog::~Example_Dialog()
@@ -132,6 +139,17 @@ void Example_Dialog::on_button_interactive()
pDialog->show();
}
+void Example_Dialog::on_button_non_modal()
+{
+ const Glib::ustring strMessage = "Non-modal message box.";
+ auto dialog = Gtk::make_managed<Gtk::MessageDialog>(*this, strMessage,
+ /* use_markup= */ false, Gtk::MessageType::INFO, Gtk::ButtonsType::OK, /* modal= */ false);
+ dialog->set_destroy_with_parent(true);
+ dialog->signal_response().connect(sigc::bind(
+ sigc::mem_fun(*this, &Example_Dialog::on_non_modal_response), dialog));
+ dialog->show();
+}
+
void Example_Dialog::on_message_response(int /* response_id */, Gtk::MessageDialog* dialog)
{
m_count++;
@@ -148,6 +166,15 @@ void Example_Dialog::on_interactive_response(int response_id, Dialog_Interactive
delete dialog;
}
+void Example_Dialog::on_non_modal_response(int /* response_id */, Gtk::MessageDialog* dialog)
+{
+ // Delete the non-modal dialog.
+ // If the Example_Dialog is deleted without first responding to the non-modal
+ // dialog, the non-modal dialog is deleted with Example_Dialog, because it's
+ // a managed widget which is destroyed with its parent.
+ delete dialog;
+}
+
Dialog_Interactive::Dialog_Interactive(Gtk::Window& parent, const Glib::ustring& entry1, const
Glib::ustring& entry2)
: Gtk::Dialog("Interactive Dialog", parent, true),
m_HBox(Gtk::Orientation::HORIZONTAL, 8),
@@ -191,4 +218,3 @@ Glib::ustring Dialog_Interactive::get_entry2() const
Dialog_Interactive::~Dialog_Interactive()
{
}
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]