From 5834454dfdb57f33bae61fb49206c33584e05ee6 Mon Sep 17 00:00:00 2001 From: patthoyts Date: Wed, 30 Dec 2009 00:29:38 +0000 Subject: Patch 2879789: Make torn-off menu entrys activate across whole window backported from HEAD. --- ChangeLog | 6 ++++++ generic/tkMenu.c | 38 +++++++++++++++++++++++++------------- tests/menu.test | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 891a366..ead5b95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-12-30 Pat Thoyts + + * generic/tkMenu.c: Torn off menu items are only activated over + * tests/menu.tcl: a limited region of the window. Fixed to make + the whole width of a menu item activate the entry. [Patch 2879789] + 2009-12-27 Pat Thoyts * win/tkWinMenu.c: Highlight for cascade items in torn-off menus diff --git a/generic/tkMenu.c b/generic/tkMenu.c index 2db5e70..98f3f60 100644 --- a/generic/tkMenu.c +++ b/generic/tkMenu.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: tkMenu.c,v 1.41.2.2 2009/04/10 16:16:04 das Exp $ + * RCS: @(#) $Id: tkMenu.c,v 1.41.2.3 2009/12/30 00:29:38 patthoyts Exp $ */ /* @@ -2905,16 +2905,16 @@ MenuDoYPosition( * * GetIndexFromCoords -- * - * Given a string of the form "@int", return the menu item corresponding - * to int. + * Given a string of the form "@integer", return the menu item + * corresponding to the provided y-coordinate in the menu window. * * Results: * If int is a valid number, *indexPtr will be the number of the - * menuentry that is the correct height. If int is invaled, *indexPtr + * menuentry that is the correct height. If int is invalid, *indexPtr * will be unchanged. Returns appropriate Tcl error number. * * Side effects: - * If int is invalid, interp's result will set to NULL. + * If int is invalid, interp's result will be set to NULL. * *---------------------------------------------------------------------- */ @@ -2928,6 +2928,7 @@ GetIndexFromCoords( { int x, y, i; char *p, *end; + int x2, borderwidth, max; TkRecomputeMenu(menuPtr); p = string + 1; @@ -2935,6 +2936,8 @@ GetIndexFromCoords( if (end == p) { goto error; } + Tk_GetPixelsFromObj(interp, menuPtr->tkwin, + menuPtr->borderWidthPtr, &borderwidth); if (*end == ',') { x = y; p = end + 1; @@ -2943,23 +2946,32 @@ GetIndexFromCoords( goto error; } } else { - Tk_GetPixelsFromObj(interp, menuPtr->tkwin, - menuPtr->borderWidthPtr, &x); + x = borderwidth; } + *indexPtr = -1; + + /* set the width of the final column to the remainder of the window + * being aware of windows that may not be mapped yet. + */ + max = Tk_IsMapped(menuPtr->tkwin) + ? Tk_Width(menuPtr->tkwin) : Tk_ReqWidth(menuPtr->tkwin); + max -= borderwidth; + for (i = 0; i < menuPtr->numEntries; i++) { + if (menuPtr->entries[i]->entryFlags & ENTRY_LAST_COLUMN) { + x2 = max; + } else { + x2 = menuPtr->entries[i]->x + menuPtr->entries[i]->width; + } if ((x >= menuPtr->entries[i]->x) && (y >= menuPtr->entries[i]->y) - && (x < (menuPtr->entries[i]->x + menuPtr->entries[i]->width)) + && (x < x2) && (y < (menuPtr->entries[i]->y + menuPtr->entries[i]->height))) { + *indexPtr = i; break; } } - if (i >= menuPtr->numEntries) { - /* i = menuPtr->numEntries - 1; */ - i = -1; - } - *indexPtr = i; return TCL_OK; error: diff --git a/tests/menu.test b/tests/menu.test index f67fcbe..653bb82 100644 --- a/tests/menu.test +++ b/tests/menu.test @@ -5,7 +5,7 @@ # Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # -# RCS: @(#) $Id: menu.test,v 1.20 2006/12/04 15:16:31 dkf Exp $ +# RCS: @(#) $Id: menu.test,v 1.20.4.1 2009/12/30 00:29:38 patthoyts Exp $ package require tcltest 2.1 eval tcltest::configure $argv @@ -2133,6 +2133,38 @@ test menu-22.2 {GetIndexFromCoords} { .m1 configure -tearoff 0 list [catch {.m1 index @5,5} msg] $msg [destroy .m1] } {0 0 {}} +test menu-22.3 {GetIndexFromCoords: mapped window, y only} { + catch {destroy .m1} + menu .m1 + .m1 add command -label "test" + .m1 configure -tearoff 0 + tk_popup .m1 0 0 + tkwait visibility .m1 + list [catch {.m1 index @5} msg] $msg [destroy .m1] +} {0 0 {}} +test menu-22.4 {GetIndexFromCoords: mapped window x,y} { + catch {destroy .m1} + menu .m1 + .m1 add command -label "test" + .m1 configure -tearoff 0 + tk_popup .m1 0 0 + tkwait visibility .m1 + update + set x [expr {[winfo width .m1] - [.m1 cget -borderwidth] - 1}] + list [catch {.m1 index @$x,5} msg] $msg [destroy .m1] +} {0 0 {}} +test menu-22.5 {GetIndexFromCoords: mapped wide window} { + catch {destroy .m1} + menu .m1 + .m1 add command -label "test" + .m1 configure -tearoff 0 + tk_popup .m1 0 0 + tkwait visibility .m1 + wm geometry .m1 200x100 + update + set x [expr {[winfo width .m1] - [.m1 cget -borderwidth] - 1}] + list [catch {.m1 index @$x,5} msg] $msg [destroy .m1] +} {0 0 {}} test menu-23.1 {RecursivelyDeleteMenu} { catch {destroy .m1} -- cgit v0.12