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",
47 "STATUS_ITEM_CLICKED",
48 "WINDOW_CLOSE_REQUESTED",
49 "WINDOW_DID_MINIMIZE",
50 "WINDOW_DID_UNMINIMIZE",
51 "WINDOW_FRAME_CHANGED",
56 if (0 <= type
&& type
< NUM_EVENT_TYPES
) return event_names
[type
];
57 return wine_dbg_sprintf("Unknown event %d", type
);
61 /***********************************************************************
64 static macdrv_event_mask
get_event_mask(DWORD mask
)
66 macdrv_event_mask event_mask
= 0;
68 if ((mask
& QS_ALLINPUT
) == QS_ALLINPUT
) return -1;
72 event_mask
|= event_mask_for_type(KEY_PRESS
);
73 event_mask
|= event_mask_for_type(KEY_RELEASE
);
74 event_mask
|= event_mask_for_type(KEYBOARD_CHANGED
);
77 if (mask
& QS_MOUSEBUTTON
)
79 event_mask
|= event_mask_for_type(MOUSE_BUTTON
);
80 event_mask
|= event_mask_for_type(MOUSE_SCROLL
);
83 if (mask
& QS_MOUSEMOVE
)
85 event_mask
|= event_mask_for_type(MOUSE_MOVED
);
86 event_mask
|= event_mask_for_type(MOUSE_MOVED_ABSOLUTE
);
89 if (mask
& QS_POSTMESSAGE
)
91 event_mask
|= event_mask_for_type(APP_DEACTIVATED
);
92 event_mask
|= event_mask_for_type(APP_QUIT_REQUESTED
);
93 event_mask
|= event_mask_for_type(DISPLAYS_CHANGED
);
94 event_mask
|= event_mask_for_type(IM_SET_TEXT
);
95 event_mask
|= event_mask_for_type(STATUS_ITEM_CLICKED
);
96 event_mask
|= event_mask_for_type(WINDOW_CLOSE_REQUESTED
);
97 event_mask
|= event_mask_for_type(WINDOW_DID_MINIMIZE
);
98 event_mask
|= event_mask_for_type(WINDOW_DID_UNMINIMIZE
);
99 event_mask
|= event_mask_for_type(WINDOW_FRAME_CHANGED
);
100 event_mask
|= event_mask_for_type(WINDOW_GOT_FOCUS
);
101 event_mask
|= event_mask_for_type(WINDOW_LOST_FOCUS
);
104 if (mask
& QS_SENDMESSAGE
)
106 event_mask
|= event_mask_for_type(QUERY_EVENT
);
113 /***********************************************************************
116 * Handler for QUERY_EVENT queries.
118 static void macdrv_query_event(HWND hwnd
, const macdrv_event
*event
)
120 BOOL success
= FALSE
;
121 macdrv_query
*query
= event
->query_event
.query
;
125 case QUERY_DRAG_DROP
:
126 TRACE("QUERY_DRAG_DROP\n");
127 success
= query_drag_drop(query
);
129 case QUERY_DRAG_EXITED
:
130 TRACE("QUERY_DRAG_EXITED\n");
131 success
= query_drag_exited(query
);
133 case QUERY_DRAG_OPERATION
:
134 TRACE("QUERY_DRAG_OPERATION\n");
135 success
= query_drag_operation(query
);
137 case QUERY_IME_CHAR_RECT
:
138 TRACE("QUERY_IME_CHAR_RECT\n");
139 success
= query_ime_char_rect(query
);
141 case QUERY_PASTEBOARD_DATA
:
142 TRACE("QUERY_PASTEBOARD_DATA\n");
143 success
= query_pasteboard_data(hwnd
, query
->pasteboard_data
.type
);
146 FIXME("unrecognized query type %d\n", query
->type
);
150 TRACE("success %d\n", success
);
151 query
->status
= success
;
152 macdrv_set_query_done(query
);
156 /***********************************************************************
157 * macdrv_handle_event
159 void macdrv_handle_event(const macdrv_event
*event
)
161 HWND hwnd
= macdrv_get_window_hwnd(event
->window
);
162 const macdrv_event
*prev
;
163 struct macdrv_thread_data
*thread_data
= macdrv_thread_data();
165 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event
->type
), hwnd
,
168 prev
= thread_data
->current_event
;
169 thread_data
->current_event
= event
;
173 case APP_DEACTIVATED
:
174 macdrv_app_deactivated();
176 case APP_QUIT_REQUESTED
:
177 macdrv_app_quit_requested(event
);
179 case DISPLAYS_CHANGED
:
180 macdrv_displays_changed(event
);
183 macdrv_im_set_text(event
);
187 macdrv_key_event(hwnd
, event
);
189 case KEYBOARD_CHANGED
:
190 macdrv_keyboard_changed(event
);
193 macdrv_mouse_button(hwnd
, event
);
196 case MOUSE_MOVED_ABSOLUTE
:
197 macdrv_mouse_moved(hwnd
, event
);
200 macdrv_mouse_scroll(hwnd
, event
);
203 macdrv_query_event(hwnd
, event
);
205 case STATUS_ITEM_CLICKED
:
206 macdrv_status_item_clicked(event
);
208 case WINDOW_CLOSE_REQUESTED
:
209 macdrv_window_close_requested(hwnd
);
211 case WINDOW_DID_MINIMIZE
:
212 macdrv_window_did_minimize(hwnd
);
214 case WINDOW_DID_UNMINIMIZE
:
215 macdrv_window_did_unminimize(hwnd
);
217 case WINDOW_FRAME_CHANGED
:
218 macdrv_window_frame_changed(hwnd
, event
->window_frame_changed
.frame
);
220 case WINDOW_GOT_FOCUS
:
221 macdrv_window_got_focus(hwnd
, event
);
223 case WINDOW_LOST_FOCUS
:
224 macdrv_window_lost_focus(hwnd
, event
);
227 TRACE(" ignoring\n");
231 thread_data
->current_event
= prev
;
235 /***********************************************************************
238 static int process_events(macdrv_event_queue queue
, macdrv_event_mask mask
)
243 while (macdrv_copy_event_from_queue(queue
, mask
, &event
))
246 macdrv_handle_event(event
);
247 macdrv_release_event(event
);
249 if (count
) TRACE("processed %d events\n", count
);
254 /***********************************************************************
255 * MsgWaitForMultipleObjectsEx (MACDRV.@)
257 DWORD CDECL
macdrv_MsgWaitForMultipleObjectsEx(DWORD count
, const HANDLE
*handles
,
258 DWORD timeout
, DWORD mask
, DWORD flags
)
261 struct macdrv_thread_data
*data
= macdrv_thread_data();
262 macdrv_event_mask event_mask
= get_event_mask(mask
);
264 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count
,
265 handles
, timeout
, mask
, flags
);
269 if (!count
&& !timeout
) return WAIT_TIMEOUT
;
270 return WaitForMultipleObjectsEx(count
, handles
, flags
& MWMO_WAITALL
,
271 timeout
, flags
& MWMO_ALERTABLE
);
274 if (data
->current_event
&& data
->current_event
->type
!= QUERY_EVENT
&&
275 data
->current_event
->type
!= APP_QUIT_REQUESTED
)
276 event_mask
= 0; /* don't process nested events */
278 if (process_events(data
->queue
, event_mask
)) ret
= count
- 1;
279 else if (count
|| timeout
)
281 ret
= WaitForMultipleObjectsEx(count
, handles
, flags
& MWMO_WAITALL
,
282 timeout
, flags
& MWMO_ALERTABLE
);
283 if (ret
== count
- 1) process_events(data
->queue
, event_mask
);
285 else ret
= WAIT_TIMEOUT
;