2 * xgamelist.c -- Game list window, part of X front end for XBoard
5 * Copyright 1995 Free Software Foundation, Inc.
7 * The following terms apply to the enhanced version of XBoard distributed
8 * by the Free Software Foundation:
9 * ------------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * ------------------------------------------------------------------------
25 * See the file ChangeLog for a revision history.
33 #include <sys/types.h>
38 #else /* not STDC_HEADERS */
39 extern char *getenv();
42 # else /* not HAVE_STRING_H */
44 # endif /* not HAVE_STRING_H */
45 #endif /* not STDC_HEADERS */
51 #include <X11/Intrinsic.h>
52 #include <X11/StringDefs.h>
53 #include <X11/Shell.h>
54 #include <X11/cursorfont.h>
56 #include <X11/Xaw3d/Dialog.h>
57 #include <X11/Xaw3d/Form.h>
58 #include <X11/Xaw3d/List.h>
59 #include <X11/Xaw3d/Label.h>
60 #include <X11/Xaw3d/SimpleMenu.h>
61 #include <X11/Xaw3d/SmeBSB.h>
62 #include <X11/Xaw3d/SmeLine.h>
63 #include <X11/Xaw3d/Box.h>
64 #include <X11/Xaw3d/MenuButton.h>
65 #include <X11/Xaw3d/Text.h>
66 #include <X11/Xaw3d/AsciiText.h>
67 #include <X11/Xaw3d/Viewport.h>
69 #include <X11/Xaw/Dialog.h>
70 #include <X11/Xaw/Form.h>
71 #include <X11/Xaw/List.h>
72 #include <X11/Xaw/Label.h>
73 #include <X11/Xaw/SimpleMenu.h>
74 #include <X11/Xaw/SmeBSB.h>
75 #include <X11/Xaw/SmeLine.h>
76 #include <X11/Xaw/Box.h>
77 #include <X11/Xaw/MenuButton.h>
78 #include <X11/Xaw/Text.h>
79 #include <X11/Xaw/AsciiText.h>
80 #include <X11/Xaw/Viewport.h>
87 #include "xgamelist.h"
89 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
90 extern Display *xDisplay;
91 extern int squareSize;
92 extern Pixmap xMarkPixmap;
93 extern char *layoutName;
95 char gameListTranslations[] =
96 "<Btn1Up>(2): LoadSelectedProc() \n \
97 <Key>Return: LoadSelectedProc() \n";
109 static Arg layoutArgs[] = {
110 { XtNborderWidth, 0 },
111 { XtNdefaultDistance, 0 }
115 GameListCreate(name, callback, client_data)
117 XtCallbackProc callback;
118 XtPointer client_data;
121 Widget shell, form, viewport, listwidg, layout;
122 Widget b_load, b_loadprev, b_loadnext, b_close;
125 GameListClosure *glc = (GameListClosure *) client_data;
128 XtSetArg(args[j], XtNwidth, &fw_width); j++;
129 XtGetValues(formWidget, args, j);
132 XtSetArg(args[j], XtNresizable, True); j++;
133 XtSetArg(args[j], XtNallowShellResize, True); j++;
136 XtCreatePopupShell(name, topLevelShellWidgetClass,
137 shellWidget, args, j);
140 XtCreatePopupShell(name, transientShellWidgetClass,
141 shellWidget, args, j);
144 XtCreateManagedWidget(layoutName, formWidgetClass, shell,
145 layoutArgs, XtNumber(layoutArgs));
147 XtSetArg(args[j], XtNborderWidth, 0); j++;
149 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
152 XtSetArg(args[j], XtNtop, XtChainTop); j++;
153 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
154 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
155 XtSetArg(args[j], XtNright, XtChainRight); j++;
156 XtSetArg(args[j], XtNresizable, False); j++;
157 XtSetArg(args[j], XtNwidth, fw_width); j++;
158 XtSetArg(args[j], XtNallowVert, True); j++;
160 XtCreateManagedWidget("viewport", viewportWidgetClass, form, args, j);
163 XtSetArg(args[j], XtNlist, glc->strings); j++;
164 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
165 XtSetArg(args[j], XtNforceColumns, True); j++;
166 XtSetArg(args[j], XtNverticalList, True); j++;
168 XtCreateManagedWidget("list", listWidgetClass, viewport, args, j);
169 XawListHighlight(listwidg, 0);
170 XtAugmentTranslations(listwidg,
171 XtParseTranslationTable(gameListTranslations));
174 XtSetArg(args[j], XtNfromVert, viewport); j++;
175 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
176 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
177 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
178 XtSetArg(args[j], XtNright, XtChainLeft); j++;
180 XtCreateManagedWidget("load", commandWidgetClass, form, args, j);
181 XtAddCallback(b_load, XtNcallback, callback, client_data);
184 XtSetArg(args[j], XtNfromVert, viewport); j++;
185 XtSetArg(args[j], XtNfromHoriz, b_load); j++;
186 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
187 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
188 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
189 XtSetArg(args[j], XtNright, XtChainLeft); j++;
191 XtCreateManagedWidget("prev", commandWidgetClass, form, args, j);
192 XtAddCallback(b_loadprev, XtNcallback, callback, client_data);
195 XtSetArg(args[j], XtNfromVert, viewport); j++;
196 XtSetArg(args[j], XtNfromHoriz, b_loadprev); j++;
197 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
198 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
199 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
200 XtSetArg(args[j], XtNright, XtChainLeft); j++;
202 XtCreateManagedWidget("next", commandWidgetClass, form, args, j);
203 XtAddCallback(b_loadnext, XtNcallback, callback, client_data);
206 XtSetArg(args[j], XtNfromVert, viewport); j++;
207 XtSetArg(args[j], XtNfromHoriz, b_loadnext); j++;
208 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
209 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
210 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
211 XtSetArg(args[j], XtNright, XtChainLeft); j++;
213 XtCreateManagedWidget("close", commandWidgetClass, form, args, j);
214 XtAddCallback(b_close, XtNcallback, callback, client_data);
223 XtSetArg(args[j], XtNheight, &h1); j++;
224 XtSetArg(args[j], XtNy, &y1); j++;
225 XtGetValues(boardWidget, args, j);
226 glc->w = fw_width * 3/4;
227 glc->h = squareSize * 3;
229 XSync(xDisplay, False);
231 /* This code seems to tickle an X bug if it is executed too soon
232 after xboard starts up. The coordinates get transformed as if
233 the main window was positioned at (0, 0).
235 XtTranslateCoords(shellWidget, (fw_width - glc->w) / 2,
236 y1 + (h1 - glc->h + appData.borderYoffset) / 2,
239 XTranslateCoordinates(xDisplay, XtWindow(shellWidget),
240 RootWindowOfScreen(XtScreen(shellWidget)),
241 (fw_width - glc->w) / 2,
242 y1 + (h1 - glc->h + appData.borderYoffset) / 2,
247 if (glc->y < 0) glc->y = 0; /*avoid positioning top offscreen*/
250 XtSetArg(args[j], XtNheight, glc->h); j++;
251 XtSetArg(args[j], XtNwidth, glc->w); j++;
252 XtSetArg(args[j], XtNx, glc->x - appData.borderXoffset); j++;
253 XtSetArg(args[j], XtNy, glc->y - appData.borderYoffset); j++;
254 XtSetValues(shell, args, j);
256 XtRealizeWidget(shell);
257 CatchDeleteWindow(shell, "GameListPopDown");
263 GameListCallback(w, client_data, call_data)
265 XtPointer client_data, call_data;
271 GameListClosure *glc = (GameListClosure *) client_data;
272 XawListReturnStruct *rs;
276 XtSetArg(args[j], XtNlabel, &name); j++;
277 XtGetValues(w, args, j);
279 if (strcmp(name, "close") == 0) {
283 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
284 rs = XawListShowCurrent(listwidg);
285 if (strcmp(name, "load") == 0) {
286 index = rs->list_index;
288 DisplayError("No game selected", 0);
291 } else if (strcmp(name, "next") == 0) {
292 index = rs->list_index + 1;
293 if (index >= ((ListGame *) gameList.tailPred)->number) {
294 DisplayError("Can't go forward any further", 0);
297 XawListHighlight(listwidg, index);
298 } else if (strcmp(name, "prev") == 0) {
299 index = rs->list_index - 1;
301 DisplayError("Can't back up any further", 0);
304 XawListHighlight(listwidg, index);
306 if (cmailMsgLoaded) {
307 CmailLoadGame(glc->fp, index + 1, glc->filename, True);
309 LoadGame(glc->fp, index + 1, glc->filename, True);
313 static GameListClosure *glc = NULL;
316 GameListPopUp(fp, filename)
327 glc = (GameListClosure *) calloc(1, sizeof(GameListClosure));
328 glc->x = glc->y = -1;
331 if (glc->strings != NULL) {
339 nstrings = ((ListGame *) gameList.tailPred)->number;
340 glc->strings = (char **) malloc((nstrings + 1) * sizeof(char *));
342 lg = (ListGame *) gameList.head;
344 *st++ = GameListLine(lg->number, &lg->gameInfo);
345 lg = (ListGame *) lg->node.succ;
351 if (glc->filename != NULL) free(glc->filename);
352 glc->filename = StrSave(filename);
354 if (glc->shell == NULL) {
355 glc->shell = GameListCreate(filename, GameListCallback, glc);
357 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
358 XawListChange(listwidg, glc->strings, 0, 0, True);
359 XawListHighlight(listwidg, 0);
361 XtSetArg(args[j], XtNiconName, (XtArgVal) filename); j++;
362 XtSetArg(args[j], XtNtitle, (XtArgVal) filename); j++;
363 XtSetValues(glc->shell, args, j);
366 XtPopup(glc->shell, XtGrabNone);
369 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
370 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Game List"),
377 if (glc == NULL) return;
379 if (glc->strings != NULL) {
392 ShowGameListProc(w, event, prms, nprms)
402 DisplayError("There is no game list", 0);
409 XtPopup(glc->shell, XtGrabNone);
412 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
413 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Game List"),
418 LoadSelectedProc(w, event, prms, nprms)
425 XawListReturnStruct *rs;
428 if (glc == NULL) return;
429 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
430 rs = XawListShowCurrent(listwidg);
431 index = rs->list_index;
432 if (index < 0) return;
433 if (cmailMsgLoaded) {
434 CmailLoadGame(glc->fp, index + 1, glc->filename, True);
436 LoadGame(glc->fp, index + 1, glc->filename, True);
446 if (glc == NULL) return;
448 XtSetArg(args[j], XtNx, &glc->x); j++;
449 XtSetArg(args[j], XtNy, &glc->y); j++;
450 XtSetArg(args[j], XtNheight, &glc->h); j++;
451 XtSetArg(args[j], XtNwidth, &glc->w); j++;
452 XtGetValues(glc->shell, args, j);
453 XtPopdown(glc->shell);
454 XtSetKeyboardFocus(shellWidget, formWidget);
457 XtSetArg(args[j], XtNleftBitmap, None); j++;
458 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Game List"),
463 GameListHighlight(index)
467 if (glc == NULL || !glc->up) return;
468 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
469 XawListHighlight(listwidg, index - 1);