home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
FUNCS
/
FNLIST.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-14
|
5KB
|
216 lines
/*
fnlist.c 10/02/87
% list_funcs
List Functions:
A field has multiple choices.
A popup menu displays the choices.
The Variable is a char *
and contains the selected choice.
The choices are contained in the field's second data pointer in
the form "choice 1, choice 2, choice 3" (commas delimit).
The cursor is turned off.
C-scape 3.2
Copyright (c) 1987, 1988 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
3/31/88 jmd Removed tinkering of static strings
4/06/88 jmd added call to sed_DoSpecial
4/13/88 jmd changed MAX_FIELD_LEN to MAX_CHOICE_LEN
9/15/88 jmd removed vid_Cursor calls
9/17/88 jmd added std_ funcs
10/09/88 jmd added SED_ABORT support
10/14/88 jdc added var_size element to field_funcs_struct
11/05/88 jmd removed menu_Close
12/14/88 jdc remove pointer subtraction from list_GetChoice()
12/20/88 jmd tests for missing list elements
2/07/89 jmd added char * cast
4/10/89 jmd added oakpriv.h
6/07/89 jmd added test for mouse code (later removed)
11/29/89 jmd added casts for DG
3/28/90 jmd ansi-fied
8/05/89 jmd added hilite support
8/13/89 jmd added test of current record contents
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "cscape.h"
#include "fnfunc.h" /* for field functions */
#include "scancode.h"
#include "msys.h" /* for msys_ParseChoice */
#include "oakpriv.h" /* for memmove() macro */
#define DELIMITER ','
OSTATIC char *list_GetChoice(char *list, int num, char *string);
#define MAX_CHOICE_LEN 80 /* maximum length of a choice */
OGLOBAL field_funcs_struct list_funcs = {
stdNoCur_fenter,
std_fexit,
list_fkey,
string_senter,
string_sexit,
VAR_STRING
};
void list_fkey(sed_type sed)
/*
Cycle through list of changes when the SPACE bar is pressed.
*/
{
int scancode;
menu_type list_menu;
sed_type list_sed;
int fieldno, row, col;
char *list, *rec, s[MAX_CHOICE_LEN + 1];
byte reg, sel;
int hichar;
int i = 0, fno = -1;
scancode = kb_Read();
if (sed_DoSpecial(sed, scancode))
return;
if (special_key(sed, scancode))
return;
if (inter_field(sed, scancode))
return;
if (inter_page(sed, scancode))
return;
fieldno = sed_GetFieldNo(sed);
if ((list = (char *) sed_GetCurrFieldData(sed, 1)) != NULL) {
/* look at the current record contents */
rec = sed_GetCurrRecord(sed);
list_menu = menu_Open();
/* set the color of the list */
sed_GetFieldColors(sed, fieldno, ®, &sel);
while (list_GetChoice(list, i, s) != NULL) {
/* check for hilighted characters */
hichar = msys_ParseChoice(s, s, MAX_CHOICE_LEN);
/* see if this choice matches the current record contents */
if (strcmp(rec, s) == 0) {
fno = i;
}
menu_Printf(list_menu, "@p[%d,0] @fh%d[%s] ", i++, NULL, &menu_funcs, hichar, s);
}
menu_Flush(list_menu);
list_sed = sed_Open(list_menu);
sed_SetColors(list_sed, sel, sel, reg);
sed_SetBorder(list_sed, bd_1);
/* set higlghted colors, use bolded version of normal attrs */
sed_SetHiColors(list_sed, sel | 0x08, reg | 0x08);
/* adjust the position of the list */
row = sed_GetFieldRow(sed, fieldno) - sed_GetBorderHeight(list_sed)/2;
row = (row < disp_GetHeight() - sed_GetBorderHeight(list_sed) - 1) ? row :
disp_GetHeight() - sed_GetBorderHeight(list_sed) - 2;
row = (row > 0) ? row : 0;
col = sed_GetFieldLastCol(sed, fieldno);
col = (col + sed_GetBorderWidth(list_sed) < disp_GetWidth()) ? col :
disp_GetWidth() - sed_GetBorderWidth(list_sed) - 2;
if (sed_GetBorderHeight(list_sed) > disp_GetHeight() -1 ) {
sed_SetHeight(list_sed, disp_GetHeight() - 3);
}
sed_SetPosition(list_sed, row, col);
/* attach a mouse handler to the popup */
sed_SetMouse(list_sed, sedmou_GreedyTrack);
/* go to the currently selected choice */
if (fno >= 0) {
sed_GotoField(list_sed, fno);
}
/* put up list of choices */
sed_Repaint(list_sed);
if (sed_Go(list_sed) != 0) {
sed_SetCurrRecord(sed, sed_GetCurrMerge(list_sed));
}
sed_UpdateCurrField(sed);
sed_Close(list_sed);
}
/* reset baton */
sed_SetBaton(sed, -1);
}
static char *list_GetChoice(char *list, int num, char *string)
/*
Copies the num'th choice from the list into string.
Returns string.
List is of the form:
"choice 1,choice 2,choice 3" (commas delimit).
returns NULL if num is too large.
Note: assumes that string is at least MAX_CHOICE_LEN + 1 chars long.
*/
{
int p, q;
unsigned len;
/* skip leading DELIMITERS */
for (p = 0; list[p] == DELIMITER; p++) {
;
}
for (q = p;; p++) {
/* skip empty entries */
if ((list[p] == DELIMITER || list[p] == '\0') && num-- <= 0) {
if ((len = p - q) > MAX_CHOICE_LEN) {
len = MAX_CHOICE_LEN;
}
memmove((VOID *) string, (VOID *) (list + q), len);
string[len] = '\0';
break;
}
else if (list[p] == DELIMITER) {
/* point q to beginning of next entry */
for (q = p + 1; list[q] == DELIMITER; q++, p++) {
;
}
if (list[q] == '\0') {
return(NULL);
}
}
else if (list[p] == '\0') {
return(NULL);
}
}
return(string);
}