1 /* $Id: macdlg.c,v 1.8 2003/01/25 15:15:40 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);
58 s->settings_window = GetNewDialog(wSettings, NULL, (WindowPtr)-1);
60 SetWRefCon(s->settings_window, (long)s);
61 ShowWindow(s->settings_window);
64 void mac_dupsession(void)
66 Session *s1 = (Session *)GetWRefCon(FrontWindow());
69 s2 = smalloc(sizeof(*s2));
70 memset(s2, 0, sizeof(*s2));
72 s2->hasfile = s1->hasfile;
73 s2->savefile = s1->savefile;
78 static OSErr mac_opensessionfrom(FSSpec *fss)
85 s = smalloc(sizeof(*s));
86 memset(s, 0, sizeof(*s));
88 err = FSpGetFInfo(fss, &fi);
89 if (err != noErr) return err;
90 if (fi.fdFlags & kIsStationery)
97 sesshandle = open_settings_r_fsp(fss);
98 if (sesshandle == NULL) {
99 /* XXX need a way to pass up an error number */
103 load_open_settings(sesshandle, TRUE, &s->cfg);
104 close_settings_r(sesshandle);
114 void mac_opensession(void) {
115 StandardFileReply sfr;
116 static const OSType sftypes[] = { 'Sess', 0, 0, 0 };
118 StandardGetFile(NULL, 1, sftypes, &sfr);
119 if (!sfr.sfGood) return;
121 mac_opensessionfrom(&sfr.sfFile);
122 /* XXX handle error */
125 void mac_savesession(void)
127 Session *s = (Session *)GetWRefCon(FrontWindow());
131 sesshandle = open_settings_w_fsp(&s->savefile);
132 if (sesshandle == NULL) return; /* XXX report error */
133 save_open_settings(sesshandle, TRUE, &s->cfg);
134 close_settings_w(sesshandle);
137 void mac_savesessionas(void)
139 Session *s = (Session *)GetWRefCon(FrontWindow());
140 StandardFileReply sfr;
143 StandardPutFile("\pSave session as:",
144 s->hasfile ? s->savefile.name : "\puntitled", &sfr);
145 if (!sfr.sfGood) return;
147 if (!sfr.sfReplacing) {
148 FSpCreateResFile(&sfr.sfFile, PUTTY_CREATOR, SESS_TYPE, sfr.sfScript);
149 if (ResError() != noErr) return; /* XXX report error */
151 sesshandle = open_settings_w_fsp(&sfr.sfFile);
152 if (sesshandle == NULL) return; /* XXX report error */
153 save_open_settings(sesshandle, TRUE, &s->cfg);
154 close_settings_w(sesshandle);
156 s->savefile = sfr.sfFile;
159 pascal OSErr mac_aevt_oapp(const AppleEvent *req, AppleEvent *reply,
165 if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard,
166 &type, NULL, 0, &size) == noErr)
167 return errAEParamMissed;
169 /* XXX we should do something here. */
173 pascal OSErr mac_aevt_odoc(const AppleEvent *req, AppleEvent *reply,
179 AEDescList docs = { typeNull, NULL };
184 err = AEGetParamDesc(req, keyDirectObject, typeAEList, &docs);
185 if (err != noErr) goto out;
187 if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard,
188 &type, NULL, 0, &size) == noErr) {
189 err = errAEParamMissed;
193 err = AECountItems(&docs, &ndocs);
194 if (err != noErr) goto out;
196 for (i = 0; i < ndocs; i++) {
197 err = AEGetNthPtr(&docs, i + 1, typeFSS,
198 &keywd, &type, &fss, sizeof(fss), &size);
199 if (err != noErr) goto out;
200 err = mac_opensessionfrom(&fss);
201 if (err != noErr) goto out;
205 AEDisposeDesc(&docs);
209 pascal OSErr mac_aevt_pdoc(const AppleEvent *req, AppleEvent *reply,
215 if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard,
216 &type, NULL, 0, &size) == noErr)
217 return errAEParamMissed;
219 /* We can't meaningfully do anything here. */
220 return errAEEventNotHandled;
223 void mac_activatedlg(WindowPtr window, EventRecord *event)
225 DialogItemType itemtype;
231 active = (event->modifiers & activeFlag) != 0;
232 GetDialogItem(window, wiSettingsOpen, &itemtype, &itemhandle, &itemrect);
233 HiliteControl((ControlHandle)itemhandle, active ? 0 : 255);
234 DialogSelect(event, &window, &item);
237 void mac_clickdlg(WindowPtr window, EventRecord *event)
240 Session *s = (Session *)GetWRefCon(window);
242 if (DialogSelect(event, &window, &item))
253 * c-file-style: "simon"