From: ben Date: Thu, 23 Jan 2003 22:57:43 +0000 (+0000) Subject: Add Apple Event handlers for 'aevt'/'oapp', 'aevt'/'odoc' and 'aevt'/'pdoc'. X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/commitdiff_plain/d70e3b83f17cd28a8cc183bd77501d3726c7211d Add Apple Event handlers for 'aevt'/'oapp', 'aevt'/'odoc' and 'aevt'/'pdoc'. None of them does anything useful yet (though the odoc one tries to). git-svn-id: svn://svn.tartarus.org/sgt/putty@2700 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/mac/mac.c b/mac/mac.c index d7ac91fd..3ae34aa1 100644 --- a/mac/mac.c +++ b/mac/mac.c @@ -1,4 +1,4 @@ -/* $Id: mac.c,v 1.34 2003/01/20 22:55:08 ben Exp $ */ +/* $Id: mac.c,v 1.35 2003/01/23 22:57:43 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -90,7 +90,6 @@ static void mac_adjustmenus(void); static void mac_closewindow(WindowPtr); static void mac_zoomwindow(WindowPtr, short); #pragma noreturn (cleanup_exit) -static pascal OSErr mac_aevt_quit(const AppleEvent *, AppleEvent *, long); struct mac_windows { WindowPtr about; @@ -231,6 +230,12 @@ static void mac_startup(void) { } /* 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); } @@ -651,9 +656,15 @@ static void mac_adjustcursor(RgnHandle cursrgn) { } } -static pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply, +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; diff --git a/mac/mac.h b/mac/mac.h index 591919dd..42d54c61 100644 --- a/mac/mac.h +++ b/mac/mac.h @@ -144,6 +144,11 @@ extern Socket ot_register(void *, Plug); extern Socket ot_new(SockAddr addr, int, int, int, int, Plug); extern Socket ot_newlistener(char *, int, Plug, int); extern char *ot_addr_error(SockAddr); +/* Apple Event Handlers (in various files) */ +extern pascal OSErr mac_aevt_oapp(const AppleEvent *, AppleEvent *, long); +extern pascal OSErr mac_aevt_odoc(const AppleEvent *, AppleEvent *, long); +extern pascal OSErr mac_aevt_pdoc(const AppleEvent *, AppleEvent *, long); +extern pascal OSErr mac_aevt_quit(const AppleEvent *, AppleEvent *, long); #endif diff --git a/mac/macdlg.c b/mac/macdlg.c index 95f634ed..53ba24c0 100644 --- a/mac/macdlg.c +++ b/mac/macdlg.c @@ -1,4 +1,4 @@ -/* $Id: macdlg.c,v 1.5 2003/01/18 20:52:59 ben Exp $ */ +/* $Id: macdlg.c,v 1.6 2003/01/23 22:57:43 ben Exp $ */ /* * Copyright (c) 2002 Ben Harris * All rights reserved. @@ -30,6 +30,8 @@ */ #include +#include +#include #include #include #include @@ -60,30 +62,35 @@ void mac_newsession(void) ShowWindow(s->settings_window); } -void mac_opensession(void) { +static OSErr mac_opensessionfrom(FSSpec *fss) +{ + FInfo fi; Session *s; - StandardFileReply sfr; - static const OSType sftypes[] = { 'Sess', 0, 0, 0 }; void *sesshandle; int i; + OSErr err; s = smalloc(sizeof(*s)); memset(s, 0, sizeof(*s)); - StandardGetFile(NULL, 1, sftypes, &sfr); - if (!sfr.sfGood) goto fail; - - sesshandle = open_settings_r_fsp(&sfr.sfFile); - if (sesshandle == NULL) goto fail; - load_open_settings(sesshandle, TRUE, &s->cfg); - close_settings_r(sesshandle); - if (sfr.sfFlags & kIsStationery) + err = FSpGetFInfo(fss, &fi); + if (err != noErr) return err; + if (fi.fdFlags & kIsStationery) s->hasfile = FALSE; else { s->hasfile = TRUE; - s->savefile = sfr.sfFile; + s->savefile = *fss; } + sesshandle = open_settings_r_fsp(fss); + if (sesshandle == NULL) { + /* XXX need a way to pass up an error number */ + err = -9999; + goto fail; + } + 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. @@ -98,11 +105,22 @@ void mac_opensession(void) { fatalbox("Unsupported protocol number found"); } mac_startsession(s); - return; + return noErr; fail: sfree(s); - return; + return err; +} + +void mac_opensession(void) { + StandardFileReply sfr; + static const OSType sftypes[] = { 'Sess', 0, 0, 0 }; + + StandardGetFile(NULL, 1, sftypes, &sfr); + if (!sfr.sfGood) return; + + mac_opensessionfrom(&sfr.sfFile); + /* XXX handle error */ } void mac_savesession(void) @@ -139,6 +157,70 @@ void mac_savesessionas(void) s->savefile = sfr.sfFile; } +pascal OSErr mac_aevt_oapp(const AppleEvent *req, AppleEvent *reply, + long refcon) +{ + DescType type; + Size size; + + if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, + &type, NULL, 0, &size) == noErr) + return errAEParamMissed; + + /* XXX we should do something here. */ + return noErr; +} + +pascal OSErr mac_aevt_odoc(const AppleEvent *req, AppleEvent *reply, + long refcon) +{ + DescType type; + AEKeyword keywd; + Size size; + AEDescList docs = { typeNull, NULL }; + OSErr err; + long ndocs, i; + FSSpec fss; + + err = AEGetParamDesc(req, keyDirectObject, typeAEList, &docs); + if (err != noErr) goto out; + + if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, + &type, NULL, 0, &size) == noErr) { + err = errAEParamMissed; + goto out; + } + + err = AECountItems(&docs, &ndocs); + if (err != noErr) goto out; + + for (i = 0; i < ndocs; i++) { + err = AEGetNthPtr(&docs, i, typeFSS, &keywd, &type, &fss, sizeof(fss), + &size); + if (err != noErr) goto out; + err = mac_opensessionfrom(&fss); + if (err != noErr) goto out; + } + + out: + AEDisposeDesc(&docs); + return err; +} + +pascal OSErr mac_aevt_pdoc(const AppleEvent *req, AppleEvent *reply, + long refcon) +{ + DescType type; + Size size; + + if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, + &type, NULL, 0, &size) == noErr) + return errAEParamMissed; + + /* We can't meaningfully do anything here. */ + return errAEEventNotHandled; +} + void mac_activatedlg(WindowPtr window, EventRecord *event) { DialogItemType itemtype;