]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkgeometry-win32.c
Misc stuff
[~andy/gtk] / gdk / win32 / gdkgeometry-win32.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /* gdkgeometry-win32.c: emulation of 32 bit coordinates within the
21  * limits of Win32 GDI. The idea of big window emulation is more or less
22  * a copy of the X11 version, and the equvalent of guffaw scrolling
23  * is ScrollWindowEx(). While we determine the invalidated region
24  * ourself during scrolling, we do not pass SW_INVALIDATE to
25  * ScrollWindowEx() to avoid a unnecessary WM_PAINT.
26  *
27  * Bits are always scrolled correctly by ScrollWindowEx(), but
28  * some big children may hit the coordinate boundary (i.e.
29  * win32_x/win32_y < -16383) after scrolling. They needed to be moved
30  * back to the real position determined by gdk_window_compute_position().
31  * This is handled in gdk_window_postmove().
32  * 
33  * The X11 version by Owen Taylor <otaylor@redhat.com>
34  * Copyright Red Hat, Inc. 2000
35  * Win32 hack by Tor Lillqvist <tml@iki.fi>
36  * and Hans Breuer <hans@breuer.org>
37  * Modified by Ivan, Wong Yat Cheung <email@ivanwong.info>
38  * so that big window emulation finally works.
39  */
40
41 #include "config.h"
42 #include "gdk.h"                /* For gdk_rectangle_intersect */
43 #include "gdkregion.h"
44 #include "gdkregion-generic.h"
45 #include "gdkinternals.h"
46 #include "gdkprivate-win32.h"
47
48 #define SIZE_LIMIT 32767
49
50 typedef struct _GdkWindowParentPos GdkWindowParentPos;
51
52 void
53 _gdk_window_move_resize_child (GdkWindow *window,
54                                gint       x,
55                                gint       y,
56                                gint       width,
57                                gint       height)
58 {
59   GdkWindowImplWin32 *impl;
60   GdkWindowObject *obj;
61   gboolean is_move;
62   gboolean is_resize;
63
64   g_return_if_fail (window != NULL);
65   g_return_if_fail (GDK_IS_WINDOW (window));
66
67   obj = GDK_WINDOW_OBJECT (window);
68   impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
69
70   is_move = (x - obj->x != 0) && (y - obj->y != 0);
71   is_resize = obj->width != width && obj->height != height;
72   
73   GDK_NOTE (MISC, g_print ("_gdk_window_move_resize_child: %s@%+d%+d %dx%d@%+d%+d\n",
74                         _gdk_win32_drawable_description (window),
75                         obj->x, obj->y, width, height, x, y));
76
77   if (width > 65535 || height > 65535)
78   {
79           g_warning ("Native children wider or taller than 65535 pixels are not supported.");
80
81           if (width > 65535)
82                   width = 65535;
83           if (height > 65535)
84                   height = 65535;
85   }
86
87   obj->x = x;
88   obj->y = y;
89   obj->width = width;
90   obj->height = height;
91   
92   GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,%d,%d,"
93                        "NOACTIVATE|NOZORDER%s%s)\n",
94                        GDK_WINDOW_HWND (window),
95                        obj->x + obj->parent->abs_x, obj->y + obj->parent->abs_y, 
96                        width, height,
97                        (is_move ? "" : "|NOMOVE"),
98                        (is_resize ? "" : "|NOSIZE")));
99
100   API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL,
101                        obj->x + obj->parent->abs_x, obj->y + obj->parent->abs_y, 
102                        width, height,
103                        SWP_NOACTIVATE | SWP_NOZORDER | 
104                        (is_move ? 0 : SWP_NOMOVE) |
105                        (is_resize ? 0 : SWP_NOSIZE)));
106 }
107
108 void
109 _gdk_window_process_expose (GdkWindow *window,
110                             GdkRegion *invalidate_region)
111 {
112   GdkWindowImplWin32 *impl;
113   //GdkRegion *clip_region;
114   impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
115   
116   GDK_NOTE (EVENTS, g_print ("_gdk_window_process_expose: %p %s\n",
117                              GDK_WINDOW_HWND (window),
118                              _gdk_win32_gdkregion_to_string (invalidate_region)));
119
120   if (!gdk_region_empty (invalidate_region))
121     _gdk_window_invalidate_for_expose (window, invalidate_region);
122   
123   g_print ("_gdk_window_process_expose\n");
124   gdk_region_destroy (invalidate_region);
125 }
126
127 static void
128 gdk_window_tmp_unset_bg (GdkWindow *window)
129 {
130   GdkWindowImplWin32 *impl;
131   GdkWindowObject *obj;
132
133   obj = (GdkWindowObject *) window;
134   impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
135
136   impl->no_bg = TRUE;
137
138   /*
139    * The X version sets background = None to avoid updateing for a moment.
140    * Not sure if this could really emulate it.
141    */
142   if (obj->bg_pixmap != GDK_NO_BG)
143     /* handled in WM_ERASEBKGRND proceesing */;
144 }
145
146 static void
147 gdk_window_tmp_reset_bg (GdkWindow *window)
148 {
149   GdkWindowImplWin32 *impl;
150   GdkWindowObject *obj;
151
152   obj = (GdkWindowObject *) window;
153   impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
154
155   impl->no_bg = FALSE;
156 }
157
158 static GdkRegion *
159 gdk_window_clip_changed (GdkWindow    *window,
160                          GdkRectangle *old_clip,
161                          GdkRectangle *new_clip)
162 {
163   GdkWindowImplWin32 *impl;
164   GdkWindowObject *obj;
165   GdkRegion *old_clip_region;
166   GdkRegion *new_clip_region;
167   
168   if (((GdkWindowObject *)window)->input_only)
169     return NULL;
170
171   obj = (GdkWindowObject *) window;
172   impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
173   
174   old_clip_region = gdk_region_rectangle (old_clip);
175   new_clip_region = gdk_region_rectangle (new_clip);
176
177   /* Trim invalid region of window to new clip rectangle
178    */
179   if (obj->update_area)
180     gdk_region_intersect (obj->update_area, new_clip_region);
181
182   /* Invalidate newly exposed portion of window
183    */
184   gdk_region_subtract (new_clip_region, old_clip_region);
185   if (!gdk_region_empty (new_clip_region))
186     gdk_window_tmp_unset_bg (window);
187   else
188     {
189       g_print ("gdk_window_clip_changed (new_clip_region)\n");
190       gdk_region_destroy (new_clip_region);
191       new_clip_region = NULL;
192     }
193   g_print ("gdk_window_clip_changed (old_clip_region)\n");
194   gdk_region_destroy (old_clip_region);
195
196   return new_clip_region;
197 }
198
199 static void
200 gdk_window_post_scroll (GdkWindow    *window,
201                         GdkRegion    *new_clip_region)
202 {
203   GDK_NOTE (EVENTS,
204             g_print ("gdk_window_clip_changed: invalidating region: %s\n",
205                      _gdk_win32_gdkregion_to_string (new_clip_region)));
206
207   gdk_window_invalidate_region (window, new_clip_region, FALSE);
208   g_print ("gdk_window_post_scroll\n");
209   gdk_region_destroy (new_clip_region);
210 }