2 * wgamelist.c -- Game list window for WinBoard
5 * Copyright 1995 Free Software Foundation, Inc.
7 * ------------------------------------------------------------------------
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * ------------------------------------------------------------------------
26 #include <windows.h> /* required for all Windows applications */
42 HWND gameListDialog = NULL;
43 BOOLEAN gameListUp = FALSE;
45 char* gameFileName = NULL;
46 int gameListX, gameListY, gameListW, gameListH;
48 /* Imports from winboard.c */
49 extern HINSTANCE hInst;
54 GameListDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
56 static HANDLE hwndText;
60 static int sizeX, sizeY;
61 int newSizeX, newSizeY, flags;
67 SendDlgItemMessage(hDlg, OPT_GameListText, LB_RESETCONTENT, 0, 0);
69 /* Initialize the dialog items */
70 hwndText = GetDlgItem(hDlg, OPT_TagsText);
71 lg = (ListGame *) gameList.head;
72 for (nItem = 0; nItem < ((ListGame *) gameList.tailPred)->number; nItem++){
73 char *st = GameListLine(lg->number, &lg->gameInfo);
74 SendDlgItemMessage(hDlg, OPT_GameListText, LB_ADDSTRING, 0, (LPARAM) st);
76 lg = (ListGame *) lg->node.succ;
78 SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, 0, 0);
79 /* Size and position the dialog */
80 if (!gameListDialog) {
81 gameListDialog = hDlg;
83 GetClientRect(hDlg, &rect);
86 if (gameListX != CW_USEDEFAULT && gameListY != CW_USEDEFAULT &&
87 gameListW != CW_USEDEFAULT && gameListH != CW_USEDEFAULT) {
89 EnsureOnScreen(&gameListX, &gameListY);
90 wp.length = sizeof(WINDOWPLACEMENT);
93 wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0;
94 wp.rcNormalPosition.left = gameListX;
95 wp.rcNormalPosition.right = gameListX + gameListW;
96 wp.rcNormalPosition.top = gameListY;
97 wp.rcNormalPosition.bottom = gameListY + gameListH;
98 SetWindowPlacement(hDlg, &wp);
100 GetClientRect(hDlg, &rect);
101 newSizeX = rect.right;
102 newSizeY = rect.bottom;
103 ResizeEditPlusButtons(hDlg, hwndText, sizeX, sizeY,
112 newSizeX = LOWORD(lParam);
113 newSizeY = HIWORD(lParam);
114 ResizeEditPlusButtons(hDlg, GetDlgItem(hDlg, OPT_GameListText),
115 sizeX, sizeY, newSizeX, newSizeY);
120 case WM_GETMINMAXINFO:
121 /* Prevent resizing window too small */
122 mmi = (MINMAXINFO *) lParam;
123 mmi->ptMinTrackSize.x = 100;
124 mmi->ptMinTrackSize.y = 100;
128 switch (LOWORD(wParam)) {
130 case OPT_GameListLoad:
131 nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);
133 /* is this possible? */
134 DisplayError("No game selected", 0);
137 break; /* load the game*/
139 case OPT_GameListNext:
140 nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);
142 if (nItem >= ((ListGame *) gameList.tailPred)->number) {
143 DisplayError("Can't go forward any further", 0);
146 SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0);
147 break; /* load the game*/
149 case OPT_GameListPrev:
150 nItem = SendDlgItemMessage(hDlg, OPT_GameListText, LB_GETCURSEL, 0, 0);
153 DisplayError("Can't back up any further", 0);
155 SendDlgItemMessage(hDlg, OPT_GameListText, LB_SETCURSEL, nItem, 0);
156 break; /* load the game*/
159 case OPT_GameListClose:
163 case OPT_GameListText:
164 switch (HIWORD(wParam)) {
166 nItem = SendMessage((HWND) lParam, LB_GETCURSEL, 0, 0);
167 break; /* load the game*/
178 if (cmailMsgLoaded) {
179 CmailLoadGame(gameFile, nItem + 1, gameFileName, TRUE);
181 LoadGame(gameFile, nItem + 1, gameFileName, TRUE);
192 VOID GameListPopUp(FILE *fp, char *filename)
197 if (gameFileName != filename) {
198 if (gameFileName) free(gameFileName);
199 gameFileName = StrSave(filename);
201 CheckMenuItem(GetMenu(hwndMain), IDM_ShowGameList, MF_CHECKED);
202 if (gameListDialog) {
203 SendMessage(gameListDialog, WM_INITDIALOG, 0, 0);
204 if (!gameListUp) ShowWindow(gameListDialog, SW_SHOW);
206 lpProc = MakeProcInstance((FARPROC)GameListDialog, hInst);
207 CreateDialog(hInst, MAKEINTRESOURCE(DLG_GameList),
208 hwndMain, (DLGPROC)lpProc);
209 FreeProcInstance(lpProc);
214 VOID GameListPopDown(void)
216 CheckMenuItem(GetMenu(hwndMain), IDM_ShowGameList, MF_UNCHECKED);
217 if (gameListDialog) ShowWindow(gameListDialog, SW_HIDE);
222 VOID GameListHighlight(int index)
224 if (gameListDialog == NULL) return;
225 SendDlgItemMessage(gameListDialog, OPT_GameListText,
226 LB_SETCURSEL, index - 1, 0);
230 VOID GameListDestroy()
239 VOID ShowGameListProc()
245 GameListPopUp(gameFile, gameFileName);
247 DisplayError("No game list", 0);