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",
48 "STATUS_ITEM_CLICKED",
49 "WINDOW_CLOSE_REQUESTED",
50 "WINDOW_DID_MINIMIZE",
51 "WINDOW_DID_UNMINIMIZE",
52 "WINDOW_FRAME_CHANGED",
57 if (0 <= type
&& type
< NUM_EVENT_TYPES
) return event_names
[type
];
58 return wine_dbg_sprintf("Unknown event %d", type
);
62 /***********************************************************************
65 static macdrv_event_mask
get_event_mask(DWORD mask
)
67 macdrv_event_mask event_mask
= 0;
69 if ((mask
& QS_ALLINPUT
) == QS_ALLINPUT
) return -1;
73 event_mask
|= event_mask_for_type(KEY_PRESS
);
74 event_mask
|= event_mask_for_type(KEY_RELEASE
);
75 event_mask
|= event_mask_for_type(KEYBOARD_CHANGED
);
78 if (mask
& QS_MOUSEBUTTON
)
80 event_mask
|= event_mask_for_type(MOUSE_BUTTON
);
81 event_mask
|= event_mask_for_type(MOUSE_SCROLL
);
84 if (mask
& QS_MOUSEMOVE
)
86 event_mask
|= event_mask_for_type(MOUSE_MOVED
);
87 event_mask
|= event_mask_for_type(MOUSE_MOVED_ABSOLUTE
);
90 if (mask
& QS_POSTMESSAGE
)
92 event_mask
|= event_mask_for_type(APP_DEACTIVATED
);
93 event_mask
|= event_mask_for_type(APP_QUIT_REQUESTED
);
94 event_mask
|= event_mask_for_type(DISPLAYS_CHANGED
);
95 event_mask
|= event_mask_for_type(IM_SET_CURSOR_POS
);
96 event_mask
|= event_mask_for_type(IM_SET_TEXT
);
97 event_mask
|= event_mask_for_type(STATUS_ITEM_CLICKED
);
98 event_mask
|= event_mask_for_type(WINDOW_CLOSE_REQUESTED
);
99 event_mask
|= event_mask_for_type(WINDOW_DID_MINIMIZE
);
100 event_mask
|= event_mask_for_type(WINDOW_DID_UNMINIMIZE
);
101 event_mask
|= event_mask_for_type(WINDOW_FRAME_CHANGED
);
102 event_mask
|= event_mask_for_type(WINDOW_GOT_FOCUS
);
103 event_mask
|= event_mask_for_type(WINDOW_LOST_FOCUS
);
106 if (mask
& QS_SENDMESSAGE
)
108 event_mask
|= event_mask_for_type(QUERY_EVENT
);
115 /***********************************************************************
118 * Handler for QUERY_EVENT queries.
120 static void macdrv_query_event(HWND hwnd
, const macdrv_event
*event
)
122 BOOL success
= FALSE
;
123 macdrv_query
*query
= event
->query_event
.query
;
127 case QUERY_DRAG_DROP
:
128 TRACE("QUERY_DRAG_DROP\n");
129 success
= query_drag_drop(query
);
131 case QUERY_DRAG_EXITED
:
132 TRACE("QUERY_DRAG_EXITED\n");
133 success
= query_drag_exited(query
);
135 case QUERY_DRAG_OPERATION
:
136 TRACE("QUERY_DRAG_OPERATION\n");
137 success
= query_drag_operation(query
);
139 case QUERY_PASTEBOARD_DATA
:
140 TRACE("QUERY_PASTEBOARD_DATA\n");
141 success
= query_pasteboard_data(hwnd
, query
->pasteboard_data
.type
);
144 FIXME("unrecognized query type %d\n", query
->type
);
148 TRACE("success %d\n", success
);
149 query
->status
= success
;
150 macdrv_set_query_done(query
);
154 /***********************************************************************
155 * macdrv_handle_event
157 void macdrv_handle_event(const macdrv_event
*event
)
159 HWND hwnd
= macdrv_get_window_hwnd(event
->window
);
160 const macdrv_event
*prev
;
161 struct macdrv_thread_data
*thread_data
= macdrv_thread_data();
163 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event
->type
), hwnd
,
166 prev
= thread_data
->current_event
;
167 thread_data
->current_event
= event
;
171 case APP_DEACTIVATED
:
172 macdrv_app_deactivated();
174 case APP_QUIT_REQUESTED
:
175 macdrv_app_quit_requested(event
);
177 case DISPLAYS_CHANGED
:
178 macdrv_displays_changed(event
);
180 case IM_SET_CURSOR_POS
:
181 macdrv_im_set_cursor_pos(event
);
184 macdrv_im_set_text(event
);
188 macdrv_key_event(hwnd
, event
);
190 case KEYBOARD_CHANGED
:
191 macdrv_keyboard_changed(event
);
194 macdrv_mouse_button(hwnd
, event
);
197 case MOUSE_MOVED_ABSOLUTE
:
198 macdrv_mouse_moved(hwnd
, event
);
201 macdrv_mouse_scroll(hwnd
, event
);
204 macdrv_query_event(hwnd
, event
);
206 case STATUS_ITEM_CLICKED
:
207 macdrv_status_item_clicked(event
);
209 case WINDOW_CLOSE_REQUESTED
:
210 macdrv_window_close_requested(hwnd
);
212 case WINDOW_DID_MINIMIZE
:
213 macdrv_window_did_minimize(hwnd
);
215 case WINDOW_DID_UNMINIMIZE
:
216 macdrv_window_did_unminimize(hwnd
);
218 case WINDOW_FRAME_CHANGED
:
219 macdrv_window_frame_changed(hwnd
, event
->window_frame_changed
.frame
);
221 case WINDOW_GOT_FOCUS
:
222 macdrv_window_got_focus(hwnd
, event
);
224 case WINDOW_LOST_FOCUS
:
225 macdrv_window_lost_focus(hwnd
, event
);
228 TRACE(" ignoring\n");
232 thread_data
->current_event
= prev
;
236 /***********************************************************************
239 static int process_events(macdrv_event_queue queue
, macdrv_event_mask mask
)
244 while (macdrv_copy_event_from_queue(queue
, mask
, &event
))
247 macdrv_handle_event(event
);
248 macdrv_release_event(event
);
250 if (count
) TRACE("processed %d events\n", count
);
255 /***********************************************************************
256 * MsgWaitForMultipleObjectsEx (MACDRV.@)
258 DWORD CDECL
macdrv_MsgWaitForMultipleObjectsEx(DWORD count
, const HANDLE
*handles
,
259 DWORD timeout
, DWORD mask
, DWORD flags
)
262 struct macdrv_thread_data
*data
= macdrv_thread_data();
263 macdrv_event_mask event_mask
= get_event_mask(mask
);
265 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count
,
266 handles
, timeout
, mask
, flags
);
270 if (!count
&& !timeout
) return WAIT_TIMEOUT
;
271 return WaitForMultipleObjectsEx(count
, handles
, flags
& MWMO_WAITALL
,
272 timeout
, flags
& MWMO_ALERTABLE
);
275 if (data
->current_event
&& data
->current_event
->type
!= QUERY_EVENT
&&
276 data
->current_event
->type
!= APP_QUIT_REQUESTED
)
277 event_mask
= 0; /* don't process nested events */
279 if (process_events(data
->queue
, event_mask
)) ret
= count
- 1;
280 else if (count
|| timeout
)
282 ret
= WaitForMultipleObjectsEx(count
, handles
, flags
& MWMO_WAITALL
,
283 timeout
, flags
& MWMO_ALERTABLE
);
284 if (ret
== count
- 1) process_events(data
->queue
, event_mask
);
286 else ret
= WAIT_TIMEOUT
;