]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Pointer-shape canging added -- we now have an I-beam cursor in the terminal
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 21 Mar 1999 23:23:43 +0000 (23:23 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 21 Mar 1999 23:23:43 +0000 (23:23 +0000)
 window.
Pasting works!

[originally from svn r123]

mac.c
mac.h
macterm.c
testback.c

diff --git a/mac.c b/mac.c
index ea2664002b27ea743e84b996b15f62b5b0981326..6304b1ca1eb34b683f545b7f615cdaa556fb6692 100644 (file)
--- 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 cfc11a70972a2c2c224f89ed032d8c365967bdbc..7e3b3e7999ce562e04bacf85fffb0b1446b6d2c1 100644 (file)
--- 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 *);
index fd0e1f330aedb541d01a28a1fc36eb95a192ab0d..3e62829f27e66a9d323ac70630db09ba5970ac83 100644 (file)
--- 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,
index be49761a6451b7efc223671e3b5c495092d4a48e..b2ccd17a67e76835bf43777c7dcbce6641eff424 100644 (file)
@@ -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();
 }