STDWIN 0.9.5, Part 13/19
Guido van Rossum
guido at cwi.nl
Mon Mar 4 21:58:15 AEST 1991
Archive-name: stdwin/part13
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 13 (of 19)."
# Contents: Appls/bed/bed.c Appls/dpv/dpvcontrol.c
# Conf/proto.os.amoeba Ports/alfa/event.c Ports/alfa/syswin.c
# Ports/mac/macwin.h Ports/mac/stdwin.c Ports/x11/cursor.c
# Ports/x11/event.c
# Wrapped by guido at voorn.cwi.nl on Mon Mar 4 12:37:30 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Appls/bed/bed.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Appls/bed/bed.c'\"
else
echo shar: Extracting \"'Appls/bed/bed.c'\" \(5379 characters\)
sed "s/^X//" >'Appls/bed/bed.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include <ctype.h>
X#include "bed.h"
X#include "menu.h"
X
X#define MINSQRSIZE 5
X#define MAXSQRSIZE 15
X
XMENU *pfmenu ;
XMENU *pmmenu ;
XMENU *popmenu ;
X
Xint sqrsize ;
X
Xint map_width = DEF_COLS ;
Xint map_height = DEF_ROWS ;
X
Xchar *raster = NULL ;
Xint raster_lenght ;
Xint stride ;
X
Xint lastbyte ;
Xchar bits[] = { 0xFF, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F } ;
X
Xchar *title = NULL ;
Xchar *fname = NULL ;
X
XWINDOW *win ;
X
Xbool changed = FALSE ;
X
Xbool text_only = FALSE ;
X
Xextern bool drawline ;
X
Xextern bool drawcircle ;
X
Xextern bool selrect ;
Xextern int sr_left ;
Xextern int sr_top ;
Xextern int sr_right ;
Xextern int sr_bottom ;
X
Xextern void invertbit () ;
X
Xvoid
Xdrawproc (win, left, top, right, bottom)
X WINDOW *win ;
X int left ;
X int top ;
X int right ;
X int bottom ;
X{
X int row ;
X register int col ;
X register int l ;
X register int r ;
X int t ;
X int b ;
X int rend ;
X int fcol, fbyte, fbit, flr ;
X
X if (left < 0) left = 0 ;
X if (right > map_width * sqrsize) right = map_width * sqrsize ;
X if (top < 0) top = 0 ;
X if (bottom > map_height * sqrsize ) bottom = map_height * sqrsize ;
X
X rend = (right+sqrsize-1) / sqrsize ;
X
X fcol = left / sqrsize ;
X flr = fcol * sqrsize ;
X fbyte = fcol / 8 ;
X fbit = fcol % 8 ;
X
X for (row = top / sqrsize, t = row * sqrsize, b = t + sqrsize ;
X t < bottom ;
X ++row, t += sqrsize, b = t + sqrsize) {
X
X register char *byte ;
X register int pbit ;
X
X col = fcol ;
X l = r = flr ;
X byte = raster + (row * stride) + fbyte ;
X pbit = fbit ;
X
X while (col++ < rend) {
X if (*byte & (1 << pbit)) {
X r += sqrsize ;
X }
X else {
X if (l < r) {
X wpaint(l, t, r, b);
X l = r ;
X }
X l += sqrsize ;
X r = l ;
X }
X
X if (++pbit >= 8) {
X pbit = 0 ;
X ++byte ;
X }
X }
X
X if (l < r) wpaint (l, t, r, b) ;
X }
X
X if (drawline) plotline (invertbit, TRUE) ;
X else if (drawcircle) plotline (invertbit, TRUE) ;
X else if (selrect)
X wxorrect (sr_left * sqrsize, sr_top * sqrsize,
X sr_right * sqrsize, sr_bottom * sqrsize) ;
X}
X
Xvoid
Xnewraster ()
X{
X int i ;
X
X if (raster != NULL) {
X free (raster) ;
X raster = NULL ;
X }
X
X lastbyte = map_width % 8 ;
X stride = (map_width + 7) / 8 ;
X raster_lenght = stride * map_height ;
X
X raster = (char *) malloc (raster_lenght) ;
X if (raster == NULL) {
X wdone () ;
X fprintf (stderr, "cannot get enough memory\n") ;
X exit (1) ;
X }
X
X for (i = 0 ; i < raster_lenght ; ++i)
X raster[i] = 0 ;
X}
X
Xvoid
Xsetsqrsize ()
X{
X if (wlineheight () == 1)
X text_only = sqrsize = 1 ;
X else {
X sqrsize = 1 ;
X /* int width ;
X int height ;
X int swidth ;
X int sheight ;
X
X wgetscrsize (&width, &height) ;
X
X swidth = (2 * width) / (3 * map_width) ;
X sheight = (2 * height) / (3 * map_height) ;
X sqrsize = swidth < sheight ? swidth : sheight ;
X if (sqrsize < MINSQRSIZE)
X sqrsize = MINSQRSIZE ;
X else if (sqrsize > MAXSQRSIZE)
X sqrsize = MAXSQRSIZE ;
X */
X }
X}
X
Xvoid
Xsetup()
X{
X int i ;
X
X setsqrsize () ;
X
X wsetdefwinsize (map_width * sqrsize, map_height * sqrsize) ;
X
X win = wopen (title == NULL ? "Untitled" : title, drawproc) ;
X if (win == NULL) {
X wmessage ("Can't open window") ;
X return ;
X }
X
X wsetdocsize (win, map_width * sqrsize, map_height * sqrsize) ;
X
X pfmenu = wmenucreate(FILE_MENU, "File");
X wmenuadditem (pfmenu, "Open", 'O') ;
X wmenuadditem (pfmenu, "New", 'N') ;
X wmenuadditem (pfmenu, "", -1) ;
X wmenuadditem (pfmenu, "Save", 'S') ;
X wmenuadditem (pfmenu, "Save As ...", -1) ;
X wmenuadditem (pfmenu, "", -1) ;
X wmenuadditem (pfmenu, "Quit", 'Q') ;
X
X pmmenu = wmenucreate (MODE_MENU, "Mode") ;
X wmenuadditem (pmmenu, "Pencil", -1) ;
X wmenuadditem (pmmenu, "Line", -1) ;
X wmenuadditem (pmmenu, "Circle", -1) ;
X wmenuadditem (pmmenu, "Select", -1) ;
X
X popmenu = wmenucreate(OP_MENU, "Operations") ;
X wmenuadditem (popmenu, "Clear bits", -1) ;
X wmenuadditem (popmenu, "Set bits", -1) ;
X wmenuadditem (popmenu, "Invert bits", -1) ;
X wmenuadditem (popmenu, "", -1) ;
X wmenuadditem (popmenu, "Transpose major", -1) ;
X wmenuadditem (popmenu, "Transpose minor", -1) ;
X wmenuadditem (popmenu, "Rotate left", -1) ;
X wmenuadditem (popmenu, "Rotate right", -1) ;
X wmenuadditem (popmenu, "Flip horizontal", -1) ;
X wmenuadditem (popmenu, "Flip vertical", -1) ;
X wmenuadditem (popmenu, "Zoom in", '+') ;
X wmenuadditem (popmenu, "Zoom out", '-') ;
X
X wmenucheck (pmmenu, PENCIL_ITEM, TRUE) ;
X
X for (i = TRANS_MAJ_ITEM ; i <= FLIP_VERT_ITEM ; i++)
X wmenuenable (popmenu, i, FALSE) ;
X}
X
Xvoid
Xmainloop ()
X{
X for (;;) {
X EVENT e ;
X
X wgetevent (&e) ;
X switch (e.type) {
X case WE_MOUSE_DOWN :
X case WE_MOUSE_MOVE :
X case WE_MOUSE_UP :
X do_mouse (&e) ;
X break;
X case WE_COMMAND :
X switch (e.u.command) {
X case WC_CLOSE :
X if (do_quit ())
X return ;
X break ;
X case WC_CANCEL :
X return ;
X }
X break ;
X case WE_CLOSE :
X if (do_quit ())
X return ;
X break ;
X case WE_MENU :
X switch (e.u.m.id) {
X case FILE_MENU :
X if (do_file_menu (&e))
X return ;
X break ;
X case MODE_MENU :
X do_mode_menu (&e) ;
X break ;
X case OP_MENU :
X do_op_menu (&e) ;
X break ;
X }
X break ;
X }
X }
X}
X
Xmain (argc, argv)
X int argc ;
X char *argv[] ;
X{
X extern char *strip () ;
X
X winitargs (&argc, &argv) ;
X
X if (argc > 1) {
X fname = strdup (argv[1]) ;
X title = strip (fname) ;
X if (!readbitmap ()) {
X free (fname) ;
X fname = title = NULL ;
X newraster () ;
X }
X }
X else
X newraster () ;
X
X setup () ;
X
X mainloop () ;
X
X wdone () ;
X
X exit (0) ;
X}
END_OF_FILE
if test 5379 -ne `wc -c <'Appls/bed/bed.c'`; then
echo shar: \"'Appls/bed/bed.c'\" unpacked with wrong size!
fi
# end of 'Appls/bed/bed.c'
fi
if test -f 'Appls/dpv/dpvcontrol.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Appls/dpv/dpvcontrol.c'\"
else
echo shar: Extracting \"'Appls/dpv/dpvcontrol.c'\" \(5402 characters\)
sed "s/^X//" >'Appls/dpv/dpvcontrol.c' <<'END_OF_FILE'
X/* dpv -- ditroff previewer. User interface, controlling the rest. */
X
X#include "dpv.h"
X#include "dpvmachine.h"
X#include "dpvoutput.h"
X
X#ifdef unix
X#define DO_PRINTMENU
X#endif
X
Xchar *devname;
X
Xpreview(file, firstpage)
X char *file;
X int firstpage;
X{
X initialize(file, firstpage);
X addmenus();
X eventloop(file);
X cleanup();
X wdone();
X}
X
XMENU *mainmmenu;
X
X/* Menu IDs */
X#define MAINMENU 1
X#define PRINTMENU 2
X
X/* Control menu items */
X#define FIRSTPAGE 0
X#define PREVPAGE 1
X#define NEXTPAGE 2
X#define LASTPAGE 3
X/* --- */
X#define GOTOPAGE 5
X/* --- */
X#define QUIT 7
X
X#ifdef DO_PRINTMENU
X
XMENU *printmenu;
X
X#define MAXNPRINT 50 /* Max # items in print menu */
X
Xstruct _printitem {
X char *text; /* Menu item text */
X char *device; /* Required device, or NULL if N/A */
X char *command; /* Shell command to execute */
X} printitems[MAXNPRINT]= {
X /* XXX This is extremely site-dependent */
X {"Typeset on Harris", "har", "lpr -Phar -n %s"},
X {"Harris emulation on Agfa", "har", "toagfa %s"},
X {"Print on ${PRINTER-psc}", "psc", "lpr -P${PRINTER-psc} -n %s"},
X {"Print on Oce", "psc", "lpr -Poce -n %s"},
X {"Print on PostScript", "psc", "lpr -Ppsc -n %s"},
X {"Print on Agfa", "psc", "lpr -Pagfa -n %s"},
X};
X
Xint nprint;
X
Xint
Xcountprintmenu()
X{
X while (nprint < MAXNPRINT && printitems[nprint].text != NULL)
X nprint++;
X}
X
Xint
Xaddprinter(name)
X char *name;
X{
X char buf[100];
X countprintmenu();
X if (nprint >= MAXNPRINT) {
X error(WARNING, "too many printer definitions, rest igonred");
X return;
X }
X sprintf(buf, "Print on %s", name);
X printitems[nprint].text = strdup(buf);
X printitems[nprint].device = NULL; /* Unspecified */
X sprintf(buf, "lpr -P%s -n %%s", name);
X printitems[nprint].command = strdup(buf);
X nprint++;
X}
X
X#endif
X
Xaddmenus()
X{
X MENU *mp;
X int i;
X
X mainmmenu= mp= wmenucreate(MAINMENU, "Command");
X
X wmenuadditem(mp, "First page", 'F');
X wmenuadditem(mp, "Previous page", 'P');
X wmenuadditem(mp, "Next page", 'N');
X wmenuadditem(mp, "Last page", 'L');
X wmenuadditem(mp, "", -1);
X wmenuadditem(mp, "Go to page...", 'G');
X wmenuadditem(mp, "", -1);
X wmenuadditem(mp, "Quit", 'Q');
X
X#ifdef DO_PRINTMENU
X countprintmenu();
X printmenu= mp= wmenucreate(PRINTMENU, "Print");
X for (i= 0; i < nprint; ++i) {
X wmenuadditem(mp, printitems[i].text, -1);
X if (!canprint(i))
X wmenuenable(mp, i, FALSE);
X }
X#endif
X}
X
Xeventloop(filename)
X char *filename;
X{
X int num= -1;
X for (;;) {
X EVENT e;
X int lastnum= num;
X wgetevent(&e);
X num= -1;
X switch(e.type) {
X
X case WE_MENU:
X switch (e.u.m.id) {
X case MAINMENU:
X if (e.u.m.item == QUIT)
X return;
X do_mainmenu(e.u.m.item);
X break;
X case PRINTMENU:
X do_printmenu(filename, e.u.m.item);
X break;
X }
X break;
X
X case WE_CHAR:
X /* The mnemonics used here may remind you of
X the main menu's shortcuts, the 'vi' editor,
X the 'more' pages, or the 'rn' news reader... */
X switch (e.u.character) {
X case 'q':
X case 'Q':
X return;
X case ' ':
X case '+':
X case 'n':
X case 'N':
X forwpage(lastnum);
X break;
X case '-':
X if (lastnum > 0)
X backpage(lastnum);
X else
X gotopage(prevpage);
X break;
X case 'b':
X case 'B':
X case 'p':
X case 'P':
X backpage(lastnum);
X break;
X case '^':
X case 'f':
X case 'F':
X gotopage(1);
X break;
X case '$':
X gotopage(32000);
X break;
X case 'g':
X case 'G':
X case 'l':
X case 'L':
X if (lastnum > 0)
X gotopage(lastnum);
X else
X gotopage(32000);
X break;
X case '.':
X if (lastnum > 0)
X gotopage(lastnum);
X else
X changeall(); /* Force a redraw */
X break;
X default:
X if (isdigit(e.u.character)) {
X num= e.u.character - '0';
X if (lastnum > 0)
X num += 10*lastnum;
X }
X else {
X wfleep();
X lastnum= 0;
X }
X }
X break;
X
X case WE_CLOSE:
X return;
X
X case WE_COMMAND:
X switch (e.u.command) {
X case WC_RETURN:
X if (lastnum > 0)
X gotopage(lastnum);
X else
X forwpage(1);
X break;
X case WC_DOWN:
X forwpage(lastnum);
X break;
X case WC_UP:
X case WC_BACKSPACE:
X backpage(lastnum);
X break;
X case WC_CLOSE:
X /*
X case WC_CANCEL:
X */
X return;
X default:
X wfleep();
X }
X break;
X
X }
X }
X}
X
Xdo_mainmenu(item)
X int item;
X{
X switch (item) {
X case FIRSTPAGE:
X gotopage(1);
X break;
X case PREVPAGE:
X backpage(1);
X break;
X case NEXTPAGE:
X forwpage(1);
X break;
X case LASTPAGE:
X gotopage(32000);
X break;
X case GOTOPAGE:
X {
X static char buf[10];
X int num;
X char extra;
X if (!waskstr("Go to page:", buf, sizeof buf)
X || buf[0] == '\0')
X return;
X if (sscanf(buf, " %d %c", &num, &extra) != 1 ||
X num <= 0) {
X wmessage("Invalid page number");
X return;
X }
X gotopage(num);
X }
X break;
X }
X}
X
Xdo_printmenu(filename, item)
X char *filename;
X int item;
X{
X#ifdef DO_PRINTMENU
X char buf[256];
X int sts;
X
X if (item < 0 || item >= nprint)
X return;
X
X if (!canprint(item)) {
X sprintf(buf, "Can't convert %s output to %s",
X devname == NULL ? "unspecified" : devname,
X printitems[item].device);
X wmessage(buf);
X return;
X }
X
X sprintf(buf, printitems[item].command, filename);
X sts= system(buf);
X if (sts != 0) {
X sprintf(buf, "Print command failed, exit status 0x%x", sts);
X wmessage(buf);
X }
X#endif
X}
X
X#ifdef DO_PRINTMENU
Xstatic bool
Xcanprint(item)
X int item;
X{
X return printitems[item].device == NULL ||
X devname != NULL &&
X strcmp(printitems[item].device, devname) == 0;
X}
X#endif
END_OF_FILE
if test 5402 -ne `wc -c <'Appls/dpv/dpvcontrol.c'`; then
echo shar: \"'Appls/dpv/dpvcontrol.c'\" unpacked with wrong size!
fi
# end of 'Appls/dpv/dpvcontrol.c'
fi
if test -f 'Conf/proto.os.amoeba' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Conf/proto.os.amoeba'\"
else
echo shar: Extracting \"'Conf/proto.os.amoeba'\" \(1230 characters\)
sed "s/^X//" >'Conf/proto.os.amoeba' <<'END_OF_FILE'
X
X#
X# Definitions for operating system Amoeba
X#
X
X# Define the name of this O.S. here.
X#
XOS= amoeba
X
X# Choose ONE of the following definitions of RANLIB.
X# BSD-based systems will need ranlib to be called after a library is
X# changed.
X# SYSV-based systems don't have ranlib; the value 'true' makes Make happy.
X#
XRANLIB= ranlib # for BSD
X#RANLIB= true # for SYSV
X
X# Define the name of the script used to update the dependencies in
X# the Makefile.
X# Choices are:
X# slowmkdep -- always works (as far as I know)
X# fastmkdep -- uses cc -M, which isn't always available
X# makedepend -- Todd Brunhoff's superfast tool (comes with X11)
X# (This needs -Dunix because of configure.h)
X# You may also place this definition in the proto.arch.* file if no
X# method works for every architecture supported by this OS.
X#
X#MKDEP= $(CONF)/slowmkdep
X#MKDEP= $(CONF)/fastmkdep
X#MKDEP= makedepend -Dunix
X
X# Define the system libraries to link with programs that use termcap and X11
X# (In some cases these are architecture-dependent)
X#
X#LIBTERMCAP= -ltermcap
X#LIBX11= -lX11
X
X# Other OS-specific choices (-I flags, -D flags, compiler options)
X#
XOSINCLS= -I/usr/amoeba/src/h -I/usr/amoeba/src/h/posix
XOSDEFS= -DAMOEBA -DSYSV
XOSOPTS=
END_OF_FILE
if test 1230 -ne `wc -c <'Conf/proto.os.amoeba'`; then
echo shar: \"'Conf/proto.os.amoeba'\" unpacked with wrong size!
fi
# end of 'Conf/proto.os.amoeba'
fi
if test -f 'Ports/alfa/event.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Ports/alfa/event.c'\"
else
echo shar: Extracting \"'Ports/alfa/event.c'\" \(6191 characters\)
sed "s/^X//" >'Ports/alfa/event.c' <<'END_OF_FILE'
X/* STDWIN -- EVENTS. */
X
X#include "alfa.h"
X
X/* There are three levels of event processing.
X The lowest ('raw') level only inputs single characters.
X The middle ('sys') level translates sequences of keys to menu shortcuts
X and 'commands'.
X The highest ('appl') level executes certain commands and can call the
X interactive menu selection code. It also sets the window parameter.
X For each level there are variants to wait or poll.
X Additional routines to get from one level to another:
X wmapchar: inspect key map and possibly convert char event
X wsyscommand: execute/transform system menu
X
X/* Raw event -- read one character. If blocking is FALSE,
X don't read if trmavail() returns -1, meaning it can't tell whether
X there is input or not. In that case only synchronous input works. */
X
X
Xstatic bool
Xwrawevent(ep, blocking)
X EVENT *ep;
X bool blocking;
X{
X if (!blocking && trmavail() <= 0)
X return FALSE;
X ep->u.character= trminput();
X if (ep->u.character < 0) {
X ep->type= WE_NULL;
X return FALSE;
X }
X else {
X ep->type= WE_CHAR;
X return TRUE;
X }
X}
X
Xstatic void wmapchar(); /* Forward */
X
X/* System event -- read a character and translate using the key map. */
X
Xbool
Xwsysevent(ep, blocking)
X EVENT *ep;
X bool blocking;
X{
X struct keymap mapentry;
X
X if (!wrawevent(ep, blocking))
X return FALSE;
X /* Using a temporary to avoid a tahoe C compiler bug */
X mapentry= _wprimap[ep->u.character & 0xff];
X wmapchar(ep, mapentry);
X return ep->type != WE_NULL;
X}
X
X/* Key map translation from raw event.
X This may read more characters if the start of a multi-key sequence is
X found. */
X
Xstatic void
Xwmapchar(ep, mapentry)
X EVENT *ep;
X struct keymap mapentry;
X{
X switch (mapentry.type) {
X
X case SHORTCUT:
X ep->type= WE_MENU;
X ep->u.m.id= mapentry.id;
X ep->u.m.item= mapentry.item;
X break;
X
X case SECONDARY:
X if (wrawevent(ep, TRUE)) {
X struct keymap *map;
X struct keymap *altmap= NULL;
X for (map= _wsecmap[mapentry.id];
X map->type != SENTINEL;
X ++map) {
X if (map->key == ep->u.character) {
X wmapchar(ep, *map);
X return;
X }
X else if (islower(ep->u.character) &&
X map->key == toupper(ep->u.character))
X altmap= map;
X }
X if (altmap != NULL) {
X wmapchar(ep, *altmap);
X return;
X }
X }
X trmbell();
X ep->type= WE_NULL;
X break;
X
X }
X}
X
Xvoid
Xwgoto(ep, type)
X EVENT *ep;
X int type;
X{
X int h, v;
X
X trmsense(&v, &h);
X if (v >= 0) {
X WINDOW *win;
X for (win= &winlist[1]; win < &winlist[MAXWINDOWS]; ++win) {
X if (win->open && v >= win->top && v < win->bottom) {
X if (win == front) {
X ep->type= type;
X ep->u.where.h= h;
X ep->u.where.v= v + win->offset;
X ep->u.where.clicks= 1;
X ep->u.where.button= 1;
X ep->u.where.mask=
X (type == WE_MOUSE_UP ? 0 : 1);
X return;
X }
X wsetactive(win);
X break;
X }
X }
X }
X ep->type= WE_NULL;
X}
X
Xvoid
Xwmouseup(ep)
X EVENT *ep;
X{
X int h, v;
X
X trmsense(&v, &h);
X if (v < 0)
X ep->type= WE_NULL;
X else {
X ep->type= WE_MOUSE_UP;
X ep->u.where.h= h;
X ep->u.where.v= v + front->offset;
X ep->u.where.clicks= 1;
X ep->u.where.button= 1;
X ep->u.where.mask= 0;
X }
X}
X
Xstatic void wdoupdates(); /* Forward */
X
X/* Application event. */
X
Xstatic EVENT ebuf;
X
Xvoid
Xwungetevent(ep)
X EVENT *ep;
X{
X ebuf= *ep;
X}
X
Xbool
Xwpollevent(ep)
X EVENT *ep;
X{
X return wevent(ep, FALSE);
X}
X
Xvoid
Xwgetevent(ep)
X EVENT *ep;
X{
X (void) wevent(ep, TRUE);
X}
X
Xstatic bool
Xwevent(ep, blocking)
X EVENT *ep;
X bool blocking;
X{
X static int lasttype= WE_NULL;
X
X if (ebuf.type != WE_NULL) {
X *ep= ebuf;
X ebuf.type= WE_NULL;
X return TRUE;
X }
X
X ep->type= WE_NULL;
X ep->window= NULL;
X if (lasttype == WE_MOUSE_DOWN)
X wmouseup(ep);
X while (ep->type == WE_NULL) {
X if (front != wasfront) {
X if (wasfront != NULL) {
X ep->type= WE_DEACTIVATE;
X ep->window= wasfront;
X wasfront= NULL;
X }
X else {
X menubarchanged();
X ep->type= WE_ACTIVATE;
X wasfront= front;
X }
X }
X else {
X if (trmavail() <= 0)
X wdoupdates(ep);
X if (ep->type == WE_NULL) {
X /* Remove this call if no select() exists */
X if (_w_checktimer(ep, blocking))
X break;
X if (!wsysevent(ep, blocking)) {
X ep->type= WE_NULL;
X break;
X }
X if (ep->type == WE_MENU && ep->u.m.id == 0)
X wsyscommand(ep);
X }
X }
X }
X if (ep->window == NULL && front != syswin)
X ep->window= front;
X lasttype= ep->type;
X return ep->type != WE_NULL;
X}
X
Xvoid
Xwsyscommand(ep)
X EVENT *ep;
X{
X ep->type= WE_NULL;
X
X switch (ep->u.m.item) {
X
X default:
X if (ep->u.m.item <= LAST_CMD) {
X ep->type= WE_COMMAND;
X ep->u.command= ep->u.m.item - FIRST_CMD;
X }
X break;
X
X case NEXT_WIN:
X _wselnext();
X break;
X
X case PREV_WIN:
X _wselprev();
X break;
X
X case SUSPEND_PROC:
X _wsuspend();
X break;
X
X case REDRAW_SCREEN:
X _wredraw();
X break;
X
X case MOUSE_DOWN:
X case MOUSE_UP:
X wgoto(ep, ep->u.m.item - MOUSE_DOWN + WE_MOUSE_DOWN);
X break;
X
X case LITERAL_NEXT:
X _wlitnext(ep);
X break;
X
X case MENU_CALL:
X menuselect(ep);
X break;
X
X }
X}
X
X/* Flush output and place cursor. */
X
Xvoid
Xwflush()
X{
X int y= front->curv - front->offset;
X int x= front->curh;
X
X if (front->curv < 0 || y < front->top || y >= front->bottom) {
X y= front->top;
X if (y > 0)
X --y;
X x= 0;
X }
X else if (x < 0)
X x= 0;
X else if (x >= columns)
X x= columns-1;
X trmsync(y, x);
X}
X
X/* Process pending window updates.
X If a window has no draw procedure, a WE_DRAW event is generated instead. */
X
Xstatic void
Xwdoupdates(ep)
X EVENT *ep;
X{
X WINDOW *win;
X int left, top, right, bottom;
X
X for (win= winlist; win < &winlist[MAXWINDOWS]; ++win) {
X if (win->open) {
X if (win->top > 0 && !uptodate[win->top - 1])
X wdrawtitle(win);
X if (wgetchange(win, &left, &top, &right, &bottom)) {
X if (win->drawproc == NULL) {
X ep->type= WE_DRAW;
X ep->window= win;
X ep->u.area.left= left;
X ep->u.area.top= top;
X ep->u.area.right= right;
X ep->u.area.bottom= bottom;
X return;
X }
X else {
X wbegindrawing(win);
X (*win->drawproc)(win,
X left, top, right, bottom);
X wenddrawing(win);
X }
X }
X if(win->resized) {
X win->resized = FALSE;
X ep->type = WE_SIZE;
X ep->window = win;
X return;
X }
X }
X }
X wflush();
X}
X
Xvoid
X_wlitnext(ep)
X EVENT *ep;
X{
X (void) wrawevent(ep, TRUE);
X}
END_OF_FILE
if test 6191 -ne `wc -c <'Ports/alfa/event.c'`; then
echo shar: \"'Ports/alfa/event.c'\" unpacked with wrong size!
fi
# end of 'Ports/alfa/event.c'
fi
if test -f 'Ports/alfa/syswin.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Ports/alfa/syswin.c'\"
else
echo shar: Extracting \"'Ports/alfa/syswin.c'\" \(6713 characters\)
sed "s/^X//" >'Ports/alfa/syswin.c' <<'END_OF_FILE'
X/* STDWIN -- SYSTEM WINDOW. */
X
X#include "alfa.h"
X
XWINDOW *syswin; /* Window id 0, the system window */
X /* Global because wgetevent needs to know about
X it, so it can suppress events belonging to
X this window. */
X
Xstatic void
Xhelpmessage()
X{
X char buf[256];
X char shortcut[256];
X
X getbindings(shortcut, 0, MENU_CALL);
X sprintf(buf, "[Use %s to get a menu of commands]", shortcut);
X wmessage(buf);
X}
X
Xvoid
Xinitsyswin()
X{
X syswin= wopen("System", wsysdraw);
X helpmessage();
X}
X
Xchar *sysmsg; /* Message to be drawn at (0, 0) */
XTEXTEDIT *syste; /* Textedit record to be drawn, too */
X
X#ifdef EM
Xstatic char **Butt=NULL;
X#endif
X
X/*ARGSUSED*/
Xvoid
Xwsysdraw(win, left, top, right, bottom)
X WINDOW *win;
X int left, top;
X int right, bottom;
X{
X if (sysmsg != NULL) {
X (void) wdrawtext(0, 0, sysmsg, -1);
X if (syste != NULL)
X tedraw(syste);
X#ifdef EM
X if(Butt)
X drawbuttons();
X#endif
X }
X else
X drawmenubar();
X}
X
Xvoid
Xmenubarchanged()
X{
X uptodate[0]= FALSE;
X}
X
X/* Print a message in the system window.
X If the message is non-null, the screen is updated immediately. */
X
Xvoid
Xwmessage(str)
X char *str;
X{
X if (sysmsg != NULL)
X free(sysmsg);
X sysmsg= strdup(str);
X if (syste != NULL) {
X tefree(syste);
X syste= NULL;
X }
X wchange(syswin, 0, 0, 9999, 9999);
X wnocaret(syswin);
X if (str != NULL) {
X wupdate(syswin);
X wflush();
X }
X}
X
X/* Ask for an input string. */
X
Xbool
Xwaskstr(prompt, buf, len)
X char *prompt;
X char *buf;
X int len;
X{
X WINDOW *savewin= front;
X WINDOW *win= syswin;
X bool ok= FALSE;
X bool stop= FALSE;
X int teleft;
X
X wsetactive(win);
X wmessage((char *) NULL);
X sysmsg= prompt;
X teleft= wtextwidth(prompt, -1) + wtextwidth(" ", 1);
X if (teleft > columns * 3/4)
X teleft= columns * 3/4;
X syste= tealloc(syswin, teleft, 0, columns-teleft);
X tereplace(syste, buf);
X tesetfocus(syste, 0, 9999);
X do {
X EVENT e;
X
X if (!wsysevent(&e, FALSE)) {
X wupdate(syswin);
X wflush();
X wsysevent(&e, TRUE);
X }
X e.window= syswin; /* Not filled in by wsys*event();
X needed by teevent(). */
X
X switch (e.type) {
X
X case WE_MENU:
X if (e.u.m.id != 0) {
X wfleep();
X break;
X }
X switch (e.u.m.item) {
X
X case SUSPEND_PROC:
X _wsuspend();
X break;
X
X case REDRAW_SCREEN:
X _wredraw();
X break;
X
X default:
X if (e.u.m.item >= FIRST_CMD &&
X e.u.m.item <= LAST_CMD)
X wsyscommand(&e);
X break;
X }
X if (e.type != WE_COMMAND)
X break;
X
X /* Fall through from previous case! */
X case WE_COMMAND:
X switch (e.u.command) {
X
X case WC_RETURN:
X case WC_CANCEL:
X ok= e.u.command == WC_RETURN;
X stop= TRUE;
X break;
X
X default:
X if (!teevent(syste, &e))
X wfleep();
X break;
X
X }
X break;
X
X case WE_CHAR:
X case WE_MOUSE_DOWN:
X case WE_MOUSE_MOVE:
X case WE_MOUSE_UP:
X if (!teevent(syste, &e))
X wfleep();
X break;
X
X }
X } while (!stop);
X if (ok) {
X strncpy(buf, tegettext(syste), len);
X buf[len-1]= EOS;
X }
X sysmsg= NULL;
X wmessage((char *) NULL);
X wsetactive(savewin);
X return ok;
X}
X
X#ifdef EM
X/* EuroMath hacks -- I still hop I can get rid of this again... */
X#define META(c) ((c)|128)
X#define UNMETA(c) ((c)&~128)
X#define min(a,b) (a)<(b)?(a):(b)
Xchar *hack;
Xint Curr;
X
Xwdialog(prompt, buf, len, butt, def)
Xchar *prompt, *buf, **butt;
Xint len, def;
X{
X WINDOW *savewin= front;
X WINDOW *win= syswin;
X bool ok= FALSE;
X bool stop= FALSE;
X int teleft;
X int y=1, i;
X extern char* esc;
X extern char *expandCommand();
X
X if(butt==NULL)
X return waskstr(prompt, buf, len);
X
X Butt=butt;
X Curr=0;
X/* highlight the default button */
X for(i=0;butt[def-1][i];i++) butt[def-1][i]=META(butt[def-1][i]);
X wsetactive(win);
X wmessage((char *) NULL);
X sysmsg= prompt;
X teleft= wtextwidth(prompt, -1) + wtextwidth(" ", 1);
X if (teleft > columns * 3/4)
X teleft= columns * 3/4;
X syste= tealloc(syswin, teleft, 0, columns-teleft);
X tereplace(syste, strdup(buf));
X tesetfocus(syste, 0, 9999);
X/* calculate the number of buttons */
X while(butt[y-1]) {
X ++y;
X }
X --y;
Xrestart:
X do {
X EVENT e;
X
X if (!wsysevent(&e, FALSE)) {
X wupdate(syswin);
X wflush();
X wsysevent(&e, TRUE);
X }
X e.window= syswin; /* Not filled in by wsys*event();
X needed by teevent(). */
X
X switch (e.type) {
X case WE_MENU:
X if (e.u.m.id != 0) {
X wfleep();
X break;
X }
X switch (e.u.m.item) {
X
X case SUSPEND_PROC:
X _wsuspend();
X break;
X
X case REDRAW_SCREEN:
X _wredraw();
X break;
X
X default:
X if (e.u.m.item >= FIRST_CMD &&
X e.u.m.item <= LAST_CMD)
X wsyscommand(&e);
X break;
X }
X if (e.type != WE_COMMAND)
X break;
X
X /* Fall through from previous case! */
X case WE_COMMAND:
X switch (e.u.command) {
X/* the arrow-keys (up & down) are used to escape from the texedit
X buffer and select a button from the buttonlist */
X case WC_UP:
X --Curr;
X if(Curr<0)
X Curr=0;
X break;
X case WC_DOWN:
X ++Curr;
X if(Curr>y)
X Curr=0;
X break;
X case WC_RETURN:
X case WC_CANCEL:
X ok= e.u.command == WC_RETURN;
X stop= TRUE;
X break;
X
X default:
X if (Curr > 0)
X wfleep();
X else if (!teevent(syste, &e))
X wfleep();
X break;
X
X }
X break;
X
X case WE_CHAR:
X if(hack && e.u.character == *esc) {
X/* this is used by cmdbox(): pressing the `escape' character causes
Xthe typed in buffer to be expanded */
X char *buf2;
X tesetfocus(syste,0,9999);
X strzcpy(buf,tegettext(syste),min(len,tegetlen(syste)+1));
X buf2=expandCommand(hack, buf);
X tereplace(syste, buf2);
X tesetfocus(syste,0,9999);
X break;
X }
X case WE_MOUSE_DOWN:
X case WE_MOUSE_MOVE:
X case WE_MOUSE_UP:
X if(Curr > 0)
X wfleep();
X else if (!teevent(syste, &e))
X wfleep();
X break;
X
X }
X } while (!stop);
X if(hack && Curr == 3) {
X/* button 3 is "EXPAND". Used by cmdbox() */
X char *buf2;
X tesetfocus(syste,0,9999);
X strzcpy(buf,tegettext(syste),min(len,tegetlen(syste)+1));
X buf2=expandCommand(hack, tegettext(syste));
X tereplace(syste, buf2);
X tesetfocus(syste,0,9999);
X ok=stop=FALSE; Curr=0;
X goto restart;
X }
X if (ok) {
X strzcpy(buf, tegettext(syste), min(len, tegetlen(syste)+1));
X }
X sysmsg= NULL;
X wmessage((char *) NULL);
X wsetactive(savewin);
X if(Curr==0) Curr=def;
X Butt=NULL;
X for(i=0;butt[def-1][i];i++) butt[def-1][i]=UNMETA(butt[def-1][i]);
X _wredraw();
X return Curr;
X}
X
X/* this is inserted in the syswin drawproc whenever there are buttons
Xactive */
X
Xdrawbuttons()
X{
Xint y=1;
Xchar buf[256];
X
X while(Butt[y-1]) {
X if(y==Curr) sprintf(buf, "%c %s", META('o'), Butt[y-1]);
X else sprintf(buf, "o %s", Butt[y-1]);
X trmputdata(y, y, 0, buf);
X ++y;
X }
X trmputdata(y,y,0,"");
X}
X
X/* additional EuroMath WM routine, called after returning from an
XEditor-session (OpenTTY) */
X
XRedrawAll()
X{
X_wredraw();
X}
X
X#endif
END_OF_FILE
if test 6713 -ne `wc -c <'Ports/alfa/syswin.c'`; then
echo shar: \"'Ports/alfa/syswin.c'\" unpacked with wrong size!
fi
# end of 'Ports/alfa/syswin.c'
fi
if test -f 'Ports/mac/macwin.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Ports/mac/macwin.h'\"
else
echo shar: Extracting \"'Ports/mac/macwin.h'\" \(6389 characters\)
sed "s/^X//" >'Ports/mac/macwin.h' <<'END_OF_FILE'
X/* Source for the precompiled header file "macwin.h" in THINK C.
X This file includes other header files and defines symbols and types.
X It is included in the project for convenience; it generates no code.
X
X **********************************************************************
X * When you edit this file, you must generate a new "macwin.h": *
X * Choose "Precompile..." from the Source menu and save as "macwin.h" *
X * (overwriting the old "macwin.h"). *
X **********************************************************************
X
X For Think C version 3.0, define THINK_C_3_0 in "stdwconf.h".
X
X For MPW, move macwin.c to macwin.h and remove the <MacHeaders>
X include below.
X*/
X
X
X#include <MacHeaders> /*** REMOVE THIS FOR MPW ***/
X
X#include "stdwconf.h" /* Will set MPW or THINK_C */
X
X
X#ifdef MPW
X
X/* Without NO_STDIO, some THINK specific code gets compiled */
X#define NO_STDIO
X
X/* MPW names for Mac include files */
X#include <Types.h>
X#include <Quickdraw.h>
X#include <Windows.h>
X#include <Controls.h>
X
X/* Quickdraw globals aren't really global in MPW */
X#define QD(var) qd.var
X
X/* MPW allows 'static' in forward declarations */
X#define STATIC static
X
X/* MPW passes all Points by value */
X#define PASSPOINT &
X
X/* MPW glue converts most string on the fly.
X (XXX I believe you can turn this off now?) */
X#define CLEVERGLUE
X
X#endif
X
X
X#ifdef THINK_C
X
X/* You may also define NO_STDIO under THINK C, to avoid pulling in stdio */
X/* ...and for 4.0, it doesn't work anymore (sigh) */
X#ifndef THINK_C_3_0
X#define NO_STDIO
X#endif
X
X/* THINK's <WindowMgr.h> omits two essential constants of the Mac+ ROM */
X#define zoomDocProc 8
X#define zoomNoGrow 12
X
X/* Pascal-to-C and back string conversion routines have different names */
X#include <pascal.h>
X#define p2cstr PtoCstr
X#define c2pstr CtoPstr /* XXX actually, used nowhere */
X
X/* Quickdraw globals are real globals in THINK C */
X#define QD(var) (var)
X
X/* THINK C can't declare forward functions as static */
X#define STATIC /**/
X
X/* THINK C passes Points by value to some toolbox routines */
X#define PASSPOINT /**/
X
X#endif
X
X
X/* Private include files: */
X
X#include "tools.h"
X#include "stdwin.h"
X#include "menu.h"
X
X
X#ifdef CLEVERGLUE
X/* MPW converts C to Pascal strings in the glue */
X#define PSTRING(str) (str)
X#else
X/* THINK C needs a real function to do this (see "pstring.c").
X This is different from CtoPstr since it does not do it inline */
Xextern char *PSTRING _ARGS((char *));
X#endif
X
X
X/* Window struct. */
X
Xstruct _window {
X short tag; /* Window tag, usable as document id */
X void (*drawproc)(); /* Draw procedure */
X WindowPtr w; /* Mac Window */
X int hcaret, vcaret; /* Caret position, document coordinates */
X bool caret_on; /* Set if caret currently visible */
X TEXTATTR attr; /* Text attributes */
X ControlHandle hbar, vbar; /* Scroll bars */
X int docwidth, docheight; /* Document size */
X int orgh, orgv; /* Window origin, document coordinates */
X struct menubar mbar; /* List of attached local menus */
X unsigned long timer; /* Tick count for timer event */
X CURSOR *cursor; /* Cursor if not default */
X};
X
Xextern TEXTATTR wattr; /* Current text attributes */
X
X#define TX_INVERSE 0x80 /* Or-ed into style bits */
X
X/* Peculiarities of the Macintosh: */
X
X#define TICKSPERSECOND 60 /* Clock ticks at 60 Hz (everywhere) */
X
X#define MENUBARHEIGHT 20 /* Height of menu bar */
X#define TITLEBARHEIGHT 18 /* Height of window title bar */
X#define BAR 15 /* Scroll bar width, minus one pixel */
X
X/* ASCII codes generated by special keys: */
X#define ENTER_KEY 0x03
X
X#define LEFT_ARROW 0x1c
X#define RIGHT_ARROW 0x1d
X#define UP_ARROW 0x1e
X#define DOWN_ARROW 0x1f
X
X
X/* Miscellaneous definitions. */
X
X#define CLICK_DIST 5 /* Max mouse move within a click */
X
X/* Parameters for top left corner choice algorithm: */
X#define LEFT 20 /* Initial left */
X#define TOP 40 /* Initial top */
X#define HINCR 20 /* Increment for left */
X#define VINCR 16 /* Increment for top */
X
X/* Minimal window size (determined by room for scroll bars only): */
X#define MIN_WIDTH (2*BAR)
X#define MIN_HEIGHT (2*BAR)
X
X/* Text drawn in the very left or right margin doesn't look nice.
X Therefore, we have a little margin on each side.
X Its width is determined here: */
X#define LSLOP 4 /* Pixels in left margin */
X#define RSLOP 4 /* Pixels in right margin */
X
X/* Global data: */
Xextern GrafPtr screen; /* Window Manager's GrafPort */
Xextern WINDOW *active; /* Active window, if any */
Xextern bool _wmenuhilite; /* Set if menu item highlighted */
Xextern bool _wm_down; /* Set if mouse down (in appl. area) */
X
X/* Function prototypes: */
X
Xvoid dprintf _ARGS((char *fmt, ...));
X
Xvoid wsetstyle _ARGS((Style face));
X
XWINDOW *whichwin _ARGS((WindowPtr w));
X
Xvoid makerect _ARGS((WINDOW *win, Rect *pr,
X int left, int top, int right, int bottom));
Xvoid getwinrect _ARGS((WINDOW *win, Rect *pr));
X
Xvoid set_arrow _ARGS((void));
Xvoid set_applcursor _ARGS((void));
Xvoid set_watch _ARGS((void));
Xvoid set_ibeam _ARGS((void));
Xvoid set_hand _ARGS((void));
X
Xvoid makescrollbars _ARGS((WINDOW *win));
Xvoid movescrollbars _ARGS((WINDOW *win));
Xvoid hidescrollbars _ARGS((WINDOW *win));
Xvoid showscrollbars _ARGS((WINDOW *win));
X
Xvoid scrollby _ARGS((WINDOW *win, Rect *pr, int dh, int dv));
Xvoid do_scroll _ARGS((Point *pwhere,
X WINDOW *win, ControlHandle bar, int pcode));
Xvoid dragscroll _ARGS((WINDOW *win, int h, int v, int constrained));
X
Xvoid initwattr _ARGS((void));
X
Xvoid inval_border _ARGS((WindowPtr w));
Xvoid valid_border _ARGS((WindowPtr w));
X
Xvoid rmlocalmenus _ARGS((WINDOW *win));
Xvoid addlocalmenus _ARGS((WINDOW *win));
Xvoid initmbar _ARGS((struct menubar *mp));
Xvoid killmbar _ARGS((struct menubar *mp));
Xvoid setup_menus _ARGS((void));
X
Xvoid do_about _ARGS((void));
Xvoid getargcargv _ARGS((int *pargc, char ***pargv));
Xvoid fullpath _ARGS((char *buf, int wdrefnum, char *file));
Xchar *getdirname _ARGS((int wdrefnum));
X
X
Xvoid rmcaret _ARGS((WINDOW *win));
Xvoid showcaret _ARGS((WINDOW *win));
Xvoid blinkcaret _ARGS((WINDOW *win));
Xvoid _wresetmouse _ARGS((void));
X
Xvoid _wfreeclip _ARGS((void));
Xbool checktimer _ARGS((EVENT *ep));
Xvoid autoscroll _ARGS((WINDOW *active, int h, int v));
Xvoid _wdo_menu _ARGS((EVENT *ep, long menu_item));
X
X/* SetRect is much faster this way... */
X#define SetRect(pr, l, t, r, b) ((pr)->left = (l), (pr)->top = (t), \
X (pr)->right = (r), (pr)->bottom = (b))
END_OF_FILE
if test 6389 -ne `wc -c <'Ports/mac/macwin.h'`; then
echo shar: \"'Ports/mac/macwin.h'\" unpacked with wrong size!
fi
# end of 'Ports/mac/macwin.h'
fi
if test -f 'Ports/mac/stdwin.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Ports/mac/stdwin.c'\"
else
echo shar: Extracting \"'Ports/mac/stdwin.c'\" \(6341 characters\)
sed "s/^X//" >'Ports/mac/stdwin.c' <<'END_OF_FILE'
X/* MAC STDWIN -- BASIC ROUTINES. */
X
X#include "macwin.h"
X#ifdef MPW
X#include <Fonts.h>
X#include <Menus.h>
X#include <TextEdit.h>
X#include <Dialogs.h>
X#include <OSUtils.h>
X#include <SegLoad.h>
X#endif
X
X
X/* GLOBAL DATA. */
X
X /* XXX choose less obvious names */
XGrafPtr screen; /* The Mac Window Manager's GrafPort */
XTEXTATTR wattr; /* Current or default text attributes */
X
Xstatic int def_left= LEFT;
Xstatic int def_top= TOP;
Xstatic int def_width, def_height;
X
X
X/* INITIALIZATION AND TERMINATION. */
X
X/* Initialization */
X
Xint std_open_hook();
XSTATIC pascal resume _ARGS((void));
X
X/* Initialize, using and updating argc/argv: */
Xvoid
Xwinitargs(pargc, pargv)
X int *pargc;
X char ***pargv;
X{
X wargs(pargc, pargv);
X winit();
X}
X
X/* Initialize without touching argc/argv */
Xvoid
Xwinit()
X{
X#ifndef NO_STDIO
X /* Tell the THINK C stdio library we have initialized already */
X Stdio_MacInit(TRUE);
X#endif
X
X#ifdef THINK_C
X#ifndef THINK_C_3_0
X /*
X THINK C 4.0 may have done these initializations for us when
X the application has already used the console in any way.
X Doing them again is not a good idea.
X The THINK library avoids initializing the world if it appears
X that it has already been initialized, but in that case it
X will only allow output (all input requests return EOF).
X Thus, the application has two options:
X - call winit() or winitargs() first, then use the console
X only for (debugging) output; or
X - print at least one character to stdout first, then
X stdwin menu bar may not function properly.
X From inspection of the THINK library source it appears that
X when the console is initialized, stdin->std is cleared,
X so the test below suffices to skip initializations.
X */
X if (stdin->std)
X#endif
X#endif
X {
X MaxApplZone();
X InitGraf(&QD(thePort));
X InitFonts();
X InitWindows();
X TEInit();
X InitDialogs(resume);
X InitMenus();
X InitCursor();
X setup_menus();
X }
X GetWMgrPort(&screen);
X initwattr();
X#ifdef MPW
X set_open_hook(std_open_hook);
X#endif
X wsetdefwinsize(0, 0);
X set_watch();
X}
X
Xvoid
Xwdone()
X{
X}
X
Xvoid
Xwgetscrsize(pwidth, pheight)
X int *pwidth, *pheight;
X{
X Rect r;
X r= screen->portRect;
X *pwidth= r.right - r.left;
X *pheight= r.bottom - r.top;
X}
X
Xvoid
Xwgetscrmm(pmmwidth, pmmheight)
X int *pmmwidth, *pmmheight;
X{
X Rect r;
X r= screen->portRect;
X /* XXX Three pixels/mm is an approximation of the truth at most */
X *pmmwidth= (r.right - r.left) / 3;
X *pmmheight= (r.bottom - r.top) / 3;
X}
X
X/* Routine called by "Resume" button in bomb box (passed to InitDialogs).
X I have yet to see a program crash where an attempted exit to the
X Finder caused any harm, so I think it's safe.
X Anyway, it's tremendously useful during debugging. */
X
Xstatic pascal
Xresume()
X{
X ExitToShell();
X}
X
X/* WINDOWS. */
X
X/* Find the WINDOW pointer corresponding to a WindowPtr. */
X
XWINDOW *
Xwhichwin(w)
X WindowPtr w;
X{
X if (((WindowPeek)w)->windowKind < userKind)
X return NULL; /* Not an application-created window */
X else {
X WINDOW *win;
X
X win= (WINDOW *) GetWRefCon(w);
X if (win != NULL && win->w == w)
X return win;
X else
X return NULL;
X }
X}
X
XWINDOW *
Xwopen(title, drawproc)
X char *title;
X void (*drawproc)();
X{
X WINDOW *win= ALLOC(WINDOW);
X Rect r;
X
X if (win == NULL) {
X dprintf("wopen: ALLOC failed"); /* XXX */
X return NULL;
X }
X
X /* Find a nice position for the window. */
X if (def_left + def_width + BAR + LSLOP + RSLOP
X > screen->portRect.right) {
X def_left= LEFT;
X CLIPMAX(def_left, screen->portRect.right -
X (def_width + BAR + LSLOP + RSLOP));
X CLIPMIN(def_left, 0);
X }
X if (def_top + def_height + BAR > screen->portRect.bottom) {
X def_top= TOP;
X CLIPMAX(def_top, screen->portRect.bottom -
X (def_height + BAR));
X CLIPMIN(def_top, MENUBARHEIGHT + TITLEBARHEIGHT);
X }
X
X SetRect(&r, def_left, def_top,
X def_left+def_width + BAR + LSLOP + RSLOP,
X def_top+def_height + BAR);
X def_left += HINCR;
X def_top += VINCR;
X
X win->w= NewWindow((Ptr)NULL, &r, PSTRING(title), TRUE, zoomDocProc,
X (WindowPtr)(-1), TRUE, 0L);
X SetWRefCon(win->w, (long)win);
X
X win->tag= 0;
X win->drawproc= drawproc;
X win->hcaret= win->vcaret= -1;
X win->caret_on= FALSE;
X win->attr= wattr;
X win->hbar= win->vbar= NULL;
X win->docwidth= 0;
X win->docheight= 0;
X win->orgh= -LSLOP;
X win->orgv= 0;
X win->timer= 0;
X win->cursor = NULL;
X
X initmbar(&win->mbar);
X makescrollbars(win);
X
X return win;
X}
X
Xvoid
Xwclose(win)
X WINDOW *win;
X{
X if (win == active) {
X rmlocalmenus(win);
X active= NULL;
X }
X killmbar(&win->mbar);
X DisposeWindow(win->w);
X FREE(win);
X}
X
Xvoid
Xwgetwinsize(win, pwidth, pheight)
X WINDOW *win;
X int *pwidth, *pheight;
X{
X Rect r;
X
X getwinrect(win, &r);
X *pwidth= r.right - r.left - LSLOP - RSLOP;
X *pheight= r.bottom - r.top;
X}
X
Xvoid
Xwsettitle(win, title)
X WINDOW *win;
X char *title;
X{
X SetWTitle(win->w, PSTRING(title));
X}
X
Xchar *
Xwgettitle(win)
X WINDOW *win;
X{
X static char title[256];
X GetWTitle(win->w, title);
X#ifndef CLEVERGLUE
X PtoCstr(title);
X#endif
X return title;
X}
X
Xvoid
Xwfleep()
X{
X SysBeep(5);
X}
X
Xvoid
Xwsetmaxwinsize(width, height)
X int width, height;
X{
X /* Not supported yet (should be stored in the window struct
X and used by do_grow). */
X /* XXX This procedure should disappear completely, it was
X only invented for the Whitechapel which allocates bitmap
X memory to the window when it is first created! */
X /* XXX Well, maybe it has some use. In fact both min and max
X window size are sometimes useful... */
X}
X
Xvoid
Xwsetdefwinpos(h, v)
X int h, v;
X{
X /* XXX Sanity checks? Change interaction with wopen()? */
X if (h > 0)
X def_left = h;
X if (v > 0)
X def_top = v;
X}
X
Xvoid
Xwgetdefwinpos(ph, pv)
X int *ph, *pv;
X{
X *ph = def_left;
X *pv = def_top;
X}
X
Xvoid
Xwsetdefwinsize(width, height)
X int width, height;
X{
X /* XXX Shouldn't this be done by wopen() instead? */
X if (width <= 0) {
X width= screen->portRect.right * 2/3;
X CLIPMAX(width, 512);
X }
X CLIPMAX(width, screen->portRect.right - BAR - LSLOP - RSLOP);
X CLIPMIN(width, MIN_WIDTH);
X
X if (height <= 0) {
X height= screen->portRect.bottom * 2/3;
X CLIPMAX(height, 342);
X }
X CLIPMAX(height, screen->portRect.bottom
X - MENUBARHEIGHT - TITLEBARHEIGHT - BAR);
X CLIPMIN(height, MIN_HEIGHT);
X
X def_width= width;
X def_height= height;
X}
X
Xvoid
Xwgetdefwinsize(pwidth, pheight)
X int *pwidth, *pheight;
X{
X *pwidth = def_width;
X *pheight = def_height;
X}
X
Xvoid
Xwsetactive(win)
X WINDOW *win;
X{
X SelectWindow(win->w);
X}
END_OF_FILE
if test 6341 -ne `wc -c <'Ports/mac/stdwin.c'`; then
echo shar: \"'Ports/mac/stdwin.c'\" unpacked with wrong size!
fi
# end of 'Ports/mac/stdwin.c'
fi
if test -f 'Ports/x11/cursor.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Ports/x11/cursor.c'\"
else
echo shar: Extracting \"'Ports/x11/cursor.c'\" \(5190 characters\)
sed "s/^X//" >'Ports/x11/cursor.c' <<'END_OF_FILE'
X/* This was copied from the standard X11R4 client twm and then changed */
X
X/*
X * Copyright 1989 Massachusetts Institute of Technology
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided
X * that the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of M.I.T. not be used in advertising
X * or publicity pertaining to distribution of the software without specific,
X * written prior permission. M.I.T. makes no representations about the
X * suitability of this software for any purpose. It is provided "as is"
X * without express or implied warranty.
X *
X * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
X * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
X * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
X * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
X * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X */
X
X/***********************************************************************
X *
X * $XConsortium: cursor.c,v 1.10 89/12/14 14:52:23 jim Exp $
X *
X * cursor creation code
X *
X * 05-Apr-89 Thomas E. LaStrange File created
X *
X ***********************************************************************/
X
X#include "x11.h"
X
Xstatic struct _CursorName {
X char *name;
X unsigned int shape;
X Cursor cursor;
X} cursor_names[] = {
X
X{"X_cursor", XC_X_cursor, None},
X{"arrow", XC_arrow, None},
X{"based_arrow_down", XC_based_arrow_down, None},
X{"based_arrow_up", XC_based_arrow_up, None},
X{"boat", XC_boat, None},
X{"bogosity", XC_bogosity, None},
X{"bottom_left_corner", XC_bottom_left_corner, None},
X{"bottom_right_corner", XC_bottom_right_corner, None},
X{"bottom_side", XC_bottom_side, None},
X{"bottom_tee", XC_bottom_tee, None},
X{"box_spiral", XC_box_spiral, None},
X{"center_ptr", XC_center_ptr, None},
X{"circle", XC_circle, None},
X{"clock", XC_clock, None},
X{"coffee_mug", XC_coffee_mug, None},
X{"cross", XC_cross, None},
X{"cross_reverse", XC_cross_reverse, None},
X{"crosshair", XC_crosshair, None},
X{"diamond_cross", XC_diamond_cross, None},
X{"dot", XC_dot, None},
X{"dotbox", XC_dotbox, None},
X{"double_arrow", XC_double_arrow, None},
X{"draft_large", XC_draft_large, None},
X{"draft_small", XC_draft_small, None},
X{"draped_box", XC_draped_box, None},
X{"exchange", XC_exchange, None},
X{"fleur", XC_fleur, None},
X{"gobbler", XC_gobbler, None},
X{"gumby", XC_gumby, None},
X{"hand1", XC_hand1, None},
X{"hand2", XC_hand2, None},
X{"heart", XC_heart, None},
X{"ibeam", XC_xterm, None}, /* Mac stdwin compat */
X{"icon", XC_icon, None},
X{"iron_cross", XC_iron_cross, None},
X{"left_ptr", XC_left_ptr, None},
X{"left_side", XC_left_side, None},
X{"left_tee", XC_left_tee, None},
X{"leftbutton", XC_leftbutton, None},
X{"ll_angle", XC_ll_angle, None},
X{"lr_angle", XC_lr_angle, None},
X{"man", XC_man, None},
X{"middlebutton", XC_middlebutton, None},
X{"mouse", XC_mouse, None},
X{"pencil", XC_pencil, None},
X{"pirate", XC_pirate, None},
X{"plus", XC_plus, None},
X{"question_arrow", XC_question_arrow, None},
X{"right_ptr", XC_right_ptr, None},
X{"right_side", XC_right_side, None},
X{"right_tee", XC_right_tee, None},
X{"rightbutton", XC_rightbutton, None},
X{"rtl_logo", XC_rtl_logo, None},
X{"sailboat", XC_sailboat, None},
X{"sb_down_arrow", XC_sb_down_arrow, None},
X{"sb_h_double_arrow", XC_sb_h_double_arrow, None},
X{"sb_left_arrow", XC_sb_left_arrow, None},
X{"sb_right_arrow", XC_sb_right_arrow, None},
X{"sb_up_arrow", XC_sb_up_arrow, None},
X{"sb_v_double_arrow", XC_sb_v_double_arrow, None},
X{"shuttle", XC_shuttle, None},
X{"sizing", XC_sizing, None},
X{"spider", XC_spider, None},
X{"spraycan", XC_spraycan, None},
X{"star", XC_star, None},
X{"target", XC_target, None},
X{"tcross", XC_tcross, None},
X{"top_left_arrow", XC_top_left_arrow, None},
X{"top_left_corner", XC_top_left_corner, None},
X{"top_right_corner", XC_top_right_corner, None},
X{"top_side", XC_top_side, None},
X{"top_tee", XC_top_tee, None},
X{"trek", XC_trek, None},
X{"ul_angle", XC_ul_angle, None},
X{"umbrella", XC_umbrella, None},
X{"ur_angle", XC_ur_angle, None},
X{"watch", XC_watch, None},
X{"xterm", XC_xterm, None},
X};
X
Xstatic
XNewFontCursor (dpy, cp, str)
X Display *dpy;
X Cursor *cp;
X char *str;
X{
X int i;
X
X for (i = 0; i < sizeof(cursor_names)/sizeof(struct _CursorName); i++)
X {
X if (strcmp(str, cursor_names[i].name) == 0)
X {
X if (cursor_names[i].cursor == None)
X cursor_names[i].cursor = XCreateFontCursor(dpy,
X cursor_names[i].shape);
X *cp = cursor_names[i].cursor;
X return;
X }
X }
X _wwarning("NewFontCursor: unable to find font cursor \"%s\"", str);
X *cp = None;
X}
X
XCURSOR *
Xwfetchcursor(name)
X char *name;
X{
X Cursor c;
X NewFontCursor(_wd, &c, name);
X if (c == None)
X return NULL;
X else
X return (CURSOR *)c;
X}
END_OF_FILE
if test 5190 -ne `wc -c <'Ports/x11/cursor.c'`; then
echo shar: \"'Ports/x11/cursor.c'\" unpacked with wrong size!
fi
# end of 'Ports/x11/cursor.c'
fi
if test -f 'Ports/x11/event.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Ports/x11/event.c'\"
else
echo shar: Extracting \"'Ports/x11/event.c'\" \(5450 characters\)
sed "s/^X//" >'Ports/x11/event.c' <<'END_OF_FILE'
X/* X11 STDWIN -- High levent handling */
X
X/* THIS CODE IS A MESS. SHOULD BE RESTRUCTURED! */
X
X#include "x11.h"
X#include "llevent.h"
X#include <X11/keysym.h>
X
Xstatic WINDOW *active;
Xstatic WINDOW *prev_active;
X
X/* Ensure none of the window pointers refer to the given window --
X it's being closed so the pointer becomes invalid. */
X
X_w_deactivate(win)
X WINDOW *win;
X{
X if (win == active)
X active= NULL;
X if (win == _w_new_active)
X _w_new_active= NULL;
X if (win == prev_active)
X prev_active= NULL;
X if (win == _w_bs.win) {
X _w_bs.win= NULL;
X _w_bs.down= FALSE;
X }
X}
X
XWINDOW *
X_w_get_last_active()
X{
X if (_w_new_active != NULL)
X return _w_new_active;
X if (active != NULL)
X return active;
X if (prev_active != NULL)
X return prev_active;
X /* No window was ever active. Pick one at random. */
X return _w_somewin();
X}
X
XWINDOW *
Xwgetactive()
X{
X return active;
X}
X
X/* wungetevent may be called from a signal handler.
X If this is the case, we must send an event to ourselves
X so it is picked up (eventually).
X There is really still a race condition:
X if wungetevent copies an event into the evsave buffer
X when wgetevent is halfway of copying one out, we lose.
X This can only be fixed with multiple buffers and I dont
X want to think about that now. */
X
Xstatic bool in_getevent;
XEVENT _w_evsave; /* Accessible by _w_ll_event */
X
Xvoid
Xwungetevent(ep)
X EVENT *ep;
X{
X if (ep->type != WE_NULL) {
X _w_evsave= *ep;
X#ifdef PIPEHACK
X if (in_getevent) {
X if (_wpipe[1] < 0)
X _wwarning("wungetevent: can't interrupt wgetevent");
X else if (write(_wpipe[1], "x", 1) != 1)
X _wwarning("wungetevent: pipe write failed");
X else
X _wdebug(1, "wungetevent: wrote to pipe");
X }
X#endif
X }
X}
X
Xstatic void
X_wwaitevent(ep, mayblock)
X EVENT *ep;
X bool mayblock;
X{
X XEvent e;
X
X in_getevent= TRUE;
X
X if (_w_evsave.type != WE_NULL) {
X *ep= _w_evsave;
X _w_evsave.type= WE_NULL;
X in_getevent= FALSE;
X return;
X }
X
X /* Break out of this loop when we've got an event for the appl.,
X or, if mayblock is false, when we would block (in XNextEvent) */
X for (;;) {
X if (_w_close_this != NULL) {
X /* WM_DELETE_WINDOW detected */
X ep->type = WE_COMMAND;
X ep->window = _w_close_this;
X ep->u.command = WC_CLOSE;
X _w_close_this = NULL;
X break;
X }
X if (_w_lostselection(ep))
X return;
X if (_w_keysym != 0) {
X if (_w_new_active != active) {
X if (active != NULL) {
X ep->type= WE_DEACTIVATE;
X ep->window= prev_active= active;
X active= NULL;
X }
X else {
X ep->type= WE_ACTIVATE;
X ep->window= active= _w_new_active;
X }
X }
X else {
X ep->type= WE_CHAR;
X ep->window= active;
X ep->u.character= _w_keysym;
X change_key_event(ep);
X _w_keysym= 0;
X }
X if (ep->type != WE_NULL)
X break;
X }
X if (_w_bs_changed || _w_moved) {
X ep->type= WE_NULL;
X switch (_w_bs.isub) {
X case MBAR:
X _whitmbar(&_w_bs, ep);
X break;
X case MWIN:
X _whitmwin(&_w_bs, ep); /* XXX test */
X break;
X case HBAR:
X _whithbar(&_w_bs, ep);
X break;
X case VBAR:
X _whitvbar(&_w_bs, ep);
X break;
X case WA:
X ep->type= _w_moved ?
X WE_MOUSE_MOVE :
X _w_bs.down ?
X WE_MOUSE_DOWN :
X WE_MOUSE_UP;
X ep->window= _w_bs.win;
X ep->u.where.h= _w_bs.x;
X ep->u.where.v= _w_bs.y;
X ep->u.where.button= _w_bs.button;
X ep->u.where.clicks= _w_bs.clicks;
X ep->u.where.mask= _w_bs.mask;
X break;
X }
X _w_bs_changed= _w_moved= FALSE;
X if (ep->type != WE_NULL)
X break;
X }
X if (_w_checktimer(ep, FALSE))
X break;
X if (XPending(_wd) == 0)
X XSync(_wd, FALSE);
X if (XPending(_wd) == 0) {
X if (_w_new_active != active) {
X /* Why is this code duplicated here? */
X if (active != NULL) {
X ep->type= WE_DEACTIVATE;
X ep->window= prev_active= active;
X active= NULL;
X }
X else {
X ep->type= WE_ACTIVATE;
X ep->window= active= _w_new_active;
X }
X break;
X }
X if (_w_resized && _w_doresizes(ep))
X break;
X if (_w_dirty && _w_doupdates(ep))
X break;
X if (XPending(_wd) == 0 && _w_checktimer(ep, mayblock)
X || !mayblock)
X break;
X }
X#ifdef PIPEHACK
X if (_w_evsave.type != NULL) {
X /* Lots of race conditions here! */
X char dummy[256];
X int n;
X _wdebug(1, "wgetevent: got evt from handler");
X *ep= _w_evsave;
X _w_evsave.type= WE_NULL;
X if ((n= read(_wpipe[0], dummy, sizeof dummy)) <= 0)
X _wdebug(1, "wgetevent: read from pipe failed");
X else if (n != 1)
X _wdebug(0, "wgetevent: got %d bytes from pipe!", n);
X break;
X }
X#endif
X XNextEvent(_wd, &e);
X _w_ll_event(&e);
X }
X
X in_getevent= FALSE;
X}
X
Xbool
Xwpollevent(ep)
X EVENT *ep;
X{
X ep->type = WE_NULL;
X _wwaitevent(ep, FALSE);
X return ep->type != WE_NULL;
X}
X
Xvoid
Xwgetevent(ep)
X EVENT *ep;
X{
X _wwaitevent(ep, TRUE);
X}
X
Xstatic
Xchange_key_event(ep)
X EVENT *ep;
X{
X if (_w_state & Mod1Mask) {
X ep->type= WE_NULL;
X _w_menukey(ep->u.character, ep);
X return;
X }
X switch (ep->u.character) {
X case XK_Left:
X ep->u.command= WC_LEFT;
X break;
X case XK_Right:
X ep->u.command= WC_RIGHT;
X break;
X case XK_Up:
X ep->u.command= WC_UP;
X break;
X case XK_Down:
X ep->u.command= WC_DOWN;
X break;
X case '\n':
X case '\r':
X ep->u.command= WC_RETURN;
X break;
X case '\3':
X ep->u.command= WC_CANCEL;
X break;
X case '\b':
X case '\177': /* DEL */
X ep->u.command= WC_BACKSPACE;
X break;
X case '\t':
X ep->u.command= WC_TAB;
X break;
X default:
X if (ep->u.character < 0 || ep->u.character > 0177)
X ep->type= WE_NULL;
X return;
X }
X ep->type= WE_COMMAND;
X}
END_OF_FILE
if test 5450 -ne `wc -c <'Ports/x11/event.c'`; then
echo shar: \"'Ports/x11/event.c'\" unpacked with wrong size!
fi
# end of 'Ports/x11/event.c'
fi
echo shar: End of archive 13 \(of 19\).
cp /dev/null ark13isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 19 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
More information about the Alt.sources
mailing list