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

Subversion Repositories or1k_old

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Spinint
2
# ----------------------------------------------------------------------
3
# Implements an integer spinner widget.  It inherits basic spinner
4
# functionality from Spinner and adds specific features to create
5
# an integer-only spinner.
6
# Arrows may be placed horizontally or vertically.
7
# User may specify an integer range and step value.
8
# Spinner may be configured to wrap when min or max value is reached.
9
#
10
# NOTE:
11
# Spinint integer values should not exceed the size of a long integer.
12
# For a 32 bit long the integer range is -2147483648 to 2147483647.
13
#
14
# ----------------------------------------------------------------------
15
#   AUTHOR:  Sue Yockey               Phone: (214) 519-2517
16
#                                     E-mail: syockey@spd.dsccc.com
17
#                                             yockey@acm.org
18
#
19
#   @(#) $Id: spinint.itk,v 1.1.1.1 2002-01-16 10:24:50 markom Exp $
20
# ----------------------------------------------------------------------
21
#            Copyright (c) 1995 DSC Technologies Corporation
22
# ======================================================================
23
# Permission to use, copy, modify, distribute and license this software
24
# and its documentation for any purpose, and without fee or written
25
# agreement with DSC, is hereby granted, provided that the above copyright
26
# notice appears in all copies and that both the copyright notice and
27
# warranty disclaimer below appear in supporting documentation, and that
28
# the names of DSC Technologies Corporation or DSC Communications
29
# Corporation not be used in advertising or publicity pertaining to the
30
# software without specific, written prior permission.
31
#
32
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
33
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
34
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
35
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
36
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
37
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
40
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
41
# SOFTWARE.
42
# ======================================================================
43
 
44
#
45
# Usual options.
46
#
47
itk::usual Spinint {
48
    keep -background -borderwidth -cursor -foreground -highlightcolor \
49
         -highlightthickness -insertbackground  -insertborderwidth \
50
         -insertofftime -insertontime -insertwidth -labelfont \
51
         -selectbackground -selectborderwidth -selectforeground \
52
         -textbackground -textfont
53
}
54
 
55
# ------------------------------------------------------------------
56
#                            SPININT
57
# ------------------------------------------------------------------
58
class iwidgets::Spinint {
59
    inherit iwidgets::Spinner
60
 
61
    constructor {args} {
62
        Spinner::constructor -validate numeric
63
    } {}
64
 
65
    itk_option define -range range Range ""
66
    itk_option define -step step Step 1
67
    itk_option define -wrap wrap Wrap true
68
 
69
    public method up {}
70
    public method down {}
71
}
72
 
73
#
74
# Provide a lowercased access method for the Spinint class.
75
#
76
proc ::iwidgets::spinint {pathName args} {
77
    uplevel ::iwidgets::Spinint $pathName $args
78
}
79
 
80
# ------------------------------------------------------------------
81
#                        CONSTRUCTOR
82
# ------------------------------------------------------------------
83
body iwidgets::Spinint::constructor {args} {
84
    eval itk_initialize $args
85
 
86
    $itk_component(entry) delete 0 end
87
 
88
    if {[lindex $itk_option(-range) 0] == ""} {
89
        $itk_component(entry) insert 0 "0"
90
    } else {
91
        $itk_component(entry) insert 0 [lindex $itk_option(-range) 0]
92
    }
93
}
94
 
95
# ------------------------------------------------------------------
96
#                             OPTIONS
97
# ------------------------------------------------------------------
98
 
99
# ------------------------------------------------------------------
100
# OPTION: -range
101
#
102
# Set min and max values for spinner.
103
# ------------------------------------------------------------------
104
configbody iwidgets::Spinint::range {
105
    if {$itk_option(-range) != ""} {
106
        if {[llength $itk_option(-range)] != 2} {
107
            error "wrong # args: should be\
108
                    \"$itk_component(hull) configure -range {begin end}\""
109
        }
110
 
111
        set min [lindex $itk_option(-range) 0]
112
        set max [lindex $itk_option(-range) 1]
113
 
114
        if {![regexp {^-?[0-9]+$} $min]} {
115
            error "bad range option \"$min\": begin value must be\
116
                    an integer"
117
        }
118
        if {![regexp {^-?[0-9]+$} $max]} {
119
            error "bad range option \"$max\": end value must be\
120
                    an integer"
121
        }
122
        if {$min > $max} {
123
            error "bad option starting range \"$min\": must be less\
124
                    than ending: \"$max\""
125
        }
126
    }
127
}
128
 
129
# ------------------------------------------------------------------
130
# OPTION: -step
131
#
132
# Increment spinner by step value.
133
# ------------------------------------------------------------------
134
configbody iwidgets::Spinint::step {
135
}
136
 
137
# ------------------------------------------------------------------
138
# OPTION: -wrap
139
#
140
# Specify whether spinner should wrap value if at min or max.
141
# ------------------------------------------------------------------
142
configbody iwidgets::Spinint::wrap {
143
}
144
 
145
# ------------------------------------------------------------------
146
#                            METHODS
147
# ------------------------------------------------------------------
148
 
149
# ------------------------------------------------------------------
150
# METHOD: up
151
#
152
# Up arrow button press event.  Increment value in entry.
153
# ------------------------------------------------------------------
154
body iwidgets::Spinint::up {} {
155
    set min_range [lindex $itk_option(-range) 0]
156
    set max_range [lindex $itk_option(-range) 1]
157
 
158
    set val [$itk_component(entry) get]
159
    if {[lindex $itk_option(-range) 0] != ""} {
160
 
161
        #
162
        # Check boundaries.
163
        #
164
        if {$val >= $min_range && $val < $max_range} {
165
            incr val $itk_option(-step)
166
 
167
            #
168
            # Re-check boundaries.
169
            #
170
            if {$val >= $min_range && $val <= $max_range} {
171
                $itk_component(entry) delete 0 end
172
                $itk_component(entry) insert 0 $val
173
            } else {
174
 
175
                #
176
                # This is wrap when -step > 1.
177
                #
178
                if {$itk_option(-wrap)} {
179
                    if {$val > $max_range} {
180
                        $itk_component(entry) delete 0 end
181
                        $itk_component(entry) insert 0 $min_range
182
                    } else {
183
                        uplevel #0 $itk_option(-invalid)
184
                    }
185
                } else {
186
                    uplevel #0 $itk_option(-invalid)
187
                }
188
            }
189
 
190
        } else {
191
            if {$itk_option(-wrap)} {
192
                if {$val == $max_range} {
193
                    $itk_component(entry) delete 0 end
194
                    $itk_component(entry) insert 0 $min_range
195
                } else {
196
                    uplevel #0 $itk_option(-invalid)
197
                }
198
            } else {
199
                uplevel #0 $itk_option(-invalid)
200
            }
201
        }
202
    } else {
203
 
204
        #
205
        # No boundaries.
206
        #
207
        incr val $itk_option(-step)
208
        $itk_component(entry) delete 0 end
209
        $itk_component(entry) insert 0 $val
210
    }
211
}
212
 
213
# ------------------------------------------------------------------
214
# METHOD: down
215
#
216
# Down arrow button press event.  Decrement value in entry.
217
# ------------------------------------------------------------------
218
body iwidgets::Spinint::down {} {
219
    set min_range [lindex $itk_option(-range) 0]
220
    set max_range [lindex $itk_option(-range) 1]
221
 
222
    set val [$itk_component(entry) get]
223
    if {[lindex $itk_option(-range) 0] != ""} {
224
 
225
        #
226
        # Check boundaries.
227
        #
228
        if {$val > $min_range && $val <= $max_range} {
229
            incr val -$itk_option(-step)
230
 
231
            #
232
            # Re-check boundaries.
233
            #
234
            if {$val >= $min_range && $val <= $max_range} {
235
                $itk_component(entry) delete 0 end
236
                $itk_component(entry) insert 0 $val
237
            } else {
238
 
239
                #
240
                # This is wrap when -step > 1.
241
                #
242
                if {$itk_option(-wrap)} {
243
                    if {$val < $min_range} {
244
                        $itk_component(entry) delete 0 end
245
                        $itk_component(entry) insert 0 $max_range
246
                    } else {
247
                        uplevel #0 $itk_option(-invalid)
248
                    }
249
                } else {
250
                    uplevel #0 $itk_option(-invalid)
251
                }
252
            }
253
 
254
        } else {
255
            if {$itk_option(-wrap)} {
256
                if {$val == $min_range} {
257
                    $itk_component(entry) delete 0 end
258
                    $itk_component(entry) insert 0 $max_range
259
                } else {
260
                    uplevel #0 $itk_option(-invalid)
261
                }
262
            } else {
263
                uplevel #0 $itk_option(-invalid)
264
            }
265
        }
266
    } else {
267
 
268
        #
269
        # No boundaries.
270
        #
271
        incr val -$itk_option(-step)
272
        $itk_component(entry) delete 0 end
273
        $itk_component(entry) insert 0 $val
274
    }
275
}

powered by: WebSVN 2.1.0

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