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",
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 /***********************************************************************
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;
76 event_mask
|= event_mask_for_type(HOTKEY_PRESS
);
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
);
125 /***********************************************************************
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
;
137 case QUERY_DRAG_DROP
:
138 TRACE("QUERY_DRAG_DROP\n");
139 success
= query_drag_drop(query
);
141 case QUERY_DRAG_EXITED
:
142 TRACE("QUERY_DRAG_EXITED\n");
143 success
= query_drag_exited(query
);
145 case QUERY_DRAG_OPERATION
:
146 TRACE("QUERY_DRAG_OPERATION\n");
147 success
= query_drag_operation(query
);
149 case QUERY_IME_CHAR_RECT
:
150 TRACE("QUERY_IME_CHAR_RECT\n");
151 success
= query_ime_char_rect(query
);
153 case QUERY_PASTEBOARD_DATA
:
154 TRACE("QUERY_PASTEBOARD_DATA\n");
155 success
= query_pasteboard_data(hwnd
, query
->pasteboard_data
.type
);
157 case QUERY_RESIZE_START
:
158 TRACE("QUERY_RESIZE_START\n");
159 success
= query_resize_start(hwnd
);
161 case QUERY_MIN_MAX_INFO
:
162 TRACE("QUERY_MIN_MAX_INFO\n");
163 success
= query_min_max_info(hwnd
);
166 FIXME("unrecognized query type %d\n", query
->type
);
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
,
188 prev
= thread_data
->current_event
;
189 thread_data
->current_event
= event
;
193 case APP_DEACTIVATED
:
194 macdrv_app_deactivated();
196 case APP_QUIT_REQUESTED
:
197 macdrv_app_quit_requested(event
);
199 case DISPLAYS_CHANGED
:
200 macdrv_displays_changed(event
);
203 macdrv_hotkey_press(event
);
206 macdrv_im_set_text(event
);
210 macdrv_key_event(hwnd
, event
);
212 case KEYBOARD_CHANGED
:
213 macdrv_keyboard_changed(event
);
216 macdrv_mouse_button(hwnd
, event
);
219 case MOUSE_MOVED_ABSOLUTE
:
220 macdrv_mouse_moved(hwnd
, event
);
223 macdrv_mouse_scroll(hwnd
, event
);
226 macdrv_query_event(hwnd
, event
);
228 case RELEASE_CAPTURE
:
229 macdrv_release_capture(hwnd
, event
);
231 case STATUS_ITEM_MOUSE_BUTTON
:
232 macdrv_status_item_mouse_button(event
);
234 case STATUS_ITEM_MOUSE_MOVE
:
235 macdrv_status_item_mouse_move(event
);
237 case WINDOW_BROUGHT_FORWARD
:
238 macdrv_window_brought_forward(hwnd
);
240 case WINDOW_CLOSE_REQUESTED
:
241 macdrv_window_close_requested(hwnd
);
243 case WINDOW_DID_UNMINIMIZE
:
244 macdrv_window_did_unminimize(hwnd
);
246 case WINDOW_FRAME_CHANGED
:
247 macdrv_window_frame_changed(hwnd
, event
);
249 case WINDOW_GOT_FOCUS
:
250 macdrv_window_got_focus(hwnd
, event
);
252 case WINDOW_LOST_FOCUS
:
253 macdrv_window_lost_focus(hwnd
, event
);
255 case WINDOW_MINIMIZE_REQUESTED
:
256 macdrv_window_minimize_requested(hwnd
);
258 case WINDOW_RESIZE_ENDED
:
259 macdrv_window_resize_ended(hwnd
);
262 TRACE(" ignoring\n");
266 thread_data
->current_event
= prev
;
270 /***********************************************************************
273 static int process_events(macdrv_event_queue queue
, macdrv_event_mask mask
)
278 while (macdrv_copy_event_from_queue(queue
, mask
, &event
))
281 macdrv_handle_event(event
);
282 macdrv_release_event(event
);
284 if (count
) TRACE("processed %d events\n", count
);
289 /***********************************************************************
290 * MsgWaitForMultipleObjectsEx (MACDRV.@)
292 DWORD CDECL
macdrv_MsgWaitForMultipleObjectsEx(DWORD count
, const HANDLE
*handles
,
293 DWORD timeout
, DWORD mask
, DWORD flags
)
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
);
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
;