user32: Merge the AcquireClipboard and EmptyClipboard driver entry points.
[wine.git] / dlls / winemac.drv / event.c
blob58b507c51d1dad4509b9698278ef3be5388b6adb
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_DEACTIVATED",
36 "APP_QUIT_REQUESTED",
37 "DISPLAYS_CHANGED",
38 "HOTKEY_PRESS",
39 "IM_SET_TEXT",
40 "KEY_PRESS",
41 "KEY_RELEASE",
42 "KEYBOARD_CHANGED",
43 "MOUSE_BUTTON",
44 "MOUSE_MOVED",
45 "MOUSE_MOVED_ABSOLUTE",
46 "MOUSE_SCROLL",
47 "QUERY_EVENT",
48 "RELEASE_CAPTURE",
49 "STATUS_ITEM_MOUSE_BUTTON",
50 "STATUS_ITEM_MOUSE_MOVE",
51 "WINDOW_BROUGHT_FORWARD",
52 "WINDOW_CLOSE_REQUESTED",
53 "WINDOW_DID_UNMINIMIZE",
54 "WINDOW_DRAG_BEGIN",
55 "WINDOW_DRAG_END",
56 "WINDOW_FRAME_CHANGED",
57 "WINDOW_GOT_FOCUS",
58 "WINDOW_LOST_FOCUS",
59 "WINDOW_MAXIMIZE_REQUESTED",
60 "WINDOW_MINIMIZE_REQUESTED",
61 "WINDOW_RESIZE_ENDED",
62 "WINDOW_RESTORE_REQUESTED",
65 if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
66 return wine_dbg_sprintf("Unknown event %d", type);
70 /***********************************************************************
71 * get_event_mask
73 static macdrv_event_mask get_event_mask(DWORD mask)
75 macdrv_event_mask event_mask = 0;
77 if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return -1;
79 if (mask & QS_HOTKEY)
80 event_mask |= event_mask_for_type(HOTKEY_PRESS);
82 if (mask & QS_KEY)
84 event_mask |= event_mask_for_type(KEY_PRESS);
85 event_mask |= event_mask_for_type(KEY_RELEASE);
86 event_mask |= event_mask_for_type(KEYBOARD_CHANGED);
89 if (mask & QS_MOUSEBUTTON)
91 event_mask |= event_mask_for_type(MOUSE_BUTTON);
92 event_mask |= event_mask_for_type(MOUSE_SCROLL);
95 if (mask & QS_MOUSEMOVE)
97 event_mask |= event_mask_for_type(MOUSE_MOVED);
98 event_mask |= event_mask_for_type(MOUSE_MOVED_ABSOLUTE);
101 if (mask & QS_POSTMESSAGE)
103 event_mask |= event_mask_for_type(APP_DEACTIVATED);
104 event_mask |= event_mask_for_type(APP_QUIT_REQUESTED);
105 event_mask |= event_mask_for_type(DISPLAYS_CHANGED);
106 event_mask |= event_mask_for_type(IM_SET_TEXT);
107 event_mask |= event_mask_for_type(STATUS_ITEM_MOUSE_BUTTON);
108 event_mask |= event_mask_for_type(STATUS_ITEM_MOUSE_MOVE);
109 event_mask |= event_mask_for_type(WINDOW_DID_UNMINIMIZE);
110 event_mask |= event_mask_for_type(WINDOW_FRAME_CHANGED);
111 event_mask |= event_mask_for_type(WINDOW_GOT_FOCUS);
112 event_mask |= event_mask_for_type(WINDOW_LOST_FOCUS);
115 if (mask & QS_SENDMESSAGE)
117 event_mask |= event_mask_for_type(QUERY_EVENT);
118 event_mask |= event_mask_for_type(RELEASE_CAPTURE);
119 event_mask |= event_mask_for_type(WINDOW_BROUGHT_FORWARD);
120 event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
121 event_mask |= event_mask_for_type(WINDOW_DRAG_BEGIN);
122 event_mask |= event_mask_for_type(WINDOW_DRAG_END);
123 event_mask |= event_mask_for_type(WINDOW_MAXIMIZE_REQUESTED);
124 event_mask |= event_mask_for_type(WINDOW_MINIMIZE_REQUESTED);
125 event_mask |= event_mask_for_type(WINDOW_RESIZE_ENDED);
126 event_mask |= event_mask_for_type(WINDOW_RESTORE_REQUESTED);
129 return event_mask;
133 /***********************************************************************
134 * macdrv_query_event
136 * Handler for QUERY_EVENT queries.
138 static void macdrv_query_event(HWND hwnd, const macdrv_event *event)
140 BOOL success = FALSE;
141 macdrv_query *query = event->query_event.query;
143 switch (query->type)
145 case QUERY_DRAG_DROP:
146 TRACE("QUERY_DRAG_DROP\n");
147 success = query_drag_drop(query);
148 break;
149 case QUERY_DRAG_EXITED:
150 TRACE("QUERY_DRAG_EXITED\n");
151 success = query_drag_exited(query);
152 break;
153 case QUERY_DRAG_OPERATION:
154 TRACE("QUERY_DRAG_OPERATION\n");
155 success = query_drag_operation(query);
156 break;
157 case QUERY_IME_CHAR_RECT:
158 TRACE("QUERY_IME_CHAR_RECT\n");
159 success = query_ime_char_rect(query);
160 break;
161 case QUERY_PASTEBOARD_DATA:
162 TRACE("QUERY_PASTEBOARD_DATA\n");
163 success = query_pasteboard_data(hwnd, query->pasteboard_data.type);
164 break;
165 case QUERY_RESIZE_SIZE:
166 TRACE("QUERY_RESIZE_SIZE\n");
167 success = query_resize_size(hwnd, query);
168 break;
169 case QUERY_RESIZE_START:
170 TRACE("QUERY_RESIZE_START\n");
171 success = query_resize_start(hwnd);
172 break;
173 case QUERY_MIN_MAX_INFO:
174 TRACE("QUERY_MIN_MAX_INFO\n");
175 success = query_min_max_info(hwnd);
176 break;
177 default:
178 FIXME("unrecognized query type %d\n", query->type);
179 break;
182 TRACE("success %d\n", success);
183 query->status = success;
184 macdrv_set_query_done(query);
188 /***********************************************************************
189 * macdrv_handle_event
191 void macdrv_handle_event(const macdrv_event *event)
193 HWND hwnd = macdrv_get_window_hwnd(event->window);
194 const macdrv_event *prev;
195 struct macdrv_thread_data *thread_data = macdrv_thread_data();
197 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event->type), hwnd,
198 event->window);
200 prev = thread_data->current_event;
201 thread_data->current_event = event;
203 switch (event->type)
205 case APP_DEACTIVATED:
206 macdrv_app_deactivated();
207 break;
208 case APP_QUIT_REQUESTED:
209 macdrv_app_quit_requested(event);
210 break;
211 case DISPLAYS_CHANGED:
212 macdrv_displays_changed(event);
213 break;
214 case HOTKEY_PRESS:
215 macdrv_hotkey_press(event);
216 break;
217 case IM_SET_TEXT:
218 macdrv_im_set_text(event);
219 break;
220 case KEY_PRESS:
221 case KEY_RELEASE:
222 macdrv_key_event(hwnd, event);
223 break;
224 case KEYBOARD_CHANGED:
225 macdrv_keyboard_changed(event);
226 break;
227 case MOUSE_BUTTON:
228 macdrv_mouse_button(hwnd, event);
229 break;
230 case MOUSE_MOVED:
231 case MOUSE_MOVED_ABSOLUTE:
232 macdrv_mouse_moved(hwnd, event);
233 break;
234 case MOUSE_SCROLL:
235 macdrv_mouse_scroll(hwnd, event);
236 break;
237 case QUERY_EVENT:
238 macdrv_query_event(hwnd, event);
239 break;
240 case RELEASE_CAPTURE:
241 macdrv_release_capture(hwnd, event);
242 break;
243 case STATUS_ITEM_MOUSE_BUTTON:
244 macdrv_status_item_mouse_button(event);
245 break;
246 case STATUS_ITEM_MOUSE_MOVE:
247 macdrv_status_item_mouse_move(event);
248 break;
249 case WINDOW_BROUGHT_FORWARD:
250 macdrv_window_brought_forward(hwnd);
251 break;
252 case WINDOW_CLOSE_REQUESTED:
253 macdrv_window_close_requested(hwnd);
254 break;
255 case WINDOW_DID_UNMINIMIZE:
256 macdrv_window_did_unminimize(hwnd);
257 break;
258 case WINDOW_DRAG_BEGIN:
259 macdrv_window_drag_begin(hwnd);
260 break;
261 case WINDOW_DRAG_END:
262 macdrv_window_drag_end(hwnd);
263 break;
264 case WINDOW_FRAME_CHANGED:
265 macdrv_window_frame_changed(hwnd, event);
266 break;
267 case WINDOW_GOT_FOCUS:
268 macdrv_window_got_focus(hwnd, event);
269 break;
270 case WINDOW_LOST_FOCUS:
271 macdrv_window_lost_focus(hwnd, event);
272 break;
273 case WINDOW_MAXIMIZE_REQUESTED:
274 macdrv_window_maximize_requested(hwnd);
275 break;
276 case WINDOW_MINIMIZE_REQUESTED:
277 macdrv_window_minimize_requested(hwnd);
278 break;
279 case WINDOW_RESIZE_ENDED:
280 macdrv_window_resize_ended(hwnd);
281 break;
282 case WINDOW_RESTORE_REQUESTED:
283 macdrv_window_restore_requested(hwnd, event);
284 break;
285 default:
286 TRACE(" ignoring\n");
287 break;
290 thread_data->current_event = prev;
294 /***********************************************************************
295 * process_events
297 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
299 macdrv_event *event;
300 int count = 0;
302 while (macdrv_copy_event_from_queue(queue, mask, &event))
304 count++;
305 macdrv_handle_event(event);
306 macdrv_release_event(event);
308 if (count) TRACE("processed %d events\n", count);
309 return count;
313 /***********************************************************************
314 * MsgWaitForMultipleObjectsEx (MACDRV.@)
316 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
317 DWORD timeout, DWORD mask, DWORD flags)
319 DWORD ret;
320 struct macdrv_thread_data *data = macdrv_thread_data();
321 macdrv_event_mask event_mask = get_event_mask(mask);
323 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count,
324 handles, timeout, mask, flags);
326 if (!data)
328 if (!count && !timeout) return WAIT_TIMEOUT;
329 return WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
330 timeout, flags & MWMO_ALERTABLE);
333 if (data->current_event && data->current_event->type != QUERY_EVENT &&
334 data->current_event->type != APP_QUIT_REQUESTED &&
335 data->current_event->type != WINDOW_DRAG_BEGIN)
336 event_mask = 0; /* don't process nested events */
338 if (process_events(data->queue, event_mask)) ret = count - 1;
339 else if (count || timeout)
341 ret = WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
342 timeout, flags & MWMO_ALERTABLE);
343 if (ret == count - 1) process_events(data->queue, event_mask);
345 else ret = WAIT_TIMEOUT;
347 return ret;