OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [libgui/] [src/] [tkTable.tcl] - Diff between revs 579 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 579 Rev 1765
# table.tcl --
# table.tcl --
#
#
# version 1.8, jeff.hobbs@acm.org
# version 1.8, jeff.hobbs@acm.org
# This file defines the default bindings for Tk table widgets
# This file defines the default bindings for Tk table widgets
# and provides procedures that help in implementing those bindings.
# and provides procedures that help in implementing those bindings.
#
#
 
 
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# tkPriv elements used in this file:
# tkPriv elements used in this file:
#
#
# afterId -             Token returned by "after" for autoscanning.
# afterId -             Token returned by "after" for autoscanning.
# tablePrev -           The last element to be selected or deselected
# tablePrev -           The last element to be selected or deselected
#                       during a selection operation.
#                       during a selection operation.
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
 
 
# tkTableClipboardKeysyms --
# tkTableClipboardKeysyms --
# This procedure is invoked to identify the keys that correspond to
# This procedure is invoked to identify the keys that correspond to
# the "copy", "cut", and "paste" functions for the clipboard.
# the "copy", "cut", and "paste" functions for the clipboard.
#
#
# Arguments:
# Arguments:
# copy -        Name of the key (keysym name plus modifiers, if any,
# copy -        Name of the key (keysym name plus modifiers, if any,
#               such as "Meta-y") used for the copy operation.
#               such as "Meta-y") used for the copy operation.
# cut -         Name of the key used for the cut operation.
# cut -         Name of the key used for the cut operation.
# paste -       Name of the key used for the paste operation.
# paste -       Name of the key used for the paste operation.
 
 
proc tkTableClipboardKeysyms {copy cut paste} {
proc tkTableClipboardKeysyms {copy cut paste} {
    bind Table <$copy>  {tk_tableCopy %W}
    bind Table <$copy>  {tk_tableCopy %W}
    bind Table <$cut>   {tk_tableCut %W}
    bind Table <$cut>   {tk_tableCut %W}
    bind Table <$paste> {tk_tablePaste %W}
    bind Table <$paste> {tk_tablePaste %W}
}
}
 
 
## Interactive row resizing, affected by -resizeborders option
## Interactive row resizing, affected by -resizeborders option
##
##
bind Table <3>          {
bind Table <3>          {
    ## You might want to check for row returned if you want to
    ## You might want to check for row returned if you want to
    ## restrict the resizing of certain rows
    ## restrict the resizing of certain rows
    %W border mark %x %y
    %W border mark %x %y
}
}
bind Table <B3-Motion>  { %W border dragto %x %y }
bind Table <B3-Motion>  { %W border dragto %x %y }
 
 
## Button events
## Button events
 
 
bind Table <1> {
bind Table <1> {
    if {[winfo exists %W]} {
    if {[winfo exists %W]} {
        tkTableBeginSelect %W [%W index @%x,%y]
        tkTableBeginSelect %W [%W index @%x,%y]
        focus %W
        focus %W
    }
    }
}
}
bind Table <B1-Motion> {
bind Table <B1-Motion> {
    array set tkPriv {x %x y %y}
    array set tkPriv {x %x y %y}
    tkTableMotion %W [%W index @%x,%y]
    tkTableMotion %W [%W index @%x,%y]
}
}
bind Table <Double-1> {
bind Table <Double-1> {
    # empty
    # empty
}
}
bind Table <ButtonRelease-1> {
bind Table <ButtonRelease-1> {
    if {[winfo exists %W]} {
    if {[winfo exists %W]} {
        tkCancelRepeat
        tkCancelRepeat
        %W activate @%x,%y
        %W activate @%x,%y
    }
    }
}
}
 
 
bind Table <Shift-1>    {tkTableBeginExtend %W [%W index @%x,%y]}
bind Table <Shift-1>    {tkTableBeginExtend %W [%W index @%x,%y]}
bind Table <Control-1>  {tkTableBeginToggle %W [%W index @%x,%y]}
bind Table <Control-1>  {tkTableBeginToggle %W [%W index @%x,%y]}
bind Table <B1-Enter>   {tkCancelRepeat}
bind Table <B1-Enter>   {tkCancelRepeat}
bind Table <B1-Leave>   {
bind Table <B1-Leave>   {
    array set tkPriv {x %x y %y}
    array set tkPriv {x %x y %y}
    tkTableAutoScan %W
    tkTableAutoScan %W
}
}
bind Table <2> {
bind Table <2> {
    %W scan mark %x %y
    %W scan mark %x %y
    array set tkPriv {x %x y %y}
    array set tkPriv {x %x y %y}
    set tkPriv(mouseMoved) 0
    set tkPriv(mouseMoved) 0
}
}
bind Table <B2-Motion> {
bind Table <B2-Motion> {
    if {(%x != $tkPriv(x)) || (%y != $tkPriv(y))} { set tkPriv(mouseMoved) 1 }
    if {(%x != $tkPriv(x)) || (%y != $tkPriv(y))} { set tkPriv(mouseMoved) 1 }
    if $tkPriv(mouseMoved) { %W scan dragto %x %y }
    if $tkPriv(mouseMoved) { %W scan dragto %x %y }
}
}
bind Table <ButtonRelease-2> {
bind Table <ButtonRelease-2> {
    if {!$tkPriv(mouseMoved)} { tk_tablePaste %W [%W index @%x,%y] }
    if {!$tkPriv(mouseMoved)} { tk_tablePaste %W [%W index @%x,%y] }
}
}
 
 
## Key events
## Key events
 
 
if {[string comp {} [info command event]]} {
if {[string comp {} [info command event]]} {
    tkTableClipboardKeysyms <Copy> <Cut> <Paste>
    tkTableClipboardKeysyms <Copy> <Cut> <Paste>
} else {
} else {
    tkTableClipboardKeysyms Control-c Control-x Control-v
    tkTableClipboardKeysyms Control-c Control-x Control-v
}
}
 
 
bind Table <Any-Tab> {
bind Table <Any-Tab> {
    # empty to allow Tk focus movement
    # empty to allow Tk focus movement
}
}
# This forces a cell commit if an active cell exists
# This forces a cell commit if an active cell exists
# Remove this if you don't want cell commit to occur
# Remove this if you don't want cell commit to occur
# on every FocusOut
# on every FocusOut
bind Table <FocusOut> {
bind Table <FocusOut> {
    catch {%W activate active}
    catch {%W activate active}
}
}
bind Table <Shift-Up>           {tkTableExtendSelect %W -1  0}
bind Table <Shift-Up>           {tkTableExtendSelect %W -1  0}
bind Table <Shift-Down>         {tkTableExtendSelect %W  1  0}
bind Table <Shift-Down>         {tkTableExtendSelect %W  1  0}
bind Table <Shift-Left>         {tkTableExtendSelect %W  0 -1}
bind Table <Shift-Left>         {tkTableExtendSelect %W  0 -1}
bind Table <Shift-Right>        {tkTableExtendSelect %W  0  1}
bind Table <Shift-Right>        {tkTableExtendSelect %W  0  1}
bind Table <Prior>              {%W yview scroll -1 pages; %W activate @0,0}
bind Table <Prior>              {%W yview scroll -1 pages; %W activate @0,0}
bind Table <Next>               {%W yview scroll  1 pages; %W activate @0,0}
bind Table <Next>               {%W yview scroll  1 pages; %W activate @0,0}
bind Table <Control-Prior>      {%W xview scroll -1 pages}
bind Table <Control-Prior>      {%W xview scroll -1 pages}
bind Table <Control-Next>       {%W xview scroll  1 pages}
bind Table <Control-Next>       {%W xview scroll  1 pages}
bind Table <Home>               {%W see origin}
bind Table <Home>               {%W see origin}
bind Table <End>                {%W see end}
bind Table <End>                {%W see end}
bind Table <Control-Home> {
bind Table <Control-Home> {
    %W selection clear all
    %W selection clear all
    %W activate origin
    %W activate origin
    %W selection set active
    %W selection set active
    %W see active
    %W see active
}
}
bind Table <Control-End> {
bind Table <Control-End> {
    %W selection clear all
    %W selection clear all
    %W activate end
    %W activate end
    %W selection set active
    %W selection set active
    %W see active
    %W see active
}
}
bind Table <Shift-Control-Home> {tkTableDataExtend %W origin}
bind Table <Shift-Control-Home> {tkTableDataExtend %W origin}
bind Table <Shift-Control-End>  {tkTableDataExtend %W end}
bind Table <Shift-Control-End>  {tkTableDataExtend %W end}
bind Table <Select>             {tkTableBeginSelect %W [%W index active]}
bind Table <Select>             {tkTableBeginSelect %W [%W index active]}
bind Table <Shift-Select>       {tkTableBeginExtend %W [%W index active]}
bind Table <Shift-Select>       {tkTableBeginExtend %W [%W index active]}
bind Table <Control-slash>      {tkTableSelectAll %W}
bind Table <Control-slash>      {tkTableSelectAll %W}
bind Table <Control-backslash> {
bind Table <Control-backslash> {
    if {[string match browse [%W cget -selectmode]]} {%W selection clear all}
    if {[string match browse [%W cget -selectmode]]} {%W selection clear all}
}
}
bind Table <Up>                 {tkTableMoveCell %W -1  0}
bind Table <Up>                 {tkTableMoveCell %W -1  0}
bind Table <Down>               {tkTableMoveCell %W  1  0}
bind Table <Down>               {tkTableMoveCell %W  1  0}
bind Table <Left>               {tkTableMoveCell %W  0 -1}
bind Table <Left>               {tkTableMoveCell %W  0 -1}
bind Table <Right>              {tkTableMoveCell %W  0  1}
bind Table <Right>              {tkTableMoveCell %W  0  1}
bind Table <Any-KeyPress> {
bind Table <Any-KeyPress> {
    if {[string compare {} %A]} { %W insert active insert %A }
    if {[string compare {} %A]} { %W insert active insert %A }
}
}
bind Table <BackSpace> {
bind Table <BackSpace> {
    set tkPriv(junk) [%W icursor]
    set tkPriv(junk) [%W icursor]
    if {[string compare {} $tkPriv(junk)] && $tkPriv(junk)} {
    if {[string compare {} $tkPriv(junk)] && $tkPriv(junk)} {
        %W delete active [expr {$tkPriv(junk)-1}]
        %W delete active [expr {$tkPriv(junk)-1}]
    }
    }
}
}
bind Table <Delete>             {%W delete active insert}
bind Table <Delete>             {%W delete active insert}
bind Table <Escape>             {%W reread}
bind Table <Escape>             {%W reread}
 
 
#bind Table <Return>            {tkTableMoveCell %W 1 0}
#bind Table <Return>            {tkTableMoveCell %W 1 0}
bind Table <Return> {
bind Table <Return> {
    %W insert active insert "\n"
    %W insert active insert "\n"
}
}
 
 
bind Table <Control-Left>       {%W icursor [expr {[%W icursor]-1}]}
bind Table <Control-Left>       {%W icursor [expr {[%W icursor]-1}]}
bind Table <Control-Right>      {%W icursor [expr {[%W icursor]+1}]}
bind Table <Control-Right>      {%W icursor [expr {[%W icursor]+1}]}
bind Table <Control-e>          {%W icursor end}
bind Table <Control-e>          {%W icursor end}
bind Table <Control-a>          {%W icursor 0}
bind Table <Control-a>          {%W icursor 0}
bind Table <Control-k>          {%W delete active insert end}
bind Table <Control-k>          {%W delete active insert end}
bind Table <Control-equal>      {tkTableChangeWidth %W active  1}
bind Table <Control-equal>      {tkTableChangeWidth %W active  1}
bind Table <Control-minus>      {tkTableChangeWidth %W active -1}
bind Table <Control-minus>      {tkTableChangeWidth %W active -1}
 
 
# tkTableBeginSelect --
# tkTableBeginSelect --
#
#
# This procedure is typically invoked on button-1 presses. It begins
# This procedure is typically invoked on button-1 presses. It begins
# the process of making a selection in the table. Its exact behavior
# the process of making a selection in the table. Its exact behavior
# depends on the selection mode currently in effect for the table;
# depends on the selection mode currently in effect for the table;
# see the Motif documentation for details.
# see the Motif documentation for details.
#
#
# Arguments:
# Arguments:
# w     - The table widget.
# w     - The table widget.
# el    - The element for the selection operation (typically the
# el    - The element for the selection operation (typically the
#       one under the pointer).  Must be in row,col form.
#       one under the pointer).  Must be in row,col form.
 
 
proc tkTableBeginSelect {w el} {
proc tkTableBeginSelect {w el} {
    global tkPriv
    global tkPriv
    if {[scan $el %d,%d r c] != 2} return
    if {[scan $el %d,%d r c] != 2} return
    switch [$w cget -selectmode] {
    switch [$w cget -selectmode] {
        multiple {
        multiple {
            if {[$w tag includes title $el]} {
            if {[$w tag includes title $el]} {
                ## in the title area
                ## in the title area
                if {$r < [$w cget -titlerows]+[$w cget -roworigin]} {
                if {$r < [$w cget -titlerows]+[$w cget -roworigin]} {
                    ## We're in a column header
                    ## We're in a column header
                    if {$c < [$w cget -titlecols]+[$w cget -colorigin]} {
                    if {$c < [$w cget -titlecols]+[$w cget -colorigin]} {
                        ## We're in the topleft title area
                        ## We're in the topleft title area
                        set inc topleft
                        set inc topleft
                        set el2 end
                        set el2 end
                    } else {
                    } else {
                        set inc [$w index topleft row],$c
                        set inc [$w index topleft row],$c
                        set el2 [$w index end row],$c
                        set el2 [$w index end row],$c
                    }
                    }
                } else {
                } else {
                    ## We're in a row header
                    ## We're in a row header
                    set inc $r,[$w index topleft col]
                    set inc $r,[$w index topleft col]
                    set el2 $r,[$w index end col]
                    set el2 $r,[$w index end col]
                }
                }
            } else {
            } else {
                set inc $el
                set inc $el
                set el2 $el
                set el2 $el
            }
            }
            if [$w selection includes $inc] {
            if [$w selection includes $inc] {
                $w selection clear $el $el2
                $w selection clear $el $el2
            } else {
            } else {
                $w selection set $el $el2
                $w selection set $el $el2
            }
            }
        }
        }
        extended {
        extended {
            $w selection clear all
            $w selection clear all
            if {[$w tag includes title $el]} {
            if {[$w tag includes title $el]} {
                if {$r < [$w cget -titlerows]+[$w cget -roworigin]} {
                if {$r < [$w cget -titlerows]+[$w cget -roworigin]} {
                    ## We're in a column header
                    ## We're in a column header
                    if {$c < [$w cget -titlecols]+[$w cget -colorigin]} {
                    if {$c < [$w cget -titlecols]+[$w cget -colorigin]} {
                        $w selection set origin end
                        $w selection set origin end
                    } else {
                    } else {
                        $w selection set $el [$w index end row],$c
                        $w selection set $el [$w index end row],$c
                    }
                    }
                } else {
                } else {
                    ## We're in a row header
                    ## We're in a row header
                    $w selection set $el $r,[$w index end col]
                    $w selection set $el $r,[$w index end col]
                }
                }
            } else {
            } else {
                $w selection set $el
                $w selection set $el
            }
            }
            $w selection anchor $el
            $w selection anchor $el
            set tkPriv(tablePrev) $el
            set tkPriv(tablePrev) $el
        }
        }
        default {
        default {
            if {![$w tag includes title $el]} {
            if {![$w tag includes title $el]} {
                $w selection clear all
                $w selection clear all
                $w selection set $el
                $w selection set $el
                set tkPriv(tablePrev) $el
                set tkPriv(tablePrev) $el
            }
            }
            $w selection anchor $el
            $w selection anchor $el
        }
        }
    }
    }
}
}
 
 
# tkTableMotion --
# tkTableMotion --
#
#
# This procedure is called to process mouse motion events while
# This procedure is called to process mouse motion events while
# button 1 is down. It may move or extend the selection, depending
# button 1 is down. It may move or extend the selection, depending
# on the table's selection mode.
# on the table's selection mode.
#
#
# Arguments:
# Arguments:
# w     - The table widget.
# w     - The table widget.
# el    - The element under the pointer (must be in row,col form).
# el    - The element under the pointer (must be in row,col form).
 
 
proc tkTableMotion {w el} {
proc tkTableMotion {w el} {
    global tkPriv
    global tkPriv
    if {![info exists tkPriv(tablePrev)]} {
    if {![info exists tkPriv(tablePrev)]} {
        set tkPriv(tablePrev) $el
        set tkPriv(tablePrev) $el
        return
        return
    }
    }
    if {[string match $tkPriv(tablePrev) $el]} return
    if {[string match $tkPriv(tablePrev) $el]} return
    switch [$w cget -selectmode] {
    switch [$w cget -selectmode] {
        browse {
        browse {
            $w selection clear all
            $w selection clear all
            $w selection set $el
            $w selection set $el
            set tkPriv(tablePrev) $el
            set tkPriv(tablePrev) $el
        }
        }
        extended {
        extended {
            scan $tkPriv(tablePrev) %d,%d r c
            scan $tkPriv(tablePrev) %d,%d r c
            scan $el %d,%d elr elc
            scan $el %d,%d elr elc
            if {[$w tag includes title $el]} {
            if {[$w tag includes title $el]} {
                if {$r < [$w cget -titlerows]+[$w cget -roworigin]} {
                if {$r < [$w cget -titlerows]+[$w cget -roworigin]} {
                    ## We're in a column header
                    ## We're in a column header
                    if {$c < [$w cget -titlecols]+[$w cget -colorigin]} {
                    if {$c < [$w cget -titlecols]+[$w cget -colorigin]} {
                        ## We're in the topleft title area
                        ## We're in the topleft title area
                        $w selection clear anchor end
                        $w selection clear anchor end
                    } else {
                    } else {
                        $w selection clear anchor [$w index end row],$c
                        $w selection clear anchor [$w index end row],$c
                    }
                    }
                    $w selection set anchor [$w index end row],$elc
                    $w selection set anchor [$w index end row],$elc
                } else {
                } else {
                    ## We're in a row header
                    ## We're in a row header
                    $w selection clear anchor $r,[$w index end col]
                    $w selection clear anchor $r,[$w index end col]
                    $w selection set anchor $elr,[$w index end col]
                    $w selection set anchor $elr,[$w index end col]
                }
                }
            } else {
            } else {
                $w selection clear anchor $tkPriv(tablePrev)
                $w selection clear anchor $tkPriv(tablePrev)
                $w selection set anchor $el
                $w selection set anchor $el
            }
            }
            set tkPriv(tablePrev) $el
            set tkPriv(tablePrev) $el
        }
        }
    }
    }
}
}
 
 
# tkTableBeginExtend --
# tkTableBeginExtend --
#
#
# This procedure is typically invoked on shift-button-1 presses. It
# This procedure is typically invoked on shift-button-1 presses. It
# begins the process of extending a selection in the table. Its
# begins the process of extending a selection in the table. Its
# exact behavior depends on the selection mode currently in effect
# exact behavior depends on the selection mode currently in effect
# for the table; see the Motif documentation for details.
# for the table; see the Motif documentation for details.
#
#
# Arguments:
# Arguments:
# w - The table widget.
# w - The table widget.
# el - The element for the selection operation (typically the
# el - The element for the selection operation (typically the
# one under the pointer). Must be in numerical form.
# one under the pointer). Must be in numerical form.
 
 
proc tkTableBeginExtend {w el} {
proc tkTableBeginExtend {w el} {
    if {[string match extended [$w cget -selectmode]] &&
    if {[string match extended [$w cget -selectmode]] &&
        [$w selection includes anchor]} {
        [$w selection includes anchor]} {
        tkTableMotion $w $el
        tkTableMotion $w $el
    }
    }
}
}
 
 
# tkTableBeginToggle --
# tkTableBeginToggle --
#
#
# This procedure is typically invoked on control-button-1 presses. It
# This procedure is typically invoked on control-button-1 presses. It
# begins the process of toggling a selection in the table. Its
# begins the process of toggling a selection in the table. Its
# exact behavior depends on the selection mode currently in effect
# exact behavior depends on the selection mode currently in effect
# for the table; see the Motif documentation for details.
# for the table; see the Motif documentation for details.
#
#
# Arguments:
# Arguments:
# w - The table widget.
# w - The table widget.
# el - The element for the selection operation (typically the
# el - The element for the selection operation (typically the
# one under the pointer). Must be in numerical form.
# one under the pointer). Must be in numerical form.
 
 
proc tkTableBeginToggle {w el} {
proc tkTableBeginToggle {w el} {
    global tkPriv
    global tkPriv
    if {[string match extended [$w cget -selectmode]]} {
    if {[string match extended [$w cget -selectmode]]} {
        set tkPriv(tablePrev) $el
        set tkPriv(tablePrev) $el
        $w selection anchor $el
        $w selection anchor $el
        if [$w selection includes $el] {
        if [$w selection includes $el] {
            $w selection clear $el
            $w selection clear $el
        } else {
        } else {
            $w selection set $el
            $w selection set $el
        }
        }
    }
    }
}
}
 
 
# tkTableAutoScan --
# tkTableAutoScan --
# This procedure is invoked when the mouse leaves an entry window
# This procedure is invoked when the mouse leaves an entry window
# with button 1 down. It scrolls the window up, down, left, or
# with button 1 down. It scrolls the window up, down, left, or
# right, depending on where the mouse left the window, and reschedules
# right, depending on where the mouse left the window, and reschedules
# itself as an "after" command so that the window continues to scroll until
# itself as an "after" command so that the window continues to scroll until
# the mouse moves back into the window or the mouse button is released.
# the mouse moves back into the window or the mouse button is released.
#
#
# Arguments:
# Arguments:
# w - The entry window.
# w - The entry window.
 
 
proc tkTableAutoScan {w} {
proc tkTableAutoScan {w} {
    global tkPriv
    global tkPriv
    if {![winfo exists $w]} return
    if {![winfo exists $w]} return
    set x $tkPriv(x)
    set x $tkPriv(x)
    set y $tkPriv(y)
    set y $tkPriv(y)
    if {$y >= [winfo height $w]} {
    if {$y >= [winfo height $w]} {
        $w yview scroll 1 units
        $w yview scroll 1 units
    } elseif {$y < 0} {
    } elseif {$y < 0} {
        $w yview scroll -1 units
        $w yview scroll -1 units
    } elseif {$x >= [winfo width $w]} {
    } elseif {$x >= [winfo width $w]} {
        $w xview scroll 1 units
        $w xview scroll 1 units
    } elseif {$x < 0} {
    } elseif {$x < 0} {
        $w xview scroll -1 units
        $w xview scroll -1 units
    } else {
    } else {
        return
        return
    }
    }
    tkTableMotion $w [$w index @$x,$y]
    tkTableMotion $w [$w index @$x,$y]
    set tkPriv(afterId) [after 50 tkTableAutoScan $w]
    set tkPriv(afterId) [after 50 tkTableAutoScan $w]
}
}
 
 
# tkTableMoveCell --
# tkTableMoveCell --
#
#
# Moves the location cursor (active element) by the specified number
# Moves the location cursor (active element) by the specified number
# of cells and changes the selection if we're in browse or extended
# of cells and changes the selection if we're in browse or extended
# selection mode.
# selection mode.
#
#
# Arguments:
# Arguments:
# w - The table widget.
# w - The table widget.
# x - +1 to move down one cell, -1 to move up one cell.
# x - +1 to move down one cell, -1 to move up one cell.
# y - +1 to move right one cell, -1 to move left one cell.
# y - +1 to move right one cell, -1 to move left one cell.
 
 
proc tkTableMoveCell {w x y} {
proc tkTableMoveCell {w x y} {
    global tkPriv
    global tkPriv
    if {[catch {$w index active row} r]} return
    if {[catch {$w index active row} r]} return
    set c [$w index active col]
    set c [$w index active col]
    $w activate [incr r $x],[incr c $y]
    $w activate [incr r $x],[incr c $y]
    $w see active
    $w see active
    switch [$w cget -selectmode] {
    switch [$w cget -selectmode] {
        browse {
        browse {
            $w selection clear all
            $w selection clear all
            $w selection set active
            $w selection set active
        }
        }
        extended {
        extended {
            $w selection clear all
            $w selection clear all
            $w selection set active
            $w selection set active
            $w selection anchor active
            $w selection anchor active
            set tkPriv(tablePrev) [$w index active]
            set tkPriv(tablePrev) [$w index active]
        }
        }
    }
    }
}
}
 
 
# tkTableExtendSelect --
# tkTableExtendSelect --
#
#
# Does nothing unless we're in extended selection mode; in this
# Does nothing unless we're in extended selection mode; in this
# case it moves the location cursor (active element) by the specified
# case it moves the location cursor (active element) by the specified
# number of cells, and extends the selection to that point.
# number of cells, and extends the selection to that point.
#
#
# Arguments:
# Arguments:
# w - The table widget.
# w - The table widget.
# x - +1 to move down one cell, -1 to move up one cell.
# x - +1 to move down one cell, -1 to move up one cell.
# y - +1 to move right one cell, -1 to move left one cell.
# y - +1 to move right one cell, -1 to move left one cell.
 
 
proc tkTableExtendSelect {w x y} {
proc tkTableExtendSelect {w x y} {
    if {[string compare extended [$w cget -selectmode]] ||
    if {[string compare extended [$w cget -selectmode]] ||
        [catch {$w index active row} r]} return
        [catch {$w index active row} r]} return
    set c [$w index active col]
    set c [$w index active col]
    $w activate [incr r $x],[incr c $y]
    $w activate [incr r $x],[incr c $y]
    $w see active
    $w see active
    tkTableMotion $w [$w index active]
    tkTableMotion $w [$w index active]
}
}
 
 
# tkTableDataExtend
# tkTableDataExtend
#
#
# This procedure is called for key-presses such as Shift-KEndData.
# This procedure is called for key-presses such as Shift-KEndData.
# If the selection mode isnt multiple or extend then it does nothing.
# If the selection mode isnt multiple or extend then it does nothing.
# Otherwise it moves the active element to el and, if we're in
# Otherwise it moves the active element to el and, if we're in
# extended mode, extends the selection to that point.
# extended mode, extends the selection to that point.
#
#
# Arguments:
# Arguments:
# w - The table widget.
# w - The table widget.
# el - An integer cell number.
# el - An integer cell number.
 
 
proc tkTableDataExtend {w el} {
proc tkTableDataExtend {w el} {
    set mode [$w cget -selectmode]
    set mode [$w cget -selectmode]
    if {[string match extended $mode]} {
    if {[string match extended $mode]} {
        $w activate $el
        $w activate $el
        $w see $el
        $w see $el
        if [$w selection includes anchor] {tkTableMotion $w $el}
        if [$w selection includes anchor] {tkTableMotion $w $el}
    } elseif {[string match multiple $mode]} {
    } elseif {[string match multiple $mode]} {
        $w activate $el
        $w activate $el
        $w see $el
        $w see $el
    }
    }
}
}
 
 
# tkTableSelectAll
# tkTableSelectAll
#
#
# This procedure is invoked to handle the "select all" operation.
# This procedure is invoked to handle the "select all" operation.
# For single and browse mode, it just selects the active element.
# For single and browse mode, it just selects the active element.
# Otherwise it selects everything in the widget.
# Otherwise it selects everything in the widget.
#
#
# Arguments:
# Arguments:
# w - The table widget.
# w - The table widget.
 
 
proc tkTableSelectAll {w} {
proc tkTableSelectAll {w} {
    if {[regexp {^(single|browse)$} [$w cget -selectmode]]} {
    if {[regexp {^(single|browse)$} [$w cget -selectmode]]} {
        $w selection clear all
        $w selection clear all
        $w selection set active
        $w selection set active
        tkTableHandleType $w [$w index active]
        tkTableHandleType $w [$w index active]
    } else {
    } else {
        $w selection set origin end
        $w selection set origin end
    }
    }
}
}
 
 
# tkTableChangeWidth --
# tkTableChangeWidth --
# Adjust the widget of the specified cell by $a.
# Adjust the widget of the specified cell by $a.
#
#
# Arguments:
# Arguments:
# w - The table widget.
# w - The table widget.
# i - cell index
# i - cell index
# a - amount to adjust by
# a - amount to adjust by
 
 
proc tkTableChangeWidth {w i a} {
proc tkTableChangeWidth {w i a} {
    set tmp [$w index $i col]
    set tmp [$w index $i col]
    if {[set width [$w width $tmp]] >= 0} {
    if {[set width [$w width $tmp]] >= 0} {
        $w width $tmp [incr width $a]
        $w width $tmp [incr width $a]
    } else {
    } else {
        $w width $tmp [incr width -$a]
        $w width $tmp [incr width -$a]
    }
    }
}
}
 
 
# tk_tableCopy --
# tk_tableCopy --
# This procedure copies the selection from a table widget into the
# This procedure copies the selection from a table widget into the
# clipboard.
# clipboard.
#
#
# Arguments:
# Arguments:
# w -           Name of a table widget.
# w -           Name of a table widget.
 
 
proc tk_tableCopy w {
proc tk_tableCopy w {
    if {[selection own -displayof $w] == "$w"} {
    if {[selection own -displayof $w] == "$w"} {
        clipboard clear -displayof $w
        clipboard clear -displayof $w
        catch {clipboard append -displayof $w [selection get -displayof $w]}
        catch {clipboard append -displayof $w [selection get -displayof $w]}
    }
    }
}
}
 
 
# tk_tableCut --
# tk_tableCut --
# This procedure copies the selection from a table widget into the
# This procedure copies the selection from a table widget into the
# clipboard, then deletes the selection (if it exists in the given
# clipboard, then deletes the selection (if it exists in the given
# widget).
# widget).
#
#
# Arguments:
# Arguments:
# w -           Name of a table widget.
# w -           Name of a table widget.
 
 
proc tk_tableCut w {
proc tk_tableCut w {
    if {[selection own -displayof $w] == "$w"} {
    if {[selection own -displayof $w] == "$w"} {
        clipboard clear -displayof $w
        clipboard clear -displayof $w
        catch {
        catch {
            clipboard append -displayof $w [selection get -displayof $w]
            clipboard append -displayof $w [selection get -displayof $w]
            $w cursel set {}
            $w cursel set {}
            $w selection clear all
            $w selection clear all
        }
        }
    }
    }
}
}
 
 
# tk_tablePaste --
# tk_tablePaste --
# This procedure pastes the contents of the clipboard to the specified
# This procedure pastes the contents of the clipboard to the specified
# cell (active by default) in a table widget.
# cell (active by default) in a table widget.
#
#
# Arguments:
# Arguments:
# w -           Name of a table widget.
# w -           Name of a table widget.
# cell -        Cell to start pasting in.
# cell -        Cell to start pasting in.
 
 
proc tk_tablePaste {w {cell {}}} {
proc tk_tablePaste {w {cell {}}} {
    if {[string compare {} $cell]} {
    if {[string compare {} $cell]} {
        if {[catch {selection get -displayof $w} data]} return
        if {[catch {selection get -displayof $w} data]} return
    } else {
    } else {
        if {[catch {selection get -displayof $w -selection CLIPBOARD} data]} {
        if {[catch {selection get -displayof $w -selection CLIPBOARD} data]} {
            return
            return
        }
        }
        set cell active
        set cell active
    }
    }
    tk_tablePasteHandler $w [$w index $cell] $data
    tk_tablePasteHandler $w [$w index $cell] $data
    if {[$w cget -state] == "normal"} {focus $w}
    if {[$w cget -state] == "normal"} {focus $w}
}
}
 
 
# tk_tablePasteHandler --
# tk_tablePasteHandler --
# This procedure handles how data is pasted into the table widget.
# This procedure handles how data is pasted into the table widget.
# This handles data in the default table selection form.
# This handles data in the default table selection form.
# NOTE: this allows pasting into all cells, even those with -state disabled
# NOTE: this allows pasting into all cells, even those with -state disabled
#
#
# Arguments:
# Arguments:
# w -           Name of a table widget.
# w -           Name of a table widget.
# cell -        Cell to start pasting in.
# cell -        Cell to start pasting in.
 
 
proc tk_tablePasteHandler {w cell data} {
proc tk_tablePasteHandler {w cell data} {
    set rows    [expr {[$w cget -rows]-[$w cget -roworigin]}]
    set rows    [expr {[$w cget -rows]-[$w cget -roworigin]}]
    set cols    [expr {[$w cget -cols]-[$w cget -colorigin]}]
    set cols    [expr {[$w cget -cols]-[$w cget -colorigin]}]
    set r       [$w index $cell row]
    set r       [$w index $cell row]
    set c       [$w index $cell col]
    set c       [$w index $cell col]
    set rsep    [$w cget -rowseparator]
    set rsep    [$w cget -rowseparator]
    set csep    [$w cget -colseparator]
    set csep    [$w cget -colseparator]
    ## Assume separate rows are split by row separator if specified
    ## Assume separate rows are split by row separator if specified
    ## If you were to want multi-character row separators, you would need:
    ## If you were to want multi-character row separators, you would need:
    # regsub -all $rsep $data <newline> data
    # regsub -all $rsep $data <newline> data
    # set data [join $data <newline>]
    # set data [join $data <newline>]
    if {[string comp {} $rsep]} { set data [split $data $rsep] }
    if {[string comp {} $rsep]} { set data [split $data $rsep] }
    set row     $r
    set row     $r
    foreach line $data {
    foreach line $data {
        if {$row > $rows} break
        if {$row > $rows} break
        set col $c
        set col $c
        ## Assume separate cols are split by col separator if specified
        ## Assume separate cols are split by col separator if specified
        ## Unless a -separator was specified
        ## Unless a -separator was specified
        if {[string comp {} $csep]} { set line [split $line $csep] }
        if {[string comp {} $csep]} { set line [split $line $csep] }
        ## If you were to want multi-character col separators, you would need:
        ## If you were to want multi-character col separators, you would need:
        # regsub -all $csep $line <newline> line
        # regsub -all $csep $line <newline> line
        # set line [join $line <newline>]
        # set line [join $line <newline>]
        foreach item $line {
        foreach item $line {
            if {$col > $cols} break
            if {$col > $cols} break
            $w set $row,$col $item
            $w set $row,$col $item
            incr col
            incr col
        }
        }
        incr row
        incr row
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.