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 unsigned int style
; /* window style */
72 unsigned int ex_style
; /* window extended style */
73 unsigned int id
; /* window id */
74 void* instance
; /* creator instance */
75 void* user_data
; /* user-specific data */
76 WCHAR
*text
; /* window caption text */
77 int paint_count
; /* count of pending paints for this window */
78 int prop_inuse
; /* number of in-use window properties */
79 int prop_alloc
; /* number of allocated window properties */
80 struct property
*properties
; /* window properties array */
81 int nb_extra_bytes
; /* number of extra bytes */
82 char extra_bytes
[1]; /* extra bytes storage */
85 static struct window
*top_window
; /* top-level (desktop) window */
87 /* global window pointers */
88 static struct window
*shell_window
;
89 static struct window
*shell_listview
;
90 static struct window
*progman_window
;
91 static struct window
*taskman_window
;
93 /* retrieve a pointer to a window from its handle */
94 inline static struct window
*get_window( user_handle_t handle
)
96 struct window
*ret
= get_user_object( handle
, USER_WINDOW
);
97 if (!ret
) set_error( STATUS_INVALID_HANDLE
);
101 /* unlink a window from the tree */
102 static void unlink_window( struct window
*win
)
104 struct window
*parent
= win
->parent
;
108 if (win
->next
) win
->next
->prev
= win
->prev
;
109 else if (parent
->last_child
== win
) parent
->last_child
= win
->prev
;
111 if (win
->prev
) win
->prev
->next
= win
->next
;
112 else if (parent
->first_child
== win
) parent
->first_child
= win
->next
;
113 else if (parent
->first_unlinked
== win
) parent
->first_unlinked
= win
->next
;
117 /* link a window into the tree (or unlink it if the new parent is NULL) */
118 static void link_window( struct window
*win
, struct window
*parent
, struct window
*previous
)
120 unlink_window( win
); /* unlink it from the previous location */
124 win
->parent
= parent
;
125 if ((win
->prev
= previous
))
127 if ((win
->next
= previous
->next
)) win
->next
->prev
= win
;
128 else if (win
->parent
->last_child
== previous
) win
->parent
->last_child
= win
;
129 win
->prev
->next
= win
;
133 if ((win
->next
= parent
->first_child
)) win
->next
->prev
= win
;
134 else win
->parent
->last_child
= win
;
135 parent
->first_child
= win
;
138 else /* move it to parent unlinked list */
140 parent
= win
->parent
;
141 if ((win
->next
= parent
->first_unlinked
)) win
->next
->prev
= win
;
143 parent
->first_unlinked
= win
;
147 /* set a window property */
148 static void set_property( struct window
*win
, atom_t atom
, obj_handle_t handle
,
149 enum property_type type
)
152 struct property
*new_props
;
154 /* check if it exists already */
155 for (i
= 0; i
< win
->prop_inuse
; i
++)
157 if (win
->properties
[i
].type
== PROP_TYPE_FREE
)
162 if (win
->properties
[i
].atom
== atom
)
164 win
->properties
[i
].type
= type
;
165 win
->properties
[i
].handle
= handle
;
170 /* need to add an entry */
171 if (!grab_global_atom( atom
)) return;
175 if (win
->prop_inuse
>= win
->prop_alloc
)
177 /* need to grow the array */
178 if (!(new_props
= realloc( win
->properties
,
179 sizeof(*new_props
) * (win
->prop_alloc
+ 16) )))
181 set_error( STATUS_NO_MEMORY
);
182 release_global_atom( atom
);
185 win
->prop_alloc
+= 16;
186 win
->properties
= new_props
;
188 free
= win
->prop_inuse
++;
190 win
->properties
[free
].atom
= atom
;
191 win
->properties
[free
].type
= type
;
192 win
->properties
[free
].handle
= handle
;
195 /* remove a window property */
196 static obj_handle_t
remove_property( struct window
*win
, atom_t atom
)
200 for (i
= 0; i
< win
->prop_inuse
; i
++)
202 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
203 if (win
->properties
[i
].atom
== atom
)
205 release_global_atom( atom
);
206 win
->properties
[i
].type
= PROP_TYPE_FREE
;
207 return win
->properties
[i
].handle
;
210 /* FIXME: last error? */
214 /* find a window property */
215 static obj_handle_t
get_property( struct window
*win
, atom_t atom
)
219 for (i
= 0; i
< win
->prop_inuse
; i
++)
221 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
222 if (win
->properties
[i
].atom
== atom
) return win
->properties
[i
].handle
;
224 /* FIXME: last error? */
228 /* destroy all properties of a window */
229 inline static void destroy_properties( struct window
*win
)
233 if (!win
->properties
) return;
234 for (i
= 0; i
< win
->prop_inuse
; i
++)
236 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
237 release_global_atom( win
->properties
[i
].atom
);
239 free( win
->properties
);
242 /* destroy a window */
243 static void destroy_window( struct window
*win
)
245 assert( win
!= top_window
);
247 /* destroy all children */
248 while (win
->first_child
) destroy_window( win
->first_child
);
249 while (win
->first_unlinked
) destroy_window( win
->first_unlinked
);
251 if (win
->thread
->queue
)
253 if (win
->paint_count
) inc_queue_paint_count( win
->thread
, -win
->paint_count
);
254 queue_cleanup_window( win
->thread
, win
->handle
);
256 /* reset global window pointers, if the corresponding window is destroyed */
257 if (win
== shell_window
) shell_window
= NULL
;
258 if (win
== shell_listview
) shell_listview
= NULL
;
259 if (win
== progman_window
) progman_window
= NULL
;
260 if (win
== taskman_window
) taskman_window
= NULL
;
261 free_user_handle( win
->handle
);
262 destroy_properties( win
);
263 unlink_window( win
);
264 release_class( win
->class );
265 if (win
->text
) free( win
->text
);
266 memset( win
, 0x55, sizeof(*win
) );
270 /* create a new window structure (note: the window is not linked in the window tree) */
271 static struct window
*create_window( struct window
*parent
, struct window
*owner
,
272 atom_t atom
, void *instance
)
276 struct window_class
*class = grab_class( current
->process
, atom
, instance
, &extra_bytes
);
278 if (!class) return NULL
;
280 win
= mem_alloc( sizeof(*win
) + extra_bytes
- 1 );
283 release_class( class );
287 if (!(win
->handle
= alloc_user_handle( win
, USER_WINDOW
)))
289 release_class( class );
293 win
->parent
= parent
;
294 win
->owner
= owner
? owner
->handle
: 0;
295 win
->first_child
= NULL
;
296 win
->last_child
= NULL
;
297 win
->first_unlinked
= NULL
;
298 win
->thread
= current
;
301 win
->last_active
= win
->handle
;
305 win
->instance
= NULL
;
306 win
->user_data
= NULL
;
308 win
->paint_count
= 0;
311 win
->properties
= NULL
;
312 win
->nb_extra_bytes
= extra_bytes
;
313 memset( win
->extra_bytes
, 0, extra_bytes
);
315 if (parent
) /* put it on parent unlinked list */
317 if ((win
->next
= parent
->first_unlinked
)) win
->next
->prev
= win
;
319 parent
->first_unlinked
= win
;
321 else win
->next
= win
->prev
= NULL
;
323 /* if parent belongs to a different thread, attach the two threads */
324 if (parent
&& parent
->thread
&& parent
->thread
!= current
)
325 attach_thread_input( current
, parent
->thread
);
329 /* destroy all windows belonging to a given thread */
330 void destroy_thread_windows( struct thread
*thread
)
332 user_handle_t handle
= 0;
335 while ((win
= next_user_handle( &handle
, USER_WINDOW
)))
337 if (win
->thread
!= thread
) continue;
338 destroy_window( win
);
342 /* check whether child is a descendant of parent */
343 int is_child_window( user_handle_t parent
, user_handle_t child
)
345 struct window
*child_ptr
= get_user_object( child
, USER_WINDOW
);
346 struct window
*parent_ptr
= get_user_object( parent
, USER_WINDOW
);
348 if (!child_ptr
|| !parent_ptr
) return 0;
349 while (child_ptr
->parent
)
351 if (child_ptr
->parent
== parent_ptr
) return 1;
352 child_ptr
= child_ptr
->parent
;
357 /* check whether window is a top-level window */
358 int is_top_level_window( user_handle_t window
)
360 struct window
*win
= get_user_object( window
, USER_WINDOW
);
361 return (win
&& win
->parent
== top_window
);
364 /* make a window active if possible */
365 int make_window_active( user_handle_t window
)
367 struct window
*owner
, *win
= get_window( window
);
371 /* set last active for window and its owner */
372 win
->last_active
= win
->handle
;
373 if ((owner
= get_user_object( win
->owner
, USER_WINDOW
))) owner
->last_active
= win
->handle
;
377 /* find child of 'parent' that contains the given point (in parent-relative coords) */
378 static struct window
*child_window_from_point( struct window
*parent
, int x
, int y
)
382 for (ptr
= parent
->first_child
; ptr
; ptr
= ptr
->next
)
384 if (!(ptr
->style
& WS_VISIBLE
)) continue; /* not visible -> skip */
385 if ((ptr
->style
& (WS_POPUP
|WS_CHILD
|WS_DISABLED
)) == (WS_CHILD
|WS_DISABLED
))
386 continue; /* disabled child -> skip */
387 if ((ptr
->ex_style
& (WS_EX_LAYERED
|WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
|WS_EX_TRANSPARENT
))
388 continue; /* transparent -> skip */
389 if (x
< ptr
->window_rect
.left
|| x
>= ptr
->window_rect
.right
||
390 y
< ptr
->window_rect
.top
|| y
>= ptr
->window_rect
.bottom
)
391 continue; /* not in window -> skip */
393 /* FIXME: check window region here */
395 /* if window is minimized or disabled, return at once */
396 if (ptr
->style
& (WS_MINIMIZE
|WS_DISABLED
)) return ptr
;
398 /* if point is not in client area, return at once */
399 if (x
< ptr
->client_rect
.left
|| x
>= ptr
->client_rect
.right
||
400 y
< ptr
->client_rect
.top
|| y
>= ptr
->client_rect
.bottom
)
403 return child_window_from_point( ptr
, x
- ptr
->client_rect
.left
, y
- ptr
->client_rect
.top
);
405 return parent
; /* not found any child */
408 /* find window containing point (in absolute coords) */
409 user_handle_t
window_from_point( int x
, int y
)
413 if (!top_window
) return 0;
414 ret
= child_window_from_point( top_window
, x
, y
);
418 /* return the thread owning a window */
419 struct thread
*get_window_thread( user_handle_t handle
)
421 struct window
*win
= get_user_object( handle
, USER_WINDOW
);
422 if (!win
|| !win
->thread
) return NULL
;
423 return (struct thread
*)grab_object( win
->thread
);
426 /* find a child of the specified window that needs repainting */
427 static struct window
*find_child_to_repaint( struct window
*parent
, struct thread
*thread
)
429 struct window
*ptr
, *ret
= NULL
;
431 for (ptr
= parent
->first_child
; ptr
&& !ret
; ptr
= ptr
->next
)
433 if (!(ptr
->style
& WS_VISIBLE
)) continue;
434 if (ptr
->paint_count
&& ptr
->thread
== thread
)
436 else /* explore its children */
437 ret
= find_child_to_repaint( ptr
, thread
);
440 if (ret
&& (ret
->ex_style
& WS_EX_TRANSPARENT
))
442 /* transparent window, check for non-transparent sibling to paint first */
443 for (ptr
= ret
->next
; ptr
; ptr
= ptr
->next
)
445 if (!(ptr
->style
& WS_VISIBLE
)) continue;
446 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
447 if (ptr
->paint_count
&& ptr
->thread
== thread
) return ptr
;
454 /* find a window that needs repainting */
455 user_handle_t
find_window_to_repaint( user_handle_t parent
, struct thread
*thread
)
457 struct window
*win
= parent
? get_window( parent
) : top_window
;
459 if (!win
|| !(win
->style
& WS_VISIBLE
)) return 0;
460 if (!win
->paint_count
|| win
->thread
!= thread
)
461 win
= find_child_to_repaint( win
, thread
);
462 return win
? win
->handle
: 0;
466 /* clip all children of a given window out of the visible region */
467 static struct region
*clip_children( struct window
*parent
, struct window
*last
,
468 struct region
*region
, int offset_x
, int offset_y
)
471 struct region
*tmp
= create_empty_region();
473 if (!tmp
) return NULL
;
474 for (ptr
= parent
->first_child
; ptr
&& ptr
!= last
; ptr
= ptr
->next
)
476 if (!(ptr
->style
& WS_VISIBLE
)) continue;
477 if (ptr
->ex_style
& WS_EX_TRANSPARENT
) continue;
478 set_region_rect( tmp
, &ptr
->window_rect
);
479 offset_region( tmp
, offset_x
, offset_y
);
480 if (!(region
= subtract_region( region
, region
, tmp
))) break;
481 if (is_region_empty( region
)) break;
488 /* compute the visible region of a window */
489 static struct region
*get_visible_region( struct window
*win
, struct window
*top
,
492 struct region
*tmp
, *region
;
495 int offset_x
, offset_y
;
497 if (!(region
= create_empty_region())) return NULL
;
499 /* first check if all ancestors are visible */
501 for (ptr
= win
; ptr
!= top_window
; ptr
= ptr
->parent
)
502 if (!(ptr
->style
& WS_VISIBLE
)) return region
; /* empty region */
504 /* retrieve window rectangle in parent coordinates */
506 if ((flags
& DCX_PARENTCLIP
) && win
->parent
)
508 rect
.left
= rect
.top
= 0;
509 rect
.right
= win
->parent
->client_rect
.right
- win
->parent
->client_rect
.left
;
510 rect
.bottom
= win
->parent
->client_rect
.bottom
- win
->parent
->client_rect
.top
;
511 offset_x
= win
->client_rect
.left
;
512 offset_y
= win
->client_rect
.top
;
514 else if (flags
& DCX_WINDOW
)
516 rect
= win
->window_rect
;
517 offset_x
= win
->window_rect
.left
;
518 offset_y
= win
->window_rect
.top
;
522 rect
= win
->client_rect
;
523 offset_x
= win
->client_rect
.left
;
524 offset_y
= win
->client_rect
.top
;
527 /* create a region relative to the window itself */
529 set_region_rect( region
, &rect
);
530 offset_region( region
, -offset_x
, -offset_y
);
534 if (flags
& DCX_CLIPCHILDREN
)
536 if (!clip_children( win
, NULL
, region
,
537 offset_x
- win
->client_rect
.left
,
538 offset_y
- win
->client_rect
.top
)) goto error
;
541 /* clip siblings of ancestors */
543 if (top
&& top
!= win
&& (tmp
= create_empty_region()) != NULL
)
545 offset_region( region
, offset_x
, offset_y
); /* make it relative to parent */
548 if (win
->style
& WS_CLIPSIBLINGS
)
550 if (!clip_children( win
->parent
, win
, region
, 0, 0 )) goto error
;
551 if (is_region_empty( region
)) break;
553 if (win
== top
) break;
554 /* clip to parent client area */
556 offset_x
+= win
->client_rect
.left
;
557 offset_y
+= win
->client_rect
.top
;
558 offset_region( region
, win
->client_rect
.left
, win
->client_rect
.top
);
559 set_region_rect( tmp
, &win
->client_rect
);
560 if (!intersect_region( region
, region
, tmp
)) goto error
;
561 if (is_region_empty( region
)) break;
563 offset_region( region
, -offset_x
, -offset_y
); /* make it relative to target window again */
569 free_region( region
);
574 /* get the window class of a window */
575 struct window_class
* get_window_class( user_handle_t window
)
578 if (!(win
= get_window( window
))) return NULL
;
583 /* create a window */
584 DECL_HANDLER(create_window
)
589 if (!req
->parent
) /* return desktop window */
593 if (!(top_window
= create_window( NULL
, NULL
, req
->atom
, req
->instance
))) return;
594 top_window
->thread
= NULL
; /* no thread owns the desktop */
595 top_window
->style
= WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
601 struct window
*parent
, *owner
= NULL
;
603 if (!(parent
= get_window( req
->parent
))) return;
604 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
605 if (owner
== top_window
) owner
= NULL
;
606 else if (owner
&& parent
!= top_window
)
608 /* an owned window must be created as top-level */
609 set_error( STATUS_ACCESS_DENIED
);
612 if (!(win
= create_window( parent
, owner
, req
->atom
, req
->instance
))) return;
614 reply
->handle
= win
->handle
;
615 reply
->extra
= win
->nb_extra_bytes
;
616 reply
->class_ptr
= get_class_client_ptr( win
->class );
620 /* link a window into the tree */
621 DECL_HANDLER(link_window
)
623 struct window
*win
, *parent
= NULL
, *previous
= NULL
;
625 if (!(win
= get_window( req
->handle
))) return;
626 if (req
->parent
&& !(parent
= get_window( req
->parent
))) return;
628 if (win
== top_window
)
630 set_error( STATUS_INVALID_PARAMETER
);
633 reply
->full_parent
= parent
? parent
->handle
: 0;
634 if (parent
&& req
->previous
)
636 if (req
->previous
== (user_handle_t
)1) /* special case: HWND_BOTTOM */
638 previous
= parent
->last_child
;
639 if (previous
== win
) return; /* nothing to do */
643 if (!(previous
= get_window( req
->previous
))) return;
644 /* previous must be a child of parent, and not win itself */
645 if (previous
->parent
!= parent
|| previous
== win
)
647 set_error( STATUS_INVALID_PARAMETER
);
652 link_window( win
, parent
, previous
);
656 /* destroy a window */
657 DECL_HANDLER(destroy_window
)
659 struct window
*win
= get_window( req
->handle
);
662 if (win
!= top_window
) destroy_window( win
);
663 else set_error( STATUS_ACCESS_DENIED
);
668 /* set a window owner */
669 DECL_HANDLER(set_window_owner
)
671 struct window
*win
= get_window( req
->handle
);
672 struct window
*owner
= NULL
;
675 if (req
->owner
&& !(owner
= get_window( req
->owner
))) return;
676 if (win
== top_window
)
678 set_error( STATUS_ACCESS_DENIED
);
681 reply
->prev_owner
= win
->owner
;
682 reply
->full_owner
= win
->owner
= owner
? owner
->handle
: 0;
686 /* get information from a window handle */
687 DECL_HANDLER(get_window_info
)
689 struct window
*win
= get_window( req
->handle
);
691 reply
->full_handle
= 0;
692 reply
->tid
= reply
->pid
= 0;
695 reply
->full_handle
= win
->handle
;
696 reply
->last_active
= win
->handle
;
697 if (get_user_object( win
->last_active
, USER_WINDOW
)) reply
->last_active
= win
->last_active
;
700 reply
->tid
= get_thread_id( win
->thread
);
701 reply
->pid
= get_process_id( win
->thread
->process
);
702 reply
->atom
= get_class_atom( win
->class );
708 /* set some information in a window */
709 DECL_HANDLER(set_window_info
)
711 struct window
*win
= get_window( req
->handle
);
714 if (req
->flags
&& win
== top_window
)
716 set_error( STATUS_ACCESS_DENIED
);
719 if (req
->extra_size
> sizeof(req
->extra_value
) ||
720 req
->extra_offset
< -1 ||
721 req
->extra_offset
> win
->nb_extra_bytes
- (int)req
->extra_size
)
723 set_win32_error( ERROR_INVALID_INDEX
);
726 if (req
->extra_offset
!= -1)
728 memcpy( &reply
->old_extra_value
, win
->extra_bytes
+ req
->extra_offset
, req
->extra_size
);
730 else if (req
->flags
& SET_WIN_EXTRA
)
732 set_win32_error( ERROR_INVALID_INDEX
);
735 reply
->old_style
= win
->style
;
736 reply
->old_ex_style
= win
->ex_style
;
737 reply
->old_id
= win
->id
;
738 reply
->old_instance
= win
->instance
;
739 reply
->old_user_data
= win
->user_data
;
740 if (req
->flags
& SET_WIN_STYLE
) win
->style
= req
->style
;
741 if (req
->flags
& SET_WIN_EXSTYLE
) win
->ex_style
= req
->ex_style
;
742 if (req
->flags
& SET_WIN_ID
) win
->id
= req
->id
;
743 if (req
->flags
& SET_WIN_INSTANCE
) win
->instance
= req
->instance
;
744 if (req
->flags
& SET_WIN_USERDATA
) win
->user_data
= req
->user_data
;
745 if (req
->flags
& SET_WIN_EXTRA
) memcpy( win
->extra_bytes
+ req
->extra_offset
,
746 &req
->extra_value
, req
->extra_size
);
750 /* get a list of the window parents, up to the root of the tree */
751 DECL_HANDLER(get_window_parents
)
753 struct window
*ptr
, *win
= get_window( req
->handle
);
758 if (win
) for (ptr
= win
->parent
; ptr
; ptr
= ptr
->parent
) total
++;
760 reply
->count
= total
;
761 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
762 if (len
&& ((data
= set_reply_data_size( len
))))
764 for (ptr
= win
->parent
; ptr
&& len
; ptr
= ptr
->parent
, len
-= sizeof(*data
))
765 *data
++ = ptr
->handle
;
770 /* get a list of the window children */
771 DECL_HANDLER(get_window_children
)
773 struct window
*ptr
, *parent
= get_window( req
->parent
);
779 for (ptr
= parent
->first_child
, total
= 0; ptr
; ptr
= ptr
->next
)
781 if (req
->atom
&& get_class_atom(ptr
->class) != req
->atom
) continue;
782 if (req
->tid
&& get_thread_id(ptr
->thread
) != req
->tid
) continue;
786 reply
->count
= total
;
787 len
= min( get_reply_max_size(), total
* sizeof(user_handle_t
) );
788 if (len
&& ((data
= set_reply_data_size( len
))))
790 for (ptr
= parent
->first_child
; ptr
&& len
; ptr
= ptr
->next
)
792 if (req
->atom
&& get_class_atom(ptr
->class) != req
->atom
) continue;
793 if (req
->tid
&& get_thread_id(ptr
->thread
) != req
->tid
) continue;
794 *data
++ = ptr
->handle
;
795 len
-= sizeof(*data
);
801 /* get window tree information from a window handle */
802 DECL_HANDLER(get_window_tree
)
804 struct window
*win
= get_window( req
->handle
);
810 struct window
*parent
= win
->parent
;
811 reply
->parent
= parent
->handle
;
812 reply
->owner
= win
->owner
;
813 reply
->next_sibling
= win
->next
? win
->next
->handle
: 0;
814 reply
->prev_sibling
= win
->prev
? win
->prev
->handle
: 0;
815 reply
->first_sibling
= parent
->first_child
? parent
->first_child
->handle
: 0;
816 reply
->last_sibling
= parent
->last_child
? parent
->last_child
->handle
: 0;
822 reply
->next_sibling
= 0;
823 reply
->prev_sibling
= 0;
824 reply
->first_sibling
= 0;
825 reply
->last_sibling
= 0;
827 reply
->first_child
= win
->first_child
? win
->first_child
->handle
: 0;
828 reply
->last_child
= win
->last_child
? win
->last_child
->handle
: 0;
832 /* set the window and client rectangles of a window */
833 DECL_HANDLER(set_window_rectangles
)
835 struct window
*win
= get_window( req
->handle
);
839 win
->window_rect
= req
->window
;
840 win
->client_rect
= req
->client
;
845 /* get the window and client rectangles of a window */
846 DECL_HANDLER(get_window_rectangles
)
848 struct window
*win
= get_window( req
->handle
);
852 reply
->window
= win
->window_rect
;
853 reply
->client
= win
->client_rect
;
858 /* get the window text */
859 DECL_HANDLER(get_window_text
)
861 struct window
*win
= get_window( req
->handle
);
863 if (win
&& win
->text
)
865 size_t len
= strlenW( win
->text
) * sizeof(WCHAR
);
866 if (len
> get_reply_max_size()) len
= get_reply_max_size();
867 set_reply_data( win
->text
, len
);
872 /* set the window text */
873 DECL_HANDLER(set_window_text
)
875 struct window
*win
= get_window( req
->handle
);
880 size_t len
= get_req_data_size() / sizeof(WCHAR
);
883 if (!(text
= mem_alloc( (len
+1) * sizeof(WCHAR
) ))) return;
884 memcpy( text
, get_req_data(), len
* sizeof(WCHAR
) );
887 if (win
->text
) free( win
->text
);
893 /* increment the window paint count */
894 DECL_HANDLER(inc_window_paint_count
)
896 struct window
*win
= get_window( req
->handle
);
898 if (win
&& win
->thread
)
900 int old
= win
->paint_count
;
901 if ((win
->paint_count
+= req
->incr
) < 0) win
->paint_count
= 0;
902 inc_queue_paint_count( win
->thread
, win
->paint_count
- old
);
907 /* get the coordinates offset between two windows */
908 DECL_HANDLER(get_windows_offset
)
912 reply
->x
= reply
->y
= 0;
915 if (!(win
= get_window( req
->from
))) return;
918 reply
->x
+= win
->client_rect
.left
;
919 reply
->y
+= win
->client_rect
.top
;
925 if (!(win
= get_window( req
->to
))) return;
928 reply
->x
-= win
->client_rect
.left
;
929 reply
->y
-= win
->client_rect
.top
;
936 /* get the visible region of a window */
937 DECL_HANDLER(get_visible_region
)
939 struct region
*region
;
940 struct window
*win
= get_window( req
->window
);
941 struct window
*top
= NULL
;
944 if (req
->top_win
&& !(top
= get_window( req
->top_win
))) return;
946 if ((region
= get_visible_region( win
, top
, req
->flags
)))
948 rectangle_t
*data
= get_region_data_and_free( region
, &reply
->total_size
);
949 set_reply_data_ptr( data
, min(reply
->total_size
,get_reply_max_size()) );
954 /* set a window property */
955 DECL_HANDLER(set_window_property
)
957 struct window
*win
= get_window( req
->window
);
959 if (win
) set_property( win
, req
->atom
, req
->handle
,
960 req
->string
? PROP_TYPE_STRING
: PROP_TYPE_ATOM
);
964 /* remove a window property */
965 DECL_HANDLER(remove_window_property
)
967 struct window
*win
= get_window( req
->window
);
969 if (win
) reply
->handle
= remove_property( win
, req
->atom
);
973 /* get a window property */
974 DECL_HANDLER(get_window_property
)
976 struct window
*win
= get_window( req
->window
);
978 if (win
) reply
->handle
= get_property( win
, req
->atom
);
982 /* get the list of properties of a window */
983 DECL_HANDLER(get_window_properties
)
985 property_data_t
*data
;
986 int i
, count
, max
= get_reply_max_size() / sizeof(*data
);
987 struct window
*win
= get_window( req
->window
);
992 for (i
= count
= 0; i
< win
->prop_inuse
; i
++)
993 if (win
->properties
[i
].type
!= PROP_TYPE_FREE
) count
++;
994 reply
->total
= count
;
996 if (count
> max
) count
= max
;
997 if (!count
|| !(data
= set_reply_data_size( count
* sizeof(*data
) ))) return;
999 for (i
= 0; i
< win
->prop_inuse
&& count
; i
++)
1001 if (win
->properties
[i
].type
== PROP_TYPE_FREE
) continue;
1002 data
->atom
= win
->properties
[i
].atom
;
1003 data
->string
= (win
->properties
[i
].type
== PROP_TYPE_STRING
);
1004 data
->handle
= win
->properties
[i
].handle
;
1011 /* get the new window pointer for a global window, checking permissions */
1012 /* helper for set_global_windows request */
1013 static int get_new_global_window( struct window
**win
, user_handle_t handle
)
1022 set_error( STATUS_ACCESS_DENIED
);
1025 *win
= get_window( handle
);
1026 return (*win
!= NULL
);
1029 /* Set/get the global windows */
1030 DECL_HANDLER(set_global_windows
)
1032 struct window
*new_shell_window
= shell_window
;
1033 struct window
*new_shell_listview
= shell_listview
;
1034 struct window
*new_progman_window
= progman_window
;
1035 struct window
*new_taskman_window
= taskman_window
;
1037 reply
->old_shell_window
= shell_window
? shell_window
->handle
: 0;
1038 reply
->old_shell_listview
= shell_listview
? shell_listview
->handle
: 0;
1039 reply
->old_progman_window
= progman_window
? progman_window
->handle
: 0;
1040 reply
->old_taskman_window
= taskman_window
? taskman_window
->handle
: 0;
1042 if (req
->flags
& SET_GLOBAL_SHELL_WINDOWS
)
1044 if (!get_new_global_window( &new_shell_window
, req
->shell_window
)) return;
1045 if (!get_new_global_window( &new_shell_listview
, req
->shell_listview
)) return;
1047 if (req
->flags
& SET_GLOBAL_PROGMAN_WINDOW
)
1049 if (!get_new_global_window( &new_progman_window
, req
->progman_window
)) return;
1051 if (req
->flags
& SET_GLOBAL_TASKMAN_WINDOW
)
1053 if (!get_new_global_window( &new_taskman_window
, req
->taskman_window
)) return;
1055 shell_window
= new_shell_window
;
1056 shell_listview
= new_shell_listview
;
1057 progman_window
= new_progman_window
;
1058 taskman_window
= new_taskman_window
;