--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <fcntl.h>
+#include <math.h>
+
+#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' );
+}
+
return result;\r
}\r
\r
-/* [AS] Game list options */\r
-typedef struct {\r
- char id;\r
- char * name;\r
-} GLT_Item;\r
-\r
-static GLT_Item GLT_ItemInfo[] = {\r
- { GLT_EVENT, "Event" },\r
- { GLT_SITE, "Site" },\r
- { GLT_DATE, "Date" },\r
- { GLT_ROUND, "Round" },\r
- { GLT_PLAYERS, "Players" },\r
- { GLT_RESULT, "Result" },\r
- { GLT_WHITE_ELO, "White Rating" },\r
- { GLT_BLACK_ELO, "Black Rating" },\r
- { GLT_TIME_CONTROL,"Time Control" },\r
- { GLT_VARIANT, "Variant" },\r
- { GLT_OUT_OF_BOOK,PGN_OUT_OF_BOOK },\r
- { GLT_RESULT_COMMENT, "Result Comment" }, // [HGM] rescom\r
- { 0, 0 }\r
-};\r
-\r
-const char * GLT_FindItem( char id )\r
-{\r
- const char * result = 0;\r
+/* [AS] Game list options. Refactored by HGM */\r
\r
- GLT_Item * list = GLT_ItemInfo;\r
+HWND gameListOptionsDialog;\r
\r
- while( list->id != 0 ) {\r
- if( list->id == id ) {\r
- result = list->name;\r
- break;\r
- }\r
-\r
- list++;\r
- }\r
-\r
- return result;\r
+// low-level front-end: clear text edit / list widget\r
+void\r
+GLT_ClearList()\r
+{\r
+ SendDlgItemMessage( gameListOptionsDialog, IDC_GameListTags, LB_RESETCONTENT, 0, 0 );\r
}\r
\r
-void GLT_AddToList( HWND hDlg, int iDlgItem, char id, int index )\r
+// low-level front-end: clear text edit / list widget\r
+void\r
+GLT_DeSelectList()\r
{\r
- const char * name = GLT_FindItem( id );\r
-\r
- if( name != 0 ) {\r
- if( index >= 0 ) {\r
- SendDlgItemMessage( hDlg, iDlgItem, LB_INSERTSTRING, index, (LPARAM) name );\r
- }\r
- else {\r
- SendDlgItemMessage( hDlg, iDlgItem, LB_ADDSTRING, 0, (LPARAM) name );\r
- }\r
- }\r
+ SendDlgItemMessage( gameListOptionsDialog, IDC_GameListTags, LB_SETCURSEL, 0, 0 );\r
}\r
\r
-void GLT_TagsToList( HWND hDlg, char * tags )\r
+// low-level front-end: append line to text edit / list widget\r
+void\r
+GLT_AddToList( char *name )\r
{\r
- char * pc = tags;\r
-\r
- SendDlgItemMessage( hDlg, IDC_GameListTags, LB_RESETCONTENT, 0, 0 );\r
-\r
- while( *pc ) {\r
- GLT_AddToList( hDlg, IDC_GameListTags, *pc, -1 );\r
- pc++;\r
- }\r
-\r
- SendDlgItemMessage( hDlg, IDC_GameListTags, LB_ADDSTRING, 0, (LPARAM) "\t --- Hidden tags ---" );\r
-\r
- pc = GLT_ALL_TAGS;\r
-\r
- while( *pc ) {\r
- if( strchr( tags, *pc ) == 0 ) {\r
- GLT_AddToList( hDlg, IDC_GameListTags, *pc, -1 );\r
- }\r
- pc++;\r
+ if( name != 0 ) {\r
+ SendDlgItemMessage( gameListOptionsDialog, IDC_GameListTags, LB_ADDSTRING, 0, (LPARAM) name );\r
}\r
-\r
- SendDlgItemMessage( hDlg, IDC_GameListTags, LB_SETCURSEL, 0, 0 );\r
}\r
\r
-char GLT_ListItemToTag( HWND hDlg, int index )\r
+// low-level front-end: get line from text edit / list widget\r
+Boolean\r
+GLT_GetFromList( int index, char *name )\r
{\r
- char result = '\0';\r
- char name[128];\r
-\r
- GLT_Item * list = GLT_ItemInfo;\r
-\r
- if( SendDlgItemMessage( hDlg, IDC_GameListTags, LB_GETTEXT, index, (LPARAM) name ) != LB_ERR ) {\r
- while( list->id != 0 ) {\r
- if( strcmp( list->name, name ) == 0 ) {\r
- result = list->id;\r
- break;\r
- }\r
-\r
- list++;\r
- }\r
+ if( name != 0 ) {\r
+ if( SendDlgItemMessage( gameListOptionsDialog, IDC_GameListTags, LB_GETTEXT, index, (LPARAM) name ) != LB_ERR )\r
+ return TRUE;\r
}\r
-\r
- return result;\r
+ return FALSE;\r
}\r
\r
void GLT_MoveSelection( HWND hDlg, int delta )\r
\r
LRESULT CALLBACK GameListOptions_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
{\r
- static char glt[64];\r
- static char * lpUserGLT;\r
-\r
switch( message )\r
{\r
case WM_INITDIALOG:\r
- lpUserGLT = (char *) lParam;\r
+ gameListOptionsDialog = hDlg; // [HGM] pass through global to keep out off back-end\r
\r
- strcpy( glt, lpUserGLT );\r
-\r
CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER));\r
\r
/* Initialize list */\r
- GLT_TagsToList( hDlg, glt );\r
+ GLT_TagsToList( lpUserGLT );\r
\r
SetFocus( GetDlgItem(hDlg, IDC_GameListTags) );\r
\r
case WM_COMMAND:\r
switch( LOWORD(wParam) ) {\r
case IDOK:\r
- {\r
- char * pc = lpUserGLT;\r
- int idx = 0;\r
-// int cnt = (int) SendDlgItemMessage( hDlg, IDC_GameListTags, LB_GETCOUNT, 0, 0 );\r
- char id;\r
-\r
- do {\r
- id = GLT_ListItemToTag( hDlg, idx );\r
-\r
- *pc++ = id;\r
- idx++;\r
- } while( id != '\0' );\r
- }\r
+ GLT_ParseList();\r
EndDialog( hDlg, 0 );\r
return TRUE;\r
case IDCANCEL:\r
return TRUE;\r
\r
case IDC_GLT_Default:\r
- strcpy( glt, GLT_DEFAULT_TAGS );\r
- GLT_TagsToList( hDlg, glt );\r
+ GLT_TagsToList( GLT_DEFAULT_TAGS );\r
return TRUE;\r
\r
case IDC_GLT_Restore:\r
- strcpy( glt, lpUserGLT );\r
- GLT_TagsToList( hDlg, glt );\r
+ GLT_TagsToList( appData.gameListTags );\r
return TRUE;\r
\r
case IDC_GLT_Up:\r
\r
int GameListOptions()\r
{\r
- char glt[64];\r
int result;\r
FARPROC lpProc = MakeProcInstance( (FARPROC) GameListOptions_Proc, hInst );\r
\r
- strcpy( glt, appData.gameListTags );\r
+ strcpy( lpUserGLT, appData.gameListTags );\r
\r
- result = DialogBoxParam( hInst, MAKEINTRESOURCE(DLG_GameListOptions), hwndMain, (DLGPROC)lpProc, (LPARAM)glt );\r
+ result = DialogBoxParam( hInst, MAKEINTRESOURCE(DLG_GameListOptions), hwndMain, (DLGPROC)lpProc, (LPARAM)lpUserGLT );\r
\r
if( result == 0 ) {\r
/* [AS] Memory leak here! */\r
- appData.gameListTags = strdup( glt ); \r
+ appData.gameListTags = strdup( lpUserGLT ); \r
}\r
\r
return result;\r
}\r
\r
-\r
VOID\r
DisplayIcsInteractionTitle(char *str)\r
{\r