2015-06-20 01:59:15 +00:00
|
|
|
/* Info Bars
|
2020-09-13 18:59:33 +00:00
|
|
|
* #Keywords: GtkInfoBar
|
2009-06-22 21:22:23 +00:00
|
|
|
*
|
|
|
|
* Info bar widgets are used to report important messages to the user.
|
|
|
|
*/
|
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
#include <glib/gi18n.h>
|
2009-06-22 21:22:23 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_bar_response (GtkInfoBar *info_bar,
|
2020-07-24 13:54:49 +00:00
|
|
|
int response_id,
|
2009-06-22 21:22:23 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2015-06-28 13:23:28 +00:00
|
|
|
GtkWidget *window;
|
2009-06-22 21:22:23 +00:00
|
|
|
|
2013-07-31 16:42:10 +00:00
|
|
|
if (response_id == GTK_RESPONSE_CLOSE)
|
|
|
|
{
|
2017-01-12 08:10:02 +00:00
|
|
|
gtk_info_bar_set_revealed (info_bar, FALSE);
|
2013-07-31 16:42:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
window = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (info_bar)));
|
2009-06-22 21:22:23 +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,
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
"You clicked a button on an info bar");
|
2009-06-22 21:22:23 +00:00
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
|
|
|
"Your response has id %d", response_id);
|
2012-02-27 11:07:08 +00:00
|
|
|
|
2020-05-09 14:26:22 +00:00
|
|
|
g_signal_connect_swapped (dialog, "response",
|
|
|
|
G_CALLBACK (gtk_window_destroy), dialog);
|
2012-02-27 11:07:08 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (dialog);
|
2009-06-22 21:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_infobar (GtkWidget *do_widget)
|
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
static GtkWidget *window = NULL;
|
2009-06-22 21:22:23 +00:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *bar;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *label;
|
2013-07-31 16:42:10 +00:00
|
|
|
GtkWidget *actions;
|
|
|
|
GtkWidget *button;
|
2009-06-22 21:22:23 +00:00
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
2013-07-31 16:42:10 +00:00
|
|
|
actions = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-04-26 03:33:33 +00:00
|
|
|
gtk_widget_add_css_class (actions, "linked");
|
2013-07-31 16:42:10 +00:00
|
|
|
|
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));
|
2009-06-22 21:22:23 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Info Bars");
|
2020-04-26 03:33:33 +00:00
|
|
|
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);
|
2009-06-22 21:22:23 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
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-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), vbox);
|
2009-06-22 21:22:23 +00:00
|
|
|
|
|
|
|
bar = gtk_info_bar_new ();
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), bar);
|
2009-06-22 21:22:23 +00:00
|
|
|
gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_INFO);
|
|
|
|
label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_INFO");
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
2015-06-28 14:21:45 +00:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
2020-05-13 09:04:49 +00:00
|
|
|
gtk_info_bar_add_child (GTK_INFO_BAR (bar), label);
|
2009-06-22 21:22:23 +00:00
|
|
|
|
2013-07-31 16:42:10 +00:00
|
|
|
button = gtk_toggle_button_new_with_label ("Message");
|
2017-01-12 08:10:02 +00:00
|
|
|
g_object_bind_property (bar, "revealed", button, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (actions), button);
|
2013-07-31 16:42:10 +00:00
|
|
|
|
2009-06-22 21:22:23 +00:00
|
|
|
bar = gtk_info_bar_new ();
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), bar);
|
2009-06-22 21:22:23 +00:00
|
|
|
gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_WARNING);
|
|
|
|
label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_WARNING");
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
2015-06-28 14:21:45 +00:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
2020-05-13 09:04:49 +00:00
|
|
|
gtk_info_bar_add_child (GTK_INFO_BAR (bar), label);
|
2009-06-22 21:22:23 +00:00
|
|
|
|
2013-07-31 16:42:10 +00:00
|
|
|
button = gtk_toggle_button_new_with_label ("Warning");
|
2017-01-12 08:10:02 +00:00
|
|
|
g_object_bind_property (bar, "revealed", button, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (actions), button);
|
2013-07-31 16:42:10 +00:00
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
bar = gtk_info_bar_new_with_buttons (_("_OK"), GTK_RESPONSE_OK, NULL);
|
2013-07-15 19:08:10 +00:00
|
|
|
gtk_info_bar_set_show_close_button (GTK_INFO_BAR (bar), TRUE);
|
2009-06-22 21:22:23 +00:00
|
|
|
g_signal_connect (bar, "response", G_CALLBACK (on_bar_response), window);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), bar);
|
2009-06-22 21:22:23 +00:00
|
|
|
gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_QUESTION);
|
2015-06-28 14:21:45 +00:00
|
|
|
label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_QUESTION");
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
2015-06-28 14:21:45 +00:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
2020-05-13 09:04:49 +00:00
|
|
|
gtk_info_bar_add_child (GTK_INFO_BAR (bar), label);
|
2020-01-10 00:01:59 +00:00
|
|
|
gtk_info_bar_set_default_response (GTK_INFO_BAR (bar), GTK_RESPONSE_OK);
|
2009-06-22 21:22:23 +00:00
|
|
|
|
2013-07-31 16:42:10 +00:00
|
|
|
button = gtk_toggle_button_new_with_label ("Question");
|
2017-01-12 08:10:02 +00:00
|
|
|
g_object_bind_property (bar, "revealed", button, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (actions), button);
|
2013-07-31 16:42:10 +00:00
|
|
|
|
2009-06-22 21:22:23 +00:00
|
|
|
bar = gtk_info_bar_new ();
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), bar);
|
2009-06-22 21:22:23 +00:00
|
|
|
gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_ERROR);
|
|
|
|
label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_ERROR");
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
2015-06-28 14:21:45 +00:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
2020-05-13 09:04:49 +00:00
|
|
|
gtk_info_bar_add_child (GTK_INFO_BAR (bar), label);
|
2009-06-22 21:22:23 +00:00
|
|
|
|
2013-07-31 16:42:10 +00:00
|
|
|
button = gtk_toggle_button_new_with_label ("Error");
|
2017-01-12 08:10:02 +00:00
|
|
|
g_object_bind_property (bar, "revealed", button, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (actions), button);
|
2013-07-31 16:42:10 +00:00
|
|
|
|
2009-06-22 21:22:23 +00:00
|
|
|
bar = gtk_info_bar_new ();
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), bar);
|
2009-06-22 21:22:23 +00:00
|
|
|
gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_OTHER);
|
|
|
|
label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_OTHER");
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
2015-06-28 14:21:45 +00:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
2020-05-13 09:04:49 +00:00
|
|
|
gtk_info_bar_add_child (GTK_INFO_BAR (bar), label);
|
2009-06-22 21:22:23 +00:00
|
|
|
|
2013-07-31 16:42:10 +00:00
|
|
|
button = gtk_toggle_button_new_with_label ("Other");
|
2017-01-12 08:10:02 +00:00
|
|
|
g_object_bind_property (bar, "revealed", button, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (actions), button);
|
2013-07-31 16:42:10 +00:00
|
|
|
|
2020-04-26 03:33:33 +00:00
|
|
|
frame = gtk_frame_new ("An example of different info bars");
|
2016-10-02 15:37:22 +00:00
|
|
|
gtk_widget_set_margin_top (frame, 8);
|
|
|
|
gtk_widget_set_margin_bottom (frame, 8);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2009-06-22 21:22:23 +00:00
|
|
|
|
2020-04-26 03:33:33 +00:00
|
|
|
gtk_widget_set_halign (actions, GTK_ALIGN_CENTER);
|
2009-06-22 21:22:23 +00:00
|
|
|
|
2020-04-26 03:33:33 +00:00
|
|
|
gtk_widget_set_margin_start (actions, 8);
|
|
|
|
gtk_widget_set_margin_end (actions, 8);
|
|
|
|
gtk_widget_set_margin_top (actions, 8);
|
|
|
|
gtk_widget_set_margin_bottom (actions, 8);
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), actions);
|
2009-06-22 21:22:23 +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);
|
2009-06-22 21:22:23 +00:00
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2009-06-22 21:22:23 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|