Fix multi-leg promotions
[xboard.git] / winboard / wgamelist.c
index 886b02c..19917e6 100644 (file)
@@ -1,7 +1,8 @@
 /*\r
  * wgamelist.c -- Game list window for WinBoard\r
  *\r
- * Copyright 1995, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.\r
+ * Copyright 1995, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free\r
+ * Software Foundation, Inc.\r
  *\r
  * Enhancements Copyright 2005 Alessandro Scotti\r
  *\r
@@ -48,16 +49,8 @@ static BOOLEAN gameListUp = FALSE;
 static FILE* gameFile;\r
 static char* gameFileName = NULL;\r
 \r
-struct GameListStats\r
-{\r
-    int white_wins;\r
-    int black_wins;\r
-    int drawn;\r
-    int unfinished;\r
-};\r
-\r
 /* [AS] Setup the game list according to the specified filter */\r
-static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct GameListStats * stats, BOOL byPos, BOOL narrow )\r
+int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct GameListStats * stats, BOOL byPos, BOOL narrow )\r
 {\r
     ListGame * lg = (ListGame *) gameList.head;\r
     int nItem;\r
@@ -66,6 +59,9 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct
     int count = 0;\r
     struct GameListStats dummy;\r
 \r
+    if(!hDlg) hDlg = gameListDialog; // [HGM] to allow calling from Game List Options dialog\r
+    if(!hDlg) return 0;\r
+\r
     /* Initialize stats (use a dummy variable if caller not interested in them) */\r
     if( stats == NULL ) {\r
         stats = &dummy;\r
@@ -95,7 +91,7 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct
 \r
         if(nItem % 2000 == 0) {\r
           snprintf(buf, MSG_SIZ, _("Scanning through games (%d)"), nItem);\r
-          SetWindowText(hwndMain, buf);\r
+          SetWindowText(hwndMain, buf); DoEvents();\r
         }\r
 \r
       if(!narrow || lg->position >= 0) {\r
@@ -164,7 +160,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
   int nItem;\r
   RECT rect;\r
   static int sizeX, sizeY;\r
-  int newSizeX, newSizeY, flags;\r
+  int newSizeX, newSizeY;\r
   MINMAXINFO *mmi;\r
   static BOOL filterHasFocus = FALSE;\r
   int count;\r
@@ -197,7 +193,6 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
     /* Size and position the dialog */\r
     if (!gameListDialog) {\r
       gameListDialog = hDlg;\r
-      flags = SWP_NOZORDER;\r
       GetClientRect(hDlg, &rect);\r
       sizeX = rect.right;\r
       sizeY = rect.bottom;\r
@@ -407,6 +402,7 @@ VOID GameListPopUp(FILE *fp, char *filename)
     gameFileName = StrSave(filename);\r
   }\r
   CheckMenuItem(GetMenu(hwndMain), IDM_ShowGameList, MF_CHECKED);\r
+  EnableMenuItem(GetMenu(hwndMain), IDM_SaveSelected, MF_ENABLED);\r
   if (gameListDialog) {\r
     SendMessage(gameListDialog, WM_INITDIALOG, 0, 0);\r
     if (!gameListUp) ShowWindow(gameListDialog, SW_SHOW);\r
@@ -428,6 +424,7 @@ FILE *GameFile()
 VOID GameListPopDown(void)\r
 {\r
   CheckMenuItem(GetMenu(hwndMain), IDM_ShowGameList, MF_UNCHECKED);\r
+  EnableMenuItem(GetMenu(hwndMain), IDM_SaveSelected, MF_GRAYED);\r
   if (gameListDialog) ShowWindow(gameListDialog, SW_HIDE);\r
   gameListUp = FALSE;\r
 }\r
@@ -436,14 +433,22 @@ VOID GameListPopDown(void)
 VOID GameListHighlight(int index)\r
 {\r
   char buf[MSG_SIZ];\r
-  int i, res = 0;\r
+  int i, j, k, n, res = 0;\r
   if (gameListDialog == NULL) return;\r
-  for(i=0; res != LB_ERR; i++) {\r
+  for(i=64; ; i+=i) {\r
         res = SendDlgItemMessage( gameListDialog, OPT_GameListText, LB_GETTEXT, i, (LPARAM)buf );\r
-        if(index <= atoi( buf )) break;\r
+        if(res == LB_ERR || index < atoi( buf )) break;\r
+  }\r
+  j = i/2;\r
+  while(i-j > 1) {\r
+        n = (i + j) >> 1;\r
+        res = SendDlgItemMessage( gameListDialog, OPT_GameListText, LB_GETTEXT, n, (LPARAM)buf );\r
+        if(res == LB_ERR || index < (k = atoi( buf ))) i = n; else {\r
+            j = n;\r
+            if(index == k) break;\r
+        }\r
   }\r
-  SendDlgItemMessage(gameListDialog, OPT_GameListText,\r
-    LB_SETCURSEL, i, 0);\r
+  SendDlgItemMessage(gameListDialog, OPT_GameListText, LB_SETCURSEL, j, 0);\r
 }\r
 \r
 \r