2 * woptions.c -- Options dialog box routines for WinBoard
4 * Copyright 2000,2009 Free Software Foundation, Inc.
6 * Enhancements Copyright 2005 Alessandro Scotti
8 * ------------------------------------------------------------------------
10 * GNU XBoard is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or (at
13 * your option) any later version.
15 * GNU XBoard is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see http://www.gnu.org/licenses/. *
23 *------------------------------------------------------------------------
24 ** See the file ChangeLog for a revision history. */
28 #include <windows.h> /* required for all Windows applications */
31 #include <shlobj.h> /* [AS] Requires NT 4.0 or Win95 */
39 #include "wedittags.h"
47 /* Imports from winboard.c */
49 extern MyFont *font[NUM_SIZES][NUM_FONTS];
50 extern HINSTANCE hInst; /* current instance */
51 extern HWND hwndMain; /* root window*/
52 extern BOOLEAN alwaysOnTop;
53 extern RECT boardRect;
54 extern COLORREF lightSquareColor, darkSquareColor, whitePieceColor,
55 blackPieceColor, highlightSquareColor, premoveHighlightColor;
57 extern BoardSize boardSize;
58 extern COLORREF consoleBackgroundColor;
59 extern MyColorizeAttribs colorizeAttribs[]; /* do I need the size? */
60 extern MyTextAttribs textAttribs[];
61 extern MySound sounds[];
62 extern ColorClass currentColorClass;
63 extern HWND hwndConsole;
64 extern char *defaultTextAttribs[];
65 extern HWND commentDialog;
66 extern HWND moveHistoryDialog;
67 extern HWND engineOutputDialog;
68 extern char installDir[];
69 extern HWND hCommPort; /* currently open comm port */
71 extern BOOLEAN chessProgram;
72 extern int startedFromPositionFile; /* [HGM] loadPos */
86 /* module prototypes */
88 LRESULT CALLBACK GeneralOptions(HWND, UINT, WPARAM, LPARAM);
89 LRESULT CALLBACK BoardOptions(HWND, UINT, WPARAM, LPARAM);
90 LRESULT CALLBACK NewVariant(HWND, UINT, WPARAM, LPARAM);
91 LRESULT CALLBACK IcsOptions(HWND, UINT, WPARAM, LPARAM);
92 LRESULT CALLBACK FontOptions(HWND, UINT, WPARAM, LPARAM);
93 LRESULT CALLBACK CommPortOptions(HWND, UINT, WPARAM, LPARAM);
94 LRESULT CALLBACK LoadOptions(HWND, UINT, WPARAM, LPARAM);
95 LRESULT CALLBACK SaveOptions(HWND, UINT, WPARAM, LPARAM);
96 LRESULT CALLBACK TimeControl(HWND, UINT, WPARAM, LPARAM);
97 VOID ChangeBoardSize(BoardSize newSize);
98 VOID PaintSampleSquare(
101 COLORREF squareColor,
103 COLORREF squareOutlineColor,
104 COLORREF pieceDetailColor,
109 VOID PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color);
110 VOID SetBoardOptionEnables(HWND hDlg);
111 BoardSize BoardOptionsWhichRadio(HWND hDlg);
112 BOOL APIENTRY MyCreateFont(HWND hwnd, MyFont *font);
113 VOID UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca);
114 LRESULT CALLBACK ColorizeTextDialog(HWND , UINT, WPARAM, LPARAM);
115 VOID ColorizeTextPopup(HWND hwnd, ColorClass cc);
116 VOID SetIcsOptionEnables(HWND hDlg);
117 VOID SetSampleFontText(HWND hwnd, int id, const MyFont *mf);
118 VOID CopyFont(MyFont *dest, const MyFont *src);
119 void InitSoundComboData(SoundComboData *scd);
120 void ResetSoundComboData(SoundComboData *scd);
121 void InitSoundCombo(HWND hwndCombo, SoundComboData *scd);
122 int SoundDialogWhichRadio(HWND hDlg);
123 VOID SoundDialogSetEnables(HWND hDlg, int radio);
124 char * SoundDialogGetName(HWND hDlg, int radio);
125 void DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name);
126 VOID ParseCommSettings(char *arg, DCB *dcb);
127 VOID PrintCommSettings(FILE *f, char *name, DCB *dcb);
128 void InitCombo(HANDLE hwndCombo, ComboData *cd);
129 void SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value);
130 VOID SetLoadOptionEnables(HWND hDlg);
131 VOID SetSaveOptionEnables(HWND hDlg);
132 VOID SetTimeControlEnables(HWND hDlg);
133 void NewSettingEvent(int option, char *command, int value);
135 /*---------------------------------------------------------------------------*\
137 * General Options Dialog functions
139 \*---------------------------------------------------------------------------*/
143 GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
145 static Boolean oldShowCoords;
146 static Boolean oldBlindfold;
147 static Boolean oldShowButtonBar;
150 case WM_INITDIALOG: /* message: initialize dialog box */
151 oldShowCoords = appData.showCoords;
152 oldBlindfold = appData.blindfold;
153 oldShowButtonBar = appData.showButtonBar;
155 /* Center the dialog over the application window */
156 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
158 /* Initialize the dialog items */
159 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
161 CHECK_BOX(OPT_AlwaysOnTop, alwaysOnTop);
162 CHECK_BOX(OPT_AlwaysQueen, appData.alwaysPromoteToQueen);
163 CHECK_BOX(OPT_AnimateDragging, appData.animateDragging);
164 CHECK_BOX(OPT_AnimateMoving, appData.animate);
165 CHECK_BOX(OPT_AutoFlag, appData.autoCallFlag);
166 CHECK_BOX(OPT_AutoFlipView, appData.autoFlipView);
167 CHECK_BOX(OPT_AutoRaiseBoard, appData.autoRaiseBoard);
168 CHECK_BOX(OPT_Blindfold, appData.blindfold);
169 CHECK_BOX(OPT_HighlightDragging, appData.highlightDragging);
170 CHECK_BOX(OPT_HighlightLastMove, appData.highlightLastMove);
171 CHECK_BOX(OPT_PeriodicUpdates, appData.periodicUpdates);
172 CHECK_BOX(OPT_PonderNextMove, appData.ponderNextMove);
173 CHECK_BOX(OPT_PopupExitMessage, appData.popupExitMessage);
174 CHECK_BOX(OPT_PopupMoveErrors, appData.popupMoveErrors);
175 CHECK_BOX(OPT_ShowButtonBar, appData.showButtonBar);
176 CHECK_BOX(OPT_ShowCoordinates, appData.showCoords);
177 CHECK_BOX(OPT_ShowThinking, appData.showThinking);
178 CHECK_BOX(OPT_TestLegality, appData.testLegality);
179 CHECK_BOX(OPT_HideThinkFromHuman, appData.hideThinkingFromHuman);
180 CHECK_BOX(OPT_SaveExtPGN, appData.saveExtendedInfoInPGN);
181 CHECK_BOX(OPT_ExtraInfoInMoveHistory, appData.showEvalInMoveHistory);
182 CHECK_BOX(OPT_HighlightMoveArrow, appData.highlightMoveWithArrow);
186 EnableWindow(GetDlgItem(hDlg, OPT_AutoFlag),
187 appData.icsActive || !appData.noChessProgram);
188 EnableWindow(GetDlgItem(hDlg, OPT_AutoFlipView),
189 appData.icsActive || !appData.noChessProgram);
190 EnableWindow(GetDlgItem(hDlg, OPT_PonderNextMove),
191 !appData.noChessProgram);
192 EnableWindow(GetDlgItem(hDlg, OPT_PeriodicUpdates),
193 !appData.noChessProgram && !appData.icsActive);
194 EnableWindow(GetDlgItem(hDlg, OPT_ShowThinking),
195 !appData.noChessProgram);
199 case WM_COMMAND: /* message: received a command */
200 switch (LOWORD(wParam)) {
202 /* Read changed options from the dialog box */
204 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
206 alwaysOnTop = IS_CHECKED(OPT_AlwaysOnTop);
207 appData.alwaysPromoteToQueen = IS_CHECKED(OPT_AlwaysQueen);
208 appData.animateDragging = IS_CHECKED(OPT_AnimateDragging);
209 appData.animate = IS_CHECKED(OPT_AnimateMoving);
210 appData.autoCallFlag = IS_CHECKED(OPT_AutoFlag);
211 appData.autoFlipView = IS_CHECKED(OPT_AutoFlipView);
212 appData.autoRaiseBoard = IS_CHECKED(OPT_AutoRaiseBoard);
213 appData.blindfold = IS_CHECKED(OPT_Blindfold);
214 appData.highlightDragging = IS_CHECKED(OPT_HighlightDragging);
215 appData.highlightLastMove = IS_CHECKED(OPT_HighlightLastMove);
216 PeriodicUpdatesEvent( IS_CHECKED(OPT_PeriodicUpdates));
217 PonderNextMoveEvent( IS_CHECKED(OPT_PonderNextMove));
218 appData.popupExitMessage = IS_CHECKED(OPT_PopupExitMessage);
219 appData.popupMoveErrors = IS_CHECKED(OPT_PopupMoveErrors);
220 appData.showButtonBar = IS_CHECKED(OPT_ShowButtonBar);
221 appData.showCoords = IS_CHECKED(OPT_ShowCoordinates);
222 // [HGM] thinking: next three moved up
223 appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN);
224 appData.hideThinkingFromHuman= IS_CHECKED(OPT_HideThinkFromHuman);
225 appData.showEvalInMoveHistory= IS_CHECKED(OPT_ExtraInfoInMoveHistory);
226 appData.showThinking = IS_CHECKED(OPT_ShowThinking);
227 ShowThinkingEvent(); // [HGM] thinking: tests four options
228 appData.testLegality = IS_CHECKED(OPT_TestLegality);
229 appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow);
233 SetWindowPos(hwndMain, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
234 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
237 SetWindowPos(hwndConsole, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
238 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
241 if (!appData.highlightLastMove) {
243 DrawPosition(FALSE, NULL);
246 * for some reason the redraw seems smoother when we invalidate
247 * the board rect after the call to EndDialog()
249 EndDialog(hDlg, TRUE);
251 if (oldShowButtonBar != appData.showButtonBar) {
252 InitDrawingSizes(boardSize, 0);
253 } else if ((oldShowCoords != appData.showCoords) ||
254 (oldBlindfold != appData.blindfold)) {
255 InvalidateRect(hwndMain, &boardRect, FALSE);
261 EndDialog(hDlg, FALSE);
271 GeneralOptionsPopup(HWND hwnd)
275 lpProc = MakeProcInstance((FARPROC)GeneralOptionsDialog, hInst);
276 DialogBox(hInst, MAKEINTRESOURCE(DLG_GeneralOptions), hwnd,
278 FreeProcInstance(lpProc);
280 /*---------------------------------------------------------------------------*\
282 * Board Options Dialog functions
284 \*---------------------------------------------------------------------------*/
286 const int SAMPLE_SQ_SIZE = 54;
289 ChangeBoardSize(BoardSize newSize)
291 if (newSize != boardSize) {
293 InitDrawingSizes(boardSize, 0);
301 COLORREF squareColor,
303 COLORREF squareOutlineColor,
304 COLORREF pieceDetailColor,
311 HBRUSH brushSquareOutline;
313 HBRUSH brushPieceDetail;
314 HBRUSH oldBrushPiece = NULL;
315 HBRUSH oldBrushSquare;
316 HBITMAP oldBitmapMem;
317 HBITMAP oldBitmapTemp;
318 HBITMAP bufferBitmap;
320 HDC hdcScreen, hdcMem, hdcTemp;
322 HWND hCtrl = GetDlgItem(hwnd, ctrlid);
327 const int OUTLINE = 2;
328 const int BORDER = 4;
330 InvalidateRect(hCtrl, NULL, TRUE);
332 GetClientRect(hCtrl, &rect);
333 x = rect.left + (BORDER / 2);
334 y = rect.top + (BORDER / 2);
335 hdcScreen = GetDC(hCtrl);
336 hdcMem = CreateCompatibleDC(hdcScreen);
337 hdcTemp = CreateCompatibleDC(hdcScreen);
339 bufferBitmap = CreateCompatibleBitmap(hdcScreen, rect.right-rect.left+1,
340 rect.bottom-rect.top+1);
341 oldBitmapMem = SelectObject(hdcMem, bufferBitmap);
343 SelectPalette(hdcMem, hPal, FALSE);
345 brushSquare = CreateSolidBrush(squareColor);
346 brushSquareOutline = CreateSolidBrush(squareOutlineColor);
347 brushPiece = CreateSolidBrush(pieceColor);
348 brushPieceDetail = CreateSolidBrush(pieceDetailColor);
351 * first draw the rectangle
353 pen = CreatePen(PS_SOLID, BORDER, squareOutlineColor);
354 oldPen = (HPEN) SelectObject(hdcMem, pen);
355 oldBrushSquare = (HBRUSH)SelectObject(hdcMem, brushSquare);
356 Rectangle(hdcMem, rect.left, rect.top, rect.right, rect.bottom);
362 oldBitmapTemp = SelectObject(hdcTemp, pieces[OUTLINE]);
363 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, hdcTemp, 0, 0,
364 isWhitePiece ? SRCCOPY : NOTSRCCOPY);
365 SelectObject(hdcTemp, oldBitmapTemp);
368 oldBitmapTemp = SelectObject(hdcTemp, pieces[WHITE]);
369 oldBrushPiece = SelectObject(hdcMem, brushPiece);
370 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
371 hdcTemp, 0, 0, 0x00B8074A);
372 /* Use black for outline of white pieces */
373 SelectObject(hdcTemp, pieces[OUTLINE]);
374 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
375 hdcTemp, 0, 0, SRCAND);
377 /* Use square color for details of black pieces */
378 oldBitmapTemp = SelectObject(hdcTemp, pieces[SOLID]);
379 oldBrushPiece = SelectObject(hdcMem, brushPiece);
380 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
381 hdcTemp, 0, 0, 0x00B8074A);
383 SelectObject(hdcMem, oldBrushPiece);
384 SelectObject(hdcTemp, oldBitmapTemp);
387 * copy the memory dc to the screen
389 SelectObject(hdcMem, bufferBitmap);
390 BitBlt(hdcScreen, rect.left, rect.top,
391 rect.right - rect.left,
392 rect.bottom - rect.top,
393 hdcMem, rect.left, rect.top, SRCCOPY);
394 SelectObject(hdcMem, oldBitmapMem);
398 SelectObject(hdcMem, oldBrushPiece);
399 SelectObject(hdcMem, oldPen);
400 DeleteObject(brushPiece);
401 DeleteObject(brushPieceDetail);
402 DeleteObject(brushSquare);
403 DeleteObject(brushSquareOutline);
407 ReleaseDC(hCtrl, hdcScreen);
412 PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color)
415 HBRUSH brush, oldBrush;
417 HWND hCtrl = GetDlgItem(hwnd, ctrlid);
420 InvalidateRect(hCtrl, NULL, TRUE);
422 GetClientRect(hCtrl, &rect);
423 brush = CreateSolidBrush(color);
424 oldBrush = (HBRUSH)SelectObject(hdc, brush);
425 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
426 SelectObject(hdc, oldBrush);
428 ReleaseDC(hCtrl, hdc);
433 SetBoardOptionEnables(HWND hDlg)
435 if (IsDlgButtonChecked(hDlg, OPT_Monochrome)) {
436 ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_HIDE);
437 ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_HIDE);
438 ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_HIDE);
439 ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_HIDE);
441 EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), FALSE);
442 EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), FALSE);
443 EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), FALSE);
444 EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), FALSE);
446 ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_SHOW);
447 ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_SHOW);
448 ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_SHOW);
449 ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_SHOW);
451 EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), TRUE);
452 EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), TRUE);
453 EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), TRUE);
454 EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), TRUE);
459 BoardOptionsWhichRadio(HWND hDlg)
461 return (IsDlgButtonChecked(hDlg, OPT_SizeTiny) ? SizeTiny :
462 (IsDlgButtonChecked(hDlg, OPT_SizeTeeny) ? SizeTeeny :
463 (IsDlgButtonChecked(hDlg, OPT_SizeDinky) ? SizeDinky :
464 (IsDlgButtonChecked(hDlg, OPT_SizePetite) ? SizePetite :
465 (IsDlgButtonChecked(hDlg, OPT_SizeSlim) ? SizeSlim :
466 (IsDlgButtonChecked(hDlg, OPT_SizeSmall) ? SizeSmall :
467 (IsDlgButtonChecked(hDlg, OPT_SizeMediocre) ? SizeMediocre :
468 (IsDlgButtonChecked(hDlg, OPT_SizeMiddling) ? SizeMiddling :
469 (IsDlgButtonChecked(hDlg, OPT_SizeAverage) ? SizeAverage :
470 (IsDlgButtonChecked(hDlg, OPT_SizeModerate) ? SizeModerate :
471 (IsDlgButtonChecked(hDlg, OPT_SizeMedium) ? SizeMedium :
472 (IsDlgButtonChecked(hDlg, OPT_SizeBulky) ? SizeBulky :
473 (IsDlgButtonChecked(hDlg, OPT_SizeLarge) ? SizeLarge :
474 (IsDlgButtonChecked(hDlg, OPT_SizeBig) ? SizeBig :
475 (IsDlgButtonChecked(hDlg, OPT_SizeHuge) ? SizeHuge :
476 (IsDlgButtonChecked(hDlg, OPT_SizeGiant) ? SizeGiant :
477 (IsDlgButtonChecked(hDlg, OPT_SizeColossal) ? SizeColossal :
478 SizeTitanic )))))))))))))))));
482 BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
484 static Boolean mono, white, flip;
485 static BoardSize size;
486 static COLORREF lsc, dsc, wpc, bpc, hsc, phc;
487 static HBITMAP pieces[3];
490 case WM_INITDIALOG: /* message: initialize dialog box */
491 /* Center the dialog over the application window */
492 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
493 /* Initialize the dialog items */
496 CheckDlgButton(hDlg, OPT_SizeTiny, TRUE);
499 CheckDlgButton(hDlg, OPT_SizeTeeny, TRUE);
502 CheckDlgButton(hDlg, OPT_SizeDinky, TRUE);
505 CheckDlgButton(hDlg, OPT_SizePetite, TRUE);
508 CheckDlgButton(hDlg, OPT_SizeSlim, TRUE);
511 CheckDlgButton(hDlg, OPT_SizeSmall, TRUE);
514 CheckDlgButton(hDlg, OPT_SizeMediocre, TRUE);
517 CheckDlgButton(hDlg, OPT_SizeMiddling, TRUE);
520 CheckDlgButton(hDlg, OPT_SizeAverage, TRUE);
523 CheckDlgButton(hDlg, OPT_SizeModerate, TRUE);
526 CheckDlgButton(hDlg, OPT_SizeMedium, TRUE);
529 CheckDlgButton(hDlg, OPT_SizeBulky, TRUE);
532 CheckDlgButton(hDlg, OPT_SizeLarge, TRUE);
535 CheckDlgButton(hDlg, OPT_SizeBig, TRUE);
538 CheckDlgButton(hDlg, OPT_SizeHuge, TRUE);
541 CheckDlgButton(hDlg, OPT_SizeGiant, TRUE);
544 CheckDlgButton(hDlg, OPT_SizeColossal, TRUE);
547 CheckDlgButton(hDlg, OPT_SizeTitanic, TRUE);
548 default: ; // should not happen, but suppresses warning on pedantic compilers
551 if (appData.monoMode)
552 CheckDlgButton(hDlg, OPT_Monochrome, TRUE);
554 if (appData.allWhite)
555 CheckDlgButton(hDlg, OPT_AllWhite, TRUE);
557 if (appData.upsideDown)
558 CheckDlgButton(hDlg, OPT_UpsideDown, TRUE);
560 pieces[0] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "s");
561 pieces[1] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "w");
562 pieces[2] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "o");
564 lsc = lightSquareColor;
565 dsc = darkSquareColor;
566 wpc = whitePieceColor;
567 bpc = blackPieceColor;
568 hsc = highlightSquareColor;
569 phc = premoveHighlightColor;
570 mono = appData.monoMode;
571 white= appData.allWhite;
572 flip = appData.upsideDown;
575 SetBoardOptionEnables(hDlg);
579 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
580 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
581 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
582 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
583 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
584 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
585 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
587 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
588 FALSE, mono, pieces);
592 case WM_COMMAND: /* message: received a command */
593 switch (LOWORD(wParam)) {
596 * if we call EndDialog() after the call to ChangeBoardSize(),
597 * then ChangeBoardSize() does not take effect, although the new
598 * boardSize is saved. Go figure...
600 EndDialog(hDlg, TRUE);
602 size = BoardOptionsWhichRadio(hDlg);
605 * did any settings change?
607 if (size != boardSize) {
608 ChangeBoardSize(size);
611 if ((mono != appData.monoMode) ||
612 (lsc != lightSquareColor) ||
613 (dsc != darkSquareColor) ||
614 (wpc != whitePieceColor) ||
615 (bpc != blackPieceColor) ||
616 (hsc != highlightSquareColor) ||
617 (flip != appData.upsideDown) ||
618 (white != appData.allWhite) ||
619 (phc != premoveHighlightColor)) {
621 lightSquareColor = lsc;
622 darkSquareColor = dsc;
623 whitePieceColor = wpc;
624 blackPieceColor = bpc;
625 highlightSquareColor = hsc;
626 premoveHighlightColor = phc;
627 appData.monoMode = mono;
628 appData.allWhite = white;
629 appData.upsideDown = flip;
632 InitDrawingSizes(boardSize, 0);
633 InvalidateRect(hwndMain, &boardRect, FALSE);
635 DeleteObject(pieces[0]);
636 DeleteObject(pieces[1]);
637 DeleteObject(pieces[2]);
641 DeleteObject(pieces[0]);
642 DeleteObject(pieces[1]);
643 DeleteObject(pieces[2]);
644 EndDialog(hDlg, FALSE);
647 case OPT_ChooseLightSquareColor:
648 if (ChangeColor(hDlg, &lsc))
649 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
650 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
654 case OPT_ChooseDarkSquareColor:
655 if (ChangeColor(hDlg, &dsc))
656 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
657 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
658 FALSE, mono, pieces);
661 case OPT_ChooseWhitePieceColor:
662 if (ChangeColor(hDlg, &wpc))
663 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
664 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
668 case OPT_ChooseBlackPieceColor:
669 if (ChangeColor(hDlg, &bpc))
670 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
671 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
672 FALSE, mono, pieces);
675 case OPT_ChooseHighlightSquareColor:
676 if (ChangeColor(hDlg, &hsc))
677 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
678 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
682 case OPT_ChoosePremoveHighlightColor:
683 if (ChangeColor(hDlg, &phc))
684 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
685 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
686 FALSE, mono, pieces);
689 case OPT_DefaultBoardColors:
690 lsc = ParseColorName(LIGHT_SQUARE_COLOR);
691 dsc = ParseColorName(DARK_SQUARE_COLOR);
692 wpc = ParseColorName(WHITE_PIECE_COLOR);
693 bpc = ParseColorName(BLACK_PIECE_COLOR);
694 hsc = ParseColorName(HIGHLIGHT_SQUARE_COLOR);
695 phc = ParseColorName(PREMOVE_HIGHLIGHT_COLOR);
699 CheckDlgButton(hDlg, OPT_Monochrome, FALSE);
700 CheckDlgButton(hDlg, OPT_AllWhite, FALSE);
701 CheckDlgButton(hDlg, OPT_UpsideDown, FALSE);
702 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
703 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
704 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
705 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
706 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
707 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
708 SetBoardOptionEnables(hDlg);
709 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
711 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
712 FALSE, mono, pieces);
717 SetBoardOptionEnables(hDlg);
722 SetBoardOptionEnables(hDlg);
727 SetBoardOptionEnables(hDlg);
737 BoardOptionsPopup(HWND hwnd)
739 FARPROC lpProc = MakeProcInstance((FARPROC)BoardOptionsDialog, hInst);
740 DialogBox(hInst, MAKEINTRESOURCE(DLG_BoardOptions), hwnd,
742 FreeProcInstance(lpProc);
746 VariantWhichRadio(HWND hDlg)
748 return (IsDlgButtonChecked(hDlg, OPT_VariantFairy) ? VariantFairy :
749 (IsDlgButtonChecked(hDlg, OPT_VariantGothic) ? VariantGothic :
750 (IsDlgButtonChecked(hDlg, OPT_VariantCrazyhouse) ? VariantCrazyhouse :
751 (IsDlgButtonChecked(hDlg, OPT_VariantBughouse) ? VariantBughouse :
752 (IsDlgButtonChecked(hDlg, OPT_VariantCourier) ? VariantCourier :
753 (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :
754 (IsDlgButtonChecked(hDlg, OPT_VariantShogi) ? VariantShogi :
755 (IsDlgButtonChecked(hDlg, OPT_VariantXiangqi) ? VariantXiangqi :
756 (IsDlgButtonChecked(hDlg, OPT_VariantCapablanca) ? VariantCapablanca :
757 (IsDlgButtonChecked(hDlg, OPT_VariantTwoKings) ? VariantTwoKings :
758 (IsDlgButtonChecked(hDlg, OPT_VariantKnightmate) ? VariantKnightmate :
759 (IsDlgButtonChecked(hDlg, OPT_VariantLosers) ? VariantLosers :
760 (IsDlgButtonChecked(hDlg, OPT_VariantSuicide) ? VariantSuicide :
761 (IsDlgButtonChecked(hDlg, OPT_VariantAtomic) ? VariantAtomic :
762 (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :
763 (IsDlgButtonChecked(hDlg, OPT_VariantFRC) ? VariantFischeRandom :
764 (IsDlgButtonChecked(hDlg, OPT_VariantCylinder) ? VariantCylinder :
765 (IsDlgButtonChecked(hDlg, OPT_VariantFalcon) ? VariantFalcon :
766 (IsDlgButtonChecked(hDlg, OPT_VariantCRC) ? VariantCapaRandom :
767 (IsDlgButtonChecked(hDlg, OPT_VariantSuper) ? VariantSuper :
768 (IsDlgButtonChecked(hDlg, OPT_VariantBerolina) ? VariantBerolina :
769 (IsDlgButtonChecked(hDlg, OPT_VariantJanus) ? VariantJanus :
770 (IsDlgButtonChecked(hDlg, OPT_VariantWildcastle) ? VariantWildCastle :
771 (IsDlgButtonChecked(hDlg, OPT_VariantNocastle) ? VariantNoCastle :
772 (IsDlgButtonChecked(hDlg, OPT_Variant3Check) ? Variant3Check :
773 (IsDlgButtonChecked(hDlg, OPT_VariantGreat) ? VariantGreat :
774 (IsDlgButtonChecked(hDlg, OPT_VariantGiveaway) ? VariantGiveaway :
775 (IsDlgButtonChecked(hDlg, OPT_VariantTwilight) ? VariantTwilight :
776 VariantNormal ))))))))))))))))))))))))))));
780 NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
782 static VariantClass v;
783 static int n1_ok, n2_ok, n3_ok;
786 case WM_INITDIALOG: /* message: initialize dialog box */
787 /* Center the dialog over the application window */
788 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
789 /* Initialize the dialog items */
790 switch (gameInfo.variant) {
792 CheckDlgButton(hDlg, OPT_VariantNormal, TRUE);
794 case VariantCrazyhouse:
795 CheckDlgButton(hDlg, OPT_VariantCrazyhouse, TRUE);
797 case VariantBughouse:
798 CheckDlgButton(hDlg, OPT_VariantBughouse, TRUE);
801 CheckDlgButton(hDlg, OPT_VariantShogi, TRUE);
804 CheckDlgButton(hDlg, OPT_VariantXiangqi, TRUE);
806 case VariantCapablanca:
807 CheckDlgButton(hDlg, OPT_VariantCapablanca, TRUE);
810 CheckDlgButton(hDlg, OPT_VariantGothic, TRUE);
813 CheckDlgButton(hDlg, OPT_VariantCourier, TRUE);
815 case VariantKnightmate:
816 CheckDlgButton(hDlg, OPT_VariantKnightmate, TRUE);
818 case VariantTwoKings:
819 CheckDlgButton(hDlg, OPT_VariantTwoKings, TRUE);
822 CheckDlgButton(hDlg, OPT_VariantFairy, TRUE);
825 CheckDlgButton(hDlg, OPT_VariantAtomic, TRUE);
828 CheckDlgButton(hDlg, OPT_VariantSuicide, TRUE);
831 CheckDlgButton(hDlg, OPT_VariantLosers, TRUE);
833 case VariantShatranj:
834 CheckDlgButton(hDlg, OPT_VariantShatranj, TRUE);
836 case VariantFischeRandom:
837 CheckDlgButton(hDlg, OPT_VariantFRC, TRUE);
839 case VariantCapaRandom:
840 CheckDlgButton(hDlg, OPT_VariantCRC, TRUE);
843 CheckDlgButton(hDlg, OPT_VariantFalcon, TRUE);
845 case VariantCylinder:
846 CheckDlgButton(hDlg, OPT_VariantCylinder, TRUE);
849 CheckDlgButton(hDlg, OPT_Variant3Check, TRUE);
852 CheckDlgButton(hDlg, OPT_VariantSuper, TRUE);
854 case VariantBerolina:
855 CheckDlgButton(hDlg, OPT_VariantBerolina, TRUE);
858 CheckDlgButton(hDlg, OPT_VariantJanus, TRUE);
860 case VariantWildCastle:
861 CheckDlgButton(hDlg, OPT_VariantWildcastle, TRUE);
863 case VariantNoCastle:
864 CheckDlgButton(hDlg, OPT_VariantNocastle, TRUE);
867 CheckDlgButton(hDlg, OPT_VariantGreat, TRUE);
869 case VariantGiveaway:
870 CheckDlgButton(hDlg, OPT_VariantGiveaway, TRUE);
872 case VariantTwilight:
873 CheckDlgButton(hDlg, OPT_VariantTwilight, TRUE);
878 SetDlgItemInt( hDlg, IDC_Files, -1, TRUE );
879 SendDlgItemMessage( hDlg, IDC_Files, EM_SETSEL, 0, -1 );
881 SetDlgItemInt( hDlg, IDC_Ranks, -1, TRUE );
882 SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );
884 SetDlgItemInt( hDlg, IDC_Holdings, -1, TRUE );
885 SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );
887 n1_ok = n2_ok = n3_ok = FALSE;
891 case WM_COMMAND: /* message: received a command */
892 switch (LOWORD(wParam)) {
895 * if we call EndDialog() after the call to ChangeBoardSize(),
896 * then ChangeBoardSize() does not take effect, although the new
897 * boardSize is saved. Go figure...
899 EndDialog(hDlg, TRUE);
901 v = VariantWhichRadio(hDlg);
902 if(!appData.noChessProgram) { char *name = VariantName(v), buf[MSG_SIZ];
903 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
904 /* [HGM] in protocol 2 we check if variant is suported by engine */
905 sprintf(buf, "Variant %s not supported by %s", name, first.tidy);
906 DisplayError(buf, 0);
907 return TRUE; /* treat as "Cancel" if first engine does not support it */
909 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
910 sprintf(buf, "Warning: second engine (%s) does not support this!", second.tidy);
911 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
915 gameInfo.variant = v;
916 appData.variant = VariantName(v);
918 appData.NrFiles = (int) GetDlgItemInt(hDlg, IDC_Files, NULL, FALSE );
919 appData.NrRanks = (int) GetDlgItemInt(hDlg, IDC_Ranks, NULL, FALSE );
920 appData.holdingsSize = (int) GetDlgItemInt(hDlg, IDC_Holdings, NULL, FALSE );
922 if(!n1_ok) appData.NrFiles = -1;
923 if(!n2_ok) appData.NrRanks = -1;
924 if(!n3_ok) appData.holdingsSize = -1;
926 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
927 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
928 appData.pieceToCharTable = NULL;
934 EndDialog(hDlg, FALSE);
940 if( HIWORD(wParam) == EN_CHANGE ) {
942 GetDlgItemInt(hDlg, IDC_Files, &n1_ok, FALSE );
943 GetDlgItemInt(hDlg, IDC_Ranks, &n2_ok, FALSE );
944 GetDlgItemInt(hDlg, IDC_Holdings, &n3_ok, FALSE );
946 /*EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok ? TRUE : FALSE );*/
957 NewVariantPopup(HWND hwnd)
959 FARPROC lpProc = MakeProcInstance((FARPROC)NewVariantDialog, hInst);
960 DialogBox(hInst, MAKEINTRESOURCE(DLG_NewVariant), hwnd,
962 FreeProcInstance(lpProc);
965 /*---------------------------------------------------------------------------*\
967 * ICS Options Dialog functions
969 \*---------------------------------------------------------------------------*/
972 MyCreateFont(HWND hwnd, MyFont *font)
977 /* Initialize members of the CHOOSEFONT structure. */
978 cf.lStructSize = sizeof(CHOOSEFONT);
981 cf.lpLogFont = &font->lf;
983 cf.Flags = CF_SCREENFONTS|/*CF_ANSIONLY|*/CF_INITTOLOGFONTSTRUCT;
984 cf.rgbColors = RGB(0,0,0);
986 cf.lpfnHook = (LPCFHOOKPROC)NULL;
987 cf.lpTemplateName = (LPSTR)NULL;
988 cf.hInstance = (HINSTANCE) NULL;
989 cf.lpszStyle = (LPSTR)NULL;
990 cf.nFontType = SCREEN_FONTTYPE;
994 /* Display the CHOOSEFONT common-dialog box. */
995 if (!ChooseFont(&cf)) {
999 /* Create a logical font based on the user's */
1000 /* selection and return a handle identifying */
1002 hf = CreateFontIndirect(cf.lpLogFont);
1008 font->mfp.pointSize = (float) (cf.iPointSize / 10.0);
1009 font->mfp.bold = (font->lf.lfWeight >= FW_BOLD);
1010 font->mfp.italic = font->lf.lfItalic;
1011 font->mfp.underline = font->lf.lfUnderline;
1012 font->mfp.strikeout = font->lf.lfStrikeOut;
1013 strcpy(font->mfp.faceName, font->lf.lfFaceName);
1019 UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca)
1022 cf.cbSize = sizeof(CHARFORMAT);
1024 CFM_COLOR|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE;
1025 cf.crTextColor = mca->color;
1026 cf.dwEffects = mca->effects;
1027 strcpy(cf.szFaceName, font[boardSize][CONSOLE_FONT]->mfp.faceName);
1029 * The 20.0 below is in fact documented. yHeight is expressed in twips.
1030 * A twip is 1/20 of a font's point size. See documentation of CHARFORMAT.
1033 cf.yHeight = (int)(font[boardSize][CONSOLE_FONT]->mfp.pointSize * 20.0 + 0.5);
1034 cf.bCharSet = DEFAULT_CHARSET; /* should be ignored anyway */
1035 cf.bPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
1036 SendDlgItemMessage(hDlg, id, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1040 ColorizeTextDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1042 static MyColorizeAttribs mca;
1043 static ColorClass cc;
1044 COLORREF background = (COLORREF)0;
1048 cc = (ColorClass)lParam;
1049 mca = colorizeAttribs[cc];
1050 /* Center the dialog over the application window */
1051 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1052 /* Initialize the dialog items */
1053 CheckDlgButton(hDlg, OPT_Bold, (mca.effects & CFE_BOLD) != 0);
1054 CheckDlgButton(hDlg, OPT_Italic, (mca.effects & CFE_ITALIC) != 0);
1055 CheckDlgButton(hDlg, OPT_Underline, (mca.effects & CFE_UNDERLINE) != 0);
1056 CheckDlgButton(hDlg, OPT_Strikeout, (mca.effects & CFE_STRIKEOUT) != 0);
1058 /* get the current background color from the parent window */
1059 SendMessage(GetWindow(hDlg, GW_OWNER),WM_COMMAND,
1060 (WPARAM)WM_USER_GetConsoleBackground,
1061 (LPARAM)&background);
1063 /* set the background color */
1064 SendDlgItemMessage(hDlg, OPT_Sample, EM_SETBKGNDCOLOR, FALSE, background);
1066 SetDlgItemText(hDlg, OPT_Sample, mca.name);
1067 UpdateSampleText(hDlg, OPT_Sample, &mca);
1070 case WM_COMMAND: /* message: received a command */
1071 switch (LOWORD(wParam)) {
1073 /* Read changed options from the dialog box */
1074 colorizeAttribs[cc] = mca;
1075 textAttribs[cc].color = mca.color;
1076 textAttribs[cc].effects = mca.effects;
1077 Colorize(currentColorClass, TRUE);
1078 if (cc == ColorNormal) {
1080 cf.cbSize = sizeof(CHARFORMAT);
1081 cf.dwMask = CFM_COLOR;
1082 cf.crTextColor = mca.color;
1083 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1084 EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1086 EndDialog(hDlg, TRUE);
1090 EndDialog(hDlg, FALSE);
1093 case OPT_ChooseColor:
1094 ChangeColor(hDlg, &mca.color);
1095 UpdateSampleText(hDlg, OPT_Sample, &mca);
1100 (IsDlgButtonChecked(hDlg, OPT_Bold) ? CFE_BOLD : 0) |
1101 (IsDlgButtonChecked(hDlg, OPT_Italic) ? CFE_ITALIC : 0) |
1102 (IsDlgButtonChecked(hDlg, OPT_Underline) ? CFE_UNDERLINE : 0) |
1103 (IsDlgButtonChecked(hDlg, OPT_Strikeout) ? CFE_STRIKEOUT : 0);
1104 UpdateSampleText(hDlg, OPT_Sample, &mca);
1113 ColorizeTextPopup(HWND hwnd, ColorClass cc)
1117 lpProc = MakeProcInstance((FARPROC)ColorizeTextDialog, hInst);
1118 DialogBoxParam(hInst, MAKEINTRESOURCE(DLG_Colorize),
1119 hwnd, (DLGPROC)lpProc, (LPARAM) cc);
1120 FreeProcInstance(lpProc);
1124 SetIcsOptionEnables(HWND hDlg)
1126 #define ENABLE_DLG_ITEM(x,y) EnableWindow(GetDlgItem(hDlg,(x)), (y))
1128 UINT state = IsDlgButtonChecked(hDlg, OPT_Premove);
1129 ENABLE_DLG_ITEM(OPT_PremoveWhite, state);
1130 ENABLE_DLG_ITEM(OPT_PremoveWhiteText, state);
1131 ENABLE_DLG_ITEM(OPT_PremoveBlack, state);
1132 ENABLE_DLG_ITEM(OPT_PremoveBlackText, state);
1134 ENABLE_DLG_ITEM(OPT_IcsAlarmTime, IsDlgButtonChecked(hDlg, OPT_IcsAlarm));
1136 #undef ENABLE_DLG_ITEM
1141 IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1146 static COLORREF cbc;
1147 static MyColorizeAttribs *mca;
1151 case WM_INITDIALOG: /* message: initialize dialog box */
1153 mca = colorizeAttribs;
1155 for (i=0; i < NColorClasses - 1; i++) {
1156 mca[i].color = textAttribs[i].color;
1157 mca[i].effects = textAttribs[i].effects;
1159 cbc = consoleBackgroundColor;
1161 /* Center the dialog over the application window */
1162 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1164 /* Initialize the dialog items */
1165 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
1167 CHECK_BOX(OPT_AutoComment, appData.autoComment);
1168 CHECK_BOX(OPT_AutoObserve, appData.autoObserve);
1169 CHECK_BOX(OPT_GetMoveList, appData.getMoveList);
1170 CHECK_BOX(OPT_LocalLineEditing, appData.localLineEditing);
1171 CHECK_BOX(OPT_QuietPlay, appData.quietPlay);
1172 CHECK_BOX(OPT_Premove, appData.premove);
1173 CHECK_BOX(OPT_PremoveWhite, appData.premoveWhite);
1174 CHECK_BOX(OPT_PremoveBlack, appData.premoveBlack);
1175 CHECK_BOX(OPT_IcsAlarm, appData.icsAlarm);
1176 CHECK_BOX(OPT_DontColorize, !appData.colorize);
1180 sprintf(buf, "%d", appData.icsAlarmTime / 1000);
1181 SetDlgItemText(hDlg, OPT_IcsAlarmTime, buf);
1182 SetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText);
1183 SetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText);
1185 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1186 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1187 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1188 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1189 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1190 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1191 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1192 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1193 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1194 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1196 SetDlgItemText(hDlg, OPT_SampleShout, mca[ColorShout].name);
1197 SetDlgItemText(hDlg, OPT_SampleSShout, mca[ColorSShout].name);
1198 SetDlgItemText(hDlg, OPT_SampleChannel1, mca[ColorChannel1].name);
1199 SetDlgItemText(hDlg, OPT_SampleChannel, mca[ColorChannel].name);
1200 SetDlgItemText(hDlg, OPT_SampleKibitz, mca[ColorKibitz].name);
1201 SetDlgItemText(hDlg, OPT_SampleTell, mca[ColorTell].name);
1202 SetDlgItemText(hDlg, OPT_SampleChallenge, mca[ColorChallenge].name);
1203 SetDlgItemText(hDlg, OPT_SampleRequest, mca[ColorRequest].name);
1204 SetDlgItemText(hDlg, OPT_SampleSeek, mca[ColorSeek].name);
1205 SetDlgItemText(hDlg, OPT_SampleNormal, mca[ColorNormal].name);
1207 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1208 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1209 UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]);
1210 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1211 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1212 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1213 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1214 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1215 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1216 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1218 SetIcsOptionEnables(hDlg);
1221 case WM_COMMAND: /* message: received a command */
1222 switch (LOWORD(wParam)) {
1224 case WM_USER_GetConsoleBackground:
1225 /* the ColorizeTextDialog needs the current background color */
1226 colorref = (COLORREF *)lParam;
1231 /* Read changed options from the dialog box */
1232 GetDlgItemText(hDlg, OPT_IcsAlarmTime, buf, MSG_SIZ);
1233 if (sscanf(buf, "%d", &number) != 1 || (number < 0)){
1234 MessageBox(hDlg, "Invalid ICS Alarm Time",
1235 "Option Error", MB_OK|MB_ICONEXCLAMATION);
1239 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
1241 appData.icsAlarm = IS_CHECKED(OPT_IcsAlarm);
1242 appData.premove = IS_CHECKED(OPT_Premove);
1243 appData.premoveWhite = IS_CHECKED(OPT_PremoveWhite);
1244 appData.premoveBlack = IS_CHECKED(OPT_PremoveBlack);
1245 appData.autoComment = IS_CHECKED(OPT_AutoComment);
1246 appData.autoObserve = IS_CHECKED(OPT_AutoObserve);
1247 appData.getMoveList = IS_CHECKED(OPT_GetMoveList);
1248 appData.localLineEditing = IS_CHECKED(OPT_LocalLineEditing);
1249 appData.quietPlay = IS_CHECKED(OPT_QuietPlay);
1253 appData.icsAlarmTime = number * 1000;
1254 GetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText, 5);
1255 GetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText, 5);
1257 if (appData.localLineEditing) {
1266 (Boolean)!IsDlgButtonChecked(hDlg, OPT_DontColorize);
1268 if (!appData.colorize) {
1270 COLORREF background = ParseColorName(COLOR_BKGD);
1272 SetDefaultTextAttribs();
1273 Colorize(currentColorClass);
1275 cf.cbSize = sizeof(CHARFORMAT);
1276 cf.dwMask = CFM_COLOR;
1277 cf.crTextColor = ParseColorName(COLOR_NORMAL);
1279 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1280 EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1281 SendDlgItemMessage(hwndConsole, OPT_ConsoleText,
1282 EM_SETBKGNDCOLOR, FALSE, background);
1283 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1284 EM_SETBKGNDCOLOR, FALSE, background);
1287 if (cbc != consoleBackgroundColor) {
1288 consoleBackgroundColor = cbc;
1289 if (appData.colorize) {
1290 SendDlgItemMessage(hwndConsole, OPT_ConsoleText,
1291 EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);
1292 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1293 EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);
1297 for (i=0; i < NColorClasses - 1; i++) {
1298 textAttribs[i].color = mca[i].color;
1299 textAttribs[i].effects = mca[i].effects;
1302 EndDialog(hDlg, TRUE);
1306 EndDialog(hDlg, FALSE);
1309 case OPT_ChooseShoutColor:
1310 ColorizeTextPopup(hDlg, ColorShout);
1311 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1314 case OPT_ChooseSShoutColor:
1315 ColorizeTextPopup(hDlg, ColorSShout);
1316 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1319 case OPT_ChooseChannel1Color:
1320 ColorizeTextPopup(hDlg, ColorChannel1);
1321 UpdateSampleText(hDlg, OPT_SampleChannel1,
1322 &colorizeAttribs[ColorChannel1]);
1325 case OPT_ChooseChannelColor:
1326 ColorizeTextPopup(hDlg, ColorChannel);
1327 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1330 case OPT_ChooseKibitzColor:
1331 ColorizeTextPopup(hDlg, ColorKibitz);
1332 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1335 case OPT_ChooseTellColor:
1336 ColorizeTextPopup(hDlg, ColorTell);
1337 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1340 case OPT_ChooseChallengeColor:
1341 ColorizeTextPopup(hDlg, ColorChallenge);
1342 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1345 case OPT_ChooseRequestColor:
1346 ColorizeTextPopup(hDlg, ColorRequest);
1347 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1350 case OPT_ChooseSeekColor:
1351 ColorizeTextPopup(hDlg, ColorSeek);
1352 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1355 case OPT_ChooseNormalColor:
1356 ColorizeTextPopup(hDlg, ColorNormal);
1357 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1360 case OPT_ChooseBackgroundColor:
1361 if (ChangeColor(hDlg, &cbc)) {
1362 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1363 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1364 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1365 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1366 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1367 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1368 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1369 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1370 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1371 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1375 case OPT_DefaultColors:
1376 for (i=0; i < NColorClasses - 1; i++)
1377 ParseAttribs(&mca[i].color,
1379 defaultTextAttribs[i]);
1381 cbc = ParseColorName(COLOR_BKGD);
1382 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1383 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1384 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1385 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1386 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1387 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1388 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1389 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1390 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1391 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1393 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1394 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1395 UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]);
1396 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1397 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1398 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1399 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1400 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1401 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1402 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1406 SetIcsOptionEnables(hDlg);
1415 IcsOptionsPopup(HWND hwnd)
1417 FARPROC lpProc = MakeProcInstance((FARPROC)IcsOptionsDialog, hInst);
1418 DialogBox(hInst, MAKEINTRESOURCE(DLG_IcsOptions), hwnd,
1420 FreeProcInstance(lpProc);
1423 /*---------------------------------------------------------------------------*\
1425 * Fonts Dialog functions
1427 \*---------------------------------------------------------------------------*/
1430 SetSampleFontText(HWND hwnd, int id, const MyFont *mf)
1437 RECT rectClient, rectFormat;
1442 len = sprintf(buf, "%.0f pt. %s%s%s\n",
1443 mf->mfp.pointSize, mf->mfp.faceName,
1444 mf->mfp.bold ? " bold" : "",
1445 mf->mfp.italic ? " italic" : "");
1446 SetDlgItemText(hwnd, id, buf);
1448 hControl = GetDlgItem(hwnd, id);
1449 hdc = GetDC(hControl);
1450 SetMapMode(hdc, MM_TEXT); /* 1 pixel == 1 logical unit */
1451 oldFont = SelectObject(hdc, mf->hf);
1453 /* get number of logical units necessary to display font name */
1454 GetTextExtentPoint32(hdc, buf, len, &size);
1456 /* calculate formatting rectangle in the rich edit control.
1457 * May be larger or smaller than the actual control.
1459 GetClientRect(hControl, &rectClient);
1460 center.x = (rectClient.left + rectClient.right) / 2;
1461 center.y = (rectClient.top + rectClient.bottom) / 2;
1462 rectFormat.top = center.y - (size.cy / 2) - 1;
1463 rectFormat.bottom = center.y + (size.cy / 2) + 1;
1464 rectFormat.left = center.x - (size.cx / 2) - 1;
1465 rectFormat.right = center.x + (size.cx / 2) + 1;
1467 cf.cbSize = sizeof(CHARFORMAT);
1468 cf.dwMask = CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_BOLD|CFM_ITALIC;
1470 if (mf->lf.lfWeight == FW_BOLD) cf.dwEffects |= CFE_BOLD;
1471 if (mf->lf.lfItalic) cf.dwEffects |= CFE_ITALIC;
1472 strcpy(cf.szFaceName, mf->mfp.faceName);
1474 * yHeight is expressed in twips. A twip is 1/20 of a font's point
1475 * size. See documentation of CHARFORMAT. --msw
1477 cf.yHeight = (int)(mf->mfp.pointSize * 20.0 + 0.5);
1478 cf.bCharSet = mf->lf.lfCharSet;
1479 cf.bPitchAndFamily = mf->lf.lfPitchAndFamily;
1481 /* format the text in the rich edit control */
1482 SendMessage(hControl, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf);
1483 SendMessage(hControl, EM_SETRECT, (WPARAM)0, (LPARAM) &rectFormat);
1486 SelectObject(hdc, oldFont);
1487 ReleaseDC(hControl, hdc);
1491 CopyFont(MyFont *dest, const MyFont *src)
1493 dest->mfp.pointSize = src->mfp.pointSize;
1494 dest->mfp.bold = src->mfp.bold;
1495 dest->mfp.italic = src->mfp.italic;
1496 dest->mfp.underline = src->mfp.underline;
1497 dest->mfp.strikeout = src->mfp.strikeout;
1498 lstrcpy(dest->mfp.faceName, src->mfp.faceName);
1499 CreateFontInMF(dest);
1504 FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1506 static MyFont workFont[NUM_FONTS];
1507 static BOOL firstPaint;
1514 /* copy the current font settings into a working copy */
1515 for (i=0; i < NUM_FONTS; i++)
1516 CopyFont(&workFont[i], font[boardSize][i]);
1518 if (!appData.icsActive)
1519 EnableWindow(GetDlgItem(hDlg, OPT_ChooseConsoleFont), FALSE);
1521 firstPaint = TRUE; /* see rant below */
1523 /* If I don't call SetFocus(), the dialog won't respond to the keyboard
1524 * when first drawn. Why is this the only dialog that behaves this way? Is
1525 * is the WM_PAINT stuff below?? Sigh...
1527 SetFocus(GetDlgItem(hDlg, IDOK));
1531 /* This should not be necessary. However, if SetSampleFontText() is called
1532 * in response to WM_INITDIALOG, the strings are not properly centered in
1533 * the controls when the dialog first appears. I can't figure out why, so
1534 * this is the workaround. --msw
1537 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1538 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1539 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1540 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1541 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1542 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1543 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1548 case WM_COMMAND: /* message: received a command */
1549 switch (LOWORD(wParam)) {
1552 /* again, it seems to avoid redraw problems if we call EndDialog first */
1553 EndDialog(hDlg, FALSE);
1555 /* copy modified settings back to the fonts array */
1556 for (i=0; i < NUM_FONTS; i++)
1557 CopyFont(font[boardSize][i], &workFont[i]);
1559 /* a sad necessity due to the original design of having a separate
1560 * console font, tags font, and comment font for each board size. IMHO
1561 * these fonts should not be dependent on the current board size. I'm
1562 * running out of time, so I am doing this hack rather than redesign the
1563 * data structure. Besides, I think if I redesigned the data structure, I
1564 * might break backwards compatibility with old winboard.ini files.
1567 for (i=0; i < NUM_SIZES; i++) {
1568 CopyFont(font[i][EDITTAGS_FONT], &workFont[EDITTAGS_FONT]);
1569 CopyFont(font[i][CONSOLE_FONT], &workFont[CONSOLE_FONT]);
1570 CopyFont(font[i][COMMENT_FONT], &workFont[COMMENT_FONT]);
1571 CopyFont(font[i][MOVEHISTORY_FONT], &workFont[MOVEHISTORY_FONT]);
1573 /* end sad necessity */
1575 InitDrawingSizes(boardSize, 0);
1576 InvalidateRect(hwndMain, NULL, TRUE);
1578 if (commentDialog) {
1579 SendDlgItemMessage(commentDialog, OPT_CommentText,
1580 WM_SETFONT, (WPARAM)font[boardSize][COMMENT_FONT]->hf,
1581 MAKELPARAM(TRUE, 0));
1582 GetClientRect(GetDlgItem(commentDialog, OPT_CommentText), &rect);
1583 InvalidateRect(commentDialog, &rect, TRUE);
1586 if (editTagsDialog) {
1587 SendDlgItemMessage(editTagsDialog, OPT_TagsText,
1588 WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf,
1589 MAKELPARAM(TRUE, 0));
1590 GetClientRect(GetDlgItem(editTagsDialog, OPT_TagsText), &rect);
1591 InvalidateRect(editTagsDialog, &rect, TRUE);
1594 if( moveHistoryDialog != NULL ) {
1595 SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory,
1596 WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,
1597 MAKELPARAM(TRUE, 0));
1598 SendMessage( moveHistoryDialog, WM_INITDIALOG, 0, 0 );
1599 // InvalidateRect(editTagsDialog, NULL, TRUE); // [HGM] this ws improperly cloned?
1602 if( engineOutputDialog != NULL ) {
1603 SendDlgItemMessage(engineOutputDialog, IDC_EngineMemo1,
1604 WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,
1605 MAKELPARAM(TRUE, 0));
1606 SendDlgItemMessage(engineOutputDialog, IDC_EngineMemo2,
1607 WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,
1608 MAKELPARAM(TRUE, 0));
1612 ChangedConsoleFont();
1615 for (i=0; i<NUM_FONTS; i++)
1616 DeleteObject(&workFont[i].hf);
1621 for (i=0; i<NUM_FONTS; i++)
1622 DeleteObject(&workFont[i].hf);
1623 EndDialog(hDlg, FALSE);
1626 case OPT_ChooseClockFont:
1627 MyCreateFont(hDlg, &workFont[CLOCK_FONT]);
1628 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1631 case OPT_ChooseMessageFont:
1632 MyCreateFont(hDlg, &workFont[MESSAGE_FONT]);
1633 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1636 case OPT_ChooseCoordFont:
1637 MyCreateFont(hDlg, &workFont[COORD_FONT]);
1638 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1641 case OPT_ChooseTagFont:
1642 MyCreateFont(hDlg, &workFont[EDITTAGS_FONT]);
1643 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1646 case OPT_ChooseCommentsFont:
1647 MyCreateFont(hDlg, &workFont[COMMENT_FONT]);
1648 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1651 case OPT_ChooseConsoleFont:
1652 MyCreateFont(hDlg, &workFont[CONSOLE_FONT]);
1653 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1656 case OPT_ChooseMoveHistoryFont:
1657 MyCreateFont(hDlg, &workFont[MOVEHISTORY_FONT]);
1658 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1661 case OPT_DefaultFonts:
1662 for (i=0; i<NUM_FONTS; i++) {
1663 DeleteObject(&workFont[i].hf);
1664 ParseFontName(font[boardSize][i]->def, &workFont[i].mfp);
1665 CreateFontInMF(&workFont[i]);
1667 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1668 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1669 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1670 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1671 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1672 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1673 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1681 FontsOptionsPopup(HWND hwnd)
1683 FARPROC lpProc = MakeProcInstance((FARPROC)FontOptionsDialog, hInst);
1684 DialogBox(hInst, MAKEINTRESOURCE(DLG_Fonts), hwnd,
1686 FreeProcInstance(lpProc);
1689 /*---------------------------------------------------------------------------*\
1691 * Sounds Dialog functions
1693 \*---------------------------------------------------------------------------*/
1696 SoundComboData soundComboData[] = {
1699 {"ICS Alarm", NULL},
1703 {"ICS Unfinished", NULL},
1705 {"SShout/CShout", NULL},
1706 {"Channel 1", NULL},
1710 {"Challenge", NULL},
1718 InitSoundComboData(SoundComboData *scd)
1724 /* copy current sound settings to combo array */
1726 for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) {
1727 scd[sc].name = strdup(sounds[sc].name);
1729 for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) {
1730 index = (int)cc + (int)NSoundClasses;
1731 scd[index].name = strdup(textAttribs[cc].sound.name);
1737 ResetSoundComboData(SoundComboData *scd)
1739 while (scd->label) {
1740 if (scd->name != NULL) {
1749 InitSoundCombo(HWND hwndCombo, SoundComboData *scd)
1754 SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
1756 /* send the labels to the combo box */
1757 while (scd->label) {
1758 err = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) scd->label);
1760 sprintf(buf, "InitSoundCombo(): err '%d', cnt '%d'\n",
1761 (int)err, (int)cnt);
1762 MessageBox(NULL, buf, NULL, MB_OK);
1766 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) 0, (LPARAM) 0);
1770 SoundDialogWhichRadio(HWND hDlg)
1772 if (IsDlgButtonChecked(hDlg, OPT_NoSound)) return OPT_NoSound;
1773 if (IsDlgButtonChecked(hDlg, OPT_DefaultBeep)) return OPT_DefaultBeep;
1774 if (IsDlgButtonChecked(hDlg, OPT_BuiltInSound)) return OPT_BuiltInSound;
1775 if (IsDlgButtonChecked(hDlg, OPT_WavFile)) return OPT_WavFile;
1780 SoundDialogSetEnables(HWND hDlg, int radio)
1782 EnableWindow(GetDlgItem(hDlg, OPT_BuiltInSoundName),
1783 radio == OPT_BuiltInSound);
1784 EnableWindow(GetDlgItem(hDlg, OPT_WavFileName), radio == OPT_WavFile);
1785 EnableWindow(GetDlgItem(hDlg, OPT_BrowseSound), radio == OPT_WavFile);
1789 SoundDialogGetName(HWND hDlg, int radio)
1791 static char buf[MSG_SIZ], buf2[MSG_SIZ], buf3[MSG_SIZ];
1797 case OPT_DefaultBeep:
1799 case OPT_BuiltInSound:
1801 GetDlgItemText(hDlg, OPT_BuiltInSoundName, buf + 1, sizeof(buf) - 1);
1804 GetDlgItemText(hDlg, OPT_WavFileName, buf, sizeof(buf));
1805 GetCurrentDirectory(MSG_SIZ, buf3);
1806 SetCurrentDirectory(installDir);
1807 if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {
1812 SetCurrentDirectory(buf3);
1818 DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name)
1822 * I think it's best to clear the combo and edit boxes. It looks stupid
1823 * to have a value from another sound event sitting there grayed out.
1825 SetDlgItemText(hDlg, OPT_WavFileName, "");
1826 SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
1828 if (appData.debugMode)
1829 fprintf(debugFP, "DisplaySelectedSound(,,'%s'):\n", name);
1832 radio = OPT_NoSound;
1835 if (name[1] == NULLCHAR) {
1836 radio = OPT_DefaultBeep;
1838 radio = OPT_WavFile;
1839 SetDlgItemText(hDlg, OPT_WavFileName, name);
1843 if (name[1] == NULLCHAR) {
1844 radio = OPT_NoSound;
1846 radio = OPT_BuiltInSound;
1847 if (SendMessage(hCombo, CB_SELECTSTRING, (WPARAM) -1,
1848 (LPARAM) (name + 1)) == CB_ERR) {
1849 SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
1850 SendMessage(hCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) (name + 1));
1855 radio = OPT_WavFile;
1856 SetDlgItemText(hDlg, OPT_WavFileName, name);
1859 SoundDialogSetEnables(hDlg, radio);
1860 CheckRadioButton(hDlg, OPT_NoSound, OPT_WavFile, radio);
1864 char *builtInSoundNames[] = BUILT_IN_SOUND_NAMES;
1867 SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1869 static HWND hSoundCombo;
1879 SoundComboData *scd;
1884 /* Center the dialog over the application window */
1885 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1887 /* Initialize the built-in sounds combo */
1888 hBISN = GetDlgItem(hDlg, OPT_BuiltInSoundName);
1889 InitComboStrings(hBISN, builtInSoundNames);
1891 /* Initialize the sound events combo */
1893 InitSoundComboData(soundComboData);
1894 hSoundCombo = GetDlgItem(hDlg, CBO_Sounds);
1895 InitSoundCombo(hSoundCombo, soundComboData);
1897 /* update the dialog */
1898 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
1901 case WM_COMMAND: /* message: received a command */
1903 if (((HWND)lParam == hSoundCombo) &&
1904 (HIWORD(wParam) == CBN_SELCHANGE)) {
1906 * the user has selected a new sound event. We must store the name for
1907 * the previously selected event, then retrieve the name for the
1908 * newly selected event and update the dialog.
1910 radio = SoundDialogWhichRadio(hDlg);
1911 newName = strdup(SoundDialogGetName(hDlg, radio));
1913 if (strcmp(newName, soundComboData[index].name) != 0) {
1914 free(soundComboData[index].name);
1915 soundComboData[index].name = newName;
1920 /* now get the settings for the newly selected event */
1921 index = SendMessage(hSoundCombo, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
1922 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
1926 switch (LOWORD(wParam)) {
1929 * save the name for the currently selected sound event
1931 radio = SoundDialogWhichRadio(hDlg);
1932 newName = strdup(SoundDialogGetName(hDlg, radio));
1934 if (strcmp(soundComboData[index].name, newName) != 0) {
1935 free(soundComboData[index].name);
1936 soundComboData[index].name = newName;
1942 /* save all the sound names that changed and load the sounds */
1944 for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) {
1945 if (strcmp(soundComboData[sc].name, sounds[sc].name) != 0) {
1946 free(sounds[sc].name);
1947 sounds[sc].name = strdup(soundComboData[sc].name);
1948 MyLoadSound(&sounds[sc]);
1951 for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) {
1952 index = (int)cc + (int)NSoundClasses;
1953 if (strcmp(soundComboData[index].name,
1954 textAttribs[cc].sound.name) != 0) {
1955 free(textAttribs[cc].sound.name);
1956 textAttribs[cc].sound.name = strdup(soundComboData[index].name);
1957 MyLoadSound(&textAttribs[cc].sound);
1961 mute = FALSE; // [HGM] mute: switch sounds automatically on if we select one
1962 CheckMenuItem(GetMenu(hwndMain),IDM_MuteSounds,MF_BYCOMMAND|MF_UNCHECKED);
1963 ResetSoundComboData(soundComboData);
1964 EndDialog(hDlg, TRUE);
1968 ResetSoundComboData(soundComboData);
1969 EndDialog(hDlg, FALSE);
1972 case OPT_DefaultSounds:
1973 /* can't use SetDefaultSounds() because we need to be able to "undo" if
1974 * user selects "Cancel" later on. So we do it the hard way here.
1976 scd = &soundComboData[0];
1977 while (scd->label != NULL) {
1978 if (scd->name != NULL) free(scd->name);
1979 scd->name = strdup("");
1982 free(soundComboData[(int)SoundBell].name);
1983 soundComboData[(int)SoundBell].name = strdup(SOUND_BELL);
1984 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
1988 radio = SoundDialogWhichRadio(hDlg);
1989 tmp.name = strdup(SoundDialogGetName(hDlg, radio));
1992 oldMute = mute; mute = FALSE; // [HGM] mute: always sound when user presses play, ignorig mute setting
1995 if (tmp.data != NULL) FreeResource(tmp.data); // technically obsolete fn, but tmp.data is NOT malloc'd mem
1996 if (tmp.name != NULL) free(tmp.name);
1999 case OPT_BrowseSound:
2000 f = OpenFileDialog(hDlg, "rb", NULL, "wav", SOUND_FILT,
2001 "Browse for Sound File", NULL, NULL, buf);
2004 SetDlgItemText(hDlg, OPT_WavFileName, buf);
2009 radio = SoundDialogWhichRadio(hDlg);
2010 SoundDialogSetEnables(hDlg, radio);
2019 VOID SoundOptionsPopup(HWND hwnd)
2023 lpProc = MakeProcInstance((FARPROC)SoundOptionsDialog, hInst);
2024 DialogBox(hInst, MAKEINTRESOURCE(DLG_Sound), hwnd, (DLGPROC)lpProc);
2025 FreeProcInstance(lpProc);
2029 /*---------------------------------------------------------------------------*\
2031 * Comm Port dialog functions
2033 \*---------------------------------------------------------------------------*/
2043 ComboData cdPort[] = { {"None", PORT_NONE}, {"COM1", 1}, {"COM2", 2},
2044 {"COM3", 3}, {"COM4", 4}, {NULL, 0} };
2045 ComboData cdDataRate[] = { {"110", 110}, {"300", 300}, {"600", 600}, {"1200", 1200},
2046 {"2400", 2400}, {"4800", 4800}, {"9600", 9600}, {"19200", 19200},
2047 {"38400", 38400}, {NULL, 0} };
2048 ComboData cdDataBits[] = { {"5", 5}, {"6", 6}, {"7", 7}, {"8", 8}, {NULL, 0} };
2049 ComboData cdParity[] = { {"None", NOPARITY}, {"Odd", ODDPARITY}, {"Even", EVENPARITY},
2050 {"Mark", MARKPARITY}, {"Space", SPACEPARITY}, {NULL, 0} };
2051 ComboData cdStopBits[] = { {"1", ONESTOPBIT}, {"1.5", ONE5STOPBITS},
2052 {"2", TWOSTOPBITS}, {NULL, 0} };
2053 ComboData cdFlow[] = { {"None", FLOW_NONE}, {"Xoff/Xon", FLOW_XOFF}, {"CTS", FLOW_CTS},
2054 {"DSR", FLOW_DSR}, {NULL, 0} };
2058 ParseCommSettings(char *arg, DCB *dcb)
2060 int dataRate, count;
2061 char bits[MSG_SIZ], parity[MSG_SIZ], stopBits[MSG_SIZ], flow[MSG_SIZ];
2063 count = sscanf(arg, "%d%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]",
2064 &dataRate, bits, parity, stopBits, flow);
2065 if (count != 5) goto cant_parse;
2066 dcb->BaudRate = dataRate;
2068 while (cd->label != NULL) {
2069 if (StrCaseCmp(cd->label, bits) == 0) {
2070 dcb->ByteSize = cd->value;
2075 if (cd->label == NULL) goto cant_parse;
2077 while (cd->label != NULL) {
2078 if (StrCaseCmp(cd->label, parity) == 0) {
2079 dcb->Parity = cd->value;
2084 if (cd->label == NULL) goto cant_parse;
2086 while (cd->label != NULL) {
2087 if (StrCaseCmp(cd->label, stopBits) == 0) {
2088 dcb->StopBits = cd->value;
2094 if (cd->label == NULL) goto cant_parse;
2095 while (cd->label != NULL) {
2096 if (StrCaseCmp(cd->label, flow) == 0) {
2097 switch (cd->value) {
2100 dcb->fOutxCtsFlow = FALSE;
2101 dcb->fOutxDsrFlow = FALSE;
2105 dcb->fOutxCtsFlow = TRUE;
2106 dcb->fOutxDsrFlow = FALSE;
2110 dcb->fOutxCtsFlow = FALSE;
2111 dcb->fOutxDsrFlow = TRUE;
2115 dcb->fOutxCtsFlow = FALSE;
2116 dcb->fOutxDsrFlow = FALSE;
2123 if (cd->label == NULL) goto cant_parse;
2126 ExitArgError("Can't parse com port settings", arg);
2130 VOID PrintCommSettings(FILE *f, char *name, DCB *dcb)
2132 char *flow = "??", *parity = "??", *stopBits = "??";
2136 while (cd->label != NULL) {
2137 if (dcb->Parity == cd->value) {
2144 while (cd->label != NULL) {
2145 if (dcb->StopBits == cd->value) {
2146 stopBits = cd->label;
2152 flow = cdFlow[FLOW_XOFF].label;
2153 } else if (dcb->fOutxCtsFlow) {
2154 flow = cdFlow[FLOW_CTS].label;
2155 } else if (dcb->fOutxDsrFlow) {
2156 flow = cdFlow[FLOW_DSR].label;
2158 flow = cdFlow[FLOW_NONE].label;
2160 fprintf(f, "/%s=%d,%d,%s,%s,%s\n", name,
2161 (int)dcb->BaudRate, dcb->ByteSize, parity, stopBits, flow);
2166 InitCombo(HANDLE hwndCombo, ComboData *cd)
2168 SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
2170 while (cd->label != NULL) {
2171 SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) cd->label);
2177 SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value)
2182 while (cd->label != NULL) {
2183 if (cd->value == value) {
2184 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) i, (LPARAM) 0);
2193 CommPortOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2203 case WM_INITDIALOG: /* message: initialize dialog box */
2204 /* Center the dialog over the application window */
2205 CenterWindow (hDlg, GetWindow(hDlg, GW_OWNER));
2206 /* Initialize the dialog items */
2207 /* !! There should probably be some synchronization
2208 in accessing hCommPort and dcb. Or does modal nature
2209 of this dialog box do it for us?
2211 hwndCombo = GetDlgItem(hDlg, OPT_Port);
2212 InitCombo(hwndCombo, cdPort);
2213 p = strrchr(appData.icsCommPort, '\\');
2214 if (p++ == NULL) p = appData.icsCommPort;
2216 (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) p) == CB_ERR)) {
2217 SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) "None");
2219 EnableWindow(hwndCombo, hCommPort == NULL); /*!! don't allow change for now*/
2221 hwndCombo = GetDlgItem(hDlg, OPT_DataRate);
2222 InitCombo(hwndCombo, cdDataRate);
2223 sprintf(buf, "%u", (int)dcb.BaudRate);
2224 if (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) buf) == CB_ERR) {
2225 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
2226 SendMessage(hwndCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) buf);
2229 hwndCombo = GetDlgItem(hDlg, OPT_Bits);
2230 InitCombo(hwndCombo, cdDataBits);
2231 SelectComboValue(hwndCombo, cdDataBits, dcb.ByteSize);
2233 hwndCombo = GetDlgItem(hDlg, OPT_Parity);
2234 InitCombo(hwndCombo, cdParity);
2235 SelectComboValue(hwndCombo, cdParity, dcb.Parity);
2237 hwndCombo = GetDlgItem(hDlg, OPT_StopBits);
2238 InitCombo(hwndCombo, cdStopBits);
2239 SelectComboValue(hwndCombo, cdStopBits, dcb.StopBits);
2241 hwndCombo = GetDlgItem(hDlg, OPT_Flow);
2242 InitCombo(hwndCombo, cdFlow);
2244 SelectComboValue(hwndCombo, cdFlow, FLOW_XOFF);
2245 } else if (dcb.fOutxCtsFlow) {
2246 SelectComboValue(hwndCombo, cdFlow, FLOW_CTS);
2247 } else if (dcb.fOutxDsrFlow) {
2248 SelectComboValue(hwndCombo, cdFlow, FLOW_DSR);
2250 SelectComboValue(hwndCombo, cdFlow, FLOW_NONE);
2254 case WM_COMMAND: /* message: received a command */
2255 switch (LOWORD(wParam)) {
2257 /* Read changed options from the dialog box */
2259 /* !! Currently we can't change comm ports in midstream */
2260 hwndCombo = GetDlgItem(hDlg, OPT_Port);
2261 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2262 if (index == PORT_NONE) {
2263 appData.icsCommPort = "";
2264 if (hCommPort != NULL) {
2265 CloseHandle(hCommPort);
2268 EndDialog(hDlg, TRUE);
2271 SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf);
2272 appData.icsCommPort = strdup(buf);
2273 if (hCommPort != NULL) {
2274 CloseHandle(hCommPort);
2277 /* now what?? can't really do this; have to fix up the ChildProc
2278 and InputSource records for the comm port that we gave to the
2282 hwndCombo = GetDlgItem(hDlg, OPT_DataRate);
2283 SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf);
2284 if (sscanf(buf, "%u", &value) != 1) {
2285 MessageBox(hDlg, "Invalid data rate",
2286 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2289 dcb.BaudRate = value;
2291 hwndCombo = GetDlgItem(hDlg, OPT_Bits);
2292 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2293 dcb.ByteSize = cdDataBits[index].value;
2295 hwndCombo = GetDlgItem(hDlg, OPT_Parity);
2296 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2297 dcb.Parity = cdParity[index].value;
2299 hwndCombo = GetDlgItem(hDlg, OPT_StopBits);
2300 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2301 dcb.StopBits = cdStopBits[index].value;
2303 hwndCombo = GetDlgItem(hDlg, OPT_Flow);
2304 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2305 switch (cdFlow[index].value) {
2308 dcb.fOutxCtsFlow = FALSE;
2309 dcb.fOutxDsrFlow = FALSE;
2313 dcb.fOutxCtsFlow = TRUE;
2314 dcb.fOutxDsrFlow = FALSE;
2318 dcb.fOutxCtsFlow = FALSE;
2319 dcb.fOutxDsrFlow = TRUE;
2323 dcb.fOutxCtsFlow = FALSE;
2324 dcb.fOutxDsrFlow = FALSE;
2327 if (!SetCommState(hCommPort, (LPDCB) &dcb)) {
2328 err = GetLastError();
2329 switch(MessageBox(hDlg,
2330 "Failed to set comm port state;\r\ninvalid options?",
2331 "Option Error", MB_ABORTRETRYIGNORE|MB_ICONQUESTION)) {
2333 DisplayFatalError("Failed to set comm port state", err, 1);
2334 exit(1); /*is it ok to do this from here?*/
2340 EndDialog(hDlg, TRUE);
2345 EndDialog(hDlg, TRUE);
2349 EndDialog(hDlg, FALSE);
2361 CommPortOptionsPopup(HWND hwnd)
2363 FARPROC lpProc = MakeProcInstance((FARPROC)CommPortOptionsDialog, hInst);
2364 DialogBox(hInst, MAKEINTRESOURCE(DLG_CommPort), hwnd, (DLGPROC) lpProc);
2365 FreeProcInstance(lpProc);
2368 /*---------------------------------------------------------------------------*\
2370 * Load Options dialog functions
2372 \*---------------------------------------------------------------------------*/
2375 SetLoadOptionEnables(HWND hDlg)
2379 state = IsDlgButtonChecked(hDlg, OPT_Autostep);
2380 EnableWindow(GetDlgItem(hDlg, OPT_ASTimeDelay), state);
2381 EnableWindow(GetDlgItem(hDlg, OPT_AStext1), state);
2385 LoadOptions(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2391 case WM_INITDIALOG: /* message: initialize dialog box */
2392 /* Center the dialog over the application window */
2393 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2394 /* Initialize the dialog items */
2395 if (appData.timeDelay >= 0.0) {
2396 CheckDlgButton(hDlg, OPT_Autostep, TRUE);
2397 sprintf(buf, "%.2g", appData.timeDelay);
2398 SetDlgItemText(hDlg, OPT_ASTimeDelay, buf);
2400 CheckDlgButton(hDlg, OPT_Autostep, FALSE);
2402 SetLoadOptionEnables(hDlg);
2405 case WM_COMMAND: /* message: received a command */
2406 switch (LOWORD(wParam)) {
2408 /* Read changed options from the dialog box */
2409 if (IsDlgButtonChecked(hDlg, OPT_Autostep)) {
2410 GetDlgItemText(hDlg, OPT_ASTimeDelay, buf, MSG_SIZ);
2411 if (sscanf(buf, "%f", &fnumber) != 1) {
2412 MessageBox(hDlg, "Invalid load game step rate",
2413 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2416 appData.timeDelay = fnumber;
2418 appData.timeDelay = (float) -1.0;
2420 EndDialog(hDlg, TRUE);
2424 EndDialog(hDlg, FALSE);
2428 SetLoadOptionEnables(hDlg);
2438 LoadOptionsPopup(HWND hwnd)
2440 FARPROC lpProc = MakeProcInstance((FARPROC)LoadOptions, hInst);
2441 DialogBox(hInst, MAKEINTRESOURCE(DLG_LoadOptions), hwnd, (DLGPROC) lpProc);
2442 FreeProcInstance(lpProc);
2445 /*---------------------------------------------------------------------------*\
2447 * Save Options dialog functions
2449 \*---------------------------------------------------------------------------*/
2452 SetSaveOptionEnables(HWND hDlg)
2456 state = IsDlgButtonChecked(hDlg, OPT_Autosave);
2457 EnableWindow(GetDlgItem(hDlg, OPT_AVPrompt), state);
2458 EnableWindow(GetDlgItem(hDlg, OPT_AVToFile), state);
2459 if (state && !IsDlgButtonChecked(hDlg, OPT_AVPrompt) &&
2460 !IsDlgButtonChecked(hDlg, OPT_AVToFile)) {
2461 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt);
2464 state = state && IsDlgButtonChecked(hDlg, OPT_AVToFile);
2465 EnableWindow(GetDlgItem(hDlg, OPT_AVFilename), state);
2466 EnableWindow(GetDlgItem(hDlg, OPT_AVBrowse), state);
2470 SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2476 case WM_INITDIALOG: /* message: initialize dialog box */
2477 /* Center the dialog over the application window */
2478 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2479 /* Initialize the dialog items */
2480 if (*appData.saveGameFile != NULLCHAR) {
2481 CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE);
2482 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVToFile);
2483 SetDlgItemText(hDlg, OPT_AVFilename, appData.saveGameFile);
2484 } else if (appData.autoSaveGames) {
2485 CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE);
2486 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt);
2488 CheckDlgButton(hDlg, OPT_Autosave, (UINT) FALSE);
2490 if (appData.oldSaveStyle) {
2491 CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_Old);
2493 CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_PGN);
2495 CheckDlgButton( hDlg, OPT_OutOfBookInfo, appData.saveOutOfBookInfo );
2496 SetSaveOptionEnables(hDlg);
2499 case WM_COMMAND: /* message: received a command */
2500 switch (LOWORD(wParam)) {
2502 /* Read changed options from the dialog box */
2503 if (IsDlgButtonChecked(hDlg, OPT_Autosave)) {
2504 appData.autoSaveGames = TRUE;
2505 if (IsDlgButtonChecked(hDlg, OPT_AVPrompt)) {
2506 appData.saveGameFile = "";
2507 } else /*if (IsDlgButtonChecked(hDlg, OPT_AVToFile))*/ {
2508 GetDlgItemText(hDlg, OPT_AVFilename, buf, MSG_SIZ);
2509 if (*buf == NULLCHAR) {
2510 MessageBox(hDlg, "Invalid save game file name",
2511 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2514 if ((isalpha(buf[0]) && buf[1] == ':') ||
2515 (buf[0] == '\\' && buf[1] == '\\')) {
2516 appData.saveGameFile = strdup(buf);
2518 char buf2[MSG_SIZ], buf3[MSG_SIZ];
2520 GetCurrentDirectory(MSG_SIZ, buf3);
2521 SetCurrentDirectory(installDir);
2522 if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {
2523 appData.saveGameFile = strdup(buf2);
2525 appData.saveGameFile = strdup(buf);
2527 SetCurrentDirectory(buf3);
2531 appData.autoSaveGames = FALSE;
2532 appData.saveGameFile = "";
2534 appData.oldSaveStyle = IsDlgButtonChecked(hDlg, OPT_Old);
2535 appData.saveOutOfBookInfo = IsDlgButtonChecked( hDlg, OPT_OutOfBookInfo );
2536 EndDialog(hDlg, TRUE);
2540 EndDialog(hDlg, FALSE);
2544 f = OpenFileDialog(hDlg, "a", NULL,
2545 appData.oldSaveStyle ? "gam" : "pgn",
2546 GAME_FILT, "Browse for Auto Save File",
2550 SetDlgItemText(hDlg, OPT_AVFilename, buf);
2555 SetSaveOptionEnables(hDlg);
2564 SaveOptionsPopup(HWND hwnd)
2566 FARPROC lpProc = MakeProcInstance((FARPROC)SaveOptionsDialog, hInst);
2567 DialogBox(hInst, MAKEINTRESOURCE(DLG_SaveOptions), hwnd, (DLGPROC) lpProc);
2568 FreeProcInstance(lpProc);
2571 /*---------------------------------------------------------------------------*\
2573 * Time Control Options dialog functions
2575 \*---------------------------------------------------------------------------*/
2578 SetTimeControlEnables(HWND hDlg)
2582 state = IsDlgButtonChecked(hDlg, OPT_TCUseMoves);
2583 EnableWindow(GetDlgItem(hDlg, OPT_TCTime), state);
2584 EnableWindow(GetDlgItem(hDlg, OPT_TCMoves), state);
2585 EnableWindow(GetDlgItem(hDlg, OPT_TCtext1), state);
2586 EnableWindow(GetDlgItem(hDlg, OPT_TCtext2), state);
2587 EnableWindow(GetDlgItem(hDlg, OPT_TCTime2), !state);
2588 EnableWindow(GetDlgItem(hDlg, OPT_TCInc), !state);
2589 EnableWindow(GetDlgItem(hDlg, OPT_TCitext1), !state);
2590 EnableWindow(GetDlgItem(hDlg, OPT_TCitext2), !state);
2591 EnableWindow(GetDlgItem(hDlg, OPT_TCitext3), !state);
2596 TimeControl(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2599 int mps, increment, odds1, odds2;
2603 case WM_INITDIALOG: /* message: initialize dialog box */
2604 /* Center the dialog over the application window */
2605 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2606 /* Initialize the dialog items */
2607 if (appData.clockMode && !appData.icsActive) {
2608 if (appData.timeIncrement == -1) {
2609 CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,
2611 SetDlgItemText(hDlg, OPT_TCTime, appData.timeControl);
2612 SetDlgItemInt(hDlg, OPT_TCMoves, appData.movesPerSession,
2614 SetDlgItemText(hDlg, OPT_TCTime2, "");
2615 SetDlgItemText(hDlg, OPT_TCInc, "");
2617 CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,
2619 SetDlgItemText(hDlg, OPT_TCTime, "");
2620 SetDlgItemText(hDlg, OPT_TCMoves, "");
2621 SetDlgItemText(hDlg, OPT_TCTime2, appData.timeControl);
2622 SetDlgItemInt(hDlg, OPT_TCInc, appData.timeIncrement, FALSE);
2624 SetDlgItemInt(hDlg, OPT_TCOdds1, 1, FALSE);
2625 SetDlgItemInt(hDlg, OPT_TCOdds2, 1, FALSE);
2626 SetTimeControlEnables(hDlg);
2630 case WM_COMMAND: /* message: received a command */
2631 switch (LOWORD(wParam)) {
2633 /* Read changed options from the dialog box */
2634 if (IsDlgButtonChecked(hDlg, OPT_TCUseMoves)) {
2636 mps = GetDlgItemInt(hDlg, OPT_TCMoves, &ok, FALSE);
2637 if (!ok || mps <= 0) {
2638 MessageBox(hDlg, "Invalid moves per time control",
2639 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2642 GetDlgItemText(hDlg, OPT_TCTime, buf, MSG_SIZ);
2643 if (!ParseTimeControl(buf, increment, mps)) {
2644 MessageBox(hDlg, "Invalid minutes per time control",
2645 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2649 increment = GetDlgItemInt(hDlg, OPT_TCInc, &ok, FALSE);
2650 mps = appData.movesPerSession;
2651 if (!ok || increment < 0) {
2652 MessageBox(hDlg, "Invalid increment",
2653 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2656 GetDlgItemText(hDlg, OPT_TCTime2, buf, MSG_SIZ);
2657 if (!ParseTimeControl(buf, increment, mps)) {
2658 MessageBox(hDlg, "Invalid initial time",
2659 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2663 odds1 = GetDlgItemInt(hDlg, OPT_TCOdds1, &ok, FALSE);
2664 odds2 = GetDlgItemInt(hDlg, OPT_TCOdds2, &ok2, FALSE);
2665 if (!ok || !ok2 || odds1 <= 0 || odds2 <= 0) {
2666 MessageBox(hDlg, "Invalid time-odds factor",
2667 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2670 appData.timeControl = strdup(buf);
2671 appData.movesPerSession = mps;
2672 appData.timeIncrement = increment;
2673 appData.firstTimeOdds = first.timeOdds = odds1;
2674 appData.secondTimeOdds = second.timeOdds = odds2;
2676 EndDialog(hDlg, TRUE);
2680 EndDialog(hDlg, FALSE);
2684 SetTimeControlEnables(hDlg);
2693 TimeControlOptionsPopup(HWND hwnd)
2695 if (gameMode != BeginningOfGame) {
2696 DisplayError("Changing time control during a game is not implemented", 0);
2698 FARPROC lpProc = MakeProcInstance((FARPROC)TimeControl, hInst);
2699 DialogBox(hInst, MAKEINTRESOURCE(DLG_TimeControl), hwnd, (DLGPROC) lpProc);
2700 FreeProcInstance(lpProc);
2704 /*---------------------------------------------------------------------------*\
2706 * Engine Options Dialog functions
2708 \*---------------------------------------------------------------------------*/
2709 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
2710 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
2712 #define INT_ABS( n ) ((n) >= 0 ? (n) : -(n))
2714 LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2717 case WM_INITDIALOG: /* message: initialize dialog box */
2719 /* Center the dialog over the application window */
2720 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2722 /* Initialize the dialog items */
2723 CHECK_BOX(IDC_EpPeriodicUpdates, appData.periodicUpdates);
2724 CHECK_BOX(IDC_EpPonder, appData.ponderNextMove);
2725 CHECK_BOX(IDC_EpShowThinking, appData.showThinking);
2726 CHECK_BOX(IDC_EpHideThinkingHuman, appData.hideThinkingFromHuman);
2728 CHECK_BOX(IDC_TestClaims, appData.testClaims);
2729 CHECK_BOX(IDC_DetectMates, appData.checkMates);
2730 CHECK_BOX(IDC_MaterialDraws, appData.materialDraws);
2731 CHECK_BOX(IDC_TrivialDraws, appData.trivialDraws);
2733 CHECK_BOX(IDC_ScoreAbs1, appData.firstScoreIsAbsolute);
2734 CHECK_BOX(IDC_ScoreAbs2, appData.secondScoreIsAbsolute);
2736 SetDlgItemInt( hDlg, IDC_EpDrawMoveCount, appData.adjudicateDrawMoves, TRUE );
2737 SendDlgItemMessage( hDlg, IDC_EpDrawMoveCount, EM_SETSEL, 0, -1 );
2739 SetDlgItemInt( hDlg, IDC_EpAdjudicationThreshold, INT_ABS(appData.adjudicateLossThreshold), TRUE );
2740 SendDlgItemMessage( hDlg, IDC_EpAdjudicationThreshold, EM_SETSEL, 0, -1 );
2742 SetDlgItemInt( hDlg, IDC_RuleMoves, appData.ruleMoves, TRUE );
2743 SendDlgItemMessage( hDlg, IDC_RuleMoves, EM_SETSEL, 0, -1 );
2745 SetDlgItemInt( hDlg, IDC_DrawRepeats, INT_ABS(appData.drawRepeats), TRUE );
2746 SendDlgItemMessage( hDlg, IDC_DrawRepeats, EM_SETSEL, 0, -1 );
2750 case WM_COMMAND: /* message: received a command */
2751 switch (LOWORD(wParam)) {
2753 /* Read changed options from the dialog box */
2754 PeriodicUpdatesEvent( IS_CHECKED(IDC_EpPeriodicUpdates));
2755 PonderNextMoveEvent( IS_CHECKED(IDC_EpPonder));
2756 appData.hideThinkingFromHuman= IS_CHECKED(IDC_EpHideThinkingHuman); // [HGM] thinking: moved up
2757 appData.showThinking = IS_CHECKED(IDC_EpShowThinking);
2758 ShowThinkingEvent(); // [HGM] thinking: tests all options that need thinking output
2759 appData.testClaims = IS_CHECKED(IDC_TestClaims);
2760 appData.checkMates = IS_CHECKED(IDC_DetectMates);
2761 appData.materialDraws = IS_CHECKED(IDC_MaterialDraws);
2762 appData.trivialDraws = IS_CHECKED(IDC_TrivialDraws);
2764 appData.adjudicateDrawMoves = GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, NULL, FALSE );
2765 appData.adjudicateLossThreshold = - (int) GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, NULL, FALSE );
2766 appData.ruleMoves = GetDlgItemInt(hDlg, IDC_RuleMoves, NULL, FALSE );
2767 appData.drawRepeats = (int) GetDlgItemInt(hDlg, IDC_DrawRepeats, NULL, FALSE );
2769 appData.firstScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs1);
2770 appData.secondScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs2);
2772 EndDialog(hDlg, TRUE);
2776 EndDialog(hDlg, FALSE);
2779 case IDC_EpDrawMoveCount:
2780 case IDC_EpAdjudicationThreshold:
2781 case IDC_DrawRepeats:
2783 if( HIWORD(wParam) == EN_CHANGE ) {
2789 GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, &n1_ok, FALSE );
2790 GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, &n2_ok, FALSE );
2791 GetDlgItemInt(hDlg, IDC_RuleMoves, &n3_ok, FALSE );
2792 GetDlgItemInt(hDlg, IDC_DrawRepeats, &n4_ok, FALSE );
2794 EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok && n4_ok ? TRUE : FALSE );
2803 VOID EnginePlayOptionsPopup(HWND hwnd)
2807 lpProc = MakeProcInstance((FARPROC)EnginePlayOptionsDialog, hInst);
2808 DialogBox(hInst, MAKEINTRESOURCE(DLG_EnginePlayOptions), hwnd, (DLGPROC) lpProc);
2809 FreeProcInstance(lpProc);
2812 /*---------------------------------------------------------------------------*\
2814 * UCI Options Dialog functions
2816 \*---------------------------------------------------------------------------*/
2817 static BOOL BrowseForFolder( const char * title, char * path )
2819 BOOL result = FALSE;
2823 ZeroMemory( &bi, sizeof(bi) );
2825 bi.lpszTitle = title == 0 ? "Choose Folder" : title;
2826 bi.ulFlags = BIF_RETURNONLYFSDIRS;
2828 pidl = SHBrowseForFolder( &bi );
2831 IMalloc * imalloc = 0;
2833 if( SHGetPathFromIDList( pidl, path ) ) {
2837 if( SUCCEEDED( SHGetMalloc ( &imalloc ) ) ) {
2838 imalloc->lpVtbl->Free(imalloc,pidl);
2839 imalloc->lpVtbl->Release(imalloc);
2846 LRESULT CALLBACK UciOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2852 case WM_INITDIALOG: /* message: initialize dialog box */
2854 /* Center the dialog over the application window */
2855 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2857 /* Initialize the dialog items */
2858 SetDlgItemText( hDlg, IDC_PolyglotDir, appData.polyglotDir );
2859 SetDlgItemInt( hDlg, IDC_HashSize, appData.defaultHashSize, TRUE );
2860 SetDlgItemText( hDlg, IDC_PathToEGTB, appData.defaultPathEGTB );
2861 SetDlgItemInt( hDlg, IDC_SizeOfEGTB, appData.defaultCacheSizeEGTB, TRUE );
2862 CheckDlgButton( hDlg, IDC_UseBook, (BOOL) appData.usePolyglotBook );
2863 SetDlgItemText( hDlg, IDC_BookFile, appData.polyglotBook );
2864 // [HGM] smp: input field for nr of cores:
2865 SetDlgItemInt( hDlg, IDC_Cores, appData.smpCores, TRUE );
2866 // [HGM] book: tick boxes for own book use
2867 CheckDlgButton( hDlg, IDC_OwnBook1, (BOOL) appData.firstHasOwnBookUCI );
2868 CheckDlgButton( hDlg, IDC_OwnBook2, (BOOL) appData.secondHasOwnBookUCI );
2870 SendDlgItemMessage( hDlg, IDC_PolyglotDir, EM_SETSEL, 0, -1 );
2874 case WM_COMMAND: /* message: received a command */
2875 switch (LOWORD(wParam)) {
2877 GetDlgItemText( hDlg, IDC_PolyglotDir, buf, sizeof(buf) );
2878 appData.polyglotDir = strdup(buf);
2879 appData.defaultHashSize = GetDlgItemInt(hDlg, IDC_HashSize, NULL, FALSE );
2880 appData.defaultCacheSizeEGTB = GetDlgItemInt(hDlg, IDC_SizeOfEGTB, NULL, FALSE );
2881 GetDlgItemText( hDlg, IDC_PathToEGTB, buf, sizeof(buf) );
2882 appData.defaultPathEGTB = strdup(buf);
2883 GetDlgItemText( hDlg, IDC_BookFile, buf, sizeof(buf) );
2884 appData.polyglotBook = strdup(buf);
2885 appData.usePolyglotBook = (Boolean) IsDlgButtonChecked( hDlg, IDC_UseBook );
2886 // [HGM] smp: get nr of cores:
2887 oldCores = appData.smpCores;
2888 appData.smpCores = GetDlgItemInt(hDlg, IDC_Cores, NULL, FALSE );
2889 if(appData.smpCores != oldCores) NewSettingEvent(FALSE, "cores", appData.smpCores);
2890 // [HGM] book: read tick boxes for own book use
2891 appData.firstHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook1 );
2892 appData.secondHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook2 );
2894 if(gameMode == BeginningOfGame) Reset(TRUE, TRUE);
2895 EndDialog(hDlg, TRUE);
2899 EndDialog(hDlg, FALSE);
2902 case IDC_BrowseForBook:
2905 'A','l','l',' ','F','i','l','e','s', 0,
2907 'B','I','N',' ','F','i','l','e','s', 0,
2908 '*','.','b','i','n', 0,
2915 ZeroMemory( &ofn, sizeof(ofn) );
2917 ofn.lStructSize = sizeof(ofn);
2918 ofn.hwndOwner = hDlg;
2919 ofn.hInstance = hInst;
2920 ofn.lpstrFilter = filter;
2921 ofn.lpstrFile = buf;
2922 ofn.nMaxFile = sizeof(buf);
2923 ofn.lpstrTitle = "Choose Book";
2924 ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;
2926 if( GetOpenFileName( &ofn ) ) {
2927 SetDlgItemText( hDlg, IDC_BookFile, buf );
2932 case IDC_BrowseForPolyglotDir:
2933 if( BrowseForFolder( "Choose Polyglot Directory", buf ) ) {
2934 SetDlgItemText( hDlg, IDC_PolyglotDir, buf );
2936 strcat( buf, "\\polyglot.exe" );
2938 if( GetFileAttributes(buf) == 0xFFFFFFFF ) {
2939 MessageBox( hDlg, "Polyglot was not found in the specified folder!", "Warning", MB_OK | MB_ICONWARNING );
2944 case IDC_BrowseForEGTB:
2945 if( BrowseForFolder( "Choose EGTB Directory:", buf ) ) {
2946 SetDlgItemText( hDlg, IDC_PathToEGTB, buf );
2951 case IDC_SizeOfEGTB:
2952 if( HIWORD(wParam) == EN_CHANGE ) {
2956 GetDlgItemInt(hDlg, IDC_HashSize, &n1_ok, FALSE );
2957 GetDlgItemInt(hDlg, IDC_SizeOfEGTB, &n2_ok, FALSE );
2959 EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok ? TRUE : FALSE );
2968 VOID UciOptionsPopup(HWND hwnd)
2972 lpProc = MakeProcInstance((FARPROC)UciOptionsDialog, hInst);
2973 DialogBox(hInst, MAKEINTRESOURCE(DLG_OptionsUCI), hwnd, (DLGPROC) lpProc);
2974 FreeProcInstance(lpProc);