home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
archives
/
atarist.tar.gz
/
atarist.tar
/
astgem.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-06-19
|
9KB
|
369 lines
/*
* "astgem.c" ATARI ST GEM Window & Screen Management
*/
#include <osbind.h> /* TOS binding */
#include <stdio.h> /* common I/O defs */
#include <obdefs.h> /* common Object definitions */
#include <gemdefs.h> /* common GEM definitions */
#include "astinc.h" /* common KERMIT definitions */
#include "astobj.h" /* KERMIT object definitions */
extern FILE *fopen(),*fopenb();
/* communication variables for AES & VDI */
int contrl[12];
int intin[128];
int ptsin[128];
int intout[128];
int ptsout[128];
int workin[12];
int workout[57];
/* global variables */
int vdi_handle; /* handle for workstation */
int wi_handle; /* handle for one (fake) window */
int ap_id;
OBJECT /* addrs of objects */
*menu_addr,
*obj_addr;
int mbuf[8]; /* message buffer */
int gl_wchar, gl_hchar, gl_wbox, gl_hbox; /* parameters of virt. works. */
int xdesk, ydesk, hdesk, wdesk; /* desktop parameters */
/* initialize screen */
w_init_screen()
{int i,dummy;
ap_id = appl_init();
vdi_handle = graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox);
wind_get(0,WF_WORKXYWH,&xdesk,&ydesk,&wdesk,&hdesk);
for (i = 0; i < 10; i++) workin[i] = 1;
workin[10] = 2; /* use RC coordinates */
v_opnvwk(workin, &vdi_handle, workout);
if (!rsrc_load(KER_RSC))
{form_error(2);
return FALSE;
};
if (rsrc_gaddr(0,0,&menu_addr) == 0)
{form_alert(1,"[3][Resource File Format?][ABORT]");
return FALSE;
};
rsrc_gaddr(R_TREE,KERMENU,&menu_addr);
menu_bar(menu_addr,1);
return TRUE;
}
/* terminate code for screen management */
w_exit_screen()
{
v_clsvwk(vdi_handle);
appl_exit();
}
/* the main dispatcher */
w_multi()
{char *objstr;
check_options();
fgetpath(kpathname);
fgetpath(gpathname);
graf_mouse(ARROW,0x0L);
while (TRUE)
{evnt_mesag(mbuf);
wind_update(1); /* deselect menu */
if (mbuf[0] == MN_SELECTED)
{switch (mbuf[3])
{case MDESK: /* Desk */
if (mbuf[4] == ABOUTKER)
{
rsrc_gaddr(R_TREE,KRABOUT,&obj_addr);
objstr = (obj_addr[KRAVMM].ob_spec)->te_ptext;
sprintf(objstr,"%2d%02d",VERSION,RELEASE);
objstr = (obj_addr[KRAVDAT].ob_spec)->te_ptext;
sprintf(objstr,VERDATE);
displ_object(KRABOUT,-1,-1,MDESK,&obj_addr);
form_do(obj_addr,-1);
destroy_object(KRABOUT,-1,-1,MDESK);
change_state(obj_addr,KRABOUOK,NORMAL);
};
break;
case MFILE: /* File Menu */
switch (mbuf[4])
{case FQUIT:
fsetpath(kpathname);
if (debug) fclose(deb);
if (translog) fclose(log);
wind_update(0);
return; /* return and quit */
case FDELETE:
mdelfile(); break;
case FTYPE:
mtypefile(); break;
case FRENAME:
mrenfile(); break;
case FDFREE:
mdfree(); break;
}; /* switch on mbuf[4] in case MFILE */
break;
case MTRANS: /* Transfer Menu */
do_transfer(mbuf[4]);
break;
case MOPTION:
do_options(mbuf[4]);
break;
}; /* switch on mbuf[3] */
menu_tnormal(menu_addr,mbuf[3],1);
}; /* if message for us */
wind_update(0);
}; /* while */
} /* w_multi */
/*
* display an alert message
*/
displ_alert(cnt,obix)
int cnt,obix;
{long aaddr;
rsrc_gaddr(R_STRING,obix,&aaddr);
cnt = form_alert(cnt,aaddr);
return cnt;
}
/*
* change state of an object but don't display
*/
change_state(tree,ix,state)
long tree;
int state,ix;
{
objc_change(tree,ix,0,xdesk,ydesk,wdesk,hdesk,state,0);
}
/*
* draw an object
*/
displ_object(ix, x, y, menuix, ad)
int ix, x, y, menuix;
long int *ad;
/* if x or y < 0 then the centered position is used */
/* if y == 0 then y will be half a box below the menu bar */
/* otherwise the new x,y positions are used
/* menuix is the subindex of a menu title which is used for */
/* dial form. if -1 no growing box is displayed */
/* if -2 no dial form */
{ int obj_x, obj_y, obj_w, obj_h;
rsrc_gaddr(R_TREE,ix,ad);
form_center(*ad,&obj_x,&obj_y,&obj_w,&obj_h);
obj_x = ((x >= 0) ? x : obj_x);
y = ((y == 0) ? (ydesk+(gl_hbox/3)) : y);
obj_y = ((y >= 0) ? y : obj_y);
(*ad)->ob_x = obj_x + 3;
(*ad)->ob_y = obj_y + 3;
if (menuix == -1)
form_dial(0,0,0,0,0,obj_x,obj_y,obj_w,obj_h);
else if (menuix >= 0)
{
form_dial(0,menu_addr[menuix].ob_x,0,4*gl_wbox,gl_hbox,
obj_x,obj_y,obj_w,obj_h);
form_dial(1,menu_addr[menuix].ob_x,0,4*gl_wbox,gl_hbox,
obj_x,obj_y,obj_w,obj_h);
};
objc_draw(*ad,ROOT,MAX_DEPTH,obj_x,obj_y,obj_w,obj_h);
}
/*
* destroy an object
*/
destroy_object(ix, x, y, menuix)
int ix, x, y, menuix;
/* same parameter conventions as above */
{long ad;
int obj_x, obj_y, obj_w, obj_h;
rsrc_gaddr(R_TREE,ix,&ad);
form_center(ad,&obj_x,&obj_y,&obj_w,&obj_h);
obj_x = ((x >= 0) ? x : obj_x);
y = ((y == 0) ? (ydesk+(gl_hbox/3)) : y);
obj_y = ((y >= 0) ? y : obj_y);
(ad)->ob_x = obj_x + 3;
(ad)->ob_y = obj_y + 3;
if (menuix == -1)
form_dial(3,0,0,0,0,obj_x,obj_y,obj_w,obj_h);
else if (menuix >= 0)
{
form_dial(2,menu_addr[menuix].ob_x,0,4*gl_wbox,gl_hbox,
obj_x,obj_y,obj_w,obj_h);
form_dial(3,menu_addr[menuix].ob_x,0,4*gl_wbox,gl_hbox,
obj_x,obj_y,obj_w,obj_h);
};
}
/*
* some terminal functions
*/
/*
* type out a file in terminal mode
*/
mtypefile()
{
int lcnt;
char c, resp;
char *cp;
displ_object(KRMDOTYP,-1,0,MFILE,&obj_addr);
if (!fsetfilename(gpathname,filnam))
{destroy_object(KRMDOTYP,-1,0,MFILE);
return;
};
fp = fopen(filnam,"r");
if (fp == NIL)
{displ_alert(1,KRFILNEX);
destroy_object(KRMDOTYP,-1,0,MFILE);
return;};
destroy_object(KRMDOTYP,-1,0,MFILE);
menu_tnormal(menu_addr,MFILE,1);
init_terminal();
rsrc_gaddr(R_TREE,KRMESSS,&obj_addr);
while (Cconis()) Cnecin();
lcnt = 0;
while (TRUE)
{c = getc(fp);
if (feof(fp) || ferror(fp)) break;
Crawio(c);
if (c == '\n')
{Crawio(CR);
if (++lcnt > 22)
{lcnt = 0;
for (cp = obj_addr[MSMORE].ob_spec; *cp; cp++)
Crawio(*cp);
resp = Crawcin();
if (resp == ETX) break;
Crawio(CR);
v_eeol(vdi_handle);
};
};
};
if (resp != ETX)
{Crawio(CR);
Crawio(LF);
for (cp = obj_addr[MSEOF].ob_spec; *cp; cp++)
Crawio(*cp);
Crawcin();
};
fclose(fp);
exit_terminal();
}
/*
* init workstation as a terminal
*/
int init_terminal()
{
graf_mouse(M_OFF,NIL);
wi_handle = wind_create(0,xdesk,ydesk,wdesk,hdesk);
graf_growbox(menu_addr[MFILE].ob_x,0,4*gl_wbox,gl_hbox,
xdesk,ydesk,wdesk,hdesk);
wind_open(wi_handle,xdesk,ydesk,wdesk,hdesk);
v_enter_cur(vdi_handle);
v_curhome(vdi_handle);
v_eeos(vdi_handle);
}
/*
* exit terminal mode
*/
exit_terminal()
{
v_curhome(vdi_handle);
v_eeos(vdi_handle);
v_exit_cur(vdi_handle);
menu_bar(menu_addr,1);
wind_close(wi_handle);
wind_delete(wi_handle);
graf_shrinkbox(menu_addr[MFILE].ob_x,0,gl_wbox,gl_hbox,
xdesk,ydesk,wdesk,hdesk);
graf_mouse(M_ON,NIL);
}
/*
* ask for file and delete
*/
mdelfile()
{long addr;
displ_object(KRMDODEL,-1,0,MFILE,&addr);
if (fsetfilename(gpathname,filnam))
if (access(filnam,4) != 0)
displ_alert(1,KRFILNEX);
else
{
if (unlink(filnam) != 0)
displ_alert(1,KRDELERR);
else
displ_alert(1,KRDELDON);
};
destroy_object(KRMDODEL,-1,0,MFILE);
};
/*
* rename a file
*/
mrenfile()
{char oname[FILNAMLEN],
nname[FILNAMLEN];
OBJECT *objp;
int objx;
displ_object(KRMDOREN,-1,0,MFILE,&objp);
objx = KRMDOREN;
if (fsetfilename(gpathname,filnam))
if (access(filnam,4) != 0)
displ_alert(1,KRFILNEX);
else
{strcpy(oname,gpathname);
strcat(oname,filnam);
destroy_object(KRMDOREN,-1,0,MFILE);
displ_object(KRMDORE2,-1,0,MFILE,&objx);
objx = KRMDORE2;
if (fsetfilename(gpathname,filnam))
if (access(filnam,2) == 0)
displ_alert(1,KRFILEX);
else
{strcpy(nname,gpathname);
strcat(nname,filnam);
destroy_object(KRMDORE2,-1,0,MFILE);
objx = -1;
if (Frename(0,oname,nname) != 0)
displ_alert(1,KRRENERR);
else
displ_alert(1,KRRENDON);
};
};
if (objx >= 0)
destroy_object(objx,-1,0,MFILE);
}
/* display free disk space */
mdfree()
{OBJECT *objp;
char *bytp, *idp;
long int infbuf[4];
rsrc_gaddr(R_TREE,KRDFREE,&objp);
bytp = objp[KRDFBY].ob_spec->te_ptext;
idp = objp[KRDFID].ob_spec->te_ptext;
*bytp = '\0';
*idp = Dgetdrv() + 'A';
displ_object(KRDFREE,-1,-1,MFILE,&objp);
form_do(objp,KRDFID);
change_state(objp,KRDFOK,NORMAL);
if (Dfree(infbuf,*idp - 'A' + 1) != 0)
strcpy(bytp,"????????");
else
sprintf(bytp,"%ld",(infbuf[0] * infbuf[2] * infbuf[3]));
displ_object(KRDFREE,-1,-1,-2,&objp);
form_do(objp,-1);
change_state(objp,KRDFOK,NORMAL);
destroy_object(KRDFREE,-1,-1,MFILE);
}