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