]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - mac.c
The "about" box now behaves approximately as it should (though we still don't
[PuTTY.git] / mac.c
diff --git a/mac.c b/mac.c
index 6304b1ca1eb34b683f545b7f615cdaa556fb6692..d90fc37558bd7f8b4a1081dace4f5f1caf057cd2 100644 (file)
--- a/mac.c
+++ b/mac.c
@@ -1,4 +1,4 @@
-/* $Id: mac.c,v 1.1.2.17 1999/03/21 23:23:42 ben Exp $ */
+/* $Id: mac.c,v 1.1.2.23 1999/04/02 12:58:02 ben Exp $ */
 /*
  * Copyright (c) 1999 Ben Harris
  * All rights reserved.
 #include <Menus.h>
 #include <TextEdit.h>
 #include <Appearance.h>
+#include <CodeFragments.h>
 #include <Dialogs.h>
 #include <Devices.h>
 #include <DiskInit.h>
 #include <Gestalt.h>
+#include <Resources.h>
 #include <ToolUtils.h>
 
+#include <assert.h>
 #include <limits.h>
 #include <stdarg.h>
 #include <stdlib.h>            /* putty.h needs size_t */
@@ -59,24 +62,25 @@ 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 *);
-static void mac_activatewindow(WindowPtr, Boolean);
+static void mac_activatewindow(WindowPtr, EventRecord *);
+static void mac_activateabout(WindowPtr, EventRecord *);
 static void mac_updatewindow(WindowPtr);
 static void mac_keypress(EventRecord *);
 static int mac_windowtype(WindowPtr);
 static void mac_menucommand(long);
+static void mac_openabout(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);
-
-static void mac_newsession(void);
+#pragma noreturn (mac_shutdown)
 
 struct mac_windows {
-    WindowPtr terminal; /* XXX: Temporary */
     WindowPtr about;
     WindowPtr licence;
 };
@@ -89,6 +93,8 @@ int main (int argc, char **argv) {
     mac_eventloop();
 }
 
+#pragma noreturn (main)
+
 static void mac_startup(void) {
     Handle menuBar;
 
@@ -115,9 +121,15 @@ static void mac_startup(void) {
            mac_gestalts.apprvers = 0x0100;
        else
            mac_gestalts.apprvers = 0;
+    /* Paranoia: Did we manage to pull in AppearanceLib? */
+    if (&RegisterAppearanceClient == kUnresolvedCFragSymbolAddress)
+       mac_gestalts.apprvers = 0;
     /* 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)
@@ -131,7 +143,6 @@ static void mac_startup(void) {
     mac_adjustmenus();
     DrawMenuBar();
     InitCursor();
-    windows.terminal = NULL;
     windows.about = NULL;
     windows.licence = NULL;
 }
@@ -139,7 +150,6 @@ static void mac_startup(void) {
 static void mac_eventloop(void) {
     Boolean gotevent;
     EventRecord event;
-    int i;
     RgnHandle cursrgn;
 
     cursrgn = NewRgn();
@@ -199,8 +209,7 @@ static void mac_event(EventRecord *event) {
         mac_keypress(event);
         break;
       case activateEvt:
-       mac_activatewindow((WindowPtr)event->message,
-                          (event->modifiers & activeFlag) != 0);
+       mac_activatewindow((WindowPtr)event->message, event);
         break;
       case updateEvt:
         mac_updatewindow((WindowPtr)event->message);
@@ -240,16 +249,34 @@ static void mac_growwindow(WindowPtr window, EventRecord *event) {
     }
 }
 
-static void mac_activatewindow(WindowPtr window, Boolean active) {
+static void mac_activatewindow(WindowPtr window, EventRecord *event) {
+    int active;
 
+    active = (event->modifiers & activeFlag) != 0;
     mac_adjustmenus();
     switch (mac_windowtype(window)) {
       case wTerminal:
        mac_activateterm(window, active);
        break;
+      case wAbout:
+       mac_activateabout(window, event);
+       break;
     }
 }
 
+static void mac_activateabout(WindowPtr window, EventRecord *event) {
+    DialogItemType itemtype;
+    Handle itemhandle;
+    short item;
+    Rect itemrect;
+    int active;
+
+    active = (event->modifiers & activeFlag) != 0;
+    GetDialogItem(window, wiAboutLicence, &itemtype, &itemhandle, &itemrect);
+    HiliteControl((ControlHandle)itemhandle, active ? 0 : 255);
+    DialogSelect(event, &window, &item);
+}
+
 static void mac_updatewindow(WindowPtr window) {
 
     switch (mac_windowtype(window)) {
@@ -288,14 +315,19 @@ 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 {
-       window = FrontWindow();
        switch (mac_windowtype(window)) {
          case wTerminal:
            mac_keyterm(window, event);
@@ -317,10 +349,7 @@ static void mac_menucommand(long result) {
       case mApple:
         switch (item) {
           case iAbout:
-           if (windows.about)
-               SelectWindow(windows.about);
-           else
-               windows.about = GetNewDialog(wAbout, NULL, (WindowPtr)-1);
+           mac_openabout();
             goto done;
           default:
             GetMenuItemText(GetMenuHandle(mApple), item, da);
@@ -352,6 +381,28 @@ static void mac_menucommand(long result) {
     HiliteMenu(0);
 }
 
+static void mac_openabout(void) {
+    DialogItemType itemtype;
+    Handle item;
+    VersRecHndl vers;
+    Rect box;
+    StringPtr longvers;
+
+    if (windows.about)
+       SelectWindow(windows.about);
+    else {
+       windows.about = GetNewDialog(wAbout, NULL, (WindowPtr)-1);
+       /* XXX check we're using the right resource file? */
+       vers = (VersRecHndl)GetResource('vers', 1);
+       assert(vers != NULL && *vers != NULL);
+       longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1;
+       GetDialogItem(windows.about, wiAboutVersion, &itemtype, &item, &box);
+       assert(itemtype & kStaticTextDialogItem);
+       SetDialogItemText(item, longvers);
+       ShowWindow(windows.about);
+    }
+}
+
 static void mac_closewindow(WindowPtr window) {
 
     switch (mac_windowtype(window)) {