widl: Silence a gcc warning.
[wine.git] / dlls / winemac.drv / event.c
blob7ec59c0f9038142cc9980d45d64420828c7a5e07
1 /*
2 * MACDRV event driver
4 * Copyright 1993 Alexandre Julliard
5 * 1999 Noel Borthwick
6 * Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
25 #include "macdrv.h"
26 #include "winuser.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(event);
31 /* return the name of an Mac event */
32 static const char *dbgstr_event(int type)
34 static const char * const event_names[] = {
35 "APP_ACTIVATED",
36 "APP_DEACTIVATED",
37 "APP_QUIT_REQUESTED",
38 "DISPLAYS_CHANGED",
39 "HOTKEY_PRESS",
40 "IM_SET_TEXT",
41 "KEY_PRESS",
42 "KEY_RELEASE",
43 "KEYBOARD_CHANGED",
44 "LOST_PASTEBOARD_OWNERSHIP",
45 "MOUSE_BUTTON",
46 "MOUSE_MOVED",
47 "MOUSE_MOVED_ABSOLUTE",
48 "MOUSE_SCROLL",
49 "QUERY_EVENT",
50 "QUERY_EVENT_NO_PREEMPT_WAIT",
51 "REASSERT_WINDOW_POSITION",
52 "RELEASE_CAPTURE",
53 "SENT_TEXT_INPUT",
54 "STATUS_ITEM_MOUSE_BUTTON",
55 "STATUS_ITEM_MOUSE_MOVE",
56 "WINDOW_BROUGHT_FORWARD",
57 "WINDOW_CLOSE_REQUESTED",
58 "WINDOW_DID_UNMINIMIZE",
59 "WINDOW_DRAG_BEGIN",
60 "WINDOW_DRAG_END",
61 "WINDOW_FRAME_CHANGED",
62 "WINDOW_GOT_FOCUS",
63 "WINDOW_LOST_FOCUS",
64 "WINDOW_MAXIMIZE_REQUESTED",
65 "WINDOW_MINIMIZE_REQUESTED",
66 "WINDOW_RESIZE_ENDED",
67 "WINDOW_RESTORE_REQUESTED",
70 if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
71 return wine_dbg_sprintf("Unknown event %d", type);
75 /***********************************************************************
76 * get_event_mask
78 static macdrv_event_mask get_event_mask(DWORD mask)
80 macdrv_event_mask event_mask = 0;
82 if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return -1;
84 if (mask & QS_HOTKEY)
85 event_mask |= event_mask_for_type(HOTKEY_PRESS);
87 if (mask & QS_KEY)
89 event_mask |= event_mask_for_type(KEY_PRESS);
90 event_mask |= event_mask_for_type(KEY_RELEASE);
91 event_mask |= event_mask_for_type(KEYBOARD_CHANGED);
94 if (mask & QS_MOUSEBUTTON)
96 event_mask |= event_mask_for_type(MOUSE_BUTTON);
97 event_mask |= event_mask_for_type(MOUSE_SCROLL);
100 if (mask & QS_MOUSEMOVE)
102 event_mask |= event_mask_for_type(MOUSE_MOVED);
103 event_mask |= event_mask_for_type(MOUSE_MOVED_ABSOLUTE);
106 if (mask & QS_POSTMESSAGE)
108 event_mask |= event_mask_for_type(APP_ACTIVATED);
109 event_mask |= event_mask_for_type(APP_DEACTIVATED);
110 event_mask |= event_mask_for_type(APP_QUIT_REQUESTED);
111 event_mask |= event_mask_for_type(DISPLAYS_CHANGED);
112 event_mask |= event_mask_for_type(IM_SET_TEXT);
113 event_mask |= event_mask_for_type(LOST_PASTEBOARD_OWNERSHIP);
114 event_mask |= event_mask_for_type(STATUS_ITEM_MOUSE_BUTTON);
115 event_mask |= event_mask_for_type(STATUS_ITEM_MOUSE_MOVE);
116 event_mask |= event_mask_for_type(WINDOW_DID_UNMINIMIZE);
117 event_mask |= event_mask_for_type(WINDOW_FRAME_CHANGED);
118 event_mask |= event_mask_for_type(WINDOW_GOT_FOCUS);
119 event_mask |= event_mask_for_type(WINDOW_LOST_FOCUS);
122 if (mask & QS_SENDMESSAGE)
124 event_mask |= event_mask_for_type(QUERY_EVENT);
125 event_mask |= event_mask_for_type(QUERY_EVENT_NO_PREEMPT_WAIT);
126 event_mask |= event_mask_for_type(REASSERT_WINDOW_POSITION);
127 event_mask |= event_mask_for_type(RELEASE_CAPTURE);
128 event_mask |= event_mask_for_type(SENT_TEXT_INPUT);
129 event_mask |= event_mask_for_type(WINDOW_BROUGHT_FORWARD);
130 event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
131 event_mask |= event_mask_for_type(WINDOW_DRAG_BEGIN);
132 event_mask |= event_mask_for_type(WINDOW_DRAG_END);
133 event_mask |= event_mask_for_type(WINDOW_MAXIMIZE_REQUESTED);
134 event_mask |= event_mask_for_type(WINDOW_MINIMIZE_REQUESTED);
135 event_mask |= event_mask_for_type(WINDOW_RESIZE_ENDED);
136 event_mask |= event_mask_for_type(WINDOW_RESTORE_REQUESTED);
139 return event_mask;
143 /***********************************************************************
144 * macdrv_query_event
146 * Handler for QUERY_EVENT and QUERY_EVENT_NO_PREEMPT_WAIT queries.
148 static void macdrv_query_event(HWND hwnd, const macdrv_event *event)
150 BOOL success = FALSE;
151 macdrv_query *query = event->query_event.query;
153 switch (query->type)
155 case QUERY_DRAG_DROP:
156 TRACE("QUERY_DRAG_DROP\n");
157 success = query_drag_drop(query);
158 break;
159 case QUERY_DRAG_EXITED:
160 TRACE("QUERY_DRAG_EXITED\n");
161 success = query_drag_exited(query);
162 break;
163 case QUERY_DRAG_OPERATION:
164 TRACE("QUERY_DRAG_OPERATION\n");
165 success = query_drag_operation(query);
166 break;
167 case QUERY_IME_CHAR_RECT:
168 TRACE("QUERY_IME_CHAR_RECT\n");
169 success = query_ime_char_rect(query);
170 break;
171 case QUERY_PASTEBOARD_DATA:
172 TRACE("QUERY_PASTEBOARD_DATA\n");
173 success = query_pasteboard_data(hwnd, query->pasteboard_data.type);
174 break;
175 case QUERY_RESIZE_SIZE:
176 TRACE("QUERY_RESIZE_SIZE\n");
177 success = query_resize_size(hwnd, query);
178 break;
179 case QUERY_RESIZE_START:
180 TRACE("QUERY_RESIZE_START\n");
181 success = query_resize_start(hwnd);
182 break;
183 case QUERY_MIN_MAX_INFO:
184 TRACE("QUERY_MIN_MAX_INFO\n");
185 success = query_min_max_info(hwnd);
186 break;
187 default:
188 FIXME("unrecognized query type %d\n", query->type);
189 break;
192 TRACE("success %d\n", success);
193 query->status = success;
194 macdrv_set_query_done(query);
198 /***********************************************************************
199 * macdrv_handle_event
201 void macdrv_handle_event(const macdrv_event *event)
203 HWND hwnd = macdrv_get_window_hwnd(event->window);
204 const macdrv_event *prev;
205 struct macdrv_thread_data *thread_data = macdrv_thread_data();
207 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event->type), hwnd,
208 event->window);
210 prev = thread_data->current_event;
211 thread_data->current_event = event;
213 switch (event->type)
215 case APP_ACTIVATED:
216 macdrv_app_activated();
217 break;
218 case APP_DEACTIVATED:
219 macdrv_app_deactivated();
220 break;
221 case APP_QUIT_REQUESTED:
222 macdrv_app_quit_requested(event);
223 break;
224 case DISPLAYS_CHANGED:
225 macdrv_displays_changed(event);
226 break;
227 case HOTKEY_PRESS:
228 macdrv_hotkey_press(event);
229 break;
230 case IM_SET_TEXT:
231 macdrv_im_set_text(event);
232 break;
233 case KEY_PRESS:
234 case KEY_RELEASE:
235 macdrv_key_event(hwnd, event);
236 break;
237 case KEYBOARD_CHANGED:
238 macdrv_keyboard_changed(event);
239 break;
240 case LOST_PASTEBOARD_OWNERSHIP:
241 macdrv_lost_pasteboard_ownership(hwnd);
242 break;
243 case MOUSE_BUTTON:
244 macdrv_mouse_button(hwnd, event);
245 break;
246 case MOUSE_MOVED:
247 case MOUSE_MOVED_ABSOLUTE:
248 macdrv_mouse_moved(hwnd, event);
249 break;
250 case MOUSE_SCROLL:
251 macdrv_mouse_scroll(hwnd, event);
252 break;
253 case QUERY_EVENT:
254 case QUERY_EVENT_NO_PREEMPT_WAIT:
255 macdrv_query_event(hwnd, event);
256 break;
257 case REASSERT_WINDOW_POSITION:
258 macdrv_reassert_window_position(hwnd);
259 break;
260 case RELEASE_CAPTURE:
261 macdrv_release_capture(hwnd, event);
262 break;
263 case SENT_TEXT_INPUT:
264 macdrv_sent_text_input(event);
265 break;
266 case STATUS_ITEM_MOUSE_BUTTON:
267 macdrv_status_item_mouse_button(event);
268 break;
269 case STATUS_ITEM_MOUSE_MOVE:
270 macdrv_status_item_mouse_move(event);
271 break;
272 case WINDOW_BROUGHT_FORWARD:
273 macdrv_window_brought_forward(hwnd);
274 break;
275 case WINDOW_CLOSE_REQUESTED:
276 macdrv_window_close_requested(hwnd);
277 break;
278 case WINDOW_DID_UNMINIMIZE:
279 macdrv_window_did_unminimize(hwnd);
280 break;
281 case WINDOW_DRAG_BEGIN:
282 macdrv_window_drag_begin(hwnd, event);
283 break;
284 case WINDOW_DRAG_END:
285 macdrv_window_drag_end(hwnd);
286 break;
287 case WINDOW_FRAME_CHANGED:
288 macdrv_window_frame_changed(hwnd, event);
289 break;
290 case WINDOW_GOT_FOCUS:
291 macdrv_window_got_focus(hwnd, event);
292 break;
293 case WINDOW_LOST_FOCUS:
294 macdrv_window_lost_focus(hwnd, event);
295 break;
296 case WINDOW_MAXIMIZE_REQUESTED:
297 macdrv_window_maximize_requested(hwnd);
298 break;
299 case WINDOW_MINIMIZE_REQUESTED:
300 macdrv_window_minimize_requested(hwnd);
301 break;
302 case WINDOW_RESIZE_ENDED:
303 macdrv_window_resize_ended(hwnd);
304 break;
305 case WINDOW_RESTORE_REQUESTED:
306 macdrv_window_restore_requested(hwnd, event);
307 break;
308 default:
309 TRACE(" ignoring\n");
310 break;
313 thread_data->current_event = prev;
317 /***********************************************************************
318 * process_events
320 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
322 macdrv_event *event;
323 int count = 0;
325 while (macdrv_copy_event_from_queue(queue, mask, &event))
327 count++;
328 macdrv_handle_event(event);
329 macdrv_release_event(event);
331 if (count) TRACE("processed %d events\n", count);
332 return count;
336 /***********************************************************************
337 * MsgWaitForMultipleObjectsEx (MACDRV.@)
339 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
340 DWORD timeout, DWORD mask, DWORD flags)
342 DWORD ret;
343 struct macdrv_thread_data *data = macdrv_thread_data();
344 macdrv_event_mask event_mask = get_event_mask(mask);
346 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count,
347 handles, timeout, mask, flags);
349 if (!data)
351 if (!count && !timeout) return WAIT_TIMEOUT;
352 return WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
353 timeout, flags & MWMO_ALERTABLE);
356 if (data->current_event && data->current_event->type != QUERY_EVENT &&
357 data->current_event->type != QUERY_EVENT_NO_PREEMPT_WAIT &&
358 data->current_event->type != APP_QUIT_REQUESTED &&
359 data->current_event->type != WINDOW_DRAG_BEGIN)
360 event_mask = 0; /* don't process nested events */
362 if (process_events(data->queue, event_mask)) ret = count - 1;
363 else if (count || timeout)
365 ret = WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
366 timeout, flags & MWMO_ALERTABLE);
367 if (ret == count - 1) process_events(data->queue, event_mask);
369 else ret = WAIT_TIMEOUT;
371 return ret;