2002-07-29 17:03:51 +04:00
|
|
|
/* $NetBSD: menu.h,v 1.12 2002/07/29 13:03:51 blymn Exp $ */
|
1999-11-23 14:12:34 +03:00
|
|
|
|
|
|
|
/*-
|
1999-12-16 15:08:06 +03:00
|
|
|
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
|
1999-11-23 14:12:34 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
2001-06-13 14:45:57 +04:00
|
|
|
* derived from this software without specific prior written permission
|
1999-11-23 14:12:34 +03:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-11-24 15:17:11 +03:00
|
|
|
#ifndef _MENU_H_
|
|
|
|
#define _MENU_H_
|
|
|
|
|
1999-11-23 14:12:34 +03:00
|
|
|
#include <curses.h>
|
|
|
|
#include <eti.h>
|
|
|
|
|
|
|
|
/* requests for the menu_driver call */
|
2002-02-04 16:02:05 +03:00
|
|
|
#define REQ_BASE_NUM (KEY_MAX + 0x100)
|
|
|
|
#define REQ_LEFT_ITEM (KEY_MAX + 0x101)
|
|
|
|
#define REQ_RIGHT_ITEM (KEY_MAX + 0x102)
|
|
|
|
#define REQ_UP_ITEM (KEY_MAX + 0x103)
|
|
|
|
#define REQ_DOWN_ITEM (KEY_MAX + 0x104)
|
|
|
|
#define REQ_SCR_ULINE (KEY_MAX + 0x105)
|
|
|
|
#define REQ_SCR_DLINE (KEY_MAX + 0x106)
|
|
|
|
#define REQ_SCR_DPAGE (KEY_MAX + 0x107)
|
|
|
|
#define REQ_SCR_UPAGE (KEY_MAX + 0x108)
|
|
|
|
#define REQ_FIRST_ITEM (KEY_MAX + 0x109)
|
|
|
|
#define REQ_LAST_ITEM (KEY_MAX + 0x10a)
|
|
|
|
#define REQ_NEXT_ITEM (KEY_MAX + 0x10b)
|
|
|
|
#define REQ_PREV_ITEM (KEY_MAX + 0x10c)
|
|
|
|
#define REQ_TOGGLE_ITEM (KEY_MAX + 0x10d)
|
|
|
|
#define REQ_CLEAR_PATTERN (KEY_MAX + 0x10e)
|
|
|
|
#define REQ_BACK_PATTERN (KEY_MAX + 0x10f)
|
|
|
|
#define REQ_NEXT_MATCH (KEY_MAX + 0x110)
|
|
|
|
#define REQ_PREV_MATCH (KEY_MAX + 0x111)
|
1999-11-23 14:12:34 +03:00
|
|
|
|
2002-02-04 16:02:05 +03:00
|
|
|
#define MAX_COMMAND (KEY_MAX + 0x111) /* last menu driver request
|
|
|
|
- for application defined
|
|
|
|
commands */
|
1999-11-23 14:12:34 +03:00
|
|
|
|
|
|
|
/* Menu options */
|
|
|
|
typedef unsigned int OPTIONS;
|
|
|
|
|
|
|
|
/* and the values they can have */
|
|
|
|
#define O_ONEVALUE (0x1)
|
|
|
|
#define O_SHOWDESC (0x2)
|
|
|
|
#define O_ROWMAJOR (0x4)
|
|
|
|
#define O_IGNORECASE (0x8)
|
|
|
|
#define O_SHOWMATCH (0x10)
|
|
|
|
#define O_NONCYCLIC (0x20)
|
|
|
|
#define O_SELECTABLE (0x40)
|
2002-07-29 17:03:51 +04:00
|
|
|
#define O_RADIO (0x80)
|
1999-11-23 14:12:34 +03:00
|
|
|
|
|
|
|
typedef struct __menu_str {
|
|
|
|
char *string;
|
|
|
|
int length;
|
|
|
|
} MENU_STR;
|
|
|
|
|
|
|
|
typedef struct __menu MENU;
|
|
|
|
typedef struct __item ITEM;
|
|
|
|
|
1999-12-16 15:08:06 +03:00
|
|
|
typedef void (*Menu_Hook) (MENU *);
|
1999-11-23 14:12:34 +03:00
|
|
|
|
|
|
|
struct __item {
|
|
|
|
MENU_STR name;
|
|
|
|
MENU_STR description;
|
|
|
|
char *userptr;
|
|
|
|
int visible; /* set if item is visible */
|
|
|
|
int selected; /* set if item has been selected */
|
|
|
|
int row; /* menu row this item is on */
|
|
|
|
int col; /* menu column this item is on */
|
|
|
|
OPTIONS opts;
|
|
|
|
MENU *parent; /* menu this item is bound to */
|
|
|
|
int index; /* index number for this item, if attached */
|
|
|
|
/* The following are the item's neighbours - makes menu
|
|
|
|
navigation easier */
|
|
|
|
ITEM *left;
|
|
|
|
ITEM *right;
|
|
|
|
ITEM *up;
|
|
|
|
ITEM *down;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct __menu {
|
|
|
|
int rows; /* max number of rows to be displayed */
|
|
|
|
int cols; /* max number of columns to be displayed */
|
|
|
|
int item_rows; /* number of item rows we have */
|
|
|
|
int item_cols; /* number of item columns we have */
|
|
|
|
int cur_row; /* current cursor row */
|
|
|
|
int cur_col; /* current cursor column */
|
|
|
|
MENU_STR mark; /* menu mark string */
|
|
|
|
MENU_STR unmark; /* menu unmark string */
|
|
|
|
OPTIONS opts; /* options for the menu */
|
|
|
|
char *pattern; /* the pattern buffer */
|
|
|
|
int plen; /* pattern buffer length */
|
|
|
|
int match_len; /* length of pattern matched */
|
|
|
|
int posted; /* set if menu is posted */
|
|
|
|
attr_t fore; /* menu foreground */
|
|
|
|
attr_t back; /* menu background */
|
|
|
|
attr_t grey; /* greyed out (nonselectable) menu item */
|
|
|
|
int pad; /* filler char between name and description */
|
|
|
|
char *userptr;
|
|
|
|
int top_row; /* the row that is at the top of the menu */
|
|
|
|
int max_item_width; /* widest item */
|
|
|
|
int col_width; /* width of the menu columns - this is not always
|
|
|
|
the same as the widest item */
|
|
|
|
int item_count; /* number of items attached */
|
|
|
|
ITEM **items; /* items associated with this menu */
|
|
|
|
int cur_item; /* item cursor is currently positioned at */
|
|
|
|
int in_init; /* set when processing an init or term function call */
|
1999-12-16 15:08:06 +03:00
|
|
|
Menu_Hook menu_init; /* call this when menu is posted */
|
|
|
|
Menu_Hook menu_term; /* call this when menu is unposted */
|
|
|
|
Menu_Hook item_init; /* call this when menu posted & after
|
1999-11-23 14:12:34 +03:00
|
|
|
current item changes */
|
1999-12-16 15:08:06 +03:00
|
|
|
Menu_Hook item_term; /* call this when menu unposted & just
|
1999-11-23 14:12:34 +03:00
|
|
|
before current item changes */
|
|
|
|
WINDOW *menu_win; /* the menu window */
|
|
|
|
WINDOW *menu_subwin; /* the menu subwindow */
|
2002-02-04 16:02:05 +03:00
|
|
|
WINDOW *scrwin; /* the window to write to */
|
1999-11-23 14:12:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Public function prototypes. */
|
|
|
|
__BEGIN_DECLS
|
2000-05-11 18:01:28 +04:00
|
|
|
int menu_driver(MENU *, int);
|
|
|
|
int scale_menu(MENU *, int *, int *);
|
|
|
|
int set_top_row(MENU *, int);
|
|
|
|
int pos_menu_cursor(MENU *);
|
|
|
|
int top_row(MENU *);
|
|
|
|
|
|
|
|
int free_menu(MENU *);
|
|
|
|
char menu_back(MENU *);
|
|
|
|
char menu_fore(MENU *);
|
|
|
|
void menu_format(MENU *, int *, int *);
|
|
|
|
char menu_grey(MENU *);
|
|
|
|
Menu_Hook menu_init(MENU *);
|
|
|
|
char *menu_mark(MENU *);
|
|
|
|
OPTIONS menu_opts(MENU *);
|
|
|
|
int menu_opts_off(MENU *, OPTIONS);
|
|
|
|
int menu_opts_on(MENU *, OPTIONS);
|
|
|
|
int menu_pad(MENU *);
|
|
|
|
char *menu_pattern(MENU *);
|
|
|
|
WINDOW *menu_sub(MENU *);
|
|
|
|
Menu_Hook menu_term(MENU *);
|
|
|
|
char *menu_unmark (MENU *);
|
|
|
|
char *menu_userptr(MENU *);
|
|
|
|
WINDOW *menu_win(MENU *);
|
|
|
|
MENU *new_menu(ITEM **);
|
|
|
|
int post_menu(MENU *);
|
|
|
|
int set_menu_back(MENU *, attr_t);
|
|
|
|
int set_menu_fore(MENU *, attr_t);
|
|
|
|
int set_menu_format(MENU *, int, int);
|
|
|
|
int set_menu_grey(MENU *, attr_t);
|
|
|
|
int set_menu_init(MENU *, Menu_Hook);
|
|
|
|
int set_menu_items(MENU *, ITEM **);
|
|
|
|
int set_menu_mark(MENU *, char *);
|
|
|
|
int set_menu_opts(MENU *, OPTIONS);
|
|
|
|
int set_menu_pad(MENU *, int);
|
|
|
|
int set_menu_pattern(MENU *, char *);
|
|
|
|
int set_menu_sub(MENU *, WINDOW *);
|
|
|
|
int set_menu_term(MENU *, Menu_Hook);
|
|
|
|
int set_menu_unmark(MENU *, char *);
|
|
|
|
int set_menu_userptr(MENU *, char *);
|
|
|
|
int set_menu_win(MENU *, WINDOW *);
|
|
|
|
int unpost_menu(MENU *);
|
|
|
|
|
|
|
|
ITEM *current_item(MENU *);
|
|
|
|
int free_item(ITEM *);
|
|
|
|
int item_count(MENU *);
|
|
|
|
char *item_description(ITEM *);
|
|
|
|
int item_index(ITEM *);
|
|
|
|
Menu_Hook item_init(MENU *);
|
|
|
|
char *item_name(ITEM *);
|
|
|
|
OPTIONS item_opts(ITEM *);
|
|
|
|
int item_opts_off(ITEM *, OPTIONS);
|
|
|
|
int item_opts_on(ITEM *, OPTIONS);
|
2002-07-29 17:03:51 +04:00
|
|
|
int item_selected(MENU *, int **); /* return the item index of selected */
|
2000-05-11 18:01:28 +04:00
|
|
|
Menu_Hook item_term(MENU *);
|
|
|
|
char *item_userptr(ITEM *);
|
|
|
|
int item_value(ITEM *);
|
|
|
|
int item_visible(ITEM *);
|
|
|
|
ITEM **menu_items(MENU *);
|
|
|
|
ITEM *new_item(char *, char *);
|
|
|
|
int set_current_item(MENU *, ITEM *);
|
|
|
|
int set_item_init(MENU *, Menu_Hook);
|
|
|
|
int set_item_opts(ITEM *, OPTIONS);
|
|
|
|
int set_item_term(MENU *, Menu_Hook);
|
|
|
|
int set_item_userptr(ITEM *, char *);
|
|
|
|
int set_item_value(ITEM *, int);
|
1999-11-23 14:12:34 +03:00
|
|
|
|
|
|
|
__END_DECLS
|
|
|
|
|
1999-11-24 15:17:11 +03:00
|
|
|
#endif /* !_MENU_H_ */
|