aboutsummaryrefslogtreecommitdiff
path: root/Perl/ZincText.pm
diff options
context:
space:
mode:
authorlecoanet2002-03-28 10:41:37 +0000
committerlecoanet2002-03-28 10:41:37 +0000
commit9be3be3ff3662c21cba709f5d9c3c8167efc409c (patch)
tree0aa3e29cab2e531190290e2a006bbf47204b4438 /Perl/ZincText.pm
parent0635ba1528f2a60e6f4ad2bfabb969926f5af12d (diff)
downloadtkzinc-9be3be3ff3662c21cba709f5d9c3c8167efc409c.zip
tkzinc-9be3be3ff3662c21cba709f5d9c3c8167efc409c.tar.gz
tkzinc-9be3be3ff3662c21cba709f5d9c3c8167efc409c.tar.bz2
tkzinc-9be3be3ff3662c21cba709f5d9c3c8167efc409c.tar.xz
*** empty log message ***
Diffstat (limited to 'Perl/ZincText.pm')
-rw-r--r--Perl/ZincText.pm93
1 files changed, 93 insertions, 0 deletions
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', '<B1-Motion>' => sub {extendSel($zinc)});
+ $zinc->bind('text', '<Shift-B1-Motion>' => sub {extendSel($zinc)});
+ $zinc->bind('text', '<Shift-1>' => sub {
+ my $e = $zinc->XEvent();
+ my($x, $y) = ($e->x, $e->y);
+ $zinc->select('adjust', 'current', "\@$x,$y"); });
+ $zinc->bind('text', '<Left>' => sub {moveCur($zinc, -1);});
+ $zinc->bind('text', '<Right>' => sub {moveCur($zinc, 1);});
+ $zinc->bind('text', '<Control-a>' => sub {setCur($zinc, 0);});
+ $zinc->bind('text', '<Home>' => sub {setCur($zinc, 0);});
+ $zinc->bind('text', '<Control-e>' => sub {setCur($zinc, 'end');});
+ $zinc->bind('text', '<End>' => sub {setCur($zinc, 'end');});
+ $zinc->bind('text', '<KeyPress>' => sub {insertChar($zinc);});
+ $zinc->bind('text', '<Shift-KeyPress>' => sub {insertChar($zinc);});
+ $zinc->bind('text', '<Return>' => sub {
+ $zinc->insert($zinc->focus(), 'insert', "\n"); });
+ $zinc->bind('text', '<BackSpace>' => sub {textDel($zinc, -1)});
+ $zinc->bind('text', '<Delete>' => sub {textDel($zinc, 0)});
+ $zinc->bind('text', '<Control-d>' => sub {
+ $zinc->dchars($zinc->focus(), 'sel.first', 'sel.last'); });
+ $zinc->bind('text', '<Control-y>' => 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;