diff options
author | Kevin Walzer <kw@codebykevin.com> | 2012-09-25 14:51:04 (GMT) |
---|---|---|
committer | Kevin Walzer <kw@codebykevin.com> | 2012-09-25 14:51:04 (GMT) |
commit | 59e0055e5372987ed7f16557ff3eeb6f75512b98 (patch) | |
tree | dea6f020e98cf06efcef68e084c7a1787f87e140 /macosx/tkMacOSXHLEvents.c | |
parent | dbec27a4c7733b44e33ba898fef7e8636e86caa0 (diff) | |
parent | 1ccc0a498dc186888117726c326b68dde101af48 (diff) | |
download | tk-59e0055e5372987ed7f16557ff3eeb6f75512b98.zip tk-59e0055e5372987ed7f16557ff3eeb6f75512b98.tar.gz tk-59e0055e5372987ed7f16557ff3eeb6f75512b98.tar.bz2 |
Merge Tk-Cocoa backport into core-8-5-branch
Diffstat (limited to 'macosx/tkMacOSXHLEvents.c')
-rw-r--r-- | macosx/tkMacOSXHLEvents.c | 97 |
1 files changed, 62 insertions, 35 deletions
diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c index 14ce7d9..a886408 100644 --- a/macosx/tkMacOSXHLEvents.c +++ b/macosx/tkMacOSXHLEvents.c @@ -5,11 +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$ */ #include "tkMacOSXPrivate.h" @@ -31,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 - /* *---------------------------------------------------------------------- @@ -83,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); } } } @@ -131,9 +149,9 @@ TkMacOSXInitAppleEvents( int TkMacOSXDoHLEvent( - EventRecord *theEvent) + void *theEvent) { - return AEProcessAppleEvent(theEvent); + return AEProcessAppleEvent((EventRecord *)theEvent); } /* @@ -156,7 +174,7 @@ static OSErr QuitHandler( const AppleEvent *event, AppleEvent *reply, - long handlerRefcon) + SRefCon handlerRefcon) { Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; KillEvent *eventPtr; @@ -199,14 +217,15 @@ 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) { + int code = Tcl_GlobalEval(interp, "::tk::mac::OpenApplication"); + if (code != TCL_OK) { Tcl_BackgroundError(interp); } } @@ -233,7 +252,7 @@ static OSErr RappHandler( const AppleEvent *event, AppleEvent *reply, - long handlerRefcon) + SRefCon handlerRefcon) { Tcl_CmdInfo dummy; Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; @@ -242,7 +261,8 @@ RappHandler( if (interp && Tcl_GetCommandInfo(interp, "::tk::mac::ReopenApplication", &dummy)) { - if (Tcl_GlobalEval(interp, "::tk::mac::ReopenApplication") != TCL_OK){ + int code = Tcl_GlobalEval(interp, "::tk::mac::ReopenApplication"); + if (code != TCL_OK){ Tcl_BackgroundError(interp); } } @@ -270,14 +290,15 @@ 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) { + int code = Tcl_GlobalEval(interp, "::tk::mac::ShowPreferences"); + if (code != TCL_OK) { Tcl_BackgroundError(interp); } } @@ -304,7 +325,7 @@ static OSErr OdocHandler( const AppleEvent *event, AppleEvent *reply, - long handlerRefcon) + SRefCon handlerRefcon) { Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; AEDescList fileSpecList; @@ -315,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 @@ -365,8 +387,9 @@ OdocHandler( * Now handle the event by evaluating a script. */ - if (Tcl_EvalEx(interp, Tcl_DStringValue(&command), - Tcl_DStringLength(&command), TCL_EVAL_GLOBAL) != TCL_OK) { + code = Tcl_EvalEx(interp, Tcl_DStringValue(&command), + Tcl_DStringLength(&command), TCL_EVAL_GLOBAL); + if (code != TCL_OK) { Tcl_BackgroundError(interp); } Tcl_DStringFree(&command); @@ -393,7 +416,7 @@ static OSErr PrintHandler( const AppleEvent * event, AppleEvent * reply, - long handlerRefcon) + SRefCon handlerRefcon) { Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; AEDescList fileSpecList; @@ -404,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 @@ -449,8 +473,9 @@ PrintHandler( * Now handle the event by evaluating a script. */ - if (Tcl_EvalEx(interp, Tcl_DStringValue(&command), - Tcl_DStringLength(&command), TCL_EVAL_GLOBAL) != TCL_OK) { + code = Tcl_EvalEx(interp, Tcl_DStringValue(&command), + Tcl_DStringLength(&command), TCL_EVAL_GLOBAL); + if (code != TCL_OK) { Tcl_BackgroundError(interp); } Tcl_DStringFree(&command); @@ -477,7 +502,7 @@ static OSErr ScriptHandler( const AppleEvent *event, AppleEvent *reply, - long handlerRefcon) + SRefCon handlerRefcon) { OSStatus theErr; AEDescList theDesc; @@ -602,8 +627,9 @@ 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... */ @@ -678,6 +704,7 @@ FSRefToDString( * Local Variables: * mode: c * c-basic-offset: 4 - * fill-column: 78 + * fill-column: 79 + * coding: utf-8 * End: */ |