Implement searching games in Game List for a position
[xboard.git] / winboard / wgamelist.c
index 863725a..c5a25f5 100644 (file)
@@ -57,10 +57,11 @@ struct GameListStats
 };\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 )\r
+static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct GameListStats * stats, BOOL byPos )\r
 {\r
     ListGame * lg = (ListGame *) gameList.head;\r
     int nItem;\r
+    char buf[MSG_SIZ];\r
     BOOL hasFilter = FALSE;\r
     int count = 0;\r
     struct GameListStats dummy;\r
@@ -86,16 +87,23 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct
     }\r
 \r
     for (nItem = 0; nItem < ((ListGame *) gameList.tailPred)->number; nItem++){\r
-        char * st = GameListLine(lg->number, &lg->gameInfo);\r
+        char * st = NULL;\r
         BOOL skip = FALSE;\r
+       int pos = -1;\r
 \r
         if( hasFilter ) {\r
-            if( ! SearchPattern( st, pszFilter ) ) {\r
-                skip = TRUE;\r
-            }\r
+            st = GameListLine(lg->number, &lg->gameInfo);\r
+           if( !SearchPattern( st, pszFilter) ) skip = TRUE;\r
+        }\r
+\r
+        if( !skip && byPos) {\r
+            if( (pos = GameContainsPosition(gameFile, lg)) < 0) skip = TRUE;\r
         }\r
 \r
+       lg->position = pos;\r
+\r
         if( ! skip ) {\r
+            if(!st) st = GameListLine(lg->number, &lg->gameInfo);\r
             SendDlgItemMessage(hDlg, OPT_GameListText, LB_ADDSTRING, 0, (LPARAM) st);\r
             count++;\r
 \r
@@ -110,7 +118,7 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct
                 stats->unfinished++;\r
         }\r
 \r
-        free(st);\r
+        if(st) free(st);\r
         lg = (ListGame *) lg->node.succ;\r
     }\r
 \r
@@ -168,7 +176,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
     /* Set font */\r
     SendDlgItemMessage( hDlg, OPT_GameListText, WM_SETFONT, (WPARAM)font[boardSize][GAMELIST_FONT]->hf, MAKELPARAM(TRUE, 0 ));\r
 \r
-    count = GameListToListBox( hDlg, gameListDialog ? TRUE : FALSE, NULL, &stats );\r
+    count = GameListToListBox( hDlg, gameListDialog ? TRUE : FALSE, NULL, &stats, FALSE         );\r
 \r
     SendDlgItemMessage( hDlg, IDC_GameListFilter, WM_SETTEXT, 0, (LPARAM) "" );\r
     SendDlgItemMessage( hDlg, IDC_GameListFilter, EM_SETLIMITTEXT, MAX_FILTER_LENGTH, 0 );\r
@@ -262,8 +270,10 @@ GameListDialog(HWND hDlg, UINT message,    WPARAM wParam, LPARAM lParam)
       /* [AS] End command replacement */\r
 \r
     switch (LOWORD(wParam)) {\r
-    case IDOK:\r
     case OPT_GameListLoad:\r
+      LoadOptionsPopup(hDlg);\r
+      return TRUE;\r
+    case IDOK:\r
       nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);\r
       if (nItem < 0) {\r
        /* is this possible? */\r
@@ -283,7 +293,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
       SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0);\r
       break; /* load the game*/\r
 \r
-    case OPT_GameListPrev:\r
+//    case OPT_GameListPrev:\r
       nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);\r
       nItem--;\r
       if (nItem < 0) {\r
@@ -295,13 +305,14 @@ GameListDialog(HWND hDlg, UINT message,   WPARAM wParam, LPARAM lParam)
       break; /* load the game*/\r
 \r
     /* [AS] */\r
+    case OPT_GameListPrev:\r
     case IDC_GameListDoFilter:\r
         {\r
             char filter[MAX_FILTER_LENGTH+1];\r
 \r
             if( GetDlgItemText( hDlg, IDC_GameListFilter, filter, sizeof(filter) ) >= 0 ) {\r
                 filter[ sizeof(filter)-1 ] = '\0';\r
-                count = GameListToListBox( hDlg, TRUE, filter, &stats );\r
+                count = GameListToListBox( hDlg, TRUE, filter, &stats, LOWORD(wParam)!=IDC_GameListDoFilter );\r
                 GameListUpdateTitle( hDlg, _("Game List"), count, ((ListGame *) gameList.tailPred)->number, &stats );\r
             }\r
         }\r