home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1993, 1994 Marc Parmet.
- * This file is part of the Macintosh port of GNU Emacs.
- *
- * GNU Emacs is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
- #if defined(THINK_C)
- #include <MacHeaders>
- #else
- #include <Types.h>
- #include <Memory.h>
- #include <Quickdraw.h>
- #include <Windows.h>
- #include <TextEdit.h>
- #include <Resources.h>
- #include <Fonts.h>
- #endif
-
- #include <GestaltEqu.h>
- #include "errno.h"
- #include "unix-types.h"
- #include "unix-constants.h"
-
- // Maybe we just need one global pointer to the tty object
- // instead of these two.
- static WindowPtr w;
- static TEHandle teh;
-
- void
- tty_update(void)
- {
- BeginUpdate(w);
- TEUpdate(&w->portRect,teh);
- SetPort(w);
- EndUpdate(w);
- }
-
- WindowPtr
- tty_window(void)
- {
- return w;
- }
-
- void
- tty_expose(void)
- {
- SelectWindow(w);
- ShowWindow(w);
- }
-
- void
- tty_activate(void)
- {
- }
-
- void
- tty_goaway(EventRecord *e)
- {
- if (TrackGoAway(w,e->where)) HideWindow(w);
- }
-
- void
- tty_drag(EventRecord *e)
- {
- /* WRONG! */
- DragWindow(w,e->where,&qd.screenBits.bounds);
- }
-
- void
- tty_content(void)
- {
- SelectWindow(w);
- }
-
- static long
- tty_dispatch(long job,long index,long fd,char *p,long n,struct savearea_lomem *lomem)
- {
- GrafPtr gp;
- struct unix_object **object = proctable[index].fd[fd].object;
-
- switch (job) {
- case unix_write:
- if (n > 0) {
- GetPort(&gp);
- if (console_window() != 0L) SelectWindow((**object).u.tty.w);
- ShowWindow((**object).u.tty.w);
- SetPort((**object).u.tty.w);
- unix_translate(p,n);
- TEInsert(p,n,(**object).u.tty.teh);
- unix_translate(p,n);
- TESelView((**object).u.tty.teh);
- SetPort(gp);
- }
- return n;
- case unix_close:
- TEDispose((**object).u.tty.teh);
- DisposeWindow((**object).u.tty.w);
- return 0;
- case unix_read:
- return handle_all_events_but_keystrokes(p,n);
- case unix_fionread:
- *(int *)p = number_of_pending_events();
- return 0;
- }
- }
-
- static void
- init_tty_window(struct unix_object **object)
- {
- Rect r;
- void *t;
- int err,have_CQD;
- long response;
- unsigned char *name = (unsigned char *)"\pstdout-stderr";
- extern WindowPtr w;
- extern TEHandle teh;
-
- err = Gestalt(gestaltQuickdrawVersion,&response);
- have_CQD = (err == 0 && response >= gestalt8BitQD);
-
- t = GetResource('WIND',135);
- if (t == 0L) {
- SetRect(&r,40,40,500,240);
- if (have_CQD)
- w = NewCWindow(0L,&r,name,1,noGrowDocProc,(WindowPtr)-1L,1,0L);
- else
- w = NewWindow(0L,&r,name,1,noGrowDocProc,(WindowPtr)-1L,1,0L);
- }
- else
- if (have_CQD)
- w = GetNewCWindow(135,0L,(WindowPtr)-1);
- else
- w = GetNewWindow(135,0L,(WindowPtr)-1);
-
- (**object).u.tty.w = w;
- r = w->portRect;
- OffsetRect(&r,-r.left,-r.top);
- InsetRect(&r,4,2);
- SetPort(w);
- TextFont(monaco);
- TextSize(9);
- teh = TENew(&r,&r);
- (**object).u.tty.teh = teh;
- TEAutoView(-1,teh);
- }
-
- int
- open_internal_dev_tty(void)
- {
- int fd;
- struct unix_object **object;
-
- object = lookup_object(object_flavor_dev_tty,0);
- if (object == 0L) {
- object = add_object(object_flavor_dev_tty,0);
- if (object == 0L) { set_errno(EUNDOC); return -1; }
- init_tty_window(object);
- }
- else
- ++(**object).count;
-
- fd = add_fd(fd_flavor_dev_tty,tty_dispatch,object);
- if (fd < 0) {
- dec_object_count(object);
- set_errno(EUNDOC);
- return -1;
- }
- else
- return fd;
- }
-