Deplace some ugliness where it belongs.
[gliv.git] / src / dirty_gtk.c
blob4c0978a2c6e0a74e8cb8c8cbc4fbb86a6e47b0e0
1 /* Even the GPL header does not want to be associated with "that". */
3 #include "gliv.h"
4 #include "dirty_gtk.h"
6 /*
7 * This is the only way I found to build a menu with N items in O(N)
8 * time instead of O(N²).
9 */
11 DirtyGtkMenu *dirty_gtk_menu_new(void)
13 DirtyGtkMenu *menu = g_new(DirtyGtkMenu, 1);
15 menu->gtk_menu_shell = GTK_MENU_SHELL(gtk_menu_new());
16 menu->last_child = NULL;
18 return menu;
21 void dirty_gtk_menu_append(DirtyGtkMenu * menu, GtkWidget * item)
23 GList *children = menu->gtk_menu_shell->children;
25 menu->last_child = g_list_last(menu->gtk_menu_shell->children);
26 menu->gtk_menu_shell->children = menu->last_child;
28 gtk_menu_shell_append(menu->gtk_menu_shell, item);
29 if (children != NULL)
30 menu->gtk_menu_shell->children = children;
33 void dirty_gtk_menu_release(DirtyGtkMenu * menu)
35 g_free(menu);
38 /*** ::grab-notify ***/
41 * This is borrowed from gtk+-2, without the gtk_grab_notify() calls.
42 * They slow down things a lot when the images menus are built with many files.
44 GtkWindowGroup *_gtk_window_get_group(GtkWindow * window)
46 if (window && window->group)
47 return window->group;
48 else {
49 static GtkWindowGroup *default_group = NULL;
51 if (!default_group)
52 default_group = gtk_window_group_new();
54 return default_group;
58 static GtkWindowGroup *gtk_main_get_window_group(GtkWidget * widget)
60 GtkWidget *toplevel = NULL;
62 if (widget)
63 toplevel = gtk_widget_get_toplevel(widget);
65 if (toplevel && GTK_IS_WINDOW(toplevel))
66 return _gtk_window_get_group(GTK_WINDOW(toplevel));
67 else
68 return _gtk_window_get_group(NULL);
71 void gtk_grab_add(GtkWidget * widget)
73 GtkWindowGroup *group;
75 g_return_if_fail(widget != NULL);
77 if (!GTK_WIDGET_HAS_GRAB(widget) && GTK_WIDGET_IS_SENSITIVE(widget)) {
78 GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_GRAB);
80 group = gtk_main_get_window_group(widget);
82 g_object_ref(widget);
83 group->grabs = g_slist_prepend(group->grabs, widget);
85 /* gtk_grab_notify (group, widget, FALSE); */
89 void gtk_grab_remove(GtkWidget * widget)
91 GtkWindowGroup *group;
93 g_return_if_fail(widget != NULL);
95 if (GTK_WIDGET_HAS_GRAB(widget)) {
96 GTK_WIDGET_UNSET_FLAGS(widget, GTK_HAS_GRAB);
98 group = gtk_main_get_window_group(widget);
99 group->grabs = g_slist_remove(group->grabs, widget);
101 g_object_unref(widget);
103 /* gtk_grab_notify (group, widget, TRUE); */