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

  1. # NOTE: Derived from ..\blib\lib\Tk\Menu.pm.  Changes made here will be lost.
  2. package Tk::Menu;
  3.  
  4. # LeftRight --
  5. # This procedure is invoked to handle "left" and "right" traversal
  6. # motions in menus. It traverses to the next menu in a menu bar,
  7. # or into or out of a cascaded menu.
  8. #
  9. # Arguments:
  10. # menu - The menu that received the keyboard
  11. # event.
  12. # direction - Direction in which to move: "left" or "right"
  13. sub LeftRight
  14. {
  15.  my $menu = shift;
  16.  my $direction = shift;
  17.  # First handle traversals into and out of cascaded menus.
  18.  if ($direction eq "right")
  19.   {
  20.    $count = 1;
  21.    if ($menu->typeIS("active","cascade"))
  22.     {
  23.      $menu->postcascade("active");
  24.      $m2 = $menu->entrycget("active","-menu");
  25.      $m2->FirstEntry if (defined $m2);
  26.      return;
  27.     }
  28.   }
  29.  else
  30.   {
  31.    $count = -1;
  32.    $m2 = $menu->parent;
  33.    if ($m2->IsMenu)
  34.     {
  35.      $menu->activate("none");
  36.      $m2->focus();
  37.      # This code unposts any posted submenu in the parent.
  38.      $tmp = $m2->index("active");
  39.      $m2->activate("none");
  40.      $m2->activate($tmp);
  41.      return;
  42.     }
  43.   }
  44.  # Can't traverse into or out of a cascaded menu. Go to the next
  45.  # or previous menubutton, if that makes sense.
  46.  $w = $Tk::postedMb;
  47.  if ($w eq "")
  48.   {
  49.    return;
  50.   }
  51.  my @buttons = $w->parent->children;
  52.  $length = @buttons;
  53.  $i = Tk::lsearch(\@buttons,$w)+$count;
  54.  while (1)
  55.   {
  56.    while ($i < 0)
  57.     {
  58.      $i += $length
  59.     }
  60.    while ($i >= $length)
  61.     {
  62.      $i += -$length
  63.     }
  64.    $mb = $buttons[$i];
  65.    last if ($mb->IsMenubutton && $mb->cget("-state") ne "disabled"
  66.             && defined($mb->cget('-menu'))
  67.             && $mb->cget('-menu')->index('last') ne 'none'
  68.            );
  69.    return if ($mb == $w);
  70.    $i += $count
  71.   }
  72.  $mb->PostFirst();
  73. }
  74.  
  75. 1;
  76.