Fix the case of product and company names.
[wine] / server / window.c
1 /*
2  * Server-side window handling
3  *
4  * Copyright (C) 2001 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <assert.h>
25 #include <stdarg.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31
32 #include "object.h"
33 #include "request.h"
34 #include "thread.h"
35 #include "process.h"
36 #include "user.h"
37 #include "unicode.h"
38
39 /* a window property */
40 struct property
41 {
42     unsigned short type;     /* property type (see below) */
43     atom_t         atom;     /* property atom */
44     obj_handle_t   handle;   /* property handle (user-defined storage) */
45 };
46
47 enum property_type
48 {
49     PROP_TYPE_FREE,   /* free entry */
50     PROP_TYPE_STRING, /* atom that was originally a string */
51     PROP_TYPE_ATOM    /* plain atom */
52 };
53
54
55 struct window
56 {
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     atom_t           atom;            /* class atom */
67     user_handle_t    last_active;     /* last active popup */
68     rectangle_t      window_rect;     /* window rectangle */
69     rectangle_t      client_rect;     /* client rectangle */
70     unsigned int     style;           /* window style */
71     unsigned int     ex_style;        /* window extended style */
72     unsigned int     id;              /* window id */
73     void*            instance;        /* creator instance */
74     void*            user_data;       /* user-specific data */
75     WCHAR           *text;            /* window caption text */
76     int              paint_count;     /* count of pending paints for this window */
77     int              prop_inuse;      /* number of in-use window properties */
78     int              prop_alloc;      /* number of allocated window properties */
79     struct property *properties;      /* window properties array */
80 };
81
82 static struct window *top_window;  /* top-level (desktop) window */
83
84
85 /* retrieve a pointer to a window from its handle */
86 inline static struct window *get_window( user_handle_t handle )
87 {
88     struct window *ret = get_user_object( handle, USER_WINDOW );
89     if (!ret) set_error( STATUS_INVALID_HANDLE );
90     return ret;
91 }
92
93 /* unlink a window from the tree */
94 static void unlink_window( struct window *win )
95 {
96     struct window *parent = win->parent;
97
98     assert( parent );
99
100     if (win->next) win->next->prev = win->prev;
101     else if (parent->last_child == win) parent->last_child = win->prev;
102
103     if (win->prev) win->prev->next = win->next;
104     else if (parent->first_child == win) parent->first_child = win->next;
105     else if (parent->first_unlinked == win) parent->first_unlinked = win->next;
106 }
107
108
109 /* link a window into the tree (or unlink it if the new parent is NULL)  */
110 static void link_window( struct window *win, struct window *parent, struct window *previous )
111 {
112     unlink_window( win );  /* unlink it from the previous location */
113
114     if (parent)
115     {
116         win->parent = parent;
117         if ((win->prev = previous))
118         {
119             if ((win->next = previous->next)) win->next->prev = win;
120             else if (win->parent->last_child == previous) win->parent->last_child = win;
121             win->prev->next = win;
122         }
123         else
124         {
125             if ((win->next = parent->first_child)) win->next->prev = win;
126             else win->parent->last_child = win;
127             parent->first_child = win;
128         }
129     }
130     else  /* move it to parent unlinked list */
131     {
132         parent = win->parent;
133         if ((win->next = parent->first_unlinked)) win->next->prev = win;
134         win->prev = NULL;
135         parent->first_unlinked = win;
136     }
137 }
138
139 /* set a window property */
140 static void set_property( struct window *win, atom_t atom, obj_handle_t handle,
141                           enum property_type type )
142 {
143     int i, free = -1;
144     struct property *new_props;
145
146     /* check if it exists already */
147     for (i = 0; i < win->prop_inuse; i++)
148     {
149         if (win->properties[i].type == PROP_TYPE_FREE)
150         {
151             free = i;
152             continue;
153         }
154         if (win->properties[i].atom == atom)
155         {
156             win->properties[i].type = type;
157             win->properties[i].handle = handle;
158             return;
159         }
160     }
161
162     /* need to add an entry */
163     if (!grab_global_atom( atom )) return;
164     if (free == -1)
165     {
166         /* no free entry */
167         if (win->prop_inuse >= win->prop_alloc)
168         {
169             /* need to grow the array */
170             if (!(new_props = realloc( win->properties,
171                                        sizeof(*new_props) * (win->prop_alloc + 16) )))
172             {
173                 set_error( STATUS_NO_MEMORY );
174                 release_global_atom( atom );
175                 return;
176             }
177             win->prop_alloc += 16;
178             win->properties = new_props;
179         }
180         free = win->prop_inuse++;
181     }
182     win->properties[free].atom   = atom;
183     win->properties[free].type   = type;
184     win->properties[free].handle = handle;
185 }
186
187 /* remove a window property */
188 static obj_handle_t remove_property( struct window *win, atom_t atom )
189 {
190     int i;
191
192     for (i = 0; i < win->prop_inuse; i++)
193     {
194         if (win->properties[i].type == PROP_TYPE_FREE) continue;
195         if (win->properties[i].atom == atom)
196         {
197             release_global_atom( atom );
198             win->properties[i].type = PROP_TYPE_FREE;
199             return win->properties[i].handle;
200         }
201     }
202     /* FIXME: last error? */
203     return 0;
204 }
205
206 /* find a window property */
207 static obj_handle_t get_property( struct window *win, atom_t atom )
208 {
209     int i;
210
211     for (i = 0; i < win->prop_inuse; i++)
212     {
213         if (win->properties[i].type == PROP_TYPE_FREE) continue;
214         if (win->properties[i].atom == atom) return win->properties[i].handle;
215     }
216     /* FIXME: last error? */
217     return 0;
218 }
219
220 /* destroy all properties of a window */
221 inline static void destroy_properties( struct window *win )
222 {
223     int i;
224
225     if (!win->properties) return;
226     for (i = 0; i < win->prop_inuse; i++)
227     {
228         if (win->properties[i].type == PROP_TYPE_FREE) continue;
229         release_global_atom( win->properties[i].atom );
230     }
231     free( win->properties );
232 }
233
234 /* destroy a window */
235 static void destroy_window( struct window *win )
236 {
237     assert( win != top_window );
238
239     /* destroy all children */
240     while (win->first_child) destroy_window( win->first_child );
241     while (win->first_unlinked) destroy_window( win->first_unlinked );
242
243     if (win->thread->queue)
244     {
245         if (win->paint_count) inc_queue_paint_count( win->thread, -win->paint_count );
246         queue_cleanup_window( win->thread, win->handle );
247     }
248     free_user_handle( win->handle );
249     destroy_properties( win );
250     unlink_window( win );
251     if (win->text) free( win->text );
252     memset( win, 0x55, sizeof(*win) );
253     free( win );
254 }
255
256 /* create a new window structure (note: the window is not linked in the window tree) */
257 static struct window *create_window( struct window *parent, struct window *owner, atom_t atom )
258 {
259     struct window *win = mem_alloc( sizeof(*win) );
260     if (!win) return NULL;
261
262     if (!(win->handle = alloc_user_handle( win, USER_WINDOW )))
263     {
264         free( win );
265         return NULL;
266     }
267     win->parent         = parent;
268     win->owner          = owner ? owner->handle : 0;
269     win->first_child    = NULL;
270     win->last_child     = NULL;
271     win->first_unlinked = NULL;
272     win->thread         = current;
273     win->atom           = atom;
274     win->last_active    = win->handle;
275     win->style          = 0;
276     win->ex_style       = 0;
277     win->id             = 0;
278     win->instance       = NULL;
279     win->user_data      = NULL;
280     win->text           = NULL;
281     win->paint_count    = 0;
282     win->prop_inuse     = 0;
283     win->prop_alloc     = 0;
284     win->properties     = NULL;
285
286     if (parent)  /* put it on parent unlinked list */
287     {
288         if ((win->next = parent->first_unlinked)) win->next->prev = win;
289         win->prev = NULL;
290         parent->first_unlinked = win;
291     }
292     else win->next = win->prev = NULL;
293
294     /* if parent belongs to a different thread, attach the two threads */
295     if (parent && parent->thread && parent->thread != current)
296         attach_thread_input( current, parent->thread );
297     return win;
298 }
299
300 /* destroy all windows belonging to a given thread */
301 void destroy_thread_windows( struct thread *thread )
302 {
303     user_handle_t handle = 0;
304     struct window *win;
305
306     while ((win = next_user_handle( &handle, USER_WINDOW )))
307     {
308         if (win->thread != thread) continue;
309         destroy_window( win );
310     }
311 }
312
313 /* check whether child is a descendant of parent */
314 int is_child_window( user_handle_t parent, user_handle_t child )
315 {
316     struct window *child_ptr = get_user_object( child, USER_WINDOW );
317     struct window *parent_ptr = get_user_object( parent, USER_WINDOW );
318
319     if (!child_ptr || !parent_ptr) return 0;
320     while (child_ptr->parent)
321     {
322         if (child_ptr->parent == parent_ptr) return 1;
323         child_ptr = child_ptr->parent;
324     }
325     return 0;
326 }
327
328 /* check whether window is a top-level window */
329 int is_top_level_window( user_handle_t window )
330 {
331     struct window *win = get_user_object( window, USER_WINDOW );
332     return (win && win->parent == top_window);
333 }
334
335 /* make a window active if possible */
336 int make_window_active( user_handle_t window )
337 {
338     struct window *owner, *win = get_window( window );
339
340     if (!win) return 0;
341
342     /* set last active for window and its owner */
343     win->last_active = win->handle;
344     if ((owner = get_user_object( win->owner, USER_WINDOW ))) owner->last_active = win->handle;
345     return 1;
346 }
347
348 /* find child of 'parent' that contains the given point (in parent-relative coords) */
349 static struct window *child_window_from_point( struct window *parent, int x, int y )
350 {
351     struct window *ptr;
352
353     for (ptr = parent->first_child; ptr; ptr = ptr->next)
354     {
355         if (!(ptr->style & WS_VISIBLE)) continue; /* not visible -> skip */
356         if ((ptr->style & (WS_POPUP|WS_CHILD|WS_DISABLED)) == (WS_CHILD|WS_DISABLED))
357             continue;  /* disabled child -> skip */
358         if ((ptr->ex_style & (WS_EX_LAYERED|WS_EX_TRANSPARENT)) == (WS_EX_LAYERED|WS_EX_TRANSPARENT))
359             continue;  /* transparent -> skip */
360         if (x < ptr->window_rect.left || x >= ptr->window_rect.right ||
361             y < ptr->window_rect.top || y >= ptr->window_rect.bottom)
362             continue;  /* not in window -> skip */
363
364         /* FIXME: check window region here */
365
366         /* if window is minimized or disabled, return at once */
367         if (ptr->style & (WS_MINIMIZE|WS_DISABLED)) return ptr;
368
369         /* if point is not in client area, return at once */
370         if (x < ptr->client_rect.left || x >= ptr->client_rect.right ||
371             y < ptr->client_rect.top || y >= ptr->client_rect.bottom)
372             return ptr;
373
374         return child_window_from_point( ptr, x - ptr->client_rect.left, y - ptr->client_rect.top );
375     }
376     return parent;  /* not found any child */
377 }
378
379 /* find window containing point (in absolute coords) */
380 user_handle_t window_from_point( int x, int y )
381 {
382     struct window *ret;
383
384     if (!top_window) return 0;
385     ret = child_window_from_point( top_window, x, y );
386     return ret->handle;
387 }
388
389 /* return the thread owning a window */
390 struct thread *get_window_thread( user_handle_t handle )
391 {
392     struct window *win = get_user_object( handle, USER_WINDOW );
393     if (!win || !win->thread) return NULL;
394     return (struct thread *)grab_object( win->thread );
395 }
396
397 /* find a child of the specified window that needs repainting */
398 static struct window *find_child_to_repaint( struct window *parent, struct thread *thread )
399 {
400     struct window *ptr, *ret = NULL;
401
402     for (ptr = parent->first_child; ptr && !ret; ptr = ptr->next)
403     {
404         if (!(ptr->style & WS_VISIBLE)) continue;
405         if (ptr->paint_count && ptr->thread == thread)
406             ret = ptr;
407         else /* explore its children */
408             ret = find_child_to_repaint( ptr, thread );
409     }
410
411     if (ret && (ret->ex_style & WS_EX_TRANSPARENT))
412     {
413         /* transparent window, check for non-transparent sibling to paint first */
414         for (ptr = ret->next; ptr; ptr = ptr->next)
415         {
416             if (!(ptr->style & WS_VISIBLE)) continue;
417             if (ptr->ex_style & WS_EX_TRANSPARENT) continue;
418             if (ptr->paint_count && ptr->thread == thread) return ptr;
419         }
420     }
421     return ret;
422 }
423
424
425 /* find a window that needs repainting */
426 user_handle_t find_window_to_repaint( user_handle_t parent, struct thread *thread )
427 {
428     struct window *win = parent ? get_window( parent ) : top_window;
429
430     if (!win || !(win->style & WS_VISIBLE)) return 0;
431     if (!win->paint_count || win->thread != thread)
432         win = find_child_to_repaint( win, thread );
433     return win ? win->handle : 0;
434 }
435
436
437 /* create a window */
438 DECL_HANDLER(create_window)
439 {
440     reply->handle = 0;
441     if (!req->parent)  /* return desktop window */
442     {
443         if (!top_window)
444         {
445             if (!(top_window = create_window( NULL, NULL, req->atom ))) return;
446             top_window->thread = NULL;  /* no thread owns the desktop */
447             top_window->style  = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
448         }
449         reply->handle = top_window->handle;
450     }
451     else
452     {
453         struct window *win, *parent, *owner = NULL;
454
455         if (!(parent = get_window( req->parent ))) return;
456         if (req->owner && !(owner = get_window( req->owner ))) return;
457         if (owner == top_window) owner = NULL;
458         else if (owner && parent != top_window)
459         {
460             /* an owned window must be created as top-level */
461             set_error( STATUS_ACCESS_DENIED );
462             return;
463         }
464         if (!(win = create_window( parent, owner, req->atom ))) return;
465         reply->handle = win->handle;
466     }
467 }
468
469
470 /* link a window into the tree */
471 DECL_HANDLER(link_window)
472 {
473     struct window *win, *parent = NULL, *previous = NULL;
474
475     if (!(win = get_window( req->handle ))) return;
476     if (req->parent && !(parent = get_window( req->parent ))) return;
477
478     if (win == top_window)
479     {
480         set_error( STATUS_INVALID_PARAMETER );
481         return;
482     }
483     reply->full_parent = parent ? parent->handle : 0;
484     if (parent && req->previous)
485     {
486         if (req->previous == (user_handle_t)1)  /* special case: HWND_BOTTOM */
487         {
488             previous = parent->last_child;
489             if (previous == win) return;  /* nothing to do */
490         }
491         else
492         {
493             if (!(previous = get_window( req->previous ))) return;
494             /* previous must be a child of parent, and not win itself */
495             if (previous->parent != parent || previous == win)
496             {
497                 set_error( STATUS_INVALID_PARAMETER );
498                 return;
499             }
500         }
501     }
502     link_window( win, parent, previous );
503 }
504
505
506 /* destroy a window */
507 DECL_HANDLER(destroy_window)
508 {
509     struct window *win = get_window( req->handle );
510     if (win)
511     {
512         if (win != top_window) destroy_window( win );
513         else set_error( STATUS_ACCESS_DENIED );
514     }
515 }
516
517
518 /* set a window owner */
519 DECL_HANDLER(set_window_owner)
520 {
521     struct window *win = get_window( req->handle );
522     struct window *owner = NULL;
523
524     if (!win) return;
525     if (req->owner && !(owner = get_window( req->owner ))) return;
526     if (win == top_window)
527     {
528         set_error( STATUS_ACCESS_DENIED );
529         return;
530     }
531     reply->prev_owner = win->owner;
532     reply->full_owner = win->owner = owner ? owner->handle : 0;
533 }
534
535
536 /* get information from a window handle */
537 DECL_HANDLER(get_window_info)
538 {
539     struct window *win = get_window( req->handle );
540
541     reply->full_handle = 0;
542     reply->tid = reply->pid = 0;
543     if (win)
544     {
545         reply->full_handle = win->handle;
546         reply->last_active = win->handle;
547         if (get_user_object( win->last_active, USER_WINDOW )) reply->last_active = win->last_active;
548         if (win->thread)
549         {
550             reply->tid  = get_thread_id( win->thread );
551             reply->pid  = get_process_id( win->thread->process );
552             reply->atom = win->atom;
553         }
554     }
555 }
556
557
558 /* set some information in a window */
559 DECL_HANDLER(set_window_info)
560 {
561     struct window *win = get_window( req->handle );
562
563     if (!win) return;
564     if (req->flags && win == top_window)
565     {
566         set_error( STATUS_ACCESS_DENIED );
567         return;
568     }
569     reply->old_style     = win->style;
570     reply->old_ex_style  = win->ex_style;
571     reply->old_id        = win->id;
572     reply->old_instance  = win->instance;
573     reply->old_user_data = win->user_data;
574     if (req->flags & SET_WIN_STYLE) win->style = req->style;
575     if (req->flags & SET_WIN_EXSTYLE) win->ex_style = req->ex_style;
576     if (req->flags & SET_WIN_ID) win->id = req->id;
577     if (req->flags & SET_WIN_INSTANCE) win->instance = req->instance;
578     if (req->flags & SET_WIN_USERDATA) win->user_data = req->user_data;
579 }
580
581
582 /* get a list of the window parents, up to the root of the tree */
583 DECL_HANDLER(get_window_parents)
584 {
585     struct window *ptr, *win = get_window( req->handle );
586     int total = 0;
587     user_handle_t *data;
588     size_t len;
589
590     if (win) for (ptr = win->parent; ptr; ptr = ptr->parent) total++;
591
592     reply->count = total;
593     len = min( get_reply_max_size(), total * sizeof(user_handle_t) );
594     if (len && ((data = set_reply_data_size( len ))))
595     {
596         for (ptr = win->parent; ptr && len; ptr = ptr->parent, len -= sizeof(*data))
597             *data++ = ptr->handle;
598     }
599 }
600
601
602 /* get a list of the window children */
603 DECL_HANDLER(get_window_children)
604 {
605     struct window *ptr, *parent = get_window( req->parent );
606     int total = 0;
607     user_handle_t *data;
608     size_t len;
609
610     if (parent)
611         for (ptr = parent->first_child, total = 0; ptr; ptr = ptr->next)
612         {
613             if (req->atom && ptr->atom != req->atom) continue;
614             if (req->tid && get_thread_id(ptr->thread) != req->tid) continue;
615             total++;
616         }
617
618     reply->count = total;
619     len = min( get_reply_max_size(), total * sizeof(user_handle_t) );
620     if (len && ((data = set_reply_data_size( len ))))
621     {
622         for (ptr = parent->first_child; ptr && len; ptr = ptr->next)
623         {
624             if (req->atom && ptr->atom != req->atom) continue;
625             if (req->tid && get_thread_id(ptr->thread) != req->tid) continue;
626             *data++ = ptr->handle;
627             len -= sizeof(*data);
628         }
629     }
630 }
631
632
633 /* get window tree information from a window handle */
634 DECL_HANDLER(get_window_tree)
635 {
636     struct window *win = get_window( req->handle );
637
638     if (!win) return;
639
640     if (win->parent)
641     {
642         struct window *parent = win->parent;
643         reply->parent        = parent->handle;
644         reply->owner         = win->owner;
645         reply->next_sibling  = win->next ? win->next->handle : 0;
646         reply->prev_sibling  = win->prev ? win->prev->handle : 0;
647         reply->first_sibling = parent->first_child ? parent->first_child->handle : 0;
648         reply->last_sibling  = parent->last_child ? parent->last_child->handle : 0;
649     }
650     else
651     {
652         reply->parent        = 0;
653         reply->owner         = 0;
654         reply->next_sibling  = 0;
655         reply->prev_sibling  = 0;
656         reply->first_sibling = 0;
657         reply->last_sibling  = 0;
658     }
659     reply->first_child = win->first_child ? win->first_child->handle : 0;
660     reply->last_child  = win->last_child ? win->last_child->handle : 0;
661 }
662
663
664 /* set the window and client rectangles of a window */
665 DECL_HANDLER(set_window_rectangles)
666 {
667     struct window *win = get_window( req->handle );
668
669     if (win)
670     {
671         win->window_rect = req->window;
672         win->client_rect = req->client;
673     }
674 }
675
676
677 /* get the window and client rectangles of a window */
678 DECL_HANDLER(get_window_rectangles)
679 {
680     struct window *win = get_window( req->handle );
681
682     if (win)
683     {
684         reply->window = win->window_rect;
685         reply->client = win->client_rect;
686     }
687 }
688
689
690 /* get the window text */
691 DECL_HANDLER(get_window_text)
692 {
693     struct window *win = get_window( req->handle );
694
695     if (win && win->text)
696     {
697         size_t len = strlenW( win->text ) * sizeof(WCHAR);
698         if (len > get_reply_max_size()) len = get_reply_max_size();
699         set_reply_data( win->text, len );
700     }
701 }
702
703
704 /* set the window text */
705 DECL_HANDLER(set_window_text)
706 {
707     struct window *win = get_window( req->handle );
708
709     if (win)
710     {
711         WCHAR *text = NULL;
712         size_t len = get_req_data_size() / sizeof(WCHAR);
713         if (len)
714         {
715             if (!(text = mem_alloc( (len+1) * sizeof(WCHAR) ))) return;
716             memcpy( text, get_req_data(), len * sizeof(WCHAR) );
717             text[len] = 0;
718         }
719         if (win->text) free( win->text );
720         win->text = text;
721     }
722 }
723
724
725 /* increment the window paint count */
726 DECL_HANDLER(inc_window_paint_count)
727 {
728     struct window *win = get_window( req->handle );
729
730     if (win && win->thread)
731     {
732         int old = win->paint_count;
733         if ((win->paint_count += req->incr) < 0) win->paint_count = 0;
734         inc_queue_paint_count( win->thread, win->paint_count - old );
735     }
736 }
737
738
739 /* get the coordinates offset between two windows */
740 DECL_HANDLER(get_windows_offset)
741 {
742     struct window *win;
743
744     reply->x = reply->y = 0;
745     if (req->from)
746     {
747         if (!(win = get_window( req->from ))) return;
748         while (win)
749         {
750             reply->x += win->client_rect.left;
751             reply->y += win->client_rect.top;
752             win = win->parent;
753         }
754     }
755     if (req->to)
756     {
757         if (!(win = get_window( req->to ))) return;
758         while (win)
759         {
760             reply->x -= win->client_rect.left;
761             reply->y -= win->client_rect.top;
762             win = win->parent;
763         }
764     }
765 }
766
767
768 /* set a window property */
769 DECL_HANDLER(set_window_property)
770 {
771     struct window *win = get_window( req->window );
772
773     if (win) set_property( win, req->atom, req->handle,
774                            req->string ? PROP_TYPE_STRING : PROP_TYPE_ATOM );
775 }
776
777
778 /* remove a window property */
779 DECL_HANDLER(remove_window_property)
780 {
781     struct window *win = get_window( req->window );
782     reply->handle = 0;
783     if (win) reply->handle = remove_property( win, req->atom );
784 }
785
786
787 /* get a window property */
788 DECL_HANDLER(get_window_property)
789 {
790     struct window *win = get_window( req->window );
791     reply->handle = 0;
792     if (win) reply->handle = get_property( win, req->atom );
793 }
794
795
796 /* get the list of properties of a window */
797 DECL_HANDLER(get_window_properties)
798 {
799     property_data_t *data;
800     int i, count, max = get_reply_max_size() / sizeof(*data);
801     struct window *win = get_window( req->window );
802
803     reply->total = 0;
804     if (!win) return;
805
806     for (i = count = 0; i < win->prop_inuse; i++)
807         if (win->properties[i].type != PROP_TYPE_FREE) count++;
808     reply->total = count;
809
810     if (count > max) count = max;
811     if (!count || !(data = set_reply_data_size( count * sizeof(*data) ))) return;
812
813     for (i = 0; i < win->prop_inuse && count; i++)
814     {
815         if (win->properties[i].type == PROP_TYPE_FREE) continue;
816         data->atom   = win->properties[i].atom;
817         data->string = (win->properties[i].type == PROP_TYPE_STRING);
818         data->handle = win->properties[i].handle;
819         data++;
820         count--;
821     }
822 }