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
22 #include "wine/port.h"
28 #define WIN32_NO_STATUS
42 /* a window property */
45 unsigned short type
; /* property type (see below) */
46 atom_t atom
; /* property atom */
47 lparam_t data
; /* property data (user-defined storage) */
52 PROP_TYPE_FREE
, /* free entry */
53 PROP_TYPE_STRING
, /* atom that was originally a string */
54 PROP_TYPE_ATOM
/* plain atom */
60 struct window
*parent
; /* parent window */
61 user_handle_t owner
; /* owner of this window */
62 struct list children
; /* list of children in Z-order */
63 struct list unlinked
; /* list of children not linked in the Z-order list */
64 struct list entry
; /* entry in parent's children list */
65 user_handle_t handle
; /* full handle for this window */
66 struct thread
*thread
; /* thread owning the window */
67 struct desktop
*desktop
; /* desktop that the window belongs to */
68 struct window_class
*class; /* window class */
69 atom_t atom
; /* class atom */
70 user_handle_t last_active
; /* last active popup */
71 rectangle_t window_rect
; /* window rectangle (relative to parent client area) */
72 rectangle_t visible_rect
; /* visible part of window rect (relative to parent client area) */
73 rectangle_t surface_rect
; /* window surface rectangle (relative to parent client area) */
74 rectangle_t client_rect
; /* client rectangle (relative to parent client area) */
75 struct region
*win_region
; /* region for shaped windows (relative to window rect) */
76 struct region
*update_region
; /* update region (relative to window rect) */
77 unsigned int style
; /* window style */
78 unsigned int ex_style
; /* window extended style */
79 unsigned int id
; /* window id */
80 mod_handle_t instance
; /* creator instance */
81 unsigned int is_unicode
: 1; /* ANSI or unicode */
82 unsigned int is_linked
: 1; /* is it linked into the parent z-order list? */
83 unsigned int is_layered
: 1; /* has layered info been set? */
84 unsigned int color_key
; /* color key for a layered window */
85 unsigned int alpha
; /* alpha value for a layered window */
86 unsigned int layered_flags
; /* flags for a layered window */
87 unsigned int dpi
; /* window DPI or 0 if per-monitor aware */
88 DPI_AWARENESS dpi_awareness
; /* DPI awareness mode */
89 lparam_t user_data
; /* user-specific data */
90 WCHAR
*text
; /* window caption text */
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
[1]; /* extra bytes storage */
99 /* flags that can be set by the client */
100 #define PAINT_HAS_SURFACE SET_WINPOS_PAINT_SURFACE
101 #define PAINT_HAS_PIXEL_FORMAT SET_WINPOS_PIXEL_FORMAT
102 #define PAINT_CLIENT_FLAGS (PAINT_HAS_SURFACE | PAINT_HAS_PIXEL_FORMAT)
103 /* flags only manipulated by the server */
104 #define PAINT_INTERNAL 0x0010 /* internal WM_PAINT pending */
105 #define PAINT_ERASE 0x0020 /* needs WM_ERASEBKGND */
106 #define PAINT_NONCLIENT 0x0040 /* needs WM_NCPAINT */
107 #define PAINT_DELAYED_ERASE 0x0080 /* still needs erase after WM_ERASEBKGND */
108 #define PAINT_PIXEL_FORMAT_CHILD 0x0100 /* at least one child has a custom pixel format */
110 /* growable array of user handles */
111 struct user_handle_array
113 user_handle_t
*handles
;
118 static const rectangle_t empty_rect
;
120 /* global window pointers */
121 static struct window
*shell_window
;
122 static struct window
*shell_listview
;
123 static struct window
*progman_window
;
124 static struct window
*taskman_window
;
126 /* magic HWND_TOP etc. pointers */
127 #define WINPTR_TOP ((struct window *)1L)
128 #define WINPTR_BOTTOM ((struct window *)2L)
129 #define WINPTR_TOPMOST ((struct window *)3L)
130 #define WINPTR_NOTOPMOST ((struct window *)4L)
132 /* retrieve a pointer to a window from its handle */
133 static inline struct window
*get_window( user_handle_t handle
)
135 struct window
*ret
= get_user_object( handle
, USER_WINDOW
);
136 if (!ret
) set_win32_error( ERROR_INVALID_WINDOW_HANDLE
);
140 /* check if window is the desktop */
141 static inline int is_desktop_window( const struct window
*win
)
143 return !win
->parent
; /* only desktop windows have no parent */
146 /* get next window in Z-order list */
147 static inline struct window
*get_next_window( struct window
*win
)
149 struct list
*ptr
= list_next( &win
->parent
->children
, &win
->entry
);
150 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
153 /* get previous window in Z-order list */
154 static inline struct window
*get_prev_window( struct window
*win
)
156 struct list
*ptr
= list_prev( &win
->parent
->children
, &win
->entry
);
157 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
160 /* get first child in Z-order list */
161 static inline struct window
*get_first_child( struct window
*win
)
163 struct list
*ptr
= list_head( &win
->children
);
164 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
167 /* get last child in Z-order list */
168 static inline struct window
*get_last_child( struct window
*win
)
170 struct list
*ptr
= list_tail( &win
->children
);
171 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
174 /* set the PAINT_PIXEL_FORMAT_CHILD flag on all the parents */
175 /* note: we never reset the flag, it's just a heuristic */
176 static inline void update_pixel_format_flags( struct window
*win
)
178 for (win
= win
->parent
; win
&& win
->parent
; win
= win
->parent
)
179 win
->paint_flags
|= PAINT_PIXEL_FORMAT_CHILD
;
182 /* get the per-monitor DPI for a window */
183 static unsigned int get_monitor_dpi( struct window
*win
)
185 /* FIXME: we return the desktop window DPI for now */
186 while (!is_desktop_window( win
)) win
= win
->parent
;
187 return win
->dpi
? win
->dpi
: USER_DEFAULT_SCREEN_DPI
;
190 /* link a window at the right place in the siblings list */
191 static void link_window( struct window
*win
, struct window
*previous
)
193 if (previous
== WINPTR_NOTOPMOST
)
195 if (!(win
->ex_style
& WS_EX_TOPMOST
) && win
->is_linked
) return; /* nothing to do */
196 win
->ex_style
&= ~WS_EX_TOPMOST
;
197 previous
= WINPTR_TOP
; /* fallback to the HWND_TOP case */
200 list_remove( &win
->entry
); /* unlink it from the previous location */
202 if (previous
== WINPTR_BOTTOM
)
204 list_add_tail( &win
->parent
->children
, &win
->entry
);
205 win
->ex_style
&= ~WS_EX_TOPMOST
;
207 else if (previous
== WINPTR_TOPMOST
)
209 list_add_head( &win
->parent
->children
, &win
->entry
);
210 win
->ex_style
|= WS_EX_TOPMOST
;
212 else if (previous
== WINPTR_TOP
)
214 struct list
*entry
= win
->parent
->children
.next
;
215 if (!(win
->ex_style
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
217 while (entry
!= &win
->parent
->children
)
219 struct window
*next
= LIST_ENTRY( entry
, struct window
, entry
);
220 if (!(next
->ex_style
& WS_EX_TOPMOST
)) break;
221 if (next
->handle
== win
->owner
) /* keep it above owner */
223 win
->ex_style
|= WS_EX_TOPMOST
;
229 list_add_before( entry
, &win
->entry
);
233 list_add_after( &previous
->entry
, &win
->entry
);
234 if (!(previous
->ex_style
& WS_EX_TOPMOST
)) win
->ex_style
&= ~WS_EX_TOPMOST
;
237 struct window
*next
= get_next_window( win
);
238 if (next
&& (next
->ex_style
& WS_EX_TOPMOST
)) win
->ex_style
|= WS_EX_TOPMOST
;
245 /* change the parent of a window (or unlink the window if the new parent is NULL) */
246 static int set_parent_window( struct window
*win
, struct window
*parent
)
250 /* make sure parent is not a child of window */
251 for (ptr
= parent
; ptr
; ptr
= ptr
->parent
)
255 set_error( STATUS_INVALID_PARAMETER
);
262 win
->parent
= parent
;
263 link_window( win
, WINPTR_TOP
);
265 if (!is_desktop_window( parent
))
267 win
->dpi
= parent
->dpi
;
268 win
->dpi_awareness
= parent
->dpi_awareness
;
271 /* if parent belongs to a different thread and the window isn't */
272 /* top-level, attach the two threads */
273 if (parent
->thread
&& parent
->thread
!= win
->thread
&& !is_desktop_window(parent
))
274 attach_thread_input( win
->thread
, parent
->thread
);
276 if (win
->paint_flags
& (PAINT_HAS_PIXEL_FORMAT
| PAINT_PIXEL_FORMAT_CHILD
))
277 update_pixel_format_flags( win
);
279 else /* move it to parent unlinked list */
281 list_remove( &win
->entry
); /* unlink it from the previous location */
282 list_add_head( &win
->parent
->unlinked
, &win
->entry
);
288 /* append a user handle to a handle array */
289 static int add_handle_to_array( struct user_handle_array
*array
, user_handle_t handle
)
291 if (array
->count
>= array
->total
)
293 int new_total
= max( array
->total
* 2, 32 );
294 user_handle_t
*new_array
= realloc( array
->handles
, new_total
* sizeof(*new_array
) );
297 free( array
->handles
);
298 set_error( STATUS_NO_MEMORY
);
301 array
->handles
= new_array
;
302 array
->total
= new_total
;
304 array
->handles
[array
->count
++] = handle
;
308 /* set a window property */
309 static void set_property( struct window
*win
, atom_t atom
, lparam_t data
, enum property_type type
)
312 struct property
*new_props
;
314 /* check if it exists already */
315 for (i
= 0; i
< win
->prop_inuse
; i
++)
317 if (win
->properties
[i
].type
== PROP_TYPE_FREE
)
322 if (win
->properties
[i
].atom
== atom
)
324 win
->properties
[i
].type
= type
;
325 win
->properties
[i
].data
= data
;
330 /* need to add an entry */
331 if (!grab_global_atom( NULL
, atom
)) return;
335 if (win
->prop_inuse
>= win
->prop_alloc
)
337 /* need to grow the array */
338 if (!(new_props
= realloc( win
->properties
,
339 sizeof(*new_props
) * (win
->prop_alloc
+ 16) )))
341 set_error( STATUS_NO_MEMORY
);
342 release_global_atom( NULL
, atom
);
345 win
->prop_alloc
+= 16;
346 win
->properties
= new_props
;
348 free
= win
->prop_inuse
++;
350 win
->properties
[free
].atom
= atom
;
351 win
->properties
[free
].type
= type
;
352 win
->properties
[free
].data
= data
;
355 /* remove a window property */
356 static lparam_t
remove_property( struct window
*win
, atom_t atom
)
360 for (i
= 0; i
< win
->prop_inuse
; i
++)
362 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
363 if (win
->properties
[i
].atom
== atom
)
365 release_global_atom( NULL
, atom
);
366 win
->properties
[i
].type
= PROP_TYPE_FREE
;
367 return win
->properties
[i
].data
;
370 /* FIXME: last error? */
374 /* find a window property */
375 static lparam_t
get_property( struct window
*win
, atom_t atom
)
379 for (i
= 0; i
< win
->prop_inuse
; i
++)
381 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
382 if (win
->properties
[i
].atom
== atom
) return win
->properties
[i
].data
;
384 /* FIXME: last error? */
388 /* destroy all properties of a window */
389 static inline void destroy_properties( struct window
*win
)
393 if (!win
->properties
) return;
394 for (i
= 0; i
< win
->prop_inuse
; i
++)
396 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
397 release_global_atom( NULL
, win
->properties
[i
].atom
);
399 free( win
->properties
);
402 /* detach a window from its owner thread but keep the window around */
403 static void detach_window_thread( struct window
*win
)
405 struct thread
*thread
= win
->thread
;
410 if (win
->update_region
) inc_queue_paint_count( thread
, -1 );
411 if (win
->paint_flags
& PAINT_INTERNAL
) inc_queue_paint_count( thread
, -1 );
412 queue_cleanup_window( thread
, win
->handle
);
414 assert( thread
->desktop_users
> 0 );
415 thread
->desktop_users
--;
416 release_class( win
->class );
419 /* don't hold a reference to the desktop so that the desktop window can be */
420 /* destroyed when the desktop ref count reaches zero */
421 release_object( win
->desktop
);
425 /* get the process owning the top window of a given desktop */
426 struct process
*get_top_window_owner( struct desktop
*desktop
)
428 struct window
*win
= desktop
->top_window
;
429 if (!win
|| !win
->thread
) return NULL
;
430 return win
->thread
->process
;
433 /* get the top window size of a given desktop */
434 void get_top_window_rectangle( struct desktop
*desktop
, rectangle_t
*rect
)
436 struct window
*win
= desktop
->top_window
;
437 *rect
= win
? win
->window_rect
: empty_rect
;
440 /* post a message to the desktop window */
441 void post_desktop_message( struct desktop
*desktop
, unsigned int message
,
442 lparam_t wparam
, lparam_t lparam
)
444 struct window
*win
= desktop
->top_window
;
445 if (win
&& win
->thread
) post_message( win
->handle
, message
, wparam
, lparam
);
448 /* create a new window structure (note: the window is not linked in the window tree) */
449 static struct window
*create_window( struct window
*parent
, struct window
*owner
,
450 atom_t atom
, mod_handle_t instance
)
453 struct window
*win
= NULL
;
454 struct desktop
*desktop
;
455 struct window_class
*class;
457 if (!(desktop
= get_thread_desktop( current
, DESKTOP_CREATEWINDOW
))) return NULL
;
459 if (!(class = grab_class( current
->process
, atom
, instance
, &extra_bytes
)))
461 release_object( desktop
);
465 if (!parent
) /* null parent is only allowed for desktop or HWND_MESSAGE top window */
467 if (is_desktop_class( class ))
468 parent
= desktop
->top_window
; /* use existing desktop if any */
469 else if (is_hwnd_message_class( class ))
470 /* use desktop window if message window is already created */
471 parent
= desktop
->msg_window
? desktop
->top_window
: NULL
;
472 else if (!(parent
= desktop
->top_window
)) /* must already have a desktop then */
474 set_error( STATUS_ACCESS_DENIED
);
479 /* parent must be on the same desktop */
480 if (parent
&& parent
->desktop
!= desktop
)
482 set_error( STATUS_ACCESS_DENIED
);
486 if (!(win
= mem_alloc( sizeof(*win
) + extra_bytes
- 1 ))) goto failed
;
487 if (!(win
->handle
= alloc_user_handle( win
, USER_WINDOW
))) goto failed
;
489 win
->parent
= parent
;
490 win
->owner
= owner
? owner
->handle
: 0;
491 win
->thread
= current
;
492 win
->desktop
= desktop
;
495 win
->last_active
= win
->handle
;
496 win
->win_region
= NULL
;
497 win
->update_region
= NULL
;
505 win
->dpi_awareness
= DPI_AWARENESS_PER_MONITOR_AWARE
;
509 win
->paint_flags
= 0;
512 win
->properties
= NULL
;
513 win
->nb_extra_bytes
= extra_bytes
;
514 win
->window_rect
= win
->visible_rect
= win
->surface_rect
= win
->client_rect
= empty_rect
;
515 memset( win
->extra_bytes
, 0, extra_bytes
);
516 list_init( &win
->children
);
517 list_init( &win
->unlinked
);
519 /* if parent belongs to a different thread and the window isn't */
520 /* top-level, attach the two threads */
521 if (parent
&& parent
->thread
&& parent
->thread
!= current
&& !is_desktop_window(parent
))
523 if (!attach_thread_input( current
, parent
->thread
)) goto failed
;
525 else /* otherwise just make sure that the thread has a message queue */
527 if (!current
->queue
&& !init_thread_queue( current
)) goto failed
;
530 /* put it on parent unlinked list */
531 if (parent
) list_add_head( &parent
->unlinked
, &win
->entry
);
534 list_init( &win
->entry
);
535 if (is_desktop_class( class ))
537 assert( !desktop
->top_window
);
538 desktop
->top_window
= win
;
539 set_process_default_desktop( current
->process
, desktop
, current
->desktop
);
543 assert( !desktop
->msg_window
);
544 desktop
->msg_window
= win
;
548 current
->desktop_users
++;
554 if (win
->handle
) free_user_handle( win
->handle
);
557 release_object( desktop
);
558 release_class( class );
562 /* destroy all windows belonging to a given thread */
563 void destroy_thread_windows( struct thread
*thread
)
565 user_handle_t handle
= 0;
568 while ((win
= next_user_handle( &handle
, USER_WINDOW
)))
570 if (win
->thread
!= thread
) continue;
571 if (is_desktop_window( win
)) detach_window_thread( win
);
572 else destroy_window( win
);
576 /* get the desktop window */
577 static struct window
*get_desktop_window( struct thread
*thread
)
579 struct window
*top_window
;
580 struct desktop
*desktop
= get_thread_desktop( thread
, 0 );
582 if (!desktop
) return NULL
;
583 top_window
= desktop
->top_window
;
584 release_object( desktop
);
588 /* check whether child is a descendant of parent */
589 int is_child_window( user_handle_t parent
, user_handle_t child
)
591 struct window
*child_ptr
= get_user_object( child
, USER_WINDOW
);
592 struct window
*parent_ptr
= get_user_object( parent
, USER_WINDOW
);
594 if (!child_ptr
|| !parent_ptr
) return 0;
595 while (child_ptr
->parent
)
597 if (child_ptr
->parent
== parent_ptr
) return 1;
598 child_ptr
= child_ptr
->parent
;
603 /* check if window can be set as foreground window */
604 int is_valid_foreground_window( user_handle_t window
)
606 struct window
*win
= get_user_object( window
, USER_WINDOW
);
607 return win
&& (win
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
;
610 /* make a window active if possible */
611 int make_window_active( user_handle_t window
)
613 struct window
*owner
, *win
= get_window( window
);
617 /* set last active for window and its owners */
621 owner
->last_active
= win
->handle
;
622 owner
= get_user_object( owner
->owner
, USER_WINDOW
);
627 /* increment (or decrement) the window paint count */
628 static inline void inc_window_paint_count( struct window
*win
, int incr
)
630 if (win
->thread
) inc_queue_paint_count( win
->thread
, incr
);
633 /* map a point between different DPI scaling levels */
634 static void map_dpi_point( struct window
*win
, int *x
, int *y
, unsigned int from
, unsigned int to
)
636 if (!from
) from
= get_monitor_dpi( win
);
637 if (!to
) to
= get_monitor_dpi( win
);
638 if (from
== to
) return;
639 *x
= scale_dpi( *x
, from
, to
);
640 *y
= scale_dpi( *y
, from
, to
);
643 /* map a window rectangle between different DPI scaling levels */
644 static void map_dpi_rect( struct window
*win
, rectangle_t
*rect
, unsigned int from
, unsigned int to
)
646 if (!from
) from
= get_monitor_dpi( win
);
647 if (!to
) to
= get_monitor_dpi( win
);
648 if (from
== to
) return;
649 scale_dpi_rect( rect
, from
, to
);
652 /* map a region between different DPI scaling levels */
653 static void map_dpi_region( struct window
*win
, struct region
*region
, unsigned int from
, unsigned int to
)
655 if (!from
) from
= get_monitor_dpi( win
);
656 if (!to
) to
= get_monitor_dpi( win
);
657 if (from
== to
) return;
658 scale_region( region
, from
, to
);
661 /* check if window and all its ancestors are visible */
662 static int is_visible( const struct window
*win
)
666 if (!(win
->style
& WS_VISIBLE
)) return 0;
668 /* if parent is minimized children are not visible */
669 if (win
&& (win
->style
& WS_MINIMIZE
)) return 0;
674 /* same as is_visible but takes a window handle */
675 int is_window_visible( user_handle_t window
)
677 struct window
*win
= get_user_object( window
, USER_WINDOW
);
679 return is_visible( win
);
682 int is_window_transparent( user_handle_t window
)
684 struct window
*win
= get_user_object( window
, USER_WINDOW
);
686 return (win
->ex_style
& (WS_EX_LAYERED
|WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
|WS_EX_TRANSPARENT
);
689 /* check if point is inside the window */
690 static inline int is_point_in_window( struct window
*win
, int x
, int y
)
692 if (!(win
->style
& WS_VISIBLE
)) return 0; /* not visible */
693 if ((win
->style
& (WS_POPUP
|WS_CHILD
|WS_DISABLED
)) == (WS_CHILD
|WS_DISABLED
))
694 return 0; /* disabled child */
695 if ((win
->ex_style
& (WS_EX_LAYERED
|WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
|WS_EX_TRANSPARENT
))
696 return 0; /* transparent */
697 if (!point_in_rect( &win
->visible_rect
, x
, y
))
698 return 0; /* not in window */
699 if (win
->win_region
&&
700 !point_in_region( win
->win_region
, x
- win
->window_rect
.left
, y
- win
->window_rect
.top
))
701 return 0; /* not in window region */
705 /* fill an array with the handles of the children of a specified window */
706 static unsigned int get_children_windows( struct window
*parent
, atom_t atom
, thread_id_t tid
,
707 user_handle_t
*handles
, unsigned int max_count
)
710 unsigned int count
= 0;
712 if (!parent
) return 0;
714 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
716 if (atom
&& get_class_atom(ptr
->class) != atom
) continue;
717 if (tid
&& get_thread_id(ptr
->thread
) != tid
) continue;
720 if (count
>= max_count
) break;
721 handles
[count
] = ptr
->handle
;
728 /* find child of 'parent' that contains the given point (in parent-relative coords) */
729 static struct window
*child_window_from_point( struct window
*parent
, int x
, int y
)
733 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
735 if (!is_point_in_window( ptr
, x
, y
)) continue; /* skip it */
737 /* if window is minimized or disabled, return at once */
738 if (ptr
->style
& (WS_MINIMIZE
|WS_DISABLED
)) return ptr
;
740 /* if point is not in client area, return at once */
741 if (!point_in_rect( &ptr
->client_rect
, x
, y
)) return ptr
;
743 return child_window_from_point( ptr
, x
- ptr
->client_rect
.left
, y
- ptr
->client_rect
.top
);
745 return parent
; /* not found any child */
748 /* find all children of 'parent' that contain the given point */
749 static int get_window_children_from_point( struct window
*parent
, int x
, int y
,
750 struct user_handle_array
*array
)
754 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
756 if (!is_point_in_window( ptr
, x
, y
)) continue; /* skip it */
758 /* if point is in client area, and window is not minimized or disabled, check children */
759 if (!(ptr
->style
& (WS_MINIMIZE
|WS_DISABLED
)) && point_in_rect( &ptr
->client_rect
, x
, y
))
761 if (!get_window_children_from_point( ptr
, x
- ptr
->client_rect
.left
,
762 y
- ptr
->client_rect
.top
, array
))
766 /* now add window to the array */
767 if (!add_handle_to_array( array
, ptr
->handle
)) return 0;
772 /* get handle of root of top-most window containing point */
773 user_handle_t
shallow_window_from_point( struct desktop
*desktop
, int x
, int y
)
777 if (!desktop
->top_window
) return 0;
779 LIST_FOR_EACH_ENTRY( ptr
, &desktop
->top_window
->children
, struct window
, entry
)
781 if (!is_point_in_window( ptr
, x
, y
)) continue; /* skip it */
784 return desktop
->top_window
->handle
;
787 /* return thread of top-most window containing point (in absolute coords) */
788 struct thread
*window_thread_from_point( user_handle_t scope
, int x
, int y
)
790 struct window
*win
= get_user_object( scope
, USER_WINDOW
);
793 if (!win
) return NULL
;
795 for (ptr
= win
; ptr
&& !is_desktop_window(ptr
); ptr
= ptr
->parent
)
797 x
-= ptr
->client_rect
.left
;
798 y
-= ptr
->client_rect
.top
;
801 ptr
= child_window_from_point( win
, x
, y
);
802 if (!ptr
->thread
) return NULL
;
803 return (struct thread
*)grab_object( ptr
->thread
);
806 /* return list of all windows containing point (in absolute coords) */
807 static int all_windows_from_point( struct window
*top
, int x
, int y
, struct user_handle_array
*array
)
811 /* make point relative to top window */
812 for (ptr
= top
->parent
; ptr
&& !is_desktop_window(ptr
); ptr
= ptr
->parent
)
814 x
-= ptr
->client_rect
.left
;
815 y
-= ptr
->client_rect
.top
;
818 if (!is_point_in_window( top
, x
, y
)) return 1;
820 /* if point is in client area, and window is not minimized or disabled, check children */
821 if (!(top
->style
& (WS_MINIMIZE
|WS_DISABLED
)) && point_in_rect( &top
->client_rect
, x
, y
))
823 if (!is_desktop_window(top
))
825 x
-= top
->client_rect
.left
;
826 y
-= top
->client_rect
.top
;
828 if (!get_window_children_from_point( top
, x
, y
, array
)) return 0;
830 /* now add window to the array */
831 if (!add_handle_to_array( array
, top
->handle
)) return 0;
836 /* return the thread owning a window */
837 struct thread
*get_window_thread( user_handle_t handle
)
839 struct window
*win
= get_user_object( handle
, USER_WINDOW
);
840 if (!win
|| !win
->thread
) return NULL
;
841 return (struct thread
*)grab_object( win
->thread
);
845 /* check if any area of a window needs repainting */
846 static inline int win_needs_repaint( struct window
*win
)
848 return win
->update_region
|| (win
->paint_flags
& PAINT_INTERNAL
);
852 /* find a child of the specified window that needs repainting */
853 static struct window
*find_child_to_repaint( struct window
*parent
, struct thread
*thread
)
855 struct window
*ptr
, *ret
= NULL
;
857 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
859 if (!(ptr
->style
& WS_VISIBLE
)) continue;
860 if (ptr
->thread
== thread
&& win_needs_repaint( ptr
))
862 else if (!(ptr
->style
& WS_MINIMIZE
)) /* explore its children */
863 ret
= find_child_to_repaint( ptr
, thread
);
867 if (ret
&& (ret
->ex_style
& WS_EX_TRANSPARENT
))
869 /* transparent window, check for non-transparent sibling to paint first */
870 for (ptr
= get_next_window(ret
); ptr
; ptr
= get_next_window(ptr
))
872 if (!(ptr
->style
& WS_VISIBLE
)) continue;
873 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
874 if (ptr
->thread
!= thread
) continue;
875 if (win_needs_repaint( ptr
)) return ptr
;
882 /* find a window that needs to receive a WM_PAINT; also clear its internal paint flag */
883 user_handle_t
find_window_to_repaint( user_handle_t parent
, struct thread
*thread
)
885 struct window
*ptr
, *win
, *top_window
= get_desktop_window( thread
);
887 if (!top_window
) return 0;
889 if (top_window
->thread
== thread
&& win_needs_repaint( top_window
)) win
= top_window
;
890 else win
= find_child_to_repaint( top_window
, thread
);
894 /* check that it is a child of the specified parent */
895 for (ptr
= win
; ptr
; ptr
= ptr
->parent
)
896 if (ptr
->handle
== parent
) break;
897 /* otherwise don't return any window, we don't repaint a child before its parent */
898 if (!ptr
) win
= NULL
;
901 win
->paint_flags
&= ~PAINT_INTERNAL
;
906 /* intersect the window region with the specified region, relative to the window parent */
907 static struct region
*intersect_window_region( struct region
*region
, struct window
*win
)
909 /* make region relative to window rect */
910 offset_region( region
, -win
->window_rect
.left
, -win
->window_rect
.top
);
911 if (!intersect_region( region
, region
, win
->win_region
)) return NULL
;
912 /* make region relative to parent again */
913 offset_region( region
, win
->window_rect
.left
, win
->window_rect
.top
);
918 /* convert coordinates from client to screen coords */
919 static inline void client_to_screen( struct window
*win
, int *x
, int *y
)
921 for ( ; win
&& !is_desktop_window(win
); win
= win
->parent
)
923 *x
+= win
->client_rect
.left
;
924 *y
+= win
->client_rect
.top
;
928 /* convert coordinates from client to screen coords */
929 static inline void client_to_screen_rect( struct window
*win
, rectangle_t
*rect
)
931 for ( ; win
&& !is_desktop_window(win
); win
= win
->parent
)
932 offset_rect( rect
, win
->client_rect
.left
, win
->client_rect
.top
);
935 /* map the region from window to screen coordinates */
936 static inline void map_win_region_to_screen( struct window
*win
, struct region
*region
)
938 if (!is_desktop_window(win
))
940 int x
= win
->window_rect
.left
;
941 int y
= win
->window_rect
.top
;
942 client_to_screen( win
->parent
, &x
, &y
);
943 offset_region( region
, x
, y
);
948 /* clip all children of a given window out of the visible region */
949 static struct region
*clip_children( struct window
*parent
, struct window
*last
,
950 struct region
*region
, int offset_x
, int offset_y
)
953 struct region
*tmp
= create_empty_region();
955 if (!tmp
) return NULL
;
956 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
958 if (ptr
== last
) break;
959 if (!(ptr
->style
& WS_VISIBLE
)) continue;
960 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
961 set_region_rect( tmp
, &ptr
->visible_rect
);
962 if (ptr
->win_region
&& !intersect_window_region( tmp
, ptr
))
967 offset_region( tmp
, offset_x
, offset_y
);
968 if (!(region
= subtract_region( region
, region
, tmp
))) break;
969 if (is_region_empty( region
)) break;
976 /* set the region to the client rect clipped by the window rect, in parent-relative coordinates */
977 static void set_region_client_rect( struct region
*region
, struct window
*win
)
981 intersect_rect( &rect
, &win
->window_rect
, &win
->client_rect
);
982 intersect_rect( &rect
, &rect
, &win
->surface_rect
);
983 set_region_rect( region
, &rect
);
987 /* set the region to the visible rect clipped by the window surface, in parent-relative coordinates */
988 static void set_region_visible_rect( struct region
*region
, struct window
*win
)
992 intersect_rect( &rect
, &win
->visible_rect
, &win
->surface_rect
);
993 set_region_rect( region
, &rect
);
997 /* get the top-level window to clip against for a given window */
998 static inline struct window
*get_top_clipping_window( struct window
*win
)
1000 while (!(win
->paint_flags
& PAINT_HAS_SURFACE
) && win
->parent
&& !is_desktop_window(win
->parent
))
1006 /* compute the visible region of a window, in window coordinates */
1007 static struct region
*get_visible_region( struct window
*win
, unsigned int flags
)
1009 struct region
*tmp
= NULL
, *region
;
1010 int offset_x
, offset_y
;
1012 if (!(region
= create_empty_region())) return NULL
;
1014 /* first check if all ancestors are visible */
1016 if (!is_visible( win
)) return region
; /* empty region */
1018 if (is_desktop_window( win
))
1020 set_region_rect( region
, &win
->window_rect
);
1024 /* create a region relative to the window itself */
1026 if ((flags
& DCX_PARENTCLIP
) && !is_desktop_window( win
->parent
))
1028 set_region_client_rect( region
, win
->parent
);
1029 offset_region( region
, -win
->parent
->client_rect
.left
, -win
->parent
->client_rect
.top
);
1031 else if (flags
& DCX_WINDOW
)
1033 set_region_visible_rect( region
, win
);
1034 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
1038 set_region_client_rect( region
, win
);
1039 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
1044 if (flags
& DCX_CLIPCHILDREN
)
1046 if (!clip_children( win
, NULL
, region
, win
->client_rect
.left
, win
->client_rect
.top
)) goto error
;
1049 /* clip siblings of ancestors */
1051 offset_x
= win
->window_rect
.left
;
1052 offset_y
= win
->window_rect
.top
;
1054 if ((tmp
= create_empty_region()) != NULL
)
1056 while (!is_desktop_window( win
->parent
))
1058 /* we don't clip out top-level siblings as that's up to the native windowing system */
1059 if (win
->style
& WS_CLIPSIBLINGS
)
1061 if (!clip_children( win
->parent
, win
, region
, 0, 0 )) goto error
;
1062 if (is_region_empty( region
)) break;
1064 /* clip to parent client area */
1066 offset_x
+= win
->client_rect
.left
;
1067 offset_y
+= win
->client_rect
.top
;
1068 offset_region( region
, win
->client_rect
.left
, win
->client_rect
.top
);
1069 set_region_client_rect( tmp
, win
);
1070 if (win
->win_region
&& !intersect_window_region( tmp
, win
)) goto error
;
1071 if (!intersect_region( region
, region
, tmp
)) goto error
;
1072 if (is_region_empty( region
)) break;
1076 offset_region( region
, -offset_x
, -offset_y
); /* make it relative to target window */
1080 if (tmp
) free_region( tmp
);
1081 free_region( region
);
1086 /* clip all children with a custom pixel format out of the visible region */
1087 static struct region
*clip_pixel_format_children( struct window
*parent
, struct region
*parent_clip
,
1088 struct region
*region
, int offset_x
, int offset_y
)
1091 struct region
*clip
= create_empty_region();
1093 if (!clip
) return NULL
;
1095 LIST_FOR_EACH_ENTRY_REV( ptr
, &parent
->children
, struct window
, entry
)
1097 if (!(ptr
->style
& WS_VISIBLE
)) continue;
1098 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
1100 /* add the visible rect */
1101 set_region_rect( clip
, &ptr
->visible_rect
);
1102 if (ptr
->win_region
&& !intersect_window_region( clip
, ptr
)) break;
1103 offset_region( clip
, offset_x
, offset_y
);
1104 if (!intersect_region( clip
, clip
, parent_clip
)) break;
1105 if (!union_region( region
, region
, clip
)) break;
1106 if (!(ptr
->paint_flags
& (PAINT_HAS_PIXEL_FORMAT
| PAINT_PIXEL_FORMAT_CHILD
))) continue;
1108 /* subtract the client rect if it uses a custom pixel format */
1109 set_region_rect( clip
, &ptr
->client_rect
);
1110 if (ptr
->win_region
&& !intersect_window_region( clip
, ptr
)) break;
1111 offset_region( clip
, offset_x
, offset_y
);
1112 if (!intersect_region( clip
, clip
, parent_clip
)) break;
1113 if ((ptr
->paint_flags
& PAINT_HAS_PIXEL_FORMAT
) && !subtract_region( region
, region
, clip
))
1116 if (!clip_pixel_format_children( ptr
, clip
, region
, offset_x
+ ptr
->client_rect
.left
,
1117 offset_y
+ ptr
->client_rect
.top
))
1120 free_region( clip
);
1125 /* compute the visible surface region of a window, in parent coordinates */
1126 static struct region
*get_surface_region( struct window
*win
)
1128 struct region
*region
, *clip
;
1129 int offset_x
, offset_y
;
1131 /* create a region relative to the window itself */
1133 if (!(region
= create_empty_region())) return NULL
;
1134 if (!(clip
= create_empty_region())) goto error
;
1135 set_region_rect( region
, &win
->visible_rect
);
1136 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
1137 set_region_rect( clip
, &win
->client_rect
);
1138 if (win
->win_region
&& !intersect_window_region( clip
, win
)) goto error
;
1140 if ((win
->paint_flags
& PAINT_HAS_PIXEL_FORMAT
) && !subtract_region( region
, region
, clip
))
1145 if (!is_desktop_window(win
))
1147 offset_x
= win
->client_rect
.left
;
1148 offset_y
= win
->client_rect
.top
;
1150 else offset_x
= offset_y
= 0;
1152 if (!clip_pixel_format_children( win
, clip
, region
, offset_x
, offset_y
)) goto error
;
1154 free_region( clip
);
1158 if (clip
) free_region( clip
);
1159 free_region( region
);
1164 /* get the window class of a window */
1165 struct window_class
* get_window_class( user_handle_t window
)
1168 if (!(win
= get_window( window
))) return NULL
;
1169 if (!win
->class) set_error( STATUS_ACCESS_DENIED
);
1173 /* determine the window visible rectangle, i.e. window or client rect cropped by parent rects */
1174 /* the returned rectangle is in window coordinates; return 0 if rectangle is empty */
1175 static int get_window_visible_rect( struct window
*win
, rectangle_t
*rect
, int frame
)
1177 int offset_x
= win
->window_rect
.left
, offset_y
= win
->window_rect
.top
;
1179 *rect
= frame
? win
->window_rect
: win
->client_rect
;
1181 if (!(win
->style
& WS_VISIBLE
)) return 0;
1182 if (is_desktop_window( win
)) return 1;
1184 while (!is_desktop_window( win
->parent
))
1187 if (!(win
->style
& WS_VISIBLE
) || win
->style
& WS_MINIMIZE
) return 0;
1188 offset_x
+= win
->client_rect
.left
;
1189 offset_y
+= win
->client_rect
.top
;
1190 offset_rect( rect
, win
->client_rect
.left
, win
->client_rect
.top
);
1191 if (!intersect_rect( rect
, rect
, &win
->client_rect
)) return 0;
1192 if (!intersect_rect( rect
, rect
, &win
->window_rect
)) return 0;
1194 offset_rect( rect
, -offset_x
, -offset_y
);
1198 /* return a copy of the specified region cropped to the window client or frame rectangle, */
1199 /* and converted from client to window coordinates. Helper for (in)validate_window. */
1200 static struct region
*crop_region_to_win_rect( struct window
*win
, struct region
*region
, int frame
)
1205 if (!get_window_visible_rect( win
, &rect
, frame
)) return NULL
;
1206 if (!(tmp
= create_empty_region())) return NULL
;
1207 set_region_rect( tmp
, &rect
);
1211 /* map it to client coords */
1212 offset_region( tmp
, win
->window_rect
.left
- win
->client_rect
.left
,
1213 win
->window_rect
.top
- win
->client_rect
.top
);
1215 /* intersect specified region with bounding rect */
1216 if (!intersect_region( tmp
, region
, tmp
)) goto done
;
1217 if (is_region_empty( tmp
)) goto done
;
1219 /* map it back to window coords */
1220 offset_region( tmp
, win
->client_rect
.left
- win
->window_rect
.left
,
1221 win
->client_rect
.top
- win
->window_rect
.top
);
1231 /* set a region as new update region for the window */
1232 static void set_update_region( struct window
*win
, struct region
*region
)
1234 if (region
&& !is_region_empty( region
))
1236 if (!win
->update_region
) inc_window_paint_count( win
, 1 );
1237 else free_region( win
->update_region
);
1238 win
->update_region
= region
;
1242 if (win
->update_region
)
1244 inc_window_paint_count( win
, -1 );
1245 free_region( win
->update_region
);
1247 win
->paint_flags
&= ~(PAINT_ERASE
| PAINT_DELAYED_ERASE
| PAINT_NONCLIENT
);
1248 win
->update_region
= NULL
;
1249 if (region
) free_region( region
);
1254 /* add a region to the update region; the passed region is freed or reused */
1255 static int add_update_region( struct window
*win
, struct region
*region
)
1257 if (win
->update_region
&& !union_region( region
, win
->update_region
, region
))
1259 free_region( region
);
1262 set_update_region( win
, region
);
1267 /* crop the update region of children to the specified rectangle, in client coords */
1268 static void crop_children_update_region( struct window
*win
, rectangle_t
*rect
)
1270 struct window
*child
;
1272 rectangle_t child_rect
;
1274 LIST_FOR_EACH_ENTRY( child
, &win
->children
, struct window
, entry
)
1276 if (!(child
->style
& WS_VISIBLE
)) continue;
1277 if (!rect
) /* crop everything out */
1279 crop_children_update_region( child
, NULL
);
1280 set_update_region( child
, NULL
);
1284 /* nothing to do if child is completely inside rect */
1285 if (child
->window_rect
.left
>= rect
->left
&&
1286 child
->window_rect
.top
>= rect
->top
&&
1287 child
->window_rect
.right
<= rect
->right
&&
1288 child
->window_rect
.bottom
<= rect
->bottom
) continue;
1290 /* map to child client coords and crop grand-children */
1292 offset_rect( &child_rect
, -child
->client_rect
.left
, -child
->client_rect
.top
);
1293 crop_children_update_region( child
, &child_rect
);
1295 /* now crop the child itself */
1296 if (!child
->update_region
) continue;
1297 if (!(tmp
= create_empty_region())) continue;
1298 set_region_rect( tmp
, rect
);
1299 offset_region( tmp
, -child
->window_rect
.left
, -child
->window_rect
.top
);
1300 if (intersect_region( tmp
, child
->update_region
, tmp
)) set_update_region( child
, tmp
);
1301 else free_region( tmp
);
1306 /* validate the non client area of a window */
1307 static void validate_non_client( struct window
*win
)
1312 if (!win
->update_region
) return; /* nothing to do */
1314 /* get client rect in window coords */
1315 rect
.left
= win
->client_rect
.left
- win
->window_rect
.left
;
1316 rect
.top
= win
->client_rect
.top
- win
->window_rect
.top
;
1317 rect
.right
= win
->client_rect
.right
- win
->window_rect
.left
;
1318 rect
.bottom
= win
->client_rect
.bottom
- win
->window_rect
.top
;
1320 if ((tmp
= create_empty_region()))
1322 set_region_rect( tmp
, &rect
);
1323 if (intersect_region( tmp
, win
->update_region
, tmp
))
1324 set_update_region( win
, tmp
);
1328 win
->paint_flags
&= ~PAINT_NONCLIENT
;
1332 /* validate a window completely so that we don't get any further paint messages for it */
1333 static void validate_whole_window( struct window
*win
)
1335 set_update_region( win
, NULL
);
1337 if (win
->paint_flags
& PAINT_INTERNAL
)
1339 win
->paint_flags
&= ~PAINT_INTERNAL
;
1340 inc_window_paint_count( win
, -1 );
1345 /* validate a window's children so that we don't get any further paint messages for it */
1346 static void validate_children( struct window
*win
)
1348 struct window
*child
;
1350 LIST_FOR_EACH_ENTRY( child
, &win
->children
, struct window
, entry
)
1352 if (!(child
->style
& WS_VISIBLE
)) continue;
1353 validate_children(child
);
1354 validate_whole_window(child
);
1359 /* validate the update region of a window on all parents; helper for get_update_region */
1360 static void validate_parents( struct window
*child
)
1362 int offset_x
= 0, offset_y
= 0;
1363 struct window
*win
= child
;
1364 struct region
*tmp
= NULL
;
1366 if (!child
->update_region
) return;
1370 /* map to parent client coords */
1371 offset_x
+= win
->window_rect
.left
;
1372 offset_y
+= win
->window_rect
.top
;
1376 /* and now map to window coords */
1377 offset_x
+= win
->client_rect
.left
- win
->window_rect
.left
;
1378 offset_y
+= win
->client_rect
.top
- win
->window_rect
.top
;
1380 if (win
->update_region
&& !(win
->style
& WS_CLIPCHILDREN
))
1382 if (!tmp
&& !(tmp
= create_empty_region())) return;
1383 offset_region( child
->update_region
, offset_x
, offset_y
);
1384 if (subtract_region( tmp
, win
->update_region
, child
->update_region
))
1386 set_update_region( win
, tmp
);
1389 /* restore child coords */
1390 offset_region( child
->update_region
, -offset_x
, -offset_y
);
1393 if (tmp
) free_region( tmp
);
1397 /* add/subtract a region (in client coordinates) to the update region of the window */
1398 static void redraw_window( struct window
*win
, struct region
*region
, int frame
, unsigned int flags
)
1400 struct region
*child_rgn
, *tmp
;
1401 struct window
*child
;
1403 if (flags
& RDW_INVALIDATE
)
1405 if (!(tmp
= crop_region_to_win_rect( win
, region
, frame
))) return;
1407 if (!add_update_region( win
, tmp
)) return;
1409 if (flags
& RDW_FRAME
) win
->paint_flags
|= PAINT_NONCLIENT
;
1410 if (flags
& RDW_ERASE
) win
->paint_flags
|= PAINT_ERASE
;
1412 else if (flags
& RDW_VALIDATE
)
1414 if (!region
&& (flags
& RDW_NOFRAME
)) /* shortcut: validate everything */
1416 set_update_region( win
, NULL
);
1418 else if (win
->update_region
)
1420 if ((tmp
= crop_region_to_win_rect( win
, region
, frame
)))
1422 if (!subtract_region( tmp
, win
->update_region
, tmp
))
1427 set_update_region( win
, tmp
);
1429 if (flags
& RDW_NOFRAME
) validate_non_client( win
);
1430 if (flags
& RDW_NOERASE
) win
->paint_flags
&= ~(PAINT_ERASE
| PAINT_DELAYED_ERASE
);
1434 if ((flags
& RDW_INTERNALPAINT
) && !(win
->paint_flags
& PAINT_INTERNAL
))
1436 win
->paint_flags
|= PAINT_INTERNAL
;
1437 inc_window_paint_count( win
, 1 );
1439 else if ((flags
& RDW_NOINTERNALPAINT
) && (win
->paint_flags
& PAINT_INTERNAL
))
1441 win
->paint_flags
&= ~PAINT_INTERNAL
;
1442 inc_window_paint_count( win
, -1 );
1445 /* now process children recursively */
1447 if (flags
& RDW_NOCHILDREN
) return;
1448 if (win
->style
& WS_MINIMIZE
) return;
1449 if ((win
->style
& WS_CLIPCHILDREN
) && !(flags
& RDW_ALLCHILDREN
)) return;
1451 if (!(tmp
= crop_region_to_win_rect( win
, region
, 0 ))) return;
1453 /* map to client coordinates */
1454 offset_region( tmp
, win
->window_rect
.left
- win
->client_rect
.left
,
1455 win
->window_rect
.top
- win
->client_rect
.top
);
1457 if (flags
& RDW_INVALIDATE
) flags
|= RDW_FRAME
| RDW_ERASE
;
1459 LIST_FOR_EACH_ENTRY( child
, &win
->children
, struct window
, entry
)
1461 if (!(child
->style
& WS_VISIBLE
)) continue;
1462 if (!(child_rgn
= create_empty_region())) continue;
1463 if (copy_region( child_rgn
, tmp
))
1465 map_dpi_region( child
, child_rgn
, win
->dpi
, child
->dpi
);
1466 if (rect_in_region( child_rgn
, &child
->window_rect
))
1468 offset_region( child_rgn
, -child
->client_rect
.left
, -child
->client_rect
.top
);
1469 redraw_window( child
, child_rgn
, 1, flags
);
1472 free_region( child_rgn
);
1479 /* retrieve the update flags for a window depending on the state of the update region */
1480 static unsigned int get_update_flags( struct window
*win
, unsigned int flags
)
1482 unsigned int ret
= 0;
1484 if (flags
& UPDATE_NONCLIENT
)
1486 if ((win
->paint_flags
& PAINT_NONCLIENT
) && win
->update_region
) ret
|= UPDATE_NONCLIENT
;
1488 if (flags
& UPDATE_ERASE
)
1490 if ((win
->paint_flags
& PAINT_ERASE
) && win
->update_region
) ret
|= UPDATE_ERASE
;
1492 if (flags
& UPDATE_PAINT
)
1494 if (win
->update_region
)
1496 if (win
->paint_flags
& PAINT_DELAYED_ERASE
) ret
|= UPDATE_DELAYED_ERASE
;
1497 ret
|= UPDATE_PAINT
;
1500 if (flags
& UPDATE_INTERNALPAINT
)
1502 if (win
->paint_flags
& PAINT_INTERNAL
)
1504 ret
|= UPDATE_INTERNALPAINT
;
1505 if (win
->paint_flags
& PAINT_DELAYED_ERASE
) ret
|= UPDATE_DELAYED_ERASE
;
1512 /* iterate through the children of the given window until we find one with some update flags */
1513 static unsigned int get_child_update_flags( struct window
*win
, struct window
*from_child
,
1514 unsigned int flags
, struct window
**child
)
1517 unsigned int ret
= 0;
1519 /* first make sure we want to iterate children at all */
1521 if (win
->style
& WS_MINIMIZE
) return 0;
1523 /* note: the WS_CLIPCHILDREN test is the opposite of the invalidation case,
1524 * here we only want to repaint children of windows that clip them, others
1525 * need to wait for WM_PAINT to be done in the parent first.
1527 if (!(flags
& UPDATE_ALLCHILDREN
) && !(win
->style
& WS_CLIPCHILDREN
)) return 0;
1529 LIST_FOR_EACH_ENTRY( ptr
, &win
->children
, struct window
, entry
)
1531 if (from_child
) /* skip all children until from_child is found */
1533 if (ptr
== from_child
) from_child
= NULL
;
1536 if (!(ptr
->style
& WS_VISIBLE
)) continue;
1537 if ((ret
= get_update_flags( ptr
, flags
)) != 0)
1542 if ((ret
= get_child_update_flags( ptr
, NULL
, flags
, child
))) break;
1547 /* iterate through children and siblings of the given window until we find one with some update flags */
1548 static unsigned int get_window_update_flags( struct window
*win
, struct window
*from_child
,
1549 unsigned int flags
, struct window
**child
)
1552 struct window
*ptr
, *from_sibling
= NULL
;
1554 /* if some parent is not visible start from the next sibling */
1556 if (!is_visible( win
)) return 0;
1557 for (ptr
= from_child
; ptr
; ptr
= ptr
->parent
)
1559 if (!(ptr
->style
& WS_VISIBLE
) || (ptr
->style
& WS_MINIMIZE
)) from_sibling
= ptr
;
1560 if (ptr
== win
) break;
1563 /* non-client painting must be delayed if one of the parents is going to
1564 * be repainted and doesn't clip children */
1566 if ((flags
& UPDATE_NONCLIENT
) && !(flags
& (UPDATE_PAINT
|UPDATE_INTERNALPAINT
)))
1568 for (ptr
= win
->parent
; ptr
; ptr
= ptr
->parent
)
1570 if (!(ptr
->style
& WS_CLIPCHILDREN
) && win_needs_repaint( ptr
))
1573 if (from_child
&& !(flags
& UPDATE_ALLCHILDREN
))
1575 for (ptr
= from_sibling
? from_sibling
: from_child
; ptr
; ptr
= ptr
->parent
)
1577 if (!(ptr
->style
& WS_CLIPCHILDREN
) && win_needs_repaint( ptr
)) from_sibling
= ptr
;
1578 if (ptr
== win
) break;
1584 /* check window itself (only if not restarting from a child) */
1588 if ((ret
= get_update_flags( win
, flags
)))
1596 /* now check children */
1598 if (flags
& UPDATE_NOCHILDREN
) return 0;
1601 if ((ret
= get_child_update_flags( from_child
, NULL
, flags
, child
))) return ret
;
1602 from_sibling
= from_child
;
1605 /* then check siblings and parent siblings */
1607 while (from_sibling
->parent
&& from_sibling
!= win
)
1609 if ((ret
= get_child_update_flags( from_sibling
->parent
, from_sibling
, flags
, child
)))
1611 from_sibling
= from_sibling
->parent
;
1617 /* expose the areas revealed by a vis region change on the window parent */
1618 /* returns the region exposed on the window itself (in client coordinates) */
1619 static struct region
*expose_window( struct window
*win
, const rectangle_t
*old_window_rect
,
1620 struct region
*old_vis_rgn
)
1622 struct region
*new_vis_rgn
, *exposed_rgn
;
1624 if (!(new_vis_rgn
= get_visible_region( win
, DCX_WINDOW
))) return NULL
;
1626 if ((exposed_rgn
= create_empty_region()))
1628 if (subtract_region( exposed_rgn
, new_vis_rgn
, old_vis_rgn
) && !is_region_empty( exposed_rgn
))
1630 /* make it relative to the new client area */
1631 offset_region( exposed_rgn
, win
->window_rect
.left
- win
->client_rect
.left
,
1632 win
->window_rect
.top
- win
->client_rect
.top
);
1636 free_region( exposed_rgn
);
1641 if (win
->parent
&& !is_desktop_window( win
->parent
))
1643 /* make it relative to the old window pos for subtracting */
1644 offset_region( new_vis_rgn
, win
->window_rect
.left
- old_window_rect
->left
,
1645 win
->window_rect
.top
- old_window_rect
->top
);
1647 if ((win
->parent
->style
& WS_CLIPCHILDREN
) ?
1648 subtract_region( new_vis_rgn
, old_vis_rgn
, new_vis_rgn
) :
1649 xor_region( new_vis_rgn
, old_vis_rgn
, new_vis_rgn
))
1651 if (!is_region_empty( new_vis_rgn
))
1653 /* make it relative to parent */
1654 offset_region( new_vis_rgn
, old_window_rect
->left
, old_window_rect
->top
);
1655 redraw_window( win
->parent
, new_vis_rgn
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1659 free_region( new_vis_rgn
);
1664 /* set the window and client rectangles, updating the update region if necessary */
1665 static void set_window_pos( struct window
*win
, struct window
*previous
,
1666 unsigned int swp_flags
, const rectangle_t
*window_rect
,
1667 const rectangle_t
*client_rect
, const rectangle_t
*visible_rect
,
1668 const rectangle_t
*surface_rect
, const rectangle_t
*valid_rect
)
1670 struct region
*old_vis_rgn
= NULL
, *exposed_rgn
= NULL
;
1671 const rectangle_t old_window_rect
= win
->window_rect
;
1672 const rectangle_t old_visible_rect
= win
->visible_rect
;
1673 const rectangle_t old_client_rect
= win
->client_rect
;
1675 int client_changed
, frame_changed
;
1676 int visible
= (win
->style
& WS_VISIBLE
) || (swp_flags
& SWP_SHOWWINDOW
);
1678 if (win
->parent
&& !is_visible( win
->parent
)) visible
= 0;
1680 if (visible
&& !(old_vis_rgn
= get_visible_region( win
, DCX_WINDOW
))) return;
1682 /* set the new window info before invalidating anything */
1684 win
->window_rect
= *window_rect
;
1685 win
->visible_rect
= *visible_rect
;
1686 win
->surface_rect
= *surface_rect
;
1687 win
->client_rect
= *client_rect
;
1688 if (!(swp_flags
& SWP_NOZORDER
) && win
->parent
) link_window( win
, previous
);
1689 if (swp_flags
& SWP_SHOWWINDOW
) win
->style
|= WS_VISIBLE
;
1690 else if (swp_flags
& SWP_HIDEWINDOW
) win
->style
&= ~WS_VISIBLE
;
1692 /* keep children at the same position relative to top right corner when the parent is mirrored */
1693 if (win
->ex_style
& WS_EX_LAYOUTRTL
)
1695 struct window
*child
;
1696 int old_size
= old_client_rect
.right
- old_client_rect
.left
;
1697 int new_size
= win
->client_rect
.right
- win
->client_rect
.left
;
1699 if (old_size
!= new_size
) LIST_FOR_EACH_ENTRY( child
, &win
->children
, struct window
, entry
)
1701 offset_rect( &child
->window_rect
, new_size
- old_size
, 0 );
1702 offset_rect( &child
->visible_rect
, new_size
- old_size
, 0 );
1703 offset_rect( &child
->surface_rect
, new_size
- old_size
, 0 );
1704 offset_rect( &child
->client_rect
, new_size
- old_size
, 0 );
1708 /* reset cursor clip rectangle when the desktop changes size */
1709 if (win
== win
->desktop
->top_window
) win
->desktop
->cursor
.clip
= *window_rect
;
1711 /* if the window is not visible, everything is easy */
1712 if (!visible
) return;
1714 /* expose anything revealed by the change */
1716 if (!(swp_flags
& SWP_NOREDRAW
))
1717 exposed_rgn
= expose_window( win
, &old_window_rect
, old_vis_rgn
);
1719 if (!(win
->style
& WS_VISIBLE
))
1721 /* clear the update region since the window is no longer visible */
1722 validate_whole_window( win
);
1723 validate_children( win
);
1727 /* crop update region to the new window rect */
1729 if (win
->update_region
)
1731 if (get_window_visible_rect( win
, &rect
, 1 ))
1733 struct region
*tmp
= create_empty_region();
1736 set_region_rect( tmp
, &rect
);
1737 if (intersect_region( tmp
, win
->update_region
, tmp
))
1738 set_update_region( win
, tmp
);
1743 else set_update_region( win
, NULL
); /* visible rect is empty */
1746 /* crop children regions to the new window rect */
1748 if (get_window_visible_rect( win
, &rect
, 0 ))
1750 /* map to client coords */
1751 offset_rect( &rect
, win
->window_rect
.left
- win
->client_rect
.left
,
1752 win
->window_rect
.top
- win
->client_rect
.top
);
1753 crop_children_update_region( win
, &rect
);
1755 else crop_children_update_region( win
, NULL
);
1757 if (swp_flags
& SWP_NOREDRAW
) goto done
; /* do not repaint anything */
1759 /* expose the whole non-client area if it changed in any way */
1761 if (swp_flags
& SWP_NOCOPYBITS
)
1763 frame_changed
= ((swp_flags
& SWP_FRAMECHANGED
) ||
1764 memcmp( window_rect
, &old_window_rect
, sizeof(old_window_rect
) ) ||
1765 memcmp( visible_rect
, &old_visible_rect
, sizeof(old_visible_rect
) ));
1766 client_changed
= memcmp( client_rect
, &old_client_rect
, sizeof(old_client_rect
) );
1770 /* assume the bits have been moved to follow the window rect */
1771 int x_offset
= window_rect
->left
- old_window_rect
.left
;
1772 int y_offset
= window_rect
->top
- old_window_rect
.top
;
1773 frame_changed
= ((swp_flags
& SWP_FRAMECHANGED
) ||
1774 window_rect
->right
- old_window_rect
.right
!= x_offset
||
1775 window_rect
->bottom
- old_window_rect
.bottom
!= y_offset
||
1776 visible_rect
->left
- old_visible_rect
.left
!= x_offset
||
1777 visible_rect
->right
- old_visible_rect
.right
!= x_offset
||
1778 visible_rect
->top
- old_visible_rect
.top
!= y_offset
||
1779 visible_rect
->bottom
- old_visible_rect
.bottom
!= y_offset
);
1780 client_changed
= (client_rect
->left
- old_client_rect
.left
!= x_offset
||
1781 client_rect
->right
- old_client_rect
.right
!= x_offset
||
1782 client_rect
->top
- old_client_rect
.top
!= y_offset
||
1783 client_rect
->bottom
- old_client_rect
.bottom
!= y_offset
||
1784 memcmp( valid_rect
, client_rect
, sizeof(*client_rect
) ));
1787 if (frame_changed
|| client_changed
)
1789 struct region
*win_rgn
= old_vis_rgn
; /* reuse previous region */
1791 set_region_rect( win_rgn
, window_rect
);
1792 if (!is_rect_empty( valid_rect
))
1794 /* subtract the valid portion of client rect from the total region */
1795 struct region
*tmp
= create_empty_region();
1798 set_region_rect( tmp
, valid_rect
);
1799 /* subtract update region since invalid parts of the valid rect won't be copied */
1800 if (win
->update_region
)
1802 offset_region( tmp
, -window_rect
->left
, -window_rect
->top
);
1803 subtract_region( tmp
, tmp
, win
->update_region
);
1804 offset_region( tmp
, window_rect
->left
, window_rect
->top
);
1806 if (subtract_region( tmp
, win_rgn
, tmp
)) win_rgn
= tmp
;
1807 else free_region( tmp
);
1810 if (!is_desktop_window(win
))
1811 offset_region( win_rgn
, -client_rect
->left
, -client_rect
->top
);
1814 union_region( exposed_rgn
, exposed_rgn
, win_rgn
);
1815 if (win_rgn
!= old_vis_rgn
) free_region( win_rgn
);
1819 exposed_rgn
= win_rgn
;
1820 if (win_rgn
== old_vis_rgn
) old_vis_rgn
= NULL
;
1825 redraw_window( win
, exposed_rgn
, 1, RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
1828 if (old_vis_rgn
) free_region( old_vis_rgn
);
1829 if (exposed_rgn
) free_region( exposed_rgn
);
1830 clear_error(); /* we ignore out of memory errors once the new rects have been set */
1834 /* set the window region, updating the update region if necessary */
1835 static void set_window_region( struct window
*win
, struct region
*region
, int redraw
)
1837 struct region
*old_vis_rgn
= NULL
, *exposed_rgn
;
1839 /* no need to redraw if window is not visible */
1840 if (redraw
&& !is_visible( win
)) redraw
= 0;
1842 if (redraw
) old_vis_rgn
= get_visible_region( win
, DCX_WINDOW
);
1844 if (win
->win_region
) free_region( win
->win_region
);
1845 win
->win_region
= region
;
1847 /* expose anything revealed by the change */
1848 if (old_vis_rgn
&& ((exposed_rgn
= expose_window( win
, &win
->window_rect
, old_vis_rgn
))))
1850 redraw_window( win
, exposed_rgn
, 1, RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
1851 free_region( exposed_rgn
);
1854 if (old_vis_rgn
) free_region( old_vis_rgn
);
1855 clear_error(); /* we ignore out of memory errors since the region has been set */
1859 /* destroy a window */
1860 void destroy_window( struct window
*win
)
1862 /* hide the window */
1863 if (is_visible(win
))
1865 struct region
*vis_rgn
= get_visible_region( win
, DCX_WINDOW
);
1866 win
->style
&= ~WS_VISIBLE
;
1869 struct region
*exposed_rgn
= expose_window( win
, &win
->window_rect
, vis_rgn
);
1870 if (exposed_rgn
) free_region( exposed_rgn
);
1871 free_region( vis_rgn
);
1873 validate_whole_window( win
);
1874 validate_children( win
);
1877 /* destroy all children */
1878 while (!list_empty(&win
->children
))
1879 destroy_window( LIST_ENTRY( list_head(&win
->children
), struct window
, entry
));
1880 while (!list_empty(&win
->unlinked
))
1881 destroy_window( LIST_ENTRY( list_head(&win
->unlinked
), struct window
, entry
));
1883 /* reset global window pointers, if the corresponding window is destroyed */
1884 if (win
== shell_window
) shell_window
= NULL
;
1885 if (win
== shell_listview
) shell_listview
= NULL
;
1886 if (win
== progman_window
) progman_window
= NULL
;
1887 if (win
== taskman_window
) taskman_window
= NULL
;
1888 free_hotkeys( win
->desktop
, win
->handle
);
1889 cleanup_clipboard_window( win
->desktop
, win
->handle
);
1890 free_user_handle( win
->handle
);
1891 destroy_properties( win
);
1892 list_remove( &win
->entry
);
1893 if (is_desktop_window(win
))
1895 struct desktop
*desktop
= win
->desktop
;
1896 assert( desktop
->top_window
== win
|| desktop
->msg_window
== win
);
1897 if (desktop
->top_window
== win
) desktop
->top_window
= NULL
;
1898 else desktop
->msg_window
= NULL
;
1900 else if (is_desktop_window( win
->parent
))
1902 post_message( win
->parent
->handle
, WM_PARENTNOTIFY
, WM_DESTROY
, win
->handle
);
1905 detach_window_thread( win
);
1906 if (win
->win_region
) free_region( win
->win_region
);
1907 if (win
->update_region
) free_region( win
->update_region
);
1908 if (win
->class) release_class( win
->class );
1910 memset( win
, 0x55, sizeof(*win
) + win
->nb_extra_bytes
- 1 );
1915 /* create a window */
1916 DECL_HANDLER(create_window
)
1918 struct window
*win
, *parent
= NULL
, *owner
= NULL
;
1919 struct unicode_str cls_name
= get_req_unicode_str();
1923 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
1927 if (!(owner
= get_window( req
->owner
))) return;
1928 if (is_desktop_window(owner
)) owner
= NULL
;
1929 else if (parent
&& !is_desktop_window(parent
))
1931 /* an owned window must be created as top-level */
1932 set_error( STATUS_ACCESS_DENIED
);
1935 else /* owner must be a top-level window */
1936 while ((owner
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& !is_desktop_window(owner
->parent
))
1937 owner
= owner
->parent
;
1940 atom
= cls_name
.len
? find_global_atom( NULL
, &cls_name
) : req
->atom
;
1942 if (!(win
= create_window( parent
, owner
, atom
, req
->instance
))) return;
1944 if (parent
&& !is_desktop_window( parent
))
1946 win
->dpi_awareness
= parent
->dpi_awareness
;
1947 win
->dpi
= parent
->dpi
;
1949 else if (!parent
|| req
->awareness
!= DPI_AWARENESS_PER_MONITOR_AWARE
)
1951 win
->dpi_awareness
= req
->awareness
;
1952 win
->dpi
= req
->dpi
;
1955 reply
->handle
= win
->handle
;
1956 reply
->parent
= win
->parent
? win
->parent
->handle
: 0;
1957 reply
->owner
= win
->owner
;
1958 reply
->extra
= win
->nb_extra_bytes
;
1959 reply
->dpi
= win
->dpi
;
1960 reply
->awareness
= win
->dpi_awareness
;
1961 reply
->class_ptr
= get_class_client_ptr( win
->class );
1965 /* set the parent of a window */
1966 DECL_HANDLER(set_parent
)
1968 struct window
*win
, *parent
= NULL
;
1970 if (!(win
= get_window( req
->handle
))) return;
1971 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
1973 if (is_desktop_window(win
))
1975 set_error( STATUS_INVALID_PARAMETER
);
1978 reply
->old_parent
= win
->parent
->handle
;
1979 reply
->full_parent
= parent
? parent
->handle
: 0;
1980 set_parent_window( win
, parent
);
1981 reply
->dpi
= win
->dpi
;
1982 reply
->awareness
= win
->dpi_awareness
;
1986 /* destroy a window */
1987 DECL_HANDLER(destroy_window
)
1989 struct window
*win
= get_window( req
->handle
);
1992 if (!is_desktop_window(win
)) destroy_window( win
);
1993 else if (win
->thread
== current
) detach_window_thread( win
);
1994 else set_error( STATUS_ACCESS_DENIED
);
1999 /* retrieve the desktop window for the current thread */
2000 DECL_HANDLER(get_desktop_window
)
2002 struct desktop
*desktop
= get_thread_desktop( current
, 0 );
2005 if (!desktop
) return;
2007 /* if winstation is invisible, then avoid roundtrip */
2008 force
= req
->force
|| !(desktop
->winstation
->flags
& WSF_VISIBLE
);
2010 if (!desktop
->top_window
&& force
) /* create it */
2012 if ((desktop
->top_window
= create_window( NULL
, NULL
, DESKTOP_ATOM
, 0 )))
2014 detach_window_thread( desktop
->top_window
);
2015 desktop
->top_window
->style
= WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
2019 if (!desktop
->msg_window
&& force
) /* create it */
2021 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e'};
2022 static const struct unicode_str name
= { messageW
, sizeof(messageW
) };
2023 atom_t atom
= add_global_atom( NULL
, &name
);
2024 if (atom
&& (desktop
->msg_window
= create_window( NULL
, NULL
, atom
, 0 )))
2026 detach_window_thread( desktop
->msg_window
);
2027 desktop
->msg_window
->style
= WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
2031 reply
->top_window
= desktop
->top_window
? desktop
->top_window
->handle
: 0;
2032 reply
->msg_window
= desktop
->msg_window
? desktop
->msg_window
->handle
: 0;
2033 release_object( desktop
);
2037 /* set a window owner */
2038 DECL_HANDLER(set_window_owner
)
2040 struct window
*win
= get_window( req
->handle
);
2041 struct window
*owner
= NULL
, *ptr
;
2044 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
2045 if (is_desktop_window(win
))
2047 set_error( STATUS_ACCESS_DENIED
);
2051 /* make sure owner is not a successor of window */
2052 for (ptr
= owner
; ptr
; ptr
= ptr
->owner
? get_window( ptr
->owner
) : NULL
)
2056 set_error( STATUS_INVALID_PARAMETER
);
2061 reply
->prev_owner
= win
->owner
;
2062 reply
->full_owner
= win
->owner
= owner
? owner
->handle
: 0;
2066 /* get information from a window handle */
2067 DECL_HANDLER(get_window_info
)
2069 struct window
*win
= get_window( req
->handle
);
2073 reply
->full_handle
= win
->handle
;
2074 reply
->last_active
= win
->handle
;
2075 reply
->is_unicode
= win
->is_unicode
;
2076 reply
->awareness
= win
->dpi_awareness
;
2077 reply
->dpi
= win
->dpi
? win
->dpi
: get_monitor_dpi( win
);
2078 if (get_user_object( win
->last_active
, USER_WINDOW
)) reply
->last_active
= win
->last_active
;
2081 reply
->tid
= get_thread_id( win
->thread
);
2082 reply
->pid
= get_process_id( win
->thread
->process
);
2083 reply
->atom
= win
->class ? get_class_atom( win
->class ) : DESKTOP_ATOM
;
2088 /* set some information in a window */
2089 DECL_HANDLER(set_window_info
)
2091 struct window
*win
= get_window( req
->handle
);
2094 if (req
->flags
&& is_desktop_window(win
) && win
->thread
!= current
)
2096 set_error( STATUS_ACCESS_DENIED
);
2099 if (req
->extra_size
> sizeof(req
->extra_value
) ||
2100 req
->extra_offset
< -1 ||
2101 req
->extra_offset
> win
->nb_extra_bytes
- (int)req
->extra_size
)
2103 set_win32_error( ERROR_INVALID_INDEX
);
2106 if (req
->extra_offset
!= -1)
2108 memcpy( &reply
->old_extra_value
, win
->extra_bytes
+ req
->extra_offset
, req
->extra_size
);
2110 else if (req
->flags
& SET_WIN_EXTRA
)
2112 set_win32_error( ERROR_INVALID_INDEX
);
2115 reply
->old_style
= win
->style
;
2116 reply
->old_ex_style
= win
->ex_style
;
2117 reply
->old_id
= win
->id
;
2118 reply
->old_instance
= win
->instance
;
2119 reply
->old_user_data
= win
->user_data
;
2120 if (req
->flags
& SET_WIN_STYLE
) win
->style
= req
->style
;
2121 if (req
->flags
& SET_WIN_EXSTYLE
)
2123 /* WS_EX_TOPMOST can only be changed for unlinked windows */
2124 if (!win
->is_linked
) win
->ex_style
= req
->ex_style
;
2125 else win
->ex_style
= (req
->ex_style
& ~WS_EX_TOPMOST
) | (win
->ex_style
& WS_EX_TOPMOST
);
2126 if (!(win
->ex_style
& WS_EX_LAYERED
)) win
->is_layered
= 0;
2128 if (req
->flags
& SET_WIN_ID
) win
->id
= req
->id
;
2129 if (req
->flags
& SET_WIN_INSTANCE
) win
->instance
= req
->instance
;
2130 if (req
->flags
& SET_WIN_UNICODE
) win
->is_unicode
= req
->is_unicode
;
2131 if (req
->flags
& SET_WIN_USERDATA
) win
->user_data
= req
->user_data
;
2132 if (req
->flags
& SET_WIN_EXTRA
) memcpy( win
->extra_bytes
+ req
->extra_offset
,
2133 &req
->extra_value
, req
->extra_size
);
2135 /* changing window style triggers a non-client paint */
2136 if (req
->flags
& SET_WIN_STYLE
) win
->paint_flags
|= PAINT_NONCLIENT
;
2140 /* get a list of the window parents, up to the root of the tree */
2141 DECL_HANDLER(get_window_parents
)
2143 struct window
*ptr
, *win
= get_window( req
->handle
);
2145 user_handle_t
*data
;
2148 if (win
) for (ptr
= win
->parent
; ptr
; ptr
= ptr
->parent
) total
++;
2150 reply
->count
= total
;
2151 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
2152 if (len
&& ((data
= set_reply_data_size( len
))))
2154 for (ptr
= win
->parent
; ptr
&& len
; ptr
= ptr
->parent
, len
-= sizeof(*data
))
2155 *data
++ = ptr
->handle
;
2160 /* get a list of the window children */
2161 DECL_HANDLER(get_window_children
)
2163 struct window
*parent
= NULL
;
2165 user_handle_t
*data
;
2167 struct unicode_str cls_name
= get_req_unicode_str();
2168 atom_t atom
= req
->atom
;
2169 struct desktop
*desktop
= NULL
;
2171 if (cls_name
.len
&& !(atom
= find_global_atom( NULL
, &cls_name
))) return;
2175 if (!(desktop
= get_desktop_obj( current
->process
, req
->desktop
, DESKTOP_ENUMERATE
))) return;
2176 parent
= desktop
->top_window
;
2180 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
2181 if (!parent
&& !(desktop
= get_thread_desktop( current
, 0 ))) return;
2185 total
= get_children_windows( parent
, atom
, req
->tid
, NULL
, 0 );
2187 total
= get_children_windows( desktop
->top_window
, atom
, req
->tid
, NULL
, 0 ) +
2188 get_children_windows( desktop
->msg_window
, atom
, req
->tid
, NULL
, 0 );
2190 reply
->count
= total
;
2191 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
2192 if (len
&& ((data
= set_reply_data_size( len
))))
2194 if (parent
) get_children_windows( parent
, atom
, req
->tid
, data
, len
/ sizeof(user_handle_t
) );
2197 total
= get_children_windows( desktop
->top_window
, atom
, req
->tid
,
2198 data
, len
/ sizeof(user_handle_t
) );
2200 len
-= total
* sizeof(user_handle_t
);
2201 if (len
>= sizeof(user_handle_t
))
2202 get_children_windows( desktop
->msg_window
, atom
, req
->tid
,
2203 data
, len
/ sizeof(user_handle_t
) );
2206 if (desktop
) release_object( desktop
);
2210 /* get a list of the window children that contain a given point */
2211 DECL_HANDLER(get_window_children_from_point
)
2213 struct user_handle_array array
;
2214 struct window
*parent
= get_window( req
->parent
);
2217 if (!parent
) return;
2219 array
.handles
= NULL
;
2222 if (!all_windows_from_point( parent
, req
->x
, req
->y
, &array
)) return;
2224 reply
->count
= array
.count
;
2225 len
= min( get_reply_max_size(), array
.count
* sizeof(user_handle_t
) );
2226 if (len
) set_reply_data_ptr( array
.handles
, len
);
2227 else free( array
.handles
);
2231 /* get window tree information from a window handle */
2232 DECL_HANDLER(get_window_tree
)
2234 struct window
*ptr
, *win
= get_window( req
->handle
);
2240 reply
->next_sibling
= 0;
2241 reply
->prev_sibling
= 0;
2242 reply
->first_sibling
= 0;
2243 reply
->last_sibling
= 0;
2244 reply
->first_child
= 0;
2245 reply
->last_child
= 0;
2249 struct window
*parent
= win
->parent
;
2250 reply
->parent
= parent
->handle
;
2251 reply
->owner
= win
->owner
;
2254 if ((ptr
= get_next_window( win
))) reply
->next_sibling
= ptr
->handle
;
2255 if ((ptr
= get_prev_window( win
))) reply
->prev_sibling
= ptr
->handle
;
2257 if ((ptr
= get_first_child( parent
))) reply
->first_sibling
= ptr
->handle
;
2258 if ((ptr
= get_last_child( parent
))) reply
->last_sibling
= ptr
->handle
;
2260 if ((ptr
= get_first_child( win
))) reply
->first_child
= ptr
->handle
;
2261 if ((ptr
= get_last_child( win
))) reply
->last_child
= ptr
->handle
;
2265 /* set the position and Z order of a window */
2266 DECL_HANDLER(set_window_pos
)
2268 rectangle_t window_rect
, client_rect
, visible_rect
, surface_rect
, valid_rect
;
2269 const rectangle_t
*extra_rects
= get_req_data();
2270 struct window
*previous
= NULL
;
2271 struct window
*top
, *win
= get_window( req
->handle
);
2272 unsigned int flags
= req
->swp_flags
;
2275 if (!win
->parent
) flags
|= SWP_NOZORDER
; /* no Z order for the desktop */
2277 if (!(flags
& SWP_NOZORDER
))
2279 switch ((int)req
->previous
)
2281 case 0: /* HWND_TOP */
2282 previous
= WINPTR_TOP
;
2284 case 1: /* HWND_BOTTOM */
2285 previous
= WINPTR_BOTTOM
;
2287 case -1: /* HWND_TOPMOST */
2288 previous
= WINPTR_TOPMOST
;
2290 case -2: /* HWND_NOTOPMOST */
2291 previous
= WINPTR_NOTOPMOST
;
2294 if (!(previous
= get_window( req
->previous
))) return;
2295 /* previous must be a sibling */
2296 if (previous
->parent
!= win
->parent
)
2298 set_error( STATUS_INVALID_PARAMETER
);
2303 if (previous
== win
) flags
|= SWP_NOZORDER
; /* nothing to do */
2306 /* windows that use UpdateLayeredWindow don't trigger repaints */
2307 if ((win
->ex_style
& WS_EX_LAYERED
) && !win
->is_layered
) flags
|= SWP_NOREDRAW
;
2309 /* window rectangle must be ordered properly */
2310 if (req
->window
.right
< req
->window
.left
|| req
->window
.bottom
< req
->window
.top
)
2312 set_error( STATUS_INVALID_PARAMETER
);
2316 window_rect
= req
->window
;
2317 client_rect
= req
->client
;
2318 if (get_req_data_size() >= sizeof(rectangle_t
)) visible_rect
= extra_rects
[0];
2319 else visible_rect
= window_rect
;
2320 if (get_req_data_size() >= 2 * sizeof(rectangle_t
)) surface_rect
= extra_rects
[1];
2321 else surface_rect
= visible_rect
;
2322 if (get_req_data_size() >= 3 * sizeof(rectangle_t
)) valid_rect
= extra_rects
[2];
2323 else valid_rect
= empty_rect
;
2324 if (win
->parent
&& win
->parent
->ex_style
& WS_EX_LAYOUTRTL
)
2326 mirror_rect( &win
->parent
->client_rect
, &window_rect
);
2327 mirror_rect( &win
->parent
->client_rect
, &visible_rect
);
2328 mirror_rect( &win
->parent
->client_rect
, &client_rect
);
2329 mirror_rect( &win
->parent
->client_rect
, &surface_rect
);
2330 mirror_rect( &win
->parent
->client_rect
, &valid_rect
);
2333 win
->paint_flags
= (win
->paint_flags
& ~PAINT_CLIENT_FLAGS
) | (req
->paint_flags
& PAINT_CLIENT_FLAGS
);
2334 if (win
->paint_flags
& PAINT_HAS_PIXEL_FORMAT
) update_pixel_format_flags( win
);
2336 set_window_pos( win
, previous
, flags
, &window_rect
, &client_rect
,
2337 &visible_rect
, &surface_rect
, &valid_rect
);
2339 reply
->new_style
= win
->style
;
2340 reply
->new_ex_style
= win
->ex_style
;
2342 top
= get_top_clipping_window( win
);
2343 if (is_visible( top
) && (top
->paint_flags
& PAINT_HAS_SURFACE
))
2345 reply
->surface_win
= top
->handle
;
2346 reply
->needs_update
= !!(top
->paint_flags
& (PAINT_HAS_PIXEL_FORMAT
| PAINT_PIXEL_FORMAT_CHILD
));
2351 /* get the window and client rectangles of a window */
2352 DECL_HANDLER(get_window_rectangles
)
2354 struct window
*win
= get_window( req
->handle
);
2358 reply
->window
= win
->window_rect
;
2359 reply
->client
= win
->client_rect
;
2361 switch (req
->relative
)
2364 offset_rect( &reply
->window
, -win
->client_rect
.left
, -win
->client_rect
.top
);
2365 offset_rect( &reply
->client
, -win
->client_rect
.left
, -win
->client_rect
.top
);
2366 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_rect( &win
->client_rect
, &reply
->window
);
2369 offset_rect( &reply
->window
, -win
->window_rect
.left
, -win
->window_rect
.top
);
2370 offset_rect( &reply
->client
, -win
->window_rect
.left
, -win
->window_rect
.top
);
2371 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_rect( &win
->window_rect
, &reply
->client
);
2374 if (win
->parent
&& win
->parent
->ex_style
& WS_EX_LAYOUTRTL
)
2376 mirror_rect( &win
->parent
->client_rect
, &reply
->window
);
2377 mirror_rect( &win
->parent
->client_rect
, &reply
->client
);
2381 client_to_screen_rect( win
->parent
, &reply
->window
);
2382 client_to_screen_rect( win
->parent
, &reply
->client
);
2385 set_error( STATUS_INVALID_PARAMETER
);
2388 map_dpi_rect( win
, &reply
->window
, win
->dpi
, req
->dpi
);
2389 map_dpi_rect( win
, &reply
->client
, win
->dpi
, req
->dpi
);
2393 /* get the window text */
2394 DECL_HANDLER(get_window_text
)
2396 struct window
*win
= get_window( req
->handle
);
2398 if (win
&& win
->text
)
2400 reply
->length
= strlenW( win
->text
);
2401 set_reply_data( win
->text
, min( reply
->length
* sizeof(WCHAR
), get_reply_max_size() ));
2406 /* set the window text */
2407 DECL_HANDLER(set_window_text
)
2409 struct window
*win
= get_window( req
->handle
);
2414 data_size_t len
= get_req_data_size() / sizeof(WCHAR
);
2417 if (!(text
= mem_alloc( (len
+1) * sizeof(WCHAR
) ))) return;
2418 memcpy( text
, get_req_data(), len
* sizeof(WCHAR
) );
2427 /* get the coordinates offset between two windows */
2428 DECL_HANDLER(get_windows_offset
)
2431 int x
, y
, mirror_from
= 0, mirror_to
= 0;
2433 reply
->x
= reply
->y
= 0;
2436 if (!(win
= get_window( req
->from
))) return;
2437 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_from
= 1;
2438 x
= mirror_from
? win
->client_rect
.right
- win
->client_rect
.left
: 0;
2440 client_to_screen( win
, &x
, &y
);
2441 map_dpi_point( win
, &x
, &y
, win
->dpi
, req
->dpi
);
2447 if (!(win
= get_window( req
->to
))) return;
2448 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_to
= 1;
2449 x
= mirror_to
? win
->client_rect
.right
- win
->client_rect
.left
: 0;
2451 client_to_screen( win
, &x
, &y
);
2452 map_dpi_point( win
, &x
, &y
, win
->dpi
, req
->dpi
);
2456 if (mirror_from
) reply
->x
= -reply
->x
;
2457 reply
->mirror
= mirror_from
^ mirror_to
;
2461 /* get the visible region of a window */
2462 DECL_HANDLER(get_visible_region
)
2464 struct region
*region
;
2465 struct window
*top
, *win
= get_window( req
->window
);
2469 top
= get_top_clipping_window( win
);
2470 if ((region
= get_visible_region( win
, req
->flags
)))
2473 map_win_region_to_screen( win
, region
);
2474 data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
2475 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
2477 reply
->top_win
= top
->handle
;
2478 reply
->top_rect
= top
->surface_rect
;
2480 if (!is_desktop_window(win
))
2482 reply
->win_rect
= (req
->flags
& DCX_WINDOW
) ? win
->window_rect
: win
->client_rect
;
2483 client_to_screen_rect( top
->parent
, &reply
->top_rect
);
2484 client_to_screen_rect( win
->parent
, &reply
->win_rect
);
2488 reply
->win_rect
.left
= 0;
2489 reply
->win_rect
.top
= 0;
2490 reply
->win_rect
.right
= win
->client_rect
.right
- win
->client_rect
.left
;
2491 reply
->win_rect
.bottom
= win
->client_rect
.bottom
- win
->client_rect
.top
;
2493 reply
->paint_flags
= win
->paint_flags
& PAINT_CLIENT_FLAGS
;
2497 /* get the surface visible region of a window */
2498 DECL_HANDLER(get_surface_region
)
2500 struct region
*region
;
2501 struct window
*win
= get_window( req
->window
);
2503 if (!win
|| !is_visible( win
)) return;
2505 if ((region
= get_surface_region( win
)))
2507 rectangle_t
*data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
2508 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
2510 reply
->visible_rect
= win
->visible_rect
;
2514 /* get the window region */
2515 DECL_HANDLER(get_window_region
)
2518 struct window
*win
= get_window( req
->window
);
2521 if (!win
->win_region
) return;
2523 if (win
->ex_style
& WS_EX_LAYOUTRTL
)
2525 struct region
*region
= create_empty_region();
2527 if (!region
) return;
2528 if (!copy_region( region
, win
->win_region
))
2530 free_region( region
);
2533 mirror_region( &win
->window_rect
, region
);
2534 data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
2536 else data
= get_region_data( win
->win_region
, get_reply_max_size(), &reply
->total_size
);
2538 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
2542 /* set the window region */
2543 DECL_HANDLER(set_window_region
)
2545 struct region
*region
= NULL
;
2546 struct window
*win
= get_window( req
->window
);
2550 if (get_req_data_size()) /* no data means remove the region completely */
2552 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
2554 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_region( &win
->window_rect
, region
);
2556 set_window_region( win
, region
, req
->redraw
);
2560 /* get a window update region */
2561 DECL_HANDLER(get_update_region
)
2564 unsigned int flags
= req
->flags
;
2565 struct window
*from_child
= NULL
;
2566 struct window
*win
= get_window( req
->window
);
2571 if (req
->from_child
)
2575 if (!(from_child
= get_window( req
->from_child
))) return;
2577 /* make sure from_child is a child of win */
2579 while (ptr
&& ptr
!= win
) ptr
= ptr
->parent
;
2582 set_error( STATUS_INVALID_PARAMETER
);
2587 if (flags
& UPDATE_DELAYED_ERASE
) /* this means that the previous call didn't erase */
2589 if (from_child
) from_child
->paint_flags
|= PAINT_DELAYED_ERASE
;
2590 else win
->paint_flags
|= PAINT_DELAYED_ERASE
;
2593 reply
->flags
= get_window_update_flags( win
, from_child
, flags
, &win
);
2594 reply
->child
= win
->handle
;
2596 if (flags
& UPDATE_NOREGION
) return;
2598 if (win
->update_region
)
2600 /* convert update region to screen coordinates */
2601 struct region
*region
= create_empty_region();
2603 if (!region
) return;
2604 if (!copy_region( region
, win
->update_region
))
2606 free_region( region
);
2609 if ((flags
& UPDATE_CLIPCHILDREN
) && (win
->style
& WS_CLIPCHILDREN
))
2610 clip_children( win
, NULL
, region
, win
->client_rect
.left
- win
->window_rect
.left
,
2611 win
->client_rect
.top
- win
->window_rect
.top
);
2612 map_win_region_to_screen( win
, region
);
2613 if (!(data
= get_region_data_and_free( region
, get_reply_max_size(),
2614 &reply
->total_size
))) return;
2615 set_reply_data_ptr( data
, reply
->total_size
);
2618 if (reply
->flags
& (UPDATE_PAINT
|UPDATE_INTERNALPAINT
)) /* validate everything */
2620 validate_parents( win
);
2621 validate_whole_window( win
);
2625 if (reply
->flags
& UPDATE_NONCLIENT
) validate_non_client( win
);
2626 if (reply
->flags
& UPDATE_ERASE
)
2628 win
->paint_flags
&= ~(PAINT_ERASE
| PAINT_DELAYED_ERASE
);
2629 /* desktop window only gets erased, not repainted */
2630 if (is_desktop_window(win
)) validate_whole_window( win
);
2636 /* update the z order of a window so that a given rectangle is fully visible */
2637 DECL_HANDLER(update_window_zorder
)
2639 rectangle_t tmp
, rect
= req
->rect
;
2640 struct window
*ptr
, *win
= get_window( req
->window
);
2642 if (!win
|| !win
->parent
|| !is_visible( win
)) return; /* nothing to do */
2643 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_rect( &win
->client_rect
, &rect
);
2644 offset_rect( &rect
, win
->client_rect
.left
, win
->client_rect
.top
);
2646 LIST_FOR_EACH_ENTRY( ptr
, &win
->parent
->children
, struct window
, entry
)
2648 if (ptr
== win
) break;
2649 if (!(ptr
->style
& WS_VISIBLE
)) continue;
2650 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
2651 if (ptr
->is_layered
&& (ptr
->layered_flags
& LWA_COLORKEY
)) continue;
2652 if (!intersect_rect( &tmp
, &ptr
->visible_rect
, &rect
)) continue;
2653 if (ptr
->win_region
)
2656 offset_rect( &tmp
, -ptr
->window_rect
.left
, -ptr
->window_rect
.top
);
2657 if (!rect_in_region( ptr
->win_region
, &tmp
)) continue;
2659 /* found a window obscuring the rectangle, now move win above this one */
2660 /* making sure to not violate the topmost rule */
2661 if (!(ptr
->ex_style
& WS_EX_TOPMOST
) || (win
->ex_style
& WS_EX_TOPMOST
))
2663 list_remove( &win
->entry
);
2664 list_add_before( &ptr
->entry
, &win
->entry
);
2671 /* mark parts of a window as needing a redraw */
2672 DECL_HANDLER(redraw_window
)
2674 unsigned int flags
= req
->flags
;
2675 struct region
*region
= NULL
;
2680 if (!(win
= get_desktop_window( current
))) return;
2684 if (!(win
= get_window( req
->window
))) return;
2685 if (is_desktop_window( win
)) flags
&= ~RDW_ALLCHILDREN
;
2688 if (!is_visible( win
)) return; /* nothing to do */
2690 if (flags
& (RDW_VALIDATE
|RDW_INVALIDATE
))
2692 if (get_req_data_size()) /* no data means whole rectangle */
2694 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
2696 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_region( &win
->client_rect
, region
);
2700 redraw_window( win
, region
, (flags
& RDW_INVALIDATE
) && (flags
& RDW_FRAME
), flags
);
2701 if (region
) free_region( region
);
2705 /* set a window property */
2706 DECL_HANDLER(set_window_property
)
2708 struct unicode_str name
= get_req_unicode_str();
2709 struct window
*win
= get_window( req
->window
);
2715 atom_t atom
= add_global_atom( NULL
, &name
);
2718 set_property( win
, atom
, req
->data
, PROP_TYPE_STRING
);
2719 release_global_atom( NULL
, atom
);
2722 else set_property( win
, req
->atom
, req
->data
, PROP_TYPE_ATOM
);
2726 /* remove a window property */
2727 DECL_HANDLER(remove_window_property
)
2729 struct unicode_str name
= get_req_unicode_str();
2730 struct window
*win
= get_window( req
->window
);
2734 atom_t atom
= name
.len
? find_global_atom( NULL
, &name
) : req
->atom
;
2735 if (atom
) reply
->data
= remove_property( win
, atom
);
2740 /* get a window property */
2741 DECL_HANDLER(get_window_property
)
2743 struct unicode_str name
= get_req_unicode_str();
2744 struct window
*win
= get_window( req
->window
);
2748 atom_t atom
= name
.len
? find_global_atom( NULL
, &name
) : req
->atom
;
2749 if (atom
) reply
->data
= get_property( win
, atom
);
2754 /* get the list of properties of a window */
2755 DECL_HANDLER(get_window_properties
)
2757 property_data_t
*data
;
2758 int i
, count
, max
= get_reply_max_size() / sizeof(*data
);
2759 struct window
*win
= get_window( req
->window
);
2764 for (i
= count
= 0; i
< win
->prop_inuse
; i
++)
2765 if (win
->properties
[i
].type
!= PROP_TYPE_FREE
) count
++;
2766 reply
->total
= count
;
2768 if (count
> max
) count
= max
;
2769 if (!count
|| !(data
= set_reply_data_size( count
* sizeof(*data
) ))) return;
2771 for (i
= 0; i
< win
->prop_inuse
&& count
; i
++)
2773 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
2774 data
->atom
= win
->properties
[i
].atom
;
2775 data
->string
= (win
->properties
[i
].type
== PROP_TYPE_STRING
);
2776 data
->data
= win
->properties
[i
].data
;
2783 /* get the new window pointer for a global window, checking permissions */
2784 /* helper for set_global_windows request */
2785 static int get_new_global_window( struct window
**win
, user_handle_t handle
)
2794 set_error( STATUS_ACCESS_DENIED
);
2797 *win
= get_window( handle
);
2798 return (*win
!= NULL
);
2801 /* Set/get the global windows */
2802 DECL_HANDLER(set_global_windows
)
2804 struct window
*new_shell_window
= shell_window
;
2805 struct window
*new_shell_listview
= shell_listview
;
2806 struct window
*new_progman_window
= progman_window
;
2807 struct window
*new_taskman_window
= taskman_window
;
2809 reply
->old_shell_window
= shell_window
? shell_window
->handle
: 0;
2810 reply
->old_shell_listview
= shell_listview
? shell_listview
->handle
: 0;
2811 reply
->old_progman_window
= progman_window
? progman_window
->handle
: 0;
2812 reply
->old_taskman_window
= taskman_window
? taskman_window
->handle
: 0;
2814 if (req
->flags
& SET_GLOBAL_SHELL_WINDOWS
)
2816 if (!get_new_global_window( &new_shell_window
, req
->shell_window
)) return;
2817 if (!get_new_global_window( &new_shell_listview
, req
->shell_listview
)) return;
2819 if (req
->flags
& SET_GLOBAL_PROGMAN_WINDOW
)
2821 if (!get_new_global_window( &new_progman_window
, req
->progman_window
)) return;
2823 if (req
->flags
& SET_GLOBAL_TASKMAN_WINDOW
)
2825 if (!get_new_global_window( &new_taskman_window
, req
->taskman_window
)) return;
2827 shell_window
= new_shell_window
;
2828 shell_listview
= new_shell_listview
;
2829 progman_window
= new_progman_window
;
2830 taskman_window
= new_taskman_window
;
2833 /* retrieve layered info for a window */
2834 DECL_HANDLER(get_window_layered_info
)
2836 struct window
*win
= get_window( req
->handle
);
2840 if (win
->is_layered
)
2842 reply
->color_key
= win
->color_key
;
2843 reply
->alpha
= win
->alpha
;
2844 reply
->flags
= win
->layered_flags
;
2846 else set_win32_error( ERROR_INVALID_WINDOW_HANDLE
);
2850 /* set layered info for a window */
2851 DECL_HANDLER(set_window_layered_info
)
2853 struct window
*win
= get_window( req
->handle
);
2857 if (win
->ex_style
& WS_EX_LAYERED
)
2859 int was_layered
= win
->is_layered
;
2861 if (req
->flags
& LWA_ALPHA
) win
->alpha
= req
->alpha
;
2862 else if (!win
->is_layered
) win
->alpha
= 0; /* alpha init value is 0 */
2864 win
->color_key
= req
->color_key
;
2865 win
->layered_flags
= req
->flags
;
2866 win
->is_layered
= 1;
2867 /* repaint since we know now it's not going to use UpdateLayeredWindow */
2868 if (!was_layered
) redraw_window( win
, 0, 1, RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
);
2870 else set_win32_error( ERROR_INVALID_WINDOW_HANDLE
);