~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/common/entry.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # entry.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1993-2002 The Regents of the University of California.
  6 # All rights reserved.
  7 #
  8 # Redistribution and use in source and binary forms, with or without
  9 # modification, are permitted provided that the following conditions are met:
 10 #
 11 # A. Redistributions of source code must retain the above copyright notice,
 12 #    this list of conditions and the following disclaimer.
 13 # B. Redistributions in binary form must reproduce the above copyright notice,
 14 #    this list of conditions and the following disclaimer in the documentation
 15 #    and/or other materials provided with the distribution.
 16 # C. Neither the names of the copyright holders nor the names of its
 17 #    contributors may be used to endorse or promote products derived from this
 18 #    software without specific prior written permission.
 19 #
 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30 #
 31 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/common/entry.tcl,v 1.17 2002/02/14 18:22:08 lim Exp $
 32 
 33 
 34 #
 35 # For any entry created, the global (array) entryTab($w:object)
 36 # contains the name of the Otcl object to invoke when the entry is
 37 # updated (where $w is the wind path of the entry widget).
 38 # The "update" method takes one arg: the new value.
 39 # It should return 0 if the edit should be accepted,
 40 # and non-zero otherwise.  entryTab($w:value) should be
 41 # set to the initial value when the widget is created
 42 # (hidden in Entry base class).
 43 #
 44 
 45 bind Entry <Enter> {
 46         catch {
 47                 global entryTab
 48                 if $entryTab(%W:focus) {
 49                         focus %W
 50                 }
 51         }
 52 }
 53 bind Entry <Return> {
 54     set validateMode [%W cget -validate]
 55     %W validate
 56     %W configure -validate $validateMode
 57 }
 58 bind Entry <Escape> {
 59         focus .
 60         %W select clear
 61         %W delete 0 end
 62         catch {
 63                 global entryTab
 64                 set entryTab(%W:focus) 0
 65                 %W insert 0 $entryTab(%W:value)
 66         }
 67 }
 68 bind Entry <Control-g> [bind Entry <Escape>]
 69 
 70 bind Entry <Control-u> {
 71     tkEntrySetCursor %W 0
 72     %W delete insert end
 73 }
 74 
 75 proc mk.entry { w action text } {
 76         puts stderr "Use the new Entry class"
 77         exit 1
 78 }
 79 
 80 Class Entry
 81 
 82 # calls {$obj update key} if obj is not null,
 83 # otherwise calls {$self update key}
 84 #
 85 Entry instproc init { w value {obj {}} } {
 86         $self instvar win_
 87         set win_ $w
 88         entry $w -relief raised -borderwidth 1 -exportselection 1 \
 89                 -font [$self get_option entryFont] \
 90                 -validate focusout -validatecommand "$self validate %W %P"
 91         global entryTab
 92         if {$obj == {}} {
 93                 set entryTab($w:object) $self
 94         } else {
 95                 set entryTab($w:object) $obj
 96         }
 97         set entryTab($w:value) $value
 98         $w insert 0 $value
 99 }
100 
101 Entry instproc entry-value { } {
102         global entryTab
103         $self instvar win_
104         $win_ validate
105         return $entryTab($win_:value)
106 }
107 
108 Entry instproc set-value {v} {
109         global entryTab
110         $self instvar win_
111         $win_ delete 0 end
112         $win_ insert 0 $v
113         set entryTab($win_:value) $v
114 }
115 
116 Entry instproc clear { } {
117         global entryTab
118         $self instvar win_
119         set entryTab($win_:value) 0
120         $win_ insert 0 ""
121 }
122 
123 Entry instproc validate {entryName newValue} {
124     global entryTab
125     $self instvar win_
126 
127     set validateResult 1
128     set oldValue $entryTab($entryName:value)
129 
130     if {[catch {set reject [$entryTab($entryName:object) update $newValue]}]} {
131 
132         # The update method doesn't exist or it had a runtime error.
133 
134         set reject 0
135     }
136 
137     if {$reject} {
138         $win_ delete 0 end
139         $win_ insert 0 $oldValue
140         bell
141         set validateResult 0
142     } else {
143         set entryTab($entryName:value) $newValue
144         set validateResult 1
145     }
146 
147     return $validateResult
148 }
149 
150 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.