home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
SDGO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-18
|
7KB
|
276 lines
/*
sdgo.c
% sed_ReallyGo (activation and field function handling)
Contains sed_ReallyGo() and
routines for calling the field functions.
If function address is NULL then perform the default action.
default actions:
fenter(sed) { }
fkey(sed) { sed_ToggleExit(sed); }
fexit(sed) { return(TRUE); }
senter(sed, fieldno) { }
sexit(sed, fieldno) { }
C-scape 3.2
Copyright (c) 1986, 1987, by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
11/08/86 jmd written
11/09/86 jmd tested and placed into sdgo.c file
11/10/86 jmd added protected mode
1/22/87 jmd moved senter funcs to sed_Repaint()
3/28/87 jmd added cursor control and active mode.
9/23/87 jmd removed field_funcs cast.
11/18/87 jmd changed names of some low-level funcs
11/19/87 jmd changed menu_GetFieldFuncs to menu_GetFuncs
4/05/88 jmd added sed_DoSpecial()
4/08/88 jmd changed sed->fieldcount to sed_GetFieldCount()
6/30/88 jmd removed cursor save
7/07/88 jmd added sed_DoMsg()
9/14/88 jmd changed cursor handling
10/02/88 jmd added win_MakeCurrent
10/19/88 jmd added test for bad fieldno
11/19/88 jmd changed to sed_ReallyGo, removed sed_DoMsg
12/10/88 jmd added mousecode reset
3/24/89 jmd added sed_ macros
4/06/89 jmd changed true to otrue
4/26/89 jmd added Aux support
8/23/89 jmd Added cache flag support
11/10/89 jmd now resets fieldpos when needed
12/10/89 jmd added SED_GO aux messages
3/14/90 jmd added additional Cache/Flush calls
3/17/90 jmd added PREFEXIT message
3/28/90 jmd ansi-fied
7/19/90 jmd added test for NULL sed in sed_DoAux
7/29/90 jmd removed sed_DoAux
8/04/90 jmd removed SED_GO aux message, now handled by win_Go
10/18/90 jmd added SED_POSTFENTER message (under protest)
*/
#include "sed.h"
int sed_ReallyGo(sed_type sed)
/*
This is the REAL sed Go function. It is called from the
sed window class. It activates the sed and controls the
field functions. It is attached to the sed as a wingo_func.
It returns the value of the sed's baton.
*/
{
register int i;
register int first_fld;
cs_Assert(sed_Ok(sed), CS_SD_GO_SED, 0);
if (sed_GetFieldCount(sed) == 0) {
/* empty sed */
return(sed_GetBaton(sed));
}
else if (sed_GetFieldNo(sed) < 0) {
/* If someone deleted all the fields and then put some back... */
/* or if we added fields after creating the sed */
sed_SetFieldNo(sed, 0);
/* reset the current field pointer */
sed_SetCurrField(sed, menu_GetField(sed_GetMenu(sed), sed_GetFieldNo(sed)));
/* reset the current field position */
sed_SetRecordPos(sed, menu_GetFirstFieldPos(sed_GetMenu(sed), sed_GetFieldNo(sed)));
}
/* Find the first unprotected field (starting with current field) */
for (first_fld = sed_GetFieldNo(sed); first_fld < sed_GetFieldCount(sed); first_fld++) {
if (!menu_IsProtected(sed_GetMenu(sed), first_fld)) {
break;
}
}
if (first_fld >= sed_GetFieldCount(sed)) {
/* no unprotected fields found */
return(sed_GetBaton(sed));
}
/* Reset exit_toggle. */
sed_SetExit(sed, FALSE);
/* Set active mode */
sed_SetActive(sed, TRUE);
/* Save the cursor type */
sed_SetCtype(sed, sed_GetCursorType(sed));
disp_Cache();
/* make sure field is visible */
sd_scroll_adjust(sed, first_fld);
/* highlight active field */
sd_goto_field(sed, first_fld);
/* call fentry function */
sed_DoFieldFenter(sed, sed_GetFieldNo(sed));
disp_Flush();
/* Main loop. */
while(!(sed_GetExit(sed))) {
/* call fkey funcs until exit_toggle */
while (!(sed_GetExit(sed))) {
sed_SetCache(sed, FALSE);
sed_DoFieldFkey(sed, sed_GetFieldNo(sed));
/* do we need to flush? */
if (sed_IsCache(sed)) {
disp_Flush();
}
}
/* don't leave unless fexit function and Aux function return TRUE */
if (!sed_DoFieldFexit(sed, sed_GetFieldNo(sed)) ||
!sed_DoAux(sed, SED_PRESEXIT, NULL, NULL)) {
sed_SetExit(sed, FALSE);
sed_SetNextWin(sed, NULL); /* reset next win */
}
}
/* reset the border prompt */
sed_BorderPrompt(sed, NULL);
/* Call sexit functions. */
for (i = 0; i < sed_GetFieldCount(sed); i++) {
sed_DoFieldSexit(sed,i);
}
/* Send message to Aux function */
sed_DoAux(sed, SED_POSTSEXIT, NULL, NULL);
/* Reset active mode */
sed_SetActive(sed, FALSE);
/* Unhighlight active field */
sd_goto_field(sed, sed_GetFieldNo(sed));
/* Restore the cursor type */
sed_SetCursorType(sed, sed_GetCtype(sed));
return(sed_GetBaton(sed));
}
/*** field function routines **************************************************/
void sed_DoFieldFenter(sed_type sed, int fld)
{
fenter_fptr func;
sed_DoAux(sed, SED_PREFENTER, NULL, NULL);
if ((func = (menu_GetFuncs(sed_GetMenu(sed), fld))->fentry) != FNULL) {
disp_Cache();
(*func)(sed);
disp_Flush();
}
sed_DoAux(sed, SED_POSTFENTER, NULL, NULL);
}
void sed_DoFieldFkey(sed_type sed, int fld)
{
fkey_fptr func;
if ((func = (menu_GetFuncs(sed_GetMenu(sed), fld))->fkey) != FNULL) {
(*func)(sed);
}
else {
sed_SetExit(sed, TRUE);
}
}
boolean sed_DoFieldFexit(sed_type sed, int fld)
/*
Calls the field's fexit function, sends PREFEXIT and POSTFEXIT
aux messages.
*/
{
fexit_fptr func;
if (!sed_DoAux(sed, SED_PREFEXIT, NULL, NULL)) {
return(FALSE);
}
if ((func = (menu_GetFuncs(sed_GetMenu(sed), fld))->fexit) != FNULL
&& (*func)(sed) == FALSE) {
return(FALSE);
}
return(sed_DoAux(sed, SED_POSTFEXIT, NULL, NULL));
}
void sed_DoFieldSenter(sed_type sed, int fld)
{
senter_fptr func;
if ((func = (menu_GetFuncs(sed_GetMenu(sed), fld))->sentry) != FNULL) {
(*func)(sed, fld);
}
}
void sed_DoFieldSexit(sed_type sed, int fld)
{
sexit_fptr func;
if ((func = (menu_GetFuncs(sed_GetMenu(sed), fld))->sexit) != FNULL) {
(*func)(sed, fld);
}
}
boolean sed_DoSpecial(sed_type sed, int key)
/*
Call the sed's special function.
Returns FALSE if there is no special function
else it returns the special function's return value.
*/
{
if (sed_GetSpecial(sed) == FNULL) {
return(FALSE);
}
return((*(sed_GetSpecial(sed)))(sed, key));
}
boolean sd_exitfield(sed_type sed)
/*
Exits the current field.
If sed is active, calls FieldFexit and resets cursor type
else does nothing.
Returns FALSE if fexit fails
*/
{
if (sed_IsActive(sed)) {
if (sed_DoFieldFexit(sed, sed_GetFieldNo(sed))) {
/* Restore the cursor type */
sed_SetCursorType(sed, sed_GetCtype(sed));
return(TRUE);
}
else {
return(FALSE);
}
}
return(TRUE);
}