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;
97 void SetFocus P((Widget w, XtPointer data, XEvent *event, Boolean *b));
99 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget, gameListShell;
101 extern int squareSize;
102 extern Pixmap xMarkPixmap;
103 extern char *layoutName;
105 static Widget filterText;
106 static char filterString[MSG_SIZ];
107 static int listLength;
109 char gameListTranslations[] =
110 "<Btn1Up>(2): LoadSelectedProc(0) \n \
111 <Key>Home: LoadSelectedProc(-2) \n \
112 <Key>End: LoadSelectedProc(2) \n \
113 <Key>Up: LoadSelectedProc(-1) \n \
114 <Key>Down: LoadSelectedProc(1) \n \
115 <Key>Left: LoadSelectedProc(-1) \n \
116 <Key>Right: LoadSelectedProc(1) \n \
117 <Key>Return: LoadSelectedProc(0) \n";
118 char filterTranslations[] =
119 "<Key>Return: SetFilterProc() \n";
130 static GameListClosure *glc = NULL;
132 static Arg layoutArgs[] = {
133 { XtNborderWidth, 0 },
134 { XtNdefaultDistance, 0 }
138 GameListCreate(name, callback, client_data)
140 XtCallbackProc callback;
141 XtPointer client_data;
148 { // [HGM] filter: put in separate routine, to make callable from call-back
153 nstrings = ((ListGame *) gameList.tailPred)->number;
154 glc->strings = (char **) malloc((nstrings + 1) * sizeof(char *));
156 lg = (ListGame *) gameList.head;
159 line = GameListLine(lg->number, &lg->gameInfo);
160 if(filterString[0] == NULLCHAR || SearchPattern( line, filterString ) ) {
161 *st++ = line; // [HGM] filter: make adding line conditional
164 lg = (ListGame *) lg->node.succ;
172 { // [HGM] filter: put in separate routine, to make callable from call-back
177 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
178 XawListChange(listwidg, glc->strings, 0, 0, True);
179 XawListHighlight(listwidg, 0);
183 GameListCallback(w, client_data, call_data)
185 XtPointer client_data, call_data;
191 GameListClosure *glc = (GameListClosure *) client_data;
192 XawListReturnStruct *rs;
196 XtSetArg(args[j], XtNlabel, &name); j++;
197 XtGetValues(w, args, j);
199 if (strcmp(name, _("close")) == 0) {
203 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
204 rs = XawListShowCurrent(listwidg);
205 if (strcmp(name, _("load")) == 0) {
206 index = rs->list_index;
208 DisplayError(_("No game selected"), 0);
211 } else if (strcmp(name, _("next")) == 0) {
212 index = rs->list_index + 1;
213 if (index >= listLength) {
214 DisplayError(_("Can't go forward any further"), 0);
217 XawListHighlight(listwidg, index);
218 } else if (strcmp(name, _("prev")) == 0) {
219 index = rs->list_index - 1;
221 DisplayError(_("Can't back up any further"), 0);
224 XawListHighlight(listwidg, index);
225 } else if (strcmp(name, _("apply")) == 0) {
228 XtSetArg(args[j], XtNstring, &name); j++;
229 XtGetValues(filterText, args, j);
230 strcpy(filterString, name);
231 XawListHighlight(listwidg, 0);
232 if(GameListPrepare()) GameListReplace(); // crashes on empty list...
235 index = atoi(glc->strings[index])-1; // [HGM] filter: read true index from sequence nr of line
236 if (cmailMsgLoaded) {
237 CmailLoadGame(glc->fp, index + 1, glc->filename, True);
239 LoadGame(glc->fp, index + 1, glc->filename, True);
244 GameListPopUp(fp, filename)
252 /* first clear everything, do we need this? */
253 gtk_list_store_clear(LIST_GameList);
255 /* fill list with information */
256 lg = (ListGame *) gameList.head;
257 nstrings = ((ListGame *) gameList.tailPred)->number;
260 gtk_list_store_append (LIST_GameList, &iter);
261 gtk_list_store_set (LIST_GameList, &iter,
262 0, StrSave(filename),
263 1, GameListLine(lg->number, &lg->gameInfo),
266 lg = (ListGame *) lg->node.succ;
270 gtk_widget_show (GUI_GameList);
272 // XtPopup(glc->shell, XtGrabNone);
275 // XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
276 // XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Game List"),
287 gtk_list_store_clear(LIST_GameList);
292 ShowGameListProc(w, event, prms, nprms)
302 DisplayError(_("There is no game list"), 0);
309 XtPopup(glc->shell, XtGrabNone);
312 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
313 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Game List"),
318 LoadSelectedProc(w, event, prms, nprms)
325 XawListReturnStruct *rs;
326 int index, direction = atoi(prms[0]);
328 if (glc == NULL) return;
329 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
330 rs = XawListShowCurrent(listwidg);
331 index = rs->list_index;
332 if (index < 0) return;
335 if(direction == -2) index = 0;
336 if(direction == 2) index = listLength-1;
337 if(index < 0 || index >= listLength) return;
338 XawListHighlight(listwidg, index);
341 index = atoi(glc->strings[index])-1; // [HGM] filter: read true index from sequence nr of line
342 if (cmailMsgLoaded) {
343 CmailLoadGame(glc->fp, index + 1, glc->filename, True);
345 LoadGame(glc->fp, index + 1, glc->filename, True);
350 SetFilterProc(w, event, prms, nprms)
360 XtSetArg(args[j], XtNstring, &name); j++;
361 XtGetValues(filterText, args, j);
362 strcpy(filterString, name);
363 if(GameListPrepare()) GameListReplace(); // crashes on empty list...
364 list = XtNameToWidget(glc->shell, "*form.viewport.list");
365 XawListHighlight(list, 0);
367 XtSetArg(args[j], XtNdisplayCaret, False); j++;
368 XtSetValues(filterText, args, j);
369 XtSetKeyboardFocus(glc->shell, list);
375 /* hides the history window */
377 gtk_widget_hide (GUI_GameList);
382 GameListHighlight(index)
387 if (glc == NULL || !glc->up) return;
388 listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
390 while(*st && atoi(*st)<index) st++,i++;
391 XawListHighlight(listwidg, i);
397 /* return status of history window */
399 return gtk_widget_get_visible (GUI_GameList);
402 //--------------------------------- Game-List options dialog ------------------------------------------
404 Widget gameListOptShell, listwidg;
415 void GLT_AddToList(char *name)
417 strings[stringPtr++] = name;
418 strings[stringPtr] = NULL;
421 Boolean GLT_GetFromList(int index, char *name)
423 strcpy(name, strings[index]);
426 void GLT_DeSelectList()
428 XawListChange(listwidg, strings, 0, 0, True);
429 XawListHighlight(listwidg, 0);
433 GameListOptionsPopDown()
438 if (gameListOptShell == NULL) return;
439 XtPopdown(gameListOptShell);
440 XtDestroyWidget(gameListOptShell);
441 gameListOptShell = 0;
442 // XtSetKeyboardFocus(shellWidget, formWidget);
446 GameListOptionsCallback(w, client_data, call_data)
448 XtPointer client_data, call_data;
454 XawListReturnStruct *rs;
459 XtSetArg(args[j], XtNlabel, &name); j++;
460 XtGetValues(w, args, j);
462 if (strcmp(name, _("OK")) == 0) {
464 appData.gameListTags = strdup(lpUserGLT);
465 GameListOptionsPopDown();
468 if (strcmp(name, _("cancel")) == 0) {
469 GameListOptionsPopDown();
472 listwidg = XtNameToWidget(gameListOptShell, "*form.list");
473 rs = XawListShowCurrent(listwidg);
474 index = rs->list_index;
476 DisplayError(_("No tag selected"), 0);
480 if (strcmp(name, _("down")) == 0) {
481 if(index >= strlen(GLT_ALL_TAGS)) return;
482 strings[index] = strings[index+1];
483 strings[++index] = p;
485 if (strcmp(name, _("up")) == 0) {
486 if(index == 0) return;
487 strings[index] = strings[index-1];
488 strings[--index] = p;
490 if (strcmp(name, _("factory")) == 0) {
491 strcpy(lpUserGLT, GLT_DEFAULT_TAGS);
492 GLT_TagsToList(lpUserGLT);
495 XawListHighlight(listwidg, index);
499 GameListOptionsCreate()
502 Widget shell, form, viewport, layout;
503 Widget b_load, b_loadprev, b_loadnext, b_close, b_cancel;
505 XtPointer client_data = NULL;
509 XtSetArg(args[j], XtNwidth, &fw_width); j++;
510 XtGetValues(formWidget, args, j);
513 XtSetArg(args[j], XtNresizable, True); j++;
514 XtSetArg(args[j], XtNallowShellResize, True); j++;
515 // shell = gameListOptShell =
516 // XtCreatePopupShell("Game-list options", transientShellWidgetClass,
517 // shellWidget, args, j);
519 XtCreateManagedWidget(layoutName, formWidgetClass, shell,
520 layoutArgs, XtNumber(layoutArgs));
522 XtSetArg(args[j], XtNborderWidth, 0); j++;
524 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
527 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
528 XtSetArg(args[j], XtNforceColumns, True); j++;
529 XtSetArg(args[j], XtNverticalList, True); j++;
530 listwidg = viewport =
531 XtCreateManagedWidget("list", listWidgetClass, form, args, j);
532 XawListHighlight(listwidg, 0);
533 // XtAugmentTranslations(listwidg,
534 // XtParseTranslationTable(gameListOptTranslations));
537 XtSetArg(args[j], XtNfromVert, viewport); j++;
538 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
539 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
540 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
541 XtSetArg(args[j], XtNright, XtChainLeft); j++;
543 XtCreateManagedWidget(_("factory"), commandWidgetClass, form, args, j);
544 XtAddCallback(b_load, XtNcallback, GameListOptionsCallback, client_data);
547 XtSetArg(args[j], XtNfromVert, viewport); j++;
548 XtSetArg(args[j], XtNfromHoriz, b_load); j++;
549 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
550 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
551 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
552 XtSetArg(args[j], XtNright, XtChainLeft); j++;
554 XtCreateManagedWidget(_("up"), commandWidgetClass, form, args, j);
555 XtAddCallback(b_loadprev, XtNcallback, GameListOptionsCallback, client_data);
558 XtSetArg(args[j], XtNfromVert, viewport); j++;
559 XtSetArg(args[j], XtNfromHoriz, b_loadprev); j++;
560 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
561 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
562 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
563 XtSetArg(args[j], XtNright, XtChainLeft); j++;
565 XtCreateManagedWidget(_("down"), commandWidgetClass, form, args, j);
566 XtAddCallback(b_loadnext, XtNcallback, GameListOptionsCallback, client_data);
569 XtSetArg(args[j], XtNfromVert, viewport); j++;
570 XtSetArg(args[j], XtNfromHoriz, b_loadnext); j++;
571 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
572 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
573 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
574 XtSetArg(args[j], XtNright, XtChainLeft); j++;
576 XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
577 XtAddCallback(b_cancel, XtNcallback, GameListOptionsCallback, client_data);
580 XtSetArg(args[j], XtNfromVert, viewport); j++;
581 XtSetArg(args[j], XtNfromHoriz, b_cancel); j++;
582 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
583 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
584 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
585 XtSetArg(args[j], XtNright, XtChainLeft); j++;
587 XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
588 XtAddCallback(b_close, XtNcallback, GameListOptionsCallback, client_data);
590 strcpy(lpUserGLT, appData.gameListTags);
591 GLT_TagsToList(lpUserGLT);
593 XtRealizeWidget(shell);
594 // CatchDeleteWindow(shell, "GameListOptionsPopDown");
600 GameListOptionsPopUp(Widget w, XEvent *event, String *prms, Cardinal *nprms)
606 if (gameListOptShell == NULL) {
607 gameListOptShell = GameListOptionsCreate();
610 XtPopup(gameListOptShell, XtGrabNone);