2 * xoptions.c -- Move list window, part of X front end for XBoard
4 * Copyright 2000, 2009, 2010, 2011 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_("Seirawan"), "#FFBFBF", 0, VariantSChess},
970 {N_("Superchess"), "#FFBFBF", 0, VariantSuper},
971 {N_("crazyhouse"), "#FFBFBF", 0, VariantCrazyhouse},
972 {N_("bughouse"), "#FFBFBF", 0, VariantBughouse},
973 {N_("shogi (9x9)"), "#BFFFFF", 0, VariantShogi},
974 {N_("xiangqi (9x10)"), "#BFFFFF", 0, VariantXiangqi},
975 {N_("courier (12x8)"), "#BFFFBF", 0, VariantCourier},
976 {N_("Capablanca (10x8)"), "#BFBFFF", 0, VariantCapablanca},
978 {N_("Gothic (10x8)"), "#BFBFFF", 0, VariantGothic},
980 {N_("janus (10x8)"), "#BFBFFF", 0, VariantJanus},
981 {N_("CRC (10x8)"), "#BFBFFF", 0, VariantCapaRandom},
983 {N_("Falcon (10x8)"), "#BFBFFF", 0, VariantFalcon},
985 {N_("Spartan"), "#FF0000", 0, VariantSpartan},
986 {NULL, 0, 0, (VariantClass) 0}
990 Widget NewVariantShell;
992 void NewVariantPopDown()
994 if (!NewVariantUp) return;
995 XtPopdown(NewVariantShell);
996 XtDestroyWidget(NewVariantShell);
997 NewVariantUp = False;
1001 void NewVariantCallback(w, client_data, call_data)
1003 XtPointer client_data, call_data;
1009 XtSetArg(args[0], XtNlabel, &name);
1010 XtGetValues(w, args, 1);
1012 if (strcmp(name, _(" OK ")) == 0) {
1013 int nr = (intptr_t) XawToggleGetCurrent(buttonDesc[0].handle) - 1;
1015 v = buttonDesc[nr].variant;
1016 if(!appData.noChessProgram) {
1017 char *name = VariantName(v), buf[MSG_SIZ];
1018 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
1019 /* [HGM] in protocol 2 we check if variant is suported by engine */
1020 snprintf(buf, MSG_SIZ, _("Variant %s not supported by %s"), name, first.tidy);
1021 DisplayError(buf, 0);
1022 // NewVariantPopDown();
1023 return; /* ignore OK if first engine does not support it */
1025 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
1026 snprintf(buf, MSG_SIZ, _("Warning: second engine (%s) does not support this!"), second.tidy);
1027 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
1031 gameInfo.variant = v;
1032 appData.variant = VariantName(v);
1034 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
1035 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
1036 appData.pieceToCharTable = NULL;
1038 NewVariantPopDown();
1043 void NewVariantPopUp()
1046 Widget popup, layout, form, last = NULL, b_ok, b_cancel;
1051 XrmValue vFrom, vTo;
1054 XtSetArg(args[i], XtNresizable, True); i++;
1055 // XtSetArg(args[i], XtNwidth, 250); i++;
1056 // XtSetArg(args[i], XtNheight, 300); i++;
1057 NewVariantShell = popup =
1058 XtCreatePopupShell(_("NewVariant Menu"), transientShellWidgetClass,
1059 shellWidget, args, i);
1062 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1063 layoutArgs, XtNumber(layoutArgs));
1066 XtCreateManagedWidget("form", formWidgetClass, layout,
1067 formArgs, XtNumber(formArgs));
1069 for(i = 0; buttonDesc[i].name != NULL; i++) {
1071 if (!appData.monoMode) {
1072 vFrom.addr = (caddr_t) buttonDesc[i].color;
1073 vFrom.size = strlen(buttonDesc[i].color);
1074 XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1075 if (vTo.addr == NULL) {
1076 buttonColor = (Pixel) -1;
1078 buttonColor = *(Pixel *) vTo.addr;
1083 XtSetArg(args[j], XtNradioGroup, last); j++;
1084 XtSetArg(args[j], XtNwidth, 125); j++;
1085 // XtSetArg(args[j], XtNheight, 16); j++;
1086 XtSetArg(args[j], XtNfromVert, i == 15 ? NULL : last); j++;
1087 XtSetArg(args[j], XtNfromHoriz, i < 15 ? NULL : buttonDesc[i-15].handle); j++;
1088 XtSetArg(args[j], XtNradioData, i+1); j++;
1089 XtSetArg(args[j], XtNbackground, buttonColor); j++;
1090 XtSetArg(args[j], XtNstate, gameInfo.variant == buttonDesc[i].variant); j++;
1091 XtSetArg(args[j], XtNsensitive, appData.noChessProgram || strstr(first.variants, VariantName(buttonDesc[i].variant))); j++;
1092 buttonDesc[i].handle = last =
1093 XtCreateManagedWidget(buttonDesc[i].name, toggleWidgetClass, form, args, j);
1097 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1098 XtSetArg(args[j], XtNfromHoriz, buttonDesc[12].handle); j++;
1099 XtSetArg(args[j], XtNheight, 35); j++;
1100 // XtSetArg(args[j], XtNwidth, 60); j++;
1101 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1102 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1103 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1104 XtSetArg(args[j], XtNright, XtChainRight); j++;
1105 b_cancel= XtCreateManagedWidget(_("CANCEL"), commandWidgetClass, form, args, j);
1106 XtAddCallback(b_cancel, XtNcallback, NewVariantPopDown, (XtPointer) 0);
1109 XtSetArg(args[j], XtNfromHoriz, b_cancel); j++;
1110 XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++;
1111 XtSetArg(args[j], XtNheight, 35); j++;
1112 // XtSetArg(args[j], XtNwidth, 60); j++;
1113 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1114 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1115 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1116 XtSetArg(args[j], XtNright, XtChainRight); j++;
1117 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass, form, args, j);
1118 XtAddCallback(b_ok, XtNcallback, NewVariantCallback, (XtPointer) 0);
1121 XtSetArg(args[j], XtNfromVert, buttonDesc[14].handle); j++;
1122 // XtSetArg(args[j], XtNheight, 70); j++;
1123 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1124 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1125 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1126 XtSetArg(args[j], XtNright, XtChainRight); j++;
1127 XtSetArg(args[j], XtNlabel, _("WARNING: variants with un-orthodox\n"
1128 "pieces only have built-in bitmaps\n"
1129 "for -boardSize middling, bulky and\n"
1130 "petite, and substitute king or amazon\n"
1131 "for missing bitmaps. (See manual.)")); j++;
1132 XtCreateManagedWidget("warning", labelWidgetClass, form, args, j);
1134 XtRealizeWidget(popup);
1135 CatchDeleteWindow(popup, "NewVariantPopDown");
1137 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1138 &x, &y, &win_x, &win_y, &mask);
1140 XtSetArg(args[0], XtNx, x - 10);
1141 XtSetArg(args[1], XtNy, y - 30);
1142 XtSetValues(popup, args, 2);
1144 XtPopup(popup, XtGrabExclusive);
1145 NewVariantUp = True;
1148 void NewVariantProc(w, event, prms, nprms)
1157 //--------------------------- UCI Menu Popup ------------------------------------------
1167 struct UciControl controlDesc[] = {
1168 {N_("maximum nr of CPUs:"), 0, &appData.smpCores},
1169 {N_("Polyglot Directory:"), 0, &appData.polyglotDir},
1170 {N_("Hash Size (MB):"), 0, &appData.defaultHashSize},
1171 {N_("EGTB Path:"), 0, &appData.defaultPathEGTB},
1172 {N_("EGTB Cache (MB):"), 0, &appData.defaultCacheSizeEGTB},
1173 {N_("Polyglot Book:"), 0, &appData.polyglotBook},
1181 XtPopdown(UciShell);
1182 XtDestroyWidget(UciShell);
1187 void UciCallback(w, client_data, call_data)
1189 XtPointer client_data, call_data;
1193 int oldCores = appData.smpCores, ponder = 0;
1195 XtSetArg(args[0], XtNlabel, &name);
1196 XtGetValues(w, args, 1);
1198 if (strcmp(name, _("OK")) == 0) {
1199 int i, j; String name;
1200 for(i=0; i<6; i++) {
1201 XtSetArg(args[0], XtNstring, &name);
1202 XtGetValues(controlDesc[i].handle, args, 1);
1205 *(char**) controlDesc[i].ptr = strdup(name);
1207 if(sscanf(name, "%d", &j) == 1)
1208 *(int*) controlDesc[i].ptr = j;
1211 XtSetArg(args[0], XtNstate, &appData.usePolyglotBook);
1212 XtGetValues(w1, args, 1);
1213 XtSetArg(args[0], XtNstate, &appData.firstHasOwnBookUCI);
1214 XtGetValues(w2, args, 1);
1215 XtSetArg(args[0], XtNstate, &appData.secondHasOwnBookUCI);
1216 XtGetValues(w3, args, 1);
1217 XtSetArg(args[0], XtNstate, &ponder);
1218 XtGetValues(w4, args, 1);
1220 // adjust setting in other menu for duplicates
1221 // (perhaps duplicates should be removed from general Option Menu?)
1222 XtSetArg(args[0], XtNleftBitmap, ponder ? xMarkPixmap : None);
1223 XtSetValues(XtNameToWidget(menuBarWidget,
1224 "menuOptions.Ponder Next Move"), args, 1);
1226 // make sure changes are sent to first engine by re-initializing it
1227 // if it was already started pre-emptively at end of previous game
1228 if(gameMode == BeginningOfGame) Reset(True, True); else {
1229 // Some changed setting need immediate sending always.
1230 PonderNextMoveEvent(ponder);
1231 if(oldCores != appData.smpCores)
1232 NewSettingEvent(False, &(first.maxCores), "cores", appData.smpCores);
1242 Widget popup, layout, form, b_ok, b_cancel, last = NULL, new, upperLeft;
1250 XtSetArg(args[i], XtNresizable, True); i++;
1251 // XtSetArg(args[i], XtNwidth, 300); i++;
1253 XtCreatePopupShell(_("Engine Settings"), transientShellWidgetClass,
1254 shellWidget, args, i);
1257 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1258 layoutArgs, XtNumber(layoutArgs));
1262 XtCreateManagedWidget("form", formWidgetClass, layout,
1263 formArgs, XtNumber(formArgs));
1266 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1267 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1268 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1269 // XtSetArg(args[j], XtNheight, 20); j++;
1270 for(i = 0; controlDesc[i].name != NULL; i++) {
1272 XtSetArg(args[j], XtNfromVert, last); j++;
1273 // XtSetArg(args[j], XtNwidth, 130); j++;
1274 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1275 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1276 XtSetArg(args[j], XtNborderWidth, 0); j++;
1277 new = XtCreateManagedWidget(controlDesc[i].name, labelWidgetClass, form, args, j);
1278 if(i==0) upperLeft = new;
1281 XtSetArg(args[j], XtNborderWidth, 1); j++;
1282 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1283 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1284 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1285 XtSetArg(args[j], XtNright, XtChainRight); j++;
1286 XtSetArg(args[j], XtNresizable, True); j++;
1287 XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++;
1288 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
1290 XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ?
1291 * (char**) controlDesc[i].ptr : ""); j++;
1293 snprintf(def, MSG_SIZ, "%d", * (int*) controlDesc[i].ptr);
1294 XtSetArg(args[j], XtNstring, def); j++;
1296 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1297 controlDesc[i].handle = last =
1298 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
1299 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1303 XtSetArg(args[j], XtNfromHoriz, controlDesc[0].handle); j++;
1304 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
1305 XtSetArg(args[j], XtNtop, XtChainTop); j++;
1306 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1307 XtSetArg(args[j], XtNright, XtChainRight); j++;
1308 XtSetArg(args[j], XtNstate, appData.ponderNextMove); j++;
1309 w4 = XtCreateManagedWidget(_("Ponder"), toggleWidgetClass, form, args, j);
1312 XtSetArg(args[j], XtNfromVert, last); j++;
1313 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1314 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1315 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1316 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1317 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1318 XtAddCallback(b_ok, XtNcallback, UciCallback, (XtPointer) 0);
1320 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
1321 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1322 XtAddCallback(b_cancel, XtNcallback, UciPopDown, (XtPointer) 0);
1325 XtSetArg(args[j], XtNfromHoriz, upperLeft); j++;
1326 XtSetArg(args[j], XtNstate, appData.usePolyglotBook); j++;
1327 w1 = XtCreateManagedWidget(_(" use book "), toggleWidgetClass, form, args, j);
1328 // XtAddCallback(w1, XtNcallback, UciCallback, (XtPointer) 0);
1331 XtSetArg(args[j], XtNfromHoriz, w1); j++;
1332 XtSetArg(args[j], XtNstate, appData.firstHasOwnBookUCI); j++;
1333 w2 = XtCreateManagedWidget(_("own book 1"), toggleWidgetClass, form, args, j);
1334 // XtAddCallback(w2, XtNcallback, UciCallback, (XtPointer) 0);
1337 XtSetArg(args[j], XtNfromHoriz, w2); j++;
1338 XtSetArg(args[j], XtNstate, appData.secondHasOwnBookUCI); j++;
1339 w3 = XtCreateManagedWidget(_("own book 2"), toggleWidgetClass, form, args, j);
1340 // XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0);
1342 XtRealizeWidget(popup);
1343 CatchDeleteWindow(popup, "UciPopDown");
1345 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1346 &x, &y, &win_x, &win_y, &mask);
1348 XtSetArg(args[0], XtNx, x - 10);
1349 XtSetArg(args[1], XtNy, y - 30);
1350 XtSetValues(popup, args, 2);
1352 XtPopup(popup, XtGrabExclusive);
1356 SetFocus(controlDesc[2].handle, popup, (XEvent*) NULL, False);
1357 // XtSetKeyboardFocus(popup, controlDesc[1].handle);
1360 void UciMenuProc(w, event, prms, nprms)
1369 //--------------------------- Engine-specific options menu ----------------------------------
1372 Widget SettingsShell;
1373 int values[MAX_OPTIONS];
1374 ChessProgramState *currentCps;
1376 void SettingsPopDown()
1378 if (!SettingsUp) return;
1380 XtPopdown(SettingsShell);
1381 XtDestroyWidget(SettingsShell);
1386 void SpinCallback(w, client_data, call_data)
1388 XtPointer client_data, call_data;
1394 int data = (intptr_t) client_data;
1396 XtSetArg(args[0], XtNlabel, &name);
1397 XtGetValues(w, args, 1);
1400 XtSetArg(args[0], XtNstring, &val);
1401 XtGetValues(currentCps->option[data].handle, args, 1);
1402 sscanf(val, "%d", &j);
1403 if (strcmp(name, "+") == 0) {
1404 if(++j > currentCps->option[data].max) return;
1406 if (strcmp(name, "-") == 0) {
1407 if(--j < currentCps->option[data].min) return;
1409 snprintf(buf, MSG_SIZ, "%d", j);
1410 XtSetArg(args[0], XtNstring, buf);
1411 XtSetValues(currentCps->option[data].handle, args, 1);
1414 void SettingsCallback(w, client_data, call_data)
1416 XtPointer client_data, call_data;
1422 int data = (intptr_t) client_data;
1424 XtSetArg(args[0], XtNlabel, &name);
1425 XtGetValues(w, args, 1);
1427 if (strcmp(name, _("cancel")) == 0) {
1431 if (strcmp(name, _("OK")) == 0 || data) { // save buttons imply OK
1432 for(i=0; i<currentCps->nrOptions; i++) { // send all options that had to be OK-ed to engine
1433 switch(currentCps->option[i].type) {
1435 XtSetArg(args[0], XtNstring, &val);
1436 XtGetValues(currentCps->option[i].handle, args, 1);
1437 if(strcmp(currentCps->option[i].textValue, val)) {
1438 safeStrCpy(currentCps->option[i].textValue, val, MSG_SIZ - (currentCps->option[i].textValue - currentCps->option[i].name) );
1439 snprintf(buf, MSG_SIZ, "option %s=%s\n", currentCps->option[i].name, val);
1440 SendToProgram(buf, currentCps);
1444 XtSetArg(args[0], XtNstring, &val);
1445 XtGetValues(currentCps->option[i].handle, args, 1);
1446 sscanf(val, "%d", &j);
1447 if(j > currentCps->option[i].max) j = currentCps->option[i].max;
1448 if(j < currentCps->option[i].min) j = currentCps->option[i].min;
1449 if(currentCps->option[i].value != j) {
1450 currentCps->option[i].value = j;
1451 snprintf(buf, MSG_SIZ, "option %s=%d\n", currentCps->option[i].name, j);
1452 SendToProgram(buf, currentCps);
1457 XtSetArg(args[0], XtNstate, &j);
1458 XtGetValues(currentCps->option[i].handle, args, 1);
1459 if(currentCps->option[i].value != j) {
1460 currentCps->option[i].value = j;
1461 snprintf(buf, MSG_SIZ, "option %s=%d\n", currentCps->option[i].name, j);
1462 SendToProgram(buf, currentCps);
1466 if(currentCps->option[i].value != values[i]) {
1467 currentCps->option[i].value = values[i];
1468 snprintf(buf, MSG_SIZ, "option %s=%s\n", currentCps->option[i].name,
1469 ((char**)currentCps->option[i].textValue)[values[i]]);
1470 SendToProgram(buf, currentCps);
1474 if( appData.debugMode )
1475 fprintf(debugFP, "SettingsPopUp: unexpected case in switch.\n");
1479 if(data) { // send save-button command to engine
1480 snprintf(buf, MSG_SIZ, "option %s\n", name);
1481 SendToProgram(buf, currentCps);
1486 snprintf(buf, MSG_SIZ, "option %s\n", name);
1487 SendToProgram(buf, currentCps);
1490 void ComboSelect(w, addr, index) // callback for all combo items
1496 int i = ((intptr_t)addr)>>8;
1497 int j = 255 & (intptr_t) addr;
1499 values[i] = j; // store in temporary, for transfer at OK
1500 XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]);
1501 XtSetValues(currentCps->option[i].handle, args, 1);
1504 void CreateComboPopup(parent, name, n, mb)
1514 menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
1517 XtSetArg(args[j], XtNwidth, 100); j++;
1518 // XtSetArg(args[j], XtNright, XtChainRight); j++;
1519 while (mb[i] != NULL) {
1520 entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
1522 XtAddCallback(entry, XtNcallback,
1523 (XtCallbackProc) ComboSelect,
1524 (caddr_t)(intptr_t) (256*n+i));
1530 SettingsPopUp(ChessProgramState *cps)
1533 Widget popup, layout, dialog, edit=NULL, form, last, b_ok, b_cancel, leftMargin = NULL, textField = NULL;
1535 int x, y, i, j, height, width, h, c;
1536 int win_x, win_y, maxWidth, maxTextWidth;
1539 static char pane[6] = "paneX";
1540 Widget texts[100], forelast = NULL, anchor, widest;
1542 // to do: start up second engine if needed
1543 if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
1546 if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1;
1547 height = cps->nrOptions / width + 1;
1549 XtSetArg(args[i], XtNresizable, True); i++;
1550 SettingsShell = popup =
1551 XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
1552 shellWidget, args, i);
1555 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1556 layoutArgs, XtNumber(layoutArgs));
1557 for(c=0; c<width; c++) {
1560 XtCreateManagedWidget(pane, formWidgetClass, layout,
1561 formArgs, XtNumber(formArgs));
1563 XtSetArg(args[j], XtNfromHoriz, leftMargin); j++;
1564 XtSetValues(form, args, j);
1567 last = widest = NULL; anchor = forelast;
1568 for(h=0; h<height; h++) {
1571 if(i >= cps->nrOptions) break;
1572 switch(cps->option[i].type) {
1574 snprintf(def, MSG_SIZ, "%d", cps->option[i].value);
1577 XtSetArg(args[j], XtNfromVert, last); j++;
1578 XtSetArg(args[j], XtNborderWidth, 0); j++;
1579 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1581 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1583 XtSetArg(args[j], XtNfromVert, last); j++;
1584 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1585 XtSetArg(args[j], XtNborderWidth, 1); j++;
1586 XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 175); j++;
1587 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1588 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1589 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1590 XtSetArg(args[j], XtNright, XtChainRight); j++;
1591 XtSetArg(args[j], XtNresizable, True); j++;
1592 XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue); j++;
1593 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
1595 cps->option[i].handle = (void*)
1596 (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1597 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1598 if(cps->option[i].type == TextBox) break;
1600 // add increment and decrement controls for spin
1602 XtSetArg(args[j], XtNfromVert, edit); j++;
1603 XtSetArg(args[j], XtNfromHoriz, last); j++;
1604 XtSetArg(args[j], XtNheight, 10); j++;
1605 XtSetArg(args[j], XtNwidth, 20); j++;
1606 edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j);
1607 XtAddCallback(edit, XtNcallback, SpinCallback,
1608 (XtPointer)(intptr_t) i);
1611 XtSetArg(args[j], XtNfromVert, edit); j++;
1612 XtSetArg(args[j], XtNfromHoriz, last); j++;
1613 XtSetArg(args[j], XtNheight, 10); j++;
1614 XtSetArg(args[j], XtNwidth, 20); j++;
1615 last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1616 XtAddCallback(last, XtNcallback, SpinCallback,
1617 (XtPointer)(intptr_t) i);
1621 XtSetArg(args[j], XtNfromVert, last); j++;
1622 XtSetArg(args[j], XtNwidth, 10); j++;
1623 XtSetArg(args[j], XtNheight, 10); j++;
1624 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1625 cps->option[i].handle = (void*)
1626 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1628 XtSetArg(args[j], XtNfromVert, last); j++;
1629 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1630 XtSetArg(args[j], XtNborderWidth, 0); j++;
1631 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1632 last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1637 XtSetArg(args[j], XtNfromVert, last); j++;
1638 XtSetArg(args[j], XtNstate, cps->option[i].value); j++;
1639 cps->option[i].handle = (void*)
1640 (dialog = last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));
1641 XtAddCallback(last, XtNcallback, SettingsCallback,
1642 (XtPointer)(intptr_t) (cps->option[i].type == SaveButton));
1646 XtSetArg(args[j], XtNfromVert, last); j++;
1647 XtSetArg(args[j], XtNborderWidth, 0); j++;
1648 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1649 dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);
1652 XtSetArg(args[j], XtNfromVert, last); j++;
1653 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1654 XtSetArg(args[j], XtNwidth, 100); j++;
1655 XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name)); j++;
1656 XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]); j++;
1657 cps->option[i].handle = (void*)
1658 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1659 CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue);
1660 values[i] = cps->option[i].value;
1663 if( appData.debugMode )
1664 fprintf(debugFP, "SettingsPopUp: unexpected case in switch.\n");
1669 // make an attempt to align all spins and textbox controls
1670 maxWidth = maxTextWidth = 0;
1671 for(h=0; h<height; h++) {
1673 if(i >= cps->nrOptions) break;
1674 if(cps->option[i].type == Spin || cps->option[i].type == TextBox) {
1677 XtSetArg(args[j], XtNwidth, &w); j++;
1678 XtGetValues(texts[h], args, j);
1679 if(cps->option[i].type == Spin) {
1680 if(w > maxWidth) maxWidth = w;
1683 if(w > maxTextWidth) maxTextWidth = w;
1684 if(!widest) widest = texts[h];
1688 if(maxTextWidth + 110 < maxWidth)
1689 maxTextWidth = maxWidth - 110;
1690 else maxWidth = maxTextWidth + 110;
1691 for(h=0; h<height; h++) {
1693 if(i >= cps->nrOptions) break;
1695 if(cps->option[i].type == Spin) {
1696 XtSetArg(args[j], XtNwidth, maxWidth); j++;
1697 XtSetValues(texts[h], args, j);
1699 if(cps->option[i].type == TextBox) {
1700 XtSetArg(args[j], XtNwidth, maxTextWidth); j++;
1701 XtSetValues(texts[h], args, j);
1706 XtSetArg(args[j], XtNfromVert, anchor ? anchor : last); j++;
1707 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1708 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1709 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1710 XtSetArg(args[j], XtNright, XtChainRight); j++;
1711 XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog); j++;
1712 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1713 XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
1715 XtSetArg(args[j-1], XtNfromHoriz, b_ok);
1716 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1717 XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
1719 XtRealizeWidget(popup);
1720 CatchDeleteWindow(popup, "SettingsPopDown");
1722 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1723 &x, &y, &win_x, &win_y, &mask);
1725 XtSetArg(args[0], XtNx, x - 10);
1726 XtSetArg(args[1], XtNy, y - 30);
1727 XtSetValues(popup, args, 2);
1729 XtPopup(popup, XtGrabExclusive);
1733 if(textField)SetFocus(textField, popup, (XEvent*) NULL, False);
1736 void FirstSettingsProc(w, event, prms, nprms)
1742 SettingsPopUp(&first);
1745 void SecondSettingsProc(w, event, prms, nprms)
1751 if(WaitForSecond(SettingsMenuIfReady)) return;
1752 SettingsPopUp(&second);
1755 //---------------------------- Chat Windows ----------------------------------------------
1757 void OutputChatMessage(int partner, char *mess)