1 |
578 |
markom |
#
|
2 |
|
|
# Scrolledlistbox
|
3 |
|
|
# ----------------------------------------------------------------------
|
4 |
|
|
# Implements a scrolled listbox with additional options to manage
|
5 |
|
|
# horizontal and vertical scrollbars. This includes options to control
|
6 |
|
|
# which scrollbars are displayed and the method, i.e. statically,
|
7 |
|
|
# dynamically, or none at all.
|
8 |
|
|
#
|
9 |
|
|
# ----------------------------------------------------------------------
|
10 |
|
|
# AUTHOR: Mark L. Ulferts EMAIL: mulferts@austin.dsccc.com
|
11 |
|
|
#
|
12 |
|
|
# @(#) $Id: scrolledlistbox.itk,v 1.1.1.1 2002-01-16 10:24:50 markom Exp $
|
13 |
|
|
# ----------------------------------------------------------------------
|
14 |
|
|
# Copyright (c) 1995 DSC Technologies Corporation
|
15 |
|
|
# ======================================================================
|
16 |
|
|
# Permission to use, copy, modify, distribute and license this software
|
17 |
|
|
# and its documentation for any purpose, and without fee or written
|
18 |
|
|
# agreement with DSC, is hereby granted, provided that the above copyright
|
19 |
|
|
# notice appears in all copies and that both the copyright notice and
|
20 |
|
|
# warranty disclaimer below appear in supporting documentation, and that
|
21 |
|
|
# the names of DSC Technologies Corporation or DSC Communications
|
22 |
|
|
# Corporation not be used in advertising or publicity pertaining to the
|
23 |
|
|
# software without specific, written prior permission.
|
24 |
|
|
#
|
25 |
|
|
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
26 |
|
|
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
|
27 |
|
|
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
|
28 |
|
|
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
|
29 |
|
|
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
|
30 |
|
|
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
31 |
|
|
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
32 |
|
|
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
|
33 |
|
|
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
34 |
|
|
# SOFTWARE.
|
35 |
|
|
# ======================================================================
|
36 |
|
|
|
37 |
|
|
#
|
38 |
|
|
# Usual options.
|
39 |
|
|
#
|
40 |
|
|
itk::usual Scrolledlistbox {
|
41 |
|
|
keep -activebackground -activerelief -background -borderwidth -cursor \
|
42 |
|
|
-elementborderwidth -foreground -highlightcolor -highlightthickness \
|
43 |
|
|
-jump -labelfont -selectbackground -selectborderwidth \
|
44 |
|
|
-selectforeground -textbackground -textfont -troughcolor
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
# ------------------------------------------------------------------
|
48 |
|
|
# SCROLLEDLISTBOX
|
49 |
|
|
# ------------------------------------------------------------------
|
50 |
|
|
class iwidgets::Scrolledlistbox {
|
51 |
|
|
inherit iwidgets::Scrolledwidget
|
52 |
|
|
|
53 |
|
|
constructor {args} {}
|
54 |
|
|
destructor {}
|
55 |
|
|
|
56 |
|
|
itk_option define -dblclickcommand dblClickCommand Command {}
|
57 |
|
|
itk_option define -selectioncommand selectionCommand Command {}
|
58 |
|
|
itk_option define -width width Width 0
|
59 |
|
|
itk_option define -height height Height 0
|
60 |
|
|
itk_option define -visibleitems visibleItems VisibleItems 20x10
|
61 |
|
|
itk_option define -state state State normal
|
62 |
|
|
|
63 |
|
|
public method curselection {}
|
64 |
|
|
public method activate {index}
|
65 |
|
|
public method bbox {index}
|
66 |
|
|
public method clear {}
|
67 |
|
|
public method see {index}
|
68 |
|
|
public method index {index}
|
69 |
|
|
public method delete {first {last {}}}
|
70 |
|
|
public method get {first {last {}}}
|
71 |
|
|
public method getcurselection {}
|
72 |
|
|
public method insert {index string args}
|
73 |
|
|
public method nearest {y}
|
74 |
|
|
public method scan {option args}
|
75 |
|
|
public method selection {option first {last {}}}
|
76 |
|
|
public method size {}
|
77 |
|
|
public method selecteditemcount {}
|
78 |
|
|
public method justify {direction}
|
79 |
|
|
public method sort {{mode ascending}}
|
80 |
|
|
public method xview {args}
|
81 |
|
|
public method yview {args}
|
82 |
|
|
|
83 |
|
|
protected method _makeSelection {}
|
84 |
|
|
protected method _dblclick {}
|
85 |
|
|
protected method _fixIndex {index}
|
86 |
|
|
|
87 |
|
|
#
|
88 |
|
|
# List the event sequences that invoke single and double selection.
|
89 |
|
|
# Should these change in the underlying Tk listbox, then they must
|
90 |
|
|
# change here too.
|
91 |
|
|
#
|
92 |
|
|
common doubleSelectSeq { \
|
93 |
|
|
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
common singleSelectSeq { \
|
97 |
|
|
\
|
98 |
|
|
\
|
99 |
|
|
\
|
100 |
|
|
\
|
101 |
|
|
\
|
102 |
|
|
\
|
103 |
|
|
\
|
104 |
|
|
\
|
105 |
|
|
\
|
106 |
|
|
\
|
107 |
|
|
\
|
108 |
|
|
\
|
109 |
|
|
\
|
110 |
|
|
\
|
111 |
|
|
\
|
112 |
|
|
\
|
113 |
|
|
\
|
114 |
|
|
\
|
115 |
|
|
|
116 |
|
|
}
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
#
|
120 |
|
|
# Provide a lowercased access method for the Scrolledlistbox class.
|
121 |
|
|
#
|
122 |
|
|
proc ::iwidgets::scrolledlistbox {pathName args} {
|
123 |
|
|
uplevel ::iwidgets::Scrolledlistbox $pathName $args
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
#
|
127 |
|
|
# Use option database to override default resources of base classes.
|
128 |
|
|
#
|
129 |
|
|
option add *Scrolledlistbox.labelPos n widgetDefault
|
130 |
|
|
|
131 |
|
|
# ------------------------------------------------------------------
|
132 |
|
|
# CONSTRUCTOR
|
133 |
|
|
# ------------------------------------------------------------------
|
134 |
|
|
body iwidgets::Scrolledlistbox::constructor {args} {
|
135 |
|
|
#
|
136 |
|
|
# Our -width and -height options are slightly different than
|
137 |
|
|
# those implemented by our base class, so we're going to
|
138 |
|
|
# remove them and redefine our own.
|
139 |
|
|
#
|
140 |
|
|
itk_option remove iwidgets::Scrolledwidget::width
|
141 |
|
|
itk_option remove iwidgets::Scrolledwidget::height
|
142 |
|
|
|
143 |
|
|
#
|
144 |
|
|
# Create the listbox.
|
145 |
|
|
#
|
146 |
|
|
itk_component add listbox {
|
147 |
|
|
listbox $itk_interior.listbox \
|
148 |
|
|
-width 1 -height 1 \
|
149 |
|
|
-xscrollcommand \
|
150 |
|
|
[code $this _scrollWidget $itk_interior.horizsb] \
|
151 |
|
|
-yscrollcommand \
|
152 |
|
|
[code $this _scrollWidget $itk_interior.vertsb]
|
153 |
|
|
} {
|
154 |
|
|
usual
|
155 |
|
|
|
156 |
|
|
keep -borderwidth -exportselection -relief -selectmode
|
157 |
|
|
|
158 |
|
|
rename -font -textfont textFont Font
|
159 |
|
|
rename -background -textbackground textBackground Background
|
160 |
|
|
rename -highlightbackground -background background Background
|
161 |
|
|
}
|
162 |
|
|
grid $itk_component(listbox) -row 1 -column 1 -sticky nsew
|
163 |
|
|
grid rowconfigure $_interior 1 -weight 1
|
164 |
|
|
grid columnconfigure $_interior 1 -weight 1
|
165 |
|
|
|
166 |
|
|
#
|
167 |
|
|
# Configure the command on the vertical scroll bar in the base class.
|
168 |
|
|
#
|
169 |
|
|
$itk_component(vertsb) configure \
|
170 |
|
|
-command [code $itk_component(listbox) yview]
|
171 |
|
|
|
172 |
|
|
#
|
173 |
|
|
# Configure the command on the horizontal scroll bar in the base class.
|
174 |
|
|
#
|
175 |
|
|
$itk_component(horizsb) configure \
|
176 |
|
|
-command [code $itk_component(listbox) xview]
|
177 |
|
|
|
178 |
|
|
#
|
179 |
|
|
# Create a set of bindings for monitoring the selection and install
|
180 |
|
|
# them on the listbox component.
|
181 |
|
|
#
|
182 |
|
|
foreach seq $singleSelectSeq {
|
183 |
|
|
bind SLBSelect$this $seq [code $this _makeSelection]
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
foreach seq $doubleSelectSeq {
|
187 |
|
|
bind SLBSelect$this $seq [code $this _dblclick]
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
bindtags $itk_component(listbox) \
|
191 |
|
|
[linsert [bindtags $itk_component(listbox)] end SLBSelect$this]
|
192 |
|
|
|
193 |
|
|
#
|
194 |
|
|
# Also create a set of bindings for disabling the scrolledlistbox.
|
195 |
|
|
# Since the command for it is "break", we can drop the $this since
|
196 |
|
|
# they don't need to be unique to the object level.
|
197 |
|
|
#
|
198 |
|
|
if {[bind SLBDisabled] == {}} {
|
199 |
|
|
foreach seq $singleSelectSeq {
|
200 |
|
|
bind SLBDisabled $seq break
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
bind SLBDisabled break
|
204 |
|
|
|
205 |
|
|
foreach seq $doubleSelectSeq {
|
206 |
|
|
bind SLBDisabled $seq break
|
207 |
|
|
}
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
#
|
211 |
|
|
# Initialize the widget based on the command line options.
|
212 |
|
|
#
|
213 |
|
|
eval itk_initialize $args
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
# ------------------------------------------------------------------
|
217 |
|
|
# DESTURCTOR
|
218 |
|
|
# ------------------------------------------------------------------
|
219 |
|
|
body iwidgets::Scrolledlistbox::destructor {} {
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
# ------------------------------------------------------------------
|
223 |
|
|
# OPTIONS
|
224 |
|
|
# ------------------------------------------------------------------
|
225 |
|
|
|
226 |
|
|
# ------------------------------------------------------------------
|
227 |
|
|
# OPTION: -dblclickcommand
|
228 |
|
|
#
|
229 |
|
|
# Specify a command to be executed upon double click of a listbox
|
230 |
|
|
# item. Also, create a couple of bindings used for specific
|
231 |
|
|
# selection modes
|
232 |
|
|
# ------------------------------------------------------------------
|
233 |
|
|
configbody iwidgets::Scrolledlistbox::dblclickcommand {}
|
234 |
|
|
|
235 |
|
|
# ------------------------------------------------------------------
|
236 |
|
|
# OPTION: -selectioncommand
|
237 |
|
|
#
|
238 |
|
|
# Specifies a command to be executed upon selection of a listbox
|
239 |
|
|
# item. The command will be called upon each selection regardless
|
240 |
|
|
# of selection mode..
|
241 |
|
|
# ------------------------------------------------------------------
|
242 |
|
|
configbody iwidgets::Scrolledlistbox::selectioncommand {}
|
243 |
|
|
|
244 |
|
|
# ------------------------------------------------------------------
|
245 |
|
|
# OPTION: -width
|
246 |
|
|
#
|
247 |
|
|
# Specifies the width of the scrolled list box as an entire unit.
|
248 |
|
|
# The value may be specified in any of the forms acceptable to
|
249 |
|
|
# Tk_GetPixels. Any additional space needed to display the other
|
250 |
|
|
# components such as margins and scrollbars force the listbox
|
251 |
|
|
# to be compressed. A value of zero along with the same value for
|
252 |
|
|
# the height causes the value given for the visibleitems option
|
253 |
|
|
# to be applied which administers geometry constraints in a different
|
254 |
|
|
# manner.
|
255 |
|
|
# ------------------------------------------------------------------
|
256 |
|
|
configbody iwidgets::Scrolledlistbox::width {
|
257 |
|
|
if {$itk_option(-width) != 0} {
|
258 |
|
|
set shell [lindex [grid info $itk_component(listbox)] 1]
|
259 |
|
|
|
260 |
|
|
#
|
261 |
|
|
# Due to a bug in the tk4.2 grid, we have to check the
|
262 |
|
|
# propagation before setting it. Setting it to the same
|
263 |
|
|
# value it already is will cause it to toggle.
|
264 |
|
|
#
|
265 |
|
|
if {[grid propagate $shell]} {
|
266 |
|
|
grid propagate $shell no
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
$itk_component(listbox) configure -width 1
|
270 |
|
|
$shell configure \
|
271 |
|
|
-width [winfo pixels $shell $itk_option(-width)]
|
272 |
|
|
} else {
|
273 |
|
|
configure -visibleitems $itk_option(-visibleitems)
|
274 |
|
|
}
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
# ------------------------------------------------------------------
|
278 |
|
|
# OPTION: -height
|
279 |
|
|
#
|
280 |
|
|
# Specifies the height of the scrolled list box as an entire unit.
|
281 |
|
|
# The value may be specified in any of the forms acceptable to
|
282 |
|
|
# Tk_GetPixels. Any additional space needed to display the other
|
283 |
|
|
# components such as margins and scrollbars force the listbox
|
284 |
|
|
# to be compressed. A value of zero along with the same value for
|
285 |
|
|
# the width causes the value given for the visibleitems option
|
286 |
|
|
# to be applied which administers geometry constraints in a different
|
287 |
|
|
# manner.
|
288 |
|
|
# ------------------------------------------------------------------
|
289 |
|
|
configbody iwidgets::Scrolledlistbox::height {
|
290 |
|
|
if {$itk_option(-height) != 0} {
|
291 |
|
|
set shell [lindex [grid info $itk_component(listbox)] 1]
|
292 |
|
|
|
293 |
|
|
#
|
294 |
|
|
# Due to a bug in the tk4.2 grid, we have to check the
|
295 |
|
|
# propagation before setting it. Setting it to the same
|
296 |
|
|
# value it already is will cause it to toggle.
|
297 |
|
|
#
|
298 |
|
|
if {[grid propagate $shell]} {
|
299 |
|
|
grid propagate $shell no
|
300 |
|
|
}
|
301 |
|
|
|
302 |
|
|
$itk_component(listbox) configure -height 1
|
303 |
|
|
$shell configure \
|
304 |
|
|
-height [winfo pixels $shell $itk_option(-height)]
|
305 |
|
|
} else {
|
306 |
|
|
configure -visibleitems $itk_option(-visibleitems)
|
307 |
|
|
}
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
# ------------------------------------------------------------------
|
311 |
|
|
# OPTION: -visibleitems
|
312 |
|
|
#
|
313 |
|
|
# Specified the widthxheight in characters and lines for the listbox.
|
314 |
|
|
# This option is only administered if the width and height options
|
315 |
|
|
# are both set to zero, otherwise they take precedence. With the
|
316 |
|
|
# visibleitems option engaged, geometry constraints are maintained
|
317 |
|
|
# only on the listbox. The size of the other components such as
|
318 |
|
|
# labels, margins, and scrollbars, are additive and independent,
|
319 |
|
|
# effecting the overall size of the scrolled list box. In contrast,
|
320 |
|
|
# should the width and height options have non zero values, they
|
321 |
|
|
# are applied to the scrolled list box as a whole. The listbox
|
322 |
|
|
# is compressed or expanded to maintain the geometry constraints.
|
323 |
|
|
# ------------------------------------------------------------------
|
324 |
|
|
configbody iwidgets::Scrolledlistbox::visibleitems {
|
325 |
|
|
if {[regexp {^[0-9]+x[0-9]+$} $itk_option(-visibleitems)]} {
|
326 |
|
|
if {($itk_option(-width) == 0) && \
|
327 |
|
|
($itk_option(-height) == 0)} {
|
328 |
|
|
set chars [lindex [split $itk_option(-visibleitems) x] 0]
|
329 |
|
|
set lines [lindex [split $itk_option(-visibleitems) x] 1]
|
330 |
|
|
|
331 |
|
|
set shell [lindex [grid info $itk_component(listbox)] 1]
|
332 |
|
|
|
333 |
|
|
#
|
334 |
|
|
# Due to a bug in the tk4.2 grid, we have to check the
|
335 |
|
|
# propagation before setting it. Setting it to the same
|
336 |
|
|
# value it already is will cause it to toggle.
|
337 |
|
|
#
|
338 |
|
|
if {! [grid propagate $shell]} {
|
339 |
|
|
grid propagate $shell yes
|
340 |
|
|
}
|
341 |
|
|
|
342 |
|
|
$itk_component(listbox) configure -width $chars -height $lines
|
343 |
|
|
}
|
344 |
|
|
|
345 |
|
|
} else {
|
346 |
|
|
error "bad visibleitems option\
|
347 |
|
|
\"$itk_option(-visibleitems)\": should be\
|
348 |
|
|
widthxheight"
|
349 |
|
|
}
|
350 |
|
|
}
|
351 |
|
|
|
352 |
|
|
# ------------------------------------------------------------------
|
353 |
|
|
# OPTION: -state
|
354 |
|
|
#
|
355 |
|
|
# Specifies the state of the scrolledlistbox which may be either
|
356 |
|
|
# disabled or normal. In a disabled state, the scrolledlistbox
|
357 |
|
|
# does not accept user selection. The default is normal.
|
358 |
|
|
# ------------------------------------------------------------------
|
359 |
|
|
configbody iwidgets::Scrolledlistbox::state {
|
360 |
|
|
set tags [bindtags $itk_component(listbox)]
|
361 |
|
|
|
362 |
|
|
#
|
363 |
|
|
# If the state is normal, then we need to remove the disabled
|
364 |
|
|
# bindings if they exist. If the state is disabled, then we need
|
365 |
|
|
# to install the disabled bindings if they haven't been already.
|
366 |
|
|
#
|
367 |
|
|
switch -- $itk_option(-state) {
|
368 |
|
|
normal {
|
369 |
|
|
if {[set index [lsearch $tags SLBDisabled]] != -1} {
|
370 |
|
|
bindtags $itk_component(listbox) \
|
371 |
|
|
[lreplace $tags $index $index]
|
372 |
|
|
}
|
373 |
|
|
}
|
374 |
|
|
|
375 |
|
|
disabled {
|
376 |
|
|
if {[set index [lsearch $tags SLBDisabled]] == -1} {
|
377 |
|
|
bindtags $itk_component(listbox) \
|
378 |
|
|
[linsert $tags 1 SLBDisabled]
|
379 |
|
|
}
|
380 |
|
|
}
|
381 |
|
|
default {
|
382 |
|
|
error "bad state value \"$itk_option(-state)\":\
|
383 |
|
|
must be normal or disabled"
|
384 |
|
|
}
|
385 |
|
|
}
|
386 |
|
|
}
|
387 |
|
|
|
388 |
|
|
# ------------------------------------------------------------------
|
389 |
|
|
# METHODS
|
390 |
|
|
# ------------------------------------------------------------------
|
391 |
|
|
|
392 |
|
|
# ------------------------------------------------------------------
|
393 |
|
|
# METHOD: curselection
|
394 |
|
|
#
|
395 |
|
|
# Returns a list containing the indices of all the elements in the
|
396 |
|
|
# listbox that are currently selected.
|
397 |
|
|
# ------------------------------------------------------------------
|
398 |
|
|
body iwidgets::Scrolledlistbox::curselection {} {
|
399 |
|
|
return [$itk_component(listbox) curselection]
|
400 |
|
|
}
|
401 |
|
|
|
402 |
|
|
# ------------------------------------------------------------------
|
403 |
|
|
# METHOD: activate index
|
404 |
|
|
#
|
405 |
|
|
# Sets the active element to the one indicated by index.
|
406 |
|
|
# ------------------------------------------------------------------
|
407 |
|
|
body iwidgets::Scrolledlistbox::activate {index} {
|
408 |
|
|
return [$itk_component(listbox) activate [_fixIndex $index]]
|
409 |
|
|
}
|
410 |
|
|
|
411 |
|
|
# ------------------------------------------------------------------
|
412 |
|
|
# METHOD: bbox index
|
413 |
|
|
#
|
414 |
|
|
# Returns four element list describing the bounding box for the list
|
415 |
|
|
# item at index
|
416 |
|
|
# ------------------------------------------------------------------
|
417 |
|
|
body iwidgets::Scrolledlistbox::bbox {index} {
|
418 |
|
|
return [$itk_component(listbox) bbox [_fixIndex $index]]
|
419 |
|
|
}
|
420 |
|
|
|
421 |
|
|
# ------------------------------------------------------------------
|
422 |
|
|
# METHOD clear
|
423 |
|
|
#
|
424 |
|
|
# Clear the listbox area of all items.
|
425 |
|
|
# ------------------------------------------------------------------
|
426 |
|
|
body iwidgets::Scrolledlistbox::clear {} {
|
427 |
|
|
delete 0 end
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
# ------------------------------------------------------------------
|
431 |
|
|
# METHOD: see index
|
432 |
|
|
#
|
433 |
|
|
# Adjusts the view such that the element given by index is visible.
|
434 |
|
|
# ------------------------------------------------------------------
|
435 |
|
|
body iwidgets::Scrolledlistbox::see {index} {
|
436 |
|
|
$itk_component(listbox) see [_fixIndex $index]
|
437 |
|
|
}
|
438 |
|
|
|
439 |
|
|
# ------------------------------------------------------------------
|
440 |
|
|
# METHOD: index index
|
441 |
|
|
#
|
442 |
|
|
# Returns the decimal string giving the integer index corresponding
|
443 |
|
|
# to index. The index value may be a integer number, active,
|
444 |
|
|
# anchor, end, @x,y, or a pattern.
|
445 |
|
|
# ------------------------------------------------------------------
|
446 |
|
|
body iwidgets::Scrolledlistbox::index {index} {
|
447 |
|
|
if {[regexp {(^[0-9]+$)|(active)|(anchor)|(end)|(^@-?[0-9]+,-?[0-9]+$)} $index]} {
|
448 |
|
|
return [$itk_component(listbox) index $index]
|
449 |
|
|
|
450 |
|
|
} else {
|
451 |
|
|
set indexValue [lsearch -glob [get 0 end] $index]
|
452 |
|
|
|
453 |
|
|
if {$indexValue == -1} {
|
454 |
|
|
error "bad Scrolledlistbox index \"$index\": must be active, anchor, end, @x,y, number, or a pattern"
|
455 |
|
|
}
|
456 |
|
|
|
457 |
|
|
return $indexValue
|
458 |
|
|
}
|
459 |
|
|
}
|
460 |
|
|
|
461 |
|
|
# ------------------------------------------------------------------
|
462 |
|
|
# METHOD: _fixIndex index
|
463 |
|
|
#
|
464 |
|
|
# Similar to the regular "index" method, but it only converts
|
465 |
|
|
# the index to a numerical value if it is a string pattern. If
|
466 |
|
|
# the index is in the proper form to be used with the listbox,
|
467 |
|
|
# it is left alone. This fixes problems associated with converting
|
468 |
|
|
# an index such as "end" to a numerical value.
|
469 |
|
|
# ------------------------------------------------------------------
|
470 |
|
|
body iwidgets::Scrolledlistbox::_fixIndex {index} {
|
471 |
|
|
if {[regexp {(^[0-9]+$)|(active)|(anchor)|(end)|(^@[0-9]+,[0-9]+$)} $index]} {
|
472 |
|
|
return $index
|
473 |
|
|
|
474 |
|
|
} else {
|
475 |
|
|
set indexValue [lsearch -glob [get 0 end] $index]
|
476 |
|
|
|
477 |
|
|
if {$indexValue == -1} {
|
478 |
|
|
error "bad Scrolledlistbox index \"$index\": must be active, anchor, end, @x,y, number, or a pattern"
|
479 |
|
|
}
|
480 |
|
|
|
481 |
|
|
return $indexValue
|
482 |
|
|
}
|
483 |
|
|
}
|
484 |
|
|
|
485 |
|
|
# ------------------------------------------------------------------
|
486 |
|
|
# METHOD: delete first ?last?
|
487 |
|
|
#
|
488 |
|
|
# Delete one or more elements from list box based on the first and
|
489 |
|
|
# last index values. Indexes may be a number, active, anchor, end,
|
490 |
|
|
# @x,y, or a pattern.
|
491 |
|
|
# ------------------------------------------------------------------
|
492 |
|
|
body iwidgets::Scrolledlistbox::delete {first {last {}}} {
|
493 |
|
|
set first [_fixIndex $first]
|
494 |
|
|
|
495 |
|
|
if {$last != {}} {
|
496 |
|
|
set last [_fixIndex $last]
|
497 |
|
|
} else {
|
498 |
|
|
set last $first
|
499 |
|
|
}
|
500 |
|
|
|
501 |
|
|
eval $itk_component(listbox) delete $first $last
|
502 |
|
|
}
|
503 |
|
|
|
504 |
|
|
# ------------------------------------------------------------------
|
505 |
|
|
# METHOD: get first ?last?
|
506 |
|
|
#
|
507 |
|
|
# Returns the elements of the listbox indicated by the indexes.
|
508 |
|
|
# Indexes may be a number, active, anchor, end, @x,y, ora pattern.
|
509 |
|
|
# ------------------------------------------------------------------
|
510 |
|
|
body iwidgets::Scrolledlistbox::get {first {last {}}} {
|
511 |
|
|
set first [_fixIndex $first]
|
512 |
|
|
|
513 |
|
|
if {$last != {}} {
|
514 |
|
|
set last [_fixIndex $last]
|
515 |
|
|
}
|
516 |
|
|
|
517 |
|
|
if {$last == {}} {
|
518 |
|
|
return [$itk_component(listbox) get $first]
|
519 |
|
|
} else {
|
520 |
|
|
return [$itk_component(listbox) get $first $last]
|
521 |
|
|
}
|
522 |
|
|
}
|
523 |
|
|
|
524 |
|
|
# ------------------------------------------------------------------
|
525 |
|
|
# METHOD: getcurselection
|
526 |
|
|
#
|
527 |
|
|
# Returns the contents of the listbox element indicated by the current
|
528 |
|
|
# selection indexes. Short cut version of get and curselection
|
529 |
|
|
# command combination.
|
530 |
|
|
# ------------------------------------------------------------------
|
531 |
|
|
body iwidgets::Scrolledlistbox::getcurselection {} {
|
532 |
|
|
set rlist {}
|
533 |
|
|
|
534 |
|
|
if {[selecteditemcount] > 0} {
|
535 |
|
|
set cursels [$itk_component(listbox) curselection]
|
536 |
|
|
|
537 |
|
|
switch $itk_option(-selectmode) {
|
538 |
|
|
single -
|
539 |
|
|
browse {
|
540 |
|
|
set rlist [$itk_component(listbox) get $cursels]
|
541 |
|
|
}
|
542 |
|
|
|
543 |
|
|
multiple -
|
544 |
|
|
extended {
|
545 |
|
|
foreach sel $cursels {
|
546 |
|
|
lappend rlist [$itk_component(listbox) get $sel]
|
547 |
|
|
}
|
548 |
|
|
}
|
549 |
|
|
}
|
550 |
|
|
}
|
551 |
|
|
|
552 |
|
|
return $rlist
|
553 |
|
|
}
|
554 |
|
|
|
555 |
|
|
# ------------------------------------------------------------------
|
556 |
|
|
# METHOD: insert index string ?string ...?
|
557 |
|
|
#
|
558 |
|
|
# Insert zero or more elements in the list just before the element
|
559 |
|
|
# given by index.
|
560 |
|
|
# ------------------------------------------------------------------
|
561 |
|
|
body iwidgets::Scrolledlistbox::insert {index string args} {
|
562 |
|
|
set index [_fixIndex $index]
|
563 |
|
|
set args [linsert $args 0 $string]
|
564 |
|
|
|
565 |
|
|
eval $itk_component(listbox) insert $index $args
|
566 |
|
|
}
|
567 |
|
|
|
568 |
|
|
# ------------------------------------------------------------------
|
569 |
|
|
# METHOD: nearest y
|
570 |
|
|
#
|
571 |
|
|
# Given a y-coordinate within the listbox, this command returns the
|
572 |
|
|
# index of the visible listbox element nearest to that y-coordinate.
|
573 |
|
|
# ------------------------------------------------------------------
|
574 |
|
|
body iwidgets::Scrolledlistbox::nearest {y} {
|
575 |
|
|
$itk_component(listbox) nearest $y
|
576 |
|
|
}
|
577 |
|
|
|
578 |
|
|
# ------------------------------------------------------------------
|
579 |
|
|
# METHOD: scan option args
|
580 |
|
|
#
|
581 |
|
|
# Implements scanning on listboxes.
|
582 |
|
|
# ------------------------------------------------------------------
|
583 |
|
|
body iwidgets::Scrolledlistbox::scan {option args} {
|
584 |
|
|
eval $itk_component(listbox) scan $option $args
|
585 |
|
|
}
|
586 |
|
|
|
587 |
|
|
# ------------------------------------------------------------------
|
588 |
|
|
# METHOD: selection option first ?last?
|
589 |
|
|
#
|
590 |
|
|
# Adjusts the selection within the listbox. The index value may be
|
591 |
|
|
# a integer number, active, anchor, end, @x,y, or a pattern.
|
592 |
|
|
# ------------------------------------------------------------------
|
593 |
|
|
body iwidgets::Scrolledlistbox::selection {option first {last {}}} {
|
594 |
|
|
set first [_fixIndex $first]
|
595 |
|
|
|
596 |
|
|
if {$last != {}} {
|
597 |
|
|
set last [_fixIndex $last]
|
598 |
|
|
$itk_component(listbox) selection $option $first $last
|
599 |
|
|
} else {
|
600 |
|
|
$itk_component(listbox) selection $option $first
|
601 |
|
|
}
|
602 |
|
|
}
|
603 |
|
|
|
604 |
|
|
# ------------------------------------------------------------------
|
605 |
|
|
# METHOD: size
|
606 |
|
|
#
|
607 |
|
|
# Returns a decimal string indicating the total number of elements
|
608 |
|
|
# in the listbox.
|
609 |
|
|
# ------------------------------------------------------------------
|
610 |
|
|
body iwidgets::Scrolledlistbox::size {} {
|
611 |
|
|
return [$itk_component(listbox) size]
|
612 |
|
|
}
|
613 |
|
|
|
614 |
|
|
# ------------------------------------------------------------------
|
615 |
|
|
# METHOD: selecteditemcount
|
616 |
|
|
#
|
617 |
|
|
# Returns a decimal string indicating the total number of selected
|
618 |
|
|
# elements in the listbox.
|
619 |
|
|
# ------------------------------------------------------------------
|
620 |
|
|
body iwidgets::Scrolledlistbox::selecteditemcount {} {
|
621 |
|
|
return [llength [$itk_component(listbox) curselection]]
|
622 |
|
|
}
|
623 |
|
|
|
624 |
|
|
# ------------------------------------------------------------------
|
625 |
|
|
# METHOD: justify direction
|
626 |
|
|
#
|
627 |
|
|
# Justifies the list scrolled region in one of four directions: top,
|
628 |
|
|
# bottom, left, or right.
|
629 |
|
|
# ------------------------------------------------------------------
|
630 |
|
|
body iwidgets::Scrolledlistbox::justify {direction} {
|
631 |
|
|
switch $direction {
|
632 |
|
|
left {
|
633 |
|
|
$itk_component(listbox) xview moveto 0
|
634 |
|
|
}
|
635 |
|
|
right {
|
636 |
|
|
$itk_component(listbox) xview moveto 1
|
637 |
|
|
}
|
638 |
|
|
top {
|
639 |
|
|
$itk_component(listbox) yview moveto 0
|
640 |
|
|
}
|
641 |
|
|
bottom {
|
642 |
|
|
$itk_component(listbox) yview moveto 1
|
643 |
|
|
}
|
644 |
|
|
default {
|
645 |
|
|
error "bad justify argument \"$direction\": should\
|
646 |
|
|
be left, right, top, or bottom"
|
647 |
|
|
}
|
648 |
|
|
}
|
649 |
|
|
}
|
650 |
|
|
|
651 |
|
|
# ------------------------------------------------------------------
|
652 |
|
|
# METHOD: sort mode
|
653 |
|
|
#
|
654 |
|
|
# Sort the current list in either "ascending/increasing" or
|
655 |
|
|
# "descending/decreasing" order.
|
656 |
|
|
# ------------------------------------------------------------------
|
657 |
|
|
body iwidgets::Scrolledlistbox::sort {{mode ascending}} {
|
658 |
|
|
switch $mode {
|
659 |
|
|
ascending -
|
660 |
|
|
increasing {
|
661 |
|
|
set vals [$itk_component(listbox) get 0 end]
|
662 |
|
|
if {[llength $vals] != 0} {
|
663 |
|
|
$itk_component(listbox) delete 0 end
|
664 |
|
|
eval $itk_component(listbox) insert end \
|
665 |
|
|
[lsort -increasing $vals]
|
666 |
|
|
}
|
667 |
|
|
}
|
668 |
|
|
descending -
|
669 |
|
|
decreasing {
|
670 |
|
|
set vals [$itk_component(listbox) get 0 end]
|
671 |
|
|
if {[llength $vals] != 0} {
|
672 |
|
|
$itk_component(listbox) delete 0 end
|
673 |
|
|
eval $itk_component(listbox) insert end \
|
674 |
|
|
[lsort -decreasing $vals]
|
675 |
|
|
}
|
676 |
|
|
}
|
677 |
|
|
default {
|
678 |
|
|
error "bad sort argument \"$mode\": should be\
|
679 |
|
|
ascending, descending, increasing, or decreasing"
|
680 |
|
|
}
|
681 |
|
|
}
|
682 |
|
|
}
|
683 |
|
|
|
684 |
|
|
# ------------------------------------------------------------------
|
685 |
|
|
# METHOD: xview args
|
686 |
|
|
#
|
687 |
|
|
# Change or query the vertical position of the text in the list box.
|
688 |
|
|
# ------------------------------------------------------------------
|
689 |
|
|
body iwidgets::Scrolledlistbox::xview {args} {
|
690 |
|
|
return [eval $itk_component(listbox) xview $args]
|
691 |
|
|
}
|
692 |
|
|
|
693 |
|
|
# ------------------------------------------------------------------
|
694 |
|
|
# METHOD: yview args
|
695 |
|
|
#
|
696 |
|
|
# Change or query the horizontal position of the text in the list box.
|
697 |
|
|
# ------------------------------------------------------------------
|
698 |
|
|
body iwidgets::Scrolledlistbox::yview {args} {
|
699 |
|
|
return [eval $itk_component(listbox) yview $args]
|
700 |
|
|
}
|
701 |
|
|
|
702 |
|
|
# ------------------------------------------------------------------
|
703 |
|
|
# PROTECTED METHOD: _makeSelection
|
704 |
|
|
#
|
705 |
|
|
# Evaluate the selection command.
|
706 |
|
|
# ------------------------------------------------------------------
|
707 |
|
|
body iwidgets::Scrolledlistbox::_makeSelection {} {
|
708 |
|
|
uplevel #0 $itk_option(-selectioncommand)
|
709 |
|
|
}
|
710 |
|
|
|
711 |
|
|
# ------------------------------------------------------------------
|
712 |
|
|
# PROTECTED METHOD: _dblclick
|
713 |
|
|
#
|
714 |
|
|
# Evaluate the double click command option if not empty.
|
715 |
|
|
# ------------------------------------------------------------------
|
716 |
|
|
body iwidgets::Scrolledlistbox::_dblclick {} {
|
717 |
|
|
uplevel #0 $itk_option(-dblclickcommand)
|
718 |
|
|
}
|
719 |
|
|
|