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_context
; /* DPI awareness context */
87 lparam_t user_data
; /* user-specific data */
88 WCHAR
*text
; /* window caption text */
89 data_size_t text_len
; /* length of window caption */
90 unsigned int paint_flags
; /* various painting flags */
91 int prop_inuse
; /* number of in-use window properties */
92 int prop_alloc
; /* number of allocated window properties */
93 struct property
*properties
; /* window properties array */
94 int nb_extra_bytes
; /* number of extra bytes */
95 char *extra_bytes
; /* extra bytes storage */
98 static void window_dump( struct object
*obj
, int verbose
);
99 static void window_destroy( struct object
*obj
);
101 static const struct object_ops window_ops
=
103 sizeof(struct window
), /* size */
105 window_dump
, /* dump */
106 no_add_queue
, /* add_queue */
107 NULL
, /* remove_queue */
109 NULL
, /* satisfied */
110 no_signal
, /* signal */
111 no_get_fd
, /* get_fd */
112 default_map_access
, /* map_access */
113 default_get_sd
, /* get_sd */
114 default_set_sd
, /* set_sd */
115 no_get_full_name
, /* get_full_name */
116 no_lookup_name
, /* lookup_name */
117 no_link_name
, /* link_name */
118 NULL
, /* unlink_name */
119 no_open_file
, /* open_file */
120 no_kernel_obj_list
, /* get_kernel_obj_list */
121 no_close_handle
, /* close_handle */
122 window_destroy
/* destroy */
125 /* flags that can be set by the client */
126 #define PAINT_HAS_SURFACE SET_WINPOS_PAINT_SURFACE
127 #define PAINT_HAS_PIXEL_FORMAT SET_WINPOS_PIXEL_FORMAT
128 #define PAINT_CLIENT_FLAGS (PAINT_HAS_SURFACE | PAINT_HAS_PIXEL_FORMAT)
129 /* flags only manipulated by the server */
130 #define PAINT_INTERNAL 0x0010 /* internal WM_PAINT pending */
131 #define PAINT_ERASE 0x0020 /* needs WM_ERASEBKGND */
132 #define PAINT_NONCLIENT 0x0040 /* needs WM_NCPAINT */
133 #define PAINT_DELAYED_ERASE 0x0080 /* still needs erase after WM_ERASEBKGND */
134 #define PAINT_PIXEL_FORMAT_CHILD 0x0100 /* at least one child has a custom pixel format */
136 /* growable array of user handles */
137 struct user_handle_array
139 user_handle_t
*handles
;
144 static const rectangle_t empty_rect
;
146 /* global window pointers */
147 static struct window
*shell_window
;
148 static struct window
*shell_listview
;
149 static struct window
*progman_window
;
150 static struct window
*taskman_window
;
152 /* magic HWND_TOP etc. pointers */
153 #define WINPTR_TOP ((struct window *)1L)
154 #define WINPTR_BOTTOM ((struct window *)2L)
155 #define WINPTR_TOPMOST ((struct window *)3L)
156 #define WINPTR_NOTOPMOST ((struct window *)4L)
158 static void window_dump( struct object
*obj
, int verbose
)
160 struct window
*win
= (struct window
*)obj
;
161 assert( obj
->ops
== &window_ops
);
162 fprintf( stderr
, "window %p handle %x\n", win
, win
->handle
);
165 static void window_destroy( struct object
*obj
)
167 struct window
*win
= (struct window
*)obj
;
169 assert( !win
->handle
);
173 list_remove( &win
->entry
);
174 release_object( win
->parent
);
177 if (win
->win_region
) free_region( win
->win_region
);
178 if (win
->update_region
) free_region( win
->update_region
);
179 if (win
->class) release_class( win
->class );
182 if (win
->nb_extra_bytes
)
184 memset( win
->extra_bytes
, 0x55, win
->nb_extra_bytes
);
185 free( win
->extra_bytes
);
189 /* retrieve a pointer to a window from its handle */
190 static inline struct window
*get_window( user_handle_t handle
)
192 struct window
*ret
= get_user_object( handle
, USER_WINDOW
);
193 if (!ret
) set_win32_error( ERROR_INVALID_WINDOW_HANDLE
);
197 /* check if window is the desktop */
198 static inline int is_desktop_window( const struct window
*win
)
200 return !win
->parent
; /* only desktop windows have no parent */
203 /* check if window is orphaned */
204 static int is_orphan_window( struct window
*win
)
206 do if (win
->is_orphan
) return 1;
207 while ((win
= win
->parent
));
211 /* get next window in Z-order list */
212 static inline struct window
*get_next_window( struct window
*win
)
214 struct list
*ptr
= list_next( &win
->parent
->children
, &win
->entry
);
215 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
218 /* get previous window in Z-order list */
219 static inline struct window
*get_prev_window( struct window
*win
)
221 struct list
*ptr
= list_prev( &win
->parent
->children
, &win
->entry
);
222 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
225 /* get first child in Z-order list */
226 static inline struct window
*get_first_child( struct window
*win
)
228 struct list
*ptr
= list_head( &win
->children
);
229 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
232 /* get last child in Z-order list */
233 static inline struct window
*get_last_child( struct window
*win
)
235 struct list
*ptr
= list_tail( &win
->children
);
236 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
239 /* set the PAINT_PIXEL_FORMAT_CHILD flag on all the parents */
240 /* note: we never reset the flag, it's just a heuristic */
241 static inline void update_pixel_format_flags( struct window
*win
)
243 for (win
= win
->parent
; win
&& win
->parent
; win
= win
->parent
)
244 win
->paint_flags
|= PAINT_PIXEL_FORMAT_CHILD
;
247 static unsigned int get_window_dpi( struct window
*win
)
250 if ((dpi
= NTUSER_DPI_CONTEXT_GET_DPI( win
->dpi_context
))) return dpi
;
251 /* FIXME: return the window monitor DPI? */
252 return USER_DEFAULT_SCREEN_DPI
;
255 /* get the per-monitor DPI for a window */
256 static unsigned int get_monitor_dpi( struct window
*win
)
258 /* FIXME: we return the desktop window DPI for now */
259 while (!is_desktop_window( win
)) win
= win
->parent
;
260 return get_window_dpi( win
);
263 /* link a window at the right place in the siblings list */
264 static int link_window( struct window
*win
, struct window
*previous
)
266 struct list
*old_prev
;
268 if (previous
== WINPTR_NOTOPMOST
)
270 if (!(win
->ex_style
& WS_EX_TOPMOST
) && win
->is_linked
) return 0; /* nothing to do */
271 win
->ex_style
&= ~WS_EX_TOPMOST
;
272 previous
= WINPTR_TOP
; /* fallback to the HWND_TOP case */
275 old_prev
= win
->is_linked
? win
->entry
.prev
: NULL
;
276 list_remove( &win
->entry
); /* unlink it from the previous location */
278 if (previous
== WINPTR_BOTTOM
)
280 list_add_tail( &win
->parent
->children
, &win
->entry
);
281 win
->ex_style
&= ~WS_EX_TOPMOST
;
283 else if (previous
== WINPTR_TOPMOST
)
285 list_add_head( &win
->parent
->children
, &win
->entry
);
286 win
->ex_style
|= WS_EX_TOPMOST
;
288 else if (previous
== WINPTR_TOP
)
290 struct list
*entry
= win
->parent
->children
.next
;
291 if (!(win
->ex_style
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
293 while (entry
!= &win
->parent
->children
)
295 struct window
*next
= LIST_ENTRY( entry
, struct window
, entry
);
296 if (!(next
->ex_style
& WS_EX_TOPMOST
)) break;
297 if (next
->handle
== win
->owner
) /* keep it above owner */
299 win
->ex_style
|= WS_EX_TOPMOST
;
305 list_add_before( entry
, &win
->entry
);
309 list_add_after( &previous
->entry
, &win
->entry
);
310 if (!(previous
->ex_style
& WS_EX_TOPMOST
)) win
->ex_style
&= ~WS_EX_TOPMOST
;
313 struct window
*next
= get_next_window( win
);
314 if (next
&& (next
->ex_style
& WS_EX_TOPMOST
)) win
->ex_style
|= WS_EX_TOPMOST
;
319 return old_prev
!= win
->entry
.prev
;
322 /* change the parent of a window (or unlink the window if the new parent is NULL) */
323 static int set_parent_window( struct window
*win
, struct window
*parent
)
327 /* make sure parent is not a child of window */
328 for (ptr
= parent
; ptr
; ptr
= ptr
->parent
)
332 set_error( STATUS_INVALID_PARAMETER
);
339 if (win
->parent
) release_object( win
->parent
);
340 win
->parent
= (struct window
*)grab_object( parent
);
341 link_window( win
, WINPTR_TOP
);
343 if (!is_desktop_window( parent
)) win
->dpi_context
= parent
->dpi_context
;
345 /* if parent belongs to a different thread and the window isn't */
346 /* top-level, attach the two threads */
347 if (parent
->thread
&& parent
->thread
!= win
->thread
&& !is_desktop_window(parent
))
348 attach_thread_input( win
->thread
, parent
->thread
);
350 if (win
->paint_flags
& (PAINT_HAS_PIXEL_FORMAT
| PAINT_PIXEL_FORMAT_CHILD
))
351 update_pixel_format_flags( win
);
353 else /* move it to parent unlinked list */
355 list_remove( &win
->entry
); /* unlink it from the previous location */
356 list_add_head( &win
->parent
->unlinked
, &win
->entry
);
363 /* append a user handle to a handle array */
364 static int add_handle_to_array( struct user_handle_array
*array
, user_handle_t handle
)
366 if (array
->count
>= array
->total
)
368 int new_total
= max( array
->total
* 2, 32 );
369 user_handle_t
*new_array
= realloc( array
->handles
, new_total
* sizeof(*new_array
) );
372 free( array
->handles
);
373 set_error( STATUS_NO_MEMORY
);
376 array
->handles
= new_array
;
377 array
->total
= new_total
;
379 array
->handles
[array
->count
++] = handle
;
383 /* set a window property */
384 static void set_property( struct window
*win
, atom_t atom
, lparam_t data
, enum property_type type
)
387 struct property
*new_props
;
389 /* check if it exists already */
390 for (i
= 0; i
< win
->prop_inuse
; i
++)
392 if (win
->properties
[i
].type
== PROP_TYPE_FREE
)
397 if (win
->properties
[i
].atom
== atom
)
399 win
->properties
[i
].type
= type
;
400 win
->properties
[i
].data
= data
;
405 /* need to add an entry */
406 if (!grab_global_atom( NULL
, atom
)) return;
410 if (win
->prop_inuse
>= win
->prop_alloc
)
412 /* need to grow the array */
413 if (!(new_props
= realloc( win
->properties
,
414 sizeof(*new_props
) * (win
->prop_alloc
+ 16) )))
416 set_error( STATUS_NO_MEMORY
);
417 release_global_atom( NULL
, atom
);
420 win
->prop_alloc
+= 16;
421 win
->properties
= new_props
;
423 free
= win
->prop_inuse
++;
425 win
->properties
[free
].atom
= atom
;
426 win
->properties
[free
].type
= type
;
427 win
->properties
[free
].data
= data
;
430 /* remove a window property */
431 static lparam_t
remove_property( struct window
*win
, atom_t atom
)
435 for (i
= 0; i
< win
->prop_inuse
; i
++)
437 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
438 if (win
->properties
[i
].atom
== atom
)
440 release_global_atom( NULL
, atom
);
441 win
->properties
[i
].type
= PROP_TYPE_FREE
;
442 return win
->properties
[i
].data
;
445 /* FIXME: last error? */
449 /* find a window property */
450 static lparam_t
get_property( struct window
*win
, atom_t atom
)
454 for (i
= 0; i
< win
->prop_inuse
; i
++)
456 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
457 if (win
->properties
[i
].atom
== atom
) return win
->properties
[i
].data
;
459 /* FIXME: last error? */
463 /* destroy all properties of a window */
464 static inline void destroy_properties( struct window
*win
)
468 if (!win
->properties
) return;
469 for (i
= 0; i
< win
->prop_inuse
; i
++)
471 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
472 release_global_atom( NULL
, win
->properties
[i
].atom
);
474 free( win
->properties
);
477 /* detach a window from its owner thread but keep the window around */
478 static void detach_window_thread( struct window
*win
)
480 struct thread
*thread
= win
->thread
;
485 if (win
->update_region
) inc_queue_paint_count( thread
, -1 );
486 if (win
->paint_flags
& PAINT_INTERNAL
) inc_queue_paint_count( thread
, -1 );
487 queue_cleanup_window( thread
, win
->handle
);
489 assert( thread
->desktop_users
> 0 );
490 thread
->desktop_users
--;
491 release_class( win
->class );
494 /* don't hold a reference to the desktop so that the desktop window can be */
495 /* destroyed when the desktop ref count reaches zero */
496 release_object( win
->desktop
);
500 /* get the process owning the top window of a given desktop */
501 struct process
*get_top_window_owner( struct desktop
*desktop
)
503 struct window
*win
= desktop
->top_window
;
504 if (!win
|| !win
->thread
) return NULL
;
505 return win
->thread
->process
;
508 /* get the top window size of a given desktop */
509 void get_top_window_rectangle( struct desktop
*desktop
, rectangle_t
*rect
)
511 struct window
*win
= desktop
->top_window
;
512 *rect
= win
? win
->window_rect
: empty_rect
;
515 /* post a message to the desktop window */
516 void post_desktop_message( struct desktop
*desktop
, unsigned int message
,
517 lparam_t wparam
, lparam_t lparam
)
519 struct window
*win
= desktop
->top_window
;
520 if (win
&& win
->thread
) post_message( win
->handle
, message
, wparam
, lparam
);
523 /* create a new window structure (note: the window is not linked in the window tree) */
524 static struct window
*create_window( struct window
*parent
, struct window
*owner
,
525 atom_t atom
, mod_handle_t instance
)
528 struct window
*win
= NULL
;
529 struct desktop
*desktop
;
530 struct window_class
*class;
532 if (!(desktop
= get_thread_desktop( current
, DESKTOP_CREATEWINDOW
))) return NULL
;
534 if (!(class = grab_class( current
->process
, atom
, instance
, &extra_bytes
)))
536 release_object( desktop
);
540 if (!parent
) /* null parent is only allowed for desktop or HWND_MESSAGE top window */
542 if (is_desktop_class( class ))
543 parent
= desktop
->top_window
; /* use existing desktop if any */
544 else if (is_hwnd_message_class( class ))
545 /* use desktop window if message window is already created */
546 parent
= desktop
->msg_window
? desktop
->top_window
: NULL
;
547 else if (!(parent
= desktop
->top_window
)) /* must already have a desktop then */
549 set_error( STATUS_ACCESS_DENIED
);
554 /* parent must be on the same desktop */
555 if (parent
&& parent
->desktop
!= desktop
)
557 set_error( STATUS_ACCESS_DENIED
);
561 if (!(win
= alloc_object( &window_ops
))) goto failed
;
562 win
->parent
= parent
? (struct window
*)grab_object( parent
) : NULL
;
563 win
->owner
= owner
? owner
->handle
: 0;
564 win
->thread
= current
;
565 win
->desktop
= desktop
;
568 win
->last_active
= win
->handle
;
569 win
->win_region
= NULL
;
570 win
->update_region
= NULL
;
579 win
->dpi_context
= NTUSER_DPI_PER_MONITOR_AWARE
;
583 win
->paint_flags
= 0;
586 win
->properties
= NULL
;
587 win
->nb_extra_bytes
= 0;
588 win
->extra_bytes
= NULL
;
589 win
->window_rect
= win
->visible_rect
= win
->surface_rect
= win
->client_rect
= empty_rect
;
590 list_init( &win
->children
);
591 list_init( &win
->unlinked
);
595 if (!(win
->extra_bytes
= mem_alloc( extra_bytes
))) goto failed
;
596 memset( win
->extra_bytes
, 0, extra_bytes
);
597 win
->nb_extra_bytes
= extra_bytes
;
599 if (!(win
->handle
= alloc_user_handle( win
, USER_WINDOW
))) goto failed
;
601 /* if parent belongs to a different thread and the window isn't */
602 /* top-level, attach the two threads */
603 if (parent
&& parent
->thread
&& parent
->thread
!= current
&& !is_desktop_window(parent
))
605 if (!attach_thread_input( current
, parent
->thread
)) goto failed
;
607 else /* otherwise just make sure that the thread has a message queue */
609 if (!current
->queue
&& !init_thread_queue( current
)) goto failed
;
612 /* put it on parent unlinked list */
613 if (parent
) list_add_head( &parent
->unlinked
, &win
->entry
);
616 list_init( &win
->entry
);
617 if (is_desktop_class( class ))
619 assert( !desktop
->top_window
);
620 desktop
->top_window
= win
;
621 set_process_default_desktop( current
->process
, desktop
, current
->desktop
);
625 assert( !desktop
->msg_window
);
626 desktop
->msg_window
= win
;
630 current
->desktop_users
++;
638 free_user_handle( win
->handle
);
641 release_object( win
);
643 release_object( desktop
);
644 release_class( class );
648 /* destroy all windows belonging to a given thread */
649 void destroy_thread_windows( struct thread
*thread
)
651 user_handle_t handle
= 0;
654 while ((win
= next_user_handle( &handle
, USER_WINDOW
)))
656 if (win
->thread
!= thread
) continue;
657 if (is_desktop_window( win
)) detach_window_thread( win
);
658 else free_window_handle( win
);
662 /* get the desktop window */
663 static struct window
*get_desktop_window( struct thread
*thread
)
665 struct window
*top_window
;
666 struct desktop
*desktop
= get_thread_desktop( thread
, 0 );
668 if (!desktop
) return NULL
;
669 top_window
= desktop
->top_window
;
670 release_object( desktop
);
674 /* check whether child is a descendant of parent */
675 int is_child_window( user_handle_t parent
, user_handle_t child
)
677 struct window
*child_ptr
= get_user_object( child
, USER_WINDOW
);
678 struct window
*parent_ptr
= get_user_object( parent
, USER_WINDOW
);
680 if (!child_ptr
|| !parent_ptr
) return 0;
681 while (child_ptr
->parent
)
683 if (child_ptr
->parent
== parent_ptr
) return 1;
684 child_ptr
= child_ptr
->parent
;
689 /* check if window can be set as foreground window */
690 int is_valid_foreground_window( user_handle_t window
)
692 struct window
*win
= get_user_object( window
, USER_WINDOW
);
693 return win
&& (win
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
;
696 /* make a window active if possible */
697 int make_window_active( user_handle_t window
)
699 struct window
*owner
, *win
= get_window( window
);
703 /* set last active for window and its owners */
707 owner
->last_active
= win
->handle
;
708 owner
= get_user_object( owner
->owner
, USER_WINDOW
);
713 /* increment (or decrement) the window paint count */
714 static inline void inc_window_paint_count( struct window
*win
, int incr
)
716 if (win
->thread
) inc_queue_paint_count( win
->thread
, incr
);
719 /* map a point between different DPI scaling levels */
720 static void map_dpi_point( struct window
*win
, int *x
, int *y
, unsigned int from
, unsigned int to
)
722 if (!from
) from
= get_monitor_dpi( win
);
723 if (!to
) to
= get_monitor_dpi( win
);
724 if (from
== to
) return;
725 *x
= scale_dpi( *x
, from
, to
);
726 *y
= scale_dpi( *y
, from
, to
);
729 /* map a window rectangle between different DPI scaling levels */
730 static void map_dpi_rect( struct window
*win
, rectangle_t
*rect
, unsigned int from
, unsigned int to
)
732 if (!from
) from
= get_monitor_dpi( win
);
733 if (!to
) to
= get_monitor_dpi( win
);
734 if (from
== to
) return;
735 scale_dpi_rect( rect
, from
, to
);
738 /* map a region between different DPI scaling levels */
739 static void map_dpi_region( struct window
*win
, struct region
*region
, unsigned int from
, unsigned int to
)
741 if (!from
) from
= get_monitor_dpi( win
);
742 if (!to
) to
= get_monitor_dpi( win
);
743 if (from
== to
) return;
744 scale_region( region
, from
, to
);
747 /* convert coordinates from client to screen coords */
748 static inline void client_to_screen( struct window
*win
, int *x
, int *y
)
750 for ( ; win
&& !is_desktop_window(win
); win
= win
->parent
)
752 *x
+= win
->client_rect
.left
;
753 *y
+= win
->client_rect
.top
;
757 /* convert coordinates from screen to client coords and dpi */
758 static void screen_to_client( struct window
*win
, int *x
, int *y
, unsigned int dpi
)
760 int offset_x
= 0, offset_y
= 0;
762 if (is_desktop_window( win
)) return;
764 client_to_screen( win
, &offset_x
, &offset_y
);
765 map_dpi_point( win
, x
, y
, dpi
, get_window_dpi( win
) );
770 /* check if window and all its ancestors are visible */
771 static int is_visible( const struct window
*win
)
775 if (!(win
->style
& WS_VISIBLE
)) return 0;
777 /* if parent is minimized children are not visible */
778 if (win
&& (win
->style
& WS_MINIMIZE
)) return 0;
783 /* same as is_visible but takes a window handle */
784 int is_window_visible( user_handle_t window
)
786 struct window
*win
= get_user_object( window
, USER_WINDOW
);
788 return is_visible( win
);
791 int is_window_transparent( user_handle_t window
)
793 struct window
*win
= get_user_object( window
, USER_WINDOW
);
795 return (win
->ex_style
& (WS_EX_LAYERED
|WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
|WS_EX_TRANSPARENT
);
798 static int is_window_using_parent_dc( struct window
*win
)
800 return (win
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& (get_class_style( win
->class ) & CS_PARENTDC
) != 0;
803 static int is_window_composited( struct window
*win
)
805 return (win
->ex_style
& WS_EX_COMPOSITED
) != 0 && !is_window_using_parent_dc(win
);
808 static int is_parent_composited( struct window
*win
)
810 return win
->parent
&& is_window_composited( win
->parent
);
813 /* check if point is inside the window, and map to window dpi */
814 static int is_point_in_window( struct window
*win
, int *x
, int *y
, unsigned int dpi
)
816 if (!(win
->style
& WS_VISIBLE
)) return 0; /* not visible */
817 if ((win
->style
& (WS_POPUP
|WS_CHILD
|WS_DISABLED
)) == (WS_CHILD
|WS_DISABLED
))
818 return 0; /* disabled child */
819 if ((win
->ex_style
& (WS_EX_LAYERED
|WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
|WS_EX_TRANSPARENT
))
820 return 0; /* transparent */
821 map_dpi_point( win
, x
, y
, dpi
, get_window_dpi( win
) );
822 if (!point_in_rect( &win
->visible_rect
, *x
, *y
))
823 return 0; /* not in window */
824 if (win
->win_region
&&
825 !point_in_region( win
->win_region
, *x
- win
->window_rect
.left
, *y
- win
->window_rect
.top
))
826 return 0; /* not in window region */
830 /* fill an array with the handles of the children of a specified window */
831 static unsigned int get_children_windows( struct window
*parent
, atom_t atom
, thread_id_t tid
,
832 user_handle_t
*handles
, unsigned int max_count
)
835 unsigned int count
= 0;
837 if (!parent
) return 0;
839 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
841 if (atom
&& get_class_atom(ptr
->class) != atom
) continue;
842 if (tid
&& get_thread_id(ptr
->thread
) != tid
) continue;
845 if (count
>= max_count
) break;
846 handles
[count
] = ptr
->handle
;
853 /* find child of 'parent' that contains the given point (in parent-relative coords) */
854 static struct window
*child_window_from_point( struct window
*parent
, int x
, int y
)
858 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
860 int x_child
= x
, y_child
= y
;
862 if (!is_point_in_window( ptr
, &x_child
, &y_child
, get_window_dpi( parent
) )) continue; /* skip it */
864 /* if window is minimized or disabled, return at once */
865 if (ptr
->style
& (WS_MINIMIZE
|WS_DISABLED
)) return ptr
;
867 /* if point is not in client area, return at once */
868 if (!point_in_rect( &ptr
->client_rect
, x_child
, y_child
)) return ptr
;
870 return child_window_from_point( ptr
, x_child
- ptr
->client_rect
.left
,
871 y_child
- ptr
->client_rect
.top
);
873 return parent
; /* not found any child */
876 /* find all children of 'parent' that contain the given point */
877 static int get_window_children_from_point( struct window
*parent
, int x
, int y
,
878 struct user_handle_array
*array
)
882 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
884 int x_child
= x
, y_child
= y
;
886 if (!is_point_in_window( ptr
, &x_child
, &y_child
, get_window_dpi( parent
) )) continue; /* skip it */
888 /* if point is in client area, and window is not minimized or disabled, check children */
889 if (!(ptr
->style
& (WS_MINIMIZE
|WS_DISABLED
)) && point_in_rect( &ptr
->client_rect
, x_child
, y_child
))
891 if (!get_window_children_from_point( ptr
, x_child
- ptr
->client_rect
.left
,
892 y_child
- ptr
->client_rect
.top
, array
))
896 /* now add window to the array */
897 if (!add_handle_to_array( array
, ptr
->handle
)) return 0;
902 /* get handle of root of top-most window containing point */
903 user_handle_t
shallow_window_from_point( struct desktop
*desktop
, int x
, int y
)
907 if (!desktop
->top_window
) return 0;
909 LIST_FOR_EACH_ENTRY( ptr
, &desktop
->top_window
->children
, struct window
, entry
)
911 int x_child
= x
, y_child
= y
;
913 if (!is_point_in_window( ptr
, &x_child
, &y_child
, 0 )) continue; /* skip it */
916 return desktop
->top_window
->handle
;
919 /* return thread of top-most window containing point (in absolute coords) */
920 struct thread
*window_thread_from_point( user_handle_t scope
, int x
, int y
)
922 struct window
*win
= get_user_object( scope
, USER_WINDOW
);
924 if (!win
) return NULL
;
926 screen_to_client( win
, &x
, &y
, 0 );
927 win
= child_window_from_point( win
, x
, y
);
928 if (!win
->thread
) return NULL
;
929 return (struct thread
*)grab_object( win
->thread
);
932 /* return list of all windows containing point (in absolute coords) */
933 static int all_windows_from_point( struct window
*top
, int x
, int y
, unsigned int dpi
,
934 struct user_handle_array
*array
)
936 if (!is_desktop_window( top
) && !is_desktop_window( top
->parent
))
938 screen_to_client( top
->parent
, &x
, &y
, dpi
);
939 dpi
= get_window_dpi( top
->parent
);
942 if (!is_point_in_window( top
, &x
, &y
, dpi
)) return 1;
943 /* if point is in client area, and window is not minimized or disabled, check children */
944 if (!(top
->style
& (WS_MINIMIZE
|WS_DISABLED
)) && point_in_rect( &top
->client_rect
, x
, y
))
946 if (!is_desktop_window(top
))
948 x
-= top
->client_rect
.left
;
949 y
-= top
->client_rect
.top
;
951 if (!get_window_children_from_point( top
, x
, y
, array
)) return 0;
953 /* now add window to the array */
954 if (!add_handle_to_array( array
, top
->handle
)) return 0;
959 /* return the thread owning a window */
960 struct thread
*get_window_thread( user_handle_t handle
)
962 struct window
*win
= get_user_object( handle
, USER_WINDOW
);
963 if (!win
|| !win
->thread
) return NULL
;
964 return (struct thread
*)grab_object( win
->thread
);
968 /* check if any area of a window needs repainting */
969 static inline int win_needs_repaint( struct window
*win
)
971 return win
->update_region
|| (win
->paint_flags
& PAINT_INTERNAL
);
975 /* find a child of the specified window that needs repainting */
976 static struct window
*find_child_to_repaint( struct window
*parent
, struct thread
*thread
)
978 struct window
*ptr
, *ret
= NULL
;
980 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
982 if (!(ptr
->style
& WS_VISIBLE
)) continue;
983 if (ptr
->thread
== thread
&& win_needs_repaint( ptr
))
985 else if (!(ptr
->style
& WS_MINIMIZE
)) /* explore its children */
986 ret
= find_child_to_repaint( ptr
, thread
);
990 if (ret
&& (ret
->ex_style
& WS_EX_TRANSPARENT
))
992 /* transparent window, check for non-transparent sibling to paint first */
993 for (ptr
= get_next_window(ret
); ptr
; ptr
= get_next_window(ptr
))
995 if (!(ptr
->style
& WS_VISIBLE
)) continue;
996 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
997 if (ptr
->thread
!= thread
) continue;
998 if (win_needs_repaint( ptr
)) return ptr
;
1005 /* find a window that needs to receive a WM_PAINT; also clear its internal paint flag */
1006 user_handle_t
find_window_to_repaint( user_handle_t parent
, struct thread
*thread
)
1008 struct window
*ptr
, *win
, *top_window
= get_desktop_window( thread
);
1010 if (!top_window
) return 0;
1012 if (top_window
->thread
== thread
&& win_needs_repaint( top_window
)) win
= top_window
;
1013 else win
= find_child_to_repaint( top_window
, thread
);
1017 /* check that it is a child of the specified parent */
1018 for (ptr
= win
; ptr
; ptr
= ptr
->parent
)
1019 if (ptr
->handle
== parent
) break;
1020 /* otherwise don't return any window, we don't repaint a child before its parent */
1021 if (!ptr
) win
= NULL
;
1024 win
->paint_flags
&= ~PAINT_INTERNAL
;
1029 /* intersect the window region with the specified region, relative to the window parent */
1030 static struct region
*intersect_window_region( struct region
*region
, struct window
*win
)
1032 /* make region relative to window rect */
1033 offset_region( region
, -win
->window_rect
.left
, -win
->window_rect
.top
);
1034 if (!intersect_region( region
, region
, win
->win_region
)) return NULL
;
1035 /* make region relative to parent again */
1036 offset_region( region
, win
->window_rect
.left
, win
->window_rect
.top
);
1041 /* convert coordinates from client to screen coords */
1042 static inline void client_to_screen_rect( struct window
*win
, rectangle_t
*rect
)
1044 for ( ; win
&& !is_desktop_window(win
); win
= win
->parent
)
1045 offset_rect( rect
, win
->client_rect
.left
, win
->client_rect
.top
);
1048 /* map the region from window to screen coordinates */
1049 static inline void map_win_region_to_screen( struct window
*win
, struct region
*region
)
1051 if (!is_desktop_window(win
))
1053 int x
= win
->window_rect
.left
;
1054 int y
= win
->window_rect
.top
;
1055 client_to_screen( win
->parent
, &x
, &y
);
1056 offset_region( region
, x
, y
);
1061 /* clip all children of a given window out of the visible region */
1062 static struct region
*clip_children( struct window
*parent
, struct window
*last
,
1063 struct region
*region
, int offset_x
, int offset_y
)
1066 struct region
*tmp
= create_empty_region();
1068 if (!tmp
) return NULL
;
1069 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
1071 if (ptr
== last
) break;
1072 if (!(ptr
->style
& WS_VISIBLE
)) continue;
1073 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
1074 set_region_rect( tmp
, &ptr
->visible_rect
);
1075 if (ptr
->win_region
&& !intersect_window_region( tmp
, ptr
))
1080 offset_region( tmp
, offset_x
, offset_y
);
1081 if (!(region
= subtract_region( region
, region
, tmp
))) break;
1082 if (is_region_empty( region
)) break;
1089 /* set the region to the client rect clipped by the window rect, in parent-relative coordinates */
1090 static void set_region_client_rect( struct region
*region
, struct window
*win
)
1094 intersect_rect( &rect
, &win
->window_rect
, &win
->client_rect
);
1095 intersect_rect( &rect
, &rect
, &win
->surface_rect
);
1096 set_region_rect( region
, &rect
);
1100 /* set the region to the visible rect clipped by the window surface, in parent-relative coordinates */
1101 static void set_region_visible_rect( struct region
*region
, struct window
*win
)
1105 intersect_rect( &rect
, &win
->visible_rect
, &win
->surface_rect
);
1106 set_region_rect( region
, &rect
);
1110 /* get the top-level window to clip against for a given window */
1111 static inline struct window
*get_top_clipping_window( struct window
*win
)
1113 while (!(win
->paint_flags
& PAINT_HAS_SURFACE
) && win
->parent
&& !is_desktop_window(win
->parent
))
1119 /* compute the visible region of a window, in window coordinates */
1120 static struct region
*get_visible_region( struct window
*win
, unsigned int flags
)
1122 struct region
*tmp
= NULL
, *region
;
1123 int offset_x
, offset_y
;
1125 if (!(region
= create_empty_region())) return NULL
;
1127 /* first check if all ancestors are visible */
1129 if (!is_visible( win
)) return region
; /* empty region */
1131 if (is_desktop_window( win
))
1133 set_region_rect( region
, &win
->window_rect
);
1137 /* create a region relative to the window itself */
1139 if ((flags
& DCX_PARENTCLIP
) && !is_desktop_window( win
->parent
))
1141 set_region_client_rect( region
, win
->parent
);
1142 offset_region( region
, -win
->parent
->client_rect
.left
, -win
->parent
->client_rect
.top
);
1144 else if (flags
& DCX_WINDOW
)
1146 set_region_visible_rect( region
, win
);
1147 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
1151 set_region_client_rect( region
, win
);
1152 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
1157 if (flags
& DCX_CLIPCHILDREN
)
1159 if (!clip_children( win
, NULL
, region
, win
->client_rect
.left
, win
->client_rect
.top
)) goto error
;
1162 /* clip siblings of ancestors */
1164 offset_x
= win
->window_rect
.left
;
1165 offset_y
= win
->window_rect
.top
;
1167 if ((tmp
= create_empty_region()) != NULL
)
1169 while (!is_desktop_window( win
->parent
))
1171 /* we don't clip out top-level siblings as that's up to the native windowing system */
1172 if (win
->style
& WS_CLIPSIBLINGS
)
1174 if (!clip_children( win
->parent
, win
, region
, 0, 0 )) goto error
;
1175 if (is_region_empty( region
)) break;
1177 /* clip to parent client area */
1179 offset_x
+= win
->client_rect
.left
;
1180 offset_y
+= win
->client_rect
.top
;
1181 offset_region( region
, win
->client_rect
.left
, win
->client_rect
.top
);
1182 set_region_client_rect( tmp
, win
);
1183 if (win
->win_region
&& !intersect_window_region( tmp
, win
)) goto error
;
1184 if (!intersect_region( region
, region
, tmp
)) goto error
;
1185 if (is_region_empty( region
)) break;
1189 offset_region( region
, -offset_x
, -offset_y
); /* make it relative to target window */
1193 if (tmp
) free_region( tmp
);
1194 free_region( region
);
1199 /* clip all children with a custom pixel format out of the visible region */
1200 static struct region
*clip_pixel_format_children( struct window
*parent
, struct region
*parent_clip
,
1201 struct region
*region
, int offset_x
, int offset_y
)
1204 struct region
*clip
= create_empty_region();
1206 if (!clip
) return NULL
;
1208 LIST_FOR_EACH_ENTRY_REV( ptr
, &parent
->children
, struct window
, entry
)
1210 if (!(ptr
->style
& WS_VISIBLE
)) continue;
1211 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
1213 /* add the visible rect */
1214 set_region_rect( clip
, &ptr
->visible_rect
);
1215 if (ptr
->win_region
&& !intersect_window_region( clip
, ptr
)) break;
1216 offset_region( clip
, offset_x
, offset_y
);
1217 if (!intersect_region( clip
, clip
, parent_clip
)) break;
1218 if (!union_region( region
, region
, clip
)) break;
1219 if (!(ptr
->paint_flags
& (PAINT_HAS_PIXEL_FORMAT
| PAINT_PIXEL_FORMAT_CHILD
))) continue;
1221 /* subtract the client rect if it uses a custom pixel format */
1222 set_region_rect( clip
, &ptr
->client_rect
);
1223 if (ptr
->win_region
&& !intersect_window_region( clip
, ptr
)) break;
1224 offset_region( clip
, offset_x
, offset_y
);
1225 if (!intersect_region( clip
, clip
, parent_clip
)) break;
1226 if ((ptr
->paint_flags
& PAINT_HAS_PIXEL_FORMAT
) && !subtract_region( region
, region
, clip
))
1229 if (!clip_pixel_format_children( ptr
, clip
, region
, offset_x
+ ptr
->client_rect
.left
,
1230 offset_y
+ ptr
->client_rect
.top
))
1233 free_region( clip
);
1238 /* compute the visible surface region of a window, in parent coordinates */
1239 static struct region
*get_surface_region( struct window
*win
)
1241 struct region
*region
, *clip
;
1242 int offset_x
, offset_y
;
1244 /* create a region relative to the window itself */
1246 if (!(region
= create_empty_region())) return NULL
;
1247 if (!(clip
= create_empty_region())) goto error
;
1248 set_region_rect( region
, &win
->visible_rect
);
1249 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
1250 set_region_rect( clip
, &win
->client_rect
);
1251 if (win
->win_region
&& !intersect_window_region( clip
, win
)) goto error
;
1253 if ((win
->paint_flags
& PAINT_HAS_PIXEL_FORMAT
) && !subtract_region( region
, region
, clip
))
1258 if (!is_desktop_window(win
))
1260 offset_x
= win
->client_rect
.left
;
1261 offset_y
= win
->client_rect
.top
;
1263 else offset_x
= offset_y
= 0;
1265 if (!clip_pixel_format_children( win
, clip
, region
, offset_x
, offset_y
)) goto error
;
1267 free_region( clip
);
1271 if (clip
) free_region( clip
);
1272 free_region( region
);
1277 /* get the window class of a window */
1278 struct window_class
* get_window_class( user_handle_t window
)
1281 if (!(win
= get_window( window
))) return NULL
;
1282 if (!win
->class) set_error( STATUS_ACCESS_DENIED
);
1286 /* determine the window visible rectangle, i.e. window or client rect cropped by parent rects */
1287 /* the returned rectangle is in window coordinates; return 0 if rectangle is empty */
1288 static int get_window_visible_rect( struct window
*win
, rectangle_t
*rect
, int frame
)
1290 int offset_x
= win
->window_rect
.left
, offset_y
= win
->window_rect
.top
;
1292 *rect
= frame
? win
->window_rect
: win
->client_rect
;
1294 if (!(win
->style
& WS_VISIBLE
)) return 0;
1295 if (is_desktop_window( win
)) return 1;
1297 while (!is_desktop_window( win
->parent
))
1300 if (!(win
->style
& WS_VISIBLE
) || win
->style
& WS_MINIMIZE
) return 0;
1301 offset_x
+= win
->client_rect
.left
;
1302 offset_y
+= win
->client_rect
.top
;
1303 offset_rect( rect
, win
->client_rect
.left
, win
->client_rect
.top
);
1304 if (!intersect_rect( rect
, rect
, &win
->client_rect
)) return 0;
1305 if (!intersect_rect( rect
, rect
, &win
->window_rect
)) return 0;
1307 offset_rect( rect
, -offset_x
, -offset_y
);
1311 /* return a copy of the specified region cropped to the window client or frame rectangle, */
1312 /* and converted from client to window coordinates. Helper for (in)validate_window. */
1313 static struct region
*crop_region_to_win_rect( struct window
*win
, struct region
*region
, int frame
)
1318 if (!get_window_visible_rect( win
, &rect
, frame
)) return NULL
;
1319 if (!(tmp
= create_empty_region())) return NULL
;
1320 set_region_rect( tmp
, &rect
);
1324 /* map it to client coords */
1325 offset_region( tmp
, win
->window_rect
.left
- win
->client_rect
.left
,
1326 win
->window_rect
.top
- win
->client_rect
.top
);
1328 /* intersect specified region with bounding rect */
1329 if (!intersect_region( tmp
, region
, tmp
)) goto done
;
1330 if (is_region_empty( tmp
)) goto done
;
1332 /* map it back to window coords */
1333 offset_region( tmp
, win
->client_rect
.left
- win
->window_rect
.left
,
1334 win
->client_rect
.top
- win
->window_rect
.top
);
1344 /* set a region as new update region for the window */
1345 static void set_update_region( struct window
*win
, struct region
*region
)
1347 if (region
&& !is_region_empty( region
))
1349 if (!win
->update_region
) inc_window_paint_count( win
, 1 );
1350 else free_region( win
->update_region
);
1351 win
->update_region
= region
;
1355 if (win
->update_region
)
1357 inc_window_paint_count( win
, -1 );
1358 free_region( win
->update_region
);
1360 win
->paint_flags
&= ~(PAINT_ERASE
| PAINT_DELAYED_ERASE
| PAINT_NONCLIENT
);
1361 win
->update_region
= NULL
;
1362 if (region
) free_region( region
);
1367 /* add a region to the update region; the passed region is freed or reused */
1368 static int add_update_region( struct window
*win
, struct region
*region
)
1370 if (win
->update_region
&& !union_region( region
, win
->update_region
, region
))
1372 free_region( region
);
1375 set_update_region( win
, region
);
1380 /* crop the update region of children to the specified rectangle, in client coords */
1381 static void crop_children_update_region( struct window
*win
, rectangle_t
*rect
)
1383 struct window
*child
;
1385 rectangle_t child_rect
;
1387 LIST_FOR_EACH_ENTRY( child
, &win
->children
, struct window
, entry
)
1389 if (!(child
->style
& WS_VISIBLE
)) continue;
1390 if (!rect
) /* crop everything out */
1392 crop_children_update_region( child
, NULL
);
1393 set_update_region( child
, NULL
);
1397 /* nothing to do if child is completely inside rect */
1398 if (child
->window_rect
.left
>= rect
->left
&&
1399 child
->window_rect
.top
>= rect
->top
&&
1400 child
->window_rect
.right
<= rect
->right
&&
1401 child
->window_rect
.bottom
<= rect
->bottom
) continue;
1403 /* map to child client coords and crop grand-children */
1405 offset_rect( &child_rect
, -child
->client_rect
.left
, -child
->client_rect
.top
);
1406 crop_children_update_region( child
, &child_rect
);
1408 /* now crop the child itself */
1409 if (!child
->update_region
) continue;
1410 if (!(tmp
= create_empty_region())) continue;
1411 set_region_rect( tmp
, rect
);
1412 offset_region( tmp
, -child
->window_rect
.left
, -child
->window_rect
.top
);
1413 if (intersect_region( tmp
, child
->update_region
, tmp
)) set_update_region( child
, tmp
);
1414 else free_region( tmp
);
1419 /* validate the non client area of a window */
1420 static void validate_non_client( struct window
*win
)
1425 if (!win
->update_region
) return; /* nothing to do */
1427 /* get client rect in window coords */
1428 rect
.left
= win
->client_rect
.left
- win
->window_rect
.left
;
1429 rect
.top
= win
->client_rect
.top
- win
->window_rect
.top
;
1430 rect
.right
= win
->client_rect
.right
- win
->window_rect
.left
;
1431 rect
.bottom
= win
->client_rect
.bottom
- win
->window_rect
.top
;
1433 if ((tmp
= create_empty_region()))
1435 set_region_rect( tmp
, &rect
);
1436 if (intersect_region( tmp
, win
->update_region
, tmp
))
1437 set_update_region( win
, tmp
);
1441 win
->paint_flags
&= ~PAINT_NONCLIENT
;
1445 /* validate a window completely so that we don't get any further paint messages for it */
1446 static void validate_whole_window( struct window
*win
)
1448 set_update_region( win
, NULL
);
1450 if (win
->paint_flags
& PAINT_INTERNAL
)
1452 win
->paint_flags
&= ~PAINT_INTERNAL
;
1453 inc_window_paint_count( win
, -1 );
1458 /* validate a window's children so that we don't get any further paint messages for it */
1459 static void validate_children( struct window
*win
)
1461 struct window
*child
;
1463 LIST_FOR_EACH_ENTRY( child
, &win
->children
, struct window
, entry
)
1465 if (!(child
->style
& WS_VISIBLE
)) continue;
1466 validate_children(child
);
1467 validate_whole_window(child
);
1472 /* validate the update region of a window on all parents; helper for get_update_region */
1473 static void validate_parents( struct window
*child
)
1475 int offset_x
= 0, offset_y
= 0;
1476 struct window
*win
= child
;
1477 struct region
*tmp
= NULL
;
1479 if (!child
->update_region
) return;
1483 /* map to parent client coords */
1484 offset_x
+= win
->window_rect
.left
;
1485 offset_y
+= win
->window_rect
.top
;
1489 /* and now map to window coords */
1490 offset_x
+= win
->client_rect
.left
- win
->window_rect
.left
;
1491 offset_y
+= win
->client_rect
.top
- win
->window_rect
.top
;
1493 if (win
->update_region
&& !(win
->style
& WS_CLIPCHILDREN
))
1495 if (!tmp
&& !(tmp
= create_empty_region())) return;
1496 offset_region( child
->update_region
, offset_x
, offset_y
);
1497 if (subtract_region( tmp
, win
->update_region
, child
->update_region
))
1499 set_update_region( win
, tmp
);
1502 /* restore child coords */
1503 offset_region( child
->update_region
, -offset_x
, -offset_y
);
1506 if (tmp
) free_region( tmp
);
1510 /* add/subtract a region (in client coordinates) to the update region of the window */
1511 static void redraw_window( struct window
*win
, struct region
*region
, int frame
, unsigned int flags
)
1513 struct region
*child_rgn
, *tmp
;
1514 struct window
*child
;
1516 if (flags
& RDW_INVALIDATE
)
1518 if (!(tmp
= crop_region_to_win_rect( win
, region
, frame
))) return;
1520 if (!add_update_region( win
, tmp
)) return;
1522 if (flags
& RDW_FRAME
) win
->paint_flags
|= PAINT_NONCLIENT
;
1523 if (flags
& RDW_ERASE
) win
->paint_flags
|= PAINT_ERASE
;
1525 else if (flags
& RDW_VALIDATE
)
1527 if (!region
&& (flags
& RDW_NOFRAME
)) /* shortcut: validate everything */
1529 set_update_region( win
, NULL
);
1531 else if (win
->update_region
)
1533 if ((tmp
= crop_region_to_win_rect( win
, region
, frame
)))
1535 if (!subtract_region( tmp
, win
->update_region
, tmp
))
1540 set_update_region( win
, tmp
);
1542 if (flags
& RDW_NOFRAME
) validate_non_client( win
);
1543 if (flags
& RDW_NOERASE
) win
->paint_flags
&= ~(PAINT_ERASE
| PAINT_DELAYED_ERASE
);
1547 if ((flags
& RDW_INTERNALPAINT
) && !(win
->paint_flags
& PAINT_INTERNAL
))
1549 win
->paint_flags
|= PAINT_INTERNAL
;
1550 inc_window_paint_count( win
, 1 );
1552 else if ((flags
& RDW_NOINTERNALPAINT
) && (win
->paint_flags
& PAINT_INTERNAL
))
1554 win
->paint_flags
&= ~PAINT_INTERNAL
;
1555 inc_window_paint_count( win
, -1 );
1558 /* now process children recursively */
1560 if (flags
& RDW_NOCHILDREN
) return;
1561 if (win
->style
& WS_MINIMIZE
) return;
1562 if ((win
->style
& WS_CLIPCHILDREN
) && !(flags
& RDW_ALLCHILDREN
)) return;
1564 if (!(tmp
= crop_region_to_win_rect( win
, region
, 0 ))) return;
1566 /* map to client coordinates */
1567 offset_region( tmp
, win
->window_rect
.left
- win
->client_rect
.left
,
1568 win
->window_rect
.top
- win
->client_rect
.top
);
1570 if (flags
& RDW_INVALIDATE
) flags
|= RDW_FRAME
| RDW_ERASE
;
1572 LIST_FOR_EACH_ENTRY( child
, &win
->children
, struct window
, entry
)
1574 if (!(child
->style
& WS_VISIBLE
)) continue;
1575 if (!(child_rgn
= create_empty_region())) continue;
1576 if (copy_region( child_rgn
, tmp
))
1578 map_dpi_region( child
, child_rgn
, get_window_dpi( win
), get_window_dpi( child
) );
1579 if (rect_in_region( child_rgn
, &child
->window_rect
))
1581 offset_region( child_rgn
, -child
->client_rect
.left
, -child
->client_rect
.top
);
1582 redraw_window( child
, child_rgn
, 1, flags
);
1585 free_region( child_rgn
);
1592 /* retrieve the update flags for a window depending on the state of the update region */
1593 static unsigned int get_update_flags( struct window
*win
, unsigned int flags
)
1595 unsigned int ret
= 0;
1597 if (flags
& UPDATE_NONCLIENT
)
1599 if ((win
->paint_flags
& PAINT_NONCLIENT
) && win
->update_region
) ret
|= UPDATE_NONCLIENT
;
1601 if (flags
& UPDATE_ERASE
)
1603 if ((win
->paint_flags
& PAINT_ERASE
) && win
->update_region
) ret
|= UPDATE_ERASE
;
1605 if (flags
& UPDATE_PAINT
)
1607 if (win
->update_region
)
1609 if (win
->paint_flags
& PAINT_DELAYED_ERASE
) ret
|= UPDATE_DELAYED_ERASE
;
1610 ret
|= UPDATE_PAINT
;
1613 if (flags
& UPDATE_INTERNALPAINT
)
1615 if (win
->paint_flags
& PAINT_INTERNAL
)
1617 ret
|= UPDATE_INTERNALPAINT
;
1618 if (win
->paint_flags
& PAINT_DELAYED_ERASE
) ret
|= UPDATE_DELAYED_ERASE
;
1625 /* iterate through the children of the given window until we find one with some update flags */
1626 static unsigned int get_child_update_flags( struct window
*win
, struct window
*from_child
,
1627 unsigned int flags
, struct window
**child
)
1630 unsigned int ret
= 0;
1632 /* first make sure we want to iterate children at all */
1634 if (win
->style
& WS_MINIMIZE
) return 0;
1636 /* note: the WS_CLIPCHILDREN test is the opposite of the invalidation case,
1637 * here we only want to repaint children of windows that clip them, others
1638 * need to wait for WM_PAINT to be done in the parent first.
1640 if (!(flags
& UPDATE_ALLCHILDREN
) && !(win
->style
& WS_CLIPCHILDREN
)) return 0;
1642 LIST_FOR_EACH_ENTRY( ptr
, &win
->children
, struct window
, entry
)
1644 if (from_child
) /* skip all children until from_child is found */
1646 if (ptr
== from_child
) from_child
= NULL
;
1649 if (!(ptr
->style
& WS_VISIBLE
)) continue;
1650 if ((ret
= get_update_flags( ptr
, flags
)) != 0)
1655 if ((ret
= get_child_update_flags( ptr
, NULL
, flags
, child
))) break;
1660 /* iterate through children and siblings of the given window until we find one with some update flags */
1661 static unsigned int get_window_update_flags( struct window
*win
, struct window
*from_child
,
1662 unsigned int flags
, struct window
**child
)
1665 struct window
*ptr
, *from_sibling
= NULL
;
1667 /* if some parent is not visible start from the next sibling */
1669 if (!is_visible( win
)) return 0;
1670 for (ptr
= from_child
; ptr
; ptr
= ptr
->parent
)
1672 if (!(ptr
->style
& WS_VISIBLE
) || (ptr
->style
& WS_MINIMIZE
)) from_sibling
= ptr
;
1673 if (ptr
== win
) break;
1676 /* non-client painting must be delayed if one of the parents is going to
1677 * be repainted and doesn't clip children */
1679 if ((flags
& UPDATE_NONCLIENT
) && !(flags
& (UPDATE_PAINT
|UPDATE_INTERNALPAINT
)))
1681 for (ptr
= win
->parent
; ptr
; ptr
= ptr
->parent
)
1683 if (!(ptr
->style
& WS_CLIPCHILDREN
) && win_needs_repaint( ptr
))
1686 if (from_child
&& !(flags
& UPDATE_ALLCHILDREN
))
1688 for (ptr
= from_sibling
? from_sibling
: from_child
; ptr
; ptr
= ptr
->parent
)
1690 if (!(ptr
->style
& WS_CLIPCHILDREN
) && win_needs_repaint( ptr
)) from_sibling
= ptr
;
1691 if (ptr
== win
) break;
1697 /* check window itself (only if not restarting from a child) */
1701 if ((ret
= get_update_flags( win
, flags
)))
1709 /* now check children */
1711 if (flags
& UPDATE_NOCHILDREN
) return 0;
1714 if ((ret
= get_child_update_flags( from_child
, NULL
, flags
, child
))) return ret
;
1715 from_sibling
= from_child
;
1718 /* then check siblings and parent siblings */
1720 while (from_sibling
->parent
&& from_sibling
!= win
)
1722 if ((ret
= get_child_update_flags( from_sibling
->parent
, from_sibling
, flags
, child
)))
1724 from_sibling
= from_sibling
->parent
;
1730 /* expose the areas revealed by a vis region change on the window parent */
1731 /* returns the region exposed on the window itself (in client coordinates) */
1732 static struct region
*expose_window( struct window
*win
, const rectangle_t
*old_window_rect
,
1733 struct region
*old_vis_rgn
, int zorder_changed
)
1735 struct region
*new_vis_rgn
, *exposed_rgn
;
1736 int is_composited
= is_parent_composited( win
);
1738 if (!(new_vis_rgn
= get_visible_region( win
, DCX_WINDOW
))) return NULL
;
1740 if (is_composited
&& !zorder_changed
&&
1741 is_rect_equal( old_window_rect
, &win
->window_rect
) &&
1742 is_region_equal( old_vis_rgn
, new_vis_rgn
))
1744 free_region( new_vis_rgn
);
1748 if ((exposed_rgn
= create_empty_region()))
1750 if ((is_composited
? union_region( exposed_rgn
, new_vis_rgn
, old_vis_rgn
)
1751 : subtract_region( exposed_rgn
, new_vis_rgn
, old_vis_rgn
)) &&
1752 !is_region_empty( exposed_rgn
))
1754 /* make it relative to the new client area */
1755 offset_region( exposed_rgn
, win
->window_rect
.left
- win
->client_rect
.left
,
1756 win
->window_rect
.top
- win
->client_rect
.top
);
1760 free_region( exposed_rgn
);
1765 if (win
->parent
&& !is_desktop_window( win
->parent
))
1767 /* make it relative to the old window pos for subtracting */
1768 offset_region( new_vis_rgn
, win
->window_rect
.left
- old_window_rect
->left
,
1769 win
->window_rect
.top
- old_window_rect
->top
);
1771 if (is_region_empty( old_vis_rgn
) ||
1772 (is_composited
? union_region( new_vis_rgn
, old_vis_rgn
, new_vis_rgn
)
1773 : subtract_region( new_vis_rgn
, old_vis_rgn
, new_vis_rgn
)))
1775 if (!is_region_empty( new_vis_rgn
))
1777 /* make it relative to parent */
1778 offset_region( new_vis_rgn
, old_window_rect
->left
, old_window_rect
->top
);
1779 redraw_window( win
->parent
, new_vis_rgn
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1783 free_region( new_vis_rgn
);
1788 /* set the window and client rectangles, updating the update region if necessary */
1789 static void set_window_pos( struct window
*win
, struct window
*previous
,
1790 unsigned int swp_flags
, const rectangle_t
*window_rect
,
1791 const rectangle_t
*client_rect
, const rectangle_t
*visible_rect
,
1792 const rectangle_t
*surface_rect
, const rectangle_t
*valid_rect
)
1794 struct region
*old_vis_rgn
= NULL
, *exposed_rgn
= NULL
;
1795 const rectangle_t old_window_rect
= win
->window_rect
;
1796 const rectangle_t old_visible_rect
= win
->visible_rect
;
1797 const rectangle_t old_client_rect
= win
->client_rect
;
1799 int client_changed
, frame_changed
;
1800 int visible
= (win
->style
& WS_VISIBLE
) || (swp_flags
& SWP_SHOWWINDOW
);
1801 int zorder_changed
= 0;
1803 if (win
->parent
&& !is_visible( win
->parent
)) visible
= 0;
1805 if (visible
&& !(old_vis_rgn
= get_visible_region( win
, DCX_WINDOW
))) return;
1807 /* set the new window info before invalidating anything */
1809 win
->window_rect
= *window_rect
;
1810 win
->visible_rect
= *visible_rect
;
1811 win
->surface_rect
= *surface_rect
;
1812 win
->client_rect
= *client_rect
;
1813 if (!(swp_flags
& SWP_NOZORDER
) && win
->parent
) zorder_changed
|= link_window( win
, previous
);
1814 if (swp_flags
& SWP_SHOWWINDOW
) win
->style
|= WS_VISIBLE
;
1815 else if (swp_flags
& SWP_HIDEWINDOW
) win
->style
&= ~WS_VISIBLE
;
1817 /* keep children at the same position relative to top right corner when the parent is mirrored */
1818 if (win
->ex_style
& WS_EX_LAYOUTRTL
)
1820 struct window
*child
;
1821 int old_size
= old_client_rect
.right
- old_client_rect
.left
;
1822 int new_size
= win
->client_rect
.right
- win
->client_rect
.left
;
1824 if (old_size
!= new_size
) LIST_FOR_EACH_ENTRY( child
, &win
->children
, struct window
, entry
)
1826 offset_rect( &child
->window_rect
, new_size
- old_size
, 0 );
1827 offset_rect( &child
->visible_rect
, new_size
- old_size
, 0 );
1828 offset_rect( &child
->surface_rect
, new_size
- old_size
, 0 );
1829 offset_rect( &child
->client_rect
, new_size
- old_size
, 0 );
1833 /* reset cursor clip rectangle when the desktop changes size */
1834 if (win
== win
->desktop
->top_window
) set_clip_rectangle( win
->desktop
, NULL
, SET_CURSOR_NOCLIP
, 1 );
1836 /* if the window is not visible, everything is easy */
1837 if (!visible
) return;
1839 /* expose anything revealed by the change */
1841 if (!(swp_flags
& SWP_NOREDRAW
))
1842 exposed_rgn
= expose_window( win
, &old_window_rect
, old_vis_rgn
, zorder_changed
);
1844 if (!(win
->style
& WS_VISIBLE
))
1846 /* clear the update region since the window is no longer visible */
1847 validate_whole_window( win
);
1848 validate_children( win
);
1852 /* crop update region to the new window rect */
1854 if (win
->update_region
)
1856 if (get_window_visible_rect( win
, &rect
, 1 ))
1858 struct region
*tmp
= create_empty_region();
1861 set_region_rect( tmp
, &rect
);
1862 if (intersect_region( tmp
, win
->update_region
, tmp
))
1863 set_update_region( win
, tmp
);
1868 else set_update_region( win
, NULL
); /* visible rect is empty */
1871 /* crop children regions to the new window rect */
1873 if (get_window_visible_rect( win
, &rect
, 0 ))
1875 /* map to client coords */
1876 offset_rect( &rect
, win
->window_rect
.left
- win
->client_rect
.left
,
1877 win
->window_rect
.top
- win
->client_rect
.top
);
1878 crop_children_update_region( win
, &rect
);
1880 else crop_children_update_region( win
, NULL
);
1882 if (swp_flags
& SWP_NOREDRAW
) goto done
; /* do not repaint anything */
1884 /* expose the whole non-client area if it changed in any way */
1886 if (swp_flags
& SWP_NOCOPYBITS
)
1888 frame_changed
= ((swp_flags
& SWP_FRAMECHANGED
) ||
1889 memcmp( window_rect
, &old_window_rect
, sizeof(old_window_rect
) ) ||
1890 memcmp( visible_rect
, &old_visible_rect
, sizeof(old_visible_rect
) ));
1891 client_changed
= memcmp( client_rect
, &old_client_rect
, sizeof(old_client_rect
) );
1895 /* assume the bits have been moved to follow the window rect */
1896 int x_offset
= window_rect
->left
- old_window_rect
.left
;
1897 int y_offset
= window_rect
->top
- old_window_rect
.top
;
1898 frame_changed
= ((swp_flags
& SWP_FRAMECHANGED
) ||
1899 window_rect
->right
- old_window_rect
.right
!= x_offset
||
1900 window_rect
->bottom
- old_window_rect
.bottom
!= y_offset
||
1901 visible_rect
->left
- old_visible_rect
.left
!= x_offset
||
1902 visible_rect
->right
- old_visible_rect
.right
!= x_offset
||
1903 visible_rect
->top
- old_visible_rect
.top
!= y_offset
||
1904 visible_rect
->bottom
- old_visible_rect
.bottom
!= y_offset
);
1905 client_changed
= (client_rect
->left
- old_client_rect
.left
!= x_offset
||
1906 client_rect
->right
- old_client_rect
.right
!= x_offset
||
1907 client_rect
->top
- old_client_rect
.top
!= y_offset
||
1908 client_rect
->bottom
- old_client_rect
.bottom
!= y_offset
||
1909 memcmp( valid_rect
, client_rect
, sizeof(*client_rect
) ));
1912 if (frame_changed
|| client_changed
)
1914 struct region
*win_rgn
= old_vis_rgn
; /* reuse previous region */
1916 set_region_rect( win_rgn
, window_rect
);
1917 if (!is_rect_empty( valid_rect
))
1919 /* subtract the valid portion of client rect from the total region */
1920 struct region
*tmp
= create_empty_region();
1923 set_region_rect( tmp
, valid_rect
);
1924 /* subtract update region since invalid parts of the valid rect won't be copied */
1925 if (win
->update_region
)
1927 offset_region( tmp
, -window_rect
->left
, -window_rect
->top
);
1928 subtract_region( tmp
, tmp
, win
->update_region
);
1929 offset_region( tmp
, window_rect
->left
, window_rect
->top
);
1931 if (subtract_region( tmp
, win_rgn
, tmp
)) win_rgn
= tmp
;
1932 else free_region( tmp
);
1935 if (!is_desktop_window(win
))
1936 offset_region( win_rgn
, -client_rect
->left
, -client_rect
->top
);
1939 union_region( exposed_rgn
, exposed_rgn
, win_rgn
);
1940 if (win_rgn
!= old_vis_rgn
) free_region( win_rgn
);
1944 exposed_rgn
= win_rgn
;
1945 if (win_rgn
== old_vis_rgn
) old_vis_rgn
= NULL
;
1950 redraw_window( win
, exposed_rgn
, 1, RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
1953 if (old_vis_rgn
) free_region( old_vis_rgn
);
1954 if (exposed_rgn
) free_region( exposed_rgn
);
1955 clear_error(); /* we ignore out of memory errors once the new rects have been set */
1959 /* set the window region, updating the update region if necessary */
1960 static void set_window_region( struct window
*win
, struct region
*region
, int redraw
)
1962 struct region
*old_vis_rgn
= NULL
, *exposed_rgn
;
1964 /* no need to redraw if window is not visible */
1965 if (redraw
&& !is_visible( win
)) redraw
= 0;
1967 if (redraw
) old_vis_rgn
= get_visible_region( win
, DCX_WINDOW
);
1969 if (win
->win_region
) free_region( win
->win_region
);
1970 win
->win_region
= region
;
1972 /* expose anything revealed by the change */
1973 if (old_vis_rgn
&& ((exposed_rgn
= expose_window( win
, &win
->window_rect
, old_vis_rgn
, 0 ))))
1975 redraw_window( win
, exposed_rgn
, 1, RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
1976 free_region( exposed_rgn
);
1979 if (old_vis_rgn
) free_region( old_vis_rgn
);
1980 clear_error(); /* we ignore out of memory errors since the region has been set */
1984 /* destroy a window */
1985 void free_window_handle( struct window
*win
)
1987 struct window
*child
, *next
;
1989 assert( win
->handle
);
1991 /* hide the window */
1992 if (is_visible(win
))
1994 struct region
*vis_rgn
= get_visible_region( win
, DCX_WINDOW
);
1995 win
->style
&= ~WS_VISIBLE
;
1998 struct region
*exposed_rgn
= expose_window( win
, &win
->window_rect
, vis_rgn
, 0 );
1999 if (exposed_rgn
) free_region( exposed_rgn
);
2000 free_region( vis_rgn
);
2002 validate_whole_window( win
);
2003 validate_children( win
);
2006 /* destroy all children */
2007 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &win
->children
, struct window
, entry
)
2009 if (!child
->handle
) continue;
2010 if (!win
->thread
|| !child
->thread
|| win
->thread
== child
->thread
)
2011 free_window_handle( child
);
2013 send_notify_message( child
->handle
, WM_WINE_DESTROYWINDOW
, 0, 0 );
2015 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &win
->children
, struct window
, entry
)
2017 if (!child
->handle
) continue;
2018 if (!win
->thread
|| !child
->thread
|| win
->thread
== child
->thread
)
2019 free_window_handle( child
);
2021 send_notify_message( child
->handle
, WM_WINE_DESTROYWINDOW
, 0, 0 );
2024 /* reset global window pointers, if the corresponding window is destroyed */
2025 if (win
== shell_window
) shell_window
= NULL
;
2026 if (win
== shell_listview
) shell_listview
= NULL
;
2027 if (win
== progman_window
) progman_window
= NULL
;
2028 if (win
== taskman_window
) taskman_window
= NULL
;
2029 free_hotkeys( win
->desktop
, win
->handle
);
2030 cleanup_clipboard_window( win
->desktop
, win
->handle
);
2031 destroy_properties( win
);
2032 if (is_desktop_window(win
))
2034 struct desktop
*desktop
= win
->desktop
;
2035 assert( desktop
->top_window
== win
|| desktop
->msg_window
== win
);
2036 if (desktop
->top_window
== win
) desktop
->top_window
= NULL
;
2037 else desktop
->msg_window
= NULL
;
2039 else if (is_desktop_window( win
->parent
))
2041 post_message( win
->parent
->handle
, WM_PARENTNOTIFY
, WM_DESTROY
, win
->handle
);
2044 detach_window_thread( win
);
2046 if (win
->parent
) set_parent_window( win
, NULL
);
2047 free_user_handle( win
->handle
);
2049 release_object( win
);
2053 /* create a window */
2054 DECL_HANDLER(create_window
)
2056 struct window
*win
, *parent
= NULL
, *owner
= NULL
;
2057 struct unicode_str cls_name
= get_req_unicode_str();
2063 if (!(parent
= get_window( req
->parent
))) return;
2064 if (is_orphan_window( parent
))
2066 set_error( STATUS_INVALID_PARAMETER
);
2073 if (!(owner
= get_window( req
->owner
))) return;
2074 if (is_desktop_window(owner
)) owner
= NULL
;
2075 else if (parent
&& !is_desktop_window(parent
))
2077 /* an owned window must be created as top-level */
2078 set_error( STATUS_ACCESS_DENIED
);
2081 else /* owner must be a top-level window */
2082 while ((owner
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& !is_desktop_window(owner
->parent
))
2083 owner
= owner
->parent
;
2086 atom
= cls_name
.len
? find_global_atom( NULL
, &cls_name
) : req
->atom
;
2088 if (!(win
= create_window( parent
, owner
, atom
, req
->instance
))) return;
2090 if (parent
&& !is_desktop_window( parent
))
2091 win
->dpi_context
= parent
->dpi_context
;
2092 else if (!parent
|| !NTUSER_DPI_CONTEXT_IS_MONITOR_AWARE( req
->dpi_context
))
2093 win
->dpi_context
= req
->dpi_context
;
2095 win
->style
= req
->style
;
2096 win
->ex_style
= req
->ex_style
;
2098 reply
->handle
= win
->handle
;
2099 reply
->parent
= win
->parent
? win
->parent
->handle
: 0;
2100 reply
->owner
= win
->owner
;
2101 reply
->extra
= win
->nb_extra_bytes
;
2102 reply
->dpi_context
= win
->dpi_context
;
2103 reply
->class_ptr
= get_class_client_ptr( win
->class );
2107 /* set the parent of a window */
2108 DECL_HANDLER(set_parent
)
2110 struct window
*win
, *parent
= NULL
;
2112 if (!(win
= get_window( req
->handle
))) return;
2113 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
2115 if (is_desktop_window(win
) || is_orphan_window( win
) || (parent
&& is_orphan_window( parent
)))
2117 set_error( STATUS_INVALID_PARAMETER
);
2120 reply
->old_parent
= win
->parent
->handle
;
2121 reply
->full_parent
= parent
? parent
->handle
: 0;
2122 set_parent_window( win
, parent
);
2123 reply
->dpi_context
= win
->dpi_context
;
2127 /* destroy a window */
2128 DECL_HANDLER(destroy_window
)
2134 destroy_thread_windows( current
);
2136 else if ((win
= get_window( req
->handle
)))
2138 if (!is_desktop_window(win
)) free_window_handle( win
);
2139 else if (win
->thread
== current
) detach_window_thread( win
);
2140 else set_error( STATUS_ACCESS_DENIED
);
2145 /* retrieve the desktop window for the current thread */
2146 DECL_HANDLER(get_desktop_window
)
2148 struct desktop
*desktop
= get_thread_desktop( current
, 0 );
2150 if (!desktop
) return;
2152 if (!desktop
->top_window
&& req
->force
) /* create it */
2154 if ((desktop
->top_window
= create_window( NULL
, NULL
, DESKTOP_ATOM
, 0 )))
2156 detach_window_thread( desktop
->top_window
);
2157 desktop
->top_window
->style
= WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
2161 if (!desktop
->msg_window
&& req
->force
) /* create it */
2163 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e'};
2164 static const struct unicode_str name
= { messageW
, sizeof(messageW
) };
2165 atom_t atom
= add_global_atom( NULL
, &name
);
2166 if (atom
&& (desktop
->msg_window
= create_window( NULL
, NULL
, atom
, 0 )))
2168 detach_window_thread( desktop
->msg_window
);
2169 desktop
->msg_window
->style
= WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
2173 reply
->top_window
= desktop
->top_window
? desktop
->top_window
->handle
: 0;
2174 reply
->msg_window
= desktop
->msg_window
? desktop
->msg_window
->handle
: 0;
2175 release_object( desktop
);
2179 /* set a window owner */
2180 DECL_HANDLER(set_window_owner
)
2182 struct window
*win
= get_window( req
->handle
);
2183 struct window
*owner
= NULL
, *ptr
;
2186 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
2187 if (is_desktop_window(win
))
2189 set_error( STATUS_ACCESS_DENIED
);
2193 /* make sure owner is not a successor of window */
2194 for (ptr
= owner
; ptr
; ptr
= ptr
->owner
? get_window( ptr
->owner
) : NULL
)
2198 set_error( STATUS_INVALID_PARAMETER
);
2203 reply
->prev_owner
= win
->owner
;
2204 reply
->full_owner
= win
->owner
= owner
? owner
->handle
: 0;
2208 /* get information from a window handle */
2209 DECL_HANDLER(get_window_info
)
2211 struct window
*win
= get_window( req
->handle
);
2215 reply
->full_handle
= win
->handle
;
2216 reply
->last_active
= win
->handle
;
2217 reply
->is_unicode
= win
->is_unicode
;
2218 reply
->dpi_context
= win
->dpi_context
;
2220 if (get_user_object( win
->last_active
, USER_WINDOW
)) reply
->last_active
= win
->last_active
;
2223 reply
->tid
= get_thread_id( win
->thread
);
2224 reply
->pid
= get_process_id( win
->thread
->process
);
2225 reply
->atom
= win
->class ? get_class_atom( win
->class ) : DESKTOP_ATOM
;
2230 /* set some information in a window */
2231 DECL_HANDLER(set_window_info
)
2233 struct window
*win
= get_window( req
->handle
);
2236 if (req
->flags
&& is_desktop_window(win
) && win
->thread
!= current
)
2238 set_error( STATUS_ACCESS_DENIED
);
2241 if (req
->extra_size
> sizeof(req
->extra_value
) ||
2242 req
->extra_offset
< -1 ||
2243 req
->extra_offset
> win
->nb_extra_bytes
- (int)req
->extra_size
)
2245 set_win32_error( ERROR_INVALID_INDEX
);
2248 if (req
->extra_offset
!= -1)
2250 memcpy( &reply
->old_extra_value
, win
->extra_bytes
+ req
->extra_offset
, req
->extra_size
);
2252 else if (req
->flags
& SET_WIN_EXTRA
)
2254 set_win32_error( ERROR_INVALID_INDEX
);
2257 reply
->old_style
= win
->style
;
2258 reply
->old_ex_style
= win
->ex_style
;
2259 reply
->old_id
= win
->id
;
2260 reply
->old_instance
= win
->instance
;
2261 reply
->old_user_data
= win
->user_data
;
2262 if (req
->flags
& SET_WIN_STYLE
) win
->style
= req
->style
;
2263 if (req
->flags
& SET_WIN_EXSTYLE
)
2265 /* WS_EX_TOPMOST can only be changed for unlinked windows */
2266 if (!win
->is_linked
) win
->ex_style
= req
->ex_style
;
2267 else win
->ex_style
= (req
->ex_style
& ~WS_EX_TOPMOST
) | (win
->ex_style
& WS_EX_TOPMOST
);
2268 if (!(win
->ex_style
& WS_EX_LAYERED
)) win
->is_layered
= 0;
2270 if (req
->flags
& SET_WIN_ID
) win
->id
= req
->extra_value
;
2271 if (req
->flags
& SET_WIN_INSTANCE
) win
->instance
= req
->instance
;
2272 if (req
->flags
& SET_WIN_UNICODE
) win
->is_unicode
= req
->is_unicode
;
2273 if (req
->flags
& SET_WIN_USERDATA
) win
->user_data
= req
->user_data
;
2274 if (req
->flags
& SET_WIN_EXTRA
) memcpy( win
->extra_bytes
+ req
->extra_offset
,
2275 &req
->extra_value
, req
->extra_size
);
2277 /* changing window style triggers a non-client paint */
2278 if (req
->flags
& SET_WIN_STYLE
) win
->paint_flags
|= PAINT_NONCLIENT
;
2282 /* get a list of the window parents, up to the root of the tree */
2283 DECL_HANDLER(get_window_parents
)
2285 struct window
*ptr
, *win
= get_window( req
->handle
);
2287 user_handle_t
*data
;
2290 if (win
) for (ptr
= win
->parent
; ptr
; ptr
= ptr
->parent
) total
++;
2292 reply
->count
= total
;
2293 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
2294 if (len
&& ((data
= set_reply_data_size( len
))))
2296 for (ptr
= win
->parent
; ptr
&& len
; ptr
= ptr
->parent
, len
-= sizeof(*data
))
2297 *data
++ = ptr
->handle
;
2302 /* get a list of the window children */
2303 DECL_HANDLER(get_window_children
)
2305 struct window
*parent
= NULL
;
2307 user_handle_t
*data
;
2309 struct unicode_str cls_name
= get_req_unicode_str();
2310 atom_t atom
= req
->atom
;
2311 struct desktop
*desktop
= NULL
;
2313 if (cls_name
.len
&& !(atom
= find_global_atom( NULL
, &cls_name
))) return;
2317 if (!(desktop
= get_desktop_obj( current
->process
, req
->desktop
, DESKTOP_ENUMERATE
))) return;
2318 parent
= desktop
->top_window
;
2322 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
2323 if (!parent
&& !(desktop
= get_thread_desktop( current
, 0 ))) return;
2327 total
= get_children_windows( parent
, atom
, req
->tid
, NULL
, 0 );
2329 total
= get_children_windows( desktop
->top_window
, atom
, req
->tid
, NULL
, 0 ) +
2330 get_children_windows( desktop
->msg_window
, atom
, req
->tid
, NULL
, 0 );
2332 reply
->count
= total
;
2333 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
2334 if (len
&& ((data
= set_reply_data_size( len
))))
2336 if (parent
) get_children_windows( parent
, atom
, req
->tid
, data
, len
/ sizeof(user_handle_t
) );
2339 total
= get_children_windows( desktop
->top_window
, atom
, req
->tid
,
2340 data
, len
/ sizeof(user_handle_t
) );
2342 len
-= total
* sizeof(user_handle_t
);
2343 if (len
>= sizeof(user_handle_t
))
2344 get_children_windows( desktop
->msg_window
, atom
, req
->tid
,
2345 data
, len
/ sizeof(user_handle_t
) );
2348 if (desktop
) release_object( desktop
);
2352 /* get a list of the window children that contain a given point */
2353 DECL_HANDLER(get_window_children_from_point
)
2355 struct user_handle_array array
;
2356 struct window
*parent
= get_window( req
->parent
);
2359 if (!parent
) return;
2361 array
.handles
= NULL
;
2364 if (!all_windows_from_point( parent
, req
->x
, req
->y
, req
->dpi
, &array
)) return;
2366 reply
->count
= array
.count
;
2367 len
= min( get_reply_max_size(), array
.count
* sizeof(user_handle_t
) );
2368 if (len
) set_reply_data_ptr( array
.handles
, len
);
2369 else free( array
.handles
);
2373 /* get window tree information from a window handle */
2374 DECL_HANDLER(get_window_tree
)
2376 struct window
*ptr
, *win
= get_window( req
->handle
);
2382 reply
->next_sibling
= 0;
2383 reply
->prev_sibling
= 0;
2384 reply
->first_sibling
= 0;
2385 reply
->last_sibling
= 0;
2386 reply
->first_child
= 0;
2387 reply
->last_child
= 0;
2391 struct window
*parent
= win
->parent
;
2392 reply
->parent
= parent
->handle
;
2393 reply
->owner
= win
->owner
;
2396 if ((ptr
= get_next_window( win
))) reply
->next_sibling
= ptr
->handle
;
2397 if ((ptr
= get_prev_window( win
))) reply
->prev_sibling
= ptr
->handle
;
2399 if ((ptr
= get_first_child( parent
))) reply
->first_sibling
= ptr
->handle
;
2400 if ((ptr
= get_last_child( parent
))) reply
->last_sibling
= ptr
->handle
;
2402 if ((ptr
= get_first_child( win
))) reply
->first_child
= ptr
->handle
;
2403 if ((ptr
= get_last_child( win
))) reply
->last_child
= ptr
->handle
;
2407 /* set the position and Z order of a window */
2408 DECL_HANDLER(set_window_pos
)
2410 rectangle_t window_rect
, client_rect
, visible_rect
, surface_rect
, valid_rect
;
2411 const rectangle_t
*extra_rects
= get_req_data();
2412 struct window
*previous
= NULL
;
2413 struct window
*top
, *win
= get_window( req
->handle
);
2414 unsigned int flags
= req
->swp_flags
;
2417 if (!win
->parent
) flags
|= SWP_NOZORDER
; /* no Z order for the desktop */
2419 if (!(flags
& SWP_NOZORDER
))
2421 switch ((int)req
->previous
)
2423 case 0: /* HWND_TOP */
2424 previous
= WINPTR_TOP
;
2426 case 1: /* HWND_BOTTOM */
2427 previous
= WINPTR_BOTTOM
;
2429 case -1: /* HWND_TOPMOST */
2430 previous
= WINPTR_TOPMOST
;
2432 case -2: /* HWND_NOTOPMOST */
2433 previous
= WINPTR_NOTOPMOST
;
2436 if (!(previous
= get_window( req
->previous
))) return;
2437 /* previous must be a sibling */
2438 if (previous
->parent
!= win
->parent
)
2440 set_error( STATUS_INVALID_PARAMETER
);
2445 if (previous
== win
) flags
|= SWP_NOZORDER
; /* nothing to do */
2448 /* windows that use UpdateLayeredWindow don't trigger repaints */
2449 if ((win
->ex_style
& WS_EX_LAYERED
) && !win
->is_layered
) flags
|= SWP_NOREDRAW
;
2451 /* window rectangle must be ordered properly */
2452 if (req
->window
.right
< req
->window
.left
|| req
->window
.bottom
< req
->window
.top
)
2454 set_error( STATUS_INVALID_PARAMETER
);
2458 window_rect
= req
->window
;
2459 client_rect
= req
->client
;
2460 if (get_req_data_size() >= sizeof(rectangle_t
)) visible_rect
= extra_rects
[0];
2461 else visible_rect
= window_rect
;
2462 if (get_req_data_size() >= 2 * sizeof(rectangle_t
)) surface_rect
= extra_rects
[1];
2463 else surface_rect
= visible_rect
;
2464 if (get_req_data_size() >= 3 * sizeof(rectangle_t
)) valid_rect
= extra_rects
[2];
2465 else valid_rect
= empty_rect
;
2466 if (win
->parent
&& win
->parent
->ex_style
& WS_EX_LAYOUTRTL
)
2468 mirror_rect( &win
->parent
->client_rect
, &window_rect
);
2469 mirror_rect( &win
->parent
->client_rect
, &visible_rect
);
2470 mirror_rect( &win
->parent
->client_rect
, &client_rect
);
2471 mirror_rect( &win
->parent
->client_rect
, &surface_rect
);
2472 mirror_rect( &win
->parent
->client_rect
, &valid_rect
);
2475 win
->paint_flags
= (win
->paint_flags
& ~PAINT_CLIENT_FLAGS
) | (req
->paint_flags
& PAINT_CLIENT_FLAGS
);
2476 if (win
->paint_flags
& PAINT_HAS_PIXEL_FORMAT
) update_pixel_format_flags( win
);
2478 set_window_pos( win
, previous
, flags
, &window_rect
, &client_rect
,
2479 &visible_rect
, &surface_rect
, &valid_rect
);
2481 reply
->new_style
= win
->style
;
2482 reply
->new_ex_style
= win
->ex_style
;
2484 top
= get_top_clipping_window( win
);
2485 if (is_visible( top
) && (top
->paint_flags
& PAINT_HAS_SURFACE
))
2487 reply
->surface_win
= top
->handle
;
2488 reply
->needs_update
= !!(top
->paint_flags
& (PAINT_HAS_PIXEL_FORMAT
| PAINT_PIXEL_FORMAT_CHILD
)) ||
2494 /* get the window and client rectangles of a window */
2495 DECL_HANDLER(get_window_rectangles
)
2497 struct window
*win
= get_window( req
->handle
);
2501 reply
->window
= win
->window_rect
;
2502 reply
->client
= win
->client_rect
;
2504 switch (req
->relative
)
2507 offset_rect( &reply
->window
, -win
->client_rect
.left
, -win
->client_rect
.top
);
2508 offset_rect( &reply
->client
, -win
->client_rect
.left
, -win
->client_rect
.top
);
2509 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_rect( &win
->client_rect
, &reply
->window
);
2512 offset_rect( &reply
->window
, -win
->window_rect
.left
, -win
->window_rect
.top
);
2513 offset_rect( &reply
->client
, -win
->window_rect
.left
, -win
->window_rect
.top
);
2514 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_rect( &win
->window_rect
, &reply
->client
);
2517 if (win
->parent
&& win
->parent
->ex_style
& WS_EX_LAYOUTRTL
)
2519 mirror_rect( &win
->parent
->client_rect
, &reply
->window
);
2520 mirror_rect( &win
->parent
->client_rect
, &reply
->client
);
2524 client_to_screen_rect( win
->parent
, &reply
->window
);
2525 client_to_screen_rect( win
->parent
, &reply
->client
);
2528 set_error( STATUS_INVALID_PARAMETER
);
2531 map_dpi_rect( win
, &reply
->window
, get_window_dpi( win
), req
->dpi
);
2532 map_dpi_rect( win
, &reply
->client
, get_window_dpi( win
), req
->dpi
);
2536 /* get the window text */
2537 DECL_HANDLER(get_window_text
)
2539 struct window
*win
= get_window( req
->handle
);
2541 if (win
&& win
->text_len
)
2543 reply
->length
= win
->text_len
/ sizeof(WCHAR
);
2544 set_reply_data( win
->text
, min( win
->text_len
, get_reply_max_size() ));
2549 /* set the window text */
2550 DECL_HANDLER(set_window_text
)
2554 struct window
*win
= get_window( req
->handle
);
2557 len
= (get_req_data_size() / sizeof(WCHAR
)) * sizeof(WCHAR
);
2558 if (len
&& !(text
= memdup( get_req_data(), len
))) return;
2561 win
->text_len
= len
;
2565 /* get the coordinates offset between two windows */
2566 DECL_HANDLER(get_windows_offset
)
2569 int x
, y
, mirror_from
= 0, mirror_to
= 0;
2571 reply
->x
= reply
->y
= 0;
2574 if (!(win
= get_window( req
->from
))) return;
2575 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_from
= 1;
2576 x
= mirror_from
? win
->client_rect
.right
- win
->client_rect
.left
: 0;
2578 client_to_screen( win
, &x
, &y
);
2579 map_dpi_point( win
, &x
, &y
, get_window_dpi( win
), req
->dpi
);
2585 if (!(win
= get_window( req
->to
))) return;
2586 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_to
= 1;
2587 x
= mirror_to
? win
->client_rect
.right
- win
->client_rect
.left
: 0;
2589 client_to_screen( win
, &x
, &y
);
2590 map_dpi_point( win
, &x
, &y
, get_window_dpi( win
), req
->dpi
);
2594 if (mirror_from
) reply
->x
= -reply
->x
;
2595 reply
->mirror
= mirror_from
^ mirror_to
;
2599 /* get the visible region of a window */
2600 DECL_HANDLER(get_visible_region
)
2602 struct region
*region
;
2603 struct window
*top
, *win
= get_window( req
->window
);
2607 top
= get_top_clipping_window( win
);
2608 if ((region
= get_visible_region( win
, req
->flags
)))
2611 map_win_region_to_screen( win
, region
);
2612 data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
2613 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
2615 reply
->top_win
= top
->handle
;
2616 reply
->top_rect
= top
->surface_rect
;
2618 if (!is_desktop_window(win
))
2620 reply
->win_rect
= (req
->flags
& DCX_WINDOW
) ? win
->window_rect
: win
->client_rect
;
2621 client_to_screen_rect( top
->parent
, &reply
->top_rect
);
2622 client_to_screen_rect( win
->parent
, &reply
->win_rect
);
2626 reply
->win_rect
.left
= 0;
2627 reply
->win_rect
.top
= 0;
2628 reply
->win_rect
.right
= win
->client_rect
.right
- win
->client_rect
.left
;
2629 reply
->win_rect
.bottom
= win
->client_rect
.bottom
- win
->client_rect
.top
;
2631 reply
->paint_flags
= win
->paint_flags
& PAINT_CLIENT_FLAGS
;
2635 /* get the window regions */
2636 DECL_HANDLER(get_window_region
)
2639 struct region
*region
;
2640 struct window
*win
= get_window( req
->window
);
2644 reply
->visible_rect
= win
->visible_rect
;
2647 if (!is_visible( win
)) return;
2649 if ((region
= get_surface_region( win
)))
2651 rectangle_t
*data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
2652 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
2657 if (!win
->win_region
) return;
2659 if (win
->ex_style
& WS_EX_LAYOUTRTL
)
2661 struct region
*region
= create_empty_region();
2663 if (!region
) return;
2664 if (!copy_region( region
, win
->win_region
))
2666 free_region( region
);
2669 mirror_region( &win
->window_rect
, region
);
2670 data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
2672 else data
= get_region_data( win
->win_region
, get_reply_max_size(), &reply
->total_size
);
2674 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
2678 /* set the window region */
2679 DECL_HANDLER(set_window_region
)
2681 struct region
*region
= NULL
;
2682 struct window
*win
= get_window( req
->window
);
2686 if (get_req_data_size()) /* no data means remove the region completely */
2688 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
2690 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_region( &win
->window_rect
, region
);
2692 set_window_region( win
, region
, req
->redraw
);
2696 /* get a window update region */
2697 DECL_HANDLER(get_update_region
)
2700 unsigned int flags
= req
->flags
;
2701 struct window
*from_child
= NULL
;
2702 struct window
*win
= get_window( req
->window
);
2707 if (req
->from_child
)
2711 if (!(from_child
= get_window( req
->from_child
))) return;
2713 /* make sure from_child is a child of win */
2715 while (ptr
&& ptr
!= win
) ptr
= ptr
->parent
;
2718 set_error( STATUS_INVALID_PARAMETER
);
2723 if (flags
& UPDATE_DELAYED_ERASE
) /* this means that the previous call didn't erase */
2725 if (from_child
) from_child
->paint_flags
|= PAINT_DELAYED_ERASE
;
2726 else win
->paint_flags
|= PAINT_DELAYED_ERASE
;
2729 reply
->flags
= get_window_update_flags( win
, from_child
, flags
, &win
);
2730 reply
->child
= win
->handle
;
2732 if (flags
& UPDATE_NOREGION
) return;
2734 if (win
->update_region
)
2736 /* convert update region to screen coordinates */
2737 struct region
*region
= create_empty_region();
2739 if (!region
) return;
2740 if (!copy_region( region
, win
->update_region
))
2742 free_region( region
);
2745 if ((flags
& UPDATE_CLIPCHILDREN
) && (win
->style
& WS_CLIPCHILDREN
))
2746 clip_children( win
, NULL
, region
, win
->client_rect
.left
- win
->window_rect
.left
,
2747 win
->client_rect
.top
- win
->window_rect
.top
);
2748 map_win_region_to_screen( win
, region
);
2749 if (!(data
= get_region_data_and_free( region
, get_reply_max_size(),
2750 &reply
->total_size
))) return;
2751 set_reply_data_ptr( data
, reply
->total_size
);
2754 if (reply
->flags
& (UPDATE_PAINT
|UPDATE_INTERNALPAINT
)) /* validate everything */
2756 validate_parents( win
);
2757 validate_whole_window( win
);
2761 if (reply
->flags
& UPDATE_NONCLIENT
) validate_non_client( win
);
2762 if (reply
->flags
& UPDATE_ERASE
)
2764 win
->paint_flags
&= ~(PAINT_ERASE
| PAINT_DELAYED_ERASE
);
2765 /* desktop window only gets erased, not repainted */
2766 if (is_desktop_window(win
)) validate_whole_window( win
);
2772 /* update the z order of a window so that a given rectangle is fully visible */
2773 DECL_HANDLER(update_window_zorder
)
2775 rectangle_t tmp
, rect
= req
->rect
;
2776 struct window
*ptr
, *win
= get_window( req
->window
);
2778 if (!win
|| !win
->parent
|| !is_visible( win
)) return; /* nothing to do */
2780 LIST_FOR_EACH_ENTRY( ptr
, &win
->parent
->children
, struct window
, entry
)
2782 if (ptr
== win
) break;
2783 if (!(ptr
->style
& WS_VISIBLE
)) continue;
2784 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
2785 if (ptr
->is_layered
&& (ptr
->layered_flags
& LWA_COLORKEY
)) continue;
2787 map_dpi_rect( win
, &tmp
, get_window_dpi( win
->parent
), get_window_dpi( win
) );
2788 if (!intersect_rect( &tmp
, &tmp
, &ptr
->visible_rect
)) continue;
2789 if (ptr
->win_region
)
2791 offset_rect( &tmp
, -ptr
->window_rect
.left
, -ptr
->window_rect
.top
);
2792 if (!rect_in_region( ptr
->win_region
, &tmp
)) continue;
2794 /* found a window obscuring the rectangle, now move win above this one */
2795 /* making sure to not violate the topmost rule */
2796 if (!(ptr
->ex_style
& WS_EX_TOPMOST
) || (win
->ex_style
& WS_EX_TOPMOST
))
2798 list_remove( &win
->entry
);
2799 list_add_before( &ptr
->entry
, &win
->entry
);
2806 /* mark parts of a window as needing a redraw */
2807 DECL_HANDLER(redraw_window
)
2809 unsigned int flags
= req
->flags
;
2810 struct region
*region
= NULL
;
2815 if (!(win
= get_desktop_window( current
))) return;
2819 if (!(win
= get_window( req
->window
))) return;
2820 if (is_desktop_window( win
)) flags
&= ~RDW_ALLCHILDREN
;
2823 if (!is_visible( win
)) return; /* nothing to do */
2825 if (flags
& (RDW_VALIDATE
|RDW_INVALIDATE
))
2827 if (get_req_data_size()) /* no data means whole rectangle */
2829 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
2831 if (win
->ex_style
& WS_EX_LAYOUTRTL
) mirror_region( &win
->client_rect
, region
);
2835 redraw_window( win
, region
, (flags
& RDW_INVALIDATE
) && (flags
& RDW_FRAME
), flags
);
2836 if (region
) free_region( region
);
2840 /* set a window property */
2841 DECL_HANDLER(set_window_property
)
2843 struct unicode_str name
= get_req_unicode_str();
2844 struct window
*win
= get_window( req
->window
);
2850 atom_t atom
= add_global_atom( NULL
, &name
);
2853 set_property( win
, atom
, req
->data
, PROP_TYPE_STRING
);
2854 release_global_atom( NULL
, atom
);
2857 else set_property( win
, req
->atom
, req
->data
, PROP_TYPE_ATOM
);
2861 /* remove a window property */
2862 DECL_HANDLER(remove_window_property
)
2864 struct unicode_str name
= get_req_unicode_str();
2865 struct window
*win
= get_window( req
->window
);
2869 atom_t atom
= name
.len
? find_global_atom( NULL
, &name
) : req
->atom
;
2870 if (atom
) reply
->data
= remove_property( win
, atom
);
2875 /* get a window property */
2876 DECL_HANDLER(get_window_property
)
2878 struct unicode_str name
= get_req_unicode_str();
2879 struct window
*win
= get_window( req
->window
);
2883 atom_t atom
= name
.len
? find_global_atom( NULL
, &name
) : req
->atom
;
2884 if (atom
) reply
->data
= get_property( win
, atom
);
2889 /* get the list of properties of a window */
2890 DECL_HANDLER(get_window_properties
)
2892 property_data_t
*data
;
2893 int i
, count
, max
= get_reply_max_size() / sizeof(*data
);
2894 struct window
*win
= get_window( req
->window
);
2899 for (i
= count
= 0; i
< win
->prop_inuse
; i
++)
2900 if (win
->properties
[i
].type
!= PROP_TYPE_FREE
) count
++;
2901 reply
->total
= count
;
2903 if (count
> max
) count
= max
;
2904 if (!count
|| !(data
= set_reply_data_size( count
* sizeof(*data
) ))) return;
2906 for (i
= 0; i
< win
->prop_inuse
&& count
; i
++)
2908 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
2909 data
->atom
= win
->properties
[i
].atom
;
2910 data
->string
= (win
->properties
[i
].type
== PROP_TYPE_STRING
);
2911 data
->data
= win
->properties
[i
].data
;
2918 /* get the new window pointer for a global window, checking permissions */
2919 /* helper for set_global_windows request */
2920 static int get_new_global_window( struct window
**win
, user_handle_t handle
)
2929 set_error( STATUS_ACCESS_DENIED
);
2932 *win
= get_window( handle
);
2933 return (*win
!= NULL
);
2936 /* Set/get the global windows */
2937 DECL_HANDLER(set_global_windows
)
2939 struct window
*new_shell_window
= shell_window
;
2940 struct window
*new_shell_listview
= shell_listview
;
2941 struct window
*new_progman_window
= progman_window
;
2942 struct window
*new_taskman_window
= taskman_window
;
2944 reply
->old_shell_window
= shell_window
? shell_window
->handle
: 0;
2945 reply
->old_shell_listview
= shell_listview
? shell_listview
->handle
: 0;
2946 reply
->old_progman_window
= progman_window
? progman_window
->handle
: 0;
2947 reply
->old_taskman_window
= taskman_window
? taskman_window
->handle
: 0;
2949 if (req
->flags
& SET_GLOBAL_SHELL_WINDOWS
)
2951 if (!get_new_global_window( &new_shell_window
, req
->shell_window
)) return;
2952 if (!get_new_global_window( &new_shell_listview
, req
->shell_listview
)) return;
2954 if (req
->flags
& SET_GLOBAL_PROGMAN_WINDOW
)
2956 if (!get_new_global_window( &new_progman_window
, req
->progman_window
)) return;
2958 if (req
->flags
& SET_GLOBAL_TASKMAN_WINDOW
)
2960 if (!get_new_global_window( &new_taskman_window
, req
->taskman_window
)) return;
2962 shell_window
= new_shell_window
;
2963 shell_listview
= new_shell_listview
;
2964 progman_window
= new_progman_window
;
2965 taskman_window
= new_taskman_window
;
2968 /* retrieve layered info for a window */
2969 DECL_HANDLER(get_window_layered_info
)
2971 struct window
*win
= get_window( req
->handle
);
2975 if (win
->is_layered
)
2977 reply
->color_key
= win
->color_key
;
2978 reply
->alpha
= win
->alpha
;
2979 reply
->flags
= win
->layered_flags
;
2981 else set_win32_error( ERROR_INVALID_WINDOW_HANDLE
);
2985 /* set layered info for a window */
2986 DECL_HANDLER(set_window_layered_info
)
2988 struct window
*win
= get_window( req
->handle
);
2992 if (win
->ex_style
& WS_EX_LAYERED
)
2994 int was_layered
= win
->is_layered
;
2996 if (req
->flags
& LWA_ALPHA
) win
->alpha
= req
->alpha
;
2997 else if (!win
->is_layered
) win
->alpha
= 0; /* alpha init value is 0 */
2999 win
->color_key
= req
->color_key
;
3000 win
->layered_flags
= req
->flags
;
3001 win
->is_layered
= 1;
3002 /* repaint since we know now it's not going to use UpdateLayeredWindow */
3003 if (!was_layered
) redraw_window( win
, 0, 1, RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
);
3005 else set_win32_error( ERROR_INVALID_WINDOW_HANDLE
);