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 window
*first_child
; /* first child in Z-order */
60 struct window
*last_child
; /* last child in Z-order */
61 struct window
*first_unlinked
; /* first child not linked in the Z-order list */
62 struct window
*next
; /* next window in Z-order */
63 struct window
*prev
; /* prev window in Z-order */
64 user_handle_t handle
; /* full handle for this window */
65 struct thread
*thread
; /* thread owning the window */
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 client_rect
; /* client rectangle (relative to parent client area) */
71 struct region
*win_region
; /* region for shaped windows (relative to window rect) */
72 struct region
*update_region
; /* update region (relative to window rect) */
73 unsigned int style
; /* window style */
74 unsigned int ex_style
; /* window extended style */
75 unsigned int id
; /* window id */
76 void* instance
; /* creator instance */
77 void* user_data
; /* user-specific data */
78 WCHAR
*text
; /* window caption text */
79 unsigned int paint_flags
; /* various painting flags */
80 int prop_inuse
; /* number of in-use window properties */
81 int prop_alloc
; /* number of allocated window properties */
82 struct property
*properties
; /* window properties array */
83 int nb_extra_bytes
; /* number of extra bytes */
84 char extra_bytes
[1]; /* extra bytes storage */
87 #define PAINT_INTERNAL 0x01 /* internal WM_PAINT pending */
88 #define PAINT_ERASE 0x02 /* needs WM_ERASEBKGND */
89 #define PAINT_NONCLIENT 0x04 /* needs WM_NCPAINT */
91 /* growable array of user handles */
92 struct user_handle_array
94 user_handle_t
*handles
;
99 static struct window
*top_window
; /* top-level (desktop) window */
101 /* global window pointers */
102 static struct window
*shell_window
;
103 static struct window
*shell_listview
;
104 static struct window
*progman_window
;
105 static struct window
*taskman_window
;
107 /* retrieve a pointer to a window from its handle */
108 inline static struct window
*get_window( user_handle_t handle
)
110 struct window
*ret
= get_user_object( handle
, USER_WINDOW
);
111 if (!ret
) set_error( STATUS_INVALID_HANDLE
);
115 /* unlink a window from the tree */
116 static void unlink_window( struct window
*win
)
118 struct window
*parent
= win
->parent
;
122 if (win
->next
) win
->next
->prev
= win
->prev
;
123 else if (parent
->last_child
== win
) parent
->last_child
= win
->prev
;
125 if (win
->prev
) win
->prev
->next
= win
->next
;
126 else if (parent
->first_child
== win
) parent
->first_child
= win
->next
;
127 else if (parent
->first_unlinked
== win
) parent
->first_unlinked
= win
->next
;
131 /* link a window into the tree (or unlink it if the new parent is NULL) */
132 static void link_window( struct window
*win
, struct window
*parent
, struct window
*previous
)
134 unlink_window( win
); /* unlink it from the previous location */
138 win
->parent
= parent
;
139 if ((win
->prev
= previous
))
141 if ((win
->next
= previous
->next
)) win
->next
->prev
= win
;
142 else if (win
->parent
->last_child
== previous
) win
->parent
->last_child
= win
;
143 win
->prev
->next
= win
;
147 if ((win
->next
= parent
->first_child
)) win
->next
->prev
= win
;
148 else win
->parent
->last_child
= win
;
149 parent
->first_child
= win
;
152 else /* move it to parent unlinked list */
154 parent
= win
->parent
;
155 if ((win
->next
= parent
->first_unlinked
)) win
->next
->prev
= win
;
157 parent
->first_unlinked
= win
;
161 /* append a user handle to a handle array */
162 static int add_handle_to_array( struct user_handle_array
*array
, user_handle_t handle
)
164 if (array
->count
>= array
->total
)
166 int new_total
= max( array
->total
* 2, 32 );
167 user_handle_t
*new_array
= realloc( array
->handles
, new_total
* sizeof(*new_array
) );
170 free( array
->handles
);
171 set_error( STATUS_NO_MEMORY
);
174 array
->handles
= new_array
;
175 array
->total
= new_total
;
177 array
->handles
[array
->count
++] = handle
;
181 /* set a window property */
182 static void set_property( struct window
*win
, atom_t atom
, obj_handle_t handle
,
183 enum property_type type
)
186 struct property
*new_props
;
188 /* check if it exists already */
189 for (i
= 0; i
< win
->prop_inuse
; i
++)
191 if (win
->properties
[i
].type
== PROP_TYPE_FREE
)
196 if (win
->properties
[i
].atom
== atom
)
198 win
->properties
[i
].type
= type
;
199 win
->properties
[i
].handle
= handle
;
204 /* need to add an entry */
205 if (!grab_global_atom( atom
)) return;
209 if (win
->prop_inuse
>= win
->prop_alloc
)
211 /* need to grow the array */
212 if (!(new_props
= realloc( win
->properties
,
213 sizeof(*new_props
) * (win
->prop_alloc
+ 16) )))
215 set_error( STATUS_NO_MEMORY
);
216 release_global_atom( atom
);
219 win
->prop_alloc
+= 16;
220 win
->properties
= new_props
;
222 free
= win
->prop_inuse
++;
224 win
->properties
[free
].atom
= atom
;
225 win
->properties
[free
].type
= type
;
226 win
->properties
[free
].handle
= handle
;
229 /* remove a window property */
230 static obj_handle_t
remove_property( struct window
*win
, atom_t atom
)
234 for (i
= 0; i
< win
->prop_inuse
; i
++)
236 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
237 if (win
->properties
[i
].atom
== atom
)
239 release_global_atom( atom
);
240 win
->properties
[i
].type
= PROP_TYPE_FREE
;
241 return win
->properties
[i
].handle
;
244 /* FIXME: last error? */
248 /* find a window property */
249 static obj_handle_t
get_property( struct window
*win
, atom_t atom
)
253 for (i
= 0; i
< win
->prop_inuse
; i
++)
255 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
256 if (win
->properties
[i
].atom
== atom
) return win
->properties
[i
].handle
;
258 /* FIXME: last error? */
262 /* destroy all properties of a window */
263 inline static void destroy_properties( struct window
*win
)
267 if (!win
->properties
) return;
268 for (i
= 0; i
< win
->prop_inuse
; i
++)
270 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
271 release_global_atom( win
->properties
[i
].atom
);
273 free( win
->properties
);
276 /* destroy a window */
277 static void destroy_window( struct window
*win
)
279 assert( win
!= top_window
);
281 /* destroy all children */
282 while (win
->first_child
) destroy_window( win
->first_child
);
283 while (win
->first_unlinked
) destroy_window( win
->first_unlinked
);
285 if (win
->thread
->queue
)
287 if (win
->update_region
) inc_queue_paint_count( win
->thread
, -1 );
288 if (win
->paint_flags
& PAINT_INTERNAL
) inc_queue_paint_count( win
->thread
, -1 );
289 queue_cleanup_window( win
->thread
, win
->handle
);
291 /* reset global window pointers, if the corresponding window is destroyed */
292 if (win
== shell_window
) shell_window
= NULL
;
293 if (win
== shell_listview
) shell_listview
= NULL
;
294 if (win
== progman_window
) progman_window
= NULL
;
295 if (win
== taskman_window
) taskman_window
= NULL
;
296 free_user_handle( win
->handle
);
297 destroy_properties( win
);
298 unlink_window( win
);
299 if (win
->win_region
) free_region( win
->win_region
);
300 if (win
->update_region
) free_region( win
->update_region
);
301 release_class( win
->class );
302 if (win
->text
) free( win
->text
);
303 memset( win
, 0x55, sizeof(*win
) );
307 /* create a new window structure (note: the window is not linked in the window tree) */
308 static struct window
*create_window( struct window
*parent
, struct window
*owner
,
309 atom_t atom
, void *instance
)
313 struct window_class
*class = grab_class( current
->process
, atom
, instance
, &extra_bytes
);
315 if (!class) return NULL
;
317 win
= mem_alloc( sizeof(*win
) + extra_bytes
- 1 );
320 release_class( class );
324 if (!(win
->handle
= alloc_user_handle( win
, USER_WINDOW
)))
326 release_class( class );
330 win
->parent
= parent
;
331 win
->owner
= owner
? owner
->handle
: 0;
332 win
->first_child
= NULL
;
333 win
->last_child
= NULL
;
334 win
->first_unlinked
= NULL
;
335 win
->thread
= current
;
338 win
->last_active
= win
->handle
;
339 win
->win_region
= NULL
;
340 win
->update_region
= NULL
;
344 win
->instance
= NULL
;
345 win
->user_data
= NULL
;
347 win
->paint_flags
= 0;
350 win
->properties
= NULL
;
351 win
->nb_extra_bytes
= extra_bytes
;
352 memset( win
->extra_bytes
, 0, extra_bytes
);
354 if (parent
) /* put it on parent unlinked list */
356 if ((win
->next
= parent
->first_unlinked
)) win
->next
->prev
= win
;
358 parent
->first_unlinked
= win
;
360 else win
->next
= win
->prev
= NULL
;
362 /* if parent belongs to a different thread, attach the two threads */
363 if (parent
&& parent
->thread
&& parent
->thread
!= current
)
364 attach_thread_input( current
, parent
->thread
);
368 /* destroy all windows belonging to a given thread */
369 void destroy_thread_windows( struct thread
*thread
)
371 user_handle_t handle
= 0;
374 while ((win
= next_user_handle( &handle
, USER_WINDOW
)))
376 if (win
->thread
!= thread
) continue;
377 destroy_window( win
);
381 /* check whether child is a descendant of parent */
382 int is_child_window( user_handle_t parent
, user_handle_t child
)
384 struct window
*child_ptr
= get_user_object( child
, USER_WINDOW
);
385 struct window
*parent_ptr
= get_user_object( parent
, USER_WINDOW
);
387 if (!child_ptr
|| !parent_ptr
) return 0;
388 while (child_ptr
->parent
)
390 if (child_ptr
->parent
== parent_ptr
) return 1;
391 child_ptr
= child_ptr
->parent
;
396 /* check whether window is a top-level window */
397 int is_top_level_window( user_handle_t window
)
399 struct window
*win
= get_user_object( window
, USER_WINDOW
);
400 return (win
&& win
->parent
== top_window
);
403 /* make a window active if possible */
404 int make_window_active( user_handle_t window
)
406 struct window
*owner
, *win
= get_window( window
);
410 /* set last active for window and its owner */
411 win
->last_active
= win
->handle
;
412 if ((owner
= get_user_object( win
->owner
, USER_WINDOW
))) owner
->last_active
= win
->handle
;
416 /* increment (or decrement) the window paint count */
417 static inline void inc_window_paint_count( struct window
*win
, int incr
)
419 if (win
->thread
) inc_queue_paint_count( win
->thread
, incr
);
422 /* check if window and all its ancestors are visible */
423 static int is_visible( const struct window
*win
)
425 while (win
&& win
!= top_window
)
427 if (!(win
->style
& WS_VISIBLE
)) return 0;
429 /* if parent is minimized children are not visible */
430 if (win
&& (win
->style
& WS_MINIMIZE
)) return 0;
435 /* same as is_visible but takes a window handle */
436 int is_window_visible( user_handle_t window
)
438 struct window
*win
= get_user_object( window
, USER_WINDOW
);
440 return is_visible( win
);
443 /* check if point is inside the window */
444 static inline int is_point_in_window( struct window
*win
, int x
, int y
)
446 if (!(win
->style
& WS_VISIBLE
)) return 0; /* not visible */
447 if ((win
->style
& (WS_POPUP
|WS_CHILD
|WS_DISABLED
)) == (WS_CHILD
|WS_DISABLED
))
448 return 0; /* disabled child */
449 if ((win
->ex_style
& (WS_EX_LAYERED
|WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
|WS_EX_TRANSPARENT
))
450 return 0; /* transparent */
451 if (x
< win
->window_rect
.left
|| x
>= win
->window_rect
.right
||
452 y
< win
->window_rect
.top
|| y
>= win
->window_rect
.bottom
)
453 return 0; /* not in window */
454 if (win
->win_region
&&
455 !point_in_region( win
->win_region
, x
- win
->window_rect
.left
, y
- win
->window_rect
.top
))
456 return 0; /* not in window region */
460 /* find child of 'parent' that contains the given point (in parent-relative coords) */
461 static struct window
*child_window_from_point( struct window
*parent
, int x
, int y
)
465 for (ptr
= parent
->first_child
; ptr
; ptr
= ptr
->next
)
467 if (!is_point_in_window( ptr
, x
, y
)) continue; /* skip it */
469 /* if window is minimized or disabled, return at once */
470 if (ptr
->style
& (WS_MINIMIZE
|WS_DISABLED
)) return ptr
;
472 /* if point is not in client area, return at once */
473 if (x
< ptr
->client_rect
.left
|| x
>= ptr
->client_rect
.right
||
474 y
< ptr
->client_rect
.top
|| y
>= ptr
->client_rect
.bottom
)
477 return child_window_from_point( ptr
, x
- ptr
->client_rect
.left
, y
- ptr
->client_rect
.top
);
479 return parent
; /* not found any child */
482 /* find all children of 'parent' that contain the given point */
483 static int get_window_children_from_point( struct window
*parent
, int x
, int y
,
484 struct user_handle_array
*array
)
488 for (ptr
= parent
->first_child
; ptr
; ptr
= ptr
->next
)
490 if (!is_point_in_window( ptr
, x
, y
)) continue; /* skip it */
492 /* if point is in client area, and window is not minimized or disabled, check children */
493 if (!(ptr
->style
& (WS_MINIMIZE
|WS_DISABLED
)) &&
494 x
>= ptr
->client_rect
.left
&& x
< ptr
->client_rect
.right
&&
495 y
>= ptr
->client_rect
.top
&& y
< ptr
->client_rect
.bottom
)
497 if (!get_window_children_from_point( ptr
, x
- ptr
->client_rect
.left
,
498 y
- ptr
->client_rect
.top
, array
))
502 /* now add window to the array */
503 if (!add_handle_to_array( array
, ptr
->handle
)) return 0;
508 /* find window containing point (in absolute coords) */
509 user_handle_t
window_from_point( int x
, int y
)
513 if (!top_window
) return 0;
514 ret
= child_window_from_point( top_window
, x
, y
);
518 /* return list of all windows containing point (in absolute coords) */
519 static int all_windows_from_point( struct window
*top
, int x
, int y
, struct user_handle_array
*array
)
523 /* make point relative to top window */
524 for (ptr
= top
->parent
; ptr
&& ptr
!= top_window
; ptr
= ptr
->parent
)
526 x
-= ptr
->client_rect
.left
;
527 y
-= ptr
->client_rect
.top
;
530 if (!is_point_in_window( top
, x
, y
)) return 1;
532 /* if point is in client area, and window is not minimized or disabled, check children */
533 if (!(top
->style
& (WS_MINIMIZE
|WS_DISABLED
)) &&
534 x
>= top
->client_rect
.left
&& x
< top
->client_rect
.right
&&
535 y
>= top
->client_rect
.top
&& y
< top
->client_rect
.bottom
)
537 if (!get_window_children_from_point( top
, x
- top
->client_rect
.left
,
538 y
- top
->client_rect
.top
, array
))
541 /* now add window to the array */
542 if (!add_handle_to_array( array
, top
->handle
)) return 0;
547 /* return the thread owning a window */
548 struct thread
*get_window_thread( user_handle_t handle
)
550 struct window
*win
= get_user_object( handle
, USER_WINDOW
);
551 if (!win
|| !win
->thread
) return NULL
;
552 return (struct thread
*)grab_object( win
->thread
);
556 /* check if any area of a window needs repainting */
557 static inline int win_needs_repaint( struct window
*win
)
559 return win
->update_region
|| (win
->paint_flags
& PAINT_INTERNAL
);
563 /* find a child of the specified window that needs repainting */
564 static struct window
*find_child_to_repaint( struct window
*parent
, struct thread
*thread
)
566 struct window
*ptr
, *ret
= NULL
;
568 for (ptr
= parent
->first_child
; ptr
&& !ret
; ptr
= ptr
->next
)
570 if (!(ptr
->style
& WS_VISIBLE
)) continue;
571 if (ptr
->thread
== thread
&& win_needs_repaint( ptr
))
573 else if (!(ptr
->style
& WS_MINIMIZE
)) /* explore its children */
574 ret
= find_child_to_repaint( ptr
, thread
);
577 if (ret
&& (ret
->ex_style
& WS_EX_TRANSPARENT
))
579 /* transparent window, check for non-transparent sibling to paint first */
580 for (ptr
= ret
->next
; ptr
; ptr
= ptr
->next
)
582 if (!(ptr
->style
& WS_VISIBLE
)) continue;
583 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
584 if (ptr
->thread
!= thread
) continue;
585 if (win_needs_repaint( ptr
)) return ptr
;
592 /* find a window that needs to receive a WM_PAINT */
593 user_handle_t
find_window_to_repaint( user_handle_t parent
, struct thread
*thread
)
595 struct window
*ptr
, *win
= find_child_to_repaint( top_window
, thread
);
599 if (!parent
) return win
->handle
;
600 /* check that it is a child of the specified parent */
601 for (ptr
= win
; ptr
; ptr
= ptr
->parent
)
602 if (ptr
->handle
== parent
) return win
->handle
;
603 /* otherwise don't return any window, we don't repaint a child before its parent */
609 /* intersect the window region with the specified region, relative to the window parent */
610 static struct region
*intersect_window_region( struct region
*region
, struct window
*win
)
612 /* make region relative to window rect */
613 offset_region( region
, -win
->window_rect
.left
, -win
->window_rect
.top
);
614 if (!intersect_region( region
, region
, win
->win_region
)) return NULL
;
615 /* make region relative to parent again */
616 offset_region( region
, win
->window_rect
.left
, win
->window_rect
.top
);
621 /* clip all children of a given window out of the visible region */
622 static struct region
*clip_children( struct window
*parent
, struct window
*last
,
623 struct region
*region
, int offset_x
, int offset_y
)
626 struct region
*tmp
= create_empty_region();
628 if (!tmp
) return NULL
;
629 for (ptr
= parent
->first_child
; ptr
&& ptr
!= last
; ptr
= ptr
->next
)
631 if (!(ptr
->style
& WS_VISIBLE
)) continue;
632 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
633 set_region_rect( tmp
, &ptr
->window_rect
);
634 if (ptr
->win_region
&& !intersect_window_region( tmp
, ptr
))
639 offset_region( tmp
, offset_x
, offset_y
);
640 if (!(region
= subtract_region( region
, region
, tmp
))) break;
641 if (is_region_empty( region
)) break;
648 /* compute the visible region of a window */
649 static struct region
*get_visible_region( struct window
*win
, struct window
*top
,
652 struct region
*tmp
, *region
;
653 int offset_x
, offset_y
;
655 if (!(region
= create_empty_region())) return NULL
;
657 /* first check if all ancestors are visible */
659 if (!is_visible( win
)) return region
; /* empty region */
661 /* create a region relative to the window itself */
663 if ((flags
& DCX_PARENTCLIP
) && win
!= top
&& win
->parent
)
666 rect
.left
= rect
.top
= 0;
667 rect
.right
= win
->parent
->client_rect
.right
- win
->parent
->client_rect
.left
;
668 rect
.bottom
= win
->parent
->client_rect
.bottom
- win
->parent
->client_rect
.top
;
669 set_region_rect( region
, &rect
);
670 offset_x
= win
->client_rect
.left
;
671 offset_y
= win
->client_rect
.top
;
673 else if (flags
& DCX_WINDOW
)
675 set_region_rect( region
, &win
->window_rect
);
676 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
677 offset_x
= win
->window_rect
.left
;
678 offset_y
= win
->window_rect
.top
;
682 set_region_rect( region
, &win
->client_rect
);
683 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
684 offset_x
= win
->client_rect
.left
;
685 offset_y
= win
->client_rect
.top
;
687 offset_region( region
, -offset_x
, -offset_y
);
691 if (flags
& DCX_CLIPCHILDREN
)
693 if (!clip_children( win
, NULL
, region
,
694 offset_x
- win
->client_rect
.left
,
695 offset_y
- win
->client_rect
.top
)) goto error
;
698 /* clip siblings of ancestors */
700 if (top
&& top
!= win
&& (tmp
= create_empty_region()) != NULL
)
702 offset_region( region
, offset_x
, offset_y
); /* make it relative to parent */
703 while (win
!= top
&& win
->parent
)
705 if (win
->style
& WS_CLIPSIBLINGS
)
707 if (!clip_children( win
->parent
, win
, region
, 0, 0 )) goto error
;
708 if (is_region_empty( region
)) break;
710 /* clip to parent client area */
712 offset_x
+= win
->client_rect
.left
;
713 offset_y
+= win
->client_rect
.top
;
714 offset_region( region
, win
->client_rect
.left
, win
->client_rect
.top
);
715 set_region_rect( tmp
, &win
->client_rect
);
716 if (win
->win_region
&& !intersect_window_region( tmp
, win
))
721 if (!intersect_region( region
, region
, tmp
))
726 if (is_region_empty( region
)) break;
728 offset_region( region
, -offset_x
, -offset_y
); /* make it relative to target window again */
734 free_region( region
);
739 /* get the window class of a window */
740 struct window_class
* get_window_class( user_handle_t window
)
743 if (!(win
= get_window( window
))) return NULL
;
747 /* return a copy of the specified region cropped to the window client or frame rectangle, */
748 /* and converted from client to window coordinates. Helper for (in)validate_window. */
749 static struct region
*crop_region_to_win_rect( struct window
*win
, struct region
*region
, int frame
)
752 struct region
*tmp
= create_empty_region();
754 if (!tmp
) return NULL
;
756 /* get bounding rect in client coords */
759 rect
.left
= win
->window_rect
.left
- win
->client_rect
.left
;
760 rect
.top
= win
->window_rect
.top
- win
->client_rect
.top
;
761 rect
.right
= win
->window_rect
.right
- win
->client_rect
.left
;
762 rect
.bottom
= win
->window_rect
.bottom
- win
->client_rect
.top
;
768 rect
.right
= win
->client_rect
.right
- win
->client_rect
.left
;
769 rect
.bottom
= win
->client_rect
.bottom
- win
->client_rect
.top
;
771 set_region_rect( tmp
, &rect
);
773 /* intersect specified region with bounding rect */
774 if (region
&& !intersect_region( tmp
, region
, tmp
)) goto done
;
775 if (is_region_empty( tmp
)) goto done
;
777 /* map it to window coords */
778 offset_region( tmp
, win
->client_rect
.left
- win
->window_rect
.left
,
779 win
->client_rect
.top
- win
->window_rect
.top
);
788 /* set a region as new update region for the window */
789 static void set_update_region( struct window
*win
, struct region
*region
)
791 if (region
&& !is_region_empty( region
))
793 if (!win
->update_region
) inc_window_paint_count( win
, 1 );
794 else free_region( win
->update_region
);
795 win
->update_region
= region
;
799 if (win
->update_region
) inc_window_paint_count( win
, -1 );
800 win
->paint_flags
&= ~(PAINT_ERASE
| PAINT_NONCLIENT
);
801 win
->update_region
= NULL
;
802 if (region
) free_region( region
);
807 /* add a region to the update region; the passed region is freed or reused */
808 static int add_update_region( struct window
*win
, struct region
*region
)
810 if (win
->update_region
&& !union_region( region
, win
->update_region
, region
))
812 free_region( region
);
815 set_update_region( win
, region
);
820 /* validate the non client area of a window */
821 static void validate_non_client( struct window
*win
)
826 if (!win
->update_region
) return; /* nothing to do */
828 /* get client rect in window coords */
829 rect
.left
= win
->client_rect
.left
- win
->window_rect
.left
;
830 rect
.top
= win
->client_rect
.top
- win
->window_rect
.top
;
831 rect
.right
= win
->client_rect
.right
- win
->window_rect
.left
;
832 rect
.bottom
= win
->client_rect
.bottom
- win
->window_rect
.top
;
834 if ((tmp
= create_region( &rect
, 1 )))
836 if (intersect_region( tmp
, win
->update_region
, tmp
))
837 set_update_region( win
, tmp
);
841 win
->paint_flags
&= ~PAINT_NONCLIENT
;
845 /* validate a window completely so that we don't get any further paint messages for it */
846 static void validate_whole_window( struct window
*win
)
848 set_update_region( win
, NULL
);
850 if (win
->paint_flags
& PAINT_INTERNAL
)
852 win
->paint_flags
&= ~PAINT_INTERNAL
;
853 inc_window_paint_count( win
, -1 );
858 /* validate the update region of a window on all parents; helper for redraw_window */
859 static void validate_parents( struct window
*child
)
861 int offset_x
= 0, offset_y
= 0;
862 struct window
*win
= child
;
863 struct region
*tmp
= NULL
;
865 if (!child
->update_region
) return;
867 while (win
->parent
&& win
->parent
!= top_window
)
869 /* map to parent client coords */
870 offset_x
+= win
->window_rect
.left
;
871 offset_y
+= win
->window_rect
.top
;
875 /* and now map to window coords */
876 offset_x
+= win
->client_rect
.left
- win
->window_rect
.left
;
877 offset_y
+= win
->client_rect
.top
- win
->window_rect
.top
;
879 if (win
->update_region
&& !(win
->style
& WS_CLIPCHILDREN
))
881 if (!tmp
&& !(tmp
= create_empty_region())) return;
882 offset_region( child
->update_region
, offset_x
, offset_y
);
883 if (subtract_region( tmp
, win
->update_region
, child
->update_region
))
885 set_update_region( win
, tmp
);
888 /* restore child coords */
889 offset_region( child
->update_region
, -offset_x
, -offset_y
);
892 if (tmp
) free_region( tmp
);
896 /* add/subtract a region (in client coordinates) to the update region of the window */
897 static void redraw_window( struct window
*win
, struct region
*region
, int frame
, unsigned int flags
)
900 struct window
*child
;
902 if (flags
& RDW_INVALIDATE
)
904 if (!(tmp
= crop_region_to_win_rect( win
, region
, frame
))) return;
906 if (!add_update_region( win
, tmp
)) return;
908 if (flags
& RDW_FRAME
) win
->paint_flags
|= PAINT_NONCLIENT
;
909 if (flags
& RDW_ERASE
) win
->paint_flags
|= PAINT_ERASE
;
911 else if (flags
& RDW_VALIDATE
)
913 if (!region
&& (flags
& RDW_NOFRAME
)) /* shortcut: validate everything */
915 set_update_region( win
, NULL
);
917 else if (win
->update_region
)
919 if ((tmp
= crop_region_to_win_rect( win
, region
, frame
)))
921 if (!subtract_region( tmp
, win
->update_region
, tmp
))
926 set_update_region( win
, tmp
);
928 if (flags
& RDW_NOFRAME
) validate_non_client( win
);
929 if (flags
& RDW_NOERASE
) win
->paint_flags
&= ~PAINT_ERASE
;
933 if ((flags
& RDW_INTERNALPAINT
) && !(win
->paint_flags
& PAINT_INTERNAL
))
935 win
->paint_flags
|= PAINT_INTERNAL
;
936 inc_window_paint_count( win
, 1 );
938 else if ((flags
& RDW_NOINTERNALPAINT
) && (win
->paint_flags
& PAINT_INTERNAL
))
940 win
->paint_flags
&= ~PAINT_INTERNAL
;
941 inc_window_paint_count( win
, -1 );
944 if (flags
& RDW_UPDATENOW
)
946 validate_parents( win
);
947 flags
&= ~RDW_UPDATENOW
;
950 /* now process children recursively */
952 if (flags
& RDW_NOCHILDREN
) return;
953 if (win
->style
& WS_MINIMIZE
) return;
954 if ((win
->style
& WS_CLIPCHILDREN
) && !(flags
& RDW_ALLCHILDREN
)) return;
956 if (!(tmp
= crop_region_to_win_rect( win
, region
, 0 ))) return;
958 /* map to client coordinates */
959 offset_region( tmp
, win
->window_rect
.left
- win
->client_rect
.left
,
960 win
->window_rect
.top
- win
->client_rect
.top
);
962 if (flags
& RDW_INVALIDATE
) flags
|= RDW_FRAME
| RDW_ERASE
;
964 for (child
= win
->first_child
; child
; child
= child
->next
)
966 if (!(child
->style
& WS_VISIBLE
)) continue;
967 if (!rect_in_region( tmp
, &child
->window_rect
)) continue;
968 offset_region( tmp
, -child
->client_rect
.left
, -child
->client_rect
.top
);
969 redraw_window( child
, tmp
, 1, flags
);
970 offset_region( tmp
, child
->client_rect
.left
, child
->client_rect
.top
);
976 /* retrieve the update flags for a window depending on the state of the update region */
977 static unsigned int get_update_flags( struct window
*win
, unsigned int flags
)
979 unsigned int ret
= 0;
981 if (flags
& UPDATE_NONCLIENT
)
983 if ((win
->paint_flags
& PAINT_NONCLIENT
) && win
->update_region
) ret
|= UPDATE_NONCLIENT
;
985 if (flags
& UPDATE_ERASE
)
987 if ((win
->paint_flags
& PAINT_ERASE
) && win
->update_region
) ret
|= UPDATE_ERASE
;
989 if (flags
& UPDATE_PAINT
)
991 if (win
->update_region
) ret
|= UPDATE_PAINT
;
993 if (flags
& UPDATE_INTERNALPAINT
)
995 if (win
->paint_flags
& PAINT_INTERNAL
) ret
|= UPDATE_INTERNALPAINT
;
1001 /* iterate through the children of the given window until we find one with some update flags */
1002 static unsigned int get_child_update_flags( struct window
*win
, unsigned int flags
,
1003 struct window
**child
)
1006 unsigned int ret
= 0;
1008 for (ptr
= win
->first_child
; ptr
&& !ret
; ptr
= ptr
->next
)
1010 if (!(ptr
->style
& WS_VISIBLE
)) continue;
1011 if ((ret
= get_update_flags( ptr
, flags
)) != 0)
1016 if (ptr
->style
& WS_MINIMIZE
) continue;
1018 /* Note: the WS_CLIPCHILDREN test is the opposite of the invalidation case,
1019 * here we only want to repaint children of windows that clip them, others
1020 * need to wait for WM_PAINT to be done in the parent first.
1022 if (!(flags
& UPDATE_NOCHILDREN
) &&
1023 ((flags
& UPDATE_ALLCHILDREN
) || (ptr
->style
& WS_CLIPCHILDREN
)))
1024 ret
= get_child_update_flags( ptr
, flags
, child
);
1030 /* expose a region of a window, looking for the top most parent that needs to be exposed */
1031 /* the region is in window coordinates */
1032 static void expose_window( struct window
*win
, struct window
*top
, struct region
*region
)
1034 struct window
*parent
, *ptr
;
1035 int offset_x
, offset_y
;
1037 /* find the top most parent that doesn't clip either siblings or children */
1038 for (parent
= ptr
= win
; ptr
!= top
; ptr
= ptr
->parent
)
1040 if (!(ptr
->style
& WS_CLIPCHILDREN
)) parent
= ptr
;
1041 if (!(ptr
->style
& WS_CLIPSIBLINGS
)) parent
= ptr
->parent
;
1043 if (parent
== win
&& parent
!= top
&& win
->parent
)
1044 parent
= win
->parent
; /* always go up at least one level if possible */
1046 offset_x
= win
->window_rect
.left
- win
->client_rect
.left
;
1047 offset_y
= win
->window_rect
.top
- win
->client_rect
.top
;
1048 for (ptr
= win
; ptr
!= parent
; ptr
= ptr
->parent
)
1050 offset_x
+= ptr
->client_rect
.left
;
1051 offset_y
+= ptr
->client_rect
.top
;
1053 offset_region( region
, offset_x
, offset_y
);
1054 redraw_window( parent
, region
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1055 offset_region( region
, -offset_x
, -offset_y
);
1059 /* validate that the specified window and client rects are valid */
1060 static int validate_window_rectangles( const rectangle_t
*window_rect
, const rectangle_t
*client_rect
)
1062 /* rectangles must be ordered properly */
1063 if (window_rect
->right
< window_rect
->left
) return 0;
1064 if (window_rect
->bottom
< window_rect
->top
) return 0;
1065 if (client_rect
->right
< client_rect
->left
) return 0;
1066 if (client_rect
->bottom
< client_rect
->top
) return 0;
1067 /* client rect must be inside window rect */
1068 if (client_rect
->left
< window_rect
->left
) return 0;
1069 if (client_rect
->right
> window_rect
->right
) return 0;
1070 if (client_rect
->top
< window_rect
->top
) return 0;
1071 if (client_rect
->bottom
> window_rect
->bottom
) return 0;
1076 /* set the window and client rectangles, updating the update region if necessary */
1077 static void set_window_pos( struct window
*win
, struct window
*top
, struct window
*previous
,
1078 unsigned int swp_flags
, unsigned int wvr_flags
,
1079 const rectangle_t
*window_rect
, const rectangle_t
*client_rect
)
1081 struct region
*old_vis_rgn
, *new_vis_rgn
;
1082 const rectangle_t old_window_rect
= win
->window_rect
;
1083 const rectangle_t old_client_rect
= win
->client_rect
;
1085 /* if the window is not visible, everything is easy */
1087 if ((win
->parent
&& !is_visible( win
->parent
)) ||
1088 (!(win
->style
& WS_VISIBLE
) && !(swp_flags
& SWP_SHOWWINDOW
)))
1090 win
->window_rect
= *window_rect
;
1091 win
->client_rect
= *client_rect
;
1092 if (!(swp_flags
& SWP_NOZORDER
)) link_window( win
, win
->parent
, previous
);
1093 if (swp_flags
& SWP_SHOWWINDOW
) win
->style
|= WS_VISIBLE
;
1094 else if (swp_flags
& SWP_HIDEWINDOW
) win
->style
&= ~WS_VISIBLE
;
1098 if (!(old_vis_rgn
= get_visible_region( win
, top
, DCX_WINDOW
))) return;
1100 /* set the new window info before invalidating anything */
1102 win
->window_rect
= *window_rect
;
1103 win
->client_rect
= *client_rect
;
1104 if (!(swp_flags
& SWP_NOZORDER
)) link_window( win
, win
->parent
, previous
);
1105 if (swp_flags
& SWP_SHOWWINDOW
) win
->style
|= WS_VISIBLE
;
1106 else if (swp_flags
& SWP_HIDEWINDOW
) win
->style
&= ~WS_VISIBLE
;
1108 if (!(new_vis_rgn
= get_visible_region( win
, top
, DCX_WINDOW
)))
1110 free_region( old_vis_rgn
);
1111 clear_error(); /* ignore error since the window info has been modified already */
1115 /* expose anything revealed by the change */
1117 offset_region( old_vis_rgn
, old_window_rect
.left
- window_rect
->left
,
1118 old_window_rect
.top
- window_rect
->top
);
1119 if (xor_region( new_vis_rgn
, old_vis_rgn
, new_vis_rgn
)) expose_window( win
, top
, new_vis_rgn
);
1120 free_region( old_vis_rgn
);
1122 if (!(win
->style
& WS_VISIBLE
))
1124 /* clear the update region since the window is no longer visible */
1125 validate_whole_window( win
);
1129 /* expose the whole non-client area if it changed in any way */
1131 if ((swp_flags
& SWP_FRAMECHANGED
) ||
1132 memcmp( window_rect
, &old_window_rect
, sizeof(old_window_rect
) ) ||
1133 memcmp( client_rect
, &old_client_rect
, sizeof(old_client_rect
) ))
1135 struct region
*tmp
= create_region( client_rect
, 1 );
1139 set_region_rect( new_vis_rgn
, window_rect
);
1140 if (subtract_region( tmp
, new_vis_rgn
, tmp
))
1142 offset_region( tmp
, -window_rect
->left
, -window_rect
->top
);
1143 add_update_region( win
, tmp
);
1145 else free_region( tmp
);
1149 /* expose/validate new client areas + children */
1151 /* FIXME: expose everything for now */
1152 if (memcmp( client_rect
, &old_client_rect
, sizeof(old_client_rect
) ))
1153 redraw_window( win
, 0, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
1156 free_region( new_vis_rgn
);
1157 clear_error(); /* we ignore out of memory errors once the new rects have been set */
1161 /* create a window */
1162 DECL_HANDLER(create_window
)
1167 if (!req
->parent
) /* return desktop window */
1171 if (!(top_window
= create_window( NULL
, NULL
, req
->atom
, req
->instance
))) return;
1172 top_window
->thread
= NULL
; /* no thread owns the desktop */
1173 top_window
->style
= WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
1179 struct window
*parent
, *owner
= NULL
;
1181 if (!(parent
= get_window( req
->parent
))) return;
1182 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
1183 if (owner
== top_window
) owner
= NULL
;
1184 else if (owner
&& parent
!= top_window
)
1186 /* an owned window must be created as top-level */
1187 set_error( STATUS_ACCESS_DENIED
);
1190 if (!(win
= create_window( parent
, owner
, req
->atom
, req
->instance
))) return;
1192 reply
->handle
= win
->handle
;
1193 reply
->extra
= win
->nb_extra_bytes
;
1194 reply
->class_ptr
= get_class_client_ptr( win
->class );
1198 /* link a window into the tree */
1199 DECL_HANDLER(link_window
)
1201 struct window
*win
, *parent
= NULL
, *previous
= NULL
;
1203 if (!(win
= get_window( req
->handle
))) return;
1204 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
1206 if (win
== top_window
)
1208 set_error( STATUS_INVALID_PARAMETER
);
1211 reply
->full_parent
= parent
? parent
->handle
: 0;
1212 if (parent
&& req
->previous
)
1214 if (req
->previous
== (user_handle_t
)1) /* special case: HWND_BOTTOM */
1216 previous
= parent
->last_child
;
1217 if (previous
== win
) return; /* nothing to do */
1221 if (!(previous
= get_window( req
->previous
))) return;
1222 /* previous must be a child of parent, and not win itself */
1223 if (previous
->parent
!= parent
|| previous
== win
)
1225 set_error( STATUS_INVALID_PARAMETER
);
1230 link_window( win
, parent
, previous
);
1234 /* destroy a window */
1235 DECL_HANDLER(destroy_window
)
1237 struct window
*win
= get_window( req
->handle
);
1240 if (win
!= top_window
) destroy_window( win
);
1241 else set_error( STATUS_ACCESS_DENIED
);
1246 /* set a window owner */
1247 DECL_HANDLER(set_window_owner
)
1249 struct window
*win
= get_window( req
->handle
);
1250 struct window
*owner
= NULL
;
1253 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
1254 if (win
== top_window
)
1256 set_error( STATUS_ACCESS_DENIED
);
1259 reply
->prev_owner
= win
->owner
;
1260 reply
->full_owner
= win
->owner
= owner
? owner
->handle
: 0;
1264 /* get information from a window handle */
1265 DECL_HANDLER(get_window_info
)
1267 struct window
*win
= get_window( req
->handle
);
1269 reply
->full_handle
= 0;
1270 reply
->tid
= reply
->pid
= 0;
1273 reply
->full_handle
= win
->handle
;
1274 reply
->last_active
= win
->handle
;
1275 if (get_user_object( win
->last_active
, USER_WINDOW
)) reply
->last_active
= win
->last_active
;
1278 reply
->tid
= get_thread_id( win
->thread
);
1279 reply
->pid
= get_process_id( win
->thread
->process
);
1280 reply
->atom
= get_class_atom( win
->class );
1286 /* set some information in a window */
1287 DECL_HANDLER(set_window_info
)
1289 struct window
*win
= get_window( req
->handle
);
1292 if (req
->flags
&& win
== top_window
)
1294 set_error( STATUS_ACCESS_DENIED
);
1297 if (req
->extra_size
> sizeof(req
->extra_value
) ||
1298 req
->extra_offset
< -1 ||
1299 req
->extra_offset
> win
->nb_extra_bytes
- (int)req
->extra_size
)
1301 set_win32_error( ERROR_INVALID_INDEX
);
1304 if (req
->extra_offset
!= -1)
1306 memcpy( &reply
->old_extra_value
, win
->extra_bytes
+ req
->extra_offset
, req
->extra_size
);
1308 else if (req
->flags
& SET_WIN_EXTRA
)
1310 set_win32_error( ERROR_INVALID_INDEX
);
1313 reply
->old_style
= win
->style
;
1314 reply
->old_ex_style
= win
->ex_style
;
1315 reply
->old_id
= win
->id
;
1316 reply
->old_instance
= win
->instance
;
1317 reply
->old_user_data
= win
->user_data
;
1318 if (req
->flags
& SET_WIN_STYLE
) win
->style
= req
->style
;
1319 if (req
->flags
& SET_WIN_EXSTYLE
) win
->ex_style
= req
->ex_style
;
1320 if (req
->flags
& SET_WIN_ID
) win
->id
= req
->id
;
1321 if (req
->flags
& SET_WIN_INSTANCE
) win
->instance
= req
->instance
;
1322 if (req
->flags
& SET_WIN_USERDATA
) win
->user_data
= req
->user_data
;
1323 if (req
->flags
& SET_WIN_EXTRA
) memcpy( win
->extra_bytes
+ req
->extra_offset
,
1324 &req
->extra_value
, req
->extra_size
);
1326 /* changing window style triggers a non-client paint */
1327 if (req
->flags
& SET_WIN_STYLE
) win
->paint_flags
|= PAINT_NONCLIENT
;
1331 /* get a list of the window parents, up to the root of the tree */
1332 DECL_HANDLER(get_window_parents
)
1334 struct window
*ptr
, *win
= get_window( req
->handle
);
1336 user_handle_t
*data
;
1339 if (win
) for (ptr
= win
->parent
; ptr
; ptr
= ptr
->parent
) total
++;
1341 reply
->count
= total
;
1342 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
1343 if (len
&& ((data
= set_reply_data_size( len
))))
1345 for (ptr
= win
->parent
; ptr
&& len
; ptr
= ptr
->parent
, len
-= sizeof(*data
))
1346 *data
++ = ptr
->handle
;
1351 /* get a list of the window children */
1352 DECL_HANDLER(get_window_children
)
1354 struct window
*ptr
, *parent
= get_window( req
->parent
);
1356 user_handle_t
*data
;
1360 for (ptr
= parent
->first_child
, total
= 0; ptr
; ptr
= ptr
->next
)
1362 if (req
->atom
&& get_class_atom(ptr
->class) != req
->atom
) continue;
1363 if (req
->tid
&& get_thread_id(ptr
->thread
) != req
->tid
) continue;
1367 reply
->count
= total
;
1368 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
1369 if (len
&& ((data
= set_reply_data_size( len
))))
1371 for (ptr
= parent
->first_child
; ptr
&& len
; ptr
= ptr
->next
)
1373 if (req
->atom
&& get_class_atom(ptr
->class) != req
->atom
) continue;
1374 if (req
->tid
&& get_thread_id(ptr
->thread
) != req
->tid
) continue;
1375 *data
++ = ptr
->handle
;
1376 len
-= sizeof(*data
);
1382 /* get a list of the window children that contain a given point */
1383 DECL_HANDLER(get_window_children_from_point
)
1385 struct user_handle_array array
;
1386 struct window
*parent
= get_window( req
->parent
);
1389 if (!parent
) return;
1391 array
.handles
= NULL
;
1394 if (!all_windows_from_point( parent
, req
->x
, req
->y
, &array
)) return;
1396 reply
->count
= array
.count
;
1397 len
= min( get_reply_max_size(), array
.count
* sizeof(user_handle_t
) );
1398 if (len
) set_reply_data_ptr( array
.handles
, len
);
1399 else free( array
.handles
);
1403 /* get window tree information from a window handle */
1404 DECL_HANDLER(get_window_tree
)
1406 struct window
*win
= get_window( req
->handle
);
1412 struct window
*parent
= win
->parent
;
1413 reply
->parent
= parent
->handle
;
1414 reply
->owner
= win
->owner
;
1415 reply
->next_sibling
= win
->next
? win
->next
->handle
: 0;
1416 reply
->prev_sibling
= win
->prev
? win
->prev
->handle
: 0;
1417 reply
->first_sibling
= parent
->first_child
? parent
->first_child
->handle
: 0;
1418 reply
->last_sibling
= parent
->last_child
? parent
->last_child
->handle
: 0;
1424 reply
->next_sibling
= 0;
1425 reply
->prev_sibling
= 0;
1426 reply
->first_sibling
= 0;
1427 reply
->last_sibling
= 0;
1429 reply
->first_child
= win
->first_child
? win
->first_child
->handle
: 0;
1430 reply
->last_child
= win
->last_child
? win
->last_child
->handle
: 0;
1434 /* set the position and Z order of a window */
1435 DECL_HANDLER(set_window_pos
)
1437 struct window
*previous
= NULL
;
1438 struct window
*top
= top_window
;
1439 struct window
*win
= get_window( req
->handle
);
1440 unsigned int flags
= req
->flags
;
1443 if (!win
->parent
) flags
|= SWP_NOZORDER
; /* no Z order for the desktop */
1447 if (!(top
= get_window( req
->top_win
))) return;
1450 if (!(flags
& SWP_NOZORDER
))
1452 if (!req
->previous
) /* special case: HWND_TOP */
1454 if (win
->parent
->first_child
== win
) flags
|= SWP_NOZORDER
;
1456 else if (req
->previous
== (user_handle_t
)1) /* special case: HWND_BOTTOM */
1458 previous
= win
->parent
->last_child
;
1462 if (!(previous
= get_window( req
->previous
))) return;
1463 /* previous must be a sibling */
1464 if (previous
->parent
!= win
->parent
)
1466 set_error( STATUS_INVALID_PARAMETER
);
1470 if (previous
== win
) flags
|= SWP_NOZORDER
; /* nothing to do */
1473 if (!validate_window_rectangles( &req
->window
, &req
->client
))
1475 set_error( STATUS_INVALID_PARAMETER
);
1479 set_window_pos( win
, top
, previous
, flags
, req
->redraw_flags
, &req
->window
, &req
->client
);
1480 reply
->new_style
= win
->style
;
1484 /* get the window and client rectangles of a window */
1485 DECL_HANDLER(get_window_rectangles
)
1487 struct window
*win
= get_window( req
->handle
);
1491 reply
->window
= win
->window_rect
;
1492 reply
->client
= win
->client_rect
;
1497 /* get the window text */
1498 DECL_HANDLER(get_window_text
)
1500 struct window
*win
= get_window( req
->handle
);
1502 if (win
&& win
->text
)
1504 size_t len
= strlenW( win
->text
) * sizeof(WCHAR
);
1505 if (len
> get_reply_max_size()) len
= get_reply_max_size();
1506 set_reply_data( win
->text
, len
);
1511 /* set the window text */
1512 DECL_HANDLER(set_window_text
)
1514 struct window
*win
= get_window( req
->handle
);
1519 size_t len
= get_req_data_size() / sizeof(WCHAR
);
1522 if (!(text
= mem_alloc( (len
+1) * sizeof(WCHAR
) ))) return;
1523 memcpy( text
, get_req_data(), len
* sizeof(WCHAR
) );
1526 if (win
->text
) free( win
->text
);
1532 /* get the coordinates offset between two windows */
1533 DECL_HANDLER(get_windows_offset
)
1537 reply
->x
= reply
->y
= 0;
1540 if (!(win
= get_window( req
->from
))) return;
1543 reply
->x
+= win
->client_rect
.left
;
1544 reply
->y
+= win
->client_rect
.top
;
1550 if (!(win
= get_window( req
->to
))) return;
1553 reply
->x
-= win
->client_rect
.left
;
1554 reply
->y
-= win
->client_rect
.top
;
1561 /* get the visible region of a window */
1562 DECL_HANDLER(get_visible_region
)
1564 struct region
*region
;
1565 struct window
*win
= get_window( req
->window
);
1566 struct window
*top
= NULL
;
1569 if (req
->top_win
&& !(top
= get_window( req
->top_win
))) return;
1571 if ((region
= get_visible_region( win
, top
, req
->flags
)))
1573 rectangle_t
*data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
1574 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
1579 /* get the window region */
1580 DECL_HANDLER(get_window_region
)
1582 struct window
*win
= get_window( req
->window
);
1586 if (win
->win_region
)
1588 rectangle_t
*data
= get_region_data( win
->win_region
, get_reply_max_size(), &reply
->total_size
);
1589 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
1594 /* set the window region */
1595 DECL_HANDLER(set_window_region
)
1597 struct region
*region
= NULL
;
1598 struct window
*win
= get_window( req
->window
);
1602 if (get_req_data_size()) /* no data means remove the region completely */
1604 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
1607 if (win
->win_region
) free_region( win
->win_region
);
1608 win
->win_region
= region
;
1612 /* get a window update region */
1613 DECL_HANDLER(get_update_region
)
1616 unsigned int flags
= req
->flags
;
1617 struct window
*win
= get_window( req
->window
);
1620 if (!win
|| !is_visible( win
)) return;
1622 if ((flags
& UPDATE_NONCLIENT
) && !(flags
& (UPDATE_PAINT
|UPDATE_INTERNALPAINT
)))
1624 /* non-client painting must be delayed if one of the parents is going to
1625 * be repainted and doesn't clip children */
1628 for (ptr
= win
->parent
; ptr
&& ptr
!= top_window
; ptr
= ptr
->parent
)
1630 if (!(ptr
->style
& WS_CLIPCHILDREN
) && win_needs_repaint( ptr
))
1635 if (!(reply
->flags
= get_update_flags( win
, flags
)))
1637 /* if window doesn't need any repaint, check the children */
1638 if (!(flags
& UPDATE_NOCHILDREN
) &&
1639 ((flags
& UPDATE_ALLCHILDREN
) || (win
->style
& WS_CLIPCHILDREN
)))
1641 reply
->flags
= get_child_update_flags( win
, flags
, &win
);
1645 reply
->child
= win
->handle
;
1647 if (flags
& UPDATE_NOREGION
) return;
1649 if (win
->update_region
)
1651 if (!(data
= get_region_data( win
->update_region
, get_reply_max_size(),
1652 &reply
->total_size
))) return;
1653 set_reply_data_ptr( data
, reply
->total_size
);
1656 if (reply
->flags
& (UPDATE_PAINT
|UPDATE_INTERNALPAINT
)) /* validate everything */
1658 validate_whole_window( win
);
1662 if (reply
->flags
& UPDATE_NONCLIENT
) validate_non_client( win
);
1663 if (reply
->flags
& UPDATE_ERASE
)
1665 win
->paint_flags
&= ~PAINT_ERASE
;
1666 /* desktop window only gets erased, not repainted */
1667 if (win
== top_window
) validate_whole_window( win
);
1673 /* mark parts of a window as needing a redraw */
1674 DECL_HANDLER(redraw_window
)
1676 struct region
*region
= NULL
;
1677 struct window
*win
= get_window( req
->window
);
1680 if (!is_visible( win
)) return; /* nothing to do */
1682 if (req
->flags
& (RDW_VALIDATE
|RDW_INVALIDATE
))
1684 if (get_req_data_size()) /* no data means whole rectangle */
1686 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
1691 redraw_window( win
, region
, (req
->flags
& RDW_INVALIDATE
) && (req
->flags
& RDW_FRAME
),
1693 if (region
) free_region( region
);
1697 /* set a window property */
1698 DECL_HANDLER(set_window_property
)
1700 struct window
*win
= get_window( req
->window
);
1702 if (win
) set_property( win
, req
->atom
, req
->handle
,
1703 req
->string
? PROP_TYPE_STRING
: PROP_TYPE_ATOM
);
1707 /* remove a window property */
1708 DECL_HANDLER(remove_window_property
)
1710 struct window
*win
= get_window( req
->window
);
1712 if (win
) reply
->handle
= remove_property( win
, req
->atom
);
1716 /* get a window property */
1717 DECL_HANDLER(get_window_property
)
1719 struct window
*win
= get_window( req
->window
);
1721 if (win
) reply
->handle
= get_property( win
, req
->atom
);
1725 /* get the list of properties of a window */
1726 DECL_HANDLER(get_window_properties
)
1728 property_data_t
*data
;
1729 int i
, count
, max
= get_reply_max_size() / sizeof(*data
);
1730 struct window
*win
= get_window( req
->window
);
1735 for (i
= count
= 0; i
< win
->prop_inuse
; i
++)
1736 if (win
->properties
[i
].type
!= PROP_TYPE_FREE
) count
++;
1737 reply
->total
= count
;
1739 if (count
> max
) count
= max
;
1740 if (!count
|| !(data
= set_reply_data_size( count
* sizeof(*data
) ))) return;
1742 for (i
= 0; i
< win
->prop_inuse
&& count
; i
++)
1744 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
1745 data
->atom
= win
->properties
[i
].atom
;
1746 data
->string
= (win
->properties
[i
].type
== PROP_TYPE_STRING
);
1747 data
->handle
= win
->properties
[i
].handle
;
1754 /* get the new window pointer for a global window, checking permissions */
1755 /* helper for set_global_windows request */
1756 static int get_new_global_window( struct window
**win
, user_handle_t handle
)
1765 set_error( STATUS_ACCESS_DENIED
);
1768 *win
= get_window( handle
);
1769 return (*win
!= NULL
);
1772 /* Set/get the global windows */
1773 DECL_HANDLER(set_global_windows
)
1775 struct window
*new_shell_window
= shell_window
;
1776 struct window
*new_shell_listview
= shell_listview
;
1777 struct window
*new_progman_window
= progman_window
;
1778 struct window
*new_taskman_window
= taskman_window
;
1780 reply
->old_shell_window
= shell_window
? shell_window
->handle
: 0;
1781 reply
->old_shell_listview
= shell_listview
? shell_listview
->handle
: 0;
1782 reply
->old_progman_window
= progman_window
? progman_window
->handle
: 0;
1783 reply
->old_taskman_window
= taskman_window
? taskman_window
->handle
: 0;
1785 if (req
->flags
& SET_GLOBAL_SHELL_WINDOWS
)
1787 if (!get_new_global_window( &new_shell_window
, req
->shell_window
)) return;
1788 if (!get_new_global_window( &new_shell_listview
, req
->shell_listview
)) return;
1790 if (req
->flags
& SET_GLOBAL_PROGMAN_WINDOW
)
1792 if (!get_new_global_window( &new_progman_window
, req
->progman_window
)) return;
1794 if (req
->flags
& SET_GLOBAL_TASKMAN_WINDOW
)
1796 if (!get_new_global_window( &new_taskman_window
, req
->taskman_window
)) return;
1798 shell_window
= new_shell_window
;
1799 shell_listview
= new_shell_listview
;
1800 progman_window
= new_progman_window
;
1801 taskman_window
= new_taskman_window
;