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
25 #include "scancodes.h"
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
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
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
64 #define SHADOWATTR 0x00
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
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)
99 // Used for printing debugging messages
100 #define DEBUGLINE 23 // debugging info goes here
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
111 typedef unsigned char uchar;
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;
122 uchar submenunum; // For submenu's
123 uchar checked; // For check boxes
124 uchar radiomenunum; // Item mapping to a radio menu
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
137 t_handler_return ACTION_VALID,ACTION_INVALID; // Specific values
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
145 typedef enum {HDLR_SCREEN, HDLR_KEYS } t_handler;
146 // Types of handlers for menu system
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);
153 typedef struct s_menuitem {
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
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.
168 typedef t_menuitem *pt_menuitem; // Pointer to type menuitem
170 typedef struct s_menu {
171 pt_menuitem *items; // pointer to array of pointer to menuitems
173 int maxmenusize; // the size of array allocated
174 uchar numitems; // how many items do we actually have
176 uchar row,col; // Position where this menu should be displayed
177 uchar menuheight; // Maximum number of items to be displayed
180 typedef t_menu *pt_menu; // Pointer to type menu
182 typedef struct s_menusystem {
183 pt_menu menus[MAXMENUS];
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)
194 uchar normalattr[2]; // [0] is non-hlite attr, [1] is hlite attr
195 uchar reverseattr[2];
197 uchar revinactattr[2];
207 uchar maxrow,minrow,numrows; // Number of rows in the window
208 uchar maxcol,mincol,numcols; // Number of columns in the window
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
216 typedef t_menusystem *pt_menusystem; // Pointer to type menusystem
218 /************************************************************************
219 * IMPORTANT INFORMATION
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.
225 * If they are constant strings, you may receive warning from the compiler
226 * about "converting from char const * to char *". Ignore these errors.
228 * This hack/trick of storing these pointers will help in reducing the size
229 * of the internal structures by a lot.
231 ***************************************************************************
234 pt_menuitem showmenus(uchar startmenu);
236 pt_menusystem init_menusystem(const char *title);
237 void close_menusystem(); // Deallocate memory used
239 void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected);
241 void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected);
243 void set_status_info(uchar statusattr, uchar statushlite, uchar statline);
245 void set_title_info(uchar tfillchar, uchar titleattr);
247 void set_misc_info(uchar fillchar, uchar fillattr,uchar spacechar, uchar shadowattr);
248 void set_box_type(boxtype bt);
250 void set_window_size(uchar top, uchar left, uchar bot, uchar right); // Set the window which menusystem should use
252 void set_menu_options(uchar maxmenuheight);
253 // maximum height of a menu
255 void reg_handler(t_handler htype, void * handler); // Register handler
257 void unreg_handler( t_handler htype);
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();
264 // Create a new menu and return its position
265 uchar add_menu(const char *title, int maxmenusize);
267 void set_menu_pos(uchar row,uchar col); // Set the position of this menu.
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);
272 // Set shortcut key and help id
273 void set_item_options(uchar shortcut,int helpid);
275 // Set the shortcut key for the current item
276 static inline void set_shortcut(uchar shortcut)
278 set_item_options(shortcut,0xFFFF);
281 // Add a separator to the "current" menu
282 pt_menuitem add_sep();
284 // Main function for the user's config file
285 int menumain(char *cmdline);