svchost: Move to GUI subsystem (as native).
[wine.git] / server / window.c
blob242e93f303ab38530591e7a6e0475a053302db28
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 int link_window( struct window *win, struct window *previous )
259 struct list *old_prev;
261 if (previous == WINPTR_NOTOPMOST)
263 if (!(win->ex_style & WS_EX_TOPMOST) && win->is_linked) return 0; /* nothing to do */
264 win->ex_style &= ~WS_EX_TOPMOST;
265 previous = WINPTR_TOP; /* fallback to the HWND_TOP case */
268 old_prev = win->is_linked ? win->entry.prev : NULL;
269 list_remove( &win->entry ); /* unlink it from the previous location */
271 if (previous == WINPTR_BOTTOM)
273 list_add_tail( &win->parent->children, &win->entry );
274 win->ex_style &= ~WS_EX_TOPMOST;
276 else if (previous == WINPTR_TOPMOST)
278 list_add_head( &win->parent->children, &win->entry );
279 win->ex_style |= WS_EX_TOPMOST;
281 else if (previous == WINPTR_TOP)
283 struct list *entry = win->parent->children.next;
284 if (!(win->ex_style & WS_EX_TOPMOST)) /* put it above the first non-topmost window */
286 while (entry != &win->parent->children)
288 struct window *next = LIST_ENTRY( entry, struct window, entry );
289 if (!(next->ex_style & WS_EX_TOPMOST)) break;
290 if (next->handle == win->owner) /* keep it above owner */
292 win->ex_style |= WS_EX_TOPMOST;
293 break;
295 entry = entry->next;
298 list_add_before( entry, &win->entry );
300 else
302 list_add_after( &previous->entry, &win->entry );
303 if (!(previous->ex_style & WS_EX_TOPMOST)) win->ex_style &= ~WS_EX_TOPMOST;
304 else
306 struct window *next = get_next_window( win );
307 if (next && (next->ex_style & WS_EX_TOPMOST)) win->ex_style |= WS_EX_TOPMOST;
311 win->is_linked = 1;
312 return old_prev != win->entry.prev;
315 /* change the parent of a window (or unlink the window if the new parent is NULL) */
316 static int set_parent_window( struct window *win, struct window *parent )
318 struct window *ptr;
320 /* make sure parent is not a child of window */
321 for (ptr = parent; ptr; ptr = ptr->parent)
323 if (ptr == win)
325 set_error( STATUS_INVALID_PARAMETER );
326 return 0;
330 if (parent)
332 if (win->parent) release_object( win->parent );
333 win->parent = (struct window *)grab_object( parent );
334 link_window( win, WINPTR_TOP );
336 if (!is_desktop_window( parent ))
338 win->dpi = parent->dpi;
339 win->dpi_awareness = parent->dpi_awareness;
342 /* if parent belongs to a different thread and the window isn't */
343 /* top-level, attach the two threads */
344 if (parent->thread && parent->thread != win->thread && !is_desktop_window(parent))
345 attach_thread_input( win->thread, parent->thread );
347 if (win->paint_flags & (PAINT_HAS_PIXEL_FORMAT | PAINT_PIXEL_FORMAT_CHILD))
348 update_pixel_format_flags( win );
350 else /* move it to parent unlinked list */
352 list_remove( &win->entry ); /* unlink it from the previous location */
353 list_add_head( &win->parent->unlinked, &win->entry );
354 win->is_linked = 0;
355 win->is_orphan = 1;
357 return 1;
360 /* append a user handle to a handle array */
361 static int add_handle_to_array( struct user_handle_array *array, user_handle_t handle )
363 if (array->count >= array->total)
365 int new_total = max( array->total * 2, 32 );
366 user_handle_t *new_array = realloc( array->handles, new_total * sizeof(*new_array) );
367 if (!new_array)
369 free( array->handles );
370 set_error( STATUS_NO_MEMORY );
371 return 0;
373 array->handles = new_array;
374 array->total = new_total;
376 array->handles[array->count++] = handle;
377 return 1;
380 /* set a window property */
381 static void set_property( struct window *win, atom_t atom, lparam_t data, enum property_type type )
383 int i, free = -1;
384 struct property *new_props;
386 /* check if it exists already */
387 for (i = 0; i < win->prop_inuse; i++)
389 if (win->properties[i].type == PROP_TYPE_FREE)
391 free = i;
392 continue;
394 if (win->properties[i].atom == atom)
396 win->properties[i].type = type;
397 win->properties[i].data = data;
398 return;
402 /* need to add an entry */
403 if (!grab_global_atom( NULL, atom )) return;
404 if (free == -1)
406 /* no free entry */
407 if (win->prop_inuse >= win->prop_alloc)
409 /* need to grow the array */
410 if (!(new_props = realloc( win->properties,
411 sizeof(*new_props) * (win->prop_alloc + 16) )))
413 set_error( STATUS_NO_MEMORY );
414 release_global_atom( NULL, atom );
415 return;
417 win->prop_alloc += 16;
418 win->properties = new_props;
420 free = win->prop_inuse++;
422 win->properties[free].atom = atom;
423 win->properties[free].type = type;
424 win->properties[free].data = data;
427 /* remove a window property */
428 static lparam_t remove_property( struct window *win, atom_t atom )
430 int i;
432 for (i = 0; i < win->prop_inuse; i++)
434 if (win->properties[i].type == PROP_TYPE_FREE) continue;
435 if (win->properties[i].atom == atom)
437 release_global_atom( NULL, atom );
438 win->properties[i].type = PROP_TYPE_FREE;
439 return win->properties[i].data;
442 /* FIXME: last error? */
443 return 0;
446 /* find a window property */
447 static lparam_t get_property( struct window *win, atom_t atom )
449 int i;
451 for (i = 0; i < win->prop_inuse; i++)
453 if (win->properties[i].type == PROP_TYPE_FREE) continue;
454 if (win->properties[i].atom == atom) return win->properties[i].data;
456 /* FIXME: last error? */
457 return 0;
460 /* destroy all properties of a window */
461 static inline void destroy_properties( struct window *win )
463 int i;
465 if (!win->properties) return;
466 for (i = 0; i < win->prop_inuse; i++)
468 if (win->properties[i].type == PROP_TYPE_FREE) continue;
469 release_global_atom( NULL, win->properties[i].atom );
471 free( win->properties );
474 /* detach a window from its owner thread but keep the window around */
475 static void detach_window_thread( struct window *win )
477 struct thread *thread = win->thread;
479 if (!thread) return;
480 if (thread->queue)
482 if (win->update_region) inc_queue_paint_count( thread, -1 );
483 if (win->paint_flags & PAINT_INTERNAL) inc_queue_paint_count( thread, -1 );
484 queue_cleanup_window( thread, win->handle );
486 assert( thread->desktop_users > 0 );
487 thread->desktop_users--;
488 release_class( win->class );
489 win->class = NULL;
491 /* don't hold a reference to the desktop so that the desktop window can be */
492 /* destroyed when the desktop ref count reaches zero */
493 release_object( win->desktop );
494 win->thread = NULL;
497 /* get the process owning the top window of a given desktop */
498 struct process *get_top_window_owner( struct desktop *desktop )
500 struct window *win = desktop->top_window;
501 if (!win || !win->thread) return NULL;
502 return win->thread->process;
505 /* get the top window size of a given desktop */
506 void get_top_window_rectangle( struct desktop *desktop, rectangle_t *rect )
508 struct window *win = desktop->top_window;
509 *rect = win ? win->window_rect : empty_rect;
512 /* post a message to the desktop window */
513 void post_desktop_message( struct desktop *desktop, unsigned int message,
514 lparam_t wparam, lparam_t lparam )
516 struct window *win = desktop->top_window;
517 if (win && win->thread) post_message( win->handle, message, wparam, lparam );
520 /* create a new window structure (note: the window is not linked in the window tree) */
521 static struct window *create_window( struct window *parent, struct window *owner,
522 atom_t atom, mod_handle_t instance )
524 int extra_bytes;
525 struct window *win = NULL;
526 struct desktop *desktop;
527 struct window_class *class;
529 if (!(desktop = get_thread_desktop( current, DESKTOP_CREATEWINDOW ))) return NULL;
531 if (!(class = grab_class( current->process, atom, instance, &extra_bytes )))
533 release_object( desktop );
534 return NULL;
537 if (!parent) /* null parent is only allowed for desktop or HWND_MESSAGE top window */
539 if (is_desktop_class( class ))
540 parent = desktop->top_window; /* use existing desktop if any */
541 else if (is_hwnd_message_class( class ))
542 /* use desktop window if message window is already created */
543 parent = desktop->msg_window ? desktop->top_window : NULL;
544 else if (!(parent = desktop->top_window)) /* must already have a desktop then */
546 set_error( STATUS_ACCESS_DENIED );
547 goto failed;
551 /* parent must be on the same desktop */
552 if (parent && parent->desktop != desktop)
554 set_error( STATUS_ACCESS_DENIED );
555 goto failed;
558 if (!(win = alloc_object( &window_ops ))) goto failed;
559 win->parent = parent ? (struct window *)grab_object( parent ) : NULL;
560 win->owner = owner ? owner->handle : 0;
561 win->thread = current;
562 win->desktop = desktop;
563 win->class = class;
564 win->atom = atom;
565 win->last_active = win->handle;
566 win->win_region = NULL;
567 win->update_region = NULL;
568 win->style = 0;
569 win->ex_style = 0;
570 win->id = 0;
571 win->instance = 0;
572 win->is_unicode = 1;
573 win->is_linked = 0;
574 win->is_layered = 0;
575 win->is_orphan = 0;
576 win->dpi_awareness = DPI_AWARENESS_PER_MONITOR_AWARE;
577 win->dpi = 0;
578 win->user_data = 0;
579 win->text = NULL;
580 win->text_len = 0;
581 win->paint_flags = 0;
582 win->prop_inuse = 0;
583 win->prop_alloc = 0;
584 win->properties = NULL;
585 win->nb_extra_bytes = 0;
586 win->extra_bytes = NULL;
587 win->window_rect = win->visible_rect = win->surface_rect = win->client_rect = empty_rect;
588 list_init( &win->children );
589 list_init( &win->unlinked );
591 if (extra_bytes)
593 if (!(win->extra_bytes = mem_alloc( extra_bytes ))) goto failed;
594 memset( win->extra_bytes, 0, extra_bytes );
595 win->nb_extra_bytes = extra_bytes;
597 if (!(win->handle = alloc_user_handle( win, USER_WINDOW ))) goto failed;
599 /* if parent belongs to a different thread and the window isn't */
600 /* top-level, attach the two threads */
601 if (parent && parent->thread && parent->thread != current && !is_desktop_window(parent))
603 if (!attach_thread_input( current, parent->thread )) goto failed;
605 else /* otherwise just make sure that the thread has a message queue */
607 if (!current->queue && !init_thread_queue( current )) goto failed;
610 /* put it on parent unlinked list */
611 if (parent) list_add_head( &parent->unlinked, &win->entry );
612 else
614 list_init( &win->entry );
615 if (is_desktop_class( class ))
617 assert( !desktop->top_window );
618 desktop->top_window = win;
619 set_process_default_desktop( current->process, desktop, current->desktop );
621 else
623 assert( !desktop->msg_window );
624 desktop->msg_window = win;
628 current->desktop_users++;
629 return win;
631 failed:
632 if (win)
634 if (win->handle)
636 free_user_handle( win->handle );
637 win->handle = 0;
639 release_object( win );
641 release_object( desktop );
642 release_class( class );
643 return NULL;
646 /* destroy all windows belonging to a given thread */
647 void destroy_thread_windows( struct thread *thread )
649 user_handle_t handle = 0;
650 struct window *win;
652 while ((win = next_user_handle( &handle, USER_WINDOW )))
654 if (win->thread != thread) continue;
655 if (is_desktop_window( win )) detach_window_thread( win );
656 else free_window_handle( win );
660 /* get the desktop window */
661 static struct window *get_desktop_window( struct thread *thread )
663 struct window *top_window;
664 struct desktop *desktop = get_thread_desktop( thread, 0 );
666 if (!desktop) return NULL;
667 top_window = desktop->top_window;
668 release_object( desktop );
669 return top_window;
672 /* check whether child is a descendant of parent */
673 int is_child_window( user_handle_t parent, user_handle_t child )
675 struct window *child_ptr = get_user_object( child, USER_WINDOW );
676 struct window *parent_ptr = get_user_object( parent, USER_WINDOW );
678 if (!child_ptr || !parent_ptr) return 0;
679 while (child_ptr->parent)
681 if (child_ptr->parent == parent_ptr) return 1;
682 child_ptr = child_ptr->parent;
684 return 0;
687 /* check if window can be set as foreground window */
688 int is_valid_foreground_window( user_handle_t window )
690 struct window *win = get_user_object( window, USER_WINDOW );
691 return win && (win->style & (WS_POPUP|WS_CHILD)) != WS_CHILD;
694 /* make a window active if possible */
695 int make_window_active( user_handle_t window )
697 struct window *owner, *win = get_window( window );
699 if (!win) return 0;
701 /* set last active for window and its owners */
702 owner = win;
703 while (owner)
705 owner->last_active = win->handle;
706 owner = get_user_object( owner->owner, USER_WINDOW );
708 return 1;
711 /* increment (or decrement) the window paint count */
712 static inline void inc_window_paint_count( struct window *win, int incr )
714 if (win->thread) inc_queue_paint_count( win->thread, incr );
717 /* map a point between different DPI scaling levels */
718 static void map_dpi_point( struct window *win, int *x, int *y, unsigned int from, unsigned int to )
720 if (!from) from = get_monitor_dpi( win );
721 if (!to) to = get_monitor_dpi( win );
722 if (from == to) return;
723 *x = scale_dpi( *x, from, to );
724 *y = scale_dpi( *y, from, to );
727 /* map a window rectangle between different DPI scaling levels */
728 static void map_dpi_rect( struct window *win, rectangle_t *rect, unsigned int from, unsigned int to )
730 if (!from) from = get_monitor_dpi( win );
731 if (!to) to = get_monitor_dpi( win );
732 if (from == to) return;
733 scale_dpi_rect( rect, from, to );
736 /* map a region between different DPI scaling levels */
737 static void map_dpi_region( struct window *win, struct region *region, unsigned int from, unsigned int to )
739 if (!from) from = get_monitor_dpi( win );
740 if (!to) to = get_monitor_dpi( win );
741 if (from == to) return;
742 scale_region( region, from, to );
745 /* convert coordinates from client to screen coords */
746 static inline void client_to_screen( struct window *win, int *x, int *y )
748 for ( ; win && !is_desktop_window(win); win = win->parent)
750 *x += win->client_rect.left;
751 *y += win->client_rect.top;
755 /* convert coordinates from screen to client coords and dpi */
756 static void screen_to_client( struct window *win, int *x, int *y, unsigned int dpi )
758 int offset_x = 0, offset_y = 0;
760 if (is_desktop_window( win )) return;
762 client_to_screen( win, &offset_x, &offset_y );
763 map_dpi_point( win, x, y, dpi, win->dpi );
764 *x -= offset_x;
765 *y -= offset_y;
768 /* check if window and all its ancestors are visible */
769 static int is_visible( const struct window *win )
771 while (win)
773 if (!(win->style & WS_VISIBLE)) return 0;
774 win = win->parent;
775 /* if parent is minimized children are not visible */
776 if (win && (win->style & WS_MINIMIZE)) return 0;
778 return 1;
781 /* same as is_visible but takes a window handle */
782 int is_window_visible( user_handle_t window )
784 struct window *win = get_user_object( window, USER_WINDOW );
785 if (!win) return 0;
786 return is_visible( win );
789 int is_window_transparent( user_handle_t window )
791 struct window *win = get_user_object( window, USER_WINDOW );
792 if (!win) return 0;
793 return (win->ex_style & (WS_EX_LAYERED|WS_EX_TRANSPARENT)) == (WS_EX_LAYERED|WS_EX_TRANSPARENT);
796 static int is_window_using_parent_dc( struct window *win )
798 return (win->style & (WS_POPUP|WS_CHILD)) == WS_CHILD && (get_class_style( win->class ) & CS_PARENTDC) != 0;
801 static int is_window_composited( struct window *win )
803 return (win->ex_style & WS_EX_COMPOSITED) != 0 && !is_window_using_parent_dc(win);
806 static int is_parent_composited( struct window *win )
808 return win->parent && is_window_composited( win->parent );
811 /* check if point is inside the window, and map to window dpi */
812 static int is_point_in_window( struct window *win, int *x, int *y, unsigned int dpi )
814 if (!(win->style & WS_VISIBLE)) return 0; /* not visible */
815 if ((win->style & (WS_POPUP|WS_CHILD|WS_DISABLED)) == (WS_CHILD|WS_DISABLED))
816 return 0; /* disabled child */
817 if ((win->ex_style & (WS_EX_LAYERED|WS_EX_TRANSPARENT)) == (WS_EX_LAYERED|WS_EX_TRANSPARENT))
818 return 0; /* transparent */
819 map_dpi_point( win, x, y, dpi, win->dpi );
820 if (!point_in_rect( &win->visible_rect, *x, *y ))
821 return 0; /* not in window */
822 if (win->win_region &&
823 !point_in_region( win->win_region, *x - win->window_rect.left, *y - win->window_rect.top ))
824 return 0; /* not in window region */
825 return 1;
828 /* fill an array with the handles of the children of a specified window */
829 static unsigned int get_children_windows( struct window *parent, atom_t atom, thread_id_t tid,
830 user_handle_t *handles, unsigned int max_count )
832 struct window *ptr;
833 unsigned int count = 0;
835 if (!parent) return 0;
837 LIST_FOR_EACH_ENTRY( ptr, &parent->children, struct window, entry )
839 if (atom && get_class_atom(ptr->class) != atom) continue;
840 if (tid && get_thread_id(ptr->thread) != tid) continue;
841 if (handles)
843 if (count >= max_count) break;
844 handles[count] = ptr->handle;
846 count++;
848 return count;
851 /* find child of 'parent' that contains the given point (in parent-relative coords) */
852 static struct window *child_window_from_point( struct window *parent, int x, int y )
854 struct window *ptr;
856 LIST_FOR_EACH_ENTRY( ptr, &parent->children, struct window, entry )
858 int x_child = x, y_child = y;
860 if (!is_point_in_window( ptr, &x_child, &y_child, parent->dpi )) continue; /* skip it */
862 /* if window is minimized or disabled, return at once */
863 if (ptr->style & (WS_MINIMIZE|WS_DISABLED)) return ptr;
865 /* if point is not in client area, return at once */
866 if (!point_in_rect( &ptr->client_rect, x_child, y_child )) return ptr;
868 return child_window_from_point( ptr, x_child - ptr->client_rect.left,
869 y_child - ptr->client_rect.top );
871 return parent; /* not found any child */
874 /* find all children of 'parent' that contain the given point */
875 static int get_window_children_from_point( struct window *parent, int x, int y,
876 struct user_handle_array *array )
878 struct window *ptr;
880 LIST_FOR_EACH_ENTRY( ptr, &parent->children, struct window, entry )
882 int x_child = x, y_child = y;
884 if (!is_point_in_window( ptr, &x_child, &y_child, parent->dpi )) continue; /* skip it */
886 /* if point is in client area, and window is not minimized or disabled, check children */
887 if (!(ptr->style & (WS_MINIMIZE|WS_DISABLED)) && point_in_rect( &ptr->client_rect, x_child, y_child ))
889 if (!get_window_children_from_point( ptr, x_child - ptr->client_rect.left,
890 y_child - ptr->client_rect.top, array ))
891 return 0;
894 /* now add window to the array */
895 if (!add_handle_to_array( array, ptr->handle )) return 0;
897 return 1;
900 /* get handle of root of top-most window containing point */
901 user_handle_t shallow_window_from_point( struct desktop *desktop, int x, int y )
903 struct window *ptr;
905 if (!desktop->top_window) return 0;
907 LIST_FOR_EACH_ENTRY( ptr, &desktop->top_window->children, struct window, entry )
909 int x_child = x, y_child = y;
911 if (!is_point_in_window( ptr, &x_child, &y_child, 0 )) continue; /* skip it */
912 return ptr->handle;
914 return desktop->top_window->handle;
917 /* return thread of top-most window containing point (in absolute coords) */
918 struct thread *window_thread_from_point( user_handle_t scope, int x, int y )
920 struct window *win = get_user_object( scope, USER_WINDOW );
922 if (!win) return NULL;
924 screen_to_client( win, &x, &y, 0 );
925 win = child_window_from_point( win, x, y );
926 if (!win->thread) return NULL;
927 return (struct thread *)grab_object( win->thread );
930 /* return list of all windows containing point (in absolute coords) */
931 static int all_windows_from_point( struct window *top, int x, int y, unsigned int dpi,
932 struct user_handle_array *array )
934 if (!is_desktop_window( top ) && !is_desktop_window( top->parent ))
936 screen_to_client( top->parent, &x, &y, dpi );
937 dpi = top->parent->dpi;
940 if (!is_point_in_window( top, &x, &y, dpi )) return 1;
941 /* if point is in client area, and window is not minimized or disabled, check children */
942 if (!(top->style & (WS_MINIMIZE|WS_DISABLED)) && point_in_rect( &top->client_rect, x, y ))
944 if (!is_desktop_window(top))
946 x -= top->client_rect.left;
947 y -= top->client_rect.top;
949 if (!get_window_children_from_point( top, x, y, array )) return 0;
951 /* now add window to the array */
952 if (!add_handle_to_array( array, top->handle )) return 0;
953 return 1;
957 /* return the thread owning a window */
958 struct thread *get_window_thread( user_handle_t handle )
960 struct window *win = get_user_object( handle, USER_WINDOW );
961 if (!win || !win->thread) return NULL;
962 return (struct thread *)grab_object( win->thread );
966 /* check if any area of a window needs repainting */
967 static inline int win_needs_repaint( struct window *win )
969 return win->update_region || (win->paint_flags & PAINT_INTERNAL);
973 /* find a child of the specified window that needs repainting */
974 static struct window *find_child_to_repaint( struct window *parent, struct thread *thread )
976 struct window *ptr, *ret = NULL;
978 LIST_FOR_EACH_ENTRY( ptr, &parent->children, struct window, entry )
980 if (!(ptr->style & WS_VISIBLE)) continue;
981 if (ptr->thread == thread && win_needs_repaint( ptr ))
982 ret = ptr;
983 else if (!(ptr->style & WS_MINIMIZE)) /* explore its children */
984 ret = find_child_to_repaint( ptr, thread );
985 if (ret) break;
988 if (ret && (ret->ex_style & WS_EX_TRANSPARENT))
990 /* transparent window, check for non-transparent sibling to paint first */
991 for (ptr = get_next_window(ret); ptr; ptr = get_next_window(ptr))
993 if (!(ptr->style & WS_VISIBLE)) continue;
994 if (ptr->ex_style & WS_EX_TRANSPARENT) continue;
995 if (ptr->thread != thread) continue;
996 if (win_needs_repaint( ptr )) return ptr;
999 return ret;
1003 /* find a window that needs to receive a WM_PAINT; also clear its internal paint flag */
1004 user_handle_t find_window_to_repaint( user_handle_t parent, struct thread *thread )
1006 struct window *ptr, *win, *top_window = get_desktop_window( thread );
1008 if (!top_window) return 0;
1010 if (top_window->thread == thread && win_needs_repaint( top_window )) win = top_window;
1011 else win = find_child_to_repaint( top_window, thread );
1013 if (win && parent)
1015 /* check that it is a child of the specified parent */
1016 for (ptr = win; ptr; ptr = ptr->parent)
1017 if (ptr->handle == parent) break;
1018 /* otherwise don't return any window, we don't repaint a child before its parent */
1019 if (!ptr) win = NULL;
1021 if (!win) return 0;
1022 win->paint_flags &= ~PAINT_INTERNAL;
1023 return win->handle;
1027 /* intersect the window region with the specified region, relative to the window parent */
1028 static struct region *intersect_window_region( struct region *region, struct window *win )
1030 /* make region relative to window rect */
1031 offset_region( region, -win->window_rect.left, -win->window_rect.top );
1032 if (!intersect_region( region, region, win->win_region )) return NULL;
1033 /* make region relative to parent again */
1034 offset_region( region, win->window_rect.left, win->window_rect.top );
1035 return region;
1039 /* convert coordinates from client to screen coords */
1040 static inline void client_to_screen_rect( struct window *win, rectangle_t *rect )
1042 for ( ; win && !is_desktop_window(win); win = win->parent)
1043 offset_rect( rect, win->client_rect.left, win->client_rect.top );
1046 /* map the region from window to screen coordinates */
1047 static inline void map_win_region_to_screen( struct window *win, struct region *region )
1049 if (!is_desktop_window(win))
1051 int x = win->window_rect.left;
1052 int y = win->window_rect.top;
1053 client_to_screen( win->parent, &x, &y );
1054 offset_region( region, x, y );
1059 /* clip all children of a given window out of the visible region */
1060 static struct region *clip_children( struct window *parent, struct window *last,
1061 struct region *region, int offset_x, int offset_y )
1063 struct window *ptr;
1064 struct region *tmp = create_empty_region();
1066 if (!tmp) return NULL;
1067 LIST_FOR_EACH_ENTRY( ptr, &parent->children, struct window, entry )
1069 if (ptr == last) break;
1070 if (!(ptr->style & WS_VISIBLE)) continue;
1071 if (ptr->ex_style & WS_EX_TRANSPARENT) continue;
1072 set_region_rect( tmp, &ptr->visible_rect );
1073 if (ptr->win_region && !intersect_window_region( tmp, ptr ))
1075 free_region( tmp );
1076 return NULL;
1078 offset_region( tmp, offset_x, offset_y );
1079 if (!(region = subtract_region( region, region, tmp ))) break;
1080 if (is_region_empty( region )) break;
1082 free_region( tmp );
1083 return region;
1087 /* set the region to the client rect clipped by the window rect, in parent-relative coordinates */
1088 static void set_region_client_rect( struct region *region, struct window *win )
1090 rectangle_t rect;
1092 intersect_rect( &rect, &win->window_rect, &win->client_rect );
1093 intersect_rect( &rect, &rect, &win->surface_rect );
1094 set_region_rect( region, &rect );
1098 /* set the region to the visible rect clipped by the window surface, in parent-relative coordinates */
1099 static void set_region_visible_rect( struct region *region, struct window *win )
1101 rectangle_t rect;
1103 intersect_rect( &rect, &win->visible_rect, &win->surface_rect );
1104 set_region_rect( region, &rect );
1108 /* get the top-level window to clip against for a given window */
1109 static inline struct window *get_top_clipping_window( struct window *win )
1111 while (!(win->paint_flags & PAINT_HAS_SURFACE) && win->parent && !is_desktop_window(win->parent))
1112 win = win->parent;
1113 return win;
1117 /* compute the visible region of a window, in window coordinates */
1118 static struct region *get_visible_region( struct window *win, unsigned int flags )
1120 struct region *tmp = NULL, *region;
1121 int offset_x, offset_y;
1123 if (!(region = create_empty_region())) return NULL;
1125 /* first check if all ancestors are visible */
1127 if (!is_visible( win )) return region; /* empty region */
1129 if (is_desktop_window( win ))
1131 set_region_rect( region, &win->window_rect );
1132 return region;
1135 /* create a region relative to the window itself */
1137 if ((flags & DCX_PARENTCLIP) && !is_desktop_window( win->parent ))
1139 set_region_client_rect( region, win->parent );
1140 offset_region( region, -win->parent->client_rect.left, -win->parent->client_rect.top );
1142 else if (flags & DCX_WINDOW)
1144 set_region_visible_rect( region, win );
1145 if (win->win_region && !intersect_window_region( region, win )) goto error;
1147 else
1149 set_region_client_rect( region, win );
1150 if (win->win_region && !intersect_window_region( region, win )) goto error;
1153 /* clip children */
1155 if (flags & DCX_CLIPCHILDREN)
1157 if (!clip_children( win, NULL, region, win->client_rect.left, win->client_rect.top )) goto error;
1160 /* clip siblings of ancestors */
1162 offset_x = win->window_rect.left;
1163 offset_y = win->window_rect.top;
1165 if ((tmp = create_empty_region()) != NULL)
1167 while (!is_desktop_window( win->parent ))
1169 /* we don't clip out top-level siblings as that's up to the native windowing system */
1170 if (win->style & WS_CLIPSIBLINGS)
1172 if (!clip_children( win->parent, win, region, 0, 0 )) goto error;
1173 if (is_region_empty( region )) break;
1175 /* clip to parent client area */
1176 win = win->parent;
1177 offset_x += win->client_rect.left;
1178 offset_y += win->client_rect.top;
1179 offset_region( region, win->client_rect.left, win->client_rect.top );
1180 set_region_client_rect( tmp, win );
1181 if (win->win_region && !intersect_window_region( tmp, win )) goto error;
1182 if (!intersect_region( region, region, tmp )) goto error;
1183 if (is_region_empty( region )) break;
1185 free_region( tmp );
1187 offset_region( region, -offset_x, -offset_y ); /* make it relative to target window */
1188 return region;
1190 error:
1191 if (tmp) free_region( tmp );
1192 free_region( region );
1193 return NULL;
1197 /* clip all children with a custom pixel format out of the visible region */
1198 static struct region *clip_pixel_format_children( struct window *parent, struct region *parent_clip,
1199 struct region *region, int offset_x, int offset_y )
1201 struct window *ptr;
1202 struct region *clip = create_empty_region();
1204 if (!clip) return NULL;
1206 LIST_FOR_EACH_ENTRY_REV( ptr, &parent->children, struct window, entry )
1208 if (!(ptr->style & WS_VISIBLE)) continue;
1209 if (ptr->ex_style & WS_EX_TRANSPARENT) continue;
1211 /* add the visible rect */
1212 set_region_rect( clip, &ptr->visible_rect );
1213 if (ptr->win_region && !intersect_window_region( clip, ptr )) break;
1214 offset_region( clip, offset_x, offset_y );
1215 if (!intersect_region( clip, clip, parent_clip )) break;
1216 if (!union_region( region, region, clip )) break;
1217 if (!(ptr->paint_flags & (PAINT_HAS_PIXEL_FORMAT | PAINT_PIXEL_FORMAT_CHILD))) continue;
1219 /* subtract the client rect if it uses a custom pixel format */
1220 set_region_rect( clip, &ptr->client_rect );
1221 if (ptr->win_region && !intersect_window_region( clip, ptr )) break;
1222 offset_region( clip, offset_x, offset_y );
1223 if (!intersect_region( clip, clip, parent_clip )) break;
1224 if ((ptr->paint_flags & PAINT_HAS_PIXEL_FORMAT) && !subtract_region( region, region, clip ))
1225 break;
1227 if (!clip_pixel_format_children( ptr, clip, region, offset_x + ptr->client_rect.left,
1228 offset_y + ptr->client_rect.top ))
1229 break;
1231 free_region( clip );
1232 return region;
1236 /* compute the visible surface region of a window, in parent coordinates */
1237 static struct region *get_surface_region( struct window *win )
1239 struct region *region, *clip;
1240 int offset_x, offset_y;
1242 /* create a region relative to the window itself */
1244 if (!(region = create_empty_region())) return NULL;
1245 if (!(clip = create_empty_region())) goto error;
1246 set_region_rect( region, &win->visible_rect );
1247 if (win->win_region && !intersect_window_region( region, win )) goto error;
1248 set_region_rect( clip, &win->client_rect );
1249 if (win->win_region && !intersect_window_region( clip, win )) goto error;
1251 if ((win->paint_flags & PAINT_HAS_PIXEL_FORMAT) && !subtract_region( region, region, clip ))
1252 goto error;
1254 /* clip children */
1256 if (!is_desktop_window(win))
1258 offset_x = win->client_rect.left;
1259 offset_y = win->client_rect.top;
1261 else offset_x = offset_y = 0;
1263 if (!clip_pixel_format_children( win, clip, region, offset_x, offset_y )) goto error;
1265 free_region( clip );
1266 return region;
1268 error:
1269 if (clip) free_region( clip );
1270 free_region( region );
1271 return NULL;
1275 /* get the window class of a window */
1276 struct window_class* get_window_class( user_handle_t window )
1278 struct window *win;
1279 if (!(win = get_window( window ))) return NULL;
1280 if (!win->class) set_error( STATUS_ACCESS_DENIED );
1281 return win->class;
1284 /* determine the window visible rectangle, i.e. window or client rect cropped by parent rects */
1285 /* the returned rectangle is in window coordinates; return 0 if rectangle is empty */
1286 static int get_window_visible_rect( struct window *win, rectangle_t *rect, int frame )
1288 int offset_x = win->window_rect.left, offset_y = win->window_rect.top;
1290 *rect = frame ? win->window_rect : win->client_rect;
1292 if (!(win->style & WS_VISIBLE)) return 0;
1293 if (is_desktop_window( win )) return 1;
1295 while (!is_desktop_window( win->parent ))
1297 win = win->parent;
1298 if (!(win->style & WS_VISIBLE) || win->style & WS_MINIMIZE) return 0;
1299 offset_x += win->client_rect.left;
1300 offset_y += win->client_rect.top;
1301 offset_rect( rect, win->client_rect.left, win->client_rect.top );
1302 if (!intersect_rect( rect, rect, &win->client_rect )) return 0;
1303 if (!intersect_rect( rect, rect, &win->window_rect )) return 0;
1305 offset_rect( rect, -offset_x, -offset_y );
1306 return 1;
1309 /* return a copy of the specified region cropped to the window client or frame rectangle, */
1310 /* and converted from client to window coordinates. Helper for (in)validate_window. */
1311 static struct region *crop_region_to_win_rect( struct window *win, struct region *region, int frame )
1313 rectangle_t rect;
1314 struct region *tmp;
1316 if (!get_window_visible_rect( win, &rect, frame )) return NULL;
1317 if (!(tmp = create_empty_region())) return NULL;
1318 set_region_rect( tmp, &rect );
1320 if (region)
1322 /* map it to client coords */
1323 offset_region( tmp, win->window_rect.left - win->client_rect.left,
1324 win->window_rect.top - win->client_rect.top );
1326 /* intersect specified region with bounding rect */
1327 if (!intersect_region( tmp, region, tmp )) goto done;
1328 if (is_region_empty( tmp )) goto done;
1330 /* map it back to window coords */
1331 offset_region( tmp, win->client_rect.left - win->window_rect.left,
1332 win->client_rect.top - win->window_rect.top );
1334 return tmp;
1336 done:
1337 free_region( tmp );
1338 return NULL;
1342 /* set a region as new update region for the window */
1343 static void set_update_region( struct window *win, struct region *region )
1345 if (region && !is_region_empty( region ))
1347 if (!win->update_region) inc_window_paint_count( win, 1 );
1348 else free_region( win->update_region );
1349 win->update_region = region;
1351 else
1353 if (win->update_region)
1355 inc_window_paint_count( win, -1 );
1356 free_region( win->update_region );
1358 win->paint_flags &= ~(PAINT_ERASE | PAINT_DELAYED_ERASE | PAINT_NONCLIENT);
1359 win->update_region = NULL;
1360 if (region) free_region( region );
1365 /* add a region to the update region; the passed region is freed or reused */
1366 static int add_update_region( struct window *win, struct region *region )
1368 if (win->update_region && !union_region( region, win->update_region, region ))
1370 free_region( region );
1371 return 0;
1373 set_update_region( win, region );
1374 return 1;
1378 /* crop the update region of children to the specified rectangle, in client coords */
1379 static void crop_children_update_region( struct window *win, rectangle_t *rect )
1381 struct window *child;
1382 struct region *tmp;
1383 rectangle_t child_rect;
1385 LIST_FOR_EACH_ENTRY( child, &win->children, struct window, entry )
1387 if (!(child->style & WS_VISIBLE)) continue;
1388 if (!rect) /* crop everything out */
1390 crop_children_update_region( child, NULL );
1391 set_update_region( child, NULL );
1392 continue;
1395 /* nothing to do if child is completely inside rect */
1396 if (child->window_rect.left >= rect->left &&
1397 child->window_rect.top >= rect->top &&
1398 child->window_rect.right <= rect->right &&
1399 child->window_rect.bottom <= rect->bottom) continue;
1401 /* map to child client coords and crop grand-children */
1402 child_rect = *rect;
1403 offset_rect( &child_rect, -child->client_rect.left, -child->client_rect.top );
1404 crop_children_update_region( child, &child_rect );
1406 /* now crop the child itself */
1407 if (!child->update_region) continue;
1408 if (!(tmp = create_empty_region())) continue;
1409 set_region_rect( tmp, rect );
1410 offset_region( tmp, -child->window_rect.left, -child->window_rect.top );
1411 if (intersect_region( tmp, child->update_region, tmp )) set_update_region( child, tmp );
1412 else free_region( tmp );
1417 /* validate the non client area of a window */
1418 static void validate_non_client( struct window *win )
1420 struct region *tmp;
1421 rectangle_t rect;
1423 if (!win->update_region) return; /* nothing to do */
1425 /* get client rect in window coords */
1426 rect.left = win->client_rect.left - win->window_rect.left;
1427 rect.top = win->client_rect.top - win->window_rect.top;
1428 rect.right = win->client_rect.right - win->window_rect.left;
1429 rect.bottom = win->client_rect.bottom - win->window_rect.top;
1431 if ((tmp = create_empty_region()))
1433 set_region_rect( tmp, &rect );
1434 if (intersect_region( tmp, win->update_region, tmp ))
1435 set_update_region( win, tmp );
1436 else
1437 free_region( tmp );
1439 win->paint_flags &= ~PAINT_NONCLIENT;
1443 /* validate a window completely so that we don't get any further paint messages for it */
1444 static void validate_whole_window( struct window *win )
1446 set_update_region( win, NULL );
1448 if (win->paint_flags & PAINT_INTERNAL)
1450 win->paint_flags &= ~PAINT_INTERNAL;
1451 inc_window_paint_count( win, -1 );
1456 /* validate a window's children so that we don't get any further paint messages for it */
1457 static void validate_children( struct window *win )
1459 struct window *child;
1461 LIST_FOR_EACH_ENTRY( child, &win->children, struct window, entry )
1463 if (!(child->style & WS_VISIBLE)) continue;
1464 validate_children(child);
1465 validate_whole_window(child);
1470 /* validate the update region of a window on all parents; helper for get_update_region */
1471 static void validate_parents( struct window *child )
1473 int offset_x = 0, offset_y = 0;
1474 struct window *win = child;
1475 struct region *tmp = NULL;
1477 if (!child->update_region) return;
1479 while (win->parent)
1481 /* map to parent client coords */
1482 offset_x += win->window_rect.left;
1483 offset_y += win->window_rect.top;
1485 win = win->parent;
1487 /* and now map to window coords */
1488 offset_x += win->client_rect.left - win->window_rect.left;
1489 offset_y += win->client_rect.top - win->window_rect.top;
1491 if (win->update_region && !(win->style & WS_CLIPCHILDREN))
1493 if (!tmp && !(tmp = create_empty_region())) return;
1494 offset_region( child->update_region, offset_x, offset_y );
1495 if (subtract_region( tmp, win->update_region, child->update_region ))
1497 set_update_region( win, tmp );
1498 tmp = NULL;
1500 /* restore child coords */
1501 offset_region( child->update_region, -offset_x, -offset_y );
1504 if (tmp) free_region( tmp );
1508 /* add/subtract a region (in client coordinates) to the update region of the window */
1509 static void redraw_window( struct window *win, struct region *region, int frame, unsigned int flags )
1511 struct region *child_rgn, *tmp;
1512 struct window *child;
1514 if (flags & RDW_INVALIDATE)
1516 if (!(tmp = crop_region_to_win_rect( win, region, frame ))) return;
1518 if (!add_update_region( win, tmp )) return;
1520 if (flags & RDW_FRAME) win->paint_flags |= PAINT_NONCLIENT;
1521 if (flags & RDW_ERASE) win->paint_flags |= PAINT_ERASE;
1523 else if (flags & RDW_VALIDATE)
1525 if (!region && (flags & RDW_NOFRAME)) /* shortcut: validate everything */
1527 set_update_region( win, NULL );
1529 else if (win->update_region)
1531 if ((tmp = crop_region_to_win_rect( win, region, frame )))
1533 if (!subtract_region( tmp, win->update_region, tmp ))
1535 free_region( tmp );
1536 return;
1538 set_update_region( win, tmp );
1540 if (flags & RDW_NOFRAME) validate_non_client( win );
1541 if (flags & RDW_NOERASE) win->paint_flags &= ~(PAINT_ERASE | PAINT_DELAYED_ERASE);
1545 if ((flags & RDW_INTERNALPAINT) && !(win->paint_flags & PAINT_INTERNAL))
1547 win->paint_flags |= PAINT_INTERNAL;
1548 inc_window_paint_count( win, 1 );
1550 else if ((flags & RDW_NOINTERNALPAINT) && (win->paint_flags & PAINT_INTERNAL))
1552 win->paint_flags &= ~PAINT_INTERNAL;
1553 inc_window_paint_count( win, -1 );
1556 /* now process children recursively */
1558 if (flags & RDW_NOCHILDREN) return;
1559 if (win->style & WS_MINIMIZE) return;
1560 if ((win->style & WS_CLIPCHILDREN) && !(flags & RDW_ALLCHILDREN)) return;
1562 if (!(tmp = crop_region_to_win_rect( win, region, 0 ))) return;
1564 /* map to client coordinates */
1565 offset_region( tmp, win->window_rect.left - win->client_rect.left,
1566 win->window_rect.top - win->client_rect.top );
1568 if (flags & RDW_INVALIDATE) flags |= RDW_FRAME | RDW_ERASE;
1570 LIST_FOR_EACH_ENTRY( child, &win->children, struct window, entry )
1572 if (!(child->style & WS_VISIBLE)) continue;
1573 if (!(child_rgn = create_empty_region())) continue;
1574 if (copy_region( child_rgn, tmp ))
1576 map_dpi_region( child, child_rgn, win->dpi, child->dpi );
1577 if (rect_in_region( child_rgn, &child->window_rect ))
1579 offset_region( child_rgn, -child->client_rect.left, -child->client_rect.top );
1580 redraw_window( child, child_rgn, 1, flags );
1583 free_region( child_rgn );
1586 free_region( tmp );
1590 /* retrieve the update flags for a window depending on the state of the update region */
1591 static unsigned int get_update_flags( struct window *win, unsigned int flags )
1593 unsigned int ret = 0;
1595 if (flags & UPDATE_NONCLIENT)
1597 if ((win->paint_flags & PAINT_NONCLIENT) && win->update_region) ret |= UPDATE_NONCLIENT;
1599 if (flags & UPDATE_ERASE)
1601 if ((win->paint_flags & PAINT_ERASE) && win->update_region) ret |= UPDATE_ERASE;
1603 if (flags & UPDATE_PAINT)
1605 if (win->update_region)
1607 if (win->paint_flags & PAINT_DELAYED_ERASE) ret |= UPDATE_DELAYED_ERASE;
1608 ret |= UPDATE_PAINT;
1611 if (flags & UPDATE_INTERNALPAINT)
1613 if (win->paint_flags & PAINT_INTERNAL)
1615 ret |= UPDATE_INTERNALPAINT;
1616 if (win->paint_flags & PAINT_DELAYED_ERASE) ret |= UPDATE_DELAYED_ERASE;
1619 return ret;
1623 /* iterate through the children of the given window until we find one with some update flags */
1624 static unsigned int get_child_update_flags( struct window *win, struct window *from_child,
1625 unsigned int flags, struct window **child )
1627 struct window *ptr;
1628 unsigned int ret = 0;
1630 /* first make sure we want to iterate children at all */
1632 if (win->style & WS_MINIMIZE) return 0;
1634 /* note: the WS_CLIPCHILDREN test is the opposite of the invalidation case,
1635 * here we only want to repaint children of windows that clip them, others
1636 * need to wait for WM_PAINT to be done in the parent first.
1638 if (!(flags & UPDATE_ALLCHILDREN) && !(win->style & WS_CLIPCHILDREN)) return 0;
1640 LIST_FOR_EACH_ENTRY( ptr, &win->children, struct window, entry )
1642 if (from_child) /* skip all children until from_child is found */
1644 if (ptr == from_child) from_child = NULL;
1645 continue;
1647 if (!(ptr->style & WS_VISIBLE)) continue;
1648 if ((ret = get_update_flags( ptr, flags )) != 0)
1650 *child = ptr;
1651 break;
1653 if ((ret = get_child_update_flags( ptr, NULL, flags, child ))) break;
1655 return ret;
1658 /* iterate through children and siblings of the given window until we find one with some update flags */
1659 static unsigned int get_window_update_flags( struct window *win, struct window *from_child,
1660 unsigned int flags, struct window **child )
1662 unsigned int ret;
1663 struct window *ptr, *from_sibling = NULL;
1665 /* if some parent is not visible start from the next sibling */
1667 if (!is_visible( win )) return 0;
1668 for (ptr = from_child; ptr; ptr = ptr->parent)
1670 if (!(ptr->style & WS_VISIBLE) || (ptr->style & WS_MINIMIZE)) from_sibling = ptr;
1671 if (ptr == win) break;
1674 /* non-client painting must be delayed if one of the parents is going to
1675 * be repainted and doesn't clip children */
1677 if ((flags & UPDATE_NONCLIENT) && !(flags & (UPDATE_PAINT|UPDATE_INTERNALPAINT)))
1679 for (ptr = win->parent; ptr; ptr = ptr->parent)
1681 if (!(ptr->style & WS_CLIPCHILDREN) && win_needs_repaint( ptr ))
1682 return 0;
1684 if (from_child && !(flags & UPDATE_ALLCHILDREN))
1686 for (ptr = from_sibling ? from_sibling : from_child; ptr; ptr = ptr->parent)
1688 if (!(ptr->style & WS_CLIPCHILDREN) && win_needs_repaint( ptr )) from_sibling = ptr;
1689 if (ptr == win) break;
1695 /* check window itself (only if not restarting from a child) */
1697 if (!from_child)
1699 if ((ret = get_update_flags( win, flags )))
1701 *child = win;
1702 return ret;
1704 from_child = win;
1707 /* now check children */
1709 if (flags & UPDATE_NOCHILDREN) return 0;
1710 if (!from_sibling)
1712 if ((ret = get_child_update_flags( from_child, NULL, flags, child ))) return ret;
1713 from_sibling = from_child;
1716 /* then check siblings and parent siblings */
1718 while (from_sibling->parent && from_sibling != win)
1720 if ((ret = get_child_update_flags( from_sibling->parent, from_sibling, flags, child )))
1721 return ret;
1722 from_sibling = from_sibling->parent;
1724 return 0;
1728 /* expose the areas revealed by a vis region change on the window parent */
1729 /* returns the region exposed on the window itself (in client coordinates) */
1730 static struct region *expose_window( struct window *win, const rectangle_t *old_window_rect,
1731 struct region *old_vis_rgn, int zorder_changed )
1733 struct region *new_vis_rgn, *exposed_rgn;
1734 int is_composited = is_parent_composited( win );
1736 if (!(new_vis_rgn = get_visible_region( win, DCX_WINDOW ))) return NULL;
1738 if (is_composited && !zorder_changed &&
1739 is_rect_equal( old_window_rect, &win->window_rect ) &&
1740 is_region_equal( old_vis_rgn, new_vis_rgn ))
1742 free_region( new_vis_rgn );
1743 return NULL;
1746 if ((exposed_rgn = create_empty_region()))
1748 if ((is_composited ? union_region( exposed_rgn, new_vis_rgn, old_vis_rgn )
1749 : subtract_region( exposed_rgn, new_vis_rgn, old_vis_rgn )) &&
1750 !is_region_empty( exposed_rgn ))
1752 /* make it relative to the new client area */
1753 offset_region( exposed_rgn, win->window_rect.left - win->client_rect.left,
1754 win->window_rect.top - win->client_rect.top );
1756 else
1758 free_region( exposed_rgn );
1759 exposed_rgn = NULL;
1763 if (win->parent && !is_desktop_window( win->parent ))
1765 /* make it relative to the old window pos for subtracting */
1766 offset_region( new_vis_rgn, win->window_rect.left - old_window_rect->left,
1767 win->window_rect.top - old_window_rect->top );
1769 if (is_region_empty( old_vis_rgn ) ||
1770 (is_composited ? union_region( new_vis_rgn, old_vis_rgn, new_vis_rgn )
1771 : subtract_region( new_vis_rgn, old_vis_rgn, new_vis_rgn )))
1773 if (!is_region_empty( new_vis_rgn ))
1775 /* make it relative to parent */
1776 offset_region( new_vis_rgn, old_window_rect->left, old_window_rect->top );
1777 redraw_window( win->parent, new_vis_rgn, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
1781 free_region( new_vis_rgn );
1782 return exposed_rgn;
1786 /* set the window and client rectangles, updating the update region if necessary */
1787 static void set_window_pos( struct window *win, struct window *previous,
1788 unsigned int swp_flags, const rectangle_t *window_rect,
1789 const rectangle_t *client_rect, const rectangle_t *visible_rect,
1790 const rectangle_t *surface_rect, const rectangle_t *valid_rect )
1792 struct region *old_vis_rgn = NULL, *exposed_rgn = NULL;
1793 const rectangle_t old_window_rect = win->window_rect;
1794 const rectangle_t old_visible_rect = win->visible_rect;
1795 const rectangle_t old_client_rect = win->client_rect;
1796 rectangle_t rect;
1797 int client_changed, frame_changed;
1798 int visible = (win->style & WS_VISIBLE) || (swp_flags & SWP_SHOWWINDOW);
1799 int zorder_changed = 0;
1801 if (win->parent && !is_visible( win->parent )) visible = 0;
1803 if (visible && !(old_vis_rgn = get_visible_region( win, DCX_WINDOW ))) return;
1805 /* set the new window info before invalidating anything */
1807 win->window_rect = *window_rect;
1808 win->visible_rect = *visible_rect;
1809 win->surface_rect = *surface_rect;
1810 win->client_rect = *client_rect;
1811 if (!(swp_flags & SWP_NOZORDER) && win->parent) zorder_changed |= link_window( win, previous );
1812 if (swp_flags & SWP_SHOWWINDOW) win->style |= WS_VISIBLE;
1813 else if (swp_flags & SWP_HIDEWINDOW) win->style &= ~WS_VISIBLE;
1815 /* keep children at the same position relative to top right corner when the parent is mirrored */
1816 if (win->ex_style & WS_EX_LAYOUTRTL)
1818 struct window *child;
1819 int old_size = old_client_rect.right - old_client_rect.left;
1820 int new_size = win->client_rect.right - win->client_rect.left;
1822 if (old_size != new_size) LIST_FOR_EACH_ENTRY( child, &win->children, struct window, entry )
1824 offset_rect( &child->window_rect, new_size - old_size, 0 );
1825 offset_rect( &child->visible_rect, new_size - old_size, 0 );
1826 offset_rect( &child->surface_rect, new_size - old_size, 0 );
1827 offset_rect( &child->client_rect, new_size - old_size, 0 );
1831 /* reset cursor clip rectangle when the desktop changes size */
1832 if (win == win->desktop->top_window) set_clip_rectangle( win->desktop, NULL, SET_CURSOR_NOCLIP, 1 );
1834 /* if the window is not visible, everything is easy */
1835 if (!visible) return;
1837 /* expose anything revealed by the change */
1839 if (!(swp_flags & SWP_NOREDRAW))
1840 exposed_rgn = expose_window( win, &old_window_rect, old_vis_rgn, zorder_changed );
1842 if (!(win->style & WS_VISIBLE))
1844 /* clear the update region since the window is no longer visible */
1845 validate_whole_window( win );
1846 validate_children( win );
1847 goto done;
1850 /* crop update region to the new window rect */
1852 if (win->update_region)
1854 if (get_window_visible_rect( win, &rect, 1 ))
1856 struct region *tmp = create_empty_region();
1857 if (tmp)
1859 set_region_rect( tmp, &rect );
1860 if (intersect_region( tmp, win->update_region, tmp ))
1861 set_update_region( win, tmp );
1862 else
1863 free_region( tmp );
1866 else set_update_region( win, NULL ); /* visible rect is empty */
1869 /* crop children regions to the new window rect */
1871 if (get_window_visible_rect( win, &rect, 0 ))
1873 /* map to client coords */
1874 offset_rect( &rect, win->window_rect.left - win->client_rect.left,
1875 win->window_rect.top - win->client_rect.top );
1876 crop_children_update_region( win, &rect );
1878 else crop_children_update_region( win, NULL );
1880 if (swp_flags & SWP_NOREDRAW) goto done; /* do not repaint anything */
1882 /* expose the whole non-client area if it changed in any way */
1884 if (swp_flags & SWP_NOCOPYBITS)
1886 frame_changed = ((swp_flags & SWP_FRAMECHANGED) ||
1887 memcmp( window_rect, &old_window_rect, sizeof(old_window_rect) ) ||
1888 memcmp( visible_rect, &old_visible_rect, sizeof(old_visible_rect) ));
1889 client_changed = memcmp( client_rect, &old_client_rect, sizeof(old_client_rect) );
1891 else
1893 /* assume the bits have been moved to follow the window rect */
1894 int x_offset = window_rect->left - old_window_rect.left;
1895 int y_offset = window_rect->top - old_window_rect.top;
1896 frame_changed = ((swp_flags & SWP_FRAMECHANGED) ||
1897 window_rect->right - old_window_rect.right != x_offset ||
1898 window_rect->bottom - old_window_rect.bottom != y_offset ||
1899 visible_rect->left - old_visible_rect.left != x_offset ||
1900 visible_rect->right - old_visible_rect.right != x_offset ||
1901 visible_rect->top - old_visible_rect.top != y_offset ||
1902 visible_rect->bottom - old_visible_rect.bottom != y_offset);
1903 client_changed = (client_rect->left - old_client_rect.left != x_offset ||
1904 client_rect->right - old_client_rect.right != x_offset ||
1905 client_rect->top - old_client_rect.top != y_offset ||
1906 client_rect->bottom - old_client_rect.bottom != y_offset ||
1907 memcmp( valid_rect, client_rect, sizeof(*client_rect) ));
1910 if (frame_changed || client_changed)
1912 struct region *win_rgn = old_vis_rgn; /* reuse previous region */
1914 set_region_rect( win_rgn, window_rect );
1915 if (!is_rect_empty( valid_rect ))
1917 /* subtract the valid portion of client rect from the total region */
1918 struct region *tmp = create_empty_region();
1919 if (tmp)
1921 set_region_rect( tmp, valid_rect );
1922 /* subtract update region since invalid parts of the valid rect won't be copied */
1923 if (win->update_region)
1925 offset_region( tmp, -window_rect->left, -window_rect->top );
1926 subtract_region( tmp, tmp, win->update_region );
1927 offset_region( tmp, window_rect->left, window_rect->top );
1929 if (subtract_region( tmp, win_rgn, tmp )) win_rgn = tmp;
1930 else free_region( tmp );
1933 if (!is_desktop_window(win))
1934 offset_region( win_rgn, -client_rect->left, -client_rect->top );
1935 if (exposed_rgn)
1937 union_region( exposed_rgn, exposed_rgn, win_rgn );
1938 if (win_rgn != old_vis_rgn) free_region( win_rgn );
1940 else
1942 exposed_rgn = win_rgn;
1943 if (win_rgn == old_vis_rgn) old_vis_rgn = NULL;
1947 if (exposed_rgn)
1948 redraw_window( win, exposed_rgn, 1, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
1950 done:
1951 if (old_vis_rgn) free_region( old_vis_rgn );
1952 if (exposed_rgn) free_region( exposed_rgn );
1953 clear_error(); /* we ignore out of memory errors once the new rects have been set */
1957 /* set the window region, updating the update region if necessary */
1958 static void set_window_region( struct window *win, struct region *region, int redraw )
1960 struct region *old_vis_rgn = NULL, *exposed_rgn;
1962 /* no need to redraw if window is not visible */
1963 if (redraw && !is_visible( win )) redraw = 0;
1965 if (redraw) old_vis_rgn = get_visible_region( win, DCX_WINDOW );
1967 if (win->win_region) free_region( win->win_region );
1968 win->win_region = region;
1970 /* expose anything revealed by the change */
1971 if (old_vis_rgn && ((exposed_rgn = expose_window( win, &win->window_rect, old_vis_rgn, 0 ))))
1973 redraw_window( win, exposed_rgn, 1, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
1974 free_region( exposed_rgn );
1977 if (old_vis_rgn) free_region( old_vis_rgn );
1978 clear_error(); /* we ignore out of memory errors since the region has been set */
1982 /* destroy a window */
1983 void free_window_handle( struct window *win )
1985 struct window *child, *next;
1987 assert( win->handle );
1989 /* hide the window */
1990 if (is_visible(win))
1992 struct region *vis_rgn = get_visible_region( win, DCX_WINDOW );
1993 win->style &= ~WS_VISIBLE;
1994 if (vis_rgn)
1996 struct region *exposed_rgn = expose_window( win, &win->window_rect, vis_rgn, 0 );
1997 if (exposed_rgn) free_region( exposed_rgn );
1998 free_region( vis_rgn );
2000 validate_whole_window( win );
2001 validate_children( win );
2004 /* destroy all children */
2005 LIST_FOR_EACH_ENTRY_SAFE( child, next, &win->children, struct window, entry )
2007 if (!child->handle) continue;
2008 if (!win->thread || !child->thread || win->thread == child->thread)
2009 free_window_handle( child );
2010 else
2011 send_notify_message( child->handle, WM_WINE_DESTROYWINDOW, 0, 0 );
2013 LIST_FOR_EACH_ENTRY_SAFE( child, next, &win->children, struct window, entry )
2015 if (!child->handle) continue;
2016 if (!win->thread || !child->thread || win->thread == child->thread)
2017 free_window_handle( child );
2018 else
2019 send_notify_message( child->handle, WM_WINE_DESTROYWINDOW, 0, 0 );
2022 /* reset global window pointers, if the corresponding window is destroyed */
2023 if (win == shell_window) shell_window = NULL;
2024 if (win == shell_listview) shell_listview = NULL;
2025 if (win == progman_window) progman_window = NULL;
2026 if (win == taskman_window) taskman_window = NULL;
2027 free_hotkeys( win->desktop, win->handle );
2028 cleanup_clipboard_window( win->desktop, win->handle );
2029 destroy_properties( win );
2030 if (is_desktop_window(win))
2032 struct desktop *desktop = win->desktop;
2033 assert( desktop->top_window == win || desktop->msg_window == win );
2034 if (desktop->top_window == win) desktop->top_window = NULL;
2035 else desktop->msg_window = NULL;
2037 else if (is_desktop_window( win->parent ))
2039 post_message( win->parent->handle, WM_PARENTNOTIFY, WM_DESTROY, win->handle );
2042 detach_window_thread( win );
2044 if (win->parent) set_parent_window( win, NULL );
2045 free_user_handle( win->handle );
2046 win->handle = 0;
2047 release_object( win );
2051 /* create a window */
2052 DECL_HANDLER(create_window)
2054 struct window *win, *parent = NULL, *owner = NULL;
2055 struct unicode_str cls_name = get_req_unicode_str();
2056 atom_t atom;
2058 reply->handle = 0;
2059 if (req->parent)
2061 if (!(parent = get_window( req->parent ))) return;
2062 if (is_orphan_window( parent ))
2064 set_error( STATUS_INVALID_PARAMETER );
2065 return;
2069 if (req->owner)
2071 if (!(owner = get_window( req->owner ))) return;
2072 if (is_desktop_window(owner)) owner = NULL;
2073 else if (parent && !is_desktop_window(parent))
2075 /* an owned window must be created as top-level */
2076 set_error( STATUS_ACCESS_DENIED );
2077 return;
2079 else /* owner must be a top-level window */
2080 while ((owner->style & (WS_POPUP|WS_CHILD)) == WS_CHILD && !is_desktop_window(owner->parent))
2081 owner = owner->parent;
2084 atom = cls_name.len ? find_global_atom( NULL, &cls_name ) : req->atom;
2086 if (!(win = create_window( parent, owner, atom, req->instance ))) return;
2088 if (parent && !is_desktop_window( parent ))
2090 win->dpi_awareness = parent->dpi_awareness;
2091 win->dpi = parent->dpi;
2093 else if (!parent || req->awareness != DPI_AWARENESS_PER_MONITOR_AWARE)
2095 win->dpi_awareness = req->awareness;
2096 win->dpi = req->dpi;
2098 win->style = req->style;
2099 win->ex_style = req->ex_style;
2101 reply->handle = win->handle;
2102 reply->parent = win->parent ? win->parent->handle : 0;
2103 reply->owner = win->owner;
2104 reply->extra = win->nb_extra_bytes;
2105 reply->dpi = win->dpi;
2106 reply->awareness = win->dpi_awareness;
2107 reply->class_ptr = get_class_client_ptr( win->class );
2111 /* set the parent of a window */
2112 DECL_HANDLER(set_parent)
2114 struct window *win, *parent = NULL;
2116 if (!(win = get_window( req->handle ))) return;
2117 if (req->parent && !(parent = get_window( req->parent ))) return;
2119 if (is_desktop_window(win) || is_orphan_window( win ) || (parent && is_orphan_window( parent )))
2121 set_error( STATUS_INVALID_PARAMETER );
2122 return;
2124 reply->old_parent = win->parent->handle;
2125 reply->full_parent = parent ? parent->handle : 0;
2126 set_parent_window( win, parent );
2127 reply->dpi = win->dpi;
2128 reply->awareness = win->dpi_awareness;
2132 /* destroy a window */
2133 DECL_HANDLER(destroy_window)
2135 struct window *win;
2137 if (!req->handle)
2139 destroy_thread_windows( current );
2141 else if ((win = get_window( req->handle )))
2143 if (!is_desktop_window(win)) free_window_handle( win );
2144 else if (win->thread == current) detach_window_thread( win );
2145 else set_error( STATUS_ACCESS_DENIED );
2150 /* retrieve the desktop window for the current thread */
2151 DECL_HANDLER(get_desktop_window)
2153 struct desktop *desktop = get_thread_desktop( current, 0 );
2155 if (!desktop) return;
2157 if (!desktop->top_window && req->force) /* create it */
2159 if ((desktop->top_window = create_window( NULL, NULL, DESKTOP_ATOM, 0 )))
2161 detach_window_thread( desktop->top_window );
2162 desktop->top_window->style = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
2166 if (!desktop->msg_window && req->force) /* create it */
2168 static const WCHAR messageW[] = {'M','e','s','s','a','g','e'};
2169 static const struct unicode_str name = { messageW, sizeof(messageW) };
2170 atom_t atom = add_global_atom( NULL, &name );
2171 if (atom && (desktop->msg_window = create_window( NULL, NULL, atom, 0 )))
2173 detach_window_thread( desktop->msg_window );
2174 desktop->msg_window->style = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
2178 reply->top_window = desktop->top_window ? desktop->top_window->handle : 0;
2179 reply->msg_window = desktop->msg_window ? desktop->msg_window->handle : 0;
2180 release_object( desktop );
2184 /* set a window owner */
2185 DECL_HANDLER(set_window_owner)
2187 struct window *win = get_window( req->handle );
2188 struct window *owner = NULL, *ptr;
2190 if (!win) return;
2191 if (req->owner && !(owner = get_window( req->owner ))) return;
2192 if (is_desktop_window(win))
2194 set_error( STATUS_ACCESS_DENIED );
2195 return;
2198 /* make sure owner is not a successor of window */
2199 for (ptr = owner; ptr; ptr = ptr->owner ? get_window( ptr->owner ) : NULL)
2201 if (ptr == win)
2203 set_error( STATUS_INVALID_PARAMETER );
2204 return;
2208 reply->prev_owner = win->owner;
2209 reply->full_owner = win->owner = owner ? owner->handle : 0;
2213 /* get information from a window handle */
2214 DECL_HANDLER(get_window_info)
2216 struct window *win = get_window( req->handle );
2218 if (!win) return;
2220 reply->full_handle = win->handle;
2221 reply->last_active = win->handle;
2222 reply->is_unicode = win->is_unicode;
2223 reply->awareness = win->dpi_awareness;
2224 reply->dpi = win->dpi ? win->dpi : get_monitor_dpi( win );
2225 if (get_user_object( win->last_active, USER_WINDOW )) reply->last_active = win->last_active;
2226 if (win->thread)
2228 reply->tid = get_thread_id( win->thread );
2229 reply->pid = get_process_id( win->thread->process );
2230 reply->atom = win->class ? get_class_atom( win->class ) : DESKTOP_ATOM;
2235 /* set some information in a window */
2236 DECL_HANDLER(set_window_info)
2238 struct window *win = get_window( req->handle );
2240 if (!win) return;
2241 if (req->flags && is_desktop_window(win) && win->thread != current)
2243 set_error( STATUS_ACCESS_DENIED );
2244 return;
2246 if (req->extra_size > sizeof(req->extra_value) ||
2247 req->extra_offset < -1 ||
2248 req->extra_offset > win->nb_extra_bytes - (int)req->extra_size)
2250 set_win32_error( ERROR_INVALID_INDEX );
2251 return;
2253 if (req->extra_offset != -1)
2255 memcpy( &reply->old_extra_value, win->extra_bytes + req->extra_offset, req->extra_size );
2257 else if (req->flags & SET_WIN_EXTRA)
2259 set_win32_error( ERROR_INVALID_INDEX );
2260 return;
2262 reply->old_style = win->style;
2263 reply->old_ex_style = win->ex_style;
2264 reply->old_id = win->id;
2265 reply->old_instance = win->instance;
2266 reply->old_user_data = win->user_data;
2267 if (req->flags & SET_WIN_STYLE) win->style = req->style;
2268 if (req->flags & SET_WIN_EXSTYLE)
2270 /* WS_EX_TOPMOST can only be changed for unlinked windows */
2271 if (!win->is_linked) win->ex_style = req->ex_style;
2272 else win->ex_style = (req->ex_style & ~WS_EX_TOPMOST) | (win->ex_style & WS_EX_TOPMOST);
2273 if (!(win->ex_style & WS_EX_LAYERED)) win->is_layered = 0;
2275 if (req->flags & SET_WIN_ID) win->id = req->extra_value;
2276 if (req->flags & SET_WIN_INSTANCE) win->instance = req->instance;
2277 if (req->flags & SET_WIN_UNICODE) win->is_unicode = req->is_unicode;
2278 if (req->flags & SET_WIN_USERDATA) win->user_data = req->user_data;
2279 if (req->flags & SET_WIN_EXTRA) memcpy( win->extra_bytes + req->extra_offset,
2280 &req->extra_value, req->extra_size );
2282 /* changing window style triggers a non-client paint */
2283 if (req->flags & SET_WIN_STYLE) win->paint_flags |= PAINT_NONCLIENT;
2287 /* get a list of the window parents, up to the root of the tree */
2288 DECL_HANDLER(get_window_parents)
2290 struct window *ptr, *win = get_window( req->handle );
2291 int total = 0;
2292 user_handle_t *data;
2293 data_size_t len;
2295 if (win) for (ptr = win->parent; ptr; ptr = ptr->parent) total++;
2297 reply->count = total;
2298 len = min( get_reply_max_size(), total * sizeof(user_handle_t) );
2299 if (len && ((data = set_reply_data_size( len ))))
2301 for (ptr = win->parent; ptr && len; ptr = ptr->parent, len -= sizeof(*data))
2302 *data++ = ptr->handle;
2307 /* get a list of the window children */
2308 DECL_HANDLER(get_window_children)
2310 struct window *parent = NULL;
2311 unsigned int total;
2312 user_handle_t *data;
2313 data_size_t len;
2314 struct unicode_str cls_name = get_req_unicode_str();
2315 atom_t atom = req->atom;
2316 struct desktop *desktop = NULL;
2318 if (cls_name.len && !(atom = find_global_atom( NULL, &cls_name ))) return;
2320 if (req->desktop)
2322 if (!(desktop = get_desktop_obj( current->process, req->desktop, DESKTOP_ENUMERATE ))) return;
2323 parent = desktop->top_window;
2325 else
2327 if (req->parent && !(parent = get_window( req->parent ))) return;
2328 if (!parent && !(desktop = get_thread_desktop( current, 0 ))) return;
2331 if (parent)
2332 total = get_children_windows( parent, atom, req->tid, NULL, 0 );
2333 else
2334 total = get_children_windows( desktop->top_window, atom, req->tid, NULL, 0 ) +
2335 get_children_windows( desktop->msg_window, atom, req->tid, NULL, 0 );
2337 reply->count = total;
2338 len = min( get_reply_max_size(), total * sizeof(user_handle_t) );
2339 if (len && ((data = set_reply_data_size( len ))))
2341 if (parent) get_children_windows( parent, atom, req->tid, data, len / sizeof(user_handle_t) );
2342 else
2344 total = get_children_windows( desktop->top_window, atom, req->tid,
2345 data, len / sizeof(user_handle_t) );
2346 data += total;
2347 len -= total * sizeof(user_handle_t);
2348 if (len >= sizeof(user_handle_t))
2349 get_children_windows( desktop->msg_window, atom, req->tid,
2350 data, len / sizeof(user_handle_t) );
2353 if (desktop) release_object( desktop );
2357 /* get a list of the window children that contain a given point */
2358 DECL_HANDLER(get_window_children_from_point)
2360 struct user_handle_array array;
2361 struct window *parent = get_window( req->parent );
2362 data_size_t len;
2364 if (!parent) return;
2366 array.handles = NULL;
2367 array.count = 0;
2368 array.total = 0;
2369 if (!all_windows_from_point( parent, req->x, req->y, req->dpi, &array )) return;
2371 reply->count = array.count;
2372 len = min( get_reply_max_size(), array.count * sizeof(user_handle_t) );
2373 if (len) set_reply_data_ptr( array.handles, len );
2374 else free( array.handles );
2378 /* get window tree information from a window handle */
2379 DECL_HANDLER(get_window_tree)
2381 struct window *ptr, *win = get_window( req->handle );
2383 if (!win) return;
2385 reply->parent = 0;
2386 reply->owner = 0;
2387 reply->next_sibling = 0;
2388 reply->prev_sibling = 0;
2389 reply->first_sibling = 0;
2390 reply->last_sibling = 0;
2391 reply->first_child = 0;
2392 reply->last_child = 0;
2394 if (win->parent)
2396 struct window *parent = win->parent;
2397 reply->parent = parent->handle;
2398 reply->owner = win->owner;
2399 if (win->is_linked)
2401 if ((ptr = get_next_window( win ))) reply->next_sibling = ptr->handle;
2402 if ((ptr = get_prev_window( win ))) reply->prev_sibling = ptr->handle;
2404 if ((ptr = get_first_child( parent ))) reply->first_sibling = ptr->handle;
2405 if ((ptr = get_last_child( parent ))) reply->last_sibling = ptr->handle;
2407 if ((ptr = get_first_child( win ))) reply->first_child = ptr->handle;
2408 if ((ptr = get_last_child( win ))) reply->last_child = ptr->handle;
2412 /* set the position and Z order of a window */
2413 DECL_HANDLER(set_window_pos)
2415 rectangle_t window_rect, client_rect, visible_rect, surface_rect, valid_rect;
2416 const rectangle_t *extra_rects = get_req_data();
2417 struct window *previous = NULL;
2418 struct window *top, *win = get_window( req->handle );
2419 unsigned int flags = req->swp_flags;
2421 if (!win) return;
2422 if (!win->parent) flags |= SWP_NOZORDER; /* no Z order for the desktop */
2424 if (!(flags & SWP_NOZORDER))
2426 switch ((int)req->previous)
2428 case 0: /* HWND_TOP */
2429 previous = WINPTR_TOP;
2430 break;
2431 case 1: /* HWND_BOTTOM */
2432 previous = WINPTR_BOTTOM;
2433 break;
2434 case -1: /* HWND_TOPMOST */
2435 previous = WINPTR_TOPMOST;
2436 break;
2437 case -2: /* HWND_NOTOPMOST */
2438 previous = WINPTR_NOTOPMOST;
2439 break;
2440 default:
2441 if (!(previous = get_window( req->previous ))) return;
2442 /* previous must be a sibling */
2443 if (previous->parent != win->parent)
2445 set_error( STATUS_INVALID_PARAMETER );
2446 return;
2448 break;
2450 if (previous == win) flags |= SWP_NOZORDER; /* nothing to do */
2453 /* windows that use UpdateLayeredWindow don't trigger repaints */
2454 if ((win->ex_style & WS_EX_LAYERED) && !win->is_layered) flags |= SWP_NOREDRAW;
2456 /* window rectangle must be ordered properly */
2457 if (req->window.right < req->window.left || req->window.bottom < req->window.top)
2459 set_error( STATUS_INVALID_PARAMETER );
2460 return;
2463 window_rect = req->window;
2464 client_rect = req->client;
2465 if (get_req_data_size() >= sizeof(rectangle_t)) visible_rect = extra_rects[0];
2466 else visible_rect = window_rect;
2467 if (get_req_data_size() >= 2 * sizeof(rectangle_t)) surface_rect = extra_rects[1];
2468 else surface_rect = visible_rect;
2469 if (get_req_data_size() >= 3 * sizeof(rectangle_t)) valid_rect = extra_rects[2];
2470 else valid_rect = empty_rect;
2471 if (win->parent && win->parent->ex_style & WS_EX_LAYOUTRTL)
2473 mirror_rect( &win->parent->client_rect, &window_rect );
2474 mirror_rect( &win->parent->client_rect, &visible_rect );
2475 mirror_rect( &win->parent->client_rect, &client_rect );
2476 mirror_rect( &win->parent->client_rect, &surface_rect );
2477 mirror_rect( &win->parent->client_rect, &valid_rect );
2480 win->paint_flags = (win->paint_flags & ~PAINT_CLIENT_FLAGS) | (req->paint_flags & PAINT_CLIENT_FLAGS);
2481 if (win->paint_flags & PAINT_HAS_PIXEL_FORMAT) update_pixel_format_flags( win );
2483 set_window_pos( win, previous, flags, &window_rect, &client_rect,
2484 &visible_rect, &surface_rect, &valid_rect );
2486 reply->new_style = win->style;
2487 reply->new_ex_style = win->ex_style;
2489 top = get_top_clipping_window( win );
2490 if (is_visible( top ) && (top->paint_flags & PAINT_HAS_SURFACE))
2492 reply->surface_win = top->handle;
2493 reply->needs_update = !!(top->paint_flags & (PAINT_HAS_PIXEL_FORMAT | PAINT_PIXEL_FORMAT_CHILD));
2498 /* get the window and client rectangles of a window */
2499 DECL_HANDLER(get_window_rectangles)
2501 struct window *win = get_window( req->handle );
2503 if (!win) return;
2505 reply->window = win->window_rect;
2506 reply->client = win->client_rect;
2508 switch (req->relative)
2510 case COORDS_CLIENT:
2511 offset_rect( &reply->window, -win->client_rect.left, -win->client_rect.top );
2512 offset_rect( &reply->client, -win->client_rect.left, -win->client_rect.top );
2513 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_rect( &win->client_rect, &reply->window );
2514 break;
2515 case COORDS_WINDOW:
2516 offset_rect( &reply->window, -win->window_rect.left, -win->window_rect.top );
2517 offset_rect( &reply->client, -win->window_rect.left, -win->window_rect.top );
2518 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_rect( &win->window_rect, &reply->client );
2519 break;
2520 case COORDS_PARENT:
2521 if (win->parent && win->parent->ex_style & WS_EX_LAYOUTRTL)
2523 mirror_rect( &win->parent->client_rect, &reply->window );
2524 mirror_rect( &win->parent->client_rect, &reply->client );
2526 break;
2527 case COORDS_SCREEN:
2528 client_to_screen_rect( win->parent, &reply->window );
2529 client_to_screen_rect( win->parent, &reply->client );
2530 break;
2531 default:
2532 set_error( STATUS_INVALID_PARAMETER );
2533 break;
2535 map_dpi_rect( win, &reply->window, win->dpi, req->dpi );
2536 map_dpi_rect( win, &reply->client, win->dpi, req->dpi );
2540 /* get the window text */
2541 DECL_HANDLER(get_window_text)
2543 struct window *win = get_window( req->handle );
2545 if (win && win->text_len)
2547 reply->length = win->text_len / sizeof(WCHAR);
2548 set_reply_data( win->text, min( win->text_len, get_reply_max_size() ));
2553 /* set the window text */
2554 DECL_HANDLER(set_window_text)
2556 data_size_t len;
2557 WCHAR *text = NULL;
2558 struct window *win = get_window( req->handle );
2560 if (!win) return;
2561 len = (get_req_data_size() / sizeof(WCHAR)) * sizeof(WCHAR);
2562 if (len && !(text = memdup( get_req_data(), len ))) return;
2563 free( win->text );
2564 win->text = text;
2565 win->text_len = len;
2569 /* get the coordinates offset between two windows */
2570 DECL_HANDLER(get_windows_offset)
2572 struct window *win;
2573 int x, y, mirror_from = 0, mirror_to = 0;
2575 reply->x = reply->y = 0;
2576 if (req->from)
2578 if (!(win = get_window( req->from ))) return;
2579 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_from = 1;
2580 x = mirror_from ? win->client_rect.right - win->client_rect.left : 0;
2581 y = 0;
2582 client_to_screen( win, &x, &y );
2583 map_dpi_point( win, &x, &y, win->dpi, req->dpi );
2584 reply->x += x;
2585 reply->y += y;
2587 if (req->to)
2589 if (!(win = get_window( req->to ))) return;
2590 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_to = 1;
2591 x = mirror_to ? win->client_rect.right - win->client_rect.left : 0;
2592 y = 0;
2593 client_to_screen( win, &x, &y );
2594 map_dpi_point( win, &x, &y, win->dpi, req->dpi );
2595 reply->x -= x;
2596 reply->y -= y;
2598 if (mirror_from) reply->x = -reply->x;
2599 reply->mirror = mirror_from ^ mirror_to;
2603 /* get the visible region of a window */
2604 DECL_HANDLER(get_visible_region)
2606 struct region *region;
2607 struct window *top, *win = get_window( req->window );
2609 if (!win) return;
2611 top = get_top_clipping_window( win );
2612 if ((region = get_visible_region( win, req->flags )))
2614 rectangle_t *data;
2615 map_win_region_to_screen( win, region );
2616 data = get_region_data_and_free( region, get_reply_max_size(), &reply->total_size );
2617 if (data) set_reply_data_ptr( data, reply->total_size );
2619 reply->top_win = top->handle;
2620 reply->top_rect = top->surface_rect;
2622 if (!is_desktop_window(win))
2624 reply->win_rect = (req->flags & DCX_WINDOW) ? win->window_rect : win->client_rect;
2625 client_to_screen_rect( top->parent, &reply->top_rect );
2626 client_to_screen_rect( win->parent, &reply->win_rect );
2628 else
2630 reply->win_rect.left = 0;
2631 reply->win_rect.top = 0;
2632 reply->win_rect.right = win->client_rect.right - win->client_rect.left;
2633 reply->win_rect.bottom = win->client_rect.bottom - win->client_rect.top;
2635 reply->paint_flags = win->paint_flags & PAINT_CLIENT_FLAGS;
2639 /* get the surface visible region of a window */
2640 DECL_HANDLER(get_surface_region)
2642 struct region *region;
2643 struct window *win = get_window( req->window );
2645 if (!win || !is_visible( win )) return;
2647 if ((region = get_surface_region( win )))
2649 rectangle_t *data = get_region_data_and_free( region, get_reply_max_size(), &reply->total_size );
2650 if (data) set_reply_data_ptr( data, reply->total_size );
2652 reply->visible_rect = win->visible_rect;
2656 /* get the window region */
2657 DECL_HANDLER(get_window_region)
2659 rectangle_t *data;
2660 struct window *win = get_window( req->window );
2662 if (!win) return;
2663 if (!win->win_region) return;
2665 if (win->ex_style & WS_EX_LAYOUTRTL)
2667 struct region *region = create_empty_region();
2669 if (!region) return;
2670 if (!copy_region( region, win->win_region ))
2672 free_region( region );
2673 return;
2675 mirror_region( &win->window_rect, region );
2676 data = get_region_data_and_free( region, get_reply_max_size(), &reply->total_size );
2678 else data = get_region_data( win->win_region, get_reply_max_size(), &reply->total_size );
2680 if (data) set_reply_data_ptr( data, reply->total_size );
2684 /* set the window region */
2685 DECL_HANDLER(set_window_region)
2687 struct region *region = NULL;
2688 struct window *win = get_window( req->window );
2690 if (!win) return;
2692 if (get_req_data_size()) /* no data means remove the region completely */
2694 if (!(region = create_region_from_req_data( get_req_data(), get_req_data_size() )))
2695 return;
2696 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_region( &win->window_rect, region );
2698 set_window_region( win, region, req->redraw );
2702 /* get a window update region */
2703 DECL_HANDLER(get_update_region)
2705 rectangle_t *data;
2706 unsigned int flags = req->flags;
2707 struct window *from_child = NULL;
2708 struct window *win = get_window( req->window );
2710 reply->flags = 0;
2711 if (!win) return;
2713 if (req->from_child)
2715 struct window *ptr;
2717 if (!(from_child = get_window( req->from_child ))) return;
2719 /* make sure from_child is a child of win */
2720 ptr = from_child;
2721 while (ptr && ptr != win) ptr = ptr->parent;
2722 if (!ptr)
2724 set_error( STATUS_INVALID_PARAMETER );
2725 return;
2729 if (flags & UPDATE_DELAYED_ERASE) /* this means that the previous call didn't erase */
2731 if (from_child) from_child->paint_flags |= PAINT_DELAYED_ERASE;
2732 else win->paint_flags |= PAINT_DELAYED_ERASE;
2735 reply->flags = get_window_update_flags( win, from_child, flags, &win );
2736 reply->child = win->handle;
2738 if (flags & UPDATE_NOREGION) return;
2740 if (win->update_region)
2742 /* convert update region to screen coordinates */
2743 struct region *region = create_empty_region();
2745 if (!region) return;
2746 if (!copy_region( region, win->update_region ))
2748 free_region( region );
2749 return;
2751 if ((flags & UPDATE_CLIPCHILDREN) && (win->style & WS_CLIPCHILDREN))
2752 clip_children( win, NULL, region, win->client_rect.left - win->window_rect.left,
2753 win->client_rect.top - win->window_rect.top );
2754 map_win_region_to_screen( win, region );
2755 if (!(data = get_region_data_and_free( region, get_reply_max_size(),
2756 &reply->total_size ))) return;
2757 set_reply_data_ptr( data, reply->total_size );
2760 if (reply->flags & (UPDATE_PAINT|UPDATE_INTERNALPAINT)) /* validate everything */
2762 validate_parents( win );
2763 validate_whole_window( win );
2765 else
2767 if (reply->flags & UPDATE_NONCLIENT) validate_non_client( win );
2768 if (reply->flags & UPDATE_ERASE)
2770 win->paint_flags &= ~(PAINT_ERASE | PAINT_DELAYED_ERASE);
2771 /* desktop window only gets erased, not repainted */
2772 if (is_desktop_window(win)) validate_whole_window( win );
2778 /* update the z order of a window so that a given rectangle is fully visible */
2779 DECL_HANDLER(update_window_zorder)
2781 rectangle_t tmp, rect = req->rect;
2782 struct window *ptr, *win = get_window( req->window );
2784 if (!win || !win->parent || !is_visible( win )) return; /* nothing to do */
2786 LIST_FOR_EACH_ENTRY( ptr, &win->parent->children, struct window, entry )
2788 if (ptr == win) break;
2789 if (!(ptr->style & WS_VISIBLE)) continue;
2790 if (ptr->ex_style & WS_EX_TRANSPARENT) continue;
2791 if (ptr->is_layered && (ptr->layered_flags & LWA_COLORKEY)) continue;
2792 tmp = rect;
2793 map_dpi_rect( win, &tmp, win->parent->dpi, win->dpi );
2794 if (!intersect_rect( &tmp, &tmp, &ptr->visible_rect )) continue;
2795 if (ptr->win_region)
2797 offset_rect( &tmp, -ptr->window_rect.left, -ptr->window_rect.top );
2798 if (!rect_in_region( ptr->win_region, &tmp )) continue;
2800 /* found a window obscuring the rectangle, now move win above this one */
2801 /* making sure to not violate the topmost rule */
2802 if (!(ptr->ex_style & WS_EX_TOPMOST) || (win->ex_style & WS_EX_TOPMOST))
2804 list_remove( &win->entry );
2805 list_add_before( &ptr->entry, &win->entry );
2807 break;
2812 /* mark parts of a window as needing a redraw */
2813 DECL_HANDLER(redraw_window)
2815 unsigned int flags = req->flags;
2816 struct region *region = NULL;
2817 struct window *win;
2819 if (!req->window)
2821 if (!(win = get_desktop_window( current ))) return;
2823 else
2825 if (!(win = get_window( req->window ))) return;
2826 if (is_desktop_window( win )) flags &= ~RDW_ALLCHILDREN;
2829 if (!is_visible( win )) return; /* nothing to do */
2831 if (flags & (RDW_VALIDATE|RDW_INVALIDATE))
2833 if (get_req_data_size()) /* no data means whole rectangle */
2835 if (!(region = create_region_from_req_data( get_req_data(), get_req_data_size() )))
2836 return;
2837 if (win->ex_style & WS_EX_LAYOUTRTL) mirror_region( &win->client_rect, region );
2841 redraw_window( win, region, (flags & RDW_INVALIDATE) && (flags & RDW_FRAME), flags );
2842 if (region) free_region( region );
2846 /* set a window property */
2847 DECL_HANDLER(set_window_property)
2849 struct unicode_str name = get_req_unicode_str();
2850 struct window *win = get_window( req->window );
2852 if (!win) return;
2854 if (name.len)
2856 atom_t atom = add_global_atom( NULL, &name );
2857 if (atom)
2859 set_property( win, atom, req->data, PROP_TYPE_STRING );
2860 release_global_atom( NULL, atom );
2863 else set_property( win, req->atom, req->data, PROP_TYPE_ATOM );
2867 /* remove a window property */
2868 DECL_HANDLER(remove_window_property)
2870 struct unicode_str name = get_req_unicode_str();
2871 struct window *win = get_window( req->window );
2873 if (win)
2875 atom_t atom = name.len ? find_global_atom( NULL, &name ) : req->atom;
2876 if (atom) reply->data = remove_property( win, atom );
2881 /* get a window property */
2882 DECL_HANDLER(get_window_property)
2884 struct unicode_str name = get_req_unicode_str();
2885 struct window *win = get_window( req->window );
2887 if (win)
2889 atom_t atom = name.len ? find_global_atom( NULL, &name ) : req->atom;
2890 if (atom) reply->data = get_property( win, atom );
2895 /* get the list of properties of a window */
2896 DECL_HANDLER(get_window_properties)
2898 property_data_t *data;
2899 int i, count, max = get_reply_max_size() / sizeof(*data);
2900 struct window *win = get_window( req->window );
2902 reply->total = 0;
2903 if (!win) return;
2905 for (i = count = 0; i < win->prop_inuse; i++)
2906 if (win->properties[i].type != PROP_TYPE_FREE) count++;
2907 reply->total = count;
2909 if (count > max) count = max;
2910 if (!count || !(data = set_reply_data_size( count * sizeof(*data) ))) return;
2912 for (i = 0; i < win->prop_inuse && count; i++)
2914 if (win->properties[i].type == PROP_TYPE_FREE) continue;
2915 data->atom = win->properties[i].atom;
2916 data->string = (win->properties[i].type == PROP_TYPE_STRING);
2917 data->data = win->properties[i].data;
2918 data++;
2919 count--;
2924 /* get the new window pointer for a global window, checking permissions */
2925 /* helper for set_global_windows request */
2926 static int get_new_global_window( struct window **win, user_handle_t handle )
2928 if (!handle)
2930 *win = NULL;
2931 return 1;
2933 else if (*win)
2935 set_error( STATUS_ACCESS_DENIED );
2936 return 0;
2938 *win = get_window( handle );
2939 return (*win != NULL);
2942 /* Set/get the global windows */
2943 DECL_HANDLER(set_global_windows)
2945 struct window *new_shell_window = shell_window;
2946 struct window *new_shell_listview = shell_listview;
2947 struct window *new_progman_window = progman_window;
2948 struct window *new_taskman_window = taskman_window;
2950 reply->old_shell_window = shell_window ? shell_window->handle : 0;
2951 reply->old_shell_listview = shell_listview ? shell_listview->handle : 0;
2952 reply->old_progman_window = progman_window ? progman_window->handle : 0;
2953 reply->old_taskman_window = taskman_window ? taskman_window->handle : 0;
2955 if (req->flags & SET_GLOBAL_SHELL_WINDOWS)
2957 if (!get_new_global_window( &new_shell_window, req->shell_window )) return;
2958 if (!get_new_global_window( &new_shell_listview, req->shell_listview )) return;
2960 if (req->flags & SET_GLOBAL_PROGMAN_WINDOW)
2962 if (!get_new_global_window( &new_progman_window, req->progman_window )) return;
2964 if (req->flags & SET_GLOBAL_TASKMAN_WINDOW)
2966 if (!get_new_global_window( &new_taskman_window, req->taskman_window )) return;
2968 shell_window = new_shell_window;
2969 shell_listview = new_shell_listview;
2970 progman_window = new_progman_window;
2971 taskman_window = new_taskman_window;
2974 /* retrieve layered info for a window */
2975 DECL_HANDLER(get_window_layered_info)
2977 struct window *win = get_window( req->handle );
2979 if (!win) return;
2981 if (win->is_layered)
2983 reply->color_key = win->color_key;
2984 reply->alpha = win->alpha;
2985 reply->flags = win->layered_flags;
2987 else set_win32_error( ERROR_INVALID_WINDOW_HANDLE );
2991 /* set layered info for a window */
2992 DECL_HANDLER(set_window_layered_info)
2994 struct window *win = get_window( req->handle );
2996 if (!win) return;
2998 if (win->ex_style & WS_EX_LAYERED)
3000 int was_layered = win->is_layered;
3002 if (req->flags & LWA_ALPHA) win->alpha = req->alpha;
3003 else if (!win->is_layered) win->alpha = 0; /* alpha init value is 0 */
3005 win->color_key = req->color_key;
3006 win->layered_flags = req->flags;
3007 win->is_layered = 1;
3008 /* repaint since we know now it's not going to use UpdateLayeredWindow */
3009 if (!was_layered) redraw_window( win, 0, 1, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3011 else set_win32_error( ERROR_INVALID_WINDOW_HANDLE );