Some code refactoring and cleanup; one small bug fix
[xboard.git] / winboard / wgamelist.c
index 3c13ae6..31d36ff 100644 (file)
@@ -1,9 +1,10 @@
 /*\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
  *\r
+ * Enhancements Copyright 2005 Alessandro Scotti\r
+ *\r
  * ------------------------------------------------------------------------\r
  *\r
  * GNU XBoard is free software: you can redistribute it and/or modify\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
-\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
@@ -224,6 +218,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
@@ -259,7 +256,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 +413,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 +440,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 +478,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