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
[] = {
44 "LOST_PASTEBOARD_OWNERSHIP",
47 "MOUSE_MOVED_ABSOLUTE",
50 "QUERY_EVENT_NO_PREEMPT_WAIT",
51 "REASSERT_WINDOW_POSITION",
54 "STATUS_ITEM_MOUSE_BUTTON",
55 "STATUS_ITEM_MOUSE_MOVE",
56 "WINDOW_BROUGHT_FORWARD",
57 "WINDOW_CLOSE_REQUESTED",
58 "WINDOW_DID_UNMINIMIZE",
61 "WINDOW_FRAME_CHANGED",
64 "WINDOW_MAXIMIZE_REQUESTED",
65 "WINDOW_MINIMIZE_REQUESTED",
66 "WINDOW_RESIZE_ENDED",
67 "WINDOW_RESTORE_REQUESTED",
70 if (0 <= type
&& type
< NUM_EVENT_TYPES
) return event_names
[type
];
71 return wine_dbg_sprintf("Unknown event %d", type
);
75 /***********************************************************************
78 static macdrv_event_mask
get_event_mask(DWORD mask
)
80 macdrv_event_mask event_mask
= 0;
82 if ((mask
& QS_ALLINPUT
) == QS_ALLINPUT
) return -1;
85 event_mask
|= event_mask_for_type(HOTKEY_PRESS
);
89 event_mask
|= event_mask_for_type(KEY_PRESS
);
90 event_mask
|= event_mask_for_type(KEY_RELEASE
);
91 event_mask
|= event_mask_for_type(KEYBOARD_CHANGED
);
94 if (mask
& QS_MOUSEBUTTON
)
96 event_mask
|= event_mask_for_type(MOUSE_BUTTON
);
97 event_mask
|= event_mask_for_type(MOUSE_SCROLL
);
100 if (mask
& QS_MOUSEMOVE
)
102 event_mask
|= event_mask_for_type(MOUSE_MOVED
);
103 event_mask
|= event_mask_for_type(MOUSE_MOVED_ABSOLUTE
);
106 if (mask
& QS_POSTMESSAGE
)
108 event_mask
|= event_mask_for_type(APP_ACTIVATED
);
109 event_mask
|= event_mask_for_type(APP_DEACTIVATED
);
110 event_mask
|= event_mask_for_type(APP_QUIT_REQUESTED
);
111 event_mask
|= event_mask_for_type(DISPLAYS_CHANGED
);
112 event_mask
|= event_mask_for_type(IM_SET_TEXT
);
113 event_mask
|= event_mask_for_type(LOST_PASTEBOARD_OWNERSHIP
);
114 event_mask
|= event_mask_for_type(STATUS_ITEM_MOUSE_BUTTON
);
115 event_mask
|= event_mask_for_type(STATUS_ITEM_MOUSE_MOVE
);
116 event_mask
|= event_mask_for_type(WINDOW_DID_UNMINIMIZE
);
117 event_mask
|= event_mask_for_type(WINDOW_FRAME_CHANGED
);
118 event_mask
|= event_mask_for_type(WINDOW_GOT_FOCUS
);
119 event_mask
|= event_mask_for_type(WINDOW_LOST_FOCUS
);
122 if (mask
& QS_SENDMESSAGE
)
124 event_mask
|= event_mask_for_type(QUERY_EVENT
);
125 event_mask
|= event_mask_for_type(QUERY_EVENT_NO_PREEMPT_WAIT
);
126 event_mask
|= event_mask_for_type(REASSERT_WINDOW_POSITION
);
127 event_mask
|= event_mask_for_type(RELEASE_CAPTURE
);
128 event_mask
|= event_mask_for_type(SENT_TEXT_INPUT
);
129 event_mask
|= event_mask_for_type(WINDOW_BROUGHT_FORWARD
);
130 event_mask
|= event_mask_for_type(WINDOW_CLOSE_REQUESTED
);
131 event_mask
|= event_mask_for_type(WINDOW_DRAG_BEGIN
);
132 event_mask
|= event_mask_for_type(WINDOW_DRAG_END
);
133 event_mask
|= event_mask_for_type(WINDOW_MAXIMIZE_REQUESTED
);
134 event_mask
|= event_mask_for_type(WINDOW_MINIMIZE_REQUESTED
);
135 event_mask
|= event_mask_for_type(WINDOW_RESIZE_ENDED
);
136 event_mask
|= event_mask_for_type(WINDOW_RESTORE_REQUESTED
);
143 /***********************************************************************
146 * Handler for QUERY_EVENT and QUERY_EVENT_NO_PREEMPT_WAIT queries.
148 static void macdrv_query_event(HWND hwnd
, const macdrv_event
*event
)
150 BOOL success
= FALSE
;
151 macdrv_query
*query
= event
->query_event
.query
;
155 case QUERY_DRAG_DROP
:
156 TRACE("QUERY_DRAG_DROP\n");
157 success
= query_drag_drop(query
);
159 case QUERY_DRAG_EXITED
:
160 TRACE("QUERY_DRAG_EXITED\n");
161 success
= query_drag_exited(query
);
163 case QUERY_DRAG_OPERATION
:
164 TRACE("QUERY_DRAG_OPERATION\n");
165 success
= query_drag_operation(query
);
167 case QUERY_IME_CHAR_RECT
:
168 TRACE("QUERY_IME_CHAR_RECT\n");
169 success
= query_ime_char_rect(query
);
171 case QUERY_PASTEBOARD_DATA
:
172 TRACE("QUERY_PASTEBOARD_DATA\n");
173 success
= query_pasteboard_data(hwnd
, query
->pasteboard_data
.type
);
175 case QUERY_RESIZE_SIZE
:
176 TRACE("QUERY_RESIZE_SIZE\n");
177 success
= query_resize_size(hwnd
, query
);
179 case QUERY_RESIZE_START
:
180 TRACE("QUERY_RESIZE_START\n");
181 success
= query_resize_start(hwnd
);
183 case QUERY_MIN_MAX_INFO
:
184 TRACE("QUERY_MIN_MAX_INFO\n");
185 success
= query_min_max_info(hwnd
);
188 FIXME("unrecognized query type %d\n", query
->type
);
192 TRACE("success %d\n", success
);
193 query
->status
= success
;
194 macdrv_set_query_done(query
);
198 /***********************************************************************
199 * macdrv_handle_event
201 void macdrv_handle_event(const macdrv_event
*event
)
203 HWND hwnd
= macdrv_get_window_hwnd(event
->window
);
204 const macdrv_event
*prev
;
205 struct macdrv_thread_data
*thread_data
= macdrv_thread_data();
207 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event
->type
), hwnd
,
210 prev
= thread_data
->current_event
;
211 thread_data
->current_event
= event
;
216 macdrv_app_activated();
218 case APP_DEACTIVATED
:
219 macdrv_app_deactivated();
221 case APP_QUIT_REQUESTED
:
222 macdrv_app_quit_requested(event
);
224 case DISPLAYS_CHANGED
:
225 macdrv_displays_changed(event
);
228 macdrv_hotkey_press(event
);
231 macdrv_im_set_text(event
);
235 macdrv_key_event(hwnd
, event
);
237 case KEYBOARD_CHANGED
:
238 macdrv_keyboard_changed(event
);
240 case LOST_PASTEBOARD_OWNERSHIP
:
241 macdrv_lost_pasteboard_ownership(hwnd
);
244 macdrv_mouse_button(hwnd
, event
);
247 case MOUSE_MOVED_ABSOLUTE
:
248 macdrv_mouse_moved(hwnd
, event
);
251 macdrv_mouse_scroll(hwnd
, event
);
254 case QUERY_EVENT_NO_PREEMPT_WAIT
:
255 macdrv_query_event(hwnd
, event
);
257 case REASSERT_WINDOW_POSITION
:
258 macdrv_reassert_window_position(hwnd
);
260 case RELEASE_CAPTURE
:
261 macdrv_release_capture(hwnd
, event
);
263 case SENT_TEXT_INPUT
:
264 macdrv_sent_text_input(event
);
266 case STATUS_ITEM_MOUSE_BUTTON
:
267 macdrv_status_item_mouse_button(event
);
269 case STATUS_ITEM_MOUSE_MOVE
:
270 macdrv_status_item_mouse_move(event
);
272 case WINDOW_BROUGHT_FORWARD
:
273 macdrv_window_brought_forward(hwnd
);
275 case WINDOW_CLOSE_REQUESTED
:
276 macdrv_window_close_requested(hwnd
);
278 case WINDOW_DID_UNMINIMIZE
:
279 macdrv_window_did_unminimize(hwnd
);
281 case WINDOW_DRAG_BEGIN
:
282 macdrv_window_drag_begin(hwnd
, event
);
284 case WINDOW_DRAG_END
:
285 macdrv_window_drag_end(hwnd
);
287 case WINDOW_FRAME_CHANGED
:
288 macdrv_window_frame_changed(hwnd
, event
);
290 case WINDOW_GOT_FOCUS
:
291 macdrv_window_got_focus(hwnd
, event
);
293 case WINDOW_LOST_FOCUS
:
294 macdrv_window_lost_focus(hwnd
, event
);
296 case WINDOW_MAXIMIZE_REQUESTED
:
297 macdrv_window_maximize_requested(hwnd
);
299 case WINDOW_MINIMIZE_REQUESTED
:
300 macdrv_window_minimize_requested(hwnd
);
302 case WINDOW_RESIZE_ENDED
:
303 macdrv_window_resize_ended(hwnd
);
305 case WINDOW_RESTORE_REQUESTED
:
306 macdrv_window_restore_requested(hwnd
, event
);
309 TRACE(" ignoring\n");
313 thread_data
->current_event
= prev
;
317 /***********************************************************************
320 static int process_events(macdrv_event_queue queue
, macdrv_event_mask mask
)
325 while (macdrv_copy_event_from_queue(queue
, mask
, &event
))
328 macdrv_handle_event(event
);
329 macdrv_release_event(event
);
331 if (count
) TRACE("processed %d events\n", count
);
336 /***********************************************************************
337 * MsgWaitForMultipleObjectsEx (MACDRV.@)
339 DWORD CDECL
macdrv_MsgWaitForMultipleObjectsEx(DWORD count
, const HANDLE
*handles
,
340 DWORD timeout
, DWORD mask
, DWORD flags
)
343 struct macdrv_thread_data
*data
= macdrv_thread_data();
344 macdrv_event_mask event_mask
= get_event_mask(mask
);
346 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count
,
347 handles
, timeout
, mask
, flags
);
351 if (!count
&& !timeout
) return WAIT_TIMEOUT
;
352 return WaitForMultipleObjectsEx(count
, handles
, flags
& MWMO_WAITALL
,
353 timeout
, flags
& MWMO_ALERTABLE
);
356 if (data
->current_event
&& data
->current_event
->type
!= QUERY_EVENT
&&
357 data
->current_event
->type
!= QUERY_EVENT_NO_PREEMPT_WAIT
&&
358 data
->current_event
->type
!= APP_QUIT_REQUESTED
&&
359 data
->current_event
->type
!= WINDOW_DRAG_BEGIN
)
360 event_mask
= 0; /* don't process nested events */
362 if (process_events(data
->queue
, event_mask
)) ret
= count
- 1;
363 else if (count
|| timeout
)
365 ret
= WaitForMultipleObjectsEx(count
, handles
, flags
& MWMO_WAITALL
,
366 timeout
, flags
& MWMO_ALERTABLE
);
367 if (ret
== count
- 1) process_events(data
->queue
, event_mask
);
369 else ret
= WAIT_TIMEOUT
;