winemac: Add support for mouse-move and right- and middle-click events on systray...
[wine/multimedia.git] / dlls / winemac.drv / event.c
blob8a8acf36b53dc719e97cb93a3b80ade913174495
1 /*
2 * MACDRV event driver
4 * Copyright 1993 Alexandre Julliard
5 * 1999 Noel Borthwick
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
23 #include "config.h"
25 #include "macdrv.h"
26 #include "winuser.h"
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[] = {
35 "APP_DEACTIVATED",
36 "APP_QUIT_REQUESTED",
37 "DISPLAYS_CHANGED",
38 "IM_SET_TEXT",
39 "KEY_PRESS",
40 "KEY_RELEASE",
41 "KEYBOARD_CHANGED",
42 "MOUSE_BUTTON",
43 "MOUSE_MOVED",
44 "MOUSE_MOVED_ABSOLUTE",
45 "MOUSE_SCROLL",
46 "QUERY_EVENT",
47 "RELEASE_CAPTURE",
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",
54 "WINDOW_GOT_FOCUS",
55 "WINDOW_LOST_FOCUS",
58 if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
59 return wine_dbg_sprintf("Unknown event %d", type);
63 /***********************************************************************
64 * get_event_mask
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;
72 if (mask & QS_KEY)
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);
113 return event_mask;
117 /***********************************************************************
118 * macdrv_query_event
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;
127 switch (query->type)
129 case QUERY_DRAG_DROP:
130 TRACE("QUERY_DRAG_DROP\n");
131 success = query_drag_drop(query);
132 break;
133 case QUERY_DRAG_EXITED:
134 TRACE("QUERY_DRAG_EXITED\n");
135 success = query_drag_exited(query);
136 break;
137 case QUERY_DRAG_OPERATION:
138 TRACE("QUERY_DRAG_OPERATION\n");
139 success = query_drag_operation(query);
140 break;
141 case QUERY_IME_CHAR_RECT:
142 TRACE("QUERY_IME_CHAR_RECT\n");
143 success = query_ime_char_rect(query);
144 break;
145 case QUERY_PASTEBOARD_DATA:
146 TRACE("QUERY_PASTEBOARD_DATA\n");
147 success = query_pasteboard_data(hwnd, query->pasteboard_data.type);
148 break;
149 default:
150 FIXME("unrecognized query type %d\n", query->type);
151 break;
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,
170 event->window);
172 prev = thread_data->current_event;
173 thread_data->current_event = event;
175 switch (event->type)
177 case APP_DEACTIVATED:
178 macdrv_app_deactivated();
179 break;
180 case APP_QUIT_REQUESTED:
181 macdrv_app_quit_requested(event);
182 break;
183 case DISPLAYS_CHANGED:
184 macdrv_displays_changed(event);
185 break;
186 case IM_SET_TEXT:
187 macdrv_im_set_text(event);
188 break;
189 case KEY_PRESS:
190 case KEY_RELEASE:
191 macdrv_key_event(hwnd, event);
192 break;
193 case KEYBOARD_CHANGED:
194 macdrv_keyboard_changed(event);
195 break;
196 case MOUSE_BUTTON:
197 macdrv_mouse_button(hwnd, event);
198 break;
199 case MOUSE_MOVED:
200 case MOUSE_MOVED_ABSOLUTE:
201 macdrv_mouse_moved(hwnd, event);
202 break;
203 case MOUSE_SCROLL:
204 macdrv_mouse_scroll(hwnd, event);
205 break;
206 case QUERY_EVENT:
207 macdrv_query_event(hwnd, event);
208 break;
209 case RELEASE_CAPTURE:
210 macdrv_release_capture(hwnd, event);
211 break;
212 case STATUS_ITEM_MOUSE_BUTTON:
213 macdrv_status_item_mouse_button(event);
214 break;
215 case STATUS_ITEM_MOUSE_MOVE:
216 macdrv_status_item_mouse_move(event);
217 break;
218 case WINDOW_CLOSE_REQUESTED:
219 macdrv_window_close_requested(hwnd);
220 break;
221 case WINDOW_DID_MINIMIZE:
222 macdrv_window_did_minimize(hwnd);
223 break;
224 case WINDOW_DID_UNMINIMIZE:
225 macdrv_window_did_unminimize(hwnd);
226 break;
227 case WINDOW_FRAME_CHANGED:
228 macdrv_window_frame_changed(hwnd, event->window_frame_changed.frame);
229 break;
230 case WINDOW_GOT_FOCUS:
231 macdrv_window_got_focus(hwnd, event);
232 break;
233 case WINDOW_LOST_FOCUS:
234 macdrv_window_lost_focus(hwnd, event);
235 break;
236 default:
237 TRACE(" ignoring\n");
238 break;
241 thread_data->current_event = prev;
245 /***********************************************************************
246 * process_events
248 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
250 macdrv_event *event;
251 int count = 0;
253 while (macdrv_copy_event_from_queue(queue, mask, &event))
255 count++;
256 macdrv_handle_event(event);
257 macdrv_release_event(event);
259 if (count) TRACE("processed %d events\n", count);
260 return count;
264 /***********************************************************************
265 * MsgWaitForMultipleObjectsEx (MACDRV.@)
267 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
268 DWORD timeout, DWORD mask, DWORD flags)
270 DWORD ret;
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);
277 if (!data)
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;
297 return ret;