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