OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [itcl/] [iwidgets3.0.0/] [generic/] [radiobox.itk] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#
2
# Radiobox
3
# ----------------------------------------------------------------------
4
# Implements a radiobuttonbox.  Supports adding, inserting, deleting,
5
# selecting, and deselecting of radiobuttons by tag and index.
6
#
7
# ----------------------------------------------------------------------
8
#  AUTHOR: Michael J. McLennan          EMAIL: mmclennan@lucent.com
9
#          Mark L. Ulferts              EMAIL: mulferts@austin.dsccc.com
10
#
11
#  @(#) $Id: radiobox.itk,v 1.1.1.1 2002-01-16 10:24:50 markom Exp $
12
# ----------------------------------------------------------------------
13
#            Copyright (c) 1995 DSC Technologies Corporation
14
# ======================================================================
15
# Permission to use, copy, modify, distribute and license this software
16
# and its documentation for any purpose, and without fee or written
17
# agreement with DSC, is hereby granted, provided that the above copyright
18
# notice appears in all copies and that both the copyright notice and
19
# warranty disclaimer below appear in supporting documentation, and that
20
# the names of DSC Technologies Corporation or DSC Communications
21
# Corporation not be used in advertising or publicity pertaining to the
22
# software without specific, written prior permission.
23
#
24
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
25
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
26
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
27
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
28
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
29
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
30
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
31
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
32
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
33
# SOFTWARE.
34
# ======================================================================
35
 
36
#
37
# Usual options.
38
#
39
itk::usual Radiobox {
40
    keep -background -borderwidth -cursor -disabledforeground \
41
        -foreground -labelfont -selectcolor
42
}
43
 
44
# ------------------------------------------------------------------
45
#                            RADIOBOX
46
# ------------------------------------------------------------------
47
class iwidgets::Radiobox {
48
    inherit iwidgets::Labeledframe
49
 
50
    constructor {args} {}
51
 
52
    itk_option define -disabledforeground \
53
        disabledForeground DisabledForeground {}
54
    itk_option define -selectcolor selectColor Background {}
55
    itk_option define -command command Command {}
56
 
57
    public {
58
      method add {tag args}
59
      method buttonconfigure {index args}
60
      method delete {index}
61
      method deselect {index}
62
      method flash {index}
63
      method get {}
64
      method index {index}
65
      method insert {index tag args}
66
      method select {index}
67
    }
68
 
69
    protected method _command { name1 name2 opt }
70
 
71
    private {
72
      method gettag {index}      ;# Get the tag of the checkbutton associated
73
                                 ;# with a numeric index
74
 
75
      method _rearrange {}       ;# List of radiobutton tags.
76
      variable _buttons {}       ;# List of radiobutton tags.
77
      common _modes              ;# Current selection.
78
      variable _unique 0         ;# Unique id for choice creation.
79
    }
80
}
81
 
82
#
83
# Provide a lowercased access method for the Radiobox class.
84
#
85
proc ::iwidgets::radiobox {pathName args} {
86
    uplevel ::iwidgets::Radiobox $pathName $args
87
}
88
 
89
#
90
# Use option database to override default resources of base classes.
91
#
92
option add *Radiobox.labelMargin        10      widgetDefault
93
option add *Radiobox.labelFont     \
94
      "-Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*"  widgetDefault
95
option add *Radiobox.labelPos           nw      widgetDefault
96
option add *Radiobox.borderWidth        2       widgetDefault
97
option add *Radiobox.relief             groove  widgetDefault
98
 
99
# ------------------------------------------------------------------
100
#                        CONSTRUCTOR
101
# ------------------------------------------------------------------
102
body iwidgets::Radiobox::constructor {args} {
103
    trace variable [scope _modes($this)] w [code $this _command]
104
 
105
    grid columnconfigure $itk_component(childsite) 0 -weight 1
106
 
107
    eval itk_initialize $args
108
}
109
 
110
# ------------------------------------------------------------------
111
#                            OPTIONS
112
# ------------------------------------------------------------------
113
 
114
# ------------------------------------------------------------------
115
# OPTION: -command
116
#
117
# Specifies a command to be evaluated upon change in the radiobox
118
# ------------------------------------------------------------------
119
configbody iwidgets::Radiobox::command {}
120
 
121
# ------------------------------------------------------------------
122
#                            METHODS
123
# ------------------------------------------------------------------
124
 
125
# ------------------------------------------------------------------
126
# METHOD: index index
127
#
128
# Searches the radiobutton tags in the radiobox for the one with the
129
# requested tag, numerical index, or keyword "end".  Returns the
130
# choices's numerical index if found, otherwise error.
131
# ------------------------------------------------------------------
132
body iwidgets::Radiobox::index {index} {
133
    if {[llength $_buttons] > 0} {
134
        if {[regexp {(^[0-9]+$)} $index]} {
135
            if {$index < [llength $_buttons]} {
136
                return $index
137
            } else {
138
                error "Radiobox index \"$index\" is out of range"
139
            }
140
 
141
        } elseif {$index == "end"} {
142
            return [expr [llength $_buttons] - 1]
143
 
144
        } else {
145
            if {[set idx [lsearch $_buttons $index]] != -1} {
146
                return $idx
147
            }
148
 
149
            error "bad Radiobox index \"$index\": must be number, end,\
150
                    or pattern"
151
        }
152
 
153
    } else {
154
        error "Radiobox \"$itk_component(hull)\" has no radiobuttons"
155
    }
156
}
157
 
158
# ------------------------------------------------------------------
159
# METHOD: add tag ?option value option value ...?
160
#
161
# Add a new tagged radiobutton to the radiobox at the end.  The method
162
# takes additional options which are passed on to the radiobutton
163
# constructor.  These include most of the typical radiobutton
164
# options.  The tag is returned.
165
# ------------------------------------------------------------------
166
body iwidgets::Radiobox::add {tag args} {
167
    itk_component add $tag {
168
        eval radiobutton $itk_component(childsite).rb[incr _unique] \
169
            -variable [list [scope _modes($this)]] \
170
            -anchor w \
171
            -justify left \
172
            -highlightthickness 0 \
173
            -value $tag $args
174
    } {
175
      usual
176
      ignore -highlightthickness -highlightcolor
177
      rename -font -labelfont labelFont Font
178
    }
179
    lappend _buttons $tag
180
    grid $itk_component($tag)
181
    after idle [code $this _rearrange]
182
 
183
    return $tag
184
}
185
 
186
# ------------------------------------------------------------------
187
# METHOD: insert index tag ?option value option value ...?
188
#
189
# Insert the tagged radiobutton in the radiobox just before the
190
# one given by index.  Any additional options are passed on to the
191
# radiobutton constructor.  These include the typical radiobutton
192
# options.  The tag is returned.
193
# ------------------------------------------------------------------
194
body iwidgets::Radiobox::insert {index tag args} {
195
    itk_component add $tag {
196
        eval radiobutton $itk_component(childsite).rb[incr _unique] \
197
            -variable [list [scope _modes($this)]] \
198
            -highlightthickness 0 \
199
            -anchor w \
200
            -justify left \
201
            -value $tag $args
202
    } {
203
      usual
204
      ignore -highlightthickness -highlightcolor
205
      rename -font -labelfont labelFont Font
206
    }
207
    set index [index $index]
208
    set before [lindex $_buttons $index]
209
    set _buttons [linsert $_buttons $index $tag]
210
    grid $itk_component($tag)
211
    after idle [code $this _rearrange]
212
 
213
    return $tag
214
}
215
 
216
# ------------------------------------------------------------------
217
# METHOD: _rearrange
218
#
219
# Rearrange the buttons in the childsite frame using
220
# the grid geometry manager.
221
# ------------------------------------------------------------------
222
body iwidgets::Radiobox::_rearrange {} {
223
    set index 0
224
    set master $itk_component(childsite)
225
 
226
    if {[set count [llength $_buttons]] > 0} {
227
        foreach tag $_buttons {
228
            grid configure $itk_component($tag) -row $index -sticky nw
229
            grid rowconfigure $master $index -weight 0
230
            incr index
231
        }
232
        grid rowconfigure $master [expr $count-1] -weight 1
233
    }
234
}
235
 
236
# ------------------------------------------------------------------
237
# METHOD: delete index
238
#
239
# Delete the specified radiobutton.
240
# ------------------------------------------------------------------
241
body iwidgets::Radiobox::delete {index} {
242
 
243
    set tag [gettag $index]
244
    set index [index $index]
245
 
246
    destroy $itk_component($tag)
247
 
248
    set _buttons [lreplace $_buttons $index $index]
249
 
250
    if {$_modes($this) == $tag} {
251
        set _modes($this) {}
252
    }
253
    after idle [code $this _rearrange]
254
    return
255
}
256
 
257
# ------------------------------------------------------------------
258
# METHOD: select index
259
#
260
# Select the specified radiobutton.
261
# ------------------------------------------------------------------
262
body iwidgets::Radiobox::select {index} {
263
    set tag [gettag $index]
264
    $itk_component($tag) invoke
265
}
266
 
267
# ------------------------------------------------------------------
268
# METHOD: get
269
#
270
# Return the tag of the currently selected radiobutton.
271
# ------------------------------------------------------------------
272
body iwidgets::Radiobox::get {} {
273
    return $_modes($this)
274
}
275
 
276
# ------------------------------------------------------------------
277
# METHOD: deselect index
278
#
279
# Deselect the specified radiobutton.
280
# ------------------------------------------------------------------
281
body iwidgets::Radiobox::deselect {index} {
282
    set tag [gettag $index]
283
    $itk_component($tag) deselect
284
}
285
 
286
# ------------------------------------------------------------------
287
# METHOD: flash index
288
#
289
# Flash the specified radiobutton.
290
# ------------------------------------------------------------------
291
body iwidgets::Radiobox::flash {index} {
292
    set tag [gettag $index]
293
    $itk_component($tag) flash
294
}
295
 
296
# ------------------------------------------------------------------
297
# METHOD: buttonconfigure index ?option? ?value option value ...?
298
#
299
# Configure a specified radiobutton.  This method allows configuration
300
# of radiobuttons from the Radiobox level.  The options may have any
301
# of the values accepted by the add method.
302
# ------------------------------------------------------------------
303
body iwidgets::Radiobox::buttonconfigure {index args} {
304
    set tag [gettag $index]
305
    eval $itk_component($tag) configure $args
306
}
307
 
308
# ------------------------------------------------------------------
309
# CALLBACK METHOD: _command name1 name2 opt
310
#
311
# Tied to the trace on _modes($this). Whenever our -variable for our
312
# radiobuttons change, this method is invoked. It in turn calls
313
# the user specified tcl script given by -command.
314
# ------------------------------------------------------------------
315
body iwidgets::Radiobox::_command { name1 name2 opt } {
316
    uplevel #0 $itk_option(-command)
317
}
318
 
319
# ------------------------------------------------------------------
320
# METHOD: gettag index
321
#
322
# Return the tag of the checkbutton associated with a specified
323
# numeric index
324
# ------------------------------------------------------------------
325
body iwidgets::Radiobox::gettag {index} {
326
    return [lindex $_buttons [index $index]]
327
}
328
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.