allowe parsing / disambiguation of SAN moves like Xe4 in certain situations
[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 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
84 extern Display *xDisplay;
85 extern int squareSize;
86 extern Pixmap xMarkPixmap;
87 extern char *layoutName;
88 extern Window xBoardWindow;
89 extern Arg layoutArgs[2], formArgs[2];
90 Pixel timerForegroundPixel, timerBackgroundPixel;
91
92 // [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines
93
94 static Widget previous = NULL;
95
96 void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
97 {
98     Arg args;
99
100     if(previous) {
101         XtSetArg(args, XtNdisplayCaret, False);
102         XtSetValues(previous, &args, 1);
103     }
104     XtSetArg(args, XtNdisplayCaret, True);
105     XtSetValues(w, &args, 1);
106     XtSetKeyboardFocus((Widget) data, w);
107     previous = w;
108 }
109
110 //--------------------------- New Shuffle Game --------------------------------------------
111 extern int shuffleOpenings;
112 extern int startedFromPositionFile;
113 int shuffleUp;
114 Widget shuffleShell;
115
116 void ShufflePopDown()
117 {
118     if (!shuffleUp) return;
119     XtPopdown(shuffleShell);
120     XtDestroyWidget(shuffleShell);
121     shuffleUp = False;
122     ModeHighlight();
123 }
124
125 void ShuffleCallback(w, client_data, call_data)
126      Widget w;
127      XtPointer client_data, call_data;
128 {
129     String name;
130     Widget w2;
131     Arg args[16];
132     char buf[80];
133     
134     XtSetArg(args[0], XtNlabel, &name);
135     XtGetValues(w, args, 1);
136     
137     if (strcmp(name, _("cancel")) == 0) {
138         ShufflePopDown();
139         return;
140     }
141     if (strcmp(name, _("off")) == 0) {
142         ShufflePopDown();
143         shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it!
144         ResetGameEvent();
145         return;
146     }
147     if (strcmp(name, _("random")) == 0) {
148         sprintf(buf, "%d", rand());
149         XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
150         XtSetValues(XtParent(w), args, 1);
151         return;
152     }
153     if (strcmp(name, _("ok")) == 0) {
154         int nr; String name;
155         name = XawDialogGetValueString(w2 = XtParent(w));
156         if(sscanf(name ,"%d",&nr) != 1) {
157             sprintf(buf, "%d", appData.defaultFrcPosition);
158             XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
159             XtSetValues(w2, args, 1);
160             return;
161         }
162         appData.defaultFrcPosition = nr;
163         shuffleOpenings = True;
164         ShufflePopDown();
165         ResetGameEvent();
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     j=0;
1069     XtSetArg(args[j], XtNfromVert, buttonDesc[14].handle);  j++;
1070 //    XtSetArg(args[j], XtNheight, 70); j++;
1071     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
1072     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
1073     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
1074     XtSetArg(args[j], XtNright, XtChainRight);  j++;
1075     XtSetArg(args[j], XtNlabel, _("WARNING: variants with un-orthodox\n"
1076                                   "pieces only have built-in bitmaps\n"
1077                                   "for -boardSize middling, bulky and\n"
1078                                   "petite, and substitute king or amazon\n"
1079                                   "for missing bitmaps. (See manual.)")); j++;
1080     XtCreateManagedWidget("warning", labelWidgetClass, form, args, j);
1081
1082             XtRealizeWidget(popup);
1083     CatchDeleteWindow(popup, "NewVariantPopDown");
1084     
1085     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1086                   &x, &y, &win_x, &win_y, &mask);
1087     
1088     XtSetArg(args[0], XtNx, x - 10);
1089     XtSetArg(args[1], XtNy, y - 30);
1090     XtSetValues(popup, args, 2);
1091     
1092     XtPopup(popup, XtGrabExclusive);
1093     NewVariantUp = True;
1094 }
1095
1096 void NewVariantProc(w, event, prms, nprms)
1097      Widget w;
1098      XEvent *event;
1099      String *prms;
1100      Cardinal *nprms;
1101 {
1102    NewVariantPopUp();
1103 }
1104
1105 //--------------------------- UCI Menu Popup ------------------------------------------
1106 int UciUp;
1107 Widget UciShell;
1108
1109 struct UciControl {
1110   char *name;
1111   Widget handle;
1112   void *ptr;
1113 };
1114
1115 struct UciControl controlDesc[] = {
1116   {N_("maximum nr of CPUs:"), 0, &appData.smpCores},
1117   {N_("Polyglot Directory:"), 0, &appData.polyglotDir},
1118   {N_("Hash Size (MB):"),     0, &appData.defaultHashSize},
1119   {N_("EGTB Path:"),          0, &appData.defaultPathEGTB},
1120   {N_("EGTB Cache (MB):"),    0, &appData.defaultCacheSizeEGTB},
1121   {N_("Polyglot Book:"),      0, &appData.polyglotBook},
1122   {NULL, 0, NULL},
1123 };
1124
1125 void UciPopDown()
1126 {
1127     if (!UciUp) return;
1128     XtPopdown(UciShell);
1129     XtDestroyWidget(UciShell);
1130     UciUp = False;
1131     ModeHighlight();
1132 }
1133
1134 void UciCallback(w, client_data, call_data)
1135      Widget w;
1136      XtPointer client_data, call_data;
1137 {
1138     String name;
1139     Arg args[16];
1140     char buf[80];
1141     int oldCores = appData.smpCores, ponder = 0;
1142     
1143     XtSetArg(args[0], XtNlabel, &name);
1144     XtGetValues(w, args, 1);
1145     
1146     if (strcmp(name, _("OK")) == 0) {
1147         int nr, i, j; String name;
1148         for(i=0; i<6; i++) {
1149             XtSetArg(args[0], XtNstring, &name);
1150             XtGetValues(controlDesc[i].handle, args, 1);
1151             if(i&1) {
1152                 if(name)
1153                     *(char**) controlDesc[i].ptr = strdup(name);
1154             } else {
1155                 if(sscanf(name, "%d", &j) == 1) 
1156                     *(int*) controlDesc[i].ptr = j;
1157             }
1158         }
1159         XtSetArg(args[0], XtNstate, &appData.usePolyglotBook);
1160         XtGetValues(w1, args, 1);
1161         XtSetArg(args[0], XtNstate, &appData.firstHasOwnBookUCI);
1162         XtGetValues(w2, args, 1);
1163         XtSetArg(args[0], XtNstate, &appData.secondHasOwnBookUCI);
1164         XtGetValues(w3, args, 1);
1165         XtSetArg(args[0], XtNstate, &ponder);
1166         XtGetValues(w4, args, 1);
1167
1168         // adjust setting in other menu for duplicates 
1169         // (perhaps duplicates should be removed from general Option Menu?)
1170         XtSetArg(args[0], XtNleftBitmap, ponder ? xMarkPixmap : None);
1171         XtSetValues(XtNameToWidget(menuBarWidget,
1172                                    "menuOptions.Ponder Next Move"), args, 1);
1173
1174         // make sure changes are sent to first engine by re-initializing it
1175         // if it was already started pre-emptively at end of previous game
1176         if(gameMode == BeginningOfGame) Reset(True, True); else {
1177             // Some changed setting need immediate sending always.
1178             PonderNextMoveEvent(ponder);
1179             if(oldCores != appData.smpCores)
1180                 NewSettingEvent(False, "cores", appData.smpCores);
1181       }
1182       UciPopDown();
1183       return;
1184     }
1185 }
1186
1187 void UciPopUp()
1188 {
1189     Arg args[16];
1190     Widget popup, layout, dialog, edit, form, b_ok, b_cancel, last = NULL, new, upperLeft;
1191     Window root, child;
1192     int x, y, i, j;
1193     int win_x, win_y;
1194     unsigned int mask;
1195     char def[80];
1196     
1197     i = 0;
1198     XtSetArg(args[i], XtNresizable, True); i++;
1199 //    XtSetArg(args[i], XtNwidth, 300); i++;
1200     UciShell = popup =
1201       XtCreatePopupShell(_("Engine Settings"), transientShellWidgetClass,
1202                          shellWidget, args, i);
1203     
1204     layout =
1205       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1206                             layoutArgs, XtNumber(layoutArgs));
1207   
1208     
1209     form =
1210       XtCreateManagedWidget("form", formWidgetClass, layout,
1211                             formArgs, XtNumber(formArgs));
1212   
1213     j = 0;
1214     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
1215     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
1216     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
1217 //    XtSetArg(args[j], XtNheight, 20); j++;
1218     for(i = 0; controlDesc[i].name != NULL; i++) {
1219         j = 3;
1220         XtSetArg(args[j], XtNfromVert, last); j++;
1221 //      XtSetArg(args[j], XtNwidth, 130); j++;
1222         XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1223         XtSetArg(args[j], XtNright, XtChainLeft);  j++;
1224         XtSetArg(args[j], XtNborderWidth, 0); j++;
1225         new = XtCreateManagedWidget(controlDesc[i].name, labelWidgetClass, form, args, j);
1226         if(i==0) upperLeft = new;
1227
1228         j = 4;
1229         XtSetArg(args[j], XtNborderWidth, 1); j++;
1230         XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
1231         XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
1232         XtSetArg(args[j], XtNdisplayCaret, False);  j++;
1233         XtSetArg(args[j], XtNright, XtChainRight);  j++;
1234         XtSetArg(args[j], XtNresizable, True);  j++;
1235         XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++;
1236         if(i&1) {
1237             XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ? 
1238                                          * (char**) controlDesc[i].ptr : ""); j++;
1239         } else {
1240             sprintf(def, "%d", * (int*) controlDesc[i].ptr);
1241             XtSetArg(args[j], XtNstring, def); j++;
1242         }
1243         XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1244         controlDesc[i].handle = last =
1245             XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
1246         XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1247     }
1248
1249     j=0;
1250     XtSetArg(args[j], XtNfromHoriz, controlDesc[0].handle);  j++;
1251     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
1252     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
1253     XtSetArg(args[j], XtNleft, XtChainRight);  j++;
1254     XtSetArg(args[j], XtNright, XtChainRight);  j++;
1255     XtSetArg(args[j], XtNstate, appData.ponderNextMove);  j++;
1256     w4 = XtCreateManagedWidget(_("Ponder"), toggleWidgetClass, form, args, j);   
1257
1258     j=0;
1259     XtSetArg(args[j], XtNfromVert, last);  j++;
1260     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
1261     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
1262     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
1263     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
1264     b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);   
1265     XtAddCallback(b_ok, XtNcallback, UciCallback, (XtPointer) 0);
1266
1267     XtSetArg(args[j], XtNfromHoriz, b_ok);  j++;
1268     b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);   
1269     XtAddCallback(b_cancel, XtNcallback, UciPopDown, (XtPointer) 0);
1270
1271     j = 5;
1272     XtSetArg(args[j], XtNfromHoriz, upperLeft);  j++;
1273     XtSetArg(args[j], XtNstate, appData.usePolyglotBook);  j++;
1274     w1 = XtCreateManagedWidget(_(" use book "), toggleWidgetClass, form, args, j);   
1275 //    XtAddCallback(w1, XtNcallback, UciCallback, (XtPointer) 0);
1276
1277     j = 5;
1278     XtSetArg(args[j], XtNfromHoriz, w1);  j++;
1279     XtSetArg(args[j], XtNstate, appData.firstHasOwnBookUCI);  j++;
1280     w2 = XtCreateManagedWidget(_("own book 1"), toggleWidgetClass, form, args, j);   
1281 //    XtAddCallback(w2, XtNcallback, UciCallback, (XtPointer) 0);
1282
1283     j = 5;
1284     XtSetArg(args[j], XtNfromHoriz, w2);  j++;
1285     XtSetArg(args[j], XtNstate, appData.secondHasOwnBookUCI);  j++;
1286     w3 = XtCreateManagedWidget(_("own book 2"), toggleWidgetClass, form, args, j);   
1287 //    XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0);
1288
1289     XtRealizeWidget(popup);
1290     CatchDeleteWindow(popup, "UciPopDown");
1291     
1292     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1293                   &x, &y, &win_x, &win_y, &mask);
1294     
1295     XtSetArg(args[0], XtNx, x - 10);
1296     XtSetArg(args[1], XtNy, y - 30);
1297     XtSetValues(popup, args, 2);
1298     
1299     XtPopup(popup, XtGrabExclusive);
1300     UciUp = True;
1301
1302     previous = NULL;
1303     SetFocus(controlDesc[2].handle, popup, (XEvent*) NULL, False);
1304 //    XtSetKeyboardFocus(popup, controlDesc[1].handle);
1305 }
1306
1307 void UciMenuProc(w, event, prms, nprms)
1308      Widget w;
1309      XEvent *event;
1310      String *prms;
1311      Cardinal *nprms;
1312 {
1313    UciPopUp();
1314 }
1315
1316 //--------------------------- Engine-specific options menu ----------------------------------
1317
1318 int SettingsUp;
1319 Widget SettingsShell;
1320 int values[MAX_OPTIONS];
1321 ChessProgramState *currentCps;
1322
1323 void SettingsPopDown()
1324 {
1325     if (!SettingsUp) return;
1326     XtPopdown(SettingsShell);
1327     XtDestroyWidget(SettingsShell);
1328     SettingsUp = False;
1329     ModeHighlight();
1330 }
1331
1332 void SpinCallback(w, client_data, call_data)
1333      Widget w;
1334      XtPointer client_data, call_data;
1335 {
1336     String name, val;
1337     Widget w2;
1338     Arg args[16];
1339     char buf[MSG_SIZ];
1340     int i, j;
1341     
1342     XtSetArg(args[0], XtNlabel, &name);
1343     XtGetValues(w, args, 1);
1344     
1345     j = 0;
1346     XtSetArg(args[0], XtNstring, &val);
1347     XtGetValues(currentCps->option[(int)client_data].handle, args, 1);
1348     sscanf(val, "%d", &j);
1349     if (strcmp(name, "+") == 0) {
1350         if(++j > currentCps->option[(int)client_data].max) return;
1351     } else
1352     if (strcmp(name, "-") == 0) {
1353         if(--j < currentCps->option[(int)client_data].min) return;
1354     } else return;
1355     sprintf(buf, "%d", j);
1356     XtSetArg(args[0], XtNstring, buf);
1357     XtSetValues(currentCps->option[(int)client_data].handle, args, 1);
1358 }
1359
1360 void SettingsCallback(w, client_data, call_data)
1361      Widget w;
1362      XtPointer client_data, call_data;
1363 {
1364     String name, val;
1365     Widget w2;
1366     Arg args[16];
1367     char buf[MSG_SIZ];
1368     int i, j;
1369     
1370     XtSetArg(args[0], XtNlabel, &name);
1371     XtGetValues(w, args, 1);
1372     
1373     if (strcmp(name, _("cancel")) == 0) {
1374         SettingsPopDown();
1375         return;
1376     }
1377     if (strcmp(name, _("OK")) == 0 || (int)client_data) { // save buttons imply OK
1378         int nr;
1379
1380         for(i=0; i<currentCps->nrOptions; i++) { // send all options that had to be OK-ed to engine
1381             switch(currentCps->option[i].type) {
1382                 case TextBox:
1383                     XtSetArg(args[0], XtNstring, &val);
1384                     XtGetValues(currentCps->option[i].handle, args, 1);
1385                     if(strcmp(currentCps->option[i].textValue, val)) {
1386                         strcpy(currentCps->option[i].textValue, val);
1387                         sprintf(buf, "option %s=%s\n", currentCps->option[i].name, val);
1388                         SendToProgram(buf, currentCps);
1389                     }
1390                     break;
1391                 case Spin:
1392                     XtSetArg(args[0], XtNstring, &val);
1393                     XtGetValues(currentCps->option[i].handle, args, 1);
1394                     sscanf(val, "%d", &j);
1395                     if(j > currentCps->option[i].max) j = currentCps->option[i].max;
1396                     if(j < currentCps->option[i].min) j = currentCps->option[i].min;
1397                     if(currentCps->option[i].value != j) {
1398                         currentCps->option[i].value = j;
1399                         sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1400                         SendToProgram(buf, currentCps);
1401                     }
1402                     break;
1403                 case CheckBox:
1404                     j = 0;
1405                     XtSetArg(args[0], XtNstate, &j);
1406                     XtGetValues(currentCps->option[i].handle, args, 1);
1407                     if(currentCps->option[i].value != j) {
1408                         currentCps->option[i].value = j;
1409                         sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1410                         SendToProgram(buf, currentCps);
1411                     }
1412                     break;
1413                 case ComboBox:
1414                     if(currentCps->option[i].value != values[i]) {
1415                         currentCps->option[i].value = values[i];
1416                         sprintf(buf, "option %s=%s\n", currentCps->option[i].name, 
1417                                 ((char**)currentCps->option[i].textValue)[values[i]]);
1418                         SendToProgram(buf, currentCps);
1419                     }
1420                     break;
1421             }
1422         }
1423         if((int)client_data) { // send save-button command to engine
1424             sprintf(buf, "option %s\n", name);
1425             SendToProgram(buf, currentCps);
1426         }
1427         SettingsPopDown();
1428         return;
1429     }
1430     sprintf(buf, "option %s\n", name);
1431     SendToProgram(buf, currentCps);
1432 }
1433
1434 void ComboSelect(w, addr, index) // callback for all combo items
1435      Widget w;
1436      caddr_t addr;
1437      caddr_t index;
1438 {
1439     Arg args[16];
1440     int i = ((int)addr)>>8;
1441     int j = 255 & (int) addr;
1442
1443     values[i] = j; // store in temporary, for transfer at OK
1444     XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]);
1445     XtSetValues(currentCps->option[i].handle, args, 1);
1446 }
1447
1448 void CreateComboPopup(parent, name, n, mb)
1449      Widget parent;
1450      String name;
1451      int n;
1452      char *mb[];
1453 {
1454     int i=0, j;
1455     Widget menu, entry;
1456     Arg args[16];
1457
1458     menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
1459                               parent, NULL, 0);
1460     j = 0;
1461     XtSetArg(args[j], XtNwidth, 100);  j++;
1462 //    XtSetArg(args[j], XtNright, XtChainRight);  j++;
1463     while (mb[i] != NULL) {
1464             entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
1465                                           menu, args, j);
1466             XtAddCallback(entry, XtNcallback,
1467                           (XtCallbackProc) ComboSelect,
1468                           (caddr_t) (256*n+i));
1469         i++;
1470     }
1471 }       
1472
1473 void SettingsPopUp(ChessProgramState *cps)
1474 {
1475     Arg args[16];
1476     Widget popup, layout, dialog, edit=NULL, form, oldform, last, b_ok, b_cancel, leftMargin = NULL;
1477     Window root, child;
1478     int x, y, i, j, height, width, h, c;
1479     int win_x, win_y;
1480     unsigned int mask;
1481     char def[80], *p, *q;
1482     static char pane[6] = "paneX";
1483
1484     // to do: start up second engine if needed
1485     if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
1486     currentCps = cps;
1487
1488     if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1;
1489     height = cps->nrOptions / width + 1;
1490      i = 0;
1491     XtSetArg(args[i], XtNresizable, True); i++;
1492     SettingsShell = popup =
1493       XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
1494                          shellWidget, args, i);
1495     
1496     layout =
1497       XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1498                             layoutArgs, XtNumber(layoutArgs));
1499   for(c=0; c<width; c++) {
1500     pane[4] = 'A'+c;
1501     form =
1502       XtCreateManagedWidget(pane, formWidgetClass, layout,
1503                             formArgs, XtNumber(formArgs));
1504     j=0;
1505     XtSetArg(args[j], XtNfromHoriz, leftMargin);  j++;
1506     XtSetValues(form, args, j);
1507     leftMargin = form;
1508  
1509     last = NULL;
1510     for(h=0; h<height; h++) {
1511         i = h + c*height;
1512         if(i >= cps->nrOptions) break;
1513         switch(cps->option[i].type) {
1514           case Spin:
1515             sprintf(def, "%d", cps->option[i].value);
1516           case TextBox:
1517             j=0;
1518             XtSetArg(args[j], XtNfromVert, last);  j++;
1519             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1520             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1521             dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);   
1522             j=0;
1523             XtSetArg(args[j], XtNfromVert, last);  j++;
1524             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1525             XtSetArg(args[j], XtNborderWidth, 1); j++;
1526             XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 100); j++;
1527             XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
1528             XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
1529             XtSetArg(args[j], XtNdisplayCaret, False);  j++;
1530             XtSetArg(args[j], XtNright, XtChainRight);  j++;
1531             XtSetArg(args[j], XtNresizable, True);  j++;
1532             XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue);  j++;
1533             edit = last;
1534             cps->option[i].handle = (void*)
1535                 (last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));   
1536             XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1537             if(cps->option[i].type == TextBox) break;
1538
1539             // add increment and decrement controls for spin
1540             j=0;
1541             XtSetArg(args[j], XtNfromVert, edit);  j++;
1542             XtSetArg(args[j], XtNfromHoriz, last);  j++;
1543             XtSetArg(args[j], XtNheight, 10);  j++;
1544             XtSetArg(args[j], XtNwidth, 20);  j++;
1545             edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j);
1546             XtAddCallback(edit, XtNcallback, SpinCallback, (XtPointer) i);
1547
1548             j=0;
1549             XtSetArg(args[j], XtNfromVert, edit);  j++;
1550             XtSetArg(args[j], XtNfromHoriz, last);  j++;
1551             XtSetArg(args[j], XtNheight, 10);  j++;
1552             XtSetArg(args[j], XtNwidth, 20);  j++;
1553             last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1554             XtAddCallback(last, XtNcallback, SpinCallback, (XtPointer) i);
1555             break;
1556           case CheckBox:
1557             j=0;
1558             XtSetArg(args[j], XtNfromVert, last);  j++;
1559             XtSetArg(args[j], XtNwidth, 10);  j++;
1560             XtSetArg(args[j], XtNheight, 10);  j++;
1561             XtSetArg(args[j], XtNstate, cps->option[i].value);  j++;
1562             cps->option[i].handle = (void*) 
1563                 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));   
1564             j=0;
1565             XtSetArg(args[j], XtNfromVert, last);  j++;
1566             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1567             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1568             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1569             last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1570             break;
1571           case SaveButton:
1572           case Button:
1573             j=0;
1574             XtSetArg(args[j], XtNfromVert, last);  j++;
1575             XtSetArg(args[j], XtNstate, cps->option[i].value);  j++;
1576             cps->option[i].handle = (void*) 
1577                 (last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));   
1578             XtAddCallback(last, XtNcallback, SettingsCallback, (XtPointer) (cps->option[i].type == SaveButton));
1579             break;
1580           case ComboBox:
1581             j=0;
1582             XtSetArg(args[j], XtNfromVert, last);  j++;
1583             XtSetArg(args[j], XtNborderWidth, 0);  j++;
1584             XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
1585             dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1586
1587             j=0;
1588             XtSetArg(args[j], XtNfromVert, last);  j++;
1589             XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
1590             XtSetArg(args[j], XtNwidth, 100);  j++;
1591             XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name));  j++;
1592             XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]);  j++;
1593             cps->option[i].handle = (void*) 
1594                 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));   
1595             CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue);
1596             values[i] = cps->option[i].value;
1597             break;
1598         }
1599     }
1600   }
1601     j=0;
1602     XtSetArg(args[j], XtNfromVert, last);  j++;
1603     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
1604     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
1605     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
1606     XtSetArg(args[j], XtNright, XtChainLeft);  j++;
1607     b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);   
1608     XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
1609
1610     XtSetArg(args[j], XtNfromHoriz, b_ok);  j++;
1611     b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);   
1612     XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
1613
1614     XtRealizeWidget(popup);
1615     CatchDeleteWindow(popup, "SettingsPopDown");
1616     
1617     XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1618                   &x, &y, &win_x, &win_y, &mask);
1619     
1620     XtSetArg(args[0], XtNx, x - 10);
1621     XtSetArg(args[1], XtNy, y - 30);
1622     XtSetValues(popup, args, 2);
1623     
1624     XtPopup(popup, XtGrabExclusive);
1625     SettingsUp = True;
1626
1627     previous = NULL;
1628     if(edit)SetFocus(edit, popup, (XEvent*) NULL, False);
1629 }
1630
1631 void FirstSettingsProc(w, event, prms, nprms)
1632      Widget w;
1633      XEvent *event;
1634      String *prms;
1635      Cardinal *nprms;
1636 {
1637    SettingsPopUp(&first);
1638 }
1639
1640 void SecondSettingsProc(w, event, prms, nprms)
1641      Widget w;
1642      XEvent *event;
1643      String *prms;
1644      Cardinal *nprms;
1645 {
1646    SettingsPopUp(&second);
1647 }
1648
1649 //---------------------------- Chat Windows ----------------------------------------------
1650
1651 void OutputChatMessage(int partner, char *mess)
1652 {
1653     return; // dummy
1654 }
1655