Fix multi-leg promotions
[xboard.git] / history.c
index 6773133..1270ed9 100644 (file)
--- a/history.c
+++ b/history.c
@@ -6,6 +6,9 @@
  *
  * Copyright 2005 Alessandro Scotti
  *
+ * Enhancements Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015,
+ * 2016 Free Software Foundation, Inc.
+ *
  * ------------------------------------------------------------------------
  *
  * GNU XBoard is free software: you can redistribute it and/or modify
@@ -19,7 +22,7 @@
  * General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://www.gnu.org/licenses/. 
+ * along with this program. If not, see http://www.gnu.org/licenses/.
  *
  * ------------------------------------------------------------------------
  ** See the file ChangeLog for a revision history.  */
@@ -50,6 +53,7 @@ typedef char MoveHistoryString[ MOVE_LEN*2 ];
 static int lastFirst = 0;
 static int lastLast = 0;
 static int lastCurrent = -1;
+static int lastGames;
 
 static char lastLastMove[ MOVE_LEN ];
 
@@ -69,17 +73,18 @@ static HistoryMove histMoves[ MAX_MOVES ];
 /* Note: in the following code a "Memo" is a Rich Edit control (it's Delphi lingo) */
 
 // back-end after replacing Windows data-types by equivalents
-static Boolean OnlyCurrentPositionChanged()
+static Boolean
+OnlyCurrentPositionChanged ()
 {
     Boolean result = FALSE;
 
     if( lastFirst >= 0 &&
         lastLast >= lastFirst &&
-        lastCurrent >= lastFirst && 
+        lastCurrent >= lastFirst &&
         currFirst == lastFirst &&
         currLast == lastLast &&
         currCurrent >= 0 &&
-        TRUE )
+        lastGames == storedGames )
     {
         result = TRUE;
 
@@ -95,7 +100,8 @@ static Boolean OnlyCurrentPositionChanged()
 }
 
 // back-end, after replacing Windows data types
-static Boolean OneMoveAppended()
+static Boolean
+OneMoveAppended ()
 {
     Boolean result = FALSE;
 
@@ -105,7 +111,7 @@ static Boolean OneMoveAppended()
         lastLast == (currLast-1) &&
         lastCurrent == (currCurrent-1) &&
         currCurrent == (currLast-1) &&
-        TRUE )
+        lastGames == storedGames )
     {
         result = TRUE;
     }
@@ -114,7 +120,8 @@ static Boolean OneMoveAppended()
 }
 
 // back-end, now that color and font-style are passed as numbers
-static void AppendMoveToMemo( int index )
+static void
+AppendMoveToMemo (int index)
 {
     char buf[64];
 
@@ -139,7 +146,7 @@ static void AppendMoveToMemo( int index )
 
     /* PV info (if any) */
     if( appData.showEvalInMoveHistory && currPvInfo[index].depth > 0 ) {
-        sprintf( buf, "{%s%.2f/%d} ", 
+        sprintf( buf, "{%s%.2f/%d} ",
             currPvInfo[index].score >= 0 ? "+" : "",
             currPvInfo[index].score / 100.0,
             currPvInfo[index].depth );
@@ -149,7 +156,8 @@ static void AppendMoveToMemo( int index )
 }
 
 // back-end
-void RefreshMemoContent()
+void
+RefreshMemoContent ()
 {
     int i;
 
@@ -161,25 +169,27 @@ void RefreshMemoContent()
 }
 
 // back-end part taken out of HighlightMove to determine character positions
-static void DoHighlight(int index, int onoff)
+static void
+DoHighlight (int index, int onoff)
 {
     if( index >= 0 && index < MAX_MOVES ) {
-        HighlightMove( histMoves[index].memoOffset, 
+        HighlightMove( histMoves[index].memoOffset,
             histMoves[index].memoOffset + histMoves[index].memoLength, onoff );
     }
 }
 
 // back-end, now that a wrapper is provided for the front-end code to do the actual scrolling
-void MemoContentUpdated()
+void
+MemoContentUpdated ()
 {
     int caretPos;
 
-    DoHighlight( lastCurrent, FALSE );
-    DoHighlight( currCurrent, TRUE );
+    if(lastCurrent <= currLast) DoHighlight( lastCurrent, FALSE );
 
     lastFirst = currFirst;
     lastLast = currLast;
     lastCurrent = currCurrent;
+    lastGames = storedGames;
     lastLastMove[0] = '\0';
 
     if( lastLast > 0 ) {
@@ -195,10 +205,12 @@ void MemoContentUpdated()
     }
 
     ScrollToCurrent(caretPos);
+    DoHighlight( currCurrent, TRUE ); // [HGM] moved last, because in X some scrolling methods spoil highlighting
 }
 
 // back-end. Must be called as double-click call-back on move-history text edit
-void FindMoveByCharIndex( int char_index )
+void
+FindMoveByCharIndex (int char_index)
 {
     int index;
 
@@ -212,7 +224,8 @@ void FindMoveByCharIndex( int char_index )
 }
 
 // back-end. In WinBoard called by call-back, but could be called directly by SetIfExists?
-void UpdateMoveHistory()
+void
+UpdateMoveHistory ()
 {
         /* Update the GUI */
         if( OnlyCurrentPositionChanged() ) {
@@ -229,7 +242,8 @@ void UpdateMoveHistory()
 }
 
 // back-end
-void MoveHistorySet( char movelist[][2*MOVE_LEN], int first, int last, int current, ChessProgramStats_Move * pvInfo )
+void
+MoveHistorySet (char movelist[][2*MOVE_LEN], int first, int last, int current, ChessProgramStats_Move * pvInfo)
 {
     /* [AS] Danger! For now we rely on the movelist parameter being a static variable! */
 
@@ -242,4 +256,3 @@ void MoveHistorySet( char movelist[][2*MOVE_LEN], int first, int last, int curre
     if(MoveHistoryDialogExists())
         UpdateMoveHistory(); // [HGM] call this directly, in stead of through call-back
 }
-