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"));
409 MarkMenuItem("Options.Mute", mute);
419 # define MARK_MENU_ITEM(X,Y)
421 # define MARK_MENU_ITEM(X,Y) MarkMenuItem(X, Y)
425 PonderNextMoveProc ()
427 PonderNextMoveEvent(!appData.ponderNextMove);
428 MARK_MENU_ITEM("Options.PonderNextMove", appData.ponderNextMove);
434 appData.alwaysPromoteToQueen = !appData.alwaysPromoteToQueen;
435 MARK_MENU_ITEM("Options.AlwaysQueen", appData.alwaysPromoteToQueen);
439 AnimateDraggingProc ()
441 appData.animateDragging = !appData.animateDragging;
443 if (appData.animateDragging) CreateAnimVars();
444 MARK_MENU_ITEM("Options.AnimateDragging", appData.animateDragging);
450 appData.animate = !appData.animate;
451 if (appData.animate) CreateAnimVars();
452 MARK_MENU_ITEM("Options.AnimateMoving", appData.animate);
458 appData.autoCallFlag = !appData.autoCallFlag;
459 MARK_MENU_ITEM("Options.AutoFlag", appData.autoCallFlag);
465 appData.autoFlipView = !appData.autoFlipView;
466 MARK_MENU_ITEM("Options.AutoFlipView", appData.autoFlipView);
472 appData.blindfold = !appData.blindfold;
473 MARK_MENU_ITEM("Options.Blindfold", appData.blindfold);
474 DrawPosition(True, NULL);
480 appData.testLegality = !appData.testLegality;
481 MARK_MENU_ITEM("Options.TestLegality", appData.testLegality);
488 if (appData.flashCount == 0) {
489 appData.flashCount = 3;
491 appData.flashCount = -appData.flashCount;
493 MARK_MENU_ITEM("Options.FlashMoves", appData.flashCount > 0);
498 HighlightDraggingProc ()
500 appData.highlightDragging = !appData.highlightDragging;
501 MARK_MENU_ITEM("Options.HighlightDragging", appData.highlightDragging);
506 HighlightLastMoveProc ()
508 appData.highlightLastMove = !appData.highlightLastMove;
509 MARK_MENU_ITEM("Options.HighlightLastMove", appData.highlightLastMove);
513 HighlightArrowProc ()
515 appData.highlightMoveWithArrow = !appData.highlightMoveWithArrow;
516 MARK_MENU_ITEM("Options.HighlightWithArrow", appData.highlightMoveWithArrow);
522 appData.icsAlarm = !appData.icsAlarm;
523 // MARK_MENU_ITEM("Options.ICSAlarm", appData.icsAlarm);
529 appData.ringBellAfterMoves = !appData.ringBellAfterMoves;
530 MARK_MENU_ITEM("Options.MoveSound", appData.ringBellAfterMoves);
536 appData.oneClick = !appData.oneClick;
537 MARK_MENU_ITEM("Options.OneClickMoving", appData.oneClick);
541 PeriodicUpdatesProc ()
543 PeriodicUpdatesEvent(!appData.periodicUpdates);
544 MARK_MENU_ITEM("Options.PeriodicUpdates", appData.periodicUpdates);
548 PopupExitMessageProc ()
550 appData.popupExitMessage = !appData.popupExitMessage;
551 MARK_MENU_ITEM("Options.PopupExitMessage", appData.popupExitMessage);
555 PopupMoveErrorsProc ()
557 appData.popupMoveErrors = !appData.popupMoveErrors;
558 MARK_MENU_ITEM("Options.PopupMoveErrors", appData.popupMoveErrors);
564 appData.premove = !appData.premove;
565 // MARK_MENU_ITEM("Options.Premove", appData.premove);
571 appData.showCoords = !appData.showCoords;
572 MARK_MENU_ITEM("Options.ShowCoords", appData.showCoords);
573 DrawPosition(True, NULL);
579 appData.showThinking = !appData.showThinking; // [HGM] thinking: taken out of ShowThinkingEvent
586 appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman; // [HGM] thinking: taken out of ShowThinkingEvent
589 MARK_MENU_ITEM("Options.HideThinking", appData.hideThinkingFromHuman);
595 ScheduleDelayedEvent(CreateBookEvent, 50);
601 FileNamePopUp(_("Save game file name?"),
608 * Menu definition tables
611 MenuItem fileMenu[] = {
612 {N_("New Game"), "<Ctrl>n", "NewGame", ResetGameEvent},
613 {N_("New Shuffle Game..."), NULL, "NewShuffleGame", ShuffleMenuProc},
614 {N_("New Variant..."), "<Alt><Shift>v", "NewVariant", NewVariantProc},// [HGM] variant: not functional yet
615 {"----", NULL, NULL, NothingProc},
616 {N_("Load Game"), "<Ctrl>o", "LoadGame", LoadGameProc, CHECK},
617 {N_("Load Position"), "<Ctrl><Shift>o", "LoadPosition", LoadPositionProc},
618 {N_("Next Position"), "<Shift>Page_Down", "LoadNextPosition", LoadNextPositionProc},
619 {N_("Prev Position"), "<Shift>Page_Up", "LoadPreviousPosition", LoadPrevPositionProc},
620 {"----", NULL, NULL, NothingProc},
621 {N_("Save Game"), "<Ctrl>s", "SaveGame", SaveGameProc},
622 {N_("Save Position"), "<Ctrl><Shift>s", "SavePosition", SavePositionProc},
623 {N_("Save Selected Games"), NULL, "SaveSelected", SaveSelectedProc},
624 {N_("Save Games as Book"), NULL, "CreateBook", CreateBookDelayed},
625 {"----", NULL, NULL, NothingProc},
626 {N_("Mail Move"), NULL, "MailMove", MailMoveEvent},
627 {N_("Reload CMail Message"), NULL, "ReloadCMailMessage", ReloadCmailMsgProc},
628 {"----", NULL, NULL, NothingProc},
629 {N_("Quit "), "<Ctrl>q", "Quit", QuitProc},
630 {NULL, NULL, NULL, NULL}
633 MenuItem editMenu[] = {
634 {N_("Copy Game"), "<Ctrl>c", "CopyGame", CopyGameProc},
635 {N_("Copy Position"), "<Ctrl><Shift>c", "CopyPosition", CopyPositionProc},
636 {N_("Copy Game List"), NULL, "CopyGameList", CopyGameListProc},
637 {"----", NULL, NULL, NothingProc},
638 {N_("Paste Game"), "<Ctrl>v", "PasteGame", PasteGameProc},
639 {N_("Paste Position"), "<Ctrl><Shift>v", "PastePosition", PastePositionProc},
640 {"----", NULL, NULL, NothingProc},
641 {N_("Edit Game"), "<Ctrl>e", "EditGame", EditGameEvent},
642 {N_("Edit Position"), "<Ctrl><Shift>e", "EditPosition", EditPositionEvent},
643 {N_("Edit Tags"), NULL, "EditTags", EditTagsProc},
644 {N_("Edit Comment"), NULL, "EditComment", EditCommentProc},
645 {N_("Edit Book"), NULL, "EditBook", EditBookEvent},
646 {"----", NULL, NULL, NothingProc},
647 {N_("Revert"), "Home", "Revert", RevertProc},
648 {N_("Annotate"), NULL, "Annotate", AnnotateProc},
649 {N_("Truncate Game"), "End", "TruncateGame", TruncateGameEvent},
650 {"----", NULL, NULL, NothingProc},
651 {N_("Backward"), "<Alt>Left", "Backward", BackwardEvent},
652 {N_("Forward"), "<Alt>Right", "Forward", ForwardEvent},
653 {N_("Back to Start"), "<Alt>Home", "BacktoStart", ToStartEvent},
654 {N_("Forward to End"), "<Alt>End", "ForwardtoEnd", ToEndEvent},
655 {NULL, NULL, NULL, NULL}
658 MenuItem viewMenu[] = {
659 {N_("Flip View"), "F2", "FlipView", FlipViewProc, CHECK},
660 {"----", NULL, NULL, NothingProc},
661 {N_("Engine Output"), "<Alt><Shift>o", "EngineOutput", EngineOutputProc, CHECK},
662 {N_("Move History"), "<Alt><Shift>h", "MoveHistory", HistoryShowProc, CHECK}, // [HGM] hist: activate 4.2.7 code
663 {N_("Evaluation Graph"), "<Alt><Shift>e", "EvaluationGraph", EvalGraphProc, CHECK},
664 {N_("Game List"), "<Alt><Shift>g", "GameList", ShowGameListProc, CHECK},
665 {"----", NULL, NULL, NothingProc},
666 {N_("Tags"), NULL, "Tags", EditTagsProc, CHECK},
667 {N_("Comments"), NULL, "Comments", EditCommentProc, CHECK},
668 {N_("ICS Input Box"), NULL, "ICSInputBox", IcsInputBoxProc, CHECK},
669 {N_("ICS/Chat Console"), NULL, "OpenChatWindow", ChatProc, CHECK},
670 {N_("ICS text menu"), NULL, "ICStextmenu", IcsTextProc, CHECK},
671 {N_("Edit ICS menu..."), NULL, "EditTextMenu", EditMenuProc},
672 {"----", NULL, NULL, NothingProc},
673 {N_("Edit Theme List..."), NULL, "EditThemeList", EditThemesProc},
674 {N_("Board..."), NULL, "Board", BoardOptionsProc},
675 {N_("Fonts..."), NULL, "Fonts", FontsProc},
676 {N_("Game List Tags..."), NULL, "GameListTags", GameListOptionsProc},
677 {NULL, NULL, NULL, NULL}
680 MenuItem modeMenu[] = {
681 {N_("Machine White"), "<Ctrl>w", "MachineWhite", MachineWhiteEvent, RADIO },
682 {N_("Machine Black"), "<Ctrl>b", "MachineBlack", MachineBlackEvent, RADIO },
683 {N_("Two Machines"), "<Ctrl>t", "TwoMachines", TwoMachinesEvent, RADIO },
684 {N_("Analysis Mode"), "<Ctrl>a", "AnalysisMode", (MenuProc*) AnalyzeModeEvent, RADIO },
685 {N_("Analyze Game"), "<Ctrl>g", "AnalyzeFile", AnalyzeFileEvent, RADIO },
686 {N_("Edit Game"), "<Ctrl>e", "EditGame", EditGameEvent, RADIO },
687 {N_("Edit Position"), "<Ctrl><Shift>e", "EditPosition", EditPositionEvent, RADIO },
688 {N_("Training"), NULL, "Training", TrainingEvent, RADIO },
689 {N_("ICS Client"), NULL, "ICSClient", IcsClientEvent, RADIO },
690 {"----", NULL, NULL, NothingProc},
691 {N_("Machine Match"), NULL, "MachineMatch", MatchProc, CHECK },
692 {N_("Pause"), "Pause", "Pause", PauseEvent, CHECK },
693 {NULL, NULL, NULL, NULL}
696 MenuItem actionMenu[] = {
697 {N_("Accept"), "F3", "Accept", AcceptEvent},
698 {N_("Decline"), "F4", "Decline", DeclineEvent},
699 {N_("Rematch"), "F12", "Rematch", RematchEvent},
700 {"----", NULL, NULL, NothingProc},
701 {N_("Call Flag"), "F5", "CallFlag", CallFlagEvent},
702 {N_("Draw"), "F6", "Draw", DrawEvent},
703 {N_("Adjourn"), "F7", "Adjourn", AdjournEvent},
704 {N_("Abort"), "F8", "Abort", AbortEvent},
705 {N_("Resign"), "F9", "Resign", ResignEvent},
706 {"----", NULL, NULL, NothingProc},
707 {N_("Stop Observing"), "F10", "StopObserving", StopObservingEvent},
708 {N_("Stop Examining"), "F11", "StopExamining", StopExaminingEvent},
709 {N_("Upload to Examine"), NULL, "UploadtoExamine", UploadGameEvent},
710 {"----", NULL, NULL, NothingProc},
711 {N_("Adjudicate to White"), NULL, "AdjudicatetoWhite", AdjuWhiteProc},
712 {N_("Adjudicate to Black"), NULL, "AdjudicatetoBlack", AdjuBlackProc},
713 {N_("Adjudicate Draw"), NULL, "AdjudicateDraw", AdjuDrawProc},
714 {NULL, NULL, NULL, NULL}
717 MenuItem engineMenu[100] = {
718 {N_("Edit Engine List..."), NULL, "EditEngList", EditEngineProc},
719 {"----", NULL, NULL, NothingProc},
720 {N_("Load New 1st Engine..."), NULL, "LoadNew1stEngine", LoadEngine1Proc},
721 {N_("Load New 2nd Engine..."), NULL, "LoadNew2ndEngine", LoadEngine2Proc},
722 {"----", NULL, NULL, NothingProc},
723 {N_("Engine #1 Settings..."), NULL, "Engine#1Settings", FirstSettingsProc},
724 {N_("Engine #2 Settings..."), NULL, "Engine#2Settings", SecondSettingsProc},
725 {N_("Common Settings..."), "<Alt><Shift>u","CommonEngine", UciMenuProc},
726 {"----", NULL, NULL, NothingProc},
727 {N_("Hint"), NULL, "Hint", HintEvent},
728 {N_("Book"), NULL, "Book", BookEvent},
729 {"----", NULL, NULL, NothingProc},
730 {N_("Move Now"), "<Ctrl>m", "MoveNow", MoveNowEvent},
731 {N_("Retract Move"), "<Ctrl>x", "RetractMove", RetractMoveEvent},
732 {NULL, NULL, NULL, NULL}
735 MenuItem optionsMenu[] = {
736 {N_("Mute all Sounds"), NULL, "Mute", MuteProc, CHECK},
737 {"----", NULL, NULL, NothingProc},
739 {N_("General..."), NULL, "General", OptionsProc},
741 {N_("Time Control..."), "<Alt><Shift>t", "TimeControl", TimeControlProc},
742 {N_("Adjudications..."), "<Alt><Shift>j", "Adjudications", EngineMenuProc},
743 {N_("ICS..."), NULL, "ICS", IcsOptionsProc},
744 {N_("Tournament..."), NULL, "Match", MatchOptionsProc},
745 {N_("Load Game..."), NULL, "LoadGame", LoadOptionsProc},
746 {N_("Save Game..."), NULL, "SaveGame", SaveOptionsProc},
747 {N_("Game List..."), NULL, "GameList", GameListOptionsProc},
748 {N_("Sounds..."), NULL, "Sounds", SoundOptionsProc},
749 {"----", NULL, NULL, NothingProc},
750 #ifndef OPTIONSDIALOG
751 {N_("Always Queen"), "<Ctrl><Shift>q", "AlwaysQueen", AlwaysQueenProc},
752 {N_("Animate Dragging"), NULL, "AnimateDragging", AnimateDraggingProc},
753 {N_("Animate Moving"), "<Ctrl><Shift>a", "AnimateMoving", AnimateMovingProc},
754 {N_("Auto Flag"), "<Ctrl><Shift>f", "AutoFlag", AutoflagProc},
755 {N_("Auto Flip View"), NULL, "AutoFlipView", AutoflipProc},
756 {N_("Blindfold"), NULL, "Blindfold", BlindfoldProc},
757 {N_("Flash Moves"), NULL, "FlashMoves", FlashMovesProc},
759 {N_("Highlight Dragging"), NULL, "HighlightDragging", HighlightDraggingProc},
761 {N_("Highlight Last Move"), NULL, "HighlightLastMove", HighlightLastMoveProc},
762 {N_("Highlight With Arrow"), NULL, "HighlightWithArrow", HighlightArrowProc},
763 {N_("Move Sound"), NULL, "MoveSound", MoveSoundProc},
764 {N_("One-Click Moving"), NULL, "OneClickMoving", OneClickProc},
765 {N_("Periodic Updates"), NULL, "PeriodicUpdates", PeriodicUpdatesProc},
766 {N_("Ponder Next Move"), "<Ctrl><Shift>p", "PonderNextMove", PonderNextMoveProc},
767 {N_("Popup Exit Message"), NULL, "PopupExitMessage", PopupExitMessageProc},
768 {N_("Popup Move Errors"), NULL, "PopupMoveErrors", PopupMoveErrorsProc},
769 {N_("Show Coords"), NULL, "ShowCoords", ShowCoordsProc},
770 {N_("Hide Thinking"), "<Ctrl><Shift>h", "HideThinking", HideThinkingProc},
771 {N_("Test Legality"), "<Ctrl><Shift>l", "TestLegality", TestLegalityProc},
772 {"----", NULL, NULL, NothingProc},
774 {N_("Save Settings Now"), NULL, "SaveSettingsNow", SaveSettingsProc},
775 {N_("Save Settings on Exit"), NULL, "SaveSettingsonExit", SaveOnExitProc, CHECK },
776 {NULL, NULL, NULL, NULL}
779 MenuItem helpMenu[] = {
780 {N_("Info XBoard"), NULL, "InfoXBoard", InfoProc},
781 {N_("Man XBoard"), "F1", "ManXBoard", ManProc},
782 {"----", NULL, NULL, NothingProc},
783 {N_("XBoard Home Page"), NULL, "XBoardHomePage", HomePageProc},
784 {N_("On-line User Guide"), NULL, "On-lineUserGuide", GuideProc},
785 {N_("Development News"), NULL, "DevelopmentNews", NewsPageProc},
786 {N_("e-Mail Bug Report"), NULL, "e-MailBugReport", BugReportProc},
787 {"----", NULL, NULL, NothingProc},
788 {N_("About XBoard"), NULL, "AboutXBoard", AboutProc},
789 {NULL, NULL, NULL, NULL}
792 MenuItem noMenu[] = {
793 { "", "<Alt>Next" ,"LoadNextGame", LoadNextGameProc },
794 { "", "<Alt>Prior" ,"LoadPrevGame", LoadPrevGameProc },
795 { "", NULL,"ReloadGame", ReloadGameProc },
796 { "", NULL,"ReloadPosition", ReloadPositionProc },
797 #ifndef OPTIONSDIALOG
798 { "", NULL,"AlwaysQueen", AlwaysQueenProc },
799 { "", NULL,"AnimateDragging", AnimateDraggingProc },
800 { "", NULL,"AnimateMoving", AnimateMovingProc },
801 { "", NULL,"Autoflag", AutoflagProc },
802 { "", NULL,"Autoflip", AutoflipProc },
803 { "", NULL,"Blindfold", BlindfoldProc },
804 { "", NULL,"FlashMoves", FlashMovesProc },
806 { "", NULL,"HighlightDragging", HighlightDraggingProc },
808 { "", NULL,"HighlightLastMove", HighlightLastMoveProc },
809 { "", NULL,"MoveSound", MoveSoundProc },
810 { "", NULL,"PeriodicUpdates", PeriodicUpdatesProc },
811 { "", NULL,"PopupExitMessage", PopupExitMessageProc },
812 { "", NULL,"PopupMoveErrors", PopupMoveErrorsProc },
813 { "", NULL,"ShowCoords", ShowCoordsProc },
814 { "", NULL,"ShowThinking", ShowThinkingProc },
815 { "", NULL,"HideThinking", HideThinkingProc },
816 { "", NULL,"TestLegality", TestLegalityProc },
818 { "", NULL,"AboutGame", AboutGameEvent },
819 { "", "<Ctrl>d" ,"DebugProc", DebugProc },
820 { "", NULL,"Nothing", NothingProc },
821 {NULL, NULL, NULL, NULL}
825 {N_("File"), "File", fileMenu},
826 {N_("Edit"), "Edit", editMenu},
827 {N_("View"), "View", viewMenu},
828 {N_("Mode"), "Mode", modeMenu},
829 {N_("Action"), "Action", actionMenu},
830 {N_("Engine"), "Engine", engineMenu},
831 {N_("Options"), "Options", optionsMenu},
832 {N_("Help"), "Help", helpMenu},
834 { "", "None", noMenu}
838 MenuNameToItem (char *menuName)
841 char buf[MSG_SIZ], *p;
843 static MenuItem a = { NULL, NULL, NULL, NothingProc };
844 extern Option mainOptions[];
845 safeStrCpy(buf, menuName, MSG_SIZ);
846 p = strchr(buf, '.');
847 if(!p) menuTab = noMenu, p = menuName; else {
849 for(i=0; menuBar[i].name; i++)
850 if(!strcmp(buf, menuBar[i].name)) break;
851 if(!menuBar[i].name) return NULL; // main menu not found
852 menuTab = menuBar[i].mi;
854 if(*p == NULLCHAR) { a.handle = mainOptions[i+1].handle; return &a; } // main menu bar
855 for(i=0; menuTab[i].string; i++)
856 if(menuTab[i].ref && !strcmp(p, menuTab[i].ref)) return menuTab + i;
857 return NULL; // item not found
863 AppendEnginesToMenu (char *list)
867 if(appData.icsActive || appData.recentEngines <= 0) return;
868 for(firstEngineItem=0; engineMenu[firstEngineItem].string; firstEngineItem++);
869 recentEngines = strdup(list);
871 p = strchr(list, '\n'); if(p == NULL) break;
872 if(i == 0) engineMenu[firstEngineItem++].string = "----"; // at least one valid item to add
874 if(firstEngineItem + i < 99)
875 engineMenu[firstEngineItem+i].string = strdup(list); // just set name; MenuProc stays NULL
876 i++; *p = '\n'; list = p + 1;
880 Enables icsEnables[] = {
881 { "File.MailMove", False },
882 { "File.ReloadCMailMessage", False },
883 { "Mode.MachineBlack", False },
884 { "Mode.MachineWhite", False },
885 { "Mode.AnalysisMode", False },
886 { "Mode.AnalyzeFile", False },
887 { "Mode.TwoMachines", False },
888 { "Mode.MachineMatch", False },
890 { "Engine.Hint", False },
891 { "Engine.Book", False },
892 { "Engine.MoveNow", False },
893 #ifndef OPTIONSDIALOG
894 { "PeriodicUpdates", False },
895 { "HideThinking", False },
896 { "PonderNextMove", False },
899 { "Engine.Engine#1Settings", False },
900 { "Engine.Engine#2Settings", False },
901 { "Engine.Load1stEngine", False },
902 { "Engine.Load2ndEngine", False },
903 { "Edit.Annotate", False },
904 { "Options.Match", False },
908 Enables ncpEnables[] = {
909 { "File.MailMove", False },
910 { "File.ReloadCMailMessage", False },
911 { "Mode.MachineWhite", False },
912 { "Mode.MachineBlack", False },
913 { "Mode.AnalysisMode", False },
914 { "Mode.AnalyzeFile", False },
915 { "Mode.TwoMachines", False },
916 { "Mode.MachineMatch", False },
917 { "Mode.ICSClient", False },
918 { "View.ICStextmenu", False },
919 { "View.ICSInputBox", False },
920 { "View.OpenChatWindow", False },
921 { "Action.", False },
922 { "Edit.Revert", False },
923 { "Edit.Annotate", False },
924 { "Engine.Engine#1Settings", False },
925 { "Engine.Engine#2Settings", False },
926 { "Engine.MoveNow", False },
927 { "Engine.RetractMove", False },
928 { "Options.ICS", False },
929 #ifndef OPTIONSDIALOG
930 { "Options.AutoFlag", False },
931 { "Options.AutoFlip View", False },
932 // { "Options.ICSAlarm", False },
933 { "Options.MoveSound", False },
934 { "Options.HideThinking", False },
935 { "Options.PeriodicUpdates", False },
936 { "Options.PonderNextMove", False },
938 { "Engine.Hint", False },
939 { "Engine.Book", False },
943 Enables gnuEnables[] = {
944 { "Mode.ICSClient", False },
945 { "View.ICStextmenu", False },
946 { "View.ICSInputBox", False },
947 { "View.OpenChatWindow", False },
948 { "Action.Accept", False },
949 { "Action.Decline", False },
950 { "Action.Rematch", False },
951 { "Action.Adjourn", False },
952 { "Action.StopExamining", False },
953 { "Action.StopObserving", False },
954 { "Action.UploadtoExamine", False },
955 { "Edit.Revert", False },
956 { "Edit.Annotate", False },
957 { "Options.ICS", False },
959 /* The next two options rely on SetCmailMode being called *after* */
960 /* SetGNUMode so that when GNU is being used to give hints these */
961 /* menu options are still available */
963 { "File.MailMove", False },
964 { "File.ReloadCMailMessage", False },
965 // [HGM] The following have been added to make a switch from ncp to GNU mode possible
966 { "Mode.MachineWhite", True },
967 { "Mode.MachineBlack", True },
968 { "Mode.AnalysisMode", True },
969 { "Mode.AnalyzeFile", True },
970 { "Mode.TwoMachines", True },
971 { "Mode.MachineMatch", True },
972 { "Engine.Engine#1Settings", True },
973 { "Engine.Engine#2Settings", True },
974 { "Engine.Hint", True },
975 { "Engine.Book", True },
976 { "Engine.MoveNow", True },
977 { "Engine.RetractMove", True },
982 Enables cmailEnables[] = {
984 { "Action.CallFlag", False },
985 { "Action.Draw", True },
986 { "Action.Adjourn", False },
987 { "Action.Abort", False },
988 { "Action.StopObserving", False },
989 { "Action.StopExamining", False },
990 { "File.MailMove", True },
991 { "File.ReloadCMailMessage", True },
995 Enables trainingOnEnables[] = {
996 { "Edit.EditComment", False },
997 { "Mode.Pause", False },
998 { "Edit.Forward", False },
999 { "Edit.Backward", False },
1000 { "Edit.ForwardtoEnd", False },
1001 { "Edit.BacktoStart", False },
1002 { "Engine.MoveNow", False },
1003 { "Edit.TruncateGame", False },
1007 Enables trainingOffEnables[] = {
1008 { "Edit.EditComment", True },
1009 { "Mode.Pause", True },
1010 { "Edit.Forward", True },
1011 { "Edit.Backward", True },
1012 { "Edit.ForwardtoEnd", True },
1013 { "Edit.BacktoStart", True },
1014 { "Engine.MoveNow", True },
1015 { "Engine.TruncateGame", True },
1019 Enables machineThinkingEnables[] = {
1020 { "File.LoadGame", False },
1021 // { "LoadNextGame", False },
1022 // { "LoadPreviousGame", False },
1023 // { "ReloadSameGame", False },
1024 { "Edit.PasteGame", False },
1025 { "File.LoadPosition", False },
1026 // { "LoadNextPosition", False },
1027 // { "LoadPreviousPosition", False },
1028 // { "ReloadSamePosition", False },
1029 { "Edit.PastePosition", False },
1030 { "Mode.MachineWhite", False },
1031 { "Mode.MachineBlack", False },
1032 { "Mode.TwoMachines", False },
1033 // { "MachineMatch", False },
1034 { "Engine.RetractMove", False },
1038 Enables userThinkingEnables[] = {
1039 { "File.LoadGame", True },
1040 // { "LoadNextGame", True },
1041 // { "LoadPreviousGame", True },
1042 // { "ReloadSameGame", True },
1043 { "Edit.PasteGame", True },
1044 { "File.LoadPosition", True },
1045 // { "LoadNextPosition", True },
1046 // { "LoadPreviousPosition", True },
1047 // { "ReloadSamePosition", True },
1048 { "Edit.PastePosition", True },
1049 { "Mode.MachineWhite", True },
1050 { "Mode.MachineBlack", True },
1051 { "Mode.TwoMachines", True },
1052 // { "MachineMatch", True },
1053 { "Engine.RetractMove", True },
1060 SetMenuEnables(icsEnables);
1063 if (appData.zippyPlay && !appData.noChessProgram) { /* [DM] icsEngineAnalyze */
1064 EnableNamedMenuItem("Mode.AnalysisMode", True);
1065 EnableNamedMenuItem("Engine.Engine#1Settings", True);
1073 SetMenuEnables(ncpEnables);
1079 SetMenuEnables(gnuEnables);
1085 SetMenuEnables(cmailEnables);
1089 SetTrainingModeOn ()
1091 SetMenuEnables(trainingOnEnables);
1092 if (appData.showButtonBar) {
1093 EnableButtonBar(False);
1099 SetTrainingModeOff ()
1101 SetMenuEnables(trainingOffEnables);
1102 if (appData.showButtonBar) {
1103 EnableButtonBar(True);
1108 SetUserThinkingEnables ()
1110 if (appData.noChessProgram) return;
1111 SetMenuEnables(userThinkingEnables);
1115 SetMachineThinkingEnables ()
1117 if (appData.noChessProgram) return;
1118 SetMenuEnables(machineThinkingEnables);
1120 case MachinePlaysBlack:
1121 case MachinePlaysWhite:
1122 case TwoMachinesPlay:
1123 EnableNamedMenuItem(ModeToWidgetName(gameMode), True);
1131 GreyRevert (Boolean grey)
1133 EnableNamedMenuItem("Edit.Revert", !grey);
1134 EnableNamedMenuItem("Edit.Annotate", !grey);
1138 ModeToWidgetName (GameMode mode)
1141 case BeginningOfGame:
1142 if (appData.icsActive)
1143 return "Mode.ICSClient";
1144 else if (appData.noChessProgram ||
1145 *appData.cmailGameName != NULLCHAR)
1146 return "Mode.EditGame";
1148 return "Mode.MachineBlack";
1149 case MachinePlaysBlack:
1150 return "Mode.MachineBlack";
1151 case MachinePlaysWhite:
1152 return "Mode.MachineWhite";
1154 return "Mode.AnalysisMode";
1156 return "Mode.AnalyzeFile";
1157 case TwoMachinesPlay:
1158 return "Mode.TwoMachines";
1160 return "Mode.EditGame";
1161 case PlayFromGameFile:
1162 return "File.LoadGame";
1164 return "Mode.EditPosition";
1166 return "Mode.Training";
1167 case IcsPlayingWhite:
1168 case IcsPlayingBlack:
1172 return "Mode.ICSClient";
1180 InstallNewEngine (char *command, char *dir, char *variants, char *protocol)
1181 { // install the given engine in XBoard's -firstChessProgramNames
1182 char buf[MSG_SIZ], *quote = "";
1183 if(strchr(command, ' ')) { // quoting needed
1184 if(!strchr(command, '"')) quote = "\""; else
1185 if(!strchr(command, '\'')) quote = "'"; else {
1186 printf("Could not auto-install %s\n", command); // too complex
1189 // construct engine line, with optional -fd and -fUCI arguments
1190 snprintf(buf, MSG_SIZ, "%s%s%s", quote, command, quote);
1191 if(strcmp(dir, "") && strcmp(dir, "."))
1192 snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fd %s", dir);
1193 if(!strcmp(protocol, "uci"))
1194 snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fUCI");
1195 if(strstr(firstChessProgramNames, buf)) return; // avoid duplicats
1197 quote = malloc(strlen(firstChessProgramNames) + strlen(buf) + 2);
1198 sprintf(quote, "%s%s\n", firstChessProgramNames, buf);
1199 FREE(firstChessProgramNames); firstChessProgramNames = quote;
1202 #ifdef HAVE_DIRENT_H
1205 #include <sys/dir.h>
1206 #define dirent direct
1210 InstallFromDir (char *dirName, char *protocol, char *settingsFile)
1211 { // scan system for new plugin specs in given directory
1214 struct stat statBuf;
1215 time_t lastSaved = 0;
1218 if(!stat(settingsFile, &statBuf)) lastSaved = statBuf.st_mtime;
1219 snprintf(buf, 1024, "%s/%s", dirName, protocol);
1221 if(!(dir = opendir(buf))) return;
1222 while( (dp = readdir(dir))) {
1223 time_t installed = 0;
1224 if(!strstr(dp->d_name, ".eng")) continue; // to suppress . and ..
1225 snprintf(buf, 1024, "%s/%s/%s", dirName, protocol, dp->d_name);
1226 if(!stat(buf, &statBuf)) installed = statBuf.st_mtime;
1227 if(lastSaved == 0 || (int) (installed - lastSaved) > 0) { // first time we see it
1228 FILE *f = fopen(buf, "r");
1229 if(f) { // read the plugin-specs
1230 char engineCommand[1024], engineDir[1024], variants[1024];
1231 char bad=0, dummy, *engineCom = engineCommand;
1233 if(fscanf(f, "plugin spec %d.%d%c", &major, &minor, &dummy) != 3 ||
1234 fscanf(f, "%[^\n]%c", engineCommand, &dummy) != 2 ||
1235 fscanf(f, "%[^\n]%c", variants, &dummy) != 2) bad = 1;
1238 // uncomment following two lines for chess-only installs
1239 // if(!(p = strstr(variants, "chess")) ||
1240 // p != variants && p[-1] != ',' || p[5] && p[5] != ',') continue;
1241 // split off engine working directory (if any)
1242 strcpy(engineDir, "");
1243 if(sscanf(engineCommand, "cd %[^;];%c", engineDir, &dummy) == 2)
1244 engineCom = engineCommand + strlen(engineDir) + 4;
1245 InstallNewEngine(engineCom, engineDir, variants, protocol);
1253 AutoInstallProtocol (char *settingsFile, char *protocol)
1254 { // install new engines for given protocol (both from package and source)
1255 InstallFromDir("/usr/local/share/games/plugins", protocol, settingsFile);
1256 InstallFromDir("/usr/share/games/plugins", protocol, settingsFile);
1260 AutoInstall (char *settingsFile)
1261 { // install all new XBoard and UCI engines
1262 AutoInstallProtocol(settingsFile, "xboard");
1263 AutoInstallProtocol(settingsFile, "uci");
1269 #ifndef OPTIONSDIALOG
1270 if (appData.alwaysPromoteToQueen) {
1271 MarkMenuItem("Options.Always Queen", True);
1273 if (appData.animateDragging) {
1274 MarkMenuItem("Options.Animate Dragging", True);
1276 if (appData.animate) {
1277 MarkMenuItem("Options.Animate Moving", True);
1279 if (appData.autoCallFlag) {
1280 MarkMenuItem("Options.Auto Flag", True);
1282 if (appData.autoFlipView) {
1283 XtSetValues(XtNameToWidget(menuBarWidget,"Options.Auto Flip View", True);
1285 if (appData.blindfold) {
1286 MarkMenuItem("Options.Blindfold", True);
1288 if (appData.flashCount > 0) {
1289 MarkMenuItem("Options.Flash Moves", True);
1292 if (appData.highlightDragging) {
1293 MarkMenuItem("Options.Highlight Dragging", True);
1296 if (appData.highlightLastMove) {
1297 MarkMenuItem("Options.Highlight Last Move", True);
1299 if (appData.highlightMoveWithArrow) {
1300 MarkMenuItem("Options.Arrow", True);
1302 // if (appData.icsAlarm) {
1303 // MarkMenuItem("Options.ICS Alarm", True);
1305 if (appData.ringBellAfterMoves) {
1306 MarkMenuItem("Options.Move Sound", True);
1308 if (appData.oneClick) {
1309 MarkMenuItem("Options.OneClick", True);
1311 if (appData.periodicUpdates) {
1312 MarkMenuItem("Options.Periodic Updates", True);
1314 if (appData.ponderNextMove) {
1315 MarkMenuItem("Options.Ponder Next Move", True);
1317 if (appData.popupExitMessage) {
1318 MarkMenuItem("Options.Popup Exit Message", True);
1320 if (appData.popupMoveErrors) {
1321 MarkMenuItem("Options.Popup Move Errors", True);
1323 // if (appData.premove) {
1324 // MarkMenuItem("Options.Premove", True);
1326 if (appData.showCoords) {
1327 MarkMenuItem("Options.Show Coords", True);
1329 if (appData.hideThinkingFromHuman) {
1330 MarkMenuItem("Options.Hide Thinking", True);
1332 if (appData.testLegality) {
1333 MarkMenuItem("Options.Test Legality", True);
1336 if (saveSettingsOnExit) {
1337 MarkMenuItem("Options.SaveSettingsonExit", True);
1339 EnableNamedMenuItem("File.SaveSelected", False);
1341 // all XBoard builds get here, but not WinBoard...
1342 if(*appData.autoInstall) AutoInstall(settingsFileName);