From: Scott Moynes Date: Mon, 24 Mar 2003 21:54:47 +0000 (+0000) Subject: Added some menu structure. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=3443454f33f88e10f187b78594ecfb5c09e1448d;p=chaz%2Fopenbox Added some menu structure. --- diff --git a/openbox/menu.c b/openbox/menu.c new file mode 100644 index 00000000..bd6cf065 --- /dev/null +++ b/openbox/menu.c @@ -0,0 +1,53 @@ +#include +#include "menu.h" + +Menu *menu_new(char *label, Menu *parent) +{ + Menu *new_menu = g_new(Menu, 1); + new_menu->label = g_strdup(lable); + new_menu->parent = parent; + + new_menu->entries = NULL; + new_menu->tail = NULL; + new_menu->shown = FALSE; + new_menu->invalid = FALSE; + /* default controllers? */ + + return new_menu; +} + +MenuEntry *menu_entry_new_full(char *label, Action *action, + MenuEntryRenderType render_type, + gpointer render_data, gpointer submenu) +{ + MenuEntry *menu_entry = g_new(MenuEntry, 1); + + menu_entry->label = g_strdup(label); + menu_entry->action.func = action->func; + menu_entry->action.data = action->data; //watch out. copying Client * ptr + + menu_entry->render_data = render_data; //watch out. + menu_entry->submenu = submenu; + + return menu_entry; +} + +void menu_entry_set_submenu(MenuEntry *entry, Menu *submenu) +{ + assert(entry != NULL); + + entry->submenu = submenu; + + if(entry->parent != NULL) + entry->parent->invalid = TRUE; +} + +void menu_add_entry(Menu *menu, MenuEntry *entry) +{ + assert(menu != NULL && entry != NULL); + + menu->entries = g_list_append(menu->entries, entry); + entry->parent = menu; + + menu->invalid = TRUE; +} diff --git a/openbox/menu.h b/openbox/menu.h new file mode 100644 index 00000000..d7d27c2c --- /dev/null +++ b/openbox/menu.h @@ -0,0 +1,61 @@ +#ifndef __menu_h +#define __menu_h + +#include + +typedef struct { + char *label; + + GList *entries; + /* GList *tail; */ + + /* ? */ + gboolean shown; + gboolean invalid; + + Menu *parent; + + /* waste o' pointers */ + void (*show)( /* some bummu */); + void (*hide)( /* some bummu */); + void (*update)( /* some bummu */); + void (*mouseover)( /* some bummu */); + void (*selected)( /* some bummu */); +} Menu; + +typedef enum MenuEntryRenderType { + MenuEntryRenderType_None = 0, + MenuEntryRenderType_Submenu 1 << 0, + MenuEntryRenderType_Boolean 1 << 1, + MenuEntryRenderType_Separator 1 << 2, + + MenuEntryRenderType_Other 1 << 7 +} MenuEntryType; + + +typedef struct { + char *label; + Menu *parent; + + Action action; + + MenuEntryRenderType render_type; + gboolean enabled; + gboolean boolean_value; + gpointer render_data; + + Menu *submenu; +} MenuEntry; + +Menu *menu_new(char *label, Menu *parent); +MenuEntry *menu_entry_new_full(char *label, Action *action, + MenuEntryRenderType render_type, + gpointer render_data, gpointer submenu); + +#define menu_entry_new(label, action) \ + menu_entry_new(label, action, MenuEntryRenderType_None, NULL, NULL) + +void menu_entry_set_submenu(MenuEntry *entry, Menu *submenu); + +void menu_add_entry(Menu *menu, MenuEntry *entry); +#endif