X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwgamelist.c;h=19917e6a1cbd08cc082113ff21a4a466d94941a7;hb=HEAD;hp=d0b624c2d012bba262ad4d4a891dccc655049ef1;hpb=e70077aab0199817f37aef9ed0bdba1bbca93b45;p=xboard.git diff --git a/winboard/wgamelist.c b/winboard/wgamelist.c index d0b624c..19917e6 100644 --- a/winboard/wgamelist.c +++ b/winboard/wgamelist.c @@ -1,7 +1,8 @@ /* * wgamelist.c -- Game list window for WinBoard * - * Copyright 1995, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + * Copyright 1995, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free + * Software Foundation, Inc. * * Enhancements Copyright 2005 Alessandro Scotti * @@ -48,16 +49,8 @@ static BOOLEAN gameListUp = FALSE; static FILE* gameFile; static char* gameFileName = NULL; -struct GameListStats -{ - int white_wins; - int black_wins; - int drawn; - int unfinished; -}; - /* [AS] Setup the game list according to the specified filter */ -static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct GameListStats * stats, BOOL byPos ) +int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct GameListStats * stats, BOOL byPos, BOOL narrow ) { ListGame * lg = (ListGame *) gameList.head; int nItem; @@ -66,6 +59,9 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct int count = 0; struct GameListStats dummy; + if(!hDlg) hDlg = gameListDialog; // [HGM] to allow calling from Game List Options dialog + if(!hDlg) return 0; + /* Initialize stats (use a dummy variable if caller not interested in them) */ if( stats == NULL ) { stats = &dummy; @@ -95,9 +91,10 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct if(nItem % 2000 == 0) { snprintf(buf, MSG_SIZ, _("Scanning through games (%d)"), nItem); - SetWindowText(hwndMain, buf); + SetWindowText(hwndMain, buf); DoEvents(); } + if(!narrow || lg->position >= 0) { if( hasFilter ) { st = GameListLine(lg->number, &lg->gameInfo); if( !SearchPattern( st, pszFilter) ) skip = TRUE; @@ -107,8 +104,6 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct if( (pos = GameContainsPosition(gameFile, lg)) < 0) skip = TRUE; } - lg->position = pos; - if( ! skip ) { if(!st) st = GameListLine(lg->number, &lg->gameInfo); SendDlgItemMessage(hDlg, OPT_GameListText, LB_ADDSTRING, 0, (LPARAM) st); @@ -123,7 +118,11 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct stats->drawn++; else stats->unfinished++; + if(!byPos) pos = 0; } + } + + lg->position = pos; if(st) free(st); lg = (ListGame *) lg->node.succ; @@ -161,7 +160,7 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) int nItem; RECT rect; static int sizeX, sizeY; - int newSizeX, newSizeY, flags; + int newSizeX, newSizeY; MINMAXINFO *mmi; static BOOL filterHasFocus = FALSE; int count; @@ -184,7 +183,7 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) /* Set font */ SendDlgItemMessage( hDlg, OPT_GameListText, WM_SETFONT, (WPARAM)font[boardSize][GAMELIST_FONT]->hf, MAKELPARAM(TRUE, 0 )); - count = GameListToListBox( hDlg, gameListDialog ? TRUE : FALSE, NULL, &stats, FALSE ); + count = GameListToListBox( hDlg, gameListDialog ? TRUE : FALSE, NULL, &stats, FALSE, FALSE ); SendDlgItemMessage( hDlg, IDC_GameListFilter, WM_SETTEXT, 0, (LPARAM) "" ); SendDlgItemMessage( hDlg, IDC_GameListFilter, EM_SETLIMITTEXT, MAX_FILTER_LENGTH, 0 ); @@ -194,7 +193,6 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) /* Size and position the dialog */ if (!gameListDialog) { gameListDialog = hDlg; - flags = SWP_NOZORDER; GetClientRect(hDlg, &rect); sizeX = rect.right; sizeY = rect.bottom; @@ -302,6 +300,7 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) break; /* load the game*/ case OPT_GameListPrev: +#if 0 nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0); nItem--; if (nItem < 0) { @@ -311,7 +310,7 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0); break; /* load the game*/ - +#endif /* [AS] */ case OPT_GameListFind: case IDC_GameListDoFilter: @@ -320,7 +319,7 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) if( GetDlgItemText( hDlg, IDC_GameListFilter, filter, sizeof(filter) ) >= 0 ) { filter[ sizeof(filter)-1 ] = '\0'; - count = GameListToListBox( hDlg, TRUE, filter, &stats, LOWORD(wParam)!=IDC_GameListDoFilter ); + count = GameListToListBox( hDlg, TRUE, filter, &stats, LOWORD(wParam)!=IDC_GameListDoFilter, LOWORD(wParam)==OPT_GameListNarrow ); GameListUpdateTitle( hDlg, _("Game List"), count, ((ListGame *) gameList.tailPred)->number, &stats ); } } @@ -403,6 +402,7 @@ VOID GameListPopUp(FILE *fp, char *filename) gameFileName = StrSave(filename); } CheckMenuItem(GetMenu(hwndMain), IDM_ShowGameList, MF_CHECKED); + EnableMenuItem(GetMenu(hwndMain), IDM_SaveSelected, MF_ENABLED); if (gameListDialog) { SendMessage(gameListDialog, WM_INITDIALOG, 0, 0); if (!gameListUp) ShowWindow(gameListDialog, SW_SHOW); @@ -416,9 +416,15 @@ VOID GameListPopUp(FILE *fp, char *filename) gameListUp = TRUE; } +FILE *GameFile() +{ + return gameFile; +} + VOID GameListPopDown(void) { CheckMenuItem(GetMenu(hwndMain), IDM_ShowGameList, MF_UNCHECKED); + EnableMenuItem(GetMenu(hwndMain), IDM_SaveSelected, MF_GRAYED); if (gameListDialog) ShowWindow(gameListDialog, SW_HIDE); gameListUp = FALSE; } @@ -427,14 +433,22 @@ VOID GameListPopDown(void) VOID GameListHighlight(int index) { char buf[MSG_SIZ]; - int i, res = 0; + int i, j, k, n, res = 0; if (gameListDialog == NULL) return; - for(i=0; res != LB_ERR; i++) { + for(i=64; ; i+=i) { res = SendDlgItemMessage( gameListDialog, OPT_GameListText, LB_GETTEXT, i, (LPARAM)buf ); - if(index <= atoi( buf )) break; + if(res == LB_ERR || index < atoi( buf )) break; + } + j = i/2; + while(i-j > 1) { + n = (i + j) >> 1; + res = SendDlgItemMessage( gameListDialog, OPT_GameListText, LB_GETTEXT, n, (LPARAM)buf ); + if(res == LB_ERR || index < (k = atoi( buf ))) i = n; else { + j = n; + if(index == k) break; + } } - SendDlgItemMessage(gameListDialog, OPT_GameListText, - LB_SETCURSEL, i, 0); + SendDlgItemMessage(gameListDialog, OPT_GameListText, LB_SETCURSEL, j, 0); }