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 */
50 #include <X11/Intrinsic.h>
51 #include <X11/StringDefs.h>
52 #include <X11/Shell.h>
53 #include <X11/Xaw/Dialog.h>
54 #include <X11/Xaw/Form.h>
55 #include <X11/Xaw/List.h>
56 #include <X11/Xaw/Label.h>
57 #include <X11/Xaw/SimpleMenu.h>
58 #include <X11/Xaw/SmeBSB.h>
59 #include <X11/Xaw/SmeLine.h>
60 #include <X11/Xaw/Box.h>
61 #include <X11/Xaw/Paned.h>
62 #include <X11/Xaw/MenuButton.h>
63 #include <X11/cursorfont.h>
64 #include <X11/Xaw/Text.h>
65 #include <X11/Xaw/AsciiText.h>
66 #include <X11/Xaw/Viewport.h>
67 #include <X11/Xaw/Toggle.h>
75 # define _(s) gettext (s)
76 # define N_(s) gettext_noop (s)
82 extern void SendToProgram P((char *message, ChessProgramState *cps));
84 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
85 extern Display *xDisplay;
86 extern int squareSize;
87 extern Pixmap xMarkPixmap;
88 extern char *layoutName;
89 extern Window xBoardWindow;
90 extern Arg layoutArgs[2], formArgs[2];
91 Pixel timerForegroundPixel, timerBackgroundPixel;
93 // [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines
95 static Widget previous = NULL;
97 void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
102 XtSetArg(args, XtNdisplayCaret, False);
103 XtSetValues(previous, &args, 1);
105 XtSetArg(args, XtNdisplayCaret, True);
106 XtSetValues(w, &args, 1);
107 XtSetKeyboardFocus((Widget) data, w);
111 //--------------------------- New Shuffle Game --------------------------------------------
112 extern int shuffleOpenings;
113 extern int startedFromPositionFile;
117 void ShufflePopDown()
119 if (!shuffleUp) return;
120 XtPopdown(shuffleShell);
121 XtDestroyWidget(shuffleShell);
126 void ShuffleCallback(w, client_data, call_data)
128 XtPointer client_data, call_data;
135 XtSetArg(args[0], XtNlabel, &name);
136 XtGetValues(w, args, 1);
138 if (strcmp(name, _("cancel")) == 0) {
142 if (strcmp(name, _("off")) == 0) {
144 shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it!
148 if (strcmp(name, _("random")) == 0) {
149 sprintf(buf, "%d", rand());
150 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
151 XtSetValues(XtParent(w), args, 1);
154 if (strcmp(name, _("ok")) == 0) {
156 name = XawDialogGetValueString(w2 = XtParent(w));
157 if(sscanf(name ,"%d",&nr) != 1) {
158 sprintf(buf, "%d", appData.defaultFrcPosition);
159 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
160 XtSetValues(w2, args, 1);
163 appData.defaultFrcPosition = nr;
164 shuffleOpenings = True;
174 Widget popup, layout, dialog, edit;
182 XtSetArg(args[i], XtNresizable, True); i++;
183 XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
184 shuffleShell = popup =
185 XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass,
186 shellWidget, args, i);
189 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
190 layoutArgs, XtNumber(layoutArgs));
192 sprintf(def, "%d\n", appData.defaultFrcPosition);
194 XtSetArg(args[i], XtNlabel, _("Start-position number:")); i++;
195 XtSetArg(args[i], XtNvalue, def); i++;
196 XtSetArg(args[i], XtNborderWidth, 0); i++;
197 dialog = XtCreateManagedWidget(_("Shuffle"), dialogWidgetClass,
200 // XtSetArg(args[0], XtNeditType, XawtextEdit); // [HGM] can't get edit to work decently
201 // XtSetArg(args[1], XtNuseStringInPlace, False);
202 // XtSetValues(dialog, args, 2);
204 XawDialogAddButton(dialog, _("ok"), ShuffleCallback, (XtPointer) dialog);
205 XawDialogAddButton(dialog, _("cancel"), ShuffleCallback, (XtPointer) dialog);
206 XawDialogAddButton(dialog, _("random"), ShuffleCallback, (XtPointer) dialog);
207 XawDialogAddButton(dialog, _("off"), ShuffleCallback, (XtPointer) dialog);
209 XtRealizeWidget(popup);
210 CatchDeleteWindow(popup, "ShufflePopDown");
212 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
213 &x, &y, &win_x, &win_y, &mask);
215 XtSetArg(args[0], XtNx, x - 10);
216 XtSetArg(args[1], XtNy, y - 30);
217 XtSetValues(popup, args, 2);
219 XtPopup(popup, XtGrabExclusive);
222 edit = XtNameToWidget(dialog, "*value");
224 XtSetKeyboardFocus(popup, edit);
227 void ShuffleMenuProc(w, event, prms, nprms)
233 // if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
234 // Reset(FALSE, TRUE);
239 //--------------------------- Time-Control Menu Popup ----------------------------------
241 Widget TimeControlShell;
243 Widget tcMess1, tcMess2, tcData, tcTime, tcOdds1, tcOdds2;
244 int tcIncrement, tcMoves;
246 void TimeControlPopDown()
248 if (!TimeControlUp) return;
250 XtPopdown(TimeControlShell);
251 XtDestroyWidget(TimeControlShell);
252 TimeControlUp = False;
256 void TimeControlCallback(w, client_data, call_data)
258 XtPointer client_data, call_data;
266 XtSetArg(args[0], XtNlabel, &name);
267 XtGetValues(w, args, 1);
269 if (strcmp(name, _("classical")) == 0) {
272 XtSetArg(args[j], XtNlabel, _("minutes for each")); j++;
273 XtSetValues(tcMess1, args, j);
275 XtSetArg(args[j], XtNlabel, _("moves")); j++;
276 XtSetValues(tcMess2, args, j);
278 XtSetArg(args[j], XtNstring, &name); j++;
279 XtGetValues(tcData, args, j);
280 tcIncrement = 0; sscanf(name, "%d", &tcIncrement);
281 sprintf(buf, "%d", tcMoves);
283 XtSetArg(args[j], XtNstring, buf); j++;
284 XtSetValues(tcData, args, j);
288 if (strcmp(name, _("incremental")) == 0) {
291 XtSetArg(args[j], XtNlabel, _("minutes, plus")); j++;
292 XtSetValues(tcMess1, args, j);
294 XtSetArg(args[j], XtNlabel, _("sec/move")); j++;
295 XtSetValues(tcMess2, args, j);
297 XtSetArg(args[j], XtNstring, &name); j++;
298 XtGetValues(tcData, args, j);
299 tcMoves = appData.movesPerSession; sscanf(name, "%d", &tcMoves);
300 sprintf(buf, "%d", tcIncrement);
302 XtSetArg(args[j], XtNstring, buf); j++;
303 XtSetValues(tcData, args, j);
307 if (strcmp(name, _(" OK ")) == 0) {
308 int inc, mps, tc, ok;
309 XtSetArg(args[0], XtNstring, &txt);
310 XtGetValues(tcData, args, 1);
312 ok = sscanf(txt, "%d", &inc); mps = 0;
313 if(!ok && txt[0] == 0) { inc = 0; ok = 1; } // accept empty string as zero
316 ok = sscanf(txt, "%d", &mps); inc = -1;
320 XtSetArg(args[0], XtNstring, ""); // erase any offending input
321 XtSetValues(tcData, args, 1);
324 XtSetArg(args[0], XtNstring, &txt);
325 XtGetValues(tcTime, args, 1);
326 if(!ParseTimeControl(txt, inc, mps)) {
327 XtSetArg(args[0], XtNstring, ""); // erase any offending input
328 XtSetValues(tcTime, args, 1);
329 DisplayError(_("Bad Time-Control String"), 0);
332 appData.movesPerSession = mps;
333 appData.timeIncrement = inc;
334 appData.timeControl = strdup(txt);
335 XtSetArg(args[0], XtNstring, &txt);
336 XtGetValues(tcOdds1, args, 1);
337 appData.firstTimeOdds = first.timeOdds
338 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
339 XtGetValues(tcOdds2, args, 1);
340 appData.secondTimeOdds = second.timeOdds
341 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
344 TimeControlPopDown();
349 void TimeControlPopUp()
352 Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, mess;
359 tcInc = (appData.timeIncrement >= 0);
360 tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
361 if(!tcInc) tcIncrement = 0;
362 sprintf(def, "%d", tcInc ? tcIncrement : tcMoves);
365 XtSetArg(args[i], XtNresizable, True); i++;
366 // XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
367 TimeControlShell = popup =
368 XtCreatePopupShell(_("TimeControl Menu"), transientShellWidgetClass,
369 shellWidget, args, i);
372 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
373 layoutArgs, XtNumber(layoutArgs));
376 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
377 formArgs, XtNumber(formArgs));
380 // XtSetArg(args[j], XtNwidth, (XtArgVal) 300); j++;
381 // XtSetArg(args[j], XtNheight, (XtArgVal) 85); j++;
382 XtSetValues(popup, args, j);
385 XtSetArg(args[j], XtNborderWidth, 1); j++;
386 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
387 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
388 XtSetArg(args[j], XtNstring, appData.timeControl); j++;
389 XtSetArg(args[j], XtNdisplayCaret, False); j++;
390 XtSetArg(args[j], XtNtop, XtChainTop); j++;
391 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
392 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
393 XtSetArg(args[j], XtNright, XtChainRight); j++;
394 XtSetArg(args[j], XtNresizable, True); j++;
395 XtSetArg(args[j], XtNwidth, 85); j++;
396 // XtSetArg(args[j], XtNheight, 20); j++;
397 tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j);
398 XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup);
401 XtSetArg(args[j], XtNlabel, tcInc ? _(" minutes, plus ") : _("minutes for each")); j++;
402 XtSetArg(args[j], XtNborderWidth, 0); j++;
403 XtSetArg(args[j], XtNfromHoriz, tcTime); j++;
404 XtSetArg(args[j], XtNtop, XtChainTop); j++;
405 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
406 XtSetArg(args[j], XtNleft, XtChainRight); j++;
407 XtSetArg(args[j], XtNright, XtChainRight); j++;
408 // XtSetArg(args[j], XtNwidth, 100); j++;
409 // XtSetArg(args[j], XtNheight, 20); j++;
410 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
413 XtSetArg(args[j], XtNborderWidth, 1); j++;
414 XtSetArg(args[j], XtNfromHoriz, tcMess1); j++;
415 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
416 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
417 XtSetArg(args[j], XtNstring, def); j++;
418 XtSetArg(args[j], XtNdisplayCaret, False); j++;
419 XtSetArg(args[j], XtNtop, XtChainTop); j++;
420 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
421 XtSetArg(args[j], XtNleft, XtChainRight); j++;
422 XtSetArg(args[j], XtNright, XtChainRight); j++;
423 XtSetArg(args[j], XtNresizable, True); j++;
424 XtSetArg(args[j], XtNwidth, 40); j++;
425 // XtSetArg(args[j], XtNheight, 20); j++;
426 tcData = XtCreateManagedWidget("MPS", asciiTextWidgetClass, form, args, j);
427 XtAddEventHandler(tcData, ButtonPressMask, False, SetFocus, (XtPointer) popup);
430 XtSetArg(args[j], XtNlabel, tcInc ? _("sec/move") : _("moves ")); j++;
431 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
432 XtSetArg(args[j], XtNborderWidth, 0); j++;
433 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
434 XtSetArg(args[j], XtNtop, XtChainTop); j++;
435 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
436 XtSetArg(args[j], XtNleft, XtChainRight); j++;
437 XtSetArg(args[j], XtNright, XtChainRight); j++;
438 // XtSetArg(args[j], XtNwidth, 80); j++;
439 // XtSetArg(args[j], XtNheight, 20); j++;
440 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass,
444 XtSetArg(args[j], XtNborderWidth, 1); j++;
445 XtSetArg(args[j], XtNfromVert, tcTime); j++;
446 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
447 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
448 XtSetArg(args[j], XtNstring, "1"); j++;
449 XtSetArg(args[j], XtNdisplayCaret, False); j++;
450 XtSetArg(args[j], XtNtop, XtChainTop); j++;
451 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
452 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
453 XtSetArg(args[j], XtNright, XtChainLeft); j++;
454 XtSetArg(args[j], XtNresizable, True); j++;
455 XtSetArg(args[j], XtNwidth, 40); j++;
456 // XtSetArg(args[j], XtNheight, 20); j++;
457 tcOdds1 = XtCreateManagedWidget("Odds1", asciiTextWidgetClass, form, args, j);
458 XtAddEventHandler(tcOdds1, ButtonPressMask, False, SetFocus, (XtPointer) popup);
461 XtSetArg(args[j], XtNborderWidth, 1); j++;
462 XtSetArg(args[j], XtNfromVert, tcTime); j++;
463 XtSetArg(args[j], XtNfromHoriz, tcOdds1); j++;
464 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
465 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
466 XtSetArg(args[j], XtNstring, "1"); j++;
467 XtSetArg(args[j], XtNdisplayCaret, False); j++;
468 XtSetArg(args[j], XtNtop, XtChainTop); j++;
469 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
470 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
471 XtSetArg(args[j], XtNright, XtChainLeft); j++;
472 XtSetArg(args[j], XtNresizable, True); j++;
473 XtSetArg(args[j], XtNwidth, 40); j++;
474 // XtSetArg(args[j], XtNheight, 20); j++;
475 tcOdds2 = XtCreateManagedWidget("Odds2", asciiTextWidgetClass, form, args, j);
476 XtAddEventHandler(tcOdds2, ButtonPressMask, False, SetFocus, (XtPointer) popup);
479 XtSetArg(args[j], XtNlabel, _("Engine #1 and #2 Time-Odds Factors")); j++;
480 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
481 XtSetArg(args[j], XtNborderWidth, 0); j++;
482 XtSetArg(args[j], XtNfromVert, tcTime); j++;
483 XtSetArg(args[j], XtNfromHoriz, tcOdds2); j++;
484 XtSetArg(args[j], XtNtop, XtChainTop); j++;
485 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
486 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
487 XtSetArg(args[j], XtNright, XtChainRight); j++;
488 // XtSetArg(args[j], XtNwidth, 200); j++;
489 // XtSetArg(args[j], XtNheight, 20); j++;
490 mess = XtCreateManagedWidget("Oddstext", labelWidgetClass,
493 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
494 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
495 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
496 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
497 XtSetArg(args[j], XtNright, XtChainLeft); j++;
498 b_clas= XtCreateManagedWidget(_("classical"), commandWidgetClass,
500 XtAddCallback(b_clas, XtNcallback, TimeControlCallback, (XtPointer) 0);
503 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
504 XtSetArg(args[j], XtNfromHoriz, b_clas); j++;
505 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
506 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
507 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
508 XtSetArg(args[j], XtNright, XtChainLeft); j++;
509 b_inc = XtCreateManagedWidget(_("incremental"), commandWidgetClass,
511 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
514 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
515 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
516 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
517 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
518 XtSetArg(args[j], XtNleft, XtChainRight); j++;
519 XtSetArg(args[j], XtNright, XtChainRight); j++;
520 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass,
522 XtAddCallback(b_ok, XtNcallback, TimeControlCallback, (XtPointer) 0);
525 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
526 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
527 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
528 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
529 XtSetArg(args[j], XtNleft, XtChainRight); j++;
530 XtSetArg(args[j], XtNright, XtChainRight); j++;
531 b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
533 XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0);
535 XtRealizeWidget(popup);
536 CatchDeleteWindow(popup, "TimeControlPopDown");
538 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
539 &x, &y, &win_x, &win_y, &mask);
541 XtSetArg(args[0], XtNx, x - 10);
542 XtSetArg(args[1], XtNy, y - 30);
543 XtSetValues(popup, args, 2);
545 XtPopup(popup, XtGrabExclusive);
546 TimeControlUp = True;
549 SetFocus(tcTime, popup, (XEvent*) NULL, False);
550 // XtSetKeyboardFocus(popup, tcTime);
553 void TimeControlProc(w, event, prms, nprms)
562 //--------------------------- Engine-Options Menu Popup ----------------------------------
565 extern int adjudicateLossThreshold;
567 Widget engDrawMoves, engThreshold, engRule, engRepeat;
571 if (!EngineUp) return;
573 XtPopdown(EngineShell);
574 XtDestroyWidget(EngineShell);
579 int ReadToggle(Widget w)
581 Arg args; Boolean res;
583 XtSetArg(args, XtNstate, &res);
584 XtGetValues(w, &args, 1);
589 Widget w1, w2, w3, w4, w5, w6, w7, w8;
591 void EngineCallback(w, client_data, call_data)
593 XtPointer client_data, call_data;
601 XtSetArg(args[0], XtNlabel, &name);
602 XtGetValues(w, args, 1);
604 if (strcmp(name, _("OK")) == 0) {
606 appData.periodicUpdates = ReadToggle(w1);
607 // appData.hideThinkingFromHuman = ReadToggle(w2);
608 first.scoreIsAbsolute = appData.firstScoreIsAbsolute = ReadToggle(w3);
609 second.scoreIsAbsolute = appData.secondScoreIsAbsolute = ReadToggle(w4);
610 appData.testClaims = ReadToggle(w5);
611 appData.checkMates = ReadToggle(w6);
612 appData.materialDraws = ReadToggle(w7);
613 appData.trivialDraws = ReadToggle(w8);
615 // adjust setting in other menu for duplicates
616 // (perhaps duplicates should be removed from general Option Menu?)
617 // XtSetArg(args[0], XtNleftBitmap, appData.showThinking ? xMarkPixmap : None);
618 // XtSetValues(XtNameToWidget(menuBarWidget,
619 // "menuOptions.Show Thinking"), args, 1);
621 // read out numeric controls, simply ignore bad formats for now
622 XtSetArg(args[0], XtNstring, &name);
623 XtGetValues(engDrawMoves, args, 1);
624 if(sscanf(name, "%d", &j) == 1) appData.adjudicateDrawMoves = j;
625 XtGetValues(engThreshold, args, 1);
626 if(sscanf(name, "%d", &j) == 1)
627 adjudicateLossThreshold = appData.adjudicateLossThreshold = -j; // inverted!
628 XtGetValues(engRule, args, 1);
629 if(sscanf(name, "%d", &j) == 1) appData.ruleMoves = j;
630 XtGetValues(engRepeat, args, 1);
631 if(sscanf(name, "%d", &j) == 1) appData.drawRepeats = j;
634 ShowThinkingEvent(); // [HGM] thinking: score adjudication might need thinking output
642 Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, s1;
644 int x, y, i, j, width;
649 tcInc = (appData.timeIncrement >= 0);
650 tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
651 if(!tcInc) tcIncrement = 0;
652 sprintf(def, "%d", tcInc ? tcIncrement : tcMoves);
655 XtSetArg(args[i], XtNresizable, True); i++;
656 // XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
657 EngineShell = popup =
658 XtCreatePopupShell(_("Adjudications"), transientShellWidgetClass,
659 shellWidget, args, i);
662 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
663 layoutArgs, XtNumber(layoutArgs));
666 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
667 formArgs, XtNumber(formArgs));
670 // XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++;
671 // XtSetArg(args[j], XtNheight, (XtArgVal) 400); j++;
672 // XtSetValues(popup, args, j);
675 // XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++;
676 // XtSetArg(args[j], XtNheight, (XtArgVal) 20); j++;
677 XtSetArg(args[j], XtNleft, (XtArgVal) XtChainLeft); j++;
678 XtSetArg(args[j], XtNright, (XtArgVal) XtChainRight); j++;
679 XtSetArg(args[j], XtNstate, appData.periodicUpdates); j++;
680 // XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
681 w1 = XtCreateManagedWidget(_("Periodic Updates (Analysis Mode)"), toggleWidgetClass, form, args, j);
683 XtSetArg(args[j], XtNwidth, (XtArgVal) &width);
684 XtGetValues(w1, &args[j], 1);
686 // XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w1);
687 // XtSetArg(args[j-3], XtNstate, appData.hideThinkingFromHuman);
688 // w2 = XtCreateManagedWidget(_("Hide Thinking from Human"), toggleWidgetClass, form, args, j);
690 XtSetArg(args[j], XtNwidth, (XtArgVal) width); j++;
691 XtSetArg(args[j-2], XtNstate, appData.firstScoreIsAbsolute);
692 XtSetArg(args[j], XtNfromVert, (XtArgVal) w1); j++;
693 w3 = XtCreateManagedWidget(_("Engine #1 Score is Absolute"), toggleWidgetClass, form, args, j);
695 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w3);
696 XtSetArg(args[j-3], XtNstate, appData.secondScoreIsAbsolute);
697 w4 = XtCreateManagedWidget(_("Engine #2 Score is Absolute"), toggleWidgetClass, form, args, j);
699 s1 = XtCreateManagedWidget(_("\nEngine-Engine Adjudications:"), labelWidgetClass, form, args, 3);
701 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) s1);
702 XtSetArg(args[j-3], XtNstate, appData.testClaims);
703 w5 = XtCreateManagedWidget(_("Verify Engine Result Claims"), toggleWidgetClass, form, args, j);
705 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w5);
706 XtSetArg(args[j-3], XtNstate, appData.checkMates);
707 w6 = XtCreateManagedWidget(_("Detect All Mates"), toggleWidgetClass, form, args, j);
709 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w6);
710 XtSetArg(args[j-3], XtNstate, appData.materialDraws);
711 w7 = XtCreateManagedWidget(_("Draw when Insuff. Mating Material"), toggleWidgetClass, form, args, j);
713 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w7);
714 XtSetArg(args[j-3], XtNstate, appData.trivialDraws);
715 w8 = XtCreateManagedWidget(_("Adjudicate Trivial Draws"), toggleWidgetClass, form, args, j);
717 XtSetArg(args[0], XtNfromVert, (XtArgVal) w4);
718 XtSetArg(args[1], XtNborderWidth, (XtArgVal) 0);
719 XtSetValues(s1, args, 2);
721 sprintf(def, "%d", appData.adjudicateDrawMoves);
723 XtSetArg(args[j], XtNborderWidth, 1); j++;
724 XtSetArg(args[j], XtNfromVert, w8); j++;
725 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
726 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
727 XtSetArg(args[j], XtNstring, def); j++;
728 XtSetArg(args[j], XtNdisplayCaret, False); j++;
729 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
730 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
731 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
732 XtSetArg(args[j], XtNright, XtChainLeft); j++;
733 XtSetArg(args[j], XtNresizable, True); j++;
734 XtSetArg(args[j], XtNwidth, 60); j++;
735 // XtSetArg(args[j], XtNheight, 20); j++;
736 engDrawMoves = XtCreateManagedWidget("Length", asciiTextWidgetClass, form, args, j);
737 XtAddEventHandler(engDrawMoves, ButtonPressMask, False, SetFocus, (XtPointer) popup);
740 XtSetArg(args[j], XtNlabel, _(" moves maximum, then draw")); j++;
741 XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
742 XtSetArg(args[j], XtNborderWidth, 0); j++;
743 XtSetArg(args[j], XtNfromVert, w8); j++;
744 XtSetArg(args[j], XtNfromHoriz, engDrawMoves); j++;
745 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
746 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
747 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
748 XtSetArg(args[j], XtNright, XtChainLeft); j++;
749 // XtSetArg(args[j], XtNwidth, 170); j++;
750 // XtSetArg(args[j], XtNheight, 20); j++;
751 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
753 sprintf(def, "%d", -appData.adjudicateLossThreshold); // inverted!
755 XtSetArg(args[j], XtNborderWidth, 1); j++;
756 XtSetArg(args[j], XtNfromVert, engDrawMoves); j++;
757 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
758 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
759 XtSetArg(args[j], XtNstring, def); j++;
760 XtSetArg(args[j], XtNdisplayCaret, False); j++;
761 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
762 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
763 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
764 XtSetArg(args[j], XtNright, XtChainLeft); j++;
765 XtSetArg(args[j], XtNresizable, True); j++;
766 XtSetArg(args[j], XtNwidth, 60); j++;
767 // XtSetArg(args[j], XtNheight, 20); j++;
768 engThreshold = XtCreateManagedWidget("Threshold", asciiTextWidgetClass, form, args, j);
769 XtAddEventHandler(engThreshold, ButtonPressMask, False, SetFocus, (XtPointer) popup);
772 XtSetArg(args[j], XtNlabel, _("-centiPawn lead is win")); j++;
773 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
774 XtSetArg(args[j], XtNborderWidth, 0); j++;
775 XtSetArg(args[j], XtNfromVert, engDrawMoves); j++;
776 XtSetArg(args[j], XtNfromHoriz, engThreshold); j++;
777 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
778 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
779 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
780 XtSetArg(args[j], XtNright, XtChainLeft); j++;
781 // XtSetArg(args[j], XtNwidth, 150); j++;
782 // XtSetArg(args[j], XtNheight, 20); j++;
783 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j);
785 sprintf(def, "%d", appData.ruleMoves);
787 XtSetArg(args[j], XtNborderWidth, 1); j++;
788 XtSetArg(args[j], XtNfromVert, engThreshold); j++;
789 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
790 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
791 XtSetArg(args[j], XtNstring, def); j++;
792 XtSetArg(args[j], XtNdisplayCaret, False); j++;
793 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
794 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
795 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
796 XtSetArg(args[j], XtNright, XtChainLeft); j++;
797 XtSetArg(args[j], XtNresizable, True); j++;
798 XtSetArg(args[j], XtNwidth, 30); j++;
799 // XtSetArg(args[j], XtNheight, 20); j++;
800 engRule = XtCreateManagedWidget("Rule", asciiTextWidgetClass, form, args, j);
801 XtAddEventHandler(engRule, ButtonPressMask, False, SetFocus, (XtPointer) popup);
804 XtSetArg(args[j], XtNlabel, _("-move rule applied")); j++;
805 XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
806 XtSetArg(args[j], XtNborderWidth, 0); j++;
807 XtSetArg(args[j], XtNfromVert, engThreshold); j++;
808 XtSetArg(args[j], XtNfromHoriz, engRule); j++;
809 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
810 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
811 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
812 XtSetArg(args[j], XtNright, XtChainLeft); j++;
813 // XtSetArg(args[j], XtNwidth, 130); j++;
814 // XtSetArg(args[j], XtNheight, 20); j++;
815 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
817 sprintf(def, "%d", appData.drawRepeats);
819 XtSetArg(args[j], XtNborderWidth, 1); j++;
820 XtSetArg(args[j], XtNfromVert, engRule); j++;
821 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
822 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
823 XtSetArg(args[j], XtNstring, def); j++;
824 XtSetArg(args[j], XtNdisplayCaret, False); j++;
825 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
826 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
827 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
828 XtSetArg(args[j], XtNright, XtChainLeft); j++;
829 XtSetArg(args[j], XtNresizable, True); j++;
830 XtSetArg(args[j], XtNwidth, 30); j++;
831 // XtSetArg(args[j], XtNheight, 20); j++;
832 engRepeat = XtCreateManagedWidget("Repeats", asciiTextWidgetClass, form, args, j);
833 XtAddEventHandler(engRepeat, ButtonPressMask, False, SetFocus, (XtPointer) popup);
836 XtSetArg(args[j], XtNlabel, _("-fold repeat is draw")); j++;
837 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
838 XtSetArg(args[j], XtNborderWidth, 0); j++;
839 XtSetArg(args[j], XtNfromVert, engRule); j++;
840 XtSetArg(args[j], XtNfromHoriz, engRepeat); j++;
841 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
842 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
843 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
844 XtSetArg(args[j], XtNright, XtChainLeft); j++;
845 // XtSetArg(args[j], XtNwidth, 130); j++;
846 // XtSetArg(args[j], XtNheight, 20); j++;
847 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j);
850 XtSetArg(args[j], XtNfromVert, engRepeat); j++;
851 XtSetArg(args[j], XtNfromHoriz, tcMess2); j++;
852 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
853 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
854 XtSetArg(args[j], XtNleft, XtChainRight); j++;
855 XtSetArg(args[j], XtNright, XtChainRight); j++;
856 b_ok= XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
857 XtAddCallback(b_ok, XtNcallback, EngineCallback, (XtPointer) 0);
860 XtSetArg(args[j], XtNfromVert, engRepeat); j++;
861 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
862 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
863 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
864 XtSetArg(args[j], XtNleft, XtChainRight); j++;
865 XtSetArg(args[j], XtNright, XtChainRight); j++;
866 b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
868 XtAddCallback(b_cancel, XtNcallback, EnginePopDown, (XtPointer) 0);
870 XtRealizeWidget(popup);
871 CatchDeleteWindow(popup, "EnginePopDown");
873 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
874 &x, &y, &win_x, &win_y, &mask);
876 XtSetArg(args[0], XtNx, x - 10);
877 XtSetArg(args[1], XtNy, y - 30);
878 XtSetValues(popup, args, 2);
880 XtPopup(popup, XtGrabExclusive);
884 SetFocus(engThreshold, popup, (XEvent*) NULL, False);
887 void EngineMenuProc(w, event, prms, nprms)
896 //--------------------------- New-Variant Menu PopUp -----------------------------------
897 struct NewVarButton {
901 VariantClass variant;
904 struct NewVarButton buttonDesc[] = {
905 {N_("normal"), "#FFFFFF", 0, VariantNormal},
906 {N_("FRC"), "#FFFFFF", 0, VariantFischeRandom},
907 {N_("wild castle"), "#FFFFFF", 0, VariantWildCastle},
908 {N_("no castle"), "#FFFFFF", 0, VariantNoCastle},
909 {N_("knightmate"), "#FFFFFF", 0, VariantKnightmate},
910 {N_("berolina"), "#FFFFFF", 0, VariantBerolina},
911 {N_("cylinder"), "#FFFFFF", 0, VariantCylinder},
912 {N_("shatranj"), "#FFFFFF", 0, VariantShatranj},
913 {N_("makruk"), "#FFFFFF", 0, VariantMakruk},
914 {N_("atomic"), "#FFFFFF", 0, VariantAtomic},
915 {N_("two kings"), "#FFFFFF", 0, VariantTwoKings},
916 {N_("3-checks"), "#FFFFFF", 0, Variant3Check},
917 {N_("suicide"), "#FFFFBF", 0, VariantSuicide},
918 {N_("give-away"), "#FFFFBF", 0, VariantGiveaway},
919 {N_("losers"), "#FFFFBF", 0, VariantLosers},
920 {N_("fairy"), "#BFBFBF", 0, VariantFairy},
921 {N_("Superchess"), "#FFBFBF", 0, VariantSuper},
922 {N_("crazyhouse"), "#FFBFBF", 0, VariantCrazyhouse},
923 {N_("bughouse"), "#FFBFBF", 0, VariantBughouse},
924 {N_("shogi (9x9)"), "#BFFFFF", 0, VariantShogi},
925 {N_("xiangqi (9x10)"), "#BFFFFF", 0, VariantXiangqi},
926 {N_("courier (12x8)"), "#BFFFBF", 0, VariantCourier},
927 {N_("janus (10x8)"), "#BFBFFF", 0, VariantJanus},
928 {N_("Capablanca (10x8)"), "#BFBFFF", 0, VariantCapablanca},
929 {N_("CRC (10x8)"), "#BFBFFF", 0, VariantCapaRandom},
931 {N_("Gothic (10x8)"), "#BFBFFF", 0, VariantGothic},
934 {N_("Falcon (10x8)"), "#BFBFFF", 0, VariantFalcon},
936 {NULL, 0, 0, (VariantClass) 0}
940 Widget NewVariantShell;
942 void NewVariantPopDown()
944 if (!NewVariantUp) return;
945 XtPopdown(NewVariantShell);
946 XtDestroyWidget(NewVariantShell);
947 NewVariantUp = False;
951 void NewVariantCallback(w, client_data, call_data)
953 XtPointer client_data, call_data;
961 XtSetArg(args[0], XtNlabel, &name);
962 XtGetValues(w, args, 1);
964 if (strcmp(name, _(" OK ")) == 0) {
965 int nr = (intptr_t) XawToggleGetCurrent(buttonDesc[0].handle) - 1;
967 v = buttonDesc[nr].variant;
968 if(!appData.noChessProgram) {
969 char *name = VariantName(v), buf[MSG_SIZ];
970 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
971 /* [HGM] in protocol 2 we check if variant is suported by engine */
972 sprintf(buf, _("Variant %s not supported by %s"), name, first.tidy);
973 DisplayError(buf, 0);
974 // NewVariantPopDown();
975 return; /* ignore OK if first engine does not support it */
977 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
978 sprintf(buf, _("Warning: second engine (%s) does not support this!"), second.tidy);
979 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
983 gameInfo.variant = v;
984 appData.variant = VariantName(v);
986 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
987 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
988 appData.pieceToCharTable = NULL;
995 void NewVariantPopUp()
998 Widget popup, layout, dialog, edit, form, last = NULL, b_ok, b_cancel;
1004 XrmValue vFrom, vTo;
1007 XtSetArg(args[i], XtNresizable, True); i++;
1008 // XtSetArg(args[i], XtNwidth, 250); i++;
1009 // XtSetArg(args[i], XtNheight, 300); i++;
1010 NewVariantShell = popup =
1011 XtCreatePopupShell(_("NewVariant Menu"), transientShellWidgetClass,
1012 shellWidget, args, i);
1015 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1016 layoutArgs, XtNumber(layoutArgs));
1019 XtCreateManagedWidget("form", formWidgetClass, layout,
1020 formArgs, XtNumber(formArgs));
1022 for(i = 0; buttonDesc[i].name != NULL; i++) {
1024 if (!appData.monoMode) {
1025 vFrom.addr = (caddr_t) buttonDesc[i].color;
1026 vFrom.size = strlen(buttonDesc[i].color);
1027 XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1028 if (vTo.addr == NULL) {
1029 buttonColor = (Pixel) -1;
1031 buttonColor = *(Pixel *) vTo.addr;
1036 XtSetArg(args[j], XtNradioGroup, last); j++;
1037 XtSetArg(args[j], XtNwidth, 125); j++;
1038 // XtSetArg(args[j], XtNheight, 16); j++;
1039 XtSetArg(args[j], XtNfromVert, i == 15 ? NULL : last); j++;
1040 XtSetArg(args[j], XtNfromHoriz, i < 15 ? NULL : buttonDesc[i-15].handle); j++;
1041 XtSetArg(args[j], XtNradioData, i+1); j++;
1042 XtSetArg(args[j], XtNbackground, buttonColor); j++;
1043 XtSetArg(args[j], XtNstate, gameInfo.variant == buttonDesc[i].variant); j++;
1044 buttonDesc[i].handle = last =
1045 XtCreateManagedWidget(buttonDesc[i].name, toggleWidgetClass, form, args, j);
1049 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1050 XtSetArg(args[j], XtNfromHoriz, buttonDesc[12].handle); j++;
1051 XtSetArg(args[j], XtNheight, 35); j++;
1052 // XtSetArg(args[j], XtNwidth, 60); j++;
1053 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1054 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1055 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1056 XtSetArg(args[j], XtNright, XtChainRight); j++;
1057 b_cancel= XtCreateManagedWidget(_("CANCEL"), commandWidgetClass, form, args, j);
1058 XtAddCallback(b_cancel, XtNcallback, NewVariantPopDown, (XtPointer) 0);
1061 XtSetArg(args[j], XtNfromHoriz, b_cancel); j++;
1062 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1063 XtSetArg(args[j], XtNheight, 35); j++;
1064 // XtSetArg(args[j], XtNwidth, 60); j++;
1065 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1066 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1067 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1068 XtSetArg(args[j], XtNright, XtChainRight); j++;
1069 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass, form, args, j);
1070 XtAddCallback(b_ok, XtNcallback, NewVariantCallback, (XtPointer) 0);
1073 XtSetArg(args[j], XtNfromVert, buttonDesc[14].handle); j++;
1074 // XtSetArg(args[j], XtNheight, 70); j++;
1075 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1076 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1077 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1078 XtSetArg(args[j], XtNright, XtChainRight); j++;
1079 XtSetArg(args[j], XtNlabel, _("WARNING: variants with un-orthodox\n"
1080 "pieces only have built-in bitmaps\n"
1081 "for -boardSize middling, bulky and\n"
1082 "petite, and substitute king or amazon\n"
1083 "for missing bitmaps. (See manual.)")); j++;
1084 XtCreateManagedWidget("warning", labelWidgetClass, form, args, j);
1086 XtRealizeWidget(popup);
1087 CatchDeleteWindow(popup, "NewVariantPopDown");
1089 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1090 &x, &y, &win_x, &win_y, &mask);
1092 XtSetArg(args[0], XtNx, x - 10);
1093 XtSetArg(args[1], XtNy, y - 30);
1094 XtSetValues(popup, args, 2);
1096 XtPopup(popup, XtGrabExclusive);
1097 NewVariantUp = True;
1100 void NewVariantProc(w, event, prms, nprms)
1109 //--------------------------- UCI Menu Popup ------------------------------------------
1119 struct UciControl controlDesc[] = {
1120 {N_("maximum nr of CPUs:"), 0, &appData.smpCores},
1121 {N_("Polyglot Directory:"), 0, &appData.polyglotDir},
1122 {N_("Hash Size (MB):"), 0, &appData.defaultHashSize},
1123 {N_("EGTB Path:"), 0, &appData.defaultPathEGTB},
1124 {N_("EGTB Cache (MB):"), 0, &appData.defaultCacheSizeEGTB},
1125 {N_("Polyglot Book:"), 0, &appData.polyglotBook},
1133 XtPopdown(UciShell);
1134 XtDestroyWidget(UciShell);
1139 void UciCallback(w, client_data, call_data)
1141 XtPointer client_data, call_data;
1146 int oldCores = appData.smpCores, ponder = 0;
1148 XtSetArg(args[0], XtNlabel, &name);
1149 XtGetValues(w, args, 1);
1151 if (strcmp(name, _("OK")) == 0) {
1152 int nr, i, j; String name;
1153 for(i=0; i<6; i++) {
1154 XtSetArg(args[0], XtNstring, &name);
1155 XtGetValues(controlDesc[i].handle, args, 1);
1158 *(char**) controlDesc[i].ptr = strdup(name);
1160 if(sscanf(name, "%d", &j) == 1)
1161 *(int*) controlDesc[i].ptr = j;
1164 XtSetArg(args[0], XtNstate, &appData.usePolyglotBook);
1165 XtGetValues(w1, args, 1);
1166 XtSetArg(args[0], XtNstate, &appData.firstHasOwnBookUCI);
1167 XtGetValues(w2, args, 1);
1168 XtSetArg(args[0], XtNstate, &appData.secondHasOwnBookUCI);
1169 XtGetValues(w3, args, 1);
1170 XtSetArg(args[0], XtNstate, &ponder);
1171 XtGetValues(w4, args, 1);
1173 // adjust setting in other menu for duplicates
1174 // (perhaps duplicates should be removed from general Option Menu?)
1175 XtSetArg(args[0], XtNleftBitmap, ponder ? xMarkPixmap : None);
1176 XtSetValues(XtNameToWidget(menuBarWidget,
1177 "menuOptions.Ponder Next Move"), args, 1);
1179 // make sure changes are sent to first engine by re-initializing it
1180 // if it was already started pre-emptively at end of previous game
1181 if(gameMode == BeginningOfGame) Reset(True, True); else {
1182 // Some changed setting need immediate sending always.
1183 PonderNextMoveEvent(ponder);
1184 if(oldCores != appData.smpCores)
1185 NewSettingEvent(False, "cores", appData.smpCores);
1195 Widget popup, layout, dialog, edit, form, b_ok, b_cancel, last = NULL, new, upperLeft;
1203 XtSetArg(args[i], XtNresizable, True); i++;
1204 // XtSetArg(args[i], XtNwidth, 300); i++;
1206 XtCreatePopupShell(_("Engine Settings"), transientShellWidgetClass,
1207 shellWidget, args, i);
1210 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1211 layoutArgs, XtNumber(layoutArgs));
1215 XtCreateManagedWidget("form", formWidgetClass, layout,
1216 formArgs, XtNumber(formArgs));
1219 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1220 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1221 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1222 // XtSetArg(args[j], XtNheight, 20); j++;
1223 for(i = 0; controlDesc[i].name != NULL; i++) {
1225 XtSetArg(args[j], XtNfromVert, last); j++;
1226 // XtSetArg(args[j], XtNwidth, 130); j++;
1227 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1228 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1229 XtSetArg(args[j], XtNborderWidth, 0); j++;
1230 new = XtCreateManagedWidget(controlDesc[i].name, labelWidgetClass, form, args, j);
1231 if(i==0) upperLeft = new;
1234 XtSetArg(args[j], XtNborderWidth, 1); j++;
1235 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1236 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1237 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1238 XtSetArg(args[j], XtNright, XtChainRight); j++;
1239 XtSetArg(args[j], XtNresizable, True); j++;
1240 XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++;
1242 XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ?
1243 * (char**) controlDesc[i].ptr : ""); j++;
1245 sprintf(def, "%d", * (int*) controlDesc[i].ptr);
1246 XtSetArg(args[j], XtNstring, def); j++;
1248 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1249 controlDesc[i].handle = last =
1250 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
1251 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1255 XtSetArg(args[j], XtNfromHoriz, controlDesc[0].handle); j++;
1256 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1257 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1258 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1259 XtSetArg(args[j], XtNright, XtChainRight); j++;
1260 XtSetArg(args[j], XtNstate, appData.ponderNextMove); j++;
1261 w4 = XtCreateManagedWidget(_("Ponder"), toggleWidgetClass, form, args, j);
1264 XtSetArg(args[j], XtNfromVert, last); j++;
1265 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1266 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1267 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1268 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1269 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1270 XtAddCallback(b_ok, XtNcallback, UciCallback, (XtPointer) 0);
1272 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
1273 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1274 XtAddCallback(b_cancel, XtNcallback, UciPopDown, (XtPointer) 0);
1277 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1278 XtSetArg(args[j], XtNstate, appData.usePolyglotBook); j++;
1279 w1 = XtCreateManagedWidget(_(" use book "), toggleWidgetClass, form, args, j);
1280 // XtAddCallback(w1, XtNcallback, UciCallback, (XtPointer) 0);
1283 XtSetArg(args[j], XtNfromHoriz, w1); j++;
1284 XtSetArg(args[j], XtNstate, appData.firstHasOwnBookUCI); j++;
1285 w2 = XtCreateManagedWidget(_("own book 1"), toggleWidgetClass, form, args, j);
1286 // XtAddCallback(w2, XtNcallback, UciCallback, (XtPointer) 0);
1289 XtSetArg(args[j], XtNfromHoriz, w2); j++;
1290 XtSetArg(args[j], XtNstate, appData.secondHasOwnBookUCI); j++;
1291 w3 = XtCreateManagedWidget(_("own book 2"), toggleWidgetClass, form, args, j);
1292 // XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0);
1294 XtRealizeWidget(popup);
1295 CatchDeleteWindow(popup, "UciPopDown");
1297 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1298 &x, &y, &win_x, &win_y, &mask);
1300 XtSetArg(args[0], XtNx, x - 10);
1301 XtSetArg(args[1], XtNy, y - 30);
1302 XtSetValues(popup, args, 2);
1304 XtPopup(popup, XtGrabExclusive);
1308 SetFocus(controlDesc[2].handle, popup, (XEvent*) NULL, False);
1309 // XtSetKeyboardFocus(popup, controlDesc[1].handle);
1312 void UciMenuProc(w, event, prms, nprms)
1321 //--------------------------- Engine-specific options menu ----------------------------------
1324 Widget SettingsShell;
1325 int values[MAX_OPTIONS];
1326 ChessProgramState *currentCps;
1328 void SettingsPopDown()
1330 if (!SettingsUp) return;
1332 XtPopdown(SettingsShell);
1333 XtDestroyWidget(SettingsShell);
1338 void SpinCallback(w, client_data, call_data)
1340 XtPointer client_data, call_data;
1347 int data = (intptr_t) client_data;
1349 XtSetArg(args[0], XtNlabel, &name);
1350 XtGetValues(w, args, 1);
1353 XtSetArg(args[0], XtNstring, &val);
1354 XtGetValues(currentCps->option[data].handle, args, 1);
1355 sscanf(val, "%d", &j);
1356 if (strcmp(name, "+") == 0) {
1357 if(++j > currentCps->option[data].max) return;
1359 if (strcmp(name, "-") == 0) {
1360 if(--j < currentCps->option[data].min) return;
1362 sprintf(buf, "%d", j);
1363 XtSetArg(args[0], XtNstring, buf);
1364 XtSetValues(currentCps->option[data].handle, args, 1);
1367 void SettingsCallback(w, client_data, call_data)
1369 XtPointer client_data, call_data;
1376 int data = (intptr_t) client_data;
1378 XtSetArg(args[0], XtNlabel, &name);
1379 XtGetValues(w, args, 1);
1381 if (strcmp(name, _("cancel")) == 0) {
1385 if (strcmp(name, _("OK")) == 0 || data) { // save buttons imply OK
1388 for(i=0; i<currentCps->nrOptions; i++) { // send all options that had to be OK-ed to engine
1389 switch(currentCps->option[i].type) {
1391 XtSetArg(args[0], XtNstring, &val);
1392 XtGetValues(currentCps->option[i].handle, args, 1);
1393 if(strcmp(currentCps->option[i].textValue, val)) {
1394 strcpy(currentCps->option[i].textValue, val);
1395 sprintf(buf, "option %s=%s\n", currentCps->option[i].name, val);
1396 SendToProgram(buf, currentCps);
1400 XtSetArg(args[0], XtNstring, &val);
1401 XtGetValues(currentCps->option[i].handle, args, 1);
1402 sscanf(val, "%d", &j);
1403 if(j > currentCps->option[i].max) j = currentCps->option[i].max;
1404 if(j < currentCps->option[i].min) j = currentCps->option[i].min;
1405 if(currentCps->option[i].value != j) {
1406 currentCps->option[i].value = j;
1407 sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1408 SendToProgram(buf, currentCps);
1413 XtSetArg(args[0], XtNstate, &j);
1414 XtGetValues(currentCps->option[i].handle, args, 1);
1415 if(currentCps->option[i].value != j) {
1416 currentCps->option[i].value = j;
1417 sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1418 SendToProgram(buf, currentCps);
1422 if(currentCps->option[i].value != values[i]) {
1423 currentCps->option[i].value = values[i];
1424 sprintf(buf, "option %s=%s\n", currentCps->option[i].name,
1425 ((char**)currentCps->option[i].textValue)[values[i]]);
1426 SendToProgram(buf, currentCps);
1431 if(data) { // send save-button command to engine
1432 sprintf(buf, "option %s\n", name);
1433 SendToProgram(buf, currentCps);
1438 sprintf(buf, "option %s\n", name);
1439 SendToProgram(buf, currentCps);
1442 void ComboSelect(w, addr, index) // callback for all combo items
1448 int i = ((intptr_t)addr)>>8;
1449 int j = 255 & (intptr_t) addr;
1451 values[i] = j; // store in temporary, for transfer at OK
1452 XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]);
1453 XtSetValues(currentCps->option[i].handle, args, 1);
1456 void CreateComboPopup(parent, name, n, mb)
1466 menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
1469 XtSetArg(args[j], XtNwidth, 100); j++;
1470 // XtSetArg(args[j], XtNright, XtChainRight); j++;
1471 while (mb[i] != NULL) {
1472 entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
1474 XtAddCallback(entry, XtNcallback,
1475 (XtCallbackProc) ComboSelect,
1476 (caddr_t)(intptr_t) (256*n+i));
1481 void SettingsPopUp(ChessProgramState *cps)
1484 Widget popup, layout, dialog, edit=NULL, form, oldform, last, b_ok, b_cancel, leftMargin = NULL;
1486 int x, y, i, j, height, width, h, c;
1487 int win_x, win_y, maxWidth, maxTextWidth;
1489 char def[80], *p, *q;
1490 static char pane[6] = "paneX";
1491 Widget texts[100], forelast = NULL, anchor, widest;
1493 // to do: start up second engine if needed
1494 if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
1497 if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1;
1498 height = cps->nrOptions / width + 1;
1500 XtSetArg(args[i], XtNresizable, True); i++;
1501 SettingsShell = popup =
1502 XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
1503 shellWidget, args, i);
1506 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1507 layoutArgs, XtNumber(layoutArgs));
1508 for(c=0; c<width; c++) {
1511 XtCreateManagedWidget(pane, formWidgetClass, layout,
1512 formArgs, XtNumber(formArgs));
1514 XtSetArg(args[j], XtNfromHoriz, leftMargin); j++;
1515 XtSetValues(form, args, j);
1518 last = widest = NULL; anchor = forelast;
1519 for(h=0; h<height; h++) {
1522 if(i >= cps->nrOptions) break;
1523 switch(cps->option[i].type) {
1525 sprintf(def, "%d", cps->option[i].value);
1528 XtSetArg(args[j], XtNfromVert, last); j++;
1529 XtSetArg(args[j], XtNborderWidth, 0); j++;
1530 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1532 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1534 XtSetArg(args[j], XtNfromVert, last); j++;
1535 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1536 XtSetArg(args[j], XtNborderWidth, 1); j++;
1537 XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 175); j++;
1538 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1539 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1540 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1541 XtSetArg(args[j], XtNright, XtChainRight); j++;
1542 XtSetArg(args[j], XtNresizable, True); j++;
1543 XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue); j++;
1545 cps->option[i].handle = (void*)
1546 (last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1547 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1548 if(cps->option[i].type == TextBox) break;
1550 // add increment and decrement controls for spin
1552 XtSetArg(args[j], XtNfromVert, edit); j++;
1553 XtSetArg(args[j], XtNfromHoriz, last); j++;
1554 XtSetArg(args[j], XtNheight, 10); j++;
1555 XtSetArg(args[j], XtNwidth, 20); j++;
1556 edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j);
1557 XtAddCallback(edit, XtNcallback, SpinCallback,
1558 (XtPointer)(intptr_t) i);
1561 XtSetArg(args[j], XtNfromVert, edit); j++;
1562 XtSetArg(args[j], XtNfromHoriz, last); j++;
1563 XtSetArg(args[j], XtNheight, 10); j++;
1564 XtSetArg(args[j], XtNwidth, 20); j++;
1565 last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1566 XtAddCallback(last, XtNcallback, SpinCallback,
1567 (XtPointer)(intptr_t) i);
1571 XtSetArg(args[j], XtNfromVert, last); j++;
1572 XtSetArg(args[j], XtNwidth, 10); j++;
1573 XtSetArg(args[j], XtNheight, 10); j++;
1574 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1575 cps->option[i].handle = (void*)
1576 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1578 XtSetArg(args[j], XtNfromVert, last); j++;
1579 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1580 XtSetArg(args[j], XtNborderWidth, 0); j++;
1581 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1582 last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1587 XtSetArg(args[j], XtNfromVert, last); j++;
1588 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1589 cps->option[i].handle = (void*)
1590 (dialog = last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));
1591 XtAddCallback(last, XtNcallback, SettingsCallback,
1592 (XtPointer)(intptr_t) (cps->option[i].type == SaveButton));
1596 XtSetArg(args[j], XtNfromVert, last); j++;
1597 XtSetArg(args[j], XtNborderWidth, 0); j++;
1598 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1599 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1602 XtSetArg(args[j], XtNfromVert, last); j++;
1603 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1604 XtSetArg(args[j], XtNwidth, 100); j++;
1605 XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name)); j++;
1606 XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]); j++;
1607 cps->option[i].handle = (void*)
1608 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1609 CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue);
1610 values[i] = cps->option[i].value;
1615 // make an attempt to align all spins and textbox controls
1616 maxWidth = maxTextWidth = 0;
1617 for(h=0; h<height; h++) {
1619 if(i >= cps->nrOptions) break;
1620 if(cps->option[i].type == Spin || cps->option[i].type == TextBox) {
1623 XtSetArg(args[j], XtNwidth, &w); j++;
1624 XtGetValues(texts[h], args, j);
1625 if(cps->option[i].type == Spin) {
1626 if(w > maxWidth) maxWidth = w;
1629 if(w > maxTextWidth) maxTextWidth = w;
1630 if(!widest) widest = texts[h];
1634 if(maxTextWidth + 110 < maxWidth)
1635 maxTextWidth = maxWidth - 110;
1636 else maxWidth = maxTextWidth + 110;
1637 for(h=0; h<height; h++) {
1639 if(i >= cps->nrOptions) break;
1641 if(cps->option[i].type == Spin) {
1642 XtSetArg(args[j], XtNwidth, maxWidth); j++;
1643 XtSetValues(texts[h], args, j);
1645 if(cps->option[i].type == TextBox) {
1646 XtSetArg(args[j], XtNwidth, maxTextWidth); j++;
1647 XtSetValues(texts[h], args, j);
1652 XtSetArg(args[j], XtNfromVert, anchor ? anchor : last); j++;
1653 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1654 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1655 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1656 XtSetArg(args[j], XtNright, XtChainRight); j++;
1657 XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog); j++;
1658 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1659 XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
1661 XtSetArg(args[j-1], XtNfromHoriz, b_ok);
1662 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1663 XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
1665 XtRealizeWidget(popup);
1666 CatchDeleteWindow(popup, "SettingsPopDown");
1668 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1669 &x, &y, &win_x, &win_y, &mask);
1671 XtSetArg(args[0], XtNx, x - 10);
1672 XtSetArg(args[1], XtNy, y - 30);
1673 XtSetValues(popup, args, 2);
1675 XtPopup(popup, XtGrabExclusive);
1679 if(edit)SetFocus(edit, popup, (XEvent*) NULL, False);
1682 void FirstSettingsProc(w, event, prms, nprms)
1688 SettingsPopUp(&first);
1691 void SecondSettingsProc(w, event, prms, nprms)
1697 SettingsPopUp(&second);
1700 //---------------------------- Chat Windows ----------------------------------------------
1702 void OutputChatMessage(int partner, char *mess)