updated files (AUTHORS, Changelog, etc) for new release
[xboard.git] / winboard / woptions.c
index 0941cce..379a8d6 100644 (file)
@@ -1,25 +1,27 @@
 /*\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
  *\r
- * Copyright 2000 Free Software Foundation, Inc.\r
+ * Copyright 2000, 2009, 2010 Free 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
@@ -27,6 +29,7 @@
 #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 "winboard.h"\r
@@ -61,11 +64,12 @@ extern HWND hwndConsole;
 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 startedFromPositionFile; /* [HGM] loadPos */\r
+extern int startedFromPositionFile; /* [HGM] loadPos */\r
 \r
 /* types */\r
 \r
@@ -126,6 +130,7 @@ void SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value);
 VOID SetLoadOptionEnables(HWND hDlg);\r
 VOID SetSaveOptionEnables(HWND hDlg);\r
 VOID SetTimeControlEnables(HWND hDlg);\r
+void NewSettingEvent(int option, char *command, int value);\r
 \r
 /*---------------------------------------------------------------------------*\\r
  *\r
@@ -218,12 +223,8 @@ GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN);\r
       appData.hideThinkingFromHuman= IS_CHECKED(OPT_HideThinkFromHuman);\r
       appData.showEvalInMoveHistory= IS_CHECKED(OPT_ExtraInfoInMoveHistory);\r
-#if 0\r
-      ShowThinkingEvent(             IS_CHECKED(OPT_ShowThinking));\r
-#else\r
       appData.showThinking         = IS_CHECKED(OPT_ShowThinking);\r
       ShowThinkingEvent(); // [HGM] thinking: tests four options\r
-#endif\r
       appData.testLegality         = IS_CHECKED(OPT_TestLegality);\r
       appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow);\r
 \r
@@ -310,7 +311,7 @@ PaintSampleSquare(
   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
@@ -368,38 +369,16 @@ PaintSampleSquare(
       oldBrushPiece = SelectObject(hdcMem, brushPiece);\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
             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
             hdcTemp, 0, 0, 0x00B8074A);\r
-#endif\r
     }\r
     SelectObject(hdcMem, oldBrushPiece);\r
     SelectObject(hdcTemp, oldBitmapTemp);\r
@@ -566,6 +545,7 @@ 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
@@ -789,16 +769,18 @@ VariantWhichRadio(HWND hDlg)
          (IsDlgButtonChecked(hDlg, OPT_VariantJanus) ? VariantJanus :\r
          (IsDlgButtonChecked(hDlg, OPT_VariantWildcastle) ? VariantWildCastle :\r
          (IsDlgButtonChecked(hDlg, OPT_VariantNocastle) ? VariantNoCastle :\r
-          VariantNormal ))))))))))))))))))))))));\r
+         (IsDlgButtonChecked(hDlg, OPT_Variant3Check) ? Variant3Check :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantGreat) ? VariantGreat :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantGiveaway) ? VariantGiveaway :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantTwilight) ? VariantTwilight :\r
+         (IsDlgButtonChecked(hDlg, OPT_VariantMakruk) ? VariantMakruk :\r
+          VariantNormal )))))))))))))))))))))))))))));\r
 }\r
 \r
 LRESULT CALLBACK\r
 NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
 {\r
-  static Boolean  mono;\r
   static VariantClass v;\r
-  static COLORREF lsc, dsc, wpc, bpc, hsc, phc;\r
-  static HBITMAP pieces[3];\r
   static int n1_ok, n2_ok, n3_ok;\r
 \r
   switch (message) {\r
@@ -865,6 +847,8 @@ NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       CheckDlgButton(hDlg, OPT_VariantCylinder, TRUE);\r
       break;\r
     case Variant3Check:\r
+      CheckDlgButton(hDlg, OPT_Variant3Check, TRUE);\r
+      break;\r
     case VariantSuper:\r
       CheckDlgButton(hDlg, OPT_VariantSuper, TRUE);\r
       break;\r
@@ -880,6 +864,19 @@ NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     case VariantNoCastle:\r
       CheckDlgButton(hDlg, OPT_VariantNocastle, TRUE);\r
       break;\r
+    case VariantGreat:\r
+      CheckDlgButton(hDlg, OPT_VariantGreat, TRUE);\r
+      break;\r
+    case VariantGiveaway:\r
+      CheckDlgButton(hDlg, OPT_VariantGiveaway, TRUE);\r
+      break;\r
+    case VariantTwilight:\r
+      CheckDlgButton(hDlg, OPT_VariantTwilight, TRUE);\r
+      break;\r
+    case VariantMakruk:\r
+      CheckDlgButton(hDlg, OPT_VariantMakruk, TRUE);\r
+      break;\r
+    default: ;\r
     }\r
 \r
     SetDlgItemInt( hDlg, IDC_Files, -1, TRUE );\r
@@ -1017,6 +1014,7 @@ 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
+  font->mfp.charset = font->lf.lfCharSet;\r
   strcpy(font->mfp.faceName, font->lf.lfFaceName);\r
   return TRUE;\r
 }\r
@@ -1028,7 +1026,7 @@ UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca)
   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
+    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
@@ -1272,7 +1270,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
@@ -1471,21 +1471,6 @@ 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
@@ -1517,6 +1502,7 @@ 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
+  dest->mfp.charset   = src->mfp.charset;\r
   lstrcpy(dest->mfp.faceName, src->mfp.faceName);\r
   CreateFontInMF(dest);\r
 }\r
@@ -1617,7 +1603,17 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory,\r
          WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, \r
          MAKELPARAM(TRUE, 0));\r
-       InvalidateRect(editTagsDialog, NULL, TRUE);\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
@@ -1770,7 +1766,7 @@ InitSoundCombo(HWND hwndCombo, SoundComboData *scd)
     err = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) scd->label);\r
     if (err != cnt++) {\r
       sprintf(buf, "InitSoundCombo(): err '%d', cnt '%d'\n",\r
-         err, cnt);\r
+         (int)err, (int)cnt);\r
       MessageBox(NULL, buf, NULL, MB_OK);\r
     }\r
     scd++;\r
@@ -1889,6 +1885,7 @@ 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
@@ -1969,6 +1966,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
@@ -1998,8 +1997,10 @@ 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
@@ -2165,7 +2166,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
@@ -2227,7 +2228,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
+    sprintf(buf, "%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
@@ -2761,12 +2762,8 @@ LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam,
       PeriodicUpdatesEvent(          IS_CHECKED(IDC_EpPeriodicUpdates));\r
       PonderNextMoveEvent(           IS_CHECKED(IDC_EpPonder));\r
       appData.hideThinkingFromHuman= IS_CHECKED(IDC_EpHideThinkingHuman); // [HGM] thinking: moved up\r
-#if 0\r
-      ShowThinkingEvent(             IS_CHECKED(IDC_EpShowThinking));\r
-#else\r
       appData.showThinking   = IS_CHECKED(IDC_EpShowThinking);\r
       ShowThinkingEvent(); // [HGM] thinking: tests all options that need thinking output\r
-#endif\r
       appData.testClaims    = IS_CHECKED(IDC_TestClaims);\r
       appData.checkMates    = IS_CHECKED(IDC_DetectMates);\r
       appData.materialDraws = IS_CHECKED(IDC_MaterialDraws);\r
@@ -2777,8 +2774,8 @@ LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam,
       appData.ruleMoves = GetDlgItemInt(hDlg, IDC_RuleMoves, NULL, FALSE );\r
       appData.drawRepeats = (int) GetDlgItemInt(hDlg, IDC_DrawRepeats, NULL, FALSE );\r
 \r
-      appData.firstScoreIsAbsolute  = IS_CHECKED(IDC_ScoreAbs1);\r
-      appData.secondScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs2);\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