home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
SLUG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-28
|
4KB
|
156 lines
/*
slug.c
% slug menu routines
rules for user functions:
they get passed two arguments (a VOID * and an int).
The VOID * is passed through msys_Go().
The int is the value parameter from the slug_list struct.
they return a positive value if processing is finished
This value is passed up and returned from msys_Go
0 acts like an ESCape was pressed.
int user_func(VOID *, int);
C-scape 3.2
Copyright (c) 1988, by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
8/30/88 jdc re-created
12/11/88 jmd moved idata to ufunc _od
4/22/89 jmd changed border to bord
8/11/89 jmd added call to ufunc_Open
12/12/89 ted overhauled.
1/05/89 jmd added hilite support to the def structure
2/26/90 ted Made slug_Repaint a function again.
3/28/90 jmd ansi-fied
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "cscape.h"
#include "oaktag.h" /* For IDs in msys.h */
#include "msys.h"
#define SLUG_MIN_WIDTH 20
#define MAXCHOICE 80
/* this scratch pad must be static as slug_create is called recursively */
static char choice_string[MAXCHOICE + 1];
/* -------------------------------------------------------------------------- */
sed_type slug_create(struct slug_list slug_def[], int dir, bd_fptr bord, byte bkg, byte sel, byte bdr, field_funcs_ptr ffuncs, mouhandler_fptr mfunc)
/*
Create a menuing system object from a slug_list.
This function gets called recursively.
*/
{
menu_type menu;
sed_type sed;
bob_type bob;
int i, dif;
int hichar;
if ((menu = menu_Open()) == NULL) {
return(NULL);
}
for ( i = 0; slug_def[i].choice != NULL ; i++) {
bob = NULL;
if ( dir == MENU_VERTICAL && i > 0 ) {
menu_Printf(menu, "\n");
}
if (slug_def[i].child != NULL) { /* make the child */
if ((bob = slug_create(slug_def[i].child, dir, bord, bkg,
sel, bdr, ffuncs, mfunc)) == NULL) {
return(NULL);
}
bob_SetDepend(bob, BOB_INDEPENDENT);
}
else if ((bob = ufunc_Open(slug_def[i].slug_func, slug_def[i].value)) == NULL ) {
return(NULL);
}
/* check for hilighted characters */
if ((hichar = msys_ParseChoice(slug_def[i].choice, choice_string, MAXCHOICE)) >= 0) {
hichar++;
}
menu_Printf(menu, "@fbdh%d[ %s ]", NULL, ffuncs, bob,
slug_def[i].message, hichar, choice_string);
}
menu_Flush(menu);
if ((sed = sed_Open(menu)) == NULL) {
return(NULL);
}
sed_SetColors(sed, bkg, bkg, sel);
sed_SetBorder(sed, bord);
sed_SetBorderColor(sed, bdr);
sed_SetBorderTitle(sed, slug_def[i].message);
sed_SetLabel(sed, slug_def[i].value);
sed_SetMouse(sed, mfunc);
if (dir == MENU_VERTICAL) {
if (sed_GetWidth(sed) < SLUG_MIN_WIDTH) {
sed_SetWidth(sed, SLUG_MIN_WIDTH);
}
if ( (dif = sed_GetBorderHeight(sed) - disp_GetHeight()) > 0 ) {
sed_SetHeight(sed, sed_GetHeight(sed) - dif);
}
}
else {
sed_SetWidth(sed, disp_GetWidth());
}
return(sed);
}
/* -------------------------------------------------------------------------- */
int slug_Go(sed_type sed, int startfld, int row, int col, VOID *data)
/*
Calls go (sed_Go) on a slug menu (sed).
'row' and 'column' are the position of the slug menu.
(use -1, -1, to override positioning)
'startfld' is the field number of the starting field (use -1 to ignore)
'data' is the data passed on to the user functions.
*/
{
int ret;
if (row != -1 && col != -1) {
sed_SetPosition(sed, row, col);
}
if (startfld != -1 ) { /* upon original entry */
sed_GotoField(sed, startfld);
}
sed_SetData(sed, data);
sed_Repaint(sed);
ret = sed_Go(sed);
sed_Pop(sed);
return(ret);
}
/* -------------------------------------------------------------------------- */
void slug_Repaint(sed_type sed, int row, int col)
{
if (row != -1 && col != -1) {
sed_SetPosition(sed, row, col);
}
sed_Repaint(sed);
}
/* -------------------------------------------------------------------------- */