1 | #include <gtk/gtk.h> |
2 | |
3 | typedef enum { |
4 | RESPONSE_UNREVEAL, |
5 | } Response; |
6 | |
7 | static void |
8 | on_info_bar_response (GtkInfoBar *info_bar, |
9 | int response_id, |
10 | void *user_data) |
11 | { |
12 | switch (response_id) |
13 | { |
14 | case GTK_RESPONSE_CLOSE: |
15 | gtk_widget_hide (GTK_WIDGET (info_bar)); |
16 | break; |
17 | |
18 | case RESPONSE_UNREVEAL: |
19 | gtk_info_bar_set_revealed (info_bar, FALSE); |
20 | break; |
21 | |
22 | default: |
23 | g_assert_not_reached (); |
24 | } |
25 | } |
26 | |
27 | static void |
28 | on_activate (GApplication *application, |
29 | void *user_data) |
30 | { |
31 | GtkWidget *box; |
32 | GtkWidget *info_bar; |
33 | GtkWidget *widget; |
34 | |
35 | box = gtk_box_new (orientation: GTK_ORIENTATION_VERTICAL, spacing: 10); |
36 | |
37 | info_bar = gtk_info_bar_new (); |
38 | gtk_info_bar_add_child (GTK_INFO_BAR (info_bar), |
39 | widget: gtk_label_new (str: "Hello!\nI am a GtkInfoBar" )); |
40 | |
41 | widget = gtk_toggle_button_new_with_label (label: "Toggle :visible" ); |
42 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); |
43 | g_object_bind_property (source: widget, source_property: "active" , |
44 | target: info_bar, target_property: "visible" , |
45 | flags: G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); |
46 | gtk_box_append (GTK_BOX (box), child: widget); |
47 | |
48 | widget = gtk_toggle_button_new_with_label (label: "Toggle :revealed" ); |
49 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); |
50 | g_object_bind_property (source: widget, source_property: "active" , |
51 | target: info_bar, target_property: "revealed" , |
52 | flags: G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); |
53 | gtk_box_append (GTK_BOX (box), child: widget); |
54 | |
55 | widget = gtk_toggle_button_new_with_label (label: "Toggle :show-close-button" ); |
56 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); |
57 | g_object_bind_property (source: widget, source_property: "active" , |
58 | target: info_bar, target_property: "show-close-button" , |
59 | flags: G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); |
60 | gtk_box_append (GTK_BOX (box), child: widget); |
61 | |
62 | widget = gtk_combo_box_text_new (); |
63 | gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), |
64 | NULL, text: "GTK_MESSAGE_INFO" ); |
65 | gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), |
66 | NULL, text: "GTK_MESSAGE_WARNING" ); |
67 | gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), |
68 | NULL, text: "GTK_MESSAGE_QUESTION" ); |
69 | gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), |
70 | NULL, text: "GTK_MESSAGE_ERROR" ); |
71 | gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), |
72 | NULL, text: "GTK_MESSAGE_OTHER" ); |
73 | gtk_combo_box_set_active (GTK_COMBO_BOX (widget), index_: 0); |
74 | g_object_bind_property (source: widget, source_property: "active" , |
75 | target: info_bar, target_property: "message-type" , |
76 | flags: G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); |
77 | gtk_box_append (GTK_BOX (box), child: widget); |
78 | |
79 | gtk_box_append (GTK_BOX (box), child: info_bar); |
80 | |
81 | widget = gtk_button_new_with_label (label: "Un-reveal" ); |
82 | gtk_info_bar_add_action_widget (GTK_INFO_BAR (info_bar), child: widget, |
83 | response_id: RESPONSE_UNREVEAL); |
84 | |
85 | g_signal_connect (info_bar, "response" , |
86 | G_CALLBACK (on_info_bar_response), widget); |
87 | |
88 | widget = gtk_window_new (); |
89 | gtk_window_set_child (GTK_WINDOW (widget), child: box); |
90 | gtk_widget_show (widget); |
91 | gtk_application_add_window (GTK_APPLICATION (application), |
92 | GTK_WINDOW (widget)); |
93 | } |
94 | |
95 | int |
96 | main (int argc, |
97 | char *argv[]) |
98 | { |
99 | GtkApplication *application; |
100 | int result; |
101 | |
102 | application = gtk_application_new (application_id: "org.gtk.test.infobar" , |
103 | flags: G_APPLICATION_FLAGS_NONE); |
104 | g_signal_connect (application, "activate" , G_CALLBACK (on_activate), NULL); |
105 | |
106 | result = g_application_run (G_APPLICATION (application), argc, argv); |
107 | g_object_unref (object: application); |
108 | return result; |
109 | } |
110 | |