Updated copyright notice to 2011
[xboard.git] / winboard / wgamelist.c
index 2fa1533..48aa85d 100644 (file)
@@ -1,7 +1,7 @@
 /*\r
  * wgamelist.c -- Game list window for WinBoard\r
  *\r
- * Copyright 1995,2009 Free Software Foundation, Inc.\r
+ * Copyright 1995, 2009, 2010, 2011 Free Software Foundation, Inc.\r
  *\r
  * Enhancements Copyright 2005 Alessandro Scotti\r
  *\r
 #include <dlgs.h>\r
 \r
 #include "common.h"\r
-#include "winboard.h"\r
 #include "frontend.h"\r
 #include "backend.h"\r
+#include "winboard.h"\r
 \r
 #include "wsnap.h"\r
-#include "wgamelist.h"\r
 \r
-extern BoardSize boardSize;\r
+#define _(s) T_(s)\r
 \r
 /* Module globals */\r
-HWND gameListDialog = NULL;\r
-BOOLEAN gameListUp = FALSE;\r
-FILE* gameFile;\r
-char* gameFileName = NULL;\r
-\r
-/* Imports from winboard.c */\r
-extern HINSTANCE hInst;\r
-extern HWND hwndMain;\r
-extern WindowPlacement wpGameList;\r
+static BOOLEAN gameListUp = FALSE;\r
+static FILE* gameFile;\r
+static char* gameFileName = NULL;\r
 \r
 struct GameListStats\r
 {\r
@@ -63,62 +56,6 @@ struct GameListStats
     int unfinished;\r
 };\r
 \r
-/* [AS] Wildcard pattern matching */\r
-static BOOL HasPattern( const char * text, const char * pattern )\r
-{\r
-    while( *pattern != '\0' ) {\r
-        if( *pattern == '*' ) {\r
-            while( *pattern == '*' ) {\r
-                pattern++;\r
-            }\r
-\r
-            if( *pattern == '\0' ) {\r
-                return TRUE;\r
-            }\r
-\r
-            while( *text != '\0' ) {\r
-                if( HasPattern( text, pattern ) ) {\r
-                    return TRUE;\r
-                }\r
-                text++;\r
-            }\r
-        }\r
-        else if( (*pattern == *text) || ((*pattern == '?') && (*text != '\0')) ) {\r
-            pattern++;\r
-            text++;\r
-            continue;\r
-        }\r
-\r
-        return FALSE;\r
-    }\r
-\r
-    return TRUE;\r
-}\r
-\r
-static BOOL SearchPattern( const char * text, const char * pattern )\r
-{\r
-    BOOL result = TRUE;\r
-\r
-    if( pattern != NULL && *pattern != '\0' ) {\r
-        if( *pattern == '*' ) {\r
-            result = HasPattern( text, pattern );\r
-        }\r
-        else {\r
-            result = FALSE;\r
-\r
-            while( *text != '\0' ) {\r
-                if( HasPattern( text, pattern ) ) {\r
-                    result = TRUE;\r
-                    break;\r
-                }\r
-                text++;\r
-            }\r
-        }\r
-    }\r
-\r
-    return result;\r
-}\r
-\r
 /* [AS] Setup the game list according to the specified filter */\r
 static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct GameListStats * stats )\r
 {\r
@@ -129,7 +66,7 @@ static int GameListToListBox( HWND hDlg, BOOL boReset, char * pszFilter, struct
     struct GameListStats dummy;\r
 \r
     /* Initialize stats (use a dummy variable if caller not interested in them) */\r
-    if( stats == NULL ) { \r
+    if( stats == NULL ) {\r
         stats = &dummy;\r
     }\r
 \r
@@ -187,7 +124,7 @@ static int GameListUpdateTitle( HWND hDlg, char * pszTitle, int item_count, int
 {\r
     char buf[256];\r
 \r
-    sprintf( buf, "%s - %d/%d games", pszTitle, item_count, item_total );\r
+    snprintf( buf, sizeof(buf)/sizeof(buf[0]),_("%s - %d/%d games"), pszTitle, item_count, item_total );\r
 \r
     if( stats != 0 ) {\r
         sprintf( buf+strlen(buf), " (%d-%d-%d)", stats->white_wins, stats->black_wins, stats->drawn );\r
@@ -216,7 +153,8 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
   static SnapData sd;\r
 \r
   switch (message) {\r
-  case WM_INITDIALOG: \r
+  case WM_INITDIALOG:\r
+    Translate(hDlg, DLG_GameList);\r
     GetWindowText( hDlg, szDlgTitle, sizeof(szDlgTitle) );\r
     szDlgTitle[ sizeof(szDlgTitle)-1 ] = '\0';\r
 \r
@@ -265,12 +203,13 @@ GameListDialog(HWND hDlg, UINT message,   WPARAM wParam, LPARAM lParam)
                              newSizeX, newSizeY);\r
        sizeX = newSizeX;\r
        sizeY = newSizeY;\r
-      }\r
+      } else\r
+        GetActualPlacement( gameListDialog, &wpGameList );\r
 \r
-      GameListUpdateTitle( hDlg, szDlgTitle, count, ((ListGame *) gameList.tailPred)->number, &stats );\r
     }\r
+      GameListUpdateTitle( hDlg, _("Game List"), count, ((ListGame *) gameList.tailPred)->number, &stats ); // [HGM] always update title\r
     return FALSE;\r
-    \r
+\r
   case WM_SIZE:\r
     newSizeX = LOWORD(lParam);\r
     newSizeY = HIWORD(lParam);\r
@@ -291,7 +230,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
 \r
   case WM_EXITSIZEMOVE:\r
     return OnExitSizeMove( &sd, hDlg, wParam, lParam );\r
-  \r
+\r
   case WM_GETMINMAXINFO:\r
     /* Prevent resizing window too small */\r
     mmi = (MINMAXINFO *) lParam;\r
@@ -300,7 +239,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
     break;\r
 \r
   case WM_COMMAND:\r
-      /* \r
+      /*\r
         [AS]\r
         If <Enter> is pressed while editing the filter, it's better to apply\r
         the filter rather than selecting the current game.\r
@@ -327,28 +266,28 @@ GameListDialog(HWND hDlg, UINT message,   WPARAM wParam, LPARAM lParam)
       nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);\r
       if (nItem < 0) {\r
        /* is this possible? */\r
-       DisplayError("No game selected", 0);\r
+       DisplayError(_("No game selected"), 0);\r
        return TRUE;\r
       }\r
       break; /* load the game*/\r
-      \r
+\r
     case OPT_GameListNext:\r
       nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);\r
       nItem++;\r
       if (nItem >= ((ListGame *) gameList.tailPred)->number) {\r
         /* [AS] Removed error message */\r
-       /* DisplayError("Can't go forward any further", 0); */\r
+       /* DisplayError(_("Can't go forward any further"), 0); */\r
        return TRUE;\r
       }\r
       SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0);\r
       break; /* load the game*/\r
-      \r
+\r
     case OPT_GameListPrev:\r
       nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);\r
       nItem--;\r
       if (nItem < 0) {\r
         /* [AS] Removed error message, added return */\r
-       /* DisplayError("Can't back up any further", 0); */\r
+       /* DisplayError(_("Can't back up any further"), 0); */\r
         return TRUE;\r
       }\r
       SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0);\r
@@ -358,11 +297,11 @@ GameListDialog(HWND hDlg, UINT message,   WPARAM wParam, LPARAM lParam)
     case IDC_GameListDoFilter:\r
         {\r
             char filter[MAX_FILTER_LENGTH+1];\r
-            \r
+\r
             if( GetDlgItemText( hDlg, IDC_GameListFilter, filter, sizeof(filter) ) >= 0 ) {\r
                 filter[ sizeof(filter)-1 ] = '\0';\r
                 count = GameListToListBox( hDlg, TRUE, filter, &stats );\r
-                GameListUpdateTitle( hDlg, szDlgTitle, count, ((ListGame *) gameList.tailPred)->number, &stats );\r
+                GameListUpdateTitle( hDlg, _("Game List"), count, ((ListGame *) gameList.tailPred)->number, &stats );\r
             }\r
         }\r
         return FALSE;\r
@@ -372,13 +311,13 @@ GameListDialog(HWND hDlg, UINT message,   WPARAM wParam, LPARAM lParam)
     case OPT_GameListClose:\r
       GameListPopDown();\r
       return TRUE;\r
-      \r
+\r
     case OPT_GameListText:\r
       switch (HIWORD(wParam)) {\r
       case LBN_DBLCLK:\r
        nItem = SendMessage((HWND) lParam, LB_GETCURSEL, 0, 0);\r
        break; /* load the game*/\r
-       \r
+\r
       default:\r
        return FALSE;\r
       }\r
@@ -421,6 +360,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
         }\r
         else {\r
             LoadGame(gameFile, nItem + 1, gameFileName, TRUE);\r
+           SetFocus(hwndMain); // [HGM] automatic focus switch\r
         }\r
     }\r
 \r
@@ -436,7 +376,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
 VOID GameListPopUp(FILE *fp, char *filename)\r
 {\r
   FARPROC lpProc;\r
-  \r
+\r
   gameFile = fp;\r
   if (gameFileName != filename) {\r
     if (gameFileName) free(gameFileName);\r
@@ -446,6 +386,7 @@ VOID GameListPopUp(FILE *fp, char *filename)
   if (gameListDialog) {\r
     SendMessage(gameListDialog, WM_INITDIALOG, 0, 0);\r
     if (!gameListUp) ShowWindow(gameListDialog, SW_SHOW);\r
+    else SetFocus(gameListDialog);\r
   } else {\r
     lpProc = MakeProcInstance((FARPROC)GameListDialog, hInst);\r
     CreateDialog(hInst, MAKEINTRESOURCE(DLG_GameList),\r
@@ -466,7 +407,7 @@ VOID GameListPopDown(void)
 VOID GameListHighlight(int index)\r
 {\r
   if (gameListDialog == NULL) return;\r
-  SendDlgItemMessage(gameListDialog, OPT_GameListText, \r
+  SendDlgItemMessage(gameListDialog, OPT_GameListText,\r
     LB_SETCURSEL, index - 1, 0);\r
 }\r
 \r
@@ -483,12 +424,13 @@ VOID GameListDestroy()
 VOID ShowGameListProc()\r
 {\r
   if (gameListUp) {\r
-    GameListPopDown();\r
+    if(gameListDialog) SetFocus(gameListDialog);\r
+//    GameListPopDown();\r
   } else {\r
     if (gameFileName) {\r
       GameListPopUp(gameFile, gameFileName);\r
     } else {\r
-      DisplayError("No game list", 0);\r
+      DisplayError(_("No game list"), 0);\r
     }\r
   }\r
 }\r
@@ -502,7 +444,7 @@ HGLOBAL ExportGameListAsText()
     DWORD dwLen = 0;\r
 \r
     if( ! gameFileName || ((ListGame *) gameList.tailPred)->number <= 0 ) {\r
-        DisplayError("Game list not loaded or empty", 0);\r
+        DisplayError(_(_("Game list not loaded or empty")), 0);\r
         return NULL;\r
     }\r
 \r