Made the beep sounds for JAWS board navigation configurable through command-line...
[xboard.git] / xoptions.c
1 /*
2  * xoptions.c -- Move list window, part of X front end for XBoard
3  *
4  * Copyright 2000,2009 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
49 #include <X11/Intrinsic.h>
50 #include <X11/StringDefs.h>
51 #include <X11/Shell.h>
52 #include <X11/Xaw/Dialog.h>
53 #include <X11/Xaw/Form.h>
54 #include <X11/Xaw/List.h>
55 #include <X11/Xaw/Label.h>
56 #include <X11/Xaw/SimpleMenu.h>
57 #include <X11/Xaw/SmeBSB.h>
58 #include <X11/Xaw/SmeLine.h>
59 #include <X11/Xaw/Box.h>
60 #include <X11/Xaw/Paned.h>
61 #include <X11/Xaw/MenuButton.h>
62 #include <X11/cursorfont.h>
63 #include <X11/Xaw/Text.h>
64 #include <X11/Xaw/AsciiText.h>
65 #include <X11/Xaw/Viewport.h>
66 #include <X11/Xaw/Toggle.h>
67
68 #include "common.h"
69 #include "backend.h"
70 #include "xboard.h"
71 #include "gettext.h"
72
73 #ifdef ENABLE_NLS
74 # define  _(s) gettext (s)
75 # define N_(s) gettext_noop (s)
76 #else
77 # define  _(s) (s)
78 # define N_(s)  s
79 #endif
80
81 extern void SendToProgram P((char *message, ChessProgramState *cps));
82
83
84 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
85 extern Display *xDisplay;
86 extern int squareSize;
87 extern Pixmap xMarkPixmap;
88 extern char *layoutName;
89 extern Window xBoardWindow;
90 extern Arg layoutArgs[2], formArgs[2];
91 Pixel timerForegroundPixel, timerBackgroundPixel;
92
93 // [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines
94
95 static Widget previous = NULL;
96
97 void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
98 {
99     Arg args;
100
101     if(previous) {
102         XtSetArg(args, XtNdisplayCaret, False);
103         XtSetValues(previous, &args, 1);
104     }
105     XtSetArg(args, XtNdisplayCaret, True);
106     XtSetValues(w, &args, 1);
107     XtSetKeyboardFocus((Widget) data, w);
108     previous = w;
109 }
110
111 //--------------------------- New Shuffle Game --------------------------------------------
112 extern int shuffleOpenings;
113 extern int startedFromPositionFile;
114 int shuffleUp;
115 Widget shuffleShell;
116
117 void ShufflePopDown()
118 {
119     if (!shuffleUp) return;
120     XtPopdown(shuffleShell);
121     XtDestroyWidget(shuffleShell);
122     shuffleUp = False;
123     ModeHighlight();
124 }
125
126 void ShuffleCallback(w, client_data, call_data)
127      Widget w;
128      XtPointer client_data, call_data;
129 {
130     String name;
131     Widget w2;
132     Arg args[16];
133     char buf[80];
134     
135     XtSetArg(args[0], XtNlabel, &name);
136     XtGetValues(w, args, 1);
137     
138     if (strcmp(name, _("cancel")) == 0) {
139         ShufflePopDown();
140         return;
141     }
142     if (strcmp(name, _("off")) == 0) {
143         ShufflePopDown();
144         shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it!
145         ResetGameEvent();
146         AnalysisPopDown();
147         return;
148     }
149     if (strcmp(name, _("random")) == 0) {
150         sprintf(buf, "%d", rand());
151         XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
152         XtSetValues(XtParent(w), args, 1);
153         return;
154     }
155     if (strcmp(name, _("ok")) == 0) {
156         int nr; String name;
157         name = XawDialogGetValueString(w2 = XtParent(w));
158         if(sscanf(name ,"%d",&nr) != 1) {
159             sprintf(buf, "%d", appData.defaultFrcPosition);
160             XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
161             XtSetValues(w2, args, 1);
162             return;
163         }
164         appData.defaultFrcPosition = nr;
165         shuffleOpenings = True;
166         ShufflePopDown();
167         ResetGameEvent();
168         AnalysisPopDown();
169         return;
170     }
171 }
172
173 void ShufflePopUp()
174 {
175     Arg args[16];
176     Widget popup, layout, dialog, edit;
177     Window root, child;
178     int x, y, i;
179     int win_x, win_y;
180     unsigned int mask;
181     char def[80];
182     
183     i = 0;
184     XtSetArg(args[i], XtNresizable, True); i++;
185     XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
186     shuffleShell = popup =
187       XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass,
188                          shellWidget, args, i);
189     
190     layout =
191       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
192                             layoutArgs, XtNumber(layoutArgs));
193   
194     sprintf(def, "%d\n", appData.defaultFrcPosition);
195     i = 0;
196     XtSetArg(args[i], XtNlabel, _("Start-position number:")); i++;
197     XtSetArg(args[i], XtNvalue, def); i++;
198     XtSetArg(args[i], XtNborderWidth, 0); i++;
199     dialog = XtCreateManagedWidget(_("Shuffle"), dialogWidgetClass,
200                                    layout, args, i);
201     
202 //    XtSetArg(args[0], XtNeditType, XawtextEdit);  // [HGM] can't get edit to work decently
203 //    XtSetArg(args[1], XtNuseStringInPlace, False);
204 //    XtSetValues(dialog, args, 2);
205
206     XawDialogAddButton(dialog, _("ok"), ShuffleCallback, (XtPointer) dialog);
207     XawDialogAddButton(dialog, _("cancel"), ShuffleCallback, (XtPointer) dialog);
208     XawDialogAddButton(dialog, _("random"), ShuffleCallback, (XtPointer) dialog);
209     XawDialogAddButton(dialog, _("off"), ShuffleCallback, (XtPointer) dialog);
210     
211     XtRealizeWidget(popup);
212     CatchDeleteWindow(popup, "ShufflePopDown");
213     
214     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
215                   &x, &y, &win_x, &win_y, &mask);
216     
217     XtSetArg(args[0], XtNx, x - 10);
218     XtSetArg(args[1], XtNy, y - 30);
219     XtSetValues(popup, args, 2);
220     
221     XtPopup(popup, XtGrabExclusive);
222     shuffleUp = True;
223     
224     edit = XtNameToWidget(dialog, "*value");
225
226     XtSetKeyboardFocus(popup, edit);
227 }
228
229 void ShuffleMenuProc(w, event, prms, nprms)
230      Widget w;
231      XEvent *event;
232      String *prms;
233      Cardinal *nprms;
234 {
235 //    if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
236 //      Reset(FALSE, TRUE);
237 //    }
238     ShufflePopUp();
239 }
240
241 //--------------------------- Time-Control Menu Popup ----------------------------------
242 int TimeControlUp;
243 Widget TimeControlShell;
244 int tcInc;
245 Widget tcMess1, tcMess2, tcData, tcTime, tcOdds1, tcOdds2;
246 int tcIncrement, tcMoves;
247
248 void TimeControlPopDown()
249 {
250     if (!TimeControlUp) return;
251     XtPopdown(TimeControlShell);
252     XtDestroyWidget(TimeControlShell);
253     TimeControlUp = False;
254     ModeHighlight();
255 }
256
257 void TimeControlCallback(w, client_data, call_data)
258      Widget w;
259      XtPointer client_data, call_data;
260 {
261     String name, txt;
262     Widget w2;
263     Arg args[16];
264     char buf[80];
265     int j;
266
267     XtSetArg(args[0], XtNlabel, &name);
268     XtGetValues(w, args, 1);
269     
270     if (strcmp(name, _("classical")) == 0) {
271         if(!tcInc) return;
272         j=0;
273         XtSetArg(args[j], XtNlabel, _("minutes for each")); j++;
274         XtSetValues(tcMess1, args, j);
275         j=0;
276         XtSetArg(args[j], XtNlabel, _("moves")); j++;
277         XtSetValues(tcMess2, args, j);
278         j=0;
279         XtSetArg(args[j], XtNstring, &name); j++;
280         XtGetValues(tcData, args, j);
281         tcIncrement = 0; sscanf(name, "%d", &tcIncrement);
282         sprintf(buf, "%d", tcMoves);
283         j=0;
284         XtSetArg(args[j], XtNstring, buf); j++;
285         XtSetValues(tcData, args, j);
286         tcInc = False;
287         return;
288     }
289     if (strcmp(name, _("incremental")) == 0) {
290         if(tcInc) return;
291         j=0;
292         XtSetArg(args[j], XtNlabel, _("minutes, plus")); j++;
293         XtSetValues(tcMess1, args, j);
294         j=0;
295         XtSetArg(args[j], XtNlabel, _("sec/move")); j++;
296         XtSetValues(tcMess2, args, j);
297         j=0;
298         XtSetArg(args[j], XtNstring, &name); j++;
299         XtGetValues(tcData, args, j);
300         tcMoves = appData.movesPerSession; sscanf(name, "%d", &tcMoves);
301         sprintf(buf, "%d", tcIncrement);
302         j=0;
303         XtSetArg(args[j], XtNstring, buf); j++;
304         XtSetValues(tcData, args, j);
305         tcInc = True;
306         return;
307     }
308     if (strcmp(name, _(" OK ")) == 0) {
309         int inc, mps, tc, ok;
310         XtSetArg(args[0], XtNstring, &txt);
311         XtGetValues(tcData, args, 1);
312         if(tcInc) {
313             ok = sscanf(txt, "%d", &inc); mps = 0;
314             if(!ok && txt[0] == 0) { inc = 0; ok = 1; } // accept empty string as zero
315             ok &= (inc >= 0);
316         } else {
317             ok = sscanf(txt, "%d", &mps); inc = -1;
318             ok &= (mps > 0);
319         }
320         if(ok != 1) {
321             XtSetArg(args[0], XtNstring, ""); // erase any offending input
322             XtSetValues(tcData, args, 1);
323             return;
324         }
325         XtSetArg(args[0], XtNstring, &txt);
326         XtGetValues(tcTime, args, 1);
327         if(!ParseTimeControl(txt, inc, mps)) {
328             XtSetArg(args[0], XtNstring, ""); // erase any offending input
329             XtSetValues(tcTime, args, 1);
330             DisplayError(_("Bad Time-Control String"), 0);
331             return;
332         }
333         appData.movesPerSession = mps;
334         appData.timeIncrement = inc;
335         appData.timeControl = strdup(txt);
336         XtSetArg(args[0], XtNstring, &txt);
337         XtGetValues(tcOdds1, args, 1);
338         appData.firstTimeOdds = first.timeOdds 
339                 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
340         XtGetValues(tcOdds2, args, 1);
341         appData.secondTimeOdds = second.timeOdds 
342                 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
343
344         Reset(True, True);
345         TimeControlPopDown();
346         return;
347     }
348 }
349
350 void TimeControlPopUp()
351 {
352     Arg args[16];
353     Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, mess;
354     Window root, child;
355     int x, y, i, j;
356     int win_x, win_y;
357     unsigned int mask;
358     char def[80];
359     
360     tcInc = (appData.timeIncrement >= 0);
361     tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
362     if(!tcInc) tcIncrement = 0;
363     sprintf(def, "%d", tcInc ? tcIncrement : tcMoves);
364
365     i = 0;
366     XtSetArg(args[i], XtNresizable, True); i++;
367 //    XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
368     TimeControlShell = popup =
369       XtCreatePopupShell(_("TimeControl Menu"), transientShellWidgetClass,
370                          shellWidget, args, i);
371     
372     layout =
373       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
374                             layoutArgs, XtNumber(layoutArgs));
375   
376     form =
377       XtCreateManagedWidget(layoutName, formWidgetClass, layout,
378                             formArgs, XtNumber(formArgs));
379   
380     j = 0;
381 //    XtSetArg(args[j], XtNwidth,     (XtArgVal) 300); j++;
382 //    XtSetArg(args[j], XtNheight,    (XtArgVal) 85); j++;
383     XtSetValues(popup, args, j);
384
385     j= 0;
386     XtSetArg(args[j], XtNborderWidth, 1); j++;
387     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
388     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
389     XtSetArg(args[j], XtNstring, appData.timeControl);  j++;
390     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
391     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
392     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
393     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
394     XtSetArg(args[j], XtNright, XtChainRight);  j++;
395     XtSetArg(args[j], XtNresizable, True);  j++;
396     XtSetArg(args[j], XtNwidth,  85);  j++;
397 //    XtSetArg(args[j], XtNheight, 20);  j++;
398     tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j);
399     XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup);
400
401     j= 0;
402     XtSetArg(args[j], XtNlabel, tcInc ? _("   minutes, plus   ") : _("minutes for each")); j++;
403     XtSetArg(args[j], XtNborderWidth, 0); j++;
404     XtSetArg(args[j], XtNfromHoriz, tcTime); j++;
405     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
406     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
407     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
408     XtSetArg(args[j], XtNright, XtChainRight);  j++;
409   //  XtSetArg(args[j], XtNwidth,  100);  j++;
410   //  XtSetArg(args[j], XtNheight, 20);  j++;
411     tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
412
413     j= 0;
414     XtSetArg(args[j], XtNborderWidth, 1); j++;
415     XtSetArg(args[j], XtNfromHoriz, tcMess1); j++;
416     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
417     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
418     XtSetArg(args[j], XtNstring, def);  j++;
419     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
420     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
421     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
422     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
423     XtSetArg(args[j], XtNright, XtChainRight);  j++;
424     XtSetArg(args[j], XtNresizable, True);  j++;
425     XtSetArg(args[j], XtNwidth,  40);  j++;
426 //    XtSetArg(args[j], XtNheight, 20);  j++;
427     tcData = XtCreateManagedWidget("MPS", asciiTextWidgetClass, form, args, j);
428     XtAddEventHandler(tcData, ButtonPressMask, False, SetFocus, (XtPointer) popup);
429
430     j= 0;
431     XtSetArg(args[j], XtNlabel, tcInc ? _("sec/move") : _("moves     ")); j++;
432     XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
433     XtSetArg(args[j], XtNborderWidth, 0); j++;
434     XtSetArg(args[j], XtNfromHoriz, tcData); j++;
435     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
436     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
437     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
438     XtSetArg(args[j], XtNright, XtChainRight);  j++;
439 //    XtSetArg(args[j], XtNwidth,  80);  j++;
440 //    XtSetArg(args[j], XtNheight, 20);  j++;
441     tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass,
442                                    form, args, j);
443
444     j= 0;
445     XtSetArg(args[j], XtNborderWidth, 1); j++;
446     XtSetArg(args[j], XtNfromVert, tcTime); j++;
447     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
448     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
449     XtSetArg(args[j], XtNstring, "1");  j++;
450     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
451     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
452     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
453     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
454     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
455     XtSetArg(args[j], XtNresizable, True);  j++;
456     XtSetArg(args[j], XtNwidth,  40);  j++;
457 //    XtSetArg(args[j], XtNheight, 20);  j++;
458     tcOdds1 = XtCreateManagedWidget("Odds1", asciiTextWidgetClass, form, args, j);
459     XtAddEventHandler(tcOdds1, ButtonPressMask, False, SetFocus, (XtPointer) popup);
460
461     j= 0;
462     XtSetArg(args[j], XtNborderWidth, 1); j++;
463     XtSetArg(args[j], XtNfromVert, tcTime); j++;
464     XtSetArg(args[j], XtNfromHoriz, tcOdds1); j++;
465     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
466     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
467     XtSetArg(args[j], XtNstring, "1");  j++;
468     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
469     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
470     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
471     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
472     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
473     XtSetArg(args[j], XtNresizable, True);  j++;
474     XtSetArg(args[j], XtNwidth,  40);  j++;
475 //    XtSetArg(args[j], XtNheight, 20);  j++;
476     tcOdds2 = XtCreateManagedWidget("Odds2", asciiTextWidgetClass, form, args, j);
477     XtAddEventHandler(tcOdds2, ButtonPressMask, False, SetFocus, (XtPointer) popup);
478
479     j= 0;
480     XtSetArg(args[j], XtNlabel, _("Engine #1 and #2 Time-Odds Factors")); j++;
481     XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
482     XtSetArg(args[j], XtNborderWidth, 0); j++;
483     XtSetArg(args[j], XtNfromVert, tcTime); j++;
484     XtSetArg(args[j], XtNfromHoriz, tcOdds2); j++;
485     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
486     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
487     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
488     XtSetArg(args[j], XtNright, XtChainRight);  j++;
489 //    XtSetArg(args[j], XtNwidth,  200);  j++;
490 //    XtSetArg(args[j], XtNheight, 20);  j++;
491     mess = XtCreateManagedWidget("Oddstext", labelWidgetClass,
492                                    form, args, j);
493     j=0;
494     XtSetArg(args[j], XtNfromVert, tcOdds1);  j++;
495     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
496     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
497     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
498     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
499     b_clas= XtCreateManagedWidget(_("classical"), commandWidgetClass,
500                                    form, args, j);   
501     XtAddCallback(b_clas, XtNcallback, TimeControlCallback, (XtPointer) 0);
502
503     j=0;
504     XtSetArg(args[j], XtNfromVert, tcOdds1);  j++;
505     XtSetArg(args[j], XtNfromHoriz, b_clas);  j++;
506     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
507     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
508     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
509     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
510     b_inc = XtCreateManagedWidget(_("incremental"), commandWidgetClass,
511                                    form, args, j);   
512     XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
513
514     j=0;
515     XtSetArg(args[j], XtNfromVert, tcOdds1);  j++;
516     XtSetArg(args[j], XtNfromHoriz, tcData);  j++;
517     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
518     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
519     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
520     XtSetArg(args[j], XtNright, XtChainRight);  j++;
521     b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass,
522                                    form, args, j);   
523     XtAddCallback(b_ok, XtNcallback, TimeControlCallback, (XtPointer) 0);
524
525     j=0;
526     XtSetArg(args[j], XtNfromVert, tcOdds1);  j++;
527     XtSetArg(args[j], XtNfromHoriz, b_ok);  j++;
528     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
529     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
530     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
531     XtSetArg(args[j], XtNright, XtChainRight);  j++;
532     b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
533                                    form, args, j);   
534     XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0);
535
536     XtRealizeWidget(popup);
537     CatchDeleteWindow(popup, "TimeControlPopDown");
538     
539     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
540                   &x, &y, &win_x, &win_y, &mask);
541     
542     XtSetArg(args[0], XtNx, x - 10);
543     XtSetArg(args[1], XtNy, y - 30);
544     XtSetValues(popup, args, 2);
545     
546     XtPopup(popup, XtGrabExclusive);
547     TimeControlUp = True;
548     
549     previous = NULL;
550     SetFocus(tcTime, popup, (XEvent*) NULL, False);
551 //    XtSetKeyboardFocus(popup, tcTime);
552 }
553
554 void TimeControlProc(w, event, prms, nprms)
555      Widget w;
556      XEvent *event;
557      String *prms;
558      Cardinal *nprms;
559 {
560    TimeControlPopUp();
561 }
562
563 //--------------------------- Engine-Options Menu Popup ----------------------------------
564 int EngineUp;
565 Widget EngineShell;
566 extern int adjudicateLossThreshold;
567
568 Widget engDrawMoves, engThreshold, engRule, engRepeat;
569
570 void EnginePopDown()
571 {
572     if (!EngineUp) return;
573     XtPopdown(EngineShell);
574     XtDestroyWidget(EngineShell);
575     EngineUp = False;
576     ModeHighlight();
577 }
578
579 int ReadToggle(Widget w)
580 {
581     Arg args; Boolean res;
582
583     XtSetArg(args, XtNstate, &res);
584     XtGetValues(w, &args, 1);
585
586     return res;
587 }
588
589 Widget w1, w2, w3, w4, w5, w6, w7, w8;
590
591 void EngineCallback(w, client_data, call_data)
592      Widget w;
593      XtPointer client_data, call_data;
594 {
595     String name;
596     Widget s2;
597     Arg args[16];
598     char buf[80];
599     int j;
600     
601     XtSetArg(args[0], XtNlabel, &name);
602     XtGetValues(w, args, 1);
603     
604     if (strcmp(name, _("OK")) == 0) {
605         // read all switches
606         appData.periodicUpdates = ReadToggle(w1);
607 //      appData.hideThinkingFromHuman = ReadToggle(w2);
608         appData.firstScoreIsAbsolute  = ReadToggle(w3);
609         appData.secondScoreIsAbsolute = ReadToggle(w4);
610         appData.testClaims    = ReadToggle(w5);
611         appData.checkMates    = ReadToggle(w6);
612         appData.materialDraws = ReadToggle(w7);
613         appData.trivialDraws  = ReadToggle(w8);
614
615         // adjust setting in other menu for duplicates 
616         // (perhaps duplicates should be removed from general Option Menu?)
617 //      XtSetArg(args[0], XtNleftBitmap, appData.showThinking ? xMarkPixmap : None);
618 //      XtSetValues(XtNameToWidget(menuBarWidget,
619 //                                 "menuOptions.Show Thinking"), args, 1);
620
621         // read out numeric controls, simply ignore bad formats for now
622         XtSetArg(args[0], XtNstring, &name);
623         XtGetValues(engDrawMoves, args, 1);
624         if(sscanf(name, "%d", &j) == 1) appData.adjudicateDrawMoves = j;
625         XtGetValues(engThreshold, args, 1);
626         if(sscanf(name, "%d", &j) == 1) 
627                 adjudicateLossThreshold = appData.adjudicateLossThreshold = -j; // inverted!
628         XtGetValues(engRule, args, 1);
629         if(sscanf(name, "%d", &j) == 1) appData.ruleMoves = j;
630         XtGetValues(engRepeat, args, 1);
631         if(sscanf(name, "%d", &j) == 1) appData.drawRepeats = j;
632
633         EnginePopDown();
634         ShowThinkingEvent(); // [HGM] thinking: score adjudication might need thinking output
635         return;
636     }
637 }
638
639 void EnginePopUp()
640 {
641     Arg args[16];
642     Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, s1; 
643     Window root, child;
644     int x, y, i, j, width;
645     int win_x, win_y;
646     unsigned int mask;
647     char def[80];
648     
649     tcInc = (appData.timeIncrement >= 0);
650     tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
651     if(!tcInc) tcIncrement = 0;
652     sprintf(def, "%d", tcInc ? tcIncrement : tcMoves);
653
654     i = 0;
655     XtSetArg(args[i], XtNresizable, True); i++;
656 //    XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
657     EngineShell = popup =
658       XtCreatePopupShell(_("Adjudications"), transientShellWidgetClass,
659                          shellWidget, args, i);
660     
661     layout =
662       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
663                             layoutArgs, XtNumber(layoutArgs));
664   
665     form =
666       XtCreateManagedWidget(layoutName, formWidgetClass, layout,
667                             formArgs, XtNumber(formArgs));
668   
669     j = 0;
670 //    XtSetArg(args[j], XtNwidth,     (XtArgVal) 250); j++;
671 //    XtSetArg(args[j], XtNheight,    (XtArgVal) 400); j++;
672 //    XtSetValues(popup, args, j);
673
674     j = 0;
675 //    XtSetArg(args[j], XtNwidth,       (XtArgVal) 250); j++;
676 //    XtSetArg(args[j], XtNheight,      (XtArgVal) 20); j++;
677     XtSetArg(args[j], XtNleft,        (XtArgVal) XtChainLeft); j++;
678     XtSetArg(args[j], XtNright,       (XtArgVal) XtChainRight); j++;
679     XtSetArg(args[j], XtNstate,       appData.periodicUpdates); j++;
680 //    XtSetArg(args[j], XtNjustify,     (XtArgVal) XtJustifyLeft); j++;
681     w1 = XtCreateManagedWidget(_("Periodic Updates (Analysis Mode)"), toggleWidgetClass, form, args, j);
682
683     XtSetArg(args[j], XtNwidth,       (XtArgVal) &width);
684     XtGetValues(w1, &args[j], 1);
685
686 //    XtSetArg(args[j-1], XtNfromVert,  (XtArgVal) w1);
687 //    XtSetArg(args[j-3], XtNstate,       appData.hideThinkingFromHuman);
688 //    w2 = XtCreateManagedWidget(_("Hide Thinking from Human"), toggleWidgetClass, form, args, j);
689
690     XtSetArg(args[j], XtNwidth,       (XtArgVal) width); j++;
691     XtSetArg(args[j-2], XtNstate,     appData.firstScoreIsAbsolute);
692     XtSetArg(args[j], XtNfromVert,    (XtArgVal) w1); j++;
693     w3 = XtCreateManagedWidget(_("Engine #1 Score is Absolute"), toggleWidgetClass, form, args, j);
694
695     XtSetArg(args[j-1], XtNfromVert,  (XtArgVal) w3);
696     XtSetArg(args[j-3], XtNstate,       appData.secondScoreIsAbsolute);
697     w4 = XtCreateManagedWidget(_("Engine #2 Score is Absolute"), toggleWidgetClass, form, args, j);
698
699     s1 = XtCreateManagedWidget(_("\nEngine-Engine Adjudications:"), labelWidgetClass, form, args, 3);
700
701     XtSetArg(args[j-1], XtNfromVert,  (XtArgVal) s1);
702     XtSetArg(args[j-3], XtNstate,       appData.testClaims);
703     w5 = XtCreateManagedWidget(_("Verify Engine Result Claims"), toggleWidgetClass, form, args, j);
704
705     XtSetArg(args[j-1], XtNfromVert,  (XtArgVal) w5);
706     XtSetArg(args[j-3], XtNstate,       appData.checkMates);
707     w6 = XtCreateManagedWidget(_("Detect All Mates"), toggleWidgetClass, form, args, j);
708
709     XtSetArg(args[j-1], XtNfromVert,  (XtArgVal) w6);
710     XtSetArg(args[j-3], XtNstate,       appData.materialDraws);
711     w7 = XtCreateManagedWidget(_("Draw when Insuff. Mating Material"), toggleWidgetClass, form, args, j);
712
713     XtSetArg(args[j-1], XtNfromVert,  (XtArgVal) w7);
714     XtSetArg(args[j-3], XtNstate,       appData.trivialDraws);
715     w8 = XtCreateManagedWidget(_("Adjudicate Trivial Draws"), toggleWidgetClass, form, args, j);
716
717     XtSetArg(args[0], XtNfromVert,  (XtArgVal) w4);
718     XtSetArg(args[1], XtNborderWidth, (XtArgVal) 0);
719     XtSetValues(s1, args, 2);
720
721     sprintf(def, "%d", appData.adjudicateDrawMoves);
722     j= 0;
723     XtSetArg(args[j], XtNborderWidth, 1); j++;
724     XtSetArg(args[j], XtNfromVert, w8); j++;
725     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
726     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
727     XtSetArg(args[j], XtNstring, def);  j++;
728     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
729     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
730     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
731     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
732     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
733     XtSetArg(args[j], XtNresizable, True);  j++;
734     XtSetArg(args[j], XtNwidth,  60);  j++;
735 //    XtSetArg(args[j], XtNheight, 20);  j++;
736     engDrawMoves = XtCreateManagedWidget("Length", asciiTextWidgetClass, form, args, j);
737     XtAddEventHandler(engDrawMoves, ButtonPressMask, False, SetFocus, (XtPointer) popup);
738
739     j= 0;
740     XtSetArg(args[j], XtNlabel, _(" moves maximum, then draw")); j++;
741     XtSetArg(args[j], XtNjustify,     (XtArgVal) XtJustifyLeft); j++;
742     XtSetArg(args[j], XtNborderWidth, 0); j++;
743     XtSetArg(args[j], XtNfromVert, w8); j++;
744     XtSetArg(args[j], XtNfromHoriz, engDrawMoves); j++;
745     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
746     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
747     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
748     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
749 //    XtSetArg(args[j], XtNwidth,  170);  j++;
750 //    XtSetArg(args[j], XtNheight, 20);  j++;
751     tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
752
753     sprintf(def, "%d", -appData.adjudicateLossThreshold); // inverted!
754     j= 0;
755     XtSetArg(args[j], XtNborderWidth, 1); j++;
756     XtSetArg(args[j], XtNfromVert, engDrawMoves); j++;
757     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
758     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
759     XtSetArg(args[j], XtNstring, def);  j++;
760     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
761     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
762     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
763     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
764     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
765     XtSetArg(args[j], XtNresizable, True);  j++;
766     XtSetArg(args[j], XtNwidth,  60);  j++;
767 //    XtSetArg(args[j], XtNheight, 20);  j++;
768     engThreshold = XtCreateManagedWidget("Threshold", asciiTextWidgetClass, form, args, j);
769     XtAddEventHandler(engThreshold, ButtonPressMask, False, SetFocus, (XtPointer) popup);
770
771     j= 0;
772     XtSetArg(args[j], XtNlabel, _("-centiPawn lead is win")); j++;
773     XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
774     XtSetArg(args[j], XtNborderWidth, 0); j++;
775     XtSetArg(args[j], XtNfromVert, engDrawMoves); j++;
776     XtSetArg(args[j], XtNfromHoriz, engThreshold); j++;
777     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
778     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
779     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
780     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
781 //    XtSetArg(args[j], XtNwidth,  150);  j++;
782 //    XtSetArg(args[j], XtNheight, 20);  j++;
783     tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j);
784
785     sprintf(def, "%d", appData.ruleMoves);
786     j= 0;
787     XtSetArg(args[j], XtNborderWidth, 1); j++;
788     XtSetArg(args[j], XtNfromVert, engThreshold); j++;
789     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
790     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
791     XtSetArg(args[j], XtNstring, def);  j++;
792     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
793     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
794     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
795     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
796     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
797     XtSetArg(args[j], XtNresizable, True);  j++;
798     XtSetArg(args[j], XtNwidth,  30);  j++;
799 //    XtSetArg(args[j], XtNheight, 20);  j++;
800     engRule = XtCreateManagedWidget("Rule", asciiTextWidgetClass, form, args, j);
801     XtAddEventHandler(engRule, ButtonPressMask, False, SetFocus, (XtPointer) popup);
802
803     j= 0;
804     XtSetArg(args[j], XtNlabel, _("-move rule applied")); j++;
805     XtSetArg(args[j], XtNjustify,     (XtArgVal) XtJustifyLeft); j++;
806     XtSetArg(args[j], XtNborderWidth, 0); j++;
807     XtSetArg(args[j], XtNfromVert, engThreshold); j++;
808     XtSetArg(args[j], XtNfromHoriz, engRule); j++;
809     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
810     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
811     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
812     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
813 //    XtSetArg(args[j], XtNwidth,  130);  j++;
814 //    XtSetArg(args[j], XtNheight, 20);  j++;
815     tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
816
817     sprintf(def, "%d", appData.drawRepeats);
818     j= 0;
819     XtSetArg(args[j], XtNborderWidth, 1); j++;
820     XtSetArg(args[j], XtNfromVert, engRule); j++;
821     XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
822     XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
823     XtSetArg(args[j], XtNstring, def);  j++;
824     XtSetArg(args[j], XtNdisplayCaret, False);  j++;
825     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
826     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
827     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
828     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
829     XtSetArg(args[j], XtNresizable, True);  j++;
830     XtSetArg(args[j], XtNwidth,  30);  j++;
831 //    XtSetArg(args[j], XtNheight, 20);  j++;
832     engRepeat = XtCreateManagedWidget("Repeats", asciiTextWidgetClass, form, args, j);
833     XtAddEventHandler(engRepeat, ButtonPressMask, False, SetFocus, (XtPointer) popup);
834
835     j= 0;
836     XtSetArg(args[j], XtNlabel, _("-fold repeat is draw")); j++;
837     XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
838     XtSetArg(args[j], XtNborderWidth, 0); j++;
839     XtSetArg(args[j], XtNfromVert, engRule); j++;
840     XtSetArg(args[j], XtNfromHoriz, engRepeat); j++;
841     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
842     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
843     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
844     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
845 //    XtSetArg(args[j], XtNwidth,  130);  j++;
846 //    XtSetArg(args[j], XtNheight, 20);  j++;
847     tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j);
848
849     j=0;
850     XtSetArg(args[j], XtNfromVert, engRepeat);  j++;
851     XtSetArg(args[j], XtNfromHoriz, tcMess2);  j++;
852     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
853     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
854     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
855     XtSetArg(args[j], XtNright, XtChainRight);  j++;
856     b_ok= XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);   
857     XtAddCallback(b_ok, XtNcallback, EngineCallback, (XtPointer) 0);
858
859     j=0;
860     XtSetArg(args[j], XtNfromVert, engRepeat);  j++;
861     XtSetArg(args[j], XtNfromHoriz, b_ok);  j++;
862     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
863     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
864     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
865     XtSetArg(args[j], XtNright, XtChainRight);  j++;
866     b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
867                                    form, args, j);   
868     XtAddCallback(b_cancel, XtNcallback, EnginePopDown, (XtPointer) 0);
869
870     XtRealizeWidget(popup);
871     CatchDeleteWindow(popup, "EnginePopDown");
872     
873     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
874                   &x, &y, &win_x, &win_y, &mask);
875     
876     XtSetArg(args[0], XtNx, x - 10);
877     XtSetArg(args[1], XtNy, y - 30);
878     XtSetValues(popup, args, 2);
879     
880     XtPopup(popup, XtGrabExclusive);
881     EngineUp = True;
882     
883     previous = NULL;
884     SetFocus(engThreshold, popup, (XEvent*) NULL, False);
885 }
886
887 void EngineMenuProc(w, event, prms, nprms)
888      Widget w;
889      XEvent *event;
890      String *prms;
891      Cardinal *nprms;
892 {
893    EnginePopUp();
894 }
895
896 //--------------------------- New-Variant Menu PopUp -----------------------------------
897 struct NewVarButton {
898   char   *name;
899   char *color;
900   Widget handle;
901   VariantClass variant;
902 };
903
904 struct NewVarButton buttonDesc[] = {
905     {N_("normal"),            "#FFFFFF", 0, VariantNormal},
906     {N_("FRC"),               "#FFFFFF", 0, VariantFischeRandom},
907     {N_("wild castle"),       "#FFFFFF", 0, VariantWildCastle},
908     {N_("no castle"),         "#FFFFFF", 0, VariantNoCastle},
909     {N_("knightmate"),        "#FFFFFF", 0, VariantKnightmate},
910     {N_("berolina"),          "#FFFFFF", 0, VariantBerolina},
911     {N_("cylinder"),          "#FFFFFF", 0, VariantCylinder},
912     {N_("shatranj"),          "#FFFFFF", 0, VariantShatranj},
913     {N_("atomic"),            "#FFFFFF", 0, VariantAtomic},
914     {N_("two kings"),         "#FFFFFF", 0, VariantTwoKings},
915     {N_("3-checks"),          "#FFFFFF", 0, Variant3Check},
916     {N_("suicide"),           "#FFFFBF", 0, VariantSuicide},
917     {N_("give-away"),         "#FFFFBF", 0, VariantGiveaway},
918     {N_("losers"),            "#FFFFBF", 0, VariantLosers},
919     {N_("fairy"),             "#BFBFBF", 0, VariantFairy},
920     {N_("Superchess"),        "#FFBFBF", 0, VariantSuper},
921     {N_("crazyhouse"),        "#FFBFBF", 0, VariantCrazyhouse},
922     {N_("bughouse"),          "#FFBFBF", 0, VariantBughouse},
923     {N_("shogi (9x9)"),       "#BFFFFF", 0, VariantShogi},
924     {N_("xiangqi (9x10)"),    "#BFFFFF", 0, VariantXiangqi},
925     {N_("courier (12x8)"),    "#BFFFBF", 0, VariantCourier},
926     {N_("janus (10x8)"),      "#BFBFFF", 0, VariantJanus},
927     {N_("Capablanca (10x8)"), "#BFBFFF", 0, VariantCapablanca},
928     {N_("CRC (10x8)"),        "#BFBFFF", 0, VariantCapaRandom},
929 #ifdef GOTHIC
930     {N_("Gothic (10x8)"),     "#BFBFFF", 0, VariantGothic},
931 #endif
932 #ifdef FALCON
933     {N_("Falcon (10x8)"),     "#BFBFFF", 0, VariantFalcon},
934 #endif
935     {NULL,                0, 0, (VariantClass) 0}
936 };
937
938 int NewVariantUp;
939 Widget NewVariantShell;
940
941 void NewVariantPopDown()
942 {
943     if (!NewVariantUp) return;
944     XtPopdown(NewVariantShell);
945     XtDestroyWidget(NewVariantShell);
946     NewVariantUp = False;
947     ModeHighlight();
948 }
949
950 void NewVariantCallback(w, client_data, call_data)
951      Widget w;
952      XtPointer client_data, call_data;
953 {
954     String name;
955     Widget w2;
956     Arg args[16];
957     char buf[80];
958     VariantClass v;
959     
960     XtSetArg(args[0], XtNlabel, &name);
961     XtGetValues(w, args, 1);
962     
963     if (strcmp(name, _("  OK  ")) == 0) {
964         int nr = (int) XawToggleGetCurrent(buttonDesc[0].handle) - 1;
965         if(nr < 0) return;
966         v = buttonDesc[nr].variant;
967         if(!appData.noChessProgram) { 
968             char *name = VariantName(v), buf[MSG_SIZ];
969             if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
970                 /* [HGM] in protocol 2 we check if variant is suported by engine */
971                 sprintf(buf, _("Variant %s not supported by %s"), name, first.tidy);
972                 DisplayError(buf, 0);
973 //              NewVariantPopDown();
974                 return; /* ignore OK if first engine does not support it */
975             } else
976             if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
977                 sprintf(buf, _("Warning: second engine (%s) does not support this!"), second.tidy);
978                 DisplayError(buf, 0);   /* use of second engine is optional; only warn user */
979             }
980         }
981
982         gameInfo.variant = v;
983         appData.variant = VariantName(v);
984
985         shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
986         startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
987         appData.pieceToCharTable = NULL;
988         Reset(True, True);
989         NewVariantPopDown();
990         return;
991     }
992 }
993
994 void NewVariantPopUp()
995 {
996     Arg args[16];
997     Widget popup, layout, dialog, edit, form, last = NULL, b_ok, b_cancel;
998     Window root, child;
999     int x, y, i, j;
1000     int win_x, win_y;
1001     unsigned int mask;
1002     char def[80];
1003     XrmValue vFrom, vTo;
1004
1005     i = 0;
1006     XtSetArg(args[i], XtNresizable, True); i++;
1007 //    XtSetArg(args[i], XtNwidth, 250); i++;
1008 //    XtSetArg(args[i], XtNheight, 300); i++;
1009     NewVariantShell = popup =
1010       XtCreatePopupShell(_("NewVariant Menu"), transientShellWidgetClass,
1011                          shellWidget, args, i);
1012     
1013     layout =
1014       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1015                             layoutArgs, XtNumber(layoutArgs));
1016   
1017     form =
1018       XtCreateManagedWidget("form", formWidgetClass, layout,
1019                             formArgs, XtNumber(formArgs));
1020   
1021     for(i = 0; buttonDesc[i].name != NULL; i++) {
1022         Pixel buttonColor;
1023         if (!appData.monoMode) {
1024             vFrom.addr = (caddr_t) buttonDesc[i].color;
1025             vFrom.size = strlen(buttonDesc[i].color);
1026             XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1027             if (vTo.addr == NULL) {
1028                 buttonColor = (Pixel) -1;
1029             } else {
1030                 buttonColor = *(Pixel *) vTo.addr;
1031             }
1032         }
1033     
1034         j = 0;
1035         XtSetArg(args[j], XtNradioGroup, last); j++;
1036         XtSetArg(args[j], XtNwidth, 125); j++;
1037 //      XtSetArg(args[j], XtNheight, 16); j++;
1038         XtSetArg(args[j], XtNfromVert, i == 15 ? NULL : last); j++;
1039         XtSetArg(args[j], XtNfromHoriz, i < 15 ? NULL : buttonDesc[i-15].handle); j++;
1040         XtSetArg(args[j], XtNradioData, i+1); j++;
1041         XtSetArg(args[j], XtNbackground, buttonColor); j++;
1042         XtSetArg(args[j], XtNstate, gameInfo.variant == buttonDesc[i].variant); j++;
1043         buttonDesc[i].handle = last =
1044             XtCreateManagedWidget(buttonDesc[i].name, toggleWidgetClass, form, args, j);
1045     }
1046
1047     j=0;
1048     XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle);  j++;
1049     XtSetArg(args[j], XtNfromHoriz, buttonDesc[12].handle);  j++;
1050     XtSetArg(args[j], XtNheight, 35); j++;
1051 //    XtSetArg(args[j], XtNwidth, 60); j++;
1052     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
1053     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
1054     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
1055     XtSetArg(args[j], XtNright, XtChainRight);  j++;
1056     b_cancel= XtCreateManagedWidget(_("CANCEL"), commandWidgetClass, form, args, j);   
1057     XtAddCallback(b_cancel, XtNcallback, NewVariantPopDown, (XtPointer) 0);
1058
1059     j=0;
1060     XtSetArg(args[j], XtNfromHoriz, b_cancel);  j++;
1061     XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle);  j++;
1062     XtSetArg(args[j], XtNheight, 35); j++;
1063 //    XtSetArg(args[j], XtNwidth, 60); j++;
1064     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
1065     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
1066     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
1067     XtSetArg(args[j], XtNright, XtChainRight);  j++;
1068     b_ok= XtCreateManagedWidget(_("  OK  "), commandWidgetClass, form, args, j);   
1069     XtAddCallback(b_ok, XtNcallback, NewVariantCallback, (XtPointer) 0);
1070
1071     j=0;
1072     XtSetArg(args[j], XtNfromVert, buttonDesc[14].handle);  j++;
1073 //    XtSetArg(args[j], XtNheight, 70); j++;
1074     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
1075     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
1076     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
1077     XtSetArg(args[j], XtNright, XtChainRight);  j++;
1078     XtSetArg(args[j], XtNlabel, _("WARNING: variants with un-orthodox\n"
1079                                   "pieces only have built-in bitmaps\n"
1080                                   "for -boardSize middling, bulky and\n"
1081                                   "petite, and substitute king or amazon\n"
1082                                   "for missing bitmaps. (See manual.)")); j++;
1083     XtCreateManagedWidget("warning", labelWidgetClass, form, args, j);
1084
1085     XtRealizeWidget(popup);
1086     CatchDeleteWindow(popup, "NewVariantPopDown");
1087     
1088     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1089                   &x, &y, &win_x, &win_y, &mask);
1090     
1091     XtSetArg(args[0], XtNx, x - 10);
1092     XtSetArg(args[1], XtNy, y - 30);
1093     XtSetValues(popup, args, 2);
1094     
1095     XtPopup(popup, XtGrabExclusive);
1096     NewVariantUp = True;
1097 }
1098
1099 void NewVariantProc(w, event, prms, nprms)
1100      Widget w;
1101      XEvent *event;
1102      String *prms;
1103      Cardinal *nprms;
1104 {
1105    NewVariantPopUp();
1106 }
1107
1108 //--------------------------- UCI Menu Popup ------------------------------------------
1109 int UciUp;
1110 Widget UciShell;
1111
1112 struct UciControl {
1113   char *name;
1114   Widget handle;
1115   void *ptr;
1116 };
1117
1118 struct UciControl controlDesc[] = {
1119   {N_("maximum nr of CPUs:"), 0, &appData.smpCores},
1120   {N_("Polyglot Directory:"), 0, &appData.polyglotDir},
1121   {N_("Hash Size (MB):"),     0, &appData.defaultHashSize},
1122   {N_("EGTB Path:"),          0, &appData.defaultPathEGTB},
1123   {N_("EGTB Cache (MB):"),    0, &appData.defaultCacheSizeEGTB},
1124   {N_("Polyglot Book:"),      0, &appData.polyglotBook},
1125   {NULL, 0, NULL},
1126 };
1127
1128 void UciPopDown()
1129 {
1130     if (!UciUp) return;
1131     XtPopdown(UciShell);
1132     XtDestroyWidget(UciShell);
1133     UciUp = False;
1134     ModeHighlight();
1135 }
1136
1137 void UciCallback(w, client_data, call_data)
1138      Widget w;
1139      XtPointer client_data, call_data;
1140 {
1141     String name;
1142     Arg args[16];
1143     char buf[80];
1144     int oldCores = appData.smpCores, ponder = 0;
1145     
1146     XtSetArg(args[0], XtNlabel, &name);
1147     XtGetValues(w, args, 1);
1148     
1149     if (strcmp(name, _("OK")) == 0) {
1150         int nr, i, j; String name;
1151         for(i=0; i<6; i++) {
1152             XtSetArg(args[0], XtNstring, &name);
1153             XtGetValues(controlDesc[i].handle, args, 1);
1154             if(i&1) {
1155                 if(name)
1156                     *(char**) controlDesc[i].ptr = strdup(name);
1157             } else {
1158                 if(sscanf(name, "%d", &j) == 1) 
1159                     *(int*) controlDesc[i].ptr = j;
1160             }
1161         }
1162         XtSetArg(args[0], XtNstate, &appData.usePolyglotBook);
1163         XtGetValues(w1, args, 1);
1164         XtSetArg(args[0], XtNstate, &appData.firstHasOwnBookUCI);
1165         XtGetValues(w2, args, 1);
1166         XtSetArg(args[0], XtNstate, &appData.secondHasOwnBookUCI);
1167         XtGetValues(w3, args, 1);
1168         XtSetArg(args[0], XtNstate, &ponder);
1169         XtGetValues(w4, args, 1);
1170
1171         // adjust setting in other menu for duplicates 
1172         // (perhaps duplicates should be removed from general Option Menu?)
1173         XtSetArg(args[0], XtNleftBitmap, ponder ? xMarkPixmap : None);
1174         XtSetValues(XtNameToWidget(menuBarWidget,
1175                                    "menuOptions.Ponder Next Move"), args, 1);
1176
1177         // make sure changes are sent to first engine by re-initializing it
1178         // if it was already started pre-emptively at end of previous game
1179         if(gameMode == BeginningOfGame) Reset(True, True); else {
1180             // Some changed setting need immediate sending always.
1181             PonderNextMoveEvent(ponder);
1182             if(oldCores != appData.smpCores)
1183                 NewSettingEvent(False, "cores", appData.smpCores);
1184       }
1185       UciPopDown();
1186       return;
1187     }
1188 }
1189
1190 void UciPopUp()
1191 {
1192     Arg args[16];
1193     Widget popup, layout, dialog, edit, form, b_ok, b_cancel, last = NULL, new, upperLeft;
1194     Window root, child;
1195     int x, y, i, j;
1196     int win_x, win_y;
1197     unsigned int mask;
1198     char def[80];
1199     
1200     i = 0;
1201     XtSetArg(args[i], XtNresizable, True); i++;
1202 //    XtSetArg(args[i], XtNwidth, 300); i++;
1203     UciShell = popup =
1204       XtCreatePopupShell(_("Engine Settings"), transientShellWidgetClass,
1205                          shellWidget, args, i);
1206     
1207     layout =
1208       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1209                             layoutArgs, XtNumber(layoutArgs));
1210   
1211     
1212     form =
1213       XtCreateManagedWidget("form", formWidgetClass, layout,
1214                             formArgs, XtNumber(formArgs));
1215   
1216     j = 0;
1217     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
1218     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
1219     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
1220 //    XtSetArg(args[j], XtNheight, 20); j++;
1221     for(i = 0; controlDesc[i].name != NULL; i++) {
1222         j = 3;
1223         XtSetArg(args[j], XtNfromVert, last); j++;
1224 //      XtSetArg(args[j], XtNwidth, 130); j++;
1225         XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1226         XtSetArg(args[j], XtNright, XtChainLeft);  j++;
1227         XtSetArg(args[j], XtNborderWidth, 0); j++;
1228         new = XtCreateManagedWidget(controlDesc[i].name, labelWidgetClass, form, args, j);
1229         if(i==0) upperLeft = new;
1230
1231         j = 4;
1232         XtSetArg(args[j], XtNborderWidth, 1); j++;
1233         XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
1234         XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
1235         XtSetArg(args[j], XtNdisplayCaret, False);  j++;
1236         XtSetArg(args[j], XtNright, XtChainRight);  j++;
1237         XtSetArg(args[j], XtNresizable, True);  j++;
1238         XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++;
1239         if(i&1) {
1240             XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ? 
1241                                          * (char**) controlDesc[i].ptr : ""); j++;
1242         } else {
1243             sprintf(def, "%d", * (int*) controlDesc[i].ptr);
1244             XtSetArg(args[j], XtNstring, def); j++;
1245         }
1246         XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1247         controlDesc[i].handle = last =
1248             XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
1249         XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1250     }
1251
1252     j=0;
1253     XtSetArg(args[j], XtNfromHoriz, controlDesc[0].handle);  j++;
1254     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
1255     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
1256     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
1257     XtSetArg(args[j], XtNright, XtChainRight);  j++;
1258     XtSetArg(args[j], XtNstate, appData.ponderNextMove);  j++;
1259     w4 = XtCreateManagedWidget(_("Ponder"), toggleWidgetClass, form, args, j);   
1260
1261     j=0;
1262     XtSetArg(args[j], XtNfromVert, last);  j++;
1263     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
1264     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
1265     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
1266     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
1267     b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);   
1268     XtAddCallback(b_ok, XtNcallback, UciCallback, (XtPointer) 0);
1269
1270     XtSetArg(args[j], XtNfromHoriz, b_ok);  j++;
1271     b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);   
1272     XtAddCallback(b_cancel, XtNcallback, UciPopDown, (XtPointer) 0);
1273
1274     j = 5;
1275     XtSetArg(args[j], XtNfromHoriz, upperLeft);  j++;
1276     XtSetArg(args[j], XtNstate, appData.usePolyglotBook);  j++;
1277     w1 = XtCreateManagedWidget(_(" use book "), toggleWidgetClass, form, args, j);   
1278 //    XtAddCallback(w1, XtNcallback, UciCallback, (XtPointer) 0);
1279
1280     j = 5;
1281     XtSetArg(args[j], XtNfromHoriz, w1);  j++;
1282     XtSetArg(args[j], XtNstate, appData.firstHasOwnBookUCI);  j++;
1283     w2 = XtCreateManagedWidget(_("own book 1"), toggleWidgetClass, form, args, j);   
1284 //    XtAddCallback(w2, XtNcallback, UciCallback, (XtPointer) 0);
1285
1286     j = 5;
1287     XtSetArg(args[j], XtNfromHoriz, w2);  j++;
1288     XtSetArg(args[j], XtNstate, appData.secondHasOwnBookUCI);  j++;
1289     w3 = XtCreateManagedWidget(_("own book 2"), toggleWidgetClass, form, args, j);   
1290 //    XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0);
1291
1292     XtRealizeWidget(popup);
1293     CatchDeleteWindow(popup, "UciPopDown");
1294     
1295     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1296                   &x, &y, &win_x, &win_y, &mask);
1297     
1298     XtSetArg(args[0], XtNx, x - 10);
1299     XtSetArg(args[1], XtNy, y - 30);
1300     XtSetValues(popup, args, 2);
1301     
1302     XtPopup(popup, XtGrabExclusive);
1303     UciUp = True;
1304
1305     previous = NULL;
1306     SetFocus(controlDesc[2].handle, popup, (XEvent*) NULL, False);
1307 //    XtSetKeyboardFocus(popup, controlDesc[1].handle);
1308 }
1309
1310 void UciMenuProc(w, event, prms, nprms)
1311      Widget w;
1312      XEvent *event;
1313      String *prms;
1314      Cardinal *nprms;
1315 {
1316    UciPopUp();
1317 }
1318
1319 //--------------------------- Engine-specific options menu ----------------------------------
1320
1321 int SettingsUp;
1322 Widget SettingsShell;
1323 int values[MAX_OPTIONS];
1324 ChessProgramState *currentCps;
1325
1326 void SettingsPopDown()
1327 {
1328     if (!SettingsUp) return;
1329     XtPopdown(SettingsShell);
1330     XtDestroyWidget(SettingsShell);
1331     SettingsUp = False;
1332     ModeHighlight();
1333 }
1334
1335 void SpinCallback(w, client_data, call_data)
1336      Widget w;
1337      XtPointer client_data, call_data;
1338 {
1339     String name, val;
1340     Widget w2;
1341     Arg args[16];
1342     char buf[MSG_SIZ];
1343     int i, j;
1344     
1345     XtSetArg(args[0], XtNlabel, &name);
1346     XtGetValues(w, args, 1);
1347     
1348     j = 0;
1349     XtSetArg(args[0], XtNstring, &val);
1350     XtGetValues(currentCps->option[(int)client_data].handle, args, 1);
1351     sscanf(val, "%d", &j);
1352     if (strcmp(name, "+") == 0) {
1353         if(++j > currentCps->option[(int)client_data].max) return;
1354     } else
1355     if (strcmp(name, "-") == 0) {
1356         if(--j < currentCps->option[(int)client_data].min) return;
1357     } else return;
1358     sprintf(buf, "%d", j);
1359     XtSetArg(args[0], XtNstring, buf);
1360     XtSetValues(currentCps->option[(int)client_data].handle, args, 1);
1361 }
1362
1363 void SettingsCallback(w, client_data, call_data)
1364      Widget w;
1365      XtPointer client_data, call_data;
1366 {
1367     String name, val;
1368     Widget w2;
1369     Arg args[16];
1370     char buf[MSG_SIZ];
1371     int i, j;
1372     
1373     XtSetArg(args[0], XtNlabel, &name);
1374     XtGetValues(w, args, 1);
1375     
1376     if (strcmp(name, _("cancel")) == 0) {
1377         SettingsPopDown();
1378         return;
1379     }
1380     if (strcmp(name, _("OK")) == 0 || (int)client_data) { // save buttons imply OK
1381         int nr;
1382
1383         for(i=0; i<currentCps->nrOptions; i++) { // send all options that had to be OK-ed to engine
1384             switch(currentCps->option[i].type) {
1385                 case TextBox:
1386                     XtSetArg(args[0], XtNstring, &val);
1387                     XtGetValues(currentCps->option[i].handle, args, 1);
1388                     if(strcmp(currentCps->option[i].textValue, val)) {
1389                         strcpy(currentCps->option[i].textValue, val);
1390                         sprintf(buf, "option %s=%s\n", currentCps->option[i].name, val);
1391                         SendToProgram(buf, currentCps);
1392                     }
1393                     break;
1394                 case Spin:
1395                     XtSetArg(args[0], XtNstring, &val);
1396                     XtGetValues(currentCps->option[i].handle, args, 1);
1397                     sscanf(val, "%d", &j);
1398                     if(j > currentCps->option[i].max) j = currentCps->option[i].max;
1399                     if(j < currentCps->option[i].min) j = currentCps->option[i].min;
1400                     if(currentCps->option[i].value != j) {
1401                         currentCps->option[i].value = j;
1402                         sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1403                         SendToProgram(buf, currentCps);
1404                     }
1405                     break;
1406                 case CheckBox:
1407                     j = 0;
1408                     XtSetArg(args[0], XtNstate, &j);
1409                     XtGetValues(currentCps->option[i].handle, args, 1);
1410                     if(currentCps->option[i].value != j) {
1411                         currentCps->option[i].value = j;
1412                         sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1413                         SendToProgram(buf, currentCps);
1414                     }
1415                     break;
1416                 case ComboBox:
1417                     if(currentCps->option[i].value != values[i]) {
1418                         currentCps->option[i].value = values[i];
1419                         sprintf(buf, "option %s=%s\n", currentCps->option[i].name, 
1420                                 ((char**)currentCps->option[i].textValue)[values[i]]);
1421                         SendToProgram(buf, currentCps);
1422                     }
1423                     break;
1424             }
1425         }
1426         if((int)client_data) { // send save-button command to engine
1427             sprintf(buf, "option %s\n", name);
1428             SendToProgram(buf, currentCps);
1429         }
1430         SettingsPopDown();
1431         return;
1432     }
1433     sprintf(buf, "option %s\n", name);
1434     SendToProgram(buf, currentCps);
1435 }
1436
1437 void ComboSelect(w, addr, index) // callback for all combo items
1438      Widget w;
1439      caddr_t addr;
1440      caddr_t index;
1441 {
1442     Arg args[16];
1443     int i = ((int)addr)>>8;
1444     int j = 255 & (int) addr;
1445
1446     values[i] = j; // store in temporary, for transfer at OK
1447     XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]);
1448     XtSetValues(currentCps->option[i].handle, args, 1);
1449 }
1450
1451 void CreateComboPopup(parent, name, n, mb)
1452      Widget parent;
1453      String name;
1454      int n;
1455      char *mb[];
1456 {
1457     int i=0, j;
1458     Widget menu, entry;
1459     Arg args[16];
1460
1461     menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
1462                               parent, NULL, 0);
1463     j = 0;
1464     XtSetArg(args[j], XtNwidth, 100);  j++;
1465 //    XtSetArg(args[j], XtNright, XtChainRight);  j++;
1466     while (mb[i] != NULL) {
1467             entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
1468                                           menu, args, j);
1469             XtAddCallback(entry, XtNcallback,
1470                           (XtCallbackProc) ComboSelect,
1471                           (caddr_t) (256*n+i));
1472         i++;
1473     }
1474 }       
1475
1476 void SettingsPopUp(ChessProgramState *cps)
1477 {
1478     Arg args[16];
1479     Widget popup, layout, dialog, edit, form, oldform, last, b_ok, b_cancel, leftMargin = NULL;
1480     Window root, child;
1481     int x, y, i, j, height, width, h, c;
1482     int win_x, win_y;
1483     unsigned int mask;
1484     char def[80], *p, *q;
1485     static char pane[6] = "paneX";
1486
1487     // to do: start up second engine if needed
1488     if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
1489     currentCps = cps;
1490
1491     if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1;
1492     height = cps->nrOptions / width + 1;
1493     i = 0;
1494     XtSetArg(args[i], XtNresizable, True); i++;
1495     SettingsShell = popup =
1496       XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
1497                          shellWidget, args, i);
1498     
1499     layout =
1500       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1501                             layoutArgs, XtNumber(layoutArgs));
1502   for(c=0; c<width; c++) {
1503     pane[4] = 'A'+c;
1504     form =
1505       XtCreateManagedWidget(pane, formWidgetClass, layout,
1506                             formArgs, XtNumber(formArgs));
1507     j=0;
1508     XtSetArg(args[j], XtNfromHoriz, leftMargin);  j++;
1509     XtSetValues(form, args, j);
1510     leftMargin = form;
1511
1512     last = NULL;
1513     for(h=0; h<height; h++) {
1514         i = h + c*height;
1515         if(i >= cps->nrOptions) break;
1516         switch(cps->option[i].type) {
1517           case Spin:
1518             sprintf(def, "%d", cps->option[i].value);
1519           case TextBox:
1520             j=0;
1521             XtSetArg(args[j], XtNfromVert, last);  j++;
1522             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1523             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1524             dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);   
1525             j=0;
1526             XtSetArg(args[j], XtNfromVert, last);  j++;
1527             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1528             XtSetArg(args[j], XtNborderWidth, 1); j++;
1529             XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 100); j++;
1530             XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
1531             XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
1532             XtSetArg(args[j], XtNdisplayCaret, False);  j++;
1533             XtSetArg(args[j], XtNright, XtChainRight);  j++;
1534             XtSetArg(args[j], XtNresizable, True);  j++;
1535             XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue);  j++;
1536             edit = last;
1537             cps->option[i].handle = (void*)
1538                 (last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));   
1539             XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1540             if(cps->option[i].type == TextBox) break;
1541
1542             // add increment and decrement controls for spin
1543             j=0;
1544             XtSetArg(args[j], XtNfromVert, edit);  j++;
1545             XtSetArg(args[j], XtNfromHoriz, last);  j++;
1546             XtSetArg(args[j], XtNheight, 10);  j++;
1547             XtSetArg(args[j], XtNwidth, 20);  j++;
1548             edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j);
1549             XtAddCallback(edit, XtNcallback, SpinCallback, (XtPointer) i);
1550
1551             j=0;
1552             XtSetArg(args[j], XtNfromVert, edit);  j++;
1553             XtSetArg(args[j], XtNfromHoriz, last);  j++;
1554             XtSetArg(args[j], XtNheight, 10);  j++;
1555             XtSetArg(args[j], XtNwidth, 20);  j++;
1556             last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1557             XtAddCallback(last, XtNcallback, SpinCallback, (XtPointer) i);
1558             break;
1559           case CheckBox:
1560             j=0;
1561             XtSetArg(args[j], XtNfromVert, last);  j++;
1562             XtSetArg(args[j], XtNwidth, 10);  j++;
1563             XtSetArg(args[j], XtNheight, 10);  j++;
1564             XtSetArg(args[j], XtNstate, cps->option[i].value);  j++;
1565             cps->option[i].handle = (void*) 
1566                 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));   
1567             j=0;
1568             XtSetArg(args[j], XtNfromVert, last);  j++;
1569             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1570             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1571             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1572             last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1573             break;
1574           case SaveButton:
1575           case Button:
1576             j=0;
1577             XtSetArg(args[j], XtNfromVert, last);  j++;
1578             XtSetArg(args[j], XtNstate, cps->option[i].value);  j++;
1579             cps->option[i].handle = (void*) 
1580                 (last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));   
1581             XtAddCallback(last, XtNcallback, SettingsCallback, (XtPointer) (cps->option[i].type == SaveButton));
1582             break;
1583           case ComboBox:
1584             j=0;
1585             XtSetArg(args[j], XtNfromVert, last);  j++;
1586             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1587             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1588             dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1589
1590             j=0;
1591             XtSetArg(args[j], XtNfromVert, last);  j++;
1592             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1593             XtSetArg(args[j], XtNwidth, 100);  j++;
1594             XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name));  j++;
1595             XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]);  j++;
1596             cps->option[i].handle = (void*) 
1597                 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));   
1598             CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue);
1599             values[i] = cps->option[i].value;
1600             break;
1601         }
1602     }
1603   }
1604     j=0;
1605     XtSetArg(args[j], XtNfromVert, last);  j++;
1606     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
1607     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
1608     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
1609     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
1610     b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);   
1611     XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
1612
1613     XtSetArg(args[j], XtNfromHoriz, b_ok);  j++;
1614     b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);   
1615     XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
1616
1617     XtRealizeWidget(popup);
1618     CatchDeleteWindow(popup, "SettingsPopDown");
1619     
1620     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1621                   &x, &y, &win_x, &win_y, &mask);
1622     
1623     XtSetArg(args[0], XtNx, x - 10);
1624     XtSetArg(args[1], XtNy, y - 30);
1625     XtSetValues(popup, args, 2);
1626     
1627     XtPopup(popup, XtGrabExclusive);
1628     SettingsUp = True;
1629
1630     previous = NULL;
1631     SetFocus(edit, popup, (XEvent*) NULL, False);
1632 }
1633
1634 void FirstSettingsProc(w, event, prms, nprms)
1635      Widget w;
1636      XEvent *event;
1637      String *prms;
1638      Cardinal *nprms;
1639 {
1640    SettingsPopUp(&first);
1641 }
1642
1643 void SecondSettingsProc(w, event, prms, nprms)
1644      Widget w;
1645      XEvent *event;
1646      String *prms;
1647      Cardinal *nprms;
1648 {
1649    SettingsPopUp(&second);
1650 }
1651
1652 //--------------------------- General Popup for Cloning ----------------------------------
1653 #if 0
1654 int XXXUp;
1655 Widget XXXShell;
1656
1657 void XXXPopDown()
1658 {
1659     if (!XXXUp) return;
1660     XtPopdown(XXXShell);
1661     XtDestroyWidget(XXXShell);
1662     XXXUp = False;
1663     ModeHighlight();
1664 }
1665
1666 void XXXCallback(w, client_data, call_data)
1667      Widget w;
1668      XtPointer client_data, call_data;
1669 {
1670     String name;
1671     Widget w2;
1672     Arg args[16];
1673     char buf[80];
1674     
1675     XtSetArg(args[0], XtNlabel, &name);
1676     XtGetValues(w, args, 1);
1677     
1678     if (strcmp(name, _("cancel")) == 0) {
1679         XXXPopDown();
1680         return;
1681     }
1682     if (strcmp(name, _("ok")) == 0) {
1683         int nr; String name;
1684         name = XawDialogGetValueString(w2 = XtParent(w));
1685         if(sscanf(name ,"%d",&nr) != 1) {
1686             sprintf(buf, "%d", appData.defaultFrcPosition);
1687             XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
1688             XtSetValues(w2, args, 1);
1689             return;
1690         }
1691         XXXPopDown();
1692         return;
1693     }
1694 }
1695
1696 void XXXPopUp()
1697 {
1698     Arg args[16];
1699     Widget popup, layout, dialog, edit;
1700     Window root, child;
1701     int x, y, i;
1702     int win_x, win_y;
1703     unsigned int mask;
1704     char def[80];
1705     
1706     i = 0;
1707     XtSetArg(args[i], XtNresizable, True); i++;
1708     XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
1709     XXXShell = popup =
1710       XtCreatePopupShell(_("XXX Menu"), transientShellWidgetClass,
1711                          shellWidget, args, i);
1712     
1713     layout =
1714       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1715                             layoutArgs, XtNumber(layoutArgs));
1716   
1717     sprintf(def, "%d\n", appData.defaultFrcPosition);
1718     i = 0;
1719     XtSetArg(args[i], XtNlabel, ""); i++;
1720     XtSetArg(args[i], XtNvalue, def); i++;
1721     XtSetArg(args[i], XtNborderWidth, 0); i++;
1722     dialog = XtCreateManagedWidget("XXX", dialogWidgetClass,
1723                                    layout, args, i);
1724     
1725     XawDialogAddButton(dialog, _("ok"), XXXCallback, (XtPointer) dialog);
1726     XawDialogAddButton(dialog, _("cancel"), XXXCallback, (XtPointer) dialog);
1727     
1728     XtRealizeWidget(popup);
1729     CatchDeleteWindow(popup, "XXXPopDown");
1730     
1731     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1732                   &x, &y, &win_x, &win_y, &mask);
1733     
1734     XtSetArg(args[0], XtNx, x - 10);
1735     XtSetArg(args[1], XtNy, y - 30);
1736     XtSetValues(popup, args, 2);
1737     
1738     XtPopup(popup, XtGrabExclusive);
1739     XXXUp = True;
1740     
1741     edit = XtNameToWidget(dialog, "*value");
1742
1743     previous = NULL;
1744     SetFocus(engThreshold, popup, (XEvent*) NULL, False);
1745 }
1746
1747 void XXXMenuProc(w, event, prms, nprms)
1748      Widget w;
1749      XEvent *event;
1750      String *prms;
1751      Cardinal *nprms;
1752 {
1753    XXXPopUp();
1754 }
1755 #endif