X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwgamelist.c;h=19917e6a1cbd08cc082113ff21a4a466d94941a7;hb=HEAD;hp=e582a468ae02fd5095d3f6c7175739609cbf0199;hpb=79173c63a1184a8c99f5b25ae5d20ccf27ac01bc;p=xboard.git diff --git a/winboard/wgamelist.c b/winboard/wgamelist.c index e582a46..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 Free Software Foundation, Inc. + * Copyright 1995, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free + * Software Foundation, Inc. * * Enhancements Copyright 2005 Alessandro Scotti * @@ -48,25 +49,21 @@ 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 ) +int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct GameListStats * stats, BOOL byPos, BOOL narrow ) { ListGame * lg = (ListGame *) gameList.head; int nItem; + char buf[MSG_SIZ]; BOOL hasFilter = FALSE; 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 ) { + if( stats == NULL ) { stats = &dummy; } @@ -85,17 +82,30 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct } } + if(byPos) InitSearch(); + for (nItem = 0; nItem < ((ListGame *) gameList.tailPred)->number; nItem++){ - char * st = GameListLine(lg->number, &lg->gameInfo); + char * st = NULL; BOOL skip = FALSE; + int pos = -1; + if(nItem % 2000 == 0) { + snprintf(buf, MSG_SIZ, _("Scanning through games (%d)"), nItem); + SetWindowText(hwndMain, buf); DoEvents(); + } + + if(!narrow || lg->position >= 0) { if( hasFilter ) { - if( ! SearchPattern( st, pszFilter ) ) { - skip = TRUE; - } + st = GameListLine(lg->number, &lg->gameInfo); + if( !SearchPattern( st, pszFilter) ) skip = TRUE; + } + + if( !skip && byPos) { + if( (pos = GameContainsPosition(gameFile, lg)) < 0) skip = TRUE; } if( ! skip ) { + if(!st) st = GameListLine(lg->number, &lg->gameInfo); SendDlgItemMessage(hDlg, OPT_GameListText, LB_ADDSTRING, 0, (LPARAM) st); count++; @@ -108,13 +118,18 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct stats->drawn++; else stats->unfinished++; + if(!byPos) pos = 0; } + } - free(st); + lg->position = pos; + + if(st) free(st); lg = (ListGame *) lg->node.succ; } SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, 0, 0); + SetWindowText(hwndMain, "WinBoard"); return count; } @@ -124,7 +139,7 @@ static int GameListUpdateTitle( HWND hDlg, char * pszTitle, int item_count, int { char buf[256]; - sprintf( buf, _("%s - %d/%d games"), pszTitle, item_count, item_total ); + snprintf( buf, sizeof(buf)/sizeof(buf[0]),_("%s - %d/%d games"), pszTitle, item_count, item_total ); if( stats != 0 ) { sprintf( buf+strlen(buf), " (%d-%d-%d)", stats->white_wins, stats->black_wins, stats->drawn ); @@ -145,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; @@ -153,7 +168,7 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) static SnapData sd; switch (message) { - case WM_INITDIALOG: + case WM_INITDIALOG: Translate(hDlg, DLG_GameList); GetWindowText( hDlg, szDlgTitle, sizeof(szDlgTitle) ); szDlgTitle[ sizeof(szDlgTitle)-1 ] = '\0'; @@ -166,9 +181,9 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) hwndText = GetDlgItem(hDlg, OPT_TagsText); /* Set font */ - SendDlgItemMessage( hDlg, OPT_GameListText, WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, MAKELPARAM(TRUE, 0 )); + SendDlgItemMessage( hDlg, OPT_GameListText, WM_SETFONT, (WPARAM)font[boardSize][GAMELIST_FONT]->hf, MAKELPARAM(TRUE, 0 )); - count = GameListToListBox( hDlg, gameListDialog ? TRUE : FALSE, NULL, &stats ); + 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 ); @@ -178,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; @@ -203,13 +217,14 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) newSizeX, newSizeY); sizeX = newSizeX; sizeY = newSizeY; - } else + } else GetActualPlacement( gameListDialog, &wpGameList ); } GameListUpdateTitle( hDlg, _("Game List"), count, ((ListGame *) gameList.tailPred)->number, &stats ); // [HGM] always update title + GameListHighlight(lastLoadGameNumber); return FALSE; - + case WM_SIZE: newSizeX = LOWORD(lParam); newSizeY = HIWORD(lParam); @@ -230,7 +245,7 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_EXITSIZEMOVE: return OnExitSizeMove( &sd, hDlg, wParam, lParam ); - + case WM_GETMINMAXINFO: /* Prevent resizing window too small */ mmi = (MINMAXINFO *) lParam; @@ -239,7 +254,7 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_COMMAND: - /* + /* [AS] If is pressed while editing the filter, it's better to apply the filter rather than selecting the current game. @@ -261,8 +276,10 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) /* [AS] End command replacement */ switch (LOWORD(wParam)) { - case IDOK: case OPT_GameListLoad: + LoadOptionsPopup(hDlg); + return TRUE; + case IDOK: nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0); if (nItem < 0) { /* is this possible? */ @@ -270,7 +287,7 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) return TRUE; } break; /* load the game*/ - + case OPT_GameListNext: nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0); nItem++; @@ -281,8 +298,9 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0); break; /* load the game*/ - + case OPT_GameListPrev: +#if 0 nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0); nItem--; if (nItem < 0) { @@ -292,15 +310,16 @@ 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: { char filter[MAX_FILTER_LENGTH+1]; - + if( GetDlgItemText( hDlg, IDC_GameListFilter, filter, sizeof(filter) ) >= 0 ) { filter[ sizeof(filter)-1 ] = '\0'; - count = GameListToListBox( hDlg, TRUE, filter, &stats ); + count = GameListToListBox( hDlg, TRUE, filter, &stats, LOWORD(wParam)!=IDC_GameListDoFilter, LOWORD(wParam)==OPT_GameListNarrow ); GameListUpdateTitle( hDlg, _("Game List"), count, ((ListGame *) gameList.tailPred)->number, &stats ); } } @@ -311,13 +330,13 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case OPT_GameListClose: GameListPopDown(); return TRUE; - + case OPT_GameListText: switch (HIWORD(wParam)) { case LBN_DBLCLK: nItem = SendMessage((HWND) lParam, LB_GETCURSEL, 0, 0); break; /* load the game*/ - + default: return FALSE; } @@ -359,8 +378,8 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) CmailLoadGame(gameFile, nItem + 1, gameFileName, TRUE); } else { - SetFocus(hwndMain); // [HGM] automatic focus switch LoadGame(gameFile, nItem + 1, gameFileName, TRUE); + SetFocus(hwndMain); // [HGM] automatic focus switch } } @@ -376,13 +395,14 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) VOID GameListPopUp(FILE *fp, char *filename) { FARPROC lpProc; - + gameFile = fp; if (gameFileName != filename) { if (gameFileName) free(gameFileName); 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); @@ -396,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; } @@ -406,9 +432,23 @@ VOID GameListPopDown(void) VOID GameListHighlight(int index) { + char buf[MSG_SIZ]; + int i, j, k, n, res = 0; if (gameListDialog == NULL) return; - SendDlgItemMessage(gameListDialog, OPT_GameListText, - LB_SETCURSEL, index - 1, 0); + for(i=64; ; i+=i) { + res = SendDlgItemMessage( gameListDialog, OPT_GameListText, LB_GETTEXT, i, (LPARAM)buf ); + 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, j, 0); }