annotate lisp/w3/w3-widget.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; w3-widget.el,v --- An image widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Author: wmperry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Created: 1996/05/29 03:11:24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Version: 1.14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: faces, help, comm, news, mail, processes, mouse, hypermedia
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; Copyright (c) 1993, 1994, 1995 by William M. Perry (wmperry@spry.com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; This file is not part of GNU Emacs, but the same permissions apply.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; This is a widget that will do the best it can with an image.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; It can handle all the common occurences of images on the world wide web
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; 1. A plain image - displays either a glyph of the image, or the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; alternative text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; 2. A hyperlinked image - an image that is also a hypertext link to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; another page. Displays either a glyph of the image, or the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; alternative text. When activated with the mouse or the keyboard,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; the 'href' property of the widget is retrieved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; 3. Server side imagemaps - an image that has hotzones that lead to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; different areas. Unfortunately, we cannot tell where the links go
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; from the client - all processing is done by the server. Displays
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; either a glyph of the image, or the alternative text. When activated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; with the mouse or the keyboard, the coordinates clicked on are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; sent to the remote server as HREF?x,y. If the link is activated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; by the keyboard, then 0,0 are sent as the coordinates.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; 4. Client side imagemaps - an image that has hotzones that lead to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; different areas. All processing is done on the client side, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; we can actually show a decent representation on a TTY. Displays
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; either a glyph of the image, or a drop-down-list of the destinations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; These are either URLs (http://foo/...) or alternative text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (require 'cl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (require 'widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (require 'w3-vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (require 'w3-mouse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defvar w3-image-widget-keymap (make-sparse-keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 "Keymap used over glyphs in an image widget")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (define-key w3-image-widget-keymap (vector w3-mouse-button1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 'w3-image-widget-button-press)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (define-key w3-image-widget-keymap (vector w3-mouse-button2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 'w3-image-widget-button-press)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (define-widget 'image 'default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "A fairly complex image widget."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 :convert-widget 'w3-image-widget-convert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 :value-to-internal (lambda (widget value) value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 :value-to-external (lambda (widget value) value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 :value-set 'w3-image-widget-value-set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 :create 'w3-image-widget-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 :delete 'w3-image-widget-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 :value-create 'w3-image-widget-value-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 :value-delete 'w3-image-widget-value-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 :value-get 'w3-image-widget-value-get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 :notify 'w3-image-widget-notify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (defun w3-image-widget-convert (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (let ((args (widget-get widget :args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (widget-put widget :args nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (widget-put widget (car args) (cadr args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (setq args (cddr args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (defun w3-image-widget-value-get (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (let ((children (widget-get widget :children)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (and (car children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (widget-apply (car children) :value-get))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (defun w3-image-widget-create (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; Create an image widget at point in the current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (let ((where (widget-get widget 'where)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ((null where)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (setq where (set-marker (make-marker) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ((markerp where)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ((integerp where)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq where (set-marker (make-marker) where)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (error "IMPOSSIBLE position in w3-image-widget-create: %s" where)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (widget-put widget 'where where))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (w3-image-widget-value-create widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defun w3-image-widget-value-set (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; Recreate widget with new value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (w3-image-widget-delete widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (if (w3-glyphp value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (widget-put widget 'glyph value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (widget-put widget :value value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (widget-apply widget :create)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (defsubst w3-image-widget-usemap (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (let ((usemap (widget-get widget 'usemap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (if (listp usemap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 usemap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (if (and usemap (string-match "^#" usemap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (setq usemap (substring usemap 1 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (cdr-safe (assoc usemap w3-imagemaps)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (defun w3-image-widget-callback (widget widget-ignore &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (and (widget-get widget 'href) (w3-fetch (widget-get widget 'href))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defun w3-image-widget-value-create (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;; Insert the printed representation of the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (let (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (href (widget-get widget 'href))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (server-map (widget-get widget 'ismap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (client-map (w3-image-widget-usemap widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (where (or (widget-get widget 'where) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (glyph (widget-get widget 'glyph))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (alt (widget-get widget 'alt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (real-widget nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (invalid-glyph nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; Specifier-instance will signal an error if we have an invalid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; image specifier, which would be the case if we get screwed up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; data back from a URL somewhere.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (setq invalid-glyph (and glyph (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (if (specifier-instance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (glyph-image glyph))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (error t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (if (or (not glyph) invalid-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; Do a TTY or delayed image version of the image.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (if (= 0 (length alt)) (setq alt nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (goto-char where)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (client-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (let* ((default nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (options (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (if (eq (aref x 0) 'default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (setq default (aref x 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (if (and (not default) (stringp (aref x 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (setq default (aref x 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (list 'choice-item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 :format "%[%t%]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 :tag (or (aref x 3) (aref x 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 :value (aref x 2)))) client-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (setq real-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (apply 'widget-create 'choice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 :tag (or (widget-get widget :tag) "Imagemap")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 :notify (widget-get widget :notify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 :value default options))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ((and server-map (stringp href))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (setq real-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (widget-create 'push :tag alt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 :delete 'widget-default-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 :value href
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 :notify (widget-get widget :notify))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (href
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (setq real-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (widget-create 'push :tag (or alt "Image")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 :value href
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 :delete 'widget-default-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 :notify 'w3-image-widget-callback)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (alt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (setq real-widget (widget-create 'item :format "%v" :value alt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if (not real-widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (widget-put real-widget 'usemap (widget-get widget 'usemap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (widget-put real-widget 'href href)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (widget-put real-widget 'ismap server-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (widget-put real-widget :parent widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (widget-put widget :children (list real-widget))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;;; Actually use the image
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (let ((extent (or (widget-get widget 'extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (make-extent where where))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (set-extent-endpoints extent where where)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (widget-put widget 'extent extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (widget-put widget :children nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (set-extent-property extent 'keymap w3-image-widget-keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (set-extent-property extent 'begin-glyph glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (set-extent-property extent 'help-echo (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ((and href (or client-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 server-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (format "%s [map]" href))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (href href)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (set-glyph-property glyph 'widget widget)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (defun w3-image-widget-delete (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; Remove the widget from the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (let ((extent (widget-get widget 'extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (child (car (widget-get widget :children))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (extent ; Remove a glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (delete-extent extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (child ; Remove a child widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (widget-apply child :delete))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (t ; Doh! Do nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (if (fboundp 'mouse-event-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (fset 'w3-mouse-event-p 'mouse-event-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (fset 'w3-mouse-event-p 'ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (if (fboundp 'glyphp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (fset 'w3-glyphp 'glyphp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (fset 'w3-glyphp 'ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (defun w3-image-widget-button-press (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (interactive "@e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (let* ((glyph (and event (w3-mouse-event-p event) (event-glyph event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (widget (and glyph (glyph-property glyph 'widget))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (w3-image-widget-notify widget widget event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (defun w3-image-widget-notify (widget widget-changed &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;; Happens when anything changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (let* ((glyph (and event (w3-mouse-event-p event) (event-glyph event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (x (and glyph (event-glyph-x-pixel event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (y (and glyph (event-glyph-y-pixel event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (ismap (widget-get widget 'ismap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (usemap (w3-image-widget-usemap widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (href (widget-get widget 'href))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (value (widget-value widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ((and glyph usemap) ; Do the client-side imagemap stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (setq href (w3-point-in-map (vector x y) usemap nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (if href
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (w3-fetch href)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (message "No destination found for %d,%d" x y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ((and glyph x y ismap) ; Do the server-side imagemap stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (w3-fetch (format "%s?%d,%d" href x y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (usemap ; Dummed-down tty client side imap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (w3-fetch value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (ismap ; Do server-side dummy imagemap for tty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (w3-fetch (concat href "?0,0")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ((stringp href) ; Normal hyperlink
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (w3-fetch href))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (t ; Huh?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (provide 'w3-widget)