annotate lisp/prim/toolbar.el @ 155:43dd3413c7c7 r20-3b4

Import from CVS: tag r20-3b4
author cvs
date Mon, 13 Aug 2007 09:39:39 +0200
parents 131b0175ea99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
1 ;;; toolbar.el --- Toolbar support for XEmacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
2
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
3 ;; Copyright (C) 1995, 1997 Free Software Foundation, Inc.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
4
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
5 ;; Maintainer: XEmacs Development Team
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
6 ;; Keywords: extensions, internal
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
22 ;; Free Software Foundation, 59 Temple Place - Suite 330,
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
23 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
27 ;;; Commentary:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
28
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
29 ;;; Code:
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
30
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (defvar toolbar-help-enabled t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 "If non-nil help is echoed for toolbar buttons.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defvar toolbar-icon-directory nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "Location of standard toolbar icon bitmaps.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (defun toolbar-make-button-list (up &optional down disabled cap-up cap-down cap-disabled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 "Calls make-glyph on each arg and returns a list of the results."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (if (featurep 'x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (let ((up-glyph (make-glyph up))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (down-glyph (and down (make-glyph down)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (disabled-glyph (and disabled (make-glyph disabled)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (cap-up-glyph (and cap-up (make-glyph cap-up)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (cap-down-glyph (and cap-down (make-glyph cap-down)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (cap-disabled-glyph (and cap-disabled (make-glyph cap-disabled))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (if cap-disabled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (list up-glyph down-glyph disabled-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 cap-up-glyph cap-down-glyph cap-disabled-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (if cap-down
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (list up-glyph down-glyph disabled-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 cap-up-glyph cap-down-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (if cap-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (list up-glyph down-glyph disabled-glyph cap-up-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (if disabled-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (list up-glyph down-glyph disabled-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (if down-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (list up-glyph down-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (list up-glyph)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defun init-toolbar-location ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (if (not toolbar-icon-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (setq toolbar-icon-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (expand-file-name "toolbar" data-directory)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (defun init-toolbar-from-resources (locale)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (if (and (featurep 'x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (or (eq locale 'global)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (eq 'x (device-or-frame-type locale)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (x-init-toolbar-from-resources locale))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; #### Is this actually needed or will the code in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; default-mouse-motion-handler suffice?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (define-key global-map 'button1up 'release-toolbar-button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (defvar toolbar-map (let ((m (make-sparse-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (set-keymap-name m 'toolbar-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "Keymap consulted for mouse-clicks over a toolbar.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (define-key toolbar-map 'button1 'press-toolbar-button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (define-key toolbar-map 'button1up 'release-and-activate-toolbar-button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defvar last-pressed-toolbar-button nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defvar toolbar-active nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; It really sucks that we also have to tie onto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; default-mouse-motion-handler to make sliding buttons work right.
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 press-toolbar-button (event)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
93 "Press a toolbar button. This only changes its appearance.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
94 Call function stored in `toolbar-blank-press-function,' if any, with EVENT as
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
95 an argument if press is over a blank area of the toolbar."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (interactive "_e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (setq this-command last-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (let ((button (event-toolbar-button event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; We silently ignore non-buttons. This most likely means we are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;; over a blank part of the toolbar.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq toolbar-active t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (if (toolbar-button-p button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (set-toolbar-button-down-flag button t)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
105 (setq last-pressed-toolbar-button button))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
106 ;; Added by Bob Weiner, Motorola Inc., 10/6/95, to handle
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
107 ;; presses on blank portions of toolbars.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
108 (and (boundp 'toolbar-blank-press-function)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
109 (functionp toolbar-blank-press-function)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
110 (funcall toolbar-blank-press-function event)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (defun release-and-activate-toolbar-button (event)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
113 "Release a toolbar button and activate its callback.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
114 Call function stored in `toolbar-blank-release-function,' if any, with EVENT
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
115 as an argument if release is over a blank area of the toolbar."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (interactive "_e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (or (button-release-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (error "%s must be invoked by a mouse-release" this-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (release-toolbar-button event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (let ((button (event-toolbar-button event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (if (and (toolbar-button-p button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (toolbar-button-enabled-p button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (toolbar-button-callback button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (let ((callback (toolbar-button-callback button)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq this-command callback)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
126 ;; Handle arbitrary functions.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
127 (if (functionp callback)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
128 (if (commandp callback)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
129 (call-interactively callback)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
130 (funcall callback))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (eval callback))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; If current is not t, then only release the toolbar button stored in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; last-pressed-toolbar-button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (defun release-toolbar-button-internal (event current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (let ((button (event-toolbar-button event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (setq zmacs-region-stays t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (if (and last-pressed-toolbar-button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (not (eq last-pressed-toolbar-button button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (toolbar-button-p last-pressed-toolbar-button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (set-toolbar-button-down-flag last-pressed-toolbar-button nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (setq last-pressed-toolbar-button nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (if (and current (toolbar-button-p button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (set-toolbar-button-down-flag button nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (defun release-toolbar-button (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 "Release all pressed toolbar buttons."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (interactive "_e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (or (button-release-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (error "%s must be invoked by a mouse-release" this-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (release-toolbar-button-internal event t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; Don't set this-command if we're being called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; from release-and-activate-toolbar-button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (setq this-command last-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (setq toolbar-active nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (defun release-previous-toolbar-button (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (setq zmacs-region-stays t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (release-toolbar-button-internal event nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 70
diff changeset
163 ;;; toolbar.el ends here