0
|
1 ;;; Balloon help for XEmacs (requires 19.12 or later)
|
22
|
2 ;;; Copyright (C) 1995, 1997 Kyle E. Jones
|
0
|
3 ;;;
|
|
4 ;;; This program is free software; you can redistribute it and/or modify
|
|
5 ;;; it under the terms of the GNU General Public License as published by
|
|
6 ;;; the Free Software Foundation; either version 1, or (at your option)
|
|
7 ;;; 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 ;;; A copy of the GNU General Public License can be obtained from this
|
|
15 ;;; program's author (send electronic mail to kyle@uunet.uu.net) or from
|
|
16 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
|
|
17 ;;; 02139, USA.
|
|
18 ;;;
|
|
19 ;;; Send bug reports to kyle@wonderworks.com
|
|
20
|
|
21 ;; Balloon help pops up a small frame to display help text
|
|
22 ;; relating to objects that the mouse cursor passes over.
|
|
23 ;;
|
|
24 ;; Installation:
|
|
25 ;;
|
|
26 ;; Byte-compile the file balloon-help.el (with M-x byte-compile-file)
|
|
27 ;; and put the .elc file in a directory in your load-path. Add the
|
|
28 ;; following line to your .emacs:
|
|
29 ;;
|
|
30 ;; (require 'balloon-help)
|
|
31 ;;
|
|
32 ;; For 19.12 users:
|
|
33 ;; If you are using fvwm, [tv]twm or ol[v]wm, you can also add
|
|
34 ;; the following lines to various configuration file to use
|
|
35 ;; minimal decorations on the balloon help frames.
|
|
36 ;;
|
|
37 ;; In .emacs:
|
|
38 ;; (setq balloon-help-frame-name "balloon-help")
|
|
39 ;;
|
|
40 ;; For ol[v]wm use this in .Xdefaults:
|
|
41 ;; olvwm.NoDecor: balloon-help
|
|
42 ;; or
|
|
43 ;; olwm.MinimalDecor: balloon-help
|
|
44 ;;
|
|
45 ;; For fvvm use this in your .fvwmrc:
|
|
46 ;; NoTitle balloon-help
|
|
47 ;; or
|
|
48 ;; Style "balloon-help" NoTitle, NoHandles, BorderWidth 0
|
|
49 ;;
|
|
50 ;; For twm use this in your .twmrc:
|
|
51 ;; NoTitle { "balloon-help" }
|
|
52 ;;
|
|
53 ;; Under 19.13 and later versions the balloon-help frame uses a
|
|
54 ;; transient window that is not normally decorated by window
|
|
55 ;; managers. So the window manager directives should not be
|
|
56 ;; needed for XEmacs 19.13 and beyond.
|
|
57
|
|
58 (provide 'balloon-help)
|
|
59
|
36
|
60 (defvar balloon-help-version "1.05"
|
0
|
61 "Version string for Balloon Help.")
|
|
62
|
|
63 (defvar balloon-help-mode t
|
|
64 "*Non-nil means Balloon help mode is enabled.")
|
|
65
|
|
66 (defvar balloon-help-timeout 1500
|
|
67 "*Display help after this many milliseconds of mouse inactivity.")
|
|
68
|
|
69 (defvar balloon-help-foreground "black"
|
|
70 "*The foreground color for displaying balloon help text.")
|
|
71
|
|
72 (defvar balloon-help-background "rgb:c0/c0/c0"
|
|
73 "*The background color for the balloon help frame.")
|
|
74
|
|
75 (defvar balloon-help-background-pixmap ""
|
|
76 "*The background pixmap for the balloon help frame.")
|
|
77
|
|
78 (defvar balloon-help-font "fixed"
|
|
79 "*The font for displaying balloon help text.")
|
|
80
|
|
81 (defvar balloon-help-border-color "black"
|
|
82 "*The color for displaying balloon help frame's border.")
|
|
83
|
26
|
84 (defvar balloon-help-border-width 2
|
|
85 "*The width of the balloon help frame's border.")
|
|
86
|
0
|
87 (defvar balloon-help-use-sound nil
|
|
88 "*Non-nil value means play a sound to herald the appearance
|
|
89 and disappearance of the help frame.
|
|
90
|
|
91 `balloon-help-appears' will be played when the frame appears.
|
|
92 `balloon-help-disappears' will be played when the frame disappears.
|
|
93
|
|
94 See the documentation for the function load-sound-file to see how
|
|
95 define sounds.")
|
|
96
|
|
97 (defvar balloon-help-frame-name nil
|
|
98 "*The frame name to use for the frame to display the balloon help.")
|
|
99
|
22
|
100 (defvar balloon-help-aggressively-follow-mouse nil
|
|
101 "*Non-nil means the balloon should move with the mouse even if the mouse
|
|
102 is over the same object as the last mouse motion event.")
|
|
103
|
0
|
104 ;;;
|
|
105 ;;; End of user variables.
|
|
106 ;;;
|
|
107
|
|
108 (defvar mouse-motion-hook mouse-motion-handler
|
|
109 "Hooks to be run whenever the user moves the mouse.
|
|
110 Each hook is called with one argument, the mouse motion event.")
|
|
111
|
|
112 (defun mouse-motion-hook (event)
|
|
113 "Run the hooks attached to mouse-motion-hook."
|
|
114 (run-hook-with-args 'mouse-motion-hook event))
|
|
115
|
|
116 (setq mouse-motion-handler 'mouse-motion-hook)
|
|
117
|
|
118 (defvar balloon-help-frame nil
|
|
119 "Balloon help is displayed in this frame.")
|
|
120
|
|
121 (defvar balloon-help-help-object nil
|
|
122 "Object that the mouse is over that has a help property, nil otherwise.")
|
|
123
|
|
124 (defvar balloon-help-help-object-x nil
|
|
125 "Last horizontal mouse position over balloon-help-help-object.")
|
|
126
|
|
127 (defvar balloon-help-help-object-y nil
|
|
128 "Last vertical mouse position over balloon-help-help-object.")
|
|
129
|
|
130 (defvar balloon-help-buffer nil
|
|
131 "Buffer used to display balloon help.")
|
|
132
|
|
133 (defvar balloon-help-timeout-id nil
|
|
134 "Timeout id for the balloon help timeout.")
|
|
135
|
|
136 (defvar balloon-help-display-pending nil
|
|
137 "Non-nil value means the help frame will be visible as soon
|
|
138 as the X server gets around to displaying it. Nil means it
|
|
139 will be invisible as soon as the X server decides to hide it.")
|
|
140
|
|
141 (defun balloon-help-mode (&optional arg)
|
|
142 "Toggle Balloon Help mode.
|
|
143 With arg, turn Balloon Help mode on iff arg is positive.
|
|
144
|
|
145 With Balloon Help enabled, a small frame is displayed whenever
|
|
146 the mouse rests on an object that has a help property of some
|
|
147 kind. The text of that help property is displayed in the frame.
|
|
148
|
|
149 For extents, the 'balloon-help' property is
|
|
150 checked.
|
|
151
|
|
152 For toolbar buttons, the help-string slot of the toolbar button
|
|
153 is checked.
|
|
154
|
|
155 If the value is a string, it is used as the help message.
|
|
156
|
|
157 If the property's value is a symbol, it is assumed to be the name
|
|
158 of a function and it will be called with one argument, the object
|
|
159 under the mouse, and the return value of that function will be
|
|
160 used as the help message."
|
|
161 (interactive "P")
|
|
162 (setq balloon-help-mode (or (and arg (> (prefix-numeric-value arg) 0))
|
|
163 (and (null arg) (null balloon-help-mode))))
|
|
164 (if (null balloon-help-mode)
|
|
165 (balloon-help-undisplay-help)))
|
|
166
|
|
167 (defun balloon-help-displayed ()
|
|
168 (and (frame-live-p balloon-help-frame)
|
|
169 (frame-visible-p balloon-help-frame)))
|
|
170
|
|
171 (defun balloon-help-motion-hook (event)
|
|
172 (cond
|
|
173 ((null balloon-help-mode) t)
|
|
174 ((button-press-event-p event)
|
|
175 (setq balloon-help-help-object nil)
|
|
176 (if balloon-help-timeout-id
|
|
177 (disable-timeout balloon-help-timeout-id))
|
|
178 (if (balloon-help-displayed)
|
|
179 (balloon-help-undisplay-help)))
|
|
180 (t
|
|
181 (let* ((buffer (event-buffer event))
|
|
182 (frame (event-frame event))
|
|
183 (point (and buffer (event-point event)))
|
36
|
184 (modeline-point (and buffer (event-modeline-position event)))
|
|
185 (modeline-extent (and modeline-point
|
|
186 (map-extents
|
|
187 (function (lambda (e ignored) e))
|
|
188 (symbol-value-in-buffer
|
|
189 'generated-modeline-string
|
|
190 buffer)
|
|
191 modeline-point modeline-point
|
|
192 nil nil
|
|
193 'balloon-help)))
|
0
|
194 (glyph-extent (event-glyph-extent event))
|
|
195 (glyph-extent (if (and glyph-extent
|
|
196 (extent-property glyph-extent
|
|
197 'balloon-help))
|
|
198 glyph-extent))
|
|
199 (extent (and point
|
|
200 (extent-at point buffer 'balloon-help)))
|
|
201 (button (event-toolbar-button event))
|
|
202 (button (if (and button (toolbar-button-help-string button))
|
|
203 button
|
|
204 nil))
|
36
|
205 (object (or modeline-extent glyph-extent extent button))
|
0
|
206 (id balloon-help-timeout-id))
|
|
207 (if (null object)
|
|
208 (if (and balloon-help-frame
|
|
209 (not (eq frame balloon-help-frame)))
|
|
210 (progn
|
|
211 (setq balloon-help-help-object nil)
|
|
212 (if id
|
|
213 (disable-timeout id))
|
|
214 (if (balloon-help-displayed)
|
|
215 (balloon-help-undisplay-help))))
|
|
216 (let* ((params (frame-parameters frame))
|
|
217 (top (cdr (assq 'top params)))
|
|
218 (left (cdr (assq 'left params)))
|
|
219 (xtop-toolbar-height
|
26
|
220 (if (and (specifier-instance top-toolbar-visible-p frame)
|
|
221 (specifier-instance top-toolbar frame))
|
|
222 (specifier-instance top-toolbar-height frame)
|
0
|
223 0))
|
|
224 (xleft-toolbar-width
|
26
|
225 (if (and (specifier-instance left-toolbar-visible-p frame)
|
|
226 (specifier-instance left-toolbar frame))
|
|
227 (specifier-instance left-toolbar-width frame)
|
0
|
228 0))
|
26
|
229 (menubar-height
|
|
230 (if (and buffer
|
|
231 (specifier-instance menubar-visible-p)
|
|
232 (save-excursion (set-buffer buffer) current-menubar))
|
|
233 22 0)))
|
0
|
234 (setq balloon-help-help-object-x
|
|
235 (+ left xleft-toolbar-width (event-x-pixel event))
|
|
236 balloon-help-help-object-y
|
|
237 (+ top xtop-toolbar-height menubar-height
|
|
238 (event-y-pixel event))))
|
|
239 (cond ((eq frame balloon-help-frame) t)
|
|
240 ((eq object balloon-help-help-object)
|
22
|
241 (if (and (balloon-help-displayed)
|
|
242 balloon-help-aggressively-follow-mouse)
|
0
|
243 (balloon-help-move-help-frame)))
|
|
244 ((balloon-help-displayed)
|
|
245 (setq balloon-help-help-object object)
|
|
246 (balloon-help-display-help))
|
|
247 (t
|
|
248 (setq balloon-help-help-object object)
|
|
249 (if id
|
|
250 (disable-timeout id))
|
|
251 (setq balloon-help-timeout-id
|
|
252 (add-timeout (/ balloon-help-timeout 1000.0)
|
|
253 (function balloon-help-display-help)
|
|
254 nil)))))))))
|
|
255
|
|
256 (defun balloon-help-pre-command-hook (&rest ignored)
|
|
257 (setq balloon-help-help-object nil)
|
|
258 (if (balloon-help-displayed)
|
|
259 (balloon-help-undisplay-help)))
|
|
260
|
|
261 (fset 'balloon-help-post-command-hook 'balloon-help-pre-command-hook)
|
|
262 (fset 'balloon-help-mouse-leave-frame-hook 'balloon-help-pre-command-hook)
|
|
263 (fset 'balloon-help-deselect-frame-hook 'balloon-help-pre-command-hook)
|
|
264
|
|
265 (defun balloon-help-display-help (&rest ignored)
|
|
266 (setq balloon-help-timeout-id nil)
|
|
267 (if balloon-help-help-object
|
|
268 (let* ((object balloon-help-help-object)
|
|
269 (help (or (and (extent-live-p object)
|
|
270 (extent-property object 'balloon-help))
|
|
271 (and (toolbar-button-p object)
|
|
272 (toolbar-button-help-string object))
|
|
273 (and (stringp object) object))))
|
|
274 ;; if help is non-null and is not a string, run it as
|
|
275 ;; function to produuce the help string.
|
|
276 (if (or (null help) (not (symbolp help)))
|
|
277 nil
|
|
278 (condition-case data
|
|
279 (setq help (funcall help object))
|
|
280 (error
|
|
281 (setq help (format "help function signaled: %S" data)))))
|
|
282 (if (stringp help)
|
|
283 (save-excursion
|
|
284 (if (not (bufferp balloon-help-buffer))
|
|
285 (setq balloon-help-buffer
|
|
286 (get-buffer-create " *balloon-help*")))
|
|
287 (if (not (frame-live-p balloon-help-frame))
|
|
288 (setq balloon-help-frame (balloon-help-make-help-frame)))
|
|
289 (set-buffer balloon-help-buffer)
|
|
290 (erase-buffer)
|
|
291 (insert help)
|
|
292 (if (not (bolp))
|
|
293 (insert ?\n))
|
|
294 ;; help strings longer than 2 lines have the last
|
|
295 ;; line stolen by the minibuffer, so make sure the
|
|
296 ;; last line is blank. Make the top line blank for
|
|
297 ;; some symmetry.
|
|
298 (if (< 2 (count-lines (point-min) (point-max)))
|
|
299 (progn
|
|
300 (insert ?\n)
|
|
301 ;; add a second blank line at the end to
|
|
302 ;; prevent the modeline bar from clipping the
|
|
303 ;; descenders of the last line of text.
|
|
304 (insert ?\n)
|
|
305 (goto-char (point-min))
|
|
306 (insert ?\n)))
|
|
307 ;; cursor will be at point-min because we're just
|
|
308 ;; moving point which doesn't affect window-point
|
|
309 ;; when the window isn't selected. Indent
|
|
310 ;; everything so that the cursor will be over a
|
|
311 ;; space. The 1-pixel bar cursor will be
|
|
312 ;; completely invisible this way.
|
|
313 (indent-rigidly (point-min) (point-max) 1)
|
|
314 (balloon-help-move-help-frame)
|
|
315 (balloon-help-resize-help-frame)
|
|
316 (balloon-help-expose-help-frame))))))
|
|
317
|
|
318 (defun balloon-help-undisplay-help ()
|
|
319 (balloon-help-hide-help-frame))
|
|
320
|
|
321 (defun balloon-help-hide-help-frame ()
|
|
322 (if (balloon-help-displayed)
|
|
323 (progn
|
|
324 (make-frame-invisible balloon-help-frame)
|
|
325 (if (and balloon-help-use-sound balloon-help-display-pending)
|
|
326 (play-sound 'balloon-help-disappears))
|
|
327 (setq balloon-help-display-pending nil))))
|
|
328
|
|
329 (defun balloon-help-expose-help-frame ()
|
|
330 (if (not (balloon-help-displayed))
|
|
331 (progn
|
|
332 (make-frame-visible balloon-help-frame)
|
|
333 (if (and balloon-help-use-sound (null balloon-help-display-pending))
|
|
334 (play-sound 'balloon-help-appears))
|
|
335 (setq balloon-help-display-pending t))))
|
|
336
|
|
337 (defun balloon-help-resize-help-frame ()
|
|
338 (save-excursion
|
|
339 (set-buffer balloon-help-buffer)
|
|
340 (let ((longest 0)
|
|
341 (lines 0)
|
|
342 (done nil)
|
|
343 (window-min-height 1)
|
|
344 (window-min-width 1))
|
|
345 (goto-char (point-min))
|
|
346 (while (not done)
|
|
347 (end-of-line)
|
|
348 (setq longest (max longest (current-column))
|
|
349 done (not (= 0 (forward-line))))
|
|
350 (and (not done) (setq lines (1+ lines))))
|
|
351 (set-frame-size balloon-help-frame (+ 1 longest) lines))))
|
|
352
|
26
|
353 (defun balloon-help-make-junk-frame ()
|
|
354 (let ((window-min-height 1)
|
|
355 (window-min-width 1))
|
36
|
356 (save-excursion
|
|
357 (set-buffer (generate-new-buffer "*junk-frame-buffer*"))
|
|
358 (prog1
|
|
359 (make-frame '(minibuffer t initially-unmapped t width 1 height 1))
|
|
360 (rename-buffer " *junk-frame-buffer*" t)))))
|
26
|
361
|
0
|
362 (defun balloon-help-make-help-frame ()
|
|
363 (save-excursion
|
|
364 (set-buffer balloon-help-buffer)
|
|
365 (set-buffer-menubar nil)
|
|
366 (let* ((x (balloon-help-compute-help-frame-x-location))
|
|
367 (y (balloon-help-compute-help-frame-y-location))
|
|
368 (window-min-height 1)
|
|
369 (window-min-width 1)
|
|
370 (frame (make-frame (list
|
|
371 '(initially-unmapped . t)
|
|
372 ;; try to evade frame decorations
|
|
373 (cons 'name (or balloon-help-frame-name
|
|
374 "xclock"))
|
26
|
375 (cons 'border-width balloon-help-border-width)
|
0
|
376 (cons 'border-color balloon-help-border-color)
|
|
377 (cons 'top y)
|
|
378 (cons 'left x)
|
26
|
379 (cons 'popup (balloon-help-make-junk-frame))
|
0
|
380 '(width . 3)
|
|
381 '(height . 1)))))
|
|
382 (set-face-font 'default balloon-help-font frame)
|
|
383 (set-face-foreground 'default balloon-help-foreground frame)
|
|
384 (set-face-background 'default balloon-help-background frame)
|
|
385 (set-face-background-pixmap 'default balloon-help-background-pixmap
|
|
386 frame)
|
|
387 (set-window-buffer (frame-selected-window frame) balloon-help-buffer)
|
|
388 (set-specifier has-modeline-p (cons frame nil))
|
|
389 (set-specifier top-toolbar-height (cons frame 0))
|
|
390 (set-specifier left-toolbar-width (cons frame 0))
|
|
391 (set-specifier right-toolbar-width (cons frame 0))
|
|
392 (set-specifier bottom-toolbar-height (cons frame 0))
|
|
393 (set-specifier top-toolbar (cons frame nil))
|
|
394 (set-specifier left-toolbar (cons frame nil))
|
|
395 (set-specifier right-toolbar (cons frame nil))
|
|
396 (set-specifier bottom-toolbar (cons frame nil))
|
|
397 (set-specifier scrollbar-width (cons frame 0))
|
|
398 (set-specifier scrollbar-height (cons frame 0))
|
26
|
399 (and (boundp 'text-cursor-visible-p)
|
|
400 (specifierp text-cursor-visible-p)
|
|
401 (set-specifier text-cursor-visible-p (cons frame nil)))
|
0
|
402 (set-specifier modeline-shadow-thickness (cons frame 0))
|
|
403 (set-face-background 'modeline balloon-help-background frame)
|
|
404 frame )))
|
|
405
|
|
406 (defun balloon-help-compute-help-frame-x-location ()
|
|
407 (max 0 (+ 32 balloon-help-help-object-x)))
|
|
408
|
|
409 (defun balloon-help-compute-help-frame-y-location ()
|
|
410 (max 0 (+ 48 balloon-help-help-object-y)))
|
|
411
|
|
412 (defun balloon-help-move-help-frame ()
|
|
413 (let ((x (balloon-help-compute-help-frame-x-location))
|
|
414 (y (balloon-help-compute-help-frame-y-location)))
|
|
415 (set-frame-position balloon-help-frame x y)))
|
|
416
|
|
417 (add-hook 'mouse-motion-hook 'balloon-help-motion-hook)
|
|
418 (add-hook 'pre-command-hook 'balloon-help-pre-command-hook)
|
|
419 (add-hook 'post-command-hook 'balloon-help-post-command-hook)
|
|
420 (add-hook 'mouse-leave-frame-hook 'balloon-help-mouse-leave-frame-hook)
|
26
|
421 ;; loses with ClickToFocus under fvwm
|
|
422 ;;(add-hook 'deselect-frame-hook 'balloon-help-deselect-frame-hook)
|