macdrv: Rework the way we handle cursor position and composition text.
[wine.git] / dlls / winemac.drv / event.c
blobdeac187d7c49a27e4a77cf31cb65a37244f0e940
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 "STATUS_ITEM_CLICKED",
48 "WINDOW_CLOSE_REQUESTED",
49 "WINDOW_DID_MINIMIZE",
50 "WINDOW_DID_UNMINIMIZE",
51 "WINDOW_FRAME_CHANGED",
52 "WINDOW_GOT_FOCUS",
53 "WINDOW_LOST_FOCUS",
56 if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
57 return wine_dbg_sprintf("Unknown event %d", type);
61 /***********************************************************************
62 * get_event_mask
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;
70 if (mask & QS_KEY)
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);
109 return event_mask;
113 /***********************************************************************
114 * macdrv_query_event
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;
123 switch (query->type)
125 case QUERY_DRAG_DROP:
126 TRACE("QUERY_DRAG_DROP\n");
127 success = query_drag_drop(query);
128 break;
129 case QUERY_DRAG_EXITED:
130 TRACE("QUERY_DRAG_EXITED\n");
131 success = query_drag_exited(query);
132 break;
133 case QUERY_DRAG_OPERATION:
134 TRACE("QUERY_DRAG_OPERATION\n");
135 success = query_drag_operation(query);
136 break;
137 case QUERY_IME_CHAR_RECT:
138 TRACE("QUERY_IME_CHAR_RECT\n");
139 success = query_ime_char_rect(query);
140 break;
141 case QUERY_PASTEBOARD_DATA:
142 TRACE("QUERY_PASTEBOARD_DATA\n");
143 success = query_pasteboard_data(hwnd, query->pasteboard_data.type);
144 break;
145 default:
146 FIXME("unrecognized query type %d\n", query->type);
147 break;
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,
166 event->window);
168 prev = thread_data->current_event;
169 thread_data->current_event = event;
171 switch (event->type)
173 case APP_DEACTIVATED:
174 macdrv_app_deactivated();
175 break;
176 case APP_QUIT_REQUESTED:
177 macdrv_app_quit_requested(event);
178 break;
179 case DISPLAYS_CHANGED:
180 macdrv_displays_changed(event);
181 break;
182 case IM_SET_TEXT:
183 macdrv_im_set_text(event);
184 break;
185 case KEY_PRESS:
186 case KEY_RELEASE:
187 macdrv_key_event(hwnd, event);
188 break;
189 case KEYBOARD_CHANGED:
190 macdrv_keyboard_changed(event);
191 break;
192 case MOUSE_BUTTON:
193 macdrv_mouse_button(hwnd, event);
194 break;
195 case MOUSE_MOVED:
196 case MOUSE_MOVED_ABSOLUTE:
197 macdrv_mouse_moved(hwnd, event);
198 break;
199 case MOUSE_SCROLL:
200 macdrv_mouse_scroll(hwnd, event);
201 break;
202 case QUERY_EVENT:
203 macdrv_query_event(hwnd, event);
204 break;
205 case STATUS_ITEM_CLICKED:
206 macdrv_status_item_clicked(event);
207 break;
208 case WINDOW_CLOSE_REQUESTED:
209 macdrv_window_close_requested(hwnd);
210 break;
211 case WINDOW_DID_MINIMIZE:
212 macdrv_window_did_minimize(hwnd);
213 break;
214 case WINDOW_DID_UNMINIMIZE:
215 macdrv_window_did_unminimize(hwnd);
216 break;
217 case WINDOW_FRAME_CHANGED:
218 macdrv_window_frame_changed(hwnd, event->window_frame_changed.frame);
219 break;
220 case WINDOW_GOT_FOCUS:
221 macdrv_window_got_focus(hwnd, event);
222 break;
223 case WINDOW_LOST_FOCUS:
224 macdrv_window_lost_focus(hwnd, event);
225 break;
226 default:
227 TRACE(" ignoring\n");
228 break;
231 thread_data->current_event = prev;
235 /***********************************************************************
236 * process_events
238 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
240 macdrv_event *event;
241 int count = 0;
243 while (macdrv_copy_event_from_queue(queue, mask, &event))
245 count++;
246 macdrv_handle_event(event);
247 macdrv_release_event(event);
249 if (count) TRACE("processed %d events\n", count);
250 return count;
254 /***********************************************************************
255 * MsgWaitForMultipleObjectsEx (MACDRV.@)
257 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
258 DWORD timeout, DWORD mask, DWORD flags)
260 DWORD ret;
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);
267 if (!data)
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;
287 return ret;