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 "STATUS_ITEM_CLICKED",
46 "WINDOW_CLOSE_REQUESTED",
47 "WINDOW_DID_MINIMIZE",
48 "WINDOW_DID_UNMINIMIZE",
49 "WINDOW_FRAME_CHANGED",
54 if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
55 return wine_dbg_sprintf("Unknown event %d", type);
59 /***********************************************************************
62 static macdrv_event_mask get_event_mask(DWORD mask)
64 macdrv_event_mask event_mask = 0;
66 if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return -1;
70 event_mask |= event_mask_for_type(KEY_PRESS);
71 event_mask |= event_mask_for_type(KEY_RELEASE);
72 event_mask |= event_mask_for_type(KEYBOARD_CHANGED);
75 if (mask & QS_MOUSEBUTTON)
77 event_mask |= event_mask_for_type(MOUSE_BUTTON);
78 event_mask |= event_mask_for_type(MOUSE_SCROLL);
81 if (mask & QS_MOUSEMOVE)
83 event_mask |= event_mask_for_type(MOUSE_MOVED);
84 event_mask |= event_mask_for_type(MOUSE_MOVED_ABSOLUTE);
87 if (mask & QS_POSTMESSAGE)
89 event_mask |= event_mask_for_type(APP_DEACTIVATED);
90 event_mask |= event_mask_for_type(DISPLAYS_CHANGED);
91 event_mask |= event_mask_for_type(STATUS_ITEM_CLICKED);
92 event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
93 event_mask |= event_mask_for_type(WINDOW_DID_MINIMIZE);
94 event_mask |= event_mask_for_type(WINDOW_DID_UNMINIMIZE);
95 event_mask |= event_mask_for_type(WINDOW_FRAME_CHANGED);
96 event_mask |= event_mask_for_type(WINDOW_GOT_FOCUS);
97 event_mask |= event_mask_for_type(WINDOW_LOST_FOCUS);
100 if (mask & QS_SENDMESSAGE)
102 event_mask |= event_mask_for_type(QUERY_EVENT);
109 /***********************************************************************
112 * Handler for QUERY_EVENT queries.
114 static void macdrv_query_event(HWND hwnd, macdrv_event *event)
116 BOOL success = FALSE;
117 macdrv_query *query = event->query_event.query;
121 case QUERY_DRAG_DROP:
122 TRACE("QUERY_DRAG_DROP\n");
123 success = query_drag_drop(query);
125 case QUERY_DRAG_EXITED:
126 TRACE("QUERY_DRAG_EXITED\n");
127 success = query_drag_exited(query);
129 case QUERY_DRAG_OPERATION:
130 TRACE("QUERY_DRAG_OPERATION\n");
131 success = query_drag_operation(query);
133 case QUERY_PASTEBOARD_DATA:
134 TRACE("QUERY_PASTEBOARD_DATA\n");
135 success = query_pasteboard_data(hwnd, query->pasteboard_data.type);
138 FIXME("unrecognized query type %d\n", query->type);
142 TRACE("success %d\n", success);
143 query->status = success;
144 macdrv_set_query_done(query);
148 /***********************************************************************
149 * macdrv_handle_event
151 void macdrv_handle_event(macdrv_event *event)
153 HWND hwnd = macdrv_get_window_hwnd(event->window);
154 const macdrv_event *prev;
155 struct macdrv_thread_data *thread_data = macdrv_thread_data();
157 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event->type), hwnd,
160 prev = thread_data->current_event;
161 thread_data->current_event = event;
165 case APP_DEACTIVATED:
166 macdrv_app_deactivated();
168 case DISPLAYS_CHANGED:
169 macdrv_displays_changed(event);
173 macdrv_key_event(hwnd, event);
175 case KEYBOARD_CHANGED:
176 macdrv_keyboard_changed(event);
179 macdrv_mouse_button(hwnd, event);
182 case MOUSE_MOVED_ABSOLUTE:
183 macdrv_mouse_moved(hwnd, event);
186 macdrv_mouse_scroll(hwnd, event);
189 macdrv_query_event(hwnd, event);
191 case STATUS_ITEM_CLICKED:
192 macdrv_status_item_clicked(event);
194 case WINDOW_CLOSE_REQUESTED:
195 macdrv_window_close_requested(hwnd);
197 case WINDOW_DID_MINIMIZE:
198 macdrv_window_did_minimize(hwnd);
200 case WINDOW_DID_UNMINIMIZE:
201 macdrv_window_did_unminimize(hwnd);
203 case WINDOW_FRAME_CHANGED:
204 macdrv_window_frame_changed(hwnd, event->window_frame_changed.frame);
206 case WINDOW_GOT_FOCUS:
207 macdrv_window_got_focus(hwnd, event);
209 case WINDOW_LOST_FOCUS:
210 macdrv_window_lost_focus(hwnd, event);
213 TRACE(" ignoring\n");
217 thread_data->current_event = prev;
221 /***********************************************************************
224 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
229 while (macdrv_get_event_from_queue(queue, mask, &event))
232 macdrv_handle_event(&event);
233 macdrv_cleanup_event(&event);
235 if (count) TRACE("processed %d events\n", count);
240 /***********************************************************************
241 * MsgWaitForMultipleObjectsEx (MACDRV.@)
243 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
244 DWORD timeout, DWORD mask, DWORD flags)
247 struct macdrv_thread_data *data = macdrv_thread_data();
248 macdrv_event_mask event_mask = get_event_mask(mask);
250 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count,
251 handles, timeout, mask, flags);
255 if (!count && !timeout) return WAIT_TIMEOUT;
256 return WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
257 timeout, flags & MWMO_ALERTABLE);
260 if (data->current_event && data->current_event->type != QUERY_EVENT)
261 event_mask = 0; /* don't process nested events */
263 if (process_events(data->queue, event_mask)) ret = count - 1;
264 else if (count || timeout)
266 ret = WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
267 timeout, flags & MWMO_ALERTABLE);
268 if (ret == count - 1) process_events(data->queue, event_mask);
270 else ret = WAIT_TIMEOUT;