ws2_32/tests: Use winetest_push_context() in test_WSAAddressToString().
[wine.git] / server / window.c
blob7675cd1103d6d2bae65b5bc831b13401f217629c
1 /*
2 * Server-side window handling
4 * Copyright (C) 2001 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <assert.h>
24 #include <stdarg.h>
26 #include "ntstatus.h"
27 #define WIN32_NO_STATUS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "ntuser.h"
32 #include "object.h"
33 #include "request.h"
34 #include "thread.h"
35 #include "process.h"
36 #include "user.h"
37 #include "unicode.h"
39 /* a window property */
40 struct property
42 unsigned short type; /* property type (see below) */
43 atom_t atom; /* property atom */
44 lparam_t data; /* property data (user-defined storage) */
47 enum property_type
49 PROP_TYPE_FREE, /* free entry */
50 PROP_TYPE_STRING, /* atom that was originally a string */
51 PROP_TYPE_ATOM /* plain atom */
55 struct window
57 struct object obj; /* object header */
58 struct window *parent; /* parent window */
59 user_handle_t owner; /* owner of this window */
60 struct list children; /* list of children in Z-order */
61 struct list unlinked; /* list of children not linked in the Z-order list */
62 struct list entry; /* entry in parent's children list */
63 user_handle_t handle; /* full handle for this window */
64 struct thread *thread; /* thread owning the window */
65 struct desktop *desktop; /* desktop that the window belongs to */
66 struct window_class *class; /* window class */
67 atom_t atom; /* class atom */
68 user_handle_t last_active; /* last active popup */
69 rectangle_t window_rect; /* window rectangle (relative to parent client area) */
70 rectangle_t visible_rect; /* visible part of window rect (relative to parent client area) */
71 rectangle_t surface_rect; /* window surface rectangle (relative to parent client area) */
72 rectangle_t client_rect; /* client rectangle (relative to parent client area) */
73 struct region *win_region; /* region for shaped windows (relative to window rect) */
74 struct region *update_region; /* update region (relative to window rect) */
75 unsigned int style; /* window style */
76 unsigned int ex_style; /* window extended style */
77 lparam_t id; /* window id */
78 mod_handle_t instance; /* creator instance */
79 unsigned int is_unicode : 1; /* ANSI or unicode */
80 unsigned int is_linked : 1; /* is it linked into the parent z-order list? */
81 unsigned int is_layered : 1; /* has layered info been set? */
82 unsigned int is_orphan : 1; /* is window orphaned */
83 unsigned int color_key; /* color key for a layered window */
84 unsigned int alpha; /* alpha value for a layered window */
85 unsigned int layered_flags; /* flags for a layered window */
86 unsigned int dpi; /* window DPI or 0 if per-monitor aware */
87 DPI_AWARENESS dpi_awareness; /* DPI awareness mode */
88 lparam_t user_data; /* user-specific data */
89 WCHAR *text; /* window caption text */
90 data_size_t text_len; /* length of window caption */
91 unsigned int paint_flags; /* various painting flags */
92 int prop_inuse; /* number of in-use window properties */
93 int prop_alloc; /* number of allocated window properties */
94 struct property *properties; /* window properties array */
95 int nb_extra_bytes; /* number of extra bytes */
96 char *extra_bytes; /* extra bytes storage */
99 static void window_dump( struct object *obj, int verbose );
100 static void window_destroy( struct object *obj );
102 static const struct object_ops window_ops =
104 sizeof(struct window), /* size */
105 &no_type, /* type */
106 window_dump, /* dump */
107 no_add_queue, /* add_queue */
108 NULL, /* remove_queue */
109 NULL, /* signaled */
110 NULL, /* satisfied */
111 no_signal, /* signal */
112 no_get_fd, /* get_fd */
113 default_map_access, /* map_access */
114 default_get_sd, /* get_sd */
115 default_set_sd, /* set_sd */
116 no_get_full_name, /* get_full_name */
117 no_lookup_name, /* lookup_name */
118 no_link_name, /* link_name */
119 NULL, /* unlink_name */
120 no_open_file, /* open_file */
121 no_kernel_obj_list, /* get_kernel_obj_list */
122 no_close_handle, /* close_handle */
123 window_destroy /* destroy */
126 /* flags that can be set by the client */
127 #define PAINT_HAS_SURFACE SET_WINPOS_PAINT_SURFACE
128 #define PAINT_HAS_PIXEL_FORMAT SET_WINPOS_PIXEL_FORMAT
129 #define PAINT_CLIENT_FLAGS (PAINT_HAS_SURFACE | PAINT_HAS_PIXEL_FORMAT)
130 /* flags only manipulated by the server */
131 #define PAINT_INTERNAL 0x0010 /* internal WM_PAINT pending */
132 #define PAINT_ERASE 0x0020 /* needs WM_ERASEBKGND */
133 #define PAINT_NONCLIENT 0x0040 /* needs WM_NCPAINT */
134 #define PAINT_DELAYED_ERASE 0x0080 /* still needs erase after WM_ERASEBKGND */
135 #define PAINT_PIXEL_FORMAT_CHILD 0x0100 /* at least one child has a custom pixel format */
137 /* growable array of user handles */
138 struct user_handle_array
140 user_handle_t *handles;
141 int count;
142 int total;
145 static const rectangle_t empty_rect;
147 /* global window pointers */
148 static struct window *shell_window;
149 static struct window *shell_listview;
150 static struct window *progman_window;
151 static struct window *taskman_window;
153 /* magic HWND_TOP etc. pointers */
154 #define WINPTR_TOP ((struct window *)1L)
155 #define WINPTR_BOTTOM ((struct window *)2L)
156 #define WINPTR_TOPMOST ((struct window *)3L)
157 #define WINPTR_NOTOPMOST ((struct window *)4L)
159 static void window_dump( struct object *obj, int verbose )
161 struct window *win = (struct window *)obj;
162 assert( obj->ops == &window_ops );
163 fprintf( stderr, "window %p handle %x\n", win, win->handle );
166 static void window_destroy( struct object *obj )
168 struct window *win = (struct window *)obj;
170 assert( !win->handle );
172 if (win->parent)
174 list_remove( &win->entry );
175 release_object( win->parent );
178 if (win->win_region) free_region( win->win_region );
179 if (win->update_region) free_region( win->update_region );
180 if (win->class) release_class( win->class );
181 free( win->text );
183 if (win->nb_extra_bytes)
185 memset( win->extra_bytes, 0x55, win->nb_extra_bytes );
186 free( win->extra_bytes );
190 /* retrieve a pointer to a window from its handle */
191 static inline struct window *get_window( user_handle_t handle )
193 struct window *ret = get_user_object( handle, USER_WINDOW );
194 if (!ret) set_win32_error( ERROR_INVALID_WINDOW_HANDLE );
195 return ret;
198 /* check if window is the desktop */
199 static inline int is_desktop_window( const struct window *win )
201 return !win->parent; /* only desktop windows have no parent */
204 /* check if window is orphaned */
205 static int is_orphan_window( struct window *win )
207 do if (win->is_orphan) return 1;
208 while ((win = win->parent));
209 return 0;
212 /* get next window in Z-order list */
213 static inline struct window *get_next_window( struct window *win )
215 struct list *ptr = list_next( &win->parent->children, &win->entry );
216 return ptr ? LIST_ENTRY( ptr, struct window, entry ) : NULL;
219 /* get previous window in Z-order list */
220 static inline struct window *get_prev_window( struct window *win )
222 struct list *ptr = list_prev( &win->parent->children, &win->entry );
223 return ptr ? LIST_ENTRY( ptr, struct window, entry ) : NULL;
226 /* get first child in Z-order list */
227 static inline struct window *get_first_child( struct window *win )
229 struct list *ptr = list_head( &win->children );
230 return ptr ? LIST_ENTRY( ptr, struct window, entry ) : NULL;
233 /* get last child in Z-order list */
234 static inline struct window *get_last_child( struct window *win )
236 struct list *ptr = list_tail( &win->children );
237 return ptr ? LIST_ENTRY( ptr, struct window, entry ) : NULL;
240 /* set the PAINT_PIXEL_FORMAT_CHILD flag on all the parents */
241 /* note: we never reset the flag, it's just a heuristic */
242 static inline void update_pixel_format_flags( struct window *win )
244 for (win = win->parent; win && win->parent; win = win->parent)
245 win->paint_flags |= PAINT_PIXEL_FORMAT_CHILD;
248 /* get the per-monitor DPI for a window */
249 static unsigned int get_monitor_dpi( struct window *win )
251 /* FIXME: we return the desktop window DPI for now */
252 while (!is_desktop_window( win )) win = win->parent;
253 return win->dpi ? win->dpi : USER_DEFAULT_SCREEN_DPI;
256 /* link a window at the right place in the siblings list */
257 static void link_window( struct window *win, struct window *previous )
259 if (previous == WINPTR_NOTOPMOST)
261 if (!(win->ex_style & WS_EX_TOPMOST) && win->is_linked) return; /* nothing to do */
262 win->ex_style &= ~WS_EX_TOPMOST;
263 previous = WINPTR_TOP; /* fallback to the HWND_TOP case */
266 list_remove( &win->entry ); /* unlink it from the previous location */
268 if (previous == WINPTR_BOTTOM)
270 list_add_tail( &win->parent->children, &win->entry );
271 win->ex_style &= ~WS_EX_TOPMOST;
273 else if (previous == WINPTR_TOPMOST)
275 list_add_head( &win->parent->children, &win->entry );
276 win->ex_style |= WS_EX_TOPMOST;
278 else if (previous == WINPTR_TOP)
280 struct list *entry = win->parent->children.next;
281 if (!(win->ex_style & WS_EX_TOPMOST)) /* put it above the first non-topmost window */
283 while (entry != &win->parent->children)
285 struct window *next = LIST_ENTRY( entry, struct window, entry );
286 if (!(next->ex_style & WS_EX_TOPMOST)) break;
287 if (next->handle == win->owner) /* keep it above owner */
289 win->ex_style |= WS_EX_TOPMOST;
290 break;
292 entry = entry->next;
295 list_add_before( entry, &win->entry );
297 else
299 list_add_after( &previous->entry, &win->entry );
300 if (!(previous->ex_style & WS_EX_TOPMOST)) win->ex_style &= ~WS_EX_TOPMOST;
301 else
303 struct window *next = get_next_window( win );
304 if (next && (next->ex_style & WS_EX_TOPMOST)) win->ex_style |= WS_EX_TOPMOST;
308 win->is_linked = 1;
311 /* change the parent of a window (or unlink the window if the new parent is NULL) */
312 static int set_parent_window( struct window *win, struct window *parent )
314 struct window *ptr;
316 /* make sure parent is not a child of window */
317 for (ptr = parent; ptr; ptr = ptr->parent)
319 if (ptr == win)
321 set_error( STATUS_INVALID_PARAMETER );
322 return 0;
326 if (parent)
328 if (win->parent) release_object( win->parent );
329 win->parent = (struct window *)grab_object( parent );
330 link_window( win, WINPTR_TOP );
332 if (!is_desktop_window( parent ))
334 win->dpi = parent->dpi;
335 win->dpi_awareness = parent->dpi_awareness;
338 /* if parent belongs to a different thread and the window isn't */
339 /* top-level, attach the two threads */
340 if (parent->thread && parent->thread != win->thread && !is_desktop_window(parent))
341 attach_thread_input( win->thread, parent->thread );
343 if (win->paint_flags & (PAINT_HAS_PIXEL_FORMAT | PAINT_PIXEL_FORMAT_CHILD))
344 update_pixel_format_flags( win );
346 else /* move it to parent unlinked list */
348 list_remove( &win->entry ); /* unlink it from the previous location */
349 list_add_head( &win->parent->unlinked, &win->entry );
350 win->is_linked = 0;
351 win->is_orphan = 1;
353 return 1;
356 /* append a user handle to a handle array */
357 static int add_handle_to_array( struct user_handle_array *array, user_handle_t handle )
359 if (array->count >= array->total)
361 int new_total = max( array->total * 2, 32 );
362 user_handle_t *new_array = realloc( array->handles, new_total * sizeof(*new_array) );
363 if (!new_array)
365 free( array->handles );
366 set_error( STATUS_NO_MEMORY );
367 return 0;
369 array->handles = new_array;
370 array->total = new_total;
372 array->handles[array->count++] = handle;
373 return 1;
376 /* set a window property */
377 static void set_property( struct window *win, atom_t atom, lparam_t data, enum property_type type )
379 int i, free = -1;
380 struct property *new_props;
382 /* check if it exists already */
383 for (i = 0; i < win->prop_inuse; i++)
385 if (win->properties[i].type == PROP_TYPE_FREE)
387 free = i;
388 continue;
390 if (win->properties[i].atom == atom)
392 win->properties[i].type = type;
393 win->properties[i].data = data;
394 return;
398 /* need to add an entry */
399 if (!grab_global_atom( NULL, atom )) return;
400 if (free == -1)
402 /* no free entry */
403 if (win->prop_inuse >= win->prop_alloc)
405 /* need to grow the array */
406 if (!(new_props = realloc( win->properties,
407 sizeof(*new_props) * (win->prop_alloc + 16) )))
409 set_error( STATUS_NO_MEMORY );
410 release_global_atom( NULL, atom );
411 return;
413 win->prop_alloc += 16;
414 win->properties = new_props;
416 free = win->prop_inuse++;
418 win->properties[free].atom = atom;
419 win->properties[free].type = type;
420 win->properties[free].data = data;
423 /* remove a window property */
424 static lparam_t remove_property( struct window *win, atom_t atom )
426 int i;
428 for (i = 0; i < win->prop_inuse; i++)
430 if (win->properties[i].type == PROP_TYPE_FREE) continue;
431 if (win->properties[i].atom == atom)
433 release_global_atom( NULL, atom );
434 win->properties[i].type = PROP_TYPE_FREE;
435 return win->properties[i].data;
438 /* FIXME: last error? */
439 return 0;
442 /* find a window property */
443 static lparam_t get_property( struct window *win, atom_t atom )
445 int i;
447 for (i = 0; i < win->prop_inuse; i++)
449 if (win->properties[i].type == PROP_TYPE_FREE) continue;
450 if (win->properties[i].atom == atom) return win->properties[i].data;
452 /* FIXME: last error? */
453 return 0;
456 /* destroy all properties of a window */
457 static inline void destroy_properties( struct window *win )
459 int i;
461 if (!win->properties) return;
462 for (i = 0; i < win->prop_inuse; i++)
464 if (win->properties[i].type == PROP_TYPE_FREE) continue;
465 release_global_atom( NULL, win->properties[i].atom );
467 free( win->properties );
470 /* detach a window from its owner thread but keep the window around */
471 static void detach_window_thread( struct window *win )
473 struct thread *thread = win->thread;
475 if (!thread) return;
476 if (thread->queue)
478 if (win->update_region) inc_queue_paint_count( thread, -1 );
479 if (win->paint_flags & PAINT_INTERNAL) inc_queue_paint_count( thread, -1 );
480 queue_cleanup_window( thread, win->handle );
482 assert( thread->desktop_users > 0 );
483 thread->desktop_users--;
484 release_class( win->class );
485 win->class = NULL;
487 /* don't hold a reference to the desktop so that the desktop window can be */
488 /* destroyed when the desktop ref count reaches zero */
489 release_object( win->desktop );
490 win->thread = NULL;
493 /* get the process owning the top window of a given desktop */
494 struct process *get_top_window_owner( struct desktop *desktop )
496 struct window *win = desktop->top_window;
497 if (!win || !win->thread) return NULL;
498 return win->thread->process;
501 /* get the top window size of a given desktop */
502 void get_top_window_rectangle( struct desktop *desktop, rectangle_t *rect )
504 struct window *win = desktop->top_window;
505 *rect = win ? win->window_rect : empty_rect;
508 /* post a message to the desktop window */
509 void post_desktop_message( struct desktop *desktop, unsigned int message,
510 lparam_t wparam, lparam_t lparam )
512 struct window *win = desktop->top_window;
513 if (win && win->thread) post_message( win->handle, message, wparam, lparam );
516 /* create a new window structure (note: the window is not linked in the window tree) */
517 static struct window *create_window( struct window *parent, struct window *owner,
518 atom_t atom, mod_handle_t instance )
520 int extra_bytes;
521 struct window *win = NULL;
522 struct desktop *desktop;
523 struct window_class *class;
525 if (!(desktop = get_thread_desktop( current, DESKTOP_CREATEWINDOW ))) return NULL;
527 if (!(class = grab_class( current->process, atom, instance, &extra_bytes )))
529 release_object( desktop );
530 return NULL;
533 if (!parent) /* null parent is only allowed for desktop or HWND_MESSAGE top window */
535 if (is_desktop_class( class ))
536 parent = desktop->top_window; /* use existing desktop if any */
537 else if (is_hwnd_message_class( class ))
538 /* use desktop window if message window is already created */
539 parent = desktop->msg_window ? desktop->top_window : NULL;
540 else if (!(parent = desktop->top_window)) /* must already have a desktop then */
542 set_error( STATUS_ACCESS_DENIED );
543 goto failed;
547 /* parent must be on the same desktop */
548 if (parent && parent->desktop != desktop)
550 set_error( STATUS_ACCESS_DENIED );
551 goto failed;
554 if (!(win = alloc_object( &window_ops ))) goto failed;
555 win->parent = parent ? (struct window *)grab_object( parent ) : NULL;
556 win->owner = owner ? owner->handle : 0;
557 win->thread = current;
558 win->desktop = desktop;
559 win->class = class;
560 win->atom = atom;
561 win->last_active = win->handle;
562 win->win_region = NULL;
563 win->update_region = NULL;
564 win->style = 0;
565 win->ex_style = 0;
566 win->id = 0;
567 win->instance = 0;
568 win->is_unicode = 1;
569 win->is_linked = 0;
570 win->is_layered = 0;
571 win->is_orphan = 0;
572 win->dpi_awareness = DPI_AWARENESS_PER_MONITOR_AWARE;
573 win->dpi = 0;
574 win->user_data = 0;
575 win->text = NULL;
576 win->text_len = 0;
577 win->paint_flags = 0;
578 win->prop_inuse = 0;
579 win->prop_alloc = 0;
580 win->properties = NULL;
581 win->nb_extra_bytes = 0;
582 win->extra_bytes = NULL;
583 win->window_rect = win->visible_rect = win->surface_rect = win->client_rect = empty_rect;
584 list_init( &win->children );
585 list_init( &win->unlinked );
587 if (extra_bytes)
589 if (!(win->extra_bytes = mem_alloc( extra_bytes ))) goto failed;
590 memset( win->extra_bytes, 0, extra_bytes );
591 win->nb_extra_bytes = extra_bytes;
593 if (!(win->handle = alloc_user_handle( win, USER_WINDOW ))) goto failed;
595 /* if parent belongs to a different thread and the window isn't */
596 /* top-level, attach the two threads */
597 if (parent && parent->thread && parent->thread != current && !is_desktop_window(parent))
599 if (!attach_thread_input( current, parent->thread )) goto failed;
601 else /* otherwise just make sure that the thread has a message queue */
603 if (!current->queue && !init_thread_queue( current )) goto failed;
606 /* put it on parent unlinked list */
607 if (parent) list_add_head( &parent->unlinked, &win->entry );
608 else
610 list_init( &win->entry );
611 if (is_desktop_class( class ))
613 assert( !desktop->top_window );
614 desktop->top_window = win;
615 set_process_default_desktop( current->process, desktop, current->desktop );
617 else
619 assert( !desktop->msg_window );
620 desktop->msg_window = win;
624 current->desktop_users++;
625 return win;
627 failed:
628 if (win)
630 if (win->handle)
632 free_user_handle( win->handle );
633 win->handle = 0;
635 release_object( win );
637 release_object( desktop );
638 release_class( class );
639 return NULL;
642 /* destroy all windows belonging to a given thread */
643 void destroy_thread_windows( struct thread *thread )
645 user_handle_t handle = 0;
646 struct window *win;
648 while ((win = next_user_handle( &handle, USER_WINDOW )))
650 if (win->thread != thread) continue;
651 if (is_desktop_window( win )) detach_window_thread( win );
652 else free_window_handle( win );
656 /* get the desktop window */
657 static struct window *get_desktop_window( struct thread *thread )
659 struct window *top_window;
660 struct desktop *desktop = get_thread_desktop( thread, 0 );
662 if (!desktop) return NULL;
663 top_window = desktop->top_window;
664 release_object( desktop );
665 return top_window;
668 /* check whether child is a descendant of parent */
669 int is_child_window( user_handle_t parent, user_handle_t child )
671 struct window *child_ptr = get_user_object( child, USER_WINDOW );
672 struct window *parent_ptr = get_user_object( parent, USER_WINDOW );
674 if (!child_ptr || !parent_ptr) return 0;
675 while (child_ptr->parent)
677 if (child_ptr->parent == parent_ptr) return 1;
678 child_ptr = child_ptr->parent;
680 return 0;
683 /* check if window can be set as foreground window */
684 int is_valid_foreground_window( user_handle_t window )
686 struct window *win = get_user_object( window, USER_WINDOW );
687 return win && (win->style & (WS_POPUP|WS_CHILD)) != WS_CHILD;
690 /* make a window active if possible */
691 int make_window_active( user_handle_t window )
693 struct window *owner, *win = get_window( window );
695 if (!win) return 0;
697 /* set last active for window and its owners */
698 owner = win;
699 while (owner)
701 owner->last_active = win->handle;
702 owner = get_user_object( owner->owner, USER_WINDOW );
704 return 1;
707 /* increment (or decrement) the window paint count */
708 static inline void inc_window_paint_count( struct window *win, int incr )
710 if (win->thread) inc_queue_paint_count( win->thread, incr );
713 /* map a point between different DPI scaling levels */
714 static void map_dpi_point( struct window *win, int *x, int *y, unsigned int from, unsigned int to )
716 if (!from) from = get_monitor_dpi( win );
717 if (!to) to = get_monitor_dpi( win );
718 if (from == to) return;
719 *x = scale_dpi( *x, from, to );
720 *y = scale_dpi( *y, from, to );
723 /* map a window rectangle between different DPI scaling levels */
724 static void map_dpi_rect( struct window *win, rectangle_t *rect, unsigned int from, unsigned int to )
726 if (!from) from = get_monitor_dpi( win );
727 if (!to) to = get_monitor_dpi( win );
728 if (from == to) return;
729 scale_dpi_rect( rect, from, to );
732 /* map a region between different DPI scaling levels */
733 static void map_dpi_region( struct window *win, struct region *region, unsigned int from, unsigned int to )
735 if (!from) from = get_monitor_dpi( win );
736 if (!to) to = get_monitor_dpi( win );
737 if (from == to) return;
738 scale_region( region, from, to );
741 /* convert coordinates from client to screen coords */
742 static inline void client_to_screen( struct window *win, int *x, int *y )
744 for ( ; win && !is_desktop_window(win); win = win->parent)
746 *x += win->client_rect.left;
747 *y += win->client_rect.top;
751 /* convert coordinates from screen to client coords and dpi */
752 static void screen_to_client( struct window *win, int *x, int *y, unsigned int dpi )
754 int offset_x = 0, offset_y = 0;
756 if (is_desktop_window( win )) return;
758 client_to_screen( win, &offset_x, &offset_y );
759 map_dpi_point( win, x, y, dpi, win->dpi );
760 *x -= offset_x;
761 *y -= offset_y;
764 /* check if window and all its ancestors are visible */
765 static int is_visible( const struct window *win )
767 while (win)
769 if (!(win->style & WS_VISIBLE)) return 0;
770 win = win->parent;
771 /* if parent is minimized children are not visible */
772 if (win && (win->style & WS_MINIMIZE)) return 0;
774 return 1;
777 /* same as is_visible but takes a window handle */
778 int is_window_visible( user_handle_t window )
780 struct window *win = get_user_object( window, USER_WINDOW );
781 if (!win) return 0;
782 return is_visible( win );
785 int is_window_transparent( user_handle_t window )
787 struct window *win = get_user_object( window, USER_WINDOW );
788 if (!win) return 0;
789 return (win->ex_style & (WS_EX_LAYERED|WS_EX_TRANSPARENT)) == (WS_EX_LAYERED|WS_EX_TRANSPARENT);
792 /* check if point is inside the window, and map to window dpi */
793 static int is_point_in_window( struct window *win, int *x, int *y, unsigned int dpi )
795 if (!(win->style & WS_VISIBLE)) return 0; /* not visible */
796 if ((win->style & (WS_POPUP|WS_CHILD|WS_DISABLED)) == (WS_CHILD|WS_DISABLED))
797 return 0; /* disabled child */
798 if ((win->ex_style & (WS_EX_LAYERED|WS_EX_TRANSPARENT)) == (WS_EX_LAYERED|WS_EX_TRANSPARENT))
799 return 0; /* transparent */
800 map_dpi_point( win, x, y, dpi, win->dpi );
801 if (!point_in_rect( &win->visible_rect, *x, *y ))
802 return 0; /* not in window */
803 if (win->win_region &&
804 !point_in_region( win->win_region, *x - win->window_rect.left, *y - win->window_rect.top ))
805 return 0; /* not in window region */
806 return 1;
809 /* fill an array with the handles of the children of a specified window */
810 static unsigned int get_children_windows( struct window *parent, atom_t atom, thread_id_t tid,
811 user_handle_t *handles, unsigned int max_count )
813 struct window *ptr;
814 unsigned int count = 0;
816 if (!parent) return 0;
818 LIST_FOR_EACH_ENTRY( ptr, &parent->children, struct window, entry )
820 if (atom && get_class_atom(ptr->class) != atom) continue;
821 if (tid && get_thread_id(ptr->thread) != tid) continue;
822 if (handles)
824 if (count >= max_count) break;
825 handles[count] = ptr->handle;
827 count++;
829 return count;
832 /* find child of 'parent' that contains the given point (in parent-relative coords) */
833 static struct window *child_window_from_point( struct window *parent, int x, int y )
835 struct window *ptr;
837 LIST_FOR_EACH_ENTRY( ptr, &parent->children, struct window, entry )
839 int x_child = x, y_child = y;
841 if (!is_point_in_window( ptr, &x_child, &y_child, parent->dpi )) continue; /* skip it */
843 /* if window is minimized or disabled, return at once */
844 if (ptr->style & (WS_MINIMIZE|WS_DISABLED)) return ptr;
846 /* if point is not in client area, return at once */
847 if (!point_in_rect( &ptr->client_rect, x_child, y_child )) return ptr;
849 return child_window_from_point( ptr, x_child - ptr->client_rect.left,
850 y_child - ptr->client_rect.top );
852 return parent; /* not found any child */
855 /* find all children of 'parent' that contain the given point */
856 static int get_window_children_from_point( struct window *parent, int x, int y,
857 struct user_handle_array *array )
859 struct window *ptr;
861 LIST_FOR_EACH_ENTRY( ptr, &parent->children, struct window, entry )
863 int x_child = x, y_child = y;
865 if (!is_point_in_window( ptr, &x_child, &y_child, parent->dpi )) continue; /* skip it */
867 /* if point is in client area, and window is not minimized or disabled, check children */
868 if (!(ptr->style & (WS_MINIMIZE|WS_DISABLED)) && point_in_rect( &ptr->client_rect, x_child, y_child ))
870 if (!get_window_children_from_point( ptr, x_child - ptr->client_rect.left,
871 y_child - ptr->client_rect.top, array ))
872 return 0;
875 /* now add window to the array */
876 if (!add_handle_to_array( array, ptr->handle )) return 0;
878 return 1;
881 /* get handle of root of top-most window containing point */
882 user_handle_t shallow_window_from_point( struct desktop *desktop, int x, int y )
884 struct window *ptr;
886 if (!desktop->top_window) return 0;
888 LIST_FOR_EACH_ENTRY( ptr, &desktop->top_window->children, struct window, entry )
890 int x_child = x, y_child = y;
892 if (!is_point_in_window( ptr, &x_child, &y_child, 0 )) continue; /* skip it */
893 return ptr->handle;
895 return desktop->top_window->handle;
898 /* return thread of top-most window containing point (in absolute coords) */
899 struct thread *window_thread_from_point( user_handle_t scope, int x, int y )
901 struct window *win = get_user_object( scope, USER_WINDOW );
903 if (!win) return NULL;
905 screen_to_client( win, &x, &y, 0 );
906 win = child_window_from_point( win, x, y );
907 if (!win->thread) return NULL;
908 return (struct thread *)grab_object( win->thread );
911 /* return list of all windows containing point (in absolute coords) */
912 static int all_windows_from_point( struct window *top, int x, int y, unsigned int dpi,
913 struct user_handle_array *array )
915 if (!is_desktop_window( top ) && !is_desktop_window( top->parent ))
917 screen_to_client( top->parent, &x, &y, dpi );
918 dpi = top->parent->dpi;
921 if (!is_point_in_window( top, &x, &y, dpi )) return 1;
922 /* if point is in client area, and window is not minimized or disabled, check children */
923 if (!(top->style & (WS_MINIMIZE|WS_DISABLED)) && point_in_rect( &top->client_rect, x, y ))
925 if (!is_desktop_window(top))
927 x -= top->client_rect.left;
928 y -= top->client_rect.top;
930 if (!get_window_children_from_point( top, x, y, array )) return 0;
932 /* now add window to the array */
933 if (!add_handle_to_array( array, top->handle )) return 0;
934 return 1;
938 /* return the thread owning a window */
939 struct thread *get_window_thread( user_handle_t handle )
941 struct window *win = get_user_object( handle, USER_WINDOW );
942 if (!win || !win->thread) return NULL;
943 return (struct thread *)grab_object( win->thread );
947 /* check if any area of a window needs repainting */
948 static inline int win_needs_repaint( struct window *win )
950 return win->update_region || (win->paint_flags & PAINT_INTERNAL);
954 /* find a child of the specified window that needs repainting */
955 static struct window *find_child_to_repaint( struct window *parent, struct thread *thread )
957 struct window *ptr, *ret = NULL;
959 LIST_FOR_EACH_ENTRY( ptr, &parent->children, struct window, entry )
961 if (!(ptr->style & WS_VISIBLE)) continue;
962 if (ptr->thread == thread && win_needs_repaint( ptr ))
963 ret = ptr;
964 else if (!(ptr->style & WS_MINIMIZE)) /* explore its children */
965 ret = find_child_to_repaint( ptr, thread );
966 if (ret) break;
969 if (ret && (ret->ex_style & WS_EX_TRANSPARENT))
971 /* transparent window, check for non-transparent sibling to paint first */
972 for (ptr = get_next_window(ret); ptr; ptr = get_next_window(ptr))
974 if (!(ptr->style & WS_VISIBLE)) continue;
975 if (ptr->ex_style & WS_EX_TRANSPARENT) continue;
976 if (ptr->thread != thread) continue;
977 if (win_needs_repaint( ptr )) return ptr;
980 return ret;
984 /* find a window that needs to receive a WM_PAINT; also clear its internal paint flag */
985 user_handle_t find_window_to_repaint( user_handle_t parent, struct thread *thread )
987 struct window *ptr, *win, *top_window = get_desktop_window( thread );
989 if (!top_window) return 0;
991 if (top_window->thread == thread && win_needs_repaint( top_window )) win = top_window;
992 else win = find_child_to_repaint( top_window, thread );
994 if (win && parent)
996 /* check that it is a child of the specified parent */
997 for (ptr = win; ptr; ptr = ptr->parent)
998 if (ptr->handle == parent) break;
999 /* otherwise don't return any window, we don't repaint a child before its parent */
1000 if (!ptr) win = NULL;
1002 if (!win) return 0;
1003 win->paint_flags &= ~PAINT_INTERNAL;
1004 return win->handle;
1008 /* intersect the window region with the specified region, relative to the window parent */
1009 static struct region *intersect_window_region( struct region *region, struct window *win )
1011 /* make region relative to window rect */
1012 offset_region( region, -win->window_rect.left, -win->window_rect.top );
1013 if (!intersect_region( region, region, win->win_region )) return NULL;
1014 /* make region relative to parent again */
1015 offset_region( region, win->window_rect.left, win->window_rect.top );
1016 return region;
1020 /* convert coordinates from client to screen coords */
1021 static inline void client_to_screen_rect( struct window *win, rectangle_t *rect )
1023 for ( ; win && !is_desktop_window(win); win = win->parent)
1024 offset_rect( rect, win->client_rect.left, win->client_rect.top );
1027 /* map the region from window to screen coordinates */
1028 static inline void map_win_region_to_screen( struct window *win, struct region *region )
1030 if (!is_desktop_window(win))
1032 int x = win->window_rect.left;
1033 int y = win->window_rect.top;
1034 client_to_screen( win->parent, &x, &y );
1035 offset_region( region, x, y );
1040 /* clip all children of a given window out of the visible region */
1041 static struct region *clip_children( struct window *parent, struct window *last,
1042 struct region *region, int offset_x, int offset_y )
1044 struct window *ptr;
1045 struct region *tmp = create_empty_region();
1047 if (!tmp) return NULL;
1048 LIST_FOR_EACH_ENTRY( ptr, &parent->children, struct window, entry )
1050 if (ptr == last) break;
1051 if (!(ptr->style & WS_VISIBLE)) continue;
1052 if (ptr->ex_style & WS_EX_TRANSPARENT) continue;
1053 set_region_rect( tmp, &ptr->visible_rect );
1054 if (ptr->win_region && !intersect_window_region( tmp, ptr ))
1056 free_region( tmp );
1057 return NULL;
1059 offset_region( tmp, offset_x, offset_y );
1060 if (!(region = subtract_region( region, region, tmp ))) break;
1061 if (is_region_empty( region )) break;
1063 free_region( tmp );
1064 return region;
1068 /* set the region to the client rect clipped by the window rect, in parent-relative coordinates */
1069 static void set_region_client_rect( struct region *region, struct window *win )
1071 rectangle_t rect;
1073 intersect_rect( &rect, &win->window_rect, &win->client_rect );
1074 intersect_rect( &rect, &rect, &win->surface_rect );
1075 set_region_rect( region, &rect );
1079 /* set the region to the visible rect clipped by the window surface, in parent-relative coordinates */
1080 static void set_region_visible_rect( struct region *region, struct window *win )
1082 rectangle_t rect;
1084 intersect_rect( &rect, &win->visible_rect, &win->surface_rect );
1085 set_region_rect( region, &rect );
1089 /* get the top-level window to clip against for a given window */
1090 static inline struct window *get_top_clipping_window( struct window *win )
1092 while (!(win->paint_flags & PAINT_HAS_SURFACE) && win->parent && !is_desktop_window(win->parent))
1093 win = win->parent;
1094 return win;
1098 /* compute the visible region of a window, in window coordinates */
1099 static struct region *get_visible_region( struct window *win, unsigned int flags )
1101 struct region *tmp = NULL, *region;
1102 int offset_x, offset_y;
1104 if (!(region = create_empty_region())) return NULL;
1106 /* first check if all ancestors are visible */
1108 if (!is_visible( win )) return region; /* empty region */
1110 if (is_desktop_window( win ))
1112 set_region_rect( region, &win->window_rect );
1113 return region;
1116 /* create a region relative to the window itself */
1118 if ((flags & DCX_PARENTCLIP) && !is_desktop_window( win->parent ))
1120 set_region_client_rect( region, win->parent );
1121 offset_region( region, -win->parent->client_rect.left, -win->parent->client_rect.top );
1123 else if (flags & DCX_WINDOW)
1125 set_region_visible_rect( region, win );
1126 if (win->win_region && !intersect_window_region( region, win )) goto error;
1128 else
1130 set_region_client_rect( region, win );
1131 if (win->win_region && !intersect_window_region( region, win )) goto error;
1134 /* clip children */
1136 if (flags & DCX_CLIPCHILDREN)
1138 if (!clip_children( win, NULL, region, win->client_rect.left, win->client_rect.top )) goto error;
1141 /* clip siblings of ancestors */
1143 offset_x = win->window_rect.left;
1144 offset_y = win->window_rect.top;
1146 if ((tmp = create_empty_region()) != NULL)
1148 while (!is_desktop_window( win->parent ))
1150 /* we don't clip out top-level siblings as that's up to the native windowing system */
1151 if (win->style & WS_CLIPSIBLINGS)
1153 if (!clip_children( win->parent, win, region, 0, 0 )) goto error;
1154 if (is_region_empty( region )) break;
1156 /* clip to parent client area */
1157 win = win->parent;
1158 offset_x += win->client_rect.left;
1159 offset_y += win->client_rect.top;
1160 offset_region( region, win->client_rect.left, win->client_rect.top );
1161 set_region_client_rect( tmp, win );
1162 if (win->win_region && !intersect_window_region( tmp, win )) goto error;
1163 if (!intersect_region( region, region, tmp )) goto error;
1164 if (is_region_empty( region )) break;
1166 free_region( tmp );
1168 offset_region( region, -offset_x, -offset_y ); /* make it relative to target window */
1169 return region;
1171 error:
1172 if (tmp) free_region( tmp );
1173 free_region( region );
1174 return NULL;
1178 /* clip all children with a custom pixel format out of the visible region */
1179 static struct region *clip_pixel_format_children( struct window *parent, struct region *parent_clip,
1180 struct region *region, int offset_x, int offset_y )
1182 struct window *ptr;
1183 struct region *clip = create_empty_region();
1185 if (!clip) return NULL;
1187 LIST_FOR_EACH_ENTRY_REV( ptr, &parent->children, struct window, entry )
1189 if (!(ptr->style & WS_VISIBLE)) continue;
1190 if (ptr->ex_style & WS_EX_TRANSPARENT) continue;
1192 /* add the visible rect */
1193 set_region_rect( clip, &ptr->visible_rect );
1194 if (ptr->win_region && !intersect_window_region( clip, ptr )) break;
1195 offset_region( clip, offset_x, offset_y );
1196 if (!intersect_region( clip, clip, parent_clip )) break;
1197 if (!union_region( region, region, clip )) break;
1198 if (!(ptr->paint_flags & (PAINT_HAS_PIXEL_FORMAT | PAINT_PIXEL_FORMAT_CHILD))) continue;
1200 /* subtract the client rect if it uses a custom pixel format */
1201 set_region_rect( clip, &ptr->client_rect );
1202 if (ptr->win_region && !intersect_window_region( clip, ptr )) break;
1203 offset_region( clip, offset_x, offset_y );
1204 if (!intersect_region( clip, clip, parent_clip )) break;
1205 if ((ptr->paint_flags & PAINT_HAS_PIXEL_FORMAT) && !subtract_region( region, region, clip ))
1206 break;
1208 if (!clip_pixel_format_children( ptr, clip, region, offset_x + ptr->client_rect.left,
1209 offset_y + ptr->client_rect.top ))
1210 break;
1212 free_region( clip );
1213 return region;
1217 /* compute the visible surface region of a window, in parent coordinates */
1218 static struct region *get_surface_region( struct window *win )
1220 struct region *region, *clip;
1221 int offset_x, offset_y;
1223 /* create a region relative to the window itself */
1225 if (!(region = create_empty_region())) return NULL;
1226 if (!(clip = create_empty_region())) goto error;
1227 set_region_rect( region, &win->visible_rect );
1228 if (win->win_region && !intersect_window_region( region, win )) goto error;
1229 set_region_rect( clip, &win->client_rect );
1230 if (win->win_region && !intersect_window_region( clip, win )) goto error;
1232 if ((win->paint_flags & PAINT_HAS_PIXEL_FORMAT) && !subtract_region( region, region, clip ))
1233 goto error;
1235 /* clip children */
1237 if (!is_desktop_window(win))
1239 offset_x = win->client_rect.left;
1240 offset_y = win->client_rect.top;
1242 else offset_x = offset_y = 0;
1244 if (!clip_pixel_format_children( win, clip, region, offset_x, offset_y )) goto error;
1246 free_region( clip );
1247 return region;
1249 error:
1250 if (clip) free_region( clip );
1251 free_region( region );
1252 return NULL;
1256 /* get the window class of a window */
1257 struct window_class* get_window_class( user_handle_t window )
1259 struct window *win;
1260 if (!(win = get_window( window ))) return NULL;
1261 if (!win->class) set_error( STATUS_ACCESS_DENIED );
1262 return win->class;
1265 /* determine the window visible rectangle, i.e. window or client rect cropped by parent rects */
1266 /* the returned rectangle is in window coordinates; return 0 if rectangle is empty */
1267 static int get_window_visible_rect( struct window *win, rectangle_t *rect, int frame )
1269 int offset_x = win->window_rect.left, offset_y = win->window_rect.top;
1271 *rect = frame ? win->window_rect : win->client_rect;
1273 if (!(win->style & WS_VISIBLE)) return 0;
1274 if (is_desktop_window( win )) return 1;
1276 while (!is_desktop_window( win->parent ))
1278 win = win->parent;
1279 if (!(win->style & WS_VISIBLE) || win->style & WS_MINIMIZE) return 0;
1280 offset_x += win->client_rect.left;
1281 offset_y += win->client_rect.top;
1282 offset_rect( rect, win->client_rect.left, win->client_rect.top );
1283 if (!intersect_rect( rect, rect, &win->client_rect )) return 0;
1284 if (!intersect_rect( rect, rect, &win->window_rect )) return 0;
1286 offset_rect( rect, -offset_x, -offset_y );
1287 return 1;
1290 /* return a copy of the specified region cropped to the window client or frame rectangle, */
1291 /* and converted from client to window coordinates. Helper for (in)validate_window. */
1292 static struct region *crop_region_to_win_rect( struct window *win, struct region *region, int frame )
1294 rectangle_t rect;
1295 struct region *tmp;
1297 if (!get_window_visible_rect( win, &rect, frame )) return NULL;
1298 if (!(tmp = create_empty_region())) return NULL;
1299 set_region_rect( tmp, &rect );
1301 if (region)
1303 /* map it to client coords */
1304 offset_region( tmp, win->window_rect.left - win->client_rect.left,
1305 win->window_rect.top - win->client_rect.top );
1307 /* intersect specified region with bounding rect */
1308 if (!intersect_region( tmp, region, tmp )) goto done;
1309 if (is_region_empty( tmp )) goto done;
1311 /* map it back to window coords */
1312 offset_region( tmp, win->client_rect.left - win->window_rect.left,
1313 win->client_rect.top - win->window_rect.top );
1315 return tmp;
1317 done:
1318 free_region( tmp );
1319 return NULL;
1323 /* set a region as new update region for the window */
1324 static void set_update_region( struct window *win, struct region *region )
1326 if (region && !is_region_empty( region ))
1328 if (!win->update_region) inc_window_paint_count( win, 1 );
1329 else free_region( win->update_region );
1330 win->update_region = region;
1332 else
1334 if (win->update_region)
1336 inc_window_paint_count( win, -1 );
1337 free_region( win->update_region );
1339 win->paint_flags &= ~(PAINT_ERASE | PAINT_DELAYED_ERASE | PAINT_NONCLIENT);
1340 win->update_region = NULL;
1341 if (region) free_region( region );
1346 /* add a region to the update region; the passed region is freed or reused */
1347 static int add_update_region( struct window *win, struct region *region )
1349 if (win->update_region && !union_region( region, win->update_region, region ))
1351 free_region( region );
1352 return 0;
1354 set_update_region( win, region );
1355 return 1;
1359 /* crop the update region of children to the specified rectangle, in client coords */
1360 static void crop_children_update_region( struct window *win, rectangle_t *rect )
1362 struct window *child;
1363 struct region *tmp;
1364 rectangle_t child_rect;
1366 LIST_FOR_EACH_ENTRY( child, &win->children, struct window, entry )
1368 if (!(child->style & WS_VISIBLE)) continue;
1369 if (!rect) /* crop everything out */
1371 crop_children_update_region( child, NULL );
1372 set_update_region( child, NULL );
1373 continue;
1376 /* nothing to do if child is completely inside rect */
1377 if (child->window_rect.left >= rect->left &&
1378 child->window_rect.top >= rect->top &&
1379 child->window_rect.right <= rect->right &&
1380 child->window_rect.bottom <= rect->bottom) continue;
1382 /* map to child client coords and crop grand-children */
1383 child_rect = *rect;
1384 offset_rect( &child_rect, -child->client_rect.left, -child->client_rect.top );
1385 crop_children_update_region( child, &child_rect );
1387 /* now crop the child itself */
1388 if (!child->update_region) continue;
1389 if (!(tmp = create_empty_region())) continue;
1390 set_region_rect( tmp, rect );
1391 offset_region( tmp, -child->window_rect.left, -child->window_rect.top );
1392 if (intersect_region( tmp, child->update_region, tmp )) set_update_region( child, tmp );
1393 else free_region( tmp );
1398 /* validate the non client area of a window */
1399 static void validate_non_client( struct window *win )
1401 struct region *tmp;
1402 rectangle_t rect;
1404 if (!win->update_region) return; /* nothing to do */
1406 /* get client rect in window coords */
1407 rect.left = win->client_rect.left - win->window_rect.left;
1408 rect.top = win->client_rect.top - win->window_rect.top;
1409 rect.right = win->client_rect.right - win->window_rect.left;
1410 rect.bottom = win->client_rect.bottom - win->window_rect.top;
1412 if ((tmp = create_empty_region()))
1414 set_region_rect( tmp, &rect );
1415 if (intersect_region( tmp, win->update_region, tmp ))
1416 set_update_region( win, tmp );
1417 else
1418 free_region( tmp );
1420 win->paint_flags &= ~PAINT_NONCLIENT;
1424 /* validate a window completely so that we don't get any further paint messages for it */
1425 static void validate_whole_window( struct window *win )
1427 set_update_region( win, NULL );
1429 if (win->paint_flags & PAINT_INTERNAL)
1431 win->paint_flags &= ~PAINT_INTERNAL;
1432 inc_window_paint_count( win, -1 );
1437 /* validate a window's children so that we don't get any further paint messages for it */
1438 static void validate_children( struct window *win )
1440 struct window *child;
1442 LIST_FOR_EACH_ENTRY( child, &win->children, struct window, entry )
1444 if (!(child->style & WS_VISIBLE)) continue;
1445 validate_children(child);
1446 validate_whole_window(child);
1451 /* validate the update region of a window on all parents; helper for get_update_region */
1452 static void validate_parents( struct window *child )
1454 int offset_x = 0, offset_y = 0;
1455 struct window *win = child;
1456 struct region *tmp = NULL;
1458 if (!child->update_region) return;
1460 while (win->parent)
1462 /* map to parent client coords */
1463 offset_x += win->window_rect.left;
1464 offset_y += win->window_rect.top;
1466 win = win->parent;
1468 /* and now map to window coords */
1469 offset_x += win->client_rect.left - win->window_rect.left;
1470 offset_y += win->client_rect.top - win->window_rect.top;
1472 if (win->update_region && !(win->style & WS_CLIPCHILDREN))
1474 if (!tmp && !(tmp = create_empty_region())) return;
1475 offset_region( child->update_region, offset_x, offset_y );
1476 if (subtract_region( tmp, win->update_region, child->update_region ))
1478 set_update_region( win, tmp );
1479 tmp = NULL;
1481 /* restore child coords */
1482 offset_region( child->update_region, -offset_x, -offset_y );
1485 if (tmp) free_region( tmp );
1489 /* add/subtract a region (in client coordinates) to the update region of the window */
1490 static void redraw_window( struct window *win, struct region *region, int frame, unsigned int flags )
1492 struct region *child_rgn, *tmp;
1493 struct window *child;
1495 if (flags & RDW_INVALIDATE)
1497 if (!(tmp = crop_region_to_win_rect( win, region, frame ))) return;
1499 if (!add_update_region( win, tmp )) return;
1501 if (flags & RDW_FRAME) win->paint_flags |= PAINT_NONCLIENT;
1502 if (flags & RDW_ERASE) win->paint_flags |= PAINT_ERASE;
1504 else if (flags & RDW_VALIDATE)
1506 if (!region && (flags & RDW_NOFRAME)) /* shortcut: validate everything */
1508 set_update_region( win, NULL );
1510 else if (win->update_region)
1512 if ((tmp = crop_region_to_win_rect( win, region, frame )))
1514 if (!subtract_region( tmp, win->update_region, tmp ))
1516 free_region( tmp );
1517 return;
1519 set_update_region( win, tmp );
1521 if (flags & RDW_NOFRAME) validate_non_client( win );
1522 if (flags & RDW_NOERASE) win->paint_flags &= ~(PAINT_ERASE | PAINT_DELAYED_ERASE);
1526 if ((flags & RDW_INTERNALPAINT) && !(win->paint_flags & PAINT_INTERNAL))
1528 win->paint_flags |= PAINT_INTERNAL;
1529 inc_window_paint_count( win, 1 );
1531 else if ((flags & RDW_NOINTERNALPAINT) && (win->paint_flags & PAINT_INTERNAL))
1533 win->paint_flags &= ~PAINT_INTERNAL;
1534 inc_window_paint_count( win, -1 );
1537 /* now process children recursively */
1539 if (flags & RDW_NOCHILDREN) return;
1540 if (win->style & WS_MINIMIZE) return;
1541 if ((win->style & WS_CLIPCHILDREN) && !(flags & RDW_ALLCHILDREN)) return;
1543 if (!(tmp = crop_region_to_win_rect( win, region, 0 ))) return;
1545 /* map to client coordinates */
1546 offset_region( tmp, win->window_rect.left - win->client_rect.left,
1547 win->window_rect.top - win->client_rect.top );
1549 if (flags & RDW_INVALIDATE) flags |= RDW_FRAME | RDW_ERASE;
1551 LIST_FOR_EACH_ENTRY( child, &win->children, struct window, entry )
1553 if (!(child->style & WS_VISIBLE)) continue;
1554 if (!(child_rgn = create_empty_region())) continue;
1555 if (copy_region( child_rgn, tmp ))
1557 map_dpi_region( child, child_rgn, win->dpi, child->dpi );
1558 if (rect_in_region( child_rgn, &child->window_rect ))
1560 offset_region( child_rgn, -child->client_rect.left, -child->client_rect.top );
1561 redraw_window( child, child_rgn, 1, flags );
1564 free_region( child_rgn );
1567 free_region( tmp );
1571 /* retrieve the update flags for a window depending on the state of the update region */
1572 static unsigned int get_update_flags( struct window *win, unsigned int flags )
1574 unsigned int ret = 0;
1576 if (flags & UPDATE_NONCLIENT)
1578 if ((win->paint_flags & PAINT_NONCLIENT) && win->update_region) ret |= UPDATE_NONCLIENT;
1580 if (flags & UPDATE_ERASE)
1582 if ((win->paint_flags & PAINT_ERASE) && win->update_region) ret |= UPDATE_ERASE;
1584 if (flags & UPDATE_PAINT)
1586 if (win->update_region)
1588 if (win->paint_flags & PAINT_DELAYED_ERASE) ret |= UPDATE_DELAYED_ERASE;
1589 ret |= UPDATE_PAINT;
1592 if (flags & UPDATE_INTERNALPAINT)
1594 if (win->paint_flags & PAINT_INTERNAL)
1596 ret |= UPDATE_INTERNALPAINT;
1597 if (win->paint_flags & PAINT_DELAYED_ERASE) ret |= UPDATE_DELAYED_ERASE;
1600 return ret;
1604 /* iterate through the children of the given window until we find one with some update flags */
1605 static unsigned int get_child_update_flags( struct window *win, struct window *from_child,
1606 unsigned int flags, struct window **child )
1608 struct window *ptr;
1609 unsigned int ret = 0;
1611 /* first make sure we want to iterate children at all */
1613 if (win->style & WS_MINIMIZE) return 0;
1615 /* note: the WS_CLIPCHILDREN test is the opposite of the invalidation case,
1616 * here we only want to repaint children of windows that clip them, others
1617 * need to wait for WM_PAINT to be done in the parent first.
1619 if (!(flags & UPDATE_ALLCHILDREN) && !(win->style & WS_CLIPCHILDREN)) return 0;
1621 LIST_FOR_EACH_ENTRY( ptr, &win->children, struct window, entry )
1623 if (from_child) /* skip all children until from_child is found */
1625 if (ptr == from_child) from_child = NULL;
1626 continue;
1628 if (!(ptr->style & WS_VISIBLE)) continue;
1629 if ((ret = get_update_flags( ptr, flags )) != 0)
1631 *child = ptr;
1632 break;
1634 if ((ret = get_child_update_flags( ptr, NULL, flags, child ))) break;
1636 return ret;
1639 /* iterate through children and siblings of the given window until we find one with some update flags */
1640 static unsigned int get_window_update_flags( struct window *win, struct window *from_child,
1641 unsigned int flags, struct window **child )
1643 unsigned int ret;
1644 struct window *ptr, *from_sibling = NULL;
1646 /* if some parent is not visible start from the next sibling */
1648 if (!is_visible( win )) return 0;
1649 for (ptr = from_child; ptr; ptr = ptr->parent)
1651 if (!(ptr->style & WS_VISIBLE) || (ptr->style & WS_MINIMIZE)) from_sibling = ptr;
1652 if (ptr == win) break;
1655 /* non-client painting must be delayed if one of the parents is going to
1656 * be repainted and doesn't clip children */
1658 if ((flags & UPDATE_NONCLIENT) && !(flags & (UPDATE_PAINT|UPDATE_INTERNALPAINT)))
1660 for (ptr = win->parent; ptr; ptr = ptr->parent)
1662 if (!(ptr->style & WS_CLIPCHILDREN) && win_needs_repaint( ptr ))
1663 return 0;
1665 if (from_child && !(flags & UPDATE_ALLCHILDREN))
1667 for (ptr = from_sibling ? from_sibling : from_child; ptr; ptr = ptr->parent)
1669 if (!(ptr->style & WS_CLIPCHILDREN) && win_needs_repaint( ptr )) from_sibling = ptr;
1670 if (ptr == win) break;
1676 /* check window itself (only if not restarting from a child) */
1678 if (!from_child)
1680 if ((ret = get_update_flags( win, flags )))
1682 *child = win;
1683 return ret;
1685 from_child = win;
1688 /* now check children */
1690 if (flags & UPDATE_NOCHILDREN) return 0;
1691 if (!from_sibling)
1693 if ((ret = get_child_update_flags( from_child, NULL, flags, child ))) return ret;
1694 from_sibling = from_child;
1697 /* then check siblings and parent siblings */
1699 while (from_sibling->parent && from_sibling != win)
1701 if ((ret = get_child_update_flags( from_sibling->parent, from_sibling, flags, child )))
1702 return ret;
1703 from_sibling = from_sibling->parent;
1705 return 0;
1709 /* expose the areas revealed by a vis region change on the window parent */
1710 /* returns the region exposed on the window itself (in client coordinates) */
1711 static struct region *expose_window( struct window *win, const rectangle_t *old_window_rect,
1712 struct region *old_vis_rgn )
1714 struct region *new_vis_rgn, *exposed_rgn;
1716 if (!(new_vis_rgn = get_visible_region( win, DCX_WINDOW ))) return NULL;
1718 if ((exposed_rgn = create_empty_region()))
1720 if (subtract_region( exposed_rgn, new_vis_rgn, old_vis_rgn ) && !is_region_empty( exposed_rgn ))
1722 /* make it relative to the new client area */
1723 offset_region( exposed_rgn, win->window_rect.left - win->client_rect.left,
1724 win->window_rect.top - win->client_rect.top );
1726 else
1728 free_region( exposed_rgn );
1729 exposed_rgn = NULL;
1733 if (win->parent && !is_desktop_window( win->parent ))
1735 /* make it relative to the old window pos for subtracting */
1736 offset_region( new_vis_rgn, win->window_rect.left - old_window_rect->left,
1737 win->window_rect.top - old_window_rect->top );
1739 if ((win->parent->style & WS_CLIPCHILDREN) ?
1740 subtract_region( new_vis_rgn, old_vis_rgn, new_vis_rgn ) :
1741 xor_region( new_vis_rgn, old_vis_rgn, new_vis_rgn ))
1743 if (!is_region_empty( new_vis_rgn ))
1745 /* make it relative to parent */
1746 offset_region( new_vis_rgn, old_window_rect->left, old_window_rect->top );
1747 redraw_window( win->parent, new_vis_rgn, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
1751 free_region( new_vis_rgn );
1752 return exposed_rgn;
1756 /* set the window and client rectangles, updating the update region if necessary */
1757 static void set_window_pos( struct window *win, struct window *previous,
1758 unsigned int swp_flags, const rectangle_t *window_rect,
1759 const rectangle_t *client_rect, const rectangle_t *visible_rect,
1760 const rectangle_t *surface_rect, const rectangle_t *valid_rect )
1762 struct region *old_vis_rgn = NULL, *exposed_rgn = NULL;
1763 const rectangle_t old_window_rect = win->window_rect;
1764 const rectangle_t old_visible_rect = win->visible_rect;
1765 const rectangle_t old_client_rect = win->client_rect;
1766 rectangle_t rect;
1767 int client_changed, frame_changed;
1768 int visible = (win->style & WS_VISIBLE) || (swp_flags & SWP_SHOWWINDOW);
1770 if (win->parent && !is_visible( win->parent )) visible = 0;
1772 if (visible && !(old_vis_rgn = get_visible_region( win, DCX_WINDOW ))) return;
1774 /* set the new window info before invalidating anything */
1776 win->window_rect = *window_rect;
1777 win->visible_rect = *visible_rect;
1778 win->surface_rect = *surface_rect;
1779 win->client_rect = *client_rect;
1780 if (!(swp_flags & SWP_NOZORDER) && win->parent) link_window( win, previous );
1781 if (swp_flags & SWP_SHOWWINDOW) win->style |= WS_VISIBLE;
1782 else if (swp_flags & SWP_HIDEWINDOW) win->style &= ~WS_VISIBLE;
1784 /* keep children at the same position relative to top right corner when the parent is mirrored */
1785 if (win->ex_style & WS_EX_LAYOUTRTL)
1787 struct window *child;
1788 int old_size = old_client_rect.right - old_client_rect.left;
1789 int new_size = win->client_rect.right - win->client_rect.left;
1791 if (old_size != new_size) LIST_FOR_EACH_ENTRY( child, &win->children, struct window, entry )
1793 offset_rect( &child->window_rect, new_size - old_size, 0 );
1794 offset_rect( &child->visible_rect, new_size - old_size, 0 );
1795 offset_rect( &child->surface_rect, new_size - old_size, 0 );
1796 offset_rect( &child->client_rect, new_size - old_size, 0 );
1800 /* reset cursor clip rectangle when the desktop changes size */
1801 if (win == win->desktop->top_window) win->desktop->cursor.clip = *window_rect;
1803 /* if the window is not visible, everything is easy */
1804 if (!visible) return;
1806 /* expose anything revealed by the change */
1808 if (!(swp_flags & SWP_NOREDRAW))
1809 exposed_rgn = expose_window( win, &old_window_rect, old_vis_rgn );
1811 if (!(win->style & WS_VISIBLE))
1813 /* clear the update region since the window is no longer visible */
1814 validate_whole_window( win );
1815 validate_children( win );
1816 goto done;
1819 /* crop update region to the new window rect */
1821 if (win->update_region)
1823 if (get_window_visible_rect( win, &rect, 1 ))
1825 struct region *tmp = create_empty_region();
1826 if (tmp)
1828 set_region_rect( tmp, &rect );
1829 if (intersect_region( tmp, win->update_region, tmp ))
1830 set_update_region( win, tmp );
1831 else
1832 free_region( tmp );
1835 else set_update_region( win, NULL ); /* visible rect is empty */
1838 /* crop children regions to the new window rect */
1840 if (get_window_visible_rect( win, &rect, 0 ))
1842 /* map to client coords */
1843 offset_rect( &rect, win->window_rect.left - win->client_rect.left,
1844 win->window_rect.top - win->client_rect.top );
1845 crop_children_update_region( win, &rect );
1847 else crop_children_update_region( win, NULL );
1849 if (swp_flags & SWP_NOREDRAW) goto done; /* do not repaint anything */
1851 /* expose the whole non-client area if it changed in any way */
1853 if (swp_flags & SWP_NOCOPYBITS)
1855 frame_changed = ((swp_flags & SWP_FRAMECHANGED) ||
1856 memcmp( window_rect, &old_window_rect, sizeof(old_window_rect) ) ||
1857 memcmp( visible_rect, &old_visible_rect, sizeof(old_visible_rect) ));
1858 client_changed = memcmp( client_rect, &old_client_rect, sizeof(old_client_rect) );
1860 else
1862 /* assume the bits have been moved to follow the window rect */
1863 int x_offset = window_rect->left - old_window_rect.left;
1864 int y_offset = window_rect->top - old_window_rect.top;
1865 frame_changed = ((swp_flags & SWP_FRAMECHANGED) ||
1866 window_rect->right - old_window_rect.right != x_offset ||
1867 window_rect->bottom - old_window_rect.bottom != y_offset ||
1868 visible_rect->left - old_visible_rect.left != x_offset ||
1869 visible_rect->right - old_visible_rect.right != x_offset ||
1870 visible_rect->top - old_visible_rect.top != y_offset ||
1871 visible_rect->bottom - old_visible_rect.bottom != y_offset);
1872 client_changed = (client_rect->left - old_client_rect.left != x_offset ||
1873 client_rect->right - old_client_rect.right != x_offset ||
1874 client_rect->top - old_client_rect.top != y_offset ||
1875 client_rect->bottom - old_client_rect.bottom != y_offset ||
1876 memcmp( valid_rect, client_rect, sizeof(*client_rect) ));
1879 if (frame_changed || client_changed)
1881 struct region *win_rgn = old_vis_rgn; /* reuse previous region */
1883 set_region_rect( win_rgn, window_rect );
1884 if (!is_rect_empty( valid_rect ))
1886 /* subtract the valid portion of client rect from the total region */
1887 struct region *tmp = create_empty_region();
1888 if (tmp)
1890 set_region_rect( tmp, valid_rect );
1891 /* subtract update region since invalid parts of the valid rect won't be copied */
1892 if (win->update_region)
1894 offset_region( tmp, -window_rect->left, -window_rect->top );
1895 subtract_region( tmp, tmp, win->update_region );
1896 offset_region( tmp, window_rect->left, window_rect->top );
1898 if (subtract_region( tmp, win_rgn, tmp )) win_rgn = tmp;
1899 else free_region( tmp );
1902 if (!is_desktop_window(win))
1903 offset_region( win_rgn, -client_rect->left, -client_rect->top );
1904 if (exposed_rgn)
1906 union_region( exposed_rgn, exposed_rgn, win_rgn );
1907 if (win_rgn != old_vis_rgn) free_region( win_rgn );
1909 else
1911 exposed_rgn = win_rgn;
1912 if (win_rgn == old_vis_rgn) old_vis_rgn = NULL;
1916 if (exposed_rgn)
1917 redraw_window( win, exposed_rgn, 1, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
1919 done:
1920 if (old_vis_rgn) free_region( old_vis_rgn );
1921 if (exposed_rgn) free_region( exposed_rgn );
1922 clear_error(); /* we ignore out of memory errors once the new rects have been set */
1926 /* set the window region, updating the update region if necessary */
1927 static void set_window_region( struct window *win, struct region *region, int redraw )
1929 struct region *old_vis_rgn = NULL, *exposed_rgn;
1931 /* no need to redraw if window is not visible */
1932 if (redraw && !is_visible( win )) redraw = 0;
1934 if (redraw) old_vis_rgn = get_visible_region( win, DCX_WINDOW );
1936 if (win->win_region) free_region( win->win_region );
1937 win->win_region = region;
1939 /* expose anything revealed by the change */
1940 if (old_vis_rgn && ((exposed_rgn = expose_window( win, &win->window_rect, old_vis_rgn ))))
1942 redraw_window( win, exposed_rgn, 1, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
1943 free_region( exposed_rgn );
1946 if (old_vis_rgn) free_region( old_vis_rgn );
1947 clear_error(); /* we ignore out of memory errors since the region has been set */
1951 /* destroy a window */
1952 void free_window_handle( struct window *win )
1954 struct window *child, *next;
1956 assert( win->handle );
1958 /* hide the window */
1959 if (is_visible(win))
1961 struct region *vis_rgn = get_visible_region( win, DCX_WINDOW );
1962 win->style &= ~WS_VISIBLE;
1963 if (vis_rgn)
1965 struct region *exposed_rgn = expose_window( win, &win->window_rect, vis_rgn );
1966 if (exposed_rgn) free_region( exposed_rgn );
1967 free_region( vis_rgn );
1969 validate_whole_window( win );
1970 validate_children( win );
1973 /* destroy all children */
1974 LIST_FOR_EACH_ENTRY_SAFE( child, next, &win->children, struct window, entry )
1976 if (!child->handle) continue;
1977 if (!win->thread || !child->thread || win->thread == child->thread)
1978 free_window_handle( child );
1979 else
1980 send_notify_message( child->handle, WM_WINE_DESTROYWINDOW, 0, 0 );
1982 LIST_FOR_EACH_ENTRY_SAFE( child, next, &win->children, struct window, entry )
1984 if (!child->handle) continue;
1985 if (!win->thread || !child->thread || win->thread == child->thread)
1986 free_window_handle( child );
1987 else
1988 send_notify_message( child->handle, WM_WINE_DESTROYWINDOW, 0, 0 );
1991 /* reset global window pointers, if the corresponding window is destroyed */
1992 if (win == shell_window) shell_window = NULL;
1993 if (win == shell_listview) shell_listview = NULL;
1994 if (win == progman_window) progman_window = NULL;
1995 if (win == taskman_window) taskman_window = NULL;
1996 free_hotkeys( win->desktop, win->handle );
1997 cleanup_clipboard_window( win->desktop, win->handle );
1998 destroy_properties( win );
1999 if (is_desktop_window(win))
2001 struct desktop *desktop = win->desktop;
2002 assert( desktop->top_window == win || desktop->msg_window == win );
2003 if (desktop->top_window == win) desktop->top_window = NULL;
2004 else desktop->msg_window = NULL;
2006 else if (is_desktop_window( win->parent ))
2008 post_message( win->parent->handle, WM_PARENTNOTIFY, WM_DESTROY, win->handle );
2011 detach_window_thread( win );
2013 if (win->parent) set_parent_window( win, NULL );
2014 free_user_handle( win->handle );
2015 win->handle = 0;
2016 release_object( win );
2020 /* create a window */
2021 DECL_HANDLER(create_window)
2023 struct window *win, *parent = NULL, *owner = NULL;
2024 struct unicode_str cls_name = get_req_unicode_str();
2025 atom_t atom;
2027 reply->handle = 0;
2028 if (req->parent)
2030 if (!(parent = get_window( req->parent ))) return;
2031 if (is_orphan_window( parent ))
2033 set_error( STATUS_INVALID_PARAMETER );
2034 return;
2038 if (req->owner)
2040 if (!(owner = get_window( req->owner ))) return;
2041 if (is_desktop_window(owner)) owner = NULL;
2042 else if (parent && !is_desktop_window(parent))
2044 /* an owned window must be created as top-level */
2045 set_error( STATUS_ACCESS_DENIED );
2046 return;
2048 else /* owner must be a top-level window */
2049 while ((owner->style & (WS_POPUP|WS_CHILD)) == WS_CHILD && !is_desktop_window(owner->parent))
2050 owner = owner->parent;
2053 atom = cls_name.len ? find_global_atom( NULL, &cls_name ) : req->atom;
2055 if (!(win = create_window( parent, owner, atom, req->instance ))) return;
2057 if (parent && !is_desktop_window( parent ))
2059 win->dpi_awareness = parent->dpi_awareness;
2060 win->dpi = parent->dpi;
2062 else if (!parent || req->awareness != DPI_AWARENESS_PER_MONITOR_AWARE)
2064 win->dpi_awareness = req->awareness;
2065 win->dpi = req->dpi;
2067 win->style = req->style;
2068 win->ex_style = req->ex_style;
2070 reply->handle = win->handle;
2071 reply->parent = win->parent ? win->parent->handle : 0;
2072 reply->owner = win->owner;
2073 reply->extra = win->nb_extra_bytes;
2074 reply->dpi = win->dpi;
2075 reply->awareness = win->dpi_awareness;
2076 reply->class_ptr = get_class_client_ptr( win->class );
2080 /* set the parent of a window */
2081 DECL_HANDLER(set_parent)
2083 struct window *win, *parent = NULL;
2085 if (!(win = get_window( req->handle ))) return;
2086 if (req->parent && !(parent = get_window( req->parent ))) return;
2088 if (is_desktop_window(win) || is_orphan_window( win ) || (parent && is_orphan_window( parent )))
2090 set_error( STATUS_INVALID_PARAMETER );
2091 return;
2093 reply->old_parent = win->parent->handle;
2094 reply->full_parent = parent ? parent->handle : 0;
2095 set_parent_window( win, parent );
2096 reply->dpi = win->dpi;
2097 reply->awareness = win->dpi_awareness;
2101 /* destroy a window */
2102 DECL_HANDLER(destroy_window)
2104 struct window *win;
2106 if (!req->handle)
2108 destroy_thread_windows( current );
2110 else if ((win = get_window( req->handle )))
2112 if (!is_desktop_window(win)) free_window_handle( win );
2113 else if (win->thread == current) detach_window_thread( win );
2114 else set_error( STATUS_ACCESS_DENIED );
2119 /* retrieve the desktop window for the current thread */
2120 DECL_HANDLER(get_desktop_window)
2122 struct desktop *desktop = get_thread_desktop( current, 0 );
2123 int force;
2125 if (!desktop) return;
2127 /* if winstation is invisible, then avoid roundtrip */
2128 force = req->force || !(desktop->winstation->flags & WSF_VISIBLE);
2130 if (!desktop->top_window && force) /* create it */
2132 if ((desktop->top_window = create_window( NULL, NULL, DESKTOP_ATOM, 0 )))
2134 detach_window_thread( desktop->top_window );
2135 desktop->top_window->style = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
2139 if (!desktop->msg_window && force) /* create it */
2141 static const WCHAR messageW[] = {'M','e','s','s','a','g','e'};
2142 static const struct unicode_str name = { messageW, sizeof(messageW) };
2143 atom_t atom = add_global_atom( NULL, &name );
2144 if (atom && (desktop->msg_window = create_window( NULL, NULL, atom, 0 )))
2146 detach_window_thread( desktop->msg_window );
2147 desktop->msg_window->style = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
2151 reply->top_window = desktop->top_window ? desktop->top_window->handle : 0;
2152 reply->msg_window = desktop->msg_window ? desktop->msg_window->handle : 0;
2153 release_object( desktop );
2157 /* set a window owner */
2158 DECL_HANDLER(set_window_owner)
2160 struct window *win = get_window( req->handle );
2161 struct window *owner = NULL, *ptr;
2163 if (!win) return;
2164 if (req->owner && !(owner = get_window( req->owner ))) return;
2165 if (is_desktop_window(win))
2167 set_error( STATUS_ACCESS_DENIED );
2168 return;
2171 /* make sure owner is not a successor of window */
2172 for (ptr = owner; ptr; ptr = ptr->owner ? get_window( ptr->owner ) : NULL)
2174 if (ptr == win)
2176 set_error( STATUS_INVALID_PARAMETER );
2177 return;
2181 reply->prev_owner = win->owner;
2182 reply->full_owner = win->owner = owner ? owner->handle : 0;
2186 /* get information from a window handle */
2187 DECL_HANDLER(get_window_info)
2189 struct window *win = get_window( req->handle );
2191 if (!win) return;
2193 reply->full_handle = win->handle;
2194 reply->last_active = win->handle;
2195 reply->is_unicode = win->is_unicode;
2196 reply->awareness = win->dpi_awareness;
2197 reply->dpi = win->dpi ? win->dpi : get_monitor_dpi( win );
2198 if (get_user_object( win->last_active, USER_WINDOW )) reply->last_active = win->last_active;
2199 if (win->thread)
2201 reply->tid = get_thread_id( win->thread );
2202 reply->pid = get_process_id( win->thread->process );
2203 reply->atom = win->class ? get_class_atom( win->class ) : DESKTOP_ATOM;
2208 /* set some information in a window */
2209 DECL_HANDLER(set_window_info)
2211 struct window *win = get_window( req->handle );
2213 if (!win) return;
2214 if (req->flags && is_desktop_window(win) && win->thread != current)
2216 set_error( STATUS_ACCESS_DENIED );
2217 return;
2219 if (req->extra_size > sizeof(req->extra_value) ||
2220 req->extra_offset < -1 ||
2221 req->extra_offset > win->nb_extra_bytes - (int)req->extra_size)
2223 set_win32_error( ERROR_INVALID_INDEX );
2224 return;
2226 if (req->extra_offset != -1)
2228 memcpy( &reply->old_extra_value, win->extra_bytes + req->extra_offset, req->extra_size );
2230 else if (req->flags & SET_WIN_EXTRA)
2232 set_win32_error( ERROR_INVALID_INDEX );
2233 return;
2235 reply->old_style = win->style;
2236 reply->old_ex_style = win->ex_style;
2237 reply->old_id = win->id;
2238 reply->old_instance = win->instance;
2239 reply->old_user_data = win->user_data;
2240 if (req->flags & SET_WIN_STYLE) win->style = req->style;
2241 if (req->flags & SET_WIN_EXSTYLE)
2243 /* WS_EX_TOPMOST can only be changed for unlinked windows */
2244 if (!win->is_linked) win->ex_style = req->ex_style;
2245 else win->ex_style = (req->ex_style & ~WS_EX_TOPMOST) | (win->ex_style & WS_EX_TOPMOST);
2246 if (!(win->ex_style & WS_EX_LAYERED)) win->is_layered = 0;
2248 if (req->flags & SET_WIN_ID) win->id = req->extra_value;
2249 if (req->flags & SET_WIN_INSTANCE) win->instance = req->instance;
2250 if (req->flags & SET_WIN_UNICODE) win->is_unicode = req->is_unicode;
2251 if (req->flags & SET_WIN_USERDATA) win->user_data = req->user_data;
2252 if (req->flags & SET_WIN_EXTRA) memcpy( win->extra_bytes + req->extra_offset,
2253 &req->extra_value, req->extra_size );
2255 /* changing window style triggers a non-client paint */
2256 if (req->flags & SET_WIN_STYLE) win->paint_flags |= PAINT_NONCLIENT;
2260 /* get a list of the window parents, up to the root of the tree */
2261 DECL_HANDLER(get_window_parents)
2263 struct window *ptr, *win = get_window( req->handle );
2264 int total = 0;
2265 user_handle_t *data;
2266 data_size_t len;
2268 if (win) for (ptr = win->parent; ptr; ptr = ptr->parent) total++;
2270 reply->count = total;
2271 len = min( get_reply_max_size(), total * sizeof(user_handle_t) );
2272 if (len && ((data = set_reply_data_size( len ))))
2274 for (ptr = win->parent; ptr && len; ptr = ptr->parent, len -= sizeof(*data))
2275 *data++ = ptr->handle;
2280 /* get a list of the window children */
2281 DECL_HANDLER(get_window_children)
2283 struct window *parent = NULL;
2284 unsigned int total;
2285 user_handle_t *data;
2286 data_size_t len;
2287 struct unicode_str cls_name = get_req_unicode_str();
2288 atom_t atom = req->atom;
2289 struct desktop *desktop = NULL;
2291 if (cls_name.len && !(atom = find_global_atom( NULL, &cls_name ))) return;
2293 if (req->desktop)
2295 if (!(desktop = get_desktop_obj( current->process, req->desktop, DESKTOP_ENUMERATE ))) return;
2296 parent = desktop->top_window;
2298 else
2300 if (req->parent && !(parent = get_window( req->parent ))) return;
2301 if (!parent && !(desktop = get_thread_desktop( current, 0 ))) return;
2304 if (parent)
2305 total = get_children_windows( parent, atom, req->tid, NULL, 0 );
2306 else
2307 total = get_children_windows( desktop->top_window, atom, req->tid, NULL, 0 ) +
2308 get_children_windows( desktop->msg_window, atom, req->tid, NULL, 0 );
2310 reply->count = total;
2311 len = min( get_reply_max_size(), total * sizeof(user_handle_t) );
2312 if (len && ((data = set_reply_data_size( len ))))
2314 if (parent) get_children_windows( parent, atom, req->tid, data, len / sizeof(user_handle_t) );
2315 else
2317 total = get_children_windows( desktop->top_window, atom, req->tid,
2318 data, len / sizeof(user_handle_t) );
2319 data += total;
2320 len -= total * sizeof(user_handle_t);
2321 if (len >= sizeof(user_handle_t))
2322 get_children_windows( desktop->msg_window, atom, req->tid,
2323 data, len / sizeof(user_handle_t) );
2326 if (desktop) release_object( desktop );
2330 /* get a list of the window children that contain a given point */
2331 DECL_HANDLER(get_window_children_from_point)
2333 struct user_handle_array array;
2334 struct window *parent = get_window( req->parent );
2335 data_size_t len;
2337 if (!parent) return;
2339 array.handles = NULL;
2340 array.count = 0;
2341 array.total = 0;
2342 if (!all_windows_from_point( parent, req->x, req->y, req->dpi, &array )) return;
2344 reply->count = array.count;
2345 len = min( get_reply_max_size(), array.count * sizeof(user_handle_t) );
2346 if (len) set_reply_data_ptr( array.handles, len );
2347 else free( array.handles );
2351 /* get window tree information from a window handle */
2352 DECL_HANDLER(get_window_tree)
2354 struct window *ptr, *win = get_window( req->handle );
2356 if (!win) return;
2358 reply->parent = 0;
2359 reply->owner = 0;
2360 reply->next_sibling = 0;
2361 reply->prev_sibling = 0;
2362 reply->first_sibling = 0;
2363 reply->last_sibling = 0;
2364 reply->first_child = 0;
2365 reply->last_child = 0;
2367 if (win->parent)
2369 struct window *parent = win->parent;
2370 reply->parent = parent->handle;
2371 reply->owner = win->owner;
2372 if (win->is_linked)
2374 if ((ptr = get_next_window( win ))) reply->next_sibling = ptr->handle;
2375 if ((ptr = get_prev_window( win ))) reply->prev_sibling = ptr->handle;
2377 if ((ptr = get_first_child( parent ))) reply->first_sibling = ptr->handle;
2378 if ((ptr = get_last_child( parent ))) reply->last_sibling = ptr->handle;
2380 if ((ptr = get_first_child( win ))) reply->first_child = ptr->handle;
2381 if ((ptr = get_last_child( win ))) reply->last_child = ptr->handle;
2385 /* set the position and Z order of a window */
2386 DECL_HANDLER(set_window_pos)
2388 rectangle_t window_rect, client_rect, visible_rect, surface_rect, valid_rect;
2389 const rectangle_t *extra_rects = get_req_data();
2390 struct window *previous = NULL;
2391 struct window *top, *win = get_window( req->handle );
2392 unsigned int flags = req->swp_flags;
2394 if (!win) return;
2395 if (!win->parent) flags |= SWP_NOZORDER; /* no Z order for the desktop */
2397 if (!(flags & SWP_NOZORDER))
2399 switch ((int)req->previous)
2401 case 0: /* HWND_TOP */
2402 previous = WINPTR_TOP;
2403 break;
2404 case 1: /* HWND_BOTTOM */
2405 previous = WINPTR_BOTTOM;
2406 break;
2407 case -1: /* HWND_TOPMOST */
2408 previous = WINPTR_TOPMOST;
2409 break;
2410 case -2: /* HWND_NOTOPMOST */
2411 previous = WINPTR_NOTOPMOST;
2412 break;
2413 default:
2414 if (!(previous = get_window( req->previous ))) return;
2415 /* previous must be a sibling */
2416 if (previous->parent != win->parent)
2418 set_error( STATUS_INVALID_PARAMETER );
2419 return;
2421 break;
2423 if (previous == win) flags |= SWP_NOZORDER; /* nothing to do */
2426 /* windows that use UpdateLayeredWindow don't trigger repaints */
2427 if ((win->ex_style & WS_EX_LAYERED) && !win->is_layered) flags |= SWP_NOREDRAW;
2429 /* window rectangle must be ordered properly */
2430 if (req->window.right < req->window.left || req->window.bottom < req->window.top)
2432 set_error( STATUS_INVALID_PARAMETER );
2433 return;
2436 window_rect = req->window;
2437 client_rect = req->client;
2438 if (get_req_data_size() >= sizeof(rectangle_t)) visible_rect = extra_rects[0];
2439 else visible_rect = window_rect;
2440 if (get_req_data_size() >= 2 * sizeof(rectangle_t)) surface_rect = extra_rects[1];
2441 else surface_rect = visible_rect;
2442 if (get_req_data_size() >= 3 * sizeof(rectangle_t)) valid_rect = extra_rects[2];
2443 else valid_rect = empty_rect;
2444 if (win->parent && win->parent->ex_style & WS_EX_LAYOUTRTL)
2446 mirror_rect( &win->parent->client_rect, &window_rect );
2447 mirror_rect( &win->parent->client_rect, &visible_rect );
2448 mirror_rect( &win->parent->client_rect, &client_rect );
2449 mirror_rect( &win->parent->client_rect, &surface_rect );
2450 mirror_rect( &win->parent->client_rect, &valid_rect );
2453 win->paint_flags = (win->paint_flags & ~PAINT_CLIENT_FLAGS) | (req->paint_flags & PAINT_CLIENT_FLAGS);
2454 if (win->paint_flags & PAINT_HAS_PIXEL_FORMAT) update_pixel_format_flags( win );
2456 set_window_pos( win, previous, flags, &window_rect, &client_rect,
2457 &visible_rect, &surface_rect, &valid_rect );
2459 reply->new_style = win->style;
2460 reply->new_ex_style = win->ex_style;
2462 top = get_top_clipping_window( win );
2463 if (is_visible( top ) && (top->paint_flags & PAINT_HAS_SURFACE))
2465 reply->surface_win = top->handle;
2466 reply->needs_update = !!(top->paint_flags & (PAINT_HAS_PIXEL_FORMAT | PAINT_PIXEL_FORMAT_CHILD));
2471 /* get the window and client rectangles of a window */
2472 DECL_HANDLER(get_window_rectangles)
2474 struct window *win = get_window( req->handle );
2476 if (!win) return;
2478 reply->window = win->window_rect;
2479 reply->client = win->client_rect;
2481 switch (req->relative)
2483 case COORDS_CLIENT:
2484 offset_rect( &reply->window, -win->client_rect.left, -win->client_rect.top );
2485 offset_rect( &reply->client, -win->client_rect.left, -win->client_rect.top );
2486 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_rect( &win->client_rect, &reply->window );
2487 break;
2488 case COORDS_WINDOW:
2489 offset_rect( &reply->window, -win->window_rect.left, -win->window_rect.top );
2490 offset_rect( &reply->client, -win->window_rect.left, -win->window_rect.top );
2491 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_rect( &win->window_rect, &reply->client );
2492 break;
2493 case COORDS_PARENT:
2494 if (win->parent && win->parent->ex_style & WS_EX_LAYOUTRTL)
2496 mirror_rect( &win->parent->client_rect, &reply->window );
2497 mirror_rect( &win->parent->client_rect, &reply->client );
2499 break;
2500 case COORDS_SCREEN:
2501 client_to_screen_rect( win->parent, &reply->window );
2502 client_to_screen_rect( win->parent, &reply->client );
2503 break;
2504 default:
2505 set_error( STATUS_INVALID_PARAMETER );
2506 break;
2508 map_dpi_rect( win, &reply->window, win->dpi, req->dpi );
2509 map_dpi_rect( win, &reply->client, win->dpi, req->dpi );
2513 /* get the window text */
2514 DECL_HANDLER(get_window_text)
2516 struct window *win = get_window( req->handle );
2518 if (win && win->text_len)
2520 reply->length = win->text_len / sizeof(WCHAR);
2521 set_reply_data( win->text, min( win->text_len, get_reply_max_size() ));
2526 /* set the window text */
2527 DECL_HANDLER(set_window_text)
2529 data_size_t len;
2530 WCHAR *text = NULL;
2531 struct window *win = get_window( req->handle );
2533 if (!win) return;
2534 len = (get_req_data_size() / sizeof(WCHAR)) * sizeof(WCHAR);
2535 if (len && !(text = memdup( get_req_data(), len ))) return;
2536 free( win->text );
2537 win->text = text;
2538 win->text_len = len;
2542 /* get the coordinates offset between two windows */
2543 DECL_HANDLER(get_windows_offset)
2545 struct window *win;
2546 int x, y, mirror_from = 0, mirror_to = 0;
2548 reply->x = reply->y = 0;
2549 if (req->from)
2551 if (!(win = get_window( req->from ))) return;
2552 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_from = 1;
2553 x = mirror_from ? win->client_rect.right - win->client_rect.left : 0;
2554 y = 0;
2555 client_to_screen( win, &x, &y );
2556 map_dpi_point( win, &x, &y, win->dpi, req->dpi );
2557 reply->x += x;
2558 reply->y += y;
2560 if (req->to)
2562 if (!(win = get_window( req->to ))) return;
2563 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_to = 1;
2564 x = mirror_to ? win->client_rect.right - win->client_rect.left : 0;
2565 y = 0;
2566 client_to_screen( win, &x, &y );
2567 map_dpi_point( win, &x, &y, win->dpi, req->dpi );
2568 reply->x -= x;
2569 reply->y -= y;
2571 if (mirror_from) reply->x = -reply->x;
2572 reply->mirror = mirror_from ^ mirror_to;
2576 /* get the visible region of a window */
2577 DECL_HANDLER(get_visible_region)
2579 struct region *region;
2580 struct window *top, *win = get_window( req->window );
2582 if (!win) return;
2584 top = get_top_clipping_window( win );
2585 if ((region = get_visible_region( win, req->flags )))
2587 rectangle_t *data;
2588 map_win_region_to_screen( win, region );
2589 data = get_region_data_and_free( region, get_reply_max_size(), &reply->total_size );
2590 if (data) set_reply_data_ptr( data, reply->total_size );
2592 reply->top_win = top->handle;
2593 reply->top_rect = top->surface_rect;
2595 if (!is_desktop_window(win))
2597 reply->win_rect = (req->flags & DCX_WINDOW) ? win->window_rect : win->client_rect;
2598 client_to_screen_rect( top->parent, &reply->top_rect );
2599 client_to_screen_rect( win->parent, &reply->win_rect );
2601 else
2603 reply->win_rect.left = 0;
2604 reply->win_rect.top = 0;
2605 reply->win_rect.right = win->client_rect.right - win->client_rect.left;
2606 reply->win_rect.bottom = win->client_rect.bottom - win->client_rect.top;
2608 reply->paint_flags = win->paint_flags & PAINT_CLIENT_FLAGS;
2612 /* get the surface visible region of a window */
2613 DECL_HANDLER(get_surface_region)
2615 struct region *region;
2616 struct window *win = get_window( req->window );
2618 if (!win || !is_visible( win )) return;
2620 if ((region = get_surface_region( win )))
2622 rectangle_t *data = get_region_data_and_free( region, get_reply_max_size(), &reply->total_size );
2623 if (data) set_reply_data_ptr( data, reply->total_size );
2625 reply->visible_rect = win->visible_rect;
2629 /* get the window region */
2630 DECL_HANDLER(get_window_region)
2632 rectangle_t *data;
2633 struct window *win = get_window( req->window );
2635 if (!win) return;
2636 if (!win->win_region) return;
2638 if (win->ex_style & WS_EX_LAYOUTRTL)
2640 struct region *region = create_empty_region();
2642 if (!region) return;
2643 if (!copy_region( region, win->win_region ))
2645 free_region( region );
2646 return;
2648 mirror_region( &win->window_rect, region );
2649 data = get_region_data_and_free( region, get_reply_max_size(), &reply->total_size );
2651 else data = get_region_data( win->win_region, get_reply_max_size(), &reply->total_size );
2653 if (data) set_reply_data_ptr( data, reply->total_size );
2657 /* set the window region */
2658 DECL_HANDLER(set_window_region)
2660 struct region *region = NULL;
2661 struct window *win = get_window( req->window );
2663 if (!win) return;
2665 if (get_req_data_size()) /* no data means remove the region completely */
2667 if (!(region = create_region_from_req_data( get_req_data(), get_req_data_size() )))
2668 return;
2669 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_region( &win->window_rect, region );
2671 set_window_region( win, region, req->redraw );
2675 /* get a window update region */
2676 DECL_HANDLER(get_update_region)
2678 rectangle_t *data;
2679 unsigned int flags = req->flags;
2680 struct window *from_child = NULL;
2681 struct window *win = get_window( req->window );
2683 reply->flags = 0;
2684 if (!win) return;
2686 if (req->from_child)
2688 struct window *ptr;
2690 if (!(from_child = get_window( req->from_child ))) return;
2692 /* make sure from_child is a child of win */
2693 ptr = from_child;
2694 while (ptr && ptr != win) ptr = ptr->parent;
2695 if (!ptr)
2697 set_error( STATUS_INVALID_PARAMETER );
2698 return;
2702 if (flags & UPDATE_DELAYED_ERASE) /* this means that the previous call didn't erase */
2704 if (from_child) from_child->paint_flags |= PAINT_DELAYED_ERASE;
2705 else win->paint_flags |= PAINT_DELAYED_ERASE;
2708 reply->flags = get_window_update_flags( win, from_child, flags, &win );
2709 reply->child = win->handle;
2711 if (flags & UPDATE_NOREGION) return;
2713 if (win->update_region)
2715 /* convert update region to screen coordinates */
2716 struct region *region = create_empty_region();
2718 if (!region) return;
2719 if (!copy_region( region, win->update_region ))
2721 free_region( region );
2722 return;
2724 if ((flags & UPDATE_CLIPCHILDREN) && (win->style & WS_CLIPCHILDREN))
2725 clip_children( win, NULL, region, win->client_rect.left - win->window_rect.left,
2726 win->client_rect.top - win->window_rect.top );
2727 map_win_region_to_screen( win, region );
2728 if (!(data = get_region_data_and_free( region, get_reply_max_size(),
2729 &reply->total_size ))) return;
2730 set_reply_data_ptr( data, reply->total_size );
2733 if (reply->flags & (UPDATE_PAINT|UPDATE_INTERNALPAINT)) /* validate everything */
2735 validate_parents( win );
2736 validate_whole_window( win );
2738 else
2740 if (reply->flags & UPDATE_NONCLIENT) validate_non_client( win );
2741 if (reply->flags & UPDATE_ERASE)
2743 win->paint_flags &= ~(PAINT_ERASE | PAINT_DELAYED_ERASE);
2744 /* desktop window only gets erased, not repainted */
2745 if (is_desktop_window(win)) validate_whole_window( win );
2751 /* update the z order of a window so that a given rectangle is fully visible */
2752 DECL_HANDLER(update_window_zorder)
2754 rectangle_t tmp, rect = req->rect;
2755 struct window *ptr, *win = get_window( req->window );
2757 if (!win || !win->parent || !is_visible( win )) return; /* nothing to do */
2759 LIST_FOR_EACH_ENTRY( ptr, &win->parent->children, struct window, entry )
2761 if (ptr == win) break;
2762 if (!(ptr->style & WS_VISIBLE)) continue;
2763 if (ptr->ex_style & WS_EX_TRANSPARENT) continue;
2764 if (ptr->is_layered && (ptr->layered_flags & LWA_COLORKEY)) continue;
2765 tmp = rect;
2766 map_dpi_rect( win, &tmp, win->parent->dpi, win->dpi );
2767 if (!intersect_rect( &tmp, &tmp, &ptr->visible_rect )) continue;
2768 if (ptr->win_region)
2770 offset_rect( &tmp, -ptr->window_rect.left, -ptr->window_rect.top );
2771 if (!rect_in_region( ptr->win_region, &tmp )) continue;
2773 /* found a window obscuring the rectangle, now move win above this one */
2774 /* making sure to not violate the topmost rule */
2775 if (!(ptr->ex_style & WS_EX_TOPMOST) || (win->ex_style & WS_EX_TOPMOST))
2777 list_remove( &win->entry );
2778 list_add_before( &ptr->entry, &win->entry );
2780 break;
2785 /* mark parts of a window as needing a redraw */
2786 DECL_HANDLER(redraw_window)
2788 unsigned int flags = req->flags;
2789 struct region *region = NULL;
2790 struct window *win;
2792 if (!req->window)
2794 if (!(win = get_desktop_window( current ))) return;
2796 else
2798 if (!(win = get_window( req->window ))) return;
2799 if (is_desktop_window( win )) flags &= ~RDW_ALLCHILDREN;
2802 if (!is_visible( win )) return; /* nothing to do */
2804 if (flags & (RDW_VALIDATE|RDW_INVALIDATE))
2806 if (get_req_data_size()) /* no data means whole rectangle */
2808 if (!(region = create_region_from_req_data( get_req_data(), get_req_data_size() )))
2809 return;
2810 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_region( &win->client_rect, region );
2814 redraw_window( win, region, (flags & RDW_INVALIDATE) && (flags & RDW_FRAME), flags );
2815 if (region) free_region( region );
2819 /* set a window property */
2820 DECL_HANDLER(set_window_property)
2822 struct unicode_str name = get_req_unicode_str();
2823 struct window *win = get_window( req->window );
2825 if (!win) return;
2827 if (name.len)
2829 atom_t atom = add_global_atom( NULL, &name );
2830 if (atom)
2832 set_property( win, atom, req->data, PROP_TYPE_STRING );
2833 release_global_atom( NULL, atom );
2836 else set_property( win, req->atom, req->data, PROP_TYPE_ATOM );
2840 /* remove a window property */
2841 DECL_HANDLER(remove_window_property)
2843 struct unicode_str name = get_req_unicode_str();
2844 struct window *win = get_window( req->window );
2846 if (win)
2848 atom_t atom = name.len ? find_global_atom( NULL, &name ) : req->atom;
2849 if (atom) reply->data = remove_property( win, atom );
2854 /* get a window property */
2855 DECL_HANDLER(get_window_property)
2857 struct unicode_str name = get_req_unicode_str();
2858 struct window *win = get_window( req->window );
2860 if (win)
2862 atom_t atom = name.len ? find_global_atom( NULL, &name ) : req->atom;
2863 if (atom) reply->data = get_property( win, atom );
2868 /* get the list of properties of a window */
2869 DECL_HANDLER(get_window_properties)
2871 property_data_t *data;
2872 int i, count, max = get_reply_max_size() / sizeof(*data);
2873 struct window *win = get_window( req->window );
2875 reply->total = 0;
2876 if (!win) return;
2878 for (i = count = 0; i < win->prop_inuse; i++)
2879 if (win->properties[i].type != PROP_TYPE_FREE) count++;
2880 reply->total = count;
2882 if (count > max) count = max;
2883 if (!count || !(data = set_reply_data_size( count * sizeof(*data) ))) return;
2885 for (i = 0; i < win->prop_inuse && count; i++)
2887 if (win->properties[i].type == PROP_TYPE_FREE) continue;
2888 data->atom = win->properties[i].atom;
2889 data->string = (win->properties[i].type == PROP_TYPE_STRING);
2890 data->data = win->properties[i].data;
2891 data++;
2892 count--;
2897 /* get the new window pointer for a global window, checking permissions */
2898 /* helper for set_global_windows request */
2899 static int get_new_global_window( struct window **win, user_handle_t handle )
2901 if (!handle)
2903 *win = NULL;
2904 return 1;
2906 else if (*win)
2908 set_error( STATUS_ACCESS_DENIED );
2909 return 0;
2911 *win = get_window( handle );
2912 return (*win != NULL);
2915 /* Set/get the global windows */
2916 DECL_HANDLER(set_global_windows)
2918 struct window *new_shell_window = shell_window;
2919 struct window *new_shell_listview = shell_listview;
2920 struct window *new_progman_window = progman_window;
2921 struct window *new_taskman_window = taskman_window;
2923 reply->old_shell_window = shell_window ? shell_window->handle : 0;
2924 reply->old_shell_listview = shell_listview ? shell_listview->handle : 0;
2925 reply->old_progman_window = progman_window ? progman_window->handle : 0;
2926 reply->old_taskman_window = taskman_window ? taskman_window->handle : 0;
2928 if (req->flags & SET_GLOBAL_SHELL_WINDOWS)
2930 if (!get_new_global_window( &new_shell_window, req->shell_window )) return;
2931 if (!get_new_global_window( &new_shell_listview, req->shell_listview )) return;
2933 if (req->flags & SET_GLOBAL_PROGMAN_WINDOW)
2935 if (!get_new_global_window( &new_progman_window, req->progman_window )) return;
2937 if (req->flags & SET_GLOBAL_TASKMAN_WINDOW)
2939 if (!get_new_global_window( &new_taskman_window, req->taskman_window )) return;
2941 shell_window = new_shell_window;
2942 shell_listview = new_shell_listview;
2943 progman_window = new_progman_window;
2944 taskman_window = new_taskman_window;
2947 /* retrieve layered info for a window */
2948 DECL_HANDLER(get_window_layered_info)
2950 struct window *win = get_window( req->handle );
2952 if (!win) return;
2954 if (win->is_layered)
2956 reply->color_key = win->color_key;
2957 reply->alpha = win->alpha;
2958 reply->flags = win->layered_flags;
2960 else set_win32_error( ERROR_INVALID_WINDOW_HANDLE );
2964 /* set layered info for a window */
2965 DECL_HANDLER(set_window_layered_info)
2967 struct window *win = get_window( req->handle );
2969 if (!win) return;
2971 if (win->ex_style & WS_EX_LAYERED)
2973 int was_layered = win->is_layered;
2975 if (req->flags & LWA_ALPHA) win->alpha = req->alpha;
2976 else if (!win->is_layered) win->alpha = 0; /* alpha init value is 0 */
2978 win->color_key = req->color_key;
2979 win->layered_flags = req->flags;
2980 win->is_layered = 1;
2981 /* repaint since we know now it's not going to use UpdateLayeredWindow */
2982 if (!was_layered) redraw_window( win, 0, 1, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
2984 else set_win32_error( ERROR_INVALID_WINDOW_HANDLE );