# This file converted to perltk using the tcl2perl script and much hand-editing. # jc 6/26/00 # # table.tcl -- # # version align with tkTable 2.4, jeff.hobbs@acm.org # This file defines the default bindings for Tk table widgets # and provides procedures that help in implementing those bindings. # #-------------------------------------------------------------------------- # tkPriv elements used in this file: # # afterId - Token returned by "after" for autoscanning. # tablePrev - The last element to be selected or deselected # during a selection operation. # mouseMoved - Boolean to indicate whether mouse moved while # the button was pressed. #-------------------------------------------------------------------------- ## Interactive cell resizing, affected by -resizeborders option ## package Tk::TableMatrix; use AutoLoader; use Carp; use strict; use vars( '%tkPriv', '$VERSION'); $VERSION = '0.5'; use Tk qw( Ev ); use base qw(Tk::Widget); Construct Tk::Widget 'TableMatrix'; bootstrap Tk::TableMatrix; sub Tk_cmd { \&Tk::tablematrix }; sub Tk::Widget::ScrlTableMatrix { shift->Scrolled('TableMatrix' => @_) } Tk::Methods("activate", "bbox", "border", "cget", "clear", "configure", "curselection", "curvalue", "delete", "get", "rowHeight", "hidden", "icursor", "index", "insert", "postscript", "reread", "scan", "see", "selection", "set", "spans", "tag", "validate", "version", "window", "colWidth", "xview", "yview"); use Tk::Submethods ( 'border' => [qw(mark dragto)], 'clear' => [qw(cache sizes tags all)], 'delete' => [qw(active cols rows)], 'insert' => [qw(active cols rows)], 'scan' => [qw(mark dragto)], 'selection'=> [qw(anchor clear includes set)], 'tag' => [qw(cell cget col configure delete exists includes names row)], 'window' => [qw(cget configure delete move names)], 'xview' => [qw(moveto scroll)], 'yview' => [qw(moveto scroll)], ); sub ClassInit { my ($class,$mw) = @_; $mw->bind($class,'<3>', sub { my $w = shift; my $Ev = $w->XEvent; ## You might want to check for cell returned if you want to ## restrict the resizing of certain cells $w->border('mark',$Ev->x,$Ev->y); } ); $mw->bind($class,'',['border','dragto',Ev('x'),Ev('y')]); $mw->bind($class,'<1>', sub { my $w = shift; my $Ev = $w->XEvent; if ($w->exists) { $w->BeginSelect($w->index('@' . $Ev->x.",".$Ev->y)); $w->focus; } $tkPriv{x} = $Ev->x; $tkPriv{y} = $Ev->y; $tkPriv{'mouseMoved'} = 0; } ); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; # If we already had motion, or we moved more than 1 pixel, # then we start the Motion routine $tkPriv{'mouseMoved'} = 1 if ($tkPriv{'mouseMoved'} || abs($Ev->x - $tkPriv{x}) > 1 || abs($Ev->y - $tkPriv{y}) > 1); $w->Motion($w->index('@' . $Ev->x.",".$Ev->y)) if ($tkPriv{'mouseMoved'}); } ); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; # empty } ); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; if ($w->exists) { $w->CancelRepeat; $w->activate('@' . $Ev->x.",".$Ev->y); } } ); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; $w->BeginExtend( $w->index('@' . $Ev->x.",".$Ev->y)); } ); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; $w->BeginToggle($w->index('@' . $Ev->x.",".$Ev->y)); } ); $mw->bind($class,'','CancelRepeat'); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; $tkPriv{x} = $Ev->x; $tkPriv{y} = $Ev->y; $w->AutoScan; } ); $mw->bind($class,'<2>', sub { my $w = shift; my $Ev = $w->XEvent; $w->scan('mark',$Ev->x,$Ev->y); $tkPriv{x} = $Ev->x; $tkPriv{y} = $Ev->y; $tkPriv{'mouseMoved'} = 0; } ); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; $tkPriv{'mouseMoved'} = 1 if ($Ev->x ne $tkPriv{'x'} || $Ev->y ne $tkPriv{'y'}); $w->scan('dragto',$Ev->x,$Ev->y) if ($tkPriv{'mouseMoved'}); } ); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; $w->Paste($w->index('@' . $Ev->x.",".$Ev->y)) unless ($tkPriv{'mouseMoved'}); } ); ClipboardKeysyms( $mw, $class, qw/ /); ClipboardKeysyms( $mw, $class, 'Control-c', 'Control-x', 'Control-v'); ############################ $mw->bind($class,'<>', sub { my $w = shift; my $Ev = $w->XEvent; eval { $w->activate('active'); } ; } ); # Remove this if you don't want cell commit to occur on every # Leave of the table. Another possible choice is . $mw->eventAdd( qw[ <> ]); $mw->bind($class,'',['ExtendSelect',-1,0]); $mw->bind($class,'',['ExtendSelect',1,0]); $mw->bind($class,'',['ExtendSelect',0,-1]); $mw->bind($class,'',['ExtendSelect',0,1]); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; $w->yview('scroll',-1,'pages'); $w->activate('@0,0'); } ); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; $w->yview('scroll',1,'pages'); $w->activate('@0,0'); } ); $mw->bind($class,'',['xview','scroll',-1,'pages']); $mw->bind($class,'',['xview','scroll',1,'pages']); $mw->bind($class,'',['see','origin']); $mw->bind($class,'',['see','end']); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; $w->selection('clear','all'); $w->activate('origin'); $w->selection('set','active'); $w->see('active'); } ); $mw->bind($class,'', sub { my $w = shift; my $Ev = $w->XEvent; $w->selection('clear','all'); $w->activate('end'); $w->selection('set','active'); $w->see('active'); } ); $mw->bind($class,'',['DataExtend','origin']); $mw->bind($class,'',['DataExtend','end']); $mw->bind($class,'