1 ;;; toolbar.el --- Toolbar support for XEmacs
3 ;; Copyright (C) 1995, 1997 Free Software Foundation, Inc.
5 ;; Maintainer: XEmacs Development Team
6 ;; Keywords: extensions, internal, dumped
8 ;; This file is part of XEmacs.
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)
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.
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.
25 ;;; Synched up with: Not in FSF.
29 ;; This file is dumped with XEmacs (when toolbar support is compiled in).
33 (defcustom toolbar-visible-p ;; added for the options menu - dverna apr. 98
34 (specifier-instance default-toolbar-visible-p)
35 "Whether the default toolbar is globally visible. This option can be
36 customized through the options menu."
39 :set #'(lambda (var val)
40 (set-specifier default-toolbar-visible-p val)
41 (setq toolbar-visible-p val))
44 (defcustom toolbar-captioned-p ;; added for the options menu - dverna apr. 98
45 (specifier-instance toolbar-buttons-captioned-p)
46 "Whether the toolbars buttons are globally captioned. This option can be
47 customized through the options menu."
50 :set #'(lambda (var val)
51 (set-specifier toolbar-buttons-captioned-p val)
52 (setq toolbar-captioned-p val))
55 (defcustom default-toolbar-position ;; added for the options menu - dverna
56 (default-toolbar-position)
57 "The location of the default toolbar. It can be 'top, 'bottom, 'left or
58 'right. This option can be customized through the options menu."
60 :type '(choice (const :tag "top" top)
61 (const :tag "bottom" bottom)
62 (const :tag "left" left)
63 (const :tag "right" right))
64 :set #'(lambda (var val)
65 (set-default-toolbar-position val)
66 (setq default-toolbar-position val))
69 (defvar toolbar-help-enabled t
70 "If non-nil help is echoed for toolbar buttons.")
72 (defvar toolbar-icon-directory nil
73 "Location of standard toolbar icon bitmaps.")
75 (defun toolbar-make-button-list (up &optional down disabled cap-up cap-down cap-disabled)
76 "Call make-glyph on each arg and return a list of the results."
77 (let ((up-glyph (make-glyph up))
78 (down-glyph (and down (make-glyph down)))
79 (disabled-glyph (and disabled (make-glyph disabled)))
80 (cap-up-glyph (and cap-up (make-glyph cap-up)))
81 (cap-down-glyph (and cap-down (make-glyph cap-down)))
82 (cap-disabled-glyph (and cap-disabled (make-glyph cap-disabled))))
84 (list up-glyph down-glyph disabled-glyph
85 cap-up-glyph cap-down-glyph cap-disabled-glyph)
87 (list up-glyph down-glyph disabled-glyph
88 cap-up-glyph cap-down-glyph)
90 (list up-glyph down-glyph disabled-glyph cap-up-glyph)
92 (list up-glyph down-glyph disabled-glyph)
94 (list up-glyph down-glyph)
95 (list up-glyph))))))))
97 (defun init-toolbar-location ()
98 (if (not toolbar-icon-directory)
99 (let ((name (locate-data-directory "toolbar")))
101 (setq toolbar-icon-directory
102 (file-name-as-directory name))))))
104 (defun init-toolbar-from-resources (locale)
105 (if (and (featurep 'x)
106 (not (featurep 'infodock))
107 (or (eq locale 'global)
108 (eq 'x (device-or-frame-type locale))))
109 (x-init-toolbar-from-resources locale)))
112 ;; #### Is this actually needed or will the code in
113 ;; default-mouse-motion-handler suffice?
114 (define-key global-map 'button1up 'release-toolbar-button)
116 (defvar toolbar-map (let ((m (make-sparse-keymap)))
117 (set-keymap-name m 'toolbar-map)
119 "Keymap consulted for mouse-clicks over a toolbar.")
121 (define-key toolbar-map 'button1 'press-toolbar-button)
122 (define-key toolbar-map 'button1up 'release-and-activate-toolbar-button)
123 (defvar last-pressed-toolbar-button nil)
124 (defvar toolbar-active nil)
126 (defvar toolbar-blank-press-function nil
127 "Function to call if a blank area of the toolbar is pressed.")
130 ;; It really sucks that we also have to tie onto
131 ;; default-mouse-motion-handler to make sliding buttons work right.
133 (defun press-toolbar-button (event)
134 "Press a toolbar button. This only changes its appearance.
135 Call function stored in `toolbar-blank-press-function,' if any, with EVENT as
136 an argument if press is over a blank area of the toolbar."
138 (setq this-command last-command)
139 (let ((button (event-toolbar-button event)))
140 ;; We silently ignore non-buttons. This most likely means we are
141 ;; over a blank part of the toolbar.
142 (setq toolbar-active t)
143 (if (toolbar-button-p button)
145 (set-toolbar-button-down-flag button t)
146 (setq last-pressed-toolbar-button button))
147 ;; Added by Bob Weiner, Motorola Inc., 10/6/95, to handle
148 ;; presses on blank portions of toolbars.
149 (when (functionp toolbar-blank-press-function)
150 (funcall toolbar-blank-press-function event)))))
152 (defun release-and-activate-toolbar-button (event)
153 "Release a toolbar button and activate its callback.
154 Call function stored in `toolbar-blank-release-function,' if any, with EVENT
155 as an argument if release is over a blank area of the toolbar."
157 (or (button-release-event-p event)
158 (error "%s must be invoked by a mouse-release" this-command))
159 (release-toolbar-button event)
160 (let ((button (event-toolbar-button event)))
161 (if (and (toolbar-button-p button)
162 (toolbar-button-enabled-p button)
163 (toolbar-button-callback button))
164 (let ((callback (toolbar-button-callback button)))
165 (setq this-command callback)
166 ;; Handle arbitrary functions.
167 (if (functionp callback)
168 (if (commandp callback)
169 (call-interactively callback)
173 ;; If current is not t, then only release the toolbar button stored in
174 ;; last-pressed-toolbar-button
175 (defun release-toolbar-button-internal (event current)
176 (let ((button (event-toolbar-button event)))
177 (setq zmacs-region-stays t)
178 (if (and last-pressed-toolbar-button
179 (not (eq last-pressed-toolbar-button button))
180 (toolbar-button-p last-pressed-toolbar-button))
182 (set-toolbar-button-down-flag last-pressed-toolbar-button nil)
183 (setq last-pressed-toolbar-button nil)))
184 (if (and current (toolbar-button-p button))
185 (set-toolbar-button-down-flag button nil))))
187 (defun release-toolbar-button (event)
188 "Release all pressed toolbar buttons."
190 (or (button-release-event-p event)
191 (error "%s must be invoked by a mouse-release" this-command))
192 (release-toolbar-button-internal event t)
193 ;; Don't set this-command if we're being called
194 ;; from release-and-activate-toolbar-button.
196 (setq this-command last-command))
197 (setq toolbar-active nil))
199 (defun release-previous-toolbar-button (event)
200 (setq zmacs-region-stays t)
201 (release-toolbar-button-internal event nil))
203 (defun make-toolbar-specifier (spec-list)
204 "Return a new `toolbar' specifier object with the given specification list.
205 SPEC-LIST can be a list of specifications (each of which is a cons of a
206 locale and a list of instantiators), a single instantiator, or a list
207 of instantiators. See `make-specifier' for more information about
210 Toolbar specifiers are used to specify the format of a toolbar.
211 The values of the variables `default-toolbar', `top-toolbar',
212 `left-toolbar', `right-toolbar', and `bottom-toolbar' are always
215 Valid toolbar instantiators are called \"toolbar descriptors\"
216 and are lists of vectors. See `default-toolbar' for a description
217 of the exact format."
218 (make-specifier-and-init 'toolbar spec-list))
220 ;;; toolbar.el ends here