annotate lisp/prim/toolbar.el @ 0:376386a54a3c r19-14

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