From 537386f4a6d884537e64d0a994b375d97d5ccf10 Mon Sep 17 00:00:00 2001 From: Kevin Walzer Date: Thu, 7 Mar 2019 03:56:19 +0000 Subject: Clean up implementation and documentation of ::tk::mac::PrintDocument command; was mapped internally to ::tk::mac::OpenDocument and print event never fired; changed parameter to a single file path --- doc/tk_mac.n | 5 ++--- macosx/tkMacOSXHLEvents.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/doc/tk_mac.n b/doc/tk_mac.n index b0aa36f..3762afc 100644 --- a/doc/tk_mac.n +++ b/doc/tk_mac.n @@ -117,9 +117,8 @@ proc ::tk::mac::OpenDocument {args} { If a proc of this name is defined it is the default Apple Event handler for kAEPrintDocuments, .QW pdoc , -the Apple Event sent when your application is asked to print one or more -documents (e.g., via the Print menu item in the Finder). It works the same -way as \fBtk::mac::OpenDocument\fR in terms of arguments. +the Apple Event sent when your application is asked to print a +document. It takes a single absolute file path as an argument. .TP \fB::tk::mac::Quit\fR . diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c index 0bd2d5e..d2843a8 100644 --- a/macosx/tkMacOSXHLEvents.c +++ b/macosx/tkMacOSXHLEvents.c @@ -126,9 +126,24 @@ static int ReallyKillMe(Tcl_Event *eventPtr, int flags); - (void) handlePrintDocumentsEvent: (NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent { - tkMacOSXProcessFiles(event, replyEvent, _eventInterp, "::tk::mac::PrintDocument"); + + 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); + } } + - (void) handleDoScriptEvent: (NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent { -- cgit v0.12