Carbonise. Until we support Navigation Services, loading and saving sessions
[sgt/putty] / mac / macdlg.c
index 2606f0b..56f2d9a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macdlg.c,v 1.7 2003/01/25 14:04:47 ben Exp $ */
+/* $Id: macdlg.c,v 1.9 2003/02/01 23:55:00 ben Exp $ */
 /*
  * Copyright (c) 2002 Ben Harris
  * All rights reserved.
@@ -53,21 +53,34 @@ void mac_newsession(void)
     s = smalloc(sizeof(*s));
     memset(s, 0, sizeof(*s));
     do_defaults(NULL, &s->cfg);
-    s->back = &loop_backend;
     s->hasfile = FALSE;
 
-    s->settings_window = GetNewDialog(wSettings, NULL, (WindowPtr)-1);
+    s->settings_window =
+       GetDialogWindow(GetNewDialog(wSettings, NULL, (WindowPtr)-1));
 
     SetWRefCon(s->settings_window, (long)s);
     ShowWindow(s->settings_window);
 }
 
+void mac_dupsession(void)
+{
+    Session *s1 = (Session *)GetWRefCon(FrontWindow());
+    Session *s2;
+
+    s2 = smalloc(sizeof(*s2));
+    memset(s2, 0, sizeof(*s2));
+    s2->cfg = s1->cfg;
+    s2->hasfile = s1->hasfile;
+    s2->savefile = s1->savefile;
+
+    mac_startsession(s2);
+}
+
 static OSErr mac_opensessionfrom(FSSpec *fss)
 {
     FInfo fi;
     Session *s;
     void *sesshandle;
-    int i;
     OSErr err;
 
     s = smalloc(sizeof(*s));
@@ -91,19 +104,6 @@ static OSErr mac_opensessionfrom(FSSpec *fss)
     load_open_settings(sesshandle, TRUE, &s->cfg);
     close_settings_r(sesshandle);
 
-    /*
-     * Select protocol. This is farmed out into a table in a
-     * separate file to enable an ssh-free variant.
-     */
-    s->back = NULL;
-    for (i = 0; backends[i].backend != NULL; i++)
-       if (backends[i].protocol == s->cfg.protocol) {
-           s->back = backends[i].backend;
-           break;
-       }
-    if (s->back == NULL) {
-       fatalbox("Unsupported protocol number found");
-    }
     mac_startsession(s);
     return noErr;
 
@@ -112,7 +112,9 @@ static OSErr mac_opensessionfrom(FSSpec *fss)
     return err;
 }
 
-void mac_opensession(void) {
+void mac_opensession(void)
+{
+#if !TARGET_API_MAC_CARBON /* XXX Navigation Services */
     StandardFileReply sfr;
     static const OSType sftypes[] = { 'Sess', 0, 0, 0 };
 
@@ -121,6 +123,7 @@ void mac_opensession(void) {
 
     mac_opensessionfrom(&sfr.sfFile);
     /* XXX handle error */
+#endif
 }
 
 void mac_savesession(void)
@@ -137,6 +140,7 @@ void mac_savesession(void)
 
 void mac_savesessionas(void)
 {
+#if !TARGET_API_MAC_CARBON /* XXX Navigation Services */
     Session *s = (Session *)GetWRefCon(FrontWindow());
     StandardFileReply sfr;
     void *sesshandle;
@@ -155,6 +159,7 @@ void mac_savesessionas(void)
     close_settings_w(sesshandle);
     s->hasfile = TRUE;
     s->savefile = sfr.sfFile;
+#endif
 }
 
 pascal OSErr mac_aevt_oapp(const AppleEvent *req, AppleEvent *reply,
@@ -228,22 +233,24 @@ void mac_activatedlg(WindowPtr window, EventRecord *event)
     short item;
     Rect itemrect;
     int active;
+    DialogRef dialog = GetDialogFromWindow(window);
 
     active = (event->modifiers & activeFlag) != 0;
-    GetDialogItem(window, wiSettingsOpen, &itemtype, &itemhandle, &itemrect);
+    GetDialogItem(dialog, wiSettingsOpen, &itemtype, &itemhandle, &itemrect);
     HiliteControl((ControlHandle)itemhandle, active ? 0 : 255);
-    DialogSelect(event, &window, &item);
+    DialogSelect(event, &dialog, &item);
 }
 
 void mac_clickdlg(WindowPtr window, EventRecord *event)
 {
     short item;
     Session *s = (Session *)GetWRefCon(window);
+    DialogRef dialog = GetDialogFromWindow(window);
 
-    if (DialogSelect(event, &window, &item))
+    if (DialogSelect(event, &dialog, &item))
        switch (item) {
          case wiSettingsOpen:
-           CloseWindow(window);
+           HideWindow(window);
            mac_startsession(s);
            break;
        }