2 * wgamelist.c -- Game list window for WinBoard
\r
5 * Copyright 1995 Free Software Foundation, Inc.
\r
7 * ------------------------------------------------------------------------
\r
8 * This program is free software; you can redistribute it and/or modify
\r
9 * it under the terms of the GNU General Public License as published by
\r
10 * the Free Software Foundation; either version 2 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU General Public License
\r
19 * along with this program; if not, write to the Free Software
\r
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\r
21 * ------------------------------------------------------------------------
\r
26 #include <windows.h> /* required for all Windows applications */
\r
32 #include <commdlg.h>
\r
36 #include "winboard.h"
\r
37 #include "frontend.h"
\r
38 #include "backend.h"
\r
40 /* Module globals */
\r
41 HWND gameListDialog = NULL;
\r
42 BOOLEAN gameListUp = FALSE;
\r
44 char* gameFileName = NULL;
\r
45 int gameListX, gameListY, gameListW, gameListH;
\r
47 /* Imports from winboard.c */
\r
48 extern HINSTANCE hInst;
\r
49 extern HWND hwndMain;
\r
53 GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
\r
55 static HANDLE hwndText;
\r
59 static int sizeX, sizeY;
\r
60 int newSizeX, newSizeY, flags;
\r
64 case WM_INITDIALOG:
\r
65 if (gameListDialog) {
\r
66 SendDlgItemMessage(hDlg, OPT_GameListText, LB_RESETCONTENT, 0, 0);
\r
68 /* Initialize the dialog items */
\r
69 hwndText = GetDlgItem(hDlg, OPT_TagsText);
\r
70 lg = (ListGame *) gameList.head;
\r
71 for (nItem = 0; nItem < ((ListGame *) gameList.tailPred)->number; nItem++){
\r
72 char *st = GameListLine(lg->number, &lg->gameInfo);
\r
73 SendDlgItemMessage(hDlg, OPT_GameListText, LB_ADDSTRING, 0, (LPARAM) st);
\r
75 lg = (ListGame *) lg->node.succ;
\r
77 SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, 0, 0);
\r
78 /* Size and position the dialog */
\r
79 if (!gameListDialog) {
\r
80 gameListDialog = hDlg;
\r
81 flags = SWP_NOZORDER;
\r
82 GetClientRect(hDlg, &rect);
\r
84 sizeY = rect.bottom;
\r
85 if (gameListX != CW_USEDEFAULT && gameListY != CW_USEDEFAULT &&
\r
86 gameListW != CW_USEDEFAULT && gameListH != CW_USEDEFAULT) {
\r
88 EnsureOnScreen(&gameListX, &gameListY);
\r
89 wp.length = sizeof(WINDOWPLACEMENT);
\r
91 wp.showCmd = SW_SHOW;
\r
92 wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0;
\r
93 wp.rcNormalPosition.left = gameListX;
\r
94 wp.rcNormalPosition.right = gameListX + gameListW;
\r
95 wp.rcNormalPosition.top = gameListY;
\r
96 wp.rcNormalPosition.bottom = gameListY + gameListH;
\r
97 SetWindowPlacement(hDlg, &wp);
\r
99 GetClientRect(hDlg, &rect);
\r
100 newSizeX = rect.right;
\r
101 newSizeY = rect.bottom;
\r
102 ResizeEditPlusButtons(hDlg, hwndText, sizeX, sizeY,
\r
103 newSizeX, newSizeY);
\r
111 newSizeX = LOWORD(lParam);
\r
112 newSizeY = HIWORD(lParam);
\r
113 ResizeEditPlusButtons(hDlg, GetDlgItem(hDlg, OPT_GameListText),
\r
114 sizeX, sizeY, newSizeX, newSizeY);
\r
119 case WM_GETMINMAXINFO:
\r
120 /* Prevent resizing window too small */
\r
121 mmi = (MINMAXINFO *) lParam;
\r
122 mmi->ptMinTrackSize.x = 100;
\r
123 mmi->ptMinTrackSize.y = 100;
\r
127 switch (LOWORD(wParam)) {
\r
129 case OPT_GameListLoad:
\r
130 nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);
\r
132 /* is this possible? */
\r
133 DisplayError("No game selected", 0);
\r
136 break; /* load the game*/
\r
138 case OPT_GameListNext:
\r
139 nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);
\r
141 if (nItem >= ((ListGame *) gameList.tailPred)->number) {
\r
142 DisplayError("Can't go forward any further", 0);
\r
145 SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0);
\r
146 break; /* load the game*/
\r
148 case OPT_GameListPrev:
\r
149 nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);
\r
152 DisplayError("Can't back up any further", 0);
\r
154 SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0);
\r
155 break; /* load the game*/
\r
158 case OPT_GameListClose:
\r
162 case OPT_GameListText:
\r
163 switch (HIWORD(wParam)) {
\r
165 nItem = SendMessage((HWND) lParam, LB_GETCURSEL, 0, 0);
\r
166 break; /* load the game*/
\r
176 /* Load the game */
\r
177 if (cmailMsgLoaded) {
\r
178 CmailLoadGame(gameFile, nItem + 1, gameFileName, TRUE);
\r
180 LoadGame(gameFile, nItem + 1, gameFileName, TRUE);
\r
191 VOID GameListPopUp(FILE *fp, char *filename)
\r
196 if (gameFileName != filename) {
\r
197 if (gameFileName) free(gameFileName);
\r
198 gameFileName = StrSave(filename);
\r
200 CheckMenuItem(GetMenu(hwndMain), IDM_ShowGameList, MF_CHECKED);
\r
201 if (gameListDialog) {
\r
202 SendMessage(gameListDialog, WM_INITDIALOG, 0, 0);
\r
203 if (!gameListUp) ShowWindow(gameListDialog, SW_SHOW);
\r
205 lpProc = MakeProcInstance((FARPROC)GameListDialog, hInst);
\r
206 CreateDialog(hInst, MAKEINTRESOURCE(DLG_GameList),
\r
207 hwndMain, (DLGPROC)lpProc);
\r
208 FreeProcInstance(lpProc);
\r
213 VOID GameListPopDown(void)
\r
215 CheckMenuItem(GetMenu(hwndMain), IDM_ShowGameList, MF_UNCHECKED);
\r
216 if (gameListDialog) ShowWindow(gameListDialog, SW_HIDE);
\r
217 gameListUp = FALSE;
\r
221 VOID GameListHighlight(int index)
\r
223 if (gameListDialog == NULL) return;
\r
224 SendDlgItemMessage(gameListDialog, OPT_GameListText,
\r
225 LB_SETCURSEL, index - 1, 0);
\r
229 VOID GameListDestroy()
\r
232 if (gameFileName) {
\r
233 free(gameFileName);
\r
234 gameFileName = NULL;
\r
238 VOID ShowGameListProc()
\r
243 if (gameFileName) {
\r
244 GameListPopUp(gameFile, gameFileName);
\r
246 DisplayError("No game list", 0);
\r