I think the Carbon build now works well enough to be worth turning on by
[u/mdw/putty] / mac / mac.c
index a0bc998..d8b9b2f 100644 (file)
--- a/mac/mac.c
+++ b/mac/mac.c
@@ -1,4 +1,4 @@
-/* $Id: mac.c,v 1.49 2003/02/15 16:22:15 ben Exp $ */
+/* $Id: mac.c,v 1.51 2003/02/23 11:58:59 ben Exp $ */
 /*
  * Copyright (c) 1999, 2003 Ben Harris
  * All rights reserved.
@@ -76,6 +76,7 @@ static void mac_event(EventRecord *);
 static void mac_contentclick(WindowPtr, EventRecord *);
 static void mac_growwindow(WindowPtr, EventRecord *);
 static void mac_activatewindow(WindowPtr, EventRecord *);
+static void mac_suspendresume(EventRecord *);
 static void mac_activateabout(WindowPtr, EventRecord *);
 static void mac_updatewindow(WindowPtr);
 static void mac_updatelicence(WindowPtr);
@@ -323,6 +324,13 @@ static void mac_event(EventRecord *event) {
         }
         break;
 #endif
+      case osEvt:
+       switch ((event->message & osEvtMessageMask) >> 24) {
+         case suspendResumeMessage:
+           mac_suspendresume(event);
+           break;
+       }
+       break;
       case kHighLevelEvent:
        AEProcessAppleEvent(event); /* errors? */
        break;
@@ -377,7 +385,7 @@ static int mac_windowtype(WindowPtr window)
 static void mac_keypress(EventRecord *event) {
     WindowPtr window;
 
-    window = FrontWindow();
+    window = mac_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.
@@ -388,7 +396,7 @@ static void mac_keypress(EventRecord *event) {
        mac_adjustmenus();
        mac_menucommand(MenuKey(event->message & charCodeMask));
     } else {
-       if (mac_wininfo(window)->key != NULL)
+       if (window != NULL && mac_wininfo(window)->key != NULL)
            (*mac_wininfo(window)->key)(window, event);
     }       
 }
@@ -402,7 +410,7 @@ static void mac_menucommand(long result) {
 
     menu = HiWord(result);
     item = LoWord(result);
-    window = FrontWindow();
+    window = mac_frontwindow();
     /* Things which do the same whatever window we're in. */
     switch (menu) {
       case mApple:
@@ -445,7 +453,7 @@ static void mac_menucommand(long result) {
         break;
     }
     /* If we get here, handling is up to window-specific code. */
-    if (mac_wininfo(window)->menu != NULL)
+    if (window != NULL && mac_wininfo(window)->menu != NULL)
        (*mac_wininfo(window)->menu)(window, menu, item);
 
   done:
@@ -467,6 +475,27 @@ static void mac_closewindow(WindowPtr window) {
     }
 }
 
+static void mac_suspendresume(EventRecord *event)
+{
+    WindowPtr front;
+    EventRecord fakeevent;
+
+    /*
+     * We're called either before we're suspended or after we're
+     * resumed, so we're the front application at this point.
+     */
+    front = FrontWindow();
+    if (front != NULL) {
+       fakeevent.what = activateEvt;
+       fakeevent.message = (UInt32)front;
+       fakeevent.when = event->when;
+       fakeevent.where = event->where;
+       fakeevent.modifiers =
+           (event->message & resumeFlag) ? activeFlag : 0;
+       mac_activatewindow(front, &fakeevent);
+    }
+}
+
 static void mac_zoomwindow(WindowPtr window, short part) {
 
     /* FIXME: do something */
@@ -483,7 +512,7 @@ static void mac_adjustmenus(void) {
     WindowPtr window;
     MenuHandle menu;
 
-    window = FrontWindow();
+    window = mac_frontwindow();
     menu = GetMenuHandle(mApple);
     EnableItem(menu, 0);
     EnableItem(menu, iAbout);
@@ -497,7 +526,7 @@ static void mac_adjustmenus(void) {
        DisableItem(menu, iClose);
     EnableItem(menu, iQuit);
 
-    if (mac_wininfo(window)->adjustmenus != NULL)
+    if (window != NULL && mac_wininfo(window)->adjustmenus != NULL)
        (*mac_wininfo(window)->adjustmenus)(window);
     else {
        DisableItem(menu, iSave);