updated year in copyright info
[xboard.git] / winboard / wgamelist.c
index 1c8a15d..50d2978 100644 (file)
@@ -1,8 +1,9 @@
 /*\r
  * wgamelist.c -- Game list window for WinBoard\r
- * $Id: wgamelist.c,v 2.1 2003/10/27 19:21:02 mann Exp $\r
  *\r
- * Copyright 1995,2009 Free Software Foundation, Inc.\r
+ * Copyright 1995, 2009, 2010 Free Software Foundation, Inc.\r
+ *\r
+ * Enhancements Copyright 2005 Alessandro Scotti\r
  *\r
  * ------------------------------------------------------------------------\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
 /* Module globals */\r
-HWND gameListDialog = NULL;\r
-BOOLEAN gameListUp = FALSE;\r
-FILE* gameFile;\r
-char* gameFileName = NULL;\r
-int gameListX, gameListY, gameListW, gameListH;\r
-\r
-/* Imports from winboard.c */\r
-extern HINSTANCE hInst;\r
-extern HWND hwndMain;\r
+static BOOLEAN gameListUp = FALSE;\r
+static FILE* gameFile;\r
+static char* gameFileName = NULL;\r
 \r
 struct GameListStats\r
 {\r
@@ -60,62 +54,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
@@ -224,6 +162,9 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
     /* Initialize the dialog items */\r
     hwndText = GetDlgItem(hDlg, OPT_TagsText);\r
 \r
+    /* Set font */\r
+    SendDlgItemMessage( hDlg, OPT_GameListText, WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, MAKELPARAM(TRUE, 0 ));\r
+\r
     count = GameListToListBox( hDlg, gameListDialog ? TRUE : FALSE, NULL, &stats );\r
 \r
     SendDlgItemMessage( hDlg, IDC_GameListFilter, WM_SETTEXT, 0, (LPARAM) "" );\r
@@ -238,18 +179,18 @@ GameListDialog(HWND hDlg, UINT message,   WPARAM wParam, LPARAM lParam)
       GetClientRect(hDlg, &rect);\r
       sizeX = rect.right;\r
       sizeY = rect.bottom;\r
-      if (gameListX != CW_USEDEFAULT && gameListY != CW_USEDEFAULT &&\r
-         gameListW != CW_USEDEFAULT && gameListH != CW_USEDEFAULT) {\r
+      if (wpGameList.x != CW_USEDEFAULT && wpGameList.y != CW_USEDEFAULT &&\r
+         wpGameList.width != CW_USEDEFAULT && wpGameList.height != CW_USEDEFAULT) {\r
        WINDOWPLACEMENT wp;\r
-       EnsureOnScreen(&gameListX, &gameListY);\r
+       EnsureOnScreen(&wpGameList.x, &wpGameList.y, 0, 0);\r
        wp.length = sizeof(WINDOWPLACEMENT);\r
        wp.flags = 0;\r
        wp.showCmd = SW_SHOW;\r
        wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0;\r
-       wp.rcNormalPosition.left = gameListX;\r
-       wp.rcNormalPosition.right = gameListX + gameListW;\r
-       wp.rcNormalPosition.top = gameListY;\r
-       wp.rcNormalPosition.bottom = gameListY + gameListH;\r
+       wp.rcNormalPosition.left = wpGameList.x;\r
+       wp.rcNormalPosition.right = wpGameList.x + wpGameList.width;\r
+       wp.rcNormalPosition.top = wpGameList.y;\r
+       wp.rcNormalPosition.bottom = wpGameList.y + wpGameList.height;\r
        SetWindowPlacement(hDlg, &wp);\r
 \r
        GetClientRect(hDlg, &rect);\r
@@ -259,7 +200,9 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
                              newSizeX, newSizeY);\r
        sizeX = newSizeX;\r
        sizeY = newSizeY;\r
-      }\r
+      } \r
+   else \r
+     GetActualPlacement( gameListDialog, &wpGameList );\r
 \r
       GameListUpdateTitle( hDlg, szDlgTitle, count, ((ListGame *) gameList.tailPred)->number, &stats );\r
     }\r
@@ -414,6 +357,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
             CmailLoadGame(gameFile, nItem + 1, gameFileName, TRUE);\r
         }\r
         else {\r
+           SetFocus(hwndMain); // [HGM] automatic focus switch\r
             LoadGame(gameFile, nItem + 1, gameFileName, TRUE);\r
         }\r
     }\r
@@ -440,6 +384,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
@@ -477,7 +422,8 @@ 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