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[] = {
37 "WINDOW_CLOSE_REQUESTED",
38 "WINDOW_FRAME_CHANGED",
43 if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
44 return wine_dbg_sprintf("Unknown event %d", type);
48 /***********************************************************************
51 static macdrv_event_mask get_event_mask(DWORD mask)
53 macdrv_event_mask event_mask = 0;
55 if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return -1;
57 if (mask & QS_MOUSEBUTTON)
58 event_mask |= event_mask_for_type(MOUSE_BUTTON);
60 if (mask & QS_POSTMESSAGE)
62 event_mask |= event_mask_for_type(APP_DEACTIVATED);
63 event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
64 event_mask |= event_mask_for_type(WINDOW_FRAME_CHANGED);
65 event_mask |= event_mask_for_type(WINDOW_GOT_FOCUS);
66 event_mask |= event_mask_for_type(WINDOW_LOST_FOCUS);
73 /***********************************************************************
76 void macdrv_handle_event(macdrv_event *event)
78 HWND hwnd = macdrv_get_window_hwnd(event->window);
79 const macdrv_event *prev;
80 struct macdrv_thread_data *thread_data = macdrv_thread_data();
82 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event->type), hwnd,
85 prev = thread_data->current_event;
86 thread_data->current_event = event;
91 macdrv_app_deactivated();
94 macdrv_mouse_button(hwnd, event);
96 case WINDOW_CLOSE_REQUESTED:
97 macdrv_window_close_requested(hwnd);
99 case WINDOW_FRAME_CHANGED:
100 macdrv_window_frame_changed(hwnd, event->window_frame_changed.frame);
102 case WINDOW_GOT_FOCUS:
103 macdrv_window_got_focus(hwnd, event);
105 case WINDOW_LOST_FOCUS:
106 macdrv_window_lost_focus(hwnd, event);
109 TRACE(" ignoring\n");
113 thread_data->current_event = prev;
117 /***********************************************************************
120 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
125 while (macdrv_get_event_from_queue(queue, mask, &event))
128 macdrv_handle_event(&event);
129 macdrv_cleanup_event(&event);
131 if (count) TRACE("processed %d events\n", count);
136 /***********************************************************************
137 * MsgWaitForMultipleObjectsEx (MACDRV.@)
139 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
140 DWORD timeout, DWORD mask, DWORD flags)
143 struct macdrv_thread_data *data = macdrv_thread_data();
144 macdrv_event_mask event_mask = get_event_mask(mask);
146 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count,
147 handles, timeout, mask, flags);
151 if (!count && !timeout) return WAIT_TIMEOUT;
152 return WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
153 timeout, flags & MWMO_ALERTABLE);
156 if (data->current_event) event_mask = 0; /* don't process nested events */
158 if (process_events(data->queue, event_mask)) ret = count - 1;
159 else if (count || timeout)
161 ret = WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
162 timeout, flags & MWMO_ALERTABLE);
163 if (ret == count - 1) process_events(data->queue, event_mask);
165 else ret = WAIT_TIMEOUT;