Bwidget Source Code
Check-in [347d417b33]
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:Added support for keyboard traversal. The widget will now tab in even when it is not editible. Also the entry widget content will be selected when the user tabs in. The key bindings now allow a traversal of the list (<Down> brings up the list). The arrow button no longer switches to an up button, but instead changes relief. The button is now more Windows NT like (for Windows NT).
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 347d417b33670b07876896b954f37f28e1cc756a
User & Date: sven 1999-10-21 17:41:37
Context
1999-10-22
00:09
* tree.tcl: Added a -selectable option to tree nodes, which controls whether or not a given node is selectable (duh). This works with the new -selectcommand option for the tree, and with keyboard traversal (also new). Now, whenever the tree gets a "selection set", it calls the given -selectcommand with the name of the tree and the list of selected nodes, which makes it easier to just drop in place and use. check-in: 3f7df86982 user: ericm tags: trunk
1999-10-21
17:41
Added support for keyboard traversal. The widget will now tab in even when it is not editible. Also the entry widget content will be selected when the user tabs in. The key bindings now allow a traversal of the list (<Down> brings up the list). The arrow button no longer switches to an up button, but instead changes relief. The button is now more Windows NT like (for Windows NT). check-in: 347d417b33 user: sven tags: trunk
1999-10-20
22:15
* panedw.tcl: Added a -class PanedWindow option to the main frame (the megawidget) of the paned window. check-in: cf9a0e7e76 user: ericm tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to combobox.tcl.

1
2
3
4
5
6
7
8
9
10
11
..
53
54
55
56
57
58
59


60
61
62
63
64
65
66
67
68
69
70


71


72




73
74
75
76
77
78

79
80

81
82
83
84
85
86
87
88

89
90

91
92
93
94
95


96
97
98
99
100
101
102
103
104
105
...
114
115
116
117
118
119
120

121
122

123
124
125
126
127
128
129
...
275
276
277
278
279
280
281
282


283
284
285
286
287
288
289
290
291

292
293
294
295


296
297

298
299
300

301
302
303
304
305
306
307
308

309
310
311
312
313
314
315
316
317
...
334
335
336
337
338
339
340















































# ------------------------------------------------------------------------------
#  combobox.tcl
#  This file is part of Unifix BWidget Toolkit
#  $Id: combobox.tcl,v 1.1.1.1 1999/08/03 20:20:23 ericm Exp $
# ------------------------------------------------------------------------------
#  Index of commands:
#     - ComboBox::create
#     - ComboBox::configure
#     - ComboBox::cget
#     - ComboBox::setvalue
#     - ComboBox::getvalue
................................................................................
}


# ------------------------------------------------------------------------------
#  Command ComboBox::create
# ------------------------------------------------------------------------------
proc ComboBox::create { path args } {


    Widget::init ComboBox $path $args

    frame $path -background [Widget::getoption $path -background] \
        -highlightthickness 0 -bd 0 -relief flat -takefocus 0

    bindtags $path [list $path BwComboBox [winfo toplevel $path] all]

    set labf  [eval LabelFrame::create $path.labf [Widget::subcget $path .labf] \
                   -focus $path.e]
    set entry [eval Entry::create $path.e [Widget::subcget $path .e] \
                   -relief flat -borderwidth 0]





    set width  11




    set height [winfo reqheight $entry]
    set arrow [eval ArrowButton::create $path.a [Widget::subcget $path .a] \
                   -width $width -height $height \
                   -highlightthickness 0 -borderwidth 1 -takefocus 0 \
                   -dir   bottom \
                   -type  button \

                   -command [list "ComboBox::_mapliste $path"]]


    set frame [LabelFrame::getframe $labf]

    pack $arrow -in $frame -side right -fill y
    pack $entry -in $frame -side left  -fill both -expand yes
    pack $labf  -fill x -expand yes

    if { [Widget::getoption $path -editable] == 0 } {
        ::bind $entry <ButtonPress-1> "ArrowButton::invoke $path.a"

    } else {
        ::bind $entry <ButtonPress-1> "ComboBox::_unmapliste $path"

    }

    ::bind $path  <ButtonPress-1> "ComboBox::_unmapliste $path"
    ::bind $entry <Key-Up>        "ComboBox::_modify_value $path previous"
    ::bind $entry <Key-Down>      "ComboBox::_modify_value $path next"


    ::bind $entry <Key-Prior>     "ComboBox::_modify_value $path first"
    ::bind $entry <Key-Next>      "ComboBox::_modify_value $path last"

    rename $path ::$path:cmd
    proc ::$path { cmd args } "return \[eval ComboBox::\$cmd $path \$args\]"

    return $path
}


................................................................................
         [Widget::hasChanged $path -font f] } {
        destroy $path.shell.listb
    }

    if { [Widget::hasChanged $path -editable ed] } {
        if { $ed } {
            ::bind $path.e <ButtonPress-1> "ComboBox::_unmapliste $path"

        } else {
            ::bind $path.e <ButtonPress-1> "ArrowButton::invoke $path.a"

        }
    }

    return $res
}


................................................................................
        uplevel \#0 $cmd
    }
    if { ![llength [Widget::getoption $path -values]] } {
        return
    }
    _create_popup $path

    ArrowButton::configure $path.a -dir top


    $listb selection clear 0 end
    set values [$listb get 0 end]
    set curval [Entry::cget $path.e -text]
    if { [set idx [lsearch $values $curval]] != -1 ||
         [set idx [lsearch $values "$curval*"]] != -1 } {
        $listb selection set $idx
        $listb activate $idx
        $listb see $idx
    } else {

        $listb activate 0
        $listb see 0
    }



    set frame [LabelFrame::getframe $path.labf]
    BWidget::place $path.shell [winfo width $frame] 0 below $frame

    wm deiconify $path.shell
    raise $path.shell
    BWidget::grab global $path

}


# ------------------------------------------------------------------------------
#  Command ComboBox::_unmapliste
# ------------------------------------------------------------------------------
proc ComboBox::_unmapliste { path } {
    BWidget::grab release $path

    destroy $path.shell
    ArrowButton::configure $path.a -dir bottom
}


# ------------------------------------------------------------------------------
#  Command ComboBox::_select
# ------------------------------------------------------------------------------
proc ComboBox::_select { path index } {
................................................................................
proc ComboBox::_modify_value { path direction } {
    if { [setvalue $path $direction] } {
        if { [set cmd [Widget::getoption $path -modifycmd]] != "" } {
            uplevel \#0 $cmd
        }
    }
}

















































|







 







>
>










|
>
>
|
>
>
|
>
>
>
>






>

|
>






|
|
>

|
>



|
|
>
>
|
|
|







 







>


>







 







|
>
>









>




>
>


>



>








>

<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
..
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
...
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# ------------------------------------------------------------------------------
#  combobox.tcl
#  This file is part of Unifix BWidget Toolkit
#  $Id: combobox.tcl,v 1.2 1999/10/21 17:41:37 sven Exp $
# ------------------------------------------------------------------------------
#  Index of commands:
#     - ComboBox::create
#     - ComboBox::configure
#     - ComboBox::cget
#     - ComboBox::setvalue
#     - ComboBox::getvalue
................................................................................
}


# ------------------------------------------------------------------------------
#  Command ComboBox::create
# ------------------------------------------------------------------------------
proc ComboBox::create { path args } {
    global tcl_platform
    
    Widget::init ComboBox $path $args

    frame $path -background [Widget::getoption $path -background] \
        -highlightthickness 0 -bd 0 -relief flat -takefocus 0

    bindtags $path [list $path BwComboBox [winfo toplevel $path] all]

    set labf  [eval LabelFrame::create $path.labf [Widget::subcget $path .labf] \
                   -focus $path.e]
    set entry [eval Entry::create $path.e [Widget::subcget $path .e] \
                   -relief flat -borderwidth 0 -takefocus 1]
    ::bind $path.e <FocusIn> "$path _focus_in"
    ::bind $path.e <FocusOut> "$path _focus_out"
    
    if {![string compare $tcl_platform(platform) "unix"]} {
        set ipadx 0
        set width  11
    } else {
        set ipadx 2
        set width  15
    }
    set height [winfo reqheight $entry]
    set arrow [eval ArrowButton::create $path.a [Widget::subcget $path .a] \
                   -width $width -height $height \
                   -highlightthickness 0 -borderwidth 1 -takefocus 0 \
                   -dir   bottom \
                   -type  button \
                   -ipadx $ipadx \
                   -command [list "ComboBox::_mapliste $path"]]
    
    
    set frame [LabelFrame::getframe $labf]

    pack $arrow -in $frame -side right -fill y
    pack $entry -in $frame -side left  -fill both -expand yes
    pack $labf  -fill x -expand yes

    if { [Widget::getoption $path -editable] != 0 } {
        ::bind $entry <ButtonPress-1> "ComboBox::_unmapliste $path"
        $path.e config -state normal
    } else {
        ::bind $entry <ButtonPress-1> "ArrowButton::invoke $path.a"
        $path.e config -state disabled
    }

    ::bind $path  <ButtonPress-1> "ComboBox::_unmapliste $path"
    ::bind $entry <Key-Up>        "ComboBox::_unmapliste $path"
    ::bind $entry <Key-Down>      "ComboBox::_mapliste $path"
    ::bind $entry <Control-Up>    "ComboBox::_modify_value $path previous"
    ::bind $entry <Control-Down>  "ComboBox::_modify_value $path next"
    ::bind $entry <Control-Prior> "ComboBox::_modify_value $path first"
    ::bind $entry <Control-Next>  "ComboBox::_modify_value $path last"
    
    rename $path ::$path:cmd
    proc ::$path { cmd args } "return \[eval ComboBox::\$cmd $path \$args\]"

    return $path
}


................................................................................
         [Widget::hasChanged $path -font f] } {
        destroy $path.shell.listb
    }

    if { [Widget::hasChanged $path -editable ed] } {
        if { $ed } {
            ::bind $path.e <ButtonPress-1> "ComboBox::_unmapliste $path"
            $path.e config -state normal
        } else {
            ::bind $path.e <ButtonPress-1> "ArrowButton::invoke $path.a"
            $path.e config -state disabled
        }
    }

    return $res
}


................................................................................
        uplevel \#0 $cmd
    }
    if { ![llength [Widget::getoption $path -values]] } {
        return
    }
    _create_popup $path

    ArrowButton::configure $path.a -relief sunken
    update
    
    $listb selection clear 0 end
    set values [$listb get 0 end]
    set curval [Entry::cget $path.e -text]
    if { [set idx [lsearch $values $curval]] != -1 ||
         [set idx [lsearch $values "$curval*"]] != -1 } {
        $listb selection set $idx
        $listb activate $idx
        $listb see $idx
    } else {
        $listb selection set 0
        $listb activate 0
        $listb see 0
    }

    ::bind $listb <Escape> "ComboBox::_unmapliste $path; break"
    
    set frame [LabelFrame::getframe $path.labf]
    BWidget::place $path.shell [winfo width $frame] 0 below $frame
    focus -force $listb
    wm deiconify $path.shell
    raise $path.shell
    BWidget::grab global $path
    ArrowButton::configure $path.a -relief raised
}


# ------------------------------------------------------------------------------
#  Command ComboBox::_unmapliste
# ------------------------------------------------------------------------------
proc ComboBox::_unmapliste { path } {
    BWidget::grab release $path
    focus -force $path.e
    destroy $path.shell

}


# ------------------------------------------------------------------------------
#  Command ComboBox::_select
# ------------------------------------------------------------------------------
proc ComboBox::_select { path index } {
................................................................................
proc ComboBox::_modify_value { path direction } {
    if { [setvalue $path $direction] } {
        if { [set cmd [Widget::getoption $path -modifycmd]] != "" } {
            uplevel \#0 $cmd
        }
    }
}


# ------------------------------------------------------------------------------
#  Command ComboBox::_focus_in
# ------------------------------------------------------------------------------
proc ComboBox::_focus_in { path } {
    variable background
    variable foreground

    if { [Widget::getoption $path -editable] == 0 } {
        set value  [Entry::cget $path.e -text]
        if {[string equal $value ""]} {
            # If the entry is empty, we need to do some magic to
            # make it "selected"
            if {[$path.e cget -bg] != [$path.e cget -selectbackground]} {
                # Copy only if we know that this is not the selection
                # background color (by accident... focus out without
                # focus in etc.
                set background [$path.e cget -bg]
                set foreground [$path.e cget -fg]
            }
            $path.e configure -bg [$path.e cget -selectbackground]
            $path.e configure -fg [$path.e cget -selectforeground]
        }
    }
    $path.e selection clear
    $path.e selection range 0 end
}


# ------------------------------------------------------------------------------
#  Command ComboBox::_focus_out
# ------------------------------------------------------------------------------
proc ComboBox::_focus_out { path } {
    variable background
    variable foreground

    if { [Widget::getoption $path -editable] == 0 } {
        if {[info exists background]} {
            $path.e configure -bg $background
            $path.e configure -fg $foreground
            unset background
            unset foreground
        }
    }
    $path.e selection clear
}