home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
SLEDWIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-31
|
11KB
|
425 lines
/*
sledwin.c
% sledwin_Class: The sled window class
C-scape 3.2
Copyright (c) 1988-1990, by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
2/07/89 jmd initialized sleddata to avoid warning
3/24/89 jmd added sed_ macros
3/29/89 jmd converted seds to 'pure' objects
4/11/89 jmd fixed field blanking (this fixes graphics mode bug)
fixed GoHome in ScrollReq
4/19/89 jdc changed sled_Open() to sled_ReallyOpen()
4/28/89 jdc removed protection from sled_remapper()
5/23/89 jdc put protection back (bob grid movement requires it)
added failure checks to sled_ReallyOpen()
added support for varsize == 0
7/22/89 jdc moved sled_ReallyOpen and sled_remapper to sledopen.c
8/04/89 gam changed #include <sledwin.h> to sled.h
8/05/89 gam added protection/marking for rows and columns
8/06/89 gam added sled_getrowflags function for Microsoft
8/10/89 gam added remapper check to sled_SetColVar().
8/21/89 jdc broke out close code into sledwin_Close (LNF)
8/23/89 jmd added tests for menu == NULL
9/12/89 gam added scroll message to sled_remapper
10/17/89 gam fixed scrolldown bug after a sed_SetHeight
11/08/89 jdc added PAINTREQ message and removed remapper from
sled_SetColVar
11/08/89 jmd removed DoRaw Macro
11/21/89 gam added check for win_IsEmployed before calling RepaintFields
2/14/90 jdc messed with load code
2/23/90 jdc fixed resize code
3/14/90 jmd made sled_SetColVar a boolean
3/28/90 jmd ansi-fied
4/13/90 jmd added case for WINM_SHADOW
4/19/90 jdc preened
4/27/90 jdc preened
5/01/90 jdc added field removal for resize smaller
5/02/90 jdc readded lost information
5/08/90 jdc preened
5/30/90 jdc added better error checking in SetColVar
6/12/90 jdc tweeked so column arrays always grow evenly
fixed row protection
6/13/90 jdc fixed scrolling with protection
6/15/90 jdc added FieldCount check for sledwin_Close
6/22/90 jdc moved sledwin_Close to sledopen.c
7/11/90 pmcm added varsize 0 check to sled_SetColVar so we don't
give sa_Blank NULL sarray's
7/18/90 pmcm added bounds check of col arg to sled_SetColVar so
we don't violate the protect column data
7/25/90 jdc added fexit call in Remap
Remap now returns SED_STUCK, SED_INVALID, or SED_MOVED
put GoHome and Fenter call from spc_Sled in Remap
8/08/90 jdc fixed resize larger field adding order
8/27/90 jdc now suppresses resizing smaller than one field row
10/04/90 jmd added cast to sa_Get for C++
*/
#include "sed.h"
#include "sldwinod.h"
#include "sadecl.h"
#include "sled.h"
#include "sledprot.h"
#include "sfile.h" /* load save capability always linked in! */
int sledwin_Class(VOID *objdata, int msg, VOID *indata, VOID *outdata)
/*
Dispatch function for sed windows.
*/
{
sledwin_od *sledwd;
inposdata_struct *ipd;
ofont_type font;
sed_type sed;
int row, col, fld, i, dif, hgt, ret = TRUE;
menu_type menu;
sledwd = (sledwin_od *) objdata;
switch (msg) {
case WINM_PAINTREQ:
sled_remapper(sledod_GetSelf(sledwd), 0);
return(sedwin_Class(&(sledwd->sedwd), msg, indata, outdata));
case OBJM_LOAD:
{
/* !! no direct inheritance from sedwin_Class */
sed_type sed;
sfile_type sfile;
sed = sledod_GetSelf(sledwd);
sfile = (sfile_type)indata;
if (!win_Class(&(sledwd->sedwd.wd), msg, indata, outdata)
|| !sed_Init(sed, sf_loadmenu(sfile))) {
sed_Close(sed);
return(FALSE);
}
if (!sled_Init(sed, 1, FNULL) || !sed_load(sfile, sed)) {
sledwin_Close(sed);
sed_Close(sed);
return(FALSE);
}
break;
}
case OBJM_GETDATASIZE:
((ogds_struct *) outdata)->odsize = sizeof(sledwin_od);
((ogds_struct *) outdata)->xdsize = sizeof(sled_xd);
((ogds_struct *) outdata)->id = ID_SLEDWIN;
break;
case OBJM_WHO:
/* Identify ourselves */
if (*((int *) indata) == ID_SLEDWIN) {
return(TRUE);
}
return(sedwin_Class(&(sledwd->sedwd), msg, indata, outdata));
case WINM_SETSIZE:
sed = sledod_GetSelf(sledwd);
/* remember old size */
hgt = sed_GetHeight(sed);
col = sed_GetWidth(sed);
/* only continue if menu exists */
if ((menu = sed_GetMenu(sed)) == NULL) {
sedwin_Class(&(sledwd->sedwd), msg, indata, outdata);
break;
}
if (((opoint *)indata)->y / ofont_GetHeight(win_GetFont(sed))
< menu_GetFieldRow(sed_GetMenu(sed), 0) + 1) {
/* don't shrink less than one field row */
((opoint *)indata)->y =
(menu_GetFieldRow(sed_GetMenu(sed), 0) + 1)
* ofont_GetHeight(win_GetFont(sed));
}
/* resize sed */
sedwin_Class(&(sledwd->sedwd), msg, indata, outdata);
if (sed_GetWidth(sed) > col
&& (dif = sed_GetWidth(sed) + sed_GetXoffset(sed)
- menu_GetFieldLastCol(menu, sed_GetFieldNo(sed)) - 1) > 0) {
sed_ScrollLeft(sed, (dif > sed_GetXoffset(sed))
? sed_GetXoffset(sed) : dif);
}
if (sed_GetHeight(sed) < hgt) {
/* smaller */
if ((row = hgt - sed_GetHeight(sed))
>= menu_GetFieldCount(menu) / sled_GetWidth(sed)) {
row = menu_GetFieldCount(menu) / sled_GetWidth(sed) - 1;
}
/* reposition highlight, UpField takes care of protection */
i = sed_GetHeight(sed) - menu_GetFieldRow(sed_GetMenu(sed), 0);
do {
i--;
if (i < 0 || (fld = sed_GetGridField(sed, i, sled_GetCol(sed))) < 0) {
fld = -1;
break;
}
else if (sed_GetFieldNo(sed) <= fld) {
fld = sed_GetFieldNo(sed);
break;
}
} while (sed_IsProtectedField(sed, fld));
if (fld == -1) {
sled_Remap(sed, -1);
}
else {
sed_GotoField(sed, fld);
}
if (row > 0) {
sed_DeleteRows(sed, sed_GetHeight(sed), row);
}
break;
}
/* larger */
col = 0;
dif = sed_GetHeight(sed) - hgt;
sed_DoSexits(sed);
/* add fields */
for (i = hgt; i < sed_GetHeight(sed); i++) {
for (fld = 0; fld >= 0; fld = menu_GetFieldRight(menu, fld)) {
ret = menu_CopyField(menu, i, menu_GetFieldCol(menu, fld), menu, fld);
}
}
/* adjust the sled offset if possible */
if (sled_GetOffset(sed) + sed_GetHeight(sed) - 1 > sled_GetColSize(sed)
&& (col = sled_GetOffset(sed)) > 0) {
col = (col < dif) ? col : dif;
}
sled_remapper(sed, -col);
sed_DoSenters(sed);
if (win_IsEmployed(sed)) sed_Update(sed);
/* adjust field for remapping */
if (col != 0) {
sed_GotoGridField(sed, sed_GetGridRow(sed, sed_GetFieldNo(sed)) + col,
sed_GetGridCol(sed, sed_GetFieldNo(sed)));
}
break;
case WINM_SCROLLREQ:
/* A request to scroll the sled */
sed = sledod_GetSelf(sledwd);
row = ((opoint *)indata)->y / win_GetFontHeight(sed);
col = ((opoint *)indata)->x / win_GetFontWidth(sed);
if (col < 0) {
sed_ScrollLeft(sed, -col);
}
else if (col > 0) {
sed_ScrollRight(sed, col);
}
if (row != 0 && sled_Remap(sed, row)) {
/* the field should appear to be newly entered */
sed_GoHome(sed);
sed_DoFieldFenter(sed, sed_GetFieldNo(sed));
}
break;
case WINM_GETINPOS:
/* get the menu size relative to the sed
so that borders can compute scroll lights
*/
ipd = (inposdata_struct *)outdata;
font = win_GetFont(ipd->win);
sed = sledod_GetSelf(sledwd);
if (sed_GetMenu(sed) != NULL) {
/* Xoffset same as seds */
ipd->inbox.xmin = - (sed_GetXoffset(sed) * ofont_GetWidth(font));
ipd->inbox.xmax = ipd->inbox.xmin +
(sed_GetMenuVWidth(sed) * ofont_GetWidth(font));
/* but not Yoffset */
ipd->inbox.ymin = - ((sed_GetYoffset(sed) + sled_GetOffset(sed)) * ofont_GetHeight(font));
ipd->inbox.ymax = ipd->inbox.ymin +
(sled_GetColSize(sed) + menu_GetFieldRow(sed_GetMenu(sed), 0))
* ofont_GetHeight(font);
}
break;
case WINM_SHADOW:
case WINM_PAINT:
/* Set field blanking flag to prevent painting of
fields past the current last row of the sled
*/
sed = sledod_GetSelf(sledwd);
sledwd->sedwd.blank = sled_GetColSize(sed) - sled_GetOffset(sed)
+ field_GetRow(sed_GetField(sed, 0));
/* pass message up to sed superclass */
sedwin_Class(&(sledwd->sedwd), msg, indata, outdata);
/* reset blanking flag */
sledwd->sedwd.blank = -1;
break;
case OBJM_CLOSE:
sledwin_Close(sledod_GetSelf(sledwd));
/* No Break; fall through to default */
default:
return(sedwin_Class(&(sledwd->sedwd), msg, indata, outdata));
}
return(ret);
}
/* Auxillary Functions */
int sled_Remap(sed_type sed, int offset)
/*
*/
{
boolean ret = TRUE;
int row, oldoffset, i;
oldoffset = offset;
row = sled_GetRow(sed);
if (offset < 0) {
/* can't go to row < 0 */
if (row == 0) return(SED_STUCK);
if ((i = row + offset) < 0) i = 0;
/* adjust for row protection */
for ( ; sled_IsProtectedRow(sed, i); i--) {
if (i == 0) return(SED_STUCK);
}
offset = i - row;
}
else if (offset > 0) {
/* can't go to row >= sled_GetColSize(sed) */
if (row == sled_GetColSize(sed) - 1) return(SED_STUCK);
if ((i = row + offset) >= sled_GetColSize(sed)) {
i = sled_GetColSize(sed) - 1;
}
/* adjust for row protection */
for ( ; sled_IsProtectedRow(sed, i); i++) {
if (i >= sled_GetColSize(sed) - 1) return(SED_STUCK);
}
offset = i - row;
}
if (!sd_exitfield(sed)) return(SED_INVALID);
sed_DoSexits(sed);
if (offset != 0 && (ret = sled_remapper(sed, offset)) == TRUE) {
/* Move out of Protected Row in the original direction */
if (sled_IsProtectedRow(sed, sled_GetRow(sed))) {
if (oldoffset < 0) {
sed_UpField(sed);
}
else {
sed_DownField(sed);
}
}
if (win_IsEmployed(sed)) {
sed_RepaintFields(sed);
}
else {
sed_DoSenters(sed);
}
}
/* the field should appear to be newly entered */
sed_GoHome(sed);
sed_DoFieldFenter(sed, sed_GetFieldNo(sed));
return((ret == TRUE) ? SED_MOVED : SED_STUCK);
}
VOID *sled_GetColVar(sed_type sed, int col, int row)
/*
*/
{
return(sa_Get((sarray_type) xa_Get(sled_GetXa(sed), col), (long)row));
}
boolean sled_SetColVar(sed_type sed, int col, int row, VOID *data)
/*
*/
{
int i, len;
sarray_type sa;
if (col >= sled_GetWidth(sed)) {
return(FALSE);
}
if ((len = row - sled_GetColSize(sed) + 1) > 0) {
for (i = 0; i < sled_GetWidth(sed); i++) {
if (sed_GetVarSize(sed, sed_GetGridField(sed, 0, i) ) != 0) {
sa = (sarray_type) xa_Get(sled_GetXa(sed), i);
if (sa_Blank(sa, (long) sled_GetColSize(sed), len, FALSE) == NULL) {
return(FALSE);
}
}
}
sled_SetColSize(sed, row + 1);
sed_SendBorderMsg(sed, BDM_SCROLL, NULL, NULL);
}
sa = (sarray_type) xa_Get(sled_GetXa(sed), col);
return(sa_Put(sa, (long)row, data) != NULL);
}
int sled_getrowspecial(sed_type sed, int row)
{
int *temp;
temp = (int *)sa_Get((sarray_type) xa_Get(sled_GetXa(sed), sled_GetWidth(sed)), (long)(row));
if (temp == NULL) {
return(0);
}
else {
return(*temp);
}
}