4 * Copyright 1993 Alexandre Julliard
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
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[] = {
42 "MOUSE_MOVED_ABSOLUTE",
45 "WINDOW_CLOSE_REQUESTED",
46 "WINDOW_DID_MINIMIZE",
47 "WINDOW_DID_UNMINIMIZE",
48 "WINDOW_FRAME_CHANGED",
53 if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
54 return wine_dbg_sprintf("Unknown event %d", type);
58 /***********************************************************************
61 static macdrv_event_mask get_event_mask(DWORD mask)
63 macdrv_event_mask event_mask = 0;
65 if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return -1;
69 event_mask |= event_mask_for_type(KEY_PRESS);
70 event_mask |= event_mask_for_type(KEY_RELEASE);
71 event_mask |= event_mask_for_type(KEYBOARD_CHANGED);
74 if (mask & QS_MOUSEBUTTON)
76 event_mask |= event_mask_for_type(MOUSE_BUTTON);
77 event_mask |= event_mask_for_type(MOUSE_SCROLL);
80 if (mask & QS_MOUSEMOVE)
82 event_mask |= event_mask_for_type(MOUSE_MOVED);
83 event_mask |= event_mask_for_type(MOUSE_MOVED_ABSOLUTE);
86 if (mask & QS_POSTMESSAGE)
88 event_mask |= event_mask_for_type(APP_DEACTIVATED);
89 event_mask |= event_mask_for_type(DISPLAYS_CHANGED);
90 event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
91 event_mask |= event_mask_for_type(WINDOW_DID_MINIMIZE);
92 event_mask |= event_mask_for_type(WINDOW_DID_UNMINIMIZE);
93 event_mask |= event_mask_for_type(WINDOW_FRAME_CHANGED);
94 event_mask |= event_mask_for_type(WINDOW_GOT_FOCUS);
95 event_mask |= event_mask_for_type(WINDOW_LOST_FOCUS);
98 if (mask & QS_SENDMESSAGE)
100 event_mask |= event_mask_for_type(QUERY_EVENT);
107 /***********************************************************************
110 * Handler for QUERY_EVENT queries.
112 static void macdrv_query_event(HWND hwnd, macdrv_event *event)
114 BOOL success = FALSE;
115 macdrv_query *query = event->query_event.query;
119 case QUERY_DRAG_DROP:
120 TRACE("QUERY_DRAG_DROP\n");
121 success = query_drag_drop(query);
123 case QUERY_DRAG_EXITED:
124 TRACE("QUERY_DRAG_EXITED\n");
125 success = query_drag_exited(query);
127 case QUERY_DRAG_OPERATION:
128 TRACE("QUERY_DRAG_OPERATION\n");
129 success = query_drag_operation(query);
131 case QUERY_PASTEBOARD_DATA:
132 TRACE("QUERY_PASTEBOARD_DATA\n");
133 success = query_pasteboard_data(hwnd, query->pasteboard_data.type);
136 FIXME("unrecognized query type %d\n", query->type);
140 TRACE("success %d\n", success);
141 query->status = success;
142 macdrv_set_query_done(query);
146 /***********************************************************************
147 * macdrv_handle_event
149 void macdrv_handle_event(macdrv_event *event)
151 HWND hwnd = macdrv_get_window_hwnd(event->window);
152 const macdrv_event *prev;
153 struct macdrv_thread_data *thread_data = macdrv_thread_data();
155 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event->type), hwnd,
158 prev = thread_data->current_event;
159 thread_data->current_event = event;
163 case APP_DEACTIVATED:
164 macdrv_app_deactivated();
166 case DISPLAYS_CHANGED:
167 macdrv_displays_changed(event);
171 macdrv_key_event(hwnd, event);
173 case KEYBOARD_CHANGED:
174 macdrv_keyboard_changed(event);
177 macdrv_mouse_button(hwnd, event);
180 case MOUSE_MOVED_ABSOLUTE:
181 macdrv_mouse_moved(hwnd, event);
184 macdrv_mouse_scroll(hwnd, event);
187 macdrv_query_event(hwnd, event);
189 case WINDOW_CLOSE_REQUESTED:
190 macdrv_window_close_requested(hwnd);
192 case WINDOW_DID_MINIMIZE:
193 macdrv_window_did_minimize(hwnd);
195 case WINDOW_DID_UNMINIMIZE:
196 macdrv_window_did_unminimize(hwnd);
198 case WINDOW_FRAME_CHANGED:
199 macdrv_window_frame_changed(hwnd, event->window_frame_changed.frame);
201 case WINDOW_GOT_FOCUS:
202 macdrv_window_got_focus(hwnd, event);
204 case WINDOW_LOST_FOCUS:
205 macdrv_window_lost_focus(hwnd, event);
208 TRACE(" ignoring\n");
212 thread_data->current_event = prev;
216 /***********************************************************************
219 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
224 while (macdrv_get_event_from_queue(queue, mask, &event))
227 macdrv_handle_event(&event);
228 macdrv_cleanup_event(&event);
230 if (count) TRACE("processed %d events\n", count);
235 /***********************************************************************
236 * MsgWaitForMultipleObjectsEx (MACDRV.@)
238 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
239 DWORD timeout, DWORD mask, DWORD flags)
242 struct macdrv_thread_data *data = macdrv_thread_data();
243 macdrv_event_mask event_mask = get_event_mask(mask);
245 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count,
246 handles, timeout, mask, flags);
250 if (!count && !timeout) return WAIT_TIMEOUT;
251 return WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
252 timeout, flags & MWMO_ALERTABLE);
255 if (data->current_event && data->current_event->type != QUERY_EVENT)
256 event_mask = 0; /* don't process nested events */
258 if (process_events(data->queue, event_mask)) ret = count - 1;
259 else if (count || timeout)
261 ret = WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
262 timeout, flags & MWMO_ALERTABLE);
263 if (ret == count - 1) process_events(data->queue, event_mask);
265 else ret = WAIT_TIMEOUT;