From 4c0836f8ae0a1a68edf876a7bcce826b8518d658 Mon Sep 17 00:00:00 2001 From: patthoyts Date: Sat, 15 Nov 2008 00:00:27 +0000 Subject: bug 2239034: restrict [wm manage] to Frame type widgets --- ChangeLog | 14 ++++++- doc/wm.n | 8 +++- generic/tk.h | 7 +++- generic/tkFrame.c | 8 +++- macosx/tkMacOSXWm.c | 8 +++- tests/wm.test | 118 +++++++++++++++++++++++++++++++++++++++++++++------- unix/tkUnixWm.c | 8 +++- win/tkWinWm.c | 8 +++- 8 files changed, 155 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 85d0405..e4852d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,19 @@ +2008-11-14 Pat Thoyts + + * generic/tk.h: The tip 125 implementation permits the + * generic/tkFrame.c: wm manage command to manage any widget but + * macosx/tkMacOSXWm.c: only those with Frame instance data should + * unix/tkUnixWm.c: be permitted. We now check for the suitability + * win/tkWinWm.c: and raise an error for non-frame widgets. + * test/wm.test: Updated the tests and documentation. + * doc/wm.n: See also [Bug 2239034] + 2008-11-12 Joe English * generic/ttk/ttkWidget.c: Reworked widget construction and destruction sequence; fixes [Bug 2207435] and several other problems discovered during investigation of same. - * generic/ttk/ttkButton.c(CheckbuttonInitialize): + * generic/ttk/ttkButton.c(CheckbuttonInitialize): Account for initializeProc being called earlier in the construction sequence now. * tests/ttk/ttk.test: Updated test suite. @@ -19,7 +29,7 @@ 2008-11-11 Joe English - * generic/ttk/ttkWidget.c(BeginDrawing): Don't crash when + * generic/ttk/ttkWidget.c(BeginDrawing): Don't crash when application uses nondefault visual [Bug 2264732]. 2008-11-11 Jan Nijtmans diff --git a/doc/wm.n b/doc/wm.n index a0ac98a..01569fa 100644 --- a/doc/wm.n +++ b/doc/wm.n @@ -5,7 +5,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: wm.n,v 1.40 2008/09/23 13:36:58 dkf Exp $ +'\" RCS: @(#) $Id: wm.n,v 1.41 2008/11/15 00:00:27 patthoyts Exp $ '\" .so man.macros .TH wm n 8.5 Tk "Tk Built-In Commands" @@ -442,7 +442,11 @@ Note: not all window managers support the notion of an icon window. \fBwm manage \fIwidget\fR . The \fIwidget\fR specified will become a stand alone top-level window. The -window will be decorated with the window managers title bar, etc. +window will be decorated with the window managers title bar, etc. Only +\fIframe\fR, \fIlabelframe\fR and \fItoplevel\fR widgets can be used +with this command. Attempting to pass any other widget type will raise +an error. Attempting to manage a \fItoplevel\fR widget is benign and +achieves nothing. See also \fBGEOMETRY MANAGEMENT\fR. .TP \fBwm maxsize \fIwindow\fR ?\fIwidth height\fR? . diff --git a/generic/tk.h b/generic/tk.h index 516205b..0144e61 100644 --- a/generic/tk.h +++ b/generic/tk.h @@ -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: tk.h,v 1.124 2008/11/12 00:15:26 nijtmans Exp $ + * RCS: @(#) $Id: tk.h,v 1.125 2008/11/15 00:00:27 patthoyts Exp $ */ #ifndef _TK @@ -721,6 +721,8 @@ typedef XActivateDeactivateEvent XDeactivateEvent; (((Tk_FakeWin *) (tkwin))->flags & TK_WIN_MANAGED) #define Tk_TopWinHierarchy(tkwin) \ (((Tk_FakeWin *) (tkwin))->flags & TK_TOP_HIERARCHY) +#define Tk_IsManageable(tkwin) \ + (((Tk_FakeWin *) (tkwin))->flags & TK_WM_MANAGEABLE) #define Tk_ReqWidth(tkwin) (((Tk_FakeWin *) (tkwin))->reqWidth) #define Tk_ReqHeight(tkwin) (((Tk_FakeWin *) (tkwin))->reqHeight) /* Tk_InternalBorderWidth is deprecated */ @@ -856,6 +858,8 @@ typedef struct Tk_FakeWin { * TK_PROP_PROPCHANGE 1 means that PropertyNotify events in the * window's children should propagate up to this * window. + * TK_WM_MANAGEABLE 1 marks a window as capable of being converted + * into a toplevel using [wm manage]. */ #define TK_MAPPED 1 @@ -877,6 +881,7 @@ typedef struct Tk_FakeWin { #define TK_WIN_MANAGED 0x10000 #define TK_TOP_HIERARCHY 0x20000 #define TK_PROP_PROPCHANGE 0x40000 +#define TK_WM_MANAGEABLE 0x80000 /* *---------------------------------------------------------------------- diff --git a/generic/tkFrame.c b/generic/tkFrame.c index 472c8ca..4ff8866 100644 --- a/generic/tkFrame.c +++ b/generic/tkFrame.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: tkFrame.c,v 1.36 2008/11/08 22:52:29 dkf Exp $ + * RCS: @(#) $Id: tkFrame.c,v 1.37 2008/11/15 00:00:27 patthoyts Exp $ */ #include "default.h" @@ -556,6 +556,12 @@ CreateFrame( } if (newWin == NULL) { goto error; + } else { + /* + * Mark Tk frames as suitable candidates for [wm manage] + */ + TkWindow *winPtr = (TkWindow *)newWin; + winPtr->flags |= TK_WM_MANAGEABLE; } if (className == NULL) { className = Tk_GetOption(newWin, "class", "Class"); diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 5e4c9b3..9374f43 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -13,7 +13,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXWm.c,v 1.70 2008/10/17 23:18:38 nijtmans Exp $ + * RCS: @(#) $Id: tkMacOSXWm.c,v 1.71 2008/11/15 00:00:27 patthoyts Exp $ */ #include "tkMacOSXPrivate.h" @@ -2174,6 +2174,12 @@ WmManageCmd( if (!Tk_IsTopLevel(frameWin)) { MacDrawable *macWin = (MacDrawable *) winPtr->window; + if (!Tk_IsManageable(frameWin)) { + Tcl_AppendResult(interp, "window \"", + Tk_PathName(frameWin), "\" is not manageable: must be " + "a frame, labelframe or toplevel", NULL); + return TCL_ERROR; + } TkFocusSplit(winPtr); Tk_UnmapWindow(frameWin); if (wmPtr == NULL) { diff --git a/tests/wm.test b/tests/wm.test index 7a8a538..f28eeab 100644 --- a/tests/wm.test +++ b/tests/wm.test @@ -7,7 +7,7 @@ # Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # -# RCS: @(#) $Id: wm.test,v 1.45 2008/10/08 15:39:13 dgp Exp $ +# RCS: @(#) $Id: wm.test,v 1.46 2008/11/15 00:00:27 patthoyts Exp $ # This file tests window manager interactions that work across platforms. # Window manager tests that only work on a specific platform should be placed @@ -2091,28 +2091,112 @@ test wm-deletion-epoch-1.1 {Deletion epoch on multiple displays} -constraints al } ### Docking test (manage, forget) ### -test wm-manage-1.1 {managing a button} -setup { +test wm-manage-1.1 {managing a frame} -setup { set result [list] } -body { toplevel .t - button .t.b -text "Manage This" - pack .t.b + frame .t.f + pack [label .t.f.l -text hello] + wm manage .t.f + raise .t.f update - lappend result [winfo manage .t.b] - lappend result [winfo toplevel .t.b] - wm manage .t.b + lappend result [winfo manage .t.f] + lappend result [winfo toplevel .t.f] +} -cleanup { + deleteWindows +} -result {wm .t.f} +test wm-manage-1.2 {managing a toplevel} -setup { + set result [list] +} -body { + toplevel .t + pack [label .t.l -text hello] + wm manage .t + raise .t update - lappend result [winfo manage .t.b] - lappend result [winfo toplevel .t.b] - wm forget .t.b - pack .t.b + lappend result [winfo manage .t] + lappend result [winfo toplevel .t] +} -cleanup { + deleteWindows +} -result {wm .t} +test wm-manage-1.3 {managing a labelframe} -setup { + set result [list] +} -body { + toplevel .t + labelframe .t.f -text Labelframe + pack [label .t.f.l -text hello] + wm manage .t.f + raise .t.f + update + lappend result [winfo manage .t.f] + lappend result [winfo toplevel .t.f] +} -cleanup { + deleteWindows +} -result {wm .t.f} +test wm-manage-1.4 {managing a ttk::frame} -setup { + set result [list] +} -body { + toplevel .t + ttk::frame .t.f + pack [label .t.f.l -text hello] + wm manage .t.f + raise .t.f + update + lappend result [winfo manage .t.f] + lappend result [winfo toplevel .t.f] +} -cleanup { + deleteWindows +} -returnCodes error -result "window \".t.f\" is not manageable: must be a frame, labelframe or toplevel" +test wm-manage-1.5 {managing a text widget} -setup { + set result [list] +} -body { + toplevel .t + text .t.f + .t.f insert end "Manage text\n" {} + wm manage .t.f + raise .t.f + update + lappend result [winfo manage .t.f] + lappend result [winfo toplevel .t.f] +} -cleanup { + deleteWindows +} -returnCodes error -result "window \".t.f\" is not manageable: must be a frame, labelframe or toplevel" +test wm-manage-1.6 {managing a button} -setup { + set result [list] +} -body { + toplevel .t + button .t.f -text Button + wm manage .t.f + raise .t.f + update + lappend result [winfo manage .t.f] + lappend result [winfo toplevel .t.f] +} -cleanup { + deleteWindows +} -returnCodes error -result "window \".t.f\" is not manageable: must be a frame, labelframe or toplevel" +test wm-manage-1.7 {managing a frame} -setup { + set result [list] +} -body { + toplevel .t + frame .t.f + pack [label .t.f.l -text Label] + pack .t.f + update + lappend result [winfo manage .t.f] + lappend result [winfo toplevel .t.f] + wm manage .t.f + raise .t.f update - lappend result [winfo manage .t.b] - lappend result [winfo toplevel .t.b] + lappend result [winfo manage .t.f] + lappend result [winfo toplevel .t.f] + wm forget .t.f + pack .t.f + update + lappend result [winfo manage .t.f] + lappend result [winfo toplevel .t.f] } -cleanup { deleteWindows -} -result {pack .t wm .t.b pack .t} -test wm-manage-1.2 {unmanaging a toplevel} -setup { +} -result {pack .t wm .t.f pack .t} +test wm-manage-1.8 {unmanaging a toplevel} -setup { set result [list] } -body { toplevel .t @@ -2188,3 +2272,7 @@ cleanupTests catch {unset results} catch {unset focusin} return + +# Local variables: +# mode: tcl +# End: diff --git a/unix/tkUnixWm.c b/unix/tkUnixWm.c index 358ba0f..2218d86 100644 --- a/unix/tkUnixWm.c +++ b/unix/tkUnixWm.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: tkUnixWm.c,v 1.64 2008/11/08 18:44:40 dkf Exp $ + * RCS: @(#) $Id: tkUnixWm.c,v 1.65 2008/11/15 00:00:27 patthoyts Exp $ */ #include "tkUnixInt.h" @@ -2660,6 +2660,12 @@ WmManageCmd( register WmInfo *wmPtr = winPtr->wmInfoPtr; if (!Tk_IsTopLevel(frameWin)) { + if (!Tk_IsManageable(frameWin)) { + Tcl_AppendResult(interp, "window \"", + Tk_PathName(frameWin), "\" is not manageable: must be " + "a frame, labelframe or toplevel", NULL); + return TCL_ERROR; + } TkFocusSplit(winPtr); Tk_UnmapWindow(frameWin); winPtr->flags |= TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED; diff --git a/win/tkWinWm.c b/win/tkWinWm.c index 004397d..7660c04 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.131 2008/10/17 23:18:38 nijtmans Exp $ + * RCS: @(#) $Id: tkWinWm.c,v 1.132 2008/11/15 00:00:27 patthoyts Exp $ */ #include "tkWinInt.h" @@ -4587,6 +4587,12 @@ WmManageCmd( register WmInfo *wmPtr = winPtr->wmInfoPtr; if (!Tk_IsTopLevel(frameWin)) { + if (!Tk_IsManageable(frameWin)) { + Tcl_AppendResult(interp, "window \"", + Tk_PathName(frameWin), "\" is not manageable: must be " + "a frame, labelframe or toplevel", NULL); + return TCL_ERROR; + } TkFocusSplit(winPtr); Tk_UnmapWindow(frameWin); winPtr->flags |= TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED; -- cgit v0.12