From 16d002d074ef55142d2eb9740bed4ed2ad4a8e01 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Sun, 30 May 1999 02:15:33 +0000 Subject: [PATCH] AdjustWindowRectEx2 renamed to SafeAdjustWindowRectEx. Don't override all * gdk/win32/gdkwindow.c: AdjustWindowRectEx2 renamed to SafeAdjustWindowRectEx. Don't override all calls to AdjustWindowRectEx by it, but use it only in two places: When creating a new top-level window and when moving a top-level window. Use screen coordinate rectangle, not client rectangle, in gdk_window_move. Thus SafeAdjustWindowRectEx will do its job only when we try to place a window so that the decoration (mainly, title bar) isn't visible. These changes fix the bug that showed up for instance as the GIMP's saved top-level windows moving right and down (by an amount equal to the window decoration) for each session. This bug showed up also in testgtk's "Saved Position". gdk_window_resize also redone a bit. --- ChangeLog | 20 ++++++ ChangeLog.pre-2-0 | 20 ++++++ ChangeLog.pre-2-10 | 20 ++++++ ChangeLog.pre-2-2 | 20 ++++++ ChangeLog.pre-2-4 | 20 ++++++ ChangeLog.pre-2-6 | 20 ++++++ ChangeLog.pre-2-8 | 20 ++++++ gdk/win32/gdkwindow-win32.c | 124 ++++++++++++++++++++---------------- gdk/win32/gdkwindow.c | 124 ++++++++++++++++++++---------------- 9 files changed, 278 insertions(+), 110 deletions(-) diff --git a/ChangeLog b/ChangeLog index 259bf0f597..0970ddad49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +1999-05-30 Tor Lillqvist + + * gdk/win32/gdkwindow.c: AdjustWindowRectEx2 renamed to + SafeAdjustWindowRectEx. Don't override all calls to + AdjustWindowRectEx by it, but use it only in two places: When + creating a new top-level window and when moving a top-level + window. + + Use screen coordinate rectangle, not client rectangle, in + gdk_window_move. Thus SafeAdjustWindowRectEx will do its job only + when we try to place a window so that the decoration (mainly, + title bar) isn't visible. + + These changes fix the bug that showed up for instance as the + GIMP's saved top-level windows moving right and down (by an amount + equal to the window decoration) for each session. This bug showed + up also in testgtk's "Saved Position". + + gdk_window_resize also redone a bit. + 1999-05-25 Tor Lillqvist * gtk/testgtkrc: Add (commented out) Windows-style theme diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 259bf0f597..0970ddad49 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,23 @@ +1999-05-30 Tor Lillqvist + + * gdk/win32/gdkwindow.c: AdjustWindowRectEx2 renamed to + SafeAdjustWindowRectEx. Don't override all calls to + AdjustWindowRectEx by it, but use it only in two places: When + creating a new top-level window and when moving a top-level + window. + + Use screen coordinate rectangle, not client rectangle, in + gdk_window_move. Thus SafeAdjustWindowRectEx will do its job only + when we try to place a window so that the decoration (mainly, + title bar) isn't visible. + + These changes fix the bug that showed up for instance as the + GIMP's saved top-level windows moving right and down (by an amount + equal to the window decoration) for each session. This bug showed + up also in testgtk's "Saved Position". + + gdk_window_resize also redone a bit. + 1999-05-25 Tor Lillqvist * gtk/testgtkrc: Add (commented out) Windows-style theme diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 259bf0f597..0970ddad49 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,23 @@ +1999-05-30 Tor Lillqvist + + * gdk/win32/gdkwindow.c: AdjustWindowRectEx2 renamed to + SafeAdjustWindowRectEx. Don't override all calls to + AdjustWindowRectEx by it, but use it only in two places: When + creating a new top-level window and when moving a top-level + window. + + Use screen coordinate rectangle, not client rectangle, in + gdk_window_move. Thus SafeAdjustWindowRectEx will do its job only + when we try to place a window so that the decoration (mainly, + title bar) isn't visible. + + These changes fix the bug that showed up for instance as the + GIMP's saved top-level windows moving right and down (by an amount + equal to the window decoration) for each session. This bug showed + up also in testgtk's "Saved Position". + + gdk_window_resize also redone a bit. + 1999-05-25 Tor Lillqvist * gtk/testgtkrc: Add (commented out) Windows-style theme diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 259bf0f597..0970ddad49 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,23 @@ +1999-05-30 Tor Lillqvist + + * gdk/win32/gdkwindow.c: AdjustWindowRectEx2 renamed to + SafeAdjustWindowRectEx. Don't override all calls to + AdjustWindowRectEx by it, but use it only in two places: When + creating a new top-level window and when moving a top-level + window. + + Use screen coordinate rectangle, not client rectangle, in + gdk_window_move. Thus SafeAdjustWindowRectEx will do its job only + when we try to place a window so that the decoration (mainly, + title bar) isn't visible. + + These changes fix the bug that showed up for instance as the + GIMP's saved top-level windows moving right and down (by an amount + equal to the window decoration) for each session. This bug showed + up also in testgtk's "Saved Position". + + gdk_window_resize also redone a bit. + 1999-05-25 Tor Lillqvist * gtk/testgtkrc: Add (commented out) Windows-style theme diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 259bf0f597..0970ddad49 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,23 @@ +1999-05-30 Tor Lillqvist + + * gdk/win32/gdkwindow.c: AdjustWindowRectEx2 renamed to + SafeAdjustWindowRectEx. Don't override all calls to + AdjustWindowRectEx by it, but use it only in two places: When + creating a new top-level window and when moving a top-level + window. + + Use screen coordinate rectangle, not client rectangle, in + gdk_window_move. Thus SafeAdjustWindowRectEx will do its job only + when we try to place a window so that the decoration (mainly, + title bar) isn't visible. + + These changes fix the bug that showed up for instance as the + GIMP's saved top-level windows moving right and down (by an amount + equal to the window decoration) for each session. This bug showed + up also in testgtk's "Saved Position". + + gdk_window_resize also redone a bit. + 1999-05-25 Tor Lillqvist * gtk/testgtkrc: Add (commented out) Windows-style theme diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 259bf0f597..0970ddad49 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,23 @@ +1999-05-30 Tor Lillqvist + + * gdk/win32/gdkwindow.c: AdjustWindowRectEx2 renamed to + SafeAdjustWindowRectEx. Don't override all calls to + AdjustWindowRectEx by it, but use it only in two places: When + creating a new top-level window and when moving a top-level + window. + + Use screen coordinate rectangle, not client rectangle, in + gdk_window_move. Thus SafeAdjustWindowRectEx will do its job only + when we try to place a window so that the decoration (mainly, + title bar) isn't visible. + + These changes fix the bug that showed up for instance as the + GIMP's saved top-level windows moving right and down (by an amount + equal to the window decoration) for each session. This bug showed + up also in testgtk's "Saved Position". + + gdk_window_resize also redone a bit. + 1999-05-25 Tor Lillqvist * gtk/testgtkrc: Add (commented out) Windows-style theme diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 259bf0f597..0970ddad49 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,23 @@ +1999-05-30 Tor Lillqvist + + * gdk/win32/gdkwindow.c: AdjustWindowRectEx2 renamed to + SafeAdjustWindowRectEx. Don't override all calls to + AdjustWindowRectEx by it, but use it only in two places: When + creating a new top-level window and when moving a top-level + window. + + Use screen coordinate rectangle, not client rectangle, in + gdk_window_move. Thus SafeAdjustWindowRectEx will do its job only + when we try to place a window so that the decoration (mainly, + title bar) isn't visible. + + These changes fix the bug that showed up for instance as the + GIMP's saved top-level windows moving right and down (by an amount + equal to the window decoration) for each session. This bug showed + up also in testgtk's "Saved Position". + + gdk_window_resize also redone a bit. + 1999-05-25 Tor Lillqvist * gtk/testgtkrc: Add (commented out) Windows-style theme diff --git a/gdk/win32/gdkwindow-win32.c b/gdk/win32/gdkwindow-win32.c index d41750ae40..d003fff506 100644 --- a/gdk/win32/gdkwindow-win32.c +++ b/gdk/win32/gdkwindow-win32.c @@ -36,10 +36,11 @@ /* The Win API function AdjustWindowRect may return negative values * resulting in obscured title bars. This helper function is coreccting it. */ -BOOL AdjustWindowRectEx2(RECT* lpRect, - DWORD dwStyle, - BOOL bMenu, - DWORD dwExStyle) +BOOL +SafeAdjustWindowRectEx (RECT* lpRect, + DWORD dwStyle, + BOOL bMenu, + DWORD dwExStyle) { if (!AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle)) return FALSE; @@ -55,8 +56,6 @@ BOOL AdjustWindowRectEx2(RECT* lpRect, } return TRUE; } -/* HB: now use it */ -#define AdjustWindowRectEx AdjustWindowRectEx2 /* Forward declarations */ static gboolean gdk_window_gravity_works (void); @@ -176,18 +175,9 @@ gdk_window_new (GdkWindow *parent, private->resize_count = 0; private->ref_count = 1; - if (attributes_mask & GDK_WA_X) - x = attributes->x; - else - x = 0; + private->x = (attributes_mask & GDK_WA_X) ? attributes->x : 0; + private->y = (attributes_mask & GDK_WA_Y) ? attributes->y : 0; - if (attributes_mask & GDK_WA_Y) - y = attributes->y; - else - y = 0; - - private->x = x; - private->y = y; private->width = (attributes->width > 1) ? (attributes->width) : (1); private->height = (attributes->height > 1) ? (attributes->height) : (1); private->window_type = attributes->window_type; @@ -362,7 +352,7 @@ gdk_window_new (GdkWindow *parent, rect.right = rect.left + private->width; rect.bottom = rect.top + private->height; - if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) + if (!SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) g_warning ("gdk_window_new: AdjustWindowRectEx failed"); if (x != CW_USEDEFAULT) @@ -753,18 +743,39 @@ gdk_window_move (GdkWindow *window, if (!private->destroyed) { RECT rect; - DWORD dwStyle; - DWORD dwExStyle; GDK_NOTE (MISC, g_print ("gdk_window_move: %#x +%d+%d\n", private->xwindow, x, y)); + GetClientRect (private->xwindow, &rect); - dwStyle = GetWindowLong (private->xwindow, GWL_STYLE); - dwExStyle = GetWindowLong (private->xwindow, GWL_EXSTYLE); - if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) - g_warning ("gdk_window_move: AdjustWindowRectEx failed"); - if (private->window_type == GDK_WINDOW_CHILD) + if (private->window_type != GDK_WINDOW_CHILD) + { + POINT ptTL, ptBR; + DWORD dwStyle; + DWORD dwExStyle; + + ptTL.x = 0; + ptTL.y = 0; + ClientToScreen (private->xwindow, &ptTL); + rect.left = x; + rect.top = y; + + ptBR.x = rect.right; + ptBR.y = rect.bottom; + ClientToScreen (private->xwindow, &ptBR); + rect.right = x + ptBR.x - ptTL.x; + rect.bottom = y + ptBR.y - ptTL.y; + + dwStyle = GetWindowLong (private->xwindow, GWL_STYLE); + dwExStyle = GetWindowLong (private->xwindow, GWL_EXSTYLE); + if (!SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) + g_warning ("gdk_window_move: AdjustWindowRectEx failed"); + + x = rect.left; + y = rect.top; + } + else { private->x = x; private->y = y; @@ -772,10 +783,9 @@ gdk_window_move (GdkWindow *window, GDK_NOTE (MISC, g_print ("...MoveWindow(%#x,%dx%d@+%d+%d)\n", private->xwindow, rect.right - rect.left, rect.bottom - rect.top, - x + rect.left, y + rect.top)); + x, y)); if (!MoveWindow (private->xwindow, - x + rect.left, y + rect.top, - rect.right - rect.left, rect.bottom - rect.top, + x, y, rect.right - rect.left, rect.bottom - rect.top, TRUE)) g_warning ("gdk_window_move: MoveWindow failed"); } @@ -802,52 +812,50 @@ gdk_window_resize (GdkWindow *window, (private->width != (guint16) width) || (private->height != (guint16) height))) { - RECT rect; - POINT pt; - DWORD dwStyle; - DWORD dwExStyle; int x, y; GDK_NOTE (MISC, g_print ("gdk_window_resize: %#x %dx%d\n", private->xwindow, width, height)); - pt.x = 0; - pt.y = 0; - ClientToScreen (private->xwindow, &pt); - rect.left = pt.x; - rect.top = pt.y; - rect.right = pt.x + width; - rect.bottom = pt.y + height; - - dwStyle = GetWindowLong (private->xwindow, GWL_STYLE); - dwExStyle = GetWindowLong (private->xwindow, GWL_EXSTYLE); - if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) - g_warning ("gdk_window_resize: AdjustWindowRectEx failed"); if (private->window_type != GDK_WINDOW_CHILD) { + POINT pt; + RECT rect; + DWORD dwStyle; + DWORD dwExStyle; + + pt.x = 0; + pt.y = 0; + ClientToScreen (private->xwindow, &pt); + rect.left = pt.x; + rect.top = pt.y; + rect.right = pt.x + width; + rect.bottom = pt.y + height; + + dwStyle = GetWindowLong (private->xwindow, GWL_STYLE); + dwExStyle = GetWindowLong (private->xwindow, GWL_EXSTYLE); + if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) + g_warning ("gdk_window_resize: AdjustWindowRectEx failed"); + x = rect.left; y = rect.top; + width = rect.right - rect.left; + height = rect.bottom - rect.top; } else { x = private->x; y = private->y; + private->width = width; + private->height = height; } private->resize_count += 1; - if (private->window_type == GDK_WINDOW_CHILD) - { - private->width = width; - private->height = height; - } GDK_NOTE (MISC, g_print ("...MoveWindow(%#x,%dx%d@+%d+%d)\n", - private->xwindow, - rect.right - rect.left, rect.bottom - rect.top, - x, y)); + private->xwindow, width, height, x, y)); if (!MoveWindow (private->xwindow, - x, y, - rect.right - rect.left, rect.bottom - rect.top, + x, y, width, height, TRUE)) g_warning ("gdk_window_resize: MoveWindow failed"); } @@ -1784,7 +1792,9 @@ gdk_window_get_origin (GdkWindow *window, *x = tx; if (y) *y = ty; - + + GDK_NOTE (MISC, g_print ("gdk_window_get_origin: %#x: +%d+%d\n", + private->xwindow, tx, ty)); return return_val; } @@ -1826,6 +1836,10 @@ gdk_window_get_root_origin (GdkWindow *window, *x = pt.x; if (y) *y = pt.y; + + GDK_NOTE (MISC, g_print ("gdk_window_get_root_origin: %#x: (%#x) +%d+%d\n", + ((GdkWindowPrivate *) window)->xwindow, + private->xwindow, pt.x, pt.y)); } GdkWindow* diff --git a/gdk/win32/gdkwindow.c b/gdk/win32/gdkwindow.c index d41750ae40..d003fff506 100644 --- a/gdk/win32/gdkwindow.c +++ b/gdk/win32/gdkwindow.c @@ -36,10 +36,11 @@ /* The Win API function AdjustWindowRect may return negative values * resulting in obscured title bars. This helper function is coreccting it. */ -BOOL AdjustWindowRectEx2(RECT* lpRect, - DWORD dwStyle, - BOOL bMenu, - DWORD dwExStyle) +BOOL +SafeAdjustWindowRectEx (RECT* lpRect, + DWORD dwStyle, + BOOL bMenu, + DWORD dwExStyle) { if (!AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle)) return FALSE; @@ -55,8 +56,6 @@ BOOL AdjustWindowRectEx2(RECT* lpRect, } return TRUE; } -/* HB: now use it */ -#define AdjustWindowRectEx AdjustWindowRectEx2 /* Forward declarations */ static gboolean gdk_window_gravity_works (void); @@ -176,18 +175,9 @@ gdk_window_new (GdkWindow *parent, private->resize_count = 0; private->ref_count = 1; - if (attributes_mask & GDK_WA_X) - x = attributes->x; - else - x = 0; + private->x = (attributes_mask & GDK_WA_X) ? attributes->x : 0; + private->y = (attributes_mask & GDK_WA_Y) ? attributes->y : 0; - if (attributes_mask & GDK_WA_Y) - y = attributes->y; - else - y = 0; - - private->x = x; - private->y = y; private->width = (attributes->width > 1) ? (attributes->width) : (1); private->height = (attributes->height > 1) ? (attributes->height) : (1); private->window_type = attributes->window_type; @@ -362,7 +352,7 @@ gdk_window_new (GdkWindow *parent, rect.right = rect.left + private->width; rect.bottom = rect.top + private->height; - if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) + if (!SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) g_warning ("gdk_window_new: AdjustWindowRectEx failed"); if (x != CW_USEDEFAULT) @@ -753,18 +743,39 @@ gdk_window_move (GdkWindow *window, if (!private->destroyed) { RECT rect; - DWORD dwStyle; - DWORD dwExStyle; GDK_NOTE (MISC, g_print ("gdk_window_move: %#x +%d+%d\n", private->xwindow, x, y)); + GetClientRect (private->xwindow, &rect); - dwStyle = GetWindowLong (private->xwindow, GWL_STYLE); - dwExStyle = GetWindowLong (private->xwindow, GWL_EXSTYLE); - if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) - g_warning ("gdk_window_move: AdjustWindowRectEx failed"); - if (private->window_type == GDK_WINDOW_CHILD) + if (private->window_type != GDK_WINDOW_CHILD) + { + POINT ptTL, ptBR; + DWORD dwStyle; + DWORD dwExStyle; + + ptTL.x = 0; + ptTL.y = 0; + ClientToScreen (private->xwindow, &ptTL); + rect.left = x; + rect.top = y; + + ptBR.x = rect.right; + ptBR.y = rect.bottom; + ClientToScreen (private->xwindow, &ptBR); + rect.right = x + ptBR.x - ptTL.x; + rect.bottom = y + ptBR.y - ptTL.y; + + dwStyle = GetWindowLong (private->xwindow, GWL_STYLE); + dwExStyle = GetWindowLong (private->xwindow, GWL_EXSTYLE); + if (!SafeAdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) + g_warning ("gdk_window_move: AdjustWindowRectEx failed"); + + x = rect.left; + y = rect.top; + } + else { private->x = x; private->y = y; @@ -772,10 +783,9 @@ gdk_window_move (GdkWindow *window, GDK_NOTE (MISC, g_print ("...MoveWindow(%#x,%dx%d@+%d+%d)\n", private->xwindow, rect.right - rect.left, rect.bottom - rect.top, - x + rect.left, y + rect.top)); + x, y)); if (!MoveWindow (private->xwindow, - x + rect.left, y + rect.top, - rect.right - rect.left, rect.bottom - rect.top, + x, y, rect.right - rect.left, rect.bottom - rect.top, TRUE)) g_warning ("gdk_window_move: MoveWindow failed"); } @@ -802,52 +812,50 @@ gdk_window_resize (GdkWindow *window, (private->width != (guint16) width) || (private->height != (guint16) height))) { - RECT rect; - POINT pt; - DWORD dwStyle; - DWORD dwExStyle; int x, y; GDK_NOTE (MISC, g_print ("gdk_window_resize: %#x %dx%d\n", private->xwindow, width, height)); - pt.x = 0; - pt.y = 0; - ClientToScreen (private->xwindow, &pt); - rect.left = pt.x; - rect.top = pt.y; - rect.right = pt.x + width; - rect.bottom = pt.y + height; - - dwStyle = GetWindowLong (private->xwindow, GWL_STYLE); - dwExStyle = GetWindowLong (private->xwindow, GWL_EXSTYLE); - if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) - g_warning ("gdk_window_resize: AdjustWindowRectEx failed"); if (private->window_type != GDK_WINDOW_CHILD) { + POINT pt; + RECT rect; + DWORD dwStyle; + DWORD dwExStyle; + + pt.x = 0; + pt.y = 0; + ClientToScreen (private->xwindow, &pt); + rect.left = pt.x; + rect.top = pt.y; + rect.right = pt.x + width; + rect.bottom = pt.y + height; + + dwStyle = GetWindowLong (private->xwindow, GWL_STYLE); + dwExStyle = GetWindowLong (private->xwindow, GWL_EXSTYLE); + if (!AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle)) + g_warning ("gdk_window_resize: AdjustWindowRectEx failed"); + x = rect.left; y = rect.top; + width = rect.right - rect.left; + height = rect.bottom - rect.top; } else { x = private->x; y = private->y; + private->width = width; + private->height = height; } private->resize_count += 1; - if (private->window_type == GDK_WINDOW_CHILD) - { - private->width = width; - private->height = height; - } GDK_NOTE (MISC, g_print ("...MoveWindow(%#x,%dx%d@+%d+%d)\n", - private->xwindow, - rect.right - rect.left, rect.bottom - rect.top, - x, y)); + private->xwindow, width, height, x, y)); if (!MoveWindow (private->xwindow, - x, y, - rect.right - rect.left, rect.bottom - rect.top, + x, y, width, height, TRUE)) g_warning ("gdk_window_resize: MoveWindow failed"); } @@ -1784,7 +1792,9 @@ gdk_window_get_origin (GdkWindow *window, *x = tx; if (y) *y = ty; - + + GDK_NOTE (MISC, g_print ("gdk_window_get_origin: %#x: +%d+%d\n", + private->xwindow, tx, ty)); return return_val; } @@ -1826,6 +1836,10 @@ gdk_window_get_root_origin (GdkWindow *window, *x = pt.x; if (y) *y = pt.y; + + GDK_NOTE (MISC, g_print ("gdk_window_get_root_origin: %#x: (%#x) +%d+%d\n", + ((GdkWindowPrivate *) window)->xwindow, + private->xwindow, pt.x, pt.y)); } GdkWindow*