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

  1. # NOTE: Derived from ..\blib\lib\Tk\Entry.pm.  Changes made here will be lost.
  2. package Tk::Entry;
  3.  
  4. # MouseSelect --
  5. # This procedure is invoked when dragging out a selection with
  6. # the mouse. Depending on the selection mode (character, word,
  7. # line) it selects in different-sized units. This procedure
  8. # ignores mouse motions initially until the mouse has moved from
  9. # one character to another or until there have been multiple clicks.
  10. #
  11. # Arguments:
  12. # w - The entry window in which the button was pressed.
  13. # x - The x-coordinate of the mouse.
  14. sub MouseSelect
  15. {
  16.  my $w = shift;
  17.  my $x = shift;
  18.  my $cur = $w->index("@" . $x);
  19.  my $anchor = $w->index("anchor");
  20.  if (($cur != $anchor) || (abs($Tk::pressX - $x) >= 3))
  21.   {
  22.    $Tk::mouseMoved = 1
  23.   }
  24.  my $mode = $Tk::selectMode;
  25.  if ($mode eq "char")
  26.   {
  27.    if ($Tk::mouseMoved)
  28.     {
  29.      if ($cur < $anchor)
  30.       {
  31.        $w->selection("to",$cur)
  32.       }
  33.      else
  34.       {
  35.        $w->selection("to",$cur+1)
  36.       }
  37.     }
  38.   }
  39.  elsif ($mode eq "word")
  40.   {
  41.    if ($cur < $w->index("anchor"))
  42.     {
  43.      $w->selection("range",$w->wordstart($cur),$w->wordend($anchor-1))
  44.     }
  45.    else
  46.     {
  47.      $w->selection("range",$w->wordstart($anchor),$w->wordend($cur))
  48.     }
  49.   }
  50.  elsif ($mode eq "line")
  51.   {
  52.    $w->selection("range",0,"end")
  53.   }
  54.  $w->idletasks;
  55. }
  56.  
  57. 1;
  58.