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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
39 /* a window property */
42 unsigned short type
; /* property type (see below) */
43 atom_t atom
; /* property atom */
44 obj_handle_t handle
; /* property handle (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 window
*parent
; /* parent window */
58 user_handle_t owner
; /* owner of this window */
59 struct list children
; /* list of children in Z-order */
60 struct list unlinked
; /* list of children not linked in the Z-order list */
61 struct list entry
; /* entry in parent's children list */
62 user_handle_t handle
; /* full handle for this window */
63 struct thread
*thread
; /* thread owning the window */
64 struct window_class
*class; /* window class */
65 atom_t atom
; /* class atom */
66 user_handle_t last_active
; /* last active popup */
67 rectangle_t window_rect
; /* window rectangle (relative to parent client area) */
68 rectangle_t visible_rect
; /* visible part of window rect (relative to parent client area) */
69 rectangle_t client_rect
; /* client rectangle (relative to parent client area) */
70 struct region
*win_region
; /* region for shaped windows (relative to window rect) */
71 struct region
*update_region
; /* update region (relative to window rect) */
72 unsigned int style
; /* window style */
73 unsigned int ex_style
; /* window extended style */
74 unsigned int id
; /* window id */
75 void* instance
; /* creator instance */
76 void* user_data
; /* user-specific data */
77 WCHAR
*text
; /* window caption text */
78 unsigned int paint_flags
; /* various painting flags */
79 int prop_inuse
; /* number of in-use window properties */
80 int prop_alloc
; /* number of allocated window properties */
81 struct property
*properties
; /* window properties array */
82 int nb_extra_bytes
; /* number of extra bytes */
83 char extra_bytes
[1]; /* extra bytes storage */
86 #define PAINT_INTERNAL 0x01 /* internal WM_PAINT pending */
87 #define PAINT_ERASE 0x02 /* needs WM_ERASEBKGND */
88 #define PAINT_NONCLIENT 0x04 /* needs WM_NCPAINT */
90 /* growable array of user handles */
91 struct user_handle_array
93 user_handle_t
*handles
;
98 static struct window
*top_window
; /* top-level (desktop) window */
100 /* global window pointers */
101 static struct window
*shell_window
;
102 static struct window
*shell_listview
;
103 static struct window
*progman_window
;
104 static struct window
*taskman_window
;
106 /* retrieve a pointer to a window from its handle */
107 inline static struct window
*get_window( user_handle_t handle
)
109 struct window
*ret
= get_user_object( handle
, USER_WINDOW
);
110 if (!ret
) set_error( STATUS_INVALID_HANDLE
);
114 /* change the parent of a window (or unlink the window if the new parent is NULL) */
115 static int set_parent_window( struct window
*win
, struct window
*parent
)
119 /* make sure parent is not a child of window */
120 for (ptr
= parent
; ptr
; ptr
= ptr
->parent
)
124 set_error( STATUS_INVALID_PARAMETER
);
129 list_remove( &win
->entry
); /* unlink it from the previous location */
133 win
->parent
= parent
;
134 list_add_head( &parent
->children
, &win
->entry
);
136 /* if parent belongs to a different thread, attach the two threads */
137 if (parent
->thread
&& parent
->thread
!= win
->thread
)
138 attach_thread_input( win
->thread
, parent
->thread
);
140 else /* move it to parent unlinked list */
142 list_add_head( &win
->parent
->unlinked
, &win
->entry
);
147 /* get next window in Z-order list */
148 static inline struct window
*get_next_window( struct window
*win
)
150 struct list
*ptr
= list_next( &win
->parent
->children
, &win
->entry
);
151 if (ptr
== &win
->parent
->unlinked
) ptr
= NULL
;
152 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
155 /* get previous window in Z-order list */
156 static inline struct window
*get_prev_window( struct window
*win
)
158 struct list
*ptr
= list_prev( &win
->parent
->children
, &win
->entry
);
159 if (ptr
== &win
->parent
->unlinked
) ptr
= NULL
;
160 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
163 /* get first child in Z-order list */
164 static inline struct window
*get_first_child( struct window
*win
)
166 struct list
*ptr
= list_head( &win
->children
);
167 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
170 /* get last child in Z-order list */
171 static inline struct window
*get_last_child( struct window
*win
)
173 struct list
*ptr
= list_tail( &win
->children
);
174 return ptr
? LIST_ENTRY( ptr
, struct window
, entry
) : NULL
;
177 /* append a user handle to a handle array */
178 static int add_handle_to_array( struct user_handle_array
*array
, user_handle_t handle
)
180 if (array
->count
>= array
->total
)
182 int new_total
= max( array
->total
* 2, 32 );
183 user_handle_t
*new_array
= realloc( array
->handles
, new_total
* sizeof(*new_array
) );
186 free( array
->handles
);
187 set_error( STATUS_NO_MEMORY
);
190 array
->handles
= new_array
;
191 array
->total
= new_total
;
193 array
->handles
[array
->count
++] = handle
;
197 /* set a window property */
198 static void set_property( struct window
*win
, atom_t atom
, obj_handle_t handle
,
199 enum property_type type
)
202 struct property
*new_props
;
204 /* check if it exists already */
205 for (i
= 0; i
< win
->prop_inuse
; i
++)
207 if (win
->properties
[i
].type
== PROP_TYPE_FREE
)
212 if (win
->properties
[i
].atom
== atom
)
214 win
->properties
[i
].type
= type
;
215 win
->properties
[i
].handle
= handle
;
220 /* need to add an entry */
221 if (!grab_global_atom( atom
)) return;
225 if (win
->prop_inuse
>= win
->prop_alloc
)
227 /* need to grow the array */
228 if (!(new_props
= realloc( win
->properties
,
229 sizeof(*new_props
) * (win
->prop_alloc
+ 16) )))
231 set_error( STATUS_NO_MEMORY
);
232 release_global_atom( atom
);
235 win
->prop_alloc
+= 16;
236 win
->properties
= new_props
;
238 free
= win
->prop_inuse
++;
240 win
->properties
[free
].atom
= atom
;
241 win
->properties
[free
].type
= type
;
242 win
->properties
[free
].handle
= handle
;
245 /* remove a window property */
246 static obj_handle_t
remove_property( struct window
*win
, atom_t atom
)
250 for (i
= 0; i
< win
->prop_inuse
; i
++)
252 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
253 if (win
->properties
[i
].atom
== atom
)
255 release_global_atom( atom
);
256 win
->properties
[i
].type
= PROP_TYPE_FREE
;
257 return win
->properties
[i
].handle
;
260 /* FIXME: last error? */
264 /* find a window property */
265 static obj_handle_t
get_property( struct window
*win
, atom_t atom
)
269 for (i
= 0; i
< win
->prop_inuse
; i
++)
271 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
272 if (win
->properties
[i
].atom
== atom
) return win
->properties
[i
].handle
;
274 /* FIXME: last error? */
278 /* destroy all properties of a window */
279 inline static void destroy_properties( struct window
*win
)
283 if (!win
->properties
) return;
284 for (i
= 0; i
< win
->prop_inuse
; i
++)
286 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
287 release_global_atom( win
->properties
[i
].atom
);
289 free( win
->properties
);
292 /* destroy a window */
293 static void destroy_window( struct window
*win
)
295 assert( win
!= top_window
);
297 /* destroy all children */
298 while (!list_empty(&win
->children
))
299 destroy_window( LIST_ENTRY( list_head(&win
->children
), struct window
, entry
));
300 while (!list_empty(&win
->unlinked
))
301 destroy_window( LIST_ENTRY( list_head(&win
->unlinked
), struct window
, entry
));
303 if (win
->thread
->queue
)
305 if (win
->update_region
) inc_queue_paint_count( win
->thread
, -1 );
306 if (win
->paint_flags
& PAINT_INTERNAL
) inc_queue_paint_count( win
->thread
, -1 );
307 queue_cleanup_window( win
->thread
, win
->handle
);
309 /* reset global window pointers, if the corresponding window is destroyed */
310 if (win
== shell_window
) shell_window
= NULL
;
311 if (win
== shell_listview
) shell_listview
= NULL
;
312 if (win
== progman_window
) progman_window
= NULL
;
313 if (win
== taskman_window
) taskman_window
= NULL
;
314 free_user_handle( win
->handle
);
315 destroy_properties( win
);
316 list_remove( &win
->entry
);
317 if (win
->win_region
) free_region( win
->win_region
);
318 if (win
->update_region
) free_region( win
->update_region
);
319 release_class( win
->class );
320 if (win
->text
) free( win
->text
);
321 memset( win
, 0x55, sizeof(*win
) + win
->nb_extra_bytes
- 1 );
325 /* create a new window structure (note: the window is not linked in the window tree) */
326 static struct window
*create_window( struct window
*parent
, struct window
*owner
,
327 atom_t atom
, void *instance
)
331 struct window_class
*class = grab_class( current
->process
, atom
, instance
, &extra_bytes
);
333 if (!class) return NULL
;
335 win
= mem_alloc( sizeof(*win
) + extra_bytes
- 1 );
338 release_class( class );
342 if (!(win
->handle
= alloc_user_handle( win
, USER_WINDOW
)))
344 release_class( class );
348 win
->parent
= parent
;
349 win
->owner
= owner
? owner
->handle
: 0;
350 win
->thread
= current
;
353 win
->last_active
= win
->handle
;
354 win
->win_region
= NULL
;
355 win
->update_region
= NULL
;
359 win
->instance
= NULL
;
360 win
->user_data
= NULL
;
362 win
->paint_flags
= 0;
365 win
->properties
= NULL
;
366 win
->nb_extra_bytes
= extra_bytes
;
367 memset( win
->extra_bytes
, 0, extra_bytes
);
368 list_init( &win
->children
);
369 list_init( &win
->unlinked
);
371 /* put it on parent unlinked list */
372 if (parent
) list_add_head( &parent
->unlinked
, &win
->entry
);
374 /* if parent belongs to a different thread, attach the two threads */
375 if (parent
&& parent
->thread
&& parent
->thread
!= current
)
376 attach_thread_input( current
, parent
->thread
);
380 /* destroy all windows belonging to a given thread */
381 void destroy_thread_windows( struct thread
*thread
)
383 user_handle_t handle
= 0;
386 while ((win
= next_user_handle( &handle
, USER_WINDOW
)))
388 if (win
->thread
!= thread
) continue;
389 destroy_window( win
);
393 /* check whether child is a descendant of parent */
394 int is_child_window( user_handle_t parent
, user_handle_t child
)
396 struct window
*child_ptr
= get_user_object( child
, USER_WINDOW
);
397 struct window
*parent_ptr
= get_user_object( parent
, USER_WINDOW
);
399 if (!child_ptr
|| !parent_ptr
) return 0;
400 while (child_ptr
->parent
)
402 if (child_ptr
->parent
== parent_ptr
) return 1;
403 child_ptr
= child_ptr
->parent
;
408 /* check whether window is a top-level window */
409 int is_top_level_window( user_handle_t window
)
411 struct window
*win
= get_user_object( window
, USER_WINDOW
);
412 return (win
&& win
->parent
== top_window
);
415 /* make a window active if possible */
416 int make_window_active( user_handle_t window
)
418 struct window
*owner
, *win
= get_window( window
);
422 /* set last active for window and its owner */
423 win
->last_active
= win
->handle
;
424 if ((owner
= get_user_object( win
->owner
, USER_WINDOW
))) owner
->last_active
= win
->handle
;
428 /* increment (or decrement) the window paint count */
429 static inline void inc_window_paint_count( struct window
*win
, int incr
)
431 if (win
->thread
) inc_queue_paint_count( win
->thread
, incr
);
434 /* check if window and all its ancestors are visible */
435 static int is_visible( const struct window
*win
)
437 while (win
&& win
!= top_window
)
439 if (!(win
->style
& WS_VISIBLE
)) return 0;
441 /* if parent is minimized children are not visible */
442 if (win
&& (win
->style
& WS_MINIMIZE
)) return 0;
447 /* same as is_visible but takes a window handle */
448 int is_window_visible( user_handle_t window
)
450 struct window
*win
= get_user_object( window
, USER_WINDOW
);
452 return is_visible( win
);
455 /* check if point is inside the window */
456 static inline int is_point_in_window( struct window
*win
, int x
, int y
)
458 if (!(win
->style
& WS_VISIBLE
)) return 0; /* not visible */
459 if ((win
->style
& (WS_POPUP
|WS_CHILD
|WS_DISABLED
)) == (WS_CHILD
|WS_DISABLED
))
460 return 0; /* disabled child */
461 if ((win
->ex_style
& (WS_EX_LAYERED
|WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
|WS_EX_TRANSPARENT
))
462 return 0; /* transparent */
463 if (x
< win
->visible_rect
.left
|| x
>= win
->visible_rect
.right
||
464 y
< win
->visible_rect
.top
|| y
>= win
->visible_rect
.bottom
)
465 return 0; /* not in window */
466 if (win
->win_region
&&
467 !point_in_region( win
->win_region
, x
- win
->window_rect
.left
, y
- win
->window_rect
.top
))
468 return 0; /* not in window region */
472 /* find child of 'parent' that contains the given point (in parent-relative coords) */
473 static struct window
*child_window_from_point( struct window
*parent
, int x
, int y
)
477 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
479 if (!is_point_in_window( ptr
, x
, y
)) continue; /* skip it */
481 /* if window is minimized or disabled, return at once */
482 if (ptr
->style
& (WS_MINIMIZE
|WS_DISABLED
)) return ptr
;
484 /* if point is not in client area, return at once */
485 if (x
< ptr
->client_rect
.left
|| x
>= ptr
->client_rect
.right
||
486 y
< ptr
->client_rect
.top
|| y
>= ptr
->client_rect
.bottom
)
489 return child_window_from_point( ptr
, x
- ptr
->client_rect
.left
, y
- ptr
->client_rect
.top
);
491 return parent
; /* not found any child */
494 /* find all children of 'parent' that contain the given point */
495 static int get_window_children_from_point( struct window
*parent
, int x
, int y
,
496 struct user_handle_array
*array
)
500 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
502 if (!is_point_in_window( ptr
, x
, y
)) continue; /* skip it */
504 /* if point is in client area, and window is not minimized or disabled, check children */
505 if (!(ptr
->style
& (WS_MINIMIZE
|WS_DISABLED
)) &&
506 x
>= ptr
->client_rect
.left
&& x
< ptr
->client_rect
.right
&&
507 y
>= ptr
->client_rect
.top
&& y
< ptr
->client_rect
.bottom
)
509 if (!get_window_children_from_point( ptr
, x
- ptr
->client_rect
.left
,
510 y
- ptr
->client_rect
.top
, array
))
514 /* now add window to the array */
515 if (!add_handle_to_array( array
, ptr
->handle
)) return 0;
520 /* find window containing point (in absolute coords) */
521 user_handle_t
window_from_point( int x
, int y
)
525 if (!top_window
) return 0;
526 ret
= child_window_from_point( top_window
, x
, y
);
530 /* return list of all windows containing point (in absolute coords) */
531 static int all_windows_from_point( struct window
*top
, int x
, int y
, struct user_handle_array
*array
)
535 /* make point relative to top window */
536 for (ptr
= top
->parent
; ptr
&& ptr
!= top_window
; ptr
= ptr
->parent
)
538 x
-= ptr
->client_rect
.left
;
539 y
-= ptr
->client_rect
.top
;
542 if (!is_point_in_window( top
, x
, y
)) return 1;
544 /* if point is in client area, and window is not minimized or disabled, check children */
545 if (!(top
->style
& (WS_MINIMIZE
|WS_DISABLED
)) &&
546 x
>= top
->client_rect
.left
&& x
< top
->client_rect
.right
&&
547 y
>= top
->client_rect
.top
&& y
< top
->client_rect
.bottom
)
549 if (!get_window_children_from_point( top
, x
- top
->client_rect
.left
,
550 y
- top
->client_rect
.top
, array
))
553 /* now add window to the array */
554 if (!add_handle_to_array( array
, top
->handle
)) return 0;
559 /* return the thread owning a window */
560 struct thread
*get_window_thread( user_handle_t handle
)
562 struct window
*win
= get_user_object( handle
, USER_WINDOW
);
563 if (!win
|| !win
->thread
) return NULL
;
564 return (struct thread
*)grab_object( win
->thread
);
568 /* check if any area of a window needs repainting */
569 static inline int win_needs_repaint( struct window
*win
)
571 return win
->update_region
|| (win
->paint_flags
& PAINT_INTERNAL
);
575 /* find a child of the specified window that needs repainting */
576 static struct window
*find_child_to_repaint( struct window
*parent
, struct thread
*thread
)
578 struct window
*ptr
, *ret
= NULL
;
580 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
582 if (!(ptr
->style
& WS_VISIBLE
)) continue;
583 if (ptr
->thread
== thread
&& win_needs_repaint( ptr
))
585 else if (!(ptr
->style
& WS_MINIMIZE
)) /* explore its children */
586 ret
= find_child_to_repaint( ptr
, thread
);
590 if (ret
&& (ret
->ex_style
& WS_EX_TRANSPARENT
))
592 /* transparent window, check for non-transparent sibling to paint first */
593 for (ptr
= get_next_window(ret
); ptr
; ptr
= get_next_window(ptr
))
595 if (!(ptr
->style
& WS_VISIBLE
)) continue;
596 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
597 if (ptr
->thread
!= thread
) continue;
598 if (win_needs_repaint( ptr
)) return ptr
;
605 /* find a window that needs to receive a WM_PAINT; also clear its internal paint flag */
606 user_handle_t
find_window_to_repaint( user_handle_t parent
, struct thread
*thread
)
608 struct window
*ptr
, *win
= find_child_to_repaint( top_window
, thread
);
612 /* check that it is a child of the specified parent */
613 for (ptr
= win
; ptr
; ptr
= ptr
->parent
)
614 if (ptr
->handle
== parent
) break;
615 /* otherwise don't return any window, we don't repaint a child before its parent */
616 if (!ptr
) win
= NULL
;
619 win
->paint_flags
&= ~PAINT_INTERNAL
;
624 /* intersect the window region with the specified region, relative to the window parent */
625 static struct region
*intersect_window_region( struct region
*region
, struct window
*win
)
627 /* make region relative to window rect */
628 offset_region( region
, -win
->window_rect
.left
, -win
->window_rect
.top
);
629 if (!intersect_region( region
, region
, win
->win_region
)) return NULL
;
630 /* make region relative to parent again */
631 offset_region( region
, win
->window_rect
.left
, win
->window_rect
.top
);
636 /* convert coordinates from client to screen coords */
637 static inline void client_to_screen( struct window
*win
, int *x
, int *y
)
639 for ( ; win
; win
= win
->parent
)
641 *x
+= win
->client_rect
.left
;
642 *y
+= win
->client_rect
.top
;
646 /* map the region from window to screen coordinates */
647 static inline void map_win_region_to_screen( struct window
*win
, struct region
*region
)
649 int x
= win
->window_rect
.left
;
650 int y
= win
->window_rect
.top
;
651 client_to_screen( win
->parent
, &x
, &y
);
652 offset_region( region
, x
, y
);
656 /* clip all children of a given window out of the visible region */
657 static struct region
*clip_children( struct window
*parent
, struct window
*last
,
658 struct region
*region
, int offset_x
, int offset_y
)
661 struct region
*tmp
= create_empty_region();
663 if (!tmp
) return NULL
;
664 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
666 if (ptr
== last
) break;
667 if (!(ptr
->style
& WS_VISIBLE
)) continue;
668 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
669 set_region_rect( tmp
, &ptr
->visible_rect
);
670 if (ptr
->win_region
&& !intersect_window_region( tmp
, ptr
))
675 offset_region( tmp
, offset_x
, offset_y
);
676 if (!(region
= subtract_region( region
, region
, tmp
))) break;
677 if (is_region_empty( region
)) break;
684 /* compute the intersection of two rectangles; return 0 if the result is empty */
685 static inline int intersect_rect( rectangle_t
*dst
, const rectangle_t
*src1
, const rectangle_t
*src2
)
687 dst
->left
= max( src1
->left
, src2
->left
);
688 dst
->top
= max( src1
->top
, src2
->top
);
689 dst
->right
= min( src1
->right
, src2
->right
);
690 dst
->bottom
= min( src1
->bottom
, src2
->bottom
);
691 return (dst
->left
< dst
->right
&& dst
->top
< dst
->bottom
);
695 /* set the region to the client rect clipped by the window rect, in parent-relative coordinates */
696 static void set_region_client_rect( struct region
*region
, struct window
*win
)
700 intersect_rect( &rect
, &win
->window_rect
, &win
->client_rect
);
701 set_region_rect( region
, &rect
);
705 /* get the top-level window to clip against for a given window */
706 static inline struct window
*get_top_clipping_window( struct window
*win
)
708 while (win
->parent
&& win
->parent
!= top_window
) win
= win
->parent
;
713 /* compute the visible region of a window, in window coordinates */
714 static struct region
*get_visible_region( struct window
*win
, struct window
*top
, unsigned int flags
)
716 struct region
*tmp
= NULL
, *region
;
717 int offset_x
, offset_y
;
719 if (!(region
= create_empty_region())) return NULL
;
721 /* first check if all ancestors are visible */
723 if (!is_visible( win
)) return region
; /* empty region */
725 /* create a region relative to the window itself */
727 if ((flags
& DCX_PARENTCLIP
) && win
!= top
&& win
->parent
)
729 set_region_client_rect( region
, win
->parent
);
730 offset_region( region
, -win
->parent
->client_rect
.left
, -win
->parent
->client_rect
.top
);
732 else if (flags
& DCX_WINDOW
)
734 set_region_rect( region
, &win
->visible_rect
);
735 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
739 set_region_client_rect( region
, win
);
740 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
742 offset_x
= win
->window_rect
.left
;
743 offset_y
= win
->window_rect
.top
;
747 if (flags
& DCX_CLIPCHILDREN
)
749 if (!clip_children( win
, NULL
, region
, win
->client_rect
.left
, win
->client_rect
.top
))
753 /* clip siblings of ancestors */
755 if (top
&& top
!= win
&& (tmp
= create_empty_region()) != NULL
)
757 while (win
!= top
&& win
->parent
)
759 if (win
->style
& WS_CLIPSIBLINGS
)
761 if (!clip_children( win
->parent
, win
, region
, 0, 0 )) goto error
;
762 if (is_region_empty( region
)) break;
764 /* clip to parent client area */
766 offset_x
+= win
->client_rect
.left
;
767 offset_y
+= win
->client_rect
.top
;
768 offset_region( region
, win
->client_rect
.left
, win
->client_rect
.top
);
769 set_region_client_rect( tmp
, win
);
770 if (win
->win_region
&& !intersect_window_region( tmp
, win
)) goto error
;
771 if (!intersect_region( region
, region
, tmp
)) goto error
;
772 if (is_region_empty( region
)) break;
776 offset_region( region
, -offset_x
, -offset_y
); /* make it relative to target window */
780 if (tmp
) free_region( tmp
);
781 free_region( region
);
786 /* get the window class of a window */
787 struct window_class
* get_window_class( user_handle_t window
)
790 if (!(win
= get_window( window
))) return NULL
;
794 /* return a copy of the specified region cropped to the window client or frame rectangle, */
795 /* and converted from client to window coordinates. Helper for (in)validate_window. */
796 static struct region
*crop_region_to_win_rect( struct window
*win
, struct region
*region
, int frame
)
798 struct region
*tmp
= create_empty_region();
800 if (!tmp
) return NULL
;
802 /* get bounding rect in client coords */
803 if (frame
) set_region_rect( tmp
, &win
->window_rect
);
804 else set_region_client_rect( tmp
, win
);
805 offset_region( tmp
, -win
->client_rect
.left
, -win
->client_rect
.top
);
807 /* intersect specified region with bounding rect */
808 if (region
&& !intersect_region( tmp
, region
, tmp
)) goto done
;
809 if (is_region_empty( tmp
)) goto done
;
811 /* map it to window coords */
812 offset_region( tmp
, win
->client_rect
.left
- win
->window_rect
.left
,
813 win
->client_rect
.top
- win
->window_rect
.top
);
822 /* set a region as new update region for the window */
823 static void set_update_region( struct window
*win
, struct region
*region
)
825 if (region
&& !is_region_empty( region
))
827 if (!win
->update_region
) inc_window_paint_count( win
, 1 );
828 else free_region( win
->update_region
);
829 win
->update_region
= region
;
833 if (win
->update_region
) inc_window_paint_count( win
, -1 );
834 win
->paint_flags
&= ~(PAINT_ERASE
| PAINT_NONCLIENT
);
835 win
->update_region
= NULL
;
836 if (region
) free_region( region
);
841 /* add a region to the update region; the passed region is freed or reused */
842 static int add_update_region( struct window
*win
, struct region
*region
)
844 if (win
->update_region
&& !union_region( region
, win
->update_region
, region
))
846 free_region( region
);
849 set_update_region( win
, region
);
854 /* validate the non client area of a window */
855 static void validate_non_client( struct window
*win
)
860 if (!win
->update_region
) return; /* nothing to do */
862 /* get client rect in window coords */
863 rect
.left
= win
->client_rect
.left
- win
->window_rect
.left
;
864 rect
.top
= win
->client_rect
.top
- win
->window_rect
.top
;
865 rect
.right
= win
->client_rect
.right
- win
->window_rect
.left
;
866 rect
.bottom
= win
->client_rect
.bottom
- win
->window_rect
.top
;
868 if ((tmp
= create_empty_region()))
870 set_region_rect( tmp
, &rect
);
871 if (intersect_region( tmp
, win
->update_region
, tmp
))
872 set_update_region( win
, tmp
);
876 win
->paint_flags
&= ~PAINT_NONCLIENT
;
880 /* validate a window completely so that we don't get any further paint messages for it */
881 static void validate_whole_window( struct window
*win
)
883 set_update_region( win
, NULL
);
885 if (win
->paint_flags
& PAINT_INTERNAL
)
887 win
->paint_flags
&= ~PAINT_INTERNAL
;
888 inc_window_paint_count( win
, -1 );
893 /* validate the update region of a window on all parents; helper for redraw_window */
894 static void validate_parents( struct window
*child
)
896 int offset_x
= 0, offset_y
= 0;
897 struct window
*win
= child
;
898 struct region
*tmp
= NULL
;
900 if (!child
->update_region
) return;
902 while (win
->parent
&& win
->parent
!= top_window
)
904 /* map to parent client coords */
905 offset_x
+= win
->window_rect
.left
;
906 offset_y
+= win
->window_rect
.top
;
910 /* and now map to window coords */
911 offset_x
+= win
->client_rect
.left
- win
->window_rect
.left
;
912 offset_y
+= win
->client_rect
.top
- win
->window_rect
.top
;
914 if (win
->update_region
&& !(win
->style
& WS_CLIPCHILDREN
))
916 if (!tmp
&& !(tmp
= create_empty_region())) return;
917 offset_region( child
->update_region
, offset_x
, offset_y
);
918 if (subtract_region( tmp
, win
->update_region
, child
->update_region
))
920 set_update_region( win
, tmp
);
923 /* restore child coords */
924 offset_region( child
->update_region
, -offset_x
, -offset_y
);
927 if (tmp
) free_region( tmp
);
931 /* add/subtract a region (in client coordinates) to the update region of the window */
932 static void redraw_window( struct window
*win
, struct region
*region
, int frame
, unsigned int flags
)
935 struct window
*child
;
937 if (flags
& RDW_INVALIDATE
)
939 if (!(tmp
= crop_region_to_win_rect( win
, region
, frame
))) return;
941 if (!add_update_region( win
, tmp
)) return;
943 if (flags
& RDW_FRAME
) win
->paint_flags
|= PAINT_NONCLIENT
;
944 if (flags
& RDW_ERASE
) win
->paint_flags
|= PAINT_ERASE
;
946 else if (flags
& RDW_VALIDATE
)
948 if (!region
&& (flags
& RDW_NOFRAME
)) /* shortcut: validate everything */
950 set_update_region( win
, NULL
);
952 else if (win
->update_region
)
954 if ((tmp
= crop_region_to_win_rect( win
, region
, frame
)))
956 if (!subtract_region( tmp
, win
->update_region
, tmp
))
961 set_update_region( win
, tmp
);
963 if (flags
& RDW_NOFRAME
) validate_non_client( win
);
964 if (flags
& RDW_NOERASE
) win
->paint_flags
&= ~PAINT_ERASE
;
968 if ((flags
& RDW_INTERNALPAINT
) && !(win
->paint_flags
& PAINT_INTERNAL
))
970 win
->paint_flags
|= PAINT_INTERNAL
;
971 inc_window_paint_count( win
, 1 );
973 else if ((flags
& RDW_NOINTERNALPAINT
) && (win
->paint_flags
& PAINT_INTERNAL
))
975 win
->paint_flags
&= ~PAINT_INTERNAL
;
976 inc_window_paint_count( win
, -1 );
979 if (flags
& RDW_UPDATENOW
)
981 validate_parents( win
);
982 flags
&= ~RDW_UPDATENOW
;
985 /* now process children recursively */
987 if (flags
& RDW_NOCHILDREN
) return;
988 if (win
->style
& WS_MINIMIZE
) return;
989 if ((win
->style
& WS_CLIPCHILDREN
) && !(flags
& RDW_ALLCHILDREN
)) return;
991 if (!(tmp
= crop_region_to_win_rect( win
, region
, 0 ))) return;
993 /* map to client coordinates */
994 offset_region( tmp
, win
->window_rect
.left
- win
->client_rect
.left
,
995 win
->window_rect
.top
- win
->client_rect
.top
);
997 if (flags
& RDW_INVALIDATE
) flags
|= RDW_FRAME
| RDW_ERASE
;
999 LIST_FOR_EACH_ENTRY( child
, &win
->children
, struct window
, entry
)
1001 if (!(child
->style
& WS_VISIBLE
)) continue;
1002 if (!rect_in_region( tmp
, &child
->window_rect
)) continue;
1003 offset_region( tmp
, -child
->client_rect
.left
, -child
->client_rect
.top
);
1004 redraw_window( child
, tmp
, 1, flags
);
1005 offset_region( tmp
, child
->client_rect
.left
, child
->client_rect
.top
);
1011 /* retrieve the update flags for a window depending on the state of the update region */
1012 static unsigned int get_update_flags( struct window
*win
, unsigned int flags
)
1014 unsigned int ret
= 0;
1016 if (flags
& UPDATE_NONCLIENT
)
1018 if ((win
->paint_flags
& PAINT_NONCLIENT
) && win
->update_region
) ret
|= UPDATE_NONCLIENT
;
1020 if (flags
& UPDATE_ERASE
)
1022 if ((win
->paint_flags
& PAINT_ERASE
) && win
->update_region
) ret
|= UPDATE_ERASE
;
1024 if (flags
& UPDATE_PAINT
)
1026 if (win
->update_region
) ret
|= UPDATE_PAINT
;
1028 if (flags
& UPDATE_INTERNALPAINT
)
1030 if (win
->paint_flags
& PAINT_INTERNAL
) ret
|= UPDATE_INTERNALPAINT
;
1036 /* iterate through the children of the given window until we find one with some update flags */
1037 static unsigned int get_child_update_flags( struct window
*win
, unsigned int flags
,
1038 struct window
**child
)
1041 unsigned int ret
= 0;
1043 LIST_FOR_EACH_ENTRY( ptr
, &win
->children
, struct window
, entry
)
1045 if (!(ptr
->style
& WS_VISIBLE
)) continue;
1046 if ((ret
= get_update_flags( ptr
, flags
)) != 0)
1051 if (ptr
->style
& WS_MINIMIZE
) continue;
1053 /* Note: the WS_CLIPCHILDREN test is the opposite of the invalidation case,
1054 * here we only want to repaint children of windows that clip them, others
1055 * need to wait for WM_PAINT to be done in the parent first.
1057 if (!(flags
& UPDATE_NOCHILDREN
) &&
1058 ((flags
& UPDATE_ALLCHILDREN
) || (ptr
->style
& WS_CLIPCHILDREN
)))
1060 if ((ret
= get_child_update_flags( ptr
, flags
, child
))) break;
1067 /* expose a region of a window, looking for the top most parent that needs to be exposed */
1068 /* the region is in window coordinates */
1069 static void expose_window( struct window
*win
, struct window
*top
, struct region
*region
)
1071 struct window
*parent
, *ptr
;
1072 int offset_x
, offset_y
;
1074 /* find the top most parent that doesn't clip either siblings or children */
1075 for (parent
= ptr
= win
; ptr
!= top
; ptr
= ptr
->parent
)
1077 if (!(ptr
->style
& WS_CLIPCHILDREN
)) parent
= ptr
;
1078 if (!(ptr
->style
& WS_CLIPSIBLINGS
)) parent
= ptr
->parent
;
1080 if (parent
== win
&& parent
!= top
&& win
->parent
)
1081 parent
= win
->parent
; /* always go up at least one level if possible */
1083 offset_x
= win
->window_rect
.left
- win
->client_rect
.left
;
1084 offset_y
= win
->window_rect
.top
- win
->client_rect
.top
;
1085 for (ptr
= win
; ptr
!= parent
; ptr
= ptr
->parent
)
1087 offset_x
+= ptr
->client_rect
.left
;
1088 offset_y
+= ptr
->client_rect
.top
;
1090 offset_region( region
, offset_x
, offset_y
);
1091 redraw_window( parent
, region
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1092 offset_region( region
, -offset_x
, -offset_y
);
1096 /* set the window and client rectangles, updating the update region if necessary */
1097 static void set_window_pos( struct window
*win
, struct window
*previous
,
1098 unsigned int swp_flags
, const rectangle_t
*window_rect
,
1099 const rectangle_t
*client_rect
, const rectangle_t
*visible_rect
,
1100 const rectangle_t
*valid_rects
)
1102 struct region
*old_vis_rgn
= NULL
, *new_vis_rgn
;
1103 const rectangle_t old_window_rect
= win
->window_rect
;
1104 const rectangle_t old_visible_rect
= win
->visible_rect
;
1105 const rectangle_t old_client_rect
= win
->client_rect
;
1106 struct window
*top
= get_top_clipping_window( win
);
1107 int visible
= (win
->style
& WS_VISIBLE
) || (swp_flags
& SWP_SHOWWINDOW
);
1109 if (win
->parent
&& !is_visible( win
->parent
)) visible
= 0;
1111 if (visible
&& !(old_vis_rgn
= get_visible_region( win
, top
, DCX_WINDOW
))) return;
1113 /* set the new window info before invalidating anything */
1115 win
->window_rect
= *window_rect
;
1116 win
->visible_rect
= *visible_rect
;
1117 win
->client_rect
= *client_rect
;
1118 if (!(swp_flags
& SWP_NOZORDER
) && win
->parent
)
1120 list_remove( &win
->entry
); /* unlink it from the previous location */
1121 if (previous
) list_add_after( &previous
->entry
, &win
->entry
);
1122 else list_add_head( &win
->parent
->children
, &win
->entry
);
1124 if (swp_flags
& SWP_SHOWWINDOW
) win
->style
|= WS_VISIBLE
;
1125 else if (swp_flags
& SWP_HIDEWINDOW
) win
->style
&= ~WS_VISIBLE
;
1127 /* if the window is not visible, everything is easy */
1128 if (!visible
) return;
1130 if (!(new_vis_rgn
= get_visible_region( win
, top
, DCX_WINDOW
)))
1132 free_region( old_vis_rgn
);
1133 clear_error(); /* ignore error since the window info has been modified already */
1137 /* expose anything revealed by the change */
1139 if (!(swp_flags
& SWP_NOREDRAW
))
1141 offset_region( old_vis_rgn
, old_window_rect
.left
- window_rect
->left
,
1142 old_window_rect
.top
- window_rect
->top
);
1143 if (xor_region( new_vis_rgn
, old_vis_rgn
, new_vis_rgn
))
1144 expose_window( win
, top
, new_vis_rgn
);
1146 free_region( old_vis_rgn
);
1148 if (!(win
->style
& WS_VISIBLE
))
1150 /* clear the update region since the window is no longer visible */
1151 validate_whole_window( win
);
1155 if (swp_flags
& SWP_NOREDRAW
) goto done
; /* do not repaint anything */
1157 /* expose the whole non-client area if it changed in any way */
1159 if ((swp_flags
& SWP_FRAMECHANGED
) ||
1160 memcmp( window_rect
, &old_window_rect
, sizeof(old_window_rect
) ) ||
1161 memcmp( visible_rect
, &old_visible_rect
, sizeof(old_visible_rect
) ) ||
1162 memcmp( client_rect
, &old_client_rect
, sizeof(old_client_rect
) ))
1164 struct region
*tmp
= create_empty_region();
1168 /* subtract the valid portion of client rect from the total region */
1169 if (!memcmp( client_rect
, &old_client_rect
, sizeof(old_client_rect
) ))
1170 set_region_rect( tmp
, client_rect
);
1171 else if (valid_rects
)
1172 set_region_rect( tmp
, &valid_rects
[0] );
1174 set_region_rect( new_vis_rgn
, window_rect
);
1175 if (subtract_region( tmp
, new_vis_rgn
, tmp
))
1177 offset_region( tmp
, -client_rect
->left
, -client_rect
->top
);
1178 redraw_window( win
, tmp
, 1, RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
1185 free_region( new_vis_rgn
);
1186 clear_error(); /* we ignore out of memory errors once the new rects have been set */
1190 /* create a window */
1191 DECL_HANDLER(create_window
)
1196 if (!req
->parent
) /* return desktop window */
1200 if (!(top_window
= create_window( NULL
, NULL
, req
->atom
, req
->instance
))) return;
1201 top_window
->thread
= NULL
; /* no thread owns the desktop */
1202 top_window
->style
= WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
1208 struct window
*parent
, *owner
= NULL
;
1210 if (!(parent
= get_window( req
->parent
))) return;
1211 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
1212 if (owner
== top_window
) owner
= NULL
;
1213 else if (owner
&& parent
!= top_window
)
1215 /* an owned window must be created as top-level */
1216 set_error( STATUS_ACCESS_DENIED
);
1219 if (!(win
= create_window( parent
, owner
, req
->atom
, req
->instance
))) return;
1221 reply
->handle
= win
->handle
;
1222 reply
->extra
= win
->nb_extra_bytes
;
1223 reply
->class_ptr
= get_class_client_ptr( win
->class );
1227 /* set the parent of a window */
1228 DECL_HANDLER(set_parent
)
1230 struct window
*win
, *parent
= NULL
;
1232 if (!(win
= get_window( req
->handle
))) return;
1233 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
1235 if (win
== top_window
)
1237 set_error( STATUS_INVALID_PARAMETER
);
1240 reply
->old_parent
= win
->parent
->handle
;
1241 reply
->full_parent
= parent
? parent
->handle
: 0;
1242 set_parent_window( win
, parent
);
1246 /* destroy a window */
1247 DECL_HANDLER(destroy_window
)
1249 struct window
*win
= get_window( req
->handle
);
1252 if (win
!= top_window
) destroy_window( win
);
1253 else set_error( STATUS_ACCESS_DENIED
);
1258 /* set a window owner */
1259 DECL_HANDLER(set_window_owner
)
1261 struct window
*win
= get_window( req
->handle
);
1262 struct window
*owner
= NULL
;
1265 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
1266 if (win
== top_window
)
1268 set_error( STATUS_ACCESS_DENIED
);
1271 reply
->prev_owner
= win
->owner
;
1272 reply
->full_owner
= win
->owner
= owner
? owner
->handle
: 0;
1276 /* get information from a window handle */
1277 DECL_HANDLER(get_window_info
)
1279 struct window
*win
= get_window( req
->handle
);
1281 reply
->full_handle
= 0;
1282 reply
->tid
= reply
->pid
= 0;
1285 reply
->full_handle
= win
->handle
;
1286 reply
->last_active
= win
->handle
;
1287 if (get_user_object( win
->last_active
, USER_WINDOW
)) reply
->last_active
= win
->last_active
;
1290 reply
->tid
= get_thread_id( win
->thread
);
1291 reply
->pid
= get_process_id( win
->thread
->process
);
1292 reply
->atom
= get_class_atom( win
->class );
1298 /* set some information in a window */
1299 DECL_HANDLER(set_window_info
)
1301 struct window
*win
= get_window( req
->handle
);
1304 if (req
->flags
&& win
== top_window
)
1306 set_error( STATUS_ACCESS_DENIED
);
1309 if (req
->extra_size
> sizeof(req
->extra_value
) ||
1310 req
->extra_offset
< -1 ||
1311 req
->extra_offset
> win
->nb_extra_bytes
- (int)req
->extra_size
)
1313 set_win32_error( ERROR_INVALID_INDEX
);
1316 if (req
->extra_offset
!= -1)
1318 memcpy( &reply
->old_extra_value
, win
->extra_bytes
+ req
->extra_offset
, req
->extra_size
);
1320 else if (req
->flags
& SET_WIN_EXTRA
)
1322 set_win32_error( ERROR_INVALID_INDEX
);
1325 reply
->old_style
= win
->style
;
1326 reply
->old_ex_style
= win
->ex_style
;
1327 reply
->old_id
= win
->id
;
1328 reply
->old_instance
= win
->instance
;
1329 reply
->old_user_data
= win
->user_data
;
1330 if (req
->flags
& SET_WIN_STYLE
) win
->style
= req
->style
;
1331 if (req
->flags
& SET_WIN_EXSTYLE
) win
->ex_style
= req
->ex_style
;
1332 if (req
->flags
& SET_WIN_ID
) win
->id
= req
->id
;
1333 if (req
->flags
& SET_WIN_INSTANCE
) win
->instance
= req
->instance
;
1334 if (req
->flags
& SET_WIN_USERDATA
) win
->user_data
= req
->user_data
;
1335 if (req
->flags
& SET_WIN_EXTRA
) memcpy( win
->extra_bytes
+ req
->extra_offset
,
1336 &req
->extra_value
, req
->extra_size
);
1338 /* changing window style triggers a non-client paint */
1339 if (req
->flags
& SET_WIN_STYLE
) win
->paint_flags
|= PAINT_NONCLIENT
;
1343 /* get a list of the window parents, up to the root of the tree */
1344 DECL_HANDLER(get_window_parents
)
1346 struct window
*ptr
, *win
= get_window( req
->handle
);
1348 user_handle_t
*data
;
1351 if (win
) for (ptr
= win
->parent
; ptr
; ptr
= ptr
->parent
) total
++;
1353 reply
->count
= total
;
1354 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
1355 if (len
&& ((data
= set_reply_data_size( len
))))
1357 for (ptr
= win
->parent
; ptr
&& len
; ptr
= ptr
->parent
, len
-= sizeof(*data
))
1358 *data
++ = ptr
->handle
;
1363 /* get a list of the window children */
1364 DECL_HANDLER(get_window_children
)
1366 struct window
*ptr
, *parent
= get_window( req
->parent
);
1368 user_handle_t
*data
;
1373 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
1375 if (req
->atom
&& get_class_atom(ptr
->class) != req
->atom
) continue;
1376 if (req
->tid
&& get_thread_id(ptr
->thread
) != req
->tid
) continue;
1380 reply
->count
= total
;
1381 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
1382 if (len
&& ((data
= set_reply_data_size( len
))))
1384 LIST_FOR_EACH_ENTRY( ptr
, &parent
->children
, struct window
, entry
)
1386 if (len
< sizeof(*data
)) break;
1387 if (req
->atom
&& get_class_atom(ptr
->class) != req
->atom
) continue;
1388 if (req
->tid
&& get_thread_id(ptr
->thread
) != req
->tid
) continue;
1389 *data
++ = ptr
->handle
;
1390 len
-= sizeof(*data
);
1396 /* get a list of the window children that contain a given point */
1397 DECL_HANDLER(get_window_children_from_point
)
1399 struct user_handle_array array
;
1400 struct window
*parent
= get_window( req
->parent
);
1403 if (!parent
) return;
1405 array
.handles
= NULL
;
1408 if (!all_windows_from_point( parent
, req
->x
, req
->y
, &array
)) return;
1410 reply
->count
= array
.count
;
1411 len
= min( get_reply_max_size(), array
.count
* sizeof(user_handle_t
) );
1412 if (len
) set_reply_data_ptr( array
.handles
, len
);
1413 else free( array
.handles
);
1417 /* get window tree information from a window handle */
1418 DECL_HANDLER(get_window_tree
)
1420 struct window
*ptr
, *win
= get_window( req
->handle
);
1426 reply
->next_sibling
= 0;
1427 reply
->prev_sibling
= 0;
1428 reply
->first_sibling
= 0;
1429 reply
->last_sibling
= 0;
1430 reply
->first_child
= 0;
1431 reply
->last_child
= 0;
1435 struct window
*parent
= win
->parent
;
1436 reply
->parent
= parent
->handle
;
1437 reply
->owner
= win
->owner
;
1438 if ((ptr
= get_next_window( win
))) reply
->next_sibling
= ptr
->handle
;
1439 if ((ptr
= get_prev_window( win
))) reply
->prev_sibling
= ptr
->handle
;
1440 if ((ptr
= get_first_child( parent
))) reply
->first_sibling
= ptr
->handle
;
1441 if ((ptr
= get_last_child( parent
))) reply
->last_sibling
= ptr
->handle
;
1443 if ((ptr
= get_first_child( win
))) reply
->first_child
= ptr
->handle
;
1444 if ((ptr
= get_last_child( win
))) reply
->last_child
= ptr
->handle
;
1448 /* set the position and Z order of a window */
1449 DECL_HANDLER(set_window_pos
)
1451 const rectangle_t
*visible_rect
= NULL
, *valid_rects
= NULL
;
1452 struct window
*previous
= NULL
;
1453 struct window
*win
= get_window( req
->handle
);
1454 unsigned int flags
= req
->flags
;
1457 if (!win
->parent
) flags
|= SWP_NOZORDER
; /* no Z order for the desktop */
1459 if (!(flags
& SWP_NOZORDER
))
1461 if (!req
->previous
) /* special case: HWND_TOP */
1463 if (get_first_child(win
->parent
) == win
) flags
|= SWP_NOZORDER
;
1465 else if (req
->previous
== (user_handle_t
)1) /* special case: HWND_BOTTOM */
1467 previous
= get_last_child( win
->parent
);
1471 if (!(previous
= get_window( req
->previous
))) return;
1472 /* previous must be a sibling */
1473 if (previous
->parent
!= win
->parent
)
1475 set_error( STATUS_INVALID_PARAMETER
);
1479 if (previous
== win
) flags
|= SWP_NOZORDER
; /* nothing to do */
1482 /* window rectangle must be ordered properly */
1483 if (req
->window
.right
< req
->window
.left
|| req
->window
.bottom
< req
->window
.top
)
1485 set_error( STATUS_INVALID_PARAMETER
);
1489 if (get_req_data_size() >= sizeof(rectangle_t
)) visible_rect
= get_req_data();
1490 if (get_req_data_size() >= 3 * sizeof(rectangle_t
)) valid_rects
= visible_rect
+ 1;
1492 if (!visible_rect
) visible_rect
= &req
->window
;
1493 set_window_pos( win
, previous
, flags
, &req
->window
, &req
->client
, visible_rect
, valid_rects
);
1494 reply
->new_style
= win
->style
;
1498 /* get the window and client rectangles of a window */
1499 DECL_HANDLER(get_window_rectangles
)
1501 struct window
*win
= get_window( req
->handle
);
1505 reply
->window
= win
->window_rect
;
1506 reply
->visible
= win
->visible_rect
;
1507 reply
->client
= win
->client_rect
;
1512 /* get the window text */
1513 DECL_HANDLER(get_window_text
)
1515 struct window
*win
= get_window( req
->handle
);
1517 if (win
&& win
->text
)
1519 size_t len
= strlenW( win
->text
) * sizeof(WCHAR
);
1520 if (len
> get_reply_max_size()) len
= get_reply_max_size();
1521 set_reply_data( win
->text
, len
);
1526 /* set the window text */
1527 DECL_HANDLER(set_window_text
)
1529 struct window
*win
= get_window( req
->handle
);
1534 size_t len
= get_req_data_size() / sizeof(WCHAR
);
1537 if (!(text
= mem_alloc( (len
+1) * sizeof(WCHAR
) ))) return;
1538 memcpy( text
, get_req_data(), len
* sizeof(WCHAR
) );
1541 if (win
->text
) free( win
->text
);
1547 /* get the coordinates offset between two windows */
1548 DECL_HANDLER(get_windows_offset
)
1552 reply
->x
= reply
->y
= 0;
1555 if (!(win
= get_window( req
->from
))) return;
1558 reply
->x
+= win
->client_rect
.left
;
1559 reply
->y
+= win
->client_rect
.top
;
1565 if (!(win
= get_window( req
->to
))) return;
1568 reply
->x
-= win
->client_rect
.left
;
1569 reply
->y
-= win
->client_rect
.top
;
1576 /* get the visible region of a window */
1577 DECL_HANDLER(get_visible_region
)
1579 struct region
*region
;
1580 struct window
*top
, *win
= get_window( req
->window
);
1584 top
= get_top_clipping_window( win
);
1585 if ((region
= get_visible_region( win
, top
, req
->flags
)))
1588 map_win_region_to_screen( win
, region
);
1589 data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
1590 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
1592 reply
->top_win
= top
->handle
;
1593 reply
->top_org_x
= top
->visible_rect
.left
;
1594 reply
->top_org_y
= top
->visible_rect
.top
;
1595 reply
->win_org_x
= (req
->flags
& DCX_WINDOW
) ? win
->window_rect
.left
: win
->client_rect
.left
;
1596 reply
->win_org_y
= (req
->flags
& DCX_WINDOW
) ? win
->window_rect
.top
: win
->client_rect
.top
;
1597 client_to_screen( top
->parent
, &reply
->top_org_x
, &reply
->top_org_y
);
1598 client_to_screen( win
->parent
, &reply
->win_org_x
, &reply
->win_org_y
);
1602 /* get the window region */
1603 DECL_HANDLER(get_window_region
)
1605 struct window
*win
= get_window( req
->window
);
1609 if (win
->win_region
)
1611 rectangle_t
*data
= get_region_data( win
->win_region
, get_reply_max_size(), &reply
->total_size
);
1612 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
1617 /* set the window region */
1618 DECL_HANDLER(set_window_region
)
1620 struct region
*region
= NULL
;
1621 struct window
*win
= get_window( req
->window
);
1625 if (get_req_data_size()) /* no data means remove the region completely */
1627 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
1630 if (win
->win_region
) free_region( win
->win_region
);
1631 win
->win_region
= region
;
1635 /* get a window update region */
1636 DECL_HANDLER(get_update_region
)
1639 unsigned int flags
= req
->flags
;
1640 struct window
*win
= get_window( req
->window
);
1643 if (!win
|| !is_visible( win
)) return;
1645 if ((flags
& UPDATE_NONCLIENT
) && !(flags
& (UPDATE_PAINT
|UPDATE_INTERNALPAINT
)))
1647 /* non-client painting must be delayed if one of the parents is going to
1648 * be repainted and doesn't clip children */
1651 for (ptr
= win
->parent
; ptr
&& ptr
!= top_window
; ptr
= ptr
->parent
)
1653 if (!(ptr
->style
& WS_CLIPCHILDREN
) && win_needs_repaint( ptr
))
1658 if (!(reply
->flags
= get_update_flags( win
, flags
)))
1660 /* if window doesn't need any repaint, check the children */
1661 if (!(flags
& UPDATE_NOCHILDREN
) &&
1662 ((flags
& UPDATE_ALLCHILDREN
) || (win
->style
& WS_CLIPCHILDREN
)) &&
1663 !(win
->style
& WS_MINIMIZE
))
1665 reply
->flags
= get_child_update_flags( win
, flags
, &win
);
1669 reply
->child
= win
->handle
;
1671 if (flags
& UPDATE_NOREGION
) return;
1673 if (win
->update_region
)
1675 /* convert update region to screen coordinates */
1676 struct region
*region
= create_empty_region();
1678 if (!region
) return;
1679 if (!copy_region( region
, win
->update_region
))
1681 free_region( region
);
1684 map_win_region_to_screen( win
, region
);
1685 if (!(data
= get_region_data_and_free( region
, get_reply_max_size(),
1686 &reply
->total_size
))) return;
1687 set_reply_data_ptr( data
, reply
->total_size
);
1690 if (reply
->flags
& (UPDATE_PAINT
|UPDATE_INTERNALPAINT
)) /* validate everything */
1692 validate_whole_window( win
);
1696 if (reply
->flags
& UPDATE_NONCLIENT
) validate_non_client( win
);
1697 if (reply
->flags
& UPDATE_ERASE
)
1699 win
->paint_flags
&= ~PAINT_ERASE
;
1700 /* desktop window only gets erased, not repainted */
1701 if (win
== top_window
) validate_whole_window( win
);
1707 /* update the z order of a window so that a given rectangle is fully visible */
1708 DECL_HANDLER(update_window_zorder
)
1711 struct window
*ptr
, *win
= get_window( req
->window
);
1713 if (!win
|| !win
->parent
|| !is_visible( win
)) return; /* nothing to do */
1715 LIST_FOR_EACH_ENTRY( ptr
, &win
->parent
->children
, struct window
, entry
)
1717 if (ptr
== win
) break;
1718 if (!(ptr
->style
& WS_VISIBLE
)) continue;
1719 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
1720 if (!intersect_rect( &tmp
, &ptr
->visible_rect
, &req
->rect
)) continue;
1721 if (ptr
->win_region
&& !rect_in_region( ptr
->win_region
, &req
->rect
)) continue;
1722 /* found a window obscuring the rectangle, now move win above this one */
1723 list_remove( &win
->entry
);
1724 list_add_before( &ptr
->entry
, &win
->entry
);
1730 /* mark parts of a window as needing a redraw */
1731 DECL_HANDLER(redraw_window
)
1733 struct region
*region
= NULL
;
1734 struct window
*win
= get_window( req
->window
);
1737 if (!is_visible( win
)) return; /* nothing to do */
1739 if (req
->flags
& (RDW_VALIDATE
|RDW_INVALIDATE
))
1741 if (get_req_data_size()) /* no data means whole rectangle */
1743 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
1748 redraw_window( win
, region
, (req
->flags
& RDW_INVALIDATE
) && (req
->flags
& RDW_FRAME
),
1750 if (region
) free_region( region
);
1754 /* set a window property */
1755 DECL_HANDLER(set_window_property
)
1757 struct window
*win
= get_window( req
->window
);
1759 if (win
) set_property( win
, req
->atom
, req
->handle
,
1760 req
->string
? PROP_TYPE_STRING
: PROP_TYPE_ATOM
);
1764 /* remove a window property */
1765 DECL_HANDLER(remove_window_property
)
1767 struct window
*win
= get_window( req
->window
);
1769 if (win
) reply
->handle
= remove_property( win
, req
->atom
);
1773 /* get a window property */
1774 DECL_HANDLER(get_window_property
)
1776 struct window
*win
= get_window( req
->window
);
1778 if (win
) reply
->handle
= get_property( win
, req
->atom
);
1782 /* get the list of properties of a window */
1783 DECL_HANDLER(get_window_properties
)
1785 property_data_t
*data
;
1786 int i
, count
, max
= get_reply_max_size() / sizeof(*data
);
1787 struct window
*win
= get_window( req
->window
);
1792 for (i
= count
= 0; i
< win
->prop_inuse
; i
++)
1793 if (win
->properties
[i
].type
!= PROP_TYPE_FREE
) count
++;
1794 reply
->total
= count
;
1796 if (count
> max
) count
= max
;
1797 if (!count
|| !(data
= set_reply_data_size( count
* sizeof(*data
) ))) return;
1799 for (i
= 0; i
< win
->prop_inuse
&& count
; i
++)
1801 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
1802 data
->atom
= win
->properties
[i
].atom
;
1803 data
->string
= (win
->properties
[i
].type
== PROP_TYPE_STRING
);
1804 data
->handle
= win
->properties
[i
].handle
;
1811 /* get the new window pointer for a global window, checking permissions */
1812 /* helper for set_global_windows request */
1813 static int get_new_global_window( struct window
**win
, user_handle_t handle
)
1822 set_error( STATUS_ACCESS_DENIED
);
1825 *win
= get_window( handle
);
1826 return (*win
!= NULL
);
1829 /* Set/get the global windows */
1830 DECL_HANDLER(set_global_windows
)
1832 struct window
*new_shell_window
= shell_window
;
1833 struct window
*new_shell_listview
= shell_listview
;
1834 struct window
*new_progman_window
= progman_window
;
1835 struct window
*new_taskman_window
= taskman_window
;
1837 reply
->old_shell_window
= shell_window
? shell_window
->handle
: 0;
1838 reply
->old_shell_listview
= shell_listview
? shell_listview
->handle
: 0;
1839 reply
->old_progman_window
= progman_window
? progman_window
->handle
: 0;
1840 reply
->old_taskman_window
= taskman_window
? taskman_window
->handle
: 0;
1842 if (req
->flags
& SET_GLOBAL_SHELL_WINDOWS
)
1844 if (!get_new_global_window( &new_shell_window
, req
->shell_window
)) return;
1845 if (!get_new_global_window( &new_shell_listview
, req
->shell_listview
)) return;
1847 if (req
->flags
& SET_GLOBAL_PROGMAN_WINDOW
)
1849 if (!get_new_global_window( &new_progman_window
, req
->progman_window
)) return;
1851 if (req
->flags
& SET_GLOBAL_TASKMAN_WINDOW
)
1853 if (!get_new_global_window( &new_taskman_window
, req
->taskman_window
)) return;
1855 shell_window
= new_shell_window
;
1856 shell_listview
= new_shell_listview
;
1857 progman_window
= new_progman_window
;
1858 taskman_window
= new_taskman_window
;