X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwgamelist.c;h=d0b624c2d012bba262ad4d4a891dccc655049ef1;hb=e70077aab0199817f37aef9ed0bdba1bbca93b45;hp=2fa15333af1f05a20ca6358c7026409a49a8e30d;hpb=bb1c4f8ed2489e4891fe044532a35107d33174d2;p=xboard.git diff --git a/winboard/wgamelist.c b/winboard/wgamelist.c index 2fa1533..d0b624c 100644 --- a/winboard/wgamelist.c +++ b/winboard/wgamelist.c @@ -1,7 +1,7 @@ /* * wgamelist.c -- Game list window for WinBoard * - * Copyright 1995,2009 Free Software Foundation, Inc. + * Copyright 1995, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. * * Enhancements Copyright 2005 Alessandro Scotti * @@ -35,25 +35,18 @@ #include #include "common.h" -#include "winboard.h" #include "frontend.h" #include "backend.h" +#include "winboard.h" #include "wsnap.h" -#include "wgamelist.h" -extern BoardSize boardSize; +#define _(s) T_(s) /* Module globals */ -HWND gameListDialog = NULL; -BOOLEAN gameListUp = FALSE; -FILE* gameFile; -char* gameFileName = NULL; - -/* Imports from winboard.c */ -extern HINSTANCE hInst; -extern HWND hwndMain; -extern WindowPlacement wpGameList; +static BOOLEAN gameListUp = FALSE; +static FILE* gameFile; +static char* gameFileName = NULL; struct GameListStats { @@ -63,73 +56,18 @@ struct GameListStats int unfinished; }; -/* [AS] Wildcard pattern matching */ -static BOOL HasPattern( const char * text, const char * pattern ) -{ - while( *pattern != '\0' ) { - if( *pattern == '*' ) { - while( *pattern == '*' ) { - pattern++; - } - - if( *pattern == '\0' ) { - return TRUE; - } - - while( *text != '\0' ) { - if( HasPattern( text, pattern ) ) { - return TRUE; - } - text++; - } - } - else if( (*pattern == *text) || ((*pattern == '?') && (*text != '\0')) ) { - pattern++; - text++; - continue; - } - - return FALSE; - } - - return TRUE; -} - -static BOOL SearchPattern( const char * text, const char * pattern ) -{ - BOOL result = TRUE; - - if( pattern != NULL && *pattern != '\0' ) { - if( *pattern == '*' ) { - result = HasPattern( text, pattern ); - } - else { - result = FALSE; - - while( *text != '\0' ) { - if( HasPattern( text, pattern ) ) { - result = TRUE; - break; - } - text++; - } - } - } - - return result; -} - /* [AS] Setup the game list according to the specified filter */ -static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct GameListStats * stats ) +static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct GameListStats * stats, BOOL byPos ) { ListGame * lg = (ListGame *) gameList.head; int nItem; + char buf[MSG_SIZ]; BOOL hasFilter = FALSE; int count = 0; struct GameListStats dummy; /* Initialize stats (use a dummy variable if caller not interested in them) */ - if( stats == NULL ) { + if( stats == NULL ) { stats = &dummy; } @@ -148,17 +86,31 @@ 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); + } 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; } + lg->position = pos; + if( ! skip ) { + if(!st) st = GameListLine(lg->number, &lg->gameInfo); SendDlgItemMessage(hDlg, OPT_GameListText, LB_ADDSTRING, 0, (LPARAM) st); count++; @@ -173,11 +125,12 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct stats->unfinished++; } - free(st); + if(st) free(st); lg = (ListGame *) lg->node.succ; } SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, 0, 0); + SetWindowText(hwndMain, "WinBoard"); return count; } @@ -187,7 +140,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 ); @@ -216,7 +169,8 @@ 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'; @@ -228,9 +182,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 ); SendDlgItemMessage( hDlg, IDC_GameListFilter, WM_SETTEXT, 0, (LPARAM) "" ); SendDlgItemMessage( hDlg, IDC_GameListFilter, EM_SETLIMITTEXT, MAX_FILTER_LENGTH, 0 ); @@ -265,12 +219,14 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) newSizeX, newSizeY); sizeX = newSizeX; sizeY = newSizeY; - } + } else + GetActualPlacement( gameListDialog, &wpGameList ); - GameListUpdateTitle( hDlg, szDlgTitle, count, ((ListGame *) gameList.tailPred)->number, &stats ); } + 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); @@ -291,7 +247,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; @@ -300,7 +256,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. @@ -322,47 +278,50 @@ 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? */ - DisplayError("No game selected", 0); + DisplayError(_("No game selected"), 0); return TRUE; } break; /* load the game*/ - + case OPT_GameListNext: nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0); nItem++; if (nItem >= ((ListGame *) gameList.tailPred)->number) { /* [AS] Removed error message */ - /* DisplayError("Can't go forward any further", 0); */ + /* DisplayError(_("Can't go forward any further"), 0); */ return TRUE; } SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0); break; /* load the game*/ - + case OPT_GameListPrev: nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0); nItem--; if (nItem < 0) { /* [AS] Removed error message, added return */ - /* DisplayError("Can't back up any further", 0); */ + /* DisplayError(_("Can't back up any further"), 0); */ return TRUE; } SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0); break; /* load the game*/ /* [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 ); - GameListUpdateTitle( hDlg, szDlgTitle, count, ((ListGame *) gameList.tailPred)->number, &stats ); + count = GameListToListBox( hDlg, TRUE, filter, &stats, LOWORD(wParam)!=IDC_GameListDoFilter ); + GameListUpdateTitle( hDlg, _("Game List"), count, ((ListGame *) gameList.tailPred)->number, &stats ); } } return FALSE; @@ -372,13 +331,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; } @@ -421,6 +380,7 @@ GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } else { LoadGame(gameFile, nItem + 1, gameFileName, TRUE); + SetFocus(hwndMain); // [HGM] automatic focus switch } } @@ -436,7 +396,7 @@ 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); @@ -446,6 +406,7 @@ VOID GameListPopUp(FILE *fp, char *filename) if (gameListDialog) { SendMessage(gameListDialog, WM_INITDIALOG, 0, 0); if (!gameListUp) ShowWindow(gameListDialog, SW_SHOW); + else SetFocus(gameListDialog); } else { lpProc = MakeProcInstance((FARPROC)GameListDialog, hInst); CreateDialog(hInst, MAKEINTRESOURCE(DLG_GameList), @@ -465,9 +426,15 @@ VOID GameListPopDown(void) VOID GameListHighlight(int index) { + char buf[MSG_SIZ]; + int i, res = 0; if (gameListDialog == NULL) return; - SendDlgItemMessage(gameListDialog, OPT_GameListText, - LB_SETCURSEL, index - 1, 0); + for(i=0; res != LB_ERR; i++) { + res = SendDlgItemMessage( gameListDialog, OPT_GameListText, LB_GETTEXT, i, (LPARAM)buf ); + if(index <= atoi( buf )) break; + } + SendDlgItemMessage(gameListDialog, OPT_GameListText, + LB_SETCURSEL, i, 0); } @@ -483,12 +450,13 @@ VOID GameListDestroy() VOID ShowGameListProc() { if (gameListUp) { - GameListPopDown(); + if(gameListDialog) SetFocus(gameListDialog); +// GameListPopDown(); } else { if (gameFileName) { GameListPopUp(gameFile, gameFileName); } else { - DisplayError("No game list", 0); + DisplayError(_("No game list"), 0); } } } @@ -502,7 +470,7 @@ HGLOBAL ExportGameListAsText() DWORD dwLen = 0; if( ! gameFileName || ((ListGame *) gameList.tailPred)->number <= 0 ) { - DisplayError("Game list not loaded or empty", 0); + DisplayError(_(_("Game list not loaded or empty")), 0); return NULL; }