summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--macosx/tkMacOSXHLEvents.c80
2 files changed, 39 insertions, 48 deletions
diff --git a/ChangeLog b/ChangeLog
index bd1fabb..b8df108 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-24 Daniel Steffen <das@users.sourceforge.net>
+
+ * macosx/tkMacOSXHLEvents.c (ScriptHandler): fix "do script" apple
+ event handler issues on recent Mac OS X releases by using AE coercion
+ to 'utf8' for text data and to 'fsrf' for alias data. (reported by
+ Youness Alaoui on tcl-mac)
+
2009-08-08 Donal K. Fellows <dkf@users.sf.net>
* library/demos/pendulum.tcl: Make the display handle being resized
diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c
index 3705d55..66714ee 100644
--- a/macosx/tkMacOSXHLEvents.c
+++ b/macosx/tkMacOSXHLEvents.c
@@ -6,12 +6,12 @@
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright 2001, Apple Computer, Inc.
- * Copyright (c) 2006 Daniel A. Steffen <das@users.sourceforge.net>
+ * 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.
*
- * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.15.2.2 2008/09/02 16:14:18 das Exp $
+ * RCS: @(#) $Id: tkMacOSXHLEvents.c,v 1.15.2.3 2009/08/24 00:59:09 das Exp $
*/
#include "tkMacOSXPrivate.h"
@@ -483,6 +483,7 @@ ScriptHandler(
{
OSStatus theErr;
AEDescList theDesc;
+ Size size;
int tclErr = -1;
Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
char errString[128];
@@ -495,8 +496,8 @@ ScriptHandler(
theErr = AEGetParamDesc(event, keyDirectObject, typeWildCard,
&theDesc);
if (theErr != noErr) {
- sprintf(errString, "AEDoScriptHandler: GetParamDesc error %ld",
- theErr);
+ sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d",
+ (int)theErr);
theErr = AEPutParamPtr(reply, keyErrorString, typeChar, errString,
strlen(errString));
} else if (MissedAnyParameters(event)) {
@@ -508,66 +509,49 @@ ScriptHandler(
AEPutParamPtr(reply, keyErrorString, typeChar, errString,
strlen(errString));
theErr = -1771;
- } else if (theDesc.descriptorType == (DescType) typeChar) {
- /*
- * We've had some data sent to us. Evaluate it.
- */
-
- Tcl_DString encodedText;
- short i;
- Size size = AEGetDescDataSize(&theDesc);
- char *data = ckalloc(size + 1);
-
- AEGetDescData(&theDesc, data, size);
- data[size] = 0;
- for (i = 0; i < size; i++) {
- if (data[i] == '\r') {
- data[i] = '\n';
- }
- }
- AEReplaceDescData(theDesc.descriptorType, data, size + 1, &theDesc);
- Tcl_ExternalToUtfDString(NULL, data, size, &encodedText);
- tclErr = Tcl_EvalEx(interp, Tcl_DStringValue(&encodedText),
- Tcl_DStringLength(&encodedText), TCL_EVAL_GLOBAL);
- Tcl_DStringFree(&encodedText);
- } else if (theDesc.descriptorType == (DescType) typeAlias) {
+ } else if (theDesc.descriptorType == (DescType) typeAlias &&
+ AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, NULL,
+ 0, &size) == noErr && size == sizeof(FSRef)) {
/*
* We've had a file sent to us. Source it.
*/
- Boolean dummy;
FSRef file;
- Size theSize = AEGetDescDataSize(&theDesc);
- AliasPtr alias = (AliasPtr) ckalloc(theSize);
-
- if (alias) {
- AEGetDescData(&theDesc, alias, theSize);
-
- theErr = FSResolveAlias(NULL, &alias, &file, &dummy);
- ckfree((char*)alias);
- } else {
- theErr = memFullErr;
- }
+ theErr = AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, &file,
+ size, NULL);
if (theErr == noErr) {
Tcl_DString scriptName;
theErr = FSRefToDString(&file, &scriptName);
if (theErr == noErr) {
- Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName));
+ tclErr = Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName));
Tcl_DStringFree(&scriptName);
+ } else {
+ sprintf(errString, "AEDoScriptHandler: file not found");
+ AEPutParamPtr(reply, keyErrorString, typeChar, errString,
+ strlen(errString));
}
- } else {
- sprintf(errString, "AEDoScriptHandler: file not found");
- AEPutParamPtr(reply, keyErrorString, typeChar, errString,
- strlen(errString));
+ }
+ } else if (AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL, NULL,
+ 0, &size) == noErr && size) {
+ /*
+ * We've had some data sent to us. Evaluate it.
+ */
+
+ char *data = ckalloc(size + 1);
+ theErr = AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL, data,
+ size, NULL);
+ if (theErr == noErr) {
+ tclErr = Tcl_EvalEx(interp, data, size, TCL_EVAL_GLOBAL);
}
} else {
/*
* Umm, don't recognize what we've got...
*/
- sprintf(errString, "AEDoScriptHandler: invalid script type '%-4.4s',"
- " must be 'alis' or 'TEXT'", (char*) &theDesc.descriptorType);
+ sprintf(errString, "AEDoScriptHandler: invalid script type '%-4.4s', "
+ "must be 'alis' or coercable to 'utf8'",
+ (char*) &theDesc.descriptorType);
AEPutParamPtr(reply, keyErrorString, typeChar, errString,
strlen(errString));
theErr = -1770;
@@ -586,7 +570,7 @@ ScriptHandler(
AEPutParamPtr(reply, keyDirectObject, typeChar, result, reslen);
} else {
AEPutParamPtr(reply, keyErrorString, typeChar, result, reslen);
- AEPutParamPtr(reply, keyErrorNumber, typeInteger, (Ptr) &tclErr,
+ AEPutParamPtr(reply, keyErrorNumber, typeSInt32, (Ptr) &tclErr,
sizeof(int));
}
}
@@ -655,7 +639,7 @@ MissedAnyParameters(
Size actualSize;
OSStatus err;
- err = ChkErr(AEGetAttributePtr, theEvent, keyMissedKeywordAttr,
+ err = AEGetAttributePtr(theEvent, keyMissedKeywordAttr,
typeWildCard, &returnedType, NULL, 0, &actualSize);
return (err != errAEDescNotFound);