tests: Stop using menus

This commit is contained in:
Matthias Clasen 2019-12-26 23:16:53 -05:00
parent bf4ec504b2
commit 5c97f09796
11 changed files with 23 additions and 2479 deletions

View File

@ -114,7 +114,6 @@ gtk_tests = [
['testpopover'],
['gdkgears', ['gtkgears.c']],
['listmodel'],
['testpopupat'],
['testgaction'],
['testwidgetfocus'],
['testwidgettransforms'],

File diff suppressed because it is too large Load Diff

View File

@ -717,7 +717,6 @@ static void
activate (GApplication *app)
{
GtkWidget *box;
GtkWidget *bar;
GtkWidget *sw;
GtkWidget *contents;
@ -729,10 +728,6 @@ activate (GApplication *app)
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (main_window), box);
bar = gtk_menu_bar_new ();
gtk_widget_show (bar);
gtk_container_add (GTK_CONTAINER (box), bar);
/* Create document */
sw = gtk_scrolled_window_new (NULL, NULL);

View File

@ -125,10 +125,10 @@ int main (int argc, char **argv)
GtkBuilder *builder = gtk_builder_new_from_string (menu_data, -1);
menu_model = G_MENU_MODEL (gtk_builder_get_object (builder, "menu_model"));
menu = gtk_menu_new_from_model (menu_model);
menu = gtk_popover_menu_new_from_model (NULL, menu_model);
}
gtk_menu_button_set_popup (GTK_MENU_BUTTON (menubutton), menu);
gtk_menu_button_set_popover (GTK_MENU_BUTTON (menubutton), menu);
gtk_container_add (GTK_CONTAINER (box), menubutton);
gtk_widget_set_halign (button1, GTK_ALIGN_CENTER);
gtk_actionable_set_action_name (GTK_ACTIONABLE (button1), "win.change-label-button");

View File

@ -674,7 +674,6 @@ main (int argc, char *argv[])
{
button = gtk_menu_button_new ();
gtk_button_set_label (GTK_BUTTON (button), "Click here");
gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (button), TRUE);
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), model);
gtk_widget_insert_action_group (button, "actions", group);
gtk_container_add (GTK_CONTAINER (box), button);

View File

@ -1604,150 +1604,6 @@ create_listbox (GtkWidget *widget)
}
/*
* Menu demo
*/
static GtkWidget*
create_menu (gint depth, gint length)
{
GtkWidget *menu;
GtkWidget *menuitem;
GtkWidget *image;
GtkWidget *box;
GtkWidget *label;
GSList *group;
char buf[32];
int i, j;
if (depth < 1)
return NULL;
menu = gtk_menu_new ();
group = NULL;
image = gtk_image_new_from_icon_name ("document-open");
menuitem = gtk_menu_item_new ();
label = gtk_label_new ("Image Item");
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_container_add (GTK_CONTAINER (box), image);
gtk_container_add (GTK_CONTAINER (box), label);
gtk_container_add (GTK_CONTAINER (menuitem), box);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
for (i = 0, j = 1; i < length; i++, j++)
{
sprintf (buf, "item %2d - %d", depth, j);
menuitem = gtk_radio_menu_item_new_with_label (group, buf);
group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
if (i == 3)
gtk_widget_set_sensitive (menuitem, FALSE);
if (i == 5)
gtk_check_menu_item_set_inconsistent (GTK_CHECK_MENU_ITEM (menuitem),
TRUE);
if (i < 5)
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem),
create_menu (depth - 1, 5));
}
return menu;
}
static void
create_menus (GtkWidget *widget)
{
static GtkWidget *window = NULL;
GtkWidget *box1;
GtkWidget *box2;
GtkWidget *button;
GtkWidget *separator;
GtkWidget *box;
GtkWidget *label;
if (!window)
{
GtkWidget *menubar;
GtkWidget *menu;
GtkWidget *menuitem;
GtkWidget *image;
GdkDisplay *display = gtk_widget_get_display (widget);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_hide_on_close (GTK_WINDOW (window), TRUE);
gtk_window_set_display (GTK_WINDOW (window), display);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
gtk_window_set_title (GTK_WINDOW (window), "menus");
box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
menubar = gtk_menu_bar_new ();
gtk_container_add (GTK_CONTAINER (box1), menubar);
menu = create_menu (2, 50);
menuitem = gtk_menu_item_new_with_label ("test\nline2");
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
menuitem = gtk_menu_item_new_with_label ("foo");
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3, 5));
gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
image = gtk_image_new_from_icon_name ("help-browser");
menuitem = gtk_menu_item_new ();
label = gtk_label_new ("Help");
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_container_add (GTK_CONTAINER (box), label);
gtk_container_add (GTK_CONTAINER (box), image);
gtk_container_add (GTK_CONTAINER (menuitem), box);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4, 5));
gtk_widget_set_hexpand (menuitem, TRUE);
gtk_widget_set_halign (menuitem, GTK_ALIGN_END);
gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
menubar = gtk_menu_bar_new ();
gtk_container_add (GTK_CONTAINER (box1), menubar);
menu = create_menu (2, 10);
menuitem = gtk_menu_item_new_with_label ("Second menu bar");
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
gtk_container_add (GTK_CONTAINER (box1), box2);
separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (box1), separator);
box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
gtk_container_add (GTK_CONTAINER (box1), box2);
button = gtk_button_new_with_label ("close");
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy),
window);
gtk_container_add (GTK_CONTAINER (box2), button);
gtk_window_set_default_widget (GTK_WINDOW (window), button);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
}
static GtkWidget *
accel_button_new (GtkAccelGroup *accel_group,
const gchar *text,
@ -6296,7 +6152,6 @@ struct {
{ "key lookup", create_key_lookup },
{ "labels", create_labels },
{ "listbox", create_listbox },
{ "menus", create_menus },
{ "message dialog", create_message_dialog },
{ "modal window", create_modal_window, TRUE },
{ "native dialogs", create_native_dialogs },

View File

@ -334,25 +334,24 @@ do_popup_menu (GtkWidget *icon_list,
{
GtkIconView *icon_view = GTK_ICON_VIEW (icon_list);
GtkWidget *menu;
GtkWidget *menuitem;
GtkWidget *item;
ItemData *data;
if (!path)
return;
menu = gtk_menu_new ();
menu = gtk_popover_new (icon_list);
data = g_new0 (ItemData, 1);
data->icon_list = icon_view;
data->path = path;
g_object_set_data_full (G_OBJECT (menu), "item-path", data, (GDestroyNotify)free_item_data);
menuitem = gtk_menu_item_new_with_label ("Activate");
gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
g_signal_connect (menuitem, "activate", G_CALLBACK (item_cb), data);
item = gtk_button_new_with_label ("Activate");
gtk_container_add (GTK_CONTAINER (menu), item);
g_signal_connect (item, "clicked", G_CALLBACK (item_cb), data);
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
gtk_popover_popup (GTK_POPOVER (menu));
}
static void

View File

@ -12,7 +12,7 @@ horizontal_alignment_changed (GtkComboBox *box)
GList *l;
for (l = menubuttons; l != NULL; l = l->next) {
GtkMenu *popup = gtk_menu_button_get_popup (GTK_MENU_BUTTON (l->data));
GtkPopover *popup = gtk_menu_button_get_popover (GTK_MENU_BUTTON (l->data));
if (popup != NULL)
gtk_widget_set_halign (GTK_WIDGET (popup), alignment);
}
@ -25,7 +25,7 @@ vertical_alignment_changed (GtkComboBox *box)
GList *l;
for (l = menubuttons; l != NULL; l = l->next) {
GtkMenu *popup = gtk_menu_button_get_popup (GTK_MENU_BUTTON (l->data));
GtkPopover *popup = gtk_menu_button_get_popover (GTK_MENU_BUTTON (l->data));
if (popup != NULL)
gtk_widget_set_valign (GTK_WIDGET (popup), alignment);
}
@ -40,7 +40,6 @@ int main (int argc, char **argv)
GtkWidget *label;
GtkWidget *check;
GtkWidget *combo;
GtkWidget *menu_widget;
GtkAccelGroup *accel_group;
guint i;
guint row = 0;
@ -102,32 +101,6 @@ int main (int argc, char **argv)
gtk_grid_attach_next_to (GTK_GRID (grid), button, entry, GTK_POS_RIGHT, 1, 1);
menubuttons = g_list_prepend (menubuttons, button);
/* Button with GtkMenu */
menu_widget = gtk_menu_new ();
for (i = 0; i < 5; ++i) {
GtkWidget *item;
if (i == 2) {
item = gtk_menu_item_new_with_mnemonic ("_Copy");
} else {
char *label;
label = g_strdup_printf ("Item _%d", i + 1);
item = gtk_menu_item_new_with_mnemonic (label);
g_free (label);
}
gtk_menu_item_set_use_underline (GTK_MENU_ITEM (item), TRUE);
gtk_container_add (GTK_CONTAINER (menu_widget), item);
}
gtk_widget_show (menu_widget);
button = gtk_menu_button_new ();
gtk_widget_set_halign (button, GTK_ALIGN_START);
menubuttons = g_list_prepend (menubuttons, button);
gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu_widget);
gtk_grid_attach (GTK_GRID (grid), button, 1, row++, 1, 1);
check = gtk_check_button_new_with_label ("Popover");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE);
gtk_grid_attach (GTK_GRID (grid), check, 0, row, 1, 1);

View File

@ -101,7 +101,6 @@ main (int argc, char *argv[])
gtk_container_add (GTK_CONTAINER (box), button2);
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), model);
gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (button), TRUE);
popover = GTK_WIDGET (gtk_menu_button_get_popover (GTK_MENU_BUTTON (button)));
popover1 = gtk_popover_menu_new_from_model_full (NULL, model, GTK_POPOVER_MENU_NESTED);

View File

@ -1,64 +0,0 @@
#include <gtk/gtk.h>
static void
destroy_cb (GtkWidget *window,
GtkBuilder *builder)
{
gtk_main_quit ();
}
static void
populate_popup_cb (GtkAppChooserWidget *app_chooser_widget,
GtkMenu *menu,
GAppInfo *app_info,
gpointer user_data)
{
GtkWidget *menu_item;
menu_item = gtk_menu_item_new_with_label ("Menu Item A");
gtk_widget_show (menu_item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
menu_item = gtk_menu_item_new_with_label ("Menu Item B");
gtk_widget_show (menu_item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
menu_item = gtk_menu_item_new_with_label ("Menu Item C");
gtk_widget_show (menu_item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
menu_item = gtk_menu_item_new_with_label ("Menu Item D");
gtk_widget_show (menu_item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
menu_item = gtk_menu_item_new_with_label ("Menu Item E");
gtk_widget_show (menu_item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
}
int
main (int argc,
char *argv[])
{
GtkBuilder *builder;
GtkWidget *window;
GtkWidget *app_chooser_widget;
gtk_init ();
builder = gtk_builder_new_from_file ("popupat.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), builder);
app_chooser_widget = GTK_WIDGET (gtk_builder_get_object (builder, "appchooserwidget"));
g_signal_connect (app_chooser_widget, "populate-popup", G_CALLBACK (populate_popup_cb), builder);
gtk_widget_show (window);
gtk_main ();
g_object_unref (builder);
return 0;
}

View File

@ -320,44 +320,6 @@ rtl_toggled (GtkCheckButton *check)
gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR);
}
static gboolean
popup_context_menu (GtkToolbar *toolbar, gint x, gint y, gint button_number)
{
GtkMenu *menu = GTK_MENU (gtk_menu_new ());
int i;
for (i = 0; i < 5; i++)
{
GtkWidget *item;
gchar *label = g_strdup_printf ("Item _%d", i);
item = gtk_menu_item_new_with_mnemonic (label);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
if (button_number != -1)
{
gtk_menu_popup_at_pointer (menu, NULL);
}
else
{
GtkWindow *window;
GtkWidget *widget;
window = GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (toolbar)));
widget = gtk_root_get_focus (GTK_ROOT (window));
if (!widget)
widget = GTK_WIDGET (toolbar);
gtk_menu_popup_at_widget (menu,
widget,
GDK_GRAVITY_SOUTH_EAST,
GDK_GRAVITY_NORTH_WEST,
NULL);
}
return TRUE;
}
static GtkToolItem *drag_item = NULL;
static gboolean
@ -433,6 +395,7 @@ main (gint argc, gchar **argv)
GtkListStore *store;
GtkWidget *image;
GtkWidget *menuitem;
GtkWidget *box;
GtkWidget *button;
GtkWidget *label;
GIcon *gicon;
@ -501,40 +464,42 @@ main (gint argc, gchar **argv)
g_timeout_add (3000, (GSourceFunc) timeout_cb, item);
gtk_tool_item_set_expand (item, TRUE);
menu = gtk_menu_new ();
menu = gtk_popover_new (NULL);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (menu), box);
for (i = 0; i < 20; i++)
{
char *text;
text = g_strdup_printf ("Menuitem %d", i);
menuitem = gtk_menu_item_new_with_label (text);
menuitem = gtk_button_new_with_label (text);
g_free (text);
gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
gtk_container_add (GTK_CONTAINER (box), menuitem);
}
item = gtk_menu_tool_button_new (NULL, NULL);
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "document-open");
gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Open");
gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu);
gtk_menu_tool_button_set_popover (GTK_MENU_TOOL_BUTTON (item), menu);
add_item_to_list (store, item, "Open");
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
g_timeout_add (3000, (GSourceFunc) timeout_cb1, item);
menu = gtk_menu_new ();
menu = gtk_popover_new (NULL);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (menu), box);
for (i = 0; i < 20; i++)
{
char *text;
text = g_strdup_printf ("A%d", i);
menuitem = gtk_menu_item_new_with_label (text);
menuitem = gtk_button_new_with_label (text);
g_free (text);
gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
gtk_container_add (GTK_CONTAINER (box), menuitem);
}
item = gtk_menu_tool_button_new (NULL, NULL);
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-previous");
gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Back");
gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu);
gtk_menu_tool_button_set_popover (GTK_MENU_TOOL_BUTTON (item), menu);
add_item_to_list (store, item, "BackWithHistory");
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
@ -669,8 +634,6 @@ main (gint argc, gchar **argv)
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect (toolbar, "popup_context_menu", G_CALLBACK (popup_context_menu), NULL);
gtk_main ();
return 0;