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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#
2
# Timeentry
3
# ----------------------------------------------------------------------
4
# Implements a quicken style time entry field with a popup clock
5
# by combining the timefield and watch widgets together.  This
6
# allows a user to enter the time via the keyboard or by using the
7
# mouse by selecting the watch icon which brings up a popup clock.
8
# ----------------------------------------------------------------------
9
#   AUTHOR:  Mark L. Ulferts          E-mail: mulferts@austin.dsccc.com
10
#
11
#   @(#) $Id: timeentry.itk,v 1.1.1.1 2002-01-16 10:24:50 markom Exp $
12
# ----------------------------------------------------------------------
13
#            Copyright (c) 1997 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, UPTIMES, 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 Timeentry {
40
    keep -background -borderwidth -cursor -foreground -highlightcolor \
41
        -highlightthickness -labelfont -textbackground -textfont
42
}
43
 
44
# ------------------------------------------------------------------
45
#                              TIMEENTRY
46
# ------------------------------------------------------------------
47
class iwidgets::Timeentry {
48
    inherit iwidgets::Timefield
49
 
50
    constructor {args} {}
51
 
52
    itk_option define -grab grab Grab "global"
53
    itk_option define -icon icon Icon {}
54
    itk_option define -state state State normal
55
    itk_option define -closetext closeText Text Close
56
 
57
    #
58
    # The watch widget isn't created until needed, yet we need
59
    # its options to be available upon creation of a timeentry widget.
60
    # So, we'll define them in these class now so they can just be
61
    # propagated onto the watch later.
62
    #
63
    itk_option define -hourradius hourRadius Radius .50
64
    itk_option define -hourcolor hourColor Color red
65
 
66
    itk_option define -minuteradius minuteRadius Radius .80
67
    itk_option define -minutecolor minuteColor Color yellow
68
 
69
    itk_option define -pivotradius pivotRadius Radius .10
70
    itk_option define -pivotcolor pivotColor Color white
71
 
72
    itk_option define -secondradius secondRadius Radius .90
73
    itk_option define -secondcolor secondColor Color black
74
 
75
    itk_option define -clockcolor clockColor Color white
76
    itk_option define -clockstipple clockStipple ClockStipple {}
77
 
78
    itk_option define -tickcolor tickColor Color black
79
 
80
    itk_option define -watchheight watchHeight Height 175
81
    itk_option define -watchwidth watchWidth Width 155
82
 
83
    protected {
84
        method _getPopupTime {}
85
        method _releaseGrab {}
86
        method _popup {}
87
        method _getDefaultIcon {}
88
 
89
        common _defaultIcon ""
90
    }
91
}
92
 
93
#
94
# Provide a lowercased access method for the timeentry class.
95
#
96
proc ::iwidgets::timeentry {pathName args} {
97
    uplevel ::iwidgets::Timeentry $pathName $args
98
}
99
 
100
#
101
# Use option database to override default resources of base classes.
102
#
103
option add *Timeentry.watchWidth 155 widgetDefault
104
option add *Timeentry.watchHeight 175 widgetDefault
105
 
106
# ------------------------------------------------------------------
107
#                        CONSTRUCTOR
108
# ------------------------------------------------------------------
109
body iwidgets::Timeentry::constructor {args} {
110
    #
111
    # Create an icon label to act as a button to bring up the
112
    # watch popup.
113
    #
114
    itk_component add iconbutton {
115
        label $itk_interior.iconbutton -relief raised
116
    } {
117
        keep -borderwidth -cursor -foreground
118
    }
119
    grid $itk_component(iconbutton) -row 0 -column 0 -sticky ns
120
 
121
    #
122
    # Initialize the widget based on the command line options.
123
    #
124
    eval itk_initialize $args
125
}
126
 
127
# ------------------------------------------------------------------
128
#                             OPTIONS
129
# ------------------------------------------------------------------
130
 
131
# ------------------------------------------------------------------
132
# OPTION: -icon
133
#
134
# Specifies the clock icon image to be used in the time entry.
135
# Should one not be provided, then a default pixmap will be used
136
# if possible, bitmap otherwise.
137
# ------------------------------------------------------------------
138
configbody iwidgets::Timeentry::icon {
139
    if {$itk_option(-icon) == {}} {
140
        $itk_component(iconbutton) configure -image [_getDefaultIcon]
141
    } else {
142
        if {[lsearch [image names] $itk_option(-icon)] == -1} {
143
            error "bad icon option \"$itk_option(-icon)\":\
144
                   should be an existing image"
145
        } else {
146
            $itk_component(iconbutton) configure -image $itk_option(-icon)
147
        }
148
    }
149
}
150
 
151
# ------------------------------------------------------------------
152
# OPTION: -grab
153
#
154
# Specifies the grab level, local or global, to be obtained when
155
# bringing up the popup watch.  The default is global.
156
# ------------------------------------------------------------------
157
configbody iwidgets::Timeentry::grab {
158
    switch -- $itk_option(-grab) {
159
        "local" - "global" {}
160
        default {
161
            error "bad grab option \"$itk_option(-grab)\":\
162
                   should be local or global"
163
        }
164
    }
165
}
166
 
167
# ------------------------------------------------------------------
168
# OPTION: -state
169
#
170
# Specifies the state of the widget which may be disabled or
171
# normal.  A disabled state prevents selection of the time field
172
# or time icon button.
173
# ------------------------------------------------------------------
174
configbody iwidgets::Timeentry::state {
175
    switch -- $itk_option(-state) {
176
        normal {
177
            bind $itk_component(iconbutton)  [code $this _popup]
178
        }
179
        disabled {
180
            bind $itk_component(iconbutton)  {}
181
        }
182
    }
183
}
184
 
185
# ------------------------------------------------------------------
186
#                            METHODS
187
# ------------------------------------------------------------------
188
# ------------------------------------------------------------------
189
# PROTECTED METHOD: _getDefaultIcon
190
#
191
# This method is invoked uto retrieve the name of the default icon
192
# image displayed in the icon button.
193
# ------------------------------------------------------------------
194
body iwidgets::Timeentry::_getDefaultIcon {} {
195
 
196
  if {[lsearch [image types] pixmap] != -1} {
197
        set _defaultIcon [image create pixmap -data {
198
                    /* XPM */
199
                    static char *watch1a[] = {
200
                        /* width height num_colors chars_per_pixel */
201
                        "    20    20        8            1",
202
                        /* colors */
203
                        ". c #000000",
204
                        "# c #000099",
205
                        "a c #009999",
206
                        "b c #999999",
207
                        "c c #cccccc",
208
                        "d c #ffff00",
209
                        "e c #d9d9d9",
210
                        "f c #ffffff",
211
                        /* pixels */
212
                        "eeeeebbbcccccbbbeeee",
213
                        "eeeee...#####..beeee",
214
                        "eeeee#aacccccaabeeee",
215
                        "eeee#accccccccc##eee",
216
                        "eee#ccc#cc#ccdcff#ee",
217
                        "ee#accccccccccfcca#e",
218
                        "eeaccccccc.cccfcccae",
219
                        "eeac#cccfc.cccc##cae",
220
                        "e#cccccffc.cccccccc#",
221
                        "e#ccccfffc.cccccccc#",
222
                        "e#cc#ffcc......c#cc#",
223
                        "e#ccfffccc.cccccccc#",
224
                        "e#cffccfcc.cccccccc#",
225
                        "eeafdccfcccccccd#cae",
226
                        "eeafcffcccccccccccae",
227
                        "eee#fcc#cccccdccc#ee",
228
                        "eee#fcc#cc#cc#ccc#ee",
229
                        "eeee#accccccccc##eee",
230
                        "eeeee#aacccccaabeeee",
231
                        "eeeee...#####..beeee"
232
                    };
233
                }]
234
    } else {
235
        set _defaultIcon [image create bitmap -data {
236
                    #define watch1a_width 20
237
                    #define watch1a_height 20
238
                    static char watch1a_bits[] = {
239
                        0x40,0x40,0xf0,0xe0,0x7f,0xf0,0xe0,0xe0,0xf0,0x30,
240
                        0x80,0xf1,0x88,0x04,0xf2,0x0c,0x00,0xf6,0x04,0x04,
241
                        0xf4,0x94,0x84,0xf5,0x02,0x06,0xf8,0x02,0x0c,0xf8,
242
                        0x12,0x7e,0xf9,0x02,0x04,0xf8,0x02,0x24,0xf8,0x04,
243
                        0x00,0xf5,0x04,0x00,0xf4,0x88,0x02,0xf2,0x88,0x64,
244
                        0xf2,0x30,0x80,0xf1,0xe0,0x60,0xf0,0xe0,0xff,0xf0};
245
                }]
246
    }
247
 
248
    #
249
    # Since this image will only need to be created once, we redefine
250
    # this method to just return the image name for subsequent calls.
251
    #
252
    body ::iwidgets::Timeentry::_getDefaultIcon {} {
253
        return $_defaultIcon
254
    }
255
 
256
    return $_defaultIcon
257
}
258
 
259
 
260
# ------------------------------------------------------------------
261
# PROTECTED METHOD: _popup
262
#
263
# This method is invoked upon selection of the icon button.  It
264
# creates a watch widget within a toplevel popup, calculates
265
# the position at which to display the watch, performs a grab
266
# and displays the watch.
267
# ------------------------------------------------------------------
268
body iwidgets::Timeentry::_popup {} {
269
    #
270
    # First, let's nullify the icon binding so that any another
271
    # selections are ignored until were done with this one.  Next,
272
    # change the relief of the icon.
273
    #
274
    bind $itk_component(iconbutton)  {}
275
    $itk_component(iconbutton) configure -relief sunken
276
 
277
    #
278
    # Create a withdrawn toplevel widget and remove the window
279
    # decoration via override redirect.
280
    #
281
    itk_component add -private popup {
282
        toplevel $itk_interior.popup
283
    }
284
    $itk_component(popup) configure -borderwidth 2 -background black
285
    wm withdraw $itk_component(popup)
286
    wm overrideredirect $itk_component(popup) 1
287
 
288
    #
289
    # Add a binding to for Escape to always release the grab.
290
    #
291
    bind $itk_component(popup)  [code $this _releaseGrab]
292
 
293
    #
294
    # Create the watch widget.
295
    #
296
    itk_component add watch {
297
        iwidgets::Watch $itk_component(popup).watch
298
    } {
299
        usual
300
 
301
        rename -width -watchwidth watchWidth Width
302
        rename -height -watchheight watchHeight Height
303
 
304
        keep -hourradius -minuteradius -minutecolor -pivotradius -pivotcolor \
305
            -secondradius -secondcolor -clockcolor -clockstipple -tickcolor
306
    }
307
    grid $itk_component(watch) -row 0 -column 0
308
    $itk_component(watch) configure -cursor top_left_arrow
309
 
310
    #
311
    # Create a button widget so the user can say they are done.
312
    #
313
    itk_component add close {
314
        button $itk_component(popup).close -command [code $this _getPopupTime]
315
    } {
316
        usual
317
        rename -text -closetext closeText Text
318
    }
319
    grid $itk_component(close) -row 1 -column 0 -sticky ew
320
    $itk_component(close) configure -cursor top_left_arrow
321
 
322
    #
323
    # The icon button will be used as the basis for the position of the
324
    # popup on the screen.  We'll always attempt to locate the popup
325
    # off the lower right corner of the button.  If that would put
326
    # the popup off the screen, then we'll put above the upper left.
327
    #
328
    set rootx [winfo rootx $itk_component(iconbutton)]
329
    set rooty [winfo rooty $itk_component(iconbutton)]
330
    set popupwidth [cget -watchwidth]
331
    set popupheight [expr [cget -watchheight] + \
332
                         [winfo reqheight $itk_component(close)]]
333
 
334
    set popupx [expr $rootx + 3 + \
335
                    [winfo width $itk_component(iconbutton)]]
336
    set popupy [expr $rooty + 3 + \
337
                    [winfo height $itk_component(iconbutton)]]
338
 
339
    if {([expr $popupx + $popupwidth] > [winfo screenwidth .]) || \
340
            ([expr $popupy + $popupheight] > [winfo screenheight .])} {
341
        set popupx [expr $rootx - 3 - $popupwidth]
342
        set popupy [expr $rooty - 3 - $popupheight]
343
    }
344
 
345
    #
346
    # Get the current time from the timefield widget and both
347
    # show and select it on the watch.
348
    #
349
    $itk_component(watch) show [get]
350
 
351
    #
352
    # Display the popup at the calculated position.
353
    #
354
    wm geometry $itk_component(popup) +$popupx+$popupy
355
    wm deiconify $itk_component(popup)
356
    tkwait visibility $itk_component(popup)
357
 
358
    #
359
    # Perform either a local or global grab based on the -grab option.
360
    #
361
    if {$itk_option(-grab) == "local"} {
362
        grab $itk_component(popup)
363
    } else {
364
        grab -global $itk_component(popup)
365
    }
366
 
367
    #
368
    # Make sure the widget is above all others and give it focus.
369
    #
370
    raise $itk_component(popup)
371
    focus $itk_component(watch)
372
}
373
 
374
# ------------------------------------------------------------------
375
# PROTECTED METHOD: _popupGetTime
376
#
377
# This method is the callback for selection of a time on the
378
# watch.  It releases the grab and sets the time in the
379
# timefield widget.
380
# ------------------------------------------------------------------
381
body iwidgets::Timeentry::_getPopupTime {} {
382
    show [$itk_component(watch) get -clicks]
383
    _releaseGrab
384
}
385
 
386
# ------------------------------------------------------------------
387
# PROTECTED METHOD: _releaseGrab
388
#
389
# This method releases the grab, destroys the popup, changes the
390
# relief of the button back to raised and reapplies the binding
391
# to the icon button that engages the popup action.
392
# ------------------------------------------------------------------
393
body iwidgets::Timeentry::_releaseGrab {} {
394
    grab release $itk_component(popup)
395
    $itk_component(iconbutton) configure -relief raised
396
    destroy $itk_component(popup)
397
    unset itk_component(popup)
398
    bind $itk_component(iconbutton)  [code $this _popup]
399
}

powered by: WebSVN 2.1.0

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