2 * xgamelist.c -- Game list window, part of X front end for XBoard
4 * Copyright 1995,2009 Free Software Foundation, Inc.
5 * ------------------------------------------------------------------------
7 * GNU XBoard is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at
10 * your option) any later version.
12 * GNU XBoard is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see http://www.gnu.org/licenses/. *
20 *------------------------------------------------------------------------
21 ** See the file ChangeLog for a revision history. */
29 #include <sys/types.h>
34 #else /* not STDC_HEADERS */
35 extern char *getenv();
38 # else /* not HAVE_STRING_H */
40 # endif /* not HAVE_STRING_H */
41 #endif /* not STDC_HEADERS */
47 #include <X11/Intrinsic.h>
48 #include <X11/StringDefs.h>
49 #include <X11/Shell.h>
50 #include <X11/cursorfont.h>
52 #include <X11/Xaw3d/Dialog.h>
53 #include <X11/Xaw3d/Form.h>
54 #include <X11/Xaw3d/List.h>
55 #include <X11/Xaw3d/Label.h>
56 #include <X11/Xaw3d/SimpleMenu.h>
57 #include <X11/Xaw3d/SmeBSB.h>
58 #include <X11/Xaw3d/SmeLine.h>
59 #include <X11/Xaw3d/Box.h>
60 #include <X11/Xaw3d/MenuButton.h>
61 #include <X11/Xaw3d/Text.h>
62 #include <X11/Xaw3d/AsciiText.h>
63 #include <X11/Xaw3d/Viewport.h>
65 #include <X11/Xaw/Dialog.h>
66 #include <X11/Xaw/Form.h>
67 #include <X11/Xaw/List.h>
68 #include <X11/Xaw/Label.h>
69 #include <X11/Xaw/SimpleMenu.h>
70 #include <X11/Xaw/SmeBSB.h>
71 #include <X11/Xaw/SmeLine.h>
72 #include <X11/Xaw/Box.h>
73 #include <X11/Xaw/MenuButton.h>
74 #include <X11/Xaw/Text.h>
75 #include <X11/Xaw/AsciiText.h>
76 #include <X11/Xaw/Viewport.h>
83 #include "xgamelist.h"
87 # define _(s) gettext (s)
88 # define N_(s) gettext_noop (s)
94 extern GtkWidget *GUI_GameList;
95 extern GtkListStore *LIST_GameList;
98 extern Widget formWidget, boardWidget, menuBarWidget, gameListShell;
99 extern int squareSize;
100 extern Pixmap xMarkPixmap;
101 extern char *layoutName;
103 char gameListTranslations[] =
104 "<Btn1Up>(2): LoadSelectedProc() \n \
105 <Key>Return: LoadSelectedProc() \n";
117 static Arg layoutArgs[] = {
118 { XtNborderWidth, 0 },
119 { XtNdefaultDistance, 0 }
123 GameListCreate(name, callback, client_data)
125 XtCallbackProc callback;
126 XtPointer client_data;
132 GameListCallback(w, client_data, call_data)
134 XtPointer client_data, call_data;
140 GameListClosure *glc = (GameListClosure *) client_data;
141 XawListReturnStruct *rs;
145 XtSetArg(args[j], XtNlabel, &name); j++;
146 XtGetValues(w, args, j);
148 if (strcmp(name, _("close")) == 0) {
152 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
153 rs = XawListShowCurrent(listwidg);
154 if (strcmp(name, _("load")) == 0) {
155 index = rs->list_index;
157 DisplayError(_("No game selected"), 0);
160 } else if (strcmp(name, _("next")) == 0) {
161 index = rs->list_index + 1;
162 if (index >= ((ListGame *) gameList.tailPred)->number) {
163 DisplayError(_("Can't go forward any further"), 0);
166 XawListHighlight(listwidg, index);
167 } else if (strcmp(name, _("prev")) == 0) {
168 index = rs->list_index - 1;
170 DisplayError(_("Can't back up any further"), 0);
173 XawListHighlight(listwidg, index);
175 if (cmailMsgLoaded) {
176 CmailLoadGame(glc->fp, index + 1, glc->filename, True);
178 LoadGame(glc->fp, index + 1, glc->filename, True);
182 static GameListClosure *glc = NULL;
185 GameListPopUp(fp, filename)
193 /* first clear everything, do we need this? */
194 gtk_list_store_clear(LIST_GameList);
196 /* fill list with information */
197 lg = (ListGame *) gameList.head;
198 nstrings = ((ListGame *) gameList.tailPred)->number;
201 gtk_list_store_append (LIST_GameList, &iter);
202 gtk_list_store_set (LIST_GameList, &iter,
203 0, StrSave(filename),
204 1, GameListLine(lg->number, &lg->gameInfo),
207 lg = (ListGame *) lg->node.succ;
212 gtk_widget_show (GUI_GameList);
214 // XtPopup(glc->shell, XtGrabNone);
217 // XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
218 // XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Game List"),
229 gtk_list_store_clear(LIST_GameList);
234 ShowGameListProc(w, event, prms, nprms)
244 DisplayError(_("There is no game list"), 0);
251 XtPopup(glc->shell, XtGrabNone);
254 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
255 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Game List"),
260 LoadSelectedProc(w, event, prms, nprms)
267 XawListReturnStruct *rs;
270 if (glc == NULL) return;
271 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
272 rs = XawListShowCurrent(listwidg);
273 index = rs->list_index;
274 if (index < 0) return;
275 if (cmailMsgLoaded) {
276 CmailLoadGame(glc->fp, index + 1, glc->filename, True);
278 LoadGame(glc->fp, index + 1, glc->filename, True);
285 /* hides the history window */
287 gtk_widget_hide (GUI_GameList);
292 GameListHighlight(index)
296 if (glc == NULL || !glc->up) return;
297 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
298 XawListHighlight(listwidg, index - 1);
304 /* return status of history window */
306 return gtk_widget_get_visible (GUI_GameList);