Redo common-engine dialog with generic popup
[xboard.git] / xoptions.c
1 /*
2  * xoptions.c -- Move list window, part of X front end for XBoard
3  *
4  * Copyright 2000, 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 // [HGM] this file is the counterpart of woptions.c, containing xboard popup menus
24 // similar to those of WinBoard, to set the most common options interactively.
25
26 #include "config.h"
27
28 #include <stdio.h>
29 #include <ctype.h>
30 #include <errno.h>
31 #include <sys/types.h>
32
33 #if STDC_HEADERS
34 # include <stdlib.h>
35 # include <string.h>
36 #else /* not STDC_HEADERS */
37 extern char *getenv();
38 # if HAVE_STRING_H
39 #  include <string.h>
40 # else /* not HAVE_STRING_H */
41 #  include <strings.h>
42 # endif /* not HAVE_STRING_H */
43 #endif /* not STDC_HEADERS */
44
45 #if HAVE_UNISTD_H
46 # include <unistd.h>
47 #endif
48 #include <stdint.h>
49
50 #include <X11/Intrinsic.h>
51 #include <X11/StringDefs.h>
52 #include <X11/Shell.h>
53 #include <X11/Xaw/Dialog.h>
54 #include <X11/Xaw/Form.h>
55 #include <X11/Xaw/List.h>
56 #include <X11/Xaw/Label.h>
57 #include <X11/Xaw/SimpleMenu.h>
58 #include <X11/Xaw/SmeBSB.h>
59 #include <X11/Xaw/SmeLine.h>
60 #include <X11/Xaw/Box.h>
61 #include <X11/Xaw/Paned.h>
62 #include <X11/Xaw/MenuButton.h>
63 #include <X11/cursorfont.h>
64 #include <X11/Xaw/Text.h>
65 #include <X11/Xaw/AsciiText.h>
66 #include <X11/Xaw/Viewport.h>
67 #include <X11/Xaw/Toggle.h>
68
69 #include "common.h"
70 #include "backend.h"
71 #include "xboard.h"
72 #include "gettext.h"
73
74 #ifdef ENABLE_NLS
75 # define  _(s) gettext (s)
76 # define N_(s) gettext_noop (s)
77 #else
78 # define  _(s) (s)
79 # define N_(s)  s
80 #endif
81
82 extern void SendToProgram P((char *message, ChessProgramState *cps));
83 FILE * XsraSelFile P((Widget w, char *prompt, char *ok, char *cancel, char *failed,
84                 char *init_path, char *mode, int (*show_entry)(), char **name_return));
85
86 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
87 extern Display *xDisplay;
88 extern int squareSize;
89 extern Pixmap xMarkPixmap;
90 extern char *layoutName;
91 extern Window xBoardWindow;
92 extern Arg layoutArgs[2], formArgs[2];
93 Pixel timerForegroundPixel, timerBackgroundPixel;
94 extern int searchTime;
95 extern int lineGap;
96
97 // [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines
98
99 static Widget previous = NULL;
100
101 void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
102 {
103     Arg args[2];
104     char *s;
105
106     if(previous) {
107         XtSetArg(args[0], XtNdisplayCaret, False);
108         XtSetValues(previous, args, 1);
109     }
110     XtSetArg(args[0], XtNstring, &s);
111     XtGetValues(w, args, 1);
112     XtSetArg(args[0], XtNdisplayCaret, True);
113     XtSetArg(args[1], XtNinsertPosition, strlen(s));
114     XtSetValues(w, args, 2);
115     XtSetKeyboardFocus((Widget) data, w);
116     previous = w;
117 }
118
119 //--------------------------- New Shuffle Game --------------------------------------------
120 extern int shuffleOpenings;
121 extern int startedFromPositionFile;
122 int shuffleUp;
123 Widget shuffleShell;
124
125 void ShufflePopDown()
126 {
127     if (!shuffleUp) return;
128     XtPopdown(shuffleShell);
129     XtDestroyWidget(shuffleShell);
130     shuffleUp = False;
131     ModeHighlight();
132 }
133
134 void ShuffleCallback(w, client_data, call_data)
135      Widget w;
136      XtPointer client_data, call_data;
137 {
138     String name;
139     Widget w2;
140     Arg args[16];
141     char buf[MSG_SIZ];
142
143     XtSetArg(args[0], XtNlabel, &name);
144     XtGetValues(w, args, 1);
145
146     if (strcmp(name, _("cancel")) == 0) {
147         ShufflePopDown();
148         return;
149     }
150     if (strcmp(name, _("off")) == 0) {
151         ShufflePopDown();
152         shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it!
153         ResetGameEvent();
154         return;
155     }
156     if (strcmp(name, _("random")) == 0) {
157       snprintf(buf, MSG_SIZ,  "%d", rand());
158         XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
159         XtSetValues(XtParent(w), args, 1);
160         return;
161     }
162     if (strcmp(name, _("ok")) == 0) {
163         int nr; String name;
164         name = XawDialogGetValueString(w2 = XtParent(w));
165         if(sscanf(name ,"%d",&nr) != 1) {
166           snprintf(buf, MSG_SIZ,  "%d", appData.defaultFrcPosition);
167             XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
168             XtSetValues(w2, args, 1);
169             return;
170         }
171         appData.defaultFrcPosition = nr;
172         shuffleOpenings = True;
173         ShufflePopDown();
174         ResetGameEvent();
175         return;
176     }
177 }
178
179 void ShufflePopUp()
180 {
181     Arg args[16];
182     Widget popup, layout, dialog, edit;
183     Window root, child;
184     int x, y, i;
185     int win_x, win_y;
186     unsigned int mask;
187     char def[MSG_SIZ];
188
189     i = 0;
190     XtSetArg(args[i], XtNresizable, True); i++;
191     XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
192     shuffleShell = popup =
193       XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass,
194                          shellWidget, args, i);
195
196     layout =
197       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
198                             layoutArgs, XtNumber(layoutArgs));
199
200     snprintf(def, MSG_SIZ,  "%d\n", appData.defaultFrcPosition);
201     i = 0;
202     XtSetArg(args[i], XtNlabel, _("Start-position number:")); i++;
203     XtSetArg(args[i], XtNvalue, def); i++;
204     XtSetArg(args[i], XtNborderWidth, 0); i++;
205     dialog = XtCreateManagedWidget(_("Shuffle"), dialogWidgetClass,
206                                    layout, args, i);
207
208 //    XtSetArg(args[0], XtNeditType, XawtextEdit);  // [HGM] can't get edit to work decently
209 //    XtSetArg(args[1], XtNuseStringInPlace, False);
210 //    XtSetValues(dialog, args, 2);
211
212     XawDialogAddButton(dialog, _("ok"), ShuffleCallback, (XtPointer) dialog);
213     XawDialogAddButton(dialog, _("cancel"), ShuffleCallback, (XtPointer) dialog);
214     XawDialogAddButton(dialog, _("random"), ShuffleCallback, (XtPointer) dialog);
215     XawDialogAddButton(dialog, _("off"), ShuffleCallback, (XtPointer) dialog);
216
217     XtRealizeWidget(popup);
218     CatchDeleteWindow(popup, "ShufflePopDown");
219
220     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
221                   &x, &y, &win_x, &win_y, &mask);
222
223     XtSetArg(args[0], XtNx, x - 10);
224     XtSetArg(args[1], XtNy, y - 30);
225     XtSetValues(popup, args, 2);
226
227     XtPopup(popup, XtGrabExclusive);
228     shuffleUp = True;
229
230     edit = XtNameToWidget(dialog, "*value");
231
232     XtSetKeyboardFocus(popup, edit);
233 }
234
235 void ShuffleMenuProc(w, event, prms, nprms)
236      Widget w;
237      XEvent *event;
238      String *prms;
239      Cardinal *nprms;
240 {
241 //    if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
242 //      Reset(FALSE, TRUE);
243 //    }
244     ShufflePopUp();
245 }
246
247 //--------------------------- Time-Control Menu Popup ----------------------------------
248 int TimeControlUp;
249 Widget TimeControlShell;
250 int tcInc;
251 Widget tcMess1, tcMess2, tcData, tcTime, tcOdds1, tcOdds2;
252 int tcIncrement, tcMoves;
253
254 void TimeControlPopDown()
255 {
256     if (!TimeControlUp) return;
257     previous = NULL;
258     XtPopdown(TimeControlShell);
259     XtDestroyWidget(TimeControlShell);
260     TimeControlUp = False;
261     ModeHighlight();
262 }
263
264 void TimeControlCallback(w, client_data, call_data)
265      Widget w;
266      XtPointer client_data, call_data;
267 {
268     String name, txt;
269     Arg args[16];
270     char buf[MSG_SIZ];
271     int j;
272
273     XtSetArg(args[0], XtNlabel, &name);
274     XtGetValues(w, args, 1);
275
276     if (strcmp(name, _("classical")) == 0) {
277         if(tcInc == 0) return;
278         j=0;
279         XtSetArg(args[j], XtNlabel, _("minutes for each")); j++;
280         XtSetValues(tcMess1, args, j);
281         j=0;
282         XtSetArg(args[j], XtNlabel, _("moves")); j++;
283         XtSetValues(tcMess2, args, j);
284         if(tcInc == 1) {
285             j=0;
286             XtSetArg(args[j], XtNstring, &name); j++;
287             XtGetValues(tcData, args, j);
288             tcIncrement = 0; sscanf(name, "%d", &tcIncrement);
289         }
290         snprintf(buf, MSG_SIZ,  "%d", tcMoves);
291         j=0;
292         XtSetArg(args[j], XtNstring, buf); j++;
293         XtSetValues(tcData, args, j);
294         tcInc = 0;
295         return;
296     }
297     if (strcmp(name, _("incremental")) == 0) {
298         if(tcInc == 1) return;
299         j=0;
300         XtSetArg(args[j], XtNlabel, _("minutes, plus")); j++;
301         XtSetValues(tcMess1, args, j);
302         j=0;
303         XtSetArg(args[j], XtNlabel, _("sec/move")); j++;
304         XtSetValues(tcMess2, args, j);
305         if(tcInc == 0) {
306             j=0;
307             XtSetArg(args[j], XtNstring, &name); j++;
308             XtGetValues(tcData, args, j);
309             tcMoves = appData.movesPerSession; sscanf(name, "%d", &tcMoves);
310         }
311         snprintf(buf, MSG_SIZ,  "%d", tcIncrement);
312         j=0;
313         XtSetArg(args[j], XtNstring, buf); j++;
314         XtSetValues(tcData, args, j);
315         tcInc = 1;
316         return;
317     }
318     if (strcmp(name, _("fixed time")) == 0) {
319         if(tcInc == 2) return;
320         j=0;
321         XtSetArg(args[j], XtNlabel, _("sec/move (max)")); j++;
322         XtSetValues(tcMess1, args, j);
323         j=0;
324         XtSetArg(args[j], XtNlabel, _("")); j++;
325         XtSetValues(tcMess2, args, j);
326         j=0;
327         XtSetArg(args[j], XtNstring, ""); j++;
328         XtSetValues(tcData, args, j);
329         tcInc = 2;
330         return;
331     }
332     if (strcmp(name, _(" OK ")) == 0) {
333         int inc, mps, ok;
334         XtSetArg(args[0], XtNstring, &txt);
335         XtGetValues(tcData, args, 1);
336         switch(tcInc) {
337           case 1:
338             ok = sscanf(txt, "%d", &inc); mps = 0;
339             if(!ok && txt[0] == 0) { inc = 0; ok = 1; } // accept empty string as zero
340             ok &= (inc >= 0);
341             break;
342           case 0:
343             ok = sscanf(txt, "%d", &mps); inc = -1;
344             ok &= (mps > 0);
345             break;
346           case 2:
347             ok = 1; inc = -1; mps = 40;
348         }
349         if(ok != 1) {
350             XtSetArg(args[0], XtNstring, ""); // erase any offending input
351             XtSetValues(tcData, args, 1);
352             return;
353         }
354         XtSetArg(args[0], XtNstring, &txt);
355         XtGetValues(tcTime, args, 1);
356         if(tcInc == 2) {
357             if(sscanf(txt, "%d", &inc) != 1) {
358                 XtSetArg(args[0], XtNstring, ""); // erase any offending input
359                 XtSetValues(tcTime, args, 1);
360                 DisplayError(_("Bad Time-Control String"), 0);
361                 return;
362             }
363             searchTime = inc;
364         } else {
365             if(!ParseTimeControl(txt, inc, mps)) {
366                 XtSetArg(args[0], XtNstring, ""); // erase any offending input
367                 XtSetValues(tcTime, args, 1);
368                 DisplayError(_("Bad Time-Control String"), 0);
369                 return;
370             }
371             searchTime = 0;
372             appData.movesPerSession = mps;
373             appData.timeIncrement = inc;
374             appData.timeControl = strdup(txt);
375         }
376         XtSetArg(args[0], XtNstring, &txt);
377         XtGetValues(tcOdds1, args, 1);
378         appData.firstTimeOdds = first.timeOdds
379                 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
380         XtGetValues(tcOdds2, args, 1);
381         appData.secondTimeOdds = second.timeOdds
382                 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
383
384         Reset(True, True);
385         TimeControlPopDown();
386         return;
387     }
388 }
389
390 void TimeControlPopUp()
391 {
392     Arg args[16];
393     Widget popup, layout, form,  b_ok, b_cancel, b_clas, b_inc, mess;
394     Window root, child;
395     int x, y, i, j;
396     int win_x, win_y;
397     unsigned int mask;
398     char def[MSG_SIZ];
399
400     tcInc = searchTime > 0 ? 2 : (appData.timeIncrement >= 0);
401     tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
402     if(!tcInc) tcIncrement = 0;
403     snprintf(def, MSG_SIZ,  "%d", tcInc ? tcIncrement : tcMoves);
404
405     i = 0;
406     XtSetArg(args[i], XtNresizable, True); i++;
407 //    XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
408     TimeControlShell = popup =
409       XtCreatePopupShell(_("TimeControl Menu"), transientShellWidgetClass,
410                          shellWidget, args, i);
411
412     layout =
413       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
414                             layoutArgs, XtNumber(layoutArgs));
415
416     form =
417       XtCreateManagedWidget(layoutName, formWidgetClass, layout,
418                             formArgs, XtNumber(formArgs));
419
420     j = 0;
421 //    XtSetArg(args[j], XtNwidth,     (XtArgVal) 300); j++;
422 //    XtSetArg(args[j], XtNheight,    (XtArgVal) 85); j++;
423     XtSetValues(popup, args, j);
424
425     j= 0;
426     XtSetArg(args[j], XtNborderWidth, 1); j++;
427     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
428     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
429     XtSetArg(args[j], XtNstring, appData.timeControl);  j++;
430     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
431     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
432     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
433     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
434     XtSetArg(args[j], XtNright, XtChainRight);  j++;
435     XtSetArg(args[j], XtNresizable, True);  j++;
436     XtSetArg(args[j], XtNwidth,  85);  j++;
437     XtSetArg(args[j], XtNinsertPosition, 9999);  j++;
438     tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j);
439     XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup);
440
441     j= 0;
442     XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _("sec/move (max)   ") : _("   minutes, plus   ") : _("minutes for each")); j++;
443     XtSetArg(args[j], XtNborderWidth, 0); j++;
444     XtSetArg(args[j], XtNfromHoriz, tcTime); j++;
445     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
446     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
447     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
448     XtSetArg(args[j], XtNright, XtChainRight);  j++;
449   //  XtSetArg(args[j], XtNwidth,  100);  j++;
450   //  XtSetArg(args[j], XtNheight, 20);  j++;
451     tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
452
453     j= 0;
454     XtSetArg(args[j], XtNborderWidth, 1); j++;
455     XtSetArg(args[j], XtNfromHoriz, tcMess1); j++;
456     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
457     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
458     XtSetArg(args[j], XtNstring, def);  j++;
459     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
460     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
461     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
462     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
463     XtSetArg(args[j], XtNright, XtChainRight);  j++;
464     XtSetArg(args[j], XtNresizable, True);  j++;
465     XtSetArg(args[j], XtNwidth,  40);  j++;
466 //    XtSetArg(args[j], XtNheight, 20);  j++;
467     tcData = XtCreateManagedWidget("MPS", asciiTextWidgetClass, form, args, j);
468     XtAddEventHandler(tcData, ButtonPressMask, False, SetFocus, (XtPointer) popup);
469
470     j= 0;
471     XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _("             ") : _("sec/move") : _("moves     ")); j++;
472     XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
473     XtSetArg(args[j], XtNborderWidth, 0); j++;
474     XtSetArg(args[j], XtNfromHoriz, tcData); j++;
475     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
476     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
477     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
478     XtSetArg(args[j], XtNright, XtChainRight);  j++;
479 //    XtSetArg(args[j], XtNwidth,  80);  j++;
480 //    XtSetArg(args[j], XtNheight, 20);  j++;
481     tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass,
482                                    form, args, j);
483
484     j= 0;
485     XtSetArg(args[j], XtNborderWidth, 1); j++;
486     XtSetArg(args[j], XtNfromVert, tcTime); j++;
487     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
488     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
489     XtSetArg(args[j], XtNstring, "1");  j++;
490     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
491     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
492     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
493     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
494     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
495     XtSetArg(args[j], XtNresizable, True);  j++;
496     XtSetArg(args[j], XtNwidth,  40);  j++;
497 //    XtSetArg(args[j], XtNheight, 20);  j++;
498     tcOdds1 = XtCreateManagedWidget("Odds1", asciiTextWidgetClass, form, args, j);
499     XtAddEventHandler(tcOdds1, ButtonPressMask, False, SetFocus, (XtPointer) popup);
500
501     j= 0;
502     XtSetArg(args[j], XtNborderWidth, 1); j++;
503     XtSetArg(args[j], XtNfromVert, tcTime); j++;
504     XtSetArg(args[j], XtNfromHoriz, tcOdds1); j++;
505     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
506     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
507     XtSetArg(args[j], XtNstring, "1");  j++;
508     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
509     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
510     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
511     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
512     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
513     XtSetArg(args[j], XtNresizable, True);  j++;
514     XtSetArg(args[j], XtNwidth,  40);  j++;
515 //    XtSetArg(args[j], XtNheight, 20);  j++;
516     tcOdds2 = XtCreateManagedWidget("Odds2", asciiTextWidgetClass, form, args, j);
517     XtAddEventHandler(tcOdds2, ButtonPressMask, False, SetFocus, (XtPointer) popup);
518
519     j= 0;
520     XtSetArg(args[j], XtNlabel, _("Engine #1 and #2 Time-Odds Factors")); j++;
521     XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
522     XtSetArg(args[j], XtNborderWidth, 0); j++;
523     XtSetArg(args[j], XtNfromVert, tcTime); j++;
524     XtSetArg(args[j], XtNfromHoriz, tcOdds2); j++;
525     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
526     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
527     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
528     XtSetArg(args[j], XtNright, XtChainRight);  j++;
529 //    XtSetArg(args[j], XtNwidth,  200);  j++;
530 //    XtSetArg(args[j], XtNheight, 20);  j++;
531     mess = XtCreateManagedWidget("Oddstext", labelWidgetClass,
532                                    form, args, j);
533     j=0;
534     XtSetArg(args[j], XtNfromVert, tcOdds1);  j++;
535     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
536     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
537     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
538     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
539     XtSetArg(args[j], XtNstate, tcInc==0); j++;
540     b_clas= XtCreateManagedWidget(_("classical"), toggleWidgetClass,
541                                    form, args, j);
542     XtAddCallback(b_clas, XtNcallback, TimeControlCallback, (XtPointer) 0);
543
544     j=0;
545     XtSetArg(args[j], XtNradioGroup, b_clas); j++;
546     XtSetArg(args[j], XtNfromVert, tcOdds1);  j++;
547     XtSetArg(args[j], XtNfromHoriz, b_clas);  j++;
548     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
549     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
550     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
551     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
552     XtSetArg(args[j], XtNstate, tcInc==1); j++;
553     b_inc = XtCreateManagedWidget(_("incremental"), toggleWidgetClass,
554                                    form, args, j);
555     XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
556
557     j=0;
558     XtSetArg(args[j], XtNradioGroup, b_inc); j++;
559     XtSetArg(args[j], XtNfromVert, tcOdds1);  j++;
560     XtSetArg(args[j], XtNfromHoriz, b_inc);  j++;
561     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
562     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
563     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
564     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
565     XtSetArg(args[j], XtNstate, tcInc==2); j++;
566     b_inc = XtCreateManagedWidget(_("fixed time"), toggleWidgetClass,
567                                    form, args, j);
568     XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
569
570     j=0;
571     XtSetArg(args[j], XtNfromVert, tcOdds1);  j++;
572     XtSetArg(args[j], XtNfromHoriz, tcData);  j++;
573     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
574     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
575     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
576     XtSetArg(args[j], XtNright, XtChainRight);  j++;
577     b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass,
578                                    form, args, j);
579     XtAddCallback(b_ok, XtNcallback, TimeControlCallback, (XtPointer) 0);
580
581     j=0;
582     XtSetArg(args[j], XtNfromVert, tcOdds1);  j++;
583     XtSetArg(args[j], XtNfromHoriz, b_ok);  j++;
584     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
585     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
586     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
587     XtSetArg(args[j], XtNright, XtChainRight);  j++;
588     b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
589                                    form, args, j);
590     XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0);
591
592     XtRealizeWidget(popup);
593     CatchDeleteWindow(popup, "TimeControlPopDown");
594
595     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
596                   &x, &y, &win_x, &win_y, &mask);
597
598     XtSetArg(args[0], XtNx, x - 10);
599     XtSetArg(args[1], XtNy, y - 30);
600     XtSetValues(popup, args, 2);
601
602     XtPopup(popup, XtGrabExclusive);
603     TimeControlUp = True;
604
605     previous = NULL;
606     SetFocus(tcTime, popup, (XEvent*) NULL, False);
607 //    XtSetKeyboardFocus(popup, tcTime);
608 }
609
610 void TimeControlProc(w, event, prms, nprms)
611      Widget w;
612      XEvent *event;
613      String *prms;
614      Cardinal *nprms;
615 {
616    TimeControlPopUp();
617 }
618
619 Widget w1, w2, w3, w4, w5, w6, w7, w8;
620
621 //--------------------------- New-Variant Menu PopUp -----------------------------------
622 struct NewVarButton {
623   char   *name;
624   char *color;
625   Widget handle;
626   VariantClass variant;
627 };
628
629 struct NewVarButton buttonDesc[] = {
630     {N_("normal"),            "#FFFFFF", 0, VariantNormal},
631     {N_("FRC"),               "#FFFFFF", 0, VariantFischeRandom},
632     {N_("wild castle"),       "#FFFFFF", 0, VariantWildCastle},
633     {N_("no castle"),         "#FFFFFF", 0, VariantNoCastle},
634     {N_("knightmate"),        "#FFFFFF", 0, VariantKnightmate},
635     {N_("berolina"),          "#FFFFFF", 0, VariantBerolina},
636     {N_("cylinder"),          "#FFFFFF", 0, VariantCylinder},
637     {N_("shatranj"),          "#FFFFFF", 0, VariantShatranj},
638     {N_("makruk"),            "#FFFFFF", 0, VariantMakruk},
639     {N_("atomic"),            "#FFFFFF", 0, VariantAtomic},
640     {N_("two kings"),         "#FFFFFF", 0, VariantTwoKings},
641     {N_("3-checks"),          "#FFFFFF", 0, Variant3Check},
642     {N_("suicide"),           "#FFFFBF", 0, VariantSuicide},
643     {N_("give-away"),         "#FFFFBF", 0, VariantGiveaway},
644     {N_("losers"),            "#FFFFBF", 0, VariantLosers},
645     {N_("fairy"),             "#BFBFBF", 0, VariantFairy},
646     {N_("Seirawan"),          "#FFBFBF", 0, VariantSChess},
647     {N_("Superchess"),        "#FFBFBF", 0, VariantSuper},
648     {N_("crazyhouse"),        "#FFBFBF", 0, VariantCrazyhouse},
649     {N_("bughouse"),          "#FFBFBF", 0, VariantBughouse},
650     {N_("shogi (9x9)"),       "#BFFFFF", 0, VariantShogi},
651     {N_("xiangqi (9x10)"),    "#BFFFFF", 0, VariantXiangqi},
652     {N_("courier (12x8)"),    "#BFFFBF", 0, VariantCourier},
653     {N_("Capablanca (10x8)"), "#BFBFFF", 0, VariantCapablanca},
654 #ifdef GOTHIC
655     {N_("Gothic (10x8)"),     "#BFBFFF", 0, VariantGothic},
656 #endif
657     {N_("janus (10x8)"),      "#BFBFFF", 0, VariantJanus},
658     {N_("CRC (10x8)"),        "#BFBFFF", 0, VariantCapaRandom},
659 #ifdef FALCON
660     {N_("Falcon (10x8)"),     "#BFBFFF", 0, VariantFalcon},
661 #endif
662     {N_("Spartan"),           "#FF0000", 0, VariantSpartan},
663     {NULL,                0, 0, (VariantClass) 0}
664 };
665
666 int NewVariantUp;
667 Widget NewVariantShell;
668
669 void NewVariantPopDown()
670 {
671     if (!NewVariantUp) return;
672     XtPopdown(NewVariantShell);
673     XtDestroyWidget(NewVariantShell);
674     NewVariantUp = False;
675     ModeHighlight();
676 }
677
678 void NewVariantCallback(w, client_data, call_data)
679      Widget w;
680      XtPointer client_data, call_data;
681 {
682     String name;
683     Arg args[16];
684     VariantClass v;
685
686     XtSetArg(args[0], XtNlabel, &name);
687     XtGetValues(w, args, 1);
688
689     if (strcmp(name, _("  OK  ")) == 0) {
690         int nr = (intptr_t) XawToggleGetCurrent(buttonDesc[0].handle) - 1;
691         if(nr < 0) return;
692         v = buttonDesc[nr].variant;
693         if(!appData.noChessProgram) {
694             char *name = VariantName(v), buf[MSG_SIZ];
695             if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
696                 /* [HGM] in protocol 2 we check if variant is suported by engine */
697               snprintf(buf, MSG_SIZ,  _("Variant %s not supported by %s"), name, first.tidy);
698                 DisplayError(buf, 0);
699 //              NewVariantPopDown();
700                 return; /* ignore OK if first engine does not support it */
701             } else
702             if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
703               snprintf(buf, MSG_SIZ,  _("Warning: second engine (%s) does not support this!"), second.tidy);
704                 DisplayError(buf, 0);   /* use of second engine is optional; only warn user */
705             }
706         }
707
708         gameInfo.variant = v;
709         appData.variant = VariantName(v);
710
711         shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
712         startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
713         appData.pieceToCharTable = NULL;
714         Reset(True, True);
715         NewVariantPopDown();
716         return;
717     }
718 }
719
720 void NewVariantPopUp()
721 {
722     Arg args[16];
723     Widget popup, layout, form, last = NULL, b_ok, b_cancel;
724     Window root, child;
725     int x, y, i, j;
726     int win_x, win_y;
727     unsigned int mask;
728     XrmValue vFrom, vTo;
729
730     i = 0;
731     XtSetArg(args[i], XtNresizable, True); i++;
732 //    XtSetArg(args[i], XtNwidth, 250); i++;
733 //    XtSetArg(args[i], XtNheight, 300); i++;
734     NewVariantShell = popup =
735       XtCreatePopupShell(_("NewVariant Menu"), transientShellWidgetClass,
736                          shellWidget, args, i);
737
738     layout =
739       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
740                             layoutArgs, XtNumber(layoutArgs));
741
742     form =
743       XtCreateManagedWidget("form", formWidgetClass, layout,
744                             formArgs, XtNumber(formArgs));
745
746     for(i = 0; buttonDesc[i].name != NULL; i++) {
747         Pixel buttonColor;
748         if (!appData.monoMode) {
749             vFrom.addr = (caddr_t) buttonDesc[i].color;
750             vFrom.size = strlen(buttonDesc[i].color);
751             XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
752             if (vTo.addr == NULL) {
753                 buttonColor = (Pixel) -1;
754             } else {
755                 buttonColor = *(Pixel *) vTo.addr;
756             }
757         }
758
759         j = 0;
760         XtSetArg(args[j], XtNradioGroup, last); j++;
761         XtSetArg(args[j], XtNwidth, 125); j++;
762 //      XtSetArg(args[j], XtNheight, 16); j++;
763         XtSetArg(args[j], XtNfromVert, i == 15 ? NULL : last); j++;
764         XtSetArg(args[j], XtNfromHoriz, i < 15 ? NULL : buttonDesc[i-15].handle); j++;
765         XtSetArg(args[j], XtNradioData, i+1); j++;
766         XtSetArg(args[j], XtNbackground, buttonColor); j++;
767         XtSetArg(args[j], XtNstate, gameInfo.variant == buttonDesc[i].variant); j++;
768         XtSetArg(args[j], XtNsensitive, appData.noChessProgram || strstr(first.variants, VariantName(buttonDesc[i].variant))); j++;
769         buttonDesc[i].handle = last =
770             XtCreateManagedWidget(buttonDesc[i].name, toggleWidgetClass, form, args, j);
771     }
772
773     j=0;
774     XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle);  j++;
775     XtSetArg(args[j], XtNfromHoriz, buttonDesc[12].handle);  j++;
776     XtSetArg(args[j], XtNheight, 35); j++;
777 //    XtSetArg(args[j], XtNwidth, 60); j++;
778     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
779     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
780     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
781     XtSetArg(args[j], XtNright, XtChainRight);  j++;
782     b_cancel= XtCreateManagedWidget(_("CANCEL"), commandWidgetClass, form, args, j);
783     XtAddCallback(b_cancel, XtNcallback, NewVariantPopDown, (XtPointer) 0);
784
785     j=0;
786     XtSetArg(args[j], XtNfromHoriz, b_cancel);  j++;
787     XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle);  j++;
788     XtSetArg(args[j], XtNheight, 35); j++;
789 //    XtSetArg(args[j], XtNwidth, 60); j++;
790     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
791     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
792     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
793     XtSetArg(args[j], XtNright, XtChainRight);  j++;
794     b_ok= XtCreateManagedWidget(_("  OK  "), commandWidgetClass, form, args, j);
795     XtAddCallback(b_ok, XtNcallback, NewVariantCallback, (XtPointer) 0);
796
797     j=0;
798     XtSetArg(args[j], XtNfromVert, buttonDesc[14].handle);  j++;
799 //    XtSetArg(args[j], XtNheight, 70); j++;
800     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
801     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
802     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
803     XtSetArg(args[j], XtNright, XtChainRight);  j++;
804     XtSetArg(args[j], XtNlabel, _("WARNING: variants with un-orthodox\n"
805                                   "pieces only have built-in bitmaps\n"
806                                   "for -boardSize middling, bulky and\n"
807                                   "petite, and substitute king or amazon\n"
808                                   "for missing bitmaps. (See manual.)")); j++;
809     XtCreateManagedWidget("warning", labelWidgetClass, form, args, j);
810
811             XtRealizeWidget(popup);
812     CatchDeleteWindow(popup, "NewVariantPopDown");
813
814     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
815                   &x, &y, &win_x, &win_y, &mask);
816
817     XtSetArg(args[0], XtNx, x - 10);
818     XtSetArg(args[1], XtNy, y - 30);
819     XtSetValues(popup, args, 2);
820
821     XtPopup(popup, XtGrabExclusive);
822     NewVariantUp = True;
823 }
824
825 void NewVariantProc(w, event, prms, nprms)
826      Widget w;
827      XEvent *event;
828      String *prms;
829      Cardinal *nprms;
830 {
831    NewVariantPopUp();
832 }
833
834 //--------------------------- Engine-specific options menu ----------------------------------
835
836 int SettingsUp;
837 Widget SettingsShell;
838 int values[MAX_OPTIONS];
839 ChessProgramState *currentCps;
840
841 void SettingsPopDown()
842 {
843     if (!SettingsUp) return;
844     previous = NULL;
845     XtPopdown(SettingsShell);
846     XtDestroyWidget(SettingsShell);
847     SettingsUp = False;
848     ModeHighlight();
849 }
850
851 void SpinCallback(w, client_data, call_data)
852      Widget w;
853      XtPointer client_data, call_data;
854 {
855     String name, val;
856     Arg args[16];
857     char buf[MSG_SIZ], *p;
858     int j;
859     int data = (intptr_t) client_data;
860
861     XtSetArg(args[0], XtNlabel, &name);
862     XtGetValues(w, args, 1);
863
864     j = 0;
865     XtSetArg(args[0], XtNstring, &val);
866     XtGetValues(currentCps->option[data].handle, args, 1);
867     sscanf(val, "%d", &j);
868     if (strcmp(name, "browse") == 0) {
869         if(XsraSelFile(SettingsShell, currentCps->option[data].name, NULL, NULL, "", "", 
870                                   currentCps->option[data].type == PathName ? "p" : "f", NULL, &p)) {
871                 int len = strlen(p);
872                 if(len && p[len-1] == '/') p[len-1] = NULLCHAR;
873                 XtSetArg(args[0], XtNstring, p);
874                 XtSetValues(currentCps->option[data].handle, args, 1);
875         }
876         SetFocus(currentCps->option[data].handle, SettingsShell, (XEvent*) NULL, False);
877         return;
878     } else
879     if (strcmp(name, "+") == 0) {
880         if(++j > currentCps->option[data].max) return;
881     } else
882     if (strcmp(name, "-") == 0) {
883         if(--j < currentCps->option[data].min) return;
884     } else return;
885     snprintf(buf, MSG_SIZ,  "%d", j);
886     XtSetArg(args[0], XtNstring, buf);
887     XtSetValues(currentCps->option[data].handle, args, 1);
888 }
889
890 void SettingsCallback(w, client_data, call_data)
891      Widget w;
892      XtPointer client_data, call_data;
893 {
894     String name, val;
895     Arg args[16];
896     char buf[MSG_SIZ];
897     int i, j;
898     int data = (intptr_t) client_data;
899
900     XtSetArg(args[0], XtNlabel, &name);
901     XtGetValues(w, args, 1);
902
903     if (strcmp(name, _("cancel")) == 0) {
904         SettingsPopDown();
905         return;
906     }
907     if (strcmp(name, _("OK")) == 0 || data) { // save buttons imply OK
908         for(i=0; i<currentCps->nrOptions; i++) { // send all options that had to be OK-ed to engine
909             switch(currentCps->option[i].type) {
910                 case TextBox:
911                     XtSetArg(args[0], XtNstring, &val);
912                     XtGetValues(currentCps->option[i].handle, args, 1);
913                     if(strcmp(currentCps->option[i].textValue, val)) {
914                       safeStrCpy(currentCps->option[i].textValue, val, MSG_SIZ - (currentCps->option[i].textValue - currentCps->option[i].name) );
915                       snprintf(buf, MSG_SIZ,  "option %s=%s\n", currentCps->option[i].name, val);
916                       SendToProgram(buf, currentCps);
917                     }
918                     break;
919                 case Spin:
920                     XtSetArg(args[0], XtNstring, &val);
921                     XtGetValues(currentCps->option[i].handle, args, 1);
922                     sscanf(val, "%d", &j);
923                     if(j > currentCps->option[i].max) j = currentCps->option[i].max;
924                     if(j < currentCps->option[i].min) j = currentCps->option[i].min;
925                     if(currentCps->option[i].value != j) {
926                         currentCps->option[i].value = j;
927                         snprintf(buf, MSG_SIZ,  "option %s=%d\n", currentCps->option[i].name, j);
928                         SendToProgram(buf, currentCps);
929                     }
930                     break;
931                 case CheckBox:
932                     j = 0;
933                     XtSetArg(args[0], XtNstate, &j);
934                     XtGetValues(currentCps->option[i].handle, args, 1);
935                     if(currentCps->option[i].value != j) {
936                         currentCps->option[i].value = j;
937                         snprintf(buf, MSG_SIZ,  "option %s=%d\n", currentCps->option[i].name, j);
938                         SendToProgram(buf, currentCps);
939                     }
940                     break;
941                 case ComboBox:
942                     if(currentCps->option[i].value != values[i]) {
943                         currentCps->option[i].value = values[i];
944                         snprintf(buf, MSG_SIZ,  "option %s=%s\n", currentCps->option[i].name,
945                                 ((char**)currentCps->option[i].textValue)[values[i]]);
946                         SendToProgram(buf, currentCps);
947                     }
948                     break;
949             default:
950               if( appData.debugMode )
951                 fprintf(debugFP, "SettingsPopUp: unexpected case in switch.\n");
952               break;
953             }
954         }
955         if(data) { // send save-button command to engine
956           snprintf(buf, MSG_SIZ,  "option %s\n", name);
957           SendToProgram(buf, currentCps);
958         }
959         SettingsPopDown();
960         return;
961     }
962     snprintf(buf, MSG_SIZ,  "option %s\n", name);
963     SendToProgram(buf, currentCps);
964 }
965
966 void ComboSelect(w, addr, index) // callback for all combo items
967      Widget w;
968      caddr_t addr;
969      caddr_t index;
970 {
971     Arg args[16];
972     int i = ((intptr_t)addr)>>8;
973     int j = 255 & (intptr_t) addr;
974
975     values[i] = j; // store in temporary, for transfer at OK
976     XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]);
977     XtSetValues(currentCps->option[i].handle, args, 1);
978 }
979
980 void CreateComboPopup(parent, name, n, mb)
981      Widget parent;
982      String name;
983      int n;
984      char *mb[];
985 {
986     int i=0, j;
987     Widget menu, entry;
988     Arg args[16];
989
990     menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
991                               parent, NULL, 0);
992     j = 0;
993     XtSetArg(args[j], XtNwidth, 100);  j++;
994 //    XtSetArg(args[j], XtNright, XtChainRight);  j++;
995     while (mb[i] != NULL) {
996             entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
997                                           menu, args, j);
998             XtAddCallback(entry, XtNcallback,
999                           (XtCallbackProc) ComboSelect,
1000                           (caddr_t)(intptr_t) (256*n+i));
1001         i++;
1002     }
1003 }
1004
1005 void
1006 SettingsPopUp(ChessProgramState *cps)
1007 {
1008     Arg args[16];
1009     Widget popup, layout, dialog, edit=NULL, form,  last, b_ok, b_cancel, leftMargin = NULL, textField = NULL;
1010     Window root, child;
1011     int x, y, i, j, height, width, h, c;
1012     int win_x, win_y, maxWidth, maxTextWidth;
1013     unsigned int mask;
1014     char def[MSG_SIZ];
1015     static char pane[6] = "paneX";
1016     Widget texts[100], forelast = NULL, anchor, widest;
1017
1018     // to do: start up second engine if needed
1019     if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
1020     currentCps = cps;
1021
1022     if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1;
1023     height = cps->nrOptions / width + 1;
1024      i = 0;
1025     XtSetArg(args[i], XtNresizable, True); i++;
1026     SettingsShell = popup =
1027       XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
1028                          shellWidget, args, i);
1029
1030     layout =
1031       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1032                             layoutArgs, XtNumber(layoutArgs));
1033   for(c=0; c<width; c++) {
1034     pane[4] = 'A'+c;
1035     form =
1036       XtCreateManagedWidget(pane, formWidgetClass, layout,
1037                             formArgs, XtNumber(formArgs));
1038     j=0;
1039     XtSetArg(args[j], XtNfromHoriz, leftMargin);  j++;
1040     XtSetValues(form, args, j);
1041     leftMargin = form;
1042
1043     last = widest = NULL; anchor = forelast;
1044     for(h=0; h<height; h++) {
1045         forelast = last;
1046         i = h + c*height;
1047         if(i >= cps->nrOptions) break;
1048         switch(cps->option[i].type) {
1049           case Spin:
1050             snprintf(def, MSG_SIZ,  "%d", cps->option[i].value);
1051           case TextBox:
1052             j=0;
1053             XtSetArg(args[j], XtNfromVert, last);  j++;
1054             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1055             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1056             texts[h] =
1057             dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1058             j=0;
1059             XtSetArg(args[j], XtNfromVert, last);  j++;
1060             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1061             XtSetArg(args[j], XtNborderWidth, 1); j++;
1062             XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 175); j++;
1063             XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
1064             XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
1065             XtSetArg(args[j], XtNdisplayCaret, False);  j++;
1066             XtSetArg(args[j], XtNright, XtChainRight);  j++;
1067             XtSetArg(args[j], XtNresizable, True);  j++;
1068             XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue);  j++;
1069             XtSetArg(args[j], XtNinsertPosition, 9999);  j++;
1070             edit = last;
1071             cps->option[i].handle = (void*)
1072                 (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1073             XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1074             if(cps->option[i].type == TextBox) break;
1075
1076             // add increment and decrement controls for spin
1077             j=0;
1078             XtSetArg(args[j], XtNfromVert, edit);  j++;
1079             XtSetArg(args[j], XtNfromHoriz, last);  j++;
1080             XtSetArg(args[j], XtNheight, 10);  j++;
1081             XtSetArg(args[j], XtNwidth, 20);  j++;
1082             edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j);
1083             XtAddCallback(edit, XtNcallback, SpinCallback,
1084                           (XtPointer)(intptr_t) i);
1085
1086             j=0;
1087             XtSetArg(args[j], XtNfromVert, edit);  j++;
1088             XtSetArg(args[j], XtNfromHoriz, last);  j++;
1089             XtSetArg(args[j], XtNheight, 10);  j++;
1090             XtSetArg(args[j], XtNwidth, 20);  j++;
1091             last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1092             XtAddCallback(last, XtNcallback, SpinCallback,
1093                           (XtPointer)(intptr_t) i);
1094             break;
1095           case CheckBox:
1096             j=0;
1097             XtSetArg(args[j], XtNfromVert, last);  j++;
1098             XtSetArg(args[j], XtNwidth, 10);  j++;
1099             XtSetArg(args[j], XtNheight, 10);  j++;
1100             XtSetArg(args[j], XtNstate, cps->option[i].value);  j++;
1101             cps->option[i].handle = (void*)
1102                 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1103             j=0;
1104             XtSetArg(args[j], XtNfromVert, last);  j++;
1105             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1106             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1107             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1108             last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1109             break;
1110           case SaveButton:
1111           case Button:
1112             j=0;
1113             XtSetArg(args[j], XtNfromVert, last);  j++;
1114             XtSetArg(args[j], XtNstate, cps->option[i].value);  j++;
1115             cps->option[i].handle = (void*)
1116                 (dialog = last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));
1117             XtAddCallback(last, XtNcallback, SettingsCallback,
1118                           (XtPointer)(intptr_t) (cps->option[i].type == SaveButton));
1119             break;
1120           case ComboBox:
1121             j=0;
1122             XtSetArg(args[j], XtNfromVert, last);  j++;
1123             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1124             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1125             dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1126
1127             j=0;
1128             XtSetArg(args[j], XtNfromVert, last);  j++;
1129             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1130             XtSetArg(args[j], XtNwidth, 100);  j++;
1131             XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name));  j++;
1132             XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]);  j++;
1133             cps->option[i].handle = (void*)
1134                 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1135             CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue);
1136             values[i] = cps->option[i].value;
1137             break;
1138         default:
1139           if( appData.debugMode )
1140             fprintf(debugFP, "SettingsPopUp: unexpected case in switch.\n");
1141           break;
1142         }
1143     }
1144
1145     // make an attempt to align all spins and textbox controls
1146     maxWidth = maxTextWidth = 0;
1147     for(h=0; h<height; h++) {
1148         i = h + c*height;
1149         if(i >= cps->nrOptions) break;
1150         if(cps->option[i].type == Spin || cps->option[i].type == TextBox) {
1151             Dimension w;
1152             j=0;
1153             XtSetArg(args[j], XtNwidth, &w);  j++;
1154             XtGetValues(texts[h], args, j);
1155             if(cps->option[i].type == Spin) {
1156                 if(w > maxWidth) maxWidth = w;
1157                 widest = texts[h];
1158             } else {
1159                 if(w > maxTextWidth) maxTextWidth = w;
1160                 if(!widest) widest = texts[h];
1161             }
1162         }
1163     }
1164     if(maxTextWidth + 110 < maxWidth)
1165          maxTextWidth = maxWidth - 110;
1166     else maxWidth = maxTextWidth + 110;
1167     for(h=0; h<height; h++) {
1168         i = h + c*height;
1169         if(i >= cps->nrOptions) break;
1170         j=0;
1171         if(cps->option[i].type == Spin) {
1172             XtSetArg(args[j], XtNwidth, maxWidth);  j++;
1173             XtSetValues(texts[h], args, j);
1174         } else
1175         if(cps->option[i].type == TextBox) {
1176             XtSetArg(args[j], XtNwidth, maxTextWidth);  j++;
1177             XtSetValues(texts[h], args, j);
1178         }
1179     }
1180   }
1181     j=0;
1182     XtSetArg(args[j], XtNfromVert, anchor ? anchor : last);  j++;
1183     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
1184     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
1185     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
1186     XtSetArg(args[j], XtNright, XtChainRight);  j++;
1187     XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog);  j++;
1188     b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1189     XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
1190
1191     XtSetArg(args[j-1], XtNfromHoriz, b_ok);
1192     b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1193     XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
1194
1195     XtRealizeWidget(popup);
1196     CatchDeleteWindow(popup, "SettingsPopDown");
1197
1198     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1199                   &x, &y, &win_x, &win_y, &mask);
1200
1201     XtSetArg(args[0], XtNx, x - 10);
1202     XtSetArg(args[1], XtNy, y - 30);
1203     XtSetValues(popup, args, 2);
1204
1205     XtPopup(popup, XtGrabExclusive);
1206     SettingsUp = True;
1207
1208     previous = NULL;
1209     if(textField)SetFocus(textField, popup, (XEvent*) NULL, False);
1210 }
1211
1212 void FirstSettingsProc(w, event, prms, nprms)
1213      Widget w;
1214      XEvent *event;
1215      String *prms;
1216      Cardinal *nprms;
1217 {
1218    SettingsPopUp(&first);
1219 }
1220
1221 void SecondSettingsProc(w, event, prms, nprms)
1222      Widget w;
1223      XEvent *event;
1224      String *prms;
1225      Cardinal *nprms;
1226 {
1227    if(WaitForSecond(SettingsMenuIfReady)) return;
1228    SettingsPopUp(&second);
1229 }
1230
1231 //----------------------------Generic dialog --------------------------------------------
1232
1233 // cloned from Engine Settings dialog
1234
1235 typedef void ButtonCallback(int n);
1236
1237 char *trialSound;
1238 static Option *currentOption;
1239 static int oldCores, oldPonder;
1240 int MakeColors P((void));
1241 void CreateGCs P((int redo));
1242 void CreateXPMBoard P((char *s, int kind));
1243 void CreateXPMPieces P((void));
1244 void GenericReadout();
1245
1246 void CommonOptionsOK(int n)
1247 {
1248         int newPonder = appData.ponderNextMove;
1249         // make sure changes are sent to first engine by re-initializing it
1250         // if it was already started pre-emptively at end of previous game
1251         if(gameMode == BeginningOfGame) Reset(True, True); else {
1252             // Some changed setting need immediate sending always.
1253             if(oldCores != appData.smpCores)
1254                 NewSettingEvent(False, &(first.maxCores), "cores", appData.smpCores);
1255             appData.ponderNextMove = oldPonder;
1256             PonderNextMoveEvent(newPonder);
1257         }
1258 }
1259
1260 Option commonEngineOptions[] = {
1261 { 0,     0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, _("Ponder Next Move") },
1262 { 0,  0, 1000, NULL, (void*) &appData.smpCores, "", NULL, Spin, _("Maximum Number of CPUs per Engine:") },
1263 { 0,     0, 0, NULL, (void*) &appData.polyglotDir, "", NULL, PathName, _("Polygot Directory:") },
1264 { 0, 0, 16000, NULL, (void*) &appData.defaultHashSize, "", NULL, Spin, _("Hash-Table Size (MB):") },
1265 { 0,     0, 0, NULL, (void*) &appData.defaultPathEGTB, "", NULL, PathName, _("Nalimov EGTB Path:") },
1266 { 0,  0, 1000, NULL, (void*) &appData.defaultCacheSizeEGTB, "", NULL, Spin, _("EGTB Cache Size (MB):") },
1267 { 0,     0, 0, NULL, (void*) &appData.usePolyglotBook, "", NULL, CheckBox, _("Use GUI Book") },
1268 { 0,     0, 0, NULL, (void*) &appData.polyglotBook, "", NULL, FileName, _("Opening-Book Filename:") },
1269 { 0,   0, 100, NULL, (void*) &appData.bookDepth, "", NULL, Spin, _("Book Depth (moves):") },
1270 { 0,   0, 100, NULL, (void*) &appData.bookStrength, "", NULL, Spin, _("Book Variety (0) vs. Strength (100):") },
1271 { 0,     0, 0, NULL, (void*) &appData.firstHasOwnBookUCI, "", NULL, CheckBox, _("Engine #1 Has Own Book") },
1272 { 0,     0, 0, NULL, (void*) &appData.secondHasOwnBookUCI, "", NULL, CheckBox, _("Engine #2 Has Own Book          ") },
1273 { 0,     1, 0, NULL, (void*) &CommonOptionsOK, "", NULL, EndMark , "" }
1274 };
1275
1276 Option adjudicationOptions[] = {
1277 { 0, 0,    0, NULL, (void*) &appData.checkMates, "", NULL, CheckBox, _("Detect all Mates") },
1278 { 0, 0,    0, NULL, (void*) &appData.testClaims, "", NULL, CheckBox, _("Verify Engine Result Claims") },
1279 { 0, 0,    0, NULL, (void*) &appData.materialDraws, "", NULL, CheckBox, _("Draw if Insufficient Mating Material") },
1280 { 0, 0,    0, NULL, (void*) &appData.trivialDraws, "", NULL, CheckBox, _("Adjudicate Trivial Draws (3-Move Delay)") },
1281 { 0, 0,  100, NULL, (void*) &appData.ruleMoves, "", NULL, Spin, _("N-Move Rule:") },
1282 { 0, 0,    6, NULL, (void*) &appData.drawRepeats, "", NULL, Spin, _("N-fold Repeats:") },
1283 { 0, 0, 1000, NULL, (void*) &appData.adjudicateDrawMoves, "", NULL, Spin, _("Draw after N Moves Total:") },
1284 { 0,-5000, 0, NULL, (void*) &appData.adjudicateLossThreshold, "", NULL, Spin, _("Win / Loss Threshold:") },
1285 { 0, 0,    0, NULL, (void*) &first.scoreIsAbsolute, "", NULL, CheckBox, _("Negate Score of Engine #1") },
1286 { 0, 0,    0, NULL, (void*) &second.scoreIsAbsolute, "", NULL, CheckBox, _("Negate Score of Engine #2") },
1287 { 0, 1,    0, NULL, NULL, "", NULL, EndMark , "" }
1288 };
1289
1290 void IcsOptionsOK(int n)
1291 {
1292     ParseIcsTextColors();
1293 }
1294
1295 Option icsOptions[] = {
1296 { 0, 0, 0, NULL, (void*) &appData.autoKibitz, "",  NULL, CheckBox, _("Auto-Kibitz") },
1297 { 0, 0, 0, NULL, (void*) &appData.autoComment, "", NULL, CheckBox, _("Auto-Comment") },
1298 { 0, 0, 0, NULL, (void*) &appData.autoObserve, "", NULL, CheckBox, _("Auto-Observe") },
1299 { 0, 0, 0, NULL, (void*) &appData.autoRaiseBoard, "", NULL, CheckBox, _("Auto-Raise Board") },
1300 { 0, 0, 0, NULL, (void*) &appData.bgObserve, "",   NULL, CheckBox, _("Background Observe while Playing") },
1301 { 0, 0, 0, NULL, (void*) &appData.dualBoard, "",   NULL, CheckBox, _("Dual Board for Background-Observed Game") },
1302 { 0, 0, 0, NULL, (void*) &appData.getMoveList, "", NULL, CheckBox, _("Get Move List") },
1303 { 0, 0, 0, NULL, (void*) &appData.quietPlay, "",   NULL, CheckBox, _("Quiet Play") },
1304 { 0, 0, 0, NULL, (void*) &appData.seekGraph, "",   NULL, CheckBox, _("Seek Graph") },
1305 { 0, 0, 0, NULL, (void*) &appData.autoRefresh, "", NULL, CheckBox, _("Auto-Refresh Seek Graph") },
1306 { 0, 0, 0, NULL, (void*) &appData.premove, "",     NULL, CheckBox, _("Premove") },
1307 { 0, 0, 0, NULL, (void*) &appData.premoveWhite, "", NULL, CheckBox, _("Premove for White") },
1308 { 0, 0, 0, NULL, (void*) &appData.premoveWhiteText, "", NULL, TextBox, _("First White Move:") },
1309 { 0, 0, 0, NULL, (void*) &appData.premoveBlack, "", NULL, CheckBox, _("Premove for Black") },
1310 { 0, 0, 0, NULL, (void*) &appData.premoveBlackText, "", NULL, TextBox, _("First Black Move:") },
1311 { 0, 0, 0, NULL, NULL, NULL, NULL, Break, "" },
1312 { 0, 0, 0, NULL, (void*) &appData.icsAlarm, "", NULL, CheckBox, _("Alarm") },
1313 { 0, 0, 100000000, NULL, (void*) &appData.icsAlarmTime, "", NULL, Spin, _("Alarm Time (msec):") },
1314 //{ 0, 0, 0, NULL, (void*) &appData.chatBoxes, "", NULL, TextBox, _("Startup Chat Boxes:") },
1315 { 0, 0, 0, NULL, (void*) &appData.colorize, "", NULL, CheckBox, _("Colorize Messages") },
1316 { 0, 0, 0, NULL, (void*) &appData.colorShout, "", NULL, TextBox, _("Shout Text Colors:") },
1317 { 0, 0, 0, NULL, (void*) &appData.colorSShout, "", NULL, TextBox, _("S-Shout Text Colors:") },
1318 { 0, 0, 0, NULL, (void*) &appData.colorChannel1, "", NULL, TextBox, _("Channel #1 Text Colors:") },
1319 { 0, 0, 0, NULL, (void*) &appData.colorChannel, "", NULL, TextBox, _("Other Channel Text Colors:") },
1320 { 0, 0, 0, NULL, (void*) &appData.colorKibitz, "", NULL, TextBox, _("Kibitz Text Colors:") },
1321 { 0, 0, 0, NULL, (void*) &appData.colorTell, "", NULL, TextBox, _("Tell Text Colors:") },
1322 { 0, 0, 0, NULL, (void*) &appData.colorChallenge, "", NULL, TextBox, _("Challenge Text Colors:") },
1323 { 0, 0, 0, NULL, (void*) &appData.colorRequest, "", NULL, TextBox, _("Request Text Colors:") },
1324 { 0, 0, 0, NULL, (void*) &appData.colorSeek, "", NULL, TextBox, _("Seek Text Colors:") },
1325 { 0, 0, 0, NULL, (void*) &IcsOptionsOK, "", NULL, EndMark , "" }
1326 };
1327
1328 Option loadOptions[] = {
1329 { 0, 0, 0, NULL, (void*) &appData.autoDisplayTags, "", NULL, CheckBox, _("Auto-Display Tags") },
1330 { 0, 0, 0, NULL, (void*) &appData.autoDisplayComment, "", NULL, CheckBox, _("Auto-Display Comment") },
1331 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, _("Auto-Play speed of loaded games\n(0 = instant, -1 = off):") },
1332 { 0, -1, 10000000, NULL, (void*) &appData.timeDelay, "", NULL, Fractional, _("Seconds per Move:") },
1333 { 0,  0, 0, NULL, NULL, "", NULL, EndMark , "" }
1334 };
1335
1336 Option saveOptions[] = {
1337 { 0, 0, 0, NULL, (void*) &appData.autoSaveGames, "", NULL, CheckBox, _("Auto-Save Games") },
1338 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, "", NULL, FileName,  _("Save Games on File:") },
1339 { 0, 0, 0, NULL, (void*) &appData.savePositionFile, "", NULL, FileName,  _("Save Final Positions on File:") },
1340 { 0, 0, 0, NULL, (void*) &appData.pgnEventHeader, "", NULL, TextBox,  _("PGN Event Header:") },
1341 { 0, 0, 0, NULL, (void*) &appData.oldSaveStyle, "", NULL, CheckBox, _("Old Save Style (as opposed to PGN)") },
1342 { 0, 0, 0, NULL, (void*) &appData.saveExtendedInfoInPGN, "", NULL, CheckBox, _("Save Score/Depth Info in PGN") },
1343 { 0, 0, 0, NULL, (void*) &appData.saveOutOfBookInfo, "", NULL, CheckBox, _("Save Out-of-Book Info in PGN           ") },
1344 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
1345 };
1346
1347 char *soundNames[] = {
1348         N_("No Sound"),
1349         N_("Default Beep"),
1350         N_("Above WAV File"),
1351         N_("Ching"),
1352         N_("Click"),
1353         N_("Ding"),
1354         N_("Gong"),
1355         N_("Laser"),
1356         N_("Penalty"),
1357         N_("Phone"),
1358         N_("Thud"),
1359         N_("Challenge"),
1360         N_("Tell"),
1361         NULL,
1362         N_("User File")
1363 };
1364
1365 char *soundFiles[] = { // sound files corresponding to above names
1366         "",
1367         "$",
1368         "*", // kludge alert: as first thing in the dialog readout this is replaced with the user-given .WAV filename
1369         "ching.wav",
1370         "click.wav",
1371         "ding1.wav",
1372         "gong.wav",
1373         "laser.wav",
1374         "penalty.wav",
1375         "phone.wav",
1376         "thud.wav",
1377         "challenge.wav",
1378         "tell.wav",
1379         NULL,
1380         NULL
1381 };
1382
1383 void Test(int n)
1384 {
1385     if(soundFiles[values[3]]) PlaySound(soundFiles[values[3]]);
1386 }
1387
1388 Option soundOptions[] = {
1389 { 0, 0, 0, NULL, (void*) &appData.soundProgram, "", NULL, TextBox, _("Sound Program:") },
1390 { 0, 0, 0, NULL, (void*) &appData.soundDirectory, "", NULL, PathName, _("Sounds Directory:") },
1391 { 0, 0, 0, NULL, (void*) (soundFiles+2) /* kludge! */, "", NULL, FileName, _("User WAV File:") },
1392 { 0, 0, 0, NULL, (void*) &trialSound, (char*) soundNames, soundFiles, ComboBox, _("Try-Out Sound:") },
1393 { 0, 1, 0, NULL, (void*) &Test, NULL, NULL, Button, _("Play") },
1394 { 0, 0, 0, NULL, (void*) &appData.soundMove, (char*) soundNames, soundFiles, ComboBox, _("Move:") },
1395 { 0, 0, 0, NULL, (void*) &appData.soundIcsWin, (char*) soundNames, soundFiles, ComboBox, _("Win:") },
1396 { 0, 0, 0, NULL, (void*) &appData.soundIcsLoss, (char*) soundNames, soundFiles, ComboBox, _("Lose:") },
1397 { 0, 0, 0, NULL, (void*) &appData.soundIcsDraw, (char*) soundNames, soundFiles, ComboBox, _("Draw:") },
1398 { 0, 0, 0, NULL, (void*) &appData.soundIcsUnfinished, (char*) soundNames, soundFiles, ComboBox, _("Unfinished:") },
1399 { 0, 0, 0, NULL, (void*) &appData.soundIcsAlarm, (char*) soundNames, soundFiles, ComboBox, _("Alarm:") },
1400 { 0, 0, 0, NULL, (void*) &appData.soundShout, (char*) soundNames, soundFiles, ComboBox, _("Shout:") },
1401 { 0, 0, 0, NULL, (void*) &appData.soundSShout, (char*) soundNames, soundFiles, ComboBox, _("S-Shout:") },
1402 { 0, 0, 0, NULL, (void*) &appData.soundChannel, (char*) soundNames, soundFiles, ComboBox, _("Channel:") },
1403 { 0, 0, 0, NULL, (void*) &appData.soundChannel1, (char*) soundNames, soundFiles, ComboBox, _("Channel 1:") },
1404 { 0, 0, 0, NULL, (void*) &appData.soundTell, (char*) soundNames, soundFiles, ComboBox, _("Tell:") },
1405 { 0, 0, 0, NULL, (void*) &appData.soundKibitz, (char*) soundNames, soundFiles, ComboBox, _("Kibitz:") },
1406 { 0, 0, 0, NULL, (void*) &appData.soundChallenge, (char*) soundNames, soundFiles, ComboBox, _("Challenge:") },
1407 { 0, 0, 0, NULL, (void*) &appData.soundRequest, (char*) soundNames, soundFiles, ComboBox, _("Request:") },
1408 { 0, 0, 0, NULL, (void*) &appData.soundSeek, (char*) soundNames, soundFiles, ComboBox, _("Seek:") },
1409 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
1410 };
1411
1412 void SetColor(char *colorName, Widget box)
1413 {
1414         Arg args[5];
1415         Pixel buttonColor;
1416         XrmValue vFrom, vTo;
1417         if (!appData.monoMode) {
1418             vFrom.addr = (caddr_t) colorName;
1419             vFrom.size = strlen(colorName);
1420             XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1421             if (vTo.addr == NULL) {
1422                 buttonColor = (Pixel) -1;
1423             } else {
1424                 buttonColor = *(Pixel *) vTo.addr;
1425             }
1426         }
1427         XtSetArg(args[0], XtNbackground, buttonColor);;
1428         XtSetValues(box, args, 1);
1429 }
1430
1431 void AdjustColor(int i)
1432 {
1433     int n = currentOption[i].value, col, j, r, g, b, step = 10;
1434     char *s, buf[MSG_SIZ]; // color string
1435     Arg args[5];
1436     XtSetArg(args[0], XtNstring, &s);
1437     XtGetValues(currentOption[i-n-1].handle, args, 1);
1438     if(sscanf(s, "#%x", &col) != 1) return;   // malformed
1439     b = col & 0xFF; g = col & 0xFF00; r = col & 0xFF0000;
1440     switch(n) {
1441         case 1: g -= 0x100*step; b -= step; break;
1442         case 2: r -= 0x10000*step; b -= step; break;
1443         case 3: g -= 0x100*step; r -= 0x10000*step; break;
1444         case 4: r += 0x10000*step; g += 0x100*step; b += step; break;
1445     }
1446     if(r < 0) r = 0; if(g < 0) g = 0; if(b < 0) b = 0;
1447     if(r > 0xFF0000) r = 0xFF0000; if(g > 0xFF00) g = 0xFF00; if(b > 0xFF) b = 0xFF;
1448     col = r | g | b;
1449     snprintf(buf, MSG_SIZ, "#%06x", col);
1450     for(j=1; j<7; j++) if(buf[j] >= 'a') buf[j] -= 32; // capitalize
1451     SetColor(buf, currentOption[i-n].handle);
1452     XtSetArg(args[0], XtNstring, buf);
1453     XtSetValues(currentOption[i-n-1].handle, args, 1);
1454 }
1455
1456 void BoardOptionsOK(int n)
1457 {
1458     if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap;
1459     MakeColors(); CreateGCs(True);
1460     CreateXPMPieces();
1461     CreateXPMBoard(appData.liteBackTextureFile, 1);
1462     CreateXPMBoard(appData.darkBackTextureFile, 0);
1463     InitDrawingSizes(-1, 0);
1464     DrawPosition(True, NULL);
1465 }
1466
1467 Option boardOptions[] = {
1468 { 0,   0, 70, NULL, (void*) &appData.whitePieceColor, "", NULL, TextBox, _("White Piece Color:") },
1469 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1470 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1471 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1472 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1473 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1474 { 0,   0, 70, NULL, (void*) &appData.blackPieceColor, "", NULL, TextBox, _("Black Piece Color:") },
1475 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1476 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1477 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1478 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1479 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1480 { 0,   0, 70, NULL, (void*) &appData.lightSquareColor, "", NULL, TextBox, _("Light Square Color:") },
1481 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1482 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1483 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1484 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1485 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1486 { 0,   0, 70, NULL, (void*) &appData.darkSquareColor, "", NULL, TextBox, _("Dark Square Color:") },
1487 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1488 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1489 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1490 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1491 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1492 { 0,   0, 70, NULL, (void*) &appData.highlightSquareColor, "", NULL, TextBox, _("Highlight Color:") },
1493 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1494 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1495 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1496 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1497 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1498 { 0,   0, 70, NULL, (void*) &appData.premoveHighlightColor, "", NULL, TextBox, _("Premove Highlight Color:") },
1499 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1500 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1501 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1502 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1503 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1504 { 0, 0, 0, NULL, (void*) &appData.upsideDown, "", NULL, CheckBox, _("Flip Pieces Shogi Style") },
1505 { 0, 0, 0, NULL, (void*) &appData.allWhite, "", NULL, CheckBox, _("Use Outline Pieces for Black") },
1506 { 0, 0, 0, NULL, (void*) &appData.monoMode, "", NULL, CheckBox, _("Mono Mode") },
1507 { 0,-1, 5, NULL, (void*) &appData.overrideLineGap, "", NULL, Spin, _("Line Gap ( -1 = default for board size):") },
1508 { 0, 0, 0, NULL, (void*) &appData.liteBackTextureFile, "", NULL, FileName, _("Light-Squares Texture File:") },
1509 { 0, 0, 0, NULL, (void*) &appData.darkBackTextureFile, "", NULL, FileName, _("Dark-Squares Texture File:") },
1510 { 0, 0, 0, NULL, (void*) &appData.bitmapDirectory, "", NULL, PathName, _("Directory with Bitmap Pieces:") },
1511 { 0, 0, 0, NULL, (void*) &appData.pixmapDirectory, "", NULL, PathName, _("Directory with Pixmap Pieces:") },
1512 { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" }
1513 };
1514
1515 void GenericReadout()
1516 {
1517     int i, j;
1518     String name, val;
1519     Arg args[16];
1520     char buf[MSG_SIZ];
1521     float x;
1522         for(i=0; ; i++) { // send all options that had to be OK-ed to engine
1523             switch(currentOption[i].type) {
1524                 case TextBox:
1525                 case FileName:
1526                 case PathName:
1527                     XtSetArg(args[0], XtNstring, &val);
1528                     XtGetValues(currentOption[i].handle, args, 1);
1529                     if(*(char**) currentOption[i].target == NULL || strcmp(*(char**) currentOption[i].target, val)) {
1530                         safeStrCpy(currentOption[i].name + 100, val, MSG_SIZ-100); // text value kept in pivate storage for each option
1531                         *(char**) currentOption[i].target = currentOption[i].name + 100; // option gets to point to that
1532                     }
1533                     break;
1534                 case Spin:
1535                 case Fractional:
1536                     XtSetArg(args[0], XtNstring, &val);
1537                     XtGetValues(currentOption[i].handle, args, 1);
1538                     sscanf(val, "%f", &x);
1539                     if(x > currentOption[i].max) x = currentOption[i].max;
1540                     if(x < currentOption[i].min) x = currentOption[i].min;
1541                     if(currentOption[i].value != x) {
1542                         currentOption[i].value = x;
1543                         if(currentOption[i].type == Spin) *(int*) currentOption[i].target = x;
1544                         else *(float*) currentOption[i].target = x;
1545                     }
1546                     break;
1547                 case CheckBox:
1548                     j = 0;
1549                     XtSetArg(args[0], XtNstate, &j);
1550                     XtGetValues(currentOption[i].handle, args, 1);
1551                     if(currentOption[i].value != j) {
1552                         currentOption[i].value = j;
1553                         *(Boolean*) currentOption[i].target = j;
1554                     }
1555                     break;
1556                 case ComboBox:
1557                     val = ((char**)currentOption[i].choice)[values[i]];
1558                     if(val && (*(char**) currentOption[i].target == NULL || strcmp(*(char**) currentOption[i].target, val))) {
1559                       if(*(char**) currentOption[i].target) free(*(char**) currentOption[i].target);
1560                       *(char**) currentOption[i].target = strdup(val);
1561                     }
1562                     break;
1563                 case EndMark:
1564                     if(currentOption[i].target) // callback for implementing necessary actions on OK (like redraw)
1565                         ((ButtonCallback*) currentOption[i].target)(i);
1566                     break;
1567             default:
1568                 printf("GenericReadout: unexpected case in switch.\n");
1569                 case Button:
1570                 case Label:
1571               break;
1572             }
1573             if(currentOption[i].type == EndMark) break;
1574         }
1575 }
1576
1577 void GenericCallback(w, client_data, call_data)
1578      Widget w;
1579      XtPointer client_data, call_data;
1580 {
1581     String name, val;
1582     Arg args[16];
1583     char buf[MSG_SIZ];
1584     int i, j;
1585     int data = (intptr_t) client_data;
1586
1587     XtSetArg(args[0], XtNlabel, &name);
1588     XtGetValues(w, args, 1);
1589
1590     if (strcmp(name, _("cancel")) == 0) {
1591         SettingsPopDown();
1592         return;
1593     }
1594     if (strcmp(name, _("OK")) == 0) { // save buttons imply OK
1595         GenericReadout();
1596         SettingsPopDown();
1597         return;
1598     }
1599     ((ButtonCallback*) currentOption[data].target)(data);
1600 }
1601
1602 void
1603 GenericPopUp(Option *option, char *title)
1604 {
1605     Arg args[16];
1606     Widget popup, layout, dialog, edit=NULL, form,  last, b_ok, b_cancel, leftMargin = NULL, textField = NULL;
1607     Window root, child;
1608     int x, y, i, j, height=999, width=1, h, c, w;
1609     int win_x, win_y, maxWidth, maxTextWidth;
1610     unsigned int mask;
1611     char def[MSG_SIZ], *msg;
1612     static char pane[6] = "paneX";
1613     Widget texts[100], forelast = NULL, anchor, widest, lastrow = NULL;
1614
1615     currentOption = option; // make available to callback
1616     // kludge: fake address of a ChessProgramState struct that contains the options, so Spin and Combo callbacks work on it
1617     currentCps = (ChessProgramState *) ((char *) option - ((char *)&first.option - (char *)&first));
1618
1619 //    if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1;
1620 //    height = cps->nrOptions / width + 1;
1621      i = 0;
1622     XtSetArg(args[i], XtNresizable, True); i++;
1623     SettingsShell = popup =
1624       XtCreatePopupShell(title, transientShellWidgetClass,
1625                          shellWidget, args, i);
1626
1627     layout =
1628       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1629                             layoutArgs, XtNumber(layoutArgs));
1630   for(c=0; c<width; c++) {
1631     pane[4] = 'A'+c;
1632     form =
1633       XtCreateManagedWidget(pane, formWidgetClass, layout,
1634                             formArgs, XtNumber(formArgs));
1635     j=0;
1636     XtSetArg(args[j], XtNfromHoriz, leftMargin);  j++;
1637     XtSetValues(form, args, j);
1638     leftMargin = form;
1639
1640     last = widest = NULL; anchor = lastrow;
1641     for(h=0; h<height; h++) {
1642         i = h + c*height;
1643         if(option[i].type == EndMark) break;
1644         lastrow = forelast;
1645         forelast = last;
1646         switch(option[i].type) {
1647           case Fractional:
1648             snprintf(def, MSG_SIZ,  "%.2f", *(float*)option[i].target);
1649             option[i].value = *(float*)option[i].target;
1650             goto tBox;
1651           case Spin:
1652             snprintf(def, MSG_SIZ,  "%d", option[i].value = *(int*)option[i].target);
1653           case TextBox:
1654           case FileName:
1655           case PathName:
1656           tBox:
1657             if(option[i].name[0]) {
1658             j=0;
1659             XtSetArg(args[j], XtNfromVert, last);  j++;
1660             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1661             XtSetArg(args[j], XtNright, XtChainLeft); j++;
1662             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1663             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1664             texts[h] =
1665             dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
1666             } else texts[h] = dialog = NULL;
1667             w = option[i].type == Spin || option[i].type == Fractional ? 70 : option[i].max ? option[i].max : 205;
1668             if(option[i].type == FileName || option[i].type == PathName) w -= 55;
1669             j=0;
1670             XtSetArg(args[j], XtNfromVert, last);  j++;
1671             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1672             XtSetArg(args[j], XtNborderWidth, 1); j++;
1673             XtSetArg(args[j], XtNwidth, w); j++;
1674             if(option[i].type == TextBox && option[i].min) XtSetArg(args[j], XtNheight, option[i].min); j++;
1675             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1676             XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
1677             XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
1678             XtSetArg(args[j], XtNdisplayCaret, False);  j++;
1679             XtSetArg(args[j], XtNright, XtChainRight);  j++;
1680             XtSetArg(args[j], XtNresizable, True);  j++;
1681             XtSetArg(args[j], XtNstring, option[i].type==Spin || option[i].type==Fractional ? def : *(char**)option[i].target);  j++;
1682             XtSetArg(args[j], XtNinsertPosition, 9999);  j++;
1683             edit = last;
1684             option[i].handle = (void*)
1685                 (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1686             XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1687
1688             if(option[i].type == TextBox || option[i].type == Fractional) break;
1689
1690             // add increment and decrement controls for spin
1691             j=0;
1692             XtSetArg(args[j], XtNfromVert, edit);  j++;
1693             XtSetArg(args[j], XtNfromHoriz, last);  j++;
1694             XtSetArg(args[j], XtNleft, XtChainRight); j++;
1695             XtSetArg(args[j], XtNright, XtChainRight); j++;
1696             if(option[i].type == FileName || option[i].type == PathName) {
1697                 w = 50; msg = "browse";
1698             } else {
1699                 XtSetArg(args[j], XtNheight, 10);  j++;
1700                 w = 20; msg = "+";
1701             }
1702             XtSetArg(args[j], XtNwidth, w);  j++;
1703             edit = XtCreateManagedWidget(msg, commandWidgetClass, form, args, j);
1704             XtAddCallback(edit, XtNcallback, SpinCallback,
1705                           (XtPointer)(intptr_t) i);
1706
1707             if(option[i].type != Spin) break;
1708
1709             j=0;
1710             XtSetArg(args[j], XtNfromVert, edit);  j++;
1711             XtSetArg(args[j], XtNfromHoriz, last);  j++;
1712             XtSetArg(args[j], XtNheight, 10);  j++;
1713             XtSetArg(args[j], XtNwidth, 20);  j++;
1714             XtSetArg(args[j], XtNleft, XtChainRight); j++;
1715             XtSetArg(args[j], XtNright, XtChainRight); j++;
1716             last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1717             XtAddCallback(last, XtNcallback, SpinCallback,
1718                           (XtPointer)(intptr_t) i);
1719             break;
1720           case CheckBox:
1721             j=0;
1722             XtSetArg(args[j], XtNfromVert, last);  j++;
1723             XtSetArg(args[j], XtNwidth, 10);  j++;
1724             XtSetArg(args[j], XtNheight, 10);  j++;
1725             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1726             XtSetArg(args[j], XtNright, XtChainLeft); j++;
1727             XtSetArg(args[j], XtNstate, option[i].value = *(Boolean*)option[i].target);  j++;
1728             option[i].handle = (void*)
1729                 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1730           case Label:
1731             msg = option[i].name;
1732             if(*msg == NULLCHAR) msg = option[i].textValue;
1733             if(!msg) break;
1734             j=0;
1735             XtSetArg(args[j], XtNfromVert, last);  j++;
1736             XtSetArg(args[j], XtNfromHoriz, option[i].type != Label ? dialog : NULL);  j++;
1737             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1738             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1739             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1740             last = XtCreateManagedWidget(msg, labelWidgetClass, form, args, j);
1741             break;
1742           case Button:
1743             j=0;
1744             XtSetArg(args[j], XtNfromVert, option[i].min & 1 ? lastrow : last);  j++;
1745             if(option[i].min & 1) { XtSetArg(args[j], XtNfromHoriz, last);  j++; }
1746             else  { XtSetArg(args[j], XtNfromHoriz, NULL);  j++; lastrow = forelast; }
1747             if(option[i].max) XtSetArg(args[j], XtNwidth, option[i].max);  j++;
1748             if(option[i].textValue) { // special for buttons of New Variant dialog
1749                 XtSetArg(args[j], XtNsensitive, appData.noChessProgram || option[i].value < 0
1750                                          || strstr(first.variants, VariantName(option[i].value))); j++;
1751                 XtSetArg(args[j], XtNborderWidth, (gameInfo.variant == option[i].value)+1); j++;
1752             }
1753             option[i].handle = (void*)
1754                 (dialog = last = XtCreateManagedWidget(option[i].name, commandWidgetClass, form, args, j));
1755             if(option[i].target == NULL) SetColor( *(char**) option[i-1].target, last); else
1756             XtAddCallback(last, XtNcallback, GenericCallback,
1757                           (XtPointer)(intptr_t) i);
1758             if(option[i].textValue) SetColor( option[i].textValue, last);
1759             forelast = lastrow; // next button can go on same row
1760             break;
1761           case ComboBox:
1762             j=0;
1763             XtSetArg(args[j], XtNfromVert, last);  j++;
1764             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1765             XtSetArg(args[j], XtNright, XtChainLeft); j++;
1766             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1767             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1768             texts[h] = dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
1769
1770             for(j=0; option[i].choice[j]; j++)
1771                 if(*(char**)option[i].target && !strcmp(*(char**)option[i].target, option[i].choice[j])) break;
1772             option[i].value = j + (option[i].choice[j] == NULL);
1773
1774             j=0;
1775             XtSetArg(args[j], XtNfromVert, last);  j++;
1776             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1777             XtSetArg(args[j], XtNwidth, option[i].max ? option[i].max : 100);  j++;
1778             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1779             XtSetArg(args[j], XtNmenuName, XtNewString(option[i].name));  j++;
1780             XtSetArg(args[j], XtNlabel, ((char**)option[i].textValue)[option[i].value]);  j++;
1781             option[i].handle = (void*)
1782                 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1783             CreateComboPopup(last, option[i].name, i, (char **) option[i].textValue);
1784             values[i] = option[i].value;
1785             break;
1786           case Break:
1787             width++;
1788             height = i+1;
1789             break;
1790         default:
1791             printf("GenericPopUp: unexpected case in switch.\n");
1792             break;
1793         }
1794     }
1795
1796     // make an attempt to align all spins and textbox controls
1797     maxWidth = maxTextWidth = 0;
1798     for(h=0; h<height; h++) {
1799         i = h + c*height;
1800         if(option[i].type == EndMark) break;
1801         if(option[i].type == Spin || option[i].type == TextBox || option[i].type == ComboBox
1802                                   || option[i].type == PathName || option[i].type == FileName) {
1803             Dimension w;
1804             if(!texts[h]) continue;
1805             j=0;
1806             XtSetArg(args[j], XtNwidth, &w);  j++;
1807             XtGetValues(texts[h], args, j);
1808             if(option[i].type == Spin) {
1809                 if(w > maxWidth) maxWidth = w;
1810                 widest = texts[h];
1811             } else {
1812                 if(w > maxTextWidth) maxTextWidth = w;
1813                 if(!widest) widest = texts[h];
1814             }
1815         }
1816     }
1817     if(maxTextWidth + 110 < maxWidth)
1818          maxTextWidth = maxWidth - 110;
1819     else maxWidth = maxTextWidth + 110;
1820     for(h=0; h<height; h++) {
1821         i = h + c*height;
1822         if(option[i].type == EndMark) break;
1823         if(!texts[h]) continue;
1824         j=0;
1825         if(option[i].type == Spin) {
1826             XtSetArg(args[j], XtNwidth, maxWidth);  j++;
1827             XtSetValues(texts[h], args, j);
1828         } else
1829         if(option[i].type == TextBox || option[i].type == ComboBox || option[i].type == PathName || option[i].type == FileName) {
1830             XtSetArg(args[j], XtNwidth, maxTextWidth);  j++;
1831             XtSetValues(texts[h], args, j);
1832         }
1833     }
1834   }
1835
1836   if(!(option[i].min & 2)) {
1837     j=0;
1838     if(option[i].min & 1) { XtSetArg(args[j], XtNfromHoriz, last); last = forelast; } else
1839     XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog);  j++;
1840     XtSetArg(args[j], XtNfromVert, anchor ? anchor : last);  j++;
1841     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
1842     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
1843     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
1844     XtSetArg(args[j], XtNright, XtChainRight);  j++;
1845     b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1846     XtAddCallback(b_ok, XtNcallback, GenericCallback, (XtPointer) 0);
1847
1848     XtSetArg(args[0], XtNfromHoriz, b_ok);
1849     b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1850     XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
1851   }
1852
1853     XtRealizeWidget(popup);
1854     CatchDeleteWindow(popup, "SettingsPopDown");
1855
1856     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1857                   &x, &y, &win_x, &win_y, &mask);
1858
1859     XtSetArg(args[0], XtNx, x - 10);
1860     XtSetArg(args[1], XtNy, y - 30);
1861     XtSetValues(popup, args, 2);
1862
1863     XtPopup(popup, XtGrabExclusive);
1864     SettingsUp = True;
1865
1866     previous = NULL;
1867     if(textField)SetFocus(textField, popup, (XEvent*) NULL, False);
1868 }
1869
1870
1871 void IcsOptionsProc(w, event, prms, nprms)
1872      Widget w;
1873      XEvent *event;
1874      String *prms;
1875      Cardinal *nprms;
1876 {
1877    GenericPopUp(icsOptions, _("ICS Options"));
1878 }
1879
1880 void LoadOptionsProc(w, event, prms, nprms)
1881      Widget w;
1882      XEvent *event;
1883      String *prms;
1884      Cardinal *nprms;
1885 {
1886    GenericPopUp(loadOptions, _("Load Game Options"));
1887 }
1888
1889 void SaveOptionsProc(w, event, prms, nprms)
1890      Widget w;
1891      XEvent *event;
1892      String *prms;
1893      Cardinal *nprms;
1894 {
1895    GenericPopUp(saveOptions, _("Save Game Options"));
1896 }
1897
1898 void SoundOptionsProc(w, event, prms, nprms)
1899      Widget w;
1900      XEvent *event;
1901      String *prms;
1902      Cardinal *nprms;
1903 {
1904    soundFiles[2] = "*";
1905    GenericPopUp(soundOptions, _("Sound Options"));
1906 }
1907
1908 void BoardOptionsProc(w, event, prms, nprms)
1909      Widget w;
1910      XEvent *event;
1911      String *prms;
1912      Cardinal *nprms;
1913 {
1914    GenericPopUp(boardOptions, _("Board Options"));
1915 }
1916
1917 void EngineMenuProc(w, event, prms, nprms)
1918      Widget w;
1919      XEvent *event;
1920      String *prms;
1921      Cardinal *nprms;
1922 {
1923    GenericPopUp(adjudicationOptions, "Adjudicate non-ICS Games");
1924 }
1925
1926 void UciMenuProc(w, event, prms, nprms)
1927      Widget w;
1928      XEvent *event;
1929      String *prms;
1930      Cardinal *nprms;
1931 {
1932    oldCores = appData.smpCores;
1933    oldPonder = appData.ponderNextMove;
1934    GenericPopUp(commonEngineOptions, _("Common Engine Settings"));
1935 }
1936
1937 //---------------------------- Chat Windows ----------------------------------------------
1938
1939 void OutputChatMessage(int partner, char *mess)
1940 {
1941     return; // dummy
1942 }
1943