Debug message fix
[sxemacs] / lisp / events.el
1 ;;; events.el --- event functions for XEmacs.
2
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1996-7 Sun Microsystems, Inc.
5 ;; Copyright (C) 1996 Ben Wing.
6
7 ;; Maintainer: Martin Buchholz
8 ;; Keywords: internal, event, dumped
9
10 ;; This file is part of SXEmacs.
11
12 ;; SXEmacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; SXEmacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Synched up with: Not in FSF.
26
27 ;;; Commentary:
28
29 ;; This file is dumped with SXEmacs.
30
31 ;;; Code:
32
33
34 (defun event-console (event)
35   "Return the console that EVENT occurred on.
36 This will be nil for some types of events (e.g. eval events)."
37   (cdfw-console (event-channel event)))
38
39 (defun event-device (event)
40   "Return the device that EVENT occurred on.
41 This will be nil for some types of events (e.g. keyboard and eval events)."
42   (dfw-device (event-channel event)))
43
44 (defun event-frame (event)
45   "Return the frame that EVENT occurred on.
46 This will be nil for some types of events (e.g. keyboard and eval events)."
47   (fw-frame (event-channel event)))
48
49 (defun event-buffer (event)
50   "Return the buffer of the window over which mouse event EVENT occurred.
51 Return nil unless both (mouse-event-p EVENT) and
52 (event-over-text-area-p EVENT) are non-nil."
53   (let ((window (event-window event)))
54     (and (windowp window) (window-buffer window))))
55
56 (defalias 'allocate-event 'make-event)
57
58
59 (defun key-press-event-p (object)
60   "Return t if OBJECT is a key-press event."
61   (and (event-live-p object) (eq 'key-press (event-type object))))
62
63 (defun button-press-event-p (object)
64   "Return t if OBJECT is a mouse button-press event."
65   (and (event-live-p object) (eq 'button-press (event-type object))))
66
67 (defun button-release-event-p (object)
68   "Return t if OBJECT is a mouse button-release event."
69   (and (event-live-p object) (eq 'button-release (event-type object))))
70
71 (defun button-event-p (object)
72   "Return t if OBJECT is a mouse button-press or button-release event."
73   (and (event-live-p object)
74        (memq (event-type object) '(button-press button-release))
75        t))
76
77 (defun motion-event-p (object)
78   "Return t if OBJECT is a mouse motion event."
79   (and (event-live-p object) (eq 'motion (event-type object))))
80
81 (defun mouse-event-p (object)
82   "Return t if OBJECT is a mouse button-press, button-release or motion event."
83   (and (event-live-p object)
84        (memq (event-type object) '(button-press button-release motion))
85        t))
86
87 (defun process-event-p (object)
88   "Return t if OBJECT is a process-output event."
89   (and (event-live-p object) (eq 'process (event-type object))))
90
91 (defun timeout-event-p (object)
92   "Return t if OBJECT is a timeout event."
93   (and (event-live-p object) (eq 'timeout (event-type object))))
94
95 (defun eval-event-p (object)
96   "Return t if OBJECT is an eval event."
97   (and (event-live-p object) (eq 'eval (event-type object))))
98
99 (defun misc-user-event-p (object)
100   "Return t if OBJECT is a misc-user event.
101 A misc-user event is a user event that is not a keypress or mouse click;
102 normally this means a menu selection or scrollbar action."
103   (and (event-live-p object) (eq 'misc-user (event-type object))))
104
105 ;; You could just as easily use event-glyph but we include this for
106 ;; consistency.
107
108 (defun event-over-glyph-p (object)
109   "Return t if OBJECT is a mouse event occurring over a glyph.
110 Mouse events are events of type button-press, button-release or motion."
111   (and (event-live-p object) (event-glyph object) t))
112
113 (defun keyboard-translate (&rest pairs)
114   "Translate character or keysym FROM to TO at a low level.
115 Multiple FROM-TO pairs may be specified.
116
117 See `keyboard-translate-table' for more information."
118   (while pairs
119     (puthash (pop pairs) (pop pairs) keyboard-translate-table)))
120
121 (put 'tab       'ascii-character ?\t)
122 (put 'linefeed  'ascii-character ?\n)
123 (put 'clear     'ascii-character 12)
124 (put 'return    'ascii-character ?\r)
125 (put 'escape    'ascii-character ?\e)
126 (put 'space     'ascii-character ? )
127
128  ;; Do the same voodoo for the keypad keys.  I used to bind these to keyboard
129  ;; macros (for instance, kp-0 was bound to "0") so that they would track the
130  ;; bindings of the corresponding keys by default, but that made the display
131  ;; of M-x describe-bindings much harder to read, so now we'll just bind them
132  ;; to self-insert by default.  Not a big difference...
133
134 (put 'kp-0 'ascii-character ?0)
135 (put 'kp-1 'ascii-character ?1)
136 (put 'kp-2 'ascii-character ?2)
137 (put 'kp-3 'ascii-character ?3)
138 (put 'kp-4 'ascii-character ?4)
139 (put 'kp-5 'ascii-character ?5)
140 (put 'kp-6 'ascii-character ?6)
141 (put 'kp-7 'ascii-character ?7)
142 (put 'kp-8 'ascii-character ?8)
143 (put 'kp-9 'ascii-character ?9)
144
145 (put 'kp-space     'ascii-character ? )
146 (put 'kp-tab       'ascii-character ?\t)
147 (put 'kp-enter     'ascii-character ?\r)
148 (put 'kp-equal     'ascii-character ?=)
149 (put 'kp-multiply  'ascii-character ?*)
150 (put 'kp-add       'ascii-character ?+)
151 (put 'kp-separator 'ascii-character ?,)
152 (put 'kp-subtract  'ascii-character ?-)
153 (put 'kp-decimal   'ascii-character ?.)
154 (put 'kp-divide    'ascii-character ?/)
155
156 ;;; events.el ends here