summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2019-09-01 18:35:14 (GMT)
committerKevin Walzer <kw@codebykevin.com>2019-09-01 18:35:14 (GMT)
commitef44bffe25ebbc5384bbec83e47fd7871140e0de (patch)
tree6da741c5cbbec043d1ca4035782abcb4bdd00070
parentb47684b3d7c8ac79186f4928931bc520ea9fec42 (diff)
downloadtk-ef44bffe25ebbc5384bbec83e47fd7871140e0de.zip
tk-ef44bffe25ebbc5384bbec83e47fd7871140e0de.tar.gz
tk-ef44bffe25ebbc5384bbec83e47fd7871140e0de.tar.bz2
Complete cleanup of Apple Event processing after recent updates to window display on app startup
-rw-r--r--doc/tk_mac.n8
-rw-r--r--library/tk.tcl3
-rw-r--r--macosx/tkMacOSXHLEvents.c83
3 files changed, 46 insertions, 48 deletions
diff --git a/doc/tk_mac.n b/doc/tk_mac.n
index bf9159a..87c43aa 100644
--- a/doc/tk_mac.n
+++ b/doc/tk_mac.n
@@ -48,15 +48,15 @@ the command is absent, no action will be taken.
.TP
\fB::tk::mac::DoScriptFile\fR
.
-The default Apple Event handler for AEDoScriptHandler. This command,
-if defined, executes a Tcl file when an AppleScript sends a
+The default Apple Event handler for AEDoScriptHandler. This command
+executes a Tcl file when an AppleScript sends a
.QW "do script"
command to Wish with a file path as a parameter.
.TP
\fB::tk::mac::DoScriptText\fR
.
-The default Apple Event handler for AEDoScriptHandler. This command,
-if defined, executes Tcl code when an AppleScript sends a
+The default Apple Event handler for AEDoScriptHandler. This command
+executes Tcl code when an AppleScript sends a
.QW "do script"
command to Wish with Tcl code or a Tcl procedure as a parameter.
.TP
diff --git a/library/tk.tcl b/library/tk.tcl
index deaf784..0e48278 100644
--- a/library/tk.tcl
+++ b/library/tk.tcl
@@ -733,6 +733,7 @@ proc tk::mac::LaunchURL {url} {
proc saymyname {} {
- puts "my name is [exec whoami]"
+ # tk_messageBox -message "my name is kevin"
+ exec say "My name is [exec whoami]"
}
diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c
index 72c7d08..7f08b61 100644
--- a/macosx/tkMacOSXHLEvents.c
+++ b/macosx/tkMacOSXHLEvents.c
@@ -260,11 +260,11 @@ static char* scriptTextProc = "::tk::mac::DoScriptText";
}
if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text, &type,
NULL, 0, &actual)) {
+ /*
+ * The descriptor can be coerced to UTF8 text. Evaluate as Tcl, * or pass the text as a string argument to ::tk::mac::DoScriptText
+ * if that procedure exists.
+ */
if (actual > 0) {
- /*
- * The descriptor can be coerced to UTF8 text. Evaluate as Tcl, * or pass the text as a string argument to ::tk::mac::DoScriptText
- * if that procedure exists.
- */
char *data = ckalloc(actual + 1);
if (noErr == AEGetParamPtr(theDesc, keyDirectObject,
@@ -272,52 +272,49 @@ static char* scriptTextProc = "::tk::mac::DoScriptText";
data, actual, NULL)) {
Tcl_DString *textScriptCommand = &staticAEInfo.command;
Tcl_DStringInit(textScriptCommand);
+ Tcl_DStringAppend(textScriptCommand, scriptTextProc, -1);
+ Tcl_DStringAppendElement(textScriptCommand, data);
if (Tcl_FindCommand(_eventInterp, scriptTextProc, NULL, 0)) {
- Tcl_DStringAppend(textScriptCommand, scriptTextProc, -1);
+ tclErr = Tcl_EvalEx(_eventInterp,Tcl_DStringValue(textScriptCommand),Tcl_DStringLength(textScriptCommand), TCL_EVAL_GLOBAL);
+ if (tclErr!= TCL_OK) {
+ Tcl_BackgroundException(_eventInterp, tclErr);
+ }
+ Tcl_DStringFree(textScriptCommand);
+ ckfree(data);
} else {
- Tcl_DStringAppend(textScriptCommand, "eval", -1);
+ /*
+ * The DoScript procedure may not be defined because
+ * the Apple Event is being processed before Tk has
+ * been fully initialized. So try
+ * to run the procedure as an idle task.
+ */
+ staticAEInfo.interp = _eventInterp;
+ staticAEInfo.procedure = scriptTextProc;
+ Tcl_DoWhenIdle(ProcessAppleEventEventually, (ClientData)&staticAEInfo);
}
- NSLog(@"data is %s", data);
- Tcl_DStringAppendElement(textScriptCommand, data);
- int tclErr = Tcl_EvalEx(_eventInterp,Tcl_DStringValue(textScriptCommand),Tcl_DStringLength(textScriptCommand), TCL_EVAL_GLOBAL);
- if (tclErr!= TCL_OK) {
- Tcl_BackgroundException(_eventInterp, tclErr);
- }
- Tcl_DStringFree(textScriptCommand);
- ckfree(data);
- } else {
- /*
- * The DoScript procedure may not be defined because
- * the Apple Event is being processed before Tk has
- * been fully initialized. So try
- * to run the procedure as an idle task.
- */
- staticAEInfo.interp = _eventInterp;
- staticAEInfo.procedure = scriptTextProc;
- Tcl_DoWhenIdle(ProcessAppleEventEventually, (ClientData)&staticAEInfo);
}
- }
- /*
- * 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));
+ /*
+ * 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));
+ }
}
+ return;
}
- return;
}
}