Make generic dialog popup reentrant
[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
627 void SettingsPopDown()
628 {
629     if (!SettingsUp) return;
630     previous = NULL;
631     XtPopdown(SettingsShell);
632     XtDestroyWidget(SettingsShell);
633     SettingsUp = False;
634     ModeHighlight();
635 }
636
637 void SpinCallback(w, client_data, call_data)
638      Widget w;
639      XtPointer client_data, call_data;
640 {
641     String name, val;
642     Arg args[16];
643     char buf[MSG_SIZ], *p;
644     int j;
645     int data = (intptr_t) client_data;
646
647     XtSetArg(args[0], XtNlabel, &name);
648     XtGetValues(w, args, 1);
649
650     j = 0;
651     XtSetArg(args[0], XtNstring, &val);
652     XtGetValues(currentCps->option[data].handle, args, 1);
653     sscanf(val, "%d", &j);
654     if (strcmp(name, "browse") == 0) {
655         if(XsraSelFile(SettingsShell, currentCps->option[data].name, NULL, NULL, "", "", 
656                                   currentCps->option[data].type == PathName ? "p" : "f", NULL, &p)) {
657                 int len = strlen(p);
658                 if(len && p[len-1] == '/') p[len-1] = NULLCHAR;
659                 XtSetArg(args[0], XtNstring, p);
660                 XtSetValues(currentCps->option[data].handle, args, 1);
661         }
662         SetFocus(currentCps->option[data].handle, SettingsShell, (XEvent*) NULL, False);
663         return;
664     } else
665     if (strcmp(name, "+") == 0) {
666         if(++j > currentCps->option[data].max) return;
667     } else
668     if (strcmp(name, "-") == 0) {
669         if(--j < currentCps->option[data].min) return;
670     } else return;
671     snprintf(buf, MSG_SIZ,  "%d", j);
672     XtSetArg(args[0], XtNstring, buf);
673     XtSetValues(currentCps->option[data].handle, args, 1);
674 }
675
676 void SettingsCallback(w, client_data, call_data)
677      Widget w;
678      XtPointer client_data, call_data;
679 {
680     String name, val;
681     Arg args[16];
682     char buf[MSG_SIZ];
683     int i, j;
684     int data = (intptr_t) client_data;
685
686     XtSetArg(args[0], XtNlabel, &name);
687     XtGetValues(w, args, 1);
688
689     if (strcmp(name, _("cancel")) == 0) {
690         SettingsPopDown();
691         return;
692     }
693     if (strcmp(name, _("OK")) == 0 || data) { // save buttons imply OK
694         for(i=0; i<currentCps->nrOptions; i++) { // send all options that had to be OK-ed to engine
695             switch(currentCps->option[i].type) {
696                 case TextBox:
697                     XtSetArg(args[0], XtNstring, &val);
698                     XtGetValues(currentCps->option[i].handle, args, 1);
699                     if(strcmp(currentCps->option[i].textValue, val)) {
700                       safeStrCpy(currentCps->option[i].textValue, val, MSG_SIZ - (currentCps->option[i].textValue - currentCps->option[i].name) );
701                       snprintf(buf, MSG_SIZ,  "option %s=%s\n", currentCps->option[i].name, val);
702                       SendToProgram(buf, currentCps);
703                     }
704                     break;
705                 case Spin:
706                     XtSetArg(args[0], XtNstring, &val);
707                     XtGetValues(currentCps->option[i].handle, args, 1);
708                     sscanf(val, "%d", &j);
709                     if(j > currentCps->option[i].max) j = currentCps->option[i].max;
710                     if(j < currentCps->option[i].min) j = currentCps->option[i].min;
711                     if(currentCps->option[i].value != j) {
712                         currentCps->option[i].value = j;
713                         snprintf(buf, MSG_SIZ,  "option %s=%d\n", currentCps->option[i].name, j);
714                         SendToProgram(buf, currentCps);
715                     }
716                     break;
717                 case CheckBox:
718                     j = 0;
719                     XtSetArg(args[0], XtNstate, &j);
720                     XtGetValues(currentCps->option[i].handle, args, 1);
721                     if(currentCps->option[i].value != j) {
722                         currentCps->option[i].value = j;
723                         snprintf(buf, MSG_SIZ,  "option %s=%d\n", currentCps->option[i].name, j);
724                         SendToProgram(buf, currentCps);
725                     }
726                     break;
727                 case ComboBox:
728                     if(currentCps->option[i].value != values[i]) {
729                         currentCps->option[i].value = values[i];
730                         snprintf(buf, MSG_SIZ,  "option %s=%s\n", currentCps->option[i].name,
731                                 ((char**)currentCps->option[i].textValue)[values[i]]);
732                         SendToProgram(buf, currentCps);
733                     }
734                     break;
735             default:
736               if( appData.debugMode )
737                 fprintf(debugFP, "SettingsPopUp: unexpected case in switch.\n");
738               break;
739             }
740         }
741         if(data) { // send save-button command to engine
742           snprintf(buf, MSG_SIZ,  "option %s\n", name);
743           SendToProgram(buf, currentCps);
744         }
745         SettingsPopDown();
746         return;
747     }
748     snprintf(buf, MSG_SIZ,  "option %s\n", name);
749     SendToProgram(buf, currentCps);
750 }
751
752 void ComboSelect(w, addr, index) // callback for all combo items
753      Widget w;
754      caddr_t addr;
755      caddr_t index;
756 {
757     Arg args[16];
758     int i = ((intptr_t)addr)>>8;
759     int j = 255 & (intptr_t) addr;
760
761     values[i] = j; // store in temporary, for transfer at OK
762     XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]);
763     XtSetValues(currentCps->option[i].handle, args, 1);
764 }
765
766 void CreateComboPopup(parent, name, n, mb)
767      Widget parent;
768      String name;
769      int n;
770      char *mb[];
771 {
772     int i=0, j;
773     Widget menu, entry;
774     Arg args[16];
775
776     menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
777                               parent, NULL, 0);
778     j = 0;
779     XtSetArg(args[j], XtNwidth, 100);  j++;
780 //    XtSetArg(args[j], XtNright, XtChainRight);  j++;
781     while (mb[i] != NULL) {
782             entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
783                                           menu, args, j);
784             XtAddCallback(entry, XtNcallback,
785                           (XtCallbackProc) ComboSelect,
786                           (caddr_t)(intptr_t) (256*n+i));
787         i++;
788     }
789 }
790
791 void
792 SettingsPopUp(ChessProgramState *cps)
793 {
794     Arg args[16];
795     Widget popup, layout, dialog, edit=NULL, form,  last, b_ok, b_cancel, leftMargin = NULL, textField = NULL;
796     Window root, child;
797     int x, y, i, j, height, width, h, c;
798     int win_x, win_y, maxWidth, maxTextWidth;
799     unsigned int mask;
800     char def[MSG_SIZ];
801     static char pane[6] = "paneX";
802     Widget texts[100], forelast = NULL, anchor, widest;
803
804     // to do: start up second engine if needed
805     if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
806     currentCps = cps;
807
808     if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1;
809     height = cps->nrOptions / width + 1;
810      i = 0;
811     XtSetArg(args[i], XtNresizable, True); i++;
812     SettingsShell = popup =
813       XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
814                          shellWidget, args, i);
815
816     layout =
817       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
818                             layoutArgs, XtNumber(layoutArgs));
819   for(c=0; c<width; c++) {
820     pane[4] = 'A'+c;
821     form =
822       XtCreateManagedWidget(pane, formWidgetClass, layout,
823                             formArgs, XtNumber(formArgs));
824     j=0;
825     XtSetArg(args[j], XtNfromHoriz, leftMargin);  j++;
826     XtSetValues(form, args, j);
827     leftMargin = form;
828
829     last = widest = NULL; anchor = forelast;
830     for(h=0; h<height; h++) {
831         forelast = last;
832         i = h + c*height;
833         if(i >= cps->nrOptions) break;
834         switch(cps->option[i].type) {
835           case Spin:
836             snprintf(def, MSG_SIZ,  "%d", cps->option[i].value);
837           case TextBox:
838             j=0;
839             XtSetArg(args[j], XtNfromVert, last);  j++;
840             XtSetArg(args[j], XtNborderWidth, 0);  j++;
841             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
842             texts[h] =
843             dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
844             j=0;
845             XtSetArg(args[j], XtNfromVert, last);  j++;
846             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
847             XtSetArg(args[j], XtNborderWidth, 1); j++;
848             XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 175); j++;
849             XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
850             XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
851             XtSetArg(args[j], XtNdisplayCaret, False);  j++;
852             XtSetArg(args[j], XtNright, XtChainRight);  j++;
853             XtSetArg(args[j], XtNresizable, True);  j++;
854             XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue);  j++;
855             XtSetArg(args[j], XtNinsertPosition, 9999);  j++;
856             edit = last;
857             cps->option[i].handle = (void*)
858                 (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
859             XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
860             if(cps->option[i].type == TextBox) break;
861
862             // add increment and decrement controls for spin
863             j=0;
864             XtSetArg(args[j], XtNfromVert, edit);  j++;
865             XtSetArg(args[j], XtNfromHoriz, last);  j++;
866             XtSetArg(args[j], XtNheight, 10);  j++;
867             XtSetArg(args[j], XtNwidth, 20);  j++;
868             edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j);
869             XtAddCallback(edit, XtNcallback, SpinCallback,
870                           (XtPointer)(intptr_t) i);
871
872             j=0;
873             XtSetArg(args[j], XtNfromVert, edit);  j++;
874             XtSetArg(args[j], XtNfromHoriz, last);  j++;
875             XtSetArg(args[j], XtNheight, 10);  j++;
876             XtSetArg(args[j], XtNwidth, 20);  j++;
877             last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
878             XtAddCallback(last, XtNcallback, SpinCallback,
879                           (XtPointer)(intptr_t) i);
880             break;
881           case CheckBox:
882             j=0;
883             XtSetArg(args[j], XtNfromVert, last);  j++;
884             XtSetArg(args[j], XtNwidth, 10);  j++;
885             XtSetArg(args[j], XtNheight, 10);  j++;
886             XtSetArg(args[j], XtNstate, cps->option[i].value);  j++;
887             cps->option[i].handle = (void*)
888                 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
889             j=0;
890             XtSetArg(args[j], XtNfromVert, last);  j++;
891             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
892             XtSetArg(args[j], XtNborderWidth, 0);  j++;
893             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
894             last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
895             break;
896           case SaveButton:
897           case Button:
898             j=0;
899             XtSetArg(args[j], XtNfromVert, last);  j++;
900             XtSetArg(args[j], XtNstate, cps->option[i].value);  j++;
901             cps->option[i].handle = (void*)
902                 (dialog = last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));
903             XtAddCallback(last, XtNcallback, SettingsCallback,
904                           (XtPointer)(intptr_t) (cps->option[i].type == SaveButton));
905             break;
906           case ComboBox:
907             j=0;
908             XtSetArg(args[j], XtNfromVert, last);  j++;
909             XtSetArg(args[j], XtNborderWidth, 0);  j++;
910             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
911             dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
912
913             j=0;
914             XtSetArg(args[j], XtNfromVert, last);  j++;
915             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
916             XtSetArg(args[j], XtNwidth, 100);  j++;
917             XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name));  j++;
918             XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]);  j++;
919             cps->option[i].handle = (void*)
920                 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
921             CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue);
922             values[i] = cps->option[i].value;
923             break;
924         default:
925           if( appData.debugMode )
926             fprintf(debugFP, "SettingsPopUp: unexpected case in switch.\n");
927           break;
928         }
929     }
930
931     // make an attempt to align all spins and textbox controls
932     maxWidth = maxTextWidth = 0;
933     for(h=0; h<height; h++) {
934         i = h + c*height;
935         if(i >= cps->nrOptions) break;
936         if(cps->option[i].type == Spin || cps->option[i].type == TextBox) {
937             Dimension w;
938             j=0;
939             XtSetArg(args[j], XtNwidth, &w);  j++;
940             XtGetValues(texts[h], args, j);
941             if(cps->option[i].type == Spin) {
942                 if(w > maxWidth) maxWidth = w;
943                 widest = texts[h];
944             } else {
945                 if(w > maxTextWidth) maxTextWidth = w;
946                 if(!widest) widest = texts[h];
947             }
948         }
949     }
950     if(maxTextWidth + 110 < maxWidth)
951          maxTextWidth = maxWidth - 110;
952     else maxWidth = maxTextWidth + 110;
953     for(h=0; h<height; h++) {
954         i = h + c*height;
955         if(i >= cps->nrOptions) break;
956         j=0;
957         if(cps->option[i].type == Spin) {
958             XtSetArg(args[j], XtNwidth, maxWidth);  j++;
959             XtSetValues(texts[h], args, j);
960         } else
961         if(cps->option[i].type == TextBox) {
962             XtSetArg(args[j], XtNwidth, maxTextWidth);  j++;
963             XtSetValues(texts[h], args, j);
964         }
965     }
966   }
967     j=0;
968     XtSetArg(args[j], XtNfromVert, anchor ? anchor : last);  j++;
969     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
970     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
971     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
972     XtSetArg(args[j], XtNright, XtChainRight);  j++;
973     XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog);  j++;
974     b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
975     XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
976
977     XtSetArg(args[j-1], XtNfromHoriz, b_ok);
978     b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
979     XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
980
981     XtRealizeWidget(popup);
982     CatchDeleteWindow(popup, "SettingsPopDown");
983
984     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
985                   &x, &y, &win_x, &win_y, &mask);
986
987     XtSetArg(args[0], XtNx, x - 10);
988     XtSetArg(args[1], XtNy, y - 30);
989     XtSetValues(popup, args, 2);
990
991     XtPopup(popup, XtGrabExclusive);
992     SettingsUp = True;
993
994     previous = NULL;
995     if(textField)SetFocus(textField, popup, (XEvent*) NULL, False);
996 }
997
998 void FirstSettingsProc(w, event, prms, nprms)
999      Widget w;
1000      XEvent *event;
1001      String *prms;
1002      Cardinal *nprms;
1003 {
1004    SettingsPopUp(&first);
1005 }
1006
1007 void SecondSettingsProc(w, event, prms, nprms)
1008      Widget w;
1009      XEvent *event;
1010      String *prms;
1011      Cardinal *nprms;
1012 {
1013    if(WaitForSecond(SettingsMenuIfReady)) return;
1014    SettingsPopUp(&second);
1015 }
1016
1017 //----------------------------Generic dialog --------------------------------------------
1018
1019 // cloned from Engine Settings dialog
1020
1021 typedef void ButtonCallback(int n);
1022
1023 char *trialSound;
1024 static Option *currentOption;
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     return 1;
1071 }
1072
1073 void GenericPopDown(w, event, prms, nprms)
1074      Widget w;
1075      XEvent *event;
1076      String *prms;
1077      Cardinal *nprms;
1078 {
1079     int n;
1080     PopDown(prms[0][0] - '0');
1081 }
1082
1083 Option matchOptions[] = {
1084 { 0,  2, 1000000000, NULL, (void*) &appData.defaultMatchGames, "", NULL, Spin, _("Default Number of Games in Match:") },
1085 { 0,  0, 1000000000, NULL, (void*) &appData.matchPause, "", NULL, Spin, _("Pause between Match Games (msec):") },
1086 { 0,  0,          0, NULL, (void*) &appData.loadGameFile, "", NULL, FileName, _("Game File with Opening Lines:") },
1087 { 0, -2, 1000000000, NULL, (void*) &appData.loadGameIndex, "", NULL, Spin, _("Game Number (-1 or -2 = Auto-Increment):") },
1088 { 0,  0,          0, NULL, (void*) &appData.loadPositionFile, "", NULL, FileName, _("File with Start Positions:") },
1089 { 0, -2, 1000000000, NULL, (void*) &appData.loadPositionIndex, "", NULL, Spin, _("Position Number (-1 or -2 = Auto-Increment):") },
1090 { 0,  0, 1000000000, NULL, (void*) &appData.rewindIndex, "", NULL, Spin, _("Rewind Index after this many Games (0 = never):") },
1091 { 0, 0, 0, NULL, NULL, "", NULL, EndMark , "" }
1092 };
1093
1094 void GeneralOptionsOK(int n)
1095 {
1096         int newPonder = appData.ponderNextMove;
1097         appData.ponderNextMove = oldPonder;
1098         PonderNextMoveEvent(newPonder);
1099 }
1100
1101 Option generalOptions[] = {
1102 { 0,  0, 0, NULL, (void*) &appData.alwaysPromoteToQueen, "", NULL, CheckBox, _("Always Queen") },
1103 { 0,  0, 0, NULL, (void*) &appData.animateDragging, "", NULL, CheckBox, _("Animate Dragging") },
1104 { 0,  0, 0, NULL, (void*) &appData.animate, "", NULL, CheckBox, _("Animate Moving") },
1105 { 0,  0, 0, NULL, (void*) &appData.autoCallFlag, "", NULL, CheckBox, _("Auto Flag") },
1106 { 0,  0, 0, NULL, (void*) &appData.autoFlipView, "", NULL, CheckBox, _("Auto Flip View") },
1107 { 0,  0, 0, NULL, (void*) &appData.blindfold, "", NULL, CheckBox, _("Blindfold") },
1108 { 0,  0, 0, NULL, (void*) &appData.dropMenu, "", NULL, CheckBox, _("Drop Menu") },
1109 { 0,  0, 0, NULL, (void*) &appData.highlightDragging, "", NULL, CheckBox, _("Highlight Dragging (Show Move Targets)") },
1110 { 0,  0, 0, NULL, (void*) &appData.highlightLastMove, "", NULL, CheckBox, _("Highlight Last Move") },
1111 { 0,  0, 0, NULL, (void*) &appData.highlightMoveWithArrow, "", NULL, CheckBox, _("Highlight with Arrow") },
1112 { 0,  0, 0, NULL, (void*) &appData.ringBellAfterMoves, "", NULL, CheckBox, _("Move Sound") },
1113 { 0,  0, 0, NULL, (void*) &appData.oneClick, "", NULL, CheckBox, _("One-Click Moving") },
1114 { 0,  0, 0, NULL, (void*) &appData.periodicUpdates, "", NULL, CheckBox, _("Periodic Updates (in Analysis Mode)") },
1115 { 0,  0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, _("Ponder Next Move") },
1116 { 0,  0, 0, NULL, (void*) &appData.popupExitMessage, "", NULL, CheckBox, _("Popup Exit Messages") },
1117 { 0,  0, 0, NULL, (void*) &appData.popupMoveErrors, "", NULL, CheckBox, _("Popup Move Errors") },
1118 { 0,  0, 0, NULL, (void*) &appData.showCoords, "", NULL, CheckBox, _("Show Coordinates") },
1119 { 0,  0, 0, NULL, (void*) &appData.markers, "", NULL, CheckBox, _("Show Target Squares") },
1120 { 0,  0, 0, NULL, (void*) &appData.hideThinkingFromHuman, "", NULL, CheckBox, _("Hide Thinking from Human") },
1121 { 0,  0, 0, NULL, (void*) &appData.testLegality, "", NULL, CheckBox, _("Test Legality") },
1122 { 0, 0, 10, NULL, (void*) &appData.flashCount, "", NULL, Spin, _("Flash Moves (0 = no flashing):") },
1123 { 0, 1, 10, NULL, (void*) &appData.flashRate, "", NULL, Spin, _("Flash Rate (high = fast):") },
1124 { 0, 5, 100,NULL, (void*) &appData.animSpeed, "", NULL, Spin, _("Animation Speed (high = slow):") },
1125 { 0,  0, 0, NULL, (void*) &GeneralOptionsOK, "", NULL, EndMark , "" }
1126 };
1127
1128 void Pick(int n)
1129 {
1130         VariantClass v = currentOption[n].value;
1131         if(!appData.noChessProgram) {
1132             char *name = VariantName(v), buf[MSG_SIZ];
1133             if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
1134                 /* [HGM] in protocol 2 we check if variant is suported by engine */
1135               snprintf(buf, MSG_SIZ,  _("Variant %s not supported by %s"), name, first.tidy);
1136                 DisplayError(buf, 0);
1137                 return; /* ignore OK if first engine does not support it */
1138             } else
1139             if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
1140               snprintf(buf, MSG_SIZ,  _("Warning: second engine (%s) does not support this!"), second.tidy);
1141                 DisplayError(buf, 0);   /* use of second engine is optional; only warn user */
1142             }
1143         }
1144
1145         GenericReadout(); // make sure ranks and file settings are read
1146
1147         gameInfo.variant = v;
1148         appData.variant = VariantName(v);
1149
1150         shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
1151         startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
1152         appData.pieceToCharTable = NULL;
1153         appData.pieceNickNames = "";
1154         appData.colorNickNames = "";
1155         Reset(True, True);
1156         PopDown(0);
1157         return;
1158 }
1159
1160 Option variantDescriptors[] = {
1161 { VariantNormal, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("normal")},
1162 { VariantFairy, 1, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("fairy")},
1163 { VariantFischeRandom, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("FRC")},
1164 { VariantSChess, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Seirawan")},
1165 { VariantWildCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("wild castle")},
1166 { VariantSuper, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Superchess")},
1167 { VariantNoCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("no castle")},
1168 { VariantCrazyhouse, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("crazyhouse")},
1169 { VariantKnightmate, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("knightmate")},
1170 { VariantBughouse, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("bughouse")},
1171 { VariantBerolina, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("berolina")},
1172 { VariantShogi, 1, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("shogi (9x9)")},
1173 { VariantCylinder, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("cylinder")},
1174 { VariantXiangqi, 1, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("xiangqi (9x10)")},
1175 { VariantShatranj, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("shatranj")},
1176 { VariantCourier, 1, 135, NULL, (void*) &Pick, "#BFFFBF", NULL, Button, N_("courier (12x8)")},
1177 { VariantMakruk, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("makruk")},
1178 { VariantGreat, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Great Shatranj (10x8)")},
1179 { VariantAtomic, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("atomic")},
1180 { VariantCapablanca, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Capablanca (10x8)")},
1181 { VariantTwoKings, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("two kings")},
1182 { VariantGothic, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Gothic (10x8)")},
1183 { Variant3Check, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("3-checks")},
1184 { VariantJanus, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("janus (10x8)")},
1185 { VariantSuicide, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("suicide")},
1186 { VariantCapaRandom, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("CRC (10x8)")},
1187 { VariantGiveaway, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("give-away")},
1188 { VariantSpartan, 1, 135, NULL, (void*) &Pick, "#FF0000", NULL, Button, N_("Spartan")},
1189 { VariantLosers, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("losers")},
1190 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, _("Board size ( -1 = default for selected variant):")},
1191 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.NrRanks, "", NULL, Spin, N_("Number of Board Ranks:") },
1192 { 0, -1, BOARD_FILES, NULL, (void*) &appData.NrFiles, "", NULL, Spin, N_("Number of Board Files:") },
1193 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.holdingsSize, "", NULL, Spin, N_("Holdings Size:") },
1194 { 0, 0, 0, NULL, NULL, NULL, NULL, Label,
1195                                 _("WARNING: variants with un-orthodox\n"
1196                                   "pieces only have built-in bitmaps\n"
1197                                   "for -boardSize middling, bulky and\n"
1198                                   "petite, and substitute king or amazon\n"
1199                                   "for missing bitmaps. (See manual.)")},
1200 { 0, 2, 0, NULL, NULL, "", NULL, EndMark , "" }
1201 };
1202
1203 void CommonOptionsOK(int n)
1204 {
1205         int newPonder = appData.ponderNextMove;
1206         // make sure changes are sent to first engine by re-initializing it
1207         // if it was already started pre-emptively at end of previous game
1208         if(gameMode == BeginningOfGame) Reset(True, True); else {
1209             // Some changed setting need immediate sending always.
1210             if(oldCores != appData.smpCores)
1211                 NewSettingEvent(False, &(first.maxCores), "cores", appData.smpCores);
1212             appData.ponderNextMove = oldPonder;
1213             PonderNextMoveEvent(newPonder);
1214         }
1215 }
1216
1217 Option commonEngineOptions[] = {
1218 { 0,     0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, _("Ponder Next Move") },
1219 { 0,  0, 1000, NULL, (void*) &appData.smpCores, "", NULL, Spin, _("Maximum Number of CPUs per Engine:") },
1220 { 0,     0, 0, NULL, (void*) &appData.polyglotDir, "", NULL, PathName, _("Polygot Directory:") },
1221 { 0, 0, 16000, NULL, (void*) &appData.defaultHashSize, "", NULL, Spin, _("Hash-Table Size (MB):") },
1222 { 0,     0, 0, NULL, (void*) &appData.defaultPathEGTB, "", NULL, PathName, _("Nalimov EGTB Path:") },
1223 { 0,  0, 1000, NULL, (void*) &appData.defaultCacheSizeEGTB, "", NULL, Spin, _("EGTB Cache Size (MB):") },
1224 { 0,     0, 0, NULL, (void*) &appData.usePolyglotBook, "", NULL, CheckBox, _("Use GUI Book") },
1225 { 0,     0, 0, NULL, (void*) &appData.polyglotBook, "", NULL, FileName, _("Opening-Book Filename:") },
1226 { 0,   0, 100, NULL, (void*) &appData.bookDepth, "", NULL, Spin, _("Book Depth (moves):") },
1227 { 0,   0, 100, NULL, (void*) &appData.bookStrength, "", NULL, Spin, _("Book Variety (0) vs. Strength (100):") },
1228 { 0,     0, 0, NULL, (void*) &appData.firstHasOwnBookUCI, "", NULL, CheckBox, _("Engine #1 Has Own Book") },
1229 { 0,     0, 0, NULL, (void*) &appData.secondHasOwnBookUCI, "", NULL, CheckBox, _("Engine #2 Has Own Book          ") },
1230 { 0,     1, 0, NULL, (void*) &CommonOptionsOK, "", NULL, EndMark , "" }
1231 };
1232
1233 Option adjudicationOptions[] = {
1234 { 0, 0,    0, NULL, (void*) &appData.checkMates, "", NULL, CheckBox, _("Detect all Mates") },
1235 { 0, 0,    0, NULL, (void*) &appData.testClaims, "", NULL, CheckBox, _("Verify Engine Result Claims") },
1236 { 0, 0,    0, NULL, (void*) &appData.materialDraws, "", NULL, CheckBox, _("Draw if Insufficient Mating Material") },
1237 { 0, 0,    0, NULL, (void*) &appData.trivialDraws, "", NULL, CheckBox, _("Adjudicate Trivial Draws (3-Move Delay)") },
1238 { 0, 0,  100, NULL, (void*) &appData.ruleMoves, "", NULL, Spin, _("N-Move Rule:") },
1239 { 0, 0,    6, NULL, (void*) &appData.drawRepeats, "", NULL, Spin, _("N-fold Repeats:") },
1240 { 0, 0, 1000, NULL, (void*) &appData.adjudicateDrawMoves, "", NULL, Spin, _("Draw after N Moves Total:") },
1241 { 0,-5000, 0, NULL, (void*) &appData.adjudicateLossThreshold, "", NULL, Spin, _("Win / Loss Threshold:") },
1242 { 0, 0,    0, NULL, (void*) &first.scoreIsAbsolute, "", NULL, CheckBox, _("Negate Score of Engine #1") },
1243 { 0, 0,    0, NULL, (void*) &second.scoreIsAbsolute, "", NULL, CheckBox, _("Negate Score of Engine #2") },
1244 { 0, 1,    0, NULL, NULL, "", NULL, EndMark , "" }
1245 };
1246
1247 void IcsOptionsOK(int n)
1248 {
1249     ParseIcsTextColors();
1250 }
1251
1252 Option icsOptions[] = {
1253 { 0, 0, 0, NULL, (void*) &appData.autoKibitz, "",  NULL, CheckBox, _("Auto-Kibitz") },
1254 { 0, 0, 0, NULL, (void*) &appData.autoComment, "", NULL, CheckBox, _("Auto-Comment") },
1255 { 0, 0, 0, NULL, (void*) &appData.autoObserve, "", NULL, CheckBox, _("Auto-Observe") },
1256 { 0, 0, 0, NULL, (void*) &appData.autoRaiseBoard, "", NULL, CheckBox, _("Auto-Raise Board") },
1257 { 0, 0, 0, NULL, (void*) &appData.bgObserve, "",   NULL, CheckBox, _("Background Observe while Playing") },
1258 { 0, 0, 0, NULL, (void*) &appData.dualBoard, "",   NULL, CheckBox, _("Dual Board for Background-Observed Game") },
1259 { 0, 0, 0, NULL, (void*) &appData.getMoveList, "", NULL, CheckBox, _("Get Move List") },
1260 { 0, 0, 0, NULL, (void*) &appData.quietPlay, "",   NULL, CheckBox, _("Quiet Play") },
1261 { 0, 0, 0, NULL, (void*) &appData.seekGraph, "",   NULL, CheckBox, _("Seek Graph") },
1262 { 0, 0, 0, NULL, (void*) &appData.autoRefresh, "", NULL, CheckBox, _("Auto-Refresh Seek Graph") },
1263 { 0, 0, 0, NULL, (void*) &appData.premove, "",     NULL, CheckBox, _("Premove") },
1264 { 0, 0, 0, NULL, (void*) &appData.premoveWhite, "", NULL, CheckBox, _("Premove for White") },
1265 { 0, 0, 0, NULL, (void*) &appData.premoveWhiteText, "", NULL, TextBox, _("First White Move:") },
1266 { 0, 0, 0, NULL, (void*) &appData.premoveBlack, "", NULL, CheckBox, _("Premove for Black") },
1267 { 0, 0, 0, NULL, (void*) &appData.premoveBlackText, "", NULL, TextBox, _("First Black Move:") },
1268 { 0, 0, 0, NULL, NULL, NULL, NULL, Break, "" },
1269 { 0, 0, 0, NULL, (void*) &appData.icsAlarm, "", NULL, CheckBox, _("Alarm") },
1270 { 0, 0, 100000000, NULL, (void*) &appData.icsAlarmTime, "", NULL, Spin, _("Alarm Time (msec):") },
1271 //{ 0, 0, 0, NULL, (void*) &appData.chatBoxes, "", NULL, TextBox, _("Startup Chat Boxes:") },
1272 { 0, 0, 0, NULL, (void*) &appData.colorize, "", NULL, CheckBox, _("Colorize Messages") },
1273 { 0, 0, 0, NULL, (void*) &appData.colorShout, "", NULL, TextBox, _("Shout Text Colors:") },
1274 { 0, 0, 0, NULL, (void*) &appData.colorSShout, "", NULL, TextBox, _("S-Shout Text Colors:") },
1275 { 0, 0, 0, NULL, (void*) &appData.colorChannel1, "", NULL, TextBox, _("Channel #1 Text Colors:") },
1276 { 0, 0, 0, NULL, (void*) &appData.colorChannel, "", NULL, TextBox, _("Other Channel Text Colors:") },
1277 { 0, 0, 0, NULL, (void*) &appData.colorKibitz, "", NULL, TextBox, _("Kibitz Text Colors:") },
1278 { 0, 0, 0, NULL, (void*) &appData.colorTell, "", NULL, TextBox, _("Tell Text Colors:") },
1279 { 0, 0, 0, NULL, (void*) &appData.colorChallenge, "", NULL, TextBox, _("Challenge Text Colors:") },
1280 { 0, 0, 0, NULL, (void*) &appData.colorRequest, "", NULL, TextBox, _("Request Text Colors:") },
1281 { 0, 0, 0, NULL, (void*) &appData.colorSeek, "", NULL, TextBox, _("Seek Text Colors:") },
1282 { 0, 0, 0, NULL, (void*) &IcsOptionsOK, "", NULL, EndMark , "" }
1283 };
1284
1285 Option loadOptions[] = {
1286 { 0, 0, 0, NULL, (void*) &appData.autoDisplayTags, "", NULL, CheckBox, _("Auto-Display Tags") },
1287 { 0, 0, 0, NULL, (void*) &appData.autoDisplayComment, "", NULL, CheckBox, _("Auto-Display Comment") },
1288 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, _("Auto-Play speed of loaded games\n(0 = instant, -1 = off):") },
1289 { 0, -1, 10000000, NULL, (void*) &appData.timeDelay, "", NULL, Fractional, _("Seconds per Move:") },
1290 { 0,  0, 0, NULL, NULL, "", NULL, EndMark , "" }
1291 };
1292
1293 Option saveOptions[] = {
1294 { 0, 0, 0, NULL, (void*) &appData.autoSaveGames, "", NULL, CheckBox, _("Auto-Save Games") },
1295 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, "", NULL, FileName,  _("Save Games on File:") },
1296 { 0, 0, 0, NULL, (void*) &appData.savePositionFile, "", NULL, FileName,  _("Save Final Positions on File:") },
1297 { 0, 0, 0, NULL, (void*) &appData.pgnEventHeader, "", NULL, TextBox,  _("PGN Event Header:") },
1298 { 0, 0, 0, NULL, (void*) &appData.oldSaveStyle, "", NULL, CheckBox, _("Old Save Style (as opposed to PGN)") },
1299 { 0, 0, 0, NULL, (void*) &appData.saveExtendedInfoInPGN, "", NULL, CheckBox, _("Save Score/Depth Info in PGN") },
1300 { 0, 0, 0, NULL, (void*) &appData.saveOutOfBookInfo, "", NULL, CheckBox, _("Save Out-of-Book Info in PGN           ") },
1301 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
1302 };
1303
1304 char *soundNames[] = {
1305         N_("No Sound"),
1306         N_("Default Beep"),
1307         N_("Above WAV File"),
1308         N_("Ching"),
1309         N_("Click"),
1310         N_("Ding"),
1311         N_("Gong"),
1312         N_("Laser"),
1313         N_("Penalty"),
1314         N_("Phone"),
1315         N_("Thud"),
1316         N_("Challenge"),
1317         N_("Tell"),
1318         NULL,
1319         N_("User File")
1320 };
1321
1322 char *soundFiles[] = { // sound files corresponding to above names
1323         "",
1324         "$",
1325         "*", // kludge alert: as first thing in the dialog readout this is replaced with the user-given .WAV filename
1326         "ching.wav",
1327         "click.wav",
1328         "ding1.wav",
1329         "gong.wav",
1330         "laser.wav",
1331         "penalty.wav",
1332         "phone.wav",
1333         "thud.wav",
1334         "challenge.wav",
1335         "tell.wav",
1336         NULL,
1337         NULL
1338 };
1339
1340 void Test(int n)
1341 {
1342     if(soundFiles[values[3]]) PlaySound(soundFiles[values[3]]);
1343 }
1344
1345 Option soundOptions[] = {
1346 { 0, 0, 0, NULL, (void*) &appData.soundProgram, "", NULL, TextBox, _("Sound Program:") },
1347 { 0, 0, 0, NULL, (void*) &appData.soundDirectory, "", NULL, PathName, _("Sounds Directory:") },
1348 { 0, 0, 0, NULL, (void*) (soundFiles+2) /* kludge! */, "", NULL, FileName, _("User WAV File:") },
1349 { 0, 0, 0, NULL, (void*) &trialSound, (char*) soundNames, soundFiles, ComboBox, _("Try-Out Sound:") },
1350 { 0, 1, 0, NULL, (void*) &Test, NULL, NULL, Button, _("Play") },
1351 { 0, 0, 0, NULL, (void*) &appData.soundMove, (char*) soundNames, soundFiles, ComboBox, _("Move:") },
1352 { 0, 0, 0, NULL, (void*) &appData.soundIcsWin, (char*) soundNames, soundFiles, ComboBox, _("Win:") },
1353 { 0, 0, 0, NULL, (void*) &appData.soundIcsLoss, (char*) soundNames, soundFiles, ComboBox, _("Lose:") },
1354 { 0, 0, 0, NULL, (void*) &appData.soundIcsDraw, (char*) soundNames, soundFiles, ComboBox, _("Draw:") },
1355 { 0, 0, 0, NULL, (void*) &appData.soundIcsUnfinished, (char*) soundNames, soundFiles, ComboBox, _("Unfinished:") },
1356 { 0, 0, 0, NULL, (void*) &appData.soundIcsAlarm, (char*) soundNames, soundFiles, ComboBox, _("Alarm:") },
1357 { 0, 0, 0, NULL, (void*) &appData.soundShout, (char*) soundNames, soundFiles, ComboBox, _("Shout:") },
1358 { 0, 0, 0, NULL, (void*) &appData.soundSShout, (char*) soundNames, soundFiles, ComboBox, _("S-Shout:") },
1359 { 0, 0, 0, NULL, (void*) &appData.soundChannel, (char*) soundNames, soundFiles, ComboBox, _("Channel:") },
1360 { 0, 0, 0, NULL, (void*) &appData.soundChannel1, (char*) soundNames, soundFiles, ComboBox, _("Channel 1:") },
1361 { 0, 0, 0, NULL, (void*) &appData.soundTell, (char*) soundNames, soundFiles, ComboBox, _("Tell:") },
1362 { 0, 0, 0, NULL, (void*) &appData.soundKibitz, (char*) soundNames, soundFiles, ComboBox, _("Kibitz:") },
1363 { 0, 0, 0, NULL, (void*) &appData.soundChallenge, (char*) soundNames, soundFiles, ComboBox, _("Challenge:") },
1364 { 0, 0, 0, NULL, (void*) &appData.soundRequest, (char*) soundNames, soundFiles, ComboBox, _("Request:") },
1365 { 0, 0, 0, NULL, (void*) &appData.soundSeek, (char*) soundNames, soundFiles, ComboBox, _("Seek:") },
1366 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
1367 };
1368
1369 void SetColor(char *colorName, Widget box)
1370 {
1371         Arg args[5];
1372         Pixel buttonColor;
1373         XrmValue vFrom, vTo;
1374         if (!appData.monoMode) {
1375             vFrom.addr = (caddr_t) colorName;
1376             vFrom.size = strlen(colorName);
1377             XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1378             if (vTo.addr == NULL) {
1379                 buttonColor = (Pixel) -1;
1380             } else {
1381                 buttonColor = *(Pixel *) vTo.addr;
1382             }
1383         }
1384         XtSetArg(args[0], XtNbackground, buttonColor);;
1385         XtSetValues(box, args, 1);
1386 }
1387
1388 void AdjustColor(int i)
1389 {
1390     int n = currentOption[i].value, col, j, r, g, b, step = 10;
1391     char *s, buf[MSG_SIZ]; // color string
1392     Arg args[5];
1393     XtSetArg(args[0], XtNstring, &s);
1394     XtGetValues(currentOption[i-n-1].handle, args, 1);
1395     if(sscanf(s, "#%x", &col) != 1) return;   // malformed
1396     b = col & 0xFF; g = col & 0xFF00; r = col & 0xFF0000;
1397     switch(n) {
1398         case 1: g -= 0x100*step; b -= step; break;
1399         case 2: r -= 0x10000*step; b -= step; break;
1400         case 3: g -= 0x100*step; r -= 0x10000*step; break;
1401         case 4: r += 0x10000*step; g += 0x100*step; b += step; break;
1402     }
1403     if(r < 0) r = 0; if(g < 0) g = 0; if(b < 0) b = 0;
1404     if(r > 0xFF0000) r = 0xFF0000; if(g > 0xFF00) g = 0xFF00; if(b > 0xFF) b = 0xFF;
1405     col = r | g | b;
1406     snprintf(buf, MSG_SIZ, "#%06x", col);
1407     for(j=1; j<7; j++) if(buf[j] >= 'a') buf[j] -= 32; // capitalize
1408     SetColor(buf, currentOption[i-n].handle);
1409     XtSetArg(args[0], XtNstring, buf);
1410     XtSetValues(currentOption[i-n-1].handle, args, 1);
1411 }
1412
1413 void BoardOptionsOK(int n)
1414 {
1415     if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap;
1416     MakeColors(); CreateGCs(True);
1417     CreateXPMPieces();
1418     CreateXPMBoard(appData.liteBackTextureFile, 1);
1419     CreateXPMBoard(appData.darkBackTextureFile, 0);
1420     InitDrawingSizes(-1, 0);
1421     DrawPosition(True, NULL);
1422 }
1423
1424 Option boardOptions[] = {
1425 { 0,   0, 70, NULL, (void*) &appData.whitePieceColor, "", NULL, TextBox, _("White Piece Color:") },
1426 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1427 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1428 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1429 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1430 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1431 { 0,   0, 70, NULL, (void*) &appData.blackPieceColor, "", NULL, TextBox, _("Black Piece Color:") },
1432 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1433 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1434 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1435 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1436 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1437 { 0,   0, 70, NULL, (void*) &appData.lightSquareColor, "", NULL, TextBox, _("Light Square Color:") },
1438 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1439 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1440 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1441 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1442 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1443 { 0,   0, 70, NULL, (void*) &appData.darkSquareColor, "", NULL, TextBox, _("Dark Square Color:") },
1444 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1445 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1446 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1447 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1448 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1449 { 0,   0, 70, NULL, (void*) &appData.highlightSquareColor, "", NULL, TextBox, _("Highlight Color:") },
1450 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1451 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1452 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1453 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1454 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1455 { 0,   0, 70, NULL, (void*) &appData.premoveHighlightColor, "", NULL, TextBox, _("Premove Highlight Color:") },
1456 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, "      " },
1457 {    1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1458 {    2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1459 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1460 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1461 { 0, 0, 0, NULL, (void*) &appData.upsideDown, "", NULL, CheckBox, _("Flip Pieces Shogi Style") },
1462 { 0, 0, 0, NULL, (void*) &appData.allWhite, "", NULL, CheckBox, _("Use Outline Pieces for Black") },
1463 { 0, 0, 0, NULL, (void*) &appData.monoMode, "", NULL, CheckBox, _("Mono Mode") },
1464 { 0,-1, 5, NULL, (void*) &appData.overrideLineGap, "", NULL, Spin, _("Line Gap ( -1 = default for board size):") },
1465 { 0, 0, 0, NULL, (void*) &appData.liteBackTextureFile, "", NULL, FileName, _("Light-Squares Texture File:") },
1466 { 0, 0, 0, NULL, (void*) &appData.darkBackTextureFile, "", NULL, FileName, _("Dark-Squares Texture File:") },
1467 { 0, 0, 0, NULL, (void*) &appData.bitmapDirectory, "", NULL, PathName, _("Directory with Bitmap Pieces:") },
1468 { 0, 0, 0, NULL, (void*) &appData.pixmapDirectory, "", NULL, PathName, _("Directory with Pixmap Pieces:") },
1469 { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" }
1470 };
1471
1472 void GenericReadout()
1473 {
1474     int i, j;
1475     String name, val;
1476     Arg args[16];
1477     char buf[MSG_SIZ];
1478     float x;
1479         for(i=0; ; i++) { // send all options that had to be OK-ed to engine
1480             switch(currentOption[i].type) {
1481                 case TextBox:
1482                 case FileName:
1483                 case PathName:
1484                     XtSetArg(args[0], XtNstring, &val);
1485                     XtGetValues(currentOption[i].handle, args, 1);
1486                     if(*(char**) currentOption[i].target == NULL || strcmp(*(char**) currentOption[i].target, val)) {
1487                         safeStrCpy(currentOption[i].name + 100, val, MSG_SIZ-100); // text value kept in pivate storage for each option
1488                         *(char**) currentOption[i].target = currentOption[i].name + 100; // option gets to point to that
1489                     }
1490                     break;
1491                 case Spin:
1492                 case Fractional:
1493                     XtSetArg(args[0], XtNstring, &val);
1494                     XtGetValues(currentOption[i].handle, args, 1);
1495                     sscanf(val, "%f", &x);
1496                     if(x > currentOption[i].max) x = currentOption[i].max;
1497                     if(x < currentOption[i].min) x = currentOption[i].min;
1498                     if(currentOption[i].value != x) {
1499                         currentOption[i].value = x;
1500                         if(currentOption[i].type == Spin) *(int*) currentOption[i].target = x;
1501                         else *(float*) currentOption[i].target = x;
1502                     }
1503                     break;
1504                 case CheckBox:
1505                     j = 0;
1506                     XtSetArg(args[0], XtNstate, &j);
1507                     XtGetValues(currentOption[i].handle, args, 1);
1508                     if(currentOption[i].value != j) {
1509                         currentOption[i].value = j;
1510                         *(Boolean*) currentOption[i].target = j;
1511                     }
1512                     break;
1513                 case ComboBox:
1514                     val = ((char**)currentOption[i].choice)[values[i]];
1515                     if(val && (*(char**) currentOption[i].target == NULL || strcmp(*(char**) currentOption[i].target, val))) {
1516                       if(*(char**) currentOption[i].target) free(*(char**) currentOption[i].target);
1517                       *(char**) currentOption[i].target = strdup(val);
1518                     }
1519                     break;
1520                 case EndMark:
1521                     if(currentOption[i].target) // callback for implementing necessary actions on OK (like redraw)
1522                         ((ButtonCallback*) currentOption[i].target)(i);
1523                     break;
1524             default:
1525                 printf("GenericReadout: unexpected case in switch.\n");
1526                 case Button:
1527                 case Label:
1528               break;
1529             }
1530             if(currentOption[i].type == EndMark) break;
1531         }
1532 }
1533
1534 void GenericCallback(w, client_data, call_data)
1535      Widget w;
1536      XtPointer client_data, call_data;
1537 {
1538     String name, val;
1539     Arg args[16];
1540     char buf[MSG_SIZ];
1541     int i, j;
1542     int data = (intptr_t) client_data;
1543
1544     currentOption = dialogOptions[data>>16]; data &= 0xFFFF;
1545
1546     XtSetArg(args[0], XtNlabel, &name);
1547     XtGetValues(w, args, 1);
1548
1549     if (strcmp(name, _("cancel")) == 0) {
1550         PopDown(data);
1551         return;
1552     }
1553     if (strcmp(name, _("OK")) == 0) { // save buttons imply OK
1554         GenericReadout();
1555         PopDown(data);
1556         return;
1557     }
1558     if(currentOption[data].textValue);
1559     ((ButtonCallback*) currentOption[data].target)(data);
1560 }
1561
1562 int
1563 GenericPopUp(Option *option, char *title, int dlgNr)
1564 {
1565     Arg args[16];
1566     Widget popup, layout, dialog, edit=NULL, form,  last, b_ok, b_cancel, leftMargin = NULL, textField = NULL;
1567     Window root, child;
1568     int x, y, i, j, height=999, width=1, h, c, w;
1569     int win_x, win_y, maxWidth, maxTextWidth;
1570     unsigned int mask;
1571     char def[MSG_SIZ], *msg;
1572     static char pane[6] = "paneX";
1573     Widget texts[100], forelast = NULL, anchor, widest, lastrow = NULL;
1574
1575     if(shellUp[dlgNr]) return 0; // already up
1576     if(dlgNr && shells[dlgNr]) {
1577         XtPopup(shells[dlgNr], XtGrabNone);
1578         shellUp[dlgNr] = True;
1579         return 0;
1580     }
1581
1582     dialogOptions[dlgNr] = option; // make available to callback
1583     // kludge: fake address of a ChessProgramState struct that contains the options, so Spin and Combo callbacks work on it
1584     // WARNING: this kludge does not work for persistent dialogs, so that these cannot have spin or combo controls!
1585     currentCps = (ChessProgramState *) ((char *) option - ((char *)&first.option - (char *)&first));
1586
1587 //    if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1;
1588 //    height = cps->nrOptions / width + 1;
1589      i = 0;
1590     XtSetArg(args[i], XtNresizable, True); i++;
1591     popup = shells[dlgNr] =
1592       XtCreatePopupShell(title, transientShellWidgetClass,
1593                          shellWidget, args, i);
1594
1595     layout =
1596       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1597                             layoutArgs, XtNumber(layoutArgs));
1598   for(c=0; c<width; c++) {
1599     pane[4] = 'A'+c;
1600     form =
1601       XtCreateManagedWidget(pane, formWidgetClass, layout,
1602                             formArgs, XtNumber(formArgs));
1603     j=0;
1604     XtSetArg(args[j], XtNfromHoriz, leftMargin);  j++;
1605     XtSetValues(form, args, j);
1606     leftMargin = form;
1607
1608     last = widest = NULL; anchor = lastrow;
1609     for(h=0; h<height; h++) {
1610         i = h + c*height;
1611         if(option[i].type == EndMark) break;
1612         lastrow = forelast;
1613         forelast = last;
1614         switch(option[i].type) {
1615           case Fractional:
1616             snprintf(def, MSG_SIZ,  "%.2f", *(float*)option[i].target);
1617             option[i].value = *(float*)option[i].target;
1618             goto tBox;
1619           case Spin:
1620             snprintf(def, MSG_SIZ,  "%d", option[i].value = *(int*)option[i].target);
1621           case TextBox:
1622           case FileName:
1623           case PathName:
1624           tBox:
1625             if(option[i].name[0]) {
1626             j=0;
1627             XtSetArg(args[j], XtNfromVert, last);  j++;
1628             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1629             XtSetArg(args[j], XtNright, XtChainLeft); j++;
1630             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1631             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1632             texts[h] =
1633             dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
1634             } else texts[h] = dialog = NULL;
1635             w = option[i].type == Spin || option[i].type == Fractional ? 70 : option[i].max ? option[i].max : 205;
1636             if(option[i].type == FileName || option[i].type == PathName) w -= 55;
1637             j=0;
1638             XtSetArg(args[j], XtNfromVert, last);  j++;
1639             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1640             XtSetArg(args[j], XtNborderWidth, 1); j++;
1641             XtSetArg(args[j], XtNwidth, w); j++;
1642             if(option[i].type == TextBox && option[i].min) {
1643                 XtSetArg(args[j], XtNheight, option[i].min); j++;
1644                 if(option[i].value & 1) { XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways);  j++; }
1645                 if(option[i].value & 2) { XtSetArg(args[j], XtNscrollHorizontal, XawtextScrollAlways);  j++; }
1646                 if(option[i].value & 4) { XtSetArg(args[j], XtNautoFill, True);  j++; }
1647                 if(option[i].value & 8) { XtSetArg(args[j], XtNwrap, XawtextWrapWord); j++; }
1648             }
1649             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1650             XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
1651             XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
1652             XtSetArg(args[j], XtNdisplayCaret, False);  j++;
1653             XtSetArg(args[j], XtNright, XtChainRight);  j++;
1654             XtSetArg(args[j], XtNresizable, True);  j++;
1655             XtSetArg(args[j], XtNstring, option[i].type==Spin || option[i].type==Fractional ? def : *(char**)option[i].target);  j++;
1656             XtSetArg(args[j], XtNinsertPosition, 9999);  j++;
1657             edit = last;
1658             option[i].handle = (void*)
1659                 (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1660             XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1661
1662             if(option[i].type == TextBox || option[i].type == Fractional) break;
1663
1664             // add increment and decrement controls for spin
1665             j=0;
1666             XtSetArg(args[j], XtNfromVert, edit);  j++;
1667             XtSetArg(args[j], XtNfromHoriz, last);  j++;
1668             XtSetArg(args[j], XtNleft, XtChainRight); j++;
1669             XtSetArg(args[j], XtNright, XtChainRight); j++;
1670             if(option[i].type == FileName || option[i].type == PathName) {
1671                 w = 50; msg = "browse";
1672             } else {
1673                 XtSetArg(args[j], XtNheight, 10);  j++;
1674                 w = 20; msg = "+";
1675             }
1676             XtSetArg(args[j], XtNwidth, w);  j++;
1677             edit = XtCreateManagedWidget(msg, commandWidgetClass, form, args, j);
1678             XtAddCallback(edit, XtNcallback, SpinCallback,
1679                           (XtPointer)(intptr_t) i);
1680
1681             if(option[i].type != Spin) break;
1682
1683             j=0;
1684             XtSetArg(args[j], XtNfromVert, edit);  j++;
1685             XtSetArg(args[j], XtNfromHoriz, last);  j++;
1686             XtSetArg(args[j], XtNheight, 10);  j++;
1687             XtSetArg(args[j], XtNwidth, 20);  j++;
1688             XtSetArg(args[j], XtNleft, XtChainRight); j++;
1689             XtSetArg(args[j], XtNright, XtChainRight); j++;
1690             last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1691             XtAddCallback(last, XtNcallback, SpinCallback,
1692                           (XtPointer)(intptr_t) i);
1693             break;
1694           case CheckBox:
1695             j=0;
1696             XtSetArg(args[j], XtNfromVert, last);  j++;
1697             XtSetArg(args[j], XtNwidth, 10);  j++;
1698             XtSetArg(args[j], XtNheight, 10);  j++;
1699             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1700             XtSetArg(args[j], XtNright, XtChainLeft); j++;
1701             XtSetArg(args[j], XtNstate, option[i].value = *(Boolean*)option[i].target);  j++;
1702             option[i].handle = (void*)
1703                 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1704           case Label:
1705             msg = option[i].name;
1706             if(*msg == NULLCHAR) msg = option[i].textValue;
1707             if(!msg) break;
1708             j=0;
1709             XtSetArg(args[j], XtNfromVert, last);  j++;
1710             XtSetArg(args[j], XtNfromHoriz, option[i].type != Label ? dialog : NULL);  j++;
1711             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1712             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1713             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1714             last = XtCreateManagedWidget(msg, labelWidgetClass, form, args, j);
1715             break;
1716           case Button:
1717             j=0;
1718             XtSetArg(args[j], XtNfromVert, option[i].min & 1 ? lastrow : last);  j++;
1719             if(option[i].min & 1) { XtSetArg(args[j], XtNfromHoriz, last);  j++; }
1720             else  { XtSetArg(args[j], XtNfromHoriz, NULL);  j++; lastrow = forelast; }
1721             if(option[i].max) XtSetArg(args[j], XtNwidth, option[i].max);  j++;
1722             if(option[i].textValue) { // special for buttons of New Variant dialog
1723                 XtSetArg(args[j], XtNsensitive, appData.noChessProgram || option[i].value < 0
1724                                          || strstr(first.variants, VariantName(option[i].value))); j++;
1725                 XtSetArg(args[j], XtNborderWidth, (gameInfo.variant == option[i].value)+1); j++;
1726             }
1727             option[i].handle = (void*)
1728                 (dialog = last = XtCreateManagedWidget(option[i].name, commandWidgetClass, form, args, j));
1729             if(option[i].target == NULL) SetColor( *(char**) option[i-1].target, last); else
1730             XtAddCallback(last, XtNcallback, GenericCallback,
1731                           (XtPointer)(intptr_t) i + (dlgNr<<16));
1732             if(option[i].textValue) SetColor( option[i].textValue, last);
1733             forelast = lastrow; // next button can go on same row
1734             break;
1735           case ComboBox:
1736             j=0;
1737             XtSetArg(args[j], XtNfromVert, last);  j++;
1738             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1739             XtSetArg(args[j], XtNright, XtChainLeft); j++;
1740             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1741             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1742             texts[h] = dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
1743
1744             for(j=0; option[i].choice[j]; j++)
1745                 if(*(char**)option[i].target && !strcmp(*(char**)option[i].target, option[i].choice[j])) break;
1746             option[i].value = j + (option[i].choice[j] == NULL);
1747
1748             j=0;
1749             XtSetArg(args[j], XtNfromVert, last);  j++;
1750             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1751             XtSetArg(args[j], XtNwidth, option[i].max ? option[i].max : 100);  j++;
1752             XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1753             XtSetArg(args[j], XtNmenuName, XtNewString(option[i].name));  j++;
1754             XtSetArg(args[j], XtNlabel, ((char**)option[i].textValue)[option[i].value]);  j++;
1755             option[i].handle = (void*)
1756                 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1757             CreateComboPopup(last, option[i].name, i, (char **) option[i].textValue);
1758             values[i] = option[i].value;
1759             break;
1760           case Break:
1761             width++;
1762             height = i+1;
1763             break;
1764         default:
1765             printf("GenericPopUp: unexpected case in switch.\n");
1766             break;
1767         }
1768     }
1769
1770     // make an attempt to align all spins and textbox controls
1771     maxWidth = maxTextWidth = 0;
1772     for(h=0; h<height; h++) {
1773         i = h + c*height;
1774         if(option[i].type == EndMark) break;
1775         if(option[i].type == Spin || option[i].type == TextBox || option[i].type == ComboBox
1776                                   || option[i].type == PathName || option[i].type == FileName) {
1777             Dimension w;
1778             if(!texts[h]) continue;
1779             j=0;
1780             XtSetArg(args[j], XtNwidth, &w);  j++;
1781             XtGetValues(texts[h], args, j);
1782             if(option[i].type == Spin) {
1783                 if(w > maxWidth) maxWidth = w;
1784                 widest = texts[h];
1785             } else {
1786                 if(w > maxTextWidth) maxTextWidth = w;
1787                 if(!widest) widest = texts[h];
1788             }
1789         }
1790     }
1791     if(maxTextWidth + 110 < maxWidth)
1792          maxTextWidth = maxWidth - 110;
1793     else maxWidth = maxTextWidth + 110;
1794     for(h=0; h<height; h++) {
1795         i = h + c*height;
1796         if(option[i].type == EndMark) break;
1797         if(!texts[h]) continue;
1798         j=0;
1799         if(option[i].type == Spin) {
1800             XtSetArg(args[j], XtNwidth, maxWidth);  j++;
1801             XtSetValues(texts[h], args, j);
1802         } else
1803         if(option[i].type == TextBox || option[i].type == ComboBox || option[i].type == PathName || option[i].type == FileName) {
1804             XtSetArg(args[j], XtNwidth, maxTextWidth);  j++;
1805             XtSetValues(texts[h], args, j);
1806         }
1807     }
1808   }
1809
1810   if(!(option[i].min & 2)) {
1811     j=0;
1812     if(option[i].min & 1) { XtSetArg(args[j], XtNfromHoriz, last); last = forelast; } else
1813     XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog);  j++;
1814     XtSetArg(args[j], XtNfromVert, anchor ? anchor : last);  j++;
1815     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
1816     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
1817     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
1818     XtSetArg(args[j], XtNright, XtChainRight);  j++;
1819     b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1820     XtAddCallback(b_ok, XtNcallback, GenericCallback, (XtPointer) dlgNr);
1821
1822     XtSetArg(args[0], XtNfromHoriz, b_ok);
1823     b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1824     XtAddCallback(b_cancel, XtNcallback, GenericCallback, (XtPointer) dlgNr);
1825   }
1826
1827     XtRealizeWidget(popup);
1828     XSetWMProtocols(xDisplay, XtWindow(popup), &wm_delete_window, 1);
1829     snprintf(def, MSG_SIZ, "<Message>WM_PROTOCOLS: GenericPopDown(\"%d\") \n", dlgNr);
1830     XtAugmentTranslations(popup, XtParseTranslationTable(def));
1831     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1832                   &x, &y, &win_x, &win_y, &mask);
1833
1834     XtSetArg(args[0], XtNx, x - 10);
1835     XtSetArg(args[1], XtNy, y - 30);
1836     XtSetValues(popup, args, 2);
1837
1838     XtPopup(popup, dlgNr ? XtGrabNone : XtGrabExclusive);
1839     shellUp[dlgNr] = True;
1840     previous = NULL;
1841     if(textField)SetFocus(textField, popup, (XEvent*) NULL, False);
1842     if(dlgNr && wp[dlgNr] && wp[dlgNr]->width > 0) { // if persistent window-info available, reposition
1843         j = 0;
1844         XtSetArg(args[j], XtNheight, (Dimension) (wp[dlgNr]->height));  j++;
1845         XtSetArg(args[j], XtNwidth,  (Dimension) (wp[dlgNr]->width));  j++;
1846         XtSetArg(args[j], XtNx, (Position) (wp[dlgNr]->x));  j++;
1847         XtSetArg(args[j], XtNy, (Position) (wp[dlgNr]->y));  j++;
1848         XtSetValues(popup, args, j);
1849     }
1850     return 1;
1851 }
1852
1853
1854 void IcsOptionsProc(w, event, prms, nprms)
1855      Widget w;
1856      XEvent *event;
1857      String *prms;
1858      Cardinal *nprms;
1859 {
1860    GenericPopUp(icsOptions, _("ICS Options"), 0);
1861 }
1862
1863 void LoadOptionsProc(w, event, prms, nprms)
1864      Widget w;
1865      XEvent *event;
1866      String *prms;
1867      Cardinal *nprms;
1868 {
1869    GenericPopUp(loadOptions, _("Load Game Options"), 0);
1870 }
1871
1872 void SaveOptionsProc(w, event, prms, nprms)
1873      Widget w;
1874      XEvent *event;
1875      String *prms;
1876      Cardinal *nprms;
1877 {
1878    GenericPopUp(saveOptions, _("Save Game Options"), 0);
1879 }
1880
1881 void SoundOptionsProc(w, event, prms, nprms)
1882      Widget w;
1883      XEvent *event;
1884      String *prms;
1885      Cardinal *nprms;
1886 {
1887    soundFiles[2] = "*";
1888    GenericPopUp(soundOptions, _("Sound Options"), 0);
1889 }
1890
1891 void BoardOptionsProc(w, event, prms, nprms)
1892      Widget w;
1893      XEvent *event;
1894      String *prms;
1895      Cardinal *nprms;
1896 {
1897    GenericPopUp(boardOptions, _("Board Options"), 0);
1898 }
1899
1900 void EngineMenuProc(w, event, prms, nprms)
1901      Widget w;
1902      XEvent *event;
1903      String *prms;
1904      Cardinal *nprms;
1905 {
1906    GenericPopUp(adjudicationOptions, "Adjudicate non-ICS Games", 0);
1907 }
1908
1909 void UciMenuProc(w, event, prms, nprms)
1910      Widget w;
1911      XEvent *event;
1912      String *prms;
1913      Cardinal *nprms;
1914 {
1915    oldCores = appData.smpCores;
1916    oldPonder = appData.ponderNextMove;
1917    GenericPopUp(commonEngineOptions, _("Common Engine Settings"), 0);
1918 }
1919
1920 void NewVariantProc(w, event, prms, nprms)
1921      Widget w;
1922      XEvent *event;
1923      String *prms;
1924      Cardinal *nprms;
1925 {
1926    GenericPopUp(variantDescriptors, _("New Variant"), 0);
1927 }
1928
1929 void OptionsProc(w, event, prms, nprms)
1930      Widget w;
1931      XEvent *event;
1932      String *prms;
1933      Cardinal *nprms;
1934 {
1935    oldPonder = appData.ponderNextMove;
1936    GenericPopUp(generalOptions, _("General Options"), 0);
1937 }
1938
1939 void MatchOptionsProc(w, event, prms, nprms)
1940      Widget w;
1941      XEvent *event;
1942      String *prms;
1943      Cardinal *nprms;
1944 {
1945    GenericPopUp(matchOptions, _("Match Options"), 0);
1946 }
1947
1948 //---------------------------- Chat Windows ----------------------------------------------
1949
1950 void OutputChatMessage(int partner, char *mess)
1951 {
1952     return; // dummy
1953 }
1954