1 |
578 |
markom |
# Viewer for HTML help info
|
2 |
|
|
# Copyright 1998, 1999 Cygnus Solutions
|
3 |
|
|
#
|
4 |
|
|
# This program is free software; you can redistribute it and/or modify it
|
5 |
|
|
# under the terms of the GNU General Public License (GPL) as published by
|
6 |
|
|
# the Free Software Foundation; either version 2 of the License, or (at
|
7 |
|
|
# your option) any later version.
|
8 |
|
|
#
|
9 |
|
|
# This program is distributed in the hope that it will be useful,
|
10 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
# GNU General Public License for more details.
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
# -----------------------------------------------------------------------------
|
16 |
|
|
# NAME:
|
17 |
|
|
# HtmlViewer::constructor
|
18 |
|
|
#
|
19 |
|
|
# SYNOPSIS:
|
20 |
|
|
# constructor args
|
21 |
|
|
#
|
22 |
|
|
# DESC:
|
23 |
|
|
# Creates the Help Viewer window.
|
24 |
|
|
# -----------------------------------------------------------------------------
|
25 |
|
|
body HtmlViewer::constructor {args} {
|
26 |
|
|
window_name "Help"
|
27 |
|
|
eval itk_initialize $args
|
28 |
|
|
_buildwin
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
# -----------------------------------------------------------------------------
|
33 |
|
|
# NAME:
|
34 |
|
|
# private method HtmlViewer::_buildwin
|
35 |
|
|
#
|
36 |
|
|
# SYNOPSIS:
|
37 |
|
|
# _buildwin args
|
38 |
|
|
#
|
39 |
|
|
# DESC:
|
40 |
|
|
# This function is called by the constructor to build the widget. It
|
41 |
|
|
# creates pulldown menus, buttons, a stack, and a scrolledhtml widget.
|
42 |
|
|
# Finally it loads help/index.html. This last step should change if
|
43 |
|
|
# this widget is ever used for anything but help.
|
44 |
|
|
# -----------------------------------------------------------------------------
|
45 |
|
|
body HtmlViewer::_buildwin {} {
|
46 |
|
|
global GDBTK_LIBRARY gdb_ImageDir
|
47 |
|
|
|
48 |
|
|
set _links [PageStack \#auto]
|
49 |
|
|
|
50 |
|
|
# create pulldown menu
|
51 |
|
|
set menu [menu $itk_interior.m -tearoff 0]
|
52 |
|
|
$menu add cascade -menu $menu.file -label "File" -underline 0
|
53 |
|
|
set _m [menu $menu.file]
|
54 |
|
|
$_m add command -label "Back" -underline 0 -command "$this back"
|
55 |
|
|
$_m add command -label "Forward" -underline 0 -command "$this forward"
|
56 |
|
|
$_m add command -label "Home" -underline 0 -command "$this link $file"
|
57 |
|
|
$_m add separator
|
58 |
|
|
$_m add command -label "Close" -underline 0 -command "delete object $this"
|
59 |
|
|
$menu add cascade -menu $menu.topic -label "Topics" -underline 0
|
60 |
|
|
set _t [menu $menu.topic]
|
61 |
|
|
foreach t $topics {
|
62 |
|
|
$_t add command -label [lindex $t 0] -command "$this link [lindex $t 1]"
|
63 |
|
|
}
|
64 |
|
|
[winfo toplevel $itk_interior] configure -menu $menu
|
65 |
|
|
|
66 |
|
|
# create buttons
|
67 |
|
|
set _f [frame $itk_interior.b]
|
68 |
|
|
button $_f.back -command "$this back" \
|
69 |
|
|
-image [image create photo -file [file join $gdb_ImageDir back.gif]]
|
70 |
|
|
button $_f.fore -command "$this forward" \
|
71 |
|
|
-image [image create photo -file [file join $gdb_ImageDir fore.gif]]
|
72 |
|
|
button $_f.home -command "$this link $file" \
|
73 |
|
|
-image [image create photo -file [file join $gdb_ImageDir home.gif]]
|
74 |
|
|
standard_toolbar $_f $_f.back $_f.fore $_f.home
|
75 |
|
|
|
76 |
|
|
_enable 0 back fore
|
77 |
|
|
|
78 |
|
|
# create html widget
|
79 |
|
|
set _html [iwidgets::scrolledhtml $itk_interior.a -linkcommand "$this link"]
|
80 |
|
|
|
81 |
|
|
# get things going by loading index.html
|
82 |
|
|
$_html import [file join $GDBTK_LIBRARY help $file]
|
83 |
|
|
$_links push $file
|
84 |
|
|
|
85 |
|
|
pack $_f -side top -fill x
|
86 |
|
|
pack $_html -expand yes -fill both
|
87 |
|
|
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
# -----------------------------------------------------------------------------
|
91 |
|
|
# NAME: public method PageStack::push
|
92 |
|
|
# SYNOPSIS: push val
|
93 |
|
|
# DESC: Pushes a value onto the stack.
|
94 |
|
|
# -----------------------------------------------------------------------------
|
95 |
|
|
body PageStack::push {val} {
|
96 |
|
|
incr _ptr
|
97 |
|
|
incr _max
|
98 |
|
|
if {$_ptr < $_max} {
|
99 |
|
|
set _max $_ptr
|
100 |
|
|
}
|
101 |
|
|
set _stack($_ptr) $val
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
# -----------------------------------------------------------------------------
|
105 |
|
|
# NAME: public method PageStack::back
|
106 |
|
|
# SYNOPSIS: back
|
107 |
|
|
# DESC: Moves the stack pointer back by one.
|
108 |
|
|
# RETURNS: Returns the value on the stack, or 0 on error.
|
109 |
|
|
# -----------------------------------------------------------------------------
|
110 |
|
|
body PageStack::back {} {
|
111 |
|
|
if {$_ptr > 0} {
|
112 |
|
|
incr _ptr -1
|
113 |
|
|
return $_stack($_ptr)
|
114 |
|
|
}
|
115 |
|
|
return 0
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
# -----------------------------------------------------------------------------
|
119 |
|
|
# NAME: public method PageStack::next
|
120 |
|
|
# SYNOPSIS: next
|
121 |
|
|
# DESC: Moves the stack pointer forward by one.
|
122 |
|
|
# RETURNS: Returns the value on the stack, or 0 on error.
|
123 |
|
|
# -----------------------------------------------------------------------------
|
124 |
|
|
body PageStack::next {} {
|
125 |
|
|
if {$_ptr < $_max} {
|
126 |
|
|
incr _ptr
|
127 |
|
|
return $_stack($_ptr)
|
128 |
|
|
}
|
129 |
|
|
return 0
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
# -----------------------------------------------------------------------------
|
133 |
|
|
# NAME: public method PageStack:more
|
134 |
|
|
# SYNOPSIS: more
|
135 |
|
|
# DESC: Indicates if the stack pointer is not at the top.
|
136 |
|
|
# RETURNS: Returns 1 if PageStack::next will suceed, 0 otherwise.
|
137 |
|
|
# -----------------------------------------------------------------------------
|
138 |
|
|
body PageStack::more {} {
|
139 |
|
|
if {$_ptr < $_max} {
|
140 |
|
|
return 1
|
141 |
|
|
}
|
142 |
|
|
return 0
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
# -----------------------------------------------------------------------------
|
146 |
|
|
# NAME: public method PageStack:less
|
147 |
|
|
# SYNOPSIS: less
|
148 |
|
|
# DESC: Indicates if the stack pointer is not at the bottom of stack.
|
149 |
|
|
# RETURNS: Returns 1 if PageStack::back will suceed, 0 otherwise.
|
150 |
|
|
# -----------------------------------------------------------------------------
|
151 |
|
|
body PageStack::less {} {
|
152 |
|
|
if {$_ptr > 0} {
|
153 |
|
|
return 1
|
154 |
|
|
}
|
155 |
|
|
return 0
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
# -----------------------------------------------------------------------------
|
159 |
|
|
# NAME: public method PageStack:current
|
160 |
|
|
# SYNOPSIS: current
|
161 |
|
|
# RETURNS: Returns the current value on the stack.
|
162 |
|
|
# -----------------------------------------------------------------------------
|
163 |
|
|
body PageStack::current {} {
|
164 |
|
|
if {$_ptr > 0} {
|
165 |
|
|
return $_stack($_ptr)
|
166 |
|
|
}
|
167 |
|
|
return 0
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
# ------------------------------------------------------------------------------
|
171 |
|
|
# NAME:
|
172 |
|
|
# private method HtmlViewer::_enable
|
173 |
|
|
#
|
174 |
|
|
# SYNOPSIS:
|
175 |
|
|
# _enable { on args }
|
176 |
|
|
#
|
177 |
|
|
# DESC:
|
178 |
|
|
# Enables or disables buttons and menus.
|
179 |
|
|
#
|
180 |
|
|
# ARGS:
|
181 |
|
|
# on - "1" to enable, "0" to disable
|
182 |
|
|
# args - things to enable/disable. May include "back",
|
183 |
|
|
# "fore", and "home"
|
184 |
|
|
#
|
185 |
|
|
# ------------------------------------------------------------------------------
|
186 |
|
|
body HtmlViewer::_enable { on args } {
|
187 |
|
|
if {$on} {
|
188 |
|
|
set state normal
|
189 |
|
|
} else {
|
190 |
|
|
set state disabled
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
foreach a $args {
|
194 |
|
|
switch $a {
|
195 |
|
|
back {
|
196 |
|
|
# set state of "back"
|
197 |
|
|
$_m entryconfigure 0 -state $state
|
198 |
|
|
$_f.back configure -state $state
|
199 |
|
|
}
|
200 |
|
|
fore {
|
201 |
|
|
# set state of "forward"
|
202 |
|
|
$_m entryconfigure 1 -state $state
|
203 |
|
|
$_f.fore configure -state $state
|
204 |
|
|
}
|
205 |
|
|
home {
|
206 |
|
|
# set state of "home"
|
207 |
|
|
$_m entryconfigure 2 -state $state
|
208 |
|
|
$_f.home configure -state $state
|
209 |
|
|
}
|
210 |
|
|
}
|
211 |
|
|
}
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
# ------------------------------------------------------------------------------
|
215 |
|
|
# NAME: public method HtmlViewer::back
|
216 |
|
|
# SYNOPSIS: back
|
217 |
|
|
# DESC: Moves to the previous page
|
218 |
|
|
# ------------------------------------------------------------------------------
|
219 |
|
|
body HtmlViewer::back {} {
|
220 |
|
|
set res [$_links back]
|
221 |
|
|
if {$res != 0} {
|
222 |
|
|
load $res
|
223 |
|
|
if {![$_links less]} {
|
224 |
|
|
_enable 0 back
|
225 |
|
|
}
|
226 |
|
|
}
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
# ------------------------------------------------------------------------------
|
230 |
|
|
# NAME: public method HtmlViewer::forward
|
231 |
|
|
# SYNOPSIS: forward
|
232 |
|
|
# DESC: Moves to the next page
|
233 |
|
|
# ------------------------------------------------------------------------------
|
234 |
|
|
body HtmlViewer::forward {} {
|
235 |
|
|
set res [$_links next]
|
236 |
|
|
if {$res != 0} {
|
237 |
|
|
load $res
|
238 |
|
|
if {![$_links more]} {
|
239 |
|
|
_enable 0 fore
|
240 |
|
|
}
|
241 |
|
|
}
|
242 |
|
|
}
|
243 |
|
|
|
244 |
|
|
# ------------------------------------------------------------------------------
|
245 |
|
|
# NAME: public method HtmlViewer::link
|
246 |
|
|
# SYNOPSIS: link page
|
247 |
|
|
# ARDS: page - link to the page to load
|
248 |
|
|
# DESC: Saves the page on the stack and calls the "load" method
|
249 |
|
|
# ------------------------------------------------------------------------------
|
250 |
|
|
body HtmlViewer::link {page} {
|
251 |
|
|
if {$page != [$_links current]} {
|
252 |
|
|
$_links push $page
|
253 |
|
|
load $page
|
254 |
|
|
if {![$_links more]} {
|
255 |
|
|
_enable 0 fore
|
256 |
|
|
}
|
257 |
|
|
}
|
258 |
|
|
}
|
259 |
|
|
|
260 |
|
|
# ------------------------------------------------------------------------------
|
261 |
|
|
# NAME: private method HtmlViewer::load
|
262 |
|
|
# SYNOPSIS: load link
|
263 |
|
|
# DESC: Disables menus and buttons, sets cursor, loads a page into
|
264 |
|
|
# the html widget, then resets cursor and enables the menus
|
265 |
|
|
# and buttons
|
266 |
|
|
# ------------------------------------------------------------------------------
|
267 |
|
|
body HtmlViewer::load {link} {
|
268 |
|
|
_enable 0 back fore home
|
269 |
|
|
$itk_interior configure -cursor watch
|
270 |
|
|
$_html import -link $link
|
271 |
|
|
$itk_interior configure -cursor ""
|
272 |
|
|
_enable 1 back fore home
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
# ------------------------------------------------------------------------------
|
276 |
|
|
# NAME: public proc HtmlViewer::open_help
|
277 |
|
|
# SYNOPSIS: HtmlViewer::open_help file
|
278 |
|
|
# DESC: If the prefs are set to use a browser, attempts
|
279 |
|
|
# to do so. Otherwise, uses builtin HtmlViewer class.
|
280 |
|
|
# ------------------------------------------------------------------------------
|
281 |
|
|
body HtmlViewer::open_help {hfile} {
|
282 |
|
|
set link file://[file join $::GDBTK_LIBRARY help $hfile]
|
283 |
|
|
if {![pref get gdb/help/browser] || ![::open_url $link]} {
|
284 |
|
|
ManagedWin::open HtmlViewer -file $hfile
|
285 |
|
|
}
|
286 |
|
|
}
|