2 * woptions.c -- Options dialog box routines for WinBoard
3 * $Id: woptions.c,v 2.1 2003/10/27 19:21:02 mann Exp $
5 * Copyright 2000,2009 Free Software Foundation, Inc.
7 * ------------------------------------------------------------------------
9 * GNU XBoard is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or (at
12 * your option) any later version.
14 * GNU XBoard is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see http://www.gnu.org/licenses/. *
22 *------------------------------------------------------------------------
23 ** See the file ChangeLog for a revision history. */
27 #include <windows.h> /* required for all Windows applications */
30 #include <shlobj.h> /* [AS] Requires NT 4.0 or Win95 */
38 #include "wedittags.h"
46 /* Imports from winboard.c */
48 extern MyFont *font[NUM_SIZES][NUM_FONTS];
49 extern HINSTANCE hInst; /* current instance */
50 extern HWND hwndMain; /* root window*/
51 extern BOOLEAN alwaysOnTop;
52 extern RECT boardRect;
53 extern COLORREF lightSquareColor, darkSquareColor, whitePieceColor,
54 blackPieceColor, highlightSquareColor, premoveHighlightColor;
56 extern BoardSize boardSize;
57 extern COLORREF consoleBackgroundColor;
58 extern MyColorizeAttribs colorizeAttribs[]; /* do I need the size? */
59 extern MyTextAttribs textAttribs[];
60 extern MySound sounds[];
61 extern ColorClass currentColorClass;
62 extern HWND hwndConsole;
63 extern char *defaultTextAttribs[];
64 extern HWND commentDialog;
65 extern HWND moveHistoryDialog;
66 extern char installDir[];
67 extern HWND hCommPort; /* currently open comm port */
69 extern BOOLEAN chessProgram;
70 extern int startedFromPositionFile; /* [HGM] loadPos */
84 /* module prototypes */
86 LRESULT CALLBACK GeneralOptions(HWND, UINT, WPARAM, LPARAM);
87 LRESULT CALLBACK BoardOptions(HWND, UINT, WPARAM, LPARAM);
88 LRESULT CALLBACK NewVariant(HWND, UINT, WPARAM, LPARAM);
89 LRESULT CALLBACK IcsOptions(HWND, UINT, WPARAM, LPARAM);
90 LRESULT CALLBACK FontOptions(HWND, UINT, WPARAM, LPARAM);
91 LRESULT CALLBACK CommPortOptions(HWND, UINT, WPARAM, LPARAM);
92 LRESULT CALLBACK LoadOptions(HWND, UINT, WPARAM, LPARAM);
93 LRESULT CALLBACK SaveOptions(HWND, UINT, WPARAM, LPARAM);
94 LRESULT CALLBACK TimeControl(HWND, UINT, WPARAM, LPARAM);
95 VOID ChangeBoardSize(BoardSize newSize);
96 VOID PaintSampleSquare(
101 COLORREF squareOutlineColor,
102 COLORREF pieceDetailColor,
107 VOID PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color);
108 VOID SetBoardOptionEnables(HWND hDlg);
109 BoardSize BoardOptionsWhichRadio(HWND hDlg);
110 BOOL APIENTRY MyCreateFont(HWND hwnd, MyFont *font);
111 VOID UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca);
112 LRESULT CALLBACK ColorizeTextDialog(HWND , UINT, WPARAM, LPARAM);
113 VOID ColorizeTextPopup(HWND hwnd, ColorClass cc);
114 VOID SetIcsOptionEnables(HWND hDlg);
115 VOID SetSampleFontText(HWND hwnd, int id, const MyFont *mf);
116 VOID CopyFont(MyFont *dest, const MyFont *src);
117 void InitSoundComboData(SoundComboData *scd);
118 void ResetSoundComboData(SoundComboData *scd);
119 void InitSoundCombo(HWND hwndCombo, SoundComboData *scd);
120 int SoundDialogWhichRadio(HWND hDlg);
121 VOID SoundDialogSetEnables(HWND hDlg, int radio);
122 char * SoundDialogGetName(HWND hDlg, int radio);
123 void DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name);
124 VOID ParseCommSettings(char *arg, DCB *dcb);
125 VOID PrintCommSettings(FILE *f, char *name, DCB *dcb);
126 void InitCombo(HANDLE hwndCombo, ComboData *cd);
127 void SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value);
128 VOID SetLoadOptionEnables(HWND hDlg);
129 VOID SetSaveOptionEnables(HWND hDlg);
130 VOID SetTimeControlEnables(HWND hDlg);
131 void NewSettingEvent(int option, char *command, int value);
133 /*---------------------------------------------------------------------------*\
135 * General Options Dialog functions
137 \*---------------------------------------------------------------------------*/
141 GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
143 static Boolean oldShowCoords;
144 static Boolean oldBlindfold;
145 static Boolean oldShowButtonBar;
148 case WM_INITDIALOG: /* message: initialize dialog box */
149 oldShowCoords = appData.showCoords;
150 oldBlindfold = appData.blindfold;
151 oldShowButtonBar = appData.showButtonBar;
153 /* Center the dialog over the application window */
154 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
156 /* Initialize the dialog items */
157 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
159 CHECK_BOX(OPT_AlwaysOnTop, alwaysOnTop);
160 CHECK_BOX(OPT_AlwaysQueen, appData.alwaysPromoteToQueen);
161 CHECK_BOX(OPT_AnimateDragging, appData.animateDragging);
162 CHECK_BOX(OPT_AnimateMoving, appData.animate);
163 CHECK_BOX(OPT_AutoFlag, appData.autoCallFlag);
164 CHECK_BOX(OPT_AutoFlipView, appData.autoFlipView);
165 CHECK_BOX(OPT_AutoRaiseBoard, appData.autoRaiseBoard);
166 CHECK_BOX(OPT_Blindfold, appData.blindfold);
167 CHECK_BOX(OPT_HighlightDragging, appData.highlightDragging);
168 CHECK_BOX(OPT_HighlightLastMove, appData.highlightLastMove);
169 CHECK_BOX(OPT_PeriodicUpdates, appData.periodicUpdates);
170 CHECK_BOX(OPT_PonderNextMove, appData.ponderNextMove);
171 CHECK_BOX(OPT_PopupExitMessage, appData.popupExitMessage);
172 CHECK_BOX(OPT_PopupMoveErrors, appData.popupMoveErrors);
173 CHECK_BOX(OPT_ShowButtonBar, appData.showButtonBar);
174 CHECK_BOX(OPT_ShowCoordinates, appData.showCoords);
175 CHECK_BOX(OPT_ShowThinking, appData.showThinking);
176 CHECK_BOX(OPT_TestLegality, appData.testLegality);
177 CHECK_BOX(OPT_HideThinkFromHuman, appData.hideThinkingFromHuman);
178 CHECK_BOX(OPT_SaveExtPGN, appData.saveExtendedInfoInPGN);
179 CHECK_BOX(OPT_ExtraInfoInMoveHistory, appData.showEvalInMoveHistory);
180 CHECK_BOX(OPT_HighlightMoveArrow, appData.highlightMoveWithArrow);
184 EnableWindow(GetDlgItem(hDlg, OPT_AutoFlag),
185 appData.icsActive || !appData.noChessProgram);
186 EnableWindow(GetDlgItem(hDlg, OPT_AutoFlipView),
187 appData.icsActive || !appData.noChessProgram);
188 EnableWindow(GetDlgItem(hDlg, OPT_PonderNextMove),
189 !appData.noChessProgram);
190 EnableWindow(GetDlgItem(hDlg, OPT_PeriodicUpdates),
191 !appData.noChessProgram && !appData.icsActive);
192 EnableWindow(GetDlgItem(hDlg, OPT_ShowThinking),
193 !appData.noChessProgram);
197 case WM_COMMAND: /* message: received a command */
198 switch (LOWORD(wParam)) {
200 /* Read changed options from the dialog box */
202 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
204 alwaysOnTop = IS_CHECKED(OPT_AlwaysOnTop);
205 appData.alwaysPromoteToQueen = IS_CHECKED(OPT_AlwaysQueen);
206 appData.animateDragging = IS_CHECKED(OPT_AnimateDragging);
207 appData.animate = IS_CHECKED(OPT_AnimateMoving);
208 appData.autoCallFlag = IS_CHECKED(OPT_AutoFlag);
209 appData.autoFlipView = IS_CHECKED(OPT_AutoFlipView);
210 appData.autoRaiseBoard = IS_CHECKED(OPT_AutoRaiseBoard);
211 appData.blindfold = IS_CHECKED(OPT_Blindfold);
212 appData.highlightDragging = IS_CHECKED(OPT_HighlightDragging);
213 appData.highlightLastMove = IS_CHECKED(OPT_HighlightLastMove);
214 PeriodicUpdatesEvent( IS_CHECKED(OPT_PeriodicUpdates));
215 PonderNextMoveEvent( IS_CHECKED(OPT_PonderNextMove));
216 appData.popupExitMessage = IS_CHECKED(OPT_PopupExitMessage);
217 appData.popupMoveErrors = IS_CHECKED(OPT_PopupMoveErrors);
218 appData.showButtonBar = IS_CHECKED(OPT_ShowButtonBar);
219 appData.showCoords = IS_CHECKED(OPT_ShowCoordinates);
220 // [HGM] thinking: next three moved up
221 appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN);
222 appData.hideThinkingFromHuman= IS_CHECKED(OPT_HideThinkFromHuman);
223 appData.showEvalInMoveHistory= IS_CHECKED(OPT_ExtraInfoInMoveHistory);
225 ShowThinkingEvent( IS_CHECKED(OPT_ShowThinking));
227 appData.showThinking = IS_CHECKED(OPT_ShowThinking);
228 ShowThinkingEvent(); // [HGM] thinking: tests four options
230 appData.testLegality = IS_CHECKED(OPT_TestLegality);
231 appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow);
235 SetWindowPos(hwndMain, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
236 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
239 SetWindowPos(hwndConsole, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
240 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
243 if (!appData.highlightLastMove) {
245 DrawPosition(FALSE, NULL);
248 * for some reason the redraw seems smoother when we invalidate
249 * the board rect after the call to EndDialog()
251 EndDialog(hDlg, TRUE);
253 if (oldShowButtonBar != appData.showButtonBar) {
254 InitDrawingSizes(boardSize, 0);
255 } else if ((oldShowCoords != appData.showCoords) ||
256 (oldBlindfold != appData.blindfold)) {
257 InvalidateRect(hwndMain, &boardRect, FALSE);
263 EndDialog(hDlg, FALSE);
273 GeneralOptionsPopup(HWND hwnd)
277 lpProc = MakeProcInstance((FARPROC)GeneralOptionsDialog, hInst);
278 DialogBox(hInst, MAKEINTRESOURCE(DLG_GeneralOptions), hwnd,
280 FreeProcInstance(lpProc);
282 /*---------------------------------------------------------------------------*\
284 * Board Options Dialog functions
286 \*---------------------------------------------------------------------------*/
288 const int SAMPLE_SQ_SIZE = 54;
291 ChangeBoardSize(BoardSize newSize)
293 if (newSize != boardSize) {
295 InitDrawingSizes(boardSize, 0);
303 COLORREF squareColor,
305 COLORREF squareOutlineColor,
306 COLORREF pieceDetailColor,
313 HBRUSH brushSquareOutline;
315 HBRUSH brushPieceDetail;
316 HBRUSH oldBrushPiece = NULL;
317 HBRUSH oldBrushSquare;
318 HBITMAP oldBitmapMem;
319 HBITMAP oldBitmapTemp;
320 HBITMAP bufferBitmap;
322 HDC hdcScreen, hdcMem, hdcTemp;
324 HWND hCtrl = GetDlgItem(hwnd, ctrlid);
329 const int OUTLINE = 2;
330 const int BORDER = 4;
332 InvalidateRect(hCtrl, NULL, TRUE);
334 GetClientRect(hCtrl, &rect);
335 x = rect.left + (BORDER / 2);
336 y = rect.top + (BORDER / 2);
337 hdcScreen = GetDC(hCtrl);
338 hdcMem = CreateCompatibleDC(hdcScreen);
339 hdcTemp = CreateCompatibleDC(hdcScreen);
341 bufferBitmap = CreateCompatibleBitmap(hdcScreen, rect.right-rect.left+1,
342 rect.bottom-rect.top+1);
343 oldBitmapMem = SelectObject(hdcMem, bufferBitmap);
345 SelectPalette(hdcMem, hPal, FALSE);
347 brushSquare = CreateSolidBrush(squareColor);
348 brushSquareOutline = CreateSolidBrush(squareOutlineColor);
349 brushPiece = CreateSolidBrush(pieceColor);
350 brushPieceDetail = CreateSolidBrush(pieceDetailColor);
353 * first draw the rectangle
355 pen = CreatePen(PS_SOLID, BORDER, squareOutlineColor);
356 oldPen = (HPEN) SelectObject(hdcMem, pen);
357 oldBrushSquare = (HBRUSH)SelectObject(hdcMem, brushSquare);
358 Rectangle(hdcMem, rect.left, rect.top, rect.right, rect.bottom);
364 oldBitmapTemp = SelectObject(hdcTemp, pieces[OUTLINE]);
365 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, hdcTemp, 0, 0,
366 isWhitePiece ? SRCCOPY : NOTSRCCOPY);
367 SelectObject(hdcTemp, oldBitmapTemp);
370 oldBitmapTemp = SelectObject(hdcTemp, pieces[WHITE]);
371 oldBrushPiece = SelectObject(hdcMem, brushPiece);
372 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
373 hdcTemp, 0, 0, 0x00B8074A);
375 /* Use pieceDetailColor for outline of white pieces */
376 SelectObject(hdcTemp, pieces[OUTLINE]);
377 SelectObject(hdcMem, brushPieceDetail);
378 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
379 hdcTemp, 0, 0, 0x00B8074A);
381 /* Use black for outline of white pieces */
382 SelectObject(hdcTemp, pieces[OUTLINE]);
383 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
384 hdcTemp, 0, 0, SRCAND);
388 /* Use pieceDetailColor for details of black pieces */
389 /* Requires filled-in solid bitmaps (BLACK_PIECE class); the
390 WHITE_PIECE ones aren't always the right shape. */
391 oldBitmapTemp = SelectObject(hdcTemp, pieces[BLACK]);
392 oldBrushPiece = SelectObject(hdcMem, brushPieceDetail);
393 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
394 hdcTemp, 0, 0, 0x00B8074A);
395 SelectObject(hdcTemp, pieces[SOLID]);
396 SelectObject(hdcMem, brushPiece);
397 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
398 hdcTemp, 0, 0, 0x00B8074A);
400 /* Use square color for details of black pieces */
401 oldBitmapTemp = SelectObject(hdcTemp, pieces[SOLID]);
402 oldBrushPiece = SelectObject(hdcMem, brushPiece);
403 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
404 hdcTemp, 0, 0, 0x00B8074A);
407 SelectObject(hdcMem, oldBrushPiece);
408 SelectObject(hdcTemp, oldBitmapTemp);
411 * copy the memory dc to the screen
413 SelectObject(hdcMem, bufferBitmap);
414 BitBlt(hdcScreen, rect.left, rect.top,
415 rect.right - rect.left,
416 rect.bottom - rect.top,
417 hdcMem, rect.left, rect.top, SRCCOPY);
418 SelectObject(hdcMem, oldBitmapMem);
422 SelectObject(hdcMem, oldBrushPiece);
423 SelectObject(hdcMem, oldPen);
424 DeleteObject(brushPiece);
425 DeleteObject(brushPieceDetail);
426 DeleteObject(brushSquare);
427 DeleteObject(brushSquareOutline);
431 ReleaseDC(hCtrl, hdcScreen);
436 PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color)
439 HBRUSH brush, oldBrush;
441 HWND hCtrl = GetDlgItem(hwnd, ctrlid);
444 InvalidateRect(hCtrl, NULL, TRUE);
446 GetClientRect(hCtrl, &rect);
447 brush = CreateSolidBrush(color);
448 oldBrush = (HBRUSH)SelectObject(hdc, brush);
449 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
450 SelectObject(hdc, oldBrush);
452 ReleaseDC(hCtrl, hdc);
457 SetBoardOptionEnables(HWND hDlg)
459 if (IsDlgButtonChecked(hDlg, OPT_Monochrome)) {
460 ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_HIDE);
461 ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_HIDE);
462 ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_HIDE);
463 ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_HIDE);
465 EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), FALSE);
466 EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), FALSE);
467 EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), FALSE);
468 EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), FALSE);
470 ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_SHOW);
471 ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_SHOW);
472 ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_SHOW);
473 ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_SHOW);
475 EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), TRUE);
476 EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), TRUE);
477 EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), TRUE);
478 EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), TRUE);
483 BoardOptionsWhichRadio(HWND hDlg)
485 return (IsDlgButtonChecked(hDlg, OPT_SizeTiny) ? SizeTiny :
486 (IsDlgButtonChecked(hDlg, OPT_SizeTeeny) ? SizeTeeny :
487 (IsDlgButtonChecked(hDlg, OPT_SizeDinky) ? SizeDinky :
488 (IsDlgButtonChecked(hDlg, OPT_SizePetite) ? SizePetite :
489 (IsDlgButtonChecked(hDlg, OPT_SizeSlim) ? SizeSlim :
490 (IsDlgButtonChecked(hDlg, OPT_SizeSmall) ? SizeSmall :
491 (IsDlgButtonChecked(hDlg, OPT_SizeMediocre) ? SizeMediocre :
492 (IsDlgButtonChecked(hDlg, OPT_SizeMiddling) ? SizeMiddling :
493 (IsDlgButtonChecked(hDlg, OPT_SizeAverage) ? SizeAverage :
494 (IsDlgButtonChecked(hDlg, OPT_SizeModerate) ? SizeModerate :
495 (IsDlgButtonChecked(hDlg, OPT_SizeMedium) ? SizeMedium :
496 (IsDlgButtonChecked(hDlg, OPT_SizeBulky) ? SizeBulky :
497 (IsDlgButtonChecked(hDlg, OPT_SizeLarge) ? SizeLarge :
498 (IsDlgButtonChecked(hDlg, OPT_SizeBig) ? SizeBig :
499 (IsDlgButtonChecked(hDlg, OPT_SizeHuge) ? SizeHuge :
500 (IsDlgButtonChecked(hDlg, OPT_SizeGiant) ? SizeGiant :
501 (IsDlgButtonChecked(hDlg, OPT_SizeColossal) ? SizeColossal :
502 SizeTitanic )))))))))))))))));
506 BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
508 static Boolean mono, white, flip;
509 static BoardSize size;
510 static COLORREF lsc, dsc, wpc, bpc, hsc, phc;
511 static HBITMAP pieces[3];
514 case WM_INITDIALOG: /* message: initialize dialog box */
515 /* Center the dialog over the application window */
516 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
517 /* Initialize the dialog items */
520 CheckDlgButton(hDlg, OPT_SizeTiny, TRUE);
523 CheckDlgButton(hDlg, OPT_SizeTeeny, TRUE);
526 CheckDlgButton(hDlg, OPT_SizeDinky, TRUE);
529 CheckDlgButton(hDlg, OPT_SizePetite, TRUE);
532 CheckDlgButton(hDlg, OPT_SizeSlim, TRUE);
535 CheckDlgButton(hDlg, OPT_SizeSmall, TRUE);
538 CheckDlgButton(hDlg, OPT_SizeMediocre, TRUE);
541 CheckDlgButton(hDlg, OPT_SizeMiddling, TRUE);
544 CheckDlgButton(hDlg, OPT_SizeAverage, TRUE);
547 CheckDlgButton(hDlg, OPT_SizeModerate, TRUE);
550 CheckDlgButton(hDlg, OPT_SizeMedium, TRUE);
553 CheckDlgButton(hDlg, OPT_SizeBulky, TRUE);
556 CheckDlgButton(hDlg, OPT_SizeLarge, TRUE);
559 CheckDlgButton(hDlg, OPT_SizeBig, TRUE);
562 CheckDlgButton(hDlg, OPT_SizeHuge, TRUE);
565 CheckDlgButton(hDlg, OPT_SizeGiant, TRUE);
568 CheckDlgButton(hDlg, OPT_SizeColossal, TRUE);
571 CheckDlgButton(hDlg, OPT_SizeTitanic, TRUE);
572 default: ; // should not happen, but suppresses warning on pedantic compilers
575 if (appData.monoMode)
576 CheckDlgButton(hDlg, OPT_Monochrome, TRUE);
578 if (appData.allWhite)
579 CheckDlgButton(hDlg, OPT_AllWhite, TRUE);
581 if (appData.upsideDown)
582 CheckDlgButton(hDlg, OPT_UpsideDown, TRUE);
584 pieces[0] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "s");
585 pieces[1] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "w");
586 pieces[2] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "o");
588 lsc = lightSquareColor;
589 dsc = darkSquareColor;
590 wpc = whitePieceColor;
591 bpc = blackPieceColor;
592 hsc = highlightSquareColor;
593 phc = premoveHighlightColor;
594 mono = appData.monoMode;
595 white= appData.allWhite;
596 flip = appData.upsideDown;
599 SetBoardOptionEnables(hDlg);
603 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
604 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
605 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
606 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
607 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
608 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
609 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
611 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
612 FALSE, mono, pieces);
616 case WM_COMMAND: /* message: received a command */
617 switch (LOWORD(wParam)) {
620 * if we call EndDialog() after the call to ChangeBoardSize(),
621 * then ChangeBoardSize() does not take effect, although the new
622 * boardSize is saved. Go figure...
624 EndDialog(hDlg, TRUE);
626 size = BoardOptionsWhichRadio(hDlg);
629 * did any settings change?
631 if (size != boardSize) {
632 ChangeBoardSize(size);
635 if ((mono != appData.monoMode) ||
636 (lsc != lightSquareColor) ||
637 (dsc != darkSquareColor) ||
638 (wpc != whitePieceColor) ||
639 (bpc != blackPieceColor) ||
640 (hsc != highlightSquareColor) ||
641 (flip != appData.upsideDown) ||
642 (white != appData.allWhite) ||
643 (phc != premoveHighlightColor)) {
645 lightSquareColor = lsc;
646 darkSquareColor = dsc;
647 whitePieceColor = wpc;
648 blackPieceColor = bpc;
649 highlightSquareColor = hsc;
650 premoveHighlightColor = phc;
651 appData.monoMode = mono;
652 appData.allWhite = white;
653 appData.upsideDown = flip;
656 InitDrawingSizes(boardSize, 0);
657 InvalidateRect(hwndMain, &boardRect, FALSE);
659 DeleteObject(pieces[0]);
660 DeleteObject(pieces[1]);
661 DeleteObject(pieces[2]);
665 DeleteObject(pieces[0]);
666 DeleteObject(pieces[1]);
667 DeleteObject(pieces[2]);
668 EndDialog(hDlg, FALSE);
671 case OPT_ChooseLightSquareColor:
672 if (ChangeColor(hDlg, &lsc))
673 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
674 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
678 case OPT_ChooseDarkSquareColor:
679 if (ChangeColor(hDlg, &dsc))
680 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
681 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
682 FALSE, mono, pieces);
685 case OPT_ChooseWhitePieceColor:
686 if (ChangeColor(hDlg, &wpc))
687 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
688 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
692 case OPT_ChooseBlackPieceColor:
693 if (ChangeColor(hDlg, &bpc))
694 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
695 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
696 FALSE, mono, pieces);
699 case OPT_ChooseHighlightSquareColor:
700 if (ChangeColor(hDlg, &hsc))
701 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
702 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
706 case OPT_ChoosePremoveHighlightColor:
707 if (ChangeColor(hDlg, &phc))
708 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
709 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
710 FALSE, mono, pieces);
713 case OPT_DefaultBoardColors:
714 lsc = ParseColorName(LIGHT_SQUARE_COLOR);
715 dsc = ParseColorName(DARK_SQUARE_COLOR);
716 wpc = ParseColorName(WHITE_PIECE_COLOR);
717 bpc = ParseColorName(BLACK_PIECE_COLOR);
718 hsc = ParseColorName(HIGHLIGHT_SQUARE_COLOR);
719 phc = ParseColorName(PREMOVE_HIGHLIGHT_COLOR);
723 CheckDlgButton(hDlg, OPT_Monochrome, FALSE);
724 CheckDlgButton(hDlg, OPT_AllWhite, FALSE);
725 CheckDlgButton(hDlg, OPT_UpsideDown, FALSE);
726 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
727 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
728 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
729 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
730 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
731 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
732 SetBoardOptionEnables(hDlg);
733 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
735 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
736 FALSE, mono, pieces);
741 SetBoardOptionEnables(hDlg);
746 SetBoardOptionEnables(hDlg);
751 SetBoardOptionEnables(hDlg);
761 BoardOptionsPopup(HWND hwnd)
763 FARPROC lpProc = MakeProcInstance((FARPROC)BoardOptionsDialog, hInst);
764 DialogBox(hInst, MAKEINTRESOURCE(DLG_BoardOptions), hwnd,
766 FreeProcInstance(lpProc);
770 VariantWhichRadio(HWND hDlg)
772 return (IsDlgButtonChecked(hDlg, OPT_VariantFairy) ? VariantFairy :
773 (IsDlgButtonChecked(hDlg, OPT_VariantGothic) ? VariantGothic :
774 (IsDlgButtonChecked(hDlg, OPT_VariantCrazyhouse) ? VariantCrazyhouse :
775 (IsDlgButtonChecked(hDlg, OPT_VariantBughouse) ? VariantBughouse :
776 (IsDlgButtonChecked(hDlg, OPT_VariantCourier) ? VariantCourier :
777 (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :
778 (IsDlgButtonChecked(hDlg, OPT_VariantShogi) ? VariantShogi :
779 (IsDlgButtonChecked(hDlg, OPT_VariantXiangqi) ? VariantXiangqi :
780 (IsDlgButtonChecked(hDlg, OPT_VariantCapablanca) ? VariantCapablanca :
781 (IsDlgButtonChecked(hDlg, OPT_VariantTwoKings) ? VariantTwoKings :
782 (IsDlgButtonChecked(hDlg, OPT_VariantKnightmate) ? VariantKnightmate :
783 (IsDlgButtonChecked(hDlg, OPT_VariantLosers) ? VariantLosers :
784 (IsDlgButtonChecked(hDlg, OPT_VariantSuicide) ? VariantSuicide :
785 (IsDlgButtonChecked(hDlg, OPT_VariantAtomic) ? VariantAtomic :
786 (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :
787 (IsDlgButtonChecked(hDlg, OPT_VariantFRC) ? VariantFischeRandom :
788 (IsDlgButtonChecked(hDlg, OPT_VariantCylinder) ? VariantCylinder :
789 (IsDlgButtonChecked(hDlg, OPT_VariantFalcon) ? VariantFalcon :
790 (IsDlgButtonChecked(hDlg, OPT_VariantCRC) ? VariantCapaRandom :
791 (IsDlgButtonChecked(hDlg, OPT_VariantSuper) ? VariantSuper :
792 (IsDlgButtonChecked(hDlg, OPT_VariantBerolina) ? VariantBerolina :
793 (IsDlgButtonChecked(hDlg, OPT_VariantJanus) ? VariantJanus :
794 (IsDlgButtonChecked(hDlg, OPT_VariantWildcastle) ? VariantWildCastle :
795 (IsDlgButtonChecked(hDlg, OPT_VariantNocastle) ? VariantNoCastle :
796 VariantNormal ))))))))))))))))))))))));
800 NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
802 static VariantClass v;
803 static int n1_ok, n2_ok, n3_ok;
806 case WM_INITDIALOG: /* message: initialize dialog box */
807 /* Center the dialog over the application window */
808 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
809 /* Initialize the dialog items */
810 switch (gameInfo.variant) {
812 CheckDlgButton(hDlg, OPT_VariantNormal, TRUE);
814 case VariantCrazyhouse:
815 CheckDlgButton(hDlg, OPT_VariantCrazyhouse, TRUE);
817 case VariantBughouse:
818 CheckDlgButton(hDlg, OPT_VariantBughouse, TRUE);
821 CheckDlgButton(hDlg, OPT_VariantShogi, TRUE);
824 CheckDlgButton(hDlg, OPT_VariantXiangqi, TRUE);
826 case VariantCapablanca:
827 CheckDlgButton(hDlg, OPT_VariantCapablanca, TRUE);
830 CheckDlgButton(hDlg, OPT_VariantGothic, TRUE);
833 CheckDlgButton(hDlg, OPT_VariantCourier, TRUE);
835 case VariantKnightmate:
836 CheckDlgButton(hDlg, OPT_VariantKnightmate, TRUE);
838 case VariantTwoKings:
839 CheckDlgButton(hDlg, OPT_VariantTwoKings, TRUE);
842 CheckDlgButton(hDlg, OPT_VariantFairy, TRUE);
845 CheckDlgButton(hDlg, OPT_VariantAtomic, TRUE);
848 CheckDlgButton(hDlg, OPT_VariantSuicide, TRUE);
851 CheckDlgButton(hDlg, OPT_VariantLosers, TRUE);
853 case VariantShatranj:
854 CheckDlgButton(hDlg, OPT_VariantShatranj, TRUE);
856 case VariantFischeRandom:
857 CheckDlgButton(hDlg, OPT_VariantFRC, TRUE);
859 case VariantCapaRandom:
860 CheckDlgButton(hDlg, OPT_VariantCRC, TRUE);
863 CheckDlgButton(hDlg, OPT_VariantFalcon, TRUE);
865 case VariantCylinder:
866 CheckDlgButton(hDlg, OPT_VariantCylinder, TRUE);
870 CheckDlgButton(hDlg, OPT_VariantSuper, TRUE);
872 case VariantBerolina:
873 CheckDlgButton(hDlg, OPT_VariantBerolina, TRUE);
876 CheckDlgButton(hDlg, OPT_VariantJanus, TRUE);
878 case VariantWildCastle:
879 CheckDlgButton(hDlg, OPT_VariantWildcastle, TRUE);
881 case VariantNoCastle:
882 CheckDlgButton(hDlg, OPT_VariantNocastle, TRUE);
884 // case VariantGreat: // Note to self: must still make this button (and GiveAway too).
885 // CheckDlgButton(hDlg, OPT_VariantGreat, TRUE);
890 SetDlgItemInt( hDlg, IDC_Files, -1, TRUE );
891 SendDlgItemMessage( hDlg, IDC_Files, EM_SETSEL, 0, -1 );
893 SetDlgItemInt( hDlg, IDC_Ranks, -1, TRUE );
894 SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );
896 SetDlgItemInt( hDlg, IDC_Holdings, -1, TRUE );
897 SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );
899 n1_ok = n2_ok = n3_ok = FALSE;
903 case WM_COMMAND: /* message: received a command */
904 switch (LOWORD(wParam)) {
907 * if we call EndDialog() after the call to ChangeBoardSize(),
908 * then ChangeBoardSize() does not take effect, although the new
909 * boardSize is saved. Go figure...
911 EndDialog(hDlg, TRUE);
913 v = VariantWhichRadio(hDlg);
914 if(!appData.noChessProgram) { char *name = VariantName(v), buf[MSG_SIZ];
915 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
916 /* [HGM] in protocol 2 we check if variant is suported by engine */
917 sprintf(buf, "Variant %s not supported by %s", name, first.tidy);
918 DisplayError(buf, 0);
919 return TRUE; /* treat as "Cancel" if first engine does not support it */
921 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
922 sprintf(buf, "Warning: second engine (%s) does not support this!", second.tidy);
923 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
927 gameInfo.variant = v;
928 appData.variant = VariantName(v);
930 appData.NrFiles = (int) GetDlgItemInt(hDlg, IDC_Files, NULL, FALSE );
931 appData.NrRanks = (int) GetDlgItemInt(hDlg, IDC_Ranks, NULL, FALSE );
932 appData.holdingsSize = (int) GetDlgItemInt(hDlg, IDC_Holdings, NULL, FALSE );
934 if(!n1_ok) appData.NrFiles = -1;
935 if(!n2_ok) appData.NrRanks = -1;
936 if(!n3_ok) appData.holdingsSize = -1;
938 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
939 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
940 appData.pieceToCharTable = NULL;
946 EndDialog(hDlg, FALSE);
952 if( HIWORD(wParam) == EN_CHANGE ) {
954 GetDlgItemInt(hDlg, IDC_Files, &n1_ok, FALSE );
955 GetDlgItemInt(hDlg, IDC_Ranks, &n2_ok, FALSE );
956 GetDlgItemInt(hDlg, IDC_Holdings, &n3_ok, FALSE );
958 /*EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok ? TRUE : FALSE );*/
969 NewVariantPopup(HWND hwnd)
971 FARPROC lpProc = MakeProcInstance((FARPROC)NewVariantDialog, hInst);
972 DialogBox(hInst, MAKEINTRESOURCE(DLG_NewVariant), hwnd,
974 FreeProcInstance(lpProc);
977 /*---------------------------------------------------------------------------*\
979 * ICS Options Dialog functions
981 \*---------------------------------------------------------------------------*/
984 MyCreateFont(HWND hwnd, MyFont *font)
989 /* Initialize members of the CHOOSEFONT structure. */
990 cf.lStructSize = sizeof(CHOOSEFONT);
993 cf.lpLogFont = &font->lf;
995 cf.Flags = CF_SCREENFONTS|/*CF_ANSIONLY|*/CF_INITTOLOGFONTSTRUCT;
996 cf.rgbColors = RGB(0,0,0);
998 cf.lpfnHook = (LPCFHOOKPROC)NULL;
999 cf.lpTemplateName = (LPSTR)NULL;
1000 cf.hInstance = (HINSTANCE) NULL;
1001 cf.lpszStyle = (LPSTR)NULL;
1002 cf.nFontType = SCREEN_FONTTYPE;
1006 /* Display the CHOOSEFONT common-dialog box. */
1007 if (!ChooseFont(&cf)) {
1011 /* Create a logical font based on the user's */
1012 /* selection and return a handle identifying */
1014 hf = CreateFontIndirect(cf.lpLogFont);
1020 font->mfp.pointSize = (float) (cf.iPointSize / 10.0);
1021 font->mfp.bold = (font->lf.lfWeight >= FW_BOLD);
1022 font->mfp.italic = font->lf.lfItalic;
1023 font->mfp.underline = font->lf.lfUnderline;
1024 font->mfp.strikeout = font->lf.lfStrikeOut;
1025 strcpy(font->mfp.faceName, font->lf.lfFaceName);
1031 UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca)
1034 cf.cbSize = sizeof(CHARFORMAT);
1036 CFM_COLOR|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE;
1037 cf.crTextColor = mca->color;
1038 cf.dwEffects = mca->effects;
1039 strcpy(cf.szFaceName, font[boardSize][CONSOLE_FONT]->mfp.faceName);
1041 * The 20.0 below is in fact documented. yHeight is expressed in twips.
1042 * A twip is 1/20 of a font's point size. See documentation of CHARFORMAT.
1045 cf.yHeight = (int)(font[boardSize][CONSOLE_FONT]->mfp.pointSize * 20.0 + 0.5);
1046 cf.bCharSet = DEFAULT_CHARSET; /* should be ignored anyway */
1047 cf.bPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
1048 SendDlgItemMessage(hDlg, id, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1052 ColorizeTextDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1054 static MyColorizeAttribs mca;
1055 static ColorClass cc;
1056 COLORREF background = (COLORREF)0;
1060 cc = (ColorClass)lParam;
1061 mca = colorizeAttribs[cc];
1062 /* Center the dialog over the application window */
1063 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1064 /* Initialize the dialog items */
1065 CheckDlgButton(hDlg, OPT_Bold, (mca.effects & CFE_BOLD) != 0);
1066 CheckDlgButton(hDlg, OPT_Italic, (mca.effects & CFE_ITALIC) != 0);
1067 CheckDlgButton(hDlg, OPT_Underline, (mca.effects & CFE_UNDERLINE) != 0);
1068 CheckDlgButton(hDlg, OPT_Strikeout, (mca.effects & CFE_STRIKEOUT) != 0);
1070 /* get the current background color from the parent window */
1071 SendMessage(GetWindow(hDlg, GW_OWNER),WM_COMMAND,
1072 (WPARAM)WM_USER_GetConsoleBackground,
1073 (LPARAM)&background);
1075 /* set the background color */
1076 SendDlgItemMessage(hDlg, OPT_Sample, EM_SETBKGNDCOLOR, FALSE, background);
1078 SetDlgItemText(hDlg, OPT_Sample, mca.name);
1079 UpdateSampleText(hDlg, OPT_Sample, &mca);
1082 case WM_COMMAND: /* message: received a command */
1083 switch (LOWORD(wParam)) {
1085 /* Read changed options from the dialog box */
1086 colorizeAttribs[cc] = mca;
1087 textAttribs[cc].color = mca.color;
1088 textAttribs[cc].effects = mca.effects;
1089 Colorize(currentColorClass, TRUE);
1090 if (cc == ColorNormal) {
1092 cf.cbSize = sizeof(CHARFORMAT);
1093 cf.dwMask = CFM_COLOR;
1094 cf.crTextColor = mca.color;
1095 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1096 EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1098 EndDialog(hDlg, TRUE);
1102 EndDialog(hDlg, FALSE);
1105 case OPT_ChooseColor:
1106 ChangeColor(hDlg, &mca.color);
1107 UpdateSampleText(hDlg, OPT_Sample, &mca);
1112 (IsDlgButtonChecked(hDlg, OPT_Bold) ? CFE_BOLD : 0) |
1113 (IsDlgButtonChecked(hDlg, OPT_Italic) ? CFE_ITALIC : 0) |
1114 (IsDlgButtonChecked(hDlg, OPT_Underline) ? CFE_UNDERLINE : 0) |
1115 (IsDlgButtonChecked(hDlg, OPT_Strikeout) ? CFE_STRIKEOUT : 0);
1116 UpdateSampleText(hDlg, OPT_Sample, &mca);
1125 ColorizeTextPopup(HWND hwnd, ColorClass cc)
1129 lpProc = MakeProcInstance((FARPROC)ColorizeTextDialog, hInst);
1130 DialogBoxParam(hInst, MAKEINTRESOURCE(DLG_Colorize),
1131 hwnd, (DLGPROC)lpProc, (LPARAM) cc);
1132 FreeProcInstance(lpProc);
1136 SetIcsOptionEnables(HWND hDlg)
1138 #define ENABLE_DLG_ITEM(x,y) EnableWindow(GetDlgItem(hDlg,(x)), (y))
1140 UINT state = IsDlgButtonChecked(hDlg, OPT_Premove);
1141 ENABLE_DLG_ITEM(OPT_PremoveWhite, state);
1142 ENABLE_DLG_ITEM(OPT_PremoveWhiteText, state);
1143 ENABLE_DLG_ITEM(OPT_PremoveBlack, state);
1144 ENABLE_DLG_ITEM(OPT_PremoveBlackText, state);
1146 ENABLE_DLG_ITEM(OPT_IcsAlarmTime, IsDlgButtonChecked(hDlg, OPT_IcsAlarm));
1148 #undef ENABLE_DLG_ITEM
1153 IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1158 static COLORREF cbc;
1159 static MyColorizeAttribs *mca;
1163 case WM_INITDIALOG: /* message: initialize dialog box */
1165 mca = colorizeAttribs;
1167 for (i=0; i < NColorClasses - 1; i++) {
1168 mca[i].color = textAttribs[i].color;
1169 mca[i].effects = textAttribs[i].effects;
1171 cbc = consoleBackgroundColor;
1173 /* Center the dialog over the application window */
1174 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1176 /* Initialize the dialog items */
1177 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
1179 CHECK_BOX(OPT_AutoComment, appData.autoComment);
1180 CHECK_BOX(OPT_AutoObserve, appData.autoObserve);
1181 CHECK_BOX(OPT_GetMoveList, appData.getMoveList);
1182 CHECK_BOX(OPT_LocalLineEditing, appData.localLineEditing);
1183 CHECK_BOX(OPT_QuietPlay, appData.quietPlay);
1184 CHECK_BOX(OPT_Premove, appData.premove);
1185 CHECK_BOX(OPT_PremoveWhite, appData.premoveWhite);
1186 CHECK_BOX(OPT_PremoveBlack, appData.premoveBlack);
1187 CHECK_BOX(OPT_IcsAlarm, appData.icsAlarm);
1188 CHECK_BOX(OPT_DontColorize, !appData.colorize);
1192 sprintf(buf, "%d", appData.icsAlarmTime / 1000);
1193 SetDlgItemText(hDlg, OPT_IcsAlarmTime, buf);
1194 SetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText);
1195 SetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText);
1197 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1198 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1199 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1200 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1201 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1202 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1203 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1204 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1205 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1206 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1208 SetDlgItemText(hDlg, OPT_SampleShout, mca[ColorShout].name);
1209 SetDlgItemText(hDlg, OPT_SampleSShout, mca[ColorSShout].name);
1210 SetDlgItemText(hDlg, OPT_SampleChannel1, mca[ColorChannel1].name);
1211 SetDlgItemText(hDlg, OPT_SampleChannel, mca[ColorChannel].name);
1212 SetDlgItemText(hDlg, OPT_SampleKibitz, mca[ColorKibitz].name);
1213 SetDlgItemText(hDlg, OPT_SampleTell, mca[ColorTell].name);
1214 SetDlgItemText(hDlg, OPT_SampleChallenge, mca[ColorChallenge].name);
1215 SetDlgItemText(hDlg, OPT_SampleRequest, mca[ColorRequest].name);
1216 SetDlgItemText(hDlg, OPT_SampleSeek, mca[ColorSeek].name);
1217 SetDlgItemText(hDlg, OPT_SampleNormal, mca[ColorNormal].name);
1219 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1220 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1221 UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]);
1222 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1223 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1224 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1225 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1226 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1227 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1228 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1230 SetIcsOptionEnables(hDlg);
1233 case WM_COMMAND: /* message: received a command */
1234 switch (LOWORD(wParam)) {
1236 case WM_USER_GetConsoleBackground:
1237 /* the ColorizeTextDialog needs the current background color */
1238 colorref = (COLORREF *)lParam;
1243 /* Read changed options from the dialog box */
1244 GetDlgItemText(hDlg, OPT_IcsAlarmTime, buf, MSG_SIZ);
1245 if (sscanf(buf, "%d", &number) != 1 || (number < 0)){
1246 MessageBox(hDlg, "Invalid ICS Alarm Time",
1247 "Option Error", MB_OK|MB_ICONEXCLAMATION);
1251 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
1253 appData.icsAlarm = IS_CHECKED(OPT_IcsAlarm);
1254 appData.premove = IS_CHECKED(OPT_Premove);
1255 appData.premoveWhite = IS_CHECKED(OPT_PremoveWhite);
1256 appData.premoveBlack = IS_CHECKED(OPT_PremoveBlack);
1257 appData.autoComment = IS_CHECKED(OPT_AutoComment);
1258 appData.autoObserve = IS_CHECKED(OPT_AutoObserve);
1259 appData.getMoveList = IS_CHECKED(OPT_GetMoveList);
1260 appData.localLineEditing = IS_CHECKED(OPT_LocalLineEditing);
1261 appData.quietPlay = IS_CHECKED(OPT_QuietPlay);
1265 appData.icsAlarmTime = number * 1000;
1266 GetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText, 5);
1267 GetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText, 5);
1269 if (appData.localLineEditing) {
1278 (Boolean)!IsDlgButtonChecked(hDlg, OPT_DontColorize);
1280 if (!appData.colorize) {
1282 COLORREF background = ParseColorName(COLOR_BKGD);
1284 SetDefaultTextAttribs();
1285 Colorize(currentColorClass);
1287 cf.cbSize = sizeof(CHARFORMAT);
1288 cf.dwMask = CFM_COLOR;
1289 cf.crTextColor = ParseColorName(COLOR_NORMAL);
1291 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1292 EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1293 SendDlgItemMessage(hwndConsole, OPT_ConsoleText,
1294 EM_SETBKGNDCOLOR, FALSE, background);
1295 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1296 EM_SETBKGNDCOLOR, FALSE, background);
1299 if (cbc != consoleBackgroundColor) {
1300 consoleBackgroundColor = cbc;
1301 if (appData.colorize) {
1302 SendDlgItemMessage(hwndConsole, OPT_ConsoleText,
1303 EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);
1304 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1305 EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);
1309 for (i=0; i < NColorClasses - 1; i++) {
1310 textAttribs[i].color = mca[i].color;
1311 textAttribs[i].effects = mca[i].effects;
1314 EndDialog(hDlg, TRUE);
1318 EndDialog(hDlg, FALSE);
1321 case OPT_ChooseShoutColor:
1322 ColorizeTextPopup(hDlg, ColorShout);
1323 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1326 case OPT_ChooseSShoutColor:
1327 ColorizeTextPopup(hDlg, ColorSShout);
1328 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1331 case OPT_ChooseChannel1Color:
1332 ColorizeTextPopup(hDlg, ColorChannel1);
1333 UpdateSampleText(hDlg, OPT_SampleChannel1,
1334 &colorizeAttribs[ColorChannel1]);
1337 case OPT_ChooseChannelColor:
1338 ColorizeTextPopup(hDlg, ColorChannel);
1339 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1342 case OPT_ChooseKibitzColor:
1343 ColorizeTextPopup(hDlg, ColorKibitz);
1344 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1347 case OPT_ChooseTellColor:
1348 ColorizeTextPopup(hDlg, ColorTell);
1349 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1352 case OPT_ChooseChallengeColor:
1353 ColorizeTextPopup(hDlg, ColorChallenge);
1354 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1357 case OPT_ChooseRequestColor:
1358 ColorizeTextPopup(hDlg, ColorRequest);
1359 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1362 case OPT_ChooseSeekColor:
1363 ColorizeTextPopup(hDlg, ColorSeek);
1364 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1367 case OPT_ChooseNormalColor:
1368 ColorizeTextPopup(hDlg, ColorNormal);
1369 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1372 case OPT_ChooseBackgroundColor:
1373 if (ChangeColor(hDlg, &cbc)) {
1374 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1375 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1376 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1377 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1378 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1379 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1380 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1381 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1382 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1383 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1387 case OPT_DefaultColors:
1388 for (i=0; i < NColorClasses - 1; i++)
1389 ParseAttribs(&mca[i].color,
1391 defaultTextAttribs[i]);
1393 cbc = ParseColorName(COLOR_BKGD);
1394 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1395 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1396 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1397 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1398 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1399 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1400 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1401 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1402 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1403 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1405 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1406 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1407 UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]);
1408 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1409 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1410 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1411 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1412 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1413 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1414 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1418 SetIcsOptionEnables(hDlg);
1427 IcsOptionsPopup(HWND hwnd)
1429 FARPROC lpProc = MakeProcInstance((FARPROC)IcsOptionsDialog, hInst);
1430 DialogBox(hInst, MAKEINTRESOURCE(DLG_IcsOptions), hwnd,
1432 FreeProcInstance(lpProc);
1435 /*---------------------------------------------------------------------------*\
1437 * Fonts Dialog functions
1439 \*---------------------------------------------------------------------------*/
1442 SetSampleFontText(HWND hwnd, int id, const MyFont *mf)
1449 RECT rectClient, rectFormat;
1454 len = sprintf(buf, "%.0f pt. %s%s%s\n",
1455 mf->mfp.pointSize, mf->mfp.faceName,
1456 mf->mfp.bold ? " bold" : "",
1457 mf->mfp.italic ? " italic" : "");
1458 SetDlgItemText(hwnd, id, buf);
1460 hControl = GetDlgItem(hwnd, id);
1461 hdc = GetDC(hControl);
1462 SetMapMode(hdc, MM_TEXT); /* 1 pixel == 1 logical unit */
1463 oldFont = SelectObject(hdc, mf->hf);
1465 /* get number of logical units necessary to display font name */
1466 GetTextExtentPoint32(hdc, buf, len, &size);
1468 /* calculate formatting rectangle in the rich edit control.
1469 * May be larger or smaller than the actual control.
1471 GetClientRect(hControl, &rectClient);
1472 center.x = (rectClient.left + rectClient.right) / 2;
1473 center.y = (rectClient.top + rectClient.bottom) / 2;
1474 rectFormat.top = center.y - (size.cy / 2) - 1;
1475 rectFormat.bottom = center.y + (size.cy / 2) + 1;
1476 rectFormat.left = center.x - (size.cx / 2) - 1;
1477 rectFormat.right = center.x + (size.cx / 2) + 1;
1480 fprintf(debugFP, "\nfont: %s\n"
1481 "center.x %d, centerY %d\n"
1482 "size.cx %d, size.cy %d\n"
1483 "client.top %d, bottom %d, left %d, right %d\n"
1484 "format.top %d, bottom %d, left %d, right %d\n",
1488 rectClient.top, rectClient.bottom, rectClient.left,
1490 rectFormat.top, rectFormat.bottom, rectFormat.left,
1494 cf.cbSize = sizeof(CHARFORMAT);
1495 cf.dwMask = CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_BOLD|CFM_ITALIC;
1497 if (mf->lf.lfWeight == FW_BOLD) cf.dwEffects |= CFE_BOLD;
1498 if (mf->lf.lfItalic) cf.dwEffects |= CFE_ITALIC;
1499 strcpy(cf.szFaceName, mf->mfp.faceName);
1501 * yHeight is expressed in twips. A twip is 1/20 of a font's point
1502 * size. See documentation of CHARFORMAT. --msw
1504 cf.yHeight = (int)(mf->mfp.pointSize * 20.0 + 0.5);
1505 cf.bCharSet = mf->lf.lfCharSet;
1506 cf.bPitchAndFamily = mf->lf.lfPitchAndFamily;
1508 /* format the text in the rich edit control */
1509 SendMessage(hControl, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf);
1510 SendMessage(hControl, EM_SETRECT, (WPARAM)0, (LPARAM) &rectFormat);
1513 SelectObject(hdc, oldFont);
1514 ReleaseDC(hControl, hdc);
1518 CopyFont(MyFont *dest, const MyFont *src)
1520 dest->mfp.pointSize = src->mfp.pointSize;
1521 dest->mfp.bold = src->mfp.bold;
1522 dest->mfp.italic = src->mfp.italic;
1523 dest->mfp.underline = src->mfp.underline;
1524 dest->mfp.strikeout = src->mfp.strikeout;
1525 lstrcpy(dest->mfp.faceName, src->mfp.faceName);
1526 CreateFontInMF(dest);
1531 FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1533 static MyFont workFont[NUM_FONTS];
1534 static BOOL firstPaint;
1541 /* copy the current font settings into a working copy */
1542 for (i=0; i < NUM_FONTS; i++)
1543 CopyFont(&workFont[i], font[boardSize][i]);
1545 if (!appData.icsActive)
1546 EnableWindow(GetDlgItem(hDlg, OPT_ChooseConsoleFont), FALSE);
1548 firstPaint = TRUE; /* see rant below */
1550 /* If I don't call SetFocus(), the dialog won't respond to the keyboard
1551 * when first drawn. Why is this the only dialog that behaves this way? Is
1552 * is the WM_PAINT stuff below?? Sigh...
1554 SetFocus(GetDlgItem(hDlg, IDOK));
1558 /* This should not be necessary. However, if SetSampleFontText() is called
1559 * in response to WM_INITDIALOG, the strings are not properly centered in
1560 * the controls when the dialog first appears. I can't figure out why, so
1561 * this is the workaround. --msw
1564 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1565 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1566 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1567 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1568 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1569 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1570 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1575 case WM_COMMAND: /* message: received a command */
1576 switch (LOWORD(wParam)) {
1579 /* again, it seems to avoid redraw problems if we call EndDialog first */
1580 EndDialog(hDlg, FALSE);
1582 /* copy modified settings back to the fonts array */
1583 for (i=0; i < NUM_FONTS; i++)
1584 CopyFont(font[boardSize][i], &workFont[i]);
1586 /* a sad necessity due to the original design of having a separate
1587 * console font, tags font, and comment font for each board size. IMHO
1588 * these fonts should not be dependent on the current board size. I'm
1589 * running out of time, so I am doing this hack rather than redesign the
1590 * data structure. Besides, I think if I redesigned the data structure, I
1591 * might break backwards compatibility with old winboard.ini files.
1594 for (i=0; i < NUM_SIZES; i++) {
1595 CopyFont(font[i][EDITTAGS_FONT], &workFont[EDITTAGS_FONT]);
1596 CopyFont(font[i][CONSOLE_FONT], &workFont[CONSOLE_FONT]);
1597 CopyFont(font[i][COMMENT_FONT], &workFont[COMMENT_FONT]);
1598 CopyFont(font[i][MOVEHISTORY_FONT], &workFont[MOVEHISTORY_FONT]);
1600 /* end sad necessity */
1602 InitDrawingSizes(boardSize, 0);
1603 InvalidateRect(hwndMain, NULL, TRUE);
1605 if (commentDialog) {
1606 SendDlgItemMessage(commentDialog, OPT_CommentText,
1607 WM_SETFONT, (WPARAM)font[boardSize][COMMENT_FONT]->hf,
1608 MAKELPARAM(TRUE, 0));
1609 GetClientRect(GetDlgItem(commentDialog, OPT_CommentText), &rect);
1610 InvalidateRect(commentDialog, &rect, TRUE);
1613 if (editTagsDialog) {
1614 SendDlgItemMessage(editTagsDialog, OPT_TagsText,
1615 WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf,
1616 MAKELPARAM(TRUE, 0));
1617 GetClientRect(GetDlgItem(editTagsDialog, OPT_TagsText), &rect);
1618 InvalidateRect(editTagsDialog, &rect, TRUE);
1621 if( moveHistoryDialog != NULL ) {
1622 SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory,
1623 WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,
1624 MAKELPARAM(TRUE, 0));
1625 InvalidateRect(editTagsDialog, NULL, TRUE);
1629 ChangedConsoleFont();
1632 for (i=0; i<NUM_FONTS; i++)
1633 DeleteObject(&workFont[i].hf);
1638 for (i=0; i<NUM_FONTS; i++)
1639 DeleteObject(&workFont[i].hf);
1640 EndDialog(hDlg, FALSE);
1643 case OPT_ChooseClockFont:
1644 MyCreateFont(hDlg, &workFont[CLOCK_FONT]);
1645 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1648 case OPT_ChooseMessageFont:
1649 MyCreateFont(hDlg, &workFont[MESSAGE_FONT]);
1650 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1653 case OPT_ChooseCoordFont:
1654 MyCreateFont(hDlg, &workFont[COORD_FONT]);
1655 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1658 case OPT_ChooseTagFont:
1659 MyCreateFont(hDlg, &workFont[EDITTAGS_FONT]);
1660 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1663 case OPT_ChooseCommentsFont:
1664 MyCreateFont(hDlg, &workFont[COMMENT_FONT]);
1665 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1668 case OPT_ChooseConsoleFont:
1669 MyCreateFont(hDlg, &workFont[CONSOLE_FONT]);
1670 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1673 case OPT_ChooseMoveHistoryFont:
1674 MyCreateFont(hDlg, &workFont[MOVEHISTORY_FONT]);
1675 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1678 case OPT_DefaultFonts:
1679 for (i=0; i<NUM_FONTS; i++) {
1680 DeleteObject(&workFont[i].hf);
1681 ParseFontName(font[boardSize][i]->def, &workFont[i].mfp);
1682 CreateFontInMF(&workFont[i]);
1684 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1685 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1686 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1687 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1688 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1689 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1690 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1698 FontsOptionsPopup(HWND hwnd)
1700 FARPROC lpProc = MakeProcInstance((FARPROC)FontOptionsDialog, hInst);
1701 DialogBox(hInst, MAKEINTRESOURCE(DLG_Fonts), hwnd,
1703 FreeProcInstance(lpProc);
1706 /*---------------------------------------------------------------------------*\
1708 * Sounds Dialog functions
1710 \*---------------------------------------------------------------------------*/
1713 SoundComboData soundComboData[] = {
1716 {"ICS Alarm", NULL},
1720 {"ICS Unfinished", NULL},
1722 {"SShout/CShout", NULL},
1723 {"Channel 1", NULL},
1727 {"Challenge", NULL},
1735 InitSoundComboData(SoundComboData *scd)
1741 /* copy current sound settings to combo array */
1743 for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) {
1744 scd[sc].name = strdup(sounds[sc].name);
1746 for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) {
1747 index = (int)cc + (int)NSoundClasses;
1748 scd[index].name = strdup(textAttribs[cc].sound.name);
1754 ResetSoundComboData(SoundComboData *scd)
1756 while (scd->label) {
1757 if (scd->name != NULL) {
1766 InitSoundCombo(HWND hwndCombo, SoundComboData *scd)
1771 SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
1773 /* send the labels to the combo box */
1774 while (scd->label) {
1775 err = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) scd->label);
1777 sprintf(buf, "InitSoundCombo(): err '%d', cnt '%d'\n",
1778 (int)err, (int)cnt);
1779 MessageBox(NULL, buf, NULL, MB_OK);
1783 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) 0, (LPARAM) 0);
1787 SoundDialogWhichRadio(HWND hDlg)
1789 if (IsDlgButtonChecked(hDlg, OPT_NoSound)) return OPT_NoSound;
1790 if (IsDlgButtonChecked(hDlg, OPT_DefaultBeep)) return OPT_DefaultBeep;
1791 if (IsDlgButtonChecked(hDlg, OPT_BuiltInSound)) return OPT_BuiltInSound;
1792 if (IsDlgButtonChecked(hDlg, OPT_WavFile)) return OPT_WavFile;
1797 SoundDialogSetEnables(HWND hDlg, int radio)
1799 EnableWindow(GetDlgItem(hDlg, OPT_BuiltInSoundName),
1800 radio == OPT_BuiltInSound);
1801 EnableWindow(GetDlgItem(hDlg, OPT_WavFileName), radio == OPT_WavFile);
1802 EnableWindow(GetDlgItem(hDlg, OPT_BrowseSound), radio == OPT_WavFile);
1806 SoundDialogGetName(HWND hDlg, int radio)
1808 static char buf[MSG_SIZ], buf2[MSG_SIZ], buf3[MSG_SIZ];
1814 case OPT_DefaultBeep:
1816 case OPT_BuiltInSound:
1818 GetDlgItemText(hDlg, OPT_BuiltInSoundName, buf + 1, sizeof(buf) - 1);
1821 GetDlgItemText(hDlg, OPT_WavFileName, buf, sizeof(buf));
1822 GetCurrentDirectory(MSG_SIZ, buf3);
1823 SetCurrentDirectory(installDir);
1824 if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {
1829 SetCurrentDirectory(buf3);
1835 DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name)
1839 * I think it's best to clear the combo and edit boxes. It looks stupid
1840 * to have a value from another sound event sitting there grayed out.
1842 SetDlgItemText(hDlg, OPT_WavFileName, "");
1843 SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
1845 if (appData.debugMode)
1846 fprintf(debugFP, "DisplaySelectedSound(,,'%s'):\n", name);
1849 radio = OPT_NoSound;
1852 if (name[1] == NULLCHAR) {
1853 radio = OPT_DefaultBeep;
1855 radio = OPT_WavFile;
1856 SetDlgItemText(hDlg, OPT_WavFileName, name);
1860 if (name[1] == NULLCHAR) {
1861 radio = OPT_NoSound;
1863 radio = OPT_BuiltInSound;
1864 if (SendMessage(hCombo, CB_SELECTSTRING, (WPARAM) -1,
1865 (LPARAM) (name + 1)) == CB_ERR) {
1866 SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
1867 SendMessage(hCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) (name + 1));
1872 radio = OPT_WavFile;
1873 SetDlgItemText(hDlg, OPT_WavFileName, name);
1876 SoundDialogSetEnables(hDlg, radio);
1877 CheckRadioButton(hDlg, OPT_NoSound, OPT_WavFile, radio);
1881 char *builtInSoundNames[] = BUILT_IN_SOUND_NAMES;
1884 SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1886 static HWND hSoundCombo;
1896 SoundComboData *scd;
1900 /* Center the dialog over the application window */
1901 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1903 /* Initialize the built-in sounds combo */
1904 hBISN = GetDlgItem(hDlg, OPT_BuiltInSoundName);
1905 InitComboStrings(hBISN, builtInSoundNames);
1907 /* Initialize the sound events combo */
1909 InitSoundComboData(soundComboData);
1910 hSoundCombo = GetDlgItem(hDlg, CBO_Sounds);
1911 InitSoundCombo(hSoundCombo, soundComboData);
1913 /* update the dialog */
1914 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
1917 case WM_COMMAND: /* message: received a command */
1919 if (((HWND)lParam == hSoundCombo) &&
1920 (HIWORD(wParam) == CBN_SELCHANGE)) {
1922 * the user has selected a new sound event. We must store the name for
1923 * the previously selected event, then retrieve the name for the
1924 * newly selected event and update the dialog.
1926 radio = SoundDialogWhichRadio(hDlg);
1927 newName = strdup(SoundDialogGetName(hDlg, radio));
1929 if (strcmp(newName, soundComboData[index].name) != 0) {
1930 free(soundComboData[index].name);
1931 soundComboData[index].name = newName;
1936 /* now get the settings for the newly selected event */
1937 index = SendMessage(hSoundCombo, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
1938 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
1942 switch (LOWORD(wParam)) {
1945 * save the name for the currently selected sound event
1947 radio = SoundDialogWhichRadio(hDlg);
1948 newName = strdup(SoundDialogGetName(hDlg, radio));
1950 if (strcmp(soundComboData[index].name, newName) != 0) {
1951 free(soundComboData[index].name);
1952 soundComboData[index].name = newName;
1958 /* save all the sound names that changed and load the sounds */
1960 for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) {
1961 if (strcmp(soundComboData[sc].name, sounds[sc].name) != 0) {
1962 free(sounds[sc].name);
1963 sounds[sc].name = strdup(soundComboData[sc].name);
1964 MyLoadSound(&sounds[sc]);
1967 for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) {
1968 index = (int)cc + (int)NSoundClasses;
1969 if (strcmp(soundComboData[index].name,
1970 textAttribs[cc].sound.name) != 0) {
1971 free(textAttribs[cc].sound.name);
1972 textAttribs[cc].sound.name = strdup(soundComboData[index].name);
1973 MyLoadSound(&textAttribs[cc].sound);
1977 ResetSoundComboData(soundComboData);
1978 EndDialog(hDlg, TRUE);
1982 ResetSoundComboData(soundComboData);
1983 EndDialog(hDlg, FALSE);
1986 case OPT_DefaultSounds:
1987 /* can't use SetDefaultSounds() because we need to be able to "undo" if
1988 * user selects "Cancel" later on. So we do it the hard way here.
1990 scd = &soundComboData[0];
1991 while (scd->label != NULL) {
1992 if (scd->name != NULL) free(scd->name);
1993 scd->name = strdup("");
1996 free(soundComboData[(int)SoundBell].name);
1997 soundComboData[(int)SoundBell].name = strdup(SOUND_BELL);
1998 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
2002 radio = SoundDialogWhichRadio(hDlg);
2003 tmp.name = strdup(SoundDialogGetName(hDlg, radio));
2007 if (tmp.data != NULL) FreeResource(tmp.data); // technically obsolete fn, but tmp.data is NOT malloc'd mem
2008 if (tmp.name != NULL) free(tmp.name);
2011 case OPT_BrowseSound:
2012 f = OpenFileDialog(hDlg, "rb", NULL, "wav", SOUND_FILT,
2013 "Browse for Sound File", NULL, NULL, buf);
2016 SetDlgItemText(hDlg, OPT_WavFileName, buf);
2021 radio = SoundDialogWhichRadio(hDlg);
2022 SoundDialogSetEnables(hDlg, radio);
2031 VOID SoundOptionsPopup(HWND hwnd)
2035 lpProc = MakeProcInstance((FARPROC)SoundOptionsDialog, hInst);
2036 DialogBox(hInst, MAKEINTRESOURCE(DLG_Sound), hwnd, (DLGPROC)lpProc);
2037 FreeProcInstance(lpProc);
2041 /*---------------------------------------------------------------------------*\
2043 * Comm Port dialog functions
2045 \*---------------------------------------------------------------------------*/
2055 ComboData cdPort[] = { {"None", PORT_NONE}, {"COM1", 1}, {"COM2", 2},
2056 {"COM3", 3}, {"COM4", 4}, {NULL, 0} };
2057 ComboData cdDataRate[] = { {"110", 110}, {"300", 300}, {"600", 600}, {"1200", 1200},
2058 {"2400", 2400}, {"4800", 4800}, {"9600", 9600}, {"19200", 19200},
2059 {"38400", 38400}, {NULL, 0} };
2060 ComboData cdDataBits[] = { {"5", 5}, {"6", 6}, {"7", 7}, {"8", 8}, {NULL, 0} };
2061 ComboData cdParity[] = { {"None", NOPARITY}, {"Odd", ODDPARITY}, {"Even", EVENPARITY},
2062 {"Mark", MARKPARITY}, {"Space", SPACEPARITY}, {NULL, 0} };
2063 ComboData cdStopBits[] = { {"1", ONESTOPBIT}, {"1.5", ONE5STOPBITS},
2064 {"2", TWOSTOPBITS}, {NULL, 0} };
2065 ComboData cdFlow[] = { {"None", FLOW_NONE}, {"Xoff/Xon", FLOW_XOFF}, {"CTS", FLOW_CTS},
2066 {"DSR", FLOW_DSR}, {NULL, 0} };
2070 ParseCommSettings(char *arg, DCB *dcb)
2072 int dataRate, count;
2073 char bits[MSG_SIZ], parity[MSG_SIZ], stopBits[MSG_SIZ], flow[MSG_SIZ];
2075 count = sscanf(arg, "%d%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]",
2076 &dataRate, bits, parity, stopBits, flow);
2077 if (count != 5) goto cant_parse;
2078 dcb->BaudRate = dataRate;
2080 while (cd->label != NULL) {
2081 if (StrCaseCmp(cd->label, bits) == 0) {
2082 dcb->ByteSize = cd->value;
2087 if (cd->label == NULL) goto cant_parse;
2089 while (cd->label != NULL) {
2090 if (StrCaseCmp(cd->label, parity) == 0) {
2091 dcb->Parity = cd->value;
2096 if (cd->label == NULL) goto cant_parse;
2098 while (cd->label != NULL) {
2099 if (StrCaseCmp(cd->label, stopBits) == 0) {
2100 dcb->StopBits = cd->value;
2106 if (cd->label == NULL) goto cant_parse;
2107 while (cd->label != NULL) {
2108 if (StrCaseCmp(cd->label, flow) == 0) {
2109 switch (cd->value) {
2112 dcb->fOutxCtsFlow = FALSE;
2113 dcb->fOutxDsrFlow = FALSE;
2117 dcb->fOutxCtsFlow = TRUE;
2118 dcb->fOutxDsrFlow = FALSE;
2122 dcb->fOutxCtsFlow = FALSE;
2123 dcb->fOutxDsrFlow = TRUE;
2127 dcb->fOutxCtsFlow = FALSE;
2128 dcb->fOutxDsrFlow = FALSE;
2135 if (cd->label == NULL) goto cant_parse;
2138 ExitArgError("Can't parse com port settings", arg);
2142 VOID PrintCommSettings(FILE *f, char *name, DCB *dcb)
2144 char *flow = "??", *parity = "??", *stopBits = "??";
2148 while (cd->label != NULL) {
2149 if (dcb->Parity == cd->value) {
2156 while (cd->label != NULL) {
2157 if (dcb->StopBits == cd->value) {
2158 stopBits = cd->label;
2164 flow = cdFlow[FLOW_XOFF].label;
2165 } else if (dcb->fOutxCtsFlow) {
2166 flow = cdFlow[FLOW_CTS].label;
2167 } else if (dcb->fOutxDsrFlow) {
2168 flow = cdFlow[FLOW_DSR].label;
2170 flow = cdFlow[FLOW_NONE].label;
2172 fprintf(f, "/%s=%d,%d,%s,%s,%s\n", name,
2173 (int)dcb->BaudRate, dcb->ByteSize, parity, stopBits, flow);
2178 InitCombo(HANDLE hwndCombo, ComboData *cd)
2180 SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
2182 while (cd->label != NULL) {
2183 SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) cd->label);
2189 SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value)
2194 while (cd->label != NULL) {
2195 if (cd->value == value) {
2196 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) i, (LPARAM) 0);
2205 CommPortOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2215 case WM_INITDIALOG: /* message: initialize dialog box */
2216 /* Center the dialog over the application window */
2217 CenterWindow (hDlg, GetWindow(hDlg, GW_OWNER));
2218 /* Initialize the dialog items */
2219 /* !! There should probably be some synchronization
2220 in accessing hCommPort and dcb. Or does modal nature
2221 of this dialog box do it for us?
2223 hwndCombo = GetDlgItem(hDlg, OPT_Port);
2224 InitCombo(hwndCombo, cdPort);
2225 p = strrchr(appData.icsCommPort, '\\');
2226 if (p++ == NULL) p = appData.icsCommPort;
2228 (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) p) == CB_ERR)) {
2229 SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) "None");
2231 EnableWindow(hwndCombo, hCommPort == NULL); /*!! don't allow change for now*/
2233 hwndCombo = GetDlgItem(hDlg, OPT_DataRate);
2234 InitCombo(hwndCombo, cdDataRate);
2235 sprintf(buf, "%u", (int)dcb.BaudRate);
2236 if (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) buf) == CB_ERR) {
2237 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
2238 SendMessage(hwndCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) buf);
2241 hwndCombo = GetDlgItem(hDlg, OPT_Bits);
2242 InitCombo(hwndCombo, cdDataBits);
2243 SelectComboValue(hwndCombo, cdDataBits, dcb.ByteSize);
2245 hwndCombo = GetDlgItem(hDlg, OPT_Parity);
2246 InitCombo(hwndCombo, cdParity);
2247 SelectComboValue(hwndCombo, cdParity, dcb.Parity);
2249 hwndCombo = GetDlgItem(hDlg, OPT_StopBits);
2250 InitCombo(hwndCombo, cdStopBits);
2251 SelectComboValue(hwndCombo, cdStopBits, dcb.StopBits);
2253 hwndCombo = GetDlgItem(hDlg, OPT_Flow);
2254 InitCombo(hwndCombo, cdFlow);
2256 SelectComboValue(hwndCombo, cdFlow, FLOW_XOFF);
2257 } else if (dcb.fOutxCtsFlow) {
2258 SelectComboValue(hwndCombo, cdFlow, FLOW_CTS);
2259 } else if (dcb.fOutxDsrFlow) {
2260 SelectComboValue(hwndCombo, cdFlow, FLOW_DSR);
2262 SelectComboValue(hwndCombo, cdFlow, FLOW_NONE);
2266 case WM_COMMAND: /* message: received a command */
2267 switch (LOWORD(wParam)) {
2269 /* Read changed options from the dialog box */
2271 /* !! Currently we can't change comm ports in midstream */
2272 hwndCombo = GetDlgItem(hDlg, OPT_Port);
2273 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2274 if (index == PORT_NONE) {
2275 appData.icsCommPort = "";
2276 if (hCommPort != NULL) {
2277 CloseHandle(hCommPort);
2280 EndDialog(hDlg, TRUE);
2283 SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf);
2284 appData.icsCommPort = strdup(buf);
2285 if (hCommPort != NULL) {
2286 CloseHandle(hCommPort);
2289 /* now what?? can't really do this; have to fix up the ChildProc
2290 and InputSource records for the comm port that we gave to the
2294 hwndCombo = GetDlgItem(hDlg, OPT_DataRate);
2295 SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf);
2296 if (sscanf(buf, "%u", &value) != 1) {
2297 MessageBox(hDlg, "Invalid data rate",
2298 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2301 dcb.BaudRate = value;
2303 hwndCombo = GetDlgItem(hDlg, OPT_Bits);
2304 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2305 dcb.ByteSize = cdDataBits[index].value;
2307 hwndCombo = GetDlgItem(hDlg, OPT_Parity);
2308 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2309 dcb.Parity = cdParity[index].value;
2311 hwndCombo = GetDlgItem(hDlg, OPT_StopBits);
2312 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2313 dcb.StopBits = cdStopBits[index].value;
2315 hwndCombo = GetDlgItem(hDlg, OPT_Flow);
2316 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2317 switch (cdFlow[index].value) {
2320 dcb.fOutxCtsFlow = FALSE;
2321 dcb.fOutxDsrFlow = FALSE;
2325 dcb.fOutxCtsFlow = TRUE;
2326 dcb.fOutxDsrFlow = FALSE;
2330 dcb.fOutxCtsFlow = FALSE;
2331 dcb.fOutxDsrFlow = TRUE;
2335 dcb.fOutxCtsFlow = FALSE;
2336 dcb.fOutxDsrFlow = FALSE;
2339 if (!SetCommState(hCommPort, (LPDCB) &dcb)) {
2340 err = GetLastError();
2341 switch(MessageBox(hDlg,
2342 "Failed to set comm port state;\r\ninvalid options?",
2343 "Option Error", MB_ABORTRETRYIGNORE|MB_ICONQUESTION)) {
2345 DisplayFatalError("Failed to set comm port state", err, 1);
2346 exit(1); /*is it ok to do this from here?*/
2352 EndDialog(hDlg, TRUE);
2357 EndDialog(hDlg, TRUE);
2361 EndDialog(hDlg, FALSE);
2373 CommPortOptionsPopup(HWND hwnd)
2375 FARPROC lpProc = MakeProcInstance((FARPROC)CommPortOptionsDialog, hInst);
2376 DialogBox(hInst, MAKEINTRESOURCE(DLG_CommPort), hwnd, (DLGPROC) lpProc);
2377 FreeProcInstance(lpProc);
2380 /*---------------------------------------------------------------------------*\
2382 * Load Options dialog functions
2384 \*---------------------------------------------------------------------------*/
2387 SetLoadOptionEnables(HWND hDlg)
2391 state = IsDlgButtonChecked(hDlg, OPT_Autostep);
2392 EnableWindow(GetDlgItem(hDlg, OPT_ASTimeDelay), state);
2393 EnableWindow(GetDlgItem(hDlg, OPT_AStext1), state);
2397 LoadOptions(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2403 case WM_INITDIALOG: /* message: initialize dialog box */
2404 /* Center the dialog over the application window */
2405 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2406 /* Initialize the dialog items */
2407 if (appData.timeDelay >= 0.0) {
2408 CheckDlgButton(hDlg, OPT_Autostep, TRUE);
2409 sprintf(buf, "%.2g", appData.timeDelay);
2410 SetDlgItemText(hDlg, OPT_ASTimeDelay, buf);
2412 CheckDlgButton(hDlg, OPT_Autostep, FALSE);
2414 SetLoadOptionEnables(hDlg);
2417 case WM_COMMAND: /* message: received a command */
2418 switch (LOWORD(wParam)) {
2420 /* Read changed options from the dialog box */
2421 if (IsDlgButtonChecked(hDlg, OPT_Autostep)) {
2422 GetDlgItemText(hDlg, OPT_ASTimeDelay, buf, MSG_SIZ);
2423 if (sscanf(buf, "%f", &fnumber) != 1) {
2424 MessageBox(hDlg, "Invalid load game step rate",
2425 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2428 appData.timeDelay = fnumber;
2430 appData.timeDelay = (float) -1.0;
2432 EndDialog(hDlg, TRUE);
2436 EndDialog(hDlg, FALSE);
2440 SetLoadOptionEnables(hDlg);
2450 LoadOptionsPopup(HWND hwnd)
2452 FARPROC lpProc = MakeProcInstance((FARPROC)LoadOptions, hInst);
2453 DialogBox(hInst, MAKEINTRESOURCE(DLG_LoadOptions), hwnd, (DLGPROC) lpProc);
2454 FreeProcInstance(lpProc);
2457 /*---------------------------------------------------------------------------*\
2459 * Save Options dialog functions
2461 \*---------------------------------------------------------------------------*/
2464 SetSaveOptionEnables(HWND hDlg)
2468 state = IsDlgButtonChecked(hDlg, OPT_Autosave);
2469 EnableWindow(GetDlgItem(hDlg, OPT_AVPrompt), state);
2470 EnableWindow(GetDlgItem(hDlg, OPT_AVToFile), state);
2471 if (state && !IsDlgButtonChecked(hDlg, OPT_AVPrompt) &&
2472 !IsDlgButtonChecked(hDlg, OPT_AVToFile)) {
2473 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt);
2476 state = state && IsDlgButtonChecked(hDlg, OPT_AVToFile);
2477 EnableWindow(GetDlgItem(hDlg, OPT_AVFilename), state);
2478 EnableWindow(GetDlgItem(hDlg, OPT_AVBrowse), state);
2482 SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2488 case WM_INITDIALOG: /* message: initialize dialog box */
2489 /* Center the dialog over the application window */
2490 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2491 /* Initialize the dialog items */
2492 if (*appData.saveGameFile != NULLCHAR) {
2493 CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE);
2494 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVToFile);
2495 SetDlgItemText(hDlg, OPT_AVFilename, appData.saveGameFile);
2496 } else if (appData.autoSaveGames) {
2497 CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE);
2498 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt);
2500 CheckDlgButton(hDlg, OPT_Autosave, (UINT) FALSE);
2502 if (appData.oldSaveStyle) {
2503 CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_Old);
2505 CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_PGN);
2507 CheckDlgButton( hDlg, OPT_OutOfBookInfo, appData.saveOutOfBookInfo );
2508 SetSaveOptionEnables(hDlg);
2511 case WM_COMMAND: /* message: received a command */
2512 switch (LOWORD(wParam)) {
2514 /* Read changed options from the dialog box */
2515 if (IsDlgButtonChecked(hDlg, OPT_Autosave)) {
2516 appData.autoSaveGames = TRUE;
2517 if (IsDlgButtonChecked(hDlg, OPT_AVPrompt)) {
2518 appData.saveGameFile = "";
2519 } else /*if (IsDlgButtonChecked(hDlg, OPT_AVToFile))*/ {
2520 GetDlgItemText(hDlg, OPT_AVFilename, buf, MSG_SIZ);
2521 if (*buf == NULLCHAR) {
2522 MessageBox(hDlg, "Invalid save game file name",
2523 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2526 if ((isalpha(buf[0]) && buf[1] == ':') ||
2527 (buf[0] == '\\' && buf[1] == '\\')) {
2528 appData.saveGameFile = strdup(buf);
2530 char buf2[MSG_SIZ], buf3[MSG_SIZ];
2532 GetCurrentDirectory(MSG_SIZ, buf3);
2533 SetCurrentDirectory(installDir);
2534 if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {
2535 appData.saveGameFile = strdup(buf2);
2537 appData.saveGameFile = strdup(buf);
2539 SetCurrentDirectory(buf3);
2543 appData.autoSaveGames = FALSE;
2544 appData.saveGameFile = "";
2546 appData.oldSaveStyle = IsDlgButtonChecked(hDlg, OPT_Old);
2547 appData.saveOutOfBookInfo = IsDlgButtonChecked( hDlg, OPT_OutOfBookInfo );
2548 EndDialog(hDlg, TRUE);
2552 EndDialog(hDlg, FALSE);
2556 f = OpenFileDialog(hDlg, "a", NULL,
2557 appData.oldSaveStyle ? "gam" : "pgn",
2558 GAME_FILT, "Browse for Auto Save File",
2562 SetDlgItemText(hDlg, OPT_AVFilename, buf);
2567 SetSaveOptionEnables(hDlg);
2576 SaveOptionsPopup(HWND hwnd)
2578 FARPROC lpProc = MakeProcInstance((FARPROC)SaveOptionsDialog, hInst);
2579 DialogBox(hInst, MAKEINTRESOURCE(DLG_SaveOptions), hwnd, (DLGPROC) lpProc);
2580 FreeProcInstance(lpProc);
2583 /*---------------------------------------------------------------------------*\
2585 * Time Control Options dialog functions
2587 \*---------------------------------------------------------------------------*/
2590 SetTimeControlEnables(HWND hDlg)
2594 state = IsDlgButtonChecked(hDlg, OPT_TCUseMoves);
2595 EnableWindow(GetDlgItem(hDlg, OPT_TCTime), state);
2596 EnableWindow(GetDlgItem(hDlg, OPT_TCMoves), state);
2597 EnableWindow(GetDlgItem(hDlg, OPT_TCtext1), state);
2598 EnableWindow(GetDlgItem(hDlg, OPT_TCtext2), state);
2599 EnableWindow(GetDlgItem(hDlg, OPT_TCTime2), !state);
2600 EnableWindow(GetDlgItem(hDlg, OPT_TCInc), !state);
2601 EnableWindow(GetDlgItem(hDlg, OPT_TCitext1), !state);
2602 EnableWindow(GetDlgItem(hDlg, OPT_TCitext2), !state);
2603 EnableWindow(GetDlgItem(hDlg, OPT_TCitext3), !state);
2608 TimeControl(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2611 int mps, increment, odds1, odds2;
2615 case WM_INITDIALOG: /* message: initialize dialog box */
2616 /* Center the dialog over the application window */
2617 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2618 /* Initialize the dialog items */
2619 if (appData.clockMode && !appData.icsActive) {
2620 if (appData.timeIncrement == -1) {
2621 CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,
2623 SetDlgItemText(hDlg, OPT_TCTime, appData.timeControl);
2624 SetDlgItemInt(hDlg, OPT_TCMoves, appData.movesPerSession,
2626 SetDlgItemText(hDlg, OPT_TCTime2, "");
2627 SetDlgItemText(hDlg, OPT_TCInc, "");
2629 CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,
2631 SetDlgItemText(hDlg, OPT_TCTime, "");
2632 SetDlgItemText(hDlg, OPT_TCMoves, "");
2633 SetDlgItemText(hDlg, OPT_TCTime2, appData.timeControl);
2634 SetDlgItemInt(hDlg, OPT_TCInc, appData.timeIncrement, FALSE);
2636 SetDlgItemInt(hDlg, OPT_TCOdds1, 1, FALSE);
2637 SetDlgItemInt(hDlg, OPT_TCOdds2, 1, FALSE);
2638 SetTimeControlEnables(hDlg);
2642 case WM_COMMAND: /* message: received a command */
2643 switch (LOWORD(wParam)) {
2645 /* Read changed options from the dialog box */
2646 if (IsDlgButtonChecked(hDlg, OPT_TCUseMoves)) {
2648 mps = GetDlgItemInt(hDlg, OPT_TCMoves, &ok, FALSE);
2649 if (!ok || mps <= 0) {
2650 MessageBox(hDlg, "Invalid moves per time control",
2651 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2654 GetDlgItemText(hDlg, OPT_TCTime, buf, MSG_SIZ);
2655 if (!ParseTimeControl(buf, increment, mps)) {
2656 MessageBox(hDlg, "Invalid minutes per time control",
2657 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2661 increment = GetDlgItemInt(hDlg, OPT_TCInc, &ok, FALSE);
2662 mps = appData.movesPerSession;
2663 if (!ok || increment < 0) {
2664 MessageBox(hDlg, "Invalid increment",
2665 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2668 GetDlgItemText(hDlg, OPT_TCTime2, buf, MSG_SIZ);
2669 if (!ParseTimeControl(buf, increment, mps)) {
2670 MessageBox(hDlg, "Invalid initial time",
2671 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2675 odds1 = GetDlgItemInt(hDlg, OPT_TCOdds1, &ok, FALSE);
2676 odds2 = GetDlgItemInt(hDlg, OPT_TCOdds2, &ok2, FALSE);
2677 if (!ok || !ok2 || odds1 <= 0 || odds2 <= 0) {
2678 MessageBox(hDlg, "Invalid time-odds factor",
2679 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2682 appData.timeControl = strdup(buf);
2683 appData.movesPerSession = mps;
2684 appData.timeIncrement = increment;
2685 appData.firstTimeOdds = first.timeOdds = odds1;
2686 appData.secondTimeOdds = second.timeOdds = odds2;
2688 EndDialog(hDlg, TRUE);
2692 EndDialog(hDlg, FALSE);
2696 SetTimeControlEnables(hDlg);
2705 TimeControlOptionsPopup(HWND hwnd)
2707 if (gameMode != BeginningOfGame) {
2708 DisplayError("Changing time control during a game is not implemented", 0);
2710 FARPROC lpProc = MakeProcInstance((FARPROC)TimeControl, hInst);
2711 DialogBox(hInst, MAKEINTRESOURCE(DLG_TimeControl), hwnd, (DLGPROC) lpProc);
2712 FreeProcInstance(lpProc);
2716 /*---------------------------------------------------------------------------*\
2718 * Engine Options Dialog functions
2720 \*---------------------------------------------------------------------------*/
2721 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
2722 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
2724 #define INT_ABS( n ) ((n) >= 0 ? (n) : -(n))
2726 LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2729 case WM_INITDIALOG: /* message: initialize dialog box */
2731 /* Center the dialog over the application window */
2732 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2734 /* Initialize the dialog items */
2735 CHECK_BOX(IDC_EpPeriodicUpdates, appData.periodicUpdates);
2736 CHECK_BOX(IDC_EpPonder, appData.ponderNextMove);
2737 CHECK_BOX(IDC_EpShowThinking, appData.showThinking);
2738 CHECK_BOX(IDC_EpHideThinkingHuman, appData.hideThinkingFromHuman);
2740 CHECK_BOX(IDC_TestClaims, appData.testClaims);
2741 CHECK_BOX(IDC_DetectMates, appData.checkMates);
2742 CHECK_BOX(IDC_MaterialDraws, appData.materialDraws);
2743 CHECK_BOX(IDC_TrivialDraws, appData.trivialDraws);
2745 CHECK_BOX(IDC_ScoreAbs1, appData.firstScoreIsAbsolute);
2746 CHECK_BOX(IDC_ScoreAbs2, appData.secondScoreIsAbsolute);
2748 SetDlgItemInt( hDlg, IDC_EpDrawMoveCount, appData.adjudicateDrawMoves, TRUE );
2749 SendDlgItemMessage( hDlg, IDC_EpDrawMoveCount, EM_SETSEL, 0, -1 );
2751 SetDlgItemInt( hDlg, IDC_EpAdjudicationThreshold, INT_ABS(appData.adjudicateLossThreshold), TRUE );
2752 SendDlgItemMessage( hDlg, IDC_EpAdjudicationThreshold, EM_SETSEL, 0, -1 );
2754 SetDlgItemInt( hDlg, IDC_RuleMoves, appData.ruleMoves, TRUE );
2755 SendDlgItemMessage( hDlg, IDC_RuleMoves, EM_SETSEL, 0, -1 );
2757 SetDlgItemInt( hDlg, IDC_DrawRepeats, INT_ABS(appData.drawRepeats), TRUE );
2758 SendDlgItemMessage( hDlg, IDC_DrawRepeats, EM_SETSEL, 0, -1 );
2762 case WM_COMMAND: /* message: received a command */
2763 switch (LOWORD(wParam)) {
2765 /* Read changed options from the dialog box */
2766 PeriodicUpdatesEvent( IS_CHECKED(IDC_EpPeriodicUpdates));
2767 PonderNextMoveEvent( IS_CHECKED(IDC_EpPonder));
2768 appData.hideThinkingFromHuman= IS_CHECKED(IDC_EpHideThinkingHuman); // [HGM] thinking: moved up
2770 ShowThinkingEvent( IS_CHECKED(IDC_EpShowThinking));
2772 appData.showThinking = IS_CHECKED(IDC_EpShowThinking);
2773 ShowThinkingEvent(); // [HGM] thinking: tests all options that need thinking output
2775 appData.testClaims = IS_CHECKED(IDC_TestClaims);
2776 appData.checkMates = IS_CHECKED(IDC_DetectMates);
2777 appData.materialDraws = IS_CHECKED(IDC_MaterialDraws);
2778 appData.trivialDraws = IS_CHECKED(IDC_TrivialDraws);
2780 appData.adjudicateDrawMoves = GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, NULL, FALSE );
2781 appData.adjudicateLossThreshold = - (int) GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, NULL, FALSE );
2782 appData.ruleMoves = GetDlgItemInt(hDlg, IDC_RuleMoves, NULL, FALSE );
2783 appData.drawRepeats = (int) GetDlgItemInt(hDlg, IDC_DrawRepeats, NULL, FALSE );
2785 appData.firstScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs1);
2786 appData.secondScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs2);
2788 EndDialog(hDlg, TRUE);
2792 EndDialog(hDlg, FALSE);
2795 case IDC_EpDrawMoveCount:
2796 case IDC_EpAdjudicationThreshold:
2797 case IDC_DrawRepeats:
2799 if( HIWORD(wParam) == EN_CHANGE ) {
2805 GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, &n1_ok, FALSE );
2806 GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, &n2_ok, FALSE );
2807 GetDlgItemInt(hDlg, IDC_RuleMoves, &n3_ok, FALSE );
2808 GetDlgItemInt(hDlg, IDC_DrawRepeats, &n4_ok, FALSE );
2810 EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok && n4_ok ? TRUE : FALSE );
2819 VOID EnginePlayOptionsPopup(HWND hwnd)
2823 lpProc = MakeProcInstance((FARPROC)EnginePlayOptionsDialog, hInst);
2824 DialogBox(hInst, MAKEINTRESOURCE(DLG_EnginePlayOptions), hwnd, (DLGPROC) lpProc);
2825 FreeProcInstance(lpProc);
2828 /*---------------------------------------------------------------------------*\
2830 * UCI Options Dialog functions
2832 \*---------------------------------------------------------------------------*/
2833 static BOOL BrowseForFolder( const char * title, char * path )
2835 BOOL result = FALSE;
2839 ZeroMemory( &bi, sizeof(bi) );
2841 bi.lpszTitle = title == 0 ? "Choose Folder" : title;
2842 bi.ulFlags = BIF_RETURNONLYFSDIRS;
2844 pidl = SHBrowseForFolder( &bi );
2847 IMalloc * imalloc = 0;
2849 if( SHGetPathFromIDList( pidl, path ) ) {
2853 if( SUCCEEDED( SHGetMalloc ( &imalloc ) ) ) {
2854 imalloc->lpVtbl->Free(imalloc,pidl);
2855 imalloc->lpVtbl->Release(imalloc);
2862 LRESULT CALLBACK UciOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2868 case WM_INITDIALOG: /* message: initialize dialog box */
2870 /* Center the dialog over the application window */
2871 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2873 /* Initialize the dialog items */
2874 SetDlgItemText( hDlg, IDC_PolyglotDir, appData.polyglotDir );
2875 SetDlgItemInt( hDlg, IDC_HashSize, appData.defaultHashSize, TRUE );
2876 SetDlgItemText( hDlg, IDC_PathToEGTB, appData.defaultPathEGTB );
2877 SetDlgItemInt( hDlg, IDC_SizeOfEGTB, appData.defaultCacheSizeEGTB, TRUE );
2878 CheckDlgButton( hDlg, IDC_UseBook, (BOOL) appData.usePolyglotBook );
2879 SetDlgItemText( hDlg, IDC_BookFile, appData.polyglotBook );
2880 // [HGM] smp: input field for nr of cores:
2881 SetDlgItemInt( hDlg, IDC_Cores, appData.smpCores, TRUE );
2882 // [HGM] book: tick boxes for own book use
2883 CheckDlgButton( hDlg, IDC_OwnBook1, (BOOL) appData.firstHasOwnBookUCI );
2884 CheckDlgButton( hDlg, IDC_OwnBook2, (BOOL) appData.secondHasOwnBookUCI );
2886 SendDlgItemMessage( hDlg, IDC_PolyglotDir, EM_SETSEL, 0, -1 );
2890 case WM_COMMAND: /* message: received a command */
2891 switch (LOWORD(wParam)) {
2893 GetDlgItemText( hDlg, IDC_PolyglotDir, buf, sizeof(buf) );
2894 appData.polyglotDir = strdup(buf);
2895 appData.defaultHashSize = GetDlgItemInt(hDlg, IDC_HashSize, NULL, FALSE );
2896 appData.defaultCacheSizeEGTB = GetDlgItemInt(hDlg, IDC_SizeOfEGTB, NULL, FALSE );
2897 GetDlgItemText( hDlg, IDC_PathToEGTB, buf, sizeof(buf) );
2898 appData.defaultPathEGTB = strdup(buf);
2899 GetDlgItemText( hDlg, IDC_BookFile, buf, sizeof(buf) );
2900 appData.polyglotBook = strdup(buf);
2901 appData.usePolyglotBook = (Boolean) IsDlgButtonChecked( hDlg, IDC_UseBook );
2902 // [HGM] smp: get nr of cores:
2903 oldCores = appData.smpCores;
2904 appData.smpCores = GetDlgItemInt(hDlg, IDC_Cores, NULL, FALSE );
2905 if(appData.smpCores != oldCores) NewSettingEvent(FALSE, "cores", appData.smpCores);
2906 // [HGM] book: read tick boxes for own book use
2907 appData.firstHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook1 );
2908 appData.secondHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook2 );
2910 if(gameMode == BeginningOfGame) Reset(TRUE, TRUE);
2911 EndDialog(hDlg, TRUE);
2915 EndDialog(hDlg, FALSE);
2918 case IDC_BrowseForBook:
2921 'A','l','l',' ','F','i','l','e','s', 0,
2923 'B','I','N',' ','F','i','l','e','s', 0,
2924 '*','.','b','i','n', 0,
2931 ZeroMemory( &ofn, sizeof(ofn) );
2933 ofn.lStructSize = sizeof(ofn);
2934 ofn.hwndOwner = hDlg;
2935 ofn.hInstance = hInst;
2936 ofn.lpstrFilter = filter;
2937 ofn.lpstrFile = buf;
2938 ofn.nMaxFile = sizeof(buf);
2939 ofn.lpstrTitle = "Choose Book";
2940 ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;
2942 if( GetOpenFileName( &ofn ) ) {
2943 SetDlgItemText( hDlg, IDC_BookFile, buf );
2948 case IDC_BrowseForPolyglotDir:
2949 if( BrowseForFolder( "Choose Polyglot Directory", buf ) ) {
2950 SetDlgItemText( hDlg, IDC_PolyglotDir, buf );
2952 strcat( buf, "\\polyglot.exe" );
2954 if( GetFileAttributes(buf) == 0xFFFFFFFF ) {
2955 MessageBox( hDlg, "Polyglot was not found in the specified folder!", "Warning", MB_OK | MB_ICONWARNING );
2960 case IDC_BrowseForEGTB:
2961 if( BrowseForFolder( "Choose EGTB Directory:", buf ) ) {
2962 SetDlgItemText( hDlg, IDC_PathToEGTB, buf );
2967 case IDC_SizeOfEGTB:
2968 if( HIWORD(wParam) == EN_CHANGE ) {
2972 GetDlgItemInt(hDlg, IDC_HashSize, &n1_ok, FALSE );
2973 GetDlgItemInt(hDlg, IDC_SizeOfEGTB, &n2_ok, FALSE );
2975 EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok ? TRUE : FALSE );
2984 VOID UciOptionsPopup(HWND hwnd)
2988 lpProc = MakeProcInstance((FARPROC)UciOptionsDialog, hInst);
2989 DialogBox(hInst, MAKEINTRESOURCE(DLG_OptionsUCI), hwnd, (DLGPROC) lpProc);
2990 FreeProcInstance(lpProc);