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",
54 "WINDOW_FRAME_CHANGED",
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 /***********************************************************************
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;
75 event_mask
|= event_mask_for_type(HOTKEY_PRESS
);
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
);
123 /***********************************************************************
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
;
135 case QUERY_DRAG_DROP
:
136 TRACE("QUERY_DRAG_DROP\n");
137 success
= query_drag_drop(query
);
139 case QUERY_DRAG_EXITED
:
140 TRACE("QUERY_DRAG_EXITED\n");
141 success
= query_drag_exited(query
);
143 case QUERY_DRAG_OPERATION
:
144 TRACE("QUERY_DRAG_OPERATION\n");
145 success
= query_drag_operation(query
);
147 case QUERY_IME_CHAR_RECT
:
148 TRACE("QUERY_IME_CHAR_RECT\n");
149 success
= query_ime_char_rect(query
);
151 case QUERY_PASTEBOARD_DATA
:
152 TRACE("QUERY_PASTEBOARD_DATA\n");
153 success
= query_pasteboard_data(hwnd
, query
->pasteboard_data
.type
);
155 case QUERY_RESIZE_END
:
156 TRACE("QUERY_RESIZE_END\n");
157 success
= query_resize_end(hwnd
);
159 case QUERY_RESIZE_START
:
160 TRACE("QUERY_RESIZE_START\n");
161 success
= query_resize_start(hwnd
);
163 case QUERY_MIN_MAX_INFO
:
164 TRACE("QUERY_MIN_MAX_INFO\n");
165 success
= query_min_max_info(hwnd
);
168 FIXME("unrecognized query type %d\n", query
->type
);
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
,
190 prev
= thread_data
->current_event
;
191 thread_data
->current_event
= event
;
195 case APP_DEACTIVATED
:
196 macdrv_app_deactivated();
198 case APP_QUIT_REQUESTED
:
199 macdrv_app_quit_requested(event
);
201 case DISPLAYS_CHANGED
:
202 macdrv_displays_changed(event
);
205 macdrv_hotkey_press(event
);
208 macdrv_im_set_text(event
);
212 macdrv_key_event(hwnd
, event
);
214 case KEYBOARD_CHANGED
:
215 macdrv_keyboard_changed(event
);
218 macdrv_mouse_button(hwnd
, event
);
221 case MOUSE_MOVED_ABSOLUTE
:
222 macdrv_mouse_moved(hwnd
, event
);
225 macdrv_mouse_scroll(hwnd
, event
);
228 macdrv_query_event(hwnd
, event
);
230 case RELEASE_CAPTURE
:
231 macdrv_release_capture(hwnd
, event
);
233 case STATUS_ITEM_MOUSE_BUTTON
:
234 macdrv_status_item_mouse_button(event
);
236 case STATUS_ITEM_MOUSE_MOVE
:
237 macdrv_status_item_mouse_move(event
);
239 case WINDOW_BROUGHT_FORWARD
:
240 macdrv_window_brought_forward(hwnd
);
242 case WINDOW_CLOSE_REQUESTED
:
243 macdrv_window_close_requested(hwnd
);
245 case WINDOW_DID_UNMINIMIZE
:
246 macdrv_window_did_unminimize(hwnd
);
248 case WINDOW_FRAME_CHANGED
:
249 macdrv_window_frame_changed(hwnd
, event
);
251 case WINDOW_GOT_FOCUS
:
252 macdrv_window_got_focus(hwnd
, event
);
254 case WINDOW_LOST_FOCUS
:
255 macdrv_window_lost_focus(hwnd
, event
);
257 case WINDOW_MINIMIZE_REQUESTED
:
258 macdrv_window_minimize_requested(hwnd
);
261 TRACE(" ignoring\n");
265 thread_data
->current_event
= prev
;
269 /***********************************************************************
272 static int process_events(macdrv_event_queue queue
, macdrv_event_mask mask
)
277 while (macdrv_copy_event_from_queue(queue
, mask
, &event
))
280 macdrv_handle_event(event
);
281 macdrv_release_event(event
);
283 if (count
) TRACE("processed %d events\n", count
);
288 /***********************************************************************
289 * MsgWaitForMultipleObjectsEx (MACDRV.@)
291 DWORD CDECL
macdrv_MsgWaitForMultipleObjectsEx(DWORD count
, const HANDLE
*handles
,
292 DWORD timeout
, DWORD mask
, DWORD flags
)
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
);
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
;