Fix GameListHighlight WB
[xboard.git] / winboard / wgamelist.c
index 4fa6025..196c837 100644 (file)
@@ -164,7 +164,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 +197,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 +406,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 +428,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 +437,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
-  SendDlgItemMessage(gameListDialog, OPT_GameListText,\r
-    LB_SETCURSEL, i, 0);\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, LB_SETCURSEL, j, 0);\r
 }\r
 \r
 \r