mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 02:40:11 +00:00
Add various tests for stock widgets
This test demonstrates that various deprecated ways to construct buttons and menuitems still work as they are supposed to, including always-show-image functionality.
This commit is contained in:
parent
1e1c1556f6
commit
05907afc1c
@ -97,6 +97,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
|
||||
$(testsocket_programs) \
|
||||
testspinbutton \
|
||||
teststatusicon \
|
||||
teststockbuttonmenu \
|
||||
testtoolbar \
|
||||
stresstest-toolbar \
|
||||
testtreechanging \
|
||||
@ -232,6 +233,7 @@ testsocket_DEPENDENCIES = $(DEPS)
|
||||
testsocket_child_DEPENDENCIES = $(DEPS)
|
||||
testspinbutton_DEPENDENCIES = $(TEST_DEPS)
|
||||
teststatusicon_DEPENDENCIES = $(TEST_DEPS)
|
||||
teststockbuttonmenu_DEPENDENCIES = $(TEST_DEPS)
|
||||
testtreechanging_DEPENDENCIES = $(DEPS)
|
||||
testtreeedit_DEPENDENCIES = $(DEPS)
|
||||
testtreemodel_DEPENDENCIES = $(DEPS)
|
||||
|
97
tests/teststockbuttonmenu.c
Normal file
97
tests/teststockbuttonmenu.c
Normal file
@ -0,0 +1,97 @@
|
||||
#include <glib.h>
|
||||
#define GDK_VERSION_MIN_REQUIRED G_ENCODE_VERSION (3, 8)
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
GtkWidget *window;
|
||||
GtkWidget *grid;
|
||||
GtkWidget *button;
|
||||
GtkWidget *menu;
|
||||
GtkWidget *item;
|
||||
GtkWidget *box;
|
||||
GtkAction *action1;
|
||||
GtkAction *action2;
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
action1 = gtk_action_new ("bold", NULL, NULL, GTK_STOCK_BOLD);
|
||||
action2 = gtk_action_new ("new", NULL, NULL, GTK_STOCK_NEW);
|
||||
gtk_action_set_always_show_image (action2, TRUE);
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
|
||||
grid = gtk_grid_new ();
|
||||
gtk_container_add (GTK_CONTAINER (window), grid);
|
||||
|
||||
/* plain old stock button */
|
||||
button = gtk_button_new_from_stock (GTK_STOCK_DELETE);
|
||||
gtk_container_add (GTK_CONTAINER (grid), button);
|
||||
|
||||
/* gtk_button_set_always_show_image still works */
|
||||
button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
|
||||
gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
|
||||
gtk_container_add (GTK_CONTAINER (grid), button);
|
||||
|
||||
/* old-style image-only button */
|
||||
button = gtk_button_new ();
|
||||
gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_icon_name ("edit-find", GTK_ICON_SIZE_BUTTON));
|
||||
gtk_container_add (GTK_CONTAINER (grid), button);
|
||||
|
||||
/* new-style image-only button */
|
||||
button = gtk_button_new_from_icon_name ("edit-clear", GTK_ICON_SIZE_BUTTON);
|
||||
gtk_container_add (GTK_CONTAINER (grid), button);
|
||||
|
||||
/* GtkAction-backed button */
|
||||
button = gtk_button_new ();
|
||||
gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
|
||||
gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action1);
|
||||
gtk_container_add (GTK_CONTAINER (grid), button);
|
||||
|
||||
/* gtk_action_set_always_show_image still works for buttons */
|
||||
button = gtk_button_new ();
|
||||
gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
|
||||
gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action2);
|
||||
gtk_container_add (GTK_CONTAINER (grid), button);
|
||||
|
||||
button = gtk_menu_button_new ();
|
||||
gtk_container_add (GTK_CONTAINER (grid), button);
|
||||
|
||||
menu = gtk_menu_new ();
|
||||
gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu);
|
||||
|
||||
/* plain old stock menuitem */
|
||||
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
||||
|
||||
/* gtk_image_menu_item_set_always_show_image still works */
|
||||
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLOSE, NULL);
|
||||
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
||||
|
||||
/* new-style menuitem with image */
|
||||
item = gtk_menu_item_new ();
|
||||
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
||||
gtk_container_add (GTK_CONTAINER (item), box);
|
||||
gtk_container_add (GTK_CONTAINER (box), gtk_image_new_from_icon_name ("edit-clear", GTK_ICON_SIZE_MENU));
|
||||
gtk_container_add (GTK_CONTAINER (box), gtk_label_new_with_mnemonic ("_Clear"));
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
||||
|
||||
/* GtkAction-backed menuitem */
|
||||
item = gtk_image_menu_item_new ();
|
||||
gtk_activatable_set_related_action (GTK_ACTIVATABLE (item), action1);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
||||
|
||||
/* gtk_action_set_always_show_image still works for menuitems */
|
||||
item = gtk_image_menu_item_new ();
|
||||
gtk_activatable_set_related_action (GTK_ACTIVATABLE (item), action2);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
||||
|
||||
gtk_widget_show_all (menu);
|
||||
|
||||
gtk_widget_show_all (window);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user