summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatthoyts <patthoyts@users.sourceforge.net>2009-06-02 09:26:57 (GMT)
committerpatthoyts <patthoyts@users.sourceforge.net>2009-06-02 09:26:57 (GMT)
commit5098f86b8c628ee641dfd130ec9f516d91805eff (patch)
treebc1b4e39a7f4d9c50c7e9fa7d09c7cda6e968889
parent90c1a43eb7a8a363aef33e43ff390646b70aff1f (diff)
downloadtk-5098f86b8c628ee641dfd130ec9f516d91805eff.zip
tk-5098f86b8c628ee641dfd130ec9f516d91805eff.tar.gz
tk-5098f86b8c628ee641dfd130ec9f516d91805eff.tar.bz2
[Bug 2799589] Avoid setting the focus on a deleted window during delayed activation.
-rw-r--r--ChangeLog5
-rw-r--r--tests/winWm.test46
-rw-r--r--win/tkWinWm.c16
3 files changed, 63 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 5290800..7d123f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-06-02 Pat Thoyts <patthoyts@users.sourceforge.net>
+
+ * win/tkWinWm.c: [Bug 2799589] Avoid setting the focus on a
+ * tests/winWm.test: deleted window during delayed activation.
+
2009-05-21 Pat Thoyts <patthoyts@users.sourceforge.net>
* win/tkWinMenu.c: [Bug 2794778]: Calls to CallWindowProc can lead
diff --git a/tests/winWm.test b/tests/winWm.test
index 9ba872f..0f2f8d3 100644
--- a/tests/winWm.test
+++ b/tests/winWm.test
@@ -9,7 +9,7 @@
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
-# RCS: @(#) $Id: winWm.test,v 1.21 2008/10/06 23:13:19 patthoyts Exp $
+# RCS: @(#) $Id: winWm.test,v 1.22 2009/06/02 09:26:57 patthoyts Exp $
package require tcltest 2.2
namespace import ::tcltest::*
@@ -445,6 +445,50 @@ test winWm-8.2 {Tk_WmCmd procedure, "iconphoto" option} -constraints win -setup
destroy .t
} -result {}
+test winWm-9.0 "Bug #2799589 - delayed activation of destroyed window" -setup {
+ proc winwm90click {w} {
+ if {![winfo ismapped $w]} { update }
+ event generate $w <Enter>
+ focus -force $w
+ event generate $w <ButtonPress-1> -x 5 -y 5
+ event generate $w <ButtonRelease-1> -x 5 -y 5
+ }
+ proc winwm90proc3 {} {
+ global winwm90done winwm90check
+ set w .sd
+ toplevel $w
+ pack [button $w.b -text "OK" -command {set winwm90check 1}]
+ bind $w.b <Map> {after idle {winwm90click %W}}
+ update idletasks
+ tkwait visibility $w
+ grab $w
+ tkwait variable winwm90check
+ grab release $w
+ destroy $w
+ after idle {set winwm90done ok}
+ }
+ proc winwm90proc2 {w} { winwm90proc3; destroy $w }
+ proc winwm90proc1 {w} {
+ toplevel $w
+ pack [button $w.b -text "Do dialog" -command [list winwm90proc2 $w]]
+ bind $w.b <Map> {bind %W <Map> {}; after idle {winwm90click %W}}
+ }
+ global winwm90done
+ set winwm90done wait
+ toplevel .t
+} -body {
+ pack [button .t.b -text "Show" -command {winwm90proc1 .tx}]
+ bind .t.b <Map> {bind %W <Map> {}; after idle {winwm90click %W}}
+ after 5000 {set winwm90done timeout}
+ vwait winwm90done
+ set winwm90done
+} -cleanup {
+ foreach cmd {proc1 proc2 proc3 click} {
+ rename winwm90$cmd {}
+ }
+ destroy .tx .t .sd
+} -result {ok}
+
destroy .t
# cleanup
diff --git a/win/tkWinWm.c b/win/tkWinWm.c
index c038194..c272e65 100644
--- a/win/tkWinWm.c
+++ b/win/tkWinWm.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkWinWm.c,v 1.138 2009/05/03 06:46:13 dkf Exp $
+ * RCS: @(#) $Id: tkWinWm.c,v 1.139 2009/06/02 09:26:57 patthoyts Exp $
*/
#include "tkWinInt.h"
@@ -8259,10 +8259,20 @@ ActivateWindow(
*/
if (winPtr) {
+ Window window;
if (TkGrabState(winPtr) != TK_GRAB_EXCLUDED) {
- SetFocus(Tk_GetHWND(winPtr->window));
+ window = winPtr->window;
} else {
- SetFocus(Tk_GetHWND(winPtr->dispPtr->grabWinPtr->window));
+ window = winPtr->dispPtr->grabWinPtr->window;
+ }
+
+ /*
+ * Ensure the window was not destroyed while we were postponing
+ * the activation [Bug 2799589]
+ */
+
+ if (window) {
+ SetFocus(Tk_GetHWND(window));
}
}