changes from Alessandro Scotti from 20060112
[xboard.git] / winboard / woptions.c
index d568cee..16e9313 100644 (file)
@@ -26,6 +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 */
 \r
 #include "common.h"\r
 #include "winboard.h"\r
@@ -169,6 +170,8 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     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);
 \r
 #undef CHECK_BOX\r
 \r
@@ -212,6 +215,8 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       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);
 \r
 #undef IS_CHECKED\r
 \r
@@ -2237,6 +2242,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 );
     SetSaveOptionEnables(hDlg);\r
     return TRUE;\r
 \r
@@ -2276,6 +2282,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 );
       EndDialog(hDlg, TRUE);\r
       return TRUE;\r
 \r
@@ -2433,4 +2440,231 @@ TimeControlOptionsPopup(HWND hwnd)
   }\r
 }\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);
+}