winemac: Implement MOUSE_SCROLL events.
[wine.git] / dlls / winemac.drv / event.c
blobf03fef4cf6b4453efecd9f2989a1c4787e06f07b
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 "KEY_PRESS",
37 "KEY_RELEASE",
38 "KEYBOARD_CHANGED",
39 "MOUSE_BUTTON",
40 "MOUSE_MOVED",
41 "MOUSE_MOVED_ABSOLUTE",
42 "MOUSE_SCROLL",
43 "WINDOW_CLOSE_REQUESTED",
44 "WINDOW_DID_MINIMIZE",
45 "WINDOW_DID_UNMINIMIZE",
46 "WINDOW_FRAME_CHANGED",
47 "WINDOW_GOT_FOCUS",
48 "WINDOW_LOST_FOCUS",
51 if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
52 return wine_dbg_sprintf("Unknown event %d", type);
56 /***********************************************************************
57 * get_event_mask
59 static macdrv_event_mask get_event_mask(DWORD mask)
61 macdrv_event_mask event_mask = 0;
63 if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return -1;
65 if (mask & QS_KEY)
67 event_mask |= event_mask_for_type(KEY_PRESS);
68 event_mask |= event_mask_for_type(KEY_RELEASE);
69 event_mask |= event_mask_for_type(KEYBOARD_CHANGED);
72 if (mask & QS_MOUSEBUTTON)
74 event_mask |= event_mask_for_type(MOUSE_BUTTON);
75 event_mask |= event_mask_for_type(MOUSE_SCROLL);
78 if (mask & QS_MOUSEMOVE)
80 event_mask |= event_mask_for_type(MOUSE_MOVED);
81 event_mask |= event_mask_for_type(MOUSE_MOVED_ABSOLUTE);
84 if (mask & QS_POSTMESSAGE)
86 event_mask |= event_mask_for_type(APP_DEACTIVATED);
87 event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
88 event_mask |= event_mask_for_type(WINDOW_DID_MINIMIZE);
89 event_mask |= event_mask_for_type(WINDOW_DID_UNMINIMIZE);
90 event_mask |= event_mask_for_type(WINDOW_FRAME_CHANGED);
91 event_mask |= event_mask_for_type(WINDOW_GOT_FOCUS);
92 event_mask |= event_mask_for_type(WINDOW_LOST_FOCUS);
95 return event_mask;
99 /***********************************************************************
100 * macdrv_handle_event
102 void macdrv_handle_event(macdrv_event *event)
104 HWND hwnd = macdrv_get_window_hwnd(event->window);
105 const macdrv_event *prev;
106 struct macdrv_thread_data *thread_data = macdrv_thread_data();
108 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event->type), hwnd,
109 event->window);
111 prev = thread_data->current_event;
112 thread_data->current_event = event;
114 switch (event->type)
116 case APP_DEACTIVATED:
117 macdrv_app_deactivated();
118 break;
119 case KEY_PRESS:
120 case KEY_RELEASE:
121 macdrv_key_event(hwnd, event);
122 break;
123 case KEYBOARD_CHANGED:
124 macdrv_keyboard_changed(event);
125 break;
126 case MOUSE_BUTTON:
127 macdrv_mouse_button(hwnd, event);
128 break;
129 case MOUSE_MOVED:
130 case MOUSE_MOVED_ABSOLUTE:
131 macdrv_mouse_moved(hwnd, event);
132 break;
133 case MOUSE_SCROLL:
134 macdrv_mouse_scroll(hwnd, event);
135 break;
136 case WINDOW_CLOSE_REQUESTED:
137 macdrv_window_close_requested(hwnd);
138 break;
139 case WINDOW_DID_MINIMIZE:
140 macdrv_window_did_minimize(hwnd);
141 break;
142 case WINDOW_DID_UNMINIMIZE:
143 macdrv_window_did_unminimize(hwnd);
144 break;
145 case WINDOW_FRAME_CHANGED:
146 macdrv_window_frame_changed(hwnd, event->window_frame_changed.frame);
147 break;
148 case WINDOW_GOT_FOCUS:
149 macdrv_window_got_focus(hwnd, event);
150 break;
151 case WINDOW_LOST_FOCUS:
152 macdrv_window_lost_focus(hwnd, event);
153 break;
154 default:
155 TRACE(" ignoring\n");
156 break;
159 thread_data->current_event = prev;
163 /***********************************************************************
164 * process_events
166 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
168 macdrv_event event;
169 int count = 0;
171 while (macdrv_get_event_from_queue(queue, mask, &event))
173 count++;
174 macdrv_handle_event(&event);
175 macdrv_cleanup_event(&event);
177 if (count) TRACE("processed %d events\n", count);
178 return count;
182 /***********************************************************************
183 * MsgWaitForMultipleObjectsEx (MACDRV.@)
185 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
186 DWORD timeout, DWORD mask, DWORD flags)
188 DWORD ret;
189 struct macdrv_thread_data *data = macdrv_thread_data();
190 macdrv_event_mask event_mask = get_event_mask(mask);
192 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count,
193 handles, timeout, mask, flags);
195 if (!data)
197 if (!count && !timeout) return WAIT_TIMEOUT;
198 return WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
199 timeout, flags & MWMO_ALERTABLE);
202 if (data->current_event) event_mask = 0; /* don't process nested events */
204 if (process_events(data->queue, event_mask)) ret = count - 1;
205 else if (count || timeout)
207 ret = WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
208 timeout, flags & MWMO_ALERTABLE);
209 if (ret == count - 1) process_events(data->queue, event_mask);
211 else ret = WAIT_TIMEOUT;
213 return ret;