Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Server-side window handling |
| 3 | * |
| 4 | * Copyright (C) 2001 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 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 |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Alexandre Julliard | 5769d1d | 2002-04-26 19:05:15 +0000 | [diff] [blame] | 21 | #include "config.h" |
| 22 | #include "wine/port.h" |
| 23 | |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 24 | #include <assert.h> |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 25 | #include <stdarg.h> |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 26 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 27 | #include "windef.h" |
Alexandre Julliard | 47f9821 | 2001-11-14 21:28:36 +0000 | [diff] [blame] | 28 | #include "winbase.h" |
| 29 | #include "wingdi.h" |
| 30 | #include "winuser.h" |
| 31 | |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 32 | #include "object.h" |
| 33 | #include "request.h" |
| 34 | #include "thread.h" |
| 35 | #include "process.h" |
| 36 | #include "user.h" |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 37 | #include "unicode.h" |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 38 | |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 39 | /* a window property */ |
| 40 | struct property |
| 41 | { |
| 42 | unsigned short type; /* property type (see below) */ |
| 43 | atom_t atom; /* property atom */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 44 | obj_handle_t handle; /* property handle (user-defined storage) */ |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 55 | struct window |
| 56 | { |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 57 | struct window *parent; /* parent window */ |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 58 | user_handle_t owner; /* owner of this window */ |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 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 */ |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 66 | atom_t atom; /* class atom */ |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 67 | user_handle_t last_active; /* last active popup */ |
Alexandre Julliard | 0d50965 | 2001-10-16 21:55:37 +0000 | [diff] [blame] | 68 | rectangle_t window_rect; /* window rectangle */ |
| 69 | rectangle_t client_rect; /* client rectangle */ |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 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 */ |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 75 | WCHAR *text; /* window caption text */ |
| 76 | int paint_count; /* count of pending paints for this window */ |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 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 */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | static struct window *top_window; /* top-level (desktop) window */ |
| 83 | |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 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 | { |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 112 | unlink_window( win ); /* unlink it from the previous location */ |
| 113 | |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 114 | if (parent) |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 115 | { |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 116 | win->parent = parent; |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 117 | if ((win->prev = previous)) |
| 118 | { |
| 119 | if ((win->next = previous->next)) win->next->prev = win; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 120 | else if (win->parent->last_child == previous) win->parent->last_child = win; |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 121 | win->prev->next = win; |
| 122 | } |
| 123 | else |
| 124 | { |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 125 | if ((win->next = parent->first_child)) win->next->prev = win; |
| 126 | else win->parent->last_child = win; |
| 127 | parent->first_child = win; |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 128 | } |
| 129 | } |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 130 | else /* move it to parent unlinked list */ |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 131 | { |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 132 | parent = win->parent; |
| 133 | if ((win->next = parent->first_unlinked)) win->next->prev = win; |
| 134 | win->prev = NULL; |
| 135 | parent->first_unlinked = win; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 136 | } |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 139 | /* set a window property */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 140 | static void set_property( struct window *win, atom_t atom, obj_handle_t handle, |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 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 */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 188 | static obj_handle_t remove_property( struct window *win, atom_t atom ) |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 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 */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 207 | static obj_handle_t get_property( struct window *win, atom_t atom ) |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 234 | /* destroy a window */ |
| 235 | static void destroy_window( struct window *win ) |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 236 | { |
| 237 | assert( win != top_window ); |
| 238 | |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 239 | /* destroy all children */ |
| 240 | while (win->first_child) destroy_window( win->first_child ); |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 241 | while (win->first_unlinked) destroy_window( win->first_unlinked ); |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 242 | |
Alexandre Julliard | e806c97 | 2001-11-24 03:44:47 +0000 | [diff] [blame] | 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 | } |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 248 | free_user_handle( win->handle ); |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 249 | destroy_properties( win ); |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 250 | unlink_window( win ); |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 251 | if (win->text) free( win->text ); |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 252 | memset( win, 0x55, sizeof(*win) ); |
| 253 | free( win ); |
| 254 | } |
| 255 | |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 256 | /* create a new window structure (note: the window is not linked in the window tree) */ |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 257 | static struct window *create_window( struct window *parent, struct window *owner, atom_t atom ) |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 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 | } |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 267 | win->parent = parent; |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 268 | win->owner = owner ? owner->handle : 0; |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 269 | win->first_child = NULL; |
| 270 | win->last_child = NULL; |
| 271 | win->first_unlinked = NULL; |
| 272 | win->thread = current; |
| 273 | win->atom = atom; |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 274 | win->last_active = win->handle; |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 275 | win->style = 0; |
| 276 | win->ex_style = 0; |
| 277 | win->id = 0; |
| 278 | win->instance = NULL; |
| 279 | win->user_data = NULL; |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 280 | win->text = NULL; |
| 281 | win->paint_count = 0; |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 282 | win->prop_inuse = 0; |
| 283 | win->prop_alloc = 0; |
| 284 | win->properties = NULL; |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | ab5063b | 2002-10-11 18:50:15 +0000 | [diff] [blame] | 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 ); |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 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; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 309 | destroy_window( win ); |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 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 | { |
Alexandre Julliard | 3783e49 | 2003-01-08 19:55:08 +0000 | [diff] [blame] | 351 | struct window *ptr; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 352 | |
Alexandre Julliard | 3783e49 | 2003-01-08 19:55:08 +0000 | [diff] [blame] | 353 | for (ptr = parent->first_child; ptr; ptr = ptr->next) |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 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 | } |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 388 | |
Alexandre Julliard | 81f2a73 | 2002-03-23 20:43:52 +0000 | [diff] [blame] | 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 | } |
Alexandre Julliard | 47f9821 | 2001-11-14 21:28:36 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 437 | /* create a window */ |
| 438 | DECL_HANDLER(create_window) |
| 439 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 440 | reply->handle = 0; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 441 | if (!req->parent) /* return desktop window */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 442 | { |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 443 | if (!top_window) |
| 444 | { |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 445 | if (!(top_window = create_window( NULL, NULL, req->atom ))) return; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 446 | top_window->thread = NULL; /* no thread owns the desktop */ |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 447 | top_window->style = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 448 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 449 | reply->handle = top_window->handle; |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 450 | } |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 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; |
Alexandre Julliard | 4a9c839 | 2001-11-06 17:54:15 +0000 | [diff] [blame] | 457 | if (owner == top_window) owner = NULL; |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 458 | else if (owner && parent != top_window) |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 459 | { |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 460 | /* an owned window must be created as top-level */ |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 461 | set_error( STATUS_ACCESS_DENIED ); |
| 462 | return; |
| 463 | } |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 464 | if (!(win = create_window( parent, owner, req->atom ))) return; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 465 | reply->handle = win->handle; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 466 | } |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 475 | if (!(win = get_window( req->handle ))) return; |
| 476 | if (req->parent && !(parent = get_window( req->parent ))) return; |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 477 | |
| 478 | if (win == top_window) |
| 479 | { |
| 480 | set_error( STATUS_INVALID_PARAMETER ); |
| 481 | return; |
| 482 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 483 | reply->full_parent = parent ? parent->handle : 0; |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 484 | if (parent && req->previous) |
| 485 | { |
Alexandre Julliard | 5af055d | 2001-09-24 01:13:48 +0000 | [diff] [blame] | 486 | if (req->previous == (user_handle_t)1) /* special case: HWND_BOTTOM */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 487 | { |
Alexandre Julliard | 5af055d | 2001-09-24 01:13:48 +0000 | [diff] [blame] | 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 | } |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | link_window( win, parent, previous ); |
| 503 | } |
| 504 | |
| 505 | |
| 506 | /* destroy a window */ |
| 507 | DECL_HANDLER(destroy_window) |
| 508 | { |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 509 | struct window *win = get_window( req->handle ); |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 510 | if (win) |
| 511 | { |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 512 | if (win != top_window) destroy_window( win ); |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 513 | else set_error( STATUS_ACCESS_DENIED ); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 518 | /* set a window owner */ |
| 519 | DECL_HANDLER(set_window_owner) |
| 520 | { |
| 521 | struct window *win = get_window( req->handle ); |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 522 | struct window *owner = NULL; |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 523 | |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 524 | if (!win) return; |
| 525 | if (req->owner && !(owner = get_window( req->owner ))) return; |
| 526 | if (win == top_window) |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 527 | { |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 528 | set_error( STATUS_ACCESS_DENIED ); |
| 529 | return; |
| 530 | } |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 531 | reply->prev_owner = win->owner; |
| 532 | reply->full_owner = win->owner = owner ? owner->handle : 0; |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 536 | /* get information from a window handle */ |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 537 | DECL_HANDLER(get_window_info) |
| 538 | { |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 539 | struct window *win = get_window( req->handle ); |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 540 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 541 | reply->full_handle = 0; |
| 542 | reply->tid = reply->pid = 0; |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 543 | if (win) |
| 544 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 545 | reply->full_handle = win->handle; |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 546 | reply->last_active = win->handle; |
| 547 | if (get_user_object( win->last_active, USER_WINDOW )) reply->last_active = win->last_active; |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 548 | if (win->thread) |
| 549 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 550 | reply->tid = get_thread_id( win->thread ); |
| 551 | reply->pid = get_process_id( win->thread->process ); |
| 552 | reply->atom = win->atom; |
Alexandre Julliard | 1a66d22 | 2001-08-28 18:44:52 +0000 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | } |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 556 | |
| 557 | |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 558 | /* set some information in a window */ |
| 559 | DECL_HANDLER(set_window_info) |
| 560 | { |
| 561 | struct window *win = get_window( req->handle ); |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 562 | |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 563 | if (!win) return; |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 564 | if (req->flags && win == top_window) |
| 565 | { |
| 566 | set_error( STATUS_ACCESS_DENIED ); |
| 567 | return; |
| 568 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 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; |
Alexandre Julliard | ddc3317 | 2001-10-22 19:08:33 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 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; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 587 | user_handle_t *data; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 588 | size_t len; |
| 589 | |
| 590 | if (win) for (ptr = win->parent; ptr; ptr = ptr->parent) total++; |
| 591 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 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 )))) |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 595 | { |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 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; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 607 | user_handle_t *data; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 608 | size_t len; |
| 609 | |
| 610 | if (parent) |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 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 | } |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 617 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 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 )))) |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 621 | { |
Uwe Bonnes | 4f7d893 | 2002-04-11 17:32:10 +0000 | [diff] [blame] | 622 | for (ptr = parent->first_child; ptr && len; ptr = ptr->next) |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 623 | { |
| 624 | if (req->atom && ptr->atom != req->atom) continue; |
| 625 | if (req->tid && get_thread_id(ptr->thread) != req->tid) continue; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 626 | *data++ = ptr->handle; |
Uwe Bonnes | 4f7d893 | 2002-04-11 17:32:10 +0000 | [diff] [blame] | 627 | len -= sizeof(*data); |
Alexandre Julliard | 844ceb9 | 2001-10-09 23:26:40 +0000 | [diff] [blame] | 628 | } |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 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; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 643 | reply->parent = parent->handle; |
Alexandre Julliard | 7dafa61 | 2002-09-25 00:21:56 +0000 | [diff] [blame] | 644 | reply->owner = win->owner; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 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; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 649 | } |
| 650 | else |
| 651 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 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; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 658 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 659 | reply->first_child = win->first_child ? win->first_child->handle : 0; |
| 660 | reply->last_child = win->last_child ? win->last_child->handle : 0; |
Alexandre Julliard | a09da0c | 2001-09-21 21:08:40 +0000 | [diff] [blame] | 661 | } |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 662 | |
| 663 | |
Alexandre Julliard | 0d50965 | 2001-10-16 21:55:37 +0000 | [diff] [blame] | 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 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 684 | reply->window = win->window_rect; |
| 685 | reply->client = win->client_rect; |
Alexandre Julliard | 0d50965 | 2001-10-16 21:55:37 +0000 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | |
| 689 | |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 690 | /* get the window text */ |
| 691 | DECL_HANDLER(get_window_text) |
| 692 | { |
| 693 | struct window *win = get_window( req->handle ); |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 694 | |
| 695 | if (win && win->text) |
| 696 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 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 ); |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 700 | } |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 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; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 712 | size_t len = get_req_data_size() / sizeof(WCHAR); |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 713 | if (len) |
| 714 | { |
| 715 | if (!(text = mem_alloc( (len+1) * sizeof(WCHAR) ))) return; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 716 | memcpy( text, get_req_data(), len * sizeof(WCHAR) ); |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | 47f9821 | 2001-11-14 21:28:36 +0000 | [diff] [blame] | 730 | if (win && win->thread) |
Alexandre Julliard | 805bdc5 | 2001-11-13 22:23:48 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | 0d50965 | 2001-10-16 21:55:37 +0000 | [diff] [blame] | 739 | /* get the coordinates offset between two windows */ |
| 740 | DECL_HANDLER(get_windows_offset) |
| 741 | { |
| 742 | struct window *win; |
| 743 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 744 | reply->x = reply->y = 0; |
Alexandre Julliard | 0d50965 | 2001-10-16 21:55:37 +0000 | [diff] [blame] | 745 | if (req->from) |
| 746 | { |
| 747 | if (!(win = get_window( req->from ))) return; |
| 748 | while (win) |
| 749 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 750 | reply->x += win->client_rect.left; |
| 751 | reply->y += win->client_rect.top; |
Alexandre Julliard | 0d50965 | 2001-10-16 21:55:37 +0000 | [diff] [blame] | 752 | win = win->parent; |
| 753 | } |
| 754 | } |
| 755 | if (req->to) |
| 756 | { |
| 757 | if (!(win = get_window( req->to ))) return; |
| 758 | while (win) |
| 759 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 760 | reply->x -= win->client_rect.left; |
| 761 | reply->y -= win->client_rect.top; |
Alexandre Julliard | 0d50965 | 2001-10-16 21:55:37 +0000 | [diff] [blame] | 762 | win = win->parent; |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 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 ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 782 | reply->handle = 0; |
| 783 | if (win) reply->handle = remove_property( win, req->atom ); |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | |
| 787 | /* get a window property */ |
| 788 | DECL_HANDLER(get_window_property) |
| 789 | { |
| 790 | struct window *win = get_window( req->window ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 791 | reply->handle = 0; |
| 792 | if (win) reply->handle = get_property( win, req->atom ); |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | |
| 796 | /* get the list of properties of a window */ |
| 797 | DECL_HANDLER(get_window_properties) |
| 798 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 799 | property_data_t *data; |
| 800 | int i, count, max = get_reply_max_size() / sizeof(*data); |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 801 | struct window *win = get_window( req->window ); |
| 802 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 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 | } |
Alexandre Julliard | 7a2017d | 2001-10-12 19:10:26 +0000 | [diff] [blame] | 822 | } |