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);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (content_area), hbox);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
image = gtk_image_new_from_icon_name ("dialog-question", GTK_ICON_SIZE_DIALOG);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (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);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (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 ();
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (local_entry1), gtk_entry_get_text (GTK_ENTRY (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 ();
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (local_entry2), gtk_entry_get_text (GTK_ENTRY (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)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry1), gtk_entry_get_text (GTK_ENTRY (local_entry1)));
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry2), gtk_entry_get_text (GTK_ENTRY (local_entry2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2003-11-08 22:08:05 +00:00
|
|
|
gtk_window_set_screen (GTK_WINDOW (window),
|
2011-09-02 03:55:47 +00:00
|
|
|
gtk_widget_get_screen (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");
|
2016-10-26 19:11:18 +00:00
|
|
|
g_object_set (frame, "margin", 8, NULL);
|
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);
|
2016-10-26 19:11:18 +00:00
|
|
|
g_object_set (vbox, "margin", 8, NULL);
|
2001-02-20 01:37:27 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
|
|
|
|
/* Standard message dialog */
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (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);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), button);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (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);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (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);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), vbox2);
|
|
|
|
gtk_box_pack_start (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);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (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
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_widget_destroy (window);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|