[BACK]Return to menu.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libmenu

File: [cvs.NetBSD.org] / src / lib / libmenu / menu.h (download)

Revision 1.13, Mon Mar 22 19:01:09 2004 UTC (16 years, 2 months ago) by jdc
Branch: MAIN
CVS Tags: yamt-pf42-baseX, yamt-pf42-base4, yamt-pf42-base3, yamt-pf42-base2, yamt-pf42-base, yamt-pf42, yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, wrstuden-revivesa-base-3, wrstuden-revivesa-base-2, wrstuden-revivesa-base-1, wrstuden-revivesa-base, wrstuden-revivesa, wrstuden-fixsa-newbase, wrstuden-fixsa-base-1, wrstuden-fixsa-base, wrstuden-fixsa, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, netbsd-5-base, netbsd-5-2-RELEASE, netbsd-5-2-RC1, netbsd-5-2-3-RELEASE, netbsd-5-2-2-RELEASE, netbsd-5-2-1-RELEASE, netbsd-5-2, netbsd-5-1-RELEASE, netbsd-5-1-RC4, netbsd-5-1-RC3, netbsd-5-1-RC2, netbsd-5-1-RC1, netbsd-5-1-5-RELEASE, netbsd-5-1-4-RELEASE, netbsd-5-1-3-RELEASE, netbsd-5-1-2-RELEASE, netbsd-5-1-1-RELEASE, netbsd-5-1, netbsd-5-0-RELEASE, netbsd-5-0-RC4, netbsd-5-0-RC3, netbsd-5-0-RC2, netbsd-5-0-RC1, netbsd-5-0-2-RELEASE, netbsd-5-0-1-RELEASE, netbsd-5-0, netbsd-5, netbsd-4-base, netbsd-4-0-RELEASE, netbsd-4-0-RC5, netbsd-4-0-RC4, netbsd-4-0-RC3, netbsd-4-0-RC2, netbsd-4-0-RC1, netbsd-4-0-1-RELEASE, netbsd-4-0, netbsd-4, netbsd-3-base, netbsd-3-1-RELEASE, netbsd-3-1-RC4, netbsd-3-1-RC3, netbsd-3-1-RC2, netbsd-3-1-RC1, netbsd-3-1-1-RELEASE, netbsd-3-1, netbsd-3-0-RELEASE, netbsd-3-0-RC6, netbsd-3-0-RC5, netbsd-3-0-RC4, netbsd-3-0-RC3, netbsd-3-0-RC2, netbsd-3-0-RC1, netbsd-3-0-3-RELEASE, netbsd-3-0-2-RELEASE, netbsd-3-0-1-RELEASE, netbsd-3-0, netbsd-3, netbsd-2-base, netbsd-2-1-RELEASE, netbsd-2-1-RC6, netbsd-2-1-RC5, netbsd-2-1-RC4, netbsd-2-1-RC3, netbsd-2-1-RC2, netbsd-2-1-RC1, netbsd-2-1, netbsd-2-0-base, netbsd-2-0-RELEASE, netbsd-2-0-RC5, netbsd-2-0-RC4, netbsd-2-0-RC3, netbsd-2-0-RC2, netbsd-2-0-RC1, netbsd-2-0-3-RELEASE, netbsd-2-0-2-RELEASE, netbsd-2-0-1-RELEASE, netbsd-2-0, netbsd-2, mjf-devfs2-base, mjf-devfs2, matt-premerge-20091211, matt-nb8-mediatek-base, matt-nb8-mediatek, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-nb5-pq3-base, matt-nb5-pq3, matt-nb5-mips64-u2-k2-k4-k7-k8-k9, matt-nb5-mips64-u1-k1-k5, matt-nb5-mips64-premerge-20101231, matt-nb5-mips64-premerge-20091211, matt-nb5-mips64-k15, matt-nb5-mips64, matt-nb4-mips64-k7-u2a-k9b, matt-mips64-premerge-20101231, matt-mips64-base2, matt-mips64-base, matt-mips64, matt-armv6-prevmlocking, matt-armv6-nbase, matt-armv6-base, matt-armv6, localcount-20160914, keiichi-mipv6-base, keiichi-mipv6, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, is-mlppp-base, is-mlppp, hpcarm-cleanup-nbase, hpcarm-cleanup-base, hpcarm-cleanup, cube-autoconf-base, cube-autoconf, cherry-xenmp-base, cherry-xenmp, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver, abandoned-netbsd-4-base, abandoned-netbsd-4, HEAD
Changes since 1.12: +20 -20 lines

Change the key definitions so that they no longer collide with the ones in
libform.  Do this because the library major number is changing (the libcurses
major number is changing).
Suggested by Brett Lymn,

/*	$NetBSD: menu.h,v 1.13 2004/03/22 19:01:09 jdc Exp $	*/

/*-
 * Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
 * 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
 *    derived from this software without specific prior written permission
 *
 * 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.
 *
 *
 */

#ifndef	_MENU_H_
#define	_MENU_H_

#include <curses.h>
#include <eti.h>

/* requests for the menu_driver call */
#define REQ_BASE_NUM      (KEY_MAX + 0x200)
#define REQ_LEFT_ITEM     (KEY_MAX + 0x201)
#define REQ_RIGHT_ITEM    (KEY_MAX + 0x202)
#define REQ_UP_ITEM       (KEY_MAX + 0x203)
#define REQ_DOWN_ITEM     (KEY_MAX + 0x204)
#define REQ_SCR_ULINE     (KEY_MAX + 0x205)
#define REQ_SCR_DLINE     (KEY_MAX + 0x206)
#define REQ_SCR_DPAGE     (KEY_MAX + 0x207)
#define REQ_SCR_UPAGE     (KEY_MAX + 0x208)
#define REQ_FIRST_ITEM    (KEY_MAX + 0x209)
#define REQ_LAST_ITEM     (KEY_MAX + 0x20a)
#define REQ_NEXT_ITEM     (KEY_MAX + 0x20b)
#define REQ_PREV_ITEM     (KEY_MAX + 0x20c)
#define REQ_TOGGLE_ITEM   (KEY_MAX + 0x20d)
#define REQ_CLEAR_PATTERN (KEY_MAX + 0x20e)
#define REQ_BACK_PATTERN  (KEY_MAX + 0x20f)
#define REQ_NEXT_MATCH    (KEY_MAX + 0x210)
#define REQ_PREV_MATCH    (KEY_MAX + 0x211)

#define MAX_COMMAND       (KEY_MAX + 0x211) /* last menu driver request
					       - for application defined
					       commands */

/* 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)
#define O_RADIO      (0x80)

typedef struct __menu_str {
        char *string;
        int length;
} MENU_STR;

typedef struct __menu MENU;
typedef struct __item ITEM;

typedef void (*Menu_Hook) (MENU *);

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 */
        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
				       current item changes */
        Menu_Hook item_term; /* call this when menu unposted & just
				       before current item changes */
        WINDOW *menu_win; /* the menu window */
        WINDOW *menu_subwin; /* the menu subwindow */
	WINDOW *scrwin; /* the window to write to */
};


/* Public function prototypes. */
__BEGIN_DECLS
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);
int item_selected(MENU *, int **); /* return the item index of selected */
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);

__END_DECLS

#endif /* !_MENU_H_ */