428
|
1 ;;; toolbar.el --- Toolbar support for XEmacs
|
|
2
|
|
3 ;; Copyright (C) 1995, 1997 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer: XEmacs Development Team
|
|
6 ;; Keywords: extensions, internal, dumped
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
|
24
|
|
25 ;;; Synched up with: Not in FSF.
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; This file is dumped with XEmacs (when toolbar support is compiled in).
|
|
30
|
|
31 ;;; Code:
|
|
32
|
|
33 (defcustom toolbar-visible-p ;; added for the options menu - dverna apr. 98
|
|
34 (specifier-instance default-toolbar-visible-p)
|
763
|
35 "*Whether the default toolbar is globally visible.
|
|
36 This option can be customized through the options menu."
|
428
|
37 :group 'display
|
|
38 :type 'boolean
|
|
39 :set #'(lambda (var val)
|
|
40 (set-specifier default-toolbar-visible-p val)
|
|
41 (setq toolbar-visible-p val))
|
|
42 )
|
|
43
|
|
44 (defcustom toolbar-captioned-p ;; added for the options menu - dverna apr. 98
|
|
45 (specifier-instance toolbar-buttons-captioned-p)
|
763
|
46 "*Whether the toolbars buttons are globally captioned.
|
|
47 This option can be customized through the options menu."
|
428
|
48 :group 'display
|
|
49 :type 'boolean
|
|
50 :set #'(lambda (var val)
|
|
51 (set-specifier toolbar-buttons-captioned-p val)
|
|
52 (setq toolbar-captioned-p val))
|
|
53 )
|
|
54
|
|
55 (defcustom default-toolbar-position ;; added for the options menu - dverna
|
|
56 (default-toolbar-position)
|
763
|
57 "*The location of the default toolbar: 'top, 'bottom, 'left, or 'right.
|
|
58 This option can be customized through the options menu."
|
428
|
59 :group 'display
|
442
|
60 :type '(choice (const :tag "top" top)
|
|
61 (const :tag "bottom" bottom)
|
|
62 (const :tag "left" left)
|
|
63 (const :tag "right" right))
|
428
|
64 :set #'(lambda (var val)
|
763
|
65 (let* ((height (window-height))
|
|
66 (hdiff (- (frame-height) height))
|
|
67 (width (window-width)))
|
|
68 (set-default-toolbar-position val)
|
|
69 (setq default-toolbar-position val)
|
|
70 ;; needed or dimensions don't update?
|
|
71 (redisplay-frame)
|
|
72 ;; This probably only works correctly if there is only one
|
|
73 ;; Emacs window. If windows are split, it probably results in
|
|
74 ;; small adjustments in their sizes.
|
|
75 (set-frame-size (selected-frame) width (+ height hdiff))
|
767
|
76 )))
|
428
|
77
|
|
78 (defvar toolbar-help-enabled t
|
|
79 "If non-nil help is echoed for toolbar buttons.")
|
|
80
|
|
81 (defvar toolbar-icon-directory nil
|
|
82 "Location of standard toolbar icon bitmaps.")
|
|
83
|
|
84 (defun toolbar-make-button-list (up &optional down disabled cap-up cap-down cap-disabled)
|
|
85 "Call make-glyph on each arg and return a list of the results."
|
|
86 (let ((up-glyph (make-glyph up))
|
|
87 (down-glyph (and down (make-glyph down)))
|
|
88 (disabled-glyph (and disabled (make-glyph disabled)))
|
|
89 (cap-up-glyph (and cap-up (make-glyph cap-up)))
|
|
90 (cap-down-glyph (and cap-down (make-glyph cap-down)))
|
|
91 (cap-disabled-glyph (and cap-disabled (make-glyph cap-disabled))))
|
|
92 (if cap-disabled
|
|
93 (list up-glyph down-glyph disabled-glyph
|
|
94 cap-up-glyph cap-down-glyph cap-disabled-glyph)
|
|
95 (if cap-down
|
|
96 (list up-glyph down-glyph disabled-glyph
|
|
97 cap-up-glyph cap-down-glyph)
|
|
98 (if cap-up
|
|
99 (list up-glyph down-glyph disabled-glyph cap-up-glyph)
|
|
100 (if disabled-glyph
|
|
101 (list up-glyph down-glyph disabled-glyph)
|
|
102 (if down-glyph
|
|
103 (list up-glyph down-glyph)
|
|
104 (list up-glyph))))))))
|
|
105
|
|
106 (defun init-toolbar-location ()
|
|
107 (if (not toolbar-icon-directory)
|
|
108 (let ((name (locate-data-directory "toolbar")))
|
|
109 (if name
|
|
110 (setq toolbar-icon-directory
|
|
111 (file-name-as-directory name))))))
|
|
112
|
487
|
113 ;; called from toolbar.c during device and frame initialization
|
428
|
114 (defun init-toolbar-from-resources (locale)
|
|
115 (if (and (featurep 'x)
|
|
116 (not (featurep 'infodock))
|
|
117 (or (eq locale 'global)
|
|
118 (eq 'x (device-or-frame-type locale))))
|
502
|
119 (declare-fboundp (x-init-toolbar-from-resources locale))))
|
428
|
120
|
|
121
|
|
122 ;; #### Is this actually needed or will the code in
|
|
123 ;; default-mouse-motion-handler suffice?
|
|
124 (define-key global-map 'button1up 'release-toolbar-button)
|
|
125
|
|
126 (defvar toolbar-map (let ((m (make-sparse-keymap)))
|
|
127 (set-keymap-name m 'toolbar-map)
|
|
128 m)
|
|
129 "Keymap consulted for mouse-clicks over a toolbar.")
|
|
130
|
|
131 (define-key toolbar-map 'button1 'press-toolbar-button)
|
|
132 (define-key toolbar-map 'button1up 'release-and-activate-toolbar-button)
|
|
133 (defvar last-pressed-toolbar-button nil)
|
|
134 (defvar toolbar-active nil)
|
|
135
|
442
|
136 (defvar toolbar-blank-press-function nil
|
|
137 "Function to call if a blank area of the toolbar is pressed.")
|
|
138
|
428
|
139 ;;
|
|
140 ;; It really sucks that we also have to tie onto
|
|
141 ;; default-mouse-motion-handler to make sliding buttons work right.
|
|
142 ;;
|
|
143 (defun press-toolbar-button (event)
|
|
144 "Press a toolbar button. This only changes its appearance.
|
|
145 Call function stored in `toolbar-blank-press-function,' if any, with EVENT as
|
|
146 an argument if press is over a blank area of the toolbar."
|
|
147 (interactive "_e")
|
|
148 (setq this-command last-command)
|
|
149 (let ((button (event-toolbar-button event)))
|
|
150 ;; We silently ignore non-buttons. This most likely means we are
|
|
151 ;; over a blank part of the toolbar.
|
|
152 (setq toolbar-active t)
|
|
153 (if (toolbar-button-p button)
|
|
154 (progn
|
|
155 (set-toolbar-button-down-flag button t)
|
|
156 (setq last-pressed-toolbar-button button))
|
|
157 ;; Added by Bob Weiner, Motorola Inc., 10/6/95, to handle
|
|
158 ;; presses on blank portions of toolbars.
|
442
|
159 (when (functionp toolbar-blank-press-function)
|
|
160 (funcall toolbar-blank-press-function event)))))
|
428
|
161
|
|
162 (defun release-and-activate-toolbar-button (event)
|
|
163 "Release a toolbar button and activate its callback.
|
|
164 Call function stored in `toolbar-blank-release-function,' if any, with EVENT
|
|
165 as an argument if release is over a blank area of the toolbar."
|
|
166 (interactive "_e")
|
|
167 (or (button-release-event-p event)
|
|
168 (error "%s must be invoked by a mouse-release" this-command))
|
|
169 (release-toolbar-button event)
|
|
170 (let ((button (event-toolbar-button event)))
|
|
171 (if (and (toolbar-button-p button)
|
|
172 (toolbar-button-enabled-p button)
|
|
173 (toolbar-button-callback button))
|
|
174 (let ((callback (toolbar-button-callback button)))
|
|
175 (setq this-command callback)
|
|
176 ;; Handle arbitrary functions.
|
|
177 (if (functionp callback)
|
|
178 (if (commandp callback)
|
|
179 (call-interactively callback)
|
|
180 (funcall callback))
|
|
181 (eval callback))))))
|
|
182
|
|
183 ;; If current is not t, then only release the toolbar button stored in
|
|
184 ;; last-pressed-toolbar-button
|
|
185 (defun release-toolbar-button-internal (event current)
|
|
186 (let ((button (event-toolbar-button event)))
|
|
187 (setq zmacs-region-stays t)
|
|
188 (if (and last-pressed-toolbar-button
|
|
189 (not (eq last-pressed-toolbar-button button))
|
|
190 (toolbar-button-p last-pressed-toolbar-button))
|
|
191 (progn
|
|
192 (set-toolbar-button-down-flag last-pressed-toolbar-button nil)
|
|
193 (setq last-pressed-toolbar-button nil)))
|
|
194 (if (and current (toolbar-button-p button))
|
|
195 (set-toolbar-button-down-flag button nil))))
|
|
196
|
|
197 (defun release-toolbar-button (event)
|
|
198 "Release all pressed toolbar buttons."
|
|
199 (interactive "_e")
|
|
200 (or (button-release-event-p event)
|
|
201 (error "%s must be invoked by a mouse-release" this-command))
|
|
202 (release-toolbar-button-internal event t)
|
|
203 ;; Don't set this-command if we're being called
|
|
204 ;; from release-and-activate-toolbar-button.
|
|
205 (if (interactive-p)
|
|
206 (setq this-command last-command))
|
|
207 (setq toolbar-active nil))
|
|
208
|
|
209 (defun release-previous-toolbar-button (event)
|
|
210 (setq zmacs-region-stays t)
|
|
211 (release-toolbar-button-internal event nil))
|
|
212
|
442
|
213 (defun make-toolbar-specifier (spec-list)
|
|
214 "Return a new `toolbar' specifier object with the given specification list.
|
|
215 SPEC-LIST can be a list of specifications (each of which is a cons of a
|
|
216 locale and a list of instantiators), a single instantiator, or a list
|
|
217 of instantiators. See `make-specifier' for more information about
|
|
218 specifiers.
|
|
219
|
|
220 Toolbar specifiers are used to specify the format of a toolbar.
|
|
221 The values of the variables `default-toolbar', `top-toolbar',
|
|
222 `left-toolbar', `right-toolbar', and `bottom-toolbar' are always
|
|
223 toolbar specifiers.
|
|
224
|
|
225 Valid toolbar instantiators are called \"toolbar descriptors\"
|
|
226 and are lists of vectors. See `default-toolbar' for a description
|
|
227 of the exact format."
|
|
228 (make-specifier-and-init 'toolbar spec-list))
|
|
229
|
428
|
230 ;;; toolbar.el ends here
|