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