f2a797e4419ebc557b167242deb14dfde1821251
[xboard.git] / winboard / woptions.c
1 /*\r
2  * woptions.c -- Options dialog box routines for WinBoard\r
3  * $Id: woptions.c,v 2.1 2003/10/27 19:21:02 mann Exp $\r
4  *\r
5  * Copyright 2000 Free Software Foundation, Inc.\r
6  *\r
7  * ------------------------------------------------------------------------\r
8  * This program is free software; you can redistribute it and/or modify\r
9  * it under the terms of the GNU General Public License as published by\r
10  * the Free Software Foundation; either version 2 of the License, or\r
11  * (at your option) any later version.\r
12  *\r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  * GNU General Public License for more details.\r
17  *\r
18  * You should have received a copy of the GNU General Public License\r
19  * along with this program; if not, write to the Free Software\r
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
21  * ------------------------------------------------------------------------\r
22  */\r
23 \r
24 #include "config.h"\r
25 \r
26 #include <windows.h>   /* required for all Windows applications */\r
27 #include <stdio.h>\r
28 #include <stdlib.h>\r
29 #include <shlobj.h>    /* [AS] Requires NT 4.0 or Win95 */\r
30 \r
31 #include "common.h"\r
32 #include "winboard.h"\r
33 #include "backend.h"\r
34 #include "woptions.h"\r
35 #include "defaults.h"\r
36 #include "wedittags.h"\r
37 #include <richedit.h>\r
38 \r
39 #if __GNUC__\r
40 #include <errno.h>\r
41 #include <string.h>\r
42 #endif\r
43 \r
44 /* Imports from winboard.c */\r
45 \r
46 extern MyFont *font[NUM_SIZES][NUM_FONTS];\r
47 extern HINSTANCE hInst;          /* current instance */\r
48 extern HWND hwndMain;            /* root window*/\r
49 extern BOOLEAN alwaysOnTop;\r
50 extern RECT boardRect;\r
51 extern COLORREF lightSquareColor, darkSquareColor, whitePieceColor, \r
52   blackPieceColor, highlightSquareColor, premoveHighlightColor;\r
53 extern HPALETTE hPal;\r
54 extern BoardSize boardSize;\r
55 extern COLORREF consoleBackgroundColor;\r
56 extern MyColorizeAttribs colorizeAttribs[]; /* do I need the size? */\r
57 extern MyTextAttribs textAttribs[];\r
58 extern MySound sounds[];\r
59 extern ColorClass currentColorClass;\r
60 extern HWND hwndConsole;\r
61 extern char *defaultTextAttribs[];\r
62 extern HWND commentDialog;\r
63 extern HWND moveHistoryDialog;\r
64 extern char installDir[];\r
65 extern HWND hCommPort;    /* currently open comm port */\r
66 extern DCB dcb;\r
67 extern BOOLEAN chessProgram;\r
68 extern startedFromPositionFile; /* [HGM] loadPos */\r
69 \r
70 /* types */\r
71 \r
72 typedef struct {\r
73   char *label;\r
74   unsigned value;\r
75 } ComboData;\r
76 \r
77 typedef struct {\r
78   char *label;\r
79   char *name;\r
80 } SoundComboData;\r
81 \r
82 /* module prototypes */\r
83 \r
84 LRESULT CALLBACK GeneralOptions(HWND, UINT, WPARAM, LPARAM);\r
85 LRESULT CALLBACK BoardOptions(HWND, UINT, WPARAM, LPARAM);\r
86 LRESULT CALLBACK NewVariant(HWND, UINT, WPARAM, LPARAM);\r
87 LRESULT CALLBACK IcsOptions(HWND, UINT, WPARAM, LPARAM);\r
88 LRESULT CALLBACK FontOptions(HWND, UINT, WPARAM, LPARAM);\r
89 LRESULT CALLBACK CommPortOptions(HWND, UINT, WPARAM, LPARAM);\r
90 LRESULT CALLBACK LoadOptions(HWND, UINT, WPARAM, LPARAM);\r
91 LRESULT CALLBACK SaveOptions(HWND, UINT, WPARAM, LPARAM);\r
92 LRESULT CALLBACK TimeControl(HWND, UINT, WPARAM, LPARAM);\r
93 VOID ChangeBoardSize(BoardSize newSize);\r
94 VOID PaintSampleSquare(\r
95     HWND     hwnd, \r
96     int      ctrlid, \r
97     COLORREF squareColor, \r
98     COLORREF pieceColor,\r
99     COLORREF squareOutlineColor,\r
100     COLORREF pieceDetailColor,\r
101     BOOL     isWhitePiece,\r
102     BOOL     isMono,\r
103     HBITMAP  pieces[3] \r
104     );\r
105 VOID PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color);\r
106 VOID SetBoardOptionEnables(HWND hDlg);\r
107 BoardSize BoardOptionsWhichRadio(HWND hDlg);\r
108 BOOL APIENTRY MyCreateFont(HWND hwnd, MyFont *font);\r
109 VOID UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca);\r
110 LRESULT CALLBACK ColorizeTextDialog(HWND , UINT, WPARAM, LPARAM);\r
111 VOID ColorizeTextPopup(HWND hwnd, ColorClass cc);\r
112 VOID SetIcsOptionEnables(HWND hDlg);\r
113 VOID SetSampleFontText(HWND hwnd, int id, const MyFont *mf);\r
114 VOID CopyFont(MyFont *dest, const MyFont *src);\r
115 void InitSoundComboData(SoundComboData *scd);\r
116 void ResetSoundComboData(SoundComboData *scd);\r
117 void InitSoundCombo(HWND hwndCombo, SoundComboData *scd);\r
118 int SoundDialogWhichRadio(HWND hDlg);\r
119 VOID SoundDialogSetEnables(HWND hDlg, int radio);\r
120 char * SoundDialogGetName(HWND hDlg, int radio);\r
121 void DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name);\r
122 VOID ParseCommSettings(char *arg, DCB *dcb);\r
123 VOID PrintCommSettings(FILE *f, char *name, DCB *dcb);\r
124 void InitCombo(HANDLE hwndCombo, ComboData *cd);\r
125 void SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value);\r
126 VOID SetLoadOptionEnables(HWND hDlg);\r
127 VOID SetSaveOptionEnables(HWND hDlg);\r
128 VOID SetTimeControlEnables(HWND hDlg);\r
129 \r
130 /*---------------------------------------------------------------------------*\\r
131  *\r
132  * General Options Dialog functions\r
133  *\r
134 \*---------------------------------------------------------------------------*/\r
135 \r
136 \r
137 LRESULT CALLBACK\r
138 GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
139 {\r
140   static Boolean oldShowCoords;\r
141   static Boolean oldBlindfold;\r
142   static Boolean oldShowButtonBar;\r
143 \r
144   switch (message) {\r
145   case WM_INITDIALOG: /* message: initialize dialog box */\r
146     oldShowCoords = appData.showCoords;\r
147     oldBlindfold  = appData.blindfold;\r
148     oldShowButtonBar = appData.showButtonBar;\r
149 \r
150     /* Center the dialog over the application window */\r
151     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
152 \r
153     /* Initialize the dialog items */\r
154 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))\r
155 \r
156     CHECK_BOX(OPT_AlwaysOnTop, alwaysOnTop);\r
157     CHECK_BOX(OPT_AlwaysQueen, appData.alwaysPromoteToQueen);\r
158     CHECK_BOX(OPT_AnimateDragging, appData.animateDragging);\r
159     CHECK_BOX(OPT_AnimateMoving, appData.animate);\r
160     CHECK_BOX(OPT_AutoFlag, appData.autoCallFlag);\r
161     CHECK_BOX(OPT_AutoFlipView, appData.autoFlipView);\r
162     CHECK_BOX(OPT_AutoRaiseBoard, appData.autoRaiseBoard);\r
163     CHECK_BOX(OPT_Blindfold, appData.blindfold);\r
164     CHECK_BOX(OPT_HighlightDragging, appData.highlightDragging);\r
165     CHECK_BOX(OPT_HighlightLastMove, appData.highlightLastMove);\r
166     CHECK_BOX(OPT_PeriodicUpdates, appData.periodicUpdates);\r
167     CHECK_BOX(OPT_PonderNextMove, appData.ponderNextMove);\r
168     CHECK_BOX(OPT_PopupExitMessage, appData.popupExitMessage);\r
169     CHECK_BOX(OPT_PopupMoveErrors, appData.popupMoveErrors);\r
170     CHECK_BOX(OPT_ShowButtonBar, appData.showButtonBar);\r
171     CHECK_BOX(OPT_ShowCoordinates, appData.showCoords);\r
172     CHECK_BOX(OPT_ShowThinking, appData.showThinking);\r
173     CHECK_BOX(OPT_TestLegality, appData.testLegality);\r
174     CHECK_BOX(OPT_HideThinkFromHuman, appData.hideThinkingFromHuman);\r
175     CHECK_BOX(OPT_SaveExtPGN, appData.saveExtendedInfoInPGN);\r
176     CHECK_BOX(OPT_ExtraInfoInMoveHistory, appData.showEvalInMoveHistory);\r
177     CHECK_BOX(OPT_HighlightMoveArrow, appData.highlightMoveWithArrow);\r
178 \r
179 #undef CHECK_BOX\r
180 \r
181     EnableWindow(GetDlgItem(hDlg, OPT_AutoFlag),\r
182                  appData.icsActive || !appData.noChessProgram);\r
183     EnableWindow(GetDlgItem(hDlg, OPT_AutoFlipView),\r
184                  appData.icsActive || !appData.noChessProgram);\r
185     EnableWindow(GetDlgItem(hDlg, OPT_PonderNextMove),\r
186                  !appData.noChessProgram);\r
187     EnableWindow(GetDlgItem(hDlg, OPT_PeriodicUpdates), \r
188                  !appData.noChessProgram && !appData.icsActive);\r
189     EnableWindow(GetDlgItem(hDlg, OPT_ShowThinking), \r
190                  !appData.noChessProgram);\r
191     return TRUE;\r
192 \r
193 \r
194   case WM_COMMAND: /* message: received a command */\r
195     switch (LOWORD(wParam)) {\r
196     case IDOK:\r
197       /* Read changed options from the dialog box */\r
198       \r
199 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))\r
200 \r
201       alwaysOnTop                  = IS_CHECKED(OPT_AlwaysOnTop);\r
202       appData.alwaysPromoteToQueen = IS_CHECKED(OPT_AlwaysQueen);\r
203       appData.animateDragging      = IS_CHECKED(OPT_AnimateDragging);\r
204       appData.animate              = IS_CHECKED(OPT_AnimateMoving);\r
205       appData.autoCallFlag         = IS_CHECKED(OPT_AutoFlag);\r
206       appData.autoFlipView         = IS_CHECKED(OPT_AutoFlipView);\r
207       appData.autoRaiseBoard       = IS_CHECKED(OPT_AutoRaiseBoard);\r
208       appData.blindfold            = IS_CHECKED(OPT_Blindfold);\r
209       appData.highlightDragging    = IS_CHECKED(OPT_HighlightDragging);\r
210       appData.highlightLastMove    = IS_CHECKED(OPT_HighlightLastMove);\r
211       PeriodicUpdatesEvent(          IS_CHECKED(OPT_PeriodicUpdates));\r
212       PonderNextMoveEvent(           IS_CHECKED(OPT_PonderNextMove));\r
213       appData.popupExitMessage     = IS_CHECKED(OPT_PopupExitMessage);\r
214       appData.popupMoveErrors      = IS_CHECKED(OPT_PopupMoveErrors);\r
215       appData.showButtonBar        = IS_CHECKED(OPT_ShowButtonBar);\r
216       appData.showCoords           = IS_CHECKED(OPT_ShowCoordinates);\r
217       ShowThinkingEvent(             IS_CHECKED(OPT_ShowThinking));\r
218       appData.testLegality         = IS_CHECKED(OPT_TestLegality);\r
219       appData.hideThinkingFromHuman= IS_CHECKED(OPT_HideThinkFromHuman);\r
220       appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN);\r
221       appData.showEvalInMoveHistory= IS_CHECKED(OPT_ExtraInfoInMoveHistory);\r
222       appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow);\r
223 \r
224 #undef IS_CHECKED\r
225 \r
226       SetWindowPos(hwndMain, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,\r
227                    0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);\r
228 #if AOT_CONSOLE\r
229       if (hwndConsole) {\r
230         SetWindowPos(hwndConsole, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,\r
231                      0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);\r
232       }\r
233 #endif\r
234       if (!appData.highlightLastMove) {\r
235         ClearHighlights();\r
236         DrawPosition(FALSE, NULL);\r
237       }\r
238       /* \r
239        * for some reason the redraw seems smoother when we invalidate\r
240        * the board rect after the call to EndDialog()\r
241        */\r
242       EndDialog(hDlg, TRUE);\r
243 \r
244       if (oldShowButtonBar != appData.showButtonBar) {\r
245         InitDrawingSizes(boardSize, 0);\r
246       } else if ((oldShowCoords != appData.showCoords) || \r
247                  (oldBlindfold != appData.blindfold)) {\r
248         InvalidateRect(hwndMain, &boardRect, FALSE);\r
249       }\r
250 \r
251       return TRUE;\r
252 \r
253     case IDCANCEL:\r
254       EndDialog(hDlg, FALSE);\r
255       return TRUE;\r
256 \r
257     }\r
258     break;\r
259   }\r
260   return FALSE;\r
261 }\r
262 \r
263 VOID \r
264 GeneralOptionsPopup(HWND hwnd)\r
265 {\r
266   FARPROC lpProc;\r
267 \r
268   lpProc = MakeProcInstance((FARPROC)GeneralOptionsDialog, hInst);\r
269   DialogBox(hInst, MAKEINTRESOURCE(DLG_GeneralOptions), hwnd,\r
270             (DLGPROC) lpProc);\r
271   FreeProcInstance(lpProc);\r
272 }\r
273 /*---------------------------------------------------------------------------*\\r
274  *\r
275  * Board Options Dialog functions\r
276  *\r
277 \*---------------------------------------------------------------------------*/\r
278 \r
279 const int SAMPLE_SQ_SIZE = 54;\r
280 \r
281 VOID\r
282 ChangeBoardSize(BoardSize newSize)\r
283 {\r
284   if (newSize != boardSize) {\r
285     boardSize = newSize;\r
286     InitDrawingSizes(boardSize, 0);\r
287   }\r
288 }\r
289 \r
290 VOID\r
291 PaintSampleSquare(\r
292     HWND     hwnd, \r
293     int      ctrlid, \r
294     COLORREF squareColor, \r
295     COLORREF pieceColor,\r
296     COLORREF squareOutlineColor,\r
297     COLORREF pieceDetailColor,\r
298     BOOL     isWhitePiece,\r
299     BOOL     isMono,\r
300     HBITMAP  pieces[3] \r
301     )\r
302 {\r
303   HBRUSH  brushSquare;\r
304   HBRUSH  brushSquareOutline;\r
305   HBRUSH  brushPiece;\r
306   HBRUSH  brushPieceDetail;\r
307   HBRUSH  oldBrushPiece;\r
308   HBRUSH  oldBrushSquare;\r
309   HBITMAP oldBitmapMem;\r
310   HBITMAP oldBitmapTemp;\r
311   HBITMAP bufferBitmap;\r
312   RECT    rect;\r
313   HDC     hdcScreen, hdcMem, hdcTemp;\r
314   HPEN    pen, oldPen;\r
315   HWND    hCtrl = GetDlgItem(hwnd, ctrlid);\r
316   int     x, y;\r
317 \r
318   const int SOLID   = 0;\r
319   const int WHITE   = 1;\r
320   const int OUTLINE = 2;\r
321   const int BORDER  = 4;\r
322 \r
323   InvalidateRect(hCtrl, NULL, TRUE);\r
324   UpdateWindow(hCtrl);\r
325   GetClientRect(hCtrl, &rect);\r
326   x = rect.left + (BORDER / 2);\r
327   y = rect.top  + (BORDER / 2);\r
328   hdcScreen = GetDC(hCtrl);\r
329   hdcMem  = CreateCompatibleDC(hdcScreen);\r
330   hdcTemp = CreateCompatibleDC(hdcScreen);\r
331 \r
332   bufferBitmap = CreateCompatibleBitmap(hdcScreen, rect.right-rect.left+1,\r
333                                         rect.bottom-rect.top+1);\r
334   oldBitmapMem = SelectObject(hdcMem, bufferBitmap);\r
335   if (!isMono) {\r
336     SelectPalette(hdcMem, hPal, FALSE);\r
337   }\r
338   brushSquare         = CreateSolidBrush(squareColor);\r
339   brushSquareOutline  = CreateSolidBrush(squareOutlineColor);\r
340   brushPiece          = CreateSolidBrush(pieceColor);\r
341   brushPieceDetail    = CreateSolidBrush(pieceDetailColor);\r
342 \r
343   /* \r
344    * first draw the rectangle \r
345    */\r
346   pen      = CreatePen(PS_SOLID, BORDER, squareOutlineColor);\r
347   oldPen   = (HPEN)  SelectObject(hdcMem, pen);\r
348   oldBrushSquare = (HBRUSH)SelectObject(hdcMem, brushSquare);\r
349   Rectangle(hdcMem, rect.left, rect.top, rect.right, rect.bottom);\r
350 \r
351   /* \r
352    * now draw the piece\r
353    */\r
354   if (isMono) {\r
355     oldBitmapTemp = SelectObject(hdcTemp, pieces[OUTLINE]);\r
356     BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, hdcTemp, 0, 0,\r
357            isWhitePiece ? SRCCOPY : NOTSRCCOPY);\r
358     SelectObject(hdcTemp, oldBitmapTemp);\r
359   } else {\r
360     if (isWhitePiece) {\r
361       oldBitmapTemp = SelectObject(hdcTemp, pieces[WHITE]);\r
362       oldBrushPiece = SelectObject(hdcMem, brushPiece);\r
363       BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
364              hdcTemp, 0, 0, 0x00B8074A);\r
365 #if 0\r
366       /* Use pieceDetailColor for outline of white pieces */\r
367       SelectObject(hdcTemp, pieces[OUTLINE]);\r
368       SelectObject(hdcMem, brushPieceDetail);\r
369       BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
370              hdcTemp, 0, 0, 0x00B8074A);\r
371 #else\r
372       /* Use black for outline of white pieces */\r
373       SelectObject(hdcTemp, pieces[OUTLINE]);\r
374       BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
375              hdcTemp, 0, 0, SRCAND);\r
376 #endif\r
377     } else {\r
378 #if 0\r
379       /* Use pieceDetailColor for details of black pieces */\r
380       /* Requires filled-in solid bitmaps (BLACK_PIECE class); the\r
381          WHITE_PIECE ones aren't always the right shape. */\r
382       oldBitmapTemp = SelectObject(hdcTemp, pieces[BLACK]);\r
383       oldBrushPiece = SelectObject(hdcMem, brushPieceDetail);\r
384       BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
385              hdcTemp, 0, 0, 0x00B8074A);\r
386       SelectObject(hdcTemp, pieces[SOLID]);\r
387       SelectObject(hdcMem, brushPiece);\r
388       BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
389              hdcTemp, 0, 0, 0x00B8074A);\r
390 #else\r
391       /* Use square color for details of black pieces */\r
392       oldBitmapTemp = SelectObject(hdcTemp, pieces[SOLID]);\r
393       oldBrushPiece = SelectObject(hdcMem, brushPiece);\r
394       BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
395              hdcTemp, 0, 0, 0x00B8074A);\r
396 #endif\r
397     }\r
398     SelectObject(hdcMem, oldBrushPiece);\r
399     SelectObject(hdcTemp, oldBitmapTemp);\r
400   }\r
401   /* \r
402    * copy the memory dc to the screen\r
403    */\r
404   SelectObject(hdcMem, bufferBitmap);\r
405   BitBlt(hdcScreen, rect.left, rect.top,\r
406          rect.right - rect.left,\r
407          rect.bottom - rect.top,\r
408          hdcMem, rect.left, rect.top, SRCCOPY);\r
409   SelectObject(hdcMem, oldBitmapMem);\r
410   /* \r
411    * clean up\r
412    */\r
413   SelectObject(hdcMem, oldBrushPiece);\r
414   SelectObject(hdcMem, oldPen);\r
415   DeleteObject(brushPiece);\r
416   DeleteObject(brushPieceDetail);\r
417   DeleteObject(brushSquare);\r
418   DeleteObject(brushSquareOutline);\r
419   DeleteObject(pen);\r
420   DeleteDC(hdcTemp);\r
421   DeleteDC(hdcMem);\r
422   ReleaseDC(hCtrl, hdcScreen);\r
423 }\r
424 \r
425 \r
426 VOID\r
427 PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color)\r
428 {\r
429   HDC    hdc;\r
430   HBRUSH brush, oldBrush;\r
431   RECT   rect;\r
432   HWND   hCtrl = GetDlgItem(hwnd, ctrlid);\r
433 \r
434   hdc = GetDC(hCtrl);\r
435   InvalidateRect(hCtrl, NULL, TRUE);\r
436   UpdateWindow(hCtrl);\r
437   GetClientRect(hCtrl, &rect);\r
438   brush = CreateSolidBrush(color);\r
439   oldBrush = (HBRUSH)SelectObject(hdc, brush);\r
440   Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);\r
441   SelectObject(hdc, oldBrush);\r
442   DeleteObject(brush);\r
443   ReleaseDC(hCtrl, hdc);\r
444 }\r
445 \r
446 \r
447 VOID\r
448 SetBoardOptionEnables(HWND hDlg)\r
449 {\r
450   if (IsDlgButtonChecked(hDlg, OPT_Monochrome)) {\r
451     ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_HIDE);\r
452     ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_HIDE);\r
453     ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_HIDE);\r
454     ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_HIDE);\r
455 \r
456     EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), FALSE);\r
457     EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), FALSE);\r
458     EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), FALSE);\r
459     EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), FALSE);\r
460   } else {\r
461     ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_SHOW);\r
462     ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_SHOW);\r
463     ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_SHOW);\r
464     ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_SHOW);\r
465 \r
466     EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), TRUE);\r
467     EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), TRUE);\r
468     EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), TRUE);\r
469     EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), TRUE);\r
470   }\r
471 }\r
472 \r
473 BoardSize \r
474 BoardOptionsWhichRadio(HWND hDlg)\r
475 {\r
476   return (IsDlgButtonChecked(hDlg, OPT_SizeTiny) ? SizeTiny :\r
477          (IsDlgButtonChecked(hDlg, OPT_SizeTeeny) ? SizeTeeny :\r
478          (IsDlgButtonChecked(hDlg, OPT_SizeDinky) ? SizeDinky :\r
479          (IsDlgButtonChecked(hDlg, OPT_SizePetite) ? SizePetite :\r
480          (IsDlgButtonChecked(hDlg, OPT_SizeSlim) ? SizeSlim :\r
481          (IsDlgButtonChecked(hDlg, OPT_SizeSmall) ? SizeSmall :\r
482          (IsDlgButtonChecked(hDlg, OPT_SizeMediocre) ? SizeMediocre :\r
483          (IsDlgButtonChecked(hDlg, OPT_SizeMiddling) ? SizeMiddling :\r
484          (IsDlgButtonChecked(hDlg, OPT_SizeAverage) ? SizeAverage :\r
485          (IsDlgButtonChecked(hDlg, OPT_SizeModerate) ? SizeModerate :\r
486          (IsDlgButtonChecked(hDlg, OPT_SizeMedium) ? SizeMedium :\r
487          (IsDlgButtonChecked(hDlg, OPT_SizeBulky) ? SizeBulky :\r
488          (IsDlgButtonChecked(hDlg, OPT_SizeLarge) ? SizeLarge :\r
489          (IsDlgButtonChecked(hDlg, OPT_SizeBig) ? SizeBig :\r
490          (IsDlgButtonChecked(hDlg, OPT_SizeHuge) ? SizeHuge :\r
491          (IsDlgButtonChecked(hDlg, OPT_SizeGiant) ? SizeGiant :\r
492          (IsDlgButtonChecked(hDlg, OPT_SizeColossal) ? SizeColossal :\r
493           SizeTitanic )))))))))))))))));\r
494 }\r
495 \r
496 LRESULT CALLBACK\r
497 BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
498 {\r
499   static Boolean  mono, white, flip;\r
500   static BoardSize size;\r
501   static COLORREF lsc, dsc, wpc, bpc, hsc, phc;\r
502   static HBITMAP pieces[3];\r
503 \r
504   switch (message) {\r
505   case WM_INITDIALOG: /* message: initialize dialog box */\r
506     /* Center the dialog over the application window */\r
507     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
508     /* Initialize the dialog items */\r
509     switch (boardSize) {\r
510     case SizeTiny:\r
511       CheckDlgButton(hDlg, OPT_SizeTiny, TRUE);\r
512       break;\r
513     case SizeTeeny:\r
514       CheckDlgButton(hDlg, OPT_SizeTeeny, TRUE);\r
515       break;\r
516     case SizeDinky:\r
517       CheckDlgButton(hDlg, OPT_SizeDinky, TRUE);\r
518       break;\r
519     case SizePetite:\r
520       CheckDlgButton(hDlg, OPT_SizePetite, TRUE);\r
521       break;\r
522     case SizeSlim:\r
523       CheckDlgButton(hDlg, OPT_SizeSlim, TRUE);\r
524       break;\r
525     case SizeSmall:\r
526       CheckDlgButton(hDlg, OPT_SizeSmall, TRUE);\r
527       break;\r
528     case SizeMediocre:\r
529       CheckDlgButton(hDlg, OPT_SizeMediocre, TRUE);\r
530       break;\r
531     case SizeMiddling:\r
532       CheckDlgButton(hDlg, OPT_SizeMiddling, TRUE);\r
533       break;\r
534     case SizeAverage:\r
535       CheckDlgButton(hDlg, OPT_SizeAverage, TRUE);\r
536       break;\r
537     case SizeModerate:\r
538       CheckDlgButton(hDlg, OPT_SizeModerate, TRUE);\r
539       break;\r
540     case SizeMedium:\r
541       CheckDlgButton(hDlg, OPT_SizeMedium, TRUE);\r
542       break;\r
543     case SizeBulky:\r
544       CheckDlgButton(hDlg, OPT_SizeBulky, TRUE);\r
545       break;\r
546     case SizeLarge:\r
547       CheckDlgButton(hDlg, OPT_SizeLarge, TRUE);\r
548       break;\r
549     case SizeBig:\r
550       CheckDlgButton(hDlg, OPT_SizeBig, TRUE);\r
551       break;\r
552     case SizeHuge:\r
553       CheckDlgButton(hDlg, OPT_SizeHuge, TRUE);\r
554       break;\r
555     case SizeGiant:\r
556       CheckDlgButton(hDlg, OPT_SizeGiant, TRUE);\r
557       break;\r
558     case SizeColossal:\r
559       CheckDlgButton(hDlg, OPT_SizeColossal, TRUE);\r
560       break;\r
561     case SizeTitanic:\r
562       CheckDlgButton(hDlg, OPT_SizeTitanic, TRUE);\r
563     }\r
564 \r
565     if (appData.monoMode)\r
566       CheckDlgButton(hDlg, OPT_Monochrome, TRUE);\r
567 \r
568     if (appData.allWhite)\r
569       CheckDlgButton(hDlg, OPT_AllWhite, TRUE);\r
570 \r
571     if (appData.upsideDown)\r
572       CheckDlgButton(hDlg, OPT_UpsideDown, TRUE);\r
573 \r
574     pieces[0] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "s");\r
575     pieces[1] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "w");\r
576     pieces[2] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "o");\r
577         \r
578     lsc = lightSquareColor;\r
579     dsc = darkSquareColor;\r
580     wpc = whitePieceColor;\r
581     bpc = blackPieceColor;\r
582     hsc = highlightSquareColor;\r
583     phc = premoveHighlightColor;\r
584     mono = appData.monoMode;\r
585     white= appData.allWhite;\r
586     flip = appData.upsideDown;\r
587     size = boardSize;\r
588 \r
589     SetBoardOptionEnables(hDlg);\r
590     return TRUE;\r
591 \r
592   case WM_PAINT:\r
593     PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);\r
594     PaintColorBlock(hDlg, OPT_DarkSquareColor,  dsc);\r
595     PaintColorBlock(hDlg, OPT_WhitePieceColor,  wpc);\r
596     PaintColorBlock(hDlg, OPT_BlackPieceColor,  bpc);\r
597     PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);\r
598     PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);\r
599     PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,\r
600         TRUE, mono, pieces);\r
601     PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,\r
602         FALSE, mono, pieces);\r
603 \r
604     return FALSE;\r
605 \r
606   case WM_COMMAND: /* message: received a command */\r
607     switch (LOWORD(wParam)) {\r
608     case IDOK:\r
609       /* \r
610        * if we call EndDialog() after the call to ChangeBoardSize(),\r
611        * then ChangeBoardSize() does not take effect, although the new\r
612        * boardSize is saved. Go figure...\r
613        */\r
614       EndDialog(hDlg, TRUE);\r
615 \r
616       size = BoardOptionsWhichRadio(hDlg);\r
617 \r
618       /*\r
619        * did any settings change?\r
620        */\r
621       if (size != boardSize) {\r
622         ChangeBoardSize(size);\r
623       }\r
624 \r
625       if ((mono != appData.monoMode) ||\r
626           (lsc  != lightSquareColor) ||\r
627           (dsc  != darkSquareColor) ||\r
628           (wpc  != whitePieceColor) ||\r
629           (bpc  != blackPieceColor) ||\r
630           (hsc  != highlightSquareColor) ||\r
631           (flip != appData.upsideDown) ||\r
632           (white != appData.allWhite) ||\r
633           (phc  != premoveHighlightColor)) {\r
634 \r
635           lightSquareColor = lsc;\r
636           darkSquareColor = dsc;\r
637           whitePieceColor = wpc;\r
638           blackPieceColor = bpc;\r
639           highlightSquareColor = hsc;\r
640           premoveHighlightColor = phc;\r
641           appData.monoMode = mono;\r
642           appData.allWhite = white;\r
643           appData.upsideDown = flip;\r
644 \r
645           InitDrawingColors();\r
646           InitDrawingSizes(boardSize, 0);\r
647           InvalidateRect(hwndMain, &boardRect, FALSE);\r
648       }\r
649       DeleteObject(pieces[0]);\r
650       DeleteObject(pieces[1]);\r
651       DeleteObject(pieces[2]);\r
652       return TRUE;\r
653 \r
654     case IDCANCEL:\r
655       DeleteObject(pieces[0]);\r
656       DeleteObject(pieces[1]);\r
657       DeleteObject(pieces[2]);\r
658       EndDialog(hDlg, FALSE);\r
659       return TRUE;\r
660 \r
661     case OPT_ChooseLightSquareColor:\r
662       if (ChangeColor(hDlg, &lsc)) \r
663         PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);\r
664         PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,\r
665             TRUE, mono, pieces);\r
666       break;\r
667 \r
668     case OPT_ChooseDarkSquareColor:\r
669       if (ChangeColor(hDlg, &dsc)) \r
670         PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);\r
671         PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,\r
672             FALSE, mono, pieces);\r
673       break;\r
674 \r
675     case OPT_ChooseWhitePieceColor:\r
676       if (ChangeColor(hDlg, &wpc)) \r
677         PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);\r
678         PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,\r
679             TRUE, mono, pieces);\r
680       break;\r
681 \r
682     case OPT_ChooseBlackPieceColor:\r
683       if (ChangeColor(hDlg, &bpc)) \r
684         PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);\r
685         PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,\r
686             FALSE, mono, pieces);\r
687       break;\r
688 \r
689     case OPT_ChooseHighlightSquareColor:\r
690       if (ChangeColor(hDlg, &hsc)) \r
691         PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);\r
692         PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,\r
693             TRUE, mono, pieces);\r
694       break;\r
695 \r
696     case OPT_ChoosePremoveHighlightColor:\r
697       if (ChangeColor(hDlg, &phc)) \r
698         PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);\r
699         PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,\r
700             FALSE, mono, pieces);\r
701       break;\r
702 \r
703     case OPT_DefaultBoardColors:\r
704       lsc = ParseColorName(LIGHT_SQUARE_COLOR);\r
705       dsc = ParseColorName(DARK_SQUARE_COLOR);\r
706       wpc = ParseColorName(WHITE_PIECE_COLOR);\r
707       bpc = ParseColorName(BLACK_PIECE_COLOR);\r
708       hsc = ParseColorName(HIGHLIGHT_SQUARE_COLOR);\r
709       phc = ParseColorName(PREMOVE_HIGHLIGHT_COLOR);\r
710       mono = FALSE;\r
711       white= FALSE;\r
712       flip = FALSE;\r
713       CheckDlgButton(hDlg, OPT_Monochrome, FALSE);\r
714       CheckDlgButton(hDlg, OPT_AllWhite,   FALSE);\r
715       CheckDlgButton(hDlg, OPT_UpsideDown, FALSE);\r
716       PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);\r
717       PaintColorBlock(hDlg, OPT_DarkSquareColor,  dsc);\r
718       PaintColorBlock(hDlg, OPT_WhitePieceColor,  wpc);\r
719       PaintColorBlock(hDlg, OPT_BlackPieceColor,  bpc);\r
720       PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);\r
721       PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);\r
722       SetBoardOptionEnables(hDlg);\r
723       PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,\r
724           TRUE, mono, pieces);\r
725       PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,\r
726           FALSE, mono, pieces);\r
727       break;\r
728 \r
729     case OPT_Monochrome:\r
730       mono = !mono;\r
731       SetBoardOptionEnables(hDlg);\r
732       break;\r
733 \r
734     case OPT_AllWhite:\r
735       white = !white;\r
736       SetBoardOptionEnables(hDlg);\r
737       break;\r
738 \r
739     case OPT_UpsideDown:\r
740       flip = !flip;\r
741       SetBoardOptionEnables(hDlg);\r
742       break;\r
743     }\r
744     break;\r
745   }\r
746   return FALSE;\r
747 }\r
748 \r
749 \r
750 VOID\r
751 BoardOptionsPopup(HWND hwnd)\r
752 {\r
753   FARPROC lpProc = MakeProcInstance((FARPROC)BoardOptionsDialog, hInst);\r
754   DialogBox(hInst, MAKEINTRESOURCE(DLG_BoardOptions), hwnd,\r
755           (DLGPROC) lpProc);\r
756   FreeProcInstance(lpProc);\r
757 }\r
758 \r
759 VariantClass\r
760 VariantWhichRadio(HWND hDlg)\r
761 {\r
762   return (IsDlgButtonChecked(hDlg, OPT_VariantFairy) ? VariantFairy :\r
763          (IsDlgButtonChecked(hDlg, OPT_VariantGothic) ? VariantGothic :\r
764          (IsDlgButtonChecked(hDlg, OPT_VariantCrazyhouse) ? VariantCrazyhouse :\r
765          (IsDlgButtonChecked(hDlg, OPT_VariantBughouse) ? VariantBughouse :\r
766          (IsDlgButtonChecked(hDlg, OPT_VariantCourier) ? VariantCourier :\r
767          (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :\r
768          (IsDlgButtonChecked(hDlg, OPT_VariantShogi) ? VariantShogi :\r
769          (IsDlgButtonChecked(hDlg, OPT_VariantXiangqi) ? VariantXiangqi :\r
770          (IsDlgButtonChecked(hDlg, OPT_VariantCapablanca) ? VariantCapablanca :\r
771          (IsDlgButtonChecked(hDlg, OPT_VariantTwoKings) ? VariantTwoKings :\r
772          (IsDlgButtonChecked(hDlg, OPT_VariantKnightmate) ? VariantKnightmate :\r
773          (IsDlgButtonChecked(hDlg, OPT_VariantLosers) ? VariantLosers :\r
774          (IsDlgButtonChecked(hDlg, OPT_VariantSuicide) ? VariantSuicide :\r
775          (IsDlgButtonChecked(hDlg, OPT_VariantAtomic) ? VariantAtomic :\r
776          (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj :\r
777          (IsDlgButtonChecked(hDlg, OPT_VariantFRC) ? VariantFischeRandom :\r
778          (IsDlgButtonChecked(hDlg, OPT_VariantCylinder) ? VariantCylinder :\r
779          (IsDlgButtonChecked(hDlg, OPT_VariantFalcon) ? VariantFalcon :\r
780           VariantNormal ))))))))))))))))));\r
781 }\r
782 \r
783 LRESULT CALLBACK\r
784 NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
785 {\r
786   static Boolean  mono;\r
787   static VariantClass v;\r
788   static COLORREF lsc, dsc, wpc, bpc, hsc, phc;\r
789   static HBITMAP pieces[3];\r
790   static int n1_ok, n2_ok, n3_ok;\r
791 \r
792   switch (message) {\r
793   case WM_INITDIALOG: /* message: initialize dialog box */\r
794     /* Center the dialog over the application window */\r
795     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
796     /* Initialize the dialog items */\r
797     switch (gameInfo.variant) {\r
798     case VariantNormal:\r
799       CheckDlgButton(hDlg, OPT_VariantNormal, TRUE);\r
800       break;\r
801     case VariantCrazyhouse:\r
802       CheckDlgButton(hDlg, OPT_VariantCrazyhouse, TRUE);\r
803       break;\r
804     case VariantBughouse:\r
805       CheckDlgButton(hDlg, OPT_VariantBughouse, TRUE);\r
806       break;\r
807     case VariantShogi:\r
808       CheckDlgButton(hDlg, OPT_VariantShogi, TRUE);\r
809       break;\r
810     case VariantXiangqi:\r
811       CheckDlgButton(hDlg, OPT_VariantXiangqi, TRUE);\r
812       break;\r
813     case VariantCapablanca:\r
814       CheckDlgButton(hDlg, OPT_VariantCapablanca, TRUE);\r
815       break;\r
816     case VariantGothic:\r
817       CheckDlgButton(hDlg, OPT_VariantGothic, TRUE);\r
818       break;\r
819     case VariantCourier:\r
820       CheckDlgButton(hDlg, OPT_VariantCourier, TRUE);\r
821       break;\r
822     case VariantKnightmate:\r
823       CheckDlgButton(hDlg, OPT_VariantKnightmate, TRUE);\r
824       break;\r
825     case VariantTwoKings:\r
826       CheckDlgButton(hDlg, OPT_VariantTwoKings, TRUE);\r
827       break;\r
828     case VariantFairy:\r
829       CheckDlgButton(hDlg, OPT_VariantFairy, TRUE);\r
830       break;\r
831     case VariantAtomic:\r
832       CheckDlgButton(hDlg, OPT_VariantAtomic, TRUE);\r
833       break;\r
834     case VariantSuicide:\r
835       CheckDlgButton(hDlg, OPT_VariantSuicide, TRUE);\r
836       break;\r
837     case VariantLosers:\r
838       CheckDlgButton(hDlg, OPT_VariantLosers, TRUE);\r
839       break;\r
840     case VariantShatranj:\r
841       CheckDlgButton(hDlg, OPT_VariantShatranj, TRUE);\r
842       break;\r
843     case VariantFischeRandom:\r
844       CheckDlgButton(hDlg, OPT_VariantFRC, TRUE);\r
845       break;\r
846     }\r
847 \r
848     SetDlgItemInt( hDlg, IDC_Files, -1, TRUE );\r
849     SendDlgItemMessage( hDlg, IDC_Files, EM_SETSEL, 0, -1 );\r
850 \r
851     SetDlgItemInt( hDlg, IDC_Ranks, -1, TRUE );\r
852     SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );\r
853 \r
854     SetDlgItemInt( hDlg, IDC_Holdings, -1, TRUE );\r
855     SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );\r
856 \r
857     n1_ok = n2_ok = n3_ok = FALSE;\r
858 \r
859     return TRUE;\r
860 \r
861   case WM_COMMAND: /* message: received a command */\r
862     switch (LOWORD(wParam)) {\r
863     case IDOK:\r
864       /* \r
865        * if we call EndDialog() after the call to ChangeBoardSize(),\r
866        * then ChangeBoardSize() does not take effect, although the new\r
867        * boardSize is saved. Go figure...\r
868        */\r
869       EndDialog(hDlg, TRUE);\r
870 \r
871       v = VariantWhichRadio(hDlg);\r
872 \r
873       gameInfo.variant = v;\r
874       appData.variant = VariantName(v);\r
875 \r
876       appData.NrFiles = (int) GetDlgItemInt(hDlg, IDC_Files, NULL, FALSE );\r
877       appData.NrRanks = (int) GetDlgItemInt(hDlg, IDC_Ranks, NULL, FALSE );\r
878       appData.holdingsSize = (int) GetDlgItemInt(hDlg, IDC_Holdings, NULL, FALSE );\r
879 \r
880       if(!n1_ok) appData.NrFiles = -1;\r
881       if(!n2_ok) appData.NrRanks = -1;\r
882       if(!n3_ok) appData.holdingsSize = -1;\r
883 \r
884       startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */\r
885       appData.pieceToCharTable = NULL;\r
886       Reset(TRUE, TRUE);\r
887 \r
888       return TRUE;\r
889 \r
890     case IDCANCEL:\r
891       EndDialog(hDlg, FALSE);\r
892       return TRUE;\r
893 \r
894     case IDC_Ranks:\r
895     case IDC_Files:\r
896     case IDC_Holdings:\r
897         if( HIWORD(wParam) == EN_CHANGE ) {\r
898 \r
899             GetDlgItemInt(hDlg, IDC_Files, &n1_ok, FALSE );\r
900             GetDlgItemInt(hDlg, IDC_Ranks, &n2_ok, FALSE );\r
901             GetDlgItemInt(hDlg, IDC_Holdings, &n3_ok, FALSE );\r
902 \r
903             /*EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok ? TRUE : FALSE );*/\r
904         }\r
905         return TRUE;\r
906     }\r
907     break;\r
908   }\r
909   return FALSE;\r
910 }\r
911 \r
912 \r
913 VOID\r
914 NewVariantPopup(HWND hwnd)\r
915 {\r
916   FARPROC lpProc = MakeProcInstance((FARPROC)NewVariantDialog, hInst);\r
917   DialogBox(hInst, MAKEINTRESOURCE(DLG_NewVariant), hwnd,\r
918           (DLGPROC) lpProc);\r
919   FreeProcInstance(lpProc);\r
920 }\r
921 \r
922 /*---------------------------------------------------------------------------*\\r
923  *\r
924  * ICS Options Dialog functions\r
925  *\r
926 \*---------------------------------------------------------------------------*/\r
927 \r
928 BOOL APIENTRY\r
929 MyCreateFont(HWND hwnd, MyFont *font)\r
930 {\r
931   CHOOSEFONT cf;\r
932   HFONT hf;\r
933 \r
934   /* Initialize members of the CHOOSEFONT structure. */\r
935   cf.lStructSize = sizeof(CHOOSEFONT);\r
936   cf.hwndOwner = hwnd;\r
937   cf.hDC = (HDC)NULL;\r
938   cf.lpLogFont = &font->lf;\r
939   cf.iPointSize = 0;\r
940   cf.Flags = CF_SCREENFONTS|/*CF_ANSIONLY|*/CF_INITTOLOGFONTSTRUCT;\r
941   cf.rgbColors = RGB(0,0,0);\r
942   cf.lCustData = 0L;\r
943   cf.lpfnHook = (LPCFHOOKPROC)NULL;\r
944   cf.lpTemplateName = (LPSTR)NULL;\r
945   cf.hInstance = (HINSTANCE) NULL;\r
946   cf.lpszStyle = (LPSTR)NULL;\r
947   cf.nFontType = SCREEN_FONTTYPE;\r
948   cf.nSizeMin = 0;\r
949   cf.nSizeMax = 0;\r
950 \r
951   /* Display the CHOOSEFONT common-dialog box. */\r
952   if (!ChooseFont(&cf)) {\r
953     return FALSE;\r
954   }\r
955 \r
956   /* Create a logical font based on the user's   */\r
957   /* selection and return a handle identifying   */\r
958   /* that font. */\r
959   hf = CreateFontIndirect(cf.lpLogFont);\r
960   if (hf == NULL) {\r
961     return FALSE;\r
962   }\r
963 \r
964   font->hf = hf;\r
965   font->mfp.pointSize = (float) (cf.iPointSize / 10.0);\r
966   font->mfp.bold = (font->lf.lfWeight >= FW_BOLD);\r
967   font->mfp.italic = font->lf.lfItalic;\r
968   font->mfp.underline = font->lf.lfUnderline;\r
969   font->mfp.strikeout = font->lf.lfStrikeOut;\r
970   strcpy(font->mfp.faceName, font->lf.lfFaceName);\r
971   return TRUE;\r
972 }\r
973 \r
974 \r
975 VOID\r
976 UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca)\r
977 {\r
978   CHARFORMAT cf;\r
979   cf.cbSize = sizeof(CHARFORMAT);\r
980   cf.dwMask = \r
981     CFM_COLOR|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE;\r
982   cf.crTextColor = mca->color;\r
983   cf.dwEffects = mca->effects;\r
984   strcpy(cf.szFaceName, font[boardSize][CONSOLE_FONT]->mfp.faceName);\r
985   /* \r
986    * The 20.0 below is in fact documented. yHeight is expressed in twips.\r
987    * A twip is 1/20 of a font's point size. See documentation of CHARFORMAT.\r
988    * --msw\r
989    */\r
990   cf.yHeight = (int)(font[boardSize][CONSOLE_FONT]->mfp.pointSize * 20.0 + 0.5);\r
991   cf.bCharSet = DEFAULT_CHARSET; /* should be ignored anyway */\r
992   cf.bPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;\r
993   SendDlgItemMessage(hDlg, id, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);\r
994 }\r
995 \r
996 LRESULT CALLBACK\r
997 ColorizeTextDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
998 {\r
999   static MyColorizeAttribs mca;\r
1000   static ColorClass cc;\r
1001   COLORREF background = (COLORREF)0;\r
1002 \r
1003   switch (message) {\r
1004   case WM_INITDIALOG:\r
1005     cc = (ColorClass)lParam;\r
1006     mca = colorizeAttribs[cc];\r
1007     /* Center the dialog over the application window */\r
1008     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
1009     /* Initialize the dialog items */\r
1010     CheckDlgButton(hDlg, OPT_Bold, (mca.effects & CFE_BOLD) != 0);\r
1011     CheckDlgButton(hDlg, OPT_Italic, (mca.effects & CFE_ITALIC) != 0);\r
1012     CheckDlgButton(hDlg, OPT_Underline, (mca.effects & CFE_UNDERLINE) != 0);\r
1013     CheckDlgButton(hDlg, OPT_Strikeout, (mca.effects & CFE_STRIKEOUT) != 0);\r
1014 \r
1015     /* get the current background color from the parent window */\r
1016     SendMessage(GetWindow(hDlg, GW_OWNER),WM_COMMAND, \r
1017                 (WPARAM)WM_USER_GetConsoleBackground, \r
1018                 (LPARAM)&background);\r
1019 \r
1020     /* set the background color */\r
1021     SendDlgItemMessage(hDlg, OPT_Sample, EM_SETBKGNDCOLOR, FALSE, background);\r
1022 \r
1023     SetDlgItemText(hDlg, OPT_Sample, mca.name);\r
1024     UpdateSampleText(hDlg, OPT_Sample, &mca);\r
1025     return TRUE;\r
1026 \r
1027   case WM_COMMAND: /* message: received a command */\r
1028     switch (LOWORD(wParam)) {\r
1029     case IDOK:\r
1030       /* Read changed options from the dialog box */\r
1031       colorizeAttribs[cc] = mca;\r
1032       textAttribs[cc].color = mca.color;\r
1033       textAttribs[cc].effects = mca.effects;\r
1034       Colorize(currentColorClass, TRUE);\r
1035       if (cc == ColorNormal) {\r
1036         CHARFORMAT cf;\r
1037         cf.cbSize = sizeof(CHARFORMAT);\r
1038         cf.dwMask = CFM_COLOR;\r
1039         cf.crTextColor = mca.color;\r
1040         SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, \r
1041           EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);\r
1042       }\r
1043       EndDialog(hDlg, TRUE);\r
1044       return TRUE;\r
1045 \r
1046     case IDCANCEL:\r
1047       EndDialog(hDlg, FALSE);\r
1048       return TRUE;\r
1049 \r
1050     case OPT_ChooseColor:\r
1051       ChangeColor(hDlg, &mca.color);\r
1052       UpdateSampleText(hDlg, OPT_Sample, &mca);\r
1053       return TRUE;\r
1054 \r
1055     default:\r
1056       mca.effects =\r
1057         (IsDlgButtonChecked(hDlg, OPT_Bold) ? CFE_BOLD : 0) |\r
1058         (IsDlgButtonChecked(hDlg, OPT_Italic) ? CFE_ITALIC : 0) |\r
1059         (IsDlgButtonChecked(hDlg, OPT_Underline) ? CFE_UNDERLINE : 0) |\r
1060         (IsDlgButtonChecked(hDlg, OPT_Strikeout) ? CFE_STRIKEOUT : 0);\r
1061       UpdateSampleText(hDlg, OPT_Sample, &mca);\r
1062       break;\r
1063     }\r
1064     break;\r
1065   }\r
1066   return FALSE;\r
1067 }\r
1068 \r
1069 VOID\r
1070 ColorizeTextPopup(HWND hwnd, ColorClass cc)\r
1071 {\r
1072   FARPROC lpProc;\r
1073 \r
1074   lpProc = MakeProcInstance((FARPROC)ColorizeTextDialog, hInst);\r
1075   DialogBoxParam(hInst, MAKEINTRESOURCE(DLG_Colorize),\r
1076     hwnd, (DLGPROC)lpProc, (LPARAM) cc);\r
1077   FreeProcInstance(lpProc);\r
1078 }\r
1079 \r
1080 VOID\r
1081 SetIcsOptionEnables(HWND hDlg)\r
1082 {\r
1083 #define ENABLE_DLG_ITEM(x,y) EnableWindow(GetDlgItem(hDlg,(x)), (y))\r
1084 \r
1085   UINT state = IsDlgButtonChecked(hDlg, OPT_Premove);\r
1086   ENABLE_DLG_ITEM(OPT_PremoveWhite, state);\r
1087   ENABLE_DLG_ITEM(OPT_PremoveWhiteText, state);\r
1088   ENABLE_DLG_ITEM(OPT_PremoveBlack, state);\r
1089   ENABLE_DLG_ITEM(OPT_PremoveBlackText, state);\r
1090 \r
1091   ENABLE_DLG_ITEM(OPT_IcsAlarmTime, IsDlgButtonChecked(hDlg, OPT_IcsAlarm));\r
1092 \r
1093 #undef ENABLE_DLG_ITEM\r
1094 }\r
1095 \r
1096 \r
1097 LRESULT CALLBACK\r
1098 IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
1099 {\r
1100   char buf[MSG_SIZ];\r
1101   int number;\r
1102   int i;\r
1103   static COLORREF cbc;\r
1104   static MyColorizeAttribs *mca;\r
1105   COLORREF *colorref;\r
1106 \r
1107   switch (message) {\r
1108   case WM_INITDIALOG: /* message: initialize dialog box */\r
1109 \r
1110     mca = colorizeAttribs;\r
1111 \r
1112     for (i=0; i < NColorClasses - 1; i++) {\r
1113       mca[i].color   = textAttribs[i].color;\r
1114       mca[i].effects = textAttribs[i].effects;\r
1115     }\r
1116     cbc = consoleBackgroundColor;\r
1117 \r
1118     /* Center the dialog over the application window */\r
1119     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
1120 \r
1121     /* Initialize the dialog items */\r
1122 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))\r
1123 \r
1124     CHECK_BOX(OPT_AutoComment, appData.autoComment);\r
1125     CHECK_BOX(OPT_AutoObserve, appData.autoObserve);\r
1126     CHECK_BOX(OPT_GetMoveList, appData.getMoveList);\r
1127     CHECK_BOX(OPT_LocalLineEditing, appData.localLineEditing);\r
1128     CHECK_BOX(OPT_QuietPlay, appData.quietPlay);\r
1129     CHECK_BOX(OPT_Premove, appData.premove);\r
1130     CHECK_BOX(OPT_PremoveWhite, appData.premoveWhite);\r
1131     CHECK_BOX(OPT_PremoveBlack, appData.premoveBlack);\r
1132     CHECK_BOX(OPT_IcsAlarm, appData.icsAlarm);\r
1133     CHECK_BOX(OPT_DontColorize, !appData.colorize);\r
1134 \r
1135 #undef CHECK_BOX\r
1136 \r
1137     sprintf(buf, "%d", appData.icsAlarmTime / 1000);\r
1138     SetDlgItemText(hDlg, OPT_IcsAlarmTime, buf);\r
1139     SetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText);\r
1140     SetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText);\r
1141 \r
1142     SendDlgItemMessage(hDlg, OPT_SampleShout,     EM_SETBKGNDCOLOR, 0, cbc);\r
1143     SendDlgItemMessage(hDlg, OPT_SampleSShout,    EM_SETBKGNDCOLOR, 0, cbc);\r
1144     SendDlgItemMessage(hDlg, OPT_SampleChannel1,  EM_SETBKGNDCOLOR, 0, cbc);\r
1145     SendDlgItemMessage(hDlg, OPT_SampleChannel,   EM_SETBKGNDCOLOR, 0, cbc);\r
1146     SendDlgItemMessage(hDlg, OPT_SampleKibitz,    EM_SETBKGNDCOLOR, 0, cbc);\r
1147     SendDlgItemMessage(hDlg, OPT_SampleTell,      EM_SETBKGNDCOLOR, 0, cbc);\r
1148     SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);\r
1149     SendDlgItemMessage(hDlg, OPT_SampleRequest,   EM_SETBKGNDCOLOR, 0, cbc);\r
1150     SendDlgItemMessage(hDlg, OPT_SampleSeek,      EM_SETBKGNDCOLOR, 0, cbc);\r
1151     SendDlgItemMessage(hDlg, OPT_SampleNormal,    EM_SETBKGNDCOLOR, 0, cbc);\r
1152 \r
1153     SetDlgItemText(hDlg, OPT_SampleShout,     mca[ColorShout].name);\r
1154     SetDlgItemText(hDlg, OPT_SampleSShout,    mca[ColorSShout].name);\r
1155     SetDlgItemText(hDlg, OPT_SampleChannel1,  mca[ColorChannel1].name);\r
1156     SetDlgItemText(hDlg, OPT_SampleChannel,   mca[ColorChannel].name);\r
1157     SetDlgItemText(hDlg, OPT_SampleKibitz,    mca[ColorKibitz].name);\r
1158     SetDlgItemText(hDlg, OPT_SampleTell,      mca[ColorTell].name);\r
1159     SetDlgItemText(hDlg, OPT_SampleChallenge, mca[ColorChallenge].name);\r
1160     SetDlgItemText(hDlg, OPT_SampleRequest,   mca[ColorRequest].name);\r
1161     SetDlgItemText(hDlg, OPT_SampleSeek,      mca[ColorSeek].name);\r
1162     SetDlgItemText(hDlg, OPT_SampleNormal,    mca[ColorNormal].name);\r
1163 \r
1164     UpdateSampleText(hDlg, OPT_SampleShout,     &mca[ColorShout]);\r
1165     UpdateSampleText(hDlg, OPT_SampleSShout,    &mca[ColorSShout]);\r
1166     UpdateSampleText(hDlg, OPT_SampleChannel1,  &mca[ColorChannel1]);\r
1167     UpdateSampleText(hDlg, OPT_SampleChannel,   &mca[ColorChannel]);\r
1168     UpdateSampleText(hDlg, OPT_SampleKibitz,    &mca[ColorKibitz]);\r
1169     UpdateSampleText(hDlg, OPT_SampleTell,      &mca[ColorTell]);\r
1170     UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);\r
1171     UpdateSampleText(hDlg, OPT_SampleRequest,   &mca[ColorRequest]);\r
1172     UpdateSampleText(hDlg, OPT_SampleSeek,      &mca[ColorSeek]);\r
1173     UpdateSampleText(hDlg, OPT_SampleNormal,    &mca[ColorNormal]);\r
1174 \r
1175     SetIcsOptionEnables(hDlg);\r
1176     return TRUE;\r
1177 \r
1178   case WM_COMMAND: /* message: received a command */\r
1179     switch (LOWORD(wParam)) {\r
1180 \r
1181     case WM_USER_GetConsoleBackground: \r
1182       /* the ColorizeTextDialog needs the current background color */\r
1183       colorref = (COLORREF *)lParam;\r
1184       *colorref = cbc;\r
1185       return FALSE;\r
1186 \r
1187     case IDOK:\r
1188       /* Read changed options from the dialog box */\r
1189       GetDlgItemText(hDlg, OPT_IcsAlarmTime, buf, MSG_SIZ);\r
1190       if (sscanf(buf, "%d", &number) != 1 || (number < 0)){\r
1191           MessageBox(hDlg, "Invalid ICS Alarm Time",\r
1192                      "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
1193           return FALSE;\r
1194       }\r
1195 \r
1196 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))\r
1197 \r
1198       appData.icsAlarm         = IS_CHECKED(OPT_IcsAlarm);\r
1199       appData.premove          = IS_CHECKED(OPT_Premove);\r
1200       appData.premoveWhite     = IS_CHECKED(OPT_PremoveWhite);\r
1201       appData.premoveBlack     = IS_CHECKED(OPT_PremoveBlack);\r
1202       appData.autoComment      = IS_CHECKED(OPT_AutoComment);\r
1203       appData.autoObserve      = IS_CHECKED(OPT_AutoObserve);\r
1204       appData.getMoveList      = IS_CHECKED(OPT_GetMoveList);\r
1205       appData.localLineEditing = IS_CHECKED(OPT_LocalLineEditing);\r
1206       appData.quietPlay        = IS_CHECKED(OPT_QuietPlay);\r
1207 \r
1208 #undef IS_CHECKED\r
1209 \r
1210       appData.icsAlarmTime = number * 1000;\r
1211       GetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText, 5);\r
1212       GetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText, 5);\r
1213 \r
1214       if (appData.localLineEditing) {\r
1215         DontEcho();\r
1216         EchoOn();\r
1217       } else {\r
1218         DoEcho();\r
1219         EchoOff();\r
1220       }\r
1221 \r
1222       appData.colorize =\r
1223         (Boolean)!IsDlgButtonChecked(hDlg, OPT_DontColorize);\r
1224 \r
1225       if (!appData.colorize) {\r
1226         CHARFORMAT cf;\r
1227         COLORREF background = ParseColorName(COLOR_BKGD);\r
1228         /*\r
1229         SetDefaultTextAttribs();\r
1230         Colorize(currentColorClass);\r
1231         */\r
1232         cf.cbSize = sizeof(CHARFORMAT);\r
1233         cf.dwMask = CFM_COLOR;\r
1234         cf.crTextColor = ParseColorName(COLOR_NORMAL);\r
1235 \r
1236         SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, \r
1237           EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);\r
1238         SendDlgItemMessage(hwndConsole, OPT_ConsoleText, \r
1239           EM_SETBKGNDCOLOR, FALSE, background);\r
1240         SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, \r
1241           EM_SETBKGNDCOLOR, FALSE, background);\r
1242       }\r
1243 \r
1244       if (cbc != consoleBackgroundColor) {\r
1245         consoleBackgroundColor = cbc;\r
1246         if (appData.colorize) {\r
1247           SendDlgItemMessage(hwndConsole, OPT_ConsoleText, \r
1248             EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);\r
1249           SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, \r
1250             EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);\r
1251         }\r
1252       }\r
1253 \r
1254       for (i=0; i < NColorClasses - 1; i++) {\r
1255         textAttribs[i].color   = mca[i].color;\r
1256         textAttribs[i].effects = mca[i].effects;\r
1257       }\r
1258 \r
1259       EndDialog(hDlg, TRUE);\r
1260       return TRUE;\r
1261 \r
1262     case IDCANCEL:\r
1263       EndDialog(hDlg, FALSE);\r
1264       return TRUE;\r
1265 \r
1266     case OPT_ChooseShoutColor:\r
1267       ColorizeTextPopup(hDlg, ColorShout);\r
1268       UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]);\r
1269       break;\r
1270 \r
1271     case OPT_ChooseSShoutColor:\r
1272       ColorizeTextPopup(hDlg, ColorSShout);\r
1273       UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]);\r
1274       break;\r
1275 \r
1276     case OPT_ChooseChannel1Color:\r
1277       ColorizeTextPopup(hDlg, ColorChannel1);\r
1278       UpdateSampleText(hDlg, OPT_SampleChannel1, \r
1279                        &colorizeAttribs[ColorChannel1]);\r
1280       break;\r
1281 \r
1282     case OPT_ChooseChannelColor:\r
1283       ColorizeTextPopup(hDlg, ColorChannel);\r
1284       UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]);\r
1285       break;\r
1286 \r
1287     case OPT_ChooseKibitzColor:\r
1288       ColorizeTextPopup(hDlg, ColorKibitz);\r
1289       UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]);\r
1290       break;\r
1291 \r
1292     case OPT_ChooseTellColor:\r
1293       ColorizeTextPopup(hDlg, ColorTell);\r
1294       UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]);\r
1295       break;\r
1296 \r
1297     case OPT_ChooseChallengeColor:\r
1298       ColorizeTextPopup(hDlg, ColorChallenge);\r
1299       UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);\r
1300       break;\r
1301 \r
1302     case OPT_ChooseRequestColor:\r
1303       ColorizeTextPopup(hDlg, ColorRequest);\r
1304       UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]);\r
1305       break;\r
1306 \r
1307     case OPT_ChooseSeekColor:\r
1308       ColorizeTextPopup(hDlg, ColorSeek);\r
1309       UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);\r
1310       break;\r
1311 \r
1312     case OPT_ChooseNormalColor:\r
1313       ColorizeTextPopup(hDlg, ColorNormal);\r
1314       UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);\r
1315       break;\r
1316 \r
1317     case OPT_ChooseBackgroundColor:\r
1318       if (ChangeColor(hDlg, &cbc)) {\r
1319         SendDlgItemMessage(hDlg, OPT_SampleShout,     EM_SETBKGNDCOLOR, 0, cbc);\r
1320         SendDlgItemMessage(hDlg, OPT_SampleSShout,    EM_SETBKGNDCOLOR, 0, cbc);\r
1321         SendDlgItemMessage(hDlg, OPT_SampleChannel1,  EM_SETBKGNDCOLOR, 0, cbc);\r
1322         SendDlgItemMessage(hDlg, OPT_SampleChannel,   EM_SETBKGNDCOLOR, 0, cbc);\r
1323         SendDlgItemMessage(hDlg, OPT_SampleKibitz,    EM_SETBKGNDCOLOR, 0, cbc);\r
1324         SendDlgItemMessage(hDlg, OPT_SampleTell,      EM_SETBKGNDCOLOR, 0, cbc);\r
1325         SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);\r
1326         SendDlgItemMessage(hDlg, OPT_SampleRequest,   EM_SETBKGNDCOLOR, 0, cbc);\r
1327         SendDlgItemMessage(hDlg, OPT_SampleSeek,      EM_SETBKGNDCOLOR, 0, cbc);\r
1328         SendDlgItemMessage(hDlg, OPT_SampleNormal,    EM_SETBKGNDCOLOR, 0, cbc);\r
1329       }\r
1330       break;\r
1331 \r
1332     case OPT_DefaultColors:\r
1333       for (i=0; i < NColorClasses - 1; i++)\r
1334         ParseAttribs(&mca[i].color, \r
1335                      &mca[i].effects,\r
1336                      defaultTextAttribs[i]);\r
1337 \r
1338       cbc = ParseColorName(COLOR_BKGD);\r
1339       SendDlgItemMessage(hDlg, OPT_SampleShout,     EM_SETBKGNDCOLOR, 0, cbc);\r
1340       SendDlgItemMessage(hDlg, OPT_SampleSShout,    EM_SETBKGNDCOLOR, 0, cbc);\r
1341       SendDlgItemMessage(hDlg, OPT_SampleChannel1,  EM_SETBKGNDCOLOR, 0, cbc);\r
1342       SendDlgItemMessage(hDlg, OPT_SampleChannel,   EM_SETBKGNDCOLOR, 0, cbc);\r
1343       SendDlgItemMessage(hDlg, OPT_SampleKibitz,    EM_SETBKGNDCOLOR, 0, cbc);\r
1344       SendDlgItemMessage(hDlg, OPT_SampleTell,      EM_SETBKGNDCOLOR, 0, cbc);\r
1345       SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc);\r
1346       SendDlgItemMessage(hDlg, OPT_SampleRequest,   EM_SETBKGNDCOLOR, 0, cbc);\r
1347       SendDlgItemMessage(hDlg, OPT_SampleSeek,      EM_SETBKGNDCOLOR, 0, cbc);\r
1348       SendDlgItemMessage(hDlg, OPT_SampleNormal,    EM_SETBKGNDCOLOR, 0, cbc);\r
1349 \r
1350       UpdateSampleText(hDlg, OPT_SampleShout,     &mca[ColorShout]);\r
1351       UpdateSampleText(hDlg, OPT_SampleSShout,    &mca[ColorSShout]);\r
1352       UpdateSampleText(hDlg, OPT_SampleChannel1,  &mca[ColorChannel1]);\r
1353       UpdateSampleText(hDlg, OPT_SampleChannel,   &mca[ColorChannel]);\r
1354       UpdateSampleText(hDlg, OPT_SampleKibitz,    &mca[ColorKibitz]);\r
1355       UpdateSampleText(hDlg, OPT_SampleTell,      &mca[ColorTell]);\r
1356       UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]);\r
1357       UpdateSampleText(hDlg, OPT_SampleRequest,   &mca[ColorRequest]);\r
1358       UpdateSampleText(hDlg, OPT_SampleSeek,      &mca[ColorSeek]);\r
1359       UpdateSampleText(hDlg, OPT_SampleNormal,    &mca[ColorNormal]);\r
1360       break;\r
1361 \r
1362     default:\r
1363       SetIcsOptionEnables(hDlg);\r
1364       break;\r
1365     }\r
1366     break;\r
1367   }\r
1368   return FALSE;\r
1369 }\r
1370 \r
1371 VOID\r
1372 IcsOptionsPopup(HWND hwnd)\r
1373 {\r
1374   FARPROC lpProc = MakeProcInstance((FARPROC)IcsOptionsDialog, hInst);\r
1375   DialogBox(hInst, MAKEINTRESOURCE(DLG_IcsOptions), hwnd,\r
1376             (DLGPROC) lpProc);\r
1377   FreeProcInstance(lpProc);\r
1378 }\r
1379 \r
1380 /*---------------------------------------------------------------------------*\\r
1381  *\r
1382  * Fonts Dialog functions\r
1383  *\r
1384 \*---------------------------------------------------------------------------*/\r
1385 \r
1386 VOID\r
1387 SetSampleFontText(HWND hwnd, int id, const MyFont *mf)\r
1388 {\r
1389   char buf[MSG_SIZ];\r
1390   HWND hControl;\r
1391   HDC hdc;\r
1392   CHARFORMAT cf;\r
1393   SIZE size;\r
1394   RECT rectClient, rectFormat;\r
1395   HFONT oldFont;\r
1396   POINT center;\r
1397   int len;\r
1398 \r
1399   len = sprintf(buf, "%.0f pt. %s%s%s\n",\r
1400                 mf->mfp.pointSize, mf->mfp.faceName,\r
1401                 mf->mfp.bold ? " bold" : "",\r
1402                 mf->mfp.italic ? " italic" : "");\r
1403   SetDlgItemText(hwnd, id, buf);\r
1404 \r
1405   hControl = GetDlgItem(hwnd, id);\r
1406   hdc = GetDC(hControl);\r
1407   SetMapMode(hdc, MM_TEXT);     /* 1 pixel == 1 logical unit */\r
1408   oldFont = SelectObject(hdc, mf->hf);\r
1409   \r
1410   /* get number of logical units necessary to display font name */\r
1411   GetTextExtentPoint32(hdc, buf, len, &size);\r
1412 \r
1413   /* calculate formatting rectangle in the rich edit control.  \r
1414    * May be larger or smaller than the actual control.\r
1415    */\r
1416   GetClientRect(hControl, &rectClient);\r
1417   center.x = (rectClient.left + rectClient.right) / 2;\r
1418   center.y = (rectClient.top  + rectClient.bottom) / 2;\r
1419   rectFormat.top    = center.y - (size.cy / 2) - 1;\r
1420   rectFormat.bottom = center.y + (size.cy / 2) + 1;\r
1421   rectFormat.left   = center.x - (size.cx / 2) - 1;\r
1422   rectFormat.right  = center.x + (size.cx / 2) + 1;\r
1423 \r
1424 #if 0\r
1425   fprintf(debugFP, "\nfont: %s\n"\r
1426                    "center.x   %d, centerY %d\n"\r
1427                    "size.cx    %d, size.cy %d\n"\r
1428                    "client.top %d, bottom %d, left %d, right %d\n"\r
1429                    "format.top %d, bottom %d, left %d, right %d\n",\r
1430                    buf,\r
1431                    center.x, center.y,\r
1432                    size.cx, size.cy,\r
1433                    rectClient.top, rectClient.bottom, rectClient.left,\r
1434                    rectClient.right,\r
1435                    rectFormat.top, rectFormat.bottom, rectFormat.left,\r
1436                    rectFormat.right);\r
1437 #endif\r
1438 \r
1439   cf.cbSize = sizeof(CHARFORMAT);\r
1440   cf.dwMask = CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_BOLD|CFM_ITALIC;\r
1441   cf.dwEffects = 0;\r
1442   if (mf->lf.lfWeight == FW_BOLD) cf.dwEffects |= CFE_BOLD;\r
1443   if (mf->lf.lfItalic) cf.dwEffects |= CFE_ITALIC;\r
1444   strcpy(cf.szFaceName, mf->mfp.faceName);\r
1445   /*\r
1446    * yHeight is expressed in twips.  A twip is 1/20 of a font's point\r
1447    * size. See documentation of CHARFORMAT.  --msw\r
1448    */\r
1449   cf.yHeight = (int)(mf->mfp.pointSize * 20.0 + 0.5);\r
1450   cf.bCharSet = mf->lf.lfCharSet;\r
1451   cf.bPitchAndFamily = mf->lf.lfPitchAndFamily;\r
1452 \r
1453   /* format the text in the rich edit control */\r
1454   SendMessage(hControl, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf);\r
1455   SendMessage(hControl, EM_SETRECT, (WPARAM)0, (LPARAM) &rectFormat);\r
1456 \r
1457   /* clean up */\r
1458   SelectObject(hdc, oldFont);\r
1459   ReleaseDC(hControl, hdc);\r
1460 }\r
1461 \r
1462 VOID\r
1463 CopyFont(MyFont *dest, const MyFont *src)\r
1464 {\r
1465   dest->mfp.pointSize = src->mfp.pointSize;\r
1466   dest->mfp.bold      = src->mfp.bold;\r
1467   dest->mfp.italic    = src->mfp.italic;\r
1468   dest->mfp.underline = src->mfp.underline;\r
1469   dest->mfp.strikeout = src->mfp.strikeout;\r
1470   lstrcpy(dest->mfp.faceName, src->mfp.faceName);\r
1471   CreateFontInMF(dest);\r
1472 }\r
1473 \r
1474 \r
1475 LRESULT CALLBACK\r
1476 FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
1477 {\r
1478   static MyFont workFont[NUM_FONTS];\r
1479   static BOOL firstPaint;\r
1480   int i;\r
1481   RECT rect;\r
1482 \r
1483   switch (message) {\r
1484   case WM_INITDIALOG:\r
1485 \r
1486     /* copy the current font settings into a working copy */\r
1487     for (i=0; i < NUM_FONTS; i++)\r
1488       CopyFont(&workFont[i], font[boardSize][i]);\r
1489 \r
1490     if (!appData.icsActive)\r
1491       EnableWindow(GetDlgItem(hDlg, OPT_ChooseConsoleFont), FALSE);\r
1492 \r
1493     firstPaint = TRUE;  /* see rant below */\r
1494 \r
1495     /* If I don't call SetFocus(), the dialog won't respond to the keyboard\r
1496      * when first drawn. Why is this the only dialog that behaves this way? Is\r
1497      * is the WM_PAINT stuff below?? Sigh...\r
1498      */\r
1499     SetFocus(GetDlgItem(hDlg, IDOK));\r
1500     break;\r
1501 \r
1502   case WM_PAINT:\r
1503     /* This should not be necessary. However, if SetSampleFontText() is called\r
1504      * in response to WM_INITDIALOG, the strings are not properly centered in\r
1505      * the controls when the dialog first appears. I can't figure out why, so\r
1506      * this is the workaround.  --msw\r
1507      */\r
1508     if (firstPaint) {\r
1509       SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);\r
1510       SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);\r
1511       SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);\r
1512       SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);\r
1513       SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);\r
1514       SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);\r
1515       SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);\r
1516       firstPaint = FALSE;\r
1517     }\r
1518     break;\r
1519 \r
1520   case WM_COMMAND: /* message: received a command */\r
1521     switch (LOWORD(wParam)) {\r
1522 \r
1523     case IDOK:\r
1524       /* again, it seems to avoid redraw problems if we call EndDialog first */\r
1525       EndDialog(hDlg, FALSE);\r
1526 \r
1527       /* copy modified settings back to the fonts array */\r
1528       for (i=0; i < NUM_FONTS; i++)\r
1529         CopyFont(font[boardSize][i], &workFont[i]);\r
1530 \r
1531       /* a sad necessity due to the original design of having a separate\r
1532        * console font, tags font, and comment font for each board size.  IMHO\r
1533        * these fonts should not be dependent on the current board size.  I'm\r
1534        * running out of time, so I am doing this hack rather than redesign the\r
1535        * data structure. Besides, I think if I redesigned the data structure, I\r
1536        * might break backwards compatibility with old winboard.ini files.\r
1537        * --msw\r
1538        */\r
1539       for (i=0; i < NUM_SIZES; i++) {\r
1540         CopyFont(font[i][EDITTAGS_FONT], &workFont[EDITTAGS_FONT]);\r
1541         CopyFont(font[i][CONSOLE_FONT],  &workFont[CONSOLE_FONT]);\r
1542         CopyFont(font[i][COMMENT_FONT],  &workFont[COMMENT_FONT]);\r
1543         CopyFont(font[i][MOVEHISTORY_FONT],  &workFont[MOVEHISTORY_FONT]);\r
1544       }\r
1545       /* end sad necessity */\r
1546 \r
1547       InitDrawingSizes(boardSize, 0);\r
1548       InvalidateRect(hwndMain, NULL, TRUE);\r
1549 \r
1550       if (commentDialog) {\r
1551         SendDlgItemMessage(commentDialog, OPT_CommentText,\r
1552           WM_SETFONT, (WPARAM)font[boardSize][COMMENT_FONT]->hf, \r
1553           MAKELPARAM(TRUE, 0));\r
1554         GetClientRect(GetDlgItem(commentDialog, OPT_CommentText), &rect);\r
1555         InvalidateRect(commentDialog, &rect, TRUE);\r
1556       }\r
1557 \r
1558       if (editTagsDialog) {\r
1559         SendDlgItemMessage(editTagsDialog, OPT_TagsText,\r
1560           WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf, \r
1561           MAKELPARAM(TRUE, 0));\r
1562         GetClientRect(GetDlgItem(editTagsDialog, OPT_TagsText), &rect);\r
1563         InvalidateRect(editTagsDialog, &rect, TRUE);\r
1564       }\r
1565 \r
1566       if( moveHistoryDialog != NULL ) {\r
1567         SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory,\r
1568           WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, \r
1569           MAKELPARAM(TRUE, 0));\r
1570         InvalidateRect(editTagsDialog, NULL, TRUE);\r
1571       }\r
1572 \r
1573       if (hwndConsole) {\r
1574         ChangedConsoleFont();\r
1575       }\r
1576 \r
1577       for (i=0; i<NUM_FONTS; i++)\r
1578         DeleteObject(&workFont[i].hf);\r
1579 \r
1580       return TRUE;\r
1581 \r
1582     case IDCANCEL:\r
1583       for (i=0; i<NUM_FONTS; i++)\r
1584         DeleteObject(&workFont[i].hf);\r
1585       EndDialog(hDlg, FALSE);\r
1586       return TRUE;\r
1587 \r
1588     case OPT_ChooseClockFont:\r
1589       MyCreateFont(hDlg, &workFont[CLOCK_FONT]);\r
1590       SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);\r
1591       break;\r
1592 \r
1593     case OPT_ChooseMessageFont:\r
1594       MyCreateFont(hDlg, &workFont[MESSAGE_FONT]);\r
1595       SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);\r
1596       break;\r
1597 \r
1598     case OPT_ChooseCoordFont:\r
1599       MyCreateFont(hDlg, &workFont[COORD_FONT]);\r
1600       SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);\r
1601       break;\r
1602 \r
1603     case OPT_ChooseTagFont:\r
1604       MyCreateFont(hDlg, &workFont[EDITTAGS_FONT]);\r
1605       SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);\r
1606       break;\r
1607 \r
1608     case OPT_ChooseCommentsFont:\r
1609       MyCreateFont(hDlg, &workFont[COMMENT_FONT]);\r
1610       SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);\r
1611       break;\r
1612 \r
1613     case OPT_ChooseConsoleFont:\r
1614       MyCreateFont(hDlg, &workFont[CONSOLE_FONT]);\r
1615       SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);\r
1616       break;\r
1617 \r
1618     case OPT_ChooseMoveHistoryFont:\r
1619       MyCreateFont(hDlg, &workFont[MOVEHISTORY_FONT]);\r
1620       SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);\r
1621       break;\r
1622 \r
1623     case OPT_DefaultFonts:\r
1624       for (i=0; i<NUM_FONTS; i++) {\r
1625         DeleteObject(&workFont[i].hf);\r
1626         ParseFontName(font[boardSize][i]->def, &workFont[i].mfp);\r
1627         CreateFontInMF(&workFont[i]);\r
1628       }\r
1629       SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]);\r
1630       SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]);\r
1631       SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]);\r
1632       SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);\r
1633       SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);\r
1634       SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);\r
1635       SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);\r
1636       break;\r
1637     }\r
1638   }\r
1639   return FALSE;\r
1640 }\r
1641 \r
1642 VOID\r
1643 FontsOptionsPopup(HWND hwnd)\r
1644 {\r
1645   FARPROC lpProc = MakeProcInstance((FARPROC)FontOptionsDialog, hInst);\r
1646   DialogBox(hInst, MAKEINTRESOURCE(DLG_Fonts), hwnd,\r
1647           (DLGPROC) lpProc);\r
1648   FreeProcInstance(lpProc);\r
1649 }\r
1650 \r
1651 /*---------------------------------------------------------------------------*\\r
1652  *\r
1653  * Sounds Dialog functions\r
1654  *\r
1655 \*---------------------------------------------------------------------------*/\r
1656 \r
1657 \r
1658 SoundComboData soundComboData[] = {\r
1659   {"Move", NULL},\r
1660   {"Bell", NULL},\r
1661   {"ICS Alarm", NULL},\r
1662   {"ICS Win", NULL},\r
1663   {"ICS Loss", NULL},\r
1664   {"ICS Draw", NULL},\r
1665   {"ICS Unfinished", NULL},\r
1666   {"Shout", NULL},\r
1667   {"SShout/CShout", NULL},\r
1668   {"Channel 1", NULL},\r
1669   {"Channel", NULL},\r
1670   {"Kibitz", NULL},\r
1671   {"Tell", NULL},\r
1672   {"Challenge", NULL},\r
1673   {"Request", NULL},\r
1674   {"Seek", NULL},\r
1675   {NULL, NULL},\r
1676 };\r
1677 \r
1678 \r
1679 void\r
1680 InitSoundComboData(SoundComboData *scd)\r
1681 {\r
1682   SoundClass sc;\r
1683   ColorClass cc;\r
1684   int index;\r
1685 \r
1686   /* copy current sound settings to combo array */\r
1687 \r
1688   for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) {\r
1689     scd[sc].name = strdup(sounds[sc].name);\r
1690   }\r
1691   for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) {\r
1692     index = (int)cc + (int)NSoundClasses;\r
1693     scd[index].name = strdup(textAttribs[cc].sound.name);\r
1694   }\r
1695 }\r
1696 \r
1697 \r
1698 void\r
1699 ResetSoundComboData(SoundComboData *scd)\r
1700 {\r
1701   while (scd->label) {\r
1702     if (scd->name != NULL) {\r
1703       free (scd->name);\r
1704       scd->name = NULL;\r
1705     }\r
1706     scd++;\r
1707   }\r
1708 }\r
1709 \r
1710 void\r
1711 InitSoundCombo(HWND hwndCombo, SoundComboData *scd)\r
1712 {\r
1713   char buf[255];\r
1714   DWORD err;\r
1715   DWORD cnt = 0;\r
1716   SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);\r
1717 \r
1718   /* send the labels to the combo box */\r
1719   while (scd->label) {\r
1720     err = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) scd->label);\r
1721     if (err != cnt++) {\r
1722       sprintf(buf, "InitSoundCombo(): err '%d', cnt '%d'\n",\r
1723           err, cnt);\r
1724       MessageBox(NULL, buf, NULL, MB_OK);\r
1725     }\r
1726     scd++;\r
1727   }\r
1728   SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) 0, (LPARAM) 0);\r
1729 }\r
1730 \r
1731 int\r
1732 SoundDialogWhichRadio(HWND hDlg)\r
1733 {\r
1734   if (IsDlgButtonChecked(hDlg, OPT_NoSound)) return OPT_NoSound;\r
1735   if (IsDlgButtonChecked(hDlg, OPT_DefaultBeep)) return OPT_DefaultBeep;\r
1736   if (IsDlgButtonChecked(hDlg, OPT_BuiltInSound)) return OPT_BuiltInSound;\r
1737   if (IsDlgButtonChecked(hDlg, OPT_WavFile)) return OPT_WavFile;\r
1738   return -1;\r
1739 }\r
1740 \r
1741 VOID\r
1742 SoundDialogSetEnables(HWND hDlg, int radio)\r
1743 {\r
1744   EnableWindow(GetDlgItem(hDlg, OPT_BuiltInSoundName),\r
1745                radio == OPT_BuiltInSound);\r
1746   EnableWindow(GetDlgItem(hDlg, OPT_WavFileName), radio == OPT_WavFile);\r
1747   EnableWindow(GetDlgItem(hDlg, OPT_BrowseSound), radio == OPT_WavFile);\r
1748 }\r
1749 \r
1750 char *\r
1751 SoundDialogGetName(HWND hDlg, int radio)\r
1752 {\r
1753   static char buf[MSG_SIZ], buf2[MSG_SIZ], buf3[MSG_SIZ];\r
1754   char *dummy, *ret;\r
1755   switch (radio) {\r
1756   case OPT_NoSound:\r
1757   default:\r
1758     return "";\r
1759   case OPT_DefaultBeep:\r
1760     return "$";\r
1761   case OPT_BuiltInSound:\r
1762     buf[0] = '!';\r
1763     GetDlgItemText(hDlg, OPT_BuiltInSoundName, buf + 1, sizeof(buf) - 1);\r
1764     return buf;\r
1765   case OPT_WavFile:\r
1766     GetDlgItemText(hDlg, OPT_WavFileName, buf, sizeof(buf));\r
1767     GetCurrentDirectory(MSG_SIZ, buf3);\r
1768     SetCurrentDirectory(installDir);\r
1769     if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {\r
1770       ret = buf2;\r
1771     } else {\r
1772       ret = buf;\r
1773     }\r
1774     SetCurrentDirectory(buf3);\r
1775     return ret;\r
1776   }\r
1777 }\r
1778 \r
1779 void\r
1780 DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name)\r
1781 {\r
1782   int radio;\r
1783   /* \r
1784    * I think it's best to clear the combo and edit boxes. It looks stupid\r
1785    * to have a value from another sound event sitting there grayed out.\r
1786    */\r
1787   SetDlgItemText(hDlg, OPT_WavFileName, "");\r
1788   SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);\r
1789 \r
1790   if (appData.debugMode)\r
1791       fprintf(debugFP, "DisplaySelectedSound(,,'%s'):\n", name);\r
1792   switch (name[0]) {\r
1793   case NULLCHAR:\r
1794     radio = OPT_NoSound;\r
1795     break;\r
1796   case '$':\r
1797     if (name[1] == NULLCHAR) {\r
1798       radio = OPT_DefaultBeep;\r
1799     } else {\r
1800       radio = OPT_WavFile;\r
1801       SetDlgItemText(hDlg, OPT_WavFileName, name);\r
1802     }\r
1803     break;\r
1804   case '!':\r
1805     if (name[1] == NULLCHAR) {\r
1806       radio = OPT_NoSound;\r
1807     } else {\r
1808       radio = OPT_BuiltInSound;\r
1809       if (SendMessage(hCombo, CB_SELECTSTRING, (WPARAM) -1, \r
1810                       (LPARAM) (name + 1)) == CB_ERR) {\r
1811         SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);\r
1812         SendMessage(hCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) (name + 1));\r
1813       }\r
1814     }\r
1815     break;\r
1816   default:\r
1817     radio = OPT_WavFile;\r
1818     SetDlgItemText(hDlg, OPT_WavFileName, name);\r
1819     break;\r
1820   }\r
1821   SoundDialogSetEnables(hDlg, radio);\r
1822   CheckRadioButton(hDlg, OPT_NoSound, OPT_WavFile, radio);\r
1823 }\r
1824     \r
1825 \r
1826 char *builtInSoundNames[] = BUILT_IN_SOUND_NAMES;\r
1827 \r
1828 LRESULT CALLBACK\r
1829 SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
1830 {\r
1831   static HWND hSoundCombo;\r
1832   static DWORD index;\r
1833   static HWND hBISN;\r
1834   int radio;\r
1835   MySound tmp;\r
1836   FILE *f;\r
1837   char buf[MSG_SIZ];\r
1838   char *newName;\r
1839   SoundClass sc;\r
1840   ColorClass cc;\r
1841   SoundComboData *scd;\r
1842 \r
1843   switch (message) {\r
1844   case WM_INITDIALOG:\r
1845     /* Center the dialog over the application window */\r
1846     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
1847 \r
1848     /* Initialize the built-in sounds combo */\r
1849     hBISN = GetDlgItem(hDlg, OPT_BuiltInSoundName);\r
1850      InitComboStrings(hBISN, builtInSoundNames);\r
1851 \r
1852     /* Initialize the  sound events combo */\r
1853     index = 0;\r
1854     InitSoundComboData(soundComboData);\r
1855     hSoundCombo = GetDlgItem(hDlg, CBO_Sounds);\r
1856     InitSoundCombo(hSoundCombo, soundComboData);\r
1857 \r
1858     /* update the dialog */\r
1859     DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);\r
1860     return TRUE;\r
1861 \r
1862   case WM_COMMAND: /* message: received a command */\r
1863 \r
1864     if (((HWND)lParam == hSoundCombo) && \r
1865         (HIWORD(wParam) == CBN_SELCHANGE)) {\r
1866       /* \r
1867        * the user has selected a new sound event. We must store the name for\r
1868        * the previously selected event, then retrieve the name for the\r
1869        * newly selected event and update the dialog. \r
1870        */\r
1871       radio = SoundDialogWhichRadio(hDlg);\r
1872       newName = strdup(SoundDialogGetName(hDlg, radio));\r
1873       \r
1874       if (strcmp(newName, soundComboData[index].name) != 0) {\r
1875         free(soundComboData[index].name);\r
1876         soundComboData[index].name = newName;\r
1877       } else {\r
1878         free(newName);\r
1879         newName = NULL;\r
1880       }\r
1881       /* now get the settings for the newly selected event */\r
1882       index = SendMessage(hSoundCombo, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);\r
1883       DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);\r
1884       \r
1885       return TRUE;\r
1886     }\r
1887     switch (LOWORD(wParam)) {\r
1888     case IDOK:\r
1889       /* \r
1890        * save the name for the currently selected sound event \r
1891        */\r
1892       radio = SoundDialogWhichRadio(hDlg);\r
1893       newName = strdup(SoundDialogGetName(hDlg, radio));\r
1894 \r
1895       if (strcmp(soundComboData[index].name, newName) != 0) {\r
1896         free(soundComboData[index].name);\r
1897         soundComboData[index].name = newName;\r
1898       } else {\r
1899         free(newName);\r
1900         newName = NULL;\r
1901       }\r
1902 \r
1903       /* save all the sound names that changed and load the sounds */\r
1904 \r
1905       for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) {\r
1906         if (strcmp(soundComboData[sc].name, sounds[sc].name) != 0) {\r
1907           free(sounds[sc].name);\r
1908           sounds[sc].name = strdup(soundComboData[sc].name);\r
1909           MyLoadSound(&sounds[sc]);\r
1910         }\r
1911       }\r
1912       for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) {\r
1913         index = (int)cc + (int)NSoundClasses;\r
1914         if (strcmp(soundComboData[index].name, \r
1915                    textAttribs[cc].sound.name) != 0) {\r
1916           free(textAttribs[cc].sound.name);\r
1917           textAttribs[cc].sound.name = strdup(soundComboData[index].name);\r
1918           MyLoadSound(&textAttribs[cc].sound);\r
1919         }\r
1920       }\r
1921 \r
1922       ResetSoundComboData(soundComboData);\r
1923       EndDialog(hDlg, TRUE);\r
1924       return TRUE;\r
1925 \r
1926     case IDCANCEL:\r
1927       ResetSoundComboData(soundComboData);\r
1928       EndDialog(hDlg, FALSE);\r
1929       return TRUE;\r
1930 \r
1931     case OPT_DefaultSounds:\r
1932       /* can't use SetDefaultSounds() because we need to be able to "undo" if\r
1933        * user selects "Cancel" later on. So we do it the hard way here.\r
1934        */\r
1935       scd = &soundComboData[0];\r
1936       while (scd->label != NULL) {\r
1937         if (scd->name != NULL) free(scd->name);\r
1938         scd->name = strdup("");\r
1939         scd++;\r
1940       }\r
1941       free(soundComboData[(int)SoundBell].name);\r
1942       soundComboData[(int)SoundBell].name = strdup(SOUND_BELL);\r
1943       DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);\r
1944       break;\r
1945 \r
1946     case OPT_PlaySound:\r
1947       radio = SoundDialogWhichRadio(hDlg);\r
1948       tmp.name = strdup(SoundDialogGetName(hDlg, radio));\r
1949       tmp.data = NULL;\r
1950       MyLoadSound(&tmp);\r
1951       MyPlaySound(&tmp);\r
1952       if (tmp.data  != NULL) free(tmp.data);\r
1953       if (tmp.name != NULL) free(tmp.name);\r
1954       return TRUE;\r
1955 \r
1956     case OPT_BrowseSound:\r
1957       f = OpenFileDialog(hDlg, FALSE, NULL, "wav", SOUND_FILT,\r
1958         "Browse for Sound File", NULL, NULL, buf);\r
1959       if (f != NULL) {\r
1960         fclose(f);\r
1961         SetDlgItemText(hDlg, OPT_WavFileName, buf);\r
1962       }\r
1963       return TRUE;\r
1964 \r
1965     default:\r
1966       radio = SoundDialogWhichRadio(hDlg);\r
1967       SoundDialogSetEnables(hDlg, radio);\r
1968       break;\r
1969     }\r
1970     break;\r
1971   }\r
1972   return FALSE;\r
1973 }\r
1974 \r
1975 \r
1976 VOID SoundOptionsPopup(HWND hwnd)\r
1977 {\r
1978   FARPROC lpProc;\r
1979 \r
1980   lpProc = MakeProcInstance((FARPROC)SoundOptionsDialog, hInst);\r
1981   DialogBox(hInst, MAKEINTRESOURCE(DLG_Sound), hwnd, (DLGPROC)lpProc);\r
1982   FreeProcInstance(lpProc);\r
1983 }\r
1984 \r
1985 \r
1986 /*---------------------------------------------------------------------------*\\r
1987  *\r
1988  * Comm Port dialog functions\r
1989  *\r
1990 \*---------------------------------------------------------------------------*/\r
1991 \r
1992 \r
1993 #define FLOW_NONE   0\r
1994 #define FLOW_XOFF   1\r
1995 #define FLOW_CTS    2\r
1996 #define FLOW_DSR    3\r
1997 \r
1998 #define PORT_NONE\r
1999 \r
2000 ComboData cdPort[]     = { {"None", PORT_NONE}, {"COM1", 1}, {"COM2", 2},\r
2001                            {"COM3", 3}, {"COM4", 4}, {NULL, 0} };\r
2002 ComboData cdDataRate[] = { {"110", 110}, {"300", 300}, {"600", 600}, {"1200", 1200},\r
2003                            {"2400", 2400}, {"4800", 4800}, {"9600", 9600}, {"19200", 19200},\r
2004                            {"38400", 38400}, {NULL, 0} };\r
2005 ComboData cdDataBits[] = { {"5", 5}, {"6", 6}, {"7", 7}, {"8", 8}, {NULL, 0} };\r
2006 ComboData cdParity[]   = { {"None", NOPARITY}, {"Odd", ODDPARITY}, {"Even", EVENPARITY},\r
2007                            {"Mark", MARKPARITY}, {"Space", SPACEPARITY}, {NULL, 0} };\r
2008 ComboData cdStopBits[] = { {"1", ONESTOPBIT}, {"1.5", ONE5STOPBITS},\r
2009                            {"2", TWOSTOPBITS}, {NULL, 0} };\r
2010 ComboData cdFlow[]     = { {"None", FLOW_NONE}, {"Xoff/Xon", FLOW_XOFF}, {"CTS", FLOW_CTS},\r
2011                            {"DSR", FLOW_DSR}, {NULL, 0} };\r
2012 \r
2013 \r
2014 VOID\r
2015 ParseCommSettings(char *arg, DCB *dcb)\r
2016 {\r
2017   int dataRate, count;\r
2018   char bits[MSG_SIZ], parity[MSG_SIZ], stopBits[MSG_SIZ], flow[MSG_SIZ];\r
2019   ComboData *cd;\r
2020   count = sscanf(arg, "%d%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]",\r
2021     &dataRate, bits, parity, stopBits, flow);\r
2022   if (count != 5) goto cant_parse;\r
2023   dcb->BaudRate = dataRate;\r
2024   cd = cdDataBits;\r
2025   while (cd->label != NULL) {\r
2026     if (StrCaseCmp(cd->label, bits) == 0) {\r
2027       dcb->ByteSize = cd->value;\r
2028       break;\r
2029     }\r
2030     cd++;\r
2031   }\r
2032   if (cd->label == NULL) goto cant_parse;\r
2033   cd = cdParity;\r
2034   while (cd->label != NULL) {\r
2035     if (StrCaseCmp(cd->label, parity) == 0) {\r
2036       dcb->Parity = cd->value;\r
2037       break;\r
2038     }\r
2039     cd++;\r
2040   }\r
2041   if (cd->label == NULL) goto cant_parse;\r
2042   cd = cdStopBits;\r
2043   while (cd->label != NULL) {\r
2044     if (StrCaseCmp(cd->label, stopBits) == 0) {\r
2045       dcb->StopBits = cd->value;\r
2046       break;\r
2047     }\r
2048     cd++;\r
2049   }\r
2050   cd = cdFlow;\r
2051   if (cd->label == NULL) goto cant_parse;\r
2052   while (cd->label != NULL) {\r
2053     if (StrCaseCmp(cd->label, flow) == 0) {\r
2054       switch (cd->value) {\r
2055       case FLOW_NONE:\r
2056         dcb->fOutX = FALSE;\r
2057         dcb->fOutxCtsFlow = FALSE;\r
2058         dcb->fOutxDsrFlow = FALSE;\r
2059         break;\r
2060       case FLOW_CTS:\r
2061         dcb->fOutX = FALSE;\r
2062         dcb->fOutxCtsFlow = TRUE;\r
2063         dcb->fOutxDsrFlow = FALSE;\r
2064         break;\r
2065       case FLOW_DSR:\r
2066         dcb->fOutX = FALSE;\r
2067         dcb->fOutxCtsFlow = FALSE;\r
2068         dcb->fOutxDsrFlow = TRUE;\r
2069         break;\r
2070       case FLOW_XOFF:\r
2071         dcb->fOutX = TRUE;\r
2072         dcb->fOutxCtsFlow = FALSE;\r
2073         dcb->fOutxDsrFlow = FALSE;\r
2074         break;\r
2075       }\r
2076       break;\r
2077     }\r
2078     cd++;\r
2079   }\r
2080   if (cd->label == NULL) goto cant_parse;\r
2081   return;\r
2082 cant_parse:\r
2083     ExitArgError("Can't parse com port settings", arg);\r
2084 }\r
2085 \r
2086 \r
2087 VOID PrintCommSettings(FILE *f, char *name, DCB *dcb)\r
2088 {\r
2089   char *flow = "??", *parity = "??", *stopBits = "??";\r
2090   ComboData *cd;\r
2091   \r
2092   cd = cdParity;\r
2093   while (cd->label != NULL) {\r
2094     if (dcb->Parity == cd->value) {\r
2095       parity = cd->label;\r
2096       break;\r
2097     }\r
2098     cd++;\r
2099   }\r
2100   cd = cdStopBits;\r
2101   while (cd->label != NULL) {\r
2102     if (dcb->StopBits == cd->value) {\r
2103       stopBits = cd->label;\r
2104       break;\r
2105     }\r
2106     cd++;\r
2107   }\r
2108   if (dcb->fOutX) {\r
2109     flow = cdFlow[FLOW_XOFF].label;\r
2110   } else if (dcb->fOutxCtsFlow) {\r
2111     flow = cdFlow[FLOW_CTS].label;\r
2112   } else if (dcb->fOutxDsrFlow) {\r
2113     flow = cdFlow[FLOW_DSR].label;\r
2114   } else {\r
2115     flow = cdFlow[FLOW_NONE].label;\r
2116   }\r
2117   fprintf(f, "/%s=%d,%d,%s,%s,%s\n", name,\r
2118     dcb->BaudRate, dcb->ByteSize, parity, stopBits, flow);\r
2119 }\r
2120 \r
2121 \r
2122 void\r
2123 InitCombo(HANDLE hwndCombo, ComboData *cd)\r
2124 {\r
2125   SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);\r
2126 \r
2127   while (cd->label != NULL) {\r
2128     SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) cd->label);\r
2129     cd++;\r
2130   }\r
2131 }\r
2132 \r
2133 void\r
2134 SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value)\r
2135 {\r
2136   int i;\r
2137 \r
2138   i = 0;\r
2139   while (cd->label != NULL) {\r
2140     if (cd->value == value) {\r
2141       SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) i, (LPARAM) 0);\r
2142       return;\r
2143     }\r
2144     cd++;\r
2145     i++;\r
2146   }\r
2147 }\r
2148 \r
2149 LRESULT CALLBACK\r
2150 CommPortOptionsDialog(HWND hDlg, UINT message, WPARAM wParam,   LPARAM lParam)\r
2151 {\r
2152   char buf[MSG_SIZ];\r
2153   HANDLE hwndCombo;\r
2154   char *p;\r
2155   LRESULT index;\r
2156   unsigned value;\r
2157   int err;\r
2158 \r
2159   switch (message) {\r
2160   case WM_INITDIALOG: /* message: initialize dialog box */\r
2161     /* Center the dialog over the application window */\r
2162     CenterWindow (hDlg, GetWindow(hDlg, GW_OWNER));\r
2163     /* Initialize the dialog items */\r
2164     /* !! There should probably be some synchronization\r
2165        in accessing hCommPort and dcb.  Or does modal nature\r
2166        of this dialog box do it for us?\r
2167        */\r
2168     hwndCombo = GetDlgItem(hDlg, OPT_Port);\r
2169     InitCombo(hwndCombo, cdPort);\r
2170     p = strrchr(appData.icsCommPort, '\\');\r
2171     if (p++ == NULL) p = appData.icsCommPort;\r
2172     if ((*p == '\0') ||\r
2173         (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) p) == CB_ERR)) {\r
2174       SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) "None");\r
2175     }\r
2176     EnableWindow(hwndCombo, hCommPort == NULL); /*!! don't allow change for now*/\r
2177 \r
2178     hwndCombo = GetDlgItem(hDlg, OPT_DataRate);\r
2179     InitCombo(hwndCombo, cdDataRate);\r
2180     sprintf(buf, "%u", dcb.BaudRate);\r
2181     if (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) buf) == CB_ERR) {\r
2182       SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);\r
2183       SendMessage(hwndCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) buf);\r
2184     }\r
2185 \r
2186     hwndCombo = GetDlgItem(hDlg, OPT_Bits);\r
2187     InitCombo(hwndCombo, cdDataBits);\r
2188     SelectComboValue(hwndCombo, cdDataBits, dcb.ByteSize);\r
2189 \r
2190     hwndCombo = GetDlgItem(hDlg, OPT_Parity);\r
2191     InitCombo(hwndCombo, cdParity);\r
2192     SelectComboValue(hwndCombo, cdParity, dcb.Parity);\r
2193 \r
2194     hwndCombo = GetDlgItem(hDlg, OPT_StopBits);\r
2195     InitCombo(hwndCombo, cdStopBits);\r
2196     SelectComboValue(hwndCombo, cdStopBits, dcb.StopBits);\r
2197 \r
2198     hwndCombo = GetDlgItem(hDlg, OPT_Flow);\r
2199     InitCombo(hwndCombo, cdFlow);\r
2200     if (dcb.fOutX) {\r
2201       SelectComboValue(hwndCombo, cdFlow, FLOW_XOFF);\r
2202     } else if (dcb.fOutxCtsFlow) {\r
2203       SelectComboValue(hwndCombo, cdFlow, FLOW_CTS);\r
2204     } else if (dcb.fOutxDsrFlow) {\r
2205       SelectComboValue(hwndCombo, cdFlow, FLOW_DSR);\r
2206     } else {\r
2207       SelectComboValue(hwndCombo, cdFlow, FLOW_NONE);\r
2208     }\r
2209     return TRUE;\r
2210 \r
2211   case WM_COMMAND: /* message: received a command */\r
2212     switch (LOWORD(wParam)) {\r
2213     case IDOK:\r
2214       /* Read changed options from the dialog box */\r
2215 #ifdef NOTDEF\r
2216       /* !! Currently we can't change comm ports in midstream */\r
2217       hwndCombo = GetDlgItem(hDlg, OPT_Port);\r
2218       index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);\r
2219       if (index == PORT_NONE) {\r
2220         appData.icsCommPort = "";\r
2221         if (hCommPort != NULL) {\r
2222           CloseHandle(hCommPort);\r
2223           hCommPort = NULL;\r
2224         }\r
2225         EndDialog(hDlg, TRUE);\r
2226         return TRUE;\r
2227       }\r
2228       SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf);\r
2229       appData.icsCommPort = strdup(buf);\r
2230       if (hCommPort != NULL) {\r
2231         CloseHandle(hCommPort);\r
2232         hCommPort = NULL;\r
2233       }\r
2234       /* now what?? can't really do this; have to fix up the ChildProc\r
2235          and InputSource records for the comm port that we gave to the\r
2236          back end. */\r
2237 #endif /*NOTDEF*/\r
2238 \r
2239       hwndCombo = GetDlgItem(hDlg, OPT_DataRate);\r
2240       SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf);\r
2241       if (sscanf(buf, "%u", &value) != 1) {\r
2242         MessageBox(hDlg, "Invalid data rate",\r
2243                    "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
2244         return TRUE;\r
2245       }\r
2246       dcb.BaudRate = value;\r
2247 \r
2248       hwndCombo = GetDlgItem(hDlg, OPT_Bits);\r
2249       index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);\r
2250       dcb.ByteSize = cdDataBits[index].value;\r
2251 \r
2252       hwndCombo = GetDlgItem(hDlg, OPT_Parity);\r
2253       index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);\r
2254       dcb.Parity = cdParity[index].value;\r
2255 \r
2256       hwndCombo = GetDlgItem(hDlg, OPT_StopBits);\r
2257       index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);\r
2258       dcb.StopBits = cdStopBits[index].value;\r
2259 \r
2260       hwndCombo = GetDlgItem(hDlg, OPT_Flow);\r
2261       index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);\r
2262       switch (cdFlow[index].value) {\r
2263       case FLOW_NONE:\r
2264         dcb.fOutX = FALSE;\r
2265         dcb.fOutxCtsFlow = FALSE;\r
2266         dcb.fOutxDsrFlow = FALSE;\r
2267         break;\r
2268       case FLOW_CTS:\r
2269         dcb.fOutX = FALSE;\r
2270         dcb.fOutxCtsFlow = TRUE;\r
2271         dcb.fOutxDsrFlow = FALSE;\r
2272         break;\r
2273       case FLOW_DSR:\r
2274         dcb.fOutX = FALSE;\r
2275         dcb.fOutxCtsFlow = FALSE;\r
2276         dcb.fOutxDsrFlow = TRUE;\r
2277         break;\r
2278       case FLOW_XOFF:\r
2279         dcb.fOutX = TRUE;\r
2280         dcb.fOutxCtsFlow = FALSE;\r
2281         dcb.fOutxDsrFlow = FALSE;\r
2282         break;\r
2283       }\r
2284       if (!SetCommState(hCommPort, (LPDCB) &dcb)) {\r
2285         err = GetLastError();\r
2286         switch(MessageBox(hDlg, \r
2287                          "Failed to set comm port state;\r\ninvalid options?",\r
2288                          "Option Error", MB_ABORTRETRYIGNORE|MB_ICONQUESTION)) {\r
2289         case IDABORT:\r
2290           DisplayFatalError("Failed to set comm port state", err, 1);\r
2291           exit(1);  /*is it ok to do this from here?*/\r
2292 \r
2293         case IDRETRY:\r
2294           return TRUE;\r
2295 \r
2296         case IDIGNORE:\r
2297           EndDialog(hDlg, TRUE);\r
2298           return TRUE;\r
2299         }\r
2300       }\r
2301 \r
2302       EndDialog(hDlg, TRUE);\r
2303       return TRUE;\r
2304 \r
2305     case IDCANCEL:\r
2306       EndDialog(hDlg, FALSE);\r
2307       return TRUE;\r
2308 \r
2309     default:\r
2310       break;\r
2311     }\r
2312     break;\r
2313   }\r
2314   return FALSE;\r
2315 }\r
2316 \r
2317 VOID\r
2318 CommPortOptionsPopup(HWND hwnd)\r
2319 {\r
2320   FARPROC lpProc = MakeProcInstance((FARPROC)CommPortOptionsDialog, hInst);\r
2321   DialogBox(hInst, MAKEINTRESOURCE(DLG_CommPort), hwnd, (DLGPROC) lpProc);\r
2322   FreeProcInstance(lpProc);\r
2323 }\r
2324 \r
2325 /*---------------------------------------------------------------------------*\\r
2326  *\r
2327  * Load Options dialog functions\r
2328  *\r
2329 \*---------------------------------------------------------------------------*/\r
2330 \r
2331 VOID\r
2332 SetLoadOptionEnables(HWND hDlg)\r
2333 {\r
2334   UINT state;\r
2335 \r
2336   state = IsDlgButtonChecked(hDlg, OPT_Autostep);\r
2337   EnableWindow(GetDlgItem(hDlg, OPT_ASTimeDelay), state);\r
2338   EnableWindow(GetDlgItem(hDlg, OPT_AStext1), state);\r
2339 }\r
2340 \r
2341 LRESULT CALLBACK\r
2342 LoadOptions(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
2343 {\r
2344   char buf[MSG_SIZ];\r
2345   float fnumber;\r
2346 \r
2347   switch (message) {\r
2348   case WM_INITDIALOG: /* message: initialize dialog box */\r
2349     /* Center the dialog over the application window */\r
2350     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
2351     /* Initialize the dialog items */\r
2352     if (appData.timeDelay >= 0.0) {\r
2353       CheckDlgButton(hDlg, OPT_Autostep, TRUE);\r
2354       sprintf(buf, "%.2g", appData.timeDelay);\r
2355       SetDlgItemText(hDlg, OPT_ASTimeDelay, buf);\r
2356     } else {\r
2357       CheckDlgButton(hDlg, OPT_Autostep, FALSE);\r
2358     }\r
2359     SetLoadOptionEnables(hDlg);\r
2360     return TRUE;\r
2361 \r
2362   case WM_COMMAND: /* message: received a command */\r
2363     switch (LOWORD(wParam)) {\r
2364     case IDOK:\r
2365       /* Read changed options from the dialog box */\r
2366       if (IsDlgButtonChecked(hDlg, OPT_Autostep)) {\r
2367         GetDlgItemText(hDlg, OPT_ASTimeDelay, buf, MSG_SIZ);\r
2368         if (sscanf(buf, "%f", &fnumber) != 1) {\r
2369           MessageBox(hDlg, "Invalid load game step rate",\r
2370                      "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
2371           return FALSE;\r
2372         }\r
2373         appData.timeDelay = fnumber;\r
2374       } else {\r
2375         appData.timeDelay = (float) -1.0;\r
2376       }\r
2377       EndDialog(hDlg, TRUE);\r
2378       return TRUE;\r
2379 \r
2380     case IDCANCEL:\r
2381       EndDialog(hDlg, FALSE);\r
2382       return TRUE;\r
2383 \r
2384     default:\r
2385       SetLoadOptionEnables(hDlg);\r
2386       break;\r
2387     }\r
2388     break;\r
2389   }\r
2390   return FALSE;\r
2391 }\r
2392 \r
2393 \r
2394 VOID \r
2395 LoadOptionsPopup(HWND hwnd)\r
2396 {\r
2397   FARPROC lpProc = MakeProcInstance((FARPROC)LoadOptions, hInst);\r
2398   DialogBox(hInst, MAKEINTRESOURCE(DLG_LoadOptions), hwnd, (DLGPROC) lpProc);\r
2399   FreeProcInstance(lpProc);\r
2400 }\r
2401 \r
2402 /*---------------------------------------------------------------------------*\\r
2403  *\r
2404  * Save Options dialog functions\r
2405  *\r
2406 \*---------------------------------------------------------------------------*/\r
2407 \r
2408 VOID\r
2409 SetSaveOptionEnables(HWND hDlg)\r
2410 {\r
2411   UINT state;\r
2412 \r
2413   state = IsDlgButtonChecked(hDlg, OPT_Autosave);\r
2414   EnableWindow(GetDlgItem(hDlg, OPT_AVPrompt), state);\r
2415   EnableWindow(GetDlgItem(hDlg, OPT_AVToFile), state);\r
2416   if (state && !IsDlgButtonChecked(hDlg, OPT_AVPrompt) &&\r
2417       !IsDlgButtonChecked(hDlg, OPT_AVToFile)) {\r
2418     CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt);\r
2419   }\r
2420 \r
2421   state = state && IsDlgButtonChecked(hDlg, OPT_AVToFile);\r
2422   EnableWindow(GetDlgItem(hDlg, OPT_AVFilename), state);\r
2423   EnableWindow(GetDlgItem(hDlg, OPT_AVBrowse), state);\r
2424 }\r
2425 \r
2426 LRESULT CALLBACK\r
2427 SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
2428 {\r
2429   char buf[MSG_SIZ];\r
2430   FILE *f;\r
2431 \r
2432   switch (message) {\r
2433   case WM_INITDIALOG: /* message: initialize dialog box */\r
2434     /* Center the dialog over the application window */\r
2435     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
2436     /* Initialize the dialog items */\r
2437     if (*appData.saveGameFile != NULLCHAR) {\r
2438       CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE);\r
2439       CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVToFile);\r
2440       SetDlgItemText(hDlg, OPT_AVFilename, appData.saveGameFile);\r
2441     } else if (appData.autoSaveGames) {\r
2442       CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE);\r
2443       CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt);\r
2444     } else {\r
2445       CheckDlgButton(hDlg, OPT_Autosave, (UINT) FALSE);\r
2446     }\r
2447     if (appData.oldSaveStyle) {\r
2448       CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_Old);\r
2449     } else {\r
2450       CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_PGN);\r
2451     }\r
2452     CheckDlgButton( hDlg, OPT_OutOfBookInfo, appData.saveOutOfBookInfo );\r
2453     SetSaveOptionEnables(hDlg);\r
2454     return TRUE;\r
2455 \r
2456   case WM_COMMAND: /* message: received a command */\r
2457     switch (LOWORD(wParam)) {\r
2458     case IDOK:\r
2459       /* Read changed options from the dialog box */\r
2460       if (IsDlgButtonChecked(hDlg, OPT_Autosave)) {\r
2461         appData.autoSaveGames = TRUE;\r
2462         if (IsDlgButtonChecked(hDlg, OPT_AVPrompt)) {\r
2463           appData.saveGameFile = "";\r
2464         } else /*if (IsDlgButtonChecked(hDlg, OPT_AVToFile))*/ {\r
2465           GetDlgItemText(hDlg, OPT_AVFilename, buf, MSG_SIZ);\r
2466           if (*buf == NULLCHAR) {\r
2467             MessageBox(hDlg, "Invalid save game file name",\r
2468                        "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
2469             return FALSE;\r
2470           }\r
2471           if ((isalpha(buf[0]) && buf[1] == ':') ||\r
2472             (buf[0] == '\\' && buf[1] == '\\')) {\r
2473             appData.saveGameFile = strdup(buf);\r
2474           } else {\r
2475             char buf2[MSG_SIZ], buf3[MSG_SIZ];\r
2476             char *dummy;\r
2477             GetCurrentDirectory(MSG_SIZ, buf3);\r
2478             SetCurrentDirectory(installDir);\r
2479             if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {\r
2480               appData.saveGameFile = strdup(buf2);\r
2481             } else {\r
2482               appData.saveGameFile = strdup(buf);\r
2483             }\r
2484             SetCurrentDirectory(buf3);\r
2485           }\r
2486         }\r
2487       } else {\r
2488         appData.autoSaveGames = FALSE;\r
2489         appData.saveGameFile = "";\r
2490       }\r
2491       appData.oldSaveStyle = IsDlgButtonChecked(hDlg, OPT_Old);\r
2492       appData.saveOutOfBookInfo = IsDlgButtonChecked( hDlg, OPT_OutOfBookInfo );\r
2493       EndDialog(hDlg, TRUE);\r
2494       return TRUE;\r
2495 \r
2496     case IDCANCEL:\r
2497       EndDialog(hDlg, FALSE);\r
2498       return TRUE;\r
2499 \r
2500     case OPT_AVBrowse:\r
2501       f = OpenFileDialog(hDlg, TRUE, NULL, \r
2502                          appData.oldSaveStyle ? "gam" : "pgn", \r
2503                          GAME_FILT, "Browse for Auto Save File", \r
2504                          NULL, NULL, buf);\r
2505       if (f != NULL) {\r
2506         fclose(f);\r
2507         SetDlgItemText(hDlg, OPT_AVFilename, buf);\r
2508       }\r
2509       break;\r
2510 \r
2511     default:\r
2512       SetSaveOptionEnables(hDlg);\r
2513       break;\r
2514     }\r
2515     break;\r
2516   }\r
2517   return FALSE;\r
2518 }\r
2519 \r
2520 VOID\r
2521 SaveOptionsPopup(HWND hwnd)\r
2522 {\r
2523   FARPROC lpProc = MakeProcInstance((FARPROC)SaveOptionsDialog, hInst);\r
2524   DialogBox(hInst, MAKEINTRESOURCE(DLG_SaveOptions), hwnd, (DLGPROC) lpProc);\r
2525   FreeProcInstance(lpProc);\r
2526 }\r
2527 \r
2528 /*---------------------------------------------------------------------------*\\r
2529  *\r
2530  * Time Control Options dialog functions\r
2531  *\r
2532 \*---------------------------------------------------------------------------*/\r
2533 \r
2534 VOID\r
2535 SetTimeControlEnables(HWND hDlg)\r
2536 {\r
2537   UINT state;\r
2538 \r
2539   state = IsDlgButtonChecked(hDlg, OPT_TCUseMoves);\r
2540   EnableWindow(GetDlgItem(hDlg, OPT_TCTime), state);\r
2541   EnableWindow(GetDlgItem(hDlg, OPT_TCMoves), state);\r
2542   EnableWindow(GetDlgItem(hDlg, OPT_TCtext1), state);\r
2543   EnableWindow(GetDlgItem(hDlg, OPT_TCtext2), state);\r
2544   EnableWindow(GetDlgItem(hDlg, OPT_TCTime2), !state);\r
2545   EnableWindow(GetDlgItem(hDlg, OPT_TCInc), !state);\r
2546   EnableWindow(GetDlgItem(hDlg, OPT_TCitext1), !state);\r
2547   EnableWindow(GetDlgItem(hDlg, OPT_TCitext2), !state);\r
2548   EnableWindow(GetDlgItem(hDlg, OPT_TCitext3), !state);\r
2549 }\r
2550 \r
2551 \r
2552 LRESULT CALLBACK\r
2553 TimeControl(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
2554 {\r
2555   char buf[MSG_SIZ];\r
2556   int mps, increment;\r
2557   BOOL ok;\r
2558 \r
2559   switch (message) {\r
2560   case WM_INITDIALOG: /* message: initialize dialog box */\r
2561     /* Center the dialog over the application window */\r
2562     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
2563     /* Initialize the dialog items */\r
2564     if (appData.clockMode && !appData.icsActive) {\r
2565       if (appData.timeIncrement == -1) {\r
2566         CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,\r
2567                          OPT_TCUseMoves);\r
2568         SetDlgItemText(hDlg, OPT_TCTime, appData.timeControl);\r
2569         SetDlgItemInt(hDlg, OPT_TCMoves, appData.movesPerSession,\r
2570                       FALSE);\r
2571         SetDlgItemText(hDlg, OPT_TCTime2, "");\r
2572         SetDlgItemText(hDlg, OPT_TCInc, "");\r
2573       } else {\r
2574         CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,\r
2575                          OPT_TCUseInc);\r
2576         SetDlgItemText(hDlg, OPT_TCTime, "");\r
2577         SetDlgItemText(hDlg, OPT_TCMoves, "");\r
2578         SetDlgItemText(hDlg, OPT_TCTime2, appData.timeControl);\r
2579         SetDlgItemInt(hDlg, OPT_TCInc, appData.timeIncrement, FALSE);\r
2580       }\r
2581       SetTimeControlEnables(hDlg);\r
2582     }\r
2583     return TRUE;\r
2584 \r
2585   case WM_COMMAND: /* message: received a command */\r
2586     switch (LOWORD(wParam)) {\r
2587     case IDOK:\r
2588       /* Read changed options from the dialog box */\r
2589       if (IsDlgButtonChecked(hDlg, OPT_TCUseMoves)) {\r
2590         increment = -1;\r
2591         mps = GetDlgItemInt(hDlg, OPT_TCMoves, &ok, FALSE);\r
2592         if (!ok || mps <= 0) {\r
2593           MessageBox(hDlg, "Invalid moves per time control",\r
2594                      "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
2595           return FALSE;\r
2596         }\r
2597         GetDlgItemText(hDlg, OPT_TCTime, buf, MSG_SIZ);\r
2598         if (!ParseTimeControl(buf, increment, mps)) {\r
2599           MessageBox(hDlg, "Invalid minutes per time control",\r
2600                      "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
2601           return FALSE;\r
2602         }\r
2603       } else {\r
2604         increment = GetDlgItemInt(hDlg, OPT_TCInc, &ok, FALSE);\r
2605         mps = appData.movesPerSession;\r
2606         if (!ok || increment < 0) {\r
2607           MessageBox(hDlg, "Invalid increment",\r
2608                      "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
2609           return FALSE;\r
2610         }\r
2611         GetDlgItemText(hDlg, OPT_TCTime2, buf, MSG_SIZ);\r
2612         if (!ParseTimeControl(buf, increment, mps)) {\r
2613           MessageBox(hDlg, "Invalid initial time",\r
2614                      "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
2615           return FALSE;\r
2616         }\r
2617       }\r
2618       appData.timeControl = strdup(buf);\r
2619       appData.movesPerSession = mps;\r
2620       appData.timeIncrement = increment;\r
2621       Reset(TRUE, TRUE);\r
2622       EndDialog(hDlg, TRUE);\r
2623       return TRUE;\r
2624 \r
2625     case IDCANCEL:\r
2626       EndDialog(hDlg, FALSE);\r
2627       return TRUE;\r
2628 \r
2629     default:\r
2630       SetTimeControlEnables(hDlg);\r
2631       break;\r
2632     }\r
2633     break;\r
2634   }\r
2635   return FALSE;\r
2636 }\r
2637 \r
2638 VOID\r
2639 TimeControlOptionsPopup(HWND hwnd)\r
2640 {\r
2641   if (gameMode != BeginningOfGame) {\r
2642     DisplayError("Changing time control during a game is not implemented", 0);\r
2643   } else {\r
2644     FARPROC lpProc = MakeProcInstance((FARPROC)TimeControl, hInst);\r
2645     DialogBox(hInst, MAKEINTRESOURCE(DLG_TimeControl), hwnd, (DLGPROC) lpProc);\r
2646     FreeProcInstance(lpProc);\r
2647   }\r
2648 }\r
2649 \r
2650 /*---------------------------------------------------------------------------*\\r
2651  *\r
2652  * Engine Options Dialog functions\r
2653  *\r
2654 \*---------------------------------------------------------------------------*/\r
2655 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))\r
2656 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))\r
2657 \r
2658 #define INT_ABS( n )    ((n) >= 0 ? (n) : -(n))\r
2659 \r
2660 LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
2661 {\r
2662   switch (message) {\r
2663   case WM_INITDIALOG: /* message: initialize dialog box */\r
2664 \r
2665     /* Center the dialog over the application window */\r
2666     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
2667 \r
2668     /* Initialize the dialog items */\r
2669     CHECK_BOX(IDC_EpPeriodicUpdates, appData.periodicUpdates);\r
2670     CHECK_BOX(IDC_EpPonder, appData.ponderNextMove);\r
2671     CHECK_BOX(IDC_EpShowThinking, appData.showThinking);\r
2672     CHECK_BOX(IDC_EpHideThinkingHuman, appData.hideThinkingFromHuman);\r
2673 \r
2674     CHECK_BOX(IDC_TestClaims, appData.testClaims);\r
2675     CHECK_BOX(IDC_DetectMates, appData.checkMates);\r
2676     CHECK_BOX(IDC_MaterialDraws, appData.materialDraws);\r
2677     CHECK_BOX(IDC_TrivialDraws, appData.trivialDraws);\r
2678 \r
2679     SetDlgItemInt( hDlg, IDC_EpDrawMoveCount, appData.adjudicateDrawMoves, TRUE );\r
2680     SendDlgItemMessage( hDlg, IDC_EpDrawMoveCount, EM_SETSEL, 0, -1 );\r
2681 \r
2682     SetDlgItemInt( hDlg, IDC_EpAdjudicationThreshold, INT_ABS(appData.adjudicateLossThreshold), TRUE );\r
2683     SendDlgItemMessage( hDlg, IDC_EpAdjudicationThreshold, EM_SETSEL, 0, -1 );\r
2684 \r
2685     SetDlgItemInt( hDlg, IDC_RuleMoves, appData.ruleMoves, TRUE );\r
2686     SendDlgItemMessage( hDlg, IDC_RuleMoves, EM_SETSEL, 0, -1 );\r
2687 \r
2688     SetDlgItemInt( hDlg, IDC_DrawRepeats, INT_ABS(appData.drawRepeats), TRUE );\r
2689     SendDlgItemMessage( hDlg, IDC_DrawRepeats, EM_SETSEL, 0, -1 );\r
2690 \r
2691     return TRUE;\r
2692 \r
2693   case WM_COMMAND: /* message: received a command */\r
2694     switch (LOWORD(wParam)) {\r
2695     case IDOK:\r
2696       /* Read changed options from the dialog box */\r
2697       PeriodicUpdatesEvent(          IS_CHECKED(IDC_EpPeriodicUpdates));\r
2698       PonderNextMoveEvent(           IS_CHECKED(IDC_EpPonder));\r
2699       ShowThinkingEvent(             IS_CHECKED(IDC_EpShowThinking));\r
2700       appData.hideThinkingFromHuman= IS_CHECKED(IDC_EpHideThinkingHuman);\r
2701       appData.testClaims    = IS_CHECKED(IDC_TestClaims);\r
2702       appData.checkMates    = IS_CHECKED(IDC_DetectMates);\r
2703       appData.materialDraws = IS_CHECKED(IDC_MaterialDraws);\r
2704       appData.trivialDraws  = IS_CHECKED(IDC_TrivialDraws);\r
2705 \r
2706       appData.adjudicateDrawMoves = GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, NULL, FALSE );\r
2707       appData.adjudicateLossThreshold = - (int) GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, NULL, FALSE );\r
2708       appData.ruleMoves = GetDlgItemInt(hDlg, IDC_RuleMoves, NULL, FALSE );\r
2709       appData.drawRepeats = (int) GetDlgItemInt(hDlg, IDC_DrawRepeats, NULL, FALSE );\r
2710 \r
2711       EndDialog(hDlg, TRUE);\r
2712       return TRUE;\r
2713 \r
2714     case IDCANCEL:\r
2715       EndDialog(hDlg, FALSE);\r
2716       return TRUE;\r
2717 \r
2718     case IDC_EpDrawMoveCount:\r
2719     case IDC_EpAdjudicationThreshold:\r
2720     case IDC_DrawRepeats:\r
2721     case IDC_RuleMoves:\r
2722         if( HIWORD(wParam) == EN_CHANGE ) {\r
2723             int n1_ok;\r
2724             int n2_ok;\r
2725             int n3_ok;\r
2726             int n4_ok;\r
2727 \r
2728             GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, &n1_ok, FALSE );\r
2729             GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, &n2_ok, FALSE );\r
2730             GetDlgItemInt(hDlg, IDC_RuleMoves, &n3_ok, FALSE );\r
2731             GetDlgItemInt(hDlg, IDC_DrawRepeats, &n4_ok, FALSE );\r
2732 \r
2733             EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok && n4_ok ? TRUE : FALSE );\r
2734         }\r
2735         return TRUE;\r
2736     }\r
2737     break;\r
2738   }\r
2739   return FALSE;\r
2740 }\r
2741 \r
2742 VOID EnginePlayOptionsPopup(HWND hwnd)\r
2743 {\r
2744   FARPROC lpProc;\r
2745 \r
2746   lpProc = MakeProcInstance((FARPROC)EnginePlayOptionsDialog, hInst);\r
2747   DialogBox(hInst, MAKEINTRESOURCE(DLG_EnginePlayOptions), hwnd, (DLGPROC) lpProc);\r
2748   FreeProcInstance(lpProc);\r
2749 }\r
2750 \r
2751 /*---------------------------------------------------------------------------*\\r
2752  *\r
2753  * UCI Options Dialog functions\r
2754  *\r
2755 \*---------------------------------------------------------------------------*/\r
2756 static BOOL BrowseForFolder( const char * title, char * path )\r
2757 {\r
2758     BOOL result = FALSE;\r
2759     BROWSEINFO bi;\r
2760     LPITEMIDLIST pidl;\r
2761 \r
2762     ZeroMemory( &bi, sizeof(bi) );\r
2763 \r
2764     bi.lpszTitle = title == 0 ? "Choose Folder" : title;\r
2765     bi.ulFlags = BIF_RETURNONLYFSDIRS;\r
2766 \r
2767     pidl = SHBrowseForFolder( &bi );\r
2768 \r
2769     if( pidl != 0 ) {\r
2770         IMalloc * imalloc = 0;\r
2771 \r
2772         if( SHGetPathFromIDList( pidl, path ) ) {\r
2773             result = TRUE;\r
2774         }\r
2775 \r
2776         if( SUCCEEDED( SHGetMalloc ( &imalloc ) ) ) {\r
2777             imalloc->lpVtbl->Free(imalloc,pidl);\r
2778             imalloc->lpVtbl->Release(imalloc);\r
2779         }\r
2780     }\r
2781 \r
2782     return result;\r
2783 }\r
2784 \r
2785 LRESULT CALLBACK UciOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
2786 {\r
2787   char buf[MAX_PATH];\r
2788 \r
2789   switch (message) {\r
2790   case WM_INITDIALOG: /* message: initialize dialog box */\r
2791 \r
2792     /* Center the dialog over the application window */\r
2793     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
2794 \r
2795     /* Initialize the dialog items */\r
2796     SetDlgItemText( hDlg, IDC_PolyglotDir, appData.polyglotDir );\r
2797     SetDlgItemInt( hDlg, IDC_HashSize, appData.defaultHashSize, TRUE );\r
2798     SetDlgItemText( hDlg, IDC_PathToEGTB, appData.defaultPathEGTB );\r
2799     SetDlgItemInt( hDlg, IDC_SizeOfEGTB, appData.defaultCacheSizeEGTB, TRUE );\r
2800     CheckDlgButton( hDlg, IDC_UseBook, (BOOL) appData.usePolyglotBook );\r
2801     SetDlgItemText( hDlg, IDC_BookFile, appData.polyglotBook );\r
2802 \r
2803     SendDlgItemMessage( hDlg, IDC_PolyglotDir, EM_SETSEL, 0, -1 );\r
2804 \r
2805     return TRUE;\r
2806 \r
2807   case WM_COMMAND: /* message: received a command */\r
2808     switch (LOWORD(wParam)) {\r
2809     case IDOK:\r
2810       GetDlgItemText( hDlg, IDC_PolyglotDir, buf, sizeof(buf) );\r
2811       appData.polyglotDir = strdup(buf);\r
2812       appData.defaultHashSize = GetDlgItemInt(hDlg, IDC_HashSize, NULL, FALSE );\r
2813       appData.defaultCacheSizeEGTB = GetDlgItemInt(hDlg, IDC_SizeOfEGTB, NULL, FALSE );\r
2814       GetDlgItemText( hDlg, IDC_PathToEGTB, buf, sizeof(buf) );\r
2815       appData.defaultPathEGTB = strdup(buf);\r
2816       GetDlgItemText( hDlg, IDC_BookFile, buf, sizeof(buf) );\r
2817       appData.polyglotBook = strdup(buf);\r
2818       appData.usePolyglotBook = (Boolean) IsDlgButtonChecked( hDlg, IDC_UseBook );\r
2819 \r
2820       EndDialog(hDlg, TRUE);\r
2821       return TRUE;\r
2822 \r
2823     case IDCANCEL:\r
2824       EndDialog(hDlg, FALSE);\r
2825       return TRUE;\r
2826 \r
2827     case IDC_BrowseForBook:\r
2828       {\r
2829           char filter[] = { \r
2830               'A','l','l',' ','F','i','l','e','s', 0,\r
2831               '*','.','*', 0,\r
2832               'B','I','N',' ','F','i','l','e','s', 0,\r
2833               '*','.','b','i','n', 0,\r
2834               0 };\r
2835 \r
2836           OPENFILENAME ofn;\r
2837 \r
2838           strcpy( buf, "" );\r
2839 \r
2840           ZeroMemory( &ofn, sizeof(ofn) );\r
2841 \r
2842           ofn.lStructSize = sizeof(ofn);\r
2843           ofn.hwndOwner = hDlg;\r
2844           ofn.hInstance = hInst;\r
2845           ofn.lpstrFilter = filter;\r
2846           ofn.lpstrFile = buf;\r
2847           ofn.nMaxFile = sizeof(buf);\r
2848           ofn.lpstrTitle = "Choose Book";\r
2849           ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;\r
2850 \r
2851           if( GetOpenFileName( &ofn ) ) {\r
2852               SetDlgItemText( hDlg, IDC_BookFile, buf );\r
2853           }\r
2854       }\r
2855       return TRUE;\r
2856 \r
2857     case IDC_BrowseForPolyglotDir:\r
2858       if( BrowseForFolder( "Choose Polyglot Directory", buf ) ) {\r
2859         SetDlgItemText( hDlg, IDC_PolyglotDir, buf );\r
2860 \r
2861         strcat( buf, "\\polyglot.exe" );\r
2862 \r
2863         if( GetFileAttributes(buf) == 0xFFFFFFFF ) {\r
2864             MessageBox( hDlg, "Polyglot was not found in the specified folder!", "Warning", MB_OK | MB_ICONWARNING );\r
2865         }\r
2866       }\r
2867       return TRUE;\r
2868 \r
2869     case IDC_BrowseForEGTB:\r
2870       if( BrowseForFolder( "Choose EGTB Directory:", buf ) ) {\r
2871         SetDlgItemText( hDlg, IDC_PathToEGTB, buf );\r
2872       }\r
2873       return TRUE;\r
2874 \r
2875     case IDC_HashSize:\r
2876     case IDC_SizeOfEGTB:\r
2877         if( HIWORD(wParam) == EN_CHANGE ) {\r
2878             int n1_ok;\r
2879             int n2_ok;\r
2880 \r
2881             GetDlgItemInt(hDlg, IDC_HashSize, &n1_ok, FALSE );\r
2882             GetDlgItemInt(hDlg, IDC_SizeOfEGTB, &n2_ok, FALSE );\r
2883 \r
2884             EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok ? TRUE : FALSE );\r
2885         }\r
2886         return TRUE;\r
2887     }\r
2888     break;\r
2889   }\r
2890   return FALSE;\r
2891 }\r
2892 \r
2893 VOID UciOptionsPopup(HWND hwnd)\r
2894 {\r
2895   FARPROC lpProc;\r
2896 \r
2897   lpProc = MakeProcInstance((FARPROC)UciOptionsDialog, hInst);\r
2898   DialogBox(hInst, MAKEINTRESOURCE(DLG_OptionsUCI), hwnd, (DLGPROC) lpProc);\r
2899   FreeProcInstance(lpProc);\r
2900 }\r