Tk Source Code

View Ticket
Login
Ticket UUID: 1353416
Title: tk_popup posts menu at the wrong place
Type: Bug Version: obsolete: 8.4.11
Submitter: fvogel Created on: 2005-11-10 20:02:08
Subsystem: 13. Win Menus Assigned To: hobbs
Priority: 7 High Severity:
Status: Closed Last Modified: 2014-02-19 21:42:15
Resolution: Fixed Closed By: hobbs
    Closed on: 2005-12-01 17:48:27
Description:
The bug occurs when tk_popup tries to post a menu at 
a position that does not allow to display the full menu 
height on screen.

The problem can be reproduced with this simple script 
to launch in wish:

menu .m
for {set i 0} {$i<15} {incr i} {
    .m add command -label "hello $i"
}
bind . <Button-1> { \
    tk_popup .m \
            [winfo pointerx .] \
            [winfo pointery .] \
}

Enlarge or move the . window so as its lower border is 
near the lower border of the screen and click button-1 in 
this area.

Since the menu is too tall to fit in the screen if the first 
line is placed at the cursor position, Tk computes a new 
placement point of the menu.

This computation must be incorrect since the menu is 
posted much too far away upwards.

Note however that the behaviour appears to be OK wrt 
the right side of the screen.

This is with Tck/Tk 8.4.11.
It is OK with 8.5 alpha release.
User Comments: hobbs added on 2005-12-02 00:48:27:
Logged In: YES 
user_id=72656

Backported fix that was used for 8.5, to reduce available
screenheight by 10 in calculation.  I believe that Windows
is actually adding padding for the menu shadow.

afaupell added on 2005-11-19 03:03:14:
Logged In: YES 
user_id=812825

proc tk::PostOverPoint should be changed to the following:

global tcl_platform
    
    if {[string compare $entry {}]} {
if {$entry == [$menu index last]} {
    incr y [expr {-([$menu yposition $entry]  + 
[winfo reqheight $menu])/2}]
} else {
    incr y [expr {-([$menu yposition $entry]  + 
[$menu yposition [expr {$entry+1}]])/2}]
}
incr x [expr {-[winfo reqwidth $menu]/2}]
    }
    $menu post $x $y
    if {$entry ne "" && [$menu entrycget $entry -state] 
ne "disabled"} {
$menu activate $entry
GenerateMenuSelect $menu
    }