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 "MOUSE_MOVED_ABSOLUTE",
48 "STATUS_ITEM_MOUSE_BUTTON",
49 "STATUS_ITEM_MOUSE_MOVE",
50 "WINDOW_CLOSE_REQUESTED",
51 "WINDOW_DID_MINIMIZE",
52 "WINDOW_DID_UNMINIMIZE",
53 "WINDOW_FRAME_CHANGED",
58 if (0 <= type
&& type
< NUM_EVENT_TYPES
) return event_names
[type
];
59 return wine_dbg_sprintf("Unknown event %d", type
);
63 /***********************************************************************
66 static macdrv_event_mask
get_event_mask(DWORD mask
)
68 macdrv_event_mask event_mask
= 0;
70 if ((mask
& QS_ALLINPUT
) == QS_ALLINPUT
) return -1;
74 event_mask
|= event_mask_for_type(KEY_PRESS
);
75 event_mask
|= event_mask_for_type(KEY_RELEASE
);
76 event_mask
|= event_mask_for_type(KEYBOARD_CHANGED
);
79 if (mask
& QS_MOUSEBUTTON
)
81 event_mask
|= event_mask_for_type(MOUSE_BUTTON
);
82 event_mask
|= event_mask_for_type(MOUSE_SCROLL
);
85 if (mask
& QS_MOUSEMOVE
)
87 event_mask
|= event_mask_for_type(MOUSE_MOVED
);
88 event_mask
|= event_mask_for_type(MOUSE_MOVED_ABSOLUTE
);
91 if (mask
& QS_POSTMESSAGE
)
93 event_mask
|= event_mask_for_type(APP_DEACTIVATED
);
94 event_mask
|= event_mask_for_type(APP_QUIT_REQUESTED
);
95 event_mask
|= event_mask_for_type(DISPLAYS_CHANGED
);
96 event_mask
|= event_mask_for_type(IM_SET_TEXT
);
97 event_mask
|= event_mask_for_type(STATUS_ITEM_MOUSE_BUTTON
);
98 event_mask
|= event_mask_for_type(STATUS_ITEM_MOUSE_MOVE
);
99 event_mask
|= event_mask_for_type(WINDOW_CLOSE_REQUESTED
);
100 event_mask
|= event_mask_for_type(WINDOW_DID_MINIMIZE
);
101 event_mask
|= event_mask_for_type(WINDOW_DID_UNMINIMIZE
);
102 event_mask
|= event_mask_for_type(WINDOW_FRAME_CHANGED
);
103 event_mask
|= event_mask_for_type(WINDOW_GOT_FOCUS
);
104 event_mask
|= event_mask_for_type(WINDOW_LOST_FOCUS
);
107 if (mask
& QS_SENDMESSAGE
)
109 event_mask
|= event_mask_for_type(QUERY_EVENT
);
110 event_mask
|= event_mask_for_type(RELEASE_CAPTURE
);
117 /***********************************************************************
120 * Handler for QUERY_EVENT queries.
122 static void macdrv_query_event(HWND hwnd
, const macdrv_event
*event
)
124 BOOL success
= FALSE
;
125 macdrv_query
*query
= event
->query_event
.query
;
129 case QUERY_DRAG_DROP
:
130 TRACE("QUERY_DRAG_DROP\n");
131 success
= query_drag_drop(query
);
133 case QUERY_DRAG_EXITED
:
134 TRACE("QUERY_DRAG_EXITED\n");
135 success
= query_drag_exited(query
);
137 case QUERY_DRAG_OPERATION
:
138 TRACE("QUERY_DRAG_OPERATION\n");
139 success
= query_drag_operation(query
);
141 case QUERY_IME_CHAR_RECT
:
142 TRACE("QUERY_IME_CHAR_RECT\n");
143 success
= query_ime_char_rect(query
);
145 case QUERY_PASTEBOARD_DATA
:
146 TRACE("QUERY_PASTEBOARD_DATA\n");
147 success
= query_pasteboard_data(hwnd
, query
->pasteboard_data
.type
);
150 FIXME("unrecognized query type %d\n", query
->type
);
154 TRACE("success %d\n", success
);
155 query
->status
= success
;
156 macdrv_set_query_done(query
);
160 /***********************************************************************
161 * macdrv_handle_event
163 void macdrv_handle_event(const macdrv_event
*event
)
165 HWND hwnd
= macdrv_get_window_hwnd(event
->window
);
166 const macdrv_event
*prev
;
167 struct macdrv_thread_data
*thread_data
= macdrv_thread_data();
169 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event
->type
), hwnd
,
172 prev
= thread_data
->current_event
;
173 thread_data
->current_event
= event
;
177 case APP_DEACTIVATED
:
178 macdrv_app_deactivated();
180 case APP_QUIT_REQUESTED
:
181 macdrv_app_quit_requested(event
);
183 case DISPLAYS_CHANGED
:
184 macdrv_displays_changed(event
);
187 macdrv_im_set_text(event
);
191 macdrv_key_event(hwnd
, event
);
193 case KEYBOARD_CHANGED
:
194 macdrv_keyboard_changed(event
);
197 macdrv_mouse_button(hwnd
, event
);
200 case MOUSE_MOVED_ABSOLUTE
:
201 macdrv_mouse_moved(hwnd
, event
);
204 macdrv_mouse_scroll(hwnd
, event
);
207 macdrv_query_event(hwnd
, event
);
209 case RELEASE_CAPTURE
:
210 macdrv_release_capture(hwnd
, event
);
212 case STATUS_ITEM_MOUSE_BUTTON
:
213 macdrv_status_item_mouse_button(event
);
215 case STATUS_ITEM_MOUSE_MOVE
:
216 macdrv_status_item_mouse_move(event
);
218 case WINDOW_CLOSE_REQUESTED
:
219 macdrv_window_close_requested(hwnd
);
221 case WINDOW_DID_MINIMIZE
:
222 macdrv_window_did_minimize(hwnd
);
224 case WINDOW_DID_UNMINIMIZE
:
225 macdrv_window_did_unminimize(hwnd
);
227 case WINDOW_FRAME_CHANGED
:
228 macdrv_window_frame_changed(hwnd
, event
->window_frame_changed
.frame
);
230 case WINDOW_GOT_FOCUS
:
231 macdrv_window_got_focus(hwnd
, event
);
233 case WINDOW_LOST_FOCUS
:
234 macdrv_window_lost_focus(hwnd
, event
);
237 TRACE(" ignoring\n");
241 thread_data
->current_event
= prev
;
245 /***********************************************************************
248 static int process_events(macdrv_event_queue queue
, macdrv_event_mask mask
)
253 while (macdrv_copy_event_from_queue(queue
, mask
, &event
))
256 macdrv_handle_event(event
);
257 macdrv_release_event(event
);
259 if (count
) TRACE("processed %d events\n", count
);
264 /***********************************************************************
265 * MsgWaitForMultipleObjectsEx (MACDRV.@)
267 DWORD CDECL
macdrv_MsgWaitForMultipleObjectsEx(DWORD count
, const HANDLE
*handles
,
268 DWORD timeout
, DWORD mask
, DWORD flags
)
271 struct macdrv_thread_data
*data
= macdrv_thread_data();
272 macdrv_event_mask event_mask
= get_event_mask(mask
);
274 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count
,
275 handles
, timeout
, mask
, flags
);
279 if (!count
&& !timeout
) return WAIT_TIMEOUT
;
280 return WaitForMultipleObjectsEx(count
, handles
, flags
& MWMO_WAITALL
,
281 timeout
, flags
& MWMO_ALERTABLE
);
284 if (data
->current_event
&& data
->current_event
->type
!= QUERY_EVENT
&&
285 data
->current_event
->type
!= APP_QUIT_REQUESTED
)
286 event_mask
= 0; /* don't process nested events */
288 if (process_events(data
->queue
, event_mask
)) ret
= count
- 1;
289 else if (count
|| timeout
)
291 ret
= WaitForMultipleObjectsEx(count
, handles
, flags
& MWMO_WAITALL
,
292 timeout
, flags
& MWMO_ALERTABLE
);
293 if (ret
== count
- 1) process_events(data
->queue
, event_mask
);
295 else ret
= WAIT_TIMEOUT
;