2018-03-12 15:29:21 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2022-10-08 00:59:10 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2018-03-12 18:57:06 +00:00
|
|
|
typedef enum {
|
|
|
|
RESPONSE_UNREVEAL,
|
|
|
|
} Response;
|
2018-03-12 15:29:21 +00:00
|
|
|
|
|
|
|
static void
|
2018-03-12 18:57:06 +00:00
|
|
|
on_info_bar_response (GtkInfoBar *info_bar,
|
|
|
|
int response_id,
|
|
|
|
void *user_data)
|
2018-03-12 15:29:21 +00:00
|
|
|
{
|
2018-03-12 18:57:06 +00:00
|
|
|
switch (response_id)
|
|
|
|
{
|
|
|
|
case GTK_RESPONSE_CLOSE:
|
|
|
|
gtk_widget_hide (GTK_WIDGET (info_bar));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESPONSE_UNREVEAL:
|
|
|
|
gtk_info_bar_set_revealed (info_bar, FALSE);
|
|
|
|
break;
|
2018-03-12 15:29:21 +00:00
|
|
|
|
2018-03-12 18:57:06 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2018-03-12 15:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_activate (GApplication *application,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *info_bar;
|
2018-03-12 18:57:06 +00:00
|
|
|
GtkWidget *widget;
|
2018-03-12 15:29:21 +00:00
|
|
|
|
2018-03-12 18:57:06 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
|
2018-03-12 15:29:21 +00:00
|
|
|
|
|
|
|
info_bar = gtk_info_bar_new ();
|
2020-05-07 16:52:49 +00:00
|
|
|
gtk_info_bar_add_child (GTK_INFO_BAR (info_bar),
|
|
|
|
gtk_label_new ("Hello!\nI am a GtkInfoBar"));
|
2018-03-12 15:29:21 +00:00
|
|
|
|
2018-03-12 18:57:06 +00:00
|
|
|
widget = gtk_toggle_button_new_with_label ("Toggle :visible");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
|
|
|
|
g_object_bind_property (widget, "active",
|
|
|
|
info_bar, "visible",
|
|
|
|
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), widget);
|
2018-03-12 15:29:21 +00:00
|
|
|
|
2018-03-12 18:57:06 +00:00
|
|
|
widget = gtk_toggle_button_new_with_label ("Toggle :revealed");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
|
|
|
|
g_object_bind_property (widget, "active",
|
|
|
|
info_bar, "revealed",
|
|
|
|
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), widget);
|
2018-03-12 18:57:06 +00:00
|
|
|
|
|
|
|
widget = gtk_toggle_button_new_with_label ("Toggle :show-close-button");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
|
|
|
|
g_object_bind_property (widget, "active",
|
|
|
|
info_bar, "show-close-button",
|
|
|
|
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), widget);
|
2018-03-12 18:57:06 +00:00
|
|
|
|
|
|
|
widget = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget),
|
|
|
|
NULL, "GTK_MESSAGE_INFO");
|
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget),
|
|
|
|
NULL, "GTK_MESSAGE_WARNING");
|
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget),
|
|
|
|
NULL, "GTK_MESSAGE_QUESTION");
|
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget),
|
|
|
|
NULL, "GTK_MESSAGE_ERROR");
|
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget),
|
|
|
|
NULL, "GTK_MESSAGE_OTHER");
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
|
|
|
|
g_object_bind_property (widget, "active",
|
|
|
|
info_bar, "message-type",
|
|
|
|
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), widget);
|
2018-03-12 15:29:21 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), info_bar);
|
2018-03-12 15:29:21 +00:00
|
|
|
|
2018-03-12 18:57:06 +00:00
|
|
|
widget = gtk_button_new_with_label ("Un-reveal");
|
|
|
|
gtk_info_bar_add_action_widget (GTK_INFO_BAR (info_bar), widget,
|
|
|
|
RESPONSE_UNREVEAL);
|
|
|
|
|
|
|
|
g_signal_connect (info_bar, "response",
|
|
|
|
G_CALLBACK (on_info_bar_response), widget);
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
widget = gtk_window_new ();
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (widget), box);
|
2018-03-12 18:57:06 +00:00
|
|
|
gtk_widget_show (widget);
|
2018-03-12 15:29:21 +00:00
|
|
|
gtk_application_add_window (GTK_APPLICATION (application),
|
2018-03-12 18:57:06 +00:00
|
|
|
GTK_WINDOW (widget));
|
2018-03-12 15:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
|
|
|
{
|
|
|
|
GtkApplication *application;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
application = gtk_application_new ("org.gtk.test.infobar",
|
|
|
|
G_APPLICATION_FLAGS_NONE);
|
|
|
|
g_signal_connect (application, "activate", G_CALLBACK (on_activate), NULL);
|
|
|
|
|
|
|
|
result = g_application_run (G_APPLICATION (application), argc, argv);
|
|
|
|
g_object_unref (application);
|
|
|
|
return result;
|
|
|
|
}
|