2 * xoptions.c -- Move list window, part of X front end for XBoard
4 * Copyright 2000, 2009, 2010 Free Software Foundation, Inc.
5 * ------------------------------------------------------------------------
7 * GNU XBoard is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at
10 * your option) any later version.
12 * GNU XBoard is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see http://www.gnu.org/licenses/. *
20 *------------------------------------------------------------------------
21 ** See the file ChangeLog for a revision history. */
23 // [HGM] this file is the counterpart of woptions.c, containing xboard popup menus
24 // similar to those of WinBoard, to set the most common options interactively.
31 #include <sys/types.h>
36 #else /* not STDC_HEADERS */
37 extern char *getenv();
40 # else /* not HAVE_STRING_H */
42 # endif /* not HAVE_STRING_H */
43 #endif /* not STDC_HEADERS */
50 #include <X11/Intrinsic.h>
51 #include <X11/StringDefs.h>
52 #include <X11/Shell.h>
53 #include <X11/Xaw/Dialog.h>
54 #include <X11/Xaw/Form.h>
55 #include <X11/Xaw/List.h>
56 #include <X11/Xaw/Label.h>
57 #include <X11/Xaw/SimpleMenu.h>
58 #include <X11/Xaw/SmeBSB.h>
59 #include <X11/Xaw/SmeLine.h>
60 #include <X11/Xaw/Box.h>
61 #include <X11/Xaw/Paned.h>
62 #include <X11/Xaw/MenuButton.h>
63 #include <X11/cursorfont.h>
64 #include <X11/Xaw/Text.h>
65 #include <X11/Xaw/AsciiText.h>
66 #include <X11/Xaw/Viewport.h>
67 #include <X11/Xaw/Toggle.h>
75 # define _(s) gettext (s)
76 # define N_(s) gettext_noop (s)
82 extern void SendToProgram P((char *message, ChessProgramState *cps));
84 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
85 extern Display *xDisplay;
86 extern int squareSize;
87 extern Pixmap xMarkPixmap;
88 extern char *layoutName;
89 extern Window xBoardWindow;
90 extern Arg layoutArgs[2], formArgs[2];
91 Pixel timerForegroundPixel, timerBackgroundPixel;
92 extern int searchTime;
94 // [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines
96 static Widget previous = NULL;
98 void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
103 XtSetArg(args, XtNdisplayCaret, False);
104 XtSetValues(previous, &args, 1);
106 XtSetArg(args, XtNdisplayCaret, True);
107 XtSetValues(w, &args, 1);
108 XtSetKeyboardFocus((Widget) data, w);
112 //--------------------------- New Shuffle Game --------------------------------------------
113 extern int shuffleOpenings;
114 extern int startedFromPositionFile;
118 void ShufflePopDown()
120 if (!shuffleUp) return;
121 XtPopdown(shuffleShell);
122 XtDestroyWidget(shuffleShell);
127 void ShuffleCallback(w, client_data, call_data)
129 XtPointer client_data, call_data;
136 XtSetArg(args[0], XtNlabel, &name);
137 XtGetValues(w, args, 1);
139 if (strcmp(name, _("cancel")) == 0) {
143 if (strcmp(name, _("off")) == 0) {
145 shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it!
149 if (strcmp(name, _("random")) == 0) {
150 snprintf(buf, MSG_SIZ, "%d", rand());
151 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
152 XtSetValues(XtParent(w), args, 1);
155 if (strcmp(name, _("ok")) == 0) {
157 name = XawDialogGetValueString(w2 = XtParent(w));
158 if(sscanf(name ,"%d",&nr) != 1) {
159 snprintf(buf, MSG_SIZ, "%d", appData.defaultFrcPosition);
160 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
161 XtSetValues(w2, args, 1);
164 appData.defaultFrcPosition = nr;
165 shuffleOpenings = True;
175 Widget popup, layout, dialog, edit;
183 XtSetArg(args[i], XtNresizable, True); i++;
184 XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
185 shuffleShell = popup =
186 XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass,
187 shellWidget, args, i);
190 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
191 layoutArgs, XtNumber(layoutArgs));
193 snprintf(def, MSG_SIZ, "%d\n", appData.defaultFrcPosition);
195 XtSetArg(args[i], XtNlabel, _("Start-position number:")); i++;
196 XtSetArg(args[i], XtNvalue, def); i++;
197 XtSetArg(args[i], XtNborderWidth, 0); i++;
198 dialog = XtCreateManagedWidget(_("Shuffle"), dialogWidgetClass,
201 // XtSetArg(args[0], XtNeditType, XawtextEdit); // [HGM] can't get edit to work decently
202 // XtSetArg(args[1], XtNuseStringInPlace, False);
203 // XtSetValues(dialog, args, 2);
205 XawDialogAddButton(dialog, _("ok"), ShuffleCallback, (XtPointer) dialog);
206 XawDialogAddButton(dialog, _("cancel"), ShuffleCallback, (XtPointer) dialog);
207 XawDialogAddButton(dialog, _("random"), ShuffleCallback, (XtPointer) dialog);
208 XawDialogAddButton(dialog, _("off"), ShuffleCallback, (XtPointer) dialog);
210 XtRealizeWidget(popup);
211 CatchDeleteWindow(popup, "ShufflePopDown");
213 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
214 &x, &y, &win_x, &win_y, &mask);
216 XtSetArg(args[0], XtNx, x - 10);
217 XtSetArg(args[1], XtNy, y - 30);
218 XtSetValues(popup, args, 2);
220 XtPopup(popup, XtGrabExclusive);
223 edit = XtNameToWidget(dialog, "*value");
225 XtSetKeyboardFocus(popup, edit);
228 void ShuffleMenuProc(w, event, prms, nprms)
234 // if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
235 // Reset(FALSE, TRUE);
240 //--------------------------- Time-Control Menu Popup ----------------------------------
242 Widget TimeControlShell;
244 Widget tcMess1, tcMess2, tcData, tcTime, tcOdds1, tcOdds2;
245 int tcIncrement, tcMoves;
247 void TimeControlPopDown()
249 if (!TimeControlUp) return;
251 XtPopdown(TimeControlShell);
252 XtDestroyWidget(TimeControlShell);
253 TimeControlUp = False;
257 void TimeControlCallback(w, client_data, call_data)
259 XtPointer client_data, call_data;
266 XtSetArg(args[0], XtNlabel, &name);
267 XtGetValues(w, args, 1);
269 if (strcmp(name, _("classical")) == 0) {
270 if(tcInc == 0) return;
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);
279 XtSetArg(args[j], XtNstring, &name); j++;
280 XtGetValues(tcData, args, j);
281 tcIncrement = 0; sscanf(name, "%d", &tcIncrement);
283 snprintf(buf, MSG_SIZ, "%d", tcMoves);
285 XtSetArg(args[j], XtNstring, buf); j++;
286 XtSetValues(tcData, args, j);
290 if (strcmp(name, _("incremental")) == 0) {
291 if(tcInc == 1) return;
293 XtSetArg(args[j], XtNlabel, _("minutes, plus")); j++;
294 XtSetValues(tcMess1, args, j);
296 XtSetArg(args[j], XtNlabel, _("sec/move")); j++;
297 XtSetValues(tcMess2, args, j);
300 XtSetArg(args[j], XtNstring, &name); j++;
301 XtGetValues(tcData, args, j);
302 tcMoves = appData.movesPerSession; sscanf(name, "%d", &tcMoves);
304 snprintf(buf, MSG_SIZ, "%d", tcIncrement);
306 XtSetArg(args[j], XtNstring, buf); j++;
307 XtSetValues(tcData, args, j);
311 if (strcmp(name, _("fixed time")) == 0) {
312 if(tcInc == 2) return;
314 XtSetArg(args[j], XtNlabel, _("sec/move (max)")); j++;
315 XtSetValues(tcMess1, args, j);
317 XtSetArg(args[j], XtNlabel, _("")); j++;
318 XtSetValues(tcMess2, args, j);
320 XtSetArg(args[j], XtNstring, ""); j++;
321 XtSetValues(tcData, args, j);
325 if (strcmp(name, _(" OK ")) == 0) {
327 XtSetArg(args[0], XtNstring, &txt);
328 XtGetValues(tcData, args, 1);
331 ok = sscanf(txt, "%d", &inc); mps = 0;
332 if(!ok && txt[0] == 0) { inc = 0; ok = 1; } // accept empty string as zero
336 ok = sscanf(txt, "%d", &mps); inc = -1;
340 ok = 1; inc = -1; mps = 40;
343 XtSetArg(args[0], XtNstring, ""); // erase any offending input
344 XtSetValues(tcData, args, 1);
347 XtSetArg(args[0], XtNstring, &txt);
348 XtGetValues(tcTime, args, 1);
350 if(sscanf(txt, "%d", &inc) != 1) {
351 XtSetArg(args[0], XtNstring, ""); // erase any offending input
352 XtSetValues(tcTime, args, 1);
353 DisplayError(_("Bad Time-Control String"), 0);
358 if(!ParseTimeControl(txt, inc, mps)) {
359 XtSetArg(args[0], XtNstring, ""); // erase any offending input
360 XtSetValues(tcTime, args, 1);
361 DisplayError(_("Bad Time-Control String"), 0);
365 appData.movesPerSession = mps;
366 appData.timeIncrement = inc;
367 appData.timeControl = strdup(txt);
369 XtSetArg(args[0], XtNstring, &txt);
370 XtGetValues(tcOdds1, args, 1);
371 appData.firstTimeOdds = first.timeOdds
372 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
373 XtGetValues(tcOdds2, args, 1);
374 appData.secondTimeOdds = second.timeOdds
375 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
378 TimeControlPopDown();
383 void TimeControlPopUp()
386 Widget popup, layout, form, b_ok, b_cancel, b_clas, b_inc, mess;
393 tcInc = searchTime > 0 ? 2 : (appData.timeIncrement >= 0);
394 tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
395 if(!tcInc) tcIncrement = 0;
396 snprintf(def, MSG_SIZ, "%d", tcInc ? tcIncrement : tcMoves);
399 XtSetArg(args[i], XtNresizable, True); i++;
400 // XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
401 TimeControlShell = popup =
402 XtCreatePopupShell(_("TimeControl Menu"), transientShellWidgetClass,
403 shellWidget, args, i);
406 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
407 layoutArgs, XtNumber(layoutArgs));
410 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
411 formArgs, XtNumber(formArgs));
414 // XtSetArg(args[j], XtNwidth, (XtArgVal) 300); j++;
415 // XtSetArg(args[j], XtNheight, (XtArgVal) 85); j++;
416 XtSetValues(popup, args, j);
419 XtSetArg(args[j], XtNborderWidth, 1); j++;
420 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
421 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
422 XtSetArg(args[j], XtNstring, appData.timeControl); j++;
423 XtSetArg(args[j], XtNdisplayCaret, False); j++;
424 XtSetArg(args[j], XtNtop, XtChainTop); j++;
425 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
426 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
427 XtSetArg(args[j], XtNright, XtChainRight); j++;
428 XtSetArg(args[j], XtNresizable, True); j++;
429 XtSetArg(args[j], XtNwidth, 85); j++;
430 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
431 tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j);
432 XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup);
435 XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _("sec/move (max) ") : _(" minutes, plus ") : _("minutes for each")); j++;
436 XtSetArg(args[j], XtNborderWidth, 0); j++;
437 XtSetArg(args[j], XtNfromHoriz, tcTime); j++;
438 XtSetArg(args[j], XtNtop, XtChainTop); j++;
439 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
440 XtSetArg(args[j], XtNleft, XtChainRight); j++;
441 XtSetArg(args[j], XtNright, XtChainRight); j++;
442 // XtSetArg(args[j], XtNwidth, 100); j++;
443 // XtSetArg(args[j], XtNheight, 20); j++;
444 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
447 XtSetArg(args[j], XtNborderWidth, 1); j++;
448 XtSetArg(args[j], XtNfromHoriz, tcMess1); j++;
449 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
450 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
451 XtSetArg(args[j], XtNstring, def); j++;
452 XtSetArg(args[j], XtNdisplayCaret, False); j++;
453 XtSetArg(args[j], XtNtop, XtChainTop); j++;
454 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
455 XtSetArg(args[j], XtNleft, XtChainRight); j++;
456 XtSetArg(args[j], XtNright, XtChainRight); j++;
457 XtSetArg(args[j], XtNresizable, True); j++;
458 XtSetArg(args[j], XtNwidth, 40); j++;
459 // XtSetArg(args[j], XtNheight, 20); j++;
460 tcData = XtCreateManagedWidget("MPS", asciiTextWidgetClass, form, args, j);
461 XtAddEventHandler(tcData, ButtonPressMask, False, SetFocus, (XtPointer) popup);
464 XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _(" ") : _("sec/move") : _("moves ")); j++;
465 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
466 XtSetArg(args[j], XtNborderWidth, 0); j++;
467 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
468 XtSetArg(args[j], XtNtop, XtChainTop); j++;
469 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
470 XtSetArg(args[j], XtNleft, XtChainRight); j++;
471 XtSetArg(args[j], XtNright, XtChainRight); j++;
472 // XtSetArg(args[j], XtNwidth, 80); j++;
473 // XtSetArg(args[j], XtNheight, 20); j++;
474 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass,
478 XtSetArg(args[j], XtNborderWidth, 1); j++;
479 XtSetArg(args[j], XtNfromVert, tcTime); j++;
480 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
481 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
482 XtSetArg(args[j], XtNstring, "1"); j++;
483 XtSetArg(args[j], XtNdisplayCaret, False); 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, XtChainLeft); j++;
488 XtSetArg(args[j], XtNresizable, True); j++;
489 XtSetArg(args[j], XtNwidth, 40); j++;
490 // XtSetArg(args[j], XtNheight, 20); j++;
491 tcOdds1 = XtCreateManagedWidget("Odds1", asciiTextWidgetClass, form, args, j);
492 XtAddEventHandler(tcOdds1, ButtonPressMask, False, SetFocus, (XtPointer) popup);
495 XtSetArg(args[j], XtNborderWidth, 1); j++;
496 XtSetArg(args[j], XtNfromVert, tcTime); j++;
497 XtSetArg(args[j], XtNfromHoriz, tcOdds1); j++;
498 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
499 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
500 XtSetArg(args[j], XtNstring, "1"); j++;
501 XtSetArg(args[j], XtNdisplayCaret, False); j++;
502 XtSetArg(args[j], XtNtop, XtChainTop); j++;
503 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
504 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
505 XtSetArg(args[j], XtNright, XtChainLeft); j++;
506 XtSetArg(args[j], XtNresizable, True); j++;
507 XtSetArg(args[j], XtNwidth, 40); j++;
508 // XtSetArg(args[j], XtNheight, 20); j++;
509 tcOdds2 = XtCreateManagedWidget("Odds2", asciiTextWidgetClass, form, args, j);
510 XtAddEventHandler(tcOdds2, ButtonPressMask, False, SetFocus, (XtPointer) popup);
513 XtSetArg(args[j], XtNlabel, _("Engine #1 and #2 Time-Odds Factors")); j++;
514 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
515 XtSetArg(args[j], XtNborderWidth, 0); j++;
516 XtSetArg(args[j], XtNfromVert, tcTime); j++;
517 XtSetArg(args[j], XtNfromHoriz, tcOdds2); j++;
518 XtSetArg(args[j], XtNtop, XtChainTop); j++;
519 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
520 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
521 XtSetArg(args[j], XtNright, XtChainRight); j++;
522 // XtSetArg(args[j], XtNwidth, 200); j++;
523 // XtSetArg(args[j], XtNheight, 20); j++;
524 mess = XtCreateManagedWidget("Oddstext", labelWidgetClass,
527 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
528 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
529 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
530 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
531 XtSetArg(args[j], XtNright, XtChainLeft); j++;
532 XtSetArg(args[j], XtNstate, tcInc==0); j++;
533 b_clas= XtCreateManagedWidget(_("classical"), toggleWidgetClass,
535 XtAddCallback(b_clas, XtNcallback, TimeControlCallback, (XtPointer) 0);
538 XtSetArg(args[j], XtNradioGroup, b_clas); j++;
539 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
540 XtSetArg(args[j], XtNfromHoriz, b_clas); j++;
541 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
542 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
543 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
544 XtSetArg(args[j], XtNright, XtChainLeft); j++;
545 XtSetArg(args[j], XtNstate, tcInc==1); j++;
546 b_inc = XtCreateManagedWidget(_("incremental"), toggleWidgetClass,
548 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
551 XtSetArg(args[j], XtNradioGroup, b_inc); j++;
552 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
553 XtSetArg(args[j], XtNfromHoriz, b_inc); j++;
554 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
555 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
556 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
557 XtSetArg(args[j], XtNright, XtChainLeft); j++;
558 XtSetArg(args[j], XtNstate, tcInc==2); j++;
559 b_inc = XtCreateManagedWidget(_("fixed time"), toggleWidgetClass,
561 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
564 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
565 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
566 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
567 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
568 XtSetArg(args[j], XtNleft, XtChainRight); j++;
569 XtSetArg(args[j], XtNright, XtChainRight); j++;
570 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass,
572 XtAddCallback(b_ok, XtNcallback, TimeControlCallback, (XtPointer) 0);
575 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
576 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
577 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
578 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
579 XtSetArg(args[j], XtNleft, XtChainRight); j++;
580 XtSetArg(args[j], XtNright, XtChainRight); j++;
581 b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
583 XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0);
585 XtRealizeWidget(popup);
586 CatchDeleteWindow(popup, "TimeControlPopDown");
588 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
589 &x, &y, &win_x, &win_y, &mask);
591 XtSetArg(args[0], XtNx, x - 10);
592 XtSetArg(args[1], XtNy, y - 30);
593 XtSetValues(popup, args, 2);
595 XtPopup(popup, XtGrabExclusive);
596 TimeControlUp = True;
599 SetFocus(tcTime, popup, (XEvent*) NULL, False);
600 // XtSetKeyboardFocus(popup, tcTime);
603 void TimeControlProc(w, event, prms, nprms)
612 //--------------------------- Engine-Options Menu Popup ----------------------------------
615 extern int adjudicateLossThreshold;
617 Widget engDrawMoves, engThreshold, engRule, engRepeat;
621 if (!EngineUp) return;
623 XtPopdown(EngineShell);
624 XtDestroyWidget(EngineShell);
629 int ReadToggle(Widget w)
631 Arg args; Boolean res;
633 XtSetArg(args, XtNstate, &res);
634 XtGetValues(w, &args, 1);
639 Widget w1, w2, w3, w4, w5, w6, w7, w8;
641 void EngineCallback(w, client_data, call_data)
643 XtPointer client_data, call_data;
649 XtSetArg(args[0], XtNlabel, &name);
650 XtGetValues(w, args, 1);
652 if (strcmp(name, _("OK")) == 0) {
654 appData.periodicUpdates = ReadToggle(w1);
655 // appData.hideThinkingFromHuman = ReadToggle(w2);
656 first.scoreIsAbsolute = appData.firstScoreIsAbsolute = ReadToggle(w3);
657 second.scoreIsAbsolute = appData.secondScoreIsAbsolute = ReadToggle(w4);
658 appData.testClaims = ReadToggle(w5);
659 appData.checkMates = ReadToggle(w6);
660 appData.materialDraws = ReadToggle(w7);
661 appData.trivialDraws = ReadToggle(w8);
663 // adjust setting in other menu for duplicates
664 // (perhaps duplicates should be removed from general Option Menu?)
665 // XtSetArg(args[0], XtNleftBitmap, appData.showThinking ? xMarkPixmap : None);
666 // XtSetValues(XtNameToWidget(menuBarWidget,
667 // "menuOptions.Show Thinking"), args, 1);
669 // read out numeric controls, simply ignore bad formats for now
670 XtSetArg(args[0], XtNstring, &name);
671 XtGetValues(engDrawMoves, args, 1);
672 if(sscanf(name, "%d", &j) == 1) appData.adjudicateDrawMoves = j;
673 XtGetValues(engThreshold, args, 1);
674 if(sscanf(name, "%d", &j) == 1)
675 adjudicateLossThreshold = appData.adjudicateLossThreshold = -j; // inverted!
676 XtGetValues(engRule, args, 1);
677 if(sscanf(name, "%d", &j) == 1) appData.ruleMoves = j;
678 XtGetValues(engRepeat, args, 1);
679 if(sscanf(name, "%d", &j) == 1) appData.drawRepeats = j;
682 ShowThinkingEvent(); // [HGM] thinking: score adjudication might need thinking output
690 Widget popup, layout, form, b_ok, b_cancel, s1;
692 int x, y, i, j, width;
697 tcInc = (appData.timeIncrement >= 0);
698 tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
699 if(!tcInc) tcIncrement = 0;
700 snprintf(def, MSG_SIZ, "%d", tcInc ? tcIncrement : tcMoves);
703 XtSetArg(args[i], XtNresizable, True); i++;
704 // XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
705 EngineShell = popup =
706 XtCreatePopupShell(_("Adjudications"), transientShellWidgetClass,
707 shellWidget, args, i);
710 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
711 layoutArgs, XtNumber(layoutArgs));
714 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
715 formArgs, XtNumber(formArgs));
718 // XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++;
719 // XtSetArg(args[j], XtNheight, (XtArgVal) 400); j++;
720 // XtSetValues(popup, args, j);
723 // XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++;
724 // XtSetArg(args[j], XtNheight, (XtArgVal) 20); j++;
725 XtSetArg(args[j], XtNleft, (XtArgVal) XtChainLeft); j++;
726 XtSetArg(args[j], XtNright, (XtArgVal) XtChainRight); j++;
727 XtSetArg(args[j], XtNstate, appData.periodicUpdates); j++;
728 // XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
729 w1 = XtCreateManagedWidget(_("Periodic Updates (Analysis Mode)"), toggleWidgetClass, form, args, j);
731 XtSetArg(args[j], XtNwidth, (XtArgVal) &width);
732 XtGetValues(w1, &args[j], 1);
734 // XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w1);
735 // XtSetArg(args[j-3], XtNstate, appData.hideThinkingFromHuman);
736 // w2 = XtCreateManagedWidget(_("Hide Thinking from Human"), toggleWidgetClass, form, args, j);
738 XtSetArg(args[j], XtNwidth, (XtArgVal) width); j++;
739 XtSetArg(args[j-2], XtNstate, appData.firstScoreIsAbsolute);
740 XtSetArg(args[j], XtNfromVert, (XtArgVal) w1); j++;
741 w3 = XtCreateManagedWidget(_("Engine #1 Score is Absolute"), toggleWidgetClass, form, args, j);
743 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w3);
744 XtSetArg(args[j-3], XtNstate, appData.secondScoreIsAbsolute);
745 w4 = XtCreateManagedWidget(_("Engine #2 Score is Absolute"), toggleWidgetClass, form, args, j);
747 s1 = XtCreateManagedWidget(_("\nAdjudications in non-ICS games:"), labelWidgetClass, form, args, 3);
749 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) s1);
750 XtSetArg(args[j-3], XtNstate, appData.testClaims);
751 w5 = XtCreateManagedWidget(_("Verify Engine Result Claims"), toggleWidgetClass, form, args, j);
753 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w5);
754 XtSetArg(args[j-3], XtNstate, appData.checkMates);
755 w6 = XtCreateManagedWidget(_("Detect All Mates"), toggleWidgetClass, form, args, j);
757 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w6);
758 XtSetArg(args[j-3], XtNstate, appData.materialDraws);
759 w7 = XtCreateManagedWidget(_("Draw when Insuff. Mating Material"), toggleWidgetClass, form, args, j);
761 XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w7);
762 XtSetArg(args[j-3], XtNstate, appData.trivialDraws);
763 w8 = XtCreateManagedWidget(_("Adjudicate Trivial Draws"), toggleWidgetClass, form, args, j);
765 XtSetArg(args[0], XtNfromVert, (XtArgVal) w4);
766 XtSetArg(args[1], XtNborderWidth, (XtArgVal) 0);
767 XtSetValues(s1, args, 2);
769 snprintf(def, MSG_SIZ, "%d", appData.adjudicateDrawMoves);
771 XtSetArg(args[j], XtNborderWidth, 1); j++;
772 XtSetArg(args[j], XtNfromVert, w8); j++;
773 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
774 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
775 XtSetArg(args[j], XtNstring, def); j++;
776 XtSetArg(args[j], XtNdisplayCaret, False); 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], XtNresizable, True); j++;
782 XtSetArg(args[j], XtNwidth, 60); j++;
783 // XtSetArg(args[j], XtNheight, 20); j++;
784 engDrawMoves = XtCreateManagedWidget("Length", asciiTextWidgetClass, form, args, j);
785 XtAddEventHandler(engDrawMoves, ButtonPressMask, False, SetFocus, (XtPointer) popup);
788 XtSetArg(args[j], XtNlabel, _(" moves maximum, then draw")); j++;
789 XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
790 XtSetArg(args[j], XtNborderWidth, 0); j++;
791 XtSetArg(args[j], XtNfromVert, w8); j++;
792 XtSetArg(args[j], XtNfromHoriz, engDrawMoves); 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], XtNwidth, 170); j++;
798 // XtSetArg(args[j], XtNheight, 20); j++;
799 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
801 snprintf(def, MSG_SIZ, "%d", -appData.adjudicateLossThreshold); // inverted!
803 XtSetArg(args[j], XtNborderWidth, 1); j++;
804 XtSetArg(args[j], XtNfromVert, engDrawMoves); j++;
805 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
806 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
807 XtSetArg(args[j], XtNstring, def); j++;
808 XtSetArg(args[j], XtNdisplayCaret, False); 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], XtNresizable, True); j++;
814 XtSetArg(args[j], XtNwidth, 60); j++;
815 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
816 engThreshold = XtCreateManagedWidget("Threshold", asciiTextWidgetClass, form, args, j);
817 XtAddEventHandler(engThreshold, ButtonPressMask, False, SetFocus, (XtPointer) popup);
820 XtSetArg(args[j], XtNlabel, _("-centiPawn lead is win")); j++;
821 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
822 XtSetArg(args[j], XtNborderWidth, 0); j++;
823 XtSetArg(args[j], XtNfromVert, engDrawMoves); j++;
824 XtSetArg(args[j], XtNfromHoriz, engThreshold); 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], XtNwidth, 150); j++;
830 // XtSetArg(args[j], XtNheight, 20); j++;
831 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j);
833 snprintf(def, MSG_SIZ, "%d", appData.ruleMoves);
835 XtSetArg(args[j], XtNborderWidth, 1); j++;
836 XtSetArg(args[j], XtNfromVert, engThreshold); j++;
837 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
838 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
839 XtSetArg(args[j], XtNstring, def); j++;
840 XtSetArg(args[j], XtNdisplayCaret, False); 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], XtNresizable, True); j++;
846 XtSetArg(args[j], XtNwidth, 30); j++;
847 // XtSetArg(args[j], XtNheight, 20); j++;
848 engRule = XtCreateManagedWidget("Rule", asciiTextWidgetClass, form, args, j);
849 XtAddEventHandler(engRule, ButtonPressMask, False, SetFocus, (XtPointer) popup);
852 XtSetArg(args[j], XtNlabel, _("-move rule applied")); j++;
853 XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++;
854 XtSetArg(args[j], XtNborderWidth, 0); j++;
855 XtSetArg(args[j], XtNfromVert, engThreshold); j++;
856 XtSetArg(args[j], XtNfromHoriz, engRule); j++;
857 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
858 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
859 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
860 XtSetArg(args[j], XtNright, XtChainLeft); j++;
861 // XtSetArg(args[j], XtNwidth, 130); j++;
862 // XtSetArg(args[j], XtNheight, 20); j++;
863 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
865 snprintf(def, MSG_SIZ, "%d", appData.drawRepeats);
867 XtSetArg(args[j], XtNborderWidth, 1); j++;
868 XtSetArg(args[j], XtNfromVert, engRule); j++;
869 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
870 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
871 XtSetArg(args[j], XtNstring, def); j++;
872 XtSetArg(args[j], XtNdisplayCaret, False); j++;
873 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
874 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
875 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
876 XtSetArg(args[j], XtNright, XtChainLeft); j++;
877 XtSetArg(args[j], XtNresizable, True); j++;
878 XtSetArg(args[j], XtNwidth, 30); j++;
879 // XtSetArg(args[j], XtNheight, 20); j++;
880 engRepeat = XtCreateManagedWidget("Repeats", asciiTextWidgetClass, form, args, j);
881 XtAddEventHandler(engRepeat, ButtonPressMask, False, SetFocus, (XtPointer) popup);
884 XtSetArg(args[j], XtNlabel, _("-fold repeat is draw")); j++;
885 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
886 XtSetArg(args[j], XtNborderWidth, 0); j++;
887 XtSetArg(args[j], XtNfromVert, engRule); j++;
888 XtSetArg(args[j], XtNfromHoriz, engRepeat); j++;
889 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
890 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
891 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
892 XtSetArg(args[j], XtNright, XtChainLeft); j++;
893 // XtSetArg(args[j], XtNwidth, 130); j++;
894 // XtSetArg(args[j], XtNheight, 20); j++;
895 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j);
898 XtSetArg(args[j], XtNfromVert, engRepeat); j++;
899 XtSetArg(args[j], XtNfromHoriz, tcMess2); j++;
900 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
901 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
902 XtSetArg(args[j], XtNleft, XtChainRight); j++;
903 XtSetArg(args[j], XtNright, XtChainRight); j++;
904 b_ok= XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
905 XtAddCallback(b_ok, XtNcallback, EngineCallback, (XtPointer) 0);
908 XtSetArg(args[j], XtNfromVert, engRepeat); j++;
909 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
910 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
911 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
912 XtSetArg(args[j], XtNleft, XtChainRight); j++;
913 XtSetArg(args[j], XtNright, XtChainRight); j++;
914 b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
916 XtAddCallback(b_cancel, XtNcallback, EnginePopDown, (XtPointer) 0);
918 XtRealizeWidget(popup);
919 CatchDeleteWindow(popup, "EnginePopDown");
921 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
922 &x, &y, &win_x, &win_y, &mask);
924 XtSetArg(args[0], XtNx, x - 10);
925 XtSetArg(args[1], XtNy, y - 30);
926 XtSetValues(popup, args, 2);
928 XtPopup(popup, XtGrabExclusive);
932 SetFocus(engThreshold, popup, (XEvent*) NULL, False);
935 void EngineMenuProc(w, event, prms, nprms)
944 //--------------------------- New-Variant Menu PopUp -----------------------------------
945 struct NewVarButton {
949 VariantClass variant;
952 struct NewVarButton buttonDesc[] = {
953 {N_("normal"), "#FFFFFF", 0, VariantNormal},
954 {N_("FRC"), "#FFFFFF", 0, VariantFischeRandom},
955 {N_("wild castle"), "#FFFFFF", 0, VariantWildCastle},
956 {N_("no castle"), "#FFFFFF", 0, VariantNoCastle},
957 {N_("knightmate"), "#FFFFFF", 0, VariantKnightmate},
958 {N_("berolina"), "#FFFFFF", 0, VariantBerolina},
959 {N_("cylinder"), "#FFFFFF", 0, VariantCylinder},
960 {N_("shatranj"), "#FFFFFF", 0, VariantShatranj},
961 {N_("makruk"), "#FFFFFF", 0, VariantMakruk},
962 {N_("atomic"), "#FFFFFF", 0, VariantAtomic},
963 {N_("two kings"), "#FFFFFF", 0, VariantTwoKings},
964 {N_("3-checks"), "#FFFFFF", 0, Variant3Check},
965 {N_("suicide"), "#FFFFBF", 0, VariantSuicide},
966 {N_("give-away"), "#FFFFBF", 0, VariantGiveaway},
967 {N_("losers"), "#FFFFBF", 0, VariantLosers},
968 {N_("fairy"), "#BFBFBF", 0, VariantFairy},
969 {N_("Superchess"), "#FFBFBF", 0, VariantSuper},
970 {N_("crazyhouse"), "#FFBFBF", 0, VariantCrazyhouse},
971 {N_("bughouse"), "#FFBFBF", 0, VariantBughouse},
972 {N_("shogi (9x9)"), "#BFFFFF", 0, VariantShogi},
973 {N_("xiangqi (9x10)"), "#BFFFFF", 0, VariantXiangqi},
974 {N_("courier (12x8)"), "#BFFFBF", 0, VariantCourier},
975 {N_("janus (10x8)"), "#BFBFFF", 0, VariantJanus},
976 {N_("Capablanca (10x8)"), "#BFBFFF", 0, VariantCapablanca},
977 {N_("CRC (10x8)"), "#BFBFFF", 0, VariantCapaRandom},
979 {N_("Gothic (10x8)"), "#BFBFFF", 0, VariantGothic},
982 {N_("Falcon (10x8)"), "#BFBFFF", 0, VariantFalcon},
984 {NULL, 0, 0, (VariantClass) 0}
988 Widget NewVariantShell;
990 void NewVariantPopDown()
992 if (!NewVariantUp) return;
993 XtPopdown(NewVariantShell);
994 XtDestroyWidget(NewVariantShell);
995 NewVariantUp = False;
999 void NewVariantCallback(w, client_data, call_data)
1001 XtPointer client_data, call_data;
1007 XtSetArg(args[0], XtNlabel, &name);
1008 XtGetValues(w, args, 1);
1010 if (strcmp(name, _(" OK ")) == 0) {
1011 int nr = (intptr_t) XawToggleGetCurrent(buttonDesc[0].handle) - 1;
1013 v = buttonDesc[nr].variant;
1014 if(!appData.noChessProgram) {
1015 char *name = VariantName(v), buf[MSG_SIZ];
1016 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
1017 /* [HGM] in protocol 2 we check if variant is suported by engine */
1018 snprintf(buf, MSG_SIZ, _("Variant %s not supported by %s"), name, first.tidy);
1019 DisplayError(buf, 0);
1020 // NewVariantPopDown();
1021 return; /* ignore OK if first engine does not support it */
1023 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
1024 snprintf(buf, MSG_SIZ, _("Warning: second engine (%s) does not support this!"), second.tidy);
1025 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
1029 gameInfo.variant = v;
1030 appData.variant = VariantName(v);
1032 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
1033 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
1034 appData.pieceToCharTable = NULL;
1036 NewVariantPopDown();
1041 void NewVariantPopUp()
1044 Widget popup, layout, form, last = NULL, b_ok, b_cancel;
1049 XrmValue vFrom, vTo;
1052 XtSetArg(args[i], XtNresizable, True); i++;
1053 // XtSetArg(args[i], XtNwidth, 250); i++;
1054 // XtSetArg(args[i], XtNheight, 300); i++;
1055 NewVariantShell = popup =
1056 XtCreatePopupShell(_("NewVariant Menu"), transientShellWidgetClass,
1057 shellWidget, args, i);
1060 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1061 layoutArgs, XtNumber(layoutArgs));
1064 XtCreateManagedWidget("form", formWidgetClass, layout,
1065 formArgs, XtNumber(formArgs));
1067 for(i = 0; buttonDesc[i].name != NULL; i++) {
1069 if (!appData.monoMode) {
1070 vFrom.addr = (caddr_t) buttonDesc[i].color;
1071 vFrom.size = strlen(buttonDesc[i].color);
1072 XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1073 if (vTo.addr == NULL) {
1074 buttonColor = (Pixel) -1;
1076 buttonColor = *(Pixel *) vTo.addr;
1081 XtSetArg(args[j], XtNradioGroup, last); j++;
1082 XtSetArg(args[j], XtNwidth, 125); j++;
1083 // XtSetArg(args[j], XtNheight, 16); j++;
1084 XtSetArg(args[j], XtNfromVert, i == 15 ? NULL : last); j++;
1085 XtSetArg(args[j], XtNfromHoriz, i < 15 ? NULL : buttonDesc[i-15].handle); j++;
1086 XtSetArg(args[j], XtNradioData, i+1); j++;
1087 XtSetArg(args[j], XtNbackground, buttonColor); j++;
1088 XtSetArg(args[j], XtNstate, gameInfo.variant == buttonDesc[i].variant); j++;
1089 buttonDesc[i].handle = last =
1090 XtCreateManagedWidget(buttonDesc[i].name, toggleWidgetClass, form, args, j);
1094 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1095 XtSetArg(args[j], XtNfromHoriz, buttonDesc[12].handle); j++;
1096 XtSetArg(args[j], XtNheight, 35); j++;
1097 // XtSetArg(args[j], XtNwidth, 60); j++;
1098 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1099 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1100 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1101 XtSetArg(args[j], XtNright, XtChainRight); j++;
1102 b_cancel= XtCreateManagedWidget(_("CANCEL"), commandWidgetClass, form, args, j);
1103 XtAddCallback(b_cancel, XtNcallback, NewVariantPopDown, (XtPointer) 0);
1106 XtSetArg(args[j], XtNfromHoriz, b_cancel); j++;
1107 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1108 XtSetArg(args[j], XtNheight, 35); j++;
1109 // XtSetArg(args[j], XtNwidth, 60); j++;
1110 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1111 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1112 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1113 XtSetArg(args[j], XtNright, XtChainRight); j++;
1114 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass, form, args, j);
1115 XtAddCallback(b_ok, XtNcallback, NewVariantCallback, (XtPointer) 0);
1118 XtSetArg(args[j], XtNfromVert, buttonDesc[14].handle); j++;
1119 // XtSetArg(args[j], XtNheight, 70); j++;
1120 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1121 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1122 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1123 XtSetArg(args[j], XtNright, XtChainRight); j++;
1124 XtSetArg(args[j], XtNlabel, _("WARNING: variants with un-orthodox\n"
1125 "pieces only have built-in bitmaps\n"
1126 "for -boardSize middling, bulky and\n"
1127 "petite, and substitute king or amazon\n"
1128 "for missing bitmaps. (See manual.)")); j++;
1129 XtCreateManagedWidget("warning", labelWidgetClass, form, args, j);
1131 XtRealizeWidget(popup);
1132 CatchDeleteWindow(popup, "NewVariantPopDown");
1134 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1135 &x, &y, &win_x, &win_y, &mask);
1137 XtSetArg(args[0], XtNx, x - 10);
1138 XtSetArg(args[1], XtNy, y - 30);
1139 XtSetValues(popup, args, 2);
1141 XtPopup(popup, XtGrabExclusive);
1142 NewVariantUp = True;
1145 void NewVariantProc(w, event, prms, nprms)
1154 //--------------------------- UCI Menu Popup ------------------------------------------
1164 struct UciControl controlDesc[] = {
1165 {N_("maximum nr of CPUs:"), 0, &appData.smpCores},
1166 {N_("Polyglot Directory:"), 0, &appData.polyglotDir},
1167 {N_("Hash Size (MB):"), 0, &appData.defaultHashSize},
1168 {N_("EGTB Path:"), 0, &appData.defaultPathEGTB},
1169 {N_("EGTB Cache (MB):"), 0, &appData.defaultCacheSizeEGTB},
1170 {N_("Polyglot Book:"), 0, &appData.polyglotBook},
1178 XtPopdown(UciShell);
1179 XtDestroyWidget(UciShell);
1184 void UciCallback(w, client_data, call_data)
1186 XtPointer client_data, call_data;
1190 int oldCores = appData.smpCores, ponder = 0;
1192 XtSetArg(args[0], XtNlabel, &name);
1193 XtGetValues(w, args, 1);
1195 if (strcmp(name, _("OK")) == 0) {
1196 int i, j; String name;
1197 for(i=0; i<6; i++) {
1198 XtSetArg(args[0], XtNstring, &name);
1199 XtGetValues(controlDesc[i].handle, args, 1);
1202 *(char**) controlDesc[i].ptr = strdup(name);
1204 if(sscanf(name, "%d", &j) == 1)
1205 *(int*) controlDesc[i].ptr = j;
1208 XtSetArg(args[0], XtNstate, &appData.usePolyglotBook);
1209 XtGetValues(w1, args, 1);
1210 XtSetArg(args[0], XtNstate, &appData.firstHasOwnBookUCI);
1211 XtGetValues(w2, args, 1);
1212 XtSetArg(args[0], XtNstate, &appData.secondHasOwnBookUCI);
1213 XtGetValues(w3, args, 1);
1214 XtSetArg(args[0], XtNstate, &ponder);
1215 XtGetValues(w4, args, 1);
1217 // adjust setting in other menu for duplicates
1218 // (perhaps duplicates should be removed from general Option Menu?)
1219 XtSetArg(args[0], XtNleftBitmap, ponder ? xMarkPixmap : None);
1220 XtSetValues(XtNameToWidget(menuBarWidget,
1221 "menuOptions.Ponder Next Move"), args, 1);
1223 // make sure changes are sent to first engine by re-initializing it
1224 // if it was already started pre-emptively at end of previous game
1225 if(gameMode == BeginningOfGame) Reset(True, True); else {
1226 // Some changed setting need immediate sending always.
1227 PonderNextMoveEvent(ponder);
1228 if(oldCores != appData.smpCores)
1229 NewSettingEvent(False, &(first.maxCores), "cores", appData.smpCores);
1239 Widget popup, layout, form, b_ok, b_cancel, last = NULL, new, upperLeft;
1247 XtSetArg(args[i], XtNresizable, True); i++;
1248 // XtSetArg(args[i], XtNwidth, 300); i++;
1250 XtCreatePopupShell(_("Engine Settings"), transientShellWidgetClass,
1251 shellWidget, args, i);
1254 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1255 layoutArgs, XtNumber(layoutArgs));
1259 XtCreateManagedWidget("form", formWidgetClass, layout,
1260 formArgs, XtNumber(formArgs));
1263 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1264 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1265 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1266 // XtSetArg(args[j], XtNheight, 20); j++;
1267 for(i = 0; controlDesc[i].name != NULL; i++) {
1269 XtSetArg(args[j], XtNfromVert, last); j++;
1270 // XtSetArg(args[j], XtNwidth, 130); j++;
1271 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1272 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1273 XtSetArg(args[j], XtNborderWidth, 0); j++;
1274 new = XtCreateManagedWidget(controlDesc[i].name, labelWidgetClass, form, args, j);
1275 if(i==0) upperLeft = new;
1278 XtSetArg(args[j], XtNborderWidth, 1); j++;
1279 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1280 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1281 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1282 XtSetArg(args[j], XtNright, XtChainRight); j++;
1283 XtSetArg(args[j], XtNresizable, True); j++;
1284 XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++;
1285 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
1287 XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ?
1288 * (char**) controlDesc[i].ptr : ""); j++;
1290 snprintf(def, MSG_SIZ, "%d", * (int*) controlDesc[i].ptr);
1291 XtSetArg(args[j], XtNstring, def); j++;
1293 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1294 controlDesc[i].handle = last =
1295 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
1296 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1300 XtSetArg(args[j], XtNfromHoriz, controlDesc[0].handle); j++;
1301 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1302 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1303 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1304 XtSetArg(args[j], XtNright, XtChainRight); j++;
1305 XtSetArg(args[j], XtNstate, appData.ponderNextMove); j++;
1306 w4 = XtCreateManagedWidget(_("Ponder"), toggleWidgetClass, form, args, j);
1309 XtSetArg(args[j], XtNfromVert, last); j++;
1310 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1311 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1312 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1313 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1314 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1315 XtAddCallback(b_ok, XtNcallback, UciCallback, (XtPointer) 0);
1317 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
1318 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1319 XtAddCallback(b_cancel, XtNcallback, UciPopDown, (XtPointer) 0);
1322 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1323 XtSetArg(args[j], XtNstate, appData.usePolyglotBook); j++;
1324 w1 = XtCreateManagedWidget(_(" use book "), toggleWidgetClass, form, args, j);
1325 // XtAddCallback(w1, XtNcallback, UciCallback, (XtPointer) 0);
1328 XtSetArg(args[j], XtNfromHoriz, w1); j++;
1329 XtSetArg(args[j], XtNstate, appData.firstHasOwnBookUCI); j++;
1330 w2 = XtCreateManagedWidget(_("own book 1"), toggleWidgetClass, form, args, j);
1331 // XtAddCallback(w2, XtNcallback, UciCallback, (XtPointer) 0);
1334 XtSetArg(args[j], XtNfromHoriz, w2); j++;
1335 XtSetArg(args[j], XtNstate, appData.secondHasOwnBookUCI); j++;
1336 w3 = XtCreateManagedWidget(_("own book 2"), toggleWidgetClass, form, args, j);
1337 // XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0);
1339 XtRealizeWidget(popup);
1340 CatchDeleteWindow(popup, "UciPopDown");
1342 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1343 &x, &y, &win_x, &win_y, &mask);
1345 XtSetArg(args[0], XtNx, x - 10);
1346 XtSetArg(args[1], XtNy, y - 30);
1347 XtSetValues(popup, args, 2);
1349 XtPopup(popup, XtGrabExclusive);
1353 SetFocus(controlDesc[2].handle, popup, (XEvent*) NULL, False);
1354 // XtSetKeyboardFocus(popup, controlDesc[1].handle);
1357 void UciMenuProc(w, event, prms, nprms)
1366 //--------------------------- Engine-specific options menu ----------------------------------
1369 Widget SettingsShell;
1370 int values[MAX_OPTIONS];
1371 ChessProgramState *currentCps;
1373 void SettingsPopDown()
1375 if (!SettingsUp) return;
1377 XtPopdown(SettingsShell);
1378 XtDestroyWidget(SettingsShell);
1383 void SpinCallback(w, client_data, call_data)
1385 XtPointer client_data, call_data;
1391 int data = (intptr_t) client_data;
1393 XtSetArg(args[0], XtNlabel, &name);
1394 XtGetValues(w, args, 1);
1397 XtSetArg(args[0], XtNstring, &val);
1398 XtGetValues(currentCps->option[data].handle, args, 1);
1399 sscanf(val, "%d", &j);
1400 if (strcmp(name, "+") == 0) {
1401 if(++j > currentCps->option[data].max) return;
1403 if (strcmp(name, "-") == 0) {
1404 if(--j < currentCps->option[data].min) return;
1406 snprintf(buf, MSG_SIZ, "%d", j);
1407 XtSetArg(args[0], XtNstring, buf);
1408 XtSetValues(currentCps->option[data].handle, args, 1);
1411 void SettingsCallback(w, client_data, call_data)
1413 XtPointer client_data, call_data;
1419 int data = (intptr_t) client_data;
1421 XtSetArg(args[0], XtNlabel, &name);
1422 XtGetValues(w, args, 1);
1424 if (strcmp(name, _("cancel")) == 0) {
1428 if (strcmp(name, _("OK")) == 0 || data) { // save buttons imply OK
1429 for(i=0; i<currentCps->nrOptions; i++) { // send all options that had to be OK-ed to engine
1430 switch(currentCps->option[i].type) {
1432 XtSetArg(args[0], XtNstring, &val);
1433 XtGetValues(currentCps->option[i].handle, args, 1);
1434 if(strcmp(currentCps->option[i].textValue, val)) {
1435 safeStrCpy(currentCps->option[i].textValue, val, MSG_SIZ - (currentCps->option[i].textValue - currentCps->option[i].name) );
1436 snprintf(buf, MSG_SIZ, "option %s=%s\n", currentCps->option[i].name, val);
1437 SendToProgram(buf, currentCps);
1441 XtSetArg(args[0], XtNstring, &val);
1442 XtGetValues(currentCps->option[i].handle, args, 1);
1443 sscanf(val, "%d", &j);
1444 if(j > currentCps->option[i].max) j = currentCps->option[i].max;
1445 if(j < currentCps->option[i].min) j = currentCps->option[i].min;
1446 if(currentCps->option[i].value != j) {
1447 currentCps->option[i].value = j;
1448 snprintf(buf, MSG_SIZ, "option %s=%d\n", currentCps->option[i].name, j);
1449 SendToProgram(buf, currentCps);
1454 XtSetArg(args[0], XtNstate, &j);
1455 XtGetValues(currentCps->option[i].handle, args, 1);
1456 if(currentCps->option[i].value != j) {
1457 currentCps->option[i].value = j;
1458 snprintf(buf, MSG_SIZ, "option %s=%d\n", currentCps->option[i].name, j);
1459 SendToProgram(buf, currentCps);
1463 if(currentCps->option[i].value != values[i]) {
1464 currentCps->option[i].value = values[i];
1465 snprintf(buf, MSG_SIZ, "option %s=%s\n", currentCps->option[i].name,
1466 ((char**)currentCps->option[i].textValue)[values[i]]);
1467 SendToProgram(buf, currentCps);
1471 if( appData.debugMode )
1472 fprintf(debugFP, "SettingsPopUp: unexpected case in switch.\n");
1476 if(data) { // send save-button command to engine
1477 snprintf(buf, MSG_SIZ, "option %s\n", name);
1478 SendToProgram(buf, currentCps);
1483 snprintf(buf, MSG_SIZ, "option %s\n", name);
1484 SendToProgram(buf, currentCps);
1487 void ComboSelect(w, addr, index) // callback for all combo items
1493 int i = ((intptr_t)addr)>>8;
1494 int j = 255 & (intptr_t) addr;
1496 values[i] = j; // store in temporary, for transfer at OK
1497 XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]);
1498 XtSetValues(currentCps->option[i].handle, args, 1);
1501 void CreateComboPopup(parent, name, n, mb)
1511 menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
1514 XtSetArg(args[j], XtNwidth, 100); j++;
1515 // XtSetArg(args[j], XtNright, XtChainRight); j++;
1516 while (mb[i] != NULL) {
1517 entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
1519 XtAddCallback(entry, XtNcallback,
1520 (XtCallbackProc) ComboSelect,
1521 (caddr_t)(intptr_t) (256*n+i));
1527 SettingsPopUp(ChessProgramState *cps)
1530 Widget popup, layout, dialog, edit=NULL, form, last, b_ok, b_cancel, leftMargin = NULL, textField = NULL;
1532 int x, y, i, j, height, width, h, c;
1533 int win_x, win_y, maxWidth, maxTextWidth;
1536 static char pane[6] = "paneX";
1537 Widget texts[100], forelast = NULL, anchor, widest;
1539 // to do: start up second engine if needed
1540 if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
1543 if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1;
1544 height = cps->nrOptions / width + 1;
1546 XtSetArg(args[i], XtNresizable, True); i++;
1547 SettingsShell = popup =
1548 XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
1549 shellWidget, args, i);
1552 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1553 layoutArgs, XtNumber(layoutArgs));
1554 for(c=0; c<width; c++) {
1557 XtCreateManagedWidget(pane, formWidgetClass, layout,
1558 formArgs, XtNumber(formArgs));
1560 XtSetArg(args[j], XtNfromHoriz, leftMargin); j++;
1561 XtSetValues(form, args, j);
1564 last = widest = NULL; anchor = forelast;
1565 for(h=0; h<height; h++) {
1568 if(i >= cps->nrOptions) break;
1569 switch(cps->option[i].type) {
1571 snprintf(def, MSG_SIZ, "%d", cps->option[i].value);
1574 XtSetArg(args[j], XtNfromVert, last); j++;
1575 XtSetArg(args[j], XtNborderWidth, 0); j++;
1576 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1578 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1580 XtSetArg(args[j], XtNfromVert, last); j++;
1581 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1582 XtSetArg(args[j], XtNborderWidth, 1); j++;
1583 XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 175); j++;
1584 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1585 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1586 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1587 XtSetArg(args[j], XtNright, XtChainRight); j++;
1588 XtSetArg(args[j], XtNresizable, True); j++;
1589 XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue); j++;
1590 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
1592 cps->option[i].handle = (void*)
1593 (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1594 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1595 if(cps->option[i].type == TextBox) break;
1597 // add increment and decrement controls for spin
1599 XtSetArg(args[j], XtNfromVert, edit); j++;
1600 XtSetArg(args[j], XtNfromHoriz, last); j++;
1601 XtSetArg(args[j], XtNheight, 10); j++;
1602 XtSetArg(args[j], XtNwidth, 20); j++;
1603 edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j);
1604 XtAddCallback(edit, XtNcallback, SpinCallback,
1605 (XtPointer)(intptr_t) i);
1608 XtSetArg(args[j], XtNfromVert, edit); j++;
1609 XtSetArg(args[j], XtNfromHoriz, last); j++;
1610 XtSetArg(args[j], XtNheight, 10); j++;
1611 XtSetArg(args[j], XtNwidth, 20); j++;
1612 last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1613 XtAddCallback(last, XtNcallback, SpinCallback,
1614 (XtPointer)(intptr_t) i);
1618 XtSetArg(args[j], XtNfromVert, last); j++;
1619 XtSetArg(args[j], XtNwidth, 10); j++;
1620 XtSetArg(args[j], XtNheight, 10); j++;
1621 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1622 cps->option[i].handle = (void*)
1623 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1625 XtSetArg(args[j], XtNfromVert, last); j++;
1626 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1627 XtSetArg(args[j], XtNborderWidth, 0); j++;
1628 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1629 last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1634 XtSetArg(args[j], XtNfromVert, last); j++;
1635 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1636 cps->option[i].handle = (void*)
1637 (dialog = last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));
1638 XtAddCallback(last, XtNcallback, SettingsCallback,
1639 (XtPointer)(intptr_t) (cps->option[i].type == SaveButton));
1643 XtSetArg(args[j], XtNfromVert, last); j++;
1644 XtSetArg(args[j], XtNborderWidth, 0); j++;
1645 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1646 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1649 XtSetArg(args[j], XtNfromVert, last); j++;
1650 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1651 XtSetArg(args[j], XtNwidth, 100); j++;
1652 XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name)); j++;
1653 XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]); j++;
1654 cps->option[i].handle = (void*)
1655 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1656 CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue);
1657 values[i] = cps->option[i].value;
1660 if( appData.debugMode )
1661 fprintf(debugFP, "SettingsPopUp: unexpected case in switch.\n");
1666 // make an attempt to align all spins and textbox controls
1667 maxWidth = maxTextWidth = 0;
1668 for(h=0; h<height; h++) {
1670 if(i >= cps->nrOptions) break;
1671 if(cps->option[i].type == Spin || cps->option[i].type == TextBox) {
1674 XtSetArg(args[j], XtNwidth, &w); j++;
1675 XtGetValues(texts[h], args, j);
1676 if(cps->option[i].type == Spin) {
1677 if(w > maxWidth) maxWidth = w;
1680 if(w > maxTextWidth) maxTextWidth = w;
1681 if(!widest) widest = texts[h];
1685 if(maxTextWidth + 110 < maxWidth)
1686 maxTextWidth = maxWidth - 110;
1687 else maxWidth = maxTextWidth + 110;
1688 for(h=0; h<height; h++) {
1690 if(i >= cps->nrOptions) break;
1692 if(cps->option[i].type == Spin) {
1693 XtSetArg(args[j], XtNwidth, maxWidth); j++;
1694 XtSetValues(texts[h], args, j);
1696 if(cps->option[i].type == TextBox) {
1697 XtSetArg(args[j], XtNwidth, maxTextWidth); j++;
1698 XtSetValues(texts[h], args, j);
1703 XtSetArg(args[j], XtNfromVert, anchor ? anchor : last); j++;
1704 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1705 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1706 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1707 XtSetArg(args[j], XtNright, XtChainRight); j++;
1708 XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog); j++;
1709 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1710 XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
1712 XtSetArg(args[j-1], XtNfromHoriz, b_ok);
1713 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1714 XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
1716 XtRealizeWidget(popup);
1717 CatchDeleteWindow(popup, "SettingsPopDown");
1719 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1720 &x, &y, &win_x, &win_y, &mask);
1722 XtSetArg(args[0], XtNx, x - 10);
1723 XtSetArg(args[1], XtNy, y - 30);
1724 XtSetValues(popup, args, 2);
1726 XtPopup(popup, XtGrabExclusive);
1730 if(textField)SetFocus(textField, popup, (XEvent*) NULL, False);
1733 void FirstSettingsProc(w, event, prms, nprms)
1739 SettingsPopUp(&first);
1742 void SecondSettingsProc(w, event, prms, nprms)
1748 SettingsPopUp(&second);
1751 //---------------------------- Chat Windows ----------------------------------------------
1753 void OutputChatMessage(int partner, char *mess)