File: misc.tcl

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (202 lines) | stat: -rw-r--r-- 4,330 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
############################################
# TKSCILAB Gui Interface facility for Scilab
# Bertrand Guiheneuf - 1998 
############################################
#
# -->   misc.tcl
# 	$Id: misc.tcl,v 1.3 1998/02/24 21:40:32 guiheneu Exp guiheneu $	


######################################################################################
proc Redraw { handle } {
# Completely redraw an object by reseting all its 
# property 

    global Win;
    set name $Win($handle);
    global "$name";
    set style [set "$name\(style)" ];
    
    switch -exact -- $style {
	figure {
	}
	default {
	    set fields [array names $name];
	    
	    foreach x $fields {
		
		if {[string compare $x "parent"] != 0} {
		    SetField $handle $x [set "$name\($x)"];
		}
	    }
	    
	}
    }



}






######################################################################################
proc GetRealParent {hparent control} {
    # this routine is used to determine the real
    # parent of an object.
    # for example the parent of a figure (toplevel) is
    # always ".", ie the window with handle 0
    # if the specified parent is not valid or if the 
    # parent is "." and the object is not a figure,
    # then the parent is created

    # INPUT: 
    #  hparent : handle of the virtual parent
    #  control : type of the control (in tk)
    # OUTPUT:
    #  handle of the real parent

    global FigList gcf;
    
    switch -exact -- $control {
	menu {
	    if { $hparent >=1000 } { return $hparent}
	    if { [lsearch -exact $FigList $hparent] != -1 } {
		set h $hparent;
	    } else {
		set h [getgcf];
	    }
	    return $h;
	}

	default {
	    if { $hparent == 0 } {
		# the hparent handle is 0 so we have to determine a 
		# hparent figure
		set hparent [getgcf];
	    }
	    return $hparent;
	}
    }
}


proc getgcf {} {
    # return the current figure and create it
    # if necessary
    # INPUT : void
    # OUTPUT : handle of the current figure 

    global gcf;
    
    if { $gcf == 0 } {
	# there is no current figure, so lets create one
	set h [ CreateFigure 0]
	set hparent $h
    } else {
	# the current figure is OK
	set hparent $gcf
    }
    return $hparent;
}


######################################################################################
proc FindObj { field value } {
    # returns the handle of an object which field $field
    # matches $value
    
    global Win;
    
    
    
    set Windexes [array names Win];
    set len [llength $Windexes];
    
    set handle -1;
    
    for { set Idx 0 } { $Idx < $len } { incr Idx } {
	
	set obj "$Win([lindex $Windexes $Idx])";
	global $obj;
	
	if { [info exists "$obj\($field)"] } {
	    set tmp [set "$obj\($field)"];
	    if { [winfo exists [set "$obj\(path)"] ] } {
	    if { [string compare $tmp  $value]==0 } {
		set handle [lindex $Windexes $Idx];
		break;
	    }
	}
    }
}

return $handle;

}

######################################################################################
proc FindFig { field value } {
    # returns the handle of an object which field $field
    # matches $value
    
    global Win;
    
    
    
    set Windexes [array names Win];
    set len [llength $Windexes];
    
    set handle -1;
    
    for { set Idx 0 } { $Idx < $len } { incr Idx } {
	
	set obj "$Win([lindex $Windexes $Idx])";
	global $obj;
	
	if { [info exists "$obj\($field)"] } {
	    set tmp [set "$obj\($field)"];
	    
	    if { [string compare $tmp  $value]==0 } {
		set handle [lindex $Windexes $Idx];
		break;
	    }
	    
	}
    }

return $handle;

}


######################################################################################



  proc ChgConfigure { WinPath width height } {
      # called when the parent of a window chages its size
      
      
      global Win;

      # find the handle of the closed figure
      set h [FindObj "path" $WinPath];
      set name $Win($h);
      global "$name";
      
      set "$name\(w)" $width;
      set "$name\(h)" $height;
      set style [set "$name\(style)"];
      #if {[info exist "$name\(position)" ]} { SetField $h position  [set "$name\(position)"]; }
      if {[string compare $style slider]==0} { SetField $h position  [set "$name\(position)"]; }
      if {[info exist "$name\(fontsize)" ]} { SetField $h fontsize  [set "$name\(fontsize)"]; }
      
    
      
  }