2020-06-17 21:46:40 +00:00
|
|
|
/* Dialogs
|
2001-02-20 01:37:27 +00:00
|
|
|
*
|
2020-06-17 21:46:40 +00:00
|
|
|
* Dialogs are used to pop up transient windows for information
|
|
|
|
* and 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;
|
2020-07-24 13:54:49 +00:00
|
|
|
static int i = 1;
|
2001-02-20 01:37:27 +00:00
|
|
|
|
|
|
|
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,
|
2020-06-17 21:46:40 +00:00
|
|
|
"Test message");
|
2004-10-26 05:06:32 +00:00
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
2020-06-17 21:46:40 +00:00
|
|
|
ngettext ("Has been shown once", "Has been shown %d times", i), 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 *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),
|
2020-06-17 21:46:40 +00:00
|
|
|
GTK_DIALOG_MODAL| GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_USE_HEADER_BAR,
|
|
|
|
_("_OK"), GTK_RESPONSE_OK,
|
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
2011-09-02 03:55:47 +00:00
|
|
|
NULL);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2020-06-17 21:46:40 +00:00
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2020-06-17 21:46:40 +00:00
|
|
|
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
2001-02-20 01:37:27 +00:00
|
|
|
|
2011-08-31 15:10:19 +00:00
|
|
|
table = gtk_grid_new ();
|
2020-06-17 21:46:40 +00:00
|
|
|
gtk_widget_set_hexpand (table, TRUE);
|
|
|
|
gtk_widget_set_vexpand (table, TRUE);
|
|
|
|
gtk_widget_set_halign (table, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (table, GTK_ALIGN_CENTER);
|
|
|
|
gtk_box_append (GTK_BOX (content_area), table);
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (table), 6);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (table), 6);
|
|
|
|
|
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 *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));
|
2020-06-17 21:46:40 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Dialogs");
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
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
|
|
|
|
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-06-17 21:46:40 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), 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;
|
|
|
|
}
|