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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [iwidgets3.0.0/] [generic/] [checkbox.itk] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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