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