head	1.27;
access;
symbols
	core-8-5-9:1.23
	core-8-5-8:1.23
	macosx-cocoa-merge:1.26
	macosx-cocoa-premerge:1.25
	macosx-carbon-freeze:1.25
	core-8-5-7:1.23
	core-8-5-6:1.23
	core-8-6-b1:1.25
	core-8-6-a3:1.23
	core-8-5-5:1.23
	core-8-6-a2:1.23
	core-8-5-4:1.23
	core-8-5-3:1.23
	core-8-6-a1:1.23
	core-8-4-19:1.3.2.16
	core-8-5-branch:1.23.0.2
	core-8-5-2:1.23
	core-8-4-18:1.3.2.16
	core-8-5-1:1.23
	core-8-4-17:1.3.2.16
	core-8-5-0:1.23
	core-8-5-b3:1.22
	core-8-5-b2:1.21
	core-8-4-16:1.3.2.15
	core-8-5-b1:1.21
	core-stablilizer-merge:1.21
	core-stabilizer-branch:1.16.0.2
	core-stabilizer-merge:1.23
	core-8-4-15:1.3.2.10
	core-8-5-a6:1.16
	core-8-5-a5:1.11
	core-8-4-14:1.3.2.8
	core-8-5-a4:1.10
	core-8-4-13:1.3.2.6
	core-8-4-12:1.3.2.4
	core-8-4-11:1.3.2.1
	core-8-5-a3:1.5
	core-8-4-10:1.3.2.1
	core-8-4-9-branch:1.3.2.1.0.2
	core-8-5-a2:1.5
	core-8-4-9:1.3.2.1
	core-8-4-8:1.3.2.1
	core-8-4-7:1.3.2.1
	core-8-5-a1:1.5
	core-8-4-6:1.3.2.1
	core-8-4-5:1.3
	mistachkin-dev-branch:1.4.0.2
	core-8-4-4:1.3
	core-8-4-3:1.3
	core-8-4-branch:1.3.0.2
	core-8-4-2:1.3
	core-8-4-1:1.2
	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.3
	macosx-8-4-merge-2002-08-30-branch:1.1.2.3
	macosx-8-4-merge-2002-08-20-branch:1.1.2.3
	macosx-premerge-6-9-02:1.1.2.2
	macosx-8-4-branch:1.1.0.2;
locks; strict;
comment	@ * @;


1.27
date	2009.07.06.20.29.21;	author dkf;	state Exp;
branches;
next	1.26;

1.26
date	2009.06.29.14.35.01;	author das;	state Exp;
branches;
next	1.25;

1.25
date	2008.12.10.05.02.52;	author das;	state Exp;
branches;
next	1.24;

1.24
date	2008.10.27.11.55.44;	author dkf;	state Exp;
branches;
next	1.23;

1.23
date	2007.12.13.15.27.09;	author dgp;	state Exp;
branches;
next	1.22;

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

1.21
date	2007.06.29.03.20.01;	author das;	state Exp;
branches;
next	1.20;

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

1.19
date	2007.06.06.09.55.52;	author das;	state Exp;
branches;
next	1.18;

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

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

1.16
date	2007.04.23.23.10.10;	author das;	state Exp;
branches
	1.16.2.1;
next	1.15;

1.15
date	2007.04.23.21.24.33;	author das;	state Exp;
branches;
next	1.14;

1.14
date	2007.04.21.19.06.38;	author hobbs;	state Exp;
branches;
next	1.13;

1.13
date	2007.04.13.14.51.18;	author dkf;	state Exp;
branches;
next	1.12;

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

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

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

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

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

1.7
date	2005.09.10.14.53.20;	author das;	state Exp;
branches;
next	1.6;

1.6
date	2005.08.09.07.39.20;	author das;	state Exp;
branches;
next	1.5;

1.5
date	2004.02.16.00.19.42;	author wolfsuit;	state Exp;
branches;
next	1.4;

1.4
date	2003.09.30.23.26.09;	author wolfsuit;	state Exp;
branches;
next	1.3;

1.3
date	2003.02.19.19.27.46;	author wolfsuit;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2002.08.31.06.12.29;	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.06.10.05.38.26;	author wolfsuit;	state Exp;
branches;
next	;

1.3.2.1
date	2004.02.16.00.42.34;	author wolfsuit;	state Exp;
branches;
next	1.3.2.2;

1.3.2.2
date	2005.08.09.07.39.55;	author das;	state Exp;
branches;
next	1.3.2.3;

1.3.2.3
date	2005.09.10.14.54.17;	author das;	state Exp;
branches;
next	1.3.2.4;

1.3.2.4
date	2005.11.27.02.36.46;	author das;	state Exp;
branches;
next	1.3.2.5;

1.3.2.5
date	2006.03.28.02.44.13;	author das;	state Exp;
branches;
next	1.3.2.6;

1.3.2.6
date	2006.04.11.10.22.57;	author das;	state Exp;
branches;
next	1.3.2.7;

1.3.2.7
date	2006.04.28.06.02.59;	author das;	state Exp;
branches;
next	1.3.2.8;

1.3.2.8
date	2006.05.12.18.17.55;	author das;	state Exp;
branches;
next	1.3.2.9;

1.3.2.9
date	2006.10.31.22.33.38;	author das;	state Exp;
branches;
next	1.3.2.10;

1.3.2.10
date	2007.04.29.02.26.49;	author das;	state Exp;
branches;
next	1.3.2.11;

1.3.2.11
date	2007.05.30.06.39.38;	author das;	state Exp;
branches;
next	1.3.2.12;

1.3.2.12
date	2007.05.31.13.42.12;	author das;	state Exp;
branches;
next	1.3.2.13;

1.3.2.13
date	2007.06.06.09.56.54;	author das;	state Exp;
branches;
next	1.3.2.14;

1.3.2.14
date	2007.06.09.17.10.21;	author das;	state Exp;
branches;
next	1.3.2.15;

1.3.2.15
date	2007.06.29.03.22.02;	author das;	state Exp;
branches;
next	1.3.2.16;

1.3.2.16
date	2007.11.09.06.26.55;	author das;	state Exp;
branches;
next	;

1.16.2.1
date	2007.05.30.13.47.43;	author dgp;	state Exp;
branches;
next	1.16.2.2;

1.16.2.2
date	2007.06.01.04.01.33;	author dgp;	state Exp;
branches;
next	1.16.2.3;

1.16.2.3
date	2007.06.12.16.22.42;	author dgp;	state Exp;
branches;
next	1.16.2.4;

1.16.2.4
date	2007.07.01.17.31.32;	author dgp;	state Exp;
branches;
next	1.16.2.5;

1.16.2.5
date	2007.11.05.14.24.18;	author dgp;	state Exp;
branches;
next	;


desc
@@


1.27
log
@More marking of files as Objective-C.
@
text
@/*
 * tkMacOSXEvent.c --
 *
 *	This file contains the basic Mac OS X Event handling routines.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright 2001-2009, Apple Inc.
 * Copyright (c) 2005-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: tkMacOSXEvent.c,v 1.26 2009/06/29 14:35:01 das Exp $
 */

#include "tkMacOSXPrivate.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXDebug.h"

#pragma mark TKApplication(TKEvent)

enum {
    NSWindowWillMoveEventType = 20
};

@@implementation TKApplication(TKEvent)
/* TODO: replace by +[addLocalMonitorForEventsMatchingMask ? */
- (NSEvent *) tkProcessEvent: (NSEvent *) theEvent
{
#ifdef TK_MAC_DEBUG_EVENTS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, theEvent);
#endif
    NSEvent	    *processedEvent = theEvent;
    NSEventType	    type = [theEvent type];
    NSInteger	    subtype;
    NSUInteger	    flags;

    switch ((NSInteger)type) {
    case NSAppKitDefined:
        subtype = [theEvent subtype];

	switch (subtype) {
	case NSApplicationActivatedEventType:
	    break;
	case NSApplicationDeactivatedEventType:
	    break;
	case NSWindowExposedEventType:
	case NSScreenChangedEventType:
	    break;
	case NSWindowMovedEventType:
	    break;
        case NSWindowWillMoveEventType:
            break;

        default:
            break;
	}
	break;
    case NSKeyUp:
    case NSKeyDown:
    case NSFlagsChanged:
	flags = [theEvent modifierFlags];
	processedEvent = [self tkProcessKeyEvent:theEvent];
	break;
    case NSLeftMouseDown:
    case NSLeftMouseUp:
    case NSRightMouseDown:
    case NSRightMouseUp:
    case NSLeftMouseDragged:
    case NSRightMouseDragged:
    case NSMouseMoved:
    case NSMouseEntered:
    case NSMouseExited:
    case NSScrollWheel:
    case NSOtherMouseDown:
    case NSOtherMouseUp:
    case NSOtherMouseDragged:
    case NSTabletPoint:
    case NSTabletProximity:
	processedEvent = [self tkProcessMouseEvent:theEvent];
	break;
#if 0
    case NSSystemDefined:
        subtype = [theEvent subtype];
	break;
    case NSApplicationDefined: {
	id win;
	win = [theEvent window];
	break;
	}
    case NSCursorUpdate:
        break;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
    case NSEventTypeGesture:
    case NSEventTypeMagnify:
    case NSEventTypeRotate:
    case NSEventTypeSwipe:
    case NSEventTypeBeginGesture:
    case NSEventTypeEndGesture:
        break;
#endif
#endif

    default:
	break;
    }
    return processedEvent;
}
@@end

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXFlushWindows --
 *
 *	This routine flushes all the windows of the application. It is
 *	called by XSync().
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Flushes all Carbon windows
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE void
TkMacOSXFlushWindows(void)
{
    NSInteger windowCount;
    NSInteger *windowNumbers;

    NSCountWindows(&windowCount);
    if(windowCount) {
	windowNumbers = (NSInteger *) ckalloc(windowCount * sizeof(NSInteger));
	NSWindowList(windowCount, windowNumbers);
	for (NSInteger index = 0; index < windowCount; index++) {
	    NSWindow *w = [NSApp windowWithWindowNumber:windowNumbers[index]];
	    if (TkMacOSXGetXWindow(w)) {
		[w flushWindow];
	    }
	}
	ckfree((char*) windowNumbers);
    }
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */
@


1.26
log
@Merge of TkAqua Cocoa port
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.25 2008/12/10 05:02:52 das Exp $
d28 2
a29 1
- (NSEvent *)tkProcessEvent:(NSEvent *)theEvent {
d152 1
a152 1
 * mode: c
@


1.25
log
@TIP #324 IMPLEMENTATION
@
text
@d7 2
a8 2
 * Copyright 2001, Apple Computer, Inc.
 * Copyright (c) 2005-2007 Daniel A. Steffen <das@@users.sourceforge.net>
d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.24 2008/10/27 11:55:44 dkf Exp $
a18 17

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXFlushWindows --
 *
 *	This routine flushes all the Carbon windows of the application. It is
 *	called by XSync().
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Flushes all Carbon windows
 *
 *----------------------------------------------------------------------
 */
d20 1
a20 4
MODULE_SCOPE void
TkMacOSXFlushWindows(void)
{
    WindowRef wRef = GetWindowList();
d22 18
a39 5
    while (wRef) {
	TK_IF_MAC_OS_X_API (3, HIWindowFlush,
	    ChkErr(HIWindowFlush, wRef);
	) TK_ELSE_MAC_OS_X (3,
	    CGrafPtr portPtr = GetWindowPort(wRef);
d41 12
a52 30
	    if (QDIsPortBuffered(portPtr)) {
		QDFlushPortBuffer(portPtr, NULL);
	    }
	) TK_ENDIF
	wRef = GetNextWindow(wRef);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessEvent --
 *
 *	This dispatches a filtered Carbon event to the appropriate handler
 *
 *	Note on MacEventStatus.stopProcessing: Please be conservative in the
 *	individual handlers and don't assume the event is fully handled unless
 *	you *really* need to ensure that other handlers don't see the event
 *	anymore. Some OS manager or library might be interested in events even
 *	after they are already handled on the Tk level.
 *
 * Results:
 *	0 on success
 *	-1 on failure
 *
 * Side effects:
 *	Converts a Carbon event to a Tk event
 *
 *----------------------------------------------------------------------
 */
d54 3
a56 8
MODULE_SCOPE int
TkMacOSXProcessEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
{
    switch (eventPtr->eClass) {
    case kEventClassMouse:
	TkMacOSXProcessMouseEvent(eventPtr, statusPtr);
d58 30
a87 2
    case kEventClassWindow:
	TkMacOSXProcessWindowEvent(eventPtr, statusPtr);
d89 15
a103 21
    case kEventClassKeyboard:
	TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr);
	break;
    case kEventClassApplication:
	TkMacOSXProcessApplicationEvent(eventPtr, statusPtr);
	break;
    case kEventClassAppearance:
	TkMacOSXProcessAppearanceEvent(eventPtr, statusPtr);
	break;
    case kEventClassMenu:
	TkMacOSXProcessMenuEvent(eventPtr, statusPtr);
	break;
    case kEventClassCommand:
	TkMacOSXProcessCommandEvent(eventPtr, statusPtr);
	break;
    case kEventClassFont:
	TkMacOSXProcessFontEvent(eventPtr, statusPtr);
	break;
    default: {
	TkMacOSXDbgMsg("Unrecognised event: %s",
		TkMacOSXCarbonEventToAscii(eventPtr->eventRef));
d106 1
a106 2
    }
    return 0;
d108 1
a108 53

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessMenuEvent --
 *
 *	This routine processes the event in eventPtr, and generates the
 *	appropriate Tk events from it.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE int
TkMacOSXProcessMenuEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
{
    int menuContext;
    OSStatus err;
    MenuRef menu;
    MenuItemIndex index;

    switch (eventPtr->eKind) {
    case kEventMenuBeginTracking:
    case kEventMenuEndTracking:
    case kEventMenuOpening:
    case kEventMenuTargetItem:
	break;
    default:
	return 0;
    }
    err = ChkErr(GetEventParameter, eventPtr->eventRef,
	    kEventParamMenuContext, typeUInt32, NULL, sizeof(menuContext),
	    NULL, &menuContext);
    if (err != noErr) {
	return 0;
    }

    if ((menuContext & kMenuContextMenuBarTracking) ||
	    (menuContext & kMenuContextPopUpTracking)) {
	switch (eventPtr->eKind) {
	case kEventMenuBeginTracking:
	    TkMacOSXClearMenubarActive();

	    /*
	     * Handle -postcommand
	     */
d110 1
a110 34
	    TkMacOSXPreprocessMenu();
	    TkMacOSXTrackingLoop(1);
	    break;
	case kEventMenuEndTracking:
	    TkMacOSXTrackingLoop(0);
	    break;
	case kEventMenuOpening:
	    err = ChkErr(GetEventParameter, eventPtr->eventRef,
		    kEventParamDirectObject, typeMenuRef, NULL, sizeof(menu),
		    NULL, &menu);
	    if (err != noErr) {
		return 0;
	    }
	    TkMacOSXClearActiveMenu(menu);
	    return TkMacOSXGenerateParentMenuSelectEvent(menu);
	case kEventMenuTargetItem:
	    err = ChkErr(GetEventParameter, eventPtr->eventRef,
		    kEventParamDirectObject, typeMenuRef, NULL, sizeof(menu),
		    NULL, &menu);
	    if (err != noErr) {
		return 0;
	    }

	    err = ChkErr(GetEventParameter, eventPtr->eventRef,
		    kEventParamMenuItemIndex, typeMenuItemIndex, NULL,
		    sizeof(index), NULL, &index);
	    if (err != noErr) {
		return 0;
	    }
	    return TkMacOSXGenerateMenuSelectEvent(menu, index);
	}
    }
    return 0;
}
d115 1
a115 1
 * TkMacOSXProcessCommandEvent --
d117 2
a118 2
 *	This routine processes the event in eventPtr, and generates the
 *	appropriate Tk events from it.
d121 1
a121 1
 *	True if event(s) are generated - false otherwise.
d124 1
a124 1
 *	Additional events may be place on the Tk event queue.
d129 2
a130 4
MODULE_SCOPE int
TkMacOSXProcessCommandEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
d132 2
a133 37
    HICommand command;
    int menuContext;
    OSStatus err;

    switch (eventPtr->eKind) {
    case kEventCommandProcess:
    case kEventCommandUpdateStatus:
	break;
    default:
	return 0;
    }

    err = ChkErr(GetEventParameter, eventPtr->eventRef,
	    kEventParamDirectObject, typeHICommand, NULL, sizeof(command),
	    NULL, &command);
    if (err != noErr) {
	return 0;
    }

    if (command.attributes & kHICommandFromMenu) {
	if (eventPtr->eKind == kEventCommandProcess) {
	    err = ChkErr(GetEventParameter, eventPtr->eventRef,
		    kEventParamMenuContext, typeUInt32, NULL,
		    sizeof(menuContext), NULL, &menuContext);
	    if (err != noErr) {
		return 0;
	    }

	    if ((menuContext & kMenuContextMenuBar) &&
		    (menuContext & kMenuContextMenuBarTracking)) {
		TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef),
			command.menu.menuItemIndex,
			(GetCurrentEventKeyModifiers() & optionKey) != 0);
		return 1;
	    }
	} else {
	    Tcl_CmdInfo dummy;
d135 8
a142 18
	    if (command.commandID == kHICommandPreferences
		    && eventPtr->interp != NULL) {
		if (Tcl_GetCommandInfo(eventPtr->interp,
			"::tk::mac::ShowPreferences", &dummy)) {
		    if (!IsMenuItemEnabled(command.menu.menuRef,
			    command.menu.menuItemIndex)) {
			EnableMenuItem(command.menu.menuRef,
				command.menu.menuItemIndex);
		    }
		} else {
		    if (IsMenuItemEnabled(command.menu.menuRef,
			    command.menu.menuItemIndex)) {
			DisableMenuItem(command.menu.menuRef,
				command.menu.menuItemIndex);
		    }
		}
		statusPtr->stopProcessing = 1;
		return 1;
d145 1
a146 1
    return 0;
d153 2
a154 1
 * fill-column: 78
@


1.24
log
@Code style improvements, especially including making code less deeply nested.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.23 2007/12/13 15:27:09 dgp Exp $
d106 3
@


1.23
log
@merge stable branch onto HEAD
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.16.2.5 2007/11/05 14:24:18 dgp Exp $
a18 1

d25 2
a26 2
 *	This routine flushes all the Carbon windows of the application. It
 *	is called by XSync().
d64 4
a67 4
 *	individual handlers and don't assume the event is fully handled
 *	unless you *really* need to ensure that other handlers don't see the
 *	event anymore. Some OS manager or library might be interested in
 *	events even after they are already handled on the Tk level.
d85 26
a110 26
	case kEventClassMouse:
	    TkMacOSXProcessMouseEvent(eventPtr, statusPtr);
	    break;
	case kEventClassWindow:
	    TkMacOSXProcessWindowEvent(eventPtr, statusPtr);
	    break;
	case kEventClassKeyboard:
	    TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr);
	    break;
	case kEventClassApplication:
	    TkMacOSXProcessApplicationEvent(eventPtr, statusPtr);
	    break;
	case kEventClassAppearance:
	    TkMacOSXProcessAppearanceEvent(eventPtr, statusPtr);
	    break;
	case kEventClassMenu:
	    TkMacOSXProcessMenuEvent(eventPtr, statusPtr);
	    break;
	case kEventClassCommand:
	    TkMacOSXProcessCommandEvent(eventPtr, statusPtr);
	    break;
	default: {
	    TkMacOSXDbgMsg("Unrecognised event: %s",
		    TkMacOSXCarbonEventToAscii(eventPtr->eventRef));
	    break;
	}
d120 2
a121 2
 *	This routine processes the event in eventPtr, and
 *	generates the appropriate Tk events from it.
d139 2
d143 18
d162 9
d172 2
d175 8
d184 6
a189 11
	    break;
	default:
	    return 0;
	    break;
    }
    err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamMenuContext,
	    typeUInt32, NULL, sizeof(menuContext), NULL, &menuContext);
    if (err == noErr && ((menuContext & kMenuContextMenuBarTracking) ||
	    (menuContext & kMenuContextPopUpTracking))) {
	switch (eventPtr->eKind) {
	    MenuRef menu;
d191 7
a197 37
	    case kEventMenuBeginTracking:
		TkMacOSXClearMenubarActive();

		/*
		 * Handle -postcommand
		 */

		TkMacOSXPreprocessMenu();
		TkMacOSXTrackingLoop(1);
		break;
	    case kEventMenuEndTracking:
		TkMacOSXTrackingLoop(0);
		break;
	    case kEventMenuOpening:
		err = ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamDirectObject, typeMenuRef, NULL,
			sizeof(menu), NULL, &menu);
		if (err == noErr) {
		    TkMacOSXClearActiveMenu(menu);
		    return TkMacOSXGenerateParentMenuSelectEvent(menu);
		}
		break;
	    case kEventMenuTargetItem:
		err = ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamDirectObject, typeMenuRef, NULL,
			sizeof(menu), NULL, &menu);
		if (err == noErr) {
		    MenuItemIndex index;

		    err = ChkErr(GetEventParameter, eventPtr->eventRef,
			    kEventParamMenuItemIndex, typeMenuItemIndex, NULL,
			    sizeof(index), NULL, &index);
		    if (err == noErr) {
			return TkMacOSXGenerateMenuSelectEvent(menu, index);
		    }
		}
		break;
d208 2
a209 2
 *	This routine processes the event in eventPtr, and
 *	generates the appropriate Tk events from it.
d223 1
a223 1
    MacEventStatus * statusPtr)
d230 5
a234 6
	case kEventCommandProcess:
	case kEventCommandUpdateStatus:
	    break;
	default:
	    return 0;
	    break;
d236 1
d240 5
a244 1
    if (err == noErr && (command.attributes & kHICommandFromMenu)) {
d249 5
a253 1
	    if (err == noErr && (menuContext & kMenuContextMenuBar) &&
d262 3
a264 1
	    if (command.commandID == kHICommandPreferences && eventPtr->interp) {
d286 8
@


1.22
log
@	* macosx/tkMacOSXEvent.c (TkMacOSXProcessCommandEvent): fix boolean arg
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.21 2007/06/29 03:20:01 das Exp $
@


1.21
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
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.20 2007/06/09 17:09:40 das Exp $
d246 1
a246 1
			GetCurrentEventKeyModifiers() & optionKey);
@


1.20
log
@	* macosx/tkMacOSXColor.c: fix issues with TK_{IF,ELSE,ENDIF} macros;
	* macosx/tkMacOSXDraw.c:  implement Jaguar equivalent of unavailable
	* macosx/tkMacOSXEntry.c: kHIToolboxVersion global; panic at startup
	* macosx/tkMacOSXEvent.c: if MAC_OS_X_VERSION_MIN_REQUIRED constraint
	* macosx/tkMacOSXInit.c:  is not satisfied.
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c (XCopyArea, XCopyPlane, TkPutImage)
	(TkMacOSXSetupDrawingContext): factor out common code and standardize
	setup/restore of port, context and clipping; formatting cleanup.

	* macosx/tkMacOSXWindowEvent.c:	add error checking.
	* macosx/tkMacOSXMenu.c:	fix gcc3 warning.
	* macosx/tkMacOSXScrlbr.c:	fix testsuite crash.
	* macosx/tkMacOSXSubwindows.c:	formatting cleanup.
	* macosx/tkMacOSXRegion.c:	fix typos.
	* macosx/tkMacOSXScale.c:

	* macosx/tkMacOSXXStubs.c (Tk_GetUserInactiveTime): remove superfluous
							    CFRetain/CFRelease.

	* macosx/Wish-Release.xcconfig: disable tktest release build stripping.

	* macosx/Wish.xcodeproj/project.pbxproj: add new Tclsh-Info.plist.in.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.19 2007/06/06 09:55:52 das Exp $
d16 1
a16 1
#include "tkMacOSXInt.h"
@


1.19
log
@	* macosx/tkMacOSXMouseEvent.c (GenerateMouseWheelEvent): enable
	processing of mousewheel events in background windows.

	* macosx/tkMacOSXScrlbr.c: modernize checks for active/front window.
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXColor.c: factor out verbose #ifdef checks of
	* macosx/tkMacOSXDraw.c:  MAC_OS_X_VERSION_{MAX_ALLOWED,MIN_REQUIRED}
	* macosx/tkMacOSXEntry.c: and runtime checks of kHIToolboxVersion into
	* macosx/tkMacOSXEvent.c: new TK_{IF,ELSE,ENDIF}_MAC_OS_X macros.
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c:  factor out clip clearing in QD ports;
	* macosx/tkMacOSXEntry.c: formatting cleanup.

	* macosx/Wish.xcodeproj/project.pbxproj: add settings for Fix&Continue.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.18 2007/05/31 13:38:13 das Exp $
d52 1
a52 1
	) TK_ENDIF_MAC_OS_X
@


1.18
log
@	* macosx/tkMacOSXWindowEvent.c (GenerateUpdateEvent): complete all
	pending idle-time redraws before newly posted Expose events are
	processed; add bounds of redrawn windows to update region to ensure all
	child windows overdrawn by parents are redrawn.

	* macosx/tkMacOSXWindowEvent.c:	centralize clip and window invalidation
	* macosx/tkMacOSXSubwindows.c:	after location/size changes in the
	* macosx/tkMacOSXWm.c:		BoundsChanged carbon event handler;
	correct/add window invalidation after window attribute changes.

	* macosx/tkMacOSXSubwindows.c (XResizeWindow, XMoveResizeWindow,
	XMoveWindow): factor out common code dealing with embedded and
	non-toplevel windows; remove unnecessary clip and window invalidation.

	* macosx/tkMacOSXButton.c (TkpDisplayButton): move clip setup closer to
	native button drawing calls.

	* macosx/tkMacOSXWm.c (TkMacOSXIsWindowZoomed, TkMacOSXZoomToplevel):
	correct handle gridded windows in max size calculations.

	* macosx/tkMacOSXEvent.c (TkMacOSXFlushWindows): use HIWindowFlush API
	when available.

	* macosx/tkMacOSXColor.c:	cleanup whitespace and formatting.
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.17 2007/05/30 06:35:54 das Exp $
d44 1
a44 6
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
	if (1
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1030
		&& HIWindowFlush != NULL
#endif
	) {
d46 1
a46 3
	} else
#endif
	{
d52 1
a52 1
	}
@


1.17
log
@	* macosx/tkMacOSXMenu.c (DrawMenuSeparator): use DrawingContext API.

	* macosx/tkMacOSXWindowEvent.c (ClearPort): clip to updateRgn.

	* macosx/tkMacOSXDebug.c:	factor out debug region flashing.
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:

	* macosx/tkMacOSXEvent.c:	cleanup whitespace and formatting.
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* xlib/xgc.c:

	* macosx/Wish.xcodeproj/project.pbxproj: delete references to removed
	* macosx/Wish.xcodeproj/default.pbxuser: ttk files.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.16 2007/04/23 23:10:10 das Exp $
d44 15
a58 3
	CGrafPtr portPtr = GetWindowPort(wRef);
	if (QDIsPortBuffered(portPtr)) {
	    QDFlushPortBuffer(portPtr, NULL);
@


1.16
log
@fix whitespace & formatting
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.15 2007/04/23 21:24:33 das Exp $
d27 1
a27 1
 *	is called by the setup procedure for the Tcl/Carbon event source.
@


1.16.2.1
log
@merge updates from HEAD
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.17 2007/05/30 06:35:54 das Exp $
d27 1
a27 1
 *	is called by XSync().
@


1.16.2.2
log
@merge updates from HEAD
@
text
@d44 3
a46 15
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
	if (1
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1030
		&& HIWindowFlush != NULL
#endif
	) {
	    ChkErr(HIWindowFlush, wRef);
	} else
#endif
	{
	    CGrafPtr portPtr = GetWindowPort(wRef);

	    if (QDIsPortBuffered(portPtr)) {
		QDFlushPortBuffer(portPtr, NULL);
	    }
@


1.16.2.3
log
@merge updates from HEAD
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.16.2.2 2007/06/01 04:01:33 dgp Exp $
d44 6
a49 1
	TK_IF_MAC_OS_X_API (3, HIWindowFlush,
d51 3
a53 1
	) TK_ELSE_MAC_OS_X (3,
d59 1
a59 1
	) TK_ENDIF
@


1.16.2.4
log
@merge updates from HEAD
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id$
d16 1
a16 1
#include "tkMacOSXPrivate.h"
@


1.16.2.5
log
@merge updates from HEAD
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.16.2.4 2007/07/01 17:31:32 dgp Exp $
d246 1
a246 1
			(GetCurrentEventKeyModifiers() & optionKey) != 0);
@


1.15
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
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.14 2007/04/21 19:06:38 hobbs Exp $
d39 1
a39 1
TkMacOSXFlushWindows (void)
@


1.14
log
@	* macosx/tkMacOSXBitmap.c, macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXCarbonEvents.c, macosx/tkMacOSXClipboard.c:
	* macosx/tkMacOSXCursor.c, macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c, macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXFont.c, macosx/tkMacOSXInit.c, macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXKeyEvent.c, macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c, macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXScale.c, macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c: Revert of commits from 2007-04-13 which
	broke the OS X build.
@
text
@d1 1
a1 1
/* 
d4 1
a4 1
 * This file contains the basic Mac OS X Event handling routines.
d8 1
a8 1
 * Copyright (c) 2005-2006 Daniel A. Steffen <das@@users.sourceforge.net>
d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.12 2006/10/31 22:33:34 das Exp $
d20 1
d26 2
a27 2
 *      This routine flushes all the Carbon windows of the application.  It
 *      is called by the setup procedure for the Tcl/Carbon event source.
d30 1
a30 1
 *      None.
d33 1
a33 1
 *      Flushes all Carbon windows
d39 1
a39 1
TkMacOSXFlushWindows ()
d42 1
a42 1
    
d44 5
a48 5
        CGrafPtr portPtr = GetWindowPort(wRef);
        if (QDIsPortBuffered(portPtr)) {
            QDFlushPortBuffer(portPtr, NULL);
        }
        wRef = GetNextWindow(wRef);
d52 1
a52 1
/*      
d54 1
a54 1
 *   
a55 2
 *   
 *      This dispatches a filtered Carbon event to the appropriate handler
d57 11
a67 9
 *      Note on MacEventStatus.stopProcessing: Please be conservative in the
 *      individual handlers and don't assume the event is fully handled
 *      unless you *really* need to ensure that other handlers don't see the
 *      event anymore.  Some OS manager or library might be interested in
 *      events even after they are already handled on the Tk level.
 *
 * Results: 
 *      0 on success
 *      -1 on failure
d70 2
a71 2
 *      Converts a Carbon event to a Tk event
 *   
d75 4
a78 2
MODULE_SCOPE int  
TkMacOSXProcessEvent(TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr)
d81 27
a107 29
        case kEventClassMouse:
            TkMacOSXProcessMouseEvent(eventPtr, statusPtr);
            break;
        case kEventClassWindow:
            TkMacOSXProcessWindowEvent(eventPtr, statusPtr);
            break;  
        case kEventClassKeyboard:
            TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr);
            break;
        case kEventClassApplication:
            TkMacOSXProcessApplicationEvent(eventPtr, statusPtr);
            break;
        case kEventClassMenu:
            TkMacOSXProcessMenuEvent(eventPtr, statusPtr);
            break;  
        case kEventClassCommand:
            TkMacOSXProcessCommandEvent(eventPtr, statusPtr);
            break;  
        default:
#ifdef TK_MAC_DEBUG
            {
                char buf [256];
                fprintf(stderr,
                    "Unrecognised event : %s\n",
                    TkMacOSXCarbonEventToAscii(eventPtr->eventRef, buf));
            }
#endif
            break;
    }   
d116 2
a117 2
 *	  This routine processes the event in eventPtr, and
 *	  generates the appropriate Tk events from it.
d120 1
a120 1
 *	  True if event(s) are generated - false otherwise.
d123 1
a123 1
 *	  Additional events may be place on the Tk event queue.
d129 3
a131 1
TkMacOSXProcessMenuEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
d133 2
a134 2
    int		    menuContext;
    OSStatus	    status;
d139 2
d146 45
a190 19
    status = GetEventParameter(eventPtr->eventRef, 
	    kEventParamMenuContext,
	    typeUInt32, NULL, 
	    sizeof(menuContext), NULL,
	    &menuContext);
    if (status == noErr && (menuContext & kMenuContextMenuBar)) {
        static int oldMode = TCL_SERVICE_ALL;
        if (eventPtr->eKind == kEventMenuBeginTracking) {
            oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
            TkMacOSXClearMenubarActive();
        
            /*
             * Handle -postcommand
             */
        
            TkMacOSXPreprocessMenu();
        } else {
            Tcl_SetServiceMode(oldMode);   
        }
d200 2
a201 2
 *	  This routine processes the event in eventPtr, and
 *	  generates the appropriate Tk events from it.
d204 1
a204 1
 *	  True if event(s) are generated - false otherwise.
d207 1
a207 1
 *	  Additional events may be place on the Tk event queue.
d213 3
a215 1
TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
d217 3
a219 3
    HICommand	    command;
    int 	    menuContext;
    OSStatus	    status;
d229 4
a232 6
    status = GetEventParameter(eventPtr->eventRef, 
	    kEventParamDirectObject,
	    typeHICommand, NULL, 
	    sizeof(command), NULL,
	    &command);
    if (status == noErr && (command.attributes & kHICommandFromMenu)) {
d234 4
a237 6
	    status = GetEventParameter(eventPtr->eventRef, 
		    kEventParamMenuContext,
		    typeUInt32, NULL, 
		    sizeof(menuContext), NULL,
		    &menuContext);
	    if (status == noErr && (menuContext & kMenuContextMenuBar) &&
d247 1
a247 1
		if (Tcl_GetCommandInfo(eventPtr->interp, 
d249 1
a249 1
		    if (!IsMenuItemEnabled(command.menu.menuRef, 
d255 1
a255 1
		    if (IsMenuItemEnabled(command.menu.menuRef, 
a267 53

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXReceiveAndProcessEvent --
 *
 *      This receives a carbon event and converts it to a Tk event
 *
 * Results:
 *      0 on success
 *      Mac OS error number on failure
 *
 * Side effects:
 *      This receives the next Carbon event and converts it to the
 *      appropriate Tk event
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE OSStatus
TkMacOSXReceiveAndProcessEvent()
{
    static EventTargetRef targetRef = NULL;
    EventRef eventRef;
    OSStatus err;

    /*
     * This is a poll, since we have already counted the events coming
     * into this routine, and are guaranteed to have one waiting.
     */
     
    err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &eventRef);
    if (err == noErr) {
        if (!targetRef) {
            targetRef = GetEventDispatcherTarget();
        }
        TkMacOSXStartTclEventLoopCarbonTimer();
        err = SendEventToEventTarget(eventRef,targetRef);
        TkMacOSXStopTclEventLoopCarbonTimer();
#ifdef TK_MAC_DEBUG
        if (err != noErr && err != eventLoopTimedOutErr
                && err != eventNotHandledErr
        ) {
            char buf [256];
            fprintf(stderr,
                    "RCNE SendEventToEventTarget (%s) failed, %d\n",
                    TkMacOSXCarbonEventToAscii(eventRef, buf), (int)err);
        }
#endif
        ReleaseEvent(eventRef);
    }
    return err;
}
@


1.13
log
@Reduce the #ifdef count a lot by adding debug-print macros
@
text
@d1 1
a1 1
/*
d10 2
a11 2
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
d19 1
a19 1

d25 2
a26 2
 *      This routine flushes all the Carbon windows of the application. It is
 *      called by the setup procedure for the Tcl/Carbon event source.
d38 1
a38 1
TkMacOSXFlushWindows(void)
d41 1
a41 1

d51 1
a51 1
/*
d53 1
a53 1
 *
d55 1
a55 1
 *
d59 4
a62 4
 *      individual handlers and don't assume the event is fully handled unless
 *      you *really* need to ensure that other handlers don't see the event
 *      anymore. Some OS manager or library might be interested in events even
 *      after they are already handled on the Tk level.
d64 1
a64 1
 * Results:
d70 1
a70 1
 *
d74 2
a75 4
MODULE_SCOPE int
TkMacOSXProcessEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
d78 29
a106 26
    case kEventClassMouse:
	TkMacOSXProcessMouseEvent(eventPtr, statusPtr);
	break;
    case kEventClassWindow:
	TkMacOSXProcessWindowEvent(eventPtr, statusPtr);
	break;
    case kEventClassKeyboard:
	TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr);
	break;
    case kEventClassApplication:
	TkMacOSXProcessApplicationEvent(eventPtr, statusPtr);
	break;
    case kEventClassMenu:
	TkMacOSXProcessMenuEvent(eventPtr, statusPtr);
	break;
    case kEventClassCommand:
	TkMacOSXProcessCommandEvent(eventPtr, statusPtr);
	break;
    default: {
	char buf[256];

	LOG_MSG("Unrecognised event : %s\n",
		TkMacOSXCarbonEventToAscii(eventPtr->eventRef, buf));
	break;
    }
    }
d115 2
a116 2
 *	  This routine processes the event in eventPtr, and generates the
 *	  appropriate Tk events from it.
d128 1
a128 3
TkMacOSXProcessMenuEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
d130 2
a131 2
    int menuContext;
    OSStatus status;
d134 6
a139 6
    case kEventMenuBeginTracking:
    case kEventMenuEndTracking:
	break;
    default:
	return 0;
	break;
d141 5
a145 2
    status = GetEventParameter(eventPtr->eventRef, kEventParamMenuContext,
	    typeUInt32, NULL, sizeof(menuContext), NULL, &menuContext);
a147 1

d151 1
a151 1

d155 1
a155 1

d158 1
a158 1
            Tcl_SetServiceMode(oldMode);
d169 2
a170 2
 *	  This routine processes the event in eventPtr, and generates the
 *	  appropriate Tk events from it.
d182 1
a182 3
TkMacOSXProcessCommandEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
d184 3
a186 3
    HICommand command;
    int menuContext;
    OSStatus status;
d189 6
a194 6
    case kEventCommandProcess:
    case kEventCommandUpdateStatus:
	break;
    default:
	return 0;
	break;
d196 5
a200 2
    status = GetEventParameter(eventPtr->eventRef, kEventParamDirectObject,
	    typeHICommand, NULL, sizeof(command), NULL, &command);
d203 5
a207 3
	    status = GetEventParameter(eventPtr->eventRef,
		    kEventParamMenuContext, typeUInt32, NULL,
		    sizeof(menuContext), NULL, &menuContext);
d215 1
a215 2
	} else if (command.commandID == kHICommandPreferences
		&& eventPtr->interp) {
d217 14
a230 13

	    if (Tcl_GetCommandInfo(eventPtr->interp,
		    "::tk::mac::ShowPreferences", &dummy)) {
		if (!IsMenuItemEnabled(command.menu.menuRef,
			command.menu.menuItemIndex)) {
		    EnableMenuItem(command.menu.menuRef,
			    command.menu.menuItemIndex);
		}
	    } else {
		if (IsMenuItemEnabled(command.menu.menuRef,
			command.menu.menuItemIndex)) {
		    DisableMenuItem(command.menu.menuRef,
			    command.menu.menuItemIndex);
d232 2
a234 2
	    statusPtr->stopProcessing = 1;
	    return 1;
d259 1
a259 1
TkMacOSXReceiveAndProcessEvent(void)
d266 2
a267 2
     * This is a poll, since we have already counted the events coming into
     * this routine, and are guaranteed to have one waiting.
d269 1
a269 1

d280 5
a284 4
                && err != eventNotHandledErr) {
            char buf[256];

	    ERR_MSG("RCNE SendEventToEventTarget (%s) failed, %d",
a291 8

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */
@


1.12
log
@	* macosx/tkMacOSXDebug.c: add TkMacOSX prefix to leftover macosx-private
	* macosx/tkMacOSXDebug.h: global symbols without Tk prefix; ifdef out
	* macosx/tkMacOSXEmbed.c: currently unused debug procs.
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXCarbonEvents.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
@
text
@d1 1
a1 1
/* 
d10 2
a11 2
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.11 2006/05/12 18:17:48 das Exp $
d19 1
a19 1

d25 2
a26 2
 *      This routine flushes all the Carbon windows of the application.  It
 *      is called by the setup procedure for the Tcl/Carbon event source.
d38 1
a38 1
TkMacOSXFlushWindows ()
d41 1
a41 1
    
d51 1
a51 1
/*      
d53 1
a53 1
 *   
d55 1
a55 1
 *   
d59 4
a62 4
 *      individual handlers and don't assume the event is fully handled
 *      unless you *really* need to ensure that other handlers don't see the
 *      event anymore.  Some OS manager or library might be interested in
 *      events even after they are already handled on the Tk level.
d64 1
a64 1
 * Results: 
d70 1
a70 1
 *   
d74 4
a77 2
MODULE_SCOPE int  
TkMacOSXProcessEvent(TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr)
d80 26
a105 29
        case kEventClassMouse:
            TkMacOSXProcessMouseEvent(eventPtr, statusPtr);
            break;
        case kEventClassWindow:
            TkMacOSXProcessWindowEvent(eventPtr, statusPtr);
            break;  
        case kEventClassKeyboard:
            TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr);
            break;
        case kEventClassApplication:
            TkMacOSXProcessApplicationEvent(eventPtr, statusPtr);
            break;
        case kEventClassMenu:
            TkMacOSXProcessMenuEvent(eventPtr, statusPtr);
            break;  
        case kEventClassCommand:
            TkMacOSXProcessCommandEvent(eventPtr, statusPtr);
            break;  
        default:
#ifdef TK_MAC_DEBUG
            {
                char buf [256];
                fprintf(stderr,
                    "Unrecognised event : %s\n",
                    TkMacOSXCarbonEventToAscii(eventPtr->eventRef, buf));
            }
#endif
            break;
    }   
d114 2
a115 2
 *	  This routine processes the event in eventPtr, and
 *	  generates the appropriate Tk events from it.
d127 3
a129 1
TkMacOSXProcessMenuEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
d131 2
a132 2
    int		    menuContext;
    OSStatus	    status;
d135 6
a140 6
	case kEventMenuBeginTracking:
	case kEventMenuEndTracking:
	    break;
	default:
	    return 0;
	    break;
d142 2
a143 5
    status = GetEventParameter(eventPtr->eventRef, 
	    kEventParamMenuContext,
	    typeUInt32, NULL, 
	    sizeof(menuContext), NULL,
	    &menuContext);
d146 1
d150 1
a150 1
        
d154 1
a154 1
        
d157 1
a157 1
            Tcl_SetServiceMode(oldMode);   
d168 2
a169 2
 *	  This routine processes the event in eventPtr, and
 *	  generates the appropriate Tk events from it.
d181 3
a183 1
TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
d185 3
a187 3
    HICommand	    command;
    int 	    menuContext;
    OSStatus	    status;
d190 6
a195 6
	case kEventCommandProcess:
	case kEventCommandUpdateStatus:
	    break;
	default:
	    return 0;
	    break;
d197 2
a198 5
    status = GetEventParameter(eventPtr->eventRef, 
	    kEventParamDirectObject,
	    typeHICommand, NULL, 
	    sizeof(command), NULL,
	    &command);
d201 3
a203 5
	    status = GetEventParameter(eventPtr->eventRef, 
		    kEventParamMenuContext,
		    typeUInt32, NULL, 
		    sizeof(menuContext), NULL,
		    &menuContext);
d211 2
a212 1
	} else {
d214 13
a226 14
	    if (command.commandID == kHICommandPreferences && eventPtr->interp) {
		if (Tcl_GetCommandInfo(eventPtr->interp, 
			"::tk::mac::ShowPreferences", &dummy)) {
		    if (!IsMenuItemEnabled(command.menu.menuRef, 
			    command.menu.menuItemIndex)) {
			EnableMenuItem(command.menu.menuRef,
				command.menu.menuItemIndex);
		    }
		} else {
		    if (IsMenuItemEnabled(command.menu.menuRef, 
			    command.menu.menuItemIndex)) {
			DisableMenuItem(command.menu.menuRef,
				command.menu.menuItemIndex);
		    }
a227 2
		statusPtr->stopProcessing = 1;
		return 1;
d229 2
d255 1
a255 1
TkMacOSXReceiveAndProcessEvent()
d262 2
a263 2
     * This is a poll, since we have already counted the events coming
     * into this routine, and are guaranteed to have one waiting.
d265 1
a265 1
     
d276 4
a279 5
                && err != eventNotHandledErr
        ) {
            char buf [256];
            fprintf(stderr,
                    "RCNE SendEventToEventTarget (%s) failed, %d\n",
d287 8
@


1.11
log
@	* generic/tkCanvWind.c (DisplayWinItem, WinItemRequestProc): ensure
	canvas window items are unmapped when canvas is unmapped. [Bug 940117]

	* macosx/tkMacOSXSubwindows.c (TkMacOSXUpdateClipRgn): empty clip region
	of unmapped windows to prevent any drawing into them or into their
	children from becoming visible. [Bug 940117]

	* macosx/tkMacOSXInt.h:         revert Jim's attempt of 2005-03-14 to
	* macosx/tkMacOSXSubwindows.c:  fix Bug 940117 as it disables Map/Unmap
	event propagation to children.  [Bug 1480105]

	* macosx/tkMacOSXDraw.c (TkPutImage): handle tkPictureIsOpen flag, fixes
	incorrect positioning of images with complex alpha on native buttons;
	actual alpha blending is still broken in this situation. [Bug 1155596]

	* macosx/tkMacOSXEvent.c (TkMacOSXProcessCommandEvent):
	* macosx/tkMacOSXMenus.c (TkMacOSXInitMenus): workaround carbon bug with
	key shortcut for 'Preferences' app menu item. [Bug 1481503]

	* macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): only check
	for HICommand menu item shortcuts in the application menu.

	* macosx/tkMacOSXInt.h:       initialize keyboard layout setup in
	* macosx/tkMacOSXInit.c:      TkpInit() rather than during handling of
	* macosx/tkMacOSXKeyEvent.c:  first key down event.

	* macosx/tkMacOSXDraw.c:        add optional debug code to flash clip
	* macosx/tkMacOSXSubwindows.c:  regions during update or draw.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.10 2006/04/11 10:22:34 das Exp $
d102 1
a102 1
                    CarbonEventToAscii(eventPtr->eventRef, buf));
d285 1
a285 1
                    CarbonEventToAscii(eventRef, buf), (int)err);
@


1.10
log
@	* macosx/tkMacOSXCarbonEvents.c: handle kEventCommandUpdateStatus
	* macosx/tkMacOSXEvent.c:        carbon event to dynamically enable
	the 'Preferences' app menu item when proc [::tk::mac::ShowPreferences]
	is defined. [Bug 700316]
@
text
@d8 1
d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.9 2006/03/24 14:58:01 das Exp $
d232 1
@


1.9
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
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.8 2005/11/27 02:36:15 das Exp $
d183 2
a184 2
    HICommand       command;
    int		    menuContext;
d189 1
d201 33
a233 12
        status = GetEventParameter(eventPtr->eventRef, 
                kEventParamMenuContext,
                typeUInt32, NULL, 
                sizeof(menuContext), NULL,
                &menuContext);
        if (status == noErr && (menuContext & kMenuContextMenuBar) &&
                (menuContext & kMenuContextMenuBarTracking)) {
            TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef),
                    command.menu.menuItemIndex,
                    GetCurrentEventKeyModifiers() & optionKey);
            return 1;
        }
@


1.8
log
@	* unix/tcl.m4 (Darwin): add 64bit support, check for Tiger copyfile(),
	add CFLAGS to SHLIB_LD to support passing -isysroot in env(CFLAGS) to
	configure (flag can't be present twice, so can't be in both CFLAGS and
	LDFLAGS during configure), don't use -prebind when deploying on 10.4,
	define TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING (rdar://3171542).
	(SC_ENABLE_LANGINFO, SC_TIME_HANDLER): add/fix caching, fix obsolete
	autoconf macros. Sync with tcl/unix/tcl.m4.

	* unix/configure.in: fix obsolete autoconf macros, sync gratuitous
	formatting/ordering differences with tcl/unix/configure.in.

	* unix/Makefile.in: add CFLAGS to wish/tktest link to make executable
	linking the same as during configure (needed to avoid loosing any linker
	relevant flags in CFLAGS, in particular flags that can't be in LDFLAGS).
	Avoid concurrent linking of wish and compiling of tkTestInit.o during
	parallel make, fix dependencies and flags for building tkMacOSXInit.o
	(checkstubs, checkexports): dependency and Darwin fixes
	(dist): add new macosx files.

	* macosx/tkMacOSXEvent.c (TkMacOSXProcessEvent):
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent):
	* macosx/tkMacOSXCarbonEvents.c: install standard application event
	handler, add & call functions to start and stop carbon even timer that
	runs the tcl event loop periodically during a nested carbon event loop
	in the toolbox (e.g. during menutracking) to ensure tcl timers etc
	continue to fire, register app event handler for menu tracking and HI
	command carbon events, move menu event handling to new handlers for
	those carbon events, no longer register for/handle appleevent carbon
	event (now dealt with by standard application event handler), event
	debugging code dynamically acquires carbon event debugging functions to
	allow use on Tiger where they are no longer exported from HIToolbox.

	* macosx/tkMacOSXFont.c (TkMacOSXUseAntialiasedText):
	* macosx/tkMacOSXKeyEvent.c (GetKeyboardLayout):
	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents):
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h: abstract common code to dynamically acquire
	address of a named symbol (from a loaded dynamic library) into new
	function TkMacOSXGetNamedSymbol() and macro TkMacOSXInitNamedSymbol.

	* macosx/tkMacOSXMenu.c (TkpNewMenu):
	* macosx/tkMacOSXMenubutton.c (MenuButtonInitControl):
	* macosx/tkMacOSXMenus.c (TkMacOSXHandleMenuSelect): switch to  modern
	utf8 aware menu manager API, remove obsolete code, add error handling.

	* macosx/tkMacOSXMouseEvent.c: define OSX 10.3 or later only constants
	if necessary to allow compilation on OSX 10.2

	* macosx/tkMacOSXWm.c (UpdateSizeHints): remove code that is never
	executed.

	* xlib/xgc.c (XCreateGC): sync with core-8-4-branch change.

	* generic/tk.h: add/correct location of version numbers in macosx files.

	* generic/tkInt.h: clarify fat compile comment.

	* macosx/Wish.pbproj/default.pbxuser (new file):
	* macosx/Wish.pbproj/jingham.pbxuser:
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/Wish.xcode/default.pbxuser:
	* macosx/Wish.xcode/project.pbxproj:
	* macosx/Wish.xcodeproj/default.pbxuser (new file):
	* macosx/Wish.xcodeproj/project.pbxproj (new file): new/updated projects
	for Xcode 2.2 on 10.4, Xcode 1.5 on 10.3 & ProjectBuilder on 10.2, with
	native tktest targets and support for universal (fat) compiles.

	* macosx/Tk-Info.plist (removed):
	* macosx/Wish-Info.plist (removed):
	* macosx/buildTkConfig.tcl (removed): remove obsolete build files.

	* macosx/README: clarification/cleanup, document new Xcode projects and
	universal (fat) builds via CFLAGS (i.e. ppc and i386 at the same time).

	* unix/Makefile.in:
	* unix/aclocal.m4:
	* unix/configure.in:
	* macosx/configure.ac (new file): add support for inclusion of
	unix/configure.in by macosx/configure.ac, allows generation of a config
	headers enabled configure script in macosx (required by Xcode projects).

	* macosx/GNUmakefile: rename from Makefile to avoid overwriting by
	configure run in tk/macosx, add support for reusing configure cache,
	build target fixes.

	* generic/tk3d.h:
	* generic/tkButton.h:
	* generic/tkCanvas.c:
	* generic/tkCanvas.h:
	* generic/tkColor.h:
	* generic/tkEntry.h:
	* generic/tkFileFilter.h:
	* generic/tkFont.c:
	* generic/tkFont.h:
	* generic/tkImage.c:
	* generic/tkImgPhoto.c:
	* generic/tkInt.h:
	* generic/tkMenu.c:
	* generic/tkMenu.h:
	* generic/tkMenubutton.h:
	* generic/tkScale.h:
	* generic/tkScrollbar.h:
	* generic/tkSelect.h:
	* generic/tkStubInit.c:
	* generic/tkStubLib.c:
	* generic/tkText.h:
	* generic/tkUndo.h:
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* unix/tkUnixButton.c:
	* unix/tkUnixMenu.c:
	* xlib/xgc.c: ensure externally visible symbols not contained in stubs
	table are declared as MODULE_SCOPE (or as static if not used outside of
	own source file), #ifdef out a few Xlib and aqua functions that are
	never called. These changes allow 'make checkstubs' to complete without
	error on Darwin with gcc 4.

	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXPort.h:
	* win/tkWinTest.c:
	* generic/tkInt.decls: add functions needed by tktest to internal stubs
	table, correct signature of TkMacOSXHandleMenuSelect, add XSync to aqua
	Xlib stubs.

	* unix/tkUnixSend.c:
	* generic/tkText.c:
	* generic/tkTest.c: #ifdef unix only declarations.
	(TestmetricsCmd): unify win and mac implementation.
	(TestsendCmd): move to tkUnixSend.c to avoid access to global var.
	(TesttextCmd): move to tkText.c to avoid having to put all the internal
	text functions it uses into the stubs table.

	* generic/tkTextDisp.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXXStubs.c: fix gcc 4 warnings.

	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXScrlbr.c: sync with core-8-4-branch.

	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkStubInit.c:
	* unix/configure:
	* unix/tkConfig.h.in: regen.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.7 2005/09/10 14:53:20 das Exp $
a14 2
#include <stdio.h>

@


1.7
log
@	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): check if
	process is in front on MouseDown, otherwise request process activation
	from BringWindowForward() via new isFrontProcess param.

	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents): register our
	event handler on the dispatcher target for all carbon events of interest
	to TkAqua; this replaces event processing directly from the event queue
	and thus allows to capture events that are syntesized by Carbon and sent
	directly to the dispatcher and not to the event queue.

	* macosx/tkMacOSXEvent.c: remove TkMacOSXCountAndProcessMacEvents(),
	rename ReceiveAndProcessEvent() to TkMacOSXReceiveAndProcessEvent().
	(TkMacOSXReceiveAndProcessEvent): remove tk event processing before
	sending events to the dispatcher, all events of interest are now
	processed in our dispatcher target event handler.

	* macosx/tkMacOSXNotify.c (CarbonEventsCheckProc): dispatch events
	directly via TkMacOSXReceiveAndProcessEvent(), but dispatch no more than
	four carbon events at one time to avoid starving other event sources.

	* macosx/tkMacOSXEvent.c: formatting cleanup, move XSync() to XStubs,
	* macosx/tkMacOSXEvent.h: removed obsolete kEventClassWish handling.
	* macosx/tkMacOSXXStubs.c

	* macosx/tkMacOSXEvent.h: declare macosx internal procs as MODULE_SCOPE.
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWindowEvent.c:

	* macosx/tkMacOSXButton.c: conditionalize all debug message printing to
	* macosx/tkMacOSXCursor.c: stderr via TK_MAC_DEBUG define.
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* unix/configure.in: define TK_MAC_DEBUG on aqua when symbols enabled.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

	* library/listbox.tcl: synced aqua MouseWheel bindings with
	* library/scrlbar.tcl: core-8-4-branch.
	* library/text.tcl:

	* xlib/xcolors.c: fixed warning
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.6 2005/08/09 07:39:20 das Exp $
a20 7
/*   
 * Forward declarations of procedures used in this file.
 */ 

static int TkMacOSXProcessAppleEvent(
        TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr);

a51 46
/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessAppleEvent --
 *
 *      This processes Apple events
 *
 * Results:
 *      0 on success
 *      -1 on failure
 *
 * Side effects:
 *      Calls the Tk high-level event handler
 *
 *----------------------------------------------------------------------
 */

static int
TkMacOSXProcessAppleEvent(TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr)
{
    int  err;
    EventRecord eventRecord;
    if (ConvertEventRefToEventRecord(eventPtr->eventRef,
        &eventRecord )) {
        err = TkMacOSXDoHLEvent(&eventRecord);
        if (err != noErr) {
#ifdef TK_MAC_DEBUG
            char buf1 [ 256 ];
            char buf2 [ 256 ];
            fprintf(stderr,
                "TkMacOSXDoHLEvent failed : %s,%s,%d\n",
                CarbonEventToAscii(eventPtr->eventRef, buf1),
                ClassicEventToAscii(&eventRecord,buf2), err);
#endif
            statusPtr->err = 1;
        }
    } else {
#ifdef TK_MAC_DEBUG
        fprintf(stderr,"ConvertEventRefToEventRecord failed\n");
#endif
        statusPtr->err = 1;
    }
    return 0;
}


d91 5
a95 2
        case kEventClassAppleEvent:
            TkMacOSXProcessAppleEvent(eventPtr, statusPtr);
d114 107
d253 1
d255 1
@


1.6
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
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.5 2004/02/16 00:19:42 wolfsuit Exp $
a20 6
/*
 * Enable this define to get debug printing for events not handled.
 */

 /*#define TK_MAC_DEBUG 1 */

a26 9

static int ReceiveAndProcessEvent (void);

/*   
 * Global data used in this file.
 */ 

static EventTargetRef targetRef;

d31 1
a31 1
 * tkMacOSXFlushWindows --
d45 2
a46 2
void
tkMacOSXFlushWindows ()
d58 1
a58 47



int
XSync (Display *display, Bool flag)
{
    tkMacOSXFlushWindows();
    display->request++;
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXCountAndProcessMacEvents --
 *
 *      This routine receives any Carbon events that are in the queue and
 *      converts them to Tk events.  It is called by the event set-up and
 *      check routines
 *
 * Results:
 *      The number of events in the queue.
 *
 * Side effects:
 *      Tells the Window Manager to deliver events to the event queue of the
 *      current thread.  Receives any Carbon events on the queue and converts
 *      them to Tk events.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXCountAndProcessMacEvents()
{
    EventQueueRef qPtr;
    int           eventCount;
    qPtr = GetMainEventQueue();
    eventCount = GetNumEventsInQueue(qPtr);
    if (eventCount) {
        int n, err;
        for (n = 0, err = 0;n<eventCount && !err;n++) {
            err = ReceiveAndProcessEvent();
        }
    }
    return eventCount;
}

d85 1
d92 1
d96 3
a99 1
        fprintf(stderr,"ConvertEventRefToEventRecord failed\n");
d128 1
a128 1
int  
a146 3
        case kEventClassWish: 
            statusPtr->stopProcessing = 1;
            break;  
a148 1
            if (0)
d150 1
a150 1
                char buf [ 256 ];
d164 1
a164 1
 * ReceiveAndProcessEvent --
d179 2
a180 2
static int
ReceiveAndProcessEvent()
d182 3
a184 4
    TkMacOSXEvent       macEvent;
    MacEventStatus   eventStatus;
    int              err;
    char             buf [ 256 ];
d191 15
a205 19
    err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, 
            true, &macEvent.eventRef);
    if (err != noErr) {
        return err;
    } else {
        macEvent.eClass = GetEventClass(macEvent.eventRef);
        macEvent.eKind = GetEventKind(macEvent.eventRef);
        macEvent.interp = NULL;
        bzero(&eventStatus, sizeof(eventStatus));
        TkMacOSXProcessEvent(&macEvent,&eventStatus);
        if (!eventStatus.stopProcessing) {
            if (!targetRef) {
                targetRef = GetEventDispatcherTarget();
            }
            
            err = SendEventToEventTarget(macEvent.eventRef,targetRef);
            if (err != noErr
#if !TK_MAC_DEBUG
                    && err != eventNotHandledErr
d207 3
a209 9
                ) {
                fprintf(stderr,
                        "RCNE SendEventToEventTarget (%s) failed, %d\n",
                        CarbonEventToAscii(macEvent.eventRef, buf),err);
            }
         }
         ReleaseEvent(macEvent.eventRef);
         return 0;
     }
@


1.5
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
@d12 1
a12 1
 * RCS: @@(#) $Id$
a32 2
static int TkMacOSXProcessEvent(
        TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr);
d185 1
a185 1
static int  
d220 1
a220 2
}   

d260 1
@


1.4
log
@Add an implementation of XSync that flushes the window buffers.  This fixes 814810.
Also use tk text drawing for checkbutton & radiobutton labels.
@
text
@d72 1
a72 1
        wRef=GetNextWindow(wRef);
d146 2
a147 2
        err=TkMacOSXDoHLEvent(&eventRecord);
        if (err!=noErr) {
d256 1
a256 1
    err=ReceiveNextEvent(0, NULL, kEventDurationNoWait, 
d267 1
a267 1
                targetRef=GetEventDispatcherTarget();
d270 1
a270 1
            err= SendEventToEventTarget(macEvent.eventRef,targetRef);
d278 1
a278 1
                        CarbonEventToAscii(macEvent.eventRef,buf ),err);
@


1.3
log
@This submission contains a slightly reworked & cleaned up version of
two parts of the patches in Patch Tracker #622582 -
new-evthdlng.2003-02-12.diff and basic-keyboard.2003-02-10.diff.  The
second part puts translation of MacOS X keycodes to characters on a
better footing. The first part relaxs Tk's policy of consuming all
events unless it can see they go to windows it didn't create.  This
change gets the little traffic lights working, and should make things
like QuickTimeTcl easier to implement.
@
text
@d76 10
@


1.3.2.1
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
@d72 1
a72 1
        wRef = GetNextWindow(wRef);
a75 10


int
XSync (Display *display, Bool flag)
{
    tkMacOSXFlushWindows();
    display->request++;
    return 0;
}

d136 2
a137 2
        err = TkMacOSXDoHLEvent(&eventRecord);
        if (err != noErr) {
d246 1
a246 1
    err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, 
d257 1
a257 1
                targetRef = GetEventDispatcherTarget();
d260 1
a260 1
            err = SendEventToEventTarget(macEvent.eventRef,targetRef);
d268 1
a268 1
                        CarbonEventToAscii(macEvent.eventRef, buf),err);
@


1.3.2.2
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
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.1 2004/02/16 00:42:34 wolfsuit Exp $
d33 2
d187 1
a187 1
int  
d222 2
a223 1
}
a262 1
        macEvent.interp = NULL;
@


1.3.2.3
log
@	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): check if
	process is in front on MouseDown, otherwise request process activation
	from BringWindowForward() via new isFrontProcess param.

	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents): register our
	event handler on the dispatcher target for all carbon events of interest
	to TkAqua; this replaces event processing directly from the event queue
	and thus allows to capture events that are syntesized by Carbon and sent
	directly to the dispatcher and not to the event queue.

	* macosx/tkMacOSXEvent.c: remove TkMacOSXCountAndProcessMacEvents(),
	rename ReceiveAndProcessEvent() to TkMacOSXReceiveAndProcessEvent().
	(TkMacOSXReceiveAndProcessEvent): remove tk event processing before
	sending events to the dispatcher, all events of interest are now
	processed in our dispatcher target event handler.

	* macosx/tkMacOSXNotify.c (CarbonEventsCheckProc): dispatch events
	directly via TkMacOSXReceiveAndProcessEvent(), but dispatch no more than
	four carbon events at one time to avoid starving other event sources.

	* macosx/tkMacOSXEvent.c: formatting cleanup, move XSync() to XStubs,
	* macosx/tkMacOSXEvent.h: removed obsolete kEventClassWish handling.
	* macosx/tkMacOSXXStubs.c

	* macosx/tkMacOSXButton.c: conditionalize all debug message printing to
	* macosx/tkMacOSXCursor.c: stderr via TK_MAC_DEBUG define.
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:

	* unix/configure.in: define TK_MAC_DEBUG on aqua when symbols enabled.
	* unix/configure: autoconf-2.13

	* library/listbox.tcl: corrected comments.
	* library/text.tcl:

	* xlib/xcolors.c: fixed warning
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.2 2005/08/09 07:39:55 das Exp $
d21 6
d33 9
d46 1
a46 1
 * TkMacOSXFlushWindows --
d61 1
a61 1
TkMacOSXFlushWindows ()
d73 47
a119 1

a145 1
#ifdef TK_MAC_DEBUG
a151 1
#endif
d155 1
a155 1
#ifdef TK_MAC_DEBUG
a156 2
#endif
        statusPtr->err = 1;
d204 3
d209 1
d211 1
a211 1
                char buf [256];
d225 1
a225 1
 * TkMacOSXReceiveAndProcessEvent --
d240 2
a241 2
OSStatus
TkMacOSXReceiveAndProcessEvent()
d243 4
a246 3
    static EventTargetRef targetRef = NULL;
    EventRef eventRef;
    OSStatus err;
d253 19
a271 15
    err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &eventRef);
    if (err == noErr) {
        if (!targetRef) {
            targetRef = GetEventDispatcherTarget();
        }
        err = SendEventToEventTarget(eventRef,targetRef);
#ifdef TK_MAC_DEBUG
        if (err != noErr && err != eventLoopTimedOutErr
                && err != eventNotHandledErr
        ) {
            char buf [256];
            fprintf(stderr,
                    "RCNE SendEventToEventTarget (%s) failed, %d\n",
                    CarbonEventToAscii(eventRef, buf), (int)err);
        }
d273 9
a281 3
        ReleaseEvent(eventRef);
    }
    return err;
@


1.3.2.4
log
@	* unix/tcl.m4 (Darwin): add 64bit support, check for Tiger copyfile(),
	add CFLAGS to SHLIB_LD to support passing -isysroot in env(CFLAGS) to
	configure (flag can't be present twice, so can't be in both CFLAGS and
	LDFLAGS during configure), don't use -prebind when deploying on 10.4,
	define TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING (rdar://3171542).
	(SC_ENABLE_LANGINFO, SC_TIME_HANDLER): add/fix caching, fix obsolete
	autoconf macros. Sync with tk/unix/tcl.m4, sync whitespace with HEAD.

	* unix/configure.in: fix obsolete autoconf macros, sync gratuitous
	formatting/ordering differences with tcl/unix/configure.in.

	* unix/Makefile.in: add CFLAGS to wish/tktest link to make executable
	linking the same as during configure (needed to avoid loosing any linker
	relevant flags in CFLAGS, in particular flags that can't be in LDFLAGS).
	Avoid concurrent linking of wish and compiling of tkTestInit.o during
	parallel make, fix dependencies and flags for building tkMacOSXInit.o
	(checkstubs, checkexports): dependency and Darwin fixes

	* macosx/tkMacOSXEvent.c (TkMacOSXProcessEvent):
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent):
	* macosx/tkMacOSXCarbonEvents.c: install standard application event
	handler, add & call functions to start and stop carbon even timer that
	runs the tcl event loop periodically during a nested carbon event loop
	in the toolbox (e.g. during menutracking) to ensure tcl timers etc
	continue to fire, register app event handler for menu tracking and HI
	command carbon events, move menu event handling to new handlers for
	those carbon events, no longer register for/handle appleevent carbon
	event (now dealt with by standard application event handler), event
	debugging code dynamically acquires carbon event debugging functions to
	allow use on Tiger where they are no longer exported from HIToolbox.

	* macosx/tkMacOSXFont.c (TkMacOSXUseAntialiasedText):
	* macosx/tkMacOSXKeyEvent.c (GetKeyboardLayout):
	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents):
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h: abstract common code to dynamically acquire
	address of a named symbol (from a loaded dynamic library) into new
	function TkMacOSXGetNamedSymbol() and macro TkMacOSXInitNamedSymbol.

	* macosx/tkMacOSXMenu.c (TkpNewMenu):
	* macosx/tkMacOSXMenubutton.c (MenuButtonInitControl):
	* macosx/tkMacOSXMenus.c (TkMacOSXHandleMenuSelect): switch to  modern
	utf8 aware menu manager API, remove obsolete code, add error handling.

	* macosx/tkMacOSXMouseEvent.c: define OSX 10.3 or later only constants
	if necessary to allow compilation on OSX 10.2

	* macosx/tkMacOSXWm.c (UpdateSizeHints): remove code that is never
	executed.

	* generic/tk.h: add/correct location of version numbers in macosx files.

	* generic/tkInt.h: clarify fat compile comment.

	* macosx/Wish.pbproj/default.pbxuser (new file):
	* macosx/Wish.pbproj/jingham.pbxuser:
	* macosx/Wish.pbproj/project.pbxproj: sync with HEAD.

	* macosx/buildTkConfig.tcl (removed): remove obsolete build files.

	* macosx/README: clarification/cleanup, sync with HEAD, document
	universal (fat) builds via CFLAGS (i.e. ppc and i386 at the same time).

	* macosx/Makefile: add support for reusing configure cache, build target
	fixes.

	* generic/tkMenu.c:
	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDialog.c:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXXStubs.c:
	* macosx/tkMacOSXSubwindows.c:
	* xlib/xgc.c: declare functions and globals used only in own file as
	static, #ifdef out a few Xlib and aqua functions that are never called
	(sync with HEAD).

	* macosx/tkMacOSXPort.h:
	* generic/tkInt.decls: correct signature of TkMacOSXHandleMenuSelect,
	add XSync to aqua Xlib stubs.

	* generic/tkTest.c: #ifdef unix only declarations.
	(TestmetricsCmd): unify win and mac implementation.

	* generic/tkTextDisp.c:
	* generic/tkTextBTree.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXXStubs.c: fix gcc 4 warnings.

	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXTest.c: sync with HEAD.

	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkStubInit.c:
	* unix/configure: regen.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.3 2005/09/10 14:54:17 das Exp $
d21 7
d59 46
d144 2
a145 5
        case kEventClassMenu:
            TkMacOSXProcessMenuEvent(eventPtr, statusPtr);
            break;  
        case kEventClassCommand:
            TkMacOSXProcessCommandEvent(eventPtr, statusPtr);
a163 107
 * TkMacOSXProcessMenuEvent --
 *
 *	  This routine processes the event in eventPtr, and
 *	  generates the appropriate Tk events from it.
 *
 * Results:
 *	  True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	  Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXProcessMenuEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
{
    int		    menuContext;
    OSStatus	    status;

    switch (eventPtr->eKind) {
	case kEventMenuBeginTracking:
	case kEventMenuEndTracking:
	    break;
	default:
	    return 0;
	    break;
    }
    status = GetEventParameter(eventPtr->eventRef, 
	    kEventParamMenuContext,
	    typeUInt32, NULL, 
	    sizeof(menuContext), NULL,
	    &menuContext);
    if (status == noErr && (menuContext & kMenuContextMenuBar)) {
        static int oldMode = TCL_SERVICE_ALL;
        if (eventPtr->eKind == kEventMenuBeginTracking) {
            oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
            TkMacOSXClearMenubarActive();
        
            /*
             * Handle -postcommand
             */
        
            TkMacOSXPreprocessMenu();
        } else {
            Tcl_SetServiceMode(oldMode);   
        }
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessCommandEvent --
 *
 *	  This routine processes the event in eventPtr, and
 *	  generates the appropriate Tk events from it.
 *
 * Results:
 *	  True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	  Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
{
    HICommand       command;
    int		    menuContext;
    OSStatus	    status;

    switch (eventPtr->eKind) {
	case kEventCommandProcess:
	    break;
	default:
	    return 0;
	    break;
    }
    status = GetEventParameter(eventPtr->eventRef, 
	    kEventParamDirectObject,
	    typeHICommand, NULL, 
	    sizeof(command), NULL,
	    &command);
    if (status == noErr && (command.attributes & kHICommandFromMenu)) {
        status = GetEventParameter(eventPtr->eventRef, 
                kEventParamMenuContext,
                typeUInt32, NULL, 
                sizeof(menuContext), NULL,
                &menuContext);
        if (status == noErr && (menuContext & kMenuContextMenuBar) &&
                (menuContext & kMenuContextMenuBarTracking)) {
            TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef),
                    command.menu.menuItemIndex,
                    GetCurrentEventKeyModifiers() & optionKey);
            return 1;
        }
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
a195 1
        TkMacOSXStartTclEventLoopCarbonTimer();
a196 1
        TkMacOSXStopTclEventLoopCarbonTimer();
@


1.3.2.5
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
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.4 2005/11/27 02:36:46 das Exp $
d15 2
@


1.3.2.6
log
@	* macosx/tkMacOSXCarbonEvents.c: handle kEventCommandUpdateStatus
	* macosx/tkMacOSXEvent.c:        carbon event to dynamically enable
	the 'Preferences' app menu item when proc [::tk::mac::ShowPreferences]
	is defined. [Bug 700316]
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.5 2006/03/28 02:44:13 das Exp $
d183 2
a184 2
    HICommand	    command;
    int 	    menuContext;
a188 1
	case kEventCommandUpdateStatus:
d200 12
a211 33
	if (eventPtr->eKind == kEventCommandProcess) {
	    status = GetEventParameter(eventPtr->eventRef, 
		    kEventParamMenuContext,
		    typeUInt32, NULL, 
		    sizeof(menuContext), NULL,
		    &menuContext);
	    if (status == noErr && (menuContext & kMenuContextMenuBar) &&
		    (menuContext & kMenuContextMenuBarTracking)) {
		TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef),
			command.menu.menuItemIndex,
			GetCurrentEventKeyModifiers() & optionKey);
		return 1;
	    }
	} else {
	    Tcl_CmdInfo dummy;
	    if (command.commandID == kHICommandPreferences && eventPtr->interp) {
		if (Tcl_GetCommandInfo(eventPtr->interp, 
			"::tk::mac::ShowPreferences", &dummy)) {
		    if (!IsMenuItemEnabled(command.menu.menuRef, 
			    command.menu.menuItemIndex)) {
			EnableMenuItem(command.menu.menuRef,
				command.menu.menuItemIndex);
		    }
		} else {
		    if (IsMenuItemEnabled(command.menu.menuRef, 
			    command.menu.menuItemIndex)) {
			DisableMenuItem(command.menu.menuRef,
				command.menu.menuItemIndex);
		    }
		}
		return 1;
	    }
	}
@


1.3.2.7
log
@	* macosx/tkMacOSXWm.c (TkWmMapWindow, InitialWindowBounds): fix use of
	potentially stale window position in initial configure event on first
	map of a window. [Bug 1476443]
	(TkMacOSXWindowOffset): use modern GetWindowStructureWidths API.

	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXMouseEvent.c (TkGenerateButtonEventForXPointer): new
	internal function to generate button events for current pointer
	directly, without requiring prior call to XQueryPointer().

	* macosx/tkMacOSXMouseEvent.c (XQueryPointer): implement return of
	window-local pointer position.

	* macosx/tkMacOSXInt.h:      use improvements above to avoid calls to
	* macosx/tkMacOSXKeyEvent.c: GlobalToLocal() when the current port might
	* macosx/tkMacOSXMenu.c:     not be set correctly. May fix [Bug 1243318]
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXScrlbr.c:

	* tkAboutDlg.r: update copyright.

	* macosx/tkMacOSXCarbonEvents.c: sync with HEAD
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXFont.h:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXMenubutton.c:
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXTest.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.6 2006/04/11 10:22:57 das Exp $
d36 1
a36 1
MODULE_SCOPE void
d73 1
a73 1
MODULE_SCOPE int  
d126 1
a126 1
MODULE_SCOPE int
d180 1
a180 1
MODULE_SCOPE int
d256 1
a256 1
MODULE_SCOPE OSStatus
@


1.3.2.8
log
@	* generic/tkCanvWind.c (DisplayWinItem, WinItemRequestProc): ensure
	canvas window items are unmapped when canvas is unmapped. [Bug 940117]

	* macosx/tkMacOSXSubwindows.c (TkMacOSXUpdateClipRgn): empty clip region
	of unmapped windows to prevent any drawing into them or into their
	children from becoming visible. [Bug 940117]

	* macosx/tkMacOSXInt.h:         revert Jim's attempt of 2005-03-14 to
	* macosx/tkMacOSXSubwindows.c:  fix Bug 940117 as it disables Map/Unmap
	event propagation to children.  [Bug 1480105]

	* macosx/tkMacOSXDraw.c (TkPutImage): handle tkPictureIsOpen flag, fixes
	incorrect positioning of images with complex alpha on native buttons;
	actual alpha blending is still broken in this situation. [Bug 1155596]

	* macosx/tkMacOSXEvent.c (TkMacOSXProcessCommandEvent):
	* macosx/tkMacOSXMenus.c (TkMacOSXInitMenus): workaround carbon bug with
	key shortcut for 'Preferences' app menu item. [Bug 1481503]

	* macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): only check
	for HICommand menu item shortcuts in the application menu.

	* macosx/tkMacOSXInt.h:       initialize keyboard layout setup in
	* macosx/tkMacOSXInit.c:      TkpInit() rather than during handling of
	* macosx/tkMacOSXKeyEvent.c:  first key down event.

	* macosx/tkMacOSXDraw.c:        add optional debug code to flash clip
	* macosx/tkMacOSXSubwindows.c:  regions during update or draw.
@
text
@a7 1
 * Copyright (c) 2005-2006 Daniel A. Steffen <das@@users.sourceforge.net>
d12 1
a12 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.7 2006/04/28 06:02:59 das Exp $
a230 1
		statusPtr->stopProcessing = 1;
@


1.3.2.9
log
@	* macosx/tkMacOSXDebug.c: add TkMacOSX prefix to leftover macosx-private
	* macosx/tkMacOSXDebug.h: global symbols without Tk prefix; ifdef out
	* macosx/tkMacOSXEmbed.c: currently unused debug procs.
	* macosx/tkMacOSXEvent.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXCarbonEvents.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.8 2006/05/12 18:17:55 das Exp $
d102 1
a102 1
                    TkMacOSXCarbonEventToAscii(eventPtr->eventRef, buf));
d285 1
a285 1
                    TkMacOSXCarbonEventToAscii(eventRef, buf), (int)err);
@


1.3.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 1
a4 1
 *	This file contains the basic Mac OS X Event handling routines.
d8 1
a8 1
 * Copyright (c) 2005-2007 Daniel A. Steffen <das@@users.sourceforge.net>
d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.9 2006/10/31 22:33:38 das Exp $
a19 1

d25 2
a26 2
 *	This routine flushes all the Carbon windows of the application. It
 *	is called by the setup procedure for the Tcl/Carbon event source.
d29 1
a29 1
 *	None.
d32 1
a32 1
 *	Flushes all Carbon windows
d38 1
a38 1
TkMacOSXFlushWindows(void)
d41 1
a41 1

d43 5
a47 5
	CGrafPtr portPtr = GetWindowPort(wRef);
	if (QDIsPortBuffered(portPtr)) {
	    QDFlushPortBuffer(portPtr, NULL);
	}
	wRef = GetNextWindow(wRef);
d51 1
a51 1
/*
d53 1
a53 1
 *
d55 2
d58 9
a66 11
 *	This dispatches a filtered Carbon event to the appropriate handler
 *
 *	Note on MacEventStatus.stopProcessing: Please be conservative in the
 *	individual handlers and don't assume the event is fully handled
 *	unless you *really* need to ensure that other handlers don't see the
 *	event anymore. Some OS manager or library might be interested in
 *	events even after they are already handled on the Tk level.
 *
 * Results:
 *	0 on success
 *	-1 on failure
d69 2
a70 2
 *	Converts a Carbon event to a Tk event
 *
d74 2
a75 4
MODULE_SCOPE int
TkMacOSXProcessEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
d78 29
a106 27
	case kEventClassMouse:
	    TkMacOSXProcessMouseEvent(eventPtr, statusPtr);
	    break;
	case kEventClassWindow:
	    TkMacOSXProcessWindowEvent(eventPtr, statusPtr);
	    break;
	case kEventClassKeyboard:
	    TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr);
	    break;
	case kEventClassApplication:
	    TkMacOSXProcessApplicationEvent(eventPtr, statusPtr);
	    break;
	case kEventClassAppearance:
	    TkMacOSXProcessAppearanceEvent(eventPtr, statusPtr);
	    break;
	case kEventClassMenu:
	    TkMacOSXProcessMenuEvent(eventPtr, statusPtr);
	    break;
	case kEventClassCommand:
	    TkMacOSXProcessCommandEvent(eventPtr, statusPtr);
	    break;
	default: {
	    TkMacOSXDbgMsg("Unrecognised event: %s",
		    TkMacOSXCarbonEventToAscii(eventPtr->eventRef));
	    break;
	}
    }
d115 2
a116 2
 *	This routine processes the event in eventPtr, and
 *	generates the appropriate Tk events from it.
d119 1
a119 1
 *	True if event(s) are generated - false otherwise.
d122 1
a122 1
 *	Additional events may be place on the Tk event queue.
d128 1
a128 3
TkMacOSXProcessMenuEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
d130 2
a131 2
    int menuContext;
    OSStatus err;
a135 2
	case kEventMenuOpening:
	case kEventMenuTargetItem:
d141 19
a159 45
    err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamMenuContext,
	    typeUInt32, NULL, sizeof(menuContext), NULL, &menuContext);
    if (err == noErr && ((menuContext & kMenuContextMenuBarTracking) ||
	    (menuContext & kMenuContextPopUpTracking))) {
	switch (eventPtr->eKind) {
	    MenuRef menu;

	    case kEventMenuBeginTracking:
		TkMacOSXClearMenubarActive();

		/*
		 * Handle -postcommand
		 */

		TkMacOSXPreprocessMenu();
		TkMacOSXTrackingLoop(1);
		break;
	    case kEventMenuEndTracking:
		TkMacOSXTrackingLoop(0);
		break;
	    case kEventMenuOpening:
		err = ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamDirectObject, typeMenuRef, NULL,
			sizeof(menu), NULL, &menu);
		if (err == noErr) {
		    TkMacOSXClearActiveMenu(menu);
		    return TkMacOSXGenerateParentMenuSelectEvent(menu);
		}
		break;
	    case kEventMenuTargetItem:
		err = ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamDirectObject, typeMenuRef, NULL,
			sizeof(menu), NULL, &menu);
		if (err == noErr) {
		    MenuItemIndex index;

		    err = ChkErr(GetEventParameter, eventPtr->eventRef,
			    kEventParamMenuItemIndex, typeMenuItemIndex, NULL,
			    sizeof(index), NULL, &index);
		    if (err == noErr) {
			return TkMacOSXGenerateMenuSelectEvent(menu, index);
		    }
		}
		break;
	}
d169 2
a170 2
 *	This routine processes the event in eventPtr, and
 *	generates the appropriate Tk events from it.
d173 1
a173 1
 *	True if event(s) are generated - false otherwise.
d176 1
a176 1
 *	Additional events may be place on the Tk event queue.
d182 1
a182 3
TkMacOSXProcessCommandEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus * statusPtr)
d184 3
a186 3
    HICommand command;
    int menuContext;
    OSStatus err;
d196 6
a201 4
    err = ChkErr(GetEventParameter, eventPtr->eventRef,
	    kEventParamDirectObject, typeHICommand, NULL, sizeof(command),
	    NULL, &command);
    if (err == noErr && (command.attributes & kHICommandFromMenu)) {
d203 6
a208 4
	    err = ChkErr(GetEventParameter, eventPtr->eventRef,
		    kEventParamMenuContext, typeUInt32, NULL,
		    sizeof(menuContext), NULL, &menuContext);
	    if (err == noErr && (menuContext & kMenuContextMenuBar) &&
d218 1
a218 1
		if (Tcl_GetCommandInfo(eventPtr->interp,
d220 1
a220 1
		    if (!IsMenuItemEnabled(command.menu.menuRef,
d226 1
a226 1
		    if (IsMenuItemEnabled(command.menu.menuRef,
d239 53
@


1.3.2.11
log
@	* macosx/tkMacOSXMenu.c (DrawMenuSeparator): use DrawingContext API.

	* macosx/tkMacOSXWindowEvent.c (ClearPort): clip to updateRgn.

	* macosx/tkMacOSXDebug.c:	factor out debug region flashing.
	* macosx/tkMacOSXDebug.h:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:

	* macosx/tkMacOSXEvent.c:	cleanup whitespace and formatting.
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* xlib/xgc.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.10 2007/04/29 02:26:49 das Exp $
d27 1
a27 1
 *	is called by XSync().
@


1.3.2.12
log
@	* macosx/tkMacOSXWindowEvent.c (GenerateUpdateEvent): complete all
	pending idle-time redraws before newly posted Expose events are
	processed; add bounds of redrawn windows to update region to ensure all
	child windows overdrawn by parents are redrawn.

	* macosx/tkMacOSXWindowEvent.c:	centralize clip and window invalidation
	* macosx/tkMacOSXSubwindows.c:	after location/size changes in the
	* macosx/tkMacOSXWm.c:		BoundsChanged carbon event handler;
	correct/add window invalidation after window attribute changes.

	* macosx/tkMacOSXSubwindows.c (XResizeWindow, XMoveResizeWindow,
	XMoveWindow): factor out common code dealing with embedded and
	non-toplevel windows; remove unnecessary clip and window invalidation.

	* macosx/tkMacOSXButton.c (TkpDisplayButton): move clip setup closer to
	native button drawing calls.

	* macosx/tkMacOSXWm.c (TkMacOSXIsWindowZoomed, TkMacOSXZoomToplevel):
	correct handle gridded windows in max size calculations.

	* macosx/tkMacOSXEvent.c (TkMacOSXFlushWindows): use HIWindowFlush API
	when available.

	* macosx/tkMacOSXColor.c:	cleanup whitespace and formatting.
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.11 2007/05/30 06:39:38 das Exp $
d44 3
a46 15
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
	if (1
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1030
		&& HIWindowFlush != NULL
#endif
	) {
	    ChkErr(HIWindowFlush, wRef);
	} else
#endif
	{
	    CGrafPtr portPtr = GetWindowPort(wRef);

	    if (QDIsPortBuffered(portPtr)) {
		QDFlushPortBuffer(portPtr, NULL);
	    }
@


1.3.2.13
log
@	* macosx/tkMacOSXMouseEvent.c (GenerateMouseWheelEvent): enable
	processing of mousewheel events in background windows.

	* macosx/tkMacOSXScrlbr.c: modernize checks for active/front window.
	* macosx/tkMacOSXScale.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXColor.c: factor out verbose #ifdef checks of
	* macosx/tkMacOSXDraw.c:  MAC_OS_X_VERSION_{MAX_ALLOWED,MIN_REQUIRED}
	* macosx/tkMacOSXEntry.c: and runtime checks of kHIToolboxVersion into
	* macosx/tkMacOSXEvent.c: new TK_{IF,ELSE,ENDIF}_MAC_OS_X macros.
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c:  factor out clip clearing in QD ports;
	* macosx/tkMacOSXEntry.c: formatting cleanup.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.12 2007/05/31 13:42:12 das Exp $
d44 6
a49 1
	TK_IF_MAC_OS_X_API (3, HIWindowFlush,
d51 3
a53 1
	) TK_ELSE_MAC_OS_X (3,
d59 1
a59 1
	) TK_ENDIF_MAC_OS_X
@


1.3.2.14
log
@	* macosx/tkMacOSXColor.c: fix issues with TK_{IF,ELSE,ENDIF} macros;
	* macosx/tkMacOSXDraw.c:  implement Jaguar equivalent of unavailable
	* macosx/tkMacOSXEntry.c: kHIToolboxVersion global; panic at startup
	* macosx/tkMacOSXEvent.c: if MAC_OS_X_VERSION_MIN_REQUIRED constraint
	* macosx/tkMacOSXInit.c:  is not satisfied.
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXDraw.c (XCopyArea, XCopyPlane, TkPutImage)
	(TkMacOSXSetupDrawingContext): factor out common code and standardize
	setup/restore of port, context and clipping; formatting cleanup.

	* macosx/tkMacOSXWindowEvent.c:	add error checking.
	* macosx/tkMacOSXMenu.c:	fix gcc3 warning.
	* macosx/tkMacOSXScrlbr.c:	fix testsuite crash.
	* macosx/tkMacOSXSubwindows.c:	formatting cleanup.
	* macosx/tkMacOSXRegion.c:	fix typos.
	* macosx/tkMacOSXScale.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.13 2007/06/06 09:56:54 das Exp $
d52 1
a52 1
	) TK_ENDIF
@


1.3.2.15
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
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.14 2007/06/09 17:10:21 das Exp $
d16 1
a16 1
#include "tkMacOSXPrivate.h"
@


1.3.2.16
log
@	Backport from HEAD of Aqua changes from 2007-10-12 to 2007-11-09
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.3.2.15 2007/06/29 03:22:02 das Exp $
d246 1
a246 1
			(GetCurrentEventKeyModifiers() & optionKey) != 0);
@


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
@d4 1
a4 4
 * This file contains most of the X calls called by Tk.  Many of
 * these calls are just stubs and either don't make sense on the
 * Macintosh or thier implamentation just doesn't do anything.  Other
 * calls will eventually be moved into other files.
a15 5
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/ioctl.h>
a20 2
#define TK_MAC_DEBUG 1

d22 1
a22 2
 * The following are undocumented event classes
 *
d24 5
a28 8
enum {
    kEventClassUser = 'user',
    kEventClassCgs  = 'cgs ',
};
 
/*  
 * The following are undocumented event kinds 
 * 
a29 5
enum {
    kEventMouse8 = 8,
    kEventMouse9 = 9, 
    kEventApp103 = 103
};   
d31 6
a36 1
EventRef TkMacOSXCreateFakeEvent ();
d39 1
a39 1
 * Forward declarations of procedures used in this file.
a40 1
static int ReceiveAndProcessEvent _ANSI_ARGS_(());
d44 1
d50 3
a52 2
 *      This routine flushes all the Carbon windows of the application
 *      It is called by the setup procedure for the Tcl/Carbon event source
d74 2
a75 1
}
d81 4
a84 3
 *      This routine receives any Carbon events that aare in the 
 *      queue and converts them to tk events
 *      It is called by the event set-up and check routines
d89 3
a91 3
 *      Tells the Window Manager to deliver events to the event 
 *      queue of the current thread.
 *      Receives any Carbon events on the queue and converts them to tk events
d110 2
a111 1
}
d120 2
a121 2
 *               0 on success
 *               -1 on failure
d124 1
a124 1
 *               Calls the Tk high-level event handler
a144 2
        } else {
            statusPtr->handledByTk = 1;
d153 1
d161 6
a195 2
        case kEventClassCgs:
        case kEventClassUser:
d197 1
a197 1
            statusPtr->handledByTk = 1;
d213 1
d220 1
a220 1
 *      This receives a carbon event and converts it to a tk event
d227 2
a228 2
 *      This receives the next Carbon event
 *      and converts it to the appropriate tk event
d255 1
a255 1
        if (!eventStatus.handledByTk) {
d261 5
a265 1
            if (err != noErr /* && err != eventNotHandledErr */) {
@


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


1.1.2.1
log
@First checkin of support for Tk on Mac OS X.
@
text
@a0 278
/* 
 * tkMacOSXEvent.c --
 *
 * This file contains most of the X calls called by Tk.  Many of
 * these calls are just stubs and either don't make sense on the
 * Macintosh or thier implamentation just doesn't do anything.  Other
 * calls will eventually be moved into other files.
 *
 * 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/ioctl.h>

#include <tcl.h>

#include "tkMacOSXInt.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXDebug.h"

#define TK_MAC_DEBUG 1

/*
 * The following are undocumented event classes
 *
 */
enum {
    kEventClassUser = 'user',
    kEventClassCgs  = 'cgs ',
};
 
/*  
 * The following are undocumented event kinds 
 * 
 */ 
enum {
    kEventMouse8 = 8,
    kEventMouse9 = 9, 
    kEventApp103 = 103
};   

EventRef TkMacOSXCreateFakeEvent ();

/*   
 * Forward declarations of procedures used in this file.
 */ 
static int ReceiveAndProcessEvent _ANSI_ARGS_(());

static EventTargetRef targetRef;

/*
 *----------------------------------------------------------------------
 *
 * tkMacOSXFlushWindows --
 *
 *      This routine flushes all the Carbon windows of the application
 *      It is called by the setup procedure for the Tcl/Carbon event source
 * Results:
 *      None.
 *
 * Side effects:
 *      Flushes all Carbon windows
 *
 *----------------------------------------------------------------------
 */

void
tkMacOSXFlushWindows ()
{
    WindowRef wRef = GetWindowList();
    
    while (wRef) {
        CGrafPtr portPtr = GetWindowPort(wRef);
        if (QDIsPortBuffered(portPtr)) {
            QDFlushPortBuffer(portPtr, NULL);
        }
        wRef=GetNextWindow(wRef);
    }
}
/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXCountAndProcessMacEvents --
 *
 *      This routine receives any Carbon events that aare in the 
 *      queue and converts them to tk events
 *      It is called by the event set-up and check routines
 * Results:
 *      The number of events in the queue.
 *
 * Side effects:
 *      Tells the Window Manager to deliver events to the event 
 *      queue of the current thread.
 *      Receives any Carbon events on the queue and converts them to tk events
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXCountAndProcessMacEvents()
{
    EventQueueRef qPtr;
    int           eventCount;
    qPtr = GetMainEventQueue();
    eventCount = GetNumEventsInQueue(qPtr);
    if (eventCount) {
        int n, err;
        for (n = 0, err = 0;n<eventCount && !err;n++) {
            err = ReceiveAndProcessEvent();
        }
    }
    return eventCount;
}
/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessAppleEvent --
 *
 *      This processes Apple events
 *
 * Results:
 *               0 on success
 *               -1 on failure
 *
 * Side effects:
 *               Calls the Tk high-level event handler
 *
 *----------------------------------------------------------------------
 */

static int
TkMacOSXProcessAppleEvent(TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr)
{
    int  err;
    EventRecord eventRecord;
    if (ConvertEventRefToEventRecord(eventPtr->eventRef,
        &eventRecord )) {
        err=TkMacOSXDoHLEvent(&eventRecord);
        if (err!=noErr) {
            char buf1 [ 256 ];
            char buf2 [ 256 ];
            fprintf(stderr,
                "TkMacOSXDoHLEvent failed : %s,%s,%d\n",
                CarbonEventToAscii(eventPtr->eventRef, buf1),
                ClassicEventToAscii(&eventRecord,buf2), err);
            statusPtr->err = 1;
        } else {
            statusPtr->handledByTk = 1;
        }
    } else {
        statusPtr->err = 1;
        fprintf(stderr,"ConvertEventRefToEventRecord failed\n");
    }
    return 0;
}

/*      
 *----------------------------------------------------------------------
 *   
 * TkMacOSXProcessEvent --
 *   
 *      This dispatches a filtered Carbon event to the appropriate handler
 *
 * Results: 
 *      0 on success
 *      -1 on failure
 *
 * Side effects:
 *      Converts a Carbon event to a Tk event
 *   
 *----------------------------------------------------------------------
 */

static int  
TkMacOSXProcessEvent(TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr)
{
    switch (eventPtr->eClass) {
        case kEventClassMouse:
            TkMacOSXProcessMouseEvent(eventPtr, statusPtr);
            break;
        case kEventClassWindow:
            TkMacOSXProcessWindowEvent(eventPtr, statusPtr);
            break;  
        case kEventClassKeyboard:
            TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr);
            break;
        case kEventClassApplication:
            TkMacOSXProcessApplicationEvent(eventPtr, statusPtr);
            break;
        case kEventClassAppleEvent:
            TkMacOSXProcessAppleEvent(eventPtr, statusPtr);
            break;  
        case kEventClassCgs:
        case kEventClassUser:
        case kEventClassWish: 
            statusPtr->handledByTk = 1;
            break;  
        default:
#ifdef TK_MAC_DEBUG
            if (0)
            {
                char buf [ 256 ];
                fprintf(stderr,
                    "Unrecognised event : %s\n",
                    CarbonEventToAscii(eventPtr->eventRef, buf));
            }
#endif
            break;
    }   
    return 0;
}   

/*
 *----------------------------------------------------------------------
 *
 * ReceiveAndProcessEvent --
 *
 *      This receives a carbon event and converts it to a tk event
 *
 * Results:
 *      0 on success
 *      Mac OS error number on failure
 *
 * Side effects:
 *      This receives the next Carbon event
 *      and converts it to the appropriate tk event
 *
 *----------------------------------------------------------------------
 */

static int
ReceiveAndProcessEvent()
{
    TkMacOSXEvent       macEvent;
    MacEventStatus   eventStatus;
    int              err;
    char             buf [ 256 ];

    /*
     * This is a poll, since we have already counted the events coming
     * into this routine, and are guaranteed to have one waiting.
     */
     
    err=ReceiveNextEvent(0, NULL, kEventDurationNoWait, 
            true, &macEvent.eventRef);
    if (err != noErr) {
        return err;
    } else {
        macEvent.eClass = GetEventClass(macEvent.eventRef);
        macEvent.eKind = GetEventKind(macEvent.eventRef);
        bzero(&eventStatus, sizeof(eventStatus));
        TkMacOSXProcessEvent(&macEvent,&eventStatus);
        if (!eventStatus.handledByTk) {
            if (!targetRef) {
                targetRef=GetEventDispatcherTarget();
            }
            
            err= SendEventToEventTarget(macEvent.eventRef,targetRef);
            if (err != noErr) {
                fprintf(stderr,
                        "RCNE SendEventToEventTarget (%s) failed, %d\n",
                        CarbonEventToAscii(macEvent.eventRef,buf ),err);
            }
         }
         ReleaseEvent(macEvent.eventRef);
         return 0;
     }
}
@


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
@d15 1
a15 1
 * RCS: @@(#) $Id: tkMacOSXEvent.c,v 1.1.2.1 2001/10/15 09:22:00 wolfsuit Exp $
d24 2
@


1.1.2.3
log
@Merging with TOT as of 06/09/2002.
@
text
@d15 1
a15 1
 * RCS: @@(#) $Id$
d267 1
a267 1
            if (err != noErr /* && err != eventNotHandledErr */) {
@


