]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Menu items now turn on and off in a vaguely useful way.
authorBen Harris <bjh21@bjh21.me.uk>
Thu, 11 Mar 1999 21:40:32 +0000 (21:40 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Thu, 11 Mar 1999 21:40:32 +0000 (21:40 +0000)
Dragging to select now works.

[originally from svn r90]

mac.c
mac.h
mac_res.r
macresid.h
macterm.c

diff --git a/mac.c b/mac.c
index 6b5f866026d27516db89266825205ae54b71cbae..db6ff19ab6d0fe87007dc0c22959cfb27a6fdcd1 100644 (file)
--- a/mac.c
+++ b/mac.c
@@ -1,4 +1,4 @@
-/* $Id: mac.c,v 1.1.2.13 1999/03/09 00:09:50 ben Exp $ */
+/* $Id: mac.c,v 1.1.2.14 1999/03/11 21:40:31 ben Exp $ */
 /*
  * Copyright (c) 1999 Ben Harris
  * All rights reserved.
@@ -75,6 +75,14 @@ static void mac_shutdown(void);
 
 static void mac_newsession(void);
 
+struct mac_windows {
+    WindowPtr terminal; /* XXX: Temporary */
+    WindowPtr about;
+    WindowPtr licence;
+};
+
+struct mac_windows windows;
+
 int main (int argc, char **argv) {
 
     mac_startup();
@@ -123,6 +131,9 @@ static void mac_startup(void) {
     mac_adjustmenus();
     DrawMenuBar();
     InitCursor();
+    windows.terminal = NULL;
+    windows.about = NULL;
+    windows.licence = NULL;
 }
 
 static void mac_eventloop(void) {
@@ -228,6 +239,7 @@ static void mac_growwindow(WindowPtr window, EventRecord *event) {
 
 static void mac_activatewindow(WindowPtr window, Boolean active) {
 
+    mac_adjustmenus();
     switch (mac_windowtype(window)) {
       case wTerminal:
        mac_activateterm(window, active);
@@ -348,7 +360,29 @@ static void mac_zoomwindow(WindowPtr window, short part) {
  * Make the menus look right before the user gets to see them.
  */
 static void mac_adjustmenus(void) {
+    WindowPtr window;
+    MenuHandle menu;
 
+    window = FrontWindow();
+    menu = GetMenuHandle(mApple);
+    EnableItem(menu, 0);
+    EnableItem(menu, iAbout);
+
+    menu = GetMenuHandle(mFile);
+    EnableItem(menu, 0);
+    EnableItem(menu, iNew);
+    EnableItem(menu, iQuit);
+
+    switch (mac_windowtype(window)) {
+      case wTerminal:
+       mac_adjusttermmenus(window);
+       break;
+      default:
+       menu = GetMenuHandle(mEdit);
+       DisableItem(menu, 0);
+       break;
+    }
+    DrawMenuBar();
 }
 
 /*
@@ -386,3 +420,9 @@ void fatalbox(const char *fmt, ...) {
     StopAlert(128, nil);
     exit(1);
 }
+
+/*
+ * Local Variables:
+ * c-file-style: "simon"
+ * End:
+ */
diff --git a/mac.h b/mac.h
index 35d98eebdb5c980fdb4c26b6b8fa0500d1ae42eb..407614a3fe3991d697c7a42afe152f41aad9dc76 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_adjusttermmenus(WindowPtr);
 extern void mac_updateterm(WindowPtr);
 extern void mac_clickterm(WindowPtr, EventRecord *);
 extern void mac_growterm(WindowPtr, EventRecord *);
index fa8f79b40e4aade1cfa91349db59fffb6a595142..d41ebbc5b7d12e9d93e1cbce66b33a6b7c9e540c 100644 (file)
--- a/mac_res.r
+++ b/mac_res.r
@@ -1,4 +1,4 @@
-/* $Id: mac_res.r,v 1.1.2.8 1999/03/09 00:06:34 ben Exp $ */
+/* $Id: mac_res.r,v 1.1.2.9 1999/03/11 21:40:31 ben Exp $ */
 /*
  * Copyright (c) 1999 Ben Harris
  * All rights reserved.
@@ -244,7 +244,7 @@ resource 'icl8' (130, purgeable) {
 /* Menu bar */
 
 resource 'MBAR' (MBAR_Main, preload) {
-    { mApple, mFile }
+    { mApple, mFile, mEdit }
 };
 
 resource 'MENU' (mApple, preload) {
@@ -273,6 +273,23 @@ resource 'MENU' (mFile, preload) {
     }
 };
 
+resource 'MENU' (mEdit, preload) {
+    mEdit,
+    textMenuProc,
+    0b11111111111111111111111111111101,
+    enabled,
+    "Edit",
+    {
+       "Undo",                 noicon, "Z",   nomark, plain,
+       "-",                    noicon, nokey, nomark, plain,
+       "Cut",                  noicon, "X",   nomark, plain,
+       "Copy",                 noicon, "C",   nomark, plain,
+       "Paste",                noicon, "V",   nomark, plain,
+       "Clear",                noicon, nokey, nomark, plain,
+       "Select All",           noicon, "A",   nomark, plain,
+    }
+};
+
 /* Fatal error box.  Stolen from the Finder. */
 
 resource 'ALRT' (wFatal, "fatalbox", purgeable) {
@@ -641,11 +658,11 @@ resource 'pltt' (PREF_pltt, purgeable) {
 
 read 'pTST' (128, "test data", purgeable) "fragment";
 
-type 'cMAP' {
-    hexstring;
+type 'pMAP' {
+    hex string;
 };
 
-resource 'cMAP' (128, "Latin-1 G1 -> Mac OS Roman") {
+resource 'pMAP' (128, "Latin-1 G1 -> Mac OS Roman") {
     $"20 c1 a2 a3 db b4 00 a4 ac a9 bb c7 c2 00 a8 f8"
     $"a1 b1 00 00 ab b5 a6 e1 fc 00 bc c8 00 00 00 c0"
     $"cb e7 e5 cc 80 81 ae 82 e9 83 e6 e8 ed ea eb ec"
@@ -654,6 +671,7 @@ resource 'cMAP' (128, "Latin-1 G1 -> Mac OS Roman") {
     $"00 96 98 97 99 9b 9a d6 bf 9d 9c 9e 9f 00 00 D8"
 };
 
-resource 'cMAP' (129, "DEC line drawing -> Mac OS VT100") {
+resource 'pMAP' (129, "DEC line drawing -> Mac OS VT100") {
     $"d7 bd 09 0c 0d 0a a1 b1 00 0b d2 d3 d4 d5 da e2"
     $"e3 e4 f5 f6 f7 f8 f9 fa fb b2 b3 b9 ad a3 e1"
+};
\ No newline at end of file
index 941708f859b1e3424072392990743a48cf716589..dc1ce2a678268b940361053be9c97cc64062f85a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macresid.h,v 1.1.2.4 1999/02/28 02:38:40 ben Exp $ */
+/* $Id: macresid.h,v 1.1.2.5 1999/03/11 21:40:32 ben Exp $ */
 
 /*
  * macresid.h -- Mac resource IDs
@@ -13,6 +13,7 @@
 /* Menu IDs */
 #define mApple         128
 #define mFile          129
+#define mEdit          130
 
 /* Menu Items */
 /* Apple menu */
 #define iNew           1
 #define iClose         2
 #define iQuit          4
+/* Edit menu */
+#define iUndo          1
+#define iCut           3
+#define iCopy          4
+#define iPaste         5
+#define iClear         6
+#define iSelectAll     7
 
 /* Window types (and resource IDs) */
 #define wNone          0 /* Dummy value for no window */
index 6dffa718c675bad4c1189a6d39e6126b19fc3c63..80ac88872483b292c3b92c6988e147cbf28ba41e 100644 (file)
--- a/macterm.c
+++ b/macterm.c
@@ -1,4 +1,4 @@
-/* $Id: macterm.c,v 1.1.2.16 1999/03/09 00:09:50 ben Exp $ */
+/* $Id: macterm.c,v 1.1.2.17 1999/03/11 21:40:32 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>
 
@@ -199,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;
@@ -251,13 +274,21 @@ static void text_click(struct mac_session *s, EventRecord *event) {
        lastact = MA_CLICK;
     term_mouse(event->modifiers & shiftKey ? MB_EXTEND : MB_SELECT, lastact,
               col, row);
-    while (StillDown()) {
-       /* XXX Do something */
-    }
     lastsess = s;
     lastrow = row;
     lastcol = col;
-    lastwhen = event->when; /* XXX: should be time of mmouse _up_ */
+    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);
+    }
+    lastwhen = TickCount();
 }
 
 static pascal void mac_scrolltracker(ControlHandle control, short part) {
@@ -754,3 +785,10 @@ void do_scroll(int topline, int botline, int lines) {
     InvalRgn(update);
     DisposeRgn(update);
 }
+
+/*
+ * Emacs magic:
+ * Local Variables:
+ * c-file-style: "simon"
+ * End:
+ */