Commit | Line | Data |
---|---|---|
07bf635f RS |
1 | /* Defines a function to find the Widget that XtDispatchEvent() would use. |
2 | Copyright (C) 1992 Lucid, Inc. | |
3 | ||
4 | This file is part of the Lucid Widget Library. | |
5 | ||
6 | The Lucid Widget Library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 1, or (at your option) | |
9 | any later version. | |
10 | ||
11 | The Lucid Widget Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Emacs; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | /* | |
21 | * The function XtWidgetToDispatchTo(), given an XEvent, returns the | |
22 | * widget that XtDispatchEvent() would send that event to if called now. | |
23 | * This file copies much code from the X11r4 Xt source, and is thus a | |
24 | * portability problem. It also requires data structures defined in | |
25 | * IntrinsicI.h, which is a non-exported Xt header file, so you can't | |
26 | * compile this file unless you have the Xt sources online. | |
27 | */ | |
28 | ||
29 | #include <IntrinsicI.h> /* Don't change this: see comments in Imakefile. */ | |
30 | #include <X11/Xatom.h> | |
31 | #include "dispatch.h" | |
32 | ||
15c909ba RS |
33 | #include <X11/Xlib.h> |
34 | #include <X11/cursorfont.h> | |
35 | #include <X11/Xutil.h> | |
07bf635f | 36 | |
15c909ba RS |
37 | #ifdef XlibSpecificationRelease |
38 | #if XlibSpecificationRelease >= 5 | |
39 | #define HAVE_X11R5 | |
07bf635f | 40 | #endif |
07bf635f RS |
41 | #endif |
42 | ||
07bf635f RS |
43 | /* ## All of the code on this page was copied from the X11R5 lib/Xt/Event.c, |
44 | ## but is compatible with X11R4; the code in Event.c is different, but | |
45 | ## functionally equivalent for our purposes. | |
46 | */ | |
47 | ||
48 | #if __STDC__ | |
49 | #define Const const | |
50 | #else | |
51 | #define Const /**/ | |
52 | #endif | |
53 | ||
54 | #define NonMaskableMask ((EventMask)0x80000000L) | |
55 | ||
56 | #define COMP_EXPOSE (widget->core.widget_class->core_class.compress_exposure) | |
57 | #define COMP_EXPOSE_TYPE (COMP_EXPOSE & 0x0f) | |
58 | #define GRAPHICS_EXPOSE ((XtExposeGraphicsExpose & COMP_EXPOSE) || \ | |
59 | (XtExposeGraphicsExposeMerged & COMP_EXPOSE)) | |
60 | #define NO_EXPOSE (XtExposeNoExpose & COMP_EXPOSE) | |
61 | ||
62 | ||
63 | /* -- lots of stuff we don't need to copy, omitted -- */ | |
64 | ||
65 | ||
66 | static EventMask Const masks[] = { | |
67 | 0, /* Error, should never see */ | |
68 | 0, /* Reply, should never see */ | |
69 | KeyPressMask, /* KeyPress */ | |
70 | KeyReleaseMask, /* KeyRelease */ | |
71 | ButtonPressMask, /* ButtonPress */ | |
72 | ButtonReleaseMask, /* ButtonRelease */ | |
73 | PointerMotionMask /* MotionNotify */ | |
74 | | ButtonMotionMask, | |
75 | EnterWindowMask, /* EnterNotify */ | |
76 | LeaveWindowMask, /* LeaveNotify */ | |
77 | FocusChangeMask, /* FocusIn */ | |
78 | FocusChangeMask, /* FocusOut */ | |
79 | KeymapStateMask, /* KeymapNotify */ | |
80 | ExposureMask, /* Expose */ | |
81 | NonMaskableMask, /* GraphicsExpose, in GC */ | |
82 | NonMaskableMask, /* NoExpose, in GC */ | |
83 | VisibilityChangeMask, /* VisibilityNotify */ | |
84 | SubstructureNotifyMask, /* CreateNotify */ | |
85 | StructureNotifyMask /* DestroyNotify */ | |
86 | | SubstructureNotifyMask, | |
87 | StructureNotifyMask /* UnmapNotify */ | |
88 | | SubstructureNotifyMask, | |
89 | StructureNotifyMask /* MapNotify */ | |
90 | | SubstructureNotifyMask, | |
91 | SubstructureRedirectMask, /* MapRequest */ | |
92 | StructureNotifyMask /* ReparentNotify */ | |
93 | | SubstructureNotifyMask, | |
94 | StructureNotifyMask /* ConfigureNotify */ | |
95 | | SubstructureNotifyMask, | |
96 | SubstructureRedirectMask, /* ConfigureRequest */ | |
97 | StructureNotifyMask /* GravityNotify */ | |
98 | | SubstructureNotifyMask, | |
99 | ResizeRedirectMask, /* ResizeRequest */ | |
100 | StructureNotifyMask /* CirculateNotify */ | |
101 | | SubstructureNotifyMask, | |
102 | SubstructureRedirectMask, /* CirculateRequest */ | |
103 | PropertyChangeMask, /* PropertyNotify */ | |
104 | NonMaskableMask, /* SelectionClear */ | |
105 | NonMaskableMask, /* SelectionRequest */ | |
106 | NonMaskableMask, /* SelectionNotify */ | |
107 | ColormapChangeMask, /* ColormapNotify */ | |
108 | NonMaskableMask, /* ClientMessage */ | |
109 | NonMaskableMask /* MappingNotify */ | |
110 | }; | |
111 | ||
15c909ba | 112 | #ifndef HAVE_X11R5 |
07bf635f RS |
113 | |
114 | static /* in R5, this is not static, so we don't need to define it at all */ | |
115 | EventMask _XtConvertTypeToMask (eventType) | |
116 | int eventType; | |
117 | { | |
118 | eventType &= 0x7f; /* Events sent with XSendEvent have high bit set. */ | |
119 | if (eventType < XtNumber(masks)) | |
120 | return masks[eventType]; | |
121 | else | |
122 | return 0; | |
123 | } | |
124 | ||
15c909ba | 125 | #endif /* not HAVE_X11R5 */ |
07bf635f RS |
126 | |
127 | /* -- _XtOnGrabList() omitted -- */ | |
128 | ||
129 | ||
130 | static Widget LookupSpringLoaded(grabList) | |
131 | XtGrabList grabList; | |
132 | { | |
133 | XtGrabList gl; | |
134 | ||
135 | for (gl = grabList; gl != NULL; gl = gl->next) { | |
136 | if (gl->spring_loaded) | |
137 | if (XtIsSensitive(gl->widget)) | |
138 | return gl->widget; | |
139 | else | |
140 | return NULL; | |
141 | if (gl->exclusive) break; | |
142 | } | |
143 | return NULL; | |
144 | } | |
145 | ||
146 | ||
147 | \f | |
148 | /* This function is new. */ | |
149 | ||
150 | static Boolean WouldDispatchEvent(event, widget, mask, pd) | |
151 | register XEvent *event; | |
152 | Widget widget; | |
153 | EventMask mask; | |
154 | XtPerDisplay pd; | |
155 | { | |
156 | XtEventRec *p; | |
157 | Boolean would_dispatched = False; | |
158 | ||
159 | if ((mask == ExposureMask) || | |
160 | ((event->type == NoExpose) && NO_EXPOSE) || | |
161 | ((event->type == GraphicsExpose) && GRAPHICS_EXPOSE) ) | |
162 | if (widget->core.widget_class->core_class.expose != NULL ) | |
163 | return True; | |
164 | ||
165 | ||
166 | if ((mask == VisibilityChangeMask) && | |
167 | XtClass(widget)->core_class.visible_interest) | |
168 | return True; | |
169 | ||
170 | for (p=widget->core.event_table; p != NULL; p = p->next) | |
171 | if ((mask & p->mask) != 0 | |
15c909ba | 172 | #ifndef HAVE_X11R5 |
07bf635f RS |
173 | || (mask == 0 && p->non_filter) |
174 | #endif | |
175 | ) | |
176 | return True; | |
177 | ||
178 | return False; | |
179 | } | |
180 | ||
181 | ||
182 | /* #### This function is mostly copied from DecideToDispatch(). | |
183 | */ | |
184 | ||
185 | typedef enum _GrabType {pass, ignore, remap} GrabType; | |
186 | ||
187 | Widget | |
188 | XtWidgetToDispatchTo (XEvent* event) | |
189 | { | |
190 | register Widget widget; | |
191 | EventMask mask; | |
192 | GrabType grabType; | |
193 | Widget dspWidget; | |
194 | Time time = 0; | |
195 | XtPerDisplay pd; | |
196 | XtPerDisplayInput pdi; | |
197 | XtGrabList grabList; | |
198 | ||
199 | widget = XtWindowToWidget (event->xany.display, event->xany.window); | |
200 | pd = _XtGetPerDisplay(event->xany.display); | |
201 | pdi = _XtGetPerDisplayInput(event->xany.display); | |
202 | grabList = *_XtGetGrabList(pdi); | |
203 | ||
204 | mask = _XtConvertTypeToMask(event->xany.type); | |
205 | grabType = pass; | |
206 | switch (event->xany.type & 0x7f) { | |
207 | case KeyPress: | |
208 | case KeyRelease: grabType = remap; break; | |
209 | case ButtonPress: | |
210 | case ButtonRelease: grabType = remap; break; | |
211 | case MotionNotify: grabType = ignore; | |
212 | #define XKnownButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\ | |
213 | Button4MotionMask|Button5MotionMask) | |
214 | mask |= (event->xmotion.state & XKnownButtons); | |
215 | #undef XKnownButtons | |
216 | break; | |
217 | case EnterNotify: grabType = ignore; break; | |
218 | } | |
219 | ||
220 | if (widget == NULL) { | |
221 | if (grabType != remap) return False; | |
222 | /* event occurred in a non-widget window, but we've promised also | |
223 | to dispatch it to the nearest accessible spring_loaded widget */ | |
224 | else if ((widget = LookupSpringLoaded(grabList)) != NULL) | |
225 | return widget; | |
226 | return False; | |
227 | } | |
228 | ||
229 | switch(grabType) { | |
230 | case pass: | |
231 | return widget; | |
232 | ||
233 | case ignore: | |
234 | if ((grabList == NULL || _XtOnGrabList(widget,grabList)) | |
235 | && XtIsSensitive(widget)) { | |
236 | return widget; | |
237 | } | |
238 | return NULL; | |
239 | ||
240 | case remap: | |
241 | ||
242 | { | |
243 | Widget was_dispatched_to= NULL; | |
244 | extern Widget _XtFindRemapWidget(); | |
245 | extern void _XtUngrabBadGrabs(); | |
246 | ||
247 | dspWidget = _XtFindRemapWidget(event, widget, mask, pdi); | |
248 | ||
249 | if ((grabList == NULL || | |
250 | _XtOnGrabList(dspWidget, grabList)) && | |
251 | XtIsSensitive(dspWidget)) { | |
252 | if (WouldDispatchEvent (event, dspWidget, mask, pd)) | |
253 | was_dispatched_to = dspWidget; | |
254 | } | |
255 | ||
256 | /* Also dispatch to nearest accessible spring_loaded. */ | |
257 | /* Fetch this afterward to reflect modal list changes */ | |
258 | grabList = *_XtGetGrabList(pdi); | |
259 | widget = LookupSpringLoaded(grabList); | |
260 | if (widget != NULL && widget != dspWidget) { | |
261 | if (!was_dispatched_to) | |
262 | was_dispatched_to = widget; | |
263 | } | |
264 | ||
265 | return was_dispatched_to; | |
266 | } | |
267 | } | |
268 | /* should never reach here */ | |
269 | return NULL; | |
270 | } |