5 GHashTable *menu_hash = NULL;
7 void menu_destroy_hash_key(const gpointer data)
12 void menu_free_entries(const Menu *menu)
16 for (it = menu->entries; it; it = it->next)
17 menu_entry_free((MenuEntry *)it->data);
19 g_list_free(menu->entries);
22 void menu_destroy_hash_value(const gpointer data)
24 const Menu *del_menu = (Menu *)data;
26 g_free(del_menu->label);
27 g_free(del_menu->name);
29 menu_free_entries(del_menu);
32 void menu_entry_free(const MenuEntry *entry)
35 g_free(entry->render_data);
40 menu_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
41 menu_destroy_hash_key,
42 menu_destroy_hash_value);
47 g_hash_table_destroy(menu_hash);
50 Menu *menu_new(const char *label, const char *name, Menu *parent)
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;
57 new_menu->entries = NULL;
58 new_menu->shown = FALSE;
59 new_menu->invalid = FALSE;
60 /* default controllers? */
62 g_hash_table_insert(menu_hash, g_strdup(name), new_menu);
66 void menu_free(const char *name)
68 g_hash_table_remove(menu_hash, name);
71 MenuEntry *menu_entry_new_full(const char *label, Action *action,
72 const MenuEntryRenderType render_type,
73 gpointer render_data, gpointer submenu)
75 MenuEntry *menu_entry = g_new(MenuEntry, 1);
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*/
82 menu_entry->render_data = render_data; /*watch out.*/
83 menu_entry->submenu = submenu;
88 void menu_entry_set_submenu(MenuEntry *entry, Menu *submenu)
90 assert(entry != NULL);
92 entry->submenu = submenu;
94 if(entry->parent != NULL)
95 entry->parent->invalid = TRUE;
98 void menu_add_entry(Menu *menu, MenuEntry *entry)
100 assert(menu != NULL && entry != NULL);
102 menu->entries = g_list_append(menu->entries, entry);
103 entry->parent = menu;
105 menu->invalid = TRUE;