adding support for different windows compiler
[xboard.git] / winboard / winboard.c
index 115b2c3..a00473e 100644 (file)
@@ -2,8 +2,10 @@
  * WinBoard.c -- Windows NT front end to XBoard\r
  * $Id: winboard.c,v 2.3 2003/11/25 05:25:20 mann Exp $\r
  *\r
- * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts.\r
- * Enhancements Copyright 1992-2001 Free Software Foundation, Inc.\r
+ * Copyright 1991 by Digital Equipment Corporation, Maynard,\r
+ * Massachusetts.  Enhancements Copyright\r
+ * 1992-2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software\r
+ * Foundation, Inc.\r
  *\r
  * XBoard borrows its colors and the bitmaps.xchess bitmap set from XChess,\r
  * which was written and is copyrighted by Wayne Christopher.\r
  * SOFTWARE.\r
  * ------------------------------------------------------------------------\r
  *\r
- * The following terms apply to the enhanced version of XBoard distributed\r
- * by the Free Software Foundation:\r
+ * The following terms apply to the enhanced version of XBoard\r
+ * distributed by the Free Software Foundation:\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>\r
 #include <winuser.h>\r
 #include <winsock.h>\r
+#include <commctrl.h>\r
 \r
 #include <stdio.h>\r
 #include <stdlib.h>\r
@@ -567,12 +571,14 @@ int screenHeight, screenWidth;
 void\r
 EnsureOnScreen(int *x, int *y)\r
 {\r
-  int gap = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION);\r
+//  int gap = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION);\r
   /* Be sure window at (x,y) is not off screen (or even mostly off screen) */\r
   if (*x > screenWidth - 32) *x = 0;\r
   if (*y > screenHeight - 32) *y = 0;\r
-  if (*x < 10) *x = 10;\r
-  if (*y < gap) *y = gap;\r
+  if (*x < 0) *x = 0;\r
+  if (*y < 0) *y = 0;\r
+//  if (*x < 10) *x = 10;\r
+//  if (*y < gap) *y = gap;\r
 }\r
 \r
 BOOL\r
@@ -1666,6 +1672,8 @@ ParseArgs(GetFunc get, void *cl)
     case ArgNone:\r
       ExitArgError("Unrecognized argument", argValue);\r
       break;\r
+    case ArgTrue:\r
+    case ArgFalse: ;\r
     }\r
   }\r
 }\r
@@ -1839,6 +1847,7 @@ InitAppData(LPSTR lpCmdLine)
   appData.reuseSecond = TRUE;\r
   appData.blindfold = FALSE;\r
   appData.icsEngineAnalyze = FALSE;\r
+  memset(&dcb, 0, sizeof(DCB)); // required by VS 2002 +\r
   dcb.DCBlength = sizeof(DCB);\r
   dcb.BaudRate = 9600;\r
   dcb.fBinary = TRUE;\r
@@ -3023,8 +3032,8 @@ ResizeBoard(int newSizeX, int newSizeY, int flags)
   if (recurse > 0) return;\r
   recurse++;\r
   while (newSize > 0) {\r
-       InitDrawingSizes(newSize, 0);\r
-       if(newSizeX >= sizeInfo[newSize].cliWidth ||\r
+       InitDrawingSizes(newSize+1000, 0); // [HGM] kludge to update sizeInfo without visible effects\r
+       if(newSizeX >= sizeInfo[newSize].cliWidth &&\r
           newSizeY >= sizeInfo[newSize].cliHeight) break;\r
     newSize--;\r
   } \r
@@ -3051,7 +3060,10 @@ InitDrawingSizes(BoardSize boardSize, int flags)
   int offby;\r
   LOGBRUSH logbrush;\r
 \r
-  /* [HGM] call with -1 uses old size (for if nr of files, ranks changes) */\r
+  int suppressVisibleEffects = 0; // [HGM] kludge to request updating sizeInfo only\r
+  if((int)boardSize >= 1000 ) { boardSize -= 1000; suppressVisibleEffects = 1; }\r
+\r
+  /* [HGM] call with -2 uses old size (for if nr of files, ranks changes) */\r
   if(boardSize == (BoardSize)(-2) ) boardSize = oldBoardSize;\r
 \r
   tinyLayout = sizeInfo[boardSize].tinyLayout;\r
@@ -3154,6 +3166,7 @@ InitDrawingSizes(BoardSize boardSize, int flags)
 \r
   sizeInfo[boardSize].cliWidth = boardRect.right + OUTER_MARGIN;\r
   sizeInfo[boardSize].cliHeight = boardRect.bottom + OUTER_MARGIN;\r
+  if(suppressVisibleEffects) return; // [HGM] when called for filling sizeInfo only\r
   winWidth = 2 * GetSystemMetrics(SM_CXFRAME) + boardRect.right + OUTER_MARGIN;\r
   winHeight = 2 * GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYMENU) +\r
     GetSystemMetrics(SM_CYCAPTION) + boardRect.bottom + OUTER_MARGIN;\r
@@ -5048,15 +5061,19 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     break;\r
 \r
   case WM_MOUSEWHEEL: // [DM]\r
+    {  static int lastDir = 0; // [HGM] build in some hysteresis to avoid spurious events\r
        /* Mouse Wheel is being rolled forward\r
         * Play moves forward\r
         */\r
-       if((short)HIWORD(wParam) > 0 && currentMove < forwardMostMove) ForwardEvent();\r
+       if((short)HIWORD(wParam) > 0 && currentMove < forwardMostMove) \r
+               if(lastDir == 1) ForwardEvent(); else lastDir = 1; // [HGM] suppress first event in each direction\r
        /* Mouse Wheel is being rolled backward\r
         * Play moves backward\r
         */\r
-       if((short)HIWORD(wParam) < 0 && currentMove > backwardMostMove) BackwardEvent();\r
-       break;\r
+       if((short)HIWORD(wParam) < 0 && currentMove > backwardMostMove) \r
+               if(lastDir == -1) BackwardEvent(); else lastDir = -1;\r
+    }\r
+    break;\r
 \r
   case WM_MBUTTONDOWN:\r
   case WM_RBUTTONDOWN:\r
@@ -8851,7 +8868,7 @@ DisplayMessage(char *str1, char *str2)
   }\r
   messageText[MESSAGE_TEXT_MAX - 1] = NULLCHAR;\r
 \r
-  if (IsIconic(hwndMain)) return;\r
+  if (hwndMain == NULL || IsIconic(hwndMain)) return;\r
   hdc = GetDC(hwndMain);\r
   oldFont = SelectObject(hdc, font[boardSize][MESSAGE_FONT]->hf);\r
   ExtTextOut(hdc, messageRect.left, messageRect.top, ETO_CLIPPED|ETO_OPAQUE,\r
@@ -10684,3 +10701,4 @@ void SetProgramStats( FrontEndProgramStats * stats )
 \r
     EngineOutputUpdate( stats );\r
 }\r
+///
\ No newline at end of file