xmllite: Fail to set input for external IXmlReaderInput.
[wine] / dlls / winemac.drv / event.c
1 /*
2  * MACDRV event driver
3  *
4  * Copyright 1993 Alexandre Julliard
5  *           1999 Noel Borthwick
6  * Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers Inc.
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include "config.h"
24
25 #include "macdrv.h"
26 #include "winuser.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(event);
29
30
31 /* return the name of an Mac event */
32 static const char *dbgstr_event(int type)
33 {
34     static const char * const event_names[] = {
35         "APP_DEACTIVATED",
36         "MOUSE_BUTTON",
37         "WINDOW_CLOSE_REQUESTED",
38         "WINDOW_FRAME_CHANGED",
39         "WINDOW_GOT_FOCUS",
40         "WINDOW_LOST_FOCUS",
41     };
42
43     if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
44     return wine_dbg_sprintf("Unknown event %d", type);
45 }
46
47
48 /***********************************************************************
49  *              get_event_mask
50  */
51 static macdrv_event_mask get_event_mask(DWORD mask)
52 {
53     macdrv_event_mask event_mask = 0;
54
55     if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return -1;
56
57     if (mask & QS_MOUSEBUTTON)
58         event_mask |= event_mask_for_type(MOUSE_BUTTON);
59
60     if (mask & QS_POSTMESSAGE)
61     {
62         event_mask |= event_mask_for_type(APP_DEACTIVATED);
63         event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
64         event_mask |= event_mask_for_type(WINDOW_FRAME_CHANGED);
65         event_mask |= event_mask_for_type(WINDOW_GOT_FOCUS);
66         event_mask |= event_mask_for_type(WINDOW_LOST_FOCUS);
67     }
68
69     return event_mask;
70 }
71
72
73 /***********************************************************************
74  *              macdrv_handle_event
75  */
76 void macdrv_handle_event(macdrv_event *event)
77 {
78     HWND hwnd = macdrv_get_window_hwnd(event->window);
79     const macdrv_event *prev;
80     struct macdrv_thread_data *thread_data = macdrv_thread_data();
81
82     TRACE("%s for hwnd/window %p/%p\n", dbgstr_event(event->type), hwnd,
83           event->window);
84
85     prev = thread_data->current_event;
86     thread_data->current_event = event;
87
88     switch (event->type)
89     {
90     case APP_DEACTIVATED:
91         macdrv_app_deactivated();
92         break;
93     case MOUSE_BUTTON:
94         macdrv_mouse_button(hwnd, event);
95         break;
96     case WINDOW_CLOSE_REQUESTED:
97         macdrv_window_close_requested(hwnd);
98         break;
99     case WINDOW_FRAME_CHANGED:
100         macdrv_window_frame_changed(hwnd, event->window_frame_changed.frame);
101         break;
102     case WINDOW_GOT_FOCUS:
103         macdrv_window_got_focus(hwnd, event);
104         break;
105     case WINDOW_LOST_FOCUS:
106         macdrv_window_lost_focus(hwnd, event);
107         break;
108     default:
109         TRACE("    ignoring\n");
110         break;
111     }
112
113     thread_data->current_event = prev;
114 }
115
116
117 /***********************************************************************
118  *              process_events
119  */
120 static int process_events(macdrv_event_queue queue, macdrv_event_mask mask)
121 {
122     macdrv_event event;
123     int count = 0;
124
125     while (macdrv_get_event_from_queue(queue, mask, &event))
126     {
127         count++;
128         macdrv_handle_event(&event);
129         macdrv_cleanup_event(&event);
130     }
131     if (count) TRACE("processed %d events\n", count);
132     return count;
133 }
134
135
136 /***********************************************************************
137  *              MsgWaitForMultipleObjectsEx   (MACDRV.@)
138  */
139 DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handles,
140                                                DWORD timeout, DWORD mask, DWORD flags)
141 {
142     DWORD ret;
143     struct macdrv_thread_data *data = macdrv_thread_data();
144     macdrv_event_mask event_mask = get_event_mask(mask);
145
146     TRACE("count %d, handles %p, timeout %u, mask %x, flags %x\n", count,
147           handles, timeout, mask, flags);
148
149     if (!data)
150     {
151         if (!count && !timeout) return WAIT_TIMEOUT;
152         return WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
153                                         timeout, flags & MWMO_ALERTABLE);
154     }
155
156     if (data->current_event) event_mask = 0;  /* don't process nested events */
157
158     if (process_events(data->queue, event_mask)) ret = count - 1;
159     else if (count || timeout)
160     {
161         ret = WaitForMultipleObjectsEx(count, handles, flags & MWMO_WAITALL,
162                                        timeout, flags & MWMO_ALERTABLE);
163         if (ret == count - 1) process_events(data->queue, event_mask);
164     }
165     else ret = WAIT_TIMEOUT;
166
167     return ret;
168 }