summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXHLEvents.c
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2019-09-02 13:19:20 (GMT)
committerKevin Walzer <kw@codebykevin.com>2019-09-02 13:19:20 (GMT)
commitb81ebcc5809b069440ecdced2f9ac3d14e1e017e (patch)
tree3463bb43cb8528d3ab70558924af6c5b0b5552ce /macosx/tkMacOSXHLEvents.c
parentf2567bf666b8bd0210e2b7491e10838ae0278bfd (diff)
parent2413f540b4709f4ffade95c9ed42ac90ceced283 (diff)
downloadtk-b81ebcc5809b069440ecdced2f9ac3d14e1e017e.zip
tk-b81ebcc5809b069440ecdced2f9ac3d14e1e017e.tar.gz
tk-b81ebcc5809b069440ecdced2f9ac3d14e1e017e.tar.bz2
Merge in ae_cleanup branch; thanks to Marc Culler for patches to clean up Apple Event processing on app startup
Diffstat (limited to 'macosx/tkMacOSXHLEvents.c')
-rw-r--r--macosx/tkMacOSXHLEvents.c498
1 files changed, 245 insertions, 253 deletions
diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c
index 147101e..f223f92 100644
--- a/macosx/tkMacOSXHLEvents.c
+++ b/macosx/tkMacOSXHLEvents.c
@@ -1,13 +1,13 @@
/*
* tkMacOSXHLEvents.c --
*
- * Implements high level event support for the Macintosh. Currently, the
- * only event that really does anything is the Quit event.
+ * Implements high level event support for the Macintosh.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
- * Copyright 2001-2009, Apple Inc.
+ * Copyright (c) 2001-2009, Apple Inc.
* Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net>
- * Copyright (c) 2015 Marc Culler
+ * Copyright (c) 2015-2019 Marc Culler
+ * Copyright (c) 2019 Kevin Walzer/WordTech Communications LLC.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
@@ -30,16 +30,34 @@ typedef struct KillEvent {
} KillEvent;
/*
+ * When processing an AppleEvent as an idle task, a pointer to one
+ * of these structs is passed as the clientData.
+ */
+
+typedef struct AppleEventInfo {
+ Tcl_Interp *interp;
+ const char *procedure;
+ Tcl_DString command;
+ NSAppleEventDescriptor *replyEvent; /* Only used for DoScriptText. */
+} AppleEventInfo;
+
+/*
* Static functions used only in this file.
*/
-static void tkMacOSXProcessFiles(NSAppleEventDescriptor *event,
- NSAppleEventDescriptor *replyEvent,
- Tcl_Interp *interp, const char* procedure);
-static int MissedAnyParameters(const AppleEvent *theEvent);
-static int ReallyKillMe(Tcl_Event *eventPtr, int flags);
-static void RunSimpleTclCommand(Tcl_Interp *interp,
- const char *command);
+static int MissedAnyParameters(const AppleEvent *theEvent);
+static int ReallyKillMe(Tcl_Event *eventPtr, int flags);
+static void ProcessAppleEvent(ClientData clientData);
+
+/*
+ * Names of the procedures which can be used to process AppleEvents.
+ */
+
+static char* openDocumentProc = "::tk::mac::OpenDocument";
+static char* launchURLProc = "::tk::mac::LaunchURL";
+static char* printDocProc = "::tk::mac::PrintDocument";
+static char* scriptFileProc = "::tk::mac::DoScriptFile";
+static char* scriptTextProc = "::tk::mac::DoScriptText";
#pragma mark TKApplication(TKHLEvents)
@@ -79,60 +97,154 @@ static void RunSimpleTclCommand(Tcl_Interp *interp,
- (void) handleOpenApplicationEvent: (NSAppleEventDescriptor *)event
withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
- RunSimpleTclCommand(_eventInterp, "::tk::mac::OpenApplication");
+ if (_eventInterp &&
+ Tcl_FindCommand(_eventInterp, "::tk::mac::OpenApplication", NULL, 0)){
+ int code = Tcl_EvalEx(_eventInterp, "::tk::mac::OpenApplication",
+ -1, TCL_EVAL_GLOBAL);
+ if (code != TCL_OK) {
+ Tcl_BackgroundException(_eventInterp, code);
+ }
+ }
}
- (void) handleReopenApplicationEvent: (NSAppleEventDescriptor *)event
withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
[NSApp activateIgnoringOtherApps: YES];
- RunSimpleTclCommand(_eventInterp, "::tk::mac::ReopenApplication");
+ if (_eventInterp && Tcl_FindCommand(_eventInterp,
+ "::tk::mac::ReopenApplication", NULL, 0)) {
+ int code = Tcl_EvalEx(_eventInterp, "::tk::mac::ReopenApplication",
+ -1, TCL_EVAL_GLOBAL);
+ if (code != TCL_OK){
+ Tcl_BackgroundException(_eventInterp, code);
+ }
+ }
}
- (void) handleShowPreferencesEvent: (NSAppleEventDescriptor *)event
withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
- RunSimpleTclCommand(_eventInterp, "::tk::mac::ShowPreferences");
+ if (_eventInterp &&
+ Tcl_FindCommand(_eventInterp, "::tk::mac::ShowPreferences", NULL, 0)){
+ int code = Tcl_EvalEx(_eventInterp, "::tk::mac::ShowPreferences",
+ -1, TCL_EVAL_GLOBAL);
+ if (code != TCL_OK) {
+ Tcl_BackgroundException(_eventInterp, code);
+ }
+ }
}
- (void) handleOpenDocumentsEvent: (NSAppleEventDescriptor *)event
withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
- tkMacOSXProcessFiles(event, replyEvent, _eventInterp,
- "::tk::mac::OpenDocument");
+ Tcl_Encoding utf8;
+ const AEDesc *fileSpecDesc = nil;
+ AEDesc contents;
+ char URLString[1 + URL_MAX_LENGTH];
+ NSURL *fileURL;
+ DescType type;
+ Size actual;
+ long count, index;
+ AEKeyword keyword;
+ Tcl_DString pathName;
+ int code;
+
+ /*
+ * Do nothing if we don't have an interpreter.
+ */
+
+ if (!_eventInterp) {
+ return;
+ }
+
+ fileSpecDesc = [event aeDesc];
+ if (fileSpecDesc == nil ) {
+ return;
+ }
+
+ /*
+ * The AppleEvent's descriptor should either contain a value of
+ * typeObjectSpecifier or typeAEList. In the first case, the descriptor
+ * can be treated as a list of size 1 containing a value which can be
+ * coerced into a fileURL. In the second case we want to work with the list
+ * itself. Values in the list will be coerced into fileURL's if possible;
+ * otherwise they will be ignored.
+ */
+
+ /* Get a copy of the AppleEvent's descriptor. */
+ AEGetParamDesc(fileSpecDesc, keyDirectObject, typeWildCard, &contents);
+ if (contents.descriptorType == typeAEList) {
+ fileSpecDesc = &contents;
+ }
+
+ if (AECountItems(fileSpecDesc, &count) != noErr) {
+ AEDisposeDesc(&contents);
+ return;
+ }
+
+ /*
+ * Construct a Tcl expression which calls the ::tk::mac::OpenDocument
+ * procedure, passing the paths contained in the AppleEvent as arguments.
+ */
+
+ AppleEventInfo *AEInfo = ckalloc(sizeof(AppleEventInfo));
+ Tcl_DString *openCommand = &AEInfo->command;
+ Tcl_DStringInit(openCommand);
+ Tcl_DStringAppend(openCommand, openDocumentProc, -1);
+ utf8 = Tcl_GetEncoding(NULL, "utf-8");
+
+ for (index = 1; index <= count; index++) {
+ if (noErr != AEGetNthPtr(fileSpecDesc, index, typeFileURL, &keyword,
+ &type, (Ptr) URLString, URL_MAX_LENGTH, &actual)) {
+ continue;
+ }
+ if (type != typeFileURL) {
+ continue;
+ }
+ URLString[actual] = '\0';
+ fileURL = [NSURL URLWithString:[NSString stringWithUTF8String:(char*)URLString]];
+ if (fileURL == nil) {
+ continue;
+ }
+ Tcl_ExternalToUtfDString(utf8, [[fileURL path] UTF8String], -1, &pathName);
+ Tcl_DStringAppendElement(openCommand, Tcl_DStringValue(&pathName));
+ Tcl_DStringFree(&pathName);
+ }
+
+ Tcl_FreeEncoding(utf8);
+ AEDisposeDesc(&contents);
+ AEInfo->interp = _eventInterp;
+ AEInfo->procedure = openDocumentProc;
+ AEInfo->replyEvent = nil;
+ Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo);
}
- (void) handlePrintDocumentsEvent: (NSAppleEventDescriptor *)event
- withReplyEvent: (NSAppleEventDescriptor *)replyEvent
+ withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
NSString* file = [[event paramDescriptorForKeyword:keyDirectObject]
stringValue];
const char *printFile = [file UTF8String];
- Tcl_DString print;
-
- Tcl_DStringInit(&print);
- if (Tcl_FindCommand(_eventInterp, "::tk::mac::PrintDocument", NULL, 0)) {
- Tcl_DStringAppend(&print, "::tk::mac::PrintDocument", -1);
- }
- Tcl_DStringAppendElement(&print, printFile);
- int tclErr = Tcl_EvalEx(_eventInterp, Tcl_DStringValue(&print),
- Tcl_DStringLength(&print), TCL_EVAL_GLOBAL);
- if (tclErr != TCL_OK) {
- Tcl_BackgroundException(_eventInterp, tclErr);
- }
+ AppleEventInfo *AEInfo = ckalloc(sizeof(AppleEventInfo));
+ Tcl_DString *printCommand = &AEInfo->command;
+ Tcl_DStringInit(printCommand);
+ Tcl_DStringAppend(printCommand, printDocProc, -1);
+ Tcl_DStringAppendElement(printCommand, printFile);
+ AEInfo->interp = _eventInterp;
+ AEInfo->procedure = printDocProc;
+ AEInfo->replyEvent = nil;
+ Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo);
}
- (void) handleDoScriptEvent: (NSAppleEventDescriptor *)event
- withReplyEvent: (NSAppleEventDescriptor *)replyEvent
+ withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
OSStatus err;
const AEDesc *theDesc = nil;
DescType type = 0, initialType = 0;
Size actual;
- int tclErr = -1;
char URLBuffer[1 + URL_MAX_LENGTH];
char errString[128];
- char typeString[5];
/*
* The DoScript event receives one parameter that should be text data or a
@@ -145,267 +257,153 @@ static void RunSimpleTclCommand(Tcl_Interp *interp,
}
err = AEGetParamPtr(theDesc, keyDirectObject, typeWildCard, &initialType,
- NULL, 0, NULL);
+ NULL, 0, NULL);
if (err != noErr) {
sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d", (int)err);
- AEPutParamPtr((AppleEvent *) [replyEvent aeDesc], keyErrorString,
- typeChar, errString, strlen(errString));
+ AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString,
+ typeChar, errString, strlen(errString));
return;
}
- if (MissedAnyParameters((AppleEvent *) theDesc)) {
+ if (MissedAnyParameters((AppleEvent*)theDesc)) {
sprintf(errString, "AEDoScriptHandler: extra parameters");
- AEPutParamPtr((AppleEvent *) [replyEvent aeDesc], keyErrorString,
- typeChar, errString, strlen(errString));
+ AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString,
+ typeChar,errString, strlen(errString));
return;
}
- Tcl_Preserve(_eventInterp);
if (initialType == typeFileURL || initialType == typeAlias) {
+
/*
- * The descriptor can be coerced to a file url. Source the file, or
- * pass the path as a string argument to ::tk::mac::DoScriptFile if
- * that procedure exists.
+ * This descriptor can be coerced to a file url. Construct a Tcl
+ * expression which passes the file path as a string argument to
+ * ::tk::mac::DoScriptFile.
*/
- err = AEGetParamPtr(theDesc, keyDirectObject, typeFileURL, &type,
- (Ptr) URLBuffer, URL_MAX_LENGTH, &actual);
- if (err == noErr && actual > 0){
- URLBuffer[actual] = '\0';
- NSString *urlString = [NSString stringWithUTF8String:(char*)URLBuffer];
- NSURL *fileURL = [NSURL URLWithString:urlString];
- Tcl_DString command;
-
- Tcl_DStringInit(&command);
- if (Tcl_FindCommand(_eventInterp, "::tk::mac::DoScriptFile", NULL, 0)) {
- Tcl_DStringAppend(&command, "::tk::mac::DoScriptFile", -1);
- } else {
- Tcl_DStringAppend(&command, "source", -1);
- }
- Tcl_DStringAppendElement(&command, [[fileURL path] UTF8String]);
- tclErr = Tcl_EvalEx(_eventInterp, Tcl_DStringValue(&command),
- Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
- }
- } else if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text,
- &type, NULL, 0, &actual)) {
- if (actual > 0) {
- /*
- * The descriptor can be coerced to UTF8 text. Evaluate as Tcl, or
- * or pass the text as a string argument to ::tk::mac::DoScriptText
- * if that procedure exists.
- */
+ if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeFileURL, &type,
+ (Ptr) URLBuffer, URL_MAX_LENGTH, &actual)) {
+ if (actual > 0) {
+ URLBuffer[actual] = '\0';
+ NSString *urlString = [NSString stringWithUTF8String:(char*)URLBuffer];
+ NSURL *fileURL = [NSURL URLWithString:urlString];
+ AppleEventInfo *AEInfo = ckalloc(sizeof(AppleEventInfo));
+ Tcl_DString *scriptFileCommand = &AEInfo->command;
+ Tcl_DStringInit(scriptFileCommand);
+ Tcl_DStringAppend(scriptFileCommand, scriptFileProc, -1);
+ Tcl_DStringAppendElement(scriptFileCommand, [[fileURL path] UTF8String]);
+ AEInfo->interp = _eventInterp;
+ AEInfo->procedure = scriptFileProc;
+ AEInfo->replyEvent = nil;
+ Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo);
+ }
+ }
+ } else if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text, &type,
+ NULL, 0, &actual)) {
+ /*
+ * The descriptor cannot be coerced to a file URL but can be coerced to
+ * text. Construct a Tcl expression which passes the text as a string
+ * argument to ::tk::mac::DoScriptText.
+ */
+ if (actual > 0) {
char *data = ckalloc(actual + 1);
-
- if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text,
- &type, data, actual, NULL)) {
- if (Tcl_FindCommand(_eventInterp, "::tk::mac::DoScriptText",
- NULL, 0)) {
- Tcl_DString command;
-
- Tcl_DStringInit(&command);
- Tcl_DStringAppend(&command, "::tk::mac::DoScriptText", -1);
- Tcl_DStringAppendElement(&command, data);
- tclErr = Tcl_EvalEx(_eventInterp,
- Tcl_DStringValue(&command),
- Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
- } else {
- tclErr = Tcl_EvalEx(_eventInterp, data, actual,
- TCL_EVAL_GLOBAL);
- }
+ if (noErr == AEGetParamPtr(theDesc, keyDirectObject,
+ typeUTF8Text, &type,
+ data, actual, NULL)) {
+ AppleEventInfo *AEInfo = ckalloc(sizeof(AppleEventInfo));
+ Tcl_DString *scriptTextCommand = &AEInfo->command;
+ Tcl_DStringInit(scriptTextCommand);
+ Tcl_DStringAppend(scriptTextCommand, scriptTextProc, -1);
+ Tcl_DStringAppendElement(scriptTextCommand, data);
+ AEInfo->interp = _eventInterp;
+ AEInfo->procedure = scriptTextProc;
+ if (Tcl_FindCommand(AEInfo->interp, AEInfo->procedure, NULL, 0)) {
+ AEInfo->replyEvent = replyEvent;
+ ProcessAppleEvent((ClientData)AEInfo);
+ } else {
+ AEInfo->replyEvent = nil;
+ Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo);
+ }
}
- ckfree(data);
- }
- } else {
- /*
- * The descriptor can not be coerced to a fileURL or UTF8 text.
- */
- for (int i = 0; i < 4; i++) {
- typeString[i] = ((char*)&initialType)[3-i];
- }
- typeString[4] = '\0';
- sprintf(errString, "AEDoScriptHandler: invalid script type '%s', "
- "must be coercable to 'furl' or 'utf8'", typeString);
- AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString,
- typeChar, errString, strlen(errString));
- }
-
- /*
- * If we ran some Tcl code, put the result in the reply.
- */
-
- if (tclErr >= 0) {
- int reslen;
- const char *result =
- Tcl_GetStringFromObj(Tcl_GetObjResult(_eventInterp), &reslen);
-
- if (tclErr == TCL_OK) {
- AEPutParamPtr((AppleEvent *) [replyEvent aeDesc], keyDirectObject,
- typeChar, result, reslen);
- } else {
- AEPutParamPtr((AppleEvent *) [replyEvent aeDesc], keyErrorString,
- typeChar, result, reslen);
- AEPutParamPtr((AppleEvent *) [replyEvent aeDesc], keyErrorNumber,
- typeSInt32, (Ptr) &tclErr, sizeof(int));
}
}
- Tcl_Release(_eventInterp);
- return;
}
-
+
- (void)handleURLEvent:(NSAppleEventDescriptor*)event
withReplyEvent:(NSAppleEventDescriptor*)replyEvent
{
NSString* url = [[event paramDescriptorForKeyword:keyDirectObject]
stringValue];
- const char *cURL = [url UTF8String];
- Tcl_DString launch;
-
- Tcl_DStringInit(&launch);
- if (Tcl_FindCommand(_eventInterp, "::tk::mac::LaunchURL", NULL, 0)) {
- Tcl_DStringAppend(&launch, "::tk::mac::LaunchURL", -1);
- }
- Tcl_DStringAppendElement(&launch, cURL);
- int tclErr = Tcl_EvalEx(_eventInterp, Tcl_DStringValue(&launch),
- Tcl_DStringLength(&launch), TCL_EVAL_GLOBAL);
- if (tclErr != TCL_OK) {
- Tcl_BackgroundException(_eventInterp, tclErr);
- }
+ const char *cURL=[url UTF8String];
+ AppleEventInfo *AEInfo = ckalloc(sizeof(AppleEventInfo));
+ Tcl_DString *launchCommand = &AEInfo->command;
+ Tcl_DStringInit(launchCommand);
+ Tcl_DStringAppend(launchCommand, launchURLProc, -1);
+ Tcl_DStringAppendElement(launchCommand, cURL);
+ AEInfo->interp = _eventInterp;
+ AEInfo->procedure = launchURLProc;
+ AEInfo->replyEvent = nil;
+ Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo);
}
@end
#pragma mark -
-
-static void
-RunSimpleTclCommand(
- Tcl_Interp *interp,
- const char *command)
-{
- int code;
- if (interp && Tcl_FindCommand(interp, command, NULL, 0)) {
- Tcl_Preserve(interp);
- code = Tcl_EvalEx(interp, command, -1, TCL_EVAL_GLOBAL);
- if (code != TCL_OK) {
- Tcl_BackgroundException(interp, code);
- }
- Tcl_Release(interp);
- }
-}
-
/*
*----------------------------------------------------------------------
*
- * TkMacOSXProcessFiles --
+ * ProcessAppleEvent --
*
- * Extract a list of fileURLs from an AppleEvent and call the specified
- * procedure with the file paths as arguments.
+ * Usually used as an idle task which evaluates a Tcl expression generated
+ * from an AppleEvent. If the AppleEventInfo passed as the client data
+ * has a non-null replyEvent, the result of evaluating the expression will
+ * be added to the reply. This must not be done when this function is
+ * called as an idle task, but is done when handling DoScriptText events
+ * when this function is called directly.
*
* Results:
* None.
*
* Side effects:
- * The event is handled by running the procedure.
+ * The expression will be evaluated and the clientData will be freed.
+ * The replyEvent may be modified to contain the result of evaluating
+ * a Tcl expression.
*
*----------------------------------------------------------------------
*/
-static void
-tkMacOSXProcessFiles(
- NSAppleEventDescriptor* event,
- NSAppleEventDescriptor* replyEvent,
- Tcl_Interp *interp,
- const char* procedure)
+static void ProcessAppleEvent(
+ ClientData clientData)
{
- Tcl_Encoding utf8;
- const AEDesc *fileSpecDesc = nil;
- AEDesc contents;
- char URLString[1 + URL_MAX_LENGTH];
- NSURL *fileURL;
- DescType type;
- Size actual;
- long count, index;
- AEKeyword keyword;
- Tcl_DString command, pathName;
int code;
-
- /*
- * Do nothing if we don't have an interpreter or the procedure doesn't
- * exist.
- */
-
- if (!interp || !Tcl_FindCommand(interp, procedure, NULL, 0)) {
+ AppleEventInfo *AEInfo = (AppleEventInfo*) clientData;
+ if (!AEInfo->interp ||
+ !Tcl_FindCommand(AEInfo->interp, AEInfo->procedure, NULL, 0)) {
return;
}
-
- fileSpecDesc = [event aeDesc];
- if (fileSpecDesc == nil ) {
- return;
- }
-
- /*
- * The AppleEvent's descriptor should either contain a value of
- * typeObjectSpecifier or typeAEList. In the first case, the descriptor
- * can be treated as a list of size 1 containing a value which can be
- * coerced into a fileURL. In the second case we want to work with the list
- * itself. Values in the list will be coerced into fileURL's if possible;
- * otherwise they will be ignored.
- */
-
- /* Get a copy of the AppleEvent's descriptor. */
- AEGetParamDesc(fileSpecDesc, keyDirectObject, typeWildCard, &contents);
- if (contents.descriptorType == typeAEList) {
- fileSpecDesc = &contents;
- }
-
- if (AECountItems(fileSpecDesc, &count) != noErr) {
- AEDisposeDesc(&contents);
- return;
- }
-
- /*
- * Construct a Tcl command which calls the procedure, passing the
- * paths contained in the AppleEvent as arguments.
- */
-
- Tcl_DStringInit(&command);
- Tcl_DStringAppend(&command, procedure, -1);
- utf8 = Tcl_GetEncoding(NULL, "utf-8");
-
- for (index = 1; index <= count; index++) {
- if (noErr != AEGetNthPtr(fileSpecDesc, index, typeFileURL, &keyword,
- &type, (Ptr) URLString, URL_MAX_LENGTH, &actual)) {
- continue;
- }
- if (type != typeFileURL) {
- continue;
- }
- URLString[actual] = '\0';
- fileURL = [NSURL URLWithString:[NSString stringWithUTF8String:(char*)URLString]];
- if (fileURL == nil) {
- continue;
- }
- Tcl_ExternalToUtfDString(utf8, [[fileURL path] UTF8String], -1, &pathName);
- Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
- Tcl_DStringFree(&pathName);
+ code = Tcl_EvalEx(AEInfo->interp, Tcl_DStringValue(&AEInfo->command),
+ Tcl_DStringLength(&AEInfo->command), TCL_EVAL_GLOBAL);
+ if (code != TCL_OK) {
+ Tcl_BackgroundException(AEInfo->interp, code);
}
- Tcl_FreeEncoding(utf8);
- AEDisposeDesc(&contents);
-
- /*
- * Handle the event by evaluating the Tcl expression we constructed.
- */
-
- Tcl_Preserve(interp);
- code = Tcl_EvalEx(interp, Tcl_DStringValue(&command),
- Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
- if (code != TCL_OK) {
- Tcl_BackgroundException(interp, code);
+ if (AEInfo->replyEvent && code >= 0) {
+ int reslen;
+ const char *result = Tcl_GetStringFromObj(Tcl_GetObjResult(AEInfo->interp),
+ &reslen);
+ if (code == TCL_OK) {
+ AEPutParamPtr((AppleEvent*)[AEInfo->replyEvent aeDesc],
+ keyDirectObject, typeChar, result, reslen);
+ } else {
+ AEPutParamPtr((AppleEvent*)[AEInfo->replyEvent aeDesc],
+ keyErrorString, typeChar, result, reslen);
+ AEPutParamPtr((AppleEvent*)[AEInfo->replyEvent aeDesc],
+ keyErrorNumber, typeSInt32, (Ptr) &code, sizeof(int));
+ }
}
- Tcl_DStringFree(&command);
- Tcl_Release(interp);
+ Tcl_DStringFree(&AEInfo->command);
+ ckfree(clientData);
}
/*
@@ -429,8 +427,7 @@ void
TkMacOSXInitAppleEvents(
Tcl_Interp *interp) /* not used */
{
- NSAppleEventManager *aeManager =
- [NSAppleEventManager sharedAppleEventManager];
+ NSAppleEventManager *aeManager = [NSAppleEventManager sharedAppleEventManager];
static Boolean initialized = FALSE;
if (!initialized) {
@@ -541,12 +538,8 @@ ReallyKillMe(
int flags)
{
Tcl_Interp *interp = ((KillEvent *) eventPtr)->interp;
-
- Tcl_Preserve(interp);
-
int quit = Tcl_FindCommand(interp, "::tk::mac::Quit", NULL, 0)!=NULL;
- int code = Tcl_EvalEx(interp, quit ? "::tk::mac::Quit" : "exit", -1,
- TCL_EVAL_GLOBAL);
+ int code = Tcl_EvalEx(interp, quit ? "::tk::mac::Quit" : "exit", -1, TCL_EVAL_GLOBAL);
if (code != TCL_OK) {
/*
@@ -555,7 +548,6 @@ ReallyKillMe(
Tcl_BackgroundException(interp, code);
}
- Tcl_Release(interp);
return 1;
}
@@ -587,8 +579,8 @@ MissedAnyParameters(
typeWildCard, &returnedType, NULL, 0, &actualSize);
return (err != errAEDescNotFound);
-}
-
+}
+
/*
* Local Variables:
* mode: objc