home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
SLEDOPEN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-31
|
7KB
|
301 lines
/*
sledopen.c
% sled_ReallyOpen, sled_remapper
C-scape 3.2
Copyright (c) 1988-1990, by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
7/22/89 jdc removed from sledwin.c
7/29/89 jmd added casts for blank
8/04/89 gam changed #include <sledwin.h> to sled.h
8/05/89 gam added protection/marking of rows and columns
8/13/89 jmd revamped open/init mechanism
8/24/89 gam @fp[] in menu_Printf now works in sleds
8/26/89 jmd made torf an int
11/29/89 jmd added casts for DG
2/24/90 jdc removed sled_GetHeight
3/28/90 jmd ansi-fied
5/01/90 jdc added field removal for resize smaller
5/30/90 jdc changed the order in which sled_ReallyOpen adds fields
6/08/90 jmd turned class into wclass for C++
6/12/90 jdc preened
6/15/90 jdc added FieldCount check for sled_Init
6/22/90 jdc added reopen check for sled_Init
put sledwin_Close in here
7/11/90 jdc fixed max_varsize == 0 and sa == NULL bugs
11/31/90 ted added oak_notused call in sled_Init().
*/
#include "sed.h"
#include "sldwinod.h"
#include "sadecl.h"
#include "sled.h"
#include "sledprot.h"
sed_type sled_ReallyOpen(menu_type menu, int hgt, spc_fptr spec_func, class_fptr wclass)
/*
Create fields for the sled from the one line menu.
Open a sed and initialize it.
*/
{
sed_type sed;
int i, row, fld, fldone;
/* find the first (and only) row */
for (row = 0; (fldone = menu_GetGRow(menu, row)) <= 0; row++) {
;
}
/* the fldno returned from menu_GetGRow is the real fldno plus 1 */
fld = --fldone;
/* create hgt rows from the one row */
for (i = 1; i < hgt; i++, fld = fldone) {
do {
if (menu_CopyField(menu, row + i, menu_GetFieldCol(menu, fld), menu, fld) < 0) {
return(NULL);
}
} while ((fld = menu_GetFieldRight(menu, fld)) >= 0);
}
/* open the sed */
if ((sed = sed_ReallyOpen(menu, wclass)) == NULL) {
return(NULL);
}
sled_Init(sed, hgt, spec_func);
return(sed);
}
boolean sled_Init(sed_type sed, int hgt, spc_fptr spec_func)
/*
Initialize a sled.
*/
{
int i, col, fld, varsize, max_varsize = 0;
xarray xa;
VOID *var;
char *blank;
sarray_type sa;
iarray ca;
menu_type menu;
int torf;
oak_notused(hgt);
menu = sed_GetMenu(sed);
/* close before reallocating */
if (sled_GetXa(sed) != NULL) {
sledwin_Close(sed);
}
/* The column arrays are an xarray of sarrays */
if ((xa = xa_Open(1)) == NULL) {
goto QUIT_1;
}
sled_SetXa(sed, xa);
/* make iarray for column protection and initialize it. */
if ((ca = ia_Open(1)) == NULL) {
goto QUIT_2;
}
/* set the col protect/mark flags */
sled_setcflags(sed, ca);
if (sed_GetFieldCount(sed) <= 0) {
sled_SetOffset(sed, 0);
sled_SetColSize(sed, 0);
sled_SetWidth(sed, 0);
sled_SetBlank(sed, NULL);
return(TRUE);
}
/* find the first (and only) row */
fld = sed_GetGridField(sed, 0, 0);
col = 0;
/* create hgt rows from the one row */
do {
/* create the Column Arrays (sarrays) checking for NULL varsize */
if ((varsize = menu_GetVarSize(menu, fld)) == 0) {
sa = NULL;
}
else if ((sa = sa_Open(varsize, SLED_BSIZE, SLED_ASIZE)) == NULL) {
goto QUIT_3;
}
/* Put the sarray into the xarray */
xa_Put(xa, col, (VOID *)sa);
/* find the largest variable to allocate blank field var */
max_varsize = (max_varsize < varsize) ? varsize : max_varsize;
/* Set column protection flag */
torf = (int) sed_IsProtectedField(sed, fld);
ia_Put(ca, col, torf);
/* Next column, please */
col++;
} while ((fld = menu_GetFieldRight(menu, fld)) >= 0);
sled_SetOffset(sed, 0);
sled_SetColSize(sed, 1);
sled_SetWidth(sed, col);
/* allocate the blank field memory */
if (max_varsize <= 0) {
blank = NULL;
}
else if ((blank = (char *) ocalloc(CSA_SLEDBLANK, max_varsize, sizeof(byte))) == NULL) {
goto QUIT_3;
}
sled_SetBlank(sed, (VOID *) blank);
if (spec_func != FNULL) {
sed_SetSpecial(sed, spec_func);
}
/* make sarray for mark/protect */
if ((sa = sa_Open(sizeof(int), SLED_BSIZE, SLED_ASIZE)) == NULL) {
goto QUIT_3;
}
xa_Put(xa, col, (VOID *)sa);
/* Initialize the first row mark/protect flag */
sa_Blank(sa, 0L, 1, FALSE);
/* create one empty row */
for (i = 0; i < col; i++) {
var = sa_Put((sarray_type)xa_Get(xa, i), 0L, sled_GetBlank(sed));
sed_SetVar(sed, i, var);
}
sled_remapper(sed, 0);
return(TRUE);
/* These statements clean up if not enough memory for everything */
QUIT_3:
for ( i = 0; i <= col; i++ ) {
if ((sa = (sarray_type)xa_Get(xa, i)) != NULL) {
sa_Close(sa);
}
}
ia_Close(ca);
sled_setcflags(sed, NULL);
QUIT_2:
xa_Close(xa);
sled_SetXa(sed, NULL);
QUIT_1:
return(FALSE);
}
boolean sled_remapper(sed_type sed, int offset)
{
boolean protect, marked;
int bot, fld, row, col, i, hgt;
menu_type menu;
menu = sed_GetMenu(sed);
hgt = menu_GetFieldRow(menu, menu_GetFieldCount(menu) -1) - menu_GetFieldRow(menu, 0) + 1;
if (offset < 0) {
if (sled_GetOffset(sed) == 0) {
return(FALSE);
}
offset = (sled_GetOffset(sed) < -offset) ? -sled_GetOffset(sed) : offset;
}
else if (offset > 0) {
if ((bot = sled_GetColSize(sed) - (hgt + sled_GetOffset(sed))) <= 0) {
return(FALSE);
}
offset = (bot < offset) ? bot : offset;
}
sled_SetOffset(sed, sled_GetOffset(sed) + offset);
for (i = 0, row = sled_GetOffset(sed); i < menu_GetRowCount(menu); i++) {
if ((fld = menu_GetGRow(menu, i) - 1) < 0) {
continue;
}
protect = sled_IsProtectedRow(sed, row);
marked = sled_IsMarkedRow(sed, row);
/* loop each row */
col = 0;
do {
/* loop each col */
if (row < sled_GetColSize(sed)) {
/* row exists */
menu_SetVar(menu, fld, sa_Get((sarray_type)xa_Get(sled_GetXa(sed), col), (long)row));
menu_ProtectField(menu, fld, protect | sled_IsProtectedCol(sed, col));
if (marked | sled_IsMarkedCol(sed, col)) {
menu_MarkField(menu, fld, sled_GetRegAttr(sed), sled_GetSelAttr(sed));
}
else {
field_SetMarked(sed_GetField(sed, fld), FALSE);
}
}
else {
/* row doesn't exist */
menu_SetVar(menu, fld, sled_GetBlank(sed));
menu_ProtectField(menu, fld, TRUE);
}
col++;
} while ((fld = menu_GetFieldRight(menu, fld)) >= 0);
row++;
}
/* Send Scroll message to the border */
sed_SendBorderMsg(sed, BDM_SCROLL, NULL, NULL);
return(TRUE);
}
void sledwin_Close(sed_type sed)
{
sarray_type sa;
int i;
if (sed_GetFieldCount(sed) <= 0) return;
/* close the blank field */
if (sled_GetBlank(sed) != NULL) {
ofree(CSA_SLEDBLANK, sled_GetBlank(sed));
sled_SetBlank(sed, NULL);
}
/* close the column marking/protection array */
if (sled_getcflags(sed) != NULL) {
ia_Close(sled_getcflags(sed));
sled_getcflags(sed) = NULL;
}
/* close the xarray of column arrays */
if (sled_GetXa(sed) != NULL) {
/* close the column arrays */
for (i = 0; i < sled_GetWidth(sed); i++) {
if ((sa = (sarray_type)xa_Get(sled_GetXa(sed), i)) != NULL) {
sa_Close(sa);
}
}
xa_Close(sled_GetXa(sed));
sled_SetXa(sed, NULL);
}
}