Created new data types `Filename' and `FontSpec', intended to be
[u/mdw/putty] / mac / mac.c
index 5751ac8..32a7ece 100644 (file)
--- a/mac/mac.c
+++ b/mac/mac.c
@@ -1,4 +1,4 @@
-/* $Id: mac.c,v 1.33 2003/01/18 20:09:21 ben Exp $ */
+/* $Id: mac.c,v 1.38 2003/02/01 12:54:40 simon Exp $ */
 /*
  * Copyright (c) 1999 Ben Harris
  * All rights reserved.
@@ -29,6 +29,8 @@
  */
 
 #include <MacTypes.h>
+#include <AEDataModel.h>
+#include <AppleEvents.h>
 #include <Quickdraw.h>
 #include <Fonts.h>
 #include <MacWindows.h>
@@ -65,6 +67,7 @@ QDGlobals qd;
 Session *sesslist;
 
 static int cold = 1;
+static int borednow = FALSE;
 struct mac_gestalts mac_gestalts;
 
 static void mac_startup(void);
@@ -86,7 +89,6 @@ 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 (cleanup_exit)
 
 struct mac_windows {
@@ -169,21 +171,8 @@ static void mac_startup(void) {
        mac_gestalts.uncvattr = (*ti)->tecUnicodeConverterFeatures;
        DisposeHandle((Handle)ti);
     }
-    /* OpenTransport? */
-    if (Gestalt(gestaltOpenTpt, &mac_gestalts.otptattr) != noErr ||
-       (mac_gestalts.otptattr & gestaltOpenTptTCPPresentMask) == 0 ||
-       ot_init() != noErr)
-       mac_gestalts.otptattr = 0;
-    if (mac_gestalts.otptattr == 0) {
-       /* MacTCP? */
-       if (Gestalt(FOUR_CHAR_CODE('mtcp'), &mac_gestalts.mtcpvers) != noErr)
-           mac_gestalts.mtcpvers = 0;
-       if (mac_gestalts.mtcpvers > 0) {
-           if (mactcp_init() != noErr)
-               mac_gestalts.mtcpvers = 0;
-       }
-    } else
-       mac_gestalts.mtcpvers = 0;
+
+    sk_init();
 
     /* We've been tested with the Appearance Manager */
     if (mac_gestalts.apprvers != 0)
@@ -224,6 +213,16 @@ static void mac_startup(void) {
            LMSetCurDirStore(dirid);
        }
     }
+
+    /* Install Apple Event handlers. */
+    AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
+                         NewAEEventHandlerUPP(&mac_aevt_oapp), 0, FALSE);
+    AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
+                         NewAEEventHandlerUPP(&mac_aevt_odoc), 0, FALSE);
+    AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
+                         NewAEEventHandlerUPP(&mac_aevt_pdoc), 0, FALSE);
+    AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
+                         NewAEEventHandlerUPP(&mac_aevt_quit), 0, FALSE);
 }
 
 static void mac_eventloop(void) {
@@ -238,10 +237,9 @@ static void mac_eventloop(void) {
        mac_adjustcursor(cursrgn);
        if (gotevent)
            mac_event(&event);
-       if (mac_gestalts.mtcpvers != 0)
-           mactcp_poll();
-       if (mac_gestalts.otptattr != 0)
-           ot_poll();
+       if (borednow)
+           cleanup_exit(0);
+       sk_poll();
        mac_pollterm();
     }
     DisposeRgn(cursrgn);
@@ -304,6 +302,9 @@ static void mac_event(EventRecord *event) {
            DIBadMount(pt, event->message);
         }
         break;
+      case kHighLevelEvent:
+       AEProcessAppleEvent(event); /* errors? */
+       break;
     }
 }
 
@@ -491,6 +492,9 @@ static void mac_menucommand(long result) {
          case iSaveAs:
            mac_savesessionas();
            goto done;
+         case iDuplicate:
+           mac_dupsession();
+           goto done;
           case iQuit:
             cleanup_exit(0);
             goto done;
@@ -590,6 +594,7 @@ static void mac_adjustmenus(void) {
       case wSettings:
        DisableItem(menu, iSave); /* XXX enable if modified */
        EnableItem(menu, iSaveAs);
+       EnableItem(menu, iDuplicate);
        menu = GetMenuHandle(mEdit);
        DisableItem(menu, 0);
        break;
@@ -599,6 +604,7 @@ static void mac_adjustmenus(void) {
       default:
        DisableItem(menu, iSave);
        DisableItem(menu, iSaveAs);
+       DisableItem(menu, iDuplicate);
        menu = GetMenuHandle(mEdit);
        DisableItem(menu, 0);
        break;
@@ -637,6 +643,20 @@ static void mac_adjustcursor(RgnHandle cursrgn) {
     }
 }
 
+pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply,
+                                 long refcon)
+{
+    DescType type;
+    Size size;
+
+    if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard,
+                         &type, NULL, 0, &size) == noErr)
+       return errAEParamMissed;
+
+    borednow = 1;
+    return noErr;
+}
+
 void cleanup_exit(int status)
 {
 
@@ -721,8 +741,9 @@ void old_keyfile_warning(void)
 
 }
 
-char *platform_default_s(char const *name)
+FontSpec platform_default_font(char const *name)
 {
+    FontSpec ret;
     long smfs;
     Str255 pname;
     static char cname[256];
@@ -734,12 +755,33 @@ char *platform_default_s(char const *name)
        if (smfs != 0) {
            GetFontName(HiWord(smfs), pname);
            if (pname[0] == 0)
-               return "Monaco";
-           p2cstrcpy(cname, pname);
-           return cname;
-       } else
-           return "Monaco";
+               strcpy(ret.name, "Monaco");
+           ret.height = LoWord(smfs);
+           p2cstrcpy(ret.name, pname);
+       } else {
+           strcpy(ret.name, "Monaco");
+           ret.height = 9;
+       }
+       ret.isbold = 0;
+    } else {
+       ret.name[0] = '\0';
     }
+
+    return ret;
+}
+
+Filename platform_default_filename(const char *name)
+{
+    Filename ret;
+    if (!strcmp(name, "LogFileName"))
+       strcpy(ret.path, "putty.log");
+    else
+       *ret.path = '\0';
+    return ret;
+}
+
+char *platform_default_s(char const *name)
+{
     return NULL;
 }
 
@@ -747,16 +789,6 @@ int platform_default_i(char const *name, int def)
 {
     long smfs;
 
-    if (!strcmp(name, "FontHeight")) {
-       smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize);
-       if (smfs == 0)
-           smfs = GetScriptVariable(smRoman, smScriptMonoFondSize);
-       if (smfs != 0)
-           return LoWord(smfs);
-       else
-           return 9;
-    }
-
     /* Non-raw cut and paste of line-drawing chars works badly on the
      * current Unix stub implementation of the Unicode functions.
      * So I'm going to temporarily set the default to raw mode so
@@ -773,6 +805,29 @@ void platform_get_x11_auth(char *display, int *proto,
     /* SGT: I have no idea whether Mac X servers need anything here. */
 }
 
+Filename filename_from_str(char *str)
+{
+    Filename ret;
+    strncpy(ret.path, str, sizeof(ret.path));
+    ret.path[sizeof(ret.path)-1] = '\0';
+    return ret;
+}
+
+char *filename_to_str(Filename fn)
+{
+    return fn.path;
+}
+
+int filename_equal(Filename f1, Filename f2)
+{
+    return !strcmp(f1.path, f2.path);
+}
+
+int filename_is_null(Filename fn)
+{
+    return !*fn.path;
+}
+
 /*
  * Local Variables:
  * c-file-style: "simon"