head	1.22;
access;
symbols
	core-8-5-9:1.15.2.3
	core-8-5-8:1.15.2.3
	macosx-cocoa-merge:1.20
	macosx-cocoa-premerge:1.19
	macosx-carbon-freeze:1.19
	core-8-5-7:1.15.2.2
	core-8-5-6:1.15.2.2
	core-8-6-b1:1.19
	core-8-6-a3:1.18
	core-8-5-5:1.15.2.2
	core-8-6-a2:1.17
	core-8-5-4:1.15.2.1
	core-8-5-3:1.15
	core-8-6-a1:1.15
	core-8-4-19:1.5.2.11
	core-8-5-branch:1.15.0.2
	core-8-5-2:1.15
	core-8-4-18:1.5.2.11
	core-8-5-1:1.15
	core-8-4-17:1.5.2.11
	core-8-5-0:1.15
	core-8-5-b3:1.14
	core-8-5-b2:1.14
	core-8-4-16:1.5.2.11
	core-8-5-b1:1.14
	core-stablilizer-merge:1.14
	core-stabilizer-branch:1.13.0.2
	core-stabilizer-merge:1.15
	core-8-4-15:1.5.2.10
	core-8-5-a6:1.13
	core-8-5-a5:1.12
	core-8-4-14:1.5.2.9
	core-8-5-a4:1.11
	core-8-4-13:1.5.2.8
	core-8-4-12:1.5.2.6
	core-8-4-11:1.5.2.5
	core-8-5-a3:1.8
	core-8-4-10:1.5.2.5
	core-8-4-9-branch:1.5.2.4.0.2
	core-8-5-a2:1.7
	core-8-4-9:1.5.2.4
	core-8-4-8:1.5.2.4
	core-8-4-7:1.5.2.4
	core-8-5-a1:1.7
	core-8-4-6:1.5.2.2
	core-8-4-5:1.5.2.1
	mistachkin-dev-branch:1.6.0.2
	core-8-4-4:1.5.2.1
	core-8-4-3:1.5.2.1
	core-8-4-branch:1.5.0.2
	core-8-4-2:1.5
	core-8-4-1:1.3
	core-8-4-0:1.2
	macosx-8-4-merge-2002-08-31-trunk:1.2
	macosx-8-4-premerge-2002-08-31-branch:1.1.2.4
	macosx-8-4-merge-2002-08-30-branch:1.1.2.4
	macosx-8-4-merge-2002-08-20-branch:1.1.2.4
	macosx-premerge-6-9-02:1.1.2.2
	macosx-8-4-branch:1.1.0.2;
locks; strict;
comment	@ * @;


1.22
date	2009.08.24.00.56.00;	author das;	state Exp;
branches;
next	1.21;

1.21
date	2009.07.06.20.29.21;	author dkf;	state Exp;
branches;
next	1.20;

1.20
date	2009.06.29.14.35.01;	author das;	state Exp;
branches;
next	1.19;

1.19
date	2008.12.09.21.22.56;	author dgp;	state Exp;
branches;
next	1.18;

1.18
date	2008.09.02.16.10.55;	author das;	state Exp;
branches;
next	1.17;

1.17
date	2008.07.22.17.00.20;	author das;	state Exp;
branches;
next	1.16;

1.16
date	2008.07.02.09.44.49;	author dkf;	state Exp;
branches;
next	1.15;

1.15
date	2007.12.13.15.27.09;	author dgp;	state Exp;
branches
	1.15.2.1;
next	1.14;

1.14
date	2007.06.29.03.20.01;	author das;	state Exp;
branches;
next	1.13;

1.13
date	2007.04.23.21.24.33;	author das;	state Exp;
branches
	1.13.2.1;
next	1.12;

1.12
date	2006.05.12.18.18.36;	author das;	state Exp;
branches;
next	1.11;

1.11
date	2006.04.11.10.21.28;	author das;	state Exp;
branches;
next	1.10;

1.10
date	2006.03.24.14.58.01;	author das;	state Exp;
branches;
next	1.9;

1.9
date	2005.08.09.07.39.20;	author das;	state Exp;
branches;
next	1.8;

1.8
date	2005.05.14.20.48.15;	author das;	state Exp;
branches;
next	1.7;

1.7
date	2004.02.16.00.19.42;	author wolfsuit;	state Exp;
branches;
next	1.6;

1.6
date	2003.03.12.05.56.21;	author wolfsuit;	state Exp;
branches;
next	1.5;

1.5
date	2003.02.25.16.11.22;	author das;	state Exp;
branches
	1.5.2.1;
next	1.4;

1.4
date	2003.02.25.16.09.25;	author das;	state Exp;
branches;
next	1.3;

1.3
date	2002.09.12.17.34.16;	author das;	state Exp;
branches;
next	1.2;

1.2
date	2002.08.31.06.12.30;	author das;	state Exp;
branches;
next	1.1;

1.1
date	2001.10.15.09.22.00;	author wolfsuit;	state dead;
branches
	1.1.2.1;
next	;

1.1.2.1
date	2001.10.15.09.22.00;	author wolfsuit;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2002.02.05.02.25.17;	author wolfsuit;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2002.07.18.23.45.18;	author vincentdarley;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2002.07.21.11.11.55;	author vincentdarley;	state Exp;
branches;
next	;

1.5.2.1
date	2003.05.13.02.42.57;	author das;	state Exp;
branches;
next	1.5.2.2;

1.5.2.2
date	2004.02.16.00.42.34;	author wolfsuit;	state Exp;
branches;
next	1.5.2.3;

1.5.2.3
date	2004.03.17.19.01.46;	author wolfsuit;	state Exp;
branches;
next	1.5.2.4;

1.5.2.4
date	2004.03.17.19.35.41;	author wolfsuit;	state Exp;
branches;
next	1.5.2.5;

1.5.2.5
date	2005.05.14.20.53.31;	author das;	state Exp;
branches;
next	1.5.2.6;

1.5.2.6
date	2005.08.09.07.40.00;	author das;	state Exp;
branches;
next	1.5.2.7;

1.5.2.7
date	2006.03.28.02.44.13;	author das;	state Exp;
branches;
next	1.5.2.8;

1.5.2.8
date	2006.04.11.10.21.53;	author das;	state Exp;
branches;
next	1.5.2.9;

1.5.2.9
date	2006.05.12.18.18.52;	author das;	state Exp;
branches;
next	1.5.2.10;

1.5.2.10
date	2007.04.29.02.26.49;	author das;	state Exp;
branches;
next	1.5.2.11;

1.5.2.11
date	2007.06.29.03.22.02;	author das;	state Exp;
branches;
next	1.5.2.12;

1.5.2.12
date	2009.08.24.00.59.29;	author das;	state Exp;
branches;
next	;

1.13.2.1
date	2007.07.01.17.31.33;	author dgp;	state Exp;
branches;
next	;

1.15.2.1
date	2008.07.22.17.00.49;	author das;	state Exp;
branches;
next	1.15.2.2;

1.15.2.2
date	2008.09.02.16.14.18;	author das;	state Exp;
branches;
next	1.15.2.3;

1.15.2.3
date	2009.08.24.00.59.09;	author das;	state Exp;
branches;
next	;


desc
@@


1.22
log
@	* macosx/tkMacOSXHLEvents.c (ScriptHandler):	Fix "do script" apple
	* carbon/tkMacOSXHLEvents.c (ScriptHandler):	event handler issues
	on recent 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)
@
text
@/*
 * tkMacOSXHLEvents.c --
 *
 *	Implements high level event support for the Macintosh. Currently, the
 *	only event that really does anything is the Quit event.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * 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.21 2009/07/06 20:29:21 dkf Exp $
 */

#include "tkMacOSXPrivate.h"

/*
 * This is a Tcl_Event structure that the Quit AppleEvent handler uses to
 * schedule the ReallyKillMe function.
 */

typedef struct KillEvent {
    Tcl_Event header;		/* Information that is standard for all
				 * events. */
    Tcl_Interp *interp;		/* Interp that was passed to the Quit
				 * AppleEvent */
} KillEvent;

/*
 * Static functions used only in this file.
 */

static OSErr		QuitHandler(const AppleEvent *event,
			    AppleEvent *reply, SRefCon handlerRefcon);
static OSErr		OappHandler(const AppleEvent *event,
			    AppleEvent *reply, SRefCon handlerRefcon);
static OSErr		RappHandler(const AppleEvent *event,
			    AppleEvent *reply, SRefCon handlerRefcon);
static OSErr		OdocHandler(const AppleEvent *event,
			    AppleEvent *reply, SRefCon handlerRefcon);
static OSErr		PrintHandler(const AppleEvent *event,
			    AppleEvent *reply, SRefCon handlerRefcon);
static OSErr		ScriptHandler(const AppleEvent *event,
			    AppleEvent *reply, SRefCon handlerRefcon);
static OSErr		PrefsHandler(const AppleEvent *event,
			    AppleEvent *reply, SRefCon handlerRefcon);
static int		MissedAnyParameters(const AppleEvent *theEvent);
static int		ReallyKillMe(Tcl_Event *eventPtr, int flags);
static OSStatus		FSRefToDString(const FSRef *fsref, Tcl_DString *ds);

#pragma mark TKApplication(TKHLEvents)

@@implementation TKApplication(TKHLEvents)
- (void) terminate: (id) sender
{
    QuitHandler(NULL, NULL, (SRefCon) _eventInterp);
}

- (void) preferences: (id) sender
{
    PrefsHandler(NULL, NULL, (SRefCon) _eventInterp);
}
@@end

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXInitAppleEvents --
 *
 *	Initilize the Apple Events on the Macintosh. This registers the core
 *	event handlers.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXInitAppleEvents(
    Tcl_Interp *interp)		/* Interp to handle basic events. */
{
    AEEventHandlerUPP OappHandlerUPP, RappHandlerUPP, OdocHandlerUPP;
    AEEventHandlerUPP PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP;
    AEEventHandlerUPP PrefsHandlerUPP;
    static Boolean initialized = FALSE;

    if (!initialized) {
	initialized = TRUE;

	/*
	 * Install event handlers for the core apple events.
	 */

	QuitHandlerUPP = NewAEEventHandlerUPP(QuitHandler);
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEQuitApplication,
		QuitHandlerUPP, (SRefCon) interp, false);

	OappHandlerUPP = NewAEEventHandlerUPP(OappHandler);
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenApplication,
		OappHandlerUPP, (SRefCon) interp, false);

	RappHandlerUPP = NewAEEventHandlerUPP(RappHandler);
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEReopenApplication,
		RappHandlerUPP, (SRefCon) interp, false);

	OdocHandlerUPP = NewAEEventHandlerUPP(OdocHandler);
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenDocuments,
		OdocHandlerUPP, (SRefCon) interp, false);

	PrintHandlerUPP = NewAEEventHandlerUPP(PrintHandler);
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEPrintDocuments,
		PrintHandlerUPP, (SRefCon) interp, false);

	PrefsHandlerUPP = NewAEEventHandlerUPP(PrefsHandler);
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEShowPreferences,
		PrefsHandlerUPP, (SRefCon) interp, false);

	if (interp) {
	    ScriptHandlerUPP = NewAEEventHandlerUPP(ScriptHandler);
	    ChkErr(AEInstallEventHandler, kAEMiscStandards, kAEDoScript,
		    ScriptHandlerUPP, (SRefCon) interp, false);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXDoHLEvent --
 *
 *	Dispatch incomming highlevel events.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Depends on the incoming event.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXDoHLEvent(
    void *theEvent)
{
    return AEProcessAppleEvent((EventRecord *)theEvent);
}

/*
 *----------------------------------------------------------------------
 *
 * QuitHandler --
 *
 *	This is the 'quit' core Apple event handler.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static OSErr
QuitHandler(
    const AppleEvent *event,
    AppleEvent *reply,
    SRefCon handlerRefcon)
{
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
    KillEvent *eventPtr;

    if (interp) {
	/*
	 * Call the exit command from the event loop, since you are not
	 * supposed to call ExitToShell in an Apple Event Handler. We put this
	 * at the head of Tcl's event queue because this message usually comes
	 * when the Mac is shutting down, and we want to kill the shell as
	 * quickly as possible.
	 */

	eventPtr = (KillEvent *) ckalloc(sizeof(KillEvent));
	eventPtr->header.proc = ReallyKillMe;
	eventPtr->interp = interp;

	Tcl_QueueEvent((Tcl_Event *) eventPtr, TCL_QUEUE_HEAD);
    }
    return noErr;
}

/*
 *----------------------------------------------------------------------
 *
 * OappHandler --
 *
 *	This is the 'oapp' core Apple event handler.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static OSErr
OappHandler(
    const AppleEvent *event,
    AppleEvent *reply,
    SRefCon handlerRefcon)
{
    Tcl_CmdInfo dummy;
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;

    if (interp &&
	    Tcl_GetCommandInfo(interp, "::tk::mac::OpenApplication", &dummy)){
	int code = Tcl_GlobalEval(interp, "::tk::mac::OpenApplication");
	if (code != TCL_OK) {
	    Tcl_BackgroundException(interp, code);
	}
    }
    return noErr;
}

/*
 *----------------------------------------------------------------------
 *
 * RappHandler --
 *
 *	This is the 'rapp' core Apple event handler.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static OSErr
RappHandler(
    const AppleEvent *event,
    AppleEvent *reply,
    SRefCon handlerRefcon)
{
    Tcl_CmdInfo dummy;
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
    ProcessSerialNumber thePSN = {0, kCurrentProcess};
    OSStatus err = ChkErr(SetFrontProcess, &thePSN);

    if (interp && Tcl_GetCommandInfo(interp,
	    "::tk::mac::ReopenApplication", &dummy)) {
	int code = Tcl_GlobalEval(interp, "::tk::mac::ReopenApplication");
	if (code != TCL_OK){
	    Tcl_BackgroundException(interp, code);
	}
    }
    return err;
}

/*
 *----------------------------------------------------------------------
 *
 * PrefsHandler --
 *
 *	This is the 'pref' core Apple event handler. Called when the user
 *	selects 'Preferences...' in MacOS X
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static OSErr
PrefsHandler(
    const AppleEvent *event,
    AppleEvent *reply,
    SRefCon handlerRefcon)
{
    Tcl_CmdInfo dummy;
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;

    if (interp &&
	    Tcl_GetCommandInfo(interp, "::tk::mac::ShowPreferences", &dummy)){
	int code = Tcl_GlobalEval(interp, "::tk::mac::ShowPreferences");
	if (code != TCL_OK) {
	    Tcl_BackgroundException(interp, code);
	}
    }
    return noErr;
}

/*
 *----------------------------------------------------------------------
 *
 * OdocHandler --
 *
 *	This is the 'odoc' core Apple event handler.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static OSErr
OdocHandler(
    const AppleEvent *event,
    AppleEvent *reply,
    SRefCon handlerRefcon)
{
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
    AEDescList fileSpecList;
    FSRef file;
    DescType type;
    Size actual;
    long count, index;
    AEKeyword keyword;
    Tcl_DString command, pathName;
    Tcl_CmdInfo dummy;
    int code;

    /*
     * Don't bother if we don't have an interp or the open document procedure
     * doesn't exist.
     */

    if (!interp ||
	    !Tcl_GetCommandInfo(interp, "::tk::mac::OpenDocument", &dummy)) {
	return noErr;
    }

    /*
     * If we get any errors while retrieving our parameters we just return with
     * no error.
     */

    if (ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
	    &fileSpecList) != noErr) {
	return noErr;
    }
    if (MissedAnyParameters(event) != noErr) {
	return noErr;
    }
    if (ChkErr(AECountItems, &fileSpecList, &count) != noErr) {
	return noErr;
    }

    /*
     * Convert our parameters into a script to evaluate, skipping things that
     * we can't handle right.
     */

    Tcl_DStringInit(&command);
    Tcl_DStringAppend(&command, "::tk::mac::OpenDocument", -1);
    for (index = 1; index <= count; index++) {
	if (ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword,
		&type, (Ptr) &file, sizeof(FSRef), &actual) != noErr) {
	    continue;
	}

	if (ChkErr(FSRefToDString, &file, &pathName) == noErr) {
	    Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
	    Tcl_DStringFree(&pathName);
	}
    }

    /*
     * Now handle the event by evaluating a script.
     */

    code = Tcl_EvalEx(interp, Tcl_DStringValue(&command),
	    Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
    if (code != TCL_OK) {
	Tcl_BackgroundException(interp, code);
    }
    Tcl_DStringFree(&command);
    return noErr;
}

/*
 *----------------------------------------------------------------------
 *
 * PrintHandler --
 *
 *	This is the 'pdoc' core Apple event handler.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static OSErr
PrintHandler(
    const AppleEvent * event,
    AppleEvent * reply,
    SRefCon handlerRefcon)
{
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
    AEDescList fileSpecList;
    FSRef file;
    DescType type;
    Size actual;
    long count, index;
    AEKeyword keyword;
    Tcl_DString command, pathName;
    Tcl_CmdInfo dummy;
    int code;

    /*
     * Don't bother if we don't have an interp or the print document procedure
     * doesn't exist.
     */

    if (!interp ||
	    !Tcl_GetCommandInfo(interp, "::tk::mac::PrintDocument", &dummy)) {
	return noErr;
    }

    /*
     * If we get any errors while retrieving our parameters we just return with
     * no error.
     */

    if (ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
	    &fileSpecList) != noErr) {
	return noErr;
    }
    if (ChkErr(MissedAnyParameters, event) != noErr) {
	return noErr;
    }
    if (ChkErr(AECountItems, &fileSpecList, &count) != noErr) {
	return noErr;
    }

    Tcl_DStringInit(&command);
    Tcl_DStringAppend(&command, "::tk::mac::PrintDocument", -1);
    for (index = 1; index <= count; index++) {
	if (ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword,
		&type, (Ptr) &file, sizeof(FSRef), &actual) != noErr) {
	    continue;
	}

	if (ChkErr(FSRefToDString, &file, &pathName) == noErr) {
	    Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
	    Tcl_DStringFree(&pathName);
	}
    }

    /*
     * Now handle the event by evaluating a script.
     */

    code = Tcl_EvalEx(interp, Tcl_DStringValue(&command),
	    Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
    if (code != TCL_OK) {
	Tcl_BackgroundException(interp, code);
    }
    Tcl_DStringFree(&command);
    return noErr;
}

/*
 *----------------------------------------------------------------------
 *
 * ScriptHandler --
 *
 *	This handler process the script event.
 *
 * Results:
 *	Schedules the given event to be processed.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static OSErr
ScriptHandler(
    const AppleEvent *event,
    AppleEvent *reply,
    SRefCon handlerRefcon)
{
    OSStatus theErr;
    AEDescList theDesc;
    Size size;
    int tclErr = -1;
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
    char errString[128];

    /*
     * The do script event receives one parameter that should be data or a
     * file.
     */

    theErr = AEGetParamDesc(event, keyDirectObject, typeWildCard,
	    &theDesc);
    if (theErr != noErr) {
	sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d",
		(int)theErr);
	theErr = AEPutParamPtr(reply, keyErrorString, typeChar, errString,
		strlen(errString));
    } else if (MissedAnyParameters(event)) {
	/*
	 * Return error if parameter is missing.
	 */

	sprintf(errString, "AEDoScriptHandler: extra parameters");
	AEPutParamPtr(reply, keyErrorString, typeChar, errString,
		strlen(errString));
	theErr = -1771;
    } 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.
	 */

	FSRef file;
	theErr = AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, &file,
		size, NULL);
	if (theErr == noErr) {
	    Tcl_DString scriptName;

	    theErr = FSRefToDString(&file, &scriptName);
	    if (theErr == noErr) {
		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 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 coercable to 'utf8'",
		(char*) &theDesc.descriptorType);
	AEPutParamPtr(reply, keyErrorString, typeChar, errString,
		strlen(errString));
	theErr = -1770;
    }

    /*
     * If we actually go to run Tcl code - put the result in the reply.
     */

    if (tclErr >= 0) {
	int reslen;
	const char *result =
		Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &reslen);

	if (tclErr == TCL_OK) {
	    AEPutParamPtr(reply, keyDirectObject, typeChar, result, reslen);
	} else {
	    AEPutParamPtr(reply, keyErrorString, typeChar, result, reslen);
	    AEPutParamPtr(reply, keyErrorNumber, typeSInt32, (Ptr) &tclErr,
		    sizeof(int));
	}
    }

    AEDisposeDesc(&theDesc);
    return theErr;
}

/*
 *----------------------------------------------------------------------
 *
 * ReallyKillMe --
 *
 *	This proc tries to kill the shell by running exit, called from an
 *	event scheduled by the "Quit" AppleEvent handler.
 *
 * Results:
 *	Runs the "exit" command which might kill the shell.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
ReallyKillMe(
    Tcl_Event *eventPtr,
    int flags)
{
    Tcl_Interp *interp = ((KillEvent *) eventPtr)->interp;
    Tcl_CmdInfo dummy;
    int quit = Tcl_GetCommandInfo(interp, "::tk::mac::Quit", &dummy);
    int code = Tcl_GlobalEval(interp, quit ? "::tk::mac::Quit" : "exit");

    if (code != TCL_OK) {
	/*
	 * Should be never reached...
	 */

	Tcl_BackgroundException(interp, code);
    }
    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * MissedAnyParameters --
 *
 *	Checks to see if parameters are still left in the event.
 *
 * Results:
 *	True or false.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
MissedAnyParameters(
    const AppleEvent *theEvent)
{
   DescType returnedType;
   Size actualSize;
   OSStatus err;

   err = AEGetAttributePtr(theEvent, keyMissedKeywordAttr,
	    typeWildCard, &returnedType, NULL, 0, &actualSize);

   return (err != errAEDescNotFound);
}

/*
 *----------------------------------------------------------------------
 *
 * FSRefToDString --
 *
 *	Get a POSIX path from an FSRef.
 *
 * Results:
 *	In the parameter ds.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static OSStatus
FSRefToDString(
    const FSRef *fsref,
    Tcl_DString *ds)
{
    UInt8 fileName[PATH_MAX+1];
    OSStatus err;

    err = ChkErr(FSRefMakePath, fsref, fileName, sizeof(fileName));
    if (err == noErr) {
	Tcl_ExternalToUtfDString(NULL, (char*) fileName, -1, ds);
    }
    return err;
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */
@


1.21
log
@More marking of files as Objective-C.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.20 2009/06/29 14:35:01 das Exp $
d509 1
d535 3
a537 23
    } 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) {
a541 1
	Boolean dummy;
d543 2
a544 11
	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;
	}
d550 1
a550 1
		Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName));
d552 4
d557 12
a568 4
	} else {
	    sprintf(errString, "AEDoScriptHandler: file not found");
	    AEPutParamPtr(reply, keyErrorString, typeChar, errString,
		    strlen(errString));
d575 3
a577 2
	sprintf(errString, "AEDoScriptHandler: invalid script type '%-4.4s',"
		" must be 'alis' or 'TEXT'", (char*) &theDesc.descriptorType);
d666 1
a666 1
   err = ChkErr(AEGetAttributePtr, theEvent, keyMissedKeywordAttr,
@


1.20
log
@Merge of TkAqua Cocoa port
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.19 2008/12/09 21:22:56 dgp Exp $
d56 2
a57 2

- (void)terminate:(id)sender {
d61 2
a62 1
- (void)preferences:(id)sender {
a64 1

d721 1
a721 1
 * mode: c
@


1.19
log
@        TIP 337

        * generic/tkBind.c:     Updated callers of Tcl_BackgroundError()
        * generic/tkCanvas.c:   to use the new routine
        * generic/tkEntry.c:    Tcl_BackgroundException() as appropriate.
        * generic/tkImgBmap.c:
        * generic/tkListbox.c:
        * generic/tkSelect.c:
        * generic/tkTextDisp.c:
        * generic/tkTextWind.c:
        * macosx/tkMacOSXHLEvents.c:
        * macosx/tkMacOSXMenu.c:
        * macosx/tkMacOSXMenus.c:
        * macosx/tkMacOSXScale.c:
        * macosx/tkMacOSXWindowEvent.c:
        * unix/tkUnixScale.c:
        * unix/tkUnixWm.c:
        * win/tkWinButton.c:
        * win/tkWinMenu.c:
        * win/tkWinScrlbr.c:
        * win/tkWinWm.c:
@
text
@d8 2
a9 2
 * Copyright 2001, Apple Computer, Inc.
 * Copyright (c) 2006 Daniel A. Steffen <das@@users.sourceforge.net>
d11 2
a12 2
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.18 2008/09/02 16:10:55 das Exp $
d36 1
a36 1
			    AppleEvent *reply, long handlerRefcon);
d38 1
a38 1
			    AppleEvent *reply, long handlerRefcon);
d40 1
a40 1
			    AppleEvent *reply, long handlerRefcon);
d42 1
a42 1
			    AppleEvent *reply, long handlerRefcon);
d44 1
a44 1
			    AppleEvent *reply, long handlerRefcon);
d46 1
a46 1
			    AppleEvent *reply, long handlerRefcon);
d48 1
a48 1
			    AppleEvent *reply, long handlerRefcon);
d52 16
d104 1
a104 1
		QuitHandlerUPP, (long) interp, false);
d108 1
a108 1
		OappHandlerUPP, (long) interp, false);
d112 1
a112 1
		RappHandlerUPP, (long) interp, false);
d116 1
a116 1
		OdocHandlerUPP, (long) interp, false);
d120 1
a120 1
		PrintHandlerUPP, (long) interp, false);
d124 1
a124 1
		PrefsHandlerUPP, (long) interp, false);
d129 1
a129 1
		    ScriptHandlerUPP, (long) interp, false);
d152 1
a152 1
    EventRecord *theEvent)
d154 1
a154 1
    return AEProcessAppleEvent(theEvent);
d177 1
a177 1
    long handlerRefcon)
d220 1
a220 1
    long handlerRefcon)
d255 1
a255 1
    long handlerRefcon)
d293 1
a293 1
    long handlerRefcon)
d328 1
a328 1
    long handlerRefcon)
d419 1
a419 1
    long handlerRefcon)
d505 1
a505 1
    long handlerRefcon)
d521 2
a522 2
	sprintf(errString, "AEDoScriptHandler: GetParamDesc error %ld",
		theErr);
d612 1
a612 1
	    AEPutParamPtr(reply, keyErrorNumber, typeInteger, (Ptr) &tclErr,
d723 2
a724 1
 * fill-column: 78
@


1.18
log
@comments, whitespace
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.17 2008/07/22 17:00:20 das Exp $
d211 3
a213 2
	if (Tcl_GlobalEval(interp, "::tk::mac::OpenApplication") != TCL_OK) {
	    Tcl_BackgroundError(interp);
d248 3
a250 2
	if (Tcl_GlobalEval(interp, "::tk::mac::ReopenApplication") != TCL_OK){
	    Tcl_BackgroundError(interp);
d284 3
a286 2
	if (Tcl_GlobalEval(interp, "::tk::mac::ShowPreferences") != TCL_OK) {
	    Tcl_BackgroundError(interp);
d323 1
d374 4
a377 3
    if (Tcl_EvalEx(interp, Tcl_DStringValue(&command),
	    Tcl_DStringLength(&command), TCL_EVAL_GLOBAL) != TCL_OK) {
	Tcl_BackgroundError(interp);
d414 1
d460 4
a463 3
    if (Tcl_EvalEx(interp, Tcl_DStringValue(&command),
	    Tcl_DStringLength(&command), TCL_EVAL_GLOBAL) != TCL_OK) {
	Tcl_BackgroundError(interp);
d630 1
d632 1
a632 1
    if (Tcl_GlobalEval(interp, quit ? "::tk::mac::Quit" : "exit") != TCL_OK) {
d637 1
a637 1
	Tcl_BackgroundError(interp);
@


1.17
log
@	* macosx/tkMacOSXHLEvents.c: factor out common code; formatting.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.16 2008/07/02 09:44:49 dkf Exp $
d332 1
a332 1
     * If we get any errors wil retrieving our parameters we just return with
d421 1
a421 1
     * If we get any errors wil retrieving our parameters we just return with
d450 4
@


1.16
log
@Ensure that errors in callback scripts don't get swept under the carpet.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.15 2007/12/13 15:27:09 dgp Exp $
d500 1
a500 1
	 * Dude! Where's my parameter?
d576 1
a576 1
    if (tclErr == TCL_OK) {
d581 7
a587 9
	AEPutParamPtr(reply, keyDirectObject, typeChar, result, reslen);
    } else if (tclErr >= 0) {
	int reslen;
	const char *result =
		Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &reslen);

	AEPutParamPtr(reply, keyErrorString, typeChar, result, reslen);
	AEPutParamPtr(reply, keyErrorNumber, typeInteger, (Ptr) &tclErr,
		sizeof(int));
d618 1
a618 1
    int result;
d620 1
a620 6
    if (Tcl_GetCommandInfo(interp, "::tk::mac::Quit", &dummy)) {
	result = Tcl_GlobalEval(interp, "::tk::mac::Quit");
    } else {
	result = Tcl_GlobalEval(interp, "exit");
    }
    if (result != TCL_OK) {
d652 1
a652 1
   register OSStatus err;
d682 1
a682 1
    register OSStatus err;
d686 1
a686 1
	Tcl_ExternalToUtfDString(NULL, (char *) fileName, -1, ds);
@


1.15
log
@merge stable branch onto HEAD
@
text
@d4 2
a5 2
 *	Implements high level event support for the Macintosh. Currently,
 *	the only event that really does anything is the Quit event.
d11 2
a12 2
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.13.2.1 2007/07/01 17:31:33 dgp Exp $
d20 2
a21 2
 * This is a Tcl_Event structure that the Quit AppleEvent handler
 * uses to schedule the ReallyKillMe function.
d25 4
a28 4
    Tcl_Event header;		/* Information that is standard for
				 * all events. */
    Tcl_Interp *interp;		/* Interp that was passed to the
				 * Quit AppleEvent */
d35 17
a51 18
static OSErr QuitHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr OappHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr RappHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr OdocHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr PrintHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr ScriptHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr PrefsHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);

static int MissedAnyParameters(const AppleEvent *theEvent);
static int ReallyKillMe(Tcl_Event *eventPtr, int flags);
static OSStatus FSRefToDString(const FSRef *fsref, Tcl_DString *ds);
d58 2
a59 2
 *	Initilize the Apple Events on the Macintosh. This registers the
 *	core event handlers.
d72 1
a72 1
    Tcl_Interp *interp)		       /* Interp to handle basic events. */
d74 3
a76 2
    AEEventHandlerUPP	     OappHandlerUPP, RappHandlerUPP, OdocHandlerUPP,
	    PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP, PrefsHandlerUPP;
d85 1
d113 1
a113 1
		ScriptHandlerUPP, (long) interp, false);
d157 1
a157 1
OSErr
d159 2
a160 2
    const AppleEvent * event,
    AppleEvent * reply,
d168 5
a172 4
	 * Call the exit command from the event loop, since you are not supposed
	 * to call ExitToShell in an Apple Event Handler. We put this at the head
	 * of Tcl's event queue because this message usually comes when the Mac is
	 * shutting down, and we want to kill the shell as quickly as possible.
d200 1
a200 1
OSErr
d202 2
a203 2
    const AppleEvent * event,
    AppleEvent * reply,
d210 4
a213 2
	    Tcl_GetCommandInfo(interp, "::tk::mac::OpenApplication", &dummy)) {
	Tcl_GlobalEval(interp, "::tk::mac::OpenApplication");
d234 1
a234 1
OSErr
d236 2
a237 2
    const AppleEvent * event,
    AppleEvent * reply,
d245 5
a249 3
    if (interp &&
	    Tcl_GetCommandInfo(interp, "::tk::mac::ReopenApplication", &dummy)) {
	Tcl_GlobalEval(interp, "::tk::mac::ReopenApplication");
d259 2
a260 2
 *	This is the 'pref' core Apple event handler.
 *	Called when the user selects 'Preferences...' in MacOS X
d271 1
a271 1
OSErr
d273 2
a274 2
    const AppleEvent * event,
    AppleEvent * reply,
d281 4
a284 2
	    Tcl_GetCommandInfo(interp, "::tk::mac::ShowPreferences", &dummy)) {
	Tcl_GlobalEval(interp, "::tk::mac::ShowPreferences");
d305 1
a305 1
OSErr
d307 2
a308 2
    const AppleEvent * event,
    AppleEvent * reply,
a313 1
    OSStatus err;
d316 1
a316 1
    long count;
d318 1
a318 3
    long index;
    Tcl_DString command;
    Tcl_DString pathName;
d322 2
a323 2
     * Don't bother if we don't have an interp or
     * the open document procedure doesn't exist.
d326 3
a328 3
    if ((interp == NULL) ||
	    (Tcl_GetCommandInfo(interp, "::tk::mac::OpenDocument", &dummy)) == 0) {
	    return noErr;
d332 2
a333 2
     * If we get any errors wil retrieving our parameters
     * we just return with no error.
d336 2
a337 3
    err = ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
	    &fileSpecList);
    if (err != noErr) {
d340 1
a340 3

    err = MissedAnyParameters(event);
    if (err != noErr) {
d343 1
a343 3

    err = ChkErr(AECountItems, &fileSpecList, &count);
    if (err != noErr) {
d347 5
d355 2
a356 3
	err = ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef,
		&keyword, &type, (Ptr) &file, sizeof(FSRef), &actual);
	if ( err != noErr ) {
d360 1
a360 2
	err = ChkErr(FSRefToDString, &file, &pathName);
	if (err == noErr) {
d366 3
a368 2
    Tcl_EvalEx(interp, Tcl_DStringValue(&command), Tcl_DStringLength(&command),
	    TCL_EVAL_GLOBAL);
d370 4
d394 1
a394 1
OSErr
a402 1
    OSStatus err;
d405 1
a405 1
    long count;
d407 1
a407 3
    long index;
    Tcl_DString command;
    Tcl_DString pathName;
d411 2
a412 2
     * Don't bother if we don't have an interp or
     * the print document procedure doesn't exist.
d415 3
a417 3
    if ((interp == NULL) ||
	    (Tcl_GetCommandInfo(interp, "::tk::mac::PrintDocument", &dummy)) == 0) {
	    return noErr;
d421 2
a422 2
     * If we get any errors wil retrieving our parameters
     * we just return with no error.
d425 2
a426 3
    err = ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
	    &fileSpecList);
    if (err != noErr) {
d429 1
a429 3

    err = ChkErr(MissedAnyParameters, event);
    if (err != noErr) {
d432 1
a432 3

    err = ChkErr(AECountItems, &fileSpecList, &count);
    if (err != noErr) {
d439 2
a440 3
	err = ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword,
		&type, (Ptr) &file, sizeof(FSRef), &actual);
	if ( err != noErr ) {
d444 1
a444 2
	err = ChkErr(FSRefToDString, &file, &pathName);
	if (err == noErr) {
d450 4
a453 3
    Tcl_EvalEx(interp, Tcl_DStringValue(&command), Tcl_DStringLength(&command),
	    TCL_EVAL_GLOBAL);

d474 1
a474 1
OSErr
d476 2
a477 2
    const AppleEvent * event,
    AppleEvent * reply,
d483 1
a483 1
    Tcl_Interp *interp;
a485 2
    interp = (Tcl_Interp *) handlerRefcon;

d487 2
a488 1
     * The do script event receives one parameter that should be data or a file.
d490 1
d499 4
d507 15
a521 43
    } else {
	if (theDesc.descriptorType == (DescType)typeChar) {
	    Tcl_DString encodedText;
	    short i;
	    Size  size;
	    char  * data;

	    size = AEGetDescDataSize(&theDesc);

	    data = (char *)ckalloc(size + 1);
	    if ( !data ) {
		theErr = -1771;
	    }
	    else {
		   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) {
	    Boolean dummy;
	    FSRef file;
	    AliasPtr	alias;
	    Size	theSize;

	    theSize = AEGetDescDataSize(&theDesc);
	    alias = (AliasPtr) ckalloc(theSize);
	    if (alias) {
		AEGetDescData (&theDesc, alias, theSize);

		theErr = FSResolveAlias(NULL, &alias,
			&file, &dummy);
		ckfree((char*)alias);
	    } else {
		theErr = memFullErr;
d523 28
d552 2
a553 10
		Tcl_DString scriptName;
		theErr = FSRefToDString(&file, &scriptName);
		if (theErr == noErr) {
		    Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName));
		    Tcl_DStringFree(&scriptName);
		}
	    } else {
		sprintf(errString, "AEDoScriptHandler: file not found");
		AEPutParamPtr(reply, keyErrorString, typeChar,
			errString, strlen(errString));
d556 3
a558 6
	    sprintf(errString,
		    "AEDoScriptHandler: invalid script type '%-4.4s', must be 'alis' or 'TEXT'",
		    (char *)(&theDesc.descriptorType));
	    AEPutParamPtr(reply, keyErrorString, typeChar,
		    errString, strlen(errString));
	    theErr = -1770;
d560 10
d575 15
a589 12
    if (tclErr >= 0) {
	if (tclErr == TCL_OK)  {
	    AEPutParamPtr(reply, keyDirectObject, typeChar,
		Tcl_GetStringResult(interp),
		strlen(Tcl_GetStringResult(interp)));
	} else {
	    AEPutParamPtr(reply, keyErrorString, typeChar,
		Tcl_GetStringResult(interp),
		strlen(Tcl_GetStringResult(interp)));
	    AEPutParamPtr(reply, keyErrorNumber, typeInteger,
		(Ptr) &tclErr, sizeof(int));
	}
a592 1

d601 2
a602 2
 *	This proc tries to kill the shell by running exit,
 *	called from an event scheduled by the "Quit" AppleEvent handler.
d620 2
d623 1
a623 1
	 Tcl_GlobalEval(interp, "::tk::mac::Quit");
d625 8
a632 1
	Tcl_GlobalEval(interp, "exit");
d653 1
a653 1
int
d659 1
a659 1
   OSStatus err;
d662 1
a662 1
	   typeWildCard, &returnedType, NULL, 0, &actualSize);
d683 1
a683 1
OSStatus
d689 1
a689 1
    OSStatus err;
d693 1
a693 1
	Tcl_ExternalToUtfDString(NULL, (char*) fileName, -1, ds);
d697 8
@


1.15.2.1
log
@	* macosx/tkMacOSXHLEvents.c: sync with HEAD.
@
text
@d4 2
a5 2
 *	Implements high level event support for the Macintosh. Currently, the
 *	only event that really does anything is the Quit event.
d11 2
a12 2
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.15 2007/12/13 15:27:09 dgp Exp $
d20 2
a21 2
 * This is a Tcl_Event structure that the Quit AppleEvent handler uses to
 * schedule the ReallyKillMe function.
d25 4
a28 4
    Tcl_Event header;		/* Information that is standard for all
				 * events. */
    Tcl_Interp *interp;		/* Interp that was passed to the Quit
				 * AppleEvent */
d35 18
a52 17
static OSErr		QuitHandler(const AppleEvent *event,
			    AppleEvent *reply, long handlerRefcon);
static OSErr		OappHandler(const AppleEvent *event,
			    AppleEvent *reply, long handlerRefcon);
static OSErr		RappHandler(const AppleEvent *event,
			    AppleEvent *reply, long handlerRefcon);
static OSErr		OdocHandler(const AppleEvent *event,
			    AppleEvent *reply, long handlerRefcon);
static OSErr		PrintHandler(const AppleEvent *event,
			    AppleEvent *reply, long handlerRefcon);
static OSErr		ScriptHandler(const AppleEvent *event,
			    AppleEvent *reply, long handlerRefcon);
static OSErr		PrefsHandler(const AppleEvent *event,
			    AppleEvent *reply, long handlerRefcon);
static int		MissedAnyParameters(const AppleEvent *theEvent);
static int		ReallyKillMe(Tcl_Event *eventPtr, int flags);
static OSStatus		FSRefToDString(const FSRef *fsref, Tcl_DString *ds);
d59 2
a60 2
 *	Initilize the Apple Events on the Macintosh. This registers the core
 *	event handlers.
d73 1
a73 1
    Tcl_Interp *interp)		/* Interp to handle basic events. */
d75 2
a76 3
    AEEventHandlerUPP OappHandlerUPP, RappHandlerUPP, OdocHandlerUPP;
    AEEventHandlerUPP PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP;
    AEEventHandlerUPP PrefsHandlerUPP;
a84 1

d112 1
a112 1
		    ScriptHandlerUPP, (long) interp, false);
d156 1
a156 1
static OSErr
d158 2
a159 2
    const AppleEvent *event,
    AppleEvent *reply,
d167 4
a170 5
	 * Call the exit command from the event loop, since you are not
	 * supposed to call ExitToShell in an Apple Event Handler. We put this
	 * at the head of Tcl's event queue because this message usually comes
	 * when the Mac is shutting down, and we want to kill the shell as
	 * quickly as possible.
d198 1
a198 1
static OSErr
d200 2
a201 2
    const AppleEvent *event,
    AppleEvent *reply,
d208 2
a209 4
	    Tcl_GetCommandInfo(interp, "::tk::mac::OpenApplication", &dummy)){
	if (Tcl_GlobalEval(interp, "::tk::mac::OpenApplication") != TCL_OK) {
	    Tcl_BackgroundError(interp);
	}
d230 1
a230 1
static OSErr
d232 2
a233 2
    const AppleEvent *event,
    AppleEvent *reply,
d241 3
a243 5
    if (interp && Tcl_GetCommandInfo(interp,
	    "::tk::mac::ReopenApplication", &dummy)) {
	if (Tcl_GlobalEval(interp, "::tk::mac::ReopenApplication") != TCL_OK){
	    Tcl_BackgroundError(interp);
	}
d253 2
a254 2
 *	This is the 'pref' core Apple event handler. Called when the user
 *	selects 'Preferences...' in MacOS X
d265 1
a265 1
static OSErr
d267 2
a268 2
    const AppleEvent *event,
    AppleEvent *reply,
d275 2
a276 4
	    Tcl_GetCommandInfo(interp, "::tk::mac::ShowPreferences", &dummy)){
	if (Tcl_GlobalEval(interp, "::tk::mac::ShowPreferences") != TCL_OK) {
	    Tcl_BackgroundError(interp);
	}
d297 1
a297 1
static OSErr
d299 2
a300 2
    const AppleEvent *event,
    AppleEvent *reply,
d306 1
d309 1
a309 1
    long count, index;
d311 3
a313 1
    Tcl_DString command, pathName;
d317 2
a318 2
     * Don't bother if we don't have an interp or the open document procedure
     * doesn't exist.
d321 3
a323 3
    if (!interp ||
	    !Tcl_GetCommandInfo(interp, "::tk::mac::OpenDocument", &dummy)) {
	return noErr;
d327 2
a328 2
     * If we get any errors wil retrieving our parameters we just return with
     * no error.
d331 3
a333 2
    if (ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
	    &fileSpecList) != noErr) {
d336 3
a338 1
    if (MissedAnyParameters(event) != noErr) {
d341 3
a343 1
    if (ChkErr(AECountItems, &fileSpecList, &count) != noErr) {
a346 5
    /*
     * Convert our parameters into a script to evaluate, skipping things that
     * we can't handle right.
     */

d350 3
a352 2
	if (ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword,
		&type, (Ptr) &file, sizeof(FSRef), &actual) != noErr) {
d356 2
a357 1
	if (ChkErr(FSRefToDString, &file, &pathName) == noErr) {
d363 2
a364 3
    /*
     * Now handle the event by evaluating a script.
     */
a365 4
    if (Tcl_EvalEx(interp, Tcl_DStringValue(&command),
	    Tcl_DStringLength(&command), TCL_EVAL_GLOBAL) != TCL_OK) {
	Tcl_BackgroundError(interp);
    }
d386 1
a386 1
static OSErr
d395 1
d398 1
a398 1
    long count, index;
d400 3
a402 1
    Tcl_DString command, pathName;
d406 2
a407 2
     * Don't bother if we don't have an interp or the print document procedure
     * doesn't exist.
d410 3
a412 3
    if (!interp ||
	    !Tcl_GetCommandInfo(interp, "::tk::mac::PrintDocument", &dummy)) {
	return noErr;
d416 2
a417 2
     * If we get any errors wil retrieving our parameters we just return with
     * no error.
d420 3
a422 2
    if (ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
	    &fileSpecList) != noErr) {
d425 3
a427 1
    if (ChkErr(MissedAnyParameters, event) != noErr) {
d430 3
a432 1
    if (ChkErr(AECountItems, &fileSpecList, &count) != noErr) {
d439 3
a441 2
	if (ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword,
		&type, (Ptr) &file, sizeof(FSRef), &actual) != noErr) {
d445 2
a446 1
	if (ChkErr(FSRefToDString, &file, &pathName) == noErr) {
d452 3
a454 4
    if (Tcl_EvalEx(interp, Tcl_DStringValue(&command),
	    Tcl_DStringLength(&command), TCL_EVAL_GLOBAL) != TCL_OK) {
	Tcl_BackgroundError(interp);
    }
d475 1
a475 1
static OSErr
d477 2
a478 2
    const AppleEvent *event,
    AppleEvent *reply,
d484 1
a484 1
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
d487 2
d490 1
a490 2
     * The do script event receives one parameter that should be data or a
     * file.
a491 1

a499 4
	/*
	 * Return error if parameter is missing.
	 */

d504 43
a546 15
    } 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';
a547 28
	}
	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) {
	/*
	 * 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;
	}
	if (theErr == noErr) {
	    Tcl_DString scriptName;

	    theErr = FSRefToDString(&file, &scriptName);
d549 10
a558 2
		Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName));
		Tcl_DStringFree(&scriptName);
d561 6
a566 3
	    sprintf(errString, "AEDoScriptHandler: file not found");
	    AEPutParamPtr(reply, keyErrorString, typeChar, errString,
		    strlen(errString));
a567 10
    } 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);
	AEPutParamPtr(reply, keyErrorString, typeChar, errString,
		strlen(errString));
	theErr = -1770;
a572 1

d574 4
a577 6
	int reslen;
	const char *result =
		Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &reslen);

	if (tclErr == TCL_OK) {
	    AEPutParamPtr(reply, keyDirectObject, typeChar, result, reslen);
d579 5
a583 3
	    AEPutParamPtr(reply, keyErrorString, typeChar, result, reslen);
	    AEPutParamPtr(reply, keyErrorNumber, typeInteger, (Ptr) &tclErr,
		    sizeof(int));
d588 1
d597 2
a598 2
 *	This proc tries to kill the shell by running exit, called from an
 *	event scheduled by the "Quit" AppleEvent handler.
d616 4
a619 8
    int quit = Tcl_GetCommandInfo(interp, "::tk::mac::Quit", &dummy);

    if (Tcl_GlobalEval(interp, quit ? "::tk::mac::Quit" : "exit") != TCL_OK) {
	/*
	 * Should be never reached...
	 */

	Tcl_BackgroundError(interp);
d640 1
a640 1
static int
d649 1
a649 1
	    typeWildCard, &returnedType, NULL, 0, &actualSize);
d670 1
a670 1
static OSStatus
a683 8

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */
@


1.15.2.2
log
@comments, whitespace
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.15.2.1 2008/07/22 17:00:49 das Exp $
d332 1
a332 1
     * If we get any errors while retrieving our parameters we just return with
d421 1
a421 1
     * If we get any errors while retrieving our parameters we just return with
a449 4
    /*
     * Now handle the event by evaluating a script.
     */

@


1.15.2.3
log
@	* 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)
@
text
@d9 1
a9 1
 * Copyright (c) 2006-2009 Daniel A. Steffen <das@@users.sourceforge.net>
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.15.2.2 2008/09/02 16:14:18 das Exp $
a485 1
    Size size;
d498 2
a499 2
	sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d",
		(int)theErr);
d511 23
a533 3
    } else if (theDesc.descriptorType == (DescType) typeAlias &&
	    AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, NULL,
	    0, &size) == noErr && size == sizeof(FSRef)) {
d538 1
d540 11
a550 2
	theErr = AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, &file,
		size, NULL);
d556 1
a556 1
		tclErr = Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName));
a557 4
	    } else {
		sprintf(errString, "AEDoScriptHandler: file not found");
		AEPutParamPtr(reply, keyErrorString, typeChar, errString,
			strlen(errString));
d559 4
a562 12
	}
    } 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);
d569 2
a570 3
	sprintf(errString, "AEDoScriptHandler: invalid script type '%-4.4s', "
		"must be 'alis' or coercable to 'utf8'",
		(char*) &theDesc.descriptorType);
d589 1
a589 1
	    AEPutParamPtr(reply, keyErrorNumber, typeSInt32, (Ptr) &tclErr,
d658 1
a658 1
   err = AEGetAttributePtr(theEvent, keyMissedKeywordAttr,
@


1.14
log
@	* macosx/tkMacOSXScrlbr.c: correct int <-> dobule conversion issues
	that could lead to Carbon getting confused about scrollbar thumb size.

	* macosx/tkMacOSXDraw.c (XCopyArea, XCopyPlane, TkPutImage) use
	TkMacOSX{Setup,Restore}DrawingContext() to setup/restore clip & colors.
	(TkMacOSXSetupDrawingContext, TkMacOSXRestoreDrawingContext): add save
	and restore of QD port clip region; factor out clip region code common
	to CG and QD branches; check for port and context validity; handle
	tkPictureIsOpen flag during QD port setup.
	(TkScrollWindow): remove unnecessary scroll region manipulation

	* macosx/tkMacOSXDraw.c:	remove second global QD temp region
	* macosx/tkMacOSXInt.h:		(no longer necessary) and rename
	* macosx/tkMacOSXRegion.c:	remaining global QD temp region.
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:

	* macosx/tkMacOSXDraw.c:	make useCGDrawing variable MODULE_SCOPE
	* macosx/tkMacOSXFont.c:	and respect it for ATSUI font drawing.

	* macosx/tkMacOSXButton.c:	reduce reliance on current QD port
	* macosx/tkMacOSXColor.c:	setting and remove unnecessary
	* macosx/tkMacOSXDebug.c:	references to a drawable's QD port,
	* macosx/tkMacOSXDebug.h:	notably replace GetWindowFromPort(
	* macosx/tkMacOSXDialog.c:	TkMacOSXGetDrawablePort()) idiom by new
	* macosx/tkMacOSXDraw.c:	TkMacOSXDrawableWindow() and change
	* macosx/tkMacOSXKeyEvent.c:	TkMacOSXSetColorInPort() to take a port
	* macosx/tkMacOSXMenu.c:	argument.
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXInt.h:			factor out macros, declarations
	* macosx/tkMacOSXPrivate.h (new):	and prototypes that are purely
	internal and private to the 'macosx' sources into a new internal header
	file that does _not_ get installed into Tk.framework/PrivateHeaders.

	* macosx/tkMacOSXButton.c:		#include new tkMacOSXPrivate.h
	* macosx/tkMacOSXCarbonEvents.c:	instead of tkMacOSXInt.h.
	* macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXColor.c:
	* macosx/tkMacOSXCursor.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* macosx/ttkMacOSXTheme.c:
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.13 2007/04/23 21:24:33 das Exp $
@


1.13
log
@	* macosx/tkMacOSXCarbonEvents.c: add window event target carbon event
	* macosx/tkMacOSXEvent.c:	 handler for all kEventClassWindow and
	* macosx/tkMacOSXEvent.h:	 kEventClassMouse events;
	* macosx/tkMacOSXNotify.c:	 move all remaining events except for
	* macosx/tkMacOSXWindowEvent.c:	 kEventClassKeyboard from dispatcher to
	application event handler; pass event handler callRef downstream; fix
	debug event tracing; process all tcl event types in carbon event timer;
	delay carbon event timer first fire; add TkMacOSXTrackingLoop() to mark
	enter/exit of event tracking loop during which all tcl events but only
	carbon update events should be processed by the timer (replaces various
	calls to Tcl_SetServiceMode()); rename TkMacOSXReceiveAndProcessEvent()
	to TkMacOSXReceiveAndDispatchEvent(), move it from tkMacOSXEvent.c to
	tkMacOSXCarbonEvents.c and modify it to dequeue only update events
	during a tracking loop; add TkMacOSXRunTclEventLoop() to standardize
	the various ways in use to run the tcl event loop; add handling of
	kEventClassAppearance events (for ScrollBarVariantChanged event).

	* macosx/tkMacOSXDialog.c:	use new TkMacOSXTrackingLoop() around
	* macosx/tkMacOSXEvent.c:	blocking API that puts up modal dialogs
	* macosx/tkMacOSXMenu.c:	or when entering/exiting menu/control
	* macosx/tkMacOSXMouseEvent.c:	tracking, window dragging and other
	* macosx/tkMacOSXScale.c:	mouse tracking loops.
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c:	use new TkMacOSXRunTclEventLoop()
	* macosx/tkMacOSXScale.c:	instead of Tcl_DoOneEvent(),
	* macosx/tkMacOSXScrlbr.c:	Tcl_ServiceAll(), TclServiceIdle()
	* macosx/tkMacOSXWindowEvent.c:	and Tcl_GlobalEval("update idletasks").

	* macosx/tkMacOSXColor.c: make available as Tk system colors all
	* macosx/tkMacOSXPort.h:  appearance manager brushes, text colors and
	backgrounds with new and legacy names, as well as the fully transparent
	color "systemTransparent"; add TkMacOSXSetColorIn{Port,Context}() to
	directly set an X pixel color value in the current QD port resp. the
	given CG context without requiring passage through rgb representation
	(lossy for most system colors); modernize/remove Classic-era code;
	replace crufty strcmp() elseifs by Tcl_GetIndexFromObjStruct().

	* macosx/tkMacOSXButton.c:	use new TkMacOSXSetColorInPort()
	* macosx/tkMacOSXDraw.c:	instead of setting rgb color directly
	* macosx/tkMacOSXMenubutton.c:	to allow for non-rgb system colors.

	* macosx/tkMacOSXCursor.c: implement "none" cursor as on other
	platforms [Patch 1615427]; add all missing appearance manager cursors.

	* macosx/tkMacOSXDefault.h: set SELECT_FG_COLORs to None to match aqua
	L&F; use standard system color names; use new 'menu' system font;
	correct default scrollbar width.

	* macosx/tkMacOSXDraw.c:	standardize initialization, use and
	* macosx/tkMacOSXInt.h:		emptying of various static temp rgns
	* macosx/tkMacOSXRegion.c:	onto two global RgnHandles; in debug
	* macosx/tkMacOSXSubwindows.c:	builds, verify emptiness of these temp
	* macosx/tkMacOSXWindowEvent.c:	rgns before use.

	* macosx/tkMacOSXDraw.c: add TkMacOSX{Setup,Restore}DrawingContext() to
	* macosx/tkMacOSXInt.h:  abstract common setup & teardown of drawing
	environment (for both CG and QD); save/restore QD theme drawing state;
	handle GC clip region; add TkpClipDrawableToRect() to allow clipped
	drawing into drawable regardless of GC used; use new system color
	"systemWindowHeaderBackground" to setup background in themed toplevels;
	correct implementation of TkMacOSXMakeStippleMap().

	* macosx/tkMacOSXEntry.c:  use new TkMacOSXSetupDrawingContext() and
	* macosx/tkMacOSXFont.c:   TkMacOSXRestoreDrawingContext() instead of
	* macosx/ttkMacOSXTheme.c: various setup/teardown procs like
	TkMacOSX{SetUp,Release}CGContext(), TkMacOSXQuarz{Start,End}Draw(),
	TkMacOSXSetUpGraphicsPort() etc.

	* macosx/tkMacOSXEmbed.c: add CG context and drawable clip rgn fields
	* macosx/tkMacOSXInt.h:   to MacDrawable struct.
	* macosx/tkMacOSXSubwindows.c:

	* macosx/tkMacOSXDialog.c: make -parent option of tk_getOpenFile et al.
	use the sheet version of NavServices dialogs; ensure native parent win
	exists before using StandardSheet API for tk_messageBox [Bug 1677611];
	force sheets to behave like app-modal dialogs via WindowModality() API;
	use more modern ColorPicker API.

	* macosx/tkAboutDlg.r: use themed movable modal dialog, fix (c) year.

	* macosx/tkMacOSXEntry.c:  take xOff/yOff of MacDrawable into account
	* macosx/ttkMacOSXTheme.c: when computing locations/bounds to ensure
	correct posititioning when not drawing into intermediate pixmap.

	* macosx/tkMacOSXFont.c: use appearance manager API to map system font
	* macosx/tkMacOSXFont.h: names to TkFonts; add "menu" system font for
	menu item text drawing from MDEF; always draw with CG; remove QD
	dependent stippling algorithm; move most header declarations into the
	source file (as they were not used anywhere else).

	* macosx/tkMacOSXMenu.c:		 large-scale rewrite of custom
	* macosx/tkMacOSXMenu.r (removed):	 MDEF and related code that
	* macosx/Wish.xcode/project.pbxproj:	 restores many longtime-MIA
	* macosx/Wish.xcodeproj/project.pbxproj: features to working order
	* unix/Makefile.in:			 (e.g. images, custom colors &
	fonts in menus etc); implement compound menu items; use Appearance Mgr
	and ThemeText APIs to mimic native MDEF as closely as possible when
	default "menu" system font is used; remove now obsolete SICN drawing
	code and resources.

	* macosx/tkMacOSXCarbonEvents.c: handle additional menu carbon events
	* macosx/tkMacOSXEvent.c:	 in order to support <<MenuSelect>> in
	* macosx/tkMacOSXMenu.c:	 the menubar and in menus that are not
	* macosx/tkMacOSXMenus.c:	 using the custom MDEF [Bug 1620826];
	fix early and missing clearing of current Tk active menu entry; fix
	extraneous sending of <<MenuSelect>> during active menu entry clearing.

	* macosx/tkMacOSXMouseEvent.c: add support for async window dragging by
	the window server; set the corresponding window attribute by default.

	* macosx/tkMacOSXMouseEvent.c: rationalized handling order of
	non-mousedown events; add TkMacOSXModifierState() to retrieve the
	current key modifiers in carbon format.

	* macosx/tkMacOSXScrlbr.c: use appearance manager API to retrieve
	scrollbar component metrics; add awareness of multiple possibilites for
	scrollbar arrow position in aqua and handle user changes to arrow
	position pref; handle difference in metrics of small & large scrollbar
	variants; handle aqua "jump to here" scrollbar behaviour; correct
	computation of scroll view size and position; enforce min scrollbar
	height to avoid scrollbar component overlap; erase scrollbar area
	outside of standard width; remove broken auto-adjust code; account for
	window class when leaving space for grow box; remove code to manually
	draw grow box; use modern API for thumb scroll proc; replace
	HiliteControl() by modern API; replace control mgr constants with
	appearance mgr equivalents.

	* macosx/tkMacOSXSubwindows.c: use SetWindowBounds() API instead of
	SizeWindow(); invalidate clip regions after X{Map,Unmap}Window as fix
	for [Bug 940117] made them dependent on mapping state; remove unneeded
	calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD port;
	use native-endian pixmap on intel; remove obsolete pixmap pix locking.

	* macosx/tkMacOSXWindowEvent.c: handle only the first of a batch of
	kEventAppAvailableWindowBoundsChanged events sent per transaction;
	handle kEventWindowBoundsChanged event to support live window resizing
	and centralized sending of location/size changed ConfigureNotify
	events; ensure HIGrowBox is redrawn after bounds change; constrain
	window after dragging to ensure titlebar is not inacessible
	offscreen or under dock/menubar; handle kEventWindowGetRegion and
	kEventWindowDrawContent for transparent windows to mark resp. paint
	content region as transparent; handle kEventWindowConstrain for
	fullscreen windows to ensure bounds match new screen size; enter/exit
	fullscreen UIMode upon activation/deactivation of fullscreen window.

	* macosx/tkMacOSXWm.c: use live-resize and async-drag carbon window
	* macosx/tkMacOSXWm.h: attributes for toplevels by default; implement
	new [wm attributes] -topmost, -transparent and -fullscreen; refactor
	WmAttributesCmd() parallelling the tkUnixWm.c implementation, use thus
	factored proc to set proxy icon from [wm iconbitmap]; dynamically
	determine default values for toplevel min and max sizes (similar to
	tkWinWm.c impl): min sizes depend on window class & attributes to
	ensure visibility of all titlebar widgets and grow box, max sizes
	depend on maximal window bounds for all active displays; factor out
	code that puts into effect changes to master or override_redirect; use
	RepositionWindow() API to determine staggered initial window bounds;
	correct resize limit calculations, handle gridding and use modern
	resize API in TkMacOSXGrowToplevel(); remove sending of ConfigureNotify
	after resize or zoom (now handled by BoundsChanged handler); correct
	composite carbon window attribute handling, remove currently unusable
	attributes and add new attributes in [tk::unsupported::MacWindowStyle];
	ensure validity of window class and attributes before use; apply
	changes to window class when handling carbon window attribute changes
	(if HIWindowChangeClass() API available); add debug build warning
	message when deprecated window style is used instead of window class;
	use transparent HIGrowBox for resizable windows; avoid unnecessary
	calls to window structure width API; use tcl time API in TkpGetMS();
	add TkMacOSXEnterExitFullscreen() to enter/exit UIMode with dock and
	menubar hidden; restrict wmTracing output to debug builds; remove
	unneeded calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD
	port; workaround GetWindowStructureWidths() Carbon bug (bogus results
	for never-mapped floating windows).

	* macosx/tkMacOSXXStubs.c (TkMacOSXDisplayChanged): add maximal window
	bounds field to Screen record (in ext_data), computed as the union of
	available window positioning bounds of all graphics devices (displays).

	* macosx/tkMacOSXBitmap.c: fix macRoman encoding leak.
	* macosx/tkMacOSXCursor.c:

	* macosx/tkMacOSXDebug.c (TkMacOSXCarbonEventToAscii): use static
	* macosx/tkMacOSXDebug.h: buffer to simplify callers; const fixes.

	* macosx/tkMacOSXBitmap.c: use more efficient QDSwapPort() instead of
	* macosx/tkMacOSXButton.c: GetPort()/SetPort()/GetGWorld()/SetGWorld().
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXColor.c: use kHIToolboxVersionNumber for runtime OS
	* macosx/tkMacOSXEntry.c: version check rather than Gestalt() etc.
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c: remove obsolete and now incorrect
	* macosx/tkMacOSXInt.h:  tkMenuCascadeRgn clipping code.
	* macosx/tkMacOSXMenu.c:

	* macosx/tkMacOSXHLEvents.c: replace Tcl_GlobalEval() resp. Tcl_Eval()
	* macosx/tkMacOSXScrlbr.c:   by Tcl_EvalEx().
	* macosx/tkMacOSXInit.c:

	* macosx/tkMacOSXInit.c (TkpInit): reorder initialization steps.

	* macosx/tkMacOSXKeyEvent.c: remove pre-10.2 support.

	* macosx/tkMacOSXMenus.c: remove now useless call to
	TkMacOSXHandleTearoffMenu(); use \x.. quoting for non-latin1 macroman
	literar chars to allow file to be edited as utf-8.

	* macosx/tkMacOSXScale.c: replace TrackControl() by modern
	* macosx/tkMacOSXScrlbr.c: HandleControlClick() API (using new
	TkMacOSXModifierState()).

	* macosx/tkMacOSXInt.h:		move all constant #defines needed to
	* macosx/tkMacOSXColor.c:	support building on older OS X releases
	* macosx/tkMacOSXEvent.h:	to a central location in tkMacOSXInt.h.
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/ttkMacOSXTheme.c:

	* macosx/tkMacOSXInt.h:		 add ChkErr() macro to factor out
	* macosx/tkMacOSXButton.c:	 Carbon OSStatus return value checking
	* macosx/tkMacOSXCarbonEvents.c: and TkMacOSXDbgMsg() macro to factour
	* macosx/tkMacOSXClipboard.c:	 out debug message output; use these
	* macosx/tkMacOSXColor.c:	 macros to replace #ifdef TK_MAC_DEBUG
	* macosx/tkMacOSXCursor.c:	 blocks & direct printing to stderr,
	* macosx/tkMacOSXDebug.c:	 and to do additional OSStatus return
	* macosx/tkMacOSXDialog.c:	 checking, and to standardize OSStatus
	* macosx/tkMacOSXDraw.c:	 usage.
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXSend.c:	remove duplicate/unused declarations
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXDebug.c:	const fixes.
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/Wish-Info.plist.in: add tcl document extensions/mime types and
	LSMinimumSystemVersion, LSRequiresCarbon & NSAppleScriptEnabled keys.

	* macosx/Wish-Common.xcconfig: add Wish's Info.plist as __info_plist
	section to tktest; enable more warnings.

	* macosx/Wish.xcodeproj/project.pbxproj: add 'DebugMemCompile' build
	configuration that calls configure with --enable-symbols=all; disable
	configure check for __attribute__((__visibility__("hidden"))) in Debug
	configuration to restore availability of ZeroLink.

	* macosx/Wish-Common.xcconfig:	fix whitespace.
	* macosx/Wish-Debug.xcconfig:
	* macosx/Wish-Release.xcconfig:
	* macosx/tkMacOSXAETE.r:
	* macosx/tkMacOSXConfig.c:
	* macosx/tkMacOSXCursors.r:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXSend.c:
	* macosx/ttkMacOSXTheme.c:
	* macosx/tkMacOSXXCursors.r:
	* macosx/README:

	* macosx/GNUmakefile:		fix/add copyright and license refs.
	* macosx/Tk-Info.plist.in:
	* macosx/Wish-Info.plist.in:
	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.xcodeproj/project.pbxproj:
	* macosx/tkMacOSX.h:
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.12 2006/05/12 18:18:36 das Exp $
d17 1
a17 1
#include "tkMacOSXInt.h"
@


1.13.2.1
log
@merge updates from HEAD
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id$
d17 1
a17 1
#include "tkMacOSXPrivate.h"
@


1.12
log
@fix whitespace, copyright
@
text
@d1 1
a1 1
/* 
d4 2
a5 2
 *        Implements high level event support for the Macintosh.  Currently, 
 *        the only event that really does anything is the Quit event.
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.11 2006/04/11 10:21:28 das Exp $
d23 1
a23 1
 
d25 4
a28 4
    Tcl_Event header;           /* Information that is standard for
                                 * all events. */
    Tcl_Interp *interp;         /* Interp that was passed to the
                                 * Quit AppleEvent */
d52 1
a52 1
static OSErr FSRefToDString(const FSRef *fsref, Tcl_DString *ds);
d59 2
a60 2
 *        Initilize the Apple Events on the Macintosh.  This registers the
 *        core event handlers.
d63 1
a63 1
 *        None.
d66 1
a66 1
 *        None.
d71 1
a71 1
void 
d73 1
a73 1
    Tcl_Interp *interp)                /* Interp to handle basic events. */
d75 2
a76 4
    OSErr err;
    AEEventHandlerUPP        OappHandlerUPP, RappHandlerUPP, OdocHandlerUPP,
        PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP,
        PrefsHandlerUPP;
d80 1
a80 1
        initialized = TRUE;
d86 1
a86 1
	err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
d90 1
a90 1
	err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
d94 1
a94 1
	err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication,
d98 1
a98 1
	err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
d102 1
a102 1
	err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
d106 1
a106 1
	err = AEInstallEventHandler(kCoreEventClass, kAEShowPreferences,
d111 1
a111 1
	    err = AEInstallEventHandler(kAEMiscStandards, kAEDoScript,
d122 1
a122 1
 *        Dispatch incomming highlevel events.
d125 1
a125 1
 *        None.
d128 1
a128 1
 *        Depends on the incoming event.
d143 1
a143 1
 * QuitHandler, OappHandler, etc. --
d145 1
a145 1
 *        These are the core Apple event handlers.
d148 1
a148 1
 *        None.
d151 1
a151 1
 *        None.
d155 3
a157 2
static OSErr
QuitHandler (
d164 1
a164 1
    
d168 1
a168 1
	 * to call ExitToShell in an Apple Event Handler.  We put this at the head
d172 1
a172 1
	
d176 1
a176 1
	 
d182 18
a199 2
static OSErr 
OappHandler (
d214 18
a231 2
static OSErr 
RappHandler (
d239 2
a240 2
    OSStatus status = SetFrontProcess(&thePSN);
    
d245 1
a245 1
    return status;
d248 19
a266 3
/* Called when the user selects 'Preferences...' in MacOS X */
static OSErr 
PrefsHandler (
d281 18
a298 2
static OSErr 
OdocHandler (
d306 1
a306 1
    OSErr err;
d321 3
a323 3
    if ((interp == NULL) || 
            (Tcl_GetCommandInfo(interp, "::tk::mac::OpenDocument", &dummy)) == 0) {
            return noErr;
d325 1
a325 1
    
d331 2
a332 2
    err = AEGetParamDesc(event, keyDirectObject,
            typeAEList, &fileSpecList);
d334 1
a334 1
        return noErr;
d339 1
a339 1
        return noErr;
d342 1
a342 1
    err = AECountItems(&fileSpecList, &count);
d344 1
a344 1
        return noErr;
d350 11
a360 11
        err = AEGetNthPtr(&fileSpecList, index, typeFSRef,
                &keyword, &type, (Ptr) &file, sizeof(FSRef), &actual);
        if ( err != noErr ) {
            continue;
        }

        err = FSRefToDString(&file, &pathName);
        if (err == noErr) {
            Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
            Tcl_DStringFree(&pathName);
        }
d362 3
a364 2
    
    Tcl_GlobalEval(interp, Tcl_DStringValue(&command));
d370 18
a387 2
static OSErr 
PrintHandler (
d395 1
a395 1
    OSErr err;
d410 3
a412 3
    if ((interp == NULL) || 
            (Tcl_GetCommandInfo(interp, "::tk::mac::PrintDocument", &dummy)) == 0) {
            return noErr;
d414 1
a414 1
    
d420 2
a421 2
    err = AEGetParamDesc(event, keyDirectObject,
            typeAEList, &fileSpecList);
d423 1
a423 1
        return noErr;
d426 1
a426 1
    err = MissedAnyParameters(event);
d428 1
a428 1
        return noErr;
d431 1
a431 1
    err = AECountItems(&fileSpecList, &count);
d433 1
a433 1
        return noErr;
d439 11
a449 11
        err = AEGetNthPtr(&fileSpecList, index, typeFSRef,
                &keyword, &type, (Ptr) &file, sizeof(FSRef), &actual);
        if ( err != noErr ) {
            continue;
        }

        err = FSRefToDString(&file, &pathName);
        if (err == noErr) {
            Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
            Tcl_DStringFree(&pathName);
        }
d451 3
a453 2
    
    Tcl_GlobalEval(interp, Tcl_DStringValue(&command));
d464 1
a464 1
 *        This handler process the script event.  
d467 1
a467 1
 *        Schedules the given event to be processed.
d470 1
a470 1
 *        None.
d475 2
a476 2
static OSErr 
ScriptHandler (
d481 1
a481 1
    OSErr theErr;
d493 1
a493 1
            &theDesc);
d495 4
a498 3
        sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d", theErr);
        theErr = AEPutParamPtr(reply, keyErrorString, typeChar, errString,
                strlen(errString));
d500 4
a503 4
        sprintf(errString, "AEDoScriptHandler: extra parameters");
        AEPutParamPtr(reply, keyErrorString, typeChar, errString,
                strlen(errString));
        theErr = -1771;
d505 63
a567 62
        if (theDesc.descriptorType == (DescType)typeChar) {
            Tcl_DString encodedText;
            short i;
            Size  size;
            char  * data;
            
            size = AEGetDescDataSize(&theDesc);
            
            data = (char *)ckalloc(size + 1);
            if ( !data ) {
                theErr = -1771;
            }
            else {
                   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_GlobalEval(interp, Tcl_DStringValue(&encodedText));
            Tcl_DStringFree(&encodedText);
        } else if (theDesc.descriptorType == (DescType)typeAlias) {
            Boolean dummy;
            FSRef file;
            AliasPtr    alias;
            Size        theSize;

            theSize = AEGetDescDataSize(&theDesc);
            alias = (AliasPtr) ckalloc(theSize);
            if (alias) {
                AEGetDescData (&theDesc, alias, theSize);
            
                theErr = FSResolveAlias(NULL, &alias,
                        &file, &dummy);
                ckfree((char*)alias);
            } else {
                theErr = memFullErr;
            }
            if (theErr == noErr) {
                Tcl_DString scriptName;
                theErr = FSRefToDString(&file, &scriptName);
                if (theErr == noErr) {
                    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: invalid script type '%-4.4s', must be 'alis' or 'TEXT'",
                    (char *)(&theDesc.descriptorType));
            AEPutParamPtr(reply, keyErrorString, typeChar,
                    errString, strlen(errString));
            theErr = -1770;
        }
d574 11
a584 11
        if (tclErr == TCL_OK)  {
            AEPutParamPtr(reply, keyDirectObject, typeChar,
                Tcl_GetStringResult(interp),
                strlen(Tcl_GetStringResult(interp)));
        } else {
            AEPutParamPtr(reply, keyErrorString, typeChar,
                Tcl_GetStringResult(interp),
                strlen(Tcl_GetStringResult(interp)));
            AEPutParamPtr(reply, keyErrorNumber, typeInteger,
                (Ptr) &tclErr, sizeof(int));
        }
d586 1
a586 1
        
d597 2
a598 2
 *      This proc tries to kill the shell by running exit,
 *      called from an event scheduled by the "Quit" AppleEvent handler.
d601 1
a601 1
 *        Runs the "exit" command which might kill the shell.
d604 1
a604 1
 *        None.
d609 1
a609 1
static int 
d612 1
a612 1
    int flags) 
d629 1
a629 1
 *        Checks to see if parameters are still left in the event.  
d632 1
a632 1
 *        True or false.
d635 1
a635 1
 *        None.
d639 2
a640 2
 
static int 
d646 4
a649 1
   OSErr err;
a650 3
   err = AEGetAttributePtr(theEvent, keyMissedKeywordAttr, typeWildCard, 
                   &returnedType, NULL, 0, &actualSize);
   
d659 1
a659 1
 *      Get a POSIX path from an FSRef.
d662 1
a662 1
 *      In the parameter ds.
d665 1
a665 1
 *      None.
d670 1
a670 1
static OSErr
d676 1
a676 1
    OSErr err;
d678 1
a678 1
    err = FSRefMakePath(fsref, fileName, sizeof(fileName));
d680 1
a680 1
        Tcl_ExternalToUtfDString(NULL, (char*) fileName, -1, ds);
@


1.11
log
@	* macosx/tkMacOSXHLEvents.c:    call ::tk::mac::* procs for all
	* macosx/tkMacOSXWindowEvent.c: registered appleevents [FR 1105284],
	implement print applevent handling, style/whitespace cleanup.
@
text
@d9 1
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.10 2006/03/24 14:58:01 das Exp $
a115 1

@


1.10
log
@	* generic/tkTextDisp.c:   moved #ifdef MAC_OSX_TK code added by
	* macosx/tkMacOSXColor.c: Patch #638966 into platform specific
	* macosx/tkMacOSXInt.h:   files.

	* macosx/tkMacOSX.h:             cleaned up & rationalized order of
	* macosx/tkMacOSXBitmap.c:       #includes of tk and carbon headers.
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXCarbonEvents.c:
	* macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXColor.c:
	* macosx/tkMacOSXConfig.c:
	* macosx/tkMacOSXCursor.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXFont.h:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXWm.h:
	* macosx/tkMacOSXXStubs.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.9 2005/08/09 07:39:20 das Exp $
d20 1
a20 1
 * uses to schedule the tkReallyKillMe function.
d24 1
a24 1
    Tcl_Event header;                /* Information that is standard for
d26 1
a26 1
    Tcl_Interp *interp;                /* Interp that was passed to the
d34 18
a51 11
static OSErr QuitHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);
static OSErr OappHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);
static OSErr RappHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);
static OSErr OdocHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);
static OSErr PrintHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);
static OSErr ScriptHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);
static OSErr PrefsHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);

static int MissedAnyParameters _ANSI_ARGS_((const AppleEvent *theEvent));
static int ReallyKillMe _ANSI_ARGS_((Tcl_Event *eventPtr, int flags));
static OSErr FSRefToDString _ANSI_ARGS_((const FSRef *fsref, Tcl_DString *ds));
d78 37
a115 31
    /*
     * Install event handlers for the core apple events.
     */
    QuitHandlerUPP = NewAEEventHandlerUPP(QuitHandler);
    err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
            QuitHandlerUPP, (long) interp, false);

    OappHandlerUPP = NewAEEventHandlerUPP(OappHandler);
    err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
            OappHandlerUPP, (long) interp, false);

    RappHandlerUPP = NewAEEventHandlerUPP(RappHandler);
    err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication,
            RappHandlerUPP, (long) interp, false);

    OdocHandlerUPP = NewAEEventHandlerUPP(OdocHandler);
    err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
            OdocHandlerUPP, (long) interp, false);

    PrintHandlerUPP = NewAEEventHandlerUPP(PrintHandler);
    err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
            PrintHandlerUPP, (long) interp, false);

    PrefsHandlerUPP = NewAEEventHandlerUPP(PrefsHandler);
    err = AEInstallEventHandler(kCoreEventClass, kAEShowPreferences,
            PrefsHandlerUPP, (long) interp, false);

    if (interp != NULL) {
        ScriptHandlerUPP = NewAEEventHandlerUPP(ScriptHandler);
        err = AEInstallEventHandler(kAEMiscStandards, kAEDoScript,
            ScriptHandlerUPP, (long) interp, false);
d136 2
a137 1
TkMacOSXDoHLEvent(EventRecord *theEvent)
d147 1
a147 2
 *        These are the core Apple event handlers.  Only the Quit event does
 *        anything interesting.
d157 5
a161 1
OSErr QuitHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
d166 14
a179 13
    /*
     * Call the exit command from the event loop, since you are not supposed
     * to call ExitToShell in an Apple Event Handler.  We put this at the head
     * of Tcl's event queue because this message usually comes when the Mac is
     * shutting down, and we want to kill the shell as quickly as possible.
     */
    
    eventPtr = (KillEvent *) ckalloc(sizeof(KillEvent));
    eventPtr->header.proc = ReallyKillMe;
    eventPtr->interp = interp;
     
    Tcl_QueueEvent((Tcl_Event *) eventPtr, TCL_QUEUE_HEAD);

d182 1
a182 1

d184 4
a187 1
OappHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
d189 7
d198 1
a198 1

d200 4
a203 1
RappHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
d205 2
d208 7
a214 1
    return SetFrontProcess(&thePSN);
d216 1
a216 1

d219 4
a222 1
PrefsHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
a225 4
    /*
     * Don't bother if we don't have an interp or
     * the show preferences procedure doesn't exist.
     */
d227 3
a229 3
    if ((interp == NULL) || 
            (Tcl_GetCommandInfo(interp, "::tk::mac::ShowPreferences", &dummy)) == 0) {
            return noErr;
a230 1
    Tcl_GlobalEval(interp, "::tk::mac::ShowPreferences");
d233 1
a233 1

d235 4
a238 1
OdocHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
d305 1
a305 1

d307 4
a310 1
PrintHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
d312 63
d395 4
a398 1
ScriptHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
d527 3
a529 1
ReallyKillMe(Tcl_Event *eventPtr, int flags) 
d532 5
a536 2
    if (interp != NULL) {
        Tcl_GlobalEval(interp, "exit");
a537 1
    
d588 3
a590 1
FSRefToDString(const FSRef *fsref, Tcl_DString *ds)
@


1.9
log
@	* macosx/tkMacOSXCarbonEvents.c (AppEventHandlerProc): handle carbon
	events sent directly to application event target via the general
	TkMacOSXProcessEvent() in the same way as events posted to the event
	loop. Moved existing app event handlers to tkMacOSXWindowEvent.c.
	(TkMacOSXInitCarbonEvents): register our application event handler for
	kEventWindowExpanded events to deal with uncollapsing from the dock.

	* macosx/tkMacOSXEvent.h: made TkMacOSXProcessEvent() non-static, added
	* macosx/tkMacOSXEvent.c: new interp field to TkMacOSXEvent struct for
	                          use by app event handler.

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): retrieve
	current window, partCode, modifiers and local cursor position from
	carbon mouse event if possible. Use new static GenerateButtonEvent()
	taking a MouseEventData struct instead of TkGenerateButtonEvent() to
	avoid recomputing already known values. Move process activation on
	MouseDown into BringWindowForward() to allow clicking on window titlebar
	widgets without activating process. Move code dealing with clicks in
	window titelbar into separate function HandleWindowTitlebarMouseDown()
	to avoid code duplication. Avoid repeated calls to TkMacOSXGetXWindow()
	by storing result in MouseEventData struct.
	(TkMacOSXButtonKeyState, XQueryPointer): try to get button and modifier
	state from currently processed carbon event (to avoid unnecessary IPC
	with the window server), otherwise use modern carbon API to get this
	info instead of Button() and GetKeys(); only retrieve info caller asks
	for (via non-NULL ptr passed to XQueryPointer).
	(ButtonModifiers2State): new static function converting carbon button
	and modifier state into tk state, allows detection of more than 3 mouse
	buttons (tk supports up to 5) and of NumLock and Fn modifier keys
	(NumLock is mapped to Mod3 and Fn to Mod4).

	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessApplicationEvent): handle
	kEventWindowExpanded event to deal with window uncollapsing from the
	dock by generating tk Map event, handle kEventAppHidden and
	kEventAppShown events (moved here from tkMacOSXCarbonEvents.c).

	* macosx/tkMacOSXSubwindows.c (XUnmapWindow): only hide window when
	it is not iconified to avoid window flashing on collapse.

	* macosx/tkMacOSXWm.c: replaced Tk_DoWhenIdle() by Tcl_DoWhenIdle().
	(TkMacOSXZoomToplevel): remove call to TrackBox(), now done in
	HandleWindowTitlebarMouseDown() in tkMacOSXMouseEvent.c.
	(TkpWmSetState): avoid window flashing on collapse by unmapping after
	calling CollapseWindow(); only uncollapse window if it is collapsed.

	* generic/tkInt.decls: changed TkMacOSXZoomToplevel() signature.
	* generic/tkIntPlatDecls.h:

	* macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): only call
	GetMenuItemCommandID() on KeyDown or KeyRepeat events.

	* macosx/tkMacOSXMenu.c (ReconfigureMacintoshMenu): remove call to
	obsolete AppendResMenu() API.

	* macosx/tkMacOSXKeyEvent.c: replaced all direct uses of expensive
	* macosx/tkMacOSXMenu.c:     GetMouse() and TkMacOSXButtonKeyState()
	* macosx/tkMacOSXMenus.c:    APIs by calls to XQueryPointer()
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c:   replaced use of FrontNonFloatingWindow()
	* macosx/tkMacOSXKeyEvent.c: by ActiveNonFloatingWindow() as
	* macosx/tkMacOSXMenu.c:     recommended by Carbon docs.
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c: fixed warnings
	* macosx/tkMacOSXTest.c:

	* macosx/tkMacOSXCarbonEvents.c: added CVS Id line to file header.
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.h:

	* macosx/tkMacOSXInt.h: declare macosx internal procs as MODULE_SCOPE.
	* macosx/tkMacOSXCarbonEvents.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXWindowEvent.c

	* library/bgerror.tcl: sync with core-8-4-branch changes of 2005-07-28.
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXMouseEvent.c:

	* generic/tkFrame.c:   sync with core-8-4-branch changes of 2005-07-27.
	* generic/tkIntDecls.h:
	* generic/tkStubInit.c:
	* generic/tkFrame.c:
	* win/tkWinDraw.c:
	* unix/tkUnixDraw.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXSubwindows.c:

	* macosx/tkMacOSXButton.c: sync with core-8-4-branch.
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXScale.c:

	* library/demos/menu.tcl: removed errant '}'.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.8 2005/05/14 20:48:15 das Exp $
a15 1
#include "tkMacOSXPort.h"
a17 2
#include <Carbon/Carbon.h>

@


1.8
log
@	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXNotify.c: introduction of new tcl notifier based on
	CFRunLoop allows replacement of the custom TkAqua notifier by a
	standard tcl event source. Removes requirement of threaded tcl core
	for TkAqua, allows to stub-link TkAqua against Tcl by removing use of
	the unstubbed TclInitNotifier & TclFinalizeNotifier. [Tcl Patch 1202052]

	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.pbproj/project.pbxproj: stub-link TkAqua: build with
	USE_TCL_STUBS and link against libtclstub instead of Tcl.framework,
	unexport libtclstub symbols from Tk to avoid duplicate symbol warnings
	when linking with both Tcl and Tk, fixes for gcc4.0 warnings.

	* macosx/Wish.xcode/project.pbxproj: sync with Wish.pbproj changes
	since 2004-11-19.
	NOTE: to use this project, need to uncomment the tclConfig.h settings
	at the top of tcl/unix/configure.in, autoconf and rebuild tcl !

	* macosx/tkMacOSXBitmap.c:
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c: fixed gcc 4.0 warnings.

	* unix/tcl.m4: sync with tcl
	* unix/configure: autoconf-2.59
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.7 2004/02/16 00:19:42 wolfsuit Exp $
d74 1
a74 1
        
@


1.7
log
@Fix a bug in tk_getOpenFile - files with no types are rejected when they would
pass in Mac OS Classic.
Add the tkMacOSXCarbonEvents.c - just a skeleton right now.
A bunch of formatting nits fixed.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id$
d485 1
a485 1
        Tcl_ExternalToUtfDString(NULL, fileName, -1, ds);
@


1.6
log
@2003-03-11  Jim Ingham  <jingham@@apple.com>

        * macosx/tkMacOSXMenu.c (EventuallyInvokeMenu): New function,
        used to invoke menu commands at idle time.
        (TkMacOSXDispatchMenuEvent): Don't immediately dispatch menu
        commands, wait till the idle loop to do so.  This is more like
        what is done on Windows, and avoids the crash from destroying
        a menu in it's command.

        * macosx/tkMacOSXHLEvents.c (ReallyKillMe): Don't force the shell
        to exit.  According to the OS X HI guidelines, it should be
        possible to cancel an attempt to quit, and if we force the kill,
        here, it would not be possible to implement this.
@
text
@d332 1
a332 1
                   for (i=0; i<size; i++)
d335 2
a336 1
                   AEReplaceDescData(theDesc.descriptorType,data,size+1,&theDesc);
@


1.5
log
@	* macosx/tkMacOSXHLEvents.c: fixed conversion of apple event
	parameters to posix style path names.
	[Bug #621672] (steffen, Benjamin Riefenstahl)
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.4 2003/02/25 16:09:25 das Exp $
d407 2
a408 4
 *        This proc tries to kill the shell by running exit, and if that 
 *      has not succeeded (e.g. because someone has renamed the exit 
 *      command), calls Tcl_Exit to really kill the shell.  Called from 
 *      an event scheduled by the "Quit" AppleEvent handler.
d411 1
a411 1
 *        Kills the shell.
a425 1
    Tcl_Exit(0);
@


1.5.2.1
log
@	backport of Mac OS X specific changes on trunk since 8.4.2:

	* macosx/tkMacOSXClipboard.c (TkSelGetSelection): Convert
	'\r' to '\n' on the way into Tcl. (ingham)

	* macosx/tkMacOSXMenu.c (EventuallyInvokeMenu): New function,
	used to invoke menu commands at idle time.
	(TkMacOSXDispatchMenuEvent): Don't immediately dispatch menu
	commands, wait till the idle loop to do so.  This is more like
	what is done on Windows, and avoids the crash from destroying
	a menu in it's command. (ingham)

	* macosx/tkMacOSXHLEvents.c (ReallyKillMe): Don't force the shell
	to exit.  According to the OS X HI guidelines, it should be
	possible to cancel an attempt to quit, and if we force the kill,
	here, it would not be possible to implement this. (ingham)

	* macosx/tkMacOSXApplication.r (removed):
	* macosx/tkMacOSXLibrary.r (removed):
	* macosx/tkMacOSXResource.r (removed):
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkAboutDlg.r: updated copyrights, cleaned up about box,
	removed obsolete unused resource files. (steffen)
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.5 2003/02/25 16:11:22 das Exp $
d407 4
a410 2
 *      This proc tries to kill the shell by running exit,
 *      called from an event scheduled by the "Quit" AppleEvent handler.
d413 1
a413 1
 *        Runs the "exit" command which might kill the shell.
d428 1
@


1.5.2.2
log
@Backport Mac OS X specific fixes from TOT. See ChangeLog for details.

In tk_getOpenFile filters, handle the case where you have a Macintosh
file type and the files have no filetype.

Fix various formatting nits.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id$
d332 1
a332 1
                   for (i = 0; i < size; i++)
d335 1
a335 2
                   AEReplaceDescData(theDesc.descriptorType, data, 
		           size + 1, &theDesc);
@


1.5.2.3
log
@Get the "Command-H" -> hide binding working.  Also remove the spurious
Quit menu item from the File command.
@
text
@d48 1
a48 52

OSStatus ApplicationCarbonEventsHandler (EventHandlerCallRef inHandlerCallRef, 
        EventRef inEvent, 
        void *inUserData);
OSStatus ApplicationCarbonEventsHandler (EventHandlerCallRef inHandlerCallRef, 
        EventRef inEvent, 
        void *inUserData)
{
    Tcl_CmdInfo dummy;
    Tcl_Interp *interp = (Tcl_Interp *) inUserData;
    
    /* 
     * This is a bit of a hack.  We get "show" events both when we come back
     * from being hidden, and whenever we are activated.  I only want to run the
     * "show" proc when we have been hidden already, not as a substitute for
     * <Activate>.  So I use this toggle...
     */
     
    static int toggleHide = 0;
    
    switch(GetEventKind (inEvent))
    {
        case kEventAppHidden:
        /*
         * Don't bother if we don't have an interp or
         * the show preferences procedure doesn't exist.
         */
     
            if ((interp == NULL) || 
                    (Tcl_GetCommandInfo(interp, 
                    "::tk::mac::OnHide", &dummy)) == 0) {
                return eventNotHandledErr;
            }
            Tcl_GlobalEval(interp, "::tk::mac::OnHide");
            toggleHide = 1;
            break;
        case kEventAppShown:
            if (toggleHide == 1) {
                toggleHide = 0;
                if ((interp == NULL) || 
                        (Tcl_GetCommandInfo(interp, 
                        "::tk::mac::OnShow", &dummy)) == 0) {
                    return eventNotHandledErr;
                }
                Tcl_GlobalEval(interp, "::tk::mac::OnShow");
            }
            break;
       default:
            break;
    }
    return eventNotHandledErr;
}
d74 1
a74 5
    const EventTypeSpec inAppEventTypes[] = {
            {kEventClassApplication, kEventAppHidden},
            {kEventClassApplication, kEventAppShown}};
    UInt32 inNumTypes = 2;
    
a106 7
  
    InstallEventHandler(GetApplicationEventTarget(),
            NewEventHandlerUPP (ApplicationCarbonEventsHandler),
            inNumTypes,
            inAppEventTypes,
            (void *) interp,
            NULL);
@


1.5.2.4
log
@Trivial bug in tracking Hide/Show pairs.
@
text
@a75 1
            toggleHide = 1;
d82 1
@


1.5.2.5
log
@	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXNotify.c: introduction of new tcl notifier based on
	CFRunLoop allows replacement of the custom TkAqua notifier by a
	standard tcl event source. Removes requirement of threaded tcl core
	for TkAqua, allows to stub-link TkAqua against Tcl by removing use of
	the unstubbed TclInitNotifier & TclFinalizeNotifier. [Tcl Patch 1202052]

	* macosx/Wish.pbproj/project.pbxproj: stub-link TkAqua: build with
	USE_TCL_STUBS and link against libtclstub instead of Tcl.framework,
	unexport libtclstub symbols from Tk to avoid duplicate symbol warnings
	when linking with both Tcl and Tk, fixes for gcc4.0 warnings.

	* macosx/tkMacOSXBitmap.c:
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c: fixed gcc 4.0 warnings.

	* unix/tcl.m4: sync with tcl
	* unix/configure: autoconf-2.13
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.5.2.4 2004/03/17 19:35:41 wolfsuit Exp $
d547 1
a547 1
        Tcl_ExternalToUtfDString(NULL, (char*) fileName, -1, ds);
@


1.5.2.6
log
@	* macosx/tkMacOSXCarbonEvents.c (new): moved carbon events code into
	* macosx/tkMacOSXHLEvents.c:           new file like on HEAD,
	* macosx/tkMacOSXInit.c (TkpInit):     initialize carbon event handlers
	* macosx/tkMacOSXInt.h:                in TkpInit(), add new source
	* unix/Makefile.in:                    file to Makefile.in.

	* macosx/tkMacOSXCarbonEvents.c (AppEventHandlerProc): handle carbon
	events sent directly to application event target via the general
	TkMacOSXProcessEvent() in the same way as events posted to the event
	loop. Moved existing app event handlers to tkMacOSXWindowEvent.c.
	(TkMacOSXInitCarbonEvents): register our application event handler for
	kEventWindowExpanded events to deal with uncollapsing from the dock.

	* macosx/tkMacOSXEvent.h: made TkMacOSXProcessEvent() non-static, added
	* macosx/tkMacOSXEvent.c: new interp field to TkMacOSXEvent struct for
	                          use by app event handler.

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): retrieve
	current window, partCode, modifiers and local cursor position from
	carbon mouse event if possible. Use new static GenerateButtonEvent()
	taking a MouseEventData struct instead of TkGenerateButtonEvent() to
	avoid recomputing already known values. Move process activation on
	MouseDown into BringWindowForward() to allow clicking on window titlebar
	widgets without activating process. Move code dealing with clicks in
	window titelbar into separate function HandleWindowTitlebarMouseDown()
	to avoid code duplication. Avoid repeated calls to TkMacOSXGetXWindow()
	by storing result in MouseEventData struct.
	(TkMacOSXButtonKeyState, XQueryPointer): try to get button and modifier
	state from currently processed carbon event (to avoid unnecessary IPC
	with the window server), otherwise use modern carbon API to get this
	info instead of Button() and GetKeys(); only retrieve info caller asks
	for (via non-NULL ptr passed to XQueryPointer).
	(ButtonModifiers2State): new static function converting carbon button
	and modifier state into tk state, allows detection of more than 3 mouse
	buttons (tk supports up to 5) and of NumLock and Fn modifier keys
	(NumLock is mapped to Mod3 and Fn to Mod4).

	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessApplicationEvent): handle
	kEventWindowExpanded event to deal with window uncollapsing from the
	dock by generating tk Map event, handle kEventAppHidden and
	kEventAppShown events (moved here from tkMacOSXCarbonEvents.c).

	* macosx/tkMacOSXSubwindows.c (XUnmapWindow): only hide window when
	it is not iconified to avoid window flashing on collapse.

	* macosx/tkMacOSXWm.c: replaced Tk_DoWhenIdle() by Tcl_DoWhenIdle().
	(TkMacOSXZoomToplevel): remove call to TrackBox(), now done in
	HandleWindowTitlebarMouseDown() in tkMacOSXMouseEvent.c.
	(TkpWmSetState): avoid window flashing on collapse by unmapping after
	calling CollapseWindow(); only uncollapse window if it is collapsed.

	* generic/tkInt.decls: changed TkMacOSXZoomToplevel() signature.
	* generic/tkIntPlatDecls.h:

	* macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): only call
	GetMenuItemCommandID() on KeyDown or KeyRepeat events.

	* macosx/tkMacOSXMenu.c (ReconfigureMacintoshMenu): remove call to
	obsolete AppendResMenu() API.

	* macosx/tkMacOSXKeyEvent.c: replaced all direct uses of expensive
	* macosx/tkMacOSXMenu.c:     GetMouse() and TkMacOSXButtonKeyState()
	* macosx/tkMacOSXMenus.c:    APIs by calls to XQueryPointer()
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c:   replaced use of FrontNonFloatingWindow()
	* macosx/tkMacOSXKeyEvent.c: by ActiveNonFloatingWindow() as
	* macosx/tkMacOSXMenu.c:     recommended by Carbon docs.
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c: fixed warnings
	* macosx/tkMacOSXTest.c:

	* macosx/tkMacOSXCarbonEvents.c: added CVS Id line to file header.
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.h:

	* macosx/tkMacOSXEmbed.c: replaced all uses of panic() with Tcl_Panic()
	* macosx/tkMacOSXFont.c:  (sync with HEAD).
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXInt.h:      sync with HEAD changes of 2005-03-14.
	* macosx/tkMacOSXSubwindows.c:

	* macosx/tclets.r (removed): sync with HEAD.
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXPort.h:

	* library/demos/menu.tcl: removed errant '}'.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.5.2.5 2005/05/14 20:53:31 das Exp $
d48 52
a99 1

d125 5
a129 1

d162 7
@


1.5.2.7
log
@	* macosx/tkMacOSX.h:             Cleaned up & rationalized order of
	* macosx/tkMacOSXBitmap.c:       #includes of tk and carbon headers;
	* macosx/tkMacOSXButton.c:       sync whitespace, comments & minor
	* macosx/tkMacOSXCarbonEvents.c: changes with HEAD.
	* macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXColor.c:
	* macosx/tkMacOSXConfig.c:
	* macosx/tkMacOSXCursor.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXFont.h (new file):
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXWm.h:
	* macosx/tkMacOSXXStubs.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.5.2.6 2005/08/09 07:40:00 das Exp $
d16 1
d19 2
@


1.5.2.8
log
@	* macosx/tkMacOSXHLEvents.c:    call ::tk::mac::* procs for all
	* macosx/tkMacOSXWindowEvent.c: registered appleevents [FR 1105284],
	implement print applevent handling, style/whitespace cleanup.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.5.2.7 2006/03/28 02:44:13 das Exp $
d20 1
a20 1
 * uses to schedule the ReallyKillMe function.
d24 1
a24 1
    Tcl_Event header;           /* Information that is standard for
d26 1
a26 1
    Tcl_Interp *interp;         /* Interp that was passed to the
d34 11
a44 18
static OSErr QuitHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr OappHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr RappHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr OdocHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr PrintHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr ScriptHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);
static OSErr PrefsHandler(const AppleEvent * event, AppleEvent * reply,
	long handlerRefcon);

static int MissedAnyParameters(const AppleEvent *theEvent);
static int ReallyKillMe(Tcl_Event *eventPtr, int flags);
static OSErr FSRefToDString(const FSRef *fsref, Tcl_DString *ds);
a70 37
    static Boolean initialized = FALSE;

    if (!initialized) {
        initialized = TRUE;

	/*
	 * Install event handlers for the core apple events.
	 */
	QuitHandlerUPP = NewAEEventHandlerUPP(QuitHandler);
	err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
		QuitHandlerUPP, (long) interp, false);

	OappHandlerUPP = NewAEEventHandlerUPP(OappHandler);
	err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
		OappHandlerUPP, (long) interp, false);

	RappHandlerUPP = NewAEEventHandlerUPP(RappHandler);
	err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication,
		RappHandlerUPP, (long) interp, false);

	OdocHandlerUPP = NewAEEventHandlerUPP(OdocHandler);
	err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
		OdocHandlerUPP, (long) interp, false);

	PrintHandlerUPP = NewAEEventHandlerUPP(PrintHandler);
	err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
		PrintHandlerUPP, (long) interp, false);

	PrefsHandlerUPP = NewAEEventHandlerUPP(PrefsHandler);
	err = AEInstallEventHandler(kCoreEventClass, kAEShowPreferences,
		PrefsHandlerUPP, (long) interp, false);

	if (interp) {
	    ScriptHandlerUPP = NewAEEventHandlerUPP(ScriptHandler);
	    err = AEInstallEventHandler(kAEMiscStandards, kAEDoScript,
		ScriptHandlerUPP, (long) interp, false);
	}
d72 31
d123 1
a123 2
TkMacOSXDoHLEvent(
    EventRecord *theEvent)
d133 2
a134 1
 *        These are the core Apple event handlers.
d144 1
a144 5
static OSErr
QuitHandler (
    const AppleEvent * event,
    AppleEvent * reply,
    long handlerRefcon)
d149 13
a161 14
    if (interp) {
	/*
	 * Call the exit command from the event loop, since you are not supposed
	 * to call ExitToShell in an Apple Event Handler.  We put this at the head
	 * of Tcl's event queue because this message usually comes when the Mac is
	 * shutting down, and we want to kill the shell as quickly as possible.
	 */
	
	eventPtr = (KillEvent *) ckalloc(sizeof(KillEvent));
	eventPtr->header.proc = ReallyKillMe;
	eventPtr->interp = interp;
	 
	Tcl_QueueEvent((Tcl_Event *) eventPtr, TCL_QUEUE_HEAD);
    }
d164 1
a164 1

d166 1
a166 4
OappHandler (
    const AppleEvent * event,
    AppleEvent * reply,
    long handlerRefcon)
a167 7
    Tcl_CmdInfo dummy;
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;

    if (interp &&
	    Tcl_GetCommandInfo(interp, "::tk::mac::OpenApplication", &dummy)) {
	Tcl_GlobalEval(interp, "::tk::mac::OpenApplication");
    }
d170 1
a170 1

d172 1
a172 4
RappHandler (
    const AppleEvent * event,
    AppleEvent * reply,
    long handlerRefcon)
a173 2
    Tcl_CmdInfo dummy;
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
d175 1
a175 7
    OSStatus status = SetFrontProcess(&thePSN);
    
    if (interp &&
	    Tcl_GetCommandInfo(interp, "::tk::mac::ReopenApplication", &dummy)) {
	Tcl_GlobalEval(interp, "::tk::mac::ReopenApplication");
    }
    return status;
d177 1
a177 1

d180 1
a180 4
PrefsHandler (
    const AppleEvent * event,
    AppleEvent * reply,
    long handlerRefcon)
d184 4
d189 3
a191 3
    if (interp &&
	    Tcl_GetCommandInfo(interp, "::tk::mac::ShowPreferences", &dummy)) {
	Tcl_GlobalEval(interp, "::tk::mac::ShowPreferences");
d193 1
d196 1
a196 1

d198 1
a198 4
OdocHandler (
    const AppleEvent * event,
    AppleEvent * reply,
    long handlerRefcon)
d265 1
a265 1

d267 1
a267 4
PrintHandler (
    const AppleEvent * event,
    AppleEvent * reply,
    long handlerRefcon)
a268 63
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
    AEDescList fileSpecList;
    FSRef file;
    OSErr err;
    DescType type;
    Size actual;
    long count;
    AEKeyword keyword;
    long index;
    Tcl_DString command;
    Tcl_DString pathName;
    Tcl_CmdInfo dummy;

    /*
     * Don't bother if we don't have an interp or
     * the print document procedure doesn't exist.
     */

    if ((interp == NULL) || 
            (Tcl_GetCommandInfo(interp, "::tk::mac::PrintDocument", &dummy)) == 0) {
            return noErr;
    }
    
    /*
     * If we get any errors wil retrieving our parameters
     * we just return with no error.
     */

    err = AEGetParamDesc(event, keyDirectObject,
            typeAEList, &fileSpecList);
    if (err != noErr) {
        return noErr;
    }

    err = MissedAnyParameters(event);
    if (err != noErr) {
        return noErr;
    }

    err = AECountItems(&fileSpecList, &count);
    if (err != noErr) {
        return noErr;
    }

    Tcl_DStringInit(&command);
    Tcl_DStringAppend(&command, "::tk::mac::PrintDocument", -1);
    for (index = 1; index <= count; index++) {
        err = AEGetNthPtr(&fileSpecList, index, typeFSRef,
                &keyword, &type, (Ptr) &file, sizeof(FSRef), &actual);
        if ( err != noErr ) {
            continue;
        }

        err = FSRefToDString(&file, &pathName);
        if (err == noErr) {
            Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
            Tcl_DStringFree(&pathName);
        }
    }
    
    Tcl_GlobalEval(interp, Tcl_DStringValue(&command));

    Tcl_DStringFree(&command);
d289 1
a289 4
ScriptHandler (
    const AppleEvent * event,
    AppleEvent * reply,
    long handlerRefcon)
d418 1
a418 3
ReallyKillMe(
    Tcl_Event *eventPtr,
    int flags) 
d421 2
a422 5
    Tcl_CmdInfo dummy;
    if (Tcl_GetCommandInfo(interp, "::tk::mac::Quit", &dummy)) {
	 Tcl_GlobalEval(interp, "::tk::mac::Quit");
    } else {
	Tcl_GlobalEval(interp, "exit");
d424 1
d475 1
a475 3
FSRefToDString(
    const FSRef *fsref,
    Tcl_DString *ds)
@


1.5.2.9
log
@fix whitespace, copyright
@
text
@a8 1
 * Copyright (c) 2006 Daniel A. Steffen <das@@users.sourceforge.net>
d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.5.2.8 2006/04/11 10:21:53 das Exp $
d115 1
@


1.5.2.10
log
@	* macosx/tkMacOSXCarbonEvents.c: add window event target carbon event
	* macosx/tkMacOSXEvent.c:	 handler for all kEventClassWindow and
	* macosx/tkMacOSXEvent.h:	 kEventClassMouse events; move all
	* macosx/tkMacOSXNotify.c:	 remaining events except for
	* macosx/tkMacOSXWindowEvent.c:	 kEventClassKeyboard from dispatcher to
	application event handler; pass event handler callRef downstream; fix
	debug event tracing; process all tcl event types in carbon event timer;
	delay carbon event timer first fire; add TkMacOSXTrackingLoop() to mark
	enter/exit of event tracking loop during which all tcl events but only
	carbon update events should be processed by the timer (replaces various
	calls to Tcl_SetServiceMode()); rename TkMacOSXReceiveAndProcessEvent()
	to TkMacOSXReceiveAndDispatchEvent(), move it from tkMacOSXEvent.c to
	tkMacOSXCarbonEvents.c and modify it to dequeue only update events
	during a tracking loop; add TkMacOSXRunTclEventLoop() to standardize
	the various ways in use to run the tcl event loop; add handling of
	kEventClassAppearance events (for ScrollBarVariantChanged event).

	* macosx/tkMacOSXDialog.c:	use new TkMacOSXTrackingLoop() around
	* macosx/tkMacOSXEvent.c:	blocking API that puts up modal dialogs
	* macosx/tkMacOSXMenu.c:	or when entering/exiting menu/control
	* macosx/tkMacOSXMouseEvent.c:	tracking, window dragging and other
	* macosx/tkMacOSXScale.c:	mouse tracking loops.
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDialog.c:	use new TkMacOSXRunTclEventLoop()
	* macosx/tkMacOSXScale.c:	instead of Tcl_DoOneEvent(),
	* macosx/tkMacOSXScrlbr.c:	Tcl_ServiceAll(), TclServiceIdle()
	* macosx/tkMacOSXWindowEvent.c:	and Tcl_GlobalEval("update idletasks").

	* macosx/tkMacOSXColor.c: make available as Tk system colors all
	* macosx/tkMacOSXPort.h:  appearance manager brushes, text colors and
	backgrounds with new and legacy names, as well as the fully transparent
	color "systemTransparent"; add TkMacOSXSetColorIn{Port,Context}() to
	directly set an X pixel color value in the current QD port resp. the
	given CG context without requiring passage through rgb representation
	(lossy for most system colors); modernize/remove Classic-era code;
	replace crufty strcmp() elseifs by Tcl_GetIndexFromObjStruct().

	* macosx/tkMacOSXButton.c:	use new TkMacOSXSetColorInPort()
	* macosx/tkMacOSXDraw.c:	instead of setting rgb color directly
	* macosx/tkMacOSXMenubutton.c:	to allow for non-rgb system colors.

	* macosx/tkMacOSXCursor.c: implement "none" cursor as on other
	platforms [Patch 1615427]; add all missing appearance manager cursors.

	* macosx/tkMacOSXDefault.h: set SELECT_FG_COLORs to None to match aqua
	L&F; use standard system color names; use new 'menu' system font;
	correct default scrollbar width.

	* macosx/tkMacOSXDraw.c:	standardize initialization, use and
	* macosx/tkMacOSXInt.h:		emptying of various static temp rgns
	* macosx/tkMacOSXRegion.c:	onto two global RgnHandles; in debug
	* macosx/tkMacOSXSubwindows.c:	builds, verify emptiness of these temp
	* macosx/tkMacOSXWindowEvent.c:	rgns before use.

	* macosx/tkMacOSXDraw.c: add TkMacOSX{Setup,Restore}DrawingContext() to
	* macosx/tkMacOSXInt.h:  abstract common setup & teardown of drawing
	environment (for both CG and QD); save/restore QD theme drawing state;
	handle GC clip region; add TkpClipDrawableToRect() to allow clipped
	drawing into drawable regardless of GC used; use new system color
	"systemWindowHeaderBackground" to setup background in themed toplevels;
	correct implementation of TkMacOSXMakeStippleMap().

	* macosx/tkMacOSXEntry.c: use new TkMacOSXSetupDrawingContext() and
	* macosx/tkMacOSXFont.c:  TkMacOSXRestoreDrawingContext() instead of
	various setup/teardown procs like TkMacOSX{SetUp,Release}CGContext(),
	TkMacOSXQuarz{Start,End}Draw(), TkMacOSXSetUpGraphicsPort() etc.

	* macosx/tkMacOSXEmbed.c: add CG context and drawable clip rgn fields
	* macosx/tkMacOSXInt.h:   to MacDrawable struct.
	* macosx/tkMacOSXSubwindows.c:

	* macosx/tkMacOSXDialog.c: make -parent option of tk_getOpenFile et al.
	use the sheet version of NavServices dialogs; ensure native parent win
	exists before using StandardSheet API for tk_messageBox [Bug 1677611];
	force sheets to behave like app-modal dialogs via WindowModality() API;
	use more modern ColorPicker API.

	* macosx/tkAboutDlg.r: use themed movable modal dialog, fix (c) year.

	* macosx/tkMacOSXEntry.c:  take xOff/yOff of MacDrawable into account
	when computing locations/bounds to ensure correct posititioning when
	not drawing into intermediate pixmap.

	* macosx/tkMacOSXFont.c: use appearance manager API to map system font
	* macosx/tkMacOSXFont.h: names to TkFonts; add "menu" system font for
	menu item text drawing from MDEF; disable broken QD stippling.

	* macosx/tkMacOSXMenu.c:		large-scale rewrite of custom
	* macosx/tkMacOSXMenu.r (removed):	MDEF and related code that
	* unix/Makefile.in:			restores many longtime-MIA
	features to working order (e.g. images, custom colors & fonts in menus
	etc); implement compound menu items; use Appearance Mgr and ThemeText
	APIs to mimic native MDEF as closely as possible when default "menu"
	system font is used; remove now obsolete SICN drawing code and
	resources.

	* macosx/tkMacOSXCarbonEvents.c: handle additional menu carbon events
	* macosx/tkMacOSXEvent.c:	 in order to support <<MenuSelect>> in
	* macosx/tkMacOSXMenu.c:	 the menubar and in menus that are not
	* macosx/tkMacOSXMenus.c:	 using the custom MDEF [Bug 1620826];
	fix early and missing clearing of current Tk active menu entry; fix
	extraneous sending of <<MenuSelect>> during active menu entry clearing.

	* macosx/tkMacOSXMouseEvent.c: add support for async window dragging by
	the window server; set the corresponding window attribute by default.

	* macosx/tkMacOSXMouseEvent.c: rationalized handling order of
	non-mousedown events; add TkMacOSXModifierState() to retrieve the
	current key modifiers in carbon format.

	* macosx/tkMacOSXScrlbr.c: use appearance manager API to retrieve
	scrollbar component metrics; add awareness of multiple possibilites for
	scrollbar arrow position in aqua and handle user changes to arrow
	position pref; handle difference in metrics of small & large scrollbar
	variants; handle aqua "jump to here" scrollbar behaviour; correct
	computation of scroll view size and position; enforce min scrollbar
	height to avoid scrollbar component overlap; erase scrollbar area
	outside of standard width; remove broken auto-adjust code; account for
	window class when leaving space for grow box; remove code to manually
	draw grow box; use modern API for thumb scroll proc; replace
	HiliteControl() by modern API; replace control mgr constants with
	appearance mgr equivalents.

	* macosx/tkMacOSXSubwindows.c: use SetWindowBounds() API instead of
	SizeWindow(); invalidate clip regions after X{Map,Unmap}Window as fix
	for [Bug 940117] made them dependent on mapping state; remove unneeded
	calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD port;
	use native-endian pixmap on intel; remove obsolete pixmap pix locking.

	* macosx/tkMacOSXWindowEvent.c: handle only the first of a batch of
	kEventAppAvailableWindowBoundsChanged events sent per transaction;
	handle kEventWindowBoundsChanged event to support live window resizing
	and centralized sending of location/size changed ConfigureNotify
	events; ensure HIGrowBox is redrawn after bounds change; constrain
	window after dragging to ensure titlebar is not inacessible
	offscreen or under dock/menubar; handle kEventWindowGetRegion and
	kEventWindowDrawContent for transparent windows to mark resp. paint
	content region as transparent; handle kEventWindowConstrain for
	fullscreen windows to ensure bounds match new screen size; enter/exit
	fullscreen UIMode upon activation/deactivation of fullscreen window.

	* macosx/tkMacOSXWm.c: use live-resize and async-drag carbon window
	* macosx/tkMacOSXWm.h: attributes for toplevels by default; implement
	new [wm attributes] -topmost, -transparent and -fullscreen; refactor
	WmAttributesCmd() parallelling the tkUnixWm.c implementation, use thus
	factored proc to set proxy icon from [wm iconbitmap]; dynamically
	determine default values for toplevel min and max sizes (similar to
	tkWinWm.c impl): min sizes depend on window class & attributes to
	ensure visibility of all titlebar widgets and grow box, max sizes
	depend on maximal window bounds for all active displays; factor out
	code that puts into effect changes to master or override_redirect; use
	RepositionWindow() API to determine staggered initial window bounds;
	correct resize limit calculations, handle gridding and use modern
	resize API in TkMacOSXGrowToplevel(); remove sending of ConfigureNotify
	after resize or zoom (now handled by BoundsChanged handler); correct
	composite carbon window attribute handling, remove currently unusable
	attributes and add new attributes in [tk::unsupported::MacWindowStyle];
	ensure validity of window class and attributes before use; apply
	changes to window class when handling carbon window attribute changes
	(if HIWindowChangeClass() API available); add debug build warning
	message when deprecated window style is used instead of window class;
	use transparent HIGrowBox for resizable windows; avoid unnecessary
	calls to window structure width API; use tcl time API in TkpGetMS();
	add TkMacOSXEnterExitFullscreen() to enter/exit UIMode with dock and
	menubar hidden; restrict wmTracing output to debug builds; remove
	unneeded calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD
	port; workaround GetWindowStructureWidths() Carbon bug (bogus results
	for never-mapped floating windows).

	* macosx/tkMacOSXXStubs.c (TkMacOSXDisplayChanged): add maximal window
	bounds field to Screen record (in ext_data), computed as the union of
	available window positioning bounds of all graphics devices (displays).

	* macosx/tkMacOSXBitmap.c: fix macRoman encoding leak.
	* macosx/tkMacOSXCursor.c:

	* macosx/tkMacOSXDebug.c (TkMacOSXCarbonEventToAscii): use static
	* macosx/tkMacOSXDebug.h: buffer to simplify callers; const fixes.

	* macosx/tkMacOSXBitmap.c: use more efficient QDSwapPort() instead of
	* macosx/tkMacOSXButton.c: GetPort()/SetPort()/GetGWorld()/SetGWorld().
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXColor.c: use kHIToolboxVersionNumber for runtime OS
	* macosx/tkMacOSXEntry.c: version check rather than Gestalt() etc.
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c: remove obsolete and now incorrect
	* macosx/tkMacOSXInt.h:  tkMenuCascadeRgn clipping code.
	* macosx/tkMacOSXMenu.c:

	* macosx/tkMacOSXHLEvents.c: replace Tcl_GlobalEval() resp. Tcl_Eval()
	* macosx/tkMacOSXScrlbr.c:   by Tcl_EvalEx().
	* macosx/tkMacOSXInit.c:

	* macosx/tkMacOSXInit.c (TkpInit): reorder initialization steps.

	* macosx/tkMacOSXKeyEvent.c: remove pre-10.2 support.

	* macosx/tkMacOSXMenus.c: remove now useless call to
	TkMacOSXHandleTearoffMenu(); use \x.. quoting for non-latin1 macroman
	literar chars to allow file to be edited as utf-8.

	* macosx/tkMacOSXScale.c: replace TrackControl() by modern
	* macosx/tkMacOSXScrlbr.c: HandleControlClick() API (using new
	TkMacOSXModifierState()).

	* macosx/tkMacOSXInt.h:		move all constant #defines needed to
	* macosx/tkMacOSXColor.c:	support building on older OS X releases
	* macosx/tkMacOSXEvent.h:	to a central location in tkMacOSXInt.h.
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXInt.h:		 add ChkErr() macro to factor out
	* macosx/tkMacOSXButton.c:	 Carbon OSStatus return value checking
	* macosx/tkMacOSXCarbonEvents.c: and TkMacOSXDbgMsg() macro to factour
	* macosx/tkMacOSXClipboard.c:	 out debug message output; use these
	* macosx/tkMacOSXColor.c:	 macros to replace #ifdef TK_MAC_DEBUG
	* macosx/tkMacOSXCursor.c:	 blocks & direct printing to stderr,
	* macosx/tkMacOSXDebug.c:	 and to do additional OSStatus return
	* macosx/tkMacOSXDialog.c:	 checking, and to standardize OSStatus
	* macosx/tkMacOSXDraw.c:	 usage.
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXSend.c:	remove duplicate/unused declarations.
	* macosx/tkMacOSXXStubs.c:

	* macosx/tkMacOSXDebug.c:	const fixes.
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:

	* macosx/Wish-Info.plist.in: add tcl document extensions/mime types and
	LSMinimumSystemVersion, LSRequiresCarbon & NSAppleScriptEnabled keys.

	* macosx/tkMacOSXAETE.r:	fix whitespace.
	* macosx/tkMacOSXConfig.c:
	* macosx/tkMacOSXCursors.r:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXXCursors.r:
	* macosx/README:

	* macosx/Makefile:		fix/add copyright and license refs.
	* macosx/Tk-Info.plist.in:
	* macosx/Wish-Info.plist.in:
	* macosx/tkMacOSX.h:
@
text
@d1 1
a1 1
/*
d4 2
a5 2
 *	Implements high level event support for the Macintosh. Currently,
 *	the only event that really does anything is the Quit event.
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.5.2.9 2006/05/12 18:18:52 das Exp $
d23 1
a23 1

d25 4
a28 4
    Tcl_Event header;		/* Information that is standard for
				 * all events. */
    Tcl_Interp *interp;		/* Interp that was passed to the
				 * Quit AppleEvent */
d52 1
a52 1
static OSStatus FSRefToDString(const FSRef *fsref, Tcl_DString *ds);
d59 2
a60 2
 *	Initilize the Apple Events on the Macintosh. This registers the
 *	core event handlers.
d63 1
a63 1
 *	None.
d66 1
a66 1
 *	None.
d71 1
a71 1
void
d73 1
a73 1
    Tcl_Interp *interp)		       /* Interp to handle basic events. */
d75 4
a78 2
    AEEventHandlerUPP	     OappHandlerUPP, RappHandlerUPP, OdocHandlerUPP,
	    PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP, PrefsHandlerUPP;
d82 1
a82 1
	initialized = TRUE;
d88 1
a88 1
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEQuitApplication,
d92 1
a92 1
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenApplication,
d96 1
a96 1
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEReopenApplication,
d100 1
a100 1
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenDocuments,
d104 1
a104 1
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEPrintDocuments,
d108 1
a108 1
	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEShowPreferences,
d113 1
a113 1
	    ChkErr(AEInstallEventHandler, kAEMiscStandards, kAEDoScript,
d124 1
a124 1
 *	Dispatch incomming highlevel events.
d127 1
a127 1
 *	None.
d130 1
a130 1
 *	Depends on the incoming event.
d145 1
a145 1
 * QuitHandler --
d147 1
a147 1
 *	This is the 'quit' core Apple event handler.
d150 1
a150 1
 *	None.
d153 1
a153 1
 *	None.
d157 2
a158 3

OSErr
QuitHandler(
d165 1
a165 1

d169 1
a169 1
	 * to call ExitToShell in an Apple Event Handler. We put this at the head
d173 1
a173 1

d177 1
a177 1

d183 2
a184 18
/*
 *----------------------------------------------------------------------
 *
 * OappHandler --
 *
 *	This is the 'oapp' core Apple event handler.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

OSErr
OappHandler(
d199 2
a200 18
/*
 *----------------------------------------------------------------------
 *
 * RappHandler --
 *
 *	This is the 'rapp' core Apple event handler.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

OSErr
RappHandler(
d208 2
a209 2
    OSStatus err = ChkErr(SetFrontProcess, &thePSN);

d214 1
a214 1
    return err;
d217 3
a219 19
/*
 *----------------------------------------------------------------------
 *
 * PrefsHandler --
 *
 *	This is the 'pref' core Apple event handler.
 *	Called when the user selects 'Preferences...' in MacOS X
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

OSErr
PrefsHandler(
d234 2
a235 18
/*
 *----------------------------------------------------------------------
 *
 * OdocHandler --
 *
 *	This is the 'odoc' core Apple event handler.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

OSErr
OdocHandler(
d243 1
a243 1
    OSStatus err;
d258 3
a260 3
    if ((interp == NULL) ||
	    (Tcl_GetCommandInfo(interp, "::tk::mac::OpenDocument", &dummy)) == 0) {
	    return noErr;
d262 1
a262 1

d268 2
a269 2
    err = ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
	    &fileSpecList);
d271 1
a271 1
	return noErr;
d276 1
a276 1
	return noErr;
d279 1
a279 1
    err = ChkErr(AECountItems, &fileSpecList, &count);
d281 1
a281 1
	return noErr;
d287 11
a297 11
	err = ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef,
		&keyword, &type, (Ptr) &file, sizeof(FSRef), &actual);
	if ( err != noErr ) {
	    continue;
	}

	err = ChkErr(FSRefToDString, &file, &pathName);
	if (err == noErr) {
	    Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
	    Tcl_DStringFree(&pathName);
	}
d299 2
a300 3

    Tcl_EvalEx(interp, Tcl_DStringValue(&command), Tcl_DStringLength(&command),
	    TCL_EVAL_GLOBAL);
d306 2
a307 18
/*
 *----------------------------------------------------------------------
 *
 * PrintHandler --
 *
 *	This is the 'pdoc' core Apple event handler.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

OSErr
PrintHandler(
d315 1
a315 1
    OSStatus err;
d330 3
a332 3
    if ((interp == NULL) ||
	    (Tcl_GetCommandInfo(interp, "::tk::mac::PrintDocument", &dummy)) == 0) {
	    return noErr;
d334 1
a334 1

d340 2
a341 2
    err = ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
	    &fileSpecList);
d343 1
a343 1
	return noErr;
d346 1
a346 1
    err = ChkErr(MissedAnyParameters, event);
d348 1
a348 1
	return noErr;
d351 1
a351 1
    err = ChkErr(AECountItems, &fileSpecList, &count);
d353 1
a353 1
	return noErr;
d359 11
a369 11
	err = ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword,
		&type, (Ptr) &file, sizeof(FSRef), &actual);
	if ( err != noErr ) {
	    continue;
	}

	err = ChkErr(FSRefToDString, &file, &pathName);
	if (err == noErr) {
	    Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
	    Tcl_DStringFree(&pathName);
	}
d371 2
a372 3

    Tcl_EvalEx(interp, Tcl_DStringValue(&command), Tcl_DStringLength(&command),
	    TCL_EVAL_GLOBAL);
d383 1
a383 1
 *	This handler process the script event.
d386 1
a386 1
 *	Schedules the given event to be processed.
d389 1
a389 1
 *	None.
d394 2
a395 2
OSErr
ScriptHandler(
d400 1
a400 1
    OSStatus theErr;
d412 1
a412 1
	    &theDesc);
d414 3
a416 4
	sprintf(errString, "AEDoScriptHandler: GetParamDesc error %ld",
		theErr);
	theErr = AEPutParamPtr(reply, keyErrorString, typeChar, errString,
		strlen(errString));
d418 4
a421 4
	sprintf(errString, "AEDoScriptHandler: extra parameters");
	AEPutParamPtr(reply, keyErrorString, typeChar, errString,
		strlen(errString));
	theErr = -1771;
d423 62
a484 63
	if (theDesc.descriptorType == (DescType)typeChar) {
	    Tcl_DString encodedText;
	    short i;
	    Size  size;
	    char  * data;

	    size = AEGetDescDataSize(&theDesc);

	    data = (char *)ckalloc(size + 1);
	    if ( !data ) {
		theErr = -1771;
	    }
	    else {
		   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) {
	    Boolean dummy;
	    FSRef file;
	    AliasPtr	alias;
	    Size	theSize;

	    theSize = AEGetDescDataSize(&theDesc);
	    alias = (AliasPtr) ckalloc(theSize);
	    if (alias) {
		AEGetDescData (&theDesc, alias, theSize);

		theErr = FSResolveAlias(NULL, &alias,
			&file, &dummy);
		ckfree((char*)alias);
	    } else {
		theErr = memFullErr;
	    }
	    if (theErr == noErr) {
		Tcl_DString scriptName;
		theErr = FSRefToDString(&file, &scriptName);
		if (theErr == noErr) {
		    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: invalid script type '%-4.4s', must be 'alis' or 'TEXT'",
		    (char *)(&theDesc.descriptorType));
	    AEPutParamPtr(reply, keyErrorString, typeChar,
		    errString, strlen(errString));
	    theErr = -1770;
	}
d491 11
a501 11
	if (tclErr == TCL_OK)  {
	    AEPutParamPtr(reply, keyDirectObject, typeChar,
		Tcl_GetStringResult(interp),
		strlen(Tcl_GetStringResult(interp)));
	} else {
	    AEPutParamPtr(reply, keyErrorString, typeChar,
		Tcl_GetStringResult(interp),
		strlen(Tcl_GetStringResult(interp)));
	    AEPutParamPtr(reply, keyErrorNumber, typeInteger,
		(Ptr) &tclErr, sizeof(int));
	}
d503 1
a503 1

d514 2
a515 2
 *	This proc tries to kill the shell by running exit,
 *	called from an event scheduled by the "Quit" AppleEvent handler.
d518 1
a518 1
 *	Runs the "exit" command which might kill the shell.
d521 1
a521 1
 *	None.
d526 1
a526 1
static int
d529 1
a529 1
    int flags)
d546 1
a546 1
 *	Checks to see if parameters are still left in the event.
d549 1
a549 1
 *	True or false.
d552 1
a552 1
 *	None.
d556 2
a557 2

int
d563 1
a563 4
   OSStatus err;

   err = ChkErr(AEGetAttributePtr, theEvent, keyMissedKeywordAttr,
	   typeWildCard, &returnedType, NULL, 0, &actualSize);
d565 3
d576 1
a576 1
 *	Get a POSIX path from an FSRef.
d579 1
a579 1
 *	In the parameter ds.
d582 1
a582 1
 *	None.
d587 1
a587 1
OSStatus
d593 1
a593 1
    OSStatus err;
d595 1
a595 1
    err = ChkErr(FSRefMakePath, fsref, fileName, sizeof(fileName));
d597 1
a597 1
	Tcl_ExternalToUtfDString(NULL, (char*) fileName, -1, ds);
@


1.5.2.11
log
@	* macosx/tkMacOSXScrlbr.c: correct int <-> dobule conversion issues
	that could lead to Carbon getting confused about scrollbar thumb size.

	* macosx/tkMacOSXDraw.c (XCopyArea, XCopyPlane, TkPutImage) use
	TkMacOSX{Setup,Restore}DrawingContext() to setup/restore clip & colors.
	(TkMacOSXSetupDrawingContext, TkMacOSXRestoreDrawingContext): add save
	and restore of QD port clip region; factor out clip region code common
	to CG and QD branches; check for port and context validity; handle
	tkPictureIsOpen flag during QD port setup.
	(TkScrollWindow): remove unnecessary scroll region manipulation

	* macosx/tkMacOSXDraw.c:	remove second global QD temp region
	* macosx/tkMacOSXInt.h:		(no longer necessary) and rename
	* macosx/tkMacOSXRegion.c:	remaining global QD temp region.
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:

	* macosx/tkMacOSXDraw.c:	make useCGDrawing variable MODULE_SCOPE
	* macosx/tkMacOSXFont.c:	and sync formatting with HEAD.

	* macosx/tkMacOSXButton.c:	reduce reliance on current QD port
	* macosx/tkMacOSXColor.c:	setting and remove unnecessary
	* macosx/tkMacOSXDebug.c:	references to a drawable's QD port,
	* macosx/tkMacOSXDebug.h:	notably replace GetWindowFromPort(
	* macosx/tkMacOSXDialog.c:	TkMacOSXGetDrawablePort()) idiom by new
	* macosx/tkMacOSXDraw.c:	TkMacOSXDrawableWindow() and change
	* macosx/tkMacOSXKeyEvent.c:	TkMacOSXSetColorInPort() to take a port
	* macosx/tkMacOSXMenu.c:	argument.
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXInt.h:			factor out macros, declarations
	* macosx/tkMacOSXPrivate.h (new):	and prototypes that are purely
	internal and private to the 'macosx' sources into a new internal header
	file that does _not_ get installed into Tk.framework/PrivateHeaders.

	* macosx/tkMacOSXButton.c:		#include new tkMacOSXPrivate.h
	* macosx/tkMacOSXCarbonEvents.c:	instead of tkMacOSXInt.h.
	* macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXColor.c:
	* macosx/tkMacOSXCursor.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXHLEvents.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.5.2.10 2007/04/29 02:26:49 das Exp $
d17 1
a17 1
#include "tkMacOSXPrivate.h"
@


1.5.2.12
log
@	* 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)
@
text
@d9 1
a9 1
 * Copyright (c) 2006-2009 Daniel A. Steffen <das@@users.sourceforge.net>
d14 1
a14 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.5.2.11 2007/06/29 03:22:02 das Exp $
d495 2
a496 2
	sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d",
		(int)theErr);
d505 28
a532 5
	Size size;

	if (theDesc.descriptorType == (DescType)typeAlias &&
		AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, NULL,
		0, &size) == noErr && size == sizeof(FSRef)) {
d534 2
d537 11
a547 2
	    theErr = AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL,
		    &file, size, NULL);
a549 1

d552 1
a552 2
		    tclErr = Tcl_EvalFile(interp,
			    Tcl_DStringValue(&scriptName));
a559 9
	} else if (AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL,
		NULL, 0, &size) == noErr && size) {
	    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);
	    }
d562 1
a562 2
		    "AEDoScriptHandler: invalid script type '%-4.4s', "
		    "must be 'alis' or coercable to 'utf8'",
d582 1
a582 1
	    AEPutParamPtr(reply, keyErrorNumber, typeSInt32,
d648 2
a649 2
   err = AEGetAttributePtr(theEvent, keyMissedKeywordAttr,
	    typeWildCard, &returnedType, NULL, 0, &actualSize);
@


1.4
log
@	* macosx/tkMacOSXHLEvents.c: fixed conversion of apple event
	parameters to posix style path names.
	[Bug #621672] (steffen, Benjamin Riefenstahl)

	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXWm.c:
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkMacOSXUtil.c (removed):
	* macosx/tkMacOSXUtil.h (removed): removed all references to
	tkMacOSXUtil.{c,h}, made obsolete by the patch above. [Bug #621672]
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.3 2002/09/12 17:34:16 das Exp $
d487 1
a487 1
        Tcl_UtfToExternalDString(NULL, fileName, -1, ds);
@


1.3
log
@	* generic/tk.h:
	* mac/tkMacApplication.r:
	* mac/tkMacLibrary.r:
	* mac/tkMacResource.r:
	* macosx/tkAboutDlg.r:
	* macosx/tkMacOSXApplication.r:
	* macosx/tkMacOSXLibrary.r:
	* macosx/tkMacOSXResource.r: unified use of the two equivalent
	resource compiler header inclusion defines RC_INVOKED and
	RESOURCE_INCLUDED, now use RC_INVOKED throughout.

	* macosx/tkMacOSXAppInit.c: improved detection of Wish startup
	by the finder (by checking if stdin is /dev/null), in which
	case we want to bring up the Tk console window.

	* macosx/tkMacOSXHLEvents.c: added 'rapp' apple event handler.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.2 2002/08/31 06:12:30 das Exp $
d16 1
a16 1
#include "tkMacOSXUtil.h"
d47 1
d104 1
a104 1
        err = AEInstallEventHandler('misc', 'dosc',
d205 1
a205 1
    FSSpec file;
d250 2
a251 5
        int length;
        Handle fullPath;
        
        err = AEGetNthPtr(&fileSpecList, index, typeFSS,
                &keyword, &type, (Ptr) &file, sizeof(FSSpec), &actual);
d256 5
a260 8
        err = FSpPathFromLocation(&file, &length, &fullPath);
        HLock(fullPath);
        Tcl_ExternalToUtfDString(NULL, *fullPath, length, &pathName);
        HUnlock(fullPath);
        DisposeHandle(fullPath);

        Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
        Tcl_DStringFree(&pathName);
d317 1
a317 1
        if (theDesc.descriptorType == (DescType)'TEXT') {
d341 1
a341 1
        } else if (theDesc.descriptorType == (DescType)'alis') {
d343 8
a350 6
            FSSpec theFSS;
            Handle fullPath;
            int length;
            AliasHandle aliasHandle;

            AEGetDescData (&theDesc,&aliasHandle,sizeof(aliasHandle ) );
d352 6
a357 2
            theErr = ResolveAlias(NULL, aliasHandle,
                    &theFSS, &dummy);
d359 6
a364 5
                FSpPathFromLocation(&theFSS, &length, &fullPath);
                HLock(fullPath);
                Tcl_EvalFile(interp, *fullPath);
                HUnlock(fullPath);
                DisposeHandle(fullPath);
d461 29
@


1.2
log
@	*** macosx-8-4-branch merged into the mainline [tcl patch #602770] ***

	* generic/tk.decls:
	* generic/tkInt.decls: added new "aqua" specific entries to the
	stubs tables. Changed all "unix" entries to "x11" to allow us to
	distinguish and build both "aqua" on MacOSX and "x11" on MacOSX.

	* generic/tk.h: added a #ifnded RESOURCE_INCLUDED so that tk.h can
	be passed to the resource compiler.

	* generic/tkCmds.c (Tk_TkObjCmd): added [tk windowingsystem]
	subcommand: returns "x11" when running on X11, "win32" on Windows,
	"classic" on MacOS9 and "aqua" on MacOSX Aqua (i.e. Carbon)

	* generic/tkFont.c (TkFontGetFirstTextLayout): new private function
	returning the first chunk of a Tk_TextLayout, i.e. until the first
	font change on the first line (or the whole first line if there is
	no such font change).

	* generic/tkMain.c: made Tcl_ThreadDataKey static

	* library/demos/puzzle.tcl: fixed button metrics for aqua

	* tests/cursor.test: check for presence of arrow cursor instead of
	heart cursor

	* xlib/xcolors.c: changed xColors static initialization to more
	standard C

	* macosx/Wish.pbproj/jingham.pbxuser (new):
	* macosx/Wish.pbproj/project.pbxproj (new): project for Apple's
	ProjectBuilder IDE.

	* macosx/Makefile (new): simple makefile for building the project
	from the command line via the ProjectBuilder tool 'pbxbuild'.

	* macosx/tkMacOSXAppInit.c (new): macosx specific AppInit looking
	for a AppMain.tcl file in its bundled Resources/Scripts folder. If
	present, argv[1] is set to that file and the Scripts folder is
	added to the auto_path. This allows tk apps to embed scripts within
	their bundle directory structure.

	* macosx/tkMacOSXInit.c (new): macosx adapted version of
	tkUnixInit.c: we initialize & cache the Carbon native encoding
	(e.g. 'macRoman') and try to find the tk script library files
	inside Tk packaged as a framework.

	* macosx/tkMacOSXNotify.c (new): new macosx specific merged
	Carbon/select-based notifier.

	* macosx/tkMacOSXEvent.c (new):
	* macosx/tkMacOSXEvent.h (new):
	* macosx/tkMacOSXKeyEvent.c (new):
	* macosx/tkMacOSXMouseEvent.c (new):
	* macosx/tkMacOSXWindowEvent.c (new): new macosx specific event
	handling functionality.

	* macosx/tkMacOSX.h (new):
	* macosx/tkMacOSXBitmap.c (new):
	* macosx/tkMacOSXButton.c (new):
	* macosx/tkMacOSXClipboard.c (new):
	* macosx/tkMacOSXColor.c (new):
	* macosx/tkMacOSXConfig.c (new):
	* macosx/tkMacOSXCursor.c (new):
	* macosx/tkMacOSXDefault.h (new):
	* macosx/tkMacOSXDialog.c (new):
	* macosx/tkMacOSXDraw.c (new):
	* macosx/tkMacOSXEmbed.c (new):
	* macosx/tkMacOSXFont.c (new):
	* macosx/tkMacOSXHLEvents.c (new):
	* macosx/tkMacOSXInt.h (new):
	* macosx/tkMacOSXKeyboard.c (new):
	* macosx/tkMacOSXMenu.c (new):
	* macosx/tkMacOSXMenubutton.c (new):
	* macosx/tkMacOSXMenus.c (new):
	* macosx/tkMacOSXPort.h (new):
	* macosx/tkMacOSXRegion.c (new):
	* macosx/tkMacOSXScale.c (new):
	* macosx/tkMacOSXScrlbr.c (new):
	* macosx/tkMacOSXSubwindows.c (new):
	* macosx/tkMacOSXTest.c (new):
	* macosx/tkMacOSXUtil.c (new):
	* macosx/tkMacOSXUtil.h (new):
	* macosx/tkMacOSXWm.c (new):
	* macosx/tkMacOSXWm.h (new):
	* macosx/tkMacOSXXStubs.c (new): macosx ports of classic mac Tk
	implementation in tk/mac.

	* macosx/tkMacOSXSend.c (new): only send to local interp
	implemented currently.

	* macosx/tkMacOSXDebug.h (new):
	* macosx/tkMacOSXDebug.c (new): new macosx specific functions for
	debugging MacOS events, regions, etc.

	* macosx/tkAboutDlg.r (new):
	* macosx/tkMacOSXApplication.r (new):
	* macosx/tkMacOSXCursors.r (new):
	* macosx/tkMacOSXLibrary.r (new):
	* macosx/tkMacOSXMenu.r (new):
	* macosx/tkMacOSXResource.r (new):
	* macosx/tkMacOSXXCursors.r (new):
	* macosx/tclets.r (new): sources for Rez resource compiler.

	* macosx/Wish.icns (new): Wish application icon.

	* generic/tk.h:
	* generic/default.h:
	* generic/tkBind.c:
	* generic/tkCmds.c:
	* generic/tkGrab.c:
	* generic/tkPointer.c:
	* generic/tkPort.h:
	* generic/tkSelect.c:
	* generic/tkStubLib.c:
	* generic/tkTest.c:
	* generic/tkText.c:
	* generic/tkWindow.c:
	* unix/tkUnix3d.c:
	* xlib/xgc.c:
	* xlib/X11/X.h:
	* xlib/X11/Xlib.h:
	* xlib/X11/Xutil.h: added #includes and #ifdefs for macosx

	* library/bgerror.tcl:
	* library/button.tcl:
	* library/console.tcl:
	* library/dialog.tcl:
	* library/entry.tcl:
	* library/listbox.tcl:
	* library/menu.tcl:
	* library/msgbox.tcl:
	* library/scrlbar.tcl:
	* library/spinbox.tcl:
	* library/text.tcl:
	* library/tk.tcl:
	* library/demos/menu.tcl:
	* library/demos/menubu.tcl:
	* library/demos/widget: check [tk windowingsystem] instead of
	and/or in addition to $tcl_platform(platform).

	* generic/tkInt.h:
	* mac/tkMacBitmap.c:
	* mac/tkMacWm.c: added missing CONSTification

	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkPlatDecls.h:
	* generic/tkStubInit.c: regen
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id$
d39 1
d70 1
a70 1
    AEEventHandlerUPP        OappHandlerUPP, OdocHandlerUPP,
d85 4
d171 7
@


1.1
log
@file tkMacOSXHLEvents.c was initially added on branch macosx-8-4-branch.
@
text
@d1 447
@


1.1.2.1
log
@First checkin of support for Tk on Mac OS X.
@
text
@a0 420
/* 
 * tkMacOSXHLEvents.c --
 *
 *        Implements high level event support for the Macintosh.  Currently, 
 *        the only event that really does anything is the Quit event.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001, Apple Computer, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @@(#) $Id$
 */

#include "tcl.h"
#include "tkMacOSXUtil.h"
#include "tkMacOSXInt.h"

#include <Carbon/Carbon.h>

/*
 * This is a Tcl_Event structure that the Quit AppleEvent handler
 * uses to schedule the tkReallyKillMe function.
 */
 
typedef struct KillEvent {
    Tcl_Event header;                /* Information that is standard for
                                 * all events. */
    Tcl_Interp *interp;                /* Interp that was passed to the
                                 * Quit AppleEvent */
} KillEvent;

/*
 * Static functions used only in this file.
 */

static OSErr QuitHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);
static OSErr OappHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);
static OSErr OdocHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);
static OSErr PrintHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);
static OSErr ScriptHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);

static int MissedAnyParameters _ANSI_ARGS_((const AppleEvent *theEvent));
static int ReallyKillMe _ANSI_ARGS_((Tcl_Event *eventPtr, int flags));

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXInitAppleEvents --
 *
 *        Initilize the Apple Events on the Macintosh.  This registers the
 *        core event handlers.
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        None.
 *
 *----------------------------------------------------------------------
 */

void 
TkMacOSXInitAppleEvents(
    Tcl_Interp *interp)                /* Interp to handle basic events. */
{
    OSErr err;
    AEEventHandlerUPP        OappHandlerUPP, OdocHandlerUPP,
        PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP;
        
    /*
     * Install event handlers for the core apple events.
     */
    QuitHandlerUPP = NewAEEventHandlerUPP(QuitHandler);
    err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
            QuitHandlerUPP, (long) interp, false);

    OappHandlerUPP = NewAEEventHandlerUPP(OappHandler);
    err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
            OappHandlerUPP, (long) interp, false);

    OdocHandlerUPP = NewAEEventHandlerUPP(OdocHandler);
    err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
            OdocHandlerUPP, (long) interp, false);

    PrintHandlerUPP = NewAEEventHandlerUPP(PrintHandler);
    err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
            PrintHandlerUPP, (long) interp, false);

    if (interp != NULL) {
        ScriptHandlerUPP = NewAEEventHandlerUPP(ScriptHandler);
        err = AEInstallEventHandler('misc', 'dosc',
            ScriptHandlerUPP, (long) interp, false);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXDoHLEvent --
 *
 *        Dispatch incomming highlevel events.
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        Depends on the incoming event.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXDoHLEvent(EventRecord *theEvent)
{
    return AEProcessAppleEvent(theEvent);
}

/*
 *----------------------------------------------------------------------
 *
 * QuitHandler, OappHandler, etc. --
 *
 *        These are the core Apple event handlers.  Only the Quit event does
 *        anything interesting.
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        None.
 *
 *----------------------------------------------------------------------
 */
OSErr QuitHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
{
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
    KillEvent *eventPtr;
    
    /*
     * Call the exit command from the event loop, since you are not supposed
     * to call ExitToShell in an Apple Event Handler.  We put this at the head
     * of Tcl's event queue because this message usually comes when the Mac is
     * shutting down, and we want to kill the shell as quickly as possible.
     */
    
    eventPtr = (KillEvent *) ckalloc(sizeof(KillEvent));
    eventPtr->header.proc = ReallyKillMe;
    eventPtr->interp = interp;
     
    Tcl_QueueEvent((Tcl_Event *) eventPtr, TCL_QUEUE_HEAD);

    return noErr;
}


OSErr OappHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
{
    return noErr;
}

static OSErr OdocHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
{
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
    AEDescList fileSpecList;
    FSSpec file;
    OSErr err;
    DescType type;
    Size actual;
    long count;
    AEKeyword keyword;
    long index;
    Tcl_DString command;
    Tcl_DString pathName;
    Tcl_CmdInfo dummy;

    /*
     * Don't bother if we don't have an interp or
     * the open document procedure doesn't exist.
     */

    if ((interp == NULL) || 
            (Tcl_GetCommandInfo(interp, "::tk::mac::OpenDocument", &dummy)) == 0) {
            return noErr;
    }
    
    /*
     * If we get any errors wil retrieving our parameters
     * we just return with no error.
     */

    err = AEGetParamDesc(event, keyDirectObject,
            typeAEList, &fileSpecList);
    if (err != noErr) {
        return noErr;
    }

    err = MissedAnyParameters(event);
    if (err != noErr) {
        return noErr;
    }

    err = AECountItems(&fileSpecList, &count);
    if (err != noErr) {
        return noErr;
    }

    Tcl_DStringInit(&command);
    Tcl_DStringAppend(&command, "::tk::mac::OpenDocument", -1);
    for (index = 1; index <= count; index++) {
        int length;
        Handle fullPath;
        
        err = AEGetNthPtr(&fileSpecList, index, typeFSS,
                &keyword, &type, (Ptr) &file, sizeof(FSSpec), &actual);
        if ( err != noErr ) {
            continue;
        }

        err = FSpPathFromLocation(&file, &length, &fullPath);
        HLock(fullPath);
        Tcl_ExternalToUtfDString(NULL, *fullPath, length, &pathName);
        HUnlock(fullPath);
        DisposeHandle(fullPath);

        Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
        Tcl_DStringFree(&pathName);
    }
    
    Tcl_GlobalEval(interp, Tcl_DStringValue(&command));

    Tcl_DStringFree(&command);
    return noErr;
}

OSErr PrintHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
{
    return noErr;
}

/*
 *----------------------------------------------------------------------
 *
 * ScriptHandler --
 *
 *        This handler process the script event.  
 *
 * Results:
 *        Scedules the given event to be processed.
 *
 * Side effects:
 *        None.
 *
 *----------------------------------------------------------------------
 */

OSErr ScriptHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
{
    OSErr theErr;
    AEDescList theDesc;
    int tclErr = -1;
    Tcl_Interp *interp;
    char errString[128];

    interp = (Tcl_Interp *) handlerRefcon;

    /*
     * The do script event receives one parameter that should be data or a file.
     */
    theErr = AEGetParamDesc(event, keyDirectObject, typeWildCard,
            &theDesc);
    if (theErr != noErr) {
        sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d", theErr);
        theErr = AEPutParamPtr(reply, keyErrorString, typeChar, errString,
                strlen(errString));
    } else if (MissedAnyParameters(event)) {
        sprintf(errString, "AEDoScriptHandler: extra parameters");
        AEPutParamPtr(reply, keyErrorString, typeChar, errString,
                strlen(errString));
        theErr = -1771;
    } else {
        if (theDesc.descriptorType == (DescType)'TEXT') {
            Tcl_DString encodedText;
            short i;
            Size  size;
            char  * data;
            
            size = AEGetDescDataSize(&theDesc);
            
            data = (char *)ckalloc(size + 1);
            if ( !data ) {
                theErr = -1771;
            }
            else {
                   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_GlobalEval(interp, Tcl_DStringValue(&encodedText));
            Tcl_DStringFree(&encodedText);
        } else if (theDesc.descriptorType == (DescType)'alis') {
            Boolean dummy;
            FSSpec theFSS;
            Handle fullPath;
            int length;
            AliasHandle aliasHandle;

            AEGetDescData (&theDesc,&aliasHandle,sizeof(aliasHandle ) );
            
            theErr = ResolveAlias(NULL, aliasHandle,
                    &theFSS, &dummy);
            if (theErr == noErr) {
                FSpPathFromLocation(&theFSS, &length, &fullPath);
                HLock(fullPath);
                Tcl_EvalFile(interp, *fullPath);
                HUnlock(fullPath);
                DisposeHandle(fullPath);
            } else {
                sprintf(errString, "AEDoScriptHandler: file not found");
                AEPutParamPtr(reply, keyErrorString, typeChar,
                        errString, strlen(errString));
            }
        } else {
            sprintf(errString,
                    "AEDoScriptHandler: invalid script type '%-4.4s', must be 'alis' or 'TEXT'",
                    (char *)(&theDesc.descriptorType));
            AEPutParamPtr(reply, keyErrorString, typeChar,
                    errString, strlen(errString));
            theErr = -1770;
        }
    }

    /*
     * If we actually go to run Tcl code - put the result in the reply.
     */
    if (tclErr >= 0) {
        if (tclErr == TCL_OK)  {
            AEPutParamPtr(reply, keyDirectObject, typeChar,
                Tcl_GetStringResult(interp),
                strlen(Tcl_GetStringResult(interp)));
        } else {
            AEPutParamPtr(reply, keyErrorString, typeChar,
                Tcl_GetStringResult(interp),
                strlen(Tcl_GetStringResult(interp)));
            AEPutParamPtr(reply, keyErrorNumber, typeInteger,
                (Ptr) &tclErr, sizeof(int));
        }
    }
        
    AEDisposeDesc(&theDesc);

    return theErr;
}

/*
 *----------------------------------------------------------------------
 *
 * ReallyKillMe --
 *
 *        This proc tries to kill the shell by running exit, and if that 
 *      has not succeeded (e.g. because someone has renamed the exit 
 *      command), calls Tcl_Exit to really kill the shell.  Called from 
 *      an event scheduled by the "Quit" AppleEvent handler.
 *
 * Results:
 *        Kills the shell.
 *
 * Side effects:
 *        None.
 *
 *----------------------------------------------------------------------
 */

int 
ReallyKillMe(Tcl_Event *eventPtr, int flags) 
{
    Tcl_Interp *interp = ((KillEvent *) eventPtr)->interp;
    if (interp != NULL) {
        Tcl_GlobalEval(interp, "exit");
    }
    Tcl_Exit(0);
    
    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * MissedAnyParameters --
 *
 *        Checks to see if parameters are still left in the event.  
 *
 * Results:
 *        True or false.
 *
 * Side effects:
 *        None.
 *
 *----------------------------------------------------------------------
 */
 
static int 
MissedAnyParameters(
    const AppleEvent *theEvent)
{
   DescType returnedType;
   Size actualSize;
   OSErr err;

   err = AEGetAttributePtr(theEvent, keyMissedKeywordAttr, typeWildCard, 
                   &returnedType, NULL, 0, &actualSize);
   
   return (err != errAEDescNotFound);
}
@


1.1.2.2
log
@Merge with current TOT
Added support for the wm stackorder command
Fixed crash when selecting Menu items in the Application menu that we didn't
put there.
Added first bits of the use of CG for low-level drawing.  The line-drawing works,
the rest doesn't yet.  You have to set the file static useCGDrawing to 1 and
rebuild to activate this code.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.1.2.1 2001/10/15 09:22:00 wolfsuit Exp $
d16 1
@


1.1.2.3
log
@encodings, events
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.1.2.2 2002/02/05 02:25:17 wolfsuit Exp $
d249 1
a249 1
 *        Schedules the given event to be processed.
@


1.1.2.4
log
@encodings, and wm updates
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXHLEvents.c,v 1.1.2.3 2002/07/18 23:45:18 vincentdarley Exp $
a41 1
static OSErr PrefsHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon);
d69 1
a69 2
        PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP,
        PrefsHandlerUPP;
a89 4
    PrefsHandlerUPP = NewAEEventHandlerUPP(PrefsHandler);
    err = AEInstallEventHandler(kCoreEventClass, kAEShowPreferences,
            PrefsHandlerUPP, (long) interp, false);

a155 5
static OSErr 
OappHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
{
    return noErr;
}
d157 1
a157 3
/* Called when the user selects 'Preferences...' in MacOS X */
static OSErr 
PrefsHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
a158 12
    Tcl_CmdInfo dummy;
    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
    /*
     * Don't bother if we don't have an interp or
     * the show preferences procedure doesn't exist.
     */

    if ((interp == NULL) || 
            (Tcl_GetCommandInfo(interp, "::tk::mac::ShowPreferences", &dummy)) == 0) {
            return noErr;
    }
    Tcl_GlobalEval(interp, "::tk::mac::ShowPreferences");
d162 1
a162 2
static OSErr 
OdocHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
d236 1
a236 2
static OSErr 
PrintHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
d257 1
a257 2
static OSErr 
ScriptHandler (const AppleEvent * event, AppleEvent * reply, long handlerRefcon)
d379 1
a379 1
static int 
@


