]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkgeometry-win32.c
s/GdkRegion/cairo_region_t/ in all of gtk
[~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 "gdkinternals.h"
44 #include "gdkprivate-win32.h"
45
46 #define SIZE_LIMIT 32767
47
48 typedef struct _GdkWindowParentPos GdkWindowParentPos;
49
50 static void tmp_unset_bg (GdkWindow *window);
51 static void tmp_reset_bg (GdkWindow *window);
52
53 void
54 _gdk_window_move_resize_child (GdkWindow *window,
55                                gint       x,
56                                gint       y,
57                                gint       width,
58                                gint       height)
59 {
60   GdkWindowImplWin32 *impl;
61   GdkWindowObject *obj;
62   gboolean is_move;
63   gboolean is_resize;
64
65   g_return_if_fail (window != NULL);
66   g_return_if_fail (GDK_IS_WINDOW (window));
67
68   obj = GDK_WINDOW_OBJECT (window);
69   impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
70
71   is_move = (x - obj->x != 0) && (y - obj->y != 0);
72   is_resize = obj->width != width && obj->height != height;
73   
74   GDK_NOTE (MISC, g_print ("_gdk_window_move_resize_child: %s@%+d%+d %dx%d@%+d%+d\n",
75                            _gdk_win32_drawable_description (window),
76                            obj->x, obj->y, width, height, x, y));
77
78   if (width > 65535 || height > 65535)
79   {
80     g_warning ("Native children wider or taller than 65535 pixels are not supported.");
81
82     if (width > 65535)
83       width = 65535;
84     if (height > 65535)
85       height = 65535;
86   }
87
88   obj->x = x;
89   obj->y = y;
90   obj->width = width;
91   obj->height = height;
92
93   _gdk_win32_window_tmp_unset_parent_bg (window);
94   _gdk_win32_window_tmp_unset_bg (window, TRUE);
95   
96   GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,%d,%d,"
97                            "NOACTIVATE|NOZORDER%s%s)\n",
98                            GDK_WINDOW_HWND (window),
99                            obj->x + obj->parent->abs_x, obj->y + obj->parent->abs_y, 
100                            width, height,
101                            (is_move ? "" : "|NOMOVE"),
102                            (is_resize ? "" : "|NOSIZE")));
103
104   API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL,
105                            obj->x + obj->parent->abs_x, obj->y + obj->parent->abs_y, 
106                            width, height,
107                            SWP_NOACTIVATE | SWP_NOZORDER | 
108                            (is_move ? 0 : SWP_NOMOVE) |
109                            (is_resize ? 0 : SWP_NOSIZE)));
110
111   //_gdk_win32_window_tmp_reset_parent_bg (window);
112   _gdk_win32_window_tmp_reset_bg (window, TRUE);
113 }
114
115 void
116 _gdk_win32_window_tmp_unset_bg (GdkWindow *window,
117                                 gboolean recurse)
118 {
119   GdkWindowObject *private;
120
121   g_return_if_fail (GDK_IS_WINDOW (window));
122
123   private = (GdkWindowObject *)window;
124
125   if (private->input_only || private->destroyed ||
126       (private->window_type != GDK_WINDOW_ROOT &&
127        !GDK_WINDOW_IS_MAPPED (window)))
128     return;
129
130   if (_gdk_window_has_impl (window) &&
131       GDK_WINDOW_IS_WIN32 (window) &&
132       private->window_type != GDK_WINDOW_ROOT &&
133       private->window_type != GDK_WINDOW_FOREIGN)
134     tmp_unset_bg (window);
135
136   if (recurse)
137     {
138       GList *l;
139
140       for (l = private->children; l != NULL; l = l->next)
141         _gdk_win32_window_tmp_unset_bg (l->data, TRUE);
142     }
143 }
144
145 static void
146 tmp_unset_bg (GdkWindow *window)
147 {
148   GdkWindowImplWin32 *impl;
149   GdkWindowObject *obj;
150
151   obj = (GdkWindowObject *) window;
152   impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
153
154   impl->no_bg = TRUE;
155
156   /*
157    * The X version sets background = None to avoid updateing for a moment.
158    * Not sure if this could really emulate it.
159    */
160   if (obj->bg_pixmap != GDK_NO_BG)
161     {
162       ///* handled in WM_ERASEBKGRND proceesing */;
163
164       //HDC hdc = GetDC (GDK_WINDOW_HWND (window));
165       //erase_background (window, hdc);
166     }
167 }
168
169 static void
170 tmp_reset_bg (GdkWindow *window)
171 {
172   GdkWindowObject *obj;
173   GdkWindowImplWin32 *impl;
174
175   obj = GDK_WINDOW_OBJECT (window);
176   impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
177
178   impl->no_bg = FALSE;
179 }
180
181 void
182 _gdk_win32_window_tmp_unset_parent_bg (GdkWindow *window)
183 {
184   GdkWindowObject *private = (GdkWindowObject*)window;
185
186   if (GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_ROOT)
187     return;
188
189   window = _gdk_window_get_impl_window ((GdkWindow*)private->parent);
190   _gdk_win32_window_tmp_unset_bg (window, FALSE);
191 }
192
193 void
194 _gdk_win32_window_tmp_reset_bg (GdkWindow *window,
195                                 gboolean   recurse)
196 {
197   GdkWindowObject *private = (GdkWindowObject*)window;
198
199   g_return_if_fail (GDK_IS_WINDOW (window));
200
201   if (private->input_only || private->destroyed ||
202       (private->window_type != GDK_WINDOW_ROOT && !GDK_WINDOW_IS_MAPPED (window)))
203     return;
204
205   if (_gdk_window_has_impl (window) &&
206       GDK_WINDOW_IS_WIN32 (window) &&
207       private->window_type != GDK_WINDOW_ROOT &&
208       private->window_type != GDK_WINDOW_FOREIGN)
209     {
210       tmp_reset_bg (window);
211     }
212
213   if (recurse)
214     {
215       GList *l;
216
217       for (l = private->children; l != NULL; l = l->next)
218         _gdk_win32_window_tmp_reset_bg (l->data, TRUE);
219     }
220 }
221
222 /*
223 void
224 _gdk_win32_window_tmp_reset_bg (GdkWindow *window)
225 {
226   GdkWindowImplWin32 *impl;
227   GdkWindowObject *obj;
228
229   obj = (GdkWindowObject *) window;
230   impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
231
232   impl->no_bg = FALSE;
233 }
234 */
235
236 #if 0
237 static cairo_region_t *
238 gdk_window_clip_changed (GdkWindow    *window,
239                          GdkRectangle *old_clip,
240                          GdkRectangle *new_clip)
241 {
242   GdkWindowImplWin32 *impl;
243   GdkWindowObject *obj;
244   cairo_region_t *old_clip_region;
245   cairo_region_t *new_clip_region;
246   
247   if (((GdkWindowObject *)window)->input_only)
248     return NULL;
249
250   obj = (GdkWindowObject *) window;
251   impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
252   
253   old_clip_region = cairo_region_create_rectangle (old_clip);
254   new_clip_region = cairo_region_create_rectangle (new_clip);
255
256   /* Trim invalid region of window to new clip rectangle
257    */
258   if (obj->update_area)
259     cairo_region_intersect (obj->update_area, new_clip_region);
260
261   /* Invalidate newly exposed portion of window
262    */
263   cairo_region_subtract (new_clip_region, old_clip_region);
264   if (!cairo_region_is_empty (new_clip_region))
265     gdk_window_tmp_unset_bg (window);
266   else
267     {
268       cairo_region_destroy (new_clip_region);
269       new_clip_region = NULL;
270     }
271
272   cairo_region_destroy (old_clip_region);
273
274   return new_clip_region;
275 }
276 #endif
277
278 #if 0
279 static void
280 gdk_window_post_scroll (GdkWindow    *window,
281                         cairo_region_t    *new_clip_region)
282 {
283   GDK_NOTE (EVENTS,
284             g_print ("gdk_window_clip_changed: invalidating region: %s\n",
285                      _gdk_win32_gdkregion_to_string (new_clip_region)));
286
287   gdk_window_invalidate_region (window, new_clip_region, FALSE);
288   g_print ("gdk_window_post_scroll\n");
289   cairo_region_destroy (new_clip_region);
290 }
291
292 #endif