diff options
author | Daniel Boles <dboles@src.gnome.org> | 2018-03-12 15:29:21 +0000 |
---|---|---|
committer | Daniel Boles <dboles@src.gnome.org> | 2018-03-12 15:30:55 +0000 |
commit | 6bb1f0dbf36672eaae7173a58cae31a6e780d15a (patch) | |
tree | 046f86b4ad5d6327e38ed9deecc609369b8d3c55 /tests | |
parent | 362ef4449c8ef52dc135b92727b3c71f5823119c (diff) | |
download | gtk+-6bb1f0dbf36672eaae7173a58cae31a6e780d15a.tar.gz |
testinfobar: Add simple test of :visible/:revealed
This exists merely to prove that, having added :revealed, show() and
hide() now work reliably, as does set_revealed() for the animated case.
https://bugzilla.gnome.org/show_bug.cgi?id=710888
Diffstat (limited to 'tests')
-rw-r--r-- | tests/meson.build | 1 | ||||
-rw-r--r-- | tests/testinfobar.c | 78 |
2 files changed, 79 insertions, 0 deletions
diff --git a/tests/meson.build b/tests/meson.build index 3bdf1f6e62..a3955d430d 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -55,6 +55,7 @@ gtk_tests = [ ['testiconview'], ['testiconview-keynav'], ['testicontheme'], + ['testinfobar'], ['testimage'], ['testinput'], ['testkineticscrolling'], diff --git a/tests/testinfobar.c b/tests/testinfobar.c new file mode 100644 index 0000000000..76fb257c29 --- /dev/null +++ b/tests/testinfobar.c @@ -0,0 +1,78 @@ +#include <gtk/gtk.h> + +static void +on_button_visible_toggled (GtkToggleButton *button, + void *user_data) +{ + GtkInfoBar *info_bar = GTK_INFO_BAR (user_data); + + gtk_widget_set_visible (GTK_WIDGET (info_bar), + gtk_toggle_button_get_active (button)); +} + +static void +on_button_revealed_toggled (GtkToggleButton *button, + void *user_data) +{ + GtkInfoBar *info_bar = GTK_INFO_BAR (user_data); + + gtk_info_bar_set_revealed (info_bar, + gtk_toggle_button_get_active (button)); +} + +static void +on_activate (GApplication *application, + void *user_data) +{ + GtkWidget *window; + GtkWidget *box; + + GtkWidget *info_bar; + GtkWidget *content_area; + GtkWidget *label; + + GtkWidget *button_visible; + GtkWidget *button_revealed; + + info_bar = gtk_info_bar_new (); + content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar)); + label = gtk_label_new ("Hello!\n\nI am a GtkInfoBar"); + gtk_container_add (GTK_CONTAINER (content_area), label); + + button_visible = gtk_toggle_button_new_with_label ("Toggle ::visible"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_visible), TRUE); + g_signal_connect (button_visible, "toggled", + G_CALLBACK (on_button_visible_toggled), info_bar); + + button_revealed = gtk_toggle_button_new_with_label ("Toggle ::revealed"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_revealed), TRUE); + g_signal_connect (button_revealed, "toggled", + G_CALLBACK (on_button_revealed_toggled), info_bar); + + box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); + gtk_container_add (GTK_CONTAINER (box), button_visible); + gtk_container_add (GTK_CONTAINER (box), button_revealed); + gtk_container_add (GTK_CONTAINER (box), info_bar); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_container_add (GTK_CONTAINER (window), box); + gtk_widget_show (window); + gtk_application_add_window (GTK_APPLICATION (application), + GTK_WINDOW (window)); +} + +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; +} |