Fix multi-leg promotions
[xboard.git] / winboard / wlayout.c
index d5e8153..c308fb3 100644 (file)
@@ -3,22 +3,29 @@
  *\r
  * Author: Alessandro Scotti (Dec 2005)\r
  *\r
+ * Copyright 2005 Alessandro Scotti\r
+ *\r
+ * Enhancements Copyright 2009, 2012, 2013, 2014, 2015, 2016 Free\r
+ * Software Foundation, Inc.\r
+ *\r
  * ------------------------------------------------------------------------\r
- * This program is free software; you can redistribute it and/or modify\r
+ *\r
+ * GNU XBoard 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
+ * the Free Software Foundation, either version 3 of the License, or (at\r
+ * 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
+ * GNU XBoard is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * 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
+ * along with this program. If not, see http://www.gnu.org/licenses/.  *\r
+ *\r
+ *------------------------------------------------------------------------\r
+ ** See the file ChangeLog for a revision history.  */\r
+\r
 #include "config.h"\r
 \r
 #include <windows.h> /* required for all Windows applications */\r
@@ -29,6 +36,7 @@
 #include <dlgs.h>\r
 \r
 #include "common.h"\r
+#include "frontend.h"\r
 #include "winboard.h"\r
 \r
 VOID RestoreWindowPlacement( HWND hWnd, WindowPlacement * wp )\r
@@ -42,7 +50,7 @@ VOID RestoreWindowPlacement( HWND hWnd, WindowPlacement * wp )
 \r
         ZeroMemory( &stWP, sizeof(stWP) );\r
 \r
-       EnsureOnScreen( &wp->x, &wp->y);\r
+       EnsureOnScreen( &wp->x, &wp->y, 0, 0);\r
 \r
        stWP.length = sizeof(stWP);\r
        stWP.flags = 0;\r
@@ -89,7 +97,7 @@ static BOOL IsDefaultPlacement( WindowPlacement * wp )
     return result;\r
 }\r
 \r
-static BOOL GetActualPlacement( HWND hWnd, WindowPlacement * wp )\r
+BOOL GetActualPlacement( HWND hWnd, WindowPlacement * wp )\r
 {\r
     BOOL result = FALSE;\r
 \r
@@ -154,3 +162,40 @@ VOID ReattachAfterMove( LPRECT lprcOldPos, int new_x, int new_y, HWND hWndChild,
         }\r
     }\r
 }\r
+\r
+extern FILE *debugFP;\r
+VOID ReattachAfterSize( LPRECT lprcOldPos, int new_w, int new_h, HWND hWndChild, WindowPlacement * pwpChild )\r
+{\r
+    if( ! IsDefaultPlacement( pwpChild ) ) {\r
+        GetActualPlacement( hWndChild, pwpChild );\r
+\r
+        if( IsAttachedByWindowPlacement( lprcOldPos, pwpChild ) ) {\r
+            /* Get delta of lower right corner */\r
+            int delta_x = new_w - (lprcOldPos->right  - lprcOldPos->left);\r
+            int delta_y = new_h - (lprcOldPos->bottom - lprcOldPos->top);\r
+\r
+            /* Adjust size & placement */\r
+            if(pwpChild->x + pwpChild->width  >= lprcOldPos->right &&\r
+              (pwpChild->x + pwpChild->width  < screenGeometry.right - 5 || delta_x > 0) ) // keep right edge glued to display edge if touching\r
+               pwpChild->width += delta_x;\r
+            if(pwpChild->x + pwpChild->width  >= screenGeometry.right  ) // don't move right edge off screen\r
+               pwpChild->width = screenGeometry.right - pwpChild->x;\r
+            if(pwpChild->y + pwpChild->height >= lprcOldPos->bottom &&\r
+              (pwpChild->y + pwpChild->height < screenGeometry.bottom - 35 || delta_y > 0) ) // keep bottom edge glued to display edge if touching\r
+               pwpChild->height += delta_y;\r
+            if(pwpChild->y + pwpChild->height >= screenGeometry.bottom - 30 ) // don't move bottom edge off screen\r
+               pwpChild->height = screenGeometry.bottom - 30 - pwpChild->y;\r
+            if(pwpChild->x >= lprcOldPos->right)  pwpChild->width  -= delta_x, pwpChild->x += delta_x;\r
+            if(pwpChild->y >= lprcOldPos->bottom) pwpChild->height -= delta_y, pwpChild->y += delta_y;\r
+            if(pwpChild->width  < 30) pwpChild->width = 30;  // force minimum width\r
+            if(pwpChild->height < 50) pwpChild->height = 50; // force minimum height\r
+            /* Move window */\r
+            if( hWndChild != NULL ) {\r
+                SetWindowPos( hWndChild, HWND_TOP,\r
+                    pwpChild->x, pwpChild->y,\r
+                    pwpChild->width, pwpChild->height,\r
+                    SWP_NOZORDER );\r
+            }\r
+        }\r
+    }\r
+}\r