Change the way WinBoard chooses a default board size and size/placement of the ICS...
[xboard.git] / winboard / winboard.c
index 4095feb..a06361f 100644 (file)
@@ -587,7 +587,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine)
     InitDrawingSizes((BoardSize)ibs, 0);
     if (boardSize == (BoardSize)-1 &&
        winHeight <= screenHeight && winWidth <= screenWidth) {
-      boardSize = (BoardSize)ibs;
+      boardSize = (BoardSize)ibs - 4 < 0 ? (BoardSize)0 : (BoardSize)ibs - 4;
     }
   }
   InitDrawingSizes(boardSize, 0);
@@ -1611,6 +1611,7 @@ InitAppData(LPSTR lpCmdLine)
   appData.reuseFirst = TRUE;
   appData.reuseSecond = TRUE;
   appData.blindfold = FALSE;
+  appData.icsEngineAnalyze = FALSE;
   dcb.DCBlength = sizeof(DCB);
   dcb.BaudRate = 9600;
   dcb.fBinary = TRUE;
@@ -1627,7 +1628,7 @@ InitAppData(LPSTR lpCmdLine)
   dcb.fAbortOnError = FALSE;
   /* Microsoft SDK >= Feb. 2003 (MS VS >= 2002) */
   #if (defined(_MSC_VER) && _MSC_VER <= 1200) 
-       dcb.wReserved = 0;
+       //dcb.wReserved = 0;
   #else
     dcb.wReserved = 0;
   #endif
@@ -3404,6 +3405,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
   FILE *f;
   UINT number;
   char fileTitle[MSG_SIZ];
+  char buf[MSG_SIZ];
 
   switch (message) {
 
@@ -3638,15 +3640,38 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
     case IDM_AnalysisMode:
       if (!first.analysisSupport) {
-        char buf[MSG_SIZ];
         sprintf(buf, "%s does not support analysis", first.tidy);
         DisplayError(buf, 0);
       } else {
+       /* icsEngineAnlyze */
+       if (appData.icsActive) {
+               if (gameMode != IcsObserving) {
+                       sprintf(buf, "You are not observing a game");
+                       DisplayError(buf, 0);
+                       /* secure check */
+                       if (appData.icsEngineAnalyze) {
+                               if (appData.debugMode) 
+                                       fprintf(debugFP, "Found unexpected active ICS engine analyze \n");
+                               ExitAnalyzeMode();
+                               ModeHighlight();
+                               break;
+                       }
+                       break;
+               } else {
+                       /* if enable, user want disable icsEngineAnalyze */
+                       if (appData.icsEngineAnalyze) {
+                               ExitAnalyzeMode();
+                               ModeHighlight();
+                               break;
+                       }
+                       appData.icsEngineAnalyze = TRUE;
+                       if (appData.debugMode) fprintf(debugFP, "ICS engine analyze starting...\n");
+               }
+       } 
        if (!appData.showThinking) ToggleShowThinking();
        AnalyzeModeEvent();
       }
       break;
-
     case IDM_AnalyzeFile:
       if (!first.analysisSupport) {
         char buf[MSG_SIZ];
@@ -4019,8 +4044,8 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
       AutoPlayGameLoop(); /* call into back end */
       break;
     case ANALYSIS_TIMER_ID:
-      if ((gameMode == AnalyzeMode || gameMode == AnalyzeFile) && 
-         appData.periodicUpdates) {
+      if ((gameMode == AnalyzeMode || gameMode == AnalyzeFile
+                 || appData.icsEngineAnalyze) && appData.periodicUpdates) {
        AnalysisPeriodicEvent(0);
       } else {
        KillTimer(hwnd, analysisTimerEvent);
@@ -5600,6 +5625,23 @@ ConsoleWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       wp.rcNormalPosition.bottom = consoleY + consoleH;
       SetWindowPlacement(hDlg, &wp);
     }
+    else { /* Determine Defaults */
+      WINDOWPLACEMENT wp;
+      consoleX = winWidth + 1;
+      consoleY = boardY;
+      consoleW = screenWidth -  winWidth;
+      consoleH = winHeight;
+      EnsureOnScreen(&consoleX, &consoleY);
+      wp.length = sizeof(WINDOWPLACEMENT);
+      wp.flags = 0;
+      wp.showCmd = SW_SHOW;
+      wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0;
+      wp.rcNormalPosition.left = consoleX;
+      wp.rcNormalPosition.right = consoleX + consoleW;
+      wp.rcNormalPosition.top = consoleY;
+      wp.rcNormalPosition.bottom = consoleY + consoleH;
+      SetWindowPlacement(hDlg, &wp);
+    }
     return FALSE;
 
   case WM_SETFOCUS:
@@ -6219,6 +6261,17 @@ ModeHighlight()
   }
 
   prevChecked = nowChecked;
+
+  /* icsEngineAnalyze - Do a sceure check too */
+  if (appData.icsActive) {
+       if (appData.icsEngineAnalyze) {
+               (void) CheckMenuItem(GetMenu(hwndMain), IDM_AnalysisMode,
+                       MF_BYCOMMAND|MF_CHECKED);
+       } else {
+               (void) CheckMenuItem(GetMenu(hwndMain), IDM_AnalysisMode,
+                       MF_BYCOMMAND|MF_UNCHECKED);
+       }
+  }
 }
 
 VOID
@@ -6231,6 +6284,10 @@ SetICSMode()
 #ifdef ZIPPY
   if (appData.zippyPlay) {
     SetMenuEnables(hmenu, zippyEnables);
+       /* icsEngineAnalyze */
+    if (!appData.noChessProgram) 
+         (void) EnableMenuItem(GetMenu(hwndMain), IDM_AnalysisMode,
+          MF_BYCOMMAND|MF_ENABLED);
   }
 #endif
 }
@@ -7572,6 +7629,12 @@ AnalysisDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   case WM_COMMAND: /* message: received a command */
     switch (LOWORD(wParam)) {
     case IDCANCEL:
+          /* icsEngineAnalyze */
+          if (appData.icsActive && appData.icsEngineAnalyze) {
+                  ExitAnalyzeMode();
+                  ModeHighlight();
+                  return TRUE;
+          }
       EditGameEvent();
       return TRUE;
     default: