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