ntdll/tests: Skip test if LdrAddRefDll is missing.
[wine.git] / dlls / winemac.drv / event.c
blob5803ac759791c25b9cd7c5946e2d87b7cea362d6
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",
60 if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
61 return wine_dbg_sprintf("Unknown event %d", type);
65 /***********************************************************************
66 * get_event_mask
68 static macdrv_event_mask get_event_mask(DWORD mask)
70 macdrv_event_mask event_mask = 0;
72 if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return -1;
74 if (mask & QS_HOTKEY)
75 event_mask |= event_mask_for_type(HOTKEY_PRESS);
77 if (mask & QS_KEY)
79 event_mask |= event_mask_for_type(KEY_PRESS);
80 event_mask |= event_mask_for_type(KEY_RELEASE);
81 event_mask |= event_mask_for_type(KEYBOARD_CHANGED);
84 if (mask & QS_MOUSEBUTTON)
86 event_mask |= event_mask_for_type(MOUSE_BUTTON);
87 event_mask |= event_mask_for_type(MOUSE_SCROLL);
90 if (mask & QS_MOUSEMOVE)
92 event_mask |= event_mask_for_type(MOUSE_MOVED);
93 event_mask |= event_mask_for_type(MOUSE_MOVED_ABSOLUTE);
96 if (mask & QS_POSTMESSAGE)
98 event_mask |= event_mask_for_type(APP_DEACTIVATED);
99 event_mask |= event_mask_for_type(APP_QUIT_REQUESTED);
100 event_mask |= event_mask_for_type(DISPLAYS_CHANGED);
101 event_mask |= event_mask_for_type(IM_SET_TEXT);
102 event_mask |= event_mask_for_type(STATUS_ITEM_MOUSE_BUTTON);
103 event_mask |= event_mask_for_type(STATUS_ITEM_MOUSE_MOVE);
104 event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
105 event_mask |= event_mask_for_type(WINDOW_DID_UNMINIMIZE);
106 event_mask |= event_mask_for_type(WINDOW_FRAME_CHANGED);
107 event_mask |= event_mask_for_type(WINDOW_GOT_FOCUS);
108 event_mask |= event_mask_for_type(WINDOW_LOST_FOCUS);
111 if (mask & QS_SENDMESSAGE)
113 event_mask |= event_mask_for_type(QUERY_EVENT);
114 event_mask |= event_mask_for_type(RELEASE_CAPTURE);
115 event_mask |= event_mask_for_type(WINDOW_BROUGHT_FORWARD);
116 event_mask |= event_mask_for_type(WINDOW_MINIMIZE_REQUESTED);
119 return event_mask;
123 /***********************************************************************
124 * macdrv_query_event
126 * Handler for QUERY_EVENT queries.
128 static void macdrv_query_event(HWND hwnd, const macdrv_event *event)
130 BOOL success = FALSE;
131 macdrv_query *query = event->query_event.query;
133 switch (query->type)
135 case QUERY_DRAG_DROP:
136 TRACE("QUERY_DRAG_DROP\n");
137 success = query_drag_drop(query);
138 break;
139 case QUERY_DRAG_EXITED:
140 TRACE("QUERY_DRAG_EXITED\n");
141 success = query_drag_exited(query);
142 break;
143 case QUERY_DRAG_OPERATION:
144 TRACE("QUERY_DRAG_OPERATION\n");
145 success = query_drag_operation(query);
146 break;
147 case QUERY_IME_CHAR_RECT:
148 TRACE("QUERY_IME_CHAR_RECT\n");
149 success = query_ime_char_rect(query);
150 break;
151 case QUERY_PASTEBOARD_DATA:
152 TRACE("QUERY_PASTEBOARD_DATA\n");
153 success = query_pasteboard_data(hwnd, query->pasteboard_data.type);
154 break;
155 case QUERY_RESIZE_END:
156 TRACE("QUERY_RESIZE_END\n");
157 success = query_resize_end(hwnd);
158 break;
159 case QUERY_RESIZE_START:
160 TRACE("QUERY_RESIZE_START\n");
161 success = query_resize_start(hwnd);
162 break;
163 case QUERY_MIN_MAX_INFO:
164 TRACE("QUERY_MIN_MAX_INFO\n");
165 success = query_min_max_info(hwnd);
166 break;
167 default:
168 FIXME("unrecognized query type %d\n", query->type);
169 break;
172 TRACE("success %d\n", success);
173 query->status = success;
174 macdrv_set_query_done(query);
178 /***********************************************************************
179 * macdrv_handle_event
181 void macdrv_handle_event(const macdrv_event *event)
183 HWND hwnd = macdrv_get_window_hwnd(event->window);
184 const macdrv_event *prev;
185 struct macdrv_thread_data *thread_data = macdrv_thread_data();
187 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event->type), hwnd,
188 event->window);
190 prev = thread_data->current_event;
191 thread_data->current_event = event;
193 switch (event->type)
195 case APP_DEACTIVATED:
196 macdrv_app_deactivated();
197 break;
198 case APP_QUIT_REQUESTED:
199 macdrv_app_quit_requested(event);
200 break;
201 case DISPLAYS_CHANGED:
202 macdrv_displays_changed(event);
203 break;
204 case HOTKEY_PRESS:
205 macdrv_hotkey_press(event);
206 break;
207 case IM_SET_TEXT:
208 macdrv_im_set_text(event);
209 break;
210 case KEY_PRESS:
211 case KEY_RELEASE:
212 macdrv_key_event(hwnd, event);
213 break;
214 case KEYBOARD_CHANGED:
215 macdrv_keyboard_changed(event);
216 break;
217 case MOUSE_BUTTON:
218 macdrv_mouse_button(hwnd, event);
219 break;
220 case MOUSE_MOVED:
221 case MOUSE_MOVED_ABSOLUTE:
222 macdrv_mouse_moved(hwnd, event);
223 break;
224 case MOUSE_SCROLL:
225 macdrv_mouse_scroll(hwnd, event);
226 break;
227 case QUERY_EVENT:
228 macdrv_query_event(hwnd, event);
229 break;
230 case RELEASE_CAPTURE:
231 macdrv_release_capture(hwnd, event);
232 break;
233 case STATUS_ITEM_MOUSE_BUTTON:
234 macdrv_status_item_mouse_button(event);
235 break;
236 case STATUS_ITEM_MOUSE_MOVE:
237 macdrv_status_item_mouse_move(event);
238 break;
239 case WINDOW_BROUGHT_FORWARD:
240 macdrv_window_brought_forward(hwnd);
241 break;
242 case WINDOW_CLOSE_REQUESTED:
243 macdrv_window_close_requested(hwnd);
244 break;
245 case WINDOW_DID_UNMINIMIZE:
246 macdrv_window_did_unminimize(hwnd);
247 break;
248 case WINDOW_FRAME_CHANGED:
249 macdrv_window_frame_changed(hwnd, event);
250 break;
251 case WINDOW_GOT_FOCUS:
252 macdrv_window_got_focus(hwnd, event);
253 break;
254 case WINDOW_LOST_FOCUS:
255 macdrv_window_lost_focus(hwnd, event);
256 break;
257 case WINDOW_MINIMIZE_REQUESTED:
258 macdrv_window_minimize_requested(hwnd);
259 break;
260 default:
261 TRACE(" ignoring\n");
262 break;
265 thread_data->current_event = prev;
269 /***********************************************************************
270 * process_events
272 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
274 macdrv_event *event;
275 int count = 0;
277 while (macdrv_copy_event_from_queue(queue, mask, &event))
279 count++;
280 macdrv_handle_event(event);
281 macdrv_release_event(event);
283 if (count) TRACE("processed %d events\n", count);
284 return count;
288 /***********************************************************************
289 * MsgWaitForMultipleObjectsEx (MACDRV.@)
291 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
292 DWORD timeout, DWORD mask, DWORD flags)
294 DWORD ret;
295 struct macdrv_thread_data *data = macdrv_thread_data();
296 macdrv_event_mask event_mask = get_event_mask(mask);
298 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count,
299 handles, timeout, mask, flags);
301 if (!data)
303 if (!count && !timeout) return WAIT_TIMEOUT;
304 return WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
305 timeout, flags & MWMO_ALERTABLE);
308 if (data->current_event && data->current_event->type != QUERY_EVENT &&
309 data->current_event->type != APP_QUIT_REQUESTED)
310 event_mask = 0; /* don't process nested events */
312 if (process_events(data->queue, event_mask)) ret = count - 1;
313 else if (count || timeout)
315 ret = WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
316 timeout, flags & MWMO_ALERTABLE);
317 if (ret == count - 1) process_events(data->queue, event_mask);
319 else ret = WAIT_TIMEOUT;
321 return ret;