1 ;;; w3-toolbar.el --- Toolbar functions for emacs-w3
2 ;; Author: William M. Perry <wmperry@gnu.org>
3 ;; Created: $Date: 2001/07/19 14:15:52 $
4 ;; Version: $Revision: 1.8 $
5 ;; Keywords: mouse, toolbar
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;; Copyright (c) 1995, 1996 by William M. Perry <wmperry@cs.indiana.edu>
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
11 ;;; This file is part of GNU Emacs.
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;;; it under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 2, or (at your option)
16 ;;; any later version.
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;;; GNU General Public License for more details.
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;;; Boston, MA 02111-1307, USA.
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;;; Toolbar specific function for XEmacs and Emacs 21
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 (require 'xbm-button))
38 (defvar w3-toolbar-icon-directory nil
39 "Where the toolbar icons for W3 are.
40 In Emacs, this is searched preferentially to the normal search path.")
41 (defvar w3-toolbar-back-icon (if (featurep 'tool-bar)
43 "Toolbar icon for back")
44 (defvar w3-toolbar-forw-icon (if (featurep 'tool-bar)
46 "Toolbar icon for forward")
47 (defvar w3-toolbar-home-icon (if (featurep 'tool-bar)
49 "Toolbar icon for home")
50 (defvar w3-toolbar-reld-icon (if (featurep 'tool-bar)
52 "Toolbar icon for reload")
53 (defvar w3-toolbar-imag-icon (if (featurep 'tool-bar)
55 "Toolbar icon for images")
56 (defvar w3-toolbar-open-icon (if (featurep 'tool-bar)
58 "Toolbar icon for open url")
59 (defvar w3-toolbar-print-icon (if (featurep 'tool-bar)
61 "Toolbar icon for printing")
62 (defvar w3-toolbar-find-icon (if (featurep 'tool-bar)
64 "Toolbar icon for find")
65 (defvar w3-toolbar-stop-icon (if (featurep 'tool-bar)
67 "Toolbar icon for stop")
68 (defvar w3-toolbar-help-icon (if (featurep 'tool-bar)
70 "Toolbar icon for help")
71 (defvar w3-toolbar-hotl-icon (if (featurep 'tool-bar)
73 "Toolbar icon for hotlist")
74 (defvar w3-toolbar-file-icon (if (featurep 'tool-bar)
76 "Toolbar icon for open url")
77 (defvar w3-toolbar-printer-icon (if (featurep 'tool-bar)
79 "Toolbar icon for open url")
81 (defvar w3-link-toolbar-orientation 'bottom
82 "*Where to put the document specific toolbar. Must be one of these symbols:
84 default -- place at location specified by `default-toolbar-position'
85 top -- place along the top of the frame
86 bottom -- place along the bottom of the frame
87 right -- place along the right edge of the frame
88 left -- place along the left edge of the frame
91 (defvar w3-toolbar-orientation 'default
92 "*Where to put the w3 toolbar. Must be one of these symbols:
94 default -- place at location specified by `default-toolbar-position'
95 top -- place along the top of the frame
96 bottom -- place along the bottom of the frame
97 right -- place along the right edge of the frame
98 left -- place along the left edge of the frame
101 (defvar w3-toolbar-type 'both
102 "*What the toolbar looks like. Must be one of these symbols:
104 pictures -- Show icons (without captions if in XEmacs 19.13)
105 both -- Show icons (with captions if in XEmacs 19.13)
106 text -- Show only text buttons
108 Only has any meaning in XEmacs 19.12 when w3-toolbar-orientation is
112 '([w3-toolbar-back-icon w3-history-backward (car (w3-history-find-url-internal (url-view-url t))) "Back in history"]
113 [w3-toolbar-forw-icon w3-history-forward (cdr (w3-history-find-url-internal (url-view-url t))) "Forward in history"]
114 [w3-toolbar-home-icon w3 t "Go home"]
116 [w3-toolbar-reld-icon w3-reload-document t "Reload document"]
117 [w3-toolbar-hotl-icon w3-hotlist-view t "View hotlist"]
118 [w3-toolbar-imag-icon w3-load-delayed-images w3-delayed-images
120 [toolbar-file-icon w3-fetch t "Fetch a URL"]
121 [toolbar-printer-icon w3-mouse-print-this-url t "Print document"]
122 [w3-toolbar-find-icon w3-search-forward t "Search"]
123 ;;[w3-toolbar-stop-icon keyboard-quit t "Stop transaction"]
125 [w3-toolbar-help-icon w3-show-info-node t "Help"])
126 "The toolbar for w3")
128 (defun w3-toolbar-make-captioned-buttons ()
132 (let* ((ext (if (featurep 'xpm) ".xpm" ".xbm"))
133 (base w3-toolbar-icon-directory)
134 (up (expand-file-name (concat x "-up" ext) base))
135 (dn (expand-file-name (concat x "-dn" ext) base))
136 (no (expand-file-name (concat x "-no" ext) base))
137 (cap-up (expand-file-name (concat x "-cap-up" ext) base))
138 (cap-dn (expand-file-name (concat x "-cap-dn" ext) base))
139 (cap-no (expand-file-name (concat x "-cap-no" ext) base))
140 (var (intern (concat "w3-toolbar-" x "-icon"))))
142 (toolbar-make-button-list up dn no cap-up cap-dn cap-no)))))
144 '("back" "help" "find" "forw" "home" "hotl" "stop" "imag" "reld")))
146 (defun w3-make-text-toolbar-button (text)
148 (cdr-safe (assq 'background-toolbar-color (frame-parameters)))
151 (mapcar 'make-glyph (xpm-button-create text 0 "black" bgcol))
152 (xbm-button-create text 0))))
154 (defun w3-toolbar-make-text-buttons ()
155 (let ((bgcol (or (cdr-safe (assq 'background-toolbar-color
158 (setq w3-toolbar-back-icon (w3-make-text-toolbar-button "Back")
159 w3-toolbar-forw-icon (w3-make-text-toolbar-button "Forward")
160 w3-toolbar-home-icon (w3-make-text-toolbar-button "Home")
161 w3-toolbar-reld-icon (w3-make-text-toolbar-button "Reload")
162 w3-toolbar-hotl-icon (w3-make-text-toolbar-button "Hotlist")
163 w3-toolbar-imag-icon (w3-make-text-toolbar-button "Images")
164 w3-toolbar-open-icon (w3-make-text-toolbar-button "Open")
165 w3-toolbar-print-icon (w3-make-text-toolbar-button "Print")
166 w3-toolbar-find-icon (w3-make-text-toolbar-button "Find")
167 w3-toolbar-help-icon (w3-make-text-toolbar-button "Help!"))))
169 (defun w3-toolbar-make-picture-buttons ()
173 (let* ((ext (if (featurep 'xpm) ".xpm" ".xbm"))
174 (base w3-toolbar-icon-directory)
175 (up (expand-file-name (concat x "-cap-up" ext) base))
176 (dn (expand-file-name (concat x "-cap-dn" ext) base))
177 (no (expand-file-name (concat x "-cap-no" ext) base))
178 (var (intern (concat "w3-toolbar-" x "-icon"))))
181 ((and (file-exists-p up) (file-exists-p dn)
183 (toolbar-make-button-list up dn no))
185 (toolbar-make-button-list up))
187 '("back" "help" "find" "forw" "home" "hotl" "imag" "reld")))
189 (defun w3-toolbar-make-buttons ()
190 (if (not w3-toolbar-icon-directory)
191 (setq w3-toolbar-icon-directory
192 (if (fboundp 'locate-data-directory)
193 (locate-data-directory "w3")
194 (file-name-as-directory
195 (expand-file-name "w3" data-directory)))))
198 ((not (fboundp 'toolbar-make-button-list))
200 ((or (eq w3-toolbar-type 'text)
201 (null w3-toolbar-icon-directory)
202 (not (file-directory-p w3-toolbar-icon-directory)))
203 (w3-toolbar-make-text-buttons))
204 ((boundp 'toolbar-buttons-captioned-p)
205 (w3-toolbar-make-captioned-buttons))
206 ((featurep 'tool-bar)
208 ;; Fixme: Redundant? XEmacs versions supported have captioned
211 (w3-toolbar-make-picture-buttons)))
214 (defun w3-link-is-defined (rel &optional rev)
216 (cdr-safe (assoc rel (cdr-safe (assq 'rel w3-current-links))))
217 (cdr-safe (assoc (or rev rel) (cdr-safe (assq 'rev w3-current-links))))))
219 ;; Need to create w3-toolbar-glos-icon
220 ;; w3-toolbar-toc-icon
221 ;; w3-toolbar-copy-icon
222 (defvar w3-link-toolbar
223 '([info::toolbar-prev-icon
224 (w3-fetch (w3-link-is-defined "previous" "next"))
225 (w3-link-is-defined "previous" "next")
227 [info::toolbar-next-icon
228 (w3-fetch (w3-link-is-defined "next" "previous"))
229 (w3-link-is-defined "next" "previous")
231 [info::toolbar-up-icon
232 (w3-fetch (w3-link-is-defined "up" "down"))
233 (w3-link-is-defined "up" "down")
235 [w3-toolbar-home-icon
236 (w3-fetch (w3-link-is-defined "home"))
237 (w3-link-is-defined "home")
240 (w3-fetch (w3-link-is-defined "toc"))
241 (w3-link-is-defined "toc")
243 [w3-toolbar-find-icon
244 (w3-fetch (w3-link-is-defined "index"))
245 (w3-link-is-defined "index")
247 [w3-toolbar-glos-icon
248 (w3-fetch (w3-link-is-defined "glossary"))
249 (w3-link-is-defined "glossary")
251 [w3-toolbar-copy-icon
252 (w3-fetch (w3-link-is-defined "copyright"))
253 (w3-link-is-defined "copyright")
255 [w3-toolbar-hotl-icon
256 (w3-fetch (w3-link-is-defined "bookmark"))
257 (w3-link-is-defined "bookmark")
260 [w3-toolbar-help-icon
261 (w3-fetch (w3-link-is-defined "help"))
262 (w3-link-is-defined "help")
266 (defun w3-toolbar-from-orientation (orientation)
268 ((eq 'default w3-toolbar-orientation) default-toolbar)
269 ((eq 'bottom w3-toolbar-orientation) bottom-toolbar)
270 ((eq 'top w3-toolbar-orientation) top-toolbar)
271 ((eq 'left w3-toolbar-orientation) left-toolbar)
272 ((eq 'right w3-toolbar-orientation) right-toolbar)))
274 (defun w3-toolbar-dimension-from-orientation (orientation)
276 ((eq 'default w3-toolbar-orientation) nil)
277 ((eq 'bottom w3-toolbar-orientation) bottom-toolbar-height)
278 ((eq 'top w3-toolbar-orientation) top-toolbar-height)
279 ((eq 'left w3-toolbar-orientation) left-toolbar-width)
280 ((eq 'right w3-toolbar-orientation) right-toolbar-width)))
282 (defun w3-ensure-toolbar-visible (orientation)
283 ;; Make sure a certain toolbar is visible if necessary
284 ;; This can modify frame parameters, so watch out.
285 (let ((dimension (w3-toolbar-dimension-from-orientation orientation))
286 (toolbar (w3-toolbar-from-orientation orientation))
292 (if (and dimension toolbar
293 (setq toolbar (specifier-instance toolbar)))
295 (setq dimensions (mapcar
299 (cons (glyph-width glyph)
300 (glyph-height glyph)))))
304 (function (lambda (x)
309 widths (sort (mapcar 'car dimensions) '>=)
310 heights (sort (mapcar 'cdr dimensions) '>=)
311 needs (+ 7 (if (memq orientation '(top bottom))
314 has (specifier-instance dimension))
316 (set-specifier dimension (cons (selected-frame) needs)))))))
318 (defun w3-toolbar-active ()
320 (let ((toolbar (w3-toolbar-from-orientation w3-toolbar-orientation)))
321 (if (and toolbar (specifier-instance toolbar))
325 (defun w3-toggle-link-toolbar ()
327 (require 'info) ; For some toolbar buttons
328 (let* ((w3-toolbar-orientation w3-link-toolbar-orientation)
329 (toolbar (w3-toolbar-from-orientation w3-toolbar-orientation)))
331 (if (w3-toolbar-active)
332 (set-specifier toolbar (cons (current-buffer) nil))
333 (set-specifier toolbar w3-link-toolbar (current-buffer))))))
335 (defun w3-toggle-toolbar ()
337 (if (eq major-mode 'w3-mode)
338 (let ((toolbar (w3-toolbar-from-orientation w3-toolbar-orientation)))
341 (set-specifier toolbar (cons (current-buffer) nil)))
343 (set-specifier toolbar (cons (current-buffer) w3-toolbar)))
345 (setq w3-toolbar-orientation 'default
346 toolbar (w3-toolbar-from-orientation w3-toolbar-orientation))
348 (set-specifier toolbar (cons (current-buffer) w3-toolbar))))))
349 (if (not (eq w3-toolbar-orientation 'none))
350 (setq w3-toolbar-orientation 'none)
351 (setq w3-toolbar-orientation 'default))))
353 (defun w3-show-info-node ()
355 (Info-goto-node "(w3.info)Top"))
357 (defun w3-mouse-print-this-url (&optional e)
359 (let ((descr '("Print document as"
360 ["PostScript" (w3-print-this-url nil "PostScript") t]
361 ["Formatted Text" (w3-print-this-url nil "Formatted Text") t]
362 ["HTML Source" (w3-print-this-url nil "HTML Source") t]
364 ["Cancel" (beep) t])))
365 (popup-dialog-box descr)))
367 (defvar w3-toolbar-map
368 (if (and (featurep 'tool-bar)
369 (display-graphic-p)) ; would lose on tty
371 (if (not w3-toolbar-icon-directory)
372 (setq w3-toolbar-icon-directory
373 (file-name-as-directory
374 (expand-file-name "w3" data-directory))))
375 (let ((tool-bar-map (make-sparse-keymap))
376 ;; Add to normal image search path:
377 (load-path (cons w3-toolbar-icon-directory load-path)))
378 (dolist (desc w3-toolbar)
380 (let ((sym (aref desc 0)))
381 ;; w3-toolbar contains `toolbar-' symbols as well as
384 (setq sym (intern (format "w3-%s" sym))))
385 (if (and desc (not (keywordp (aref desc 0))))
386 (tool-bar-add-item (symbol-value sym) ; image
387 (aref desc 1) ; binding
388 (intern (aref desc 3)) ; key
390 :enable (aref desc 2))))))
393 (defun w3-add-toolbar-to-buffer ()
395 ((featurep 'infodock)
396 ;; Infodock handles toolbars differently
399 ;; XEmacs way of doing things
400 (let ((toolbar (w3-toolbar-from-orientation w3-toolbar-orientation)))
402 (set-specifier toolbar (cons (current-buffer) w3-toolbar))))
403 (set-specifier toolbar-buttons-captioned-p
404 (cons (current-buffer) (eq w3-toolbar-type 'both))))
405 ((and (featurep 'tool-bar)
407 (> (frame-parameter nil 'tool-bar-lines) 0))
408 ;; Emacs 21.x way of doing things
409 (set (make-local-variable 'tool-bar-map) w3-toolbar-map))
413 (provide 'w3-toolbar)