comctl32/tests: Use BOOL type where appropriate.
[wine.git] / dlls / winemac.drv / event.c
blob77df58252e8e90471b32fe5fdfa1260132b0245d
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_FRAME_CHANGED",
55 "WINDOW_GOT_FOCUS",
56 "WINDOW_LOST_FOCUS",
57 "WINDOW_MINIMIZE_REQUESTED",
58 "WINDOW_RESIZE_ENDED",
61 if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
62 return wine_dbg_sprintf("Unknown event %d", type);
66 /***********************************************************************
67 * get_event_mask
69 static macdrv_event_mask get_event_mask(DWORD mask)
71 macdrv_event_mask event_mask = 0;
73 if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return -1;
75 if (mask & QS_HOTKEY)
76 event_mask |= event_mask_for_type(HOTKEY_PRESS);
78 if (mask & QS_KEY)
80 event_mask |= event_mask_for_type(KEY_PRESS);
81 event_mask |= event_mask_for_type(KEY_RELEASE);
82 event_mask |= event_mask_for_type(KEYBOARD_CHANGED);
85 if (mask & QS_MOUSEBUTTON)
87 event_mask |= event_mask_for_type(MOUSE_BUTTON);
88 event_mask |= event_mask_for_type(MOUSE_SCROLL);
91 if (mask & QS_MOUSEMOVE)
93 event_mask |= event_mask_for_type(MOUSE_MOVED);
94 event_mask |= event_mask_for_type(MOUSE_MOVED_ABSOLUTE);
97 if (mask & QS_POSTMESSAGE)
99 event_mask |= event_mask_for_type(APP_DEACTIVATED);
100 event_mask |= event_mask_for_type(APP_QUIT_REQUESTED);
101 event_mask |= event_mask_for_type(DISPLAYS_CHANGED);
102 event_mask |= event_mask_for_type(IM_SET_TEXT);
103 event_mask |= event_mask_for_type(STATUS_ITEM_MOUSE_BUTTON);
104 event_mask |= event_mask_for_type(STATUS_ITEM_MOUSE_MOVE);
105 event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
106 event_mask |= event_mask_for_type(WINDOW_DID_UNMINIMIZE);
107 event_mask |= event_mask_for_type(WINDOW_FRAME_CHANGED);
108 event_mask |= event_mask_for_type(WINDOW_GOT_FOCUS);
109 event_mask |= event_mask_for_type(WINDOW_LOST_FOCUS);
112 if (mask & QS_SENDMESSAGE)
114 event_mask |= event_mask_for_type(QUERY_EVENT);
115 event_mask |= event_mask_for_type(RELEASE_CAPTURE);
116 event_mask |= event_mask_for_type(WINDOW_BROUGHT_FORWARD);
117 event_mask |= event_mask_for_type(WINDOW_MINIMIZE_REQUESTED);
118 event_mask |= event_mask_for_type(WINDOW_RESIZE_ENDED);
121 return event_mask;
125 /***********************************************************************
126 * macdrv_query_event
128 * Handler for QUERY_EVENT queries.
130 static void macdrv_query_event(HWND hwnd, const macdrv_event *event)
132 BOOL success = FALSE;
133 macdrv_query *query = event->query_event.query;
135 switch (query->type)
137 case QUERY_DRAG_DROP:
138 TRACE("QUERY_DRAG_DROP\n");
139 success = query_drag_drop(query);
140 break;
141 case QUERY_DRAG_EXITED:
142 TRACE("QUERY_DRAG_EXITED\n");
143 success = query_drag_exited(query);
144 break;
145 case QUERY_DRAG_OPERATION:
146 TRACE("QUERY_DRAG_OPERATION\n");
147 success = query_drag_operation(query);
148 break;
149 case QUERY_IME_CHAR_RECT:
150 TRACE("QUERY_IME_CHAR_RECT\n");
151 success = query_ime_char_rect(query);
152 break;
153 case QUERY_PASTEBOARD_DATA:
154 TRACE("QUERY_PASTEBOARD_DATA\n");
155 success = query_pasteboard_data(hwnd, query->pasteboard_data.type);
156 break;
157 case QUERY_RESIZE_START:
158 TRACE("QUERY_RESIZE_START\n");
159 success = query_resize_start(hwnd);
160 break;
161 case QUERY_MIN_MAX_INFO:
162 TRACE("QUERY_MIN_MAX_INFO\n");
163 success = query_min_max_info(hwnd);
164 break;
165 default:
166 FIXME("unrecognized query type %d\n", query->type);
167 break;
170 TRACE("success %d\n", success);
171 query->status = success;
172 macdrv_set_query_done(query);
176 /***********************************************************************
177 * macdrv_handle_event
179 void macdrv_handle_event(const macdrv_event *event)
181 HWND hwnd = macdrv_get_window_hwnd(event->window);
182 const macdrv_event *prev;
183 struct macdrv_thread_data *thread_data = macdrv_thread_data();
185 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event->type), hwnd,
186 event->window);
188 prev = thread_data->current_event;
189 thread_data->current_event = event;
191 switch (event->type)
193 case APP_DEACTIVATED:
194 macdrv_app_deactivated();
195 break;
196 case APP_QUIT_REQUESTED:
197 macdrv_app_quit_requested(event);
198 break;
199 case DISPLAYS_CHANGED:
200 macdrv_displays_changed(event);
201 break;
202 case HOTKEY_PRESS:
203 macdrv_hotkey_press(event);
204 break;
205 case IM_SET_TEXT:
206 macdrv_im_set_text(event);
207 break;
208 case KEY_PRESS:
209 case KEY_RELEASE:
210 macdrv_key_event(hwnd, event);
211 break;
212 case KEYBOARD_CHANGED:
213 macdrv_keyboard_changed(event);
214 break;
215 case MOUSE_BUTTON:
216 macdrv_mouse_button(hwnd, event);
217 break;
218 case MOUSE_MOVED:
219 case MOUSE_MOVED_ABSOLUTE:
220 macdrv_mouse_moved(hwnd, event);
221 break;
222 case MOUSE_SCROLL:
223 macdrv_mouse_scroll(hwnd, event);
224 break;
225 case QUERY_EVENT:
226 macdrv_query_event(hwnd, event);
227 break;
228 case RELEASE_CAPTURE:
229 macdrv_release_capture(hwnd, event);
230 break;
231 case STATUS_ITEM_MOUSE_BUTTON:
232 macdrv_status_item_mouse_button(event);
233 break;
234 case STATUS_ITEM_MOUSE_MOVE:
235 macdrv_status_item_mouse_move(event);
236 break;
237 case WINDOW_BROUGHT_FORWARD:
238 macdrv_window_brought_forward(hwnd);
239 break;
240 case WINDOW_CLOSE_REQUESTED:
241 macdrv_window_close_requested(hwnd);
242 break;
243 case WINDOW_DID_UNMINIMIZE:
244 macdrv_window_did_unminimize(hwnd);
245 break;
246 case WINDOW_FRAME_CHANGED:
247 macdrv_window_frame_changed(hwnd, event);
248 break;
249 case WINDOW_GOT_FOCUS:
250 macdrv_window_got_focus(hwnd, event);
251 break;
252 case WINDOW_LOST_FOCUS:
253 macdrv_window_lost_focus(hwnd, event);
254 break;
255 case WINDOW_MINIMIZE_REQUESTED:
256 macdrv_window_minimize_requested(hwnd);
257 break;
258 case WINDOW_RESIZE_ENDED:
259 macdrv_window_resize_ended(hwnd);
260 break;
261 default:
262 TRACE(" ignoring\n");
263 break;
266 thread_data->current_event = prev;
270 /***********************************************************************
271 * process_events
273 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
275 macdrv_event *event;
276 int count = 0;
278 while (macdrv_copy_event_from_queue(queue, mask, &event))
280 count++;
281 macdrv_handle_event(event);
282 macdrv_release_event(event);
284 if (count) TRACE("processed %d events\n", count);
285 return count;
289 /***********************************************************************
290 * MsgWaitForMultipleObjectsEx (MACDRV.@)
292 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
293 DWORD timeout, DWORD mask, DWORD flags)
295 DWORD ret;
296 struct macdrv_thread_data *data = macdrv_thread_data();
297 macdrv_event_mask event_mask = get_event_mask(mask);
299 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count,
300 handles, timeout, mask, flags);
302 if (!data)
304 if (!count && !timeout) return WAIT_TIMEOUT;
305 return WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
306 timeout, flags & MWMO_ALERTABLE);
309 if (data->current_event && data->current_event->type != QUERY_EVENT &&
310 data->current_event->type != APP_QUIT_REQUESTED)
311 event_mask = 0; /* don't process nested events */
313 if (process_events(data->queue, event_mask)) ret = count - 1;
314 else if (count || timeout)
316 ret = WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
317 timeout, flags & MWMO_ALERTABLE);
318 if (ret == count - 1) process_events(data->queue, event_mask);
320 else ret = WAIT_TIMEOUT;
322 return ret;