From 9be3be3ff3662c21cba709f5d9c3c8167efc409c Mon Sep 17 00:00:00 2001 From: lecoanet Date: Thu, 28 Mar 2002 10:41:37 +0000 Subject: *** empty log message *** --- Perl/ZincText.pm | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Perl/ZincText.pm (limited to 'Perl/ZincText.pm') diff --git a/Perl/ZincText.pm b/Perl/ZincText.pm new file mode 100644 index 0000000..2785b39 --- /dev/null +++ b/Perl/ZincText.pm @@ -0,0 +1,93 @@ + +package ZincText; + + +sub new { + my $proto = shift; + my $type = ref($proto) || $proto; + my ($zinc) = @_; + my $self = {}; + + $zinc->bind('text', '<1>' => sub {startSel($zinc)}); + $zinc->bind('text', '' => sub {extendSel($zinc)}); + $zinc->bind('text', '' => sub {extendSel($zinc)}); + $zinc->bind('text', '' => sub { + my $e = $zinc->XEvent(); + my($x, $y) = ($e->x, $e->y); + $zinc->select('adjust', 'current', "\@$x,$y"); }); + $zinc->bind('text', '' => sub {moveCur($zinc, -1);}); + $zinc->bind('text', '' => sub {moveCur($zinc, 1);}); + $zinc->bind('text', '' => sub {setCur($zinc, 0);}); + $zinc->bind('text', '' => sub {setCur($zinc, 0);}); + $zinc->bind('text', '' => sub {setCur($zinc, 'end');}); + $zinc->bind('text', '' => sub {setCur($zinc, 'end');}); + $zinc->bind('text', '' => sub {insertChar($zinc);}); + $zinc->bind('text', '' => sub {insertChar($zinc);}); + $zinc->bind('text', '' => sub { + $zinc->insert($zinc->focus(), 'insert', "\n"); }); + $zinc->bind('text', '' => sub {textDel($zinc, -1)}); + $zinc->bind('text', '' => sub {textDel($zinc, 0)}); + $zinc->bind('text', '' => sub { + $zinc->dchars($zinc->focus(), 'sel.first', 'sel.last'); }); + $zinc->bind('text', '' => sub { + $zinc->insert($zinc->focus(), 'insert', Tk::selection('get')); }); + + bless ($self, $type); + return $self; +} + + +sub insertChar { + my ($w) = @_; + my $c = $w->XEvent->A(); + + $w->insert($w->focus(), 'insert', $c); +} + + +sub setCur { + my ($w, $where) = @_; + my $it = $w->focus(); + + $w->cursor($it, $where); +} + + +sub moveCur { + my ($w, $dir) = @_; + my $it = $w->focus(); + my $index = $w->index($it, 'insert'); + + $w->cursor($it, $index + $dir); +} + + +sub startSel { + my($w) = @_; + my $e = $w->XEvent; + my($x, $y) = ($e->x, $e->y); + + $w->cursor('current', "\@$x,$y"); + $w->focus('current'); + $w->Tk::focus; + $w->select('from', 'current', "\@$x,$y"); +} + + +sub extendSel { + my($w) = @_; + my $e = $w->XEvent; + my($x, $y) = ($e->x, $e->y); + $w->select('to', 'current', "\@$x,$y"); +} + + +sub textDel { + my($w, $dir) = @_; + my $it = $w->focus(); + my $ind = $w->index($it, 'insert') + $dir; + + $w->dchars($it, $ind) if ($ind >= 0); +} + +1; -- cgit v1.1