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);
227 ShowThinkingEvent( IS_CHECKED(OPT_ShowThinking));
229 appData.showThinking = IS_CHECKED(OPT_ShowThinking);
230 ShowThinkingEvent(); // [HGM] thinking: tests four options
232 appData.testLegality = IS_CHECKED(OPT_TestLegality);
233 appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow);
237 SetWindowPos(hwndMain, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
238 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
241 SetWindowPos(hwndConsole, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
242 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
245 if (!appData.highlightLastMove) {
247 DrawPosition(FALSE, NULL);
250 * for some reason the redraw seems smoother when we invalidate
251 * the board rect after the call to EndDialog()
253 EndDialog(hDlg, TRUE);
255 if (oldShowButtonBar != appData.showButtonBar) {
256 InitDrawingSizes(boardSize, 0);
257 } else if ((oldShowCoords != appData.showCoords) ||
258 (oldBlindfold != appData.blindfold)) {
259 InvalidateRect(hwndMain, &boardRect, FALSE);
265 EndDialog(hDlg, FALSE);
275 GeneralOptionsPopup(HWND hwnd)
279 lpProc = MakeProcInstance((FARPROC)GeneralOptionsDialog, hInst);
280 DialogBox(hInst, MAKEINTRESOURCE(DLG_GeneralOptions), hwnd,
282 FreeProcInstance(lpProc);
284 /*---------------------------------------------------------------------------*\
286 * Board Options Dialog functions
288 \*---------------------------------------------------------------------------*/
290 const int SAMPLE_SQ_SIZE = 54;
293 ChangeBoardSize(BoardSize newSize)
295 if (newSize != boardSize) {
297 InitDrawingSizes(boardSize, 0);
305 COLORREF squareColor,
307 COLORREF squareOutlineColor,
308 COLORREF pieceDetailColor,
315 HBRUSH brushSquareOutline;
317 HBRUSH brushPieceDetail;
318 HBRUSH oldBrushPiece = NULL;
319 HBRUSH oldBrushSquare;
320 HBITMAP oldBitmapMem;
321 HBITMAP oldBitmapTemp;
322 HBITMAP bufferBitmap;
324 HDC hdcScreen, hdcMem, hdcTemp;
326 HWND hCtrl = GetDlgItem(hwnd, ctrlid);
331 const int OUTLINE = 2;
332 const int BORDER = 4;
334 InvalidateRect(hCtrl, NULL, TRUE);
336 GetClientRect(hCtrl, &rect);
337 x = rect.left + (BORDER / 2);
338 y = rect.top + (BORDER / 2);
339 hdcScreen = GetDC(hCtrl);
340 hdcMem = CreateCompatibleDC(hdcScreen);
341 hdcTemp = CreateCompatibleDC(hdcScreen);
343 bufferBitmap = CreateCompatibleBitmap(hdcScreen, rect.right-rect.left+1,
344 rect.bottom-rect.top+1);
345 oldBitmapMem = SelectObject(hdcMem, bufferBitmap);
347 SelectPalette(hdcMem, hPal, FALSE);
349 brushSquare = CreateSolidBrush(squareColor);
350 brushSquareOutline = CreateSolidBrush(squareOutlineColor);
351 brushPiece = CreateSolidBrush(pieceColor);
352 brushPieceDetail = CreateSolidBrush(pieceDetailColor);
355 * first draw the rectangle
357 pen = CreatePen(PS_SOLID, BORDER, squareOutlineColor);
358 oldPen = (HPEN) SelectObject(hdcMem, pen);
359 oldBrushSquare = (HBRUSH)SelectObject(hdcMem, brushSquare);
360 Rectangle(hdcMem, rect.left, rect.top, rect.right, rect.bottom);
366 oldBitmapTemp = SelectObject(hdcTemp, pieces[OUTLINE]);
367 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, hdcTemp, 0, 0,
368 isWhitePiece ? SRCCOPY : NOTSRCCOPY);
369 SelectObject(hdcTemp, oldBitmapTemp);
372 oldBitmapTemp = SelectObject(hdcTemp, pieces[WHITE]);
373 oldBrushPiece = SelectObject(hdcMem, brushPiece);
374 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
375 hdcTemp, 0, 0, 0x00B8074A);
377 /* Use pieceDetailColor for outline of white pieces */
378 SelectObject(hdcTemp, pieces[OUTLINE]);
379 SelectObject(hdcMem, brushPieceDetail);
380 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
381 hdcTemp, 0, 0, 0x00B8074A);
383 /* Use black for outline of white pieces */
384 SelectObject(hdcTemp, pieces[OUTLINE]);
385 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
386 hdcTemp, 0, 0, SRCAND);
390 /* Use pieceDetailColor for details of black pieces */
391 /* Requires filled-in solid bitmaps (BLACK_PIECE class); the
392 WHITE_PIECE ones aren't always the right shape. */
393 oldBitmapTemp = SelectObject(hdcTemp, pieces[BLACK]);
394 oldBrushPiece = SelectObject(hdcMem, brushPieceDetail);
395 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
396 hdcTemp, 0, 0, 0x00B8074A);
397 SelectObject(hdcTemp, pieces[SOLID]);
398 SelectObject(hdcMem, brushPiece);
399 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
400 hdcTemp, 0, 0, 0x00B8074A);
402 /* Use square color for details of black pieces */
403 oldBitmapTemp = SelectObject(hdcTemp, pieces[SOLID]);
404 oldBrushPiece = SelectObject(hdcMem, brushPiece);
405 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
406 hdcTemp, 0, 0, 0x00B8074A);
409 SelectObject(hdcMem, oldBrushPiece);
410 SelectObject(hdcTemp, oldBitmapTemp);
413 * copy the memory dc to the screen
415 SelectObject(hdcMem, bufferBitmap);
416 BitBlt(hdcScreen, rect.left, rect.top,
417 rect.right - rect.left,
418 rect.bottom - rect.top,
419 hdcMem, rect.left, rect.top, SRCCOPY);
420 SelectObject(hdcMem, oldBitmapMem);
424 SelectObject(hdcMem, oldBrushPiece);
425 SelectObject(hdcMem, oldPen);
426 DeleteObject(brushPiece);
427 DeleteObject(brushPieceDetail);
428 DeleteObject(brushSquare);
429 DeleteObject(brushSquareOutline);
433 ReleaseDC(hCtrl, hdcScreen);
438 PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color)
441 HBRUSH brush, oldBrush;
443 HWND hCtrl = GetDlgItem(hwnd, ctrlid);
446 InvalidateRect(hCtrl, NULL, TRUE);
448 GetClientRect(hCtrl, &rect);
449 brush = CreateSolidBrush(color);
450 oldBrush = (HBRUSH)SelectObject(hdc, brush);
451 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
452 SelectObject(hdc, oldBrush);
454 ReleaseDC(hCtrl, hdc);
459 SetBoardOptionEnables(HWND hDlg)
461 if (IsDlgButtonChecked(hDlg, OPT_Monochrome)) {
462 ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_HIDE);
463 ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_HIDE);
464 ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_HIDE);
465 ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_HIDE);
467 EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), FALSE);
468 EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), FALSE);
469 EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), FALSE);
470 EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), FALSE);
472 ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_SHOW);
473 ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_SHOW);
474 ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_SHOW);
475 ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_SHOW);
477 EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), TRUE);
478 EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), TRUE);
479 EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), TRUE);
480 EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), TRUE);
485 BoardOptionsWhichRadio(HWND hDlg)
487 return (IsDlgButtonChecked(hDlg, OPT_SizeTiny) ? SizeTiny :
488 (IsDlgButtonChecked(hDlg, OPT_SizeTeeny) ? SizeTeeny :
489 (IsDlgButtonChecked(hDlg, OPT_SizeDinky) ? SizeDinky :
490 (IsDlgButtonChecked(hDlg, OPT_SizePetite) ? SizePetite :
491 (IsDlgButtonChecked(hDlg, OPT_SizeSlim) ? SizeSlim :
492 (IsDlgButtonChecked(hDlg, OPT_SizeSmall) ? SizeSmall :
493 (IsDlgButtonChecked(hDlg, OPT_SizeMediocre) ? SizeMediocre :
494 (IsDlgButtonChecked(hDlg, OPT_SizeMiddling) ? SizeMiddling :
495 (IsDlgButtonChecked(hDlg, OPT_SizeAverage) ? SizeAverage :
496 (IsDlgButtonChecked(hDlg, OPT_SizeModerate) ? SizeModerate :
497 (IsDlgButtonChecked(hDlg, OPT_SizeMedium) ? SizeMedium :
498 (IsDlgButtonChecked(hDlg, OPT_SizeBulky) ? SizeBulky :
499 (IsDlgButtonChecked(hDlg, OPT_SizeLarge) ? SizeLarge :
500 (IsDlgButtonChecked(hDlg, OPT_SizeBig) ? SizeBig :
501 (IsDlgButtonChecked(hDlg, OPT_SizeHuge) ? SizeHuge :
502 (IsDlgButtonChecked(hDlg, OPT_SizeGiant) ? SizeGiant :
503 (IsDlgButtonChecked(hDlg, OPT_SizeColossal) ? SizeColossal :
504 SizeTitanic )))))))))))))))));
508 BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
510 static Boolean mono, white, flip;
511 static BoardSize size;
512 static COLORREF lsc, dsc, wpc, bpc, hsc, phc;
513 static HBITMAP pieces[3];
516 case WM_INITDIALOG: /* message: initialize dialog box */
517 /* Center the dialog over the application window */
518 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
519 /* Initialize the dialog items */
522 CheckDlgButton(hDlg, OPT_SizeTiny, TRUE);
525 CheckDlgButton(hDlg, OPT_SizeTeeny, TRUE);
528 CheckDlgButton(hDlg, OPT_SizeDinky, TRUE);
531 CheckDlgButton(hDlg, OPT_SizePetite, TRUE);
534 CheckDlgButton(hDlg, OPT_SizeSlim, TRUE);
537 CheckDlgButton(hDlg, OPT_SizeSmall, TRUE);
540 CheckDlgButton(hDlg, OPT_SizeMediocre, TRUE);
543 CheckDlgButton(hDlg, OPT_SizeMiddling, TRUE);
546 CheckDlgButton(hDlg, OPT_SizeAverage, TRUE);
549 CheckDlgButton(hDlg, OPT_SizeModerate, TRUE);
552 CheckDlgButton(hDlg, OPT_SizeMedium, TRUE);
555 CheckDlgButton(hDlg, OPT_SizeBulky, TRUE);
558 CheckDlgButton(hDlg, OPT_SizeLarge, TRUE);
561 CheckDlgButton(hDlg, OPT_SizeBig, TRUE);
564 CheckDlgButton(hDlg, OPT_SizeHuge, TRUE);
567 CheckDlgButton(hDlg, OPT_SizeGiant, TRUE);
570 CheckDlgButton(hDlg, OPT_SizeColossal, TRUE);
573 CheckDlgButton(hDlg, OPT_SizeTitanic, TRUE);
574 default: ; // should not happen, but suppresses warning on pedantic compilers
577 if (appData.monoMode)
578 CheckDlgButton(hDlg, OPT_Monochrome, TRUE);
580 if (appData.allWhite)
581 CheckDlgButton(hDlg, OPT_AllWhite, TRUE);
583 if (appData.upsideDown)
584 CheckDlgButton(hDlg, OPT_UpsideDown, TRUE);
586 pieces[0] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "s");
587 pieces[1] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "w");
588 pieces[2] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "o");
590 lsc = lightSquareColor;
591 dsc = darkSquareColor;
592 wpc = whitePieceColor;
593 bpc = blackPieceColor;
594 hsc = highlightSquareColor;
595 phc = premoveHighlightColor;
596 mono = appData.monoMode;
597 white= appData.allWhite;
598 flip = appData.upsideDown;
601 SetBoardOptionEnables(hDlg);
605 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
606 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
607 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
608 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
609 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
610 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
611 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
613 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
614 FALSE, mono, pieces);
618 case WM_COMMAND: /* message: received a command */
619 switch (LOWORD(wParam)) {
622 * if we call EndDialog() after the call to ChangeBoardSize(),
623 * then ChangeBoardSize() does not take effect, although the new
624 * boardSize is saved. Go figure...
626 EndDialog(hDlg, TRUE);
628 size = BoardOptionsWhichRadio(hDlg);
631 * did any settings change?
633 if (size != boardSize) {
634 ChangeBoardSize(size);
637 if ((mono != appData.monoMode) ||
638 (lsc != lightSquareColor) ||
639 (dsc != darkSquareColor) ||
640 (wpc != whitePieceColor) ||
641 (bpc != blackPieceColor) ||
642 (hsc != highlightSquareColor) ||
643 (flip != appData.upsideDown) ||
644 (white != appData.allWhite) ||
645 (phc != premoveHighlightColor)) {
647 lightSquareColor = lsc;
648 darkSquareColor = dsc;
649 whitePieceColor = wpc;
650 blackPieceColor = bpc;
651 highlightSquareColor = hsc;
652 premoveHighlightColor = phc;
653 appData.monoMode = mono;
654 appData.allWhite = white;
655 appData.upsideDown = flip;
658 InitDrawingSizes(boardSize, 0);
659 InvalidateRect(hwndMain, &boardRect, FALSE);
661 DeleteObject(pieces[0]);
662 DeleteObject(pieces[1]);
663 DeleteObject(pieces[2]);
667 DeleteObject(pieces[0]);
668 DeleteObject(pieces[1]);
669 DeleteObject(pieces[2]);
670 EndDialog(hDlg, FALSE);
673 case OPT_ChooseLightSquareColor:
674 if (ChangeColor(hDlg, &lsc))
675 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
676 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
680 case OPT_ChooseDarkSquareColor:
681 if (ChangeColor(hDlg, &dsc))
682 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
683 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
684 FALSE, mono, pieces);
687 case OPT_ChooseWhitePieceColor:
688 if (ChangeColor(hDlg, &wpc))
689 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
690 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
694 case OPT_ChooseBlackPieceColor:
695 if (ChangeColor(hDlg, &bpc))
696 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
697 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
698 FALSE, mono, pieces);
701 case OPT_ChooseHighlightSquareColor:
702 if (ChangeColor(hDlg, &hsc))
703 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
704 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
708 case OPT_ChoosePremoveHighlightColor:
709 if (ChangeColor(hDlg, &phc))
710 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
711 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
712 FALSE, mono, pieces);
715 case OPT_DefaultBoardColors:
716 lsc = ParseColorName(LIGHT_SQUARE_COLOR);
717 dsc = ParseColorName(DARK_SQUARE_COLOR);
718 wpc = ParseColorName(WHITE_PIECE_COLOR);
719 bpc = ParseColorName(BLACK_PIECE_COLOR);
720 hsc = ParseColorName(HIGHLIGHT_SQUARE_COLOR);
721 phc = ParseColorName(PREMOVE_HIGHLIGHT_COLOR);
725 CheckDlgButton(hDlg, OPT_Monochrome, FALSE);
726 CheckDlgButton(hDlg, OPT_AllWhite, FALSE);
727 CheckDlgButton(hDlg, OPT_UpsideDown, FALSE);
728 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
729 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
730 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
731 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
732 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
733 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
734 SetBoardOptionEnables(hDlg);
735 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
737 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
738 FALSE, mono, pieces);
743 SetBoardOptionEnables(hDlg);
748 SetBoardOptionEnables(hDlg);
753 SetBoardOptionEnables(hDlg);
763 BoardOptionsPopup(HWND hwnd)
765 FARPROC lpProc = MakeProcInstance((FARPROC)BoardOptionsDialog, hInst);
766 DialogBox(hInst, MAKEINTRESOURCE(DLG_BoardOptions), hwnd,
768 FreeProcInstance(lpProc);
772 VariantWhichRadio(HWND hDlg)
774 return (IsDlgButtonChecked(hDlg, OPT_VariantFairy) ? VariantFairy :
775 (IsDlgButtonChecked(hDlg, OPT_VariantGothic) ? VariantGothic :
776 (IsDlgButtonChecked(hDlg, OPT_VariantCrazyhouse) ? VariantCrazyhouse :
777 (IsDlgButtonChecked(hDlg, OPT_VariantBughouse) ? VariantBughouse :
778 (IsDlgButtonChecked(hDlg, OPT_VariantCourier) ? VariantCourier :
779 (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :
780 (IsDlgButtonChecked(hDlg, OPT_VariantShogi) ? VariantShogi :
781 (IsDlgButtonChecked(hDlg, OPT_VariantXiangqi) ? VariantXiangqi :
782 (IsDlgButtonChecked(hDlg, OPT_VariantCapablanca) ? VariantCapablanca :
783 (IsDlgButtonChecked(hDlg, OPT_VariantTwoKings) ? VariantTwoKings :
784 (IsDlgButtonChecked(hDlg, OPT_VariantKnightmate) ? VariantKnightmate :
785 (IsDlgButtonChecked(hDlg, OPT_VariantLosers) ? VariantLosers :
786 (IsDlgButtonChecked(hDlg, OPT_VariantSuicide) ? VariantSuicide :
787 (IsDlgButtonChecked(hDlg, OPT_VariantAtomic) ? VariantAtomic :
788 (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :
789 (IsDlgButtonChecked(hDlg, OPT_VariantFRC) ? VariantFischeRandom :
790 (IsDlgButtonChecked(hDlg, OPT_VariantCylinder) ? VariantCylinder :
791 (IsDlgButtonChecked(hDlg, OPT_VariantFalcon) ? VariantFalcon :
792 (IsDlgButtonChecked(hDlg, OPT_VariantCRC) ? VariantCapaRandom :
793 (IsDlgButtonChecked(hDlg, OPT_VariantSuper) ? VariantSuper :
794 (IsDlgButtonChecked(hDlg, OPT_VariantBerolina) ? VariantBerolina :
795 (IsDlgButtonChecked(hDlg, OPT_VariantJanus) ? VariantJanus :
796 (IsDlgButtonChecked(hDlg, OPT_VariantWildcastle) ? VariantWildCastle :
797 (IsDlgButtonChecked(hDlg, OPT_VariantNocastle) ? VariantNoCastle :
798 (IsDlgButtonChecked(hDlg, OPT_Variant3Check) ? Variant3Check :
799 (IsDlgButtonChecked(hDlg, OPT_VariantGreat) ? VariantGreat :
800 (IsDlgButtonChecked(hDlg, OPT_VariantGiveaway) ? VariantGiveaway :
801 (IsDlgButtonChecked(hDlg, OPT_VariantTwilight) ? VariantTwilight :
802 VariantNormal ))))))))))))))))))))))))))));
806 NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
808 static VariantClass v;
809 static int n1_ok, n2_ok, n3_ok;
812 case WM_INITDIALOG: /* message: initialize dialog box */
813 /* Center the dialog over the application window */
814 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
815 /* Initialize the dialog items */
816 switch (gameInfo.variant) {
818 CheckDlgButton(hDlg, OPT_VariantNormal, TRUE);
820 case VariantCrazyhouse:
821 CheckDlgButton(hDlg, OPT_VariantCrazyhouse, TRUE);
823 case VariantBughouse:
824 CheckDlgButton(hDlg, OPT_VariantBughouse, TRUE);
827 CheckDlgButton(hDlg, OPT_VariantShogi, TRUE);
830 CheckDlgButton(hDlg, OPT_VariantXiangqi, TRUE);
832 case VariantCapablanca:
833 CheckDlgButton(hDlg, OPT_VariantCapablanca, TRUE);
836 CheckDlgButton(hDlg, OPT_VariantGothic, TRUE);
839 CheckDlgButton(hDlg, OPT_VariantCourier, TRUE);
841 case VariantKnightmate:
842 CheckDlgButton(hDlg, OPT_VariantKnightmate, TRUE);
844 case VariantTwoKings:
845 CheckDlgButton(hDlg, OPT_VariantTwoKings, TRUE);
848 CheckDlgButton(hDlg, OPT_VariantFairy, TRUE);
851 CheckDlgButton(hDlg, OPT_VariantAtomic, TRUE);
854 CheckDlgButton(hDlg, OPT_VariantSuicide, TRUE);
857 CheckDlgButton(hDlg, OPT_VariantLosers, TRUE);
859 case VariantShatranj:
860 CheckDlgButton(hDlg, OPT_VariantShatranj, TRUE);
862 case VariantFischeRandom:
863 CheckDlgButton(hDlg, OPT_VariantFRC, TRUE);
865 case VariantCapaRandom:
866 CheckDlgButton(hDlg, OPT_VariantCRC, TRUE);
869 CheckDlgButton(hDlg, OPT_VariantFalcon, TRUE);
871 case VariantCylinder:
872 CheckDlgButton(hDlg, OPT_VariantCylinder, TRUE);
875 CheckDlgButton(hDlg, OPT_Variant3Check, TRUE);
878 CheckDlgButton(hDlg, OPT_VariantSuper, TRUE);
880 case VariantBerolina:
881 CheckDlgButton(hDlg, OPT_VariantBerolina, TRUE);
884 CheckDlgButton(hDlg, OPT_VariantJanus, TRUE);
886 case VariantWildCastle:
887 CheckDlgButton(hDlg, OPT_VariantWildcastle, TRUE);
889 case VariantNoCastle:
890 CheckDlgButton(hDlg, OPT_VariantNocastle, TRUE);
893 CheckDlgButton(hDlg, OPT_VariantGreat, TRUE);
895 case VariantGiveaway:
896 CheckDlgButton(hDlg, OPT_VariantGiveaway, TRUE);
898 case VariantTwilight:
899 CheckDlgButton(hDlg, OPT_VariantTwilight, TRUE);
904 SetDlgItemInt( hDlg, IDC_Files, -1, TRUE );
905 SendDlgItemMessage( hDlg, IDC_Files, EM_SETSEL, 0, -1 );
907 SetDlgItemInt( hDlg, IDC_Ranks, -1, TRUE );
908 SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );
910 SetDlgItemInt( hDlg, IDC_Holdings, -1, TRUE );
911 SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );
913 n1_ok = n2_ok = n3_ok = FALSE;
917 case WM_COMMAND: /* message: received a command */
918 switch (LOWORD(wParam)) {
921 * if we call EndDialog() after the call to ChangeBoardSize(),
922 * then ChangeBoardSize() does not take effect, although the new
923 * boardSize is saved. Go figure...
925 EndDialog(hDlg, TRUE);
927 v = VariantWhichRadio(hDlg);
928 if(!appData.noChessProgram) { char *name = VariantName(v), buf[MSG_SIZ];
929 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
930 /* [HGM] in protocol 2 we check if variant is suported by engine */
931 sprintf(buf, "Variant %s not supported by %s", name, first.tidy);
932 DisplayError(buf, 0);
933 return TRUE; /* treat as "Cancel" if first engine does not support it */
935 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
936 sprintf(buf, "Warning: second engine (%s) does not support this!", second.tidy);
937 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
941 gameInfo.variant = v;
942 appData.variant = VariantName(v);
944 appData.NrFiles = (int) GetDlgItemInt(hDlg, IDC_Files, NULL, FALSE );
945 appData.NrRanks = (int) GetDlgItemInt(hDlg, IDC_Ranks, NULL, FALSE );
946 appData.holdingsSize = (int) GetDlgItemInt(hDlg, IDC_Holdings, NULL, FALSE );
948 if(!n1_ok) appData.NrFiles = -1;
949 if(!n2_ok) appData.NrRanks = -1;
950 if(!n3_ok) appData.holdingsSize = -1;
952 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
953 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
954 appData.pieceToCharTable = NULL;
960 EndDialog(hDlg, FALSE);
966 if( HIWORD(wParam) == EN_CHANGE ) {
968 GetDlgItemInt(hDlg, IDC_Files, &n1_ok, FALSE );
969 GetDlgItemInt(hDlg, IDC_Ranks, &n2_ok, FALSE );
970 GetDlgItemInt(hDlg, IDC_Holdings, &n3_ok, FALSE );
972 /*EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok ? TRUE : FALSE );*/
983 NewVariantPopup(HWND hwnd)
985 FARPROC lpProc = MakeProcInstance((FARPROC)NewVariantDialog, hInst);
986 DialogBox(hInst, MAKEINTRESOURCE(DLG_NewVariant), hwnd,
988 FreeProcInstance(lpProc);
991 /*---------------------------------------------------------------------------*\
993 * ICS Options Dialog functions
995 \*---------------------------------------------------------------------------*/
998 MyCreateFont(HWND hwnd, MyFont *font)
1003 /* Initialize members of the CHOOSEFONT structure. */
1004 cf.lStructSize = sizeof(CHOOSEFONT);
1005 cf.hwndOwner = hwnd;
1007 cf.lpLogFont = &font->lf;
1009 cf.Flags = CF_SCREENFONTS|/*CF_ANSIONLY|*/CF_INITTOLOGFONTSTRUCT;
1010 cf.rgbColors = RGB(0,0,0);
1012 cf.lpfnHook = (LPCFHOOKPROC)NULL;
1013 cf.lpTemplateName = (LPSTR)NULL;
1014 cf.hInstance = (HINSTANCE) NULL;
1015 cf.lpszStyle = (LPSTR)NULL;
1016 cf.nFontType = SCREEN_FONTTYPE;
1020 /* Display the CHOOSEFONT common-dialog box. */
1021 if (!ChooseFont(&cf)) {
1025 /* Create a logical font based on the user's */
1026 /* selection and return a handle identifying */
1028 hf = CreateFontIndirect(cf.lpLogFont);
1034 font->mfp.pointSize = (float) (cf.iPointSize / 10.0);
1035 font->mfp.bold = (font->lf.lfWeight >= FW_BOLD);
1036 font->mfp.italic = font->lf.lfItalic;
1037 font->mfp.underline = font->lf.lfUnderline;
1038 font->mfp.strikeout = font->lf.lfStrikeOut;
1039 strcpy(font->mfp.faceName, font->lf.lfFaceName);
1045 UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca)
1048 cf.cbSize = sizeof(CHARFORMAT);
1050 CFM_COLOR|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE;
1051 cf.crTextColor = mca->color;
1052 cf.dwEffects = mca->effects;
1053 strcpy(cf.szFaceName, font[boardSize][CONSOLE_FONT]->mfp.faceName);
1055 * The 20.0 below is in fact documented. yHeight is expressed in twips.
1056 * A twip is 1/20 of a font's point size. See documentation of CHARFORMAT.
1059 cf.yHeight = (int)(font[boardSize][CONSOLE_FONT]->mfp.pointSize * 20.0 + 0.5);
1060 cf.bCharSet = DEFAULT_CHARSET; /* should be ignored anyway */
1061 cf.bPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
1062 SendDlgItemMessage(hDlg, id, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1066 ColorizeTextDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1068 static MyColorizeAttribs mca;
1069 static ColorClass cc;
1070 COLORREF background = (COLORREF)0;
1074 cc = (ColorClass)lParam;
1075 mca = colorizeAttribs[cc];
1076 /* Center the dialog over the application window */
1077 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1078 /* Initialize the dialog items */
1079 CheckDlgButton(hDlg, OPT_Bold, (mca.effects & CFE_BOLD) != 0);
1080 CheckDlgButton(hDlg, OPT_Italic, (mca.effects & CFE_ITALIC) != 0);
1081 CheckDlgButton(hDlg, OPT_Underline, (mca.effects & CFE_UNDERLINE) != 0);
1082 CheckDlgButton(hDlg, OPT_Strikeout, (mca.effects & CFE_STRIKEOUT) != 0);
1084 /* get the current background color from the parent window */
1085 SendMessage(GetWindow(hDlg, GW_OWNER),WM_COMMAND,
1086 (WPARAM)WM_USER_GetConsoleBackground,
1087 (LPARAM)&background);
1089 /* set the background color */
1090 SendDlgItemMessage(hDlg, OPT_Sample, EM_SETBKGNDCOLOR, FALSE, background);
1092 SetDlgItemText(hDlg, OPT_Sample, mca.name);
1093 UpdateSampleText(hDlg, OPT_Sample, &mca);
1096 case WM_COMMAND: /* message: received a command */
1097 switch (LOWORD(wParam)) {
1099 /* Read changed options from the dialog box */
1100 colorizeAttribs[cc] = mca;
1101 textAttribs[cc].color = mca.color;
1102 textAttribs[cc].effects = mca.effects;
1103 Colorize(currentColorClass, TRUE);
1104 if (cc == ColorNormal) {
1106 cf.cbSize = sizeof(CHARFORMAT);
1107 cf.dwMask = CFM_COLOR;
1108 cf.crTextColor = mca.color;
1109 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1110 EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1112 EndDialog(hDlg, TRUE);
1116 EndDialog(hDlg, FALSE);
1119 case OPT_ChooseColor:
1120 ChangeColor(hDlg, &mca.color);
1121 UpdateSampleText(hDlg, OPT_Sample, &mca);
1126 (IsDlgButtonChecked(hDlg, OPT_Bold) ? CFE_BOLD : 0) |
1127 (IsDlgButtonChecked(hDlg, OPT_Italic) ? CFE_ITALIC : 0) |
1128 (IsDlgButtonChecked(hDlg, OPT_Underline) ? CFE_UNDERLINE : 0) |
1129 (IsDlgButtonChecked(hDlg, OPT_Strikeout) ? CFE_STRIKEOUT : 0);
1130 UpdateSampleText(hDlg, OPT_Sample, &mca);
1139 ColorizeTextPopup(HWND hwnd, ColorClass cc)
1143 lpProc = MakeProcInstance((FARPROC)ColorizeTextDialog, hInst);
1144 DialogBoxParam(hInst, MAKEINTRESOURCE(DLG_Colorize),
1145 hwnd, (DLGPROC)lpProc, (LPARAM) cc);
1146 FreeProcInstance(lpProc);
1150 SetIcsOptionEnables(HWND hDlg)
1152 #define ENABLE_DLG_ITEM(x,y) EnableWindow(GetDlgItem(hDlg,(x)), (y))
1154 UINT state = IsDlgButtonChecked(hDlg, OPT_Premove);
1155 ENABLE_DLG_ITEM(OPT_PremoveWhite, state);
1156 ENABLE_DLG_ITEM(OPT_PremoveWhiteText, state);
1157 ENABLE_DLG_ITEM(OPT_PremoveBlack, state);
1158 ENABLE_DLG_ITEM(OPT_PremoveBlackText, state);
1160 ENABLE_DLG_ITEM(OPT_IcsAlarmTime, IsDlgButtonChecked(hDlg, OPT_IcsAlarm));
1162 #undef ENABLE_DLG_ITEM
1167 IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1172 static COLORREF cbc;
1173 static MyColorizeAttribs *mca;
1177 case WM_INITDIALOG: /* message: initialize dialog box */
1179 mca = colorizeAttribs;
1181 for (i=0; i < NColorClasses - 1; i++) {
1182 mca[i].color = textAttribs[i].color;
1183 mca[i].effects = textAttribs[i].effects;
1185 cbc = consoleBackgroundColor;
1187 /* Center the dialog over the application window */
1188 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1190 /* Initialize the dialog items */
1191 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
1193 CHECK_BOX(OPT_AutoComment, appData.autoComment);
1194 CHECK_BOX(OPT_AutoObserve, appData.autoObserve);
1195 CHECK_BOX(OPT_GetMoveList, appData.getMoveList);
1196 CHECK_BOX(OPT_LocalLineEditing, appData.localLineEditing);
1197 CHECK_BOX(OPT_QuietPlay, appData.quietPlay);
1198 CHECK_BOX(OPT_Premove, appData.premove);
1199 CHECK_BOX(OPT_PremoveWhite, appData.premoveWhite);
1200 CHECK_BOX(OPT_PremoveBlack, appData.premoveBlack);
1201 CHECK_BOX(OPT_IcsAlarm, appData.icsAlarm);
1202 CHECK_BOX(OPT_DontColorize, !appData.colorize);
1206 sprintf(buf, "%d", appData.icsAlarmTime / 1000);
1207 SetDlgItemText(hDlg, OPT_IcsAlarmTime, buf);
1208 SetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText);
1209 SetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText);
1211 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1212 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1213 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1214 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1215 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1216 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1217 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1218 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1219 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1220 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1222 SetDlgItemText(hDlg, OPT_SampleShout, mca[ColorShout].name);
1223 SetDlgItemText(hDlg, OPT_SampleSShout, mca[ColorSShout].name);
1224 SetDlgItemText(hDlg, OPT_SampleChannel1, mca[ColorChannel1].name);
1225 SetDlgItemText(hDlg, OPT_SampleChannel, mca[ColorChannel].name);
1226 SetDlgItemText(hDlg, OPT_SampleKibitz, mca[ColorKibitz].name);
1227 SetDlgItemText(hDlg, OPT_SampleTell, mca[ColorTell].name);
1228 SetDlgItemText(hDlg, OPT_SampleChallenge, mca[ColorChallenge].name);
1229 SetDlgItemText(hDlg, OPT_SampleRequest, mca[ColorRequest].name);
1230 SetDlgItemText(hDlg, OPT_SampleSeek, mca[ColorSeek].name);
1231 SetDlgItemText(hDlg, OPT_SampleNormal, mca[ColorNormal].name);
1233 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1234 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1235 UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]);
1236 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1237 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1238 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1239 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1240 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1241 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1242 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1244 SetIcsOptionEnables(hDlg);
1247 case WM_COMMAND: /* message: received a command */
1248 switch (LOWORD(wParam)) {
1250 case WM_USER_GetConsoleBackground:
1251 /* the ColorizeTextDialog needs the current background color */
1252 colorref = (COLORREF *)lParam;
1257 /* Read changed options from the dialog box */
1258 GetDlgItemText(hDlg, OPT_IcsAlarmTime, buf, MSG_SIZ);
1259 if (sscanf(buf, "%d", &number) != 1 || (number < 0)){
1260 MessageBox(hDlg, "Invalid ICS Alarm Time",
1261 "Option Error", MB_OK|MB_ICONEXCLAMATION);
1265 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
1267 appData.icsAlarm = IS_CHECKED(OPT_IcsAlarm);
1268 appData.premove = IS_CHECKED(OPT_Premove);
1269 appData.premoveWhite = IS_CHECKED(OPT_PremoveWhite);
1270 appData.premoveBlack = IS_CHECKED(OPT_PremoveBlack);
1271 appData.autoComment = IS_CHECKED(OPT_AutoComment);
1272 appData.autoObserve = IS_CHECKED(OPT_AutoObserve);
1273 appData.getMoveList = IS_CHECKED(OPT_GetMoveList);
1274 appData.localLineEditing = IS_CHECKED(OPT_LocalLineEditing);
1275 appData.quietPlay = IS_CHECKED(OPT_QuietPlay);
1279 appData.icsAlarmTime = number * 1000;
1280 GetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText, 5);
1281 GetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText, 5);
1283 if (appData.localLineEditing) {
1292 (Boolean)!IsDlgButtonChecked(hDlg, OPT_DontColorize);
1294 if (!appData.colorize) {
1296 COLORREF background = ParseColorName(COLOR_BKGD);
1298 SetDefaultTextAttribs();
1299 Colorize(currentColorClass);
1301 cf.cbSize = sizeof(CHARFORMAT);
1302 cf.dwMask = CFM_COLOR;
1303 cf.crTextColor = ParseColorName(COLOR_NORMAL);
1305 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1306 EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1307 SendDlgItemMessage(hwndConsole, OPT_ConsoleText,
1308 EM_SETBKGNDCOLOR, FALSE, background);
1309 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1310 EM_SETBKGNDCOLOR, FALSE, background);
1313 if (cbc != consoleBackgroundColor) {
1314 consoleBackgroundColor = cbc;
1315 if (appData.colorize) {
1316 SendDlgItemMessage(hwndConsole, OPT_ConsoleText,
1317 EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);
1318 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1319 EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);
1323 for (i=0; i < NColorClasses - 1; i++) {
1324 textAttribs[i].color = mca[i].color;
1325 textAttribs[i].effects = mca[i].effects;
1328 EndDialog(hDlg, TRUE);
1332 EndDialog(hDlg, FALSE);
1335 case OPT_ChooseShoutColor:
1336 ColorizeTextPopup(hDlg, ColorShout);
1337 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1340 case OPT_ChooseSShoutColor:
1341 ColorizeTextPopup(hDlg, ColorSShout);
1342 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1345 case OPT_ChooseChannel1Color:
1346 ColorizeTextPopup(hDlg, ColorChannel1);
1347 UpdateSampleText(hDlg, OPT_SampleChannel1,
1348 &colorizeAttribs[ColorChannel1]);
1351 case OPT_ChooseChannelColor:
1352 ColorizeTextPopup(hDlg, ColorChannel);
1353 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1356 case OPT_ChooseKibitzColor:
1357 ColorizeTextPopup(hDlg, ColorKibitz);
1358 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1361 case OPT_ChooseTellColor:
1362 ColorizeTextPopup(hDlg, ColorTell);
1363 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1366 case OPT_ChooseChallengeColor:
1367 ColorizeTextPopup(hDlg, ColorChallenge);
1368 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1371 case OPT_ChooseRequestColor:
1372 ColorizeTextPopup(hDlg, ColorRequest);
1373 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1376 case OPT_ChooseSeekColor:
1377 ColorizeTextPopup(hDlg, ColorSeek);
1378 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1381 case OPT_ChooseNormalColor:
1382 ColorizeTextPopup(hDlg, ColorNormal);
1383 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1386 case OPT_ChooseBackgroundColor:
1387 if (ChangeColor(hDlg, &cbc)) {
1388 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1389 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1390 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1391 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1392 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1393 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1394 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1395 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1396 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1397 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1401 case OPT_DefaultColors:
1402 for (i=0; i < NColorClasses - 1; i++)
1403 ParseAttribs(&mca[i].color,
1405 defaultTextAttribs[i]);
1407 cbc = ParseColorName(COLOR_BKGD);
1408 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1409 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1410 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1411 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1412 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1413 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1414 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1415 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1416 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1417 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1419 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1420 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1421 UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]);
1422 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1423 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1424 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1425 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1426 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1427 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1428 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1432 SetIcsOptionEnables(hDlg);
1441 IcsOptionsPopup(HWND hwnd)
1443 FARPROC lpProc = MakeProcInstance((FARPROC)IcsOptionsDialog, hInst);
1444 DialogBox(hInst, MAKEINTRESOURCE(DLG_IcsOptions), hwnd,
1446 FreeProcInstance(lpProc);
1449 /*---------------------------------------------------------------------------*\
1451 * Fonts Dialog functions
1453 \*---------------------------------------------------------------------------*/
1456 SetSampleFontText(HWND hwnd, int id, const MyFont *mf)
1463 RECT rectClient, rectFormat;
1468 len = sprintf(buf, "%.0f pt. %s%s%s\n",
1469 mf->mfp.pointSize, mf->mfp.faceName,
1470 mf->mfp.bold ? " bold" : "",
1471 mf->mfp.italic ? " italic" : "");
1472 SetDlgItemText(hwnd, id, buf);
1474 hControl = GetDlgItem(hwnd, id);
1475 hdc = GetDC(hControl);
1476 SetMapMode(hdc, MM_TEXT); /* 1 pixel == 1 logical unit */
1477 oldFont = SelectObject(hdc, mf->hf);
1479 /* get number of logical units necessary to display font name */
1480 GetTextExtentPoint32(hdc, buf, len, &size);
1482 /* calculate formatting rectangle in the rich edit control.
1483 * May be larger or smaller than the actual control.
1485 GetClientRect(hControl, &rectClient);
1486 center.x = (rectClient.left + rectClient.right) / 2;
1487 center.y = (rectClient.top + rectClient.bottom) / 2;
1488 rectFormat.top = center.y - (size.cy / 2) - 1;
1489 rectFormat.bottom = center.y + (size.cy / 2) + 1;
1490 rectFormat.left = center.x - (size.cx / 2) - 1;
1491 rectFormat.right = center.x + (size.cx / 2) + 1;
1494 fprintf(debugFP, "\nfont: %s\n"
1495 "center.x %d, centerY %d\n"
1496 "size.cx %d, size.cy %d\n"
1497 "client.top %d, bottom %d, left %d, right %d\n"
1498 "format.top %d, bottom %d, left %d, right %d\n",
1502 rectClient.top, rectClient.bottom, rectClient.left,
1504 rectFormat.top, rectFormat.bottom, rectFormat.left,
1508 cf.cbSize = sizeof(CHARFORMAT);
1509 cf.dwMask = CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_BOLD|CFM_ITALIC;
1511 if (mf->lf.lfWeight == FW_BOLD) cf.dwEffects |= CFE_BOLD;
1512 if (mf->lf.lfItalic) cf.dwEffects |= CFE_ITALIC;
1513 strcpy(cf.szFaceName, mf->mfp.faceName);
1515 * yHeight is expressed in twips. A twip is 1/20 of a font's point
1516 * size. See documentation of CHARFORMAT. --msw
1518 cf.yHeight = (int)(mf->mfp.pointSize * 20.0 + 0.5);
1519 cf.bCharSet = mf->lf.lfCharSet;
1520 cf.bPitchAndFamily = mf->lf.lfPitchAndFamily;
1522 /* format the text in the rich edit control */
1523 SendMessage(hControl, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf);
1524 SendMessage(hControl, EM_SETRECT, (WPARAM)0, (LPARAM) &rectFormat);
1527 SelectObject(hdc, oldFont);
1528 ReleaseDC(hControl, hdc);
1532 CopyFont(MyFont *dest, const MyFont *src)
1534 dest->mfp.pointSize = src->mfp.pointSize;
1535 dest->mfp.bold = src->mfp.bold;
1536 dest->mfp.italic = src->mfp.italic;
1537 dest->mfp.underline = src->mfp.underline;
1538 dest->mfp.strikeout = src->mfp.strikeout;
1539 lstrcpy(dest->mfp.faceName, src->mfp.faceName);
1540 CreateFontInMF(dest);
1545 FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1547 static MyFont workFont[NUM_FONTS];
1548 static BOOL firstPaint;
1555 /* copy the current font settings into a working copy */
1556 for (i=0; i < NUM_FONTS; i++)
1557 CopyFont(&workFont[i], font[boardSize][i]);
1559 if (!appData.icsActive)
1560 EnableWindow(GetDlgItem(hDlg, OPT_ChooseConsoleFont), FALSE);
1562 firstPaint = TRUE; /* see rant below */
1564 /* If I don't call SetFocus(), the dialog won't respond to the keyboard
1565 * when first drawn. Why is this the only dialog that behaves this way? Is
1566 * is the WM_PAINT stuff below?? Sigh...
1568 SetFocus(GetDlgItem(hDlg, IDOK));
1572 /* This should not be necessary. However, if SetSampleFontText() is called
1573 * in response to WM_INITDIALOG, the strings are not properly centered in
1574 * the controls when the dialog first appears. I can't figure out why, so
1575 * this is the workaround. --msw
1578 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1579 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1580 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1581 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1582 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1583 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1584 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1589 case WM_COMMAND: /* message: received a command */
1590 switch (LOWORD(wParam)) {
1593 /* again, it seems to avoid redraw problems if we call EndDialog first */
1594 EndDialog(hDlg, FALSE);
1596 /* copy modified settings back to the fonts array */
1597 for (i=0; i < NUM_FONTS; i++)
1598 CopyFont(font[boardSize][i], &workFont[i]);
1600 /* a sad necessity due to the original design of having a separate
1601 * console font, tags font, and comment font for each board size. IMHO
1602 * these fonts should not be dependent on the current board size. I'm
1603 * running out of time, so I am doing this hack rather than redesign the
1604 * data structure. Besides, I think if I redesigned the data structure, I
1605 * might break backwards compatibility with old winboard.ini files.
1608 for (i=0; i < NUM_SIZES; i++) {
1609 CopyFont(font[i][EDITTAGS_FONT], &workFont[EDITTAGS_FONT]);
1610 CopyFont(font[i][CONSOLE_FONT], &workFont[CONSOLE_FONT]);
1611 CopyFont(font[i][COMMENT_FONT], &workFont[COMMENT_FONT]);
1612 CopyFont(font[i][MOVEHISTORY_FONT], &workFont[MOVEHISTORY_FONT]);
1614 /* end sad necessity */
1616 InitDrawingSizes(boardSize, 0);
1617 InvalidateRect(hwndMain, NULL, TRUE);
1619 if (commentDialog) {
1620 SendDlgItemMessage(commentDialog, OPT_CommentText,
1621 WM_SETFONT, (WPARAM)font[boardSize][COMMENT_FONT]->hf,
1622 MAKELPARAM(TRUE, 0));
1623 GetClientRect(GetDlgItem(commentDialog, OPT_CommentText), &rect);
1624 InvalidateRect(commentDialog, &rect, TRUE);
1627 if (editTagsDialog) {
1628 SendDlgItemMessage(editTagsDialog, OPT_TagsText,
1629 WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf,
1630 MAKELPARAM(TRUE, 0));
1631 GetClientRect(GetDlgItem(editTagsDialog, OPT_TagsText), &rect);
1632 InvalidateRect(editTagsDialog, &rect, TRUE);
1635 if( moveHistoryDialog != NULL ) {
1636 SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory,
1637 WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,
1638 MAKELPARAM(TRUE, 0));
1639 SendMessage( moveHistoryDialog, WM_INITDIALOG, 0, 0 );
1640 // InvalidateRect(editTagsDialog, NULL, TRUE); // [HGM] this ws improperly cloned?
1643 if( engineOutputDialog != NULL ) {
1644 SendDlgItemMessage(engineOutputDialog, IDC_EngineMemo1,
1645 WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,
1646 MAKELPARAM(TRUE, 0));
1647 SendDlgItemMessage(engineOutputDialog, IDC_EngineMemo2,
1648 WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,
1649 MAKELPARAM(TRUE, 0));
1653 ChangedConsoleFont();
1656 for (i=0; i<NUM_FONTS; i++)
1657 DeleteObject(&workFont[i].hf);
1662 for (i=0; i<NUM_FONTS; i++)
1663 DeleteObject(&workFont[i].hf);
1664 EndDialog(hDlg, FALSE);
1667 case OPT_ChooseClockFont:
1668 MyCreateFont(hDlg, &workFont[CLOCK_FONT]);
1669 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1672 case OPT_ChooseMessageFont:
1673 MyCreateFont(hDlg, &workFont[MESSAGE_FONT]);
1674 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1677 case OPT_ChooseCoordFont:
1678 MyCreateFont(hDlg, &workFont[COORD_FONT]);
1679 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1682 case OPT_ChooseTagFont:
1683 MyCreateFont(hDlg, &workFont[EDITTAGS_FONT]);
1684 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1687 case OPT_ChooseCommentsFont:
1688 MyCreateFont(hDlg, &workFont[COMMENT_FONT]);
1689 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1692 case OPT_ChooseConsoleFont:
1693 MyCreateFont(hDlg, &workFont[CONSOLE_FONT]);
1694 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1697 case OPT_ChooseMoveHistoryFont:
1698 MyCreateFont(hDlg, &workFont[MOVEHISTORY_FONT]);
1699 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1702 case OPT_DefaultFonts:
1703 for (i=0; i<NUM_FONTS; i++) {
1704 DeleteObject(&workFont[i].hf);
1705 ParseFontName(font[boardSize][i]->def, &workFont[i].mfp);
1706 CreateFontInMF(&workFont[i]);
1708 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1709 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1710 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1711 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1712 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1713 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1714 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1722 FontsOptionsPopup(HWND hwnd)
1724 FARPROC lpProc = MakeProcInstance((FARPROC)FontOptionsDialog, hInst);
1725 DialogBox(hInst, MAKEINTRESOURCE(DLG_Fonts), hwnd,
1727 FreeProcInstance(lpProc);
1730 /*---------------------------------------------------------------------------*\
1732 * Sounds Dialog functions
1734 \*---------------------------------------------------------------------------*/
1737 SoundComboData soundComboData[] = {
1740 {"ICS Alarm", NULL},
1744 {"ICS Unfinished", NULL},
1746 {"SShout/CShout", NULL},
1747 {"Channel 1", NULL},
1751 {"Challenge", NULL},
1759 InitSoundComboData(SoundComboData *scd)
1765 /* copy current sound settings to combo array */
1767 for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) {
1768 scd[sc].name = strdup(sounds[sc].name);
1770 for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) {
1771 index = (int)cc + (int)NSoundClasses;
1772 scd[index].name = strdup(textAttribs[cc].sound.name);
1778 ResetSoundComboData(SoundComboData *scd)
1780 while (scd->label) {
1781 if (scd->name != NULL) {
1790 InitSoundCombo(HWND hwndCombo, SoundComboData *scd)
1795 SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
1797 /* send the labels to the combo box */
1798 while (scd->label) {
1799 err = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) scd->label);
1801 sprintf(buf, "InitSoundCombo(): err '%d', cnt '%d'\n",
1802 (int)err, (int)cnt);
1803 MessageBox(NULL, buf, NULL, MB_OK);
1807 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) 0, (LPARAM) 0);
1811 SoundDialogWhichRadio(HWND hDlg)
1813 if (IsDlgButtonChecked(hDlg, OPT_NoSound)) return OPT_NoSound;
1814 if (IsDlgButtonChecked(hDlg, OPT_DefaultBeep)) return OPT_DefaultBeep;
1815 if (IsDlgButtonChecked(hDlg, OPT_BuiltInSound)) return OPT_BuiltInSound;
1816 if (IsDlgButtonChecked(hDlg, OPT_WavFile)) return OPT_WavFile;
1821 SoundDialogSetEnables(HWND hDlg, int radio)
1823 EnableWindow(GetDlgItem(hDlg, OPT_BuiltInSoundName),
1824 radio == OPT_BuiltInSound);
1825 EnableWindow(GetDlgItem(hDlg, OPT_WavFileName), radio == OPT_WavFile);
1826 EnableWindow(GetDlgItem(hDlg, OPT_BrowseSound), radio == OPT_WavFile);
1830 SoundDialogGetName(HWND hDlg, int radio)
1832 static char buf[MSG_SIZ], buf2[MSG_SIZ], buf3[MSG_SIZ];
1838 case OPT_DefaultBeep:
1840 case OPT_BuiltInSound:
1842 GetDlgItemText(hDlg, OPT_BuiltInSoundName, buf + 1, sizeof(buf) - 1);
1845 GetDlgItemText(hDlg, OPT_WavFileName, buf, sizeof(buf));
1846 GetCurrentDirectory(MSG_SIZ, buf3);
1847 SetCurrentDirectory(installDir);
1848 if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {
1853 SetCurrentDirectory(buf3);
1859 DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name)
1863 * I think it's best to clear the combo and edit boxes. It looks stupid
1864 * to have a value from another sound event sitting there grayed out.
1866 SetDlgItemText(hDlg, OPT_WavFileName, "");
1867 SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
1869 if (appData.debugMode)
1870 fprintf(debugFP, "DisplaySelectedSound(,,'%s'):\n", name);
1873 radio = OPT_NoSound;
1876 if (name[1] == NULLCHAR) {
1877 radio = OPT_DefaultBeep;
1879 radio = OPT_WavFile;
1880 SetDlgItemText(hDlg, OPT_WavFileName, name);
1884 if (name[1] == NULLCHAR) {
1885 radio = OPT_NoSound;
1887 radio = OPT_BuiltInSound;
1888 if (SendMessage(hCombo, CB_SELECTSTRING, (WPARAM) -1,
1889 (LPARAM) (name + 1)) == CB_ERR) {
1890 SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
1891 SendMessage(hCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) (name + 1));
1896 radio = OPT_WavFile;
1897 SetDlgItemText(hDlg, OPT_WavFileName, name);
1900 SoundDialogSetEnables(hDlg, radio);
1901 CheckRadioButton(hDlg, OPT_NoSound, OPT_WavFile, radio);
1905 char *builtInSoundNames[] = BUILT_IN_SOUND_NAMES;
1908 SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1910 static HWND hSoundCombo;
1920 SoundComboData *scd;
1924 /* Center the dialog over the application window */
1925 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1927 /* Initialize the built-in sounds combo */
1928 hBISN = GetDlgItem(hDlg, OPT_BuiltInSoundName);
1929 InitComboStrings(hBISN, builtInSoundNames);
1931 /* Initialize the sound events combo */
1933 InitSoundComboData(soundComboData);
1934 hSoundCombo = GetDlgItem(hDlg, CBO_Sounds);
1935 InitSoundCombo(hSoundCombo, soundComboData);
1937 /* update the dialog */
1938 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
1941 case WM_COMMAND: /* message: received a command */
1943 if (((HWND)lParam == hSoundCombo) &&
1944 (HIWORD(wParam) == CBN_SELCHANGE)) {
1946 * the user has selected a new sound event. We must store the name for
1947 * the previously selected event, then retrieve the name for the
1948 * newly selected event and update the dialog.
1950 radio = SoundDialogWhichRadio(hDlg);
1951 newName = strdup(SoundDialogGetName(hDlg, radio));
1953 if (strcmp(newName, soundComboData[index].name) != 0) {
1954 free(soundComboData[index].name);
1955 soundComboData[index].name = newName;
1960 /* now get the settings for the newly selected event */
1961 index = SendMessage(hSoundCombo, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
1962 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
1966 switch (LOWORD(wParam)) {
1969 * save the name for the currently selected sound event
1971 radio = SoundDialogWhichRadio(hDlg);
1972 newName = strdup(SoundDialogGetName(hDlg, radio));
1974 if (strcmp(soundComboData[index].name, newName) != 0) {
1975 free(soundComboData[index].name);
1976 soundComboData[index].name = newName;
1982 /* save all the sound names that changed and load the sounds */
1984 for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) {
1985 if (strcmp(soundComboData[sc].name, sounds[sc].name) != 0) {
1986 free(sounds[sc].name);
1987 sounds[sc].name = strdup(soundComboData[sc].name);
1988 MyLoadSound(&sounds[sc]);
1991 for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) {
1992 index = (int)cc + (int)NSoundClasses;
1993 if (strcmp(soundComboData[index].name,
1994 textAttribs[cc].sound.name) != 0) {
1995 free(textAttribs[cc].sound.name);
1996 textAttribs[cc].sound.name = strdup(soundComboData[index].name);
1997 MyLoadSound(&textAttribs[cc].sound);
2001 ResetSoundComboData(soundComboData);
2002 EndDialog(hDlg, TRUE);
2006 ResetSoundComboData(soundComboData);
2007 EndDialog(hDlg, FALSE);
2010 case OPT_DefaultSounds:
2011 /* can't use SetDefaultSounds() because we need to be able to "undo" if
2012 * user selects "Cancel" later on. So we do it the hard way here.
2014 scd = &soundComboData[0];
2015 while (scd->label != NULL) {
2016 if (scd->name != NULL) free(scd->name);
2017 scd->name = strdup("");
2020 free(soundComboData[(int)SoundBell].name);
2021 soundComboData[(int)SoundBell].name = strdup(SOUND_BELL);
2022 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
2026 radio = SoundDialogWhichRadio(hDlg);
2027 tmp.name = strdup(SoundDialogGetName(hDlg, radio));
2031 if (tmp.data != NULL) FreeResource(tmp.data); // technically obsolete fn, but tmp.data is NOT malloc'd mem
2032 if (tmp.name != NULL) free(tmp.name);
2035 case OPT_BrowseSound:
2036 f = OpenFileDialog(hDlg, "rb", NULL, "wav", SOUND_FILT,
2037 "Browse for Sound File", NULL, NULL, buf);
2040 SetDlgItemText(hDlg, OPT_WavFileName, buf);
2045 radio = SoundDialogWhichRadio(hDlg);
2046 SoundDialogSetEnables(hDlg, radio);
2055 VOID SoundOptionsPopup(HWND hwnd)
2059 lpProc = MakeProcInstance((FARPROC)SoundOptionsDialog, hInst);
2060 DialogBox(hInst, MAKEINTRESOURCE(DLG_Sound), hwnd, (DLGPROC)lpProc);
2061 FreeProcInstance(lpProc);
2065 /*---------------------------------------------------------------------------*\
2067 * Comm Port dialog functions
2069 \*---------------------------------------------------------------------------*/
2079 ComboData cdPort[] = { {"None", PORT_NONE}, {"COM1", 1}, {"COM2", 2},
2080 {"COM3", 3}, {"COM4", 4}, {NULL, 0} };
2081 ComboData cdDataRate[] = { {"110", 110}, {"300", 300}, {"600", 600}, {"1200", 1200},
2082 {"2400", 2400}, {"4800", 4800}, {"9600", 9600}, {"19200", 19200},
2083 {"38400", 38400}, {NULL, 0} };
2084 ComboData cdDataBits[] = { {"5", 5}, {"6", 6}, {"7", 7}, {"8", 8}, {NULL, 0} };
2085 ComboData cdParity[] = { {"None", NOPARITY}, {"Odd", ODDPARITY}, {"Even", EVENPARITY},
2086 {"Mark", MARKPARITY}, {"Space", SPACEPARITY}, {NULL, 0} };
2087 ComboData cdStopBits[] = { {"1", ONESTOPBIT}, {"1.5", ONE5STOPBITS},
2088 {"2", TWOSTOPBITS}, {NULL, 0} };
2089 ComboData cdFlow[] = { {"None", FLOW_NONE}, {"Xoff/Xon", FLOW_XOFF}, {"CTS", FLOW_CTS},
2090 {"DSR", FLOW_DSR}, {NULL, 0} };
2094 ParseCommSettings(char *arg, DCB *dcb)
2096 int dataRate, count;
2097 char bits[MSG_SIZ], parity[MSG_SIZ], stopBits[MSG_SIZ], flow[MSG_SIZ];
2099 count = sscanf(arg, "%d%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]",
2100 &dataRate, bits, parity, stopBits, flow);
2101 if (count != 5) goto cant_parse;
2102 dcb->BaudRate = dataRate;
2104 while (cd->label != NULL) {
2105 if (StrCaseCmp(cd->label, bits) == 0) {
2106 dcb->ByteSize = cd->value;
2111 if (cd->label == NULL) goto cant_parse;
2113 while (cd->label != NULL) {
2114 if (StrCaseCmp(cd->label, parity) == 0) {
2115 dcb->Parity = cd->value;
2120 if (cd->label == NULL) goto cant_parse;
2122 while (cd->label != NULL) {
2123 if (StrCaseCmp(cd->label, stopBits) == 0) {
2124 dcb->StopBits = cd->value;
2130 if (cd->label == NULL) goto cant_parse;
2131 while (cd->label != NULL) {
2132 if (StrCaseCmp(cd->label, flow) == 0) {
2133 switch (cd->value) {
2136 dcb->fOutxCtsFlow = FALSE;
2137 dcb->fOutxDsrFlow = FALSE;
2141 dcb->fOutxCtsFlow = TRUE;
2142 dcb->fOutxDsrFlow = FALSE;
2146 dcb->fOutxCtsFlow = FALSE;
2147 dcb->fOutxDsrFlow = TRUE;
2151 dcb->fOutxCtsFlow = FALSE;
2152 dcb->fOutxDsrFlow = FALSE;
2159 if (cd->label == NULL) goto cant_parse;
2162 ExitArgError("Can't parse com port settings", arg);
2166 VOID PrintCommSettings(FILE *f, char *name, DCB *dcb)
2168 char *flow = "??", *parity = "??", *stopBits = "??";
2172 while (cd->label != NULL) {
2173 if (dcb->Parity == cd->value) {
2180 while (cd->label != NULL) {
2181 if (dcb->StopBits == cd->value) {
2182 stopBits = cd->label;
2188 flow = cdFlow[FLOW_XOFF].label;
2189 } else if (dcb->fOutxCtsFlow) {
2190 flow = cdFlow[FLOW_CTS].label;
2191 } else if (dcb->fOutxDsrFlow) {
2192 flow = cdFlow[FLOW_DSR].label;
2194 flow = cdFlow[FLOW_NONE].label;
2196 fprintf(f, "/%s=%d,%d,%s,%s,%s\n", name,
2197 (int)dcb->BaudRate, dcb->ByteSize, parity, stopBits, flow);
2202 InitCombo(HANDLE hwndCombo, ComboData *cd)
2204 SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
2206 while (cd->label != NULL) {
2207 SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) cd->label);
2213 SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value)
2218 while (cd->label != NULL) {
2219 if (cd->value == value) {
2220 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) i, (LPARAM) 0);
2229 CommPortOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2239 case WM_INITDIALOG: /* message: initialize dialog box */
2240 /* Center the dialog over the application window */
2241 CenterWindow (hDlg, GetWindow(hDlg, GW_OWNER));
2242 /* Initialize the dialog items */
2243 /* !! There should probably be some synchronization
2244 in accessing hCommPort and dcb. Or does modal nature
2245 of this dialog box do it for us?
2247 hwndCombo = GetDlgItem(hDlg, OPT_Port);
2248 InitCombo(hwndCombo, cdPort);
2249 p = strrchr(appData.icsCommPort, '\\');
2250 if (p++ == NULL) p = appData.icsCommPort;
2252 (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) p) == CB_ERR)) {
2253 SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) "None");
2255 EnableWindow(hwndCombo, hCommPort == NULL); /*!! don't allow change for now*/
2257 hwndCombo = GetDlgItem(hDlg, OPT_DataRate);
2258 InitCombo(hwndCombo, cdDataRate);
2259 sprintf(buf, "%u", (int)dcb.BaudRate);
2260 if (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) buf) == CB_ERR) {
2261 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
2262 SendMessage(hwndCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) buf);
2265 hwndCombo = GetDlgItem(hDlg, OPT_Bits);
2266 InitCombo(hwndCombo, cdDataBits);
2267 SelectComboValue(hwndCombo, cdDataBits, dcb.ByteSize);
2269 hwndCombo = GetDlgItem(hDlg, OPT_Parity);
2270 InitCombo(hwndCombo, cdParity);
2271 SelectComboValue(hwndCombo, cdParity, dcb.Parity);
2273 hwndCombo = GetDlgItem(hDlg, OPT_StopBits);
2274 InitCombo(hwndCombo, cdStopBits);
2275 SelectComboValue(hwndCombo, cdStopBits, dcb.StopBits);
2277 hwndCombo = GetDlgItem(hDlg, OPT_Flow);
2278 InitCombo(hwndCombo, cdFlow);
2280 SelectComboValue(hwndCombo, cdFlow, FLOW_XOFF);
2281 } else if (dcb.fOutxCtsFlow) {
2282 SelectComboValue(hwndCombo, cdFlow, FLOW_CTS);
2283 } else if (dcb.fOutxDsrFlow) {
2284 SelectComboValue(hwndCombo, cdFlow, FLOW_DSR);
2286 SelectComboValue(hwndCombo, cdFlow, FLOW_NONE);
2290 case WM_COMMAND: /* message: received a command */
2291 switch (LOWORD(wParam)) {
2293 /* Read changed options from the dialog box */
2295 /* !! Currently we can't change comm ports in midstream */
2296 hwndCombo = GetDlgItem(hDlg, OPT_Port);
2297 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2298 if (index == PORT_NONE) {
2299 appData.icsCommPort = "";
2300 if (hCommPort != NULL) {
2301 CloseHandle(hCommPort);
2304 EndDialog(hDlg, TRUE);
2307 SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf);
2308 appData.icsCommPort = strdup(buf);
2309 if (hCommPort != NULL) {
2310 CloseHandle(hCommPort);
2313 /* now what?? can't really do this; have to fix up the ChildProc
2314 and InputSource records for the comm port that we gave to the
2318 hwndCombo = GetDlgItem(hDlg, OPT_DataRate);
2319 SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf);
2320 if (sscanf(buf, "%u", &value) != 1) {
2321 MessageBox(hDlg, "Invalid data rate",
2322 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2325 dcb.BaudRate = value;
2327 hwndCombo = GetDlgItem(hDlg, OPT_Bits);
2328 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2329 dcb.ByteSize = cdDataBits[index].value;
2331 hwndCombo = GetDlgItem(hDlg, OPT_Parity);
2332 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2333 dcb.Parity = cdParity[index].value;
2335 hwndCombo = GetDlgItem(hDlg, OPT_StopBits);
2336 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2337 dcb.StopBits = cdStopBits[index].value;
2339 hwndCombo = GetDlgItem(hDlg, OPT_Flow);
2340 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2341 switch (cdFlow[index].value) {
2344 dcb.fOutxCtsFlow = FALSE;
2345 dcb.fOutxDsrFlow = FALSE;
2349 dcb.fOutxCtsFlow = TRUE;
2350 dcb.fOutxDsrFlow = FALSE;
2354 dcb.fOutxCtsFlow = FALSE;
2355 dcb.fOutxDsrFlow = TRUE;
2359 dcb.fOutxCtsFlow = FALSE;
2360 dcb.fOutxDsrFlow = FALSE;
2363 if (!SetCommState(hCommPort, (LPDCB) &dcb)) {
2364 err = GetLastError();
2365 switch(MessageBox(hDlg,
2366 "Failed to set comm port state;\r\ninvalid options?",
2367 "Option Error", MB_ABORTRETRYIGNORE|MB_ICONQUESTION)) {
2369 DisplayFatalError("Failed to set comm port state", err, 1);
2370 exit(1); /*is it ok to do this from here?*/
2376 EndDialog(hDlg, TRUE);
2381 EndDialog(hDlg, TRUE);
2385 EndDialog(hDlg, FALSE);
2397 CommPortOptionsPopup(HWND hwnd)
2399 FARPROC lpProc = MakeProcInstance((FARPROC)CommPortOptionsDialog, hInst);
2400 DialogBox(hInst, MAKEINTRESOURCE(DLG_CommPort), hwnd, (DLGPROC) lpProc);
2401 FreeProcInstance(lpProc);
2404 /*---------------------------------------------------------------------------*\
2406 * Load Options dialog functions
2408 \*---------------------------------------------------------------------------*/
2411 SetLoadOptionEnables(HWND hDlg)
2415 state = IsDlgButtonChecked(hDlg, OPT_Autostep);
2416 EnableWindow(GetDlgItem(hDlg, OPT_ASTimeDelay), state);
2417 EnableWindow(GetDlgItem(hDlg, OPT_AStext1), state);
2421 LoadOptions(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2427 case WM_INITDIALOG: /* message: initialize dialog box */
2428 /* Center the dialog over the application window */
2429 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2430 /* Initialize the dialog items */
2431 if (appData.timeDelay >= 0.0) {
2432 CheckDlgButton(hDlg, OPT_Autostep, TRUE);
2433 sprintf(buf, "%.2g", appData.timeDelay);
2434 SetDlgItemText(hDlg, OPT_ASTimeDelay, buf);
2436 CheckDlgButton(hDlg, OPT_Autostep, FALSE);
2438 SetLoadOptionEnables(hDlg);
2441 case WM_COMMAND: /* message: received a command */
2442 switch (LOWORD(wParam)) {
2444 /* Read changed options from the dialog box */
2445 if (IsDlgButtonChecked(hDlg, OPT_Autostep)) {
2446 GetDlgItemText(hDlg, OPT_ASTimeDelay, buf, MSG_SIZ);
2447 if (sscanf(buf, "%f", &fnumber) != 1) {
2448 MessageBox(hDlg, "Invalid load game step rate",
2449 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2452 appData.timeDelay = fnumber;
2454 appData.timeDelay = (float) -1.0;
2456 EndDialog(hDlg, TRUE);
2460 EndDialog(hDlg, FALSE);
2464 SetLoadOptionEnables(hDlg);
2474 LoadOptionsPopup(HWND hwnd)
2476 FARPROC lpProc = MakeProcInstance((FARPROC)LoadOptions, hInst);
2477 DialogBox(hInst, MAKEINTRESOURCE(DLG_LoadOptions), hwnd, (DLGPROC) lpProc);
2478 FreeProcInstance(lpProc);
2481 /*---------------------------------------------------------------------------*\
2483 * Save Options dialog functions
2485 \*---------------------------------------------------------------------------*/
2488 SetSaveOptionEnables(HWND hDlg)
2492 state = IsDlgButtonChecked(hDlg, OPT_Autosave);
2493 EnableWindow(GetDlgItem(hDlg, OPT_AVPrompt), state);
2494 EnableWindow(GetDlgItem(hDlg, OPT_AVToFile), state);
2495 if (state && !IsDlgButtonChecked(hDlg, OPT_AVPrompt) &&
2496 !IsDlgButtonChecked(hDlg, OPT_AVToFile)) {
2497 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt);
2500 state = state && IsDlgButtonChecked(hDlg, OPT_AVToFile);
2501 EnableWindow(GetDlgItem(hDlg, OPT_AVFilename), state);
2502 EnableWindow(GetDlgItem(hDlg, OPT_AVBrowse), state);
2506 SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2512 case WM_INITDIALOG: /* message: initialize dialog box */
2513 /* Center the dialog over the application window */
2514 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2515 /* Initialize the dialog items */
2516 if (*appData.saveGameFile != NULLCHAR) {
2517 CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE);
2518 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVToFile);
2519 SetDlgItemText(hDlg, OPT_AVFilename, appData.saveGameFile);
2520 } else if (appData.autoSaveGames) {
2521 CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE);
2522 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt);
2524 CheckDlgButton(hDlg, OPT_Autosave, (UINT) FALSE);
2526 if (appData.oldSaveStyle) {
2527 CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_Old);
2529 CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_PGN);
2531 CheckDlgButton( hDlg, OPT_OutOfBookInfo, appData.saveOutOfBookInfo );
2532 SetSaveOptionEnables(hDlg);
2535 case WM_COMMAND: /* message: received a command */
2536 switch (LOWORD(wParam)) {
2538 /* Read changed options from the dialog box */
2539 if (IsDlgButtonChecked(hDlg, OPT_Autosave)) {
2540 appData.autoSaveGames = TRUE;
2541 if (IsDlgButtonChecked(hDlg, OPT_AVPrompt)) {
2542 appData.saveGameFile = "";
2543 } else /*if (IsDlgButtonChecked(hDlg, OPT_AVToFile))*/ {
2544 GetDlgItemText(hDlg, OPT_AVFilename, buf, MSG_SIZ);
2545 if (*buf == NULLCHAR) {
2546 MessageBox(hDlg, "Invalid save game file name",
2547 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2550 if ((isalpha(buf[0]) && buf[1] == ':') ||
2551 (buf[0] == '\\' && buf[1] == '\\')) {
2552 appData.saveGameFile = strdup(buf);
2554 char buf2[MSG_SIZ], buf3[MSG_SIZ];
2556 GetCurrentDirectory(MSG_SIZ, buf3);
2557 SetCurrentDirectory(installDir);
2558 if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {
2559 appData.saveGameFile = strdup(buf2);
2561 appData.saveGameFile = strdup(buf);
2563 SetCurrentDirectory(buf3);
2567 appData.autoSaveGames = FALSE;
2568 appData.saveGameFile = "";
2570 appData.oldSaveStyle = IsDlgButtonChecked(hDlg, OPT_Old);
2571 appData.saveOutOfBookInfo = IsDlgButtonChecked( hDlg, OPT_OutOfBookInfo );
2572 EndDialog(hDlg, TRUE);
2576 EndDialog(hDlg, FALSE);
2580 f = OpenFileDialog(hDlg, "a", NULL,
2581 appData.oldSaveStyle ? "gam" : "pgn",
2582 GAME_FILT, "Browse for Auto Save File",
2586 SetDlgItemText(hDlg, OPT_AVFilename, buf);
2591 SetSaveOptionEnables(hDlg);
2600 SaveOptionsPopup(HWND hwnd)
2602 FARPROC lpProc = MakeProcInstance((FARPROC)SaveOptionsDialog, hInst);
2603 DialogBox(hInst, MAKEINTRESOURCE(DLG_SaveOptions), hwnd, (DLGPROC) lpProc);
2604 FreeProcInstance(lpProc);
2607 /*---------------------------------------------------------------------------*\
2609 * Time Control Options dialog functions
2611 \*---------------------------------------------------------------------------*/
2614 SetTimeControlEnables(HWND hDlg)
2618 state = IsDlgButtonChecked(hDlg, OPT_TCUseMoves);
2619 EnableWindow(GetDlgItem(hDlg, OPT_TCTime), state);
2620 EnableWindow(GetDlgItem(hDlg, OPT_TCMoves), state);
2621 EnableWindow(GetDlgItem(hDlg, OPT_TCtext1), state);
2622 EnableWindow(GetDlgItem(hDlg, OPT_TCtext2), state);
2623 EnableWindow(GetDlgItem(hDlg, OPT_TCTime2), !state);
2624 EnableWindow(GetDlgItem(hDlg, OPT_TCInc), !state);
2625 EnableWindow(GetDlgItem(hDlg, OPT_TCitext1), !state);
2626 EnableWindow(GetDlgItem(hDlg, OPT_TCitext2), !state);
2627 EnableWindow(GetDlgItem(hDlg, OPT_TCitext3), !state);
2632 TimeControl(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2635 int mps, increment, odds1, odds2;
2639 case WM_INITDIALOG: /* message: initialize dialog box */
2640 /* Center the dialog over the application window */
2641 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2642 /* Initialize the dialog items */
2643 if (appData.clockMode && !appData.icsActive) {
2644 if (appData.timeIncrement == -1) {
2645 CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,
2647 SetDlgItemText(hDlg, OPT_TCTime, appData.timeControl);
2648 SetDlgItemInt(hDlg, OPT_TCMoves, appData.movesPerSession,
2650 SetDlgItemText(hDlg, OPT_TCTime2, "");
2651 SetDlgItemText(hDlg, OPT_TCInc, "");
2653 CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,
2655 SetDlgItemText(hDlg, OPT_TCTime, "");
2656 SetDlgItemText(hDlg, OPT_TCMoves, "");
2657 SetDlgItemText(hDlg, OPT_TCTime2, appData.timeControl);
2658 SetDlgItemInt(hDlg, OPT_TCInc, appData.timeIncrement, FALSE);
2660 SetDlgItemInt(hDlg, OPT_TCOdds1, 1, FALSE);
2661 SetDlgItemInt(hDlg, OPT_TCOdds2, 1, FALSE);
2662 SetTimeControlEnables(hDlg);
2666 case WM_COMMAND: /* message: received a command */
2667 switch (LOWORD(wParam)) {
2669 /* Read changed options from the dialog box */
2670 if (IsDlgButtonChecked(hDlg, OPT_TCUseMoves)) {
2672 mps = GetDlgItemInt(hDlg, OPT_TCMoves, &ok, FALSE);
2673 if (!ok || mps <= 0) {
2674 MessageBox(hDlg, "Invalid moves per time control",
2675 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2678 GetDlgItemText(hDlg, OPT_TCTime, buf, MSG_SIZ);
2679 if (!ParseTimeControl(buf, increment, mps)) {
2680 MessageBox(hDlg, "Invalid minutes per time control",
2681 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2685 increment = GetDlgItemInt(hDlg, OPT_TCInc, &ok, FALSE);
2686 mps = appData.movesPerSession;
2687 if (!ok || increment < 0) {
2688 MessageBox(hDlg, "Invalid increment",
2689 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2692 GetDlgItemText(hDlg, OPT_TCTime2, buf, MSG_SIZ);
2693 if (!ParseTimeControl(buf, increment, mps)) {
2694 MessageBox(hDlg, "Invalid initial time",
2695 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2699 odds1 = GetDlgItemInt(hDlg, OPT_TCOdds1, &ok, FALSE);
2700 odds2 = GetDlgItemInt(hDlg, OPT_TCOdds2, &ok2, FALSE);
2701 if (!ok || !ok2 || odds1 <= 0 || odds2 <= 0) {
2702 MessageBox(hDlg, "Invalid time-odds factor",
2703 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2706 appData.timeControl = strdup(buf);
2707 appData.movesPerSession = mps;
2708 appData.timeIncrement = increment;
2709 appData.firstTimeOdds = first.timeOdds = odds1;
2710 appData.secondTimeOdds = second.timeOdds = odds2;
2712 EndDialog(hDlg, TRUE);
2716 EndDialog(hDlg, FALSE);
2720 SetTimeControlEnables(hDlg);
2729 TimeControlOptionsPopup(HWND hwnd)
2731 if (gameMode != BeginningOfGame) {
2732 DisplayError("Changing time control during a game is not implemented", 0);
2734 FARPROC lpProc = MakeProcInstance((FARPROC)TimeControl, hInst);
2735 DialogBox(hInst, MAKEINTRESOURCE(DLG_TimeControl), hwnd, (DLGPROC) lpProc);
2736 FreeProcInstance(lpProc);
2740 /*---------------------------------------------------------------------------*\
2742 * Engine Options Dialog functions
2744 \*---------------------------------------------------------------------------*/
2745 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
2746 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
2748 #define INT_ABS( n ) ((n) >= 0 ? (n) : -(n))
2750 LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2753 case WM_INITDIALOG: /* message: initialize dialog box */
2755 /* Center the dialog over the application window */
2756 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2758 /* Initialize the dialog items */
2759 CHECK_BOX(IDC_EpPeriodicUpdates, appData.periodicUpdates);
2760 CHECK_BOX(IDC_EpPonder, appData.ponderNextMove);
2761 CHECK_BOX(IDC_EpShowThinking, appData.showThinking);
2762 CHECK_BOX(IDC_EpHideThinkingHuman, appData.hideThinkingFromHuman);
2764 CHECK_BOX(IDC_TestClaims, appData.testClaims);
2765 CHECK_BOX(IDC_DetectMates, appData.checkMates);
2766 CHECK_BOX(IDC_MaterialDraws, appData.materialDraws);
2767 CHECK_BOX(IDC_TrivialDraws, appData.trivialDraws);
2769 CHECK_BOX(IDC_ScoreAbs1, appData.firstScoreIsAbsolute);
2770 CHECK_BOX(IDC_ScoreAbs2, appData.secondScoreIsAbsolute);
2772 SetDlgItemInt( hDlg, IDC_EpDrawMoveCount, appData.adjudicateDrawMoves, TRUE );
2773 SendDlgItemMessage( hDlg, IDC_EpDrawMoveCount, EM_SETSEL, 0, -1 );
2775 SetDlgItemInt( hDlg, IDC_EpAdjudicationThreshold, INT_ABS(appData.adjudicateLossThreshold), TRUE );
2776 SendDlgItemMessage( hDlg, IDC_EpAdjudicationThreshold, EM_SETSEL, 0, -1 );
2778 SetDlgItemInt( hDlg, IDC_RuleMoves, appData.ruleMoves, TRUE );
2779 SendDlgItemMessage( hDlg, IDC_RuleMoves, EM_SETSEL, 0, -1 );
2781 SetDlgItemInt( hDlg, IDC_DrawRepeats, INT_ABS(appData.drawRepeats), TRUE );
2782 SendDlgItemMessage( hDlg, IDC_DrawRepeats, EM_SETSEL, 0, -1 );
2786 case WM_COMMAND: /* message: received a command */
2787 switch (LOWORD(wParam)) {
2789 /* Read changed options from the dialog box */
2790 PeriodicUpdatesEvent( IS_CHECKED(IDC_EpPeriodicUpdates));
2791 PonderNextMoveEvent( IS_CHECKED(IDC_EpPonder));
2792 appData.hideThinkingFromHuman= IS_CHECKED(IDC_EpHideThinkingHuman); // [HGM] thinking: moved up
2794 ShowThinkingEvent( IS_CHECKED(IDC_EpShowThinking));
2796 appData.showThinking = IS_CHECKED(IDC_EpShowThinking);
2797 ShowThinkingEvent(); // [HGM] thinking: tests all options that need thinking output
2799 appData.testClaims = IS_CHECKED(IDC_TestClaims);
2800 appData.checkMates = IS_CHECKED(IDC_DetectMates);
2801 appData.materialDraws = IS_CHECKED(IDC_MaterialDraws);
2802 appData.trivialDraws = IS_CHECKED(IDC_TrivialDraws);
2804 appData.adjudicateDrawMoves = GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, NULL, FALSE );
2805 appData.adjudicateLossThreshold = - (int) GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, NULL, FALSE );
2806 appData.ruleMoves = GetDlgItemInt(hDlg, IDC_RuleMoves, NULL, FALSE );
2807 appData.drawRepeats = (int) GetDlgItemInt(hDlg, IDC_DrawRepeats, NULL, FALSE );
2809 appData.firstScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs1);
2810 appData.secondScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs2);
2812 EndDialog(hDlg, TRUE);
2816 EndDialog(hDlg, FALSE);
2819 case IDC_EpDrawMoveCount:
2820 case IDC_EpAdjudicationThreshold:
2821 case IDC_DrawRepeats:
2823 if( HIWORD(wParam) == EN_CHANGE ) {
2829 GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, &n1_ok, FALSE );
2830 GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, &n2_ok, FALSE );
2831 GetDlgItemInt(hDlg, IDC_RuleMoves, &n3_ok, FALSE );
2832 GetDlgItemInt(hDlg, IDC_DrawRepeats, &n4_ok, FALSE );
2834 EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok && n4_ok ? TRUE : FALSE );
2843 VOID EnginePlayOptionsPopup(HWND hwnd)
2847 lpProc = MakeProcInstance((FARPROC)EnginePlayOptionsDialog, hInst);
2848 DialogBox(hInst, MAKEINTRESOURCE(DLG_EnginePlayOptions), hwnd, (DLGPROC) lpProc);
2849 FreeProcInstance(lpProc);
2852 /*---------------------------------------------------------------------------*\
2854 * UCI Options Dialog functions
2856 \*---------------------------------------------------------------------------*/
2857 static BOOL BrowseForFolder( const char * title, char * path )
2859 BOOL result = FALSE;
2863 ZeroMemory( &bi, sizeof(bi) );
2865 bi.lpszTitle = title == 0 ? "Choose Folder" : title;
2866 bi.ulFlags = BIF_RETURNONLYFSDIRS;
2868 pidl = SHBrowseForFolder( &bi );
2871 IMalloc * imalloc = 0;
2873 if( SHGetPathFromIDList( pidl, path ) ) {
2877 if( SUCCEEDED( SHGetMalloc ( &imalloc ) ) ) {
2878 imalloc->lpVtbl->Free(imalloc,pidl);
2879 imalloc->lpVtbl->Release(imalloc);
2886 LRESULT CALLBACK UciOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2892 case WM_INITDIALOG: /* message: initialize dialog box */
2894 /* Center the dialog over the application window */
2895 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2897 /* Initialize the dialog items */
2898 SetDlgItemText( hDlg, IDC_PolyglotDir, appData.polyglotDir );
2899 SetDlgItemInt( hDlg, IDC_HashSize, appData.defaultHashSize, TRUE );
2900 SetDlgItemText( hDlg, IDC_PathToEGTB, appData.defaultPathEGTB );
2901 SetDlgItemInt( hDlg, IDC_SizeOfEGTB, appData.defaultCacheSizeEGTB, TRUE );
2902 CheckDlgButton( hDlg, IDC_UseBook, (BOOL) appData.usePolyglotBook );
2903 SetDlgItemText( hDlg, IDC_BookFile, appData.polyglotBook );
2904 // [HGM] smp: input field for nr of cores:
2905 SetDlgItemInt( hDlg, IDC_Cores, appData.smpCores, TRUE );
2906 // [HGM] book: tick boxes for own book use
2907 CheckDlgButton( hDlg, IDC_OwnBook1, (BOOL) appData.firstHasOwnBookUCI );
2908 CheckDlgButton( hDlg, IDC_OwnBook2, (BOOL) appData.secondHasOwnBookUCI );
2910 SendDlgItemMessage( hDlg, IDC_PolyglotDir, EM_SETSEL, 0, -1 );
2914 case WM_COMMAND: /* message: received a command */
2915 switch (LOWORD(wParam)) {
2917 GetDlgItemText( hDlg, IDC_PolyglotDir, buf, sizeof(buf) );
2918 appData.polyglotDir = strdup(buf);
2919 appData.defaultHashSize = GetDlgItemInt(hDlg, IDC_HashSize, NULL, FALSE );
2920 appData.defaultCacheSizeEGTB = GetDlgItemInt(hDlg, IDC_SizeOfEGTB, NULL, FALSE );
2921 GetDlgItemText( hDlg, IDC_PathToEGTB, buf, sizeof(buf) );
2922 appData.defaultPathEGTB = strdup(buf);
2923 GetDlgItemText( hDlg, IDC_BookFile, buf, sizeof(buf) );
2924 appData.polyglotBook = strdup(buf);
2925 appData.usePolyglotBook = (Boolean) IsDlgButtonChecked( hDlg, IDC_UseBook );
2926 // [HGM] smp: get nr of cores:
2927 oldCores = appData.smpCores;
2928 appData.smpCores = GetDlgItemInt(hDlg, IDC_Cores, NULL, FALSE );
2929 if(appData.smpCores != oldCores) NewSettingEvent(FALSE, "cores", appData.smpCores);
2930 // [HGM] book: read tick boxes for own book use
2931 appData.firstHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook1 );
2932 appData.secondHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook2 );
2934 if(gameMode == BeginningOfGame) Reset(TRUE, TRUE);
2935 EndDialog(hDlg, TRUE);
2939 EndDialog(hDlg, FALSE);
2942 case IDC_BrowseForBook:
2945 'A','l','l',' ','F','i','l','e','s', 0,
2947 'B','I','N',' ','F','i','l','e','s', 0,
2948 '*','.','b','i','n', 0,
2955 ZeroMemory( &ofn, sizeof(ofn) );
2957 ofn.lStructSize = sizeof(ofn);
2958 ofn.hwndOwner = hDlg;
2959 ofn.hInstance = hInst;
2960 ofn.lpstrFilter = filter;
2961 ofn.lpstrFile = buf;
2962 ofn.nMaxFile = sizeof(buf);
2963 ofn.lpstrTitle = "Choose Book";
2964 ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;
2966 if( GetOpenFileName( &ofn ) ) {
2967 SetDlgItemText( hDlg, IDC_BookFile, buf );
2972 case IDC_BrowseForPolyglotDir:
2973 if( BrowseForFolder( "Choose Polyglot Directory", buf ) ) {
2974 SetDlgItemText( hDlg, IDC_PolyglotDir, buf );
2976 strcat( buf, "\\polyglot.exe" );
2978 if( GetFileAttributes(buf) == 0xFFFFFFFF ) {
2979 MessageBox( hDlg, "Polyglot was not found in the specified folder!", "Warning", MB_OK | MB_ICONWARNING );
2984 case IDC_BrowseForEGTB:
2985 if( BrowseForFolder( "Choose EGTB Directory:", buf ) ) {
2986 SetDlgItemText( hDlg, IDC_PathToEGTB, buf );
2991 case IDC_SizeOfEGTB:
2992 if( HIWORD(wParam) == EN_CHANGE ) {
2996 GetDlgItemInt(hDlg, IDC_HashSize, &n1_ok, FALSE );
2997 GetDlgItemInt(hDlg, IDC_SizeOfEGTB, &n2_ok, FALSE );
2999 EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok ? TRUE : FALSE );
3008 VOID UciOptionsPopup(HWND hwnd)
3012 lpProc = MakeProcInstance((FARPROC)UciOptionsDialog, hInst);
3013 DialogBox(hInst, MAKEINTRESOURCE(DLG_OptionsUCI), hwnd, (DLGPROC) lpProc);
3014 FreeProcInstance(lpProc);