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