syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / menu / libmenu / menu.h
1 /* -*- c -*- ------------------------------------------------------------- *
2  *
3  *   Copyright 2004-2005 Murali Krishnan Ganapathy - All Rights Reserved
4  *
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.
10  *
11  * ----------------------------------------------------------------------- */
12
13 /* This program can be compiled for DOS with the OpenWatcom compiler
14  * (http://www.openwatcom.org/):
15  *
16  * wcl -3 -osx -mt <filename>.c
17  */
18
19 #ifndef __MENU_H__
20 #define __MENU_H__
21
22 #include "com32io.h"
23 #include "tui.h"
24 #include "syslnx.h"
25 #include "scancodes.h"
26 #include <string.h>
27
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.
33
34    For e.g. the handler could
35    * Could just quit the menu program
36    * beep and return.
37
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.
42
43    TIMEOUTNUMSTEPS of 3000 corresponds to a wait time of 300 seconds or 5 minutes
44 */
45
46 #define TIMEOUTSTEPSIZE 10  
47 #define TIMEOUTNUMSTEPS 30000L
48
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
58
59 #define STATUSATTR    0x74
60 #define STATUSHLITE   0x7B // Status highlight
61
62 #define FILLCHAR      177
63 #define FILLATTR      0x01
64 #define SHADOWATTR    0x00
65 #define SPACECHAR     ' '
66
67 #define TFILLCHAR     ' '
68 #define TITLEATTR     0x70
69
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
74
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
78
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
84
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
91
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 HELPPAGE      2  // Use this page for any additional information
97 #define STATLINE      24 // Line number where status line starts (relative to window)
98
99 // Used for printing debugging messages
100 #define DEBUGLINE     23  // debugging info goes here
101
102 // Other Chars
103 #define SUBMENUCHAR   175 // This is >> symbol
104 #define RADIOMENUCHAR '>' // > symbol for radio menu? 
105 #define EXITMENUCHAR  174 // This is << symbol
106 #define CHECKED       251 // Check mark
107 #define UNCHECKED     250 // Light bullet
108 #define RADIOSEL      '.' // Current Radio Selection 
109 #define RADIOUNSEL    ' ' // Radio option not selected
110
111 typedef unsigned char uchar;
112
113 // Types of menu's
114 #define NORMALMENU 1 
115 #define RADIOMENU  2
116
117 typedef enum {OPT_INACTIVE, OPT_SUBMENU, OPT_RUN, OPT_EXITMENU, OPT_CHECKBOX,
118               OPT_RADIOMENU, OPT_SEP, OPT_INVISIBLE,
119               OPT_RADIOITEM} t_action;
120
121 typedef union {
122   uchar submenunum; // For submenu's
123   uchar checked; // For check boxes
124   uchar radiomenunum; // Item mapping to a radio menu
125 } t_itemdata;
126
127 struct s_menuitem;
128 struct s_menu;
129 struct s_menusystem;
130
131 typedef struct {
132    unsigned int valid :1; // Is action valid?
133    unsigned int refresh:1; // Should we recompute menu stuff?
134    unsigned int reserved:6; // For future expansion
135 } t_handler_return;
136
137 t_handler_return ACTION_VALID,ACTION_INVALID; // Specific values 
138
139 typedef t_handler_return (*t_item_handler)(struct s_menusystem *, struct s_menuitem *);
140 typedef void (*t_menusystem_handler)(struct s_menusystem *, struct s_menuitem *);
141 typedef void (*t_keys_handler)(struct s_menusystem *, struct s_menuitem *,
142               unsigned int scancode); 
143     // Last parameter = HIGH BYTE = scan code , LOW BYTE = ASCII CODE
144
145 typedef enum {HDLR_SCREEN, HDLR_KEYS } t_handler; 
146 // Types of handlers for menu system 
147
148 // TIMEOUT is the list of possible values which can be returned by the handler
149 // instructing the menusystem what to do. The default is CODE_WAIT
150 typedef enum {CODE_WAIT, CODE_ENTER, CODE_ESCAPE } TIMEOUTCODE;
151 typedef TIMEOUTCODE (*t_timeout_handler)(void);
152
153 typedef struct s_menuitem {
154   char *item;
155   char *status;
156   char *data; // string containing kernel to run.. but... 
157   // for radio menu's this is a pointer to the item selected or NULL (initially)
158   void * extra_data; // Any other data user can point to
159   t_item_handler handler; // Pointer to function of type menufn
160   t_action action;
161   t_itemdata itemdata; // Data depends on action value
162   unsigned int helpid; // context sensitive help system ID
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. 
166 } t_menuitem;
167
168 typedef t_menuitem *pt_menuitem; // Pointer to type menuitem
169
170 typedef struct s_menu {
171   pt_menuitem *items; // pointer to array of pointer to menuitems
172   char *title;
173   int maxmenusize; // the size of array allocated
174   uchar numitems; // how many items do we actually have
175   uchar menuwidth;
176   uchar row,col; // Position where this menu should be displayed
177   uchar menuheight; // Maximum number of items to be displayed
178 } t_menu;
179
180 typedef t_menu *pt_menu; // Pointer to type menu
181
182 typedef struct s_menusystem {
183   pt_menu menus[MAXMENUS];
184   char *title; 
185   t_menusystem_handler handler; // Menu system handler 
186   t_keys_handler keys_handler; // Handler for unknown keys
187   t_timeout_handler ontimeout; // Timeout handler
188   unsigned long tm_numsteps; 
189   // Time to wait for key press=numsteps * stepsize milliseconds
190   unsigned int tm_stepsize; // Timeout step size (in milliseconds)
191
192   int maxmenuheight;
193   uchar nummenus;
194   uchar normalattr[2]; // [0] is non-hlite attr, [1] is hlite attr
195   uchar reverseattr[2];
196   uchar inactattr[2];
197   uchar revinactattr[2];
198   uchar statusattr[2];
199   uchar fillchar;
200   uchar fillattr;
201   uchar spacechar;
202   uchar tfillchar;
203   uchar titleattr;
204   uchar shadowattr;
205   uchar statline;
206   uchar menupage;
207   uchar maxrow,minrow,numrows; // Number of rows in the window 
208   uchar maxcol,mincol,numcols; // Number of columns in the window
209
210   // Menu box look
211   boxtype menubt; // What type of boxes should be drawn 
212   char box_horiz,box_ltrt,box_rtlt; // Some chars of the box, for redrawing portions of the box
213
214 } t_menusystem;
215
216 typedef t_menusystem *pt_menusystem; // Pointer to type menusystem
217
218 /************************************************************************
219  * IMPORTANT INFORMATION
220  *
221  * All functions which take a string as argument store the pointer
222  * for later use. So if you have alloc'ed a space for the string
223  * and are passing it to any of these functions, DO NOT deallocate it.
224  *
225  * If they are constant strings, you may receive warning from the compiler
226  * about "converting from char const * to char *". Ignore these errors.
227  *
228  * This hack/trick of storing these pointers will help in reducing the size
229  * of the internal structures by a lot.
230  *
231  ***************************************************************************
232  */
233
234 pt_menuitem showmenus(uchar startmenu);
235
236 pt_menusystem init_menusystem(const char *title); 
237 void close_menusystem(); // Deallocate memory used
238
239 void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected);
240
241 void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected);
242
243 void set_status_info(uchar statusattr, uchar statushlite, uchar statline);
244
245 void set_title_info(uchar tfillchar, uchar titleattr);
246
247 void set_misc_info(uchar fillchar, uchar fillattr,uchar spacechar, uchar shadowattr);
248 void set_box_type(boxtype bt);
249
250 void set_window_size(uchar top, uchar left, uchar bot, uchar right); // Set the window which menusystem should use
251
252 void set_menu_options(uchar maxmenuheight); 
253 // maximum height of a menu
254
255 void reg_handler(t_handler htype, void * handler); // Register handler
256
257 void unreg_handler( t_handler htype); 
258
259 void reg_ontimeout(t_timeout_handler, unsigned int numsteps, unsigned int stepsize); 
260 // Set timeout handler, set 0 for default values.
261 // So stepsize=0 means numsteps is measured in centiseconds.
262 void unreg_ontimeout();
263
264 // Create a new menu and return its position
265 uchar add_menu(const char *title, int maxmenusize); 
266
267 void set_menu_pos(uchar row,uchar col); // Set the position of this menu.
268
269 // Add item to the "current" menu 
270 pt_menuitem add_item(const char *item, const char *status, t_action action, const char *data, uchar itemdata);
271
272 // Set shortcut key and help id
273 void set_item_options(uchar shortcut,int helpid);
274
275 // Set the shortcut key for the current item
276 static inline void set_shortcut(uchar shortcut) 
277
278   set_item_options(shortcut,0xFFFF);
279 }
280
281 // Add a separator to the "current" menu
282 pt_menuitem add_sep();
283
284 // Main function for the user's config file
285 int menumain(char *cmdline);
286
287 #endif