head	1.40;
access;
symbols
	core-8-5-9:1.31.2.1
	core-8-5-8:1.31.2.1
	macosx-cocoa-merge:1.36
	macosx-cocoa-premerge:1.35
	macosx-carbon-freeze:1.35
	core-8-5-7:1.31.2.1
	core-8-5-6:1.31.2.1
	core-8-6-b1:1.35
	core-8-6-a3:1.33
	core-8-5-5:1.31.2.1
	core-8-6-a2:1.32
	core-8-5-4:1.31.2.1
	core-8-5-3:1.31.2.1
	core-8-6-a1:1.32
	core-8-4-19:1.3.2.26
	core-8-5-branch:1.31.0.2
	core-8-5-2:1.31
	core-8-4-18:1.3.2.26
	core-8-5-1:1.31
	core-8-4-17:1.3.2.26
	core-8-5-0:1.31
	core-8-5-b3:1.30
	core-8-5-b2:1.29
	core-8-4-16:1.3.2.25
	core-8-5-b1:1.28
	core-stablilizer-merge:1.28
	core-stabilizer-branch:1.22.0.2
	core-stabilizer-merge:1.31.2.1
	core-8-4-15:1.3.2.19
	core-8-5-a6:1.21
	core-8-5-a5:1.16
	core-8-4-14:1.3.2.15
	core-8-5-a4:1.13
	core-8-4-13:1.3.2.11
	core-8-4-12:1.3.2.6
	core-8-4-11:1.3.2.2
	core-8-5-a3:1.5
	core-8-4-10:1.3.2.2
	core-8-4-9-branch:1.3.2.1.0.2
	core-8-5-a2:1.4
	core-8-4-9:1.3.2.1
	core-8-4-8:1.3.2.1
	core-8-4-7:1.3.2.1
	core-8-5-a1:1.4
	core-8-4-6:1.3.2.1
	core-8-4-5:1.3
	mistachkin-dev-branch:1.3.0.4
	core-8-4-4:1.3
	core-8-4-3:1.3
	core-8-4-branch:1.3.0.2
	core-8-4-2:1.3
	core-8-4-1:1.2
	core-8-4-0:1.2
	macosx-8-4-merge-2002-08-31-trunk:1.2
	macosx-8-4-premerge-2002-08-31-branch:1.1.2.2
	macosx-8-4-merge-2002-08-30-branch:1.1.2.2
	macosx-8-4-merge-2002-08-20-branch:1.1.2.2
	macosx-premerge-6-9-02:1.1.2.2
	macosx-8-4-branch:1.1.0.2;
locks; strict;
comment	@ * @;


1.40
date	2011.01.06.00.15.24;	author wordtech;	state Exp;
branches;
next	1.39;

1.39
date	2011.01.04.22.36.58;	author wordtech;	state Exp;
branches;
next	1.38;

1.38
date	2009.08.24.00.55.08;	author das;	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.12.10.02.51.16;	author das;	state Exp;
branches;
next	1.34;

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

1.33
date	2008.10.05.21.26.11;	author dkf;	state Exp;
branches;
next	1.32;

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

1.31
date	2007.12.13.15.27.10;	author dgp;	state Exp;
branches
	1.31.2.1;
next	1.30;

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

1.29
date	2007.10.12.03.14.48;	author das;	state Exp;
branches;
next	1.28;

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

1.27
date	2007.06.29.03.20.02;	author das;	state Exp;
branches;
next	1.26;

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

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

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

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

1.22
date	2007.05.09.12.55.16;	author das;	state Exp;
branches
	1.22.2.1;
next	1.21;

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

1.20
date	2007.04.21.19.06.38;	author hobbs;	state Exp;
branches;
next	1.19;

1.19
date	2007.04.13.14.51.18;	author dkf;	state Exp;
branches;
next	1.18;

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

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

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

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

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

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

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

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

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

1.9
date	2005.12.01.06.24.16;	author hobbs;	state Exp;
branches;
next	1.8;

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

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

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

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

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

1.3
date	2003.02.19.19.27.49;	author wolfsuit;	state Exp;
branches
	1.3.2.1;
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.3.2.1
date	2004.02.16.00.42.34;	author wolfsuit;	state Exp;
branches;
next	1.3.2.2;

1.3.2.2
date	2005.03.12.00.49.28;	author wolfsuit;	state Exp;
branches;
next	1.3.2.3;

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

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

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

1.3.2.6
date	2005.11.30.01.02.55;	author hobbs;	state Exp;
branches;
next	1.3.2.7;

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

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

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

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

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

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

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

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

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

1.3.2.16
date	2006.11.02.12.24.49;	author das;	state Exp;
branches;
next	1.3.2.17;

1.3.2.17
date	2006.11.02.15.18.26;	author das;	state Exp;
branches;
next	1.3.2.18;

1.3.2.18
date	2007.04.29.02.26.50;	author das;	state Exp;
branches;
next	1.3.2.19;

1.3.2.19
date	2007.05.09.12.57.47;	author das;	state Exp;
branches;
next	1.3.2.20;

1.3.2.20
date	2007.05.30.06.39.38;	author das;	state Exp;
branches;
next	1.3.2.21;

1.3.2.21
date	2007.05.31.13.42.12;	author das;	state Exp;
branches;
next	1.3.2.22;

1.3.2.22
date	2007.06.04.09.28.45;	author das;	state Exp;
branches;
next	1.3.2.23;

1.3.2.23
date	2007.06.09.17.10.22;	author das;	state Exp;
branches;
next	1.3.2.24;

1.3.2.24
date	2007.06.29.03.22.02;	author das;	state Exp;
branches;
next	1.3.2.25;

1.3.2.25
date	2007.07.09.08.32.12;	author das;	state Exp;
branches;
next	1.3.2.26;

1.3.2.26
date	2007.11.09.06.26.56;	author das;	state Exp;
branches;
next	1.3.2.27;

1.3.2.27
date	2008.06.19.00.11.23;	author das;	state Exp;
branches;
next	;

1.22.2.1
date	2007.05.30.13.47.43;	author dgp;	state Exp;
branches;
next	1.22.2.2;

1.22.2.2
date	2007.06.01.04.01.39;	author dgp;	state Exp;
branches;
next	1.22.2.3;

1.22.2.3
date	2007.06.04.15.19.01;	author dgp;	state Exp;
branches;
next	1.22.2.4;

1.22.2.4
date	2007.06.12.16.22.42;	author dgp;	state Exp;
branches;
next	1.22.2.5;

1.22.2.5
date	2007.07.01.17.31.37;	author dgp;	state Exp;
branches;
next	1.22.2.6;

1.22.2.6
date	2007.07.10.21.54.28;	author dgp;	state Exp;
branches;
next	1.22.2.7;

1.22.2.7
date	2007.10.15.18.38.36;	author dgp;	state Exp;
branches;
next	1.22.2.8;

1.22.2.8
date	2007.11.12.19.22.39;	author dgp;	state Exp;
branches;
next	1.22.2.9;

1.22.2.9
date	2008.06.25.16.46.09;	author dgp;	state Exp;
branches;
next	;

1.31.2.1
date	2008.06.19.00.11.17;	author das;	state Exp;
branches;
next	;


desc
@@


1.40
log
@Fix for 3086887, speeds up scrolling
@
text
@/*
 * tkMacOSXWindowEvent.c --
 *
 *	This file defines the routines for both creating and handling Window
 *	Manager class events for Tk.
 *
 * 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: tkMacOSXWindowEvent.c,v 1.39 2011/01/04 22:36:58 wordtech Exp $
 */

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

/*
#ifdef TK_MAC_DEBUG
#define TK_MAC_DEBUG_EVENTS
#define TK_MAC_DEBUG_DRAWING
#endif
*/

/*
 * Declaration of functions used only in this file
 */

static int		GenerateUpdates(HIMutableShapeRef updateRgn,
			    CGRect *updateBounds, TkWindow *winPtr);
static int		GenerateActivateEvents(TkWindow *winPtr,
			    int activeFlag);
static void		DoWindowActivate(ClientData clientData);

#pragma mark TKApplication(TKWindowEvent)

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
extern NSString *NSWindowWillOrderOnScreenNotification;
extern NSString *NSWindowDidOrderOnScreenNotification;
extern NSString *NSWindowDidOrderOffScreenNotification;

#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
#define NSWindowWillStartLiveResizeNotification @@"NSWindowWillStartLiveResizeNotification"
#define NSWindowDidEndLiveResizeNotification  @@"NSWindowDidEndLiveResizeNotification"
#endif
#endif

extern NSString *opaqueTag;

@@implementation TKApplication(TKWindowEvent)

- (void) windowActivation: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
#endif
    BOOL activate = [[notification name]
	    isEqualToString:NSWindowDidBecomeKeyNotification];
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr && Tk_IsMapped(winPtr)) {
	GenerateActivateEvents(winPtr, activate);
    }
}

- (void) windowBoundsChanged: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
#endif
    BOOL movedOnly = [[notification name]
	    isEqualToString:NSWindowDidMoveNotification];

    if (movedOnly) {
	/* constraining to screen after move not needed with AppKit */
    }

    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	WmInfo *wmPtr = winPtr->wmInfoPtr;
	NSRect bounds = [w frame];
	int x, y, width = -1, height = -1, flags = 0;

	x = bounds.origin.x;
	y = tkMacOSXZeroScreenHeight - (bounds.origin.y + bounds.size.height);
	if (winPtr->changes.x != x || winPtr->changes.y != y){
	    flags |= TK_LOCATION_CHANGED;
	} else {
	    x = y = -1;
	}
	if (!movedOnly && (winPtr->changes.width != bounds.size.width ||
		winPtr->changes.height !=  bounds.size.height)) {
	    width = bounds.size.width - wmPtr->xInParent;
	    height = bounds.size.height - wmPtr->yInParent;
	    flags |= TK_SIZE_CHANGED;
	}
	if (Tcl_GetServiceMode() != TCL_SERVICE_NONE) {
	    /*
	     * Propagate geometry changes immediately.
	     */

	    flags |= TK_MACOSX_HANDLE_EVENT_IMMEDIATELY;
	}
	TkGenWMConfigureEvent((Tk_Window) winPtr, x, y, width, height, flags);
    }
}

- (void) windowExpanded: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
#endif
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	winPtr->wmInfoPtr->hints.initial_state =
		TkMacOSXIsWindowZoomed(winPtr) ? ZoomState : NormalState;
	Tk_MapWindow((Tk_Window) winPtr);
	if (Tcl_GetServiceMode() != TCL_SERVICE_NONE) {
	    /*
	     * Process all Tk events generated by Tk_MapWindow().
	     */

	    while (Tcl_ServiceEvent(0)) {}
	    while (Tcl_DoOneEvent(TCL_IDLE_EVENTS|TCL_DONT_WAIT)) {}

	    /*
	     * NSWindowDidDeminiaturizeNotification is received after
	     * NSWindowDidBecomeKeyNotification, so activate manually
	     */

	    GenerateActivateEvents(winPtr, 1);
	} else {
	    Tcl_DoWhenIdle(DoWindowActivate, winPtr);
	}
    }
}

- (void) windowCollapsed: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
#endif
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	Tk_UnmapWindow((Tk_Window) winPtr);
    }
}

- (BOOL) windowShouldClose: (NSWindow *) w
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, w);
#endif
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	TkGenWMDestroyEvent((Tk_Window) winPtr);
    }

    /*
     * If necessary, TkGenWMDestroyEvent() handles [close]ing the window,
     * so can always return NO from -windowShouldClose: for a Tk window.
     */

    return (winPtr ? NO : YES);
}

#ifdef TK_MAC_DEBUG_NOTIFICATIONS

- (void) windowDragStart: (NSNotification *) notification
{
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
}

- (void) windowLiveResize: (NSNotification *) notification
{
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
    //BOOL start = [[notification name] isEqualToString:NSWindowWillStartLiveResizeNotification];
}

- (void) windowMapped: (NSNotification *) notification
{
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	//Tk_MapWindow((Tk_Window) winPtr);
    }
}

- (void) windowBecameVisible: (NSNotification *) notification
{
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
}

- (void) windowUnmapped: (NSNotification *) notification
{
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
    NSWindow *w = [notification object];
    TkWindow *winPtr = TkMacOSXGetTkWindow(w);

    if (winPtr) {
	//Tk_UnmapWindow((Tk_Window) winPtr);
    }
}
#endif /* TK_MAC_DEBUG_NOTIFICATIONS */

- (void) _setupWindowNotifications
{
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

#define observe(n, s) \
	[nc addObserver:self selector:@@selector(s) name:(n) object:nil]
    observe(NSWindowDidBecomeKeyNotification, windowActivation:);
    observe(NSWindowDidResignKeyNotification, windowActivation:);
    observe(NSWindowDidMoveNotification, windowBoundsChanged:);
    observe(NSWindowDidResizeNotification, windowBoundsChanged:);
    observe(NSWindowDidDeminiaturizeNotification, windowExpanded:);
    observe(NSWindowDidMiniaturizeNotification, windowCollapsed:);
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    observe(NSWindowWillMoveNotification, windowDragStart:);
    observe(NSWindowWillStartLiveResizeNotification, windowLiveResize:);
    observe(NSWindowDidEndLiveResizeNotification, windowLiveResize:);
    observe(NSWindowWillOrderOnScreenNotification, windowMapped:);
    observe(NSWindowDidOrderOnScreenNotification, windowBecameVisible:);
    observe(NSWindowDidOrderOffScreenNotification, windowUnmapped:);
#endif
#undef observe
}
@@end

#pragma mark TKApplication(TKApplicationEvent)

@@implementation TKApplication(TKApplicationEvent)

- (void) applicationActivate: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
#endif
    [NSApp tkCheckPasteboard];
}

- (void) applicationDeactivate: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
#endif
    TkSuspendClipboard();
}

- (void) applicationShowHide: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
#endif
    const char *cmd = ([[notification name] isEqualToString:
	    NSApplicationDidUnhideNotification] ?
	    "::tk::mac::OnShow" : "::tk::mac::OnHide");
    Tcl_CmdInfo dummy;

    if (_eventInterp && Tcl_GetCommandInfo(_eventInterp, cmd, &dummy)) {
	int code = Tcl_EvalEx(_eventInterp, cmd, -1, TCL_EVAL_GLOBAL);

	if (code != TCL_OK) {
	    Tcl_BackgroundException(_eventInterp, code);
	}
	Tcl_ResetResult(_eventInterp);
    }
}

- (void) displayChanged: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
#endif
    TkDisplay *dispPtr = TkGetDisplayList();

    if (dispPtr) {
	TkMacOSXDisplayChanged(dispPtr->display);
    }
}
@@end

#pragma mark -

/*
 *----------------------------------------------------------------------
 *
 * GenerateUpdates --
 *
 *	Given a Macintosh update region and a Tk window this function geneates
 *	a X Expose event for the window if it is within the update region. The
 *	function will then recursivly have each damaged window generate Expose
 *	events for its child windows.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

static int
GenerateUpdates(
    HIMutableShapeRef updateRgn,
    CGRect *updateBounds,
    TkWindow *winPtr)
{
    TkWindow *childPtr;
    XEvent event;
    CGRect bounds, damageBounds;
    HIShapeRef boundsRgn, damageRgn;

    TkMacOSXWinCGBounds(winPtr, &bounds);
    if (!CGRectIntersectsRect(bounds, *updateBounds)) {
	return 0;
    }
    if (!HIShapeIntersectsRect(updateRgn, &bounds)) {
	return 0;
    }

    /*
     * Compute the bounding box of the area that the damage occured in.
     */

    boundsRgn = HIShapeCreateWithRect(&bounds);
    damageRgn = HIShapeCreateIntersection(updateRgn, boundsRgn);
    if (HIShapeIsEmpty(damageRgn)) {
	CFRelease(damageRgn);
	CFRelease(boundsRgn);
	return 0;
    }
    HIShapeGetBounds(damageRgn, &damageBounds);
   
    CFRelease(damageRgn);
    CFRelease(boundsRgn);

    event.xany.serial = LastKnownRequestProcessed(Tk_Display(winPtr));
    event.xany.send_event = false;
    event.xany.window = Tk_WindowId(winPtr);
    event.xany.display = Tk_Display(winPtr);
    event.type = Expose;
    event.xexpose.x = damageBounds.origin.x - bounds.origin.x;
    event.xexpose.y = damageBounds.origin.y - bounds.origin.y;
    event.xexpose.width = damageBounds.size.width;
    event.xexpose.height = damageBounds.size.height;
    event.xexpose.count = 0;
    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
#ifdef TK_MAC_DEBUG_DRAWING
    TKLog(@@"Expose %p {{%d, %d}, {%d, %d}}", event.xany.window, event.xexpose.x,
	event.xexpose.y, event.xexpose.width, event.xexpose.height);
#endif

    /*
     * Generate updates for the children of this window
     */

    for (childPtr = winPtr->childList; childPtr != NULL;
	    childPtr = childPtr->nextPtr) {
	if (!Tk_IsMapped(childPtr) || Tk_IsTopLevel(childPtr)) {
	    continue;
	}
	GenerateUpdates(updateRgn, updateBounds, childPtr);
    }

    /*
     * Generate updates for any contained windows
     */

    if (Tk_IsContainer(winPtr)) {
	childPtr = TkpGetOtherWindow(winPtr);
	if (childPtr != NULL && Tk_IsMapped(childPtr)) {
	    GenerateUpdates(updateRgn, updateBounds, childPtr);
	}

	/*
	 * TODO: Here we should handle out of process embedding.
	 */
    }

    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateActivateEvents --
 *
 *	Given a Macintosh window activate event this function generates all the
 *	X Activate events needed by Tk.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

int
GenerateActivateEvents(
    TkWindow *winPtr,
    int activeFlag)
{
    TkGenerateActivateEvents(winPtr, activeFlag);
    TkMacOSXGenerateFocusEvent(winPtr, activeFlag);
    TkMacOSXEnterExitFullscreen(winPtr, activeFlag);
    return true;
}

/*
 *----------------------------------------------------------------------
 *
 * DoWindowActivate --
 *
 *	Idle handler that calls GenerateActivateEvents().
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

void
DoWindowActivate(
    ClientData clientData)
{
    GenerateActivateEvents(clientData, 1);
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXGenerateFocusEvent --
 *
 *	Given a Macintosh window activate event this function generates all
 *	the X Focus events needed by Tk.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE int
TkMacOSXGenerateFocusEvent(
    TkWindow *winPtr,		/* Root X window for event. */
    int activeFlag)
{
    XEvent event;

    /*
     * Don't send focus events to windows of class help or to windows with the
     * kWindowNoActivatesAttribute.
     */

    if (winPtr->wmInfoPtr && (winPtr->wmInfoPtr->macClass == kHelpWindowClass ||
	    winPtr->wmInfoPtr->attributes & kWindowNoActivatesAttribute)) {
	return false;
    }

    /*
     * Generate FocusIn and FocusOut events. This event is only sent to the
     * toplevel window.
     */

    if (activeFlag) {
	event.xany.type = FocusIn;
    } else {
	event.xany.type = FocusOut;
    }

    event.xany.serial = LastKnownRequestProcessed(Tk_Display(winPtr));
    event.xany.send_event = False;
    event.xfocus.display = Tk_Display(winPtr);
    event.xfocus.window = winPtr->window;
    event.xfocus.mode = NotifyNormal;
    event.xfocus.detail = NotifyDetailNone;

    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
    return true;
}

/*
 *----------------------------------------------------------------------
 *
 * TkGenWMConfigureEvent --
 *
 *	Generate a ConfigureNotify event for Tk. Depending on the value of flag
 *	the values of width/height, x/y, or both may be changed.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A ConfigureNotify event is sent to Tk.
 *
 *----------------------------------------------------------------------
 */

void
TkGenWMConfigureEvent(
    Tk_Window tkwin,
    int x, int y,
    int width, int height,
    int flags)
{
    XEvent event;
    WmInfo *wmPtr;
    TkWindow *winPtr = (TkWindow *) tkwin;

    if (tkwin == NULL) {
	return;
    }

    event.type = ConfigureNotify;
    event.xconfigure.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
    event.xconfigure.send_event = False;
    event.xconfigure.display = Tk_Display(tkwin);
    event.xconfigure.event = Tk_WindowId(tkwin);
    event.xconfigure.window = Tk_WindowId(tkwin);
    event.xconfigure.border_width = winPtr->changes.border_width;
    event.xconfigure.override_redirect = winPtr->atts.override_redirect;
    if (winPtr->changes.stack_mode == Above) {
	event.xconfigure.above = winPtr->changes.sibling;
    } else {
	event.xconfigure.above = None;
    }

    if (!(flags & TK_LOCATION_CHANGED)) {
	x = Tk_X(tkwin);
	y = Tk_Y(tkwin);
    }
    if (!(flags & TK_SIZE_CHANGED)) {
	width = Tk_Width(tkwin);
	height = Tk_Height(tkwin);
    }
    event.xconfigure.x = x;
    event.xconfigure.y = y;
    event.xconfigure.width = width;
    event.xconfigure.height = height;

    if (flags & TK_MACOSX_HANDLE_EVENT_IMMEDIATELY) {
	Tk_HandleEvent(&event);
    } else {
	Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
    }

    /*
     * Update window manager information.
     */

    if (Tk_IsTopLevel(winPtr)) {
	wmPtr = winPtr->wmInfoPtr;
	if (flags & TK_LOCATION_CHANGED) {
	    wmPtr->x = x;
	    wmPtr->y = y;
	    wmPtr->flags &= ~(WM_NEGATIVE_X | WM_NEGATIVE_Y);
	}
	if ((flags & TK_SIZE_CHANGED) && !(wmPtr->flags & WM_SYNC_PENDING) &&
		((width != Tk_Width(tkwin)) || (height != Tk_Height(tkwin)))) {
	    if ((wmPtr->width == -1) && (width == winPtr->reqWidth)) {
		/*
		 * Don't set external width, since the user didn't change it
		 * from what the widgets asked for.
		 */
	    } else if (wmPtr->gridWin != NULL) {
		wmPtr->width = wmPtr->reqGridWidth
			+ (width - winPtr->reqWidth)/wmPtr->widthInc;
		if (wmPtr->width < 0) {
		    wmPtr->width = 0;
		}
	    } else {
		wmPtr->width = width;
	    }

	    if ((wmPtr->height == -1) && (height == winPtr->reqHeight)) {
		/*
		 * Don't set external height, since the user didn't change it
		 * from what the widgets asked for.
		 */
	    } else if (wmPtr->gridWin != NULL) {
		wmPtr->height = wmPtr->reqGridHeight
			+ (height - winPtr->reqHeight)/wmPtr->heightInc;
		if (wmPtr->height < 0) {
		    wmPtr->height = 0;
		}
	    } else {
		wmPtr->height = height;
	    }

	    wmPtr->configWidth = width;
	    wmPtr->configHeight = height;
	}
    }

    /*
     * Now set up the changes structure. Under X we wait for the
     * ConfigureNotify to set these values. On the Mac we know imediatly that
     * this is what we want - so we just set them. However, we need to make
     * sure the windows clipping region is marked invalid so the change is
     * visible to the subwindow.
     */

    winPtr->changes.x = x;
    winPtr->changes.y = y;
    winPtr->changes.width = width;
    winPtr->changes.height = height;
    TkMacOSXInvalClipRgns(tkwin);
}

/*
 *----------------------------------------------------------------------
 *
 * TkGenWMDestroyEvent --
 *
 *	Generate a WM Destroy event for Tk.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A WM_PROTOCOL/WM_DELETE_WINDOW event is sent to Tk.
 *
 *----------------------------------------------------------------------
 */

void
TkGenWMDestroyEvent(
    Tk_Window tkwin)
{
    XEvent event;

    event.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
    event.xany.send_event = False;
    event.xany.display = Tk_Display(tkwin);

    event.xclient.window = Tk_WindowId(tkwin);
    event.xclient.type = ClientMessage;
    event.xclient.message_type = Tk_InternAtom(tkwin, "WM_PROTOCOLS");
    event.xclient.format = 32;
    event.xclient.data.l[0] = Tk_InternAtom(tkwin, "WM_DELETE_WINDOW");
    Tk_HandleEvent(&event);
}

/*
 *----------------------------------------------------------------------
 *
 * TkWmProtocolEventProc --
 *
 *	This procedure is called by the Tk_HandleEvent whenever a ClientMessage
 *	event arrives whose type is "WM_PROTOCOLS". This procedure handles the
 *	message from the window manager in an appropriate fashion.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Depends on what sort of handler, if any, was set up for the protocol.
 *
 *----------------------------------------------------------------------
 */

void
TkWmProtocolEventProc(
    TkWindow *winPtr,		/* Window to which the event was sent. */
    XEvent *eventPtr)		/* X event. */
{
    WmInfo *wmPtr;
    ProtocolHandler *protPtr;
    Tcl_Interp *interp;
    Atom protocol;
    int result;

    wmPtr = winPtr->wmInfoPtr;
    if (wmPtr == NULL) {
	return;
    }
    protocol = (Atom) eventPtr->xclient.data.l[0];
    for (protPtr = wmPtr->protPtr; protPtr != NULL;
	    protPtr = protPtr->nextPtr) {
	if (protocol == protPtr->protocol) {
	    Tcl_Preserve(protPtr);
	    interp = protPtr->interp;
	    Tcl_Preserve(interp);
	    result = Tcl_GlobalEval(interp, protPtr->command);
	    if (result != TCL_OK) {
		Tcl_AddErrorInfo(interp, "\n    (command for \"");
		Tcl_AddErrorInfo(interp,
			Tk_GetAtomName((Tk_Window) winPtr, protocol));
		Tcl_AddErrorInfo(interp, "\" window manager protocol)");
		Tcl_BackgroundException(interp, result);
	    }
	    Tcl_Release(interp);
	    Tcl_Release(protPtr);
	    return;
	}
    }

    /*
     * No handler was present for this protocol. If this is a WM_DELETE_WINDOW
     * message then just destroy the window.
     */

    if (protocol == Tk_InternAtom((Tk_Window) winPtr, "WM_DELETE_WINDOW")) {
	Tk_DestroyWindow((Tk_Window) winPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MacOSXIsAppInFront --
 *
 *	Returns 1 if this app is the foreground app.
 *
 * Results:
 *	1 if app is in front, 0 otherwise.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_MacOSXIsAppInFront(void)
{
    OSStatus err;
    ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
    Boolean isFrontProcess = true;

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

    return (isFrontProcess == true);
}

#pragma mark TKContentView

#import <ApplicationServices/ApplicationServices.h>

/*
 * Custom content view for Tk NSWindows, containing standard NSView subviews.
 * The goal is to emulate X11-style drawing in response to Expose events:
 * during the normal AppKit drawing cycle, we supress drawing of all subviews
 * (using a technique adapted from WebKit's WebHTMLView) and instead send
 * Expose events about the subviews that would be redrawn. Tk Expose event
 * handling and drawing handlers then draw the subviews manually via their
 * -displayRectIgnoringOpacity:
 */

@@interface TKContentView(TKWindowEvent)
- (void) drawRect: (NSRect) rect;
- (void) generateExposeEvents: (HIMutableShapeRef) shape;
- (BOOL) isOpaque;
- (BOOL) wantsDefaultClipping;
- (BOOL) acceptsFirstResponder;
- (void) keyDown: (NSEvent *) theEvent;
@@end

@@implementation TKContentView
@@end

static Tk_RestrictAction
ExposeRestrictProc(
    ClientData arg,
    XEvent *eventPtr)
{
    return (eventPtr->type==Expose && eventPtr->xany.serial==PTR2UINT(arg)
	    ? TK_PROCESS_EVENT : TK_DEFER_EVENT);
}

@@implementation TKContentView(TKWindowEvent)

- (void) drawRect: (NSRect) rect
{
    const NSRect *rectsBeingDrawn;
    NSInteger rectsBeingDrawnCount;

    [self getRectsBeingDrawn:&rectsBeingDrawn count:&rectsBeingDrawnCount];
#ifdef TK_MAC_DEBUG_DRAWING
    TKLog(@@"-[%@@(%p) %s%@@]", [self class], self, _cmd, NSStringFromRect(rect));
    [[NSColor colorWithDeviceRed:0.0 green:1.0 blue:0.0 alpha:.1] setFill];
    NSRectFillListUsingOperation(rectsBeingDrawn, rectsBeingDrawnCount,
	    NSCompositeSourceOver);
#endif

    NSWindow *w = [self window];

    if ([self isOpaque] && [w showsResizeIndicator]) {
	NSRect bounds = [self convertRect:[w _growBoxRect] fromView:nil];

	if ([self needsToDrawRect:bounds]) {
	    NSEraseRect(bounds);
	}
    }

    CGFloat height = [self bounds].size.height;
    HIMutableShapeRef drawShape = HIShapeCreateMutable();

    while (rectsBeingDrawnCount--) {
	CGRect r = NSRectToCGRect(*rectsBeingDrawn++);

	r.origin.y = height - (r.origin.y + r.size.height);
	HIShapeUnionWithRect(drawShape, &r);
    }
    if (CFRunLoopGetMain() == CFRunLoopGetCurrent()) {
	[self generateExposeEvents:drawShape];
    } else {
	[self performSelectorOnMainThread:@@selector(generateExposeEvents:)
		withObject:(id)drawShape waitUntilDone:NO
		modes:[NSArray arrayWithObjects:NSRunLoopCommonModes,
			NSEventTrackingRunLoopMode, NSModalPanelRunLoopMode,
			nil]];
    }
    CFRelease(drawShape);
}

- (void) generateExposeEvents: (HIMutableShapeRef) shape
{
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
    unsigned long serial;
    CGRect updateBounds;

    if (!winPtr) {
	return;
    }
    HIShapeGetBounds(shape, &updateBounds);
    serial = LastKnownRequestProcessed(Tk_Display(winPtr));
    if (GenerateUpdates(shape, &updateBounds, winPtr) &&
	    ![[NSRunLoop currentRunLoop] currentMode] &&
	    Tcl_GetServiceMode() != TCL_SERVICE_NONE) {
	/*
	 * Ensure there are no pending idle-time redraws that could prevent the
	 * just posted Expose events from generating new redraws.
	 */

	while (Tcl_DoOneEvent(TCL_IDLE_EVENTS|TCL_DONT_WAIT)) {}

	/*
	 * For smoother drawing, process Expose events and resulting redraws
	 * immediately instead of at idle time.
	 */

	ClientData oldArg;
	Tk_RestrictProc *oldProc = Tk_RestrictEvents(ExposeRestrictProc,
		UINT2PTR(serial), &oldArg);

	while (Tcl_ServiceEvent(TCL_WINDOW_EVENTS)) {}
	Tk_RestrictEvents(oldProc, oldArg, &oldArg);
	while (Tcl_DoOneEvent(TCL_IDLE_EVENTS|TCL_DONT_WAIT)) {}
    }
}

- (void) tkToolbarButton: (id) sender
{
#ifdef TK_MAC_DEBUG_EVENTS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd);
#endif
    XVirtualEvent event;
    int x, y;
    TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
    Tk_Window tkwin = (Tk_Window) winPtr;

    bzero(&event, sizeof(XVirtualEvent));
    event.type = VirtualEvent;
    event.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
    event.send_event = false;
    event.display = Tk_Display(tkwin);
    event.event = Tk_WindowId(tkwin);
    event.root = XRootWindow(Tk_Display(tkwin), 0);
    event.subwindow = None;
    event.time = TkpGetMS();
    XQueryPointer(NULL, winPtr->window, NULL, NULL,
	    &event.x_root, &event.y_root, &x, &y, &event.state);
    Tk_TopCoordsToWindow(tkwin, x, y, &event.x, &event.y);
    event.same_screen = true;
    event.name = Tk_GetUid("ToolbarButton");
    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
}

#ifdef TK_MAC_DEBUG_DRAWING
- (void) setFrameSize: (NSSize) newSize
{
    TKLog(@@"-[%@@(%p) %s%@@]", [self class], self, _cmd,
	    NSStringFromSize(newSize));
    [super setFrameSize:newSize];
}

- (void) setNeedsDisplayInRect: (NSRect) invalidRect
{
    TKLog(@@"-[%@@(%p) %s%@@]", [self class], self, _cmd,
	    NSStringFromRect(invalidRect));
    [super setNeedsDisplayInRect:invalidRect];
}
#endif

- (BOOL) isOpaque
{
    NSWindow *w = [self window];

    if (opaqueTag != NULL) {
      return YES;
	} else {

     return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) ||
    	    ![w isOpaque]) ? NO : YES);
    }
}

- (BOOL) wantsDefaultClipping
{
    return NO;
}

- (BOOL) acceptsFirstResponder
{
    return YES;
}

- (void) keyDown: (NSEvent *) theEvent
{
#ifdef TK_MAC_DEBUG_EVENTS
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, theEvent);
#endif
}

@@end

#pragma mark TKContentViewPrivate

/*
 * Technique adapted from WebKit/WebKit/mac/WebView/WebHTMLView.mm to supress
 * normal AppKit subview drawing and make all drawing go through us.
 * Overrides NSView internals.
 */

@@interface TKContentView(TKContentViewPrivate)
- (id) initWithFrame: (NSRect) frame;
- (void) _setAsideSubviews;
- (void) _restoreSubviews;
@@end

@@interface NSView(TKContentViewPrivate)
- (void) _recursiveDisplayRectIfNeededIgnoringOpacity: (NSRect) rect
	isVisibleRect: (BOOL) isVisibleRect
	rectIsVisibleRectForView: (NSView *) visibleView
	topView: (BOOL) topView;
- (void) _recursiveDisplayAllDirtyWithLockFocus: (BOOL) needsLockFocus
	visRect: (NSRect) visRect;
- (void) _recursive: (BOOL) recurse
	displayRectIgnoringOpacity: (NSRect) displayRect
	inContext: (NSGraphicsContext *) context topView: (BOOL) topView;
- (void) _lightWeightRecursiveDisplayInRect: (NSRect) visRect;
- (BOOL) _drawRectIfEmpty;
- (void) _drawRect: (NSRect) inRect clip: (BOOL) clip;
- (void) _setDrawsOwnDescendants: (BOOL) drawsOwnDescendants;
@@end

@@implementation TKContentView(TKContentViewPrivate)

- (id) initWithFrame: (NSRect) frame
{
    self = [super initWithFrame:frame];
    if (self) {
	_savedSubviews = nil;
	_subviewsSetAside = NO;
	[self _setDrawsOwnDescendants:YES];
    }
    return self;
}

- (void) _setAsideSubviews
{
#ifdef TK_MAC_DEBUG
    if (_subviewsSetAside || _savedSubviews) {
	Tcl_Panic("TKContentView _setAsideSubviews called incorrectly");
    }
#endif
    _savedSubviews = _subviews;
    _subviews = nil;
    _subviewsSetAside = YES;
}

- (void) _restoreSubviews
{
#ifdef TK_MAC_DEBUG
    if (!_subviewsSetAside || _subviews) {
	Tcl_Panic("TKContentView _restoreSubviews called incorrectly");
    }
#endif
    _subviews = _savedSubviews;
    _savedSubviews = nil;
    _subviewsSetAside = NO;
}

- (void) _recursiveDisplayRectIfNeededIgnoringOpacity: (NSRect) rect
	isVisibleRect: (BOOL) isVisibleRect
	rectIsVisibleRectForView: (NSView *) visibleView
	topView: (BOOL) topView
{
    [self _setAsideSubviews];
    [super _recursiveDisplayRectIfNeededIgnoringOpacity:rect
	    isVisibleRect:isVisibleRect rectIsVisibleRectForView:visibleView
	    topView:topView];
    [self _restoreSubviews];
}

- (void) _recursiveDisplayAllDirtyWithLockFocus: (BOOL) needsLockFocus
	visRect: (NSRect) visRect
{
    BOOL needToSetAsideSubviews = !_subviewsSetAside;

    if (needToSetAsideSubviews) {
        [self _setAsideSubviews];
    }
    [super _recursiveDisplayAllDirtyWithLockFocus:needsLockFocus
	    visRect:visRect];
    if (needToSetAsideSubviews) {
        [self _restoreSubviews];
    }
}

- (void) _recursive: (BOOL) recurse
	displayRectIgnoringOpacity: (NSRect) displayRect
	inContext: (NSGraphicsContext *) context topView: (BOOL) topView
{
    [self _setAsideSubviews];
    [super _recursive:recurse
	    displayRectIgnoringOpacity:displayRect inContext:context
	    topView:topView];
    [self _restoreSubviews];
}

- (void) _lightWeightRecursiveDisplayInRect: (NSRect) visRect
{
    BOOL needToSetAsideSubviews = !_subviewsSetAside;

    if (needToSetAsideSubviews) {
        [self _setAsideSubviews];
    }
    [super _lightWeightRecursiveDisplayInRect:visRect];
    if (needToSetAsideSubviews) {
        [self _restoreSubviews];
    }
}

- (BOOL) _drawRectIfEmpty
{
    /*
     * Our -drawRect manages subview drawing directly, so it needs to be called
     * even if the area to be redrawn is completely obscured by subviews.
     */

    return YES;
}

- (void) _drawRect: (NSRect) inRect clip: (BOOL) clip
{
#ifdef TK_MAC_DEBUG_DRAWING
    TKLog(@@"-[%@@(%p) %s%@@]", [self class], self, _cmd,
	    NSStringFromRect(inRect));
#endif
    BOOL subviewsWereSetAside = _subviewsSetAside;

    if (subviewsWereSetAside) {
        [self _restoreSubviews];
    }
    [super _drawRect:inRect clip:clip];
    if (subviewsWereSetAside) {
        [self _setAsideSubviews];
    }
}

@@end

/*
 * Local Variables:
 * mode: objc
 * c-basic-offset: 4
 * fill-column: 79
 * coding: utf-8
 * End:
 */
@


1.39
log
@Textured background windows
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.38 2009/08/24 00:55:08 das Exp $
d348 1
a348 4
    if (!Tk_IsTopLevel(winPtr)) {
	ChkErr(TkMacOSHIShapeUnion, boundsRgn, updateRgn, updateRgn);
	HIShapeGetBounds(updateRgn, updateBounds);
    }
@


1.38
log
@	* macosx/tkMacOSXWindowEvent.c: Allow WM_DELETE_WINDOW handlers to
	prevent window closure by generating WM destroy event earlier (from
	window delegate's -windowShouldClose:). [Bug 2821084]
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.37 2009/07/06 20:29:21 dkf Exp $
d51 2
d929 7
a935 2
    return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) ||
	    ![w isOpaque]) ? NO : YES);
@


1.37
log
@More marking of files as Objective-C.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.36 2009/06/29 14:35:01 das Exp $
d157 1
a157 1
- (void) windowClosed: (NSNotification *) notification
d160 1
a160 1
    TKLog(@@"-[%@@(%p) %s] %@@", [self class], self, _cmd, notification);
a161 1
    NSWindow *w = [notification object];
d167 7
a228 1
    observe(NSWindowWillCloseNotification, windowClosed:);
@


1.36
log
@Merge of TkAqua Cocoa port
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.35 2008/12/10 02:51:16 das Exp $
d50 2
d53 2
a54 2
@@implementation TKApplication(TKWindowEvent)
- (void)windowActivation:(NSNotification *)notification {
d58 2
a59 1
    BOOL activate = [[notification name] isEqualToString:NSWindowDidBecomeKeyNotification];
d67 3
a69 1
- (void)windowBoundsChanged:(NSNotification *)notification {
d73 3
a75 1
    BOOL movedOnly = [[notification name] isEqualToString:NSWindowDidMoveNotification];
d79 1
d102 4
a105 1
	    /* propagate geometry changes immediately */
d111 3
a113 1
- (void)windowExpanded:(NSNotification *)notification {
d125 4
a128 1
	    /* Process all Tk events generated by Tk_MapWindow() */
d143 3
a145 1
- (void)windowCollapsed:(NSNotification *)notification {
d156 3
a158 1
- (void)windowClosed:(NSNotification *)notification {
d169 1
d171 3
a173 1
- (void)windowDragStart:(NSNotification *)notification {
d176 3
a178 1
- (void)windowLiveResize:(NSNotification *)notification {
d182 3
a184 1
- (void)windowMapped:(NSNotification *)notification {
d193 3
a195 2
- (void)windowBecameVisible:(NSNotification *)notification {
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
a196 1
#endif
d198 3
a200 1
- (void)windowUnmapped:(NSNotification *)notification {
d209 1
a209 1
#endif
d211 2
a212 1
- (void)_setupWindowNotifications {
d214 3
a216 1
#define observe(n, s) [nc addObserver:self selector:@@selector(s) name:(n) object:nil]
d235 1
a235 1

d239 3
a241 1
- (void)applicationActivate:(NSNotification *)notification {
d247 3
a249 1
- (void)applicationDeactivate:(NSNotification *)notification {
d255 3
a257 1
- (void)applicationShowHide:(NSNotification *)notification {
d268 1
d275 3
a277 1
- (void)displayChanged:(NSNotification *)notification {
d399 2
a400 2
 *	Given a Macintosh window activate event this function generates all
 *	the X Activate events needed by Tk.
d506 2
a507 2
 *	Generate a ConfigureNotify event for Tk. Depending on the value of
 *	flag the values of width/height, x/y, or both may be changed.
d521 2
a522 4
    int x,
    int y,
    int width,
    int height,
d584 6
d591 1
a591 9
		if (wmPtr->gridWin != NULL) {
		    wmPtr->width = wmPtr->reqGridWidth
			    + (width - winPtr->reqWidth)/wmPtr->widthInc;
		    if (wmPtr->width < 0) {
			wmPtr->width = 0;
		    }
		} else {
		    wmPtr->width = width;
		}
d593 1
d599 6
d606 1
a606 9
		if (wmPtr->gridWin != NULL) {
		    wmPtr->height = wmPtr->reqGridHeight
			    + (height - winPtr->reqHeight)/wmPtr->heightInc;
		    if (wmPtr->height < 0) {
			wmPtr->height = 0;
		    }
		} else {
		    wmPtr->height = height;
		}
d608 1
d668 3
a670 4
 *	This procedure is called by the Tk_HandleEvent whenever a
 *	ClientMessage event arrives whose type is "WM_PROTOCOLS". This
 *	procedure handles the message from the window manager in an
 *	appropriate fashion.
d757 1
a757 1

d767 3
a769 3
 * Expose events about the subviews that would be redrawn.
 * Tk Expose event handling and drawing handlers then draw the subviews
 * manually via their -displayRectIgnoringOpacity:
d773 6
a778 6
- (void)drawRect:(NSRect)rect;
- (void)generateExposeEvents:(HIMutableShapeRef)shape;
- (BOOL)isOpaque;
- (BOOL)wantsDefaultClipping;
- (BOOL)acceptsFirstResponder;
- (void)keyDown:(NSEvent *)theEvent;
d784 4
a787 1
static Tk_RestrictAction ExposeRestrictProc(ClientData arg, XEvent *eventPtr)
d789 2
a790 2
    return (eventPtr->type == Expose && eventPtr->xany.serial == PTR2UINT(arg) ?
	    TK_PROCESS_EVENT : TK_DEFER_EVENT);
d795 2
a796 1
- (void)drawRect:(NSRect)rect {
d799 1
d807 1
d809 1
d812 1
d817 1
d820 1
d823 1
d839 2
a840 1
- (void)generateExposeEvents:(HIMutableShapeRef)shape {
d854 2
a855 2
	 * Ensure there are no pending idle-time redraws that could prevent
	 * the just posted Expose events from generating new redraws.
d868 1
d875 2
a876 1
- (void)tkToolbarButton:(id)sender {
d903 4
a906 2
- (void)setFrameSize:(NSSize)newSize {
    TKLog(@@"-[%@@(%p) %s%@@]", [self class], self, _cmd, NSStringFromSize(newSize));
d909 3
a911 1
- (void)setNeedsDisplayInRect:(NSRect)invalidRect {
d917 3
a919 1
- (BOOL)isOpaque {
d926 2
a927 1
- (BOOL)wantsDefaultClipping {
d931 2
a932 1
- (BOOL)acceptsFirstResponder {
d936 2
a937 1
- (void)keyDown:(NSEvent *)theEvent {
d944 1
a944 1

d954 3
a956 3
- (id)initWithFrame:(NSRect)frame;
- (void)_setAsideSubviews;
- (void)_restoreSubviews;
d960 13
a972 7
- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)rect isVisibleRect:(BOOL)isVisibleRect rectIsVisibleRectForView:(NSView *)visibleView topView:(BOOL)topView;
- (void)_recursiveDisplayAllDirtyWithLockFocus:(BOOL)needsLockFocus visRect:(NSRect)visRect;
- (void)_recursive:(BOOL)recurse displayRectIgnoringOpacity:(NSRect)displayRect inContext:(NSGraphicsContext *)context topView:(BOOL)topView;
- (void)_lightWeightRecursiveDisplayInRect:(NSRect)visRect;
- (BOOL)_drawRectIfEmpty;
- (void)_drawRect:(NSRect)inRect clip:(BOOL)clip;
- (void)_setDrawsOwnDescendants:(BOOL)drawsOwnDescendants;
a974 1

d977 2
a978 1
- (id)initWithFrame:(NSRect)frame {
d988 1
a988 1
- (void)_setAsideSubviews
d998 1
a998 1
 }
d1000 2
a1001 2
 - (void)_restoreSubviews
 {
d1012 4
a1015 1
- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)rect isVisibleRect:(BOOL)isVisibleRect rectIsVisibleRectForView:(NSView *)visibleView topView:(BOOL)topView
d1018 3
a1020 1
    [super _recursiveDisplayRectIfNeededIgnoringOpacity:rect isVisibleRect:isVisibleRect rectIsVisibleRectForView:visibleView topView:topView];
d1024 2
a1025 1
- (void)_recursiveDisplayAllDirtyWithLockFocus:(BOOL)needsLockFocus visRect:(NSRect)visRect
d1028 1
d1032 2
a1033 1
    [super _recursiveDisplayAllDirtyWithLockFocus:needsLockFocus visRect:visRect];
d1039 3
a1041 1
- (void)_recursive:(BOOL)recurse displayRectIgnoringOpacity:(NSRect)displayRect inContext:(NSGraphicsContext *)context topView:(BOOL)topView
d1044 3
a1046 1
    [super _recursive:recurse displayRectIgnoringOpacity:displayRect inContext:context topView:topView];
d1050 2
a1051 1
- (void)_lightWeightRecursiveDisplayInRect:(NSRect)visRect {
d1053 1
d1063 2
a1064 1
- (BOOL)_drawRectIfEmpty {
d1069 1
d1073 2
a1074 1
- (void)_drawRect:(NSRect)inRect clip:(BOOL)clip {
d1076 2
a1077 1
    TKLog(@@"-[%@@(%p) %s%@@]", [self class], self, _cmd, NSStringFromRect(inRect));
d1080 1
d1094 1
a1094 1
 * mode: c
@


1.35
log
@s/Tk_BackgroundException/Tcl_BackgroundException/
@
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: tkMacOSXWindowEvent.c,v 1.34 2008/12/09 21:22:56 dgp Exp $
d23 2
a24 1
#define TK_MAC_DEBUG_CLIP_REGIONS
a31 1
static int		GenerateUpdateEvent(Window window);
d34 16
a49 19
static int		GenerateActivateEvents(Window window, int activeFlag);
static void		ClearPort(CGrafPtr port, HIShapeRef updateRgn);

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessApplicationEvent --
 *
 *	This processes Application level events, mainly activate and
 *	deactivate.
 *
 * Results:
 *	0.
 *
 * Side effects:
 *	Hide or reveal floating windows.
 *
 *----------------------------------------------------------------------
 */
d51 8
a58 6
MODULE_SCOPE int
TkMacOSXProcessApplicationEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
{
    Tcl_CmdInfo dummy;
d60 46
a105 6
    /*
     * This is a bit of a hack. We get "show" events both when we come back
     * from being hidden, and whenever we are activated. I only want to run
     * the "show" proc when we have been hidden already, not as a substitute
     * for <Activate>. So I use this toggle...
     */
d107 8
a114 1
    static int toggleHide = 0;
d116 4
a119 41
    switch (eventPtr->eKind) {
    case kEventAppActivated:
	ShowFloatingWindows();
	break;
    case kEventAppDeactivated:
	TkSuspendClipboard();
	HideFloatingWindows();
	break;
    case kEventAppQuit:
	statusPtr->stopProcessing = 1;
	break;
    case kEventAppHidden:
	if (toggleHide == 0) {
	    toggleHide = 1;
	    if (eventPtr->interp && Tcl_GetCommandInfo(eventPtr->interp,
		    "::tk::mac::OnHide", &dummy)) {
		Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnHide");
	    }
	}
	statusPtr->stopProcessing = 1;
	break;
    case kEventAppShown:
	if (toggleHide == 1) {
	    toggleHide = 0;
	    if (eventPtr->interp && Tcl_GetCommandInfo(eventPtr->interp,
		    "::tk::mac::OnShow", &dummy)) {
		Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnShow");
	    }
	}
	statusPtr->stopProcessing = 1;
	break;
    case kEventAppAvailableWindowBoundsChanged: {
	static UInt32 prevId = 0;
	UInt32 id;
	OSStatus err;

	err = ChkErr(GetEventParameter, eventPtr->eventRef,
		kEventParamTransactionID, typeUInt32, NULL, sizeof(id), NULL,
		&id);
	if (err != noErr || id != prevId) {
	    TkDisplay *dispPtr = TkGetDisplayList();
d121 3
a123 2
	    prevId = id;
	    TkMacOSXDisplayChanged(dispPtr->display);
a124 4
	/*
	 * Should we call ::tk::mac::OnDisplayChanged?
	 */
	break;
d126 10
a135 2
    default:
	break;
a136 1
    return 0;
d138 6
a143 16

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessAppearanceEvent --
 *
 *	This processes Appearance events.
 *
 * Results:
 *	0.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */
d145 2
a146 11
MODULE_SCOPE int
TkMacOSXProcessAppearanceEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
{
    switch (eventPtr->eKind) {
    case kEventAppearanceScrollBarVariantChanged:
	TkMacOSXInitScrollbarMetrics();
	break;
    default:
	break;
a147 1
    return 0;
d149 12
a160 16

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessWindowEvent --
 *
 *	This processes Window level events, mainly activate and deactivate.
 *
 * Results:
 *	0.
 *
 * Side effects:
 *	Cause Windows to be moved forward or backward in the window stack.
 *
 *----------------------------------------------------------------------
 */
d162 2
a163 27
MODULE_SCOPE int
TkMacOSXProcessWindowEvent(
    TkMacOSXEvent *eventPtr,
    MacEventStatus *statusPtr)
{
    OSStatus err;
    WindowRef whichWindow;
    Window window;
    int eventFound = false;
    TkDisplay *dispPtr;
    TkWindow *winPtr;

    switch (eventPtr->eKind) {
    case kEventWindowActivated:
    case kEventWindowDeactivated:
    case kEventWindowUpdate:
    case kEventWindowExpanding:
    case kEventWindowBoundsChanged:
    case kEventWindowDragStarted:
    case kEventWindowDragCompleted:
    case kEventWindowConstrain:
    case kEventWindowGetRegion:
    case kEventWindowDrawContent:
	break;
    default:
	return 0;
	break;
d165 13
a177 5
    err = ChkErr(GetEventParameter, eventPtr->eventRef,
	    kEventParamDirectObject, typeWindowRef, NULL, sizeof(whichWindow),
	    NULL, &whichWindow);
    if (err != noErr) {
	return 0;
d179 2
d182 21
a202 29
    window = TkMacOSXGetXWindow(whichWindow);
    dispPtr = TkGetDisplayList();
    winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window);

    switch (eventPtr->eKind) {
    case kEventWindowActivated:
    case kEventWindowDeactivated:
	if (window != None) {
	    int activate = (eventPtr->eKind == kEventWindowActivated);

	    eventFound |= GenerateActivateEvents(window, activate);
	    eventFound |= TkMacOSXGenerateFocusEvent(window, activate);
	    if (winPtr) {
		TkMacOSXEnterExitFullscreen(winPtr, activate);
	    }
	    statusPtr->stopProcessing = 1;
	}
	break;
    case kEventWindowUpdate:
	if (window != None && GenerateUpdateEvent(window)) {
	    eventFound = true;
	    statusPtr->stopProcessing = 1;
	}
	break;
    case kEventWindowExpanding:
	if (winPtr) {
	    winPtr->wmInfoPtr->hints.initial_state =
		    TkMacOSXIsWindowZoomed(winPtr) ? ZoomState : NormalState;
	    Tk_MapWindow((Tk_Window) winPtr);
d204 1
a204 6
	    /*
	     * Need to process all Tk events generated by Tk_MapWindow()
	     * before returning to ensure all children are mapped, as
	     * otherwise the Activate event that follows Expanding would not
	     * be processed by any unmapped children.
	     */
d206 21
a226 37
	    while (Tcl_ServiceEvent(TCL_WINDOW_EVENTS)) {/*empty body*/};
	    while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {/*empty body*/};
	}
	break;
    case kEventWindowBoundsChanged:
	if (winPtr) {
	    WmInfo *wmPtr = winPtr->wmInfoPtr;
	    UInt32 attr;
	    Rect bounds;
	    int x = -1, y = -1, width = -1, height = -1, flags = 0;

	    ChkErr(GetEventParameter, eventPtr->eventRef,
		    kEventParamAttributes, typeUInt32, NULL, sizeof(attr),
		    NULL, &attr);
	    ChkErr(GetEventParameter, eventPtr->eventRef,
		    kEventParamCurrentBounds, typeQDRectangle, NULL,
		    sizeof(bounds), NULL, &bounds);
	    if (attr & kWindowBoundsChangeOriginChanged) {
		x = bounds.left - wmPtr->xInParent;
		y = bounds.top - wmPtr->yInParent;
		flags |= TK_LOCATION_CHANGED;
	    }
	    if (attr & kWindowBoundsChangeSizeChanged) {
		width = bounds.right - bounds.left;
		height = bounds.bottom - bounds.top;
		flags |= TK_SIZE_CHANGED;
	    }
	    TkMacOSXInvalClipRgns((Tk_Window) winPtr);
	    TkMacOSXInvalidateWindow((MacDrawable*) window, TK_PARENT_WINDOW);
	    TkGenWMConfigureEvent((Tk_Window)winPtr, x, y, width, height,
		    flags);
	    if (attr & kWindowBoundsChangeUserResize ||
		    attr & kWindowBoundsChangeUserDrag) {
		TkMacOSXRunTclEventLoop();
	    }
	    if (wmPtr->attributes & kWindowResizableAttribute) {
		HIViewRef growBoxView;
d228 4
a231 6
		err = HIViewFindByID(HIViewGetRoot(whichWindow),
			kHIViewWindowGrowBoxID, &growBoxView);
		if (err == noErr) {
		    ChkErr(HIViewSetNeedsDisplay, growBoxView, true);
		}
	    }
d233 8
a240 69
	break;
    case kEventWindowDragStarted:
	if (!(TkMacOSXModifierState() & cmdKey)) { 
	    TkMacOSXBringWindowForward(whichWindow);
	}
	TkMacOSXTrackingLoop(1);
	break;
    case kEventWindowDragCompleted: {
	Rect maxBounds, bounds, strWidths;
	int h = 0, v = 0;

	TkMacOSXTrackingLoop(0);
	ChkErr(GetWindowGreatestAreaDevice, whichWindow, kWindowDragRgn, NULL,
		&maxBounds);
	ChkErr(GetWindowBounds, whichWindow, kWindowStructureRgn, &bounds);
	ChkErr(GetWindowStructureWidths, whichWindow, &strWidths);
	if (bounds.left > maxBounds.right - strWidths.left) {
	    h = maxBounds.right - (strWidths.left ? strWidths.left : 40)
		    - bounds.left;
	} else if (bounds.right < maxBounds.left + strWidths.right) {
	    h = maxBounds.left + (strWidths.right ? strWidths.right : 40)
		    - bounds.right;
	}
	if (bounds.top > maxBounds.bottom - strWidths.top) {
	    v = maxBounds.bottom - (strWidths.top ? strWidths.top : 40)
		    - bounds.top;
	} else if (bounds.bottom < maxBounds.top + strWidths.bottom) {
	    v = maxBounds.top + (strWidths.bottom ? strWidths.bottom : 40)
		    - bounds.bottom;
	} else if (strWidths.top && bounds.top < maxBounds.top) {
	    v = maxBounds.top - bounds.top;
	}
	if (h || v) {
	    OffsetRect(&bounds, h, v);
	    ChkErr(SetWindowBounds, whichWindow, kWindowStructureRgn,&bounds);
	}
	break;
    }
    case kEventWindowConstrain:
	if (winPtr && (winPtr->wmInfoPtr->flags & WM_FULLSCREEN) &&
		TkMacOSXMakeFullscreen(winPtr,whichWindow,1,NULL) == TCL_OK) {
	    statusPtr->stopProcessing = 1;
	}
	break;
    case kEventWindowGetRegion:
	if (winPtr && (winPtr->wmInfoPtr->flags & WM_TRANSPARENT)) {
	    WindowRegionCode code;

	    statusPtr->stopProcessing = (CallNextEventHandler(
		    eventPtr->callRef, eventPtr->eventRef) == noErr);
	    err = ChkErr(GetEventParameter, eventPtr->eventRef,
		    kEventParamWindowRegionCode, typeWindowRegionCode, NULL,
		    sizeof(code), NULL, &code);
	    if (err == noErr && code == kWindowOpaqueRgn) {
		RgnHandle rgn;

		err = ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamRgnHandle, typeQDRgnHandle, NULL,
			sizeof(rgn), NULL, &rgn);
		if (err == noErr) {
		    SetEmptyRgn(rgn);
		    statusPtr->stopProcessing = 1;
		}
	    }
	}
	break;
    case kEventWindowDrawContent:
	if (winPtr && (winPtr->wmInfoPtr->flags & WM_TRANSPARENT)) {
	    CGrafPtr port;
d242 2
a243 4
	    GetPort(&port);
	    ClearPort(port, NULL);
	}
	break;
a244 2

    return eventFound;
d246 1
a246 17

/*
 *----------------------------------------------------------------------
 *
 * GenerateUpdateEvent --
 *
 *	Given a Macintosh window update event this function generates all the
 *	Expose XEvents needed by Tk.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *	Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */
d248 1
a248 61
static int
GenerateUpdateEvent(
    Window window)
{
    WindowRef macWindow;
    TkDisplay *dispPtr;
    TkWindow  *winPtr;
    int result = 0;
    CGRect updateBounds;
    HIShapeRef rgn;
    HIMutableShapeRef updateRgn;
    int dx, dy;

    dispPtr = TkGetDisplayList();
    winPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display, window);

    if (winPtr ==NULL ){
	return result;
    }
    macWindow = TkMacOSXDrawableWindow(window);
    TK_IF_MAC_OS_X_API (5, HIWindowCopyShape,
	ChkErr(HIWindowCopyShape, macWindow, kWindowUpdateRgn,
		kHICoordSpaceWindow, &rgn);
	dx = -winPtr->wmInfoPtr->xInParent;
	dy = -winPtr->wmInfoPtr->yInParent;
    ) TK_ELSE_MAC_OS_X (5,
	Rect bounds;

	TkMacOSXCheckTmpQdRgnEmpty();
	ChkErr(GetWindowRegion, macWindow, kWindowUpdateRgn, tkMacOSXtmpQdRgn);
	rgn = HIShapeCreateWithQDRgn(tkMacOSXtmpQdRgn);
	SetEmptyRgn(tkMacOSXtmpQdRgn);
	ChkErr(GetWindowBounds, macWindow, kWindowContentRgn, &bounds);
	dx = -bounds.left;
	dy = -bounds.top;
    ) TK_ENDIF;

    updateRgn = HIShapeCreateMutableCopy(rgn);
    CFRelease(rgn);
    ChkErr(HIShapeOffset, updateRgn, dx, dy);
    HIShapeGetBounds(updateRgn, &updateBounds);
#ifdef TK_MAC_DEBUG_CLIP_REGIONS
    TkMacOSXDebugFlashRegion(window, updateRgn);
#endif /* TK_MAC_DEBUG_CLIP_REGIONS */
    BeginUpdate(macWindow);
    if (winPtr->wmInfoPtr->flags & WM_TRANSPARENT) {
	ClearPort(TkMacOSXGetDrawablePort(window), updateRgn);
    }
    result = GenerateUpdates(updateRgn, &updateBounds, winPtr);
    EndUpdate(macWindow);
    CFRelease(updateRgn);
    if (result) {
	/*
	 * Ensure there are no pending idle-time redraws that could prevent
	 * the just posted Expose events from generating new redraws.
	 */

	Tcl_DoOneEvent(TCL_IDLE_EVENTS|TCL_DONT_WAIT);
    }
    return result;
 }
d284 3
a286 5
    TK_IF_MAC_OS_X_API (4, HIShapeIntersectsRect,
	if (!HIShapeIntersectsRect(updateRgn, &bounds)) {
	    return 0;
	}
    ) TK_ENDIF
d300 4
a303 2
    ChkErr(TkMacOSHIShapeUnion, boundsRgn, updateRgn, updateRgn);
    HIShapeGetBounds(updateRgn, updateBounds);
d307 1
a307 1
    event.xany.serial = Tk_Display(winPtr)->request;
d318 4
d372 1
a372 1
    Window window,		/* Root X window for event. */
d375 21
a395 2
    TkWindow *winPtr;
    TkDisplay *dispPtr;
d397 5
a401 8
    dispPtr = TkGetDisplayList();
    winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window);
    if (winPtr == NULL || winPtr->window == None) {
	return false;
    }

    TkGenerateActivateEvents(winPtr,activeFlag);
    return true;
d423 1
a423 1
    Window window,		/* Root X window for event. */
a426 8
    Tk_Window tkwin;
    TkDisplay *dispPtr;

    dispPtr = TkGetDisplayList();
    tkwin = Tk_IdToWindow(dispPtr->display, window);
    if (tkwin == NULL) {
	return false;
    }
d433 2
a434 3
    if (((TkWindow *)tkwin)->wmInfoPtr->macClass == kHelpWindowClass ||
	    ((TkWindow *)tkwin)->wmInfoPtr->attributes &
		    kWindowNoActivatesAttribute) {
d449 1
a449 1
    event.xany.serial = dispPtr->display->request;
d451 2
a452 2
    event.xfocus.display = dispPtr->display;
    event.xfocus.window = window;
d495 1
a495 1
    event.xconfigure.serial = Tk_Display(tkwin)->request;
d521 5
a525 1
    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
d614 1
a614 1
    event.xany.serial = Tk_Display(tkwin)->request;
d623 1
a623 1
    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
d718 1
a718 1
    
d721 167
a887 1

d889 3
a891 13
 *----------------------------------------------------------------------
 *
 * ClearPort --
 *
 *	Clear (i.e. fill with transparent color) the given port.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
d894 27
a920 21
static void
ClearPort(
    CGrafPtr port,
    HIShapeRef updateRgn)
{
    CGContextRef context;
    Rect bounds;
    CGRect rect;

    GetPortBounds(port, &bounds);
    QDBeginCGContext(port, &context);
    SyncCGContextOriginWithPort(context, port);
    CGContextConcatCTM(context, CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0,
	    bounds.bottom - bounds.top));
    if (updateRgn) {
	ChkErr(HIShapeReplacePathInCGContext, updateRgn, context);
	CGContextEOClip(context);
    }
    rect = CGRectMake(0, 0, bounds.right, bounds.bottom);
    CGContextClearRect(context, rect);
    QDEndCGContext(port, &context);
d922 85
d1010 1
a1010 1
 * fill-column: 78
d1012 2
@


1.34
log
@        TIP 337

        * generic/tkBind.c:     Updated callers of Tcl_BackgroundError()
        * generic/tkCanvas.c:   to use the new routine
        * generic/tkEntry.c:    Tcl_BackgroundException() as appropriate.
        * generic/tkImgBmap.c:
        * generic/tkListbox.c:
        * generic/tkSelect.c:
        * generic/tkTextDisp.c:
        * generic/tkTextWind.c:
        * macosx/tkMacOSXHLEvents.c:
        * macosx/tkMacOSXMenu.c:
        * macosx/tkMacOSXMenus.c:
        * macosx/tkMacOSXScale.c:
        * macosx/tkMacOSXWindowEvent.c:
        * unix/tkUnixScale.c:
        * unix/tkUnixWm.c:
        * win/tkWinButton.c:
        * win/tkWinMenu.c:
        * win/tkWinScrlbr.c:
        * win/tkWinWm.c:
@
text
@d51 1
a51 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.33 2008/10/05 21:26:11 dkf Exp $
d894 1
a894 1
		Tk_BackgroundException(interp, result);
@


1.33
log
@minor improvements in legibility
@
text
@d51 1
a51 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.32 2008/06/19 00:11:08 das Exp $
d894 1
a894 1
		Tk_BackgroundError(interp);
@


1.32
log
@	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessWindowEvent): fix
	return value.
@
text
@d4 2
a5 2
 *	This file defines the routines for both creating and handling
 *	Window Manager class events for Tk.
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: tkMacOSXWindowEvent.c,v 1.31 2007/12/13 15:27:10 dgp Exp $
d69 5
a73 6
static int GenerateUpdateEvent(Window window);
static int GenerateUpdates(HIMutableShapeRef updateRgn, CGRect *updateBounds,
	TkWindow *winPtr);
static int GenerateActivateEvents(Window window, int activeFlag);
static void ClearPort(CGrafPtr port, HIShapeRef updateRgn);

d80 2
a81 2
 *	This processes Application level events, mainly activate
 *	and deactivate.
d94 2
a95 2
	TkMacOSXEvent *eventPtr,
	MacEventStatus *statusPtr)
d105 1
d109 16
a124 17
	case kEventAppActivated:
	    ShowFloatingWindows();
	    break;
	case kEventAppDeactivated:
	    TkSuspendClipboard();
	    HideFloatingWindows();
	    break;
	case kEventAppQuit:
	    statusPtr->stopProcessing = 1;
	    break;
	case kEventAppHidden:
	    if (toggleHide == 0) {
		toggleHide = 1;
		if (eventPtr->interp && Tcl_GetCommandInfo(eventPtr->interp,
			"::tk::mac::OnHide", &dummy)) {
		    Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnHide");
		}
d126 9
a134 9
	    statusPtr->stopProcessing = 1;
	    break;
	case kEventAppShown:
	    if (toggleHide == 1) {
		toggleHide = 0;
		if (eventPtr->interp && Tcl_GetCommandInfo(eventPtr->interp,
			"::tk::mac::OnShow", &dummy)) {
		    Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnShow");
		}
d136 13
a148 12
	    statusPtr->stopProcessing = 1;
	    break;
	case kEventAppAvailableWindowBoundsChanged: {
	    static UInt32 prevId = 0;
	    UInt32 id;
	    OSStatus err;

	    err = ChkErr(GetEventParameter, eventPtr->eventRef,
		    kEventParamTransactionID, typeUInt32,
		    NULL, sizeof(id), NULL, &id);
	    if (err != noErr || id != prevId) {
		TkDisplay *dispPtr = TkGetDisplayList();
d150 2
a151 7
		prevId = id;
		TkMacOSXDisplayChanged(dispPtr->display);
	    }
	    /*
	     * Should we call ::tk::mac::OnDisplayChanged?
	     */
	    break;
d153 7
a159 2
	default:
	    break;
d182 2
a183 2
	TkMacOSXEvent *eventPtr,
	MacEventStatus *statusPtr)
d186 5
a190 5
	case kEventAppearanceScrollBarVariantChanged:
	    TkMacOSXInitScrollbarMetrics();
	    break;
	default:
	    break;
d200 1
a200 2
 *	This processes Window level events, mainly activate
 *	and deactivate.
d206 1
a206 2
 *	Cause Windows to be moved forward or backward in the
 *	window stack.
d213 2
a214 2
	TkMacOSXEvent * eventPtr,
	MacEventStatus * statusPtr)
d224 14
a237 14
	case kEventWindowActivated:
	case kEventWindowDeactivated:
	case kEventWindowUpdate:
	case kEventWindowExpanding:
	case kEventWindowBoundsChanged:
	case kEventWindowDragStarted:
	case kEventWindowDragCompleted:
	case kEventWindowConstrain:
	case kEventWindowGetRegion:
	case kEventWindowDrawContent:
	    break;
	default:
	    return 0;
	    break;
d248 1
a248 1
    winPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display, window);
d251 7
a257 20
	case kEventWindowActivated:
	case kEventWindowDeactivated:
	    if (window != None) {
		int activate = (eventPtr->eKind == kEventWindowActivated);

		eventFound |= GenerateActivateEvents(window, activate);
		eventFound |= TkMacOSXGenerateFocusEvent(window, activate);
		if (winPtr) {
		    TkMacOSXEnterExitFullscreen(winPtr, activate);
		}
		statusPtr->stopProcessing = 1;
	    }
	    break;
	case kEventWindowUpdate:
	    if (window != None && GenerateUpdateEvent(window)) {
		eventFound = true;
		statusPtr->stopProcessing = 1;
	    }
	    break;
	case kEventWindowExpanding:
d259 1
a259 12
		winPtr->wmInfoPtr->hints.initial_state =
			TkMacOSXIsWindowZoomed(winPtr) ? ZoomState : 
			NormalState;
		Tk_MapWindow((Tk_Window) winPtr);
		/*
		 * Need to process all Tk events generated by Tk_MapWindow()
		 * before returning to ensure all children are mapped, as
		 * otherwise the Activate event that follows Expanding would
		 * not be processed by any unmapped children.
		 */
		while (Tcl_ServiceEvent(TCL_WINDOW_EVENTS)) {};
		while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {};
d261 21
a281 35
	    break;
	case kEventWindowBoundsChanged:
	    if (winPtr) {
		WmInfo *wmPtr = winPtr->wmInfoPtr;
		UInt32 attr;
		Rect bounds;
		int x = -1, y = -1, width = -1, height = -1, flags = 0;

		ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamAttributes, typeUInt32,
			NULL, sizeof(attr), NULL, &attr);
		ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamCurrentBounds, typeQDRectangle,
			NULL, sizeof(bounds), NULL, &bounds);
		if (attr & kWindowBoundsChangeOriginChanged) {
		    x = bounds.left - wmPtr->xInParent;
		    y = bounds.top	- wmPtr->yInParent;
		    flags |= TK_LOCATION_CHANGED;
		}
		if (attr & kWindowBoundsChangeSizeChanged) {
		    width = bounds.right  - bounds.left;
		    height = bounds.bottom - bounds.top;
		    flags |= TK_SIZE_CHANGED;
		}
		TkMacOSXInvalClipRgns((Tk_Window) winPtr);
		TkMacOSXInvalidateWindow((MacDrawable *) window,
			TK_PARENT_WINDOW);
		TkGenWMConfigureEvent((Tk_Window)winPtr, x, y, width,
			height, flags);
		if (attr & kWindowBoundsChangeUserResize ||
			attr & kWindowBoundsChangeUserDrag) {
		    TkMacOSXRunTclEventLoop();
		}
		if (wmPtr->attributes & kWindowResizableAttribute) {
		    HIViewRef growBoxView;
d283 42
a324 5
		    err = HIViewFindByID(HIViewGetRoot(whichWindow),
			    kHIViewWindowGrowBoxID, &growBoxView);
		    if (err == noErr) {
			ChkErr(HIViewSetNeedsDisplay, growBoxView, true);
		    }
d327 56
a382 56
	    break;
	case kEventWindowDragStarted:
	    if (!(TkMacOSXModifierState() & cmdKey)) { 
		TkMacOSXBringWindowForward(whichWindow);
	    }
	    TkMacOSXTrackingLoop(1);
	    break;
	case kEventWindowDragCompleted: {
	    Rect maxBounds, bounds, strWidths;
	    int h = 0, v = 0;

	    TkMacOSXTrackingLoop(0);
	    ChkErr(GetWindowGreatestAreaDevice, whichWindow,
		    kWindowDragRgn, NULL, &maxBounds);
	    ChkErr(GetWindowBounds, whichWindow, kWindowStructureRgn,
		    &bounds);
	    ChkErr(GetWindowStructureWidths, whichWindow, &strWidths);
	    if (bounds.left > maxBounds.right - strWidths.left) {
		h = maxBounds.right
			- (strWidths.left ? strWidths.left : 40)
			- bounds.left;
	    } else if (bounds.right < maxBounds.left
		    + strWidths.right) {
		h = maxBounds.left
			+ (strWidths.right ? strWidths.right : 40)
			- bounds.right;
	    }
	    if (bounds.top > maxBounds.bottom - strWidths.top) {
		v = maxBounds.bottom
			- (strWidths.top ? strWidths.top : 40)
			- bounds.top;
	    } else if (bounds.bottom < maxBounds.top
		    + strWidths.bottom) {
		v = maxBounds.top
			+ (strWidths.bottom ? strWidths.bottom : 40)
			- bounds.bottom;
	    } else if (strWidths.top && bounds.top < maxBounds.top) {
		v = maxBounds.top - bounds.top;
	    }
	    if (h || v) {
		OffsetRect(&bounds, h, v);
		ChkErr(SetWindowBounds, whichWindow,
		    kWindowStructureRgn, &bounds);
	    }
	    break;
	}
	case kEventWindowConstrain:
	    if (winPtr && (winPtr->wmInfoPtr->flags & WM_FULLSCREEN) &&
		    TkMacOSXMakeFullscreen(winPtr, whichWindow, 1,
		    NULL) == TCL_OK) {
		statusPtr->stopProcessing = 1;
	    }
	    break;
	case kEventWindowGetRegion:
	    if (winPtr && (winPtr->wmInfoPtr->flags & WM_TRANSPARENT)) {
		WindowRegionCode code;
a383 2
		statusPtr->stopProcessing = (CallNextEventHandler(
			eventPtr->callRef, eventPtr->eventRef) == noErr);
d385 5
a389 12
			kEventParamWindowRegionCode, typeWindowRegionCode,
			NULL, sizeof(code), NULL, &code);
		if (err == noErr && code == kWindowOpaqueRgn) {
		    RgnHandle rgn;

		    err = ChkErr(GetEventParameter, eventPtr->eventRef,
			    kEventParamRgnHandle, typeQDRgnHandle, NULL,
			    sizeof(rgn), NULL, &rgn);
		    if (err == noErr) {
			SetEmptyRgn(rgn);
			statusPtr->stopProcessing = 1;
		    }
d392 5
a396 4
	    break;
	case kEventWindowDrawContent:
	    if (winPtr && (winPtr->wmInfoPtr->flags & WM_TRANSPARENT)) {
		CGrafPtr port;
d398 4
a401 4
		GetPort(&port);
		ClearPort(port, NULL);
	    }
	    break;
d412 2
a413 2
 *	Given a Macintosh window update event this function generates
 *	all the Expose XEvents needed by Tk.
d423 1
d425 2
a426 1
GenerateUpdateEvent(Window window)
d459 2
a460 1
    ) TK_ENDIF
d491 4
a494 4
 *	Given a Macintosh update region and a Tk window this function
 *	geneates a X Expose event for the window if it is within the
 *	update region. The function will then recursivly have each
 *	damaged window generate Expose events for its child windows.
d584 1
a584 1

d590 2
a591 2
 *	Given a Macintosh window activate event this function generates all the
 *	X Activate events needed by Tk.
d604 2
a605 2
    Window window,		  /* Root X window for event. */
    int activeFlag )
d619 1
a619 1

d625 2
a626 2
 *	Given a Macintosh window activate event this function generates all the
 *	X Focus events needed by Tk.
d640 1
a640 1
    int activeFlag )
d653 2
a654 2
     * Don't send focus events to windows of class help or to
     * windows with the kWindowNoActivatesAttribute.
d656 1
d664 2
a665 2
     * Generate FocusIn and FocusOut events. This event
     * is only sent to the toplevel window.
d690 2
a691 3
 *	Generate a ConfigureNotify event for Tk. Depending on the
 *	value of flag the values of width/height, x/y, or both may
 *	be changed.
d751 1
d769 1
a769 1
			+ (width - winPtr->reqWidth)/wmPtr->widthInc;
d785 1
a785 1
			+ (height - winPtr->reqHeight)/wmPtr->heightInc;
d801 3
a803 3
     * this is what we want - so we just set them. However, we need to
     * make sure the windows clipping region is marked invalid so the
     * change is visible to the subwindow.
d805 1
d853 3
a855 3
 *	ClientMessage event arrives whose type is "WM_PROTOCOLS".
 *	This procedure handles the message from the window manager
 *	in an appropriate fashion.
d861 1
a861 2
 *	Depends on what sort of handler, if any, was set up for the
 *	protocol.
d883 1
a883 1
		protPtr = protPtr->nextPtr) {
d885 1
a885 1
	    Tcl_Preserve((ClientData) protPtr);
d887 1
a887 1
	    Tcl_Preserve((ClientData) interp);
d896 2
a897 2
	    Tcl_Release((ClientData) interp);
	    Tcl_Release((ClientData) protPtr);
d903 2
a904 2
     * No handler was present for this protocol. If this is a
     * WM_DELETE_WINDOW message then just destroy the window.
d958 1
d981 7
@


1.31
log
@merge stable branch onto HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.22.2.8 2007/11/12 19:22:39 dgp Exp $
d421 1
a421 1
    return 0;
@


1.31.2.1
log
@	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessWindowEvent): fix
	return value.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.31 2007/12/13 15:27:10 dgp Exp $
d421 1
a421 1
    return eventFound;
@


1.30
log
@	* macosx/tkMacOSXWindowEvent.c:	handle kEventWindowExpanding carbon
	* macosx/tkMacOSXCarbonEvents.c: event instead of kEventWindowExpanded
					to ensure activate event arrives after
					window is remapped, also need to
					process all Tk events generated by
					remapping in the event handler to
					ensure children are remapped before
					activate event is processed.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.29 2007/10/12 03:14:48 das Exp $
@


1.29
log
@	* macosx/tkMacOSXDraw.c:	replace all (internal) use of QD region
	* macosx/tkMacOSXSubwindows.c:	API by HIShape API, with conversion to
	* macosx/tkMacOSXWindowEvent.c	QD regions only when required by legacy
	* macosx/tkMacOSXPrivate.h:	Carbon or Tk API.
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXDebug.c:
	* macosx/tkMacOSXDebug.h:

	* macosx/tkMacOSXInt.h:		replace MacDrawable's QD RgnHandles
	* macosx/tkMacOSXEmbed.c:	clipRgn, aboveClipRgn & drawRgn by
	* macosx/tkMacOSXMenu.c:	HIShapeRefs visRgn & aboveVisRgn and
	* macosx/tkMacOSXSubwindows.c:	CGRect drawRect.

	* macosx/tkMacOSXWindowEvent.c:	remove use of QD port vis rgn in window
	* macosx/tkMacOSXSubwindows.c:	update rgn calculation, manually excise
	* macosx/tkMacOSXWm.c:		growbox from toplevel clip rgn instead.

	* macosx/tkMacOSXDraw.c:	replace use of QD port clip rgn by new
	* macosx/tkMacOSXPrivate.h:	clipRgn fld in TkMacOSXDrawingContext;
					handle QD/CG drawing mismatches in
					XCopyArea, XCopyPlane and TkPutImage;
					cleanup/speedup CGContext setup in
					TkMacOSXSetupDrawingContext().

	* macosx/tkMacOSXDraw.c:	change TkMacOSXSetupDrawingContext() to
	* macosx/tkMacOSXEntry.c:	return boolean indicating whether
	* macosx/tkMacOSXFont.c:	drawing is allowed (and was setup) or
	* macosx/tkMacOSXMenu.c:	not (e.g. when clipRgn is empty).
	* macosx/ttkMacOSXTheme.c:

	* macosx/tkMacOSXSubwindows.c:	signal that drawable is a pixmap via
	* macosx/tkMacOSXInt.h:		new explicit TK_IS_PIXMAP flag instead
					of a NULL cligRgn field.

	* macosx/tkMacOSXRegion.c:	add wrappers for missing/buggy HIShape
	* macosx/tkMacOSXPrivate.h:	API, and private helpers to operate on
					HIShapeRefs & convert to/from TkRegion.

	* macosx/tkMacOSXRegion.c:	add Tkp{Retain,Release}Region() API for
	* macosx/tkMacOSXInt.h:		TkRegion.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.28 2007/07/09 08:31:55 das Exp $
d235 1
a235 1
	case kEventWindowExpanded:
d278 1
a278 1
	case kEventWindowExpanded:
d280 12
a291 2
		TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
			ZoomState : NormalState);
@


1.28
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: tkMacOSXWindowEvent.c,v 1.27 2007/06/29 03:20:02 das Exp $
d76 1
a76 1
static int GenerateUpdates(RgnHandle updateRgn, Rect *updateBounds,
d79 1
a79 1
static void ClearPort(CGrafPtr port, RgnHandle updateRgn);
a432 1
    CGrafPtr destPort;
d437 4
a440 1
    Rect updateBounds, bounds;
d448 21
a468 8
    TkMacOSXCheckTmpQdRgnEmpty();
    destPort = TkMacOSXGetDrawablePort(window);
    macWindow = GetWindowFromPort(destPort);
    ChkErr(GetWindowRegion, macWindow, kWindowUpdateRgn, tkMacOSXtmpQdRgn);
    ChkErr(GetWindowBounds, macWindow, kWindowContentRgn, &bounds);
    OffsetRgn(tkMacOSXtmpQdRgn, -bounds.left, -bounds.top);
    SectRegionWithPortVisibleRegion(destPort, tkMacOSXtmpQdRgn);
    GetRegionBounds(tkMacOSXtmpQdRgn, &updateBounds);
d470 1
a470 1
    TkMacOSXDebugFlashRegion(window, tkMacOSXtmpQdRgn);
d474 1
a474 1
	ClearPort(destPort, tkMacOSXtmpQdRgn);
d476 1
a476 1
    result = GenerateUpdates(tkMacOSXtmpQdRgn, &updateBounds, winPtr);
d478 1
a478 1
    SetEmptyRgn(tkMacOSXtmpQdRgn);
d511 2
a512 2
    RgnHandle updateRgn,
    Rect *updateBounds,
d517 2
a518 2
    Rect bounds, damageBounds;
    static RgnHandle damageRgn = NULL;
d520 2
a521 8
    TkMacOSXWinBounds(winPtr, &bounds);
    if (bounds.top > updateBounds->bottom ||
	updateBounds->top > bounds.bottom ||
	bounds.left > updateBounds->right ||
	updateBounds->left > bounds.right) {
	return 0;
    }
    if (!RectInRgn(&bounds, updateRgn)) {
d524 5
d534 6
a539 2
    if (damageRgn == NULL) {
	damageRgn = NewRgn();
d541 5
a545 7
    RectRgn(damageRgn, &bounds);
    SectRgn(damageRgn, updateRgn, damageRgn);
    GetRegionBounds(damageRgn, &damageBounds);
    RectRgn(damageRgn, &bounds);
    UnionRgn(damageRgn, updateRgn, updateRgn);
    GetRegionBounds(updateRgn, updateBounds);
    SetEmptyRgn(damageRgn);
d552 4
a555 4
    event.xexpose.x = damageBounds.left - bounds.left;
    event.xexpose.y = damageBounds.top - bounds.top;
    event.xexpose.width = damageBounds.right - damageBounds.left;
    event.xexpose.height = damageBounds.bottom - damageBounds.top;
d964 1
a964 1
    RgnHandle updateRgn)
d976 2
a977 1
	ClipCGContextToRegion(context, &bounds, updateRgn);
@


1.27
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: tkMacOSXWindowEvent.c,v 1.26 2007/06/09 17:09:41 das Exp $
a71 8
 * Declarations of global variables defined in this file.
 */

static int tkMacOSXAppInFront = true;	/* Boolean variable for determining if
					 * we are the frontmost app. Only set
					 * in TkMacOSXProcessApplicationEvent
					 */
/*
d94 1
a94 1
 *	Hide or reveal floating windows, and set tkMacOSXAppInFront.
a115 1
	    tkMacOSXAppInFront = true;
a119 1
	    tkMacOSXAppInFront = false;
a327 1
	    TkMacOSXTrackingLoop(1);
d331 1
d918 10
a927 1
    return tkMacOSXAppInFront;
@


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

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

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

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

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

	* macosx/Wish.xcodeproj/project.pbxproj: add new Tclsh-Info.plist.in.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.25 2007/06/03 13:44:40 das Exp $
d60 1
a60 1
#include "tkMacOSXInt.h"
d448 1
a448 1
    Rect updateBounds;
d456 1
a456 1
    TkMacOSXCheckTmpRgnEmpty(1);
d459 5
a463 4
    ChkErr(GetWindowRegion, macWindow, kWindowUpdateRgn, tkMacOSXtmpRgn1);
    QDGlobalToLocalRegion(destPort, tkMacOSXtmpRgn1);
    SectRegionWithPortVisibleRegion(destPort, tkMacOSXtmpRgn1);
    GetRegionBounds(tkMacOSXtmpRgn1, &updateBounds);
d465 1
a465 1
    TkMacOSXDebugFlashRegion(destPort, tkMacOSXtmpRgn1);
d469 1
a469 1
	ClearPort(destPort, tkMacOSXtmpRgn1);
d471 1
a471 1
    result = GenerateUpdates(tkMacOSXtmpRgn1, &updateBounds, winPtr);
d473 1
a473 1
    SetEmptyRgn(tkMacOSXtmpRgn1);
a534 1
    OffsetRgn(damageRgn, -bounds.left, -bounds.top);
d546 4
a549 4
    event.xexpose.x = damageBounds.left;
    event.xexpose.y = damageBounds.top;
    event.xexpose.width = damageBounds.right-damageBounds.left;
    event.xexpose.height = damageBounds.bottom-damageBounds.top;
d957 3
@


1.25
log
@	* macosx/tkMacOSXDraw.c:	comment formatting fix for Xcode 3.0.
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.24 2007/05/31 13:38:17 das Exp $
d459 1
a459 1
    GetWindowRegion(macWindow, kWindowUpdateRgn, tkMacOSXtmpRgn1);
@


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

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

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

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

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

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

	* macosx/tkMacOSXColor.c:	cleanup whitespace and formatting.
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.23 2007/05/30 06:35:55 das Exp $
d576 1
a576 1
	 * NOTE: Here we should handle out of process embedding.
a577 1

@


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

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

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

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

	* macosx/Wish.xcodeproj/project.pbxproj: delete references to removed
	* macosx/Wish.xcodeproj/default.pbxuser: ttk files.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.22 2007/05/09 12:55:16 das Exp $
d317 3
d473 8
d536 3
@


1.22
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: tkMacOSXWindowEvent.c,v 1.21 2007/04/23 21:24:34 das Exp $
a78 2
static RgnHandle gDamageRgn = NULL;

d83 5
a87 4
static int GenerateUpdateEvent( Window window);
static int GenerateUpdates( RgnHandle updateRgn, TkWindow *winPtr);
static int GenerateActivateEvents( Window window, int activeFlag);
static void ClearPort(CGrafPtr port);
d413 1
a413 1
		ClearPort(port);
d440 6
a445 5
    CGrafPtr	destPort;
    WindowRef	macWindow;
    TkDisplay * dispPtr;
    TkWindow  * winPtr;
    int		result = 0;
a452 3
    if (gDamageRgn == NULL) {
	gDamageRgn = NewRgn();
    }
d459 1
d461 1
a461 6
    TkMacOSXInitNamedDebugSymbol(HIToolbox, int, QDDebugFlashRegion,
				CGrafPtr port, RgnHandle region);
    if (QDDebugFlashRegion) {
	/* Carbon-internal region flashing SPI (c.f. Technote 2124) */
	QDDebugFlashRegion(destPort, tkMacOSXtmpRgn1);
    }
d465 1
a465 1
	ClearPort(destPort);
d467 1
a467 1
    result = GenerateUpdates(tkMacOSXtmpRgn1, winPtr);
a469 1
    SetEmptyRgn(gDamageRgn);
d495 1
d500 2
a501 1
    Rect bounds, updateBounds, damageBounds;
d504 4
a507 7
    GetRegionBounds(updateRgn,&updateBounds);

    if (bounds.top > updateBounds.bottom ||
	updateBounds.top > bounds.bottom ||
	bounds.left > updateBounds.right ||
	updateBounds.left > bounds.right ||
	!RectInRgn(&bounds, updateRgn)) {
d514 13
a530 1

a531 13

    /*
     * Compute the bounding box of the area that the damage occured in.
     */

    /*
     * CopyRgn(TkMacOSXVisableClipRgn(winPtr), rgn);
     * TODO: this call doesn't work doing resizes!!!
     */
    RectRgn(gDamageRgn, &bounds);
    SectRgn(gDamageRgn, updateRgn, gDamageRgn);
    OffsetRgn(gDamageRgn, -bounds.left, -bounds.top);
    GetRegionBounds(gDamageRgn,&damageBounds);
a536 1

d544 1
a544 1
				       childPtr = childPtr->nextPtr) {
d548 1
a548 2

	GenerateUpdates(updateRgn, childPtr);
d558 1
a558 1
	    GenerateUpdates(updateRgn, childPtr);
d913 1
a913 1
Tk_MacOSXIsAppInFront (void)
d934 4
a937 1
ClearPort(CGrafPtr port) {
d944 3
@


1.22.2.1
log
@merge updates from HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.23 2007/05/30 06:35:55 das Exp $
d79 2
d85 4
a88 5
static int GenerateUpdateEvent(Window window);
static int GenerateUpdates(RgnHandle updateRgn, Rect *updateBounds,
	TkWindow *winPtr);
static int GenerateActivateEvents(Window window, int activeFlag);
static void ClearPort(CGrafPtr port, RgnHandle updateRgn);
d414 1
a414 1
		ClearPort(port, NULL);
d441 5
a445 6
    CGrafPtr destPort;
    WindowRef macWindow;
    TkDisplay *dispPtr;
    TkWindow  *winPtr;
    int result = 0;
    Rect updateBounds;
d453 3
a461 1
    GetRegionBounds(tkMacOSXtmpRgn1, &updateBounds);
d463 6
a468 1
    TkMacOSXDebugFlashRegion(destPort, tkMacOSXtmpRgn1);
d472 1
a472 1
	ClearPort(destPort, tkMacOSXtmpRgn1);
d474 1
a474 1
    result = GenerateUpdates(tkMacOSXtmpRgn1, &updateBounds, winPtr);
d477 1
a502 1
    Rect *updateBounds,
d507 1
a507 2
    Rect bounds, damageBounds;
    static RgnHandle damageRgn = NULL;
d510 7
a516 4
    if (bounds.top > updateBounds->bottom ||
	updateBounds->top > bounds.bottom ||
	bounds.left > updateBounds->right ||
	updateBounds->left > bounds.right) {
a522 13
    /*
     * Compute the bounding box of the area that the damage occured in.
     */

    if (damageRgn == NULL) {
	damageRgn = NewRgn();
    }
    RectRgn(damageRgn, &bounds);
    SectRgn(damageRgn, updateRgn, damageRgn);
    OffsetRgn(damageRgn, -bounds.left, -bounds.top);
    GetRegionBounds(damageRgn, &damageBounds);
    SetEmptyRgn(damageRgn);

d527 1
d529 13
d547 1
d555 1
a555 1
	    childPtr = childPtr->nextPtr) {
d559 2
a560 1
	GenerateUpdates(updateRgn, updateBounds, childPtr);
d570 1
a570 1
	    GenerateUpdates(updateRgn, updateBounds, childPtr);
d925 1
a925 1
Tk_MacOSXIsAppInFront(void)
d946 1
a946 4
ClearPort(
    CGrafPtr port,
    RgnHandle updateRgn)
{
a952 3
    if (updateRgn) {
	ClipCGContextToRegion(context, &bounds, updateRgn);
    }
@


1.22.2.2
log
@merge updates from HEAD
@
text
@a316 3
		TkMacOSXInvalClipRgns((Tk_Window) winPtr);
		TkMacOSXInvalidateWindow((MacDrawable *) window,
			TK_PARENT_WINDOW);
a469 8
    if (result) {
	/*
	 * Ensure there are no pending idle-time redraws that could prevent
	 * the just posted Expose events from generating new redraws.
	 */

	Tcl_DoOneEvent(TCL_IDLE_EVENTS|TCL_DONT_WAIT);
    }
a524 3
    RectRgn(damageRgn, &bounds);
    UnionRgn(damageRgn, updateRgn, updateRgn);
    GetRegionBounds(updateRgn, updateBounds);
@


1.22.2.3
log
@merge updates from HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.22.2.2 2007/06/01 04:01:39 dgp Exp $
d576 1
a576 1
	 * TODO: Here we should handle out of process embedding.
d578 1
@


1.22.2.4
log
@merge updates from HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.22.2.3 2007/06/04 15:19:01 dgp Exp $
d459 1
a459 1
    ChkErr(GetWindowRegion, macWindow, kWindowUpdateRgn, tkMacOSXtmpRgn1);
@


1.22.2.5
log
@merge updates from HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id$
d60 1
a60 1
#include "tkMacOSXPrivate.h"
d448 1
a448 1
    Rect updateBounds, bounds;
d456 1
a456 1
    TkMacOSXCheckTmpQdRgnEmpty();
d459 4
a462 5
    ChkErr(GetWindowRegion, macWindow, kWindowUpdateRgn, tkMacOSXtmpQdRgn);
    ChkErr(GetWindowBounds, macWindow, kWindowContentRgn, &bounds);
    OffsetRgn(tkMacOSXtmpQdRgn, -bounds.left, -bounds.top);
    SectRegionWithPortVisibleRegion(destPort, tkMacOSXtmpQdRgn);
    GetRegionBounds(tkMacOSXtmpQdRgn, &updateBounds);
d464 1
a464 1
    TkMacOSXDebugFlashRegion(window, tkMacOSXtmpQdRgn);
d468 1
a468 1
	ClearPort(destPort, tkMacOSXtmpQdRgn);
d470 1
a470 1
    result = GenerateUpdates(tkMacOSXtmpQdRgn, &updateBounds, winPtr);
d472 1
a472 1
    SetEmptyRgn(tkMacOSXtmpQdRgn);
d534 1
d546 4
a549 4
    event.xexpose.x = damageBounds.left - bounds.left;
    event.xexpose.y = damageBounds.top - bounds.top;
    event.xexpose.width = damageBounds.right - damageBounds.left;
    event.xexpose.height = damageBounds.bottom - damageBounds.top;
a956 3
    SyncCGContextOriginWithPort(context, port);
    CGContextConcatCTM(context, CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0,
	    bounds.bottom - bounds.top));
@


1.22.2.6
log
@merge updates from HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.22.2.5 2007/07/01 17:31:37 dgp Exp $
d72 8
d102 1
a102 1
 *	Hide or reveal floating windows.
d124 1
d129 1
d338 1
a341 1
	    TkMacOSXTrackingLoop(1);
d928 1
a928 10
    OSStatus err;
    ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
    Boolean isFrontProcess = true;

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


1.22.2.7
log
@merge updates from HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.22.2.6 2007/07/10 21:54:28 dgp Exp $
d76 1
a76 1
static int GenerateUpdates(HIMutableShapeRef updateRgn, CGRect *updateBounds,
d79 1
a79 1
static void ClearPort(CGrafPtr port, HIShapeRef updateRgn);
d433 1
d438 1
a438 4
    CGRect updateBounds;
    HIShapeRef rgn;
    HIMutableShapeRef updateRgn;
    int dx, dy;
d446 8
a453 21
    macWindow = TkMacOSXDrawableWindow(window);
    TK_IF_MAC_OS_X_API (5, HIWindowCopyShape,
	ChkErr(HIWindowCopyShape, macWindow, kWindowUpdateRgn,
		kHICoordSpaceWindow, &rgn);
	dx = -winPtr->wmInfoPtr->xInParent;
	dy = -winPtr->wmInfoPtr->yInParent;
    ) TK_ELSE_MAC_OS_X (5,
	Rect bounds;

	TkMacOSXCheckTmpQdRgnEmpty();
	ChkErr(GetWindowRegion, macWindow, kWindowUpdateRgn, tkMacOSXtmpQdRgn);
	rgn = HIShapeCreateWithQDRgn(tkMacOSXtmpQdRgn);
	SetEmptyRgn(tkMacOSXtmpQdRgn);
	ChkErr(GetWindowBounds, macWindow, kWindowContentRgn, &bounds);
	dx = -bounds.left;
	dy = -bounds.top;
    ) TK_ENDIF
    updateRgn = HIShapeCreateMutableCopy(rgn);
    CFRelease(rgn);
    ChkErr(HIShapeOffset, updateRgn, dx, dy);
    HIShapeGetBounds(updateRgn, &updateBounds);
d455 1
a455 1
    TkMacOSXDebugFlashRegion(window, updateRgn);
d459 1
a459 1
	ClearPort(TkMacOSXGetDrawablePort(window), updateRgn);
d461 1
a461 1
    result = GenerateUpdates(updateRgn, &updateBounds, winPtr);
d463 1
a463 1
    CFRelease(updateRgn);
d496 2
a497 2
    HIMutableShapeRef updateRgn,
    CGRect *updateBounds,
d502 2
a503 2
    CGRect bounds, damageBounds;
    HIShapeRef boundsRgn, damageRgn;
d505 8
a512 2
    TkMacOSXWinCGBounds(winPtr, &bounds);
    if (!CGRectIntersectsRect(bounds, *updateBounds)) {
a514 5
    TK_IF_MAC_OS_X_API (4, HIShapeIntersectsRect,
	if (!HIShapeIntersectsRect(updateRgn, &bounds)) {
	    return 0;
	}
    ) TK_ENDIF
d520 2
a521 6
    boundsRgn = HIShapeCreateWithRect(&bounds);
    damageRgn = HIShapeCreateIntersection(updateRgn, boundsRgn);
    if (HIShapeIsEmpty(damageRgn)) {
	CFRelease(damageRgn);
	CFRelease(boundsRgn);
	return 0;
d523 7
a529 5
    HIShapeGetBounds(damageRgn, &damageBounds);
    ChkErr(TkMacOSHIShapeUnion, boundsRgn, updateRgn, updateRgn);
    HIShapeGetBounds(updateRgn, updateBounds);
    CFRelease(damageRgn);
    CFRelease(boundsRgn);
d536 4
a539 4
    event.xexpose.x = damageBounds.origin.x - bounds.origin.x;
    event.xexpose.y = damageBounds.origin.y - bounds.origin.y;
    event.xexpose.width = damageBounds.size.width;
    event.xexpose.height = damageBounds.size.height;
d948 1
a948 1
    HIShapeRef updateRgn)
d960 1
a960 2
	ChkErr(HIShapeReplacePathInCGContext, updateRgn, context);
	CGContextEOClip(context);
@


1.22.2.8
log
@merge updates from HEAD
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.22.2.7 2007/10/15 18:38:36 dgp Exp $
d235 1
a235 1
	case kEventWindowExpanding:
d278 1
a278 1
	case kEventWindowExpanding:
d280 2
a281 12
		winPtr->wmInfoPtr->hints.initial_state =
			TkMacOSXIsWindowZoomed(winPtr) ? ZoomState : 
			NormalState;
		Tk_MapWindow((Tk_Window) winPtr);
		/*
		 * Need to process all Tk events generated by Tk_MapWindow()
		 * before returning to ensure all children are mapped, as
		 * otherwise the Activate event that follows Expanding would
		 * not be processed by any unmapped children.
		 */
		while (Tcl_ServiceEvent(TCL_WINDOW_EVENTS)) {};
		while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {};
@


1.22.2.9
log
@merge updates from 8.5 branch
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.22.2.8 2007/11/12 19:22:39 dgp Exp $
d421 1
a421 1
    return eventFound;
@


1.21
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: tkMacOSXWindowEvent.c,v 1.20 2007/04/21 19:06:38 hobbs Exp $
d269 4
a272 4
    if (window != None) {
	switch (eventPtr->eKind) {
	    case kEventWindowActivated:
	    case kEventWindowDeactivated: {
a280 1
		break;
d282 49
a330 49
	    case kEventWindowUpdate:
		if (GenerateUpdateEvent(window)) {
		    eventFound = true;
		    statusPtr->stopProcessing = 1;
		}
		break;
	    case kEventWindowExpanded:
		if (winPtr) {
		    TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
			    ZoomState : NormalState);
		}
		break;
	    case kEventWindowBoundsChanged:
		if (winPtr) {
		    WmInfo *wmPtr = winPtr->wmInfoPtr;
		    UInt32 attr;
		    Rect bounds;
		    int x = -1, y = -1, width = -1, height = -1, flags = 0;

		    ChkErr(GetEventParameter, eventPtr->eventRef,
			    kEventParamAttributes, typeUInt32,
			    NULL, sizeof(attr), NULL, &attr);
		    ChkErr(GetEventParameter, eventPtr->eventRef,
			    kEventParamCurrentBounds, typeQDRectangle,
			    NULL, sizeof(bounds), NULL, &bounds);
		    if (attr & kWindowBoundsChangeOriginChanged) {
			x = bounds.left - wmPtr->xInParent;
			y = bounds.top	- wmPtr->yInParent;
			flags |= TK_LOCATION_CHANGED;
		    }
		    if (attr & kWindowBoundsChangeSizeChanged) {
			width = bounds.right  - bounds.left;
			height = bounds.bottom - bounds.top;
			flags |= TK_SIZE_CHANGED;
		    }
		    TkGenWMConfigureEvent((Tk_Window)winPtr, x, y, width,
			    height, flags);
		    if (attr & kWindowBoundsChangeUserResize ||
			    attr & kWindowBoundsChangeUserDrag) {
			TkMacOSXRunTclEventLoop();
		    }
		    if (wmPtr->attributes & kWindowResizableAttribute) {
			HIViewRef growBoxView;

			err = HIViewFindByID(HIViewGetRoot(whichWindow),
				kHIViewWindowGrowBoxID, &growBoxView);
			if (err == noErr) {
			    ChkErr(HIViewSetNeedsDisplay, growBoxView, true);
			}
d333 57
a389 10
		break;
	    case kEventWindowDragStarted:
		if (winPtr) {
		    TkMacOSXTrackingLoop(1);
		}
		break;
	    case kEventWindowDragCompleted:
		if (winPtr) {
		    Rect maxBounds, bounds, strWidths;
		    int h = 0, v = 0;
d391 7
a397 47
		    TkMacOSXTrackingLoop(0);
		    ChkErr(GetWindowGreatestAreaDevice, whichWindow,
			    kWindowDragRgn, NULL, &maxBounds);
		    ChkErr(GetWindowBounds, whichWindow, kWindowStructureRgn,
			    &bounds);
		    ChkErr(GetWindowStructureWidths, whichWindow, &strWidths);
		    if (bounds.left > maxBounds.right - strWidths.left) {
			h = maxBounds.right
				- (strWidths.left ? strWidths.left : 40)
				- bounds.left;
		    } else if (bounds.right < maxBounds.left
			    + strWidths.right) {
			h = maxBounds.left
				+ (strWidths.right ? strWidths.right : 40)
				- bounds.right;
		    }
		    if (bounds.top > maxBounds.bottom - strWidths.top) {
			v = maxBounds.bottom
				- (strWidths.top ? strWidths.top : 40)
				- bounds.top;
		    } else if (bounds.bottom < maxBounds.top
			    + strWidths.bottom) {
			v = maxBounds.top
				+ (strWidths.bottom ? strWidths.bottom : 40)
				- bounds.bottom;
		    } else if (strWidths.top && bounds.top < maxBounds.top) {
			v = maxBounds.top - bounds.top;
		    }
		    if (h || v) {
			OffsetRect(&bounds, h, v);
			ChkErr(SetWindowBounds, whichWindow,
			    kWindowStructureRgn, &bounds);
		    }
		}
		break;
	    case kEventWindowConstrain:
		if (winPtr) {
		    if (winPtr->wmInfoPtr->flags & WM_FULLSCREEN &&
			    TkMacOSXMakeFullscreen(winPtr, whichWindow, 1,
			    NULL) == TCL_OK) {
			statusPtr->stopProcessing = 1;
		    }
		}
		break;
	    case kEventWindowGetRegion:
		if (winPtr && (winPtr->wmInfoPtr->flags & WM_TRANSPARENT)) {
		    WindowRegionCode code;
a398 2
		    statusPtr->stopProcessing = (CallNextEventHandler(
			    eventPtr->callRef, eventPtr->eventRef) == noErr);
d400 5
a404 12
			    kEventParamWindowRegionCode, typeWindowRegionCode,
			    NULL, sizeof(code), NULL, &code);
		    if (err == noErr && code == kWindowOpaqueRgn) {
			RgnHandle rgn;

			err = ChkErr(GetEventParameter, eventPtr->eventRef,
				kEventParamRgnHandle, typeQDRgnHandle, NULL,
				sizeof(rgn), NULL, &rgn);
			if (err == noErr) {
			    SetEmptyRgn(rgn);
			    statusPtr->stopProcessing = 1;
			}
d407 5
a411 4
		break;
	    case kEventWindowDrawContent:
		if (winPtr && (winPtr->wmInfoPtr->flags & WM_TRANSPARENT)) {
		    CGrafPtr port;
d413 4
a416 5
		    GetPort(&port);
		    ClearPort(port);
		}
		break;
	}
d418 1
@


1.20
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
@d5 1
a5 1
 *      Window Manager class events for Tk.
d8 1
a8 1
 * Copyright (c) 2005 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: tkMacOSXWindowEvent.c,v 1.18 2006/11/02 15:18:13 das Exp $
d66 6
d75 2
a76 2
static int tkMacOSXAppInFront = true;	/* Boolean variable for determining if 
					 * we are the frontmost app.  Only set 
d84 1
a84 1
 
d88 1
d90 1
a90 1

d96 2
a97 2
 *        This processes Application level events, mainly activate
 *        and deactivate.
d100 1
a100 1
 *        o.
d103 1
a103 1
 *        Hide or reveal floating windows, and set tkMacOSXAppInFront.
d107 1
a107 1
 
d110 2
a111 2
        TkMacOSXEvent *eventPtr, 
        MacEventStatus *statusPtr)
d116 2
a117 2
     * This is a bit of a hack.  We get "show" events both when we come back
     * from being hidden, and whenever we are activated.  I only want to run
d119 1
a119 1
     * for <Activate>.  So I use this toggle...
d124 32
a155 32
        case kEventAppActivated:
            tkMacOSXAppInFront = true;
            ShowFloatingWindows();
            break;
        case kEventAppDeactivated:
            TkSuspendClipboard();
            tkMacOSXAppInFront = false;
            HideFloatingWindows();
            break;
        case kEventAppQuit:
            statusPtr->stopProcessing = 1;
            break;
        case kEventAppHidden:
            if (toggleHide == 0) {
                toggleHide = 1;
                if (eventPtr->interp && Tcl_GetCommandInfo(eventPtr->interp, 
                        "::tk::mac::OnHide", &dummy)) {
                    Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnHide");
                }
            }
            statusPtr->stopProcessing = 1;
            break;
        case kEventAppShown:
            if (toggleHide == 1) {
                toggleHide = 0;
                if (eventPtr->interp && Tcl_GetCommandInfo(eventPtr->interp, 
                        "::tk::mac::OnShow", &dummy)) {
                    Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnShow");
                }
            }
            statusPtr->stopProcessing = 1;
            break;
d157 13
a169 2
            TkDisplay *dispPtr = TkGetDisplayList();
            TkMacOSXDisplayChanged(dispPtr->display);
d175 33
a207 2
        default:
            break;
d211 2
a212 1
/*
d217 2
a218 2
 *        This processes Window level events, mainly activate
 *        and deactivate.
d221 1
a221 1
 *        0.
d224 2
a225 2
 *        Cause Windows to be moved forward or backward in the 
 *        window stack.
d232 4
a235 4
        TkMacOSXEvent * eventPtr, 
        MacEventStatus * statusPtr)
{ 
    OSStatus  status;
d237 26
a262 23
    Window    window;
    int       eventFound = false;
    
    switch (eventPtr->eKind) { 
        case kEventWindowActivated:
        case kEventWindowDeactivated:
        case kEventWindowUpdate:
        case kEventWindowExpanded:
            break;
        default:
            return 0;
            break;
    }
    status = GetEventParameter(eventPtr->eventRef,
            kEventParamDirectObject,
            typeWindowRef, NULL,
            sizeof(whichWindow), NULL,
            &whichWindow);
    if (status != noErr) {
#ifdef TK_MAC_DEBUG
        fprintf ( stderr, "TkMacOSXHandleWindowEvent:Failed to retrieve window" );
#endif
        return 0;
d264 1
a264 1
    
d266 60
d327 93
a419 25
    switch (eventPtr->eKind) {
        case kEventWindowActivated:
            eventFound |= GenerateActivateEvents(window, 1);
            eventFound |= TkMacOSXGenerateFocusEvent(window, 1);
            break;
        case kEventWindowDeactivated:
            eventFound |= GenerateActivateEvents(window, 0);
            eventFound |= TkMacOSXGenerateFocusEvent(window, 0);
            break;
        case kEventWindowUpdate:
            if (GenerateUpdateEvent(window)) {
                eventFound = true;
            }
            break;
        case kEventWindowExpanded: {
            TkDisplay *dispPtr;
            TkWindow  *winPtr;
            dispPtr = TkGetDisplayList();
            winPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display, window);
            if (winPtr) {
		TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
			ZoomState : NormalState);
            }
            break;
        }
d429 2
a430 2
 *      Given a Macintosh window update event this function generates
 *      all the Expose XEvents needed by Tk.
d432 2
a433 2
 * Results:     
 *      True if event(s) are generated - false otherwise.
d436 2
a437 2
 *      Additional events may be place on the Tk event queue.
 *          
d439 1
a439 1
 */     
d443 2
a444 2
    CGrafPtr    destPort;
    WindowRef   macWindow;
d447 2
a448 3
    int         result = 0;
    static RgnHandle updtRgn = NULL, visRgn = NULL;
    
d451 1
a451 1
 
d453 1
a453 1
        return result;
d456 1
a456 7
        gDamageRgn = NewRgn();
    }
    if (updtRgn == NULL) {
        updtRgn = NewRgn();
    }
    if (visRgn == NULL) {
        visRgn = NewRgn();
d458 1
d461 4
a464 4
    GetWindowRegion(macWindow, kWindowUpdateRgn, updtRgn);
    visRgn = QDGlobalToLocalRegion(destPort, updtRgn);
    SectRegionWithPortVisibleRegion(destPort, visRgn);
#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_CLIP_REGIONS)
d466 1
a466 1
				 CGrafPtr port, RgnHandle region);
d469 1
a469 1
	QDDebugFlashRegion(destPort, visRgn);
d473 4
a476 1
    result = GenerateUpdates(visRgn, winPtr);
d478 1
a478 2
    SetEmptyRgn(visRgn);
    SetEmptyRgn(updtRgn);
d488 4
a491 4
 *        Given a Macintosh update region and a Tk window this function
 *        geneates a X Expose event for the window if it is within the
 *        update region.  The function will then recursivly have each
 *        damaged window generate Expose events for its child windows.
d494 1
a494 1
 *        True if event(s) are generated - false otherwise.
d497 1
a497 1
 *        Additional events may be place on the Tk event queue.
d513 1
a513 1
        
d515 5
a519 5
        updateBounds.top > bounds.bottom ||
        bounds.left > updateBounds.right ||
        updateBounds.left > bounds.right ||
        !RectInRgn(&bounds, updateRgn)) {
        return 0;
d522 1
a522 1
        return 0;
d529 1
a529 1
        
d532 1
a532 1
    /* 
d549 1
a549 1
    
d555 1
a555 1
     
d557 4
a560 4
                                       childPtr = childPtr->nextPtr) {
        if (!Tk_IsMapped(childPtr) || Tk_IsTopLevel(childPtr)) {
            continue;
        }
d562 1
a562 1
        GenerateUpdates(updateRgn, childPtr);
d564 1
a564 1
    
d570 10
a579 10
        childPtr = TkpGetOtherWindow(winPtr);
        if (childPtr != NULL && Tk_IsMapped(childPtr)) {
            GenerateUpdates(updateRgn, childPtr);
        }
            
        /*
         * NOTE: Here we should handle out of process embedding.
         */
                    
    }        
d584 1
a584 1
/*         
d586 1
a586 1
 *                      
a587 3
 *                      
 *      Given a Macintosh window activate event this function generates all the
 *      X Activate events needed by Tk.
d589 5
a593 2
 * Results:     
 *      True if event(s) are generated - false otherwise.
d596 2
a597 2
 *      Additional events may be place on the Tk event queue.
 *          
d600 1
a600 1
    
d603 2
a604 2
    Window window,                /* Root X window for event. */
    int    activeFlag )
d608 1
a608 1
    
d612 1
a612 1
        return false;
d619 1
a619 1
/*         
d621 1
a621 1
 *                      
a622 3
 *                      
 *      Given a Macintosh window activate event this function generates all the
 *      X Focus events needed by Tk.
d624 5
a628 2
 * Results:     
 *      True if event(s) are generated - false otherwise.
d631 2
a632 2
 *      Additional events may be place on the Tk event queue.
 *          
d634 1
a634 1
 */     
d638 2
a639 2
    Window window,              /* Root X window for event. */
    int    activeFlag )
d648 1
a648 1
        return false;
d662 1
a662 1
     * Generate FocusIn and FocusOut events.  This event
d667 1
a667 1
        event.xany.type = FocusIn;
d669 1
a669 1
        event.xany.type = FocusOut;
d682 1
a682 1

d688 1
a688 1
 *	Generate a ConfigureNotify event for Tk.  Depending on the 
d713 1
a713 1
    
d717 1
a717 1
    
d732 1
a732 6
    if (flags & TK_LOCATION_CHANGED) {
	event.xconfigure.x = x;
	event.xconfigure.y = y;
    } else {
	event.xconfigure.x = Tk_X(tkwin);
	event.xconfigure.y = Tk_Y(tkwin);
d736 1
a736 6
    if (flags & TK_SIZE_CHANGED) {
	event.xconfigure.width = width;
	event.xconfigure.height = height;
    } else {
	event.xconfigure.width = Tk_Width(tkwin);
	event.xconfigure.height = Tk_Height(tkwin);
d740 5
a744 1
    
d746 1
a746 1
    
d757 1
a757 1
	if ((flags & TK_SIZE_CHANGED) && 
d795 1
a795 1
    
d797 3
a799 3
     * Now set up the changes structure.  Under X we wait for the
     * ConfigureNotify to set these values.  On the Mac we know imediatly that
     * this is what we want - so we just set them.  However, we need to
d809 1
a809 1

d815 2
a816 1
 *	Generate a WM Destroy event for Tk.   *
d831 1
a831 1
    
d835 1
a835 1
	
d843 1
a843 1

d881 1
a881 1
				   protPtr = protPtr->nextPtr) {
d884 2
a885 2
            interp = protPtr->interp;
            Tcl_Preserve((ClientData) interp);
d894 1
a894 1
            Tcl_Release((ClientData) interp);
d901 1
a901 1
     * No handler was present for this protocol.  If this is a
d909 1
a909 1

d915 1
a915 1
 *	Returns 1 if this app is the foreground app. 
d931 28
@


1.19
log
@Reduce the #ifdef count a lot by adding debug-print macros
@
text
@d206 3
a208 1
	ERR_MSG("TkMacOSXHandleWindowEvent: Failed to retrieve window");
d211 1
a211 1

d215 24
a238 24
    case kEventWindowActivated:
	eventFound |= GenerateActivateEvents(window, 1);
	eventFound |= TkMacOSXGenerateFocusEvent(window, 1);
	break;
    case kEventWindowDeactivated:
	eventFound |= GenerateActivateEvents(window, 0);
	eventFound |= TkMacOSXGenerateFocusEvent(window, 0);
	break;
    case kEventWindowUpdate:
	if (GenerateUpdateEvent(window)) {
	    eventFound = true;
	}
	break;
    case kEventWindowExpanded: {
	TkDisplay *dispPtr = TkGetDisplayList();
	TkWindow *winPtr = (TkWindow *)
		Tk_IdToWindow(dispPtr->display, window);

	if (winPtr) {
	    TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
		    ZoomState : NormalState);
	}
	break;
    }
d248 2
a249 2
 *      Given a Macintosh window update event this function generates all the
 *      Expose XEvents needed by Tk.
d251 1
a251 1
 * Results:
@


1.18
log
@comment typo
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.17 2006/11/02 12:24:41 das Exp $
d206 1
a206 3
#ifdef TK_MAC_DEBUG
        fprintf ( stderr, "TkMacOSXHandleWindowEvent:Failed to retrieve window" );
#endif
d209 1
a209 1
    
d213 24
a236 24
        case kEventWindowActivated:
            eventFound |= GenerateActivateEvents(window, 1);
            eventFound |= TkMacOSXGenerateFocusEvent(window, 1);
            break;
        case kEventWindowDeactivated:
            eventFound |= GenerateActivateEvents(window, 0);
            eventFound |= TkMacOSXGenerateFocusEvent(window, 0);
            break;
        case kEventWindowUpdate:
            if (GenerateUpdateEvent(window)) {
                eventFound = true;
            }
            break;
        case kEventWindowExpanded: {
            TkDisplay *dispPtr;
            TkWindow  *winPtr;
            dispPtr = TkGetDisplayList();
            winPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display, window);
            if (winPtr) {
		TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
			ZoomState : NormalState);
            }
            break;
        }
d246 2
a247 2
 *      Given a Macintosh window update event this function generates
 *      all the Expose XEvents needed by Tk.
d249 1
a249 1
 * Results:     
@


1.17
log
@	* macosx/tkMacOSXWindowEvent.c (GenerateUpdateEvent): fix handling of
	Carbon Update events: the QuickDraw window update region was being
	ignored and all child TkWindows were sent an Expose XEvent even when
	they did not need to be redrawn. [Patch 1589226]
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.16 2006/09/10 17:06:32 das Exp $
d249 1
a249 1
 *      all the the Expose XEvents needed by Tk.
@


1.16
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: tkMacOSXWindowEvent.c,v 1.15 2006/07/24 04:45:23 das Exp $
d73 1
a73 2
static RgnHandle gDamageRgn;
static RgnHandle visRgn;
d80 1
a80 1
static void GenerateUpdates( RgnHandle updateRgn, TkWindow *winPtr);
d248 2
a249 2
 *      Given a Macintosh window update event this function generates all the
 *      X update events needed by Tk.
d262 1
d266 2
a267 1
    Rect        bounds;
d273 1
a273 1
        return false;
d278 3
d284 13
a296 1
    macWindow = GetWindowFromPort(TkMacOSXGetDrawablePort(window));
d298 1
a298 14
    /*
     * In the Classic version of the code, this was the "visRgn" field of the WindowRec
     * This no longer exists in OS X, so retrieve the content region instead
     * Note that this is in screen coordinates
     * We therefore convert it to window relative coordinates
     */
    GetWindowRegion (macWindow, kWindowContentRgn, visRgn );
    GetRegionBounds(visRgn,&bounds);
    bounds.right -= bounds.left;
    bounds.bottom -= bounds.top;
    bounds.left = 0;
    bounds.top=0;
    RectRgn(visRgn, &bounds);
    GenerateUpdates(visRgn, winPtr);
d300 4
a303 1
    return true;
d312 1
a312 1
 *        geneates a X damage event for the window if it is within the
d314 1
a314 1
 *        damaged window generate damage events for its child windows.
d317 1
a317 1
 *        None.
d325 1
a325 1
static void
d342 1
a342 1
        return;
d345 1
a345 1
        return;
d404 1
a404 1
    return;
@


1.15
log
@fix typo: visable -> visible
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.14 2006/05/16 06:55:05 das Exp $
d470 1
a470 1
     * overrideredirect windows.
d473 2
a474 1
	    Tk_Attributes(tkwin)->override_redirect) {
@


1.14
log
@	* macosx/tkMacOSXWindowEvent.c (TkMacOSXGenerateFocusEvent): don't send
	focus events to windows of class help or to overrideredirect windows.
	[Bug 1472624]

	* macosx/tkMacOSXWm.c: set overrideredirect windows to not become
	activated by the window manager and to not receive OS activate events
	(should make them behave more like on other platforms); use modern
	window class API for overrideredirect and transient windows; set the
	default class of overrideredirect windows to 'simple' rather than
	'plain' (i.e. no window frame); add missing Panther and Tiger window
	attributes to [::tk::unsupported::MacWindowStyle].
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.13 2006/04/11 10:21:28 das Exp $
d623 1
a623 1
     * change is visable to the subwindow.
@


1.13
log
@	* macosx/tkMacOSXHLEvents.c:    call ::tk::mac::* procs for all
	* macosx/tkMacOSXWindowEvent.c: registered appleevents [FR 1105284],
	implement print applevent handling, style/whitespace cleanup.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.12 2006/04/11 07:36:36 das Exp $
d469 9
@


1.12
log
@	* macosx/tkMacOSXInt.h:         Implemented 'zoomed' window state
	* macosx/tkMacOSXWindowEvent.c: handling for TkAqua, via titlebar
	* macosx/tkMacOSXWm.c:          widget clicks as well as [wm state].
	* doc/wm.n:                     [Bug 1073456]
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.11 2006/03/24 14:58:01 das Exp $
d131 6
a136 9
        /*
         * Don't bother if we don't have an interp or
         * the show preferences procedure doesn't exist.
         */
            toggleHide = 1;
            if ((eventPtr->interp == NULL) || 
                    (Tcl_GetCommandInfo(eventPtr->interp, 
                    "::tk::mac::OnHide", &dummy)) == 0) {
               break;
a137 1
            Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnHide");
d143 3
a145 4
                if ((eventPtr->interp == NULL) || 
                        (Tcl_GetCommandInfo(eventPtr->interp, 
                        "::tk::mac::OnShow", &dummy)) == 0) {
                    break;
a146 1
                Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnShow");
@


1.11
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: tkMacOSXWindowEvent.c,v 1.10 2006/02/09 19:08:50 das Exp $
d241 2
a242 1
                TkpWmSetState(winPtr, NormalState);
@


1.10
log
@	* generic/tk.decls:             fix signature of TkMacOSXInvalClipRgns
	* generic/tkPlatDecls.h:        to use Tk_Window instead of internal
	* macosx/tkMacOSXSubwindows.c:  type TkWindow (which led to any include
	* macosx/tkMacOSXWindowEvent.c: of public header tkMacOSX.h requiring
	* macosx/tkMacOSXWm.c:          prior include of tkInt.h).

	* generic/tk.h:          move TkAqua specific REDO_KEYSYM_LOOKUP define
	* macosx/tkMacOSXPort.h: out of tk.h into platform header.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.9 2005/12/01 06:24:16 hobbs Exp $
a60 1
#include "tkPort.h"
@


1.9
log
@	* macosx/tkMacOSXXStubs.c (TkpOpenDisplay, TkMacOSXDisplayChanged):
	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessApplicationEvent):
	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents):
	* macosx/tkMacOSXEvent.h: Trap kEventAppAvailableWindowBoundsChanged
	* macosx/tkMacOSXInt.h:   event to watch for change in display size
	and adjust internal state appropriately.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.8 2005/11/27 02:36:15 das Exp $
d626 1
a626 1
    TkMacOSXInvalClipRgns(winPtr);
@


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkStubInit.c:
	* unix/configure:
	* unix/tkConfig.h.in: regen.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.7 2005/09/10 14:53:21 das Exp $
d109 2
a110 2
    
    /* 
d112 3
a114 3
     * from being hidden, and whenever we are activated.  I only want to run the
     * "show" proc when we have been hidden already, not as a substitute for
     * <Activate>.  So I use this toggle...
d157 8
d250 1
a250 1
/*         
d252 1
a252 1
 *                      
d254 1
a254 1
 *                      
@


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

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

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

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

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

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

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

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

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

	* xlib/xcolors.c: fixed warning
@
text
@d7 5
a11 1
 *      Copyright 2001, Apple Computer, Inc.
d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.6 2005/08/09 07:39:21 das Exp $
d70 4
a73 4
int tkMacOSXAppInFront = true;     /* Boolean variable for determining if 
                                    * we are the frontmost app.  Only set 
                                    * in TkMacOSXProcessApplicationEvent
                                    */
d188 1
a188 1
    int       eventFound;
@


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	* library/demos/menu.tcl: removed errant '}'.
@
text
@d53 1
a53 1
 * RCS: @@(#) $Id$
d99 1
a99 1
int
d125 1
a125 4
        case kEventAppLaunchNotification:
        case kEventAppLaunched:
        case kEventAppTerminated:
        case kEventAppFrontSwitched:
d176 1
a176 1
int
d202 1
d204 1
@


1.5
log
@Fix for 1124237.
@
text
@d52 2
d104 10
d130 28
d193 1
d225 10
d448 1
a448 1
int
@


1.4
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
@a77 2
static int GenerateFocusEvent( Window window, int activeFlag);

d173 1
a173 1
            eventFound |= GenerateFocusEvent(window, 1);
d177 1
a177 1
            eventFound |= GenerateFocusEvent(window, 0);
d383 1
a383 1
 * GenerateFocusEvent --
d398 1
a398 1
GenerateFocusEvent(
@


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


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

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

Fix various formatting nits.
@
text
@d238 1
a238 1
    bounds.left = 0;
@


1.3.2.2
log
@Fix for 1124237 and the mysterious "sometimes buttons don't draw" bug.
@
text
@d78 2
d175 1
a175 1
            eventFound |= TkMacOSXGenerateFocusEvent(window, 1);
d179 1
a179 1
            eventFound |= TkMacOSXGenerateFocusEvent(window, 0);
d385 1
a385 1
 * TkMacOSXGenerateFocusEvent --
d400 1
a400 1
TkMacOSXGenerateFocusEvent(
@


1.3.2.3
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
@a51 2
 *
 * RCS: @@(#) $Id$
a101 10
    Tcl_CmdInfo dummy;
    
    /* 
     * This is a bit of a hack.  We get "show" events both when we come back
     * from being hidden, and whenever we are activated.  I only want to run the
     * "show" proc when we have been hidden already, not as a substitute for
     * <Activate>.  So I use this toggle...
     */
    static int toggleHide = 0;

a117 28
        case kEventAppHidden:
        /*
         * Don't bother if we don't have an interp or
         * the show preferences procedure doesn't exist.
         */
            toggleHide = 1;
            if ((eventPtr->interp == NULL) || 
                    (Tcl_GetCommandInfo(eventPtr->interp, 
                    "::tk::mac::OnHide", &dummy)) == 0) {
               break;
            }
            Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnHide");
            statusPtr->stopProcessing = 1;
            break;
        case kEventAppShown:
            if (toggleHide == 1) {
                toggleHide = 0;
                if ((eventPtr->interp == NULL) || 
                        (Tcl_GetCommandInfo(eventPtr->interp, 
                        "::tk::mac::OnShow", &dummy)) == 0) {
                    break;
                }
                Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnShow");
            }
            statusPtr->stopProcessing = 1;
            break;
        default:
            break;
a152 1
        case kEventWindowExpanded:
a183 10
        case kEventWindowExpanded: {
            TkDisplay *dispPtr;
            TkWindow  *winPtr;
            dispPtr = TkGetDisplayList();
            winPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display, window);
            if (winPtr) {
                TkpWmSetState(winPtr, NormalState);
            }
            break;
        }
@


1.3.2.4
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: tkMacOSXWindowEvent.c,v 1.3.2.3 2005/08/09 07:40:01 das Exp $
d125 4
a128 1
            statusPtr->stopProcessing = 1;
a204 1
#ifdef TK_MAC_DEBUG
a205 1
#endif
@


1.3.2.5
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: tkMacOSXWindowEvent.c,v 1.3.2.4 2005/09/10 14:54:18 das Exp $
d66 4
a69 4
static int tkMacOSXAppInFront = true;	/* Boolean variable for determining if 
					 * we are the frontmost app.  Only set 
					 * in TkMacOSXProcessApplicationEvent
					 */
d184 1
a184 1
    int       eventFound = false;
@


1.3.2.6
log
@	* macosx/tkMacOSXXStubs.c (TkpOpenDisplay, TkMacOSXDisplayChanged):
	* macosx/tkMacOSXCarbonEvents.c (TkMacOSXInitCarbonEvents):
	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessApplicationEvent):
	* macosx/tkMacOSXInt.h: Trap kEventAppAvailableWindowBoundsChanged
	event to watch for change in display size and adjust internal
	state appropriately.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.5 2005/11/27 02:36:46 das Exp $
d109 2
a110 2

    /*
d112 3
a114 3
     * from being hidden, and whenever we are activated.  I only want to run
     * the "show" proc when we have been hidden already, not as a substitute
     * for <Activate>.  So I use this toggle...
d132 4
a135 4
	    /*
	     * Don't bother if we don't have an interp or
	     * the show preferences procedure doesn't exist.
	     */
a156 8
	case kEventAppAvailableWindowBoundsChanged: {
            TkDisplay *dispPtr = TkGetDisplayList();
            TkMacOSXDisplayChanged(dispPtr->display);
	    /*
	     * Should we call ::tk::mac::OnDisplayChanged?
	     */
	    break;
	}
@


1.3.2.7
log
@        * macosx/tkMacOSXInt.h:
        * macosx/tkMacOSXWindowEvent.c:
        * macosx/tkMacOSXXStubs.c: sync comments/whitespace with HEAD.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.6 2005/11/30 01:02:55 hobbs Exp $
d132 4
a135 4
        /*
         * Don't bother if we don't have an interp or
         * the show preferences procedure doesn't exist.
         */
d250 1
a250 1
/*
d252 1
a252 1
 *
d254 1
a254 1
 *
@


1.3.2.8
log
@	* generic/tk.decls:             fix signature of TkMacOSXInvalClipRgns
	* generic/tkPlatDecls.h:        to use Tk_Window instead of internal
	* macosx/tkMacOSXSubwindows.c:  type TkWindow (which led to any include
	* macosx/tkMacOSXWindowEvent.c: of public header tkMacOSX.h requiring
	* macosx/tkMacOSXWm.c:          prior include of tkInt.h).

	* generic/tk.h:          move TkAqua specific REDO_KEYSYM_LOOKUP define
	* macosx/tkMacOSXPort.h: out of tk.h into platform header.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.7 2005/12/08 05:04:35 das Exp $
d626 1
a626 1
    TkMacOSXInvalClipRgns(tkwin);
@


1.3.2.9
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: tkMacOSXWindowEvent.c,v 1.3.2.8 2006/02/09 19:09:43 das Exp $
d61 1
@


1.3.2.10
log
@	* macosx/tkMacOSXInt.h:         Implemented 'zoomed' window state
	* macosx/tkMacOSXWindowEvent.c: handling for TkAqua, via titlebar
	* macosx/tkMacOSXWm.c:          widget clicks as well as [wm state].
	* doc/wm.n:                     [Bug 1073456]
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.9 2006/03/28 02:44:14 das Exp $
d241 1
a241 2
		TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
			ZoomState : NormalState);
@


1.3.2.11
log
@	* macosx/tkMacOSXHLEvents.c:    call ::tk::mac::* procs for all
	* macosx/tkMacOSXWindowEvent.c: registered appleevents [FR 1105284],
	implement print applevent handling, style/whitespace cleanup.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.10 2006/04/11 07:36:40 das Exp $
d131 9
a139 6
            if (toggleHide == 0) {
                toggleHide = 1;
                if (eventPtr->interp && Tcl_GetCommandInfo(eventPtr->interp, 
                        "::tk::mac::OnHide", &dummy)) {
                    Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnHide");
                }
d141 1
d147 4
a150 3
                if (eventPtr->interp && Tcl_GetCommandInfo(eventPtr->interp, 
                        "::tk::mac::OnShow", &dummy)) {
                    Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnShow");
d152 1
@


1.3.2.12
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
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.11 2006/04/11 10:21:53 das Exp $
d102 1
a102 1
MODULE_SCOPE int
d181 1
a181 1
MODULE_SCOPE int
d453 1
a453 1
MODULE_SCOPE int
@


1.3.2.13
log
@	* macosx/tkMacOSXWindowEvent.c (TkMacOSXGenerateFocusEvent): don't send
	focus events to windows of class help or to overrideredirect windows.
	[Bug 1472624]

	* macosx/tkMacOSXWm.c: set overrideredirect windows to not become
	activated by the window manager and to not receive OS activate events
	(should make them behave more like on other platforms); use modern
	window class API for overrideredirect and transient windows; set the
	default class of overrideredirect windows to 'simple' rather than
	'plain' (i.e. no window frame); add missing Panther and Tiger window
	attributes to [::tk::unsupported::MacWindowStyle].
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.12 2006/04/28 06:03:00 das Exp $
a468 9
     * Don't send focus events to windows of class help or to
     * overrideredirect windows.
     */
    if (((TkWindow *)tkwin)->wmInfoPtr->macClass == kHelpWindowClass ||
	    Tk_Attributes(tkwin)->override_redirect) {
	return false;
    }

    /*
@


1.3.2.14
log
@fix typo: visable -> visible
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.13 2006/05/16 06:55:13 das Exp $
d623 1
a623 1
     * change is visible to the subwindow.
@


1.3.2.15
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: tkMacOSXWindowEvent.c,v 1.3.2.14 2006/07/24 04:45:26 das Exp $
d470 1
a470 1
     * windows with the kWindowNoActivatesAttribute.
d473 1
a473 2
	    ((TkWindow *)tkwin)->wmInfoPtr->attributes &
		    kWindowNoActivatesAttribute) {
@


1.3.2.16
log
@	* macosx/tkMacOSXWindowEvent.c (GenerateUpdateEvent): fix handling of
	Carbon Update events: the QuickDraw window update region was being
	ignored and all child TkWindows were sent an Expose XEvent even when
	they did not need to be redrawn. [Patch 1589226]
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.15 2006/09/10 17:07:36 das Exp $
d73 2
a74 1
static RgnHandle gDamageRgn = NULL;
d81 1
a81 1
static int GenerateUpdates( RgnHandle updateRgn, TkWindow *winPtr);
d249 2
a250 2
 *      Given a Macintosh window update event this function generates
 *      all the the Expose XEvents needed by Tk.
a262 1
    CGrafPtr    destPort;
d266 1
a266 2
    int         result = 0;
    static RgnHandle updtRgn = NULL, visRgn = NULL;
d272 1
a272 1
        return result;
a276 3
    if (updtRgn == NULL) {
        updtRgn = NewRgn();
    }
d280 1
a280 13
    destPort = TkMacOSXGetDrawablePort(window);
    macWindow = GetWindowFromPort(destPort);
    GetWindowRegion(macWindow, kWindowUpdateRgn, updtRgn);
    visRgn = QDGlobalToLocalRegion(destPort, updtRgn);
    SectRegionWithPortVisibleRegion(destPort, visRgn);
#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_CLIP_REGIONS)
    TkMacOSXInitNamedDebugSymbol(HIToolbox, int, QDDebugFlashRegion,
				 CGrafPtr port, RgnHandle region);
    if (QDDebugFlashRegion) {
	/* Carbon-internal region flashing SPI (c.f. Technote 2124) */
	QDDebugFlashRegion(destPort, visRgn);
    }
#endif /* TK_MAC_DEBUG_CLIP_REGIONS */
d282 14
a295 1
    result = GenerateUpdates(visRgn, winPtr);
d297 1
a297 4
    SetEmptyRgn(visRgn);
    SetEmptyRgn(updtRgn);
    SetEmptyRgn(gDamageRgn);
    return result;
d306 1
a306 1
 *        geneates a X Expose event for the window if it is within the
d308 1
a308 1
 *        damaged window generate Expose events for its child windows.
d311 1
a311 1
 *        True if event(s) are generated - false otherwise.
d319 1
a319 1
static int
d336 1
a336 1
        return 0;
d339 1
a339 1
        return 0;
d398 1
a398 1
    return 1;
@


1.3.2.17
log
@comment typo
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.16 2006/11/02 12:24:49 das Exp $
d249 1
a249 1
 *      all the Expose XEvents needed by Tk.
@


1.3.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
@d5 1
a5 1
 *	Window Manager class events for Tk.
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: tkMacOSXWindowEvent.c,v 1.3.2.17 2006/11/02 15:18:26 das Exp $
a65 6
#ifdef TK_MAC_DEBUG
#define TK_MAC_DEBUG_CLIP_REGIONS
#endif
*/

/*
d69 2
a70 2
static int tkMacOSXAppInFront = true;	/* Boolean variable for determining if
					 * we are the frontmost app. Only set
d78 1
a78 1

a81 1
static void ClearPort(CGrafPtr port);
d83 1
a83 1

d89 2
a90 2
 *	This processes Application level events, mainly activate
 *	and deactivate.
d93 1
a93 1
 *	0.
d96 1
a96 1
 *	Hide or reveal floating windows, and set tkMacOSXAppInFront.
d100 1
a100 1

d103 2
a104 2
	TkMacOSXEvent *eventPtr,
	MacEventStatus *statusPtr)
d109 2
a110 2
     * This is a bit of a hack. We get "show" events both when we come back
     * from being hidden, and whenever we are activated. I only want to run
d112 1
a112 1
     * for <Activate>. So I use this toggle...
d117 32
a148 32
	case kEventAppActivated:
	    tkMacOSXAppInFront = true;
	    ShowFloatingWindows();
	    break;
	case kEventAppDeactivated:
	    TkSuspendClipboard();
	    tkMacOSXAppInFront = false;
	    HideFloatingWindows();
	    break;
	case kEventAppQuit:
	    statusPtr->stopProcessing = 1;
	    break;
	case kEventAppHidden:
	    if (toggleHide == 0) {
		toggleHide = 1;
		if (eventPtr->interp && Tcl_GetCommandInfo(eventPtr->interp,
			"::tk::mac::OnHide", &dummy)) {
		    Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnHide");
		}
	    }
	    statusPtr->stopProcessing = 1;
	    break;
	case kEventAppShown:
	    if (toggleHide == 1) {
		toggleHide = 0;
		if (eventPtr->interp && Tcl_GetCommandInfo(eventPtr->interp,
			"::tk::mac::OnShow", &dummy)) {
		    Tcl_GlobalEval(eventPtr->interp, "::tk::mac::OnShow");
		}
	    }
	    statusPtr->stopProcessing = 1;
	    break;
d150 2
a151 13
	    static UInt32 prevId = 0;
	    UInt32 id;
	    OSStatus err;

	    err = ChkErr(GetEventParameter, eventPtr->eventRef,
		    kEventParamTransactionID, typeUInt32,
		    NULL, sizeof(id), NULL, &id);
	    if (err != noErr || id != prevId) {
		TkDisplay *dispPtr = TkGetDisplayList();

		prevId = id;
		TkMacOSXDisplayChanged(dispPtr->display);
	    }
d157 2
a158 33
	default:
	    break;
    }
    return 0;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessAppearanceEvent --
 *
 *	This processes Appearance events.
 *
 * Results:
 *	0.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

MODULE_SCOPE int
TkMacOSXProcessAppearanceEvent(
	TkMacOSXEvent *eventPtr,
	MacEventStatus *statusPtr)
{
    switch (eventPtr->eKind) {
	case kEventAppearanceScrollBarVariantChanged:
	    TkMacOSXInitScrollbarMetrics();
	    break;
	default:
	    break;
d162 1
a162 2

/*
d167 2
a168 2
 *	This processes Window level events, mainly activate
 *	and deactivate.
d171 1
a171 1
 *	0.
d174 2
a175 2
 *	Cause Windows to be moved forward or backward in the
 *	window stack.
d182 4
a185 4
	TkMacOSXEvent * eventPtr,
	MacEventStatus * statusPtr)
{
    OSStatus err;
d187 23
a209 26
    Window window;
    int eventFound = false;
    TkDisplay *dispPtr;
    TkWindow *winPtr;

    switch (eventPtr->eKind) {
	case kEventWindowActivated:
	case kEventWindowDeactivated:
	case kEventWindowUpdate:
	case kEventWindowExpanded:
	case kEventWindowBoundsChanged:
	case kEventWindowDragStarted:
	case kEventWindowDragCompleted:
	case kEventWindowConstrain:
	case kEventWindowGetRegion:
	case kEventWindowDrawContent:
	    break;
	default:
	    return 0;
	    break;
    }
    err = ChkErr(GetEventParameter, eventPtr->eventRef,
	    kEventParamDirectObject, typeWindowRef, NULL, sizeof(whichWindow),
	    NULL, &whichWindow);
    if (err != noErr) {
	return 0;
d211 1
a211 1

a212 2
    dispPtr = TkGetDisplayList();
    winPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display, window);
d214 25
a238 151
    if (window != None) {
	switch (eventPtr->eKind) {
	    case kEventWindowActivated:
	    case kEventWindowDeactivated: {
		int activate = (eventPtr->eKind == kEventWindowActivated);

		eventFound |= GenerateActivateEvents(window, activate);
		eventFound |= TkMacOSXGenerateFocusEvent(window, activate);
		if (winPtr) {
		    TkMacOSXEnterExitFullscreen(winPtr, activate);
		}
		statusPtr->stopProcessing = 1;
		break;
	    }
	    case kEventWindowUpdate:
		if (GenerateUpdateEvent(window)) {
		    eventFound = true;
		    statusPtr->stopProcessing = 1;
		}
		break;
	    case kEventWindowExpanded:
		if (winPtr) {
		    TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
			    ZoomState : NormalState);
		}
		break;
	    case kEventWindowBoundsChanged:
		if (winPtr) {
		    WmInfo *wmPtr = winPtr->wmInfoPtr;
		    UInt32 attr;
		    Rect bounds;
		    int x = -1, y = -1, width = -1, height = -1, flags = 0;

		    ChkErr(GetEventParameter, eventPtr->eventRef,
			    kEventParamAttributes, typeUInt32,
			    NULL, sizeof(attr), NULL, &attr);
		    ChkErr(GetEventParameter, eventPtr->eventRef,
			    kEventParamCurrentBounds, typeQDRectangle,
			    NULL, sizeof(bounds), NULL, &bounds);
		    if (attr & kWindowBoundsChangeOriginChanged) {
			x = bounds.left - wmPtr->xInParent;
			y = bounds.top	- wmPtr->yInParent;
			flags |= TK_LOCATION_CHANGED;
		    }
		    if (attr & kWindowBoundsChangeSizeChanged) {
			width = bounds.right  - bounds.left;
			height = bounds.bottom - bounds.top;
			flags |= TK_SIZE_CHANGED;
		    }
		    TkGenWMConfigureEvent((Tk_Window)winPtr, x, y, width,
			    height, flags);
		    if (attr & kWindowBoundsChangeUserResize ||
			    attr & kWindowBoundsChangeUserDrag) {
			TkMacOSXRunTclEventLoop();
		    }
		    if (wmPtr->attributes & kWindowResizableAttribute) {
			HIViewRef growBoxView;

			err = HIViewFindByID(HIViewGetRoot(whichWindow),
				kHIViewWindowGrowBoxID, &growBoxView);
			if (err == noErr) {
			    ChkErr(HIViewSetNeedsDisplay, growBoxView, true);
			}
		    }
		}
		break;
	    case kEventWindowDragStarted:
		if (winPtr) {
		    TkMacOSXTrackingLoop(1);
		}
		break;
	    case kEventWindowDragCompleted:
		if (winPtr) {
		    Rect maxBounds, bounds, strWidths;
		    int h = 0, v = 0;

		    TkMacOSXTrackingLoop(0);
		    ChkErr(GetWindowGreatestAreaDevice, whichWindow,
			    kWindowDragRgn, NULL, &maxBounds);
		    ChkErr(GetWindowBounds, whichWindow, kWindowStructureRgn,
			    &bounds);
		    ChkErr(GetWindowStructureWidths, whichWindow, &strWidths);
		    if (bounds.left > maxBounds.right - strWidths.left) {
			h = maxBounds.right
				- (strWidths.left ? strWidths.left : 40)
				- bounds.left;
		    } else if (bounds.right < maxBounds.left
			    + strWidths.right) {
			h = maxBounds.left
				+ (strWidths.right ? strWidths.right : 40)
				- bounds.right;
		    }
		    if (bounds.top > maxBounds.bottom - strWidths.top) {
			v = maxBounds.bottom
				- (strWidths.top ? strWidths.top : 40)
				- bounds.top;
		    } else if (bounds.bottom < maxBounds.top
			    + strWidths.bottom) {
			v = maxBounds.top
				+ (strWidths.bottom ? strWidths.bottom : 40)
				- bounds.bottom;
		    } else if (strWidths.top && bounds.top < maxBounds.top) {
			v = maxBounds.top - bounds.top;
		    }
		    if (h || v) {
			OffsetRect(&bounds, h, v);
			ChkErr(SetWindowBounds, whichWindow,
			    kWindowStructureRgn, &bounds);
		    }
		}
		break;
	    case kEventWindowConstrain:
		if (winPtr) {
		    if (winPtr->wmInfoPtr->flags & WM_FULLSCREEN &&
			    TkMacOSXMakeFullscreen(winPtr, whichWindow, 1,
			    NULL) == TCL_OK) {
			statusPtr->stopProcessing = 1;
		    }
		}
		break;
	    case kEventWindowGetRegion:
		if (winPtr && (winPtr->wmInfoPtr->flags & WM_TRANSPARENT)) {
		    WindowRegionCode code;

		    statusPtr->stopProcessing = (CallNextEventHandler(
			    eventPtr->callRef, eventPtr->eventRef) == noErr);
		    err = ChkErr(GetEventParameter, eventPtr->eventRef,
			    kEventParamWindowRegionCode, typeWindowRegionCode,
			    NULL, sizeof(code), NULL, &code);
		    if (err == noErr && code == kWindowOpaqueRgn) {
			RgnHandle rgn;

			err = ChkErr(GetEventParameter, eventPtr->eventRef,
				kEventParamRgnHandle, typeQDRgnHandle, NULL,
				sizeof(rgn), NULL, &rgn);
			if (err == noErr) {
			    SetEmptyRgn(rgn);
			    statusPtr->stopProcessing = 1;
			}
		    }
		}
		break;
	    case kEventWindowDrawContent:
		if (winPtr && (winPtr->wmInfoPtr->flags & WM_TRANSPARENT)) {
		    CGrafPtr port;

		    GetPort(&port);
		    ClearPort(port);
		}
		break;
	}
d248 2
a249 2
 *	Given a Macintosh window update event this function generates
 *	all the Expose XEvents needed by Tk.
d251 2
a252 2
 * Results:
 *	True if event(s) are generated - false otherwise.
d255 2
a256 2
 *	Additional events may be place on the Tk event queue.
 *
d258 1
a258 1
 */
d262 2
a263 2
    CGrafPtr	destPort;
    WindowRef	macWindow;
d266 3
a268 2
    int		result = 0;

d271 1
a271 1

d273 1
a273 1
	return result;
d276 7
a282 1
	gDamageRgn = NewRgn();
a283 1
    TkMacOSXCheckTmpRgnEmpty(1);
d286 4
a289 4
    GetWindowRegion(macWindow, kWindowUpdateRgn, tkMacOSXtmpRgn1);
    QDGlobalToLocalRegion(destPort, tkMacOSXtmpRgn1);
    SectRegionWithPortVisibleRegion(destPort, tkMacOSXtmpRgn1);
#ifdef TK_MAC_DEBUG_CLIP_REGIONS
d291 1
a291 1
				CGrafPtr port, RgnHandle region);
d294 1
a294 1
	QDDebugFlashRegion(destPort, tkMacOSXtmpRgn1);
d298 1
a298 4
    if (winPtr->wmInfoPtr->flags & WM_TRANSPARENT) {
	ClearPort(destPort);
    }
    result = GenerateUpdates(tkMacOSXtmpRgn1, winPtr);
d300 2
a301 1
    SetEmptyRgn(tkMacOSXtmpRgn1);
d311 4
a314 4
 *	Given a Macintosh update region and a Tk window this function
 *	geneates a X Expose event for the window if it is within the
 *	update region. The function will then recursivly have each
 *	damaged window generate Expose events for its child windows.
d317 1
a317 1
 *	True if event(s) are generated - false otherwise.
d320 1
a320 1
 *	Additional events may be place on the Tk event queue.
d336 1
a336 1

d338 5
a342 5
	updateBounds.top > bounds.bottom ||
	bounds.left > updateBounds.right ||
	updateBounds.left > bounds.right ||
	!RectInRgn(&bounds, updateRgn)) {
	return 0;
d345 1
a345 1
	return 0;
d352 1
a352 1

d355 1
a355 1
    /*
d372 1
a372 1

d378 1
a378 1

d380 4
a383 4
				       childPtr = childPtr->nextPtr) {
	if (!Tk_IsMapped(childPtr) || Tk_IsTopLevel(childPtr)) {
	    continue;
	}
d385 1
a385 1
	GenerateUpdates(updateRgn, childPtr);
d387 1
a387 1

d393 10
a402 10
	childPtr = TkpGetOtherWindow(winPtr);
	if (childPtr != NULL && Tk_IsMapped(childPtr)) {
	    GenerateUpdates(updateRgn, childPtr);
	}

	/*
	 * NOTE: Here we should handle out of process embedding.
	 */

    }
d407 1
a407 1
/*
d409 1
a409 1
 *
d411 3
d415 2
a416 5
 *	Given a Macintosh window activate event this function generates all the
 *	X Activate events needed by Tk.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
d419 2
a420 2
 *	Additional events may be place on the Tk event queue.
 *
d423 1
a423 1

d426 2
a427 2
    Window window,		  /* Root X window for event. */
    int activeFlag )
d431 1
a431 1

d435 1
a435 1
	return false;
d442 1
a442 1
/*
d444 1
a444 1
 *
d446 3
d450 2
a451 5
 *	Given a Macintosh window activate event this function generates all the
 *	X Focus events needed by Tk.
 *
 * Results:
 *	True if event(s) are generated - false otherwise.
d454 2
a455 2
 *	Additional events may be place on the Tk event queue.
 *
d457 1
a457 1
 */
d461 2
a462 2
    Window window,		/* Root X window for event. */
    int activeFlag )
d471 1
a471 1
	return false;
d485 1
a485 1
     * Generate FocusIn and FocusOut events. This event
d490 1
a490 1
	event.xany.type = FocusIn;
d492 1
a492 1
	event.xany.type = FocusOut;
d505 1
a505 1

d511 1
a511 1
 *	Generate a ConfigureNotify event for Tk. Depending on the
d536 1
a536 1

d540 1
a540 1

d555 6
a560 1
    if (!(flags & TK_LOCATION_CHANGED)) {
d564 6
a569 1
    if (!(flags & TK_SIZE_CHANGED)) {
d573 1
a573 5
    event.xconfigure.x = x;
    event.xconfigure.y = y;
    event.xconfigure.width = width;
    event.xconfigure.height = height;

d575 1
a575 1

d586 1
a586 1
	if ((flags & TK_SIZE_CHANGED) && !(wmPtr->flags & WM_SYNC_PENDING) &&
d624 1
a624 1

d626 3
a628 3
     * Now set up the changes structure. Under X we wait for the
     * ConfigureNotify to set these values. On the Mac we know imediatly that
     * this is what we want - so we just set them. However, we need to
d638 1
a638 1

d644 1
a644 2
 *	Generate a WM Destroy event for Tk.
 *
d659 1
a659 1

d663 1
a663 1

d671 1
a671 1

d709 1
a709 1
		protPtr = protPtr->nextPtr) {
d712 2
a713 2
	    interp = protPtr->interp;
	    Tcl_Preserve((ClientData) interp);
d722 1
a722 1
	    Tcl_Release((ClientData) interp);
d729 1
a729 1
     * No handler was present for this protocol. If this is a
d737 1
a737 1

d743 1
a743 1
 *	Returns 1 if this app is the foreground app.
a758 28

/*
 *----------------------------------------------------------------------
 *
 * ClearPort --
 *
 *	Clear (i.e. fill with transparent color) the given port.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */
static void
ClearPort(CGrafPtr port) {
    CGContextRef context;
    Rect bounds;
    CGRect rect;

    GetPortBounds(port, &bounds);
    QDBeginCGContext(port, &context);
    rect = CGRectMake(0, 0, bounds.right, bounds.bottom);
    CGContextClearRect(context, rect);
    QDEndCGContext(port, &context);
}
@


1.3.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: tkMacOSXWindowEvent.c,v 1.3.2.18 2007/04/29 02:26:50 das Exp $
d269 4
a272 4
    switch (eventPtr->eKind) {
	case kEventWindowActivated:
	case kEventWindowDeactivated:
	    if (window != None) {
d281 1
d283 49
a331 49
	    break;
	case kEventWindowUpdate:
	    if (window != None && GenerateUpdateEvent(window)) {
		eventFound = true;
		statusPtr->stopProcessing = 1;
	    }
	    break;
	case kEventWindowExpanded:
	    if (winPtr) {
		TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
			ZoomState : NormalState);
	    }
	    break;
	case kEventWindowBoundsChanged:
	    if (winPtr) {
		WmInfo *wmPtr = winPtr->wmInfoPtr;
		UInt32 attr;
		Rect bounds;
		int x = -1, y = -1, width = -1, height = -1, flags = 0;

		ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamAttributes, typeUInt32,
			NULL, sizeof(attr), NULL, &attr);
		ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamCurrentBounds, typeQDRectangle,
			NULL, sizeof(bounds), NULL, &bounds);
		if (attr & kWindowBoundsChangeOriginChanged) {
		    x = bounds.left - wmPtr->xInParent;
		    y = bounds.top	- wmPtr->yInParent;
		    flags |= TK_LOCATION_CHANGED;
		}
		if (attr & kWindowBoundsChangeSizeChanged) {
		    width = bounds.right  - bounds.left;
		    height = bounds.bottom - bounds.top;
		    flags |= TK_SIZE_CHANGED;
		}
		TkGenWMConfigureEvent((Tk_Window)winPtr, x, y, width,
			height, flags);
		if (attr & kWindowBoundsChangeUserResize ||
			attr & kWindowBoundsChangeUserDrag) {
		    TkMacOSXRunTclEventLoop();
		}
		if (wmPtr->attributes & kWindowResizableAttribute) {
		    HIViewRef growBoxView;

		    err = HIViewFindByID(HIViewGetRoot(whichWindow),
			    kHIViewWindowGrowBoxID, &growBoxView);
		    if (err == noErr) {
			ChkErr(HIViewSetNeedsDisplay, growBoxView, true);
d334 10
a343 57
	    }
	    break;
	case kEventWindowDragStarted:
	    TkMacOSXTrackingLoop(1);
	    if (!(TkMacOSXModifierState() & cmdKey)) { 
		TkMacOSXBringWindowForward(whichWindow);
	    }
	    break;
	case kEventWindowDragCompleted: {
	    Rect maxBounds, bounds, strWidths;
	    int h = 0, v = 0;

	    TkMacOSXTrackingLoop(0);
	    ChkErr(GetWindowGreatestAreaDevice, whichWindow,
		    kWindowDragRgn, NULL, &maxBounds);
	    ChkErr(GetWindowBounds, whichWindow, kWindowStructureRgn,
		    &bounds);
	    ChkErr(GetWindowStructureWidths, whichWindow, &strWidths);
	    if (bounds.left > maxBounds.right - strWidths.left) {
		h = maxBounds.right
			- (strWidths.left ? strWidths.left : 40)
			- bounds.left;
	    } else if (bounds.right < maxBounds.left
		    + strWidths.right) {
		h = maxBounds.left
			+ (strWidths.right ? strWidths.right : 40)
			- bounds.right;
	    }
	    if (bounds.top > maxBounds.bottom - strWidths.top) {
		v = maxBounds.bottom
			- (strWidths.top ? strWidths.top : 40)
			- bounds.top;
	    } else if (bounds.bottom < maxBounds.top
		    + strWidths.bottom) {
		v = maxBounds.top
			+ (strWidths.bottom ? strWidths.bottom : 40)
			- bounds.bottom;
	    } else if (strWidths.top && bounds.top < maxBounds.top) {
		v = maxBounds.top - bounds.top;
	    }
	    if (h || v) {
		OffsetRect(&bounds, h, v);
		ChkErr(SetWindowBounds, whichWindow,
		    kWindowStructureRgn, &bounds);
	    }
	    break;
	}
	case kEventWindowConstrain:
	    if (winPtr && (winPtr->wmInfoPtr->flags & WM_FULLSCREEN) &&
		    TkMacOSXMakeFullscreen(winPtr, whichWindow, 1,
		    NULL) == TCL_OK) {
		statusPtr->stopProcessing = 1;
	    }
	    break;
	case kEventWindowGetRegion:
	    if (winPtr && (winPtr->wmInfoPtr->flags & WM_TRANSPARENT)) {
		WindowRegionCode code;
d345 47
a391 7
		statusPtr->stopProcessing = (CallNextEventHandler(
			eventPtr->callRef, eventPtr->eventRef) == noErr);
		err = ChkErr(GetEventParameter, eventPtr->eventRef,
			kEventParamWindowRegionCode, typeWindowRegionCode,
			NULL, sizeof(code), NULL, &code);
		if (err == noErr && code == kWindowOpaqueRgn) {
		    RgnHandle rgn;
d393 2
d396 12
a407 5
			    kEventParamRgnHandle, typeQDRgnHandle, NULL,
			    sizeof(rgn), NULL, &rgn);
		    if (err == noErr) {
			SetEmptyRgn(rgn);
			statusPtr->stopProcessing = 1;
d410 4
a413 5
	    }
	    break;
	case kEventWindowDrawContent:
	    if (winPtr && (winPtr->wmInfoPtr->flags & WM_TRANSPARENT)) {
		CGrafPtr port;
d415 5
a419 4
		GetPort(&port);
		ClearPort(port);
	    }
	    break;
a420 1

@


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

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

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

	* macosx/tkMacOSXEvent.c:	cleanup whitespace and formatting.
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXRegion.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* xlib/xgc.c:
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.19 2007/05/09 12:57:47 das Exp $
d79 2
d85 4
a88 5
static int GenerateUpdateEvent(Window window);
static int GenerateUpdates(RgnHandle updateRgn, Rect *updateBounds,
	TkWindow *winPtr);
static int GenerateActivateEvents(Window window, int activeFlag);
static void ClearPort(CGrafPtr port, RgnHandle updateRgn);
d414 1
a414 1
		ClearPort(port, NULL);
d441 5
a445 6
    CGrafPtr destPort;
    WindowRef macWindow;
    TkDisplay *dispPtr;
    TkWindow  *winPtr;
    int result = 0;
    Rect updateBounds;
d453 3
a461 1
    GetRegionBounds(tkMacOSXtmpRgn1, &updateBounds);
d463 6
a468 1
    TkMacOSXDebugFlashRegion(destPort, tkMacOSXtmpRgn1);
d472 1
a472 1
	ClearPort(destPort, tkMacOSXtmpRgn1);
d474 1
a474 1
    result = GenerateUpdates(tkMacOSXtmpRgn1, &updateBounds, winPtr);
d477 1
a502 1
    Rect *updateBounds,
d507 1
a507 2
    Rect bounds, damageBounds;
    static RgnHandle damageRgn = NULL;
d510 7
a516 4
    if (bounds.top > updateBounds->bottom ||
	updateBounds->top > bounds.bottom ||
	bounds.left > updateBounds->right ||
	updateBounds->left > bounds.right) {
a522 13
    /*
     * Compute the bounding box of the area that the damage occured in.
     */

    if (damageRgn == NULL) {
	damageRgn = NewRgn();
    }
    RectRgn(damageRgn, &bounds);
    SectRgn(damageRgn, updateRgn, damageRgn);
    OffsetRgn(damageRgn, -bounds.left, -bounds.top);
    GetRegionBounds(damageRgn, &damageBounds);
    SetEmptyRgn(damageRgn);

d527 1
d529 13
d547 1
d555 1
a555 1
	    childPtr = childPtr->nextPtr) {
d559 2
a560 1
	GenerateUpdates(updateRgn, updateBounds, childPtr);
d570 1
a570 1
	    GenerateUpdates(updateRgn, updateBounds, childPtr);
d925 1
a925 1
Tk_MacOSXIsAppInFront(void)
d946 1
a946 4
ClearPort(
    CGrafPtr port,
    RgnHandle updateRgn)
{
a952 3
    if (updateRgn) {
	ClipCGContextToRegion(context, &bounds, updateRgn);
    }
@


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

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

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

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

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

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

	* macosx/tkMacOSXColor.c:	cleanup whitespace and formatting.
	* macosx/tkMacOSXDraw.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.20 2007/05/30 06:39:38 das Exp $
a316 3
		TkMacOSXInvalClipRgns((Tk_Window) winPtr);
		TkMacOSXInvalidateWindow((MacDrawable *) window,
			TK_PARENT_WINDOW);
a469 8
    if (result) {
	/*
	 * Ensure there are no pending idle-time redraws that could prevent
	 * the just posted Expose events from generating new redraws.
	 */

	Tcl_DoOneEvent(TCL_IDLE_EVENTS|TCL_DONT_WAIT);
    }
a524 3
    RectRgn(damageRgn, &bounds);
    UnionRgn(damageRgn, updateRgn, updateRgn);
    GetRegionBounds(updateRgn, updateBounds);
@


1.3.2.22
log
@	* macosx/tkMacOSXMenu.c: add error checking; whitespace cleanup.

	* macosx/tkMacOSXDraw.c:	sync comment formatting with HEAD.
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXEntry.c:
	* macosx/tkMacOSXKeyEvent.c:
	* macosx/tkMacOSXKeyboard.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXSend.c:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWindowEvent.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.21 2007/05/31 13:42:12 das Exp $
d576 1
a576 1
	 * TODO: Here we should handle out of process embedding.
d578 1
@


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

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

	* macosx/tkMacOSXWindowEvent.c:	add error checking.
	* macosx/tkMacOSXMenu.c:	fix gcc3 warning.
	* macosx/tkMacOSXScrlbr.c:	fix testsuite crash.
	* macosx/tkMacOSXSubwindows.c:	formatting cleanup.
	* macosx/tkMacOSXRegion.c:	fix typos.
	* macosx/tkMacOSXScale.c:
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.22 2007/06/04 09:28:45 das Exp $
d459 1
a459 1
    ChkErr(GetWindowRegion, macWindow, kWindowUpdateRgn, tkMacOSXtmpRgn1);
@


1.3.2.24
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: tkMacOSXWindowEvent.c,v 1.3.2.23 2007/06/09 17:10:22 das Exp $
d60 1
a60 1
#include "tkMacOSXPrivate.h"
d448 1
a448 1
    Rect updateBounds, bounds;
d456 1
a456 1
    TkMacOSXCheckTmpQdRgnEmpty();
d459 4
a462 5
    ChkErr(GetWindowRegion, macWindow, kWindowUpdateRgn, tkMacOSXtmpQdRgn);
    ChkErr(GetWindowBounds, macWindow, kWindowContentRgn, &bounds);
    OffsetRgn(tkMacOSXtmpQdRgn, -bounds.left, -bounds.top);
    SectRegionWithPortVisibleRegion(destPort, tkMacOSXtmpQdRgn);
    GetRegionBounds(tkMacOSXtmpQdRgn, &updateBounds);
d464 1
a464 1
    TkMacOSXDebugFlashRegion(window, tkMacOSXtmpQdRgn);
d468 1
a468 1
	ClearPort(destPort, tkMacOSXtmpQdRgn);
d470 1
a470 1
    result = GenerateUpdates(tkMacOSXtmpQdRgn, &updateBounds, winPtr);
d472 1
a472 1
    SetEmptyRgn(tkMacOSXtmpQdRgn);
d534 1
d546 4
a549 4
    event.xexpose.x = damageBounds.left - bounds.left;
    event.xexpose.y = damageBounds.top - bounds.top;
    event.xexpose.width = damageBounds.right - damageBounds.left;
    event.xexpose.height = damageBounds.bottom - damageBounds.top;
a956 3
    SyncCGContextOriginWithPort(context, port);
    CGContextConcatCTM(context, CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0,
	    bounds.bottom - bounds.top));
@


1.3.2.25
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: tkMacOSXWindowEvent.c,v 1.3.2.24 2007/06/29 03:22:02 das Exp $
d72 8
d102 1
a102 1
 *	Hide or reveal floating windows.
d124 1
d129 1
d338 1
a341 1
	    TkMacOSXTrackingLoop(1);
d928 1
a928 10
    OSStatus err;
    ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
    Boolean isFrontProcess = true;

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


1.3.2.26
log
@	Backport from HEAD of Aqua changes from 2007-10-12 to 2007-11-09
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.25 2007/07/09 08:32:12 das Exp $
d76 1
a76 1
static int GenerateUpdates(HIMutableShapeRef updateRgn, CGRect *updateBounds,
d79 1
a79 1
static void ClearPort(CGrafPtr port, HIShapeRef updateRgn);
d235 1
a235 1
	case kEventWindowExpanding:
d278 1
a278 1
	case kEventWindowExpanding:
d280 2
a281 12
		winPtr->wmInfoPtr->hints.initial_state =
			TkMacOSXIsWindowZoomed(winPtr) ? ZoomState : 
			NormalState;
		Tk_MapWindow((Tk_Window) winPtr);
		/*
		 * Need to process all Tk events generated by Tk_MapWindow()
		 * before returning to ensure all children are mapped, as
		 * otherwise the Activate event that follows Expanding would
		 * not be processed by any unmapped children.
		 */
		while (Tcl_ServiceEvent(TCL_WINDOW_EVENTS)) {};
		while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {};
d433 1
d438 1
a438 4
    CGRect updateBounds;
    HIShapeRef rgn;
    HIMutableShapeRef updateRgn;
    int dx, dy;
d446 8
a453 21
    macWindow = TkMacOSXDrawableWindow(window);
    TK_IF_MAC_OS_X_API (5, HIWindowCopyShape,
	ChkErr(HIWindowCopyShape, macWindow, kWindowUpdateRgn,
		kHICoordSpaceWindow, &rgn);
	dx = -winPtr->wmInfoPtr->xInParent;
	dy = -winPtr->wmInfoPtr->yInParent;
    ) TK_ELSE_MAC_OS_X (5,
	Rect bounds;

	TkMacOSXCheckTmpQdRgnEmpty();
	ChkErr(GetWindowRegion, macWindow, kWindowUpdateRgn, tkMacOSXtmpQdRgn);
	rgn = HIShapeCreateWithQDRgn(tkMacOSXtmpQdRgn);
	SetEmptyRgn(tkMacOSXtmpQdRgn);
	ChkErr(GetWindowBounds, macWindow, kWindowContentRgn, &bounds);
	dx = -bounds.left;
	dy = -bounds.top;
    ) TK_ENDIF
    updateRgn = HIShapeCreateMutableCopy(rgn);
    CFRelease(rgn);
    ChkErr(HIShapeOffset, updateRgn, dx, dy);
    HIShapeGetBounds(updateRgn, &updateBounds);
d455 1
a455 1
    TkMacOSXDebugFlashRegion(window, updateRgn);
d459 1
a459 1
	ClearPort(TkMacOSXGetDrawablePort(window), updateRgn);
d461 1
a461 1
    result = GenerateUpdates(updateRgn, &updateBounds, winPtr);
d463 1
a463 1
    CFRelease(updateRgn);
d496 2
a497 2
    HIMutableShapeRef updateRgn,
    CGRect *updateBounds,
d502 2
a503 2
    CGRect bounds, damageBounds;
    HIShapeRef boundsRgn, damageRgn;
d505 8
a512 2
    TkMacOSXWinCGBounds(winPtr, &bounds);
    if (!CGRectIntersectsRect(bounds, *updateBounds)) {
a514 5
    TK_IF_MAC_OS_X_API (4, HIShapeIntersectsRect,
	if (!HIShapeIntersectsRect(updateRgn, &bounds)) {
	    return 0;
	}
    ) TK_ENDIF
d520 2
a521 6
    boundsRgn = HIShapeCreateWithRect(&bounds);
    damageRgn = HIShapeCreateIntersection(updateRgn, boundsRgn);
    if (HIShapeIsEmpty(damageRgn)) {
	CFRelease(damageRgn);
	CFRelease(boundsRgn);
	return 0;
d523 7
a529 5
    HIShapeGetBounds(damageRgn, &damageBounds);
    ChkErr(TkMacOSHIShapeUnion, boundsRgn, updateRgn, updateRgn);
    HIShapeGetBounds(updateRgn, updateBounds);
    CFRelease(damageRgn);
    CFRelease(boundsRgn);
d536 4
a539 4
    event.xexpose.x = damageBounds.origin.x - bounds.origin.x;
    event.xexpose.y = damageBounds.origin.y - bounds.origin.y;
    event.xexpose.width = damageBounds.size.width;
    event.xexpose.height = damageBounds.size.height;
d948 1
a948 1
    HIShapeRef updateRgn)
d960 1
a960 2
	ChkErr(HIShapeReplacePathInCGContext, updateRgn, context);
	CGContextEOClip(context);
@


1.3.2.27
log
@	* macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessWindowEvent): fix
	return value.
@
text
@d57 1
a57 1
 * RCS: @@(#) $Id: tkMacOSXWindowEvent.c,v 1.3.2.26 2007/11/09 06:26:56 das Exp $
d421 1
a421 1
    return eventFound;
@


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
@a103 1
    statusPtr->handledByTk = 1;
a156 1
            statusPtr->handledByTk = 1;
a159 1
    statusPtr->handledByTk = 1;
a183 2
            } else {
                statusPtr->handledByTk = 0;
d688 1
a688 1
}@


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


1.1.2.1
log
@First checkin of support for Tk on Mac OS X.
@
text
@a0 694
/*
 * tkMacOSXWindowEvent.c --
 *
 *	This file defines the routines for both creating and handling
 *      Window Manager class events for Tk.
 *
 *      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 <tcl.h>
#include "tkMacOSXInt.h"
#include "tkPort.h"
#include "tkMacOSXWm.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXDebug.h"

/*
 * Declarations of global variables defined in this file.
 */

int tkMacOSXAppInFront = true;     /* Boolean variable for determining if 
                                    * we are the frontmost app.  Only set 
                                    * in TkMacOSXProcessApplicationEvent
                                    */
static RgnHandle gDamageRgn;
static RgnHandle visRgn;

/*
 * Declaration of functions used only in this file
 */
 
static int GenerateUpdateEvent( Window window);
static void GenerateUpdates( RgnHandle updateRgn, TkWindow *winPtr);
static int GenerateActivateEvents( Window window, int activeFlag);
static int GenerateFocusEvent( Window window, int activeFlag);



/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessApplicationEvent --
 *
 *        This processes Application level events, mainly activate
 *        and deactivate.
 *
 * Results:
 *        o.
 *
 * Side effects:
 *        Hide or reveal floating windows, and set tkMacOSXAppInFront.
 *
 *----------------------------------------------------------------------
 */
 
int
TkMacOSXProcessApplicationEvent(
        TkMacOSXEvent *eventPtr, 
        MacEventStatus *statusPtr)
{
    statusPtr->handledByTk = 1;
    switch (eventPtr->eKind) {
        case kEventAppActivated:
            tkMacOSXAppInFront = true;
            ShowFloatingWindows();
            break;
        case kEventAppDeactivated:
            TkSuspendClipboard();
            tkMacOSXAppInFront = false;
            HideFloatingWindows();
            break;
        case kEventAppQuit:
        case kEventAppLaunchNotification:
        case kEventAppLaunched:
        case kEventAppTerminated:
        case kEventAppFrontSwitched:
            break;
    }
    return 0;
}
/*
 *----------------------------------------------------------------------
 *
 * TkMacOSXProcessWindowEvent --
 *
 *        This processes Window level events, mainly activate
 *        and deactivate.
 *
 * Results:
 *        0.
 *
 * Side effects:
 *        Cause Windows to be moved forward or backward in the 
 *        window stack.
 *
 *----------------------------------------------------------------------
 */

int
TkMacOSXProcessWindowEvent(
        TkMacOSXEvent * eventPtr, 
        MacEventStatus * statusPtr)
{ 
    OSStatus  status;
    WindowRef whichWindow;
    Window    window;
    int       eventFound;
    
    switch (eventPtr->eKind) { 
        case kEventWindowActivated:
        case kEventWindowDeactivated:
        case kEventWindowUpdate:
            break;
        default:
            statusPtr->handledByTk = 1;
            return 0;
            break;
    }
    statusPtr->handledByTk = 1;
    status = GetEventParameter(eventPtr->eventRef,
            kEventParamDirectObject,
            typeWindowRef, NULL,
            sizeof(whichWindow), NULL,
            &whichWindow);
    if (status != noErr) {
        fprintf ( stderr, "TkMacOSXHandleWindowEvent:Failed to retrieve window" );
        return 0;
    }
    
    window = TkMacOSXGetXWindow(whichWindow);

    switch (eventPtr->eKind) {
        case kEventWindowActivated:
            eventFound |= GenerateActivateEvents(window, 1);
            eventFound |= GenerateFocusEvent(window, 1);
            break;
        case kEventWindowDeactivated:
            eventFound |= GenerateActivateEvents(window, 0);
            eventFound |= GenerateFocusEvent(window, 0);
            break;
        case kEventWindowUpdate:
            if (GenerateUpdateEvent(window)) {
                eventFound = true;
            } else {
                statusPtr->handledByTk = 0;
            }
            break;
    }
    return 0;
}

/*         
 *----------------------------------------------------------------------
 *                      
 * GenerateUpdateEvent --
 *                      
 *      Given a Macintosh window update event this function generates all the
 *      X update events needed by Tk.
 *
 * Results:     
 *      True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *      Additional events may be place on the Tk event queue.
 *          
 *----------------------------------------------------------------------
 */     
static int
GenerateUpdateEvent(Window window)
{
    WindowRef   macWindow;
    TkDisplay * dispPtr;
    TkWindow  * winPtr;
    Rect        bounds;
    
    dispPtr = TkGetDisplayList();
    winPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display, window);
 
    if (winPtr ==NULL ){
        return false;
    }
    if (gDamageRgn == NULL) {
        gDamageRgn = NewRgn();
    }
    if (visRgn == NULL) {
        visRgn = NewRgn();
    }
    macWindow = GetWindowFromPort(TkMacOSXGetDrawablePort(window));
    BeginUpdate(macWindow);
    /*
     * In the Classic version of the code, this was the "visRgn" field of the WindowRec
     * This no longer exists in OS X, so retrieve the content region instead
     * Note that this is in screen coordinates
     * We therefore convert it to window relative coordinates
     */
    GetWindowRegion (macWindow, kWindowContentRgn, visRgn );
    GetRegionBounds(visRgn,&bounds);
    bounds.right -= bounds.left;
    bounds.bottom -= bounds.top;
    bounds.left=
    bounds.top=0;
    RectRgn(visRgn, &bounds);
    GenerateUpdates(visRgn, winPtr);
    EndUpdate(macWindow);
    return true;
 }

/*
 *----------------------------------------------------------------------
 *
 * GenerateUpdates --
 *
 *        Given a Macintosh update region and a Tk window this function
 *        geneates a X damage event for the window if it is within the
 *        update region.  The function will then recursivly have each
 *        damaged window generate damage events for its child windows.
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        Additional events may be place on the Tk event queue.
 *
 *----------------------------------------------------------------------
 */

static void
GenerateUpdates(
    RgnHandle updateRgn,
    TkWindow *winPtr)
{
    TkWindow *childPtr;
    XEvent event;
    Rect bounds, updateBounds, damageBounds;

    TkMacOSXWinBounds(winPtr, &bounds);
    GetRegionBounds(updateRgn,&updateBounds);
        
    if (bounds.top > updateBounds.bottom ||
        updateBounds.top > bounds.bottom ||
        bounds.left > updateBounds.right ||
        updateBounds.left > bounds.right ||
        !RectInRgn(&bounds, updateRgn)) {
        return;
    }
    if (!RectInRgn(&bounds, updateRgn)) {
        return;
    }

    event.xany.serial = Tk_Display(winPtr)->request;
    event.xany.send_event = false;
    event.xany.window = Tk_WindowId(winPtr);
    event.xany.display = Tk_Display(winPtr);
        
    event.type = Expose;

    /* 
     * Compute the bounding box of the area that the damage occured in.
     */

    /*
     * CopyRgn(TkMacOSXVisableClipRgn(winPtr), rgn);
     * TODO: this call doesn't work doing resizes!!!
     */
    RectRgn(gDamageRgn, &bounds);
    SectRgn(gDamageRgn, updateRgn, gDamageRgn);
    OffsetRgn(gDamageRgn, -bounds.left, -bounds.top);
    GetRegionBounds(gDamageRgn,&damageBounds);
    event.xexpose.x = damageBounds.left;
    event.xexpose.y = damageBounds.top;
    event.xexpose.width = damageBounds.right-damageBounds.left;
    event.xexpose.height = damageBounds.bottom-damageBounds.top;
    event.xexpose.count = 0;
    
    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);

    /*
     * Generate updates for the children of this window
     */
     
    for (childPtr = winPtr->childList; childPtr != NULL;
                                       childPtr = childPtr->nextPtr) {
        if (!Tk_IsMapped(childPtr) || Tk_IsTopLevel(childPtr)) {
            continue;
        }

        GenerateUpdates(updateRgn, childPtr);
    }
    
    /*
     * Generate updates for any contained windows
     */

    if (Tk_IsContainer(winPtr)) {
        childPtr = TkpGetOtherWindow(winPtr);
        if (childPtr != NULL && Tk_IsMapped(childPtr)) {
            GenerateUpdates(updateRgn, childPtr);
        }
            
        /*
         * NOTE: Here we should handle out of process embedding.
         */
                    
    }        

    return;
}

/*         
 *----------------------------------------------------------------------
 *                      
 * GenerateActivateEvents --
 *                      
 *      Given a Macintosh window activate event this function generates all the
 *      X Activate events needed by Tk.
 *
 * Results:     
 *      True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *      Additional events may be place on the Tk event queue.
 *          
 *----------------------------------------------------------------------
 */
    
int
GenerateActivateEvents(
    Window window,                /* Root X window for event. */
    int    activeFlag )
{
    TkWindow *winPtr;
    TkDisplay *dispPtr;
    
    dispPtr = TkGetDisplayList();
    winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window);
    if (winPtr == NULL || winPtr->window == None) {
        return false;
    }

    TkGenerateActivateEvents(winPtr,activeFlag);
    return true;
}

/*         
 *----------------------------------------------------------------------
 *                      
 * GenerateFocusEvent --
 *                      
 *      Given a Macintosh window activate event this function generates all the
 *      X Focus events needed by Tk.
 *
 * Results:     
 *      True if event(s) are generated - false otherwise.
 *
 * Side effects:
 *      Additional events may be place on the Tk event queue.
 *          
 *----------------------------------------------------------------------
 */     

int
GenerateFocusEvent(
    Window window,              /* Root X window for event. */
    int    activeFlag )
{
    XEvent event;
    Tk_Window tkwin;
    TkDisplay *dispPtr;

    dispPtr = TkGetDisplayList();
    tkwin = Tk_IdToWindow(dispPtr->display, window);
    if (tkwin == NULL) {
        return false;
    }

    /*
     * Generate FocusIn and FocusOut events.  This event
     * is only sent to the toplevel window.
     */

    if (activeFlag) {
        event.xany.type = FocusIn;
    } else {
        event.xany.type = FocusOut;
    }

    event.xany.serial = dispPtr->display->request;
    event.xany.send_event = False;
    event.xfocus.display = dispPtr->display;
    event.xfocus.window = window;
    event.xfocus.mode = NotifyNormal;
    event.xfocus.detail = NotifyDetailNone;

    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
    return true;
}

/*
 *----------------------------------------------------------------------
 *
 * TkGenWMConfigureEvent --
 *
 *	Generate a ConfigureNotify event for Tk.  Depending on the 
 *	value of flag the values of width/height, x/y, or both may
 *	be changed.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A ConfigureNotify event is sent to Tk.
 *
 *----------------------------------------------------------------------
 */

void
TkGenWMConfigureEvent(
    Tk_Window tkwin,
    int x,
    int y,
    int width,
    int height,
    int flags)
{
    XEvent event;
    WmInfo *wmPtr;
    TkWindow *winPtr = (TkWindow *) tkwin;
    
    if (tkwin == NULL) {
	return;
    }
    
    event.type = ConfigureNotify;
    event.xconfigure.serial = Tk_Display(tkwin)->request;
    event.xconfigure.send_event = False;
    event.xconfigure.display = Tk_Display(tkwin);
    event.xconfigure.event = Tk_WindowId(tkwin);
    event.xconfigure.window = Tk_WindowId(tkwin);
    event.xconfigure.border_width = winPtr->changes.border_width;
    event.xconfigure.override_redirect = winPtr->atts.override_redirect;
    if (winPtr->changes.stack_mode == Above) {
	event.xconfigure.above = winPtr->changes.sibling;
    } else {
	event.xconfigure.above = None;
    }

    if (flags & TK_LOCATION_CHANGED) {
	event.xconfigure.x = x;
	event.xconfigure.y = y;
    } else {
	event.xconfigure.x = Tk_X(tkwin);
	event.xconfigure.y = Tk_Y(tkwin);
	x = Tk_X(tkwin);
	y = Tk_Y(tkwin);
    }
    if (flags & TK_SIZE_CHANGED) {
	event.xconfigure.width = width;
	event.xconfigure.height = height;
    } else {
	event.xconfigure.width = Tk_Width(tkwin);
	event.xconfigure.height = Tk_Height(tkwin);
	width = Tk_Width(tkwin);
	height = Tk_Height(tkwin);
    }
    
    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
    
    /*
     * Update window manager information.
     */
    if (Tk_IsTopLevel(winPtr)) {
	wmPtr = winPtr->wmInfoPtr;
	if (flags & TK_LOCATION_CHANGED) {
	    wmPtr->x = x;
	    wmPtr->y = y;
	    wmPtr->flags &= ~(WM_NEGATIVE_X | WM_NEGATIVE_Y);
	}
	if ((flags & TK_SIZE_CHANGED) && 
		((width != Tk_Width(tkwin)) || (height != Tk_Height(tkwin)))) {
	    if ((wmPtr->width == -1) && (width == winPtr->reqWidth)) {
		/*
		 * Don't set external width, since the user didn't change it
		 * from what the widgets asked for.
		 */
	    } else {
		if (wmPtr->gridWin != NULL) {
		    wmPtr->width = wmPtr->reqGridWidth
			+ (width - winPtr->reqWidth)/wmPtr->widthInc;
		    if (wmPtr->width < 0) {
			wmPtr->width = 0;
		    }
		} else {
		    wmPtr->width = width;
		}
	    }
	    if ((wmPtr->height == -1) && (height == winPtr->reqHeight)) {
		/*
		 * Don't set external height, since the user didn't change it
		 * from what the widgets asked for.
		 */
	    } else {
		if (wmPtr->gridWin != NULL) {
		    wmPtr->height = wmPtr->reqGridHeight
			+ (height - winPtr->reqHeight)/wmPtr->heightInc;
		    if (wmPtr->height < 0) {
			wmPtr->height = 0;
		    }
		} else {
		    wmPtr->height = height;
		}
	    }
	    wmPtr->configWidth = width;
	    wmPtr->configHeight = height;
	}
    }
    
    /*
     * Now set up the changes structure.  Under X we wait for the
     * ConfigureNotify to set these values.  On the Mac we know imediatly that
     * this is what we want - so we just set them.  However, we need to
     * make sure the windows clipping region is marked invalid so the
     * change is visable to the subwindow.
     */
    winPtr->changes.x = x;
    winPtr->changes.y = y;
    winPtr->changes.width = width;
    winPtr->changes.height = height;
    TkMacOSXInvalClipRgns(winPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * TkGenWMDestroyEvent --
 *
 *	Generate a WM Destroy event for Tk.   *
 * Results:
 *	None.
 *
 * Side effects:
 *	A WM_PROTOCOL/WM_DELETE_WINDOW event is sent to Tk.
 *
 *----------------------------------------------------------------------
 */

void
TkGenWMDestroyEvent(
    Tk_Window tkwin)
{
    XEvent event;
    
    event.xany.serial = Tk_Display(tkwin)->request;
    event.xany.send_event = False;
    event.xany.display = Tk_Display(tkwin);
	
    event.xclient.window = Tk_WindowId(tkwin);
    event.xclient.type = ClientMessage;
    event.xclient.message_type = Tk_InternAtom(tkwin, "WM_PROTOCOLS");
    event.xclient.format = 32;
    event.xclient.data.l[0] = Tk_InternAtom(tkwin, "WM_DELETE_WINDOW");
    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
}

/*
 *----------------------------------------------------------------------
 *
 * TkWmProtocolEventProc --
 *
 *	This procedure is called by the Tk_HandleEvent whenever a
 *	ClientMessage event arrives whose type is "WM_PROTOCOLS".
 *	This procedure handles the message from the window manager
 *	in an appropriate fashion.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Depends on what sort of handler, if any, was set up for the
 *	protocol.
 *
 *----------------------------------------------------------------------
 */

void
TkWmProtocolEventProc(
    TkWindow *winPtr,		/* Window to which the event was sent. */
    XEvent *eventPtr)		/* X event. */
{
    WmInfo *wmPtr;
    ProtocolHandler *protPtr;
    Tcl_Interp *interp;
    Atom protocol;
    int result;

    wmPtr = winPtr->wmInfoPtr;
    if (wmPtr == NULL) {
	return;
    }
    protocol = (Atom) eventPtr->xclient.data.l[0];
    for (protPtr = wmPtr->protPtr; protPtr != NULL;
				   protPtr = protPtr->nextPtr) {
	if (protocol == protPtr->protocol) {
	    Tcl_Preserve((ClientData) protPtr);
            interp = protPtr->interp;
            Tcl_Preserve((ClientData) interp);
	    result = Tcl_GlobalEval(interp, protPtr->command);
	    if (result != TCL_OK) {
		Tcl_AddErrorInfo(interp, "\n    (command for \"");
		Tcl_AddErrorInfo(interp,
			Tk_GetAtomName((Tk_Window) winPtr, protocol));
		Tcl_AddErrorInfo(interp, "\" window manager protocol)");
		Tk_BackgroundError(interp);
	    }
            Tcl_Release((ClientData) interp);
	    Tcl_Release((ClientData) protPtr);
	    return;
	}
    }

    /*
     * No handler was present for this protocol.  If this is a
     * WM_DELETE_WINDOW message then just destroy the window.
     */

    if (protocol == Tk_InternAtom((Tk_Window) winPtr, "WM_DELETE_WINDOW")) {
	Tk_DestroyWindow((Tk_Window) winPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MacOSXIsAppInFront --
 *
 *	Returns 1 if this app is the foreground app. 
 *
 * Results:
 *	1 if app is in front, 0 otherwise.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_MacOSXIsAppInFront (void)
{
    return tkMacOSXAppInFront;
}@


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


