]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - mac.c
Very basic hex-dump backend for testing meta handling.
[PuTTY.git] / mac.c
diff --git a/mac.c b/mac.c
index 19636019a6c403f62afda6a96fdf9b8f35c1a6ec..267e341bb7917c27463f474a63e96e05e3fe3057 100644 (file)
--- a/mac.c
+++ b/mac.c
@@ -1,4 +1,4 @@
-/* $Id: mac.c,v 1.1.2.11 1999/03/03 22:03:54 ben Exp $ */
+/* $Id: mac.c,v 1.1.2.19 1999/03/28 02:06:10 ben Exp $ */
 /*
  * Copyright (c) 1999 Ben Harris
  * All rights reserved.
@@ -44,6 +44,7 @@
 #include <limits.h>
 #include <stdarg.h>
 #include <stdlib.h>            /* putty.h needs size_t */
+#include <stdio.h>             /* for vsprintf */
 
 #define PUTTY_DO_GLOBALS
 
@@ -58,6 +59,7 @@ struct mac_gestalts mac_gestalts;
 
 static void mac_startup(void);
 static void mac_eventloop(void);
+#pragma noreturn (mac_eventloop)
 static void mac_event(EventRecord *);
 static void mac_contentclick(WindowPtr, EventRecord *);
 static void mac_growwindow(WindowPtr, EventRecord *);
@@ -66,13 +68,20 @@ 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);
 static void mac_shutdown(void);
+#pragma noreturn (mac_shutdown)
 
-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) {
 
@@ -80,6 +89,8 @@ int main (int argc, char **argv) {
     mac_eventloop();
 }
 
+#pragma noreturn (main)
+
 static void mac_startup(void) {
     Handle menuBar;
 
@@ -109,6 +120,9 @@ static void mac_startup(void) {
     /* Mac OS 8.5 Control Manager (proportional scrollbars)? */
     if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr)
        mac_gestalts.cntlattr = 0;
+    /* Mac OS 8.5 Window Manager? */
+    if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr)
+       mac_gestalts.windattr = 0;
 
     /* We've been tested with the Appearance Manager */
     if (mac_gestalts.apprvers != 0)
@@ -122,20 +136,25 @@ static void mac_startup(void) {
     mac_adjustmenus();
     DrawMenuBar();
     InitCursor();
+    windows.terminal = NULL;
+    windows.about = NULL;
+    windows.licence = NULL;
 }
 
 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) {
@@ -227,6 +246,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);
@@ -272,46 +292,72 @@ static int mac_windowtype(WindowPtr window) {
  * Handle a key press
  */
 static void mac_keypress(EventRecord *event) {
-    char key;
+    WindowPtr window;
 
-    if (event->what == keyDown && (event->modifiers & cmdKey)) {
+    window = FrontWindow();
+    /*
+     * Check for a command-key combination, but ignore it if it counts
+     * as a meta-key combination and we're in a terminal window.
+     */
+    if (event->what == keyDown && (event->modifiers & cmdKey) &&
+       !((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers &&
+           mac_windowtype(window) == wTerminal)) {
        mac_adjustmenus();
        mac_menucommand(MenuKey(event->message & charCodeMask));
-    }
+    } else {
+       switch (mac_windowtype(window)) {
+         case wTerminal:
+           mac_keyterm(window, event);
+           break;
+       }
+    }       
 }
 
 static void mac_menucommand(long result) {
     short menu, item;
     Str255 da;
+    WindowPtr window;
 
     menu = HiWord(result);
     item = LoWord(result);
+    window = FrontWindow();
+    /* Things which do the same whatever window we're in. */
     switch (menu) {
       case mApple:
         switch (item) {
           case iAbout:
-            GetNewDialog(wAbout, NULL, (GrafPort *)-1);
-            break;
+           if (windows.about)
+               SelectWindow(windows.about);
+           else
+               windows.about = GetNewDialog(wAbout, NULL, (WindowPtr)-1);
+            goto done;
           default:
             GetMenuItemText(GetMenuHandle(mApple), item, da);
             OpenDeskAcc(da);
-            break;
+            goto done;
         }
         break;
       case mFile:
         switch (item) {
           case iNew:
             mac_newsession();
-            break;
+            goto done;
           case iClose:
-            mac_closewindow(FrontWindow());
-            break;
+            mac_closewindow(window);
+            goto done;
           case iQuit:
             mac_shutdown();
-            break;
+            goto done;
         }
         break;
     }
+    /* If we get here, handling is up to window-specific code. */
+    switch (mac_windowtype(window)) {
+      case wTerminal:
+       mac_menuterm(window, menu, item);
+       break;
+    }
+  done:
     HiliteMenu(0);
 }
 
@@ -324,6 +370,10 @@ static void mac_closewindow(WindowPtr window) {
       case wTerminal:
        /* FIXME: end session and stuff */
        break;
+      case wAbout:
+       windows.about = NULL;
+       CloseWindow(window);
+       break;
       default:
        CloseWindow(window);
        break;
@@ -339,15 +389,64 @@ 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);
+    if (window != NULL)
+       EnableItem(menu, iClose);
+    else
+       DisableItem(menu, iClose);
+    EnableItem(menu, iQuit);
 
+    switch (mac_windowtype(window)) {
+      case wTerminal:
+       mac_adjusttermmenus(window);
+       break;
+      default:
+       menu = GetMenuHandle(mEdit);
+       DisableItem(menu, 0);
+       break;
+    }
+    DrawMenuBar();
 }
 
 /*
  * 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) {
@@ -367,3 +466,9 @@ void fatalbox(const char *fmt, ...) {
     StopAlert(128, nil);
     exit(1);
 }
+
+/*
+ * Local Variables:
+ * c-file-style: "simon"
+ * End:
+ */