Use IsWindowVisible instead of GetWindowLong(GWL_STYLE) & WS_VISIBLE
[wine.git] / server / window.c
blob88dfe8fb2cf1cba4782dd7f8cf0ada0025497215
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
32 #include "object.h"
33 #include "request.h"
34 #include "thread.h"
35 #include "process.h"
36 #include "user.h"
37 #include "unicode.h"
39 /* a window property */
40 struct 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) */
47 enum property_type
49 PROP_TYPE_FREE, /* free entry */
50 PROP_TYPE_STRING, /* atom that was originally a string */
51 PROP_TYPE_ATOM /* plain atom */
55 struct window
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;
95 int count;
96 int total;
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 );
112 return ret;
115 /* unlink a window from the tree */
116 static void unlink_window( struct window *win )
118 struct window *parent = win->parent;
120 assert( 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 */
136 if (parent)
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;
145 else
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;
156 win->prev = NULL;
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) );
168 if (!new_array)
170 free( array->handles );
171 set_error( STATUS_NO_MEMORY );
172 return 0;
174 array->handles = new_array;
175 array->total = new_total;
177 array->handles[array->count++] = handle;
178 return 1;
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 )
185 int i, free = -1;
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)
193 free = i;
194 continue;
196 if (win->properties[i].atom == atom)
198 win->properties[i].type = type;
199 win->properties[i].handle = handle;
200 return;
204 /* need to add an entry */
205 if (!grab_global_atom( atom )) return;
206 if (free == -1)
208 /* no free entry */
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 );
217 return;
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 )
232 int i;
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? */
245 return 0;
248 /* find a window property */
249 static obj_handle_t get_property( struct window *win, atom_t atom )
251 int i;
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? */
259 return 0;
262 /* destroy all properties of a window */
263 inline static void destroy_properties( struct window *win )
265 int i;
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) + win->nb_extra_bytes - 1 );
304 free( 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 )
311 int extra_bytes;
312 struct window *win;
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 );
318 if (!win)
320 release_class( class );
321 return NULL;
324 if (!(win->handle = alloc_user_handle( win, USER_WINDOW )))
326 release_class( class );
327 free( win );
328 return NULL;
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;
336 win->class = class;
337 win->atom = atom;
338 win->last_active = win->handle;
339 win->win_region = NULL;
340 win->update_region = NULL;
341 win->style = 0;
342 win->ex_style = 0;
343 win->id = 0;
344 win->instance = NULL;
345 win->user_data = NULL;
346 win->text = NULL;
347 win->paint_flags = 0;
348 win->prop_inuse = 0;
349 win->prop_alloc = 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;
357 win->prev = NULL;
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 );
365 return win;
368 /* destroy all windows belonging to a given thread */
369 void destroy_thread_windows( struct thread *thread )
371 user_handle_t handle = 0;
372 struct window *win;
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;
393 return 0;
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 );
408 if (!win) return 0;
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;
413 return 1;
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;
428 win = win->parent;
429 /* if parent is minimized children are not visible */
430 if (win && (win->style & WS_MINIMIZE)) return 0;
432 return 1;
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 );
439 if (!win) return 0;
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 */
457 return 1;
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 )
463 struct window *ptr;
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)
475 return ptr;
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 )
486 struct window *ptr;
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 ))
499 return 0;
502 /* now add window to the array */
503 if (!add_handle_to_array( array, ptr->handle )) return 0;
505 return 1;
508 /* find window containing point (in absolute coords) */
509 user_handle_t window_from_point( int x, int y )
511 struct window *ret;
513 if (!top_window) return 0;
514 ret = child_window_from_point( top_window, x, y );
515 return ret->handle;
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 )
521 struct window *ptr;
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 ))
539 return 0;
541 /* now add window to the array */
542 if (!add_handle_to_array( array, top->handle )) return 0;
543 return 1;
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 ))
572 ret = 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;
588 return ret;
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 );
597 if (win)
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 */
605 return 0;
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 );
617 return region;
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 )
625 struct window *ptr;
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 ))
636 free_region( tmp );
637 return NULL;
639 offset_region( tmp, offset_x, offset_y );
640 if (!(region = subtract_region( region, region, tmp ))) break;
641 if (is_region_empty( region )) break;
643 free_region( tmp );
644 return region;
648 /* set the region to the client rect clipped by the window rect, in parent-relative coordinates */
649 static void set_region_client_rect( struct region *region, struct window *win )
651 rectangle_t rect;
653 rect.left = max( win->window_rect.left, win->client_rect.left );
654 rect.top = max( win->window_rect.top, win->client_rect.top );
655 rect.right = min( win->window_rect.right, win->client_rect.right );
656 rect.bottom = min( win->window_rect.bottom, win->client_rect.bottom );
657 set_region_rect( region, &rect );
661 /* compute the visible region of a window */
662 static struct region *get_visible_region( struct window *win, struct window *top,
663 unsigned int flags )
665 struct region *tmp, *region;
666 int offset_x, offset_y;
668 if (!(region = create_empty_region())) return NULL;
670 /* first check if all ancestors are visible */
672 if (!is_visible( win )) return region; /* empty region */
674 /* create a region relative to the window itself */
676 if ((flags & DCX_PARENTCLIP) && win != top && win->parent)
678 set_region_client_rect( region, win->parent );
679 offset_region( region, -win->parent->client_rect.left, -win->parent->client_rect.top );
680 offset_x = win->client_rect.left;
681 offset_y = win->client_rect.top;
683 else if (flags & DCX_WINDOW)
685 set_region_rect( region, &win->window_rect );
686 if (win->win_region && !intersect_window_region( region, win )) goto error;
687 offset_x = win->window_rect.left;
688 offset_y = win->window_rect.top;
690 else
692 set_region_client_rect( region, win );
693 if (win->win_region && !intersect_window_region( region, win )) goto error;
694 offset_x = win->client_rect.left;
695 offset_y = win->client_rect.top;
697 offset_region( region, -offset_x, -offset_y );
699 /* clip children */
701 if (flags & DCX_CLIPCHILDREN)
703 if (!clip_children( win, NULL, region,
704 offset_x - win->client_rect.left,
705 offset_y - win->client_rect.top )) goto error;
708 /* clip siblings of ancestors */
710 if (top && top != win && (tmp = create_empty_region()) != NULL)
712 offset_region( region, offset_x, offset_y ); /* make it relative to parent */
713 while (win != top && win->parent)
715 if (win->style & WS_CLIPSIBLINGS)
717 if (!clip_children( win->parent, win, region, 0, 0 )) goto error;
718 if (is_region_empty( region )) break;
720 /* clip to parent client area */
721 win = win->parent;
722 offset_x += win->client_rect.left;
723 offset_y += win->client_rect.top;
724 offset_region( region, win->client_rect.left, win->client_rect.top );
725 set_region_client_rect( tmp, win );
726 if (win->win_region && !intersect_window_region( tmp, win ))
728 free_region( tmp );
729 goto error;
731 if (!intersect_region( region, region, tmp ))
733 free_region( tmp );
734 goto error;
736 if (is_region_empty( region )) break;
738 offset_region( region, -offset_x, -offset_y ); /* make it relative to target window again */
739 free_region( tmp );
741 return region;
743 error:
744 free_region( region );
745 return NULL;
749 /* get the window class of a window */
750 struct window_class* get_window_class( user_handle_t window )
752 struct window *win;
753 if (!(win = get_window( window ))) return NULL;
754 return win->class;
757 /* return a copy of the specified region cropped to the window client or frame rectangle, */
758 /* and converted from client to window coordinates. Helper for (in)validate_window. */
759 static struct region *crop_region_to_win_rect( struct window *win, struct region *region, int frame )
761 struct region *tmp = create_empty_region();
763 if (!tmp) return NULL;
765 /* get bounding rect in client coords */
766 if (frame) set_region_rect( tmp, &win->window_rect );
767 else set_region_client_rect( tmp, win );
768 offset_region( tmp, -win->client_rect.left, -win->client_rect.top );
770 /* intersect specified region with bounding rect */
771 if (region && !intersect_region( tmp, region, tmp )) goto done;
772 if (is_region_empty( tmp )) goto done;
774 /* map it to window coords */
775 offset_region( tmp, win->client_rect.left - win->window_rect.left,
776 win->client_rect.top - win->window_rect.top );
777 return tmp;
779 done:
780 free_region( tmp );
781 return NULL;
785 /* set a region as new update region for the window */
786 static void set_update_region( struct window *win, struct region *region )
788 if (region && !is_region_empty( region ))
790 if (!win->update_region) inc_window_paint_count( win, 1 );
791 else free_region( win->update_region );
792 win->update_region = region;
794 else
796 if (win->update_region) inc_window_paint_count( win, -1 );
797 win->paint_flags &= ~(PAINT_ERASE | PAINT_NONCLIENT);
798 win->update_region = NULL;
799 if (region) free_region( region );
804 /* add a region to the update region; the passed region is freed or reused */
805 static int add_update_region( struct window *win, struct region *region )
807 if (win->update_region && !union_region( region, win->update_region, region ))
809 free_region( region );
810 return 0;
812 set_update_region( win, region );
813 return 1;
817 /* validate the non client area of a window */
818 static void validate_non_client( struct window *win )
820 struct region *tmp;
821 rectangle_t rect;
823 if (!win->update_region) return; /* nothing to do */
825 /* get client rect in window coords */
826 rect.left = win->client_rect.left - win->window_rect.left;
827 rect.top = win->client_rect.top - win->window_rect.top;
828 rect.right = win->client_rect.right - win->window_rect.left;
829 rect.bottom = win->client_rect.bottom - win->window_rect.top;
831 if ((tmp = create_empty_region()))
833 set_region_rect( tmp, &rect );
834 if (intersect_region( tmp, win->update_region, tmp ))
835 set_update_region( win, tmp );
836 else
837 free_region( tmp );
839 win->paint_flags &= ~PAINT_NONCLIENT;
843 /* validate a window completely so that we don't get any further paint messages for it */
844 static void validate_whole_window( struct window *win )
846 set_update_region( win, NULL );
848 if (win->paint_flags & PAINT_INTERNAL)
850 win->paint_flags &= ~PAINT_INTERNAL;
851 inc_window_paint_count( win, -1 );
856 /* validate the update region of a window on all parents; helper for redraw_window */
857 static void validate_parents( struct window *child )
859 int offset_x = 0, offset_y = 0;
860 struct window *win = child;
861 struct region *tmp = NULL;
863 if (!child->update_region) return;
865 while (win->parent && win->parent != top_window)
867 /* map to parent client coords */
868 offset_x += win->window_rect.left;
869 offset_y += win->window_rect.top;
871 win = win->parent;
873 /* and now map to window coords */
874 offset_x += win->client_rect.left - win->window_rect.left;
875 offset_y += win->client_rect.top - win->window_rect.top;
877 if (win->update_region && !(win->style & WS_CLIPCHILDREN))
879 if (!tmp && !(tmp = create_empty_region())) return;
880 offset_region( child->update_region, offset_x, offset_y );
881 if (subtract_region( tmp, win->update_region, child->update_region ))
883 set_update_region( win, tmp );
884 tmp = NULL;
886 /* restore child coords */
887 offset_region( child->update_region, -offset_x, -offset_y );
890 if (tmp) free_region( tmp );
894 /* add/subtract a region (in client coordinates) to the update region of the window */
895 static void redraw_window( struct window *win, struct region *region, int frame, unsigned int flags )
897 struct region *tmp;
898 struct window *child;
900 if (flags & RDW_INVALIDATE)
902 if (!(tmp = crop_region_to_win_rect( win, region, frame ))) return;
904 if (!add_update_region( win, tmp )) return;
906 if (flags & RDW_FRAME) win->paint_flags |= PAINT_NONCLIENT;
907 if (flags & RDW_ERASE) win->paint_flags |= PAINT_ERASE;
909 else if (flags & RDW_VALIDATE)
911 if (!region && (flags & RDW_NOFRAME)) /* shortcut: validate everything */
913 set_update_region( win, NULL );
915 else if (win->update_region)
917 if ((tmp = crop_region_to_win_rect( win, region, frame )))
919 if (!subtract_region( tmp, win->update_region, tmp ))
921 free_region( tmp );
922 return;
924 set_update_region( win, tmp );
926 if (flags & RDW_NOFRAME) validate_non_client( win );
927 if (flags & RDW_NOERASE) win->paint_flags &= ~PAINT_ERASE;
931 if ((flags & RDW_INTERNALPAINT) && !(win->paint_flags & PAINT_INTERNAL))
933 win->paint_flags |= PAINT_INTERNAL;
934 inc_window_paint_count( win, 1 );
936 else if ((flags & RDW_NOINTERNALPAINT) && (win->paint_flags & PAINT_INTERNAL))
938 win->paint_flags &= ~PAINT_INTERNAL;
939 inc_window_paint_count( win, -1 );
942 if (flags & RDW_UPDATENOW)
944 validate_parents( win );
945 flags &= ~RDW_UPDATENOW;
948 /* now process children recursively */
950 if (flags & RDW_NOCHILDREN) return;
951 if (win->style & WS_MINIMIZE) return;
952 if ((win->style & WS_CLIPCHILDREN) && !(flags & RDW_ALLCHILDREN)) return;
954 if (!(tmp = crop_region_to_win_rect( win, region, 0 ))) return;
956 /* map to client coordinates */
957 offset_region( tmp, win->window_rect.left - win->client_rect.left,
958 win->window_rect.top - win->client_rect.top );
960 if (flags & RDW_INVALIDATE) flags |= RDW_FRAME | RDW_ERASE;
962 for (child = win->first_child; child; child = child->next)
964 if (!(child->style & WS_VISIBLE)) continue;
965 if (!rect_in_region( tmp, &child->window_rect )) continue;
966 offset_region( tmp, -child->client_rect.left, -child->client_rect.top );
967 redraw_window( child, tmp, 1, flags );
968 offset_region( tmp, child->client_rect.left, child->client_rect.top );
970 free_region( tmp );
974 /* retrieve the update flags for a window depending on the state of the update region */
975 static unsigned int get_update_flags( struct window *win, unsigned int flags )
977 unsigned int ret = 0;
979 if (flags & UPDATE_NONCLIENT)
981 if ((win->paint_flags & PAINT_NONCLIENT) && win->update_region) ret |= UPDATE_NONCLIENT;
983 if (flags & UPDATE_ERASE)
985 if ((win->paint_flags & PAINT_ERASE) && win->update_region) ret |= UPDATE_ERASE;
987 if (flags & UPDATE_PAINT)
989 if (win->update_region) ret |= UPDATE_PAINT;
991 if (flags & UPDATE_INTERNALPAINT)
993 if (win->paint_flags & PAINT_INTERNAL) ret |= UPDATE_INTERNALPAINT;
995 return ret;
999 /* iterate through the children of the given window until we find one with some update flags */
1000 static unsigned int get_child_update_flags( struct window *win, unsigned int flags,
1001 struct window **child )
1003 struct window *ptr;
1004 unsigned int ret = 0;
1006 for (ptr = win->first_child; ptr && !ret; ptr = ptr->next)
1008 if (!(ptr->style & WS_VISIBLE)) continue;
1009 if ((ret = get_update_flags( ptr, flags )) != 0)
1011 *child = ptr;
1012 break;
1014 if (ptr->style & WS_MINIMIZE) continue;
1016 /* Note: the WS_CLIPCHILDREN test is the opposite of the invalidation case,
1017 * here we only want to repaint children of windows that clip them, others
1018 * need to wait for WM_PAINT to be done in the parent first.
1020 if (!(flags & UPDATE_NOCHILDREN) &&
1021 ((flags & UPDATE_ALLCHILDREN) || (ptr->style & WS_CLIPCHILDREN)))
1022 ret = get_child_update_flags( ptr, flags, child );
1024 return ret;
1028 /* expose a region of a window, looking for the top most parent that needs to be exposed */
1029 /* the region is in window coordinates */
1030 static void expose_window( struct window *win, struct window *top, struct region *region )
1032 struct window *parent, *ptr;
1033 int offset_x, offset_y;
1035 /* find the top most parent that doesn't clip either siblings or children */
1036 for (parent = ptr = win; ptr != top; ptr = ptr->parent)
1038 if (!(ptr->style & WS_CLIPCHILDREN)) parent = ptr;
1039 if (!(ptr->style & WS_CLIPSIBLINGS)) parent = ptr->parent;
1041 if (parent == win && parent != top && win->parent)
1042 parent = win->parent; /* always go up at least one level if possible */
1044 offset_x = win->window_rect.left - win->client_rect.left;
1045 offset_y = win->window_rect.top - win->client_rect.top;
1046 for (ptr = win; ptr != parent; ptr = ptr->parent)
1048 offset_x += ptr->client_rect.left;
1049 offset_y += ptr->client_rect.top;
1051 offset_region( region, offset_x, offset_y );
1052 redraw_window( parent, region, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
1053 offset_region( region, -offset_x, -offset_y );
1057 /* set the window and client rectangles, updating the update region if necessary */
1058 static void set_window_pos( struct window *win, struct window *top, struct window *previous,
1059 unsigned int swp_flags, const rectangle_t *window_rect,
1060 const rectangle_t *client_rect, const rectangle_t *valid_rects )
1062 struct region *old_vis_rgn, *new_vis_rgn;
1063 const rectangle_t old_window_rect = win->window_rect;
1064 const rectangle_t old_client_rect = win->client_rect;
1066 /* if the window is not visible, everything is easy */
1068 if ((win->parent && !is_visible( win->parent )) ||
1069 (!(win->style & WS_VISIBLE) && !(swp_flags & SWP_SHOWWINDOW)))
1071 win->window_rect = *window_rect;
1072 win->client_rect = *client_rect;
1073 if (!(swp_flags & SWP_NOZORDER)) link_window( win, win->parent, previous );
1074 if (swp_flags & SWP_SHOWWINDOW) win->style |= WS_VISIBLE;
1075 else if (swp_flags & SWP_HIDEWINDOW) win->style &= ~WS_VISIBLE;
1076 return;
1079 if (!(old_vis_rgn = get_visible_region( win, top, DCX_WINDOW ))) return;
1081 /* set the new window info before invalidating anything */
1083 win->window_rect = *window_rect;
1084 win->client_rect = *client_rect;
1085 if (!(swp_flags & SWP_NOZORDER)) link_window( win, win->parent, previous );
1086 if (swp_flags & SWP_SHOWWINDOW) win->style |= WS_VISIBLE;
1087 else if (swp_flags & SWP_HIDEWINDOW) win->style &= ~WS_VISIBLE;
1089 if (!(new_vis_rgn = get_visible_region( win, top, DCX_WINDOW )))
1091 free_region( old_vis_rgn );
1092 clear_error(); /* ignore error since the window info has been modified already */
1093 return;
1096 /* expose anything revealed by the change */
1098 if (!(swp_flags & SWP_NOREDRAW))
1100 offset_region( old_vis_rgn, old_window_rect.left - window_rect->left,
1101 old_window_rect.top - window_rect->top );
1102 if (xor_region( new_vis_rgn, old_vis_rgn, new_vis_rgn ))
1103 expose_window( win, top, new_vis_rgn );
1105 free_region( old_vis_rgn );
1107 if (!(win->style & WS_VISIBLE))
1109 /* clear the update region since the window is no longer visible */
1110 validate_whole_window( win );
1111 goto done;
1114 if (swp_flags & SWP_NOREDRAW) goto done; /* do not repaint anything */
1116 /* expose the whole non-client area if it changed in any way */
1118 if ((swp_flags & SWP_FRAMECHANGED) ||
1119 memcmp( window_rect, &old_window_rect, sizeof(old_window_rect) ) ||
1120 memcmp( client_rect, &old_client_rect, sizeof(old_client_rect) ))
1122 struct region *tmp = create_empty_region();
1124 if (tmp)
1126 /* subtract the valid portion of client rect from the total region */
1127 if (!memcmp( client_rect, &old_client_rect, sizeof(old_client_rect) ))
1128 set_region_rect( tmp, client_rect );
1129 else if (valid_rects)
1130 set_region_rect( tmp, &valid_rects[0] );
1132 set_region_rect( new_vis_rgn, window_rect );
1133 if (subtract_region( tmp, new_vis_rgn, tmp ))
1135 offset_region( tmp, -client_rect->left, -client_rect->top );
1136 redraw_window( win, tmp, 1, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
1138 free_region( tmp );
1142 done:
1143 free_region( new_vis_rgn );
1144 clear_error(); /* we ignore out of memory errors once the new rects have been set */
1148 /* create a window */
1149 DECL_HANDLER(create_window)
1151 struct window *win;
1153 reply->handle = 0;
1154 if (!req->parent) /* return desktop window */
1156 if (!top_window)
1158 if (!(top_window = create_window( NULL, NULL, req->atom, req->instance ))) return;
1159 top_window->thread = NULL; /* no thread owns the desktop */
1160 top_window->style = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
1162 win = top_window;
1164 else
1166 struct window *parent, *owner = NULL;
1168 if (!(parent = get_window( req->parent ))) return;
1169 if (req->owner && !(owner = get_window( req->owner ))) return;
1170 if (owner == top_window) owner = NULL;
1171 else if (owner && parent != top_window)
1173 /* an owned window must be created as top-level */
1174 set_error( STATUS_ACCESS_DENIED );
1175 return;
1177 if (!(win = create_window( parent, owner, req->atom, req->instance ))) return;
1179 reply->handle = win->handle;
1180 reply->extra = win->nb_extra_bytes;
1181 reply->class_ptr = get_class_client_ptr( win->class );
1185 /* link a window into the tree */
1186 DECL_HANDLER(link_window)
1188 struct window *win, *parent = NULL, *previous = NULL;
1190 if (!(win = get_window( req->handle ))) return;
1191 if (req->parent && !(parent = get_window( req->parent ))) return;
1193 if (win == top_window)
1195 set_error( STATUS_INVALID_PARAMETER );
1196 return;
1198 reply->full_parent = parent ? parent->handle : 0;
1199 if (parent && req->previous)
1201 if (req->previous == (user_handle_t)1) /* special case: HWND_BOTTOM */
1203 previous = parent->last_child;
1204 if (previous == win) return; /* nothing to do */
1206 else
1208 if (!(previous = get_window( req->previous ))) return;
1209 /* previous must be a child of parent, and not win itself */
1210 if (previous->parent != parent || previous == win)
1212 set_error( STATUS_INVALID_PARAMETER );
1213 return;
1217 link_window( win, parent, previous );
1221 /* destroy a window */
1222 DECL_HANDLER(destroy_window)
1224 struct window *win = get_window( req->handle );
1225 if (win)
1227 if (win != top_window) destroy_window( win );
1228 else set_error( STATUS_ACCESS_DENIED );
1233 /* set a window owner */
1234 DECL_HANDLER(set_window_owner)
1236 struct window *win = get_window( req->handle );
1237 struct window *owner = NULL;
1239 if (!win) return;
1240 if (req->owner && !(owner = get_window( req->owner ))) return;
1241 if (win == top_window)
1243 set_error( STATUS_ACCESS_DENIED );
1244 return;
1246 reply->prev_owner = win->owner;
1247 reply->full_owner = win->owner = owner ? owner->handle : 0;
1251 /* get information from a window handle */
1252 DECL_HANDLER(get_window_info)
1254 struct window *win = get_window( req->handle );
1256 reply->full_handle = 0;
1257 reply->tid = reply->pid = 0;
1258 if (win)
1260 reply->full_handle = win->handle;
1261 reply->last_active = win->handle;
1262 if (get_user_object( win->last_active, USER_WINDOW )) reply->last_active = win->last_active;
1263 if (win->thread)
1265 reply->tid = get_thread_id( win->thread );
1266 reply->pid = get_process_id( win->thread->process );
1267 reply->atom = get_class_atom( win->class );
1273 /* set some information in a window */
1274 DECL_HANDLER(set_window_info)
1276 struct window *win = get_window( req->handle );
1278 if (!win) return;
1279 if (req->flags && win == top_window)
1281 set_error( STATUS_ACCESS_DENIED );
1282 return;
1284 if (req->extra_size > sizeof(req->extra_value) ||
1285 req->extra_offset < -1 ||
1286 req->extra_offset > win->nb_extra_bytes - (int)req->extra_size)
1288 set_win32_error( ERROR_INVALID_INDEX );
1289 return;
1291 if (req->extra_offset != -1)
1293 memcpy( &reply->old_extra_value, win->extra_bytes + req->extra_offset, req->extra_size );
1295 else if (req->flags & SET_WIN_EXTRA)
1297 set_win32_error( ERROR_INVALID_INDEX );
1298 return;
1300 reply->old_style = win->style;
1301 reply->old_ex_style = win->ex_style;
1302 reply->old_id = win->id;
1303 reply->old_instance = win->instance;
1304 reply->old_user_data = win->user_data;
1305 if (req->flags & SET_WIN_STYLE) win->style = req->style;
1306 if (req->flags & SET_WIN_EXSTYLE) win->ex_style = req->ex_style;
1307 if (req->flags & SET_WIN_ID) win->id = req->id;
1308 if (req->flags & SET_WIN_INSTANCE) win->instance = req->instance;
1309 if (req->flags & SET_WIN_USERDATA) win->user_data = req->user_data;
1310 if (req->flags & SET_WIN_EXTRA) memcpy( win->extra_bytes + req->extra_offset,
1311 &req->extra_value, req->extra_size );
1313 /* changing window style triggers a non-client paint */
1314 if (req->flags & SET_WIN_STYLE) win->paint_flags |= PAINT_NONCLIENT;
1318 /* get a list of the window parents, up to the root of the tree */
1319 DECL_HANDLER(get_window_parents)
1321 struct window *ptr, *win = get_window( req->handle );
1322 int total = 0;
1323 user_handle_t *data;
1324 size_t len;
1326 if (win) for (ptr = win->parent; ptr; ptr = ptr->parent) total++;
1328 reply->count = total;
1329 len = min( get_reply_max_size(), total * sizeof(user_handle_t) );
1330 if (len && ((data = set_reply_data_size( len ))))
1332 for (ptr = win->parent; ptr && len; ptr = ptr->parent, len -= sizeof(*data))
1333 *data++ = ptr->handle;
1338 /* get a list of the window children */
1339 DECL_HANDLER(get_window_children)
1341 struct window *ptr, *parent = get_window( req->parent );
1342 int total = 0;
1343 user_handle_t *data;
1344 size_t len;
1346 if (parent)
1347 for (ptr = parent->first_child, total = 0; ptr; ptr = ptr->next)
1349 if (req->atom && get_class_atom(ptr->class) != req->atom) continue;
1350 if (req->tid && get_thread_id(ptr->thread) != req->tid) continue;
1351 total++;
1354 reply->count = total;
1355 len = min( get_reply_max_size(), total * sizeof(user_handle_t) );
1356 if (len && ((data = set_reply_data_size( len ))))
1358 for (ptr = parent->first_child; ptr && len; ptr = ptr->next)
1360 if (req->atom && get_class_atom(ptr->class) != req->atom) continue;
1361 if (req->tid && get_thread_id(ptr->thread) != req->tid) continue;
1362 *data++ = ptr->handle;
1363 len -= sizeof(*data);
1369 /* get a list of the window children that contain a given point */
1370 DECL_HANDLER(get_window_children_from_point)
1372 struct user_handle_array array;
1373 struct window *parent = get_window( req->parent );
1374 size_t len;
1376 if (!parent) return;
1378 array.handles = NULL;
1379 array.count = 0;
1380 array.total = 0;
1381 if (!all_windows_from_point( parent, req->x, req->y, &array )) return;
1383 reply->count = array.count;
1384 len = min( get_reply_max_size(), array.count * sizeof(user_handle_t) );
1385 if (len) set_reply_data_ptr( array.handles, len );
1386 else free( array.handles );
1390 /* get window tree information from a window handle */
1391 DECL_HANDLER(get_window_tree)
1393 struct window *win = get_window( req->handle );
1395 if (!win) return;
1397 if (win->parent)
1399 struct window *parent = win->parent;
1400 reply->parent = parent->handle;
1401 reply->owner = win->owner;
1402 reply->next_sibling = win->next ? win->next->handle : 0;
1403 reply->prev_sibling = win->prev ? win->prev->handle : 0;
1404 reply->first_sibling = parent->first_child ? parent->first_child->handle : 0;
1405 reply->last_sibling = parent->last_child ? parent->last_child->handle : 0;
1407 else
1409 reply->parent = 0;
1410 reply->owner = 0;
1411 reply->next_sibling = 0;
1412 reply->prev_sibling = 0;
1413 reply->first_sibling = 0;
1414 reply->last_sibling = 0;
1416 reply->first_child = win->first_child ? win->first_child->handle : 0;
1417 reply->last_child = win->last_child ? win->last_child->handle : 0;
1421 /* set the position and Z order of a window */
1422 DECL_HANDLER(set_window_pos)
1424 const rectangle_t *valid_rects = NULL;
1425 struct window *previous = NULL;
1426 struct window *top = top_window;
1427 struct window *win = get_window( req->handle );
1428 unsigned int flags = req->flags;
1430 if (!win) return;
1431 if (!win->parent) flags |= SWP_NOZORDER; /* no Z order for the desktop */
1433 if (req->top_win)
1435 if (!(top = get_window( req->top_win ))) return;
1438 if (!(flags & SWP_NOZORDER))
1440 if (!req->previous) /* special case: HWND_TOP */
1442 if (win->parent->first_child == win) flags |= SWP_NOZORDER;
1444 else if (req->previous == (user_handle_t)1) /* special case: HWND_BOTTOM */
1446 previous = win->parent->last_child;
1448 else
1450 if (!(previous = get_window( req->previous ))) return;
1451 /* previous must be a sibling */
1452 if (previous->parent != win->parent)
1454 set_error( STATUS_INVALID_PARAMETER );
1455 return;
1458 if (previous == win) flags |= SWP_NOZORDER; /* nothing to do */
1461 /* window rectangle must be ordered properly */
1462 if (req->window.right < req->window.left || req->window.bottom < req->window.top)
1464 set_error( STATUS_INVALID_PARAMETER );
1465 return;
1468 if (get_req_data_size() >= 2 * sizeof(rectangle_t)) valid_rects = get_req_data();
1470 set_window_pos( win, top, previous, flags, &req->window, &req->client, valid_rects );
1471 reply->new_style = win->style;
1475 /* get the window and client rectangles of a window */
1476 DECL_HANDLER(get_window_rectangles)
1478 struct window *win = get_window( req->handle );
1480 if (win)
1482 reply->window = win->window_rect;
1483 reply->client = win->client_rect;
1488 /* get the window text */
1489 DECL_HANDLER(get_window_text)
1491 struct window *win = get_window( req->handle );
1493 if (win && win->text)
1495 size_t len = strlenW( win->text ) * sizeof(WCHAR);
1496 if (len > get_reply_max_size()) len = get_reply_max_size();
1497 set_reply_data( win->text, len );
1502 /* set the window text */
1503 DECL_HANDLER(set_window_text)
1505 struct window *win = get_window( req->handle );
1507 if (win)
1509 WCHAR *text = NULL;
1510 size_t len = get_req_data_size() / sizeof(WCHAR);
1511 if (len)
1513 if (!(text = mem_alloc( (len+1) * sizeof(WCHAR) ))) return;
1514 memcpy( text, get_req_data(), len * sizeof(WCHAR) );
1515 text[len] = 0;
1517 if (win->text) free( win->text );
1518 win->text = text;
1523 /* get the coordinates offset between two windows */
1524 DECL_HANDLER(get_windows_offset)
1526 struct window *win;
1528 reply->x = reply->y = 0;
1529 if (req->from)
1531 if (!(win = get_window( req->from ))) return;
1532 while (win)
1534 reply->x += win->client_rect.left;
1535 reply->y += win->client_rect.top;
1536 win = win->parent;
1539 if (req->to)
1541 if (!(win = get_window( req->to ))) return;
1542 while (win)
1544 reply->x -= win->client_rect.left;
1545 reply->y -= win->client_rect.top;
1546 win = win->parent;
1552 /* get the visible region of a window */
1553 DECL_HANDLER(get_visible_region)
1555 struct region *region;
1556 struct window *win = get_window( req->window );
1557 struct window *top = NULL;
1559 if (!win) return;
1560 if (req->top_win && !(top = get_window( req->top_win ))) return;
1562 if ((region = get_visible_region( win, top, req->flags )))
1564 rectangle_t *data = get_region_data_and_free( region, get_reply_max_size(), &reply->total_size );
1565 if (data) set_reply_data_ptr( data, reply->total_size );
1570 /* get the window region */
1571 DECL_HANDLER(get_window_region)
1573 struct window *win = get_window( req->window );
1575 if (!win) return;
1577 if (win->win_region)
1579 rectangle_t *data = get_region_data( win->win_region, get_reply_max_size(), &reply->total_size );
1580 if (data) set_reply_data_ptr( data, reply->total_size );
1585 /* set the window region */
1586 DECL_HANDLER(set_window_region)
1588 struct region *region = NULL;
1589 struct window *win = get_window( req->window );
1591 if (!win) return;
1593 if (get_req_data_size()) /* no data means remove the region completely */
1595 if (!(region = create_region_from_req_data( get_req_data(), get_req_data_size() )))
1596 return;
1598 if (win->win_region) free_region( win->win_region );
1599 win->win_region = region;
1603 /* get a window update region */
1604 DECL_HANDLER(get_update_region)
1606 rectangle_t *data;
1607 unsigned int flags = req->flags;
1608 struct window *win = get_window( req->window );
1610 reply->flags = 0;
1611 if (!win || !is_visible( win )) return;
1613 if ((flags & UPDATE_NONCLIENT) && !(flags & (UPDATE_PAINT|UPDATE_INTERNALPAINT)))
1615 /* non-client painting must be delayed if one of the parents is going to
1616 * be repainted and doesn't clip children */
1617 struct window *ptr;
1619 for (ptr = win->parent; ptr && ptr != top_window; ptr = ptr->parent)
1621 if (!(ptr->style & WS_CLIPCHILDREN) && win_needs_repaint( ptr ))
1622 return;
1626 if (!(reply->flags = get_update_flags( win, flags )))
1628 /* if window doesn't need any repaint, check the children */
1629 if (!(flags & UPDATE_NOCHILDREN) &&
1630 ((flags & UPDATE_ALLCHILDREN) || (win->style & WS_CLIPCHILDREN)))
1632 reply->flags = get_child_update_flags( win, flags, &win );
1636 reply->child = win->handle;
1638 if (flags & UPDATE_NOREGION) return;
1640 if (win->update_region)
1642 if (!(data = get_region_data( win->update_region, get_reply_max_size(),
1643 &reply->total_size ))) return;
1644 set_reply_data_ptr( data, reply->total_size );
1647 if (reply->flags & (UPDATE_PAINT|UPDATE_INTERNALPAINT)) /* validate everything */
1649 validate_whole_window( win );
1651 else
1653 if (reply->flags & UPDATE_NONCLIENT) validate_non_client( win );
1654 if (reply->flags & UPDATE_ERASE)
1656 win->paint_flags &= ~PAINT_ERASE;
1657 /* desktop window only gets erased, not repainted */
1658 if (win == top_window) validate_whole_window( win );
1664 /* mark parts of a window as needing a redraw */
1665 DECL_HANDLER(redraw_window)
1667 struct region *region = NULL;
1668 struct window *win = get_window( req->window );
1670 if (!win) return;
1671 if (!is_visible( win )) return; /* nothing to do */
1673 if (req->flags & (RDW_VALIDATE|RDW_INVALIDATE))
1675 if (get_req_data_size()) /* no data means whole rectangle */
1677 if (!(region = create_region_from_req_data( get_req_data(), get_req_data_size() )))
1678 return;
1682 redraw_window( win, region, (req->flags & RDW_INVALIDATE) && (req->flags & RDW_FRAME),
1683 req->flags );
1684 if (region) free_region( region );
1688 /* set a window property */
1689 DECL_HANDLER(set_window_property)
1691 struct window *win = get_window( req->window );
1693 if (win) set_property( win, req->atom, req->handle,
1694 req->string ? PROP_TYPE_STRING : PROP_TYPE_ATOM );
1698 /* remove a window property */
1699 DECL_HANDLER(remove_window_property)
1701 struct window *win = get_window( req->window );
1702 reply->handle = 0;
1703 if (win) reply->handle = remove_property( win, req->atom );
1707 /* get a window property */
1708 DECL_HANDLER(get_window_property)
1710 struct window *win = get_window( req->window );
1711 reply->handle = 0;
1712 if (win) reply->handle = get_property( win, req->atom );
1716 /* get the list of properties of a window */
1717 DECL_HANDLER(get_window_properties)
1719 property_data_t *data;
1720 int i, count, max = get_reply_max_size() / sizeof(*data);
1721 struct window *win = get_window( req->window );
1723 reply->total = 0;
1724 if (!win) return;
1726 for (i = count = 0; i < win->prop_inuse; i++)
1727 if (win->properties[i].type != PROP_TYPE_FREE) count++;
1728 reply->total = count;
1730 if (count > max) count = max;
1731 if (!count || !(data = set_reply_data_size( count * sizeof(*data) ))) return;
1733 for (i = 0; i < win->prop_inuse && count; i++)
1735 if (win->properties[i].type == PROP_TYPE_FREE) continue;
1736 data->atom = win->properties[i].atom;
1737 data->string = (win->properties[i].type == PROP_TYPE_STRING);
1738 data->handle = win->properties[i].handle;
1739 data++;
1740 count--;
1745 /* get the new window pointer for a global window, checking permissions */
1746 /* helper for set_global_windows request */
1747 static int get_new_global_window( struct window **win, user_handle_t handle )
1749 if (!handle)
1751 *win = NULL;
1752 return 1;
1754 else if (*win)
1756 set_error( STATUS_ACCESS_DENIED );
1757 return 0;
1759 *win = get_window( handle );
1760 return (*win != NULL);
1763 /* Set/get the global windows */
1764 DECL_HANDLER(set_global_windows)
1766 struct window *new_shell_window = shell_window;
1767 struct window *new_shell_listview = shell_listview;
1768 struct window *new_progman_window = progman_window;
1769 struct window *new_taskman_window = taskman_window;
1771 reply->old_shell_window = shell_window ? shell_window->handle : 0;
1772 reply->old_shell_listview = shell_listview ? shell_listview->handle : 0;
1773 reply->old_progman_window = progman_window ? progman_window->handle : 0;
1774 reply->old_taskman_window = taskman_window ? taskman_window->handle : 0;
1776 if (req->flags & SET_GLOBAL_SHELL_WINDOWS)
1778 if (!get_new_global_window( &new_shell_window, req->shell_window )) return;
1779 if (!get_new_global_window( &new_shell_listview, req->shell_listview )) return;
1781 if (req->flags & SET_GLOBAL_PROGMAN_WINDOW)
1783 if (!get_new_global_window( &new_progman_window, req->progman_window )) return;
1785 if (req->flags & SET_GLOBAL_TASKMAN_WINDOW)
1787 if (!get_new_global_window( &new_taskman_window, req->taskman_window )) return;
1789 shell_window = new_shell_window;
1790 shell_listview = new_shell_listview;
1791 progman_window = new_progman_window;
1792 taskman_window = new_taskman_window;