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