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));
83 FILE * XsraSelFile P((Widget w, char *prompt, char *ok, char *cancel, char *failed,
84 char *init_path, char *mode, int (*show_entry)(), char **name_return));
86 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
87 extern Display *xDisplay;
88 extern int squareSize;
89 extern Pixmap xMarkPixmap;
90 extern char *layoutName;
91 extern Window xBoardWindow;
92 extern Arg layoutArgs[2], formArgs[2];
93 Pixel timerForegroundPixel, timerBackgroundPixel;
94 extern int searchTime;
95 extern Atom wm_delete_window;
98 // [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines
100 static Widget previous = NULL;
102 void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
108 XtSetArg(args[0], XtNdisplayCaret, False);
109 XtSetValues(previous, args, 1);
111 XtSetArg(args[0], XtNstring, &s);
112 XtGetValues(w, args, 1);
113 XtSetArg(args[0], XtNdisplayCaret, True);
114 XtSetArg(args[1], XtNinsertPosition, strlen(s));
115 XtSetValues(w, args, 2);
116 XtSetKeyboardFocus((Widget) data, w);
120 //--------------------------- New Shuffle Game --------------------------------------------
121 extern int shuffleOpenings;
122 extern int startedFromPositionFile;
126 void ShufflePopDown()
128 if (!shuffleUp) return;
129 XtPopdown(shuffleShell);
130 XtDestroyWidget(shuffleShell);
135 void ShuffleCallback(w, client_data, call_data)
137 XtPointer client_data, call_data;
144 XtSetArg(args[0], XtNlabel, &name);
145 XtGetValues(w, args, 1);
147 if (strcmp(name, _("cancel")) == 0) {
151 if (strcmp(name, _("off")) == 0) {
153 shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it!
157 if (strcmp(name, _("random")) == 0) {
158 snprintf(buf, MSG_SIZ, "%d", rand());
159 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
160 XtSetValues(XtParent(w), args, 1);
163 if (strcmp(name, _("ok")) == 0) {
165 name = XawDialogGetValueString(w2 = XtParent(w));
166 if(sscanf(name ,"%d",&nr) != 1) {
167 snprintf(buf, MSG_SIZ, "%d", appData.defaultFrcPosition);
168 XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
169 XtSetValues(w2, args, 1);
172 appData.defaultFrcPosition = nr;
173 shuffleOpenings = True;
183 Widget popup, layout, dialog, edit;
191 XtSetArg(args[i], XtNresizable, True); i++;
192 XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
193 shuffleShell = popup =
194 XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass,
195 shellWidget, args, i);
198 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
199 layoutArgs, XtNumber(layoutArgs));
201 snprintf(def, MSG_SIZ, "%d\n", appData.defaultFrcPosition);
203 XtSetArg(args[i], XtNlabel, _("Start-position number:")); i++;
204 XtSetArg(args[i], XtNvalue, def); i++;
205 XtSetArg(args[i], XtNborderWidth, 0); i++;
206 dialog = XtCreateManagedWidget(_("Shuffle"), dialogWidgetClass,
209 // XtSetArg(args[0], XtNeditType, XawtextEdit); // [HGM] can't get edit to work decently
210 // XtSetArg(args[1], XtNuseStringInPlace, False);
211 // XtSetValues(dialog, args, 2);
213 XawDialogAddButton(dialog, _("ok"), ShuffleCallback, (XtPointer) dialog);
214 XawDialogAddButton(dialog, _("cancel"), ShuffleCallback, (XtPointer) dialog);
215 XawDialogAddButton(dialog, _("random"), ShuffleCallback, (XtPointer) dialog);
216 XawDialogAddButton(dialog, _("off"), ShuffleCallback, (XtPointer) dialog);
218 XtRealizeWidget(popup);
219 CatchDeleteWindow(popup, "ShufflePopDown");
221 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
222 &x, &y, &win_x, &win_y, &mask);
224 XtSetArg(args[0], XtNx, x - 10);
225 XtSetArg(args[1], XtNy, y - 30);
226 XtSetValues(popup, args, 2);
228 XtPopup(popup, XtGrabExclusive);
231 edit = XtNameToWidget(dialog, "*value");
233 XtSetKeyboardFocus(popup, edit);
236 void ShuffleMenuProc(w, event, prms, nprms)
242 // if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
243 // Reset(FALSE, TRUE);
248 //--------------------------- Time-Control Menu Popup ----------------------------------
250 Widget TimeControlShell;
252 Widget tcMess1, tcMess2, tcData, tcTime, tcOdds1, tcOdds2;
253 int tcIncrement, tcMoves;
255 void TimeControlPopDown()
257 if (!TimeControlUp) return;
259 XtPopdown(TimeControlShell);
260 XtDestroyWidget(TimeControlShell);
261 TimeControlUp = False;
265 void TimeControlCallback(w, client_data, call_data)
267 XtPointer client_data, call_data;
274 XtSetArg(args[0], XtNlabel, &name);
275 XtGetValues(w, args, 1);
277 if (strcmp(name, _("classical")) == 0) {
278 if(tcInc == 0) return;
280 XtSetArg(args[j], XtNlabel, _("minutes for each")); j++;
281 XtSetValues(tcMess1, args, j);
283 XtSetArg(args[j], XtNlabel, _("moves")); j++;
284 XtSetValues(tcMess2, args, j);
287 XtSetArg(args[j], XtNstring, &name); j++;
288 XtGetValues(tcData, args, j);
289 tcIncrement = 0; sscanf(name, "%d", &tcIncrement);
291 snprintf(buf, MSG_SIZ, "%d", tcMoves);
293 XtSetArg(args[j], XtNstring, buf); j++;
294 XtSetValues(tcData, args, j);
298 if (strcmp(name, _("incremental")) == 0) {
299 if(tcInc == 1) return;
301 XtSetArg(args[j], XtNlabel, _("minutes, plus")); j++;
302 XtSetValues(tcMess1, args, j);
304 XtSetArg(args[j], XtNlabel, _("sec/move")); j++;
305 XtSetValues(tcMess2, args, j);
308 XtSetArg(args[j], XtNstring, &name); j++;
309 XtGetValues(tcData, args, j);
310 tcMoves = appData.movesPerSession; sscanf(name, "%d", &tcMoves);
312 snprintf(buf, MSG_SIZ, "%d", tcIncrement);
314 XtSetArg(args[j], XtNstring, buf); j++;
315 XtSetValues(tcData, args, j);
319 if (strcmp(name, _("fixed time")) == 0) {
320 if(tcInc == 2) return;
322 XtSetArg(args[j], XtNlabel, _("sec/move (max)")); j++;
323 XtSetValues(tcMess1, args, j);
325 XtSetArg(args[j], XtNlabel, _("")); j++;
326 XtSetValues(tcMess2, args, j);
328 XtSetArg(args[j], XtNstring, ""); j++;
329 XtSetValues(tcData, args, j);
333 if (strcmp(name, _(" OK ")) == 0) {
335 XtSetArg(args[0], XtNstring, &txt);
336 XtGetValues(tcData, args, 1);
339 ok = sscanf(txt, "%d", &inc); mps = 0;
340 if(!ok && txt[0] == 0) { inc = 0; ok = 1; } // accept empty string as zero
344 ok = sscanf(txt, "%d", &mps); inc = -1;
348 ok = 1; inc = -1; mps = 40;
351 XtSetArg(args[0], XtNstring, ""); // erase any offending input
352 XtSetValues(tcData, args, 1);
355 XtSetArg(args[0], XtNstring, &txt);
356 XtGetValues(tcTime, args, 1);
358 if(sscanf(txt, "%d", &inc) != 1) {
359 XtSetArg(args[0], XtNstring, ""); // erase any offending input
360 XtSetValues(tcTime, args, 1);
361 DisplayError(_("Bad Time-Control String"), 0);
366 if(!ParseTimeControl(txt, inc, mps)) {
367 XtSetArg(args[0], XtNstring, ""); // erase any offending input
368 XtSetValues(tcTime, args, 1);
369 DisplayError(_("Bad Time-Control String"), 0);
373 appData.movesPerSession = mps;
374 appData.timeIncrement = inc;
375 appData.timeControl = strdup(txt);
377 XtSetArg(args[0], XtNstring, &txt);
378 XtGetValues(tcOdds1, args, 1);
379 appData.firstTimeOdds = first.timeOdds
380 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
381 XtGetValues(tcOdds2, args, 1);
382 appData.secondTimeOdds = second.timeOdds
383 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
386 TimeControlPopDown();
391 void TimeControlPopUp()
394 Widget popup, layout, form, b_ok, b_cancel, b_clas, b_inc, mess;
401 tcInc = searchTime > 0 ? 2 : (appData.timeIncrement >= 0);
402 tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
403 if(!tcInc) tcIncrement = 0;
404 snprintf(def, MSG_SIZ, "%d", tcInc ? tcIncrement : tcMoves);
407 XtSetArg(args[i], XtNresizable, True); i++;
408 // XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
409 TimeControlShell = popup =
410 XtCreatePopupShell(_("TimeControl Menu"), transientShellWidgetClass,
411 shellWidget, args, i);
414 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
415 layoutArgs, XtNumber(layoutArgs));
418 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
419 formArgs, XtNumber(formArgs));
422 // XtSetArg(args[j], XtNwidth, (XtArgVal) 300); j++;
423 // XtSetArg(args[j], XtNheight, (XtArgVal) 85); j++;
424 XtSetValues(popup, args, j);
427 XtSetArg(args[j], XtNborderWidth, 1); j++;
428 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
429 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
430 XtSetArg(args[j], XtNstring, appData.timeControl); j++;
431 XtSetArg(args[j], XtNdisplayCaret, False); j++;
432 XtSetArg(args[j], XtNtop, XtChainTop); j++;
433 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
434 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
435 XtSetArg(args[j], XtNright, XtChainRight); j++;
436 XtSetArg(args[j], XtNresizable, True); j++;
437 XtSetArg(args[j], XtNwidth, 85); j++;
438 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
439 tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j);
440 XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup);
443 XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _("sec/move (max) ") : _(" minutes, plus ") : _("minutes for each")); j++;
444 XtSetArg(args[j], XtNborderWidth, 0); j++;
445 XtSetArg(args[j], XtNfromHoriz, tcTime); j++;
446 XtSetArg(args[j], XtNtop, XtChainTop); j++;
447 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
448 XtSetArg(args[j], XtNleft, XtChainRight); j++;
449 XtSetArg(args[j], XtNright, XtChainRight); j++;
450 // XtSetArg(args[j], XtNwidth, 100); j++;
451 // XtSetArg(args[j], XtNheight, 20); j++;
452 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
455 XtSetArg(args[j], XtNborderWidth, 1); j++;
456 XtSetArg(args[j], XtNfromHoriz, tcMess1); j++;
457 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
458 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
459 XtSetArg(args[j], XtNstring, def); j++;
460 XtSetArg(args[j], XtNdisplayCaret, False); j++;
461 XtSetArg(args[j], XtNtop, XtChainTop); j++;
462 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
463 XtSetArg(args[j], XtNleft, XtChainRight); j++;
464 XtSetArg(args[j], XtNright, XtChainRight); j++;
465 XtSetArg(args[j], XtNresizable, True); j++;
466 XtSetArg(args[j], XtNwidth, 40); j++;
467 // XtSetArg(args[j], XtNheight, 20); j++;
468 tcData = XtCreateManagedWidget("MPS", asciiTextWidgetClass, form, args, j);
469 XtAddEventHandler(tcData, ButtonPressMask, False, SetFocus, (XtPointer) popup);
472 XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _(" ") : _("sec/move") : _("moves ")); j++;
473 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
474 XtSetArg(args[j], XtNborderWidth, 0); j++;
475 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
476 XtSetArg(args[j], XtNtop, XtChainTop); j++;
477 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
478 XtSetArg(args[j], XtNleft, XtChainRight); j++;
479 XtSetArg(args[j], XtNright, XtChainRight); j++;
480 // XtSetArg(args[j], XtNwidth, 80); j++;
481 // XtSetArg(args[j], XtNheight, 20); j++;
482 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass,
486 XtSetArg(args[j], XtNborderWidth, 1); j++;
487 XtSetArg(args[j], XtNfromVert, tcTime); j++;
488 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
489 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
490 XtSetArg(args[j], XtNstring, "1"); j++;
491 XtSetArg(args[j], XtNdisplayCaret, False); j++;
492 XtSetArg(args[j], XtNtop, XtChainTop); j++;
493 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
494 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
495 XtSetArg(args[j], XtNright, XtChainLeft); j++;
496 XtSetArg(args[j], XtNresizable, True); j++;
497 XtSetArg(args[j], XtNwidth, 40); j++;
498 // XtSetArg(args[j], XtNheight, 20); j++;
499 tcOdds1 = XtCreateManagedWidget("Odds1", asciiTextWidgetClass, form, args, j);
500 XtAddEventHandler(tcOdds1, ButtonPressMask, False, SetFocus, (XtPointer) popup);
503 XtSetArg(args[j], XtNborderWidth, 1); j++;
504 XtSetArg(args[j], XtNfromVert, tcTime); j++;
505 XtSetArg(args[j], XtNfromHoriz, tcOdds1); j++;
506 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
507 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
508 XtSetArg(args[j], XtNstring, "1"); j++;
509 XtSetArg(args[j], XtNdisplayCaret, False); j++;
510 XtSetArg(args[j], XtNtop, XtChainTop); j++;
511 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
512 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
513 XtSetArg(args[j], XtNright, XtChainLeft); j++;
514 XtSetArg(args[j], XtNresizable, True); j++;
515 XtSetArg(args[j], XtNwidth, 40); j++;
516 // XtSetArg(args[j], XtNheight, 20); j++;
517 tcOdds2 = XtCreateManagedWidget("Odds2", asciiTextWidgetClass, form, args, j);
518 XtAddEventHandler(tcOdds2, ButtonPressMask, False, SetFocus, (XtPointer) popup);
521 XtSetArg(args[j], XtNlabel, _("Engine #1 and #2 Time-Odds Factors")); j++;
522 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
523 XtSetArg(args[j], XtNborderWidth, 0); j++;
524 XtSetArg(args[j], XtNfromVert, tcTime); j++;
525 XtSetArg(args[j], XtNfromHoriz, tcOdds2); j++;
526 XtSetArg(args[j], XtNtop, XtChainTop); j++;
527 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
528 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
529 XtSetArg(args[j], XtNright, XtChainRight); j++;
530 // XtSetArg(args[j], XtNwidth, 200); j++;
531 // XtSetArg(args[j], XtNheight, 20); j++;
532 mess = XtCreateManagedWidget("Oddstext", labelWidgetClass,
535 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
536 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
537 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
538 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
539 XtSetArg(args[j], XtNright, XtChainLeft); j++;
540 XtSetArg(args[j], XtNstate, tcInc==0); j++;
541 b_clas= XtCreateManagedWidget(_("classical"), toggleWidgetClass,
543 XtAddCallback(b_clas, XtNcallback, TimeControlCallback, (XtPointer) 0);
546 XtSetArg(args[j], XtNradioGroup, b_clas); j++;
547 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
548 XtSetArg(args[j], XtNfromHoriz, b_clas); j++;
549 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
550 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
551 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
552 XtSetArg(args[j], XtNright, XtChainLeft); j++;
553 XtSetArg(args[j], XtNstate, tcInc==1); j++;
554 b_inc = XtCreateManagedWidget(_("incremental"), toggleWidgetClass,
556 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
559 XtSetArg(args[j], XtNradioGroup, b_inc); j++;
560 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
561 XtSetArg(args[j], XtNfromHoriz, b_inc); j++;
562 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
563 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
564 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
565 XtSetArg(args[j], XtNright, XtChainLeft); j++;
566 XtSetArg(args[j], XtNstate, tcInc==2); j++;
567 b_inc = XtCreateManagedWidget(_("fixed time"), toggleWidgetClass,
569 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
572 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
573 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
574 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
575 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
576 XtSetArg(args[j], XtNleft, XtChainRight); j++;
577 XtSetArg(args[j], XtNright, XtChainRight); j++;
578 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass,
580 XtAddCallback(b_ok, XtNcallback, TimeControlCallback, (XtPointer) 0);
583 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
584 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
585 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
586 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
587 XtSetArg(args[j], XtNleft, XtChainRight); j++;
588 XtSetArg(args[j], XtNright, XtChainRight); j++;
589 b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
591 XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0);
593 XtRealizeWidget(popup);
594 CatchDeleteWindow(popup, "TimeControlPopDown");
596 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
597 &x, &y, &win_x, &win_y, &mask);
599 XtSetArg(args[0], XtNx, x - 10);
600 XtSetArg(args[1], XtNy, y - 30);
601 XtSetValues(popup, args, 2);
603 XtPopup(popup, XtGrabExclusive);
604 TimeControlUp = True;
607 SetFocus(tcTime, popup, (XEvent*) NULL, False);
608 // XtSetKeyboardFocus(popup, tcTime);
611 void TimeControlProc(w, event, prms, nprms)
620 //--------------------------- Engine-specific options menu ----------------------------------
622 int values[MAX_OPTIONS];
623 ChessProgramState *currentCps;
624 static Option *currentOption;
625 extern Widget shells[];
627 void SpinCallback(w, client_data, call_data)
629 XtPointer client_data, call_data;
633 char buf[MSG_SIZ], *p;
635 int data = (intptr_t) client_data;
637 XtSetArg(args[0], XtNlabel, &name);
638 XtGetValues(w, args, 1);
641 XtSetArg(args[0], XtNstring, &val);
642 XtGetValues(currentOption[data].handle, args, 1);
643 sscanf(val, "%d", &j);
644 if (strcmp(name, "browse") == 0) {
645 if(XsraSelFile(shells[0], currentOption[data].name, NULL, NULL, "", "",
646 currentOption[data].type == PathName ? "p" : "f", NULL, &p)) {
648 if(len && p[len-1] == '/') p[len-1] = NULLCHAR;
649 XtSetArg(args[0], XtNstring, p);
650 XtSetValues(currentOption[data].handle, args, 1);
652 SetFocus(currentOption[data].handle, shells[0], (XEvent*) NULL, False);
655 if (strcmp(name, "+") == 0) {
656 if(++j > currentOption[data].max) return;
658 if (strcmp(name, "-") == 0) {
659 if(--j < currentOption[data].min) return;
661 snprintf(buf, MSG_SIZ, "%d", j);
662 XtSetArg(args[0], XtNstring, buf);
663 XtSetValues(currentOption[data].handle, args, 1);
666 void ComboSelect(w, addr, index) // callback for all combo items
672 int i = ((intptr_t)addr)>>8;
673 int j = 255 & (intptr_t) addr;
675 values[i] = j; // store in temporary, for transfer at OK
676 XtSetArg(args[0], XtNlabel, ((char**)currentOption[i].textValue)[j]);
677 XtSetValues(currentOption[i].handle, args, 1);
680 void CreateComboPopup(parent, name, n, mb)
690 menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
693 XtSetArg(args[j], XtNwidth, 100); j++;
694 // XtSetArg(args[j], XtNright, XtChainRight); j++;
695 while (mb[i] != NULL) {
696 entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
698 XtAddCallback(entry, XtNcallback,
699 (XtCallbackProc) ComboSelect,
700 (caddr_t)(intptr_t) (256*n+i));
706 //----------------------------Generic dialog --------------------------------------------
708 // cloned from Engine Settings dialog (and later merged with it)
710 typedef void ButtonCallback(int n);
713 static int oldCores, oldPonder;
714 int MakeColors P((void));
715 void CreateGCs P((int redo));
716 void CreateXPMBoard P((char *s, int kind));
717 void CreateXPMPieces P((void));
718 void GenericReadout();
722 WindowPlacement *wp[10];
723 Option *dialogOptions[10];
725 void MarkMenu(char *item, int dlgNr)
728 XtSetArg(args[0], XtNleftBitmap, xMarkPixmap);
729 XtSetValues(marked[dlgNr] = XtNameToWidget(menuBarWidget, item), args, 1);
736 Dimension windowH, windowW; Position windowX, windowY;
737 if (!shellUp[n]) return 0;
738 if(n && wp[n]) { // remember position
740 XtSetArg(args[j], XtNx, &windowX); j++;
741 XtSetArg(args[j], XtNy, &windowY); j++;
742 XtSetArg(args[j], XtNheight, &windowH); j++;
743 XtSetArg(args[j], XtNwidth, &windowW); j++;
744 XtGetValues(shells[n], args, j);
747 wp[n]->width = windowW;
748 wp[n]->height = windowH;
751 XtPopdown(shells[n]);
752 if(n == 0) XtDestroyWidget(shells[n]);
755 XtSetArg(args[0], XtNleftBitmap, None);
756 XtSetValues(marked[n], args, 1);
758 if(!n) currentCps = NULL; // if an Engine Settings dialog was up, we must be popping it down now
762 void GenericPopDown(w, event, prms, nprms)
769 PopDown(prms[0][0] - '0');
772 Option matchOptions[] = {
773 { 0, 2, 1000000000, NULL, (void*) &appData.defaultMatchGames, "", NULL, Spin, _("Default Number of Games in Match:") },
774 { 0, 0, 1000000000, NULL, (void*) &appData.matchPause, "", NULL, Spin, _("Pause between Match Games (msec):") },
775 { 0, 0, 0, NULL, (void*) &appData.loadGameFile, "", NULL, FileName, _("Game File with Opening Lines:") },
776 { 0, -2, 1000000000, NULL, (void*) &appData.loadGameIndex, "", NULL, Spin, _("Game Number (-1 or -2 = Auto-Increment):") },
777 { 0, 0, 0, NULL, (void*) &appData.loadPositionFile, "", NULL, FileName, _("File with Start Positions:") },
778 { 0, -2, 1000000000, NULL, (void*) &appData.loadPositionIndex, "", NULL, Spin, _("Position Number (-1 or -2 = Auto-Increment):") },
779 { 0, 0, 1000000000, NULL, (void*) &appData.rewindIndex, "", NULL, Spin, _("Rewind Index after this many Games (0 = never):") },
780 { 0, 0, 0, NULL, NULL, "", NULL, EndMark , "" }
783 void GeneralOptionsOK(int n)
785 int newPonder = appData.ponderNextMove;
786 appData.ponderNextMove = oldPonder;
787 PonderNextMoveEvent(newPonder);
790 Option generalOptions[] = {
791 { 0, 0, 0, NULL, (void*) &appData.alwaysPromoteToQueen, "", NULL, CheckBox, _("Always Queen") },
792 { 0, 0, 0, NULL, (void*) &appData.animateDragging, "", NULL, CheckBox, _("Animate Dragging") },
793 { 0, 0, 0, NULL, (void*) &appData.animate, "", NULL, CheckBox, _("Animate Moving") },
794 { 0, 0, 0, NULL, (void*) &appData.autoCallFlag, "", NULL, CheckBox, _("Auto Flag") },
795 { 0, 0, 0, NULL, (void*) &appData.autoFlipView, "", NULL, CheckBox, _("Auto Flip View") },
796 { 0, 0, 0, NULL, (void*) &appData.blindfold, "", NULL, CheckBox, _("Blindfold") },
797 { 0, 0, 0, NULL, (void*) &appData.dropMenu, "", NULL, CheckBox, _("Drop Menu") },
798 { 0, 0, 0, NULL, (void*) &appData.highlightDragging, "", NULL, CheckBox, _("Highlight Dragging (Show Move Targets)") },
799 { 0, 0, 0, NULL, (void*) &appData.highlightLastMove, "", NULL, CheckBox, _("Highlight Last Move") },
800 { 0, 0, 0, NULL, (void*) &appData.highlightMoveWithArrow, "", NULL, CheckBox, _("Highlight with Arrow") },
801 { 0, 0, 0, NULL, (void*) &appData.ringBellAfterMoves, "", NULL, CheckBox, _("Move Sound") },
802 { 0, 0, 0, NULL, (void*) &appData.oneClick, "", NULL, CheckBox, _("One-Click Moving") },
803 { 0, 0, 0, NULL, (void*) &appData.periodicUpdates, "", NULL, CheckBox, _("Periodic Updates (in Analysis Mode)") },
804 { 0, 0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, _("Ponder Next Move") },
805 { 0, 0, 0, NULL, (void*) &appData.popupExitMessage, "", NULL, CheckBox, _("Popup Exit Messages") },
806 { 0, 0, 0, NULL, (void*) &appData.popupMoveErrors, "", NULL, CheckBox, _("Popup Move Errors") },
807 { 0, 0, 0, NULL, (void*) &appData.showCoords, "", NULL, CheckBox, _("Show Coordinates") },
808 { 0, 0, 0, NULL, (void*) &appData.markers, "", NULL, CheckBox, _("Show Target Squares") },
809 { 0, 0, 0, NULL, (void*) &appData.hideThinkingFromHuman, "", NULL, CheckBox, _("Hide Thinking from Human") },
810 { 0, 0, 0, NULL, (void*) &appData.testLegality, "", NULL, CheckBox, _("Test Legality") },
811 { 0, 0, 10, NULL, (void*) &appData.flashCount, "", NULL, Spin, _("Flash Moves (0 = no flashing):") },
812 { 0, 1, 10, NULL, (void*) &appData.flashRate, "", NULL, Spin, _("Flash Rate (high = fast):") },
813 { 0, 5, 100,NULL, (void*) &appData.animSpeed, "", NULL, Spin, _("Animation Speed (high = slow):") },
814 { 0, 0, 0, NULL, (void*) &GeneralOptionsOK, "", NULL, EndMark , "" }
819 VariantClass v = currentOption[n].value;
820 if(!appData.noChessProgram) {
821 char *name = VariantName(v), buf[MSG_SIZ];
822 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
823 /* [HGM] in protocol 2 we check if variant is suported by engine */
824 snprintf(buf, MSG_SIZ, _("Variant %s not supported by %s"), name, first.tidy);
825 DisplayError(buf, 0);
826 return; /* ignore OK if first engine does not support it */
828 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
829 snprintf(buf, MSG_SIZ, _("Warning: second engine (%s) does not support this!"), second.tidy);
830 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
834 GenericReadout(); // make sure ranks and file settings are read
836 gameInfo.variant = v;
837 appData.variant = VariantName(v);
839 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
840 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
841 appData.pieceToCharTable = NULL;
842 appData.pieceNickNames = "";
843 appData.colorNickNames = "";
849 Option variantDescriptors[] = {
850 { VariantNormal, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("normal")},
851 { VariantFairy, 1, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("fairy")},
852 { VariantFischeRandom, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("FRC")},
853 { VariantSChess, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Seirawan")},
854 { VariantWildCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("wild castle")},
855 { VariantSuper, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Superchess")},
856 { VariantNoCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("no castle")},
857 { VariantCrazyhouse, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("crazyhouse")},
858 { VariantKnightmate, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("knightmate")},
859 { VariantBughouse, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("bughouse")},
860 { VariantBerolina, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("berolina")},
861 { VariantShogi, 1, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("shogi (9x9)")},
862 { VariantCylinder, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("cylinder")},
863 { VariantXiangqi, 1, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("xiangqi (9x10)")},
864 { VariantShatranj, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("shatranj")},
865 { VariantCourier, 1, 135, NULL, (void*) &Pick, "#BFFFBF", NULL, Button, N_("courier (12x8)")},
866 { VariantMakruk, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("makruk")},
867 { VariantGreat, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Great Shatranj (10x8)")},
868 { VariantAtomic, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("atomic")},
869 { VariantCapablanca, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Capablanca (10x8)")},
870 { VariantTwoKings, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("two kings")},
871 { VariantGothic, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Gothic (10x8)")},
872 { Variant3Check, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("3-checks")},
873 { VariantJanus, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("janus (10x8)")},
874 { VariantSuicide, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("suicide")},
875 { VariantCapaRandom, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("CRC (10x8)")},
876 { VariantGiveaway, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("give-away")},
877 { VariantSpartan, 1, 135, NULL, (void*) &Pick, "#FF0000", NULL, Button, N_("Spartan")},
878 { VariantLosers, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("losers")},
879 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, _("Board size ( -1 = default for selected variant):")},
880 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.NrRanks, "", NULL, Spin, N_("Number of Board Ranks:") },
881 { 0, -1, BOARD_FILES, NULL, (void*) &appData.NrFiles, "", NULL, Spin, N_("Number of Board Files:") },
882 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.holdingsSize, "", NULL, Spin, N_("Holdings Size:") },
883 { 0, 0, 0, NULL, NULL, NULL, NULL, Label,
884 _("WARNING: variants with un-orthodox\n"
885 "pieces only have built-in bitmaps\n"
886 "for -boardSize middling, bulky and\n"
887 "petite, and substitute king or amazon\n"
888 "for missing bitmaps. (See manual.)")},
889 { 0, 2, 0, NULL, NULL, "", NULL, EndMark , "" }
892 void CommonOptionsOK(int n)
894 int newPonder = appData.ponderNextMove;
895 // make sure changes are sent to first engine by re-initializing it
896 // if it was already started pre-emptively at end of previous game
897 if(gameMode == BeginningOfGame) Reset(True, True); else {
898 // Some changed setting need immediate sending always.
899 if(oldCores != appData.smpCores)
900 NewSettingEvent(False, &(first.maxCores), "cores", appData.smpCores);
901 appData.ponderNextMove = oldPonder;
902 PonderNextMoveEvent(newPonder);
906 Option commonEngineOptions[] = {
907 { 0, 0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, _("Ponder Next Move") },
908 { 0, 0, 1000, NULL, (void*) &appData.smpCores, "", NULL, Spin, _("Maximum Number of CPUs per Engine:") },
909 { 0, 0, 0, NULL, (void*) &appData.polyglotDir, "", NULL, PathName, _("Polygot Directory:") },
910 { 0, 0, 16000, NULL, (void*) &appData.defaultHashSize, "", NULL, Spin, _("Hash-Table Size (MB):") },
911 { 0, 0, 0, NULL, (void*) &appData.defaultPathEGTB, "", NULL, PathName, _("Nalimov EGTB Path:") },
912 { 0, 0, 1000, NULL, (void*) &appData.defaultCacheSizeEGTB, "", NULL, Spin, _("EGTB Cache Size (MB):") },
913 { 0, 0, 0, NULL, (void*) &appData.usePolyglotBook, "", NULL, CheckBox, _("Use GUI Book") },
914 { 0, 0, 0, NULL, (void*) &appData.polyglotBook, "", NULL, FileName, _("Opening-Book Filename:") },
915 { 0, 0, 100, NULL, (void*) &appData.bookDepth, "", NULL, Spin, _("Book Depth (moves):") },
916 { 0, 0, 100, NULL, (void*) &appData.bookStrength, "", NULL, Spin, _("Book Variety (0) vs. Strength (100):") },
917 { 0, 0, 0, NULL, (void*) &appData.firstHasOwnBookUCI, "", NULL, CheckBox, _("Engine #1 Has Own Book") },
918 { 0, 0, 0, NULL, (void*) &appData.secondHasOwnBookUCI, "", NULL, CheckBox, _("Engine #2 Has Own Book ") },
919 { 0, 1, 0, NULL, (void*) &CommonOptionsOK, "", NULL, EndMark , "" }
922 Option adjudicationOptions[] = {
923 { 0, 0, 0, NULL, (void*) &appData.checkMates, "", NULL, CheckBox, _("Detect all Mates") },
924 { 0, 0, 0, NULL, (void*) &appData.testClaims, "", NULL, CheckBox, _("Verify Engine Result Claims") },
925 { 0, 0, 0, NULL, (void*) &appData.materialDraws, "", NULL, CheckBox, _("Draw if Insufficient Mating Material") },
926 { 0, 0, 0, NULL, (void*) &appData.trivialDraws, "", NULL, CheckBox, _("Adjudicate Trivial Draws (3-Move Delay)") },
927 { 0, 0, 100, NULL, (void*) &appData.ruleMoves, "", NULL, Spin, _("N-Move Rule:") },
928 { 0, 0, 6, NULL, (void*) &appData.drawRepeats, "", NULL, Spin, _("N-fold Repeats:") },
929 { 0, 0, 1000, NULL, (void*) &appData.adjudicateDrawMoves, "", NULL, Spin, _("Draw after N Moves Total:") },
930 { 0,-5000, 0, NULL, (void*) &appData.adjudicateLossThreshold, "", NULL, Spin, _("Win / Loss Threshold:") },
931 { 0, 0, 0, NULL, (void*) &first.scoreIsAbsolute, "", NULL, CheckBox, _("Negate Score of Engine #1") },
932 { 0, 0, 0, NULL, (void*) &second.scoreIsAbsolute, "", NULL, CheckBox, _("Negate Score of Engine #2") },
933 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
936 void IcsOptionsOK(int n)
938 ParseIcsTextColors();
941 Option icsOptions[] = {
942 { 0, 0, 0, NULL, (void*) &appData.autoKibitz, "", NULL, CheckBox, _("Auto-Kibitz") },
943 { 0, 0, 0, NULL, (void*) &appData.autoComment, "", NULL, CheckBox, _("Auto-Comment") },
944 { 0, 0, 0, NULL, (void*) &appData.autoObserve, "", NULL, CheckBox, _("Auto-Observe") },
945 { 0, 0, 0, NULL, (void*) &appData.autoRaiseBoard, "", NULL, CheckBox, _("Auto-Raise Board") },
946 { 0, 0, 0, NULL, (void*) &appData.bgObserve, "", NULL, CheckBox, _("Background Observe while Playing") },
947 { 0, 0, 0, NULL, (void*) &appData.dualBoard, "", NULL, CheckBox, _("Dual Board for Background-Observed Game") },
948 { 0, 0, 0, NULL, (void*) &appData.getMoveList, "", NULL, CheckBox, _("Get Move List") },
949 { 0, 0, 0, NULL, (void*) &appData.quietPlay, "", NULL, CheckBox, _("Quiet Play") },
950 { 0, 0, 0, NULL, (void*) &appData.seekGraph, "", NULL, CheckBox, _("Seek Graph") },
951 { 0, 0, 0, NULL, (void*) &appData.autoRefresh, "", NULL, CheckBox, _("Auto-Refresh Seek Graph") },
952 { 0, 0, 0, NULL, (void*) &appData.premove, "", NULL, CheckBox, _("Premove") },
953 { 0, 0, 0, NULL, (void*) &appData.premoveWhite, "", NULL, CheckBox, _("Premove for White") },
954 { 0, 0, 0, NULL, (void*) &appData.premoveWhiteText, "", NULL, TextBox, _("First White Move:") },
955 { 0, 0, 0, NULL, (void*) &appData.premoveBlack, "", NULL, CheckBox, _("Premove for Black") },
956 { 0, 0, 0, NULL, (void*) &appData.premoveBlackText, "", NULL, TextBox, _("First Black Move:") },
957 { 0, 0, 0, NULL, NULL, NULL, NULL, Break, "" },
958 { 0, 0, 0, NULL, (void*) &appData.icsAlarm, "", NULL, CheckBox, _("Alarm") },
959 { 0, 0, 100000000, NULL, (void*) &appData.icsAlarmTime, "", NULL, Spin, _("Alarm Time (msec):") },
960 //{ 0, 0, 0, NULL, (void*) &appData.chatBoxes, "", NULL, TextBox, _("Startup Chat Boxes:") },
961 { 0, 0, 0, NULL, (void*) &appData.colorize, "", NULL, CheckBox, _("Colorize Messages") },
962 { 0, 0, 0, NULL, (void*) &appData.colorShout, "", NULL, TextBox, _("Shout Text Colors:") },
963 { 0, 0, 0, NULL, (void*) &appData.colorSShout, "", NULL, TextBox, _("S-Shout Text Colors:") },
964 { 0, 0, 0, NULL, (void*) &appData.colorChannel1, "", NULL, TextBox, _("Channel #1 Text Colors:") },
965 { 0, 0, 0, NULL, (void*) &appData.colorChannel, "", NULL, TextBox, _("Other Channel Text Colors:") },
966 { 0, 0, 0, NULL, (void*) &appData.colorKibitz, "", NULL, TextBox, _("Kibitz Text Colors:") },
967 { 0, 0, 0, NULL, (void*) &appData.colorTell, "", NULL, TextBox, _("Tell Text Colors:") },
968 { 0, 0, 0, NULL, (void*) &appData.colorChallenge, "", NULL, TextBox, _("Challenge Text Colors:") },
969 { 0, 0, 0, NULL, (void*) &appData.colorRequest, "", NULL, TextBox, _("Request Text Colors:") },
970 { 0, 0, 0, NULL, (void*) &appData.colorSeek, "", NULL, TextBox, _("Seek Text Colors:") },
971 { 0, 0, 0, NULL, (void*) &IcsOptionsOK, "", NULL, EndMark , "" }
974 Option loadOptions[] = {
975 { 0, 0, 0, NULL, (void*) &appData.autoDisplayTags, "", NULL, CheckBox, _("Auto-Display Tags") },
976 { 0, 0, 0, NULL, (void*) &appData.autoDisplayComment, "", NULL, CheckBox, _("Auto-Display Comment") },
977 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, _("Auto-Play speed of loaded games\n(0 = instant, -1 = off):") },
978 { 0, -1, 10000000, NULL, (void*) &appData.timeDelay, "", NULL, Fractional, _("Seconds per Move:") },
979 { 0, 0, 0, NULL, NULL, "", NULL, EndMark , "" }
982 Option saveOptions[] = {
983 { 0, 0, 0, NULL, (void*) &appData.autoSaveGames, "", NULL, CheckBox, _("Auto-Save Games") },
984 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, "", NULL, FileName, _("Save Games on File:") },
985 { 0, 0, 0, NULL, (void*) &appData.savePositionFile, "", NULL, FileName, _("Save Final Positions on File:") },
986 { 0, 0, 0, NULL, (void*) &appData.pgnEventHeader, "", NULL, TextBox, _("PGN Event Header:") },
987 { 0, 0, 0, NULL, (void*) &appData.oldSaveStyle, "", NULL, CheckBox, _("Old Save Style (as opposed to PGN)") },
988 { 0, 0, 0, NULL, (void*) &appData.saveExtendedInfoInPGN, "", NULL, CheckBox, _("Save Score/Depth Info in PGN") },
989 { 0, 0, 0, NULL, (void*) &appData.saveOutOfBookInfo, "", NULL, CheckBox, _("Save Out-of-Book Info in PGN ") },
990 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
993 char *soundNames[] = {
996 N_("Above WAV File"),
1011 char *soundFiles[] = { // sound files corresponding to above names
1014 "*", // kludge alert: as first thing in the dialog readout this is replaced with the user-given .WAV filename
1031 if(soundFiles[values[3]]) PlaySound(soundFiles[values[3]]);
1034 Option soundOptions[] = {
1035 { 0, 0, 0, NULL, (void*) &appData.soundProgram, "", NULL, TextBox, _("Sound Program:") },
1036 { 0, 0, 0, NULL, (void*) &appData.soundDirectory, "", NULL, PathName, _("Sounds Directory:") },
1037 { 0, 0, 0, NULL, (void*) (soundFiles+2) /* kludge! */, "", NULL, FileName, _("User WAV File:") },
1038 { 0, 0, 0, NULL, (void*) &trialSound, (char*) soundNames, soundFiles, ComboBox, _("Try-Out Sound:") },
1039 { 0, 1, 0, NULL, (void*) &Test, NULL, NULL, Button, _("Play") },
1040 { 0, 0, 0, NULL, (void*) &appData.soundMove, (char*) soundNames, soundFiles, ComboBox, _("Move:") },
1041 { 0, 0, 0, NULL, (void*) &appData.soundIcsWin, (char*) soundNames, soundFiles, ComboBox, _("Win:") },
1042 { 0, 0, 0, NULL, (void*) &appData.soundIcsLoss, (char*) soundNames, soundFiles, ComboBox, _("Lose:") },
1043 { 0, 0, 0, NULL, (void*) &appData.soundIcsDraw, (char*) soundNames, soundFiles, ComboBox, _("Draw:") },
1044 { 0, 0, 0, NULL, (void*) &appData.soundIcsUnfinished, (char*) soundNames, soundFiles, ComboBox, _("Unfinished:") },
1045 { 0, 0, 0, NULL, (void*) &appData.soundIcsAlarm, (char*) soundNames, soundFiles, ComboBox, _("Alarm:") },
1046 { 0, 0, 0, NULL, (void*) &appData.soundShout, (char*) soundNames, soundFiles, ComboBox, _("Shout:") },
1047 { 0, 0, 0, NULL, (void*) &appData.soundSShout, (char*) soundNames, soundFiles, ComboBox, _("S-Shout:") },
1048 { 0, 0, 0, NULL, (void*) &appData.soundChannel, (char*) soundNames, soundFiles, ComboBox, _("Channel:") },
1049 { 0, 0, 0, NULL, (void*) &appData.soundChannel1, (char*) soundNames, soundFiles, ComboBox, _("Channel 1:") },
1050 { 0, 0, 0, NULL, (void*) &appData.soundTell, (char*) soundNames, soundFiles, ComboBox, _("Tell:") },
1051 { 0, 0, 0, NULL, (void*) &appData.soundKibitz, (char*) soundNames, soundFiles, ComboBox, _("Kibitz:") },
1052 { 0, 0, 0, NULL, (void*) &appData.soundChallenge, (char*) soundNames, soundFiles, ComboBox, _("Challenge:") },
1053 { 0, 0, 0, NULL, (void*) &appData.soundRequest, (char*) soundNames, soundFiles, ComboBox, _("Request:") },
1054 { 0, 0, 0, NULL, (void*) &appData.soundSeek, (char*) soundNames, soundFiles, ComboBox, _("Seek:") },
1055 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
1058 void SetColor(char *colorName, Widget box)
1062 XrmValue vFrom, vTo;
1063 if (!appData.monoMode) {
1064 vFrom.addr = (caddr_t) colorName;
1065 vFrom.size = strlen(colorName);
1066 XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1067 if (vTo.addr == NULL) {
1068 buttonColor = (Pixel) -1;
1070 buttonColor = *(Pixel *) vTo.addr;
1073 XtSetArg(args[0], XtNbackground, buttonColor);;
1074 XtSetValues(box, args, 1);
1077 void AdjustColor(int i)
1079 int n = currentOption[i].value, col, j, r, g, b, step = 10;
1080 char *s, buf[MSG_SIZ]; // color string
1082 XtSetArg(args[0], XtNstring, &s);
1083 XtGetValues(currentOption[i-n-1].handle, args, 1);
1084 if(sscanf(s, "#%x", &col) != 1) return; // malformed
1085 b = col & 0xFF; g = col & 0xFF00; r = col & 0xFF0000;
1087 case 1: g -= 0x100*step; b -= step; break;
1088 case 2: r -= 0x10000*step; b -= step; break;
1089 case 3: g -= 0x100*step; r -= 0x10000*step; break;
1090 case 4: r += 0x10000*step; g += 0x100*step; b += step; break;
1092 if(r < 0) r = 0; if(g < 0) g = 0; if(b < 0) b = 0;
1093 if(r > 0xFF0000) r = 0xFF0000; if(g > 0xFF00) g = 0xFF00; if(b > 0xFF) b = 0xFF;
1095 snprintf(buf, MSG_SIZ, "#%06x", col);
1096 for(j=1; j<7; j++) if(buf[j] >= 'a') buf[j] -= 32; // capitalize
1097 SetColor(buf, currentOption[i-n].handle);
1098 XtSetArg(args[0], XtNstring, buf);
1099 XtSetValues(currentOption[i-n-1].handle, args, 1);
1102 void BoardOptionsOK(int n)
1104 if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap;
1105 MakeColors(); CreateGCs(True);
1107 CreateXPMBoard(appData.liteBackTextureFile, 1);
1108 CreateXPMBoard(appData.darkBackTextureFile, 0);
1109 InitDrawingSizes(-1, 0);
1110 DrawPosition(True, NULL);
1113 Option boardOptions[] = {
1114 { 0, 0, 70, NULL, (void*) &appData.whitePieceColor, "", NULL, TextBox, _("White Piece Color:") },
1115 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, " " },
1116 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1117 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1118 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1119 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1120 { 0, 0, 70, NULL, (void*) &appData.blackPieceColor, "", NULL, TextBox, _("Black Piece Color:") },
1121 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, " " },
1122 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1123 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1124 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1125 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1126 { 0, 0, 70, NULL, (void*) &appData.lightSquareColor, "", NULL, TextBox, _("Light Square Color:") },
1127 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, " " },
1128 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1129 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1130 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1131 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1132 { 0, 0, 70, NULL, (void*) &appData.darkSquareColor, "", NULL, TextBox, _("Dark Square Color:") },
1133 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, " " },
1134 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1135 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1136 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1137 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1138 { 0, 0, 70, NULL, (void*) &appData.highlightSquareColor, "", NULL, TextBox, _("Highlight Color:") },
1139 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, " " },
1140 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1141 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1142 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1143 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1144 { 0, 0, 70, NULL, (void*) &appData.premoveHighlightColor, "", NULL, TextBox, _("Premove Highlight Color:") },
1145 { 1000, 1, 0, NULL, NULL, NULL, NULL, Button, " " },
1146 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1147 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1148 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1149 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "W" },
1150 { 0, 0, 0, NULL, (void*) &appData.upsideDown, "", NULL, CheckBox, _("Flip Pieces Shogi Style") },
1151 { 0, 0, 0, NULL, (void*) &appData.allWhite, "", NULL, CheckBox, _("Use Outline Pieces for Black") },
1152 { 0, 0, 0, NULL, (void*) &appData.monoMode, "", NULL, CheckBox, _("Mono Mode") },
1153 { 0,-1, 5, NULL, (void*) &appData.overrideLineGap, "", NULL, Spin, _("Line Gap ( -1 = default for board size):") },
1154 { 0, 0, 0, NULL, (void*) &appData.liteBackTextureFile, "", NULL, FileName, _("Light-Squares Texture File:") },
1155 { 0, 0, 0, NULL, (void*) &appData.darkBackTextureFile, "", NULL, FileName, _("Dark-Squares Texture File:") },
1156 { 0, 0, 0, NULL, (void*) &appData.bitmapDirectory, "", NULL, PathName, _("Directory with Bitmap Pieces:") },
1157 { 0, 0, 0, NULL, (void*) &appData.pixmapDirectory, "", NULL, PathName, _("Directory with Pixmap Pieces:") },
1158 { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" }
1161 void GenericReadout()
1166 char buf[MSG_SIZ], **dest;
1168 for(i=0; ; i++) { // send all options that had to be OK-ed to engine
1169 switch(currentOption[i].type) {
1173 XtSetArg(args[0], XtNstring, &val);
1174 XtGetValues(currentOption[i].handle, args, 1);
1175 dest = currentCps ? &(currentOption[i].textValue) : (char**) currentOption[i].target;
1176 if(*dest == NULL || strcmp(*dest, val)) {
1178 snprintf(buf, MSG_SIZ, "option %s=%s\n", currentOption[i].name, val);
1179 SendToProgram(buf, currentCps);
1180 } else *dest = currentOption[i].name + 100; // option gets to point to private storage;
1181 safeStrCpy(*dest, val, MSG_SIZ - (*dest - currentOption[i].name)); // copy text there
1186 XtSetArg(args[0], XtNstring, &val);
1187 XtGetValues(currentOption[i].handle, args, 1);
1188 sscanf(val, "%f", &x);
1189 if(x > currentOption[i].max) x = currentOption[i].max;
1190 if(x < currentOption[i].min) x = currentOption[i].min;
1191 if(currentOption[i].value != x) {
1192 currentOption[i].value = x;
1193 if(currentCps) { // engines never have float options, so no decimals!
1194 snprintf(buf, MSG_SIZ, "option %s=%.0f\n", currentOption[i].name, x);
1195 SendToProgram(buf, currentCps);
1196 } else if(currentOption[i].type == Spin) *(int*) currentOption[i].target = x;
1197 else *(float*) currentOption[i].target = x;
1202 XtSetArg(args[0], XtNstate, &j);
1203 XtGetValues(currentOption[i].handle, args, 1);
1204 if(currentOption[i].value != j) {
1205 currentOption[i].value = j;
1207 snprintf(buf, MSG_SIZ, "option %s=%d\n", currentOption[i].name, j);
1208 SendToProgram(buf, currentCps);
1209 } else *(Boolean*) currentOption[i].target = j;
1213 val = ((char**)currentOption[i].choice)[values[i]];
1215 if(currentOption[i].value == values[i]) break; // not changed
1216 currentOption[i].value = values[i];
1217 snprintf(buf, MSG_SIZ, "option %s=%s\n", currentOption[i].name,
1218 ((char**)currentOption[i].textValue)[values[i]]);
1219 SendToProgram(buf, currentCps);
1220 } else if(val && (*(char**) currentOption[i].target == NULL || strcmp(*(char**) currentOption[i].target, val))) {
1221 if(*(char**) currentOption[i].target) free(*(char**) currentOption[i].target);
1222 *(char**) currentOption[i].target = strdup(val);
1226 if(currentOption[i].target) // callback for implementing necessary actions on OK (like redraw)
1227 ((ButtonCallback*) currentOption[i].target)(i);
1230 printf("GenericReadout: unexpected case in switch.\n");
1236 if(currentOption[i].type == EndMark) break;
1240 void GenericCallback(w, client_data, call_data)
1242 XtPointer client_data, call_data;
1248 int data = (intptr_t) client_data;
1250 currentOption = dialogOptions[data>>16]; data &= 0xFFFF;
1252 XtSetArg(args[0], XtNlabel, &name);
1253 XtGetValues(w, args, 1);
1255 if (strcmp(name, _("cancel")) == 0) {
1259 if (strcmp(name, _("OK")) == 0) { // save buttons imply OK
1265 if(currentOption[data].type == SaveButton) GenericReadout();
1266 snprintf(buf, MSG_SIZ, "option %s\n", name);
1267 SendToProgram(buf, currentCps);
1268 } else ((ButtonCallback*) currentOption[data].target)(data);
1272 GenericPopUp(Option *option, char *title, int dlgNr)
1275 Widget popup, layout, dialog, edit=NULL, form, last, b_ok, b_cancel, leftMargin = NULL, textField = NULL;
1277 int x, y, i, j, height=999, width=1, h, c, w;
1278 int win_x, win_y, maxWidth, maxTextWidth;
1280 char def[MSG_SIZ], *msg;
1281 static char pane[6] = "paneX";
1282 Widget texts[100], forelast = NULL, anchor, widest, lastrow = NULL;
1284 if(shellUp[dlgNr]) return 0; // already up
1285 if(dlgNr && shells[dlgNr]) {
1286 XtPopup(shells[dlgNr], XtGrabNone);
1287 shellUp[dlgNr] = True;
1291 dialogOptions[dlgNr] = option; // make available to callback
1292 // post currentOption globally, so Spin and Combo callbacks can already use it
1293 // WARNING: this kludge does not work for persistent dialogs, so that these cannot have spin or combo controls!
1294 currentOption = option;
1296 if(currentCps) { // Settings popup for engine: format through heuristic
1297 int n = currentCps->nrOptions;
1298 if(n > 50) width = 4; else if(n>24) width = 2; else width = 1;
1299 height = n / width + 1;
1300 if(currentOption[n-1].type == Button || currentOption[n-1].type == SaveButton) currentOption[n].min = 1; // OK on same line
1301 currentOption[n].type = EndMark; currentOption[n].target = NULL; // delimit list by callback-less end mark
1304 XtSetArg(args[i], XtNresizable, True); i++;
1305 popup = shells[dlgNr] =
1306 XtCreatePopupShell(title, transientShellWidgetClass,
1307 shellWidget, args, i);
1310 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1311 layoutArgs, XtNumber(layoutArgs));
1312 for(c=0; c<width; c++) {
1315 XtCreateManagedWidget(pane, formWidgetClass, layout,
1316 formArgs, XtNumber(formArgs));
1318 XtSetArg(args[j], XtNfromHoriz, leftMargin); j++;
1319 XtSetValues(form, args, j);
1322 last = widest = NULL; anchor = lastrow;
1323 for(h=0; h<height; h++) {
1325 if(option[i].type == EndMark) break;
1328 switch(option[i].type) {
1330 snprintf(def, MSG_SIZ, "%.2f", *(float*)option[i].target);
1331 option[i].value = *(float*)option[i].target;
1334 if(!currentCps) option[i].value = *(int*)option[i].target;
1335 snprintf(def, MSG_SIZ, "%d", option[i].value);
1340 if(option[i].name[0]) {
1342 XtSetArg(args[j], XtNfromVert, last); j++;
1343 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1344 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1345 XtSetArg(args[j], XtNborderWidth, 0); j++;
1346 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1348 dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
1349 } else texts[h] = dialog = NULL;
1350 w = option[i].type == Spin || option[i].type == Fractional ? 70 : option[i].max ? option[i].max : 205;
1351 if(option[i].type == FileName || option[i].type == PathName) w -= 55;
1353 XtSetArg(args[j], XtNfromVert, last); j++;
1354 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1355 XtSetArg(args[j], XtNborderWidth, 1); j++;
1356 XtSetArg(args[j], XtNwidth, w); j++;
1357 if(option[i].type == TextBox && option[i].min) {
1358 XtSetArg(args[j], XtNheight, option[i].min); j++;
1359 if(option[i].value & 1) { XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++; }
1360 if(option[i].value & 2) { XtSetArg(args[j], XtNscrollHorizontal, XawtextScrollAlways); j++; }
1361 if(option[i].value & 4) { XtSetArg(args[j], XtNautoFill, True); j++; }
1362 if(option[i].value & 8) { XtSetArg(args[j], XtNwrap, XawtextWrapWord); j++; }
1364 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1365 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1366 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1367 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1368 XtSetArg(args[j], XtNright, XtChainRight); j++;
1369 XtSetArg(args[j], XtNresizable, True); j++;
1370 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
1371 XtSetArg(args[j], XtNstring, option[i].type==Spin || option[i].type==Fractional ? def :
1372 currentCps ? option[i].textValue : *(char**)option[i].target); j++;
1374 option[i].handle = (void*)
1375 (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1376 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1378 if(option[i].type == TextBox || option[i].type == Fractional) break;
1380 // add increment and decrement controls for spin
1382 XtSetArg(args[j], XtNfromVert, edit); j++;
1383 XtSetArg(args[j], XtNfromHoriz, last); j++;
1384 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1385 XtSetArg(args[j], XtNright, XtChainRight); j++;
1386 if(option[i].type == FileName || option[i].type == PathName) {
1387 w = 50; msg = "browse";
1389 XtSetArg(args[j], XtNheight, 10); j++;
1392 XtSetArg(args[j], XtNwidth, w); j++;
1393 edit = XtCreateManagedWidget(msg, commandWidgetClass, form, args, j);
1394 XtAddCallback(edit, XtNcallback, SpinCallback,
1395 (XtPointer)(intptr_t) i);
1397 if(option[i].type != Spin) break;
1400 XtSetArg(args[j], XtNfromVert, edit); j++;
1401 XtSetArg(args[j], XtNfromHoriz, last); j++;
1402 XtSetArg(args[j], XtNheight, 10); j++;
1403 XtSetArg(args[j], XtNwidth, 20); j++;
1404 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1405 XtSetArg(args[j], XtNright, XtChainRight); j++;
1406 last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1407 XtAddCallback(last, XtNcallback, SpinCallback,
1408 (XtPointer)(intptr_t) i);
1411 if(!currentCps) option[i].value = *(Boolean*)option[i].target;
1413 XtSetArg(args[j], XtNfromVert, last); j++;
1414 XtSetArg(args[j], XtNwidth, 10); j++;
1415 XtSetArg(args[j], XtNheight, 10); j++;
1416 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1417 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1418 XtSetArg(args[j], XtNstate, option[i].value); j++;
1419 option[i].handle = (void*)
1420 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1422 msg = option[i].name;
1423 if(*msg == NULLCHAR) msg = option[i].textValue;
1426 XtSetArg(args[j], XtNfromVert, last); j++;
1427 XtSetArg(args[j], XtNfromHoriz, option[i].type != Label ? dialog : NULL); j++;
1428 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1429 XtSetArg(args[j], XtNborderWidth, 0); j++;
1430 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1431 last = XtCreateManagedWidget(msg, labelWidgetClass, form, args, j);
1436 XtSetArg(args[j], XtNfromVert, option[i].min & 1 ? lastrow : last); j++;
1437 if(option[i].min & 1) { XtSetArg(args[j], XtNfromHoriz, last); j++; }
1438 else { XtSetArg(args[j], XtNfromHoriz, NULL); j++; lastrow = forelast; }
1439 if(option[i].max) XtSetArg(args[j], XtNwidth, option[i].max); j++;
1440 if(option[i].textValue) { // special for buttons of New Variant dialog
1441 XtSetArg(args[j], XtNsensitive, appData.noChessProgram || option[i].value < 0
1442 || strstr(first.variants, VariantName(option[i].value))); j++;
1443 XtSetArg(args[j], XtNborderWidth, (gameInfo.variant == option[i].value)+1); j++;
1445 option[i].handle = (void*)
1446 (dialog = last = XtCreateManagedWidget(option[i].name, commandWidgetClass, form, args, j));
1447 if(option[i].target == NULL && !currentCps) SetColor( *(char**) option[i-1].target, last); else
1448 XtAddCallback(last, XtNcallback, GenericCallback,
1449 (XtPointer)(intptr_t) i + (dlgNr<<16));
1450 if(option[i].textValue) SetColor( option[i].textValue, last);
1451 forelast = lastrow; // next button can go on same row
1455 XtSetArg(args[j], XtNfromVert, last); j++;
1456 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1457 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1458 XtSetArg(args[j], XtNborderWidth, 0); j++;
1459 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1460 texts[h] = dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
1462 if(currentCps) option[i].choice = (char**) option[i].textValue; else {
1463 for(j=0; option[i].choice[j]; j++)
1464 if(*(char**)option[i].target && !strcmp(*(char**)option[i].target, option[i].choice[j])) break;
1465 option[i].value = j + (option[i].choice[j] == NULL);
1469 XtSetArg(args[j], XtNfromVert, last); j++;
1470 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1471 XtSetArg(args[j], XtNwidth, option[i].max && !currentCps ? option[i].max : 100); j++;
1472 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1473 XtSetArg(args[j], XtNmenuName, XtNewString(option[i].name)); j++;
1474 XtSetArg(args[j], XtNlabel, ((char**)option[i].textValue)[option[i].value]); j++;
1475 option[i].handle = (void*)
1476 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1477 CreateComboPopup(last, option[i].name, i, (char **) option[i].textValue);
1478 values[i] = option[i].value;
1485 printf("GenericPopUp: unexpected case in switch.\n");
1490 // make an attempt to align all spins and textbox controls
1491 maxWidth = maxTextWidth = 0;
1492 for(h=0; h<height; h++) {
1494 if(option[i].type == EndMark) break;
1495 if(option[i].type == Spin || option[i].type == TextBox || option[i].type == ComboBox
1496 || option[i].type == PathName || option[i].type == FileName) {
1498 if(!texts[h]) continue;
1500 XtSetArg(args[j], XtNwidth, &w); j++;
1501 XtGetValues(texts[h], args, j);
1502 if(option[i].type == Spin) {
1503 if(w > maxWidth) maxWidth = w;
1506 if(w > maxTextWidth) maxTextWidth = w;
1507 if(!widest) widest = texts[h];
1511 if(maxTextWidth + 110 < maxWidth)
1512 maxTextWidth = maxWidth - 110;
1513 else maxWidth = maxTextWidth + 110;
1514 for(h=0; h<height; h++) {
1516 if(option[i].type == EndMark) break;
1517 if(!texts[h]) continue;
1519 if(option[i].type == Spin) {
1520 XtSetArg(args[j], XtNwidth, maxWidth); j++;
1521 XtSetValues(texts[h], args, j);
1523 if(option[i].type == TextBox || option[i].type == ComboBox || option[i].type == PathName || option[i].type == FileName) {
1524 XtSetArg(args[j], XtNwidth, maxTextWidth); j++;
1525 XtSetValues(texts[h], args, j);
1530 if(!(option[i].min & 2)) {
1532 if(option[i].min & 1) { XtSetArg(args[j], XtNfromHoriz, last); last = forelast; } else
1533 XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog); j++;
1534 XtSetArg(args[j], XtNfromVert, anchor ? anchor : last); j++;
1535 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1536 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1537 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1538 XtSetArg(args[j], XtNright, XtChainRight); j++;
1539 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1540 XtAddCallback(b_ok, XtNcallback, GenericCallback, (XtPointer) dlgNr);
1542 XtSetArg(args[0], XtNfromHoriz, b_ok);
1543 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1544 XtAddCallback(b_cancel, XtNcallback, GenericCallback, (XtPointer) dlgNr);
1547 XtRealizeWidget(popup);
1548 XSetWMProtocols(xDisplay, XtWindow(popup), &wm_delete_window, 1);
1549 snprintf(def, MSG_SIZ, "<Message>WM_PROTOCOLS: GenericPopDown(\"%d\") \n", dlgNr);
1550 XtAugmentTranslations(popup, XtParseTranslationTable(def));
1551 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1552 &x, &y, &win_x, &win_y, &mask);
1554 XtSetArg(args[0], XtNx, x - 10);
1555 XtSetArg(args[1], XtNy, y - 30);
1556 XtSetValues(popup, args, 2);
1558 XtPopup(popup, dlgNr ? XtGrabNone : XtGrabExclusive);
1559 shellUp[dlgNr] = True;
1561 if(textField)SetFocus(textField, popup, (XEvent*) NULL, False);
1562 if(dlgNr && wp[dlgNr] && wp[dlgNr]->width > 0) { // if persistent window-info available, reposition
1564 XtSetArg(args[j], XtNheight, (Dimension) (wp[dlgNr]->height)); j++;
1565 XtSetArg(args[j], XtNwidth, (Dimension) (wp[dlgNr]->width)); j++;
1566 XtSetArg(args[j], XtNx, (Position) (wp[dlgNr]->x)); j++;
1567 XtSetArg(args[j], XtNy, (Position) (wp[dlgNr]->y)); j++;
1568 XtSetValues(popup, args, j);
1574 void IcsOptionsProc(w, event, prms, nprms)
1580 GenericPopUp(icsOptions, _("ICS Options"), 0);
1583 void LoadOptionsProc(w, event, prms, nprms)
1589 GenericPopUp(loadOptions, _("Load Game Options"), 0);
1592 void SaveOptionsProc(w, event, prms, nprms)
1598 GenericPopUp(saveOptions, _("Save Game Options"), 0);
1601 void SoundOptionsProc(w, event, prms, nprms)
1607 soundFiles[2] = "*";
1608 GenericPopUp(soundOptions, _("Sound Options"), 0);
1611 void BoardOptionsProc(w, event, prms, nprms)
1617 GenericPopUp(boardOptions, _("Board Options"), 0);
1620 void EngineMenuProc(w, event, prms, nprms)
1626 GenericPopUp(adjudicationOptions, "Adjudicate non-ICS Games", 0);
1629 void UciMenuProc(w, event, prms, nprms)
1635 oldCores = appData.smpCores;
1636 oldPonder = appData.ponderNextMove;
1637 GenericPopUp(commonEngineOptions, _("Common Engine Settings"), 0);
1640 void NewVariantProc(w, event, prms, nprms)
1646 GenericPopUp(variantDescriptors, _("New Variant"), 0);
1649 void OptionsProc(w, event, prms, nprms)
1655 oldPonder = appData.ponderNextMove;
1656 GenericPopUp(generalOptions, _("General Options"), 0);
1659 void MatchOptionsProc(w, event, prms, nprms)
1665 GenericPopUp(matchOptions, _("Match Options"), 0);
1669 SettingsPopUp(ChessProgramState *cps)
1672 GenericPopUp(cps->option, _("Engine Settings"), 0);
1675 void FirstSettingsProc(w, event, prms, nprms)
1681 SettingsPopUp(&first);
1684 void SecondSettingsProc(w, event, prms, nprms)
1690 if(WaitForSecond(SettingsMenuIfReady)) return;
1691 SettingsPopUp(&second);
1694 //---------------------------- Chat Windows ----------------------------------------------
1696 void OutputChatMessage(int partner, char *mess)