]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - mac.c
Rebranch some files on 'ben-mac-port' from trunk.
[PuTTY.git] / mac.c
diff --git a/mac.c b/mac.c
index 267e341bb7917c27463f474a63e96e05e3fe3057..6de3768575ed406b93a052ec2ff3f177cc0cd32f 100644 (file)
--- a/mac.c
+++ b/mac.c
@@ -1,4 +1,4 @@
-/* $Id: mac.c,v 1.1.2.19 1999/03/28 02:06:10 ben Exp $ */
+/* $Id: mac.c,v 1.1.2.25 1999/08/02 08:04:31 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 */
@@ -63,11 +66,13 @@ static void mac_eventloop(void);
 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);
@@ -76,7 +81,6 @@ static void mac_shutdown(void);
 #pragma noreturn (mac_shutdown)
 
 struct mac_windows {
-    WindowPtr terminal; /* XXX: Temporary */
     WindowPtr about;
     WindowPtr licence;
 };
@@ -117,6 +121,9 @@ 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;
@@ -136,9 +143,24 @@ static void mac_startup(void) {
     mac_adjustmenus();
     DrawMenuBar();
     InitCursor();
-    windows.terminal = NULL;
     windows.about = NULL;
     windows.licence = NULL;
+
+    /* Initialise networking */
+#ifdef WITH_OPENTRANSPORT
+    if ((*opentpt_stack.init)() == 0)
+       net_stack = &opentpt_stack;
+    else 
+#endif
+#ifdef WITH_MACTCP
+    if ((*mactcp_stack.init)() == 0)
+       net_stack = &mactcp_stack;
+    else
+#endif
+       fatalbox("No useful TCP/IP stack found");
+
+       
+
 }
 
 static void mac_eventloop(void) {
@@ -153,6 +175,7 @@ static void mac_eventloop(void) {
        mac_adjustcursor(cursrgn);
        if (gotevent)
            mac_event(&event);
+       net_poll();
     }
     DisposeRgn(cursrgn);
 }
@@ -203,8 +226,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);
@@ -244,16 +266,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)) {
@@ -299,9 +339,9 @@ static void mac_keypress(EventRecord *event) {
      * 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) &&
+    if (event->what == keyDown && (event->modifiers & cmdKey) /*&&
        !((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers &&
-           mac_windowtype(window) == wTerminal)) {
+           mac_windowtype(window) == wTerminal)*/) {
        mac_adjustmenus();
        mac_menucommand(MenuKey(event->message & charCodeMask));
     } else {
@@ -326,10 +366,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);
@@ -361,6 +398,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)) {
@@ -451,6 +510,7 @@ static void mac_adjustcursor(RgnHandle cursrgn) {
 
 static void mac_shutdown(void) {
 
+    net_shutdown();
     exit(0);
 }