Bwidget Source Code
Check-in [36d4ee635f]
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:Make selected ComboBox item visible on first display.

ComboBox used to ask its embedded ListBox to make the selected item visible before it had ever been drawn. We now defer this action until the first redraw [eae238d5a7]

Timelines: family | ancestors | descendants | both | bwidget
Files: files | file ages | folders
SHA1: 36d4ee635f48c1f09697276944cd126f27f8df52
User & Date: adrianmedranocalvo 2016-03-07 11:57:06
Original Comment: Make selected ComboBox item visible on first display

ComboBox used to ask its embedded ListBox to make the selected item visible before it had ever been drawn. We now defer this action until the first redraw.

References
2016-03-08
07:31 New ticket [eae238d5a7] Listbox does not scroll on startup on selected item. artifact: 4eead101a9 user: oehhar
Context
2016-03-08
07:51
Added ChangeLog check-in: a89be8d3df user: oehhar tags: bwidget
2016-03-07
11:57
Make selected ComboBox item visible on first display.

ComboBox used to ask its embedded ListBox to make the selected item visible before it had ever been drawn. We now defer this action until the first redraw [eae238d5a7] check-in: 36d4ee635f user: adrianmedranocalvo tags: bwidget

2016-02-02
17:50
ChangeLog modified check-in: ec85d4e628 user: oehhar tags: bwidget
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to listbox.tcl.

23
24
25
26
27
28
29

30
31
32
33
34
35
36
...
126
127
128
129
130
131
132

133
134
135
136
137
138
139
...
735
736
737
738
739
740
741






742
743
744
745
746
747
748
749
750
751
752
753

754
755
756
757
758
759
760
...
954
955
956
957
958
959
960














961
962
963
964
965
966
967
....
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
....
1170
1171
1172
1173
1174
1175
1176



1177
1178

1179
1180
1181
1182
1183
1184
1185
#     - ListBox::see
#     - ListBox::edit
#     - ListBox::xview
#     - ListBox::yview
#     - ListBox::_update_edit_size
#     - ListBox::_destroy
#     - ListBox::_see

#     - ListBox::_update_scrollregion
#     - ListBox::_draw_item
#     - ListBox::_redraw_items
#     - ListBox::_redraw_selection
#     - ListBox::_redraw_listbox
#     - ListBox::_redraw_idle
#     - ListBox::_resize
................................................................................
    # For 8.4+ we don't want to inherit the padding
    catch {$path configure -padx 0 -pady 0}
    # widget informations
    set data(nrows) -1

    # items informations
    set data(items)    {}

    set data(selitems) {}

    # update informations
    set data(upd,level)   0
    set data(upd,afterid) ""
    set data(upd,level)   0
    set data(upd,delete)  {}
................................................................................

# ----------------------------------------------------------------------------
#  Command ListBox::see
# ----------------------------------------------------------------------------
proc ListBox::see { path item } {
    variable $path
    upvar 0  $path data







    if { [Widget::getoption $path -redraw] && $data(upd,afterid) != "" } {
        after cancel $data(upd,afterid)
        _redraw_listbox $path
    }
    set idn [$path.c find withtag n:$item]
    if { $idn != "" } {
        set idi [$path.c find withtag i:$item]
        if { $idi == "" } { set idi $idn }
        ListBox::_see $path $idn right
        ListBox::_see $path $idi left
    }

}


# ----------------------------------------------------------------------------
#  Command ListBox::edit
# ----------------------------------------------------------------------------
proc ListBox::edit { path item text {verifycmd ""} {clickres 0} {select 1}} {
................................................................................
        set x0  [expr {int([lindex $bbox 0]/$dx)}]
        if { $x0 < $xv0 } {
            $path.c xview scroll [expr {$x0-$xv0}] units
        }
    }
}
















# ----------------------------------------------------------------------------
#  Command ListBox::_update_scrollregion
# ----------------------------------------------------------------------------
proc ListBox::_update_scrollregion { path } {
    set bd   [$path.c cget -borderwidth]
    set ht   [$path.c cget -highlightthickness]
................................................................................
        set bbox [$path.c bbox "n:$item"]
        if { [llength $bbox] } {
            set imgbox [$path.c bbox i:$item]
            lassign $bbox x0 y0 x1 y1;
            if {[string compare "" $imgbox]} {
                # image may exist and may be higher than text!
                lassign $imgbox ix0 iy0 ix1 iy1;
                set bbox [list $x0 [expr {$iy0<$y0?$iy0:$y0}] $x1 [expr {$iy1>$y1?$iy1:$y1}]];
            } else {
                set bbox [list $x0 [lindex $bbox 1] $x1 [lindex $bbox 3]]
            }
	    if { $selfill && !$multi } {
		# With -selectfill, make box occupy full width of widget
		set bbox [list 0 [lindex $bbox 1] $width [lindex $bbox 3]]
	    }
................................................................................
            _redraw_items $path
        }
        _redraw_selection $path
        _update_scrollregion $path
        if {[Widget::cget $path -selectfill]} {
            _update_select_fill $path
        }



        set data(upd,level)   0
        set data(upd,afterid) ""

    }
}


# ----------------------------------------------------------------------------
#  Command ListBox::_redraw_idle
# ----------------------------------------------------------------------------






>







 







>







 







>
>
>
>
>
>





<
<
<
<
<
<
|
>







 







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







 







|







 







>
>
>


>







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
...
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754






755
756
757
758
759
760
761
762
763
...
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
....
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
....
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
#     - ListBox::see
#     - ListBox::edit
#     - ListBox::xview
#     - ListBox::yview
#     - ListBox::_update_edit_size
#     - ListBox::_destroy
#     - ListBox::_see
#     - ListBox::_see_item
#     - ListBox::_update_scrollregion
#     - ListBox::_draw_item
#     - ListBox::_redraw_items
#     - ListBox::_redraw_selection
#     - ListBox::_redraw_listbox
#     - ListBox::_redraw_idle
#     - ListBox::_resize
................................................................................
    # For 8.4+ we don't want to inherit the padding
    catch {$path configure -padx 0 -pady 0}
    # widget informations
    set data(nrows) -1

    # items informations
    set data(items)    {}
    set data(seeitem)  {}
    set data(selitems) {}

    # update informations
    set data(upd,level)   0
    set data(upd,afterid) ""
    set data(upd,level)   0
    set data(upd,delete)  {}
................................................................................

# ----------------------------------------------------------------------------
#  Command ListBox::see
# ----------------------------------------------------------------------------
proc ListBox::see { path item } {
    variable $path
    upvar 0  $path data

    if {$data(nrows) == -1} {
	# Not yet realized.
	set data(seeitem) $item
	return
    }

    if { [Widget::getoption $path -redraw] && $data(upd,afterid) != "" } {
        after cancel $data(upd,afterid)
        _redraw_listbox $path
    }







    _see_item $path $item;
}


# ----------------------------------------------------------------------------
#  Command ListBox::edit
# ----------------------------------------------------------------------------
proc ListBox::edit { path item text {verifycmd ""} {clickres 0} {select 1}} {
................................................................................
        set x0  [expr {int([lindex $bbox 0]/$dx)}]
        if { $x0 < $xv0 } {
            $path.c xview scroll [expr {$x0-$xv0}] units
        }
    }
}


# ----------------------------------------------------------------------------
#  Command ListBox::_see_item
# ----------------------------------------------------------------------------
proc ListBox::_see_item { path item } {
    set idn [$path.c find withtag n:$item]
    if { $idn != "" } {
        set idi [$path.c find withtag i:$item]
        if { $idi == "" } { set idi $idn }
        _see $path $idn right
        _see $path $idi left
    }
}


# ----------------------------------------------------------------------------
#  Command ListBox::_update_scrollregion
# ----------------------------------------------------------------------------
proc ListBox::_update_scrollregion { path } {
    set bd   [$path.c cget -borderwidth]
    set ht   [$path.c cget -highlightthickness]
................................................................................
        set bbox [$path.c bbox "n:$item"]
        if { [llength $bbox] } {
            set imgbox [$path.c bbox i:$item]
            lassign $bbox x0 y0 x1 y1;
            if {[string compare "" $imgbox]} {
                # image may exist and may be higher than text!
                lassign $imgbox ix0 iy0 ix1 iy1;
                set bbox [list $x0 [expr {$iy0<$y0?$iy0:$y0}] $x1 [expr {$iy1<$y1?$iy1:$y1}]];
            } else {
                set bbox [list $x0 [lindex $bbox 1] $x1 [lindex $bbox 3]]
            }
	    if { $selfill && !$multi } {
		# With -selectfill, make box occupy full width of widget
		set bbox [list 0 [lindex $bbox 1] $width [lindex $bbox 3]]
	    }
................................................................................
            _redraw_items $path
        }
        _redraw_selection $path
        _update_scrollregion $path
        if {[Widget::cget $path -selectfill]} {
            _update_select_fill $path
        }
	if {![string equal $data(seeitem) ""]} {
	    _see_item $path $data(seeitem);
	}
        set data(upd,level)   0
        set data(upd,afterid) ""
	set data(seeitem) "";
    }
}


# ----------------------------------------------------------------------------
#  Command ListBox::_redraw_idle
# ----------------------------------------------------------------------------