Import Tk 8.6.11

This commit is contained in:
Steve Dower
2021-03-30 00:54:10 +01:00
parent 42c69189d9
commit 070b8750b0
403 changed files with 21608 additions and 16269 deletions

View File

@@ -39,6 +39,7 @@ typedef struct AppleEventInfo {
const char *procedure;
Tcl_DString command;
NSAppleEventDescriptor *replyEvent; /* Only used for DoScriptText. */
int retryCount;
} AppleEventInfo;
/*
@@ -67,6 +68,11 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText";
[self handleQuitApplicationEvent:Nil withReplyEvent:Nil];
}
- (void) superTerminate: (id) sender
{
[super terminate:nil];
}
- (void) preferences: (id) sender
{
[self handleShowPreferencesEvent:Nil withReplyEvent:Nil];
@@ -148,6 +154,7 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText";
AEKeyword keyword;
Tcl_DString pathName;
/*
* Do nothing if we don't have an interpreter.
*/
@@ -215,7 +222,13 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText";
AEInfo->interp = _eventInterp;
AEInfo->procedure = openDocumentProc;
AEInfo->replyEvent = nil;
Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo);
AEInfo->retryCount = 0;
if (Tcl_FindCommand(_eventInterp, "::tk::mac::OpenDocuments", NULL, 0)){
ProcessAppleEvent((ClientData)AEInfo);
} else {
Tcl_CreateTimerHandler(500, ProcessAppleEvent, (ClientData)AEInfo);
}
}
- (void) handlePrintDocumentsEvent: (NSAppleEventDescriptor *)event
@@ -232,7 +245,8 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText";
AEInfo->interp = _eventInterp;
AEInfo->procedure = printDocProc;
AEInfo->replyEvent = nil;
Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo);
AEInfo->retryCount = 0;
ProcessAppleEvent((ClientData)AEInfo);
}
- (void) handleDoScriptEvent: (NSAppleEventDescriptor *)event
@@ -293,7 +307,8 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText";
AEInfo->interp = _eventInterp;
AEInfo->procedure = scriptFileProc;
AEInfo->replyEvent = nil;
Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo);
AEInfo->retryCount = 0;
ProcessAppleEvent((ClientData)AEInfo);
}
}
} else if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text, &type,
@@ -309,6 +324,7 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText";
if (noErr == AEGetParamPtr(theDesc, keyDirectObject,
typeUTF8Text, &type,
data, actual, NULL)) {
data[actual] = '\0';
AppleEventInfo *AEInfo = ckalloc(sizeof(AppleEventInfo));
Tcl_DString *scriptTextCommand = &AEInfo->command;
Tcl_DStringInit(scriptTextCommand);
@@ -316,12 +332,13 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText";
Tcl_DStringAppendElement(scriptTextCommand, data);
AEInfo->interp = _eventInterp;
AEInfo->procedure = scriptTextProc;
AEInfo->retryCount = 0;
if (Tcl_FindCommand(AEInfo->interp, AEInfo->procedure, NULL, 0)) {
AEInfo->replyEvent = replyEvent;
ProcessAppleEvent((ClientData)AEInfo);
} else {
AEInfo->replyEvent = nil;
Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo);
ProcessAppleEvent((ClientData)AEInfo);
}
}
}
@@ -342,7 +359,8 @@ static const char *scriptTextProc = "::tk::mac::DoScriptText";
AEInfo->interp = _eventInterp;
AEInfo->procedure = launchURLProc;
AEInfo->replyEvent = nil;
Tcl_DoWhenIdle(ProcessAppleEvent, (ClientData)AEInfo);
AEInfo->retryCount = 0;
ProcessAppleEvent((ClientData)AEInfo);
}
@end
@@ -377,15 +395,30 @@ static void ProcessAppleEvent(
{
int code;
AppleEventInfo *AEInfo = (AppleEventInfo*) clientData;
if (!AEInfo->interp ||
!Tcl_FindCommand(AEInfo->interp, AEInfo->procedure, NULL, 0)) {
if (!AEInfo->interp) {
return;
}
/*
* Apple events that are delivered during the app startup can arrive
* before the Tcl procedure for handling the events has been defined.
* If the command is not found we create a timer handler to process
* the event later, hopefully after the command has been created.
* We retry up to 2 times before giving up.
*/
if (!Tcl_FindCommand(AEInfo->interp, AEInfo->procedure, NULL, 0)) {
if (AEInfo->retryCount < 2) {
AEInfo->retryCount++;
Tcl_CreateTimerHandler(200, ProcessAppleEvent, clientData);
} else {
ckfree(clientData);
}
return;
}
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);
}
if (AEInfo->replyEvent && code >= 0) {
int reslen;
@@ -400,7 +433,10 @@ static void ProcessAppleEvent(
AEPutParamPtr((AppleEvent*)[AEInfo->replyEvent aeDesc],
keyErrorNumber, typeSInt32, (Ptr) &code, sizeof(int));
}
} else if (code != TCL_OK) {
Tcl_BackgroundException(AEInfo->interp, code);
}
Tcl_DStringFree(&AEInfo->command);
ckfree(clientData);
}
@@ -534,13 +570,18 @@ TkMacOSXDoHLEvent(
static int
ReallyKillMe(
Tcl_Event *eventPtr,
int flags)
TCL_UNUSED(int))
{
Tcl_Interp *interp = ((KillEvent *) eventPtr)->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);
if (!quit) {
Tcl_Exit(0);
}
int code = Tcl_EvalEx(interp, "::tk::mac::Quit", -1, TCL_EVAL_GLOBAL);
if (code != TCL_OK) {
/*
* Should be never reached...
*/