annotate lisp/prim/toolbar.el @ 140:585fb297b004 r20-2b4

Import from CVS: tag r20-2b4
author cvs
date Mon, 13 Aug 2007 09:32:43 +0200
parents 131b0175ea99
children 43dd3413c7c7
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
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
17 ;; 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
18 ;; Free Software Foundation, 59 Temple Place - Suite 330,
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
19 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 (defvar toolbar-help-enabled t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 "If non-nil help is echoed for toolbar buttons.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 (defvar toolbar-icon-directory nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 "Location of standard toolbar icon bitmaps.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (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
30 "Calls make-glyph on each arg and returns a list of the results."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (if (featurep 'x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (let ((up-glyph (make-glyph up))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (down-glyph (and down (make-glyph down)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (disabled-glyph (and disabled (make-glyph disabled)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (cap-up-glyph (and cap-up (make-glyph cap-up)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (cap-down-glyph (and cap-down (make-glyph cap-down)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (cap-disabled-glyph (and cap-disabled (make-glyph cap-disabled))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (if cap-disabled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (list up-glyph down-glyph disabled-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 cap-up-glyph cap-down-glyph cap-disabled-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (if cap-down
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (list up-glyph down-glyph disabled-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 cap-up-glyph cap-down-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (if cap-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (list up-glyph down-glyph disabled-glyph cap-up-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (if disabled-glyph
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 (if down-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (list up-glyph down-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (list up-glyph)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (defun init-toolbar-location ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (if (not toolbar-icon-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (setq toolbar-icon-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (expand-file-name "toolbar" data-directory)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defun init-toolbar-from-resources (locale)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (if (and (featurep 'x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (or (eq locale 'global)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (eq 'x (device-or-frame-type locale)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (x-init-toolbar-from-resources locale))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; #### Is this actually needed or will the code in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; default-mouse-motion-handler suffice?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (define-key global-map 'button1up 'release-toolbar-button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defvar toolbar-map (let ((m (make-sparse-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (set-keymap-name m 'toolbar-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 "Keymap consulted for mouse-clicks over a toolbar.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (define-key toolbar-map 'button1 'press-toolbar-button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (define-key toolbar-map 'button1up 'release-and-activate-toolbar-button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (defvar last-pressed-toolbar-button nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (defvar toolbar-active nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; It really sucks that we also have to tie onto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; default-mouse-motion-handler to make sliding buttons work right.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defun press-toolbar-button (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 "Press a toolbar button. This only changes its appearance."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (interactive "_e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (setq this-command last-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (let ((button (event-toolbar-button event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; We silently ignore non-buttons. This most likely means we are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; over a blank part of the toolbar.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (setq toolbar-active t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (if (toolbar-button-p button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (set-toolbar-button-down-flag button t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (setq last-pressed-toolbar-button button)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defun release-and-activate-toolbar-button (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 "Release a toolbar button and activate its callback."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (interactive "_e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (or (button-release-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (error "%s must be invoked by a mouse-release" this-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (release-toolbar-button event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (let ((button (event-toolbar-button event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (if (and (toolbar-button-p button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (toolbar-button-enabled-p button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (toolbar-button-callback button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (let ((callback (toolbar-button-callback button)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (setq this-command callback)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (if (symbolp callback)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (call-interactively callback)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (eval callback))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; If current is not t, then only release the toolbar button stored in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; last-pressed-toolbar-button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defun release-toolbar-button-internal (event current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (let ((button (event-toolbar-button event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (setq zmacs-region-stays t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (if (and last-pressed-toolbar-button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (not (eq last-pressed-toolbar-button button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (toolbar-button-p last-pressed-toolbar-button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (set-toolbar-button-down-flag last-pressed-toolbar-button nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (setq last-pressed-toolbar-button nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (if (and current (toolbar-button-p button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (set-toolbar-button-down-flag button nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defun release-toolbar-button (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "Release all pressed toolbar buttons."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (interactive "_e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (or (button-release-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (error "%s must be invoked by a mouse-release" this-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (release-toolbar-button-internal event t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; Don't set this-command if we're being called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; from release-and-activate-toolbar-button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (setq this-command last-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (setq toolbar-active nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (defun release-previous-toolbar-button (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (setq zmacs-region-stays t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (release-toolbar-button-internal event nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142