diff --git a/mac.c b/mac.c index ea266400..6304b1ca 100644 --- a/mac.c +++ b/mac.c @@ -1,4 +1,4 @@ -/* $Id: mac.c,v 1.1.2.16 1999/03/16 20:27:30 ben Exp $ */ +/* $Id: mac.c,v 1.1.2.17 1999/03/21 23:23:42 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -67,7 +67,7 @@ static void mac_updatewindow(WindowPtr); static void mac_keypress(EventRecord *); static int mac_windowtype(WindowPtr); static void mac_menucommand(long); -static void mac_adjustcursor(void); +static void mac_adjustcursor(RgnHandle); static void mac_adjustmenus(void); static void mac_closewindow(WindowPtr); static void mac_zoomwindow(WindowPtr, short); @@ -140,14 +140,17 @@ static void mac_eventloop(void) { Boolean gotevent; EventRecord event; int i; + RgnHandle cursrgn; + cursrgn = NewRgn(); for (;;) { - mac_adjustcursor(); - gotevent = WaitNextEvent(everyEvent, &event, LONG_MAX, NULL); - mac_adjustcursor(); + mac_adjustcursor(cursrgn); + gotevent = WaitNextEvent(everyEvent, &event, LONG_MAX, cursrgn); + mac_adjustcursor(cursrgn); if (gotevent) mac_event(&event); } + DisposeRgn(cursrgn); } static void mac_event(EventRecord *event) { @@ -409,9 +412,32 @@ static void mac_adjustmenus(void) { /* * Make sure the right cursor's being displayed. */ -static void mac_adjustcursor(void) { +static void mac_adjustcursor(RgnHandle cursrgn) { + Point mouse; + WindowPtr window, front; + short part; - SetCursor(&qd.arrow); + GetMouse(&mouse); + LocalToGlobal(&mouse); + part = FindWindow(mouse, &window); + front = FrontWindow(); + if (part != inContent || window == NULL || window != front) { + /* Cursor isn't in the front window, so switch to arrow */ + SetCursor(&qd.arrow); + SetRectRgn(cursrgn, SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); + if (front != NULL) + DiffRgn(cursrgn, front->visRgn, cursrgn); + } else { + switch (mac_windowtype(window)) { + case wTerminal: + mac_adjusttermcursor(window, mouse, cursrgn); + break; + default: + SetCursor(&qd.arrow); + CopyRgn(window->visRgn, cursrgn); + break; + } + } } static void mac_shutdown(void) { diff --git a/mac.h b/mac.h index cfc11a70..7e3b3e79 100644 --- a/mac.h +++ b/mac.h @@ -22,6 +22,7 @@ extern struct mac_gestalts mac_gestalts; /* from macterm.c */ extern void mac_newsession(void); extern void mac_activateterm(WindowPtr, Boolean); +extern void mac_adjusttermcursor(WindowPtr, Point, RgnHandle); extern void mac_adjusttermmenus(WindowPtr); extern void mac_updateterm(WindowPtr); extern void mac_clickterm(WindowPtr, EventRecord *); diff --git a/macterm.c b/macterm.c index fd0e1f33..3e62829f 100644 --- a/macterm.c +++ b/macterm.c @@ -1,4 +1,4 @@ -/* $Id: macterm.c,v 1.1.2.26 1999/03/18 00:04:34 ben Exp $ */ +/* $Id: macterm.c,v 1.1.2.27 1999/03/21 23:23:42 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -239,6 +239,34 @@ static void mac_adjustwinbg(struct mac_session *s) { SetWinColor(s->window, s->wctab); } +/* + * Set the cursor shape correctly + */ +void mac_adjusttermcursor(WindowPtr window, Point mouse, RgnHandle cursrgn) { + struct mac_session *s; + ControlHandle control; + short part; + int x, y; + + SetPort(window); + s = (struct mac_session *)GetWRefCon(window); + GlobalToLocal(&mouse); + part = FindControl(mouse, window, &control); + if (control == s->scrollbar) { + SetCursor(&qd.arrow); + RectRgn(cursrgn, &(*s->scrollbar)->contrlRect); + SectRgn(cursrgn, window->visRgn, cursrgn); + } else { + x = mouse.h / font_width; + y = mouse.v / font_height; + SetCursor(*GetCursor(iBeamCursor)); + /* Ask for shape changes if we leave this character cell. */ + SetRectRgn(cursrgn, x * font_width, y * font_height, + (x + 1) * font_width, (y + 1) * font_height); + SectRgn(cursrgn, window->visRgn, cursrgn); + } +} + /* * Enable/disable menu items based on the active terminal window. */ @@ -370,10 +398,12 @@ void get_clip(void **p, int *lenp) { h = NULL; } else if (GetScrap(NULL, 'TEXT', &offset) > 0) { - h = NewEmptyHandle(); + h = NewHandle(0); *lenp = GetScrap(h, 'TEXT', &offset); HLock(h); *p = *h; + if (*p == NULL || *lenp <= 0) + fatalbox("Empty scrap"); } else { *p = NULL; *lenp = 0; @@ -452,8 +482,6 @@ void mac_keyterm(WindowPtr window, EventRecord *event) { s = (struct mac_session *)GetWRefCon(window); len = mac_keytrans(s, event, buf); back->send((char *)buf, len); - term_out(); - term_update(); } static int mac_keytrans(struct mac_session *s, EventRecord *event, diff --git a/testback.c b/testback.c index be49761a..b2ccd17a 100644 --- a/testback.c +++ b/testback.c @@ -1,4 +1,4 @@ -/* $Id: testback.c,v 1.1.2.2 1999/03/18 00:04:34 ben Exp $ */ +/* $Id: testback.c,v 1.1.2.3 1999/03/21 23:23:43 ben Exp $ */ /* * Copyright (c) 1999 Simon Tatham * Copyright (c) 1999 Ben Harris @@ -70,6 +70,8 @@ static void loop_send (char *buf, int len) { inbuf_head = new_head; } } + term_out(); + term_update(); }