Adding debian version 3.35-1.
[syslinux-debian/hramrach.git] / menu / libmenu / menu.h
blob446b3adba5cc3438a2357fee8993bdacfa734ee9
1 /* -*- c -*- ------------------------------------------------------------- *
3 * Copyright 2004-2005 Murali Krishnan Ganapathy - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
13 /* This program can be compiled for DOS with the OpenWatcom compiler
14 * (http://www.openwatcom.org/):
16 * wcl -3 -osx -mt <filename>.c
19 #ifndef __MENU_H__
20 #define __MENU_H__
22 #include "com32io.h"
23 #include "tui.h"
24 #include "syslnx.h"
25 #include "scancodes.h"
26 #include <string.h>
28 // TIMEOUT PARAMETERS
29 /* If no key is pressed within TIMEOUTNUMSTEPS * TIMEOUTSTEPSIZE milliseconds
30 and if a timeout handler is registered, then that will be called.
31 The handler should either either take control from there on, or return without
32 producing any change in the current video settings.
34 For e.g. the handler could
35 * Could just quit the menu program
36 * beep and return.
38 TIMEOUTSTEPSIZE is the interval for which the program sleeps without checking for
39 any keystroke. So increasing this will make the response of the system slow.
40 Decreasing this will make a lot of interrupt calls using up your CPU. Default
41 value of TIMEOUTSTEPSIZE of 0.1 seconds should be right in most cases.
43 TIMEOUTNUMSTEPS of 3000 corresponds to a wait time of 300 seconds or 5 minutes
46 #define TIMEOUTSTEPSIZE 10
47 #define TIMEOUTNUMSTEPS 30000L
49 // Attributes
50 #define NORMALATTR 0x17
51 #define NORMALHLITE 0x1F // Normal Highlight attribute
52 #define REVERSEATTR 0x70
53 #define REVERSEHLITE 0x78 // Reverse Hightlight attribute
54 #define INACTATTR 0x18
55 #define INACTHLITE 0x10 // Inactive Highlight attribute
56 #define REVINACTATTR 0x78
57 #define REVINACTHLITE 0x70 // Reverse Inactive Highlight attr
59 #define STATUSATTR 0x74
60 #define STATUSHLITE 0x7B // Status highlight
62 #define FILLCHAR 177
63 #define FILLATTR 0x01
64 #define SHADOWATTR 0x00
65 #define SPACECHAR ' '
67 #define TFILLCHAR ' '
68 #define TITLEATTR 0x70
70 #define ENABLEHLITE '<' // Char which turns on highlight
71 #define DISABLEHLITE '>' // Char which turns off highlight
72 #define NOHLITE 0 // The offset into attrib array for non-hilite
73 #define HLITE 1 // The offset for Hlite attrib
75 #define MOREABOVE 24 // char to print when more menu items available above
76 #define MOREBELOW 25 // more items available below
77 #define SCROLLBOX 176 // Filled char to display
79 // Attributes of the menu system
80 #define MAXMENUS 10 // Maximum number of menu's allowed
81 #define MAXMENUSIZE 30 // Default value for max num of entries in each menu
82 #define MAXMENUHEIGHT 14 // Maximum number of entries displayed
83 #define MENUBOXTYPE BOX_SINSIN // Default box type Look at tui.h for other values
85 // Upper bounds on lengths
86 // We copy the given string, so user can reuse the space used to store incoming arguments.
87 #define MENULEN 40 // Each menu entry is atmost MENULEN chars
88 #define STATLEN 80 // Maximum length of status string
89 #define TITLELEN 80 // Maximum length of title string
90 #define ACTIONLEN 255 // Maximum length of an action string
92 // Layout of menu
93 #define MENUROW 3 // Row where menu is displayed (relative to window)
94 #define MENUCOL 4 // Col where menu is displayed (relative to window)
95 #define MENUPAGE 1 // show in display page 1
96 #define STATLINE 24 // Line number where status line starts (relative to window)
98 // Used for printing debugging messages
99 #define DEBUGLINE 23 // debugging info goes here
101 // Other Chars
102 #define SUBMENUCHAR 175 // This is >> symbol
103 #define RADIOMENUCHAR '>' // > symbol for radio menu?
104 #define EXITMENUCHAR 174 // This is << symbol
105 #define CHECKED 251 // Check mark
106 #define UNCHECKED 250 // Light bullet
107 #define RADIOSEL '.' // Current Radio Selection
108 #define RADIOUNSEL ' ' // Radio option not selected
110 typedef unsigned char uchar;
112 // Types of menu's
113 #define NORMALMENU 1
114 #define RADIOMENU 2
116 typedef enum {OPT_INACTIVE, OPT_SUBMENU, OPT_RUN, OPT_EXITMENU, OPT_CHECKBOX,
117 OPT_RADIOMENU, OPT_SEP, OPT_INVISIBLE,
118 OPT_RADIOITEM} t_action;
120 typedef union {
121 uchar submenunum; // For submenu's
122 uchar checked; // For check boxes
123 uchar radiomenunum; // Item mapping to a radio menu
124 } t_itemdata;
126 struct s_menuitem;
127 struct s_menu;
128 struct s_menusystem;
130 typedef struct {
131 unsigned int valid :1; // Is action valid?
132 unsigned int refresh:1; // Should we recompute menu stuff?
133 unsigned int reserved:6; // For future expansion
134 } t_handler_return;
136 t_handler_return ACTION_VALID,ACTION_INVALID; // Specific values
138 typedef t_handler_return (*t_item_handler)(struct s_menusystem *, struct s_menuitem *);
139 typedef void (*t_menusystem_handler)(struct s_menusystem *, struct s_menuitem *);
140 typedef void (*t_keys_handler)(struct s_menusystem *, struct s_menuitem *,
141 unsigned int scancode);
142 // Last parameter = HIGH BYTE = scan code , LOW BYTE = ASCII CODE
144 typedef enum {HDLR_SCREEN, HDLR_KEYS } t_handler;
145 // Types of handlers for menu system
147 // TIMEOUT is the list of possible values which can be returned by the handler
148 // instructing the menusystem what to do. The default is CODE_WAIT
149 typedef enum {CODE_WAIT, CODE_ENTER, CODE_ESCAPE } TIMEOUTCODE;
150 typedef TIMEOUTCODE (*t_timeout_handler)(void);
152 typedef struct s_menuitem {
153 char *item;
154 char *status;
155 char *data; // string containing kernel to run.. but...
156 // for radio menu's this is a pointer to the item selected or NULL (initially)
157 // for submenu's this string could be name of menu
158 void * extra_data; // Any other data user can point to
159 unsigned int helpid; // Used for Context sensitive help
160 t_item_handler handler; // Pointer to function of type menufn
161 t_action action;
162 t_itemdata itemdata; // Data depends on action value
163 uchar shortcut; // one of [A-Za-z0-9] shortcut for this menu item
164 uchar index; // Index within the menu array
165 uchar parindex; // Index of the menu in which this item appears.
167 } t_menuitem;
169 typedef t_menuitem *pt_menuitem; // Pointer to type menuitem
171 typedef struct s_menu {
172 pt_menuitem *items; // pointer to array of pointer to menuitems
173 char *title; // Title string for menu
174 char *name; // menu can be referred to by this string
175 int maxmenusize; // the size of array allocated
176 uchar numitems; // how many items do we actually have
177 uchar menuwidth;
178 uchar row,col; // Position where this menu should be displayed
179 uchar menuheight; // Maximum number of items to be displayed
180 } t_menu;
182 typedef t_menu *pt_menu; // Pointer to type menu
184 typedef struct s_menusystem {
185 pt_menu menus[MAXMENUS];
186 char *title;
187 t_menusystem_handler handler; // Menu system handler
188 t_keys_handler keys_handler; // Handler for unknown keys
189 t_timeout_handler ontimeout; // Timeout handler
190 unsigned long tm_numsteps;
191 // Time to wait for key press=numsteps * stepsize milliseconds
192 unsigned int tm_stepsize; // Timeout step size (in milliseconds)
193 // Total timeout max time spent idle before we call handler
194 unsigned long tm_total_timeout; // (in milli seconds)
195 unsigned long tm_sofar_timeout; // All accumulated timeout
196 // total timeout handler
197 t_timeout_handler ontotaltimeout; // Total timeout handler
199 int maxmenuheight;
200 uchar nummenus;
201 uchar normalattr[2]; // [0] is non-hlite attr, [1] is hlite attr
202 uchar reverseattr[2];
203 uchar inactattr[2];
204 uchar revinactattr[2];
205 uchar statusattr[2];
206 uchar fillchar;
207 uchar fillattr;
208 uchar spacechar;
209 uchar tfillchar;
210 uchar titleattr;
211 uchar shadowattr;
212 uchar statline;
213 uchar menupage;
214 uchar maxrow,minrow,numrows; // Number of rows in the window
215 uchar maxcol,mincol,numcols; // Number of columns in the window
217 // Menu box look
218 boxtype menubt; // What type of boxes should be drawn
219 char box_horiz,box_ltrt,box_rtlt; // Some chars of the box, for redrawing portions of the box
221 } t_menusystem;
223 typedef t_menusystem *pt_menusystem; // Pointer to type menusystem
225 pt_menuitem showmenus(uchar startmenu);
227 pt_menusystem init_menusystem(const char *title);
229 void close_menusystem(); // Deallocate memory used
231 void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected);
233 void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected);
235 void set_status_info(uchar statusattr, uchar statushlite, uchar statline);
237 void set_title_info(uchar tfillchar, uchar titleattr);
239 void set_misc_info(uchar fillchar, uchar fillattr,uchar spacechar, uchar shadowattr);
240 void set_box_type(boxtype bt);
242 void set_window_size(uchar top, uchar left, uchar bot, uchar right); // Set the window which menusystem should use
244 void set_menu_options(uchar maxmenuheight);
245 // maximum height of a menu
247 void reg_handler(t_handler htype, void * handler); // Register handler
249 void unreg_handler( t_handler htype);
251 void reg_ontimeout(t_timeout_handler, unsigned int numsteps, unsigned int stepsize);
252 // Set timeout handler, set 0 for default values.
253 // So stepsize=0 means numsteps is measured in centiseconds.
254 void unreg_ontimeout();
256 void reg_ontotaltimeout(t_timeout_handler, unsigned long numcentiseconds);
257 void unreg_ontotaltimeout();
259 // Find the number of the menu given the name
260 // Returns -1 if not found
261 uchar find_menu_num(const char *name);
263 // Create a new menu and return its position
264 uchar add_menu(const char *title, int maxmenusize);
266 // Create a named menu and return its position
267 uchar add_named_menu(const char *name, const char *title, int maxmenusize);
269 void set_menu_pos(uchar row,uchar col); // Set the position of this menu.
271 // Add item to the "current" menu
272 pt_menuitem add_item(const char *item, const char *status, t_action action, const char *data, uchar itemdata);
274 // Set shortcut key and help id
275 void set_item_options(uchar shortcut,int helpid);
277 // Set the shortcut key for the current item
278 static inline void set_shortcut(uchar shortcut)
280 set_item_options(shortcut,0xFFFF);
283 // Add a separator to the "current" menu
284 pt_menuitem add_sep();
286 // Generate string based on state of checkboxes and radioitem in given menu
287 // and append string to existing contents of "line"
288 // line must have enough space allocated
289 void gen_append_line(const char *menu_name,char *line);
291 #endif