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"
91 # define _(s) gettext (s)
92 # define N_(s) gettext_noop (s)
99 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
100 extern Display *xDisplay;
101 extern int squareSize;
102 extern Pixmap xMarkPixmap;
103 extern char *layoutName;
105 char gameListTranslations[] =
106 "<Btn1Up>(2): LoadSelectedProc() \n \
107 <Key>Return: LoadSelectedProc() \n";
119 static Arg layoutArgs[] = {
120 { XtNborderWidth, 0 },
121 { XtNdefaultDistance, 0 }
125 GameListCreate(name, callback, client_data)
127 XtCallbackProc callback;
128 XtPointer client_data;
131 Widget shell, form, viewport, listwidg, layout;
132 Widget b_load, b_loadprev, b_loadnext, b_close;
135 GameListClosure *glc = (GameListClosure *) client_data;
138 XtSetArg(args[j], XtNwidth, &fw_width); j++;
139 XtGetValues(formWidget, args, j);
142 XtSetArg(args[j], XtNresizable, True); j++;
143 XtSetArg(args[j], XtNallowShellResize, True); j++;
146 XtCreatePopupShell(name, topLevelShellWidgetClass,
147 shellWidget, args, j);
150 XtCreatePopupShell(name, transientShellWidgetClass,
151 shellWidget, args, j);
154 XtCreateManagedWidget(layoutName, formWidgetClass, shell,
155 layoutArgs, XtNumber(layoutArgs));
157 XtSetArg(args[j], XtNborderWidth, 0); j++;
159 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
162 XtSetArg(args[j], XtNtop, XtChainTop); j++;
163 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
164 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
165 XtSetArg(args[j], XtNright, XtChainRight); j++;
166 XtSetArg(args[j], XtNresizable, False); j++;
167 XtSetArg(args[j], XtNwidth, fw_width); j++;
168 XtSetArg(args[j], XtNallowVert, True); j++;
170 XtCreateManagedWidget("viewport", viewportWidgetClass, form, args, j);
173 XtSetArg(args[j], XtNlist, glc->strings); j++;
174 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
175 XtSetArg(args[j], XtNforceColumns, True); j++;
176 XtSetArg(args[j], XtNverticalList, True); j++;
178 XtCreateManagedWidget("list", listWidgetClass, viewport, args, j);
179 XawListHighlight(listwidg, 0);
180 XtAugmentTranslations(listwidg,
181 XtParseTranslationTable(gameListTranslations));
184 XtSetArg(args[j], XtNfromVert, viewport); j++;
185 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
186 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
187 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
188 XtSetArg(args[j], XtNright, XtChainLeft); j++;
190 XtCreateManagedWidget(_("load"), commandWidgetClass, form, args, j);
191 XtAddCallback(b_load, XtNcallback, callback, client_data);
194 XtSetArg(args[j], XtNfromVert, viewport); j++;
195 XtSetArg(args[j], XtNfromHoriz, b_load); j++;
196 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
197 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
198 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
199 XtSetArg(args[j], XtNright, XtChainLeft); j++;
201 XtCreateManagedWidget(_("prev"), commandWidgetClass, form, args, j);
202 XtAddCallback(b_loadprev, XtNcallback, callback, client_data);
205 XtSetArg(args[j], XtNfromVert, viewport); j++;
206 XtSetArg(args[j], XtNfromHoriz, b_loadprev); j++;
207 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
208 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
209 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
210 XtSetArg(args[j], XtNright, XtChainLeft); j++;
212 XtCreateManagedWidget(_("next"), commandWidgetClass, form, args, j);
213 XtAddCallback(b_loadnext, XtNcallback, callback, client_data);
216 XtSetArg(args[j], XtNfromVert, viewport); j++;
217 XtSetArg(args[j], XtNfromHoriz, b_loadnext); j++;
218 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
219 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
220 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
221 XtSetArg(args[j], XtNright, XtChainLeft); j++;
223 XtCreateManagedWidget(_("close"), commandWidgetClass, form, args, j);
224 XtAddCallback(b_close, XtNcallback, callback, client_data);
233 XtSetArg(args[j], XtNheight, &h1); j++;
234 XtSetArg(args[j], XtNy, &y1); j++;
235 XtGetValues(boardWidget, args, j);
236 glc->w = fw_width * 3/4;
237 glc->h = squareSize * 3;
239 XSync(xDisplay, False);
241 /* This code seems to tickle an X bug if it is executed too soon
242 after xboard starts up. The coordinates get transformed as if
243 the main window was positioned at (0, 0).
245 XtTranslateCoords(shellWidget, (fw_width - glc->w) / 2,
246 y1 + (h1 - glc->h + appData.borderYoffset) / 2,
249 XTranslateCoordinates(xDisplay, XtWindow(shellWidget),
250 RootWindowOfScreen(XtScreen(shellWidget)),
251 (fw_width - glc->w) / 2,
252 y1 + (h1 - glc->h + appData.borderYoffset) / 2,
257 if (glc->y < 0) glc->y = 0; /*avoid positioning top offscreen*/
260 XtSetArg(args[j], XtNheight, glc->h); j++;
261 XtSetArg(args[j], XtNwidth, glc->w); j++;
262 XtSetArg(args[j], XtNx, glc->x - appData.borderXoffset); j++;
263 XtSetArg(args[j], XtNy, glc->y - appData.borderYoffset); j++;
264 XtSetValues(shell, args, j);
266 XtRealizeWidget(shell);
267 CatchDeleteWindow(shell, "GameListPopDown");
273 GameListCallback(w, client_data, call_data)
275 XtPointer client_data, call_data;
281 GameListClosure *glc = (GameListClosure *) client_data;
282 XawListReturnStruct *rs;
286 XtSetArg(args[j], XtNlabel, &name); j++;
287 XtGetValues(w, args, j);
289 if (strcmp(name, _("close")) == 0) {
293 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
294 rs = XawListShowCurrent(listwidg);
295 if (strcmp(name, _("load")) == 0) {
296 index = rs->list_index;
298 DisplayError(_("No game selected"), 0);
301 } else if (strcmp(name, _("next")) == 0) {
302 index = rs->list_index + 1;
303 if (index >= ((ListGame *) gameList.tailPred)->number) {
304 DisplayError(_("Can't go forward any further"), 0);
307 XawListHighlight(listwidg, index);
308 } else if (strcmp(name, _("prev")) == 0) {
309 index = rs->list_index - 1;
311 DisplayError(_("Can't back up any further"), 0);
314 XawListHighlight(listwidg, index);
316 if (cmailMsgLoaded) {
317 CmailLoadGame(glc->fp, index + 1, glc->filename, True);
319 LoadGame(glc->fp, index + 1, glc->filename, True);
323 static GameListClosure *glc = NULL;
326 GameListPopUp(fp, filename)
337 glc = (GameListClosure *) calloc(1, sizeof(GameListClosure));
338 glc->x = glc->y = -1;
341 if (glc->strings != NULL) {
349 nstrings = ((ListGame *) gameList.tailPred)->number;
350 glc->strings = (char **) malloc((nstrings + 1) * sizeof(char *));
352 lg = (ListGame *) gameList.head;
354 *st++ = GameListLine(lg->number, &lg->gameInfo);
355 lg = (ListGame *) lg->node.succ;
361 if (glc->filename != NULL) free(glc->filename);
362 glc->filename = StrSave(filename);
364 if (glc->shell == NULL) {
365 glc->shell = GameListCreate(filename, GameListCallback, glc);
367 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
368 XawListChange(listwidg, glc->strings, 0, 0, True);
369 XawListHighlight(listwidg, 0);
371 XtSetArg(args[j], XtNiconName, (XtArgVal) filename); j++;
372 XtSetArg(args[j], XtNtitle, (XtArgVal) filename); j++;
373 XtSetValues(glc->shell, args, j);
376 XtPopup(glc->shell, XtGrabNone);
379 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
380 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Game List"),
387 if (glc == NULL) return;
389 if (glc->strings != NULL) {
402 ShowGameListProc(w, event, prms, nprms)
412 DisplayError(_("There is no game list"), 0);
419 XtPopup(glc->shell, XtGrabNone);
422 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
423 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Game List"),
428 LoadSelectedProc(w, event, prms, nprms)
435 XawListReturnStruct *rs;
438 if (glc == NULL) return;
439 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
440 rs = XawListShowCurrent(listwidg);
441 index = rs->list_index;
442 if (index < 0) return;
443 if (cmailMsgLoaded) {
444 CmailLoadGame(glc->fp, index + 1, glc->filename, True);
446 LoadGame(glc->fp, index + 1, glc->filename, True);
456 if (glc == NULL) return;
458 XtSetArg(args[j], XtNx, &glc->x); j++;
459 XtSetArg(args[j], XtNy, &glc->y); j++;
460 XtSetArg(args[j], XtNheight, &glc->h); j++;
461 XtSetArg(args[j], XtNwidth, &glc->w); j++;
462 XtGetValues(glc->shell, args, j);
463 XtPopdown(glc->shell);
464 XtSetKeyboardFocus(shellWidget, formWidget);
467 XtSetArg(args[j], XtNleftBitmap, None); j++;
468 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Game List"),
473 GameListHighlight(index)
477 if (glc == NULL || !glc->up) return;
478 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
479 XawListHighlight(listwidg, index - 1);