msxml3: Implement IXMLParser Get/Set Factory.
[wine/multimedia.git] / dlls / winemac.drv / event.c
blobb9131f7be7874a96587fcb8c4be4910414680f5d
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 "DISPLAYS_CHANGED",
37 "KEY_PRESS",
38 "KEY_RELEASE",
39 "KEYBOARD_CHANGED",
40 "MOUSE_BUTTON",
41 "MOUSE_MOVED",
42 "MOUSE_MOVED_ABSOLUTE",
43 "MOUSE_SCROLL",
44 "WINDOW_CLOSE_REQUESTED",
45 "WINDOW_DID_MINIMIZE",
46 "WINDOW_DID_UNMINIMIZE",
47 "WINDOW_FRAME_CHANGED",
48 "WINDOW_GOT_FOCUS",
49 "WINDOW_LOST_FOCUS",
52 if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
53 return wine_dbg_sprintf("Unknown event %d", type);
57 /***********************************************************************
58 * get_event_mask
60 static macdrv_event_mask get_event_mask(DWORD mask)
62 macdrv_event_mask event_mask = 0;
64 if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return -1;
66 if (mask & QS_KEY)
68 event_mask |= event_mask_for_type(KEY_PRESS);
69 event_mask |= event_mask_for_type(KEY_RELEASE);
70 event_mask |= event_mask_for_type(KEYBOARD_CHANGED);
73 if (mask & QS_MOUSEBUTTON)
75 event_mask |= event_mask_for_type(MOUSE_BUTTON);
76 event_mask |= event_mask_for_type(MOUSE_SCROLL);
79 if (mask & QS_MOUSEMOVE)
81 event_mask |= event_mask_for_type(MOUSE_MOVED);
82 event_mask |= event_mask_for_type(MOUSE_MOVED_ABSOLUTE);
85 if (mask & QS_POSTMESSAGE)
87 event_mask |= event_mask_for_type(APP_DEACTIVATED);
88 event_mask |= event_mask_for_type(DISPLAYS_CHANGED);
89 event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
90 event_mask |= event_mask_for_type(WINDOW_DID_MINIMIZE);
91 event_mask |= event_mask_for_type(WINDOW_DID_UNMINIMIZE);
92 event_mask |= event_mask_for_type(WINDOW_FRAME_CHANGED);
93 event_mask |= event_mask_for_type(WINDOW_GOT_FOCUS);
94 event_mask |= event_mask_for_type(WINDOW_LOST_FOCUS);
97 return event_mask;
101 /***********************************************************************
102 * macdrv_handle_event
104 void macdrv_handle_event(macdrv_event *event)
106 HWND hwnd = macdrv_get_window_hwnd(event->window);
107 const macdrv_event *prev;
108 struct macdrv_thread_data *thread_data = macdrv_thread_data();
110 TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event->type), hwnd,
111 event->window);
113 prev = thread_data->current_event;
114 thread_data->current_event = event;
116 switch (event->type)
118 case APP_DEACTIVATED:
119 macdrv_app_deactivated();
120 break;
121 case DISPLAYS_CHANGED:
122 macdrv_displays_changed(event);
123 break;
124 case KEY_PRESS:
125 case KEY_RELEASE:
126 macdrv_key_event(hwnd, event);
127 break;
128 case KEYBOARD_CHANGED:
129 macdrv_keyboard_changed(event);
130 break;
131 case MOUSE_BUTTON:
132 macdrv_mouse_button(hwnd, event);
133 break;
134 case MOUSE_MOVED:
135 case MOUSE_MOVED_ABSOLUTE:
136 macdrv_mouse_moved(hwnd, event);
137 break;
138 case MOUSE_SCROLL:
139 macdrv_mouse_scroll(hwnd, event);
140 break;
141 case WINDOW_CLOSE_REQUESTED:
142 macdrv_window_close_requested(hwnd);
143 break;
144 case WINDOW_DID_MINIMIZE:
145 macdrv_window_did_minimize(hwnd);
146 break;
147 case WINDOW_DID_UNMINIMIZE:
148 macdrv_window_did_unminimize(hwnd);
149 break;
150 case WINDOW_FRAME_CHANGED:
151 macdrv_window_frame_changed(hwnd, event->window_frame_changed.frame);
152 break;
153 case WINDOW_GOT_FOCUS:
154 macdrv_window_got_focus(hwnd, event);
155 break;
156 case WINDOW_LOST_FOCUS:
157 macdrv_window_lost_focus(hwnd, event);
158 break;
159 default:
160 TRACE(" ignoring\n");
161 break;
164 thread_data->current_event = prev;
168 /***********************************************************************
169 * process_events
171 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
173 macdrv_event event;
174 int count = 0;
176 while (macdrv_get_event_from_queue(queue, mask, &event))
178 count++;
179 macdrv_handle_event(&event);
180 macdrv_cleanup_event(&event);
182 if (count) TRACE("processed %d events\n", count);
183 return count;
187 /***********************************************************************
188 * MsgWaitForMultipleObjectsEx (MACDRV.@)
190 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
191 DWORD timeout, DWORD mask, DWORD flags)
193 DWORD ret;
194 struct macdrv_thread_data *data = macdrv_thread_data();
195 macdrv_event_mask event_mask = get_event_mask(mask);
197 TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count,
198 handles, timeout, mask, flags);
200 if (!data)
202 if (!count && !timeout) return WAIT_TIMEOUT;
203 return WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
204 timeout, flags & MWMO_ALERTABLE);
207 if (data->current_event) event_mask = 0; /* don't process nested events */
209 if (process_events(data->queue, event_mask)) ret = count - 1;
210 else if (count || timeout)
212 ret = WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
213 timeout, flags & MWMO_ALERTABLE);
214 if (ret == count - 1) process_events(data->queue, event_mask);
216 else ret = WAIT_TIMEOUT;
218 return ret;