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/Xatom.h>
54 #include <X11/Xaw/Dialog.h>
55 #include <X11/Xaw/Form.h>
56 #include <X11/Xaw/List.h>
57 #include <X11/Xaw/Label.h>
58 #include <X11/Xaw/SimpleMenu.h>
59 #include <X11/Xaw/SmeBSB.h>
60 #include <X11/Xaw/SmeLine.h>
61 #include <X11/Xaw/Box.h>
62 #include <X11/Xaw/Paned.h>
63 #include <X11/Xaw/MenuButton.h>
64 #include <X11/cursorfont.h>
65 #include <X11/Xaw/Text.h>
66 #include <X11/Xaw/AsciiText.h>
67 #include <X11/Xaw/Viewport.h>
68 #include <X11/Xaw/Toggle.h>
76 # define _(s) gettext (s)
77 # define N_(s) gettext_noop (s)
83 // [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines
85 static Widget previous = NULL;
87 void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
93 XtSetArg(args[0], XtNdisplayCaret, False);
94 XtSetValues(previous, args, 1);
96 XtSetArg(args[0], XtNstring, &s);
97 XtGetValues(w, args, 1);
98 XtSetArg(args[0], XtNdisplayCaret, True);
99 XtSetArg(args[1], XtNinsertPosition, strlen(s));
100 XtSetValues(w, args, 2);
101 XtSetKeyboardFocus((Widget) data, w);
105 //--------------------------- New Shuffle Game --------------------------------------------
109 void ShufflePopDown()
111 if (!shuffleUp) return;
112 XtPopdown(shuffleShell);
113 XtDestroyWidget(shuffleShell);
118 void ShuffleCallback(w, client_data, call_data)
120 XtPointer client_data, call_data;
127 XtSetArg(args[0], XtNlabel, &name);
128 XtGetValues(w, args, 1);
130 if (strcmp(name, _("cancel")) == 0) {
134 if (strcmp(name, _("off")) == 0) {
136 shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it!
140 if (strcmp(name, _("random")) == 0) {
141 snprintf(buf, MSG_SIZ, "%d", rand());
142 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
143 XtSetValues(XtParent(w), args, 1);
146 if (strcmp(name, _("ok")) == 0) {
148 name = XawDialogGetValueString(w2 = XtParent(w));
149 if(sscanf(name ,"%d",&nr) != 1) {
150 snprintf(buf, MSG_SIZ, "%d", appData.defaultFrcPosition);
151 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
152 XtSetValues(w2, args, 1);
155 appData.defaultFrcPosition = nr;
156 shuffleOpenings = True;
166 Widget popup, layout, dialog, edit;
174 XtSetArg(args[i], XtNresizable, True); i++;
175 XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
176 shuffleShell = popup =
177 XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass,
178 shellWidget, args, i);
181 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
182 layoutArgs, XtNumber(layoutArgs));
184 snprintf(def, MSG_SIZ, "%d\n", appData.defaultFrcPosition);
186 XtSetArg(args[i], XtNlabel, _("Start-position number:")); i++;
187 XtSetArg(args[i], XtNvalue, def); i++;
188 XtSetArg(args[i], XtNborderWidth, 0); i++;
189 dialog = XtCreateManagedWidget(_("Shuffle"), dialogWidgetClass,
192 // XtSetArg(args[0], XtNeditType, XawtextEdit); // [HGM] can't get edit to work decently
193 // XtSetArg(args[1], XtNuseStringInPlace, False);
194 // XtSetValues(dialog, args, 2);
196 XawDialogAddButton(dialog, _("ok"), ShuffleCallback, (XtPointer) dialog);
197 XawDialogAddButton(dialog, _("cancel"), ShuffleCallback, (XtPointer) dialog);
198 XawDialogAddButton(dialog, _("random"), ShuffleCallback, (XtPointer) dialog);
199 XawDialogAddButton(dialog, _("off"), ShuffleCallback, (XtPointer) dialog);
201 XtRealizeWidget(popup);
202 CatchDeleteWindow(popup, "ShufflePopDown");
204 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
205 &x, &y, &win_x, &win_y, &mask);
207 XtSetArg(args[0], XtNx, x - 10);
208 XtSetArg(args[1], XtNy, y - 30);
209 XtSetValues(popup, args, 2);
211 XtPopup(popup, XtGrabExclusive);
214 edit = XtNameToWidget(dialog, "*value");
216 XtSetKeyboardFocus(popup, edit);
219 void ShuffleMenuProc(w, event, prms, nprms)
225 // if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
226 // Reset(FALSE, TRUE);
231 //--------------------------- Time-Control Menu Popup ----------------------------------
233 Widget TimeControlShell;
235 Widget tcMess1, tcMess2, tcData, tcTime, tcOdds1, tcOdds2;
236 int tcIncrement, tcMoves;
238 void TimeControlPopDown()
240 if (!TimeControlUp) return;
242 XtPopdown(TimeControlShell);
243 XtDestroyWidget(TimeControlShell);
244 TimeControlUp = False;
248 void TimeControlCallback(w, client_data, call_data)
250 XtPointer client_data, call_data;
257 XtSetArg(args[0], XtNlabel, &name);
258 XtGetValues(w, args, 1);
260 if (strcmp(name, _("classical")) == 0) {
261 if(tcInc == 0) return;
263 XtSetArg(args[j], XtNlabel, _("minutes for each")); j++;
264 XtSetValues(tcMess1, args, j);
266 XtSetArg(args[j], XtNlabel, _("moves")); j++;
267 XtSetValues(tcMess2, args, j);
270 XtSetArg(args[j], XtNstring, &name); j++;
271 XtGetValues(tcData, args, j);
272 tcIncrement = 0; sscanf(name, "%d", &tcIncrement);
274 snprintf(buf, MSG_SIZ, "%d", tcMoves);
276 XtSetArg(args[j], XtNstring, buf); j++;
277 XtSetValues(tcData, args, j);
281 if (strcmp(name, _("incremental")) == 0) {
282 if(tcInc == 1) return;
284 XtSetArg(args[j], XtNlabel, _("minutes, plus")); j++;
285 XtSetValues(tcMess1, args, j);
287 XtSetArg(args[j], XtNlabel, _("sec/move")); j++;
288 XtSetValues(tcMess2, args, j);
291 XtSetArg(args[j], XtNstring, &name); j++;
292 XtGetValues(tcData, args, j);
293 tcMoves = appData.movesPerSession; sscanf(name, "%d", &tcMoves);
295 snprintf(buf, MSG_SIZ, "%d", tcIncrement);
297 XtSetArg(args[j], XtNstring, buf); j++;
298 XtSetValues(tcData, args, j);
302 if (strcmp(name, _("fixed time")) == 0) {
303 if(tcInc == 2) return;
305 XtSetArg(args[j], XtNlabel, _("sec/move (max)")); j++;
306 XtSetValues(tcMess1, args, j);
308 XtSetArg(args[j], XtNlabel, _("")); j++;
309 XtSetValues(tcMess2, args, j);
311 XtSetArg(args[j], XtNstring, ""); j++;
312 XtSetValues(tcData, args, j);
316 if (strcmp(name, _(" OK ")) == 0) {
318 XtSetArg(args[0], XtNstring, &txt);
319 XtGetValues(tcData, args, 1);
322 ok = sscanf(txt, "%d", &inc); mps = 0;
323 if(!ok && txt[0] == 0) { inc = 0; ok = 1; } // accept empty string as zero
327 ok = sscanf(txt, "%d", &mps); inc = -1;
331 ok = 1; inc = -1; mps = 40;
334 XtSetArg(args[0], XtNstring, ""); // erase any offending input
335 XtSetValues(tcData, args, 1);
338 XtSetArg(args[0], XtNstring, &txt);
339 XtGetValues(tcTime, args, 1);
341 if(sscanf(txt, "%d", &inc) != 1) {
342 XtSetArg(args[0], XtNstring, ""); // erase any offending input
343 XtSetValues(tcTime, args, 1);
344 DisplayError(_("Bad Time-Control String"), 0);
349 if(!ParseTimeControl(txt, inc, mps)) {
350 XtSetArg(args[0], XtNstring, ""); // erase any offending input
351 XtSetValues(tcTime, args, 1);
352 DisplayError(_("Bad Time-Control String"), 0);
356 appData.movesPerSession = mps;
357 appData.timeIncrement = inc;
358 appData.timeControl = strdup(txt);
360 XtSetArg(args[0], XtNstring, &txt);
361 XtGetValues(tcOdds1, args, 1);
362 appData.firstTimeOdds = first.timeOdds
363 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
364 XtGetValues(tcOdds2, args, 1);
365 appData.secondTimeOdds = second.timeOdds
366 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
369 TimeControlPopDown();
374 void TimeControlPopUp()
377 Widget popup, layout, form, b_ok, b_cancel, b_clas, b_inc, mess;
384 tcInc = searchTime > 0 ? 2 : (appData.timeIncrement >= 0);
385 tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
386 if(!tcInc) tcIncrement = 0;
387 snprintf(def, MSG_SIZ, "%d", tcInc ? tcIncrement : tcMoves);
390 XtSetArg(args[i], XtNresizable, True); i++;
391 // XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
392 TimeControlShell = popup =
393 XtCreatePopupShell(_("TimeControl Menu"), transientShellWidgetClass,
394 shellWidget, args, i);
397 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
398 layoutArgs, XtNumber(layoutArgs));
401 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
402 formArgs, XtNumber(formArgs));
405 // XtSetArg(args[j], XtNwidth, (XtArgVal) 300); j++;
406 // XtSetArg(args[j], XtNheight, (XtArgVal) 85); j++;
407 XtSetValues(popup, args, j);
410 XtSetArg(args[j], XtNborderWidth, 1); j++;
411 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
412 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
413 XtSetArg(args[j], XtNstring, appData.timeControl); j++;
414 XtSetArg(args[j], XtNdisplayCaret, False); j++;
415 XtSetArg(args[j], XtNtop, XtChainTop); j++;
416 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
417 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
418 XtSetArg(args[j], XtNright, XtChainRight); j++;
419 XtSetArg(args[j], XtNresizable, True); j++;
420 XtSetArg(args[j], XtNwidth, 85); j++;
421 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
422 tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j);
423 XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup);
426 XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _("sec/move (max) ") : _(" minutes, plus ") : _("minutes for each")); j++;
427 XtSetArg(args[j], XtNborderWidth, 0); j++;
428 XtSetArg(args[j], XtNfromHoriz, tcTime); j++;
429 XtSetArg(args[j], XtNtop, XtChainTop); j++;
430 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
431 XtSetArg(args[j], XtNleft, XtChainRight); j++;
432 XtSetArg(args[j], XtNright, XtChainRight); j++;
433 // XtSetArg(args[j], XtNwidth, 100); j++;
434 // XtSetArg(args[j], XtNheight, 20); j++;
435 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
438 XtSetArg(args[j], XtNborderWidth, 1); j++;
439 XtSetArg(args[j], XtNfromHoriz, tcMess1); j++;
440 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
441 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
442 XtSetArg(args[j], XtNstring, def); j++;
443 XtSetArg(args[j], XtNdisplayCaret, False); j++;
444 XtSetArg(args[j], XtNtop, XtChainTop); j++;
445 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
446 XtSetArg(args[j], XtNleft, XtChainRight); j++;
447 XtSetArg(args[j], XtNright, XtChainRight); j++;
448 XtSetArg(args[j], XtNresizable, True); j++;
449 XtSetArg(args[j], XtNwidth, 40); j++;
450 // XtSetArg(args[j], XtNheight, 20); j++;
451 tcData = XtCreateManagedWidget("MPS", asciiTextWidgetClass, form, args, j);
452 XtAddEventHandler(tcData, ButtonPressMask, False, SetFocus, (XtPointer) popup);
455 XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _(" ") : _("sec/move") : _("moves ")); j++;
456 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
457 XtSetArg(args[j], XtNborderWidth, 0); j++;
458 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
459 XtSetArg(args[j], XtNtop, XtChainTop); j++;
460 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
461 XtSetArg(args[j], XtNleft, XtChainRight); j++;
462 XtSetArg(args[j], XtNright, XtChainRight); j++;
463 // XtSetArg(args[j], XtNwidth, 80); j++;
464 // XtSetArg(args[j], XtNheight, 20); j++;
465 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass,
469 XtSetArg(args[j], XtNborderWidth, 1); j++;
470 XtSetArg(args[j], XtNfromVert, tcTime); j++;
471 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
472 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
473 XtSetArg(args[j], XtNstring, "1"); j++;
474 XtSetArg(args[j], XtNdisplayCaret, False); j++;
475 XtSetArg(args[j], XtNtop, XtChainTop); j++;
476 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
477 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
478 XtSetArg(args[j], XtNright, XtChainLeft); j++;
479 XtSetArg(args[j], XtNresizable, True); j++;
480 XtSetArg(args[j], XtNwidth, 40); j++;
481 // XtSetArg(args[j], XtNheight, 20); j++;
482 tcOdds1 = XtCreateManagedWidget("Odds1", asciiTextWidgetClass, form, args, j);
483 XtAddEventHandler(tcOdds1, ButtonPressMask, False, SetFocus, (XtPointer) popup);
486 XtSetArg(args[j], XtNborderWidth, 1); j++;
487 XtSetArg(args[j], XtNfromVert, tcTime); j++;
488 XtSetArg(args[j], XtNfromHoriz, tcOdds1); j++;
489 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
490 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
491 XtSetArg(args[j], XtNstring, "1"); j++;
492 XtSetArg(args[j], XtNdisplayCaret, False); j++;
493 XtSetArg(args[j], XtNtop, XtChainTop); j++;
494 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
495 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
496 XtSetArg(args[j], XtNright, XtChainLeft); j++;
497 XtSetArg(args[j], XtNresizable, True); j++;
498 XtSetArg(args[j], XtNwidth, 40); j++;
499 // XtSetArg(args[j], XtNheight, 20); j++;
500 tcOdds2 = XtCreateManagedWidget("Odds2", asciiTextWidgetClass, form, args, j);
501 XtAddEventHandler(tcOdds2, ButtonPressMask, False, SetFocus, (XtPointer) popup);
504 XtSetArg(args[j], XtNlabel, _("Engine #1 and #2 Time-Odds Factors")); j++;
505 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
506 XtSetArg(args[j], XtNborderWidth, 0); j++;
507 XtSetArg(args[j], XtNfromVert, tcTime); j++;
508 XtSetArg(args[j], XtNfromHoriz, tcOdds2); j++;
509 XtSetArg(args[j], XtNtop, XtChainTop); j++;
510 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
511 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
512 XtSetArg(args[j], XtNright, XtChainRight); j++;
513 // XtSetArg(args[j], XtNwidth, 200); j++;
514 // XtSetArg(args[j], XtNheight, 20); j++;
515 mess = XtCreateManagedWidget("Oddstext", labelWidgetClass,
518 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
519 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
520 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
521 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
522 XtSetArg(args[j], XtNright, XtChainLeft); j++;
523 XtSetArg(args[j], XtNstate, tcInc==0); j++;
524 b_clas= XtCreateManagedWidget(_("classical"), toggleWidgetClass,
526 XtAddCallback(b_clas, XtNcallback, TimeControlCallback, (XtPointer) 0);
529 XtSetArg(args[j], XtNradioGroup, b_clas); j++;
530 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
531 XtSetArg(args[j], XtNfromHoriz, b_clas); j++;
532 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
533 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
534 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
535 XtSetArg(args[j], XtNright, XtChainLeft); j++;
536 XtSetArg(args[j], XtNstate, tcInc==1); j++;
537 b_inc = XtCreateManagedWidget(_("incremental"), toggleWidgetClass,
539 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
542 XtSetArg(args[j], XtNradioGroup, b_inc); j++;
543 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
544 XtSetArg(args[j], XtNfromHoriz, b_inc); j++;
545 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
546 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
547 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
548 XtSetArg(args[j], XtNright, XtChainLeft); j++;
549 XtSetArg(args[j], XtNstate, tcInc==2); j++;
550 b_inc = XtCreateManagedWidget(_("fixed time"), toggleWidgetClass,
552 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
555 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
556 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
557 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
558 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
559 XtSetArg(args[j], XtNleft, XtChainRight); j++;
560 XtSetArg(args[j], XtNright, XtChainRight); j++;
561 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass,
563 XtAddCallback(b_ok, XtNcallback, TimeControlCallback, (XtPointer) 0);
566 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
567 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
568 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
569 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
570 XtSetArg(args[j], XtNleft, XtChainRight); j++;
571 XtSetArg(args[j], XtNright, XtChainRight); j++;
572 b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
574 XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0);
576 XtRealizeWidget(popup);
577 CatchDeleteWindow(popup, "TimeControlPopDown");
579 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
580 &x, &y, &win_x, &win_y, &mask);
582 XtSetArg(args[0], XtNx, x - 10);
583 XtSetArg(args[1], XtNy, y - 30);
584 XtSetValues(popup, args, 2);
586 XtPopup(popup, XtGrabExclusive);
587 TimeControlUp = True;
590 SetFocus(tcTime, popup, (XEvent*) NULL, False);
591 // XtSetKeyboardFocus(popup, tcTime);
594 void TimeControlProc(w, event, prms, nprms)
603 //--------------------------- Engine-specific options menu ----------------------------------
605 typedef void ButtonCallback(int n);
607 int values[MAX_OPTIONS];
608 ChessProgramState *currentCps;
609 static Option *currentOption;
610 static Boolean browserUp;
611 ButtonCallback *comboCallback;
613 void CheckCallback(Widget ww, XtPointer data, XEvent *event, Boolean *b)
615 Widget w = currentOption[(int)(intptr_t)data].handle;
619 XtSetArg(args[0], XtNstate, &s);
620 XtGetValues(w, args, 1);
621 XtSetArg(args[0], XtNstate, !s);
622 XtSetValues(w, args, 1);
625 void SpinCallback(w, client_data, call_data)
627 XtPointer client_data, call_data;
631 char buf[MSG_SIZ], *p;
633 int data = (intptr_t) client_data;
635 XtSetArg(args[0], XtNlabel, &name);
636 XtGetValues(w, args, 1);
639 XtSetArg(args[0], XtNstring, &val);
640 XtGetValues(currentOption[data].handle, args, 1);
641 sscanf(val, "%d", &j);
642 if (strcmp(name, "browse") == 0) {
644 XtSetArg(args[0], XtNstring, &q);
645 XtGetValues(currentOption[data].handle, args, 1);
646 for(r = ""; *q; q++) if(*q == '.') r = q; else if(*q == '/') r = ""; // last dot after last slash
647 if(!strcmp(r, "") && !currentCps && currentOption[data].type == FileName && currentOption[data].textValue)
648 r = currentOption[data].textValue;
650 if(XsraSelFile(shells[0], currentOption[data].name, NULL, NULL, "", "", r,
651 currentOption[data].type == PathName ? "p" : "f", NULL, &p)) {
653 if(len && p[len-1] == '/') p[len-1] = NULLCHAR;
654 XtSetArg(args[0], XtNstring, p);
655 XtSetValues(currentOption[data].handle, args, 1);
658 SetFocus(currentOption[data].handle, shells[0], (XEvent*) NULL, False);
661 if (strcmp(name, "+") == 0) {
662 if(++j > currentOption[data].max) return;
664 if (strcmp(name, "-") == 0) {
665 if(--j < currentOption[data].min) return;
667 snprintf(buf, MSG_SIZ, "%d", j);
668 XtSetArg(args[0], XtNstring, buf);
669 XtSetValues(currentOption[data].handle, args, 1);
670 SetFocus(currentOption[data].handle, shells[0], NULL, False);
673 void ComboSelect(w, addr, index) // callback for all combo items
679 int i = ((intptr_t)addr)>>8;
680 int j = 255 & (intptr_t) addr;
682 values[i] = j; // store in temporary, for transfer at OK
683 XtSetArg(args[0], XtNlabel, _(((char**)currentOption[i].textValue)[j]));
684 XtSetValues(currentOption[i].handle, args, 1);
686 if(currentOption[i].min & 1 && !currentCps && comboCallback) (comboCallback)(i);
689 void CreateComboPopup(parent, name, n, mb)
699 menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
702 XtSetArg(args[j], XtNwidth, 100); j++;
703 // XtSetArg(args[j], XtNright, XtChainRight); j++;
704 while (mb[i] != NULL) {
705 XtSetArg(args[j], XtNlabel, _(mb[i]));
706 entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
708 XtAddCallback(entry, XtNcallback,
709 (XtCallbackProc) ComboSelect,
710 (caddr_t)(intptr_t) (256*n+i));
716 //----------------------------Generic dialog --------------------------------------------
718 // cloned from Engine Settings dialog (and later merged with it)
720 extern WindowPlacement wpComment, wpTags;
722 static int oldCores, oldPonder;
723 int MakeColors P((void));
724 void CreateGCs P((int redo));
725 void CreateAnyPieces P((void));
726 void GenericReadout P((int selected));
730 WindowPlacement *wp[10] = { NULL, &wpComment, &wpTags };
731 Option *dialogOptions[10];
733 void MarkMenu(char *item, int dlgNr)
736 XtSetArg(args[0], XtNleftBitmap, xMarkPixmap);
737 XtSetValues(marked[dlgNr] = XtNameToWidget(menuBarWidget, item), args, 1);
744 Dimension windowH, windowW; Position windowX, windowY;
745 if (!shellUp[n]) return 0;
746 if(n && wp[n]) { // remember position
748 XtSetArg(args[j], XtNx, &windowX); j++;
749 XtSetArg(args[j], XtNy, &windowY); j++;
750 XtSetArg(args[j], XtNheight, &windowH); j++;
751 XtSetArg(args[j], XtNwidth, &windowW); j++;
752 XtGetValues(shells[n], args, j);
755 wp[n]->width = windowW;
756 wp[n]->height = windowH;
759 XtPopdown(shells[n]);
760 if(n == 0) XtDestroyWidget(shells[n]);
763 XtSetArg(args[0], XtNleftBitmap, None);
764 XtSetValues(marked[n], args, 1);
766 if(!n) currentCps = NULL; // if an Engine Settings dialog was up, we must be popping it down now
770 void GenericPopDown(w, event, prms, nprms)
776 if(browserUp) return; // prevent closing dialog when it has an open file-browse daughter
777 PopDown(prms[0][0] - '0');
780 char *engineName, *engineDir, *engineChoice, *engineLine, *nickName, *params;
781 Boolean isUCI, hasBook, storeVariant, v1, addToList, useNick;
782 extern Option installOptions[], matchOptions[];
783 char *engineNr[] = { N_("First Engine"), N_("Second Engine"), NULL };
784 char *engineList[100] = {" "}, *engineMnemonic[100] = {""};
786 void AddToTourney(int n)
789 char *p, *val, buf[10000];
792 GenericReadout(4); // selected engine
793 t.ptr = engineChoice; t.firstPos = 0; t.length = strlen(engineChoice); t.format = XawFmt8Bit;
794 XawTextReplace(matchOptions[3].handle, 9999, 9999, &t);
795 t.ptr = "\n"; t.length = 1;
796 XawTextReplace(matchOptions[3].handle, 9999, 9999, &t);
801 if(appData.participants && appData.participants[0]) free(appData.participants);
802 appData.participants = strdup(engineName);
803 PopDown(0); // early popdown to prevent FreezeUI called through MatchEvent from causing XtGrab warning
804 if(CreateTourney(appData.tourneyFile)) MatchEvent(2); // start tourney
807 Option matchOptions[] = {
808 { 0, 0, 0, NULL, (void*) &appData.tourneyFile, ".trn", NULL, FileName, N_("Tournament file:") },
809 { 0, 0, 0, NULL, (void*) &appData.roundSync, "", NULL, CheckBox, N_("Sync after round (for concurrent playing of a single") },
810 { 0, 0, 0, NULL, (void*) &appData.cycleSync, "", NULL, CheckBox, N_("Sync after cycle tourney with multiple XBoards)") },
811 { 0xD, 150, 0, NULL, (void*) &engineName, "", NULL, TextBox, "Tourney participants:" },
812 { 0, 1, 0, NULL, (void*) &engineChoice, (char*) (engineMnemonic+1), (engineMnemonic+1), ComboBox, N_("Select Engine:") },
813 { 0, 0, 10, NULL, (void*) &appData.tourneyType, "", NULL, Spin, N_("Tourney type (0 = round-robin, 1 = gauntlet):") },
814 { 0, 1, 1000000000, NULL, (void*) &appData.tourneyCycles, "", NULL, Spin, N_("Number of tourney cycles:") },
815 { 0, 1, 1000000000, NULL, (void*) &appData.defaultMatchGames, "", NULL, Spin, N_("Default Number of Games in Match (or Pairing):") },
816 { 0, 0, 1000000000, NULL, (void*) &appData.matchPause, "", NULL, Spin, N_("Pause between Match Games (msec):") },
817 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, ".pgn", NULL, FileName, N_("Save Tourney Games on:") },
818 { 0, 0, 0, NULL, (void*) &appData.loadGameFile, ".pgn", NULL, FileName, N_("Game File with Opening Lines:") },
819 { 0, -2, 1000000000, NULL, (void*) &appData.loadGameIndex, "", NULL, Spin, N_("Game Number (-1 or -2 = Auto-Increment):") },
820 { 0, 0, 0, NULL, (void*) &appData.loadPositionFile, ".fen", NULL, FileName, N_("File with Start Positions:") },
821 { 0, -2, 1000000000, NULL, (void*) &appData.loadPositionIndex, "", NULL, Spin, N_("Position Number (-1 or -2 = Auto-Increment):") },
822 { 0, 0, 1000000000, NULL, (void*) &appData.rewindIndex, "", NULL, Spin, N_("Rewind Index after this many Games (0 = never):") },
823 { 0, 0, 0, NULL, (void*) &MatchOK, "", NULL, EndMark , "" }
826 void GeneralOptionsOK(int n)
828 int newPonder = appData.ponderNextMove;
829 appData.ponderNextMove = oldPonder;
830 PonderNextMoveEvent(newPonder);
833 Option generalOptions[] = {
834 { 0, 0, 0, NULL, (void*) &appData.sweepSelect, "", NULL, CheckBox, N_("Almost Always Queen (Detour Under-Promote)") },
835 { 0, 0, 0, NULL, (void*) &appData.animateDragging, "", NULL, CheckBox, N_("Animate Dragging") },
836 { 0, 0, 0, NULL, (void*) &appData.animate, "", NULL, CheckBox, N_("Animate Moving") },
837 { 0, 0, 0, NULL, (void*) &appData.autoCallFlag, "", NULL, CheckBox, N_("Auto Flag") },
838 { 0, 0, 0, NULL, (void*) &appData.autoFlipView, "", NULL, CheckBox, N_("Auto Flip View") },
839 { 0, 0, 0, NULL, (void*) &appData.blindfold, "", NULL, CheckBox, N_("Blindfold") },
840 { 0, 0, 0, NULL, (void*) &appData.dropMenu, "", NULL, CheckBox, N_("Drop Menu") },
841 { 0, 0, 0, NULL, (void*) &appData.highlightDragging, "", NULL, CheckBox, N_("Highlight Dragging (Show Move Targets)") },
842 { 0, 0, 0, NULL, (void*) &appData.highlightLastMove, "", NULL, CheckBox, N_("Highlight Last Move") },
843 { 0, 0, 0, NULL, (void*) &appData.highlightMoveWithArrow, "", NULL, CheckBox, N_("Highlight with Arrow") },
844 { 0, 0, 0, NULL, (void*) &appData.ringBellAfterMoves, "", NULL, CheckBox, N_("Move Sound") },
845 { 0, 0, 0, NULL, (void*) &appData.oneClick, "", NULL, CheckBox, N_("One-Click Moving") },
846 { 0, 0, 0, NULL, (void*) &appData.periodicUpdates, "", NULL, CheckBox, N_("Periodic Updates (in Analysis Mode)") },
847 { 0, 0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, N_("Ponder Next Move") },
848 { 0, 0, 0, NULL, (void*) &appData.popupExitMessage, "", NULL, CheckBox, N_("Popup Exit Messages") },
849 { 0, 0, 0, NULL, (void*) &appData.popupMoveErrors, "", NULL, CheckBox, N_("Popup Move Errors") },
850 { 0, 0, 0, NULL, (void*) &appData.showCoords, "", NULL, CheckBox, N_("Show Coordinates") },
851 { 0, 0, 0, NULL, (void*) &appData.markers, "", NULL, CheckBox, N_("Show Target Squares") },
852 { 0, 0, 0, NULL, (void*) &appData.hideThinkingFromHuman, "", NULL, CheckBox, N_("Hide Thinking from Human") },
853 { 0, 0, 0, NULL, (void*) &appData.testLegality, "", NULL, CheckBox, N_("Test Legality") },
854 { 0, 0, 10, NULL, (void*) &appData.flashCount, "", NULL, Spin, N_("Flash Moves (0 = no flashing):") },
855 { 0, 1, 10, NULL, (void*) &appData.flashRate, "", NULL, Spin, N_("Flash Rate (high = fast):") },
856 { 0, 5, 100,NULL, (void*) &appData.animSpeed, "", NULL, Spin, N_("Animation Speed (high = slow):") },
857 { 0, 0, 0, NULL, (void*) &GeneralOptionsOK, "", NULL, EndMark , "" }
862 VariantClass v = currentOption[n].value;
863 if(!appData.noChessProgram) {
864 char *name = VariantName(v), buf[MSG_SIZ];
865 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
866 /* [HGM] in protocol 2 we check if variant is suported by engine */
867 snprintf(buf, MSG_SIZ, _("Variant %s not supported by %s"), name, first.tidy);
868 DisplayError(buf, 0);
869 return; /* ignore OK if first engine does not support it */
871 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
872 snprintf(buf, MSG_SIZ, _("Warning: second engine (%s) does not support this!"), second.tidy);
873 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
877 GenericReadout(-1); // make sure ranks and file settings are read
879 gameInfo.variant = v;
880 appData.variant = VariantName(v);
882 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
883 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
884 appData.pieceToCharTable = NULL;
885 appData.pieceNickNames = "";
886 appData.colorNickNames = "";
892 Option variantDescriptors[] = {
893 { VariantNormal, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("normal")},
894 { VariantFairy, 1, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("fairy")},
895 { VariantFischeRandom, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("FRC")},
896 { VariantSChess, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Seirawan")},
897 { VariantWildCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("wild castle")},
898 { VariantSuper, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Superchess")},
899 { VariantNoCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("no castle")},
900 { VariantCrazyhouse, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("crazyhouse")},
901 { VariantKnightmate, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("knightmate")},
902 { VariantBughouse, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("bughouse")},
903 { VariantBerolina, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("berolina")},
904 { VariantShogi, 1, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("shogi (9x9)")},
905 { VariantCylinder, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("cylinder")},
906 { VariantXiangqi, 1, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("xiangqi (9x10)")},
907 { VariantShatranj, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("shatranj")},
908 { VariantCourier, 1, 135, NULL, (void*) &Pick, "#BFFFBF", NULL, Button, N_("courier (12x8)")},
909 { VariantMakruk, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("makruk")},
910 { VariantGreat, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Great Shatranj (10x8)")},
911 { VariantAtomic, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("atomic")},
912 { VariantCapablanca, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Capablanca (10x8)")},
913 { VariantTwoKings, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("two kings")},
914 { VariantGothic, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Gothic (10x8)")},
915 { Variant3Check, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("3-checks")},
916 { VariantJanus, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("janus (10x8)")},
917 { VariantSuicide, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("suicide")},
918 { VariantCapaRandom, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("CRC (10x8)")},
919 { VariantGiveaway, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("give-away")},
920 { VariantSpartan, 1, 135, NULL, (void*) &Pick, "#FF0000", NULL, Button, N_("Spartan")},
921 { VariantLosers, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("losers")},
922 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Board size ( -1 = default for selected variant):")},
923 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.NrRanks, "", NULL, Spin, N_("Number of Board Ranks:") },
924 { 0, -1, BOARD_FILES, NULL, (void*) &appData.NrFiles, "", NULL, Spin, N_("Number of Board Files:") },
925 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.holdingsSize, "", NULL, Spin, N_("Holdings Size:") },
926 { 0, 0, 0, NULL, NULL, NULL, NULL, Label,
927 N_("WARNING: variants with un-orthodox\n"
928 "pieces only have built-in bitmaps\n"
929 "for -boardSize middling, bulky and\n"
930 "petite, and substitute king or amazon\n"
931 "for missing bitmaps. (See manual.)")},
932 { 0, 2, 0, NULL, NULL, "", NULL, EndMark , "" }
935 void CommonOptionsOK(int n)
937 int newPonder = appData.ponderNextMove;
938 // make sure changes are sent to first engine by re-initializing it
939 // if it was already started pre-emptively at end of previous game
940 if(gameMode == BeginningOfGame) Reset(True, True); else {
941 // Some changed setting need immediate sending always.
942 if(oldCores != appData.smpCores)
943 NewSettingEvent(False, &(first.maxCores), "cores", appData.smpCores);
944 appData.ponderNextMove = oldPonder;
945 PonderNextMoveEvent(newPonder);
949 Option commonEngineOptions[] = {
950 { 0, 0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, N_("Ponder Next Move") },
951 { 0, 0, 1000, NULL, (void*) &appData.smpCores, "", NULL, Spin, N_("Maximum Number of CPUs per Engine:") },
952 { 0, 0, 0, NULL, (void*) &appData.polyglotDir, "", NULL, PathName, N_("Polygot Directory:") },
953 { 0, 0, 16000, NULL, (void*) &appData.defaultHashSize, "", NULL, Spin, N_("Hash-Table Size (MB):") },
954 { 0, 0, 0, NULL, (void*) &appData.defaultPathEGTB, "", NULL, PathName, N_("Nalimov EGTB Path:") },
955 { 0, 0, 1000, NULL, (void*) &appData.defaultCacheSizeEGTB, "", NULL, Spin, N_("EGTB Cache Size (MB):") },
956 { 0, 0, 0, NULL, (void*) &appData.usePolyglotBook, "", NULL, CheckBox, N_("Use GUI Book") },
957 { 0, 0, 0, NULL, (void*) &appData.polyglotBook, ".bin", NULL, FileName, N_("Opening-Book Filename:") },
958 { 0, 0, 100, NULL, (void*) &appData.bookDepth, "", NULL, Spin, N_("Book Depth (moves):") },
959 { 0, 0, 100, NULL, (void*) &appData.bookStrength, "", NULL, Spin, N_("Book Variety (0) vs. Strength (100):") },
960 { 0, 0, 0, NULL, (void*) &appData.firstHasOwnBookUCI, "", NULL, CheckBox, N_("Engine #1 Has Own Book") },
961 { 0, 0, 0, NULL, (void*) &appData.secondHasOwnBookUCI, "", NULL, CheckBox, N_("Engine #2 Has Own Book ") },
962 { 0, 1, 0, NULL, (void*) &CommonOptionsOK, "", NULL, EndMark , "" }
965 Option adjudicationOptions[] = {
966 { 0, 0, 0, NULL, (void*) &appData.checkMates, "", NULL, CheckBox, N_("Detect all Mates") },
967 { 0, 0, 0, NULL, (void*) &appData.testClaims, "", NULL, CheckBox, N_("Verify Engine Result Claims") },
968 { 0, 0, 0, NULL, (void*) &appData.materialDraws, "", NULL, CheckBox, N_("Draw if Insufficient Mating Material") },
969 { 0, 0, 0, NULL, (void*) &appData.trivialDraws, "", NULL, CheckBox, N_("Adjudicate Trivial Draws (3-Move Delay)") },
970 { 0, 0, 100, NULL, (void*) &appData.ruleMoves, "", NULL, Spin, N_("N-Move Rule:") },
971 { 0, 0, 6, NULL, (void*) &appData.drawRepeats, "", NULL, Spin, N_("N-fold Repeats:") },
972 { 0, 0, 1000, NULL, (void*) &appData.adjudicateDrawMoves, "", NULL, Spin, N_("Draw after N Moves Total:") },
973 { 0,-5000, 0, NULL, (void*) &appData.adjudicateLossThreshold, "", NULL, Spin, N_("Win / Loss Threshold:") },
974 { 0, 0, 0, NULL, (void*) &first.scoreIsAbsolute, "", NULL, CheckBox, N_("Negate Score of Engine #1") },
975 { 0, 0, 0, NULL, (void*) &second.scoreIsAbsolute, "", NULL, CheckBox, N_("Negate Score of Engine #2") },
976 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
979 void IcsOptionsOK(int n)
981 ParseIcsTextColors();
984 Option icsOptions[] = {
985 { 0, 0, 0, NULL, (void*) &appData.autoKibitz, "", NULL, CheckBox, N_("Auto-Kibitz") },
986 { 0, 0, 0, NULL, (void*) &appData.autoComment, "", NULL, CheckBox, N_("Auto-Comment") },
987 { 0, 0, 0, NULL, (void*) &appData.autoObserve, "", NULL, CheckBox, N_("Auto-Observe") },
988 { 0, 0, 0, NULL, (void*) &appData.autoRaiseBoard, "", NULL, CheckBox, N_("Auto-Raise Board") },
989 { 0, 0, 0, NULL, (void*) &appData.bgObserve, "", NULL, CheckBox, N_("Background Observe while Playing") },
990 { 0, 0, 0, NULL, (void*) &appData.dualBoard, "", NULL, CheckBox, N_("Dual Board for Background-Observed Game") },
991 { 0, 0, 0, NULL, (void*) &appData.getMoveList, "", NULL, CheckBox, N_("Get Move List") },
992 { 0, 0, 0, NULL, (void*) &appData.quietPlay, "", NULL, CheckBox, N_("Quiet Play") },
993 { 0, 0, 0, NULL, (void*) &appData.seekGraph, "", NULL, CheckBox, N_("Seek Graph") },
994 { 0, 0, 0, NULL, (void*) &appData.autoRefresh, "", NULL, CheckBox, N_("Auto-Refresh Seek Graph") },
995 { 0, 0, 0, NULL, (void*) &appData.premove, "", NULL, CheckBox, N_("Premove") },
996 { 0, 0, 0, NULL, (void*) &appData.premoveWhite, "", NULL, CheckBox, N_("Premove for White") },
997 { 0, 0, 0, NULL, (void*) &appData.premoveWhiteText, "", NULL, TextBox, N_("First White Move:") },
998 { 0, 0, 0, NULL, (void*) &appData.premoveBlack, "", NULL, CheckBox, N_("Premove for Black") },
999 { 0, 0, 0, NULL, (void*) &appData.premoveBlackText, "", NULL, TextBox, N_("First Black Move:") },
1000 { 0, 0, 0, NULL, NULL, NULL, NULL, Break, "" },
1001 { 0, 0, 0, NULL, (void*) &appData.icsAlarm, "", NULL, CheckBox, N_("Alarm") },
1002 { 0, 0, 100000000, NULL, (void*) &appData.icsAlarmTime, "", NULL, Spin, N_("Alarm Time (msec):") },
1003 //{ 0, 0, 0, NULL, (void*) &appData.chatBoxes, "", NULL, TextBox, N_("Startup Chat Boxes:") },
1004 { 0, 0, 0, NULL, (void*) &appData.colorize, "", NULL, CheckBox, N_("Colorize Messages") },
1005 { 0, 0, 0, NULL, (void*) &appData.colorShout, "", NULL, TextBox, N_("Shout Text Colors:") },
1006 { 0, 0, 0, NULL, (void*) &appData.colorSShout, "", NULL, TextBox, N_("S-Shout Text Colors:") },
1007 { 0, 0, 0, NULL, (void*) &appData.colorChannel1, "", NULL, TextBox, N_("Channel #1 Text Colors:") },
1008 { 0, 0, 0, NULL, (void*) &appData.colorChannel, "", NULL, TextBox, N_("Other Channel Text Colors:") },
1009 { 0, 0, 0, NULL, (void*) &appData.colorKibitz, "", NULL, TextBox, N_("Kibitz Text Colors:") },
1010 { 0, 0, 0, NULL, (void*) &appData.colorTell, "", NULL, TextBox, N_("Tell Text Colors:") },
1011 { 0, 0, 0, NULL, (void*) &appData.colorChallenge, "", NULL, TextBox, N_("Challenge Text Colors:") },
1012 { 0, 0, 0, NULL, (void*) &appData.colorRequest, "", NULL, TextBox, N_("Request Text Colors:") },
1013 { 0, 0, 0, NULL, (void*) &appData.colorSeek, "", NULL, TextBox, N_("Seek Text Colors:") },
1014 { 0, 0, 0, NULL, (void*) &IcsOptionsOK, "", NULL, EndMark , "" }
1017 Option loadOptions[] = {
1018 { 0, 0, 0, NULL, (void*) &appData.autoDisplayTags, "", NULL, CheckBox, N_("Auto-Display Tags") },
1019 { 0, 0, 0, NULL, (void*) &appData.autoDisplayComment, "", NULL, CheckBox, N_("Auto-Display Comment") },
1020 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Auto-Play speed of loaded games\n(0 = instant, -1 = off):") },
1021 { 0, -1, 10000000, NULL, (void*) &appData.timeDelay, "", NULL, Fractional, N_("Seconds per Move:") },
1022 { 0, 0, 0, NULL, NULL, "", NULL, EndMark , "" }
1025 Option saveOptions[] = {
1026 { 0, 0, 0, NULL, (void*) &appData.autoSaveGames, "", NULL, CheckBox, N_("Auto-Save Games") },
1027 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, ".pgn", NULL, FileName, N_("Save Games on File:") },
1028 { 0, 0, 0, NULL, (void*) &appData.savePositionFile, ".fen", NULL, FileName, N_("Save Final Positions on File:") },
1029 { 0, 0, 0, NULL, (void*) &appData.pgnEventHeader, "", NULL, TextBox, N_("PGN Event Header:") },
1030 { 0, 0, 0, NULL, (void*) &appData.oldSaveStyle, "", NULL, CheckBox, N_("Old Save Style (as opposed to PGN)") },
1031 { 0, 0, 0, NULL, (void*) &appData.saveExtendedInfoInPGN, "", NULL, CheckBox, N_("Save Score/Depth Info in PGN") },
1032 { 0, 0, 0, NULL, (void*) &appData.saveOutOfBookInfo, "", NULL, CheckBox, N_("Save Out-of-Book Info in PGN ") },
1033 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
1036 char *soundNames[] = {
1039 N_("Above WAV File"),
1054 char *soundFiles[] = { // sound files corresponding to above names
1057 "*", // kludge alert: as first thing in the dialog readout this is replaced with the user-given .WAV filename
1075 if(soundFiles[values[3]]) PlaySound(soundFiles[values[3]]);
1078 Option soundOptions[] = {
1079 { 0, 0, 0, NULL, (void*) &appData.soundProgram, "", NULL, TextBox, N_("Sound Program:") },
1080 { 0, 0, 0, NULL, (void*) &appData.soundDirectory, "", NULL, PathName, N_("Sounds Directory:") },
1081 { 0, 0, 0, NULL, (void*) (soundFiles+2) /* kludge! */, ".wav", NULL, FileName, N_("User WAV File:") },
1082 { 0, 0, 0, NULL, (void*) &trialSound, (char*) soundNames, soundFiles, ComboBox, N_("Try-Out Sound:") },
1083 { 0, 1, 0, NULL, (void*) &Test, NULL, NULL, Button, N_("Play") },
1084 { 0, 0, 0, NULL, (void*) &appData.soundMove, (char*) soundNames, soundFiles, ComboBox, N_("Move:") },
1085 { 0, 0, 0, NULL, (void*) &appData.soundIcsWin, (char*) soundNames, soundFiles, ComboBox, N_("Win:") },
1086 { 0, 0, 0, NULL, (void*) &appData.soundIcsLoss, (char*) soundNames, soundFiles, ComboBox, N_("Lose:") },
1087 { 0, 0, 0, NULL, (void*) &appData.soundIcsDraw, (char*) soundNames, soundFiles, ComboBox, N_("Draw:") },
1088 { 0, 0, 0, NULL, (void*) &appData.soundIcsUnfinished, (char*) soundNames, soundFiles, ComboBox, N_("Unfinished:") },
1089 { 0, 0, 0, NULL, (void*) &appData.soundIcsAlarm, (char*) soundNames, soundFiles, ComboBox, N_("Alarm:") },
1090 { 0, 0, 0, NULL, (void*) &appData.soundShout, (char*) soundNames, soundFiles, ComboBox, N_("Shout:") },
1091 { 0, 0, 0, NULL, (void*) &appData.soundSShout, (char*) soundNames, soundFiles, ComboBox, N_("S-Shout:") },
1092 { 0, 0, 0, NULL, (void*) &appData.soundChannel, (char*) soundNames, soundFiles, ComboBox, N_("Channel:") },
1093 { 0, 0, 0, NULL, (void*) &appData.soundChannel1, (char*) soundNames, soundFiles, ComboBox, N_("Channel 1:") },
1094 { 0, 0, 0, NULL, (void*) &appData.soundTell, (char*) soundNames, soundFiles, ComboBox, N_("Tell:") },
1095 { 0, 0, 0, NULL, (void*) &appData.soundKibitz, (char*) soundNames, soundFiles, ComboBox, N_("Kibitz:") },
1096 { 0, 0, 0, NULL, (void*) &appData.soundChallenge, (char*) soundNames, soundFiles, ComboBox, N_("Challenge:") },
1097 { 0, 0, 0, NULL, (void*) &appData.soundRequest, (char*) soundNames, soundFiles, ComboBox, N_("Request:") },
1098 { 0, 0, 0, NULL, (void*) &appData.soundSeek, (char*) soundNames, soundFiles, ComboBox, N_("Seek:") },
1099 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
1102 void SetColor(char *colorName, Widget box)
1106 XrmValue vFrom, vTo;
1107 if (!appData.monoMode) {
1108 vFrom.addr = (caddr_t) colorName;
1109 vFrom.size = strlen(colorName);
1110 XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1111 if (vTo.addr == NULL) {
1112 buttonColor = (Pixel) -1;
1114 buttonColor = *(Pixel *) vTo.addr;
1116 } else buttonColor = (Pixel) 0;
1117 XtSetArg(args[0], XtNbackground, buttonColor);;
1118 XtSetValues(box, args, 1);
1121 void SetColorText(int n, char *buf)
1124 XtSetArg(args[0], XtNstring, buf);
1125 XtSetValues(currentOption[n-1].handle, args, 1);
1126 SetFocus(currentOption[n-1].handle, shells[0], NULL, False);
1127 SetColor(buf, currentOption[n].handle);
1130 void DefColor(int n)
1132 SetColorText(n, (char*) currentOption[n].choice);
1135 void RefreshColor(int source, int n)
1137 int col, j, r, g, b, step = 10;
1138 char *s, buf[MSG_SIZ]; // color string
1140 XtSetArg(args[0], XtNstring, &s);
1141 XtGetValues(currentOption[source].handle, args, 1);
1142 if(sscanf(s, "#%x", &col) != 1) return; // malformed
1143 b = col & 0xFF; g = col & 0xFF00; r = col & 0xFF0000;
1145 case 1: r += 0x10000*step;break;
1146 case 2: g += 0x100*step; break;
1147 case 3: b += step; break;
1148 case 4: r -= 0x10000*step; g -= 0x100*step; b -= step; break;
1150 if(r < 0) r = 0; if(g < 0) g = 0; if(b < 0) b = 0;
1151 if(r > 0xFF0000) r = 0xFF0000; if(g > 0xFF00) g = 0xFF00; if(b > 0xFF) b = 0xFF;
1153 snprintf(buf, MSG_SIZ, "#%06x", col);
1154 for(j=1; j<7; j++) if(buf[j] >= 'a') buf[j] -= 32; // capitalize
1155 SetColorText(source+1, buf);
1158 void ColorChanged(Widget w, XtPointer data, XEvent *event, Boolean *b)
1161 if ( (XLookupString(&(event->xkey), buf, 2, NULL, NULL) == 1) && *buf == '\r' )
1162 RefreshColor((int)(intptr_t) data, 0);
1165 void AdjustColor(int i)
1167 int n = currentOption[i].value;
1168 RefreshColor(i-n-1, n);
1171 void BoardOptionsOK(int n)
1173 if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap;
1174 useImages = useImageSqs = 0;
1175 MakeColors(); CreateGCs(True);
1177 InitDrawingSizes(-1, 0);
1178 DrawPosition(True, NULL);
1181 Option boardOptions[] = {
1182 { 0, 0, 70, NULL, (void*) &appData.whitePieceColor, "", NULL, TextBox, N_("White Piece Color:") },
1183 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#FFFFCC", Button, " " },
1184 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1185 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1186 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1187 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1188 { 0, 0, 70, NULL, (void*) &appData.blackPieceColor, "", NULL, TextBox, N_("Black Piece Color:") },
1189 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#202020", Button, " " },
1190 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1191 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1192 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1193 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1194 { 0, 0, 70, NULL, (void*) &appData.lightSquareColor, "", NULL, TextBox, N_("Light Square Color:") },
1195 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#C8C365", Button, " " },
1196 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1197 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1198 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1199 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1200 { 0, 0, 70, NULL, (void*) &appData.darkSquareColor, "", NULL, TextBox, N_("Dark Square Color:") },
1201 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#77A26D", Button, " " },
1202 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1203 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1204 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1205 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1206 { 0, 0, 70, NULL, (void*) &appData.highlightSquareColor, "", NULL, TextBox, N_("Highlight Color:") },
1207 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#FFFF00", Button, " " },
1208 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1209 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1210 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1211 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1212 { 0, 0, 70, NULL, (void*) &appData.premoveHighlightColor, "", NULL, TextBox, N_("Premove Highlight Color:") },
1213 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#FF0000", Button, " " },
1214 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1215 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1216 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1217 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1218 { 0, 0, 0, NULL, (void*) &appData.upsideDown, "", NULL, CheckBox, N_("Flip Pieces Shogi Style (Colored buttons restore default)") },
1219 //{ 0, 0, 0, NULL, (void*) &appData.allWhite, "", NULL, CheckBox, N_("Use Outline Pieces for Black") },
1220 { 0, 0, 0, NULL, (void*) &appData.monoMode, "", NULL, CheckBox, N_("Mono Mode") },
1221 { 0,-1, 5, NULL, (void*) &appData.overrideLineGap, "", NULL, Spin, N_("Line Gap ( -1 = default for board size):") },
1222 { 0, 0, 0, NULL, (void*) &appData.liteBackTextureFile, ".xpm", NULL, FileName, N_("Light-Squares Texture File:") },
1223 { 0, 0, 0, NULL, (void*) &appData.darkBackTextureFile, ".xpm", NULL, FileName, N_("Dark-Squares Texture File:") },
1224 { 0, 0, 0, NULL, (void*) &appData.bitmapDirectory, "", NULL, PathName, N_("Directory with Bitmap Pieces:") },
1225 { 0, 0, 0, NULL, (void*) &appData.pixmapDirectory, "", NULL, PathName, N_("Directory with Pixmap Pieces:") },
1226 { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" }
1229 void GenericReadout(int selected)
1234 char buf[MSG_SIZ], **dest;
1236 for(i=0; ; i++) { // send all options that had to be OK-ed to engine
1237 if(selected >= 0) { if(i < selected) continue; else if(i > selected) break; }
1238 switch(currentOption[i].type) {
1242 XtSetArg(args[0], XtNstring, &val);
1243 XtGetValues(currentOption[i].handle, args, 1);
1244 dest = currentCps ? &(currentOption[i].textValue) : (char**) currentOption[i].target;
1245 if(*dest == NULL || strcmp(*dest, val)) {
1247 snprintf(buf, MSG_SIZ, "option %s=%s\n", currentOption[i].name, val);
1248 SendToProgram(buf, currentCps);
1250 if(*dest) free(*dest);
1251 *dest = malloc(strlen(val)+1);
1253 safeStrCpy(*dest, val, MSG_SIZ - (*dest - currentOption[i].name)); // copy text there
1258 XtSetArg(args[0], XtNstring, &val);
1259 XtGetValues(currentOption[i].handle, args, 1);
1260 sscanf(val, "%f", &x);
1261 if(x > currentOption[i].max) x = currentOption[i].max;
1262 if(x < currentOption[i].min) x = currentOption[i].min;
1263 if(currentOption[i].type == Fractional)
1264 *(float*) currentOption[i].target = x; // engines never have float options!
1265 else if(currentOption[i].value != x) {
1266 currentOption[i].value = x;
1268 snprintf(buf, MSG_SIZ, "option %s=%.0f\n", currentOption[i].name, x);
1269 SendToProgram(buf, currentCps);
1270 } else *(int*) currentOption[i].target = x;
1275 XtSetArg(args[0], XtNstate, &j);
1276 XtGetValues(currentOption[i].handle, args, 1);
1277 if(currentOption[i].value != j) {
1278 currentOption[i].value = j;
1280 snprintf(buf, MSG_SIZ, "option %s=%d\n", currentOption[i].name, j);
1281 SendToProgram(buf, currentCps);
1282 } else *(Boolean*) currentOption[i].target = j;
1286 val = ((char**)currentOption[i].choice)[values[i]];
1288 if(currentOption[i].value == values[i]) break; // not changed
1289 currentOption[i].value = values[i];
1290 snprintf(buf, MSG_SIZ, "option %s=%s\n", currentOption[i].name,
1291 ((char**)currentOption[i].textValue)[values[i]]);
1292 SendToProgram(buf, currentCps);
1293 } else if(val && (*(char**) currentOption[i].target == NULL || strcmp(*(char**) currentOption[i].target, val))) {
1294 if(*(char**) currentOption[i].target) free(*(char**) currentOption[i].target);
1295 *(char**) currentOption[i].target = strdup(val);
1299 if(currentOption[i].target) // callback for implementing necessary actions on OK (like redraw)
1300 ((ButtonCallback*) currentOption[i].target)(i);
1303 printf("GenericReadout: unexpected case in switch.\n");
1310 if(currentOption[i].type == EndMark) break;
1314 void GenericCallback(w, client_data, call_data)
1316 XtPointer client_data, call_data;
1321 int data = (intptr_t) client_data;
1323 currentOption = dialogOptions[data>>16]; data &= 0xFFFF;
1325 XtSetArg(args[0], XtNlabel, &name);
1326 XtGetValues(w, args, 1);
1328 if (strcmp(name, _("cancel")) == 0) {
1332 if (strcmp(name, _("OK")) == 0) { // save buttons imply OK
1338 if(currentOption[data].type == SaveButton) GenericReadout(-1);
1339 snprintf(buf, MSG_SIZ, "option %s\n", name);
1340 SendToProgram(buf, currentCps);
1341 } else ((ButtonCallback*) currentOption[data].target)(data);
1344 static char *oneLiner = "<Key>Return: redraw-display()\n";
1347 GenericPopUp(Option *option, char *title, int dlgNr)
1350 Widget popup, layout, dialog=NULL, edit=NULL, form, last, b_ok, b_cancel, leftMargin = NULL, textField = NULL;
1352 int x, y, i, j, height=999, width=1, h, c, w;
1353 int win_x, win_y, maxWidth, maxTextWidth;
1355 char def[MSG_SIZ], *msg;
1356 static char pane[6] = "paneX";
1357 Widget texts[100], forelast = NULL, anchor, widest, lastrow = NULL;
1359 if(shellUp[dlgNr]) return 0; // already up
1360 if(dlgNr && shells[dlgNr]) {
1361 XtPopup(shells[dlgNr], XtGrabNone);
1362 shellUp[dlgNr] = True;
1366 dialogOptions[dlgNr] = option; // make available to callback
1367 // post currentOption globally, so Spin and Combo callbacks can already use it
1368 // WARNING: this kludge does not work for persistent dialogs, so that these cannot have spin or combo controls!
1369 currentOption = option;
1371 if(currentCps) { // Settings popup for engine: format through heuristic
1372 int n = currentCps->nrOptions;
1373 if(!n) { DisplayNote(_("Engine has no options")); return 0; }
1374 if(n > 50) width = 4; else if(n>24) width = 2; else width = 1;
1375 height = n / width + 1;
1376 if(n && (currentOption[n-1].type == Button || currentOption[n-1].type == SaveButton)) currentOption[n].min = 1; // OK on same line
1377 currentOption[n].type = EndMark; currentOption[n].target = NULL; // delimit list by callback-less end mark
1380 XtSetArg(args[i], XtNresizable, True); i++;
1381 popup = shells[dlgNr] =
1382 XtCreatePopupShell(title, transientShellWidgetClass,
1383 shellWidget, args, i);
1386 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1387 layoutArgs, XtNumber(layoutArgs));
1388 for(c=0; c<width; c++) {
1391 XtCreateManagedWidget(pane, formWidgetClass, layout,
1392 formArgs, XtNumber(formArgs));
1394 XtSetArg(args[j], XtNfromHoriz, leftMargin); j++;
1395 XtSetValues(form, args, j);
1398 last = widest = NULL; anchor = lastrow;
1399 for(h=0; h<height; h++) {
1401 if(option[i].type == EndMark) break;
1404 switch(option[i].type) {
1406 snprintf(def, MSG_SIZ, "%.2f", *(float*)option[i].target);
1407 option[i].value = *(float*)option[i].target;
1410 if(!currentCps) option[i].value = *(int*)option[i].target;
1411 snprintf(def, MSG_SIZ, "%d", option[i].value);
1416 if(option[i].name[0]) {
1418 XtSetArg(args[j], XtNfromVert, last); j++;
1419 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1420 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1421 XtSetArg(args[j], XtNborderWidth, 0); j++;
1422 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1423 XtSetArg(args[j], XtNlabel, _(option[i].name)); j++;
1425 dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
1426 } else texts[h] = dialog = NULL;
1427 w = option[i].type == Spin || option[i].type == Fractional ? 70 : option[i].max ? option[i].max : 205;
1428 if(option[i].type == FileName || option[i].type == PathName) w -= 55;
1430 XtSetArg(args[j], XtNfromVert, last); j++;
1431 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1432 XtSetArg(args[j], XtNborderWidth, 1); j++;
1433 XtSetArg(args[j], XtNwidth, w); j++;
1434 if(option[i].type == TextBox && option[i].min) {
1435 XtSetArg(args[j], XtNheight, option[i].min); j++;
1436 if(option[i].value & 1) { XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++; }
1437 if(option[i].value & 2) { XtSetArg(args[j], XtNscrollHorizontal, XawtextScrollAlways); j++; }
1438 if(option[i].value & 4) { XtSetArg(args[j], XtNautoFill, True); j++; }
1439 if(option[i].value & 8) { XtSetArg(args[j], XtNwrap, XawtextWrapWord); j++; }
1441 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1442 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1443 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1444 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1445 XtSetArg(args[j], XtNright, XtChainRight); j++;
1446 XtSetArg(args[j], XtNresizable, True); j++;
1447 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
1448 XtSetArg(args[j], XtNstring, option[i].type==Spin || option[i].type==Fractional ? def :
1449 currentCps ? option[i].textValue : *(char**)option[i].target); j++;
1451 option[i].handle = (void*)
1452 (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1453 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1454 if(option[i].min == 0 || option[i].type != TextBox)
1455 XtOverrideTranslations(last, XtParseTranslationTable(oneLiner));
1457 if(option[i].type == TextBox || option[i].type == Fractional) break;
1459 // add increment and decrement controls for spin
1461 XtSetArg(args[j], XtNfromVert, edit); j++;
1462 XtSetArg(args[j], XtNfromHoriz, last); j++;
1463 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1464 XtSetArg(args[j], XtNright, XtChainRight); j++;
1465 if(option[i].type == FileName || option[i].type == PathName) {
1466 w = 50; msg = _("browse");
1468 XtSetArg(args[j], XtNheight, 10); j++;
1471 XtSetArg(args[j], XtNwidth, w); j++;
1472 edit = XtCreateManagedWidget(msg, commandWidgetClass, form, args, j);
1473 XtAddCallback(edit, XtNcallback, SpinCallback, (XtPointer)(intptr_t) i);
1475 if(option[i].type != Spin) break;
1478 XtSetArg(args[j], XtNfromVert, edit); j++;
1479 XtSetArg(args[j], XtNfromHoriz, last); j++;
1480 XtSetArg(args[j], XtNheight, 10); j++;
1481 XtSetArg(args[j], XtNwidth, 20); j++;
1482 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1483 XtSetArg(args[j], XtNright, XtChainRight); j++;
1484 last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1485 XtAddCallback(last, XtNcallback, SpinCallback, (XtPointer)(intptr_t) i);
1488 if(!currentCps) option[i].value = *(Boolean*)option[i].target;
1490 XtSetArg(args[j], XtNfromVert, last); j++;
1491 XtSetArg(args[j], XtNwidth, 10); j++;
1492 XtSetArg(args[j], XtNheight, 10); j++;
1493 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1494 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1495 XtSetArg(args[j], XtNstate, option[i].value); j++;
1496 option[i].handle = (void*)
1497 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1499 msg = option[i].name;
1500 if(*msg == NULLCHAR) msg = option[i].textValue;
1503 XtSetArg(args[j], XtNfromVert, last); j++;
1504 XtSetArg(args[j], XtNfromHoriz, option[i].type != Label ? dialog : NULL); j++;
1505 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1506 XtSetArg(args[j], XtNborderWidth, 0); j++;
1507 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1508 XtSetArg(args[j], XtNlabel, _(msg)); j++;
1509 last = XtCreateManagedWidget(msg, labelWidgetClass, form, args, j);
1510 if(option[i].type == CheckBox)
1511 XtAddEventHandler(last, ButtonPressMask, False, CheckCallback, (XtPointer)(intptr_t) i);
1516 XtSetArg(args[j], XtNfromVert, option[i].min & 1 ? lastrow : last); j++;
1517 XtSetArg(args[j], XtNlabel, _(option[i].name)); j++;
1518 if(option[i].min & 1) { XtSetArg(args[j], XtNfromHoriz, last); j++; }
1519 else { XtSetArg(args[j], XtNfromHoriz, NULL); j++; lastrow = forelast; }
1520 if(option[i].max) XtSetArg(args[j], XtNwidth, option[i].max); j++;
1521 if(option[i].textValue) { // special for buttons of New Variant dialog
1522 XtSetArg(args[j], XtNsensitive, appData.noChessProgram || option[i].value < 0
1523 || strstr(first.variants, VariantName(option[i].value))); j++;
1524 XtSetArg(args[j], XtNborderWidth, (gameInfo.variant == option[i].value)+1); j++;
1526 option[i].handle = (void*)
1527 (dialog = last = XtCreateManagedWidget(option[i].name, commandWidgetClass, form, args, j));
1528 if(option[i].choice && ((char*)option[i].choice)[0] == '#' && !currentCps) {
1529 SetColor( *(char**) option[i-1].target, last);
1530 XtAddEventHandler(option[i-1].handle, KeyReleaseMask, False, ColorChanged, (XtPointer)(intptr_t) i-1);
1532 XtAddCallback(last, XtNcallback, GenericCallback,
1533 (XtPointer)(intptr_t) i + (dlgNr<<16));
1534 if(option[i].textValue) SetColor( option[i].textValue, last);
1535 forelast = lastrow; // next button can go on same row
1539 XtSetArg(args[j], XtNfromVert, last); j++;
1540 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1541 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1542 XtSetArg(args[j], XtNborderWidth, 0); j++;
1543 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1544 XtSetArg(args[j], XtNlabel, _(option[i].name)); j++;
1545 texts[h] = dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
1547 if(currentCps) option[i].choice = (char**) option[i].textValue; else {
1548 for(j=0; option[i].choice[j]; j++)
1549 if(*(char**)option[i].target && !strcmp(*(char**)option[i].target, option[i].choice[j])) break;
1550 option[i].value = j + (option[i].choice[j] == NULL);
1554 XtSetArg(args[j], XtNfromVert, last); j++;
1555 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1556 XtSetArg(args[j], XtNwidth, option[i].max && !currentCps ? option[i].max : 100); j++;
1557 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1558 XtSetArg(args[j], XtNmenuName, XtNewString(option[i].name)); j++;
1559 XtSetArg(args[j], XtNlabel, _(((char**)option[i].textValue)[option[i].value])); j++;
1560 option[i].handle = (void*)
1561 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1562 CreateComboPopup(last, option[i].name, i, (char **) option[i].textValue);
1563 values[i] = option[i].value;
1570 printf("GenericPopUp: unexpected case in switch.\n");
1575 // make an attempt to align all spins and textbox controls
1576 maxWidth = maxTextWidth = 0;
1577 for(h=0; h<height; h++) {
1579 if(option[i].type == EndMark) break;
1580 if(option[i].type == Spin || option[i].type == TextBox || option[i].type == ComboBox
1581 || option[i].type == PathName || option[i].type == FileName) {
1583 if(!texts[h]) continue;
1585 XtSetArg(args[j], XtNwidth, &w); j++;
1586 XtGetValues(texts[h], args, j);
1587 if(option[i].type == Spin) {
1588 if(w > maxWidth) maxWidth = w;
1591 if(w > maxTextWidth) maxTextWidth = w;
1592 if(!widest) widest = texts[h];
1596 if(maxTextWidth + 110 < maxWidth)
1597 maxTextWidth = maxWidth - 110;
1598 else maxWidth = maxTextWidth + 110;
1599 for(h=0; h<height; h++) {
1601 if(option[i].type == EndMark) break;
1602 if(!texts[h]) continue;
1604 if(option[i].type == Spin) {
1605 XtSetArg(args[j], XtNwidth, maxWidth); j++;
1606 XtSetValues(texts[h], args, j);
1608 if(option[i].type == TextBox || option[i].type == ComboBox || option[i].type == PathName || option[i].type == FileName) {
1609 XtSetArg(args[j], XtNwidth, maxTextWidth); j++;
1610 XtSetValues(texts[h], args, j);
1615 if(!(option[i].min & 2)) {
1617 if(option[i].min & 1) {
1618 for(j=i-1; option[j+1].min&1 && option[j].type == Button; j--) {
1619 XtSetArg(args[0], XtNtop, XtChainBottom);
1620 XtSetArg(args[1], XtNbottom, XtChainBottom);
1621 XtSetValues(option[j].handle, args, 2);
1623 if(option[j].type == TextBox && option[j].name[0] == NULLCHAR) {
1624 XtSetArg(args[0], XtNbottom, XtChainBottom);
1625 XtSetValues(option[j].handle, args, 1);
1628 XtSetArg(args[j], XtNfromHoriz, last); last = forelast;
1630 XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog); j++;
1631 XtSetArg(args[j], XtNfromVert, anchor ? anchor : last); j++;
1632 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1633 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1634 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1635 XtSetArg(args[j], XtNright, XtChainRight); j++;
1636 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1637 XtAddCallback(b_ok, XtNcallback, GenericCallback, (XtPointer)(intptr_t) dlgNr + (dlgNr<<16));
1639 XtSetArg(args[0], XtNfromHoriz, b_ok);
1640 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1641 XtAddCallback(b_cancel, XtNcallback, GenericCallback, (XtPointer)(intptr_t) dlgNr);
1644 XtRealizeWidget(popup);
1645 XSetWMProtocols(xDisplay, XtWindow(popup), &wm_delete_window, 1);
1646 snprintf(def, MSG_SIZ, "<Message>WM_PROTOCOLS: GenericPopDown(\"%d\") \n", dlgNr);
1647 XtAugmentTranslations(popup, XtParseTranslationTable(def));
1648 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1649 &x, &y, &win_x, &win_y, &mask);
1651 XtSetArg(args[0], XtNx, x - 10);
1652 XtSetArg(args[1], XtNy, y - 30);
1653 XtSetValues(popup, args, 2);
1655 XtPopup(popup, dlgNr ? XtGrabNone : XtGrabExclusive);
1656 shellUp[dlgNr] = True;
1658 if(textField)SetFocus(textField, popup, (XEvent*) NULL, False);
1659 if(dlgNr && wp[dlgNr] && wp[dlgNr]->width > 0) { // if persistent window-info available, reposition
1661 XtSetArg(args[j], XtNheight, (Dimension) (wp[dlgNr]->height)); j++;
1662 XtSetArg(args[j], XtNwidth, (Dimension) (wp[dlgNr]->width)); j++;
1663 XtSetArg(args[j], XtNx, (Position) (wp[dlgNr]->x)); j++;
1664 XtSetArg(args[j], XtNy, (Position) (wp[dlgNr]->y)); j++;
1665 XtSetValues(popup, args, j);
1671 void IcsOptionsProc(w, event, prms, nprms)
1677 GenericPopUp(icsOptions, _("ICS Options"), 0);
1680 void LoadOptionsProc(w, event, prms, nprms)
1686 GenericPopUp(loadOptions, _("Load Game Options"), 0);
1689 void SaveOptionsProc(w, event, prms, nprms)
1695 GenericPopUp(saveOptions, _("Save Game Options"), 0);
1698 void SoundOptionsProc(w, event, prms, nprms)
1704 soundFiles[2] = "*";
1705 GenericPopUp(soundOptions, _("Sound Options"), 0);
1708 void BoardOptionsProc(w, event, prms, nprms)
1714 GenericPopUp(boardOptions, _("Board Options"), 0);
1717 void EngineMenuProc(w, event, prms, nprms)
1723 GenericPopUp(adjudicationOptions, "Adjudicate non-ICS Games", 0);
1726 void UciMenuProc(w, event, prms, nprms)
1732 oldCores = appData.smpCores;
1733 oldPonder = appData.ponderNextMove;
1734 GenericPopUp(commonEngineOptions, _("Common Engine Settings"), 0);
1737 void NewVariantProc(w, event, prms, nprms)
1743 GenericPopUp(variantDescriptors, _("New Variant"), 0);
1746 void OptionsProc(w, event, prms, nprms)
1752 oldPonder = appData.ponderNextMove;
1753 GenericPopUp(generalOptions, _("General Options"), 0);
1756 void MatchOptionsProc(w, event, prms, nprms)
1762 NamesToList(firstChessProgramNames, engineList, engineMnemonic);
1763 comboCallback = &AddToTourney;
1764 GenericPopUp(matchOptions, _("Match Options"), 0);
1767 Option textOptions[100];
1768 void PutText P((char *text, int pos));
1770 void SendString(char *p)
1772 char buf[MSG_SIZ], *q;
1773 if(q = strstr(p, "$input")) {
1774 if(!shellUp[4]) return;
1775 strncpy(buf, p, MSG_SIZ);
1776 strncpy(buf + (q-p), q+6, MSG_SIZ-(q-p));
1780 snprintf(buf, MSG_SIZ, "%s\n", p);
1784 /* function called when the data to Paste is ready */
1786 SendTextCB(Widget w, XtPointer client_data, Atom *selection,
1787 Atom *type, XtPointer value, unsigned long *len, int *format)
1789 char buf[MSG_SIZ], *p = (char*) textOptions[(int)(intptr_t) client_data].choice, *name = (char*) value, *q;
1790 if (value==NULL || *len==0) return; /* nothing selected, abort */
1792 strncpy(buf, p, MSG_SIZ);
1793 q = strstr(p, "$name");
1794 snprintf(buf + (q-p), MSG_SIZ -(q-p), "%s%s", name, q+5);
1799 void SendText(int n)
1801 char *p = (char*) textOptions[n].choice;
1802 if(strstr(p, "$name")) {
1803 XtGetSelectionValue(menuBarWidget,
1804 XA_PRIMARY, XA_STRING,
1805 /* (XtSelectionCallbackProc) */ SendTextCB,
1806 (XtPointer) (intptr_t) n, /* client_data passed to PastePositionCB */
1809 } else SendString(p);
1812 void IcsTextProc(w, event, prms, nprms)
1820 if((p = icsTextMenuString) == NULL) return;
1822 q = r = p; while(*p && *p != ';') p++;
1823 for(j=0; j<p-q; j++) textOptions[i].name[j] = *r++;
1824 textOptions[i].name[j++] = 0;
1826 if(*++p == '\n') p++; // optional linefeed after button-text terminating semicolon
1828 textOptions[i].choice = (char**) (r = textOptions[i].name + j);
1829 while(*p && (*p != ';' || p[1] != '\n')) textOptions[i].name[j++] = *p++;
1830 textOptions[i].name[j++] = 0;
1832 textOptions[i].max = 135;
1833 textOptions[i].min = i&1;
1834 textOptions[i].handle = NULL;
1835 textOptions[i].target = &SendText;
1836 textOptions[i].textValue = strstr(r, "$input") ? "#80FF80" : strstr(r, "$name") ? "#FF8080" : "#FFFFFF";
1837 textOptions[i].type = Button;
1838 } while(++i < 99 && *p);
1840 textOptions[i].type = EndMark;
1841 textOptions[i].target = NULL;
1842 textOptions[i].min = 2;
1843 MarkMenu("menuView.ICStex", 3);
1844 GenericPopUp(textOptions, _("ICS text menu"), 3);
1847 static char *commentText;
1848 static int commentIndex;
1849 void ClearComment P((int n));
1850 extern char commentTranslations[];
1852 void NewComCallback(int n)
1854 ReplaceComment(commentIndex, commentText);
1857 void SaveChanges(int n)
1860 XtSetArg(args[0], XtNstring, &commentText);
1861 XtGetValues(currentOption[0].handle, args, 1);
1862 ReplaceComment(commentIndex, commentText);
1865 Option commentOptions[] = {
1866 { 0xD, 200, 250, NULL, (void*) &commentText, "", NULL, TextBox, "" },
1867 { 0, 0, 50, NULL, (void*) &ClearComment, NULL, NULL, Button, "clear" },
1868 { 0, 1, 100, NULL, (void*) &SaveChanges, NULL, NULL, Button, "save changes" },
1869 { 0, 1, 0, NULL, (void*) &NewComCallback, "", NULL, EndMark , "" }
1872 void ClearComment(int n)
1874 XtCallActionProc(commentOptions[0].handle, "select-all", NULL, NULL, 0);
1875 XtCallActionProc(commentOptions[0].handle, "kill-selection", NULL, NULL, 0);
1878 void NewCommentPopup(char *title, char *text, int index)
1883 if(shells[1]) { // if already exists, alter title and content
1884 XtSetArg(args[0], XtNtitle, title);
1885 XtSetValues(shells[1], args, 1);
1886 XtSetArg(args[0], XtNstring, text);
1887 XtSetValues(commentOptions[0].handle, args, 1);
1889 if(commentText) free(commentText); commentText = strdup(text);
1890 commentIndex = index;
1891 MarkMenu("menuView.Show Comments", 1);
1892 if(GenericPopUp(commentOptions, title, 1))
1893 XtOverrideTranslations(commentOptions[0].handle, XtParseTranslationTable(commentTranslations));
1896 static char *tagsText, *msgText;
1898 void NewTagsCallback(int n)
1900 ReplaceTags(tagsText, &gameInfo);
1903 void changeTags(int n)
1906 XtSetArg(args[0], XtNstring, &tagsText);
1907 XtGetValues(currentOption[1].handle, args, 1);
1908 ReplaceTags(tagsText, &gameInfo);
1911 Option tagsOptions[] = {
1912 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, "" },
1913 { 0xD, 200, 200, NULL, (void*) &tagsText, "", NULL, TextBox, "" },
1914 { 0, 0, 100, NULL, (void*) &changeTags, NULL, NULL, Button, "save changes" },
1915 { 0, 1, 0, NULL, (void*) &NewTagsCallback, "", NULL, EndMark , "" }
1918 void NewTagsPopup(char *text, char *msg)
1923 if(shells[2]) { // if already exists, alter title and content
1924 XtSetArg(args[0], XtNstring, text);
1925 XtSetValues(tagsOptions[1].handle, args, 1);
1927 if(tagsText) free(tagsText); tagsText = strdup(text);
1928 tagsOptions[0].textValue = msg;
1929 MarkMenu("menuView.Show Tags", 2);
1930 GenericPopUp(tagsOptions, _("Tags"), 2);
1935 Option boxOptions[] = {
1936 { 0, 30, 400, NULL, (void*) &icsText, "", NULL, TextBox, "" },
1937 { 0, 3, 0, NULL, NULL, "", NULL, EndMark , "" }
1940 void PutText(char *text, int pos)
1943 char buf[MSG_SIZ], *p;
1945 if(strstr(text, "$add ") == text) {
1946 XtSetArg(args[0], XtNstring, &p);
1947 XtGetValues(boxOptions[0].handle, args, 1);
1948 snprintf(buf, MSG_SIZ, "%s%s", p, text+5); text = buf;
1949 pos += strlen(p) - 5;
1951 XtSetArg(args[0], XtNstring, text);
1952 XtSetValues(boxOptions[0].handle, args, 1);
1953 XtSetArg(args[0], XtNinsertPosition, pos);
1954 XtSetValues(boxOptions[0].handle, args, 1);
1955 // SetFocus(boxOptions[0].handle, shells[4], NULL, False); // No idea why this does not work, and the following is needed:
1956 XSetInputFocus(xDisplay, XtWindow(boxOptions[0].handle), RevertToPointerRoot, CurrentTime);
1959 void InputBoxPopup()
1961 MarkMenu("menuView.ICS Input Box", 4);
1962 if(GenericPopUp(boxOptions, _("ICS input box"), 4))
1963 XtOverrideTranslations(boxOptions[0].handle, XtParseTranslationTable(ICSInputTranslations));
1966 void TypeInProc(w, event, prms, nprms)
1975 if(prms[0][0] == '1') {
1976 XtSetArg(args[0], XtNstring, &val);
1977 XtGetValues(boxOptions[0].handle, args, 1);
1978 TypeInDoneEvent((char*)val);
1983 char moveTypeInTranslations[] =
1984 "<Key>Return: TypeInProc(1) \n"
1985 "<Key>Escape: TypeInProc(0) \n";
1987 void PopUpMoveDialog(char firstchar)
1990 buf[0] = firstchar; icsText = buf;
1991 if(GenericPopUp(boxOptions, _("Type a move"), 0))
1992 XtOverrideTranslations(boxOptions[0].handle, XtParseTranslationTable(moveTypeInTranslations));
1995 void MoveTypeInProc(Widget widget, caddr_t unused, XEvent *event)
1997 char buf[10], keys[32];
1999 KeyCode metaL, metaR;
2000 int n = XLookupString(&(event->xkey), buf, 10, &sym, NULL);
2001 XQueryKeymap(xDisplay,keys);
2002 metaL = XKeysymToKeycode(xDisplay, XK_Meta_L);
2003 metaR = XKeysymToKeycode(xDisplay, XK_Meta_R);
2004 if ( n == 1 && *buf > 32 && !(keys[metaL>>3]&1<<(metaL&7)) && !(keys[metaR>>3]&1<<(metaR&7))) // printable, no alt
2005 PopUpMoveDialog(*buf);
2010 SettingsPopUp(ChessProgramState *cps)
2013 GenericPopUp(cps->option, _("Engine Settings"), 0);
2016 void FirstSettingsProc(w, event, prms, nprms)
2022 SettingsPopUp(&first);
2025 void SecondSettingsProc(w, event, prms, nprms)
2031 if(WaitForEngine(&second, SettingsMenuIfReady)) return;
2032 SettingsPopUp(&second);
2035 void InstallOK(int n)
2037 PopDown(0); // early popdown, to allow FreezeUI to instate grab
2038 if(engineChoice[0] == engineNr[0][0]) Load(&first, 0); else Load(&second, 1);
2041 Option installOptions[] = {
2042 { 0, 0, 0, NULL, (void*) &engineLine, (char*) engineMnemonic, engineList, ComboBox, N_("Select engine from list:") },
2043 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("or specify one below:") },
2044 { 0, 0, 0, NULL, (void*) &nickName, NULL, NULL, TextBox, N_("Nickname (optional):") },
2045 { 0, 0, 0, NULL, (void*) &useNick, NULL, NULL, CheckBox, N_("Use nickname in PGN player tags of engine-engine games") },
2046 { 0, 0, 0, NULL, (void*) &engineDir, NULL, NULL, PathName, N_("Engine Directory:") },
2047 { 0, 0, 0, NULL, (void*) &engineName, NULL, NULL, FileName, N_("Engine Command:") },
2048 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("(Directory will be derived from engine path when empty)") },
2049 { 0, 0, 0, NULL, (void*) &isUCI, NULL, NULL, CheckBox, N_("UCI") },
2050 { 0, 0, 0, NULL, (void*) &v1, NULL, NULL, CheckBox, N_("WB protocol v1 (do not wait for engine features)") },
2051 { 0, 0, 0, NULL, (void*) &hasBook, NULL, NULL, CheckBox, N_("Must not use GUI book") },
2052 { 0, 0, 0, NULL, (void*) &addToList, NULL, NULL, CheckBox, N_("Add this engine to the list") },
2053 { 0, 0, 0, NULL, (void*) &storeVariant, NULL, NULL, CheckBox, N_("Force current variant with this engine") },
2054 { 0, 0, 0, NULL, (void*) &engineChoice, (char*) engineNr, engineNr, ComboBox, N_("Load mentioned engine as") },
2055 { 0, 1, 0, NULL, (void*) &InstallOK, "", NULL, EndMark , "" }
2058 void LoadEngineProc(w, event, prms, nprms)
2064 isUCI = addToList = storeVariant = v1 = useNick = False; hasBook = True; // defaults
2065 if(engineChoice) free(engineChoice); engineChoice = strdup(engineNr[0]);
2066 if(engineLine) free(engineLine); engineLine = strdup("");
2067 if(engineDir) free(engineDir); engineDir = strdup("");
2068 if(nickName) free(nickName); nickName = strdup("");
2069 if(params) free(params); params = strdup("");
2070 NamesToList(firstChessProgramNames, engineList, engineMnemonic);
2071 GenericPopUp(installOptions, _("Load engine"), 0);
2074 //---------------------------- Chat Windows ----------------------------------------------
2076 void OutputChatMessage(int partner, char *mess)