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