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") },
258 { 0, SAME_ROW|LL, 0, NULL, NULL, "", NULL, Label, N_(" (for concurrent playing of a single") },
259 { 0, 0, 0, NULL, (void*) &appData.cycleSync, "", NULL, CheckBox, N_("Sync after cycle") },
260 { 0, SAME_ROW|LL, 0, NULL, NULL, "", NULL, Label, N_(" tourney with multiple XBoards)") },
261 { 150, T_VSCRL | T_FILL | T_WRAP,
262 0, NULL, (void*) &engineName, "", NULL, TextBox, N_("Tourney participants:") },
263 { 0, COMBO_CALLBACK | NO_GETTEXT,
264 0, NULL, (void*) &AddToTourney, (char*) (engineMnemonic+1), (engineMnemonic+1), ComboBox, N_("Select Engine:") },
265 { 0, 0, 10, NULL, (void*) &appData.tourneyType, "", NULL, Spin, N_("Tourney type (0 = round-robin, 1 = gauntlet):") },
266 { 0, 1, 1000000000, NULL, (void*) &appData.tourneyCycles, "", NULL, Spin, N_("Number of tourney cycles (or Swiss rounds):") },
267 { 0, 1, 1000000000, NULL, (void*) &appData.defaultMatchGames, "", NULL, Spin, N_("Default Number of Games in Match (or Pairing):") },
268 { 0, 0, 1000000000, NULL, (void*) &appData.matchPause, "", NULL, Spin, N_("Pause between Match Games (msec):") },
269 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, ".pgn", NULL, FileName, N_("Save Tourney Games on:") },
270 { 0, 0, 0, NULL, (void*) &appData.loadGameFile, ".pgn", NULL, FileName, N_("Game File with Opening Lines:") },
271 { 0, -2, 1000000000, NULL, (void*) &appData.loadGameIndex, "", NULL, Spin, N_("Game Number (-1 or -2 = Auto-Increment):") },
272 { 0, 0, 0, NULL, (void*) &appData.loadPositionFile, ".fen", NULL, FileName, N_("File with Start Positions:") },
273 { 0, -2, 1000000000, NULL, (void*) &appData.loadPositionIndex, "", NULL, Spin, N_("Position Number (-1 or -2 = Auto-Increment):") },
274 { 0, 0, 1000000000, NULL, (void*) &appData.rewindIndex, "", NULL, Spin, N_("Rewind Index after this many Games (0 = never):") },
275 { 0, 0, 0, NULL, (void*) &appData.defNoBook, "", NULL, CheckBox, N_("Disable own engine books by default") },
276 { 0, 0, 0, NULL, (void*) &ReplaceParticipant, NULL, NULL, Button, N_("Replace Engine") },
277 { 0, SAME_ROW, 0, NULL, (void*) &UpgradeParticipant, NULL, NULL, Button, N_("Upgrade Engine") },
278 { 0, SAME_ROW, 0, NULL, (void*) &CloneTourney, NULL, NULL, Button, N_("Clone Tourney") },
279 { 0, SAME_ROW, 0, NULL, (void*) &MatchOK, "", NULL, EndMark , "" }
283 ReplaceParticipant ()
285 GenericReadout(matchOptions, 5);
286 Substitute(strdup(engineName), True);
290 UpgradeParticipant ()
292 GenericReadout(matchOptions, 5);
293 Substitute(strdup(engineName), False);
301 GetWidgetText(matchOptions, &name);
302 if(name && name[0] && (f = fopen(name, "r")) ) {
304 saveSaveFile = appData.saveGameFile; appData.saveGameFile = NULL; // this is a persistent option, protect from change
305 ParseArgsFromFile(f);
306 engineName = appData.participants; GenericUpdate(matchOptions, -1);
307 FREE(appData.saveGameFile); appData.saveGameFile = saveSaveFile;
308 } else DisplayError(_("First you must specify an existing tourney file to clone"), 0);
314 AddLine(&matchOptions[5], engineMnemonic[values[6]+1]);
320 NamesToList(firstChessProgramNames, engineList, engineMnemonic, "all");
321 matchOptions[7].min = -(appData.pairingEngine[0] != NULLCHAR); // with pairing engine, allow Swiss
322 ASSIGN(tfName, appData.tourneyFile[0] ? appData.tourneyFile : MakeName(appData.defName));
323 ASSIGN(engineName, appData.participants);
324 GenericPopUp(matchOptions, _("Match Options"), TransientDlg, BoardWindow, MODAL, 0);
327 // ------------------------------------------- General Options --------------------------------------------------
329 static int oldShow, oldBlind, oldPonder;
332 GeneralOptionsOK (int n)
334 int newPonder = appData.ponderNextMove;
335 appData.ponderNextMove = oldPonder;
336 PonderNextMoveEvent(newPonder);
337 if(!appData.highlightLastMove) ClearHighlights(), ClearPremoveHighlights();
338 if(oldShow != appData.showCoords || oldBlind != appData.blindfold) DrawPosition(TRUE, NULL);
342 static Option generalOptions[] = {
343 { 0, 0, 0, NULL, (void*) &appData.whitePOV, "", NULL, CheckBox, N_("Absolute Analysis Scores") },
344 { 0, 0, 0, NULL, (void*) &appData.sweepSelect, "", NULL, CheckBox, N_("Almost Always Queen (Detour Under-Promote)") },
345 { 0, 0, 0, NULL, (void*) &appData.animateDragging, "", NULL, CheckBox, N_("Animate Dragging") },
346 { 0, 0, 0, NULL, (void*) &appData.animate, "", NULL, CheckBox, N_("Animate Moving") },
347 { 0, 0, 0, NULL, (void*) &appData.autoCallFlag, "", NULL, CheckBox, N_("Auto Flag") },
348 { 0, 0, 0, NULL, (void*) &appData.autoFlipView, "", NULL, CheckBox, N_("Auto Flip View") },
349 { 0, 0, 0, NULL, (void*) &appData.blindfold, "", NULL, CheckBox, N_("Blindfold") },
350 { 0, 0, 0, NULL, (void*) &appData.dropMenu, "", NULL, CheckBox, N_("Drop Menu") },
351 { 0, 0, 0, NULL, (void*) &appData.hideThinkingFromHuman, "", NULL, CheckBox, N_("Hide Thinking from Human") },
352 { 0, 0, 0, NULL, (void*) &appData.highlightLastMove, "", NULL, CheckBox, N_("Highlight Last Move") },
353 { 0, 0, 0, NULL, (void*) &appData.highlightMoveWithArrow, "", NULL, CheckBox, N_("Highlight with Arrow") },
354 { 0, 0, 0, NULL, (void*) &appData.ringBellAfterMoves, "", NULL, CheckBox, N_("Move Sound") },
355 { 0, 0, 0, NULL, (void*) &appData.oneClick, "", NULL, CheckBox, N_("One-Click Moving") },
356 { 0, 0, 0, NULL, (void*) &appData.periodicUpdates, "", NULL, CheckBox, N_("Periodic Updates (in Analysis Mode)") },
357 { 0, 0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, N_("Ponder Next Move") },
358 { 0, 0, 0, NULL, (void*) &appData.popupExitMessage, "", NULL, CheckBox, N_("Popup Exit Messages") },
359 { 0, 0, 0, NULL, (void*) &appData.popupMoveErrors, "", NULL, CheckBox, N_("Popup Move Errors") },
360 { 0, 0, 0, NULL, (void*) &appData.showEvalInMoveHistory, "", NULL, CheckBox, N_("Scores in Move List") },
361 { 0, 0, 0, NULL, (void*) &appData.showCoords, "", NULL, CheckBox, N_("Show Coordinates") },
362 { 0, 0, 0, NULL, (void*) &appData.markers, "", NULL, CheckBox, N_("Show Target Squares") },
363 { 0, 0, 0, NULL, (void*) &appData.useStickyWindows, "", NULL, CheckBox, N_("Sticky Windows") },
364 { 0, 0, 0, NULL, (void*) &appData.testLegality, "", NULL, CheckBox, N_("Test Legality") },
365 { 0, 0, 0, NULL, (void*) &appData.topLevel, "", NULL, CheckBox, N_("Top-Level Dialogs") },
366 { 0, 0,10, NULL, (void*) &appData.flashCount, "", NULL, Spin, N_("Flash Moves (0 = no flashing):") },
367 { 0, 1,10, NULL, (void*) &appData.flashRate, "", NULL, Spin, N_("Flash Rate (high = fast):") },
368 { 0, 5,100, NULL, (void*) &appData.animSpeed, "", NULL, Spin, N_("Animation Speed (high = slow):") },
369 { 0, 1,5, NULL, (void*) &appData.zoom, "", NULL, Spin, N_("Zoom factor in Evaluation Graph:") },
370 { 0, 0, 0, NULL, (void*) &GeneralOptionsOK, "", NULL, EndMark , "" }
376 oldPonder = appData.ponderNextMove;
377 oldShow = appData.showCoords; oldBlind = appData.blindfold;
378 GenericPopUp(generalOptions, _("General Options"), TransientDlg, BoardWindow, MODAL, 0);
381 //---------------------------------------------- New Variant ------------------------------------------------
383 static void Pick P((int n));
385 static Option variantDescriptors[] = {
386 { VariantNormal, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("normal")},
387 { VariantFairy, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("fairy")},
388 { VariantFischeRandom, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("FRC")},
389 { VariantSChess, SAME_ROW, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Seirawan")},
390 { VariantWildCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("wild castle")},
391 { VariantSuper, SAME_ROW, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Superchess")},
392 { VariantNoCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("no castle")},
393 { VariantCrazyhouse,SAME_ROW,135,NULL,(void*) &Pick, "#FFBFBF", NULL, Button, N_("crazyhouse")},
394 { VariantKnightmate, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("knightmate")},
395 { VariantBughouse,SAME_ROW,135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("bughouse")},
396 { VariantBerolina, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("berolina")},
397 { VariantShogi, SAME_ROW, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("shogi (9x9)")},
398 { VariantCylinder, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("cylinder")},
399 { VariantXiangqi, SAME_ROW,135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("xiangqi (9x10)")},
400 { VariantShatranj, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("shatranj")},
401 { VariantCourier, SAME_ROW,135, NULL, (void*) &Pick, "#BFFFBF", NULL, Button, N_("courier (12x8)")},
402 { VariantMakruk, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("makruk")},
403 { VariantGreat, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Great Shatranj (10x8)")},
404 { VariantAtomic, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("atomic")},
405 { VariantFalcon, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("falcon (10x8)")},
406 { VariantTwoKings, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("two kings")},
407 { VariantCapablanca,SAME_ROW,135,NULL,(void*) &Pick, "#BFBFFF", NULL, Button, N_("Capablanca (10x8)")},
408 { Variant3Check, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("3-checks")},
409 { VariantGothic, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Gothic (10x8)")},
410 { VariantSuicide, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("suicide")},
411 { VariantJanus, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("janus (10x8)")},
412 { VariantGiveaway, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("give-away")},
413 { VariantCapaRandom,SAME_ROW,135,NULL,(void*) &Pick, "#BFBFFF", NULL, Button, N_("CRC (10x8)")},
414 { VariantLosers, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("losers")},
415 { VariantGrand, SAME_ROW, 135, NULL, (void*) &Pick, "#5070FF", NULL, Button, N_("grand (10x10)")},
416 { VariantSpartan, 0, 135, NULL, (void*) &Pick, "#FF0000", NULL, Button, N_("Spartan")},
417 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Board size ( -1 = default for selected variant):")},
418 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.NrRanks, "", NULL, Spin, N_("Number of Board Ranks:") },
419 { 0, -1, BOARD_FILES, NULL, (void*) &appData.NrFiles, "", NULL, Spin, N_("Number of Board Files:") },
420 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.holdingsSize, "", NULL, Spin, N_("Holdings Size:") },
421 { 0, 0, 0, NULL, NULL, NULL, NULL, Label,
422 N_("WARNING: variants with un-orthodox\n"
423 "pieces only have built-in bitmaps\n"
424 "for -boardSize middling, bulky and\n"
425 "petite, and substitute king or amazon\n"
426 "for missing bitmaps. (See manual.)")},
427 { 0, NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
433 VariantClass v = variantDescriptors[n].value;
434 if(!appData.noChessProgram) {
435 char *name = VariantName(v), buf[MSG_SIZ];
436 if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) {
437 /* [HGM] in protocol 2 we check if variant is suported by engine */
438 snprintf(buf, MSG_SIZ, _("Variant %s not supported by %s"), name, first.tidy);
439 DisplayError(buf, 0);
440 return; /* ignore OK if first engine does not support it */
442 if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) {
443 snprintf(buf, MSG_SIZ, _("Warning: second engine (%s) does not support this!"), second.tidy);
444 DisplayError(buf, 0); /* use of second engine is optional; only warn user */
448 GenericReadout(variantDescriptors, -1); // make sure ranks and file settings are read
450 gameInfo.variant = v;
451 appData.variant = VariantName(v);
453 shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */
454 startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */
455 appData.pieceToCharTable = NULL;
456 appData.pieceNickNames = "";
457 appData.colorNickNames = "";
459 PopDown(TransientDlg);
466 GenericPopUp(variantDescriptors, _("New Variant"), TransientDlg, BoardWindow, MODAL, 0);
469 //------------------------------------------- Common Engine Options -------------------------------------
474 CommonOptionsOK (int n)
476 int newPonder = appData.ponderNextMove;
477 // make sure changes are sent to first engine by re-initializing it
478 // if it was already started pre-emptively at end of previous game
479 if(gameMode == BeginningOfGame) Reset(True, True); else {
480 // Some changed setting need immediate sending always.
481 if(oldCores != appData.smpCores)
482 NewSettingEvent(False, &(first.maxCores), "cores", appData.smpCores);
483 appData.ponderNextMove = oldPonder;
484 PonderNextMoveEvent(newPonder);
489 static Option commonEngineOptions[] = {
490 { 0, 0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, N_("Ponder Next Move") },
491 { 0, 0, 1000, NULL, (void*) &appData.smpCores, "", NULL, Spin, N_("Maximum Number of CPUs per Engine:") },
492 { 0, 0, 0, NULL, (void*) &appData.polyglotDir, "", NULL, PathName, N_("Polygot Directory:") },
493 { 0, 0,16000, NULL, (void*) &appData.defaultHashSize, "", NULL, Spin, N_("Hash-Table Size (MB):") },
494 { 0, 0, 0, NULL, (void*) &appData.defaultPathEGTB, "", NULL, PathName, N_("Nalimov EGTB Path:") },
495 { 0, 0, 1000, NULL, (void*) &appData.defaultCacheSizeEGTB, "", NULL, Spin, N_("EGTB Cache Size (MB):") },
496 { 0, 0, 0, NULL, (void*) &appData.usePolyglotBook, "", NULL, CheckBox, N_("Use GUI Book") },
497 { 0, 0, 0, NULL, (void*) &appData.polyglotBook, ".bin", NULL, FileName, N_("Opening-Book Filename:") },
498 { 0, 0, 100, NULL, (void*) &appData.bookDepth, "", NULL, Spin, N_("Book Depth (moves):") },
499 { 0, 0, 100, NULL, (void*) &appData.bookStrength, "", NULL, Spin, N_("Book Variety (0) vs. Strength (100):") },
500 { 0, 0, 0, NULL, (void*) &appData.firstHasOwnBookUCI, "", NULL, CheckBox, N_("Engine #1 Has Own Book") },
501 { 0, 0, 0, NULL, (void*) &appData.secondHasOwnBookUCI, "", NULL, CheckBox, N_("Engine #2 Has Own Book ") },
502 { 0,SAME_ROW,0,NULL, (void*) &CommonOptionsOK, "", NULL, EndMark , "" }
508 oldCores = appData.smpCores;
509 oldPonder = appData.ponderNextMove;
510 GenericPopUp(commonEngineOptions, _("Common Engine Settings"), TransientDlg, BoardWindow, MODAL, 0);
513 //------------------------------------------ Adjudication Options --------------------------------------
515 static Option adjudicationOptions[] = {
516 { 0, 0, 0, NULL, (void*) &appData.checkMates, "", NULL, CheckBox, N_("Detect all Mates") },
517 { 0, 0, 0, NULL, (void*) &appData.testClaims, "", NULL, CheckBox, N_("Verify Engine Result Claims") },
518 { 0, 0, 0, NULL, (void*) &appData.materialDraws, "", NULL, CheckBox, N_("Draw if Insufficient Mating Material") },
519 { 0, 0, 0, NULL, (void*) &appData.trivialDraws, "", NULL, CheckBox, N_("Adjudicate Trivial Draws (3-Move Delay)") },
520 { 0, 0,100, NULL, (void*) &appData.ruleMoves, "", NULL, Spin, N_("N-Move Rule:") },
521 { 0, 0, 6, NULL, (void*) &appData.drawRepeats, "", NULL, Spin, N_("N-fold Repeats:") },
522 { 0, 0,1000, NULL, (void*) &appData.adjudicateDrawMoves, "", NULL, Spin, N_("Draw after N Moves Total:") },
523 { 0, -5000,0, NULL, (void*) &appData.adjudicateLossThreshold, "", NULL, Spin, N_("Win / Loss Threshold:") },
524 { 0, 0, 0, NULL, (void*) &first.scoreIsAbsolute, "", NULL, CheckBox, N_("Negate Score of Engine #1") },
525 { 0, 0, 0, NULL, (void*) &second.scoreIsAbsolute, "", NULL, CheckBox, N_("Negate Score of Engine #2") },
526 { 0,SAME_ROW, 0, NULL, NULL, "", NULL, EndMark , "" }
532 GenericPopUp(adjudicationOptions, _("Adjudicate non-ICS Games"), TransientDlg, BoardWindow, MODAL, 0);
535 //--------------------------------------------- ICS Options ---------------------------------------------
540 ParseIcsTextColors();
544 Option icsOptions[] = {
545 { 0, 0, 0, NULL, (void*) &appData.autoKibitz, "", NULL, CheckBox, N_("Auto-Kibitz") },
546 { 0, 0, 0, NULL, (void*) &appData.autoComment, "", NULL, CheckBox, N_("Auto-Comment") },
547 { 0, 0, 0, NULL, (void*) &appData.autoObserve, "", NULL, CheckBox, N_("Auto-Observe") },
548 { 0, 0, 0, NULL, (void*) &appData.autoRaiseBoard, "", NULL, CheckBox, N_("Auto-Raise Board") },
549 { 0, 0, 0, NULL, (void*) &appData.bgObserve, "", NULL, CheckBox, N_("Background Observe while Playing") },
550 { 0, 0, 0, NULL, (void*) &appData.dualBoard, "", NULL, CheckBox, N_("Dual Board for Background-Observed Game") },
551 { 0, 0, 0, NULL, (void*) &appData.getMoveList, "", NULL, CheckBox, N_("Get Move List") },
552 { 0, 0, 0, NULL, (void*) &appData.quietPlay, "", NULL, CheckBox, N_("Quiet Play") },
553 { 0, 0, 0, NULL, (void*) &appData.seekGraph, "", NULL, CheckBox, N_("Seek Graph") },
554 { 0, 0, 0, NULL, (void*) &appData.autoRefresh, "", NULL, CheckBox, N_("Auto-Refresh Seek Graph") },
555 { 0, 0, 0, NULL, (void*) &appData.premove, "", NULL, CheckBox, N_("Premove") },
556 { 0, 0, 0, NULL, (void*) &appData.premoveWhite, "", NULL, CheckBox, N_("Premove for White") },
557 { 0, 0, 0, NULL, (void*) &appData.premoveWhiteText, "", NULL, TextBox, N_("First White Move:") },
558 { 0, 0, 0, NULL, (void*) &appData.premoveBlack, "", NULL, CheckBox, N_("Premove for Black") },
559 { 0, 0, 0, NULL, (void*) &appData.premoveBlackText, "", NULL, TextBox, N_("First Black Move:") },
560 { 0, SAME_ROW, 0, NULL, NULL, NULL, NULL, Break, "" },
561 { 0, 0, 0, NULL, (void*) &appData.icsAlarm, "", NULL, CheckBox, N_("Alarm") },
562 { 0, 0, 100000000, NULL, (void*) &appData.icsAlarmTime, "", NULL, Spin, N_("Alarm Time (msec):") },
563 //{ 0, 0, 0, NULL, (void*) &appData.chatBoxes, "", NULL, TextBox, N_("Startup Chat Boxes:") },
564 { 0, 0, 0, NULL, (void*) &appData.colorize, "", NULL, CheckBox, N_("Colorize Messages") },
565 { 0, 0, 0, NULL, (void*) &appData.colorShout, "", NULL, TextBox, N_("Shout Text Colors:") },
566 { 0, 0, 0, NULL, (void*) &appData.colorSShout, "", NULL, TextBox, N_("S-Shout Text Colors:") },
567 { 0, 0, 0, NULL, (void*) &appData.colorChannel1, "", NULL, TextBox, N_("Channel #1 Text Colors:") },
568 { 0, 0, 0, NULL, (void*) &appData.colorChannel, "", NULL, TextBox, N_("Other Channel Text Colors:") },
569 { 0, 0, 0, NULL, (void*) &appData.colorKibitz, "", NULL, TextBox, N_("Kibitz Text Colors:") },
570 { 0, 0, 0, NULL, (void*) &appData.colorTell, "", NULL, TextBox, N_("Tell Text Colors:") },
571 { 0, 0, 0, NULL, (void*) &appData.colorChallenge, "", NULL, TextBox, N_("Challenge Text Colors:") },
572 { 0, 0, 0, NULL, (void*) &appData.colorRequest, "", NULL, TextBox, N_("Request Text Colors:") },
573 { 0, 0, 0, NULL, (void*) &appData.colorSeek, "", NULL, TextBox, N_("Seek Text Colors:") },
574 { 0, 0, 0, NULL, (void*) &IcsOptionsOK, "", NULL, EndMark , "" }
580 GenericPopUp(icsOptions, _("ICS Options"), TransientDlg, BoardWindow, MODAL, 0);
583 //-------------------------------------------- Load Game Options ---------------------------------
585 static char *modeNames[] = { N_("Exact position match"), N_("Shown position is subset"), N_("Same material with exactly same Pawn chain"),
586 N_("Same material"), N_("Material range (top board half optional)"), N_("Material difference (optional stuff balanced)"), NULL };
587 static char *modeValues[] = { "1", "2", "3", "4", "5", "6" };
588 static char *searchMode;
593 appData.searchMode = atoi(searchMode);
597 static Option loadOptions[] = {
598 { 0, 0, 0, NULL, (void*) &appData.autoDisplayTags, "", NULL, CheckBox, N_("Auto-Display Tags") },
599 { 0, 0, 0, NULL, (void*) &appData.autoDisplayComment, "", NULL, CheckBox, N_("Auto-Display Comment") },
600 { 0, LR, 0, NULL, NULL, NULL, NULL, Label, N_("Auto-Play speed of loaded games\n(0 = instant, -1 = off):") },
601 { 0, -1,10000000, NULL, (void*) &appData.timeDelay, "", NULL, Fractional, N_("Seconds per Move:") },
602 { 0, LR, 0, NULL, NULL, NULL, NULL, Label, N_("\noptions to use in game-viewer mode:") },
603 { 0, 0,300, NULL, (void*) &appData.viewerOptions, "", NULL, TextBox, "" },
604 { 0, LR, 0, NULL, NULL, NULL, NULL, Label, N_("\nThresholds for position filtering in game list:") },
605 { 0, 0,5000, NULL, (void*) &appData.eloThreshold1, "", NULL, Spin, N_("Elo of strongest player at least:") },
606 { 0, 0,5000, NULL, (void*) &appData.eloThreshold2, "", NULL, Spin, N_("Elo of weakest player at least:") },
607 { 0, 0,5000, NULL, (void*) &appData.dateThreshold, "", NULL, Spin, N_("No games before year:") },
608 { 0, 1,50, NULL, (void*) &appData.stretch, "", NULL, Spin, N_("Minimum nr consecutive positions:") },
609 { 0, 0,205, NULL, (void*) &searchMode, (char*) modeValues, modeNames, ComboBox, N_("Search mode:") },
610 { 0, 0, 0, NULL, (void*) &appData.ignoreColors, "", NULL, CheckBox, N_("Also match reversed colors") },
611 { 0, 0, 0, NULL, (void*) &appData.findMirror, "", NULL, CheckBox, N_("Also match left-right flipped position") },
612 { 0, 0, 0, NULL, (void*) &LoadOptionsOK, "", NULL, EndMark , "" }
616 LoadOptionsPopUp (DialogClass parent)
618 ASSIGN(searchMode, modeValues[appData.searchMode-1]);
619 GenericPopUp(loadOptions, _("Load Game Options"), TransientDlg, parent, MODAL, 0);
624 { // called from menu
625 LoadOptionsPopUp(BoardWindow);
628 //------------------------------------------- Save Game Options --------------------------------------------
630 static Option saveOptions[] = {
631 { 0, 0, 0, NULL, (void*) &appData.autoSaveGames, "", NULL, CheckBox, N_("Auto-Save Games") },
632 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, ".pgn", NULL, FileName, N_("Save Games on File:") },
633 { 0, 0, 0, NULL, (void*) &appData.savePositionFile, ".fen", NULL, FileName, N_("Save Final Positions on File:") },
634 { 0, 0, 0, NULL, (void*) &appData.pgnEventHeader, "", NULL, TextBox, N_("PGN Event Header:") },
635 { 0, 0, 0, NULL, (void*) &appData.oldSaveStyle, "", NULL, CheckBox, N_("Old Save Style (as opposed to PGN)") },
636 { 0, 0, 0, NULL, (void*) &appData.numberTag, "", NULL, CheckBox, N_("Include Number Tag in tourney PGN") },
637 { 0, 0, 0, NULL, (void*) &appData.saveExtendedInfoInPGN, "", NULL, CheckBox, N_("Save Score/Depth Info in PGN") },
638 { 0, 0, 0, NULL, (void*) &appData.saveOutOfBookInfo, "", NULL, CheckBox, N_("Save Out-of-Book Info in PGN ") },
639 { 0, SAME_ROW, 0, NULL, NULL, "", NULL, EndMark , "" }
645 GenericPopUp(saveOptions, _("Save Game Options"), TransientDlg, BoardWindow, MODAL, 0);
648 //----------------------------------------------- Sound Options ---------------------------------------------
650 static void Test P((int n));
651 static char *trialSound;
653 static char *soundNames[] = {
656 N_("Above WAV File"),
671 static char *soundFiles[] = { // sound files corresponding to above names
674 NULL, // kludge alert: as first thing in the dialog readout this is replaced with the user-given .WAV filename
689 static Option soundOptions[] = {
690 { 0, 0, 0, NULL, (void*) &appData.soundProgram, "", NULL, TextBox, N_("Sound Program:") },
691 { 0, 0, 0, NULL, (void*) &appData.soundDirectory, "", NULL, PathName, N_("Sounds Directory:") },
692 { 0, 0, 0, NULL, (void*) (soundFiles+2) /* kludge! */, ".wav", NULL, FileName, N_("User WAV File:") },
693 { 0, 0, 0, NULL, (void*) &trialSound, (char*) soundFiles, soundNames, ComboBox, N_("Try-Out Sound:") },
694 { 0, SAME_ROW, 0, NULL, (void*) &Test, NULL, NULL, Button, N_("Play") },
695 { 0, 0, 0, NULL, (void*) &appData.soundMove, (char*) soundFiles, soundNames, ComboBox, N_("Move:") },
696 { 0, 0, 0, NULL, (void*) &appData.soundIcsWin, (char*) soundFiles, soundNames, ComboBox, N_("Win:") },
697 { 0, 0, 0, NULL, (void*) &appData.soundIcsLoss, (char*) soundFiles, soundNames, ComboBox, N_("Lose:") },
698 { 0, 0, 0, NULL, (void*) &appData.soundIcsDraw, (char*) soundFiles, soundNames, ComboBox, N_("Draw:") },
699 { 0, 0, 0, NULL, (void*) &appData.soundIcsUnfinished, (char*) soundFiles, soundNames, ComboBox, N_("Unfinished:") },
700 { 0, 0, 0, NULL, (void*) &appData.soundIcsAlarm, (char*) soundFiles, soundNames, ComboBox, N_("Alarm:") },
701 { 0, 0, 0, NULL, (void*) &appData.soundShout, (char*) soundFiles, soundNames, ComboBox, N_("Shout:") },
702 { 0, 0, 0, NULL, (void*) &appData.soundSShout, (char*) soundFiles, soundNames, ComboBox, N_("S-Shout:") },
703 { 0, 0, 0, NULL, (void*) &appData.soundChannel, (char*) soundFiles, soundNames, ComboBox, N_("Channel:") },
704 { 0, 0, 0, NULL, (void*) &appData.soundChannel1, (char*) soundFiles, soundNames, ComboBox, N_("Channel 1:") },
705 { 0, 0, 0, NULL, (void*) &appData.soundTell, (char*) soundFiles, soundNames, ComboBox, N_("Tell:") },
706 { 0, 0, 0, NULL, (void*) &appData.soundKibitz, (char*) soundFiles, soundNames, ComboBox, N_("Kibitz:") },
707 { 0, 0, 0, NULL, (void*) &appData.soundChallenge, (char*) soundFiles, soundNames, ComboBox, N_("Challenge:") },
708 { 0, 0, 0, NULL, (void*) &appData.soundRequest, (char*) soundFiles, soundNames, ComboBox, N_("Request:") },
709 { 0, 0, 0, NULL, (void*) &appData.soundSeek, (char*) soundFiles, soundNames, ComboBox, N_("Seek:") },
710 { 0, SAME_ROW, 0, NULL, NULL, "", NULL, EndMark , "" }
716 GenericReadout(soundOptions, 2);
717 if(soundFiles[values[3]]) PlaySound(soundFiles[values[3]]);
724 soundFiles[2] = strdup("*");
725 GenericPopUp(soundOptions, _("Sound Options"), TransientDlg, BoardWindow, MODAL, 0);
728 //--------------------------------------------- Board Options --------------------------------------
730 static void DefColor P((int n));
731 static void AdjustColor P((int i));
734 BoardOptionsOK (int n)
736 if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap;
737 useImages = useImageSqs = 0;
739 InitDrawingSizes(-1, 0);
740 DrawPosition(True, NULL);
744 static Option boardOptions[] = {
745 { 0, 0, 70, NULL, (void*) &appData.whitePieceColor, "", NULL, TextBox, N_("White Piece Color:") },
746 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#FFFFCC", Button, " " },
747 /* TRANSLATORS: R = single letter for the color red */
748 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
749 /* TRANSLATORS: G = single letter for the color green */
750 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
751 /* TRANSLATORS: B = single letter for the color blue */
752 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
753 /* TRANSLATORS: D = single letter to make a color darker */
754 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
755 { 0, 0, 70, NULL, (void*) &appData.blackPieceColor, "", NULL, TextBox, N_("Black Piece Color:") },
756 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#202020", Button, " " },
757 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
758 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
759 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
760 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
761 { 0, 0, 70, NULL, (void*) &appData.lightSquareColor, "", NULL, TextBox, N_("Light Square Color:") },
762 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#C8C365", Button, " " },
763 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
764 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
765 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
766 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
767 { 0, 0, 70, NULL, (void*) &appData.darkSquareColor, "", NULL, TextBox, N_("Dark Square Color:") },
768 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#77A26D", Button, " " },
769 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
770 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
771 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
772 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
773 { 0, 0, 70, NULL, (void*) &appData.highlightSquareColor, "", NULL, TextBox, N_("Highlight Color:") },
774 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#FFFF00", Button, " " },
775 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
776 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
777 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
778 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
779 { 0, 0, 70, NULL, (void*) &appData.premoveHighlightColor, "", NULL, TextBox, N_("Premove Highlight Color:") },
780 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#FF0000", Button, " " },
781 { 1, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("R") },
782 { 2, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("G") },
783 { 3, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("B") },
784 { 4, SAME_ROW, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, N_("D") },
785 { 0, 0, 0, NULL, (void*) &appData.upsideDown, "", NULL, CheckBox, N_("Flip Pieces Shogi Style (Colored buttons restore default)") },
786 //{ 0, 0, 0, NULL, (void*) &appData.allWhite, "", NULL, CheckBox, N_("Use Outline Pieces for Black") },
787 { 0, 0, 0, NULL, (void*) &appData.monoMode, "", NULL, CheckBox, N_("Mono Mode") },
788 { 0,-1, 5, NULL, (void*) &appData.overrideLineGap, "", NULL, Spin, N_("Line Gap ( -1 = default for board size):") },
789 { 0, 0, 0, NULL, (void*) &appData.useBitmaps, "", NULL, CheckBox, N_("Use Board Textures") },
790 { 0, 0, 0, NULL, (void*) &appData.liteBackTextureFile, ".xpm", NULL, FileName, N_("Light-Squares Texture File:") },
791 { 0, 0, 0, NULL, (void*) &appData.darkBackTextureFile, ".xpm", NULL, FileName, N_("Dark-Squares Texture File:") },
792 { 0, 0, 0, NULL, (void*) &appData.bitmapDirectory, "", NULL, PathName, N_("Directory with Bitmap Pieces:") },
793 { 0, 0, 0, NULL, (void*) &appData.pixmapDirectory, "", NULL, PathName, N_("Directory with Pixmap Pieces:") },
794 { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" }
798 SetColorText (int n, char *buf)
800 SetWidgetText(&boardOptions[n-1], buf, TransientDlg);
801 SetColor(buf, &boardOptions[n]);
807 SetColorText(n, (char*) boardOptions[n].choice);
811 RefreshColor (int source, int n)
813 int col, j, r, g, b, step = 10;
814 char *s, buf[MSG_SIZ]; // color string
815 GetWidgetText(&boardOptions[source], &s);
816 if(sscanf(s, "#%x", &col) != 1) return; // malformed
817 b = col & 0xFF; g = col & 0xFF00; r = col & 0xFF0000;
819 case 1: r += 0x10000*step;break;
820 case 2: g += 0x100*step; break;
821 case 3: b += step; break;
822 case 4: r -= 0x10000*step; g -= 0x100*step; b -= step; break;
824 if(r < 0) r = 0; if(g < 0) g = 0; if(b < 0) b = 0;
825 if(r > 0xFF0000) r = 0xFF0000; if(g > 0xFF00) g = 0xFF00; if(b > 0xFF) b = 0xFF;
827 snprintf(buf, MSG_SIZ, "#%06x", col);
828 for(j=1; j<7; j++) if(buf[j] >= 'a') buf[j] -= 32; // capitalize
829 SetColorText(source+1, buf);
835 int n = boardOptions[i].value;
836 RefreshColor(i-n-1, n);
842 GenericPopUp(boardOptions, _("Board Options"), TransientDlg, BoardWindow, MODAL, 0);
845 //-------------------------------------------- ICS Text Menu Options ------------------------------
847 Option textOptions[100];
848 static void PutText P((char *text, int pos));
853 char buf[MSG_SIZ], *q;
854 if(q = strstr(p, "$input")) {
855 if(!shellUp[TextMenuDlg]) return;
856 strncpy(buf, p, MSG_SIZ);
857 strncpy(buf + (q-p), q+6, MSG_SIZ-(q-p));
861 snprintf(buf, MSG_SIZ, "%s\n", p);
870 if((p = icsTextMenuString) == NULL) return;
872 q = r = p; while(*p && *p != ';') p++;
873 for(j=0; j<p-q; j++) textOptions[i].name[j] = *r++;
874 textOptions[i].name[j++] = 0;
876 if(*++p == '\n') p++; // optional linefeed after button-text terminating semicolon
878 textOptions[i].choice = (char**) (r = textOptions[i].name + j);
879 while(*p && (*p != ';' || p[1] != '\n')) textOptions[i].name[j++] = *p++;
880 textOptions[i].name[j++] = 0;
882 textOptions[i].max = 135;
883 textOptions[i].min = i&1;
884 textOptions[i].handle = NULL;
885 textOptions[i].target = &SendText;
886 textOptions[i].textValue = strstr(r, "$input") ? "#80FF80" : strstr(r, "$name") ? "#FF8080" : "#FFFFFF";
887 textOptions[i].type = Button;
888 } while(++i < 99 && *p);
890 textOptions[i].type = EndMark;
891 textOptions[i].target = NULL;
892 textOptions[i].min = 2;
893 MarkMenu("View.ICStextmenu", TextMenuDlg);
894 GenericPopUp(textOptions, _("ICS text menu"), TextMenuDlg, BoardWindow, NONMODAL, 1);
897 //---------------------------------------------------- Edit Comment -----------------------------------
899 static char *commentText;
900 static int commentIndex;
901 static void ClearComment P((int n));
902 static void SaveChanges P((int n));
905 NewComCallback (int n)
907 ReplaceComment(commentIndex, commentText);
911 Option commentOptions[] = {
912 { 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 250, NULL, (void*) &commentText, "", NULL, TextBox, "" },
913 { 0, 0, 50, NULL, (void*) &ClearComment, NULL, NULL, Button, N_("clear") },
914 { 0, SAME_ROW, 100, NULL, (void*) &SaveChanges, NULL, NULL, Button, N_("save changes") },
915 { 0, SAME_ROW, 0, NULL, (void*) &NewComCallback, "", NULL, EndMark , "" }
921 GenericReadout(commentOptions, 0);
922 ReplaceComment(commentIndex, commentText);
928 SetWidgetText(&commentOptions[0], "", CommentDlg);
932 NewCommentPopup (char *title, char *text, int index)
934 if(DialogExists(CommentDlg)) { // if already exists, alter title and content
935 SetDialogTitle(CommentDlg, title);
936 SetWidgetText(&commentOptions[0], text, CommentDlg);
938 if(commentText) free(commentText); commentText = strdup(text);
939 commentIndex = index;
940 MarkMenu("View.Comments", CommentDlg);
941 if(GenericPopUp(commentOptions, title, CommentDlg, BoardWindow, NONMODAL, 1))
942 AddHandler(&commentOptions[0], 1);
949 if (PopDown(CommentDlg)) { // popdown succesful
950 // MarkMenuItem("Edit.EditComment", False);
951 // MarkMenuItem("View.Comments", False);
956 //------------------------------------------------------ Edit Tags ----------------------------------
958 static void changeTags P((int n));
959 static char *tagsText;
962 NewTagsCallback (int n)
964 ReplaceTags(tagsText, &gameInfo);
968 static Option tagsOptions[] = {
969 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, NULL },
970 { 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 200, NULL, (void*) &tagsText, "", NULL, TextBox, "" },
971 { 0, 0, 100, NULL, (void*) &changeTags, NULL, NULL, Button, N_("save changes") },
972 { 0,SAME_ROW, 0, NULL, (void*) &NewTagsCallback, "", NULL, EndMark , "" }
978 GenericReadout(tagsOptions, 1);
979 if(bookUp) SaveToBook(tagsText); else
980 ReplaceTags(tagsText, &gameInfo);
984 NewTagsPopup (char *text, char *msg)
986 char *title = bookUp ? _("Edit book") : _("Tags");
988 if(DialogExists(TagsDlg)) { // if already exists, alter title and content
989 SetWidgetText(&tagsOptions[1], text, TagsDlg);
990 SetDialogTitle(TagsDlg, title);
992 if(tagsText) free(tagsText); tagsText = strdup(text);
993 tagsOptions[0].name = msg;
994 MarkMenu("View.Tags", TagsDlg);
995 GenericPopUp(tagsOptions, title, TagsDlg, BoardWindow, NONMODAL, 1);
998 //---------------------------------------------- ICS Input Box ----------------------------------
1002 // [HGM] code borrowed from winboard.c (which should thus go to backend.c!)
1003 #define HISTORY_SIZE 64
1004 static char *history[HISTORY_SIZE];
1005 static int histIn = 0, histP = 0;
1008 SaveInHistory (char *cmd)
1010 if (history[histIn] != NULL) {
1011 free(history[histIn]);
1012 history[histIn] = NULL;
1014 if (*cmd == NULLCHAR) return;
1015 history[histIn] = StrSave(cmd);
1016 histIn = (histIn + 1) % HISTORY_SIZE;
1017 if (history[histIn] != NULL) {
1018 free(history[histIn]);
1019 history[histIn] = NULL;
1025 PrevInHistory (char *cmd)
1028 if (histP == histIn) {
1029 if (history[histIn] != NULL) free(history[histIn]);
1030 history[histIn] = StrSave(cmd);
1032 newhp = (histP - 1 + HISTORY_SIZE) % HISTORY_SIZE;
1033 if (newhp == histIn || history[newhp] == NULL) return NULL;
1035 return history[histP];
1041 if (histP == histIn) return NULL;
1042 histP = (histP + 1) % HISTORY_SIZE;
1043 return history[histP];
1045 // end of borrowed code
1047 Option boxOptions[] = {
1048 { 30, 0, 400, NULL, (void*) &icsText, "", NULL, TextBox, "" },
1049 { 0,SAME_ROW | NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
1057 GetWidgetText(&boxOptions[0], &val);
1059 SendMultiLineToICS(val);
1060 SetWidgetText(&boxOptions[0], val, InputBoxDlg);
1065 { // [HGM] input: let up-arrow recall previous line from history
1068 if (!shellUp[InputBoxDlg]) return;
1074 GetWidgetText(&boxOptions[0], &val);
1075 val = PrevInHistory(val);
1078 val = NextInHistory();
1080 SetWidgetText(&boxOptions[0], val ? val : "", InputBoxDlg);
1084 PutText (char *text, int pos)
1086 char buf[MSG_SIZ], *p;
1088 if(strstr(text, "$add ") == text) {
1089 GetWidgetText(&boxOptions[0], &p);
1090 snprintf(buf, MSG_SIZ, "%s%s", p, text+5); text = buf;
1091 pos += strlen(p) - 5;
1093 SetWidgetText(&boxOptions[0], text, TextMenuDlg);
1094 SetInsertPos(&boxOptions[0], pos);
1100 MarkMenu("View.ICSInputBox", InputBoxDlg);
1101 if(GenericPopUp(boxOptions, _("ICS input box"), InputBoxDlg, BoardWindow, NONMODAL, 0))
1102 AddHandler(&boxOptions[0], 3);
1108 if (!PopDown(InputBoxDlg)) ICSInputBoxPopUp();
1111 //--------------------------------------------- Move Type In ------------------------------------------
1113 static int TypeInOK P((int n));
1115 Option typeOptions[] = {
1116 { 30, 0, 400, NULL, (void*) &icsText, "", NULL, TextBox, "" },
1117 { 0, SAME_ROW | NO_OK, 0, NULL, (void*) &TypeInOK, "", NULL, EndMark , "" }
1123 TypeInDoneEvent(icsText);
1128 PopUpMoveDialog (char firstchar)
1131 buf[0] = firstchar; ASSIGN(icsText, buf);
1132 if(GenericPopUp(typeOptions, _("Type a move"), TransientDlg, BoardWindow, MODAL, 0))
1133 AddHandler(&typeOptions[0], 2);
1137 BoxAutoPopUp (char *buf)
1139 if(appData.icsActive) { // text typed to board in ICS mode: divert to ICS input box
1140 if(DialogExists(InputBoxDlg)) { // box already exists: append to current contents
1141 char *p, newText[MSG_SIZ];
1142 GetWidgetText(&boxOptions[0], &p);
1143 snprintf(newText, MSG_SIZ, "%s%c", p, *buf);
1144 SetWidgetText(&boxOptions[0], newText, InputBoxDlg);
1145 if(shellUp[InputBoxDlg]) HardSetFocus (&boxOptions[0]); //why???
1146 } else icsText = buf; // box did not exist: make sure it pops up with char in it
1148 } else PopUpMoveDialog(*buf);
1151 //------------------------------------------ Engine Settings ------------------------------------
1154 SettingsPopUp (ChessProgramState *cps)
1157 GenericPopUp(cps->option, _("Engine Settings"), TransientDlg, BoardWindow, MODAL, 0);
1161 FirstSettingsProc ()
1163 SettingsPopUp(&first);
1167 SecondSettingsProc ()
1169 if(WaitForEngine(&second, SettingsMenuIfReady)) return;
1170 SettingsPopUp(&second);
1173 //----------------------------------------------- Load Engine --------------------------------------
1175 char *engineDir, *engineLine, *nickName, *params;
1176 Boolean isUCI, hasBook, storeVariant, v1, addToList, useNick;
1177 static char *engineNr[] = { N_("First Engine"), N_("Second Engine"), NULL };
1182 PopDown(TransientDlg); // early popdown, to allow FreezeUI to instate grab
1183 if(engineChoice[0] == engineNr[0][0]) Load(&first, 0); else Load(&second, 1);
1184 return FALSE; // no double PopDown!
1187 static Option installOptions[] = {
1188 { 0, NO_GETTEXT, 0, NULL, (void*) &engineLine, (char*) engineList, engineMnemonic, ComboBox, N_("Select engine from list:") },
1189 { 0, LR, 0, NULL, NULL, NULL, NULL, Label, N_("or specify one below:") },
1190 { 0, 0, 0, NULL, (void*) &nickName, NULL, NULL, TextBox, N_("Nickname (optional):") },
1191 { 0, 0, 0, NULL, (void*) &useNick, NULL, NULL, CheckBox, N_("Use nickname in PGN player tags of engine-engine games") },
1192 { 0, 0, 0, NULL, (void*) &engineDir, NULL, NULL, PathName, N_("Engine Directory:") },
1193 { 0, 0, 0, NULL, (void*) &engineName, NULL, NULL, FileName, N_("Engine Command:") },
1194 { 0, LR, 0, NULL, NULL, NULL, NULL, Label, N_("(Directory will be derived from engine path when empty)") },
1195 { 0, 0, 0, NULL, (void*) &isUCI, NULL, NULL, CheckBox, N_("UCI") },
1196 { 0, 0, 0, NULL, (void*) &v1, NULL, NULL, CheckBox, N_("WB protocol v1 (do not wait for engine features)") },
1197 { 0, 0, 0, NULL, (void*) &hasBook, NULL, NULL, CheckBox, N_("Must not use GUI book") },
1198 { 0, 0, 0, NULL, (void*) &addToList, NULL, NULL, CheckBox, N_("Add this engine to the list") },
1199 { 0, 0, 0, NULL, (void*) &storeVariant, NULL, NULL, CheckBox, N_("Force current variant with this engine") },
1200 { 0, 0, 0, NULL, (void*) &engineChoice, (char*) engineNr, engineNr, ComboBox, N_("Load mentioned engine as") },
1201 { 0,SAME_ROW, 0, NULL, (void*) &InstallOK, "", NULL, EndMark , "" }
1207 isUCI = storeVariant = v1 = useNick = False; addToList = hasBook = True; // defaults
1208 if(engineChoice) free(engineChoice); engineChoice = strdup(engineNr[0]);
1209 if(engineLine) free(engineLine); engineLine = strdup("");
1210 if(engineDir) free(engineDir); engineDir = strdup("");
1211 if(nickName) free(nickName); nickName = strdup("");
1212 if(params) free(params); params = strdup("");
1213 NamesToList(firstChessProgramNames, engineList, engineMnemonic, "all");
1214 GenericPopUp(installOptions, _("Load engine"), TransientDlg, BoardWindow, MODAL, 0);
1217 //----------------------------------------------------- Edit Book -----------------------------------------
1225 //--------------------------------------------------- New Shuffle Game ------------------------------
1227 static void SetRandom P((int n));
1236 static Option shuffleOptions[] = {
1237 { 0, 0, 50, NULL, (void*) &shuffleOpenings, NULL, NULL, CheckBox, N_("shuffle") },
1238 { 0,-1,2000000000, NULL, (void*) &appData.defaultFrcPosition, "", NULL, Spin, N_("Start-position number:") },
1239 { 0, 0, 0, NULL, (void*) &SetRandom, NULL, NULL, Button, N_("randomize") },
1240 { 0, SAME_ROW, 0, NULL, (void*) &SetRandom, NULL, NULL, Button, N_("pick fixed") },
1241 { 0,SAME_ROW, 0, NULL, (void*) &ShuffleOK, "", NULL, EndMark , "" }
1247 int r = n==2 ? -1 : random() & (1<<30)-1;
1249 snprintf(buf, MSG_SIZ, "%d", r);
1250 SetWidgetText(&shuffleOptions[1], buf, TransientDlg);
1251 SetWidgetState(&shuffleOptions[0], True);
1257 GenericPopUp(shuffleOptions, _("New Shuffle Game"), TransientDlg, BoardWindow, MODAL, 0);
1260 //------------------------------------------------------ Time Control -----------------------------------
1262 static int TcOK P((int n));
1263 int tmpMoves, tmpTc, tmpInc, tmpOdds1, tmpOdds2, tcType;
1270 static void SetTcType P((int n));
1275 static char buf[MSG_SIZ];
1276 snprintf(buf, MSG_SIZ, "%d", n);
1280 static Option tcOptions[] = {
1281 { 0, 0, 0, NULL, (void*) &SetTcType, NULL, NULL, Button, N_("classical") },
1282 { 0,SAME_ROW,0,NULL, (void*) &SetTcType, NULL, NULL, Button, N_("incremental") },
1283 { 0,SAME_ROW,0,NULL, (void*) &SetTcType, NULL, NULL, Button, N_("fixed max") },
1284 { 0, 0, 200, NULL, (void*) &tmpMoves, NULL, NULL, Spin, N_("Moves per session:") },
1285 { 0, 0,10000, NULL, (void*) &tmpTc, NULL, NULL, Spin, N_("Initial time (min):") },
1286 { 0, 0, 10000, NULL, (void*) &tmpInc, NULL, NULL, Spin, N_("Increment or max (sec/move):") },
1287 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Time-Odds factors:") },
1288 { 0, 1, 1000, NULL, (void*) &tmpOdds1, NULL, NULL, Spin, N_("Engine #1") },
1289 { 0, 1, 1000, NULL, (void*) &tmpOdds2, NULL, NULL, Spin, N_("Engine #2 / Human") },
1290 { 0, 0, 0, NULL, (void*) &TcOK, "", NULL, EndMark , "" }
1297 if(tcType == 0 && tmpMoves <= 0) return 0;
1298 if(tcType == 2 && tmpInc <= 0) return 0;
1299 GetWidgetText(&tcOptions[4], &tc); // get original text, in case it is min:sec
1303 if(!ParseTimeControl(tc, -1, tmpMoves)) return 0;
1304 appData.movesPerSession = tmpMoves;
1305 ASSIGN(appData.timeControl, tc);
1306 appData.timeIncrement = -1;
1309 if(!ParseTimeControl(tc, tmpInc, 0)) return 0;
1310 ASSIGN(appData.timeControl, tc);
1311 appData.timeIncrement = tmpInc;
1314 searchTime = tmpInc;
1316 appData.firstTimeOdds = first.timeOdds = tmpOdds1;
1317 appData.secondTimeOdds = second.timeOdds = tmpOdds2;
1325 switch(tcType = n) {
1327 SetWidgetText(&tcOptions[3], Value(tmpMoves), TransientDlg);
1328 SetWidgetText(&tcOptions[4], Value(tmpTc), TransientDlg);
1329 SetWidgetText(&tcOptions[5], _("Unused"), TransientDlg);
1332 SetWidgetText(&tcOptions[3], _("Unused"), TransientDlg);
1333 SetWidgetText(&tcOptions[4], Value(tmpTc), TransientDlg);
1334 SetWidgetText(&tcOptions[5], Value(tmpInc), TransientDlg);
1337 SetWidgetText(&tcOptions[3], _("Unused"), TransientDlg);
1338 SetWidgetText(&tcOptions[4], _("Unused"), TransientDlg);
1339 SetWidgetText(&tcOptions[5], Value(tmpInc), TransientDlg);
1346 tmpMoves = appData.movesPerSession;
1347 tmpInc = appData.timeIncrement; if(tmpInc < 0) tmpInc = 0;
1348 tmpOdds1 = tmpOdds2 = 1; tcType = 0;
1349 tmpTc = atoi(appData.timeControl);
1350 GenericPopUp(tcOptions, _("Time Control"), TransientDlg, BoardWindow, MODAL, 0);
1353 //------------------------------- Ask Question -----------------------------------------
1355 int SendReply P((int n));
1356 char pendingReplyPrefix[MSG_SIZ];
1357 ProcRef pendingReplyPR;
1360 Option askOptions[] = {
1361 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, NULL },
1362 { 0, 0, 0, NULL, (void*) &answer, "", NULL, TextBox, "" },
1363 { 0, 0, 0, NULL, (void*) &SendReply, "", NULL, EndMark , "" }
1372 // GetWidgetText(&askOptions[1], &reply);
1373 safeStrCpy(buf, pendingReplyPrefix, sizeof(buf)/sizeof(buf[0]) );
1374 if (*buf) strncat(buf, " ", MSG_SIZ - strlen(buf) - 1);
1375 strncat(buf, reply, MSG_SIZ - strlen(buf) - 1);
1376 strncat(buf, "\n", MSG_SIZ - strlen(buf) - 1);
1377 OutputToProcess(pendingReplyPR, buf, strlen(buf), &err); // does not go into debug file??? => bug
1378 if (err) DisplayFatalError(_("Error writing to chess program"), err, 0);
1383 AskQuestion (char *title, char *question, char *replyPrefix, ProcRef pr)
1385 safeStrCpy(pendingReplyPrefix, replyPrefix, sizeof(pendingReplyPrefix)/sizeof(pendingReplyPrefix[0]) );
1386 pendingReplyPR = pr;
1388 askOptions[0].name = question;
1389 if(GenericPopUp(askOptions, title, AskDlg, BoardWindow, MODAL, 0))
1390 AddHandler(&askOptions[1], 2);
1393 //---------------------------- Promotion Popup --------------------------------------
1397 static void PromoPick P((int n));
1399 static Option promoOptions[] = {
1400 { 0, 0, 0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
1401 { 0, SAME_ROW, 0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
1402 { 0, SAME_ROW, 0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
1403 { 0, SAME_ROW, 0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
1404 { 0, SAME_ROW, 0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
1405 { 0, SAME_ROW, 0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
1406 { 0, SAME_ROW, 0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
1407 { 0, SAME_ROW | NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
1413 int promoChar = promoOptions[n+count].value;
1417 if (promoChar == 0) fromX = -1;
1418 if (fromX == -1) return;
1425 UserMoveEvent(fromX, fromY, toX, toY, promoChar);
1427 if (!appData.highlightLastMove || gotPremove) ClearHighlights();
1428 if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY);
1433 SetPromo (char *name, int nr, char promoChar)
1435 safeStrCpy(promoOptions[nr].name, name, MSG_SIZ);
1436 promoOptions[nr].value = promoChar;
1441 { // choice depends on variant: prepare dialog acordingly
1443 SetPromo(_("Cancel"), --count, 0); // Beware: GenericPopUp cannot handle user buttons named "cancel" (lowe case)!
1444 if(gameInfo.variant != VariantShogi) {
1445 if (!appData.testLegality || gameInfo.variant == VariantSuicide ||
1446 gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove) ||
1447 gameInfo.variant == VariantGiveaway) {
1448 SetPromo(_("King"), --count, 'k');
1450 if(gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove)) {
1451 SetPromo(_("Captain"), --count, 'c');
1452 SetPromo(_("Lieutenant"), --count, 'l');
1453 SetPromo(_("General"), --count, 'g');
1454 SetPromo(_("Warlord"), --count, 'w');
1456 SetPromo(_("Knight"), --count, 'n');
1457 SetPromo(_("Bishop"), --count, 'b');
1458 SetPromo(_("Rook"), --count, 'r');
1459 if(gameInfo.variant == VariantCapablanca ||
1460 gameInfo.variant == VariantGothic ||
1461 gameInfo.variant == VariantCapaRandom) {
1462 SetPromo(_("Archbishop"), --count, 'a');
1463 SetPromo(_("Chancellor"), --count, 'c');
1465 SetPromo(_("Queen"), --count, 'q');
1467 } else // [HGM] shogi
1469 SetPromo(_("Defer"), --count, '=');
1470 SetPromo(_("Promote"), --count, '+');
1472 GenericPopUp(promoOptions + count, "Promotion", PromoDlg, BoardWindow, NONMODAL, 0);
1475 //---------------------------- Chat Windows ----------------------------------------------
1478 OutputChatMessage (int partner, char *mess)
1483 //--------------------------------- Game-List options dialog ------------------------------------------
1485 char *strings[LPUSERGLT_SIZE];
1496 GLT_AddToList (char *name)
1498 strings[stringPtr++] = name;
1499 strings[stringPtr] = NULL;
1503 GLT_GetFromList (int index, char *name)
1505 safeStrCpy(name, strings[index], MSG_SIZ);
1514 static void GLT_Button P((int n));
1515 static int GLT_OK P((int n));
1517 static Option listOptions[] = {
1518 { 0, LR|TB, 200, NULL, (void*) strings, "", NULL, ListBox, "" },
1519 { 0, 0, 0, NULL, (void*) &GLT_Button, NULL, NULL, Button, N_("factory") },
1520 { 0, SAME_ROW, 0, NULL, (void*) &GLT_Button, NULL, NULL, Button, N_("up") },
1521 { 0, SAME_ROW, 0, NULL, (void*) &GLT_Button, NULL, NULL, Button, N_("down") },
1522 { 0, SAME_ROW, 0, NULL, (void*) &GLT_OK, "", NULL, EndMark , "" }
1529 appData.gameListTags = strdup(lpUserGLT);
1536 int index = SelectedListBoxItem (&listOptions[0]);
1539 DisplayError(_("No tag selected"), 0);
1544 if(index >= strlen(GLT_ALL_TAGS)) return;
1545 strings[index] = strings[index+1];
1546 strings[++index] = p;
1549 if(index == 0) return;
1550 strings[index] = strings[index-1];
1551 strings[--index] = p;
1554 safeStrCpy(lpUserGLT, GLT_DEFAULT_TAGS, LPUSERGLT_SIZE);
1555 GLT_TagsToList(lpUserGLT);
1557 LoadListBox(&listOptions[0], "?"); // Note: the others don't need this, as the highlight switching redraws the change items
1559 HighlightListBoxItem(&listOptions[0], index);
1563 GameListOptionsPopUp (DialogClass parent)
1565 safeStrCpy(lpUserGLT, appData.gameListTags, LPUSERGLT_SIZE);
1566 GLT_TagsToList(lpUserGLT);
1568 GenericPopUp(listOptions, _("Game-list options"), TransientDlg, parent, MODAL, 0);
1572 GameListOptionsProc ()
1574 GameListOptionsPopUp(BoardWindow);
1577 //----------------------------- Error popup in various uses -----------------------------
1581 * XBoard has always had some pathologic behavior with multiple simultaneous error popups,
1582 * (which can occur even for modal popups when asynchrounous events, e.g. caused by engine, request a popup),
1583 * and this new implementation reproduces that as well:
1584 * Only the shell of the last instance is remembered in shells[ErrorDlg] (which replaces errorShell),
1585 * so that PopDowns ordered from the code always refer to that instance, and once that is down,
1586 * have no clue as to how to reach the others. For the Delete Window button calling PopDown this
1587 * has now been repaired, as the action routine assigned to it gets the shell passed as argument.
1590 int errorUp = False;
1595 if (!errorUp) return;
1596 dialogError = errorUp = False;
1597 PopDown(ErrorDlg); PopDown(FatalDlg); // on explicit request we pop down any error dialog
1598 if (errorExitStatus != -1) ExitEvent(errorExitStatus);
1604 dialogError = errorUp = False;
1605 PopDown(n == 1 ? FatalDlg : ErrorDlg); // kludge: non-modal dialogs have one less (dummy) option
1606 if (errorExitStatus != -1) ExitEvent(errorExitStatus);
1607 return FALSE; // prevent second Popdown !
1610 static Option errorOptions[] = {
1611 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, NULL }, // dummy option: will never be displayed
1612 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, NULL }, // textValue field will be set before popup
1613 { 0,NO_CANCEL,0, NULL, (void*) &ErrorOK, "", NULL, EndMark , "" }
1617 ErrorPopUp (char *title, char *label, int modal)
1620 errorOptions[1].name = label;
1621 if(dialogError = shellUp[TransientDlg])
1622 GenericPopUp(errorOptions+1, title, FatalDlg, TransientDlg, MODAL, 0); // pop up as daughter of the transient dialog
1624 GenericPopUp(errorOptions+modal, title, modal ? FatalDlg: ErrorDlg, BoardWindow, modal, 0); // kludge: option start address indicates modality
1628 DisplayError (String message, int error)
1633 if (appData.debugMode || appData.matchMode) {
1634 fprintf(stderr, "%s: %s\n", programName, message);
1637 if (appData.debugMode || appData.matchMode) {
1638 fprintf(stderr, "%s: %s: %s\n",
1639 programName, message, strerror(error));
1641 snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error));
1644 ErrorPopUp(_("Error"), message, FALSE);
1649 DisplayMoveError (String message)
1653 DrawPosition(FALSE, NULL);
1654 if (appData.debugMode || appData.matchMode) {
1655 fprintf(stderr, "%s: %s\n", programName, message);
1657 if (appData.popupMoveErrors) {
1658 ErrorPopUp(_("Error"), message, FALSE);
1660 DisplayMessage(message, "");
1666 DisplayFatalError (String message, int error, int status)
1670 errorExitStatus = status;
1672 fprintf(stderr, "%s: %s\n", programName, message);
1674 fprintf(stderr, "%s: %s: %s\n",
1675 programName, message, strerror(error));
1676 snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error));
1679 if (appData.popupExitMessage && boardWidget && XtIsRealized(boardWidget)) {
1680 ErrorPopUp(status ? _("Fatal Error") : _("Exiting"), message, TRUE);
1687 DisplayInformation (String message)
1690 ErrorPopUp(_("Information"), message, TRUE);
1694 DisplayNote (String message)
1697 ErrorPopUp(_("Note"), message, FALSE);
1701 DisplayTitle (char *text)
1703 char title[MSG_SIZ];
1706 if (text == NULL) text = "";
1708 if (*text != NULLCHAR) {
1709 safeStrCpy(icon, text, sizeof(icon)/sizeof(icon[0]) );
1710 safeStrCpy(title, text, sizeof(title)/sizeof(title[0]) );
1711 } else if (appData.icsActive) {
1712 snprintf(icon, sizeof(icon), "%s", appData.icsHost);
1713 snprintf(title, sizeof(title), "%s: %s", programName, appData.icsHost);
1714 } else if (appData.cmailGameName[0] != NULLCHAR) {
1715 snprintf(icon, sizeof(icon), "%s", "CMail");
1716 snprintf(title,sizeof(title), "%s: %s", programName, "CMail");
1718 // [HGM] license: This stuff should really be done in back-end, but WinBoard already had a pop-up for it
1719 } else if (gameInfo.variant == VariantGothic) {
1720 safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) );
1721 safeStrCpy(title, GOTHIC, sizeof(title)/sizeof(title[0]) );
1724 } else if (gameInfo.variant == VariantFalcon) {
1725 safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) );
1726 safeStrCpy(title, FALCON, sizeof(title)/sizeof(title[0]) );
1728 } else if (appData.noChessProgram) {
1729 safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) );
1730 safeStrCpy(title, programName, sizeof(title)/sizeof(title[0]) );
1732 safeStrCpy(icon, first.tidy, sizeof(icon)/sizeof(icon[0]) );
1733 snprintf(title,sizeof(title), "%s: %s", programName, first.tidy);
1735 SetWindowTitle(text, title, icon);
1739 DisplayWhiteClock (long timeRemaining, int highlight)
1741 if(appData.noGUI) return;
1742 DisplayTimerLabel(11, _("White"), timeRemaining, highlight);
1743 if(highlight) SetClockIcon(0);
1747 DisplayBlackClock (long timeRemaining, int highlight)
1749 if(appData.noGUI) return;
1750 DisplayTimerLabel(12, _("Black"), timeRemaining, highlight);
1751 if(highlight) SetClockIcon(1);
1754 #define PAUSE_BUTTON "P"
1755 #define PIECE_MENU_SIZE 18
1756 static String pieceMenuStrings[2][PIECE_MENU_SIZE+1] = {
1757 { N_("White"), "----", N_("Pawn"), N_("Knight"), N_("Bishop"), N_("Rook"),
1758 N_("Queen"), N_("King"), "----", N_("Elephant"), N_("Cannon"),
1759 N_("Archbishop"), N_("Chancellor"), "----", N_("Promote"), N_("Demote"),
1760 N_("Empty square"), N_("Clear board"), NULL },
1761 { N_("Black"), "----", N_("Pawn"), N_("Knight"), N_("Bishop"), N_("Rook"),
1762 N_("Queen"), N_("King"), "----", N_("Elephant"), N_("Cannon"),
1763 N_("Archbishop"), N_("Chancellor"), "----", N_("Promote"), N_("Demote"),
1764 N_("Empty square"), N_("Clear board"), NULL }
1766 /* must be in same order as pieceMenuStrings! */
1767 static ChessSquare pieceMenuTranslation[2][PIECE_MENU_SIZE] = {
1768 { WhitePlay, (ChessSquare) 0, WhitePawn, WhiteKnight, WhiteBishop,
1769 WhiteRook, WhiteQueen, WhiteKing, (ChessSquare) 0, WhiteAlfil,
1770 WhiteCannon, WhiteAngel, WhiteMarshall, (ChessSquare) 0,
1771 PromotePiece, DemotePiece, EmptySquare, ClearBoard },
1772 { BlackPlay, (ChessSquare) 0, BlackPawn, BlackKnight, BlackBishop,
1773 BlackRook, BlackQueen, BlackKing, (ChessSquare) 0, BlackAlfil,
1774 BlackCannon, BlackAngel, BlackMarshall, (ChessSquare) 0,
1775 PromotePiece, DemotePiece, EmptySquare, ClearBoard },
1778 #define DROP_MENU_SIZE 6
1779 static String dropMenuStrings[DROP_MENU_SIZE+1] = {
1780 "----", N_("Pawn"), N_("Knight"), N_("Bishop"), N_("Rook"), N_("Queen"), NULL
1782 /* must be in same order as dropMenuStrings! */
1783 static ChessSquare dropMenuTranslation[DROP_MENU_SIZE] = {
1784 (ChessSquare) 0, WhitePawn, WhiteKnight, WhiteBishop,
1785 WhiteRook, WhiteQueen
1788 // [HGM] experimental code to pop up window just like the main window, using GenercicPopUp
1790 static Option *Exp P((int n, int x, int y));
1791 void MenuCallback P((int n));
1792 void SizeKludge P((int n));
1794 static int pmFromX = -1, pmFromY = -1;
1798 { // user callback for board context menus
1799 if (pmFromX < 0 || pmFromY < 0) return;
1800 if(n == 25) DropMenuEvent(dropMenuTranslation[values[n]], pmFromX, pmFromY);
1801 else EditPositionMenuEvent(pieceMenuTranslation[n-23][values[n]], pmFromX, pmFromY);
1807 shiftKey = (ShiftKeys() & 3) != 0;
1808 ClockClick(n == 12);
1811 Option mainOptions[] = { // description of main window in terms of generic dialog creator
1812 { 0, 0xCA, 0, NULL, NULL, "", NULL, BoxBegin, "" }, // menu bar
1813 { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("File") },
1814 { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("Edit") },
1815 { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("View") },
1816 { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("Mode") },
1817 { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("Action") },
1818 { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("Engine") },
1819 { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("Options") },
1820 { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("Help") },
1821 { 0, 0, 0, NULL, (void*)&SizeKludge, "", NULL, BoxEnd, "" },
1822 { 0, LR|T2T|BORDER|SAME_ROW, 0, NULL, NULL, "", NULL, Label, "1" }, // optional title in window
1823 { 0, L2L|T2T, 200, NULL, (void*) &CCB, NULL, NULL, Label, "White" }, // white clock
1824 { 0, R2R|T2T|SAME_ROW, 200, NULL, (void*) &CCB, NULL, NULL, Label, "Black" }, // black clock
1825 { 0, LR|T2T|BORDER, 401, NULL, NULL, "", NULL, -1, "2" }, // backup for title in window (if no room for other)
1826 { 0, LR|T2T|BORDER, 270, NULL, NULL, "", NULL, Label, "message" }, // message field
1827 { 0, RR|TT|SAME_ROW, 125, NULL, NULL, "", NULL, BoxBegin, "" }, // (optional) button bar
1828 { 0, 0, 0, NULL, (void*) &ToStartEvent, NULL, NULL, Button, N_("<<") },
1829 { 0, SAME_ROW, 0, NULL, (void*) &BackwardEvent, NULL, NULL, Button, N_("<") },
1830 { 0, SAME_ROW, 0, NULL, (void*) &PauseEvent, NULL, NULL, Button, N_(PAUSE_BUTTON) },
1831 { 0, SAME_ROW, 0, NULL, (void*) &ForwardEvent, NULL, NULL, Button, N_(">") },
1832 { 0, SAME_ROW, 0, NULL, (void*) &ToEndEvent, NULL, NULL, Button, N_(">>") },
1833 { 0, 0, 0, NULL, NULL, "", NULL, BoxEnd, "" },
1834 { 401, LR|TT, 401, NULL, (char*) &Exp, NULL, NULL, Graph, "shadow board" }, // board
1835 { 2, COMBO_CALLBACK, 0, NULL, (void*) &PMSelect, NULL, pieceMenuStrings[0], PopUp, "menuW" },
1836 { 2, COMBO_CALLBACK, 0, NULL, (void*) &PMSelect, NULL, pieceMenuStrings[1], PopUp, "menuB" },
1837 { -1, COMBO_CALLBACK, 0, NULL, (void*) &PMSelect, NULL, dropMenuStrings, PopUp, "menuD" },
1838 { 0, NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
1843 { // callback called by GenericPopUp immediately after sizing the menu bar
1844 int width = BOARD_WIDTH*(squareSize + lineGap) + lineGap;
1845 int w = width - 44 - mainOptions[n].min;
1846 mainOptions[10].max = w; // width left behind menu bar
1847 if(w < 0.4*width) // if no reasonable amount of space for title, force small layout
1848 mainOptions[13].type = mainOptions[10].type, mainOptions[10].type = -1;
1852 MenuCallback (int n)
1854 MenuProc *proc = (MenuProc *) (((MenuItem*)(mainOptions[n].choice))[values[n]].proc);
1860 Exp (int n, int x, int y)
1862 static int but1, but3;
1865 if(n == 0) { // motion
1866 if(SeekGraphClick(Press, x, y, 1)) return NULL;
1867 if(but1 && !PromoScroll(x, y)) DragPieceMove(x, y);
1868 if(but3) MovePV(x, y, lineGap + BOARD_HEIGHT * (squareSize + lineGap));
1871 shiftKey = (ShiftKeys() & 3) != 0;
1873 case 1: LeftClick(Press, x, y), but1 = 1; break;
1874 case -1: LeftClick(Release, x, y), but1 = 0; break;
1875 case 2: shiftKey = !shiftKey;
1876 case 3: menuNr = RightClick(Press, x, y, &pmFromX, &pmFromY), but3 = 1; break;
1877 case -2: shiftKey = !shiftKey;
1878 case -3: menuNr = RightClick(Release, x, y, &pmFromX, &pmFromY), but3 = 0; break;
1880 DrawPosition(True, NULL);
1881 if(twoBoards) { // [HGM] dual: draw other board in other orientation
1882 flipView = !flipView; partnerUp = !partnerUp;
1883 DrawPosition(True, NULL);
1884 flipView = !flipView; partnerUp = !partnerUp;
1891 case 0: return &mainOptions[shiftKey ? 23: 24];
1892 case 1: SetupDropMenu(); return &mainOptions[25];
1894 case -1: ErrorPopDown();
1896 default: break; // -3, so no clicks caught
1902 BoardPopUp (int squareSize, int lineGap, void *clockFontThingy)
1904 extern Option *dialogOptions[];
1905 int i, size = BOARD_WIDTH*(squareSize + lineGap) + lineGap;
1906 mainOptions[11].choice = (char**) clockFontThingy;
1907 mainOptions[12].choice = (char**) clockFontThingy;
1908 mainOptions[22].value = BOARD_HEIGHT*(squareSize + lineGap) + lineGap;
1909 mainOptions[22].max = mainOptions[13].max = size; // board size
1910 mainOptions[13].max = size - 2; // board title (subtract border!)
1911 mainOptions[12].max = mainOptions[11].max = size/2-3; // clock width
1912 mainOptions[14].max = appData.showButtonBar ? size-130 : size-2; // message
1913 mainOptions[0].max = size-40; // menu bar
1914 mainOptions[10].type = appData.titleInWindow ? Label : -1 ;
1915 if(!appData.showButtonBar) for(i=15; i<22; i++) mainOptions[i].type = -1;
1916 for(i=0; i<8; i++) mainOptions[i+1].choice = (char**) menuBar[i].mi;
1917 GenericPopUp(mainOptions, "XBoard", BoardWindow, BoardWindow, NONMODAL, 1);