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_("atomic"), "#FFFFFF", 0, VariantAtomic},
914 {N_("two kings"), "#FFFFFF", 0, VariantTwoKings},
915 {N_("3-checks"), "#FFFFFF", 0, Variant3Check},
916 {N_("suicide"), "#FFFFBF", 0, VariantSuicide},
917 {N_("give-away"), "#FFFFBF", 0, VariantGiveaway},
918 {N_("losers"), "#FFFFBF", 0, VariantLosers},
919 {N_("fairy"), "#BFBFBF", 0, VariantFairy},
920 {N_("Superchess"), "#FFBFBF", 0, VariantSuper},
921 {N_("crazyhouse"), "#FFBFBF", 0, VariantCrazyhouse},
922 {N_("bughouse"), "#FFBFBF", 0, VariantBughouse},
923 {N_("shogi (9x9)"), "#BFFFFF", 0, VariantShogi},
924 {N_("xiangqi (9x10)"), "#BFFFFF", 0, VariantXiangqi},
925 {N_("courier (12x8)"), "#BFFFBF", 0, VariantCourier},
926 {N_("janus (10x8)"), "#BFBFFF", 0, VariantJanus},
927 {N_("Capablanca (10x8)"), "#BFBFFF", 0, VariantCapablanca},
928 {N_("CRC (10x8)"), "#BFBFFF", 0, VariantCapaRandom},
930 {N_("Gothic (10x8)"), "#BFBFFF", 0, VariantGothic},
933 {N_("Falcon (10x8)"), "#BFBFFF", 0, VariantFalcon},
935 {NULL, 0, 0, (VariantClass) 0}
939 Widget NewVariantShell;
941 void NewVariantPopDown()
943 if (!NewVariantUp) return;
944 XtPopdown(NewVariantShell);
945 XtDestroyWidget(NewVariantShell);
946 NewVariantUp = False;
950 void NewVariantCallback(w, client_data, call_data)
952 XtPointer client_data, call_data;
960 XtSetArg(args[0], XtNlabel, &name);
961 XtGetValues(w, args, 1);
963 if (strcmp(name, _(" OK ")) == 0) {
964 int nr = (intptr_t) XawToggleGetCurrent(buttonDesc[0].handle) - 1;
966 v = buttonDesc[nr].variant;
967 if(!appData.noChessProgram) {
968 char *name = VariantName(v), buf[MSG_SIZ];
969 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
970 /* [HGM] in protocol 2 we check if variant is suported by engine */
971 sprintf(buf, _("Variant %s not supported by %s"), name, first.tidy);
972 DisplayError(buf, 0);
973 // NewVariantPopDown();
974 return; /* ignore OK if first engine does not support it */
976 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
977 sprintf(buf, _("Warning: second engine (%s) does not support this!"), second.tidy);
978 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
982 gameInfo.variant = v;
983 appData.variant = VariantName(v);
985 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
986 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
987 appData.pieceToCharTable = NULL;
994 void NewVariantPopUp()
997 Widget popup, layout, dialog, edit, form, last = NULL, b_ok, b_cancel;
1003 XrmValue vFrom, vTo;
1006 XtSetArg(args[i], XtNresizable, True); i++;
1007 // XtSetArg(args[i], XtNwidth, 250); i++;
1008 // XtSetArg(args[i], XtNheight, 300); i++;
1009 NewVariantShell = popup =
1010 XtCreatePopupShell(_("NewVariant Menu"), transientShellWidgetClass,
1011 shellWidget, args, i);
1014 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1015 layoutArgs, XtNumber(layoutArgs));
1018 XtCreateManagedWidget("form", formWidgetClass, layout,
1019 formArgs, XtNumber(formArgs));
1021 for(i = 0; buttonDesc[i].name != NULL; i++) {
1023 if (!appData.monoMode) {
1024 vFrom.addr = (caddr_t) buttonDesc[i].color;
1025 vFrom.size = strlen(buttonDesc[i].color);
1026 XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1027 if (vTo.addr == NULL) {
1028 buttonColor = (Pixel) -1;
1030 buttonColor = *(Pixel *) vTo.addr;
1035 XtSetArg(args[j], XtNradioGroup, last); j++;
1036 XtSetArg(args[j], XtNwidth, 125); j++;
1037 // XtSetArg(args[j], XtNheight, 16); j++;
1038 XtSetArg(args[j], XtNfromVert, i == 15 ? NULL : last); j++;
1039 XtSetArg(args[j], XtNfromHoriz, i < 15 ? NULL : buttonDesc[i-15].handle); j++;
1040 XtSetArg(args[j], XtNradioData, i+1); j++;
1041 XtSetArg(args[j], XtNbackground, buttonColor); j++;
1042 XtSetArg(args[j], XtNstate, gameInfo.variant == buttonDesc[i].variant); j++;
1043 buttonDesc[i].handle = last =
1044 XtCreateManagedWidget(buttonDesc[i].name, toggleWidgetClass, form, args, j);
1048 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1049 XtSetArg(args[j], XtNfromHoriz, buttonDesc[12].handle); j++;
1050 XtSetArg(args[j], XtNheight, 35); j++;
1051 // XtSetArg(args[j], XtNwidth, 60); j++;
1052 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1053 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1054 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1055 XtSetArg(args[j], XtNright, XtChainRight); j++;
1056 b_cancel= XtCreateManagedWidget(_("CANCEL"), commandWidgetClass, form, args, j);
1057 XtAddCallback(b_cancel, XtNcallback, NewVariantPopDown, (XtPointer) 0);
1060 XtSetArg(args[j], XtNfromHoriz, b_cancel); j++;
1061 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1062 XtSetArg(args[j], XtNheight, 35); j++;
1063 // XtSetArg(args[j], XtNwidth, 60); j++;
1064 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1065 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1066 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1067 XtSetArg(args[j], XtNright, XtChainRight); j++;
1068 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass, form, args, j);
1069 XtAddCallback(b_ok, XtNcallback, NewVariantCallback, (XtPointer) 0);
1072 XtSetArg(args[j], XtNfromVert, buttonDesc[14].handle); j++;
1073 // XtSetArg(args[j], XtNheight, 70); j++;
1074 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1075 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1076 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1077 XtSetArg(args[j], XtNright, XtChainRight); j++;
1078 XtSetArg(args[j], XtNlabel, _("WARNING: variants with un-orthodox\n"
1079 "pieces only have built-in bitmaps\n"
1080 "for -boardSize middling, bulky and\n"
1081 "petite, and substitute king or amazon\n"
1082 "for missing bitmaps. (See manual.)")); j++;
1083 XtCreateManagedWidget("warning", labelWidgetClass, form, args, j);
1085 XtRealizeWidget(popup);
1086 CatchDeleteWindow(popup, "NewVariantPopDown");
1088 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1089 &x, &y, &win_x, &win_y, &mask);
1091 XtSetArg(args[0], XtNx, x - 10);
1092 XtSetArg(args[1], XtNy, y - 30);
1093 XtSetValues(popup, args, 2);
1095 XtPopup(popup, XtGrabExclusive);
1096 NewVariantUp = True;
1099 void NewVariantProc(w, event, prms, nprms)
1108 //--------------------------- UCI Menu Popup ------------------------------------------
1118 struct UciControl controlDesc[] = {
1119 {N_("maximum nr of CPUs:"), 0, &appData.smpCores},
1120 {N_("Polyglot Directory:"), 0, &appData.polyglotDir},
1121 {N_("Hash Size (MB):"), 0, &appData.defaultHashSize},
1122 {N_("EGTB Path:"), 0, &appData.defaultPathEGTB},
1123 {N_("EGTB Cache (MB):"), 0, &appData.defaultCacheSizeEGTB},
1124 {N_("Polyglot Book:"), 0, &appData.polyglotBook},
1132 XtPopdown(UciShell);
1133 XtDestroyWidget(UciShell);
1138 void UciCallback(w, client_data, call_data)
1140 XtPointer client_data, call_data;
1145 int oldCores = appData.smpCores, ponder = 0;
1147 XtSetArg(args[0], XtNlabel, &name);
1148 XtGetValues(w, args, 1);
1150 if (strcmp(name, _("OK")) == 0) {
1151 int nr, i, j; String name;
1152 for(i=0; i<6; i++) {
1153 XtSetArg(args[0], XtNstring, &name);
1154 XtGetValues(controlDesc[i].handle, args, 1);
1157 *(char**) controlDesc[i].ptr = strdup(name);
1159 if(sscanf(name, "%d", &j) == 1)
1160 *(int*) controlDesc[i].ptr = j;
1163 XtSetArg(args[0], XtNstate, &appData.usePolyglotBook);
1164 XtGetValues(w1, args, 1);
1165 XtSetArg(args[0], XtNstate, &appData.firstHasOwnBookUCI);
1166 XtGetValues(w2, args, 1);
1167 XtSetArg(args[0], XtNstate, &appData.secondHasOwnBookUCI);
1168 XtGetValues(w3, args, 1);
1169 XtSetArg(args[0], XtNstate, &ponder);
1170 XtGetValues(w4, args, 1);
1172 // adjust setting in other menu for duplicates
1173 // (perhaps duplicates should be removed from general Option Menu?)
1174 XtSetArg(args[0], XtNleftBitmap, ponder ? xMarkPixmap : None);
1175 XtSetValues(XtNameToWidget(menuBarWidget,
1176 "menuOptions.Ponder Next Move"), args, 1);
1178 // make sure changes are sent to first engine by re-initializing it
1179 // if it was already started pre-emptively at end of previous game
1180 if(gameMode == BeginningOfGame) Reset(True, True); else {
1181 // Some changed setting need immediate sending always.
1182 PonderNextMoveEvent(ponder);
1183 if(oldCores != appData.smpCores)
1184 NewSettingEvent(False, "cores", appData.smpCores);
1194 Widget popup, layout, dialog, edit, form, b_ok, b_cancel, last = NULL, new, upperLeft;
1202 XtSetArg(args[i], XtNresizable, True); i++;
1203 // XtSetArg(args[i], XtNwidth, 300); i++;
1205 XtCreatePopupShell(_("Engine Settings"), transientShellWidgetClass,
1206 shellWidget, args, i);
1209 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1210 layoutArgs, XtNumber(layoutArgs));
1214 XtCreateManagedWidget("form", formWidgetClass, layout,
1215 formArgs, XtNumber(formArgs));
1218 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1219 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1220 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1221 // XtSetArg(args[j], XtNheight, 20); j++;
1222 for(i = 0; controlDesc[i].name != NULL; i++) {
1224 XtSetArg(args[j], XtNfromVert, last); j++;
1225 // XtSetArg(args[j], XtNwidth, 130); j++;
1226 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1227 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1228 XtSetArg(args[j], XtNborderWidth, 0); j++;
1229 new = XtCreateManagedWidget(controlDesc[i].name, labelWidgetClass, form, args, j);
1230 if(i==0) upperLeft = new;
1233 XtSetArg(args[j], XtNborderWidth, 1); j++;
1234 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1235 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1236 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1237 XtSetArg(args[j], XtNright, XtChainRight); j++;
1238 XtSetArg(args[j], XtNresizable, True); j++;
1239 XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++;
1241 XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ?
1242 * (char**) controlDesc[i].ptr : ""); j++;
1244 sprintf(def, "%d", * (int*) controlDesc[i].ptr);
1245 XtSetArg(args[j], XtNstring, def); j++;
1247 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1248 controlDesc[i].handle = last =
1249 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
1250 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1254 XtSetArg(args[j], XtNfromHoriz, controlDesc[0].handle); j++;
1255 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1256 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1257 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1258 XtSetArg(args[j], XtNright, XtChainRight); j++;
1259 XtSetArg(args[j], XtNstate, appData.ponderNextMove); j++;
1260 w4 = XtCreateManagedWidget(_("Ponder"), toggleWidgetClass, form, args, j);
1263 XtSetArg(args[j], XtNfromVert, last); j++;
1264 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1265 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1266 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1267 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1268 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1269 XtAddCallback(b_ok, XtNcallback, UciCallback, (XtPointer) 0);
1271 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
1272 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1273 XtAddCallback(b_cancel, XtNcallback, UciPopDown, (XtPointer) 0);
1276 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1277 XtSetArg(args[j], XtNstate, appData.usePolyglotBook); j++;
1278 w1 = XtCreateManagedWidget(_(" use book "), toggleWidgetClass, form, args, j);
1279 // XtAddCallback(w1, XtNcallback, UciCallback, (XtPointer) 0);
1282 XtSetArg(args[j], XtNfromHoriz, w1); j++;
1283 XtSetArg(args[j], XtNstate, appData.firstHasOwnBookUCI); j++;
1284 w2 = XtCreateManagedWidget(_("own book 1"), toggleWidgetClass, form, args, j);
1285 // XtAddCallback(w2, XtNcallback, UciCallback, (XtPointer) 0);
1288 XtSetArg(args[j], XtNfromHoriz, w2); j++;
1289 XtSetArg(args[j], XtNstate, appData.secondHasOwnBookUCI); j++;
1290 w3 = XtCreateManagedWidget(_("own book 2"), toggleWidgetClass, form, args, j);
1291 // XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0);
1293 XtRealizeWidget(popup);
1294 CatchDeleteWindow(popup, "UciPopDown");
1296 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1297 &x, &y, &win_x, &win_y, &mask);
1299 XtSetArg(args[0], XtNx, x - 10);
1300 XtSetArg(args[1], XtNy, y - 30);
1301 XtSetValues(popup, args, 2);
1303 XtPopup(popup, XtGrabExclusive);
1307 SetFocus(controlDesc[2].handle, popup, (XEvent*) NULL, False);
1308 // XtSetKeyboardFocus(popup, controlDesc[1].handle);
1311 void UciMenuProc(w, event, prms, nprms)
1320 //--------------------------- Engine-specific options menu ----------------------------------
1323 Widget SettingsShell;
1324 int values[MAX_OPTIONS];
1325 ChessProgramState *currentCps;
1327 void SettingsPopDown()
1329 if (!SettingsUp) return;
1331 XtPopdown(SettingsShell);
1332 XtDestroyWidget(SettingsShell);
1337 void SpinCallback(w, client_data, call_data)
1339 XtPointer client_data, call_data;
1346 int data = (intptr_t) client_data;
1348 XtSetArg(args[0], XtNlabel, &name);
1349 XtGetValues(w, args, 1);
1352 XtSetArg(args[0], XtNstring, &val);
1353 XtGetValues(currentCps->option[data].handle, args, 1);
1354 sscanf(val, "%d", &j);
1355 if (strcmp(name, "+") == 0) {
1356 if(++j > currentCps->option[data].max) return;
1358 if (strcmp(name, "-") == 0) {
1359 if(--j < currentCps->option[data].min) return;
1361 sprintf(buf, "%d", j);
1362 XtSetArg(args[0], XtNstring, buf);
1363 XtSetValues(currentCps->option[data].handle, args, 1);
1366 void SettingsCallback(w, client_data, call_data)
1368 XtPointer client_data, call_data;
1375 int data = (intptr_t) client_data;
1377 XtSetArg(args[0], XtNlabel, &name);
1378 XtGetValues(w, args, 1);
1380 if (strcmp(name, _("cancel")) == 0) {
1384 if (strcmp(name, _("OK")) == 0 || data) { // save buttons imply OK
1387 for(i=0; i<currentCps->nrOptions; i++) { // send all options that had to be OK-ed to engine
1388 switch(currentCps->option[i].type) {
1390 XtSetArg(args[0], XtNstring, &val);
1391 XtGetValues(currentCps->option[i].handle, args, 1);
1392 if(strcmp(currentCps->option[i].textValue, val)) {
1393 strcpy(currentCps->option[i].textValue, val);
1394 sprintf(buf, "option %s=%s\n", currentCps->option[i].name, val);
1395 SendToProgram(buf, currentCps);
1399 XtSetArg(args[0], XtNstring, &val);
1400 XtGetValues(currentCps->option[i].handle, args, 1);
1401 sscanf(val, "%d", &j);
1402 if(j > currentCps->option[i].max) j = currentCps->option[i].max;
1403 if(j < currentCps->option[i].min) j = currentCps->option[i].min;
1404 if(currentCps->option[i].value != j) {
1405 currentCps->option[i].value = j;
1406 sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1407 SendToProgram(buf, currentCps);
1412 XtSetArg(args[0], XtNstate, &j);
1413 XtGetValues(currentCps->option[i].handle, args, 1);
1414 if(currentCps->option[i].value != j) {
1415 currentCps->option[i].value = j;
1416 sprintf(buf, "option %s=%d\n", currentCps->option[i].name, j);
1417 SendToProgram(buf, currentCps);
1421 if(currentCps->option[i].value != values[i]) {
1422 currentCps->option[i].value = values[i];
1423 sprintf(buf, "option %s=%s\n", currentCps->option[i].name,
1424 ((char**)currentCps->option[i].textValue)[values[i]]);
1425 SendToProgram(buf, currentCps);
1430 if(data) { // send save-button command to engine
1431 sprintf(buf, "option %s\n", name);
1432 SendToProgram(buf, currentCps);
1437 sprintf(buf, "option %s\n", name);
1438 SendToProgram(buf, currentCps);
1441 void ComboSelect(w, addr, index) // callback for all combo items
1447 int i = ((intptr_t)addr)>>8;
1448 int j = 255 & (intptr_t) addr;
1450 values[i] = j; // store in temporary, for transfer at OK
1451 XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]);
1452 XtSetValues(currentCps->option[i].handle, args, 1);
1455 void CreateComboPopup(parent, name, n, mb)
1465 menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
1468 XtSetArg(args[j], XtNwidth, 100); j++;
1469 // XtSetArg(args[j], XtNright, XtChainRight); j++;
1470 while (mb[i] != NULL) {
1471 entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
1473 XtAddCallback(entry, XtNcallback,
1474 (XtCallbackProc) ComboSelect,
1475 (caddr_t)(intptr_t) (256*n+i));
1480 void SettingsPopUp(ChessProgramState *cps)
1483 Widget popup, layout, dialog, edit=NULL, form, oldform, last, b_ok, b_cancel, leftMargin = NULL;
1485 int x, y, i, j, height, width, h, c;
1486 int win_x, win_y, maxWidth, maxTextWidth;
1488 char def[80], *p, *q;
1489 static char pane[6] = "paneX";
1490 Widget texts[100], forelast = NULL, anchor, widest;
1492 // to do: start up second engine if needed
1493 if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
1496 if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1;
1497 height = cps->nrOptions / width + 1;
1499 XtSetArg(args[i], XtNresizable, True); i++;
1500 SettingsShell = popup =
1501 XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
1502 shellWidget, args, i);
1505 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1506 layoutArgs, XtNumber(layoutArgs));
1507 for(c=0; c<width; c++) {
1510 XtCreateManagedWidget(pane, formWidgetClass, layout,
1511 formArgs, XtNumber(formArgs));
1513 XtSetArg(args[j], XtNfromHoriz, leftMargin); j++;
1514 XtSetValues(form, args, j);
1517 last = widest = NULL; anchor = forelast;
1518 for(h=0; h<height; h++) {
1521 if(i >= cps->nrOptions) break;
1522 switch(cps->option[i].type) {
1524 sprintf(def, "%d", cps->option[i].value);
1527 XtSetArg(args[j], XtNfromVert, last); j++;
1528 XtSetArg(args[j], XtNborderWidth, 0); j++;
1529 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1531 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1533 XtSetArg(args[j], XtNfromVert, last); j++;
1534 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1535 XtSetArg(args[j], XtNborderWidth, 1); j++;
1536 XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 175); j++;
1537 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1538 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1539 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1540 XtSetArg(args[j], XtNright, XtChainRight); j++;
1541 XtSetArg(args[j], XtNresizable, True); j++;
1542 XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue); j++;
1544 cps->option[i].handle = (void*)
1545 (last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1546 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1547 if(cps->option[i].type == TextBox) break;
1549 // add increment and decrement controls for spin
1551 XtSetArg(args[j], XtNfromVert, edit); j++;
1552 XtSetArg(args[j], XtNfromHoriz, last); j++;
1553 XtSetArg(args[j], XtNheight, 10); j++;
1554 XtSetArg(args[j], XtNwidth, 20); j++;
1555 edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j);
1556 XtAddCallback(edit, XtNcallback, SpinCallback,
1557 (XtPointer)(intptr_t) i);
1560 XtSetArg(args[j], XtNfromVert, edit); j++;
1561 XtSetArg(args[j], XtNfromHoriz, last); j++;
1562 XtSetArg(args[j], XtNheight, 10); j++;
1563 XtSetArg(args[j], XtNwidth, 20); j++;
1564 last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1565 XtAddCallback(last, XtNcallback, SpinCallback,
1566 (XtPointer)(intptr_t) i);
1570 XtSetArg(args[j], XtNfromVert, last); j++;
1571 XtSetArg(args[j], XtNwidth, 10); j++;
1572 XtSetArg(args[j], XtNheight, 10); j++;
1573 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1574 cps->option[i].handle = (void*)
1575 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1577 XtSetArg(args[j], XtNfromVert, last); j++;
1578 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1579 XtSetArg(args[j], XtNborderWidth, 0); j++;
1580 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1581 last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1586 XtSetArg(args[j], XtNfromVert, last); j++;
1587 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1588 cps->option[i].handle = (void*)
1589 (dialog = last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));
1590 XtAddCallback(last, XtNcallback, SettingsCallback,
1591 (XtPointer)(intptr_t) (cps->option[i].type == SaveButton));
1595 XtSetArg(args[j], XtNfromVert, last); j++;
1596 XtSetArg(args[j], XtNborderWidth, 0); j++;
1597 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1598 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1601 XtSetArg(args[j], XtNfromVert, last); j++;
1602 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1603 XtSetArg(args[j], XtNwidth, 100); j++;
1604 XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name)); j++;
1605 XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]); j++;
1606 cps->option[i].handle = (void*)
1607 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1608 CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue);
1609 values[i] = cps->option[i].value;
1614 // make an attempt to align all spins and textbox controls
1615 maxWidth = maxTextWidth = 0;
1616 for(h=0; h<height; h++) {
1618 if(i >= cps->nrOptions) break;
1619 if(cps->option[i].type == Spin || cps->option[i].type == TextBox) {
1622 XtSetArg(args[j], XtNwidth, &w); j++;
1623 XtGetValues(texts[h], args, j);
1624 if(cps->option[i].type == Spin) {
1625 if(w > maxWidth) maxWidth = w;
1628 if(w > maxTextWidth) maxTextWidth = w;
1629 if(!widest) widest = texts[h];
1633 if(maxTextWidth + 110 < maxWidth)
1634 maxTextWidth = maxWidth - 110;
1635 else maxWidth = maxTextWidth + 110;
1636 for(h=0; h<height; h++) {
1638 if(i >= cps->nrOptions) break;
1640 if(cps->option[i].type == Spin) {
1641 XtSetArg(args[j], XtNwidth, maxWidth); j++;
1642 XtSetValues(texts[h], args, j);
1644 if(cps->option[i].type == TextBox) {
1645 XtSetArg(args[j], XtNwidth, maxTextWidth); j++;
1646 XtSetValues(texts[h], args, j);
1651 XtSetArg(args[j], XtNfromVert, anchor ? anchor : last); j++;
1652 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1653 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1654 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1655 XtSetArg(args[j], XtNright, XtChainRight); j++;
1656 XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog); j++;
1657 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1658 XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
1660 XtSetArg(args[j-1], XtNfromHoriz, b_ok);
1661 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1662 XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
1664 XtRealizeWidget(popup);
1665 CatchDeleteWindow(popup, "SettingsPopDown");
1667 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1668 &x, &y, &win_x, &win_y, &mask);
1670 XtSetArg(args[0], XtNx, x - 10);
1671 XtSetArg(args[1], XtNy, y - 30);
1672 XtSetValues(popup, args, 2);
1674 XtPopup(popup, XtGrabExclusive);
1678 if(edit)SetFocus(edit, popup, (XEvent*) NULL, False);
1681 void FirstSettingsProc(w, event, prms, nprms)
1687 SettingsPopUp(&first);
1690 void SecondSettingsProc(w, event, prms, nprms)
1696 SettingsPopUp(&second);
1699 //---------------------------- Chat Windows ----------------------------------------------
1701 void OutputChatMessage(int partner, char *mess)