wineandroid: Handle additional mouse event types.
[wine.git] / dlls / wineandroid.drv / window.c
blob7d2049d57b74a1c010f552fe21de6eb860b31249
1 /*
2 * Window related functions
4 * Copyright 1993, 1994, 1995, 1996, 2001, 2013-2017 Alexandre Julliard
5 * Copyright 1993 David Metcalfe
6 * Copyright 1995, 1996 Alex Korobka
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 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <fcntl.h>
31 #include <poll.h>
32 #include <errno.h>
33 #include <stdarg.h>
34 #include <stdlib.h>
35 #include <stdio.h>
36 #ifdef HAVE_UNISTD_H
37 # include <unistd.h>
38 #endif
40 #include "windef.h"
41 #include "winbase.h"
42 #include "wingdi.h"
43 #include "winuser.h"
44 #include "wine/unicode.h"
46 #include "android.h"
47 #include "wine/server.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(android);
52 /* private window data */
53 struct android_win_data
55 HWND hwnd; /* hwnd that this private data belongs to */
56 HWND parent; /* parent hwnd for child windows */
57 RECT window_rect; /* USER window rectangle relative to parent */
58 RECT whole_rect; /* X window rectangle for the whole window relative to parent */
59 RECT client_rect; /* client area relative to parent */
60 ANativeWindow *window; /* native window wrapper that forwards calls to the desktop process */
61 struct window_surface *surface;
64 #define SWP_AGG_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
66 static CRITICAL_SECTION win_data_section;
67 static CRITICAL_SECTION_DEBUG critsect_debug =
69 0, 0, &win_data_section,
70 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
71 0, 0, { (DWORD_PTR)(__FILE__ ": win_data_section") }
73 static CRITICAL_SECTION win_data_section = { &critsect_debug, -1, 0, 0, 0, 0 };
75 static struct android_win_data *win_data_context[32768];
77 static inline int context_idx( HWND hwnd )
79 return LOWORD( hwnd ) >> 1;
82 static void set_surface_region( struct window_surface *window_surface, HRGN win_region );
84 /* only for use on sanitized BITMAPINFO structures */
85 static inline int get_dib_info_size( const BITMAPINFO *info, UINT coloruse )
87 if (info->bmiHeader.biCompression == BI_BITFIELDS)
88 return sizeof(BITMAPINFOHEADER) + 3 * sizeof(DWORD);
89 if (coloruse == DIB_PAL_COLORS)
90 return sizeof(BITMAPINFOHEADER) + info->bmiHeader.biClrUsed * sizeof(WORD);
91 return FIELD_OFFSET( BITMAPINFO, bmiColors[info->bmiHeader.biClrUsed] );
94 static inline int get_dib_stride( int width, int bpp )
96 return ((width * bpp + 31) >> 3) & ~3;
99 static inline int get_dib_image_size( const BITMAPINFO *info )
101 return get_dib_stride( info->bmiHeader.biWidth, info->bmiHeader.biBitCount )
102 * abs( info->bmiHeader.biHeight );
106 /***********************************************************************
107 * alloc_win_data
109 static struct android_win_data *alloc_win_data( HWND hwnd )
111 struct android_win_data *data;
113 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
115 data->hwnd = hwnd;
116 data->window = create_ioctl_window( hwnd, FALSE );
117 EnterCriticalSection( &win_data_section );
118 win_data_context[context_idx(hwnd)] = data;
120 return data;
124 /***********************************************************************
125 * free_win_data
127 static void free_win_data( struct android_win_data *data )
129 win_data_context[context_idx( data->hwnd )] = NULL;
130 LeaveCriticalSection( &win_data_section );
131 if (data->window) release_ioctl_window( data->window );
132 HeapFree( GetProcessHeap(), 0, data );
136 /***********************************************************************
137 * get_win_data
139 * Lock and return the data structure associated with a window.
141 static struct android_win_data *get_win_data( HWND hwnd )
143 struct android_win_data *data;
145 if (!hwnd) return NULL;
146 EnterCriticalSection( &win_data_section );
147 if ((data = win_data_context[context_idx(hwnd)]) && data->hwnd == hwnd) return data;
148 LeaveCriticalSection( &win_data_section );
149 return NULL;
153 /***********************************************************************
154 * release_win_data
156 * Release the data returned by get_win_data.
158 static void release_win_data( struct android_win_data *data )
160 if (data) LeaveCriticalSection( &win_data_section );
164 /***********************************************************************
165 * get_ioctl_window
167 static struct ANativeWindow *get_ioctl_window( HWND hwnd )
169 struct ANativeWindow *ret;
170 struct android_win_data *data = get_win_data( hwnd );
172 if (!data || !data->window) return NULL;
173 ret = grab_ioctl_window( data->window );
174 release_win_data( data );
175 return ret;
179 /* Handling of events coming from the Java side */
181 struct java_event
183 struct list entry;
184 union event_data data;
187 static struct list event_queue = LIST_INIT( event_queue );
188 static struct java_event *current_event;
189 static int event_pipe[2];
190 static DWORD desktop_tid;
192 /***********************************************************************
193 * send_event
195 int send_event( const union event_data *data )
197 int res;
199 if ((res = write( event_pipe[1], data, sizeof(*data) )) != sizeof(*data))
201 p__android_log_print( ANDROID_LOG_ERROR, "wine", "failed to send event" );
202 return -1;
204 return 0;
208 /***********************************************************************
209 * desktop_changed
211 * JNI callback, runs in the context of the Java thread.
213 void desktop_changed( JNIEnv *env, jobject obj, jint width, jint height )
215 union event_data data;
217 memset( &data, 0, sizeof(data) );
218 data.type = DESKTOP_CHANGED;
219 data.desktop.width = width;
220 data.desktop.height = height;
221 p__android_log_print( ANDROID_LOG_INFO, "wine", "desktop_changed: %ux%u", width, height );
222 send_event( &data );
226 /***********************************************************************
227 * config_changed
229 * JNI callback, runs in the context of the Java thread.
231 void config_changed( JNIEnv *env, jobject obj, jint dpi )
233 union event_data data;
235 memset( &data, 0, sizeof(data) );
236 data.type = CONFIG_CHANGED;
237 data.cfg.dpi = dpi;
238 p__android_log_print( ANDROID_LOG_INFO, "wine", "config_changed: %u dpi", dpi );
239 send_event( &data );
243 /***********************************************************************
244 * surface_changed
246 * JNI callback, runs in the context of the Java thread.
248 void surface_changed( JNIEnv *env, jobject obj, jint win, jobject surface, jboolean client )
250 union event_data data;
252 memset( &data, 0, sizeof(data) );
253 data.surface.hwnd = LongToHandle( win );
254 data.surface.client = client;
255 if (surface)
257 int width, height;
258 ANativeWindow *win = pANativeWindow_fromSurface( env, surface );
260 if (win->query( win, NATIVE_WINDOW_WIDTH, &width ) < 0) width = 0;
261 if (win->query( win, NATIVE_WINDOW_HEIGHT, &height ) < 0) height = 0;
262 data.surface.window = win;
263 data.surface.width = width;
264 data.surface.height = height;
265 p__android_log_print( ANDROID_LOG_INFO, "wine", "surface_changed: %p %s %ux%u",
266 data.surface.hwnd, client ? "client" : "whole", width, height );
268 data.type = SURFACE_CHANGED;
269 send_event( &data );
273 /***********************************************************************
274 * motion_event
276 * JNI callback, runs in the context of the Java thread.
278 jboolean motion_event( JNIEnv *env, jobject obj, jint win, jint action, jint x, jint y, jint state, jint vscroll )
280 static LONG button_state;
281 union event_data data;
282 int prev_state;
284 int mask = action & AMOTION_EVENT_ACTION_MASK;
286 if (!( mask == AMOTION_EVENT_ACTION_DOWN ||
287 mask == AMOTION_EVENT_ACTION_UP ||
288 mask == AMOTION_EVENT_ACTION_CANCEL ||
289 mask == AMOTION_EVENT_ACTION_SCROLL ||
290 mask == AMOTION_EVENT_ACTION_MOVE ||
291 mask == AMOTION_EVENT_ACTION_HOVER_MOVE ||
292 mask == AMOTION_EVENT_ACTION_BUTTON_PRESS ||
293 mask == AMOTION_EVENT_ACTION_BUTTON_RELEASE ))
294 return JNI_FALSE;
296 prev_state = InterlockedExchange( &button_state, state );
298 data.type = MOTION_EVENT;
299 data.motion.hwnd = LongToHandle( win );
300 data.motion.input.type = INPUT_MOUSE;
301 data.motion.input.u.mi.dx = x;
302 data.motion.input.u.mi.dy = y;
303 data.motion.input.u.mi.mouseData = 0;
304 data.motion.input.u.mi.time = 0;
305 data.motion.input.u.mi.dwExtraInfo = 0;
306 data.motion.input.u.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
307 switch (action & AMOTION_EVENT_ACTION_MASK)
309 case AMOTION_EVENT_ACTION_DOWN:
310 case AMOTION_EVENT_ACTION_BUTTON_PRESS:
311 if ((state & ~prev_state) & AMOTION_EVENT_BUTTON_PRIMARY)
312 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
313 if ((state & ~prev_state) & AMOTION_EVENT_BUTTON_SECONDARY)
314 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_RIGHTDOWN;
315 if ((state & ~prev_state) & AMOTION_EVENT_BUTTON_TERTIARY)
316 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_MIDDLEDOWN;
317 if (!(state & ~prev_state)) /* touch event */
318 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
319 break;
320 case AMOTION_EVENT_ACTION_UP:
321 case AMOTION_EVENT_ACTION_CANCEL:
322 case AMOTION_EVENT_ACTION_BUTTON_RELEASE:
323 if ((prev_state & ~state) & AMOTION_EVENT_BUTTON_PRIMARY)
324 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
325 if ((prev_state & ~state) & AMOTION_EVENT_BUTTON_SECONDARY)
326 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_RIGHTUP;
327 if ((prev_state & ~state) & AMOTION_EVENT_BUTTON_TERTIARY)
328 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_MIDDLEUP;
329 if (!(prev_state & ~state)) /* touch event */
330 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
331 break;
332 case AMOTION_EVENT_ACTION_SCROLL:
333 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_WHEEL;
334 data.motion.input.u.mi.mouseData = vscroll < 0 ? -WHEEL_DELTA : WHEEL_DELTA;
335 break;
336 case AMOTION_EVENT_ACTION_MOVE:
337 case AMOTION_EVENT_ACTION_HOVER_MOVE:
338 break;
339 default:
340 return JNI_FALSE;
342 send_event( &data );
343 return JNI_TRUE;
347 /***********************************************************************
348 * init_event_queue
350 static void init_event_queue(void)
352 HANDLE handle;
353 int ret;
355 if (pipe2( event_pipe, O_CLOEXEC | O_NONBLOCK ) == -1)
357 ERR( "could not create data\n" );
358 ExitProcess(1);
360 if (wine_server_fd_to_handle( event_pipe[0], GENERIC_READ | SYNCHRONIZE, 0, &handle ))
362 ERR( "Can't allocate handle for event fd\n" );
363 ExitProcess(1);
365 SERVER_START_REQ( set_queue_fd )
367 req->handle = wine_server_obj_handle( handle );
368 ret = wine_server_call( req );
370 SERVER_END_REQ;
371 if (ret)
373 ERR( "Can't store handle for event fd %x\n", ret );
374 ExitProcess(1);
376 CloseHandle( handle );
377 desktop_tid = GetCurrentThreadId();
381 /***********************************************************************
382 * pull_events
384 * Pull events from the event pipe and add them to the queue
386 static void pull_events(void)
388 struct java_event *event;
389 int res;
391 for (;;)
393 if (!(event = HeapAlloc( GetProcessHeap(), 0, sizeof(*event) ))) break;
395 res = read( event_pipe[0], &event->data, sizeof(event->data) );
396 if (res != sizeof(event->data)) break;
397 list_add_tail( &event_queue, &event->entry );
399 HeapFree( GetProcessHeap(), 0, event );
403 /***********************************************************************
404 * process_events
406 static int process_events( DWORD mask )
408 struct java_event *event, *next, *previous;
409 unsigned int count = 0;
411 assert( GetCurrentThreadId() == desktop_tid );
413 pull_events();
415 previous = current_event;
417 LIST_FOR_EACH_ENTRY_SAFE( event, next, &event_queue, struct java_event, entry )
419 switch (event->data.type)
421 case SURFACE_CHANGED:
422 break; /* always process it to unblock other threads */
423 case MOTION_EVENT:
424 if (event->data.motion.input.u.mi.dwFlags & (MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_RIGHTDOWN|
425 MOUSEEVENTF_MIDDLEDOWN|MOUSEEVENTF_LEFTUP|
426 MOUSEEVENTF_RIGHTUP|MOUSEEVENTF_MIDDLEUP))
428 if (mask & QS_MOUSEBUTTON) break;
430 else if (mask & QS_MOUSEMOVE) break;
431 continue; /* skip it */
432 case KEYBOARD_EVENT:
433 if (mask & QS_KEY) break;
434 continue; /* skip it */
435 default:
436 if (mask & QS_SENDMESSAGE) break;
437 continue; /* skip it */
440 /* remove it first, in case we process events recursively */
441 list_remove( &event->entry );
442 current_event = event;
444 switch (event->data.type)
446 case DESKTOP_CHANGED:
447 TRACE( "DESKTOP_CHANGED %ux%u\n", event->data.desktop.width, event->data.desktop.height );
448 screen_width = event->data.desktop.width;
449 screen_height = event->data.desktop.height;
450 init_monitors( screen_width, screen_height );
451 SetWindowPos( GetDesktopWindow(), 0, 0, 0, screen_width, screen_height,
452 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW );
453 break;
455 case CONFIG_CHANGED:
456 TRACE( "CONFIG_CHANGED dpi %u\n", event->data.cfg.dpi );
457 set_screen_dpi( event->data.cfg.dpi );
458 break;
460 case SURFACE_CHANGED:
461 TRACE("SURFACE_CHANGED %p %p %s size %ux%u\n", event->data.surface.hwnd,
462 event->data.surface.window, event->data.surface.client ? "client" : "whole",
463 event->data.surface.width, event->data.surface.height );
465 register_native_window( event->data.surface.hwnd, event->data.surface.window, event->data.surface.client );
466 break;
468 case MOTION_EVENT:
470 HWND capture = get_capture_window();
472 if (event->data.motion.input.u.mi.dwFlags & (MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_RIGHTDOWN|MOUSEEVENTF_MIDDLEDOWN))
473 TRACE( "BUTTONDOWN pos %d,%d hwnd %p flags %x\n",
474 event->data.motion.input.u.mi.dx, event->data.motion.input.u.mi.dy,
475 event->data.motion.hwnd, event->data.motion.input.u.mi.dwFlags );
476 else if (event->data.motion.input.u.mi.dwFlags & (MOUSEEVENTF_LEFTUP|MOUSEEVENTF_RIGHTUP|MOUSEEVENTF_MIDDLEUP))
477 TRACE( "BUTTONUP pos %d,%d hwnd %p flags %x\n",
478 event->data.motion.input.u.mi.dx, event->data.motion.input.u.mi.dy,
479 event->data.motion.hwnd, event->data.motion.input.u.mi.dwFlags );
480 else
481 TRACE( "MOUSEMOVE pos %d,%d hwnd %p flags %x\n",
482 event->data.motion.input.u.mi.dx, event->data.motion.input.u.mi.dy,
483 event->data.motion.hwnd, event->data.motion.input.u.mi.dwFlags );
484 if (!capture && (event->data.motion.input.u.mi.dwFlags & MOUSEEVENTF_ABSOLUTE))
486 RECT rect;
487 SetRect( &rect, event->data.motion.input.u.mi.dx, event->data.motion.input.u.mi.dy,
488 event->data.motion.input.u.mi.dx + 1, event->data.motion.input.u.mi.dy + 1 );
489 MapWindowPoints( 0, event->data.motion.hwnd, (POINT *)&rect, 2 );
491 SERVER_START_REQ( update_window_zorder )
493 req->window = wine_server_user_handle( event->data.motion.hwnd );
494 req->rect.left = rect.left;
495 req->rect.top = rect.top;
496 req->rect.right = rect.right;
497 req->rect.bottom = rect.bottom;
498 wine_server_call( req );
500 SERVER_END_REQ;
502 __wine_send_input( capture ? capture : event->data.motion.hwnd, &event->data.motion.input );
504 break;
506 case KEYBOARD_EVENT:
507 if (event->data.kbd.input.u.ki.dwFlags & KEYEVENTF_KEYUP)
508 TRACE("KEYUP hwnd %p vkey %x '%c' scancode %x\n", event->data.kbd.hwnd,
509 event->data.kbd.input.u.ki.wVk, event->data.kbd.input.u.ki.wVk,
510 event->data.kbd.input.u.ki.wScan );
511 else
512 TRACE("KEYDOWN hwnd %p vkey %x '%c' scancode %x\n", event->data.kbd.hwnd,
513 event->data.kbd.input.u.ki.wVk, event->data.kbd.input.u.ki.wVk,
514 event->data.kbd.input.u.ki.wScan );
515 update_keyboard_lock_state( event->data.kbd.input.u.ki.wVk, event->data.kbd.lock_state );
516 __wine_send_input( 0, &event->data.kbd.input );
517 break;
519 default:
520 FIXME( "got event %u\n", event->data.type );
522 HeapFree( GetProcessHeap(), 0, event );
523 count++;
524 /* next may have been removed by a recursive call, so reset it to the beginning of the list */
525 next = LIST_ENTRY( event_queue.next, struct java_event, entry );
527 current_event = previous;
528 return count;
532 /***********************************************************************
533 * wait_events
535 static int wait_events( int timeout )
537 assert( GetCurrentThreadId() == desktop_tid );
539 for (;;)
541 struct pollfd pollfd;
542 int ret;
544 pollfd.fd = event_pipe[0];
545 pollfd.events = POLLIN | POLLHUP;
546 ret = poll( &pollfd, 1, timeout );
547 if (ret == -1 && errno == EINTR) continue;
548 if (ret && (pollfd.revents & (POLLHUP | POLLERR))) ret = -1;
549 return ret;
554 /* Window surface support */
556 struct android_window_surface
558 struct window_surface header;
559 HWND hwnd;
560 ANativeWindow *window;
561 RECT bounds;
562 BOOL byteswap;
563 RGNDATA *region_data;
564 HRGN region;
565 BYTE alpha;
566 COLORREF color_key;
567 void *bits;
568 CRITICAL_SECTION crit;
569 BITMAPINFO info; /* variable size, must be last */
572 static struct android_window_surface *get_android_surface( struct window_surface *surface )
574 return (struct android_window_surface *)surface;
577 static inline void reset_bounds( RECT *bounds )
579 bounds->left = bounds->top = INT_MAX;
580 bounds->right = bounds->bottom = INT_MIN;
583 static inline void add_bounds_rect( RECT *bounds, const RECT *rect )
585 if (rect->left >= rect->right || rect->top >= rect->bottom) return;
586 bounds->left = min( bounds->left, rect->left );
587 bounds->top = min( bounds->top, rect->top );
588 bounds->right = max( bounds->right, rect->right );
589 bounds->bottom = max( bounds->bottom, rect->bottom );
592 /* store the palette or color mask data in the bitmap info structure */
593 static void set_color_info( BITMAPINFO *info, BOOL has_alpha )
595 DWORD *colors = (DWORD *)info->bmiColors;
597 info->bmiHeader.biSize = sizeof(info->bmiHeader);
598 info->bmiHeader.biClrUsed = 0;
599 info->bmiHeader.biBitCount = 32;
600 if (has_alpha)
602 info->bmiHeader.biCompression = BI_RGB;
603 return;
605 info->bmiHeader.biCompression = BI_BITFIELDS;
606 colors[0] = 0xff0000;
607 colors[1] = 0x00ff00;
608 colors[2] = 0x0000ff;
611 /* apply the window region to a single line of the destination image. */
612 static void apply_line_region( DWORD *dst, int width, int x, int y, const RECT *rect, const RECT *end )
614 while (rect < end && rect->top <= y && width > 0)
616 if (rect->left > x)
618 memset( dst, 0, min( rect->left - x, width ) * sizeof(*dst) );
619 dst += rect->left - x;
620 width -= rect->left - x;
621 x = rect->left;
623 if (rect->right > x)
625 dst += rect->right - x;
626 width -= rect->right - x;
627 x = rect->right;
629 rect++;
631 if (width > 0) memset( dst, 0, width * sizeof(*dst) );
634 /***********************************************************************
635 * android_surface_lock
637 static void android_surface_lock( struct window_surface *window_surface )
639 struct android_window_surface *surface = get_android_surface( window_surface );
641 EnterCriticalSection( &surface->crit );
644 /***********************************************************************
645 * android_surface_unlock
647 static void android_surface_unlock( struct window_surface *window_surface )
649 struct android_window_surface *surface = get_android_surface( window_surface );
651 LeaveCriticalSection( &surface->crit );
654 /***********************************************************************
655 * android_surface_get_bitmap_info
657 static void *android_surface_get_bitmap_info( struct window_surface *window_surface, BITMAPINFO *info )
659 struct android_window_surface *surface = get_android_surface( window_surface );
661 memcpy( info, &surface->info, get_dib_info_size( &surface->info, DIB_RGB_COLORS ));
662 return surface->bits;
665 /***********************************************************************
666 * android_surface_get_bounds
668 static RECT *android_surface_get_bounds( struct window_surface *window_surface )
670 struct android_window_surface *surface = get_android_surface( window_surface );
672 return &surface->bounds;
675 /***********************************************************************
676 * android_surface_set_region
678 static void android_surface_set_region( struct window_surface *window_surface, HRGN region )
680 struct android_window_surface *surface = get_android_surface( window_surface );
682 TRACE( "updating surface %p hwnd %p with %p\n", surface, surface->hwnd, region );
684 window_surface->funcs->lock( window_surface );
685 if (!region)
687 if (surface->region) DeleteObject( surface->region );
688 surface->region = 0;
690 else
692 if (!surface->region) surface->region = CreateRectRgn( 0, 0, 0, 0 );
693 CombineRgn( surface->region, region, 0, RGN_COPY );
695 window_surface->funcs->unlock( window_surface );
696 set_surface_region( &surface->header, (HRGN)1 );
699 /***********************************************************************
700 * android_surface_flush
702 static void android_surface_flush( struct window_surface *window_surface )
704 struct android_window_surface *surface = get_android_surface( window_surface );
705 ANativeWindow_Buffer buffer;
706 ARect rc;
707 RECT rect;
708 BOOL needs_flush;
710 window_surface->funcs->lock( window_surface );
711 SetRect( &rect, 0, 0, surface->header.rect.right - surface->header.rect.left,
712 surface->header.rect.bottom - surface->header.rect.top );
713 needs_flush = IntersectRect( &rect, &rect, &surface->bounds );
714 reset_bounds( &surface->bounds );
715 window_surface->funcs->unlock( window_surface );
716 if (!needs_flush) return;
718 TRACE( "flushing %p hwnd %p surface %s rect %s bits %p alpha %02x key %08x region %u rects\n",
719 surface, surface->hwnd, wine_dbgstr_rect( &surface->header.rect ),
720 wine_dbgstr_rect( &rect ), surface->bits, surface->alpha, surface->color_key,
721 surface->region_data ? surface->region_data->rdh.nCount : 0 );
723 rc.left = rect.left;
724 rc.top = rect.top;
725 rc.right = rect.right;
726 rc.bottom = rect.bottom;
728 if (!surface->window->perform( surface->window, NATIVE_WINDOW_LOCK, &buffer, &rc ))
730 const RECT *rgn_rect = NULL, *end = NULL;
731 unsigned int *src, *dst;
732 int x, y, width;
734 rect.left = rc.left;
735 rect.top = rc.top;
736 rect.right = rc.right;
737 rect.bottom = rc.bottom;
738 IntersectRect( &rect, &rect, &surface->header.rect );
740 if (surface->region_data)
742 rgn_rect = (RECT *)surface->region_data->Buffer;
743 end = rgn_rect + surface->region_data->rdh.nCount;
745 src = (unsigned int *)surface->bits
746 + (rect.top - surface->header.rect.top) * surface->info.bmiHeader.biWidth
747 + (rect.left - surface->header.rect.left);
748 dst = (unsigned int *)buffer.bits + rect.top * buffer.stride + rect.left;
749 width = min( rect.right - rect.left, buffer.stride );
751 for (y = rect.top; y < min( buffer.height, rect.bottom); y++)
753 if (surface->info.bmiHeader.biCompression == BI_RGB)
754 memcpy( dst, src, width * sizeof(*dst) );
755 else if (surface->alpha == 255)
756 for (x = 0; x < width; x++) dst[x] = src[x] | 0xff000000;
757 else
758 for (x = 0; x < width; x++)
759 dst[x] = ((surface->alpha << 24) |
760 (((BYTE)(src[x] >> 16) * surface->alpha / 255) << 16) |
761 (((BYTE)(src[x] >> 8) * surface->alpha / 255) << 8) |
762 (((BYTE)src[x] * surface->alpha / 255)));
764 if (surface->color_key != CLR_INVALID)
765 for (x = 0; x < width; x++) if ((src[x] & 0xffffff) == surface->color_key) dst[x] = 0;
767 if (rgn_rect)
769 while (rgn_rect < end && rgn_rect->bottom <= y) rgn_rect++;
770 apply_line_region( dst, width, rect.left, y, rgn_rect, end );
773 src += surface->info.bmiHeader.biWidth;
774 dst += buffer.stride;
776 surface->window->perform( surface->window, NATIVE_WINDOW_UNLOCK_AND_POST );
778 else TRACE( "Unable to lock surface %p window %p buffer %p\n",
779 surface, surface->hwnd, surface->window );
782 /***********************************************************************
783 * android_surface_destroy
785 static void android_surface_destroy( struct window_surface *window_surface )
787 struct android_window_surface *surface = get_android_surface( window_surface );
789 TRACE( "freeing %p bits %p\n", surface, surface->bits );
791 surface->crit.DebugInfo->Spare[0] = 0;
792 DeleteCriticalSection( &surface->crit );
793 HeapFree( GetProcessHeap(), 0, surface->region_data );
794 if (surface->region) DeleteObject( surface->region );
795 release_ioctl_window( surface->window );
796 HeapFree( GetProcessHeap(), 0, surface->bits );
797 HeapFree( GetProcessHeap(), 0, surface );
800 static const struct window_surface_funcs android_surface_funcs =
802 android_surface_lock,
803 android_surface_unlock,
804 android_surface_get_bitmap_info,
805 android_surface_get_bounds,
806 android_surface_set_region,
807 android_surface_flush,
808 android_surface_destroy
811 static BOOL is_argb_surface( struct window_surface *surface )
813 return surface && surface->funcs == &android_surface_funcs &&
814 get_android_surface( surface )->info.bmiHeader.biCompression == BI_RGB;
817 /***********************************************************************
818 * set_color_key
820 static void set_color_key( struct android_window_surface *surface, COLORREF key )
822 if (key == CLR_INVALID)
823 surface->color_key = CLR_INVALID;
824 else if (surface->info.bmiHeader.biBitCount <= 8)
825 surface->color_key = CLR_INVALID;
826 else if (key & (1 << 24)) /* PALETTEINDEX */
827 surface->color_key = 0;
828 else if (key >> 16 == 0x10ff) /* DIBINDEX */
829 surface->color_key = 0;
830 else if (surface->info.bmiHeader.biBitCount == 24)
831 surface->color_key = key;
832 else
833 surface->color_key = (GetRValue(key) << 16) | (GetGValue(key) << 8) | GetBValue(key);
836 /***********************************************************************
837 * set_surface_region
839 static void set_surface_region( struct window_surface *window_surface, HRGN win_region )
841 struct android_window_surface *surface = get_android_surface( window_surface );
842 struct android_win_data *win_data;
843 HRGN region = win_region;
844 RGNDATA *data = NULL;
845 DWORD size;
846 int offset_x, offset_y;
848 if (window_surface->funcs != &android_surface_funcs) return; /* we may get the null surface */
850 if (!(win_data = get_win_data( surface->hwnd ))) return;
851 offset_x = win_data->window_rect.left - win_data->whole_rect.left;
852 offset_y = win_data->window_rect.top - win_data->whole_rect.top;
853 release_win_data( win_data );
855 if (win_region == (HRGN)1) /* hack: win_region == 1 means retrieve region from server */
857 region = CreateRectRgn( 0, 0, win_data->window_rect.right - win_data->window_rect.left,
858 win_data->window_rect.bottom - win_data->window_rect.top );
859 if (GetWindowRgn( surface->hwnd, region ) == ERROR && !surface->region) goto done;
862 OffsetRgn( region, offset_x, offset_y );
863 if (surface->region) CombineRgn( region, region, surface->region, RGN_AND );
865 if (!(size = GetRegionData( region, 0, NULL ))) goto done;
866 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) goto done;
868 if (!GetRegionData( region, size, data ))
870 HeapFree( GetProcessHeap(), 0, data );
871 data = NULL;
874 done:
875 window_surface->funcs->lock( window_surface );
876 HeapFree( GetProcessHeap(), 0, surface->region_data );
877 surface->region_data = data;
878 *window_surface->funcs->get_bounds( window_surface ) = surface->header.rect;
879 window_surface->funcs->unlock( window_surface );
880 if (region != win_region) DeleteObject( region );
883 /***********************************************************************
884 * create_surface
886 static struct window_surface *create_surface( HWND hwnd, const RECT *rect,
887 BYTE alpha, COLORREF color_key, BOOL src_alpha )
889 struct android_window_surface *surface;
890 int width = rect->right - rect->left, height = rect->bottom - rect->top;
892 surface = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
893 FIELD_OFFSET( struct android_window_surface, info.bmiColors[3] ));
894 if (!surface) return NULL;
895 set_color_info( &surface->info, src_alpha );
896 surface->info.bmiHeader.biWidth = width;
897 surface->info.bmiHeader.biHeight = -height; /* top-down */
898 surface->info.bmiHeader.biPlanes = 1;
899 surface->info.bmiHeader.biSizeImage = get_dib_image_size( &surface->info );
901 InitializeCriticalSection( &surface->crit );
902 surface->crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": surface");
904 surface->header.funcs = &android_surface_funcs;
905 surface->header.rect = *rect;
906 surface->header.ref = 1;
907 surface->hwnd = hwnd;
908 surface->window = get_ioctl_window( hwnd );
909 surface->alpha = alpha;
910 set_color_key( surface, color_key );
911 set_surface_region( &surface->header, (HRGN)1 );
912 reset_bounds( &surface->bounds );
914 if (!(surface->bits = HeapAlloc( GetProcessHeap(), 0, surface->info.bmiHeader.biSizeImage )))
915 goto failed;
917 TRACE( "created %p hwnd %p %s bits %p-%p\n", surface, hwnd, wine_dbgstr_rect(rect),
918 surface->bits, (char *)surface->bits + surface->info.bmiHeader.biSizeImage );
920 return &surface->header;
922 failed:
923 android_surface_destroy( &surface->header );
924 return NULL;
927 /***********************************************************************
928 * set_surface_layered
930 static void set_surface_layered( struct window_surface *window_surface, BYTE alpha, COLORREF color_key )
932 struct android_window_surface *surface = get_android_surface( window_surface );
933 COLORREF prev_key;
934 BYTE prev_alpha;
936 if (window_surface->funcs != &android_surface_funcs) return; /* we may get the null surface */
938 window_surface->funcs->lock( window_surface );
939 prev_key = surface->color_key;
940 prev_alpha = surface->alpha;
941 surface->alpha = alpha;
942 set_color_key( surface, color_key );
943 if (alpha != prev_alpha || surface->color_key != prev_key) /* refresh */
944 *window_surface->funcs->get_bounds( window_surface ) = surface->header.rect;
945 window_surface->funcs->unlock( window_surface );
949 static WNDPROC desktop_orig_wndproc;
951 static LRESULT CALLBACK desktop_wndproc_wrapper( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
953 switch (msg)
955 case WM_PARENTNOTIFY:
956 if (LOWORD(wp) == WM_DESTROY) destroy_ioctl_window( (HWND)lp, FALSE );
957 break;
959 return desktop_orig_wndproc( hwnd, msg, wp, lp );
963 /***********************************************************************
964 * ANDROID_MsgWaitForMultipleObjectsEx
966 DWORD CDECL ANDROID_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
967 DWORD timeout, DWORD mask, DWORD flags )
969 if (GetCurrentThreadId() == desktop_tid)
971 /* don't process nested events */
972 if (current_event) mask = 0;
973 if (process_events( mask )) return count - 1;
975 return WaitForMultipleObjectsEx( count, handles, flags & MWMO_WAITALL,
976 timeout, flags & MWMO_ALERTABLE );
979 /**********************************************************************
980 * ANDROID_CreateWindow
982 BOOL CDECL ANDROID_CreateWindow( HWND hwnd )
984 TRACE( "%p\n", hwnd );
986 if (hwnd == GetDesktopWindow())
988 struct android_win_data *data;
990 init_event_queue();
991 start_android_device();
992 if (!(data = alloc_win_data( hwnd ))) return FALSE;
993 release_win_data( data );
995 return TRUE;
999 /***********************************************************************
1000 * ANDROID_DestroyWindow
1002 void CDECL ANDROID_DestroyWindow( HWND hwnd )
1004 struct android_win_data *data;
1006 if (!(data = get_win_data( hwnd ))) return;
1008 if (data->surface) window_surface_release( data->surface );
1009 data->surface = NULL;
1010 destroy_gl_drawable( hwnd );
1011 free_win_data( data );
1015 /***********************************************************************
1016 * create_win_data
1018 * Create a data window structure for an existing window.
1020 static struct android_win_data *create_win_data( HWND hwnd, const RECT *window_rect,
1021 const RECT *client_rect )
1023 struct android_win_data *data;
1024 HWND parent;
1026 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop or HWND_MESSAGE */
1028 if (!(data = alloc_win_data( hwnd ))) return NULL;
1030 data->parent = (parent == GetDesktopWindow()) ? 0 : parent;
1031 data->whole_rect = data->window_rect = *window_rect;
1032 data->client_rect = *client_rect;
1033 return data;
1037 static inline BOOL get_surface_rect( const RECT *visible_rect, RECT *surface_rect )
1039 if (!IntersectRect( surface_rect, visible_rect, &virtual_screen_rect )) return FALSE;
1040 OffsetRect( surface_rect, -visible_rect->left, -visible_rect->top );
1041 surface_rect->left &= ~31;
1042 surface_rect->top &= ~31;
1043 surface_rect->right = max( surface_rect->left + 32, (surface_rect->right + 31) & ~31 );
1044 surface_rect->bottom = max( surface_rect->top + 32, (surface_rect->bottom + 31) & ~31 );
1045 return TRUE;
1049 /***********************************************************************
1050 * ANDROID_WindowPosChanging
1052 void CDECL ANDROID_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flags,
1053 const RECT *window_rect, const RECT *client_rect, RECT *visible_rect,
1054 struct window_surface **surface )
1056 struct android_win_data *data = get_win_data( hwnd );
1057 RECT surface_rect;
1058 DWORD flags;
1059 COLORREF key;
1060 BYTE alpha;
1061 BOOL layered = GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYERED;
1063 TRACE( "win %p window %s client %s style %08x flags %08x\n",
1064 hwnd, wine_dbgstr_rect(window_rect), wine_dbgstr_rect(client_rect),
1065 GetWindowLongW( hwnd, GWL_STYLE ), swp_flags );
1067 if (!data && !(data = create_win_data( hwnd, window_rect, client_rect ))) return;
1069 *visible_rect = *window_rect;
1071 /* create the window surface if necessary */
1073 if (data->parent) goto done;
1074 if (swp_flags & SWP_HIDEWINDOW) goto done;
1075 if (is_argb_surface( data->surface )) goto done;
1076 if (!get_surface_rect( visible_rect, &surface_rect )) goto done;
1078 if (data->surface)
1080 if (!memcmp( &data->surface->rect, &surface_rect, sizeof(surface_rect) ))
1082 /* existing surface is good enough */
1083 window_surface_add_ref( data->surface );
1084 if (*surface) window_surface_release( *surface );
1085 *surface = data->surface;
1086 goto done;
1089 if (!(swp_flags & SWP_SHOWWINDOW) && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)) goto done;
1091 if (!layered || !GetLayeredWindowAttributes( hwnd, &key, &alpha, &flags )) flags = 0;
1092 if (!(flags & LWA_ALPHA)) alpha = 255;
1093 if (!(flags & LWA_COLORKEY)) key = CLR_INVALID;
1095 if (*surface) window_surface_release( *surface );
1096 *surface = create_surface( data->hwnd, &surface_rect, alpha, key, FALSE );
1098 done:
1099 release_win_data( data );
1103 /***********************************************************************
1104 * ANDROID_WindowPosChanged
1106 void CDECL ANDROID_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags,
1107 const RECT *window_rect, const RECT *client_rect,
1108 const RECT *visible_rect, const RECT *valid_rects,
1109 struct window_surface *surface )
1111 struct android_win_data *data;
1112 DWORD new_style = GetWindowLongW( hwnd, GWL_STYLE );
1113 HWND owner = 0;
1115 if (!(data = get_win_data( hwnd ))) return;
1117 data->window_rect = *window_rect;
1118 data->whole_rect = *visible_rect;
1119 data->client_rect = *client_rect;
1121 if (!is_argb_surface( data->surface ))
1123 if (surface) window_surface_add_ref( surface );
1124 if (data->surface) window_surface_release( data->surface );
1125 data->surface = surface;
1127 if (!data->parent) owner = GetWindow( hwnd, GW_OWNER );
1128 release_win_data( data );
1130 if (!(swp_flags & SWP_NOZORDER)) insert_after = GetWindow( hwnd, GW_HWNDPREV );
1132 TRACE( "win %p window %s client %s style %08x owner %p after %p flags %08x\n", hwnd,
1133 wine_dbgstr_rect(window_rect), wine_dbgstr_rect(client_rect),
1134 new_style, owner, insert_after, swp_flags );
1136 ioctl_window_pos_changed( hwnd, window_rect, client_rect, visible_rect,
1137 new_style, swp_flags, insert_after, owner );
1141 /***********************************************************************
1142 * ANDROID_ShowWindow
1144 UINT CDECL ANDROID_ShowWindow( HWND hwnd, INT cmd, RECT *rect, UINT swp )
1146 if (IsRectEmpty( rect )) return swp;
1147 if (!IsIconic( hwnd )) return swp;
1148 /* always hide icons off-screen */
1149 if (rect->left != -32000 || rect->top != -32000)
1151 OffsetRect( rect, -32000 - rect->left, -32000 - rect->top );
1152 swp &= ~(SWP_NOMOVE | SWP_NOCLIENTMOVE);
1154 return swp;
1158 /*****************************************************************
1159 * ANDROID_SetParent
1161 void CDECL ANDROID_SetParent( HWND hwnd, HWND parent, HWND old_parent )
1163 struct android_win_data *data;
1165 if (parent == old_parent) return;
1166 if (!(data = get_win_data( hwnd ))) return;
1168 TRACE( "win %p parent %p -> %p\n", hwnd, old_parent, parent );
1170 data->parent = (parent == GetDesktopWindow()) ? 0 : parent;
1171 ioctl_set_window_parent( hwnd, parent );
1172 release_win_data( data );
1176 /***********************************************************************
1177 * ANDROID_SetCapture
1179 void CDECL ANDROID_SetCapture( HWND hwnd, UINT flags )
1181 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
1182 ioctl_set_capture( hwnd );
1186 /***********************************************************************
1187 * ANDROID_SetWindowStyle
1189 void CDECL ANDROID_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style )
1191 struct android_win_data *data;
1192 DWORD changed = style->styleNew ^ style->styleOld;
1194 if (hwnd == GetDesktopWindow()) return;
1195 if (!(data = get_win_data( hwnd ))) return;
1197 if (offset == GWL_EXSTYLE && (changed & WS_EX_LAYERED)) /* changing WS_EX_LAYERED resets attributes */
1199 if (is_argb_surface( data->surface ))
1201 if (data->surface) window_surface_release( data->surface );
1202 data->surface = NULL;
1204 else if (data->surface) set_surface_layered( data->surface, 255, CLR_INVALID );
1206 release_win_data( data );
1210 /***********************************************************************
1211 * ANDROID_SetWindowRgn
1213 void CDECL ANDROID_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1215 struct android_win_data *data;
1217 if ((data = get_win_data( hwnd )))
1219 if (data->surface) set_surface_region( data->surface, hrgn );
1220 release_win_data( data );
1222 else FIXME( "not supported on other process window %p\n", hwnd );
1226 /***********************************************************************
1227 * ANDROID_SetLayeredWindowAttributes
1229 void CDECL ANDROID_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
1231 struct android_win_data *data;
1233 if (!(flags & LWA_ALPHA)) alpha = 255;
1234 if (!(flags & LWA_COLORKEY)) key = CLR_INVALID;
1236 if ((data = get_win_data( hwnd )))
1238 if (data->surface) set_surface_layered( data->surface, alpha, key );
1239 release_win_data( data );
1244 /*****************************************************************************
1245 * ANDROID_UpdateLayeredWindow
1247 BOOL CDECL ANDROID_UpdateLayeredWindow( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info,
1248 const RECT *window_rect )
1250 struct window_surface *surface;
1251 struct android_win_data *data;
1252 BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, 0 };
1253 COLORREF color_key = (info->dwFlags & ULW_COLORKEY) ? info->crKey : CLR_INVALID;
1254 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
1255 BITMAPINFO *bmi = (BITMAPINFO *)buffer;
1256 void *src_bits, *dst_bits;
1257 RECT rect, src_rect;
1258 HDC hdc = 0;
1259 HBITMAP dib;
1260 BOOL ret = FALSE;
1262 if (!(data = get_win_data( hwnd ))) return FALSE;
1264 rect = *window_rect;
1265 OffsetRect( &rect, -window_rect->left, -window_rect->top );
1267 surface = data->surface;
1268 if (!is_argb_surface( surface ))
1270 if (surface) window_surface_release( surface );
1271 surface = NULL;
1274 if (!surface || !EqualRect( &surface->rect, &rect ))
1276 data->surface = create_surface( data->hwnd, &rect, 255, color_key, TRUE );
1277 if (surface) window_surface_release( surface );
1278 surface = data->surface;
1280 else set_surface_layered( surface, 255, color_key );
1282 if (surface) window_surface_add_ref( surface );
1283 release_win_data( data );
1285 if (!surface) return FALSE;
1286 if (!info->hdcSrc)
1288 window_surface_release( surface );
1289 return TRUE;
1292 dst_bits = surface->funcs->get_info( surface, bmi );
1294 if (!(dib = CreateDIBSection( info->hdcDst, bmi, DIB_RGB_COLORS, &src_bits, NULL, 0 ))) goto done;
1295 if (!(hdc = CreateCompatibleDC( 0 ))) goto done;
1297 SelectObject( hdc, dib );
1299 surface->funcs->lock( surface );
1301 if (info->prcDirty)
1303 IntersectRect( &rect, &rect, info->prcDirty );
1304 memcpy( src_bits, dst_bits, bmi->bmiHeader.biSizeImage );
1305 PatBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, BLACKNESS );
1307 src_rect = rect;
1308 if (info->pptSrc) OffsetRect( &src_rect, info->pptSrc->x, info->pptSrc->y );
1309 DPtoLP( info->hdcSrc, (POINT *)&src_rect, 2 );
1311 ret = GdiAlphaBlend( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
1312 info->hdcSrc, src_rect.left, src_rect.top,
1313 src_rect.right - src_rect.left, src_rect.bottom - src_rect.top,
1314 (info->dwFlags & ULW_ALPHA) ? *info->pblend : blend );
1315 if (ret)
1317 memcpy( dst_bits, src_bits, bmi->bmiHeader.biSizeImage );
1318 add_bounds_rect( surface->funcs->get_bounds( surface ), &rect );
1321 surface->funcs->unlock( surface );
1322 surface->funcs->flush( surface );
1324 done:
1325 window_surface_release( surface );
1326 if (hdc) DeleteDC( hdc );
1327 if (dib) DeleteObject( dib );
1328 return ret;
1332 /**********************************************************************
1333 * ANDROID_WindowMessage
1335 LRESULT CDECL ANDROID_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
1337 struct android_win_data *data;
1339 switch (msg)
1341 case WM_ANDROID_REFRESH:
1342 if (wp) /* opengl client window */
1344 update_gl_drawable( hwnd );
1346 else if ((data = get_win_data( hwnd )))
1348 struct window_surface *surface = data->surface;
1349 if (surface)
1351 surface->funcs->lock( surface );
1352 *surface->funcs->get_bounds( surface ) = surface->rect;
1353 surface->funcs->unlock( surface );
1354 if (is_argb_surface( surface )) surface->funcs->flush( surface );
1356 release_win_data( data );
1358 return 0;
1359 default:
1360 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg, hwnd, wp, lp );
1361 return 0;
1366 /***********************************************************************
1367 * ANDROID_create_desktop
1369 BOOL CDECL ANDROID_create_desktop( UINT width, UINT height )
1371 desktop_orig_wndproc = (WNDPROC)SetWindowLongPtrW( GetDesktopWindow(), GWLP_WNDPROC,
1372 (LONG_PTR)desktop_wndproc_wrapper );
1374 /* wait until we receive the surface changed event */
1375 while (!screen_width)
1377 if (wait_events( 2000 ) != 1)
1379 ERR( "wait timed out\n" );
1380 break;
1382 process_events( QS_ALLINPUT );
1384 return TRUE;