2 * dialogs.c -- platform-independent code for dialogs of XBoard
4 * Copyright 2000, 2009, 2010, 2011, 2012 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 */
58 # define _(s) gettext (s)
59 # define N_(s) gettext_noop (s)
66 int values[MAX_OPTIONS];
67 ChessProgramState *currentCps;
69 //----------------------------Generic dialog --------------------------------------------
71 // cloned from Engine Settings dialog (and later merged with it)
73 char *marked[NrOfDialogs];
74 Boolean shellUp[NrOfDialogs];
77 MarkMenu (char *item, int dlgNr)
79 MarkMenuItem(marked[dlgNr] = item, True);
83 AddLine (Option *opt, char *s)
86 AppendText(opt, "\n");
89 //---------------------------------------------- Update dialog controls ------------------------------------
92 SetCurrentComboSelection (Option *opt)
95 if(!opt->textValue) opt->value = *(int*)opt->target; /* numeric */else {
96 for(j=0; opt->choice[j]; j++) // look up actual value in list of possible values, to get selection nr
97 if(*(char**)opt->target && !strcmp(*(char**)opt->target, ((char**)opt->textValue)[j])) break;
98 opt->value = j + (opt->choice[j] == NULL);
104 GenericUpdate (Option *opts, int selected)
110 if(selected >= 0) { if(i < selected) continue; else if(i > selected) break; }
111 switch(opts[i].type) {
115 SetWidgetText(&opts[i], *(char**) opts[i].target, -1);
118 sprintf(buf, "%d", *(int*) opts[i].target);
119 SetWidgetText(&opts[i], buf, -1);
122 sprintf(buf, "%4.2f", *(float*) opts[i].target);
123 SetWidgetText(&opts[i], buf, -1);
126 SetWidgetState(&opts[i], *(Boolean*) opts[i].target);
129 if(opts[i].min & COMBO_CALLBACK) break;
130 SetCurrentComboSelection(opts+i);
131 // TODO: actually display this (but it is never used that way...)
136 printf("GenericUpdate: unexpected case in switch.\n");
147 //------------------------------------------- Read out dialog controls ------------------------------------
150 GenericReadout (Option *opts, int selected)
154 char buf[MSG_SIZ], **dest;
156 for(i=0; ; i++) { // send all options that had to be OK-ed to engine
157 if(selected >= 0) { if(i < selected) continue; else if(i > selected) break; }
158 switch(opts[i].type) {
162 GetWidgetText(&opts[i], &val);
163 dest = currentCps ? &(opts[i].textValue) : (char**) opts[i].target;
164 if(*dest == NULL || strcmp(*dest, val)) {
166 snprintf(buf, MSG_SIZ, "option %s=%s\n", opts[i].name, val);
167 SendToProgram(buf, currentCps);
169 if(*dest) free(*dest);
170 *dest = malloc(strlen(val)+1);
172 safeStrCpy(*dest, val, MSG_SIZ - (*dest - opts[i].name)); // copy text there
177 GetWidgetText(&opts[i], &val);
178 x = 0.0; // Initialise because sscanf() will fail if non-numeric text is entered
179 sscanf(val, "%f", &x);
180 if(x > opts[i].max) x = opts[i].max;
181 if(x < opts[i].min) x = opts[i].min;
182 if(opts[i].type == Fractional)
183 *(float*) opts[i].target = x; // engines never have float options!
184 else if(opts[i].value != x) {
187 snprintf(buf, MSG_SIZ, "option %s=%.0f\n", opts[i].name, x);
188 SendToProgram(buf, currentCps);
189 } else *(int*) opts[i].target = x;
194 GetWidgetState(&opts[i], &j);
195 if(opts[i].value != j) {
198 snprintf(buf, MSG_SIZ, "option %s=%d\n", opts[i].name, j);
199 SendToProgram(buf, currentCps);
200 } else *(Boolean*) opts[i].target = j;
204 if(opts[i].min & COMBO_CALLBACK) break;
205 if(!opts[i].textValue) { *(int*)opts[i].target == opts[i].value; break; } // numeric
206 val = ((char**)opts[i].textValue)[values[i]];
208 if(opts[i].value == values[i]) break; // not changed
209 opts[i].value = values[i];
210 snprintf(buf, MSG_SIZ, "option %s=%s\n", opts[i].name, opts[i].choice[values[i]]);
211 SendToProgram(buf, currentCps);
212 } else if(val && (*(char**) opts[i].target == NULL || strcmp(*(char**) opts[i].target, val))) {
213 if(*(char**) opts[i].target) free(*(char**) opts[i].target);
214 *(char**) opts[i].target = strdup(val);
218 if(opts[i].target) // callback for implementing necessary actions on OK (like redraw)
219 res = ((OKCallback*) opts[i].target)(i);
222 printf("GenericReadout: unexpected case in switch.\n");
230 if(opts[i].type == EndMark) break;
235 //------------------------------------------- Match Options ------------------------------------------------------
237 char *engineName, *engineChoice, *tfName;
238 char *engineList[MAXENGINES] = {" "}, *engineMnemonic[MAXENGINES] = {""};
240 static void AddToTourney P((int n));
241 static void CloneTourney P((void));
242 static void ReplaceParticipant P((void));
243 static void UpgradeParticipant P((void));
248 ASSIGN(appData.participants, engineName);
249 if(!CreateTourney(tfName) || matchMode) return matchMode || !appData.participants[0];
250 PopDown(TransientDlg); // early popdown to prevent FreezeUI called through MatchEvent from causing XtGrab warning
251 MatchEvent(2); // start tourney
252 return FALSE; // no double PopDown!
255 static Option matchOptions[] = {
256 { 0, 0, 0, NULL, (void*) &tfName, ".trn", NULL, FileName, N_("Tournament file:") },
257 { 0, 0, 0, NULL, (void*) &appData.roundSync, "", NULL, CheckBox, N_("Sync after round (for concurrent playing of a single") },
258 { 0, 0, 0, NULL, (void*) &appData.cycleSync, "", NULL, CheckBox, N_("Sync after cycle tourney with multiple XBoards)") },
259 { 150, T_VSCRL | T_FILL | T_WRAP,
260 0, NULL, (void*) &engineName, "", NULL, TextBox, N_("Tourney participants:") },
261 { 0, COMBO_CALLBACK | NO_GETTEXT,
262 0, NULL, (void*) &AddToTourney, (char*) (engineMnemonic+1), (engineMnemonic+1), ComboBox, N_("Select Engine:") },
263 { 0, 0, 10, NULL, (void*) &appData.tourneyType, "", NULL, Spin, N_("Tourney type (0 = round-robin, 1 = gauntlet):") },
264 { 0, 1, 1000000000, NULL, (void*) &appData.tourneyCycles, "", NULL, Spin, N_("Number of tourney cycles (or Swiss rounds):") },
265 { 0, 1, 1000000000, NULL, (void*) &appData.defaultMatchGames, "", NULL, Spin, N_("Default Number of Games in Match (or Pairing):") },
266 { 0, 0, 1000000000, NULL, (void*) &appData.matchPause, "", NULL, Spin, N_("Pause between Match Games (msec):") },
267 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, ".pgn", NULL, FileName, N_("Save Tourney Games on:") },
268 { 0, 0, 0, NULL, (void*) &appData.loadGameFile, ".pgn", NULL, FileName, N_("Game File with Opening Lines:") },
269 { 0, -2, 1000000000, NULL, (void*) &appData.loadGameIndex, "", NULL, Spin, N_("Game Number (-1 or -2 = Auto-Increment):") },
270 { 0, 0, 0, NULL, (void*) &appData.loadPositionFile, ".fen", NULL, FileName, N_("File with Start Positions:") },
271 { 0, -2, 1000000000, NULL, (void*) &appData.loadPositionIndex, "", NULL, Spin, N_("Position Number (-1 or -2 = Auto-Increment):") },
272 { 0, 0, 1000000000, NULL, (void*) &appData.rewindIndex, "", NULL, Spin, N_("Rewind Index after this many Games (0 = never):") },
273 { 0, 0, 0, NULL, (void*) &appData.defNoBook, "", NULL, CheckBox, N_("Disable own engine books by default") },
274 { 0, 0, 0, NULL, (void*) &ReplaceParticipant, NULL, NULL, Button, N_("Replace Engine") },
275 { 0, SAME_ROW, 0, NULL, (void*) &UpgradeParticipant, NULL, NULL, Button, N_("Upgrade Engine") },
276 { 0, SAME_ROW, 0, NULL, (void*) &CloneTourney, NULL, NULL, Button, N_("Clone Tourney") },
277 { 0, SAME_ROW, 0, NULL, (void*) &MatchOK, "", NULL, EndMark , "" }
281 ReplaceParticipant ()
283 GenericReadout(matchOptions, 3);
284 Substitute(strdup(engineName), True);
288 UpgradeParticipant ()
290 GenericReadout(matchOptions, 3);
291 Substitute(strdup(engineName), False);
299 GetWidgetText(matchOptions, &name);
300 if(name && name[0] && (f = fopen(name, "r")) ) {
302 saveSaveFile = appData.saveGameFile; appData.saveGameFile = NULL; // this is a persistent option, protect from change
303 ParseArgsFromFile(f);
304 engineName = appData.participants; GenericUpdate(matchOptions, -1);
305 FREE(appData.saveGameFile); appData.saveGameFile = saveSaveFile;
306 } else DisplayError(_("First you must specify an existing tourney file to clone"), 0);
312 AddLine(&matchOptions[3], engineMnemonic[values[4]+1]);
318 NamesToList(firstChessProgramNames, engineList, engineMnemonic, "all");
319 matchOptions[5].min = -(appData.pairingEngine[0] != NULLCHAR); // with pairing engine, allow Swiss
320 ASSIGN(tfName, appData.tourneyFile[0] ? appData.tourneyFile : MakeName(appData.defName));
321 ASSIGN(engineName, appData.participants);
322 GenericPopUp(matchOptions, _("Match Options"), TransientDlg, BoardWindow, MODAL);
325 // ------------------------------------------- General Options --------------------------------------------------
327 static int oldShow, oldBlind, oldPonder;
330 GeneralOptionsOK (int n)
332 int newPonder = appData.ponderNextMove;
333 appData.ponderNextMove = oldPonder;
334 PonderNextMoveEvent(newPonder);
335 if(!appData.highlightLastMove) ClearHighlights(), ClearPremoveHighlights();
336 if(oldShow != appData.showCoords || oldBlind != appData.blindfold) DrawPosition(TRUE, NULL);
340 static Option generalOptions[] = {
341 { 0, 0, 0, NULL, (void*) &appData.whitePOV, "", NULL, CheckBox, N_("Absolute Analysis Scores") },
342 { 0, 0, 0, NULL, (void*) &appData.sweepSelect, "", NULL, CheckBox, N_("Almost Always Queen (Detour Under-Promote)") },
343 { 0, 0, 0, NULL, (void*) &appData.animateDragging, "", NULL, CheckBox, N_("Animate Dragging") },
344 { 0, 0, 0, NULL, (void*) &appData.animate, "", NULL, CheckBox, N_("Animate Moving") },
345 { 0, 0, 0, NULL, (void*) &appData.autoCallFlag, "", NULL, CheckBox, N_("Auto Flag") },
346 { 0, 0, 0, NULL, (void*) &appData.autoFlipView, "", NULL, CheckBox, N_("Auto Flip View") },
347 { 0, 0, 0, NULL, (void*) &appData.blindfold, "", NULL, CheckBox, N_("Blindfold") },
348 { 0, 0, 0, NULL, (void*) &appData.dropMenu, "", NULL, CheckBox, N_("Drop Menu") },
349 { 0, 0, 0, NULL, (void*) &appData.hideThinkingFromHuman, "", NULL, CheckBox, N_("Hide Thinking from Human") },
350 { 0, 0, 0, NULL, (void*) &appData.highlightLastMove, "", NULL, CheckBox, N_("Highlight Last Move") },
351 { 0, 0, 0, NULL, (void*) &appData.highlightMoveWithArrow, "", NULL, CheckBox, N_("Highlight with Arrow") },
352 { 0, 0, 0, NULL, (void*) &appData.ringBellAfterMoves, "", NULL, CheckBox, N_("Move Sound") },
353 { 0, 0, 0, NULL, (void*) &appData.oneClick, "", NULL, CheckBox, N_("One-Click Moving") },
354 { 0, 0, 0, NULL, (void*) &appData.periodicUpdates, "", NULL, CheckBox, N_("Periodic Updates (in Analysis Mode)") },
355 { 0, 0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, N_("Ponder Next Move") },
356 { 0, 0, 0, NULL, (void*) &appData.popupExitMessage, "", NULL, CheckBox, N_("Popup Exit Messages") },
357 { 0, 0, 0, NULL, (void*) &appData.popupMoveErrors, "", NULL, CheckBox, N_("Popup Move Errors") },
358 { 0, 0, 0, NULL, (void*) &appData.showEvalInMoveHistory, "", NULL, CheckBox, N_("Scores in Move List") },
359 { 0, 0, 0, NULL, (void*) &appData.showCoords, "", NULL, CheckBox, N_("Show Coordinates") },
360 { 0, 0, 0, NULL, (void*) &appData.markers, "", NULL, CheckBox, N_("Show Target Squares") },
361 { 0, 0, 0, NULL, (void*) &appData.useStickyWindows, "", NULL, CheckBox, N_("Sticky Windows") },
362 { 0, 0, 0, NULL, (void*) &appData.testLegality, "", NULL, CheckBox, N_("Test Legality") },
363 { 0, 0,10, NULL, (void*) &appData.flashCount, "", NULL, Spin, N_("Flash Moves (0 = no flashing):") },
364 { 0, 1,10, NULL, (void*) &appData.flashRate, "", NULL, Spin, N_("Flash Rate (high = fast):") },
365 { 0, 5,100, NULL, (void*) &appData.animSpeed, "", NULL, Spin, N_("Animation Speed (high = slow):") },
366 { 0, 1,5, NULL, (void*) &appData.zoom, "", NULL, Spin, N_("Zoom factor in Evaluation Graph:") },
367 { 0, 0, 0, NULL, (void*) &GeneralOptionsOK, "", NULL, EndMark , "" }
373 oldPonder = appData.ponderNextMove;
374 oldShow = appData.showCoords; oldBlind = appData.blindfold;
375 GenericPopUp(generalOptions, _("General Options"), TransientDlg, BoardWindow, MODAL);
378 //---------------------------------------------- New Variant ------------------------------------------------
380 static void Pick P((int n));
382 static Option variantDescriptors[] = {
383 { VariantNormal, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("normal")},
384 { VariantFairy, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("fairy")},
385 { VariantFischeRandom, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("FRC")},
386 { VariantSChess, SAME_ROW, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Seirawan")},
387 { VariantWildCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("wild castle")},
388 { VariantSuper, SAME_ROW, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Superchess")},
389 { VariantNoCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("no castle")},
390 { VariantCrazyhouse,SAME_ROW,135,NULL,(void*) &Pick, "#FFBFBF", NULL, Button, N_("crazyhouse")},
391 { VariantKnightmate, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("knightmate")},
392 { VariantBughouse,SAME_ROW,135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("bughouse")},
393 { VariantBerolina, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("berolina")},
394 { VariantShogi, SAME_ROW, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("shogi (9x9)")},
395 { VariantCylinder, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("cylinder")},
396 { VariantXiangqi, SAME_ROW,135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("xiangqi (9x10)")},
397 { VariantShatranj, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("shatranj")},
398 { VariantCourier, SAME_ROW,135, NULL, (void*) &Pick, "#BFFFBF", NULL, Button, N_("courier (12x8)")},
399 { VariantMakruk, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("makruk")},
400 { VariantGreat, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Great Shatranj (10x8)")},
401 { VariantAtomic, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("atomic")},
402 { VariantFalcon, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("falcon (10x8)")},
403 { VariantTwoKings, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("two kings")},
404 { VariantCapablanca,SAME_ROW,135,NULL,(void*) &Pick, "#BFBFFF", NULL, Button, N_("Capablanca (10x8)")},
405 { Variant3Check, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("3-checks")},
406 { VariantGothic, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Gothic (10x8)")},
407 { VariantSuicide, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("suicide")},
408 { VariantJanus, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("janus (10x8)")},
409 { VariantGiveaway, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("give-away")},
410 { VariantCapaRandom,SAME_ROW,135,NULL,(void*) &Pick, "#BFBFFF", NULL, Button, N_("CRC (10x8)")},
411 { VariantLosers, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("losers")},
412 { VariantGrand, SAME_ROW, 135, NULL, (void*) &Pick, "#5070FF", NULL, Button, N_("grand (10x10)")},
413 { VariantSpartan, 0, 135, NULL, (void*) &Pick, "#FF0000", NULL, Button, N_("Spartan")},
414 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Board size ( -1 = default for selected variant):")},
415 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.NrRanks, "", NULL, Spin, N_("Number of Board Ranks:") },
416 { 0, -1, BOARD_FILES, NULL, (void*) &appData.NrFiles, "", NULL, Spin, N_("Number of Board Files:") },
417 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.holdingsSize, "", NULL, Spin, N_("Holdings Size:") },
418 { 0, 0, 0, NULL, NULL, NULL, NULL, Label,
419 N_("WARNING: variants with un-orthodox\n"
420 "pieces only have built-in bitmaps\n"
421 "for -boardSize middling, bulky and\n"
422 "petite, and substitute king or amazon\n"
423 "for missing bitmaps. (See manual.)")},
424 { 0, NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
430 VariantClass v = variantDescriptors[n].value;
431 if(!appData.noChessProgram) {
432 char *name = VariantName(v), buf[MSG_SIZ];
433 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
434 /* [HGM] in protocol 2 we check if variant is suported by engine */
435 snprintf(buf, MSG_SIZ, _("Variant %s not supported by %s"), name, first.tidy);
436 DisplayError(buf, 0);
437 return; /* ignore OK if first engine does not support it */
439 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
440 snprintf(buf, MSG_SIZ, _("Warning: second engine (%s) does not support this!"), second.tidy);
441 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
445 GenericReadout(variantDescriptors, -1); // make sure ranks and file settings are read
447 gameInfo.variant = v;
448 appData.variant = VariantName(v);
450 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
451 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
452 appData.pieceToCharTable = NULL;
453 appData.pieceNickNames = "";
454 appData.colorNickNames = "";
456 PopDown(TransientDlg);
463 GenericPopUp(variantDescriptors, _("New Variant"), TransientDlg, BoardWindow, MODAL);
466 //------------------------------------------- Common Engine Options -------------------------------------
471 CommonOptionsOK (int n)
473 int newPonder = appData.ponderNextMove;
474 // make sure changes are sent to first engine by re-initializing it
475 // if it was already started pre-emptively at end of previous game
476 if(gameMode == BeginningOfGame) Reset(True, True); else {
477 // Some changed setting need immediate sending always.
478 if(oldCores != appData.smpCores)
479 NewSettingEvent(False, &(first.maxCores), "cores", appData.smpCores);
480 appData.ponderNextMove = oldPonder;
481 PonderNextMoveEvent(newPonder);
486 static Option commonEngineOptions[] = {
487 { 0, 0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, N_("Ponder Next Move") },
488 { 0, 0, 1000, NULL, (void*) &appData.smpCores, "", NULL, Spin, N_("Maximum Number of CPUs per Engine:") },
489 { 0, 0, 0, NULL, (void*) &appData.polyglotDir, "", NULL, PathName, N_("Polygot Directory:") },
490 { 0, 0,16000, NULL, (void*) &appData.defaultHashSize, "", NULL, Spin, N_("Hash-Table Size (MB):") },
491 { 0, 0, 0, NULL, (void*) &appData.defaultPathEGTB, "", NULL, PathName, N_("Nalimov EGTB Path:") },
492 { 0, 0, 1000, NULL, (void*) &appData.defaultCacheSizeEGTB, "", NULL, Spin, N_("EGTB Cache Size (MB):") },
493 { 0, 0, 0, NULL, (void*) &appData.usePolyglotBook, "", NULL, CheckBox, N_("Use GUI Book") },
494 { 0, 0, 0, NULL, (void*) &appData.polyglotBook, ".bin", NULL, FileName, N_("Opening-Book Filename:") },
495 { 0, 0, 100, NULL, (void*) &appData.bookDepth, "", NULL, Spin, N_("Book Depth (moves):") },
496 { 0, 0, 100, NULL, (void*) &appData.bookStrength, "", NULL, Spin, N_("Book Variety (0) vs. Strength (100):") },
497 { 0, 0, 0, NULL, (void*) &appData.firstHasOwnBookUCI, "", NULL, CheckBox, N_("Engine #1 Has Own Book") },
498 { 0, 0, 0, NULL, (void*) &appData.secondHasOwnBookUCI, "", NULL, CheckBox, N_("Engine #2 Has Own Book ") },
499 { 0,SAME_ROW,0,NULL, (void*) &CommonOptionsOK, "", NULL, EndMark , "" }
505 oldCores = appData.smpCores;
506 oldPonder = appData.ponderNextMove;
507 GenericPopUp(commonEngineOptions, _("Common Engine Settings"), TransientDlg, BoardWindow, MODAL);
510 //------------------------------------------ Adjudication Options --------------------------------------
512 static Option adjudicationOptions[] = {
513 { 0, 0, 0, NULL, (void*) &appData.checkMates, "", NULL, CheckBox, N_("Detect all Mates") },
514 { 0, 0, 0, NULL, (void*) &appData.testClaims, "", NULL, CheckBox, N_("Verify Engine Result Claims") },
515 { 0, 0, 0, NULL, (void*) &appData.materialDraws, "", NULL, CheckBox, N_("Draw if Insufficient Mating Material") },
516 { 0, 0, 0, NULL, (void*) &appData.trivialDraws, "", NULL, CheckBox, N_("Adjudicate Trivial Draws (3-Move Delay)") },
517 { 0, 0,100, NULL, (void*) &appData.ruleMoves, "", NULL, Spin, N_("N-Move Rule:") },
518 { 0, 0, 6, NULL, (void*) &appData.drawRepeats, "", NULL, Spin, N_("N-fold Repeats:") },
519 { 0, 0,1000, NULL, (void*) &appData.adjudicateDrawMoves, "", NULL, Spin, N_("Draw after N Moves Total:") },
520 { 0, -5000,0, NULL, (void*) &appData.adjudicateLossThreshold, "", NULL, Spin, N_("Win / Loss Threshold:") },
521 { 0, 0, 0, NULL, (void*) &first.scoreIsAbsolute, "", NULL, CheckBox, N_("Negate Score of Engine #1") },
522 { 0, 0, 0, NULL, (void*) &second.scoreIsAbsolute, "", NULL, CheckBox, N_("Negate Score of Engine #2") },
523 { 0,SAME_ROW, 0, NULL, NULL, "", NULL, EndMark , "" }
529 GenericPopUp(adjudicationOptions, _("Adjudicate non-ICS Games"), TransientDlg, BoardWindow, MODAL);
532 //--------------------------------------------- ICS Options ---------------------------------------------
537 ParseIcsTextColors();
541 Option icsOptions[] = {
542 { 0, 0, 0, NULL, (void*) &appData.autoKibitz, "", NULL, CheckBox, N_("Auto-Kibitz") },
543 { 0, 0, 0, NULL, (void*) &appData.autoComment, "", NULL, CheckBox, N_("Auto-Comment") },
544 { 0, 0, 0, NULL, (void*) &appData.autoObserve, "", NULL, CheckBox, N_("Auto-Observe") },
545 { 0, 0, 0, NULL, (void*) &appData.autoRaiseBoard, "", NULL, CheckBox, N_("Auto-Raise Board") },
546 { 0, 0, 0, NULL, (void*) &appData.bgObserve, "", NULL, CheckBox, N_("Background Observe while Playing") },
547 { 0, 0, 0, NULL, (void*) &appData.dualBoard, "", NULL, CheckBox, N_("Dual Board for Background-Observed Game") },
548 { 0, 0, 0, NULL, (void*) &appData.getMoveList, "", NULL, CheckBox, N_("Get Move List") },
549 { 0, 0, 0, NULL, (void*) &appData.quietPlay, "", NULL, CheckBox, N_("Quiet Play") },
550 { 0, 0, 0, NULL, (void*) &appData.seekGraph, "", NULL, CheckBox, N_("Seek Graph") },
551 { 0, 0, 0, NULL, (void*) &appData.autoRefresh, "", NULL, CheckBox, N_("Auto-Refresh Seek Graph") },
552 { 0, 0, 0, NULL, (void*) &appData.premove, "", NULL, CheckBox, N_("Premove") },
553 { 0, 0, 0, NULL, (void*) &appData.premoveWhite, "", NULL, CheckBox, N_("Premove for White") },
554 { 0, 0, 0, NULL, (void*) &appData.premoveWhiteText, "", NULL, TextBox, N_("First White Move:") },
555 { 0, 0, 0, NULL, (void*) &appData.premoveBlack, "", NULL, CheckBox, N_("Premove for Black") },
556 { 0, 0, 0, NULL, (void*) &appData.premoveBlackText, "", NULL, TextBox, N_("First Black Move:") },
557 { 0, SAME_ROW, 0, NULL, NULL, NULL, NULL, Break, "" },
558 { 0, 0, 0, NULL, (void*) &appData.icsAlarm, "", NULL, CheckBox, N_("Alarm") },
559 { 0, 0, 100000000, NULL, (void*) &appData.icsAlarmTime, "", NULL, Spin, N_("Alarm Time (msec):") },
560 //{ 0, 0, 0, NULL, (void*) &appData.chatBoxes, "", NULL, TextBox, N_("Startup Chat Boxes:") },
561 { 0, 0, 0, NULL, (void*) &appData.colorize, "", NULL, CheckBox, N_("Colorize Messages") },
562 { 0, 0, 0, NULL, (void*) &appData.colorShout, "", NULL, TextBox, N_("Shout Text Colors:") },
563 { 0, 0, 0, NULL, (void*) &appData.colorSShout, "", NULL, TextBox, N_("S-Shout Text Colors:") },
564 { 0, 0, 0, NULL, (void*) &appData.colorChannel1, "", NULL, TextBox, N_("Channel #1 Text Colors:") },
565 { 0, 0, 0, NULL, (void*) &appData.colorChannel, "", NULL, TextBox, N_("Other Channel Text Colors:") },
566 { 0, 0, 0, NULL, (void*) &appData.colorKibitz, "", NULL, TextBox, N_("Kibitz Text Colors:") },
567 { 0, 0, 0, NULL, (void*) &appData.colorTell, "", NULL, TextBox, N_("Tell Text Colors:") },
568 { 0, 0, 0, NULL, (void*) &appData.colorChallenge, "", NULL, TextBox, N_("Challenge Text Colors:") },
569 { 0, 0, 0, NULL, (void*) &appData.colorRequest, "", NULL, TextBox, N_("Request Text Colors:") },
570 { 0, 0, 0, NULL, (void*) &appData.colorSeek, "", NULL, TextBox, N_("Seek Text Colors:") },
571 { 0, 0, 0, NULL, (void*) &IcsOptionsOK, "", NULL, EndMark , "" }
577 GenericPopUp(icsOptions, _("ICS Options"), TransientDlg, BoardWindow, MODAL);
580 //-------------------------------------------- Load Game Options ---------------------------------
582 static char *modeNames[] = { N_("Exact position match"), N_("Shown position is subset"), N_("Same material with exactly same Pawn chain"),
583 N_("Same material"), N_("Material range (top board half optional)"), N_("Material difference (optional stuff balanced)"), NULL };
584 static char *modeValues[] = { "1", "2", "3", "4", "5", "6" };
585 static char *searchMode;
590 appData.searchMode = atoi(searchMode);
594 static Option loadOptions[] = {
595 { 0, 0, 0, NULL, (void*) &appData.autoDisplayTags, "", NULL, CheckBox, N_("Auto-Display Tags") },
596 { 0, 0, 0, NULL, (void*) &appData.autoDisplayComment, "", NULL, CheckBox, N_("Auto-Display Comment") },
597 { 0, LR, 0, NULL, NULL, NULL, NULL, Label, N_("Auto-Play speed of loaded games\n(0 = instant, -1 = off):") },
598 { 0, -1,10000000, NULL, (void*) &appData.timeDelay, "", NULL, Fractional, N_("Seconds per Move:") },
599 { 0, LR, 0, NULL, NULL, NULL, NULL, Label, N_("\noptions to use in game-viewer mode:") },
600 { 0, 0,300, NULL, (void*) &appData.viewerOptions, "", NULL, TextBox, "" },
601 { 0, LR, 0, NULL, NULL, NULL, NULL, Label, N_("\nThresholds for position filtering in game list:") },
602 { 0, 0,5000, NULL, (void*) &appData.eloThreshold1, "", NULL, Spin, N_("Elo of strongest player at least:") },
603 { 0, 0,5000, NULL, (void*) &appData.eloThreshold2, "", NULL, Spin, N_("Elo of weakest player at least:") },
604 { 0, 0,5000, NULL, (void*) &appData.dateThreshold, "", NULL, Spin, N_("No games before year:") },
605 { 0, 1,50, NULL, (void*) &appData.stretch, "", NULL, Spin, N_("Minimum nr consecutive positions:") },
606 { 0, 0,205, NULL, (void*) &searchMode, (char*) modeValues, modeNames, ComboBox, N_("Search mode:") },
607 { 0, 0, 0, NULL, (void*) &appData.ignoreColors, "", NULL, CheckBox, N_("Also match reversed colors") },
608 { 0, 0, 0, NULL, (void*) &appData.findMirror, "", NULL, CheckBox, N_("Also match left-right flipped position") },
609 { 0, 0, 0, NULL, (void*) &LoadOptionsOK, "", NULL, EndMark , "" }
615 ASSIGN(searchMode, modeValues[appData.searchMode-1]);
616 GenericPopUp(loadOptions, _("Load Game Options"), TransientDlg, BoardWindow, MODAL);
619 //------------------------------------------- Save Game Options --------------------------------------------
621 static Option saveOptions[] = {
622 { 0, 0, 0, NULL, (void*) &appData.autoSaveGames, "", NULL, CheckBox, N_("Auto-Save Games") },
623 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, ".pgn", NULL, FileName, N_("Save Games on File:") },
624 { 0, 0, 0, NULL, (void*) &appData.savePositionFile, ".fen", NULL, FileName, N_("Save Final Positions on File:") },
625 { 0, 0, 0, NULL, (void*) &appData.pgnEventHeader, "", NULL, TextBox, N_("PGN Event Header:") },
626 { 0, 0, 0, NULL, (void*) &appData.oldSaveStyle, "", NULL, CheckBox, N_("Old Save Style (as opposed to PGN)") },
627 { 0, 0, 0, NULL, (void*) &appData.numberTag, "", NULL, CheckBox, N_("Include Number Tag in tourney PGN") },
628 { 0, 0, 0, NULL, (void*) &appData.saveExtendedInfoInPGN, "", NULL, CheckBox, N_("Save Score/Depth Info in PGN") },
629 { 0, 0, 0, NULL, (void*) &appData.saveOutOfBookInfo, "", NULL, CheckBox, N_("Save Out-of-Book Info in PGN ") },
630 { 0, SAME_ROW, 0, NULL, NULL, "", NULL, EndMark , "" }
636 GenericPopUp(saveOptions, _("Save Game Options"), TransientDlg, BoardWindow, MODAL);
639 //----------------------------------------------- Sound Options ---------------------------------------------
641 static void Test P((int n));
642 static char *trialSound;
644 static char *soundNames[] = {
647 N_("Above WAV File"),
662 static char *soundFiles[] = { // sound files corresponding to above names
665 NULL, // kludge alert: as first thing in the dialog readout this is replaced with the user-given .WAV filename
680 static Option soundOptions[] = {
681 { 0, 0, 0, NULL, (void*) &appData.soundProgram, "", NULL, TextBox, N_("Sound Program:") },
682 { 0, 0, 0, NULL, (void*) &appData.soundDirectory, "", NULL, PathName, N_("Sounds Directory:") },
683 { 0, 0, 0, NULL, (void*) (soundFiles+2) /* kludge! */, ".wav", NULL, FileName, N_("User WAV File:") },
684 { 0, 0, 0, NULL, (void*) &trialSound, (char*) soundFiles, soundNames, ComboBox, N_("Try-Out Sound:") },
685 { 0, SAME_ROW, 0, NULL, (void*) &Test, NULL, NULL, Button, N_("Play") },
686 { 0, 0, 0, NULL, (void*) &appData.soundMove, (char*) soundFiles, soundNames, ComboBox, N_("Move:") },
687 { 0, 0, 0, NULL, (void*) &appData.soundIcsWin, (char*) soundFiles, soundNames, ComboBox, N_("Win:") },
688 { 0, 0, 0, NULL, (void*) &appData.soundIcsLoss, (char*) soundFiles, soundNames, ComboBox, N_("Lose:") },
689 { 0, 0, 0, NULL, (void*) &appData.soundIcsDraw, (char*) soundFiles, soundNames, ComboBox, N_("Draw:") },
690 { 0, 0, 0, NULL, (void*) &appData.soundIcsUnfinished, (char*) soundFiles, soundNames, ComboBox, N_("Unfinished:") },
691 { 0, 0, 0, NULL, (void*) &appData.soundIcsAlarm, (char*) soundFiles, soundNames, ComboBox, N_("Alarm:") },
692 { 0, 0, 0, NULL, (void*) &appData.soundShout, (char*) soundFiles, soundNames, ComboBox, N_("Shout:") },
693 { 0, 0, 0, NULL, (void*) &appData.soundSShout, (char*) soundFiles, soundNames, ComboBox, N_("S-Shout:") },
694 { 0, 0, 0, NULL, (void*) &appData.soundChannel, (char*) soundFiles, soundNames, ComboBox, N_("Channel:") },
695 { 0, 0, 0, NULL, (void*) &appData.soundChannel1, (char*) soundFiles, soundNames, ComboBox, N_("Channel 1:") },
696 { 0, 0, 0, NULL, (void*) &appData.soundTell, (char*) soundFiles, soundNames, ComboBox, N_("Tell:") },
697 { 0, 0, 0, NULL, (void*) &appData.soundKibitz, (char*) soundFiles, soundNames, ComboBox, N_("Kibitz:") },
698 { 0, 0, 0, NULL, (void*) &appData.soundChallenge, (char*) soundFiles, soundNames, ComboBox, N_("Challenge:") },
699 { 0, 0, 0, NULL, (void*) &appData.soundRequest, (char*) soundFiles, soundNames, ComboBox, N_("Request:") },
700 { 0, 0, 0, NULL, (void*) &appData.soundSeek, (char*) soundFiles, soundNames, ComboBox, N_("Seek:") },
701 { 0, SAME_ROW, 0, NULL, NULL, "", NULL, EndMark , "" }
707 GenericReadout(soundOptions, 2);
708 if(soundFiles[values[3]]) PlaySound(soundFiles[values[3]]);
715 soundFiles[2] = strdup("*");
716 GenericPopUp(soundOptions, _("Sound Options"), TransientDlg, BoardWindow, MODAL);
719 //--------------------------------------------- Board Options --------------------------------------
721 static void DefColor P((int n));
722 static void AdjustColor P((int i));
725 BoardOptionsOK (int n)
727 if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap;
728 useImages = useImageSqs = 0;
730 InitDrawingSizes(-1, 0);
731 DrawPosition(True, NULL);
735 static Option boardOptions[] = {
736 { 0, 0, 70, NULL, (void*) &appData.whitePieceColor, "", NULL, TextBox, N_("White Piece Color:") },
737 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#FFFFCC", Button, " " },
738 /* TRANSLATORS: R = single letter for the color red */
739 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
740 /* TRANSLATORS: G = single letter for the color green */
741 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
742 /* TRANSLATORS: B = single letter for the color blue */
743 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
744 /* TRANSLATORS: D = single letter to make a color darker */
745 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
746 { 0, 0, 70, NULL, (void*) &appData.blackPieceColor, "", NULL, TextBox, N_("Black Piece Color:") },
747 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#202020", Button, " " },
748 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
749 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
750 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
751 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
752 { 0, 0, 70, NULL, (void*) &appData.lightSquareColor, "", NULL, TextBox, N_("Light Square Color:") },
753 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#C8C365", Button, " " },
754 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
755 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
756 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
757 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
758 { 0, 0, 70, NULL, (void*) &appData.darkSquareColor, "", NULL, TextBox, N_("Dark Square Color:") },
759 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#77A26D", Button, " " },
760 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
761 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
762 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
763 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
764 { 0, 0, 70, NULL, (void*) &appData.highlightSquareColor, "", NULL, TextBox, N_("Highlight Color:") },
765 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#FFFF00", Button, " " },
766 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
767 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
768 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
769 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
770 { 0, 0, 70, NULL, (void*) &appData.premoveHighlightColor, "", NULL, TextBox, N_("Premove Highlight Color:") },
771 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#FF0000", Button, " " },
772 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
773 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
774 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
775 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
776 { 0, 0, 0, NULL, (void*) &appData.upsideDown, "", NULL, CheckBox, N_("Flip Pieces Shogi Style (Colored buttons restore default)") },
777 //{ 0, 0, 0, NULL, (void*) &appData.allWhite, "", NULL, CheckBox, N_("Use Outline Pieces for Black") },
778 { 0, 0, 0, NULL, (void*) &appData.monoMode, "", NULL, CheckBox, N_("Mono Mode") },
779 { 0,-1, 5, NULL, (void*) &appData.overrideLineGap, "", NULL, Spin, N_("Line Gap ( -1 = default for board size):") },
780 { 0, 0, 0, NULL, (void*) &appData.useBitmaps, "", NULL, CheckBox, N_("Use Board Textures") },
781 { 0, 0, 0, NULL, (void*) &appData.liteBackTextureFile, ".xpm", NULL, FileName, N_("Light-Squares Texture File:") },
782 { 0, 0, 0, NULL, (void*) &appData.darkBackTextureFile, ".xpm", NULL, FileName, N_("Dark-Squares Texture File:") },
783 { 0, 0, 0, NULL, (void*) &appData.bitmapDirectory, "", NULL, PathName, N_("Directory with Bitmap Pieces:") },
784 { 0, 0, 0, NULL, (void*) &appData.pixmapDirectory, "", NULL, PathName, N_("Directory with Pixmap Pieces:") },
785 { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" }
789 SetColorText (int n, char *buf)
791 SetWidgetText(&boardOptions[n-1], buf, TransientDlg);
792 SetColor(buf, &boardOptions[n]);
798 SetColorText(n, (char*) boardOptions[n].choice);
802 RefreshColor (int source, int n)
804 int col, j, r, g, b, step = 10;
805 char *s, buf[MSG_SIZ]; // color string
806 GetWidgetText(&boardOptions[source], &s);
807 if(sscanf(s, "#%x", &col) != 1) return; // malformed
808 b = col & 0xFF; g = col & 0xFF00; r = col & 0xFF0000;
810 case 1: r += 0x10000*step;break;
811 case 2: g += 0x100*step; break;
812 case 3: b += step; break;
813 case 4: r -= 0x10000*step; g -= 0x100*step; b -= step; break;
815 if(r < 0) r = 0; if(g < 0) g = 0; if(b < 0) b = 0;
816 if(r > 0xFF0000) r = 0xFF0000; if(g > 0xFF00) g = 0xFF00; if(b > 0xFF) b = 0xFF;
818 snprintf(buf, MSG_SIZ, "#%06x", col);
819 for(j=1; j<7; j++) if(buf[j] >= 'a') buf[j] -= 32; // capitalize
820 SetColorText(source+1, buf);
826 int n = boardOptions[i].value;
827 RefreshColor(i-n-1, n);
833 GenericPopUp(boardOptions, _("Board Options"), TransientDlg, BoardWindow, MODAL);
836 //-------------------------------------------- ICS Text Menu Options ------------------------------
838 Option textOptions[100];
839 static void PutText P((char *text, int pos));
844 char buf[MSG_SIZ], *q;
845 if(q = strstr(p, "$input")) {
846 if(!shellUp[TextMenuDlg]) return;
847 strncpy(buf, p, MSG_SIZ);
848 strncpy(buf + (q-p), q+6, MSG_SIZ-(q-p));
852 snprintf(buf, MSG_SIZ, "%s\n", p);
861 if((p = icsTextMenuString) == NULL) return;
863 q = r = p; while(*p && *p != ';') p++;
864 for(j=0; j<p-q; j++) textOptions[i].name[j] = *r++;
865 textOptions[i].name[j++] = 0;
867 if(*++p == '\n') p++; // optional linefeed after button-text terminating semicolon
869 textOptions[i].choice = (char**) (r = textOptions[i].name + j);
870 while(*p && (*p != ';' || p[1] != '\n')) textOptions[i].name[j++] = *p++;
871 textOptions[i].name[j++] = 0;
873 textOptions[i].max = 135;
874 textOptions[i].min = i&1;
875 textOptions[i].handle = NULL;
876 textOptions[i].target = &SendText;
877 textOptions[i].textValue = strstr(r, "$input") ? "#80FF80" : strstr(r, "$name") ? "#FF8080" : "#FFFFFF";
878 textOptions[i].type = Button;
879 } while(++i < 99 && *p);
881 textOptions[i].type = EndMark;
882 textOptions[i].target = NULL;
883 textOptions[i].min = 2;
884 MarkMenu("ICStex", TextMenuDlg);
885 GenericPopUp(textOptions, _("ICS text menu"), TextMenuDlg, BoardWindow, NONMODAL);
888 //---------------------------------------------------- Edit Comment -----------------------------------
890 static char *commentText;
891 static int commentIndex;
892 static void ClearComment P((int n));
893 static void SaveChanges P((int n));
896 NewComCallback (int n)
898 ReplaceComment(commentIndex, commentText);
902 Option commentOptions[] = {
903 { 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 250, NULL, (void*) &commentText, "", NULL, TextBox, "" },
904 { 0, 0, 50, NULL, (void*) &ClearComment, NULL, NULL, Button, N_("clear") },
905 { 0, SAME_ROW, 100, NULL, (void*) &SaveChanges, NULL, NULL, Button, N_("save changes") },
906 { 0, SAME_ROW, 0, NULL, (void*) &NewComCallback, "", NULL, EndMark , "" }
912 GenericReadout(commentOptions, 0);
913 ReplaceComment(commentIndex, commentText);
919 SetWidgetText(&commentOptions[0], "", CommentDlg);
923 NewCommentPopup (char *title, char *text, int index)
925 if(DialogExists(CommentDlg)) { // if already exists, alter title and content
926 SetDialogTitle(CommentDlg, title);
927 SetWidgetText(&commentOptions[0], text, CommentDlg);
929 if(commentText) free(commentText); commentText = strdup(text);
930 commentIndex = index;
931 MarkMenu("Show Comments", CommentDlg);
932 if(GenericPopUp(commentOptions, title, CommentDlg, BoardWindow, NONMODAL))
933 AddHandler(&commentOptions[0], 1);
940 if (PopDown(CommentDlg)) { // popdown succesful
941 MarkMenuItem("Edit Comment", False);
942 MarkMenuItem("Show Comments", False);
947 //------------------------------------------------------ Edit Tags ----------------------------------
949 static void changeTags P((int n));
950 static char *tagsText;
953 NewTagsCallback (int n)
955 ReplaceTags(tagsText, &gameInfo);
959 static Option tagsOptions[] = {
960 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, NULL },
961 { 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 200, NULL, (void*) &tagsText, "", NULL, TextBox, "" },
962 { 0, 0, 100, NULL, (void*) &changeTags, NULL, NULL, Button, N_("save changes") },
963 { 0,SAME_ROW, 0, NULL, (void*) &NewTagsCallback, "", NULL, EndMark , "" }
969 GenericReadout(tagsOptions, 1);
970 if(bookUp) SaveToBook(tagsText); else
971 ReplaceTags(tagsText, &gameInfo);
975 NewTagsPopup (char *text, char *msg)
977 char *title = bookUp ? _("Edit book") : _("Tags");
979 if(DialogExists(TagsDlg)) { // if already exists, alter title and content
980 SetWidgetText(&tagsOptions[1], text, TagsDlg);
981 SetDialogTitle(TagsDlg, title);
983 if(tagsText) free(tagsText); tagsText = strdup(text);
984 tagsOptions[0].name = msg;
985 MarkMenu("Show Tags", TagsDlg);
986 GenericPopUp(tagsOptions, title, TagsDlg, BoardWindow, NONMODAL);
989 //---------------------------------------------- ICS Input Box ----------------------------------
993 // [HGM] code borrowed from winboard.c (which should thus go to backend.c!)
994 #define HISTORY_SIZE 64
995 static char *history[HISTORY_SIZE];
996 static int histIn = 0, histP = 0;
999 SaveInHistory (char *cmd)
1001 if (history[histIn] != NULL) {
1002 free(history[histIn]);
1003 history[histIn] = NULL;
1005 if (*cmd == NULLCHAR) return;
1006 history[histIn] = StrSave(cmd);
1007 histIn = (histIn + 1) % HISTORY_SIZE;
1008 if (history[histIn] != NULL) {
1009 free(history[histIn]);
1010 history[histIn] = NULL;
1016 PrevInHistory (char *cmd)
1019 if (histP == histIn) {
1020 if (history[histIn] != NULL) free(history[histIn]);
1021 history[histIn] = StrSave(cmd);
1023 newhp = (histP - 1 + HISTORY_SIZE) % HISTORY_SIZE;
1024 if (newhp == histIn || history[newhp] == NULL) return NULL;
1026 return history[histP];
1032 if (histP == histIn) return NULL;
1033 histP = (histP + 1) % HISTORY_SIZE;
1034 return history[histP];
1036 // end of borrowed code
1038 Option boxOptions[] = {
1039 { 30, 0, 400, NULL, (void*) &icsText, "", NULL, TextBox, "" },
1040 { 0,SAME_ROW | NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
1048 GetWidgetText(&boxOptions[0], &val);
1050 SendMultiLineToICS(val);
1051 SetWidgetText(&boxOptions[0], val, InputBoxDlg);
1056 { // [HGM] input: let up-arrow recall previous line from history
1059 if (!shellUp[InputBoxDlg]) return;
1065 GetWidgetText(&boxOptions[0], &val);
1066 val = PrevInHistory(val);
1069 val = NextInHistory();
1071 SetWidgetText(&boxOptions[0], val ? val : "", InputBoxDlg);
1075 PutText (char *text, int pos)
1077 char buf[MSG_SIZ], *p;
1079 if(strstr(text, "$add ") == text) {
1080 GetWidgetText(&boxOptions[0], &p);
1081 snprintf(buf, MSG_SIZ, "%s%s", p, text+5); text = buf;
1082 pos += strlen(p) - 5;
1084 SetWidgetText(&boxOptions[0], text, TextMenuDlg);
1085 SetInsertPos(&boxOptions[0], pos);
1091 MarkMenu("ICS Input Box", InputBoxDlg);
1092 if(GenericPopUp(boxOptions, _("ICS input box"), InputBoxDlg, BoardWindow, NONMODAL))
1093 AddHandler(&boxOptions[0], 3);
1099 if (!PopDown(InputBoxDlg)) ICSInputBoxPopUp();
1102 //--------------------------------------------- Move Type In ------------------------------------------
1104 static int TypeInOK P((int n));
1106 Option typeOptions[] = {
1107 { 30, 0, 400, NULL, (void*) &icsText, "", NULL, TextBox, "" },
1108 { 0, SAME_ROW | NO_OK, 0, NULL, (void*) &TypeInOK, "", NULL, EndMark , "" }
1114 TypeInDoneEvent(icsText);
1119 PopUpMoveDialog (char firstchar)
1122 buf[0] = firstchar; ASSIGN(icsText, buf);
1123 if(GenericPopUp(typeOptions, _("Type a move"), TransientDlg, BoardWindow, MODAL))
1124 AddHandler(&typeOptions[0], 2);
1128 BoxAutoPopUp (char *buf)
1130 if(appData.icsActive) { // text typed to board in ICS mode: divert to ICS input box
1131 if(DialogExists(InputBoxDlg)) { // box already exists: append to current contents
1132 char *p, newText[MSG_SIZ];
1133 GetWidgetText(&boxOptions[0], &p);
1134 snprintf(newText, MSG_SIZ, "%s%c", p, *buf);
1135 SetWidgetText(&boxOptions[0], newText, InputBoxDlg);
1136 if(shellUp[InputBoxDlg]) HardSetFocus (&boxOptions[0]); //why???
1137 } else icsText = buf; // box did not exist: make sure it pops up with char in it
1139 } else PopUpMoveDialog(*buf);
1142 //------------------------------------------ Engine Settings ------------------------------------
1145 SettingsPopUp (ChessProgramState *cps)
1148 GenericPopUp(cps->option, _("Engine Settings"), TransientDlg, BoardWindow, MODAL);
1152 FirstSettingsProc ()
1154 SettingsPopUp(&first);
1158 SecondSettingsProc ()
1160 if(WaitForEngine(&second, SettingsMenuIfReady)) return;
1161 SettingsPopUp(&second);
1164 //----------------------------------------------- Load Engine --------------------------------------
1166 char *engineDir, *engineLine, *nickName, *params;
1167 Boolean isUCI, hasBook, storeVariant, v1, addToList, useNick;
1168 static char *engineNr[] = { N_("First Engine"), N_("Second Engine"), NULL };
1173 PopDown(TransientDlg); // early popdown, to allow FreezeUI to instate grab
1174 if(engineChoice[0] == engineNr[0][0]) Load(&first, 0); else Load(&second, 1);
1175 return FALSE; // no double PopDown!
1178 static Option installOptions[] = {
1179 { 0, NO_GETTEXT, 0, NULL, (void*) &engineLine, (char*) engineList, engineMnemonic, ComboBox, N_("Select engine from list:") },
1180 { 0, LR, 0, NULL, NULL, NULL, NULL, Label, N_("or specify one below:") },
1181 { 0, 0, 0, NULL, (void*) &nickName, NULL, NULL, TextBox, N_("Nickname (optional):") },
1182 { 0, 0, 0, NULL, (void*) &useNick, NULL, NULL, CheckBox, N_("Use nickname in PGN player tags of engine-engine games") },
1183 { 0, 0, 0, NULL, (void*) &engineDir, NULL, NULL, PathName, N_("Engine Directory:") },
1184 { 0, 0, 0, NULL, (void*) &engineName, NULL, NULL, FileName, N_("Engine Command:") },
1185 { 0, LR, 0, NULL, NULL, NULL, NULL, Label, N_("(Directory will be derived from engine path when empty)") },
1186 { 0, 0, 0, NULL, (void*) &isUCI, NULL, NULL, CheckBox, N_("UCI") },
1187 { 0, 0, 0, NULL, (void*) &v1, NULL, NULL, CheckBox, N_("WB protocol v1 (do not wait for engine features)") },
1188 { 0, 0, 0, NULL, (void*) &hasBook, NULL, NULL, CheckBox, N_("Must not use GUI book") },
1189 { 0, 0, 0, NULL, (void*) &addToList, NULL, NULL, CheckBox, N_("Add this engine to the list") },
1190 { 0, 0, 0, NULL, (void*) &storeVariant, NULL, NULL, CheckBox, N_("Force current variant with this engine") },
1191 { 0, 0, 0, NULL, (void*) &engineChoice, (char*) engineNr, engineNr, ComboBox, N_("Load mentioned engine as") },
1192 { 0,SAME_ROW, 0, NULL, (void*) &InstallOK, "", NULL, EndMark , "" }
1198 isUCI = storeVariant = v1 = useNick = False; addToList = hasBook = True; // defaults
1199 if(engineChoice) free(engineChoice); engineChoice = strdup(engineNr[0]);
1200 if(engineLine) free(engineLine); engineLine = strdup("");
1201 if(engineDir) free(engineDir); engineDir = strdup("");
1202 if(nickName) free(nickName); nickName = strdup("");
1203 if(params) free(params); params = strdup("");
1204 NamesToList(firstChessProgramNames, engineList, engineMnemonic, "all");
1205 GenericPopUp(installOptions, _("Load engine"), TransientDlg, BoardWindow, MODAL);
1208 //----------------------------------------------------- Edit Book -----------------------------------------
1216 //--------------------------------------------------- New Shuffle Game ------------------------------
1218 static void SetRandom P((int n));
1227 static Option shuffleOptions[] = {
1228 { 0, 0, 50, NULL, (void*) &shuffleOpenings, NULL, NULL, CheckBox, N_("shuffle") },
1229 { 0,-1,2000000000, NULL, (void*) &appData.defaultFrcPosition, "", NULL, Spin, N_("Start-position number:") },
1230 { 0, 0, 0, NULL, (void*) &SetRandom, NULL, NULL, Button, N_("randomize") },
1231 { 0, SAME_ROW, 0, NULL, (void*) &SetRandom, NULL, NULL, Button, N_("pick fixed") },
1232 { 0,SAME_ROW, 0, NULL, (void*) &ShuffleOK, "", NULL, EndMark , "" }
1238 int r = n==2 ? -1 : random() & (1<<30)-1;
1240 snprintf(buf, MSG_SIZ, "%d", r);
1241 SetWidgetText(&shuffleOptions[1], buf, TransientDlg);
1242 SetWidgetState(&shuffleOptions[0], True);
1248 GenericPopUp(shuffleOptions, _("New Shuffle Game"), TransientDlg, BoardWindow, MODAL);
1251 //------------------------------------------------------ Time Control -----------------------------------
1253 static int TcOK P((int n));
1254 int tmpMoves, tmpTc, tmpInc, tmpOdds1, tmpOdds2, tcType;
1261 static void SetTcType P((int n));
1266 static char buf[MSG_SIZ];
1267 snprintf(buf, MSG_SIZ, "%d", n);
1271 static Option tcOptions[] = {
1272 { 0, 0, 0, NULL, (void*) &SetTcType, NULL, NULL, Button, N_("classical") },
1273 { 0,SAME_ROW,0,NULL, (void*) &SetTcType, NULL, NULL, Button, N_("incremental") },
1274 { 0,SAME_ROW,0,NULL, (void*) &SetTcType, NULL, NULL, Button, N_("fixed max") },
1275 { 0, 0, 200, NULL, (void*) &tmpMoves, NULL, NULL, Spin, N_("Moves per session:") },
1276 { 0, 0,10000, NULL, (void*) &tmpTc, NULL, NULL, Spin, N_("Initial time (min):") },
1277 { 0, 0, 10000, NULL, (void*) &tmpInc, NULL, NULL, Spin, N_("Increment or max (sec/move):") },
1278 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Time-Odds factors:") },
1279 { 0, 1, 1000, NULL, (void*) &tmpOdds1, NULL, NULL, Spin, N_("Engine #1") },
1280 { 0, 1, 1000, NULL, (void*) &tmpOdds2, NULL, NULL, Spin, N_("Engine #2 / Human") },
1281 { 0, 0, 0, NULL, (void*) &TcOK, "", NULL, EndMark , "" }
1288 if(tcType == 0 && tmpMoves <= 0) return 0;
1289 if(tcType == 2 && tmpInc <= 0) return 0;
1290 GetWidgetText(&tcOptions[4], &tc); // get original text, in case it is min:sec
1294 if(!ParseTimeControl(tc, -1, tmpMoves)) return 0;
1295 appData.movesPerSession = tmpMoves;
1296 ASSIGN(appData.timeControl, tc);
1297 appData.timeIncrement = -1;
1300 if(!ParseTimeControl(tc, tmpInc, 0)) return 0;
1301 ASSIGN(appData.timeControl, tc);
1302 appData.timeIncrement = tmpInc;
1305 searchTime = tmpInc;
1307 appData.firstTimeOdds = first.timeOdds = tmpOdds1;
1308 appData.secondTimeOdds = second.timeOdds = tmpOdds2;
1316 switch(tcType = n) {
1318 SetWidgetText(&tcOptions[3], Value(tmpMoves), TransientDlg);
1319 SetWidgetText(&tcOptions[4], Value(tmpTc), TransientDlg);
1320 SetWidgetText(&tcOptions[5], _("Unused"), TransientDlg);
1323 SetWidgetText(&tcOptions[3], _("Unused"), TransientDlg);
1324 SetWidgetText(&tcOptions[4], Value(tmpTc), TransientDlg);
1325 SetWidgetText(&tcOptions[5], Value(tmpInc), TransientDlg);
1328 SetWidgetText(&tcOptions[3], _("Unused"), TransientDlg);
1329 SetWidgetText(&tcOptions[4], _("Unused"), TransientDlg);
1330 SetWidgetText(&tcOptions[5], Value(tmpInc), TransientDlg);
1337 tmpMoves = appData.movesPerSession;
1338 tmpInc = appData.timeIncrement; if(tmpInc < 0) tmpInc = 0;
1339 tmpOdds1 = tmpOdds2 = 1; tcType = 0;
1340 tmpTc = atoi(appData.timeControl);
1341 GenericPopUp(tcOptions, _("Time Control"), TransientDlg, BoardWindow, MODAL);
1344 //------------------------------- Ask Question -----------------------------------------
1346 int SendReply P((int n));
1347 char pendingReplyPrefix[MSG_SIZ];
1348 ProcRef pendingReplyPR;
1351 Option askOptions[] = {
1352 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, NULL },
1353 { 0, 0, 0, NULL, (void*) &answer, "", NULL, TextBox, "" },
1354 { 0, 0, 0, NULL, (void*) &SendReply, "", NULL, EndMark , "" }
1363 // GetWidgetText(&askOptions[1], &reply);
1364 safeStrCpy(buf, pendingReplyPrefix, sizeof(buf)/sizeof(buf[0]) );
1365 if (*buf) strncat(buf, " ", MSG_SIZ - strlen(buf) - 1);
1366 strncat(buf, reply, MSG_SIZ - strlen(buf) - 1);
1367 strncat(buf, "\n", MSG_SIZ - strlen(buf) - 1);
1368 OutputToProcess(pendingReplyPR, buf, strlen(buf), &err); // does not go into debug file??? => bug
1369 if (err) DisplayFatalError(_("Error writing to chess program"), err, 0);
1374 AskQuestion (char *title, char *question, char *replyPrefix, ProcRef pr)
1376 safeStrCpy(pendingReplyPrefix, replyPrefix, sizeof(pendingReplyPrefix)/sizeof(pendingReplyPrefix[0]) );
1377 pendingReplyPR = pr;
1379 askOptions[0].name = question;
1380 if(GenericPopUp(askOptions, title, AskDlg, BoardWindow, MODAL))
1381 AddHandler(&askOptions[1], 2);
1384 //---------------------------- Chat Windows ----------------------------------------------
1387 OutputChatMessage (int partner, char *mess)
1392 //----------------------------- Various display boxes -----------------------------
1395 DisplayError (String message, int error)
1400 if (appData.debugMode || appData.matchMode) {
1401 fprintf(stderr, "%s: %s\n", programName, message);
1404 if (appData.debugMode || appData.matchMode) {
1405 fprintf(stderr, "%s: %s: %s\n",
1406 programName, message, strerror(error));
1408 snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error));
1411 ErrorPopUp(_("Error"), message, FALSE);
1416 DisplayMoveError (String message)
1420 DrawPosition(FALSE, NULL);
1421 if (appData.debugMode || appData.matchMode) {
1422 fprintf(stderr, "%s: %s\n", programName, message);
1424 if (appData.popupMoveErrors) {
1425 ErrorPopUp(_("Error"), message, FALSE);
1427 DisplayMessage(message, "");
1433 DisplayFatalError (String message, int error, int status)
1437 errorExitStatus = status;
1439 fprintf(stderr, "%s: %s\n", programName, message);
1441 fprintf(stderr, "%s: %s: %s\n",
1442 programName, message, strerror(error));
1443 snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error));
1446 if (appData.popupExitMessage && boardWidget && XtIsRealized(boardWidget)) {
1447 ErrorPopUp(status ? _("Fatal Error") : _("Exiting"), message, TRUE);
1454 DisplayInformation (String message)
1457 ErrorPopUp(_("Information"), message, TRUE);
1461 DisplayNote (String message)
1464 ErrorPopUp(_("Note"), message, FALSE);
1468 DisplayTitle (char *text)
1470 char title[MSG_SIZ];
1473 if (text == NULL) text = "";
1475 if (*text != NULLCHAR) {
1476 safeStrCpy(icon, text, sizeof(icon)/sizeof(icon[0]) );
1477 safeStrCpy(title, text, sizeof(title)/sizeof(title[0]) );
1478 } else if (appData.icsActive) {
1479 snprintf(icon, sizeof(icon), "%s", appData.icsHost);
1480 snprintf(title, sizeof(title), "%s: %s", programName, appData.icsHost);
1481 } else if (appData.cmailGameName[0] != NULLCHAR) {
1482 snprintf(icon, sizeof(icon), "%s", "CMail");
1483 snprintf(title,sizeof(title), "%s: %s", programName, "CMail");
1485 // [HGM] license: This stuff should really be done in back-end, but WinBoard already had a pop-up for it
1486 } else if (gameInfo.variant == VariantGothic) {
1487 safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) );
1488 safeStrCpy(title, GOTHIC, sizeof(title)/sizeof(title[0]) );
1491 } else if (gameInfo.variant == VariantFalcon) {
1492 safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) );
1493 safeStrCpy(title, FALCON, sizeof(title)/sizeof(title[0]) );
1495 } else if (appData.noChessProgram) {
1496 safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) );
1497 safeStrCpy(title, programName, sizeof(title)/sizeof(title[0]) );
1499 safeStrCpy(icon, first.tidy, sizeof(icon)/sizeof(icon[0]) );
1500 snprintf(title,sizeof(title), "%s: %s", programName, first.tidy);
1502 SetWindowTitle(text, title, icon);