changes by H.G. Muller; version 4.3.4
[xboard.git] / winboard / woptions.c
index a740f8f..1d92129 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
  * woptions.c -- Options dialog box routines for WinBoard\r
- * $Id: woptions.c,v 2.1 2003/10/27 19:21:02 mann Exp $
+ * $Id: woptions.c,v 2.1 2003/10/27 19:21:02 mann Exp $\r
  *\r
  * Copyright 2000 Free Software Foundation, Inc.\r
  *\r
@@ -26,7 +26,7 @@
 #include <windows.h>   /* required for all Windows applications */\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
-#include <shlobj.h>    /* [AS] Requires NT 4.0 or Win95 */
+#include <shlobj.h>    /* [AS] Requires NT 4.0 or Win95 */\r
 \r
 #include "common.h"\r
 #include "winboard.h"\r
@@ -60,7 +60,7 @@ extern ColorClass currentColorClass;
 extern HWND hwndConsole;\r
 extern char *defaultTextAttribs[];\r
 extern HWND commentDialog;\r
-extern HWND moveHistoryDialog;
+extern HWND moveHistoryDialog;\r
 extern char installDir[];\r
 extern HWND hCommPort;    /* currently open comm port */\r
 extern DCB dcb;\r
@@ -82,6 +82,7 @@ typedef struct {
 \r
 LRESULT CALLBACK GeneralOptions(HWND, UINT, WPARAM, LPARAM);\r
 LRESULT CALLBACK BoardOptions(HWND, UINT, WPARAM, LPARAM);\r
+LRESULT CALLBACK NewVariant(HWND, UINT, WPARAM, LPARAM);\r
 LRESULT CALLBACK IcsOptions(HWND, UINT, WPARAM, LPARAM);\r
 LRESULT CALLBACK FontOptions(HWND, UINT, WPARAM, LPARAM);\r
 LRESULT CALLBACK CommPortOptions(HWND, UINT, WPARAM, LPARAM);\r
@@ -169,10 +170,10 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     CHECK_BOX(OPT_ShowCoordinates, appData.showCoords);\r
     CHECK_BOX(OPT_ShowThinking, appData.showThinking);\r
     CHECK_BOX(OPT_TestLegality, appData.testLegality);\r
-    CHECK_BOX(OPT_HideThinkFromHuman, appData.hideThinkingFromHuman);
-    CHECK_BOX(OPT_SaveExtPGN, appData.saveExtendedInfoInPGN);
-    CHECK_BOX(OPT_ExtraInfoInMoveHistory, appData.showEvalInMoveHistory);
-    CHECK_BOX(OPT_HighlightMoveArrow, appData.highlightMoveWithArrow);
+    CHECK_BOX(OPT_HideThinkFromHuman, appData.hideThinkingFromHuman);\r
+    CHECK_BOX(OPT_SaveExtPGN, appData.saveExtendedInfoInPGN);\r
+    CHECK_BOX(OPT_ExtraInfoInMoveHistory, appData.showEvalInMoveHistory);\r
+    CHECK_BOX(OPT_HighlightMoveArrow, appData.highlightMoveWithArrow);\r
 \r
 #undef CHECK_BOX\r
 \r
@@ -214,10 +215,10 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       appData.showCoords           = IS_CHECKED(OPT_ShowCoordinates);\r
       ShowThinkingEvent(             IS_CHECKED(OPT_ShowThinking));\r
       appData.testLegality         = IS_CHECKED(OPT_TestLegality);\r
-      appData.hideThinkingFromHuman= IS_CHECKED(OPT_HideThinkFromHuman);
-      appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN);
-      appData.showEvalInMoveHistory= IS_CHECKED(OPT_ExtraInfoInMoveHistory);
-      appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow);
+      appData.hideThinkingFromHuman= IS_CHECKED(OPT_HideThinkFromHuman);\r
+      appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN);\r
+      appData.showEvalInMoveHistory= IS_CHECKED(OPT_ExtraInfoInMoveHistory);\r
+      appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow);\r
 \r
 #undef IS_CHECKED\r
 \r
@@ -728,6 +729,161 @@ BoardOptionsPopup(HWND hwnd)
   FreeProcInstance(lpProc);\r
 }\r
 \r
+VariantClass\r
+VariantWhichRadio(HWND hDlg)\r
+{\r
+  return (IsDlgButtonChecked(hDlg, OPT_VariantFairy) ? VariantFairy :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantGothic) ? VariantGothic :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantCrazyhouse) ? VariantCrazyhouse :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantBughouse) ? VariantBughouse :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantCourier) ? VariantCourier :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantShogi) ? VariantShogi :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantXiangqi) ? VariantXiangqi :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantCapablanca) ? VariantCapablanca :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantTwoKings) ? VariantTwoKings :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantKnightmate) ? VariantKnightmate :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantLosers) ? VariantLosers :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantSuicide) ? VariantSuicide :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantAtomic) ? VariantAtomic :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :\r
+          VariantNormal )))))))))))))));\r
+}\r
+\r
+LRESULT CALLBACK\r
+NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
+{\r
+  static Boolean  mono;\r
+  static VariantClass v;\r
+  static COLORREF lsc, dsc, wpc, bpc, hsc, phc;\r
+  static HBITMAP pieces[3];\r
+  static int n1_ok, n2_ok, n3_ok;\r
+\r
+  switch (message) {\r
+  case WM_INITDIALOG: /* message: initialize dialog box */\r
+    /* Center the dialog over the application window */\r
+    CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    /* Initialize the dialog items */\r
+    switch (gameInfo.variant) {\r
+    case VariantNormal:\r
+      CheckDlgButton(hDlg, OPT_VariantNormal, TRUE);\r
+      break;\r
+    case VariantCrazyhouse:\r
+      CheckDlgButton(hDlg, OPT_VariantCrazyhouse, TRUE);\r
+      break;\r
+    case VariantBughouse:\r
+      CheckDlgButton(hDlg, OPT_VariantBughouse, TRUE);\r
+      break;\r
+    case VariantShogi:\r
+      CheckDlgButton(hDlg, OPT_VariantShogi, TRUE);\r
+      break;\r
+    case VariantXiangqi:\r
+      CheckDlgButton(hDlg, OPT_VariantXiangqi, TRUE);\r
+      break;\r
+    case VariantCapablanca:\r
+      CheckDlgButton(hDlg, OPT_VariantCapablanca, TRUE);\r
+      break;\r
+    case VariantGothic:\r
+      CheckDlgButton(hDlg, OPT_VariantGothic, TRUE);\r
+      break;\r
+    case VariantCourier:\r
+      CheckDlgButton(hDlg, OPT_VariantCourier, TRUE);\r
+      break;\r
+    case VariantKnightmate:\r
+      CheckDlgButton(hDlg, OPT_VariantKnightmate, TRUE);\r
+      break;\r
+    case VariantTwoKings:\r
+      CheckDlgButton(hDlg, OPT_VariantTwoKings, TRUE);\r
+      break;\r
+    case VariantFairy:\r
+      CheckDlgButton(hDlg, OPT_VariantFairy, TRUE);\r
+      break;\r
+    case VariantAtomic:\r
+      CheckDlgButton(hDlg, OPT_VariantAtomic, TRUE);\r
+      break;\r
+    case VariantSuicide:\r
+      CheckDlgButton(hDlg, OPT_VariantSuicide, TRUE);\r
+      break;\r
+    case VariantLosers:\r
+      CheckDlgButton(hDlg, OPT_VariantLosers, TRUE);\r
+      break;\r
+    case VariantShatranj:\r
+      CheckDlgButton(hDlg, OPT_VariantShatranj, TRUE);\r
+      break;\r
+    }\r
+\r
+    SetDlgItemInt( hDlg, IDC_Files, -1, TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_Files, EM_SETSEL, 0, -1 );\r
+\r
+    SetDlgItemInt( hDlg, IDC_Ranks, -1, TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );\r
+\r
+    SetDlgItemInt( hDlg, IDC_Holdings, -1, TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );\r
+\r
+    n1_ok = n2_ok = n3_ok = FALSE;\r
+\r
+    return TRUE;\r
+\r
+  case WM_COMMAND: /* message: received a command */\r
+    switch (LOWORD(wParam)) {\r
+    case IDOK:\r
+      /* \r
+       * if we call EndDialog() after the call to ChangeBoardSize(),\r
+       * then ChangeBoardSize() does not take effect, although the new\r
+       * boardSize is saved. Go figure...\r
+       */\r
+      EndDialog(hDlg, TRUE);\r
+\r
+      v = VariantWhichRadio(hDlg);\r
+\r
+      gameInfo.variant = v;\r
+      appData.variant = VariantName(v);\r
+\r
+      appData.NrFiles = (int) GetDlgItemInt(hDlg, IDC_Files, NULL, FALSE );\r
+      appData.NrRanks = (int) GetDlgItemInt(hDlg, IDC_Ranks, NULL, FALSE );\r
+      appData.holdingsSize = (int) GetDlgItemInt(hDlg, IDC_Holdings, NULL, FALSE );\r
+\r
+      if(!n1_ok) appData.NrFiles = -1;\r
+      if(!n2_ok) appData.NrRanks = -1;\r
+      if(!n3_ok) appData.holdingsSize = -1;\r
+\r
+      Reset(TRUE, TRUE);\r
+\r
+      return TRUE;\r
+\r
+    case IDCANCEL:\r
+      EndDialog(hDlg, FALSE);\r
+      return TRUE;\r
+\r
+    case IDC_Ranks:\r
+    case IDC_Files:\r
+    case IDC_Holdings:\r
+        if( HIWORD(wParam) == EN_CHANGE ) {\r
+\r
+            GetDlgItemInt(hDlg, IDC_Files, &n1_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_Ranks, &n2_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_Holdings, &n3_ok, FALSE );\r
+\r
+            /*EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok ? TRUE : FALSE );*/\r
+        }\r
+        return TRUE;\r
+    }\r
+    break;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+\r
+VOID\r
+NewVariantPopup(HWND hwnd)\r
+{\r
+  FARPROC lpProc = MakeProcInstance((FARPROC)NewVariantDialog, hInst);\r
+  DialogBox(hInst, MAKEINTRESOURCE(DLG_NewVariant), hwnd,\r
+         (DLGPROC) lpProc);\r
+  FreeProcInstance(lpProc);\r
+}\r
+\r
 /*---------------------------------------------------------------------------*\\r
  *\r
  * ICS Options Dialog functions\r
@@ -1321,7 +1477,7 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);\r
       SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);\r
       SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);\r
-      SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
+      SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);\r
       firstPaint = FALSE;\r
     }\r
     break;\r
@@ -1349,7 +1505,7 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        CopyFont(font[i][EDITTAGS_FONT], &workFont[EDITTAGS_FONT]);\r
        CopyFont(font[i][CONSOLE_FONT],  &workFont[CONSOLE_FONT]);\r
        CopyFont(font[i][COMMENT_FONT],  &workFont[COMMENT_FONT]);\r
-       CopyFont(font[i][MOVEHISTORY_FONT],  &workFont[MOVEHISTORY_FONT]);
+       CopyFont(font[i][MOVEHISTORY_FONT],  &workFont[MOVEHISTORY_FONT]);\r
       }\r
       /* end sad necessity */\r
 \r
@@ -1372,13 +1528,13 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        InvalidateRect(editTagsDialog, &rect, TRUE);\r
       }\r
 \r
-      if( moveHistoryDialog != NULL ) {
-       SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory,
-         WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,
-         MAKELPARAM(TRUE, 0));
-       InvalidateRect(editTagsDialog, NULL, TRUE);
-      }
-
+      if( moveHistoryDialog != NULL ) {\r
+       SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory,\r
+         WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, \r
+         MAKELPARAM(TRUE, 0));\r
+       InvalidateRect(editTagsDialog, NULL, TRUE);\r
+      }\r
+\r
       if (hwndConsole) {\r
        ChangedConsoleFont();\r
       }\r
@@ -1424,11 +1580,11 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);\r
       break;\r
 \r
-    case OPT_ChooseMoveHistoryFont:
-      MyCreateFont(hDlg, &workFont[MOVEHISTORY_FONT]);
-      SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
-      break;
-
+    case OPT_ChooseMoveHistoryFont:\r
+      MyCreateFont(hDlg, &workFont[MOVEHISTORY_FONT]);\r
+      SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);\r
+      break;\r
+\r
     case OPT_DefaultFonts:\r
       for (i=0; i<NUM_FONTS; i++) {\r
        DeleteObject(&workFont[i].hf);\r
@@ -1441,7 +1597,7 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);\r
       SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);\r
       SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);\r
-      SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
+      SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);\r
       break;\r
     }\r
   }\r
@@ -2258,7 +2414,7 @@ SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     } else {\r
       CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_PGN);\r
     }\r
-    CheckDlgButton( hDlg, OPT_OutOfBookInfo, appData.saveOutOfBookInfo );
+    CheckDlgButton( hDlg, OPT_OutOfBookInfo, appData.saveOutOfBookInfo );\r
     SetSaveOptionEnables(hDlg);\r
     return TRUE;\r
 \r
@@ -2298,7 +2454,7 @@ SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        appData.saveGameFile = "";\r
       }\r
       appData.oldSaveStyle = IsDlgButtonChecked(hDlg, OPT_Old);\r
-      appData.saveOutOfBookInfo = IsDlgButtonChecked( hDlg, OPT_OutOfBookInfo );
+      appData.saveOutOfBookInfo = IsDlgButtonChecked( hDlg, OPT_OutOfBookInfo );\r
       EndDialog(hDlg, TRUE);\r
       return TRUE;\r
 \r
@@ -2456,231 +2612,254 @@ TimeControlOptionsPopup(HWND hwnd)
   }\r
 }\r
 \r
-/*---------------------------------------------------------------------------*\
- *
- * Engine Options Dialog functions
- *
-\*---------------------------------------------------------------------------*/
-#define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
-#define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
-
-#define INT_ABS( n )    ((n) >= 0 ? (n) : -(n))
-
-LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
-{
-  switch (message) {
-  case WM_INITDIALOG: /* message: initialize dialog box */
-
-    /* Center the dialog over the application window */
-    CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
-
-    /* Initialize the dialog items */
-    CHECK_BOX(IDC_EpPeriodicUpdates, appData.periodicUpdates);
-    CHECK_BOX(IDC_EpPonder, appData.ponderNextMove);
-    CHECK_BOX(IDC_EpShowThinking, appData.showThinking);
-    CHECK_BOX(IDC_EpHideThinkingHuman, appData.hideThinkingFromHuman);
-
-    SetDlgItemInt( hDlg, IDC_EpDrawMoveCount, appData.adjudicateDrawMoves, TRUE );
-    SendDlgItemMessage( hDlg, IDC_EpDrawMoveCount, EM_SETSEL, 0, -1 );
-
-    SetDlgItemInt( hDlg, IDC_EpAdjudicationThreshold, INT_ABS(appData.adjudicateLossThreshold), TRUE );
-    SendDlgItemMessage( hDlg, IDC_EpAdjudicationThreshold, EM_SETSEL, 0, -1 );
-
-    return TRUE;
-
-  case WM_COMMAND: /* message: received a command */
-    switch (LOWORD(wParam)) {
-    case IDOK:
-      /* Read changed options from the dialog box */
-      PeriodicUpdatesEvent(          IS_CHECKED(IDC_EpPeriodicUpdates));
-      PonderNextMoveEvent(           IS_CHECKED(IDC_EpPonder));
-      ShowThinkingEvent(             IS_CHECKED(IDC_EpShowThinking));
-      appData.hideThinkingFromHuman= IS_CHECKED(IDC_EpHideThinkingHuman);
-
-      appData.adjudicateDrawMoves = GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, NULL, FALSE );
-      appData.adjudicateLossThreshold = - (int) GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, NULL, FALSE );
-
-      EndDialog(hDlg, TRUE);
-      return TRUE;
-
-    case IDCANCEL:
-      EndDialog(hDlg, FALSE);
-      return TRUE;
-
-    case IDC_EpDrawMoveCount:
-    case IDC_EpAdjudicationThreshold:
-        if( HIWORD(wParam) == EN_CHANGE ) {
-            int n1_ok;
-            int n2_ok;
-
-            GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, &n1_ok, FALSE );
-            GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, &n2_ok, FALSE );
-
-            EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok ? TRUE : FALSE );
-        }
-        return TRUE;
-    }
-    break;
-  }
-  return FALSE;
-}
-
-VOID EnginePlayOptionsPopup(HWND hwnd)
-{
-  FARPROC lpProc;
-\r
-  lpProc = MakeProcInstance((FARPROC)EnginePlayOptionsDialog, hInst);
-  DialogBox(hInst, MAKEINTRESOURCE(DLG_EnginePlayOptions), hwnd, (DLGPROC) lpProc);
-  FreeProcInstance(lpProc);
-}
-
-/*---------------------------------------------------------------------------*\
- *
- * UCI Options Dialog functions
- *
-\*---------------------------------------------------------------------------*/
-static BOOL BrowseForFolder( const char * title, char * path )
-{
-    BOOL result = FALSE;
-    BROWSEINFO bi;
-    LPITEMIDLIST pidl;
-
-    ZeroMemory( &bi, sizeof(bi) );
-
-    bi.lpszTitle = title == 0 ? "Choose Folder" : title;
-    bi.ulFlags = BIF_RETURNONLYFSDIRS;
-
-    pidl = SHBrowseForFolder( &bi );
-
-    if( pidl != 0 ) {
-        IMalloc * imalloc = 0;
-
-        if( SHGetPathFromIDList( pidl, path ) ) {
-            result = TRUE;
-        }
-
-        if( SUCCEEDED( SHGetMalloc ( &imalloc ) ) ) {
-            imalloc->lpVtbl->Free(imalloc,pidl);
-            imalloc->lpVtbl->Release(imalloc);
-        }
-    }
-
-    return result;
-}
-
-LRESULT CALLBACK UciOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
-{
-  char buf[MAX_PATH];
-
-  switch (message) {
-  case WM_INITDIALOG: /* message: initialize dialog box */
-
-    /* Center the dialog over the application window */
-    CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
-
-    /* Initialize the dialog items */
-    SetDlgItemText( hDlg, IDC_PolyglotDir, appData.polyglotDir );
-    SetDlgItemInt( hDlg, IDC_HashSize, appData.defaultHashSize, TRUE );
-    SetDlgItemText( hDlg, IDC_PathToEGTB, appData.defaultPathEGTB );
-    SetDlgItemInt( hDlg, IDC_SizeOfEGTB, appData.defaultCacheSizeEGTB, TRUE );
-    CheckDlgButton( hDlg, IDC_UseBook, (BOOL) appData.usePolyglotBook );
-    SetDlgItemText( hDlg, IDC_BookFile, appData.polyglotBook );
-
-    SendDlgItemMessage( hDlg, IDC_PolyglotDir, EM_SETSEL, 0, -1 );
-
-    return TRUE;
-
-  case WM_COMMAND: /* message: received a command */
-    switch (LOWORD(wParam)) {
-    case IDOK:
-      GetDlgItemText( hDlg, IDC_PolyglotDir, buf, sizeof(buf) );
-      appData.polyglotDir = strdup(buf);
-      appData.defaultHashSize = GetDlgItemInt(hDlg, IDC_HashSize, NULL, FALSE );
-      appData.defaultCacheSizeEGTB = GetDlgItemInt(hDlg, IDC_SizeOfEGTB, NULL, FALSE );
-      GetDlgItemText( hDlg, IDC_PathToEGTB, buf, sizeof(buf) );
-      appData.defaultPathEGTB = strdup(buf);
-      GetDlgItemText( hDlg, IDC_BookFile, buf, sizeof(buf) );
-      appData.polyglotBook = strdup(buf);
-      appData.usePolyglotBook = (Boolean) IsDlgButtonChecked( hDlg, IDC_UseBook );
-
-      EndDialog(hDlg, TRUE);
-      return TRUE;
-
-    case IDCANCEL:
-      EndDialog(hDlg, FALSE);
-      return TRUE;
-
-    case IDC_BrowseForBook:
-      {
-          char filter[] = {
-              'A','l','l',' ','F','i','l','e','s', 0,
-              '*','.','*', 0,
-              'B','I','N',' ','F','i','l','e','s', 0,
-              '*','.','b','i','n', 0,
-              0 };
-
-          OPENFILENAME ofn;
-
-          strcpy( buf, "" );
-
-          ZeroMemory( &ofn, sizeof(ofn) );
-
-          ofn.lStructSize = sizeof(ofn);
-          ofn.hwndOwner = hDlg;
-          ofn.hInstance = hInst;
-          ofn.lpstrFilter = filter;
-          ofn.lpstrFile = buf;
-          ofn.nMaxFile = sizeof(buf);
-          ofn.lpstrTitle = "Choose Book";
-          ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;
-
-          if( GetOpenFileName( &ofn ) ) {
-              SetDlgItemText( hDlg, IDC_BookFile, buf );
-          }
-      }
-      return TRUE;
-
-    case IDC_BrowseForPolyglotDir:
-      if( BrowseForFolder( "Choose Polyglot Directory", buf ) ) {
-        SetDlgItemText( hDlg, IDC_PolyglotDir, buf );
-
-        strcat( buf, "\\polyglot.exe" );
-
-        if( GetFileAttributes(buf) == 0xFFFFFFFF ) {
-            MessageBox( hDlg, "Polyglot was not found in the specified folder!", "Warning", MB_OK | MB_ICONWARNING );
-        }
-      }
-      return TRUE;
-
-    case IDC_BrowseForEGTB:
-      if( BrowseForFolder( "Choose EGTB Directory:", buf ) ) {
-        SetDlgItemText( hDlg, IDC_PathToEGTB, buf );
-      }
-      return TRUE;
-
-    case IDC_HashSize:
-    case IDC_SizeOfEGTB:
-        if( HIWORD(wParam) == EN_CHANGE ) {
-            int n1_ok;
-            int n2_ok;
-
-            GetDlgItemInt(hDlg, IDC_HashSize, &n1_ok, FALSE );
-            GetDlgItemInt(hDlg, IDC_SizeOfEGTB, &n2_ok, FALSE );
-
-            EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok ? TRUE : FALSE );
-        }
-        return TRUE;
-    }
-    break;
-  }
-  return FALSE;
-}
-
-VOID UciOptionsPopup(HWND hwnd)
-{
-  FARPROC lpProc;
-
-  lpProc = MakeProcInstance((FARPROC)UciOptionsDialog, hInst);
-  DialogBox(hInst, MAKEINTRESOURCE(DLG_OptionsUCI), hwnd, (DLGPROC) lpProc);
-  FreeProcInstance(lpProc);
-}
+/*---------------------------------------------------------------------------*\\r
+ *\r
+ * Engine Options Dialog functions\r
+ *\r
+\*---------------------------------------------------------------------------*/\r
+#define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))\r
+#define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))\r
+\r
+#define INT_ABS( n )    ((n) >= 0 ? (n) : -(n))\r
+\r
+LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
+{\r
+  switch (message) {\r
+  case WM_INITDIALOG: /* message: initialize dialog box */\r
+\r
+    /* Center the dialog over the application window */\r
+    CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+\r
+    /* Initialize the dialog items */\r
+    CHECK_BOX(IDC_EpPeriodicUpdates, appData.periodicUpdates);\r
+    CHECK_BOX(IDC_EpPonder, appData.ponderNextMove);\r
+    CHECK_BOX(IDC_EpShowThinking, appData.showThinking);\r
+    CHECK_BOX(IDC_EpHideThinkingHuman, appData.hideThinkingFromHuman);\r
+\r
+    CHECK_BOX(IDC_TestClaims, appData.testClaims);\r
+    CHECK_BOX(IDC_DetectMates, appData.checkMates);\r
+    CHECK_BOX(IDC_MaterialDraws, appData.materialDraws);\r
+    CHECK_BOX(IDC_TrivialDraws, appData.trivialDraws);\r
+\r
+    SetDlgItemInt( hDlg, IDC_EpDrawMoveCount, appData.adjudicateDrawMoves, TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_EpDrawMoveCount, EM_SETSEL, 0, -1 );\r
+\r
+    SetDlgItemInt( hDlg, IDC_EpAdjudicationThreshold, INT_ABS(appData.adjudicateLossThreshold), TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_EpAdjudicationThreshold, EM_SETSEL, 0, -1 );\r
+\r
+    SetDlgItemInt( hDlg, IDC_RuleMoves, appData.ruleMoves, TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_RuleMoves, EM_SETSEL, 0, -1 );\r
+\r
+    SetDlgItemInt( hDlg, IDC_DrawRepeats, INT_ABS(appData.drawRepeats), TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_DrawRepeats, EM_SETSEL, 0, -1 );\r
+\r
+    return TRUE;\r
+\r
+  case WM_COMMAND: /* message: received a command */\r
+    switch (LOWORD(wParam)) {\r
+    case IDOK:\r
+      /* Read changed options from the dialog box */\r
+      PeriodicUpdatesEvent(          IS_CHECKED(IDC_EpPeriodicUpdates));\r
+      PonderNextMoveEvent(           IS_CHECKED(IDC_EpPonder));\r
+      ShowThinkingEvent(             IS_CHECKED(IDC_EpShowThinking));\r
+      appData.hideThinkingFromHuman= IS_CHECKED(IDC_EpHideThinkingHuman);\r
+      appData.testClaims    = IS_CHECKED(IDC_TestClaims);\r
+      appData.checkMates    = IS_CHECKED(IDC_DetectMates);\r
+      appData.materialDraws = IS_CHECKED(IDC_MaterialDraws);\r
+      appData.trivialDraws  = IS_CHECKED(IDC_TrivialDraws);\r
+\r
+      appData.adjudicateDrawMoves = GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, NULL, FALSE );\r
+      appData.adjudicateLossThreshold = - (int) GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, NULL, FALSE );\r
+      appData.ruleMoves = GetDlgItemInt(hDlg, IDC_RuleMoves, NULL, FALSE );\r
+      appData.drawRepeats = (int) GetDlgItemInt(hDlg, IDC_DrawRepeats, NULL, FALSE );\r
+\r
+      EndDialog(hDlg, TRUE);\r
+      return TRUE;\r
+\r
+    case IDCANCEL:\r
+      EndDialog(hDlg, FALSE);\r
+      return TRUE;\r
+\r
+    case IDC_EpDrawMoveCount:\r
+    case IDC_EpAdjudicationThreshold:\r
+    case IDC_DrawRepeats:\r
+    case IDC_RuleMoves:\r
+        if( HIWORD(wParam) == EN_CHANGE ) {\r
+            int n1_ok;\r
+            int n2_ok;\r
+            int n3_ok;\r
+            int n4_ok;\r
+\r
+            GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, &n1_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, &n2_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_RuleMoves, &n3_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_DrawRepeats, &n4_ok, FALSE );\r
+\r
+            EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok && n4_ok ? TRUE : FALSE );\r
+        }\r
+        return TRUE;\r
+    }\r
+    break;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+VOID EnginePlayOptionsPopup(HWND hwnd)\r
+{\r
+  FARPROC lpProc;\r
+\r
+  lpProc = MakeProcInstance((FARPROC)EnginePlayOptionsDialog, hInst);\r
+  DialogBox(hInst, MAKEINTRESOURCE(DLG_EnginePlayOptions), hwnd, (DLGPROC) lpProc);\r
+  FreeProcInstance(lpProc);\r
+}\r
+\r
+/*---------------------------------------------------------------------------*\\r
+ *\r
+ * UCI Options Dialog functions\r
+ *\r
+\*---------------------------------------------------------------------------*/\r
+static BOOL BrowseForFolder( const char * title, char * path )\r
+{\r
+    BOOL result = FALSE;\r
+    BROWSEINFO bi;\r
+    LPITEMIDLIST pidl;\r
+\r
+    ZeroMemory( &bi, sizeof(bi) );\r
+\r
+    bi.lpszTitle = title == 0 ? "Choose Folder" : title;\r
+    bi.ulFlags = BIF_RETURNONLYFSDIRS;\r
+\r
+    pidl = SHBrowseForFolder( &bi );\r
+\r
+    if( pidl != 0 ) {\r
+        IMalloc * imalloc = 0;\r
+\r
+        if( SHGetPathFromIDList( pidl, path ) ) {\r
+            result = TRUE;\r
+        }\r
+\r
+        if( SUCCEEDED( SHGetMalloc ( &imalloc ) ) ) {\r
+            imalloc->lpVtbl->Free(imalloc,pidl);\r
+            imalloc->lpVtbl->Release(imalloc);\r
+        }\r
+    }\r
+\r
+    return result;\r
+}\r
+\r
+LRESULT CALLBACK UciOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
+{\r
+  char buf[MAX_PATH];\r
+\r
+  switch (message) {\r
+  case WM_INITDIALOG: /* message: initialize dialog box */\r
+\r
+    /* Center the dialog over the application window */\r
+    CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+\r
+    /* Initialize the dialog items */\r
+    SetDlgItemText( hDlg, IDC_PolyglotDir, appData.polyglotDir );\r
+    SetDlgItemInt( hDlg, IDC_HashSize, appData.defaultHashSize, TRUE );\r
+    SetDlgItemText( hDlg, IDC_PathToEGTB, appData.defaultPathEGTB );\r
+    SetDlgItemInt( hDlg, IDC_SizeOfEGTB, appData.defaultCacheSizeEGTB, TRUE );\r
+    CheckDlgButton( hDlg, IDC_UseBook, (BOOL) appData.usePolyglotBook );\r
+    SetDlgItemText( hDlg, IDC_BookFile, appData.polyglotBook );\r
+\r
+    SendDlgItemMessage( hDlg, IDC_PolyglotDir, EM_SETSEL, 0, -1 );\r
+\r
+    return TRUE;\r
+\r
+  case WM_COMMAND: /* message: received a command */\r
+    switch (LOWORD(wParam)) {\r
+    case IDOK:\r
+      GetDlgItemText( hDlg, IDC_PolyglotDir, buf, sizeof(buf) );\r
+      appData.polyglotDir = strdup(buf);\r
+      appData.defaultHashSize = GetDlgItemInt(hDlg, IDC_HashSize, NULL, FALSE );\r
+      appData.defaultCacheSizeEGTB = GetDlgItemInt(hDlg, IDC_SizeOfEGTB, NULL, FALSE );\r
+      GetDlgItemText( hDlg, IDC_PathToEGTB, buf, sizeof(buf) );\r
+      appData.defaultPathEGTB = strdup(buf);\r
+      GetDlgItemText( hDlg, IDC_BookFile, buf, sizeof(buf) );\r
+      appData.polyglotBook = strdup(buf);\r
+      appData.usePolyglotBook = (Boolean) IsDlgButtonChecked( hDlg, IDC_UseBook );\r
+\r
+      EndDialog(hDlg, TRUE);\r
+      return TRUE;\r
+\r
+    case IDCANCEL:\r
+      EndDialog(hDlg, FALSE);\r
+      return TRUE;\r
+\r
+    case IDC_BrowseForBook:\r
+      {\r
+          char filter[] = { \r
+              'A','l','l',' ','F','i','l','e','s', 0,\r
+              '*','.','*', 0,\r
+              'B','I','N',' ','F','i','l','e','s', 0,\r
+              '*','.','b','i','n', 0,\r
+              0 };\r
+\r
+          OPENFILENAME ofn;\r
+\r
+          strcpy( buf, "" );\r
+\r
+          ZeroMemory( &ofn, sizeof(ofn) );\r
+\r
+          ofn.lStructSize = sizeof(ofn);\r
+          ofn.hwndOwner = hDlg;\r
+          ofn.hInstance = hInst;\r
+          ofn.lpstrFilter = filter;\r
+          ofn.lpstrFile = buf;\r
+          ofn.nMaxFile = sizeof(buf);\r
+          ofn.lpstrTitle = "Choose Book";\r
+          ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;\r
+\r
+          if( GetOpenFileName( &ofn ) ) {\r
+              SetDlgItemText( hDlg, IDC_BookFile, buf );\r
+          }\r
+      }\r
+      return TRUE;\r
+\r
+    case IDC_BrowseForPolyglotDir:\r
+      if( BrowseForFolder( "Choose Polyglot Directory", buf ) ) {\r
+        SetDlgItemText( hDlg, IDC_PolyglotDir, buf );\r
+\r
+        strcat( buf, "\\polyglot.exe" );\r
+\r
+        if( GetFileAttributes(buf) == 0xFFFFFFFF ) {\r
+            MessageBox( hDlg, "Polyglot was not found in the specified folder!", "Warning", MB_OK | MB_ICONWARNING );\r
+        }\r
+      }\r
+      return TRUE;\r
+\r
+    case IDC_BrowseForEGTB:\r
+      if( BrowseForFolder( "Choose EGTB Directory:", buf ) ) {\r
+        SetDlgItemText( hDlg, IDC_PathToEGTB, buf );\r
+      }\r
+      return TRUE;\r
+\r
+    case IDC_HashSize:\r
+    case IDC_SizeOfEGTB:\r
+        if( HIWORD(wParam) == EN_CHANGE ) {\r
+            int n1_ok;\r
+            int n2_ok;\r
+\r
+            GetDlgItemInt(hDlg, IDC_HashSize, &n1_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_SizeOfEGTB, &n2_ok, FALSE );\r
+\r
+            EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok ? TRUE : FALSE );\r
+        }\r
+        return TRUE;\r
+    }\r
+    break;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+VOID UciOptionsPopup(HWND hwnd)\r
+{\r
+  FARPROC lpProc;\r
+\r
+  lpProc = MakeProcInstance((FARPROC)UciOptionsDialog, hInst);\r
+  DialogBox(hInst, MAKEINTRESOURCE(DLG_OptionsUCI), hwnd, (DLGPROC) lpProc);\r
+  FreeProcInstance(lpProc);\r
+}\r