2 * xoptions.c -- Move list window, part of X front end for XBoard
4 * Copyright 2000, 2009, 2010 Free Software Foundation, Inc.
5 * ------------------------------------------------------------------------
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.
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.
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/. *
20 *------------------------------------------------------------------------
21 ** See the file ChangeLog for a revision history. */
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.
31 #include <sys/types.h>
36 #else /* not STDC_HEADERS */
37 extern char *getenv();
40 # else /* not HAVE_STRING_H */
42 # endif /* not HAVE_STRING_H */
43 #endif /* not STDC_HEADERS */
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>
75 # define _(s) gettext (s)
76 # define N_(s) gettext_noop (s)
82 extern void SendToProgram P((char *message, ChessProgramState *cps));
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 extern int searchTime;
94 // [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines
96 static Widget previous = NULL;
98 void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
103 XtSetArg(args, XtNdisplayCaret, False);
104 XtSetValues(previous, &args, 1);
106 XtSetArg(args, XtNdisplayCaret, True);
107 XtSetValues(w, &args, 1);
108 XtSetKeyboardFocus((Widget) data, w);
112 //--------------------------- New Shuffle Game --------------------------------------------
113 extern int shuffleOpenings;
114 extern int startedFromPositionFile;
118 void ShufflePopDown()
120 if (!shuffleUp) return;
121 XtPopdown(shuffleShell);
122 XtDestroyWidget(shuffleShell);
127 void ShuffleCallback(w, client_data, call_data)
129 XtPointer client_data, call_data;
136 XtSetArg(args[0], XtNlabel, &name);
137 XtGetValues(w, args, 1);
139 if (strcmp(name, _("cancel")) == 0) {
143 if (strcmp(name, _("off")) == 0) {
145 shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it!
149 if (strcmp(name, _("random")) == 0) {
150 sprintf(buf, "%d", rand());
151 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
152 XtSetValues(XtParent(w), args, 1);
155 if (strcmp(name, _("ok")) == 0) {
157 name = XawDialogGetValueString(w2 = XtParent(w));
158 if(sscanf(name ,"%d",&nr) != 1) {
159 sprintf(buf, "%d", appData.defaultFrcPosition);
160 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
161 XtSetValues(w2, args, 1);
164 appData.defaultFrcPosition = nr;
165 shuffleOpenings = True;
175 Widget popup, layout, dialog, edit;
183 XtSetArg(args[i], XtNresizable, True); i++;
184 XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
185 shuffleShell = popup =
186 XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass,
187 shellWidget, args, i);
190 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
191 layoutArgs, XtNumber(layoutArgs));
193 sprintf(def, "%d\n", appData.defaultFrcPosition);
195 XtSetArg(args[i], XtNlabel, _("Start-position number:")); i++;
196 XtSetArg(args[i], XtNvalue, def); i++;
197 XtSetArg(args[i], XtNborderWidth, 0); i++;
198 dialog = XtCreateManagedWidget(_("Shuffle"), dialogWidgetClass,
201 // XtSetArg(args[0], XtNeditType, XawtextEdit); // [HGM] can't get edit to work decently
202 // XtSetArg(args[1], XtNuseStringInPlace, False);
203 // XtSetValues(dialog, args, 2);
205 XawDialogAddButton(dialog, _("ok"), ShuffleCallback, (XtPointer) dialog);
206 XawDialogAddButton(dialog, _("cancel"), ShuffleCallback, (XtPointer) dialog);
207 XawDialogAddButton(dialog, _("random"), ShuffleCallback, (XtPointer) dialog);
208 XawDialogAddButton(dialog, _("off"), ShuffleCallback, (XtPointer) dialog);
210 XtRealizeWidget(popup);
211 CatchDeleteWindow(popup, "ShufflePopDown");
213 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
214 &x, &y, &win_x, &win_y, &mask);
216 XtSetArg(args[0], XtNx, x - 10);
217 XtSetArg(args[1], XtNy, y - 30);
218 XtSetValues(popup, args, 2);
220 XtPopup(popup, XtGrabExclusive);
223 edit = XtNameToWidget(dialog, "*value");
225 XtSetKeyboardFocus(popup, edit);
228 void ShuffleMenuProc(w, event, prms, nprms)
234 // if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
235 // Reset(FALSE, TRUE);
240 //--------------------------- Time-Control Menu Popup ----------------------------------
242 Widget TimeControlShell;
244 Widget tcMess1, tcMess2, tcData, tcTime, tcOdds1, tcOdds2;
245 int tcIncrement, tcMoves;
247 void TimeControlPopDown()
249 if (!TimeControlUp) return;
251 XtPopdown(TimeControlShell);
252 XtDestroyWidget(TimeControlShell);
253 TimeControlUp = False;
257 void TimeControlCallback(w, client_data, call_data)
259 XtPointer client_data, call_data;
267 XtSetArg(args[0], XtNlabel, &name);
268 XtGetValues(w, args, 1);
270 if (strcmp(name, _("classical")) == 0) {
271 if(tcInc == 0) return;
273 XtSetArg(args[j], XtNlabel, _("minutes for each")); j++;
274 XtSetValues(tcMess1, args, j);
276 XtSetArg(args[j], XtNlabel, _("moves")); j++;
277 XtSetValues(tcMess2, args, j);
280 XtSetArg(args[j], XtNstring, &name); j++;
281 XtGetValues(tcData, args, j);
282 tcIncrement = 0; sscanf(name, "%d", &tcIncrement);
284 sprintf(buf, "%d", tcMoves);
286 XtSetArg(args[j], XtNstring, buf); j++;
287 XtSetValues(tcData, args, j);
291 if (strcmp(name, _("incremental")) == 0) {
292 if(tcInc == 1) return;
294 XtSetArg(args[j], XtNlabel, _("minutes, plus")); j++;
295 XtSetValues(tcMess1, args, j);
297 XtSetArg(args[j], XtNlabel, _("sec/move")); j++;
298 XtSetValues(tcMess2, args, j);
301 XtSetArg(args[j], XtNstring, &name); j++;
302 XtGetValues(tcData, args, j);
303 tcMoves = appData.movesPerSession; sscanf(name, "%d", &tcMoves);
305 sprintf(buf, "%d", tcIncrement);
307 XtSetArg(args[j], XtNstring, buf); j++;
308 XtSetValues(tcData, args, j);
312 if (strcmp(name, _("fixed time")) == 0) {
313 if(tcInc == 2) return;
315 XtSetArg(args[j], XtNlabel, _("sec/move (max)")); j++;
316 XtSetValues(tcMess1, args, j);
318 XtSetArg(args[j], XtNlabel, _("")); j++;
319 XtSetValues(tcMess2, args, j);
321 XtSetArg(args[j], XtNstring, ""); j++;
322 XtSetValues(tcData, args, j);
326 if (strcmp(name, _(" OK ")) == 0) {
327 int inc, mps, tc, ok;
328 XtSetArg(args[0], XtNstring, &txt);
329 XtGetValues(tcData, args, 1);
332 ok = sscanf(txt, "%d", &inc); mps = 0;
333 if(!ok && txt[0] == 0) { inc = 0; ok = 1; } // accept empty string as zero
337 ok = sscanf(txt, "%d", &mps); inc = -1;
341 ok = 1; inc = -1; mps = 40;
344 XtSetArg(args[0], XtNstring, ""); // erase any offending input
345 XtSetValues(tcData, args, 1);
348 XtSetArg(args[0], XtNstring, &txt);
349 XtGetValues(tcTime, args, 1);
351 if(sscanf(txt, "%d", &inc) != 1) {
352 XtSetArg(args[0], XtNstring, ""); // erase any offending input
353 XtSetValues(tcTime, args, 1);
354 DisplayError(_("Bad Time-Control String"), 0);
359 if(!ParseTimeControl(txt, inc, mps)) {
360 XtSetArg(args[0], XtNstring, ""); // erase any offending input
361 XtSetValues(tcTime, args, 1);
362 DisplayError(_("Bad Time-Control String"), 0);
366 appData.movesPerSession = mps;
367 appData.timeIncrement = inc;
368 appData.timeControl = strdup(txt);
370 XtSetArg(args[0], XtNstring, &txt);
371 XtGetValues(tcOdds1, args, 1);
372 appData.firstTimeOdds = first.timeOdds
373 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
374 XtGetValues(tcOdds2, args, 1);
375 appData.secondTimeOdds = second.timeOdds
376 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
379 TimeControlPopDown();
384 void TimeControlPopUp()
387 Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, mess;
394 tcInc = searchTime > 0 ? 2 : (appData.timeIncrement >= 0);
395 tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
396 if(!tcInc) tcIncrement = 0;
397 sprintf(def, "%d", tcInc ? tcIncrement : tcMoves);
400 XtSetArg(args[i], XtNresizable, True); i++;
401 // XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
402 TimeControlShell = popup =
403 XtCreatePopupShell(_("TimeControl Menu"), transientShellWidgetClass,
404 shellWidget, args, i);
407 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
408 layoutArgs, XtNumber(layoutArgs));
411 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
412 formArgs, XtNumber(formArgs));
415 // XtSetArg(args[j], XtNwidth, (XtArgVal) 300); j++;
416 // XtSetArg(args[j], XtNheight, (XtArgVal) 85); j++;
417 XtSetValues(popup, args, j);
420 XtSetArg(args[j], XtNborderWidth, 1); j++;
421 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
422 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
423 XtSetArg(args[j], XtNstring, appData.timeControl); j++;
424 XtSetArg(args[j], XtNdisplayCaret, False); j++;
425 XtSetArg(args[j], XtNtop, XtChainTop); j++;
426 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
427 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
428 XtSetArg(args[j], XtNright, XtChainRight); j++;
429 XtSetArg(args[j], XtNresizable, True); j++;
430 XtSetArg(args[j], XtNwidth, 85); j++;
431 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
432 tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j);
433 XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup);
436 XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _("sec/move (max) ") : _(" minutes, plus ") : _("minutes for each")); j++;
437 XtSetArg(args[j], XtNborderWidth, 0); j++;
438 XtSetArg(args[j], XtNfromHoriz, tcTime); j++;
439 XtSetArg(args[j], XtNtop, XtChainTop); j++;
440 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
441 XtSetArg(args[j], XtNleft, XtChainRight); j++;
442 XtSetArg(args[j], XtNright, XtChainRight); j++;
443 // XtSetArg(args[j], XtNwidth, 100); j++;
444 // XtSetArg(args[j], XtNheight, 20); j++;
445 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
448 XtSetArg(args[j], XtNborderWidth, 1); j++;
449 XtSetArg(args[j], XtNfromHoriz, tcMess1); j++;
450 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
451 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
452 XtSetArg(args[j], XtNstring, def); j++;
453 XtSetArg(args[j], XtNdisplayCaret, False); j++;
454 XtSetArg(args[j], XtNtop, XtChainTop); j++;
455 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
456 XtSetArg(args[j], XtNleft, XtChainRight); j++;
457 XtSetArg(args[j], XtNright, XtChainRight); j++;
458 XtSetArg(args[j], XtNresizable, True); j++;
459 XtSetArg(args[j], XtNwidth, 40); j++;
460 // XtSetArg(args[j], XtNheight, 20); j++;
461 tcData = XtCreateManagedWidget("MPS", asciiTextWidgetClass, form, args, j);
462 XtAddEventHandler(tcData, ButtonPressMask, False, SetFocus, (XtPointer) popup);
465 XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _(" ") : _("sec/move") : _("moves ")); j++;
466 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
467 XtSetArg(args[j], XtNborderWidth, 0); j++;
468 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
469 XtSetArg(args[j], XtNtop, XtChainTop); j++;
470 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
471 XtSetArg(args[j], XtNleft, XtChainRight); j++;
472 XtSetArg(args[j], XtNright, XtChainRight); j++;
473 // XtSetArg(args[j], XtNwidth, 80); j++;
474 // XtSetArg(args[j], XtNheight, 20); j++;
475 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass,
479 XtSetArg(args[j], XtNborderWidth, 1); j++;
480 XtSetArg(args[j], XtNfromVert, tcTime); j++;
481 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
482 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
483 XtSetArg(args[j], XtNstring, "1"); j++;
484 XtSetArg(args[j], XtNdisplayCaret, False); j++;
485 XtSetArg(args[j], XtNtop, XtChainTop); j++;
486 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
487 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
488 XtSetArg(args[j], XtNright, XtChainLeft); j++;
489 XtSetArg(args[j], XtNresizable, True); j++;
490 XtSetArg(args[j], XtNwidth, 40); j++;
491 // XtSetArg(args[j], XtNheight, 20); j++;
492 tcOdds1 = XtCreateManagedWidget("Odds1", asciiTextWidgetClass, form, args, j);
493 XtAddEventHandler(tcOdds1, ButtonPressMask, False, SetFocus, (XtPointer) popup);
496 XtSetArg(args[j], XtNborderWidth, 1); j++;
497 XtSetArg(args[j], XtNfromVert, tcTime); j++;
498 XtSetArg(args[j], XtNfromHoriz, tcOdds1); j++;
499 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
500 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
501 XtSetArg(args[j], XtNstring, "1"); j++;
502 XtSetArg(args[j], XtNdisplayCaret, False); j++;
503 XtSetArg(args[j], XtNtop, XtChainTop); j++;
504 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
505 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
506 XtSetArg(args[j], XtNright, XtChainLeft); j++;
507 XtSetArg(args[j], XtNresizable, True); j++;
508 XtSetArg(args[j], XtNwidth, 40); j++;
509 // XtSetArg(args[j], XtNheight, 20); j++;
510 tcOdds2 = XtCreateManagedWidget("Odds2", asciiTextWidgetClass, form, args, j);
511 XtAddEventHandler(tcOdds2, ButtonPressMask, False, SetFocus, (XtPointer) popup);
514 XtSetArg(args[j], XtNlabel, _("Engine #1 and #2 Time-Odds Factors")); j++;
515 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
516 XtSetArg(args[j], XtNborderWidth, 0); j++;
517 XtSetArg(args[j], XtNfromVert, tcTime); j++;
518 XtSetArg(args[j], XtNfromHoriz, tcOdds2); j++;
519 XtSetArg(args[j], XtNtop, XtChainTop); j++;
520 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
521 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
522 XtSetArg(args[j], XtNright, XtChainRight); j++;
523 // XtSetArg(args[j], XtNwidth, 200); j++;
524 // XtSetArg(args[j], XtNheight, 20); j++;
525 mess = XtCreateManagedWidget("Oddstext", labelWidgetClass,
528 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
529 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
530 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
531 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
532 XtSetArg(args[j], XtNright, XtChainLeft); j++;
533 XtSetArg(args[j], XtNstate, tcInc==0); j++;
534 b_clas= XtCreateManagedWidget(_("classical"), toggleWidgetClass,
536 XtAddCallback(b_clas, XtNcallback, TimeControlCallback, (XtPointer) 0);
539 XtSetArg(args[j], XtNradioGroup, b_clas); j++;
540 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
541 XtSetArg(args[j], XtNfromHoriz, b_clas); j++;
542 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
543 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
544 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
545 XtSetArg(args[j], XtNright, XtChainLeft); j++;
546 XtSetArg(args[j], XtNstate, tcInc==1); j++;
547 b_inc = XtCreateManagedWidget(_("incremental"), toggleWidgetClass,
549 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
552 XtSetArg(args[j], XtNradioGroup, b_inc); j++;
553 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
554 XtSetArg(args[j], XtNfromHoriz, b_inc); j++;
555 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
556 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
557 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
558 XtSetArg(args[j], XtNright, XtChainLeft); j++;
559 XtSetArg(args[j], XtNstate, tcInc==2); j++;
560 b_inc = XtCreateManagedWidget(_("fixed time"), toggleWidgetClass,
562 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
565 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
566 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
567 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
568 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
569 XtSetArg(args[j], XtNleft, XtChainRight); j++;
570 XtSetArg(args[j], XtNright, XtChainRight); j++;
571 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass,
573 XtAddCallback(b_ok, XtNcallback, TimeControlCallback, (XtPointer) 0);
576 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
577 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
578 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
579 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
580 XtSetArg(args[j], XtNleft, XtChainRight); j++;
581 XtSetArg(args[j], XtNright, XtChainRight); j++;
582 b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
584 XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0);
586 XtRealizeWidget(popup);
587 CatchDeleteWindow(popup, "TimeControlPopDown");
589 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
590 &x, &y, &win_x, &win_y, &mask);
592 XtSetArg(args[0], XtNx, x - 10);
593 XtSetArg(args[1], XtNy, y - 30);
594 XtSetValues(popup, args, 2);
596 XtPopup(popup, XtGrabExclusive);
597 TimeControlUp = True;
600 SetFocus(tcTime, popup, (XEvent*) NULL, False);
601 // XtSetKeyboardFocus(popup, tcTime);
604 void TimeControlProc(w, event, prms, nprms)
613 //--------------------------- Engine-Options Menu Popup ----------------------------------
616 extern int adjudicateLossThreshold;
618 Widget engDrawMoves, engThreshold, engRule, engRepeat;
622 if (!EngineUp) return;
624 XtPopdown(EngineShell);
625 XtDestroyWidget(EngineShell);
630 int ReadToggle(Widget w)
632 Arg args; Boolean res;
634 XtSetArg(args, XtNstate, &res);
635 XtGetValues(w, &args, 1);
640 Widget w1, w2, w3, w4, w5, w6, w7, w8;
642 void EngineCallback(w, client_data, call_data)
644 XtPointer client_data, call_data;
652 XtSetArg(args[0], XtNlabel, &name);
653 XtGetValues(w, args, 1);
655 if (strcmp(name, _("OK")) == 0) {
657 appData.periodicUpdates = ReadToggle(w1);
658 // appData.hideThinkingFromHuman = ReadToggle(w2);
659 first.scoreIsAbsolute = appData.firstScoreIsAbsolute = ReadToggle(w3);
660 second.scoreIsAbsolute = appData.secondScoreIsAbsolute = ReadToggle(w4);
661 appData.testClaims = ReadToggle(w5);
662 appData.checkMates = ReadToggle(w6);
663 appData.materialDraws = ReadToggle(w7);
664 appData.trivialDraws = ReadToggle(w8);
666 // adjust setting in other menu for duplicates
667 // (perhaps duplicates should be removed from general Option Menu?)
668 // XtSetArg(args[0], XtNleftBitmap, appData.showThinking ? xMarkPixmap : None);
669 // XtSetValues(XtNameToWidget(menuBarWidget,
670 // "menuOptions.Show Thinking"), args, 1);
672 // read out numeric controls, simply ignore bad formats for now
673 XtSetArg(args[0], XtNstring, &name);
674 XtGetValues(engDrawMoves, args, 1);
675 if(sscanf(name, "%d", &j) == 1) appData.adjudicateDrawMoves = j;
676 XtGetValues(engThreshold, args, 1);
677 if(sscanf(name, "%d", &j) == 1)
678 adjudicateLossThreshold = appData.adjudicateLossThreshold = -j; // inverted!
679 XtGetValues(engRule, args, 1);
680 if(sscanf(name, "%d", &j) == 1) appData.ruleMoves = j;
681 XtGetValues(engRepeat, args, 1);
682 if(sscanf(name, "%d", &j) == 1) appData.drawRepeats = j;
685 ShowThinkingEvent(); // [HGM] thinking: score adjudication might need thinking output
693 Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, s1;
695 int x, y, i, j, width;
700 tcInc = (appData.timeIncrement >= 0);
701 tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
702 if(!tcInc) tcIncrement = 0;
703 sprintf(def, "%d", tcInc ? tcIncrement : tcMoves);
706 XtSetArg(args[i], XtNresizable, True); i++;
707 // XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
708 EngineShell = popup =
709 XtCreatePopupShell(_("Adjudications"), transientShellWidgetClass,
710 shellWidget, args, i);
713 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
714 layoutArgs, XtNumber(layoutArgs));
717 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
718 formArgs, XtNumber(formArgs));
721 // XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++;
722 // XtSetArg(args[j], XtNheight, (XtArgVal) 400); j++;
723 // XtSetValues(popup, args, j);
726 // XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++;
727 // XtSetArg(args[j], XtNheight, (XtArgVal) 20); j++;
728 XtSetArg(args[j], XtNleft, (XtArgVal) XtChainLeft); j++;
729 XtSetArg(args[j], XtNright, (XtArgVal) XtChainRight); j++;
730 XtSetArg(args[j], XtNstate, appData.periodicUpdates); j++;
731 // XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
732 w1 = XtCreateManagedWidget(_("Periodic Updates (Analysis Mode)"), toggleWidgetClass, form, args, j);
734 XtSetArg(args[j], XtNwidth, (XtArgVal) &width);
735 XtGetValues(w1, &args[j], 1);
737 // XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w1);
738 // XtSetArg(args[j-3], XtNstate, appData.hideThinkingFromHuman);
739 // w2 = XtCreateManagedWidget(_("Hide Thinking from Human"), toggleWidgetClass, form, args, j);
741 XtSetArg(args[j], XtNwidth, (XtArgVal) width); j++;
742 XtSetArg(args[j-2], XtNstate, appData.firstScoreIsAbsolute);
743 XtSetArg(args[j], XtNfromVert, (XtArgVal) w1); j++;
744 w3 = XtCreateManagedWidget(_("Engine #1 Score is Absolute"), toggleWidgetClass, form, args, j);
746 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w3);
747 XtSetArg(args[j-3], XtNstate, appData.secondScoreIsAbsolute);
748 w4 = XtCreateManagedWidget(_("Engine #2 Score is Absolute"), toggleWidgetClass, form, args, j);
750 s1 = XtCreateManagedWidget(_("\nAdjudications in non-ICS games:"), labelWidgetClass, form, args, 3);
752 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) s1);
753 XtSetArg(args[j-3], XtNstate, appData.testClaims);
754 w5 = XtCreateManagedWidget(_("Verify Engine Result Claims"), toggleWidgetClass, form, args, j);
756 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w5);
757 XtSetArg(args[j-3], XtNstate, appData.checkMates);
758 w6 = XtCreateManagedWidget(_("Detect All Mates"), toggleWidgetClass, form, args, j);
760 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w6);
761 XtSetArg(args[j-3], XtNstate, appData.materialDraws);
762 w7 = XtCreateManagedWidget(_("Draw when Insuff. Mating Material"), toggleWidgetClass, form, args, j);
764 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w7);
765 XtSetArg(args[j-3], XtNstate, appData.trivialDraws);
766 w8 = XtCreateManagedWidget(_("Adjudicate Trivial Draws"), toggleWidgetClass, form, args, j);
768 XtSetArg(args[0], XtNfromVert, (XtArgVal) w4);
769 XtSetArg(args[1], XtNborderWidth, (XtArgVal) 0);
770 XtSetValues(s1, args, 2);
772 sprintf(def, "%d", appData.adjudicateDrawMoves);
774 XtSetArg(args[j], XtNborderWidth, 1); j++;
775 XtSetArg(args[j], XtNfromVert, w8); j++;
776 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
777 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
778 XtSetArg(args[j], XtNstring, def); j++;
779 XtSetArg(args[j], XtNdisplayCaret, False); j++;
780 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
781 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
782 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
783 XtSetArg(args[j], XtNright, XtChainLeft); j++;
784 XtSetArg(args[j], XtNresizable, True); j++;
785 XtSetArg(args[j], XtNwidth, 60); j++;
786 // XtSetArg(args[j], XtNheight, 20); j++;
787 engDrawMoves = XtCreateManagedWidget("Length", asciiTextWidgetClass, form, args, j);
788 XtAddEventHandler(engDrawMoves, ButtonPressMask, False, SetFocus, (XtPointer) popup);
791 XtSetArg(args[j], XtNlabel, _(" moves maximum, then draw")); j++;
792 XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
793 XtSetArg(args[j], XtNborderWidth, 0); j++;
794 XtSetArg(args[j], XtNfromVert, w8); j++;
795 XtSetArg(args[j], XtNfromHoriz, engDrawMoves); j++;
796 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
797 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
798 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
799 XtSetArg(args[j], XtNright, XtChainLeft); j++;
800 // XtSetArg(args[j], XtNwidth, 170); j++;
801 // XtSetArg(args[j], XtNheight, 20); j++;
802 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
804 sprintf(def, "%d", -appData.adjudicateLossThreshold); // inverted!
806 XtSetArg(args[j], XtNborderWidth, 1); j++;
807 XtSetArg(args[j], XtNfromVert, engDrawMoves); j++;
808 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
809 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
810 XtSetArg(args[j], XtNstring, def); j++;
811 XtSetArg(args[j], XtNdisplayCaret, False); j++;
812 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
813 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
814 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
815 XtSetArg(args[j], XtNright, XtChainLeft); j++;
816 XtSetArg(args[j], XtNresizable, True); j++;
817 XtSetArg(args[j], XtNwidth, 60); j++;
818 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
819 engThreshold = XtCreateManagedWidget("Threshold", asciiTextWidgetClass, form, args, j);
820 XtAddEventHandler(engThreshold, ButtonPressMask, False, SetFocus, (XtPointer) popup);
823 XtSetArg(args[j], XtNlabel, _("-centiPawn lead is win")); j++;
824 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
825 XtSetArg(args[j], XtNborderWidth, 0); j++;
826 XtSetArg(args[j], XtNfromVert, engDrawMoves); j++;
827 XtSetArg(args[j], XtNfromHoriz, engThreshold); j++;
828 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
829 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
830 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
831 XtSetArg(args[j], XtNright, XtChainLeft); j++;
832 // XtSetArg(args[j], XtNwidth, 150); j++;
833 // XtSetArg(args[j], XtNheight, 20); j++;
834 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j);
836 sprintf(def, "%d", appData.ruleMoves);
838 XtSetArg(args[j], XtNborderWidth, 1); j++;
839 XtSetArg(args[j], XtNfromVert, engThreshold); j++;
840 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
841 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
842 XtSetArg(args[j], XtNstring, def); j++;
843 XtSetArg(args[j], XtNdisplayCaret, False); j++;
844 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
845 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
846 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
847 XtSetArg(args[j], XtNright, XtChainLeft); j++;
848 XtSetArg(args[j], XtNresizable, True); j++;
849 XtSetArg(args[j], XtNwidth, 30); j++;
850 // XtSetArg(args[j], XtNheight, 20); j++;
851 engRule = XtCreateManagedWidget("Rule", asciiTextWidgetClass, form, args, j);
852 XtAddEventHandler(engRule, ButtonPressMask, False, SetFocus, (XtPointer) popup);
855 XtSetArg(args[j], XtNlabel, _("-move rule applied")); j++;
856 XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
857 XtSetArg(args[j], XtNborderWidth, 0); j++;
858 XtSetArg(args[j], XtNfromVert, engThreshold); j++;
859 XtSetArg(args[j], XtNfromHoriz, engRule); j++;
860 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
861 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
862 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
863 XtSetArg(args[j], XtNright, XtChainLeft); j++;
864 // XtSetArg(args[j], XtNwidth, 130); j++;
865 // XtSetArg(args[j], XtNheight, 20); j++;
866 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
868 sprintf(def, "%d", appData.drawRepeats);
870 XtSetArg(args[j], XtNborderWidth, 1); j++;
871 XtSetArg(args[j], XtNfromVert, engRule); j++;
872 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
873 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
874 XtSetArg(args[j], XtNstring, def); j++;
875 XtSetArg(args[j], XtNdisplayCaret, False); j++;
876 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
877 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
878 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
879 XtSetArg(args[j], XtNright, XtChainLeft); j++;
880 XtSetArg(args[j], XtNresizable, True); j++;
881 XtSetArg(args[j], XtNwidth, 30); j++;
882 // XtSetArg(args[j], XtNheight, 20); j++;
883 engRepeat = XtCreateManagedWidget("Repeats", asciiTextWidgetClass, form, args, j);
884 XtAddEventHandler(engRepeat, ButtonPressMask, False, SetFocus, (XtPointer) popup);
887 XtSetArg(args[j], XtNlabel, _("-fold repeat is draw")); j++;
888 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
889 XtSetArg(args[j], XtNborderWidth, 0); j++;
890 XtSetArg(args[j], XtNfromVert, engRule); j++;
891 XtSetArg(args[j], XtNfromHoriz, engRepeat); j++;
892 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
893 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
894 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
895 XtSetArg(args[j], XtNright, XtChainLeft); j++;
896 // XtSetArg(args[j], XtNwidth, 130); j++;
897 // XtSetArg(args[j], XtNheight, 20); j++;
898 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j);
901 XtSetArg(args[j], XtNfromVert, engRepeat); j++;
902 XtSetArg(args[j], XtNfromHoriz, tcMess2); j++;
903 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
904 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
905 XtSetArg(args[j], XtNleft, XtChainRight); j++;
906 XtSetArg(args[j], XtNright, XtChainRight); j++;
907 b_ok= XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
908 XtAddCallback(b_ok, XtNcallback, EngineCallback, (XtPointer) 0);
911 XtSetArg(args[j], XtNfromVert, engRepeat); j++;
912 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
913 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
914 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
915 XtSetArg(args[j], XtNleft, XtChainRight); j++;
916 XtSetArg(args[j], XtNright, XtChainRight); j++;
917 b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
919 XtAddCallback(b_cancel, XtNcallback, EnginePopDown, (XtPointer) 0);
921 XtRealizeWidget(popup);
922 CatchDeleteWindow(popup, "EnginePopDown");
924 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
925 &x, &y, &win_x, &win_y, &mask);
927 XtSetArg(args[0], XtNx, x - 10);
928 XtSetArg(args[1], XtNy, y - 30);
929 XtSetValues(popup, args, 2);
931 XtPopup(popup, XtGrabExclusive);
935 SetFocus(engThreshold, popup, (XEvent*) NULL, False);
938 void EngineMenuProc(w, event, prms, nprms)
947 //--------------------------- New-Variant Menu PopUp -----------------------------------
948 struct NewVarButton {
952 VariantClass variant;
955 struct NewVarButton buttonDesc[] = {
956 {N_("normal"), "#FFFFFF", 0, VariantNormal},
957 {N_("FRC"), "#FFFFFF", 0, VariantFischeRandom},
958 {N_("wild castle"), "#FFFFFF", 0, VariantWildCastle},
959 {N_("no castle"), "#FFFFFF", 0, VariantNoCastle},
960 {N_("knightmate"), "#FFFFFF", 0, VariantKnightmate},
961 {N_("berolina"), "#FFFFFF", 0, VariantBerolina},
962 {N_("cylinder"), "#FFFFFF", 0, VariantCylinder},
963 {N_("shatranj"), "#FFFFFF", 0, VariantShatranj},
964 {N_("makruk"), "#FFFFFF", 0, VariantMakruk},
965 {N_("atomic"), "#FFFFFF", 0, VariantAtomic},
966 {N_("two kings"), "#FFFFFF", 0, VariantTwoKings},
967 {N_("3-checks"), "#FFFFFF", 0, Variant3Check},
968 {N_("suicide"), "#FFFFBF", 0, VariantSuicide},
969 {N_("give-away"), "#FFFFBF", 0, VariantGiveaway},
970 {N_("losers"), "#FFFFBF", 0, VariantLosers},
971 {N_("fairy"), "#BFBFBF", 0, VariantFairy},
972 {N_("Superchess"), "#FFBFBF", 0, VariantSuper},
973 {N_("crazyhouse"), "#FFBFBF", 0, VariantCrazyhouse},
974 {N_("bughouse"), "#FFBFBF", 0, VariantBughouse},
975 {N_("shogi (9x9)"), "#BFFFFF", 0, VariantShogi},
976 {N_("xiangqi (9x10)"), "#BFFFFF", 0, VariantXiangqi},
977 {N_("courier (12x8)"), "#BFFFBF", 0, VariantCourier},
978 {N_("janus (10x8)"), "#BFBFFF", 0, VariantJanus},
979 {N_("Capablanca (10x8)"), "#BFBFFF", 0, VariantCapablanca},
980 {N_("CRC (10x8)"), "#BFBFFF", 0, VariantCapaRandom},
982 {N_("Gothic (10x8)"), "#BFBFFF", 0, VariantGothic},
985 {N_("Falcon (10x8)"), "#BFBFFF", 0, VariantFalcon},
987 {NULL, 0, 0, (VariantClass) 0}
991 Widget NewVariantShell;
993 void NewVariantPopDown()
995 if (!NewVariantUp) return;
996 XtPopdown(NewVariantShell);
997 XtDestroyWidget(NewVariantShell);
998 NewVariantUp = False;
1002 void NewVariantCallback(w, client_data, call_data)
1004 XtPointer client_data, call_data;
1012 XtSetArg(args[0], XtNlabel, &name);
1013 XtGetValues(w, args, 1);
1015 if (strcmp(name, _(" OK ")) == 0) {
1016 int nr = (intptr_t) XawToggleGetCurrent(buttonDesc[0].handle) - 1;
1018 v = buttonDesc[nr].variant;
1019 if(!appData.noChessProgram) {
1020 char *name = VariantName(v), buf[MSG_SIZ];
1021 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
1022 /* [HGM] in protocol 2 we check if variant is suported by engine */
1023 sprintf(buf, _("Variant %s not supported by %s"), name, first.tidy);
1024 DisplayError(buf, 0);
1025 // NewVariantPopDown();
1026 return; /* ignore OK if first engine does not support it */
1028 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
1029 sprintf(buf, _("Warning: second engine (%s) does not support this!"), second.tidy);
1030 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
1034 gameInfo.variant = v;
1035 appData.variant = VariantName(v);
1037 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
1038 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
1039 appData.pieceToCharTable = NULL;
1041 NewVariantPopDown();
1046 void NewVariantPopUp()
1049 Widget popup, layout, dialog, edit, form, last = NULL, b_ok, b_cancel;
1055 XrmValue vFrom, vTo;
1058 XtSetArg(args[i], XtNresizable, True); i++;
1059 // XtSetArg(args[i], XtNwidth, 250); i++;
1060 // XtSetArg(args[i], XtNheight, 300); i++;
1061 NewVariantShell = popup =
1062 XtCreatePopupShell(_("NewVariant Menu"), transientShellWidgetClass,
1063 shellWidget, args, i);
1066 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1067 layoutArgs, XtNumber(layoutArgs));
1070 XtCreateManagedWidget("form", formWidgetClass, layout,
1071 formArgs, XtNumber(formArgs));
1073 for(i = 0; buttonDesc[i].name != NULL; i++) {
1075 if (!appData.monoMode) {
1076 vFrom.addr = (caddr_t) buttonDesc[i].color;
1077 vFrom.size = strlen(buttonDesc[i].color);
1078 XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1079 if (vTo.addr == NULL) {
1080 buttonColor = (Pixel) -1;
1082 buttonColor = *(Pixel *) vTo.addr;
1087 XtSetArg(args[j], XtNradioGroup, last); j++;
1088 XtSetArg(args[j], XtNwidth, 125); j++;
1089 // XtSetArg(args[j], XtNheight, 16); j++;
1090 XtSetArg(args[j], XtNfromVert, i == 15 ? NULL : last); j++;
1091 XtSetArg(args[j], XtNfromHoriz, i < 15 ? NULL : buttonDesc[i-15].handle); j++;
1092 XtSetArg(args[j], XtNradioData, i+1); j++;
1093 XtSetArg(args[j], XtNbackground, buttonColor); j++;
1094 XtSetArg(args[j], XtNstate, gameInfo.variant == buttonDesc[i].variant); j++;
1095 buttonDesc[i].handle = last =
1096 XtCreateManagedWidget(buttonDesc[i].name, toggleWidgetClass, form, args, j);
1100 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1101 XtSetArg(args[j], XtNfromHoriz, buttonDesc[12].handle); j++;
1102 XtSetArg(args[j], XtNheight, 35); j++;
1103 // XtSetArg(args[j], XtNwidth, 60); j++;
1104 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1105 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1106 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1107 XtSetArg(args[j], XtNright, XtChainRight); j++;
1108 b_cancel= XtCreateManagedWidget(_("CANCEL"), commandWidgetClass, form, args, j);
1109 XtAddCallback(b_cancel, XtNcallback, NewVariantPopDown, (XtPointer) 0);
1112 XtSetArg(args[j], XtNfromHoriz, b_cancel); j++;
1113 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1114 XtSetArg(args[j], XtNheight, 35); j++;
1115 // XtSetArg(args[j], XtNwidth, 60); j++;
1116 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1117 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1118 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1119 XtSetArg(args[j], XtNright, XtChainRight); j++;
1120 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass, form, args, j);
1121 XtAddCallback(b_ok, XtNcallback, NewVariantCallback, (XtPointer) 0);
1124 XtSetArg(args[j], XtNfromVert, buttonDesc[14].handle); j++;
1125 // XtSetArg(args[j], XtNheight, 70); j++;
1126 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1127 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1128 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1129 XtSetArg(args[j], XtNright, XtChainRight); j++;
1130 XtSetArg(args[j], XtNlabel, _("WARNING: variants with un-orthodox\n"
1131 "pieces only have built-in bitmaps\n"
1132 "for -boardSize middling, bulky and\n"
1133 "petite, and substitute king or amazon\n"
1134 "for missing bitmaps. (See manual.)")); j++;
1135 XtCreateManagedWidget("warning", labelWidgetClass, form, args, j);
1137 XtRealizeWidget(popup);
1138 CatchDeleteWindow(popup, "NewVariantPopDown");
1140 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1141 &x, &y, &win_x, &win_y, &mask);
1143 XtSetArg(args[0], XtNx, x - 10);
1144 XtSetArg(args[1], XtNy, y - 30);
1145 XtSetValues(popup, args, 2);
1147 XtPopup(popup, XtGrabExclusive);
1148 NewVariantUp = True;
1151 void NewVariantProc(w, event, prms, nprms)
1160 //--------------------------- UCI Menu Popup ------------------------------------------
1170 struct UciControl controlDesc[] = {
1171 {N_("maximum nr of CPUs:"), 0, &appData.smpCores},
1172 {N_("Polyglot Directory:"), 0, &appData.polyglotDir},
1173 {N_("Hash Size (MB):"), 0, &appData.defaultHashSize},
1174 {N_("EGTB Path:"), 0, &appData.defaultPathEGTB},
1175 {N_("EGTB Cache (MB):"), 0, &appData.defaultCacheSizeEGTB},
1176 {N_("Polyglot Book:"), 0, &appData.polyglotBook},
1184 XtPopdown(UciShell);
1185 XtDestroyWidget(UciShell);
1190 void UciCallback(w, client_data, call_data)
1192 XtPointer client_data, call_data;
1197 int oldCores = appData.smpCores, ponder = 0;
1199 XtSetArg(args[0], XtNlabel, &name);
1200 XtGetValues(w, args, 1);
1202 if (strcmp(name, _("OK")) == 0) {
1203 int nr, i, j; String name;
1204 for(i=0; i<6; i++) {
1205 XtSetArg(args[0], XtNstring, &name);
1206 XtGetValues(controlDesc[i].handle, args, 1);
1209 *(char**) controlDesc[i].ptr = strdup(name);
1211 if(sscanf(name, "%d", &j) == 1)
1212 *(int*) controlDesc[i].ptr = j;
1215 XtSetArg(args[0], XtNstate, &appData.usePolyglotBook);
1216 XtGetValues(w1, args, 1);
1217 XtSetArg(args[0], XtNstate, &appData.firstHasOwnBookUCI);
1218 XtGetValues(w2, args, 1);
1219 XtSetArg(args[0], XtNstate, &appData.secondHasOwnBookUCI);
1220 XtGetValues(w3, args, 1);
1221 XtSetArg(args[0], XtNstate, &ponder);
1222 XtGetValues(w4, args, 1);
1224 // adjust setting in other menu for duplicates
1225 // (perhaps duplicates should be removed from general Option Menu?)
1226 XtSetArg(args[0], XtNleftBitmap, ponder ? xMarkPixmap : None);
1227 XtSetValues(XtNameToWidget(menuBarWidget,
1228 "menuOptions.Ponder Next Move"), args, 1);
1230 // make sure changes are sent to first engine by re-initializing it
1231 // if it was already started pre-emptively at end of previous game
1232 if(gameMode == BeginningOfGame) Reset(True, True); else {
1233 // Some changed setting need immediate sending always.
1234 PonderNextMoveEvent(ponder);
1235 if(oldCores != appData.smpCores)
1236 NewSettingEvent(False, &(first.maxCores), "cores", appData.smpCores);
1246 Widget popup, layout, dialog, edit, form, b_ok, b_cancel, last = NULL, new, upperLeft;
1254 XtSetArg(args[i], XtNresizable, True); i++;
1255 // XtSetArg(args[i], XtNwidth, 300); i++;
1257 XtCreatePopupShell(_("Engine Settings"), transientShellWidgetClass,
1258 shellWidget, args, i);
1261 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1262 layoutArgs, XtNumber(layoutArgs));
1266 XtCreateManagedWidget("form", formWidgetClass, layout,
1267 formArgs, XtNumber(formArgs));
1270 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1271 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1272 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1273 // XtSetArg(args[j], XtNheight, 20); j++;
1274 for(i = 0; controlDesc[i].name != NULL; i++) {
1276 XtSetArg(args[j], XtNfromVert, last); j++;
1277 // XtSetArg(args[j], XtNwidth, 130); j++;
1278 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1279 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1280 XtSetArg(args[j], XtNborderWidth, 0); j++;
1281 new = XtCreateManagedWidget(controlDesc[i].name, labelWidgetClass, form, args, j);
1282 if(i==0) upperLeft = new;
1285 XtSetArg(args[j], XtNborderWidth, 1); j++;
1286 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1287 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1288 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1289 XtSetArg(args[j], XtNright, XtChainRight); j++;
1290 XtSetArg(args[j], XtNresizable, True); j++;
1291 XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++;
1292 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
1294 XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ?
1295 * (char**) controlDesc[i].ptr : ""); j++;
1297 sprintf(def, "%d", * (int*) controlDesc[i].ptr);
1298 XtSetArg(args[j], XtNstring, def); j++;
1300 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1301 controlDesc[i].handle = last =
1302 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
1303 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1307 XtSetArg(args[j], XtNfromHoriz, controlDesc[0].handle); j++;
1308 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1309 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1310 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1311 XtSetArg(args[j], XtNright, XtChainRight); j++;
1312 XtSetArg(args[j], XtNstate, appData.ponderNextMove); j++;
1313 w4 = XtCreateManagedWidget(_("Ponder"), toggleWidgetClass, form, args, j);
1316 XtSetArg(args[j], XtNfromVert, last); j++;
1317 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1318 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1319 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1320 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1321 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1322 XtAddCallback(b_ok, XtNcallback, UciCallback, (XtPointer) 0);
1324 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
1325 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1326 XtAddCallback(b_cancel, XtNcallback, UciPopDown, (XtPointer) 0);
1329 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1330 XtSetArg(args[j], XtNstate, appData.usePolyglotBook); j++;
1331 w1 = XtCreateManagedWidget(_(" use book "), toggleWidgetClass, form, args, j);
1332 // XtAddCallback(w1, XtNcallback, UciCallback, (XtPointer) 0);
1335 XtSetArg(args[j], XtNfromHoriz, w1); j++;
1336 XtSetArg(args[j], XtNstate, appData.firstHasOwnBookUCI); j++;
1337 w2 = XtCreateManagedWidget(_("own book 1"), toggleWidgetClass, form, args, j);
1338 // XtAddCallback(w2, XtNcallback, UciCallback, (XtPointer) 0);
1341 XtSetArg(args[j], XtNfromHoriz, w2); j++;
1342 XtSetArg(args[j], XtNstate, appData.secondHasOwnBookUCI); j++;
1343 w3 = XtCreateManagedWidget(_("own book 2"), toggleWidgetClass, form, args, j);
1344 // XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0);
1346 XtRealizeWidget(popup);
1347 CatchDeleteWindow(popup, "UciPopDown");
1349 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1350 &x, &y, &win_x, &win_y, &mask);
1352 XtSetArg(args[0], XtNx, x - 10);
1353 XtSetArg(args[1], XtNy, y - 30);
1354 XtSetValues(popup, args, 2);
1356 XtPopup(popup, XtGrabExclusive);
1360 SetFocus(controlDesc[2].handle, popup, (XEvent*) NULL, False);
1361 // XtSetKeyboardFocus(popup, controlDesc[1].handle);
1364 void UciMenuProc(w, event, prms, nprms)
1373 //--------------------------- Engine-specific options menu ----------------------------------
1376 Widget SettingsShell;
1377 int values[MAX_OPTIONS];
1378 ChessProgramState *currentCps;
1380 void SettingsPopDown()
1382 if (!SettingsUp) return;
1384 XtPopdown(SettingsShell);
1385 XtDestroyWidget(SettingsShell);
1390 void SpinCallback(w, client_data, call_data)
1392 XtPointer client_data, call_data;
1399 int data = (intptr_t) client_data;
1401 XtSetArg(args[0], XtNlabel, &name);
1402 XtGetValues(w, args, 1);
1405 XtSetArg(args[0], XtNstring, &val);
1406 XtGetValues(currentCps->option[data].handle, args, 1);
1407 sscanf(val, "%d", &j);
1408 if (strcmp(name, "+") == 0) {
1409 if(++j > currentCps->option[data].max) return;
1411 if (strcmp(name, "-") == 0) {
1412 if(--j < currentCps->option[data].min) return;
1414 sprintf(buf, "%d", j);
1415 XtSetArg(args[0], XtNstring, buf);
1416 XtSetValues(currentCps->option[data].handle, args, 1);
1419 void SettingsCallback(w, client_data, call_data)
1421 XtPointer client_data, call_data;
1428 int data = (intptr_t) client_data;
1430 XtSetArg(args[0], XtNlabel, &name);
1431 XtGetValues(w, args, 1);
1433 if (strcmp(name, _("cancel")) == 0) {
1437 if (strcmp(name, _("OK")) == 0 || data) { // save buttons imply OK
1440 for(i=0; i<currentCps->nrOptions; i++) { // send all options that had to be OK-ed to engine
1441 switch(currentCps->option[i].type) {
1443 XtSetArg(args[0], XtNstring, &val);
1444 XtGetValues(currentCps->option[i].handle, args, 1);
1445 if(strcmp(currentCps->option[i].textValue, val)) {
1446 strcpy(currentCps->option[i].textValue, val);
1447 sprintf(buf, "option %s=%s\n", currentCps->option[i].name, val);
1448 SendToProgram(buf, currentCps);
1452 XtSetArg(args[0], XtNstring, &val);
1453 XtGetValues(currentCps->option[i].handle, args, 1);
1454 sscanf(val, "%d", &j);
1455 if(j > currentCps->option[i].max) j = currentCps->option[i].max;
1456 if(j < currentCps->option[i].min) j = currentCps->option[i].min;
1457 if(currentCps->option[i].value != j) {
1458 currentCps->option[i].value = j;
1459 sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1460 SendToProgram(buf, currentCps);
1465 XtSetArg(args[0], XtNstate, &j);
1466 XtGetValues(currentCps->option[i].handle, args, 1);
1467 if(currentCps->option[i].value != j) {
1468 currentCps->option[i].value = j;
1469 sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1470 SendToProgram(buf, currentCps);
1474 if(currentCps->option[i].value != values[i]) {
1475 currentCps->option[i].value = values[i];
1476 sprintf(buf, "option %s=%s\n", currentCps->option[i].name,
1477 ((char**)currentCps->option[i].textValue)[values[i]]);
1478 SendToProgram(buf, currentCps);
1483 if(data) { // send save-button command to engine
1484 sprintf(buf, "option %s\n", name);
1485 SendToProgram(buf, currentCps);
1490 sprintf(buf, "option %s\n", name);
1491 SendToProgram(buf, currentCps);
1494 void ComboSelect(w, addr, index) // callback for all combo items
1500 int i = ((intptr_t)addr)>>8;
1501 int j = 255 & (intptr_t) addr;
1503 values[i] = j; // store in temporary, for transfer at OK
1504 XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]);
1505 XtSetValues(currentCps->option[i].handle, args, 1);
1508 void CreateComboPopup(parent, name, n, mb)
1518 menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
1521 XtSetArg(args[j], XtNwidth, 100); j++;
1522 // XtSetArg(args[j], XtNright, XtChainRight); j++;
1523 while (mb[i] != NULL) {
1524 entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
1526 XtAddCallback(entry, XtNcallback,
1527 (XtCallbackProc) ComboSelect,
1528 (caddr_t)(intptr_t) (256*n+i));
1533 void SettingsPopUp(ChessProgramState *cps)
1536 Widget popup, layout, dialog, edit=NULL, form, oldform, last, b_ok, b_cancel, leftMargin = NULL, textField = NULL;
1538 int x, y, i, j, height, width, h, c;
1539 int win_x, win_y, maxWidth, maxTextWidth;
1541 char def[80], *p, *q;
1542 static char pane[6] = "paneX";
1543 Widget texts[100], forelast = NULL, anchor, widest;
1545 // to do: start up second engine if needed
1546 if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
1549 if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1;
1550 height = cps->nrOptions / width + 1;
1552 XtSetArg(args[i], XtNresizable, True); i++;
1553 SettingsShell = popup =
1554 XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
1555 shellWidget, args, i);
1558 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1559 layoutArgs, XtNumber(layoutArgs));
1560 for(c=0; c<width; c++) {
1563 XtCreateManagedWidget(pane, formWidgetClass, layout,
1564 formArgs, XtNumber(formArgs));
1566 XtSetArg(args[j], XtNfromHoriz, leftMargin); j++;
1567 XtSetValues(form, args, j);
1570 last = widest = NULL; anchor = forelast;
1571 for(h=0; h<height; h++) {
1574 if(i >= cps->nrOptions) break;
1575 switch(cps->option[i].type) {
1577 sprintf(def, "%d", cps->option[i].value);
1580 XtSetArg(args[j], XtNfromVert, last); j++;
1581 XtSetArg(args[j], XtNborderWidth, 0); j++;
1582 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1584 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1586 XtSetArg(args[j], XtNfromVert, last); j++;
1587 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1588 XtSetArg(args[j], XtNborderWidth, 1); j++;
1589 XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 175); j++;
1590 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1591 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1592 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1593 XtSetArg(args[j], XtNright, XtChainRight); j++;
1594 XtSetArg(args[j], XtNresizable, True); j++;
1595 XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue); j++;
1596 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
1598 cps->option[i].handle = (void*)
1599 (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1600 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1601 if(cps->option[i].type == TextBox) break;
1603 // add increment and decrement controls for spin
1605 XtSetArg(args[j], XtNfromVert, edit); j++;
1606 XtSetArg(args[j], XtNfromHoriz, last); j++;
1607 XtSetArg(args[j], XtNheight, 10); j++;
1608 XtSetArg(args[j], XtNwidth, 20); j++;
1609 edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j);
1610 XtAddCallback(edit, XtNcallback, SpinCallback,
1611 (XtPointer)(intptr_t) i);
1614 XtSetArg(args[j], XtNfromVert, edit); j++;
1615 XtSetArg(args[j], XtNfromHoriz, last); j++;
1616 XtSetArg(args[j], XtNheight, 10); j++;
1617 XtSetArg(args[j], XtNwidth, 20); j++;
1618 last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1619 XtAddCallback(last, XtNcallback, SpinCallback,
1620 (XtPointer)(intptr_t) i);
1624 XtSetArg(args[j], XtNfromVert, last); j++;
1625 XtSetArg(args[j], XtNwidth, 10); j++;
1626 XtSetArg(args[j], XtNheight, 10); j++;
1627 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1628 cps->option[i].handle = (void*)
1629 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1631 XtSetArg(args[j], XtNfromVert, last); j++;
1632 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1633 XtSetArg(args[j], XtNborderWidth, 0); j++;
1634 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1635 last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1640 XtSetArg(args[j], XtNfromVert, last); j++;
1641 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1642 cps->option[i].handle = (void*)
1643 (dialog = last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));
1644 XtAddCallback(last, XtNcallback, SettingsCallback,
1645 (XtPointer)(intptr_t) (cps->option[i].type == SaveButton));
1649 XtSetArg(args[j], XtNfromVert, last); j++;
1650 XtSetArg(args[j], XtNborderWidth, 0); j++;
1651 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1652 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1655 XtSetArg(args[j], XtNfromVert, last); j++;
1656 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1657 XtSetArg(args[j], XtNwidth, 100); j++;
1658 XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name)); j++;
1659 XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]); j++;
1660 cps->option[i].handle = (void*)
1661 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1662 CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue);
1663 values[i] = cps->option[i].value;
1668 // make an attempt to align all spins and textbox controls
1669 maxWidth = maxTextWidth = 0;
1670 for(h=0; h<height; h++) {
1672 if(i >= cps->nrOptions) break;
1673 if(cps->option[i].type == Spin || cps->option[i].type == TextBox) {
1676 XtSetArg(args[j], XtNwidth, &w); j++;
1677 XtGetValues(texts[h], args, j);
1678 if(cps->option[i].type == Spin) {
1679 if(w > maxWidth) maxWidth = w;
1682 if(w > maxTextWidth) maxTextWidth = w;
1683 if(!widest) widest = texts[h];
1687 if(maxTextWidth + 110 < maxWidth)
1688 maxTextWidth = maxWidth - 110;
1689 else maxWidth = maxTextWidth + 110;
1690 for(h=0; h<height; h++) {
1692 if(i >= cps->nrOptions) break;
1694 if(cps->option[i].type == Spin) {
1695 XtSetArg(args[j], XtNwidth, maxWidth); j++;
1696 XtSetValues(texts[h], args, j);
1698 if(cps->option[i].type == TextBox) {
1699 XtSetArg(args[j], XtNwidth, maxTextWidth); j++;
1700 XtSetValues(texts[h], args, j);
1705 XtSetArg(args[j], XtNfromVert, anchor ? anchor : last); j++;
1706 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1707 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1708 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1709 XtSetArg(args[j], XtNright, XtChainRight); j++;
1710 XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog); j++;
1711 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1712 XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
1714 XtSetArg(args[j-1], XtNfromHoriz, b_ok);
1715 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1716 XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
1718 XtRealizeWidget(popup);
1719 CatchDeleteWindow(popup, "SettingsPopDown");
1721 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1722 &x, &y, &win_x, &win_y, &mask);
1724 XtSetArg(args[0], XtNx, x - 10);
1725 XtSetArg(args[1], XtNy, y - 30);
1726 XtSetValues(popup, args, 2);
1728 XtPopup(popup, XtGrabExclusive);
1732 if(textField)SetFocus(textField, popup, (XEvent*) NULL, False);
1735 void FirstSettingsProc(w, event, prms, nprms)
1741 SettingsPopUp(&first);
1744 void SecondSettingsProc(w, event, prms, nprms)
1750 SettingsPopUp(&second);
1753 //---------------------------- Chat Windows ----------------------------------------------
1755 void OutputChatMessage(int partner, char *mess)