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

  1. # NOTE: Derived from ..\blib\lib\Tk\Menu.pm.  Changes made here will be lost.
  2. package Tk::Menu;
  3.  
  4. # FirstEntry --
  5. # Given a menu, this procedure finds the first entry that isn't
  6. # disabled or a tear-off or separator, and activates that entry.
  7. # However, if there is already an active entry in the menu (e.g.,
  8. # because of a previous call to tkPostOverPoint) then the active
  9. # entry isn't changed. This procedure also sets the input focus
  10. # to the menu.
  11. #
  12. # Arguments:
  13. # menu - Name of the menu window (possibly empty).
  14. sub FirstEntry
  15. {
  16.  my $menu = shift;
  17.  return if (!defined($menu) || $menu eq "" || !ref($menu));
  18.  $menu->Enter;
  19.  return if ($menu->index("active") ne "none");
  20.  $last = $menu->index("last");
  21.  return if ($last eq 'none');
  22.  for ($i = 0;$i <= $last;$i += 1)
  23.   {
  24.    my $state = eval {local $SIG{__DIE__};  $menu->entrycget($i,"-state") };
  25.    if (defined $state && $state ne "disabled" && !$menu->typeIS($i,"tearoff"))
  26.     {
  27.      $menu->activate($i);
  28.      return;
  29.     }
  30.   }
  31. }
  32.  
  33. 1;
  34.