Fix multi-leg promotions
[xboard.git] / winboard / woptions.c
index d568cee..34e3800 100644 (file)
@@ -1,38 +1,43 @@
 /*\r
  * woptions.c -- Options dialog box routines for WinBoard\r
- * $Id: woptions.c,v 2.1 2003/10/27 19:21:02 mann Exp $
  *\r
- * Copyright 2000 Free Software Foundation, Inc.\r
+ * Copyright 2000, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free\r
+ * Software Foundation, Inc.\r
+ *\r
+ * Enhancements Copyright 2005 Alessandro Scotti\r
  *\r
  * ------------------------------------------------------------------------\r
- * This program is free software; you can redistribute it and/or modify\r
+ *\r
+ * GNU XBoard is free software: you can redistribute it and/or modify\r
  * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
+ * the Free Software Foundation, either version 3 of the License, or (at\r
+ * your option) any later version.\r
  *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
+ * GNU XBoard is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * General Public License for more details.\r
  *\r
  * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- * ------------------------------------------------------------------------\r
- */\r
+ * along with this program. If not, see http://www.gnu.org/licenses/.  *\r
+ *\r
+ *------------------------------------------------------------------------\r
+ ** See the file ChangeLog for a revision history.  */\r
 \r
 #include "config.h"\r
 \r
 #include <windows.h>   /* required for all Windows applications */\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
+#include <shlobj.h>    /* [AS] Requires NT 4.0 or Win95 */\r
+#include <ctype.h>\r
 \r
 #include "common.h"\r
+#include "frontend.h"\r
 #include "winboard.h"\r
 #include "backend.h"\r
 #include "woptions.h"\r
 #include "defaults.h"\r
-#include "wedittags.h"\r
 #include <richedit.h>\r
 \r
 #if __GNUC__\r
@@ -40,6 +45,9 @@
 #include <string.h>\r
 #endif\r
 \r
+#define _(s) T_(s)\r
+#define N_(s) s\r
+\r
 /* Imports from winboard.c */\r
 \r
 extern MyFont *font[NUM_SIZES][NUM_FONTS];\r
@@ -47,7 +55,7 @@ extern HINSTANCE hInst;          /* current instance */
 extern HWND hwndMain;            /* root window*/\r
 extern BOOLEAN alwaysOnTop;\r
 extern RECT boardRect;\r
-extern COLORREF lightSquareColor, darkSquareColor, whitePieceColor, \r
+extern COLORREF lightSquareColor, darkSquareColor, whitePieceColor,\r
   blackPieceColor, highlightSquareColor, premoveHighlightColor;\r
 extern HPALETTE hPal;\r
 extern BoardSize boardSize;\r
@@ -59,10 +67,14 @@ extern ColorClass currentColorClass;
 extern HWND hwndConsole;\r
 extern char *defaultTextAttribs[];\r
 extern HWND commentDialog;\r
+extern HWND moveHistoryDialog;\r
+extern HWND engineOutputDialog;\r
 extern char installDir[];\r
 extern HWND hCommPort;    /* currently open comm port */\r
 extern DCB dcb;\r
 extern BOOLEAN chessProgram;\r
+extern int startedFromPositionFile; /* [HGM] loadPos */\r
+extern int searchTime;\r
 \r
 /* types */\r
 \r
@@ -80,6 +92,7 @@ typedef struct {
 \r
 LRESULT CALLBACK GeneralOptions(HWND, UINT, WPARAM, LPARAM);\r
 LRESULT CALLBACK BoardOptions(HWND, UINT, WPARAM, LPARAM);\r
+LRESULT CALLBACK NewVariant(HWND, UINT, WPARAM, LPARAM);\r
 LRESULT CALLBACK IcsOptions(HWND, UINT, WPARAM, LPARAM);\r
 LRESULT CALLBACK FontOptions(HWND, UINT, WPARAM, LPARAM);\r
 LRESULT CALLBACK CommPortOptions(HWND, UINT, WPARAM, LPARAM);\r
@@ -88,15 +101,15 @@ LRESULT CALLBACK SaveOptions(HWND, UINT, WPARAM, LPARAM);
 LRESULT CALLBACK TimeControl(HWND, UINT, WPARAM, LPARAM);\r
 VOID ChangeBoardSize(BoardSize newSize);\r
 VOID PaintSampleSquare(\r
-    HWND     hwnd, \r
-    int      ctrlid, \r
-    COLORREF squareColor, \r
+    HWND     hwnd,\r
+    int      ctrlid,\r
+    COLORREF squareColor,\r
     COLORREF pieceColor,\r
     COLORREF squareOutlineColor,\r
     COLORREF pieceDetailColor,\r
     BOOL     isWhitePiece,\r
     BOOL     isMono,\r
-    HBITMAP  pieces[3] \r
+    HBITMAP  pieces[3]\r
     );\r
 VOID PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color);\r
 VOID SetBoardOptionEnables(HWND hDlg);\r
@@ -123,6 +136,28 @@ VOID SetLoadOptionEnables(HWND hDlg);
 VOID SetSaveOptionEnables(HWND hDlg);\r
 VOID SetTimeControlEnables(HWND hDlg);\r
 \r
+char *\r
+InterpretFileName(char *buf, char *homeDir)\r
+{ // [HGM] file name relative to homeDir. (Taken out of SafeOptionsDialog, because it is generally useful)\r
+  char *result = NULL;\r
+  if ((isalpha(buf[0]) && buf[1] == ':') ||\r
+    (buf[0] == '\\' && buf[1] == '\\')) {\r
+    return strdup(buf);\r
+  } else {\r
+    char buf2[MSG_SIZ], buf3[MSG_SIZ];\r
+    char *dummy;\r
+    GetCurrentDirectory(MSG_SIZ, buf3);\r
+    SetCurrentDirectory(homeDir);\r
+    if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {\r
+      result = strdup(buf2);\r
+    } else {\r
+      result = strdup(buf);\r
+    }\r
+    SetCurrentDirectory(buf3);\r
+  }\r
+  return result;\r
+}\r
+\r
 /*---------------------------------------------------------------------------*\\r
  *\r
  * General Options Dialog functions\r
@@ -136,15 +171,18 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   static Boolean oldShowCoords;\r
   static Boolean oldBlindfold;\r
   static Boolean oldShowButtonBar;\r
+  static Boolean oldAutoLogo;\r
 \r
   switch (message) {\r
   case WM_INITDIALOG: /* message: initialize dialog box */\r
     oldShowCoords = appData.showCoords;\r
     oldBlindfold  = appData.blindfold;\r
     oldShowButtonBar = appData.showButtonBar;\r
+    oldAutoLogo  = appData.autoLogo;\r
 \r
     /* Center the dialog over the application window */\r
     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_GeneralOptions);\r
 \r
     /* Initialize the dialog items */\r
 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))\r
@@ -167,8 +205,17 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     CHECK_BOX(OPT_ShowCoordinates, appData.showCoords);\r
     CHECK_BOX(OPT_ShowThinking, appData.showThinking);\r
     CHECK_BOX(OPT_TestLegality, appData.testLegality);\r
-    CHECK_BOX(OPT_HideThinkFromHuman, appData.hideThinkingFromHuman);
-    CHECK_BOX(OPT_SaveExtPGN, appData.saveExtendedInfoInPGN);
+    CHECK_BOX(OPT_HideThinkFromHuman, appData.hideThinkingFromHuman);\r
+    CHECK_BOX(OPT_SaveExtPGN, appData.saveExtendedInfoInPGN);\r
+    CHECK_BOX(OPT_ExtraInfoInMoveHistory, appData.showEvalInMoveHistory);\r
+    CHECK_BOX(OPT_HighlightMoveArrow, appData.highlightMoveWithArrow);\r
+    CHECK_BOX(OPT_AutoLogo, appData.autoLogo); // [HGM] logo\r
+    CHECK_BOX(OPT_SmartMove, appData.oneClick); // [HGM] one-click\r
+    CHECK_BOX(OPT_AutoTags, appData.autoDisplayTags); // [HGM]\r
+    CHECK_BOX(OPT_AutoComment, appData.autoDisplayComment); // [HGM]\r
+    CHECK_BOX(OPT_Headers, appData.headers); // [HGM]\r
+    CHECK_BOX(OPT_Variations, appData.variations); // [HGM]\r
+    CHECK_BOX(OPT_AutoExtend, appData.autoExtend); // [HGM]\r
 \r
 #undef CHECK_BOX\r
 \r
@@ -178,9 +225,9 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
                 appData.icsActive || !appData.noChessProgram);\r
     EnableWindow(GetDlgItem(hDlg, OPT_PonderNextMove),\r
                 !appData.noChessProgram);\r
-    EnableWindow(GetDlgItem(hDlg, OPT_PeriodicUpdates), \r
+    EnableWindow(GetDlgItem(hDlg, OPT_PeriodicUpdates),\r
                 !appData.noChessProgram && !appData.icsActive);\r
-    EnableWindow(GetDlgItem(hDlg, OPT_ShowThinking), \r
+    EnableWindow(GetDlgItem(hDlg, OPT_ShowThinking),\r
                 !appData.noChessProgram);\r
     return TRUE;\r
 \r
@@ -189,7 +236,7 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     switch (LOWORD(wParam)) {\r
     case IDOK:\r
       /* Read changed options from the dialog box */\r
-      \r
+\r
 #define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))\r
 \r
       alwaysOnTop                  = IS_CHECKED(OPT_AlwaysOnTop);\r
@@ -208,10 +255,21 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       appData.popupMoveErrors      = IS_CHECKED(OPT_PopupMoveErrors);\r
       appData.showButtonBar        = IS_CHECKED(OPT_ShowButtonBar);\r
       appData.showCoords           = IS_CHECKED(OPT_ShowCoordinates);\r
-      ShowThinkingEvent(             IS_CHECKED(OPT_ShowThinking));\r
+      // [HGM] thinking: next three moved up\r
+      appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN);\r
+      appData.hideThinkingFromHuman= IS_CHECKED(OPT_HideThinkFromHuman);\r
+      appData.showEvalInMoveHistory= IS_CHECKED(OPT_ExtraInfoInMoveHistory);\r
+      appData.showThinking         = IS_CHECKED(OPT_ShowThinking);\r
+      ShowThinkingEvent(); // [HGM] thinking: tests four options\r
       appData.testLegality         = IS_CHECKED(OPT_TestLegality);\r
-      appData.hideThinkingFromHuman= IS_CHECKED(OPT_HideThinkFromHuman);
-      appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN);
+      appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow);\r
+      appData.autoLogo             =IS_CHECKED(OPT_AutoLogo); // [HGM] logo\r
+      appData.oneClick             =IS_CHECKED(OPT_SmartMove); // [HGM] one-click\r
+      appData.autoDisplayTags      =IS_CHECKED(OPT_AutoTags); // [HGM]\r
+      appData.autoDisplayComment   =IS_CHECKED(OPT_AutoComment); // [HGM]\r
+      appData.headers              =IS_CHECKED(OPT_Headers); // [HGM]\r
+      appData.variations           =IS_CHECKED(OPT_Variations); // [HGM]\r
+      appData.autoExtend           =IS_CHECKED(OPT_AutoExtend); // [HGM]\r
 \r
 #undef IS_CHECKED\r
 \r
@@ -227,15 +285,18 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        ClearHighlights();\r
        DrawPosition(FALSE, NULL);\r
       }\r
-      /* \r
+      /*\r
        * for some reason the redraw seems smoother when we invalidate\r
        * the board rect after the call to EndDialog()\r
        */\r
       EndDialog(hDlg, TRUE);\r
 \r
-      if (oldShowButtonBar != appData.showButtonBar) {\r
+      if (oldAutoLogo != appData.autoLogo) { // [HGM] logo: remove any logos when we switch autologo off\r
+       if(oldAutoLogo) first.programLogo = second.programLogo = NULL;\r
        InitDrawingSizes(boardSize, 0);\r
-      } else if ((oldShowCoords != appData.showCoords) || \r
+      } else if (oldShowButtonBar != appData.showButtonBar) {\r
+       InitDrawingSizes(boardSize, 0);\r
+      } else if ((oldShowCoords != appData.showCoords) ||\r
                 (oldBlindfold != appData.blindfold)) {\r
        InvalidateRect(hwndMain, &boardRect, FALSE);\r
       }\r
@@ -252,7 +313,7 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   return FALSE;\r
 }\r
 \r
-VOID \r
+VOID\r
 GeneralOptionsPopup(HWND hwnd)\r
 {\r
   FARPROC lpProc;\r
@@ -281,22 +342,22 @@ ChangeBoardSize(BoardSize newSize)
 \r
 VOID\r
 PaintSampleSquare(\r
-    HWND     hwnd, \r
-    int      ctrlid, \r
-    COLORREF squareColor, \r
+    HWND     hwnd,\r
+    int      ctrlid,\r
+    COLORREF squareColor,\r
     COLORREF pieceColor,\r
     COLORREF squareOutlineColor,\r
     COLORREF pieceDetailColor,\r
     BOOL     isWhitePiece,\r
     BOOL     isMono,\r
-    HBITMAP  pieces[3] \r
+    HBITMAP  pieces[3]\r
     )\r
 {\r
   HBRUSH  brushSquare;\r
   HBRUSH  brushSquareOutline;\r
   HBRUSH  brushPiece;\r
   HBRUSH  brushPieceDetail;\r
-  HBRUSH  oldBrushPiece;\r
+  HBRUSH  oldBrushPiece = NULL;\r
   HBRUSH  oldBrushSquare;\r
   HBITMAP oldBitmapMem;\r
   HBITMAP oldBitmapTemp;\r
@@ -332,15 +393,15 @@ PaintSampleSquare(
   brushPiece          = CreateSolidBrush(pieceColor);\r
   brushPieceDetail    = CreateSolidBrush(pieceDetailColor);\r
 \r
-  /* \r
-   * first draw the rectangle \r
+  /*\r
+   * first draw the rectangle\r
    */\r
   pen      = CreatePen(PS_SOLID, BORDER, squareOutlineColor);\r
   oldPen   = (HPEN)  SelectObject(hdcMem, pen);\r
   oldBrushSquare = (HBRUSH)SelectObject(hdcMem, brushSquare);\r
   Rectangle(hdcMem, rect.left, rect.top, rect.right, rect.bottom);\r
 \r
-  /* \r
+  /*\r
    * now draw the piece\r
    */\r
   if (isMono) {\r
@@ -352,45 +413,23 @@ PaintSampleSquare(
     if (isWhitePiece) {\r
       oldBitmapTemp = SelectObject(hdcTemp, pieces[WHITE]);\r
       oldBrushPiece = SelectObject(hdcMem, brushPiece);\r
-      BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
+      BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,\r
             hdcTemp, 0, 0, 0x00B8074A);\r
-#if 0\r
-      /* Use pieceDetailColor for outline of white pieces */\r
-      SelectObject(hdcTemp, pieces[OUTLINE]);\r
-      SelectObject(hdcMem, brushPieceDetail);\r
-      BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
-            hdcTemp, 0, 0, 0x00B8074A);\r
-#else\r
       /* Use black for outline of white pieces */\r
       SelectObject(hdcTemp, pieces[OUTLINE]);\r
-      BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
+      BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,\r
             hdcTemp, 0, 0, SRCAND);\r
-#endif\r
     } else {\r
-#if 0\r
-      /* Use pieceDetailColor for details of black pieces */\r
-      /* Requires filled-in solid bitmaps (BLACK_PIECE class); the\r
-        WHITE_PIECE ones aren't always the right shape. */\r
-      oldBitmapTemp = SelectObject(hdcTemp, pieces[BLACK]);\r
-      oldBrushPiece = SelectObject(hdcMem, brushPieceDetail);\r
-      BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
-            hdcTemp, 0, 0, 0x00B8074A);\r
-      SelectObject(hdcTemp, pieces[SOLID]);\r
-      SelectObject(hdcMem, brushPiece);\r
-      BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
-            hdcTemp, 0, 0, 0x00B8074A);\r
-#else\r
       /* Use square color for details of black pieces */\r
       oldBitmapTemp = SelectObject(hdcTemp, pieces[SOLID]);\r
       oldBrushPiece = SelectObject(hdcMem, brushPiece);\r
-      BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, \r
+      BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE,\r
             hdcTemp, 0, 0, 0x00B8074A);\r
-#endif\r
     }\r
     SelectObject(hdcMem, oldBrushPiece);\r
     SelectObject(hdcTemp, oldBitmapTemp);\r
   }\r
-  /* \r
+  /*\r
    * copy the memory dc to the screen\r
    */\r
   SelectObject(hdcMem, bufferBitmap);\r
@@ -399,10 +438,10 @@ PaintSampleSquare(
         rect.bottom - rect.top,\r
         hdcMem, rect.left, rect.top, SRCCOPY);\r
   SelectObject(hdcMem, oldBitmapMem);\r
-  /* \r
+  /*\r
    * clean up\r
    */\r
-  SelectObject(hdcMem, oldBrushPiece);\r
+  SelectObject(hdcMem, oldBrushSquare);\r
   SelectObject(hdcMem, oldPen);\r
   DeleteObject(brushPiece);\r
   DeleteObject(brushPieceDetail);\r
@@ -462,7 +501,7 @@ SetBoardOptionEnables(HWND hDlg)
   }\r
 }\r
 \r
-BoardSize \r
+BoardSize\r
 BoardOptionsWhichRadio(HWND hDlg)\r
 {\r
   return (IsDlgButtonChecked(hDlg, OPT_SizeTiny) ? SizeTiny :\r
@@ -488,7 +527,7 @@ BoardOptionsWhichRadio(HWND hDlg)
 LRESULT CALLBACK\r
 BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
 {\r
-  static Boolean  mono;\r
+  static Boolean  mono, white, flip, fonts, bitmaps, grid;\r
   static BoardSize size;\r
   static COLORREF lsc, dsc, wpc, bpc, hsc, phc;\r
   static HBITMAP pieces[3];\r
@@ -497,6 +536,7 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   case WM_INITDIALOG: /* message: initialize dialog box */\r
     /* Center the dialog over the application window */\r
     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_BoardOptions);\r
     /* Initialize the dialog items */\r
     switch (boardSize) {\r
     case SizeTiny:\r
@@ -552,23 +592,44 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       break;\r
     case SizeTitanic:\r
       CheckDlgButton(hDlg, OPT_SizeTitanic, TRUE);\r
+    default: ; // should not happen, but suppresses warning on pedantic compilers\r
     }\r
 \r
     if (appData.monoMode)\r
       CheckDlgButton(hDlg, OPT_Monochrome, TRUE);\r
 \r
+    if (appData.allWhite)\r
+      CheckDlgButton(hDlg, OPT_AllWhite, TRUE);\r
+\r
+    if (appData.upsideDown)\r
+      CheckDlgButton(hDlg, OPT_UpsideDown, TRUE);\r
+\r
+    if (appData.useBitmaps)\r
+      CheckDlgButton(hDlg, OPT_Bitmaps, TRUE);\r
+\r
+    if (appData.useFont)\r
+      CheckDlgButton(hDlg, OPT_PieceFont, TRUE);\r
+\r
+    if (appData.overrideLineGap >= 0)\r
+      CheckDlgButton(hDlg, OPT_Grid, TRUE);\r
+\r
     pieces[0] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "s");\r
     pieces[1] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "w");\r
     pieces[2] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "o");\r
-       \r
+\r
     lsc = lightSquareColor;\r
     dsc = darkSquareColor;\r
-    wpc = whitePieceColor;\r
-    bpc = blackPieceColor;\r
+    fonts = appData.useFont;\r
+    wpc = fonts ? appData.fontBackColorWhite : whitePieceColor;\r
+    bpc = fonts ? appData.fontForeColorBlack : blackPieceColor;\r
     hsc = highlightSquareColor;\r
     phc = premoveHighlightColor;\r
     mono = appData.monoMode;\r
+    white= appData.allWhite;\r
+    flip = appData.upsideDown;\r
     size = boardSize;\r
+    bitmaps = appData.useBitmaps;\r
+    grid = appData.overrideLineGap >= 0;\r
 \r
     SetBoardOptionEnables(hDlg);\r
     return TRUE;\r
@@ -590,7 +651,7 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   case WM_COMMAND: /* message: received a command */\r
     switch (LOWORD(wParam)) {\r
     case IDOK:\r
-      /* \r
+      /*\r
        * if we call EndDialog() after the call to ChangeBoardSize(),\r
        * then ChangeBoardSize() does not take effect, although the new\r
        * boardSize is saved. Go figure...\r
@@ -606,21 +667,38 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        ChangeBoardSize(size);\r
       }\r
 \r
+      if (bitmaps && !appData.useBitmaps) InitTextures();\r
+\r
       if ((mono != appData.monoMode) ||\r
          (lsc  != lightSquareColor) ||\r
          (dsc  != darkSquareColor) ||\r
-         (wpc  != whitePieceColor) ||\r
-         (bpc  != blackPieceColor) ||\r
+         (wpc  != fonts ? appData.fontBackColorWhite : whitePieceColor) ||\r
+         (bpc  != fonts ? appData.fontForeColorBlack : blackPieceColor) ||\r
          (hsc  != highlightSquareColor) ||\r
+          (flip != appData.upsideDown) ||\r
+          (white != appData.allWhite) ||\r
+          (fonts != appData.useFont) ||\r
+          (bitmaps != appData.useBitmaps) ||\r
+          (grid != appData.overrideLineGap >= 0) ||\r
          (phc  != premoveHighlightColor)) {\r
 \r
          lightSquareColor = lsc;\r
          darkSquareColor = dsc;\r
-         whitePieceColor = wpc;\r
-         blackPieceColor = bpc;\r
+         if(fonts) {\r
+           appData.fontBackColorWhite = wpc;\r
+           appData.fontForeColorBlack = bpc;\r
+         } else {\r
+           whitePieceColor = wpc;\r
+           blackPieceColor = bpc;\r
+         }\r
          highlightSquareColor = hsc;\r
          premoveHighlightColor = phc;\r
          appData.monoMode = mono;\r
+          appData.allWhite = white;\r
+          appData.upsideDown = flip;\r
+          appData.useFont = fonts;\r
+          appData.useBitmaps = bitmaps;\r
+          if(grid != appData.overrideLineGap >= 0) appData.overrideLineGap = grid - 1;\r
 \r
          InitDrawingColors();\r
          InitDrawingSizes(boardSize, 0);\r
@@ -628,6 +706,7 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       }\r
       DeleteObject(pieces[0]);\r
       DeleteObject(pieces[1]);\r
+\r
       DeleteObject(pieces[2]);\r
       return TRUE;\r
 \r
@@ -639,42 +718,42 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       return TRUE;\r
 \r
     case OPT_ChooseLightSquareColor:\r
-      if (ChangeColor(hDlg, &lsc)) \r
+      if (ChangeColor(hDlg, &lsc))\r
        PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);\r
        PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,\r
            TRUE, mono, pieces);\r
       break;\r
 \r
     case OPT_ChooseDarkSquareColor:\r
-      if (ChangeColor(hDlg, &dsc)) \r
+      if (ChangeColor(hDlg, &dsc))\r
        PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc);\r
        PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,\r
            FALSE, mono, pieces);\r
       break;\r
 \r
     case OPT_ChooseWhitePieceColor:\r
-      if (ChangeColor(hDlg, &wpc)) \r
+      if (ChangeColor(hDlg, &wpc))\r
        PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc);\r
        PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,\r
            TRUE, mono, pieces);\r
       break;\r
 \r
     case OPT_ChooseBlackPieceColor:\r
-      if (ChangeColor(hDlg, &bpc)) \r
+      if (ChangeColor(hDlg, &bpc))\r
        PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc);\r
        PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,\r
            FALSE, mono, pieces);\r
       break;\r
 \r
     case OPT_ChooseHighlightSquareColor:\r
-      if (ChangeColor(hDlg, &hsc)) \r
+      if (ChangeColor(hDlg, &hsc))\r
        PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc);\r
        PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc,\r
            TRUE, mono, pieces);\r
       break;\r
 \r
     case OPT_ChoosePremoveHighlightColor:\r
-      if (ChangeColor(hDlg, &phc)) \r
+      if (ChangeColor(hDlg, &phc))\r
        PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc);\r
        PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc,\r
            FALSE, mono, pieces);\r
@@ -688,7 +767,11 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       hsc = ParseColorName(HIGHLIGHT_SQUARE_COLOR);\r
       phc = ParseColorName(PREMOVE_HIGHLIGHT_COLOR);\r
       mono = FALSE;\r
+      white= FALSE;\r
+      flip = FALSE;\r
       CheckDlgButton(hDlg, OPT_Monochrome, FALSE);\r
+      CheckDlgButton(hDlg, OPT_AllWhite,   FALSE);\r
+      CheckDlgButton(hDlg, OPT_UpsideDown, FALSE);\r
       PaintColorBlock(hDlg, OPT_LightSquareColor, lsc);\r
       PaintColorBlock(hDlg, OPT_DarkSquareColor,  dsc);\r
       PaintColorBlock(hDlg, OPT_WhitePieceColor,  wpc);\r
@@ -706,6 +789,26 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       mono = !mono;\r
       SetBoardOptionEnables(hDlg);\r
       break;\r
+\r
+    case OPT_AllWhite:\r
+      white = !white;\r
+      break;\r
+\r
+    case OPT_UpsideDown:\r
+      flip = !flip;\r
+      break;\r
+\r
+    case OPT_Bitmaps:\r
+      bitmaps = !bitmaps;\r
+      break;\r
+\r
+    case OPT_PieceFont:\r
+      fonts = !fonts;\r
+      break;\r
+\r
+    case OPT_Grid:\r
+      grid = !grid;\r
+      break;\r
     }\r
     break;\r
   }\r
@@ -722,6 +825,202 @@ BoardOptionsPopup(HWND hwnd)
   FreeProcInstance(lpProc);\r
 }\r
 \r
+int radioButton[] = {\r
+    OPT_VariantNormal,\r
+    -1, // Loadable\r
+    OPT_VariantWildcastle,\r
+    OPT_VariantNocastle,\r
+    OPT_VariantFRC,\r
+    OPT_VariantBughouse,\r
+    OPT_VariantCrazyhouse,\r
+    OPT_VariantLosers,\r
+    OPT_VariantSuicide,\r
+    OPT_VariantGiveaway,\r
+    OPT_VariantTwoKings,\r
+    -1, //Kriegspiel\r
+    OPT_VariantAtomic,\r
+    OPT_Variant3Check,\r
+    OPT_VariantShatranj,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    -1,\r
+    OPT_VariantShogi,\r
+    -1, // Chu\r
+    OPT_VariantCourier,\r
+    OPT_VariantGothic,\r
+    OPT_VariantCapablanca,\r
+    OPT_VariantKnightmate,\r
+    OPT_VariantFairy,        \r
+    OPT_VariantCylinder,\r
+    OPT_VariantFalcon,\r
+    OPT_VariantCRC,\r
+    OPT_VariantBerolina,\r
+    OPT_VariantJanus,\r
+    OPT_VariantSuper,\r
+    OPT_VariantGreat,\r
+    -1, // Twilight,\r
+    OPT_VariantMakruk,\r
+    OPT_VariantSChess,\r
+    OPT_VariantGrand,\r
+    OPT_VariantSpartan, // Spartan\r
+    OPT_VariantXiangqi,\r
+    OPT_VariantASEAN,\r
+    OPT_VariantLion,\r
+    -2 // sentinel\r
+};\r
+\r
+VariantClass\r
+VariantWhichRadio(HWND hDlg)\r
+{\r
+  int i=0, j;\r
+  *engineVariant = NULLCHAR;\r
+  while((j = radioButton[i++]) != -2) {\r
+       if(j == -1) continue; // no menu button\r
+       if(IsDlgButtonChecked(hDlg, j) &&\r
+          (appData.noChessProgram || strstr(first.variants, VariantName(i-1)))) return (VariantClass) i-1;\r
+  }\r
+  for(i=0; i<15; i++) { // check for engine-defined variants\r
+    if(IsDlgButtonChecked(hDlg, OPT_EngineVariant+i) ) {\r
+       GetDlgItemText(hDlg, OPT_EngineVariant+i, engineVariant, MSG_SIZ); // remember name, so we can resolve it later\r
+       return VariantUnknown;\r
+    }\r
+  }\r
+  return gameInfo.variant; // If no button checked, keep old\r
+}\r
+\r
+void\r
+VariantShowRadio(HWND hDlg)\r
+{\r
+  char c = *engineVariant, *v, *p;\r
+  int i=0, j;\r
+  CheckDlgButton(hDlg, radioButton[gameInfo.variant], TRUE);\r
+  *engineVariant = NULLCHAR; // [HGM] kludge to prevent VariantName will always return engineVariant\r
+  while((j = radioButton[i++]) != -2) {\r
+       if(j == -1) continue; // no menu button\r
+       v = VariantName(i-1); p = strstr(first.variants, v);\r
+       EnableWindow(GetDlgItem(hDlg, j), appData.noChessProgram || p && (!*v || strlen(v) == strlen(p) || p[strlen(v)] == ','));\r
+  }\r
+  *engineVariant = c;\r
+  for(i=0; i<15; i++) { // initialize engine-defined variants\r
+    char *v = EngineDefinedVariant(&first, i); // get name of #i\r
+    if(v) { // there is such a variant\r
+       EnableWindow(GetDlgItem(hDlg, OPT_EngineVariant+i), TRUE);     // and enable the button\r
+       SetDlgItemText(hDlg, OPT_EngineVariant+i, v);                  // put its name on button\r
+    } else EnableWindow(GetDlgItem(hDlg, OPT_EngineVariant+i), FALSE); // no such variant; disable button\r
+  }\r
+}\r
+\r
+LRESULT CALLBACK\r
+NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
+{\r
+  static VariantClass v;\r
+  static int n1_ok, n2_ok, n3_ok;\r
+\r
+  switch (message) {\r
+  case WM_INITDIALOG: /* message: initialize dialog box */\r
+    /* Center the dialog over the application window */\r
+    CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_NewVariant);\r
+\r
+    /* Initialize the dialog items */\r
+    VariantShowRadio(hDlg);\r
+\r
+    SetDlgItemInt( hDlg, IDC_Files, -1, TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_Files, EM_SETSEL, 0, -1 );\r
+\r
+    SetDlgItemInt( hDlg, IDC_Ranks, -1, TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );\r
+\r
+    SetDlgItemInt( hDlg, IDC_Holdings, -1, TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 );\r
+\r
+    n1_ok = n2_ok = n3_ok = FALSE;\r
+\r
+    return TRUE;\r
+\r
+  case WM_COMMAND: /* message: received a command */\r
+    switch (LOWORD(wParam)) {\r
+    case IDOK:\r
+      /*\r
+       * if we call EndDialog() after the call to ChangeBoardSize(),\r
+       * then ChangeBoardSize() does not take effect, although the new\r
+       * boardSize is saved. Go figure...\r
+       */\r
+      EndDialog(hDlg, TRUE);\r
+\r
+      v = VariantWhichRadio(hDlg);\r
+      if(!appData.noChessProgram) {\r
+       char *name = VariantName(v), buf[MSG_SIZ];\r
+       if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {\r
+         /* [HGM] in protocol 2 we check if variant is suported by engine */\r
+         snprintf(buf, MSG_SIZ, _("Variant %s not supported by %s"), name, first.tidy);\r
+         DisplayError(buf, 0);\r
+         return TRUE; /* treat as _("Cancel") if first engine does not support it */\r
+       } else\r
+       if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {\r
+         snprintf(buf, MSG_SIZ, _("Warning: second engine (%s) does not support this!"), second.tidy);\r
+         DisplayError(buf, 0);   /* use of second engine is optional; only warn user */\r
+       }\r
+      }\r
+\r
+      gameInfo.variant = v;\r
+      ASSIGN(appData.variant, VariantName(v));\r
+\r
+      appData.NrFiles = (int) GetDlgItemInt(hDlg, IDC_Files, NULL, FALSE );\r
+      appData.NrRanks = (int) GetDlgItemInt(hDlg, IDC_Ranks, NULL, FALSE );\r
+      appData.holdingsSize = (int) GetDlgItemInt(hDlg, IDC_Holdings, NULL, FALSE );\r
+\r
+      if(!n1_ok) appData.NrFiles = -1;\r
+      if(!n2_ok) appData.NrRanks = -1;\r
+      if(!n3_ok) appData.holdingsSize = -1;\r
+\r
+      shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */\r
+      startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */\r
+      appData.pieceToCharTable = NULL;\r
+      ASSIGN(appData.pieceNickNames, "");\r
+      ASSIGN(appData.colorNickNames, "");\r
+      ASSIGN(appData.men, "");\r
+      Reset(TRUE, TRUE);\r
+\r
+      return TRUE;\r
+\r
+    case IDCANCEL:\r
+      EndDialog(hDlg, FALSE);\r
+      return TRUE;\r
+\r
+    case IDC_Ranks:\r
+    case IDC_Files:\r
+    case IDC_Holdings:\r
+        if( HIWORD(wParam) == EN_CHANGE ) {\r
+\r
+            GetDlgItemInt(hDlg, IDC_Files, &n1_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_Ranks, &n2_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_Holdings, &n3_ok, FALSE );\r
+\r
+            /*EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok ? TRUE : FALSE );*/\r
+        }\r
+        return TRUE;\r
+    }\r
+    break;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+\r
+VOID\r
+NewVariantPopup(HWND hwnd)\r
+{\r
+  FARPROC lpProc = MakeProcInstance((FARPROC)NewVariantDialog, hInst);\r
+  DialogBox(hInst, MAKEINTRESOURCE(DLG_NewVariant), hwnd,\r
+         (DLGPROC) lpProc);\r
+  FreeProcInstance(lpProc);\r
+}\r
+\r
 /*---------------------------------------------------------------------------*\\r
  *\r
  * ICS Options Dialog functions\r
@@ -770,7 +1069,8 @@ MyCreateFont(HWND hwnd, MyFont *font)
   font->mfp.italic = font->lf.lfItalic;\r
   font->mfp.underline = font->lf.lfUnderline;\r
   font->mfp.strikeout = font->lf.lfStrikeOut;\r
-  strcpy(font->mfp.faceName, font->lf.lfFaceName);\r
+  font->mfp.charset = font->lf.lfCharSet;\r
+  safeStrCpy(font->mfp.faceName, font->lf.lfFaceName, sizeof(font->mfp.faceName)/sizeof(font->mfp.faceName[0]) );\r
   return TRUE;\r
 }\r
 \r
@@ -780,12 +1080,12 @@ UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca)
 {\r
   CHARFORMAT cf;\r
   cf.cbSize = sizeof(CHARFORMAT);\r
-  cf.dwMask = \r
-    CFM_COLOR|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE;\r
+  cf.dwMask =\r
+    CFM_COLOR|CFM_CHARSET|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE;\r
   cf.crTextColor = mca->color;\r
   cf.dwEffects = mca->effects;\r
-  strcpy(cf.szFaceName, font[boardSize][CONSOLE_FONT]->mfp.faceName);\r
-  /* \r
+  safeStrCpy(cf.szFaceName, font[boardSize][CONSOLE_FONT]->mfp.faceName, sizeof(cf.szFaceName)/sizeof(cf.szFaceName[0]) );\r
+  /*\r
    * The 20.0 below is in fact documented. yHeight is expressed in twips.\r
    * A twip is 1/20 of a font's point size. See documentation of CHARFORMAT.\r
    * --msw\r
@@ -809,6 +1109,7 @@ ColorizeTextDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     mca = colorizeAttribs[cc];\r
     /* Center the dialog over the application window */\r
     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_Colorize);\r
     /* Initialize the dialog items */\r
     CheckDlgButton(hDlg, OPT_Bold, (mca.effects & CFE_BOLD) != 0);\r
     CheckDlgButton(hDlg, OPT_Italic, (mca.effects & CFE_ITALIC) != 0);\r
@@ -816,14 +1117,14 @@ ColorizeTextDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     CheckDlgButton(hDlg, OPT_Strikeout, (mca.effects & CFE_STRIKEOUT) != 0);\r
 \r
     /* get the current background color from the parent window */\r
-    SendMessage(GetWindow(hDlg, GW_OWNER),WM_COMMAND, \r
-               (WPARAM)WM_USER_GetConsoleBackground, \r
+    SendMessage(GetWindow(hDlg, GW_OWNER),WM_COMMAND,\r
+               (WPARAM)WM_USER_GetConsoleBackground,\r
                (LPARAM)&background);\r
 \r
     /* set the background color */\r
     SendDlgItemMessage(hDlg, OPT_Sample, EM_SETBKGNDCOLOR, FALSE, background);\r
 \r
-    SetDlgItemText(hDlg, OPT_Sample, mca.name);\r
+    SetDlgItemText(hDlg, OPT_Sample, T_(mca.name));\r
     UpdateSampleText(hDlg, OPT_Sample, &mca);\r
     return TRUE;\r
 \r
@@ -840,7 +1141,7 @@ ColorizeTextDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        cf.cbSize = sizeof(CHARFORMAT);\r
        cf.dwMask = CFM_COLOR;\r
        cf.crTextColor = mca.color;\r
-       SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, \r
+       SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,\r
          EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);\r
       }\r
       EndDialog(hDlg, TRUE);\r
@@ -920,15 +1221,23 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 \r
     /* Center the dialog over the application window */\r
     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_IcsOptions);\r
 \r
     /* Initialize the dialog items */\r
 #define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))\r
 \r
+    CHECK_BOX(OPT_AutoKibitz, appData.autoKibitz);\r
     CHECK_BOX(OPT_AutoComment, appData.autoComment);\r
     CHECK_BOX(OPT_AutoObserve, appData.autoObserve);\r
+    CHECK_BOX(OPT_AutoCreate, appData.autoCreateLogon);\r
     CHECK_BOX(OPT_GetMoveList, appData.getMoveList);\r
     CHECK_BOX(OPT_LocalLineEditing, appData.localLineEditing);\r
     CHECK_BOX(OPT_QuietPlay, appData.quietPlay);\r
+    CHECK_BOX(OPT_SeekGraph, appData.seekGraph);\r
+    CHECK_BOX(OPT_AutoRefresh, appData.autoRefresh);\r
+    CHECK_BOX(OPT_BgObserve, appData.bgObserve);\r
+    CHECK_BOX(OPT_DualBoard, appData.dualBoard);\r
+    CHECK_BOX(OPT_SmartMove, appData.oneClick);\r
     CHECK_BOX(OPT_Premove, appData.premove);\r
     CHECK_BOX(OPT_PremoveWhite, appData.premoveWhite);\r
     CHECK_BOX(OPT_PremoveBlack, appData.premoveBlack);\r
@@ -937,10 +1246,11 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 \r
 #undef CHECK_BOX\r
 \r
-    sprintf(buf, "%d", appData.icsAlarmTime / 1000);\r
+    snprintf(buf, MSG_SIZ, "%d", appData.icsAlarmTime / 1000);\r
     SetDlgItemText(hDlg, OPT_IcsAlarmTime, buf);\r
     SetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText);\r
     SetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText);\r
+    SetDlgItemText(hDlg, OPT_StartupChatBoxes, appData.chatBoxes);\r
 \r
     SendDlgItemMessage(hDlg, OPT_SampleShout,     EM_SETBKGNDCOLOR, 0, cbc);\r
     SendDlgItemMessage(hDlg, OPT_SampleSShout,    EM_SETBKGNDCOLOR, 0, cbc);\r
@@ -953,16 +1263,16 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     SendDlgItemMessage(hDlg, OPT_SampleSeek,      EM_SETBKGNDCOLOR, 0, cbc);\r
     SendDlgItemMessage(hDlg, OPT_SampleNormal,    EM_SETBKGNDCOLOR, 0, cbc);\r
 \r
-    SetDlgItemText(hDlg, OPT_SampleShout,     mca[ColorShout].name);\r
-    SetDlgItemText(hDlg, OPT_SampleSShout,    mca[ColorSShout].name);\r
-    SetDlgItemText(hDlg, OPT_SampleChannel1,  mca[ColorChannel1].name);\r
-    SetDlgItemText(hDlg, OPT_SampleChannel,   mca[ColorChannel].name);\r
-    SetDlgItemText(hDlg, OPT_SampleKibitz,    mca[ColorKibitz].name);\r
-    SetDlgItemText(hDlg, OPT_SampleTell,      mca[ColorTell].name);\r
-    SetDlgItemText(hDlg, OPT_SampleChallenge, mca[ColorChallenge].name);\r
-    SetDlgItemText(hDlg, OPT_SampleRequest,   mca[ColorRequest].name);\r
-    SetDlgItemText(hDlg, OPT_SampleSeek,      mca[ColorSeek].name);\r
-    SetDlgItemText(hDlg, OPT_SampleNormal,    mca[ColorNormal].name);\r
+    SetDlgItemText(hDlg, OPT_SampleShout,     T_(mca[ColorShout].name));\r
+    SetDlgItemText(hDlg, OPT_SampleSShout,    T_(mca[ColorSShout].name));\r
+    SetDlgItemText(hDlg, OPT_SampleChannel1,  T_(mca[ColorChannel1].name));\r
+    SetDlgItemText(hDlg, OPT_SampleChannel,   T_(mca[ColorChannel].name));\r
+    SetDlgItemText(hDlg, OPT_SampleKibitz,    T_(mca[ColorKibitz].name));\r
+    SetDlgItemText(hDlg, OPT_SampleTell,      T_(mca[ColorTell].name));\r
+    SetDlgItemText(hDlg, OPT_SampleChallenge, T_(mca[ColorChallenge].name));\r
+    SetDlgItemText(hDlg, OPT_SampleRequest,   T_(mca[ColorRequest].name));\r
+    SetDlgItemText(hDlg, OPT_SampleSeek,      T_(mca[ColorSeek].name));\r
+    SetDlgItemText(hDlg, OPT_SampleNormal,    T_(mca[ColorNormal].name));\r
 \r
     UpdateSampleText(hDlg, OPT_SampleShout,     &mca[ColorShout]);\r
     UpdateSampleText(hDlg, OPT_SampleSShout,    &mca[ColorSShout]);\r
@@ -981,7 +1291,7 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   case WM_COMMAND: /* message: received a command */\r
     switch (LOWORD(wParam)) {\r
 \r
-    case WM_USER_GetConsoleBackground: \r
+    case WM_USER_GetConsoleBackground:\r
       /* the ColorizeTextDialog needs the current background color */\r
       colorref = (COLORREF *)lParam;\r
       *colorref = cbc;\r
@@ -991,8 +1301,8 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       /* Read changed options from the dialog box */\r
       GetDlgItemText(hDlg, OPT_IcsAlarmTime, buf, MSG_SIZ);\r
       if (sscanf(buf, "%d", &number) != 1 || (number < 0)){\r
-         MessageBox(hDlg, "Invalid ICS Alarm Time",\r
-                    "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
+         MessageBox(hDlg, _("Invalid ICS Alarm Time"),\r
+                    _("Option Error"), MB_OK|MB_ICONEXCLAMATION);\r
          return FALSE;\r
       }\r
 \r
@@ -1002,17 +1312,26 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       appData.premove          = IS_CHECKED(OPT_Premove);\r
       appData.premoveWhite     = IS_CHECKED(OPT_PremoveWhite);\r
       appData.premoveBlack     = IS_CHECKED(OPT_PremoveBlack);\r
+      appData.autoKibitz       = IS_CHECKED(OPT_AutoKibitz);\r
       appData.autoComment      = IS_CHECKED(OPT_AutoComment);\r
       appData.autoObserve      = IS_CHECKED(OPT_AutoObserve);\r
+      appData.autoCreateLogon  = IS_CHECKED(OPT_AutoCreate);\r
       appData.getMoveList      = IS_CHECKED(OPT_GetMoveList);\r
       appData.localLineEditing = IS_CHECKED(OPT_LocalLineEditing);\r
       appData.quietPlay        = IS_CHECKED(OPT_QuietPlay);\r
+      appData.seekGraph        = IS_CHECKED(OPT_SeekGraph);\r
+      appData.autoRefresh      = IS_CHECKED(OPT_AutoRefresh);\r
+      appData.bgObserve        = IS_CHECKED(OPT_BgObserve);\r
+      appData.dualBoard        = IS_CHECKED(OPT_DualBoard);\r
+      appData.oneClick         = IS_CHECKED(OPT_SmartMove);\r
 \r
 #undef IS_CHECKED\r
 \r
       appData.icsAlarmTime = number * 1000;\r
       GetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText, 5);\r
       GetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText, 5);\r
+      GetDlgItemText(hDlg, OPT_StartupChatBoxes, buf, sizeof(buf));\r
+      buf[sizeof(buf)-1] = NULLCHAR; appData.chatBoxes = StrSave(buf); // memory leak\r
 \r
       if (appData.localLineEditing) {\r
        DontEcho();\r
@@ -1025,7 +1344,9 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       appData.colorize =\r
        (Boolean)!IsDlgButtonChecked(hDlg, OPT_DontColorize);\r
 \r
-      if (!appData.colorize) {\r
+    ChangedConsoleFont();\r
+\r
+    if (!appData.colorize) {\r
        CHARFORMAT cf;\r
        COLORREF background = ParseColorName(COLOR_BKGD);\r
        /*\r
@@ -1036,20 +1357,20 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        cf.dwMask = CFM_COLOR;\r
        cf.crTextColor = ParseColorName(COLOR_NORMAL);\r
 \r
-       SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, \r
+       SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,\r
          EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);\r
-        SendDlgItemMessage(hwndConsole, OPT_ConsoleText, \r
+        SendDlgItemMessage(hwndConsole, OPT_ConsoleText,\r
          EM_SETBKGNDCOLOR, FALSE, background);\r
-       SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, \r
+       SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,\r
          EM_SETBKGNDCOLOR, FALSE, background);\r
       }\r
 \r
       if (cbc != consoleBackgroundColor) {\r
        consoleBackgroundColor = cbc;\r
        if (appData.colorize) {\r
-         SendDlgItemMessage(hwndConsole, OPT_ConsoleText, \r
+         SendDlgItemMessage(hwndConsole, OPT_ConsoleText,\r
            EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);\r
-         SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, \r
+         SendDlgItemMessage(hwndConsole, OPT_ConsoleInput,\r
            EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor);\r
        }\r
       }\r
@@ -1078,7 +1399,7 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 \r
     case OPT_ChooseChannel1Color:\r
       ColorizeTextPopup(hDlg, ColorChannel1);\r
-      UpdateSampleText(hDlg, OPT_SampleChannel1, \r
+      UpdateSampleText(hDlg, OPT_SampleChannel1,\r
                       &colorizeAttribs[ColorChannel1]);\r
       break;\r
 \r
@@ -1112,6 +1433,9 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]);\r
       break;\r
 \r
+\r
+\r
+\r
     case OPT_ChooseNormalColor:\r
       ColorizeTextPopup(hDlg, ColorNormal);\r
       UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]);\r
@@ -1134,7 +1458,7 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 \r
     case OPT_DefaultColors:\r
       for (i=0; i < NColorClasses - 1; i++)\r
-       ParseAttribs(&mca[i].color, \r
+       ParseAttribs(&mca[i].color,\r
                     &mca[i].effects,\r
                     defaultTextAttribs[i]);\r
 \r
@@ -1186,6 +1510,8 @@ IcsOptionsPopup(HWND hwnd)
  *\r
 \*---------------------------------------------------------------------------*/\r
 \r
+char *string; // sorry\r
+\r
 VOID\r
 SetSampleFontText(HWND hwnd, int id, const MyFont *mf)\r
 {\r
@@ -1199,21 +1525,23 @@ SetSampleFontText(HWND hwnd, int id, const MyFont *mf)
   POINT center;\r
   int len;\r
 \r
-  len = sprintf(buf, "%.0f pt. %s%s%s\n",\r
-               mf->mfp.pointSize, mf->mfp.faceName,\r
-               mf->mfp.bold ? " bold" : "",\r
-               mf->mfp.italic ? " italic" : "");\r
+  len = snprintf(buf, MSG_SIZ, "%.0f pt. %s%s%s\n",\r
+                mf->mfp.pointSize, mf->mfp.faceName,\r
+                mf->mfp.bold ? " bold" : "",\r
+                mf->mfp.italic ? " italic" : "");\r
+ if(id != OPT_SamplePieceFont)\r
   SetDlgItemText(hwnd, id, buf);\r
+ else SetDlgItemText(hwnd, id, string);\r
 \r
   hControl = GetDlgItem(hwnd, id);\r
   hdc = GetDC(hControl);\r
   SetMapMode(hdc, MM_TEXT);    /* 1 pixel == 1 logical unit */\r
   oldFont = SelectObject(hdc, mf->hf);\r
-  \r
+\r
   /* get number of logical units necessary to display font name */\r
   GetTextExtentPoint32(hdc, buf, len, &size);\r
 \r
-  /* calculate formatting rectangle in the rich edit control.  \r
+  /* calculate formatting rectangle in the rich edit control.\r
    * May be larger or smaller than the actual control.\r
    */\r
   GetClientRect(hControl, &rectClient);\r
@@ -1224,27 +1552,12 @@ SetSampleFontText(HWND hwnd, int id, const MyFont *mf)
   rectFormat.left   = center.x - (size.cx / 2) - 1;\r
   rectFormat.right  = center.x + (size.cx / 2) + 1;\r
 \r
-#if 0\r
-  fprintf(debugFP, "\nfont: %s\n"\r
-                   "center.x   %d, centerY %d\n"\r
-                  "size.cx    %d, size.cy %d\n"\r
-                  "client.top %d, bottom %d, left %d, right %d\n"\r
-                  "format.top %d, bottom %d, left %d, right %d\n",\r
-                  buf,\r
-                  center.x, center.y,\r
-                  size.cx, size.cy,\r
-                  rectClient.top, rectClient.bottom, rectClient.left,\r
-                  rectClient.right,\r
-                  rectFormat.top, rectFormat.bottom, rectFormat.left,\r
-                  rectFormat.right);\r
-#endif\r
-\r
   cf.cbSize = sizeof(CHARFORMAT);\r
   cf.dwMask = CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_BOLD|CFM_ITALIC;\r
   cf.dwEffects = 0;\r
   if (mf->lf.lfWeight == FW_BOLD) cf.dwEffects |= CFE_BOLD;\r
   if (mf->lf.lfItalic) cf.dwEffects |= CFE_ITALIC;\r
-  strcpy(cf.szFaceName, mf->mfp.faceName);\r
+  safeStrCpy(cf.szFaceName, mf->mfp.faceName, sizeof(cf.szFaceName)/sizeof(cf.szFaceName[0]) );\r
   /*\r
    * yHeight is expressed in twips.  A twip is 1/20 of a font's point\r
    * size. See documentation of CHARFORMAT.  --msw\r
@@ -1255,6 +1568,7 @@ SetSampleFontText(HWND hwnd, int id, const MyFont *mf)
 \r
   /* format the text in the rich edit control */\r
   SendMessage(hControl, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf);\r
+ if(id != OPT_SamplePieceFont)\r
   SendMessage(hControl, EM_SETRECT, (WPARAM)0, (LPARAM) &rectFormat);\r
 \r
   /* clean up */\r
@@ -1270,7 +1584,8 @@ CopyFont(MyFont *dest, const MyFont *src)
   dest->mfp.italic    = src->mfp.italic;\r
   dest->mfp.underline = src->mfp.underline;\r
   dest->mfp.strikeout = src->mfp.strikeout;\r
-  lstrcpy(dest->mfp.faceName, src->mfp.faceName);\r
+  dest->mfp.charset   = src->mfp.charset;\r
+  safeStrCpy(dest->mfp.faceName, src->mfp.faceName, sizeof(dest->mfp.faceName)/sizeof(dest->mfp.faceName[0]) );\r
   CreateFontInMF(dest);\r
 }\r
 \r
@@ -1278,8 +1593,9 @@ CopyFont(MyFont *dest, const MyFont *src)
 LRESULT CALLBACK\r
 FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
 {\r
-  static MyFont workFont[NUM_FONTS];\r
+  static MyFont workFont[NUM_FONTS+1];\r
   static BOOL firstPaint;\r
+  static char pieceText[] = "ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";\r
   int i;\r
   RECT rect;\r
 \r
@@ -1289,7 +1605,11 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     /* copy the current font settings into a working copy */\r
     for (i=0; i < NUM_FONTS; i++)\r
       CopyFont(&workFont[i], font[boardSize][i]);\r
+    strncpy(workFont[NUM_FONTS].mfp.faceName, appData.renderPiecesWithFont, sizeof(workFont[NUM_FONTS].mfp.faceName));\r
+    workFont[NUM_FONTS].mfp.pointSize = 16.;\r
+    workFont[NUM_FONTS].mfp.charset = DEFAULT_CHARSET;\r
 \r
+    Translate(hDlg, DLG_Fonts);\r
     if (!appData.icsActive)\r
       EnableWindow(GetDlgItem(hDlg, OPT_ChooseConsoleFont), FALSE);\r
 \r
@@ -1315,6 +1635,10 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);\r
       SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);\r
       SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);\r
+      SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);\r
+      SetSampleFontText(hDlg, OPT_SampleGameListFont, &workFont[GAMELIST_FONT]);\r
+      string = appData.fontToPieceTable;\r
+      SetSampleFontText(hDlg, OPT_SamplePieceFont, &workFont[NUM_FONTS]);\r
       firstPaint = FALSE;\r
     }\r
     break;\r
@@ -1330,6 +1654,13 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       for (i=0; i < NUM_FONTS; i++)\r
        CopyFont(font[boardSize][i], &workFont[i]);\r
 \r
+      { // Make new piece-to-char table\r
+       char buf[MSG_SIZ];\r
+       GetDlgItemText(hDlg, OPT_SamplePieceFont, buf, MSG_SIZ);\r
+       ASSIGN(appData.fontToPieceTable, buf);\r
+      }\r
+      ASSIGN(appData.renderPiecesWithFont, workFont[NUM_FONTS].mfp.faceName); // piece font\r
+\r
       /* a sad necessity due to the original design of having a separate\r
        * console font, tags font, and comment font for each board size.  IMHO\r
        * these fonts should not be dependent on the current board size.  I'm\r
@@ -1342,6 +1673,8 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        CopyFont(font[i][EDITTAGS_FONT], &workFont[EDITTAGS_FONT]);\r
        CopyFont(font[i][CONSOLE_FONT],  &workFont[CONSOLE_FONT]);\r
        CopyFont(font[i][COMMENT_FONT],  &workFont[COMMENT_FONT]);\r
+       CopyFont(font[i][MOVEHISTORY_FONT],  &workFont[MOVEHISTORY_FONT]);\r
+       CopyFont(font[i][GAMELIST_FONT],  &workFont[GAMELIST_FONT]);\r
       }\r
       /* end sad necessity */\r
 \r
@@ -1350,7 +1683,7 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 \r
       if (commentDialog) {\r
        SendDlgItemMessage(commentDialog, OPT_CommentText,\r
-         WM_SETFONT, (WPARAM)font[boardSize][COMMENT_FONT]->hf, \r
+         WM_SETFONT, (WPARAM)font[boardSize][COMMENT_FONT]->hf,\r
          MAKELPARAM(TRUE, 0));\r
        GetClientRect(GetDlgItem(commentDialog, OPT_CommentText), &rect);\r
        InvalidateRect(commentDialog, &rect, TRUE);\r
@@ -1358,12 +1691,29 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 \r
       if (editTagsDialog) {\r
        SendDlgItemMessage(editTagsDialog, OPT_TagsText,\r
-         WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf, \r
+         WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf,\r
          MAKELPARAM(TRUE, 0));\r
        GetClientRect(GetDlgItem(editTagsDialog, OPT_TagsText), &rect);\r
        InvalidateRect(editTagsDialog, &rect, TRUE);\r
       }\r
 \r
+      if( moveHistoryDialog != NULL ) {\r
+       SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory,\r
+         WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,\r
+         MAKELPARAM(TRUE, 0));\r
+        SendMessage( moveHistoryDialog, WM_INITDIALOG, 0, 0 );\r
+//     InvalidateRect(editTagsDialog, NULL, TRUE); // [HGM] this ws improperly cloned?\r
+      }\r
+\r
+      if( engineOutputDialog != NULL ) {\r
+       SendDlgItemMessage(engineOutputDialog, IDC_EngineMemo1,\r
+         WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,\r
+         MAKELPARAM(TRUE, 0));\r
+       SendDlgItemMessage(engineOutputDialog, IDC_EngineMemo2,\r
+         WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf,\r
+         MAKELPARAM(TRUE, 0));\r
+      }\r
+\r
       if (hwndConsole) {\r
        ChangedConsoleFont();\r
       }\r
@@ -1409,6 +1759,22 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);\r
       break;\r
 \r
+    case OPT_ChooseMoveHistoryFont:\r
+      MyCreateFont(hDlg, &workFont[MOVEHISTORY_FONT]);\r
+      SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);\r
+      break;\r
+\r
+    case OPT_ChooseGameListFont:\r
+      MyCreateFont(hDlg, &workFont[GAMELIST_FONT]);\r
+      SetSampleFontText(hDlg, OPT_SampleGameListFont, &workFont[GAMELIST_FONT]);\r
+      break;\r
+\r
+    case OPT_ChoosePieceFont:\r
+      MyCreateFont(hDlg, &workFont[NUM_FONTS]);\r
+      string = pieceText;\r
+      SetSampleFontText(hDlg, OPT_SamplePieceFont, &workFont[NUM_FONTS]);\r
+      break;\r
+\r
     case OPT_DefaultFonts:\r
       for (i=0; i<NUM_FONTS; i++) {\r
        DeleteObject(&workFont[i].hf);\r
@@ -1421,6 +1787,8 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]);\r
       SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]);\r
       SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]);\r
+      SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]);\r
+      SetSampleFontText(hDlg, OPT_SampleGameListFont, &workFont[GAMELIST_FONT]);\r
       break;\r
     }\r
   }\r
@@ -1444,22 +1812,23 @@ FontsOptionsPopup(HWND hwnd)
 \r
 \r
 SoundComboData soundComboData[] = {\r
-  {"Move", NULL},\r
-  {"Bell", NULL},\r
-  {"ICS Alarm", NULL},\r
-  {"ICS Win", NULL},\r
-  {"ICS Loss", NULL},\r
-  {"ICS Draw", NULL},\r
-  {"ICS Unfinished", NULL},\r
-  {"Shout", NULL},\r
-  {"SShout/CShout", NULL},\r
-  {"Channel 1", NULL},\r
-  {"Channel", NULL},\r
-  {"Kibitz", NULL},\r
-  {"Tell", NULL},\r
-  {"Challenge", NULL},\r
-  {"Request", NULL},\r
-  {"Seek", NULL},\r
+  {N_("Move"), NULL},\r
+  {N_("Bell"), NULL},\r
+  {N_("Roar"), NULL},\r
+  {N_("ICS Alarm"), NULL},\r
+  {N_("ICS Win"), NULL},\r
+  {N_("ICS Loss"), NULL},\r
+  {N_("ICS Draw"), NULL},\r
+  {N_("ICS Unfinished"), NULL},\r
+  {N_("Shout"), NULL},\r
+  {N_("SShout/CShout"), NULL},\r
+  {N_("Channel 1"), NULL},\r
+  {N_("Channel"), NULL},\r
+  {N_("Kibitz"), NULL},\r
+  {N_("Tell"), NULL},\r
+  {N_("Challenge"), NULL},\r
+  {N_("Request"), NULL},\r
+  {N_("Seek"), NULL},\r
   {NULL, NULL},\r
 };\r
 \r
@@ -1505,10 +1874,10 @@ InitSoundCombo(HWND hwndCombo, SoundComboData *scd)
 \r
   /* send the labels to the combo box */\r
   while (scd->label) {\r
-    err = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) scd->label);\r
+    err = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) T_(scd->label));\r
     if (err != cnt++) {\r
-      sprintf(buf, "InitSoundCombo(): err '%d', cnt '%d'\n",\r
-         err, cnt);\r
+      snprintf(buf, MSG_SIZ,  "InitSoundCombo(): err '%d', cnt '%d'\n",\r
+         (int)err, (int)cnt);\r
       MessageBox(NULL, buf, NULL, MB_OK);\r
     }\r
     scd++;\r
@@ -1568,7 +1937,7 @@ void
 DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name)\r
 {\r
   int radio;\r
-  /* \r
+  /*\r
    * I think it's best to clear the combo and edit boxes. It looks stupid\r
    * to have a value from another sound event sitting there grayed out.\r
    */\r
@@ -1594,7 +1963,7 @@ DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name)
       radio = OPT_NoSound;\r
     } else {\r
       radio = OPT_BuiltInSound;\r
-      if (SendMessage(hCombo, CB_SELECTSTRING, (WPARAM) -1, \r
+      if (SendMessage(hCombo, CB_SELECTSTRING, (WPARAM) -1,\r
                      (LPARAM) (name + 1)) == CB_ERR) {\r
        SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);\r
        SendMessage(hCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) (name + 1));\r
@@ -1609,7 +1978,7 @@ DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name)
   SoundDialogSetEnables(hDlg, radio);\r
   CheckRadioButton(hDlg, OPT_NoSound, OPT_WavFile, radio);\r
 }\r
-    \r
+\r
 \r
 char *builtInSoundNames[] = BUILT_IN_SOUND_NAMES;\r
 \r
@@ -1627,11 +1996,13 @@ SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   SoundClass sc;\r
   ColorClass cc;\r
   SoundComboData *scd;\r
+  int oldMute;\r
 \r
   switch (message) {\r
   case WM_INITDIALOG:\r
     /* Center the dialog over the application window */\r
     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_Sound);\r
 \r
     /* Initialize the built-in sounds combo */\r
     hBISN = GetDlgItem(hDlg, OPT_BuiltInSoundName);\r
@@ -1649,16 +2020,16 @@ SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 \r
   case WM_COMMAND: /* message: received a command */\r
 \r
-    if (((HWND)lParam == hSoundCombo) && \r
+    if (((HWND)lParam == hSoundCombo) &&\r
        (HIWORD(wParam) == CBN_SELCHANGE)) {\r
-      /* \r
+      /*\r
        * the user has selected a new sound event. We must store the name for\r
        * the previously selected event, then retrieve the name for the\r
-       * newly selected event and update the dialog. \r
+       * newly selected event and update the dialog.\r
        */\r
       radio = SoundDialogWhichRadio(hDlg);\r
       newName = strdup(SoundDialogGetName(hDlg, radio));\r
-      \r
+\r
       if (strcmp(newName, soundComboData[index].name) != 0) {\r
        free(soundComboData[index].name);\r
        soundComboData[index].name = newName;\r
@@ -1669,13 +2040,13 @@ SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       /* now get the settings for the newly selected event */\r
       index = SendMessage(hSoundCombo, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);\r
       DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name);\r
-      \r
+\r
       return TRUE;\r
     }\r
     switch (LOWORD(wParam)) {\r
     case IDOK:\r
-      /* \r
-       * save the name for the currently selected sound event \r
+      /*\r
+       * save the name for the currently selected sound event\r
        */\r
       radio = SoundDialogWhichRadio(hDlg);\r
       newName = strdup(SoundDialogGetName(hDlg, radio));\r
@@ -1699,7 +2070,7 @@ SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       }\r
       for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) {\r
        index = (int)cc + (int)NSoundClasses;\r
-       if (strcmp(soundComboData[index].name, \r
+       if (strcmp(soundComboData[index].name,\r
                   textAttribs[cc].sound.name) != 0) {\r
          free(textAttribs[cc].sound.name);\r
          textAttribs[cc].sound.name = strdup(soundComboData[index].name);\r
@@ -1707,6 +2078,8 @@ SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        }\r
       }\r
 \r
+       mute = FALSE; // [HGM] mute: switch sounds automatically on if we select one\r
+      CheckMenuItem(GetMenu(hwndMain),IDM_MuteSounds,MF_BYCOMMAND|MF_UNCHECKED);\r
       ResetSoundComboData(soundComboData);\r
       EndDialog(hDlg, TRUE);\r
       return TRUE;\r
@@ -1736,14 +2109,16 @@ SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       tmp.name = strdup(SoundDialogGetName(hDlg, radio));\r
       tmp.data = NULL;\r
       MyLoadSound(&tmp);\r
+       oldMute = mute; mute = FALSE; // [HGM] mute: always sound when user presses play, ignorig mute setting\r
       MyPlaySound(&tmp);\r
-      if (tmp.data  != NULL) free(tmp.data);\r
+       mute = oldMute;\r
+      if (tmp.data  != NULL) FreeResource(tmp.data); // technically obsolete fn, but tmp.data is NOT malloc'd mem\r
       if (tmp.name != NULL) free(tmp.name);\r
       return TRUE;\r
 \r
     case OPT_BrowseSound:\r
-      f = OpenFileDialog(hDlg, FALSE, NULL, "wav", SOUND_FILT,\r
-       "Browse for Sound File", NULL, NULL, buf);\r
+      f = OpenFileDialog(hDlg, "rb", NULL, "wav", SOUND_FILT,\r
+       _("Browse for Sound File"), NULL, NULL, buf);\r
       if (f != NULL) {\r
        fclose(f);\r
        SetDlgItemText(hDlg, OPT_WavFileName, buf);\r
@@ -1868,7 +2243,7 @@ ParseCommSettings(char *arg, DCB *dcb)
   if (cd->label == NULL) goto cant_parse;\r
   return;\r
 cant_parse:\r
-    ExitArgError("Can't parse com port settings", arg);\r
+    ExitArgError(_("Can't parse com port settings"), arg, TRUE);\r
 }\r
 \r
 \r
@@ -1876,7 +2251,7 @@ VOID PrintCommSettings(FILE *f, char *name, DCB *dcb)
 {\r
   char *flow = "??", *parity = "??", *stopBits = "??";\r
   ComboData *cd;\r
-  \r
+\r
   cd = cdParity;\r
   while (cd->label != NULL) {\r
     if (dcb->Parity == cd->value) {\r
@@ -1903,7 +2278,7 @@ VOID PrintCommSettings(FILE *f, char *name, DCB *dcb)
     flow = cdFlow[FLOW_NONE].label;\r
   }\r
   fprintf(f, "/%s=%d,%d,%s,%s,%s\n", name,\r
-    dcb->BaudRate, dcb->ByteSize, parity, stopBits, flow);\r
+    (int)dcb->BaudRate, dcb->ByteSize, parity, stopBits, flow);\r
 }\r
 \r
 \r
@@ -1948,6 +2323,7 @@ CommPortOptionsDialog(HWND hDlg, UINT message, WPARAM wParam,     LPARAM lParam)
   case WM_INITDIALOG: /* message: initialize dialog box */\r
     /* Center the dialog over the application window */\r
     CenterWindow (hDlg, GetWindow(hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_CommPort);\r
     /* Initialize the dialog items */\r
     /* !! There should probably be some synchronization\r
        in accessing hCommPort and dcb.  Or does modal nature\r
@@ -1965,7 +2341,7 @@ CommPortOptionsDialog(HWND hDlg, UINT message, WPARAM wParam,     LPARAM lParam)
 \r
     hwndCombo = GetDlgItem(hDlg, OPT_DataRate);\r
     InitCombo(hwndCombo, cdDataRate);\r
-    sprintf(buf, "%u", dcb.BaudRate);\r
+    snprintf(buf, MSG_SIZ, "%u", (int)dcb.BaudRate);\r
     if (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) buf) == CB_ERR) {\r
       SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);\r
       SendMessage(hwndCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) buf);\r
@@ -2027,8 +2403,8 @@ CommPortOptionsDialog(HWND hDlg, UINT message, WPARAM wParam,     LPARAM lParam)
       hwndCombo = GetDlgItem(hDlg, OPT_DataRate);\r
       SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf);\r
       if (sscanf(buf, "%u", &value) != 1) {\r
-       MessageBox(hDlg, "Invalid data rate",\r
-                  "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
+       MessageBox(hDlg, _("Invalid data rate"),\r
+                  _("Option Error"), MB_OK|MB_ICONEXCLAMATION);\r
        return TRUE;\r
       }\r
       dcb.BaudRate = value;\r
@@ -2071,11 +2447,11 @@ CommPortOptionsDialog(HWND hDlg, UINT message, WPARAM wParam,   LPARAM lParam)
       }\r
       if (!SetCommState(hCommPort, (LPDCB) &dcb)) {\r
        err = GetLastError();\r
-       switch(MessageBox(hDlg, \r
+       switch(MessageBox(hDlg,\r
                         "Failed to set comm port state;\r\ninvalid options?",\r
-                        "Option Error", MB_ABORTRETRYIGNORE|MB_ICONQUESTION)) {\r
+                        _("Option Error"), MB_ABORTRETRYIGNORE|MB_ICONQUESTION)) {\r
        case IDABORT:\r
-         DisplayFatalError("Failed to set comm port state", err, 1);\r
+         DisplayFatalError(_("Failed to set comm port state"), err, 1);\r
          exit(1);  /*is it ok to do this from here?*/\r
 \r
        case IDRETRY:\r
@@ -2116,6 +2492,17 @@ CommPortOptionsPopup(HWND hwnd)
  *\r
 \*---------------------------------------------------------------------------*/\r
 \r
+int\r
+LoadOptionsWhichRadio(HWND hDlg)\r
+{\r
+  return (IsDlgButtonChecked(hDlg, OPT_Exact) ? 1 :\r
+         (IsDlgButtonChecked(hDlg, OPT_Subset) ? 2 :\r
+         (IsDlgButtonChecked(hDlg, OPT_Struct) ? 3 :\r
+         (IsDlgButtonChecked(hDlg, OPT_Material) ? 4 :\r
+         (IsDlgButtonChecked(hDlg, OPT_Range) ? 5 :\r
+         (IsDlgButtonChecked(hDlg, OPT_Difference) ? 6 : -1))))));\r
+}\r
+\r
 VOID\r
 SetLoadOptionEnables(HWND hDlg)\r
 {\r
@@ -2131,20 +2518,49 @@ LoadOptions(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 {\r
   char buf[MSG_SIZ];\r
   float fnumber;\r
+  int ok;\r
 \r
   switch (message) {\r
   case WM_INITDIALOG: /* message: initialize dialog box */\r
     /* Center the dialog over the application window */\r
     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_LoadOptions);\r
     /* Initialize the dialog items */\r
     if (appData.timeDelay >= 0.0) {\r
       CheckDlgButton(hDlg, OPT_Autostep, TRUE);\r
-      sprintf(buf, "%.2g", appData.timeDelay);\r
+      snprintf(buf, MSG_SIZ, "%.2g", appData.timeDelay);\r
       SetDlgItemText(hDlg, OPT_ASTimeDelay, buf);\r
     } else {\r
       CheckDlgButton(hDlg, OPT_Autostep, FALSE);\r
     }\r
     SetLoadOptionEnables(hDlg);\r
+    SetDlgItemInt(hDlg, OPT_elo1, appData.eloThreshold1, FALSE);\r
+    SetDlgItemInt(hDlg, OPT_elo2, appData.eloThreshold2, FALSE);\r
+    SetDlgItemInt(hDlg, OPT_date, appData.dateThreshold, FALSE);\r
+    SetDlgItemInt(hDlg, OPT_Stretch, appData.stretch, FALSE);\r
+    CheckDlgButton(hDlg, OPT_Reversed, appData.ignoreColors);\r
+    CheckDlgButton(hDlg, OPT_Mirror, appData.findMirror);\r
+    SetDlgItemText(hDlg, OPT_Counts,  "");\r
+    switch (appData.searchMode) {\r
+    case 1:\r
+      CheckDlgButton(hDlg, OPT_Exact, TRUE);\r
+      break;\r
+    case 2:\r
+      CheckDlgButton(hDlg, OPT_Subset, TRUE);\r
+      break;\r
+    case 3:\r
+      CheckDlgButton(hDlg, OPT_Struct, TRUE);\r
+      break;\r
+    case 4:\r
+      CheckDlgButton(hDlg, OPT_Material, TRUE);\r
+      break;\r
+    case 5:\r
+      CheckDlgButton(hDlg, OPT_Range, TRUE);\r
+      break;\r
+    case 6:\r
+      CheckDlgButton(hDlg, OPT_Difference, TRUE);\r
+      break;\r
+    }\r
     return TRUE;\r
 \r
   case WM_COMMAND: /* message: received a command */\r
@@ -2154,14 +2570,25 @@ LoadOptions(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       if (IsDlgButtonChecked(hDlg, OPT_Autostep)) {\r
        GetDlgItemText(hDlg, OPT_ASTimeDelay, buf, MSG_SIZ);\r
        if (sscanf(buf, "%f", &fnumber) != 1) {\r
-         MessageBox(hDlg, "Invalid load game step rate",\r
-                    "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
+         MessageBox(hDlg, _("Invalid load game step rate"),\r
+                    _("Option Error"), MB_OK|MB_ICONEXCLAMATION);\r
          return FALSE;\r
        }\r
        appData.timeDelay = fnumber;\r
       } else {\r
        appData.timeDelay = (float) -1.0;\r
       }\r
+      appData.eloThreshold1 = GetDlgItemInt(hDlg, OPT_elo1, &ok, FALSE);\r
+      appData.eloThreshold2 = GetDlgItemInt(hDlg, OPT_elo2, &ok, FALSE);\r
+      appData.dateThreshold = GetDlgItemInt(hDlg, OPT_date, &ok, FALSE);\r
+      appData.stretch = GetDlgItemInt(hDlg, OPT_Stretch, &ok, FALSE);\r
+      appData.searchMode = LoadOptionsWhichRadio(hDlg);\r
+      appData.ignoreColors = IsDlgButtonChecked(hDlg, OPT_Reversed);\r
+      appData.findMirror   = IsDlgButtonChecked(hDlg, OPT_Mirror);\r
+      GetDlgItemText(hDlg, OPT_Counts, buf, MSG_SIZ);\r
+      appData.minPieces = appData.maxPieces = 0;\r
+      sscanf(buf, "%d-%d", &appData.minPieces, &appData.maxPieces);\r
+      if(appData.maxPieces < appData.minPieces) appData.maxPieces = appData.minPieces;\r
       EndDialog(hDlg, TRUE);\r
       return TRUE;\r
 \r
@@ -2179,7 +2606,7 @@ LoadOptions(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 }\r
 \r
 \r
-VOID \r
+VOID\r
 LoadOptionsPopup(HWND hwnd)\r
 {\r
   FARPROC lpProc = MakeProcInstance((FARPROC)LoadOptions, hInst);\r
@@ -2221,6 +2648,7 @@ SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   case WM_INITDIALOG: /* message: initialize dialog box */\r
     /* Center the dialog over the application window */\r
     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_SaveOptions);\r
     /* Initialize the dialog items */\r
     if (*appData.saveGameFile != NULLCHAR) {\r
       CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE);\r
@@ -2237,6 +2665,7 @@ SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     } else {\r
       CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_PGN);\r
     }\r
+    CheckDlgButton( hDlg, OPT_OutOfBookInfo, appData.saveOutOfBookInfo );\r
     SetSaveOptionEnables(hDlg);\r
     return TRUE;\r
 \r
@@ -2247,35 +2676,23 @@ SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       if (IsDlgButtonChecked(hDlg, OPT_Autosave)) {\r
        appData.autoSaveGames = TRUE;\r
        if (IsDlgButtonChecked(hDlg, OPT_AVPrompt)) {\r
-         appData.saveGameFile = "";\r
+         ASSIGN(appData.saveGameFile, ""); // [HGM] make sure value is ALWAYS in allocated memory\r
        } else /*if (IsDlgButtonChecked(hDlg, OPT_AVToFile))*/ {\r
          GetDlgItemText(hDlg, OPT_AVFilename, buf, MSG_SIZ);\r
          if (*buf == NULLCHAR) {\r
-           MessageBox(hDlg, "Invalid save game file name",\r
-                      "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
+           MessageBox(hDlg, _("Invalid save game file name"),\r
+                      _("Option Error"), MB_OK|MB_ICONEXCLAMATION);\r
            return FALSE;\r
          }\r
-         if ((isalpha(buf[0]) && buf[1] == ':') ||\r
-           (buf[0] == '\\' && buf[1] == '\\')) {\r
-           appData.saveGameFile = strdup(buf);\r
-         } else {\r
-           char buf2[MSG_SIZ], buf3[MSG_SIZ];\r
-           char *dummy;\r
-           GetCurrentDirectory(MSG_SIZ, buf3);\r
-           SetCurrentDirectory(installDir);\r
-           if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {\r
-             appData.saveGameFile = strdup(buf2);\r
-           } else {\r
-             appData.saveGameFile = strdup(buf);\r
-           }\r
-           SetCurrentDirectory(buf3);\r
-         }\r
+         FREE(appData.saveGameFile);\r
+         appData.saveGameFile = InterpretFileName(buf, homeDir);\r
        }\r
       } else {\r
        appData.autoSaveGames = FALSE;\r
-       appData.saveGameFile = "";\r
+       ASSIGN(appData.saveGameFile, "");\r
       }\r
       appData.oldSaveStyle = IsDlgButtonChecked(hDlg, OPT_Old);\r
+      appData.saveOutOfBookInfo = IsDlgButtonChecked( hDlg, OPT_OutOfBookInfo );\r
       EndDialog(hDlg, TRUE);\r
       return TRUE;\r
 \r
@@ -2284,9 +2701,9 @@ SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       return TRUE;\r
 \r
     case OPT_AVBrowse:\r
-      f = OpenFileDialog(hDlg, TRUE, NULL, \r
-                        appData.oldSaveStyle ? "gam" : "pgn", \r
-                        GAME_FILT, "Browse for Auto Save File", \r
+      f = OpenFileDialog(hDlg, "a", NULL,\r
+                        appData.oldSaveStyle ? "gam" : "pgn",\r
+                        GAME_FILT, _("Browse for Auto Save File"),\r
                         NULL, NULL, buf);\r
       if (f != NULL) {\r
        fclose(f);\r
@@ -2322,34 +2739,44 @@ SetTimeControlEnables(HWND hDlg)
 {\r
   UINT state;\r
 \r
-  state = IsDlgButtonChecked(hDlg, OPT_TCUseMoves);\r
-  EnableWindow(GetDlgItem(hDlg, OPT_TCTime), state);\r
-  EnableWindow(GetDlgItem(hDlg, OPT_TCMoves), state);\r
-  EnableWindow(GetDlgItem(hDlg, OPT_TCtext1), state);\r
-  EnableWindow(GetDlgItem(hDlg, OPT_TCtext2), state);\r
+  state = IsDlgButtonChecked(hDlg, OPT_TCUseMoves)\r
+       + 2*IsDlgButtonChecked(hDlg, OPT_TCUseFixed);\r
+  EnableWindow(GetDlgItem(hDlg, OPT_TCTime), state == 1);\r
+  EnableWindow(GetDlgItem(hDlg, OPT_TCMoves), state == 1);\r
+  EnableWindow(GetDlgItem(hDlg, OPT_TCtext1), state == 1);\r
+  EnableWindow(GetDlgItem(hDlg, OPT_TCtext2), state == 1);\r
   EnableWindow(GetDlgItem(hDlg, OPT_TCTime2), !state);\r
   EnableWindow(GetDlgItem(hDlg, OPT_TCInc), !state);\r
   EnableWindow(GetDlgItem(hDlg, OPT_TCitext1), !state);\r
   EnableWindow(GetDlgItem(hDlg, OPT_TCitext2), !state);\r
   EnableWindow(GetDlgItem(hDlg, OPT_TCitext3), !state);\r
+  EnableWindow(GetDlgItem(hDlg, OPT_TCFixed), state == 2);\r
+  EnableWindow(GetDlgItem(hDlg, OPT_TCftext), state == 2);\r
 }\r
 \r
 \r
 LRESULT CALLBACK\r
 TimeControl(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
 {\r
-  char buf[MSG_SIZ];\r
-  int mps, increment;\r
-  BOOL ok;\r
+  char buf[MSG_SIZ], *tc;\r
+  int mps, odds1, odds2, st;\r
+  float increment;\r
+  BOOL ok, ok2;\r
 \r
   switch (message) {\r
   case WM_INITDIALOG: /* message: initialize dialog box */\r
     /* Center the dialog over the application window */\r
     CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_TimeControl);\r
     /* Initialize the dialog items */\r
-    if (appData.clockMode && !appData.icsActive) {\r
+    if (/*appData.clockMode &&*/ !appData.icsActive) { // [HGM] even if !clockMode, we could want to set it in tournament dialog\r
+      if (searchTime) {\r
+       CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseFixed,\r
+                        OPT_TCUseFixed);\r
+       SetDlgItemInt(hDlg, OPT_TCFixed, searchTime, FALSE);\r
+      } else\r
       if (appData.timeIncrement == -1) {\r
-       CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,\r
+       CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseFixed,\r
                         OPT_TCUseMoves);\r
        SetDlgItemText(hDlg, OPT_TCTime, appData.timeControl);\r
        SetDlgItemInt(hDlg, OPT_TCMoves, appData.movesPerSession,\r
@@ -2357,13 +2784,18 @@ TimeControl(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        SetDlgItemText(hDlg, OPT_TCTime2, "");\r
        SetDlgItemText(hDlg, OPT_TCInc, "");\r
       } else {\r
-       CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc,\r
+       int i = appData.timeIncrement;\r
+       if(i == appData.timeIncrement) snprintf(buf, MSG_SIZ, "%d", i);\r
+       else snprintf(buf, MSG_SIZ, "%4.2f", appData.timeIncrement);\r
+       CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseFixed,\r
                         OPT_TCUseInc);\r
        SetDlgItemText(hDlg, OPT_TCTime, "");\r
        SetDlgItemText(hDlg, OPT_TCMoves, "");\r
        SetDlgItemText(hDlg, OPT_TCTime2, appData.timeControl);\r
-       SetDlgItemInt(hDlg, OPT_TCInc, appData.timeIncrement, FALSE);\r
+       SetDlgItemText(hDlg, OPT_TCInc, buf);\r
       }\r
+      SetDlgItemInt(hDlg, OPT_TCOdds1, 1, FALSE);\r
+      SetDlgItemInt(hDlg, OPT_TCOdds2, 1, FALSE);\r
       SetTimeControlEnables(hDlg);\r
     }\r
     return TRUE;\r
@@ -2371,39 +2803,63 @@ TimeControl(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   case WM_COMMAND: /* message: received a command */\r
     switch (LOWORD(wParam)) {\r
     case IDOK:\r
+      mps = appData.movesPerSession;\r
+      increment = appData.timeIncrement;\r
+      tc = appData.timeControl;\r
+      st = 0;\r
       /* Read changed options from the dialog box */\r
+      if (IsDlgButtonChecked(hDlg, OPT_TCUseFixed)) {\r
+       st = GetDlgItemInt(hDlg, OPT_TCFixed, &ok, FALSE);\r
+       if (!ok || st <= 0) {\r
+         MessageBox(hDlg, _("Invalid max time per move"),\r
+                    _("Option Error"), MB_OK|MB_ICONEXCLAMATION);\r
+         return FALSE;\r
+       }\r
+      } else\r
       if (IsDlgButtonChecked(hDlg, OPT_TCUseMoves)) {\r
        increment = -1;\r
        mps = GetDlgItemInt(hDlg, OPT_TCMoves, &ok, FALSE);\r
        if (!ok || mps <= 0) {\r
-         MessageBox(hDlg, "Invalid moves per time control",\r
-                    "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
+         MessageBox(hDlg, _("Invalid moves per time control"),\r
+                    _("Option Error"), MB_OK|MB_ICONEXCLAMATION);\r
          return FALSE;\r
        }\r
        GetDlgItemText(hDlg, OPT_TCTime, buf, MSG_SIZ);\r
        if (!ParseTimeControl(buf, increment, mps)) {\r
-         MessageBox(hDlg, "Invalid minutes per time control",\r
-                    "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
+         MessageBox(hDlg, _("Invalid minutes per time control"),\r
+                    _("Option Error"), MB_OK|MB_ICONEXCLAMATION);\r
          return FALSE;\r
        }\r
+      tc = buf;\r
       } else {\r
-       increment = GetDlgItemInt(hDlg, OPT_TCInc, &ok, FALSE);\r
-       mps = appData.movesPerSession;\r
+       GetDlgItemText(hDlg, OPT_TCInc, buf, MSG_SIZ);\r
+       ok = (sscanf(buf, "%f%c", &increment, buf) == 1);\r
        if (!ok || increment < 0) {\r
-         MessageBox(hDlg, "Invalid increment",\r
-                    "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
+         MessageBox(hDlg, _("Invalid increment"),\r
+                    _("Option Error"), MB_OK|MB_ICONEXCLAMATION);\r
          return FALSE;\r
        }\r
        GetDlgItemText(hDlg, OPT_TCTime2, buf, MSG_SIZ);\r
        if (!ParseTimeControl(buf, increment, mps)) {\r
-         MessageBox(hDlg, "Invalid initial time",\r
-                    "Option Error", MB_OK|MB_ICONEXCLAMATION);\r
+         MessageBox(hDlg, _("Invalid initial time"),\r
+                    _("Option Error"), MB_OK|MB_ICONEXCLAMATION);\r
          return FALSE;\r
        }\r
+      tc = buf;\r
+      }\r
+      odds1 = GetDlgItemInt(hDlg, OPT_TCOdds1, &ok, FALSE);\r
+      odds2 = GetDlgItemInt(hDlg, OPT_TCOdds2, &ok2, FALSE);\r
+      if (!ok || !ok2 || odds1 <= 0 || odds2 <= 0) {\r
+         MessageBox(hDlg, _("Invalid time-odds factor"),\r
+                    _("Option Error"), MB_OK|MB_ICONEXCLAMATION);\r
+         return FALSE;\r
       }\r
-      appData.timeControl = strdup(buf);\r
+      searchTime = st;\r
+      appData.timeControl = strdup(tc);\r
       appData.movesPerSession = mps;\r
       appData.timeIncrement = increment;\r
+      appData.firstTimeOdds  = first.timeOdds  = odds1;\r
+      appData.secondTimeOdds = second.timeOdds = odds2;\r
       Reset(TRUE, TRUE);\r
       EndDialog(hDlg, TRUE);\r
       return TRUE;\r
@@ -2425,7 +2881,7 @@ VOID
 TimeControlOptionsPopup(HWND hwnd)\r
 {\r
   if (gameMode != BeginningOfGame) {\r
-    DisplayError("Changing time control during a game is not implemented", 0);\r
+    DisplayError(_("Changing time control during a game is not implemented"), 0);\r
   } else {\r
     FARPROC lpProc = MakeProcInstance((FARPROC)TimeControl, hInst);\r
     DialogBox(hInst, MAKEINTRESOURCE(DLG_TimeControl), hwnd, (DLGPROC) lpProc);\r
@@ -2433,4 +2889,317 @@ TimeControlOptionsPopup(HWND hwnd)
   }\r
 }\r
 \r
+/*---------------------------------------------------------------------------*\\r
+ *\r
+ * Engine Options Dialog functions\r
+ *\r
+\*---------------------------------------------------------------------------*/\r
+#define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y))\r
+#define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x))\r
+\r
+#define INT_ABS( n )    ((n) >= 0 ? (n) : -(n))\r
+\r
+LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
+{\r
+  switch (message) {\r
+  case WM_INITDIALOG: /* message: initialize dialog box */\r
+\r
+    /* Center the dialog over the application window */\r
+    CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_EnginePlayOptions);\r
+\r
+    /* Initialize the dialog items */\r
+    CHECK_BOX(IDC_EpPeriodicUpdates, appData.periodicUpdates);\r
+    CHECK_BOX(IDC_EpPonder, appData.ponderNextMove);\r
+    CHECK_BOX(IDC_EpShowThinking, appData.showThinking);\r
+    CHECK_BOX(IDC_EpHideThinkingHuman, appData.hideThinkingFromHuman);\r
+\r
+    CHECK_BOX(IDC_TestClaims, appData.testClaims);\r
+    CHECK_BOX(IDC_DetectMates, appData.checkMates);\r
+    CHECK_BOX(IDC_MaterialDraws, appData.materialDraws);\r
+    CHECK_BOX(IDC_TrivialDraws, appData.trivialDraws);\r
+\r
+    CHECK_BOX(IDC_ScoreAbs1, appData.firstScoreIsAbsolute);\r
+    CHECK_BOX(IDC_ScoreAbs2, appData.secondScoreIsAbsolute);\r
+\r
+    SetDlgItemInt( hDlg, IDC_EpDrawMoveCount, appData.adjudicateDrawMoves, TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_EpDrawMoveCount, EM_SETSEL, 0, -1 );\r
+\r
+    SetDlgItemInt( hDlg, IDC_EpAdjudicationThreshold, INT_ABS(appData.adjudicateLossThreshold), TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_EpAdjudicationThreshold, EM_SETSEL, 0, -1 );\r
+\r
+    SetDlgItemInt( hDlg, IDC_RuleMoves, appData.ruleMoves, TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_RuleMoves, EM_SETSEL, 0, -1 );\r
+\r
+    SetDlgItemInt( hDlg, IDC_DrawRepeats, INT_ABS(appData.drawRepeats), TRUE );\r
+    SendDlgItemMessage( hDlg, IDC_DrawRepeats, EM_SETSEL, 0, -1 );\r
+\r
+    return TRUE;\r
+\r
+  case WM_COMMAND: /* message: received a command */\r
+    switch (LOWORD(wParam)) {\r
+    case IDOK:\r
+      /* Read changed options from the dialog box */\r
+      PeriodicUpdatesEvent(          IS_CHECKED(IDC_EpPeriodicUpdates));\r
+      PonderNextMoveEvent(           IS_CHECKED(IDC_EpPonder));\r
+      appData.hideThinkingFromHuman= IS_CHECKED(IDC_EpHideThinkingHuman); // [HGM] thinking: moved up\r
+      appData.showThinking   = IS_CHECKED(IDC_EpShowThinking);\r
+      ShowThinkingEvent(); // [HGM] thinking: tests all options that need thinking output\r
+      appData.testClaims    = IS_CHECKED(IDC_TestClaims);\r
+      appData.checkMates    = IS_CHECKED(IDC_DetectMates);\r
+      appData.materialDraws = IS_CHECKED(IDC_MaterialDraws);\r
+      appData.trivialDraws  = IS_CHECKED(IDC_TrivialDraws);\r
+\r
+      appData.adjudicateDrawMoves = GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, NULL, FALSE );\r
+      appData.adjudicateLossThreshold = - (int) GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, NULL, FALSE );\r
+      appData.ruleMoves = GetDlgItemInt(hDlg, IDC_RuleMoves, NULL, FALSE );\r
+      appData.drawRepeats = (int) GetDlgItemInt(hDlg, IDC_DrawRepeats, NULL, FALSE );\r
+\r
+      first.scoreIsAbsolute  = appData.firstScoreIsAbsolute  = IS_CHECKED(IDC_ScoreAbs1);\r
+      second.scoreIsAbsolute = appData.secondScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs2);\r
+\r
+      EndDialog(hDlg, TRUE);\r
+      return TRUE;\r
+\r
+    case IDCANCEL:\r
+      EndDialog(hDlg, FALSE);\r
+      return TRUE;\r
+\r
+    case IDC_EpDrawMoveCount:\r
+    case IDC_EpAdjudicationThreshold:\r
+    case IDC_DrawRepeats:\r
+    case IDC_RuleMoves:\r
+        if( HIWORD(wParam) == EN_CHANGE ) {\r
+            int n1_ok;\r
+            int n2_ok;\r
+            int n3_ok;\r
+            int n4_ok;\r
+\r
+            GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, &n1_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, &n2_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_RuleMoves, &n3_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_DrawRepeats, &n4_ok, FALSE );\r
+\r
+            EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok && n4_ok ? TRUE : FALSE );\r
+        }\r
+        return TRUE;\r
+    }\r
+    break;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+VOID EnginePlayOptionsPopup(HWND hwnd)\r
+{\r
+  FARPROC lpProc;\r
+\r
+  lpProc = MakeProcInstance((FARPROC)EnginePlayOptionsDialog, hInst);\r
+  DialogBox(hInst, MAKEINTRESOURCE(DLG_EnginePlayOptions), hwnd, (DLGPROC) lpProc);\r
+  FreeProcInstance(lpProc);\r
+}\r
 \r
+/*---------------------------------------------------------------------------*\\r
+ *\r
+ * UCI Options Dialog functions\r
+ *\r
+\*---------------------------------------------------------------------------*/\r
+INT CALLBACK BrowseCallbackProc(HWND hwnd, \r
+                                UINT uMsg,\r
+                                LPARAM lp, \r
+                                LPARAM pData) \r
+{\r
+    switch(uMsg) \r
+    {\r
+      case BFFM_INITIALIZED: \r
+        SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)pData);\r
+        break;\r
+    }\r
+    return 0;\r
+}\r
+\r
+BOOL BrowseForFolder( const char * title, char * path )\r
+{\r
+    BOOL result = FALSE;\r
+    BROWSEINFO bi;\r
+    LPITEMIDLIST pidl;\r
+\r
+    ZeroMemory( &bi, sizeof(bi) );\r
+\r
+    bi.lpszTitle = title == 0 ? _("Choose Folder") : title;\r
+    bi.ulFlags = BIF_RETURNONLYFSDIRS;\r
+    bi.lpfn = BrowseCallbackProc;\r
+    bi.lParam = (LPARAM) path;\r
+\r
+    pidl = SHBrowseForFolder( &bi );\r
+\r
+    if( pidl != 0 ) {\r
+        IMalloc * imalloc = 0;\r
+\r
+        if( SHGetPathFromIDList( pidl, path ) ) {\r
+            result = TRUE;\r
+        }\r
+\r
+        if( SUCCEEDED( SHGetMalloc ( &imalloc ) ) ) {\r
+            imalloc->lpVtbl->Free(imalloc,pidl);\r
+            imalloc->lpVtbl->Release(imalloc);\r
+        }\r
+    }\r
+\r
+    return result;\r
+}\r
+\r
+int\r
+IsMultiFormat(char *s)\r
+{\r
+  char *p = strchr(s, ':');\r
+  return p && p != s+1;\r
+}\r
+\r
+LRESULT CALLBACK UciOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
+{\r
+  char buf[MAX_PATH];\r
+  int oldCores;\r
+\r
+  switch (message) {\r
+  case WM_INITDIALOG: /* message: initialize dialog box */\r
+\r
+    /* Center the dialog over the application window */\r
+    CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));\r
+    Translate(hDlg, DLG_OptionsUCI);\r
+\r
+    /* Initialize the dialog items */\r
+    SetDlgItemText( hDlg, IDC_PolyglotDir, appData.polyglotDir );\r
+    SetDlgItemInt( hDlg, IDC_HashSize, appData.defaultHashSize, TRUE );\r
+    if(appData.defaultPathEGTB[0])\r
+    SetDlgItemText( hDlg, IDC_PathToEGTB, appData.defaultPathEGTB );\r
+    else\r
+    SetDlgItemText( hDlg, IDC_PathToEGTB, appData.egtFormats );\r
+    SetDlgItemInt( hDlg, IDC_SizeOfEGTB, appData.defaultCacheSizeEGTB, TRUE );\r
+    CheckDlgButton( hDlg, IDC_UseBook, (BOOL) appData.usePolyglotBook );\r
+    SetDlgItemText( hDlg, IDC_BookFile, appData.polyglotBook );\r
+    // [HGM] smp: input field for nr of cores:\r
+    SetDlgItemInt( hDlg, IDC_Cores, appData.smpCores, TRUE );\r
+    // [HGM] book: tick boxes for own book use\r
+    CheckDlgButton( hDlg, IDC_OwnBook1, (BOOL) appData.firstHasOwnBookUCI );\r
+    CheckDlgButton( hDlg, IDC_OwnBook2, (BOOL) appData.secondHasOwnBookUCI );\r
+    SetDlgItemInt( hDlg, IDC_BookDep, appData.bookDepth, TRUE );\r
+    SetDlgItemInt( hDlg, IDC_BookStr, appData.bookStrength, TRUE );\r
+    SetDlgItemInt( hDlg, IDC_Games, appData.defaultMatchGames, TRUE );\r
+\r
+    SendDlgItemMessage( hDlg, IDC_PolyglotDir, EM_SETSEL, 0, -1 );\r
+    // [HGM] Yet another ponder duplicate\r
+    CheckDlgButton( hDlg, OPT_PonderNextMove, (BOOL) appData.ponderNextMove );\r
+\r
+    return TRUE;\r
+\r
+  case WM_COMMAND: /* message: received a command */\r
+    switch (LOWORD(wParam)) {\r
+    case IDOK:\r
+      GetDlgItemText( hDlg, IDC_PolyglotDir, buf, sizeof(buf) );\r
+      appData.polyglotDir = strdup(buf);\r
+      appData.defaultHashSize = GetDlgItemInt(hDlg, IDC_HashSize, NULL, FALSE );\r
+      appData.defaultCacheSizeEGTB = GetDlgItemInt(hDlg, IDC_SizeOfEGTB, NULL, FALSE );\r
+      GetDlgItemText( hDlg, IDC_PathToEGTB, buf, sizeof(buf) );\r
+      if(IsMultiFormat(buf)) {\r
+        ASSIGN(appData.egtFormats, buf);\r
+      } else {\r
+        ASSIGN(appData.defaultPathEGTB, buf);\r
+      }\r
+      GetDlgItemText( hDlg, IDC_BookFile, buf, sizeof(buf) );\r
+      appData.polyglotBook = strdup(buf);\r
+      appData.usePolyglotBook = (Boolean) IsDlgButtonChecked( hDlg, IDC_UseBook );\r
+      // [HGM] smp: get nr of cores and ponder:\r
+      oldCores = appData.smpCores;\r
+      appData.smpCores = GetDlgItemInt(hDlg, IDC_Cores, NULL, FALSE );\r
+      if(appData.smpCores != oldCores) NewSettingEvent(FALSE, &(first.maxCores), "cores", appData.smpCores);\r
+      PonderNextMoveEvent((Boolean) IsDlgButtonChecked( hDlg, OPT_PonderNextMove ));\r
+      // [HGM] book: read tick boxes for own book use\r
+      appData.firstHasOwnBookUCI  = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook1 );\r
+      appData.secondHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook2 );\r
+      appData.bookDepth = GetDlgItemInt(hDlg, IDC_BookDep, NULL, FALSE );\r
+      appData.bookStrength = GetDlgItemInt(hDlg, IDC_BookStr, NULL, FALSE );\r
+      appData.defaultMatchGames = GetDlgItemInt(hDlg, IDC_Games, NULL, FALSE );\r
+\r
+      if(gameMode == BeginningOfGame) Reset(TRUE, TRUE);\r
+      EndDialog(hDlg, TRUE);\r
+      return TRUE;\r
+\r
+    case IDCANCEL:\r
+      EndDialog(hDlg, FALSE);\r
+      return TRUE;\r
+\r
+    case IDC_BrowseForBook:\r
+      {\r
+          char filter[] = {\r
+              'A','l','l',' ','F','i','l','e','s', 0,\r
+              '*','.','*', 0,\r
+              'B','I','N',' ','F','i','l','e','s', 0,\r
+              '*','.','b','i','n', 0,\r
+              0 };\r
+\r
+          OPENFILENAME ofn;\r
+\r
+          safeStrCpy( buf, "" , sizeof( buf)/sizeof( buf[0]) );\r
+\r
+          ZeroMemory( &ofn, sizeof(ofn) );\r
+\r
+          ofn.lStructSize = sizeof(ofn);\r
+          ofn.hwndOwner = hDlg;\r
+          ofn.hInstance = hInst;\r
+          ofn.lpstrFilter = filter;\r
+\r
+          ofn.lpstrFile = buf;\r
+          ofn.nMaxFile = sizeof(buf);\r
+          ofn.lpstrTitle = _("Choose Book");\r
+          ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;\r
+\r
+          if( GetOpenFileName( &ofn ) ) {\r
+              SetDlgItemText( hDlg, IDC_BookFile, buf );\r
+          }\r
+      }\r
+      return TRUE;\r
+\r
+    case IDC_BrowseForPolyglotDir:\r
+      if( BrowseForFolder( _("Choose Polyglot Directory"), buf ) ) {\r
+        SetDlgItemText( hDlg, IDC_PolyglotDir, buf );\r
+\r
+        strcat( buf, "\\polyglot.exe" );\r
+\r
+        if( GetFileAttributes(buf) == 0xFFFFFFFF ) {\r
+            MessageBox( hDlg, _("Polyglot was not found in the specified folder!"), "Warning", MB_OK | MB_ICONWARNING );\r
+        }\r
+      }\r
+      return TRUE;\r
+\r
+    case IDC_BrowseForEGTB:\r
+      if( BrowseForFolder( _("Choose EGTB Directory:"), buf ) ) {\r
+        SetDlgItemText( hDlg, IDC_PathToEGTB, buf );\r
+      }\r
+      return TRUE;\r
+\r
+    case IDC_HashSize:\r
+    case IDC_SizeOfEGTB:\r
+        if( HIWORD(wParam) == EN_CHANGE ) {\r
+            int n1_ok;\r
+            int n2_ok;\r
+\r
+            GetDlgItemInt(hDlg, IDC_HashSize, &n1_ok, FALSE );\r
+            GetDlgItemInt(hDlg, IDC_SizeOfEGTB, &n2_ok, FALSE );\r
+\r
+            EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok ? TRUE : FALSE );\r
+        }\r
+        return TRUE;\r
+    }\r
+    break;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+VOID UciOptionsPopup(HWND hwnd)\r
+{\r
+  FARPROC lpProc;\r
+\r
+  lpProc = MakeProcInstance((FARPROC)UciOptionsDialog, hInst);\r
+  DialogBox(hInst, MAKEINTRESOURCE(DLG_OptionsUCI), hwnd, (DLGPROC) lpProc);\r
+  FreeProcInstance(lpProc);\r
+}\r