head	1.38;
access;
symbols
	core-8-5-9:1.34
	core-8-5-8:1.34
	macosx-cocoa-merge:1.36
	macosx-cocoa-premerge:1.35
	macosx-carbon-freeze:1.35
	core-8-5-7:1.34
	core-8-5-6:1.34
	core-8-6-b1:1.35
	core-8-6-a3:1.34
	core-8-5-5:1.34
	core-8-6-a2:1.34
	core-8-5-4:1.34
	core-8-5-3:1.34
	core-8-6-a1:1.34
	core-8-4-19:1.6.2.23
	core-8-5-branch:1.34.0.2
	core-8-5-2:1.34
	core-8-4-18:1.6.2.23
	core-8-5-1:1.34
	core-8-4-17:1.6.2.23
	core-8-5-0:1.34
	core-8-5-b3:1.32
	core-8-5-b2:1.32
	core-8-4-16:1.6.2.22
	core-8-5-b1:1.32
	core-stablilizer-merge:1.32
	core-stabilizer-branch:1.29.0.2
	core-stabilizer-merge:1.34
	core-8-4-15:1.6.2.19
	core-8-5-a6:1.28
	core-8-5-a5:1.25
	core-8-4-14:1.6.2.17
	core-8-5-a4:1.21
	core-8-4-13:1.6.2.13
	core-8-4-12:1.6.2.9
	core-8-4-11:1.6.2.4
	core-8-5-a3:1.11
	core-8-4-10:1.6.2.4
	core-8-4-9-branch:1.6.2.3.0.2
	core-8-5-a2:1.10
	core-8-4-9:1.6.2.3
	core-8-4-8:1.6.2.3
	core-8-4-7:1.6.2.2
	core-8-5-a1:1.9
	core-8-4-6:1.6.2.2
	core-8-4-5:1.6
	mistachkin-dev-branch:1.7.0.2
	core-8-4-4:1.6
	core-8-4-3:1.6
	core-8-4-branch:1.6.0.2
	core-8-4-2:1.6
	core-8-4-1:1.3
	core-8-4-0:1.3
	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.38
date	2010.01.06.14.58.30;	author dkf;	state Exp;
branches;
next	1.37;

1.37
date	2009.07.06.20.29.21;	author dkf;	state Exp;
branches;
next	1.36;

1.36
date	2009.06.29.14.35.01;	author das;	state Exp;
branches;
next	1.35;

1.35
date	2008.10.27.11.55.45;	author dkf;	state Exp;
branches;
next	1.34;

1.34
date	2007.12.13.15.27.10;	author dgp;	state Exp;
branches;
next	1.33;

1.33
date	2007.12.12.23.44.22;	author das;	state Exp;
branches;
next	1.32;

1.32
date	2007.07.09.08.31.54;	author das;	state Exp;
branches;
next	1.31;

1.31
date	2007.06.29.03.20.02;	author das;	state Exp;
branches;
next	1.30;

1.30
date	2007.06.06.09.55.52;	author das;	state Exp;
branches;
next	1.29;

1.29
date	2007.05.09.12.55.15;	author das;	state Exp;
branches
	1.29.2.1;
next	1.28;

1.28
date	2007.04.23.21.24.33;	author das;	state Exp;
branches;
next	1.27;

1.27
date	2007.04.21.19.06.38;	author hobbs;	state Exp;
branches;
next	1.26;

1.26
date	2007.04.13.14.51.18;	author dkf;	state Exp;
branches;
next	1.25;

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

1.24
date	2006.08.18.07.47.11;	author das;	state Exp;
branches;
next	1.23;

1.23
date	2006.07.20.06.25.19;	author das;	state Exp;
branches;
next	1.22;

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

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

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

1.19
date	2006.04.06.22.16.09;	author vincentdarley;	state Exp;
branches;
next	1.18;

1.18
date	2006.04.06.22.15.14;	author vincentdarley;	state Exp;
branches;
next	1.17;

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

1.16
date	2005.12.13.03.44.34;	author das;	state Exp;
branches;
next	1.15;

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

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

1.13
date	2005.08.09.07.39.21;	author das;	state Exp;
branches;
next	1.12;

1.12
date	2005.07.21.20.40.18;	author hobbs;	state Exp;
branches;
next	1.11;

1.11
date	2005.03.10.07.36.23;	author wolfsuit;	state Exp;
branches;
next	1.10;

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

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

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

1.7
date	2003.07.18.11.04.59;	author vincentdarley;	state Exp;
branches;
next	1.6;

1.6
date	2003.02.19.22.20.56;	author wolfsuit;	state Exp;
branches
	1.6.2.1;
next	1.5;

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

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

1.3
date	2002.09.09.23.52.02;	author hobbs;	state Exp;
branches;
next	1.2;

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

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

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

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

1.1.2.3
date	2002.06.10.05.38.26;	author wolfsuit;	state Exp;
branches;
next	;

1.6.2.1
date	2004.02.16.00.42.34;	author wolfsuit;	state Exp;
branches;
next	1.6.2.2;

1.6.2.2
date	2004.02.17.07.17.18;	author das;	state Exp;
branches;
next	1.6.2.3;

1.6.2.3
date	2004.11.11.01.26.43;	author das;	state Exp;
branches;
next	1.6.2.4;

1.6.2.4
date	2005.03.10.07.32.28;	author wolfsuit;	state Exp;
branches;
next	1.6.2.5;

1.6.2.5
date	2005.07.21.20.41.49;	author hobbs;	state Exp;
branches;
next	1.6.2.6;

1.6.2.6
date	2005.07.28.08.00.57;	author hobbs;	state Exp;
branches;
next	1.6.2.7;

1.6.2.7
date	2005.08.09.07.40.01;	author das;	state Exp;
branches;
next	1.6.2.8;

1.6.2.8
date	2005.09.10.14.54.17;	author das;	state Exp;
branches;
next	1.6.2.9;

1.6.2.9
date	2005.11.27.02.36.46;	author das;	state Exp;
branches;
next	1.6.2.10;

1.6.2.10
date	2005.12.13.03.44.42;	author das;	state Exp;
branches;
next	1.6.2.11;

1.6.2.11
date	2006.03.28.02.44.13;	author das;	state Exp;
branches;
next	1.6.2.12;

1.6.2.12
date	2006.04.07.06.16.03;	author das;	state Exp;
branches;
next	1.6.2.13;

1.6.2.13
date	2006.04.11.05.42.11;	author das;	state Exp;
branches;
next	1.6.2.14;

1.6.2.14
date	2006.04.28.06.03.00;	author das;	state Exp;
branches;
next	1.6.2.15;

1.6.2.15
date	2006.07.20.06.27.34;	author das;	state Exp;
branches;
next	1.6.2.16;

1.6.2.16
date	2006.08.18.07.47.25;	author das;	state Exp;
branches;
next	1.6.2.17;

1.6.2.17
date	2006.09.10.17.07.36;	author das;	state Exp;
branches;
next	1.6.2.18;

1.6.2.18
date	2007.04.29.02.26.49;	author das;	state Exp;
branches;
next	1.6.2.19;

1.6.2.19
date	2007.05.09.12.57.46;	author das;	state Exp;
branches;
next	1.6.2.20;

1.6.2.20
date	2007.06.06.09.56.54;	author das;	state Exp;
branches;
next	1.6.2.21;

1.6.2.21
date	2007.06.29.03.22.02;	author das;	state Exp;
branches;
next	1.6.2.22;

1.6.2.22
date	2007.07.09.08.32.12;	author das;	state Exp;
branches;
next	1.6.2.23;

1.6.2.23
date	2007.12.18.18.21.30;	author das;	state Exp;
branches;
next	;

1.29.2.1
date	2007.06.12.16.22.42;	author dgp;	state Exp;
branches;
next	1.29.2.2;

1.29.2.2
date	2007.07.01.17.31.37;	author dgp;	state Exp;
branches;
next	1.29.2.3;

1.29.2.3
date	2007.07.10.21.54.28;	author dgp;	state Exp;
branches;
next	1.29.2.4;

1.29.2.4
date	2007.12.13.06.28.48;	author dgp;	state Exp;
branches;
next	;


desc
@@


1.38
log
@[Bug 2926819]: Factor out the pointer warping code a bit better and extend it
to work on OSX too.
@
text
@/*
 * tkMacOSXMouseEvent.c --
 *
 *	This file implements functions that decode & handle mouse events on
 *	MacOS X.
 *
 * 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: tkMacOSXMouseEvent.c,v 1.37 2009/07/06 20:29:21 dkf Exp $
 */

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

typedef struct {
    unsigned int state;
    long delta;
    Window window;
    Point global;
    Point local;
} MouseEventData;

static int		GenerateButtonEvent(MouseEventData *medPtr);
static unsigned int	ButtonModifiers2State(UInt32 buttonState,
			    UInt32 keyModifiers);

#pragma mark TKApplication(TKMouseEvent)

enum {
    NSWindowWillMoveEventType = 20
};

@@implementation TKApplication(TKMouseEvent)
- (NSEvent *) tkProcessMouseEvent: (NSEvent *) theEvent
{
#ifdef TK_MAC_DEBUG_EVENTS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, theEvent);
#endif
    id		    win;
    NSEventType	    type = [theEvent type];
#if 0
    NSTrackingArea  *trackingArea = nil;
    NSInteger eventNumber, clickCount, buttonNumber;
#endif

    switch (type) {
    case NSMouseEntered:
    case NSMouseExited:
    case NSCursorUpdate:
#if 0
	trackingArea = [theEvent trackingArea];
#endif
	/* fall through */
    case NSLeftMouseDown:
    case NSLeftMouseUp:
    case NSRightMouseDown:
    case NSRightMouseUp:
    case NSOtherMouseDown:
    case NSOtherMouseUp:

    case NSLeftMouseDragged:
    case NSRightMouseDragged:
    case NSOtherMouseDragged:

    case NSMouseMoved:
#if 0
	eventNumber = [theEvent eventNumber];
	if (!trackingArea) {
	    clickCount = [theEvent clickCount];
	    buttonNumber = [theEvent buttonNumber];
	}
#endif

    case NSTabletPoint:
    case NSTabletProximity:

    case NSScrollWheel:
	win = [self windowWithWindowNumber:[theEvent windowNumber]];
        break;

    default:
	return theEvent;
	break;
    }

    NSPoint global, local = [theEvent locationInWindow];

    if (win) {
	global = [win convertBaseToScreen:local];
	local.y = [win frame].size.height - local.y;
	global.y = tkMacOSXZeroScreenHeight - global.y;
    } else {
	local.y = tkMacOSXZeroScreenHeight - local.y;
	global = local;
    }

    Window window = TkMacOSXGetXWindow(win);
    Tk_Window tkwin = window ? Tk_IdToWindow(TkGetDisplayList()->display,
	    window) : NULL;
    if (!tkwin) {
	tkwin = TkMacOSXGetCapture();
    }
    if (!tkwin) {
	return theEvent;
    }

    /*
    MacDrawable *macWin = (MacDrawable *) window;
    NSView *view = TkMacOSXDrawableView(macWin);
    local = [view convertPoint:local fromView:nil];
    local.y = NSHeight([view bounds]) - local.y;
    */
    TkWindow  *winPtr = (TkWindow *) tkwin;
    local.x -= winPtr->wmInfoPtr->xInParent;
    local.y -= winPtr->wmInfoPtr->yInParent;

    int win_x, win_y;
    tkwin = Tk_TopCoordsToWindow(tkwin, local.x, local.y,
		&win_x, &win_y);

    unsigned int state = 0;
    NSInteger button = [theEvent buttonNumber];
    EventRef eventRef = (EventRef)[theEvent eventRef];
    UInt32 buttons;
    OSStatus err = GetEventParameter(eventRef, kEventParamMouseChord,
	    typeUInt32, NULL, sizeof(UInt32), NULL, &buttons);

    if (err == noErr) {
	state |= (buttons & ((1<<5) - 1)) << 8;
    } else if (button < 5) {
	switch (type) {
	case NSLeftMouseDown:
	case NSRightMouseDown:
	case NSLeftMouseDragged:
	case NSRightMouseDragged:
	case NSOtherMouseDown:
	    state |= 1 << (button + 8);
	    break;
	default:
	    break;
	}
    }

    NSUInteger modifiers = [theEvent modifierFlags];

    if (modifiers & NSAlphaShiftKeyMask) {
	state |= LockMask;
    }
    if (modifiers & NSShiftKeyMask) {
	state |= ShiftMask;
    }
    if (modifiers & NSControlKeyMask) {
	state |= ControlMask;
    }
    if (modifiers & NSCommandKeyMask) {
	state |= Mod1Mask;		/* command key */
    }
    if (modifiers & NSAlternateKeyMask) {
	state |= Mod2Mask;		/* option key */
    }
    if (modifiers & NSNumericPadKeyMask) {
	state |= Mod3Mask;
    }
    if (modifiers & NSFunctionKeyMask) {
	state |= Mod4Mask;
    }

    if (type != NSScrollWheel) {
#ifdef TK_MAC_DEBUG_EVENTS
	TKLog(@@"UpdatePointer %p x %f.0 y %f.0 %d", tkwin, global.x, global.y, state);
#endif
	Tk_UpdatePointer(tkwin, global.x, global.y, state);
    } else {
	CGFloat delta;
	int coarseDelta;
	XEvent xEvent;

	xEvent.type = MouseWheelEvent;
	xEvent.xbutton.x = local.x;
	xEvent.xbutton.y = local.y;
	xEvent.xbutton.x_root = global.x;
	xEvent.xbutton.y_root = global.y;
	xEvent.xany.send_event = false;
	xEvent.xany.display = Tk_Display(tkwin);
	xEvent.xany.window = Tk_WindowId(tkwin);

	delta = [theEvent deltaY];
	if (delta != 0.0) {
	    coarseDelta = (delta > -1.0 && delta < 1.0) ? (signbit(delta) ? -1 : 1) : lround(delta);
	    xEvent.xbutton.state = state;
	    xEvent.xkey.keycode = coarseDelta;
	    xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
	    Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
	}
	delta = [theEvent deltaX];
	if (delta != 0.0) {
	    coarseDelta = (delta > -1.0 && delta < 1.0) ? (signbit(delta) ? -1 : 1) : lround(delta);
	    xEvent.xbutton.state = state | ShiftMask;
	    xEvent.xkey.keycode = coarseDelta;
	    xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
	    Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
	}
    }

    return theEvent;
}
@@end

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXKeyModifiers --
 *
 *	Returns the current state of the modifier keys.
 *
 * Results:
 *	An OS Modifier state.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

EventModifiers
TkMacOSXModifierState(void)
{
    UInt32 keyModifiers;
    int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront());

    keyModifiers = isFrontProcess ? GetCurrentEventKeyModifiers() :
	    GetCurrentKeyModifiers();

    return (EventModifiers) (keyModifiers & USHRT_MAX);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXButtonKeyState --
 *
 *	Returns the current state of the button & modifier keys.
 *
 * Results:
 *	A bitwise inclusive OR of a subset of the following: Button1Mask,
 *	ShiftMask, LockMask, ControlMask, Mod*Mask.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

unsigned int
TkMacOSXButtonKeyState(void)
{
    UInt32 buttonState = 0, keyModifiers;
    int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront());

    buttonState = isFrontProcess ? GetCurrentEventButtonState() :
	    GetCurrentButtonState();
    keyModifiers = isFrontProcess ? GetCurrentEventKeyModifiers() :
	    GetCurrentKeyModifiers();

    return ButtonModifiers2State(buttonState, keyModifiers);
}

/*
 *----------------------------------------------------------------------
 *
 * ButtonModifiers2State --
 *
 *	Converts Carbon mouse button state and modifier values into a Tk
 *	button/modifier state.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static unsigned int
ButtonModifiers2State(
    UInt32 buttonState,
    UInt32 keyModifiers)
{
    unsigned int state;

    /*
     * Tk supports at most 5 buttons.
     */

    state = (buttonState & ((1<<5) - 1)) << 8;

    if (keyModifiers & alphaLock) {
	state |= LockMask;
    }
    if (keyModifiers & shiftKey) {
	state |= ShiftMask;
    }
    if (keyModifiers & controlKey) {
	state |= ControlMask;
    }
    if (keyModifiers & cmdKey) {
	state |= Mod1Mask;		/* command key */
    }
    if (keyModifiers & optionKey) {
	state |= Mod2Mask;		/* option key */
    }
    if (keyModifiers & kEventKeyModifierNumLockMask) {
	state |= Mod3Mask;
    }
    if (keyModifiers & kEventKeyModifierFnMask) {
	state |= Mod4Mask;
    }

    return state;
}

/*
 *----------------------------------------------------------------------
 *
 * XQueryPointer --
 *
 *	Check the current state of the mouse. This is not a complete
 *	implementation of this function. It only computes the root coordinates
 *	and the current mask.
 *
 * Results:
 *	Sets root_x_return, root_y_return, and mask_return. Returns true on
 *	success.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Bool
XQueryPointer(
    Display *display,
    Window w,
    Window *root_return,
    Window *child_return,
    int *root_x_return,
    int *root_y_return,
    int *win_x_return,
    int *win_y_return,
    unsigned int *mask_return)
{
    int getGlobal = (root_x_return && root_y_return);
    int getLocal = (win_x_return && win_y_return && w != None);

    if (getGlobal || getLocal) {
	NSPoint global = [NSEvent mouseLocation];

	if (getLocal) {
	    MacDrawable *macWin = (MacDrawable *) w;
	    NSWindow *win = TkMacOSXDrawableWindow(w);

	    if (win) {
		NSPoint local;

		local = [win convertScreenToBase:global];
		local.y = [win frame].size.height - local.y;
		if (macWin->winPtr && macWin->winPtr->wmInfoPtr) {
		    local.x -= macWin->winPtr->wmInfoPtr->xInParent;
		    local.y -= macWin->winPtr->wmInfoPtr->yInParent;
		}
		*win_x_return = local.x;
		*win_y_return = local.y;
	    }
	}
	if (getGlobal) {
	    *root_x_return = global.x;
	    *root_y_return = tkMacOSXZeroScreenHeight - global.y;
	}
    }
    if (mask_return) {
	*mask_return = TkMacOSXButtonKeyState();
    }
    return True;
}

/*
 *----------------------------------------------------------------------
 *
 * TkGenerateButtonEventForXPointer --
 *
 *	This procedure generates an X button event for the current pointer
 *	state as reported by XQueryPointer().
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue. Grab state may
 *	also change.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE int
TkGenerateButtonEventForXPointer(
    Window window)		/* X Window containing button event. */
{
    MouseEventData med;
    int global_x, global_y, local_x, local_y;

    bzero(&med, sizeof(MouseEventData));
    XQueryPointer(NULL, window, NULL, NULL, &global_x, &global_y,
	    &local_x, &local_y, &med.state);
    med.global.h = global_x;
    med.global.v = global_y;
    med.local.h = local_x;
    med.local.v = local_y;
    med.window = window;

    return GenerateButtonEvent(&med);
}

/*
 *----------------------------------------------------------------------
 *
 * TkGenerateButtonEvent --
 *
 *	Given a global x & y position and the button key status this procedure
 *	generates the appropiate X button event. It also handles the state
 *	changes needed to implement implicit grabs.
 *
 * Results:
 *	True if event(s) are generated, false otherwise.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue. Grab state may
 *	also change.
 *
 *----------------------------------------------------------------------
 */

int
TkGenerateButtonEvent(
    int x,			/* X location of mouse, */
    int y,			/* Y location of mouse. */
    Window window,		/* X Window containing button event. */
    unsigned int state)		/* Button Key state suitable for X event. */
{
    MacDrawable *macWin = (MacDrawable *) window;
    NSWindow *win = TkMacOSXDrawableWindow(window);
    MouseEventData med;

    bzero(&med, sizeof(MouseEventData));
    med.state = state;
    med.window = window;
    med.global.h = x;
    med.global.v = y;
    med.local = med.global;

    if (win) {
	NSPoint local = NSMakePoint(x, tkMacOSXZeroScreenHeight - y);

	local = [win convertScreenToBase:local];
	local.y = [win frame].size.height - local.y;
	if (macWin->winPtr && macWin->winPtr->wmInfoPtr) {
	    local.x -= macWin->winPtr->wmInfoPtr->xInParent;
	    local.y -= macWin->winPtr->wmInfoPtr->yInParent;
	}
	med.local.h = local.x;
	med.local.v = tkMacOSXZeroScreenHeight - local.y;
    }

    return GenerateButtonEvent(&med);
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateButtonEvent --
 *
 *	Generate an X button event from a MouseEventData structure. Handles
 *	the state changes needed to implement implicit grabs.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue. Grab state may
 *	also change.
 *
 *----------------------------------------------------------------------
 */

static int
GenerateButtonEvent(
    MouseEventData *medPtr)
{
    Tk_Window tkwin;
    int dummy;
    TkDisplay *dispPtr;

#if UNUSED
    /*
     * ButtonDown events will always occur in the front window. ButtonUp
     * events, however, may occur anywhere on the screen. ButtonUp events
     * should only be sent to Tk if in the front window or during an implicit
     * grab.
     */

    if ((medPtr->activeNonFloating == NULL)
	    || ((!(TkpIsWindowFloating(medPtr->whichWin))
	    && (medPtr->activeNonFloating != medPtr->whichWin))
	    && TkMacOSXGetCapture() == NULL)) {
	return false;
    }
#endif

    dispPtr = TkGetDisplayList();
    tkwin = Tk_IdToWindow(dispPtr->display, medPtr->window);

    if (tkwin != NULL) {
	tkwin = Tk_TopCoordsToWindow(tkwin, medPtr->local.h, medPtr->local.v,
		&dummy, &dummy);
    }

    Tk_UpdatePointer(tkwin, medPtr->global.h, medPtr->global.v, medPtr->state);
    return true;
}

void
TkpWarpPointer(
    TkDisplay *dispPtr)
{
    CGPoint pt;
    UInt32 buttonState;

    if (dispPtr->warpWindow) {
	int x, y;

	Tk_GetRootCoords(dispPtr->warpWindow, &x, &y);
	pt.x = x + dispPtr->warpX;
	pt.y = y + dispPtr->warpY;
    } else {
	pt.x = dispPtr->warpX;
	pt.y = dispPtr->warpY;
    }

    /*
     * Tell the OSX core to generate the events to make it happen. This is
     * fairly ugly, but means that under most circumstances we'll register all
     * the events that would normally be generated correctly. If we use
     * CGWarpMouseCursorPosition instead, strange things happen.
     */

    buttonState = (GetCurrentEvent() && Tk_MacOSXIsAppInFront())
	    ? GetCurrentEventButtonState() : GetCurrentButtonState();

    CGPostMouseEvent(pt, 1 /* generate motion events */, 5,
	    buttonState&1 ? 1 : 0, buttonState&2 ? 1 : 0,
	    buttonState&4 ? 1 : 0, buttonState&8 ? 1 : 0,
	    buttonState&16 ? 1 : 0);
}

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */
@


1.37
log
@More marking of files as Objective-C.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.36 2009/06/29 14:35:01 das Exp $
d540 34
@


1.36
log
@Merge of TkAqua Cocoa port
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.35 2008/10/27 11:55:45 dkf Exp $
d40 2
a41 1
- (NSEvent *)tkProcessMouseEvent:(NSEvent *)theEvent {
d93 1
d133 1
d136 11
a146 13
    } else {
	if (button < 5) {
	    switch (type) {
	    case NSLeftMouseDown:
	    case NSRightMouseDown:
	    case NSLeftMouseDragged:
	    case NSRightMouseDragged:
	    case NSOtherMouseDown:
		state |= 1 << (button + 8);
		break;
	    default:
		break;
	    }
d149 1
d542 1
a542 1
 * mode: c
@


1.35
log
@Code style improvements, especially including making code less deeply nested.
@
text
@d7 2
a8 2
 * Copyright 2001, Apple Computer, Inc.
 * Copyright (c) 2005-2007 Daniel A. Steffen <das@@users.sourceforge.net>
d13 1
a13 39
 *	The following terms apply to all files originating from Apple
 *	Computer, Inc. ("Apple") and associated with the software unless
 *	explicitly disclaimed in individual files.
 *
 *	Apple hereby grants permission to use, copy, modify, distribute, and
 *	license this software and its documentation for any purpose, provided
 *	that existing copyright notices are retained in all copies and that
 *	this notice is included verbatim in any distributions. No written
 *	agreement, license, or royalty fee is required for any of the
 *	authorized uses. Modifications to this software may be copyrighted by
 *	their authors and need not follow the licensing terms described here,
 *	provided that the new terms are clearly indicated on the first page of
 *	each file where they apply.
 *
 *	IN NO EVENT SHALL APPLE, THE AUTHORS OR DISTRIBUTORS OF THE SOFTWARE
 *	BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
 *	CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS
 *	DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF APPLE OR THE
 *	AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. APPLE,
 *	THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
 *	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 *	MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
 *	NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
 *	APPLE,THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
 *	MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 *	GOVERNMENT USE: If you are acquiring this software on behalf of the
 *	U.S. government, the Government shall have only "Restricted Rights" in
 *	the software and related documentation as defined in the Federal
 *	Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
 *	acquiring the software on behalf of the Department of Defense, the
 *	software shall be classified as "Commercial Computer Software" and the
 *	Government shall have only "Restricted Rights" as defined in Clause
 *	252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
 *	authors grant the U.S. Government and others acting in its behalf
 *	permission to use and distribute the software in accordance with the
 *	terms specified in this license.
 *
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.34 2007/12/13 15:27:10 dgp Exp $
a21 3
    WindowRef whichWin;
    WindowRef activeNonFloating;
    WindowPartCode windowPart;
a28 14
/*
 * Declarations of static variables used in this file.
 */

static int gEatButtonUp = 0;	/* 1 if we need to eat the next up event. */

/*
 * Declarations of functions used only in this file.
 */

static void		BringWindowForward(WindowRef wRef, int isFrontProcess,
			    int frontWindowOnly);
static int		GeneratePollingEvents(MouseEventData *medPtr);
static int		GenerateMouseWheelEvent(MouseEventData *medPtr);
a29 3
static int		GenerateToolbarButtonEvent(MouseEventData *medPtr);
static int		HandleWindowTitlebarMouseDown(MouseEventData *medPtr,
			    Tk_Window tkwin);
a31 20
static Tk_Window	GetGrabWindowForWindow(Tk_Window tkwin);
static int		TkMacOSXGetEatButtonUp(void);
static void		TkMacOSXSetEatButtonUp(int f);

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessMouseEvent --
 *
 *	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.
 *
 *----------------------------------------------------------------------
 */
d33 1
a33 23
MODULE_SCOPE int
TkMacOSXProcessMouseEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
{
    Tk_Window tkwin;
    Point where, where2;
    int result;
    TkDisplay *dispPtr;
    OSStatus err;
    MouseEventData mouseEventData, *medPtr = &mouseEventData;
    int isFrontProcess;

    switch (eventPtr->eKind) {
    case kEventMouseDown:
    case kEventMouseUp:
    case kEventMouseMoved:
    case kEventMouseDragged:
    case kEventMouseWheelMoved:
	break;
    default:
	return false;
    }
d35 15
a49 6
    err = ChkErr(GetEventParameter, eventPtr->eventRef,
	    kEventParamMouseLocation, typeQDPoint, NULL, sizeof(where), NULL,
	    &where);
    if (err != noErr) {
	GetGlobalMouse(&where);
    }
d51 25
a75 29
    err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamWindowRef,
	    typeWindowRef, NULL, sizeof(WindowRef), NULL, &medPtr->whichWin);
    if (err == noErr) {
	err = ChkErr(GetEventParameter, eventPtr->eventRef,
		kEventParamWindowPartCode, typeWindowPartCode, NULL,
		sizeof(WindowPartCode), NULL, &medPtr->windowPart);
    }
    if (err != noErr) {
	medPtr->windowPart = FindWindow(where, &medPtr->whichWin);
    }
    medPtr->window = TkMacOSXGetXWindow(medPtr->whichWin);
    if (medPtr->whichWin != NULL && medPtr->window == None) {
	return false;
    }
    if (eventPtr->eKind == kEventMouseDown) {
	if (IsWindowActive(medPtr->whichWin) && IsWindowPathSelectEvent(
		medPtr->whichWin, eventPtr->eventRef)) {
	    ChkErr(WindowPathSelect, medPtr->whichWin, NULL, NULL);
	    return false;
	}
	if (medPtr->windowPart == inProxyIcon) {
	    TkMacOSXTrackingLoop(1);
	    err = ChkErr(TrackWindowProxyDrag, medPtr->whichWin, where);
	    TkMacOSXTrackingLoop(0);
	    if (err == errUserWantsToDragWindow) {
		medPtr->windowPart = inDrag;
	    } else {
		return false;
	    }
d77 12
a89 15
    isFrontProcess = Tk_MacOSXIsAppInFront();
    if (isFrontProcess) {
	medPtr->state = ButtonModifiers2State(GetCurrentEventButtonState(),
		GetCurrentEventKeyModifiers());
    } else {
	medPtr->state = ButtonModifiers2State(GetCurrentButtonState(),
		GetCurrentKeyModifiers());
    }
    medPtr->global = where;
    err = ChkErr(GetEventParameter, eventPtr->eventRef,
	    kEventParamWindowMouseLocation, typeQDPoint, NULL,
	    sizeof(Point), NULL, &medPtr->local);
    if (err == noErr) {
	if (medPtr->whichWin) {
	    Rect widths;
d91 5
a95 4
	    GetWindowStructureWidths(medPtr->whichWin, &widths);
	    medPtr->local.h -=	widths.left;
	    medPtr->local.v -=	widths.top;
	}
d97 2
a98 5
	medPtr->local = where;
	if (medPtr->whichWin) {
	    QDGlobalToLocalPoint(GetWindowPort(medPtr->whichWin),
		    &medPtr->local);
	}
a99 3
    medPtr->activeNonFloating = ActiveNonFloatingWindow();
    dispPtr = TkGetDisplayList();
    tkwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
d101 5
a105 46
    if (eventPtr->eKind != kEventMouseDown) {
	int res = false;

	switch (eventPtr->eKind) {
	case kEventMouseUp:
	    /*
	     * The window manager only needs to know about mouse down events
	     * and sometimes we need to "eat" the mouse up. Otherwise, we just
	     * pass the event to Tk.
	     */

	    if (TkMacOSXGetEatButtonUp()) {
		TkMacOSXSetEatButtonUp(false);
	    } else {
		res = GenerateButtonEvent(medPtr);
	    }
	    break;
	case kEventMouseWheelMoved:
	    err = ChkErr(GetEventParameter, eventPtr->eventRef,
		    kEventParamMouseWheelDelta, typeLongInteger, NULL,
		    sizeof(long), NULL, &medPtr->delta);
	    if (err != noErr ) {
		statusPtr->err = 1;
	    } else {
		EventMouseWheelAxis axis;

		err = ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL,
			sizeof(EventMouseWheelAxis), NULL, &axis);
		if (err == noErr && axis == kEventMouseWheelAxisX) {
		    medPtr->state |= ShiftMask;
		}
		res = GenerateMouseWheelEvent(medPtr);
	    }
	    break;
	case kEventMouseMoved:
	case kEventMouseDragged:
	    res = GeneratePollingEvents(medPtr);
	    break;
	default:
	    Tcl_Panic("Unknown mouse event !");
	}
	if (res) {
	    statusPtr->stopProcessing = 1;
	}
	return res;
d107 2
a108 4

    TkMacOSXSetEatButtonUp(false);
    if (!medPtr->whichWin) {
	return false;
d112 33
a144 23
     * We got a mouse down in a window, so see if this is the activate click.
     * This click moves the window forward. We don't want the corresponding
     * mouse-up to be reported to the application or else it will mess up some
     * Tk scripts.
     */

    if (!(TkpIsWindowFloating(medPtr->whichWin))
	    && (medPtr->whichWin != medPtr->activeNonFloating
	    || !isFrontProcess)) {
	int frontWindowOnly = 1;
	int cmdDragGrow = ((medPtr->windowPart == inDrag ||
		medPtr->windowPart == inGrow) && medPtr->state & Mod1Mask);

	if (!cmdDragGrow) {
	    Tk_Window grabWin = GetGrabWindowForWindow(tkwin);

	    frontWindowOnly = !grabWin;
	    if (grabWin && grabWin != tkwin) {
		TkMacOSXSetEatButtonUp(true);
		BringWindowForward(TkMacOSXDrawableWindow(
			((TkWindow *) grabWin)->window), isFrontProcess,
			frontWindowOnly);
		return false;
a146 45

	/*
	 * Clicks in the titlebar widgets are handled without bringing the
	 * window forward.
	 */

	result = HandleWindowTitlebarMouseDown(medPtr, tkwin);
	if (result != -1) {
	    statusPtr->stopProcessing = 1;
	    return result;
	}

	/*
	 * Only windows with the kWindowNoActivatesAttribute can receive mouse
	 * events in the background.
	 */

	if (!(((TkWindow *)tkwin)->wmInfoPtr->attributes &
		kWindowNoActivatesAttribute)) {
	    /*
	     * Allow background window dragging & growing with Command down.
	     */

	    if (!cmdDragGrow) {
		TkMacOSXSetEatButtonUp(true);
		BringWindowForward(medPtr->whichWin, isFrontProcess,
			frontWindowOnly);
	    }

	    /*
	     * Allow dragging & growing of windows that were/are in the
	     * background.
	     */

	    if (!(medPtr->windowPart == inDrag ||
		    medPtr->windowPart == inGrow)) {
		return false;
	    }
	}
    } else {
	result = HandleWindowTitlebarMouseDown(medPtr, tkwin);
	if (result != -1) {
	    statusPtr->stopProcessing = 1;
	    return result;
	}
d148 1
d150 2
a151 14
    switch (medPtr->windowPart) {
    case inDrag: {
	WindowAttributes attributes;

	GetWindowAttributes(medPtr->whichWin, &attributes);
	if (!(attributes & kWindowAsyncDragAttribute)) {
	    TkMacOSXTrackingLoop(1);
	    DragWindow(medPtr->whichWin, where, NULL);
	    TkMacOSXTrackingLoop(0);
	    where2.h = where2.v = 0;
	    QDLocalToGlobalPoint(GetWindowPort(medPtr->whichWin), &where2);
	    return (EqualPt(where, where2)) ? false : true;
	}
	break;
d153 2
a154 14
    case inGrow:
	/*
	 * Generally the content region is the domain of Tk sub-windows.
	 * However, one exception is the grow region. A button down in this
	 * area will be handled by the window manager. Note: this means that
	 * Tk may not get button down events in this area!
	 */

	if (TkMacOSXGrowToplevel(medPtr->whichWin, where) == true) {
	    statusPtr->stopProcessing = 1;
	    return true;
	}
    case inContent:
	return GenerateButtonEvent(medPtr);
d156 2
a157 49
    return false;
}

/*
 *----------------------------------------------------------------------
 *
 * HandleWindowTitlebarMouseDown --
 *
 *	Handle clicks in window titlebar.
 *
 * Results:
 *	1 if event was handled, 0 if event was not handled, -1 if MouseDown
 *	was not in window titlebar.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

int
HandleWindowTitlebarMouseDown(
    MouseEventData *medPtr,
    Tk_Window tkwin)
{
    int result = INT_MAX;

    switch (medPtr->windowPart) {
    case inGoAway:
    case inCollapseBox:
    case inZoomIn:
    case inZoomOut:
    case inToolbarButton:
	if (!IsWindowActive(medPtr->whichWin)) {
	    WindowRef frontWindow = FrontNonFloatingWindow();
	    WindowModality frontWindowModality = kWindowModalityNone;

	    if (frontWindow && frontWindow != medPtr->whichWin) {
		ChkErr(GetWindowModality, frontWindow,
			&frontWindowModality, NULL);
	    }
	    if (frontWindowModality == kWindowModalityAppModal) {
		result = 0;
	    }
	}
	break;
    default:
	result = -1;
	break;
d159 2
a160 34
    
    if (result == INT_MAX) {
	result = 0;
	TkMacOSXTrackingLoop(1);
	switch (medPtr->windowPart) {
	case inGoAway:
	    if (TrackGoAway(medPtr->whichWin, medPtr->global) && tkwin) {
		TkGenWMDestroyEvent(tkwin);
		result = 1;
	    }
	    break;
	case inCollapseBox:
	    if (TrackBox(medPtr->whichWin, medPtr->global,
		    medPtr->windowPart) && tkwin) {
		TkpWmSetState((TkWindow *) tkwin, IconicState);
		result = 1;
	    }
	    break;
	case inZoomIn:
	case inZoomOut:
	    if (TrackBox(medPtr->whichWin, medPtr->global,
		    medPtr->windowPart)) {
		result = TkMacOSXZoomToplevel(medPtr->whichWin,
			medPtr->windowPart);
	    }
	    break;
	case inToolbarButton:
	    if (TrackBox(medPtr->whichWin, medPtr->global,
		    medPtr->windowPart)) {
		result = GenerateToolbarButtonEvent(medPtr);
	    }
	    break;
	}
	TkMacOSXTrackingLoop(0);
d162 2
a163 59

    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * GeneratePollingEvents --
 *
 *	This function polls the mouse position and generates X Motion, Enter &
 *	Leave events. The cursor is also updated at this time.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue. The cursor may
 *	be changed.
 *
 *----------------------------------------------------------------------
 */

static int
GeneratePollingEvents(
    MouseEventData *medPtr)
{
    Tk_Window tkwin, rootwin, grabWin;
    int local_x, local_y;
    TkDisplay *dispPtr;

    grabWin = TkMacOSXGetCapture();

    if ((!TkpIsWindowFloating(medPtr->whichWin)
	    && (medPtr->activeNonFloating != medPtr->whichWin))) {
	/*
	 * If the window for this event is not floating, and is not the active
	 * non-floating window, don't generate polling events. We don't send
	 * events to backgrounded windows. So either send it to the grabWin,
	 * or NULL if there is no grabWin.
	 */

	tkwin = grabWin;
    } else {
	/*
	 * First check whether the toplevel containing this mouse event is the
	 * grab window. If not, then send the event to the grab window.
	 * Otherwise, set tkWin to the subwindow which most closely contains
	 * the mouse event.
	 */

	dispPtr = TkGetDisplayList();
	rootwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
	if ((rootwin == NULL)
		|| ((grabWin != NULL) && (rootwin != grabWin))) {
	    tkwin = grabWin;
	} else {
	    tkwin = Tk_TopCoordsToWindow(rootwin, medPtr->local.h,
		    medPtr->local.v, &local_x, &local_y);
	}
d165 2
a166 68

    /*
     * The following call will generate the appropiate X events and adjust any
     * state that Tk must remember.
     */

    Tk_UpdatePointer(tkwin, medPtr->global.h, medPtr->global.v,
	    medPtr->state);
    return true;
}

/*
 *----------------------------------------------------------------------
 *
 * BringWindowForward --
 *
 *	Bring this background window to the front.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The window is brought forward.
 *
 *----------------------------------------------------------------------
 */

static void
BringWindowForward(
    WindowRef wRef,
    int isFrontProcess,
    int frontWindowOnly)
{
    if (wRef && !TkpIsWindowFloating(wRef) && IsValidWindowPtr(wRef)) {
	WindowRef frontWindow = FrontNonFloatingWindow();
	WindowModality frontWindowModality = kWindowModalityNone;
	
	if (frontWindow && frontWindow != wRef) {
	    ChkErr(GetWindowModality, frontWindow, &frontWindowModality, NULL);
	}
	if (frontWindowModality != kWindowModalityAppModal) {
	    Window window = TkMacOSXGetXWindow(wRef);

	    if (window != None) {
		TkDisplay *dispPtr = TkGetDisplayList();
		TkWindow *winPtr = (TkWindow *)
			Tk_IdToWindow(dispPtr->display, window);

		if (winPtr && winPtr->wmInfoPtr &&
			winPtr->wmInfoPtr->master != None) {
		    TkWindow *masterWinPtr = (TkWindow *)Tk_IdToWindow(
			    dispPtr->display, winPtr->wmInfoPtr->master);

		    if (masterWinPtr && masterWinPtr->window != None &&
			    TkMacOSXHostToplevelExists(masterWinPtr)) {
			WindowRef masterMacWin =
				TkMacOSXDrawableWindow(masterWinPtr->window);

			if (masterMacWin) {
			    BringToFront(masterMacWin);
			}
		    }
		}
	    }
	    SelectWindow(wRef);
	} else {
	    frontWindowOnly = 0;
	}
d168 2
a169 5
    if (!isFrontProcess) {
	ProcessSerialNumber ourPsn = {0, kCurrentProcess};

	ChkErr(SetFrontProcessWithOptions, &ourPsn,
		frontWindowOnly ? kSetFrontProcessFrontWindowOnly : 0);
a170 18
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXBringWindowForward --
 *
 *	Bring this window to the front in response to a mouse click. If a grab
 *	is in effect, bring the grab window to the front instead.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The window is brought forward.
 *
 *----------------------------------------------------------------------
 */
d172 34
a205 43
void
TkMacOSXBringWindowForward(
    WindowRef wRef)
{
    TkDisplay *dispPtr = TkGetDisplayList();
    Tk_Window tkwin =
	    Tk_IdToWindow(dispPtr->display, TkMacOSXGetXWindow(wRef));
    Tk_Window grabWin = GetGrabWindowForWindow(tkwin);

    if (grabWin && grabWin != tkwin) {
	wRef = TkMacOSXDrawableWindow(((TkWindow *) grabWin)->window);
    }
    TkMacOSXSetEatButtonUp(true);
    BringWindowForward(wRef, Tk_MacOSXIsAppInFront(), !grabWin);
}

/*
 *----------------------------------------------------------------------
 *
 * GetGrabWindowForWindow --
 *
 *	Get the grab window for the given window, if any.
 *
 * Results:
 *	Grab Tk_Window or None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
GetGrabWindowForWindow(
    Tk_Window tkwin) 
{
    Tk_Window grabWin = TkMacOSXGetCapture();

    if (!grabWin) {
	int grabState = TkGrabState((TkWindow *) tkwin);

	if (grabState != TK_GRAB_NONE && grabState != TK_GRAB_IN_TREE) {
	    grabWin = (Tk_Window) (((TkWindow *) tkwin)->dispPtr->grabWinPtr);
a207 28
    
    return grabWin;
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateMouseWheelEvent --
 *
 *	Generates a "MouseWheel" Tk event.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Places a mousewheel event on the event queue.
 *
 *----------------------------------------------------------------------
 */

static int
GenerateMouseWheelEvent(
    MouseEventData *medPtr)
{
    Tk_Window tkwin, rootwin;
    TkDisplay *dispPtr;
    TkWindow *winPtr;
    XEvent xEvent;
d209 1
a209 33
    dispPtr = TkGetDisplayList();
    rootwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
    if (rootwin == NULL) {
	tkwin = NULL;
    } else {
	tkwin = Tk_TopCoordsToWindow(rootwin, medPtr->local.h,
		medPtr->local.v, &xEvent.xbutton.x, &xEvent.xbutton.y);
    }

    /*
     * The following call will generate the appropiate X events and adjust any
     * state that Tk must remember.
     */

    if (!tkwin) {
	tkwin = TkMacOSXGetCapture();
    }
    if (!tkwin) {
	return false;
    }

    winPtr = (TkWindow *) tkwin;
    xEvent.type = MouseWheelEvent;
    xEvent.xkey.keycode = medPtr->delta;
    xEvent.xbutton.x_root = medPtr->global.h;
    xEvent.xbutton.y_root = medPtr->global.v;
    xEvent.xbutton.state = medPtr->state;
    xEvent.xany.serial = LastKnownRequestProcessed(winPtr->display);
    xEvent.xany.send_event = false;
    xEvent.xany.display = winPtr->display;
    xEvent.xany.window = Tk_WindowId(winPtr);
    Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
    return true;
d211 1
a211 14

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetEatButtonUp --
 *
 * Results:
 *	Return the flag indicating if we need to eat the next mouse up event.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */
d213 1
a213 26
int
TkMacOSXGetEatButtonUp(void)
{
    return gEatButtonUp;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXSetEatButtonUp --
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Sets the flag indicating if we need to eat the next mouse up event
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXSetEatButtonUp(
    int f)
{
    gEatButtonUp = f;
}
d266 2
a267 4
    if (!TkMacOSXGetEatButtonUp()) {
	buttonState = isFrontProcess ? GetCurrentEventButtonState() :
		GetCurrentButtonState();
    }
d361 1
a361 1
    int getLocal = (win_x_return && win_y_return);
d364 2
a365 19
	Point where, local;
	OSStatus err = noErr;
	int gotMouseLoc = 0;
	EventRef ev = GetCurrentEvent();

	if (ev && getLocal) {
	    err = ChkErr(GetEventParameter, ev, kEventParamWindowMouseLocation,
		    typeQDPoint, NULL, sizeof(Point), NULL, &local);
	    gotMouseLoc = (err == noErr);
	}
	if (getGlobal || !gotMouseLoc) {
	    if (ev) {
		err = ChkErr(GetEventParameter, ev, kEventParamMouseLocation,
			typeQDPoint, NULL, sizeof(Point), NULL, &where);
	    }
	    if (!ev || err != noErr) {
		GetGlobalMouse(&where);
	    }
	}
d367 5
a371 1
	    WindowRef whichWin;
d373 5
a377 20
	    if (ev) {
		err = ChkErr(GetEventParameter, ev, kEventParamWindowRef,
			typeWindowRef, NULL, sizeof(WindowRef), NULL,
			&whichWin);
	    }
	    if (!ev || err != noErr) {
		FindWindow(where, &whichWin);
	    }
	    if (gotMouseLoc) {
		if (whichWin) {
		    Rect widths;

		    ChkErr(GetWindowStructureWidths, whichWin, &widths);
		    local.h -= widths.left;
		    local.v -= widths.top;
		}
	    } else {
		local = where;
		if (whichWin) {
		    QDGlobalToLocalPoint(GetWindowPort(whichWin), &local);
d379 2
d384 2
a385 6
	    *root_x_return = where.h;
	    *root_y_return = where.v;
	}
	if (getLocal) {
	    *win_x_return = local.h;
	    *win_y_return = local.v;
d420 1
a420 1
    XQueryPointer(NULL, None, NULL, NULL, &global_x, &global_y,
a426 1
    med.activeNonFloating = ActiveNonFloatingWindow();
d457 2
a465 2
    FindWindow(med.global, &med.whichWin);
    med.activeNonFloating = ActiveNonFloatingWindow();
d467 13
a479 1
    QDGlobalToLocalPoint(GetWindowPort(med.whichWin), &med.local);
a538 56
 *----------------------------------------------------------------------
 *
 * GenerateToolbarButtonEvent --
 *
 *	Generates a "ToolbarButton" virtual event. This can be used to manage
 *	disappearing toolbars.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Places a virtual event on the event queue.
 *
 *----------------------------------------------------------------------
 */

static int
GenerateToolbarButtonEvent(
    MouseEventData *medPtr)
{
    Tk_Window rootwin, tkwin = NULL;
    TkDisplay *dispPtr;
    TkWindow *winPtr;
    XVirtualEvent event;

    dispPtr = TkGetDisplayList();
    rootwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
    if (rootwin) {
	tkwin = Tk_TopCoordsToWindow(rootwin,
		medPtr->local.h, medPtr->local.v, &event.x, &event.y);
    }
    if (!tkwin) {
	return true;
    }
    winPtr = (TkWindow *) tkwin;

    bzero(&event, sizeof(XVirtualEvent));
    event.type = VirtualEvent;
    event.serial = LastKnownRequestProcessed(winPtr->display);
    event.send_event = false;
    event.display = winPtr->display;
    event.event = winPtr->window;
    event.root = XRootWindow(winPtr->display, 0);
    event.subwindow = None;
    event.time = TkpGetMS();
    event.x_root = medPtr->global.h;
    event.y_root = medPtr->global.v;
    event.state = medPtr->state;
    event.same_screen = true;
    event.name = Tk_GetUid("ToolbarButton");

    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
    return true;
}

/*
@


1.34
log
@merge stable branch onto HEAD
@
text
@d4 2
a5 2
 *	This file implements functions that decode & handle mouse events
 *	on MacOS X.
d14 2
a15 2
 *	Computer, Inc. ("Apple") and associated with the software
 *	unless explicitly disclaimed in individual files.
d17 20
a36 24
 *
 *	Apple hereby grants permission to use, copy, modify,
 *	distribute, and license this software and its documentation
 *	for any purpose, provided that existing copyright notices are
 *	retained in all copies and that this notice is included
 *	verbatim in any distributions. No written agreement, license,
 *	or royalty fee is required for any of the authorized
 *	uses. Modifications to this software may be copyrighted by
 *	their authors and need not follow the licensing terms
 *	described here, provided that the new terms are clearly
 *	indicated on the first page of each file where they apply.
 *
 *
 *	IN NO EVENT SHALL APPLE, THE AUTHORS OR DISTRIBUTORS OF THE
 *	SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
 *	INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
 *	THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
 *	EVEN IF APPLE OR THE AUTHORS HAVE BEEN ADVISED OF THE
 *	POSSIBILITY OF SUCH DAMAGE.  APPLE, THE AUTHORS AND
 *	DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
 *	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 *	FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.	 THIS
 *	SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND APPLE,THE
 *	AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
d39 11
a49 13
 *	GOVERNMENT USE: If you are acquiring this software on behalf
 *	of the U.S. government, the Government shall have only
 *	"Restricted Rights" in the software and related documentation
 *	as defined in the Federal Acquisition Regulations (FARs) in
 *	Clause 52.227.19 (c) (2).  If you are acquiring the software
 *	on behalf of the Department of Defense, the software shall be
 *	classified as "Commercial Computer Software" and the
 *	Government shall have only "Restricted Rights" as defined in
 *	Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the
 *	foregoing, the authors grant the U.S. Government and others
 *	acting in its behalf permission to use and distribute the
 *	software in accordance with the terms specified in this
 *	license.
d51 1
a51 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.29.2.4 2007/12/13 06:28:48 dgp Exp $
d60 2
a61 2
    WindowRef	   whichWin;
    WindowRef	   activeNonFloating;
d63 5
a67 5
    unsigned int   state;
    long	   delta;
    Window	   window;
    Point	   global;
    Point	   local;
d74 1
a74 1
static int gEatButtonUp = 0;	   /* 1 if we need to eat the next up event */
d80 13
a92 13
static void BringWindowForward(WindowRef wRef, int isFrontProcess,
	int frontWindowOnly);
static int GeneratePollingEvents(MouseEventData * medPtr);
static int GenerateMouseWheelEvent(MouseEventData * medPtr);
static int GenerateButtonEvent(MouseEventData * medPtr);
static int GenerateToolbarButtonEvent(MouseEventData * medPtr);
static int HandleWindowTitlebarMouseDown(MouseEventData * medPtr, Tk_Window tkwin);
static unsigned int ButtonModifiers2State(UInt32 buttonState, UInt32 keyModifiers);
static Tk_Window GetGrabWindowForWindow(Tk_Window tkwin);

static int TkMacOSXGetEatButtonUp(void);
static void TkMacOSXSetEatButtonUp(int f);

d99 2
a100 2
 *	This routine processes the event in eventPtr, and
 *	generates the appropriate Tk events from it.
d112 3
a114 1
TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
d119 1
a119 1
    TkDisplay * dispPtr;
d121 1
a121 1
    MouseEventData mouseEventData, * medPtr = &mouseEventData;
d125 8
a132 9
	case kEventMouseDown:
	case kEventMouseUp:
	case kEventMouseMoved:
	case kEventMouseDragged:
	case kEventMouseWheelMoved:
	    break;
	default:
	    return false;
	    break;
d134 1
d136 1
a136 3
	    kEventParamMouseLocation,
	    typeQDPoint, NULL,
	    sizeof(where), NULL,
d141 3
a143 5
    err = ChkErr(GetEventParameter, eventPtr->eventRef,
	    kEventParamWindowRef,
	    typeWindowRef, NULL,
	    sizeof(WindowRef), NULL,
	    &medPtr->whichWin);
d146 2
a147 4
		kEventParamWindowPartCode,
		typeWindowPartCode, NULL,
		sizeof(WindowPartCode), NULL,
		&medPtr->windowPart);
d183 2
a184 4
	    kEventParamWindowMouseLocation,
	    typeQDPoint, NULL,
	    sizeof(Point), NULL,
	    &medPtr->local);
d188 1
d208 22
a229 13
	    case kEventMouseUp:
		/*
		 * The window manager only needs to know about mouse down
		 * events and sometimes we need to "eat" the mouse up.
		 * Otherwise, we just pass the event to Tk.
		 */
		if (TkMacOSXGetEatButtonUp()) {
		    TkMacOSXSetEatButtonUp(false);
		} else {
		    res = GenerateButtonEvent(medPtr);
		}
		break;
	    case kEventMouseWheelMoved:
d231 4
a234 13
			kEventParamMouseWheelDelta, typeLongInteger, NULL,
			sizeof(long), NULL, &medPtr->delta);
		if (err != noErr ) {
		    statusPtr->err = 1;
		} else {
		    EventMouseWheelAxis axis;
		    err = ChkErr(GetEventParameter, eventPtr->eventRef,
			    kEventParamMouseWheelAxis, typeMouseWheelAxis,
			    NULL, sizeof(EventMouseWheelAxis), NULL, &axis);
		    if (err == noErr && axis == kEventMouseWheelAxisX) {
			 medPtr->state |= ShiftMask;
		    }
		    res = GenerateMouseWheelEvent(medPtr);
d236 9
a244 7
		break;
	    case kEventMouseMoved:
	    case kEventMouseDragged:
		res = GeneratePollingEvents(medPtr);
		break;
	    default:
		Tcl_Panic("Unknown mouse event !");
d247 1
a247 1
		statusPtr->stopProcessing = 1;
d251 1
d253 31
a283 1
    if (medPtr->whichWin) {
d285 2
a286 5
	 * We got a mouse down in a window
	 * See if this is the activate click
	 * This click moves the window forward. We don't want
	 * the corresponding mouse-up to be reported to the application
	 * or else it will mess up some Tk scripts.
d289 16
a304 6
	if (!(TkpIsWindowFloating(medPtr->whichWin))
		&& (medPtr->whichWin != medPtr->activeNonFloating
		|| !isFrontProcess)) {
	    int frontWindowOnly = 1;
	    int cmdDragGrow = ((medPtr->windowPart == inDrag ||
		    medPtr->windowPart == inGrow) && medPtr->state & Mod1Mask);
d307 3
a309 10
		Tk_Window grabWin = GetGrabWindowForWindow(tkwin);

		frontWindowOnly = !grabWin;
		if (grabWin && grabWin != tkwin) {
		    TkMacOSXSetEatButtonUp(true);
		    BringWindowForward(TkMacOSXDrawableWindow(
			    ((TkWindow*)grabWin)->window), isFrontProcess,
			    frontWindowOnly);
		    return false;
		}
d313 2
a314 2
	     * Clicks in the titlebar widgets are handled without bringing the
	     * window forward.
d316 4
a319 33
	    if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) {
		statusPtr->stopProcessing = 1;
		return result;
	    } else {
		/*
		 * Only windows with the kWindowNoActivatesAttribute can
		 * receive mouse events in the background.
		 */
		if (!(((TkWindow *)tkwin)->wmInfoPtr->attributes &
			kWindowNoActivatesAttribute)) {
		    /*
		     * Allow background window dragging & growing with Command
		     * down.
		     */
		    if (!cmdDragGrow) {
			TkMacOSXSetEatButtonUp(true);
			BringWindowForward(medPtr->whichWin, isFrontProcess,
				frontWindowOnly);
		    }
		    /*
		     * Allow dragging & growing of windows that were/are in the
		     * background.
		     */
		    if (!(medPtr->windowPart == inDrag ||
			    medPtr->windowPart == inGrow)) {
			return false;
		    }
		}
	    }
	} else {
	    if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) {
		statusPtr->stopProcessing = 1;
		return result;
d322 30
a351 3
	switch (medPtr->windowPart) {
	    case inDrag: {
		WindowAttributes attributes;
d353 3
a355 36
		GetWindowAttributes(medPtr->whichWin, &attributes);
		if (!(attributes & kWindowAsyncDragAttribute)) {
		    TkMacOSXTrackingLoop(1);
		    DragWindow(medPtr->whichWin, where, NULL);
		    TkMacOSXTrackingLoop(0);
		    where2.h = where2.v = 0;
		    QDLocalToGlobalPoint(GetWindowPort(medPtr->whichWin),
			    &where2);
		    if (EqualPt(where, where2)) {
			return false;
		    }
		    return true;
		}
		break;
	    }
	    case inGrow:
		/*
		 * Generally the content region is the domain of Tk
		 * sub-windows. However, one exception is the grow
		 * region. A button down in this area will be handled
		 * by the window manager. Note: this means that Tk
		 * may not get button down events in this area!
		 */
		if (TkMacOSXGrowToplevel(medPtr->whichWin, where) == true) {
		    statusPtr->stopProcessing = 1;
		    return true;
		} else {
		    return GenerateButtonEvent(medPtr);
		}
		break;
	    case inContent:
		return GenerateButtonEvent(medPtr);
		break;
	    default:
		return false;
		break;
d357 2
d371 2
a372 2
 *	1 if event was handled, 0 if event was not handled,
 *	-1 if MouseDown was not in window titlebar.
d381 3
a383 1
HandleWindowTitlebarMouseDown(MouseEventData * medPtr, Tk_Window tkwin)
d388 27
d416 5
d422 6
d430 6
d437 3
a439 11
	    if (!IsWindowActive(medPtr->whichWin)) {
		WindowRef frontWindow = FrontNonFloatingWindow();
		WindowModality frontWindowModality = kWindowModalityNone;

		if (frontWindow && frontWindow != medPtr->whichWin) {
		    ChkErr(GetWindowModality, frontWindow,
			    &frontWindowModality, NULL);
		}
		if (frontWindowModality == kWindowModalityAppModal) {
		    result  = 0;
		}
a441 36
	default:
	    result = -1;
	    break;
    }
    
    if (result == INT_MAX) {
	result = 0;
	TkMacOSXTrackingLoop(1);
	switch (medPtr->windowPart) {
	    case inGoAway:
		if (TrackGoAway(medPtr->whichWin, medPtr->global) && tkwin) {
		    TkGenWMDestroyEvent(tkwin);
		    result = 1;
		}
		break;
	    case inCollapseBox:
		if (TrackBox(medPtr->whichWin, medPtr->global,
			medPtr->windowPart) && tkwin) {
		    TkpWmSetState((TkWindow *)tkwin, IconicState);
		    result = 1;
		}
		break;
	    case inZoomIn:
	    case inZoomOut:
		if (TrackBox(medPtr->whichWin, medPtr->global,
			medPtr->windowPart)) {
		    result = TkMacOSXZoomToplevel(medPtr->whichWin,
			    medPtr->windowPart);
		}
		break;
	    case inToolbarButton:
		if (TrackBox(medPtr->whichWin, medPtr->global,
			medPtr->windowPart)) {
		    result = GenerateToolbarButtonEvent(medPtr);
		}
		break;
d454 2
a455 3
 *	This function polls the mouse position and generates X Motion,
 *	Enter & Leave events. The cursor is also updated at this
 *	time.
d461 2
a462 2
 *	Additional events may be place on the Tk event queue.
 *	The cursor may be changed.
d468 2
a469 1
GeneratePollingEvents(MouseEventData * medPtr)
a474 1

d480 4
a483 4
	 * If the window for this event is not floating, and is not the
	 * active non-floating window, don't generate polling events.
	 * We don't send events to backgrounded windows. So either send
	 * it to the grabWin, or NULL if there is no grabWin.
d489 4
a492 4
	 * First check whether the toplevel containing this mouse
	 * event is the grab window. If not, then send the event
	 * to the grab window. Otherwise, set tkWin to the subwindow
	 * which most closely contains the mouse event.
d501 2
a502 3
	    tkwin = Tk_TopCoordsToWindow(rootwin,
		    medPtr->local.h, medPtr->local.v,
		    &local_x, &local_y);
d507 2
a508 2
     * The following call will generate the appropiate X events and
     * adjust any state that Tk must remember.
a512 1

d550 2
a551 2
		TkWindow * winPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display,
			window);
d577 2
a578 2
	ChkErr(SetFrontProcessWithOptions, &ourPsn, frontWindowOnly ?
	    kSetFrontProcessFrontWindowOnly : 0);
d587 2
a588 2
 *	Bring this window to the front in response to a mouse click. If
 *	a grab is in effect, bring the grab window to the front instead.
d604 2
a605 1
    Tk_Window tkwin = Tk_IdToWindow(dispPtr->display,TkMacOSXGetXWindow(wRef));
d609 1
a609 1
	wRef = TkMacOSXDrawableWindow(((TkWindow*)grabWin)->window);
d638 1
a638 1
	int grabState = TkGrabState((TkWindow*)tkwin);
d641 1
a641 1
	    grabWin = (Tk_Window) (((TkWindow*)tkwin)->dispPtr->grabWinPtr);
d665 2
a666 1
GenerateMouseWheelEvent(MouseEventData * medPtr)
d670 1
a670 1
    TkWindow  *winPtr;
d678 2
a679 3
	tkwin = Tk_TopCoordsToWindow(rootwin,
		medPtr->local.h, medPtr->local.v,
		&xEvent.xbutton.x, &xEvent.xbutton.y);
d683 2
a684 2
     * The following call will generate the appropiate X events and
     * adjust any state that Tk must remember.
d693 1
a704 1

d714 1
a714 2
 *	Returns the flag indicating if we need to eat the
 *	next mouse up event
d721 1
d737 1
a737 2
 *	Sets the flag indicating if we need to eat the
 *	next mouse up event
d741 1
d743 2
a744 1
TkMacOSXSetEatButtonUp(int f)
d774 1
a774 1
    return (EventModifiers)(keyModifiers & USHRT_MAX);
d785 2
a786 2
 *	A bitwise inclusive OR of a subset of the following:
 *	Button1Mask, ShiftMask, LockMask, ControlMask, Mod*Mask.
d828 3
a830 1
ButtonModifiers2State(UInt32 buttonState, UInt32 keyModifiers)
d834 4
a837 1
    /* Tk supports at most 5 buttons */
d871 2
a872 2
 *	implementation of this function. It only computes the root
 *	coordinates and the current mask.
d875 2
a876 2
 *	Sets root_x_return, root_y_return, and mask_return. Returns
 *	true on success.
d886 1
a886 1
    Display* display,
d888 7
a894 7
    Window* root_return,
    Window* child_return,
    int* root_x_return,
    int* root_y_return,
    int* win_x_return,
    int* win_y_return,
    unsigned int* mask_return)
d921 1
d965 2
a966 2
 *	This procedure generates an X button event for the current
 *	pointer state as reported by XQueryPointer().
d972 2
a973 2
 *	Additional events may be place on the Tk event queue.
 *	Grab state may also change.
d980 1
a980 1
    Window window)	  /* X Window containing button event. */
d1003 3
a1005 3
 *	Given a global x & y position and the button key status this
 *	procedure generates the appropiate X button event. It also
 *	handles the state changes needed to implement implicit grabs.
d1008 1
a1008 1
 *	True if event(s) are generated - false otherwise.
d1011 2
a1012 2
 *	Additional events may be place on the Tk event queue.
 *	Grab state may also change.
d1019 4
a1022 4
    int x,		  /* X location of mouse */
    int y,		  /* Y location of mouse */
    Window window,	  /* X Window containing button event. */
    unsigned int state)	  /* Button Key state suitable for X event */
d1044 2
a1045 2
 *	Generate an X button event from a MouseEventData structure.
 *	Handles the state changes needed to implement implicit grabs.
d1051 2
a1052 2
 *	Additional events may be place on the Tk event queue.
 *	Grab state may also change.
d1058 2
a1059 1
GenerateButtonEvent(MouseEventData * medPtr)
d1067 4
a1070 4
     * ButtonDown events will always occur in the front
     * window. ButtonUp events, however, may occur anywhere
     * on the screen. ButtonUp events should only be sent
     * to Tk if in the front window or during an implicit grab.
d1072 1
a1089 1

d1098 2
a1099 2
 *	Generates a "ToolbarButton" virtual event.
 *	This can be used to manage disappearing toolbars.
d1111 2
a1112 1
GenerateToolbarButtonEvent(MouseEventData * medPtr)
d1116 1
a1116 1
    TkWindow  *winPtr;
d1128 1
a1128 1
    winPtr = (TkWindow *)tkwin;
d1148 9
@


1.33
log
@	* macosx/tkMacOSXWm.c (ApplyMasterOverrideChanges): Revert 2007-10-26
	change to window class of transient toplevels that are not also
	overrideredirect. [Bug 1845899]

	* macosx/tkMacOSXWm.c (ApplyMasterOverrideChanges): Implement more
	* macosx/tkMacOSXMouseEvent.c (BringWindowForward): X11-like transient
	* macosx/tkMacOSXSubwindows.c (XDestroyWindow):     behaviour by adding
	transient windows to a window group owned by the master window, this
	ensures transients always remain in front of and are collapsed with the
	master; bring master to front when selecting transient windows; restore
	default window group of transients if master destroyed. [Bug 1845899]
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.32 2007/07/09 08:31:54 das Exp $
@


1.32
log
@	* macosx/tkMacOSXWindowEvent.c (Tk_MacOSXIsAppInFront):	use process mgr
	* macosx/tkMacOSXMouseEvent.c:				to determine if
	app is in front instead of relying on activate/deactivate events (which
	may arrive after this info is needed, e.g. during window drag/click
	activation); replace other process mgr use to get this info with calls
	to Tk_MacOSXIsAppInFront().

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): correct
	window click activation, titlebar click handling and background window
	dragging/growing in the presence of grabs or window-/app-modal windows;
	fix window click activation bringing all other app windows to front.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.31 2007/06/29 03:20:02 das Exp $
d558 23
@


1.31
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
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.30 2007/06/06 09:55:52 das Exp $
d86 2
a87 1
static void BringWindowForward(WindowRef wRef, Boolean isFrontProcess);
d94 1
d126 1
a126 2
    ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
    Boolean isFrontProcess = true;
d167 2
a168 1
	if (IsWindowPathSelectEvent(medPtr->whichWin, eventPtr->eventRef)) {
d183 1
a183 4
    err = ChkErr(GetFrontProcess, &frontPsn);
    if (err == noErr) {
	ChkErr(SameProcess, &frontPsn, &ourPsn, &isFrontProcess);
    }
d273 9
a281 5
	    Tk_Window grabWin = TkMacOSXGetCapture();
	    if (!grabWin) {
		int grabState = TkGrabState((TkWindow*)tkwin);
		if (grabState != TK_GRAB_NONE && grabState != TK_GRAB_IN_TREE) {
		    /* Now we want to set the focus to the local grabWin */
a282 1
		    grabWin = (Tk_Window) (((TkWindow*)tkwin)->dispPtr->grabWinPtr);
d284 2
a285 2
			    ((TkWindow*)grabWin)->window), isFrontProcess);
		    statusPtr->stopProcessing = 1;
a288 11
	    if (grabWin && grabWin != tkwin) {
		TkWindow * tkw, * grb;
		tkw = (TkWindow *)tkwin;
		grb = (TkWindow *)grabWin;
		/* Now we want to set the focus to the global grabWin */
		TkMacOSXSetEatButtonUp(true);
		BringWindowForward(TkMacOSXDrawableWindow(
			((TkWindow*)grabWin)->window), isFrontProcess);
		statusPtr->stopProcessing = 1;
		return false;
	    }
d295 1
d308 1
a308 3
		    if (!((medPtr->windowPart == inDrag ||
			    medPtr->windowPart == inGrow) &&
			    medPtr->state & Mod1Mask)) {
d310 2
a311 1
			BringWindowForward(medPtr->whichWin, isFrontProcess);
d325 1
d394 1
a394 1
    int result = 0;
a395 1
    TkMacOSXTrackingLoop(1);
a397 7
	    if (TrackGoAway(medPtr->whichWin, medPtr->global)) {
		if (tkwin) {
		    TkGenWMDestroyEvent(tkwin);
		    result = 1;
		}
	    }
	    break;
a398 7
	    if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
		if (tkwin) {
		    TkpWmSetState((TkWindow *)tkwin, IconicState);
		    result = 1;
		}
	    }
	    break;
a400 4
	    if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
		result = TkMacOSXZoomToplevel(medPtr->whichWin, medPtr->windowPart);
	    }
	    break;
d402 11
a412 2
	    if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
		result = GenerateToolbarButtonEvent(medPtr);
d419 36
a454 1
    TkMacOSXTrackingLoop(0);
d547 2
a548 1
    Boolean isFrontProcess)
d550 13
d566 2
a567 7
	ChkErr(SetFrontProcess, &ourPsn);
    }

    if (!TkpIsWindowFloating(wRef)) {
	if (IsValidWindowPtr(wRef)) {
	    SelectWindow(wRef);
	}
d576 2
a577 2
 *	Bring this background window to the front (wrapper around
 *	BringWindowForward()).
d592 35
a626 3
    OSStatus err;
    ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
    Boolean isFrontProcess = true;
d628 3
a630 3
    err = ChkErr(GetFrontProcess, &frontPsn);
    if (err == noErr) {
	ChkErr(SameProcess, &frontPsn, &ourPsn, &isFrontProcess);
d632 2
a633 1
    BringWindowForward(wRef, isFrontProcess);
d756 1
a756 5
    Boolean isFrontProcess = false;

    if (GetCurrentEvent()) {
	ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
	OSStatus err = ChkErr(GetFrontProcess, &frontPsn);
a757 4
	if (err == noErr) {
	    ChkErr(SameProcess, &frontPsn, &ourPsn, &isFrontProcess);
	}
    }
d785 1
a785 10
    Boolean isFrontProcess = false;

    if (GetCurrentEvent()) {
	ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
	OSStatus err = ChkErr(GetFrontProcess, &frontPsn);

	if (err == noErr) {
	    ChkErr(SameProcess, &frontPsn, &ourPsn, &isFrontProcess);
	}
    }
@


1.30
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
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.29 2007/05/09 12:55:15 das Exp $
d60 1
a60 1
#include "tkMacOSXInt.h"
d281 2
a282 3
		    BringWindowForward(GetWindowFromPort(
			    TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)),
			    isFrontProcess);
d293 2
a294 3
		BringWindowForward(GetWindowFromPort(
			TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)),
			isFrontProcess);
@


1.29
log
@	* macosx/tkMacOSXWindowEvent.c:	ensure window is brought to the front
	* macosx/tkMacOSXMouseEvent.c:	at the start of a window drag (except
	* macosx/tkMacOSXInt.h:		when cmd key is down); formatting and
					whitespace fixes.

	* macosx/tkMacOSXDialog.c (Tk_GetSaveFileObjCmd): add -filetypes option
	processing (fixes fileDialog-0.1, fileDialog-0.2 failures).

	* macosx/tkMacOSXEmbed.c (TkpMakeWindow, TkpUseWindow): fix sending of
	Visibility event for embedded windows (fixes frame-3.9 hang).

	* macosx/tkMacOSXScrlbr.c (ScrollbarBindProc):		fix testsuite
	* macosx/tkMacOSXSubwindows.c (TkMacOSXUpdateClipRgn):	crashes by
	adding sanity checks.

	* macosx/Wish.xcodeproj/project.pbxproj: add 'DebugUnthreaded' &
	* macosx/Wish.xcodeproj/default.pbxuser: 'DebugLeaks' targets and env
	var settings needed to run the 'leaks' tool.

	* macosx/tkMacOSXButton.c: fix debug msg typo.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.28 2007/04/23 21:24:33 das Exp $
d603 3
a605 2
    if ((!TkpIsWindowFloating(medPtr->whichWin)
	    && (medPtr->activeNonFloating != medPtr->whichWin))) {
d608 3
a610 9
	dispPtr = TkGetDisplayList();
	rootwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
	if (rootwin == NULL) {
	    tkwin = NULL;
	} else {
	    tkwin = Tk_TopCoordsToWindow(rootwin,
		    medPtr->local.h, medPtr->local.v,
		    &xEvent.xbutton.x, &xEvent.xbutton.y);
	}
@


1.29.2.1
log
@merge updates from HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.29 2007/05/09 12:55:15 das Exp $
d603 2
a604 3
    dispPtr = TkGetDisplayList();
    rootwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
    if (rootwin == NULL) {
d607 9
a615 3
	tkwin = Tk_TopCoordsToWindow(rootwin,
		medPtr->local.h, medPtr->local.v,
		&xEvent.xbutton.x, &xEvent.xbutton.y);
@


1.29.2.2
log
@merge updates from HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id$
d60 1
a60 1
#include "tkMacOSXPrivate.h"
d281 3
a283 2
		    BringWindowForward(TkMacOSXDrawableWindow(
			    ((TkWindow*)grabWin)->window), isFrontProcess);
d294 3
a296 2
		BringWindowForward(TkMacOSXDrawableWindow(
			((TkWindow*)grabWin)->window), isFrontProcess);
@


1.29.2.3
log
@merge updates from HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.29.2.2 2007/07/01 17:31:37 dgp Exp $
d86 1
a86 2
static void BringWindowForward(WindowRef wRef, int isFrontProcess,
	int frontWindowOnly);
a92 1
static Tk_Window GetGrabWindowForWindow(Tk_Window tkwin);
d124 2
a125 1
    int isFrontProcess;
d166 1
a166 2
	if (IsWindowActive(medPtr->whichWin) && IsWindowPathSelectEvent(
		medPtr->whichWin, eventPtr->eventRef)) {
d181 4
a184 1
    isFrontProcess = Tk_MacOSXIsAppInFront();
d274 5
a278 9
	    int frontWindowOnly = 1;
	    int cmdDragGrow = ((medPtr->windowPart == inDrag ||
		    medPtr->windowPart == inGrow) && medPtr->state & Mod1Mask);

	    if (!cmdDragGrow) {
		Tk_Window grabWin = GetGrabWindowForWindow(tkwin);

		frontWindowOnly = !grabWin;
		if (grabWin && grabWin != tkwin) {
d280 1
d282 2
a283 2
			    ((TkWindow*)grabWin)->window), isFrontProcess,
			    frontWindowOnly);
d287 11
a303 1
		statusPtr->stopProcessing = 1;
d316 3
a318 1
		    if (!cmdDragGrow) {
d320 1
a320 2
			BringWindowForward(medPtr->whichWin, isFrontProcess,
				frontWindowOnly);
a333 1
		statusPtr->stopProcessing = 1;
d402 1
a402 1
    int result = INT_MAX;
d404 1
d407 7
d415 7
d424 4
d429 2
a430 11
	    if (!IsWindowActive(medPtr->whichWin)) {
		WindowRef frontWindow = FrontNonFloatingWindow();
		WindowModality frontWindowModality = kWindowModalityNone;

		if (frontWindow && frontWindow != medPtr->whichWin) {
		    ChkErr(GetWindowModality, frontWindow,
			    &frontWindowModality, NULL);
		}
		if (frontWindowModality == kWindowModalityAppModal) {
		    result  = 0;
		}
d437 1
a437 36
    
    if (result == INT_MAX) {
	result = 0;
	TkMacOSXTrackingLoop(1);
	switch (medPtr->windowPart) {
	    case inGoAway:
		if (TrackGoAway(medPtr->whichWin, medPtr->global) && tkwin) {
		    TkGenWMDestroyEvent(tkwin);
		    result = 1;
		}
		break;
	    case inCollapseBox:
		if (TrackBox(medPtr->whichWin, medPtr->global,
			medPtr->windowPart) && tkwin) {
		    TkpWmSetState((TkWindow *)tkwin, IconicState);
		    result = 1;
		}
		break;
	    case inZoomIn:
	    case inZoomOut:
		if (TrackBox(medPtr->whichWin, medPtr->global,
			medPtr->windowPart)) {
		    result = TkMacOSXZoomToplevel(medPtr->whichWin,
			    medPtr->windowPart);
		}
		break;
	    case inToolbarButton:
		if (TrackBox(medPtr->whichWin, medPtr->global,
			medPtr->windowPart)) {
		    result = GenerateToolbarButtonEvent(medPtr);
		}
		break;
	}
	TkMacOSXTrackingLoop(0);
    }

d530 1
a530 2
    int isFrontProcess,
    int frontWindowOnly)
a531 13
    if (wRef && !TkpIsWindowFloating(wRef) && IsValidWindowPtr(wRef)) {
	WindowRef frontWindow = FrontNonFloatingWindow();
	WindowModality frontWindowModality = kWindowModalityNone;
	
	if (frontWindow && frontWindow != wRef) {
	    ChkErr(GetWindowModality, frontWindow, &frontWindowModality, NULL);
	}
	if (frontWindowModality != kWindowModalityAppModal) {
	    SelectWindow(wRef);
	} else {
	    frontWindowOnly = 0;
	}
    }
d535 7
a541 2
	ChkErr(SetFrontProcessWithOptions, &ourPsn, frontWindowOnly ?
	    kSetFrontProcessFrontWindowOnly : 0);
d550 2
a551 2
 *	Bring this window to the front in response to a mouse click. If
 *	a grab is in effect, bring the grab window to the front instead.
d566 3
a568 3
    TkDisplay *dispPtr = TkGetDisplayList();
    Tk_Window tkwin = Tk_IdToWindow(dispPtr->display,TkMacOSXGetXWindow(wRef));
    Tk_Window grabWin = GetGrabWindowForWindow(tkwin);
d570 3
a572 2
    if (grabWin && grabWin != tkwin) {
	wRef = TkMacOSXDrawableWindow(((TkWindow*)grabWin)->window);
d574 1
a574 35
    TkMacOSXSetEatButtonUp(true);
    BringWindowForward(wRef, Tk_MacOSXIsAppInFront(), !grabWin);
}

/*
 *----------------------------------------------------------------------
 *
 * GetGrabWindowForWindow --
 *
 *	Get the grab window for the given window, if any.
 *
 * Results:
 *	Grab Tk_Window or None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
GetGrabWindowForWindow(
    Tk_Window tkwin) 
{
    Tk_Window grabWin = TkMacOSXGetCapture();

    if (!grabWin) {
	int grabState = TkGrabState((TkWindow*)tkwin);

	if (grabState != TK_GRAB_NONE && grabState != TK_GRAB_IN_TREE) {
	    grabWin = (Tk_Window) (((TkWindow*)tkwin)->dispPtr->grabWinPtr);
	}
    }
    
    return grabWin;
d697 5
a701 1
    int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront());
d703 4
d734 10
a743 1
    int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront());
@


1.29.2.4
log
@merge updates from HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.29.2.3 2007/07/10 21:54:28 dgp Exp $
a557 23
	    Window window = TkMacOSXGetXWindow(wRef);

	    if (window != None) {
		TkDisplay *dispPtr = TkGetDisplayList();
		TkWindow * winPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display,
			window);

		if (winPtr && winPtr->wmInfoPtr &&
			winPtr->wmInfoPtr->master != None) {
		    TkWindow *masterWinPtr = (TkWindow *)Tk_IdToWindow(
			    dispPtr->display, winPtr->wmInfoPtr->master);

		    if (masterWinPtr && masterWinPtr->window != None &&
			    TkMacOSXHostToplevelExists(masterWinPtr)) {
			WindowRef masterMacWin =
				TkMacOSXDrawableWindow(masterWinPtr->window);

			if (masterMacWin) {
			    BringToFront(masterMacWin);
			}
		    }
		}
	    }
@


1.28
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
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.27 2007/04/21 19:06:38 hobbs Exp $
d307 17
a323 1
	    } else
d325 2
a326 2
		     * Only windows with the kWindowNoActivatesAttribute can
		     * receive mouse events in the background.
d328 4
a331 18
		    if (!(((TkWindow *)tkwin)->wmInfoPtr->attributes &
			    kWindowNoActivatesAttribute)) {
		/*
		 * Allow background window dragging & growing with Command down
		 */
		if (!((medPtr->windowPart == inDrag ||
			medPtr->windowPart == inGrow) &&
			medPtr->state & Mod1Mask)) {
		    TkMacOSXSetEatButtonUp(true);
		    BringWindowForward(medPtr->whichWin, isFrontProcess);
		}
		/*
		 * Allow dragging & growing of windows that were/are in the
		 * background.
		 */
		if (!(medPtr->windowPart == inDrag ||
			medPtr->windowPart == inGrow)) {
		    return false;
d518 1
a518 2
 *	Bring this background window to the front. We also set state
 *	so Tk thinks the button is currently up.
d550 32
@


1.27
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
@d8 1
a8 1
 * Copyright (c) 2005-2006 Daniel A. Steffen <das@@users.sourceforge.net>
d13 43
a55 43
 *      The following terms apply to all files originating from Apple
 *      Computer, Inc. ("Apple") and associated with the software
 *      unless explicitly disclaimed in individual files.
 *
 *
 *      Apple hereby grants permission to use, copy, modify,
 *      distribute, and license this software and its documentation
 *      for any purpose, provided that existing copyright notices are
 *      retained in all copies and that this notice is included
 *      verbatim in any distributions. No written agreement, license,
 *      or royalty fee is required for any of the authorized
 *      uses. Modifications to this software may be copyrighted by
 *      their authors and need not follow the licensing terms
 *      described here, provided that the new terms are clearly
 *      indicated on the first page of each file where they apply.
 *
 *
 *      IN NO EVENT SHALL APPLE, THE AUTHORS OR DISTRIBUTORS OF THE
 *      SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
 *      INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
 *      THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
 *      EVEN IF APPLE OR THE AUTHORS HAVE BEEN ADVISED OF THE
 *      POSSIBILITY OF SUCH DAMAGE.  APPLE, THE AUTHORS AND
 *      DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
 *      BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 *      FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS
 *      SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND APPLE,THE
 *      AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
 *      MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 *      GOVERNMENT USE: If you are acquiring this software on behalf
 *      of the U.S. government, the Government shall have only
 *      "Restricted Rights" in the software and related documentation
 *      as defined in the Federal Acquisition Regulations (FARs) in
 *      Clause 52.227.19 (c) (2).  If you are acquiring the software
 *      on behalf of the Department of Defense, the software shall be
 *      classified as "Commercial Computer Software" and the
 *      Government shall have only "Restricted Rights" as defined in
 *      Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the
 *      foregoing, the authors grant the U.S. Government and others
 *      acting in its behalf permission to use and distribute the
 *      software in accordance with the terms specified in this
 *      license.
d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.25 2006/09/10 17:06:32 das Exp $
a64 6
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
    /* Define constants only available on Mac OS X 10.3 or later */
    #define kEventParamWindowPartCode 'wpar'
    #define typeWindowPartCode        'wpar'
#endif

a68 2
    Point	   global;
    Point	   local;
d72 2
d94 1
a94 1
static int TkMacOSXGetEatButtonUp();
d97 1
d103 2
a104 2
 *	  This routine processes the event in eventPtr, and
 *	  generates the appropriate Tk events from it.
d107 1
a107 1
 *	  True if event(s) are generated - false otherwise.
d110 1
a110 1
 *	  Additional events may be place on the Tk event queue.
d118 5
a122 5
    Tk_Window	   tkwin;
    Point	   where, where2;
    int		   xOffset, yOffset, result;
    TkDisplay *	   dispPtr;
    OSStatus	   status;
d125 1
a125 1
    Boolean	   isFrontProcess = true;
d128 1
a129 1
	case kEventMouseDown:
d138 1
a138 1
    status = GetEventParameter(eventPtr->eventRef, 
d140 1
a140 1
	    typeQDPoint, NULL, 
d143 1
a143 1
    if (status != noErr) {
d146 1
a146 1
    status = GetEventParameter(eventPtr->eventRef, 
d148 1
a148 1
	    typeWindowRef, NULL, 
d151 2
a152 2
    if (status == noErr) {
	status = GetEventParameter(eventPtr->eventRef, 
d154 1
a154 1
		typeWindowPartCode, NULL, 
d158 1
a158 1
    if (status != noErr) {
d167 1
a167 1
	    status = WindowPathSelect(medPtr->whichWin, NULL, NULL);
d171 4
a174 2
	    status = TrackWindowProxyDrag(medPtr->whichWin, where);
	    if (status == errUserWantsToDragWindow) {
d181 3
a183 3
    status = GetFrontProcess(&frontPsn);
    if (status == noErr) {
	SameProcess(&frontPsn, &ourPsn, &isFrontProcess);
d193 1
a193 1
    status = GetEventParameter(eventPtr->eventRef, 
d195 1
a195 1
	    typeQDPoint, NULL, 
d198 1
a198 1
    if (status == noErr) {
d203 1
a203 1
	    medPtr->local.v -=	widths.top;	   
d209 1
a209 1
	            &medPtr->local);
a212 39

    /*
     * The window manager only needs to know about mouse down events
     * and sometimes we need to "eat" the mouse up.  Otherwise, we
     * just pass the event to Tk.

     */
    if (eventPtr->eKind == kEventMouseUp) {
	if (TkMacOSXGetEatButtonUp()) {
	    TkMacOSXSetEatButtonUp(false);
	    return false;
	}
	return GenerateButtonEvent(medPtr);
    }
    if (eventPtr->eKind == kEventMouseDown) {
	TkMacOSXSetEatButtonUp(false);
    }
    if (eventPtr->eKind == kEventMouseWheelMoved) {
	status = GetEventParameter(eventPtr->eventRef,
		kEventParamMouseWheelDelta, typeLongInteger, NULL,
		sizeof(long), NULL, &medPtr->delta);
	if (status != noErr ) {
#ifdef TK_MAC_DEBUG
	    fprintf (stderr,
		"Failed to retrieve mouse wheel delta, %d\n", (int) status);
#endif
	    statusPtr->err = 1;
	    return false;
	} else {
	    EventMouseWheelAxis axis;
	    status = GetEventParameter(eventPtr->eventRef,
		    kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL,
		    sizeof(EventMouseWheelAxis), NULL, &axis);
	    if (status == noErr && axis == kEventMouseWheelAxisX) {
		 medPtr->state |= ShiftMask;
	    }
	}
    }

d217 1
a217 3
	/*
	 * MouseMoved, MouseDragged or MouseWheelMoved 
	 */
d219 39
a257 8
	if (eventPtr->eKind == kEventMouseWheelMoved) {
	    int res = GenerateMouseWheelEvent(medPtr);
	    if (res) {
		 statusPtr->stopProcessing = 1;
	    }
	    return res;
	} else {
	    return GeneratePollingEvents(medPtr);
d259 1
d261 1
a261 1

d266 1
a266 1
	 * This click moves the window forward.	 We don't want
d275 1
a275 1
	    if ((grabWin == NULL)) {
d282 2
a283 2
		            TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)),
		            isFrontProcess);
d288 1
a288 1
	    if ((grabWin != NULL) && (grabWin != tkwin)) {
d305 3
a307 3
            if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) {
                return result;
            } else
d317 1
a317 1
                if (!((medPtr->windowPart == inDrag ||
d322 6
a327 6
                }
                /*
                 * Allow dragging & growing of windows that were/are in the
                 * background.
                 */
                if (!(medPtr->windowPart == inDrag ||
d330 2
a331 2
                }
            }
d338 15
a352 7
	    case inDrag:
		SetPort(GetWindowPort(medPtr->whichWin));
		DragWindow(medPtr->whichWin, where, NULL);
		where2.h = where2.v = 0;
		LocalToGlobal(&where2);
		if (EqualPt(where, where2)) {
		    return false;
a353 6
		TkMacOSXWindowOffset(medPtr->whichWin, &xOffset, &yOffset);
		where2.h -= xOffset;
		where2.v -= yOffset;
		TkGenWMConfigureEvent(tkwin, where2.h, where2.v,
			-1, -1, TK_LOCATION_CHANGED);
		return true;
d355 1
d359 3
a361 3
		 * sub-windows.  However, one exception is the grow	  
		 * region.	A button down in this area will be handled
		 * by the window manager.  Note: this means that Tk
d365 1
d387 1
a387 1
 *	  Handle clicks in window titlebar.
d390 2
a391 2
 *	  1 if event was handled, 0 if event was not handled,
 *	  -1 if MouseDown was not in window titlebar. 
d394 1
a394 1
 *	  Additional events may be place on the Tk event queue.
d403 2
a404 1
    
d406 30
a435 30
        case inGoAway:
            if (TrackGoAway(medPtr->whichWin, medPtr->global)) {
                if (tkwin) {
                    TkGenWMDestroyEvent(tkwin);
                    result = 1;
                }
            }
            break;
        case inCollapseBox:
            if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
                if (tkwin) {
                    TkpWmSetState((TkWindow *)tkwin, IconicState);
                    result = 1;
                }
            }
            break;
        case inZoomIn:
        case inZoomOut:
            if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
                result = TkMacOSXZoomToplevel(medPtr->whichWin, medPtr->windowPart);
            }
            break;
        case inToolbarButton:
            if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
                result = GenerateToolbarButtonEvent(medPtr);
            }
            break;
        default:
            result = -1;
            break;
d437 1
a437 1

d446 3
a448 3
 *	  This function polls the mouse position and generates X Motion,
 *	  Enter & Leave events.	 The cursor is also updated at this
 *	  time.
d451 1
a451 1
 *	  True if event(s) are generated - false otherwise.  
d454 2
a455 2
 *	  Additional events may be place on the Tk event queue.
 *	  The cursor may be changed.
d470 1
a470 1
    if ((!TkpIsWindowFloating(medPtr->whichWin) 
d475 1
a475 1
	 * We don't send events to backgrounded windows.  So either send
d483 2
a484 2
	 * event is the grab window.  If not, then send the event
	 * to the grab window.	Otherwise, set tkWin to the subwindow  
d487 1
a487 1
       
d490 1
a490 1
	if ((rootwin == NULL) 
d494 2
a495 2
	    tkwin = Tk_TopCoordsToWindow(rootwin, 
		    medPtr->local.h, medPtr->local.v, 
d499 1
a499 1
    
d507 1
a507 1
    
d516 1
a516 1
 *	Bring this background window to the front.  We also set state
d529 3
a531 1
BringWindowForward(WindowRef wRef, Boolean isFrontProcess)
d535 2
a536 6
	OSStatus status = SetFrontProcess(&ourPsn);
	if (status != noErr) {
#ifdef TK_MAC_DEBUG
	    fprintf(stderr,"SetFrontProcess failed, %d\n", (int) status);
#endif
	}
d538 1
a538 1
    
d540 1
a540 1
	if (IsValidWindowPtr(wRef))
d542 1
d565 1
a565 1
    Tk_Window tkwin, rootwin, grabWin;
d568 1
a568 1
    XEvent     xEvent;
d570 1
a570 1
    if ((!TkpIsWindowFloating(medPtr->whichWin) 
d579 2
a580 2
	    tkwin = Tk_TopCoordsToWindow(rootwin, 
		    medPtr->local.h, medPtr->local.v, 
d584 1
a584 1
    
d590 2
a591 4
    grabWin = TkMacOSXGetCapture();

    if ((tkwin == NULL) && (grabWin != NULL)) {
	tkwin = grabWin;
d594 1
a594 1
       return false;
d621 1
a621 1
 *	  None.
d625 2
a626 2
static int
TkMacOSXGetEatButtonUp()
d637 1
a637 1
 *	  None.
d645 1
a645 1
static void
d654 36
d692 1
a692 1
 *	  Returns the current state of the button & modifier keys.
d695 2
a696 3
 *	  A bitwise inclusive OR of a subset of the following:
 *	  Button1Mask, ShiftMask, LockMask, ControlMask, Mod?Mask,
 *	  Mod?Mask.
d699 1
a699 1
 *	  None.
d705 1
a705 1
TkMacOSXButtonKeyState()
d709 1
a709 1
    
d712 4
a715 3
	OSStatus status = GetFrontProcess(&frontPsn);
	if (status == noErr) {
	    SameProcess(&frontPsn, &ourPsn, &isFrontProcess);
d718 2
a719 2
    
    if (!gEatButtonUp) {
d725 1
a725 1
    
d750 1
a750 1
    
d753 2
a754 2
    
    if (keyModifiers & alphaLock) { 
d769 1
a769 1
    if (keyModifiers & kEventKeyModifierNumLockMask) { 
d772 1
a772 1
    if (keyModifiers & kEventKeyModifierFnMask) { 
d784 3
a786 3
 *	  Check the current state of the mouse.	 This is not a complete
 *	  implementation of this function.  It only computes the root
 *	  coordinates and the current mask.
d789 2
a790 2
 *	  Sets root_x_return, root_y_return, and mask_return.  Returns
 *	  true on success.
d793 1
a793 1
 *	  None.
d815 1
a815 1
	OSStatus status;
d820 3
a822 6
	    status = GetEventParameter(ev, 
		    kEventParamWindowMouseLocation,
		    typeQDPoint, NULL, 
		    sizeof(Point), NULL,
		    &local);
	    gotMouseLoc = (status == noErr);
d826 2
a827 5
		status = GetEventParameter(ev, 
			kEventParamMouseLocation,
			typeQDPoint, NULL, 
			sizeof(Point), NULL,
			&where);
d829 1
a829 1
	    if (!ev || status != noErr) {
d836 2
a837 4
		status = GetEventParameter(ev, 
			kEventParamWindowRef,
			typeWindowRef, NULL, 
			sizeof(WindowRef), NULL,
d840 1
a840 1
	    if (!ev || status != noErr) {
d846 2
a847 1
		    GetWindowStructureWidths(whichWin, &widths);
d849 1
a849 1
		    local.v -= widths.top;	   
d878 2
a879 2
 *	  This procedure generates an X button event for the current
 *	  pointer state as reported by XQueryPointer().
d882 1
a882 1
 *	  True if event(s) are generated - false otherwise.
d885 2
a886 2
 *	  Additional events may be place on the Tk event queue.
 *	  Grab state may also change.
d897 1
a897 1
    
d916 3
a918 3
 *	  Given a global x & y position and the button key status this 
 *	  procedure generates the appropiate X button event.  It also 
 *	  handles the state changes needed to implement implicit grabs.
d921 1
a921 1
 *	  True if event(s) are generated - false otherwise.
d924 2
a925 2
 *	  Additional events may be place on the Tk event queue.
 *	  Grab state may also change.
d938 1
a938 1
    
d957 2
a958 2
 *	  Generate an X button event from a MouseEventData structure.
 *	  Handles the state changes needed to implement implicit grabs.
d961 1
a961 1
 *	  True if event(s) are generated - false otherwise.
d964 2
a965 2
 *	  Additional events may be place on the Tk event queue.
 *	  Grab state may also change.
d977 2
a978 1
    /* 
d980 2
a981 2
     * window.	ButtonUp events, however, may occur anywhere
     * on the screen.  ButtonUp events should only be sent
d984 2
a985 3
    if (0  
	    && ((medPtr->activeNonFloating == NULL)
	    || ((!(TkpIsWindowFloating(medPtr->whichWin)) 
d987 1
a987 1
	    && TkMacOSXGetCapture() == NULL))) {
d990 1
d996 1
a996 1
	tkwin = Tk_TopCoordsToWindow(tkwin, medPtr->local.h, medPtr->local.v, 
d1000 1
a1000 1
    Tk_UpdatePointer(tkwin, medPtr->global.h,  medPtr->global.v, medPtr->state);
d1037 1
a1037 1
       return true;
@


1.26
log
@Reduce the #ifdef count a lot by adding debug-print macros
@
text
@d237 5
a241 2
	if (status != noErr) {
	    ERR_MSG("Failed to retrieve mouse wheel delta, %d", (int) status);
d536 1
a536 3
BringWindowForward(
    WindowRef wRef,
    Boolean isFrontProcess)
d542 3
a544 1
	    ERR_MSG("SetFrontProcess failed, %d", (int) status);
d547 1
a547 1

d549 1
a549 1
	if (IsValidWindowPtr(wRef)) {
a550 1
	}
@


1.25
log
@	* macosx/tkMacOSXColor.c (TkSetMacColor, TkpGetColor): use AppearanceMgr
	* macosx/tkMacOSXDefault.h: to retrieve platform std colors for text
	* macosx/tkMacOSXPort.h:    selections, add "systemHighlightSecondary"
	color name for standard color of inactive selections, use this color as
	default for text widget -inactiveselectbackground to implement platform
	standard look for inactive text selections.

	* library/text.tcl (aqua): remove focus bindings to set selection color.

	* generic/tkTextBTree.c (TkTextIsElided): on TkAqua, don't show inactive
	* generic/tkTextDisp.c (GetStyle):        text selection when text
	                                          widget is in disabled state.

	* generic/tkEntry.c (DisplayEntry): change default TkAqua selection
	* macosx/tkMacOSXDefault.h:         relief to "flat" (platform std).

	* generic/tkText.c (CreateWidget): fix bug leading to default text
	selection relief string DEF_TEXT_SELECT_RELIEF being ignored.

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): allow mouse
	event delivery to background windows with kWindowNoActivatesAttribute
	(e.g. overrideredirect windows), as these never come to the foreground
	they would not receive any mouse events otherwise. [Bug 1472624]

	* macosx/tkMacOSXWindowEvent.c (TkMacOSXGenerateFocusEvent): do not
	send focus events to any windows with kWindowNoActivatesAttribute.

	* macosx/tkMacOSXXStubs.c (XQueryColor, XQueryColors): implement basic
	XColor computation from pixel values, enough to make tkImg's window.c
	happy, fixes img::window failures reported on tcl-mac.

	* macosx/tkMacOSXMenu.c (DrawMenuEntryLabel): fix leak. [Bug 1554672]

	* macosx/GNUmakefile: workaround bug in 'cp -pRH' on Darwin 6 and
	earlier, fixes 'make embedded' failure reported on tcl-mac; fix error
	from 'make deploy' with same build tree as previous 'make embedded'.

	* macosx/Wish.xcodeproj/project.pbxproj: add new tclUnixCompat.c file.

	* macosx/tkMacOSXEntry.c (TkpDrawEntryBorderAndFocus): fix typo.

	* unix/tcl.m4: sync with tcl/unix/tcl.m4.
	* unix/configure: autoconf-2.59
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.24 2006/08/18 07:47:11 das Exp $
d237 2
a238 5
	if (status != noErr ) {
#ifdef TK_MAC_DEBUG
	    fprintf (stderr,
		"Failed to retrieve mouse wheel delta, %d\n", (int) status);
#endif
d533 3
a535 1
BringWindowForward(WindowRef wRef, Boolean isFrontProcess)
d541 1
a541 3
#ifdef TK_MAC_DEBUG
	    fprintf(stderr,"SetFrontProcess failed, %d\n", (int) status);
#endif
d544 1
a544 1
    
d546 1
a546 1
	if (IsValidWindowPtr(wRef))
d548 1
@


1.24
log
@	* unix/tcl.m4 (Darwin): add support for --enable-64bit on x86_64, for
	universal builds including x86_64, for 64-bit CoreFoundation on Leopard
	and for use of -mmacosx-version-min instead of MACOSX_DEPLOYMENT_TARGET.
	* unix/configure.in (Darwin): remove 64-bit arch flags from CFLAGS for
	combined 32-bit and 64-bit universal builds, as neither TkAqua nor TkX11
	can be built for 64-bit at present.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

	* macosx/Wish.xcodeproj/project.pbxproj: switch native release targets
	to use DWARF with dSYM, Xcode 3.0 changes.
	* macosx/README: updates for x86_64 and Xcode 2.3.

	* macosx/tkMacOSXInit.c (TkpInit): when available, use public
	TransformProcessType() API instead of CPSEnableForegroundOperation() SPI
	to notify the window server that we are a GUI application.

	* macosx/tkMacOSXWm.c (WmAttrGetTitlePath): use HIWindow API on >=Tiger.

	* macosx/tkMacOSXMouseEvent.c (GenerateToolbarButtonEvent):
	* macosx/tkMacOSXMenus.c (GenerateEditEvent):
	* macosx/tkMacOSXMenu.c (MenuSelectEvent): bzero XVirtualEvent structure
	before use to ensure all fields are initialized. [Bug 1542205]
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.23 2006/07/20 06:25:19 das Exp $
d61 1
d319 7
a325 1
            } else {
@


1.23
log
@	* macosx/tkMacOSXWm.c (WmAttributesCmd, WmIconbitmapCmd): add support
	* unix/tkUnixSend.c (Tk_GetUserInactiveTime):             for weakly
	importing symbols not available on OSX 10.2 or 10.3, enables binaires
	built on later OSX versions to run on earlier ones.
	* macosx/Wish.xcodeproj/project.pbxproj: enable weak-linking; turn on
	                                         extra warnings.
	* macosx/README: document how to enable weak-linking; cleanup.
	* unix/configure.in: add check on Darwin-X11 for ld support of -weak-l
	* unix/tcl.m4:       flag and weak-link libXss if possible as it is not
	available before OSX 10.4; enforce requirement of OSX 10.2 for TkAqua;
	move Darwin specific checks & defines that are only relevant to the tcl
	build out of tcl.m4; restrict framework option to Darwin; cleanup
	quoting and help messages.
	* unix/configure: autoconf-2.59
	* unix/tkConfig.h.in: autoheader-2.59

	* macosx/GNUmakefile: enable xft for TkX11 build.
	* macosx/tkMacOSXFont.c (TkMacOSXQuarzStartDraw, TkMacOSXQuarzEndDraw):
	verify validity of context returned from QDBeginCGContext() before use.
	* macosx/tkMacOSXKeyEvent.c: ifdef out diagnostic messages to stderr.

	* macosx/tkMacOSXEvent.h:      standardize MAC_OS_X_VERSION_MAX_ALLOWED
	* macosx/tkMacOSXMenu.c:       checks per QA1316, ensure define can be
	* macosx/tkMacOSXMenubutton.c: overriden on command line (from default
	* macosx/tkMacOSXMenus.c:      of current OS version).
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWm.c:

	* macosx/tkMacOSXFont.c (TkpMeasureCharsInContext): fix
	signed-with-unsigned comparison and other warnings from gcc4 -Wextra.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.22 2006/04/28 06:02:49 das Exp $
d1012 1
d1014 1
a1014 1
    winPtr = (TkWindow *)tkwin;
a1022 1

d1028 1
a1029 1

@


1.22
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/tkMacOSXDebug.h: sync #includes with core-8-4-branch.
	* macosx/tkMacOSXEvent.h:
	* macosx/tkMacOSXFont.h:
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.21 2006/04/11 05:42:01 das Exp $
d64 1
a64 2
#if !defined(MAC_OS_X_VERSION_10_3) || \
        (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3)
@


1.21
log
@typos, whitespace
@
text
@d8 1
a8 1
 * Copyright (c) 2005 Daniel A. Steffen <das@@users.sourceforge.net>
d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.20 2006/04/07 06:15:42 das Exp $
d778 5
a782 3
    if (root_x_return && root_y_return) {
	Point where;
	EventRef ev;
d784 2
d787 1
a787 1
	if ((ev = GetCurrentEvent())) {
d789 1
a789 1
		    kEventParamMouseLocation,
d791 45
a835 2
		    sizeof(where), NULL,
		    &where);
d837 3
a839 2
	if (!ev || status != noErr) {
	    GetGlobalMouse(&where);
a840 3

	*root_x_return = where.h;
	*root_y_return = where.v;
d851 38
d945 1
a945 1
static int
@


1.20
log
@	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): fix return
	values, implement window dragging & growing in background (with Command
	key down) and by fronting clicks, use correct button & modifier state
	API when application is in background (also in TkMacOSXButtonKeyState).

	* macosx/tkMacOSXWm.c (TkMacOSXGrowToplevel): ensure QD port is set
	correctly before using API relying on it.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.19 2006/04/06 22:16:09 vincentdarley Exp $
d418 1
a418 1
                    TkpWmSetState((TkWindow *)tkwin, IconicState);;
@


1.19
log
@add support for proxy icon dragging and titlepath menu
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.18 2006/04/06 22:15:14 vincentdarley Exp $
d129 2
d140 1
a140 1
	    return 0;
d168 1
a168 1
	return 0;
d172 2
a173 2
	    SInt32 result;
	    return WindowPathSelect(medPtr->whichWin, NULL, &result);
d176 1
a176 2
	    OSStatus status = TrackWindowProxyDrag(medPtr->whichWin, where);
	
d180 1
a180 4
		if (status == noErr) {
		    /* drag successful */
		}
		return status;
d184 11
a194 2
    medPtr->state = ButtonModifiers2State(GetCurrentEventButtonState(),
            GetCurrentEventKeyModifiers());
d230 3
a282 8
	ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
	Boolean		    isFrontProcess = true;

	status = GetFrontProcess(&frontPsn);
	if (status == noErr) {
	    SameProcess(&frontPsn, &ourPsn, &isFrontProcess);
	}

d314 2
a315 2
	     * Clicks in the stoplights on a MacOS X title bar are processed
	     * directly even for background windows.  Do that here.
d320 17
a336 3
                TkMacOSXSetEatButtonUp(true);
                BringWindowForward(medPtr->whichWin, isFrontProcess);
                return false;
d338 3
a340 22
	}
    }

    if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) {
        return result;
    }
    switch (medPtr->windowPart) {
	case inDrag: {
	    CGrafPtr saveWorld;
	    GDHandle saveDevice;
	    GWorldPtr dstPort;

	    GetGWorld(&saveWorld, &saveDevice);
	    dstPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
	    SetGWorld(dstPort, NULL);

	    DragWindow(medPtr->whichWin, where, NULL);
	    where2.h = where2.v = 0;
	    LocalToGlobal(&where2);
	    if (EqualPt(where, where2)) {
		SetGWorld (saveWorld, saveDevice);
		return false;
a341 8
	    TkMacOSXWindowOffset(medPtr->whichWin, &xOffset, &yOffset);
	    where2.h -= xOffset;
	    where2.v -= yOffset;
	    TkGenWMConfigureEvent(tkwin, where2.h, where2.v,
		    -1, -1, TK_LOCATION_CHANGED);
	    SetGWorld(saveWorld, saveDevice);
	    return true;
	    break;
d343 14
a356 12
	case inContent:
	    return GenerateButtonEvent(medPtr);
	    break;
	case inGrow:
	    /*
	     * Generally the content region is the domain of Tk
	     * sub-windows.  However, one exception is the grow	  
	     * region.	A button down in this area will be handled
	     * by the window manager.  Note: this means that Tk
	     * may not get button down events in this area!
	     */
	    if (TkMacOSXGrowToplevel(medPtr->whichWin, where) == true) {
d358 16
a373 1
	    } else {
d375 5
a379 5
	    }
	    break;
	default:
	    return false;
	    break;
d381 1
a381 1
    return 0;
d677 9
a685 1
    EventRef ev = GetCurrentEvent();
d688 2
a689 1
	buttonState = ev ? GetCurrentEventButtonState() : GetCurrentButtonState();
d691 2
a692 1
    keyModifiers = ev ? GetCurrentEventKeyModifiers() : GetCurrentKeyModifiers();
@


1.18
log
@add support for proxy icon dragging and titlepath menu
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.17 2006/03/24 14:58:01 das Exp $
d180 1
a180 1
		    printf("drag successful");
@


1.17
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
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.16 2005/12/13 03:44:34 das Exp $
d168 18
@


1.16
log
@	* library/demos/cscroll.tcl: add MouseWheel bindings for aqua.

	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents):
	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent,
	GenerateMouseWheelEvent): add support for kEventMouseScroll events
	(smooth mouse wheel scrolling from mighty mouse or scrolling trackpad)
	by handling kEventMouseWheelMoved on application target as well as on
	dispatcher, in order to pick up synthesized MouseWheel events from
	HIObject handler (c.f. QA1453); add support for horizontal scrolling
	events by generating MouseWheel XEvent with Shift modifier.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.15 2005/11/27 02:36:15 das Exp $
d60 1
a60 3
#include "tkInt.h"
#include <X11/X.h>
#include <X11/Xlib.h>
a61 2
#include "tkMacOSXInt.h"
#include "tkPort.h"
@


1.15
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
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.14 2005/09/10 14:53:21 das Exp $
d131 1
a131 1
    OSStatus	    status;
d211 1
a211 2
		kEventParamMouseWheelDelta,
		typeLongInteger, NULL,
d215 2
a216 2
	     fprintf (stderr,
		 "Failed to retrieve mouse wheel delta, %d\n", (int) status);
d218 11
a228 3
	     statusPtr->err = 1;
	     return false;
	 }
d236 1
a236 1
	 * MouseMoved, MouseDragged or kEventMouseWheelMoved 
d240 5
a244 1
	    return GenerateMouseWheelEvent(medPtr);
a547 1
    int local_x, local_y;
d563 1
a563 1
		    &local_x, &local_y);
d578 1
a578 1
       return true;
d583 3
a585 1
    xEvent.xbutton.state = TkMacOSXButtonKeyState();
@


1.14
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
@d7 5
a11 1
 *      Copyright 2001, Apple Computer, Inc.
d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.13 2005/08/09 07:39:21 das Exp $
d68 7
d90 1
a90 1
static int gEatButtonUp = 0;	   /* 1 if we need to eat the next * up event */
d104 2
a105 2
extern int TkMacOSXGetEatButtonUp();
extern void TkMacOSXSetEatButtonUp(int f);
a345 17
	case inMenuBar: {
	    int oldMode;

	    oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
	    TkMacOSXClearMenubarActive();

	    /*
	     * Handle -postcommand
	     */

	    TkMacOSXPreprocessMenu();
	    TkMacOSXHandleMenuSelect(MenuSelect(where),
		    medPtr->state & Mod2Mask);
	    Tcl_SetServiceMode(oldMode);
	    return true; /* TODO: may not be on event on queue. */
	    break;
	}
d597 1
a597 1
int
d617 1
a617 1
void
@


1.13
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
@d53 1
a53 1
 * RCS: @@(#) $Id$
d85 1
a85 1
static void BringWindowForward _ANSI_ARGS_((WindowRef wRef));
d113 1
a113 1
int
d204 1
d206 2
a207 1
		 "Failed to retrieve mouse wheel delta, %d\n", (int)status);
d236 9
a244 1
	 
d246 2
a247 1
		&& (medPtr->whichWin != medPtr->activeNonFloating)) {
d255 3
a257 1
		    BringWindowForward(GetWindowFromPort(TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)));
d268 3
a270 1
		BringWindowForward(GetWindowFromPort(TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)));
d283 1
a283 1
                BringWindowForward(medPtr->whichWin);
a288 1
    
d505 1
a505 1
BringWindowForward(WindowRef wRef)
d507 7
a513 9
    do {
	ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
	Boolean		    flag;
	int		    err;
	
	err = GetFrontProcess(&frontPsn);
	if (err != noErr) {
	    fprintf(stderr, "GetFrontProcess failed, %d\n", err);
	    break;
d515 1
a515 14
	err = SameProcess(&frontPsn, &ourPsn, &flag);
	if (err != noErr) {
	    fprintf(stderr, "SameProcess failed, %d\n", err);
	    break;
	} else {
	    if (!flag) {
		err = SetFrontProcess(&ourPsn);
		if (err != noErr) {
		    fprintf(stderr,"SetFrontProcess failed,%d\n", err);
		    break;
		}
	    }
	}
    } while (0);
@


1.12
log
@	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent):
	corrected if expression error (use of = instead of ==)
@
text
@d5 1
a5 1
 *      on MacOS X.
d52 2
d65 2
a66 2
    WindowRef      whichWin;
    WindowRef      activeNonFloating;
d68 2
a69 2
    Point          global;
    Point          local;   
d71 2
a72 1
    long           delta;
d79 1
a79 1
static int gEatButtonUp = 0;       /* 1 if we need to eat the next * up event */
d88 4
a91 2
static int HandleInGoAway(Tk_Window tkwin, WindowRef winPtr, Point where);
static OSErr HandleInCollapse(WindowRef win);
d101 2
a102 2
 *        This routine processes the event in eventPtr, and
 *        generates the appropriate Tk events from it.
d105 1
a105 1
 *        True if event(s) are generated - false otherwise.
d108 1
a108 1
 *        Additional events may be place on the Tk event queue.
d112 1
a112 1
 
d116 5
a120 7
    WindowRef      frontWindow;
    Tk_Window      tkwin;
    Point          where, where2;
    int            xOffset, yOffset;
    TkDisplay *    dispPtr;
    Window         window;
    int            status,err;
a121 2
    KeyMap         keyMap;
    long           modif;
d124 17
a140 9
        case kEventMouseUp:
        case kEventMouseDown:
        case kEventMouseMoved:
        case kEventMouseDragged:
        case kEventMouseWheelMoved:
            break;
        default:
            return 0;
            break;
d143 11
a153 4
            kEventParamMouseLocation,
            typeQDPoint, NULL, 
            sizeof(where), NULL,
            &where);
d155 1
a155 2
        fprintf (stderr, "Failed to retrieve mouse location,%d\n", status);
        return 0;
d157 25
a181 38
    medPtr->state = 0;
    GetKeys(keyMap);
    modif = EndianS32_BtoN(*(long*)(&keyMap[1]));

    if (modif & 2) { 
        medPtr->state |= LockMask;
    }
    if (modif & 1) {
        medPtr->state |= ShiftMask;
    }
    if (modif & 8) {
        medPtr->state |= ControlMask;
    }
    if (modif & 32768) {
        medPtr->state |= Mod1Mask;              /* command key */
    }
    if (modif & 4) {
        medPtr->state |= Mod2Mask;              /* option key */
    }
    if (eventPtr->eKind == kEventMouseDown 
            || eventPtr->eKind == kEventMouseDragged ) {
        EventMouseButton mouseButton;
        status = GetEventParameter(eventPtr->eventRef,
                kEventParamMouseButton,
                typeMouseButton, NULL,
	        sizeof(mouseButton), NULL,&mouseButton);
        if (status != noErr ) {
             fprintf (stderr, "Failed to retrieve mouse button, %d\n", status);
             statusPtr->err = 1;
             return 0;
         }
         medPtr->state |= 1 << ((mouseButton-1)+8);
    }

    medPtr->windowPart = FindWindow(where, &medPtr->whichWin);
    window = TkMacOSXGetXWindow(medPtr->whichWin);
    if (medPtr->whichWin != NULL && window == None) {
        return 0;
a182 2
    
    frontWindow = FrontWindow();
d192 5
a196 6
        if (TkMacOSXGetEatButtonUp()) {
            TkMacOSXSetEatButtonUp(false);
            return false;
        }
        return TkGenerateButtonEvent(where.h, where.v,
            window, medPtr->state);
d199 10
a208 10
        status = GetEventParameter(eventPtr->eventRef,
                kEventParamMouseWheelDelta,
                typeLongInteger, NULL,
		sizeof(medPtr->delta), NULL,&medPtr->delta);
        if (status != noErr ) {
             fprintf (stderr,
                 "Failed to retrieve mouse wheel delta, %d\n", status);
             statusPtr->err = 1;
             return false;
         }
d210 1
a210 1
    
d212 1
a212 54
    tkwin = Tk_IdToWindow(dispPtr->display, window);

    if (eventPtr->eKind != kEventMouseDown ) {
        /* 
         * MouseMoved, MouseDragged or kEventMouseWheelMoved 
         */
         
        medPtr->global = where;
        medPtr->local = where;
	/* 
	 * We must set the port to the right window -- the one
	 * we are actually going to use -- before finding
	 * the local coordinates, otherwise we will have completely
	 * wrong local x,y!
	 * 
	 * I'm pretty sure this window is medPtr->whichWin, unless
	 * perhaps there is a grab.  Certainly 'frontWindow' or
	 * 'medPtr->activeNonFloating' are wrong.
	 */ 
	SetPortWindowPort(medPtr->whichWin);
        GlobalToLocal(&medPtr->local);
        if (eventPtr->eKind == kEventMouseWheelMoved ) {
            return GenerateMouseWheelEvent(medPtr); 
        } else {
            return GeneratePollingEvents(medPtr); 
        }
    }

    if (medPtr->whichWin && eventPtr->eKind == kEventMouseDown) {
        ProcessSerialNumber frontPsn, ourPsn;
        Boolean             flag;
	err = GetFrontProcess(&frontPsn);
        if (err != noErr) {
            fprintf(stderr, "GetFrontProcess failed, %d\n", err);
            statusPtr->err = 1;
            return 1;
        }
        
        GetCurrentProcess(&ourPsn);
	err = SameProcess(&frontPsn, &ourPsn, &flag);
        if (err != noErr) {
            fprintf(stderr, "SameProcess failed, %d\n", err);
            statusPtr->err = 1;
            return 1;
        } else {
            if (!flag) {
	      err = SetFrontProcess(&ourPsn);
                if (err != noErr) {
                    fprintf(stderr,"SetFrontProcess failed,%d\n", err);
                    statusPtr->err = 1;
                    return 1;
                }
            }
        }
d214 10
d227 45
a271 62
        /*
         * We got a mouse down in a window
         * See if this is the activate click
         * This click moves the window forward.  We don't want
         * the corresponding mouse-up to be reported to the application
         * or else it will mess up some Tk scripts.
         */
         
         if (!(TkpIsWindowFloating(medPtr->whichWin))
             && (medPtr->whichWin != medPtr->activeNonFloating)) {
             Tk_Window grabWin = TkMacOSXGetCapture();
             if ((grabWin == NULL)) {
                int grabState = TkGrabState((TkWindow*)tkwin);
                if (grabState != TK_GRAB_NONE && grabState != TK_GRAB_IN_TREE) {
                   /* Now we want to set the focus to the local grabWin */
                    TkMacOSXSetEatButtonUp(true);
                    grabWin = (Tk_Window) (((TkWindow*)tkwin)->dispPtr->grabWinPtr);
                    BringWindowForward(GetWindowFromPort(TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)));
                   statusPtr->stopProcessing = 1;
                   return false;
                }
             }
             if ((grabWin != NULL) && (grabWin != tkwin)) {
                 TkWindow * tkw, * grb;
                 tkw = (TkWindow *)tkwin;
                 grb = (TkWindow *)grabWin;
		 /* Now we want to set the focus to the global grabWin */
                 TkMacOSXSetEatButtonUp(true);
                 BringWindowForward(GetWindowFromPort(TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)));
                   statusPtr->stopProcessing = 1;
                 return false;
             }

             /*
              * Clicks in the stoplights on a MacOS X title bar are processed
              * directly even for background windows.  Do that here.
              */
             
             switch (medPtr->windowPart) {
                 case inGoAway:
                     return HandleInGoAway(tkwin, medPtr->whichWin, where);
                     break;
                 case inCollapseBox:
                     err = HandleInCollapse(medPtr->whichWin);
                     if (err == noErr) {
                         statusPtr->err = 1;
                     }
                     statusPtr->stopProcessing = 1;
                     return false;
                     break;
                 case inZoomIn:
                     return false;
                     break;
                 case inZoomOut:
                     return false;
                     break;
                 default:
                     TkMacOSXSetEatButtonUp(true);
                     BringWindowForward(medPtr->whichWin);
                     return false;
             }
         }
d274 4
d279 62
a340 87
        case inDrag:
            {
                CGrafPtr saveWorld;
                GDHandle saveDevice;
                GWorldPtr dstPort;
                
                GetGWorld(&saveWorld, &saveDevice);
                dstPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
                SetGWorld(dstPort, NULL);
                
                DragWindow(medPtr->whichWin, where, NULL);
                where2.h = where2.v = 0;
                LocalToGlobal(&where2);
                if (EqualPt(where, where2)) {
                    SetGWorld (saveWorld, saveDevice);
                    return false;
                }
                TkMacOSXWindowOffset(medPtr->whichWin, &xOffset, &yOffset);
                where2.h -= xOffset;
                where2.v -= yOffset;
                TkGenWMConfigureEvent(tkwin, where2.h, where2.v,
                        -1, -1, TK_LOCATION_CHANGED);
                SetGWorld(saveWorld, saveDevice);
                return true;
                break;
            }
        case inContent:
            return TkGenerateButtonEvent(where.h, where.v, 
                    window, medPtr->state);
            break;
        case inGrow:
            /*      
             * Generally the content region is the domain of Tk
             * sub-windows.  However, one exception is the grow   
             * region.  A button down in this area will be handled
             * by the window manager.  Note: this means that Tk
             * may not get button down events in this area!
             */
            if (TkMacOSXGrowToplevel(medPtr->whichWin, where) == true) {
                return true;
            } else {
                return TkGenerateButtonEvent(where.h,
                           where.v, window, medPtr->state);
            }
            break;
        case inGoAway:
            return HandleInGoAway(tkwin, medPtr->whichWin, where);
            break;
        case inMenuBar:
            {
                int oldMode;
                KeyMap theKeys;

                GetKeys(theKeys);
                oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
                TkMacOSXClearMenubarActive();
                
                /*
                 * Handle -postcommand
                 */
                 
                TkMacOSXPreprocessMenu();
                TkMacOSXHandleMenuSelect(MenuSelect(where),
                        EndianS32_BtoN(*(long*)(&theKeys[1])) & 4);
                Tcl_SetServiceMode(oldMode);
                return true; /* TODO: may not be on event on queue. */
            }
            break;
        case inZoomIn:
        case inZoomOut:
            if (TkMacOSXZoomToplevel(medPtr->whichWin, where, 
                    medPtr->windowPart) == true) {
                return true;
            } else {
                return false;
            }
            break;
        case inCollapseBox:
            err = HandleInCollapse(medPtr->whichWin);
            if (err == noErr) {
                statusPtr->err = 1;
            }
            statusPtr->stopProcessing = 1;
            break;
        default:
            return false;
            break;
d344 1
a344 1

d348 1
a348 1
 * HandleInGoAway --
d350 1
a350 2
 *        Tracks the cursor in the go away box and deletes the window
 *        if the button stays depressed on button up.
d353 2
a354 1
 *        True if no errors - false otherwise.
d357 1
a357 1
 *        The window tkwin may be destroyed.
d361 1
d363 1
a363 1
HandleInGoAway(Tk_Window tkwin, WindowRef win, Point where)
d365 33
a397 6
    if (TrackGoAway(win, where)) {
        if (tkwin == NULL) {
            return false;
        }
        TkGenWMDestroyEvent(tkwin);
        return true;
a398 2
    return false;    
}
d400 1
a400 27
/*
 *----------------------------------------------------------------------
 *
 * HandleInCollapse --
 *
 *        Tracks the cursor in the collapse box and colapses the window
 *        if the button stays depressed on button up.
 *
 * Results:
 *        Error return from CollapseWindow
 *
 * Side effects:
 *        The window win may be collapsed.
 *
 *----------------------------------------------------------------------
 */
OSErr
HandleInCollapse(WindowRef win)
{
    OSErr err;
    
    err = CollapseWindow(win,
                         !IsWindowCollapsed(win));
    if (err != noErr) {
        fprintf(stderr,"CollapseWindow failed,%d\n", err);
    }
    return err;
d402 1
a402 1

d408 3
a410 3
 *        This function polls the mouse position and generates X Motion,
 *        Enter & Leave events.  The cursor is also updated at this
 *        time.
d413 1
a413 1
 *        True if event(s) are generated - false otherwise.  
d416 2
a417 2
 *        Additional events may be place on the Tk event queue.
 *        The cursor may be changed.
a425 1
    Window window;
d433 7
a439 7
            && (medPtr->activeNonFloating != medPtr->whichWin))) {
        /*
         * If the window for this event is not floating, and is not the
         * active non-floating window, don't generate polling events.
         * We don't send events to backgrounded windows.  So either send
         * it to the grabWin, or NULL if there is no grabWin.
         */
d441 1
a441 1
        tkwin = grabWin;
d443 6
a448 6
        /*
         * First check whether the toplevel containing this mouse
         * event is the grab window.  If not, then send the event
         * to the grab window.  Otherwise, set tkWin to the subwindow  
         * which most closely contains the mouse event.
         */
d450 10
a459 11
        window = TkMacOSXGetXWindow(medPtr->whichWin);
        dispPtr = TkGetDisplayList();
        rootwin = Tk_IdToWindow(dispPtr->display, window);
        if ((rootwin == NULL) 
                || ((grabWin != NULL) && (rootwin != grabWin))) {
            tkwin = grabWin;
        } else {
            tkwin = Tk_TopCoordsToWindow(rootwin, 
                    medPtr->local.h, medPtr->local.v, 
                    &local_x, &local_y);
        }
d468 1
a468 1
            medPtr->state);
a471 1

d473 1
a473 1
/*           
d477 3
a479 3
 *           
 *      Bring this background window to the front.  We also set state
 *      so Tk thinks the button is currently up.
d482 2
a483 2
 *      None.
 *      
d485 2
a486 2
 *      The window is brought forward.
 *          
d488 3
a490 3
 */         
  
static void     
d492 26
a517 1
{           
d519 2
a520 2
        if (IsValidWindowPtr(wRef))
        SelectWindow(wRef);
d523 16
a543 1
    Window window;
d550 2
a551 2
            && (medPtr->activeNonFloating != medPtr->whichWin))) {
        tkwin = NULL;
d553 9
a561 10
        window = TkMacOSXGetXWindow(medPtr->whichWin);
        dispPtr = TkGetDisplayList();
        rootwin = Tk_IdToWindow(dispPtr->display, window);
        if (rootwin == NULL) {
            tkwin = NULL;
        } else {
            tkwin = Tk_TopCoordsToWindow(rootwin, 
                    medPtr->local.h, medPtr->local.v, 
                    &local_x, &local_y);
        }
d572 1
a572 1
        tkwin = grabWin;
d577 1
a577 1
    winPtr = ( TkWindow *)tkwin;
d589 1
a589 1

d596 2
a597 2
 *      Returns the flag indicating if we need to eat the
 *      next mouse up event
d600 1
a600 1
 *        None.
d611 2
d616 1
a616 1
 *        None.
d619 2
a620 2
 *      Sets the flag indicating if we need to eat the
 *      next mouse up event
d622 1
d629 1
a629 1

d635 1
a635 1
 *        Returns the current state of the button & modifier keys.
d638 3
a640 3
 *        A bitwise inclusive OR of a subset of the following:
 *        Button1Mask, ShiftMask, LockMask, ControlMask, Mod?Mask,
 *        Mod?Mask.
d643 1
a643 1
 *        None.
d651 5
a655 6
    unsigned int state = 0;
    KeyMap theKeys;
    long modif;

    if (Button() & !gEatButtonUp) {
        state |= Button1Mask;
d657 21
d679 7
a685 1
    GetKeys(theKeys);
d687 8
a694 4
    modif = EndianS32_BtoN(*(long*)(&theKeys[1]));

    if (modif & 2) {
        state |= LockMask;
d696 2
a697 3

    if (modif & 1) {
        state |= ShiftMask;
d699 2
a700 3

    if (modif & 8) {
        state |= ControlMask;
d702 2
a703 3

    if (modif & 32768) {
        state |= Mod1Mask;                /* command key */
d705 2
a706 3

    if (modif & 4) {
        state |= Mod2Mask;                /* option key */
d717 3
a719 3
 *        Check the current state of the mouse.  This is not a complete
 *        implementation of this function.  It only computes the root
 *        coordinates and the current mask.
d722 2
a723 2
 *        Sets root_x_return, root_y_return, and mask_return.  Returns
 *        true on success.
d726 1
a726 1
 *        None.
d743 22
a764 11
    Point where;
    CGrafPtr port;
    GDHandle dev;

    GetGWorld(&port,&dev);
    GetMouse(&where);
    LocalToGlobal(&where);

    *root_x_return = where.h;
    *root_y_return = where.v;
    *mask_return = TkMacOSXButtonKeyState();    
d767 1
a767 2


d773 3
a775 3
 *        Given a global x & y position and the button key status this 
 *        procedure generates the appropiate X button event.  It also 
 *        handles the state changes needed to implement implicit grabs.
d778 1
a778 1
 *        True if event(s) are generated - false otherwise.
d781 2
a782 2
 *        Additional events may be place on the Tk event queue.
 *        Grab state may also change.
d789 40
a828 4
    int x,                /* X location of mouse */
    int y,                /* Y location of mouse */
    Window window,        /* X Window containing button event. */
    unsigned int state)   /* Button Key state suitable for X event */
a829 2
    WindowRef whichWin, frontWin;
    Point where;
d836 1
a836 1
     * window.  ButtonUp events, however, may occur anywhere
d840 6
a845 10
     
    where.h = x;
    where.v = y;
    FindWindow(where, &whichWin);
    frontWin = FrontNonFloatingWindow();
                        
    if (0 && ((frontWin == NULL) || ((!(TkpIsWindowFloating(whichWin)) 
            && (frontWin != whichWin))
            && TkMacOSXGetCapture() == NULL))) {
        return false;
d849 2
a850 5
    tkwin = Tk_IdToWindow(dispPtr->display, window);
    
    /* SetPortWindowPort(ActiveNonFloatingWindow()); */
    SetPortWindowPort(whichWin);
    GlobalToLocal(&where);
d852 42
a893 2
        tkwin = Tk_TopCoordsToWindow(tkwin, where.h, where.v, 
                &dummy, &dummy);
d896 16
a911 1
    Tk_UpdatePointer(tkwin, x,  y, state);
@


1.11
log
@Fix for 1160025
@
text
@d315 1
a315 1
                     if (err = noErr) {
@


1.10
log
@	* generic/tkMain.c:
	* macosx/tkMacOSXAppInit.c (removed):
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h: changes to make TkAqua dynamically loadable,
	enabling [package require Tk] from tclsh. Startup code from
	tkMacOSXAppInit.c moved into tkMacOSXInit.c, added code that
	notifies the window server that an unbundled executable is a full
	GUI application after loading Tk. [Patch 1035348]

	* doc/wm.n: documented [wm attributes] on Mac OS X. [Bug 606665]
	* macosx/tkMacOSXWm.c: implemented TIP 222 [wm attributes -alpha] on
	Mac OS X. [Patch 892194]
	WmIconbitmapCmd: adopted FSRef changes from [wm atttrs -titlepath].

	* macosx/tkMacOSXSubwindows.c: synced spacing/formatting with
	core-8-4-branch.

	* generic/tkRectOval.c:
	* macosx/README:
	* macosx/tkMacOSXDefault.h:
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h:
	* macosx/tkMacOSXMenu.c:
	* macosx/tkMacOSXWm.c: forward port from core-8-4-branch of Jim's
	and my changes for CG drawing and [wm attributes] (corresponds to
	8.4 changes dating from 09-18, 07-27, 07-24).

	* macosx/tkMacOSXMouseEvent.c: endianness fixes.

	* macosx/Wish.pbproj/project.pbxproj: corrected path to html help
	inside framework.

	* macosx/Makefile: prevent parallel make from building several
	targets at the same time.
@
text
@d337 24
a360 5
            DragWindow(medPtr->whichWin, where, NULL);
            where2.h = where2.v = 0;
            LocalToGlobal(&where2);
            if (EqualPt(where, where2)) {
                return false;
a361 7
            TkMacOSXWindowOffset(medPtr->whichWin, &xOffset, &yOffset);
            where2.h -= xOffset;
            where2.v -= yOffset;
            TkGenWMConfigureEvent(tkwin, where2.h, where2.v,
                    -1, -1, TK_LOCATION_CHANGED);
            return true;
            break;
@


1.9
log
@	* macosx/tkMacOSXMouseEvent.c: fixed modifiers for MouseWheel events.

	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkAboutDlg.r: changed year in copyright strings to 2004.
@
text
@d120 1
d144 3
a146 1
    if (keyMap[1] & 2) { 
d149 1
a149 1
    if (keyMap[1] & 1) {
d152 1
a152 1
    if (keyMap[1] & 8) {
d155 1
a155 1
    if (keyMap[1] & 32768) {
d158 1
a158 1
    if (keyMap[1] & 4) {
d387 1
a387 1
                        theKeys[1] & 4);
d684 1
d691 2
d694 1
a694 1
    if (theKeys[1] & 2) {
d698 1
a698 1
    if (theKeys[1] & 1) {
d702 1
a702 1
    if (theKeys[1] & 8) {
d706 1
a706 1
    if (theKeys[1] & 32768) {
d710 1
a710 1
    if (theKeys[1] & 4) {
@


1.8
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
@d611 1
@


1.7
log
@MacOSX fixes
@
text
@d159 1
a159 1
            || eventPtr->eKind== kEventMouseDragged ) {
d161 5
a165 4
        if ((status=GetEventParameter(eventPtr->eventRef,
             kEventParamMouseButton,
             typeMouseButton, NULL,
             sizeof(mouseButton), NULL,&mouseButton)) != noErr ) {
d173 1
a173 1
    medPtr->windowPart= FindWindow(where, &medPtr->whichWin);
d197 5
a201 4
        if ((status=GetEventParameter(eventPtr->eventRef,
             kEventParamMouseWheelDelta,
             typeLongInteger, NULL,
             sizeof(medPtr->delta), NULL,&medPtr->delta)) != noErr ) {
d238 1
a238 1
    if (medPtr->whichWin && eventPtr->eKind==kEventMouseDown) {
d241 2
a242 1
        if ((err=GetFrontProcess(&frontPsn))!=noErr) {
d249 2
a250 1
        if ((err=SameProcess(&frontPsn, &ourPsn, &flag))!=noErr) {
d256 2
a257 1
                if ((err=SetFrontProcess(&ourPsn)) != noErr) {
d492 1
a492 1
    Tk_Window tkwin, rootwin, grabWin, topPtr;
@


1.6
log
@2003-02-19  Jim Ingham <jingham@@apple.com>

        * tkMacOSXMouseEvents.c (GeneratePollingEvents): In the case
        where there was a capture window, we were sending the events to
        the capture window.  But the capture window (return value or
        TkMacOSXGetCapture) is always a toplevel.  So this is wrong in
        the case that the Event's toplevel IS the capture window - in
        which case the event should go to the subwindow most closely
        containing the event.

Fixes bug #688188
@
text
@d274 11
d289 4
a292 1
                 SysBeep(1);  
@


1.6.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
@d159 1
a159 1
            || eventPtr->eKind == kEventMouseDragged ) {
d161 4
a164 5
        status = GetEventParameter(eventPtr->eventRef,
                kEventParamMouseButton,
                typeMouseButton, NULL,
	        sizeof(mouseButton), NULL,&mouseButton);
        if (status != noErr ) {
d172 1
a172 1
    medPtr->windowPart = FindWindow(where, &medPtr->whichWin);
d196 4
a199 5
        status = GetEventParameter(eventPtr->eventRef,
                kEventParamMouseWheelDelta,
                typeLongInteger, NULL,
		sizeof(medPtr->delta), NULL,&medPtr->delta);
        if (status != noErr ) {
d236 1
a236 1
    if (medPtr->whichWin && eventPtr->eKind == kEventMouseDown) {
d239 1
a239 2
	err = GetFrontProcess(&frontPsn);
        if (err != noErr) {
d246 1
a246 2
	err = SameProcess(&frontPsn, &ourPsn, &flag);
        if (err != noErr) {
d252 1
a252 2
	      err = SetFrontProcess(&ourPsn);
                if (err != noErr) {
a273 11
             if ((grabWin == NULL)) {
                int grabState = TkGrabState((TkWindow*)tkwin);
                if (grabState != TK_GRAB_NONE && grabState != TK_GRAB_IN_TREE) {
                   /* Now we want to set the focus to the local grabWin */
                    TkMacOSXSetEatButtonUp(true);
                    grabWin = (Tk_Window) (((TkWindow*)tkwin)->dispPtr->grabWinPtr);
                    BringWindowForward(GetWindowFromPort(TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)));
                   statusPtr->stopProcessing = 1;
                   return false;
                }
             }
d278 1
a278 4
		 /* Now we want to set the focus to the global grabWin */
                 TkMacOSXSetEatButtonUp(true);
                 BringWindowForward(GetWindowFromPort(TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)));
                   statusPtr->stopProcessing = 1;
d473 1
a473 1
    Tk_Window tkwin, rootwin, grabWin;
@


1.6.2.2
log
@	* macosx/tkMacOSXMouseEvent.c: fixed modifiers for MouseWheel events.

	* library/listbox.tcl:
	* library/text.tcl:
	* library/scrlbar.tcl: on Mac OS, add bindings for MouseWheel with
	modifiers, according to platform convention:
	Option increases scrolling speed 10 fold; Space scrolls horizontally.

	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkAboutDlg.r: changed year in copyright strings to 2004.
@
text
@a610 1
    xEvent.xbutton.state = TkMacOSXButtonKeyState();
@


1.6.2.3
log
@	* generic/tkMain.c:
	* macosx/tkMacOSXAppInit.c (removed):
	* macosx/Wish.pbproj/project.pbxproj:
	* macosx/tkMacOSXInit.c:
	* macosx/tkMacOSXInt.h: changes to make TkAqua dynamically loadable,
	enabling [package require Tk] from tclsh. Startup code from
	tkMacOSXAppInit.c moved into tkMacOSXInit.c, added code that
	notifies the window server that an unbundled executable is a full
	GUI application after loading Tk. [Patch 1035348]

	* doc/wm.n: documented [wm attributes] on Mac OS X. [Bug 606665]
	* macosx/tkMacOSXWm.c: implemented TIP 222 [wm attributes -alpha] on
	Mac OS X. [Patch 892194]
	WmIconbitmapCmd: adopted FSRef changes from [wm atttrs -titlepath].

	* macosx/tkMacOSXButton.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXSubwindows.c: synced spacing/formatting with HEAD.

	* macosx/tkMacOSXMouseEvent.c: endianness fixes.

	* macosx/Wish.pbproj/project.pbxproj: corrected path to html help
	inside framework.

	* macosx/Makefile: prevent parallel make from building several
	targets at the same time.
	Ensure that xcodebuild will use Wish.pbproj project even if a .xcode
	project is also present.
@
text
@a119 1
    long           modif;
d143 1
a143 3
    modif = EndianS32_BtoN(*(long*)(&keyMap[1]));

    if (modif & 2) { 
d146 1
a146 1
    if (modif & 1) {
d149 1
a149 1
    if (modif & 8) {
d152 1
a152 1
    if (modif & 32768) {
d155 1
a155 1
    if (modif & 4) {
d384 1
a384 1
                        EndianS32_BtoN(*(long*)(&theKeys[1])) & 4);
a680 1
    long modif;
a686 2
    
    modif = EndianS32_BtoN(*(long*)(&theKeys[1]));
d688 1
a688 1
    if (modif & 2) {
d692 1
a692 1
    if (modif & 1) {
d696 1
a696 1
    if (modif & 8) {
d700 1
a700 1
    if (modif & 32768) {
d704 1
a704 1
    if (modif & 4) {
@


1.6.2.4
log
@Fix for bug 1160025.
@
text
@d337 5
a341 24
            {
                CGrafPtr saveWorld;
                GDHandle saveDevice;
                GWorldPtr dstPort;
                
                GetGWorld(&saveWorld, &saveDevice);
                dstPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
                SetGWorld(dstPort, NULL);
                
                DragWindow(medPtr->whichWin, where, NULL);
                where2.h = where2.v = 0;
                LocalToGlobal(&where2);
                if (EqualPt(where, where2)) {
                    SetGWorld (saveWorld, saveDevice);
                    return false;
                }
                TkMacOSXWindowOffset(medPtr->whichWin, &xOffset, &yOffset);
                where2.h -= xOffset;
                where2.v -= yOffset;
                TkGenWMConfigureEvent(tkwin, where2.h, where2.v,
                        -1, -1, TK_LOCATION_CHANGED);
                SetGWorld(saveWorld, saveDevice);
                return true;
                break;
d343 7
@


1.6.2.5
log
@	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent):
	corrected if expression error (use of = instead of ==)
@
text
@d315 1
a315 1
                     if (err == noErr) {
@


1.6.2.6
log
@	* macosx/tkMacOSXWm.c (TkpWmSetState): add IsWindowCollapsed check
	before calling CollapseWindow.
	(WmResizableCmd): adjust kWindow*Attributes according to resize
	parameters.

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): handle
	inToolbarButton action (generates <<ToolbarButton>> virtual event)
	and correct inCollapseBox to properly track the event (waiting for
	buttonrelease) and generate the Unmap event (Map event on
	redisplay still missing).
@
text
@d67 1
a67 1
    Point          local;
d86 1
a86 1
static int TkMacOSXToolarbuttonEvent(MouseEventData * medPtr, Point where);
d107 1
a107 1

d181 1
a181 1

d211 1
a211 1

d215 8
a222 8
    if (eventPtr->eKind != kEventMouseDown) {
	/*
	 * MouseMoved, MouseDragged or kEventMouseWheelMoved 
	 */

	medPtr->global = where;
	medPtr->local = where;
	/*
d227 1
a227 1
	 *
d231 1
a231 1
	 */
d233 6
a238 6
	GlobalToLocal(&medPtr->local);
	if (eventPtr->eKind == kEventMouseWheelMoved) {
	    return GenerateMouseWheelEvent(medPtr);
	} else {
	    return GeneratePollingEvents(medPtr);
	}
d242 2
a243 2
	ProcessSerialNumber frontPsn, ourPsn;
	Boolean             flag;
d245 7
a251 7
	if (err != noErr) {
	    fprintf(stderr, "GetFrontProcess failed, %d\n", err);
	    statusPtr->err = 1;
	    return 1;
	}

	GetCurrentProcess(&ourPsn);
d253 14
a266 14
	if (err != noErr) {
	    fprintf(stderr, "SameProcess failed, %d\n", err);
	    statusPtr->err = 1;
	    return 1;
	} else {
	    if (!flag) {
		err = SetFrontProcess(&ourPsn);
		if (err != noErr) {
		    fprintf(stderr,"SetFrontProcess failed,%d\n", err);
		    statusPtr->err = 1;
		    return 1;
		}
	    }
	}
d271 62
a332 71
	/*
	 * We got a mouse down in a window
	 * See if this is the activate click
	 * This click moves the window forward.  We don't want
	 * the corresponding mouse-up to be reported to the application
	 * or else it will mess up some Tk scripts.
	 */

	if (!(TkpIsWindowFloating(medPtr->whichWin))
		&& (medPtr->whichWin != medPtr->activeNonFloating)) {
	    Tk_Window grabWin = TkMacOSXGetCapture();
	    if ((grabWin == NULL)) {
		int grabState = TkGrabState((TkWindow*)tkwin);
		if (grabState != TK_GRAB_NONE && grabState != TK_GRAB_IN_TREE) {
		    /* Now we want to set the focus to the local grabWin */
		    TkMacOSXSetEatButtonUp(true);
		    grabWin = (Tk_Window) (((TkWindow*)tkwin)->dispPtr->grabWinPtr);
		    BringWindowForward(GetWindowFromPort(TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)));
		    statusPtr->stopProcessing = 1;
		    return false;
		}
	    }
	    if ((grabWin != NULL) && (grabWin != tkwin)) {
		TkWindow * tkw, * grb;
		tkw = (TkWindow *)tkwin;
		grb = (TkWindow *)grabWin;
		/* Now we want to set the focus to the global grabWin */
		TkMacOSXSetEatButtonUp(true);
		BringWindowForward(GetWindowFromPort(TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)));
		statusPtr->stopProcessing = 1;
		return false;
	    }

	    /*
	     * Clicks in the stoplights on a MacOS X title bar are processed
	     * directly even for background windows.  Do that here.
	     */

	    switch (medPtr->windowPart) {
		case inGoAway:
		    return HandleInGoAway(tkwin, medPtr->whichWin, where);
		    break;
		case inCollapseBox:
		    /*
		     * The Appearance Manager handles collapsing for us,
		     * but we need to make sure we propagate the event in Tk.
		     */
		    if (TrackBox(medPtr->whichWin, where, inCollapseBox)) {
			TkpWmSetState((TkWindow *)tkwin, IconicState);
		    }
		    return false;
		    break;
		case inZoomIn:
		    return false;
		    break;
		case inZoomOut:
		    return false;
		    break;
		case inToolbarButton:
		    BringWindowForward(medPtr->whichWin);
		    if (TrackBox(medPtr->whichWin, where, inToolbarButton)) {
			return TkMacOSXToolarbuttonEvent(medPtr, where);
		    }
		    return false;
		    break;
		default:
		    TkMacOSXSetEatButtonUp(true);
		    BringWindowForward(medPtr->whichWin);
		    return false;
	    }
	}
d336 87
a422 97
	case inDrag: {
	    CGrafPtr saveWorld;
	    GDHandle saveDevice;
	    GWorldPtr dstPort;

	    GetGWorld(&saveWorld, &saveDevice);
	    dstPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin));
	    SetGWorld(dstPort, NULL);

	    DragWindow(medPtr->whichWin, where, NULL);
	    where2.h = where2.v = 0;
	    LocalToGlobal(&where2);
	    if (EqualPt(where, where2)) {
		SetGWorld (saveWorld, saveDevice);
		return false;
	    }
	    TkMacOSXWindowOffset(medPtr->whichWin, &xOffset, &yOffset);
	    where2.h -= xOffset;
	    where2.v -= yOffset;
	    TkGenWMConfigureEvent(tkwin, where2.h, where2.v,
		    -1, -1, TK_LOCATION_CHANGED);
	    SetGWorld(saveWorld, saveDevice);
	    return true;
	    break;
	}
	case inContent:
	    return TkGenerateButtonEvent(where.h, where.v, 
		    window, medPtr->state);
	    break;
	case inGrow:
	    /*
	     * Generally the content region is the domain of Tk
	     * sub-windows.  However, one exception is the grow	  
	     * region.	A button down in this area will be handled
	     * by the window manager.  Note: this means that Tk
	     * may not get button down events in this area!
	     */
	    if (TkMacOSXGrowToplevel(medPtr->whichWin, where) == true) {
		return true;
	    } else {
		return TkGenerateButtonEvent(where.h,
			where.v, window, medPtr->state);
	    }
	    break;
	case inGoAway:
	    return HandleInGoAway(tkwin, medPtr->whichWin, where);
	    break;
	case inMenuBar: {
	    int oldMode;
	    KeyMap theKeys;

	    GetKeys(theKeys);
	    oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
	    TkMacOSXClearMenubarActive();

	    /*
	     * Handle -postcommand
	     */

	    TkMacOSXPreprocessMenu();
	    TkMacOSXHandleMenuSelect(MenuSelect(where),
		    EndianS32_BtoN(*(long*)(&theKeys[1])) & 4);
	    Tcl_SetServiceMode(oldMode);
	    return true; /* TODO: may not be on event on queue. */
	    break;
	}
	case inZoomIn:
	case inZoomOut:
	    if (TkMacOSXZoomToplevel(medPtr->whichWin, where, 
			medPtr->windowPart) == true) {
		return true;
	    } else {
		return false;
	    }
	    break;
	case inCollapseBox:
	    /*
	     * The Appearance Manager handles collapsing for us,
	     * but we need to make sure we propagate the event in Tk.
	     */
	    if (TrackBox(medPtr->whichWin, where, inCollapseBox)) {
		TkpWmSetState((TkWindow *)tkwin, IconicState);
	    }
	    return false;
	    break;
	case inToolbarButton:
	    /*
	     * ToolbarButton attribute pressed while active
	     */
	    if (TrackBox(medPtr->whichWin, where, inToolbarButton)) {
		return TkMacOSXToolarbuttonEvent(medPtr, where);
	    }
	    return false;
	    break;
	default:
	    return false;
	    break;
d426 1
a426 1

d453 30
a482 1
    return false;
d484 1
a484 1

d556 1
d558 1
a558 1
/*
d562 1
a562 1
 *
d568 1
a568 1
 *
d571 1
a571 1
 *
d573 3
a575 3
 */

static void
d577 1
a577 1
{
d580 1
a580 1
	    SelectWindow(wRef);
d623 1
a623 1
    winPtr = (TkWindow *) tkwin;
d770 1
a770 1
    *mask_return = TkMacOSXButtonKeyState();
d813 1
a813 1

d818 1
a818 1

d827 1
a827 1

a839 66

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXToolarbuttonEvent --
 *
 *	Generates a "ToolbarButton" virtual event.
 *	This can be used to manage disappearing toolbars.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Places a virtual event on the event queue.
 *
 *----------------------------------------------------------------------
 */

static int
TkMacOSXToolarbuttonEvent(MouseEventData * medPtr, Point where)
{
    Tk_Window rootwin, tkwin = NULL;
    Window window;
    TkDisplay *dispPtr;
    TkWindow  *winPtr;
    XVirtualEvent event;
    CGrafPtr port;
    Rect     bounds;

    window = TkMacOSXGetXWindow(medPtr->whichWin);
    dispPtr = TkGetDisplayList();
    rootwin = Tk_IdToWindow(dispPtr->display, window);
    if (rootwin) {
	int local_x, local_y;
	tkwin = Tk_TopCoordsToWindow(rootwin,
		medPtr->local.h, medPtr->local.v, &local_x, &local_y);
    }
    if (!tkwin) {
       return true;
    }

    winPtr = (TkWindow *)tkwin;
    event.type = VirtualEvent;
    event.serial = LastKnownRequestProcessed(winPtr->display);
    event.send_event = false;
    event.display = winPtr->display;
    event.event = winPtr->window;
    event.root = XRootWindow(winPtr->display, 0);
    event.subwindow = None;
    event.time = TkpGetMS();

    event.x = where.h;
    event.y = where.v;

    GetMouse(&where);
    GetPort(&port);
    GetPortBounds(port, &bounds);
    event.x_root = where.h + bounds.left;
    event.y_root = where.v + bounds.top;
    event.state = medPtr->state;
    event.same_screen = true;
    event.name = Tk_GetUid("ToolbarButton");
    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);

    return true;
}
@


1.6.2.7
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
@d5 1
a5 1
 *	on MacOS X.
a51 2
 *
 * RCS: @@(#) $Id$
d63 2
a64 2
    WindowRef	   whichWin;
    WindowRef	   activeNonFloating;
d66 2
a67 2
    Point	   global;
    Point	   local;
d69 1
a69 2
    long	   delta;
    Window	   window;
d76 1
a76 1
static int gEatButtonUp = 0;	   /* 1 if we need to eat the next * up event */
d85 2
a86 4
static int GenerateButtonEvent(MouseEventData * medPtr);
static int GenerateToolbarButtonEvent(MouseEventData * medPtr);
static int HandleWindowTitlebarMouseDown(MouseEventData * medPtr, Tk_Window tkwin);
static unsigned int ButtonModifiers2State(UInt32 buttonState, UInt32 keyModifiers);
d96 2
a97 2
 *	  This routine processes the event in eventPtr, and
 *	  generates the appropriate Tk events from it.
d100 1
a100 1
 *	  True if event(s) are generated - false otherwise.
d103 1
a103 1
 *	  Additional events may be place on the Tk event queue.
d111 7
a117 5
    Tk_Window	   tkwin;
    Point	   where, where2;
    int		   xOffset, yOffset, result;
    TkDisplay *	   dispPtr;
    OSStatus	    status;
d119 2
d123 9
a131 9
	case kEventMouseUp:
	case kEventMouseDown:
	case kEventMouseMoved:
	case kEventMouseDragged:
	case kEventMouseWheelMoved:
	    break;
	default:
	    return 0;
	    break;
d134 4
a137 4
	    kEventParamMouseLocation,
	    typeQDPoint, NULL, 
	    sizeof(where), NULL,
	    &where);
d139 2
a140 1
	GetGlobalMouse(&where);
d142 38
a179 40
    status = GetEventParameter(eventPtr->eventRef, 
	    kEventParamWindowRef,
	    typeWindowRef, NULL, 
	    sizeof(WindowRef), NULL,
	    &medPtr->whichWin);
    if (status == noErr) {
	status = GetEventParameter(eventPtr->eventRef, 
		kEventParamWindowPartCode,
		typeWindowPartCode, NULL, 
		sizeof(WindowPartCode), NULL,
		&medPtr->windowPart);
    }
    if (status != noErr) {
	medPtr->windowPart = FindWindow(where, &medPtr->whichWin);
    }
    medPtr->window = TkMacOSXGetXWindow(medPtr->whichWin);
    if (medPtr->whichWin != NULL && medPtr->window == None) {
	return 0;
    }
    medPtr->state = ButtonModifiers2State(GetCurrentEventButtonState(),
            GetCurrentEventKeyModifiers());
    medPtr->global = where;
    status = GetEventParameter(eventPtr->eventRef, 
	    kEventParamWindowMouseLocation,
	    typeQDPoint, NULL, 
	    sizeof(Point), NULL,
	    &medPtr->local);
    if (status == noErr) {
	if (medPtr->whichWin) {
	    Rect widths;
	    GetWindowStructureWidths(medPtr->whichWin, &widths);
	    medPtr->local.h -=	widths.left;
	    medPtr->local.v -=	widths.top;	   
	}
    } else {
	medPtr->local = where;
	if (medPtr->whichWin) {
	    QDGlobalToLocalPoint(GetWindowPort(medPtr->whichWin),
	            &medPtr->local);
	}
d181 2
d192 6
a197 5
	if (TkMacOSXGetEatButtonUp()) {
	    TkMacOSXSetEatButtonUp(false);
	    return false;
	}
	return GenerateButtonEvent(medPtr);
d200 10
a209 10
	status = GetEventParameter(eventPtr->eventRef,
		kEventParamMouseWheelDelta,
		typeLongInteger, NULL,
		sizeof(long), NULL, &medPtr->delta);
	if (status != noErr ) {
	     fprintf (stderr,
		 "Failed to retrieve mouse wheel delta, %d\n", (int)status);
	     statusPtr->err = 1;
	     return false;
	 }
d213 1
a213 1
    tkwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
d220 14
d241 29
d274 1
a274 1
	 * This click moves the window forward.	 We don't want
d278 1
a278 1
	 
d308 33
a340 7
            if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) {
                return result;
            } else {
                TkMacOSXSetEatButtonUp(true);
                BringWindowForward(medPtr->whichWin);
                return false;
            }
a343 4
    
    if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) {
        return result;
    }
d371 2
a372 1
	    return GenerateButtonEvent(medPtr);
d385 2
a386 1
		return GenerateButtonEvent(medPtr);
d389 3
d394 1
d396 1
d406 1
a406 1
		    medPtr->state & Mod2Mask);
d411 28
d449 1
a449 1
 * HandleWindowTitlebarMouseDown --
d451 2
a452 1
 *	  Handle clicks in window titlebar.
d455 1
a455 2
 *	  1 if event was handled, 0 if event was not handled,
 *	  -1 if MouseDown was not in window titlebar. 
d458 1
a458 1
 *	  Additional events may be place on the Tk event queue.
a461 1

d463 1
a463 1
HandleWindowTitlebarMouseDown(MouseEventData * medPtr, Tk_Window tkwin)
d465 6
a470 33
    int result = 0;
    
    switch (medPtr->windowPart) {
        case inGoAway:
            if (TrackGoAway(medPtr->whichWin, medPtr->global)) {
                if (tkwin) {
                    TkGenWMDestroyEvent(tkwin);
                    result = 1;
                }
            }
            break;
        case inCollapseBox:
            if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
                if (tkwin) {
                    TkpWmSetState((TkWindow *)tkwin, IconicState);;
                    result = 1;
                }
            }
            break;
        case inZoomIn:
        case inZoomOut:
            if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
                result = TkMacOSXZoomToplevel(medPtr->whichWin, medPtr->windowPart);
            }
            break;
        case inToolbarButton:
            if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
                result = GenerateToolbarButtonEvent(medPtr);
            }
            break;
        default:
            result = -1;
            break;
d472 1
a472 2

    return result;
d480 3
a482 3
 *	  This function polls the mouse position and generates X Motion,
 *	  Enter & Leave events.	 The cursor is also updated at this
 *	  time.
d485 1
a485 1
 *	  True if event(s) are generated - false otherwise.  
d488 2
a489 2
 *	  Additional events may be place on the Tk event queue.
 *	  The cursor may be changed.
d498 1
d506 7
a512 7
	    && (medPtr->activeNonFloating != medPtr->whichWin))) {
	/*
	 * If the window for this event is not floating, and is not the
	 * active non-floating window, don't generate polling events.
	 * We don't send events to backgrounded windows.  So either send
	 * it to the grabWin, or NULL if there is no grabWin.
	 */
d514 1
a514 1
	tkwin = grabWin;
d516 6
a521 6
	/*
	 * First check whether the toplevel containing this mouse
	 * event is the grab window.  If not, then send the event
	 * to the grab window.	Otherwise, set tkWin to the subwindow  
	 * which most closely contains the mouse event.
	 */
d523 11
a533 10
	dispPtr = TkGetDisplayList();
	rootwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
	if ((rootwin == NULL) 
		|| ((grabWin != NULL) && (rootwin != grabWin))) {
	    tkwin = grabWin;
	} else {
	    tkwin = Tk_TopCoordsToWindow(rootwin, 
		    medPtr->local.h, medPtr->local.v, 
		    &local_x, &local_y);
	}
d542 1
a542 1
	    medPtr->state);
d552 2
a553 2
 *	Bring this background window to the front.  We also set state
 *	so Tk thinks the button is currently up.
d556 1
a556 1
 *	None.
d559 1
a559 1
 *	The window is brought forward.
a566 25
    do {
	ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
	Boolean		    flag;
	int		    err;
	
	err = GetFrontProcess(&frontPsn);
	if (err != noErr) {
	    fprintf(stderr, "GetFrontProcess failed, %d\n", err);
	    break;
	}
	err = SameProcess(&frontPsn, &ourPsn, &flag);
	if (err != noErr) {
	    fprintf(stderr, "SameProcess failed, %d\n", err);
	    break;
	} else {
	    if (!flag) {
		err = SetFrontProcess(&ourPsn);
		if (err != noErr) {
		    fprintf(stderr,"SetFrontProcess failed,%d\n", err);
		    break;
		}
	    }
	}
    } while (0);
    
d568 1
a568 1
	if (IsValidWindowPtr(wRef))
a571 16

/*
 *----------------------------------------------------------------------
 *
 * GenerateMouseWheelEvent --
 *
 *	Generates a "MouseWheel" Tk event.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Places a mousewheel event on the event queue.
 *
 *----------------------------------------------------------------------
 */
d577 1
d584 2
a585 2
	    && (medPtr->activeNonFloating != medPtr->whichWin))) {
	tkwin = NULL;
d587 10
a596 9
	dispPtr = TkGetDisplayList();
	rootwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
	if (rootwin == NULL) {
	    tkwin = NULL;
	} else {
	    tkwin = Tk_TopCoordsToWindow(rootwin, 
		    medPtr->local.h, medPtr->local.v, 
		    &local_x, &local_y);
	}
d607 1
a607 1
	tkwin = grabWin;
d624 1
a624 1

d631 2
a632 2
 *	Returns the flag indicating if we need to eat the
 *	next mouse up event
d635 1
a635 1
 *	  None.
a645 2
 *----------------------------------------------------------------------
 *
d649 1
a649 1
 *	  None.
d652 2
a653 2
 *	Sets the flag indicating if we need to eat the
 *	next mouse up event
a654 1
 *----------------------------------------------------------------------
d661 1
a661 1

d667 1
a667 1
 *	  Returns the current state of the button & modifier keys.
d670 3
a672 3
 *	  A bitwise inclusive OR of a subset of the following:
 *	  Button1Mask, ShiftMask, LockMask, ControlMask, Mod?Mask,
 *	  Mod?Mask.
d675 1
a675 1
 *	  None.
d683 6
a688 5
    UInt32 buttonState = 0, keyModifiers;
    EventRef ev = GetCurrentEvent();
    
    if (!gEatButtonUp) {
	buttonState = ev ? GetCurrentEventButtonState() : GetCurrentButtonState();
d690 2
a691 1
    keyModifiers = ev ? GetCurrentEventKeyModifiers() : GetCurrentKeyModifiers();
d693 1
a693 19
    return ButtonModifiers2State(buttonState, keyModifiers);
}

/*
 *----------------------------------------------------------------------
 *
 * ButtonModifiers2State --
 *
 *	Converts Carbon mouse button state and modifier values into a Tk
 *	button/modifier state.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */
d695 2
a696 10
static unsigned int
ButtonModifiers2State(UInt32 buttonState, UInt32 keyModifiers)
{
    unsigned int state;
    
    /* Tk supports at most 5 buttons */
    state = (buttonState & ((1<<5) - 1)) << 8;
    
    if (keyModifiers & alphaLock) { 
	state |= LockMask;
d698 3
a700 2
    if (keyModifiers & shiftKey) {
	state |= ShiftMask;
d702 3
a704 2
    if (keyModifiers & controlKey) {
	state |= ControlMask;
d706 3
a708 2
    if (keyModifiers & cmdKey) {
	state |= Mod1Mask;		/* command key */
d710 3
a712 8
    if (keyModifiers & optionKey) {
	state |= Mod2Mask;		/* option key */
    }
    if (keyModifiers & kEventKeyModifierNumLockMask) { 
	state |= Mod3Mask;
    }
    if (keyModifiers & kEventKeyModifierFnMask) { 
	state |= Mod4Mask;
d723 3
a725 3
 *	  Check the current state of the mouse.	 This is not a complete
 *	  implementation of this function.  It only computes the root
 *	  coordinates and the current mask.
d728 2
a729 2
 *	  Sets root_x_return, root_y_return, and mask_return.  Returns
 *	  true on success.
d732 1
a732 1
 *	  None.
d749 11
a759 22
    if (root_x_return && root_y_return) {
	Point where;
	EventRef ev;
	OSStatus status;

	if ((ev = GetCurrentEvent())) {
	    status = GetEventParameter(ev, 
		    kEventParamMouseLocation,
		    typeQDPoint, NULL, 
		    sizeof(where), NULL,
		    &where);
	}
	if (!ev || status != noErr) {
	    GetGlobalMouse(&where);
	}

	*root_x_return = where.h;
	*root_y_return = where.v;
    }
    if (mask_return) {
	*mask_return = TkMacOSXButtonKeyState();
    }
d762 2
a763 1

d769 3
a771 3
 *	  Given a global x & y position and the button key status this 
 *	  procedure generates the appropiate X button event.  It also 
 *	  handles the state changes needed to implement implicit grabs.
d774 1
a774 1
 *	  True if event(s) are generated - false otherwise.
d777 2
a778 2
 *	  Additional events may be place on the Tk event queue.
 *	  Grab state may also change.
d785 4
a788 40
    int x,		  /* X location of mouse */
    int y,		  /* Y location of mouse */
    Window window,	  /* X Window containing button event. */
    unsigned int state)	  /* Button Key state suitable for X event */
{
    MouseEventData med;
    
    bzero(&med, sizeof(MouseEventData));
    med.state = state;
    med.window = window;
    med.global.h = x;
    med.global.v = y;
    FindWindow(med.global, &med.whichWin);
    med.activeNonFloating = ActiveNonFloatingWindow();
    med.local = med.global;
    QDGlobalToLocalPoint(GetWindowPort(med.whichWin), &med.local);

    return GenerateButtonEvent(&med);
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateButtonEvent --
 *
 *	  Generate an X button event from a MouseEventData structure.
 *	  Handles the state changes needed to implement implicit grabs.
 *
 * Results:
 *	  True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	  Additional events may be place on the Tk event queue.
 *	  Grab state may also change.
 *
 *----------------------------------------------------------------------
 */

static int
GenerateButtonEvent(MouseEventData * medPtr)
d790 2
d798 1
a798 1
     * window.	ButtonUp events, however, may occur anywhere
d802 10
a811 6
    if (0  
	    && ((medPtr->activeNonFloating == NULL)
	    || ((!(TkpIsWindowFloating(medPtr->whichWin)) 
	    && (medPtr->activeNonFloating != medPtr->whichWin))
	    && TkMacOSXGetCapture() == NULL))) {
	return false;
d815 1
a815 1
    tkwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
d817 3
d821 2
a822 2
	tkwin = Tk_TopCoordsToWindow(tkwin, medPtr->local.h, medPtr->local.v, 
		&dummy, &dummy);
d825 1
a825 1
    Tk_UpdatePointer(tkwin, medPtr->global.h,  medPtr->global.v, medPtr->state);
d833 1
a833 1
 * GenerateToolbarButtonEvent --
d848 1
a848 1
GenerateToolbarButtonEvent(MouseEventData * medPtr)
d851 1
d855 2
d858 1
d860 1
a860 1
    rootwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
d862 1
d864 1
a864 1
		medPtr->local.h, medPtr->local.v, &event.x, &event.y);
d880 8
a887 2
    event.x_root = medPtr->global.h;
    event.y_root = medPtr->global.v;
@


1.6.2.8
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
@d53 1
a53 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.7 2005/08/09 07:40:01 das Exp $
d85 1
a85 1
static void BringWindowForward(WindowRef wRef, Boolean isFrontProcess);
a203 1
#ifdef TK_MAC_DEBUG
d205 1
a205 2
		 "Failed to retrieve mouse wheel delta, %d\n", (int) status);
#endif
d234 1
a234 9

	ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
	Boolean		    isFrontProcess = true;

	status = GetFrontProcess(&frontPsn);
	if (status == noErr) {
	    SameProcess(&frontPsn, &ourPsn, &isFrontProcess);
	}

d236 1
a236 2
		&& (medPtr->whichWin != medPtr->activeNonFloating
		|| !isFrontProcess)) {
d244 1
a244 3
		    BringWindowForward(GetWindowFromPort(
		            TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)),
		            isFrontProcess);
d255 1
a255 3
		BringWindowForward(GetWindowFromPort(
			TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)),
			isFrontProcess);
d268 1
a268 1
                BringWindowForward(medPtr->whichWin, isFrontProcess);
d274 1
d491 1
a491 1
BringWindowForward(WindowRef wRef, Boolean isFrontProcess)
d493 9
a501 7
    if (!isFrontProcess) {
	ProcessSerialNumber ourPsn = {0, kCurrentProcess};
	OSStatus status = SetFrontProcess(&ourPsn);
	if (status != noErr) {
#ifdef TK_MAC_DEBUG
	    fprintf(stderr,"SetFrontProcess failed, %d\n", (int) status);
#endif
d503 14
a516 1
    }
@


1.6.2.9
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
@d7 1
a7 5
 * Copyright 2001, Apple Computer, Inc.
 * Copyright (c) 2005 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.
d53 1
a53 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.8 2005/09/10 14:54:17 das Exp $
a63 7
#if !defined(MAC_OS_X_VERSION_10_3) || \
        (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3)
    /* Define constants only available on Mac OS X 10.3 or later */
    #define kEventParamWindowPartCode 'wpar'
    #define typeWindowPartCode        'wpar'
#endif

d79 1
a79 1
static int gEatButtonUp = 0;	   /* 1 if we need to eat the next up event */
d93 2
a94 2
static int TkMacOSXGetEatButtonUp();
static void TkMacOSXSetEatButtonUp(int f);
d335 17
d603 1
a603 1
static int
d623 1
a623 1
static void
@


1.6.2.10
log
@	* library/demos/cscroll.tcl: add MouseWheel bindings for aqua.

	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents):
	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent,
	GenerateMouseWheelEvent): add support for kEventMouseScroll events
	(smooth mouse wheel scrolling from mighty mouse or scrolling trackpad)
	by handling kEventMouseWheelMoved on application target as well as on
	dispatcher, in order to pick up synthesized MouseWheel events from
	HIObject handler (c.f. QA1453); add support for horizontal scrolling
	events by generating MouseWheel XEvent with Shift modifier.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.9 2005/11/27 02:36:46 das Exp $
d131 1
a131 1
    OSStatus	   status;
d211 2
a212 1
		kEventParamMouseWheelDelta, typeLongInteger, NULL,
d216 2
a217 2
	    fprintf (stderr,
		"Failed to retrieve mouse wheel delta, %d\n", (int) status);
d219 3
a221 11
	    statusPtr->err = 1;
	    return false;
	} else {
	    EventMouseWheelAxis axis;
	    status = GetEventParameter(eventPtr->eventRef,
		    kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL,
		    sizeof(EventMouseWheelAxis), NULL, &axis);
	    if (status == noErr && axis == kEventMouseWheelAxisX) {
		 medPtr->state |= ShiftMask;
	    }
	}
d229 1
a229 1
	 * MouseMoved, MouseDragged or MouseWheelMoved 
d233 1
a233 5
	    int res = GenerateMouseWheelEvent(medPtr);
	    if (res) {
		 statusPtr->stopProcessing = 1;
	    }
	    return res;
d537 1
d553 1
a553 1
		    &xEvent.xbutton.x, &xEvent.xbutton.y);
d568 1
a568 1
       return false;
d573 1
a573 3
    xEvent.xbutton.x_root = medPtr->global.h;
    xEvent.xbutton.y_root = medPtr->global.v;
    xEvent.xbutton.state = medPtr->state;
@


1.6.2.11
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
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.10 2005/12/13 03:44:42 das Exp $
d60 4
d65 1
a65 1
#include "tkMacOSXEvent.h"
@


1.6.2.12
log
@	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): fix return
	values, implement window dragging & growing in background (with Command
	key down) and by fronting clicks, use correct button & modifier state
	API when application is in background (also in TkMacOSXButtonKeyState).

	* macosx/tkMacOSXWm.c (TkMacOSXGrowToplevel): ensure QD port is set
	correctly before using API relying on it.

	* macosx/tkMacOSXMouseEvent.c: now that [wm attributes -titlepath]
	works correctly, add OS support for dragging proxy icons and
	using the titlepath menu.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.11 2006/03/28 02:44:13 das Exp $
a128 2
    ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
    Boolean	   isFrontProcess = true;
d138 1
a138 1
	    return false;
d166 1
a166 26
	return false;
    }
    if (eventPtr->eKind == kEventMouseDown) {
	if (IsWindowPathSelectEvent(medPtr->whichWin, eventPtr->eventRef)) {
	    status = WindowPathSelect(medPtr->whichWin, NULL, NULL);
	    return false;
	}
	if (medPtr->windowPart == inProxyIcon) {
	    status = TrackWindowProxyDrag(medPtr->whichWin, where);
	    if (status == errUserWantsToDragWindow) {
		medPtr->windowPart = inDrag;
	    } else {
		return false;
	    }
	}
    }
    status = GetFrontProcess(&frontPsn);
    if (status == noErr) {
	SameProcess(&frontPsn, &ourPsn, &isFrontProcess);
    }
    if (isFrontProcess) {
	medPtr->state = ButtonModifiers2State(GetCurrentEventButtonState(),
		GetCurrentEventKeyModifiers());
    } else {
	medPtr->state = ButtonModifiers2State(GetCurrentButtonState(),
		GetCurrentKeyModifiers());
d168 2
a204 3
    if (eventPtr->eKind == kEventMouseDown) {
	TkMacOSXSetEatButtonUp(false);
    }
d255 8
d294 2
a295 2
	     * Clicks in the titlebar widgets are handled without bringing the
	     * window forward.
d300 3
a302 17
		/*
		 * Allow background window dragging & growing with Command down
		 */
                if (!((medPtr->windowPart == inDrag ||
			medPtr->windowPart == inGrow) &&
			medPtr->state & Mod1Mask)) {
		    TkMacOSXSetEatButtonUp(true);
		    BringWindowForward(medPtr->whichWin, isFrontProcess);
                }
                /*
                 * Allow dragging & growing of windows that were/are in the
                 * background.
                 */
                if (!(medPtr->windowPart == inDrag ||
			medPtr->windowPart == inGrow)) {
		    return false;
                }
d304 22
a325 3
	} else {
	    if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) {
		return result;
d327 8
d336 12
a347 14
	switch (medPtr->windowPart) {
	    case inDrag:
		SetPort(GetWindowPort(medPtr->whichWin));
		DragWindow(medPtr->whichWin, where, NULL);
		where2.h = where2.v = 0;
		LocalToGlobal(&where2);
		if (EqualPt(where, where2)) {
		    return false;
		}
		TkMacOSXWindowOffset(medPtr->whichWin, &xOffset, &yOffset);
		where2.h -= xOffset;
		where2.v -= yOffset;
		TkGenWMConfigureEvent(tkwin, where2.h, where2.v,
			-1, -1, TK_LOCATION_CHANGED);
d349 1
a349 16
		break;
	    case inGrow:
		/*
		 * Generally the content region is the domain of Tk
		 * sub-windows.  However, one exception is the grow	  
		 * region.	A button down in this area will be handled
		 * by the window manager.  Note: this means that Tk
		 * may not get button down events in this area!
		 */
		if (TkMacOSXGrowToplevel(medPtr->whichWin, where) == true) {
		    return true;
		} else {
		    return GenerateButtonEvent(medPtr);
		}
		break;
	    case inContent:
d351 5
a355 5
		break;
	    default:
		return false;
		break;
	}
d357 1
a357 1
    return false;
d653 1
a653 9
    Boolean isFrontProcess = false;
    
    if (GetCurrentEvent()) {
	ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
	OSStatus status = GetFrontProcess(&frontPsn);
	if (status == noErr) {
	    SameProcess(&frontPsn, &ourPsn, &isFrontProcess);
	}
    }
d656 1
a656 2
	buttonState = isFrontProcess ? GetCurrentEventButtonState() :
		GetCurrentButtonState();
d658 1
a658 2
    keyModifiers = isFrontProcess ? GetCurrentEventKeyModifiers() :
	    GetCurrentKeyModifiers();
@


1.6.2.13
log
@typo
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.12 2006/04/07 06:16:03 das Exp $
d418 1
a418 1
                    TkpWmSetState((TkWindow *)tkwin, IconicState);
@


1.6.2.14
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
@d8 1
a8 1
 * Copyright (c) 2005-2006 Daniel A. Steffen <das@@users.sourceforge.net>
d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.13 2006/04/11 05:42:11 das Exp $
d120 1
a120 1
MODULE_SCOPE int
d778 3
a780 5
    int getGlobal = (root_x_return && root_y_return);
    int getLocal = (win_x_return && win_y_return);

    if (getGlobal || getLocal) {
	Point where, local;
a781 2
	int gotMouseLoc = 0;
	EventRef ev = GetCurrentEvent();
d783 1
a783 1
	if (ev && getLocal) {
d785 1
a785 1
		    kEventParamWindowMouseLocation,
d787 2
a788 3
		    sizeof(Point), NULL,
		    &local);
	    gotMouseLoc = (status == noErr);
d790 2
a791 45
	if (getGlobal || !gotMouseLoc) {
	    if (ev) {
		status = GetEventParameter(ev, 
			kEventParamMouseLocation,
			typeQDPoint, NULL, 
			sizeof(Point), NULL,
			&where);
	    }
	    if (!ev || status != noErr) {
		GetGlobalMouse(&where);
	    }
	}
	if (getLocal) {
	    WindowRef whichWin;
	    if (ev) {
		status = GetEventParameter(ev, 
			kEventParamWindowRef,
			typeWindowRef, NULL, 
			sizeof(WindowRef), NULL,
			&whichWin);
	    }
	    if (!ev || status != noErr) {
		FindWindow(where, &whichWin);
	    }
	    if (gotMouseLoc) {
		if (whichWin) {
		    Rect widths;
		    GetWindowStructureWidths(whichWin, &widths);
		    local.h -= widths.left;
		    local.v -= widths.top;	   
		}
	    } else {
		local = where;
		if (whichWin) {
		    QDGlobalToLocalPoint(GetWindowPort(whichWin), &local);
		}
	    }
	}
	if (getGlobal) {
	    *root_x_return = where.h;
	    *root_y_return = where.v;
	}
	if (getLocal) {
	    *win_x_return = local.h;
	    *win_y_return = local.v;
d793 3
a805 38
 * TkGenerateButtonEventForXPointer --
 *
 *	  This procedure generates an X button event for the current
 *	  pointer state as reported by XQueryPointer().
 *
 * Results:
 *	  True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	  Additional events may be place on the Tk event queue.
 *	  Grab state may also change.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE int
TkGenerateButtonEventForXPointer(
    Window window)	  /* X Window containing button event. */
{
    MouseEventData med;
    int global_x, global_y, local_x, local_y;
    
    bzero(&med, sizeof(MouseEventData));
    XQueryPointer(NULL, None, NULL, NULL, &global_x, &global_y,
	    &local_x, &local_y, &med.state);
    med.global.h = global_x;
    med.global.v = global_y;
    med.local.h = local_x;
    med.local.v = local_y;
    med.window = window;
    med.activeNonFloating = ActiveNonFloatingWindow();

    return GenerateButtonEvent(&med);
}

/*
 *----------------------------------------------------------------------
 *
d862 1
a862 1
static int
@


1.6.2.15
log
@	* macosx/tkMacOSXWm.c (WmAttributesCmd, WmIconbitmapCmd): add support
	for weakly importing symbols not available on OSX 10.2 or 10.3, enables
	binaires built on later OSX versions to run on earlier ones.
	* macosx/README: document how to enable weak-linking; cleanup.
	* unix/configure.in: enforce requirement of OSX 10.2 for TkAqua; move
	* unix/tcl.m4:       Darwin specific checks & defines that are only
	relevant to the tcl build out of tcl.m4; restrict framework option to
	Darwin; cleanup quoting.
	* unix/configure: autoconf-2.13

	* macosx/tkMacOSXKeyEvent.c: ifdef out diagnostic messages to stderr.

	* macosx/tkMacOSXEvent.h:      standardize MAC_OS_X_VERSION_MAX_ALLOWED
	* macosx/tkMacOSXMenu.c:       checks per QA1316, ensure define can be
	* macosx/tkMacOSXMenubutton.c: overriden on command line (from default
	* macosx/tkMacOSXMenus.c:      of current OS version).
	* macosx/tkMacOSXMouseEvent.c:
	* macosx/tkMacOSXWm.c:
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.14 2006/04/28 06:03:00 das Exp $
d64 2
a65 1
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
@


1.6.2.16
log
@	* unix/tcl.m4 (Darwin): add support for --enable-64bit on x86_64, for
	universal builds including x86_64, for 64-bit CoreFoundation on Leopard
	and for use of -mmacosx-version-min instead of MACOSX_DEPLOYMENT_TARGET.
	* unix/configure.in (Darwin): remove 64-bit arch flags from CFLAGS for
	combined 32-bit and 64-bit universal builds, as neither TkAqua nor TkX11
	can be built for 64-bit at present.
	* unix/configure: autoconf-2.13

	* macosx/README: updates for x86_64 support in Tcl.

	* macosx/tkMacOSXInit.c (TkpInit): when available, use public
	TransformProcessType() API instead of CPSEnableForegroundOperation() SPI
	to notify the window server that we are a GUI application.

	* macosx/tkMacOSXWm.c (WmAttrGetTitlePath): use HIWindow API on >=Tiger.

	* macosx/tkMacOSXMouseEvent.c (GenerateToolbarButtonEvent):
	* macosx/tkMacOSXMenus.c (GenerateEditEvent):
	* macosx/tkMacOSXMenu.c (MenuSelectEvent): bzero XVirtualEvent structure
	before use to ensure all fields are initialized. [Bug 1542205]
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.15 2006/07/20 06:27:34 das Exp $
d1012 1
a1013 2

    bzero(&event, sizeof(XVirtualEvent));
d1022 1
d1028 1
a1029 1
    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
@


1.6.2.17
log
@	* macosx/tkMacOSXColor.c (TkSetMacColor, TkpGetColor): use AppearanceMgr
	* macosx/tkMacOSXDefault.h: to retrieve platform std colors for text
	* macosx/tkMacOSXPort.h:    selections, add "systemHighlightSecondary"
	color name for standard color of inactive selections.

	* library/text.tcl (aqua): change focus bindings to implement platform
	standard look for inactive text selections using this new color.

	* generic/tkTextBTree.c (TkTextIsElided): on TkAqua, don't show text
	* generic/tkTextDisp.c (GetStyle):        selection when text widget
	* generic/tkText.c (TextEventProc):       is in disabled state.

	* generic/tkEntry.c (DisplayEntry): change default TkAqua selection
	* macosx/tkMacOSXDefault.h:         relief to "flat" (platform std).

	* generic/tkText.c (Tk_TextCmd): fix bug leading to default text
	selection relief string DEF_TEXT_SELECT_RELIEF being ignored.

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): allow mouse
	event delivery to background windows with kWindowNoActivatesAttribute
	(e.g. overrideredirect windows), as these never come to the foreground
	they would not receive any mouse events otherwise. [Bug 1472624]

	* macosx/tkMacOSXWindowEvent.c (TkMacOSXGenerateFocusEvent): do not
	send focus events to any windows with kWindowNoActivatesAttribute.

	* macosx/tkMacOSXXStubs.c (XQueryColor, XQueryColors): implement basic
	XColor computation from pixel values, enough to make tkImg's window.c
	happy, fixes img::window failures reported on tcl-mac.

	* macosx/tkMacOSXMenu.c (DrawMenuEntryLabel): fix leak. [Bug 1554672]

	* macosx/Makefile: workaround bug in 'cp -pRH' on Darwin 6 and earlier,
	fixes 'make embedded' failure reported on tcl-mac; fix error from 'make
	deploy' with same build tree as previous 'make embedded'.

	* macosx/tkMacOSXEntry.c (TkpDrawEntryBorderAndFocus): fix typo.

	* unix/tcl.m4: sync with tcl/unix/tcl.m4.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.16 2006/08/18 07:47:25 das Exp $
a60 1
#include "tkMacOSXWm.h"
d318 1
a318 7
            } else
		    /*
		     * Only windows with the kWindowNoActivatesAttribute can
		     * receive mouse events in the background.
		     */
		    if (!(((TkWindow *)tkwin)->wmInfoPtr->attributes &
			    kWindowNoActivatesAttribute)) {
@


1.6.2.18
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
@d8 1
a8 1
 * Copyright (c) 2005-2007 Daniel A. Steffen <das@@users.sourceforge.net>
d13 43
a55 43
 *	The following terms apply to all files originating from Apple
 *	Computer, Inc. ("Apple") and associated with the software
 *	unless explicitly disclaimed in individual files.
 *
 *
 *	Apple hereby grants permission to use, copy, modify,
 *	distribute, and license this software and its documentation
 *	for any purpose, provided that existing copyright notices are
 *	retained in all copies and that this notice is included
 *	verbatim in any distributions. No written agreement, license,
 *	or royalty fee is required for any of the authorized
 *	uses. Modifications to this software may be copyrighted by
 *	their authors and need not follow the licensing terms
 *	described here, provided that the new terms are clearly
 *	indicated on the first page of each file where they apply.
 *
 *
 *	IN NO EVENT SHALL APPLE, THE AUTHORS OR DISTRIBUTORS OF THE
 *	SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
 *	INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
 *	THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
 *	EVEN IF APPLE OR THE AUTHORS HAVE BEEN ADVISED OF THE
 *	POSSIBILITY OF SUCH DAMAGE.  APPLE, THE AUTHORS AND
 *	DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
 *	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 *	FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.	 THIS
 *	SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND APPLE,THE
 *	AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
 *	MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 *	GOVERNMENT USE: If you are acquiring this software on behalf
 *	of the U.S. government, the Government shall have only
 *	"Restricted Rights" in the software and related documentation
 *	as defined in the Federal Acquisition Regulations (FARs) in
 *	Clause 52.227.19 (c) (2).  If you are acquiring the software
 *	on behalf of the Department of Defense, the software shall be
 *	classified as "Commercial Computer Software" and the
 *	Government shall have only "Restricted Rights" as defined in
 *	Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the
 *	foregoing, the authors grant the U.S. Government and others
 *	acting in its behalf permission to use and distribute the
 *	software in accordance with the terms specified in this
 *	license.
d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.17 2006/09/10 17:07:36 das Exp $
d65 6
d75 2
a79 2
    Point	   global;
    Point	   local;
d100 1
a100 1
static int TkMacOSXGetEatButtonUp(void);
a102 1

d108 2
a109 2
 *	This routine processes the event in eventPtr, and
 *	generates the appropriate Tk events from it.
d112 1
a112 1
 *	True if event(s) are generated - false otherwise.
d115 1
a115 1
 *	Additional events may be place on the Tk event queue.
d123 5
a127 5
    Tk_Window tkwin;
    Point where, where2;
    int result;
    TkDisplay * dispPtr;
    OSStatus err;
d130 1
a130 1
    Boolean isFrontProcess = true;
d133 1
a134 1
	case kEventMouseUp:
d143 1
a143 1
    err = ChkErr(GetEventParameter, eventPtr->eventRef,
d145 1
a145 1
	    typeQDPoint, NULL,
d148 1
a148 1
    if (err != noErr) {
d151 1
a151 1
    err = ChkErr(GetEventParameter, eventPtr->eventRef,
d153 1
a153 1
	    typeWindowRef, NULL,
d156 2
a157 2
    if (err == noErr) {
	err = ChkErr(GetEventParameter, eventPtr->eventRef,
d159 1
a159 1
		typeWindowPartCode, NULL,
d163 1
a163 1
    if (err != noErr) {
d172 1
a172 1
	    ChkErr(WindowPathSelect, medPtr->whichWin, NULL, NULL);
d176 2
a177 4
	    TkMacOSXTrackingLoop(1);
	    err = ChkErr(TrackWindowProxyDrag, medPtr->whichWin, where);
	    TkMacOSXTrackingLoop(0);
	    if (err == errUserWantsToDragWindow) {
d184 3
a186 3
    err = ChkErr(GetFrontProcess, &frontPsn);
    if (err == noErr) {
	ChkErr(SameProcess, &frontPsn, &ourPsn, &isFrontProcess);
d196 1
a196 1
    err = ChkErr(GetEventParameter, eventPtr->eventRef,
d198 1
a198 1
	    typeQDPoint, NULL,
d201 1
a201 1
    if (err == noErr) {
d206 1
a206 1
	    medPtr->local.v -=	widths.top;
d212 1
a212 1
		    &medPtr->local);
d216 39
d259 3
a261 1
	int res = false;
d263 8
a270 36
	switch (eventPtr->eKind) {
	    case kEventMouseUp:
		/*
		 * The window manager only needs to know about mouse down
		 * events and sometimes we need to "eat" the mouse up.
		 * Otherwise, we just pass the event to Tk.
		 */
		if (TkMacOSXGetEatButtonUp()) {
		    TkMacOSXSetEatButtonUp(false);
		} else {
		    res = GenerateButtonEvent(medPtr);
		}
		break;
	    case kEventMouseWheelMoved:
		err = ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamMouseWheelDelta, typeLongInteger, NULL,
			sizeof(long), NULL, &medPtr->delta);
		if (err != noErr ) {
		    statusPtr->err = 1;
		} else {
		    EventMouseWheelAxis axis;
		    err = ChkErr(GetEventParameter, eventPtr->eventRef,
			    kEventParamMouseWheelAxis, typeMouseWheelAxis,
			    NULL, sizeof(EventMouseWheelAxis), NULL, &axis);
		    if (err == noErr && axis == kEventMouseWheelAxisX) {
			 medPtr->state |= ShiftMask;
		    }
		    res = GenerateMouseWheelEvent(medPtr);
		}
		break;
	    case kEventMouseMoved:
	    case kEventMouseDragged:
		res = GeneratePollingEvents(medPtr);
		break;
	    default:
		Tcl_Panic("Unknown mouse event !");
a271 4
	if (res) {
		statusPtr->stopProcessing = 1;
	}
	return res;
d273 1
a273 1
    TkMacOSXSetEatButtonUp(false);
d278 1
a278 1
	 * This click moves the window forward. We don't want
d287 1
a287 1
	    if (!grabWin) {
d294 2
a295 2
			    TkMacOSXGetDrawablePort(((TkWindow*)grabWin)->window)),
			    isFrontProcess);
d300 1
a300 1
	    if (grabWin && grabWin != tkwin) {
d317 3
a319 3
	    if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) {
		return result;
	    } else
d329 1
a329 1
		if (!((medPtr->windowPart == inDrag ||
d334 6
a339 6
		}
		/*
		 * Allow dragging & growing of windows that were/are in the
		 * background.
		 */
		if (!(medPtr->windowPart == inDrag ||
d342 2
a343 2
		}
	    }
d350 7
a356 15
	    case inDrag: {
		WindowAttributes attributes;

		GetWindowAttributes(medPtr->whichWin, &attributes);
		if (!(attributes & kWindowAsyncDragAttribute)) {
		    TkMacOSXTrackingLoop(1);
		    DragWindow(medPtr->whichWin, where, NULL);
		    TkMacOSXTrackingLoop(0);
		    where2.h = where2.v = 0;
		    QDLocalToGlobalPoint(GetWindowPort(medPtr->whichWin),
			    &where2);
		    if (EqualPt(where, where2)) {
			return false;
		    }
		    return true;
d358 6
a364 1
	    }
d368 3
a370 3
		 * sub-windows. However, one exception is the grow
		 * region. A button down in this area will be handled
		 * by the window manager. Note: this means that Tk
a373 1
		    statusPtr->stopProcessing = 1;
d395 1
a395 1
 *	Handle clicks in window titlebar.
d398 2
a399 2
 *	1 if event was handled, 0 if event was not handled,
 *	-1 if MouseDown was not in window titlebar.
d402 1
a402 1
 *	Additional events may be place on the Tk event queue.
d411 1
a411 2

    TkMacOSXTrackingLoop(1);
d413 30
a442 30
	case inGoAway:
	    if (TrackGoAway(medPtr->whichWin, medPtr->global)) {
		if (tkwin) {
		    TkGenWMDestroyEvent(tkwin);
		    result = 1;
		}
	    }
	    break;
	case inCollapseBox:
	    if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
		if (tkwin) {
		    TkpWmSetState((TkWindow *)tkwin, IconicState);
		    result = 1;
		}
	    }
	    break;
	case inZoomIn:
	case inZoomOut:
	    if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
		result = TkMacOSXZoomToplevel(medPtr->whichWin, medPtr->windowPart);
	    }
	    break;
	case inToolbarButton:
	    if (TrackBox(medPtr->whichWin, medPtr->global, medPtr->windowPart)) {
		result = GenerateToolbarButtonEvent(medPtr);
	    }
	    break;
	default:
	    result = -1;
	    break;
d444 1
a444 1
    TkMacOSXTrackingLoop(0);
d453 3
a455 3
 *	This function polls the mouse position and generates X Motion,
 *	Enter & Leave events. The cursor is also updated at this
 *	time.
d458 1
a458 1
 *	True if event(s) are generated - false otherwise.
d461 2
a462 2
 *	Additional events may be place on the Tk event queue.
 *	The cursor may be changed.
d477 1
a477 1
    if ((!TkpIsWindowFloating(medPtr->whichWin)
d482 1
a482 1
	 * We don't send events to backgrounded windows. So either send
d490 2
a491 2
	 * event is the grab window. If not, then send the event
	 * to the grab window. Otherwise, set tkWin to the subwindow
d494 1
a494 1

d497 1
a497 1
	if ((rootwin == NULL)
d501 2
a502 2
	    tkwin = Tk_TopCoordsToWindow(rootwin,
		    medPtr->local.h, medPtr->local.v,
d506 1
a506 1

d514 1
a514 1

d523 1
a523 1
 *	Bring this background window to the front. We also set state
d536 1
a536 3
BringWindowForward(
    WindowRef wRef,
    Boolean isFrontProcess)
d540 6
a545 2

	ChkErr(SetFrontProcess, &ourPsn);
d547 1
a547 1

d549 1
a549 1
	if (IsValidWindowPtr(wRef)) {
a550 1
	}
d573 1
a573 1
    Tk_Window tkwin, rootwin;
d576 1
a576 1
    XEvent xEvent;
d578 1
a578 1
    if ((!TkpIsWindowFloating(medPtr->whichWin)
d587 2
a588 2
	    tkwin = Tk_TopCoordsToWindow(rootwin,
		    medPtr->local.h, medPtr->local.v,
d592 1
a592 1

d598 4
a601 2
    if (!tkwin) {
	tkwin = TkMacOSXGetCapture();
d604 1
a604 1
	return false;
d631 1
a631 1
 *	None.
d635 2
a636 2
int
TkMacOSXGetEatButtonUp(void)
d647 1
a647 1
 *	None.
d655 1
a655 1
void
a663 36
 * TkMacOSXKeyModifiers --
 *
 *	Returns the current state of the modifier keys.
 *
 * Results:
 *	An OS Modifier state.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

EventModifiers
TkMacOSXModifierState(void)
{
    UInt32 keyModifiers;
    Boolean isFrontProcess = false;

    if (GetCurrentEvent()) {
	ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
	OSStatus err = ChkErr(GetFrontProcess, &frontPsn);

	if (err == noErr) {
	    ChkErr(SameProcess, &frontPsn, &ourPsn, &isFrontProcess);
	}
    }
    keyModifiers = isFrontProcess ? GetCurrentEventKeyModifiers() :
	    GetCurrentKeyModifiers();

    return (EventModifiers)(keyModifiers & USHRT_MAX);
}

/*
 *----------------------------------------------------------------------
 *
d666 1
a666 1
 *	Returns the current state of the button & modifier keys.
d669 3
a671 2
 *	A bitwise inclusive OR of a subset of the following:
 *	Button1Mask, ShiftMask, LockMask, ControlMask, Mod*Mask.
d674 1
a674 1
 *	None.
d680 1
a680 1
TkMacOSXButtonKeyState(void)
d684 1
a684 1

d687 3
a689 4
	OSStatus err = ChkErr(GetFrontProcess, &frontPsn);

	if (err == noErr) {
	    ChkErr(SameProcess, &frontPsn, &ourPsn, &isFrontProcess);
d692 2
a693 2

    if (!TkMacOSXGetEatButtonUp()) {
d699 1
a699 1

d724 1
a724 1

d727 2
a728 2

    if (keyModifiers & alphaLock) {
d743 1
a743 1
    if (keyModifiers & kEventKeyModifierNumLockMask) {
d746 1
a746 1
    if (keyModifiers & kEventKeyModifierFnMask) {
d758 3
a760 3
 *	Check the current state of the mouse. This is not a complete
 *	implementation of this function. It only computes the root
 *	coordinates and the current mask.
d763 2
a764 2
 *	Sets root_x_return, root_y_return, and mask_return. Returns
 *	true on success.
d767 1
a767 1
 *	None.
d789 1
a789 1
	OSStatus err = noErr;
d794 6
a799 3
	    err = ChkErr(GetEventParameter, ev, kEventParamWindowMouseLocation,
		    typeQDPoint, NULL, sizeof(Point), NULL, &local);
	    gotMouseLoc = (err == noErr);
d803 5
a807 2
		err = ChkErr(GetEventParameter, ev, kEventParamMouseLocation,
			typeQDPoint, NULL, sizeof(Point), NULL, &where);
d809 1
a809 1
	    if (!ev || err != noErr) {
d816 4
a819 2
		err = ChkErr(GetEventParameter, ev, kEventParamWindowRef,
			typeWindowRef, NULL, sizeof(WindowRef), NULL,
d822 1
a822 1
	    if (!ev || err != noErr) {
d828 1
a828 2

		    ChkErr(GetWindowStructureWidths, whichWin, &widths);
d830 1
a830 1
		    local.v -= widths.top;
d859 2
a860 2
 *	This procedure generates an X button event for the current
 *	pointer state as reported by XQueryPointer().
d863 1
a863 1
 *	True if event(s) are generated - false otherwise.
d866 2
a867 2
 *	Additional events may be place on the Tk event queue.
 *	Grab state may also change.
d878 1
a878 1

d897 3
a899 3
 *	Given a global x & y position and the button key status this
 *	procedure generates the appropiate X button event. It also
 *	handles the state changes needed to implement implicit grabs.
d902 1
a902 1
 *	True if event(s) are generated - false otherwise.
d905 2
a906 2
 *	Additional events may be place on the Tk event queue.
 *	Grab state may also change.
d919 1
a919 1

d938 2
a939 2
 *	Generate an X button event from a MouseEventData structure.
 *	Handles the state changes needed to implement implicit grabs.
d942 1
a942 1
 *	True if event(s) are generated - false otherwise.
d945 2
a946 2
 *	Additional events may be place on the Tk event queue.
 *	Grab state may also change.
d958 1
a958 2
#if UNUSED
    /*
d960 2
a961 2
     * window. ButtonUp events, however, may occur anywhere
     * on the screen. ButtonUp events should only be sent
d964 3
a966 2
    if ((medPtr->activeNonFloating == NULL)
	    || ((!(TkpIsWindowFloating(medPtr->whichWin))
d968 1
a968 1
	    && TkMacOSXGetCapture() == NULL)) {
a970 1
#endif
d976 1
a976 1
	tkwin = Tk_TopCoordsToWindow(tkwin, medPtr->local.h, medPtr->local.v,
d980 1
a980 1
    Tk_UpdatePointer(tkwin, medPtr->global.h, medPtr->global.v, medPtr->state);
d1017 1
a1017 1
	return true;
@


1.6.2.19
log
@	* macosx/tkMacOSXWindowEvent.c:	ensure window is brought to the front
	* macosx/tkMacOSXMouseEvent.c:	at the start of a window drag (except
	* macosx/tkMacOSXInt.h:		when cmd key is down); formatting and
					whitespace fixes.

	* macosx/tkMacOSXDialog.c (Tk_GetSaveFileObjCmd): add -filetypes option
	processing.

	* macosx/tkMacOSXEmbed.c (TkpMakeWindow, TkpUseWindow): fix sending of
	Visibility event for embedded windows (fixes frame-3.9 hang).

	* macosx/tkMacOSXScrlbr.c (ScrollbarBindProc):		fix testsuite
	* macosx/tkMacOSXSubwindows.c (TkMacOSXUpdateClipRgn):	crashes by
	adding sanity checks.

	* macosx/tkMacOSXButton.c: fix debug msg typo.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.18 2007/04/29 02:26:49 das Exp $
d307 16
a322 1
	    } else {
d324 2
a325 2
		 * Only windows with the kWindowNoActivatesAttribute can
		 * receive mouse events in the background.
d327 3
a329 20
		if (!(((TkWindow *)tkwin)->wmInfoPtr->attributes &
			kWindowNoActivatesAttribute)) {
		    /*
		     * Allow background window dragging & growing with Command
		     * down.
		     */
		    if (!((medPtr->windowPart == inDrag ||
			    medPtr->windowPart == inGrow) &&
			    medPtr->state & Mod1Mask)) {
			TkMacOSXSetEatButtonUp(true);
			BringWindowForward(medPtr->whichWin, isFrontProcess);
		    }
		    /*
		     * Allow dragging & growing of windows that were/are in the
		     * background.
		     */
		    if (!(medPtr->windowPart == inDrag ||
			    medPtr->windowPart == inGrow)) {
			return false;
		    }
d516 2
a517 1
 *	Bring this background window to the front.
a548 32
 * TkMacOSXBringWindowForward --
 *
 *	Bring this background window to the front (wrapper around
 *	BringWindowForward()).
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The window is brought forward.
 *
 *----------------------------------------------------------------------
 */

void
TkMacOSXBringWindowForward(
    WindowRef wRef)
{
    OSStatus err;
    ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
    Boolean isFrontProcess = true;

    err = ChkErr(GetFrontProcess, &frontPsn);
    if (err == noErr) {
	ChkErr(SameProcess, &frontPsn, &ourPsn, &isFrontProcess);
    }
    BringWindowForward(wRef, isFrontProcess);
}

/*
 *----------------------------------------------------------------------
 *
@


1.6.2.20
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
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.19 2007/05/09 12:57:46 das Exp $
d603 2
a604 3
    dispPtr = TkGetDisplayList();
    rootwin = Tk_IdToWindow(dispPtr->display, medPtr->window);
    if (rootwin == NULL) {
d607 9
a615 3
	tkwin = Tk_TopCoordsToWindow(rootwin,
		medPtr->local.h, medPtr->local.v,
		&xEvent.xbutton.x, &xEvent.xbutton.y);
@


1.6.2.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 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
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.20 2007/06/06 09:56:54 das Exp $
d60 1
a60 1
#include "tkMacOSXPrivate.h"
d281 3
a283 2
		    BringWindowForward(TkMacOSXDrawableWindow(
			    ((TkWindow*)grabWin)->window), isFrontProcess);
d294 3
a296 2
		BringWindowForward(TkMacOSXDrawableWindow(
			((TkWindow*)grabWin)->window), isFrontProcess);
@


1.6.2.22
log
@	* macosx/tkMacOSXWindowEvent.c (Tk_MacOSXIsAppInFront):	use process mgr
	* macosx/tkMacOSXMouseEvent.c:				to determine if
	app is in front instead of relying on activate/deactivate events (which
	may arrive after this info is needed, e.g. during window drag/click
	activation); replace other process mgr use to get this info with calls
	to Tk_MacOSXIsAppInFront().

	* macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): correct
	window click activation, titlebar click handling and background window
	dragging/growing in the presence of grabs or window-/app-modal windows;
	fix window click activation bringing all other app windows to front.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.21 2007/06/29 03:22:02 das Exp $
d86 1
a86 2
static void BringWindowForward(WindowRef wRef, int isFrontProcess,
	int frontWindowOnly);
a92 1
static Tk_Window GetGrabWindowForWindow(Tk_Window tkwin);
d124 2
a125 1
    int isFrontProcess;
d166 1
a166 2
	if (IsWindowActive(medPtr->whichWin) && IsWindowPathSelectEvent(
		medPtr->whichWin, eventPtr->eventRef)) {
d181 4
a184 1
    isFrontProcess = Tk_MacOSXIsAppInFront();
d274 5
a278 9
	    int frontWindowOnly = 1;
	    int cmdDragGrow = ((medPtr->windowPart == inDrag ||
		    medPtr->windowPart == inGrow) && medPtr->state & Mod1Mask);

	    if (!cmdDragGrow) {
		Tk_Window grabWin = GetGrabWindowForWindow(tkwin);

		frontWindowOnly = !grabWin;
		if (grabWin && grabWin != tkwin) {
d280 1
d282 2
a283 2
			    ((TkWindow*)grabWin)->window), isFrontProcess,
			    frontWindowOnly);
d287 11
a303 1
		statusPtr->stopProcessing = 1;
d316 3
a318 1
		    if (!cmdDragGrow) {
d320 1
a320 2
			BringWindowForward(medPtr->whichWin, isFrontProcess,
				frontWindowOnly);
a333 1
		statusPtr->stopProcessing = 1;
d402 1
a402 1
    int result = INT_MAX;
d404 1
d407 7
d415 7
d424 4
d429 2
a430 11
	    if (!IsWindowActive(medPtr->whichWin)) {
		WindowRef frontWindow = FrontNonFloatingWindow();
		WindowModality frontWindowModality = kWindowModalityNone;

		if (frontWindow && frontWindow != medPtr->whichWin) {
		    ChkErr(GetWindowModality, frontWindow,
			    &frontWindowModality, NULL);
		}
		if (frontWindowModality == kWindowModalityAppModal) {
		    result  = 0;
		}
d437 1
a437 36
    
    if (result == INT_MAX) {
	result = 0;
	TkMacOSXTrackingLoop(1);
	switch (medPtr->windowPart) {
	    case inGoAway:
		if (TrackGoAway(medPtr->whichWin, medPtr->global) && tkwin) {
		    TkGenWMDestroyEvent(tkwin);
		    result = 1;
		}
		break;
	    case inCollapseBox:
		if (TrackBox(medPtr->whichWin, medPtr->global,
			medPtr->windowPart) && tkwin) {
		    TkpWmSetState((TkWindow *)tkwin, IconicState);
		    result = 1;
		}
		break;
	    case inZoomIn:
	    case inZoomOut:
		if (TrackBox(medPtr->whichWin, medPtr->global,
			medPtr->windowPart)) {
		    result = TkMacOSXZoomToplevel(medPtr->whichWin,
			    medPtr->windowPart);
		}
		break;
	    case inToolbarButton:
		if (TrackBox(medPtr->whichWin, medPtr->global,
			medPtr->windowPart)) {
		    result = GenerateToolbarButtonEvent(medPtr);
		}
		break;
	}
	TkMacOSXTrackingLoop(0);
    }

d530 1
a530 2
    int isFrontProcess,
    int frontWindowOnly)
a531 13
    if (wRef && !TkpIsWindowFloating(wRef) && IsValidWindowPtr(wRef)) {
	WindowRef frontWindow = FrontNonFloatingWindow();
	WindowModality frontWindowModality = kWindowModalityNone;
	
	if (frontWindow && frontWindow != wRef) {
	    ChkErr(GetWindowModality, frontWindow, &frontWindowModality, NULL);
	}
	if (frontWindowModality != kWindowModalityAppModal) {
	    SelectWindow(wRef);
	} else {
	    frontWindowOnly = 0;
	}
    }
d535 7
a541 2
	ChkErr(SetFrontProcessWithOptions, &ourPsn, frontWindowOnly ?
	    kSetFrontProcessFrontWindowOnly : 0);
d550 2
a551 2
 *	Bring this window to the front in response to a mouse click. If
 *	a grab is in effect, bring the grab window to the front instead.
d566 3
a568 3
    TkDisplay *dispPtr = TkGetDisplayList();
    Tk_Window tkwin = Tk_IdToWindow(dispPtr->display,TkMacOSXGetXWindow(wRef));
    Tk_Window grabWin = GetGrabWindowForWindow(tkwin);
d570 3
a572 2
    if (grabWin && grabWin != tkwin) {
	wRef = TkMacOSXDrawableWindow(((TkWindow*)grabWin)->window);
d574 1
a574 35
    TkMacOSXSetEatButtonUp(true);
    BringWindowForward(wRef, Tk_MacOSXIsAppInFront(), !grabWin);
}

/*
 *----------------------------------------------------------------------
 *
 * GetGrabWindowForWindow --
 *
 *	Get the grab window for the given window, if any.
 *
 * Results:
 *	Grab Tk_Window or None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
GetGrabWindowForWindow(
    Tk_Window tkwin) 
{
    Tk_Window grabWin = TkMacOSXGetCapture();

    if (!grabWin) {
	int grabState = TkGrabState((TkWindow*)tkwin);

	if (grabState != TK_GRAB_NONE && grabState != TK_GRAB_IN_TREE) {
	    grabWin = (Tk_Window) (((TkWindow*)tkwin)->dispPtr->grabWinPtr);
	}
    }
    
    return grabWin;
d697 5
a701 1
    int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront());
d703 4
d734 10
a743 1
    int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront());
@


1.6.2.23
log
@	* macosx/tkMacOSXWm.c (ApplyMasterOverrideChanges): Revert 2007-10-26
	change to window class of transient toplevels that are not also
	overrideredirect. [Bug 1845899]

	* macosx/tkMacOSXWm.c (ApplyMasterOverrideChanges): Implement more
	* macosx/tkMacOSXMouseEvent.c (BringWindowForward): X11-like transient
	* macosx/tkMacOSXSubwindows.c (XDestroyWindow):     behaviour by adding
	transient windows to a window group owned by the master window, this
	ensures transients always remain in front of and are collapsed with the
	master; bring master to front when selecting transient windows; restore
	default window group of transients if master destroyed. [Bug 1845899]
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXMouseEvent.c,v 1.6.2.22 2007/07/09 08:32:12 das Exp $
a557 23
	    Window window = TkMacOSXGetXWindow(wRef);

	    if (window != None) {
		TkDisplay *dispPtr = TkGetDisplayList();
		TkWindow * winPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display,
			window);

		if (winPtr && winPtr->wmInfoPtr &&
			winPtr->wmInfoPtr->master != None) {
		    TkWindow *masterWinPtr = (TkWindow *)Tk_IdToWindow(
			    dispPtr->display, winPtr->wmInfoPtr->master);

		    if (masterWinPtr && masterWinPtr->window != None &&
			    TkMacOSXHostToplevelExists(masterWinPtr)) {
			WindowRef masterMacWin =
				TkMacOSXDrawableWindow(masterWinPtr->window);

			if (masterMacWin) {
			    BringToFront(masterMacWin);
			}
		    }
		}
	    }
@


1.5
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
@d473 1
a473 1
    Tk_Window tkwin, rootwin, grabWin;
d478 3
a480 8
    /* 
     * I really do not understand this complicated logic.  Surely the event
     * should be to either: (1) medPtr->whichWin, the window under the mouse
     * (from which we then obviously extract the correct Tk subwindow), or
     * (2) the current grab window.  I really don't see why anything else is
     * relevant.
     */
#if 0
d483 8
a490 1
        tkwin = NULL;
d492 7
d502 3
a504 2
        if (rootwin == NULL) {
            tkwin = NULL;
a516 22
    grabWin = TkMacOSXGetCapture();

    if ((tkwin == NULL) && (grabWin != NULL)) {
        tkwin = grabWin;
    }
#else
    grabWin = TkMacOSXGetCapture();
    if (grabWin != NULL) {
	tkwin = grabWin;
    } else {
	window = TkMacOSXGetXWindow(medPtr->whichWin);
	dispPtr = TkGetDisplayList();
	rootwin = Tk_IdToWindow(dispPtr->display, window);
	if (rootwin == NULL) {
	    tkwin = NULL;
	} else {
	    tkwin = Tk_TopCoordsToWindow(rootwin, 
		    medPtr->local.h, medPtr->local.v, 
		    &local_x, &local_y);
	}
    }
#endif
@


1.4
log
@2003-02-10  Jim Ingham <jingham@@apple.com>

        * macosx/tkMacOSXCursor.c (TkMacOSXInstallCursor): Set all theme
        cursors using SetThemeCursor or SetAnimatedThemeCursors.
        (TkGetCursorByName): Use the theme cursors for arrow, ibeam, etc.
        Allow animatedCursor{NUM} form for an animated cursor with count.
        (TkpSetCursor): Don't reset the cursor if there is no change.
        * macosx/tkMacOSXMouseEvent.c (GeneratePollingEvents): Don't
        directly call TkMacOSXInstallCursor, it gets called by the call
        to Tk_UpdatePointer immediately above.
@
text
@d85 2
a128 1
            statusPtr->handledByTk = 1;
a131 1
    statusPtr->handledByTk = 1;
a174 1
        statusPtr->handledByTk = 0;
d281 29
a309 3
             TkMacOSXSetEatButtonUp(true);
             BringWindowForward(medPtr->whichWin);
             return false;
d348 1
a348 8
            if (TrackGoAway(medPtr->whichWin,where)) {
                if (tkwin == NULL) {
                    return false;
                }
                TkGenWMDestroyEvent(tkwin);
                return true;
            }
            return false;
d380 6
a385 6
             if ((err = CollapseWindow(medPtr->whichWin,
                 !IsWindowCollapsed(medPtr->whichWin)))!=noErr) {
                 fprintf(stderr,"CollapseWindow failed,%d\n", err);
                 statusPtr->err = 1;
             }
             break;
d392 59
a450 1

@


1.3
log
@	* library/tk.tcl: use command instead of control on Aqua bindings.
	Force dialogs to appear below fixed native Mac menubar.
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXKeyboard.c: Keypress/release events for pure
	modifier keys were not being passed to Tk.
	Deadkey presses were inserting null characters into text windows.
	Now they do nothing. (Still not ideal, but better than before!)
	* macosx/tkMacOSXMenu.c: Allow more than 200 menus to exist -
	increased to 2000.
	* macosx/tkMacOSXMouseEvent.c: Bad interactions between floating
	windows and ordinary ones.  Ensure that local<->global coordinate
	transformations are wrt to the correct window.
	* macosx/tkMacOSXWm.c: Better error msg for 'wm attributes'.
	Remove crash in 'wm transient'.
	Add 'noActivates' and 'noUpdates' flags to unsupported command.
	[Patch #606658] (darley)
@
text
@a455 3

    TkMacOSXInstallCursor(0);

d737 1
a737 1
}@


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
@d218 11
a228 1
        SetPortWindowPort(frontWindow);
d402 8
a409 1
 
d436 17
d720 1
a720 1
    if ((frontWin == NULL) || ((!(TkpIsWindowFloating(whichWin)) 
d722 1
a722 1
            && TkMacOSXGetCapture() == NULL)) {
d729 2
@


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


1.1.2.1
log
@First checkin of support for Tk on Mac OS X.
@
text
@a0 701
/*
 * tkMacOSXMouseEvent.c --
 *
 *	This file implements functions that decode & handle mouse events
 *      on MacOS X.
 *
 *      Copyright 2001, Apple Computer, Inc.
 *
 *      The following terms apply to all files originating from Apple
 *      Computer, Inc. ("Apple") and associated with the software
 *      unless explicitly disclaimed in individual files.
 *
 *
 *      Apple hereby grants permission to use, copy, modify,
 *      distribute, and license this software and its documentation
 *      for any purpose, provided that existing copyright notices are
 *      retained in all copies and that this notice is included
 *      verbatim in any distributions. No written agreement, license,
 *      or royalty fee is required for any of the authorized
 *      uses. Modifications to this software may be copyrighted by
 *      their authors and need not follow the licensing terms
 *      described here, provided that the new terms are clearly
 *      indicated on the first page of each file where they apply.
 *
 *
 *      IN NO EVENT SHALL APPLE, THE AUTHORS OR DISTRIBUTORS OF THE
 *      SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
 *      INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
 *      THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
 *      EVEN IF APPLE OR THE AUTHORS HAVE BEEN ADVISED OF THE
 *      POSSIBILITY OF SUCH DAMAGE.  APPLE, THE AUTHORS AND
 *      DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
 *      BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 *      FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS
 *      SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND APPLE,THE
 *      AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
 *      MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 *      GOVERNMENT USE: If you are acquiring this software on behalf
 *      of the U.S. government, the Government shall have only
 *      "Restricted Rights" in the software and related documentation
 *      as defined in the Federal Acquisition Regulations (FARs) in
 *      Clause 52.227.19 (c) (2).  If you are acquiring the software
 *      on behalf of the Department of Defense, the software shall be
 *      classified as "Commercial Computer Software" and the
 *      Government shall have only "Restricted Rights" as defined in
 *      Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the
 *      foregoing, the authors grant the U.S. Government and others
 *      acting in its behalf permission to use and distribute the
 *      software in accordance with the terms specified in this
 *      license.
 */

#include "tkInt.h"
#include <X11/X.h>
#include <X11/Xlib.h>
#include "tkMacOSXEvent.h"
#include <tcl.h>
#include "tkMacOSXInt.h"
#include "tkPort.h"
#include "tkMacOSXDebug.h"

typedef struct {
    WindowRef      whichWin;
    WindowRef      activeNonFloating;
    WindowPartCode windowPart;
    Point          global;
    Point          local;   
    unsigned int   state;
    long           delta;
} MouseEventData;

/*
 * Declarations of static variables used in this file.
 */

static int gEatButtonUp = 0;       /* 1 if we need to eat the next * up event */

/*
 * Declarations of functions used only in this file.
 */

static void BringWindowForward _ANSI_ARGS_((WindowRef wRef));
static int GeneratePollingEvents(MouseEventData * medPtr);
static int GenerateMouseWheelEvent(MouseEventData * medPtr);

extern int TkMacOSXGetEatButtonUp();
extern void TkMacOSXSetEatButtonUp(int f);

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessMouseEvent --
 *
 *        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
TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
{
    WindowRef      frontWindow;
    Tk_Window      tkwin;
    Point          where, where2;
    int            xOffset, yOffset;
    TkDisplay *    dispPtr;
    Window         window;
    int            status,err;
    MouseEventData mouseEventData, * medPtr = &mouseEventData;
    KeyMap         keyMap;

    switch (eventPtr->eKind) {
        case kEventMouseUp:
        case kEventMouseDown:
        case kEventMouseMoved:
        case kEventMouseDragged:
        case kEventMouseWheelMoved:
            break;
        default:
            statusPtr->handledByTk = 1;
            return 0;
            break;
    }
    statusPtr->handledByTk = 1;
    status = GetEventParameter(eventPtr->eventRef, 
            kEventParamMouseLocation,
            typeQDPoint, NULL, 
            sizeof(where), NULL,
            &where);
    if (status != noErr) {
        fprintf (stderr, "Failed to retrieve mouse location,%d\n", status);
        return 0;
    }
    medPtr->state = 0;
    GetKeys(keyMap);
    if (keyMap[1] & 2) { 
        medPtr->state |= LockMask;
    }
    if (keyMap[1] & 1) {
        medPtr->state |= ShiftMask;
    }
    if (keyMap[1] & 8) {
        medPtr->state |= ControlMask;
    }
    if (keyMap[1] & 32768) {
        medPtr->state |= Mod1Mask;              /* command key */
    }
    if (keyMap[1] & 4) {
        medPtr->state |= Mod2Mask;              /* option key */
    }
    if (eventPtr->eKind == kEventMouseDown 
            || eventPtr->eKind== kEventMouseDragged ) {
        EventMouseButton mouseButton;
        if ((status=GetEventParameter(eventPtr->eventRef,
             kEventParamMouseButton,
             typeMouseButton, NULL,
             sizeof(mouseButton), NULL,&mouseButton)) != noErr ) {
             fprintf (stderr, "Failed to retrieve mouse button, %d\n", status);
             statusPtr->err = 1;
             return 0;
         }
         medPtr->state |= 1 << ((mouseButton-1)+8);
    }

    medPtr->windowPart= FindWindow(where, &medPtr->whichWin);
    window = TkMacOSXGetXWindow(medPtr->whichWin);
       
    frontWindow = FrontWindow();
    medPtr->activeNonFloating = ActiveNonFloatingWindow();

    /*
     * The window manager only needs to know about mouse down events
     * and sometimes we need to "eat" the mouse up.  Otherwise, we
     * just pass the event to Tk.

     */
    if (eventPtr->eKind == kEventMouseUp) {
        if (TkMacOSXGetEatButtonUp()) {
            TkMacOSXSetEatButtonUp(false);
            return false;
        }
        return TkGenerateButtonEvent(where.h, where.v,
            window, medPtr->state);
    }
    if (eventPtr->eKind == kEventMouseWheelMoved) {
        if ((status=GetEventParameter(eventPtr->eventRef,
             kEventParamMouseWheelDelta,
             typeLongInteger, NULL,
             sizeof(medPtr->delta), NULL,&medPtr->delta)) != noErr ) {
             fprintf (stderr,
                 "Failed to retrieve mouse wheel delta, %d\n", status);
             statusPtr->err = 1;
             return false;
         }
    }
    
    dispPtr = TkGetDisplayList();
    tkwin = Tk_IdToWindow(dispPtr->display, window);

    if (eventPtr->eKind != kEventMouseDown ) {
        /* 
         * MouseMoved, MouseDragged or kEventMouseWheelMoved 
         */
         
        medPtr->global = where;
        medPtr->local = where;
        SetPortWindowPort(frontWindow);
        GlobalToLocal(&medPtr->local);
        if (eventPtr->eKind == kEventMouseWheelMoved ) {
            return GenerateMouseWheelEvent(medPtr); 
        } else {
            return GeneratePollingEvents(medPtr); 
        }
    }

    if (medPtr->whichWin && eventPtr->eKind==kEventMouseDown) {
        ProcessSerialNumber frontPsn, ourPsn;
        Boolean             flag;
        if ((err=GetFrontProcess(&frontPsn))!=noErr) {
            fprintf(stderr, "GetFrontProcess failed, %d\n", err);
            statusPtr->err = 1;
            return 1;
        }
        
        GetCurrentProcess(&ourPsn);
        if ((err=SameProcess(&frontPsn, &ourPsn, &flag))!=noErr) {
            fprintf(stderr, "SameProcess failed, %d\n", err);
            statusPtr->err = 1;
            return 1;
        } else {
            if (!flag) {
                if ((err=SetFrontProcess(&ourPsn)) != noErr) {
                    fprintf(stderr,"SetFrontProcess failed,%d\n", err);
                    statusPtr->err = 1;
                    return 1;
                }
            }
        }

    }

    if (medPtr->whichWin) {
        /*
         * We got a mouse down in a window
         * See if this is the activate click
         * This click moves the window forward.  We don't want
         * the corresponding mouse-up to be reported to the application
         * or else it will mess up some Tk scripts.
         */
         
         if (!(TkpIsWindowFloating(medPtr->whichWin))
             && (medPtr->whichWin != medPtr->activeNonFloating)) {
             Tk_Window grabWin = TkMacOSXGetCapture();
             if ((grabWin != NULL) && (grabWin != tkwin)) {
                 TkWindow * tkw, * grb;
                 tkw = (TkWindow *)tkwin;
                 grb = (TkWindow *)grabWin;
                 SysBeep(1);  
                 return false;
             }
             TkMacOSXSetEatButtonUp(true);
             BringWindowForward(medPtr->whichWin);
             return false;
         }
    }

    switch (medPtr->windowPart) {
        case inDrag:
            DragWindow(medPtr->whichWin, where, NULL);
            where2.h = where2.v = 0;
            LocalToGlobal(&where2);
            if (EqualPt(where, where2)) {
                return false;
            }
            TkMacOSXWindowOffset(medPtr->whichWin, &xOffset, &yOffset);
            where2.h -= xOffset;
            where2.v -= yOffset;
            TkGenWMConfigureEvent(tkwin, where2.h, where2.v,
                    -1, -1, TK_LOCATION_CHANGED);
            return true;
            break;
        case inContent:
            return TkGenerateButtonEvent(where.h, where.v, 
                    window, medPtr->state);
            break;
        case inGrow:
            /*      
             * Generally the content region is the domain of Tk
             * sub-windows.  However, one exception is the grow   
             * region.  A button down in this area will be handled
             * by the window manager.  Note: this means that Tk
             * may not get button down events in this area!
             */
            if (TkMacOSXGrowToplevel(medPtr->whichWin, where) == true) {
                return true;
            } else {
                return TkGenerateButtonEvent(where.h,
                           where.v, window, medPtr->state);
            }
            break;
        case inGoAway:
            if (TrackGoAway(medPtr->whichWin,where)) {
                if (tkwin == NULL) {
                    return false;
                }
                TkGenWMDestroyEvent(tkwin);
                return true;
            }
            return false;
            break;
        case inMenuBar:
            {
                int oldMode;
                KeyMap theKeys;

                GetKeys(theKeys);
                oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
                TkMacOSXClearMenubarActive();
                
                /*
                 * Handle -postcommand
                 */
                 
                TkMacOSXPreprocessMenu();
                TkMacOSXHandleMenuSelect(MenuSelect(where),
                        theKeys[1] & 4);
                Tcl_SetServiceMode(oldMode);
                return true; /* TODO: may not be on event on queue. */
            }
            break;
        case inZoomIn:
        case inZoomOut:
            if (TkMacOSXZoomToplevel(medPtr->whichWin, where, 
                    medPtr->windowPart) == true) {
                return true;
            } else {
                return false;
            }
            break;
        case inCollapseBox:
             if ((err = CollapseWindow(medPtr->whichWin,
                 !IsWindowCollapsed(medPtr->whichWin)))!=noErr) {
                 fprintf(stderr,"CollapseWindow failed,%d\n", err);
                 statusPtr->err = 1;
             }
             break;
        default:
            return false;
            break;
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * GeneratePollingEvents --
 *
 *        This function polls the mouse position and generates X Motion,
 *        Enter & Leave events.  The cursor is also updated at this
 *        time.
 *
 * Results:
 *        True if event(s) are generated - false otherwise.  
 *
 * Side effects:
 *        Additional events may be place on the Tk event queue.
 *        The cursor may be changed.
 *
 *----------------------------------------------------------------------
 */

static int
GeneratePollingEvents(MouseEventData * medPtr)
{
    Tk_Window tkwin, rootwin, grabWin;
    Window window;
    int local_x, local_y;
    TkDisplay *dispPtr;

 
    if ((!TkpIsWindowFloating(medPtr->whichWin) 
            && (medPtr->activeNonFloating != medPtr->whichWin))) {
        tkwin = NULL;
    } else {
        window = TkMacOSXGetXWindow(medPtr->whichWin);
        dispPtr = TkGetDisplayList();
        rootwin = Tk_IdToWindow(dispPtr->display, window);
        if (rootwin == NULL) {
            tkwin = NULL;
        } else {
            tkwin = Tk_TopCoordsToWindow(rootwin, 
                    medPtr->local.h, medPtr->local.v, 
                    &local_x, &local_y);
        }
    }
    
    /*
     * The following call will generate the appropiate X events and
     * adjust any state that Tk must remember.
     */

    grabWin = TkMacOSXGetCapture();

    if ((tkwin == NULL) && (grabWin != NULL)) {
        tkwin = grabWin;
    }
    Tk_UpdatePointer(tkwin, medPtr->global.h, medPtr->global.v,
            medPtr->state);
    

    TkMacOSXInstallCursor(0);

    return true;
}


/*           
 *----------------------------------------------------------------------
 *
 * BringWindowForward --
 *           
 *      Bring this background window to the front.  We also set state
 *      so Tk thinks the button is currently up.
 *
 * Results:
 *      None.
 *      
 * Side effects:
 *      The window is brought forward.
 *          
 *----------------------------------------------------------------------
 */         
  
static void     
BringWindowForward(WindowRef wRef)
{           
    if (!TkpIsWindowFloating(wRef)) {
        if (IsValidWindowPtr(wRef))
        SelectWindow(wRef);
    }
}

static int
GenerateMouseWheelEvent(MouseEventData * medPtr)
{
    Tk_Window tkwin, rootwin, grabWin;
    Window window;
    int local_x, local_y;
    TkDisplay *dispPtr;
    TkWindow  *winPtr;
    XEvent     xEvent;

    if ((!TkpIsWindowFloating(medPtr->whichWin) 
            && (medPtr->activeNonFloating != medPtr->whichWin))) {
        tkwin = NULL;
    } else {
        window = TkMacOSXGetXWindow(medPtr->whichWin);
        dispPtr = TkGetDisplayList();
        rootwin = Tk_IdToWindow(dispPtr->display, window);
        if (rootwin == NULL) {
            tkwin = NULL;
        } else {
            tkwin = Tk_TopCoordsToWindow(rootwin, 
                    medPtr->local.h, medPtr->local.v, 
                    &local_x, &local_y);
        }
    }
    
    /*
     * The following call will generate the appropiate X events and
     * adjust any state that Tk must remember.
     */

    grabWin = TkMacOSXGetCapture();

    if ((tkwin == NULL) && (grabWin != NULL)) {
        tkwin = grabWin;
    }
    if (!tkwin) {
       return true;
    }
    winPtr = ( TkWindow *)tkwin;
    xEvent.type = MouseWheelEvent;
    xEvent.xkey.keycode = medPtr->delta;
    xEvent.xany.serial = LastKnownRequestProcessed(winPtr->display);
    xEvent.xany.send_event = false;
    xEvent.xany.display = winPtr->display;
    xEvent.xany.window = Tk_WindowId(winPtr);
    Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);

    return true;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGetEatButtonUp --
 *
 * Results:
 *      Returns the flag indicating if we need to eat the
 *      next mouse up event
 *
 * Side effects:
 *        None.
 *
 *----------------------------------------------------------------------
 */
int
TkMacOSXGetEatButtonUp()
{
    return gEatButtonUp;
}

/*
 * TkMacOSXSetEatButtonUp --
 *
 * Results:
 *        None.
 *
 * Side effects:
 *      Sets the flag indicating if we need to eat the
 *      next mouse up event
 *
 */
void
TkMacOSXSetEatButtonUp(int f)
{
    gEatButtonUp = f;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXButtonKeyState --
 *
 *        Returns the current state of the button & modifier keys.
 *
 * Results:
 *        A bitwise inclusive OR of a subset of the following:
 *        Button1Mask, ShiftMask, LockMask, ControlMask, Mod?Mask,
 *        Mod?Mask.
 *
 * Side effects:
 *        None.
 *
 *----------------------------------------------------------------------
 */

unsigned int
TkMacOSXButtonKeyState()
{
    unsigned int state = 0;
    KeyMap theKeys;

    if (Button() & !gEatButtonUp) {
        state |= Button1Mask;
    }

    GetKeys(theKeys);

    if (theKeys[1] & 2) {
        state |= LockMask;
    }

    if (theKeys[1] & 1) {
        state |= ShiftMask;
    }

    if (theKeys[1] & 8) {
        state |= ControlMask;
    }

    if (theKeys[1] & 32768) {
        state |= Mod1Mask;                /* command key */
    }

    if (theKeys[1] & 4) {
        state |= Mod2Mask;                /* option key */
    }

    return state;
}

/*
 *----------------------------------------------------------------------
 *
 * XQueryPointer --
 *
 *        Check the current state of the mouse.  This is not a complete
 *        implementation of this function.  It only computes the root
 *        coordinates and the current mask.
 *
 * Results:
 *        Sets root_x_return, root_y_return, and mask_return.  Returns
 *        true on success.
 *
 * Side effects:
 *        None.
 *
 *----------------------------------------------------------------------
 */

Bool
XQueryPointer(
    Display* display,
    Window w,
    Window* root_return,
    Window* child_return,
    int* root_x_return,
    int* root_y_return,
    int* win_x_return,
    int* win_y_return,
    unsigned int* mask_return)
{
    Point where;
    CGrafPtr port;
    GDHandle dev;

    GetGWorld(&port,&dev);
    GetMouse(&where);
    LocalToGlobal(&where);

    *root_x_return = where.h;
    *root_y_return = where.v;
    *mask_return = TkMacOSXButtonKeyState();    
    return True;
}


/*
 *----------------------------------------------------------------------
 *
 * TkGenerateButtonEvent --
 *
 *        Given a global x & y position and the button key status this 
 *        procedure generates the appropiate X button event.  It also 
 *        handles the state changes needed to implement implicit grabs.
 *
 * Results:
 *        True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *        Additional events may be place on the Tk event queue.
 *        Grab state may also change.
 *
 *----------------------------------------------------------------------
 */

int
TkGenerateButtonEvent(
    int x,                /* X location of mouse */
    int y,                /* Y location of mouse */
    Window window,        /* X Window containing button event. */
    unsigned int state)   /* Button Key state suitable for X event */
{
    WindowRef whichWin, frontWin;
    Point where;
    Tk_Window tkwin;
    int dummy;
    TkDisplay *dispPtr;

    /* 
     * ButtonDown events will always occur in the front
     * window.  ButtonUp events, however, may occur anywhere
     * on the screen.  ButtonUp events should only be sent
     * to Tk if in the front window or during an implicit grab.
     */
     
    where.h = x;
    where.v = y;
    FindWindow(where, &whichWin);
    frontWin = FrontNonFloatingWindow();
                        
    if ((frontWin == NULL) || ((!(TkpIsWindowFloating(whichWin)) 
            && (frontWin != whichWin))
            && TkMacOSXGetCapture() == NULL)) {
        return false;
    }

    dispPtr = TkGetDisplayList();
    tkwin = Tk_IdToWindow(dispPtr->display, window);
    
    GlobalToLocal(&where);
    if (tkwin != NULL) {
        tkwin = Tk_TopCoordsToWindow(tkwin, where.h, where.v, 
                &dummy, &dummy);
    }

    Tk_UpdatePointer(tkwin, x,  y, state);

    return true;
}@


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
@d58 1
@


1.1.2.3
log
@Merging with TOT as of 06/09/2002.
@
text
@d174 1
a174 5
    if (medPtr->whichWin != NULL && window == None) {
        statusPtr->handledByTk = 0;
        return 0;
    }
    
@


