Big changes in code of clients, screens and widgets.
- Moved and altered code to create, destroy and manipulate clients, screens and widgets in an OO-like manner. - Moved command execution code to a commands directory, splitting commands to what subject they are concerned. - Menus are temporary disabled while working on new menu structure.
This commit is contained in:
+157
-111
@@ -7,140 +7,186 @@
|
||||
*
|
||||
* Copyright (c) 1999, William Ferrell, Scott Scriven
|
||||
*
|
||||
* Defines all the menu data and action.
|
||||
*/
|
||||
|
||||
#ifndef MENU_H
|
||||
#define MENU_H
|
||||
|
||||
#if 0
|
||||
/*************************************************************************
|
||||
Menus!
|
||||
#include "shared/LL.h"
|
||||
|
||||
This is how the LCDproc menu stuff works...
|
||||
#include "screen.h"
|
||||
|
||||
Each item has three values:
|
||||
/*********************************************************************
|
||||
* Data definitions of the menustuff
|
||||
* Do not modify attributes from your code, but call functions.
|
||||
*/
|
||||
|
||||
Title -- Text
|
||||
Type -- menu, function, checkbox, slider, mover
|
||||
Data -- Child, ExecFunc, CheckFunc, SlidFunc, ???
|
||||
typedef enum MenuItemType {
|
||||
MENUITEM_NONE = 0,
|
||||
MENUITEM_TITLE,
|
||||
MENUITEM_MENU,
|
||||
MENUITEM_ACTION,
|
||||
MENUITEM_CHECKBOX,
|
||||
MENUITEM_SLIDER,
|
||||
MENUITEM_NUMERIC_INPUT,
|
||||
MENUITEM_STRING_INPUT,
|
||||
} MenuItemType;
|
||||
|
||||
When an item is picked, do_menu() decides what to do based on type.
|
||||
--"Menus" will recurse into the "data", assuming it is a child menu.
|
||||
--"Function"-type items will have their function called.
|
||||
--CheckBox-type items will have their function called with a "read"
|
||||
parameter to get an on/off signal, and called with a "set" signal when
|
||||
picked.
|
||||
--Sliders will have the same "read" thing, and the "set" function will
|
||||
take a plus or minus parameter.
|
||||
--The Movers will act like a label until picked, and then the +/- keys
|
||||
will both rearrange the menu, and send the item a signal of some sort
|
||||
to indicate what happened. It will act like a label again after the
|
||||
user presses Enter again.
|
||||
typedef enum CheckboxValue {
|
||||
CHECKBOX_OFF = 0, CHECKBOX_ON, CHECKBOX_GRAY
|
||||
} CheckboxValue;
|
||||
|
||||
The "Data" field will really be a "void *", which is the "generic"
|
||||
data type in C...
|
||||
|
||||
Anyway, this sort of thing would be declared this way:
|
||||
|
||||
========================================================================
|
||||
/* Return codes from an event value */
|
||||
typedef enum MenuEventFuncResult {
|
||||
MENUEVENTRES_ERROR = -1, /* Something has gone wrong */
|
||||
MENUEVENTRES_OK = 0, /* Event handled OK */
|
||||
MENUEVENTRES_CLOSE, /* Event handled OK, close the menu now */
|
||||
MENUEVENTRES_QUIT /* Event handled OK, close ALL menus now */
|
||||
} MenuEventFuncResult;
|
||||
|
||||
menu_item MainMenu[] = {
|
||||
"MENU", 0, 0, // Title
|
||||
"Options", TYPE_MENU, (void *)OptionsMenu,
|
||||
"Kill LCDproc", TYPE_FUNC, (void *)Shutdown_func,
|
||||
0, 0, 0,
|
||||
};
|
||||
/* Events that can happen */
|
||||
typedef enum MenuEventType {
|
||||
MENUEVENT_SELECT, /* Item has been selected
|
||||
(menu opened, action selected) */
|
||||
MENUEVENT_UPDATE, /* Item has been modified
|
||||
(checkbox, numeric, string, password) */
|
||||
MENUEVENT_PLUS, /* Item has been modified in positive direction
|
||||
(slider moved) */
|
||||
MENUEVENT_MINUS /* Item has been modified in negative direction
|
||||
(slider moved) */
|
||||
} MenuEventType;
|
||||
|
||||
menu_item OptionsMenu[] = {
|
||||
"OPTIONS", TYPE_TITL, 0, // Title
|
||||
"24-hour Time", TYPE_CHEK, (void *)Time24_func,
|
||||
"Contrast...", TYPE_SLID, (void *)Contrast_func,
|
||||
0, 0, 0,
|
||||
};
|
||||
#define EventFunc(f) MenuEventFuncResult (f) (void *object, MenuEventType event)
|
||||
|
||||
///////////////// Elsewhere, we declare these...
|
||||
typedef struct MenuItem {
|
||||
int type; /* Type as defined above */
|
||||
char *id; /* Internal name for client supplied menus */
|
||||
EventFunc (*event_func);
|
||||
/* Defines event_func to be an event function */
|
||||
union data {
|
||||
struct menu {
|
||||
char *text; /* Visible name of the submenu */
|
||||
int current_item_index; /* At what menuitem is the selector */
|
||||
struct MenuItem *parent; /* Parent of this menu */
|
||||
LinkedList *contents; /* What's in this menu */
|
||||
} menu;
|
||||
struct checkbox {
|
||||
char *text; /* Visible name of item */
|
||||
CheckboxValue value; /* Current value */
|
||||
int allowgray; /* is CHECKBOX_GRAY allowed ? */
|
||||
} checkbox;
|
||||
struct slider {
|
||||
char *text; /* Visible name of item */
|
||||
char *lefttext; /* Text at minimal value */
|
||||
char *righttext;/* Text at minimal value */
|
||||
int value; /* Current value */
|
||||
int minvalue;
|
||||
int maxvalue;
|
||||
int stepsize;
|
||||
} slider;
|
||||
struct numeric {
|
||||
char *text; /* Visible name of item */
|
||||
int value; /* Current value */
|
||||
int maxvalue;
|
||||
int minvalue;
|
||||
} numeric;
|
||||
struct string {
|
||||
char *text; /* Visible name of item */
|
||||
char *value; /* Current value (in a buffer) */
|
||||
char passwordchar; /* For passwords */
|
||||
int maxlength;
|
||||
} string;
|
||||
struct password {
|
||||
char *text; /* Visible name of item */
|
||||
char *value; /* Current value (in a buffer) */
|
||||
int maxlength; /* Max allowed length */
|
||||
} password;
|
||||
} data;
|
||||
} MenuItem;
|
||||
|
||||
void Shutdown_func()
|
||||
#define Menu MenuItem
|
||||
/* A Menu is a MenuItem too.
|
||||
* This definition is only for better understanding of this code.
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* Functions to use the menustuff
|
||||
*/
|
||||
|
||||
MenuItem *menu_create_add_item (Menu *into_menu, int type, char *name,
|
||||
EventFunc(*event_func));
|
||||
/* Creates a new item and adds it to the given menu.
|
||||
* All attributes if the new item are cleared.
|
||||
* into_menu What menu should it be in.
|
||||
* type: type as defined above (determines also how the attributes will
|
||||
* be filled).
|
||||
* name: internal name of the item. Never visible. String will be
|
||||
* copied.
|
||||
* event_func: the event function that should be called upon actions on this
|
||||
* item. see event.h.
|
||||
* The data part of the new item is filled with 0's.
|
||||
*
|
||||
* Return value: the new item, of NULL on error.
|
||||
*
|
||||
* If you create a new menu, the menu data will automatically be allocated,
|
||||
* and the contents pointer set to this menu.
|
||||
*
|
||||
* To initialize data for the data part, do things like:
|
||||
*
|
||||
* yourname = menu_create_add_item (m, MENUITEM_STRING_INPUT, "YourName",
|
||||
* yourname_change_handler);
|
||||
* yourname->data.text = strdup ("Your name");
|
||||
* yourname->data.maxlength = 10;
|
||||
* yourname->data.value = malloc (10+1); <--- maxlength + 1
|
||||
* yourname->data.value[0] = 0; <--- clear the string
|
||||
*
|
||||
* The data NEEDS to be initialized immediately (at least before it's first
|
||||
* used).
|
||||
*
|
||||
*/
|
||||
|
||||
int menu_destroy_item (Menu *menu, MenuItem *item);
|
||||
/* Deletes item from menu and removes item from memory
|
||||
*
|
||||
* If the item is a menu, the menu data will also be deallocated.
|
||||
*
|
||||
* Return value: 0 for OK, -1 for error (eg. submenus not empty)
|
||||
*
|
||||
* To destroy the data in the data struct, do things like:
|
||||
*
|
||||
* free (yourname->data.value);
|
||||
* free (yourname->data.text);
|
||||
* menu_destroy_item (yourname);
|
||||
*/
|
||||
|
||||
static inline MenuItem *menu_getfirst_item (Menu *menu)
|
||||
/* Retrieves the first item from the list of items in the menu. */
|
||||
{
|
||||
// Do something here...
|
||||
return MENU_KILL; // or MENU_CLOSE, or MENU_OK, or MENU_ERROR
|
||||
return (MenuItem*) LL_GetFirst( menu->data.menu.contents );
|
||||
}
|
||||
|
||||
int Time24_func(int input)
|
||||
static inline MenuItem *menu_getnext_item (Menu *menu)
|
||||
/* Retrieves the next item from the list of items in the menu.
|
||||
* No other menu calls should be made between menu_first_item() and
|
||||
* this function, to keep the list-cursor where it is. */
|
||||
{
|
||||
if(input == MENU_READ) return status;
|
||||
if(input == MENU_CHECK) toggle_status(); // does something.
|
||||
return (status | MENU_OK);
|
||||
// The status is "or"-ed with the MENU value to let do_menu()
|
||||
// know what to do after selecting the item. (two return
|
||||
// values in one. :)
|
||||
|
||||
// Also, "MENU_OK" happens to be zero, so it does not matter
|
||||
// unless you want something else (like MENU_CLOSE)
|
||||
return (MenuItem*) LL_GetNext( menu->data.menu.contents );
|
||||
}
|
||||
|
||||
int Contrast_func(int input)
|
||||
{
|
||||
if(input == MENU_READ) return status;
|
||||
if(input == MENU_PLUS) increment_status(); // does something.
|
||||
if(input == MENU_MINUS) decrement_status();// does something.
|
||||
return (status | MENU_OK);
|
||||
}
|
||||
MenuItem *menu_find_item (Menu *menu, char *id);
|
||||
/* Retrieves the first item from the list of items in the menu. */
|
||||
|
||||
=====================================================================
|
||||
void menu_build_screen (MenuItem *item, Screen *s);
|
||||
/* Builds the selected menuitem on screen using widgets
|
||||
* Returns the initial state.
|
||||
*/
|
||||
|
||||
Function return values:
|
||||
MENU_OK Keeps menu open.
|
||||
MENU_CLOSE Closes menu after item is picked.
|
||||
Leaves the parent menus open.
|
||||
MENU_QUIT Closes all menus after item is picked.
|
||||
Like a normal pulldown menu.
|
||||
MENU_KILL Same as MENU_QUIT, so far.
|
||||
MENU_ERROR Um, for errors? :)
|
||||
|
||||
Also, functions for sliders and checkboxes should return a status value
|
||||
binary OR-ed with the MENU_ return value. Checkboxes should return 0 or 1,
|
||||
and sliders should return 0-255.
|
||||
|
||||
**************************************************************************/
|
||||
#endif
|
||||
|
||||
/* Return codes from selected menu items...*/
|
||||
#define MENU_ERROR -0x7FFF0000
|
||||
#define MENU_OK 0
|
||||
#define MENU_CLOSE 0x10000
|
||||
#define MENU_QUIT 0x20000
|
||||
#define MENU_KILL 0x20000
|
||||
|
||||
/* Menu item Types...*/
|
||||
#define TYPE_TITL 0
|
||||
#define TYPE_MENU 1
|
||||
#define TYPE_FUNC 2
|
||||
#define TYPE_CHEK 3
|
||||
#define TYPE_SLID 4
|
||||
#define TYPE_MOVE 5
|
||||
|
||||
#define CLIENT_MENU 0x100
|
||||
#define CLIENT_FUNC 0x101
|
||||
#define CLIENT_CHEK 0x102
|
||||
#define CLIENT_SLID 0x103
|
||||
#define CLIENT_MOVE 0x104
|
||||
|
||||
/* User actions, sent to item-handling functions as input.*/
|
||||
#define MENU_SELECT 1
|
||||
#define MENU_CHECK 2
|
||||
#define MENU_PLUS 3
|
||||
#define MENU_MINUS 4
|
||||
#define MENU_READ 5
|
||||
|
||||
typedef struct menu_item {
|
||||
char *text;
|
||||
int type;
|
||||
void *data;
|
||||
} menu_item;
|
||||
|
||||
#define Menu menu_item *
|
||||
|
||||
int do_menu (Menu menu);
|
||||
void menu_update_screen (MenuItem *item, Screen *s);
|
||||
/* Updates the widgets of the selected menuitem
|
||||
* Returns the new state.
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user