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
[] = {
45 "MOUSE_MOVED_ABSOLUTE",
49 "STATUS_ITEM_MOUSE_BUTTON",
50 "STATUS_ITEM_MOUSE_MOVE",
51 "WINDOW_BROUGHT_FORWARD",
52 "WINDOW_CLOSE_REQUESTED",
53 "WINDOW_DID_UNMINIMIZE",
56 "WINDOW_FRAME_CHANGED",
59 "WINDOW_MAXIMIZE_REQUESTED",
60 "WINDOW_MINIMIZE_REQUESTED",
61 "WINDOW_RESIZE_ENDED",
62 "WINDOW_RESTORE_REQUESTED",
65 if (0 <= type
&& type
< NUM_EVENT_TYPES
) return event_names
[type
];
66 return wine_dbg_sprintf("Unknown event %d", type
);
70 /***********************************************************************
73 static macdrv_event_mask
get_event_mask(DWORD mask
)
75 macdrv_event_mask event_mask
= 0;
77 if ((mask
& QS_ALLINPUT
) == QS_ALLINPUT
) return -1;
80 event_mask
|= event_mask_for_type(HOTKEY_PRESS
);
84 event_mask
|= event_mask_for_type(KEY_PRESS
);
85 event_mask
|= event_mask_for_type(KEY_RELEASE
);
86 event_mask
|= event_mask_for_type(KEYBOARD_CHANGED
);
89 if (mask
& QS_MOUSEBUTTON
)
91 event_mask
|= event_mask_for_type(MOUSE_BUTTON
);
92 event_mask
|= event_mask_for_type(MOUSE_SCROLL
);
95 if (mask
& QS_MOUSEMOVE
)
97 event_mask
|= event_mask_for_type(MOUSE_MOVED
);
98 event_mask
|= event_mask_for_type(MOUSE_MOVED_ABSOLUTE
);
101 if (mask
& QS_POSTMESSAGE
)
103 event_mask
|= event_mask_for_type(APP_DEACTIVATED
);
104 event_mask
|= event_mask_for_type(APP_QUIT_REQUESTED
);
105 event_mask
|= event_mask_for_type(DISPLAYS_CHANGED
);
106 event_mask
|= event_mask_for_type(IM_SET_TEXT
);
107 event_mask
|= event_mask_for_type(STATUS_ITEM_MOUSE_BUTTON
);
108 event_mask
|= event_mask_for_type(STATUS_ITEM_MOUSE_MOVE
);
109 event_mask
|= event_mask_for_type(WINDOW_DID_UNMINIMIZE
);
110 event_mask
|= event_mask_for_type(WINDOW_FRAME_CHANGED
);
111 event_mask
|= event_mask_for_type(WINDOW_GOT_FOCUS
);
112 event_mask
|= event_mask_for_type(WINDOW_LOST_FOCUS
);
115 if (mask
& QS_SENDMESSAGE
)
117 event_mask
|= event_mask_for_type(QUERY_EVENT
);
118 event_mask
|= event_mask_for_type(RELEASE_CAPTURE
);
119 event_mask
|= event_mask_for_type(WINDOW_BROUGHT_FORWARD
);
120 event_mask
|= event_mask_for_type(WINDOW_CLOSE_REQUESTED
);
121 event_mask
|= event_mask_for_type(WINDOW_DRAG_BEGIN
);
122 event_mask
|= event_mask_for_type(WINDOW_DRAG_END
);
123 event_mask
|= event_mask_for_type(WINDOW_MAXIMIZE_REQUESTED
);
124 event_mask
|= event_mask_for_type(WINDOW_MINIMIZE_REQUESTED
);
125 event_mask
|= event_mask_for_type(WINDOW_RESIZE_ENDED
);
126 event_mask
|= event_mask_for_type(WINDOW_RESTORE_REQUESTED
);
133 /***********************************************************************
136 * Handler for QUERY_EVENT queries.
138 static void macdrv_query_event(HWND hwnd
, const macdrv_event
*event
)
140 BOOL success
= FALSE
;
141 macdrv_query
*query
= event
->query_event
.query
;
145 case QUERY_DRAG_DROP
:
146 TRACE("QUERY_DRAG_DROP\n");
147 success
= query_drag_drop(query
);
149 case QUERY_DRAG_EXITED
:
150 TRACE("QUERY_DRAG_EXITED\n");
151 success
= query_drag_exited(query
);
153 case QUERY_DRAG_OPERATION
:
154 TRACE("QUERY_DRAG_OPERATION\n");
155 success
= query_drag_operation(query
);
157 case QUERY_IME_CHAR_RECT
:
158 TRACE("QUERY_IME_CHAR_RECT\n");
159 success
= query_ime_char_rect(query
);
161 case QUERY_PASTEBOARD_DATA
:
162 TRACE("QUERY_PASTEBOARD_DATA\n");
163 success
= query_pasteboard_data(hwnd
, query
->pasteboard_data
.type
);
165 case QUERY_RESIZE_SIZE
:
166 TRACE("QUERY_RESIZE_SIZE\n");
167 success
= query_resize_size(hwnd
, query
);
169 case QUERY_RESIZE_START
:
170 TRACE("QUERY_RESIZE_START\n");
171 success
= query_resize_start(hwnd
);
173 case QUERY_MIN_MAX_INFO
:
174 TRACE("QUERY_MIN_MAX_INFO\n");
175 success
= query_min_max_info(hwnd
);
178 FIXME("unrecognized query type %d\n", query
->type
);
182 TRACE("success %d\n", success
);
183 query
->status
= success
;
184 macdrv_set_query_done(query
);
188 /***********************************************************************
189 * macdrv_handle_event
191 void macdrv_handle_event(const macdrv_event
*event
)
193 HWND hwnd
= macdrv_get_window_hwnd(event
->window
);
194 const macdrv_event
*prev
;
195 struct macdrv_thread_data
*thread_data
= macdrv_thread_data();
197 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event
->type
), hwnd
,
200 prev
= thread_data
->current_event
;
201 thread_data
->current_event
= event
;
205 case APP_DEACTIVATED
:
206 macdrv_app_deactivated();
208 case APP_QUIT_REQUESTED
:
209 macdrv_app_quit_requested(event
);
211 case DISPLAYS_CHANGED
:
212 macdrv_displays_changed(event
);
215 macdrv_hotkey_press(event
);
218 macdrv_im_set_text(event
);
222 macdrv_key_event(hwnd
, event
);
224 case KEYBOARD_CHANGED
:
225 macdrv_keyboard_changed(event
);
228 macdrv_mouse_button(hwnd
, event
);
231 case MOUSE_MOVED_ABSOLUTE
:
232 macdrv_mouse_moved(hwnd
, event
);
235 macdrv_mouse_scroll(hwnd
, event
);
238 macdrv_query_event(hwnd
, event
);
240 case RELEASE_CAPTURE
:
241 macdrv_release_capture(hwnd
, event
);
243 case STATUS_ITEM_MOUSE_BUTTON
:
244 macdrv_status_item_mouse_button(event
);
246 case STATUS_ITEM_MOUSE_MOVE
:
247 macdrv_status_item_mouse_move(event
);
249 case WINDOW_BROUGHT_FORWARD
:
250 macdrv_window_brought_forward(hwnd
);
252 case WINDOW_CLOSE_REQUESTED
:
253 macdrv_window_close_requested(hwnd
);
255 case WINDOW_DID_UNMINIMIZE
:
256 macdrv_window_did_unminimize(hwnd
);
258 case WINDOW_DRAG_BEGIN
:
259 macdrv_window_drag_begin(hwnd
);
261 case WINDOW_DRAG_END
:
262 macdrv_window_drag_end(hwnd
);
264 case WINDOW_FRAME_CHANGED
:
265 macdrv_window_frame_changed(hwnd
, event
);
267 case WINDOW_GOT_FOCUS
:
268 macdrv_window_got_focus(hwnd
, event
);
270 case WINDOW_LOST_FOCUS
:
271 macdrv_window_lost_focus(hwnd
, event
);
273 case WINDOW_MAXIMIZE_REQUESTED
:
274 macdrv_window_maximize_requested(hwnd
);
276 case WINDOW_MINIMIZE_REQUESTED
:
277 macdrv_window_minimize_requested(hwnd
);
279 case WINDOW_RESIZE_ENDED
:
280 macdrv_window_resize_ended(hwnd
);
282 case WINDOW_RESTORE_REQUESTED
:
283 macdrv_window_restore_requested(hwnd
, event
);
286 TRACE(" ignoring\n");
290 thread_data
->current_event
= prev
;
294 /***********************************************************************
297 static int process_events(macdrv_event_queue queue
, macdrv_event_mask mask
)
302 while (macdrv_copy_event_from_queue(queue
, mask
, &event
))
305 macdrv_handle_event(event
);
306 macdrv_release_event(event
);
308 if (count
) TRACE("processed %d events\n", count
);
313 /***********************************************************************
314 * MsgWaitForMultipleObjectsEx (MACDRV.@)
316 DWORD CDECL
macdrv_MsgWaitForMultipleObjectsEx(DWORD count
, const HANDLE
*handles
,
317 DWORD timeout
, DWORD mask
, DWORD flags
)
320 struct macdrv_thread_data
*data
= macdrv_thread_data();
321 macdrv_event_mask event_mask
= get_event_mask(mask
);
323 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count
,
324 handles
, timeout
, mask
, flags
);
328 if (!count
&& !timeout
) return WAIT_TIMEOUT
;
329 return WaitForMultipleObjectsEx(count
, handles
, flags
& MWMO_WAITALL
,
330 timeout
, flags
& MWMO_ALERTABLE
);
333 if (data
->current_event
&& data
->current_event
->type
!= QUERY_EVENT
&&
334 data
->current_event
->type
!= APP_QUIT_REQUESTED
&&
335 data
->current_event
->type
!= WINDOW_DRAG_BEGIN
)
336 event_mask
= 0; /* don't process nested events */
338 if (process_events(data
->queue
, event_mask
)) ret
= count
- 1;
339 else if (count
|| timeout
)
341 ret
= WaitForMultipleObjectsEx(count
, handles
, flags
& MWMO_WAITALL
,
342 timeout
, flags
& MWMO_ALERTABLE
);
343 if (ret
== count
- 1) process_events(data
->queue
, event_mask
);
345 else ret
= WAIT_TIMEOUT
;