2 * xoptions.c -- Move list window, part of X front end for XBoard
4 * Copyright 2000,2009 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 */
49 #include <X11/Intrinsic.h>
50 #include <X11/StringDefs.h>
51 #include <X11/Shell.h>
52 #include <X11/Xaw/Dialog.h>
53 #include <X11/Xaw/Form.h>
54 #include <X11/Xaw/List.h>
55 #include <X11/Xaw/Label.h>
56 #include <X11/Xaw/SimpleMenu.h>
57 #include <X11/Xaw/SmeBSB.h>
58 #include <X11/Xaw/SmeLine.h>
59 #include <X11/Xaw/Box.h>
60 #include <X11/Xaw/Paned.h>
61 #include <X11/Xaw/MenuButton.h>
62 #include <X11/cursorfont.h>
63 #include <X11/Xaw/Text.h>
64 #include <X11/Xaw/AsciiText.h>
65 #include <X11/Xaw/Viewport.h>
66 #include <X11/Xaw/Toggle.h>
74 # define _(s) gettext (s)
75 # define N_(s) gettext_noop (s)
81 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
82 extern Display *xDisplay;
83 extern int squareSize;
84 extern Pixmap xMarkPixmap;
85 extern char *layoutName;
86 extern Window xBoardWindow;
87 extern Arg layoutArgs[2], formArgs[2];
88 Pixel timerForegroundPixel, timerBackgroundPixel;
90 // [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines
92 static Widget previous = NULL;
94 void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
99 XtSetArg(args, XtNdisplayCaret, False);
100 XtSetValues(previous, &args, 1);
102 XtSetArg(args, XtNdisplayCaret, True);
103 XtSetValues(w, &args, 1);
104 XtSetKeyboardFocus((Widget) data, w);
108 //--------------------------- New Shuffle Game --------------------------------------------
109 extern int shuffleOpenings;
110 extern int startedFromPositionFile;
114 void ShufflePopDown()
116 if (!shuffleUp) return;
117 XtPopdown(shuffleShell);
118 XtDestroyWidget(shuffleShell);
123 void ShuffleCallback(w, client_data, call_data)
125 XtPointer client_data, call_data;
132 XtSetArg(args[0], XtNlabel, &name);
133 XtGetValues(w, args, 1);
135 if (strcmp(name, _("cancel")) == 0) {
139 if (strcmp(name, _("off")) == 0) {
141 shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it!
146 if (strcmp(name, _("random")) == 0) {
147 sprintf(buf, "%d", rand());
148 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
149 XtSetValues(XtParent(w), args, 1);
152 if (strcmp(name, _("ok")) == 0) {
154 name = XawDialogGetValueString(w2 = XtParent(w));
155 if(sscanf(name ,"%d",&nr) != 1) {
156 sprintf(buf, "%d", appData.defaultFrcPosition);
157 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
158 XtSetValues(w2, args, 1);
161 appData.defaultFrcPosition = nr;
162 shuffleOpenings = True;
173 Widget popup, layout, dialog, edit;
181 XtSetArg(args[i], XtNresizable, True); i++;
182 XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
183 shuffleShell = popup =
184 XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass,
185 shellWidget, args, i);
188 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
189 layoutArgs, XtNumber(layoutArgs));
191 sprintf(def, "%d\n", appData.defaultFrcPosition);
193 XtSetArg(args[i], XtNlabel, _("Start-position number:")); i++;
194 XtSetArg(args[i], XtNvalue, def); i++;
195 XtSetArg(args[i], XtNborderWidth, 0); i++;
196 dialog = XtCreateManagedWidget(_("Shuffle"), dialogWidgetClass,
199 // XtSetArg(args[0], XtNeditType, XawtextEdit); // [HGM] can't get edit to work decently
200 // XtSetArg(args[1], XtNuseStringInPlace, False);
201 // XtSetValues(dialog, args, 2);
203 XawDialogAddButton(dialog, _("ok"), ShuffleCallback, (XtPointer) dialog);
204 XawDialogAddButton(dialog, _("cancel"), ShuffleCallback, (XtPointer) dialog);
205 XawDialogAddButton(dialog, _("random"), ShuffleCallback, (XtPointer) dialog);
206 XawDialogAddButton(dialog, _("off"), ShuffleCallback, (XtPointer) dialog);
208 XtRealizeWidget(popup);
209 CatchDeleteWindow(popup, "ShufflePopDown");
211 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
212 &x, &y, &win_x, &win_y, &mask);
214 XtSetArg(args[0], XtNx, x - 10);
215 XtSetArg(args[1], XtNy, y - 30);
216 XtSetValues(popup, args, 2);
218 XtPopup(popup, XtGrabExclusive);
221 edit = XtNameToWidget(dialog, "*value");
223 XtSetKeyboardFocus(popup, edit);
226 void ShuffleMenuProc(w, event, prms, nprms)
232 // if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
233 // Reset(FALSE, TRUE);
238 //--------------------------- Time-Control Menu Popup ----------------------------------
240 Widget TimeControlShell;
242 Widget tcMess1, tcMess2, tcData, tcTime, tcOdds1, tcOdds2;
243 int tcIncrement, tcMoves;
245 void TimeControlPopDown()
247 if (!TimeControlUp) return;
248 XtPopdown(TimeControlShell);
249 XtDestroyWidget(TimeControlShell);
250 TimeControlUp = False;
254 void TimeControlCallback(w, client_data, call_data)
256 XtPointer client_data, call_data;
264 XtSetArg(args[0], XtNlabel, &name);
265 XtGetValues(w, args, 1);
267 if (strcmp(name, _("classical")) == 0) {
270 XtSetArg(args[j], XtNlabel, _("minutes for each")); j++;
271 XtSetValues(tcMess1, args, j);
273 XtSetArg(args[j], XtNlabel, _("moves")); j++;
274 XtSetValues(tcMess2, args, j);
276 XtSetArg(args[j], XtNstring, &name); j++;
277 XtGetValues(tcData, args, j);
278 tcIncrement = 0; sscanf(name, "%d", &tcIncrement);
279 sprintf(buf, "%d", tcMoves);
281 XtSetArg(args[j], XtNstring, buf); j++;
282 XtSetValues(tcData, args, j);
286 if (strcmp(name, _("incremental")) == 0) {
289 XtSetArg(args[j], XtNlabel, _("minutes, plus")); j++;
290 XtSetValues(tcMess1, args, j);
292 XtSetArg(args[j], XtNlabel, _("sec/move")); j++;
293 XtSetValues(tcMess2, args, j);
295 XtSetArg(args[j], XtNstring, &name); j++;
296 XtGetValues(tcData, args, j);
297 tcMoves = appData.movesPerSession; sscanf(name, "%d", &tcMoves);
298 sprintf(buf, "%d", tcIncrement);
300 XtSetArg(args[j], XtNstring, buf); j++;
301 XtSetValues(tcData, args, j);
305 if (strcmp(name, _(" OK ")) == 0) {
306 int inc, mps, tc, ok;
307 XtSetArg(args[0], XtNstring, &txt);
308 XtGetValues(tcData, args, 1);
310 ok = sscanf(txt, "%d", &inc); mps = 0;
311 if(!ok && txt[0] == 0) { inc = 0; ok = 1; } // accept empty string as zero
314 ok = sscanf(txt, "%d", &mps); inc = -1;
318 XtSetArg(args[0], XtNstring, ""); // erase any offending input
319 XtSetValues(tcData, args, 1);
322 XtSetArg(args[0], XtNstring, &txt);
323 XtGetValues(tcTime, args, 1);
324 if(!ParseTimeControl(txt, inc, mps)) {
325 XtSetArg(args[0], XtNstring, ""); // erase any offending input
326 XtSetValues(tcTime, args, 1);
327 DisplayError(_("Bad Time-Control String"), 0);
330 appData.movesPerSession = mps;
331 appData.timeIncrement = inc;
332 appData.timeControl = strdup(txt);
333 XtSetArg(args[0], XtNstring, &txt);
334 XtGetValues(tcOdds1, args, 1);
335 appData.firstTimeOdds = first.timeOdds
336 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
337 XtGetValues(tcOdds2, args, 1);
338 appData.secondTimeOdds = second.timeOdds
339 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
342 TimeControlPopDown();
347 void TimeControlPopUp()
350 Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, mess;
357 tcInc = (appData.timeIncrement >= 0);
358 tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
359 if(!tcInc) tcIncrement = 0;
360 sprintf(def, "%d", tcInc ? tcIncrement : tcMoves);
363 XtSetArg(args[i], XtNresizable, True); i++;
364 // XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
365 TimeControlShell = popup =
366 XtCreatePopupShell(_("TimeControl Menu"), transientShellWidgetClass,
367 shellWidget, args, i);
370 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
371 layoutArgs, XtNumber(layoutArgs));
374 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
375 formArgs, XtNumber(formArgs));
378 // XtSetArg(args[j], XtNwidth, (XtArgVal) 300); j++;
379 // XtSetArg(args[j], XtNheight, (XtArgVal) 85); j++;
380 XtSetValues(popup, args, j);
383 XtSetArg(args[j], XtNborderWidth, 1); j++;
384 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
385 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
386 XtSetArg(args[j], XtNstring, appData.timeControl); j++;
387 XtSetArg(args[j], XtNdisplayCaret, False); j++;
388 XtSetArg(args[j], XtNtop, XtChainTop); j++;
389 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
390 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
391 XtSetArg(args[j], XtNright, XtChainRight); j++;
392 XtSetArg(args[j], XtNresizable, True); j++;
393 XtSetArg(args[j], XtNwidth, 85); j++;
394 // XtSetArg(args[j], XtNheight, 20); j++;
395 tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j);
396 XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup);
399 XtSetArg(args[j], XtNlabel, tcInc ? _(" minutes, plus ") : _("minutes for each")); j++;
400 XtSetArg(args[j], XtNborderWidth, 0); j++;
401 XtSetArg(args[j], XtNfromHoriz, tcTime); j++;
402 XtSetArg(args[j], XtNtop, XtChainTop); j++;
403 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
404 XtSetArg(args[j], XtNleft, XtChainRight); j++;
405 XtSetArg(args[j], XtNright, XtChainRight); j++;
406 // XtSetArg(args[j], XtNwidth, 100); j++;
407 // XtSetArg(args[j], XtNheight, 20); j++;
408 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
411 XtSetArg(args[j], XtNborderWidth, 1); j++;
412 XtSetArg(args[j], XtNfromHoriz, tcMess1); j++;
413 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
414 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
415 XtSetArg(args[j], XtNstring, def); j++;
416 XtSetArg(args[j], XtNdisplayCaret, False); j++;
417 XtSetArg(args[j], XtNtop, XtChainTop); j++;
418 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
419 XtSetArg(args[j], XtNleft, XtChainRight); j++;
420 XtSetArg(args[j], XtNright, XtChainRight); j++;
421 XtSetArg(args[j], XtNresizable, True); j++;
422 XtSetArg(args[j], XtNwidth, 40); j++;
423 // XtSetArg(args[j], XtNheight, 20); j++;
424 tcData = XtCreateManagedWidget("MPS", asciiTextWidgetClass, form, args, j);
425 XtAddEventHandler(tcData, ButtonPressMask, False, SetFocus, (XtPointer) popup);
428 XtSetArg(args[j], XtNlabel, tcInc ? _("sec/move") : _("moves ")); j++;
429 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
430 XtSetArg(args[j], XtNborderWidth, 0); j++;
431 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
432 XtSetArg(args[j], XtNtop, XtChainTop); j++;
433 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
434 XtSetArg(args[j], XtNleft, XtChainRight); j++;
435 XtSetArg(args[j], XtNright, XtChainRight); j++;
436 // XtSetArg(args[j], XtNwidth, 80); j++;
437 // XtSetArg(args[j], XtNheight, 20); j++;
438 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass,
442 XtSetArg(args[j], XtNborderWidth, 1); j++;
443 XtSetArg(args[j], XtNfromVert, tcTime); j++;
444 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
445 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
446 XtSetArg(args[j], XtNstring, "1"); j++;
447 XtSetArg(args[j], XtNdisplayCaret, False); j++;
448 XtSetArg(args[j], XtNtop, XtChainTop); j++;
449 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
450 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
451 XtSetArg(args[j], XtNright, XtChainLeft); j++;
452 XtSetArg(args[j], XtNresizable, True); j++;
453 XtSetArg(args[j], XtNwidth, 40); j++;
454 // XtSetArg(args[j], XtNheight, 20); j++;
455 tcOdds1 = XtCreateManagedWidget("Odds1", asciiTextWidgetClass, form, args, j);
456 XtAddEventHandler(tcOdds1, ButtonPressMask, False, SetFocus, (XtPointer) popup);
459 XtSetArg(args[j], XtNborderWidth, 1); j++;
460 XtSetArg(args[j], XtNfromVert, tcTime); j++;
461 XtSetArg(args[j], XtNfromHoriz, tcOdds1); j++;
462 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
463 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
464 XtSetArg(args[j], XtNstring, "1"); j++;
465 XtSetArg(args[j], XtNdisplayCaret, False); j++;
466 XtSetArg(args[j], XtNtop, XtChainTop); j++;
467 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
468 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
469 XtSetArg(args[j], XtNright, XtChainLeft); j++;
470 XtSetArg(args[j], XtNresizable, True); j++;
471 XtSetArg(args[j], XtNwidth, 40); j++;
472 // XtSetArg(args[j], XtNheight, 20); j++;
473 tcOdds2 = XtCreateManagedWidget("Odds2", asciiTextWidgetClass, form, args, j);
474 XtAddEventHandler(tcOdds2, ButtonPressMask, False, SetFocus, (XtPointer) popup);
477 XtSetArg(args[j], XtNlabel, _("Engine #1 and #2 Time-Odds Factors")); j++;
478 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
479 XtSetArg(args[j], XtNborderWidth, 0); j++;
480 XtSetArg(args[j], XtNfromVert, tcTime); j++;
481 XtSetArg(args[j], XtNfromHoriz, tcOdds2); j++;
482 XtSetArg(args[j], XtNtop, XtChainTop); j++;
483 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
484 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
485 XtSetArg(args[j], XtNright, XtChainRight); j++;
486 // XtSetArg(args[j], XtNwidth, 200); j++;
487 // XtSetArg(args[j], XtNheight, 20); j++;
488 mess = XtCreateManagedWidget("Oddstext", labelWidgetClass,
491 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
492 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
493 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
494 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
495 XtSetArg(args[j], XtNright, XtChainLeft); j++;
496 b_clas= XtCreateManagedWidget(_("classical"), commandWidgetClass,
498 XtAddCallback(b_clas, XtNcallback, TimeControlCallback, (XtPointer) 0);
501 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
502 XtSetArg(args[j], XtNfromHoriz, b_clas); j++;
503 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
504 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
505 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
506 XtSetArg(args[j], XtNright, XtChainLeft); j++;
507 b_inc = XtCreateManagedWidget(_("incremental"), commandWidgetClass,
509 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
512 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
513 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
514 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
515 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
516 XtSetArg(args[j], XtNleft, XtChainRight); j++;
517 XtSetArg(args[j], XtNright, XtChainRight); j++;
518 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass,
520 XtAddCallback(b_ok, XtNcallback, TimeControlCallback, (XtPointer) 0);
523 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
524 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
525 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
526 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
527 XtSetArg(args[j], XtNleft, XtChainRight); j++;
528 XtSetArg(args[j], XtNright, XtChainRight); j++;
529 b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
531 XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0);
533 XtRealizeWidget(popup);
534 CatchDeleteWindow(popup, "TimeControlPopDown");
536 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
537 &x, &y, &win_x, &win_y, &mask);
539 XtSetArg(args[0], XtNx, x - 10);
540 XtSetArg(args[1], XtNy, y - 30);
541 XtSetValues(popup, args, 2);
543 XtPopup(popup, XtGrabExclusive);
544 TimeControlUp = True;
547 SetFocus(tcTime, popup, (XEvent*) NULL, False);
548 // XtSetKeyboardFocus(popup, tcTime);
551 void TimeControlProc(w, event, prms, nprms)
560 //--------------------------- Engine-Options Menu Popup ----------------------------------
563 extern int adjudicateLossThreshold;
565 Widget engDrawMoves, engThreshold, engRule, engRepeat;
569 if (!EngineUp) return;
570 XtPopdown(EngineShell);
571 XtDestroyWidget(EngineShell);
576 int ReadToggle(Widget w)
578 Arg args; Boolean res;
580 XtSetArg(args, XtNstate, &res);
581 XtGetValues(w, &args, 1);
586 Widget w1, w2, w3, w4, w5, w6, w7, w8;
588 void EngineCallback(w, client_data, call_data)
590 XtPointer client_data, call_data;
598 XtSetArg(args[0], XtNlabel, &name);
599 XtGetValues(w, args, 1);
601 if (strcmp(name, _("OK")) == 0) {
603 appData.periodicUpdates = ReadToggle(w1);
604 // appData.hideThinkingFromHuman = ReadToggle(w2);
605 appData.firstScoreIsAbsolute = ReadToggle(w3);
606 appData.secondScoreIsAbsolute = ReadToggle(w4);
607 appData.testClaims = ReadToggle(w5);
608 appData.checkMates = ReadToggle(w6);
609 appData.materialDraws = ReadToggle(w7);
610 appData.trivialDraws = ReadToggle(w8);
612 // adjust setting in other menu for duplicates
613 // (perhaps duplicates should be removed from general Option Menu?)
614 // XtSetArg(args[0], XtNleftBitmap, appData.showThinking ? xMarkPixmap : None);
615 // XtSetValues(XtNameToWidget(menuBarWidget,
616 // "menuOptions.Show Thinking"), args, 1);
618 // read out numeric controls, simply ignore bad formats for now
619 XtSetArg(args[0], XtNstring, &name);
620 XtGetValues(engDrawMoves, args, 1);
621 if(sscanf(name, "%d", &j) == 1) appData.adjudicateDrawMoves = j;
622 XtGetValues(engThreshold, args, 1);
623 if(sscanf(name, "%d", &j) == 1)
624 adjudicateLossThreshold = appData.adjudicateLossThreshold = -j; // inverted!
625 XtGetValues(engRule, args, 1);
626 if(sscanf(name, "%d", &j) == 1) appData.ruleMoves = j;
627 XtGetValues(engRepeat, args, 1);
628 if(sscanf(name, "%d", &j) == 1) appData.drawRepeats = j;
631 ShowThinkingEvent(); // [HGM] thinking: score adjudication might need thinking output
639 Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, s1;
641 int x, y, i, j, width;
646 tcInc = (appData.timeIncrement >= 0);
647 tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
648 if(!tcInc) tcIncrement = 0;
649 sprintf(def, "%d", tcInc ? tcIncrement : tcMoves);
652 XtSetArg(args[i], XtNresizable, True); i++;
653 // XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
654 EngineShell = popup =
655 XtCreatePopupShell(_("Adjudications"), transientShellWidgetClass,
656 shellWidget, args, i);
659 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
660 layoutArgs, XtNumber(layoutArgs));
663 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
664 formArgs, XtNumber(formArgs));
667 // XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++;
668 // XtSetArg(args[j], XtNheight, (XtArgVal) 400); j++;
669 // XtSetValues(popup, args, j);
672 // XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++;
673 // XtSetArg(args[j], XtNheight, (XtArgVal) 20); j++;
674 XtSetArg(args[j], XtNleft, (XtArgVal) XtChainLeft); j++;
675 XtSetArg(args[j], XtNright, (XtArgVal) XtChainRight); j++;
676 XtSetArg(args[j], XtNstate, appData.periodicUpdates); j++;
677 // XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
678 w1 = XtCreateManagedWidget(_("Periodic Updates (Analysis Mode)"), toggleWidgetClass, form, args, j);
680 XtSetArg(args[j], XtNwidth, (XtArgVal) &width);
681 XtGetValues(w1, &args[j], 1);
683 // XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w1);
684 // XtSetArg(args[j-3], XtNstate, appData.hideThinkingFromHuman);
685 // w2 = XtCreateManagedWidget(_("Hide Thinking from Human"), toggleWidgetClass, form, args, j);
687 XtSetArg(args[j], XtNwidth, (XtArgVal) width); j++;
688 XtSetArg(args[j-2], XtNstate, appData.firstScoreIsAbsolute);
689 XtSetArg(args[j], XtNfromVert, (XtArgVal) w1); j++;
690 w3 = XtCreateManagedWidget(_("Engine #1 Score is Absolute"), toggleWidgetClass, form, args, j);
692 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w3);
693 XtSetArg(args[j-3], XtNstate, appData.secondScoreIsAbsolute);
694 w4 = XtCreateManagedWidget(_("Engine #2 Score is Absolute"), toggleWidgetClass, form, args, j);
696 s1 = XtCreateManagedWidget(_("\nEngine-Engine Adjudications:"), labelWidgetClass, form, args, 3);
698 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) s1);
699 XtSetArg(args[j-3], XtNstate, appData.testClaims);
700 w5 = XtCreateManagedWidget(_("Verify Engine Result Claims"), toggleWidgetClass, form, args, j);
702 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w5);
703 XtSetArg(args[j-3], XtNstate, appData.checkMates);
704 w6 = XtCreateManagedWidget(_("Detect All Mates"), toggleWidgetClass, form, args, j);
706 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w6);
707 XtSetArg(args[j-3], XtNstate, appData.materialDraws);
708 w7 = XtCreateManagedWidget(_("Draw when Insuff. Mating Material"), toggleWidgetClass, form, args, j);
710 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w7);
711 XtSetArg(args[j-3], XtNstate, appData.trivialDraws);
712 w8 = XtCreateManagedWidget(_("Adjudicate Trivial Draws"), toggleWidgetClass, form, args, j);
714 XtSetArg(args[0], XtNfromVert, (XtArgVal) w4);
715 XtSetArg(args[1], XtNborderWidth, (XtArgVal) 0);
716 XtSetValues(s1, args, 2);
718 sprintf(def, "%d", appData.adjudicateDrawMoves);
720 XtSetArg(args[j], XtNborderWidth, 1); j++;
721 XtSetArg(args[j], XtNfromVert, w8); j++;
722 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
723 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
724 XtSetArg(args[j], XtNstring, def); j++;
725 XtSetArg(args[j], XtNdisplayCaret, False); j++;
726 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
727 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
728 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
729 XtSetArg(args[j], XtNright, XtChainLeft); j++;
730 XtSetArg(args[j], XtNresizable, True); j++;
731 XtSetArg(args[j], XtNwidth, 60); j++;
732 // XtSetArg(args[j], XtNheight, 20); j++;
733 engDrawMoves = XtCreateManagedWidget("Length", asciiTextWidgetClass, form, args, j);
734 XtAddEventHandler(engDrawMoves, ButtonPressMask, False, SetFocus, (XtPointer) popup);
737 XtSetArg(args[j], XtNlabel, _(" moves maximum, then draw")); j++;
738 XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
739 XtSetArg(args[j], XtNborderWidth, 0); j++;
740 XtSetArg(args[j], XtNfromVert, w8); j++;
741 XtSetArg(args[j], XtNfromHoriz, engDrawMoves); j++;
742 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
743 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
744 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
745 XtSetArg(args[j], XtNright, XtChainLeft); j++;
746 // XtSetArg(args[j], XtNwidth, 170); j++;
747 // XtSetArg(args[j], XtNheight, 20); j++;
748 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
750 sprintf(def, "%d", -appData.adjudicateLossThreshold); // inverted!
752 XtSetArg(args[j], XtNborderWidth, 1); j++;
753 XtSetArg(args[j], XtNfromVert, engDrawMoves); j++;
754 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
755 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
756 XtSetArg(args[j], XtNstring, def); j++;
757 XtSetArg(args[j], XtNdisplayCaret, False); j++;
758 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
759 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
760 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
761 XtSetArg(args[j], XtNright, XtChainLeft); j++;
762 XtSetArg(args[j], XtNresizable, True); j++;
763 XtSetArg(args[j], XtNwidth, 60); j++;
764 // XtSetArg(args[j], XtNheight, 20); j++;
765 engThreshold = XtCreateManagedWidget("Threshold", asciiTextWidgetClass, form, args, j);
766 XtAddEventHandler(engThreshold, ButtonPressMask, False, SetFocus, (XtPointer) popup);
769 XtSetArg(args[j], XtNlabel, _("-centiPawn lead is win")); j++;
770 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
771 XtSetArg(args[j], XtNborderWidth, 0); j++;
772 XtSetArg(args[j], XtNfromVert, engDrawMoves); j++;
773 XtSetArg(args[j], XtNfromHoriz, engThreshold); j++;
774 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
775 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
776 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
777 XtSetArg(args[j], XtNright, XtChainLeft); j++;
778 // XtSetArg(args[j], XtNwidth, 150); j++;
779 // XtSetArg(args[j], XtNheight, 20); j++;
780 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j);
782 sprintf(def, "%d", appData.ruleMoves);
784 XtSetArg(args[j], XtNborderWidth, 1); j++;
785 XtSetArg(args[j], XtNfromVert, engThreshold); j++;
786 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
787 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
788 XtSetArg(args[j], XtNstring, def); j++;
789 XtSetArg(args[j], XtNdisplayCaret, False); j++;
790 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
791 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
792 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
793 XtSetArg(args[j], XtNright, XtChainLeft); j++;
794 XtSetArg(args[j], XtNresizable, True); j++;
795 XtSetArg(args[j], XtNwidth, 30); j++;
796 // XtSetArg(args[j], XtNheight, 20); j++;
797 engRule = XtCreateManagedWidget("Rule", asciiTextWidgetClass, form, args, j);
798 XtAddEventHandler(engRule, ButtonPressMask, False, SetFocus, (XtPointer) popup);
801 XtSetArg(args[j], XtNlabel, _("-move rule applied")); j++;
802 XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
803 XtSetArg(args[j], XtNborderWidth, 0); j++;
804 XtSetArg(args[j], XtNfromVert, engThreshold); j++;
805 XtSetArg(args[j], XtNfromHoriz, engRule); j++;
806 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
807 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
808 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
809 XtSetArg(args[j], XtNright, XtChainLeft); j++;
810 // XtSetArg(args[j], XtNwidth, 130); j++;
811 // XtSetArg(args[j], XtNheight, 20); j++;
812 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
814 sprintf(def, "%d", appData.drawRepeats);
816 XtSetArg(args[j], XtNborderWidth, 1); j++;
817 XtSetArg(args[j], XtNfromVert, engRule); j++;
818 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
819 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
820 XtSetArg(args[j], XtNstring, def); j++;
821 XtSetArg(args[j], XtNdisplayCaret, False); j++;
822 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
823 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
824 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
825 XtSetArg(args[j], XtNright, XtChainLeft); j++;
826 XtSetArg(args[j], XtNresizable, True); j++;
827 XtSetArg(args[j], XtNwidth, 30); j++;
828 // XtSetArg(args[j], XtNheight, 20); j++;
829 engRepeat = XtCreateManagedWidget("Repeats", asciiTextWidgetClass, form, args, j);
830 XtAddEventHandler(engRepeat, ButtonPressMask, False, SetFocus, (XtPointer) popup);
833 XtSetArg(args[j], XtNlabel, _("-fold repeat is draw")); j++;
834 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
835 XtSetArg(args[j], XtNborderWidth, 0); j++;
836 XtSetArg(args[j], XtNfromVert, engRule); j++;
837 XtSetArg(args[j], XtNfromHoriz, engRepeat); j++;
838 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
839 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
840 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
841 XtSetArg(args[j], XtNright, XtChainLeft); j++;
842 // XtSetArg(args[j], XtNwidth, 130); j++;
843 // XtSetArg(args[j], XtNheight, 20); j++;
844 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j);
847 XtSetArg(args[j], XtNfromVert, engRepeat); j++;
848 XtSetArg(args[j], XtNfromHoriz, tcMess2); j++;
849 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
850 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
851 XtSetArg(args[j], XtNleft, XtChainRight); j++;
852 XtSetArg(args[j], XtNright, XtChainRight); j++;
853 b_ok= XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
854 XtAddCallback(b_ok, XtNcallback, EngineCallback, (XtPointer) 0);
857 XtSetArg(args[j], XtNfromVert, engRepeat); j++;
858 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
859 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
860 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
861 XtSetArg(args[j], XtNleft, XtChainRight); j++;
862 XtSetArg(args[j], XtNright, XtChainRight); j++;
863 b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
865 XtAddCallback(b_cancel, XtNcallback, EnginePopDown, (XtPointer) 0);
867 XtRealizeWidget(popup);
868 CatchDeleteWindow(popup, "EnginePopDown");
870 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
871 &x, &y, &win_x, &win_y, &mask);
873 XtSetArg(args[0], XtNx, x - 10);
874 XtSetArg(args[1], XtNy, y - 30);
875 XtSetValues(popup, args, 2);
877 XtPopup(popup, XtGrabExclusive);
881 SetFocus(engThreshold, popup, (XEvent*) NULL, False);
884 void EngineMenuProc(w, event, prms, nprms)
893 //--------------------------- New-Variant Menu PopUp -----------------------------------
894 struct NewVarButton {
898 VariantClass variant;
901 struct NewVarButton buttonDesc[] = {
902 {N_("normal"), "#FFFFFF", 0, VariantNormal},
903 {N_("FRC"), "#FFFFFF", 0, VariantFischeRandom},
904 {N_("wild castle"), "#FFFFFF", 0, VariantWildCastle},
905 {N_("no castle"), "#FFFFFF", 0, VariantNoCastle},
906 {N_("knightmate"), "#FFFFFF", 0, VariantKnightmate},
907 {N_("berolina"), "#FFFFFF", 0, VariantBerolina},
908 {N_("cylinder"), "#FFFFFF", 0, VariantCylinder},
909 {N_("shatranj"), "#FFFFFF", 0, VariantShatranj},
910 {N_("atomic"), "#FFFFFF", 0, VariantAtomic},
911 {N_("two kings"), "#FFFFFF", 0, VariantTwoKings},
912 {N_("3-checks"), "#FFFFFF", 0, Variant3Check},
913 {N_("suicide"), "#FFFFBF", 0, VariantSuicide},
914 {N_("give-away"), "#FFFFBF", 0, VariantGiveaway},
915 {N_("losers"), "#FFFFBF", 0, VariantLosers},
916 {N_("fairy"), "#BFBFBF", 0, VariantFairy},
917 {N_("Superchess"), "#FFBFBF", 0, VariantSuper},
918 {N_("crazyhouse"), "#FFBFBF", 0, VariantCrazyhouse},
919 {N_("bughouse"), "#FFBFBF", 0, VariantBughouse},
920 {N_("shogi (9x9)"), "#BFFFFF", 0, VariantShogi},
921 {N_("xiangqi (9x10)"), "#BFFFFF", 0, VariantXiangqi},
922 {N_("courier (12x8)"), "#BFFFBF", 0, VariantCourier},
923 {N_("janus (10x8)"), "#BFBFFF", 0, VariantJanus},
924 {N_("Capablanca (10x8)"), "#BFBFFF", 0, VariantCapablanca},
925 {N_("CRC (10x8)"), "#BFBFFF", 0, VariantCapaRandom},
927 {N_("Gothic (10x8)"), "#BFBFFF", 0, VariantGothic},
930 {N_("Falcon (10x8)"), "#BFBFFF", 0, VariantFalcon},
932 {NULL, 0, 0, (VariantClass) 0}
936 Widget NewVariantShell;
938 void NewVariantPopDown()
940 if (!NewVariantUp) return;
941 XtPopdown(NewVariantShell);
942 XtDestroyWidget(NewVariantShell);
943 NewVariantUp = False;
947 void NewVariantCallback(w, client_data, call_data)
949 XtPointer client_data, call_data;
957 XtSetArg(args[0], XtNlabel, &name);
958 XtGetValues(w, args, 1);
960 if (strcmp(name, _(" OK ")) == 0) {
961 int nr = (int) XawToggleGetCurrent(buttonDesc[0].handle) - 1;
963 v = buttonDesc[nr].variant;
964 if(!appData.noChessProgram) {
965 char *name = VariantName(v), buf[MSG_SIZ];
966 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
967 /* [HGM] in protocol 2 we check if variant is suported by engine */
968 sprintf(buf, _("Variant %s not supported by %s"), name, first.tidy);
969 DisplayError(buf, 0);
970 // NewVariantPopDown();
971 return; /* ignore OK if first engine does not support it */
973 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
974 sprintf(buf, _("Warning: second engine (%s) does not support this!"), second.tidy);
975 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
979 gameInfo.variant = v;
980 appData.variant = VariantName(v);
982 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
983 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
984 appData.pieceToCharTable = NULL;
991 void NewVariantPopUp()
994 Widget popup, layout, dialog, edit, form, last = NULL, b_ok, b_cancel;
1000 XrmValue vFrom, vTo;
1003 XtSetArg(args[i], XtNresizable, True); i++;
1004 // XtSetArg(args[i], XtNwidth, 250); i++;
1005 // XtSetArg(args[i], XtNheight, 300); i++;
1006 NewVariantShell = popup =
1007 XtCreatePopupShell(_("NewVariant Menu"), transientShellWidgetClass,
1008 shellWidget, args, i);
1011 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1012 layoutArgs, XtNumber(layoutArgs));
1015 XtCreateManagedWidget("form", formWidgetClass, layout,
1016 formArgs, XtNumber(formArgs));
1018 for(i = 0; buttonDesc[i].name != NULL; i++) {
1020 if (!appData.monoMode) {
1021 vFrom.addr = (caddr_t) buttonDesc[i].color;
1022 vFrom.size = strlen(buttonDesc[i].color);
1023 XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1024 if (vTo.addr == NULL) {
1025 buttonColor = (Pixel) -1;
1027 buttonColor = *(Pixel *) vTo.addr;
1032 XtSetArg(args[j], XtNradioGroup, last); j++;
1033 XtSetArg(args[j], XtNwidth, 125); j++;
1034 // XtSetArg(args[j], XtNheight, 16); j++;
1035 XtSetArg(args[j], XtNfromVert, i == 15 ? NULL : last); j++;
1036 XtSetArg(args[j], XtNfromHoriz, i < 15 ? NULL : buttonDesc[i-15].handle); j++;
1037 XtSetArg(args[j], XtNradioData, i+1); j++;
1038 XtSetArg(args[j], XtNbackground, buttonColor); j++;
1039 XtSetArg(args[j], XtNstate, gameInfo.variant == buttonDesc[i].variant); j++;
1040 buttonDesc[i].handle = last =
1041 XtCreateManagedWidget(buttonDesc[i].name, toggleWidgetClass, form, args, j);
1045 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1046 XtSetArg(args[j], XtNfromHoriz, buttonDesc[12].handle); j++;
1047 XtSetArg(args[j], XtNheight, 35); j++;
1048 // XtSetArg(args[j], XtNwidth, 60); j++;
1049 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1050 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1051 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1052 XtSetArg(args[j], XtNright, XtChainRight); j++;
1053 b_cancel= XtCreateManagedWidget(_("CANCEL"), commandWidgetClass, form, args, j);
1054 XtAddCallback(b_cancel, XtNcallback, NewVariantPopDown, (XtPointer) 0);
1057 XtSetArg(args[j], XtNfromHoriz, b_cancel); j++;
1058 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1059 XtSetArg(args[j], XtNheight, 35); j++;
1060 // XtSetArg(args[j], XtNwidth, 60); j++;
1061 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1062 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1063 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1064 XtSetArg(args[j], XtNright, XtChainRight); j++;
1065 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass, form, args, j);
1066 XtAddCallback(b_ok, XtNcallback, NewVariantCallback, (XtPointer) 0);
1069 XtSetArg(args[j], XtNfromVert, buttonDesc[14].handle); j++;
1070 // XtSetArg(args[j], XtNheight, 70); j++;
1071 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1072 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1073 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1074 XtSetArg(args[j], XtNright, XtChainRight); j++;
1075 XtSetArg(args[j], XtNlabel, _("WARNING: variants with un-orthodox\n"
1076 "pieces only have built-in bitmaps\n"
1077 "for -boardSize middling, bulky and\n"
1078 "petite, and substitute king or amazon\n"
1079 "for missing bitmaps. (See manual.)")); j++;
1080 XtCreateManagedWidget("warning", labelWidgetClass, form, args, j);
1082 XtRealizeWidget(popup);
1083 CatchDeleteWindow(popup, "NewVariantPopDown");
1085 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1086 &x, &y, &win_x, &win_y, &mask);
1088 XtSetArg(args[0], XtNx, x - 10);
1089 XtSetArg(args[1], XtNy, y - 30);
1090 XtSetValues(popup, args, 2);
1092 XtPopup(popup, XtGrabExclusive);
1093 NewVariantUp = True;
1096 void NewVariantProc(w, event, prms, nprms)
1105 //--------------------------- UCI Menu Popup ------------------------------------------
1115 struct UciControl controlDesc[] = {
1116 {N_("maximum nr of CPUs:"), 0, &appData.smpCores},
1117 {N_("Polyglot Directory:"), 0, &appData.polyglotDir},
1118 {N_("Hash Size (MB):"), 0, &appData.defaultHashSize},
1119 {N_("EGTB Path:"), 0, &appData.defaultPathEGTB},
1120 {N_("EGTB Cache (MB):"), 0, &appData.defaultCacheSizeEGTB},
1121 {N_("Polyglot Book:"), 0, &appData.polyglotBook},
1128 XtPopdown(UciShell);
1129 XtDestroyWidget(UciShell);
1134 void UciCallback(w, client_data, call_data)
1136 XtPointer client_data, call_data;
1141 int oldCores = appData.smpCores, ponder = 0;
1143 XtSetArg(args[0], XtNlabel, &name);
1144 XtGetValues(w, args, 1);
1146 if (strcmp(name, _("OK")) == 0) {
1147 int nr, i, j; String name;
1148 for(i=0; i<6; i++) {
1149 XtSetArg(args[0], XtNstring, &name);
1150 XtGetValues(controlDesc[i].handle, args, 1);
1153 *(char**) controlDesc[i].ptr = strdup(name);
1155 if(sscanf(name, "%d", &j) == 1)
1156 *(int*) controlDesc[i].ptr = j;
1159 XtSetArg(args[0], XtNstate, &appData.usePolyglotBook);
1160 XtGetValues(w1, args, 1);
1161 XtSetArg(args[0], XtNstate, &appData.firstHasOwnBookUCI);
1162 XtGetValues(w2, args, 1);
1163 XtSetArg(args[0], XtNstate, &appData.secondHasOwnBookUCI);
1164 XtGetValues(w3, args, 1);
1165 XtSetArg(args[0], XtNstate, &ponder);
1166 XtGetValues(w4, args, 1);
1168 // adjust setting in other menu for duplicates
1169 // (perhaps duplicates should be removed from general Option Menu?)
1170 XtSetArg(args[0], XtNleftBitmap, ponder ? xMarkPixmap : None);
1171 XtSetValues(XtNameToWidget(menuBarWidget,
1172 "menuOptions.Ponder Next Move"), args, 1);
1174 // make sure changes are sent to first engine by re-initializing it
1175 // if it was already started pre-emptively at end of previous game
1176 if(gameMode == BeginningOfGame) Reset(True, True); else {
1177 // Some changed setting need immediate sending always.
1178 PonderNextMoveEvent(ponder);
1179 if(oldCores != appData.smpCores)
1180 NewSettingEvent(False, "cores", appData.smpCores);
1190 Widget popup, layout, dialog, edit, form, b_ok, b_cancel, last = NULL, new, upperLeft;
1198 XtSetArg(args[i], XtNresizable, True); i++;
1199 // XtSetArg(args[i], XtNwidth, 300); i++;
1201 XtCreatePopupShell(_("Engine Settings"), transientShellWidgetClass,
1202 shellWidget, args, i);
1205 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1206 layoutArgs, XtNumber(layoutArgs));
1210 XtCreateManagedWidget("form", formWidgetClass, layout,
1211 formArgs, XtNumber(formArgs));
1214 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1215 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1216 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1217 // XtSetArg(args[j], XtNheight, 20); j++;
1218 for(i = 0; controlDesc[i].name != NULL; i++) {
1220 XtSetArg(args[j], XtNfromVert, last); j++;
1221 // XtSetArg(args[j], XtNwidth, 130); j++;
1222 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1223 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1224 XtSetArg(args[j], XtNborderWidth, 0); j++;
1225 new = XtCreateManagedWidget(controlDesc[i].name, labelWidgetClass, form, args, j);
1226 if(i==0) upperLeft = new;
1229 XtSetArg(args[j], XtNborderWidth, 1); j++;
1230 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1231 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1232 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1233 XtSetArg(args[j], XtNright, XtChainRight); j++;
1234 XtSetArg(args[j], XtNresizable, True); j++;
1235 XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++;
1237 XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ?
1238 * (char**) controlDesc[i].ptr : ""); j++;
1240 sprintf(def, "%d", * (int*) controlDesc[i].ptr);
1241 XtSetArg(args[j], XtNstring, def); j++;
1243 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1244 controlDesc[i].handle = last =
1245 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
1246 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1250 XtSetArg(args[j], XtNfromHoriz, controlDesc[0].handle); j++;
1251 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1252 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1253 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1254 XtSetArg(args[j], XtNright, XtChainRight); j++;
1255 XtSetArg(args[j], XtNstate, appData.ponderNextMove); j++;
1256 w4 = XtCreateManagedWidget(_("Ponder"), toggleWidgetClass, form, args, j);
1259 XtSetArg(args[j], XtNfromVert, last); j++;
1260 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1261 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1262 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1263 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1264 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1265 XtAddCallback(b_ok, XtNcallback, UciCallback, (XtPointer) 0);
1267 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
1268 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1269 XtAddCallback(b_cancel, XtNcallback, UciPopDown, (XtPointer) 0);
1272 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1273 XtSetArg(args[j], XtNstate, appData.usePolyglotBook); j++;
1274 w1 = XtCreateManagedWidget(_(" use book "), toggleWidgetClass, form, args, j);
1275 // XtAddCallback(w1, XtNcallback, UciCallback, (XtPointer) 0);
1278 XtSetArg(args[j], XtNfromHoriz, w1); j++;
1279 XtSetArg(args[j], XtNstate, appData.firstHasOwnBookUCI); j++;
1280 w2 = XtCreateManagedWidget(_("own book 1"), toggleWidgetClass, form, args, j);
1281 // XtAddCallback(w2, XtNcallback, UciCallback, (XtPointer) 0);
1284 XtSetArg(args[j], XtNfromHoriz, w2); j++;
1285 XtSetArg(args[j], XtNstate, appData.secondHasOwnBookUCI); j++;
1286 w3 = XtCreateManagedWidget(_("own book 2"), toggleWidgetClass, form, args, j);
1287 // XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0);
1289 XtRealizeWidget(popup);
1290 CatchDeleteWindow(popup, "UciPopDown");
1292 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1293 &x, &y, &win_x, &win_y, &mask);
1295 XtSetArg(args[0], XtNx, x - 10);
1296 XtSetArg(args[1], XtNy, y - 30);
1297 XtSetValues(popup, args, 2);
1299 XtPopup(popup, XtGrabExclusive);
1303 SetFocus(controlDesc[2].handle, popup, (XEvent*) NULL, False);
1304 // XtSetKeyboardFocus(popup, controlDesc[1].handle);
1307 void UciMenuProc(w, event, prms, nprms)
1316 //--------------------------- Engine-specific options menu ----------------------------------
1319 Widget SettingsShell;
1320 int values[MAX_OPTIONS];
1321 ChessProgramState *currentCps;
1323 void SettingsPopDown()
1325 if (!SettingsUp) return;
1326 XtPopdown(SettingsShell);
1327 XtDestroyWidget(SettingsShell);
1332 void SpinCallback(w, client_data, call_data)
1334 XtPointer client_data, call_data;
1342 XtSetArg(args[0], XtNlabel, &name);
1343 XtGetValues(w, args, 1);
1346 XtSetArg(args[0], XtNstring, &val);
1347 XtGetValues(currentCps->option[(int)client_data].handle, args, 1);
1348 sscanf(val, "%d", &j);
1349 if (strcmp(name, "+") == 0) {
1350 if(++j > currentCps->option[(int)client_data].max) return;
1352 if (strcmp(name, "-") == 0) {
1353 if(--j < currentCps->option[(int)client_data].min) return;
1355 sprintf(buf, "%d", j);
1356 XtSetArg(args[0], XtNstring, buf);
1357 XtSetValues(currentCps->option[(int)client_data].handle, args, 1);
1360 void SettingsCallback(w, client_data, call_data)
1362 XtPointer client_data, call_data;
1370 XtSetArg(args[0], XtNlabel, &name);
1371 XtGetValues(w, args, 1);
1373 if (strcmp(name, _("cancel")) == 0) {
1377 if (strcmp(name, _("OK")) == 0 || (int)client_data) { // save buttons imply OK
1380 for(i=0; i<currentCps->nrOptions; i++) { // send all options that had to be OK-ed to engine
1381 switch(currentCps->option[i].type) {
1383 XtSetArg(args[0], XtNstring, &val);
1384 XtGetValues(currentCps->option[i].handle, args, 1);
1385 if(strcmp(currentCps->option[i].textValue, val)) {
1386 strcpy(currentCps->option[i].textValue, val);
1387 sprintf(buf, "option %s=%s\n", currentCps->option[i].name, val);
1388 SendToProgram(buf, currentCps);
1392 XtSetArg(args[0], XtNstring, &val);
1393 XtGetValues(currentCps->option[i].handle, args, 1);
1394 sscanf(val, "%d", &j);
1395 if(j > currentCps->option[i].max) j = currentCps->option[i].max;
1396 if(j < currentCps->option[i].min) j = currentCps->option[i].min;
1397 if(currentCps->option[i].value != j) {
1398 currentCps->option[i].value = j;
1399 sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1400 SendToProgram(buf, currentCps);
1405 XtSetArg(args[0], XtNstate, &j);
1406 XtGetValues(currentCps->option[i].handle, args, 1);
1407 if(currentCps->option[i].value != j) {
1408 currentCps->option[i].value = j;
1409 sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1410 SendToProgram(buf, currentCps);
1414 if(currentCps->option[i].value != values[i]) {
1415 currentCps->option[i].value = values[i];
1416 sprintf(buf, "option %s=%s\n", currentCps->option[i].name,
1417 ((char**)currentCps->option[i].textValue)[values[i]]);
1418 SendToProgram(buf, currentCps);
1423 if((int)client_data) { // send save-button command to engine
1424 sprintf(buf, "option %s\n", name);
1425 SendToProgram(buf, currentCps);
1430 sprintf(buf, "option %s\n", name);
1431 SendToProgram(buf, currentCps);
1434 void ComboSelect(w, addr, index) // callback for all combo items
1440 int i = ((int)addr)>>8;
1441 int j = 255 & (int) addr;
1443 values[i] = j; // store in temporary, for transfer at OK
1444 XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]);
1445 XtSetValues(currentCps->option[i].handle, args, 1);
1448 void CreateComboPopup(parent, name, n, mb)
1458 menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
1461 XtSetArg(args[j], XtNwidth, 100); j++;
1462 // XtSetArg(args[j], XtNright, XtChainRight); j++;
1463 while (mb[i] != NULL) {
1464 entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
1466 XtAddCallback(entry, XtNcallback,
1467 (XtCallbackProc) ComboSelect,
1468 (caddr_t) (256*n+i));
1473 void SettingsPopUp(ChessProgramState *cps)
1476 Widget popup, layout, dialog, edit, form, oldform, last, b_ok, b_cancel;
1481 char def[80], *p, *q;
1483 // to do: start up second engine if needed
1484 if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
1488 XtSetArg(args[i], XtNresizable, True); i++;
1489 SettingsShell = popup =
1490 XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
1491 shellWidget, args, i);
1494 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1495 layoutArgs, XtNumber(layoutArgs));
1498 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
1499 formArgs, XtNumber(formArgs));
1501 for(i=0; i<cps->nrOptions; i++) {
1502 switch(cps->option[i].type) {
1504 sprintf(def, "%d", cps->option[i].value);
1507 XtSetArg(args[j], XtNfromVert, last); j++;
1508 XtSetArg(args[j], XtNborderWidth, 0); j++;
1509 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1510 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1512 XtSetArg(args[j], XtNfromVert, last); j++;
1513 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1514 XtSetArg(args[j], XtNborderWidth, 1); j++;
1515 XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 100); j++;
1516 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1517 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1518 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1519 XtSetArg(args[j], XtNright, XtChainRight); j++;
1520 XtSetArg(args[j], XtNresizable, True); j++;
1521 XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue); j++;
1523 cps->option[i].handle = (void*)
1524 (last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1525 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1526 if(cps->option[i].type == TextBox) break;
1528 // add increment and decrement controls for spin
1530 XtSetArg(args[j], XtNfromVert, edit); j++;
1531 XtSetArg(args[j], XtNfromHoriz, last); j++;
1532 XtSetArg(args[j], XtNheight, 10); j++;
1533 XtSetArg(args[j], XtNwidth, 20); j++;
1534 edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j);
1535 XtAddCallback(edit, XtNcallback, SpinCallback, (XtPointer) i);
1538 XtSetArg(args[j], XtNfromVert, edit); j++;
1539 XtSetArg(args[j], XtNfromHoriz, last); j++;
1540 XtSetArg(args[j], XtNheight, 10); j++;
1541 XtSetArg(args[j], XtNwidth, 20); j++;
1542 last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1543 XtAddCallback(last, XtNcallback, SpinCallback, (XtPointer) i);
1547 XtSetArg(args[j], XtNfromVert, last); j++;
1548 XtSetArg(args[j], XtNwidth, 10); j++;
1549 XtSetArg(args[j], XtNheight, 10); j++;
1550 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1551 cps->option[i].handle = (void*)
1552 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1554 XtSetArg(args[j], XtNfromVert, last); j++;
1555 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1556 XtSetArg(args[j], XtNborderWidth, 0); j++;
1557 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1558 last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1563 XtSetArg(args[j], XtNfromVert, last); j++;
1564 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1565 cps->option[i].handle = (void*)
1566 (last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));
1567 XtAddCallback(last, XtNcallback, SettingsCallback, (XtPointer) (cps->option[i].type == SaveButton));
1571 XtSetArg(args[j], XtNfromVert, last); j++;
1572 XtSetArg(args[j], XtNborderWidth, 0); j++;
1573 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1574 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1577 XtSetArg(args[j], XtNfromVert, last); j++;
1578 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1579 XtSetArg(args[j], XtNwidth, 100); j++;
1580 XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name)); j++;
1581 XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]); j++;
1582 cps->option[i].handle = (void*)
1583 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1584 CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue);
1585 values[i] = cps->option[i].value;
1591 XtSetArg(args[j], XtNfromVert, last); j++;
1592 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1593 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1594 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1595 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1596 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1597 XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
1599 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
1600 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1601 XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
1603 XtRealizeWidget(popup);
1604 CatchDeleteWindow(popup, "SettingsPopDown");
1606 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1607 &x, &y, &win_x, &win_y, &mask);
1609 XtSetArg(args[0], XtNx, x - 10);
1610 XtSetArg(args[1], XtNy, y - 30);
1611 XtSetValues(popup, args, 2);
1613 XtPopup(popup, XtGrabExclusive);
1617 SetFocus(edit, popup, (XEvent*) NULL, False);
1620 void FirstSettingsProc(w, event, prms, nprms)
1626 SettingsPopUp(&first);
1629 void SecondSettingsProc(w, event, prms, nprms)
1635 SettingsPopUp(&second);
1638 //--------------------------- General Popup for Cloning ----------------------------------
1646 XtPopdown(XXXShell);
1647 XtDestroyWidget(XXXShell);
1652 void XXXCallback(w, client_data, call_data)
1654 XtPointer client_data, call_data;
1661 XtSetArg(args[0], XtNlabel, &name);
1662 XtGetValues(w, args, 1);
1664 if (strcmp(name, _("cancel")) == 0) {
1668 if (strcmp(name, _("ok")) == 0) {
1669 int nr; String name;
1670 name = XawDialogGetValueString(w2 = XtParent(w));
1671 if(sscanf(name ,"%d",&nr) != 1) {
1672 sprintf(buf, "%d", appData.defaultFrcPosition);
1673 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
1674 XtSetValues(w2, args, 1);
1685 Widget popup, layout, dialog, edit;
1693 XtSetArg(args[i], XtNresizable, True); i++;
1694 XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
1696 XtCreatePopupShell(_("XXX Menu"), transientShellWidgetClass,
1697 shellWidget, args, i);
1700 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1701 layoutArgs, XtNumber(layoutArgs));
1703 sprintf(def, "%d\n", appData.defaultFrcPosition);
1705 XtSetArg(args[i], XtNlabel, ""); i++;
1706 XtSetArg(args[i], XtNvalue, def); i++;
1707 XtSetArg(args[i], XtNborderWidth, 0); i++;
1708 dialog = XtCreateManagedWidget("XXX", dialogWidgetClass,
1711 XawDialogAddButton(dialog, _("ok"), XXXCallback, (XtPointer) dialog);
1712 XawDialogAddButton(dialog, _("cancel"), XXXCallback, (XtPointer) dialog);
1714 XtRealizeWidget(popup);
1715 CatchDeleteWindow(popup, "XXXPopDown");
1717 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1718 &x, &y, &win_x, &win_y, &mask);
1720 XtSetArg(args[0], XtNx, x - 10);
1721 XtSetArg(args[1], XtNy, y - 30);
1722 XtSetValues(popup, args, 2);
1724 XtPopup(popup, XtGrabExclusive);
1727 edit = XtNameToWidget(dialog, "*value");
1730 SetFocus(engThreshold, popup, (XEvent*) NULL, False);
1733 void XXXMenuProc(w, event, prms, nprms)