]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - macterm.c
First attempt at copying to the clipboard -- doesn't seem to work.
[PuTTY.git] / macterm.c
index 6c1f28f930225c622b79b6c90841163b76c15800..6141925e74bdb6647662f4b3289dba1c3ed5c04e 100644 (file)
--- a/macterm.c
+++ b/macterm.c
@@ -1,4 +1,4 @@
-/* $Id: macterm.c,v 1.1.2.15 1999/03/07 23:22:23 ben Exp $ */
+/* $Id: macterm.c,v 1.1.2.18 1999/03/11 23:23:45 ben Exp $ */
 /*
  * Copyright (c) 1999 Ben Harris
  * All rights reserved.
@@ -38,6 +38,7 @@
 #include <Quickdraw.h>
 #include <QuickdrawText.h>
 #include <Resources.h>
+#include <Scrap.h>
 #include <Sound.h>
 #include <ToolUtils.h>
 
@@ -70,6 +71,7 @@ static void mac_adjustsize(struct mac_session *, int, int);
 static pascal void mac_scrolltracker(ControlHandle, short);
 static pascal void do_text_for_device(short, short, GDHandle, long);
 static int mac_keytrans(struct mac_session *, EventRecord *, unsigned char *);
+static void text_click(struct mac_session *, EventRecord *);
 
 /*
  * Temporary hack till I get the terminal emulator supporting multiple
@@ -198,6 +200,28 @@ static void mac_updatewinbg(struct mac_session *s) {
     SetWinColor(s->window, cth);
 }
 
+/*
+ * Enable/disable menu items based on the active terminal window.
+ */
+void mac_adjusttermmenus(WindowPtr window) {
+    struct mac_session *s;
+    MenuHandle menu;
+    long offset;
+
+    s = (struct mac_session *)GetWRefCon(window);
+    menu = GetMenuHandle(mEdit);
+    EnableItem(menu, 0);
+    DisableItem(menu, iUndo);
+    DisableItem(menu, iCut);
+    DisableItem(menu, iCopy);
+    if (GetScrap(NULL, 'TEXT', &offset) == noTypeErr)
+       DisableItem(menu, iPaste);
+    else
+       EnableItem(menu, iPaste);
+    DisableItem(menu, iClear);
+    EnableItem(menu, iSelectAll);
+}
+
 void mac_clickterm(WindowPtr window, EventRecord *event) {
     struct mac_session *s;
     Point mouse;
@@ -222,7 +246,63 @@ void mac_clickterm(WindowPtr window, EventRecord *event) {
            TrackControl(control, mouse, mac_scrolltracker);
            break;
        }
+    } else {
+       text_click(s, event);
+    }
+}
+
+static void text_click(struct mac_session *s, EventRecord *event) {
+    Point localwhere;
+    int row, col;
+    static UInt32 lastwhen = 0;
+    static struct mac_session *lastsess = NULL;
+    static int lastrow = -1, lastcol = -1;
+    static Mouse_Action lastact = MA_NOTHING;
+
+    SetPort(s->window);
+    localwhere = event->where;
+    GlobalToLocal(&localwhere);
+
+    col = localwhere.h / font_width;
+    row = localwhere.v / font_height;
+    if (event->when - lastwhen < GetDblTime() &&
+       row == lastrow && col == lastcol && s == lastsess)
+       lastact = (lastact == MA_CLICK ? MA_2CLK :
+                  lastact == MA_2CLK ? MA_3CLK :
+                  lastact == MA_3CLK ? MA_CLICK : MA_NOTHING);
+    else
+       lastact = MA_CLICK;
+    term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT, lastact,
+              col, row);
+    lastsess = s;
+    lastrow = row;
+    lastcol = col;
+    while (StillDown()) {
+       GetMouse(&localwhere);
+       col = localwhere.h / font_width;
+       row = localwhere.v / font_height;
+       term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT,
+                  MA_DRAG, col, row);
+       if (row > rows - 1)
+           term_scroll(0, row - (rows - 1));
+       else if (row <= 0)
+           term_scroll(0, row - 1);
     }
+    term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT, MA_RELEASE,
+              col, row);
+    lastwhen = TickCount();
+}
+
+void write_clip(void *data, int len) {
+    
+    if (ZeroScrap() != noErr)
+       return;
+    PutScrap(len, 'TEXT', data);
+}
+
+void get_clip(void **p, int *lenp) {
+
+    /* XXX: do something */
 }
 
 static pascal void mac_scrolltracker(ControlHandle control, short part) {
@@ -719,3 +799,10 @@ void do_scroll(int topline, int botline, int lines) {
     InvalRgn(update);
     DisposeRgn(update);
 }
+
+/*
+ * Emacs magic:
+ * Local Variables:
+ * c-file-style: "simon"
+ * End:
+ */