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);
1068 XtRealizeWidget(popup);
1069 CatchDeleteWindow(popup, "NewVariantPopDown");
1071 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1072 &x, &y, &win_x, &win_y, &mask);
1074 XtSetArg(args[0], XtNx, x - 10);
1075 XtSetArg(args[1], XtNy, y - 30);
1076 XtSetValues(popup, args, 2);
1078 XtPopup(popup, XtGrabExclusive);
1079 NewVariantUp = True;
1082 void NewVariantProc(w, event, prms, nprms)
1091 //--------------------------- UCI Menu Popup ------------------------------------------
1101 struct UciControl controlDesc[] = {
1102 {N_("maximum nr of CPUs:"), 0, &appData.smpCores},
1103 {N_("Polyglot Directory:"), 0, &appData.polyglotDir},
1104 {N_("Hash Size (MB):"), 0, &appData.defaultHashSize},
1105 {N_("EGTB Path:"), 0, &appData.defaultPathEGTB},
1106 {N_("EGTB Cache (MB):"), 0, &appData.defaultCacheSizeEGTB},
1107 {N_("Polyglot Book:"), 0, &appData.polyglotBook},
1114 XtPopdown(UciShell);
1115 XtDestroyWidget(UciShell);
1120 void UciCallback(w, client_data, call_data)
1122 XtPointer client_data, call_data;
1127 int oldCores = appData.smpCores, ponder = 0;
1129 XtSetArg(args[0], XtNlabel, &name);
1130 XtGetValues(w, args, 1);
1132 if (strcmp(name, _("OK")) == 0) {
1133 int nr, i, j; String name;
1134 for(i=0; i<6; i++) {
1135 XtSetArg(args[0], XtNstring, &name);
1136 XtGetValues(controlDesc[i].handle, args, 1);
1139 *(char**) controlDesc[i].ptr = strdup(name);
1141 if(sscanf(name, "%d", &j) == 1)
1142 *(int*) controlDesc[i].ptr = j;
1145 XtSetArg(args[0], XtNstate, &appData.usePolyglotBook);
1146 XtGetValues(w1, args, 1);
1147 XtSetArg(args[0], XtNstate, &appData.firstHasOwnBookUCI);
1148 XtGetValues(w2, args, 1);
1149 XtSetArg(args[0], XtNstate, &appData.secondHasOwnBookUCI);
1150 XtGetValues(w3, args, 1);
1151 XtSetArg(args[0], XtNstate, &ponder);
1152 XtGetValues(w4, args, 1);
1154 // adjust setting in other menu for duplicates
1155 // (perhaps duplicates should be removed from general Option Menu?)
1156 XtSetArg(args[0], XtNleftBitmap, ponder ? xMarkPixmap : None);
1157 XtSetValues(XtNameToWidget(menuBarWidget,
1158 "menuOptions.Ponder Next Move"), args, 1);
1160 // make sure changes are sent to first engine by re-initializing it
1161 // if it was already started pre-emptively at end of previous game
1162 if(gameMode == BeginningOfGame) Reset(True, True); else {
1163 // Some changed setting need immediate sending always.
1164 PonderNextMoveEvent(ponder);
1165 if(oldCores != appData.smpCores)
1166 NewSettingEvent(False, "cores", appData.smpCores);
1176 Widget popup, layout, dialog, edit, form, b_ok, b_cancel, last = NULL, new, upperLeft;
1184 XtSetArg(args[i], XtNresizable, True); i++;
1185 // XtSetArg(args[i], XtNwidth, 300); i++;
1187 XtCreatePopupShell(_("Engine Settings"), transientShellWidgetClass,
1188 shellWidget, args, i);
1191 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1192 layoutArgs, XtNumber(layoutArgs));
1196 XtCreateManagedWidget("form", formWidgetClass, layout,
1197 formArgs, XtNumber(formArgs));
1200 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1201 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1202 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1203 // XtSetArg(args[j], XtNheight, 20); j++;
1204 for(i = 0; controlDesc[i].name != NULL; i++) {
1206 XtSetArg(args[j], XtNfromVert, last); j++;
1207 // XtSetArg(args[j], XtNwidth, 130); j++;
1208 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1209 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1210 XtSetArg(args[j], XtNborderWidth, 0); j++;
1211 new = XtCreateManagedWidget(controlDesc[i].name, labelWidgetClass, form, args, j);
1212 if(i==0) upperLeft = new;
1215 XtSetArg(args[j], XtNborderWidth, 1); j++;
1216 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1217 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1218 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1219 XtSetArg(args[j], XtNright, XtChainRight); j++;
1220 XtSetArg(args[j], XtNresizable, True); j++;
1221 XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++;
1223 XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ?
1224 * (char**) controlDesc[i].ptr : ""); j++;
1226 sprintf(def, "%d", * (int*) controlDesc[i].ptr);
1227 XtSetArg(args[j], XtNstring, def); j++;
1229 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1230 controlDesc[i].handle = last =
1231 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
1232 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1236 XtSetArg(args[j], XtNfromHoriz, controlDesc[0].handle); j++;
1237 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1238 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1239 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1240 XtSetArg(args[j], XtNright, XtChainRight); j++;
1241 XtSetArg(args[j], XtNstate, appData.ponderNextMove); j++;
1242 w4 = XtCreateManagedWidget(_("Ponder"), toggleWidgetClass, form, args, j);
1245 XtSetArg(args[j], XtNfromVert, last); j++;
1246 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1247 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1248 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1249 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1250 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1251 XtAddCallback(b_ok, XtNcallback, UciCallback, (XtPointer) 0);
1253 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
1254 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1255 XtAddCallback(b_cancel, XtNcallback, UciPopDown, (XtPointer) 0);
1258 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1259 XtSetArg(args[j], XtNstate, appData.usePolyglotBook); j++;
1260 w1 = XtCreateManagedWidget(_(" use book "), toggleWidgetClass, form, args, j);
1261 // XtAddCallback(w1, XtNcallback, UciCallback, (XtPointer) 0);
1264 XtSetArg(args[j], XtNfromHoriz, w1); j++;
1265 XtSetArg(args[j], XtNstate, appData.firstHasOwnBookUCI); j++;
1266 w2 = XtCreateManagedWidget(_("own book 1"), toggleWidgetClass, form, args, j);
1267 // XtAddCallback(w2, XtNcallback, UciCallback, (XtPointer) 0);
1270 XtSetArg(args[j], XtNfromHoriz, w2); j++;
1271 XtSetArg(args[j], XtNstate, appData.secondHasOwnBookUCI); j++;
1272 w3 = XtCreateManagedWidget(_("own book 2"), toggleWidgetClass, form, args, j);
1273 // XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0);
1275 XtRealizeWidget(popup);
1276 CatchDeleteWindow(popup, "UciPopDown");
1278 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1279 &x, &y, &win_x, &win_y, &mask);
1281 XtSetArg(args[0], XtNx, x - 10);
1282 XtSetArg(args[1], XtNy, y - 30);
1283 XtSetValues(popup, args, 2);
1285 XtPopup(popup, XtGrabExclusive);
1289 SetFocus(controlDesc[2].handle, popup, (XEvent*) NULL, False);
1290 // XtSetKeyboardFocus(popup, controlDesc[1].handle);
1293 void UciMenuProc(w, event, prms, nprms)
1302 //--------------------------- Engine-specific options menu ----------------------------------
1305 Widget SettingsShell;
1306 int values[MAX_OPTIONS];
1307 ChessProgramState *currentCps;
1309 void SettingsPopDown()
1311 if (!SettingsUp) return;
1312 XtPopdown(SettingsShell);
1313 XtDestroyWidget(SettingsShell);
1318 void SpinCallback(w, client_data, call_data)
1320 XtPointer client_data, call_data;
1328 XtSetArg(args[0], XtNlabel, &name);
1329 XtGetValues(w, args, 1);
1332 XtSetArg(args[0], XtNstring, &val);
1333 XtGetValues(currentCps->option[(int)client_data].handle, args, 1);
1334 sscanf(val, "%d", &j);
1335 if (strcmp(name, "+") == 0) {
1336 if(++j > currentCps->option[(int)client_data].max) return;
1338 if (strcmp(name, "-") == 0) {
1339 if(--j < currentCps->option[(int)client_data].min) return;
1341 sprintf(buf, "%d", j);
1342 XtSetArg(args[0], XtNstring, buf);
1343 XtSetValues(currentCps->option[(int)client_data].handle, args, 1);
1346 void SettingsCallback(w, client_data, call_data)
1348 XtPointer client_data, call_data;
1356 XtSetArg(args[0], XtNlabel, &name);
1357 XtGetValues(w, args, 1);
1359 if (strcmp(name, _("cancel")) == 0) {
1363 if (strcmp(name, _("OK")) == 0 || (int)client_data) { // save buttons imply OK
1366 for(i=0; i<currentCps->nrOptions; i++) { // send all options that had to be OK-ed to engine
1367 switch(currentCps->option[i].type) {
1369 XtSetArg(args[0], XtNstring, &val);
1370 XtGetValues(currentCps->option[i].handle, args, 1);
1371 if(strcmp(currentCps->option[i].textValue, val)) {
1372 strcpy(currentCps->option[i].textValue, val);
1373 sprintf(buf, "option %s=%s\n", currentCps->option[i].name, val);
1374 SendToProgram(buf, currentCps);
1378 XtSetArg(args[0], XtNstring, &val);
1379 XtGetValues(currentCps->option[i].handle, args, 1);
1380 sscanf(val, "%d", &j);
1381 if(j > currentCps->option[i].max) j = currentCps->option[i].max;
1382 if(j < currentCps->option[i].min) j = currentCps->option[i].min;
1383 if(currentCps->option[i].value != j) {
1384 currentCps->option[i].value = j;
1385 sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1386 SendToProgram(buf, currentCps);
1391 XtSetArg(args[0], XtNstate, &j);
1392 XtGetValues(currentCps->option[i].handle, args, 1);
1393 if(currentCps->option[i].value != j) {
1394 currentCps->option[i].value = j;
1395 sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1396 SendToProgram(buf, currentCps);
1400 if(currentCps->option[i].value != values[i]) {
1401 currentCps->option[i].value = values[i];
1402 sprintf(buf, "option %s=%s\n", currentCps->option[i].name,
1403 ((char**)currentCps->option[i].textValue)[values[i]]);
1404 SendToProgram(buf, currentCps);
1409 if((int)client_data) { // send save-button command to engine
1410 sprintf(buf, "option %s\n", name);
1411 SendToProgram(buf, currentCps);
1416 sprintf(buf, "option %s\n", name);
1417 SendToProgram(buf, currentCps);
1420 void ComboSelect(w, addr, index) // callback for all combo items
1426 int i = ((int)addr)>>8;
1427 int j = 255 & (int) addr;
1429 values[i] = j; // store in temporary, for transfer at OK
1430 XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]);
1431 XtSetValues(currentCps->option[i].handle, args, 1);
1434 void CreateComboPopup(parent, name, n, mb)
1444 menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
1447 XtSetArg(args[j], XtNwidth, 100); j++;
1448 // XtSetArg(args[j], XtNright, XtChainRight); j++;
1449 while (mb[i] != NULL) {
1450 entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
1452 XtAddCallback(entry, XtNcallback,
1453 (XtCallbackProc) ComboSelect,
1454 (caddr_t) (256*n+i));
1459 void SettingsPopUp(ChessProgramState *cps)
1462 Widget popup, layout, dialog, edit, form, oldform, last, b_ok, b_cancel;
1467 char def[80], *p, *q;
1469 // to do: start up second engine if needed
1470 if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
1474 XtSetArg(args[i], XtNresizable, True); i++;
1475 SettingsShell = popup =
1476 XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
1477 shellWidget, args, i);
1480 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1481 layoutArgs, XtNumber(layoutArgs));
1484 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
1485 formArgs, XtNumber(formArgs));
1487 for(i=0; i<cps->nrOptions; i++) {
1488 switch(cps->option[i].type) {
1490 sprintf(def, "%d", cps->option[i].value);
1493 XtSetArg(args[j], XtNfromVert, last); j++;
1494 XtSetArg(args[j], XtNborderWidth, 0); j++;
1495 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1496 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1498 XtSetArg(args[j], XtNfromVert, last); j++;
1499 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1500 XtSetArg(args[j], XtNborderWidth, 1); j++;
1501 XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 100); j++;
1502 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1503 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1504 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1505 XtSetArg(args[j], XtNright, XtChainRight); j++;
1506 XtSetArg(args[j], XtNresizable, True); j++;
1507 XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue); j++;
1509 cps->option[i].handle = (void*)
1510 (last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1511 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1512 if(cps->option[i].type == TextBox) break;
1514 // add increment and decrement controls for spin
1516 XtSetArg(args[j], XtNfromVert, edit); j++;
1517 XtSetArg(args[j], XtNfromHoriz, last); j++;
1518 XtSetArg(args[j], XtNheight, 10); j++;
1519 XtSetArg(args[j], XtNwidth, 20); j++;
1520 edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j);
1521 XtAddCallback(edit, XtNcallback, SpinCallback, (XtPointer) i);
1524 XtSetArg(args[j], XtNfromVert, edit); j++;
1525 XtSetArg(args[j], XtNfromHoriz, last); j++;
1526 XtSetArg(args[j], XtNheight, 10); j++;
1527 XtSetArg(args[j], XtNwidth, 20); j++;
1528 last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1529 XtAddCallback(last, XtNcallback, SpinCallback, (XtPointer) i);
1533 XtSetArg(args[j], XtNfromVert, last); j++;
1534 XtSetArg(args[j], XtNwidth, 10); j++;
1535 XtSetArg(args[j], XtNheight, 10); j++;
1536 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1537 cps->option[i].handle = (void*)
1538 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1540 XtSetArg(args[j], XtNfromVert, last); j++;
1541 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1542 XtSetArg(args[j], XtNborderWidth, 0); j++;
1543 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1544 last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1549 XtSetArg(args[j], XtNfromVert, last); j++;
1550 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1551 cps->option[i].handle = (void*)
1552 (last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));
1553 XtAddCallback(last, XtNcallback, SettingsCallback, (XtPointer) (cps->option[i].type == SaveButton));
1557 XtSetArg(args[j], XtNfromVert, last); j++;
1558 XtSetArg(args[j], XtNborderWidth, 0); j++;
1559 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1560 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1563 XtSetArg(args[j], XtNfromVert, last); j++;
1564 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1565 XtSetArg(args[j], XtNwidth, 100); j++;
1566 XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name)); j++;
1567 XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]); j++;
1568 cps->option[i].handle = (void*)
1569 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1570 CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue);
1571 values[i] = cps->option[i].value;
1577 XtSetArg(args[j], XtNfromVert, last); j++;
1578 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1579 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1580 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1581 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1582 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1583 XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
1585 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
1586 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1587 XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
1589 XtRealizeWidget(popup);
1590 CatchDeleteWindow(popup, "SettingsPopDown");
1592 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1593 &x, &y, &win_x, &win_y, &mask);
1595 XtSetArg(args[0], XtNx, x - 10);
1596 XtSetArg(args[1], XtNy, y - 30);
1597 XtSetValues(popup, args, 2);
1599 XtPopup(popup, XtGrabExclusive);
1603 SetFocus(edit, popup, (XEvent*) NULL, False);
1606 void FirstSettingsProc(w, event, prms, nprms)
1612 SettingsPopUp(&first);
1615 void SecondSettingsProc(w, event, prms, nprms)
1621 SettingsPopUp(&second);
1624 //--------------------------- General Popup for Cloning ----------------------------------
1632 XtPopdown(XXXShell);
1633 XtDestroyWidget(XXXShell);
1638 void XXXCallback(w, client_data, call_data)
1640 XtPointer client_data, call_data;
1647 XtSetArg(args[0], XtNlabel, &name);
1648 XtGetValues(w, args, 1);
1650 if (strcmp(name, _("cancel")) == 0) {
1654 if (strcmp(name, _("ok")) == 0) {
1655 int nr; String name;
1656 name = XawDialogGetValueString(w2 = XtParent(w));
1657 if(sscanf(name ,"%d",&nr) != 1) {
1658 sprintf(buf, "%d", appData.defaultFrcPosition);
1659 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
1660 XtSetValues(w2, args, 1);
1671 Widget popup, layout, dialog, edit;
1679 XtSetArg(args[i], XtNresizable, True); i++;
1680 XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
1682 XtCreatePopupShell(_("XXX Menu"), transientShellWidgetClass,
1683 shellWidget, args, i);
1686 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1687 layoutArgs, XtNumber(layoutArgs));
1689 sprintf(def, "%d\n", appData.defaultFrcPosition);
1691 XtSetArg(args[i], XtNlabel, ""); i++;
1692 XtSetArg(args[i], XtNvalue, def); i++;
1693 XtSetArg(args[i], XtNborderWidth, 0); i++;
1694 dialog = XtCreateManagedWidget("XXX", dialogWidgetClass,
1697 XawDialogAddButton(dialog, _("ok"), XXXCallback, (XtPointer) dialog);
1698 XawDialogAddButton(dialog, _("cancel"), XXXCallback, (XtPointer) dialog);
1700 XtRealizeWidget(popup);
1701 CatchDeleteWindow(popup, "XXXPopDown");
1703 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1704 &x, &y, &win_x, &win_y, &mask);
1706 XtSetArg(args[0], XtNx, x - 10);
1707 XtSetArg(args[1], XtNy, y - 30);
1708 XtSetValues(popup, args, 2);
1710 XtPopup(popup, XtGrabExclusive);
1713 edit = XtNameToWidget(dialog, "*value");
1716 SetFocus(engThreshold, popup, (XEvent*) NULL, False);
1719 void XXXMenuProc(w, event, prms, nprms)