diff options
author | Matthias Clasen <mclasen@redhat.com> | 2015-12-18 19:32:24 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2015-12-18 19:38:19 -0500 |
commit | 7acb670e708bc2931d6f8e1afec423b9d7b3c15c (patch) | |
tree | 9ca0b8b285fd2ec2bd66fa813ef314c6612066a5 /tests | |
parent | 18e8842a7e0f458fb1fda2d3ddb8585aa7284324 (diff) | |
download | gtk+-7acb670e708bc2931d6f8e1afec423b9d7b3c15c.tar.gz |
Add more icon entry tests
This test shows that changing icon types works.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testentryicons.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/testentryicons.c b/tests/testentryicons.c index df1d02becb..d9921edc9a 100644 --- a/tests/testentryicons.c +++ b/tests/testentryicons.c @@ -49,6 +49,50 @@ drag_data_get_cb (GtkWidget *widget, } } +static void +set_blank (GtkWidget *button, + GtkEntry *entry) +{ + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) + gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_SECONDARY, NULL); +} + +static void +set_icon_name (GtkWidget *button, + GtkEntry *entry) +{ + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) + gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_SECONDARY, "media-floppy"); +} + +static void +set_gicon (GtkWidget *button, + GtkEntry *entry) +{ + GIcon *icon; + + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) + { + icon = g_themed_icon_new ("gtk-yes"); + gtk_entry_set_icon_from_gicon (entry, GTK_ENTRY_ICON_SECONDARY, icon); + g_object_unref (icon); + } +} + +static void +set_pixbuf (GtkWidget *button, + GtkEntry *entry) +{ + GdkPixbuf *pixbuf; + + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) + { + pixbuf = gdk_pixbuf_new_from_resource ("/org/gtk/libgtk/inspector/logo.png", NULL); + gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, pixbuf); + g_object_unref (pixbuf); + } +} + int main (int argc, char **argv) { @@ -56,6 +100,11 @@ main (int argc, char **argv) GtkWidget *grid; GtkWidget *label; GtkWidget *entry; + GtkWidget *box; + GtkWidget *button1; + GtkWidget *button2; + GtkWidget *button3; + GtkWidget *button4; GIcon *icon; GtkTargetList *tlist; @@ -183,6 +232,25 @@ main (int argc, char **argv) gtk_widget_set_hexpand (entry, TRUE); gtk_grid_attach (GTK_GRID (grid), entry, 1, 4, 1, 1); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_grid_attach (GTK_GRID (grid), box, 0, 5, 3, 1); + + button1 = gtk_radio_button_new_with_label (NULL, "Blank"); + g_signal_connect (button1, "toggled", G_CALLBACK (set_blank), entry); + gtk_container_add (GTK_CONTAINER (box), button1); + button2 = gtk_radio_button_new_with_label (NULL, "Icon Name"); + gtk_radio_button_join_group (GTK_RADIO_BUTTON (button2), GTK_RADIO_BUTTON (button1)); + g_signal_connect (button2, "toggled", G_CALLBACK (set_icon_name), entry); + gtk_container_add (GTK_CONTAINER (box), button2); + button3 = gtk_radio_button_new_with_label (NULL, "GIcon"); + gtk_radio_button_join_group (GTK_RADIO_BUTTON (button3), GTK_RADIO_BUTTON (button1)); + g_signal_connect (button3, "toggled", G_CALLBACK (set_gicon), entry); + gtk_container_add (GTK_CONTAINER (box), button3); + button4 = gtk_radio_button_new_with_label (NULL, "Pixbuf"); + gtk_radio_button_join_group (GTK_RADIO_BUTTON (button4), GTK_RADIO_BUTTON (button1)); + g_signal_connect (button4, "toggled", G_CALLBACK (set_pixbuf), entry); + gtk_container_add (GTK_CONTAINER (box), button4); + gtk_widget_show_all (window); gtk_main(); |