diff options
Diffstat (limited to 'macosx/tkMacOSXHLEvents.c')
-rw-r--r-- | macosx/tkMacOSXHLEvents.c | 111 |
1 files changed, 68 insertions, 43 deletions
diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c index 66714ee..6157d48 100644 --- a/macosx/tkMacOSXHLEvents.c +++ b/macosx/tkMacOSXHLEvents.c @@ -5,13 +5,13 @@ * only event that really does anything is the Quit event. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. - * Copyright 2001, Apple Computer, Inc. + * Copyright 2001-2009, Apple Inc. * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> * - * See the file "license.terms" for information on usage and redistribution of - * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.15.2.3 2009/08/24 00:59:09 das Exp $ + * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.22 2009/08/24 00:56:00 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -33,22 +33,38 @@ typedef struct KillEvent { */ static OSErr QuitHandler(const AppleEvent *event, - AppleEvent *reply, long handlerRefcon); + AppleEvent *reply, SRefCon handlerRefcon); static OSErr OappHandler(const AppleEvent *event, - AppleEvent *reply, long handlerRefcon); + AppleEvent *reply, SRefCon handlerRefcon); static OSErr RappHandler(const AppleEvent *event, - AppleEvent *reply, long handlerRefcon); + AppleEvent *reply, SRefCon handlerRefcon); static OSErr OdocHandler(const AppleEvent *event, - AppleEvent *reply, long handlerRefcon); + AppleEvent *reply, SRefCon handlerRefcon); static OSErr PrintHandler(const AppleEvent *event, - AppleEvent *reply, long handlerRefcon); + AppleEvent *reply, SRefCon handlerRefcon); static OSErr ScriptHandler(const AppleEvent *event, - AppleEvent *reply, long handlerRefcon); + AppleEvent *reply, SRefCon handlerRefcon); static OSErr PrefsHandler(const AppleEvent *event, - AppleEvent *reply, long handlerRefcon); + AppleEvent *reply, SRefCon handlerRefcon); static int MissedAnyParameters(const AppleEvent *theEvent); static int ReallyKillMe(Tcl_Event *eventPtr, int flags); static OSStatus FSRefToDString(const FSRef *fsref, Tcl_DString *ds); + +#pragma mark TKApplication(TKHLEvents) + +@implementation TKApplication(TKHLEvents) +- (void) terminate: (id) sender +{ + QuitHandler(NULL, NULL, (SRefCon) _eventInterp); +} + +- (void) preferences: (id) sender +{ + PrefsHandler(NULL, NULL, (SRefCon) _eventInterp); +} +@end + +#pragma mark - /* *---------------------------------------------------------------------- @@ -85,32 +101,32 @@ TkMacOSXInitAppleEvents( QuitHandlerUPP = NewAEEventHandlerUPP(QuitHandler); ChkErr(AEInstallEventHandler, kCoreEventClass, kAEQuitApplication, - QuitHandlerUPP, (long) interp, false); + QuitHandlerUPP, (SRefCon) interp, false); OappHandlerUPP = NewAEEventHandlerUPP(OappHandler); ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenApplication, - OappHandlerUPP, (long) interp, false); + OappHandlerUPP, (SRefCon) interp, false); RappHandlerUPP = NewAEEventHandlerUPP(RappHandler); ChkErr(AEInstallEventHandler, kCoreEventClass, kAEReopenApplication, - RappHandlerUPP, (long) interp, false); + RappHandlerUPP, (SRefCon) interp, false); OdocHandlerUPP = NewAEEventHandlerUPP(OdocHandler); ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenDocuments, - OdocHandlerUPP, (long) interp, false); + OdocHandlerUPP, (SRefCon) interp, false); PrintHandlerUPP = NewAEEventHandlerUPP(PrintHandler); ChkErr(AEInstallEventHandler, kCoreEventClass, kAEPrintDocuments, - PrintHandlerUPP, (long) interp, false); + PrintHandlerUPP, (SRefCon) interp, false); PrefsHandlerUPP = NewAEEventHandlerUPP(PrefsHandler); ChkErr(AEInstallEventHandler, kCoreEventClass, kAEShowPreferences, - PrefsHandlerUPP, (long) interp, false); + PrefsHandlerUPP, (SRefCon) interp, false); if (interp) { ScriptHandlerUPP = NewAEEventHandlerUPP(ScriptHandler); ChkErr(AEInstallEventHandler, kAEMiscStandards, kAEDoScript, - ScriptHandlerUPP, (long) interp, false); + ScriptHandlerUPP, (SRefCon) interp, false); } } } @@ -133,9 +149,9 @@ TkMacOSXInitAppleEvents( int TkMacOSXDoHLEvent( - EventRecord *theEvent) + void *theEvent) { - return AEProcessAppleEvent(theEvent); + return AEProcessAppleEvent((EventRecord *)theEvent); } /* @@ -158,7 +174,7 @@ static OSErr QuitHandler( const AppleEvent *event, AppleEvent *reply, - long handlerRefcon) + SRefCon handlerRefcon) { Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; KillEvent *eventPtr; @@ -201,15 +217,16 @@ static OSErr OappHandler( const AppleEvent *event, AppleEvent *reply, - long handlerRefcon) + SRefCon handlerRefcon) { Tcl_CmdInfo dummy; Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; if (interp && Tcl_GetCommandInfo(interp, "::tk::mac::OpenApplication", &dummy)){ - if (Tcl_GlobalEval(interp, "::tk::mac::OpenApplication") != TCL_OK) { - Tcl_BackgroundError(interp); + int code = Tcl_GlobalEval(interp, "::tk::mac::OpenApplication"); + if (code != TCL_OK) { + Tcl_BackgroundException(interp, code); } } return noErr; @@ -235,7 +252,7 @@ static OSErr RappHandler( const AppleEvent *event, AppleEvent *reply, - long handlerRefcon) + SRefCon handlerRefcon) { Tcl_CmdInfo dummy; Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; @@ -244,8 +261,9 @@ RappHandler( if (interp && Tcl_GetCommandInfo(interp, "::tk::mac::ReopenApplication", &dummy)) { - if (Tcl_GlobalEval(interp, "::tk::mac::ReopenApplication") != TCL_OK){ - Tcl_BackgroundError(interp); + int code = Tcl_GlobalEval(interp, "::tk::mac::ReopenApplication"); + if (code != TCL_OK){ + Tcl_BackgroundException(interp, code); } } return err; @@ -272,15 +290,16 @@ static OSErr PrefsHandler( const AppleEvent *event, AppleEvent *reply, - long handlerRefcon) + SRefCon handlerRefcon) { Tcl_CmdInfo dummy; Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; if (interp && Tcl_GetCommandInfo(interp, "::tk::mac::ShowPreferences", &dummy)){ - if (Tcl_GlobalEval(interp, "::tk::mac::ShowPreferences") != TCL_OK) { - Tcl_BackgroundError(interp); + int code = Tcl_GlobalEval(interp, "::tk::mac::ShowPreferences"); + if (code != TCL_OK) { + Tcl_BackgroundException(interp, code); } } return noErr; @@ -306,7 +325,7 @@ static OSErr OdocHandler( const AppleEvent *event, AppleEvent *reply, - long handlerRefcon) + SRefCon handlerRefcon) { Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; AEDescList fileSpecList; @@ -317,6 +336,7 @@ OdocHandler( AEKeyword keyword; Tcl_DString command, pathName; Tcl_CmdInfo dummy; + int code; /* * Don't bother if we don't have an interp or the open document procedure @@ -367,9 +387,10 @@ OdocHandler( * Now handle the event by evaluating a script. */ - if (Tcl_EvalEx(interp, Tcl_DStringValue(&command), - Tcl_DStringLength(&command), TCL_EVAL_GLOBAL) != TCL_OK) { - Tcl_BackgroundError(interp); + code = Tcl_EvalEx(interp, Tcl_DStringValue(&command), + Tcl_DStringLength(&command), TCL_EVAL_GLOBAL); + if (code != TCL_OK) { + Tcl_BackgroundException(interp, code); } Tcl_DStringFree(&command); return noErr; @@ -395,7 +416,7 @@ static OSErr PrintHandler( const AppleEvent * event, AppleEvent * reply, - long handlerRefcon) + SRefCon handlerRefcon) { Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; AEDescList fileSpecList; @@ -406,6 +427,7 @@ PrintHandler( AEKeyword keyword; Tcl_DString command, pathName; Tcl_CmdInfo dummy; + int code; /* * Don't bother if we don't have an interp or the print document procedure @@ -451,9 +473,10 @@ PrintHandler( * Now handle the event by evaluating a script. */ - if (Tcl_EvalEx(interp, Tcl_DStringValue(&command), - Tcl_DStringLength(&command), TCL_EVAL_GLOBAL) != TCL_OK) { - Tcl_BackgroundError(interp); + code = Tcl_EvalEx(interp, Tcl_DStringValue(&command), + Tcl_DStringLength(&command), TCL_EVAL_GLOBAL); + if (code != TCL_OK) { + Tcl_BackgroundException(interp, code); } Tcl_DStringFree(&command); return noErr; @@ -479,7 +502,7 @@ static OSErr ScriptHandler( const AppleEvent *event, AppleEvent *reply, - long handlerRefcon) + SRefCon handlerRefcon) { OSStatus theErr; AEDescList theDesc; @@ -604,13 +627,14 @@ ReallyKillMe( Tcl_Interp *interp = ((KillEvent *) eventPtr)->interp; Tcl_CmdInfo dummy; int quit = Tcl_GetCommandInfo(interp, "::tk::mac::Quit", &dummy); + int code = Tcl_GlobalEval(interp, quit ? "::tk::mac::Quit" : "exit"); - if (Tcl_GlobalEval(interp, quit ? "::tk::mac::Quit" : "exit") != TCL_OK) { + if (code != TCL_OK) { /* * Should be never reached... */ - Tcl_BackgroundError(interp); + Tcl_BackgroundException(interp, code); } return 1; } @@ -678,8 +702,9 @@ FSRefToDString( /* * Local Variables: - * mode: c + * mode: objc * c-basic-offset: 4 - * fill-column: 78 + * fill-column: 79 + * coding: utf-8 * End: */ |