Bwidget Source Code
Check-in [f3ebbcbe31]
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:* buttonbox.tcl: Added tagging mechanism to buttonbox. When using $bbox add, the first parameter is a list of tags for the button. Then use $bbox setbuttonstate to change the state of a tag.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f3ebbcbe31e5b48322d9d46931b9e591ac21236c
User & Date: ericm 1999-09-17 20:50:22
Context
1999-09-17
22:30
Updated to reflect recent TEA changes check-in: 2911677e6b user: wart tags: trunk
20:50
* buttonbox.tcl: Added tagging mechanism to buttonbox. When using $bbox add, the first parameter is a list of tags for the button. Then use $bbox setbuttonstate to change the state of a tag. check-in: f3ebbcbe31 user: ericm tags: trunk
17:46
* mainframe.tcl: Modified menu creation/setmenustate functions to support a new model of menustate. Instead of enabling/disabling a menu item whenever any one of its tags changes state, now it only enables menu items if all of its tags are set. This makes it really easy to, say, only enable the "New Action" entry if both a project is open and an element is selected. check-in: 0406abeac2 user: ericm tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to buttonbox.tcl.

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
117
118
119
120
121
122
123










124
125
126
127
128
129
130
...
148
149
150
151
152
153
154



































155
156
157
158
159
160
161
    return [Widget::cget $path $option]
}


# ------------------------------------------------------------------------------
#  Command ButtonBox::add
# ------------------------------------------------------------------------------
proc ButtonBox::add { path args } {
    variable $path
    upvar 0  $path data

    set but     $path.b$data(nbuttons)
    set spacing [Widget::getoption $path -spacing]

    if { $data(nbuttons) == $data(default) } {
................................................................................

    eval Button::create $but \
        -background [Widget::getoption $path -background]\
        -padx       [Widget::getoption $path -padx] \
        -pady       [Widget::getoption $path -pady] \
        $args \
        -default $style











    set idx [expr {2*$data(nbuttons)}]
    if { ![string compare [Widget::getoption $path -orient] "horizontal"] } {
        grid $but -column $idx -row 0 -sticky nsew
        if { [Widget::getoption $path -homogeneous] } {
            set req [winfo reqwidth $but]
            if { $req > $data(max) } {
................................................................................
        }
    }

    incr data(nbuttons)

    return $but
}





































# ------------------------------------------------------------------------------
#  Command ButtonBox::itemconfigure
# ------------------------------------------------------------------------------
proc ButtonBox::itemconfigure { path index args } {
    if { [set idx [lsearch $args -default]] != -1 } {






|







 







>
>
>
>
>
>
>
>
>
>







 







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







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
    return [Widget::cget $path $option]
}


# ------------------------------------------------------------------------------
#  Command ButtonBox::add
# ------------------------------------------------------------------------------
proc ButtonBox::add { path tags args } {
    variable $path
    upvar 0  $path data

    set but     $path.b$data(nbuttons)
    set spacing [Widget::getoption $path -spacing]

    if { $data(nbuttons) == $data(default) } {
................................................................................

    eval Button::create $but \
        -background [Widget::getoption $path -background]\
        -padx       [Widget::getoption $path -padx] \
        -pady       [Widget::getoption $path -pady] \
        $args \
        -default $style

    # [email protected]:  set up tags, just like the menu items
    foreach tag $tags {
	lappend data(tags,$tag) $but
	if { ![info exists data(tagstate,$tag)] } {
	    set data(tagstate,$tag) 0
	}
    }
    set data(buttontags,$but) $tags
    # [email protected]

    set idx [expr {2*$data(nbuttons)}]
    if { ![string compare [Widget::getoption $path -orient] "horizontal"] } {
        grid $but -column $idx -row 0 -sticky nsew
        if { [Widget::getoption $path -homogeneous] } {
            set req [winfo reqwidth $but]
            if { $req > $data(max) } {
................................................................................
        }
    }

    incr data(nbuttons)

    return $but
}

# ::ButtonBox::setbuttonstate --
#
#	Set the state of a given button tag.  If this makes any buttons
#       enable-able (ie, all of their tags are TRUE), enable them.
#
# Arguments:
#	path        the button box widget name
#       tag         the tag to modify
#       state       the new state of $tag (0 or 1)
#
# Results:
#	None.

proc ::ButtonBox::setbuttonstate {path tag state} {
    variable $path
    upvar 0  $path data
    # First see if this is a real tag
    if { [info exists data(tagstate,$tag)] } {
	set data(tagstate,$tag) $state
	foreach but $data(tags,$tag) {
	    set expression "1"
	    foreach buttontag $data(buttontags,$but) {
		append expression " && $data(tagstate,$buttontag)"
	    }
	    if { [expr $expression] } {
		set state normal
	    } else {
		set state disabled
	    }
	    $but configure -state $state
	}
    }
    return
}


# ------------------------------------------------------------------------------
#  Command ButtonBox::itemconfigure
# ------------------------------------------------------------------------------
proc ButtonBox::itemconfigure { path index args } {
    if { [set idx [lsearch $args -default]] != -1 } {