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 */
70 rectangle_t client_rect
; /* client rectangle */
71 struct region
*win_region
; /* window region (for shaped windows) */
72 unsigned int style
; /* window style */
73 unsigned int ex_style
; /* window extended style */
74 unsigned int id
; /* window id */
75 void* instance
; /* creator instance */
76 void* user_data
; /* user-specific data */
77 WCHAR
*text
; /* window caption text */
78 int paint_count
; /* count of pending paints for this window */
79 int prop_inuse
; /* number of in-use window properties */
80 int prop_alloc
; /* number of allocated window properties */
81 struct property
*properties
; /* window properties array */
82 int nb_extra_bytes
; /* number of extra bytes */
83 char extra_bytes
[1]; /* extra bytes storage */
86 static struct window
*top_window
; /* top-level (desktop) window */
88 /* global window pointers */
89 static struct window
*shell_window
;
90 static struct window
*shell_listview
;
91 static struct window
*progman_window
;
92 static struct window
*taskman_window
;
94 /* retrieve a pointer to a window from its handle */
95 inline static struct window
*get_window( user_handle_t handle
)
97 struct window
*ret
= get_user_object( handle
, USER_WINDOW
);
98 if (!ret
) set_error( STATUS_INVALID_HANDLE
);
102 /* unlink a window from the tree */
103 static void unlink_window( struct window
*win
)
105 struct window
*parent
= win
->parent
;
109 if (win
->next
) win
->next
->prev
= win
->prev
;
110 else if (parent
->last_child
== win
) parent
->last_child
= win
->prev
;
112 if (win
->prev
) win
->prev
->next
= win
->next
;
113 else if (parent
->first_child
== win
) parent
->first_child
= win
->next
;
114 else if (parent
->first_unlinked
== win
) parent
->first_unlinked
= win
->next
;
118 /* link a window into the tree (or unlink it if the new parent is NULL) */
119 static void link_window( struct window
*win
, struct window
*parent
, struct window
*previous
)
121 unlink_window( win
); /* unlink it from the previous location */
125 win
->parent
= parent
;
126 if ((win
->prev
= previous
))
128 if ((win
->next
= previous
->next
)) win
->next
->prev
= win
;
129 else if (win
->parent
->last_child
== previous
) win
->parent
->last_child
= win
;
130 win
->prev
->next
= win
;
134 if ((win
->next
= parent
->first_child
)) win
->next
->prev
= win
;
135 else win
->parent
->last_child
= win
;
136 parent
->first_child
= win
;
139 else /* move it to parent unlinked list */
141 parent
= win
->parent
;
142 if ((win
->next
= parent
->first_unlinked
)) win
->next
->prev
= win
;
144 parent
->first_unlinked
= win
;
148 /* set a window property */
149 static void set_property( struct window
*win
, atom_t atom
, obj_handle_t handle
,
150 enum property_type type
)
153 struct property
*new_props
;
155 /* check if it exists already */
156 for (i
= 0; i
< win
->prop_inuse
; i
++)
158 if (win
->properties
[i
].type
== PROP_TYPE_FREE
)
163 if (win
->properties
[i
].atom
== atom
)
165 win
->properties
[i
].type
= type
;
166 win
->properties
[i
].handle
= handle
;
171 /* need to add an entry */
172 if (!grab_global_atom( atom
)) return;
176 if (win
->prop_inuse
>= win
->prop_alloc
)
178 /* need to grow the array */
179 if (!(new_props
= realloc( win
->properties
,
180 sizeof(*new_props
) * (win
->prop_alloc
+ 16) )))
182 set_error( STATUS_NO_MEMORY
);
183 release_global_atom( atom
);
186 win
->prop_alloc
+= 16;
187 win
->properties
= new_props
;
189 free
= win
->prop_inuse
++;
191 win
->properties
[free
].atom
= atom
;
192 win
->properties
[free
].type
= type
;
193 win
->properties
[free
].handle
= handle
;
196 /* remove a window property */
197 static obj_handle_t
remove_property( struct window
*win
, atom_t atom
)
201 for (i
= 0; i
< win
->prop_inuse
; i
++)
203 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
204 if (win
->properties
[i
].atom
== atom
)
206 release_global_atom( atom
);
207 win
->properties
[i
].type
= PROP_TYPE_FREE
;
208 return win
->properties
[i
].handle
;
211 /* FIXME: last error? */
215 /* find a window property */
216 static obj_handle_t
get_property( struct window
*win
, atom_t atom
)
220 for (i
= 0; i
< win
->prop_inuse
; i
++)
222 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
223 if (win
->properties
[i
].atom
== atom
) return win
->properties
[i
].handle
;
225 /* FIXME: last error? */
229 /* destroy all properties of a window */
230 inline static void destroy_properties( struct window
*win
)
234 if (!win
->properties
) return;
235 for (i
= 0; i
< win
->prop_inuse
; i
++)
237 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
238 release_global_atom( win
->properties
[i
].atom
);
240 free( win
->properties
);
243 /* destroy a window */
244 static void destroy_window( struct window
*win
)
246 assert( win
!= top_window
);
248 /* destroy all children */
249 while (win
->first_child
) destroy_window( win
->first_child
);
250 while (win
->first_unlinked
) destroy_window( win
->first_unlinked
);
252 if (win
->thread
->queue
)
254 if (win
->paint_count
) inc_queue_paint_count( win
->thread
, -win
->paint_count
);
255 queue_cleanup_window( win
->thread
, win
->handle
);
257 /* reset global window pointers, if the corresponding window is destroyed */
258 if (win
== shell_window
) shell_window
= NULL
;
259 if (win
== shell_listview
) shell_listview
= NULL
;
260 if (win
== progman_window
) progman_window
= NULL
;
261 if (win
== taskman_window
) taskman_window
= NULL
;
262 free_user_handle( win
->handle
);
263 destroy_properties( win
);
264 unlink_window( win
);
265 if (win
->win_region
) free_region( win
->win_region
);
266 release_class( win
->class );
267 if (win
->text
) free( win
->text
);
268 memset( win
, 0x55, sizeof(*win
) );
272 /* create a new window structure (note: the window is not linked in the window tree) */
273 static struct window
*create_window( struct window
*parent
, struct window
*owner
,
274 atom_t atom
, void *instance
)
278 struct window_class
*class = grab_class( current
->process
, atom
, instance
, &extra_bytes
);
280 if (!class) return NULL
;
282 win
= mem_alloc( sizeof(*win
) + extra_bytes
- 1 );
285 release_class( class );
289 if (!(win
->handle
= alloc_user_handle( win
, USER_WINDOW
)))
291 release_class( class );
295 win
->parent
= parent
;
296 win
->owner
= owner
? owner
->handle
: 0;
297 win
->first_child
= NULL
;
298 win
->last_child
= NULL
;
299 win
->first_unlinked
= NULL
;
300 win
->thread
= current
;
303 win
->last_active
= win
->handle
;
304 win
->win_region
= NULL
;
308 win
->instance
= NULL
;
309 win
->user_data
= NULL
;
311 win
->paint_count
= 0;
314 win
->properties
= NULL
;
315 win
->nb_extra_bytes
= extra_bytes
;
316 memset( win
->extra_bytes
, 0, extra_bytes
);
318 if (parent
) /* put it on parent unlinked list */
320 if ((win
->next
= parent
->first_unlinked
)) win
->next
->prev
= win
;
322 parent
->first_unlinked
= win
;
324 else win
->next
= win
->prev
= NULL
;
326 /* if parent belongs to a different thread, attach the two threads */
327 if (parent
&& parent
->thread
&& parent
->thread
!= current
)
328 attach_thread_input( current
, parent
->thread
);
332 /* destroy all windows belonging to a given thread */
333 void destroy_thread_windows( struct thread
*thread
)
335 user_handle_t handle
= 0;
338 while ((win
= next_user_handle( &handle
, USER_WINDOW
)))
340 if (win
->thread
!= thread
) continue;
341 destroy_window( win
);
345 /* check whether child is a descendant of parent */
346 int is_child_window( user_handle_t parent
, user_handle_t child
)
348 struct window
*child_ptr
= get_user_object( child
, USER_WINDOW
);
349 struct window
*parent_ptr
= get_user_object( parent
, USER_WINDOW
);
351 if (!child_ptr
|| !parent_ptr
) return 0;
352 while (child_ptr
->parent
)
354 if (child_ptr
->parent
== parent_ptr
) return 1;
355 child_ptr
= child_ptr
->parent
;
360 /* check whether window is a top-level window */
361 int is_top_level_window( user_handle_t window
)
363 struct window
*win
= get_user_object( window
, USER_WINDOW
);
364 return (win
&& win
->parent
== top_window
);
367 /* make a window active if possible */
368 int make_window_active( user_handle_t window
)
370 struct window
*owner
, *win
= get_window( window
);
374 /* set last active for window and its owner */
375 win
->last_active
= win
->handle
;
376 if ((owner
= get_user_object( win
->owner
, USER_WINDOW
))) owner
->last_active
= win
->handle
;
380 /* find child of 'parent' that contains the given point (in parent-relative coords) */
381 static struct window
*child_window_from_point( struct window
*parent
, int x
, int y
)
385 for (ptr
= parent
->first_child
; ptr
; ptr
= ptr
->next
)
387 if (!(ptr
->style
& WS_VISIBLE
)) continue; /* not visible -> skip */
388 if ((ptr
->style
& (WS_POPUP
|WS_CHILD
|WS_DISABLED
)) == (WS_CHILD
|WS_DISABLED
))
389 continue; /* disabled child -> skip */
390 if ((ptr
->ex_style
& (WS_EX_LAYERED
|WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
|WS_EX_TRANSPARENT
))
391 continue; /* transparent -> skip */
392 if (x
< ptr
->window_rect
.left
|| x
>= ptr
->window_rect
.right
||
393 y
< ptr
->window_rect
.top
|| y
>= ptr
->window_rect
.bottom
)
394 continue; /* not in window -> skip */
396 /* FIXME: check window region here */
398 /* if window is minimized or disabled, return at once */
399 if (ptr
->style
& (WS_MINIMIZE
|WS_DISABLED
)) return ptr
;
401 /* if point is not in client area, return at once */
402 if (x
< ptr
->client_rect
.left
|| x
>= ptr
->client_rect
.right
||
403 y
< ptr
->client_rect
.top
|| y
>= ptr
->client_rect
.bottom
)
406 return child_window_from_point( ptr
, x
- ptr
->client_rect
.left
, y
- ptr
->client_rect
.top
);
408 return parent
; /* not found any child */
411 /* find window containing point (in absolute coords) */
412 user_handle_t
window_from_point( int x
, int y
)
416 if (!top_window
) return 0;
417 ret
= child_window_from_point( top_window
, x
, y
);
421 /* return the thread owning a window */
422 struct thread
*get_window_thread( user_handle_t handle
)
424 struct window
*win
= get_user_object( handle
, USER_WINDOW
);
425 if (!win
|| !win
->thread
) return NULL
;
426 return (struct thread
*)grab_object( win
->thread
);
429 /* find a child of the specified window that needs repainting */
430 static struct window
*find_child_to_repaint( struct window
*parent
, struct thread
*thread
)
432 struct window
*ptr
, *ret
= NULL
;
434 for (ptr
= parent
->first_child
; ptr
&& !ret
; ptr
= ptr
->next
)
436 if (!(ptr
->style
& WS_VISIBLE
)) continue;
437 if (ptr
->paint_count
&& ptr
->thread
== thread
)
439 else /* explore its children */
440 ret
= find_child_to_repaint( ptr
, thread
);
443 if (ret
&& (ret
->ex_style
& WS_EX_TRANSPARENT
))
445 /* transparent window, check for non-transparent sibling to paint first */
446 for (ptr
= ret
->next
; ptr
; ptr
= ptr
->next
)
448 if (!(ptr
->style
& WS_VISIBLE
)) continue;
449 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
450 if (ptr
->paint_count
&& ptr
->thread
== thread
) return ptr
;
457 /* find a window that needs repainting */
458 user_handle_t
find_window_to_repaint( user_handle_t parent
, struct thread
*thread
)
460 struct window
*win
= parent
? get_window( parent
) : top_window
;
462 if (!win
|| !(win
->style
& WS_VISIBLE
)) return 0;
463 if (!win
->paint_count
|| win
->thread
!= thread
)
464 win
= find_child_to_repaint( win
, thread
);
465 return win
? win
->handle
: 0;
469 /* intersect the window region with the specified region, relative to the window parent */
470 static struct region
*intersect_window_region( struct region
*region
, struct window
*win
)
472 /* make region relative to window rect */
473 offset_region( region
, -win
->window_rect
.left
, -win
->window_rect
.top
);
474 if (!intersect_region( region
, region
, win
->win_region
)) return NULL
;
475 /* make region relative to parent again */
476 offset_region( region
, win
->window_rect
.left
, win
->window_rect
.top
);
481 /* clip all children of a given window out of the visible region */
482 static struct region
*clip_children( struct window
*parent
, struct window
*last
,
483 struct region
*region
, int offset_x
, int offset_y
)
486 struct region
*tmp
= create_empty_region();
488 if (!tmp
) return NULL
;
489 for (ptr
= parent
->first_child
; ptr
&& ptr
!= last
; ptr
= ptr
->next
)
491 if (!(ptr
->style
& WS_VISIBLE
)) continue;
492 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
493 set_region_rect( tmp
, &ptr
->window_rect
);
494 if (ptr
->win_region
&& !intersect_window_region( tmp
, ptr
))
499 offset_region( tmp
, offset_x
, offset_y
);
500 if (!(region
= subtract_region( region
, region
, tmp
))) break;
501 if (is_region_empty( region
)) break;
508 /* compute the visible region of a window */
509 static struct region
*get_visible_region( struct window
*win
, struct window
*top
,
512 struct region
*tmp
, *region
;
514 int offset_x
, offset_y
;
516 if (!(region
= create_empty_region())) return NULL
;
518 /* first check if all ancestors are visible */
520 for (ptr
= win
; ptr
!= top_window
; ptr
= ptr
->parent
)
521 if (!(ptr
->style
& WS_VISIBLE
)) return region
; /* empty region */
523 /* create a region relative to the window itself */
525 if ((flags
& DCX_PARENTCLIP
) && win
!= top
&& win
->parent
)
528 rect
.left
= rect
.top
= 0;
529 rect
.right
= win
->parent
->client_rect
.right
- win
->parent
->client_rect
.left
;
530 rect
.bottom
= win
->parent
->client_rect
.bottom
- win
->parent
->client_rect
.top
;
531 set_region_rect( region
, &rect
);
532 offset_x
= win
->client_rect
.left
;
533 offset_y
= win
->client_rect
.top
;
535 else if (flags
& DCX_WINDOW
)
537 set_region_rect( region
, &win
->window_rect
);
538 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
539 offset_x
= win
->window_rect
.left
;
540 offset_y
= win
->window_rect
.top
;
544 set_region_rect( region
, &win
->client_rect
);
545 if (win
->win_region
&& !intersect_window_region( region
, win
)) goto error
;
546 offset_x
= win
->client_rect
.left
;
547 offset_y
= win
->client_rect
.top
;
549 offset_region( region
, -offset_x
, -offset_y
);
553 if (flags
& DCX_CLIPCHILDREN
)
555 if (!clip_children( win
, NULL
, region
,
556 offset_x
- win
->client_rect
.left
,
557 offset_y
- win
->client_rect
.top
)) goto error
;
560 /* clip siblings of ancestors */
562 if (top
&& top
!= win
&& (tmp
= create_empty_region()) != NULL
)
564 offset_region( region
, offset_x
, offset_y
); /* make it relative to parent */
565 while (win
!= top
&& win
->parent
)
567 if (win
->style
& WS_CLIPSIBLINGS
)
569 if (!clip_children( win
->parent
, win
, region
, 0, 0 )) goto error
;
570 if (is_region_empty( region
)) break;
572 /* clip to parent client area */
574 offset_x
+= win
->client_rect
.left
;
575 offset_y
+= win
->client_rect
.top
;
576 offset_region( region
, win
->client_rect
.left
, win
->client_rect
.top
);
577 set_region_rect( tmp
, &win
->client_rect
);
578 if (win
->win_region
&& !intersect_window_region( tmp
, win
))
583 if (!intersect_region( region
, region
, tmp
))
588 if (is_region_empty( region
)) break;
590 offset_region( region
, -offset_x
, -offset_y
); /* make it relative to target window again */
596 free_region( region
);
601 /* get the window class of a window */
602 struct window_class
* get_window_class( user_handle_t window
)
605 if (!(win
= get_window( window
))) return NULL
;
610 /* create a window */
611 DECL_HANDLER(create_window
)
616 if (!req
->parent
) /* return desktop window */
620 if (!(top_window
= create_window( NULL
, NULL
, req
->atom
, req
->instance
))) return;
621 top_window
->thread
= NULL
; /* no thread owns the desktop */
622 top_window
->style
= WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
628 struct window
*parent
, *owner
= NULL
;
630 if (!(parent
= get_window( req
->parent
))) return;
631 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
632 if (owner
== top_window
) owner
= NULL
;
633 else if (owner
&& parent
!= top_window
)
635 /* an owned window must be created as top-level */
636 set_error( STATUS_ACCESS_DENIED
);
639 if (!(win
= create_window( parent
, owner
, req
->atom
, req
->instance
))) return;
641 reply
->handle
= win
->handle
;
642 reply
->extra
= win
->nb_extra_bytes
;
643 reply
->class_ptr
= get_class_client_ptr( win
->class );
647 /* link a window into the tree */
648 DECL_HANDLER(link_window
)
650 struct window
*win
, *parent
= NULL
, *previous
= NULL
;
652 if (!(win
= get_window( req
->handle
))) return;
653 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
655 if (win
== top_window
)
657 set_error( STATUS_INVALID_PARAMETER
);
660 reply
->full_parent
= parent
? parent
->handle
: 0;
661 if (parent
&& req
->previous
)
663 if (req
->previous
== (user_handle_t
)1) /* special case: HWND_BOTTOM */
665 previous
= parent
->last_child
;
666 if (previous
== win
) return; /* nothing to do */
670 if (!(previous
= get_window( req
->previous
))) return;
671 /* previous must be a child of parent, and not win itself */
672 if (previous
->parent
!= parent
|| previous
== win
)
674 set_error( STATUS_INVALID_PARAMETER
);
679 link_window( win
, parent
, previous
);
683 /* destroy a window */
684 DECL_HANDLER(destroy_window
)
686 struct window
*win
= get_window( req
->handle
);
689 if (win
!= top_window
) destroy_window( win
);
690 else set_error( STATUS_ACCESS_DENIED
);
695 /* set a window owner */
696 DECL_HANDLER(set_window_owner
)
698 struct window
*win
= get_window( req
->handle
);
699 struct window
*owner
= NULL
;
702 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
703 if (win
== top_window
)
705 set_error( STATUS_ACCESS_DENIED
);
708 reply
->prev_owner
= win
->owner
;
709 reply
->full_owner
= win
->owner
= owner
? owner
->handle
: 0;
713 /* get information from a window handle */
714 DECL_HANDLER(get_window_info
)
716 struct window
*win
= get_window( req
->handle
);
718 reply
->full_handle
= 0;
719 reply
->tid
= reply
->pid
= 0;
722 reply
->full_handle
= win
->handle
;
723 reply
->last_active
= win
->handle
;
724 if (get_user_object( win
->last_active
, USER_WINDOW
)) reply
->last_active
= win
->last_active
;
727 reply
->tid
= get_thread_id( win
->thread
);
728 reply
->pid
= get_process_id( win
->thread
->process
);
729 reply
->atom
= get_class_atom( win
->class );
735 /* set some information in a window */
736 DECL_HANDLER(set_window_info
)
738 struct window
*win
= get_window( req
->handle
);
741 if (req
->flags
&& win
== top_window
)
743 set_error( STATUS_ACCESS_DENIED
);
746 if (req
->extra_size
> sizeof(req
->extra_value
) ||
747 req
->extra_offset
< -1 ||
748 req
->extra_offset
> win
->nb_extra_bytes
- (int)req
->extra_size
)
750 set_win32_error( ERROR_INVALID_INDEX
);
753 if (req
->extra_offset
!= -1)
755 memcpy( &reply
->old_extra_value
, win
->extra_bytes
+ req
->extra_offset
, req
->extra_size
);
757 else if (req
->flags
& SET_WIN_EXTRA
)
759 set_win32_error( ERROR_INVALID_INDEX
);
762 reply
->old_style
= win
->style
;
763 reply
->old_ex_style
= win
->ex_style
;
764 reply
->old_id
= win
->id
;
765 reply
->old_instance
= win
->instance
;
766 reply
->old_user_data
= win
->user_data
;
767 if (req
->flags
& SET_WIN_STYLE
) win
->style
= req
->style
;
768 if (req
->flags
& SET_WIN_EXSTYLE
) win
->ex_style
= req
->ex_style
;
769 if (req
->flags
& SET_WIN_ID
) win
->id
= req
->id
;
770 if (req
->flags
& SET_WIN_INSTANCE
) win
->instance
= req
->instance
;
771 if (req
->flags
& SET_WIN_USERDATA
) win
->user_data
= req
->user_data
;
772 if (req
->flags
& SET_WIN_EXTRA
) memcpy( win
->extra_bytes
+ req
->extra_offset
,
773 &req
->extra_value
, req
->extra_size
);
777 /* get a list of the window parents, up to the root of the tree */
778 DECL_HANDLER(get_window_parents
)
780 struct window
*ptr
, *win
= get_window( req
->handle
);
785 if (win
) for (ptr
= win
->parent
; ptr
; ptr
= ptr
->parent
) total
++;
787 reply
->count
= total
;
788 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
789 if (len
&& ((data
= set_reply_data_size( len
))))
791 for (ptr
= win
->parent
; ptr
&& len
; ptr
= ptr
->parent
, len
-= sizeof(*data
))
792 *data
++ = ptr
->handle
;
797 /* get a list of the window children */
798 DECL_HANDLER(get_window_children
)
800 struct window
*ptr
, *parent
= get_window( req
->parent
);
806 for (ptr
= parent
->first_child
, total
= 0; ptr
; ptr
= ptr
->next
)
808 if (req
->atom
&& get_class_atom(ptr
->class) != req
->atom
) continue;
809 if (req
->tid
&& get_thread_id(ptr
->thread
) != req
->tid
) continue;
813 reply
->count
= total
;
814 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
815 if (len
&& ((data
= set_reply_data_size( len
))))
817 for (ptr
= parent
->first_child
; ptr
&& len
; ptr
= ptr
->next
)
819 if (req
->atom
&& get_class_atom(ptr
->class) != req
->atom
) continue;
820 if (req
->tid
&& get_thread_id(ptr
->thread
) != req
->tid
) continue;
821 *data
++ = ptr
->handle
;
822 len
-= sizeof(*data
);
828 /* get window tree information from a window handle */
829 DECL_HANDLER(get_window_tree
)
831 struct window
*win
= get_window( req
->handle
);
837 struct window
*parent
= win
->parent
;
838 reply
->parent
= parent
->handle
;
839 reply
->owner
= win
->owner
;
840 reply
->next_sibling
= win
->next
? win
->next
->handle
: 0;
841 reply
->prev_sibling
= win
->prev
? win
->prev
->handle
: 0;
842 reply
->first_sibling
= parent
->first_child
? parent
->first_child
->handle
: 0;
843 reply
->last_sibling
= parent
->last_child
? parent
->last_child
->handle
: 0;
849 reply
->next_sibling
= 0;
850 reply
->prev_sibling
= 0;
851 reply
->first_sibling
= 0;
852 reply
->last_sibling
= 0;
854 reply
->first_child
= win
->first_child
? win
->first_child
->handle
: 0;
855 reply
->last_child
= win
->last_child
? win
->last_child
->handle
: 0;
859 /* set the window and client rectangles of a window */
860 DECL_HANDLER(set_window_rectangles
)
862 struct window
*win
= get_window( req
->handle
);
866 win
->window_rect
= req
->window
;
867 win
->client_rect
= req
->client
;
872 /* get the window and client rectangles of a window */
873 DECL_HANDLER(get_window_rectangles
)
875 struct window
*win
= get_window( req
->handle
);
879 reply
->window
= win
->window_rect
;
880 reply
->client
= win
->client_rect
;
885 /* get the window text */
886 DECL_HANDLER(get_window_text
)
888 struct window
*win
= get_window( req
->handle
);
890 if (win
&& win
->text
)
892 size_t len
= strlenW( win
->text
) * sizeof(WCHAR
);
893 if (len
> get_reply_max_size()) len
= get_reply_max_size();
894 set_reply_data( win
->text
, len
);
899 /* set the window text */
900 DECL_HANDLER(set_window_text
)
902 struct window
*win
= get_window( req
->handle
);
907 size_t len
= get_req_data_size() / sizeof(WCHAR
);
910 if (!(text
= mem_alloc( (len
+1) * sizeof(WCHAR
) ))) return;
911 memcpy( text
, get_req_data(), len
* sizeof(WCHAR
) );
914 if (win
->text
) free( win
->text
);
920 /* increment the window paint count */
921 DECL_HANDLER(inc_window_paint_count
)
923 struct window
*win
= get_window( req
->handle
);
925 if (win
&& win
->thread
)
927 int old
= win
->paint_count
;
928 if ((win
->paint_count
+= req
->incr
) < 0) win
->paint_count
= 0;
929 inc_queue_paint_count( win
->thread
, win
->paint_count
- old
);
934 /* get the coordinates offset between two windows */
935 DECL_HANDLER(get_windows_offset
)
939 reply
->x
= reply
->y
= 0;
942 if (!(win
= get_window( req
->from
))) return;
945 reply
->x
+= win
->client_rect
.left
;
946 reply
->y
+= win
->client_rect
.top
;
952 if (!(win
= get_window( req
->to
))) return;
955 reply
->x
-= win
->client_rect
.left
;
956 reply
->y
-= win
->client_rect
.top
;
963 /* get the visible region of a window */
964 DECL_HANDLER(get_visible_region
)
966 struct region
*region
;
967 struct window
*win
= get_window( req
->window
);
968 struct window
*top
= NULL
;
971 if (req
->top_win
&& !(top
= get_window( req
->top_win
))) return;
973 if ((region
= get_visible_region( win
, top
, req
->flags
)))
975 rectangle_t
*data
= get_region_data_and_free( region
, &reply
->total_size
);
976 set_reply_data_ptr( data
, min(reply
->total_size
,get_reply_max_size()) );
981 /* get the window region */
982 DECL_HANDLER(get_window_region
)
984 struct window
*win
= get_window( req
->window
);
988 reply
->total_size
= 0;
991 rectangle_t
*data
= get_region_data( win
->win_region
, &reply
->total_size
);
992 set_reply_data_ptr( data
, min( reply
->total_size
, get_reply_max_size() ) );
997 /* set the window region */
998 DECL_HANDLER(set_window_region
)
1000 struct region
*region
= NULL
;
1001 struct window
*win
= get_window( req
->window
);
1005 if (get_req_data_size()) /* no data means remove the region completely */
1007 if (!(region
= create_region_from_req_data( get_req_data(), get_req_data_size() )))
1010 if (win
->win_region
) free_region( win
->win_region
);
1011 win
->win_region
= region
;
1015 /* set a window property */
1016 DECL_HANDLER(set_window_property
)
1018 struct window
*win
= get_window( req
->window
);
1020 if (win
) set_property( win
, req
->atom
, req
->handle
,
1021 req
->string
? PROP_TYPE_STRING
: PROP_TYPE_ATOM
);
1025 /* remove a window property */
1026 DECL_HANDLER(remove_window_property
)
1028 struct window
*win
= get_window( req
->window
);
1030 if (win
) reply
->handle
= remove_property( win
, req
->atom
);
1034 /* get a window property */
1035 DECL_HANDLER(get_window_property
)
1037 struct window
*win
= get_window( req
->window
);
1039 if (win
) reply
->handle
= get_property( win
, req
->atom
);
1043 /* get the list of properties of a window */
1044 DECL_HANDLER(get_window_properties
)
1046 property_data_t
*data
;
1047 int i
, count
, max
= get_reply_max_size() / sizeof(*data
);
1048 struct window
*win
= get_window( req
->window
);
1053 for (i
= count
= 0; i
< win
->prop_inuse
; i
++)
1054 if (win
->properties
[i
].type
!= PROP_TYPE_FREE
) count
++;
1055 reply
->total
= count
;
1057 if (count
> max
) count
= max
;
1058 if (!count
|| !(data
= set_reply_data_size( count
* sizeof(*data
) ))) return;
1060 for (i
= 0; i
< win
->prop_inuse
&& count
; i
++)
1062 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
1063 data
->atom
= win
->properties
[i
].atom
;
1064 data
->string
= (win
->properties
[i
].type
== PROP_TYPE_STRING
);
1065 data
->handle
= win
->properties
[i
].handle
;
1072 /* get the new window pointer for a global window, checking permissions */
1073 /* helper for set_global_windows request */
1074 static int get_new_global_window( struct window
**win
, user_handle_t handle
)
1083 set_error( STATUS_ACCESS_DENIED
);
1086 *win
= get_window( handle
);
1087 return (*win
!= NULL
);
1090 /* Set/get the global windows */
1091 DECL_HANDLER(set_global_windows
)
1093 struct window
*new_shell_window
= shell_window
;
1094 struct window
*new_shell_listview
= shell_listview
;
1095 struct window
*new_progman_window
= progman_window
;
1096 struct window
*new_taskman_window
= taskman_window
;
1098 reply
->old_shell_window
= shell_window
? shell_window
->handle
: 0;
1099 reply
->old_shell_listview
= shell_listview
? shell_listview
->handle
: 0;
1100 reply
->old_progman_window
= progman_window
? progman_window
->handle
: 0;
1101 reply
->old_taskman_window
= taskman_window
? taskman_window
->handle
: 0;
1103 if (req
->flags
& SET_GLOBAL_SHELL_WINDOWS
)
1105 if (!get_new_global_window( &new_shell_window
, req
->shell_window
)) return;
1106 if (!get_new_global_window( &new_shell_listview
, req
->shell_listview
)) return;
1108 if (req
->flags
& SET_GLOBAL_PROGMAN_WINDOW
)
1110 if (!get_new_global_window( &new_progman_window
, req
->progman_window
)) return;
1112 if (req
->flags
& SET_GLOBAL_TASKMAN_WINDOW
)
1114 if (!get_new_global_window( &new_taskman_window
, req
->taskman_window
)) return;
1116 shell_window
= new_shell_window
;
1117 shell_listview
= new_shell_listview
;
1118 progman_window
= new_progman_window
;
1119 taskman_window
= new_taskman_window
;