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);
|
2020-04-30 12:30:51 +00:00
|
|
|
g_signal_connect (dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
|
|
|
|
gtk_widget_show (dialog);
|
2001-02-20 01:37:27 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2020-04-30 12:30:51 +00:00
|
|
|
typedef struct {
|
|
|
|
GtkWidget *local_entry1;
|
|
|
|
GtkWidget *local_entry2;
|
|
|
|
GtkWidget *global_entry1;
|
|
|
|
GtkWidget *global_entry2;
|
|
|
|
} ResponseData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_dialog_response (GtkDialog *dialog,
|
|
|
|
int response,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ResponseData *data = user_data;
|
|
|
|
|
|
|
|
if (response == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (data->global_entry1),
|
|
|
|
gtk_editable_get_text (GTK_EDITABLE (data->local_entry1)));
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (data->global_entry2),
|
|
|
|
gtk_editable_get_text (GTK_EDITABLE (data->local_entry2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
|
|
|
}
|
|
|
|
|
2001-02-20 01:37:27 +00:00
|
|
|
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;
|
2020-04-30 12:30:51 +00:00
|
|
|
ResponseData *data;
|
2001-02-20 01:37:27 +00:00
|
|
|
|
|
|
|
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);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (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);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (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);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (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
|
|
|
|
2020-04-30 12:30:51 +00:00
|
|
|
data = g_new (ResponseData, 1);
|
|
|
|
data->local_entry1 = local_entry1;
|
|
|
|
data->local_entry2 = local_entry2;
|
|
|
|
data->global_entry1 = entry1;
|
|
|
|
data->global_entry2 = entry2;
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2020-04-30 12:30:51 +00:00
|
|
|
g_signal_connect_data (dialog, "response",
|
|
|
|
G_CALLBACK (on_dialog_response),
|
|
|
|
data, (GClosureNotify) g_free,
|
|
|
|
0);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2020-04-30 12:30:51 +00:00
|
|
|
gtk_widget_show (dialog);
|
2001-02-20 01:37:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2015-06-28 13:23:28 +00:00
|
|
|
|
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);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), frame);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
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);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (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);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (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);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (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);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), vbox2);
|
|
|
|
gtk_box_append (GTK_BOX (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);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (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
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2001-02-20 01:37:27 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|