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