summaryrefslogtreecommitdiff
path: root/tix/library/OldUtil.tcl
blob: bf2a98e2f144a550a23b203348dfa6d0c300147f (plain)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# OldUtil.tcl -
#
#	This is an undocumented file.
#	   Are these features used in Tix : NO.
#	   Should I use these features    : NO.
#
# Copyright (c) 1996, Expert Interface Technologies
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

proc setenv {name args} {
    global env

    if {[llength $args] == 1} {
        return [set env($name) [lindex $args 0]]
    } else {
        if {[info exists env($ename)] == 0} {
            tkerror "Error in setenv: "
                    "environment variable \"$name\" does not exist"
        } else {
            return $env($name)
        }
    }
}
#----------------------------------------------------------------------
#
#
#           U T I L I T Y   F U N C T I O N S  F O R   T I X 
#
#
#----------------------------------------------------------------------

# RESET THE STRING IN THE ENTRY
proc tixSetEntry {entry string} {
    set oldstate [lindex [$entry config -state] 4]
    $entry config -state normal
    $entry delete 0 end
    $entry insert 0 $string
    $entry config -state $oldstate
}

# GET THE FIRST SELECTED ITEM IN A LIST
proc tixListGetSingle {lst} {
    set indices [$lst curselection]
    if {$indices != "" } {
	return [$lst get [lindex $indices 0]]
    } else {
	return ""
    }
}

#----------------------------------------------------------------------
# RECORD A DIALOG'S POSITION AND RESTORE IT THE NEXT TIME IT IS OPENED
#----------------------------------------------------------------------
proc tixDialogRestore {w {flag -geometry}} {
    global tixDPos

    if [info exists tixDPos($w)] {
	if ![winfo ismapped $w] {
	    wm geometry $w $tixDPos($w)
	    wm deiconify $w
	}
    } elseif {$flag == "-geometry"} {
	update
	set tixDPos($w) [winfo geometry $w]
    } else {
	update
	set tixDPos($w) +[winfo rootx $w]+[winfo rooty $w]
    }
}
#----------------------------------------------------------------------
# RECORD A DIALOG'S POSITION AND RESTORE IT THE NEXT TIME IT IS OPENED
#----------------------------------------------------------------------
proc tixDialogWithdraw {w {flag -geometry}} {
    global tixDPos

    if [winfo ismapped $w] {
	if {$flag == "-geometry"} {
	    set tixDPos($w) [winfo geometry $w]
	} else {
	    set tixDPos($w) +[winfo rootx $w]+[winfo rooty $w]
	}
	wm withdraw $w
    }
}
#----------------------------------------------------------------------
# RECORD A DIALOG'S POSITION AND RESTORE IT THE NEXT TIME IT IS OPENED
#----------------------------------------------------------------------
proc tixDialogDestroy {w {flag -geometry}} {
    global tixDPos

    if [winfo ismapped $w] {
	if {$flag == "-geometry"} {
	    set tixDPos($w) [winfo geometry $w]
	} else {
	    set tixDPos($w) +[winfo rootx $w]+[winfo rooty $w]
	}
    }
    destroy $w
}

# Obsolete
#
proc tixQueryAppResource {name class default} {

    set value [option get . $name $class]
    if {$value == ""} {
	return $default
    } else {
	return $value
    }    
}
proc tixCreateToplevel {w {type -mapped}} {
    upvar #0 $w data

    toplevel $w
    wm minsize $w 0 0
    if {$type == "-withdrawn"} {
	wm withdraw $w
    }

    bind $w <Destroy>    [bind Toplevel <Destroy>]
    bind $w <Map>        [bind Toplevel <Map>]
    bind $w <Unmap>      [bind Toplevel <Unmap>]
    bind $w <Visibility> [bind Toplevel <Visibility>]
    bind $w <Destroy>    "+_tixToplevelDestroy $w"
    bind $w <Map>        "+_tixToplevelMap $w"
    bind $w <Unmap>      "+_tixToplevelUnmap $w"
    bind $w <Visibility> "+_tixToplevelVisibility $w"
}

proc _tixToplevelDestroy {w} {
    upvar #0 $w data

    unset data
}

proc _tixToplevelUnmap {w} {
    upvar #0 $w data

    foreach dlg $data(dialogs) {
	set data($dlg,geom) [winfo geometry $dlg]
	wm withdraw $dlg
    }
}

proc _tixToplevelMap {w} {
    upvar #0 $w data

    foreach dlg $data(dialogs) {
	wm geometry $dlg $data($dlg,geom)
	wm deiconify $dlg
    }
}

proc _tixToplevelVisibility {w} {
    upvar #0 $w data

    foreach dlg $data(dialogs) {
	raise $dlg $w
    }
}

proc tixCreateDialogShell {w {type -mapped}} {
    toplevel $w
    set parent [winfo parent $w]
    upvar #0 $parent data

    wm minsize $w 0 0
    wm withdraw $w
    update
    mwm transfor $w [winfo parent $w]
    lappend data(dialogs) $w
    bind $w <Destroy> "_tixDialogDestroy $w"

    if {$type != "-withdrawn"} {
	wm deiconify $w
    }
}

proc _tixDialogDestroy {w} {
    set parent [winfo parent $w]
    upvar #0 $parent data

    catch {unset $data($w,geom)}
}


proc _tixInitMainWindow {w} {
    upvar #0 $w data

    set data(dialogs) ""

    bind $w <Destroy>    +[bind Toplevel <Destroy>]
    bind $w <Map>        +[bind Toplevel <Map>]
    bind $w <Unmap>      +[bind Toplevel <Unmap>]
    bind $w <Visibility> +[bind Toplevel <Visibility>]
    bind $w <Destroy>    "+_tixToplevelDestroy $w"
    bind $w <Map>        "+_tixToplevelMap $w"
    bind $w <Unmap>      "+_tixToplevelUnmap $w"
    bind $w <Visibility> "+_tixToplevelVisibility $w"
}

# The "mwm" command comes from tkmwm, a cousin package of Tix
# If this wish does not support mwm, the following line prevent code
# that uses "mwm" from breaking.
#
if {[info commands mwm] == ""} {
    proc mwm {args} {}
}

#----------------------------------------------------------------------
# Automatically initialization call
#----------------------------------------------------------------------

# This has been disabled

if 0 {
    _tixInitMainWindow .
}