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, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /* gdkgeometry-win32.c: emulation of 32 bit coordinates within the
19  * limits of Win32 GDI. The idea of big window emulation is more or less
20  * a copy of the X11 version, and the equvalent of guffaw scrolling
21  * is ScrollWindowEx(). While we determine the invalidated region
22  * ourself during scrolling, we do not pass SW_INVALIDATE to
23  * ScrollWindowEx() to avoid a unnecessary WM_PAINT.
24  *
25  * Bits are always scrolled correctly by ScrollWindowEx(), but
26  * some big children may hit the coordinate boundary (i.e.
27  * win32_x/win32_y < -16383) after scrolling. They needed to be moved
28  * back to the real position determined by gdk_window_compute_position().
29  * This is handled in gdk_window_postmove().
30  *
31  * The X11 version by Owen Taylor <otaylor@redhat.com>
32  * Copyright Red Hat, Inc. 2000
33  * Win32 hack by Tor Lillqvist <tml@iki.fi>
34  * and Hans Breuer <hans@breuer.org>
35  * Modified by Ivan, Wong Yat Cheung <email@ivanwong.info>
36  * so that big window emulation finally works.
37  */
38 
39 #include "config.h"
40 #include "gdk.h"		/* For gdk_rectangle_intersect */
41 #include "gdkinternals.h"
42 #include "gdkprivate-win32.h"
43 #include "gdkwin32.h"
44 
45 #define SIZE_LIMIT 32767
46 
47 typedef struct _GdkWindowParentPos GdkWindowParentPos;
48 
49 static void
tmp_unset_bg(GdkWindow * window)50 tmp_unset_bg (GdkWindow *window)
51 {
52   GdkWindowImplWin32 *impl;
53 
54   impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
55 
56   impl->no_bg = TRUE;
57 }
58 
59 static void
tmp_reset_bg(GdkWindow * window)60 tmp_reset_bg (GdkWindow *window)
61 {
62   GdkWindowImplWin32 *impl;
63 
64   impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
65 
66   impl->no_bg = FALSE;
67 }
68 
69 void
_gdk_window_move_resize_child(GdkWindow * window,gint x,gint y,gint width,gint height)70 _gdk_window_move_resize_child (GdkWindow *window,
71 			       gint       x,
72 			       gint       y,
73 			       gint       width,
74 			       gint       height)
75 {
76   GdkWindowImplWin32 *impl;
77 
78   g_return_if_fail (window != NULL);
79   g_return_if_fail (GDK_IS_WINDOW (window));
80 
81   impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
82   GDK_NOTE (MISC, g_print ("_gdk_window_move_resize_child: %s@%+d%+d %dx%d@%+d%+d\n",
83 			   _gdk_win32_window_description (window),
84 			   window->x, window->y, width, height, x, y));
85 
86   if (width * impl->window_scale > 65535 || height * impl->window_scale > 65535)
87     {
88       g_warning ("Native children wider or taller than 65535 pixels are not supported.");
89 
90       if (width * impl->window_scale > 65535)
91         width = 65535 / impl->window_scale;
92       if (height * impl->window_scale > 65535)
93         height = 65535 /impl->window_scale;
94     }
95 
96   window->x = x;
97   window->y = y;
98   window->width = width;
99   window->height = height;
100   impl->unscaled_width = width * impl->window_scale;
101   impl->unscaled_height = height * impl->window_scale;
102 
103   _gdk_win32_window_tmp_unset_parent_bg (window);
104   _gdk_win32_window_tmp_unset_bg (window, TRUE);
105 
106   GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,%d,%d,"
107 			   "NOACTIVATE|NOZORDER)\n",
108 			   GDK_WINDOW_HWND (window),
109 			   (window->x + window->parent->abs_x) * impl->window_scale,
110 			   (window->y + window->parent->abs_y) * impl->window_scale,
111 			   impl->unscaled_width,
112 			   impl->unscaled_height));
113 
114   API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL,
115 			   (window->x + window->parent->abs_x) * impl->window_scale,
116 			   (window->y + window->parent->abs_y) * impl->window_scale,
117 			   impl->unscaled_width,
118 			   impl->unscaled_height,
119 			   SWP_NOACTIVATE | SWP_NOZORDER));
120 
121   _gdk_win32_window_tmp_reset_bg (window, TRUE);
122 }
123 
124 void
_gdk_win32_window_tmp_unset_bg(GdkWindow * window,gboolean recurse)125 _gdk_win32_window_tmp_unset_bg (GdkWindow *window,
126 				gboolean recurse)
127 {
128   g_return_if_fail (GDK_IS_WINDOW (window));
129 
130   if (window->input_only || window->destroyed ||
131       (window->window_type != GDK_WINDOW_ROOT &&
132        !GDK_WINDOW_IS_MAPPED (window)))
133     return;
134 
135   if (_gdk_window_has_impl (window) &&
136       GDK_WINDOW_IS_WIN32 (window) &&
137       window->window_type != GDK_WINDOW_ROOT &&
138       window->window_type != GDK_WINDOW_FOREIGN)
139     tmp_unset_bg (window);
140 
141   if (recurse)
142     {
143       GList *l;
144 
145       for (l = window->children; l != NULL; l = l->next)
146 	_gdk_win32_window_tmp_unset_bg (l->data, TRUE);
147     }
148 }
149 
150 void
_gdk_win32_window_tmp_unset_parent_bg(GdkWindow * window)151 _gdk_win32_window_tmp_unset_parent_bg (GdkWindow *window)
152 {
153   if (GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_ROOT)
154     return;
155 
156   window = _gdk_window_get_impl_window (window->parent);
157   _gdk_win32_window_tmp_unset_bg (window, FALSE);
158 }
159 
160 void
_gdk_win32_window_tmp_reset_bg(GdkWindow * window,gboolean recurse)161 _gdk_win32_window_tmp_reset_bg (GdkWindow *window,
162 				gboolean   recurse)
163 {
164   g_return_if_fail (GDK_IS_WINDOW (window));
165 
166   if (window->input_only || window->destroyed ||
167       (window->window_type != GDK_WINDOW_ROOT && !GDK_WINDOW_IS_MAPPED (window)))
168     return;
169 
170   if (_gdk_window_has_impl (window) &&
171       GDK_WINDOW_IS_WIN32 (window) &&
172       window->window_type != GDK_WINDOW_ROOT &&
173       window->window_type != GDK_WINDOW_FOREIGN)
174     {
175       tmp_reset_bg (window);
176     }
177 
178   if (recurse)
179     {
180       GList *l;
181 
182       for (l = window->children; l != NULL; l = l->next)
183 	_gdk_win32_window_tmp_reset_bg (l->data, TRUE);
184     }
185 }
186