]> Dogcows Code - chaz/openbox/blob - openbox/menu.c
these menus should not be removed, they are good and will be used.
[chaz/openbox] / openbox / menu.c
1 #include <glib.h>
2 #include "menu.h"
3 #include <assert.h>
4
5 GHashTable *menu_hash = NULL;
6
7 void menu_destroy_hash_key(const gpointer data)
8 {
9 g_free(data);
10 }
11
12 void menu_free_entries(const Menu *menu)
13 {
14 GList *it;
15
16 for (it = menu->entries; it; it = it->next)
17 menu_entry_free((MenuEntry *)it->data);
18
19 g_list_free(menu->entries);
20 }
21
22 void menu_destroy_hash_value(const gpointer data)
23 {
24 const Menu *del_menu = (Menu *)data;
25
26 g_free(del_menu->label);
27 g_free(del_menu->name);
28
29 menu_free_entries(del_menu);
30 }
31
32 void menu_entry_free(const MenuEntry *entry)
33 {
34 g_free(entry->label);
35 g_free(entry->render_data);
36 }
37
38 void menu_startup()
39 {
40 menu_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
41 menu_destroy_hash_key,
42 menu_destroy_hash_value);
43 }
44
45 void menu_shutdown()
46 {
47 g_hash_table_destroy(menu_hash);
48 }
49
50 Menu *menu_new(const char *label, const char *name, Menu *parent)
51 {
52 Menu *new_menu = g_new0(Menu, 1);
53 new_menu->label = g_strdup(label);
54 new_menu->name = g_strdup(name);
55 new_menu->parent = parent;
56
57 new_menu->entries = NULL;
58 new_menu->shown = FALSE;
59 new_menu->invalid = FALSE;
60 /* default controllers? */
61
62 g_hash_table_insert(menu_hash, g_strdup(name), new_menu);
63 return new_menu;
64 }
65
66 void menu_free(const char *name)
67 {
68 g_hash_table_remove(menu_hash, name);
69 }
70
71 MenuEntry *menu_entry_new_full(const char *label, Action *action,
72 const MenuEntryRenderType render_type,
73 gpointer render_data, gpointer submenu)
74 {
75 MenuEntry *menu_entry = g_new(MenuEntry, 1);
76
77 menu_entry->label = g_strdup(label);
78 menu_entry->render_type = render_type;
79 menu_entry->action.func = action->func;
80 menu_entry->action.data = action->data; /*watch out. copying Client * ptr*/
81
82 menu_entry->render_data = render_data; /*watch out.*/
83 menu_entry->submenu = submenu;
84
85 return menu_entry;
86 }
87
88 void menu_entry_set_submenu(MenuEntry *entry, Menu *submenu)
89 {
90 assert(entry != NULL);
91
92 entry->submenu = submenu;
93
94 if(entry->parent != NULL)
95 entry->parent->invalid = TRUE;
96 }
97
98 void menu_add_entry(Menu *menu, MenuEntry *entry)
99 {
100 assert(menu != NULL && entry != NULL);
101
102 menu->entries = g_list_append(menu->entries, entry);
103 entry->parent = menu;
104
105 menu->invalid = TRUE;
106 }
This page took 0.041698 seconds and 5 git commands to generate.