2015-06-20 01:59:15 +00:00
|
|
|
/* Dialogs and Message Boxes
|
2001-02-20 01:37:27 +00:00
|
|
|
*
|
2001-03-16 19:32:20 +00:00
|
|
|
* Dialog widgets are used to pop up a transient window for user feedback.
|
2001-02-20 01:37:27 +00:00
|
|
|
*/
|
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
#include <glib/gi18n.h>
|
2001-02-20 01:37:27 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
static GtkWidget *entry1 = NULL;
|
|
|
|
static GtkWidget *entry2 = NULL;
|
2001-02-20 01:37:27 +00:00
|
|
|
|
|
|
|
static void
|
2001-05-18 16:28:30 +00:00
|
|
|
message_dialog_clicked (GtkButton *button,
|
2011-09-02 03:55:47 +00:00
|
|
|
gpointer user_data)
|
2001-02-20 01:37:27 +00:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
static gint i = 1;
|
|
|
|
|
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
2011-09-02 03:55:47 +00:00
|
|
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_INFO,
|
2014-01-12 02:59:45 +00:00
|
|
|
GTK_BUTTONS_OK_CANCEL,
|
2011-09-02 03:55:47 +00:00
|
|
|
"This message box has been popped up the following\n"
|
|
|
|
"number of times:");
|
2004-10-26 05:06:32 +00:00
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
|
|
|
"%d", i);
|
2001-02-20 01:37:27 +00:00
|
|
|
gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-05-18 16:28:30 +00:00
|
|
|
interactive_dialog_clicked (GtkButton *button,
|
2011-09-02 03:55:47 +00:00
|
|
|
gpointer user_data)
|
2001-02-20 01:37:27 +00:00
|
|
|
{
|
2010-06-03 07:36:39 +00:00
|
|
|
GtkWidget *content_area;
|
2001-02-20 01:37:27 +00:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *hbox;
|
2013-06-21 17:46:54 +00:00
|
|
|
GtkWidget *image;
|
2001-02-20 01:37:27 +00:00
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *local_entry1;
|
|
|
|
GtkWidget *local_entry2;
|
2001-03-22 06:45:57 +00:00
|
|
|
GtkWidget *label;
|
2001-02-20 01:37:27 +00:00
|
|
|
gint response;
|
|
|
|
|
|
|
|
dialog = gtk_dialog_new_with_buttons ("Interactive Dialog",
|
2011-09-02 03:55:47 +00:00
|
|
|
GTK_WINDOW (window),
|
|
|
|
GTK_DIALOG_MODAL| GTK_DIALOG_DESTROY_WITH_PARENT,
|
2013-06-21 17:46:54 +00:00
|
|
|
_("_OK"),
|
2011-09-02 03:55:47 +00:00
|
|
|
GTK_RESPONSE_OK,
|
2013-06-21 17:46:54 +00:00
|
|
|
"_Cancel",
|
2001-09-27 00:11:23 +00:00
|
|
|
GTK_RESPONSE_CANCEL,
|
2011-09-02 03:55:47 +00:00
|
|
|
NULL);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2010-06-03 07:36:39 +00:00
|
|
|
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (content_area), hbox);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_icon_name ("dialog-question");
|
2017-11-15 02:14:47 +00:00
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), image);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2011-08-31 15:10:19 +00:00
|
|
|
table = gtk_grid_new ();
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (table), 4);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (table), 4);
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), table);
|
2001-03-22 06:45:57 +00:00
|
|
|
label = gtk_label_new_with_mnemonic ("_Entry 1");
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
|
2001-02-20 01:37:27 +00:00
|
|
|
local_entry1 = gtk_entry_new ();
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (local_entry1), gtk_editable_get_text (GTK_EDITABLE (entry1)));
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), local_entry1, 1, 0, 1, 1);
|
2001-03-22 06:45:57 +00:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), local_entry1);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic ("E_ntry 2");
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
|
2001-03-22 06:45:57 +00:00
|
|
|
|
2001-02-20 01:37:27 +00:00
|
|
|
local_entry2 = gtk_entry_new ();
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (local_entry2), gtk_editable_get_text (GTK_EDITABLE (entry2)));
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), local_entry2, 1, 1, 1, 1);
|
2001-03-22 06:45:57 +00:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), local_entry2);
|
2011-08-31 15:10:19 +00:00
|
|
|
|
2001-02-20 01:37:27 +00:00
|
|
|
response = gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
|
|
|
|
if (response == GTK_RESPONSE_OK)
|
|
|
|
{
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (entry1), gtk_editable_get_text (GTK_EDITABLE (local_entry1)));
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (entry2), gtk_editable_get_text (GTK_EDITABLE (local_entry2)));
|
2001-02-20 01:37:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
2003-11-08 22:08:05 +00:00
|
|
|
do_dialog (GtkWidget *do_widget)
|
2001-02-20 01:37:27 +00:00
|
|
|
{
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *vbox2;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *table;
|
2001-03-22 06:45:57 +00:00
|
|
|
GtkWidget *label;
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2001-02-20 01:37:27 +00:00
|
|
|
if (!window)
|
|
|
|
{
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2015-06-20 01:59:15 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Dialogs and Message Boxes");
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2015-06-28 13:23:28 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &window);
|
|
|
|
|
2001-02-20 01:37:27 +00:00
|
|
|
frame = gtk_frame_new ("Dialogs");
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (frame, 8);
|
|
|
|
gtk_widget_set_margin_end (frame, 8);
|
|
|
|
gtk_widget_set_margin_top (frame, 8);
|
|
|
|
gtk_widget_set_margin_bottom (frame, 8);
|
2001-02-20 01:37:27 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), frame);
|
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (vbox, 8);
|
|
|
|
gtk_widget_set_margin_end (vbox, 8);
|
|
|
|
gtk_widget_set_margin_top (vbox, 8);
|
|
|
|
gtk_widget_set_margin_bottom (vbox, 8);
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), vbox);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
|
|
|
/* Standard message dialog */
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
2001-03-22 06:45:57 +00:00
|
|
|
button = gtk_button_new_with_mnemonic ("_Message Dialog");
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
2011-09-02 03:55:47 +00:00
|
|
|
G_CALLBACK (message_dialog_clicked), NULL);
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), button);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
|
2001-02-20 01:37:27 +00:00
|
|
|
|
|
|
|
/* Interactive dialog*/
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2001-03-22 06:45:57 +00:00
|
|
|
button = gtk_button_new_with_mnemonic ("_Interactive Dialog");
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
2011-09-02 03:55:47 +00:00
|
|
|
G_CALLBACK (interactive_dialog_clicked), NULL);
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), vbox2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox2), button);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2011-08-31 15:10:19 +00:00
|
|
|
table = gtk_grid_new ();
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (table), 4);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (table), 4);
|
2018-12-29 08:49:24 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), table);
|
2001-03-22 06:45:57 +00:00
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic ("_Entry 1");
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
|
|
|
entry1 = gtk_entry_new ();
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), entry1, 1, 0, 1, 1);
|
2001-03-22 06:45:57 +00:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry1);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic ("E_ntry 2");
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
|
2001-03-22 06:45:57 +00:00
|
|
|
|
2001-02-20 01:37:27 +00:00
|
|
|
entry2 = gtk_entry_new ();
|
2011-08-31 15:10:19 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (table), entry2, 1, 1, 1, 1);
|
2001-02-20 01:37:27 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (window))
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2001-02-20 01:37:27 +00:00
|
|
|
else
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_widget_destroy (window);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|