changes from H.G. Muller; version 4.3.13
[xboard.git] / winboard / wlayout.c
index c0606bb..d5e8153 100644 (file)
-/*
- * Layout management
- *
- * Author: Alessandro Scotti (Dec 2005)
- *
- * ------------------------------------------------------------------------
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- * ------------------------------------------------------------------------
- */
-#include "config.h"
-
-#include <windows.h> /* required for all Windows applications */
-#include <stdio.h>
-#include <stdlib.h>
-#include <malloc.h>
-#include <commdlg.h>
-#include <dlgs.h>
-
-#include "common.h"
-#include "winboard.h"
-
-VOID RestoreWindowPlacement( HWND hWnd, WindowPlacement * wp )
-{
-    if( wp->x != CW_USEDEFAULT ||
-        wp->y != CW_USEDEFAULT ||
-        wp->width != CW_USEDEFAULT ||
-        wp->height != CW_USEDEFAULT )
-    {
-       WINDOWPLACEMENT stWP;
-
-        ZeroMemory( &stWP, sizeof(stWP) );
-
-       EnsureOnScreen( &wp->x, &wp->y);
-
-       stWP.length = sizeof(stWP);
-       stWP.flags = 0;
-       stWP.showCmd = SW_SHOW;
-       stWP.ptMaxPosition.x = 0;
-        stWP.ptMaxPosition.y = 0;
-       stWP.rcNormalPosition.left = wp->x;
-       stWP.rcNormalPosition.right = wp->x + wp->width;
-       stWP.rcNormalPosition.top = wp->y;
-       stWP.rcNormalPosition.bottom = wp->y + wp->height;
-
-       SetWindowPlacement(hWnd, &stWP);
-    }
-}
-
-VOID InitWindowPlacement( WindowPlacement * wp )
-{
-    wp->visible = TRUE;
-    wp->x = CW_USEDEFAULT;
-    wp->y = CW_USEDEFAULT;
-    wp->width = CW_USEDEFAULT;
-    wp->height = CW_USEDEFAULT;
-}
-
-static BOOL IsAttachDistance( int a, int b )
-{
-    BOOL result = FALSE;
-
-    if( a == b ) {
-        result = TRUE;
-    }
-
-    return result;
-}
-
-static BOOL IsDefaultPlacement( WindowPlacement * wp )
-{
-    BOOL result = FALSE;
-
-    if( wp->x == CW_USEDEFAULT || wp->y == CW_USEDEFAULT || wp->width == CW_USEDEFAULT || wp->height == CW_USEDEFAULT ) {
-        result = TRUE;
-    }
-
-    return result;
-}
-
-static BOOL GetActualPlacement( HWND hWnd, WindowPlacement * wp )
-{
-    BOOL result = FALSE;
-
-    if( hWnd != NULL ) {
-        WINDOWPLACEMENT stWP;
-
-        ZeroMemory( &stWP, sizeof(stWP) );
-
-        stWP.length = sizeof(stWP);
-
-        GetWindowPlacement( hWnd, &stWP );
-
-        wp->x = stWP.rcNormalPosition.left;
-        wp->y = stWP.rcNormalPosition.top;
-        wp->width = stWP.rcNormalPosition.right - stWP.rcNormalPosition.left;
-        wp->height = stWP.rcNormalPosition.bottom - stWP.rcNormalPosition.top;
-
-        result = TRUE;
-    }
-
-    return result;
-}
-
-static BOOL IsAttachedByWindowPlacement( LPRECT lprcMain, WindowPlacement * wp )
-{
-    BOOL result = FALSE;
-
-    if( ! IsDefaultPlacement(wp) ) {
-        if( IsAttachDistance( lprcMain->right, wp->x ) ||
-            IsAttachDistance( lprcMain->bottom, wp->y ) ||
-            IsAttachDistance( lprcMain->left, (wp->x + wp->width) ) ||
-            IsAttachDistance( lprcMain->top, (wp->y + wp->height) ) )
-        {
-            result = TRUE;
-        }
-    }
-
-    return result;
-}
-
-VOID ReattachAfterMove( LPRECT lprcOldPos, int new_x, int new_y, HWND hWndChild, WindowPlacement * pwpChild )
-{
-    if( ! IsDefaultPlacement( pwpChild ) ) {
-        GetActualPlacement( hWndChild, pwpChild );
-
-        if( IsAttachedByWindowPlacement( lprcOldPos, pwpChild ) ) {
-            /* Get position delta */
-            int delta_x = pwpChild->x - lprcOldPos->left;
-            int delta_y = pwpChild->y - lprcOldPos->top;
-
-            /* Adjust placement */
-            pwpChild->x = new_x + delta_x;
-            pwpChild->y = new_y + delta_y;
-
-            /* Move window */
-            if( hWndChild != NULL ) {
-                SetWindowPos( hWndChild, HWND_TOP,
-                    pwpChild->x, pwpChild->y,
-                    0, 0,
-                    SWP_NOZORDER | SWP_NOSIZE );
-            }
-        }
-    }
-}
+/*\r
+ * Layout management\r
+ *\r
+ * Author: Alessandro Scotti (Dec 2005)\r
+ *\r
+ * ------------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ * ------------------------------------------------------------------------\r
+ */\r
+#include "config.h"\r
+\r
+#include <windows.h> /* required for all Windows applications */\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <malloc.h>\r
+#include <commdlg.h>\r
+#include <dlgs.h>\r
+\r
+#include "common.h"\r
+#include "winboard.h"\r
+\r
+VOID RestoreWindowPlacement( HWND hWnd, WindowPlacement * wp )\r
+{\r
+    if( wp->x != CW_USEDEFAULT || \r
+        wp->y != CW_USEDEFAULT ||\r
+        wp->width != CW_USEDEFAULT || \r
+        wp->height != CW_USEDEFAULT )\r
+    {\r
+       WINDOWPLACEMENT stWP;\r
+\r
+        ZeroMemory( &stWP, sizeof(stWP) );\r
+\r
+       EnsureOnScreen( &wp->x, &wp->y);\r
+\r
+       stWP.length = sizeof(stWP);\r
+       stWP.flags = 0;\r
+       stWP.showCmd = SW_SHOW;\r
+       stWP.ptMaxPosition.x = 0;\r
+        stWP.ptMaxPosition.y = 0;\r
+       stWP.rcNormalPosition.left = wp->x;\r
+       stWP.rcNormalPosition.right = wp->x + wp->width;\r
+       stWP.rcNormalPosition.top = wp->y;\r
+       stWP.rcNormalPosition.bottom = wp->y + wp->height;\r
+\r
+       SetWindowPlacement(hWnd, &stWP);\r
+    }\r
+}\r
+\r
+VOID InitWindowPlacement( WindowPlacement * wp )\r
+{\r
+    wp->visible = TRUE;\r
+    wp->x = CW_USEDEFAULT;\r
+    wp->y = CW_USEDEFAULT;\r
+    wp->width = CW_USEDEFAULT;\r
+    wp->height = CW_USEDEFAULT;\r
+}\r
+\r
+static BOOL IsAttachDistance( int a, int b )\r
+{\r
+    BOOL result = FALSE;\r
+\r
+    if( a == b ) {\r
+        result = TRUE;\r
+    }\r
+\r
+    return result;\r
+}\r
+\r
+static BOOL IsDefaultPlacement( WindowPlacement * wp )\r
+{\r
+    BOOL result = FALSE;\r
+\r
+    if( wp->x == CW_USEDEFAULT || wp->y == CW_USEDEFAULT || wp->width == CW_USEDEFAULT || wp->height == CW_USEDEFAULT ) {\r
+        result = TRUE;\r
+    }\r
+\r
+    return result;\r
+}\r
+\r
+static BOOL GetActualPlacement( HWND hWnd, WindowPlacement * wp )\r
+{\r
+    BOOL result = FALSE;\r
+\r
+    if( hWnd != NULL ) {\r
+        WINDOWPLACEMENT stWP;\r
+\r
+        ZeroMemory( &stWP, sizeof(stWP) );\r
+\r
+        stWP.length = sizeof(stWP);\r
+\r
+        GetWindowPlacement( hWnd, &stWP );\r
+\r
+        wp->x = stWP.rcNormalPosition.left;\r
+        wp->y = stWP.rcNormalPosition.top;\r
+        wp->width = stWP.rcNormalPosition.right - stWP.rcNormalPosition.left;\r
+        wp->height = stWP.rcNormalPosition.bottom - stWP.rcNormalPosition.top;\r
+\r
+        result = TRUE;\r
+    }\r
+\r
+    return result;\r
+}\r
+\r
+static BOOL IsAttachedByWindowPlacement( LPRECT lprcMain, WindowPlacement * wp )\r
+{\r
+    BOOL result = FALSE;\r
+\r
+    if( ! IsDefaultPlacement(wp) ) {\r
+        if( IsAttachDistance( lprcMain->right, wp->x ) ||\r
+            IsAttachDistance( lprcMain->bottom, wp->y ) ||\r
+            IsAttachDistance( lprcMain->left, (wp->x + wp->width) ) ||\r
+            IsAttachDistance( lprcMain->top, (wp->y + wp->height) ) )\r
+        {\r
+            result = TRUE;\r
+        }\r
+    }\r
+\r
+    return result;\r
+}\r
+\r
+VOID ReattachAfterMove( LPRECT lprcOldPos, int new_x, int new_y, HWND hWndChild, WindowPlacement * pwpChild )\r
+{\r
+    if( ! IsDefaultPlacement( pwpChild ) ) {\r
+        GetActualPlacement( hWndChild, pwpChild );\r
+\r
+        if( IsAttachedByWindowPlacement( lprcOldPos, pwpChild ) ) {\r
+            /* Get position delta */\r
+            int delta_x = pwpChild->x - lprcOldPos->left;\r
+            int delta_y = pwpChild->y - lprcOldPos->top;\r
+\r
+            /* Adjust placement */\r
+            pwpChild->x = new_x + delta_x;\r
+            pwpChild->y = new_y + delta_y;\r
+\r
+            /* Move window */\r
+            if( hWndChild != NULL ) {\r
+                SetWindowPos( hWndChild, HWND_TOP,\r
+                    pwpChild->x, pwpChild->y,\r
+                    0, 0,\r
+                    SWP_NOZORDER | SWP_NOSIZE );\r
+            }\r
+        }\r
+    }\r
+}\r