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
) + win
->nb_extra_bytes
- 1 );
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; also clear its internal paint flag */
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 /* check that it is a child of the specified parent */
600 for (ptr
= win
; ptr
; ptr
= ptr
->parent
)
601 if (ptr
->handle
== parent
) break;
602 /* otherwise don't return any window, we don't repaint a child before its parent */
603 if (!ptr
) win
= NULL
;
606 win
->paint_flags
&= ~PAINT_INTERNAL
;
611 /* intersect the window region with the specified region, relative to the window parent */
612 static struct region
*intersect_window_region( struct region
*region
, struct window
*win
)
614 /* make region relative to window rect */
615 offset_region( region
, -win
->window_rect
.left
, -win
->window_rect
.top
);
616 if (!intersect_region( region
, region
, win
->win_region
)) return NULL
;
617 /* make region relative to parent again */
618 offset_region( region
, win
->window_rect
.left
, win
->window_rect
.top
);
623 /* clip all children of a given window out of the visible region */
624 static struct region
*clip_children( struct window
*parent
, struct window
*last
,
625 struct region
*region
, int offset_x
, int offset_y
)
628 struct region
*tmp
= create_empty_region();
630 if (!tmp
) return NULL
;
631 for (ptr
= parent
->first_child
; ptr
&& ptr
!= last
; ptr
= ptr
->next
)
633 if (!(ptr
->style
& WS_VISIBLE
)) continue;
634 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
635 set_region_rect( tmp
, &ptr
->window_rect
);
636 if (ptr
->win_region
&& !intersect_window_region( tmp
, ptr
))
641 offset_region( tmp
, offset_x
, offset_y
);
642 if (!(region
= subtract_region( region
, region
, tmp
))) break;
643 if (is_region_empty( region
)) break;
650 /* set the region to the client rect clipped by the window rect, in parent-relative coordinates */
651 static void set_region_client_rect( struct region
*region
, struct window
*win
)
655 rect
.left
= max( win
->window_rect
.left
, win
->client_rect
.left
);
656 rect
.top
= max( win
->window_rect
.top
, win
->client_rect
.top
);
657 rect
.right
= min( win
->window_rect
.right
, win
->client_rect
.right
);
658 rect
.bottom
= min( win
->window_rect
.bottom
, win
->client_rect
.bottom
);
659 set_region_rect( region
, &rect
);
663 /* compute the visible region of a window */
664 static struct region
*get_visible_region( struct window
*win
, struct window
*top
,
667 struct region
*tmp
, *region
;
668 int offset_x
, offset_y
;
670 if (!(region
= create_empty_region())) return NULL
;
672 /* first check if all ancestors are visible */
674 if (!is_visible( win
)) return region
; /* empty region */
676 /* create a region relative to the window itself */
678 if ((flags
& DCX_PARENTCLIP
) && win
!= top
&& win
->parent
)
680 set_region_client_rect( region
, win
->parent
);
681 offset_region( region
, -win
->parent
->client_rect
.left
, -win
->parent
->client_rect
.top
);
682 offset_x
= win
->client_rect
.left
;
683 offset_y
= win
->client_rect
.top
;
685 else if (flags
& DCX_WINDOW
)
687 set_region_rect( region
, &win
->window_rect
);
688 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
689 offset_x
= win
->window_rect
.left
;
690 offset_y
= win
->window_rect
.top
;
694 set_region_client_rect( region
, win
);
695 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
696 offset_x
= win
->client_rect
.left
;
697 offset_y
= win
->client_rect
.top
;
699 offset_region( region
, -offset_x
, -offset_y
);
703 if (flags
& DCX_CLIPCHILDREN
)
705 if (!clip_children( win
, NULL
, region
,
706 offset_x
- win
->client_rect
.left
,
707 offset_y
- win
->client_rect
.top
)) goto error
;
710 /* clip siblings of ancestors */
712 if (top
&& top
!= win
&& (tmp
= create_empty_region()) != NULL
)
714 offset_region( region
, offset_x
, offset_y
); /* make it relative to parent */
715 while (win
!= top
&& win
->parent
)
717 if (win
->style
& WS_CLIPSIBLINGS
)
719 if (!clip_children( win
->parent
, win
, region
, 0, 0 )) goto error
;
720 if (is_region_empty( region
)) break;
722 /* clip to parent client area */
724 offset_x
+= win
->client_rect
.left
;
725 offset_y
+= win
->client_rect
.top
;
726 offset_region( region
, win
->client_rect
.left
, win
->client_rect
.top
);
727 set_region_client_rect( tmp
, win
);
728 if (win
->win_region
&& !intersect_window_region( tmp
, win
))
733 if (!intersect_region( region
, region
, tmp
))
738 if (is_region_empty( region
)) break;
740 offset_region( region
, -offset_x
, -offset_y
); /* make it relative to target window again */
746 free_region( region
);
751 /* get the window class of a window */
752 struct window_class
* get_window_class( user_handle_t window
)
755 if (!(win
= get_window( window
))) return NULL
;
759 /* return a copy of the specified region cropped to the window client or frame rectangle, */
760 /* and converted from client to window coordinates. Helper for (in)validate_window. */
761 static struct region
*crop_region_to_win_rect( struct window
*win
, struct region
*region
, int frame
)
763 struct region
*tmp
= create_empty_region();
765 if (!tmp
) return NULL
;
767 /* get bounding rect in client coords */
768 if (frame
) set_region_rect( tmp
, &win
->window_rect
);
769 else set_region_client_rect( tmp
, win
);
770 offset_region( tmp
, -win
->client_rect
.left
, -win
->client_rect
.top
);
772 /* intersect specified region with bounding rect */
773 if (region
&& !intersect_region( tmp
, region
, tmp
)) goto done
;
774 if (is_region_empty( tmp
)) goto done
;
776 /* map it to window coords */
777 offset_region( tmp
, win
->client_rect
.left
- win
->window_rect
.left
,
778 win
->client_rect
.top
- win
->window_rect
.top
);
787 /* set a region as new update region for the window */
788 static void set_update_region( struct window
*win
, struct region
*region
)
790 if (region
&& !is_region_empty( region
))
792 if (!win
->update_region
) inc_window_paint_count( win
, 1 );
793 else free_region( win
->update_region
);
794 win
->update_region
= region
;
798 if (win
->update_region
) inc_window_paint_count( win
, -1 );
799 win
->paint_flags
&= ~(PAINT_ERASE
| PAINT_NONCLIENT
);
800 win
->update_region
= NULL
;
801 if (region
) free_region( region
);
806 /* add a region to the update region; the passed region is freed or reused */
807 static int add_update_region( struct window
*win
, struct region
*region
)
809 if (win
->update_region
&& !union_region( region
, win
->update_region
, region
))
811 free_region( region
);
814 set_update_region( win
, region
);
819 /* validate the non client area of a window */
820 static void validate_non_client( struct window
*win
)
825 if (!win
->update_region
) return; /* nothing to do */
827 /* get client rect in window coords */
828 rect
.left
= win
->client_rect
.left
- win
->window_rect
.left
;
829 rect
.top
= win
->client_rect
.top
- win
->window_rect
.top
;
830 rect
.right
= win
->client_rect
.right
- win
->window_rect
.left
;
831 rect
.bottom
= win
->client_rect
.bottom
- win
->window_rect
.top
;
833 if ((tmp
= create_empty_region()))
835 set_region_rect( tmp
, &rect
);
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 /* set the window and client rectangles, updating the update region if necessary */
1060 static void set_window_pos( struct window
*win
, struct window
*top
, struct window
*previous
,
1061 unsigned int swp_flags
, const rectangle_t
*window_rect
,
1062 const rectangle_t
*client_rect
, const rectangle_t
*valid_rects
)
1064 struct region
*old_vis_rgn
, *new_vis_rgn
;
1065 const rectangle_t old_window_rect
= win
->window_rect
;
1066 const rectangle_t old_client_rect
= win
->client_rect
;
1068 /* if the window is not visible, everything is easy */
1070 if ((win
->parent
&& !is_visible( win
->parent
)) ||
1071 (!(win
->style
& WS_VISIBLE
) && !(swp_flags
& SWP_SHOWWINDOW
)))
1073 win
->window_rect
= *window_rect
;
1074 win
->client_rect
= *client_rect
;
1075 if (!(swp_flags
& SWP_NOZORDER
)) link_window( win
, win
->parent
, previous
);
1076 if (swp_flags
& SWP_SHOWWINDOW
) win
->style
|= WS_VISIBLE
;
1077 else if (swp_flags
& SWP_HIDEWINDOW
) win
->style
&= ~WS_VISIBLE
;
1081 if (!(old_vis_rgn
= get_visible_region( win
, top
, DCX_WINDOW
))) return;
1083 /* set the new window info before invalidating anything */
1085 win
->window_rect
= *window_rect
;
1086 win
->client_rect
= *client_rect
;
1087 if (!(swp_flags
& SWP_NOZORDER
)) link_window( win
, win
->parent
, previous
);
1088 if (swp_flags
& SWP_SHOWWINDOW
) win
->style
|= WS_VISIBLE
;
1089 else if (swp_flags
& SWP_HIDEWINDOW
) win
->style
&= ~WS_VISIBLE
;
1091 if (!(new_vis_rgn
= get_visible_region( win
, top
, DCX_WINDOW
)))
1093 free_region( old_vis_rgn
);
1094 clear_error(); /* ignore error since the window info has been modified already */
1098 /* expose anything revealed by the change */
1100 if (!(swp_flags
& SWP_NOREDRAW
))
1102 offset_region( old_vis_rgn
, old_window_rect
.left
- window_rect
->left
,
1103 old_window_rect
.top
- window_rect
->top
);
1104 if (xor_region( new_vis_rgn
, old_vis_rgn
, new_vis_rgn
))
1105 expose_window( win
, top
, new_vis_rgn
);
1107 free_region( old_vis_rgn
);
1109 if (!(win
->style
& WS_VISIBLE
))
1111 /* clear the update region since the window is no longer visible */
1112 validate_whole_window( win
);
1116 if (swp_flags
& SWP_NOREDRAW
) goto done
; /* do not repaint anything */
1118 /* expose the whole non-client area if it changed in any way */
1120 if ((swp_flags
& SWP_FRAMECHANGED
) ||
1121 memcmp( window_rect
, &old_window_rect
, sizeof(old_window_rect
) ) ||
1122 memcmp( client_rect
, &old_client_rect
, sizeof(old_client_rect
) ))
1124 struct region
*tmp
= create_empty_region();
1128 /* subtract the valid portion of client rect from the total region */
1129 if (!memcmp( client_rect
, &old_client_rect
, sizeof(old_client_rect
) ))
1130 set_region_rect( tmp
, client_rect
);
1131 else if (valid_rects
)
1132 set_region_rect( tmp
, &valid_rects
[0] );
1134 set_region_rect( new_vis_rgn
, window_rect
);
1135 if (subtract_region( tmp
, new_vis_rgn
, tmp
))
1137 offset_region( tmp
, -client_rect
->left
, -client_rect
->top
);
1138 redraw_window( win
, tmp
, 1, RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
1145 free_region( new_vis_rgn
);
1146 clear_error(); /* we ignore out of memory errors once the new rects have been set */
1150 /* create a window */
1151 DECL_HANDLER(create_window
)
1156 if (!req
->parent
) /* return desktop window */
1160 if (!(top_window
= create_window( NULL
, NULL
, req
->atom
, req
->instance
))) return;
1161 top_window
->thread
= NULL
; /* no thread owns the desktop */
1162 top_window
->style
= WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
1168 struct window
*parent
, *owner
= NULL
;
1170 if (!(parent
= get_window( req
->parent
))) return;
1171 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
1172 if (owner
== top_window
) owner
= NULL
;
1173 else if (owner
&& parent
!= top_window
)
1175 /* an owned window must be created as top-level */
1176 set_error( STATUS_ACCESS_DENIED
);
1179 if (!(win
= create_window( parent
, owner
, req
->atom
, req
->instance
))) return;
1181 reply
->handle
= win
->handle
;
1182 reply
->extra
= win
->nb_extra_bytes
;
1183 reply
->class_ptr
= get_class_client_ptr( win
->class );
1187 /* link a window into the tree */
1188 DECL_HANDLER(link_window
)
1190 struct window
*win
, *parent
= NULL
, *previous
= NULL
;
1192 if (!(win
= get_window( req
->handle
))) return;
1193 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
1195 if (win
== top_window
)
1197 set_error( STATUS_INVALID_PARAMETER
);
1200 reply
->full_parent
= parent
? parent
->handle
: 0;
1201 if (parent
&& req
->previous
)
1203 if (req
->previous
== (user_handle_t
)1) /* special case: HWND_BOTTOM */
1205 previous
= parent
->last_child
;
1206 if (previous
== win
) return; /* nothing to do */
1210 if (!(previous
= get_window( req
->previous
))) return;
1211 /* previous must be a child of parent, and not win itself */
1212 if (previous
->parent
!= parent
|| previous
== win
)
1214 set_error( STATUS_INVALID_PARAMETER
);
1219 link_window( win
, parent
, previous
);
1223 /* destroy a window */
1224 DECL_HANDLER(destroy_window
)
1226 struct window
*win
= get_window( req
->handle
);
1229 if (win
!= top_window
) destroy_window( win
);
1230 else set_error( STATUS_ACCESS_DENIED
);
1235 /* set a window owner */
1236 DECL_HANDLER(set_window_owner
)
1238 struct window
*win
= get_window( req
->handle
);
1239 struct window
*owner
= NULL
;
1242 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
1243 if (win
== top_window
)
1245 set_error( STATUS_ACCESS_DENIED
);
1248 reply
->prev_owner
= win
->owner
;
1249 reply
->full_owner
= win
->owner
= owner
? owner
->handle
: 0;
1253 /* get information from a window handle */
1254 DECL_HANDLER(get_window_info
)
1256 struct window
*win
= get_window( req
->handle
);
1258 reply
->full_handle
= 0;
1259 reply
->tid
= reply
->pid
= 0;
1262 reply
->full_handle
= win
->handle
;
1263 reply
->last_active
= win
->handle
;
1264 if (get_user_object( win
->last_active
, USER_WINDOW
)) reply
->last_active
= win
->last_active
;
1267 reply
->tid
= get_thread_id( win
->thread
);
1268 reply
->pid
= get_process_id( win
->thread
->process
);
1269 reply
->atom
= get_class_atom( win
->class );
1275 /* set some information in a window */
1276 DECL_HANDLER(set_window_info
)
1278 struct window
*win
= get_window( req
->handle
);
1281 if (req
->flags
&& win
== top_window
)
1283 set_error( STATUS_ACCESS_DENIED
);
1286 if (req
->extra_size
> sizeof(req
->extra_value
) ||
1287 req
->extra_offset
< -1 ||
1288 req
->extra_offset
> win
->nb_extra_bytes
- (int)req
->extra_size
)
1290 set_win32_error( ERROR_INVALID_INDEX
);
1293 if (req
->extra_offset
!= -1)
1295 memcpy( &reply
->old_extra_value
, win
->extra_bytes
+ req
->extra_offset
, req
->extra_size
);
1297 else if (req
->flags
& SET_WIN_EXTRA
)
1299 set_win32_error( ERROR_INVALID_INDEX
);
1302 reply
->old_style
= win
->style
;
1303 reply
->old_ex_style
= win
->ex_style
;
1304 reply
->old_id
= win
->id
;
1305 reply
->old_instance
= win
->instance
;
1306 reply
->old_user_data
= win
->user_data
;
1307 if (req
->flags
& SET_WIN_STYLE
) win
->style
= req
->style
;
1308 if (req
->flags
& SET_WIN_EXSTYLE
) win
->ex_style
= req
->ex_style
;
1309 if (req
->flags
& SET_WIN_ID
) win
->id
= req
->id
;
1310 if (req
->flags
& SET_WIN_INSTANCE
) win
->instance
= req
->instance
;
1311 if (req
->flags
& SET_WIN_USERDATA
) win
->user_data
= req
->user_data
;
1312 if (req
->flags
& SET_WIN_EXTRA
) memcpy( win
->extra_bytes
+ req
->extra_offset
,
1313 &req
->extra_value
, req
->extra_size
);
1315 /* changing window style triggers a non-client paint */
1316 if (req
->flags
& SET_WIN_STYLE
) win
->paint_flags
|= PAINT_NONCLIENT
;
1320 /* get a list of the window parents, up to the root of the tree */
1321 DECL_HANDLER(get_window_parents
)
1323 struct window
*ptr
, *win
= get_window( req
->handle
);
1325 user_handle_t
*data
;
1328 if (win
) for (ptr
= win
->parent
; ptr
; ptr
= ptr
->parent
) total
++;
1330 reply
->count
= total
;
1331 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
1332 if (len
&& ((data
= set_reply_data_size( len
))))
1334 for (ptr
= win
->parent
; ptr
&& len
; ptr
= ptr
->parent
, len
-= sizeof(*data
))
1335 *data
++ = ptr
->handle
;
1340 /* get a list of the window children */
1341 DECL_HANDLER(get_window_children
)
1343 struct window
*ptr
, *parent
= get_window( req
->parent
);
1345 user_handle_t
*data
;
1349 for (ptr
= parent
->first_child
, total
= 0; ptr
; ptr
= ptr
->next
)
1351 if (req
->atom
&& get_class_atom(ptr
->class) != req
->atom
) continue;
1352 if (req
->tid
&& get_thread_id(ptr
->thread
) != req
->tid
) continue;
1356 reply
->count
= total
;
1357 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
1358 if (len
&& ((data
= set_reply_data_size( len
))))
1360 for (ptr
= parent
->first_child
; ptr
&& len
; 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;
1364 *data
++ = ptr
->handle
;
1365 len
-= sizeof(*data
);
1371 /* get a list of the window children that contain a given point */
1372 DECL_HANDLER(get_window_children_from_point
)
1374 struct user_handle_array array
;
1375 struct window
*parent
= get_window( req
->parent
);
1378 if (!parent
) return;
1380 array
.handles
= NULL
;
1383 if (!all_windows_from_point( parent
, req
->x
, req
->y
, &array
)) return;
1385 reply
->count
= array
.count
;
1386 len
= min( get_reply_max_size(), array
.count
* sizeof(user_handle_t
) );
1387 if (len
) set_reply_data_ptr( array
.handles
, len
);
1388 else free( array
.handles
);
1392 /* get window tree information from a window handle */
1393 DECL_HANDLER(get_window_tree
)
1395 struct window
*win
= get_window( req
->handle
);
1401 struct window
*parent
= win
->parent
;
1402 reply
->parent
= parent
->handle
;
1403 reply
->owner
= win
->owner
;
1404 reply
->next_sibling
= win
->next
? win
->next
->handle
: 0;
1405 reply
->prev_sibling
= win
->prev
? win
->prev
->handle
: 0;
1406 reply
->first_sibling
= parent
->first_child
? parent
->first_child
->handle
: 0;
1407 reply
->last_sibling
= parent
->last_child
? parent
->last_child
->handle
: 0;
1413 reply
->next_sibling
= 0;
1414 reply
->prev_sibling
= 0;
1415 reply
->first_sibling
= 0;
1416 reply
->last_sibling
= 0;
1418 reply
->first_child
= win
->first_child
? win
->first_child
->handle
: 0;
1419 reply
->last_child
= win
->last_child
? win
->last_child
->handle
: 0;
1423 /* set the position and Z order of a window */
1424 DECL_HANDLER(set_window_pos
)
1426 const rectangle_t
*valid_rects
= NULL
;
1427 struct window
*previous
= NULL
;
1428 struct window
*top
= top_window
;
1429 struct window
*win
= get_window( req
->handle
);
1430 unsigned int flags
= req
->flags
;
1433 if (!win
->parent
) flags
|= SWP_NOZORDER
; /* no Z order for the desktop */
1437 if (!(top
= get_window( req
->top_win
))) return;
1440 if (!(flags
& SWP_NOZORDER
))
1442 if (!req
->previous
) /* special case: HWND_TOP */
1444 if (win
->parent
->first_child
== win
) flags
|= SWP_NOZORDER
;
1446 else if (req
->previous
== (user_handle_t
)1) /* special case: HWND_BOTTOM */
1448 previous
= win
->parent
->last_child
;
1452 if (!(previous
= get_window( req
->previous
))) return;
1453 /* previous must be a sibling */
1454 if (previous
->parent
!= win
->parent
)
1456 set_error( STATUS_INVALID_PARAMETER
);
1460 if (previous
== win
) flags
|= SWP_NOZORDER
; /* nothing to do */
1463 /* window rectangle must be ordered properly */
1464 if (req
->window
.right
< req
->window
.left
|| req
->window
.bottom
< req
->window
.top
)
1466 set_error( STATUS_INVALID_PARAMETER
);
1470 if (get_req_data_size() >= 2 * sizeof(rectangle_t
)) valid_rects
= get_req_data();
1472 set_window_pos( win
, top
, previous
, flags
, &req
->window
, &req
->client
, valid_rects
);
1473 reply
->new_style
= win
->style
;
1477 /* get the window and client rectangles of a window */
1478 DECL_HANDLER(get_window_rectangles
)
1480 struct window
*win
= get_window( req
->handle
);
1484 reply
->window
= win
->window_rect
;
1485 reply
->client
= win
->client_rect
;
1490 /* get the window text */
1491 DECL_HANDLER(get_window_text
)
1493 struct window
*win
= get_window( req
->handle
);
1495 if (win
&& win
->text
)
1497 size_t len
= strlenW( win
->text
) * sizeof(WCHAR
);
1498 if (len
> get_reply_max_size()) len
= get_reply_max_size();
1499 set_reply_data( win
->text
, len
);
1504 /* set the window text */
1505 DECL_HANDLER(set_window_text
)
1507 struct window
*win
= get_window( req
->handle
);
1512 size_t len
= get_req_data_size() / sizeof(WCHAR
);
1515 if (!(text
= mem_alloc( (len
+1) * sizeof(WCHAR
) ))) return;
1516 memcpy( text
, get_req_data(), len
* sizeof(WCHAR
) );
1519 if (win
->text
) free( win
->text
);
1525 /* get the coordinates offset between two windows */
1526 DECL_HANDLER(get_windows_offset
)
1530 reply
->x
= reply
->y
= 0;
1533 if (!(win
= get_window( req
->from
))) return;
1536 reply
->x
+= win
->client_rect
.left
;
1537 reply
->y
+= win
->client_rect
.top
;
1543 if (!(win
= get_window( req
->to
))) return;
1546 reply
->x
-= win
->client_rect
.left
;
1547 reply
->y
-= win
->client_rect
.top
;
1554 /* get the visible region of a window */
1555 DECL_HANDLER(get_visible_region
)
1557 struct region
*region
;
1558 struct window
*win
= get_window( req
->window
);
1559 struct window
*top
= NULL
;
1562 if (req
->top_win
&& !(top
= get_window( req
->top_win
))) return;
1564 if ((region
= get_visible_region( win
, top
, req
->flags
)))
1566 rectangle_t
*data
= get_region_data_and_free( region
, get_reply_max_size(), &reply
->total_size
);
1567 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
1572 /* get the window region */
1573 DECL_HANDLER(get_window_region
)
1575 struct window
*win
= get_window( req
->window
);
1579 if (win
->win_region
)
1581 rectangle_t
*data
= get_region_data( win
->win_region
, get_reply_max_size(), &reply
->total_size
);
1582 if (data
) set_reply_data_ptr( data
, reply
->total_size
);
1587 /* set the window region */
1588 DECL_HANDLER(set_window_region
)
1590 struct region
*region
= NULL
;
1591 struct window
*win
= get_window( req
->window
);
1595 if (get_req_data_size()) /* no data means remove the region completely */
1597 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
1600 if (win
->win_region
) free_region( win
->win_region
);
1601 win
->win_region
= region
;
1605 /* get a window update region */
1606 DECL_HANDLER(get_update_region
)
1609 unsigned int flags
= req
->flags
;
1610 struct window
*win
= get_window( req
->window
);
1613 if (!win
|| !is_visible( win
)) return;
1615 if ((flags
& UPDATE_NONCLIENT
) && !(flags
& (UPDATE_PAINT
|UPDATE_INTERNALPAINT
)))
1617 /* non-client painting must be delayed if one of the parents is going to
1618 * be repainted and doesn't clip children */
1621 for (ptr
= win
->parent
; ptr
&& ptr
!= top_window
; ptr
= ptr
->parent
)
1623 if (!(ptr
->style
& WS_CLIPCHILDREN
) && win_needs_repaint( ptr
))
1628 if (!(reply
->flags
= get_update_flags( win
, flags
)))
1630 /* if window doesn't need any repaint, check the children */
1631 if (!(flags
& UPDATE_NOCHILDREN
) &&
1632 ((flags
& UPDATE_ALLCHILDREN
) || (win
->style
& WS_CLIPCHILDREN
)) &&
1633 !(win
->style
& WS_MINIMIZE
))
1635 reply
->flags
= get_child_update_flags( win
, flags
, &win
);
1639 reply
->child
= win
->handle
;
1641 if (flags
& UPDATE_NOREGION
) return;
1643 if (win
->update_region
)
1645 if (!(data
= get_region_data( win
->update_region
, get_reply_max_size(),
1646 &reply
->total_size
))) return;
1647 set_reply_data_ptr( data
, reply
->total_size
);
1650 if (reply
->flags
& (UPDATE_PAINT
|UPDATE_INTERNALPAINT
)) /* validate everything */
1652 validate_whole_window( win
);
1656 if (reply
->flags
& UPDATE_NONCLIENT
) validate_non_client( win
);
1657 if (reply
->flags
& UPDATE_ERASE
)
1659 win
->paint_flags
&= ~PAINT_ERASE
;
1660 /* desktop window only gets erased, not repainted */
1661 if (win
== top_window
) validate_whole_window( win
);
1667 /* mark parts of a window as needing a redraw */
1668 DECL_HANDLER(redraw_window
)
1670 struct region
*region
= NULL
;
1671 struct window
*win
= get_window( req
->window
);
1674 if (!is_visible( win
)) return; /* nothing to do */
1676 if (req
->flags
& (RDW_VALIDATE
|RDW_INVALIDATE
))
1678 if (get_req_data_size()) /* no data means whole rectangle */
1680 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
1685 redraw_window( win
, region
, (req
->flags
& RDW_INVALIDATE
) && (req
->flags
& RDW_FRAME
),
1687 if (region
) free_region( region
);
1691 /* set a window property */
1692 DECL_HANDLER(set_window_property
)
1694 struct window
*win
= get_window( req
->window
);
1696 if (win
) set_property( win
, req
->atom
, req
->handle
,
1697 req
->string
? PROP_TYPE_STRING
: PROP_TYPE_ATOM
);
1701 /* remove a window property */
1702 DECL_HANDLER(remove_window_property
)
1704 struct window
*win
= get_window( req
->window
);
1706 if (win
) reply
->handle
= remove_property( win
, req
->atom
);
1710 /* get a window property */
1711 DECL_HANDLER(get_window_property
)
1713 struct window
*win
= get_window( req
->window
);
1715 if (win
) reply
->handle
= get_property( win
, req
->atom
);
1719 /* get the list of properties of a window */
1720 DECL_HANDLER(get_window_properties
)
1722 property_data_t
*data
;
1723 int i
, count
, max
= get_reply_max_size() / sizeof(*data
);
1724 struct window
*win
= get_window( req
->window
);
1729 for (i
= count
= 0; i
< win
->prop_inuse
; i
++)
1730 if (win
->properties
[i
].type
!= PROP_TYPE_FREE
) count
++;
1731 reply
->total
= count
;
1733 if (count
> max
) count
= max
;
1734 if (!count
|| !(data
= set_reply_data_size( count
* sizeof(*data
) ))) return;
1736 for (i
= 0; i
< win
->prop_inuse
&& count
; i
++)
1738 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
1739 data
->atom
= win
->properties
[i
].atom
;
1740 data
->string
= (win
->properties
[i
].type
== PROP_TYPE_STRING
);
1741 data
->handle
= win
->properties
[i
].handle
;
1748 /* get the new window pointer for a global window, checking permissions */
1749 /* helper for set_global_windows request */
1750 static int get_new_global_window( struct window
**win
, user_handle_t handle
)
1759 set_error( STATUS_ACCESS_DENIED
);
1762 *win
= get_window( handle
);
1763 return (*win
!= NULL
);
1766 /* Set/get the global windows */
1767 DECL_HANDLER(set_global_windows
)
1769 struct window
*new_shell_window
= shell_window
;
1770 struct window
*new_shell_listview
= shell_listview
;
1771 struct window
*new_progman_window
= progman_window
;
1772 struct window
*new_taskman_window
= taskman_window
;
1774 reply
->old_shell_window
= shell_window
? shell_window
->handle
: 0;
1775 reply
->old_shell_listview
= shell_listview
? shell_listview
->handle
: 0;
1776 reply
->old_progman_window
= progman_window
? progman_window
->handle
: 0;
1777 reply
->old_taskman_window
= taskman_window
? taskman_window
->handle
: 0;
1779 if (req
->flags
& SET_GLOBAL_SHELL_WINDOWS
)
1781 if (!get_new_global_window( &new_shell_window
, req
->shell_window
)) return;
1782 if (!get_new_global_window( &new_shell_listview
, req
->shell_listview
)) return;
1784 if (req
->flags
& SET_GLOBAL_PROGMAN_WINDOW
)
1786 if (!get_new_global_window( &new_progman_window
, req
->progman_window
)) return;
1788 if (req
->flags
& SET_GLOBAL_TASKMAN_WINDOW
)
1790 if (!get_new_global_window( &new_taskman_window
, req
->taskman_window
)) return;
1792 shell_window
= new_shell_window
;
1793 shell_listview
= new_shell_listview
;
1794 progman_window
= new_progman_window
;
1795 taskman_window
= new_taskman_window
;