A Multi-Column Listbox
Check-in [d93cfd6f83]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:* mclistbox.tcl: Added a new binding for ButtonPress-1 to store the index of the row that is clicked on, so that when a drag event happens and the mclistbox::_init_drag_cmd os called, the index has already been calculated. Previously if the drag moved too quickly the wrong item would be dragged.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d93cfd6f832e389f132358d3557c3079673961a2
User & Date: kuchler 2000-06-19 17:47:38
Context
2000-08-08
02:28
* mclistbox.tcl: Added support for the '-state' flag so that the mclistbox can be either normal or disabled state. Since the listbox can't be disabled until tk 8.4, for now, it only disables the mclistbox by changing its foreground to the disabled foreground color. check-in: 5afd17b303 user: kuchler tags: trunk
2000-06-19
17:47
* mclistbox.tcl: Added a new binding for ButtonPress-1 to store the index of the row that is clicked on, so that when a drag event happens and the mclistbox::_init_drag_cmd os called, the index has already been calculated. Previously if the drag moved too quickly the wrong item would be dragged. check-in: d93cfd6f83 user: kuchler tags: trunk
2000-06-15
00:48
* mclistbox.tcl: Replaced several catch {unset varname} calls with if {[info exists varname]} {unset varname}. This avoids using the catch, and also prevents the ::errorInfo corruption that was happening in BWidgets.* dialog.tcl check-in: fbe64cb7af user: kuchler tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.









1
2
3
4
5
6
7








2000-06-16  Dan Kuchler  <[email protected]>

        * mclistbox.tcl: Replaced several catch {unset varname} calls with
        if {[info exists varname]} {unset varname}.  This avoids using the
        catch, and also prevents the ::errorInfo corruption that was happening
        in mclistbox
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2000-06-19  Dan Kuchler  <[email protected]>

        * mclistbox.tcl: Added a new binding for ButtonPress-1 to store the
        index of the row that is clicked on, so that when a drag event happens
        and the mclistbox::_init_drag_cmd os called, the index has already
        been calculated.  Previously if the drag moved too quickly the wrong
        item would be dragged.

2000-06-16  Dan Kuchler  <[email protected]>

        * mclistbox.tcl: Replaced several catch {unset varname} calls with
        if {[info exists varname]} {unset varname}.  This avoids using the
        catch, and also prevents the ::errorInfo corruption that was happening
        in mclistbox

Changes to mclistbox.tcl.

649
650
651
652
653
654
655



656
657
658
659
660
661
662
...
667
668
669
670
671
672
673



























674
675
676
677
678
679
680
....
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861













2862
2863
2864
2865
2866
2867
2868
	set binding [bind Listbox $event]
	regsub -all {%W} $binding {[::mclistbox::convert %W -W]} binding
	regsub -all {%x} $binding {[::mclistbox::convert %W -x %x]} binding
	regsub -all {%y} $binding {[::mclistbox::convert %W -y %y]} binding
	bind Mclistbox $event $binding
    }




    # these define bindings for the column labels for resizing. Note
    # that we need both the name of this widget (calculated by $this)
    # as well as the specific widget that the event occured over.
    # Also note that $this is a constant string that gets evaluated
    # when the binding fires.
    # What a pain.
    set this {[::mclistbox::convert %W -W]}
................................................................................
    bind MclistboxMouseBindings <Enter> \
	    "::mclistbox::ResizeEvent $this motion %W %x %X %Y"
    bind MclistboxMouseBindings <Motion> \
	    "::mclistbox::ResizeEvent $this motion %W %x %X %Y"
    bind MclistboxMouseBindings <B1-Motion> \
	    "::mclistbox::ResizeEvent $this drag %W %x %X %Y"
}




























# ::mclistbox::NewColumn --
#
#    Adds a new column to the mclistbox widget
#
# Arguments:
#
................................................................................
# Results:
#	{type {ops} data}
#       type     type of the data
#       ops      list of acceptable operations (copy, move and link)
#       data     the dragged data

proc ::mclistbox::_init_drag_cmd {path X Y top} {
    set index [$path nearest [expr {$Y - [winfo rooty $path]}]]
    set path  [::mclistbox::convert $path -W]
    upvar ::mclistbox::${path}::options options













    set cmd   $options(-draginitcmd)
    if { ![string equal $cmd ""] } {
	return [uplevel \#0 $cmd [list $path $index $top]]
    }
    return [list "LISTBOX_ITEM" {copy move} $index]
}







>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<


>
>
>
>
>
>
>
>
>
>
>
>
>







649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
...
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
....
2882
2883
2884
2885
2886
2887
2888

2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
	set binding [bind Listbox $event]
	regsub -all {%W} $binding {[::mclistbox::convert %W -W]} binding
	regsub -all {%x} $binding {[::mclistbox::convert %W -x %x]} binding
	regsub -all {%y} $binding {[::mclistbox::convert %W -y %y]} binding
	bind Mclistbox $event $binding
    }

    # Add a button press binding to track selection for drag and drop
    bind Mclistbox <ButtonPress-1> [list +::mclistbox::SetDragIndex %W %Y]

    # these define bindings for the column labels for resizing. Note
    # that we need both the name of this widget (calculated by $this)
    # as well as the specific widget that the event occured over.
    # Also note that $this is a constant string that gets evaluated
    # when the binding fires.
    # What a pain.
    set this {[::mclistbox::convert %W -W]}
................................................................................
    bind MclistboxMouseBindings <Enter> \
	    "::mclistbox::ResizeEvent $this motion %W %x %X %Y"
    bind MclistboxMouseBindings <Motion> \
	    "::mclistbox::ResizeEvent $this motion %W %x %X %Y"
    bind MclistboxMouseBindings <B1-Motion> \
	    "::mclistbox::ResizeEvent $this drag %W %x %X %Y"
}

# ::mclistbox::SetDragIndex --
#
#    Store the drag index when the button is first clicked so that the right
#    item is dragged and dropped.
#
# Arguments:
#
#    path          The path to the widget where the drag is started (%W from
#                  bind).
#    Y             The %Y from bind.
#
# Results:
#
#    Calculates the index of the row that was clicked in case it the item is
#    dragged.
#

proc ::mclistbox::SetDragIndex {path Y} {
    set index [$path nearest [expr {$Y - [winfo rooty $path]}]]
    set path  [::mclistbox::convert $path -W]
    upvar ::mclistbox::${path}::options options

    set options(dragIndex) $index
    
    return
}

# ::mclistbox::NewColumn --
#
#    Adds a new column to the mclistbox widget
#
# Arguments:
#
................................................................................
# Results:
#	{type {ops} data}
#       type     type of the data
#       ops      list of acceptable operations (copy, move and link)
#       data     the dragged data

proc ::mclistbox::_init_drag_cmd {path X Y top} {

    set path  [::mclistbox::convert $path -W]
    upvar ::mclistbox::${path}::options options

    if {[info exists options(dragIndex)]} {

        set index $options(dragIndex)

    } else {

        # I don't think this will ever happen.. We should always get a button
        # press event before the drag init is called.

        set index 0
    }

    set cmd   $options(-draginitcmd)
    if { ![string equal $cmd ""] } {
	return [uplevel \#0 $cmd [list $path $index $top]]
    }
    return [list "LISTBOX_ITEM" {copy move} $index]
}