1 /* $Id: macdlg.c,v 1.6 2003/01/23 22:57:43 ben Exp $ */
3 * Copyright (c) 2002 Ben Harris
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 * macdlg.c - settings dialogue box for Mac OS.
33 #include <AEDataModel.h>
34 #include <AppleEvents.h>
36 #include <Resources.h>
37 #include <StandardFile.h>
48 void mac_newsession(void)
52 /* This should obviously be initialised by other means */
53 s = smalloc(sizeof(*s));
54 memset(s, 0, sizeof(*s));
55 do_defaults(NULL, &s->cfg);
56 s->back = &loop_backend;
59 s->settings_window = GetNewDialog(wSettings, NULL, (WindowPtr)-1);
61 SetWRefCon(s->settings_window, (long)s);
62 ShowWindow(s->settings_window);
65 static OSErr mac_opensessionfrom(FSSpec *fss)
73 s = smalloc(sizeof(*s));
74 memset(s, 0, sizeof(*s));
76 err = FSpGetFInfo(fss, &fi);
77 if (err != noErr) return err;
78 if (fi.fdFlags & kIsStationery)
85 sesshandle = open_settings_r_fsp(fss);
86 if (sesshandle == NULL) {
87 /* XXX need a way to pass up an error number */
91 load_open_settings(sesshandle, TRUE, &s->cfg);
92 close_settings_r(sesshandle);
95 * Select protocol. This is farmed out into a table in a
96 * separate file to enable an ssh-free variant.
99 for (i = 0; backends[i].backend != NULL; i++)
100 if (backends[i].protocol == s->cfg.protocol) {
101 s->back = backends[i].backend;
104 if (s->back == NULL) {
105 fatalbox("Unsupported protocol number found");
115 void mac_opensession(void) {
116 StandardFileReply sfr;
117 static const OSType sftypes[] = { 'Sess', 0, 0, 0 };
119 StandardGetFile(NULL, 1, sftypes, &sfr);
120 if (!sfr.sfGood) return;
122 mac_opensessionfrom(&sfr.sfFile);
123 /* XXX handle error */
126 void mac_savesession(void)
128 Session *s = (Session *)GetWRefCon(FrontWindow());
132 sesshandle = open_settings_w_fsp(&s->savefile);
133 if (sesshandle == NULL) return; /* XXX report error */
134 save_open_settings(sesshandle, TRUE, &s->cfg);
135 close_settings_w(sesshandle);
138 void mac_savesessionas(void)
140 Session *s = (Session *)GetWRefCon(FrontWindow());
141 StandardFileReply sfr;
144 StandardPutFile("\pSave session as:",
145 s->hasfile ? s->savefile.name : "\puntitled", &sfr);
146 if (!sfr.sfGood) return;
148 if (!sfr.sfReplacing) {
149 FSpCreateResFile(&sfr.sfFile, PUTTY_CREATOR, SESS_TYPE, sfr.sfScript);
150 if (ResError() != noErr) return; /* XXX report error */
152 sesshandle = open_settings_w_fsp(&sfr.sfFile);
153 if (sesshandle == NULL) return; /* XXX report error */
154 save_open_settings(sesshandle, TRUE, &s->cfg);
155 close_settings_w(sesshandle);
157 s->savefile = sfr.sfFile;
160 pascal OSErr mac_aevt_oapp(const AppleEvent *req, AppleEvent *reply,
166 if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard,
167 &type, NULL, 0, &size) == noErr)
168 return errAEParamMissed;
170 /* XXX we should do something here. */
174 pascal OSErr mac_aevt_odoc(const AppleEvent *req, AppleEvent *reply,
180 AEDescList docs = { typeNull, NULL };
185 err = AEGetParamDesc(req, keyDirectObject, typeAEList, &docs);
186 if (err != noErr) goto out;
188 if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard,
189 &type, NULL, 0, &size) == noErr) {
190 err = errAEParamMissed;
194 err = AECountItems(&docs, &ndocs);
195 if (err != noErr) goto out;
197 for (i = 0; i < ndocs; i++) {
198 err = AEGetNthPtr(&docs, i, typeFSS, &keywd, &type, &fss, sizeof(fss),
200 if (err != noErr) goto out;
201 err = mac_opensessionfrom(&fss);
202 if (err != noErr) goto out;
206 AEDisposeDesc(&docs);
210 pascal OSErr mac_aevt_pdoc(const AppleEvent *req, AppleEvent *reply,
216 if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard,
217 &type, NULL, 0, &size) == noErr)
218 return errAEParamMissed;
220 /* We can't meaningfully do anything here. */
221 return errAEEventNotHandled;
224 void mac_activatedlg(WindowPtr window, EventRecord *event)
226 DialogItemType itemtype;
232 active = (event->modifiers & activeFlag) != 0;
233 GetDialogItem(window, wiSettingsOpen, &itemtype, &itemhandle, &itemrect);
234 HiliteControl((ControlHandle)itemhandle, active ? 0 : 255);
235 DialogSelect(event, &window, &item);
238 void mac_clickdlg(WindowPtr window, EventRecord *event)
241 Session *s = (Session *)GetWRefCon(window);
243 if (DialogSelect(event, &window, &item))
254 * c-file-style: "simon"