Make holdings scrollable
[xboard.git] / winboard / winboard.c
index c82ae8a..bd829b4 100644 (file)
@@ -5,7 +5,8 @@
  * Massachusetts.\r
  *\r
  * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,\r
- * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc.\r
+ * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free\r
+ * Software Foundation, Inc.\r
  *\r
  * Enhancements Copyright 2005 Alessandro Scotti\r
  *\r
  *------------------------------------------------------------------------\r
  ** See the file ChangeLog for a revision history.  */\r
 \r
+#ifndef WINVER\r
+#define WINVER 0x0500\r
+#endif\r
+\r
 #include "config.h"\r
 \r
 #include <windows.h>\r
@@ -534,12 +539,12 @@ typedef struct {
 \r
 SizeInfo sizeInfo[] = \r
 {\r
-  { "tiny",     21, 0, 1, 1, 0, 0 },\r
-  { "teeny",    25, 1, 1, 1, 0, 0 },\r
-  { "dinky",    29, 1, 1, 1, 0, 0 },\r
-  { "petite",   33, 1, 1, 1, 0, 0 },\r
-  { "slim",     37, 2, 1, 0, 0, 0 },\r
-  { "small",    40, 2, 1, 0, 0, 0 },\r
+  { "tiny",     21, 0, 1, 2, 0, 0 },\r
+  { "teeny",    25, 1, 1, 2, 0, 0 },\r
+  { "dinky",    29, 1, 1, 2, 0, 0 },\r
+  { "petite",   33, 1, 1, 2, 0, 0 },\r
+  { "slim",     37, 2, 1, 1, 0, 0 },\r
+  { "small",    40, 2, 1, 1, 0, 0 },\r
   { "mediocre", 45, 2, 1, 0, 0, 0 },\r
   { "middling", 49, 2, 0, 0, 0, 0 },\r
   { "average",  54, 2, 0, 0, 0, 0 },\r
@@ -587,7 +592,7 @@ typedef struct {
   WNDPROC wndproc;\r
 } MyButtonDesc;\r
 \r
-#define BUTTON_WIDTH (tinyLayout ? 16 : 32)\r
+#define BUTTON_WIDTH (tinyLayout == 2 ? 16 : 32)\r
 #define N_BUTTONS 5\r
 \r
 MyButtonDesc buttonDesc[N_BUTTONS] =\r
@@ -601,8 +606,9 @@ MyButtonDesc buttonDesc[N_BUTTONS] =
 \r
 int tinyLayout = 0, smallLayout = 0;\r
 #define MENU_BAR_ITEMS 9\r
-char *menuBarText[2][MENU_BAR_ITEMS+1] = {\r
+char *menuBarText[3][MENU_BAR_ITEMS+1] = {\r
   { N_("&File"), N_("&Edit"), N_("&View"), N_("&Mode"), N_("&Action"), N_("E&ngine"), N_("&Options"), N_("&Help"), NULL },\r
+  { N_("&Fil"), N_("&Ed"), N_("&Vw"), N_("&Mod"), N_("&Act"), N_("E&ng"), N_("&Opt"), N_("&Hlp"), NULL },\r
   { N_("&F"), N_("&E"), N_("&V"), N_("&M"), N_("&A"), N_("&N"), N_("&O"), N_("&H"), NULL },\r
 };\r
 \r
@@ -1105,6 +1111,8 @@ InitGeometry()
   screenGeometry.bottom = screenGeometry.top + screenHeight;\r
 }\r
 \r
+ChessProgramState broadcast;\r
+\r
 BOOL\r
 InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine)\r
 {\r
@@ -1137,7 +1145,18 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine)
     appData.ringBellAfterMoves = TRUE;\r
   }\r
   if (appData.debugMode) {\r
-    debugFP = fopen(appData.nameOfDebugFile, "w");\r
+    char *c = appData.nameOfDebugFile;\r
+    if(strstr(c, "///") == c) {\r
+      broadcast.which = "broadcaster";\r
+      broadcast.pr   = NoProc;\r
+      broadcast.isr  = NULL;\r
+      broadcast.program = c + 3;\r
+      broadcast.dir  = ".";\r
+      broadcast.host = "localhost";\r
+      StartChessProgram(&broadcast);\r
+      debugFP = (FILE*) _fdopen(_open_osfhandle((long)(((ChildProc*)(broadcast.pr))->hTo), _O_WRONLY), "w");\r
+    } else\r
+    debugFP = fopen(c, "w");\r
     setbuf(debugFP, NULL);\r
   }\r
 \r
@@ -1283,6 +1302,8 @@ LFfromMFP(LOGFONT* lf, MyFontParams *mfp)
   lf->lfCharSet = mfp->charset;\r
   lf->lfOutPrecision = OUT_DEFAULT_PRECIS;\r
 \r
+\r
+\r
   lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;\r
   lf->lfQuality = DEFAULT_QUALITY;\r
   lf->lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;\r
@@ -2047,6 +2068,7 @@ static int TranslatePieceToFontPiece( int piece )
     case WhiteSilver:\r
         return PM_WSG;\r
     case WhiteLance:\r
+\r
         return PM_WL;\r
     case WhiteFalcon:\r
         return PM_WV;\r
@@ -2176,7 +2198,7 @@ void CreatePiecesFromFont()
 HBITMAP\r
 DoLoadBitmap(HINSTANCE hinst, char *piece, int squareSize, char *suffix)\r
 {\r
-  char name[128], buf[MSG_SIZ];\r
+  char name[128], buf[MSG_SIZ], *ids = "pnbrqfeicwmohajgdvlsukaacvdklnwpwnwlwswolfgnuzebracameltowersword", *p;\r
 \r
     snprintf(name, sizeof(name)/sizeof(name[0]), "%s%d%s", piece, squareSize, suffix);\r
   if(appData.pieceDirectory[0]) {\r
@@ -2184,6 +2206,30 @@ DoLoadBitmap(HINSTANCE hinst, char *piece, int squareSize, char *suffix)
     snprintf(buf, MSG_SIZ, "%s\\%s.bmp", appData.pieceDirectory, name);\r
     res = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );\r
     if(res) return res;\r
+    p = strstr(ids, piece);\r
+    if(p) { // if we could reconstruct canonical piece number, try the pieceNNN_ format before falling back on built-ins\r
+      int n = p - ids;\r
+      switch(n) {\r
+       case 21: n = WhiteKing; break;\r
+       case 22: n = WhiteAngel; break;\r
+       case 24: n = WhiteSilver; break;\r
+       case 26: n = WhiteDragon; break;\r
+       case 28: n = WhiteLion; break;\r
+       case 30: n = WhiteTokin; break;\r
+       case 32: n = WhitePKnight; break;\r
+       case 34: n = WhitePLance; break;\r
+       case 36: n = WhitePSilver; break;\r
+       case 38: n = WhiteWolf; break;\r
+       case 42: n = WhiteGnu; break;\r
+       case 45: n = WhiteZebra; break;\r
+       case 50: n = WhiteCamel; break;\r
+       case 55: n = WhiteTower; break;\r
+       case 60: n = WhiteSword; break;\r
+      }\r
+      snprintf(buf, MSG_SIZ, "%s\\piece%d_%d%s.bmp", appData.pieceDirectory, n, squareSize, suffix);\r
+      res = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );\r
+      if(res) return res;\r
+    }\r
   }\r
   if (gameInfo.event &&\r
       strcmp(gameInfo.event, "Easter Egg Hunt") == 0 &&\r
@@ -2350,13 +2396,17 @@ InitDrawingSizes(BoardSize boardSize, int flags)
   minorSize = 0; /* [HGM] Kludge to see if demagnified pieces need to be shifted  */\r
   border = appData.useBorder && appData.border[0] ? squareSize/2 : 0;\r
 \r
+  // [HGM] decide on tininess based on total board width rather than square size\r
+  tinyLayout = squareSize * (BOARD_WIDTH);\r
+  tinyLayout = tinyLayout < 35*8 ? 2 : tinyLayout < 43*8 ? 1 : 0;\r
+\r
   if( appData.overrideLineGap >= 0 && appData.overrideLineGap <= 5 ) {\r
       lineGap = appData.overrideLineGap;\r
   }\r
 \r
   if (tinyLayout != oldTinyLayout) {\r
     long style = GetWindowLongPtr(hwndMain, GWL_STYLE);\r
-    if (tinyLayout) {\r
+    if (tinyLayout == 2) {\r
       style &= ~WS_SYSMENU;\r
       InsertMenu(hmenu, IDM_Exit, MF_BYCOMMAND, IDM_Minimize,\r
                 "&Minimize\tCtrl+F4");\r
@@ -2392,7 +2442,7 @@ InitDrawingSizes(BoardSize boardSize, int flags)
   ReleaseDC(hwndMain, hdc);\r
 \r
   /* Compute where everything goes */\r
-  if((first.programLogo || second.programLogo) && !tinyLayout) {\r
+  if((first.programLogo || second.programLogo) && tinyLayout != 2) {\r
         /* [HGM] logo: if either logo is on, reserve space for it */\r
        logoHeight =  2*clockSize.cy;\r
        leftLogoRect.left   = OUTER_MARGIN;\r
@@ -2513,7 +2563,7 @@ InitDrawingSizes(BoardSize boardSize, int flags)
                     messageRect.top, BUTTON_WIDTH, messageSize.cy, hwndMain,\r
                     (HMENU) buttonDesc[i].id,\r
                     (HINSTANCE) GetWindowLongPtr(hwndMain, GWLP_HINSTANCE), NULL);\r
-      if (tinyLayout) {\r
+      if (tinyLayout == 2) {\r
        SendMessage(buttonDesc[i].hwnd, WM_SETFONT, \r
                    (WPARAM)font[boardSize][MESSAGE_FONT]->hf,\r
                    MAKELPARAM(FALSE, 0));\r
@@ -2582,10 +2632,12 @@ InitDrawingSizes(BoardSize boardSize, int flags)
         piece = (ChessSquare) ((int) piece + 1)) {\r
       if (pieceBitmap[i][piece] != NULL)\r
        DeleteObject(pieceBitmap[i][piece]);\r
+      pieceBitmap[i][piece] = NULL;\r
     }\r
   }\r
 \r
   fontBitmapSquareSize = 0; /* [HGM] render: make sure pieces will be recreated, as we might need others now */\r
+\r
   // Orthodox Chess pieces\r
   pieceBitmap[0][WhitePawn] = DoLoadBitmap(hInst, "p", squareSize, "s");\r
   pieceBitmap[0][WhiteKnight] = DoLoadBitmap(hInst, "n", squareSize, "s");\r
@@ -2683,12 +2735,36 @@ InitDrawingSizes(BoardSize boardSize, int flags)
     pieceBitmap[0][WhiteLance] = DoLoadBitmap(hInst, "l", squareSize, "s");\r
     pieceBitmap[1][WhiteLance] = DoLoadBitmap(hInst, "l", squareSize, "o");\r
     pieceBitmap[2][WhiteLance] = DoLoadBitmap(hInst, "l", squareSize, "w");\r
+    pieceBitmap[0][WhiteAmazon] = DoLoadBitmap(hInst, "l", squareSize, "s");\r
+    pieceBitmap[1][WhiteAmazon] = DoLoadBitmap(hInst, "l", squareSize, "o");\r
+    pieceBitmap[2][WhiteAmazon] = DoLoadBitmap(hInst, "l", squareSize, "w");\r
     pieceBitmap[0][WhiteUnicorn] = DoLoadBitmap(hInst, "u", squareSize, "s");\r
     pieceBitmap[1][WhiteUnicorn] = DoLoadBitmap(hInst, "u", squareSize, "o");\r
     pieceBitmap[2][WhiteUnicorn] = DoLoadBitmap(hInst, "u", squareSize, "w");\r
     pieceBitmap[0][WhiteLion] = DoLoadBitmap(hInst, "ln", squareSize, "s");\r
     pieceBitmap[1][WhiteLion] = DoLoadBitmap(hInst, "ln", squareSize, "o");\r
     pieceBitmap[2][WhiteLion] = DoLoadBitmap(hInst, "ln", squareSize, "w");\r
+    pieceBitmap[0][WhiteCub] = DoLoadBitmap(hInst, "ln", squareSize, "s");\r
+    pieceBitmap[1][WhiteCub] = DoLoadBitmap(hInst, "ln", squareSize, "o");\r
+    pieceBitmap[2][WhiteCub] = DoLoadBitmap(hInst, "ln", squareSize, "w");\r
+    pieceBitmap[0][WhiteWolf] = DoLoadBitmap(hInst, "wolf", squareSize, "s");\r
+    pieceBitmap[1][WhiteWolf] = DoLoadBitmap(hInst, "wolf", squareSize, "o");\r
+    pieceBitmap[2][WhiteWolf] = DoLoadBitmap(hInst, "wolf", squareSize, "w");\r
+    pieceBitmap[0][WhiteCamel] = DoLoadBitmap(hInst, "camel", squareSize, "s");\r
+    pieceBitmap[1][WhiteCamel] = DoLoadBitmap(hInst, "camel", squareSize, "o");\r
+    pieceBitmap[2][WhiteCamel] = DoLoadBitmap(hInst, "camel", squareSize, "w");\r
+    pieceBitmap[0][WhiteZebra] = DoLoadBitmap(hInst, "zebra", squareSize, "s");\r
+    pieceBitmap[1][WhiteZebra] = DoLoadBitmap(hInst, "zebra", squareSize, "o");\r
+    pieceBitmap[2][WhiteZebra] = DoLoadBitmap(hInst, "n", squareSize, "w");\r
+    pieceBitmap[0][WhiteTower] = DoLoadBitmap(hInst, "tower", squareSize, "s");\r
+    pieceBitmap[1][WhiteTower] = DoLoadBitmap(hInst, "tower", squareSize, "o");\r
+    pieceBitmap[2][WhiteTower] = DoLoadBitmap(hInst, "tower", squareSize, "w");\r
+    pieceBitmap[0][WhiteSword] = DoLoadBitmap(hInst, "sword", squareSize, "s");\r
+    pieceBitmap[1][WhiteSword] = DoLoadBitmap(hInst, "sword", squareSize, "o");\r
+    pieceBitmap[2][WhiteSword] = DoLoadBitmap(hInst, "sword", squareSize, "w");\r
+    pieceBitmap[0][WhiteGnu] = DoLoadBitmap(hInst, "gnu", squareSize, "s");\r
+    pieceBitmap[1][WhiteGnu] = DoLoadBitmap(hInst, "gnu", squareSize, "o");\r
+    pieceBitmap[2][WhiteGnu] = DoLoadBitmap(hInst, "gnu", squareSize, "w");\r
 \r
     if(gameInfo.variant == VariantShogi && BOARD_HEIGHT != 7) { /* promoted Gold representations (but not in Tori!)*/\r
       pieceBitmap[0][WhiteCannon] = DoLoadBitmap(hInst, "wp", squareSize, "s");\r
@@ -2790,6 +2866,15 @@ InitDrawingSizes(BoardSize boardSize, int flags)
   pieceBitmap[2][WhiteSilver] = DoLoadBitmap(hInst, "sw", squareSize, "w");\r
   minorSize = 0;\r
   }\r
+\r
+  if(appData.pieceDirectory[0]) for(i=WhitePawn; i<BlackPawn; i++) { // try for all missing pieces with new naming convention\r
+    char buf[MSG_SIZ];\r
+    if(pieceBitmap[0][i]) continue;\r
+    snprintf(buf, MSG_SIZ, "piece%d_", i);\r
+    pieceBitmap[0][i] = DoLoadBitmap(hInst, buf, squareSize, "s");\r
+    pieceBitmap[1][i] = DoLoadBitmap(hInst, buf, squareSize, "o");\r
+    pieceBitmap[2][i] = DoLoadBitmap(hInst, buf, squareSize, "w");\r
+  }\r
 }\r
 \r
 HBITMAP\r
@@ -2936,7 +3021,7 @@ VOID
 DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y, HDC tmphdc)\r
 {\r
   HBITMAP oldBitmap;\r
-  HBRUSH oldBrush;\r
+  HBRUSH oldBrush = NULL;\r
   int tmpSize;\r
 \r
   if (appData.blindfold) return;\r
@@ -2995,6 +3080,20 @@ DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y,
       y += squareSize - minorSize - 2;\r
       tmpSize = minorSize;\r
     }\r
+#if WINVER >= 0x0500\r
+    HBITMAP pbm = PieceBitmap(piece, color ? OUTLINE_PIECE : SOLID_PIECE);\r
+    BITMAP b;\r
+    GetObject(pbm, sizeof(BITMAP), &b);\r
+    if(b.bmBitsPixel == 32) { // for now this is a kludge to indicate bitmaps with alpha channel\r
+       BLENDFUNCTION bf;\r
+       bf.BlendOp = AC_SRC_OVER;\r
+       bf.BlendFlags = 0;\r
+       bf.SourceConstantAlpha = 0xFF;\r
+       bf.AlphaFormat = AC_SRC_ALPHA;\r
+       oldBitmap = SelectObject(tmphdc, pbm);\r
+       AlphaBlend(hdc, x, y, tmpSize, tmpSize, tmphdc, 0, 0, tmpSize, tmpSize, bf);\r
+    } else\r
+#endif\r
     if (color || appData.allWhite ) {\r
       oldBitmap = SelectObject(tmphdc, PieceBitmap(piece, WHITE_PIECE));\r
       if( color )\r
@@ -3031,7 +3130,7 @@ DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y,
       else\r
         BitBlt(hdc, x, y, tmpSize, tmpSize, tmphdc, 0, 0, 0x00B8074A);\r
     }\r
-    SelectObject(hdc, oldBrush);\r
+    if(oldBrush) SelectObject(hdc, oldBrush);\r
     SelectObject(tmphdc, oldBitmap);\r
   }\r
 }\r
@@ -3706,6 +3805,10 @@ void DrawSeekClose()
 {\r
 }\r
 \r
+\r
+\r
+\r
+\r
 VOID\r
 HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)\r
 {\r
@@ -3926,6 +4029,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
         explodes.  The old and new positions both had an empty square\r
         at the destination, but animation has drawn a piece there and\r
         we have to remember to erase it. [HGM] moved until after setting lastDrawn */\r
+\r
       lastDrawn[0][animInfo.to.y][animInfo.to.x] = animInfo.piece;\r
     }\r
   }\r
@@ -3990,6 +4094,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
   }\r
 \r
   if( appData.highlightMoveWithArrow ) {\r
+\r
     DrawArrowHighlight(hdcmem);\r
   }\r
 \r
@@ -4058,7 +4163,12 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
   if(saveDiagFlag) { \r
     BITMAP b; int i, j=0, m, w, wb, fac=0; char *pData; \r
     BITMAPINFOHEADER bih; int color[16], nrColors=0;\r
+    HBITMAP src = bufferBitmap, obmp; HDC tmp = CreateCompatibleDC(hdc);\r
 \r
+    bufferBitmap = CreateCompatibleBitmap(hdc, boardRect.right-boardRect.left, Rect.bottom-Rect.top-2*OUTER_MARGIN);\r
+    obmp = SelectObject(tmp, bufferBitmap);\r
+    BitBlt(tmp, 0, 0, boardRect.right - boardRect.left, Rect.bottom - Rect.top - 2*OUTER_MARGIN,\r
+           tmphdc, boardRect.left, OUTER_MARGIN, SRCCOPY);\r
     GetObject(bufferBitmap, sizeof(b), &b);\r
     if(pData = malloc(b.bmWidthBytes*b.bmHeight + 10000)) {\r
        bih.biSize = sizeof(BITMAPINFOHEADER);\r
@@ -4122,10 +4232,14 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
        if(fac)\r
        for(i=0; i<16; i++) fputDW(diagFile, color[i]);\r
        // write bitmap data\r
+\r
        for(i=0; i<wb*(b.bmHeight - boardRect.top + OUTER_MARGIN); i++) \r
                fputc(pData[i], diagFile);\r
        free(pData);\r
      }\r
+     DeleteObject(bufferBitmap); bufferBitmap = src;\r
+     SelectObject(tmp, obmp);\r
+     DeleteDC(tmp);\r
   }\r
 \r
   SelectObject(tmphdc, oldBitmap);\r
@@ -4510,6 +4624,7 @@ static int promoStyle;
 LRESULT CALLBACK\r
 Promotion(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
 {\r
+\r
   char promoChar;\r
 \r
   switch (message) {\r
@@ -4611,7 +4726,7 @@ PromotionPopup(HWND hwnd)
 void\r
 PromotionPopUp(char choice)\r
 {\r
-  promoStyle = (choice == '+');\r
+  promoStyle = (choice == '+' || IS_SHOGI(gameInfo.variant));\r
   DrawPosition(TRUE, NULL);\r
   PromotionPopup(hwndMain);\r
 }\r
@@ -5082,12 +5197,14 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
       break;\r
 \r
     case IDM_Match: // [HGM] match: flows into next case, after setting Match Mode and nr of Games\r
+      if(matchMode) EnableMenuItem(GetMenu(hwndMain), IDM_Match, MF_BYCOMMAND|MF_GRAYED);\r
       MatchEvent(2); // distinguish from command-line-triggered case (matchMode=1)\r
       break;\r
 \r
     case IDM_TwoMachines:\r
       TwoMachinesEvent();\r
       /*\r
+\r
        * refresh the tags dialog only if it's visible\r
        */\r
       if (gameMode == TwoMachinesPlay && IsWindowVisible(editTagsDialog)) {\r
@@ -5236,6 +5353,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
       SetFocus(hwndMain);\r
       break;\r
 \r
+\r
     case IDM_ToStart:\r
       ToStartEvent();\r
       SetFocus(hwndMain);\r
@@ -5687,6 +5805,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             ReattachAfterMove( &rcMain, lpwp->x, lpwp->y, hwndConsole, &wpConsole );\r
            wpMain.x = lpwp->x;\r
             wpMain.y = lpwp->y;\r
+\r
         }\r
     }\r
     break;\r
@@ -6209,6 +6328,8 @@ InitComboStringsFromOption(HANDLE hwndCombo, char *str)
     str = buf1;\r
   }\r
 \r
+\r
+\r
   SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);\r
 \r
   for (;;) {\r
@@ -6332,11 +6453,12 @@ StartupDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
         safeStrCpy(buf, "/fcp=", sizeof(buf)/sizeof(buf[0]) );\r
        GetDlgItemText(hDlg, OPT_ChessEngineName, buf + strlen(buf), sizeof(buf) - strlen(buf));\r
         p = buf;\r
-       comboLine = strdup(p+5); // [HGM] recent: remember complete line of first combobox\r
+       currentEngine[0] = strdup(p+5); // [HGM] recent: remember complete line of first combobox\r
        ParseArgs(StringGet, &p);\r
        safeStrCpy(buf, singleList ? "/fcp=" : "/scp=", sizeof(buf)/sizeof(buf[0]) );\r
        GetDlgItemText(hDlg, OPT_SecondChessEngineName, buf + strlen(buf), sizeof(buf) - strlen(buf));\r
         p = buf;\r
+       currentEngine[1] = strdup(p+5); // [HGM] also remember engine line of 2nd for saving its settings\r
        SwapEngines(singleList); // temporarily swap first and second, to load a second 'first', ...\r
        ParseArgs(StringGet, &p);\r
        SwapEngines(singleList); // ... and then make it 'second'\r
@@ -6704,7 +6826,7 @@ TypeInNameDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     case IDOK:\r
       GetDlgItemText(hDlg, OPT_Name, move, sizeof(move));\r
       appData.userName = strdup(move);\r
-      SetUserLogo();\r
+      SetUserLogo(); DisplayLogos();\r
       SetGameInfo();\r
       if(gameMode == MachinePlaysWhite || gameMode == MachinePlaysBlack) {\r
        snprintf(move, MSG_SIZ, "%s vs. %s", gameInfo.white, gameInfo.black);\r
@@ -7644,7 +7766,7 @@ DisplayAClock(HDC hdc, int timeRemaining, int highlight,
 \r
   if (twoBoards && partnerUp) return;\r
   if (appData.clockMode) {\r
-    if (tinyLayout)\r
+    if (tinyLayout == 2)\r
       snprintf(buf, sizeof(buf)/sizeof(buf[0]), "%c %s %s", color[0], TimeString(timeRemaining), flagFell);\r
     else\r
       snprintf(buf, sizeof(buf)/sizeof(buf[0]), "%s:%c%s %s", color, (logoHeight>0 ? 0 : ' '), TimeString(timeRemaining), flagFell);\r
@@ -7660,6 +7782,7 @@ DisplayAClock(HDC hdc, int timeRemaining, int highlight,
     oldFg = SetTextColor(hdc, RGB(0, 0, 0)); /* black */\r
     oldBg = SetBkColor(hdc, RGB(255, 255, 255)); /* white */\r
   }\r
+\r
   oldFont = SelectObject(hdc, font[boardSize][CLOCK_FONT]->hf);\r
 \r
   JAWS_SILENCE\r
@@ -7976,6 +8099,7 @@ Enables gnuEnables[] = {
   { IDM_Annotate, MF_BYCOMMAND|MF_GRAYED },\r
   { IDM_NewChat, MF_BYCOMMAND|MF_GRAYED },\r
 \r
+\r
   // Needed to switch from ncp to GNU mode on Engine Load\r
   { ACTION_POS, MF_BYPOSITION|MF_ENABLED },\r
   { IDM_MachineWhite, MF_BYCOMMAND|MF_ENABLED },\r
@@ -8205,6 +8329,8 @@ ModeHighlight()
     nowChecked = 0;\r
     break;\r
   }\r
+  if(prevChecked == IDM_TwoMachines) // [HGM] 'Machine Match' might have gotten disabled when stopping match\r
+    EnableMenuItem(GetMenu(hwndMain), IDM_Match, MF_BYCOMMAND|MF_ENABLED);\r
   CheckMark(prevChecked, MF_UNCHECKED);\r
   CheckMark(nowChecked, MF_CHECKED);\r
   CheckMark(IDM_Match, matchMode && matchGame < appData.matchGames ? MF_CHECKED : MF_UNCHECKED);\r
@@ -8449,6 +8575,7 @@ DisplayFatalError(char *str, int error, int exitStatus)
     fprintf(debugFP, "%s: %s\n", label, str);\r
   }\r
   if (appData.popupExitMessage) {\r
+    if(appData.icsActive) SendToICS("logout\n"); // [HGM] make sure no new games will be started!\r
     (void) MessageBox(hwndMain, str, label, MB_OK|\r
                      (exitStatus ? MB_ICONSTOP : MB_ICONINFORMATION));\r
   }\r
@@ -8462,6 +8589,11 @@ DisplayInformation(char *str)
   (void) MessageBox(hwndMain, str, _("Information"), MB_OK|MB_ICONINFORMATION);\r
 }\r
 \r
+char *\r
+Shorten (char *s)\r
+{\r
+  return s;\r
+}\r
 \r
 VOID\r
 DisplayNote(char *str)\r
@@ -8744,7 +8876,7 @@ DisplayIcsInteractionTitle(char *str)
 }\r
 \r
 void\r
-DrawPosition(int fullRedraw, Board board)\r
+DrawPositionX(int fullRedraw, Board board)\r
 {\r
   HDCDrawPosition(NULL, (BOOLEAN) fullRedraw, board); \r
 }\r
@@ -9071,6 +9203,7 @@ IDLE_PRIORITY_CLASS         0x00000040
 */\r
         if (nice < -15) return 0x00000080;\r
         if (nice < 0)   return 0x00008000;\r
+\r
         if (nice == 0)  return 0x00000020;\r
         if (nice < 15)  return 0x00004000;\r
         return 0x00000040;\r
@@ -9549,6 +9682,7 @@ OpenRcmd(char* host, char* user, char* cmd, ProcRef* pr)
       return WSAEADDRINUSE;\r
     }\r
     if (s == INVALID_SOCKET) {\r
+\r
       if ((s = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {\r
        err = WSAGetLastError();\r
        WSACleanup();\r
@@ -9981,8 +10115,8 @@ AnimateMove(board, fromX, fromY, toX, toY)
      int toX;\r
      int toY;\r
 {\r
-  ChessSquare piece;\r
-  int x = toX, y = toY;\r
+  ChessSquare piece, victim = EmptySquare, victim2 = EmptySquare;\r
+  int x = toX, y = toY, x2 = kill2X;\r
   POINT start, finish, mid;\r
   POINT frames[kFactor * 2 + 1];\r
   int nFrames, n;\r
@@ -9995,7 +10129,11 @@ AnimateMove(board, fromX, fromY, toX, toY)
   piece = board[fromY][fromX];\r
   if (piece >= EmptySquare) return;\r
 \r
-  if(killX >= 0) toX = killX, toY = killY; // [HGM] lion: first to kill square\r
+  if(x2 >= 0) toX = kill2X, toY = kill2Y,  victim = board[killY][killX], victim2 = board[kill2Y][kill2X]; else\r
+  if(killX >= 0) toX = killX, toY = killY, victim = board[killY][killX]; // [HGM] lion: first to kill square\r
+\r
+  animInfo.from.x = fromX;\r
+  animInfo.from.y = fromY;\r
 \r
 again:\r
 \r
@@ -10023,22 +10161,30 @@ again:
   else\r
     Tween(&start, &mid, &finish, kFactor, frames, &nFrames);\r
 \r
-  animInfo.from.x = fromX;\r
-  animInfo.from.y = fromY;\r
   animInfo.to.x = toX;\r
   animInfo.to.y = toY;\r
   animInfo.lastpos = start;\r
   animInfo.piece = piece;\r
   for (n = 0; n < nFrames; n++) {\r
     animInfo.pos = frames[n];\r
-    DrawPosition(FALSE, NULL);\r
+    DrawPosition(FALSE, board);\r
     animInfo.lastpos = animInfo.pos;\r
     Sleep(appData.animSpeed);\r
   }\r
   animInfo.pos = finish;\r
-  DrawPosition(FALSE, NULL);\r
-\r
-  if(toX != x || toY != y) { fromX = toX; fromY = toY; toX = x; toY = y; goto again; } // second leg\r
+  DrawPosition(FALSE, board);\r
+\r
+  if(toX == x2 && toY == kill2Y) {\r
+    fromX = toX; fromY = toY; toX = killX; toY = killY; x2 = -1;\r
+    board[kill2Y][kill2X] = EmptySquare; goto again;\r
+  } // second leg\r
+  if(toX != x || toY != y) {\r
+    fromX = toX; fromY = toY; toX = x; toY = y;\r
+    board[killY][killX] = EmptySquare; goto again;\r
+  } // second leg\r
+\r
+if(victim2 != EmptySquare) board[kill2Y][kill2X] = victim2;\r
+if(victim  != EmptySquare) board[killY][killX] = victim;\r
 \r
   animInfo.piece = EmptySquare;\r
   Explode(board, fromX, fromY, toX, toY);\r