home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Editores / Perl5 / perl / lib / site / auto / Tk / Menu / PostOverPoint.al < prev    next >
Encoding:
Text File  |  1997-08-10  |  1012 b   |  41 lines

  1. # NOTE: Derived from ..\blib\lib\Tk\Menu.pm.  Changes made here will be lost.
  2. package Tk::Menu;
  3.  
  4. # PostOverPoint --
  5. # This procedure posts a given menu such that a given entry in the
  6. # menu is centered over a given point in the root window. It also
  7. # activates the given entry.
  8. #
  9. # Arguments:
  10. # menu - Menu to post.
  11. # x, y - Root coordinates of point.
  12. # entry - Index of entry within menu to center over (x,y).
  13. # If omitted or specified as {}, then the menu's
  14. # upper-left corner goes at (x,y).
  15. sub PostOverPoint
  16. {
  17.  my $menu = shift;
  18.  my $x = shift;
  19.  my $y = shift;
  20.  my $entry = shift;
  21.  if (defined $entry)
  22.   {
  23.    if ($entry == $menu->index("last"))
  24.     {
  25.      $y -= ($menu->yposition($entry)+$menu->height)/2;
  26.     }
  27.    else
  28.     {
  29.      $y -= ($menu->yposition($entry)+$menu->yposition($entry+1))/2;
  30.     }
  31.    $x -= $menu->reqwidth/2;
  32.   }
  33.  $menu->post($x,$y);
  34.  if (defined($entry) && $menu->entrycget($entry,"-state") ne "disabled")
  35.   {
  36.    $menu->activate($entry)
  37.   }
  38. }
  39.  
  40. 1;
  41.