1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 /* gdkgeometry-win32.c: emulation of 32 bit coordinates within the
21 * limits of Win32 GDI. Just a copy of the X11 version, more or less.
22 * Probably totally bogus in functionality. Just a quick hack, to
23 * get the thing to build. Need to write some test code for it.
24 * Well, need to find out what it is supposed to do first ;-)
26 * The X11 version by Owen Taylor <otaylor@redhat.com>
27 * Copyright Red Hat, Inc. 2000
28 * Win32 hack by Tor Lillqvist <tml@iki.fi>
29 * and Hans Breuer <hans@breuer.org>
32 #include "gdk.h" /* For gdk_rectangle_intersect */
33 #include "gdkregion.h"
34 #include "gdkregion-generic.h"
35 #include "gdkprivate-win32.h"
37 #define SIZE_LIMIT 32000
39 typedef struct _GdkWindowQueueItem GdkWindowQueueItem;
40 typedef struct _GdkWindowParentPos GdkWindowParentPos;
45 GDK_WINDOW_QUEUE_TRANSLATE,
46 GDK_WINDOW_QUEUE_ANTIEXPOSE
49 struct _GdkWindowQueueItem
53 GdkWindowQueueType type;
67 struct _GdkWindowParentPos
73 GdkRectangle clip_rect;
76 static void gdk_window_compute_position (GdkWindowImplWin32 *window,
77 GdkWindowParentPos *parent_pos,
78 GdkWin32PositionInfo *info);
79 static void gdk_window_compute_parent_pos (GdkWindowImplWin32 *window,
80 GdkWindowParentPos *parent_pos);
82 static void gdk_window_premove (GdkWindow *window,
83 GdkWindowParentPos *parent_pos);
84 static void gdk_window_postmove (GdkWindow *window,
85 GdkWindowParentPos *parent_pos);
86 static void gdk_window_queue_translation (GdkWindow *window,
89 static void gdk_window_tmp_unset_bg (GdkWindow *window);
90 static void gdk_window_tmp_reset_bg (GdkWindow *window);
91 static void gdk_window_clip_changed (GdkWindow *window,
92 GdkRectangle *old_clip,
93 GdkRectangle *new_clip);
96 static GSList *translate_queue = NULL;
100 _gdk_windowing_window_get_offsets (GdkWindow *window,
104 GdkWindowImplWin32 *impl =
105 GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
107 *x_offset = impl->position_info.x_offset;
108 *y_offset = impl->position_info.y_offset;
112 _gdk_window_init_position (GdkWindow *window)
114 GdkWindowParentPos parent_pos;
115 GdkWindowImplWin32 *impl;
117 g_return_if_fail (GDK_IS_WINDOW (window));
119 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
121 gdk_window_compute_parent_pos (impl, &parent_pos);
122 gdk_window_compute_position (impl, &parent_pos, &impl->position_info);
126 gdk_window_copy_area_scroll (GdkWindow *window,
127 GdkRectangle *dest_rect,
132 GdkWindowObject *obj = GDK_WINDOW_OBJECT (window);
136 GDK_NOTE (MISC, g_print ("gdk_window_copy_area_scroll: %p %s %d,%d\n",
137 GDK_WINDOW_HWND (window),
138 _gdk_win32_gdkrectangle_to_string (dest_rect),
141 if (dest_rect->width > 0 && dest_rect->height > 0)
144 #ifdef G_ENABLE_DEBUG
148 clipRect.left = dest_rect->x;
149 clipRect.top = dest_rect->y;
150 clipRect.right = clipRect.left + dest_rect->width;
151 clipRect.bottom = clipRect.top + dest_rect->height;
154 clipRect.right -= dx;
158 clipRect.bottom -= dy;
162 gdk_window_queue_translation (window, dx, dy);
164 if (!ScrollWindowEx (GDK_WINDOW_HWND (window),
165 dx, dy, /* in: scroll offsets */
166 NULL, /* in: scroll rect, NULL == entire client area */
167 &clipRect, /* in: restrict to */
168 NULL, /* in: update region */
169 NULL, /* out: update rect */
170 SW_INVALIDATE | SW_SCROLLCHILDREN))
171 WIN32_API_FAILED ("ScrollWindowEx");
174 (GetUpdateRect (GDK_WINDOW_HWND (window), &update_rect, FALSE),
175 g_print ("gdk_window_copy_area_scroll: post-scroll update rect: %s\n",
176 _gdk_win32_rect_to_string (&update_rect))));
179 #if 0 /* Not needed, ScrollWindowEx also scrolls the children. */
180 tmp_list = obj->children;
183 GdkWindow *child = GDK_WINDOW (tmp_list->data);
184 GdkWindowObject *child_obj = GDK_WINDOW_OBJECT (child);
186 gdk_window_move (child, child_obj->x + dx, child_obj->y + dy);
188 tmp_list = tmp_list->next;
194 compute_intermediate_position (GdkWin32PositionInfo *position_info,
195 GdkWin32PositionInfo *new_info,
198 GdkRectangle *new_position)
200 gint new_x0, new_x1, new_y0, new_y1;
202 /* Wrap d_xoffset, d_yoffset into [-32768,32767] range. For the
203 * purposes of subwindow movement, it doesn't matter if we are
204 * off by a factor of 65536, and if we don't do this range
205 * reduction, we'll end up with invalid widths.
207 d_xoffset = (gint16)d_xoffset;
208 d_yoffset = (gint16)d_yoffset;
212 new_x0 = position_info->x + d_xoffset;
213 new_x1 = position_info->x + position_info->width;
217 new_x0 = position_info->x;
218 new_x1 = position_info->x + new_info->width + d_xoffset;
221 new_position->x = new_x0;
222 new_position->width = new_x1 - new_x0;
226 new_y0 = position_info->y + d_yoffset;
227 new_y1 = position_info->y + position_info->height;
231 new_y0 = position_info->y;
232 new_y1 = position_info->y + new_info->height + d_yoffset;
235 new_position->y = new_y0;
236 new_position->height = new_y1 - new_y0;
242 gdk_window_guffaw_scroll (GdkWindow *window,
246 GdkWindowObject *obj = GDK_WINDOW_OBJECT (window);
247 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
249 gint d_xoffset = -dx;
250 gint d_yoffset = -dy;
251 GdkRectangle new_position;
252 GdkWin32PositionInfo new_info;
253 GdkWindowParentPos parent_pos;
256 GDK_NOTE (EVENTS, g_print ("gdk_window_guffaw_scroll: %p %d,%d\n",
257 GDK_WINDOW_HWND (window), dx, dy));
259 gdk_window_compute_parent_pos (impl, &parent_pos);
260 gdk_window_compute_position (impl, &parent_pos, &new_info);
262 parent_pos.x += obj->x;
263 parent_pos.y += obj->y;
264 parent_pos.win32_x += new_info.x;
265 parent_pos.win32_y += new_info.y;
266 parent_pos.clip_rect = new_info.clip_rect;
268 gdk_window_tmp_unset_bg (window);
270 if (d_xoffset < 0 || d_yoffset < 0)
271 gdk_window_queue_translation (window, MIN (d_xoffset, 0), MIN (d_yoffset, 0));
273 gdk_window_set_static_gravities (window, TRUE);
275 compute_intermediate_position (&impl->position_info, &new_info, d_xoffset, d_yoffset,
278 /* XXX: this is only translating the X11 code. Don't know why the
279 * window movement needs to be done in three steps there, and here ??
281 if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
282 new_position.x, new_position.y,
283 new_position.width, new_position.height,
284 SWP_NOACTIVATE | SWP_NOZORDER))
285 WIN32_API_FAILED ("SetWindowPos");
287 tmp_list = obj->children;
290 GDK_WINDOW_OBJECT(tmp_list->data)->x -= d_xoffset;
291 GDK_WINDOW_OBJECT(tmp_list->data)->y -= d_yoffset;
293 gdk_window_premove (tmp_list->data, &parent_pos);
294 tmp_list = tmp_list->next;
297 if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
298 new_position.x - d_xoffset, new_position.y - d_yoffset, 1, 1,
299 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE))
300 WIN32_API_FAILED ("SetWindowPos");
302 if (d_xoffset > 0 || d_yoffset > 0)
303 gdk_window_queue_translation (window, MAX (d_xoffset, 0), MAX (d_yoffset, 0));
305 if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
306 impl->position_info.x, impl->position_info.y,
307 impl->position_info.width, impl->position_info.height,
308 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE))
309 WIN32_API_FAILED ("SetWindowPos");
311 if (impl->position_info.no_bg)
312 gdk_window_tmp_reset_bg (window);
314 impl->position_info = new_info;
316 tmp_list = obj->children;
319 gdk_window_postmove (tmp_list->data, &parent_pos);
320 tmp_list = tmp_list->next;
327 gdk_window_scroll (GdkWindow *window,
332 gboolean can_guffaw_scroll = FALSE;
334 GdkRegion *invalidate_region;
335 GdkWindowImplWin32 *impl;
336 GdkWindowObject *obj;
337 GdkRectangle dest_rect;
339 g_return_if_fail (GDK_IS_WINDOW (window));
341 if (GDK_WINDOW_DESTROYED (window))
344 GDK_NOTE (EVENTS, g_print ("gdk_window_scroll: %p %d,%d\n",
345 GDK_WINDOW_HWND (window), dx, dy));
347 obj = GDK_WINDOW_OBJECT (window);
348 impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
350 if (dx == 0 && dy == 0)
353 /* Move the current invalid region */
354 if (obj->update_area)
355 gdk_region_offset (obj->update_area, dx, dy);
357 invalidate_region = gdk_region_rectangle (&impl->position_info.clip_rect);
359 dest_rect = impl->position_info.clip_rect;
362 gdk_rectangle_intersect (&dest_rect, &impl->position_info.clip_rect, &dest_rect);
364 if (dest_rect.width > 0 && dest_rect.height > 0)
366 GdkRegion *tmp_region;
368 tmp_region = gdk_region_rectangle (&dest_rect);
369 gdk_region_subtract (invalidate_region, tmp_region);
370 gdk_region_destroy (tmp_region);
373 gdk_window_invalidate_region (window, invalidate_region, TRUE);
374 gdk_region_destroy (invalidate_region);
376 /* We can guffaw scroll if we are a child window, and the parent
377 * does not extend beyond our edges. Otherwise, we use XCopyArea, then
378 * move any children later
380 if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
382 GdkWindowImplWin32 *parent_impl = GDK_WINDOW_IMPL_WIN32 (obj->parent->impl);
383 can_guffaw_scroll = ((dx == 0 || (obj->x <= 0 && obj->x + impl->width >= parent_impl->width)) &&
384 (dy == 0 || (obj->y <= 0 && obj->y + impl->height >= parent_impl->height)));
387 if (!obj->children || !can_guffaw_scroll)
388 gdk_window_copy_area_scroll (window, &dest_rect, dx, dy);
390 gdk_window_guffaw_scroll (window, dx, dy);
392 gdk_window_copy_area_scroll (window, &dest_rect, dx, dy);
397 _gdk_window_move_resize_child (GdkWindow *window,
403 GdkWindowImplWin32 *impl;
404 GdkWindowObject *obj;
405 GdkWin32PositionInfo new_info;
406 GdkWindowParentPos parent_pos;
408 gint d_xoffset, d_yoffset;
413 g_return_if_fail (window != NULL);
414 g_return_if_fail (GDK_IS_WINDOW (window));
416 obj = GDK_WINDOW_OBJECT (window);
417 impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
419 GDK_NOTE (MISC, g_print ("_gdk_window_move_resize_child: %s@+%d+%d %dx%d@+%d+%d\n",
420 _gdk_win32_drawable_description (window),
422 width, height, x, y));
427 is_move = dx != 0 || dy != 0;
428 is_resize = impl->width != width || impl->height != height;
430 if (!is_move && !is_resize)
432 GDK_NOTE (MISC, g_print ("...neither move or resize\n"));
436 GDK_NOTE (MISC, g_print ("...%s%s\n", is_move ? "is_move " : "", is_resize ? "is_resize" : ""));
441 impl->height = height;
443 gdk_window_compute_parent_pos (impl, &parent_pos);
444 gdk_window_compute_position (impl, &parent_pos, &new_info);
446 gdk_window_clip_changed (window, &impl->position_info.clip_rect, &new_info.clip_rect);
448 parent_pos.x += obj->x;
449 parent_pos.y += obj->y;
450 parent_pos.win32_x += new_info.x;
451 parent_pos.win32_y += new_info.y;
452 parent_pos.clip_rect = new_info.clip_rect;
454 d_xoffset = new_info.x_offset - impl->position_info.x_offset;
455 d_yoffset = new_info.y_offset - impl->position_info.y_offset;
457 if (d_xoffset != 0 || d_yoffset != 0)
459 GdkRectangle new_position;
461 GDK_NOTE (MISC, g_print ("...d_xoffset=%d d_yoffset=%d\n", d_xoffset, d_yoffset));
463 gdk_window_set_static_gravities (window, TRUE);
465 if (d_xoffset < 0 || d_yoffset < 0)
466 gdk_window_queue_translation (window, MIN (d_xoffset, 0), MIN (d_yoffset, 0));
468 compute_intermediate_position (&impl->position_info, &new_info, d_xoffset, d_yoffset,
471 GDK_NOTE (MISC, g_print ("...SetWindowPos(%p,%s)\n",
472 GDK_WINDOW_HWND (window),
473 _gdk_win32_gdkrectangle_to_string (&new_position)));
474 if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
475 new_position.x, new_position.y,
476 new_position.width, new_position.height,
477 SWP_NOACTIVATE | SWP_NOZORDER))
478 WIN32_API_FAILED ("SetWindowPos");
480 tmp_list = obj->children;
483 gdk_window_premove (tmp_list->data, &parent_pos);
484 tmp_list = tmp_list->next;
487 GDK_NOTE (MISC, g_print ("...SetWindowPos(%p,0x0@+%d+%d)\n",
488 GDK_WINDOW_HWND (window),
489 new_position.x + dx, new_position.y + dy));
490 if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
491 new_position.x + dx, new_position.y + dy, 0, 0,
492 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOREDRAW))
493 WIN32_API_FAILED ("SetWindowPos");
495 if (d_xoffset > 0 || d_yoffset > 0)
496 gdk_window_queue_translation (window, MAX (d_xoffset, 0), MAX (d_yoffset, 0));
498 GDK_NOTE (MISC, g_print ("...SetWindowPos(%p,%dx%d@+%d+%d)\n",
499 GDK_WINDOW_HWND (window),
500 new_info.width, new_info.height,
501 new_info.x, new_info.y));
502 if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
503 new_info.x, new_info.y,
504 new_info.width, new_info.height,
505 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW))
506 WIN32_API_FAILED ("SetWindowPos");
508 if (impl->position_info.no_bg)
509 gdk_window_tmp_reset_bg (window);
511 if (!impl->position_info.mapped && new_info.mapped && GDK_WINDOW_IS_MAPPED (obj))
513 GDK_NOTE (MISC, g_print ("...ShowWindow(%p, SW_SHOWNA)\n",
514 GDK_WINDOW_HWND (window)));
515 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNA);
518 impl->position_info = new_info;
520 tmp_list = obj->children;
523 gdk_window_postmove (tmp_list->data, &parent_pos);
524 tmp_list = tmp_list->next;
529 if (is_move && is_resize)
530 gdk_window_set_static_gravities (window, FALSE);
532 if (impl->position_info.mapped && !new_info.mapped)
534 GDK_NOTE (MISC, g_print ("...ShowWindow(%p, SW_HIDE)\n",
535 GDK_WINDOW_HWND (window)));
536 ShowWindow (GDK_WINDOW_HWND (window), SW_HIDE);
539 tmp_list = obj->children;
542 gdk_window_premove (tmp_list->data, &parent_pos);
543 tmp_list = tmp_list->next;
546 GDK_NOTE (MISC, g_print ("...SetWindowPos(%p,%dx%d@+%d+%d)\n",
547 GDK_WINDOW_HWND (window),
548 new_info.width, new_info.height,
549 new_info.x, new_info.y));
550 if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
551 new_info.x, new_info.y,
552 new_info.width, new_info.height,
553 SWP_NOACTIVATE | SWP_NOZORDER |
554 (is_move ? 0 : SWP_NOMOVE) |
555 (is_resize ? 0 : SWP_NOSIZE)))
556 WIN32_API_FAILED ("SetWindowPos");
558 tmp_list = obj->children;
561 gdk_window_postmove (tmp_list->data, &parent_pos);
562 tmp_list = tmp_list->next;
565 if (impl->position_info.no_bg)
566 gdk_window_tmp_reset_bg (window);
568 if (!impl->position_info.mapped && new_info.mapped && GDK_WINDOW_IS_MAPPED (obj))
570 GDK_NOTE (MISC, g_print ("...ShowWindow(%p, SW_SHOWNA)\n",
571 GDK_WINDOW_HWND (window)));
572 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNA);
575 impl->position_info = new_info;
580 gdk_window_compute_position (GdkWindowImplWin32 *window,
581 GdkWindowParentPos *parent_pos,
582 GdkWin32PositionInfo *info)
584 GdkWindowObject *wrapper;
588 g_return_if_fail (GDK_IS_WINDOW_IMPL_WIN32 (window));
590 wrapper = GDK_WINDOW_OBJECT (GDK_DRAWABLE_IMPL_WIN32 (window)->wrapper);
594 if (window->width <= SIZE_LIMIT)
596 info->width = window->width;
597 info->x = parent_pos->x + wrapper->x - parent_pos->win32_x;
602 info->width = SIZE_LIMIT;
603 if (parent_pos->x + wrapper->x < -(SIZE_LIMIT/2))
605 if (parent_pos->x + wrapper->x + window->width < (SIZE_LIMIT/2))
606 info->x = parent_pos->x + wrapper->x + window->width - info->width - parent_pos->win32_x;
608 info->x = -(SIZE_LIMIT/2) - parent_pos->win32_x;
611 info->x = parent_pos->x + wrapper->x - parent_pos->win32_x;
614 if (window->height <= SIZE_LIMIT)
616 info->height = window->height;
617 info->y = parent_pos->y + wrapper->y - parent_pos->win32_y;
622 info->height = SIZE_LIMIT;
623 if (parent_pos->y + wrapper->y < -(SIZE_LIMIT/2))
625 if (parent_pos->y + wrapper->y + window->height < (SIZE_LIMIT/2))
626 info->y = parent_pos->y + wrapper->y + window->height - info->height - parent_pos->win32_y;
628 info->y = -(SIZE_LIMIT/2) - parent_pos->win32_y;
631 info->y = parent_pos->y + wrapper->y - parent_pos->win32_y;
634 parent_x_offset = parent_pos->win32_x - parent_pos->x;
635 parent_y_offset = parent_pos->win32_y - parent_pos->y;
637 info->x_offset = parent_x_offset + info->x - wrapper->x;
638 info->y_offset = parent_y_offset + info->y - wrapper->y;
640 /* We don't considering the clipping of toplevel windows and their immediate children
641 * by their parents, and simply always map those windows.
643 if (parent_pos->clip_rect.width == G_MAXINT)
645 /* Check if the window would wrap around into the visible space in either direction */
646 else if (info->x + parent_x_offset < parent_pos->clip_rect.x + parent_pos->clip_rect.width - 65536 ||
647 info->x + info->width + parent_x_offset > parent_pos->clip_rect.x + 65536 ||
648 info->y + parent_y_offset < parent_pos->clip_rect.y + parent_pos->clip_rect.height - 65536 ||
649 info->y + info->height + parent_y_offset > parent_pos->clip_rect.y + 65536)
650 info->mapped = FALSE;
656 if (GDK_WINDOW_TYPE (wrapper) == GDK_WINDOW_CHILD)
658 info->clip_rect.x = wrapper->x;
659 info->clip_rect.y = wrapper->y;
660 info->clip_rect.width = window->width;
661 info->clip_rect.height = window->height;
663 gdk_rectangle_intersect (&info->clip_rect, &parent_pos->clip_rect, &info->clip_rect);
665 info->clip_rect.x -= wrapper->x;
666 info->clip_rect.y -= wrapper->y;
670 info->clip_rect.x = 0;
671 info->clip_rect.y = 0;
672 info->clip_rect.width = G_MAXINT;
673 info->clip_rect.height = G_MAXINT;
678 gdk_window_compute_parent_pos (GdkWindowImplWin32 *window,
679 GdkWindowParentPos *parent_pos)
681 GdkWindowObject *wrapper;
682 GdkWindowObject *parent;
683 GdkRectangle tmp_clip;
685 int clip_xoffset = 0;
686 int clip_yoffset = 0;
688 g_return_if_fail (GDK_IS_WINDOW_IMPL_WIN32 (window));
690 wrapper = GDK_WINDOW_OBJECT (GDK_DRAWABLE_IMPL_WIN32 (window)->wrapper);
694 parent_pos->win32_x = 0;
695 parent_pos->win32_y = 0;
697 /* We take a simple approach here and simply consider toplevel
698 * windows not to clip their children on the right/bottom, since the
699 * size of toplevel windows is not directly under our
700 * control. Clipping only really matters when scrolling and
701 * generally we aren't going to be moving the immediate child of a
702 * toplevel beyond the bounds of that toplevel.
704 * We could go ahead and recompute the clips of toplevel windows and
705 * their descendents when we receive size notification, but it would
706 * probably not be an improvement in most cases.
708 parent_pos->clip_rect.x = 0;
709 parent_pos->clip_rect.y = 0;
710 parent_pos->clip_rect.width = G_MAXINT;
711 parent_pos->clip_rect.height = G_MAXINT;
713 parent = (GdkWindowObject *)wrapper->parent;
714 while (parent && parent->window_type == GDK_WINDOW_CHILD)
716 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (parent->impl);
718 tmp_clip.x = - clip_xoffset;
719 tmp_clip.y = - clip_yoffset;
720 tmp_clip.width = impl->width;
721 tmp_clip.height = impl->height;
723 gdk_rectangle_intersect (&parent_pos->clip_rect, &tmp_clip, &parent_pos->clip_rect);
725 parent_pos->x += parent->x;
726 parent_pos->y += parent->y;
727 parent_pos->win32_x += impl->position_info.x;
728 parent_pos->win32_y += impl->position_info.y;
730 clip_xoffset += parent->x;
731 clip_yoffset += parent->y;
733 parent = (GdkWindowObject *)parent->parent;
738 gdk_window_premove (GdkWindow *window,
739 GdkWindowParentPos *parent_pos)
741 GdkWindowImplWin32 *impl;
742 GdkWindowObject *obj;
743 GdkWin32PositionInfo new_info;
745 gint d_xoffset, d_yoffset;
746 GdkWindowParentPos this_pos;
748 obj = (GdkWindowObject *) window;
749 impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
751 gdk_window_compute_position (impl, parent_pos, &new_info);
753 gdk_window_clip_changed (window, &impl->position_info.clip_rect, &new_info.clip_rect);
755 this_pos.x = parent_pos->x + obj->x;
756 this_pos.y = parent_pos->y + obj->y;
757 this_pos.win32_x = parent_pos->win32_x + new_info.x;
758 this_pos.win32_y = parent_pos->win32_y + new_info.y;
759 this_pos.clip_rect = new_info.clip_rect;
761 if (impl->position_info.mapped && !new_info.mapped)
762 ShowWindow (GDK_WINDOW_HWND (window), SW_HIDE);
764 d_xoffset = new_info.x_offset - impl->position_info.x_offset;
765 d_yoffset = new_info.y_offset - impl->position_info.y_offset;
767 if (d_xoffset != 0 || d_yoffset != 0)
769 GdkRectangle new_position;
771 if (d_xoffset < 0 || d_yoffset < 0)
772 gdk_window_queue_translation (window, MIN (d_xoffset, 0), MIN (d_yoffset, 0));
774 compute_intermediate_position (&impl->position_info, &new_info, d_xoffset, d_yoffset,
777 GDK_NOTE (MISC, g_print ("gdk_window_premove: %s@+%d+%d\n"
778 "...SetWindowPos(%s)\n",
779 _gdk_win32_drawable_description (window),
781 _gdk_win32_gdkrectangle_to_string (&new_position)));
783 if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
784 new_position.x, new_position.y,
785 new_position.width, new_position.height,
786 SWP_NOREDRAW | SWP_NOZORDER | SWP_NOACTIVATE))
787 WIN32_API_FAILED ("SetWindowPos");
790 tmp_list = obj->children;
793 gdk_window_premove (tmp_list->data, &this_pos);
794 tmp_list = tmp_list->next;
799 gdk_window_postmove (GdkWindow *window,
800 GdkWindowParentPos *parent_pos)
802 GdkWindowImplWin32 *impl;
803 GdkWindowObject *obj;
804 GdkWin32PositionInfo new_info;
806 gint d_xoffset, d_yoffset;
807 GdkWindowParentPos this_pos;
809 obj = (GdkWindowObject *) window;
810 impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
812 gdk_window_compute_position (impl, parent_pos, &new_info);
814 this_pos.x = parent_pos->x + obj->x;
815 this_pos.y = parent_pos->y + obj->y;
816 this_pos.win32_x = parent_pos->win32_x + new_info.x;
817 this_pos.win32_y = parent_pos->win32_y + new_info.y;
818 this_pos.clip_rect = new_info.clip_rect;
820 d_xoffset = new_info.x_offset - impl->position_info.x_offset;
821 d_yoffset = new_info.y_offset - impl->position_info.y_offset;
823 if (d_xoffset != 0 || d_yoffset != 0)
825 if (d_xoffset > 0 || d_yoffset > 0)
826 gdk_window_queue_translation (window, MAX (d_xoffset, 0), MAX (d_yoffset, 0));
828 GDK_NOTE (MISC, g_print ("gdk_window_postmove: %s@+%d+%d\n"
829 "...SetWindowPos(%dx%d@+%d+%d)\n",
830 _gdk_win32_drawable_description (window),
832 new_info.width, new_info.height,
833 new_info.x, new_info.y));
835 if (!SetWindowPos (GDK_WINDOW_HWND (window), NULL,
836 new_info.x, new_info.y,
837 new_info.width, new_info.height,
838 SWP_NOREDRAW | SWP_NOZORDER | SWP_NOACTIVATE))
839 WIN32_API_FAILED ("SetWindowPos");
842 if (!impl->position_info.mapped && new_info.mapped && GDK_WINDOW_IS_MAPPED (obj))
843 ShowWindow (GDK_WINDOW_HWND (window), SW_SHOWNA);
845 if (impl->position_info.no_bg)
846 gdk_window_tmp_reset_bg (window);
848 impl->position_info = new_info;
850 tmp_list = obj->children;
853 gdk_window_postmove (tmp_list->data, &this_pos);
854 tmp_list = tmp_list->next;
861 gdk_window_queue_append (GdkWindow *window,
862 GdkWindowQueueItem *item)
864 if (g_slist_length (translate_queue) >= 128)
866 GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
868 GDK_NOTE (EVENTS, g_print ("gdk_window_queue_append: length >= 128\n"));
869 _gdk_window_process_expose (window, _gdk_win32_get_next_tick (0),
870 &impl->position_info.clip_rect);
873 item->window = window;
874 item->serial = GetTickCount ();
876 GDK_NOTE (EVENTS, (g_print ("gdk_window_queue_append: %s %p %ld ",
877 (item->type == GDK_WINDOW_QUEUE_TRANSLATE ?
878 "TRANSLATE" : "ANTIEXPOSE"),
879 GDK_WINDOW_HWND (window),
881 (item->type == GDK_WINDOW_QUEUE_TRANSLATE ?
883 item->u.translate.dx, item->u.translate.dy) :
885 _gdk_win32_gdkregion_to_string (item->u.antiexpose.area)))));
887 g_object_ref (window);
888 translate_queue = g_slist_append (translate_queue, item) ;
894 gdk_window_queue_translation (GdkWindow *window,
899 GdkWindowQueueItem *item = g_new (GdkWindowQueueItem, 1);
900 item->type = GDK_WINDOW_QUEUE_TRANSLATE;
901 item->u.translate.dx = dx;
902 item->u.translate.dy = dy;
904 gdk_window_queue_append (window, item);
909 _gdk_windowing_window_queue_antiexpose (GdkWindow *window,
912 HRGN hrgn = _gdk_win32_gdkregion_to_hrgn (area, 0, 0);
914 GDK_NOTE (EVENTS, g_print ("_gdk_windowing_window_queue_antiexpose: ValidateRgn %p %s\n",
915 GDK_WINDOW_HWND (window),
916 _gdk_win32_gdkregion_to_string (area)));
918 ValidateRgn (GDK_WINDOW_HWND (window), hrgn);
926 _gdk_window_process_expose (GdkWindow *window,
927 GdkRegion *invalidate_region)
929 GdkWindowImplWin32 *impl;
930 GdkRegion *clip_region;
932 GSList *tmp_list = translate_queue;
934 impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
936 GDK_NOTE (EVENTS, g_print ("_gdk_window_process_expose: %p %s\n",
937 GDK_WINDOW_HWND (window),
938 _gdk_win32_gdkregion_to_string (invalidate_region)));
942 GdkWindowQueueItem *item = tmp_list->data;
943 tmp_list = tmp_list->next;
945 if (serial < item->serial)
947 if (item->window == window)
949 if (item->type == GDK_WINDOW_QUEUE_TRANSLATE)
951 GDK_NOTE (EVENTS, g_print ("...item %ld xlating region by %d,%d\n",
953 item->u.translate.dx, item->u.translate.dy));
954 gdk_region_offset (invalidate_region, - item->u.translate.dx, - item->u.translate.dy);
956 else /* anti-expose */
958 #ifdef G_ENABLE_DEBUG
962 (gdk_region_get_clipbox (item->u.antiexpose.area, &rect),
963 g_print ("...item %ld antiexposing %s\n",
965 _gdk_win32_gdkrectangle_to_string (&rect))));
967 gdk_region_subtract (invalidate_region, item->u.antiexpose.area);
973 GSList *tmp_link = translate_queue;
975 GDK_NOTE (EVENTS, g_print ("...item %ld being removed\n", item->serial));
977 translate_queue = g_slist_remove_link (translate_queue, translate_queue);
978 g_object_unref (item->window);
980 if (item->type == GDK_WINDOW_QUEUE_ANTIEXPOSE)
981 gdk_region_destroy (item->u.antiexpose.area);
984 g_slist_free_1 (tmp_link);
988 GDK_NOTE (EVENTS, g_print ("...queue length now %d\n", g_slist_length (translate_queue)));
990 clip_region = gdk_region_rectangle (&impl->position_info.clip_rect);
991 gdk_region_intersect (invalidate_region, clip_region);
993 if (!gdk_region_empty (invalidate_region))
994 gdk_window_invalidate_region (window, invalidate_region, FALSE);
996 gdk_region_destroy (clip_region);
1000 gdk_window_tmp_unset_bg (GdkWindow *window)
1002 GdkWindowImplWin32 *impl;
1003 GdkWindowObject *obj;
1005 obj = (GdkWindowObject *) window;
1006 impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
1008 impl->position_info.no_bg = TRUE;
1011 * The X version sets background = None to avoid updateing for a moment.
1012 * Not sure if this could really emulate it.
1014 if (obj->bg_pixmap != GDK_NO_BG)
1015 /* handled in WM_ERASEBKGRND proceesing */;
1019 gdk_window_tmp_reset_bg (GdkWindow *window)
1021 GdkWindowImplWin32 *impl;
1022 GdkWindowObject *obj;
1024 obj = (GdkWindowObject *) window;
1025 impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
1027 impl->position_info.no_bg = FALSE;
1029 if (obj->bg_pixmap == GDK_NO_BG)
1043 gdk_window_clip_changed (GdkWindow *window,
1044 GdkRectangle *old_clip,
1045 GdkRectangle *new_clip)
1047 GdkWindowImplWin32 *impl;
1048 GdkWindowObject *obj;
1049 GdkRegion *old_clip_region;
1050 GdkRegion *new_clip_region;
1052 if (((GdkWindowObject *)window)->input_only)
1055 obj = (GdkWindowObject *) window;
1056 impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
1058 old_clip_region = gdk_region_rectangle (old_clip);
1059 new_clip_region = gdk_region_rectangle (new_clip);
1061 /* We need to update this here because gdk_window_invalidate_region makes
1062 * use if it (through gdk_drawable_get_visible_region
1064 impl->position_info.clip_rect = *new_clip;
1066 /* Trim invalid region of window to new clip rectangle
1068 if (obj->update_area)
1069 gdk_region_intersect (obj->update_area, new_clip_region);
1071 /* Invalidate newly exposed portion of window
1073 gdk_region_subtract (new_clip_region, old_clip_region);
1074 if (!gdk_region_empty (new_clip_region))
1076 gdk_window_tmp_unset_bg (window);
1078 g_print ("gdk_window_clip_changed: invalidating region: %s\n",
1079 _gdk_win32_gdkregion_to_string (new_clip_region)));
1080 gdk_window_invalidate_region (window, new_clip_region, FALSE);
1083 gdk_region_destroy (new_clip_region);
1084 gdk_region_destroy (old_clip_region);