# copyright (C) 1997-2006 Jean-Luc Fontaine (mailto:jfontain@free.fr)
# this program is free software: please read the COPYRIGHT file enclosed in this package or use the Help Copyright menu

# $Id: tablesel.tcl,v 1.15 2006/01/28 19:16:59 jfontain Exp $

# implements selection on table cells, identified by row and column indices

class tableSelector {

    proc tableSelector {this args} selector {$args} {}

    proc ~tableSelector {this} {}

    ### public procedures follow:

    proc extend {this cell} {
        if {[info exists selector::($this,lastSelected)]} {
            scan $selector::($this,lastSelected) %d,%d startRow startColumn
            scan $cell %d,%d lastRow lastColumn
            if {$lastRow < $startRow} {                                                                                ;# order rows
                set last $startRow
                set startRow $lastRow
                set lastRow $last
            }
            if {$lastColumn < $startColumn} {                                                                       ;# order columns
                set last $startColumn
                set startColumn $lastColumn
                set lastColumn $last
            }
            set list {}
            for {set row $startRow} {$row <= $lastRow} {incr row} {
                for {set column $startColumn} {$column <= $lastColumn} {incr column} {
                    lappend list $row,$column
                }
            }
            selector::clear $this
            selector::set $this $list 1
        } else {
            selector::select $this $cell
        }
    }

}
