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
[] = {
42 "MOUSE_MOVED_ABSOLUTE",
44 "WINDOW_CLOSE_REQUESTED",
45 "WINDOW_DID_MINIMIZE",
46 "WINDOW_DID_UNMINIMIZE",
47 "WINDOW_FRAME_CHANGED",
52 if (0 <= type
&& type
< NUM_EVENT_TYPES
) return event_names
[type
];
53 return wine_dbg_sprintf("Unknown event %d", type
);
57 /***********************************************************************
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;
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
);
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
,
113 prev
= thread_data
->current_event
;
114 thread_data
->current_event
= event
;
118 case APP_DEACTIVATED
:
119 macdrv_app_deactivated();
121 case DISPLAYS_CHANGED
:
122 macdrv_displays_changed(event
);
126 macdrv_key_event(hwnd
, event
);
128 case KEYBOARD_CHANGED
:
129 macdrv_keyboard_changed(event
);
132 macdrv_mouse_button(hwnd
, event
);
135 case MOUSE_MOVED_ABSOLUTE
:
136 macdrv_mouse_moved(hwnd
, event
);
139 macdrv_mouse_scroll(hwnd
, event
);
141 case WINDOW_CLOSE_REQUESTED
:
142 macdrv_window_close_requested(hwnd
);
144 case WINDOW_DID_MINIMIZE
:
145 macdrv_window_did_minimize(hwnd
);
147 case WINDOW_DID_UNMINIMIZE
:
148 macdrv_window_did_unminimize(hwnd
);
150 case WINDOW_FRAME_CHANGED
:
151 macdrv_window_frame_changed(hwnd
, event
->window_frame_changed
.frame
);
153 case WINDOW_GOT_FOCUS
:
154 macdrv_window_got_focus(hwnd
, event
);
156 case WINDOW_LOST_FOCUS
:
157 macdrv_window_lost_focus(hwnd
, event
);
160 TRACE(" ignoring\n");
164 thread_data
->current_event
= prev
;
168 /***********************************************************************
171 static int process_events(macdrv_event_queue queue
, macdrv_event_mask mask
)
176 while (macdrv_get_event_from_queue(queue
, mask
, &event
))
179 macdrv_handle_event(&event
);
180 macdrv_cleanup_event(&event
);
182 if (count
) TRACE("processed %d events\n", count
);
187 /***********************************************************************
188 * MsgWaitForMultipleObjectsEx (MACDRV.@)
190 DWORD CDECL
macdrv_MsgWaitForMultipleObjectsEx(DWORD count
, const HANDLE
*handles
,
191 DWORD timeout
, DWORD mask
, DWORD flags
)
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
);
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
;