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