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
27 #define WIN32_NO_STATUS
39 /* a window property */
42 unsigned short type
; /* property type (see below) */
43 atom_t atom
; /* property atom */
44 lparam_t data
; /* property data (user-defined storage) */
49 PROP_TYPE_FREE
, /* free entry */
50 PROP_TYPE_STRING
, /* atom that was originally a string */
51 PROP_TYPE_ATOM
/* plain atom */
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 */
106 window_dump
, /* dump */
107 no_add_queue
, /* add_queue */
108 NULL
, /* remove_queue */
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
;
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
);
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 );
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
);
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
));
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
;
298 list_add_before( entry
, &win
->entry
);
302 list_add_after( &previous
->entry
, &win
->entry
);
303 if (!(previous
->ex_style
& WS_EX_TOPMOST
)) win
->ex_style
&= ~WS_EX_TOPMOST
;
306 struct window
*next
= get_next_window( win
);
307 if (next
&& (next
->ex_style
& WS_EX_TOPMOST
)) win
->ex_style
|= WS_EX_TOPMOST
;
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
)
320 /* make sure parent is not a child of window */
321 for (ptr
= parent
; ptr
; ptr
= ptr
->parent
)
325 set_error( STATUS_INVALID_PARAMETER
);
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
);
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
) );
369 free( array
->handles
);
370 set_error( STATUS_NO_MEMORY
);
373 array
->handles
= new_array
;
374 array
->total
= new_total
;
376 array
->handles
[array
->count
++] = handle
;
380 /* set a window property */
381 static void set_property( struct window
*win
, atom_t atom
, lparam_t data
, enum property_type type
)
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
)
394 if (win
->properties
[i
].atom
== atom
)
396 win
->properties
[i
].type
= type
;
397 win
->properties
[i
].data
= data
;
402 /* need to add an entry */
403 if (!grab_global_atom( NULL
, atom
)) return;
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
);
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
)
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? */
446 /* find a window property */
447 static lparam_t
get_property( struct window
*win
, atom_t atom
)
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? */
460 /* destroy all properties of a window */
461 static inline void destroy_properties( struct window
*win
)
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
;
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 );
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
);
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
)
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
);
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
);
551 /* parent must be on the same desktop */
552 if (parent
&& parent
->desktop
!= desktop
)
554 set_error( STATUS_ACCESS_DENIED
);
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
;
565 win
->last_active
= win
->handle
;
566 win
->win_region
= NULL
;
567 win
->update_region
= NULL
;
576 win
->dpi_awareness
= DPI_AWARENESS_PER_MONITOR_AWARE
;
581 win
->paint_flags
= 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
);
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
);
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
);
623 assert( !desktop
->msg_window
);
624 desktop
->msg_window
= win
;
628 current
->desktop_users
++;
636 free_user_handle( win
->handle
);
639 release_object( win
);
641 release_object( desktop
);
642 release_class( class );
646 /* destroy all windows belonging to a given thread */
647 void destroy_thread_windows( struct thread
*thread
)
649 user_handle_t handle
= 0;
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
);
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
;
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
);
701 /* set last active for window and its owners */
705 owner
->last_active
= win
->handle
;
706 owner
= get_user_object( owner
->owner
, USER_WINDOW
);
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
);
768 /* check if window and all its ancestors are visible */
769 static int is_visible( const struct window
*win
)
773 if (!(win
->style
& WS_VISIBLE
)) return 0;
775 /* if parent is minimized children are not visible */
776 if (win
&& (win
->style
& WS_MINIMIZE
)) return 0;
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
);
786 return is_visible( win
);
789 int is_window_transparent( user_handle_t window
)
791 struct window
*win
= get_user_object( window
, USER_WINDOW
);
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 */
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
)
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;
843 if (count
>= max_count
) break;
844 handles
[count
] = ptr
->handle
;
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
)
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
)
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
))
894 /* now add window to the array */
895 if (!add_handle_to_array( array
, ptr
->handle
)) return 0;
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
)
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 */
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;
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
))
983 else if (!(ptr
->style
& WS_MINIMIZE
)) /* explore its children */
984 ret
= find_child_to_repaint( ptr
, thread
);
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
;
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
);
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
;
1022 win
->paint_flags
&= ~PAINT_INTERNAL
;
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
);
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
)
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
))
1078 offset_region( tmp
, offset_x
, offset_y
);
1079 if (!(region
= subtract_region( region
, region
, tmp
))) break;
1080 if (is_region_empty( region
)) break;
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
)
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
)
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
))
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
);
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
;
1149 set_region_client_rect( region
, win
);
1150 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
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 */
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;
1187 offset_region( region
, -offset_x
, -offset_y
); /* make it relative to target window */
1191 if (tmp
) free_region( tmp
);
1192 free_region( region
);
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
)
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
))
1227 if (!clip_pixel_format_children( ptr
, clip
, region
, offset_x
+ ptr
->client_rect
.left
,
1228 offset_y
+ ptr
->client_rect
.top
))
1231 free_region( clip
);
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
))
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
);
1269 if (clip
) free_region( clip
);
1270 free_region( region
);
1275 /* get the window class of a window */
1276 struct window_class
* get_window_class( user_handle_t window
)
1279 if (!(win
= get_window( window
))) return NULL
;
1280 if (!win
->class) set_error( STATUS_ACCESS_DENIED
);
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
))
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
);
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
)
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
);
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
);
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
;
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
);
1373 set_update_region( win
, region
);
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
;
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
);
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 */
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
)
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
);
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;
1481 /* map to parent client coords */
1482 offset_x
+= win
->window_rect
.left
;
1483 offset_y
+= win
->window_rect
.top
;
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
);
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
))
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
);
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
;
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
)
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
;
1647 if (!(ptr
->style
& WS_VISIBLE
)) continue;
1648 if ((ret
= get_update_flags( ptr
, flags
)) != 0)
1653 if ((ret
= get_child_update_flags( ptr
, NULL
, flags
, child
))) break;
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
)
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
))
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) */
1699 if ((ret
= get_update_flags( win
, flags
)))
1707 /* now check children */
1709 if (flags
& UPDATE_NOCHILDREN
) return 0;
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
)))
1722 from_sibling
= from_sibling
->parent
;
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
);
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
);
1758 free_region( exposed_rgn
);
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_composited
? union_region( new_vis_rgn
, old_vis_rgn
, new_vis_rgn
)
1770 : subtract_region( new_vis_rgn
, old_vis_rgn
, new_vis_rgn
))
1772 if (!is_region_empty( new_vis_rgn
))
1774 /* make it relative to parent */
1775 offset_region( new_vis_rgn
, old_window_rect
->left
, old_window_rect
->top
);
1776 redraw_window( win
->parent
, new_vis_rgn
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1780 free_region( new_vis_rgn
);
1785 /* set the window and client rectangles, updating the update region if necessary */
1786 static void set_window_pos( struct window
*win
, struct window
*previous
,
1787 unsigned int swp_flags
, const rectangle_t
*window_rect
,
1788 const rectangle_t
*client_rect
, const rectangle_t
*visible_rect
,
1789 const rectangle_t
*surface_rect
, const rectangle_t
*valid_rect
)
1791 struct region
*old_vis_rgn
= NULL
, *exposed_rgn
= NULL
;
1792 const rectangle_t old_window_rect
= win
->window_rect
;
1793 const rectangle_t old_visible_rect
= win
->visible_rect
;
1794 const rectangle_t old_client_rect
= win
->client_rect
;
1796 int client_changed
, frame_changed
;
1797 int visible
= (win
->style
& WS_VISIBLE
) || (swp_flags
& SWP_SHOWWINDOW
);
1798 int zorder_changed
= 0;
1800 if (win
->parent
&& !is_visible( win
->parent
)) visible
= 0;
1802 if (visible
&& !(old_vis_rgn
= get_visible_region( win
, DCX_WINDOW
))) return;
1804 /* set the new window info before invalidating anything */
1806 win
->window_rect
= *window_rect
;
1807 win
->visible_rect
= *visible_rect
;
1808 win
->surface_rect
= *surface_rect
;
1809 win
->client_rect
= *client_rect
;
1810 if (!(swp_flags
& SWP_NOZORDER
) && win
->parent
) zorder_changed
|= link_window( win
, previous
);
1811 if (swp_flags
& SWP_SHOWWINDOW
) win
->style
|= WS_VISIBLE
;
1812 else if (swp_flags
& SWP_HIDEWINDOW
) win
->style
&= ~WS_VISIBLE
;
1814 /* keep children at the same position relative to top right corner when the parent is mirrored */
1815 if (win
->ex_style
& WS_EX_LAYOUTRTL
)
1817 struct window
*child
;
1818 int old_size
= old_client_rect
.right
- old_client_rect
.left
;
1819 int new_size
= win
->client_rect
.right
- win
->client_rect
.left
;
1821 if (old_size
!= new_size
) LIST_FOR_EACH_ENTRY( child
, &win
->children
, struct window
, entry
)
1823 offset_rect( &child
->window_rect
, new_size
- old_size
, 0 );
1824 offset_rect( &child
->visible_rect
, new_size
- old_size
, 0 );
1825 offset_rect( &child
->surface_rect
, new_size
- old_size
, 0 );
1826 offset_rect( &child
->client_rect
, new_size
- old_size
, 0 );
1830 /* reset cursor clip rectangle when the desktop changes size */
1831 if (win
== win
->desktop
->top_window
) win
->desktop
->cursor
.clip
= *window_rect
;
1833 /* if the window is not visible, everything is easy */
1834 if (!visible
) return;
1836 /* expose anything revealed by the change */
1838 if (!(swp_flags
& SWP_NOREDRAW
))
1839 exposed_rgn
= expose_window( win
, &old_window_rect
, old_vis_rgn
, zorder_changed
);
1841 if (!(win
->style
& WS_VISIBLE
))
1843 /* clear the update region since the window is no longer visible */
1844 validate_whole_window( win
);
1845 validate_children( win
);
1849 /* crop update region to the new window rect */
1851 if (win
->update_region
)
1853 if (get_window_visible_rect( win
, &rect
, 1 ))
1855 struct region
*tmp
= create_empty_region();
1858 set_region_rect( tmp
, &rect
);
1859 if (intersect_region( tmp
, win
->update_region
, tmp
))
1860 set_update_region( win
, tmp
);
1865 else set_update_region( win
, NULL
); /* visible rect is empty */
1868 /* crop children regions to the new window rect */
1870 if (get_window_visible_rect( win
, &rect
, 0 ))
1872 /* map to client coords */
1873 offset_rect( &rect
, win
->window_rect
.left
- win
->client_rect
.left
,
1874 win
->window_rect
.top
- win
->client_rect
.top
);
1875 crop_children_update_region( win
, &rect
);
1877 else crop_children_update_region( win
, NULL
);
1879 if (swp_flags
& SWP_NOREDRAW
) goto done
; /* do not repaint anything */
1881 /* expose the whole non-client area if it changed in any way */
1883 if (swp_flags
& SWP_NOCOPYBITS
)
1885 frame_changed
= ((swp_flags
& SWP_FRAMECHANGED
) ||
1886 memcmp( window_rect
, &old_window_rect
, sizeof(old_window_rect
) ) ||
1887 memcmp( visible_rect
, &old_visible_rect
, sizeof(old_visible_rect
) ));
1888 client_changed
= memcmp( client_rect
, &old_client_rect
, sizeof(old_client_rect
) );
1892 /* assume the bits have been moved to follow the window rect */
1893 int x_offset
= window_rect
->left
- old_window_rect
.left
;
1894 int y_offset
= window_rect
->top
- old_window_rect
.top
;
1895 frame_changed
= ((swp_flags
& SWP_FRAMECHANGED
) ||
1896 window_rect
->right
- old_window_rect
.right
!= x_offset
||
1897 window_rect
->bottom
- old_window_rect
.bottom
!= y_offset
||
1898 visible_rect
->left
- old_visible_rect
.left
!= x_offset
||
1899 visible_rect
->right
- old_visible_rect
.right
!= x_offset
||
1900 visible_rect
->top
- old_visible_rect
.top
!= y_offset
||
1901 visible_rect
->bottom
- old_visible_rect
.bottom
!= y_offset
);
1902 client_changed
= (client_rect
->left
- old_client_rect
.left
!= x_offset
||
1903 client_rect
->right
- old_client_rect
.right
!= x_offset
||
1904 client_rect
->top
- old_client_rect
.top
!= y_offset
||
1905 client_rect
->bottom
- old_client_rect
.bottom
!= y_offset
||
1906 memcmp( valid_rect
, client_rect
, sizeof(*client_rect
) ));
1909 if (frame_changed
|| client_changed
)
1911 struct region
*win_rgn
= old_vis_rgn
; /* reuse previous region */
1913 set_region_rect( win_rgn
, window_rect
);
1914 if (!is_rect_empty( valid_rect
))
1916 /* subtract the valid portion of client rect from the total region */
1917 struct region
*tmp
= create_empty_region();
1920 set_region_rect( tmp
, valid_rect
);
1921 /* subtract update region since invalid parts of the valid rect won't be copied */
1922 if (win
->update_region
)
1924 offset_region( tmp
, -window_rect
->left
, -window_rect
->top
);
1925 subtract_region( tmp
, tmp
, win
->update_region
);
1926 offset_region( tmp
, window_rect
->left
, window_rect
->top
);
1928 if (subtract_region( tmp
, win_rgn
, tmp
)) win_rgn
= tmp
;
1929 else free_region( tmp
);
1932 if (!is_desktop_window(win
))
1933 offset_region( win_rgn
, -client_rect
->left
, -client_rect
->top
);
1936 union_region( exposed_rgn
, exposed_rgn
, win_rgn
);
1937 if (win_rgn
!= old_vis_rgn
) free_region( win_rgn
);
1941 exposed_rgn
= win_rgn
;
1942 if (win_rgn
== old_vis_rgn
) old_vis_rgn
= NULL
;
1947 redraw_window( win
, exposed_rgn
, 1, RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
1950 if (old_vis_rgn
) free_region( old_vis_rgn
);
1951 if (exposed_rgn
) free_region( exposed_rgn
);
1952 clear_error(); /* we ignore out of memory errors once the new rects have been set */
1956 /* set the window region, updating the update region if necessary */
1957 static void set_window_region( struct window
*win
, struct region
*region
, int redraw
)
1959 struct region
*old_vis_rgn
= NULL
, *exposed_rgn
;
1961 /* no need to redraw if window is not visible */
1962 if (redraw
&& !is_visible( win
)) redraw
= 0;
1964 if (redraw
) old_vis_rgn
= get_visible_region( win
, DCX_WINDOW
);
1966 if (win
->win_region
) free_region( win
->win_region
);
1967 win
->win_region
= region
;
1969 /* expose anything revealed by the change */
1970 if (old_vis_rgn
&& ((exposed_rgn
= expose_window( win
, &win
->window_rect
, old_vis_rgn
, 0 ))))
1972 redraw_window( win
, exposed_rgn
, 1, RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
1973 free_region( exposed_rgn
);
1976 if (old_vis_rgn
) free_region( old_vis_rgn
);
1977 clear_error(); /* we ignore out of memory errors since the region has been set */
1981 /* destroy a window */
1982 void free_window_handle( struct window
*win
)
1984 struct window
*child
, *next
;
1986 assert( win
->handle
);
1988 /* hide the window */
1989 if (is_visible(win
))
1991 struct region
*vis_rgn
= get_visible_region( win
, DCX_WINDOW
);
1992 win
->style
&= ~WS_VISIBLE
;
1995 struct region
*exposed_rgn
= expose_window( win
, &win
->window_rect
, vis_rgn
, 0 );
1996 if (exposed_rgn
) free_region( exposed_rgn
);
1997 free_region( vis_rgn
);
1999 validate_whole_window( win
);
2000 validate_children( win
);
2003 /* destroy all children */
2004 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &win
->children
, struct window
, entry
)
2006 if (!child
->handle
) continue;
2007 if (!win
->thread
|| !child
->thread
|| win
->thread
== child
->thread
)
2008 free_window_handle( child
);
2010 send_notify_message( child
->handle
, WM_WINE_DESTROYWINDOW
, 0, 0 );
2012 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &win
->children
, struct window
, entry
)
2014 if (!child
->handle
) continue;
2015 if (!win
->thread
|| !child
->thread
|| win
->thread
== child
->thread
)
2016 free_window_handle( child
);
2018 send_notify_message( child
->handle
, WM_WINE_DESTROYWINDOW
, 0, 0 );
2021 /* reset global window pointers, if the corresponding window is destroyed */
2022 if (win
== shell_window
) shell_window
= NULL
;
2023 if (win
== shell_listview
) shell_listview
= NULL
;
2024 if (win
== progman_window
) progman_window
= NULL
;
2025 if (win
== taskman_window
) taskman_window
= NULL
;
2026 free_hotkeys( win
->desktop
, win
->handle
);
2027 cleanup_clipboard_window( win
->desktop
, win
->handle
);
2028 destroy_properties( win
);
2029 if (is_desktop_window(win
))
2031 struct desktop
*desktop
= win
->desktop
;
2032 assert( desktop
->top_window
== win
|| desktop
->msg_window
== win
);
2033 if (desktop
->top_window
== win
) desktop
->top_window
= NULL
;
2034 else desktop
->msg_window
= NULL
;
2036 else if (is_desktop_window( win
->parent
))
2038 post_message( win
->parent
->handle
, WM_PARENTNOTIFY
, WM_DESTROY
, win
->handle
);
2041 detach_window_thread( win
);
2043 if (win
->parent
) set_parent_window( win
, NULL
);
2044 free_user_handle( win
->handle
);
2046 release_object( win
);
2050 /* create a window */
2051 DECL_HANDLER(create_window
)
2053 struct window
*win
, *parent
= NULL
, *owner
= NULL
;
2054 struct unicode_str cls_name
= get_req_unicode_str();
2060 if (!(parent
= get_window( req
->parent
))) return;
2061 if (is_orphan_window( parent
))
2063 set_error( STATUS_INVALID_PARAMETER
);
2070 if (!(owner
= get_window( req
->owner
))) return;
2071 if (is_desktop_window(owner
)) owner
= NULL
;
2072 else if (parent
&& !is_desktop_window(parent
))
2074 /* an owned window must be created as top-level */
2075 set_error( STATUS_ACCESS_DENIED
);
2078 else /* owner must be a top-level window */
2079 while ((owner
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& !is_desktop_window(owner
->parent
))
2080 owner
= owner
->parent
;
2083 atom
= cls_name
.len
? find_global_atom( NULL
, &cls_name
) : req
->atom
;
2085 if (!(win
= create_window( parent
, owner
, atom
, req
->instance
))) return;
2087 if (parent
&& !is_desktop_window( parent
))
2089 win
->dpi_awareness
= parent
->dpi_awareness
;
2090 win
->dpi
= parent
->dpi
;
2092 else if (!parent
|| req
->awareness
!= DPI_AWARENESS_PER_MONITOR_AWARE
)
2094 win
->dpi_awareness
= req
->awareness
;
2095 win
->dpi
= req
->dpi
;
2097 win
->style
= req
->style
;
2098 win
->ex_style
= req
->ex_style
;
2100 reply
->handle
= win
->handle
;
2101 reply
->parent
= win
->parent
? win
->parent
->handle
: 0;
2102 reply
->owner
= win
->owner
;
2103 reply
->extra
= win
->nb_extra_bytes
;
2104 reply
->dpi
= win
->dpi
;
2105 reply
->awareness
= win
->dpi_awareness
;
2106 reply
->class_ptr
= get_class_client_ptr( win
->class );
2110 /* set the parent of a window */
2111 DECL_HANDLER(set_parent
)
2113 struct window
*win
, *parent
= NULL
;
2115 if (!(win
= get_window( req
->handle
))) return;
2116 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
2118 if (is_desktop_window(win
) || is_orphan_window( win
) || (parent
&& is_orphan_window( parent
)))
2120 set_error( STATUS_INVALID_PARAMETER
);
2123 reply
->old_parent
= win
->parent
->handle
;
2124 reply
->full_parent
= parent
? parent
->handle
: 0;
2125 set_parent_window( win
, parent
);
2126 reply
->dpi
= win
->dpi
;
2127 reply
->awareness
= win
->dpi_awareness
;
2131 /* destroy a window */
2132 DECL_HANDLER(destroy_window
)
2138 destroy_thread_windows( current
);
2140 else if ((win
= get_window( req
->handle
)))
2142 if (!is_desktop_window(win
)) free_window_handle( win
);
2143 else if (win
->thread
== current
) detach_window_thread( win
);
2144 else set_error( STATUS_ACCESS_DENIED
);
2149 /* retrieve the desktop window for the current thread */
2150 DECL_HANDLER(get_desktop_window
)
2152 struct desktop
*desktop
= get_thread_desktop( current
, 0 );
2155 if (!desktop
) return;
2157 /* if winstation is invisible, then avoid roundtrip */
2158 force
= req
->force
|| !(desktop
->winstation
->flags
& WSF_VISIBLE
);
2160 if (!desktop
->top_window
&& force
) /* create it */
2162 if ((desktop
->top_window
= create_window( NULL
, NULL
, DESKTOP_ATOM
, 0 )))
2164 detach_window_thread( desktop
->top_window
);
2165 desktop
->top_window
->style
= WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
2169 if (!desktop
->msg_window
&& force
) /* create it */
2171 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e'};
2172 static const struct unicode_str name
= { messageW
, sizeof(messageW
) };
2173 atom_t atom
= add_global_atom( NULL
, &name
);
2174 if (atom
&& (desktop
->msg_window
= create_window( NULL
, NULL
, atom
, 0 )))
2176 detach_window_thread( desktop
->msg_window
);
2177 desktop
->msg_window
->style
= WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
2181 reply
->top_window
= desktop
->top_window
? desktop
->top_window
->handle
: 0;
2182 reply
->msg_window
= desktop
->msg_window
? desktop
->msg_window
->handle
: 0;
2183 release_object( desktop
);
2187 /* set a window owner */
2188 DECL_HANDLER(set_window_owner
)
2190 struct window
*win
= get_window( req
->handle
);
2191 struct window
*owner
= NULL
, *ptr
;
2194 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
2195 if (is_desktop_window(win
))
2197 set_error( STATUS_ACCESS_DENIED
);
2201 /* make sure owner is not a successor of window */
2202 for (ptr
= owner
; ptr
; ptr
= ptr
->owner
? get_window( ptr
->owner
) : NULL
)
2206 set_error( STATUS_INVALID_PARAMETER
);
2211 reply
->prev_owner
= win
->owner
;
2212 reply
->full_owner
= win
->owner
= owner
? owner
->handle
: 0;
2216 /* get information from a window handle */
2217 DECL_HANDLER(get_window_info
)
2219 struct window
*win
= get_window( req
->handle
);
2223 reply
->full_handle
= win
->handle
;
2224 reply
->last_active
= win
->handle
;
2225 reply
->is_unicode
= win
->is_unicode
;
2226 reply
->awareness
= win
->dpi_awareness
;
2227 reply
->dpi
= win
->dpi
? win
->dpi
: get_monitor_dpi( win
);
2228 if (get_user_object( win
->last_active
, USER_WINDOW
)) reply
->last_active
= win
->last_active
;
2231 reply
->tid
= get_thread_id( win
->thread
);
2232 reply
->pid
= get_process_id( win
->thread
->process
);
2233 reply
->atom
= win
->class ? get_class_atom( win
->class ) : DESKTOP_ATOM
;
2238 /* set some information in a window */
2239 DECL_HANDLER(set_window_info
)
2241 struct window
*win
= get_window( req
->handle
);
2244 if (req
->flags
&& is_desktop_window(win
) && win
->thread
!= current
)
2246 set_error( STATUS_ACCESS_DENIED
);
2249 if (req
->extra_size
> sizeof(req
->extra_value
) ||
2250 req
->extra_offset
< -1 ||
2251 req
->extra_offset
> win
->nb_extra_bytes
- (int)req
->extra_size
)
2253 set_win32_error( ERROR_INVALID_INDEX
);
2256 if (req
->extra_offset
!= -1)
2258 memcpy( &reply
->old_extra_value
, win
->extra_bytes
+ req
->extra_offset
, req
->extra_size
);
2260 else if (req
->flags
& SET_WIN_EXTRA
)
2262 set_win32_error( ERROR_INVALID_INDEX
);
2265 reply
->old_style
= win
->style
;
2266 reply
->old_ex_style
= win
->ex_style
;
2267 reply
->old_id
= win
->id
;
2268 reply
->old_instance
= win
->instance
;
2269 reply
->old_user_data
= win
->user_data
;
2270 if (req
->flags
& SET_WIN_STYLE
) win
->style
= req
->style
;
2271 if (req
->flags
& SET_WIN_EXSTYLE
)
2273 /* WS_EX_TOPMOST can only be changed for unlinked windows */
2274 if (!win
->is_linked
) win
->ex_style
= req
->ex_style
;
2275 else win
->ex_style
= (req
->ex_style
& ~WS_EX_TOPMOST
) | (win
->ex_style
& WS_EX_TOPMOST
);
2276 if (!(win
->ex_style
& WS_EX_LAYERED
)) win
->is_layered
= 0;
2278 if (req
->flags
& SET_WIN_ID
) win
->id
= req
->extra_value
;
2279 if (req
->flags
& SET_WIN_INSTANCE
) win
->instance
= req
->instance
;
2280 if (req
->flags
& SET_WIN_UNICODE
) win
->is_unicode
= req
->is_unicode
;
2281 if (req
->flags
& SET_WIN_USERDATA
) win
->user_data
= req
->user_data
;
2282 if (req
->flags
& SET_WIN_EXTRA
) memcpy( win
->extra_bytes
+ req
->extra_offset
,
2283 &req
->extra_value
, req
->extra_size
);
2285 /* changing window style triggers a non-client paint */
2286 if (req
->flags
& SET_WIN_STYLE
) win
->paint_flags
|= PAINT_NONCLIENT
;
2290 /* get a list of the window parents, up to the root of the tree */
2291 DECL_HANDLER(get_window_parents
)
2293 struct window
*ptr
, *win
= get_window( req
->handle
);
2295 user_handle_t
*data
;
2298 if (win
) for (ptr
= win
->parent
; ptr
; ptr
= ptr
->parent
) total
++;
2300 reply
->count
= total
;
2301 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
2302 if (len
&& ((data
= set_reply_data_size( len
))))
2304 for (ptr
= win
->parent
; ptr
&& len
; ptr
= ptr
->parent
, len
-= sizeof(*data
))
2305 *data
++ = ptr
->handle
;
2310 /* get a list of the window children */
2311 DECL_HANDLER(get_window_children
)
2313 struct window
*parent
= NULL
;
2315 user_handle_t
*data
;
2317 struct unicode_str cls_name
= get_req_unicode_str();
2318 atom_t atom
= req
->atom
;
2319 struct desktop
*desktop
= NULL
;
2321 if (cls_name
.len
&& !(atom
= find_global_atom( NULL
, &cls_name
))) return;
2325 if (!(desktop
= get_desktop_obj( current
->process
, req
->desktop
, DESKTOP_ENUMERATE
))) return;
2326 parent
= desktop
->top_window
;
2330 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
2331 if (!parent
&& !(desktop
= get_thread_desktop( current
, 0 ))) return;
2335 total
= get_children_windows( parent
, atom
, req
->tid
, NULL
, 0 );
2337 total
= get_children_windows( desktop
->top_window
, atom
, req
->tid
, NULL
, 0 ) +
2338 get_children_windows( desktop
->msg_window
, atom
, req
->tid
, NULL
, 0 );
2340 reply
->count
= total
;
2341 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
2342 if (len
&& ((data
= set_reply_data_size( len
))))
2344 if (parent
) get_children_windows( parent
, atom
, req
->tid
, data
, len
/ sizeof(user_handle_t
) );
2347 total
= get_children_windows( desktop
->top_window
, atom
, req
->tid
,
2348 data
, len
/ sizeof(user_handle_t
) );
2350 len
-= total
* sizeof(user_handle_t
);
2351 if (len
>= sizeof(user_handle_t
))
2352 get_children_windows( desktop
->msg_window
, atom
, req
->tid
,
2353 data
, len
/ sizeof(user_handle_t
) );
2356 if (desktop
) release_object( desktop
);
2360 /* get a list of the window children that contain a given point */
2361 DECL_HANDLER(get_window_children_from_point
)
2363 struct user_handle_array array
;
2364 struct window
*parent
= get_window( req
->parent
);
2367 if (!parent
) return;
2369 array
.handles
= NULL
;
2372 if (!all_windows_from_point( parent
, req
->x
, req
->y
, req
->dpi
, &array
)) return;
2374 reply
->count
= array
.count
;
2375 len
= min( get_reply_max_size(), array
.count
* sizeof(user_handle_t
) );
2376 if (len
) set_reply_data_ptr( array
.handles
, len
);
2377 else free( array
.handles
);
2381 /* get window tree information from a window handle */
2382 DECL_HANDLER(get_window_tree
)
2384 struct window
*ptr
, *win
= get_window( req
->handle
);
2390 reply
->next_sibling
= 0;
2391 reply
->prev_sibling
= 0;
2392 reply
->first_sibling
= 0;
2393 reply
->last_sibling
= 0;
2394 reply
->first_child
= 0;
2395 reply
->last_child
= 0;
2399 struct window
*parent
= win
->parent
;
2400 reply
->parent
= parent
->handle
;
2401 reply
->owner
= win
->owner
;
2404 if ((ptr
= get_next_window( win
))) reply
->next_sibling
= ptr
->handle
;
2405 if ((ptr
= get_prev_window( win
))) reply
->prev_sibling
= ptr
->handle
;
2407 if ((ptr
= get_first_child( parent
))) reply
->first_sibling
= ptr
->handle
;
2408 if ((ptr
= get_last_child( parent
))) reply
->last_sibling
= ptr
->handle
;
2410 if ((ptr
= get_first_child( win
))) reply
->first_child
= ptr
->handle
;
2411 if ((ptr
= get_last_child( win
))) reply
->last_child
= ptr
->handle
;
2415 /* set the position and Z order of a window */
2416 DECL_HANDLER(set_window_pos
)
2418 rectangle_t window_rect
, client_rect
, visible_rect
, surface_rect
, valid_rect
;
2419 const rectangle_t
*extra_rects
= get_req_data();
2420 struct window
*previous
= NULL
;
2421 struct window
*top
, *win
= get_window( req
->handle
);
2422 unsigned int flags
= req
->swp_flags
;
2425 if (!win
->parent
) flags
|= SWP_NOZORDER
; /* no Z order for the desktop */
2427 if (!(flags
& SWP_NOZORDER
))
2429 switch ((int)req
->previous
)
2431 case 0: /* HWND_TOP */
2432 previous
= WINPTR_TOP
;
2434 case 1: /* HWND_BOTTOM */
2435 previous
= WINPTR_BOTTOM
;
2437 case -1: /* HWND_TOPMOST */
2438 previous
= WINPTR_TOPMOST
;
2440 case -2: /* HWND_NOTOPMOST */
2441 previous
= WINPTR_NOTOPMOST
;
2444 if (!(previous
= get_window( req
->previous
))) return;
2445 /* previous must be a sibling */
2446 if (previous
->parent
!= win
->parent
)
2448 set_error( STATUS_INVALID_PARAMETER
);
2453 if (previous
== win
) flags
|= SWP_NOZORDER
; /* nothing to do */
2456 /* windows that use UpdateLayeredWindow don't trigger repaints */
2457 if ((win
->ex_style
& WS_EX_LAYERED
) && !win
->is_layered
) flags
|= SWP_NOREDRAW
;
2459 /* window rectangle must be ordered properly */
2460 if (req
->window
.right
< req
->window
.left
|| req
->window
.bottom
< req
->window
.top
)
2462 set_error( STATUS_INVALID_PARAMETER
);
2466 window_rect
= req
->window
;
2467 client_rect
= req
->client
;
2468 if (get_req_data_size() >= sizeof(rectangle_t
)) visible_rect
= extra_rects
[0];
2469 else visible_rect
= window_rect
;
2470 if (get_req_data_size() >= 2 * sizeof(rectangle_t
)) surface_rect
= extra_rects
[1];
2471 else surface_rect
= visible_rect
;
2472 if (get_req_data_size() >= 3 * sizeof(rectangle_t
)) valid_rect
= extra_rects
[2];
2473 else valid_rect
= empty_rect
;
2474 if (win
->parent
&& win
->parent
->ex_style
& WS_EX_LAYOUTRTL
)
2476 mirror_rect( &win
->parent
->client_rect
, &window_rect
);
2477 mirror_rect( &win
->parent
->client_rect
, &visible_rect
);
2478 mirror_rect( &win
->parent
->client_rect
, &client_rect
);
2479 mirror_rect( &win
->parent
->client_rect
, &surface_rect
);
2480 mirror_rect( &win
->parent
->client_rect
, &valid_rect
);
2483 win
->paint_flags
= (win
->paint_flags
& ~PAINT_CLIENT_FLAGS
) | (req
->paint_flags
& PAINT_CLIENT_FLAGS
);
2484 if (win
->paint_flags
& PAINT_HAS_PIXEL_FORMAT
) update_pixel_format_flags( win
);
2486 set_window_pos( win
, previous
, flags
, &window_rect
, &client_rect
,
2487 &visible_rect
, &surface_rect
, &valid_rect
);
2489 reply
->new_style
= win
->style
;
2490 reply
->new_ex_style
= win
->ex_style
;
2492 top
= get_top_clipping_window( win
);
2493 if (is_visible( top
) && (top
->paint_flags
& PAINT_HAS_SURFACE
))
2495 reply
->surface_win
= top
->handle
;
2496 reply
->needs_update
= !!(top
->paint_flags
& (PAINT_HAS_PIXEL_FORMAT
| PAINT_PIXEL_FORMAT_CHILD
));
2501 /* get the window and client rectangles of a window */
2502 DECL_HANDLER(get_window_rectangles
)
2504 struct window
*win
= get_window( req
->handle
);
2508 reply
->window
= win
->window_rect
;
2509 reply
->client
= win
->client_rect
;
2511 switch (req
->relative
)
2514 offset_rect( &reply
->window
, -win
->client_rect
.left
, -win
->client_rect
.top
);
2515 offset_rect( &reply
->client
, -win
->client_rect
.left
, -win
->client_rect
.top
);
2516 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_rect( &win
->client_rect
, &reply
->window
);
2519 offset_rect( &reply
->window
, -win
->window_rect
.left
, -win
->window_rect
.top
);
2520 offset_rect( &reply
->client
, -win
->window_rect
.left
, -win
->window_rect
.top
);
2521 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_rect( &win
->window_rect
, &reply
->client
);
2524 if (win
->parent
&& win
->parent
->ex_style
& WS_EX_LAYOUTRTL
)
2526 mirror_rect( &win
->parent
->client_rect
, &reply
->window
);
2527 mirror_rect( &win
->parent
->client_rect
, &reply
->client
);
2531 client_to_screen_rect( win
->parent
, &reply
->window
);
2532 client_to_screen_rect( win
->parent
, &reply
->client
);
2535 set_error( STATUS_INVALID_PARAMETER
);
2538 map_dpi_rect( win
, &reply
->window
, win
->dpi
, req
->dpi
);
2539 map_dpi_rect( win
, &reply
->client
, win
->dpi
, req
->dpi
);
2543 /* get the window text */
2544 DECL_HANDLER(get_window_text
)
2546 struct window
*win
= get_window( req
->handle
);
2548 if (win
&& win
->text_len
)
2550 reply
->length
= win
->text_len
/ sizeof(WCHAR
);
2551 set_reply_data( win
->text
, min( win
->text_len
, get_reply_max_size() ));
2556 /* set the window text */
2557 DECL_HANDLER(set_window_text
)
2561 struct window
*win
= get_window( req
->handle
);
2564 len
= (get_req_data_size() / sizeof(WCHAR
)) * sizeof(WCHAR
);
2565 if (len
&& !(text
= memdup( get_req_data(), len
))) return;
2568 win
->text_len
= len
;
2572 /* get the coordinates offset between two windows */
2573 DECL_HANDLER(get_windows_offset
)
2576 int x
, y
, mirror_from
= 0, mirror_to
= 0;
2578 reply
->x
= reply
->y
= 0;
2581 if (!(win
= get_window( req
->from
))) return;
2582 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_from
= 1;
2583 x
= mirror_from
? win
->client_rect
.right
- win
->client_rect
.left
: 0;
2585 client_to_screen( win
, &x
, &y
);
2586 map_dpi_point( win
, &x
, &y
, win
->dpi
, req
->dpi
);
2592 if (!(win
= get_window( req
->to
))) return;
2593 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_to
= 1;
2594 x
= mirror_to
? win
->client_rect
.right
- win
->client_rect
.left
: 0;
2596 client_to_screen( win
, &x
, &y
);
2597 map_dpi_point( win
, &x
, &y
, win
->dpi
, req
->dpi
);
2601 if (mirror_from
) reply
->x
= -reply
->x
;
2602 reply
->mirror
= mirror_from
^ mirror_to
;
2606 /* get the visible region of a window */
2607 DECL_HANDLER(get_visible_region
)
2609 struct region
*region
;
2610 struct window
*top
, *win
= get_window( req
->window
);
2614 top
= get_top_clipping_window( win
);
2615 if ((region
= get_visible_region( win
, req
->flags
)))
2618 map_win_region_to_screen( win
, region
);
2619 data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
2620 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
2622 reply
->top_win
= top
->handle
;
2623 reply
->top_rect
= top
->surface_rect
;
2625 if (!is_desktop_window(win
))
2627 reply
->win_rect
= (req
->flags
& DCX_WINDOW
) ? win
->window_rect
: win
->client_rect
;
2628 client_to_screen_rect( top
->parent
, &reply
->top_rect
);
2629 client_to_screen_rect( win
->parent
, &reply
->win_rect
);
2633 reply
->win_rect
.left
= 0;
2634 reply
->win_rect
.top
= 0;
2635 reply
->win_rect
.right
= win
->client_rect
.right
- win
->client_rect
.left
;
2636 reply
->win_rect
.bottom
= win
->client_rect
.bottom
- win
->client_rect
.top
;
2638 reply
->paint_flags
= win
->paint_flags
& PAINT_CLIENT_FLAGS
;
2642 /* get the surface visible region of a window */
2643 DECL_HANDLER(get_surface_region
)
2645 struct region
*region
;
2646 struct window
*win
= get_window( req
->window
);
2648 if (!win
|| !is_visible( win
)) return;
2650 if ((region
= get_surface_region( win
)))
2652 rectangle_t
*data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
2653 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
2655 reply
->visible_rect
= win
->visible_rect
;
2659 /* get the window region */
2660 DECL_HANDLER(get_window_region
)
2663 struct window
*win
= get_window( req
->window
);
2666 if (!win
->win_region
) return;
2668 if (win
->ex_style
& WS_EX_LAYOUTRTL
)
2670 struct region
*region
= create_empty_region();
2672 if (!region
) return;
2673 if (!copy_region( region
, win
->win_region
))
2675 free_region( region
);
2678 mirror_region( &win
->window_rect
, region
);
2679 data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
2681 else data
= get_region_data( win
->win_region
, get_reply_max_size(), &reply
->total_size
);
2683 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
2687 /* set the window region */
2688 DECL_HANDLER(set_window_region
)
2690 struct region
*region
= NULL
;
2691 struct window
*win
= get_window( req
->window
);
2695 if (get_req_data_size()) /* no data means remove the region completely */
2697 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
2699 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_region( &win
->window_rect
, region
);
2701 set_window_region( win
, region
, req
->redraw
);
2705 /* get a window update region */
2706 DECL_HANDLER(get_update_region
)
2709 unsigned int flags
= req
->flags
;
2710 struct window
*from_child
= NULL
;
2711 struct window
*win
= get_window( req
->window
);
2716 if (req
->from_child
)
2720 if (!(from_child
= get_window( req
->from_child
))) return;
2722 /* make sure from_child is a child of win */
2724 while (ptr
&& ptr
!= win
) ptr
= ptr
->parent
;
2727 set_error( STATUS_INVALID_PARAMETER
);
2732 if (flags
& UPDATE_DELAYED_ERASE
) /* this means that the previous call didn't erase */
2734 if (from_child
) from_child
->paint_flags
|= PAINT_DELAYED_ERASE
;
2735 else win
->paint_flags
|= PAINT_DELAYED_ERASE
;
2738 reply
->flags
= get_window_update_flags( win
, from_child
, flags
, &win
);
2739 reply
->child
= win
->handle
;
2741 if (flags
& UPDATE_NOREGION
) return;
2743 if (win
->update_region
)
2745 /* convert update region to screen coordinates */
2746 struct region
*region
= create_empty_region();
2748 if (!region
) return;
2749 if (!copy_region( region
, win
->update_region
))
2751 free_region( region
);
2754 if ((flags
& UPDATE_CLIPCHILDREN
) && (win
->style
& WS_CLIPCHILDREN
))
2755 clip_children( win
, NULL
, region
, win
->client_rect
.left
- win
->window_rect
.left
,
2756 win
->client_rect
.top
- win
->window_rect
.top
);
2757 map_win_region_to_screen( win
, region
);
2758 if (!(data
= get_region_data_and_free( region
, get_reply_max_size(),
2759 &reply
->total_size
))) return;
2760 set_reply_data_ptr( data
, reply
->total_size
);
2763 if (reply
->flags
& (UPDATE_PAINT
|UPDATE_INTERNALPAINT
)) /* validate everything */
2765 validate_parents( win
);
2766 validate_whole_window( win
);
2770 if (reply
->flags
& UPDATE_NONCLIENT
) validate_non_client( win
);
2771 if (reply
->flags
& UPDATE_ERASE
)
2773 win
->paint_flags
&= ~(PAINT_ERASE
| PAINT_DELAYED_ERASE
);
2774 /* desktop window only gets erased, not repainted */
2775 if (is_desktop_window(win
)) validate_whole_window( win
);
2781 /* update the z order of a window so that a given rectangle is fully visible */
2782 DECL_HANDLER(update_window_zorder
)
2784 rectangle_t tmp
, rect
= req
->rect
;
2785 struct window
*ptr
, *win
= get_window( req
->window
);
2787 if (!win
|| !win
->parent
|| !is_visible( win
)) return; /* nothing to do */
2789 LIST_FOR_EACH_ENTRY( ptr
, &win
->parent
->children
, struct window
, entry
)
2791 if (ptr
== win
) break;
2792 if (!(ptr
->style
& WS_VISIBLE
)) continue;
2793 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
2794 if (ptr
->is_layered
&& (ptr
->layered_flags
& LWA_COLORKEY
)) continue;
2796 map_dpi_rect( win
, &tmp
, win
->parent
->dpi
, win
->dpi
);
2797 if (!intersect_rect( &tmp
, &tmp
, &ptr
->visible_rect
)) continue;
2798 if (ptr
->win_region
)
2800 offset_rect( &tmp
, -ptr
->window_rect
.left
, -ptr
->window_rect
.top
);
2801 if (!rect_in_region( ptr
->win_region
, &tmp
)) continue;
2803 /* found a window obscuring the rectangle, now move win above this one */
2804 /* making sure to not violate the topmost rule */
2805 if (!(ptr
->ex_style
& WS_EX_TOPMOST
) || (win
->ex_style
& WS_EX_TOPMOST
))
2807 list_remove( &win
->entry
);
2808 list_add_before( &ptr
->entry
, &win
->entry
);
2815 /* mark parts of a window as needing a redraw */
2816 DECL_HANDLER(redraw_window
)
2818 unsigned int flags
= req
->flags
;
2819 struct region
*region
= NULL
;
2824 if (!(win
= get_desktop_window( current
))) return;
2828 if (!(win
= get_window( req
->window
))) return;
2829 if (is_desktop_window( win
)) flags
&= ~RDW_ALLCHILDREN
;
2832 if (!is_visible( win
)) return; /* nothing to do */
2834 if (flags
& (RDW_VALIDATE
|RDW_INVALIDATE
))
2836 if (get_req_data_size()) /* no data means whole rectangle */
2838 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
2840 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_region( &win
->client_rect
, region
);
2844 redraw_window( win
, region
, (flags
& RDW_INVALIDATE
) && (flags
& RDW_FRAME
), flags
);
2845 if (region
) free_region( region
);
2849 /* set a window property */
2850 DECL_HANDLER(set_window_property
)
2852 struct unicode_str name
= get_req_unicode_str();
2853 struct window
*win
= get_window( req
->window
);
2859 atom_t atom
= add_global_atom( NULL
, &name
);
2862 set_property( win
, atom
, req
->data
, PROP_TYPE_STRING
);
2863 release_global_atom( NULL
, atom
);
2866 else set_property( win
, req
->atom
, req
->data
, PROP_TYPE_ATOM
);
2870 /* remove a window property */
2871 DECL_HANDLER(remove_window_property
)
2873 struct unicode_str name
= get_req_unicode_str();
2874 struct window
*win
= get_window( req
->window
);
2878 atom_t atom
= name
.len
? find_global_atom( NULL
, &name
) : req
->atom
;
2879 if (atom
) reply
->data
= remove_property( win
, atom
);
2884 /* get a window property */
2885 DECL_HANDLER(get_window_property
)
2887 struct unicode_str name
= get_req_unicode_str();
2888 struct window
*win
= get_window( req
->window
);
2892 atom_t atom
= name
.len
? find_global_atom( NULL
, &name
) : req
->atom
;
2893 if (atom
) reply
->data
= get_property( win
, atom
);
2898 /* get the list of properties of a window */
2899 DECL_HANDLER(get_window_properties
)
2901 property_data_t
*data
;
2902 int i
, count
, max
= get_reply_max_size() / sizeof(*data
);
2903 struct window
*win
= get_window( req
->window
);
2908 for (i
= count
= 0; i
< win
->prop_inuse
; i
++)
2909 if (win
->properties
[i
].type
!= PROP_TYPE_FREE
) count
++;
2910 reply
->total
= count
;
2912 if (count
> max
) count
= max
;
2913 if (!count
|| !(data
= set_reply_data_size( count
* sizeof(*data
) ))) return;
2915 for (i
= 0; i
< win
->prop_inuse
&& count
; i
++)
2917 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
2918 data
->atom
= win
->properties
[i
].atom
;
2919 data
->string
= (win
->properties
[i
].type
== PROP_TYPE_STRING
);
2920 data
->data
= win
->properties
[i
].data
;
2927 /* get the new window pointer for a global window, checking permissions */
2928 /* helper for set_global_windows request */
2929 static int get_new_global_window( struct window
**win
, user_handle_t handle
)
2938 set_error( STATUS_ACCESS_DENIED
);
2941 *win
= get_window( handle
);
2942 return (*win
!= NULL
);
2945 /* Set/get the global windows */
2946 DECL_HANDLER(set_global_windows
)
2948 struct window
*new_shell_window
= shell_window
;
2949 struct window
*new_shell_listview
= shell_listview
;
2950 struct window
*new_progman_window
= progman_window
;
2951 struct window
*new_taskman_window
= taskman_window
;
2953 reply
->old_shell_window
= shell_window
? shell_window
->handle
: 0;
2954 reply
->old_shell_listview
= shell_listview
? shell_listview
->handle
: 0;
2955 reply
->old_progman_window
= progman_window
? progman_window
->handle
: 0;
2956 reply
->old_taskman_window
= taskman_window
? taskman_window
->handle
: 0;
2958 if (req
->flags
& SET_GLOBAL_SHELL_WINDOWS
)
2960 if (!get_new_global_window( &new_shell_window
, req
->shell_window
)) return;
2961 if (!get_new_global_window( &new_shell_listview
, req
->shell_listview
)) return;
2963 if (req
->flags
& SET_GLOBAL_PROGMAN_WINDOW
)
2965 if (!get_new_global_window( &new_progman_window
, req
->progman_window
)) return;
2967 if (req
->flags
& SET_GLOBAL_TASKMAN_WINDOW
)
2969 if (!get_new_global_window( &new_taskman_window
, req
->taskman_window
)) return;
2971 shell_window
= new_shell_window
;
2972 shell_listview
= new_shell_listview
;
2973 progman_window
= new_progman_window
;
2974 taskman_window
= new_taskman_window
;
2977 /* retrieve layered info for a window */
2978 DECL_HANDLER(get_window_layered_info
)
2980 struct window
*win
= get_window( req
->handle
);
2984 if (win
->is_layered
)
2986 reply
->color_key
= win
->color_key
;
2987 reply
->alpha
= win
->alpha
;
2988 reply
->flags
= win
->layered_flags
;
2990 else set_win32_error( ERROR_INVALID_WINDOW_HANDLE
);
2994 /* set layered info for a window */
2995 DECL_HANDLER(set_window_layered_info
)
2997 struct window
*win
= get_window( req
->handle
);
3001 if (win
->ex_style
& WS_EX_LAYERED
)
3003 int was_layered
= win
->is_layered
;
3005 if (req
->flags
& LWA_ALPHA
) win
->alpha
= req
->alpha
;
3006 else if (!win
->is_layered
) win
->alpha
= 0; /* alpha init value is 0 */
3008 win
->color_key
= req
->color_key
;
3009 win
->layered_flags
= req
->flags
;
3010 win
->is_layered
= 1;
3011 /* repaint since we know now it's not going to use UpdateLayeredWindow */
3012 if (!was_layered
) redraw_window( win
, 0, 1, RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
);
3014 else set_win32_error( ERROR_INVALID_WINDOW_HANDLE
);