2 * menus.c -- platform-indendent menu handling code for XBoard
4 * Copyright 1991 by Digital Equipment Corporation, Maynard,
7 * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
8 * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free
9 * Software Foundation, Inc.
11 * The following terms apply to Digital Equipment Corporation's copyright
13 * ------------------------------------------------------------------------
16 * Permission to use, copy, modify, and distribute this software and its
17 * documentation for any purpose and without fee is hereby granted,
18 * provided that the above copyright notice appear in all copies and that
19 * both that copyright notice and this permission notice appear in
20 * supporting documentation, and that the name of Digital not be
21 * used in advertising or publicity pertaining to distribution of the
22 * software without specific, written prior permission.
24 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
25 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
26 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
27 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
28 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
29 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
31 * ------------------------------------------------------------------------
33 * The following terms apply to the enhanced version of XBoard
34 * distributed by the Free Software Foundation:
35 * ------------------------------------------------------------------------
37 * GNU XBoard is free software: you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation, either version 3 of the License, or (at
40 * your option) any later version.
42 * GNU XBoard is distributed in the hope that it will be useful, but
43 * WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
45 * General Public License for more details.
47 * You should have received a copy of the GNU General Public License
48 * along with this program. If not, see http://www.gnu.org/licenses/. *
50 *------------------------------------------------------------------------
51 ** See the file ChangeLog for a revision history. */
61 #include <sys/types.h>
69 #else /* not STDC_HEADERS */
70 extern char *getenv();
73 # else /* not HAVE_STRING_H */
75 # endif /* not HAVE_STRING_H */
76 #endif /* not STDC_HEADERS */
86 // [HGM] bitmaps: put before incuding the bitmaps / pixmaps, to know how many piece types there are.
95 # define _(s) gettext (s)
96 # define N_(s) gettext_noop (s)
103 * Button/menu procedures
106 char *gameCopyFilename, *gamePasteFilename;
107 Boolean saveSettingsOnExit;
108 char *settingsFileName;
109 char gamesDir[MSG_SIZ], positionsDir[MSG_SIZ], textureDir[MSG_SIZ], bookDir[MSG_SIZ], piecesDir[MSG_SIZ];
112 LoadGamePopUp (FILE *f, int gameNumber, char *title)
114 cmailMsgLoaded = FALSE;
115 if (gameNumber == 0) {
116 int error = GameListBuild(f);
118 DisplayError(_("Cannot build game list"), error);
119 } else if (!ListEmpty(&gameList) &&
120 ((ListGame *) gameList.tailPred)->number > 1) {
121 GameListPopUp(f, title);
127 return LoadGame(f, gameNumber, title, FALSE);
133 if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
136 FileNamePopUp(_("Load game file name?"), "", ".pgn .game", LoadGamePopUp, "rb");
158 LoadNextPositionProc ()
164 LoadPrevPositionProc ()
170 ReloadPositionProc ()
178 static char buf[MSG_SIZ];
179 if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
182 snprintf(buf, MSG_SIZ, "%s/", appData.positionDir);
183 FileNamePopUp(_("Load position file name?"), buf, ".fen .epd .pos", LoadPosition, "rb");
189 FileNamePopUp(_("Save game file name?"),
190 DefaultFileName(appData.oldSaveStyle ? "game" : "pgn"),
191 appData.oldSaveStyle ? ".game" : ".pgn",
198 FileNamePopUp(_("Save position file name?"),
199 DefaultFileName(appData.oldSaveStyle ? "pos" : "fen"),
200 appData.oldSaveStyle ? ".pos" : ".fen",
205 ReloadCmailMsgProc ()
207 ReloadCmailMsgEvent(FALSE);
211 CopyFENToClipboard ()
212 { // wrapper to make call from back-end possible
219 static char *selected_fen_position=NULL;
220 if(gameMode == EditPosition) EditPositionDone(TRUE);
221 if (selected_fen_position) free(selected_fen_position);
222 selected_fen_position = (char *)PositionToFEN(currentMove, NULL, 1);
223 if (!selected_fen_position) return;
224 CopySomething(selected_fen_position);
232 ret = SaveGameToFile(gameCopyFilename, FALSE);
241 if(!SaveGameListAsText(fopen(gameCopyFilename, "w"))) return;
261 static Enables matchOff[] = { { "Mode.MachineMatch", False }, { NULL, False } };
262 if(matchMode) SetMenuEnables(matchOff);
269 UserAdjudicationEvent(+1);
275 UserAdjudicationEvent(-1);
281 UserAdjudicationEvent(0);
299 if(twoBoards) { partnerUp = 1; DrawPosition(True, NULL); partnerUp = 0; }
300 flipView = !flipView;
301 DrawPosition(True, NULL);
307 saveSettingsOnExit = !saveSettingsOnExit;
309 MarkMenuItem("Options.SaveSettingsonExit", saveSettingsOnExit);
315 SaveSettings(settingsFileName);
322 snprintf(buf, MSG_SIZ, "%s mailto:bug-xboard@gnu.org", appData.sysOpen);
330 snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/user_guide/UserGuide.html", appData.sysOpen);
338 snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/", appData.sysOpen);
346 snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/whats_new/portal.html", appData.sysOpen);
353 char buf[2 * MSG_SIZ];
355 char *zippy = _(" (with Zippy code)");
359 snprintf(buf, sizeof(buf),
361 "Copyright 1991 Digital Equipment Corporation\n"
362 "Enhancements Copyright 1992-2016 Free Software Foundation\n"
363 "Enhancements Copyright 2005 Alessandro Scotti\n\n"
364 "%s is free software and carries NO WARRANTY;"
365 "see the file COPYING for more information.\n\n"
366 "Visit XBoard on the web at: http://www.gnu.org/software/xboard/\n"
367 "Check out the newest features at: http://www.gnu.org/software/xboard/whats_new.html\n\n"
368 "Report bugs via email at: <bug-xboard@gnu.org>\n\n"
370 programVersion, zippy, PACKAGE);
371 ErrorPopUp(_("About XBoard"), buf, FALSE);
377 appData.debugMode = !appData.debugMode;
378 if(!strcmp(appData.nameOfDebugFile, "stderr")) return; // stderr is already open, and should never be closed
379 if(!appData.debugMode) fclose(debugFP);
381 debugFP = fopen(appData.nameOfDebugFile, "w");
382 if(debugFP == NULL) debugFP = stderr;
383 else setbuf(debugFP, NULL);
390 EditAnyPopUp(firstChessProgramNames, &firstChessProgramNames, _("Registered Engines"));
396 EditAnyPopUp(appData.themeNames, &appData.themeNames, _("Predefined Themes"));
402 EditAnyPopUp(icsTextMenuString, &icsTextMenuString, _("ICS Text-Menu Definition"));
412 # define MARK_MENU_ITEM(X,Y)
414 # define MARK_MENU_ITEM(X,Y) MarkMenuItem(X, Y)
418 PonderNextMoveProc ()
420 PonderNextMoveEvent(!appData.ponderNextMove);
421 MARK_MENU_ITEM("Options.PonderNextMove", appData.ponderNextMove);
427 appData.alwaysPromoteToQueen = !appData.alwaysPromoteToQueen;
428 MARK_MENU_ITEM("Options.AlwaysQueen", appData.alwaysPromoteToQueen);
432 AnimateDraggingProc ()
434 appData.animateDragging = !appData.animateDragging;
436 if (appData.animateDragging) CreateAnimVars();
437 MARK_MENU_ITEM("Options.AnimateDragging", appData.animateDragging);
443 appData.animate = !appData.animate;
444 if (appData.animate) CreateAnimVars();
445 MARK_MENU_ITEM("Options.AnimateMoving", appData.animate);
451 appData.autoCallFlag = !appData.autoCallFlag;
452 MARK_MENU_ITEM("Options.AutoFlag", appData.autoCallFlag);
458 appData.autoFlipView = !appData.autoFlipView;
459 MARK_MENU_ITEM("Options.AutoFlipView", appData.autoFlipView);
465 appData.blindfold = !appData.blindfold;
466 MARK_MENU_ITEM("Options.Blindfold", appData.blindfold);
467 DrawPosition(True, NULL);
473 appData.testLegality = !appData.testLegality;
474 MARK_MENU_ITEM("Options.TestLegality", appData.testLegality);
481 if (appData.flashCount == 0) {
482 appData.flashCount = 3;
484 appData.flashCount = -appData.flashCount;
486 MARK_MENU_ITEM("Options.FlashMoves", appData.flashCount > 0);
491 HighlightDraggingProc ()
493 appData.highlightDragging = !appData.highlightDragging;
494 MARK_MENU_ITEM("Options.HighlightDragging", appData.highlightDragging);
499 HighlightLastMoveProc ()
501 appData.highlightLastMove = !appData.highlightLastMove;
502 MARK_MENU_ITEM("Options.HighlightLastMove", appData.highlightLastMove);
506 HighlightArrowProc ()
508 appData.highlightMoveWithArrow = !appData.highlightMoveWithArrow;
509 MARK_MENU_ITEM("Options.HighlightWithArrow", appData.highlightMoveWithArrow);
515 appData.icsAlarm = !appData.icsAlarm;
516 // MARK_MENU_ITEM("Options.ICSAlarm", appData.icsAlarm);
522 appData.ringBellAfterMoves = !appData.ringBellAfterMoves;
523 MARK_MENU_ITEM("Options.MoveSound", appData.ringBellAfterMoves);
529 appData.oneClick = !appData.oneClick;
530 MARK_MENU_ITEM("Options.OneClickMoving", appData.oneClick);
534 PeriodicUpdatesProc ()
536 PeriodicUpdatesEvent(!appData.periodicUpdates);
537 MARK_MENU_ITEM("Options.PeriodicUpdates", appData.periodicUpdates);
541 PopupExitMessageProc ()
543 appData.popupExitMessage = !appData.popupExitMessage;
544 MARK_MENU_ITEM("Options.PopupExitMessage", appData.popupExitMessage);
548 PopupMoveErrorsProc ()
550 appData.popupMoveErrors = !appData.popupMoveErrors;
551 MARK_MENU_ITEM("Options.PopupMoveErrors", appData.popupMoveErrors);
557 appData.premove = !appData.premove;
558 // MARK_MENU_ITEM("Options.Premove", appData.premove);
564 appData.showCoords = !appData.showCoords;
565 MARK_MENU_ITEM("Options.ShowCoords", appData.showCoords);
566 DrawPosition(True, NULL);
572 appData.showThinking = !appData.showThinking; // [HGM] thinking: taken out of ShowThinkingEvent
579 appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman; // [HGM] thinking: taken out of ShowThinkingEvent
582 MARK_MENU_ITEM("Options.HideThinking", appData.hideThinkingFromHuman);
588 ScheduleDelayedEvent(CreateBookEvent, 50);
594 FileNamePopUp(_("Save game file name?"),
601 * Menu definition tables
604 MenuItem fileMenu[] = {
605 {N_("New Game"), "<Ctrl>n", "NewGame", ResetGameEvent},
606 {N_("New Shuffle Game..."), NULL, "NewShuffleGame", ShuffleMenuProc},
607 {N_("New Variant..."), "<Alt><Shift>v", "NewVariant", NewVariantProc},// [HGM] variant: not functional yet
608 {"----", NULL, NULL, NothingProc},
609 {N_("Load Game"), "<Ctrl>o", "LoadGame", LoadGameProc, CHECK},
610 {N_("Load Position"), "<Ctrl><Shift>o", "LoadPosition", LoadPositionProc},
611 {N_("Next Position"), "<Shift>Page_Down", "LoadNextPosition", LoadNextPositionProc},
612 {N_("Prev Position"), "<Shift>Page_Up", "LoadPreviousPosition", LoadPrevPositionProc},
613 {"----", NULL, NULL, NothingProc},
614 {N_("Save Game"), "<Ctrl>s", "SaveGame", SaveGameProc},
615 {N_("Save Position"), "<Ctrl><Shift>s", "SavePosition", SavePositionProc},
616 {N_("Save Selected Games"), NULL, "SaveSelected", SaveSelectedProc},
617 {N_("Save Games as Book"), NULL, "CreateBook", CreateBookDelayed},
618 {"----", NULL, NULL, NothingProc},
619 {N_("Mail Move"), NULL, "MailMove", MailMoveEvent},
620 {N_("Reload CMail Message"), NULL, "ReloadCMailMessage", ReloadCmailMsgProc},
621 {"----", NULL, NULL, NothingProc},
622 {N_("Quit "), "<Ctrl>q", "Quit", QuitProc},
623 {NULL, NULL, NULL, NULL}
626 MenuItem editMenu[] = {
627 {N_("Copy Game"), "<Ctrl>c", "CopyGame", CopyGameProc},
628 {N_("Copy Position"), "<Ctrl><Shift>c", "CopyPosition", CopyPositionProc},
629 {N_("Copy Game List"), NULL, "CopyGameList", CopyGameListProc},
630 {"----", NULL, NULL, NothingProc},
631 {N_("Paste Game"), "<Ctrl>v", "PasteGame", PasteGameProc},
632 {N_("Paste Position"), "<Ctrl><Shift>v", "PastePosition", PastePositionProc},
633 {"----", NULL, NULL, NothingProc},
634 {N_("Edit Game"), "<Ctrl>e", "EditGame", EditGameEvent},
635 {N_("Edit Position"), "<Ctrl><Shift>e", "EditPosition", EditPositionEvent},
636 {N_("Edit Tags"), NULL, "EditTags", EditTagsProc},
637 {N_("Edit Comment"), NULL, "EditComment", EditCommentProc},
638 {N_("Edit Book"), NULL, "EditBook", EditBookEvent},
639 {"----", NULL, NULL, NothingProc},
640 {N_("Revert"), "Home", "Revert", RevertProc},
641 {N_("Annotate"), NULL, "Annotate", AnnotateProc},
642 {N_("Truncate Game"), "End", "TruncateGame", TruncateGameEvent},
643 {"----", NULL, NULL, NothingProc},
644 {N_("Backward"), "<Alt>Left", "Backward", BackwardEvent},
645 {N_("Forward"), "<Alt>Right", "Forward", ForwardEvent},
646 {N_("Back to Start"), "<Alt>Home", "BacktoStart", ToStartEvent},
647 {N_("Forward to End"), "<Alt>End", "ForwardtoEnd", ToEndEvent},
648 {NULL, NULL, NULL, NULL}
651 MenuItem viewMenu[] = {
652 {N_("Flip View"), "F2", "FlipView", FlipViewProc, CHECK},
653 {"----", NULL, NULL, NothingProc},
654 {N_("Engine Output"), "<Alt><Shift>o", "EngineOutput", EngineOutputProc, CHECK},
655 {N_("Move History"), "<Alt><Shift>h", "MoveHistory", HistoryShowProc, CHECK}, // [HGM] hist: activate 4.2.7 code
656 {N_("Evaluation Graph"), "<Alt><Shift>e", "EvaluationGraph", EvalGraphProc, CHECK},
657 {N_("Game List"), "<Alt><Shift>g", "GameList", ShowGameListProc, CHECK},
658 {"----", NULL, NULL, NothingProc},
659 {N_("Tags"), NULL, "Tags", EditTagsProc, CHECK},
660 {N_("Comments"), NULL, "Comments", EditCommentProc, CHECK},
661 {N_("ICS Input Box"), NULL, "ICSInputBox", IcsInputBoxProc, CHECK},
662 {N_("ICS/Chat Console"), NULL, "OpenChatWindow", ChatProc, CHECK},
663 {N_("ICS text menu"), NULL, "ICStextmenu", IcsTextProc, CHECK},
664 {N_("Edit ICS menu..."), NULL, "EditTextMenu", EditMenuProc},
665 {"----", NULL, NULL, NothingProc},
666 {N_("Edit Theme List..."), NULL, "EditThemeList", EditThemesProc},
667 {N_("Board..."), NULL, "Board", BoardOptionsProc},
668 {N_("Fonts..."), NULL, "Fonts", FontsProc},
669 {N_("Game List Tags..."), NULL, "GameListTags", GameListOptionsProc},
670 {NULL, NULL, NULL, NULL}
673 MenuItem modeMenu[] = {
674 {N_("Machine White"), "<Ctrl>w", "MachineWhite", MachineWhiteEvent, RADIO },
675 {N_("Machine Black"), "<Ctrl>b", "MachineBlack", MachineBlackEvent, RADIO },
676 {N_("Two Machines"), "<Ctrl>t", "TwoMachines", TwoMachinesEvent, RADIO },
677 {N_("Analysis Mode"), "<Ctrl>a", "AnalysisMode", (MenuProc*) AnalyzeModeEvent, RADIO },
678 {N_("Analyze Game"), "<Ctrl>g", "AnalyzeFile", AnalyzeFileEvent, RADIO },
679 {N_("Edit Game"), "<Ctrl>e", "EditGame", EditGameEvent, RADIO },
680 {N_("Edit Position"), "<Ctrl><Shift>e", "EditPosition", EditPositionEvent, RADIO },
681 {N_("Training"), NULL, "Training", TrainingEvent, RADIO },
682 {N_("ICS Client"), NULL, "ICSClient", IcsClientEvent, RADIO },
683 {"----", NULL, NULL, NothingProc},
684 {N_("Machine Match"), NULL, "MachineMatch", MatchProc, CHECK },
685 {N_("Pause"), "Pause", "Pause", PauseEvent, CHECK },
686 {NULL, NULL, NULL, NULL}
689 MenuItem actionMenu[] = {
690 {N_("Accept"), "F3", "Accept", AcceptEvent},
691 {N_("Decline"), "F4", "Decline", DeclineEvent},
692 {N_("Rematch"), "F12", "Rematch", RematchEvent},
693 {"----", NULL, NULL, NothingProc},
694 {N_("Call Flag"), "F5", "CallFlag", CallFlagEvent},
695 {N_("Draw"), "F6", "Draw", DrawEvent},
696 {N_("Adjourn"), "F7", "Adjourn", AdjournEvent},
697 {N_("Abort"), "F8", "Abort", AbortEvent},
698 {N_("Resign"), "F9", "Resign", ResignEvent},
699 {"----", NULL, NULL, NothingProc},
700 {N_("Stop Observing"), "F10", "StopObserving", StopObservingEvent},
701 {N_("Stop Examining"), "F11", "StopExamining", StopExaminingEvent},
702 {N_("Upload to Examine"), NULL, "UploadtoExamine", UploadGameEvent},
703 {"----", NULL, NULL, NothingProc},
704 {N_("Adjudicate to White"), NULL, "AdjudicatetoWhite", AdjuWhiteProc},
705 {N_("Adjudicate to Black"), NULL, "AdjudicatetoBlack", AdjuBlackProc},
706 {N_("Adjudicate Draw"), NULL, "AdjudicateDraw", AdjuDrawProc},
707 {NULL, NULL, NULL, NULL}
710 MenuItem engineMenu[100] = {
711 {N_("Edit Engine List..."), NULL, "EditEngList", EditEngineProc},
712 {"----", NULL, NULL, NothingProc},
713 {N_("Load New 1st Engine..."), NULL, "LoadNew1stEngine", LoadEngine1Proc},
714 {N_("Load New 2nd Engine..."), NULL, "LoadNew2ndEngine", LoadEngine2Proc},
715 {"----", NULL, NULL, NothingProc},
716 {N_("Engine #1 Settings..."), NULL, "Engine#1Settings", FirstSettingsProc},
717 {N_("Engine #2 Settings..."), NULL, "Engine#2Settings", SecondSettingsProc},
718 {N_("Common Settings..."), "<Alt><Shift>u","CommonEngine", UciMenuProc},
719 {"----", NULL, NULL, NothingProc},
720 {N_("Hint"), NULL, "Hint", HintEvent},
721 {N_("Book"), NULL, "Book", BookEvent},
722 {"----", NULL, NULL, NothingProc},
723 {N_("Move Now"), "<Ctrl>m", "MoveNow", MoveNowEvent},
724 {N_("Retract Move"), "<Ctrl>x", "RetractMove", RetractMoveEvent},
725 {NULL, NULL, NULL, NULL}
728 MenuItem optionsMenu[] = {
730 {N_("General..."), NULL, "General", OptionsProc},
732 {N_("Time Control..."), "<Alt><Shift>t", "TimeControl", TimeControlProc},
733 {N_("Adjudications..."), "<Alt><Shift>j", "Adjudications", EngineMenuProc},
734 {N_("ICS..."), NULL, "ICS", IcsOptionsProc},
735 {N_("Tournament..."), NULL, "Match", MatchOptionsProc},
736 {N_("Load Game..."), NULL, "LoadGame", LoadOptionsProc},
737 {N_("Save Game..."), NULL, "SaveGame", SaveOptionsProc},
738 {N_("Game List..."), NULL, "GameList", GameListOptionsProc},
739 {N_("Sounds..."), NULL, "Sounds", SoundOptionsProc},
740 {"----", NULL, NULL, NothingProc},
741 #ifndef OPTIONSDIALOG
742 {N_("Always Queen"), "<Ctrl><Shift>q", "AlwaysQueen", AlwaysQueenProc},
743 {N_("Animate Dragging"), NULL, "AnimateDragging", AnimateDraggingProc},
744 {N_("Animate Moving"), "<Ctrl><Shift>a", "AnimateMoving", AnimateMovingProc},
745 {N_("Auto Flag"), "<Ctrl><Shift>f", "AutoFlag", AutoflagProc},
746 {N_("Auto Flip View"), NULL, "AutoFlipView", AutoflipProc},
747 {N_("Blindfold"), NULL, "Blindfold", BlindfoldProc},
748 {N_("Flash Moves"), NULL, "FlashMoves", FlashMovesProc},
750 {N_("Highlight Dragging"), NULL, "HighlightDragging", HighlightDraggingProc},
752 {N_("Highlight Last Move"), NULL, "HighlightLastMove", HighlightLastMoveProc},
753 {N_("Highlight With Arrow"), NULL, "HighlightWithArrow", HighlightArrowProc},
754 {N_("Move Sound"), NULL, "MoveSound", MoveSoundProc},
755 {N_("One-Click Moving"), NULL, "OneClickMoving", OneClickProc},
756 {N_("Periodic Updates"), NULL, "PeriodicUpdates", PeriodicUpdatesProc},
757 {N_("Ponder Next Move"), "<Ctrl><Shift>p", "PonderNextMove", PonderNextMoveProc},
758 {N_("Popup Exit Message"), NULL, "PopupExitMessage", PopupExitMessageProc},
759 {N_("Popup Move Errors"), NULL, "PopupMoveErrors", PopupMoveErrorsProc},
760 {N_("Show Coords"), NULL, "ShowCoords", ShowCoordsProc},
761 {N_("Hide Thinking"), "<Ctrl><Shift>h", "HideThinking", HideThinkingProc},
762 {N_("Test Legality"), "<Ctrl><Shift>l", "TestLegality", TestLegalityProc},
763 {"----", NULL, NULL, NothingProc},
765 {N_("Save Settings Now"), NULL, "SaveSettingsNow", SaveSettingsProc},
766 {N_("Save Settings on Exit"), NULL, "SaveSettingsonExit", SaveOnExitProc, CHECK },
767 {NULL, NULL, NULL, NULL}
770 MenuItem helpMenu[] = {
771 {N_("Info XBoard"), NULL, "InfoXBoard", InfoProc},
772 {N_("Man XBoard"), "F1", "ManXBoard", ManProc},
773 {"----", NULL, NULL, NothingProc},
774 {N_("XBoard Home Page"), NULL, "XBoardHomePage", HomePageProc},
775 {N_("On-line User Guide"), NULL, "On-lineUserGuide", GuideProc},
776 {N_("Development News"), NULL, "DevelopmentNews", NewsPageProc},
777 {N_("e-Mail Bug Report"), NULL, "e-MailBugReport", BugReportProc},
778 {"----", NULL, NULL, NothingProc},
779 {N_("About XBoard"), NULL, "AboutXBoard", AboutProc},
780 {NULL, NULL, NULL, NULL}
783 MenuItem noMenu[] = {
784 { "", "<Alt>Next" ,"LoadNextGame", LoadNextGameProc },
785 { "", "<Alt>Prior" ,"LoadPrevGame", LoadPrevGameProc },
786 { "", NULL,"ReloadGame", ReloadGameProc },
787 { "", NULL,"ReloadPosition", ReloadPositionProc },
788 #ifndef OPTIONSDIALOG
789 { "", NULL,"AlwaysQueen", AlwaysQueenProc },
790 { "", NULL,"AnimateDragging", AnimateDraggingProc },
791 { "", NULL,"AnimateMoving", AnimateMovingProc },
792 { "", NULL,"Autoflag", AutoflagProc },
793 { "", NULL,"Autoflip", AutoflipProc },
794 { "", NULL,"Blindfold", BlindfoldProc },
795 { "", NULL,"FlashMoves", FlashMovesProc },
797 { "", NULL,"HighlightDragging", HighlightDraggingProc },
799 { "", NULL,"HighlightLastMove", HighlightLastMoveProc },
800 { "", NULL,"MoveSound", MoveSoundProc },
801 { "", NULL,"PeriodicUpdates", PeriodicUpdatesProc },
802 { "", NULL,"PopupExitMessage", PopupExitMessageProc },
803 { "", NULL,"PopupMoveErrors", PopupMoveErrorsProc },
804 { "", NULL,"ShowCoords", ShowCoordsProc },
805 { "", NULL,"ShowThinking", ShowThinkingProc },
806 { "", NULL,"HideThinking", HideThinkingProc },
807 { "", NULL,"TestLegality", TestLegalityProc },
809 { "", NULL,"AboutGame", AboutGameEvent },
810 { "", "<Ctrl>d" ,"DebugProc", DebugProc },
811 { "", NULL,"Nothing", NothingProc },
812 {NULL, NULL, NULL, NULL}
816 {N_("File"), "File", fileMenu},
817 {N_("Edit"), "Edit", editMenu},
818 {N_("View"), "View", viewMenu},
819 {N_("Mode"), "Mode", modeMenu},
820 {N_("Action"), "Action", actionMenu},
821 {N_("Engine"), "Engine", engineMenu},
822 {N_("Options"), "Options", optionsMenu},
823 {N_("Help"), "Help", helpMenu},
825 { "", "None", noMenu}
829 MenuNameToItem (char *menuName)
832 char buf[MSG_SIZ], *p;
834 static MenuItem a = { NULL, NULL, NULL, NothingProc };
835 extern Option mainOptions[];
836 safeStrCpy(buf, menuName, MSG_SIZ);
837 p = strchr(buf, '.');
838 if(!p) menuTab = noMenu, p = menuName; else {
840 for(i=0; menuBar[i].name; i++)
841 if(!strcmp(buf, menuBar[i].name)) break;
842 if(!menuBar[i].name) return NULL; // main menu not found
843 menuTab = menuBar[i].mi;
845 if(*p == NULLCHAR) { a.handle = mainOptions[i+1].handle; return &a; } // main menu bar
846 for(i=0; menuTab[i].string; i++)
847 if(menuTab[i].ref && !strcmp(p, menuTab[i].ref)) return menuTab + i;
848 return NULL; // item not found
854 AppendEnginesToMenu (char *list)
858 if(appData.icsActive || appData.recentEngines <= 0) return;
859 for(firstEngineItem=0; engineMenu[firstEngineItem].string; firstEngineItem++);
860 recentEngines = strdup(list);
862 p = strchr(list, '\n'); if(p == NULL) break;
863 if(i == 0) engineMenu[firstEngineItem++].string = "----"; // at least one valid item to add
865 if(firstEngineItem + i < 99)
866 engineMenu[firstEngineItem+i].string = strdup(list); // just set name; MenuProc stays NULL
867 i++; *p = '\n'; list = p + 1;
871 Enables icsEnables[] = {
872 { "File.MailMove", False },
873 { "File.ReloadCMailMessage", False },
874 { "Mode.MachineBlack", False },
875 { "Mode.MachineWhite", False },
876 { "Mode.AnalysisMode", False },
877 { "Mode.AnalyzeFile", False },
878 { "Mode.TwoMachines", False },
879 { "Mode.MachineMatch", False },
881 { "Engine.Hint", False },
882 { "Engine.Book", False },
883 { "Engine.MoveNow", False },
884 #ifndef OPTIONSDIALOG
885 { "PeriodicUpdates", False },
886 { "HideThinking", False },
887 { "PonderNextMove", False },
890 { "Engine.Engine#1Settings", False },
891 { "Engine.Engine#2Settings", False },
892 { "Engine.Load1stEngine", False },
893 { "Engine.Load2ndEngine", False },
894 { "Edit.Annotate", False },
895 { "Options.Match", False },
899 Enables ncpEnables[] = {
900 { "File.MailMove", False },
901 { "File.ReloadCMailMessage", False },
902 { "Mode.MachineWhite", False },
903 { "Mode.MachineBlack", False },
904 { "Mode.AnalysisMode", False },
905 { "Mode.AnalyzeFile", False },
906 { "Mode.TwoMachines", False },
907 { "Mode.MachineMatch", False },
908 { "Mode.ICSClient", False },
909 { "View.ICStextmenu", False },
910 { "View.ICSInputBox", False },
911 { "View.OpenChatWindow", False },
912 { "Action.", False },
913 { "Edit.Revert", False },
914 { "Edit.Annotate", False },
915 { "Engine.Engine#1Settings", False },
916 { "Engine.Engine#2Settings", False },
917 { "Engine.MoveNow", False },
918 { "Engine.RetractMove", False },
919 { "Options.ICS", False },
920 #ifndef OPTIONSDIALOG
921 { "Options.AutoFlag", False },
922 { "Options.AutoFlip View", False },
923 // { "Options.ICSAlarm", False },
924 { "Options.MoveSound", False },
925 { "Options.HideThinking", False },
926 { "Options.PeriodicUpdates", False },
927 { "Options.PonderNextMove", False },
929 { "Engine.Hint", False },
930 { "Engine.Book", False },
934 Enables gnuEnables[] = {
935 { "Mode.ICSClient", False },
936 { "View.ICStextmenu", False },
937 { "View.ICSInputBox", False },
938 { "View.OpenChatWindow", False },
939 { "Action.Accept", False },
940 { "Action.Decline", False },
941 { "Action.Rematch", False },
942 { "Action.Adjourn", False },
943 { "Action.StopExamining", False },
944 { "Action.StopObserving", False },
945 { "Action.UploadtoExamine", False },
946 { "Edit.Revert", False },
947 { "Edit.Annotate", False },
948 { "Options.ICS", False },
950 /* The next two options rely on SetCmailMode being called *after* */
951 /* SetGNUMode so that when GNU is being used to give hints these */
952 /* menu options are still available */
954 { "File.MailMove", False },
955 { "File.ReloadCMailMessage", False },
956 // [HGM] The following have been added to make a switch from ncp to GNU mode possible
957 { "Mode.MachineWhite", True },
958 { "Mode.MachineBlack", True },
959 { "Mode.AnalysisMode", True },
960 { "Mode.AnalyzeFile", True },
961 { "Mode.TwoMachines", True },
962 { "Mode.MachineMatch", True },
963 { "Engine.Engine#1Settings", True },
964 { "Engine.Engine#2Settings", True },
965 { "Engine.Hint", True },
966 { "Engine.Book", True },
967 { "Engine.MoveNow", True },
968 { "Engine.RetractMove", True },
973 Enables cmailEnables[] = {
975 { "Action.CallFlag", False },
976 { "Action.Draw", True },
977 { "Action.Adjourn", False },
978 { "Action.Abort", False },
979 { "Action.StopObserving", False },
980 { "Action.StopExamining", False },
981 { "File.MailMove", True },
982 { "File.ReloadCMailMessage", True },
986 Enables trainingOnEnables[] = {
987 { "Edit.EditComment", False },
988 { "Mode.Pause", False },
989 { "Edit.Forward", False },
990 { "Edit.Backward", False },
991 { "Edit.ForwardtoEnd", False },
992 { "Edit.BacktoStart", False },
993 { "Engine.MoveNow", False },
994 { "Edit.TruncateGame", False },
998 Enables trainingOffEnables[] = {
999 { "Edit.EditComment", True },
1000 { "Mode.Pause", True },
1001 { "Edit.Forward", True },
1002 { "Edit.Backward", True },
1003 { "Edit.ForwardtoEnd", True },
1004 { "Edit.BacktoStart", True },
1005 { "Engine.MoveNow", True },
1006 { "Engine.TruncateGame", True },
1010 Enables machineThinkingEnables[] = {
1011 { "File.LoadGame", False },
1012 // { "LoadNextGame", False },
1013 // { "LoadPreviousGame", False },
1014 // { "ReloadSameGame", False },
1015 { "Edit.PasteGame", False },
1016 { "File.LoadPosition", False },
1017 // { "LoadNextPosition", False },
1018 // { "LoadPreviousPosition", False },
1019 // { "ReloadSamePosition", False },
1020 { "Edit.PastePosition", False },
1021 { "Mode.MachineWhite", False },
1022 { "Mode.MachineBlack", False },
1023 { "Mode.TwoMachines", False },
1024 // { "MachineMatch", False },
1025 { "Engine.RetractMove", False },
1029 Enables userThinkingEnables[] = {
1030 { "File.LoadGame", True },
1031 // { "LoadNextGame", True },
1032 // { "LoadPreviousGame", True },
1033 // { "ReloadSameGame", True },
1034 { "Edit.PasteGame", True },
1035 { "File.LoadPosition", True },
1036 // { "LoadNextPosition", True },
1037 // { "LoadPreviousPosition", True },
1038 // { "ReloadSamePosition", True },
1039 { "Edit.PastePosition", True },
1040 { "Mode.MachineWhite", True },
1041 { "Mode.MachineBlack", True },
1042 { "Mode.TwoMachines", True },
1043 // { "MachineMatch", True },
1044 { "Engine.RetractMove", True },
1051 SetMenuEnables(icsEnables);
1054 if (appData.zippyPlay && !appData.noChessProgram) { /* [DM] icsEngineAnalyze */
1055 EnableNamedMenuItem("Mode.AnalysisMode", True);
1056 EnableNamedMenuItem("Engine.Engine#1Settings", True);
1064 SetMenuEnables(ncpEnables);
1070 SetMenuEnables(gnuEnables);
1076 SetMenuEnables(cmailEnables);
1080 SetTrainingModeOn ()
1082 SetMenuEnables(trainingOnEnables);
1083 if (appData.showButtonBar) {
1084 EnableButtonBar(False);
1090 SetTrainingModeOff ()
1092 SetMenuEnables(trainingOffEnables);
1093 if (appData.showButtonBar) {
1094 EnableButtonBar(True);
1099 SetUserThinkingEnables ()
1101 if (appData.noChessProgram) return;
1102 SetMenuEnables(userThinkingEnables);
1106 SetMachineThinkingEnables ()
1108 if (appData.noChessProgram) return;
1109 SetMenuEnables(machineThinkingEnables);
1111 case MachinePlaysBlack:
1112 case MachinePlaysWhite:
1113 case TwoMachinesPlay:
1114 EnableNamedMenuItem(ModeToWidgetName(gameMode), True);
1122 GreyRevert (Boolean grey)
1124 EnableNamedMenuItem("Edit.Revert", !grey);
1125 EnableNamedMenuItem("Edit.Annotate", !grey);
1129 ModeToWidgetName (GameMode mode)
1132 case BeginningOfGame:
1133 if (appData.icsActive)
1134 return "Mode.ICSClient";
1135 else if (appData.noChessProgram ||
1136 *appData.cmailGameName != NULLCHAR)
1137 return "Mode.EditGame";
1139 return "Mode.MachineBlack";
1140 case MachinePlaysBlack:
1141 return "Mode.MachineBlack";
1142 case MachinePlaysWhite:
1143 return "Mode.MachineWhite";
1145 return "Mode.AnalysisMode";
1147 return "Mode.AnalyzeFile";
1148 case TwoMachinesPlay:
1149 return "Mode.TwoMachines";
1151 return "Mode.EditGame";
1152 case PlayFromGameFile:
1153 return "File.LoadGame";
1155 return "Mode.EditPosition";
1157 return "Mode.Training";
1158 case IcsPlayingWhite:
1159 case IcsPlayingBlack:
1163 return "Mode.ICSClient";
1171 InstallNewEngine (char *command, char *dir, char *variants, char *protocol)
1172 { // install the given engine in XBoard's -firstChessProgramNames
1173 char buf[MSG_SIZ], *quote = "";
1174 if(strchr(command, ' ')) { // quoting needed
1175 if(!strchr(command, '"')) quote = "\""; else
1176 if(!strchr(command, '\'')) quote = "'"; else {
1177 printf("Could not auto-install %s\n", command); // too complex
1180 // construct engine line, with optional -fd and -fUCI arguments
1181 snprintf(buf, MSG_SIZ, "%s%s%s", quote, command, quote);
1182 if(strcmp(dir, "") && strcmp(dir, "."))
1183 snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fd %s", dir);
1184 if(!strcmp(protocol, "uci"))
1185 snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fUCI");
1186 if(strstr(firstChessProgramNames, buf)) return; // avoid duplicats
1188 quote = malloc(strlen(firstChessProgramNames) + strlen(buf) + 2);
1189 sprintf(quote, "%s%s\n", firstChessProgramNames, buf);
1190 FREE(firstChessProgramNames); firstChessProgramNames = quote;
1193 #ifdef HAVE_DIRENT_H
1196 #include <sys/dir.h>
1197 #define dirent direct
1201 InstallFromDir (char *dirName, char *protocol, char *settingsFile)
1202 { // scan system for new plugin specs in given directory
1205 struct stat statBuf;
1206 time_t lastSaved = 0;
1209 if(!stat(settingsFile, &statBuf)) lastSaved = statBuf.st_mtime;
1210 snprintf(buf, 1024, "%s/%s", dirName, protocol);
1212 if(!(dir = opendir(buf))) return;
1213 while( (dp = readdir(dir))) {
1214 time_t installed = 0;
1215 if(!strstr(dp->d_name, ".eng")) continue; // to suppress . and ..
1216 snprintf(buf, 1024, "%s/%s/%s", dirName, protocol, dp->d_name);
1217 if(!stat(buf, &statBuf)) installed = statBuf.st_mtime;
1218 if(lastSaved == 0 || (int) (installed - lastSaved) > 0) { // first time we see it
1219 FILE *f = fopen(buf, "r");
1220 if(f) { // read the plugin-specs
1221 char engineCommand[1024], engineDir[1024], variants[1024];
1222 char bad=0, dummy, *engineCom = engineCommand;
1224 if(fscanf(f, "plugin spec %d.%d%c", &major, &minor, &dummy) != 3 ||
1225 fscanf(f, "%[^\n]%c", engineCommand, &dummy) != 2 ||
1226 fscanf(f, "%[^\n]%c", variants, &dummy) != 2) bad = 1;
1229 // uncomment following two lines for chess-only installs
1230 // if(!(p = strstr(variants, "chess")) ||
1231 // p != variants && p[-1] != ',' || p[5] && p[5] != ',') continue;
1232 // split off engine working directory (if any)
1233 strcpy(engineDir, "");
1234 if(sscanf(engineCommand, "cd %[^;];%c", engineDir, &dummy) == 2)
1235 engineCom = engineCommand + strlen(engineDir) + 4;
1236 InstallNewEngine(engineCom, engineDir, variants, protocol);
1244 AutoInstallProtocol (char *settingsFile, char *protocol)
1245 { // install new engines for given protocol (both from package and source)
1246 InstallFromDir("/usr/local/share/games/plugins", protocol, settingsFile);
1247 InstallFromDir("/usr/share/games/plugins", protocol, settingsFile);
1251 AutoInstall (char *settingsFile)
1252 { // install all new XBoard and UCI engines
1253 AutoInstallProtocol(settingsFile, "xboard");
1254 AutoInstallProtocol(settingsFile, "uci");
1260 #ifndef OPTIONSDIALOG
1261 if (appData.alwaysPromoteToQueen) {
1262 MarkMenuItem("Options.Always Queen", True);
1264 if (appData.animateDragging) {
1265 MarkMenuItem("Options.Animate Dragging", True);
1267 if (appData.animate) {
1268 MarkMenuItem("Options.Animate Moving", True);
1270 if (appData.autoCallFlag) {
1271 MarkMenuItem("Options.Auto Flag", True);
1273 if (appData.autoFlipView) {
1274 XtSetValues(XtNameToWidget(menuBarWidget,"Options.Auto Flip View", True);
1276 if (appData.blindfold) {
1277 MarkMenuItem("Options.Blindfold", True);
1279 if (appData.flashCount > 0) {
1280 MarkMenuItem("Options.Flash Moves", True);
1283 if (appData.highlightDragging) {
1284 MarkMenuItem("Options.Highlight Dragging", True);
1287 if (appData.highlightLastMove) {
1288 MarkMenuItem("Options.Highlight Last Move", True);
1290 if (appData.highlightMoveWithArrow) {
1291 MarkMenuItem("Options.Arrow", True);
1293 // if (appData.icsAlarm) {
1294 // MarkMenuItem("Options.ICS Alarm", True);
1296 if (appData.ringBellAfterMoves) {
1297 MarkMenuItem("Options.Move Sound", True);
1299 if (appData.oneClick) {
1300 MarkMenuItem("Options.OneClick", True);
1302 if (appData.periodicUpdates) {
1303 MarkMenuItem("Options.Periodic Updates", True);
1305 if (appData.ponderNextMove) {
1306 MarkMenuItem("Options.Ponder Next Move", True);
1308 if (appData.popupExitMessage) {
1309 MarkMenuItem("Options.Popup Exit Message", True);
1311 if (appData.popupMoveErrors) {
1312 MarkMenuItem("Options.Popup Move Errors", True);
1314 // if (appData.premove) {
1315 // MarkMenuItem("Options.Premove", True);
1317 if (appData.showCoords) {
1318 MarkMenuItem("Options.Show Coords", True);
1320 if (appData.hideThinkingFromHuman) {
1321 MarkMenuItem("Options.Hide Thinking", True);
1323 if (appData.testLegality) {
1324 MarkMenuItem("Options.Test Legality", True);
1327 if (saveSettingsOnExit) {
1328 MarkMenuItem("Options.SaveSettingsonExit", True);
1330 EnableNamedMenuItem("File.SaveSelected", False);
1332 // all XBoard builds get here, but not WinBoard...
1333 if(*appData.autoInstall) AutoInstall(settingsFileName);