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)
94 XtSetArg(args[0], XtNdisplayCaret, False);
95 XtSetValues(previous, args, 1);
97 XtSetArg(args[0], XtNstring, &s);
98 XtGetValues(w, args, 1);
100 XtSetArg(args[0], XtNdisplayCaret, True);
101 if(!strchr(s, '\n')) XtSetArg(args[1], XtNinsertPosition, strlen(s)), j++;
102 XtSetValues(w, args, j);
103 XtSetKeyboardFocus((Widget) data, w);
107 //--------------------------- Time-Control Menu Popup ----------------------------------
109 Widget TimeControlShell;
111 Widget tcMess1, tcMess2, tcData, tcTime, tcOdds1, tcOdds2;
112 int tcIncrement, tcMoves;
114 void TimeControlPopDown()
116 if (!TimeControlUp) return;
118 XtPopdown(TimeControlShell);
119 XtDestroyWidget(TimeControlShell);
120 TimeControlUp = False;
124 void TimeControlCallback(w, client_data, call_data)
126 XtPointer client_data, call_data;
133 XtSetArg(args[0], XtNlabel, &name);
134 XtGetValues(w, args, 1);
136 if (strcmp(name, _("classical")) == 0) {
137 if(tcInc == 0) return;
139 XtSetArg(args[j], XtNlabel, _("minutes for each")); j++;
140 XtSetValues(tcMess1, args, j);
142 XtSetArg(args[j], XtNlabel, _("moves")); j++;
143 XtSetValues(tcMess2, args, j);
146 XtSetArg(args[j], XtNstring, &name); j++;
147 XtGetValues(tcData, args, j);
148 tcIncrement = 0; sscanf(name, "%d", &tcIncrement);
150 snprintf(buf, MSG_SIZ, "%d", tcMoves);
152 XtSetArg(args[j], XtNstring, buf); j++;
153 XtSetValues(tcData, args, j);
157 if (strcmp(name, _("incremental")) == 0) {
158 if(tcInc == 1) return;
160 XtSetArg(args[j], XtNlabel, _("minutes, plus")); j++;
161 XtSetValues(tcMess1, args, j);
163 XtSetArg(args[j], XtNlabel, _("sec/move")); j++;
164 XtSetValues(tcMess2, args, j);
167 XtSetArg(args[j], XtNstring, &name); j++;
168 XtGetValues(tcData, args, j);
169 tcMoves = appData.movesPerSession; sscanf(name, "%d", &tcMoves);
171 snprintf(buf, MSG_SIZ, "%d", tcIncrement);
173 XtSetArg(args[j], XtNstring, buf); j++;
174 XtSetValues(tcData, args, j);
178 if (strcmp(name, _("fixed time")) == 0) {
179 if(tcInc == 2) return;
181 XtSetArg(args[j], XtNlabel, _("sec/move (max)")); j++;
182 XtSetValues(tcMess1, args, j);
184 XtSetArg(args[j], XtNlabel, ""); j++;
185 XtSetValues(tcMess2, args, j);
187 XtSetArg(args[j], XtNstring, ""); j++;
188 XtSetValues(tcData, args, j);
192 if (strcmp(name, _(" OK ")) == 0) {
194 XtSetArg(args[0], XtNstring, &txt);
195 XtGetValues(tcData, args, 1);
198 ok = sscanf(txt, "%d", &inc); mps = 0;
199 if(!ok && txt[0] == 0) { inc = 0; ok = 1; } // accept empty string as zero
203 ok = sscanf(txt, "%d", &mps); inc = -1;
207 ok = 1; inc = -1; mps = 40;
210 XtSetArg(args[0], XtNstring, ""); // erase any offending input
211 XtSetValues(tcData, args, 1);
214 XtSetArg(args[0], XtNstring, &txt);
215 XtGetValues(tcTime, args, 1);
217 if(sscanf(txt, "%d", &inc) != 1) {
218 XtSetArg(args[0], XtNstring, ""); // erase any offending input
219 XtSetValues(tcTime, args, 1);
220 DisplayError(_("Bad Time-Control String"), 0);
225 if(!ParseTimeControl(txt, inc, mps)) {
226 XtSetArg(args[0], XtNstring, ""); // erase any offending input
227 XtSetValues(tcTime, args, 1);
228 DisplayError(_("Bad Time-Control String"), 0);
232 appData.movesPerSession = mps;
233 appData.timeIncrement = inc;
234 appData.timeControl = strdup(txt);
236 XtSetArg(args[0], XtNstring, &txt);
237 XtGetValues(tcOdds1, args, 1);
238 appData.firstTimeOdds = first.timeOdds
239 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
240 XtGetValues(tcOdds2, args, 1);
241 appData.secondTimeOdds = second.timeOdds
242 = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1;
245 TimeControlPopDown();
250 void TimeControlPopUp()
253 Widget popup, layout, form, b_ok, b_cancel, b_clas, b_inc, mess;
260 tcInc = searchTime > 0 ? 2 : (appData.timeIncrement >= 0);
261 tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement;
262 if(!tcInc) tcIncrement = 0;
263 snprintf(def, MSG_SIZ, "%d", tcInc ? tcIncrement : tcMoves);
266 XtSetArg(args[i], XtNresizable, True); i++;
267 // XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
268 TimeControlShell = popup =
269 XtCreatePopupShell(_("TimeControl Menu"), transientShellWidgetClass,
270 shellWidget, args, i);
273 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
274 layoutArgs, XtNumber(layoutArgs));
277 XtCreateManagedWidget(layoutName, formWidgetClass, layout,
278 formArgs, XtNumber(formArgs));
281 // XtSetArg(args[j], XtNwidth, (XtArgVal) 300); j++;
282 // XtSetArg(args[j], XtNheight, (XtArgVal) 85); j++;
283 XtSetValues(popup, args, j);
286 XtSetArg(args[j], XtNborderWidth, 1); j++;
287 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
288 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
289 XtSetArg(args[j], XtNstring, appData.timeControl); j++;
290 XtSetArg(args[j], XtNdisplayCaret, False); j++;
291 XtSetArg(args[j], XtNtop, XtChainTop); j++;
292 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
293 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
294 XtSetArg(args[j], XtNright, XtChainRight); j++;
295 XtSetArg(args[j], XtNresizable, True); j++;
296 XtSetArg(args[j], XtNwidth, 85); j++;
297 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
298 tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j);
299 XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup);
302 XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _("sec/move (max) ") : _(" minutes, plus ") : _("minutes for each")); j++;
303 XtSetArg(args[j], XtNborderWidth, 0); j++;
304 XtSetArg(args[j], XtNfromHoriz, tcTime); j++;
305 XtSetArg(args[j], XtNtop, XtChainTop); j++;
306 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
307 XtSetArg(args[j], XtNleft, XtChainRight); j++;
308 XtSetArg(args[j], XtNright, XtChainRight); j++;
309 // XtSetArg(args[j], XtNwidth, 100); j++;
310 // XtSetArg(args[j], XtNheight, 20); j++;
311 tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j);
314 XtSetArg(args[j], XtNborderWidth, 1); j++;
315 XtSetArg(args[j], XtNfromHoriz, tcMess1); j++;
316 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
317 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
318 XtSetArg(args[j], XtNstring, def); j++;
319 XtSetArg(args[j], XtNdisplayCaret, False); j++;
320 XtSetArg(args[j], XtNtop, XtChainTop); j++;
321 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
322 XtSetArg(args[j], XtNleft, XtChainRight); j++;
323 XtSetArg(args[j], XtNright, XtChainRight); j++;
324 XtSetArg(args[j], XtNresizable, True); j++;
325 XtSetArg(args[j], XtNwidth, 40); j++;
326 // XtSetArg(args[j], XtNheight, 20); j++;
327 tcData = XtCreateManagedWidget("MPS", asciiTextWidgetClass, form, args, j);
328 XtAddEventHandler(tcData, ButtonPressMask, False, SetFocus, (XtPointer) popup);
331 XtSetArg(args[j], XtNlabel, tcInc ? tcInc == 2 ? _(" ") : _("sec/move") : _("moves ")); j++;
332 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
333 XtSetArg(args[j], XtNborderWidth, 0); j++;
334 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
335 XtSetArg(args[j], XtNtop, XtChainTop); j++;
336 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
337 XtSetArg(args[j], XtNleft, XtChainRight); j++;
338 XtSetArg(args[j], XtNright, XtChainRight); j++;
339 // XtSetArg(args[j], XtNwidth, 80); j++;
340 // XtSetArg(args[j], XtNheight, 20); j++;
341 tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass,
345 XtSetArg(args[j], XtNborderWidth, 1); j++;
346 XtSetArg(args[j], XtNfromVert, tcTime); j++;
347 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
348 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
349 XtSetArg(args[j], XtNstring, "1"); j++;
350 XtSetArg(args[j], XtNdisplayCaret, False); j++;
351 XtSetArg(args[j], XtNtop, XtChainTop); j++;
352 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
353 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
354 XtSetArg(args[j], XtNright, XtChainLeft); j++;
355 XtSetArg(args[j], XtNresizable, True); j++;
356 XtSetArg(args[j], XtNwidth, 40); j++;
357 // XtSetArg(args[j], XtNheight, 20); j++;
358 tcOdds1 = XtCreateManagedWidget("Odds1", asciiTextWidgetClass, form, args, j);
359 XtAddEventHandler(tcOdds1, ButtonPressMask, False, SetFocus, (XtPointer) popup);
362 XtSetArg(args[j], XtNborderWidth, 1); j++;
363 XtSetArg(args[j], XtNfromVert, tcTime); j++;
364 XtSetArg(args[j], XtNfromHoriz, tcOdds1); j++;
365 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
366 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
367 XtSetArg(args[j], XtNstring, "1"); j++;
368 XtSetArg(args[j], XtNdisplayCaret, False); j++;
369 XtSetArg(args[j], XtNtop, XtChainTop); j++;
370 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
371 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
372 XtSetArg(args[j], XtNright, XtChainLeft); j++;
373 XtSetArg(args[j], XtNresizable, True); j++;
374 XtSetArg(args[j], XtNwidth, 40); j++;
375 // XtSetArg(args[j], XtNheight, 20); j++;
376 tcOdds2 = XtCreateManagedWidget("Odds2", asciiTextWidgetClass, form, args, j);
377 XtAddEventHandler(tcOdds2, ButtonPressMask, False, SetFocus, (XtPointer) popup);
380 XtSetArg(args[j], XtNlabel, _("Engine #1 and #2 Time-Odds Factors")); j++;
381 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
382 XtSetArg(args[j], XtNborderWidth, 0); j++;
383 XtSetArg(args[j], XtNfromVert, tcTime); j++;
384 XtSetArg(args[j], XtNfromHoriz, tcOdds2); j++;
385 XtSetArg(args[j], XtNtop, XtChainTop); j++;
386 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
387 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
388 XtSetArg(args[j], XtNright, XtChainRight); j++;
389 // XtSetArg(args[j], XtNwidth, 200); j++;
390 // XtSetArg(args[j], XtNheight, 20); j++;
391 mess = XtCreateManagedWidget("Oddstext", labelWidgetClass,
394 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
395 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
396 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
397 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
398 XtSetArg(args[j], XtNright, XtChainLeft); j++;
399 XtSetArg(args[j], XtNstate, tcInc==0); j++;
400 b_clas= XtCreateManagedWidget(_("classical"), toggleWidgetClass,
402 XtAddCallback(b_clas, XtNcallback, TimeControlCallback, (XtPointer) 0);
405 XtSetArg(args[j], XtNradioGroup, b_clas); j++;
406 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
407 XtSetArg(args[j], XtNfromHoriz, b_clas); j++;
408 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
409 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
410 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
411 XtSetArg(args[j], XtNright, XtChainLeft); j++;
412 XtSetArg(args[j], XtNstate, tcInc==1); j++;
413 b_inc = XtCreateManagedWidget(_("incremental"), toggleWidgetClass,
415 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
418 XtSetArg(args[j], XtNradioGroup, b_inc); j++;
419 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
420 XtSetArg(args[j], XtNfromHoriz, b_inc); j++;
421 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
422 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
423 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
424 XtSetArg(args[j], XtNright, XtChainLeft); j++;
425 XtSetArg(args[j], XtNstate, tcInc==2); j++;
426 b_inc = XtCreateManagedWidget(_("fixed time"), toggleWidgetClass,
428 XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0);
431 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
432 XtSetArg(args[j], XtNfromHoriz, tcData); j++;
433 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
434 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
435 XtSetArg(args[j], XtNleft, XtChainRight); j++;
436 XtSetArg(args[j], XtNright, XtChainRight); j++;
437 b_ok= XtCreateManagedWidget(_(" OK "), commandWidgetClass,
439 XtAddCallback(b_ok, XtNcallback, TimeControlCallback, (XtPointer) 0);
442 XtSetArg(args[j], XtNfromVert, tcOdds1); j++;
443 XtSetArg(args[j], XtNfromHoriz, b_ok); j++;
444 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
445 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
446 XtSetArg(args[j], XtNleft, XtChainRight); j++;
447 XtSetArg(args[j], XtNright, XtChainRight); j++;
448 b_cancel= XtCreateManagedWidget(_("cancel"), commandWidgetClass,
450 XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0);
452 XtRealizeWidget(popup);
453 CatchDeleteWindow(popup, "TimeControlPopDown");
455 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
456 &x, &y, &win_x, &win_y, &mask);
458 XtSetArg(args[0], XtNx, x - 10);
459 XtSetArg(args[1], XtNy, y - 30);
460 XtSetValues(popup, args, 2);
462 XtPopup(popup, XtGrabExclusive);
463 TimeControlUp = True;
466 SetFocus(tcTime, popup, (XEvent*) NULL, False);
467 // XtSetKeyboardFocus(popup, tcTime);
470 void TimeControlProc(w, event, prms, nprms)
479 //--------------------------- Engine-specific options menu ----------------------------------
481 typedef void ButtonCallback(int n);
482 typedef int OKCallback(int n);
484 int values[MAX_OPTIONS];
485 ChessProgramState *currentCps;
486 static Option *currentOption;
487 static Boolean browserUp;
488 ButtonCallback *comboCallback;
490 void GetWidgetText(Option *opt, char **buf)
493 XtSetArg(arg, XtNstring, buf);
494 XtGetValues(opt->handle, &arg, 1);
497 void SetWidgetText(Option *opt, char *buf, int n)
500 XtSetArg(arg, XtNstring, buf);
501 XtSetValues(opt->handle, &arg, 1);
502 SetFocus(opt->handle, shells[n], NULL, False);
505 void SetWidgetState(Option *opt, int state)
508 XtSetArg(arg, XtNstate, state);
509 XtSetValues(opt->handle, &arg, 1);
512 void CheckCallback(Widget ww, XtPointer data, XEvent *event, Boolean *b)
514 Widget w = currentOption[(int)(intptr_t)data].handle;
518 XtSetArg(args[0], XtNstate, &s);
519 XtGetValues(w, args, 1);
520 SetWidgetState(¤tOption[(int)(intptr_t)data], !s);
523 void SpinCallback(w, client_data, call_data)
525 XtPointer client_data, call_data;
529 char buf[MSG_SIZ], *p;
531 int data = (intptr_t) client_data;
533 XtSetArg(args[0], XtNlabel, &name);
534 XtGetValues(w, args, 1);
536 GetWidgetText(¤tOption[data], &val);
537 sscanf(val, "%d", &j);
538 if (strcmp(name, "browse") == 0) {
540 for(r = ""; *q; q++) if(*q == '.') r = q; else if(*q == '/') r = ""; // last dot after last slash
541 if(!strcmp(r, "") && !currentCps && currentOption[data].type == FileName && currentOption[data].textValue)
542 r = currentOption[data].textValue;
544 if(XsraSelFile(shells[0], currentOption[data].name, NULL, NULL, "", "", r,
545 currentOption[data].type == PathName ? "p" : "f", NULL, &p)) {
547 if(len && p[len-1] == '/') p[len-1] = NULLCHAR;
548 XtSetArg(args[0], XtNstring, p);
549 XtSetValues(currentOption[data].handle, args, 1);
552 SetFocus(currentOption[data].handle, shells[0], (XEvent*) NULL, False);
555 if (strcmp(name, "+") == 0) {
556 if(++j > currentOption[data].max) return;
558 if (strcmp(name, "-") == 0) {
559 if(--j < currentOption[data].min) return;
561 snprintf(buf, MSG_SIZ, "%d", j);
562 SetWidgetText(¤tOption[data], buf, 0);
565 void ComboSelect(w, addr, index) // callback for all combo items
571 int i = ((intptr_t)addr)>>8;
572 int j = 255 & (intptr_t) addr;
574 values[i] = j; // store in temporary, for transfer at OK
575 XtSetArg(args[0], XtNlabel, _(((char**)currentOption[i].textValue)[j]));
576 XtSetValues(currentOption[i].handle, args, 1);
578 if(currentOption[i].min & 1 && !currentCps && comboCallback) (comboCallback)(i);
581 void CreateComboPopup(parent, name, n, mb)
591 menu = XtCreatePopupShell(name, simpleMenuWidgetClass,
594 XtSetArg(args[j], XtNwidth, 100); j++;
595 // XtSetArg(args[j], XtNright, XtChainRight); j++;
596 while (mb[i] != NULL) {
597 XtSetArg(args[j], XtNlabel, _(mb[i]));
598 entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass,
600 XtAddCallback(entry, XtNcallback,
601 (XtCallbackProc) ComboSelect,
602 (caddr_t)(intptr_t) (256*n+i));
608 //----------------------------Generic dialog --------------------------------------------
610 // cloned from Engine Settings dialog (and later merged with it)
612 extern WindowPlacement wpComment, wpTags;
614 static int oldCores, oldPonder;
615 int MakeColors P((void));
616 void CreateGCs P((int redo));
617 void CreateAnyPieces P((void));
618 int GenericReadout P((int selected));
622 WindowPlacement *wp[10] = { NULL, &wpComment, &wpTags };
623 Option *dialogOptions[10];
625 void MarkMenu(char *item, int dlgNr)
628 XtSetArg(args[0], XtNleftBitmap, xMarkPixmap);
629 XtSetValues(marked[dlgNr] = XtNameToWidget(menuBarWidget, item), args, 1);
636 Dimension windowH, windowW; Position windowX, windowY;
637 if (!shellUp[n]) return 0;
638 if(n && wp[n]) { // remember position
640 XtSetArg(args[j], XtNx, &windowX); j++;
641 XtSetArg(args[j], XtNy, &windowY); j++;
642 XtSetArg(args[j], XtNheight, &windowH); j++;
643 XtSetArg(args[j], XtNwidth, &windowW); j++;
644 XtGetValues(shells[n], args, j);
647 wp[n]->width = windowW;
648 wp[n]->height = windowH;
651 XtPopdown(shells[n]);
652 if(n == 0) XtDestroyWidget(shells[n]);
655 XtSetArg(args[0], XtNleftBitmap, None);
656 XtSetValues(marked[n], args, 1);
658 if(!n) currentCps = NULL; // if an Engine Settings dialog was up, we must be popping it down now
662 void GenericPopDown(w, event, prms, nprms)
668 if(browserUp) return; // prevent closing dialog when it has an open file-browse daughter
669 PopDown(prms[0][0] - '0');
672 char *engineName, *engineDir, *engineChoice, *engineLine, *nickName, *params, *tfName;
673 Boolean isUCI, hasBook, storeVariant, v1, addToList, useNick;
674 extern Option installOptions[], matchOptions[];
675 char *engineNr[] = { N_("First Engine"), N_("Second Engine"), NULL };
676 char *engineList[100] = {" "}, *engineMnemonic[100] = {""};
678 void AddLine(Option *opt, char *s)
681 t.ptr = s; t.firstPos = 0; t.length = strlen(s); t.format = XawFmt8Bit;
682 XawTextReplace(opt->handle, 9999, 9999, &t);
683 t.ptr = "\n"; t.length = 1;
684 XawTextReplace(opt->handle, 9999, 9999, &t);
687 void AddToTourney(int n)
689 GenericReadout(4); // selected engine
690 AddLine(&matchOptions[3], engineChoice);
695 if(appData.participants && appData.participants[0]) free(appData.participants);
696 appData.participants = strdup(engineName);
697 if(!CreateTourney(tfName)) return !appData.participants[0];
698 PopDown(0); // early popdown to prevent FreezeUI called through MatchEvent from causing XtGrab warning
699 MatchEvent(2); // start tourney
703 Option matchOptions[] = {
704 { 0, 0, 0, NULL, (void*) &tfName, ".trn", NULL, FileName, N_("Tournament file:") },
705 { 0, 0, 0, NULL, (void*) &appData.roundSync, "", NULL, CheckBox, N_("Sync after round (for concurrent playing of a single") },
706 { 0, 0, 0, NULL, (void*) &appData.cycleSync, "", NULL, CheckBox, N_("Sync after cycle tourney with multiple XBoards)") },
707 { 0xD, 150, 0, NULL, (void*) &engineName, "", NULL, TextBox, "Tourney participants:" },
708 { 0, 1, 0, NULL, (void*) &engineChoice, (char*) (engineMnemonic+1), (engineMnemonic+1), ComboBox, N_("Select Engine:") },
709 { 0, 0, 10, NULL, (void*) &appData.tourneyType, "", NULL, Spin, N_("Tourney type (0 = round-robin, 1 = gauntlet):") },
710 { 0, 1, 1000000000, NULL, (void*) &appData.tourneyCycles, "", NULL, Spin, N_("Number of tourney cycles (or Swiss rounds):") },
711 { 0, 1, 1000000000, NULL, (void*) &appData.defaultMatchGames, "", NULL, Spin, N_("Default Number of Games in Match (or Pairing):") },
712 { 0, 0, 1000000000, NULL, (void*) &appData.matchPause, "", NULL, Spin, N_("Pause between Match Games (msec):") },
713 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, ".pgn", NULL, FileName, N_("Save Tourney Games on:") },
714 { 0, 0, 0, NULL, (void*) &appData.loadGameFile, ".pgn", NULL, FileName, N_("Game File with Opening Lines:") },
715 { 0, -2, 1000000000, NULL, (void*) &appData.loadGameIndex, "", NULL, Spin, N_("Game Number (-1 or -2 = Auto-Increment):") },
716 { 0, 0, 0, NULL, (void*) &appData.loadPositionFile, ".fen", NULL, FileName, N_("File with Start Positions:") },
717 { 0, -2, 1000000000, NULL, (void*) &appData.loadPositionIndex, "", NULL, Spin, N_("Position Number (-1 or -2 = Auto-Increment):") },
718 { 0, 0, 1000000000, NULL, (void*) &appData.rewindIndex, "", NULL, Spin, N_("Rewind Index after this many Games (0 = never):") },
719 { 0, 0, 0, NULL, (void*) &MatchOK, "", NULL, EndMark , "" }
722 int GeneralOptionsOK(int n)
724 int newPonder = appData.ponderNextMove;
725 appData.ponderNextMove = oldPonder;
726 PonderNextMoveEvent(newPonder);
730 Option generalOptions[] = {
731 { 0, 0, 0, NULL, (void*) &appData.sweepSelect, "", NULL, CheckBox, N_("Almost Always Queen (Detour Under-Promote)") },
732 { 0, 0, 0, NULL, (void*) &appData.animateDragging, "", NULL, CheckBox, N_("Animate Dragging") },
733 { 0, 0, 0, NULL, (void*) &appData.animate, "", NULL, CheckBox, N_("Animate Moving") },
734 { 0, 0, 0, NULL, (void*) &appData.autoCallFlag, "", NULL, CheckBox, N_("Auto Flag") },
735 { 0, 0, 0, NULL, (void*) &appData.autoFlipView, "", NULL, CheckBox, N_("Auto Flip View") },
736 { 0, 0, 0, NULL, (void*) &appData.blindfold, "", NULL, CheckBox, N_("Blindfold") },
737 { 0, 0, 0, NULL, (void*) &appData.dropMenu, "", NULL, CheckBox, N_("Drop Menu") },
738 { 0, 0, 0, NULL, (void*) &appData.hideThinkingFromHuman, "", NULL, CheckBox, N_("Hide Thinking from Human") },
739 { 0, 0, 0, NULL, (void*) &appData.highlightDragging, "", NULL, CheckBox, N_("Highlight Dragging (Show Move Targets)") },
740 { 0, 0, 0, NULL, (void*) &appData.highlightLastMove, "", NULL, CheckBox, N_("Highlight Last Move") },
741 { 0, 0, 0, NULL, (void*) &appData.highlightMoveWithArrow, "", NULL, CheckBox, N_("Highlight with Arrow") },
742 { 0, 0, 0, NULL, (void*) &appData.ringBellAfterMoves, "", NULL, CheckBox, N_("Move Sound") },
743 { 0, 0, 0, NULL, (void*) &appData.oneClick, "", NULL, CheckBox, N_("One-Click Moving") },
744 { 0, 0, 0, NULL, (void*) &appData.periodicUpdates, "", NULL, CheckBox, N_("Periodic Updates (in Analysis Mode)") },
745 { 0, 0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, N_("Ponder Next Move") },
746 { 0, 0, 0, NULL, (void*) &appData.popupExitMessage, "", NULL, CheckBox, N_("Popup Exit Messages") },
747 { 0, 0, 0, NULL, (void*) &appData.popupMoveErrors, "", NULL, CheckBox, N_("Popup Move Errors") },
748 { 0, 0, 0, NULL, (void*) &appData.showCoords, "", NULL, CheckBox, N_("Show Coordinates") },
749 { 0, 0, 0, NULL, (void*) &appData.markers, "", NULL, CheckBox, N_("Show Target Squares") },
750 { 0, 0, 0, NULL, (void*) &appData.testLegality, "", NULL, CheckBox, N_("Test Legality") },
751 { 0, 0, 10, NULL, (void*) &appData.flashCount, "", NULL, Spin, N_("Flash Moves (0 = no flashing):") },
752 { 0, 1, 10, NULL, (void*) &appData.flashRate, "", NULL, Spin, N_("Flash Rate (high = fast):") },
753 { 0, 5, 100,NULL, (void*) &appData.animSpeed, "", NULL, Spin, N_("Animation Speed (high = slow):") },
754 { 0, 0, 0, NULL, (void*) &GeneralOptionsOK, "", NULL, EndMark , "" }
759 VariantClass v = currentOption[n].value;
760 if(!appData.noChessProgram) {
761 char *name = VariantName(v), buf[MSG_SIZ];
762 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
763 /* [HGM] in protocol 2 we check if variant is suported by engine */
764 snprintf(buf, MSG_SIZ, _("Variant %s not supported by %s"), name, first.tidy);
765 DisplayError(buf, 0);
766 return; /* ignore OK if first engine does not support it */
768 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
769 snprintf(buf, MSG_SIZ, _("Warning: second engine (%s) does not support this!"), second.tidy);
770 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
774 GenericReadout(-1); // make sure ranks and file settings are read
776 gameInfo.variant = v;
777 appData.variant = VariantName(v);
779 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
780 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
781 appData.pieceToCharTable = NULL;
782 appData.pieceNickNames = "";
783 appData.colorNickNames = "";
789 Option variantDescriptors[] = {
790 { VariantNormal, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("normal")},
791 { VariantFairy, 1, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("fairy")},
792 { VariantFischeRandom, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("FRC")},
793 { VariantSChess, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Seirawan")},
794 { VariantWildCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("wild castle")},
795 { VariantSuper, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Superchess")},
796 { VariantNoCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("no castle")},
797 { VariantCrazyhouse, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("crazyhouse")},
798 { VariantKnightmate, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("knightmate")},
799 { VariantBughouse, 1, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("bughouse")},
800 { VariantBerolina, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("berolina")},
801 { VariantShogi, 1, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("shogi (9x9)")},
802 { VariantCylinder, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("cylinder")},
803 { VariantXiangqi, 1, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("xiangqi (9x10)")},
804 { VariantShatranj, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("shatranj")},
805 { VariantCourier, 1, 135, NULL, (void*) &Pick, "#BFFFBF", NULL, Button, N_("courier (12x8)")},
806 { VariantMakruk, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("makruk")},
807 { VariantGreat, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Great Shatranj (10x8)")},
808 { VariantAtomic, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("atomic")},
809 { VariantCapablanca, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Capablanca (10x8)")},
810 { VariantTwoKings, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("two kings")},
811 { VariantGothic, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Gothic (10x8)")},
812 { Variant3Check, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("3-checks")},
813 { VariantJanus, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("janus (10x8)")},
814 { VariantSuicide, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("suicide")},
815 { VariantCapaRandom, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("CRC (10x8)")},
816 { VariantGiveaway, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("give-away")},
817 { VariantSpartan, 1, 135, NULL, (void*) &Pick, "#FF0000", NULL, Button, N_("Spartan")},
818 { VariantLosers, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("losers")},
819 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Board size ( -1 = default for selected variant):")},
820 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.NrRanks, "", NULL, Spin, N_("Number of Board Ranks:") },
821 { 0, -1, BOARD_FILES, NULL, (void*) &appData.NrFiles, "", NULL, Spin, N_("Number of Board Files:") },
822 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.holdingsSize, "", NULL, Spin, N_("Holdings Size:") },
823 { 0, 0, 0, NULL, NULL, NULL, NULL, Label,
824 N_("WARNING: variants with un-orthodox\n"
825 "pieces only have built-in bitmaps\n"
826 "for -boardSize middling, bulky and\n"
827 "petite, and substitute king or amazon\n"
828 "for missing bitmaps. (See manual.)")},
829 { 0, 2, 0, NULL, NULL, "", NULL, EndMark , "" }
832 int CommonOptionsOK(int n)
834 int newPonder = appData.ponderNextMove;
835 // make sure changes are sent to first engine by re-initializing it
836 // if it was already started pre-emptively at end of previous game
837 if(gameMode == BeginningOfGame) Reset(True, True); else {
838 // Some changed setting need immediate sending always.
839 if(oldCores != appData.smpCores)
840 NewSettingEvent(False, &(first.maxCores), "cores", appData.smpCores);
841 appData.ponderNextMove = oldPonder;
842 PonderNextMoveEvent(newPonder);
847 Option commonEngineOptions[] = {
848 { 0, 0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, N_("Ponder Next Move") },
849 { 0, 0, 1000, NULL, (void*) &appData.smpCores, "", NULL, Spin, N_("Maximum Number of CPUs per Engine:") },
850 { 0, 0, 0, NULL, (void*) &appData.polyglotDir, "", NULL, PathName, N_("Polygot Directory:") },
851 { 0, 0, 16000, NULL, (void*) &appData.defaultHashSize, "", NULL, Spin, N_("Hash-Table Size (MB):") },
852 { 0, 0, 0, NULL, (void*) &appData.defaultPathEGTB, "", NULL, PathName, N_("Nalimov EGTB Path:") },
853 { 0, 0, 1000, NULL, (void*) &appData.defaultCacheSizeEGTB, "", NULL, Spin, N_("EGTB Cache Size (MB):") },
854 { 0, 0, 0, NULL, (void*) &appData.usePolyglotBook, "", NULL, CheckBox, N_("Use GUI Book") },
855 { 0, 0, 0, NULL, (void*) &appData.polyglotBook, ".bin", NULL, FileName, N_("Opening-Book Filename:") },
856 { 0, 0, 100, NULL, (void*) &appData.bookDepth, "", NULL, Spin, N_("Book Depth (moves):") },
857 { 0, 0, 100, NULL, (void*) &appData.bookStrength, "", NULL, Spin, N_("Book Variety (0) vs. Strength (100):") },
858 { 0, 0, 0, NULL, (void*) &appData.firstHasOwnBookUCI, "", NULL, CheckBox, N_("Engine #1 Has Own Book") },
859 { 0, 0, 0, NULL, (void*) &appData.secondHasOwnBookUCI, "", NULL, CheckBox, N_("Engine #2 Has Own Book ") },
860 { 0, 1, 0, NULL, (void*) &CommonOptionsOK, "", NULL, EndMark , "" }
863 Option adjudicationOptions[] = {
864 { 0, 0, 0, NULL, (void*) &appData.checkMates, "", NULL, CheckBox, N_("Detect all Mates") },
865 { 0, 0, 0, NULL, (void*) &appData.testClaims, "", NULL, CheckBox, N_("Verify Engine Result Claims") },
866 { 0, 0, 0, NULL, (void*) &appData.materialDraws, "", NULL, CheckBox, N_("Draw if Insufficient Mating Material") },
867 { 0, 0, 0, NULL, (void*) &appData.trivialDraws, "", NULL, CheckBox, N_("Adjudicate Trivial Draws (3-Move Delay)") },
868 { 0, 0, 100, NULL, (void*) &appData.ruleMoves, "", NULL, Spin, N_("N-Move Rule:") },
869 { 0, 0, 6, NULL, (void*) &appData.drawRepeats, "", NULL, Spin, N_("N-fold Repeats:") },
870 { 0, 0, 1000, NULL, (void*) &appData.adjudicateDrawMoves, "", NULL, Spin, N_("Draw after N Moves Total:") },
871 { 0,-5000, 0, NULL, (void*) &appData.adjudicateLossThreshold, "", NULL, Spin, N_("Win / Loss Threshold:") },
872 { 0, 0, 0, NULL, (void*) &first.scoreIsAbsolute, "", NULL, CheckBox, N_("Negate Score of Engine #1") },
873 { 0, 0, 0, NULL, (void*) &second.scoreIsAbsolute, "", NULL, CheckBox, N_("Negate Score of Engine #2") },
874 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
877 int IcsOptionsOK(int n)
879 ParseIcsTextColors();
883 Option icsOptions[] = {
884 { 0, 0, 0, NULL, (void*) &appData.autoKibitz, "", NULL, CheckBox, N_("Auto-Kibitz") },
885 { 0, 0, 0, NULL, (void*) &appData.autoComment, "", NULL, CheckBox, N_("Auto-Comment") },
886 { 0, 0, 0, NULL, (void*) &appData.autoObserve, "", NULL, CheckBox, N_("Auto-Observe") },
887 { 0, 0, 0, NULL, (void*) &appData.autoRaiseBoard, "", NULL, CheckBox, N_("Auto-Raise Board") },
888 { 0, 0, 0, NULL, (void*) &appData.bgObserve, "", NULL, CheckBox, N_("Background Observe while Playing") },
889 { 0, 0, 0, NULL, (void*) &appData.dualBoard, "", NULL, CheckBox, N_("Dual Board for Background-Observed Game") },
890 { 0, 0, 0, NULL, (void*) &appData.getMoveList, "", NULL, CheckBox, N_("Get Move List") },
891 { 0, 0, 0, NULL, (void*) &appData.quietPlay, "", NULL, CheckBox, N_("Quiet Play") },
892 { 0, 0, 0, NULL, (void*) &appData.seekGraph, "", NULL, CheckBox, N_("Seek Graph") },
893 { 0, 0, 0, NULL, (void*) &appData.autoRefresh, "", NULL, CheckBox, N_("Auto-Refresh Seek Graph") },
894 { 0, 0, 0, NULL, (void*) &appData.premove, "", NULL, CheckBox, N_("Premove") },
895 { 0, 0, 0, NULL, (void*) &appData.premoveWhite, "", NULL, CheckBox, N_("Premove for White") },
896 { 0, 0, 0, NULL, (void*) &appData.premoveWhiteText, "", NULL, TextBox, N_("First White Move:") },
897 { 0, 0, 0, NULL, (void*) &appData.premoveBlack, "", NULL, CheckBox, N_("Premove for Black") },
898 { 0, 0, 0, NULL, (void*) &appData.premoveBlackText, "", NULL, TextBox, N_("First Black Move:") },
899 { 0, 0, 0, NULL, NULL, NULL, NULL, Break, "" },
900 { 0, 0, 0, NULL, (void*) &appData.icsAlarm, "", NULL, CheckBox, N_("Alarm") },
901 { 0, 0, 100000000, NULL, (void*) &appData.icsAlarmTime, "", NULL, Spin, N_("Alarm Time (msec):") },
902 //{ 0, 0, 0, NULL, (void*) &appData.chatBoxes, "", NULL, TextBox, N_("Startup Chat Boxes:") },
903 { 0, 0, 0, NULL, (void*) &appData.colorize, "", NULL, CheckBox, N_("Colorize Messages") },
904 { 0, 0, 0, NULL, (void*) &appData.colorShout, "", NULL, TextBox, N_("Shout Text Colors:") },
905 { 0, 0, 0, NULL, (void*) &appData.colorSShout, "", NULL, TextBox, N_("S-Shout Text Colors:") },
906 { 0, 0, 0, NULL, (void*) &appData.colorChannel1, "", NULL, TextBox, N_("Channel #1 Text Colors:") },
907 { 0, 0, 0, NULL, (void*) &appData.colorChannel, "", NULL, TextBox, N_("Other Channel Text Colors:") },
908 { 0, 0, 0, NULL, (void*) &appData.colorKibitz, "", NULL, TextBox, N_("Kibitz Text Colors:") },
909 { 0, 0, 0, NULL, (void*) &appData.colorTell, "", NULL, TextBox, N_("Tell Text Colors:") },
910 { 0, 0, 0, NULL, (void*) &appData.colorChallenge, "", NULL, TextBox, N_("Challenge Text Colors:") },
911 { 0, 0, 0, NULL, (void*) &appData.colorRequest, "", NULL, TextBox, N_("Request Text Colors:") },
912 { 0, 0, 0, NULL, (void*) &appData.colorSeek, "", NULL, TextBox, N_("Seek Text Colors:") },
913 { 0, 0, 0, NULL, (void*) &IcsOptionsOK, "", NULL, EndMark , "" }
916 Option loadOptions[] = {
917 { 0, 0, 0, NULL, (void*) &appData.autoDisplayTags, "", NULL, CheckBox, N_("Auto-Display Tags") },
918 { 0, 0, 0, NULL, (void*) &appData.autoDisplayComment, "", NULL, CheckBox, N_("Auto-Display Comment") },
919 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Auto-Play speed of loaded games\n(0 = instant, -1 = off):") },
920 { 0, -1, 10000000, NULL, (void*) &appData.timeDelay, "", NULL, Fractional, N_("Seconds per Move:") },
921 { 0, 0, 0, NULL, NULL, "", NULL, EndMark , "" }
924 Option saveOptions[] = {
925 { 0, 0, 0, NULL, (void*) &appData.autoSaveGames, "", NULL, CheckBox, N_("Auto-Save Games") },
926 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, ".pgn", NULL, FileName, N_("Save Games on File:") },
927 { 0, 0, 0, NULL, (void*) &appData.savePositionFile, ".fen", NULL, FileName, N_("Save Final Positions on File:") },
928 { 0, 0, 0, NULL, (void*) &appData.pgnEventHeader, "", NULL, TextBox, N_("PGN Event Header:") },
929 { 0, 0, 0, NULL, (void*) &appData.oldSaveStyle, "", NULL, CheckBox, N_("Old Save Style (as opposed to PGN)") },
930 { 0, 0, 0, NULL, (void*) &appData.saveExtendedInfoInPGN, "", NULL, CheckBox, N_("Save Score/Depth Info in PGN") },
931 { 0, 0, 0, NULL, (void*) &appData.saveOutOfBookInfo, "", NULL, CheckBox, N_("Save Out-of-Book Info in PGN ") },
932 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
935 char *soundNames[] = {
938 N_("Above WAV File"),
953 char *soundFiles[] = { // sound files corresponding to above names
956 "*", // kludge alert: as first thing in the dialog readout this is replaced with the user-given .WAV filename
974 if(soundFiles[values[3]]) PlaySound(soundFiles[values[3]]);
977 Option soundOptions[] = {
978 { 0, 0, 0, NULL, (void*) &appData.soundProgram, "", NULL, TextBox, N_("Sound Program:") },
979 { 0, 0, 0, NULL, (void*) &appData.soundDirectory, "", NULL, PathName, N_("Sounds Directory:") },
980 { 0, 0, 0, NULL, (void*) (soundFiles+2) /* kludge! */, ".wav", NULL, FileName, N_("User WAV File:") },
981 { 0, 0, 0, NULL, (void*) &trialSound, (char*) soundNames, soundFiles, ComboBox, N_("Try-Out Sound:") },
982 { 0, 1, 0, NULL, (void*) &Test, NULL, NULL, Button, N_("Play") },
983 { 0, 0, 0, NULL, (void*) &appData.soundMove, (char*) soundNames, soundFiles, ComboBox, N_("Move:") },
984 { 0, 0, 0, NULL, (void*) &appData.soundIcsWin, (char*) soundNames, soundFiles, ComboBox, N_("Win:") },
985 { 0, 0, 0, NULL, (void*) &appData.soundIcsLoss, (char*) soundNames, soundFiles, ComboBox, N_("Lose:") },
986 { 0, 0, 0, NULL, (void*) &appData.soundIcsDraw, (char*) soundNames, soundFiles, ComboBox, N_("Draw:") },
987 { 0, 0, 0, NULL, (void*) &appData.soundIcsUnfinished, (char*) soundNames, soundFiles, ComboBox, N_("Unfinished:") },
988 { 0, 0, 0, NULL, (void*) &appData.soundIcsAlarm, (char*) soundNames, soundFiles, ComboBox, N_("Alarm:") },
989 { 0, 0, 0, NULL, (void*) &appData.soundShout, (char*) soundNames, soundFiles, ComboBox, N_("Shout:") },
990 { 0, 0, 0, NULL, (void*) &appData.soundSShout, (char*) soundNames, soundFiles, ComboBox, N_("S-Shout:") },
991 { 0, 0, 0, NULL, (void*) &appData.soundChannel, (char*) soundNames, soundFiles, ComboBox, N_("Channel:") },
992 { 0, 0, 0, NULL, (void*) &appData.soundChannel1, (char*) soundNames, soundFiles, ComboBox, N_("Channel 1:") },
993 { 0, 0, 0, NULL, (void*) &appData.soundTell, (char*) soundNames, soundFiles, ComboBox, N_("Tell:") },
994 { 0, 0, 0, NULL, (void*) &appData.soundKibitz, (char*) soundNames, soundFiles, ComboBox, N_("Kibitz:") },
995 { 0, 0, 0, NULL, (void*) &appData.soundChallenge, (char*) soundNames, soundFiles, ComboBox, N_("Challenge:") },
996 { 0, 0, 0, NULL, (void*) &appData.soundRequest, (char*) soundNames, soundFiles, ComboBox, N_("Request:") },
997 { 0, 0, 0, NULL, (void*) &appData.soundSeek, (char*) soundNames, soundFiles, ComboBox, N_("Seek:") },
998 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
1001 void SetColor(char *colorName, Option *box)
1005 XrmValue vFrom, vTo;
1006 if (!appData.monoMode) {
1007 vFrom.addr = (caddr_t) colorName;
1008 vFrom.size = strlen(colorName);
1009 XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
1010 if (vTo.addr == NULL) {
1011 buttonColor = (Pixel) -1;
1013 buttonColor = *(Pixel *) vTo.addr;
1015 } else buttonColor = (Pixel) 0;
1016 XtSetArg(args[0], XtNbackground, buttonColor);;
1017 XtSetValues(box->handle, args, 1);
1020 void SetColorText(int n, char *buf)
1022 SetWidgetText(¤tOption[n-1], buf, 0);
1023 SetColor(buf, ¤tOption[n]);
1026 void DefColor(int n)
1028 SetColorText(n, (char*) currentOption[n].choice);
1031 void RefreshColor(int source, int n)
1033 int col, j, r, g, b, step = 10;
1034 char *s, buf[MSG_SIZ]; // color string
1036 GetWidgetText(¤tOption[source], &s);
1037 if(sscanf(s, "#%x", &col) != 1) return; // malformed
1038 b = col & 0xFF; g = col & 0xFF00; r = col & 0xFF0000;
1040 case 1: r += 0x10000*step;break;
1041 case 2: g += 0x100*step; break;
1042 case 3: b += step; break;
1043 case 4: r -= 0x10000*step; g -= 0x100*step; b -= step; break;
1045 if(r < 0) r = 0; if(g < 0) g = 0; if(b < 0) b = 0;
1046 if(r > 0xFF0000) r = 0xFF0000; if(g > 0xFF00) g = 0xFF00; if(b > 0xFF) b = 0xFF;
1048 snprintf(buf, MSG_SIZ, "#%06x", col);
1049 for(j=1; j<7; j++) if(buf[j] >= 'a') buf[j] -= 32; // capitalize
1050 SetColorText(source+1, buf);
1053 void ColorChanged(Widget w, XtPointer data, XEvent *event, Boolean *b)
1056 if ( (XLookupString(&(event->xkey), buf, 2, NULL, NULL) == 1) && *buf == '\r' )
1057 RefreshColor((int)(intptr_t) data, 0);
1060 void AdjustColor(int i)
1062 int n = currentOption[i].value;
1063 RefreshColor(i-n-1, n);
1066 int BoardOptionsOK(int n)
1068 if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap;
1069 useImages = useImageSqs = 0;
1070 MakeColors(); CreateGCs(True);
1072 InitDrawingSizes(-1, 0);
1073 DrawPosition(True, NULL);
1077 Option boardOptions[] = {
1078 { 0, 0, 70, NULL, (void*) &appData.whitePieceColor, "", NULL, TextBox, N_("White Piece Color:") },
1079 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#FFFFCC", Button, " " },
1080 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1081 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1082 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1083 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1084 { 0, 0, 70, NULL, (void*) &appData.blackPieceColor, "", NULL, TextBox, N_("Black Piece Color:") },
1085 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#202020", Button, " " },
1086 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1087 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1088 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1089 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1090 { 0, 0, 70, NULL, (void*) &appData.lightSquareColor, "", NULL, TextBox, N_("Light Square Color:") },
1091 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#C8C365", Button, " " },
1092 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1093 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1094 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1095 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1096 { 0, 0, 70, NULL, (void*) &appData.darkSquareColor, "", NULL, TextBox, N_("Dark Square Color:") },
1097 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#77A26D", Button, " " },
1098 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1099 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1100 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1101 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1102 { 0, 0, 70, NULL, (void*) &appData.highlightSquareColor, "", NULL, TextBox, N_("Highlight Color:") },
1103 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#FFFF00", Button, " " },
1104 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1105 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1106 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1107 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1108 { 0, 0, 70, NULL, (void*) &appData.premoveHighlightColor, "", NULL, TextBox, N_("Premove Highlight Color:") },
1109 { 1000, 1, 0, NULL, (void*) &DefColor, NULL, (char**) "#FF0000", Button, " " },
1110 { 1, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "R" },
1111 { 2, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "G" },
1112 { 3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
1113 { 4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
1114 { 0, 0, 0, NULL, (void*) &appData.upsideDown, "", NULL, CheckBox, N_("Flip Pieces Shogi Style (Colored buttons restore default)") },
1115 //{ 0, 0, 0, NULL, (void*) &appData.allWhite, "", NULL, CheckBox, N_("Use Outline Pieces for Black") },
1116 { 0, 0, 0, NULL, (void*) &appData.monoMode, "", NULL, CheckBox, N_("Mono Mode") },
1117 { 0,-1, 5, NULL, (void*) &appData.overrideLineGap, "", NULL, Spin, N_("Line Gap ( -1 = default for board size):") },
1118 { 0, 0, 0, NULL, (void*) &appData.liteBackTextureFile, ".xpm", NULL, FileName, N_("Light-Squares Texture File:") },
1119 { 0, 0, 0, NULL, (void*) &appData.darkBackTextureFile, ".xpm", NULL, FileName, N_("Dark-Squares Texture File:") },
1120 { 0, 0, 0, NULL, (void*) &appData.bitmapDirectory, "", NULL, PathName, N_("Directory with Bitmap Pieces:") },
1121 { 0, 0, 0, NULL, (void*) &appData.pixmapDirectory, "", NULL, PathName, N_("Directory with Pixmap Pieces:") },
1122 { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" }
1125 int GenericReadout(int selected)
1130 char buf[MSG_SIZ], **dest;
1132 for(i=0; ; i++) { // send all options that had to be OK-ed to engine
1133 if(selected >= 0) { if(i < selected) continue; else if(i > selected) break; }
1134 switch(currentOption[i].type) {
1138 XtSetArg(args[0], XtNstring, &val);
1139 XtGetValues(currentOption[i].handle, args, 1);
1140 dest = currentCps ? &(currentOption[i].textValue) : (char**) currentOption[i].target;
1141 if(*dest == NULL || strcmp(*dest, val)) {
1143 snprintf(buf, MSG_SIZ, "option %s=%s\n", currentOption[i].name, val);
1144 SendToProgram(buf, currentCps);
1146 if(*dest) free(*dest);
1147 *dest = malloc(strlen(val)+1);
1149 safeStrCpy(*dest, val, MSG_SIZ - (*dest - currentOption[i].name)); // copy text there
1154 XtSetArg(args[0], XtNstring, &val);
1155 XtGetValues(currentOption[i].handle, args, 1);
1156 sscanf(val, "%f", &x);
1157 if(x > currentOption[i].max) x = currentOption[i].max;
1158 if(x < currentOption[i].min) x = currentOption[i].min;
1159 if(currentOption[i].type == Fractional)
1160 *(float*) currentOption[i].target = x; // engines never have float options!
1161 else if(currentOption[i].value != x) {
1162 currentOption[i].value = x;
1164 snprintf(buf, MSG_SIZ, "option %s=%.0f\n", currentOption[i].name, x);
1165 SendToProgram(buf, currentCps);
1166 } else *(int*) currentOption[i].target = x;
1171 XtSetArg(args[0], XtNstate, &j);
1172 XtGetValues(currentOption[i].handle, args, 1);
1173 if(currentOption[i].value != j) {
1174 currentOption[i].value = j;
1176 snprintf(buf, MSG_SIZ, "option %s=%d\n", currentOption[i].name, j);
1177 SendToProgram(buf, currentCps);
1178 } else *(Boolean*) currentOption[i].target = j;
1182 val = ((char**)currentOption[i].choice)[values[i]];
1184 if(currentOption[i].value == values[i]) break; // not changed
1185 currentOption[i].value = values[i];
1186 snprintf(buf, MSG_SIZ, "option %s=%s\n", currentOption[i].name,
1187 ((char**)currentOption[i].textValue)[values[i]]);
1188 SendToProgram(buf, currentCps);
1189 } else if(val && (*(char**) currentOption[i].target == NULL || strcmp(*(char**) currentOption[i].target, val))) {
1190 if(*(char**) currentOption[i].target) free(*(char**) currentOption[i].target);
1191 *(char**) currentOption[i].target = strdup(val);
1195 if(currentOption[i].target) // callback for implementing necessary actions on OK (like redraw)
1196 res = ((OKCallback*) currentOption[i].target)(i);
1199 printf("GenericReadout: unexpected case in switch.\n");
1206 if(currentOption[i].type == EndMark) break;
1211 void GenericCallback(w, client_data, call_data)
1213 XtPointer client_data, call_data;
1218 int data = (intptr_t) client_data;
1220 currentOption = dialogOptions[data>>16]; data &= 0xFFFF;
1222 XtSetArg(args[0], XtNlabel, &name);
1223 XtGetValues(w, args, 1);
1225 if (strcmp(name, _("cancel")) == 0) {
1229 if (strcmp(name, _("OK")) == 0) { // save buttons imply OK
1230 if(GenericReadout(-1)) PopDown(data);
1234 if(currentOption[data].type == SaveButton) GenericReadout(-1);
1235 snprintf(buf, MSG_SIZ, "option %s\n", name);
1236 SendToProgram(buf, currentCps);
1237 } else ((ButtonCallback*) currentOption[data].target)(data);
1240 static char *oneLiner = "<Key>Return: redraw-display()\n";
1243 GenericPopUp(Option *option, char *title, int dlgNr)
1246 Widget popup, layout, dialog=NULL, edit=NULL, form, last, b_ok, b_cancel, leftMargin = NULL, textField = NULL;
1248 int x, y, i, j, height=999, width=1, h, c, w;
1249 int win_x, win_y, maxWidth, maxTextWidth;
1251 char def[MSG_SIZ], *msg;
1252 static char pane[6] = "paneX";
1253 Widget texts[100], forelast = NULL, anchor, widest, lastrow = NULL;
1255 if(shellUp[dlgNr]) return 0; // already up
1256 if(dlgNr && shells[dlgNr]) {
1257 XtPopup(shells[dlgNr], XtGrabNone);
1258 shellUp[dlgNr] = True;
1262 dialogOptions[dlgNr] = option; // make available to callback
1263 // post currentOption globally, so Spin and Combo callbacks can already use it
1264 // WARNING: this kludge does not work for persistent dialogs, so that these cannot have spin or combo controls!
1265 currentOption = option;
1267 if(currentCps) { // Settings popup for engine: format through heuristic
1268 int n = currentCps->nrOptions;
1269 if(!n) { DisplayNote(_("Engine has no options")); return 0; }
1270 if(n > 50) width = 4; else if(n>24) width = 2; else width = 1;
1271 height = n / width + 1;
1272 if(n && (currentOption[n-1].type == Button || currentOption[n-1].type == SaveButton)) currentOption[n].min = 1; // OK on same line
1273 currentOption[n].type = EndMark; currentOption[n].target = NULL; // delimit list by callback-less end mark
1276 XtSetArg(args[i], XtNresizable, True); i++;
1277 popup = shells[dlgNr] =
1278 XtCreatePopupShell(title, transientShellWidgetClass,
1279 shellWidget, args, i);
1282 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
1283 layoutArgs, XtNumber(layoutArgs));
1284 for(c=0; c<width; c++) {
1287 XtCreateManagedWidget(pane, formWidgetClass, layout,
1288 formArgs, XtNumber(formArgs));
1290 XtSetArg(args[j], XtNfromHoriz, leftMargin); j++;
1291 XtSetValues(form, args, j);
1294 last = widest = NULL; anchor = lastrow;
1295 for(h=0; h<height; h++) {
1297 if(option[i].type == EndMark) break;
1300 switch(option[i].type) {
1302 snprintf(def, MSG_SIZ, "%.2f", *(float*)option[i].target);
1303 option[i].value = *(float*)option[i].target;
1306 if(!currentCps) option[i].value = *(int*)option[i].target;
1307 snprintf(def, MSG_SIZ, "%d", option[i].value);
1312 if(option[i].name[0]) {
1314 XtSetArg(args[j], XtNfromVert, last); j++;
1315 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1316 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1317 XtSetArg(args[j], XtNborderWidth, 0); j++;
1318 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1319 XtSetArg(args[j], XtNlabel, _(option[i].name)); j++;
1321 dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
1322 } else texts[h] = dialog = NULL;
1323 w = option[i].type == Spin || option[i].type == Fractional ? 70 : option[i].max ? option[i].max : 205;
1324 if(option[i].type == FileName || option[i].type == PathName) w -= 55;
1326 XtSetArg(args[j], XtNfromVert, last); j++;
1327 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1328 XtSetArg(args[j], XtNborderWidth, 1); j++;
1329 XtSetArg(args[j], XtNwidth, w); j++;
1330 if(option[i].type == TextBox && option[i].min) {
1331 XtSetArg(args[j], XtNheight, option[i].min); j++;
1332 if(option[i].value & 1) { XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++; }
1333 if(option[i].value & 2) { XtSetArg(args[j], XtNscrollHorizontal, XawtextScrollAlways); j++; }
1334 if(option[i].value & 4) { XtSetArg(args[j], XtNautoFill, True); j++; }
1335 if(option[i].value & 8) { XtSetArg(args[j], XtNwrap, XawtextWrapWord); j++; }
1337 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1338 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
1339 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
1340 XtSetArg(args[j], XtNdisplayCaret, False); j++;
1341 XtSetArg(args[j], XtNright, XtChainRight); j++;
1342 XtSetArg(args[j], XtNresizable, True); j++;
1343 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
1344 XtSetArg(args[j], XtNstring, option[i].type==Spin || option[i].type==Fractional ? def :
1345 currentCps ? option[i].textValue : *(char**)option[i].target); j++;
1347 option[i].handle = (void*)
1348 (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
1349 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup);
1350 if(option[i].min == 0 || option[i].type != TextBox)
1351 XtOverrideTranslations(last, XtParseTranslationTable(oneLiner));
1353 if(option[i].type == TextBox || option[i].type == Fractional) break;
1355 // add increment and decrement controls for spin
1357 XtSetArg(args[j], XtNfromVert, edit); j++;
1358 XtSetArg(args[j], XtNfromHoriz, last); j++;
1359 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1360 XtSetArg(args[j], XtNright, XtChainRight); j++;
1361 if(option[i].type == FileName || option[i].type == PathName) {
1362 w = 50; msg = _("browse");
1364 XtSetArg(args[j], XtNheight, 10); j++;
1367 XtSetArg(args[j], XtNwidth, w); j++;
1368 edit = XtCreateManagedWidget(msg, commandWidgetClass, form, args, j);
1369 XtAddCallback(edit, XtNcallback, SpinCallback, (XtPointer)(intptr_t) i);
1371 if(option[i].type != Spin) break;
1374 XtSetArg(args[j], XtNfromVert, edit); j++;
1375 XtSetArg(args[j], XtNfromHoriz, last); j++;
1376 XtSetArg(args[j], XtNheight, 10); j++;
1377 XtSetArg(args[j], XtNwidth, 20); j++;
1378 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1379 XtSetArg(args[j], XtNright, XtChainRight); j++;
1380 last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
1381 XtAddCallback(last, XtNcallback, SpinCallback, (XtPointer)(intptr_t) i);
1384 if(!currentCps) option[i].value = *(Boolean*)option[i].target;
1386 XtSetArg(args[j], XtNfromVert, last); j++;
1387 XtSetArg(args[j], XtNwidth, 10); j++;
1388 XtSetArg(args[j], XtNheight, 10); j++;
1389 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1390 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1391 XtSetArg(args[j], XtNstate, option[i].value); j++;
1392 option[i].handle = (void*)
1393 (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
1395 msg = option[i].name;
1396 if(*msg == NULLCHAR) msg = option[i].textValue;
1399 XtSetArg(args[j], XtNfromVert, last); j++;
1400 XtSetArg(args[j], XtNfromHoriz, option[i].type != Label ? dialog : NULL); j++;
1401 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1402 XtSetArg(args[j], XtNborderWidth, 0); j++;
1403 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1404 XtSetArg(args[j], XtNlabel, _(msg)); j++;
1405 last = XtCreateManagedWidget(msg, labelWidgetClass, form, args, j);
1406 if(option[i].type == CheckBox)
1407 XtAddEventHandler(last, ButtonPressMask, False, CheckCallback, (XtPointer)(intptr_t) i);
1412 XtSetArg(args[j], XtNfromVert, option[i].min & 1 ? lastrow : last); j++;
1413 XtSetArg(args[j], XtNlabel, _(option[i].name)); j++;
1414 if(option[i].min & 1) { XtSetArg(args[j], XtNfromHoriz, last); j++; }
1415 else { XtSetArg(args[j], XtNfromHoriz, NULL); j++; lastrow = forelast; }
1416 if(option[i].max) { XtSetArg(args[j], XtNwidth, option[i].max); j++; }
1417 if(option[i].textValue) { // special for buttons of New Variant dialog
1418 XtSetArg(args[j], XtNsensitive, appData.noChessProgram || option[i].value < 0
1419 || strstr(first.variants, VariantName(option[i].value))); j++;
1420 XtSetArg(args[j], XtNborderWidth, (gameInfo.variant == option[i].value)+1); j++;
1422 option[i].handle = (void*)
1423 (dialog = last = XtCreateManagedWidget(option[i].name, commandWidgetClass, form, args, j));
1424 if(option[i].choice && ((char*)option[i].choice)[0] == '#' && !currentCps) {
1425 SetColor( *(char**) option[i-1].target, &option[i]);
1426 XtAddEventHandler(option[i-1].handle, KeyReleaseMask, False, ColorChanged, (XtPointer)(intptr_t) i-1);
1428 XtAddCallback(last, XtNcallback, GenericCallback,
1429 (XtPointer)(intptr_t) i + (dlgNr<<16));
1430 if(option[i].textValue) SetColor( option[i].textValue, &option[i]);
1431 forelast = lastrow; // next button can go on same row
1435 XtSetArg(args[j], XtNfromVert, last); j++;
1436 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1437 XtSetArg(args[j], XtNright, XtChainLeft); j++;
1438 XtSetArg(args[j], XtNborderWidth, 0); j++;
1439 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
1440 XtSetArg(args[j], XtNlabel, _(option[i].name)); j++;
1441 texts[h] = dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
1443 if(currentCps) option[i].choice = (char**) option[i].textValue; else {
1444 for(j=0; option[i].choice[j]; j++)
1445 if(*(char**)option[i].target && !strcmp(*(char**)option[i].target, option[i].choice[j])) break;
1446 option[i].value = j + (option[i].choice[j] == NULL);
1450 XtSetArg(args[j], XtNfromVert, last); j++;
1451 XtSetArg(args[j], XtNfromHoriz, dialog); j++;
1452 XtSetArg(args[j], XtNwidth, option[i].max && !currentCps ? option[i].max : 100); j++;
1453 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
1454 XtSetArg(args[j], XtNmenuName, XtNewString(option[i].name)); j++;
1455 XtSetArg(args[j], XtNlabel, _(((char**)option[i].textValue)[option[i].value])); j++;
1456 option[i].handle = (void*)
1457 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
1458 CreateComboPopup(last, option[i].name, i, (char **) option[i].textValue);
1459 values[i] = option[i].value;
1466 printf("GenericPopUp: unexpected case in switch.\n");
1471 // make an attempt to align all spins and textbox controls
1472 maxWidth = maxTextWidth = 0;
1473 for(h=0; h<height; h++) {
1475 if(option[i].type == EndMark) break;
1476 if(option[i].type == Spin || option[i].type == TextBox || option[i].type == ComboBox
1477 || option[i].type == PathName || option[i].type == FileName) {
1479 if(!texts[h]) continue;
1481 XtSetArg(args[j], XtNwidth, &w); j++;
1482 XtGetValues(texts[h], args, j);
1483 if(option[i].type == Spin) {
1484 if(w > maxWidth) maxWidth = w;
1487 if(w > maxTextWidth) maxTextWidth = w;
1488 if(!widest) widest = texts[h];
1492 if(maxTextWidth + 110 < maxWidth)
1493 maxTextWidth = maxWidth - 110;
1494 else maxWidth = maxTextWidth + 110;
1495 for(h=0; h<height; h++) {
1497 if(option[i].type == EndMark) break;
1498 if(!texts[h]) continue;
1500 if(option[i].type == Spin) {
1501 XtSetArg(args[j], XtNwidth, maxWidth); j++;
1502 XtSetValues(texts[h], args, j);
1504 if(option[i].type == TextBox || option[i].type == ComboBox || option[i].type == PathName || option[i].type == FileName) {
1505 XtSetArg(args[j], XtNwidth, maxTextWidth); j++;
1506 XtSetValues(texts[h], args, j);
1511 if(!(option[i].min & 2)) {
1513 if(option[i].min & 1) {
1514 for(j=i-1; option[j+1].min&1 && option[j].type == Button; j--) {
1515 XtSetArg(args[0], XtNtop, XtChainBottom);
1516 XtSetArg(args[1], XtNbottom, XtChainBottom);
1517 XtSetValues(option[j].handle, args, 2);
1519 if(option[j].type == TextBox && option[j].name[0] == NULLCHAR) {
1520 XtSetArg(args[0], XtNbottom, XtChainBottom);
1521 XtSetValues(option[j].handle, args, 1);
1524 XtSetArg(args[j], XtNfromHoriz, last); last = forelast;
1526 XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog); j++;
1527 XtSetArg(args[j], XtNfromVert, anchor ? anchor : last); j++;
1528 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
1529 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
1530 XtSetArg(args[j], XtNleft, XtChainRight); j++;
1531 XtSetArg(args[j], XtNright, XtChainRight); j++;
1532 b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1533 XtAddCallback(b_ok, XtNcallback, GenericCallback, (XtPointer)(intptr_t) dlgNr + (dlgNr<<16));
1535 XtSetArg(args[0], XtNfromHoriz, b_ok);
1536 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1537 XtAddCallback(b_cancel, XtNcallback, GenericCallback, (XtPointer)(intptr_t) dlgNr);
1540 XtRealizeWidget(popup);
1541 XSetWMProtocols(xDisplay, XtWindow(popup), &wm_delete_window, 1);
1542 snprintf(def, MSG_SIZ, "<Message>WM_PROTOCOLS: GenericPopDown(\"%d\") \n", dlgNr);
1543 XtAugmentTranslations(popup, XtParseTranslationTable(def));
1544 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1545 &x, &y, &win_x, &win_y, &mask);
1547 XtSetArg(args[0], XtNx, x - 10);
1548 XtSetArg(args[1], XtNy, y - 30);
1549 XtSetValues(popup, args, 2);
1551 XtPopup(popup, dlgNr ? XtGrabNone : XtGrabExclusive);
1552 shellUp[dlgNr] = True;
1554 if(textField)SetFocus(textField, popup, (XEvent*) NULL, False);
1555 if(dlgNr && wp[dlgNr] && wp[dlgNr]->width > 0) { // if persistent window-info available, reposition
1557 XtSetArg(args[j], XtNheight, (Dimension) (wp[dlgNr]->height)); j++;
1558 XtSetArg(args[j], XtNwidth, (Dimension) (wp[dlgNr]->width)); j++;
1559 XtSetArg(args[j], XtNx, (Position) (wp[dlgNr]->x)); j++;
1560 XtSetArg(args[j], XtNy, (Position) (wp[dlgNr]->y)); j++;
1561 XtSetValues(popup, args, j);
1567 void IcsOptionsProc(w, event, prms, nprms)
1573 GenericPopUp(icsOptions, _("ICS Options"), 0);
1576 void LoadOptionsProc(w, event, prms, nprms)
1582 GenericPopUp(loadOptions, _("Load Game Options"), 0);
1585 void SaveOptionsProc(w, event, prms, nprms)
1591 GenericPopUp(saveOptions, _("Save Game Options"), 0);
1594 void SoundOptionsProc(w, event, prms, nprms)
1600 soundFiles[2] = "*";
1601 GenericPopUp(soundOptions, _("Sound Options"), 0);
1604 void BoardOptionsProc(w, event, prms, nprms)
1610 GenericPopUp(boardOptions, _("Board Options"), 0);
1613 void EngineMenuProc(w, event, prms, nprms)
1619 GenericPopUp(adjudicationOptions, "Adjudicate non-ICS Games", 0);
1622 void UciMenuProc(w, event, prms, nprms)
1628 oldCores = appData.smpCores;
1629 oldPonder = appData.ponderNextMove;
1630 GenericPopUp(commonEngineOptions, _("Common Engine Settings"), 0);
1633 void NewVariantProc(w, event, prms, nprms)
1639 GenericPopUp(variantDescriptors, _("New Variant"), 0);
1642 void OptionsProc(w, event, prms, nprms)
1648 oldPonder = appData.ponderNextMove;
1649 GenericPopUp(generalOptions, _("General Options"), 0);
1652 void MatchOptionsProc(w, event, prms, nprms)
1658 NamesToList(firstChessProgramNames, engineList, engineMnemonic);
1659 comboCallback = &AddToTourney;
1660 matchOptions[5].min = -(appData.pairingEngine[0] != NULLCHAR); // with pairing engine, allow Swiss
1661 ASSIGN(tfName, appData.tourneyFile[0] ? appData.tourneyFile : MakeName(appData.defName));
1662 GenericPopUp(matchOptions, _("Match Options"), 0);
1665 Option textOptions[100];
1666 void PutText P((char *text, int pos));
1668 void SendString(char *p)
1670 char buf[MSG_SIZ], *q;
1671 if(q = strstr(p, "$input")) {
1672 if(!shellUp[4]) return;
1673 strncpy(buf, p, MSG_SIZ);
1674 strncpy(buf + (q-p), q+6, MSG_SIZ-(q-p));
1678 snprintf(buf, MSG_SIZ, "%s\n", p);
1682 /* function called when the data to Paste is ready */
1684 SendTextCB(Widget w, XtPointer client_data, Atom *selection,
1685 Atom *type, XtPointer value, unsigned long *len, int *format)
1687 char buf[MSG_SIZ], *p = (char*) textOptions[(int)(intptr_t) client_data].choice, *name = (char*) value, *q;
1688 if (value==NULL || *len==0) return; /* nothing selected, abort */
1690 strncpy(buf, p, MSG_SIZ);
1691 q = strstr(p, "$name");
1692 snprintf(buf + (q-p), MSG_SIZ -(q-p), "%s%s", name, q+5);
1697 void SendText(int n)
1699 char *p = (char*) textOptions[n].choice;
1700 if(strstr(p, "$name")) {
1701 XtGetSelectionValue(menuBarWidget,
1702 XA_PRIMARY, XA_STRING,
1703 /* (XtSelectionCallbackProc) */ SendTextCB,
1704 (XtPointer) (intptr_t) n, /* client_data passed to PastePositionCB */
1707 } else SendString(p);
1710 void IcsTextProc(w, event, prms, nprms)
1718 if((p = icsTextMenuString) == NULL) return;
1720 q = r = p; while(*p && *p != ';') p++;
1721 for(j=0; j<p-q; j++) textOptions[i].name[j] = *r++;
1722 textOptions[i].name[j++] = 0;
1724 if(*++p == '\n') p++; // optional linefeed after button-text terminating semicolon
1726 textOptions[i].choice = (char**) (r = textOptions[i].name + j);
1727 while(*p && (*p != ';' || p[1] != '\n')) textOptions[i].name[j++] = *p++;
1728 textOptions[i].name[j++] = 0;
1730 textOptions[i].max = 135;
1731 textOptions[i].min = i&1;
1732 textOptions[i].handle = NULL;
1733 textOptions[i].target = &SendText;
1734 textOptions[i].textValue = strstr(r, "$input") ? "#80FF80" : strstr(r, "$name") ? "#FF8080" : "#FFFFFF";
1735 textOptions[i].type = Button;
1736 } while(++i < 99 && *p);
1738 textOptions[i].type = EndMark;
1739 textOptions[i].target = NULL;
1740 textOptions[i].min = 2;
1741 MarkMenu("menuView.ICStex", 3);
1742 GenericPopUp(textOptions, _("ICS text menu"), 3);
1745 static char *commentText;
1746 static int commentIndex;
1747 void ClearComment P((int n));
1748 extern char commentTranslations[];
1750 int NewComCallback(int n)
1752 ReplaceComment(commentIndex, commentText);
1756 void SaveChanges(int n)
1758 GetWidgetText(¤tOption[0], &commentText);
1759 ReplaceComment(commentIndex, commentText);
1762 Option commentOptions[] = {
1763 { 0xD, 200, 250, NULL, (void*) &commentText, "", NULL, TextBox, "" },
1764 { 0, 0, 50, NULL, (void*) &ClearComment, NULL, NULL, Button, "clear" },
1765 { 0, 1, 100, NULL, (void*) &SaveChanges, NULL, NULL, Button, "save changes" },
1766 { 0, 1, 0, NULL, (void*) &NewComCallback, "", NULL, EndMark , "" }
1769 void ClearComment(int n)
1771 XtCallActionProc(commentOptions[0].handle, "select-all", NULL, NULL, 0);
1772 XtCallActionProc(commentOptions[0].handle, "kill-selection", NULL, NULL, 0);
1775 void NewCommentPopup(char *title, char *text, int index)
1780 if(shells[1]) { // if already exists, alter title and content
1781 XtSetArg(args[0], XtNtitle, title);
1782 XtSetValues(shells[1], args, 1);
1783 SetWidgetText(&commentOptions[0], text, 1);
1785 if(commentText) free(commentText); commentText = strdup(text);
1786 commentIndex = index;
1787 MarkMenu("menuView.Show Comments", 1);
1788 if(GenericPopUp(commentOptions, title, 1))
1789 XtOverrideTranslations(commentOptions[0].handle, XtParseTranslationTable(commentTranslations));
1792 static char *tagsText, *msgText;
1794 int NewTagsCallback(int n)
1796 ReplaceTags(tagsText, &gameInfo);
1800 void changeTags(int n)
1802 GetWidgetText(¤tOption[1], &tagsText);
1803 if(bookUp) SaveToBook(tagsText); else
\r
1804 ReplaceTags(tagsText, &gameInfo);
1807 Option tagsOptions[] = {
1808 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, "" },
1809 { 0xD, 200, 200, NULL, (void*) &tagsText, "", NULL, TextBox, "" },
1810 { 0, 0, 100, NULL, (void*) &changeTags, NULL, NULL, Button, "save changes" },
1811 { 0, 1, 0, NULL, (void*) &NewTagsCallback, "", NULL, EndMark , "" }
1814 void NewTagsPopup(char *text, char *msg)
1818 char *title = bookUp ? _("Edit book") : _("Tags");
1820 if(shells[2]) { // if already exists, alter title and content
1821 SetWidgetText(&tagsOptions[1], text, 2);
1822 XtSetArg(args[0], XtNtitle, title);
1823 XtSetValues(shells[2], args, 1);
1825 if(tagsText) free(tagsText); tagsText = strdup(text);
1826 tagsOptions[0].textValue = msg;
1827 MarkMenu("menuView.Show Tags", 2);
1828 GenericPopUp(tagsOptions, title, 2);
1833 Option boxOptions[] = {
1834 { 0, 30, 400, NULL, (void*) &icsText, "", NULL, TextBox, "" },
1835 { 0, 3, 0, NULL, NULL, "", NULL, EndMark , "" }
1838 void PutText(char *text, int pos)
1841 char buf[MSG_SIZ], *p;
1843 if(strstr(text, "$add ") == text) {
1844 GetWidgetText(&boxOptions[0], &p);
1845 snprintf(buf, MSG_SIZ, "%s%s", p, text+5); text = buf;
1846 pos += strlen(p) - 5;
1848 SetWidgetText(&boxOptions[0], text, 4);
1849 XtSetArg(args[0], XtNinsertPosition, pos);
1850 XtSetValues(boxOptions[0].handle, args, 1);
1851 // SetFocus(boxOptions[0].handle, shells[4], NULL, False); // No idea why this does not work, and the following is needed:
1852 XSetInputFocus(xDisplay, XtWindow(boxOptions[0].handle), RevertToPointerRoot, CurrentTime);
1855 void InputBoxPopup()
1857 MarkMenu("menuView.ICS Input Box", 4);
1858 if(GenericPopUp(boxOptions, _("ICS input box"), 4))
1859 XtOverrideTranslations(boxOptions[0].handle, XtParseTranslationTable(ICSInputTranslations));
1862 void TypeInProc(w, event, prms, nprms)
1871 if(prms[0][0] == '1') {
1872 GetWidgetText(&boxOptions[0], &val);
1873 TypeInDoneEvent((char*)val);
1878 char moveTypeInTranslations[] =
1879 "<Key>Return: TypeInProc(1) \n"
1880 "<Key>Escape: TypeInProc(0) \n";
1882 void PopUpMoveDialog(char firstchar)
1885 buf[0] = firstchar; icsText = buf;
1886 if(GenericPopUp(boxOptions, _("Type a move"), 0))
1887 XtOverrideTranslations(boxOptions[0].handle, XtParseTranslationTable(moveTypeInTranslations));
1890 void MoveTypeInProc(Widget widget, caddr_t unused, XEvent *event)
1892 char buf[10], keys[32];
1894 KeyCode metaL, metaR;
1895 int n = XLookupString(&(event->xkey), buf, 10, &sym, NULL);
1896 XQueryKeymap(xDisplay,keys);
1897 metaL = XKeysymToKeycode(xDisplay, XK_Meta_L);
1898 metaR = XKeysymToKeycode(xDisplay, XK_Meta_R);
1899 if ( n == 1 && *buf > 32 && !(keys[metaL>>3]&1<<(metaL&7)) && !(keys[metaR>>3]&1<<(metaR&7))) // printable, no alt
1900 PopUpMoveDialog(*buf);
1905 SettingsPopUp(ChessProgramState *cps)
1908 GenericPopUp(cps->option, _("Engine Settings"), 0);
1911 void FirstSettingsProc(w, event, prms, nprms)
1917 SettingsPopUp(&first);
1920 void SecondSettingsProc(w, event, prms, nprms)
1926 if(WaitForEngine(&second, SettingsMenuIfReady)) return;
1927 SettingsPopUp(&second);
1930 int InstallOK(int n)
1932 PopDown(0); // early popdown, to allow FreezeUI to instate grab
1933 if(engineChoice[0] == engineNr[0][0]) Load(&first, 0); else Load(&second, 1);
1937 Option installOptions[] = {
1938 { 0, 0, 0, NULL, (void*) &engineLine, (char*) engineMnemonic, engineList, ComboBox, N_("Select engine from list:") },
1939 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("or specify one below:") },
1940 { 0, 0, 0, NULL, (void*) &nickName, NULL, NULL, TextBox, N_("Nickname (optional):") },
1941 { 0, 0, 0, NULL, (void*) &useNick, NULL, NULL, CheckBox, N_("Use nickname in PGN player tags of engine-engine games") },
1942 { 0, 0, 0, NULL, (void*) &engineDir, NULL, NULL, PathName, N_("Engine Directory:") },
1943 { 0, 0, 0, NULL, (void*) &engineName, NULL, NULL, FileName, N_("Engine Command:") },
1944 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("(Directory will be derived from engine path when empty)") },
1945 { 0, 0, 0, NULL, (void*) &isUCI, NULL, NULL, CheckBox, N_("UCI") },
1946 { 0, 0, 0, NULL, (void*) &v1, NULL, NULL, CheckBox, N_("WB protocol v1 (do not wait for engine features)") },
1947 { 0, 0, 0, NULL, (void*) &hasBook, NULL, NULL, CheckBox, N_("Must not use GUI book") },
1948 { 0, 0, 0, NULL, (void*) &addToList, NULL, NULL, CheckBox, N_("Add this engine to the list") },
1949 { 0, 0, 0, NULL, (void*) &storeVariant, NULL, NULL, CheckBox, N_("Force current variant with this engine") },
1950 { 0, 0, 0, NULL, (void*) &engineChoice, (char*) engineNr, engineNr, ComboBox, N_("Load mentioned engine as") },
1951 { 0, 1, 0, NULL, (void*) &InstallOK, "", NULL, EndMark , "" }
1954 void LoadEngineProc(w, event, prms, nprms)
1960 isUCI = storeVariant = v1 = useNick = False; addToList = hasBook = True; // defaults
1961 if(engineChoice) free(engineChoice); engineChoice = strdup(engineNr[0]);
1962 if(engineLine) free(engineLine); engineLine = strdup("");
1963 if(engineDir) free(engineDir); engineDir = strdup("");
1964 if(nickName) free(nickName); nickName = strdup("");
1965 if(params) free(params); params = strdup("");
1966 NamesToList(firstChessProgramNames, engineList, engineMnemonic);
1967 GenericPopUp(installOptions, _("Load engine"), 0);
1970 void EditBookProc(w, event, prms, nprms)
1979 void SetRandom P((int n));
1981 int ShuffleOK(int n)
1987 Option shuffleOptions[] = {
1988 { 0, 0, 50, NULL, (void*) &shuffleOpenings, NULL, NULL, CheckBox, "shuffle" },
1989 { 0,-1,2000000000, NULL, (void*) &appData.defaultFrcPosition, "", NULL, Spin, N_("Start-position number:") },
1990 { 0, 0, 0, NULL, (void*) &SetRandom, NULL, NULL, Button, "randomize" },
1991 { 0, 1, 0, NULL, (void*) &SetRandom, NULL, NULL, Button, "pick fixed" },
1992 { 0, 1, 0, NULL, (void*) &ShuffleOK, "", NULL, EndMark , "" }
1995 void SetRandom(int n)
1997 int r = n==2 ? -1 : rand() & (1<<30)-1;
2000 snprintf(buf, MSG_SIZ, "%d", r);
2001 SetWidgetText(&shuffleOptions[1], buf, 0);
2002 SetWidgetState(&shuffleOptions[0], True);
2005 void ShuffleMenuProc(w, event, prms, nprms)
2011 GenericPopUp(shuffleOptions, _("New Shuffle Game"), 0);
2014 //---------------------------- Chat Windows ----------------------------------------------
2016 void OutputChatMessage(int partner, char *mess)