Home | History | Annotate | Line # | Download | only in libmenu
menu.h revision 1.1
      1 /*      $Id: menu.h,v 1.1 1999/11/23 11:12:34 blymn Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1998-1999 Brett Lymn (blymn (at) baea.com.au, brett_lymn (at) yahoo.com)
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. The name of the author may not be used to endorse or promote products
     13  *    derived from this software withough specific prior written permission
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  *
     26  *
     27  */
     28 
     29 #include <curses.h>
     30 #include <eti.h>
     31 
     32 #ifndef MENU_H
     33 #define MENU_H 1
     34 
     35 /* the following is a hack to define attr_t until the curses lib
     36    does it officially */
     37 #ifndef CURSES_V3
     38 typedef char attr_t;
     39 #endif
     40 
     41 /* requests for the menu_driver call */
     42 #define REQ_BASE_NUM      (0x100)
     43 #define REQ_LEFT_ITEM     (0x101)
     44 #define REQ_RIGHT_ITEM    (0x102)
     45 #define REQ_UP_ITEM       (0x103)
     46 #define REQ_DOWN_ITEM     (0x104)
     47 #define REQ_SCR_ULINE     (0x105)
     48 #define REQ_SCR_DLINE     (0x106)
     49 #define REQ_SCR_DPAGE     (0x107)
     50 #define REQ_SCR_UPAGE     (0x108)
     51 #define REQ_FIRST_ITEM    (0x109)
     52 #define REQ_LAST_ITEM     (0x10a)
     53 #define REQ_NEXT_ITEM     (0x10b)
     54 #define REQ_PREV_ITEM     (0x10c)
     55 #define REQ_TOGGLE_ITEM   (0x10d)
     56 #define REQ_CLEAR_PATTERN (0x10e)
     57 #define REQ_BACK_PATTERN  (0x10f)
     58 #define REQ_NEXT_MATCH    (0x110)
     59 #define REQ_PREV_MATCH    (0x111)
     60 
     61 #define MAX_COMMAND       (0x111) /* last menu driver request - for application
     62 				     defined commands */
     63 
     64 /* Menu options */
     65 typedef unsigned int OPTIONS;
     66 
     67 /* and the values they can have */
     68 #define O_ONEVALUE   (0x1)
     69 #define O_SHOWDESC   (0x2)
     70 #define O_ROWMAJOR   (0x4)
     71 #define O_IGNORECASE (0x8)
     72 #define O_SHOWMATCH  (0x10)
     73 #define O_NONCYCLIC  (0x20)
     74 #define O_SELECTABLE (0x40)
     75 
     76 typedef struct __menu_str {
     77         char *string;
     78         int length;
     79 } MENU_STR;
     80 
     81 typedef struct __menu MENU;
     82 typedef struct __item ITEM;
     83 
     84 typedef void (*_menui_menu_hook) (MENU *);
     85 
     86 struct __item {
     87         MENU_STR name;
     88         MENU_STR description;
     89         char *userptr;
     90         int visible;  /* set if item is visible */
     91         int selected; /* set if item has been selected */
     92 	int row; /* menu row this item is on */
     93 	int col; /* menu column this item is on */
     94         OPTIONS opts;
     95         MENU *parent; /* menu this item is bound to */
     96 	int index; /* index number for this item, if attached */
     97 	  /* The following are the item's neighbours - makes menu
     98 	     navigation easier */
     99 	ITEM *left;
    100 	ITEM *right;
    101 	ITEM *up;
    102 	ITEM *down;
    103 };
    104 
    105 struct __menu {
    106         int rows; /* max number of rows to be displayed */
    107         int cols; /* max number of columns to be displayed */
    108 	int item_rows; /* number of item rows we have */
    109 	int item_cols; /* number of item columns we have */
    110         int cur_row; /* current cursor row */
    111         int cur_col; /* current cursor column */
    112         MENU_STR mark; /* menu mark string */
    113         MENU_STR unmark; /* menu unmark string */
    114         OPTIONS opts; /* options for the menu */
    115         char *pattern; /* the pattern buffer */
    116 	int plen;  /* pattern buffer length */
    117 	int match_len; /* length of pattern matched */
    118         int posted; /* set if menu is posted */
    119         attr_t fore; /* menu foreground */
    120         attr_t back; /* menu background */
    121         attr_t grey; /* greyed out (nonselectable) menu item */
    122         int pad;  /* filler char between name and description */
    123         char *userptr;
    124 	int top_row; /* the row that is at the top of the menu */
    125 	int max_item_width; /* widest item */
    126 	int col_width; /* width of the menu columns - this is not always
    127 			  the same as the widest item */
    128         int item_count; /* number of items attached */
    129         ITEM **items; /* items associated with this menu */
    130         int  cur_item; /* item cursor is currently positioned at */
    131         int in_init; /* set when processing an init or term function call */
    132         _menui_menu_hook menu_init; /* call this when menu is posted */
    133         _menui_menu_hook menu_term; /* call this when menu is unposted */
    134         _menui_menu_hook item_init; /* call this when menu posted & after
    135 				       current item changes */
    136         _menui_menu_hook item_term; /* call this when menu unposted & just
    137 				       before current item changes */
    138         WINDOW *menu_win; /* the menu window */
    139         WINDOW *menu_subwin; /* the menu subwindow */
    140 	int we_created;
    141 };
    142 
    143 
    144 /* Public function prototypes. */
    145 __BEGIN_DECLS
    146 int  menu_driver __P((MENU *, int));
    147 int scale_menu __P((MENU *, int *, int *));
    148 int set_top_row __P((MENU *, int));
    149 int pos_menu_cursor __P((MENU *));
    150 int top_row __P((MENU *));
    151 
    152 int  free_menu __P((MENU *));
    153 char menu_back __P((MENU *));
    154 char menu_fore __P((MENU *));
    155 void menu_format __P((MENU *, int *, int *));
    156 char menu_grey __P((MENU *));
    157 _menui_menu_hook menu_init __P((MENU *));
    158 char *menu_mark __P((MENU *));
    159 OPTIONS menu_opts __P((MENU *));
    160 int menu_opts_off __P((MENU *, OPTIONS));
    161 int menu_opts_on __P((MENU *, OPTIONS));
    162 int menu_pad __P((MENU *));
    163 char *menu_pattern __P((MENU *));
    164 WINDOW *menu_sub __P((MENU *));
    165 _menui_menu_hook menu_term __P((MENU *));
    166 char *menu_unmark __P((MENU *));
    167 char *menu_userptr __P((MENU *));
    168 WINDOW *menu_win __P((MENU *));
    169 MENU *new_menu __P((ITEM **));
    170 int post_menu __P((MENU *));
    171 int set_menu_back __P((MENU *, attr_t));
    172 int set_menu_fore __P((MENU *, attr_t));
    173 int set_menu_format __P((MENU *, int, int));
    174 int set_menu_grey __P((MENU *, attr_t));
    175 int set_menu_init __P((MENU *, _menui_menu_hook));
    176 int set_menu_items __P((MENU *, ITEM **));
    177 int set_menu_mark __P((MENU *, char *));
    178 int set_menu_opts __P((MENU *, OPTIONS));
    179 int set_menu_pad __P((MENU *, int));
    180 int set_menu_pattern __P((MENU *, char *));
    181 int  set_menu_sub __P((MENU *, WINDOW *));
    182 int set_menu_term __P((MENU *, _menui_menu_hook));
    183 int set_menu_unmark __P((MENU *, char *));
    184 int set_menu_userptr __P((MENU *, char *));
    185 int  set_menu_win __P((MENU *, WINDOW *));
    186 int unpost_menu __P((MENU *));
    187 
    188 ITEM *current_item __P((MENU *));
    189 int free_item __P((ITEM *));
    190 int item_count __P((MENU *));
    191 char *item_description __P((ITEM *));
    192 int item_index __P((ITEM *));
    193 _menui_menu_hook item_init __P((MENU *));
    194 char *item_name __P((ITEM *));
    195 OPTIONS item_opts __P((ITEM *));
    196 int item_opts_off __P((ITEM *, OPTIONS));
    197 int item_opts_on __P((ITEM *, OPTIONS));
    198 _menui_menu_hook item_term __P((MENU *));
    199 char *item_userptr __P((ITEM *));
    200 int item_value __P((ITEM *));
    201 int item_visible __P((ITEM *));
    202 ITEM **menu_items __P((MENU *));
    203 ITEM *new_item __P((char *, char *));
    204 int set_current_item __P((MENU *, ITEM *));
    205 int set_item_init __P((MENU *, _menui_menu_hook));
    206 int set_item_opts __P((ITEM *, OPTIONS));
    207 int set_item_term __P((MENU *, _menui_menu_hook));
    208 int set_item_userptr __P((ITEM *, char *));
    209 int set_item_value __P((ITEM *, int));
    210 
    211 #ifdef EXPOSE_PRIVATES
    212 void __menui_draw_item __P((MENU *, int));
    213 
    214 /* stole this from curses.h */
    215 #define max(a,b)        ((a) > (b) ? a : b)
    216 #endif
    217 __END_DECLS
    218 
    219 #endif
    220