Mercurial > emacs
annotate oldXMenu/Activate.c @ 58760:a7b523bc82db
(GNU Free Documentation License): Fix To link.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 05 Dec 2004 14:01:03 +0000 |
parents | 9351060ba546 |
children | 8aef5660523e 3ec251523b3e b637c617432f |
rev | line source |
---|---|
25858 | 1 /* Copyright Massachusetts Institute of Technology 1985 */ |
2 | |
3 #include "copyright.h" | |
4 | |
5 /* | |
6 * XMenu: MIT Project Athena, X Window system menu package | |
7 * | |
8 * XMenuActivate - Maps a given menu to the display and activates | |
9 * the menu for user selection. The user is allowed to | |
10 * specify which pane and selection will be current, | |
11 * the X and Y location of the menu (relative to the | |
12 * parent window) and the mouse button event mask that | |
13 * will be used to identify a selection request. | |
14 * | |
15 * A menu selection is shown to be current by placing | |
16 * a highlight box around the selection as the mouse | |
17 * cursor enters its active region. Inactive selections | |
18 * will not be highlighted. As the mouse cursor moved | |
19 * from one menu pane to another menu pane the pane being | |
20 * entered is raised and made current and the pane being | |
21 * left is lowered. | |
22 * | |
23 * Anytime XMenuActivate returns, the p_num and | |
24 * s_num are left at their last known values (i.e., | |
25 * the last known current pane and selection indices). | |
26 * The following are the defined return states: | |
27 * | |
28 * 1) If at any time an error occurs the data | |
29 * pointer is left untouched and XM_FAILURE | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
30 * is returned. |
25858 | 31 * |
32 * 2) When a selection request is received (i.e., | |
33 * when the specified mouse event occurs) the | |
34 * data pointer will be set to the data | |
35 * associated with the particular selection | |
36 * current at the time of the selection request | |
37 * and XM_SUCCESS is returned. | |
38 * | |
39 * 3) If no selection was current at the time a | |
40 * selection request is made the data pointer | |
41 * will be left untouched and XM_NO_SELECT will | |
42 * be returned. | |
43 * | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
44 * 4) If the selection that was current at the time |
25858 | 45 * a selection request is made is not an active |
46 * selection the data pointer will be left | |
47 * untouched and XM_IA_SELECT will be returned. | |
48 * | |
49 * Since X processes events in an asynchronous manner | |
50 * it is likely that XMenuActivate will encounter | |
51 * a "foreign event" while it is executing. Foreign | |
52 * events are handled in one of three ways: | |
53 * | |
54 * 1) The event is discarded. This is the default | |
55 * mode and requires no action on the part of the | |
56 * application. | |
57 * | |
58 * 2) The application has identified an asynchronous | |
59 * event handler that will be called and the | |
60 * foreign event handed off to it. Note: | |
61 * AEQ mode disables this mode temporarily. | |
62 * | |
63 * 3) The application has enabled asynchronous event | |
64 * queuing mode. In this mode all foreign events | |
65 * will be queued up untill XMenuActivate | |
66 * terminates; at which time they will be | |
67 * returned to the X event queue. As long as | |
68 * AEQ mode is enabled any asynchronous event | |
69 * handler as temporarily disabled. | |
70 * | |
71 * Any events encountered while taking down the menu | |
72 * (i.e., exposure events from occluded windows) will | |
73 * automatically be returned to the X event queue after | |
74 * XMenuActivate has cleaned the queue of any of its own | |
75 * events that are no longer needed. | |
76 * | |
77 * Author: Tony Della Fera, DEC | |
78 * March 12, 1986 | |
79 * | |
80 */ | |
81 | |
82 #include <config.h> | |
83 #include "XMenuInt.h" | |
84 | |
44752
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
85 /* For debug, set this to 0 to not grab the keyboard on menu popup */ |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
86 int x_menu_grab_keyboard = 1; |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
87 |
58167
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
88 typedef void (*Wait_func)(); |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
89 |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
90 static Wait_func wait_func; |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
91 static void* wait_data; |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
92 |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
93 void |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
94 XMenuActivateSetWaitFunction (func, data) |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
95 Wait_func func; |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
96 void *data; |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
97 { |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
98 wait_func = func; |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
99 wait_data = data; |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
100 } |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
101 |
25858 | 102 int |
27457
bbfd0e676041
(XMenuActivate): Add parameter HELP_CALLBACK.
Gerd Moellmann <gerd@gnu.org>
parents:
25858
diff
changeset
|
103 XMenuActivate(display, menu, p_num, s_num, x_pos, y_pos, event_mask, data, |
bbfd0e676041
(XMenuActivate): Add parameter HELP_CALLBACK.
Gerd Moellmann <gerd@gnu.org>
parents:
25858
diff
changeset
|
104 help_callback) |
25858 | 105 register Display *display; /* Display to put menu on. */ |
106 register XMenu *menu; /* Menu to activate. */ | |
107 int *p_num; /* Pane number selected. */ | |
108 int *s_num; /* Selection number selected. */ | |
109 int x_pos; /* X coordinate of menu position. */ | |
110 int y_pos; /* Y coordinate of menu position. */ | |
111 unsigned int event_mask; /* Mouse button event mask. */ | |
112 char **data; /* Pointer to return data value. */ | |
27457
bbfd0e676041
(XMenuActivate): Add parameter HELP_CALLBACK.
Gerd Moellmann <gerd@gnu.org>
parents:
25858
diff
changeset
|
113 void (* help_callback) (); /* Help callback. */ |
25858 | 114 { |
115 int status; /* X routine call status. */ | |
116 int orig_x; /* Upper left menu origin X coord. */ | |
117 int orig_y; /* Upper left menu origin Y coord. */ | |
118 int ret_val; /* Return value. */ | |
119 | |
120 register XMPane *p_ptr; /* Current XMPane. */ | |
121 register XMPane *event_xmp; /* Event XMPane pointer. */ | |
122 register XMPane *cur_p; /* Current pane. */ | |
123 register XMSelect *cur_s; /* Current selection. */ | |
124 XMWindow *event_xmw; /* Event XMWindow pointer. */ | |
125 XEvent event; /* X input event. */ | |
126 XEvent peek_event; /* X input peek ahead event. */ | |
127 | |
128 Bool selection = False; /* Selection has been made. */ | |
129 Bool forward = True; /* Moving forward in the pane list. */ | |
130 | |
131 Window root, child; | |
132 int root_x, root_y, win_x, win_y; | |
133 unsigned int mask; | |
134 | |
135 /* | |
136 * Define and allocate a foreign event queue to hold events | |
137 * that don't belong to XMenu. These events are later restored | |
138 * to the X event queue. | |
139 */ | |
140 typedef struct _xmeventque { | |
141 XEvent event; | |
142 struct _xmeventque *next; | |
143 } XMEventQue; | |
144 | |
145 XMEventQue *feq = NULL; /* Foreign event queue. */ | |
146 XMEventQue *feq_tmp; /* Foreign event queue temporary. */ | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
147 |
25858 | 148 /* |
149 * If there are no panes in the menu then return failure | |
150 * because the menu is not initialized. | |
151 */ | |
152 if (menu->p_count == 0) { | |
153 _XMErrorCode = XME_NOT_INIT; | |
154 return(XM_FAILURE); | |
155 } | |
156 | |
157 /* | |
158 * Find the desired current pane. | |
159 */ | |
160 cur_p = _XMGetPanePtr(menu, *p_num); | |
161 if (cur_p == NULL) { | |
162 return(XM_FAILURE); | |
163 } | |
164 cur_p->activated = cur_p->active; | |
165 | |
166 /* | |
167 * Find the desired current selection. | |
168 * If the current selection index is out of range a null current selection | |
169 * will be assumed and the cursor will be placed in the current pane | |
170 * header. | |
171 */ | |
172 cur_s = _XMGetSelectionPtr(cur_p, *s_num); | |
173 | |
174 /* | |
175 * Compute origin of menu so that cursor is in | |
176 * Correct pane and selection. | |
177 */ | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
178 _XMTransToOrigin(display, |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
179 menu, |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
180 cur_p, cur_s, |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
181 x_pos, y_pos, |
25858 | 182 &orig_x, &orig_y); |
183 menu->x_pos = orig_x; /* Store X and Y coords of menu. */ | |
184 menu->y_pos = orig_y; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
185 |
25858 | 186 if (XMenuRecompute(display, menu) == XM_FAILURE) { |
187 return(XM_FAILURE); | |
188 } | |
189 | |
190 /* | |
191 * Flush the window creation queue. | |
192 * This batches all window creates since lazy evaluation | |
193 * is more efficient than individual evaluation. | |
194 * This routine also does an XFlush(). | |
195 */ | |
196 if (_XMWinQueFlush(display, menu, cur_p, cur_s) == _FAILURE) { | |
197 return(XM_FAILURE); | |
198 } | |
199 | |
200 /* | |
201 * Make sure windows are in correct order (in case we were passed | |
202 * an already created menu in incorrect order.) | |
203 */ | |
204 for(p_ptr = menu->p_list->next; p_ptr != cur_p; p_ptr = p_ptr->next) | |
205 XRaiseWindow(display, p_ptr->window); | |
206 for(p_ptr = menu->p_list->prev; p_ptr != cur_p->prev; p_ptr = p_ptr->prev) | |
207 XRaiseWindow(display, p_ptr->window); | |
208 | |
209 /* | |
210 * Make sure all selection windows are mapped. | |
211 */ | |
212 for ( | |
213 p_ptr = menu->p_list->next; | |
214 p_ptr != menu->p_list; | |
215 p_ptr = p_ptr->next | |
216 ){ | |
217 XMapSubwindows(display, p_ptr->window); | |
218 } | |
219 | |
220 /* | |
221 * Synchronize the X buffers and the event queue. | |
222 * From here on, all events in the queue that don't belong to | |
223 * XMenu are sent back to the application via an application | |
224 * provided event handler or discarded if the application has | |
225 * not provided an event handler. | |
226 */ | |
227 XSync(display, 0); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
228 |
25858 | 229 /* |
230 * Grab the mouse for menu input. | |
231 */ | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
232 |
25858 | 233 status = XGrabPointer( |
234 display, | |
235 menu->parent, | |
236 True, | |
237 event_mask, | |
238 GrabModeAsync, | |
239 GrabModeAsync, | |
240 None, | |
241 menu->mouse_cursor, | |
242 CurrentTime | |
243 ); | |
44752
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
244 if (status == Success && x_menu_grab_keyboard) |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
245 { |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
246 status = XGrabKeyboard (display, |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
247 menu->parent, |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
248 False, |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
249 GrabModeAsync, |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
250 GrabModeAsync, |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
251 CurrentTime); |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
252 if (status != Success) |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
253 XUngrabPointer(display, CurrentTime); |
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
254 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
255 |
25858 | 256 if (status == _X_FAILURE) { |
257 _XMErrorCode = XME_GRAB_MOUSE; | |
258 return(XM_FAILURE); | |
259 } | |
260 | |
261 /* | |
262 * Map the menu panes. | |
263 */ | |
264 XMapWindow(display, cur_p->window); | |
265 for (p_ptr = menu->p_list->next; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
266 p_ptr != cur_p; |
25858 | 267 p_ptr = p_ptr->next) |
268 XMapWindow(display, p_ptr->window); | |
269 for (p_ptr = cur_p->next; | |
270 p_ptr != menu->p_list; | |
271 p_ptr = p_ptr->next) | |
272 XMapWindow(display, p_ptr->window); | |
273 | |
274 XRaiseWindow(display, cur_p->window); /* Make sure current */ | |
275 /* pane is on top. */ | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
276 |
25858 | 277 cur_s = NULL; /* Clear current selection. */ |
278 | |
279 /* | |
280 * Begin event processing loop. | |
281 */ | |
282 while (1) { | |
58167
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
283 if (wait_func) (*wait_func) (wait_data); |
25858 | 284 XNextEvent(display, &event); /* Get next event. */ |
285 switch (event.type) { /* Dispatch on the event type. */ | |
286 case Expose: | |
287 event_xmp = (XMPane *)XLookUpAssoc(display, | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
288 menu->assoc_tab, |
25858 | 289 event.xexpose.window); |
290 if (event_xmp == NULL) { | |
291 /* | |
292 * If AEQ mode is enabled then queue the event. | |
293 */ | |
294 if (menu->aeq) { | |
295 feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); | |
296 if (feq_tmp == NULL) { | |
297 _XMErrorCode = XME_CALLOC; | |
298 return(XM_FAILURE); | |
299 } | |
300 feq_tmp->event = event; | |
301 feq_tmp->next = feq; | |
302 feq = feq_tmp; | |
303 } | |
304 else if (_XMEventHandler) (*_XMEventHandler)(&event); | |
305 break; | |
306 } | |
307 if (event_xmp->activated) { | |
308 XSetWindowBackground(display, | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
309 event_xmp->window, |
25858 | 310 menu->bkgnd_color); |
311 } | |
312 else { | |
313 XSetWindowBackgroundPixmap(display, | |
314 event_xmp->window, | |
315 menu->inact_pixmap); | |
316 } | |
317 _XMRefreshPane(display, menu, event_xmp); | |
318 break; | |
319 case EnterNotify: | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
320 /* |
25858 | 321 * First wait a small period of time, and see |
322 * if another EnterNotify event follows hard on the | |
323 * heels of this one. i.e., the user is simply | |
324 * "passing through". If so, ignore this one. | |
325 */ | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
326 |
25858 | 327 event_xmw = (XMWindow *)XLookUpAssoc(display, |
328 menu->assoc_tab, | |
329 event.xcrossing.window); | |
330 if (event_xmw == NULL) break; | |
331 if (event_xmw->type == SELECTION) { | |
332 /* | |
333 * We have entered a selection. | |
334 */ | |
335 /* if (XPending(display) == 0) usleep(150000); */ | |
336 if (XPending(display) != 0) { | |
337 XPeekEvent(display, &peek_event); | |
338 if(peek_event.type == LeaveNotify) { | |
339 break; | |
340 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
341 } |
25858 | 342 cur_s = (XMSelect *)event_xmw; |
30365
5eece465cb5d
(XMenuActivate): Call help callback with two more
Gerd Moellmann <gerd@gnu.org>
parents:
27457
diff
changeset
|
343 help_callback (cur_s->help_string, |
5eece465cb5d
(XMenuActivate): Call help callback with two more
Gerd Moellmann <gerd@gnu.org>
parents:
27457
diff
changeset
|
344 cur_p->serial, cur_s->serial); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
345 |
25858 | 346 /* |
347 * If the pane we are in is active and the | |
348 * selection entered is active then activate | |
349 * the selection. | |
350 */ | |
351 if (cur_p->active && cur_s->active > 0) { | |
352 cur_s->activated = 1; | |
353 _XMRefreshSelection(display, menu, cur_s); | |
354 } | |
355 } | |
356 else { | |
357 /* | |
358 * We have entered a pane. | |
359 */ | |
360 /* if (XPending(display) == 0) usleep(150000); */ | |
361 if (XPending(display) != 0) { | |
362 XPeekEvent(display, &peek_event); | |
363 if (peek_event.type == EnterNotify) break; | |
364 } | |
365 XQueryPointer(display, | |
366 menu->parent, | |
367 &root, &child, | |
368 &root_x, &root_y, | |
369 &win_x, &win_y, | |
370 &mask); | |
371 event_xmp = (XMPane *)XLookUpAssoc(display, | |
372 menu->assoc_tab, | |
373 child); | |
374 if (event_xmp == NULL) break; | |
375 if (event_xmp == cur_p) break; | |
376 if (event_xmp->serial > cur_p->serial) forward = True; | |
377 else forward = False; | |
378 p_ptr = cur_p; | |
379 while (p_ptr != event_xmp) { | |
380 if (forward) p_ptr = p_ptr->next; | |
381 else p_ptr = p_ptr->prev; | |
382 XRaiseWindow(display, p_ptr->window); | |
383 } | |
384 if (cur_p->activated) { | |
385 cur_p->activated = False; | |
386 XSetWindowBackgroundPixmap(display, | |
387 cur_p->window, | |
388 menu->inact_pixmap); | |
389 _XMRefreshPane(display, menu, cur_p); | |
390 } | |
391 if (event_xmp->active) event_xmp->activated = True; | |
392 #if 1 | |
393 /* | |
394 * i suspect the we don't get an EXPOSE event when backing | |
395 * store is enabled; the menu windows content is probably | |
396 * not drawn in when it should be in that case. | |
397 * in that case, this is probably an ugly fix! | |
398 * i hope someone more familiar with this code would | |
399 * take it from here. -- caveh@eng.sun.com. | |
400 */ | |
401 XSetWindowBackground(display, | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
402 event_xmp->window, |
25858 | 403 menu->bkgnd_color); |
404 _XMRefreshPane(display, menu, event_xmp); | |
405 #endif | |
406 cur_p = event_xmp; | |
407 } | |
408 break; | |
409 case LeaveNotify: | |
410 event_xmw = (XMWindow *)XLookUpAssoc( | |
411 display, | |
412 menu->assoc_tab, | |
413 event.xcrossing.window | |
414 ); | |
415 if (event_xmw == NULL) break; | |
416 if(cur_s == NULL) break; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
417 |
25858 | 418 /* |
419 * If the current selection was activated then | |
420 * deactivate it. | |
421 */ | |
422 if (cur_s->activated) { | |
423 cur_s->activated = False; | |
424 _XMRefreshSelection(display, menu, cur_s); | |
425 } | |
426 cur_s = NULL; | |
427 break; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
428 |
25858 | 429 case ButtonPress: |
430 case ButtonRelease: | |
431 *p_num = cur_p->serial; | |
432 /* | |
433 * Check to see if there is a current selection. | |
434 */ | |
435 if (cur_s != NULL) { | |
436 /* | |
437 * Set the selection number to the current selection. | |
438 */ | |
439 *s_num = cur_s->serial; | |
440 /* | |
441 * If the current selection was activated then | |
442 * we have a valid selection otherwise we have | |
443 * an inactive selection. | |
444 */ | |
445 if (cur_s->activated) { | |
446 *data = cur_s->data; | |
447 ret_val = XM_SUCCESS; | |
448 } | |
449 else { | |
450 ret_val = XM_IA_SELECT; | |
451 } | |
452 } | |
453 else { | |
454 /* | |
455 * No selection was current. | |
456 */ | |
457 ret_val = XM_NO_SELECT; | |
458 } | |
459 selection = True; | |
460 break; | |
461 default: | |
462 /* | |
463 * If AEQ mode is enabled then queue the event. | |
464 */ | |
465 if (menu->aeq) { | |
466 feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); | |
467 if (feq_tmp == NULL) { | |
468 _XMErrorCode = XME_CALLOC; | |
469 return(XM_FAILURE); | |
470 } | |
471 feq_tmp->event = event; | |
472 feq_tmp->next = feq; | |
473 feq = feq_tmp; | |
474 } | |
475 else if (_XMEventHandler) (*_XMEventHandler)(&event); | |
476 } | |
477 /* | |
478 * If a selection has been made, break out of the event loop. | |
479 */ | |
480 if (selection == True) break; | |
481 } | |
482 | |
483 /* | |
484 * Unmap the menu. | |
485 */ | |
486 for ( p_ptr = menu->p_list->next; | |
487 p_ptr != menu->p_list; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
488 p_ptr = p_ptr->next) |
25858 | 489 { |
490 XUnmapWindow(display, p_ptr->window); | |
491 } | |
492 | |
493 /* | |
494 * Ungrab the mouse. | |
495 */ | |
496 XUngrabPointer(display, CurrentTime); | |
44752
17275bfd5698
Add calls to GrabKeyboard to remove strange
Jan Djärv <jan.h.d@swipnet.se>
parents:
30365
diff
changeset
|
497 XUngrabKeyboard(display, CurrentTime); |
25858 | 498 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
499 /* |
25858 | 500 * Restore bits under where the menu was if we managed |
501 * to save them and free the pixmap. | |
502 */ | |
503 | |
504 /* | |
505 * If there is a current selection deactivate it. | |
506 */ | |
507 if (cur_s != NULL) cur_s->activated = 0; | |
508 | |
509 /* | |
510 * Deactivate the current pane. | |
511 */ | |
512 cur_p->activated = 0; | |
513 XSetWindowBackgroundPixmap(display, cur_p->window, menu->inact_pixmap); | |
514 | |
515 /* | |
516 * Synchronize the X buffers and the X event queue. | |
517 */ | |
518 XSync(display, 0); | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
519 |
25858 | 520 /* |
521 * Dispatch any events remaining on the queue. | |
522 */ | |
523 while (QLength(display)) { | |
524 /* | |
525 * Fetch the next event. | |
526 */ | |
527 XNextEvent(display, &event); | |
528 | |
529 /* | |
530 * Discard any events left on the queue that belong to XMenu. | |
531 * All others are held and then returned to the event queue. | |
532 */ | |
533 switch (event.type) { | |
534 case Expose: | |
535 case EnterNotify: | |
536 case LeaveNotify: | |
537 case ButtonPress: | |
538 case ButtonRelease: | |
539 /* | |
540 * Does this event belong to one of XMenu's windows? | |
541 * If so, discard it and process the next event. | |
542 * If not fall through and treat it as a foreign event. | |
543 */ | |
544 event_xmp = (XMPane *)XLookUpAssoc( | |
545 display, | |
546 menu->assoc_tab, | |
547 event.xbutton.window | |
548 ); | |
549 if (event_xmp != NULL) continue; | |
550 default: | |
551 /* | |
552 * This is a foreign event. | |
553 * Queue it for later return to the X event queue. | |
554 */ | |
555 feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); | |
556 if (feq_tmp == NULL) { | |
557 _XMErrorCode = XME_CALLOC; | |
558 return(XM_FAILURE); | |
559 } | |
560 feq_tmp->event = event; | |
561 feq_tmp->next = feq; | |
562 feq = feq_tmp; | |
563 } | |
564 } | |
565 /* | |
566 * Return any foreign events that were queued to the X event queue. | |
567 */ | |
568 while (feq != NULL) { | |
569 feq_tmp = feq; | |
570 XPutBackEvent(display, &feq_tmp->event); | |
571 feq = feq_tmp->next; | |
572 free((char *)feq_tmp); | |
573 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44752
diff
changeset
|
574 |
58167
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
575 wait_func = 0; |
9351060ba546
* XMenu.h (XMenuActivateSetWaitFunction): New function.
Jan Djärv <jan.h.d@swipnet.se>
parents:
54770
diff
changeset
|
576 |
25858 | 577 /* |
578 * Return successfully. | |
579 */ | |
580 _XMErrorCode = XME_NO_ERROR; | |
581 return(ret_val); | |
582 | |
583 } | |
52401 | 584 |
585 /* arch-tag: 6b90b578-ecea-4328-b460-a0c96963f872 | |
586 (do not change this comment) */ |