From: H.G. Muller Date: Fri, 29 Jan 2010 11:48:50 +0000 (+0100) Subject: Refactoring of game-list-options dialog X-Git-Tag: master-20100206~19 X-Git-Url: http://winboard.nl/cgi-bin?p=xboard.git;a=commitdiff_plain;h=671b4c9fb4a307e0caaec84408afefa455901cca Refactoring of game-list-options dialog The back-end part is separated off, and moved to a file gamelistopt.c. Front-end for now stays in winboard.c. No prototypes in frontend.h yet. --- diff --git a/backend.h b/backend.h index 6899eef..effe385 100644 --- a/backend.h +++ b/backend.h @@ -264,6 +264,8 @@ int GameListBuild P((FILE *)); void GameListInitGameInfo P((GameInfo *)); char *GameListLine P((int, GameInfo *)); char * GameListLineFull P(( int, GameInfo *)); +void GLT_TagsToList P(( char * tags )); +void GLT_ParseList P((void)); extern char* StripHighlight P((char *)); /* returns static data */ extern char* StripHighlightAndTitle P((char *)); /* returns static data */ diff --git a/gamelistopt.c b/gamelistopt.c new file mode 100644 index 0000000..8cc3662 --- /dev/null +++ b/gamelistopt.c @@ -0,0 +1,151 @@ +/* + * gamelistopt.c -- Game list window for WinBoard + * + * Copyright 1995,2009 Free Software Foundation, Inc. + * + * Enhancements Copyright 2005 Alessandro Scotti + * + * ------------------------------------------------------------------------ + * + * GNU XBoard is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * GNU XBoard is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. * + * + *------------------------------------------------------------------------ + ** See the file ChangeLog for a revision history. */ + +#include "config.h" + +#include +#include +#include +#include +#include + +#include "common.h" +#include "frontend.h" +#include "backend.h" + +void GLT_ClearList(); +void GLT_DeSelectList(); +void GLT_AddToList( char *name ); +Boolean GLT_GetFromList( int index, char *name ); + +// back-end +typedef struct { + char id; + char * name; +} GLT_Item; + +// back-end: translation table tag id-char <-> full tag name +static GLT_Item GLT_ItemInfo[] = { + { GLT_EVENT, "Event" }, + { GLT_SITE, "Site" }, + { GLT_DATE, "Date" }, + { GLT_ROUND, "Round" }, + { GLT_PLAYERS, "Players" }, + { GLT_RESULT, "Result" }, + { GLT_WHITE_ELO, "White Rating" }, + { GLT_BLACK_ELO, "Black Rating" }, + { GLT_TIME_CONTROL,"Time Control" }, + { GLT_VARIANT, "Variant" }, + { GLT_OUT_OF_BOOK,PGN_OUT_OF_BOOK }, + { GLT_RESULT_COMMENT, "Result Comment" }, // [HGM] rescom + { 0, 0 } +}; + +char lpUserGLT[64]; + +// back-end: convert the tag id-char to a full tag name +char * GLT_FindItem( char id ) +{ + char * result = 0; + + GLT_Item * list = GLT_ItemInfo; + + while( list->id != 0 ) { + if( list->id == id ) { + result = list->name; + break; + } + + list++; + } + + return result; +} + +// back-end: build the list of tag names +void +GLT_TagsToList( char * tags ) +{ + char * pc = tags; + + GLT_ClearList(); + + while( *pc ) { + GLT_AddToList( GLT_FindItem(*pc) ); + pc++; + } + + GLT_AddToList( "\t --- Hidden tags ---" ); + + pc = GLT_ALL_TAGS; + + while( *pc ) { + if( strchr( tags, *pc ) == 0 ) { + GLT_AddToList( GLT_FindItem(*pc) ); + } + pc++; + } + + GLT_DeSelectList(); +} + +// back-end: retrieve item from dialog and translate to id-char +char +GLT_ListItemToTag( int index ) +{ + char result = '\0'; + char name[128]; + + GLT_Item * list = GLT_ItemInfo; + + if( GLT_GetFromList(index, name) ) { + while( list->id != 0 ) { + if( strcmp( list->name, name ) == 0 ) { + result = list->id; + break; + } + + list++; + } + } + + return result; +} + +// back-end: add items id-chars one-by-one to temp tags string +void +GLT_ParseList() +{ + char * pc = lpUserGLT; + int idx = 0; + char id; + + do { + id = GLT_ListItemToTag( idx ); + *pc++ = id; + idx++; + } while( id != '\0' ); +} + diff --git a/winboard/makefile.gcc b/winboard/makefile.gcc index 778883e..7e37463 100644 --- a/winboard/makefile.gcc +++ b/winboard/makefile.gcc @@ -4,7 +4,7 @@ PROJ=winboard -OBJS=backend.o book.o gamelist.o lists.o moves.o pgntags.o uci.o zippy.o\ +OBJS=backend.o book.o gamelist.o gamelistopt.o lists.o moves.o pgntags.o uci.o zippy.o\ parser.o wbres.o wclipbrd.o wedittags.o wengineoutput.o wevalgraph.o\ wgamelist.o whistory.o history.o winboard.o wlayout.o woptions.o wsnap.o\ wsockerr.o help.o wsettings.o wchat.o engineoutput.o evalgraph.o @@ -109,6 +109,10 @@ gamelist.o: ../gamelist.c config.h ../lists.h ../common.h ../frontend.h \ ../backend.h ../parser.h $(call compile, $<) +gamelistopt.o: ../gamelistopt.c config.h ../lists.h ../common.h ../frontend.h \ + ../backend.h + $(call compile, $<) + wclipbrd.o: wclipbrd.c config.h ../common.h ../frontend.h ../backend.h \ winboard.h resource.h wclipbrd.h ../lists.h $(call compile, $<) diff --git a/winboard/makefile.ms b/winboard/makefile.ms index 759139e..fb3e790 100644 --- a/winboard/makefile.ms +++ b/winboard/makefile.ms @@ -12,7 +12,7 @@ VCVER=6 PROJ = winboard -OBJS=backend.obj book.obj gamelist.obj lists.obj moves.obj pgntags.obj uci.obj\ +OBJS=backend.obj book.obj gamelist.obj gamelistopt.obj lists.obj moves.obj pgntags.obj uci.obj\ zippy.obj parser.obj wclipbrd.obj wedittags.obj wengineoutput.obj wevalgraph.obj\ wgamelist.obj whistory.obj history.obj winboard.obj wlayout.obj woptions.obj wsnap.obj\ wsockerr.obj help.obj wsettings.obj wchat.obj engineoutput.obj evalgraph.obj @@ -110,6 +110,10 @@ gamelist.obj: ../gamelist.c config.h ../lists.h ../common.h ../frontend.h \ ../backend.h ../parser.h $(CC) $(CFLAGS) ../gamelist.c +gamelistopt.obj: ../gamelistopt.c config.h ../lists.h ../common.h ../frontend.h \ + ../backend.h + $(CC) $(CFLAGS) ../gamelistopt.c + lists.obj: ../lists.c config.h ../lists.h ../common.h $(CC) $(CFLAGS) ../lists.c diff --git a/winboard/winboard.c b/winboard/winboard.c index 8a965c4..d790116 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -7868,104 +7868,42 @@ int NewGameFRC() return result; } -/* [AS] Game list options */ -typedef struct { - char id; - char * name; -} GLT_Item; - -static GLT_Item GLT_ItemInfo[] = { - { GLT_EVENT, "Event" }, - { GLT_SITE, "Site" }, - { GLT_DATE, "Date" }, - { GLT_ROUND, "Round" }, - { GLT_PLAYERS, "Players" }, - { GLT_RESULT, "Result" }, - { GLT_WHITE_ELO, "White Rating" }, - { GLT_BLACK_ELO, "Black Rating" }, - { GLT_TIME_CONTROL,"Time Control" }, - { GLT_VARIANT, "Variant" }, - { GLT_OUT_OF_BOOK,PGN_OUT_OF_BOOK }, - { GLT_RESULT_COMMENT, "Result Comment" }, // [HGM] rescom - { 0, 0 } -}; - -const char * GLT_FindItem( char id ) -{ - const char * result = 0; +/* [AS] Game list options. Refactored by HGM */ - GLT_Item * list = GLT_ItemInfo; +HWND gameListOptionsDialog; - while( list->id != 0 ) { - if( list->id == id ) { - result = list->name; - break; - } - - list++; - } - - return result; +// low-level front-end: clear text edit / list widget +void +GLT_ClearList() +{ + SendDlgItemMessage( gameListOptionsDialog, IDC_GameListTags, LB_RESETCONTENT, 0, 0 ); } -void GLT_AddToList( HWND hDlg, int iDlgItem, char id, int index ) +// low-level front-end: clear text edit / list widget +void +GLT_DeSelectList() { - const char * name = GLT_FindItem( id ); - - if( name != 0 ) { - if( index >= 0 ) { - SendDlgItemMessage( hDlg, iDlgItem, LB_INSERTSTRING, index, (LPARAM) name ); - } - else { - SendDlgItemMessage( hDlg, iDlgItem, LB_ADDSTRING, 0, (LPARAM) name ); - } - } + SendDlgItemMessage( gameListOptionsDialog, IDC_GameListTags, LB_SETCURSEL, 0, 0 ); } -void GLT_TagsToList( HWND hDlg, char * tags ) +// low-level front-end: append line to text edit / list widget +void +GLT_AddToList( char *name ) { - char * pc = tags; - - SendDlgItemMessage( hDlg, IDC_GameListTags, LB_RESETCONTENT, 0, 0 ); - - while( *pc ) { - GLT_AddToList( hDlg, IDC_GameListTags, *pc, -1 ); - pc++; - } - - SendDlgItemMessage( hDlg, IDC_GameListTags, LB_ADDSTRING, 0, (LPARAM) "\t --- Hidden tags ---" ); - - pc = GLT_ALL_TAGS; - - while( *pc ) { - if( strchr( tags, *pc ) == 0 ) { - GLT_AddToList( hDlg, IDC_GameListTags, *pc, -1 ); - } - pc++; + if( name != 0 ) { + SendDlgItemMessage( gameListOptionsDialog, IDC_GameListTags, LB_ADDSTRING, 0, (LPARAM) name ); } - - SendDlgItemMessage( hDlg, IDC_GameListTags, LB_SETCURSEL, 0, 0 ); } -char GLT_ListItemToTag( HWND hDlg, int index ) +// low-level front-end: get line from text edit / list widget +Boolean +GLT_GetFromList( int index, char *name ) { - char result = '\0'; - char name[128]; - - GLT_Item * list = GLT_ItemInfo; - - if( SendDlgItemMessage( hDlg, IDC_GameListTags, LB_GETTEXT, index, (LPARAM) name ) != LB_ERR ) { - while( list->id != 0 ) { - if( strcmp( list->name, name ) == 0 ) { - result = list->id; - break; - } - - list++; - } + if( name != 0 ) { + if( SendDlgItemMessage( gameListOptionsDialog, IDC_GameListTags, LB_GETTEXT, index, (LPARAM) name ) != LB_ERR ) + return TRUE; } - - return result; + return FALSE; } void GLT_MoveSelection( HWND hDlg, int delta ) @@ -7986,20 +7924,15 @@ void GLT_MoveSelection( HWND hDlg, int delta ) LRESULT CALLBACK GameListOptions_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - static char glt[64]; - static char * lpUserGLT; - switch( message ) { case WM_INITDIALOG: - lpUserGLT = (char *) lParam; + gameListOptionsDialog = hDlg; // [HGM] pass through global to keep out off back-end - strcpy( glt, lpUserGLT ); - CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER)); /* Initialize list */ - GLT_TagsToList( hDlg, glt ); + GLT_TagsToList( lpUserGLT ); SetFocus( GetDlgItem(hDlg, IDC_GameListTags) ); @@ -8008,19 +7941,7 @@ LRESULT CALLBACK GameListOptions_Proc(HWND hDlg, UINT message, WPARAM wParam, LP case WM_COMMAND: switch( LOWORD(wParam) ) { case IDOK: - { - char * pc = lpUserGLT; - int idx = 0; -// int cnt = (int) SendDlgItemMessage( hDlg, IDC_GameListTags, LB_GETCOUNT, 0, 0 ); - char id; - - do { - id = GLT_ListItemToTag( hDlg, idx ); - - *pc++ = id; - idx++; - } while( id != '\0' ); - } + GLT_ParseList(); EndDialog( hDlg, 0 ); return TRUE; case IDCANCEL: @@ -8028,13 +7949,11 @@ LRESULT CALLBACK GameListOptions_Proc(HWND hDlg, UINT message, WPARAM wParam, LP return TRUE; case IDC_GLT_Default: - strcpy( glt, GLT_DEFAULT_TAGS ); - GLT_TagsToList( hDlg, glt ); + GLT_TagsToList( GLT_DEFAULT_TAGS ); return TRUE; case IDC_GLT_Restore: - strcpy( glt, lpUserGLT ); - GLT_TagsToList( hDlg, glt ); + GLT_TagsToList( appData.gameListTags ); return TRUE; case IDC_GLT_Up: @@ -8054,23 +7973,21 @@ LRESULT CALLBACK GameListOptions_Proc(HWND hDlg, UINT message, WPARAM wParam, LP int GameListOptions() { - char glt[64]; int result; FARPROC lpProc = MakeProcInstance( (FARPROC) GameListOptions_Proc, hInst ); - strcpy( glt, appData.gameListTags ); + strcpy( lpUserGLT, appData.gameListTags ); - result = DialogBoxParam( hInst, MAKEINTRESOURCE(DLG_GameListOptions), hwndMain, (DLGPROC)lpProc, (LPARAM)glt ); + result = DialogBoxParam( hInst, MAKEINTRESOURCE(DLG_GameListOptions), hwndMain, (DLGPROC)lpProc, (LPARAM)lpUserGLT ); if( result == 0 ) { /* [AS] Memory leak here! */ - appData.gameListTags = strdup( glt ); + appData.gameListTags = strdup( lpUserGLT ); } return result; } - VOID DisplayIcsInteractionTitle(char *str) {