# table.tcl -- # # Version align with tkTable 2.7, jeff at hobbs org # This file defines the default bindings for Tk table widgets # and provides procedures that help in implementing those bindings. # # RCS: @(#) $Id: tkTable.tcl,v 1.1.1.1 2011/03/01 20:00:38 joye Exp $ #-------------------------------------------------------------------------- # ::tk::table::Priv elements used in this file: # # x && y - Coords in widget # 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. # borderInfo - Boolean to know if the user clicked on a border # borderB1 - Boolean that set whether B1 can be used for the # interactiving resizing #-------------------------------------------------------------------------- namespace eval ::tk::table { # Ensure that a namespace is created for us variable Priv array set Priv [list x 0 y 0 afterId {} mouseMoved 0 \ borderInfo {} borderB1 1] } # ::tk::table::ClipboardKeysyms -- # This procedure is invoked to identify the keys that correspond to # the "copy", "cut", and "paste" functions for the clipboard. # # Arguments: # copy - Name of the key (keysym name plus modifiers, if any, # such as "Meta-y") used for the copy operation. # cut - Name of the key used for the cut operation. # paste - Name of the key used for the paste operation. proc ::tk::table::ClipboardKeysyms {copy cut paste} { bind Table <$copy> {tk_tableCopy %W} bind Table <$cut> {tk_tableCut %W} bind Table <$paste> {tk_tablePaste %W} } ::tk::table::ClipboardKeysyms ## ## Interactive cell resizing, affected by -resizeborders option ## bind Table <3> { ## You might want to check for cell returned if you want to ## restrict the resizing of certain cells %W border mark %x %y } bind Table { %W border dragto %x %y } ## Button events bind Table <1> { ::tk::table::Button1 %W %x %y } bind Table { ::tk::table::B1Motion %W %x %y } bind Table { if {$::tk::table::Priv(borderInfo) == "" && [winfo exists %W]} { ::tk::table::CancelRepeat %W activate @%x,%y } } bind Table { # empty } bind Table {::tk::table::BeginExtend %W [%W index @%x,%y]} bind Table {::tk::table::BeginToggle %W [%W index @%x,%y]} bind Table {::tk::table::CancelRepeat} bind Table { if {$::tk::table::Priv(borderInfo) == ""} { array set ::tk::table::Priv {x %x y %y} ::tk::table::AutoScan %W } } bind Table <2> { %W scan mark %x %y array set ::tk::table::Priv {x %x y %y} set ::tk::table::Priv(mouseMoved) 0 } bind Table { if {(%x != $::tk::table::Priv(x)) || (%y != $::tk::table::Priv(y))} { set ::tk::table::Priv(mouseMoved) 1 } if {$::tk::table::Priv(mouseMoved)} { %W scan dragto %x %y } } bind Table { if {!$::tk::table::Priv(mouseMoved)} { tk_tablePaste %W [%W index @%x,%y] } } ## Key events # This forces a cell commit if an active cell exists bind Table <> { catch {%W activate active} } # Remove this if you don't want cell commit to occur on every Leave for # the table (via mouse) or FocusOut (loss of focus by table). event add <> bind Table {::tk::table::ExtendSelect %W -1 0} bind Table {::tk::table::ExtendSelect %W 1 0} bind Table {::tk::table::ExtendSelect %W 0 -1} bind Table {::tk::table::ExtendSelect %W 0 1} bind Table {%W yview scroll -1 pages; %W activate topleft} bind Table {%W yview scroll 1 pages; %W activate topleft} bind Table {%W xview scroll -1 pages} bind Table {%W xview scroll 1 pages} bind Table {%W see origin} bind Table {%W see end} bind Table { %W selection clear all %W activate origin %W selection set active %W see active } bind Table { %W selection clear all %W activate end %W selection set active %W see active } bind Table {::tk::table::DataExtend %W origin} bind Table {::tk::table::DataExtend %W end} bind Table