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
[] = {
41 "MOUSE_MOVED_ABSOLUTE",
43 "WINDOW_CLOSE_REQUESTED",
44 "WINDOW_DID_MINIMIZE",
45 "WINDOW_DID_UNMINIMIZE",
46 "WINDOW_FRAME_CHANGED",
51 if (0 <= type
&& type
< NUM_EVENT_TYPES
) return event_names
[type
];
52 return wine_dbg_sprintf("Unknown event %d", type
);
56 /***********************************************************************
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;
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
);
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
,
111 prev
= thread_data
->current_event
;
112 thread_data
->current_event
= event
;
116 case APP_DEACTIVATED
:
117 macdrv_app_deactivated();
121 macdrv_key_event(hwnd
, event
);
123 case KEYBOARD_CHANGED
:
124 macdrv_keyboard_changed(event
);
127 macdrv_mouse_button(hwnd
, event
);
130 case MOUSE_MOVED_ABSOLUTE
:
131 macdrv_mouse_moved(hwnd
, event
);
134 macdrv_mouse_scroll(hwnd
, event
);
136 case WINDOW_CLOSE_REQUESTED
:
137 macdrv_window_close_requested(hwnd
);
139 case WINDOW_DID_MINIMIZE
:
140 macdrv_window_did_minimize(hwnd
);
142 case WINDOW_DID_UNMINIMIZE
:
143 macdrv_window_did_unminimize(hwnd
);
145 case WINDOW_FRAME_CHANGED
:
146 macdrv_window_frame_changed(hwnd
, event
->window_frame_changed
.frame
);
148 case WINDOW_GOT_FOCUS
:
149 macdrv_window_got_focus(hwnd
, event
);
151 case WINDOW_LOST_FOCUS
:
152 macdrv_window_lost_focus(hwnd
, event
);
155 TRACE(" ignoring\n");
159 thread_data
->current_event
= prev
;
163 /***********************************************************************
166 static int process_events(macdrv_event_queue queue
, macdrv_event_mask mask
)
171 while (macdrv_get_event_from_queue(queue
, mask
, &event
))
174 macdrv_handle_event(&event
);
175 macdrv_cleanup_event(&event
);
177 if (count
) TRACE("processed %d events\n", count
);
182 /***********************************************************************
183 * MsgWaitForMultipleObjectsEx (MACDRV.@)
185 DWORD CDECL
macdrv_MsgWaitForMultipleObjectsEx(DWORD count
, const HANDLE
*handles
,
186 DWORD timeout
, DWORD mask
, DWORD flags
)
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
);
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
;