summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--generic/tkEvent.c19
-rw-r--r--generic/tkInt.h4
-rw-r--r--tests/event.test17
4 files changed, 47 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 27f9a9f..58a0258 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2003-02-14 Mo DeJong <mdejong@users.sourceforge.net>
+
+ * generic/tkEvent.c (Tk_HandleEvent): Fixup button
+ press state saving code, it was incorrectly converting
+ normal motion events into button press and motion
+ events in some cases.
+ * generic/tkInt.h: Add mouseButtonWindow member
+ to the TkDisplay structure.
+ * tests/event.test: Add test case for faulty
+ button motion logic.
+
2003-02-14 Jeff Hobbs <jeffh@ActiveState.com>
* README: Bumped to 8.4.2.
diff --git a/generic/tkEvent.c b/generic/tkEvent.c
index 009e2f5..954f24c 100644
--- a/generic/tkEvent.c
+++ b/generic/tkEvent.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkEvent.c,v 1.16 2002/06/19 19:37:54 mdejong Exp $
+ * RCS: @(#) $Id: tkEvent.c,v 1.17 2003/02/18 06:22:44 mdejong Exp $
*/
#include "tkPort.h"
@@ -645,6 +645,7 @@ Tk_HandleEvent(eventPtr)
if (eventPtr->type==ButtonPress) {
dispPtr = TkGetDisplay(eventPtr->xbutton.display);
+ dispPtr->mouseButtonWindow = eventPtr->xbutton.window;
eventPtr->xbutton.state |= dispPtr->mouseButtonState;
switch (eventPtr->xbutton.button) {
case 1: dispPtr->mouseButtonState |= Button1Mask; break;
@@ -653,6 +654,7 @@ Tk_HandleEvent(eventPtr)
}
} else if (eventPtr->type==ButtonRelease) {
dispPtr = TkGetDisplay(eventPtr->xbutton.display);
+ dispPtr->mouseButtonWindow = 0;
switch (eventPtr->xbutton.button) {
case 1: dispPtr->mouseButtonState &= ~Button1Mask; break;
case 2: dispPtr->mouseButtonState &= ~Button2Mask; break;
@@ -661,7 +663,20 @@ Tk_HandleEvent(eventPtr)
eventPtr->xbutton.state |= dispPtr->mouseButtonState;
} else if (eventPtr->type==MotionNotify) {
dispPtr = TkGetDisplay(eventPtr->xmotion.display);
- eventPtr->xmotion.state |= dispPtr->mouseButtonState;
+ if (dispPtr->mouseButtonState & (Button1Mask|Button2Mask|Button3Mask)) {
+ if (eventPtr->xbutton.window != dispPtr->mouseButtonWindow) {
+ /*
+ * This motion event should not be interpreted as a button
+ * press + motion event since this is not the same window
+ * the button was pressed down in.
+ */
+ dispPtr->mouseButtonState &=
+ ~(Button1Mask|Button2Mask|Button3Mask);
+ dispPtr->mouseButtonWindow = 0;
+ } else {
+ eventPtr->xmotion.state |= dispPtr->mouseButtonState;
+ }
+ }
}
/*
diff --git a/generic/tkInt.h b/generic/tkInt.h
index cd40d80..2723d41 100644
--- a/generic/tkInt.h
+++ b/generic/tkInt.h
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: $Id: tkInt.h,v 1.55 2003/01/28 20:39:15 jenglish Exp $
+ * RCS: $Id: tkInt.h,v 1.56 2003/02/18 06:22:44 mdejong Exp $
*/
#ifndef _TKINT
@@ -493,6 +493,8 @@ typedef struct TkDisplay {
*/
int mouseButtonState; /* current mouse button state for this
* display */
+ Window mouseButtonWindow; /* Window the button state was set in,
+ * added in Tk 8.4. */
Window warpWindow;
int warpX;
int warpY;
diff --git a/tests/event.test b/tests/event.test
index e989f02..66fc029 100644
--- a/tests/event.test
+++ b/tests/event.test
@@ -6,7 +6,7 @@
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
-# RCS: @(#) $Id: event.test,v 1.12 2002/12/02 03:42:28 mdejong Exp $
+# RCS: @(#) $Id: event.test,v 1.13 2003/02/18 06:22:44 mdejong Exp $
package require tcltest 2.1
namespace import -force tcltest::configure
@@ -649,6 +649,21 @@ test event-triple-click-drag-1.1 { Triple click and drag across lines in
} [list "LINE THREE\n" "LINE TWO\nLINE THREE\n" \
"LINE ONE\nLINE TWO\nLINE THREE\n"]
+test event-button-state-1.1 { button press in a window that is then
+ destroyed, when the mouse is moved into another window it
+ should not generate a <B1-motion> event since the mouse
+ was not pressed down in that window. } {
+ destroy .t
+ set t [toplevel .t]
+
+ event generate $t <ButtonPress-1>
+ destroy $t
+ set t [toplevel .t]
+ set motion nomotion
+ bind $t <B1-Motion> {set motion inmotion}
+ event generate $t <Motion>
+ set motion
+} nomotion
# cleanup