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 */
37 #include "wedittags.h"
45 /* Imports from winboard.c */
47 extern MyFont *font[NUM_SIZES][NUM_FONTS];
48 extern HINSTANCE hInst; /* current instance */
49 extern HWND hwndMain; /* root window*/
50 extern BOOLEAN alwaysOnTop;
51 extern RECT boardRect;
52 extern COLORREF lightSquareColor, darkSquareColor, whitePieceColor,
53 blackPieceColor, highlightSquareColor, premoveHighlightColor;
55 extern BoardSize boardSize;
56 extern COLORREF consoleBackgroundColor;
57 extern MyColorizeAttribs colorizeAttribs[]; /* do I need the size? */
58 extern MyTextAttribs textAttribs[];
59 extern MySound sounds[];
60 extern ColorClass currentColorClass;
61 extern HWND hwndConsole;
62 extern char *defaultTextAttribs[];
63 extern HWND commentDialog;
64 extern HWND moveHistoryDialog;
65 extern char installDir[];
66 extern HWND hCommPort; /* currently open comm port */
68 extern BOOLEAN chessProgram;
69 extern startedFromPositionFile; /* [HGM] loadPos */
83 /* module prototypes */
85 LRESULT CALLBACK GeneralOptions(HWND, UINT, WPARAM, LPARAM);
86 LRESULT CALLBACK BoardOptions(HWND, UINT, WPARAM, LPARAM);
87 LRESULT CALLBACK NewVariant(HWND, UINT, WPARAM, LPARAM);
88 LRESULT CALLBACK IcsOptions(HWND, UINT, WPARAM, LPARAM);
89 LRESULT CALLBACK FontOptions(HWND, UINT, WPARAM, LPARAM);
90 LRESULT CALLBACK CommPortOptions(HWND, UINT, WPARAM, LPARAM);
91 LRESULT CALLBACK LoadOptions(HWND, UINT, WPARAM, LPARAM);
92 LRESULT CALLBACK SaveOptions(HWND, UINT, WPARAM, LPARAM);
93 LRESULT CALLBACK TimeControl(HWND, UINT, WPARAM, LPARAM);
94 VOID ChangeBoardSize(BoardSize newSize);
95 VOID PaintSampleSquare(
100 COLORREF squareOutlineColor,
101 COLORREF pieceDetailColor,
106 VOID PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color);
107 VOID SetBoardOptionEnables(HWND hDlg);
108 BoardSize BoardOptionsWhichRadio(HWND hDlg);
109 BOOL APIENTRY MyCreateFont(HWND hwnd, MyFont *font);
110 VOID UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca);
111 LRESULT CALLBACK ColorizeTextDialog(HWND , UINT, WPARAM, LPARAM);
112 VOID ColorizeTextPopup(HWND hwnd, ColorClass cc);
113 VOID SetIcsOptionEnables(HWND hDlg);
114 VOID SetSampleFontText(HWND hwnd, int id, const MyFont *mf);
115 VOID CopyFont(MyFont *dest, const MyFont *src);
116 void InitSoundComboData(SoundComboData *scd);
117 void ResetSoundComboData(SoundComboData *scd);
118 void InitSoundCombo(HWND hwndCombo, SoundComboData *scd);
119 int SoundDialogWhichRadio(HWND hDlg);
120 VOID SoundDialogSetEnables(HWND hDlg, int radio);
121 char * SoundDialogGetName(HWND hDlg, int radio);
122 void DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name);
123 VOID ParseCommSettings(char *arg, DCB *dcb);
124 VOID PrintCommSettings(FILE *f, char *name, DCB *dcb);
125 void InitCombo(HANDLE hwndCombo, ComboData *cd);
126 void SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value);
127 VOID SetLoadOptionEnables(HWND hDlg);
128 VOID SetSaveOptionEnables(HWND hDlg);
129 VOID SetTimeControlEnables(HWND hDlg);
131 /*---------------------------------------------------------------------------*\
133 * General Options Dialog functions
135 \*---------------------------------------------------------------------------*/
139 GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
141 static Boolean oldShowCoords;
142 static Boolean oldBlindfold;
143 static Boolean oldShowButtonBar;
146 case WM_INITDIALOG: /* message: initialize dialog box */
147 oldShowCoords = appData.showCoords;
148 oldBlindfold = appData.blindfold;
149 oldShowButtonBar = appData.showButtonBar;
151 /* Center the dialog over the application window */
152 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
154 /* Initialize the dialog items */
155 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
157 CHECK_BOX(OPT_AlwaysOnTop, alwaysOnTop);
158 CHECK_BOX(OPT_AlwaysQueen, appData.alwaysPromoteToQueen);
159 CHECK_BOX(OPT_AnimateDragging, appData.animateDragging);
160 CHECK_BOX(OPT_AnimateMoving, appData.animate);
161 CHECK_BOX(OPT_AutoFlag, appData.autoCallFlag);
162 CHECK_BOX(OPT_AutoFlipView, appData.autoFlipView);
163 CHECK_BOX(OPT_AutoRaiseBoard, appData.autoRaiseBoard);
164 CHECK_BOX(OPT_Blindfold, appData.blindfold);
165 CHECK_BOX(OPT_HighlightDragging, appData.highlightDragging);
166 CHECK_BOX(OPT_HighlightLastMove, appData.highlightLastMove);
167 CHECK_BOX(OPT_PeriodicUpdates, appData.periodicUpdates);
168 CHECK_BOX(OPT_PonderNextMove, appData.ponderNextMove);
169 CHECK_BOX(OPT_PopupExitMessage, appData.popupExitMessage);
170 CHECK_BOX(OPT_PopupMoveErrors, appData.popupMoveErrors);
171 CHECK_BOX(OPT_ShowButtonBar, appData.showButtonBar);
172 CHECK_BOX(OPT_ShowCoordinates, appData.showCoords);
173 CHECK_BOX(OPT_ShowThinking, appData.showThinking);
174 CHECK_BOX(OPT_TestLegality, appData.testLegality);
175 CHECK_BOX(OPT_HideThinkFromHuman, appData.hideThinkingFromHuman);
176 CHECK_BOX(OPT_SaveExtPGN, appData.saveExtendedInfoInPGN);
177 CHECK_BOX(OPT_ExtraInfoInMoveHistory, appData.showEvalInMoveHistory);
178 CHECK_BOX(OPT_HighlightMoveArrow, appData.highlightMoveWithArrow);
182 EnableWindow(GetDlgItem(hDlg, OPT_AutoFlag),
183 appData.icsActive || !appData.noChessProgram);
184 EnableWindow(GetDlgItem(hDlg, OPT_AutoFlipView),
185 appData.icsActive || !appData.noChessProgram);
186 EnableWindow(GetDlgItem(hDlg, OPT_PonderNextMove),
187 !appData.noChessProgram);
188 EnableWindow(GetDlgItem(hDlg, OPT_PeriodicUpdates),
189 !appData.noChessProgram && !appData.icsActive);
190 EnableWindow(GetDlgItem(hDlg, OPT_ShowThinking),
191 !appData.noChessProgram);
195 case WM_COMMAND: /* message: received a command */
196 switch (LOWORD(wParam)) {
198 /* Read changed options from the dialog box */
200 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
202 alwaysOnTop = IS_CHECKED(OPT_AlwaysOnTop);
203 appData.alwaysPromoteToQueen = IS_CHECKED(OPT_AlwaysQueen);
204 appData.animateDragging = IS_CHECKED(OPT_AnimateDragging);
205 appData.animate = IS_CHECKED(OPT_AnimateMoving);
206 appData.autoCallFlag = IS_CHECKED(OPT_AutoFlag);
207 appData.autoFlipView = IS_CHECKED(OPT_AutoFlipView);
208 appData.autoRaiseBoard = IS_CHECKED(OPT_AutoRaiseBoard);
209 appData.blindfold = IS_CHECKED(OPT_Blindfold);
210 appData.highlightDragging = IS_CHECKED(OPT_HighlightDragging);
211 appData.highlightLastMove = IS_CHECKED(OPT_HighlightLastMove);
212 PeriodicUpdatesEvent( IS_CHECKED(OPT_PeriodicUpdates));
213 PonderNextMoveEvent( IS_CHECKED(OPT_PonderNextMove));
214 appData.popupExitMessage = IS_CHECKED(OPT_PopupExitMessage);
215 appData.popupMoveErrors = IS_CHECKED(OPT_PopupMoveErrors);
216 appData.showButtonBar = IS_CHECKED(OPT_ShowButtonBar);
217 appData.showCoords = IS_CHECKED(OPT_ShowCoordinates);
218 // [HGM] thinking: next three moved up
219 appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN);
220 appData.hideThinkingFromHuman= IS_CHECKED(OPT_HideThinkFromHuman);
221 appData.showEvalInMoveHistory= IS_CHECKED(OPT_ExtraInfoInMoveHistory);
223 ShowThinkingEvent( IS_CHECKED(OPT_ShowThinking));
225 appData.showThinking = IS_CHECKED(OPT_ShowThinking);
226 ShowThinkingEvent(); // [HGM] thinking: tests four options
228 appData.testLegality = IS_CHECKED(OPT_TestLegality);
229 appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow);
233 SetWindowPos(hwndMain, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
234 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
237 SetWindowPos(hwndConsole, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
238 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
241 if (!appData.highlightLastMove) {
243 DrawPosition(FALSE, NULL);
246 * for some reason the redraw seems smoother when we invalidate
247 * the board rect after the call to EndDialog()
249 EndDialog(hDlg, TRUE);
251 if (oldShowButtonBar != appData.showButtonBar) {
252 InitDrawingSizes(boardSize, 0);
253 } else if ((oldShowCoords != appData.showCoords) ||
254 (oldBlindfold != appData.blindfold)) {
255 InvalidateRect(hwndMain, &boardRect, FALSE);
261 EndDialog(hDlg, FALSE);
271 GeneralOptionsPopup(HWND hwnd)
275 lpProc = MakeProcInstance((FARPROC)GeneralOptionsDialog, hInst);
276 DialogBox(hInst, MAKEINTRESOURCE(DLG_GeneralOptions), hwnd,
278 FreeProcInstance(lpProc);
280 /*---------------------------------------------------------------------------*\
282 * Board Options Dialog functions
284 \*---------------------------------------------------------------------------*/
286 const int SAMPLE_SQ_SIZE = 54;
289 ChangeBoardSize(BoardSize newSize)
291 if (newSize != boardSize) {
293 InitDrawingSizes(boardSize, 0);
301 COLORREF squareColor,
303 COLORREF squareOutlineColor,
304 COLORREF pieceDetailColor,
311 HBRUSH brushSquareOutline;
313 HBRUSH brushPieceDetail;
314 HBRUSH oldBrushPiece;
315 HBRUSH oldBrushSquare;
316 HBITMAP oldBitmapMem;
317 HBITMAP oldBitmapTemp;
318 HBITMAP bufferBitmap;
320 HDC hdcScreen, hdcMem, hdcTemp;
322 HWND hCtrl = GetDlgItem(hwnd, ctrlid);
327 const int OUTLINE = 2;
328 const int BORDER = 4;
330 InvalidateRect(hCtrl, NULL, TRUE);
332 GetClientRect(hCtrl, &rect);
333 x = rect.left + (BORDER / 2);
334 y = rect.top + (BORDER / 2);
335 hdcScreen = GetDC(hCtrl);
336 hdcMem = CreateCompatibleDC(hdcScreen);
337 hdcTemp = CreateCompatibleDC(hdcScreen);
339 bufferBitmap = CreateCompatibleBitmap(hdcScreen, rect.right-rect.left+1,
340 rect.bottom-rect.top+1);
341 oldBitmapMem = SelectObject(hdcMem, bufferBitmap);
343 SelectPalette(hdcMem, hPal, FALSE);
345 brushSquare = CreateSolidBrush(squareColor);
346 brushSquareOutline = CreateSolidBrush(squareOutlineColor);
347 brushPiece = CreateSolidBrush(pieceColor);
348 brushPieceDetail = CreateSolidBrush(pieceDetailColor);
351 * first draw the rectangle
353 pen = CreatePen(PS_SOLID, BORDER, squareOutlineColor);
354 oldPen = (HPEN) SelectObject(hdcMem, pen);
355 oldBrushSquare = (HBRUSH)SelectObject(hdcMem, brushSquare);
356 Rectangle(hdcMem, rect.left, rect.top, rect.right, rect.bottom);
362 oldBitmapTemp = SelectObject(hdcTemp, pieces[OUTLINE]);
363 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, hdcTemp, 0, 0,
364 isWhitePiece ? SRCCOPY : NOTSRCCOPY);
365 SelectObject(hdcTemp, oldBitmapTemp);
368 oldBitmapTemp = SelectObject(hdcTemp, pieces[WHITE]);
369 oldBrushPiece = SelectObject(hdcMem, brushPiece);
370 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
371 hdcTemp, 0, 0, 0x00B8074A);
373 /* Use pieceDetailColor for outline of white pieces */
374 SelectObject(hdcTemp, pieces[OUTLINE]);
375 SelectObject(hdcMem, brushPieceDetail);
376 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
377 hdcTemp, 0, 0, 0x00B8074A);
379 /* Use black for outline of white pieces */
380 SelectObject(hdcTemp, pieces[OUTLINE]);
381 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
382 hdcTemp, 0, 0, SRCAND);
386 /* Use pieceDetailColor for details of black pieces */
387 /* Requires filled-in solid bitmaps (BLACK_PIECE class); the
388 WHITE_PIECE ones aren't always the right shape. */
389 oldBitmapTemp = SelectObject(hdcTemp, pieces[BLACK]);
390 oldBrushPiece = SelectObject(hdcMem, brushPieceDetail);
391 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
392 hdcTemp, 0, 0, 0x00B8074A);
393 SelectObject(hdcTemp, pieces[SOLID]);
394 SelectObject(hdcMem, brushPiece);
395 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
396 hdcTemp, 0, 0, 0x00B8074A);
398 /* Use square color for details of black pieces */
399 oldBitmapTemp = SelectObject(hdcTemp, pieces[SOLID]);
400 oldBrushPiece = SelectObject(hdcMem, brushPiece);
401 BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,
402 hdcTemp, 0, 0, 0x00B8074A);
405 SelectObject(hdcMem, oldBrushPiece);
406 SelectObject(hdcTemp, oldBitmapTemp);
409 * copy the memory dc to the screen
411 SelectObject(hdcMem, bufferBitmap);
412 BitBlt(hdcScreen, rect.left, rect.top,
413 rect.right - rect.left,
414 rect.bottom - rect.top,
415 hdcMem, rect.left, rect.top, SRCCOPY);
416 SelectObject(hdcMem, oldBitmapMem);
420 SelectObject(hdcMem, oldBrushPiece);
421 SelectObject(hdcMem, oldPen);
422 DeleteObject(brushPiece);
423 DeleteObject(brushPieceDetail);
424 DeleteObject(brushSquare);
425 DeleteObject(brushSquareOutline);
429 ReleaseDC(hCtrl, hdcScreen);
434 PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color)
437 HBRUSH brush, oldBrush;
439 HWND hCtrl = GetDlgItem(hwnd, ctrlid);
442 InvalidateRect(hCtrl, NULL, TRUE);
444 GetClientRect(hCtrl, &rect);
445 brush = CreateSolidBrush(color);
446 oldBrush = (HBRUSH)SelectObject(hdc, brush);
447 Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
448 SelectObject(hdc, oldBrush);
450 ReleaseDC(hCtrl, hdc);
455 SetBoardOptionEnables(HWND hDlg)
457 if (IsDlgButtonChecked(hDlg, OPT_Monochrome)) {
458 ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_HIDE);
459 ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_HIDE);
460 ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_HIDE);
461 ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_HIDE);
463 EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), FALSE);
464 EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), FALSE);
465 EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), FALSE);
466 EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), FALSE);
468 ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_SHOW);
469 ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_SHOW);
470 ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_SHOW);
471 ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_SHOW);
473 EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), TRUE);
474 EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), TRUE);
475 EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), TRUE);
476 EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), TRUE);
481 BoardOptionsWhichRadio(HWND hDlg)
483 return (IsDlgButtonChecked(hDlg, OPT_SizeTiny) ? SizeTiny :
484 (IsDlgButtonChecked(hDlg, OPT_SizeTeeny) ? SizeTeeny :
485 (IsDlgButtonChecked(hDlg, OPT_SizeDinky) ? SizeDinky :
486 (IsDlgButtonChecked(hDlg, OPT_SizePetite) ? SizePetite :
487 (IsDlgButtonChecked(hDlg, OPT_SizeSlim) ? SizeSlim :
488 (IsDlgButtonChecked(hDlg, OPT_SizeSmall) ? SizeSmall :
489 (IsDlgButtonChecked(hDlg, OPT_SizeMediocre) ? SizeMediocre :
490 (IsDlgButtonChecked(hDlg, OPT_SizeMiddling) ? SizeMiddling :
491 (IsDlgButtonChecked(hDlg, OPT_SizeAverage) ? SizeAverage :
492 (IsDlgButtonChecked(hDlg, OPT_SizeModerate) ? SizeModerate :
493 (IsDlgButtonChecked(hDlg, OPT_SizeMedium) ? SizeMedium :
494 (IsDlgButtonChecked(hDlg, OPT_SizeBulky) ? SizeBulky :
495 (IsDlgButtonChecked(hDlg, OPT_SizeLarge) ? SizeLarge :
496 (IsDlgButtonChecked(hDlg, OPT_SizeBig) ? SizeBig :
497 (IsDlgButtonChecked(hDlg, OPT_SizeHuge) ? SizeHuge :
498 (IsDlgButtonChecked(hDlg, OPT_SizeGiant) ? SizeGiant :
499 (IsDlgButtonChecked(hDlg, OPT_SizeColossal) ? SizeColossal :
500 SizeTitanic )))))))))))))))));
504 BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
506 static Boolean mono, white, flip;
507 static BoardSize size;
508 static COLORREF lsc, dsc, wpc, bpc, hsc, phc;
509 static HBITMAP pieces[3];
512 case WM_INITDIALOG: /* message: initialize dialog box */
513 /* Center the dialog over the application window */
514 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
515 /* Initialize the dialog items */
518 CheckDlgButton(hDlg, OPT_SizeTiny, TRUE);
521 CheckDlgButton(hDlg, OPT_SizeTeeny, TRUE);
524 CheckDlgButton(hDlg, OPT_SizeDinky, TRUE);
527 CheckDlgButton(hDlg, OPT_SizePetite, TRUE);
530 CheckDlgButton(hDlg, OPT_SizeSlim, TRUE);
533 CheckDlgButton(hDlg, OPT_SizeSmall, TRUE);
536 CheckDlgButton(hDlg, OPT_SizeMediocre, TRUE);
539 CheckDlgButton(hDlg, OPT_SizeMiddling, TRUE);
542 CheckDlgButton(hDlg, OPT_SizeAverage, TRUE);
545 CheckDlgButton(hDlg, OPT_SizeModerate, TRUE);
548 CheckDlgButton(hDlg, OPT_SizeMedium, TRUE);
551 CheckDlgButton(hDlg, OPT_SizeBulky, TRUE);
554 CheckDlgButton(hDlg, OPT_SizeLarge, TRUE);
557 CheckDlgButton(hDlg, OPT_SizeBig, TRUE);
560 CheckDlgButton(hDlg, OPT_SizeHuge, TRUE);
563 CheckDlgButton(hDlg, OPT_SizeGiant, TRUE);
566 CheckDlgButton(hDlg, OPT_SizeColossal, TRUE);
569 CheckDlgButton(hDlg, OPT_SizeTitanic, TRUE);
572 if (appData.monoMode)
573 CheckDlgButton(hDlg, OPT_Monochrome, TRUE);
575 if (appData.allWhite)
576 CheckDlgButton(hDlg, OPT_AllWhite, TRUE);
578 if (appData.upsideDown)
579 CheckDlgButton(hDlg, OPT_UpsideDown, TRUE);
581 pieces[0] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "s");
582 pieces[1] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "w");
583 pieces[2] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "o");
585 lsc = lightSquareColor;
586 dsc = darkSquareColor;
587 wpc = whitePieceColor;
588 bpc = blackPieceColor;
589 hsc = highlightSquareColor;
590 phc = premoveHighlightColor;
591 mono = appData.monoMode;
592 white= appData.allWhite;
593 flip = appData.upsideDown;
596 SetBoardOptionEnables(hDlg);
600 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
601 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
602 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
603 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
604 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
605 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
606 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
608 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
609 FALSE, mono, pieces);
613 case WM_COMMAND: /* message: received a command */
614 switch (LOWORD(wParam)) {
617 * if we call EndDialog() after the call to ChangeBoardSize(),
618 * then ChangeBoardSize() does not take effect, although the new
619 * boardSize is saved. Go figure...
621 EndDialog(hDlg, TRUE);
623 size = BoardOptionsWhichRadio(hDlg);
626 * did any settings change?
628 if (size != boardSize) {
629 ChangeBoardSize(size);
632 if ((mono != appData.monoMode) ||
633 (lsc != lightSquareColor) ||
634 (dsc != darkSquareColor) ||
635 (wpc != whitePieceColor) ||
636 (bpc != blackPieceColor) ||
637 (hsc != highlightSquareColor) ||
638 (flip != appData.upsideDown) ||
639 (white != appData.allWhite) ||
640 (phc != premoveHighlightColor)) {
642 lightSquareColor = lsc;
643 darkSquareColor = dsc;
644 whitePieceColor = wpc;
645 blackPieceColor = bpc;
646 highlightSquareColor = hsc;
647 premoveHighlightColor = phc;
648 appData.monoMode = mono;
649 appData.allWhite = white;
650 appData.upsideDown = flip;
653 InitDrawingSizes(boardSize, 0);
654 InvalidateRect(hwndMain, &boardRect, FALSE);
656 DeleteObject(pieces[0]);
657 DeleteObject(pieces[1]);
658 DeleteObject(pieces[2]);
662 DeleteObject(pieces[0]);
663 DeleteObject(pieces[1]);
664 DeleteObject(pieces[2]);
665 EndDialog(hDlg, FALSE);
668 case OPT_ChooseLightSquareColor:
669 if (ChangeColor(hDlg, &lsc))
670 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
671 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
675 case OPT_ChooseDarkSquareColor:
676 if (ChangeColor(hDlg, &dsc))
677 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
678 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
679 FALSE, mono, pieces);
682 case OPT_ChooseWhitePieceColor:
683 if (ChangeColor(hDlg, &wpc))
684 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
685 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
689 case OPT_ChooseBlackPieceColor:
690 if (ChangeColor(hDlg, &bpc))
691 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
692 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
693 FALSE, mono, pieces);
696 case OPT_ChooseHighlightSquareColor:
697 if (ChangeColor(hDlg, &hsc))
698 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
699 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
703 case OPT_ChoosePremoveHighlightColor:
704 if (ChangeColor(hDlg, &phc))
705 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
706 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
707 FALSE, mono, pieces);
710 case OPT_DefaultBoardColors:
711 lsc = ParseColorName(LIGHT_SQUARE_COLOR);
712 dsc = ParseColorName(DARK_SQUARE_COLOR);
713 wpc = ParseColorName(WHITE_PIECE_COLOR);
714 bpc = ParseColorName(BLACK_PIECE_COLOR);
715 hsc = ParseColorName(HIGHLIGHT_SQUARE_COLOR);
716 phc = ParseColorName(PREMOVE_HIGHLIGHT_COLOR);
720 CheckDlgButton(hDlg, OPT_Monochrome, FALSE);
721 CheckDlgButton(hDlg, OPT_AllWhite, FALSE);
722 CheckDlgButton(hDlg, OPT_UpsideDown, FALSE);
723 PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);
724 PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);
725 PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);
726 PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);
727 PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);
728 PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);
729 SetBoardOptionEnables(hDlg);
730 PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,
732 PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,
733 FALSE, mono, pieces);
738 SetBoardOptionEnables(hDlg);
743 SetBoardOptionEnables(hDlg);
748 SetBoardOptionEnables(hDlg);
758 BoardOptionsPopup(HWND hwnd)
760 FARPROC lpProc = MakeProcInstance((FARPROC)BoardOptionsDialog, hInst);
761 DialogBox(hInst, MAKEINTRESOURCE(DLG_BoardOptions), hwnd,
763 FreeProcInstance(lpProc);
767 VariantWhichRadio(HWND hDlg)
769 return (IsDlgButtonChecked(hDlg, OPT_VariantFairy) ? VariantFairy :
770 (IsDlgButtonChecked(hDlg, OPT_VariantGothic) ? VariantGothic :
771 (IsDlgButtonChecked(hDlg, OPT_VariantCrazyhouse) ? VariantCrazyhouse :
772 (IsDlgButtonChecked(hDlg, OPT_VariantBughouse) ? VariantBughouse :
773 (IsDlgButtonChecked(hDlg, OPT_VariantCourier) ? VariantCourier :
774 (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :
775 (IsDlgButtonChecked(hDlg, OPT_VariantShogi) ? VariantShogi :
776 (IsDlgButtonChecked(hDlg, OPT_VariantXiangqi) ? VariantXiangqi :
777 (IsDlgButtonChecked(hDlg, OPT_VariantCapablanca) ? VariantCapablanca :
778 (IsDlgButtonChecked(hDlg, OPT_VariantTwoKings) ? VariantTwoKings :
779 (IsDlgButtonChecked(hDlg, OPT_VariantKnightmate) ? VariantKnightmate :
780 (IsDlgButtonChecked(hDlg, OPT_VariantLosers) ? VariantLosers :
781 (IsDlgButtonChecked(hDlg, OPT_VariantSuicide) ? VariantSuicide :
782 (IsDlgButtonChecked(hDlg, OPT_VariantAtomic) ? VariantAtomic :
783 (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :
784 (IsDlgButtonChecked(hDlg, OPT_VariantFRC) ? VariantFischeRandom :
785 (IsDlgButtonChecked(hDlg, OPT_VariantCylinder) ? VariantCylinder :
786 (IsDlgButtonChecked(hDlg, OPT_VariantFalcon) ? VariantFalcon :
787 (IsDlgButtonChecked(hDlg, OPT_VariantCRC) ? VariantCapaRandom :
788 (IsDlgButtonChecked(hDlg, OPT_VariantSuper) ? VariantSuper :
789 (IsDlgButtonChecked(hDlg, OPT_VariantBerolina) ? VariantBerolina :
790 (IsDlgButtonChecked(hDlg, OPT_VariantJanus) ? VariantJanus :
791 (IsDlgButtonChecked(hDlg, OPT_VariantWildcastle) ? VariantWildCastle :
792 (IsDlgButtonChecked(hDlg, OPT_VariantNocastle) ? VariantNoCastle :
793 VariantNormal ))))))))))))))))))))))));
797 NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
800 static VariantClass v;
801 static COLORREF lsc, dsc, wpc, bpc, hsc, phc;
802 static HBITMAP pieces[3];
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);
886 SetDlgItemInt( hDlg, IDC_Files, -1, TRUE );
887 SendDlgItemMessage( hDlg, IDC_Files, EM_SETSEL, 0, -1 );
889 SetDlgItemInt( hDlg, IDC_Ranks, -1, TRUE );
890 SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );
892 SetDlgItemInt( hDlg, IDC_Holdings, -1, TRUE );
893 SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );
895 n1_ok = n2_ok = n3_ok = FALSE;
899 case WM_COMMAND: /* message: received a command */
900 switch (LOWORD(wParam)) {
903 * if we call EndDialog() after the call to ChangeBoardSize(),
904 * then ChangeBoardSize() does not take effect, although the new
905 * boardSize is saved. Go figure...
907 EndDialog(hDlg, TRUE);
909 v = VariantWhichRadio(hDlg);
910 if(!appData.noChessProgram) { char *name = VariantName(v), buf[MSG_SIZ];
911 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
912 /* [HGM] in protocol 2 we check if variant is suported by engine */
913 sprintf(buf, "Variant %s not supported by %s", name, first.tidy);
914 DisplayError(buf, 0);
915 return TRUE; /* treat as "Cancel" if first engine does not support it */
917 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
918 sprintf(buf, "Warning: second engine (%s) does not support this!", second.tidy);
919 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
923 gameInfo.variant = v;
924 appData.variant = VariantName(v);
926 appData.NrFiles = (int) GetDlgItemInt(hDlg, IDC_Files, NULL, FALSE );
927 appData.NrRanks = (int) GetDlgItemInt(hDlg, IDC_Ranks, NULL, FALSE );
928 appData.holdingsSize = (int) GetDlgItemInt(hDlg, IDC_Holdings, NULL, FALSE );
930 if(!n1_ok) appData.NrFiles = -1;
931 if(!n2_ok) appData.NrRanks = -1;
932 if(!n3_ok) appData.holdingsSize = -1;
934 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
935 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
936 appData.pieceToCharTable = NULL;
942 EndDialog(hDlg, FALSE);
948 if( HIWORD(wParam) == EN_CHANGE ) {
950 GetDlgItemInt(hDlg, IDC_Files, &n1_ok, FALSE );
951 GetDlgItemInt(hDlg, IDC_Ranks, &n2_ok, FALSE );
952 GetDlgItemInt(hDlg, IDC_Holdings, &n3_ok, FALSE );
954 /*EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok ? TRUE : FALSE );*/
965 NewVariantPopup(HWND hwnd)
967 FARPROC lpProc = MakeProcInstance((FARPROC)NewVariantDialog, hInst);
968 DialogBox(hInst, MAKEINTRESOURCE(DLG_NewVariant), hwnd,
970 FreeProcInstance(lpProc);
973 /*---------------------------------------------------------------------------*\
975 * ICS Options Dialog functions
977 \*---------------------------------------------------------------------------*/
980 MyCreateFont(HWND hwnd, MyFont *font)
985 /* Initialize members of the CHOOSEFONT structure. */
986 cf.lStructSize = sizeof(CHOOSEFONT);
989 cf.lpLogFont = &font->lf;
991 cf.Flags = CF_SCREENFONTS|/*CF_ANSIONLY|*/CF_INITTOLOGFONTSTRUCT;
992 cf.rgbColors = RGB(0,0,0);
994 cf.lpfnHook = (LPCFHOOKPROC)NULL;
995 cf.lpTemplateName = (LPSTR)NULL;
996 cf.hInstance = (HINSTANCE) NULL;
997 cf.lpszStyle = (LPSTR)NULL;
998 cf.nFontType = SCREEN_FONTTYPE;
1002 /* Display the CHOOSEFONT common-dialog box. */
1003 if (!ChooseFont(&cf)) {
1007 /* Create a logical font based on the user's */
1008 /* selection and return a handle identifying */
1010 hf = CreateFontIndirect(cf.lpLogFont);
1016 font->mfp.pointSize = (float) (cf.iPointSize / 10.0);
1017 font->mfp.bold = (font->lf.lfWeight >= FW_BOLD);
1018 font->mfp.italic = font->lf.lfItalic;
1019 font->mfp.underline = font->lf.lfUnderline;
1020 font->mfp.strikeout = font->lf.lfStrikeOut;
1021 strcpy(font->mfp.faceName, font->lf.lfFaceName);
1027 UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca)
1030 cf.cbSize = sizeof(CHARFORMAT);
1032 CFM_COLOR|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE;
1033 cf.crTextColor = mca->color;
1034 cf.dwEffects = mca->effects;
1035 strcpy(cf.szFaceName, font[boardSize][CONSOLE_FONT]->mfp.faceName);
1037 * The 20.0 below is in fact documented. yHeight is expressed in twips.
1038 * A twip is 1/20 of a font's point size. See documentation of CHARFORMAT.
1041 cf.yHeight = (int)(font[boardSize][CONSOLE_FONT]->mfp.pointSize * 20.0 + 0.5);
1042 cf.bCharSet = DEFAULT_CHARSET; /* should be ignored anyway */
1043 cf.bPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
1044 SendDlgItemMessage(hDlg, id, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1048 ColorizeTextDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1050 static MyColorizeAttribs mca;
1051 static ColorClass cc;
1052 COLORREF background = (COLORREF)0;
1056 cc = (ColorClass)lParam;
1057 mca = colorizeAttribs[cc];
1058 /* Center the dialog over the application window */
1059 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1060 /* Initialize the dialog items */
1061 CheckDlgButton(hDlg, OPT_Bold, (mca.effects & CFE_BOLD) != 0);
1062 CheckDlgButton(hDlg, OPT_Italic, (mca.effects & CFE_ITALIC) != 0);
1063 CheckDlgButton(hDlg, OPT_Underline, (mca.effects & CFE_UNDERLINE) != 0);
1064 CheckDlgButton(hDlg, OPT_Strikeout, (mca.effects & CFE_STRIKEOUT) != 0);
1066 /* get the current background color from the parent window */
1067 SendMessage(GetWindow(hDlg, GW_OWNER),WM_COMMAND,
1068 (WPARAM)WM_USER_GetConsoleBackground,
1069 (LPARAM)&background);
1071 /* set the background color */
1072 SendDlgItemMessage(hDlg, OPT_Sample, EM_SETBKGNDCOLOR, FALSE, background);
1074 SetDlgItemText(hDlg, OPT_Sample, mca.name);
1075 UpdateSampleText(hDlg, OPT_Sample, &mca);
1078 case WM_COMMAND: /* message: received a command */
1079 switch (LOWORD(wParam)) {
1081 /* Read changed options from the dialog box */
1082 colorizeAttribs[cc] = mca;
1083 textAttribs[cc].color = mca.color;
1084 textAttribs[cc].effects = mca.effects;
1085 Colorize(currentColorClass, TRUE);
1086 if (cc == ColorNormal) {
1088 cf.cbSize = sizeof(CHARFORMAT);
1089 cf.dwMask = CFM_COLOR;
1090 cf.crTextColor = mca.color;
1091 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1092 EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1094 EndDialog(hDlg, TRUE);
1098 EndDialog(hDlg, FALSE);
1101 case OPT_ChooseColor:
1102 ChangeColor(hDlg, &mca.color);
1103 UpdateSampleText(hDlg, OPT_Sample, &mca);
1108 (IsDlgButtonChecked(hDlg, OPT_Bold) ? CFE_BOLD : 0) |
1109 (IsDlgButtonChecked(hDlg, OPT_Italic) ? CFE_ITALIC : 0) |
1110 (IsDlgButtonChecked(hDlg, OPT_Underline) ? CFE_UNDERLINE : 0) |
1111 (IsDlgButtonChecked(hDlg, OPT_Strikeout) ? CFE_STRIKEOUT : 0);
1112 UpdateSampleText(hDlg, OPT_Sample, &mca);
1121 ColorizeTextPopup(HWND hwnd, ColorClass cc)
1125 lpProc = MakeProcInstance((FARPROC)ColorizeTextDialog, hInst);
1126 DialogBoxParam(hInst, MAKEINTRESOURCE(DLG_Colorize),
1127 hwnd, (DLGPROC)lpProc, (LPARAM) cc);
1128 FreeProcInstance(lpProc);
1132 SetIcsOptionEnables(HWND hDlg)
1134 #define ENABLE_DLG_ITEM(x,y) EnableWindow(GetDlgItem(hDlg,(x)), (y))
1136 UINT state = IsDlgButtonChecked(hDlg, OPT_Premove);
1137 ENABLE_DLG_ITEM(OPT_PremoveWhite, state);
1138 ENABLE_DLG_ITEM(OPT_PremoveWhiteText, state);
1139 ENABLE_DLG_ITEM(OPT_PremoveBlack, state);
1140 ENABLE_DLG_ITEM(OPT_PremoveBlackText, state);
1142 ENABLE_DLG_ITEM(OPT_IcsAlarmTime, IsDlgButtonChecked(hDlg, OPT_IcsAlarm));
1144 #undef ENABLE_DLG_ITEM
1149 IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1154 static COLORREF cbc;
1155 static MyColorizeAttribs *mca;
1159 case WM_INITDIALOG: /* message: initialize dialog box */
1161 mca = colorizeAttribs;
1163 for (i=0; i < NColorClasses - 1; i++) {
1164 mca[i].color = textAttribs[i].color;
1165 mca[i].effects = textAttribs[i].effects;
1167 cbc = consoleBackgroundColor;
1169 /* Center the dialog over the application window */
1170 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1172 /* Initialize the dialog items */
1173 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
1175 CHECK_BOX(OPT_AutoComment, appData.autoComment);
1176 CHECK_BOX(OPT_AutoObserve, appData.autoObserve);
1177 CHECK_BOX(OPT_GetMoveList, appData.getMoveList);
1178 CHECK_BOX(OPT_LocalLineEditing, appData.localLineEditing);
1179 CHECK_BOX(OPT_QuietPlay, appData.quietPlay);
1180 CHECK_BOX(OPT_Premove, appData.premove);
1181 CHECK_BOX(OPT_PremoveWhite, appData.premoveWhite);
1182 CHECK_BOX(OPT_PremoveBlack, appData.premoveBlack);
1183 CHECK_BOX(OPT_IcsAlarm, appData.icsAlarm);
1184 CHECK_BOX(OPT_DontColorize, !appData.colorize);
1188 sprintf(buf, "%d", appData.icsAlarmTime / 1000);
1189 SetDlgItemText(hDlg, OPT_IcsAlarmTime, buf);
1190 SetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText);
1191 SetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText);
1193 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1194 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1195 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1196 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1197 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1198 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1199 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1200 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1201 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1202 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1204 SetDlgItemText(hDlg, OPT_SampleShout, mca[ColorShout].name);
1205 SetDlgItemText(hDlg, OPT_SampleSShout, mca[ColorSShout].name);
1206 SetDlgItemText(hDlg, OPT_SampleChannel1, mca[ColorChannel1].name);
1207 SetDlgItemText(hDlg, OPT_SampleChannel, mca[ColorChannel].name);
1208 SetDlgItemText(hDlg, OPT_SampleKibitz, mca[ColorKibitz].name);
1209 SetDlgItemText(hDlg, OPT_SampleTell, mca[ColorTell].name);
1210 SetDlgItemText(hDlg, OPT_SampleChallenge, mca[ColorChallenge].name);
1211 SetDlgItemText(hDlg, OPT_SampleRequest, mca[ColorRequest].name);
1212 SetDlgItemText(hDlg, OPT_SampleSeek, mca[ColorSeek].name);
1213 SetDlgItemText(hDlg, OPT_SampleNormal, mca[ColorNormal].name);
1215 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1216 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1217 UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]);
1218 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1219 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1220 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1221 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1222 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1223 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1224 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1226 SetIcsOptionEnables(hDlg);
1229 case WM_COMMAND: /* message: received a command */
1230 switch (LOWORD(wParam)) {
1232 case WM_USER_GetConsoleBackground:
1233 /* the ColorizeTextDialog needs the current background color */
1234 colorref = (COLORREF *)lParam;
1239 /* Read changed options from the dialog box */
1240 GetDlgItemText(hDlg, OPT_IcsAlarmTime, buf, MSG_SIZ);
1241 if (sscanf(buf, "%d", &number) != 1 || (number < 0)){
1242 MessageBox(hDlg, "Invalid ICS Alarm Time",
1243 "Option Error", MB_OK|MB_ICONEXCLAMATION);
1247 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
1249 appData.icsAlarm = IS_CHECKED(OPT_IcsAlarm);
1250 appData.premove = IS_CHECKED(OPT_Premove);
1251 appData.premoveWhite = IS_CHECKED(OPT_PremoveWhite);
1252 appData.premoveBlack = IS_CHECKED(OPT_PremoveBlack);
1253 appData.autoComment = IS_CHECKED(OPT_AutoComment);
1254 appData.autoObserve = IS_CHECKED(OPT_AutoObserve);
1255 appData.getMoveList = IS_CHECKED(OPT_GetMoveList);
1256 appData.localLineEditing = IS_CHECKED(OPT_LocalLineEditing);
1257 appData.quietPlay = IS_CHECKED(OPT_QuietPlay);
1261 appData.icsAlarmTime = number * 1000;
1262 GetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText, 5);
1263 GetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText, 5);
1265 if (appData.localLineEditing) {
1274 (Boolean)!IsDlgButtonChecked(hDlg, OPT_DontColorize);
1276 if (!appData.colorize) {
1278 COLORREF background = ParseColorName(COLOR_BKGD);
1280 SetDefaultTextAttribs();
1281 Colorize(currentColorClass);
1283 cf.cbSize = sizeof(CHARFORMAT);
1284 cf.dwMask = CFM_COLOR;
1285 cf.crTextColor = ParseColorName(COLOR_NORMAL);
1287 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1288 EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1289 SendDlgItemMessage(hwndConsole, OPT_ConsoleText,
1290 EM_SETBKGNDCOLOR, FALSE, background);
1291 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1292 EM_SETBKGNDCOLOR, FALSE, background);
1295 if (cbc != consoleBackgroundColor) {
1296 consoleBackgroundColor = cbc;
1297 if (appData.colorize) {
1298 SendDlgItemMessage(hwndConsole, OPT_ConsoleText,
1299 EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);
1300 SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,
1301 EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);
1305 for (i=0; i < NColorClasses - 1; i++) {
1306 textAttribs[i].color = mca[i].color;
1307 textAttribs[i].effects = mca[i].effects;
1310 EndDialog(hDlg, TRUE);
1314 EndDialog(hDlg, FALSE);
1317 case OPT_ChooseShoutColor:
1318 ColorizeTextPopup(hDlg, ColorShout);
1319 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1322 case OPT_ChooseSShoutColor:
1323 ColorizeTextPopup(hDlg, ColorSShout);
1324 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1327 case OPT_ChooseChannel1Color:
1328 ColorizeTextPopup(hDlg, ColorChannel1);
1329 UpdateSampleText(hDlg, OPT_SampleChannel1,
1330 &colorizeAttribs[ColorChannel1]);
1333 case OPT_ChooseChannelColor:
1334 ColorizeTextPopup(hDlg, ColorChannel);
1335 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1338 case OPT_ChooseKibitzColor:
1339 ColorizeTextPopup(hDlg, ColorKibitz);
1340 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1343 case OPT_ChooseTellColor:
1344 ColorizeTextPopup(hDlg, ColorTell);
1345 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1348 case OPT_ChooseChallengeColor:
1349 ColorizeTextPopup(hDlg, ColorChallenge);
1350 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1353 case OPT_ChooseRequestColor:
1354 ColorizeTextPopup(hDlg, ColorRequest);
1355 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1358 case OPT_ChooseSeekColor:
1359 ColorizeTextPopup(hDlg, ColorSeek);
1360 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1363 case OPT_ChooseNormalColor:
1364 ColorizeTextPopup(hDlg, ColorNormal);
1365 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1368 case OPT_ChooseBackgroundColor:
1369 if (ChangeColor(hDlg, &cbc)) {
1370 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1371 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1372 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1373 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1374 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1375 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1376 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1377 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1378 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1379 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1383 case OPT_DefaultColors:
1384 for (i=0; i < NColorClasses - 1; i++)
1385 ParseAttribs(&mca[i].color,
1387 defaultTextAttribs[i]);
1389 cbc = ParseColorName(COLOR_BKGD);
1390 SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc);
1391 SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc);
1392 SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc);
1393 SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc);
1394 SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc);
1395 SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc);
1396 SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);
1397 SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc);
1398 SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc);
1399 SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc);
1401 UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);
1402 UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);
1403 UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]);
1404 UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);
1405 UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);
1406 UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);
1407 UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);
1408 UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);
1409 UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);
1410 UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);
1414 SetIcsOptionEnables(hDlg);
1423 IcsOptionsPopup(HWND hwnd)
1425 FARPROC lpProc = MakeProcInstance((FARPROC)IcsOptionsDialog, hInst);
1426 DialogBox(hInst, MAKEINTRESOURCE(DLG_IcsOptions), hwnd,
1428 FreeProcInstance(lpProc);
1431 /*---------------------------------------------------------------------------*\
1433 * Fonts Dialog functions
1435 \*---------------------------------------------------------------------------*/
1438 SetSampleFontText(HWND hwnd, int id, const MyFont *mf)
1445 RECT rectClient, rectFormat;
1450 len = sprintf(buf, "%.0f pt. %s%s%s\n",
1451 mf->mfp.pointSize, mf->mfp.faceName,
1452 mf->mfp.bold ? " bold" : "",
1453 mf->mfp.italic ? " italic" : "");
1454 SetDlgItemText(hwnd, id, buf);
1456 hControl = GetDlgItem(hwnd, id);
1457 hdc = GetDC(hControl);
1458 SetMapMode(hdc, MM_TEXT); /* 1 pixel == 1 logical unit */
1459 oldFont = SelectObject(hdc, mf->hf);
1461 /* get number of logical units necessary to display font name */
1462 GetTextExtentPoint32(hdc, buf, len, &size);
1464 /* calculate formatting rectangle in the rich edit control.
1465 * May be larger or smaller than the actual control.
1467 GetClientRect(hControl, &rectClient);
1468 center.x = (rectClient.left + rectClient.right) / 2;
1469 center.y = (rectClient.top + rectClient.bottom) / 2;
1470 rectFormat.top = center.y - (size.cy / 2) - 1;
1471 rectFormat.bottom = center.y + (size.cy / 2) + 1;
1472 rectFormat.left = center.x - (size.cx / 2) - 1;
1473 rectFormat.right = center.x + (size.cx / 2) + 1;
1476 fprintf(debugFP, "\nfont: %s\n"
1477 "center.x %d, centerY %d\n"
1478 "size.cx %d, size.cy %d\n"
1479 "client.top %d, bottom %d, left %d, right %d\n"
1480 "format.top %d, bottom %d, left %d, right %d\n",
1484 rectClient.top, rectClient.bottom, rectClient.left,
1486 rectFormat.top, rectFormat.bottom, rectFormat.left,
1490 cf.cbSize = sizeof(CHARFORMAT);
1491 cf.dwMask = CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_BOLD|CFM_ITALIC;
1493 if (mf->lf.lfWeight == FW_BOLD) cf.dwEffects |= CFE_BOLD;
1494 if (mf->lf.lfItalic) cf.dwEffects |= CFE_ITALIC;
1495 strcpy(cf.szFaceName, mf->mfp.faceName);
1497 * yHeight is expressed in twips. A twip is 1/20 of a font's point
1498 * size. See documentation of CHARFORMAT. --msw
1500 cf.yHeight = (int)(mf->mfp.pointSize * 20.0 + 0.5);
1501 cf.bCharSet = mf->lf.lfCharSet;
1502 cf.bPitchAndFamily = mf->lf.lfPitchAndFamily;
1504 /* format the text in the rich edit control */
1505 SendMessage(hControl, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf);
1506 SendMessage(hControl, EM_SETRECT, (WPARAM)0, (LPARAM) &rectFormat);
1509 SelectObject(hdc, oldFont);
1510 ReleaseDC(hControl, hdc);
1514 CopyFont(MyFont *dest, const MyFont *src)
1516 dest->mfp.pointSize = src->mfp.pointSize;
1517 dest->mfp.bold = src->mfp.bold;
1518 dest->mfp.italic = src->mfp.italic;
1519 dest->mfp.underline = src->mfp.underline;
1520 dest->mfp.strikeout = src->mfp.strikeout;
1521 lstrcpy(dest->mfp.faceName, src->mfp.faceName);
1522 CreateFontInMF(dest);
1527 FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1529 static MyFont workFont[NUM_FONTS];
1530 static BOOL firstPaint;
1537 /* copy the current font settings into a working copy */
1538 for (i=0; i < NUM_FONTS; i++)
1539 CopyFont(&workFont[i], font[boardSize][i]);
1541 if (!appData.icsActive)
1542 EnableWindow(GetDlgItem(hDlg, OPT_ChooseConsoleFont), FALSE);
1544 firstPaint = TRUE; /* see rant below */
1546 /* If I don't call SetFocus(), the dialog won't respond to the keyboard
1547 * when first drawn. Why is this the only dialog that behaves this way? Is
1548 * is the WM_PAINT stuff below?? Sigh...
1550 SetFocus(GetDlgItem(hDlg, IDOK));
1554 /* This should not be necessary. However, if SetSampleFontText() is called
1555 * in response to WM_INITDIALOG, the strings are not properly centered in
1556 * the controls when the dialog first appears. I can't figure out why, so
1557 * this is the workaround. --msw
1560 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1561 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1562 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1563 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1564 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1565 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1566 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1571 case WM_COMMAND: /* message: received a command */
1572 switch (LOWORD(wParam)) {
1575 /* again, it seems to avoid redraw problems if we call EndDialog first */
1576 EndDialog(hDlg, FALSE);
1578 /* copy modified settings back to the fonts array */
1579 for (i=0; i < NUM_FONTS; i++)
1580 CopyFont(font[boardSize][i], &workFont[i]);
1582 /* a sad necessity due to the original design of having a separate
1583 * console font, tags font, and comment font for each board size. IMHO
1584 * these fonts should not be dependent on the current board size. I'm
1585 * running out of time, so I am doing this hack rather than redesign the
1586 * data structure. Besides, I think if I redesigned the data structure, I
1587 * might break backwards compatibility with old winboard.ini files.
1590 for (i=0; i < NUM_SIZES; i++) {
1591 CopyFont(font[i][EDITTAGS_FONT], &workFont[EDITTAGS_FONT]);
1592 CopyFont(font[i][CONSOLE_FONT], &workFont[CONSOLE_FONT]);
1593 CopyFont(font[i][COMMENT_FONT], &workFont[COMMENT_FONT]);
1594 CopyFont(font[i][MOVEHISTORY_FONT], &workFont[MOVEHISTORY_FONT]);
1596 /* end sad necessity */
1598 InitDrawingSizes(boardSize, 0);
1599 InvalidateRect(hwndMain, NULL, TRUE);
1601 if (commentDialog) {
1602 SendDlgItemMessage(commentDialog, OPT_CommentText,
1603 WM_SETFONT, (WPARAM)font[boardSize][COMMENT_FONT]->hf,
1604 MAKELPARAM(TRUE, 0));
1605 GetClientRect(GetDlgItem(commentDialog, OPT_CommentText), &rect);
1606 InvalidateRect(commentDialog, &rect, TRUE);
1609 if (editTagsDialog) {
1610 SendDlgItemMessage(editTagsDialog, OPT_TagsText,
1611 WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf,
1612 MAKELPARAM(TRUE, 0));
1613 GetClientRect(GetDlgItem(editTagsDialog, OPT_TagsText), &rect);
1614 InvalidateRect(editTagsDialog, &rect, TRUE);
1617 if( moveHistoryDialog != NULL ) {
1618 SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory,
1619 WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,
1620 MAKELPARAM(TRUE, 0));
1621 InvalidateRect(editTagsDialog, NULL, TRUE);
1625 ChangedConsoleFont();
1628 for (i=0; i<NUM_FONTS; i++)
1629 DeleteObject(&workFont[i].hf);
1634 for (i=0; i<NUM_FONTS; i++)
1635 DeleteObject(&workFont[i].hf);
1636 EndDialog(hDlg, FALSE);
1639 case OPT_ChooseClockFont:
1640 MyCreateFont(hDlg, &workFont[CLOCK_FONT]);
1641 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1644 case OPT_ChooseMessageFont:
1645 MyCreateFont(hDlg, &workFont[MESSAGE_FONT]);
1646 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1649 case OPT_ChooseCoordFont:
1650 MyCreateFont(hDlg, &workFont[COORD_FONT]);
1651 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1654 case OPT_ChooseTagFont:
1655 MyCreateFont(hDlg, &workFont[EDITTAGS_FONT]);
1656 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1659 case OPT_ChooseCommentsFont:
1660 MyCreateFont(hDlg, &workFont[COMMENT_FONT]);
1661 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1664 case OPT_ChooseConsoleFont:
1665 MyCreateFont(hDlg, &workFont[CONSOLE_FONT]);
1666 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1669 case OPT_ChooseMoveHistoryFont:
1670 MyCreateFont(hDlg, &workFont[MOVEHISTORY_FONT]);
1671 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1674 case OPT_DefaultFonts:
1675 for (i=0; i<NUM_FONTS; i++) {
1676 DeleteObject(&workFont[i].hf);
1677 ParseFontName(font[boardSize][i]->def, &workFont[i].mfp);
1678 CreateFontInMF(&workFont[i]);
1680 SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);
1681 SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);
1682 SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);
1683 SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);
1684 SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);
1685 SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);
1686 SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);
1694 FontsOptionsPopup(HWND hwnd)
1696 FARPROC lpProc = MakeProcInstance((FARPROC)FontOptionsDialog, hInst);
1697 DialogBox(hInst, MAKEINTRESOURCE(DLG_Fonts), hwnd,
1699 FreeProcInstance(lpProc);
1702 /*---------------------------------------------------------------------------*\
1704 * Sounds Dialog functions
1706 \*---------------------------------------------------------------------------*/
1709 SoundComboData soundComboData[] = {
1712 {"ICS Alarm", NULL},
1716 {"ICS Unfinished", NULL},
1718 {"SShout/CShout", NULL},
1719 {"Channel 1", NULL},
1723 {"Challenge", NULL},
1731 InitSoundComboData(SoundComboData *scd)
1737 /* copy current sound settings to combo array */
1739 for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) {
1740 scd[sc].name = strdup(sounds[sc].name);
1742 for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) {
1743 index = (int)cc + (int)NSoundClasses;
1744 scd[index].name = strdup(textAttribs[cc].sound.name);
1750 ResetSoundComboData(SoundComboData *scd)
1752 while (scd->label) {
1753 if (scd->name != NULL) {
1762 InitSoundCombo(HWND hwndCombo, SoundComboData *scd)
1767 SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
1769 /* send the labels to the combo box */
1770 while (scd->label) {
1771 err = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) scd->label);
1773 sprintf(buf, "InitSoundCombo(): err '%d', cnt '%d'\n",
1775 MessageBox(NULL, buf, NULL, MB_OK);
1779 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) 0, (LPARAM) 0);
1783 SoundDialogWhichRadio(HWND hDlg)
1785 if (IsDlgButtonChecked(hDlg, OPT_NoSound)) return OPT_NoSound;
1786 if (IsDlgButtonChecked(hDlg, OPT_DefaultBeep)) return OPT_DefaultBeep;
1787 if (IsDlgButtonChecked(hDlg, OPT_BuiltInSound)) return OPT_BuiltInSound;
1788 if (IsDlgButtonChecked(hDlg, OPT_WavFile)) return OPT_WavFile;
1793 SoundDialogSetEnables(HWND hDlg, int radio)
1795 EnableWindow(GetDlgItem(hDlg, OPT_BuiltInSoundName),
1796 radio == OPT_BuiltInSound);
1797 EnableWindow(GetDlgItem(hDlg, OPT_WavFileName), radio == OPT_WavFile);
1798 EnableWindow(GetDlgItem(hDlg, OPT_BrowseSound), radio == OPT_WavFile);
1802 SoundDialogGetName(HWND hDlg, int radio)
1804 static char buf[MSG_SIZ], buf2[MSG_SIZ], buf3[MSG_SIZ];
1810 case OPT_DefaultBeep:
1812 case OPT_BuiltInSound:
1814 GetDlgItemText(hDlg, OPT_BuiltInSoundName, buf + 1, sizeof(buf) - 1);
1817 GetDlgItemText(hDlg, OPT_WavFileName, buf, sizeof(buf));
1818 GetCurrentDirectory(MSG_SIZ, buf3);
1819 SetCurrentDirectory(installDir);
1820 if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {
1825 SetCurrentDirectory(buf3);
1831 DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name)
1835 * I think it's best to clear the combo and edit boxes. It looks stupid
1836 * to have a value from another sound event sitting there grayed out.
1838 SetDlgItemText(hDlg, OPT_WavFileName, "");
1839 SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
1841 if (appData.debugMode)
1842 fprintf(debugFP, "DisplaySelectedSound(,,'%s'):\n", name);
1845 radio = OPT_NoSound;
1848 if (name[1] == NULLCHAR) {
1849 radio = OPT_DefaultBeep;
1851 radio = OPT_WavFile;
1852 SetDlgItemText(hDlg, OPT_WavFileName, name);
1856 if (name[1] == NULLCHAR) {
1857 radio = OPT_NoSound;
1859 radio = OPT_BuiltInSound;
1860 if (SendMessage(hCombo, CB_SELECTSTRING, (WPARAM) -1,
1861 (LPARAM) (name + 1)) == CB_ERR) {
1862 SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
1863 SendMessage(hCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) (name + 1));
1868 radio = OPT_WavFile;
1869 SetDlgItemText(hDlg, OPT_WavFileName, name);
1872 SoundDialogSetEnables(hDlg, radio);
1873 CheckRadioButton(hDlg, OPT_NoSound, OPT_WavFile, radio);
1877 char *builtInSoundNames[] = BUILT_IN_SOUND_NAMES;
1880 SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1882 static HWND hSoundCombo;
1892 SoundComboData *scd;
1896 /* Center the dialog over the application window */
1897 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
1899 /* Initialize the built-in sounds combo */
1900 hBISN = GetDlgItem(hDlg, OPT_BuiltInSoundName);
1901 InitComboStrings(hBISN, builtInSoundNames);
1903 /* Initialize the sound events combo */
1905 InitSoundComboData(soundComboData);
1906 hSoundCombo = GetDlgItem(hDlg, CBO_Sounds);
1907 InitSoundCombo(hSoundCombo, soundComboData);
1909 /* update the dialog */
1910 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
1913 case WM_COMMAND: /* message: received a command */
1915 if (((HWND)lParam == hSoundCombo) &&
1916 (HIWORD(wParam) == CBN_SELCHANGE)) {
1918 * the user has selected a new sound event. We must store the name for
1919 * the previously selected event, then retrieve the name for the
1920 * newly selected event and update the dialog.
1922 radio = SoundDialogWhichRadio(hDlg);
1923 newName = strdup(SoundDialogGetName(hDlg, radio));
1925 if (strcmp(newName, soundComboData[index].name) != 0) {
1926 free(soundComboData[index].name);
1927 soundComboData[index].name = newName;
1932 /* now get the settings for the newly selected event */
1933 index = SendMessage(hSoundCombo, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
1934 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
1938 switch (LOWORD(wParam)) {
1941 * save the name for the currently selected sound event
1943 radio = SoundDialogWhichRadio(hDlg);
1944 newName = strdup(SoundDialogGetName(hDlg, radio));
1946 if (strcmp(soundComboData[index].name, newName) != 0) {
1947 free(soundComboData[index].name);
1948 soundComboData[index].name = newName;
1954 /* save all the sound names that changed and load the sounds */
1956 for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) {
1957 if (strcmp(soundComboData[sc].name, sounds[sc].name) != 0) {
1958 free(sounds[sc].name);
1959 sounds[sc].name = strdup(soundComboData[sc].name);
1960 MyLoadSound(&sounds[sc]);
1963 for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) {
1964 index = (int)cc + (int)NSoundClasses;
1965 if (strcmp(soundComboData[index].name,
1966 textAttribs[cc].sound.name) != 0) {
1967 free(textAttribs[cc].sound.name);
1968 textAttribs[cc].sound.name = strdup(soundComboData[index].name);
1969 MyLoadSound(&textAttribs[cc].sound);
1973 ResetSoundComboData(soundComboData);
1974 EndDialog(hDlg, TRUE);
1978 ResetSoundComboData(soundComboData);
1979 EndDialog(hDlg, FALSE);
1982 case OPT_DefaultSounds:
1983 /* can't use SetDefaultSounds() because we need to be able to "undo" if
1984 * user selects "Cancel" later on. So we do it the hard way here.
1986 scd = &soundComboData[0];
1987 while (scd->label != NULL) {
1988 if (scd->name != NULL) free(scd->name);
1989 scd->name = strdup("");
1992 free(soundComboData[(int)SoundBell].name);
1993 soundComboData[(int)SoundBell].name = strdup(SOUND_BELL);
1994 DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);
1998 radio = SoundDialogWhichRadio(hDlg);
1999 tmp.name = strdup(SoundDialogGetName(hDlg, radio));
2003 if (tmp.data != NULL) FreeResource(tmp.data); // technically obsolete fn, but tmp.data is NOT malloc'd mem
2004 if (tmp.name != NULL) free(tmp.name);
2007 case OPT_BrowseSound:
2008 f = OpenFileDialog(hDlg, "rb", NULL, "wav", SOUND_FILT,
2009 "Browse for Sound File", NULL, NULL, buf);
2012 SetDlgItemText(hDlg, OPT_WavFileName, buf);
2017 radio = SoundDialogWhichRadio(hDlg);
2018 SoundDialogSetEnables(hDlg, radio);
2027 VOID SoundOptionsPopup(HWND hwnd)
2031 lpProc = MakeProcInstance((FARPROC)SoundOptionsDialog, hInst);
2032 DialogBox(hInst, MAKEINTRESOURCE(DLG_Sound), hwnd, (DLGPROC)lpProc);
2033 FreeProcInstance(lpProc);
2037 /*---------------------------------------------------------------------------*\
2039 * Comm Port dialog functions
2041 \*---------------------------------------------------------------------------*/
2051 ComboData cdPort[] = { {"None", PORT_NONE}, {"COM1", 1}, {"COM2", 2},
2052 {"COM3", 3}, {"COM4", 4}, {NULL, 0} };
2053 ComboData cdDataRate[] = { {"110", 110}, {"300", 300}, {"600", 600}, {"1200", 1200},
2054 {"2400", 2400}, {"4800", 4800}, {"9600", 9600}, {"19200", 19200},
2055 {"38400", 38400}, {NULL, 0} };
2056 ComboData cdDataBits[] = { {"5", 5}, {"6", 6}, {"7", 7}, {"8", 8}, {NULL, 0} };
2057 ComboData cdParity[] = { {"None", NOPARITY}, {"Odd", ODDPARITY}, {"Even", EVENPARITY},
2058 {"Mark", MARKPARITY}, {"Space", SPACEPARITY}, {NULL, 0} };
2059 ComboData cdStopBits[] = { {"1", ONESTOPBIT}, {"1.5", ONE5STOPBITS},
2060 {"2", TWOSTOPBITS}, {NULL, 0} };
2061 ComboData cdFlow[] = { {"None", FLOW_NONE}, {"Xoff/Xon", FLOW_XOFF}, {"CTS", FLOW_CTS},
2062 {"DSR", FLOW_DSR}, {NULL, 0} };
2066 ParseCommSettings(char *arg, DCB *dcb)
2068 int dataRate, count;
2069 char bits[MSG_SIZ], parity[MSG_SIZ], stopBits[MSG_SIZ], flow[MSG_SIZ];
2071 count = sscanf(arg, "%d%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]",
2072 &dataRate, bits, parity, stopBits, flow);
2073 if (count != 5) goto cant_parse;
2074 dcb->BaudRate = dataRate;
2076 while (cd->label != NULL) {
2077 if (StrCaseCmp(cd->label, bits) == 0) {
2078 dcb->ByteSize = cd->value;
2083 if (cd->label == NULL) goto cant_parse;
2085 while (cd->label != NULL) {
2086 if (StrCaseCmp(cd->label, parity) == 0) {
2087 dcb->Parity = cd->value;
2092 if (cd->label == NULL) goto cant_parse;
2094 while (cd->label != NULL) {
2095 if (StrCaseCmp(cd->label, stopBits) == 0) {
2096 dcb->StopBits = cd->value;
2102 if (cd->label == NULL) goto cant_parse;
2103 while (cd->label != NULL) {
2104 if (StrCaseCmp(cd->label, flow) == 0) {
2105 switch (cd->value) {
2108 dcb->fOutxCtsFlow = FALSE;
2109 dcb->fOutxDsrFlow = FALSE;
2113 dcb->fOutxCtsFlow = TRUE;
2114 dcb->fOutxDsrFlow = FALSE;
2118 dcb->fOutxCtsFlow = FALSE;
2119 dcb->fOutxDsrFlow = TRUE;
2123 dcb->fOutxCtsFlow = FALSE;
2124 dcb->fOutxDsrFlow = FALSE;
2131 if (cd->label == NULL) goto cant_parse;
2134 ExitArgError("Can't parse com port settings", arg);
2138 VOID PrintCommSettings(FILE *f, char *name, DCB *dcb)
2140 char *flow = "??", *parity = "??", *stopBits = "??";
2144 while (cd->label != NULL) {
2145 if (dcb->Parity == cd->value) {
2152 while (cd->label != NULL) {
2153 if (dcb->StopBits == cd->value) {
2154 stopBits = cd->label;
2160 flow = cdFlow[FLOW_XOFF].label;
2161 } else if (dcb->fOutxCtsFlow) {
2162 flow = cdFlow[FLOW_CTS].label;
2163 } else if (dcb->fOutxDsrFlow) {
2164 flow = cdFlow[FLOW_DSR].label;
2166 flow = cdFlow[FLOW_NONE].label;
2168 fprintf(f, "/%s=%d,%d,%s,%s,%s\n", name,
2169 dcb->BaudRate, dcb->ByteSize, parity, stopBits, flow);
2174 InitCombo(HANDLE hwndCombo, ComboData *cd)
2176 SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
2178 while (cd->label != NULL) {
2179 SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) cd->label);
2185 SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value)
2190 while (cd->label != NULL) {
2191 if (cd->value == value) {
2192 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) i, (LPARAM) 0);
2201 CommPortOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2211 case WM_INITDIALOG: /* message: initialize dialog box */
2212 /* Center the dialog over the application window */
2213 CenterWindow (hDlg, GetWindow(hDlg, GW_OWNER));
2214 /* Initialize the dialog items */
2215 /* !! There should probably be some synchronization
2216 in accessing hCommPort and dcb. Or does modal nature
2217 of this dialog box do it for us?
2219 hwndCombo = GetDlgItem(hDlg, OPT_Port);
2220 InitCombo(hwndCombo, cdPort);
2221 p = strrchr(appData.icsCommPort, '\\');
2222 if (p++ == NULL) p = appData.icsCommPort;
2224 (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) p) == CB_ERR)) {
2225 SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) "None");
2227 EnableWindow(hwndCombo, hCommPort == NULL); /*!! don't allow change for now*/
2229 hwndCombo = GetDlgItem(hDlg, OPT_DataRate);
2230 InitCombo(hwndCombo, cdDataRate);
2231 sprintf(buf, "%u", dcb.BaudRate);
2232 if (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) buf) == CB_ERR) {
2233 SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
2234 SendMessage(hwndCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) buf);
2237 hwndCombo = GetDlgItem(hDlg, OPT_Bits);
2238 InitCombo(hwndCombo, cdDataBits);
2239 SelectComboValue(hwndCombo, cdDataBits, dcb.ByteSize);
2241 hwndCombo = GetDlgItem(hDlg, OPT_Parity);
2242 InitCombo(hwndCombo, cdParity);
2243 SelectComboValue(hwndCombo, cdParity, dcb.Parity);
2245 hwndCombo = GetDlgItem(hDlg, OPT_StopBits);
2246 InitCombo(hwndCombo, cdStopBits);
2247 SelectComboValue(hwndCombo, cdStopBits, dcb.StopBits);
2249 hwndCombo = GetDlgItem(hDlg, OPT_Flow);
2250 InitCombo(hwndCombo, cdFlow);
2252 SelectComboValue(hwndCombo, cdFlow, FLOW_XOFF);
2253 } else if (dcb.fOutxCtsFlow) {
2254 SelectComboValue(hwndCombo, cdFlow, FLOW_CTS);
2255 } else if (dcb.fOutxDsrFlow) {
2256 SelectComboValue(hwndCombo, cdFlow, FLOW_DSR);
2258 SelectComboValue(hwndCombo, cdFlow, FLOW_NONE);
2262 case WM_COMMAND: /* message: received a command */
2263 switch (LOWORD(wParam)) {
2265 /* Read changed options from the dialog box */
2267 /* !! Currently we can't change comm ports in midstream */
2268 hwndCombo = GetDlgItem(hDlg, OPT_Port);
2269 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2270 if (index == PORT_NONE) {
2271 appData.icsCommPort = "";
2272 if (hCommPort != NULL) {
2273 CloseHandle(hCommPort);
2276 EndDialog(hDlg, TRUE);
2279 SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf);
2280 appData.icsCommPort = strdup(buf);
2281 if (hCommPort != NULL) {
2282 CloseHandle(hCommPort);
2285 /* now what?? can't really do this; have to fix up the ChildProc
2286 and InputSource records for the comm port that we gave to the
2290 hwndCombo = GetDlgItem(hDlg, OPT_DataRate);
2291 SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf);
2292 if (sscanf(buf, "%u", &value) != 1) {
2293 MessageBox(hDlg, "Invalid data rate",
2294 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2297 dcb.BaudRate = value;
2299 hwndCombo = GetDlgItem(hDlg, OPT_Bits);
2300 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2301 dcb.ByteSize = cdDataBits[index].value;
2303 hwndCombo = GetDlgItem(hDlg, OPT_Parity);
2304 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2305 dcb.Parity = cdParity[index].value;
2307 hwndCombo = GetDlgItem(hDlg, OPT_StopBits);
2308 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2309 dcb.StopBits = cdStopBits[index].value;
2311 hwndCombo = GetDlgItem(hDlg, OPT_Flow);
2312 index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
2313 switch (cdFlow[index].value) {
2316 dcb.fOutxCtsFlow = FALSE;
2317 dcb.fOutxDsrFlow = FALSE;
2321 dcb.fOutxCtsFlow = TRUE;
2322 dcb.fOutxDsrFlow = FALSE;
2326 dcb.fOutxCtsFlow = FALSE;
2327 dcb.fOutxDsrFlow = TRUE;
2331 dcb.fOutxCtsFlow = FALSE;
2332 dcb.fOutxDsrFlow = FALSE;
2335 if (!SetCommState(hCommPort, (LPDCB) &dcb)) {
2336 err = GetLastError();
2337 switch(MessageBox(hDlg,
2338 "Failed to set comm port state;\r\ninvalid options?",
2339 "Option Error", MB_ABORTRETRYIGNORE|MB_ICONQUESTION)) {
2341 DisplayFatalError("Failed to set comm port state", err, 1);
2342 exit(1); /*is it ok to do this from here?*/
2348 EndDialog(hDlg, TRUE);
2353 EndDialog(hDlg, TRUE);
2357 EndDialog(hDlg, FALSE);
2369 CommPortOptionsPopup(HWND hwnd)
2371 FARPROC lpProc = MakeProcInstance((FARPROC)CommPortOptionsDialog, hInst);
2372 DialogBox(hInst, MAKEINTRESOURCE(DLG_CommPort), hwnd, (DLGPROC) lpProc);
2373 FreeProcInstance(lpProc);
2376 /*---------------------------------------------------------------------------*\
2378 * Load Options dialog functions
2380 \*---------------------------------------------------------------------------*/
2383 SetLoadOptionEnables(HWND hDlg)
2387 state = IsDlgButtonChecked(hDlg, OPT_Autostep);
2388 EnableWindow(GetDlgItem(hDlg, OPT_ASTimeDelay), state);
2389 EnableWindow(GetDlgItem(hDlg, OPT_AStext1), state);
2393 LoadOptions(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2399 case WM_INITDIALOG: /* message: initialize dialog box */
2400 /* Center the dialog over the application window */
2401 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2402 /* Initialize the dialog items */
2403 if (appData.timeDelay >= 0.0) {
2404 CheckDlgButton(hDlg, OPT_Autostep, TRUE);
2405 sprintf(buf, "%.2g", appData.timeDelay);
2406 SetDlgItemText(hDlg, OPT_ASTimeDelay, buf);
2408 CheckDlgButton(hDlg, OPT_Autostep, FALSE);
2410 SetLoadOptionEnables(hDlg);
2413 case WM_COMMAND: /* message: received a command */
2414 switch (LOWORD(wParam)) {
2416 /* Read changed options from the dialog box */
2417 if (IsDlgButtonChecked(hDlg, OPT_Autostep)) {
2418 GetDlgItemText(hDlg, OPT_ASTimeDelay, buf, MSG_SIZ);
2419 if (sscanf(buf, "%f", &fnumber) != 1) {
2420 MessageBox(hDlg, "Invalid load game step rate",
2421 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2424 appData.timeDelay = fnumber;
2426 appData.timeDelay = (float) -1.0;
2428 EndDialog(hDlg, TRUE);
2432 EndDialog(hDlg, FALSE);
2436 SetLoadOptionEnables(hDlg);
2446 LoadOptionsPopup(HWND hwnd)
2448 FARPROC lpProc = MakeProcInstance((FARPROC)LoadOptions, hInst);
2449 DialogBox(hInst, MAKEINTRESOURCE(DLG_LoadOptions), hwnd, (DLGPROC) lpProc);
2450 FreeProcInstance(lpProc);
2453 /*---------------------------------------------------------------------------*\
2455 * Save Options dialog functions
2457 \*---------------------------------------------------------------------------*/
2460 SetSaveOptionEnables(HWND hDlg)
2464 state = IsDlgButtonChecked(hDlg, OPT_Autosave);
2465 EnableWindow(GetDlgItem(hDlg, OPT_AVPrompt), state);
2466 EnableWindow(GetDlgItem(hDlg, OPT_AVToFile), state);
2467 if (state && !IsDlgButtonChecked(hDlg, OPT_AVPrompt) &&
2468 !IsDlgButtonChecked(hDlg, OPT_AVToFile)) {
2469 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt);
2472 state = state && IsDlgButtonChecked(hDlg, OPT_AVToFile);
2473 EnableWindow(GetDlgItem(hDlg, OPT_AVFilename), state);
2474 EnableWindow(GetDlgItem(hDlg, OPT_AVBrowse), state);
2478 SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2484 case WM_INITDIALOG: /* message: initialize dialog box */
2485 /* Center the dialog over the application window */
2486 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2487 /* Initialize the dialog items */
2488 if (*appData.saveGameFile != NULLCHAR) {
2489 CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE);
2490 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVToFile);
2491 SetDlgItemText(hDlg, OPT_AVFilename, appData.saveGameFile);
2492 } else if (appData.autoSaveGames) {
2493 CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE);
2494 CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt);
2496 CheckDlgButton(hDlg, OPT_Autosave, (UINT) FALSE);
2498 if (appData.oldSaveStyle) {
2499 CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_Old);
2501 CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_PGN);
2503 CheckDlgButton( hDlg, OPT_OutOfBookInfo, appData.saveOutOfBookInfo );
2504 SetSaveOptionEnables(hDlg);
2507 case WM_COMMAND: /* message: received a command */
2508 switch (LOWORD(wParam)) {
2510 /* Read changed options from the dialog box */
2511 if (IsDlgButtonChecked(hDlg, OPT_Autosave)) {
2512 appData.autoSaveGames = TRUE;
2513 if (IsDlgButtonChecked(hDlg, OPT_AVPrompt)) {
2514 appData.saveGameFile = "";
2515 } else /*if (IsDlgButtonChecked(hDlg, OPT_AVToFile))*/ {
2516 GetDlgItemText(hDlg, OPT_AVFilename, buf, MSG_SIZ);
2517 if (*buf == NULLCHAR) {
2518 MessageBox(hDlg, "Invalid save game file name",
2519 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2522 if ((isalpha(buf[0]) && buf[1] == ':') ||
2523 (buf[0] == '\\' && buf[1] == '\\')) {
2524 appData.saveGameFile = strdup(buf);
2526 char buf2[MSG_SIZ], buf3[MSG_SIZ];
2528 GetCurrentDirectory(MSG_SIZ, buf3);
2529 SetCurrentDirectory(installDir);
2530 if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {
2531 appData.saveGameFile = strdup(buf2);
2533 appData.saveGameFile = strdup(buf);
2535 SetCurrentDirectory(buf3);
2539 appData.autoSaveGames = FALSE;
2540 appData.saveGameFile = "";
2542 appData.oldSaveStyle = IsDlgButtonChecked(hDlg, OPT_Old);
2543 appData.saveOutOfBookInfo = IsDlgButtonChecked( hDlg, OPT_OutOfBookInfo );
2544 EndDialog(hDlg, TRUE);
2548 EndDialog(hDlg, FALSE);
2552 f = OpenFileDialog(hDlg, "a", NULL,
2553 appData.oldSaveStyle ? "gam" : "pgn",
2554 GAME_FILT, "Browse for Auto Save File",
2558 SetDlgItemText(hDlg, OPT_AVFilename, buf);
2563 SetSaveOptionEnables(hDlg);
2572 SaveOptionsPopup(HWND hwnd)
2574 FARPROC lpProc = MakeProcInstance((FARPROC)SaveOptionsDialog, hInst);
2575 DialogBox(hInst, MAKEINTRESOURCE(DLG_SaveOptions), hwnd, (DLGPROC) lpProc);
2576 FreeProcInstance(lpProc);
2579 /*---------------------------------------------------------------------------*\
2581 * Time Control Options dialog functions
2583 \*---------------------------------------------------------------------------*/
2586 SetTimeControlEnables(HWND hDlg)
2590 state = IsDlgButtonChecked(hDlg, OPT_TCUseMoves);
2591 EnableWindow(GetDlgItem(hDlg, OPT_TCTime), state);
2592 EnableWindow(GetDlgItem(hDlg, OPT_TCMoves), state);
2593 EnableWindow(GetDlgItem(hDlg, OPT_TCtext1), state);
2594 EnableWindow(GetDlgItem(hDlg, OPT_TCtext2), state);
2595 EnableWindow(GetDlgItem(hDlg, OPT_TCTime2), !state);
2596 EnableWindow(GetDlgItem(hDlg, OPT_TCInc), !state);
2597 EnableWindow(GetDlgItem(hDlg, OPT_TCitext1), !state);
2598 EnableWindow(GetDlgItem(hDlg, OPT_TCitext2), !state);
2599 EnableWindow(GetDlgItem(hDlg, OPT_TCitext3), !state);
2604 TimeControl(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2607 int mps, increment, odds1, odds2;
2611 case WM_INITDIALOG: /* message: initialize dialog box */
2612 /* Center the dialog over the application window */
2613 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2614 /* Initialize the dialog items */
2615 if (appData.clockMode && !appData.icsActive) {
2616 if (appData.timeIncrement == -1) {
2617 CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,
2619 SetDlgItemText(hDlg, OPT_TCTime, appData.timeControl);
2620 SetDlgItemInt(hDlg, OPT_TCMoves, appData.movesPerSession,
2622 SetDlgItemText(hDlg, OPT_TCTime2, "");
2623 SetDlgItemText(hDlg, OPT_TCInc, "");
2625 CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,
2627 SetDlgItemText(hDlg, OPT_TCTime, "");
2628 SetDlgItemText(hDlg, OPT_TCMoves, "");
2629 SetDlgItemText(hDlg, OPT_TCTime2, appData.timeControl);
2630 SetDlgItemInt(hDlg, OPT_TCInc, appData.timeIncrement, FALSE);
2632 SetDlgItemInt(hDlg, OPT_TCOdds1, 1, FALSE);
2633 SetDlgItemInt(hDlg, OPT_TCOdds2, 1, FALSE);
2634 SetTimeControlEnables(hDlg);
2638 case WM_COMMAND: /* message: received a command */
2639 switch (LOWORD(wParam)) {
2641 /* Read changed options from the dialog box */
2642 if (IsDlgButtonChecked(hDlg, OPT_TCUseMoves)) {
2644 mps = GetDlgItemInt(hDlg, OPT_TCMoves, &ok, FALSE);
2645 if (!ok || mps <= 0) {
2646 MessageBox(hDlg, "Invalid moves per time control",
2647 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2650 GetDlgItemText(hDlg, OPT_TCTime, buf, MSG_SIZ);
2651 if (!ParseTimeControl(buf, increment, mps)) {
2652 MessageBox(hDlg, "Invalid minutes per time control",
2653 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2657 increment = GetDlgItemInt(hDlg, OPT_TCInc, &ok, FALSE);
2658 mps = appData.movesPerSession;
2659 if (!ok || increment < 0) {
2660 MessageBox(hDlg, "Invalid increment",
2661 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2664 GetDlgItemText(hDlg, OPT_TCTime2, buf, MSG_SIZ);
2665 if (!ParseTimeControl(buf, increment, mps)) {
2666 MessageBox(hDlg, "Invalid initial time",
2667 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2671 odds1 = GetDlgItemInt(hDlg, OPT_TCOdds1, &ok, FALSE);
2672 odds2 = GetDlgItemInt(hDlg, OPT_TCOdds2, &ok2, FALSE);
2673 if (!ok || !ok2 || odds1 <= 0 || odds2 <= 0) {
2674 MessageBox(hDlg, "Invalid time-odds factor",
2675 "Option Error", MB_OK|MB_ICONEXCLAMATION);
2678 appData.timeControl = strdup(buf);
2679 appData.movesPerSession = mps;
2680 appData.timeIncrement = increment;
2681 appData.firstTimeOdds = first.timeOdds = odds1;
2682 appData.secondTimeOdds = second.timeOdds = odds2;
2684 EndDialog(hDlg, TRUE);
2688 EndDialog(hDlg, FALSE);
2692 SetTimeControlEnables(hDlg);
2701 TimeControlOptionsPopup(HWND hwnd)
2703 if (gameMode != BeginningOfGame) {
2704 DisplayError("Changing time control during a game is not implemented", 0);
2706 FARPROC lpProc = MakeProcInstance((FARPROC)TimeControl, hInst);
2707 DialogBox(hInst, MAKEINTRESOURCE(DLG_TimeControl), hwnd, (DLGPROC) lpProc);
2708 FreeProcInstance(lpProc);
2712 /*---------------------------------------------------------------------------*\
2714 * Engine Options Dialog functions
2716 \*---------------------------------------------------------------------------*/
2717 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))
2718 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))
2720 #define INT_ABS( n ) ((n) >= 0 ? (n) : -(n))
2722 LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2725 case WM_INITDIALOG: /* message: initialize dialog box */
2727 /* Center the dialog over the application window */
2728 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2730 /* Initialize the dialog items */
2731 CHECK_BOX(IDC_EpPeriodicUpdates, appData.periodicUpdates);
2732 CHECK_BOX(IDC_EpPonder, appData.ponderNextMove);
2733 CHECK_BOX(IDC_EpShowThinking, appData.showThinking);
2734 CHECK_BOX(IDC_EpHideThinkingHuman, appData.hideThinkingFromHuman);
2736 CHECK_BOX(IDC_TestClaims, appData.testClaims);
2737 CHECK_BOX(IDC_DetectMates, appData.checkMates);
2738 CHECK_BOX(IDC_MaterialDraws, appData.materialDraws);
2739 CHECK_BOX(IDC_TrivialDraws, appData.trivialDraws);
2741 CHECK_BOX(IDC_ScoreAbs1, appData.firstScoreIsAbsolute);
2742 CHECK_BOX(IDC_ScoreAbs2, appData.secondScoreIsAbsolute);
2744 SetDlgItemInt( hDlg, IDC_EpDrawMoveCount, appData.adjudicateDrawMoves, TRUE );
2745 SendDlgItemMessage( hDlg, IDC_EpDrawMoveCount, EM_SETSEL, 0, -1 );
2747 SetDlgItemInt( hDlg, IDC_EpAdjudicationThreshold, INT_ABS(appData.adjudicateLossThreshold), TRUE );
2748 SendDlgItemMessage( hDlg, IDC_EpAdjudicationThreshold, EM_SETSEL, 0, -1 );
2750 SetDlgItemInt( hDlg, IDC_RuleMoves, appData.ruleMoves, TRUE );
2751 SendDlgItemMessage( hDlg, IDC_RuleMoves, EM_SETSEL, 0, -1 );
2753 SetDlgItemInt( hDlg, IDC_DrawRepeats, INT_ABS(appData.drawRepeats), TRUE );
2754 SendDlgItemMessage( hDlg, IDC_DrawRepeats, EM_SETSEL, 0, -1 );
2758 case WM_COMMAND: /* message: received a command */
2759 switch (LOWORD(wParam)) {
2761 /* Read changed options from the dialog box */
2762 PeriodicUpdatesEvent( IS_CHECKED(IDC_EpPeriodicUpdates));
2763 PonderNextMoveEvent( IS_CHECKED(IDC_EpPonder));
2764 appData.hideThinkingFromHuman= IS_CHECKED(IDC_EpHideThinkingHuman); // [HGM] thinking: moved up
2766 ShowThinkingEvent( IS_CHECKED(IDC_EpShowThinking));
2768 appData.showThinking = IS_CHECKED(IDC_EpShowThinking);
2769 ShowThinkingEvent(); // [HGM] thinking: tests all options that need thinking output
2771 appData.testClaims = IS_CHECKED(IDC_TestClaims);
2772 appData.checkMates = IS_CHECKED(IDC_DetectMates);
2773 appData.materialDraws = IS_CHECKED(IDC_MaterialDraws);
2774 appData.trivialDraws = IS_CHECKED(IDC_TrivialDraws);
2776 appData.adjudicateDrawMoves = GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, NULL, FALSE );
2777 appData.adjudicateLossThreshold = - (int) GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, NULL, FALSE );
2778 appData.ruleMoves = GetDlgItemInt(hDlg, IDC_RuleMoves, NULL, FALSE );
2779 appData.drawRepeats = (int) GetDlgItemInt(hDlg, IDC_DrawRepeats, NULL, FALSE );
2781 appData.firstScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs1);
2782 appData.secondScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs2);
2784 EndDialog(hDlg, TRUE);
2788 EndDialog(hDlg, FALSE);
2791 case IDC_EpDrawMoveCount:
2792 case IDC_EpAdjudicationThreshold:
2793 case IDC_DrawRepeats:
2795 if( HIWORD(wParam) == EN_CHANGE ) {
2801 GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, &n1_ok, FALSE );
2802 GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, &n2_ok, FALSE );
2803 GetDlgItemInt(hDlg, IDC_RuleMoves, &n3_ok, FALSE );
2804 GetDlgItemInt(hDlg, IDC_DrawRepeats, &n4_ok, FALSE );
2806 EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok && n4_ok ? TRUE : FALSE );
2815 VOID EnginePlayOptionsPopup(HWND hwnd)
2819 lpProc = MakeProcInstance((FARPROC)EnginePlayOptionsDialog, hInst);
2820 DialogBox(hInst, MAKEINTRESOURCE(DLG_EnginePlayOptions), hwnd, (DLGPROC) lpProc);
2821 FreeProcInstance(lpProc);
2824 /*---------------------------------------------------------------------------*\
2826 * UCI Options Dialog functions
2828 \*---------------------------------------------------------------------------*/
2829 static BOOL BrowseForFolder( const char * title, char * path )
2831 BOOL result = FALSE;
2835 ZeroMemory( &bi, sizeof(bi) );
2837 bi.lpszTitle = title == 0 ? "Choose Folder" : title;
2838 bi.ulFlags = BIF_RETURNONLYFSDIRS;
2840 pidl = SHBrowseForFolder( &bi );
2843 IMalloc * imalloc = 0;
2845 if( SHGetPathFromIDList( pidl, path ) ) {
2849 if( SUCCEEDED( SHGetMalloc ( &imalloc ) ) ) {
2850 imalloc->lpVtbl->Free(imalloc,pidl);
2851 imalloc->lpVtbl->Release(imalloc);
2858 LRESULT CALLBACK UciOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2864 case WM_INITDIALOG: /* message: initialize dialog box */
2866 /* Center the dialog over the application window */
2867 CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
2869 /* Initialize the dialog items */
2870 SetDlgItemText( hDlg, IDC_PolyglotDir, appData.polyglotDir );
2871 SetDlgItemInt( hDlg, IDC_HashSize, appData.defaultHashSize, TRUE );
2872 SetDlgItemText( hDlg, IDC_PathToEGTB, appData.defaultPathEGTB );
2873 SetDlgItemInt( hDlg, IDC_SizeOfEGTB, appData.defaultCacheSizeEGTB, TRUE );
2874 CheckDlgButton( hDlg, IDC_UseBook, (BOOL) appData.usePolyglotBook );
2875 SetDlgItemText( hDlg, IDC_BookFile, appData.polyglotBook );
2876 // [HGM] smp: input field for nr of cores:
2877 SetDlgItemInt( hDlg, IDC_Cores, appData.smpCores, TRUE );
2878 // [HGM] book: tick boxes for own book use
2879 CheckDlgButton( hDlg, IDC_OwnBook1, (BOOL) appData.firstHasOwnBookUCI );
2880 CheckDlgButton( hDlg, IDC_OwnBook2, (BOOL) appData.secondHasOwnBookUCI );
2882 SendDlgItemMessage( hDlg, IDC_PolyglotDir, EM_SETSEL, 0, -1 );
2886 case WM_COMMAND: /* message: received a command */
2887 switch (LOWORD(wParam)) {
2889 GetDlgItemText( hDlg, IDC_PolyglotDir, buf, sizeof(buf) );
2890 appData.polyglotDir = strdup(buf);
2891 appData.defaultHashSize = GetDlgItemInt(hDlg, IDC_HashSize, NULL, FALSE );
2892 appData.defaultCacheSizeEGTB = GetDlgItemInt(hDlg, IDC_SizeOfEGTB, NULL, FALSE );
2893 GetDlgItemText( hDlg, IDC_PathToEGTB, buf, sizeof(buf) );
2894 appData.defaultPathEGTB = strdup(buf);
2895 GetDlgItemText( hDlg, IDC_BookFile, buf, sizeof(buf) );
2896 appData.polyglotBook = strdup(buf);
2897 appData.usePolyglotBook = (Boolean) IsDlgButtonChecked( hDlg, IDC_UseBook );
2898 // [HGM] smp: get nr of cores:
2899 oldCores = appData.smpCores;
2900 appData.smpCores = GetDlgItemInt(hDlg, IDC_Cores, NULL, FALSE );
2901 if(appData.smpCores != oldCores) NewSettingEvent(FALSE, "cores", appData.smpCores);
2902 // [HGM] book: read tick boxes for own book use
2903 appData.firstHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook1 );
2904 appData.secondHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook2 );
2906 if(gameMode == BeginningOfGame) Reset(TRUE, TRUE);
2907 EndDialog(hDlg, TRUE);
2911 EndDialog(hDlg, FALSE);
2914 case IDC_BrowseForBook:
2917 'A','l','l',' ','F','i','l','e','s', 0,
2919 'B','I','N',' ','F','i','l','e','s', 0,
2920 '*','.','b','i','n', 0,
2927 ZeroMemory( &ofn, sizeof(ofn) );
2929 ofn.lStructSize = sizeof(ofn);
2930 ofn.hwndOwner = hDlg;
2931 ofn.hInstance = hInst;
2932 ofn.lpstrFilter = filter;
2933 ofn.lpstrFile = buf;
2934 ofn.nMaxFile = sizeof(buf);
2935 ofn.lpstrTitle = "Choose Book";
2936 ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;
2938 if( GetOpenFileName( &ofn ) ) {
2939 SetDlgItemText( hDlg, IDC_BookFile, buf );
2944 case IDC_BrowseForPolyglotDir:
2945 if( BrowseForFolder( "Choose Polyglot Directory", buf ) ) {
2946 SetDlgItemText( hDlg, IDC_PolyglotDir, buf );
2948 strcat( buf, "\\polyglot.exe" );
2950 if( GetFileAttributes(buf) == 0xFFFFFFFF ) {
2951 MessageBox( hDlg, "Polyglot was not found in the specified folder!", "Warning", MB_OK | MB_ICONWARNING );
2956 case IDC_BrowseForEGTB:
2957 if( BrowseForFolder( "Choose EGTB Directory:", buf ) ) {
2958 SetDlgItemText( hDlg, IDC_PathToEGTB, buf );
2963 case IDC_SizeOfEGTB:
2964 if( HIWORD(wParam) == EN_CHANGE ) {
2968 GetDlgItemInt(hDlg, IDC_HashSize, &n1_ok, FALSE );
2969 GetDlgItemInt(hDlg, IDC_SizeOfEGTB, &n2_ok, FALSE );
2971 EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok ? TRUE : FALSE );
2980 VOID UciOptionsPopup(HWND hwnd)
2984 lpProc = MakeProcInstance((FARPROC)UciOptionsDialog, hInst);
2985 DialogBox(hInst, MAKEINTRESOURCE(DLG_OptionsUCI), hwnd, (DLGPROC) lpProc);
2986 FreeProcInstance(lpProc);