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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [library/] [FileEnt.tcl] - Blame information for rev 1774

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

Line No. Rev Author Line
1 578 markom
# FileEnt.tcl --
2
#
3
#       TixFileEntry Widget: an entry box for entering filenames.
4
#
5
# Copyright (c) 1996, Expert Interface Technologies
6
#
7
# See the file "license.terms" for information on usage and redistribution
8
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9
#
10
 
11
tixWidgetClass tixFileEntry {
12
    -classname TixFileEntry
13
    -superclass tixLabelWidget
14
    -method {
15
        invoke filedialog update
16
    }
17
    -flag {
18
        -activatecmd -command -dialogtype -disablecallback -disabledforeground
19
        -filebitmap -selectmode -state -validatecmd -value -variable
20
    }
21
    -forcecall {
22
        -variable
23
    }
24
    -static {
25
        -filebitmap
26
    }
27
    -configspec {
28
        {-activatecmd activateCmd ActivateCmd ""}
29
        {-command command Command ""}
30
        {-dialogtype dialogType DialogType ""}
31
        {-disablecallback disableCallback DisableCallback 0 tixVerifyBoolean}
32
        {-disabledforeground disabledForeground DisabledForeground #303030}
33
        {-filebitmap fileBitmap FileBitmap ""}
34
        {-selectmode selectMode SelectMode normal}
35
        {-state state State normal}
36
        {-validatecmd validateCmd ValidateCmd ""}
37
        {-value value Value ""}
38
        {-variable variable Variable ""}
39
    }
40
    -default {
41
        {*frame.borderWidth             2}
42
        {*frame.relief                  sunken}
43
        {*Label.font         -Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*}
44
        {*Button.highlightThickness     0}
45
        {*Entry.highlightThickness      0}
46
        {*Entry.borderWidth             0}
47
        {*Entry.background              #c3c3c3}
48
    }
49
}
50
 
51
proc tixFileEntry:InitWidgetRec {w} {
52
    upvar #0 $w data
53
 
54
    tixChainMethod $w InitWidgetRec
55
    set data(varInited)   0
56
 
57
        if {$data(-filebitmap) == ""} {
58
            set data(-filebitmap) [tix getbitmap openfile]
59
        }
60
}
61
 
62
proc tixFileEntry:ConstructFramedWidget {w frame} {
63
    upvar #0 $w data
64
 
65
    tixChainMethod $w ConstructFramedWidget $frame
66
 
67
    set data(w:entry)  [entry  $frame.entry]
68
    set data(w:button) [button $frame.button -bitmap $data(-filebitmap) \
69
        -takefocus 0]
70
    set data(entryfg) [$data(w:entry) cget -fg]
71
 
72
    pack $data(w:button) -side right -fill both
73
    pack $data(w:entry)  -side left  -expand yes -fill both
74
}
75
 
76
proc tixFileEntry:SetBindings {w} {
77
    upvar #0 $w data
78
 
79
    tixChainMethod $w SetBindings
80
 
81
    $data(w:button) config -command "tixFileEntry:OpenFile $w"
82
    tixSetMegaWidget $data(w:entry) $w
83
 
84
    # If user press <return>, verify the value and call the -command
85
    #
86
    bind $data(w:entry) <Return> "tixFileEntry:invoke $w"
87
    bind $data(w:entry) <KeyPress> {
88
        if {[set [tixGetMegaWidget %W](-selectmode)] == "immediate"} {
89
            tixFileEntry:invoke [tixGetMegaWidget %W]
90
        }
91
    }
92
    bind $data(w:entry) <FocusOut>  {
93
        if {"%d" == "NotifyNonlinear" || "%d" == "NotifyNonlinearVirtual"} {
94
            tixFileEntry:invoke [tixGetMegaWidget %W]
95
        }
96
    }
97
    bind $w <FocusIn> "focus $data(w:entry)"
98
}
99
 
100
#----------------------------------------------------------------------
101
#                           CONFIG OPTIONS
102
#----------------------------------------------------------------------
103
proc tixFileEntry:config-state {w value} {
104
    upvar #0 $w data
105
 
106
    if {$value == "normal"} {
107
        $data(w:button) config -state $value
108
        $data(w:entry)  config -state $value -fg $data(entryfg)
109
        catch {
110
            $data(w:label)  config -fg $data(entryfg)
111
        }
112
    } else {
113
        $data(w:button) config -state $value
114
        $data(w:entry)  config -state $value -fg $data(-disabledforeground)
115
        catch {
116
            $data(w:label)  config -fg $data(-disabledforeground)
117
        }
118
    }
119
 
120
    return ""
121
}
122
 
123
proc tixFileEntry:config-value {w value} {
124
    tixFileEntry:SetValue $w $value
125
}
126
 
127
proc tixFileEntry:config-variable {w arg} {
128
    upvar #0 $w data
129
 
130
    if [tixVariable:ConfigVariable $w $arg] {
131
       # The value of data(-value) is changed if tixVariable:ConfigVariable 
132
       # returns true
133
       tixFileEntry:SetValue $w $data(-value)
134
    }
135
    catch {
136
        unset data(varInited)
137
    }
138
    set data(-variable) $arg
139
}
140
 
141
#----------------------------------------------------------------------
142
#                         User Commands
143
#----------------------------------------------------------------------
144
proc tixFileEntry:invoke {w} {
145
    upvar #0 $w data
146
 
147
    if {[catch {$data(w:entry) index sel.first}] == 0} {
148
        # THIS ENTRY OWNS SELECTION --> TURN IT OFF
149
        #
150
        $data(w:entry) select from end
151
        $data(w:entry) select to   end
152
    }
153
 
154
    tixFileEntry:SetValue $w [$data(w:entry) get]
155
}
156
 
157
proc tixFileEntry:filedialog {w args} {
158
    upvar #0 $w data
159
 
160
    if {$args == ""} {
161
        return [tix filedialog $data(-dialogtype)]
162
    } else {
163
        return [eval [tix filedialog $data(-dialogtype)] $args]
164
    }
165
}
166
 
167
proc tixFileEntry:update {w} {
168
    upvar #0 $w data
169
 
170
    if {"x[$data(w:entry) get]" != "x$data(-value)"} {
171
        tixFileEntry:invoke $w
172
    }
173
}
174
#----------------------------------------------------------------------
175
#                       Internal Commands
176
#----------------------------------------------------------------------
177
proc tixFileEntry:OpenFile {w} {
178
     upvar #0 $w data
179
 
180
     if {$data(-activatecmd) != ""} {
181
         uplevel #0 $data(-activatecmd)
182
     }
183
 
184
     set filedlg [tix filedialog $data(-dialogtype)]
185
 
186
 
187
     $filedlg config -parent [winfo toplevel $w] \
188
         -command "tixFileEntry:FileDlgCallback $w"
189
 
190
     focus $data(w:entry)
191
 
192
     $filedlg popup
193
}
194
 
195
proc tixFileEntry:FileDlgCallback {w args} {
196
    set filename [tixEvent flag V]
197
 
198
    tixFileEntry:SetValue $w $filename
199
}
200
 
201
proc tixFileEntry:SetValue {w value} {
202
    upvar #0 $w data
203
 
204
    if {$data(-validatecmd) != ""} {
205
        set value [tixEvalCmdBinding $w $data(-validatecmd) "" $value]
206
    }
207
 
208
    if {$data(-state) == "normal"} {
209
        $data(w:entry) delete 0 end
210
        $data(w:entry) insert 0 $value
211
        $data(w:entry) xview end
212
    }
213
 
214
    set data(-value) $value
215
 
216
    tixVariable:UpdateVariable $w
217
 
218
    if {$data(-command) != "" && !$data(-disablecallback)} {
219
        if {![info exists data(varInited)]} {
220
            set bind(specs) ""
221
            tixEvalCmdBinding $w $data(-command) bind $value
222
        }
223
    }
224
}
225
 
226
proc tixFileEntry:Destructor {w} {
227
    upvar #0 $w data
228
 
229
    tixUnsetMegaWidget $data(w:entry)
230
    tixVariable:DeleteVariable $w
231
 
232
    # Chain this to the superclass
233
    #
234
    tixChainMethod $w Destructor
235
}

powered by: WebSVN 2.1.0

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