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

Open Mash Cross Reference
mash/tcl/common/ui-util.tcl

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

  1 # ui-util.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/ui-util.tcl,v 1.25 2004/05/27 01:44:08 aswan Exp $
 32 
 33 import Entry
 34 
 35 set nids 0
 36 proc uniqueID { } {
 37         global nids
 38         incr nids
 39         return $nids
 40 }
 41 
 42 proc isCIF fmt {
 43         # only supported CIF format is h.261
 44         if { $fmt == "h261" } {
 45                 return 1
 46         }
 47         return 0
 48 }
 49 
 50 #
 51 # Return true if the two strings provide more or less the
 52 # same informational content
 53 #
 54 proc cname_redundant { name cname } {
 55         set ni [string first @ $name]
 56         if { $ni < 0 } {
 57                 return 0
 58         }
 59         set ci [string first @ $cname]
 60         if { $ci < 0 } {
 61                 return 0
 62         }
 63         if { [string compare \
 64                 [string range $name 0 $ni] \
 65                 [string range $cname 0 $ci]] == 0 } {
 66                 return 1
 67         }
 68         return 0
 69 }
 70 
 71 set current_icon_mark "FIXME"
 72 
 73 proc mk.key w {
 74         puts stderr "Use the new KeyEditor class"
 75         exit 1
 76 }
 77 
 78 #
 79 # A KeyEditor is a widget composed of a toggle button and an
 80 # text entry box.  (Here "Key" refers to an encryption key
 81 # not a keyboard key.)  The constructor takes a window to
 82 # embed the widget into and a crypt object upon which the
 83 # install-key method is dispatched to set the key to reflect
 84 # user changes.  install-key "" means encryption is disabled.
 85 # install-key returns 0 if the operation is successful or less
 86 # than 0 if the operation failed (e.g., the key was illegal)
 87 #
 88 Class KeyEditor
 89 
 90 KeyEditor instproc init { w crypt } {
 91         $self instvar crypt_ entry_ win_
 92         set crypt_ $crypt
 93         set win_ $w
 94         frame $w.key
 95         checkbutton $w.key.button -text "Encryption Key:" -relief flat \
 96                 -font [$self get_option smallfont] \
 97                 -command "$self toggle" -variable [$self tkvarname encryptOn_]\
 98                 -disabledforeground gray40
 99         set key [$self get_option sessionKey]
100 
101         # pass in $self so that Entry will call {$self update key}
102         # when key is set
103         set entry_ [new Entry $w.key.entry $key $self]
104         $self set-key $key
105         pack $w.key.button -side left
106         pack $w.key.entry -side left -fill x -expand 1
107 }
108 
109 KeyEditor instproc disable {} {
110         $self instvar win_
111         $win_.key.button configure -state disabled
112 }
113 
114 KeyEditor instproc enable {} {
115         $self instvar win_
116         $win_.key.button configure -state normal
117 }
118 
119 KeyEditor instproc set-key key {
120         $self tkvar encryptOn_
121         $self instvar crypt_ entry_
122         if { $key == "" } {
123                 $crypt_ crypt_clear
124                 set encryptOn_ 0
125                 $self disable
126         } elseif { [$crypt_ install-key $key] != "" } {
127                 # illegal key - clear the entry
128                 $self disable
129                 set encryptOn_ 0
130                 $entry_ clear
131         } else {
132                 $self enable
133                 set encryptOn_ 1
134         }
135 }
136 
137 KeyEditor instproc toggle {} {
138         $self instvar crypt_ entry_
139         $self tkvar encryptOn_
140         if $encryptOn_ {
141                 $crypt_ install-key [$entry_ entry-value]
142         } else {
143                 $crypt_ install-key ""
144         }
145 }
146 
147 KeyEditor instproc update key {
148         set key [string trim $key]
149         $self set-key $key
150         return 0
151 }
152 
153 Class TextEntry -superclass Entry
154 TextEntry instproc init { target w text } {
155         $self next $w $text
156         $self set target_ $target
157 }
158 
159 TextEntry instproc update s {
160         $self instvar target_
161         if { $s != "" } {
162                 set s [string trim $s]
163         }
164         if {$target_ == {}} {
165                 return 0
166         } else {
167                 return [eval $target_ \"$s"]
168         }
169 }
170 

~ [ 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.