46200c50a6197231c39ef22c779021b5f2394a37
[xboard.git] / xgamelist.c
1 /*
2  * xgamelist.c -- Game list window, part of X front end for XBoard
3  *
4  * Copyright 1995, 2009, 2010, 2011 Free Software Foundation, Inc.
5  * ------------------------------------------------------------------------
6  *
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.
11  *
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.
16  *
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/.  *
19  *
20  *------------------------------------------------------------------------
21  ** See the file ChangeLog for a revision history.  */
22
23 #include "config.h"
24
25 #include <stdio.h>
26 #include <ctype.h>
27 #include <errno.h>
28 #include <sys/types.h>
29
30 #if STDC_HEADERS
31 # include <stdlib.h>
32 # include <string.h>
33 #else /* not STDC_HEADERS */
34 extern char *getenv();
35 # if HAVE_STRING_H
36 #  include <string.h>
37 # else /* not HAVE_STRING_H */
38 #  include <strings.h>
39 # endif /* not HAVE_STRING_H */
40 #endif /* not STDC_HEADERS */
41
42 #if HAVE_UNISTD_H
43 # include <unistd.h>
44 #endif
45
46 #include <X11/Intrinsic.h>
47 #include <X11/StringDefs.h>
48 #include <X11/Shell.h>
49 #include <X11/cursorfont.h>
50 #if USE_XAW3D
51 #include <X11/Xaw3d/Dialog.h>
52 #include <X11/Xaw3d/Form.h>
53 #include <X11/Xaw3d/List.h>
54 #include <X11/Xaw3d/Label.h>
55 #include <X11/Xaw3d/SimpleMenu.h>
56 #include <X11/Xaw3d/SmeBSB.h>
57 #include <X11/Xaw3d/SmeLine.h>
58 #include <X11/Xaw3d/Box.h>
59 #include <X11/Xaw3d/MenuButton.h>
60 #include <X11/Xaw3d/Text.h>
61 #include <X11/Xaw3d/AsciiText.h>
62 #include <X11/Xaw3d/Viewport.h>
63 #else
64 #include <X11/Xaw/Dialog.h>
65 #include <X11/Xaw/Form.h>
66 #include <X11/Xaw/List.h>
67 #include <X11/Xaw/Label.h>
68 #include <X11/Xaw/SimpleMenu.h>
69 #include <X11/Xaw/SmeBSB.h>
70 #include <X11/Xaw/SmeLine.h>
71 #include <X11/Xaw/Box.h>
72 #include <X11/Xaw/MenuButton.h>
73 #include <X11/Xaw/Text.h>
74 #include <X11/Xaw/AsciiText.h>
75 #include <X11/Xaw/Viewport.h>
76 #endif
77
78 #include "common.h"
79 #include "frontend.h"
80 #include "backend.h"
81 #include "xboard.h"
82 #include "xgamelist.h"
83 #include "gettext.h"
84
85 #ifdef ENABLE_NLS
86 # define  _(s) gettext (s)
87 # define N_(s) gettext_noop (s)
88 #else
89 # define  _(s) (s)
90 # define N_(s)  s
91 #endif
92
93
94 void SetFocus P((Widget w, XtPointer data, XEvent *event, Boolean *b));
95
96 static Widget filterText;
97 static char filterString[MSG_SIZ];
98 static int listLength;
99
100 char gameListTranslations[] =
101   "<Btn1Up>(2): LoadSelectedProc(0) \n \
102    <Key>Home: LoadSelectedProc(-2) \n \
103    <Key>End: LoadSelectedProc(2) \n \
104    <Key>Up: LoadSelectedProc(-1) \n \
105    <Key>Down: LoadSelectedProc(1) \n \
106    <Key>Left: LoadSelectedProc(-1) \n \
107    <Key>Right: LoadSelectedProc(1) \n \
108    <Key>Return: LoadSelectedProc(0) \n";
109 char filterTranslations[] =
110   "<Key>Return: SetFilterProc() \n";
111
112 typedef struct {
113     Widget shell;
114     Position x, y;
115     Dimension w, h;
116     Boolean up;
117     FILE *fp;
118     char *filename;
119     char **strings;
120 } GameListClosure;
121 static GameListClosure *glc = NULL;
122
123 Widget
124 GameListCreate(name, callback, client_data)
125      char *name;
126      XtCallbackProc callback;
127      XtPointer client_data;
128 {
129     Arg args[16];
130     Widget shell, form, viewport, listwidg, layout, label;
131     Widget b_load, b_loadprev, b_loadnext, b_close, b_filter;
132     Dimension fw_width;
133     int j;
134     GameListClosure *glc = (GameListClosure *) client_data;
135
136     j = 0;
137     XtSetArg(args[j], XtNwidth, &fw_width);  j++;
138     XtGetValues(formWidget, args, j);
139
140     j = 0;
141     XtSetArg(args[j], XtNresizable, True);  j++;
142     XtSetArg(args[j], XtNallowShellResize, True);  j++;
143 #if TOPLEVEL
144     shell = gameListShell =
145       XtCreatePopupShell(name, topLevelShellWidgetClass,
146                          shellWidget, args, j);
147 #else
148     shell = gameListShell =
149       XtCreatePopupShell(name, transientShellWidgetClass,
150                          shellWidget, args, j);
151 #endif
152     layout =
153       XtCreateManagedWidget(layoutName, formWidgetClass, shell,
154                             layoutArgs, XtNumber(layoutArgs));
155     j = 0;
156     XtSetArg(args[j], XtNborderWidth, 0); j++;
157     form =
158       XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
159
160     j = 0;
161     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
162     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
163     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
164     XtSetArg(args[j], XtNright, XtChainRight);  j++;
165     XtSetArg(args[j], XtNresizable, False);  j++;
166     XtSetArg(args[j], XtNwidth, fw_width);  j++;
167     XtSetArg(args[j], XtNallowVert, True); j++;
168     viewport =
169       XtCreateManagedWidget("viewport", viewportWidgetClass, form, args, j);
170
171     j = 0;
172     XtSetArg(args[j], XtNlist, glc->strings);  j++;
173     XtSetArg(args[j], XtNdefaultColumns, 1);  j++;
174     XtSetArg(args[j], XtNforceColumns, True);  j++;
175     XtSetArg(args[j], XtNverticalList, True);  j++;
176     listwidg =
177       XtCreateManagedWidget("list", listWidgetClass, viewport, args, j);
178     XawListHighlight(listwidg, 0);
179     XtAugmentTranslations(listwidg,
180                           XtParseTranslationTable(gameListTranslations));
181
182     j = 0;
183     XtSetArg(args[j], XtNfromVert, viewport);  j++;
184     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
185     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
186     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
187     XtSetArg(args[j], XtNright, XtChainLeft); j++;
188     b_load =
189       XtCreateManagedWidget(_("load"), commandWidgetClass, form, args, j);
190     XtAddCallback(b_load, XtNcallback, callback, client_data);
191
192     j = 0;
193     XtSetArg(args[j], XtNfromVert, viewport);  j++;
194     XtSetArg(args[j], XtNfromHoriz, b_load);  j++;
195     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
196     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
197     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
198     XtSetArg(args[j], XtNright, XtChainLeft); j++;
199     b_loadprev =
200       XtCreateManagedWidget(_("prev"), commandWidgetClass, form, args, j);
201     XtAddCallback(b_loadprev, XtNcallback, callback, client_data);
202
203     j = 0;
204     XtSetArg(args[j], XtNfromVert, viewport);  j++;
205     XtSetArg(args[j], XtNfromHoriz, b_loadprev);  j++;
206     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
207     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
208     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
209     XtSetArg(args[j], XtNright, XtChainLeft); j++;
210     b_loadnext =
211       XtCreateManagedWidget(_("next"), commandWidgetClass, form, args, j);
212     XtAddCallback(b_loadnext, XtNcallback, callback, client_data);
213
214     j = 0;
215     XtSetArg(args[j], XtNfromVert, viewport);  j++;
216     XtSetArg(args[j], XtNfromHoriz, b_loadnext);  j++;
217     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
218     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
219     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
220     XtSetArg(args[j], XtNright, XtChainLeft); j++;
221     b_close =
222       XtCreateManagedWidget(_("close"), commandWidgetClass, form, args, j);
223     XtAddCallback(b_close, XtNcallback, callback, client_data);
224
225     j = 0;
226     XtSetArg(args[j], XtNfromVert, viewport);  j++;
227     XtSetArg(args[j], XtNfromHoriz, b_close);  j++;
228     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
229     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
230     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
231     XtSetArg(args[j], XtNright, XtChainLeft); j++;
232     XtSetArg(args[j], XtNborderWidth, 0); j++;
233     label =
234       XtCreateManagedWidget(_("Filter:"), labelWidgetClass, form, args, j);
235
236     j = 0;
237     XtSetArg(args[j], XtNfromVert, viewport);  j++;
238     XtSetArg(args[j], XtNfromHoriz, label);  j++;
239     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
240     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
241     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
242     XtSetArg(args[j], XtNright, XtChainRight); j++;
243     XtSetArg(args[j], XtNwidth, fw_width - 225 - squareSize); j++;
244     XtSetArg(args[j], XtNstring, filterString);  j++;
245     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
246     XtSetArg(args[j], XtNresizable, True);  j++;
247 //    XtSetArg(args[j], XtNwidth, bw_width);  j++; /*force wider than buttons*/
248     /* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */
249     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
250     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
251     filterText =
252       XtCreateManagedWidget(_("filtertext"), asciiTextWidgetClass, form, args, j);
253     XtAddEventHandler(filterText, ButtonPressMask, False, SetFocus, (XtPointer) shell);
254     XtOverrideTranslations(filterText,
255                           XtParseTranslationTable(filterTranslations));
256
257     j = 0;
258     XtSetArg(args[j], XtNfromVert, viewport);  j++;
259     XtSetArg(args[j], XtNfromHoriz, filterText);  j++;
260     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
261     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
262     XtSetArg(args[j], XtNleft, XtChainRight); j++;
263     XtSetArg(args[j], XtNright, XtChainRight); j++;
264     b_filter =
265       XtCreateManagedWidget(_("apply"), commandWidgetClass, form, args, j);
266     XtAddCallback(b_filter, XtNcallback, callback, client_data);
267
268
269     if(wpGameList.width > 0) {
270         glc->x = wpGameList.x;
271         glc->y = wpGameList.y;
272         glc->w = wpGameList.width;
273         glc->h = wpGameList.height;
274     }
275
276     if (glc->x == -1) {
277         Position y1;
278         Dimension h1;
279         int xx, yy;
280         Window junk;
281
282         j = 0;
283         XtSetArg(args[j], XtNheight, &h1); j++;
284         XtSetArg(args[j], XtNy, &y1); j++;
285         XtGetValues(boardWidget, args, j);
286         glc->w = fw_width * 3/4;
287         glc->h = squareSize * 3;
288
289         XSync(xDisplay, False);
290 #ifdef NOTDEF
291         /* This code seems to tickle an X bug if it is executed too soon
292            after xboard starts up.  The coordinates get transformed as if
293            the main window was positioned at (0, 0).
294         */
295         XtTranslateCoords(shellWidget, (fw_width - glc->w) / 2,
296                           y1 + (h1 - glc->h + appData.borderYoffset) / 2,
297                           &glc->x, &glc->y);
298 #else /*!NOTDEF*/
299         XTranslateCoordinates(xDisplay, XtWindow(shellWidget),
300                               RootWindowOfScreen(XtScreen(shellWidget)),
301                               (fw_width - glc->w) / 2,
302                               y1 + (h1 - glc->h + appData.borderYoffset) / 2,
303                               &xx, &yy, &junk);
304         glc->x = xx;
305         glc->y = yy;
306 #endif /*!NOTDEF*/
307         if (glc->y < 0) glc->y = 0; /*avoid positioning top offscreen*/
308     }
309     j = 0;
310     XtSetArg(args[j], XtNheight, glc->h);  j++;
311     XtSetArg(args[j], XtNwidth, glc->w);  j++;
312     XtSetArg(args[j], XtNx, glc->x - appData.borderXoffset);  j++;
313     XtSetArg(args[j], XtNy, glc->y - appData.borderYoffset);  j++;
314     XtSetValues(shell, args, j);
315
316     XtRealizeWidget(shell);
317     CatchDeleteWindow(shell, "GameListPopDown");
318     XtSetKeyboardFocus(shell, listwidg);
319
320     return shell;
321 }
322
323 static int
324 GameListPrepare()
325 {   // [HGM] filter: put in separate routine, to make callable from call-back
326     int nstrings;
327     ListGame *lg;
328     char **st, *line;
329
330     nstrings = ((ListGame *) gameList.tailPred)->number;
331     glc->strings = (char **) malloc((nstrings + 1) * sizeof(char *));
332     st = glc->strings;
333     lg = (ListGame *) gameList.head;
334     listLength = 0;
335     while (nstrings--) {
336         line = GameListLine(lg->number, &lg->gameInfo);
337         if(filterString[0] == NULLCHAR || SearchPattern( line, filterString ) ) {
338             *st++ = line; // [HGM] filter: make adding line conditional
339             listLength++;
340         }
341         lg = (ListGame *) lg->node.succ;
342      }
343     *st = NULL;
344     return listLength;
345 }
346
347 static void
348 GameListReplace()
349 {
350   // filter: put in separate routine, to make callable from call-back
351   Widget listwidg;
352
353   listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
354   XawListChange(listwidg, glc->strings, 0, 0, True);
355   XawListHighlight(listwidg, 0);
356 }
357
358 void
359 GameListCallback(w, client_data, call_data)
360      Widget w;
361      XtPointer client_data, call_data;
362 {
363     String name;
364     Arg args[16];
365     int j;
366     Widget listwidg;
367     GameListClosure *glc = (GameListClosure *) client_data;
368     XawListReturnStruct *rs;
369     int index;
370
371     j = 0;
372     XtSetArg(args[j], XtNlabel, &name);  j++;
373     XtGetValues(w, args, j);
374
375     if (strcmp(name, _("close")) == 0) {
376         GameListPopDown();
377         return;
378     }
379     listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
380     rs = XawListShowCurrent(listwidg);
381     if (strcmp(name, _("load")) == 0) {
382         index = rs->list_index;
383         if (index < 0) {
384             DisplayError(_("No game selected"), 0);
385             return;
386         }
387     } else if (strcmp(name, _("next")) == 0) {
388         index = rs->list_index + 1;
389         if (index >= listLength) {
390             DisplayError(_("Can't go forward any further"), 0);
391             return;
392         }
393         XawListHighlight(listwidg, index);
394     } else if (strcmp(name, _("prev")) == 0) {
395         index = rs->list_index - 1;
396         if (index < 0) {
397             DisplayError(_("Can't back up any further"), 0);
398             return;
399         }
400         XawListHighlight(listwidg, index);
401     } else if (strcmp(name, _("apply")) == 0) {
402         String name;
403         j = 0;
404         XtSetArg(args[j], XtNstring, &name);  j++;
405         XtGetValues(filterText, args, j);
406         safeStrCpy(filterString, name, sizeof(filterString)/sizeof(filterString[0]));
407         XawListHighlight(listwidg, 0);
408         if(GameListPrepare()) GameListReplace(); // crashes on empty list...
409         return;
410     }
411 #if 0
412     index = atoi(glc->strings[index])-1; // [HGM] filter: read true index from sequence nr of line
413     if (cmailMsgLoaded) {
414         CmailLoadGame(glc->fp, index + 1, glc->filename, True);
415     } else {
416         LoadGame(glc->fp, index + 1, glc->filename, True);
417     }
418 #else
419     printf("This code should have been unreachable. Please report bug!\n");
420 #endif
421 }
422
423 void
424 GameListPopUp(fp, filename)
425      FILE *fp;
426      char *filename;
427 {
428     Arg args[16];
429     int j;
430     char **st;
431
432     if (glc == NULL) {
433         glc = (GameListClosure *) calloc(1, sizeof(GameListClosure));
434         glc->x = glc->y = -1;
435     }
436
437     if (glc->strings != NULL) {
438         st = glc->strings;
439         while (*st) {
440             free(*st++);
441         }
442         free(glc->strings);
443     }
444
445     GameListPrepare(); // [HGM] filter: code put in separate routine
446
447     glc->fp = fp;
448
449     if (glc->filename != NULL) free(glc->filename);
450     glc->filename = StrSave(filename);
451
452
453     if (glc->shell == NULL) {
454         glc->shell = GameListCreate(filename, GameListCallback, glc);
455     } else {
456         GameListReplace(); // [HGM] filter: code put in separate routine
457         j = 0;
458         XtSetArg(args[j], XtNiconName, (XtArgVal) filename);  j++;
459         XtSetArg(args[j], XtNtitle, (XtArgVal) filename);  j++;
460         XtSetValues(glc->shell, args, j);
461     }
462
463     XtPopup(glc->shell, XtGrabNone);
464     glc->up = True;
465     j = 0;
466     XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
467     XtSetValues(XtNameToWidget(menuBarWidget, "menuView.Show Game List"),
468                 args, j);
469 }
470
471 void
472 GameListDestroy()
473 {
474     if (glc == NULL) return;
475     GameListPopDown();
476     if (glc->strings != NULL) {
477         char **st;
478         st = glc->strings;
479         while (*st) {
480             free(*st++);
481         }
482         free(glc->strings);
483     }
484     free(glc);
485     glc = NULL;
486 }
487
488 void
489 ShowGameListProc(w, event, prms, nprms)
490      Widget w;
491      XEvent *event;
492      String *prms;
493      Cardinal *nprms;
494 {
495     Arg args[16];
496     int j;
497
498     if (glc == NULL) {
499         DisplayError(_("There is no game list"), 0);
500         return;
501     }
502     if (glc->up) {
503         GameListPopDown();
504         return;
505     }
506     XtPopup(glc->shell, XtGrabNone);
507     glc->up = True;
508     j = 0;
509     XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
510     XtSetValues(XtNameToWidget(menuBarWidget, "menuView.Show Game List"),
511                 args, j);
512     GameListHighlight(lastLoadGameNumber);
513 }
514
515 void
516 LoadSelectedProc(w, event, prms, nprms)
517      Widget w;
518      XEvent *event;
519      String *prms;
520      Cardinal *nprms;
521 {
522     Widget listwidg;
523     XawListReturnStruct *rs;
524     int index, direction = atoi(prms[0]);
525
526     if (glc == NULL) return;
527     listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
528     rs = XawListShowCurrent(listwidg);
529     index = rs->list_index;
530     if (index < 0) return;
531     if(direction != 0) {
532         index += direction;
533         if(direction == -2) index = 0;
534         if(direction == 2) index = listLength-1;
535         if(index < 0 || index >= listLength) return;
536         XawListHighlight(listwidg, index);
537         return;
538     }
539     index = atoi(glc->strings[index])-1; // [HGM] filter: read true index from sequence nr of line
540     if (cmailMsgLoaded) {
541         CmailLoadGame(glc->fp, index + 1, glc->filename, True);
542     } else {
543         LoadGame(glc->fp, index + 1, glc->filename, True);
544     }
545 }
546
547 void
548 SetFilterProc(w, event, prms, nprms)
549      Widget w;
550      XEvent *event;
551      String *prms;
552      Cardinal *nprms;
553 {
554         Arg args[16];
555         String name;
556         Widget list;
557         int j = 0;
558         XtSetArg(args[j], XtNstring, &name);  j++;
559         XtGetValues(filterText, args, j);
560         safeStrCpy(filterString, name, sizeof(filterString)/sizeof(filterString[0]));
561         if(GameListPrepare()) GameListReplace(); // crashes on empty list...
562         list = XtNameToWidget(glc->shell, "*form.viewport.list");
563         XawListHighlight(list, 0);
564         j = 0;
565         XtSetArg(args[j], XtNdisplayCaret, False); j++;
566         XtSetValues(filterText, args, j);
567         XtSetKeyboardFocus(glc->shell, list);
568 }
569
570 void
571 GameListPopDown()
572 {
573     Arg args[16];
574     int j;
575
576     if (glc == NULL) return;
577     j = 0;
578     XtSetArg(args[j], XtNx, &glc->x); j++;
579     XtSetArg(args[j], XtNy, &glc->y); j++;
580     XtSetArg(args[j], XtNheight, &glc->h); j++;
581     XtSetArg(args[j], XtNwidth, &glc->w); j++;
582     XtGetValues(glc->shell, args, j);
583     wpGameList.x = glc->x - 4;
584     wpGameList.y = glc->y - 23;
585     wpGameList.width = glc->w;
586     wpGameList.height = glc->h;
587     XtPopdown(glc->shell);
588     XtSetKeyboardFocus(shellWidget, formWidget);
589     glc->up = False;
590     j = 0;
591     XtSetArg(args[j], XtNleftBitmap, None); j++;
592     XtSetValues(XtNameToWidget(menuBarWidget, "menuView.Show Game List"),
593                 args, j);
594 }
595
596 void
597 GameListHighlight(index)
598      int index;
599 {
600     Widget listwidg;
601     int i=0; char **st;
602     if (glc == NULL || !glc->up) return;
603     listwidg = XtNameToWidget(glc->shell, "*form.viewport.list");
604     st = glc->strings;
605     while(*st && atoi(*st)<index) st++,i++;
606     XawListHighlight(listwidg, i);
607 }
608
609 Boolean
610 GameListIsUp()
611 {
612     return glc && glc->up;
613 }
614
615 int SaveGameListAsText(FILE *f)\r
616 {\r
617     ListGame * lg = (ListGame *) gameList.head;\r
618     int nItem;\r
619 \r
620     if( !glc || ((ListGame *) gameList.tailPred)->number <= 0 ) {\r
621         DisplayError("Game list not loaded or empty", 0);\r
622         return False;\r
623     }\r
624 \r
625     /* Copy the list into the global memory block */\r
626     if( f != NULL ) {\r
627  
628         lg = (ListGame *) gameList.head;\r
629 \r
630         for (nItem = 0; nItem < ((ListGame *) gameList.tailPred)->number; nItem++){\r
631             char * st = GameListLineFull(lg->number, &lg->gameInfo);\r
632             char *line = GameListLine(lg->number, &lg->gameInfo);
633             if(filterString[0] == NULLCHAR || SearchPattern( line, filterString ) )
634                     fprintf( f, "%s\n", st );
635             free(st); free(line);\r
636             lg = (ListGame *) lg->node.succ;\r
637         }\r
638 \r
639         fclose(f);
640         return True;\r
641     }
642     return False;\r
643 }\r
644 //--------------------------------- Game-List options dialog ------------------------------------------
645
646 Widget gameListOptShell, listwidg;
647
648 char *strings[20];
649 int stringPtr;
650
651 void GLT_ClearList()
652 {
653     strings[0] = NULL;
654     stringPtr = 0;
655 }
656
657 void GLT_AddToList(char *name)
658 {
659     strings[stringPtr++] = name;
660     strings[stringPtr] = NULL;
661 }
662
663 Boolean GLT_GetFromList(int index, char *name)
664 {
665   safeStrCpy(name, strings[index], MSG_SIZ);
666   return TRUE;
667 }
668
669 void GLT_DeSelectList()
670 {
671     XawListChange(listwidg, strings, 0, 0, True);
672     XawListHighlight(listwidg, 0);
673 }
674
675 void
676 GameListOptionsPopDown()
677 {
678   if (gameListOptShell == NULL) return;
679
680   XtPopdown(gameListOptShell);
681   XtDestroyWidget(gameListOptShell);
682   gameListOptShell = 0;
683   XtSetKeyboardFocus(shellWidget, formWidget);
684 }
685
686 void
687 GameListOptionsCallback(w, client_data, call_data)
688      Widget w;
689      XtPointer client_data, call_data;
690 {
691     String name;
692     Arg args[16];
693     int j;
694     Widget listwidg;
695     XawListReturnStruct *rs;
696     int index;
697     char *p;
698
699     j = 0;
700     XtSetArg(args[j], XtNlabel, &name);  j++;
701     XtGetValues(w, args, j);
702
703     if (strcmp(name, _("OK")) == 0) {
704         GLT_ParseList();
705         appData.gameListTags = strdup(lpUserGLT);
706         GameListOptionsPopDown();
707         return;
708     } else
709     if (strcmp(name, _("cancel")) == 0) {
710         GameListOptionsPopDown();
711         return;
712     }
713     listwidg = XtNameToWidget(gameListOptShell, "*form.list");
714     rs = XawListShowCurrent(listwidg);
715     index = rs->list_index;
716     if (index < 0) {
717         DisplayError(_("No tag selected"), 0);
718         return;
719     }
720     p = strings[index];
721     if (strcmp(name, _("down")) == 0) {
722         if(index >= strlen(GLT_ALL_TAGS)) return;
723         strings[index] = strings[index+1];
724         strings[++index] = p;
725     } else
726     if (strcmp(name, _("up")) == 0) {
727         if(index == 0) return;
728         strings[index] = strings[index-1];
729         strings[--index] = p;
730     } else
731     if (strcmp(name, _("factory")) == 0) {
732       safeStrCpy(lpUserGLT, GLT_DEFAULT_TAGS, LPUSERGLT_SIZE);
733       GLT_TagsToList(lpUserGLT);
734       index = 0;
735     }
736     XawListHighlight(listwidg, index);
737 }
738
739 Widget
740 GameListOptionsCreate()
741 {
742     Arg args[16];
743     Widget shell, form, viewport, layout;
744     Widget b_load, b_loadprev, b_loadnext, b_close, b_cancel;
745     Dimension fw_width;
746     XtPointer client_data = NULL;
747     int j;
748
749     j = 0;
750     XtSetArg(args[j], XtNwidth, &fw_width);  j++;
751     XtGetValues(formWidget, args, j);
752
753     j = 0;
754     XtSetArg(args[j], XtNresizable, True);  j++;
755     XtSetArg(args[j], XtNallowShellResize, True);  j++;
756     shell = gameListOptShell =
757       XtCreatePopupShell("Game-list options", transientShellWidgetClass,
758                          shellWidget, args, j);
759     layout =
760       XtCreateManagedWidget(layoutName, formWidgetClass, shell,
761                             layoutArgs, XtNumber(layoutArgs));
762     j = 0;
763     XtSetArg(args[j], XtNborderWidth, 0); j++;
764     form =
765       XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
766
767     j = 0;
768     XtSetArg(args[j], XtNdefaultColumns, 1);  j++;
769     XtSetArg(args[j], XtNforceColumns, True);  j++;
770     XtSetArg(args[j], XtNverticalList, True);  j++;
771     listwidg = viewport =
772       XtCreateManagedWidget("list", listWidgetClass, form, args, j);
773     XawListHighlight(listwidg, 0);
774 //    XtAugmentTranslations(listwidg,
775 //                        XtParseTranslationTable(gameListOptTranslations));
776
777     j = 0;
778     XtSetArg(args[j], XtNfromVert, viewport);  j++;
779     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
780     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
781     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
782     XtSetArg(args[j], XtNright, XtChainLeft); j++;
783     b_load =
784       XtCreateManagedWidget(_("factory"), commandWidgetClass, form, args, j);
785     XtAddCallback(b_load, XtNcallback, GameListOptionsCallback, client_data);
786
787     j = 0;
788     XtSetArg(args[j], XtNfromVert, viewport);  j++;
789     XtSetArg(args[j], XtNfromHoriz, b_load);  j++;
790     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
791     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
792     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
793     XtSetArg(args[j], XtNright, XtChainLeft); j++;
794     b_loadprev =
795       XtCreateManagedWidget(_("up"), commandWidgetClass, form, args, j);
796     XtAddCallback(b_loadprev, XtNcallback, GameListOptionsCallback, client_data);
797
798     j = 0;
799     XtSetArg(args[j], XtNfromVert, viewport);  j++;
800     XtSetArg(args[j], XtNfromHoriz, b_loadprev);  j++;
801     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
802     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
803     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
804     XtSetArg(args[j], XtNright, XtChainLeft); j++;
805     b_loadnext =
806       XtCreateManagedWidget(_("down"), commandWidgetClass, form, args, j);
807     XtAddCallback(b_loadnext, XtNcallback, GameListOptionsCallback, client_data);
808
809     j = 0;
810     XtSetArg(args[j], XtNfromVert, viewport);  j++;
811     XtSetArg(args[j], XtNfromHoriz, b_loadnext);  j++;
812     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
813     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
814     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
815     XtSetArg(args[j], XtNright, XtChainLeft); j++;
816     b_cancel =
817       XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
818     XtAddCallback(b_cancel, XtNcallback, GameListOptionsCallback, client_data);
819
820     j = 0;
821     XtSetArg(args[j], XtNfromVert, viewport);  j++;
822     XtSetArg(args[j], XtNfromHoriz, b_cancel);  j++;
823     XtSetArg(args[j], XtNtop, XtChainBottom); j++;
824     XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
825     XtSetArg(args[j], XtNleft, XtChainLeft); j++;
826     XtSetArg(args[j], XtNright, XtChainLeft); j++;
827     b_close =
828       XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
829     XtAddCallback(b_close, XtNcallback, GameListOptionsCallback, client_data);
830
831     safeStrCpy(lpUserGLT, appData.gameListTags, LPUSERGLT_SIZE);
832     GLT_TagsToList(lpUserGLT);
833
834     XtRealizeWidget(shell);
835     CatchDeleteWindow(shell, "GameListOptionsPopDown");
836
837     return shell;
838 }
839
840 void
841 GameListOptionsPopUp(Widget w, XEvent *event, String *prms, Cardinal *nprms)
842 {
843   if (gameListOptShell == NULL)
844     gameListOptShell = GameListOptionsCreate();
845
846   XtPopup(gameListOptShell, XtGrabNone);
847 }
848
849