Added some menu structure.
This commit is contained in:
parent
3bbe809596
commit
3443454f33
2 changed files with 114 additions and 0 deletions
53
openbox/menu.c
Normal file
53
openbox/menu.c
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#include <glib.h>
|
||||||
|
#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;
|
||||||
|
}
|
61
openbox/menu.h
Normal file
61
openbox/menu.h
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#ifndef __menu_h
|
||||||
|
#define __menu_h
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
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
|
Loading…
Reference in a new issue