home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Crawly Crypt Collection 2
/
crawlyvol2.bin
/
apps
/
dtp
/
ghost
/
gs301src
/
atari
/
gp_atar2.c
< prev
next >
Wrap
Text File
|
1994-09-17
|
47KB
|
2,248 lines
/* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises. All rights reserved.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
copies. */
/* gp_atar2.c */
/*
* This file contains most of the routines that deal with windows on
* the Atari platform.
*/
#include "gp_atar2.h"
extern stream *gs_stream_stdin; /* from ziodev.c */
extern stream *gs_stream_stdout; /* from ziodev.c */
extern stream *gs_stream_stderr; /* from ziodev.c */
extern VWRK VWork; /* from gp_atar1.h */
extern PSTATE State; /* from gp_atar1.h */
extern OBJECT menuobj[], aboutobj[], iconobj[]; /* from gp_atar1.h */
extern OBJECT resobj[], devobj[], sizobj[]; /* from gp_atar1.h */
extern OBJECT printobj[]; /* from gp_atar1.h */
extern FILE *OutFile; /* from gp_atar3.c */
extern GRAPHIC Graphic; /* from gdevvdi.c */
extern int txtw_redraw(), objw_redraw(), bitw_redraw();
extern int txtw_move(), objw_move(), bitw_move();
extern int txtw_size(), bitw_size();
extern int txtw_arrow(), bitw_arrow();
extern int txtw_hslide(), bitw_hslide();
extern int txtw_vslide(), bitw_vslide();
extern int res_button(), abo_button(), dev_button();
extern int siz_button(), prn_button(), pag_button(), ign_button();
extern WINLIST *WinListAdd(), *WinListDelete(); /* from gp_atar3.c */
WINLIST *WList;
void *ObjFindH();
WINDOW *WinFindH();
WINDOW *WinFindXY();
/* Declare and assign window structures. See ataridef.h for the
* DEFINE_XXXWIN macro.
*/
WINTEXT Cons = DEFINE_WINTEXT;
WINDOW aboutwin = DEFINE_OBJWIN(aboutobj, A_GADGETS, A_TITL, NULL, abo_button);
WINDOW reswin = DEFINE_OBJWIN(resobj, R_GADGETS, R_TITL, NULL, res_button);
WINDOW devwin = DEFINE_OBJWIN(devobj, D_GADGETS, D_TITL, NULL, dev_button);
WINDOW sizwin = DEFINE_OBJWIN(sizobj, S_GADGETS, S_TITL, NULL, siz_button);
WINDOW iconwin = DEFINE_OBJWIN(iconobj, I_GADGETS, I_TITL, NULL, ign_button);
WINDOW printwin = DEFINE_OBJWIN(printobj, O_GADGETS, O_TITL, NULL, prn_button);
WINDOW pagewin = DEFINE_OBJWIN(NULL , P_GADGETS, P_TITL, NULL, pag_button);
WINDOW imagwin = DEFINE_BITWIN(&Graphic, B_GADGETS, B_TITL, NULL, ign_button);
WINDOW conswin = DEFINE_TEXTWIN(&Cons, T_GADGETS, T_TITL, NULL, ign_button);
EVENT Event = DEFINE_EVENT;
/* The following method for redirecting stdio to a window was
* stolen from the Microsoft Windows driver.
*/
gx_io_device gs_iodev_wstdio = {
"wstdio", "Special",
{ win_stdio_init, iodev_no_open_device,
iodev_no_open_file, iodev_no_fopen, iodev_no_fclose,
iodev_no_delete_file, iodev_no_rename_file,
iodev_no_file_status, iodev_no_enumerate_files
}
};
/* reinitialize stdin/out/err to use windows */
/* assume stream has already been initialized for the real stdin */
#define win_stdin_buf_size 160
private int
win_stdio_init(gx_io_device *iodev, gs_memory_t *mem)
{
if (State.Windows) {
if ( gp_file_is_console(gs_stream_stdin->file) ) {
/* Allocate a real buffer for stdin. */
/* The size must not exceed the size of the */
/* lineedit buffer. (This is a hack.) */
static const stream_procs pin =
{ s_std_noavailable, s_std_noseek, s_std_read_reset,
s_std_read_flush, s_std_close,
win_std_read_process
};
byte *buf = gs_alloc_bytes(gs_stream_stdin->memory,
win_stdin_buf_size,
"win_stdin_init");
s_std_init(gs_stream_stdin, buf, win_stdin_buf_size,
&pin, s_mode_read);
gs_stream_stdin->file = NULL;
}
{
static const stream_procs pout =
{ s_std_noavailable, s_std_noseek, s_std_write_reset,
s_std_write_flush, s_std_close,
win_std_write_process
};
if ( gp_file_is_console(gs_stream_stdout->file) ) {
gs_stream_stdout->procs = pout;
gs_stream_stdout->file = NULL;
}
if ( gp_file_is_console(gs_stream_stderr->file) ) {
gs_stream_stderr->procs = pout;
gs_stream_stderr->file = NULL;
}
}
}
}
#define ERASELINE 21 /* ^U */
#define ERASECHAR1 8 /* ^H */
#define ERASECHAR2 127 /* DEL */
/* Handle all user input. This contains the main event loop for
* Atari windows.
*/
private int
win_std_read_process(stream_state *sst, stream_cursor_read *ignore_pr,
stream_cursor_write *pw, bool last)
{
byte *buf = pw->ptr;
byte *dest = buf;
byte *limit = pw->limit - 1; /* always leave room for \n */
int ChangeX, ChangeY;
int loop_end=0;
char *sptr; /* generic string pointer */
/* Main Event Loop */
if (State.Windows) {
State.Event->WaitEvent = MU_MESAG | MU_KEYBD | MU_BUTTON;
State.Event->WaitButtonState = 1;
}
while (!loop_end && State.Windows) {
/* Find the top window. */
int empty;
WINDOW *tpwin;
wind_get(0, WF_TOP, &State.TopWin, &empty, &empty, &empty);
tpwin = WinFindH(State.TopWin);
graf_mouse(ARROW, 0L);
/* Ensure mouse and menus are in a reasonable state. */
menu_ienable(menuobj, COPY, imagwin.opened);
menu_ienable(menuobj, CLOSE, (tpwin->gadgets & CLOSER));
if (State.Event->KeyMenu) { /* fake menu events for hot keys */
State.Event->Event = MU_MESAG;
State.Event->Message[0] = MN_SELECTED;
State.Event->Message[3] = -1;
State.Event->Message[4] = State.Event->KeyMenu;
State.Event->KeyMenu = 0;
}
else if (State.Event->KeyScroll >= 0) {
WINDOW *win = WinFindXY(State.Event->MouseX, State.Event->MouseY);
State.Event->Event = 0;
if (win != NULL) {
if (win->handle != conswin.handle) {
State.Event->Event = MU_MESAG;
State.Event->Message[0] = WM_ARROWED;
State.Event->Message[3] = win->handle;
State.Event->Message[4] = State.Event->KeyScroll;
}
}
State.Event->KeyScroll = -1;
}
else {
State.Event->Event = evnt_multi(
State.Event->WaitEvent,
2,
1,
State.Event->WaitButtonState,
1,
State.Event->MouseX,
State.Event->MouseY,
1,
1,
0,
0,
0,
0,
0,
State.Event->Message,
0L,
&State.Event->MouseX,
&State.Event->MouseY,
&State.Event->ButtonState,
&State.Event->KeyState,
&State.Event->Key,
&State.Event->Clicks);
}
if (State.Event->Event & MU_BUTTON) { /* button events */
loop_end = HandleButton(&VWork, &State, &Graphic, pw, &dest);
}
if (State.Event->Event & MU_KEYBD) { /* keyboard input */
loop_end = HandleKeybd(&VWork, &State, pw, &dest);
}
if (State.Event->Event & MU_MESAG) { /* message events */
switch (State.Event->Message[0]) {
case MN_SELECTED:
loop_end = HandleMenu(&VWork, &State, &Graphic, pw, &dest);
break;
case WM_REDRAW:
{
static int FirstConsRedraw = 1;
/* Ignore the very first console redraw message. */
if ((State.Event->Message[3] == conswin.handle) &&
FirstConsRedraw) {
FirstConsRedraw = 0;
}
else {
cursor(OFF);
HandleRedraw(DIRT_RECT, &State);
cursor(ON);
}
}
break;
case WM_ARROWED:
HandleArrow(&State);
break;
case WM_HSLID:
HorizontalSlider(&State);
break;
case WM_VSLID:
VerticalSlider(&State);
break;
case WM_TOPPED:
wind_set(State.Event->Message[3], WF_TOP, 0, 0, 0, 0);
/* intentional fall-through */
case WM_ONTOP:
HandleOntop(&VWork);
break;
case WM_UNTOPPED:
HandleUntop(&VWork);
break;
case WM_CLOSED:
loop_end = HandleClose(&State, pw, &dest);
break;
case WM_FULLED:
HandleFull(&State, &VWork);
break;
case WM_MOVED:
HandleMove(&State);
break;
case WM_SIZED:
HandleSize(&State);
break;
case WM_BOTTOMED: /* CF */
wind_set(State.Event->Message[3], WF_BOTTOM, 0, 0, 0, 0);
break;
case WM_ICONIFY:
case WM_ALLICONIFY: /* CF */
HandleIcon(&VWork, &State);
break;
case WM_UNICONIFY: /* CF */
HandleUnIcon(&State);
break;
case COMMAND:
dprintf1("%s", State.Command);
graf_mouse(BUSY_BEE, 0L);
loop_end = 1;
break;
case PGFILTER:
graf_mouse(BUSY_BEE, 0L);
HandlePageFilter(&VWork, &State, pw, &dest);
graf_mouse(ARROW, 0L);
break;
case PGSELECT:
graf_mouse(BUSY_BEE, 0L);
HandlePageSelect(&VWork, &State, pw, &dest, State.Event->Message[1]);
graf_mouse(ARROW, 0L);
break;
}
}
}
return 0;
}
int
HandleMenu(VWRK *vw, PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
{
char *sptr;
byte res[4];
byte cone, cten, chun;
long diffone=0, difften=0, diffhun=0;
int loop_end=0;
if (st->Event->Message[3] != -1) {
menu_tnormal(menuobj, st->Event->Message[3], 1);
}
switch (st->Event->Message[4]) {
case ABOUT:
WinListAdd(WList, &aboutwin);
ObjWinOpen(aboutobj, &aboutwin, vw, st);
break;
case OPEN:
if (st->Event->KeyState) {
HandleHelp(OPENHELP, vw, st, pw, dest);
}
else {
st->SelectPages = 0;
menu_ienable(menuobj, PREV, 0);
menu_ienable(menuobj, NEXT, 1);
loop_end = HandleOpen(vw, st, pw, dest);
}
break;
case PAGES:
if (st->Event->KeyState) {
HandleHelp(PAGHELP, vw, st, pw, dest);
}
else {
st->SelectPages = 1;
menu_ienable(menuobj, PREV, 0);
menu_ienable(menuobj, NEXT, 0);
loop_end = HandleOpen(vw, st, pw, dest);
}
break;
case PRINT:
if (st->Event->KeyState) {
HandleHelp(OUTHELP, vw, st, pw, dest);
}
else {
WinListAdd(WList, &printwin);
ObjWinOpen(printobj, &printwin, vw, st);
}
break;
case PREV:
if (st->Event->KeyState) {
HandleHelp(PREVHELP, vw, st, pw, dest);
}
else {
loop_end = HandlePrev(st);
}
break;
case NEXT:
if (st->Event->KeyState) {
HandleHelp(NEXTHELP, vw, st, pw, dest);
}
else {
loop_end = HandleNext(st, pw, dest);
}
break;
case LOAD:
if (st->Event->KeyState) {
HandleHelp(LOADHELP, vw, st, pw, dest);
}
else {
LoadConfig(vw, st);
}
break;
case SAVE:
if (st->Event->KeyState) {
HandleHelp(SAVEHELP, vw, st, pw, dest);
}
else {
SaveConfig(vw, st);
}
break;
case QUIT:
graf_mouse(BUSY_BEE, 0L);
gs_exit(0); /* Cleanup is done in gp_exit. */
break;
case DEVICE:
if (st->Event->KeyState) {
HandleHelp(DEVHELP, vw, st, pw, dest);
}
else {
DevObjUpdate(st);
WinListAdd(WList, &devwin);
ObjWinOpen(devobj, &devwin, vw, st);
}
break;
case RES:
if (st->Event->KeyState) {
HandleHelp(RESHELP, vw, st, pw, dest);
}
else {
/* Get an ascii representation of the dialog setting. */
cone = *(byte *)(&resobj[RES_ONE].ob_spec);
cten = *(byte *)(&resobj[RES_TEN].ob_spec);
chun = *(byte *)(&resobj[RES_HUN].ob_spec);
/* Get and ascii representation of the current resolution. */
itoa(gr->XRes, res);
/* Calculate the difference, if any. */
switch (strlen(res)) {
case 3:
diffhun = (res[0] - chun) * 0x01000000L;
difften = (res[1] - cten) * 0x01000000L;
diffone = (res[2] - cone) * 0x01000000L;
break;
case 2:
difften = (res[0] - cten) * 0x01000000L;
diffone = (res[1] - cone) * 0x01000000L;
break;
case 1:
diffone = (res[0] - cone) * 0x01000000L;
break;
}
/* Fix the object to display the current resolution. */
resobj[RES_ONE].ob_spec += diffone;
resobj[RES_TEN].ob_spec += difften;
resobj[RES_HUN].ob_spec += diffhun;
WinListAdd(WList, &reswin);
ObjWinOpen(resobj, &reswin, vw, st);
}
break;
case PAGESIZE:
if (st->Event->KeyState) {
HandleHelp(SIZHELP, vw, st, pw, dest);
}
else {
WinListAdd(WList, &sizwin);
ObjWinOpen(sizobj, &sizwin, vw, st);
}
break;
case NOPAUSE:
if (st->Event->KeyState) {
HandleHelp(PAUSEHELP, vw, st, pw, dest);
}
else {
menu_icheck(menuobj, NOPAUSE,
(menuobj[NOPAUSE].ob_state ^ CHECKED));
if (menuobj[NOPAUSE].ob_state & CHECKED) {
strcpy(st->Command, "/NOPAUSE {true} def\n");
}
else {
strcpy(st->Command, "/NOPAUSE {false} def\n");
}
SendCommand(st, pw, dest);
}
break;
case PSHELP:
if (st->Event->KeyState) {
HandleHelp(PSFHELP, vw, st, pw, dest);
}
else {
menu_icheck(menuobj, PSHELP,
(menuobj[PSHELP].ob_state ^ CHECKED));
st->PSHelp = !st->PSHelp;
}
break;
case ICON:
if (st->Event->KeyState) {
HandleHelp(ICONHELP, vw, st, pw, dest);
}
else {
HandleMenuIcon(vw, st);
}
break;
case CYCLEF:
case CYCLEB:
if (st->Event->KeyState) {
HandleHelp(CYCLEHELP, vw, st, pw, dest);
}
else {
HandleCycle(st->Event->Message[4]);
}
break;
case CLOSE:
if (st->Event->KeyState) {
HandleHelp(CLOSEHELP, vw, st, pw, dest);
}
else {
st->Event->Message[3] = st->TopWin;
loop_end = HandleClose(st, pw, &dest);
}
break;
case COPY:
if (st->Event->KeyState) {
HandleHelp(COPYHELP, vw, st, pw, dest);
}
else if (imagwin.opened) {
CopyImage(gr, vw, st);
}
else {
form_alert(1, "[1][Ghostscript Error!|Nothing to Copy.][Continue]");
}
break;
}
return loop_end;
}
int
HandleHelp(char *file, VWRK *vw, PSTATE *st, stream_cursor_write *pw, byte **dest)
{
char helpfile[MAXLEN];
strcpy(helpfile, file);
if (st->PSHelp) {
sprintf(st->Command, "(%s%s) runlibfile\n", helpfile, ".ps");
SendCommand(st, pw, dest);
}
else {
graf_mouse(BUSY_BEE, 0L);
strcat(helpfile, ".hlp");
HelpWinOpen(vw, st, helpfile);
graf_mouse(ARROW, 0L);
}
}
int
HandleOpen(VWRK *vw, PSTATE *st, stream_cursor_write *pw, byte **dest)
{
char *sptr, temp[MAXLEN]="";
WINTEXT *text = conswin.obj;
int loop_end=0;
int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
/* If return was not pressed after a showpage,
* then enter a return and send a message to
* redraw the image window and run a new program
* the next time through the event loop.
*/
if ((sptr = strstr(text->buff[prevline], ">>")) != NULL) {
strcpy(st->Command, "\n");
SendCommand(st, pw, dest);
if (imagwin.opened && !imagwin.iconified) {
st->Event->SendMsg[0] = WM_REDRAW;
st->Event->SendMsg[3] = imagwin.handle;
st->Event->SendMsg[4] = imagwin.canvas.g_x;
st->Event->SendMsg[5] = imagwin.canvas.g_y;
st->Event->SendMsg[6] = imagwin.canvas.g_w;
st->Event->SendMsg[7] = imagwin.canvas.g_h;
appl_write(st->ApId, 16, st->Event->SendMsg);
}
st->Event->SendMsg[0] = MN_SELECTED;
st->Event->SendMsg[3] = -1;
st->Event->SendMsg[4] = st->SelectPages ? PAGES : OPEN;
appl_write(st->ApId, 16, st->Event->SendMsg);
graf_mouse(BUSY_BEE, 0L);
return loop_end;
}
/* Make the current input file the default selection. */
if (strlen(st->Infile)) {
strcpy(st->FileSel, st->Infile);
}
else {
strcpy(st->FileSel, "");
}
/* Get a file from the file selector. */
if (GetFile(st, "*.PS")) {
strcpy(st->Infile, st->FileSel);
strcpy(temp, st->DirSpec);
strcat(temp, st->FileSel);
if (st->SelectPages) {
if (st->Doc->numpages > 1) {
if (strcmp(st->Doc->name, temp) == 0) {
if (!pagewin.opened) {
if (!pagewin.iconified) {
WinListAdd(WList, &pagewin);
}
ObjWinOpen((OBJECT *)pagewin.obj, &pagewin, vw, st);
}
return 0;
}
DeletePageObj(st, &pagewin);
}
/* Send a message to filter pages from the file
* after all pending events have been dispatched.
*/
st->Event->SendMsg[0] = PGFILTER;
appl_write(st->ApId, 16, st->Event->SendMsg);
}
else {
if (st->Doc->numpages > 1) {
DeletePageObj(st, &pagewin);
}
/* Execute the selected file. */
sprintf(st->Command, "(%s) run\n", temp);
SendCommand(st, pw, dest);
}
}
return loop_end;
}
int
GetFile(PSTATE *st, char *template)
{
int ExitButton;
char *sptr;
strcpy(st->DirSpec, st->CurrentDir);
strcat(st->DirSpec, template);
fsel_input(st->DirSpec, st->FileSel, &ExitButton);
if (ExitButton && strlen(st->FileSel)) {
sptr = strrchr(st->DirSpec, '\\');
*++sptr = '\0';
strcpy(st->CurrentDir, st->DirSpec);
}
return (ExitButton && strlen(st->FileSel));
}
int
HandlePrev(PSTATE *st)
{
if (st->SelectPages) {
int prevpage = st->Doc->currentpage - 1;
if (prevpage < 1) {
return 0;
}
st->Event->SendMsg[0] = PGSELECT;
st->Event->SendMsg[1] = prevpage;
appl_write(st->ApId, 16, st->Event->SendMsg);
}
return 0;
}
int
HandleNext(PSTATE *st, stream_cursor_write *pw, byte **dest)
{
if (st->SelectPages) {
int nextpage = st->Doc->currentpage + 1;
if (nextpage > st->Doc->numpages) {
return 0;
}
st->Event->SendMsg[0] = PGSELECT;
st->Event->SendMsg[1] = nextpage;
appl_write(st->ApId, 16, st->Event->SendMsg);
}
else if (imagwin.opened || imagwin.iconified) {
char *sptr;
WINTEXT *text = conswin.obj;
int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
if (imagwin.opened &&
(sptr = strstr(text->buff[prevline], ">>")) != NULL) {
st->Event->SendMsg[0] = WM_REDRAW;
st->Event->SendMsg[3] = imagwin.handle;
st->Event->SendMsg[4] = imagwin.canvas.g_x;
st->Event->SendMsg[5] = imagwin.canvas.g_y;
st->Event->SendMsg[6] = imagwin.canvas.g_w;
st->Event->SendMsg[7] = imagwin.canvas.g_h;
appl_write(st->ApId, 16, st->Event->SendMsg);
}
*++(*dest) = '\n';
gemputc('\n');
pw->ptr = *dest;
graf_mouse(BUSY_BEE, 0L);
return 1;
}
return 0;
}
int
HandleMenuIcon(VWRK *vw, PSTATE *st)
{
if (!st->MultiTOS) { /* CF */
if (iconwin.opened) {
/* Close the icon. */
wind_get(iconwin.handle, WF_CURRXYWH,
&iconwin.frame.g_x, &iconwin.frame.g_y,
&iconwin.frame.g_w, &iconwin.frame.g_h);
WinClose(&iconwin);
WList = WinListDelete(WList, &iconwin);
menu_text(menuobj, ICON, (char *) " Iconify ❎i ");
/* Open all windows in the window list. */
WinListOpen(WList);
}
else {
/* Close all windows in the window list. */
WinListClose(WList);
/* Open the icon window. */
menu_text(menuobj, ICON, (char *) " UnIconify ❎i ");
WinListAdd(WList, &iconwin);
ObjWinOpen(iconobj, &iconwin, vw, st);
}
}
}
int
HandleCycle(int direction)
{
WINLIST *wl = WList;
int topwin, empty;
wind_get(0, WF_TOP, &topwin, &empty,
&empty, &empty);
do {
/* Find the current top window. */
if (wl->Win->handle == topwin) {
/* Top the next open window in the appropriate direction. */
if (direction == CYCLEF) {
while (!wl->Next->Win->opened) wl = wl->Next;
wind_set(wl->Next->Win->handle, WF_TOP, 0, 0, 0, 0);
break;
}
else if (direction == CYCLEB) {
while (!wl->Prev->Win->opened) wl = wl->Prev;
wind_set(wl->Prev->Win->handle, WF_TOP, 0, 0, 0, 0);
break;
}
}
wl = wl->Next;
}
while (wl != WList);
}
int
HandleArrow(PSTATE *st)
{
WINDOW *win = WinFindH(st->Event->Message[3]);
(win->arrow)(st);
}
int
HorizontalSlider(PSTATE *st)
{
WINDOW *win = WinFindH(st->Event->Message[3]);
(win->hslide)(st);
}
int
VerticalSlider(PSTATE *st)
{
WINDOW *win = WinFindH(st->Event->Message[3]);
(win->vslide)(st);
update_scroll(st->Event->Message[3]);
cursor(OFF);
HandleRedraw(FULL_WIN, st);
cursor(ON);
}
int
HandleOntop(VWRK *vw)
{
if (vw->ColorBits > 1 && !vw->GSPalette && !vw->TrueColor) {
/* Restore GS palette. */
SetPalette(vw->Palette, vw);
vw->GSPalette = 1;
}
}
int
HandleUntop(VWRK *vw)
{
int topwin, empty;
WINLIST *wl = WList;
wind_get(0, WF_TOP, &topwin, &empty,
&empty, &empty);
/* If the top window is not in the window list, restore
* the system palette.
*/
if (vw->GSPalette) {
do {
if (wl->Win->handle == topwin) {
return 0;
}
}
while (wl != WList);
SetPalette(vw->OldPalette, vw);
vw->GSPalette = 0;
}
}
int
HandleClose(PSTATE *st, stream_cursor_write *pw, byte **dest)
{
char *sptr;
int loop_end=0;
int handle = st->Event->Message[3];
WINDOW *win = WinFindH(handle);
WINTEXT *text = conswin.obj;
int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
if (win == NULL) {
form_alert(1, "[1][Note!|The designated window|cannot be closed.][Continue]");
return 0;
}
if (!(win->gadgets & CLOSER)) {
form_alert(1, "[1][Note!|The designated window|cannot be closed.][Continue]");
return 0;
}
WinClose(win);
switch (win->type) {
case BIT:
/* If a return has not been entered after a
* showpage, then enter one.
*/
if (win == &imagwin &&
(sptr = strstr(text->buff[prevline], ">>")) != NULL) {
strcpy(st->Command, "\n");
SendCommand(st, pw, dest);
}
break;
}
WList = WinListDelete(WList, win);
return loop_end;
}
int
HandleFull(PSTATE *st, VWRK *vw)
{
int handle = st->Event->Message[3];
if (handle == iconwin.handle) {
st->Event->KeyMenu = ICON;
}
else {
WINDOW *win = WinFindH(handle);
st->Event->SendMsg[0] = WM_SIZED;
st->Event->SendMsg[3] = win->handle;
wind_get(win->handle, WF_CURRXYWH,
&win->frame.g_x, &win->frame.g_y,
&win->frame.g_w, &win->frame.g_h);
if (win->frame.g_x == vw->full.g_x &&
win->frame.g_y == vw->full.g_y &&
win->frame.g_w == MIN(win->mframe.g_w, vw->full.g_w) &&
win->frame.g_h == MIN(win->mframe.g_h, vw->full.g_h)) {
st->Event->SendMsg[4] = win->oframe.g_x;
st->Event->SendMsg[5] = win->oframe.g_y;
st->Event->SendMsg[6] = win->oframe.g_w;
st->Event->SendMsg[7] = win->oframe.g_h;
}
else {
win->oframe.g_x = win->frame.g_x;
win->oframe.g_y = win->frame.g_y;
win->oframe.g_w = win->frame.g_w;
win->oframe.g_h = win->frame.g_h;
st->Event->SendMsg[4] = vw->full.g_x;
st->Event->SendMsg[5] = vw->full.g_y;
st->Event->SendMsg[6] = MIN(win->mframe.g_w, vw->full.g_w);
st->Event->SendMsg[7] = MIN(win->mframe.g_h, vw->full.g_h);
}
/* Send a message to handle the window resizing. */
appl_write(st->ApId, 16, st->Event->SendMsg);
}
}
int
HandleMove(PSTATE *st)
{
WINDOW *win = WinFindH(st->Event->Message[3]);
(win->move)(st);
}
int
HandleSize(PSTATE *st)
{
WINDOW *win = WinFindH(st->Event->Message[3]);
(win->size)(st);
}
int
HandleIcon(VWRK *vw, PSTATE *st)
{
int handle = st->Event->Message[3];
WINDOW *win = WinFindH(handle);
switch (st->Event->Message[0]) {
case WM_ICONIFY: /* close the iconified window */
wind_close(handle);
win->opened = 0;
win->iconified = 1;
if (win->type == OBJ) {
OBJECT *obj = win->obj;
obj[0].ob_flags ^= HIDETREE;
}
break;
case WM_ALLICONIFY: /* close all open windows */
WinListClose(WList);
break;
}
if (!iconwin.opened) {
/* Open the icon window. */
wind_set(iconwin.handle, WF_ICONIFY,
st->Event->Message[4], st->Event->Message[5],
st->Event->Message[6], st->Event->Message[7]);
wind_get(iconwin.handle, WF_CURRXYWH,
&iconwin.frame.g_x, &iconwin.frame.g_y,
&iconwin.frame.g_w, &iconwin.frame.g_h);
wind_get(iconwin.handle, WF_WORKXYWH,
&iconwin.canvas.g_x, &iconwin.canvas.g_y,
&iconwin.canvas.g_w, &iconwin.canvas.g_h);
WinListAdd(WList, &iconwin);
ObjWinOpen(iconobj, &iconwin, vw, st);
}
}
int
HandleUnIcon(PSTATE *st)
{
/* Close the icon window. */
wind_set(iconwin.handle, WF_UNICONIFY,
iconwin.frame.g_x, iconwin.frame.g_y,
iconwin.frame.g_w, iconwin.frame.g_h);
wind_get(iconwin.handle, WF_CURRXYWH,
&iconwin.frame.g_x, &iconwin.frame.g_y,
&iconwin.frame.g_w, &iconwin.frame.g_h);
WinClose(&iconwin);
WList = WinListDelete(WList, &iconwin);
/* Open all windows in the window list. */
WinListOpen(WList);
}
private int
win_std_write_process(stream_state *sst, stream_cursor_read *pr,
stream_cursor_write *ignore_pw, bool last)
{
WINTEXT *text = conswin.obj;
char string[COLUMNS+1];
char *ptr = (char *)pr->ptr + 1;
int i, j, tempcol;
int oldcol = text->cn;
uint count = pr->limit - pr->ptr;
/* dprintf3("bptr=%x, lim=%x, skip=%x\n", pr->ptr, pr->limit, pr->_skip); */
cursor(OFF);
State.Event->Message[3] = conswin.handle;
for (i=0, tempcol=0; i<count; i++) {
switch(*ptr) {
case '\r':
case '\n':
newline:
string[tempcol] = '\0';
strcat(text->buff[text->ln], string);
next_line(oldcol);
oldcol = 0;
tempcol = 0;
ptr++;
break;
case '\t':
for(j=0; j<8; j++) {
string[tempcol++] = ' ';
text->cn++;
}
ptr++;
break;
case '\b':
--tempcol;
if (--text->cn < 0) text->cn = 0;
else --ptr;
break;
default:
string[tempcol++] = *ptr;
if (++text->cn >= text->bw) goto newline;
ptr++;
break;
}
}
if (tempcol) {
int dirtw;
string[tempcol] = '\0';
strcat(text->buff[text->ln], string);
dirtw = strlen(string) * text->wc;
State.Event->Message[4] = text->cx;
State.Event->Message[5] = text->cy;
State.Event->Message[6] = dirtw;
State.Event->Message[7] = text->hc;
HandleRedraw(DIRT_RECT, &State);
text->cx += dirtw;
}
cursor(ON);
pr->ptr = pr->limit;
/* dprintf3("eptr=%x, lim=%x, skip=%x\n", pr->ptr, pr->limit, pr->_skip); */
return 0;
}
int
HandleButton(VWRK *vw, PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
{
int i, ObjectIndex, loop_end=0;
OBJECT *Object;
/* Find where the mouse click took place. */
WINDOW *win = WinFindXY(st->Event->MouseX, st->Event->MouseY);
if (win == NULL) { /* Click was not in a window. */
return 0;
}
else if (win->type != OBJ) { /* Window contains no object. */
return 0;
}
Object = (OBJECT *)win->obj;
ObjectIndex = objc_find(Object, 0, 2,
st->Event->MouseX, st->Event->MouseY);
if (!(Object[ObjectIndex].ob_flags & SELECTABLE)) {
return 0; /* Object is not selectable */
}
if (Object[ObjectIndex].ob_state & DISABLED) {
return 0; /* Object is disabled */
}
objc_change(Object, ObjectIndex, 0,
win->canvas.g_x, win->canvas.g_y,
win->canvas.g_w, win->canvas.g_h,
(Object[ObjectIndex].ob_state ^ SELECTED), 1);
if (ObjectIndex >= 0) {
loop_end = (win->button)(Object, ObjectIndex, win, vw, st, gr, pw, dest);
}
return loop_end;
}
int
HandleRedraw(int flag, PSTATE *st)
{
WINDOW *win = WinFindH(st->Event->Message[3]);
if (win == NULL) return 0; /* window is no longer open */
wind_update(BEG_UPDATE); /* lock the screen */
(win->redraw)(flag, st);
wind_update(END_UPDATE); /* release screen */
return 0;
}
int
HandleKeybd(VWRK *vw, PSTATE *st, stream_cursor_write *pw, byte **dest)
{
char *sptr; /* generic string pointer */
uint ch;
int loop_end=0, prevline;
WINTEXT *text = conswin.obj;
byte *limit = pw->limit - 1; /* always leave room for \n */
ch = (uint)( st->Event->Key & 255 );
switch (st->Event->Key) {
case 0x1800: /* alt-o */
st->Event->KeyMenu = OPEN;
break;
case 0x2200: /* alt-g */
st->Event->KeyMenu = PAGES;
break;
case 0x1900: /* alt-p */
st->Event->KeyMenu = PRINT;
break;
case 0x2f00: /* alt-v */
st->Event->KeyMenu = (menuobj[PREV].ob_state & DISABLED) ? 0 : PREV;
break;
case 0x3100: /* alt-n */
st->Event->KeyMenu = (menuobj[NEXT].ob_state & DISABLED) ? 0 : NEXT;
break;
case 0x2600: /* alt-l */
st->Event->KeyMenu = LOAD;
break;
case 0x1f00: /* alt-s */
st->Event->KeyMenu = SAVE;
break;
case 0x1000: /* alt-q */
st->Event->KeyMenu = QUIT;
break;
case 0x2000: /* alt-d */
st->Event->KeyMenu = DEVICE;
break;
case 0x1300: /* alt-r */
st->Event->KeyMenu = RES;
break;
case 0x1e00: /* alt-a */
st->Event->KeyMenu = PAGESIZE;
break;
case 0x1700: /* alt-i */
st->Event->KeyMenu = ICON;
break;
case 0x1100: /* alt-w */
st->Event->KeyMenu = CYCLEF;
break;
case 0x3000: /* alt-b */
st->Event->KeyMenu = CYCLEB;
break;
case 0x1600: /* alt-u */
st->Event->KeyMenu = CLOSE;
break;
case 0x2e00: /* alt-c */
st->Event->KeyMenu = (menuobj[COPY].ob_state & DISABLED) ? 0 : COPY;
break;
case 0x4800: /* up arrow */
st->Event->KeyScroll = WA_UPLINE;
break;
case 0x4838: /* shift up arrow */
st->Event->KeyScroll = WA_UPPAGE;
break;
case 0x5000: /* down arrow */
st->Event->KeyScroll = WA_DNLINE;
break;
case 0x5032: /* shift down arrow */
st->Event->KeyScroll = WA_DNPAGE;
break;
case 0x4b00: /* left arrow */
st->Event->KeyScroll = WA_LFLINE;
break;
case 0x4b34: /* shift left arrow */
st->Event->KeyScroll = WA_LFPAGE;
break;
case 0x4d00: /* right arrow */
st->Event->KeyScroll = WA_RTLINE;
break;
case 0x4d36: /* shift right arrow */
st->Event->KeyScroll = WA_RTPAGE;
break;
case 0x4700: /* clr/home */
st->Event->KeyState = 1;
st->Event->KeyScroll = WA_UPLINE;
break;
case 0x4737: /* shift clr/home */
st->Event->KeyState = 1;
st->Event->KeyScroll = WA_DNLINE;
break;
case 0x6200: /* help */
HandleHelp(GENHELP, vw, st, pw, dest);
break;
case 0x1c0d: /* return */
case 0x720d: /* enter */
/*
* Exit the event loop so the interpreter can
* read the input buffer.
*
* If return is pressed after a showpage and
* the image window is open, send a message to
* redraw the image window.
*/
prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
if (imagwin.opened &&
(sptr = strstr(text->buff[prevline], ">>")) != NULL) {
st->Event->SendMsg[0] = WM_REDRAW;
st->Event->SendMsg[3] = imagwin.handle;
st->Event->SendMsg[4] = imagwin.canvas.g_x;
st->Event->SendMsg[5] = imagwin.canvas.g_y;
st->Event->SendMsg[6] = imagwin.canvas.g_w;
st->Event->SendMsg[7] = imagwin.canvas.g_h;
appl_write(st->ApId, 16, st->Event->SendMsg);
}
*++(*dest) = '\n';
gemputc(ch);
pw->ptr = *dest;
graf_mouse(BUSY_BEE, 0L);
loop_end = 1;
break;
default: /* handle the input character. */
switch (ch) {
default: /* put char in the input buffer. */
if ( *dest == limit ) {
; /* MessageBeep(-1); */
}
else {
*++(*dest) = ch;
gemputc(ch);
}
break;
case ERASELINE:
clear_line(*dest - pw->ptr + 1);
*dest = pw->ptr;
break;
case ERASECHAR1:
case ERASECHAR2:
if ( *dest > pw->ptr ) {
clear_line(1);
(*dest)--;
}
break;
}
}
return loop_end;
}
#define FILT_ERR "[1][My simplistic routine|can not extract pages|\
from the selected file.|It may not conform to|Adobe's structure rules.]\
[Continue]"
int
HandlePageFilter(VWRK *vw, PSTATE *st, stream_cursor_write *pw,
byte **dest)
{
char input[MAXLEN];
int num;
strcpy(input, st->DirSpec);
strcat(input, st->Infile);
/* Filter the input file. */
if ((num = PageFilter(input, st->Doc)) <= 1) {
if (num <= 0) {
form_alert(1, FILT_ERR);
}
/* Execute the selected file. */
sprintf(st->Command, "(%s) run\n", input);
SendCommand(st, pw, dest);
}
else {
/* Create and open the page dialog. */
pagewin.obj = (void *)CreatePageObj(st->Doc->numpages);
WinListAdd(WList, &pagewin);
ObjWinOpen((OBJECT *)pagewin.obj, &pagewin, vw, st);
/* Send a message to extract and execute a page
* after all pending events have been dispatched.
*/
st->Event->SendMsg[0] = PGSELECT;
st->Event->SendMsg[1] = 0;
appl_write(st->ApId, 16, st->Event->SendMsg);
}
}
int
HandlePageSelect(VWRK *vw, PSTATE *st, stream_cursor_write *pw,
byte **dest, int page)
{
char OutRoot[MAXLEN];
st->Doc->currentpage = page;
if (page == 0) {
strcpy(OutRoot, "gs_pro");
}
else {
if (page == 1) {
menu_ienable(menuobj, PREV, 0);
menu_ienable(menuobj, NEXT, 1);
}
else if (page == st->Doc->numpages) {
menu_ienable(menuobj, PREV, 1);
menu_ienable(menuobj, NEXT, 0);
}
else {
menu_ienable(menuobj, PREV, 1);
menu_ienable(menuobj, NEXT, 1);
}
strcpy(OutRoot, "gs_pg");
}
/* Extract the page and execute. */
PageCopy(page, OutRoot, st->Doc);
sprintf(st->Command, "(%s) run\n", OutRoot);
SendCommand(st, pw, dest);
}
int
gemputc(uint ch)
{
char c[2];
int topwin, empty;
GRECT rect;
MFDB src, dest;
WINTEXT *text = conswin.obj;
src.fd_addr = (long)NULL;
dest.fd_addr = (long)NULL;
wind_get(0, WF_TOP, &topwin, &empty, &empty, &empty);
cursor(OFF);
State.Event->Message[3] = conswin.handle;
switch (ch) {
default:
c[0] = ch;
c[1] = '\0';
strcat(text->buff[text->ln], c);
if (topwin == conswin.handle) {
if ((text->cx >= align(conswin.canvas.g_x + text->xoff)) &&
(text->cx < conswin.canvas.g_x+conswin.canvas.g_w-text->wc-1) &&
(text->cy >= conswin.canvas.g_y + text->yoff) &&
(text->cy < conswin.canvas.g_y+conswin.canvas.g_h-text->hc-1)) {
graf_mouse(M_OFF, 0L);
wind_update(BEG_UPDATE); /* lock the screen */
v_gtext(VWork.VdiHandle, text->cx, text->cy, c);
wind_update(END_UPDATE); /* unlock the screen */
graf_mouse(M_ON, 0L);
}
}
else {
State.Event->Message[4] = text->cx;
State.Event->Message[5] = text->cy;
State.Event->Message[6] = text->wc;
State.Event->Message[7] = text->hc;
HandleRedraw(DIRT_RECT, &State);
}
if (++text->cn >= text->bw) goto newline;
text->cx += text->wc;
break;
case '\r':
case '\n':
newline:
text->buff[text->ln][text->cn] = '\0';
if (++text->ln >= text->bh) {
text->ln = 0;
text->scrolled = 1;
}
*text->buff[text->ln] = '\0';
if (text->scrolled) {
if (++text->fl >= text->bh) text->fl = 0;
if (++text->fdl >= text->bh) text->fdl = 0;
if (++text->ll >= text->bh) text->ll = 0;
if (++text->ldl >= text->bh) text->ldl = 0;
if ((topwin == conswin.handle) && (text->ll == text->ldl)) {
State.pxy[0] = conswin.canvas.g_x;
State.pxy[1] = conswin.canvas.g_y + text->hc;
State.pxy[2] = conswin.canvas.g_x + conswin.canvas.g_w - 1;
State.pxy[3] = conswin.canvas.g_y + conswin.canvas.g_h - 1;
State.pxy[4] = conswin.canvas.g_x;
State.pxy[5] = conswin.canvas.g_y;
State.pxy[6] = conswin.canvas.g_x + conswin.canvas.g_w - 1;
State.pxy[7] = conswin.canvas.g_y + conswin.canvas.g_h - 1
- text->hc;
graf_mouse(M_OFF, 0L);
wind_update(BEG_UPDATE); /* lock the screen */
vro_cpyfm(VWork.VdiHandle, 3, State.pxy, &src, &dest);
rect.g_x = State.Event->Message[4] = conswin.canvas.g_x;
rect.g_y = State.Event->Message[5] = text->cy;
rect.g_w = State.Event->Message[6] = conswin.canvas.g_x
+ conswin.canvas.g_w - rect.g_x;
rect.g_h = State.Event->Message[7] = text->hc;
clear_win(&rect);
wind_update(END_UPDATE); /* unlock the screen */
graf_mouse(M_ON, 0L);
}
else {
HandleRedraw(FULL_WIN, &State);
}
}
else if (text->ln == (text->ldl + 1)) {
text->top -= text->hc;
text->fdl++;
text->ldl++;
if (topwin == conswin.handle) {
State.pxy[0] = conswin.canvas.g_x;
State.pxy[1] = conswin.canvas.g_y + text->hc;
State.pxy[2] = conswin.canvas.g_x + conswin.canvas.g_w - 1;
State.pxy[3] = conswin.canvas.g_y + conswin.canvas.g_h - 1;
State.pxy[4] = conswin.canvas.g_x;
State.pxy[5] = conswin.canvas.g_y;
State.pxy[6] = conswin.canvas.g_x + conswin.canvas.g_w - 1;
State.pxy[7] = conswin.canvas.g_y + conswin.canvas.g_h - 1
- text->hc;
graf_mouse(M_OFF, 0L);
wind_update(BEG_UPDATE); /* lock the screen */
vro_cpyfm(VWork.VdiHandle, 3, State.pxy, &src, &dest);
rect.g_x = align(conswin.canvas.g_x);
rect.g_y = text->cy;
rect.g_w = conswin.canvas.g_x
+ conswin.canvas.g_w - rect.g_x;
rect.g_h = text->hc;
clear_win(&rect);
wind_update(END_UPDATE); /* unlock the screen */
graf_mouse(M_ON, 0L);
}
else {
HandleRedraw(FULL_WIN, &State);
}
update_scroll(conswin.handle);
}
else {
text->cy += text->hc;
}
text->cx = align(text->edge + text->xoff);
text->cn = 0;
break;
case '\b':
text->buff[text->ln][--text->cn] = '\0';
text->cx -= text->wc;
break;
}
cursor(ON);
}
int clear_line(int cnt)
{
int x, w;
WINTEXT *text = conswin.obj;
cursor(OFF);
State.Event->Message[3] = conswin.handle;
if (cnt < 0) {
*text->buff[text->ln] = '\0';
x = conswin.canvas.g_x;
w = conswin.canvas.g_w;
text->cx = align(text->edge + text->xoff);
text->cn = 0;
}
else {
text->cn = MAX(text->cn - cnt, 0);
text->cx -= cnt * text->wc;
text->buff[text->ln][text->cn] = '\0';
x = MAX(text->cx, conswin.canvas.g_x);
w = MIN(cnt * text->wc, conswin.canvas.g_w);
}
State.Event->Message[4] = x;
State.Event->Message[5] = text->cy;
State.Event->Message[6] = w;
State.Event->Message[7] = text->hc;
HandleRedraw(DIRT_RECT, &State);
cursor(ON);
}
int next_line(int oldcol)
{
char outline[MAXLEN];
int topwin, empty;
GRECT rect;
MFDB src, dest;
WINTEXT *text = conswin.obj;
src.fd_addr = (long)NULL;
dest.fd_addr = (long)NULL;
wind_get(0, WF_TOP, &topwin, &empty, &empty, &empty);
if (++text->ln >= text->bh) {
text->ln = 0;
text->scrolled = 1;
}
*text->buff[text->ln] = '\0';
if (text->scrolled) {
if (++text->fl >= text->bh) text->fl = 0;
if (++text->fdl >= text->bh) text->fdl = 0;
if (++text->ll >= text->bh) text->ll = 0;
if (++text->ldl >= text->bh) text->ldl = 0;
if ((topwin == conswin.handle) && (text->ll == text->ldl)) {
int offset = MAX(oldcol, text->fdc);
int startx = MAX(text->cx, align(conswin.canvas.g_x + text->xoff));
int count = text->cols - oldcol + text->fdc;
int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
graf_mouse(M_OFF, 0L );
wind_update(BEG_UPDATE); /* lock the screen */
if ((count > 0) && (strlen(text->buff[prevline]) > offset)) {
*outline = '\0';
strncat(outline, text->buff[prevline]+offset, count);
v_gtext(VWork.VdiHandle, startx, text->cy, outline);
}
State.pxy[0] = conswin.canvas.g_x;
State.pxy[1] = conswin.canvas.g_y + text->hc;
State.pxy[2] = conswin.canvas.g_x + conswin.canvas.g_w - 1;
State.pxy[3] = conswin.canvas.g_y + conswin.canvas.g_h - 1;
State.pxy[4] = conswin.canvas.g_x;
State.pxy[5] = conswin.canvas.g_y;
State.pxy[6] = conswin.canvas.g_x + conswin.canvas.g_w - 1;
State.pxy[7] = conswin.canvas.g_y + conswin.canvas.g_h - 1
- text->hc;
vro_cpyfm(VWork.VdiHandle, 3, State.pxy, &src, &dest);
rect.g_x = conswin.canvas.g_x;
rect.g_y = text->cy;
rect.g_w = conswin.canvas.g_x
+ conswin.canvas.g_w - rect.g_x;
rect.g_h = text->hc;
clear_win(&rect);
wind_update(END_UPDATE); /* unlock the screen */
graf_mouse(M_ON, 0L );
}
else {
HandleRedraw(FULL_WIN, &State);
}
}
else if (text->ln == (text->ldl + 1)) {
text->top -= text->hc;
text->fdl++;
text->ldl++;
if (topwin == conswin.handle) {
int offset = MAX(oldcol, text->fdc);
int startx = MAX(text->cx, align(conswin.canvas.g_x + text->xoff));
int count = text->cols - oldcol + text->fdc;
int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
graf_mouse(M_OFF, 0L );
wind_update(BEG_UPDATE); /* lock the screen */
if ((count > 0) && (strlen(text->buff[prevline]) > offset)) {
*outline = '\0';
strncat(outline, text->buff[prevline]+offset, count);
v_gtext(VWork.VdiHandle, startx, text->cy, outline);
}
State.pxy[0] = conswin.canvas.g_x;
State.pxy[1] = conswin.canvas.g_y + text->hc;
State.pxy[2] = conswin.canvas.g_x + conswin.canvas.g_w - 1;
State.pxy[3] = conswin.canvas.g_y + conswin.canvas.g_h - 1;
State.pxy[4] = conswin.canvas.g_x;
State.pxy[5] = conswin.canvas.g_y;
State.pxy[6] = conswin.canvas.g_x + conswin.canvas.g_w - 1;
State.pxy[7] = conswin.canvas.g_y + conswin.canvas.g_h - 1
- text->hc;
vro_cpyfm(VWork.VdiHandle, 3, State.pxy, &src, &dest);
rect.g_x = conswin.canvas.g_x;
rect.g_y = text->cy;
rect.g_w = conswin.canvas.g_x
+ conswin.canvas.g_w - rect.g_x;
rect.g_h = text->hc;
clear_win(&rect);
wind_update(END_UPDATE); /* unlock the screen */
graf_mouse(M_ON, 0L );
}
else {
HandleRedraw(FULL_WIN, &State);
}
update_scroll(conswin.handle);
}
else {
State.Event->Message[4] = text->cx;
State.Event->Message[5] = text->cy;
State.Event->Message[6] = conswin.canvas.g_x + conswin.canvas.g_w
- text->cx;
State.Event->Message[7] = text->hc;
HandleRedraw(DIRT_RECT, &State);
text->cy += text->hc;
}
text->cx = align(text->edge + text->xoff);
text->cn = 0;
}
int visible_lines(WINDOW *twin)
{
WINTEXT *text = twin->obj;
return ((twin->canvas.g_h - text->yoff) / text->hc);
}
int visible_cols(WINDOW *twin)
{
WINTEXT *text = twin->obj;
return ((twin->canvas.g_w - align(text->xoff)) / text->wc);
}
int cursor(int state)
{
int xy[4], txy[4];
GRECT rect;
WINTEXT *text = conswin.obj;
if ((state == OFF && text->cstate == ON) ||
(state == ON && text->cstate == OFF)) {
vsf_interior(VWork.VdiHandle, 1); /* set fill mode to solid */
vswr_mode(VWork.VdiHandle, 3); /* set write mode to XOR */
xy[0] = text->cx;
xy[1] = text->cy;
xy[2] = xy[0] + text->wc - 1;
xy[3] = xy[1] + text->hc - 1;
wind_get(conswin.handle, WF_FIRSTXYWH,
&rect.g_x, &rect.g_y,
&rect.g_w, &rect.g_h);
while (rect.g_w && rect.g_h) {
if (rc_intersect(&conswin.canvas, &rect)) {
grect_to_array(&rect, txy);
vs_clip(VWork.VdiHandle, 1, txy);
vr_recfl(VWork.VdiHandle, xy); /* draw the cursor */
vs_clip(VWork.VdiHandle, 0, txy);
}
wind_get(conswin.handle, WF_NEXTXYWH,
&rect.g_x, &rect.g_y,
&rect.g_w, &rect.g_h);
}
vs_clip(VWork.VdiHandle, 0, xy);
vswr_mode(VWork.VdiHandle, 1); /* restore replace mode */
text->cstate = !text->cstate; /* toggle cursor state */
}
}
int clear_win(GRECT *area)
{
int xy[4];
xy[0] = MAX(area->g_x, VWork.full.g_x);
xy[1] = MAX(area->g_y, VWork.full.g_y);
xy[2] = MIN(xy[0] + area->g_w - 1, VWork.full.g_x + VWork.full.g_w - 1);
xy[3] = MIN(xy[1] + area->g_h - 1, VWork.full.g_y + VWork.full.g_h - 1);
vsf_interior(VWork.VdiHandle, 0); /* set fill mode to hollow */
vr_recfl(VWork.VdiHandle, xy); /* clear the window */
}
WINDOW *
WinFindXY(int MouseX, int MouseY)
{
int handle = wind_find(MouseX, MouseY);
WINLIST *wl = WList;
do {
if (handle == wl->Win->handle) {
return wl->Win;
}
wl = wl->Next;
}
while (wl != WList);
return NULL;
}
WINDOW *
WinFindH(int handle)
{
WINLIST *wl = WList;
do {
if (handle == wl->Win->handle) {
return wl->Win;
}
wl = wl->Next;
}
while (wl != WList);
return NULL;
}
void *
ObjFindH(int handle)
{
WINLIST *wl = WList;
do {
if (handle == wl->Win->handle) {
if (wl->Win->type == TEXT) {
return (WINTEXT *)wl->Win->obj;
}
else if (wl->Win->type == OBJ) {
return (OBJECT *)wl->Win->obj;
}
else if (wl->Win->type == BIT) {
return (GRAPHIC *)wl->Win->obj;
}
}
wl = wl->Next;
}
while (wl != WList);
return NULL;
}
int
SendCommand(PSTATE *st, stream_cursor_write *pw, byte **dest)
{
char *sptr;
/* Change back slashes to forward. */
while ((sptr = strchr(st->Command,'\\')) != NULL) {
*sptr = '/';
}
/* Copy the command into Ghostscript's input buffer. */
for (sptr = st->Command; *sptr; sptr++) {
*++(*dest) = *sptr;
}
pw->ptr = *dest;
/* Send a message to output the command after
* all pending events have been dispatched.
*/
st->Event->SendMsg[0] = COMMAND;
appl_write(st->ApId, 16, st->Event->SendMsg);
return 0;
}
int
gemprintf(FILE *stream, const char *format, ...)
{
va_list args;
char c, *lptr, *bptr;
char buffer[1024], line[COLUMNS+1];
WINTEXT *text = conswin.obj;
int i, count;
int oldcol = text->cn;
va_start(args, format);
lptr = line;
bptr = buffer;
if (gp_file_is_console(stream) && State.Windows) {
/* Send console I/O to a window */
State.Event->Message[3] = conswin.handle;
cursor(OFF);
count = vsprintf(buffer, format, args);
for (; (c = *bptr) != '\0'; bptr++) {
switch (c) {
case '\r':
case '\n':
newline:
*lptr = '\0';
strcat(text->buff[text->ln], line);
next_line(oldcol);
oldcol = 0;
lptr = line;
break;
default:
*lptr++ = c;
if (++text->cn >= text->bw) goto newline;
}
}
if (lptr != line) {
int dirtw;
*lptr = '\0';
strcat(text->buff[text->ln], line);
dirtw = strlen(line) * text->wc;
State.Event->Message[4] = text->cx;
State.Event->Message[5] = text->cy;
State.Event->Message[6] = dirtw;
State.Event->Message[7] = text->hc;
HandleRedraw(DIRT_RECT, &State);
text->cx += dirtw;
}
cursor(ON);
}
else if (stream == NULL) { /* output for the centronics port */
OutFile = stream;
count = vsprintf(buffer, format, args);
l_start();
lputs(buffer);
l_stop();
}
else { /* print to other streams normally */
count = vfprintf(stream, format, args);
con_flush();
}
va_end(args);
return count;
}
int
csputc(int c, FILE *stream)
{
if (gp_file_is_console(stream) && State.Windows) {
gemputc(c);
}
else {
OutFile = stream;
l_start();
lputc(c);
l_stop();
}
return c;
}
int
csputs(const char *s, FILE *stream)
{
if (gp_file_is_console(stream) && State.Windows) {
gemprintf(stream, s);
}
else {
OutFile = stream;
l_start();
lputs(s);
l_stop();
}
return 1;
}
size_t
cswrite(const void *ptr, size_t size, size_t nobj, FILE *stream)
{
int count;
if (stream == NULL) {
OutFile = stream;
l_start();
for (count=0; count < size*nobj; count++) {
lputc(*(char *)(ptr++)); /* send the data */
}
l_stop();
return count;
}
else {
int ret;
ret = fwrite(ptr, size, nobj, stream);
con_flush();
return ret;
}
}
#if 0
int
csprintf(FILE *stream, char *format, ...)
{
va_list args;
char line[MAXLEN];
va_start(args, format);
if (stream == NULL) {
OutFile = stream;
vsprintf(line, format, args);
l_start();
lputs(line);
l_stop();
va_end(args);
return 0;
}
else {
vfprintf(stream, format, args);
va_end(args);
con_flush();
return 0;
}
}
#endif