X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwoptions.c;h=1d921292540030b11ae839fd2c094f29a8142877;hb=7e4f4f5718bf4efee8be4abfc981d18cfd6f8438;hp=a740f8f13ed95c3a17d4093ebb043a4c95f3dfbf;hpb=056614196635a4730170261fe0e638191f14c620;p=xboard.git diff --git a/winboard/woptions.c b/winboard/woptions.c index a740f8f..1d92129 100644 --- a/winboard/woptions.c +++ b/winboard/woptions.c @@ -1,6 +1,6 @@ /* * woptions.c -- Options dialog box routines for WinBoard - * $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 $ * * Copyright 2000 Free Software Foundation, Inc. * @@ -26,7 +26,7 @@ #include /* required for all Windows applications */ #include #include -#include /* [AS] Requires NT 4.0 or Win95 */ +#include /* [AS] Requires NT 4.0 or Win95 */ #include "common.h" #include "winboard.h" @@ -60,7 +60,7 @@ extern ColorClass currentColorClass; extern HWND hwndConsole; extern char *defaultTextAttribs[]; extern HWND commentDialog; -extern HWND moveHistoryDialog; +extern HWND moveHistoryDialog; extern char installDir[]; extern HWND hCommPort; /* currently open comm port */ extern DCB dcb; @@ -82,6 +82,7 @@ typedef struct { LRESULT CALLBACK GeneralOptions(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK BoardOptions(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK NewVariant(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK IcsOptions(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK FontOptions(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK CommPortOptions(HWND, UINT, WPARAM, LPARAM); @@ -169,10 +170,10 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) CHECK_BOX(OPT_ShowCoordinates, appData.showCoords); CHECK_BOX(OPT_ShowThinking, appData.showThinking); CHECK_BOX(OPT_TestLegality, appData.testLegality); - 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); + CHECK_BOX(OPT_SaveExtPGN, appData.saveExtendedInfoInPGN); + CHECK_BOX(OPT_ExtraInfoInMoveHistory, appData.showEvalInMoveHistory); + CHECK_BOX(OPT_HighlightMoveArrow, appData.highlightMoveWithArrow); #undef CHECK_BOX @@ -214,10 +215,10 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) appData.showCoords = IS_CHECKED(OPT_ShowCoordinates); ShowThinkingEvent( IS_CHECKED(OPT_ShowThinking)); appData.testLegality = IS_CHECKED(OPT_TestLegality); - 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); + appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN); + appData.showEvalInMoveHistory= IS_CHECKED(OPT_ExtraInfoInMoveHistory); + appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow); #undef IS_CHECKED @@ -728,6 +729,161 @@ BoardOptionsPopup(HWND hwnd) FreeProcInstance(lpProc); } +VariantClass +VariantWhichRadio(HWND hDlg) +{ + return (IsDlgButtonChecked(hDlg, OPT_VariantFairy) ? VariantFairy : + (IsDlgButtonChecked(hDlg, OPT_VariantGothic) ? VariantGothic : + (IsDlgButtonChecked(hDlg, OPT_VariantCrazyhouse) ? VariantCrazyhouse : + (IsDlgButtonChecked(hDlg, OPT_VariantBughouse) ? VariantBughouse : + (IsDlgButtonChecked(hDlg, OPT_VariantCourier) ? VariantCourier : + (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj : + (IsDlgButtonChecked(hDlg, OPT_VariantShogi) ? VariantShogi : + (IsDlgButtonChecked(hDlg, OPT_VariantXiangqi) ? VariantXiangqi : + (IsDlgButtonChecked(hDlg, OPT_VariantCapablanca) ? VariantCapablanca : + (IsDlgButtonChecked(hDlg, OPT_VariantTwoKings) ? VariantTwoKings : + (IsDlgButtonChecked(hDlg, OPT_VariantKnightmate) ? VariantKnightmate : + (IsDlgButtonChecked(hDlg, OPT_VariantLosers) ? VariantLosers : + (IsDlgButtonChecked(hDlg, OPT_VariantSuicide) ? VariantSuicide : + (IsDlgButtonChecked(hDlg, OPT_VariantAtomic) ? VariantAtomic : + (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj : + VariantNormal ))))))))))))))); +} + +LRESULT CALLBACK +NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + static Boolean mono; + static VariantClass v; + static COLORREF lsc, dsc, wpc, bpc, hsc, phc; + static HBITMAP pieces[3]; + static int n1_ok, n2_ok, n3_ok; + + 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 */ + switch (gameInfo.variant) { + case VariantNormal: + CheckDlgButton(hDlg, OPT_VariantNormal, TRUE); + break; + case VariantCrazyhouse: + CheckDlgButton(hDlg, OPT_VariantCrazyhouse, TRUE); + break; + case VariantBughouse: + CheckDlgButton(hDlg, OPT_VariantBughouse, TRUE); + break; + case VariantShogi: + CheckDlgButton(hDlg, OPT_VariantShogi, TRUE); + break; + case VariantXiangqi: + CheckDlgButton(hDlg, OPT_VariantXiangqi, TRUE); + break; + case VariantCapablanca: + CheckDlgButton(hDlg, OPT_VariantCapablanca, TRUE); + break; + case VariantGothic: + CheckDlgButton(hDlg, OPT_VariantGothic, TRUE); + break; + case VariantCourier: + CheckDlgButton(hDlg, OPT_VariantCourier, TRUE); + break; + case VariantKnightmate: + CheckDlgButton(hDlg, OPT_VariantKnightmate, TRUE); + break; + case VariantTwoKings: + CheckDlgButton(hDlg, OPT_VariantTwoKings, TRUE); + break; + case VariantFairy: + CheckDlgButton(hDlg, OPT_VariantFairy, TRUE); + break; + case VariantAtomic: + CheckDlgButton(hDlg, OPT_VariantAtomic, TRUE); + break; + case VariantSuicide: + CheckDlgButton(hDlg, OPT_VariantSuicide, TRUE); + break; + case VariantLosers: + CheckDlgButton(hDlg, OPT_VariantLosers, TRUE); + break; + case VariantShatranj: + CheckDlgButton(hDlg, OPT_VariantShatranj, TRUE); + break; + } + + SetDlgItemInt( hDlg, IDC_Files, -1, TRUE ); + SendDlgItemMessage( hDlg, IDC_Files, EM_SETSEL, 0, -1 ); + + SetDlgItemInt( hDlg, IDC_Ranks, -1, TRUE ); + SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 ); + + SetDlgItemInt( hDlg, IDC_Holdings, -1, TRUE ); + SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 ); + + n1_ok = n2_ok = n3_ok = FALSE; + + return TRUE; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + case IDOK: + /* + * if we call EndDialog() after the call to ChangeBoardSize(), + * then ChangeBoardSize() does not take effect, although the new + * boardSize is saved. Go figure... + */ + EndDialog(hDlg, TRUE); + + v = VariantWhichRadio(hDlg); + + gameInfo.variant = v; + appData.variant = VariantName(v); + + appData.NrFiles = (int) GetDlgItemInt(hDlg, IDC_Files, NULL, FALSE ); + appData.NrRanks = (int) GetDlgItemInt(hDlg, IDC_Ranks, NULL, FALSE ); + appData.holdingsSize = (int) GetDlgItemInt(hDlg, IDC_Holdings, NULL, FALSE ); + + if(!n1_ok) appData.NrFiles = -1; + if(!n2_ok) appData.NrRanks = -1; + if(!n3_ok) appData.holdingsSize = -1; + + Reset(TRUE, TRUE); + + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + case IDC_Ranks: + case IDC_Files: + case IDC_Holdings: + if( HIWORD(wParam) == EN_CHANGE ) { + + GetDlgItemInt(hDlg, IDC_Files, &n1_ok, FALSE ); + GetDlgItemInt(hDlg, IDC_Ranks, &n2_ok, FALSE ); + GetDlgItemInt(hDlg, IDC_Holdings, &n3_ok, FALSE ); + + /*EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok ? TRUE : FALSE );*/ + } + return TRUE; + } + break; + } + return FALSE; +} + + +VOID +NewVariantPopup(HWND hwnd) +{ + FARPROC lpProc = MakeProcInstance((FARPROC)NewVariantDialog, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_NewVariant), hwnd, + (DLGPROC) lpProc); + FreeProcInstance(lpProc); +} + /*---------------------------------------------------------------------------*\ * * ICS Options Dialog functions @@ -1321,7 +1477,7 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]); SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]); SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]); - SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]); + SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]); firstPaint = FALSE; } break; @@ -1349,7 +1505,7 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) CopyFont(font[i][EDITTAGS_FONT], &workFont[EDITTAGS_FONT]); CopyFont(font[i][CONSOLE_FONT], &workFont[CONSOLE_FONT]); CopyFont(font[i][COMMENT_FONT], &workFont[COMMENT_FONT]); - CopyFont(font[i][MOVEHISTORY_FONT], &workFont[MOVEHISTORY_FONT]); + CopyFont(font[i][MOVEHISTORY_FONT], &workFont[MOVEHISTORY_FONT]); } /* end sad necessity */ @@ -1372,13 +1528,13 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) InvalidateRect(editTagsDialog, &rect, TRUE); } - 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 ) { + SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory, + WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, + MAKELPARAM(TRUE, 0)); + InvalidateRect(editTagsDialog, NULL, TRUE); + } + if (hwndConsole) { ChangedConsoleFont(); } @@ -1424,11 +1580,11 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]); break; - case OPT_ChooseMoveHistoryFont: - MyCreateFont(hDlg, &workFont[MOVEHISTORY_FONT]); - SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]); - break; - + case OPT_ChooseMoveHistoryFont: + MyCreateFont(hDlg, &workFont[MOVEHISTORY_FONT]); + SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]); + break; + case OPT_DefaultFonts: for (i=0; i= 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; - - 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); -} +/*---------------------------------------------------------------------------*\ + * + * 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); + + CHECK_BOX(IDC_TestClaims, appData.testClaims); + CHECK_BOX(IDC_DetectMates, appData.checkMates); + CHECK_BOX(IDC_MaterialDraws, appData.materialDraws); + CHECK_BOX(IDC_TrivialDraws, appData.trivialDraws); + + 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 ); + + SetDlgItemInt( hDlg, IDC_RuleMoves, appData.ruleMoves, TRUE ); + SendDlgItemMessage( hDlg, IDC_RuleMoves, EM_SETSEL, 0, -1 ); + + SetDlgItemInt( hDlg, IDC_DrawRepeats, INT_ABS(appData.drawRepeats), TRUE ); + SendDlgItemMessage( hDlg, IDC_DrawRepeats, 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.testClaims = IS_CHECKED(IDC_TestClaims); + appData.checkMates = IS_CHECKED(IDC_DetectMates); + appData.materialDraws = IS_CHECKED(IDC_MaterialDraws); + appData.trivialDraws = IS_CHECKED(IDC_TrivialDraws); + + appData.adjudicateDrawMoves = GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, NULL, FALSE ); + appData.adjudicateLossThreshold = - (int) GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, NULL, FALSE ); + appData.ruleMoves = GetDlgItemInt(hDlg, IDC_RuleMoves, NULL, FALSE ); + appData.drawRepeats = (int) GetDlgItemInt(hDlg, IDC_DrawRepeats, NULL, FALSE ); + + EndDialog(hDlg, TRUE); + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + case IDC_EpDrawMoveCount: + case IDC_EpAdjudicationThreshold: + case IDC_DrawRepeats: + case IDC_RuleMoves: + if( HIWORD(wParam) == EN_CHANGE ) { + int n1_ok; + int n2_ok; + int n3_ok; + int n4_ok; + + GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, &n1_ok, FALSE ); + GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, &n2_ok, FALSE ); + GetDlgItemInt(hDlg, IDC_RuleMoves, &n3_ok, FALSE ); + GetDlgItemInt(hDlg, IDC_DrawRepeats, &n4_ok, FALSE ); + + EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok && n4_ok ? TRUE : FALSE ); + } + return TRUE; + } + break; + } + return FALSE; +} + +VOID EnginePlayOptionsPopup(HWND hwnd) +{ + FARPROC lpProc; + + 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); +}