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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
#!/usr/dist/bin/wishx -f
######################################################################
#
# help.tcl
#
# Copyright (C) 1993,1994 by John Heidemann <johnh@ficus.cs.ucla.edu>
# All rights reserved. See the main dontspace file for a full copyright
# notice.
#
# $Id: help.tcl,v 1.5 1999/09/10 05:57:13 johnh Exp $
#
# from: Id: klondikeMenus.tcl,v 1.17 1994/01/27 18:49:11 johnh Exp
#
######################################################################
#
# menu stuff
#
set rcsid(help.tcl) {$Id: help.tcl,v 1.5 1999/09/10 05:57:13 johnh Exp $}
proc readRelease {} {
global game
set catchval [catch {
set f [open $game(releasefile) r]
gets $f release
close $f
return $release
} ret]
if { $catchval == 2 } {
return $ret
} else {
return "unknown-release"
}
}
proc menuHighScores {} {
displayHighScores
}
proc menuFinishGame {} {
endGame "quit"
}
proc menuQuit {} {
global table
# quit game in progress, if any
endGame "quit"
# bail
exit 0
}
#----------------------------------------------------------------------
# (stolen from Ousterhout's demo program's mkBasic)
# and hacked to add SGML-ish (actually more MIME-ish) tags.
#
# Put the next window up tiled after the last window to go up.
# Maintain a list of relevant windows in the global variable stackList.
#
proc wmConfig {w title} {
global stackList
# debugLog "wmConfig $w $title"
#
# configure random wm stuff
#
if { [info exists stackList] == 0 } {
# setup a list with something that should never get removed
set stackList "."
}
# debugLog "\t$stackList"
#
# first geometry
#
set geometry [wm geometry [lindex $stackList [expr [llength $stackList] - 1]]]
set geoElems [split $geometry "x+"]
set geoX [lindex $geoElems 2]
set geoY [lindex $geoElems 3]
set neoGeoX [expr $geoX + 50]
set neoGeoY [expr $geoY + 50]
wm geometry $w [format "+%d+%d" $neoGeoX $neoGeoY]
lappend stackList $w
#
# cleanup
#
wm protocol $w WM_DELETE_WINDOW "unmenuHelp $w"
#
# group-hood
#
wm group $w .
#
# titles
#
wm title $w $title
wm iconname $w $title
# debugLog "\txxx: stackList $stackList"
}
proc unmenuHelp {w} {
global stackList tk_version
# debugLog "unmenuHelp $w"
# debugLog "\t$stackList"
if { [set listPos [lsearch -exact $stackList $w]] != -1 } {
set stackList [lreplace $stackList $listPos $listPos]
}
# In 4.0, we die if we destroy $w since
# tkButtonInvoke wants to do something with $w.ok
# after this "destroy $w".
# Do it later to work around the problem.
# after 10 "if \[winfo exists $w\] { destroy $w }"
# (This problem seems to have been fixed by 4.2,
# and the fix seems to cause problems there).
destroy $w
# debugLog "\t$stackList"
}
proc setMenuHelpKeyboardBindings {top target} {
global tk_version
if {$tk_version < 4.0} {
bind $top <Any-Enter> "focus $target"
} else {
focus $target
$target configure -takefocus 1
}
bind $target <Any-KeyPress-Return> "unmenuHelp $top"
bind $target <Any-KeyPress-Escape> "unmenuHelp $top"
bind $target <Any-KeyPress-KP_Enter> "unmenuHelp $top"
# mkMenuBindings $target
}
proc menuHelp {topic {titleWord ""}} {
global help helpWindowList
set w ".${topic}"
#
# destroy any existing window
# NEEDSWORK: should just bring it forward.
#
catch {unmenuHelp $w}
#
# create a new window
#
set tl [toplevel $w]
# debugLog "toplevel: $tl"
# debugLog "menuHelp $w"
# default title
if { $titleWord == "" } { set titleWord $topic }
wmConfig $w "Lava-ps--$titleWord"
set padValue 8
button $w.ok -text OK -padx [expr 2*$padValue] -command "unmenuHelp $w"
# NEEDSWORK: font selection should be configurable.
#
# If you use this code elsewhere, please follow two conscious
# style choices. First, wide things are hard to read
# (50 chars is about the most reasonable---consider newspaper
# columns). Second, we allow the user to resize the window.
# (The user should always have control, even to do stupid things.)
#
text $w.t \
-relief raised -bd 2 -yscrollcommand "$w.s set" \
-setgrid true -wrap word \
-width 60 -padx $padValue -pady $padValue \
-font -*-Times-Medium-R-*-140-*
set defFg [lindex [$w.t configure -foreground] 4]
set defBg [lindex [$w.t configure -background] 4]
$w.t tag configure italic -font -*-Times-Medium-I-Normal-*-140-*
$w.t tag configure computer -font -*-Courier-Medium-R-Normal-*-120-*
$w.t tag configure big -font -*-Times-Bold-R-Normal-*-180-*
$w.t tag configure reverse -foreground $defBg -background $defFg
scrollbar $w.s -relief flat -command "$w.t yview"
pack append $w $w.ok {bottom} $w.s {right filly} $w.t {expand fill}
$w.t mark set insert 0.0
# Set up keyboard bindings.
setMenuHelpKeyboardBindings $w "$w.ok"
#
# Scan the text for tags.
#
set t $help($topic)
while { [regexp -indices {<([^@>]*)>} $t match inds] == 1 } {
set start [lindex $inds 0]
set end [lindex $inds 1]
set keyword [string range $t $start $end]
# puts stderr "tag $keyword found at $inds"
# insert the left hand text into the thing
set oldend [$w.t index end]
$w.t insert end [string range $t 0 [expr $start-2]]
purgeAllTags $w.t $oldend insert
# check for begin/end tag
if { [string range $keyword 0 0] == "/" } {
# end region
set keyword [string trimleft $keyword "/"]
if { [info exists tags($keyword)] == 0 } {
error "end tag $keyword without beginning"
}
$w.t tag add $keyword $tags($keyword) insert
# puts stdout "tag $keyword added from $tags($keyword) to [$w.t index insert]"
unset tags($keyword)
} else {
if { [info exists tags($keyword)] == 1 } {
error "nesting of begin tag $keyword"
}
set tags($keyword) [$w.t index insert]
# puts stdout "tag $keyword begins at [$w.t index insert]"
}
# continue with the rest
set t [string range $t [expr $end+2] end]
}
set oldend [$w.t index end]
$w.t insert end $t
purgeAllTags $w.t $oldend insert
#
# Disable the text so the user can't mess with it.
#
$w.t configure -state disabled
}
proc purgeAllTags {w start end} {
# remote any bogus tags
# puts stderr "Active tags at $start are [$w tag names $start]"
foreach tag [$w tag names $start] {
$w tag remove $tag $start $end
}
}
proc menuHelpScrollToTag {topic tag} {
set w ".${topic}"
catch {$w.t yview -pickplace reverse.first}
}
proc debugLog {s} {
puts $s
}
proc debugLogPause {s} {
update idletasks
puts $s
puts "\[pause\]"
gets stdin dummy
}
|