1 /* $Id: macdlg.c,v 1.9 2003/02/01 23:55:00 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
);
59 GetDialogWindow(GetNewDialog(wSettings
, NULL
, (WindowPtr
)-1));
61 SetWRefCon(s
->settings_window
, (long)s
);
62 ShowWindow(s
->settings_window
);
65 void mac_dupsession(void)
67 Session
*s1
= (Session
*)GetWRefCon(FrontWindow());
70 s2
= smalloc(sizeof(*s2
));
71 memset(s2
, 0, sizeof(*s2
));
73 s2
->hasfile
= s1
->hasfile
;
74 s2
->savefile
= s1
->savefile
;
79 static OSErr
mac_opensessionfrom(FSSpec
*fss
)
86 s
= smalloc(sizeof(*s
));
87 memset(s
, 0, sizeof(*s
));
89 err
= FSpGetFInfo(fss
, &fi
);
90 if (err
!= noErr
) return err
;
91 if (fi
.fdFlags
& kIsStationery
)
98 sesshandle
= open_settings_r_fsp(fss
);
99 if (sesshandle
== NULL
) {
100 /* XXX need a way to pass up an error number */
104 load_open_settings(sesshandle
, TRUE
, &s
->cfg
);
105 close_settings_r(sesshandle
);
115 void mac_opensession(void)
117 #if !TARGET_API_MAC_CARBON /* XXX Navigation Services */
118 StandardFileReply sfr
;
119 static const OSType sftypes
[] = { 'Sess', 0, 0, 0 };
121 StandardGetFile(NULL
, 1, sftypes
, &sfr
);
122 if (!sfr
.sfGood
) return;
124 mac_opensessionfrom(&sfr
.sfFile
);
125 /* XXX handle error */
129 void mac_savesession(void)
131 Session
*s
= (Session
*)GetWRefCon(FrontWindow());
135 sesshandle
= open_settings_w_fsp(&s
->savefile
);
136 if (sesshandle
== NULL
) return; /* XXX report error */
137 save_open_settings(sesshandle
, TRUE
, &s
->cfg
);
138 close_settings_w(sesshandle
);
141 void mac_savesessionas(void)
143 #if !TARGET_API_MAC_CARBON /* XXX Navigation Services */
144 Session
*s
= (Session
*)GetWRefCon(FrontWindow());
145 StandardFileReply sfr
;
148 StandardPutFile("\pSave session as:",
149 s
->hasfile ? s
->savefile
.name
: "\puntitled", &sfr
);
150 if (!sfr
.sfGood
) return;
152 if (!sfr
.sfReplacing
) {
153 FSpCreateResFile(&sfr
.sfFile
, PUTTY_CREATOR
, SESS_TYPE
, sfr
.sfScript
);
154 if (ResError() != noErr
) return; /* XXX report error */
156 sesshandle
= open_settings_w_fsp(&sfr
.sfFile
);
157 if (sesshandle
== NULL
) return; /* XXX report error */
158 save_open_settings(sesshandle
, TRUE
, &s
->cfg
);
159 close_settings_w(sesshandle
);
161 s
->savefile
= sfr
.sfFile
;
165 pascal OSErr
mac_aevt_oapp(const AppleEvent
*req
, AppleEvent
*reply
,
171 if (AEGetAttributePtr(req
, keyMissedKeywordAttr
, typeWildCard
,
172 &type
, NULL
, 0, &size
) == noErr
)
173 return errAEParamMissed
;
175 /* XXX we should do something here. */
179 pascal OSErr
mac_aevt_odoc(const AppleEvent
*req
, AppleEvent
*reply
,
185 AEDescList docs
= { typeNull
, NULL
};
190 err
= AEGetParamDesc(req
, keyDirectObject
, typeAEList
, &docs
);
191 if (err
!= noErr
) goto out
;
193 if (AEGetAttributePtr(req
, keyMissedKeywordAttr
, typeWildCard
,
194 &type
, NULL
, 0, &size
) == noErr
) {
195 err
= errAEParamMissed
;
199 err
= AECountItems(&docs
, &ndocs
);
200 if (err
!= noErr
) goto out
;
202 for (i
= 0; i
< ndocs
; i
++) {
203 err
= AEGetNthPtr(&docs
, i
+ 1, typeFSS
,
204 &keywd
, &type
, &fss
, sizeof(fss
), &size
);
205 if (err
!= noErr
) goto out
;
206 err
= mac_opensessionfrom(&fss
);
207 if (err
!= noErr
) goto out
;
211 AEDisposeDesc(&docs
);
215 pascal OSErr
mac_aevt_pdoc(const AppleEvent
*req
, AppleEvent
*reply
,
221 if (AEGetAttributePtr(req
, keyMissedKeywordAttr
, typeWildCard
,
222 &type
, NULL
, 0, &size
) == noErr
)
223 return errAEParamMissed
;
225 /* We can't meaningfully do anything here. */
226 return errAEEventNotHandled
;
229 void mac_activatedlg(WindowPtr window
, EventRecord
*event
)
231 DialogItemType itemtype
;
236 DialogRef dialog
= GetDialogFromWindow(window
);
238 active
= (event
->modifiers
& activeFlag
) != 0;
239 GetDialogItem(dialog
, wiSettingsOpen
, &itemtype
, &itemhandle
, &itemrect
);
240 HiliteControl((ControlHandle
)itemhandle
, active ?
0 : 255);
241 DialogSelect(event
, &dialog
, &item
);
244 void mac_clickdlg(WindowPtr window
, EventRecord
*event
)
247 Session
*s
= (Session
*)GetWRefCon(window
);
248 DialogRef dialog
= GetDialogFromWindow(window
);
250 if (DialogSelect(event
, &dialog
, &item
))
261 * c-file-style: "simon"