home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
FUNCS
/
FNMENU.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-08
|
4KB
|
192 lines
/*
fnmenu.c 11/21/86
% menu_funcs, gmenu_funcs
C-scape 3.2
Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
11/25/86 jmd Added first letter search to menu_funcs.
4/06/88 jmd added call to sed_DoSpecial
9/17/88 jmd added std_ funcs
10/14/88 jdc added var_size element to field_funcs_struct
6/07/89 jmd added test for mouse code (later removed)
combined into one routine, added data pointer test
combined with click_funcs
7/02/89 jdc moved menucommon_return after sed_GotoField
3/28/90 jmd ansi-fied
10/04/90 pmcm removed isprint from search
12/08/90 pmcm changed std_fenter to stdNoCur_fenter
*/
#include <stdio.h>
#include <ctype.h>
#include "cscape.h"
#include "ostdlib.h" /* for atoi() */
#include "fnfunc.h" /* for field functions */
#include "scancode.h"
OSTATIC void menucommon_fkey(sed_type sed, int mode);
OSTATIC int menucommon_return(sed_type sed);
/** modes **/
#define MENU_FUNCS 0
#define GMENU_FUNCS 1
#define CLICK_FUNCS 2
OGLOBAL field_funcs_struct menu_funcs = {
stdNoCur_fenter,
std_fexit,
menu_fkey,
FNULL,
FNULL,
0
};
OGLOBAL field_funcs_struct gmenu_funcs = {
stdNoCur_fenter,
std_fexit,
gmenu_fkey,
FNULL,
FNULL,
0
};
OGLOBAL field_funcs_struct click_funcs = {
std_fenter,
std_fexit,
click_fkey,
FNULL,
FNULL,
0
};
void menu_fkey(sed_type sed)
/*
modifies: sed.
effects: Standard menu functions.
Up and down keys change choices.
Baton contains field number + 1 when ENTER is pressed
or 0 if ESC pressed.
Note: If the field's second data pointer is not NULL,
it is assumed to be a pointer to a numeric string, i.e., "2",
This string is converted to an integer and returned
via the baton when ENTER is pressed (instead of the
field number).
This makes if possible to define menus whose returns values
are not dependent on field order.
*/
{
menucommon_fkey(sed, MENU_FUNCS);
}
void gmenu_fkey(sed_type sed)
/*
modifies: sed.
effects: Grid menu functions.
Up, down, left, and right keys change choices.
Baton contains field number + 1 when ENTER is pressed
or 0 if ESC pressed.
Note: (see note for menu_fkey above)
*/
{
menucommon_fkey(sed, GMENU_FUNCS);
}
void click_fkey(sed_type sed)
/*
Just like gmenu_funcs, except that first letter choices are immediate.
*/
{
menucommon_fkey(sed, CLICK_FUNCS);
}
static void menucommon_fkey(sed_type sed, int mode)
/*
This routines does the actual work for menu and gmenu_fkey.
mode determines how the function acts, MENU_FUNCS, GMENU_FUNCS
*/
{
int scancode, letter, choice, ret;
scancode = kb_Read();
if (sed_DoSpecial(sed, scancode))
return;
if (special_key(sed, scancode))
return;
/* intercept key (and mouse) before inter_field...() */
if (scancode == ENTER || scancode == MOU_CLICK) {
sed_SetBaton(sed, menucommon_return(sed));
sed_ToggleExit(sed);
return;
}
if (mode == MENU_FUNCS) {
/* menu_fkey */
if (inter_field(sed, scancode))
return;
}
else {
/* gmenu_fkey and click_fkey */
if (inter_field_grid(sed, scancode))
return;
}
if (inter_page(sed, scancode))
return;
switch(scancode) {
case HOME:
sed_GotoFirstField(sed);
break;
case END:
sed_GotoLastField(sed);
break;
default:
/* do first letter search */
letter = ascii(scancode);
if ((choice = sed_SearchMerge(sed, (char)letter)) != -1) {
sed_GotoField(sed, choice);
ret = menucommon_return(sed);
if (mode == CLICK_FUNCS) {
/* click funcs return immediately when a letter is pressed */
sed_SetBaton(sed, ret);
sed_ToggleExit(sed);
return;
}
}
break;
}
/* reset baton */
sed_SetBaton(sed, -1);
}
static int menucommon_return(sed_type sed)
/*
Determines the return value for menucommon_fkey when a choice is made.
If the second data isn't NULL, converts it from a string to an int
and returns that value, else returns the field number + 1.
*/
{
char *d;
if ((d = (char *) sed_GetFieldData(sed, sed_GetFieldNo(sed), 1)) != NULL) {
return(atoi(d));
}
else {
return(sed_GetFieldNo(sed) + 1);
}
}