Base: LCDproc 0.5.2
[lcdproc-de200c.git] / server / menu.h
blob62463d55a1f5c12799f8e6cdb42d8383c6692592
1 /*
2 * menu.h
3 * This file is part of LCDd, the lcdproc server.
5 * This file is released under the GNU General Public License. Refer to the
6 * COPYING file distributed with this package.
8 * Copyright (c) 1999, William Ferrell, Scott Scriven
9 * 2004, F5 Networks, Inc. - IP-address input
10 * 2005, Peter Marschall - error checks, ...
12 * Defines all the menu data and actions.
16 #include "menuitem.h"
17 /* These headers are placed here on purpose ! (circular references) */
19 #ifndef MENU_H
20 #define MENU_H
22 #ifndef bool
23 # define bool short
24 # define true 1
25 # define false 0
26 #endif
28 #define min(a,b) (((a) < (b)) ? (a) : (b))
29 #define max(a,b) (((a) > (b)) ? (a) : (b))
31 #include "shared/LL.h"
33 /** A Menu is a MenuItem too.
34 * This definition is only for better understanding of this code.
36 typedef MenuItem Menu;
38 #include "screen.h"
40 /** Creates a new menu. */
41 Menu *menu_create(char *id, MenuEventFunc(*event_func),
42 char *text, Client *client);
44 /** Deletes menu from memory.
45 * Destructors will be called for all subitems.
46 * DO NOT CALL THIS FUNCTION, CALL menuitem_destroy INSTEAD !
48 void menu_destroy(Menu *menu);
50 void menu_add_item(Menu *menu, MenuItem *item);
51 /** Adds an item to the menu */
53 /** Removes an item from the menu (does not destroy it) */
54 void menu_remove_item(Menu *menu, MenuItem *item);
56 /** Destroys and removes all items from the menu */
57 void menu_destroy_all_items(Menu *menu);
59 /** Enumeration function.
60 * Retrieves the first item from the list of items in the menu.
62 static inline MenuItem *menu_getfirst_item(Menu *menu)
64 return (MenuItem*) ((menu != NULL)
65 ? LL_GetFirst(menu->data.menu.contents)
66 : NULL);
69 /** Enumeration function.
70 * Retrieves the next item from the list of items in the menu.
71 * No other menu calls should be made between menu_first_item() and
72 * this function, to keep the list-cursor where it is.
74 static inline MenuItem *menu_getnext_item(Menu *menu)
76 return (MenuItem*) ((menu != NULL)
77 ? LL_GetNext(menu->data.menu.contents)
78 : NULL);
81 /** Retrieves the current (non-hidden) item from the list of items in the
82 * menu. */
83 MenuItem *menu_get_current_item(Menu *menu);
85 /** Finds an item in the menu by the given id. */
86 MenuItem *menu_find_item(Menu *menu, char *id, bool recursive);
88 /** sets the association member of a Menu. */
89 void menu_set_association(Menu *menu, void *assoc);
91 /** Resets it to initial state.
92 * DO NOT CALL THIS FUNCTION, CALL menuitem_reset_screen INSTEAD !
94 void menu_reset(Menu *menu);
96 /** Builds the selected menuitem on screen using widgets.
97 * DO NOT CALL THIS FUNCTION, CALL menuitem_rebuild_screen INSTEAD !
99 void menu_build_screen(Menu *menu, Screen *s);
101 /** Updates the widgets of the selected menuitem
102 * DO NOT CALL THIS FUNCTION, CALL menuitem_update_screen INSTEAD !
104 void menu_update_screen(Menu *menu, Screen *s);
107 * For predecessor-Check: returns selected subitem of menu if this subitem
108 * has no own screen (action, checkbox, ...) and this subitem has a
109 * predecessor and menu otherwise.
111 * @return NULL on error. */
112 MenuItem *menu_get_item_for_predecessor_check(Menu *menu);
115 * For successor-Check: returns selected subitem of menu if
116 * this subitem has no own screen (action, checkbox, ...) or menu
117 * otherwise.
119 * @return NULL on error. */
120 MenuItem *menu_get_item_for_successor_check(Menu *menu);
122 /** Does something with the given input.
123 * key is only used if token is MENUTOKEN_OTHER.
124 * DO NOT CALL THIS FUNCTION, CALL menuitem_process_input INSTEAD !
126 MenuResult menu_process_input(Menu *menu, MenuToken token, const char *key, bool extended);
128 /** positions current item pointer on subitem subitem_id. */
129 void menu_select_subitem(Menu *menu, char *subitem_id);
130 #endif