2008-11-30 22:31:20 +00:00
|
|
|
/** \file server/menu.h
|
|
|
|
|
* Defines all the menu data and actions.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* This file is part of LCDd, the lcdproc server.
|
2001-12-27 23:30:36 +00:00
|
|
|
*
|
2008-11-30 22:31:20 +00:00
|
|
|
* This file is released under the GNU General Public License.
|
|
|
|
|
* Refer to the COPYING file distributed with this package.
|
2001-12-27 23:30:36 +00:00
|
|
|
*
|
2011-01-05 23:34:37 +00:00
|
|
|
* Copyright (c) 1999, William Ferrell, Selene Scriven
|
2005-03-13 21:23:56 +00:00
|
|
|
* 2004, F5 Networks, Inc. - IP-address input
|
|
|
|
|
* 2005, Peter Marschall - error checks, ...
|
2001-12-27 23:30:36 +00:00
|
|
|
*/
|
|
|
|
|
|
2002-06-28 23:35:55 +00:00
|
|
|
#include "menuitem.h"
|
|
|
|
|
/* These headers are placed here on purpose ! (circular references) */
|
|
|
|
|
|
1999-12-09 23:15:14 +00:00
|
|
|
#ifndef MENU_H
|
|
|
|
|
#define MENU_H
|
|
|
|
|
|
2002-05-26 19:21:23 +00:00
|
|
|
#ifndef bool
|
|
|
|
|
# define bool short
|
|
|
|
|
# define true 1
|
|
|
|
|
# define false 0
|
|
|
|
|
#endif
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2002-06-28 23:35:55 +00:00
|
|
|
#include "shared/LL.h"
|
|
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** A Menu is a MenuItem too.
|
2002-04-26 00:00:31 +00:00
|
|
|
* This definition is only for better understanding of this code.
|
|
|
|
|
*/
|
2005-05-20 09:44:12 +00:00
|
|
|
typedef MenuItem Menu;
|
2002-04-26 00:00:31 +00:00
|
|
|
|
2002-06-28 23:35:55 +00:00
|
|
|
#include "screen.h"
|
|
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** Creates a new menu. */
|
2007-04-02 21:29:53 +00:00
|
|
|
Menu *menu_create(char *id, MenuEventFunc(*event_func),
|
2005-05-20 09:44:12 +00:00
|
|
|
char *text, Client *client);
|
2002-04-26 00:00:31 +00:00
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** Deletes menu from memory.
|
2002-05-26 19:21:23 +00:00
|
|
|
* Destructors will be called for all subitems.
|
2005-04-05 07:28:18 +00:00
|
|
|
* DO NOT CALL THIS FUNCTION, CALL menuitem_destroy INSTEAD !
|
2002-04-26 00:00:31 +00:00
|
|
|
*/
|
2007-04-02 21:29:53 +00:00
|
|
|
void menu_destroy(Menu *menu);
|
2002-04-26 00:00:31 +00:00
|
|
|
|
2007-04-02 21:29:53 +00:00
|
|
|
void menu_add_item(Menu *menu, MenuItem *item);
|
2005-05-20 09:44:12 +00:00
|
|
|
/** Adds an item to the menu */
|
2002-05-26 19:21:23 +00:00
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** Removes an item from the menu (does not destroy it) */
|
2007-04-02 21:29:53 +00:00
|
|
|
void menu_remove_item(Menu *menu, MenuItem *item);
|
2002-05-26 19:21:23 +00:00
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** Destroys and removes all items from the menu */
|
2007-04-02 21:29:53 +00:00
|
|
|
void menu_destroy_all_items(Menu *menu);
|
2002-04-26 00:00:31 +00:00
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** Enumeration function.
|
2002-05-26 19:21:23 +00:00
|
|
|
* Retrieves the first item from the list of items in the menu.
|
|
|
|
|
*/
|
2007-04-02 21:29:53 +00:00
|
|
|
static inline MenuItem *menu_getfirst_item(Menu *menu)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2005-02-28 20:21:40 +00:00
|
|
|
return (MenuItem*) ((menu != NULL)
|
|
|
|
|
? LL_GetFirst(menu->data.menu.contents)
|
|
|
|
|
: NULL);
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** Enumeration function.
|
2002-05-26 19:21:23 +00:00
|
|
|
* Retrieves the next item from the list of items in the menu.
|
2002-04-26 00:00:31 +00:00
|
|
|
* No other menu calls should be made between menu_first_item() and
|
2002-05-26 19:21:23 +00:00
|
|
|
* this function, to keep the list-cursor where it is.
|
|
|
|
|
*/
|
2007-04-02 21:29:53 +00:00
|
|
|
static inline MenuItem *menu_getnext_item(Menu *menu)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2005-02-28 20:21:40 +00:00
|
|
|
return (MenuItem*) ((menu != NULL)
|
|
|
|
|
? LL_GetNext(menu->data.menu.contents)
|
|
|
|
|
: NULL);
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2005-06-01 22:45:43 +00:00
|
|
|
/** Retrieves the current (non-hidden) item from the list of items in the
|
|
|
|
|
* menu. */
|
2007-04-02 21:29:53 +00:00
|
|
|
MenuItem *menu_get_current_item(Menu *menu);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** Finds an item in the menu by the given id. */
|
2007-04-02 21:29:53 +00:00
|
|
|
MenuItem *menu_find_item(Menu *menu, char *id, bool recursive);
|
2002-05-26 19:21:23 +00:00
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** sets the association member of a Menu. */
|
|
|
|
|
void menu_set_association(Menu *menu, void *assoc);
|
|
|
|
|
|
|
|
|
|
/** Resets it to initial state.
|
2005-02-28 20:21:40 +00:00
|
|
|
* DO NOT CALL THIS FUNCTION, CALL menuitem_reset_screen INSTEAD !
|
2002-04-26 00:00:31 +00:00
|
|
|
*/
|
2007-04-02 21:29:53 +00:00
|
|
|
void menu_reset(Menu *menu);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** Builds the selected menuitem on screen using widgets.
|
2005-02-28 20:21:40 +00:00
|
|
|
* DO NOT CALL THIS FUNCTION, CALL menuitem_rebuild_screen INSTEAD !
|
2002-05-26 19:21:23 +00:00
|
|
|
*/
|
2007-04-02 21:29:53 +00:00
|
|
|
void menu_build_screen(Menu *menu, Screen *s);
|
2002-05-26 19:21:23 +00:00
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** Updates the widgets of the selected menuitem
|
2005-02-28 20:21:40 +00:00
|
|
|
* DO NOT CALL THIS FUNCTION, CALL menuitem_update_screen INSTEAD !
|
2002-05-26 19:21:23 +00:00
|
|
|
*/
|
2007-04-02 21:29:53 +00:00
|
|
|
void menu_update_screen(Menu *menu, Screen *s);
|
2002-05-26 19:21:23 +00:00
|
|
|
|
2005-07-17 16:13:24 +00:00
|
|
|
/**
|
|
|
|
|
* For predecessor-Check: returns selected subitem of menu if this subitem
|
|
|
|
|
* has no own screen (action, checkbox, ...) and this subitem has a
|
|
|
|
|
* predecessor and menu otherwise.
|
|
|
|
|
*
|
|
|
|
|
* @return NULL on error. */
|
2007-04-02 21:29:53 +00:00
|
|
|
MenuItem *menu_get_item_for_predecessor_check(Menu *menu);
|
2005-07-17 16:13:24 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* For successor-Check: returns selected subitem of menu if
|
|
|
|
|
* this subitem has no own screen (action, checkbox, ...) or menu
|
|
|
|
|
* otherwise.
|
|
|
|
|
*
|
|
|
|
|
* @return NULL on error. */
|
2007-04-02 21:29:53 +00:00
|
|
|
MenuItem *menu_get_item_for_successor_check(Menu *menu);
|
2005-07-17 16:13:24 +00:00
|
|
|
|
2005-05-20 09:44:12 +00:00
|
|
|
/** Does something with the given input.
|
2002-05-26 19:21:23 +00:00
|
|
|
* key is only used if token is MENUTOKEN_OTHER.
|
2005-02-28 20:21:40 +00:00
|
|
|
* DO NOT CALL THIS FUNCTION, CALL menuitem_process_input INSTEAD !
|
2002-04-26 00:00:31 +00:00
|
|
|
*/
|
2007-10-05 08:21:10 +00:00
|
|
|
MenuResult menu_process_input(Menu *menu, MenuToken token, const char *key, unsigned int keymask);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2007-10-13 15:33:59 +00:00
|
|
|
/** positions current item pointer on subitem item_id. */
|
|
|
|
|
void menu_select_subitem(Menu *menu, char *item_id);
|
1999-12-09 23:15:14 +00:00
|
|
|
#endif
|