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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [library/] [Variable.tcl] - Blame information for rev 1771

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

Line No. Rev Author Line
1 578 markom
# Variable.tcl --
2
#
3
#       Routines in this file are used to set up and operate variables
4
#       for classes that support the -variable option
5
#
6
# Copyright (c) 1996, Expert Interface Technologies
7
#
8
# See the file "license.terms" for information on usage and redistribution
9
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
#
11
 
12
 
13
 
14
# tixVariable:ConfigVariable --
15
#
16
#       Set up the -variable option for the object $w
17
#
18
# Side effects:
19
#
20
#       data(-variable) is changed to the name of the global variable
21
#       if the global variable exists, data(-value) takes the value of this
22
#       variable.
23
#       if the global variable does not exist, it is created with the
24
#       current data(-value)
25
#
26
# Return value:
27
#
28
#       true is data(-value) is changed, indicating that data(-command)
29
#       should be invoked.
30
#
31
proc tixVariable:ConfigVariable {w arg} {
32
    upvar #0 $w data
33
 
34
    set changed 0
35
 
36
    if {$data(-variable) != ""} {
37
        uplevel #0 \
38
            [list trace vdelete $data(-variable) w "tixVariable:TraceProc $w"]
39
    }
40
 
41
    if {$arg != ""} {
42
        if [uplevel #0 info exists [list $arg]] {
43
            # This global variable exists, we use its value
44
            #
45
            set data(-value) [uplevel #0 set [list $arg]]
46
            set changed 1
47
        } else {
48
            # This global variable does not exist; let's set it 
49
            #
50
            uplevel #0 [list set $arg $data(-value)]
51
        }
52
        uplevel #0 \
53
            [list trace variable $arg w "tixVariable:TraceProc $w"]
54
    }
55
 
56
    return $changed
57
}
58
 
59
proc tixVariable:UpdateVariable {w} {
60
    upvar #0 $w data
61
 
62
    if {$data(-variable) != ""} {
63
        uplevel #0 \
64
            [list trace vdelete  $data(-variable) w "tixVariable:TraceProc $w"]
65
        uplevel #0 \
66
            [list set $data(-variable) $data(-value)]
67
        uplevel #0 \
68
            [list trace variable $data(-variable) w "tixVariable:TraceProc $w"]
69
 
70
        # just in case someone has another trace and restricted my change
71
        #
72
        set data(-value) [uplevel #0 set [list $data(-variable)]]
73
    }
74
}
75
 
76
proc tixVariable:TraceProc {w name1 name2 op} {
77
    upvar #0 $w data
78
    set varname $data(-variable)
79
 
80
    if [catch {$w config -value [uplevel #0 [list set $varname]]} err] {
81
        uplevel #0 [list set $varname [list [$w cget -value]]]
82
        error $err
83
    }
84
    return
85
}
86
 
87
proc tixVariable:DeleteVariable {w} {
88
    upvar #0 $w data
89
 
90
    # Must delete the trace command of the -variable
91
    #
92
    if {$data(-variable) != ""} {
93
        uplevel #0 \
94
            [list trace vdelete $data(-variable) w "tixVariable:TraceProc $w"]
95
    }
96
}

powered by: WebSVN 2.1.0

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