package Tk::Entry; # Converted from entry.tcl -- # # This file defines the default bindings for Tk entry widgets. # # @(#) entry.tcl 1.22 94/12/17 16:05:14 # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994 Sun Microsystems, Inc. # Copyright (c) 1995-2003 Nick Ing-Simmons. All rights reserved. # This program is free software; you can redistribute it and/or use vars qw($VERSION); use strict; $VERSION = sprintf '4.%03d',q$Revision: #17 $ =~ /#(\d+)/; # modify it under the same terms as Perl itself, subject # to additional disclaimer in license.terms due to partial # derivation from Tk4.0 sources. use Tk::Widget (); use Tk::Clipboard (); use base qw(Tk::Clipboard Tk::Widget); import Tk qw(Ev $XS_VERSION); Construct Tk::Widget 'Entry'; bootstrap Tk::Entry; sub Tk_cmd { \&Tk::entry } Tk::Methods('bbox','delete','get','icursor','index','insert','scan', 'selection','validate','xview'); use Tk::Submethods ( 'selection' => [qw(clear range adjust present to from)], 'xview' => [qw(moveto scroll)], ); sub wordstart {my ($w,$pos) = @_; my $string = $w->get; $pos = $w->index('insert')-1 unless(defined $pos); $string = substr($string,0,$pos); $string =~ s/\S*$//; length $string; } sub wordend {my ($w,$pos) = @_; my $string = $w->get; my $anc = length $string; $pos = $w->index('insert') unless(defined $pos); $string = substr($string,$pos); $string =~ s/^(?:((?=\s)\s*|(?=\S)\S*))//x; $anc - length($string); } sub deltainsert { my ($w,$d) = @_; return $w->index('insert')+$d; } # # Bind -- # This procedure is invoked the first time the mouse enters an # entry widget or an entry widget receives the input focus. It creates # all of the class bindings for entries. # # Arguments: # event - Indicates which event caused the procedure to be invoked # (Enter or FocusIn). It is used so that we can carry out # the functions of that event in addition to setting up # bindings. sub ClassInit { my ($class,$mw) = @_; $class->SUPER::ClassInit($mw); # <>, <> and <> defined in Tk::Clipboard $mw->bind($class,'<>' => sub { my $w = shift; $w->delete("sel.first", "sel.last"); }); $mw->bind($class,'<>' => [sub { my($w, $x) = @_; # XXX logic in Tcl/Tk version screwed up? if (!$Tk::strictMotif && !$Tk::mouseMoved) { $w->Paste($x); } }, Ev('x')]); # Standard Motif bindings: # The binding is different from the Tcl/Tk version: $mw->bind($class,'','selectionClear'); $mw->bind($class,'<1>',['Button1',Ev('x'),Ev('y')]); $mw->bind($class,'',['Button1Release',Ev('x'),Ev('y')]); $mw->bind($class,'',['Motion',Ev('x'),Ev('y')]); $mw->bind($class,'',['MouseSelect',Ev('x'),'word','sel.first']); $mw->bind($class,'',['MouseSelect',Ev('x'),'word']); $mw->bind($class,'',['MouseSelect',Ev('x'),'line',0]); $mw->bind($class,'',['MouseSelect',Ev('x'),'line']); $mw->bind($class,'','Shift_1'); $mw->bind($class,'',['AutoScan',Ev('x')]); $mw->bind($class,'','CancelRepeat'); $mw->bind($class,'','Control_1'); $mw->bind($class,'', ['SetCursor',Ev('deltainsert',-1)]); $mw->bind($class,'',['SetCursor',Ev('deltainsert',1)]); $mw->bind($class,'',['KeySelect',Ev('deltainsert',-1)]); $mw->bind($class,'',['KeySelect',Ev('deltainsert',1)]); $mw->bind($class,'',['SetCursor',Ev(['wordstart'])]); $mw->bind($class,'',['SetCursor',Ev(['wordend'])]); $mw->bind($class,'',['KeySelect',Ev(['wordstart'])]); $mw->bind($class,'',['KeySelect',Ev(['wordend'])]); $mw->bind($class,'',['SetCursor',0]); $mw->bind($class,'',['KeySelect',0]); $mw->bind($class,'',['SetCursor','end']); $mw->bind($class,'',['KeySelect','end']); $mw->bind($class,'','Delete'); $mw->bind($class,'','Backspace'); $mw->bind($class,'',['selectionFrom','insert']); $mw->bind($class,'