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 Free Software Foundation, Inc.
10 * The following terms apply to Digital Equipment Corporation's copyright
12 * ------------------------------------------------------------------------
15 * Permission to use, copy, modify, and distribute this software and its
16 * documentation for any purpose and without fee is hereby granted,
17 * provided that the above copyright notice appear in all copies and that
18 * both that copyright notice and this permission notice appear in
19 * supporting documentation, and that the name of Digital not be
20 * used in advertising or publicity pertaining to distribution of the
21 * software without specific, written prior permission.
23 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
25 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
26 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
30 * ------------------------------------------------------------------------
32 * The following terms apply to the enhanced version of XBoard
33 * distributed by the Free Software Foundation:
34 * ------------------------------------------------------------------------
36 * GNU XBoard is free software: you can redistribute it and/or modify
37 * it under the terms of the GNU General Public License as published by
38 * the Free Software Foundation, either version 3 of the License, or (at
39 * your option) any later version.
41 * GNU XBoard is distributed in the hope that it will be useful, but
42 * WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44 * General Public License for more details.
46 * You should have received a copy of the GNU General Public License
47 * along with this program. If not, see http://www.gnu.org/licenses/. *
49 *------------------------------------------------------------------------
50 ** See the file ChangeLog for a revision history. */
60 #include <sys/types.h>
68 #else /* not STDC_HEADERS */
69 extern char *getenv();
72 # else /* not HAVE_STRING_H */
74 # endif /* not HAVE_STRING_H */
75 #endif /* not STDC_HEADERS */
85 // [HGM] bitmaps: put before incuding the bitmaps / pixmaps, to know how many piece types there are.
94 # define _(s) gettext (s)
95 # define N_(s) gettext_noop (s)
102 * Button/menu procedures
105 char *gameCopyFilename, *gamePasteFilename;
106 Boolean saveSettingsOnExit;
107 char *settingsFileName;
108 char gamesDir[MSG_SIZ], positionsDir[MSG_SIZ], textureDir[MSG_SIZ], bookDir[MSG_SIZ], piecesDir[MSG_SIZ];
111 LoadGamePopUp (FILE *f, int gameNumber, char *title)
113 cmailMsgLoaded = FALSE;
114 if (gameNumber == 0) {
115 int error = GameListBuild(f);
117 DisplayError(_("Cannot build game list"), error);
118 } else if (!ListEmpty(&gameList) &&
119 ((ListGame *) gameList.tailPred)->number > 1) {
120 GameListPopUp(f, title);
126 return LoadGame(f, gameNumber, title, FALSE);
132 if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
135 FileNamePopUp(_("Load game file name?"), "", ".pgn .game", LoadGamePopUp, "rb");
157 LoadNextPositionProc ()
163 LoadPrevPositionProc ()
169 ReloadPositionProc ()
177 static char buf[MSG_SIZ];
178 if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
181 snprintf(buf, MSG_SIZ, "%s/", appData.positionDir);
182 FileNamePopUp(_("Load position file name?"), buf, ".fen .epd .pos", LoadPosition, "rb");
188 FileNamePopUp(_("Save game file name?"),
189 DefaultFileName(appData.oldSaveStyle ? "game" : "pgn"),
190 appData.oldSaveStyle ? ".game" : ".pgn",
197 FileNamePopUp(_("Save position file name?"),
198 DefaultFileName(appData.oldSaveStyle ? "pos" : "fen"),
199 appData.oldSaveStyle ? ".pos" : ".fen",
204 ReloadCmailMsgProc ()
206 ReloadCmailMsgEvent(FALSE);
210 CopyFENToClipboard ()
211 { // wrapper to make call from back-end possible
218 static char *selected_fen_position=NULL;
219 if(gameMode == EditPosition) EditPositionDone(TRUE);
220 if (selected_fen_position) free(selected_fen_position);
221 selected_fen_position = (char *)PositionToFEN(currentMove, NULL, 1);
222 if (!selected_fen_position) return;
223 CopySomething(selected_fen_position);
231 ret = SaveGameToFile(gameCopyFilename, FALSE);
240 if(!SaveGameListAsText(fopen(gameCopyFilename, "w"))) return;
266 UserAdjudicationEvent(+1);
272 UserAdjudicationEvent(-1);
278 UserAdjudicationEvent(0);
296 if(twoBoards) { partnerUp = 1; DrawPosition(True, NULL); partnerUp = 0; }
297 flipView = !flipView;
298 DrawPosition(True, NULL);
304 saveSettingsOnExit = !saveSettingsOnExit;
306 MarkMenuItem("Options.SaveSettingsonExit", saveSettingsOnExit);
312 SaveSettings(settingsFileName);
319 snprintf(buf, MSG_SIZ, "%s mailto:bug-xboard@gnu.org", appData.sysOpen);
327 snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/user_guide/UserGuide.html", appData.sysOpen);
335 snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/", appData.sysOpen);
343 snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/whats_new/portal.html", appData.sysOpen);
350 char buf[2 * MSG_SIZ];
352 char *zippy = _(" (with Zippy code)");
356 snprintf(buf, sizeof(buf),
358 "Copyright 1991 Digital Equipment Corporation\n"
359 "Enhancements Copyright 1992-2015 Free Software Foundation\n"
360 "Enhancements Copyright 2005 Alessandro Scotti\n\n"
361 "%s is free software and carries NO WARRANTY;"
362 "see the file COPYING for more information.\n"
363 "The GTK build of this version is experimental and unstable\n\n"
364 "Visit XBoard on the web at: http://www.gnu.org/software/xboard/\n"
365 "Check out the newest features at: http://www.gnu.org/software/xboard/whats_new.html\n\n"
366 "Report bugs via email at: <bug-xboard@gnu.org>\n\n"
368 programVersion, zippy, PACKAGE);
369 ErrorPopUp(_("About XBoard"), buf, FALSE);
375 appData.debugMode = !appData.debugMode;
376 if(!strcmp(appData.nameOfDebugFile, "stderr")) return; // stderr is already open, and should never be closed
377 if(!appData.debugMode) fclose(debugFP);
379 debugFP = fopen(appData.nameOfDebugFile, "w");
380 if(debugFP == NULL) debugFP = stderr;
381 else setbuf(debugFP, NULL);
388 EditTagsPopUp(firstChessProgramNames, &firstChessProgramNames);
398 # define MARK_MENU_ITEM(X,Y)
400 # define MARK_MENU_ITEM(X,Y) MarkMenuItem(X, Y)
404 PonderNextMoveProc ()
406 PonderNextMoveEvent(!appData.ponderNextMove);
407 MARK_MENU_ITEM("Options.PonderNextMove", appData.ponderNextMove);
413 appData.alwaysPromoteToQueen = !appData.alwaysPromoteToQueen;
414 MARK_MENU_ITEM("Options.AlwaysQueen", appData.alwaysPromoteToQueen);
418 AnimateDraggingProc ()
420 appData.animateDragging = !appData.animateDragging;
422 if (appData.animateDragging) CreateAnimVars();
423 MARK_MENU_ITEM("Options.AnimateDragging", appData.animateDragging);
429 appData.animate = !appData.animate;
430 if (appData.animate) CreateAnimVars();
431 MARK_MENU_ITEM("Options.AnimateMoving", appData.animate);
437 appData.autoCallFlag = !appData.autoCallFlag;
438 MARK_MENU_ITEM("Options.AutoFlag", appData.autoCallFlag);
444 appData.autoFlipView = !appData.autoFlipView;
445 MARK_MENU_ITEM("Options.AutoFlipView", appData.autoFlipView);
451 appData.blindfold = !appData.blindfold;
452 MARK_MENU_ITEM("Options.Blindfold", appData.blindfold);
453 DrawPosition(True, NULL);
459 appData.testLegality = !appData.testLegality;
460 MARK_MENU_ITEM("Options.TestLegality", appData.testLegality);
467 if (appData.flashCount == 0) {
468 appData.flashCount = 3;
470 appData.flashCount = -appData.flashCount;
472 MARK_MENU_ITEM("Options.FlashMoves", appData.flashCount > 0);
477 HighlightDraggingProc ()
479 appData.highlightDragging = !appData.highlightDragging;
480 MARK_MENU_ITEM("Options.HighlightDragging", appData.highlightDragging);
485 HighlightLastMoveProc ()
487 appData.highlightLastMove = !appData.highlightLastMove;
488 MARK_MENU_ITEM("Options.HighlightLastMove", appData.highlightLastMove);
492 HighlightArrowProc ()
494 appData.highlightMoveWithArrow = !appData.highlightMoveWithArrow;
495 MARK_MENU_ITEM("Options.HighlightWithArrow", appData.highlightMoveWithArrow);
501 appData.icsAlarm = !appData.icsAlarm;
502 // MARK_MENU_ITEM("Options.ICSAlarm", appData.icsAlarm);
508 appData.ringBellAfterMoves = !appData.ringBellAfterMoves;
509 MARK_MENU_ITEM("Options.MoveSound", appData.ringBellAfterMoves);
515 appData.oneClick = !appData.oneClick;
516 MARK_MENU_ITEM("Options.OneClickMoving", appData.oneClick);
520 PeriodicUpdatesProc ()
522 PeriodicUpdatesEvent(!appData.periodicUpdates);
523 MARK_MENU_ITEM("Options.PeriodicUpdates", appData.periodicUpdates);
527 PopupExitMessageProc ()
529 appData.popupExitMessage = !appData.popupExitMessage;
530 MARK_MENU_ITEM("Options.PopupExitMessage", appData.popupExitMessage);
534 PopupMoveErrorsProc ()
536 appData.popupMoveErrors = !appData.popupMoveErrors;
537 MARK_MENU_ITEM("Options.PopupMoveErrors", appData.popupMoveErrors);
543 appData.premove = !appData.premove;
544 // MARK_MENU_ITEM("Options.Premove", appData.premove);
550 appData.showCoords = !appData.showCoords;
551 MARK_MENU_ITEM("Options.ShowCoords", appData.showCoords);
552 DrawPosition(True, NULL);
558 appData.showThinking = !appData.showThinking; // [HGM] thinking: taken out of ShowThinkingEvent
565 appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman; // [HGM] thinking: taken out of ShowThinkingEvent
568 MARK_MENU_ITEM("Options.HideThinking", appData.hideThinkingFromHuman);
574 ScheduleDelayedEvent(CreateBookEvent, 50);
580 FileNamePopUp(_("Save game file name?"),
587 * Menu definition tables
590 MenuItem fileMenu[] = {
591 {N_("New Game"), "<Ctrl>n", "NewGame", ResetGameEvent},
592 {N_("New Shuffle Game..."), NULL, "NewShuffleGame", ShuffleMenuProc},
593 {N_("New Variant..."), "<Alt><Shift>v", "NewVariant", NewVariantProc},// [HGM] variant: not functional yet
594 {"----", NULL, NULL, NothingProc},
595 {N_("Load Game"), "<Ctrl>o", "LoadGame", LoadGameProc, CHECK},
596 {N_("Load Position"), "<Ctrl><Shift>o", "LoadPosition", LoadPositionProc},
597 {N_("Next Position"), "<Shift>Page_Down", "LoadNextPosition", LoadNextPositionProc},
598 {N_("Prev Position"), "<Shift>Page_Up", "LoadPreviousPosition", LoadPrevPositionProc},
599 {"----", NULL, NULL, NothingProc},
600 {N_("Save Game"), "<Ctrl>s", "SaveGame", SaveGameProc},
601 {N_("Save Position"), "<Ctrl><Shift>s", "SavePosition", SavePositionProc},
602 {N_("Save Selected Games"), NULL, "SaveSelected", SaveSelectedProc},
603 {N_("Save Games as Book"), NULL, "CreateBook", CreateBookDelayed},
604 {"----", NULL, NULL, NothingProc},
605 {N_("Mail Move"), NULL, "MailMove", MailMoveEvent},
606 {N_("Reload CMail Message"), NULL, "ReloadCMailMessage", ReloadCmailMsgProc},
607 {"----", NULL, NULL, NothingProc},
608 {N_("Quit "), "<Ctrl>q", "Quit", QuitProc},
609 {NULL, NULL, NULL, NULL}
612 MenuItem editMenu[] = {
613 {N_("Copy Game"), "<Ctrl>c", "CopyGame", CopyGameProc},
614 {N_("Copy Position"), "<Ctrl><Shift>c", "CopyPosition", CopyPositionProc},
615 {N_("Copy Game List"), NULL, "CopyGameList", CopyGameListProc},
616 {"----", NULL, NULL, NothingProc},
617 {N_("Paste Game"), "<Ctrl>v", "PasteGame", PasteGameProc},
618 {N_("Paste Position"), "<Ctrl><Shift>v", "PastePosition", PastePositionProc},
619 {"----", NULL, NULL, NothingProc},
620 {N_("Edit Game"), "<Ctrl>e", "EditGame", EditGameEvent},
621 {N_("Edit Position"), "<Ctrl><Shift>e", "EditPosition", EditPositionEvent},
622 {N_("Edit Tags"), NULL, "EditTags", EditTagsProc},
623 {N_("Edit Comment"), NULL, "EditComment", EditCommentProc},
624 {N_("Edit Book"), NULL, "EditBook", EditBookEvent},
625 {"----", NULL, NULL, NothingProc},
626 {N_("Revert"), "Home", "Revert", RevertProc},
627 {N_("Annotate"), NULL, "Annotate", AnnotateProc},
628 {N_("Truncate Game"), "End", "TruncateGame", TruncateGameEvent},
629 {"----", NULL, NULL, NothingProc},
630 {N_("Backward"), "<Alt>Left", "Backward", BackwardEvent},
631 {N_("Forward"), "<Alt>Right", "Forward", ForwardEvent},
632 {N_("Back to Start"), "<Alt>Home", "BacktoStart", ToStartEvent},
633 {N_("Forward to End"), "<Alt>End", "ForwardtoEnd", ToEndEvent},
634 {NULL, NULL, NULL, NULL}
637 MenuItem viewMenu[] = {
638 {N_("Flip View"), "F2", "FlipView", FlipViewProc, CHECK},
639 {"----", NULL, NULL, NothingProc},
640 {N_("Engine Output"), "<Alt><Shift>o", "EngineOutput", EngineOutputProc, CHECK},
641 {N_("Move History"), "<Alt><Shift>h", "MoveHistory", HistoryShowProc, CHECK}, // [HGM] hist: activate 4.2.7 code
642 {N_("Evaluation Graph"), "<Alt><Shift>e", "EvaluationGraph", EvalGraphProc, CHECK},
643 {N_("Game List"), "<Alt><Shift>g", "GameList", ShowGameListProc, CHECK},
644 {N_("ICS text menu"), NULL, "ICStextmenu", IcsTextProc, CHECK},
645 {"----", NULL, NULL, NothingProc},
646 {N_("Tags"), NULL, "Tags", EditTagsProc, CHECK},
647 {N_("Comments"), NULL, "Comments", EditCommentProc, CHECK},
648 {N_("ICS Input Box"), NULL, "ICSInputBox", IcsInputBoxProc, CHECK},
649 {N_("ICS/Chat Console"), NULL, "OpenChatWindow", ChatProc, CHECK},
650 {"----", NULL, NULL, NothingProc},
651 {N_("Board..."), NULL, "Board", BoardOptionsProc},
652 {N_("Game List Tags..."), NULL, "GameListTags", GameListOptionsProc},
653 {NULL, NULL, NULL, NULL}
656 MenuItem modeMenu[] = {
657 {N_("Machine White"), "<Ctrl>w", "MachineWhite", MachineWhiteEvent, RADIO },
658 {N_("Machine Black"), "<Ctrl>b", "MachineBlack", MachineBlackEvent, RADIO },
659 {N_("Two Machines"), "<Ctrl>t", "TwoMachines", TwoMachinesEvent, RADIO },
660 {N_("Analysis Mode"), "<Ctrl>a", "AnalysisMode", (MenuProc*) AnalyzeModeEvent, RADIO },
661 {N_("Analyze Game"), "<Ctrl>g", "AnalyzeFile", AnalyzeFileEvent, RADIO },
662 {N_("Edit Game"), "<Ctrl>e", "EditGame", EditGameEvent, RADIO },
663 {N_("Edit Position"), "<Ctrl><Shift>e", "EditPosition", EditPositionEvent, RADIO },
664 {N_("Training"), NULL, "Training", TrainingEvent, RADIO },
665 {N_("ICS Client"), NULL, "ICSClient", IcsClientEvent, RADIO },
666 {"----", NULL, NULL, NothingProc},
667 {N_("Machine Match"), NULL, "MachineMatch", MatchProc, CHECK },
668 {N_("Pause"), "Pause", "Pause", PauseEvent, CHECK },
669 {NULL, NULL, NULL, NULL}
672 MenuItem actionMenu[] = {
673 {N_("Accept"), "F3", "Accept", AcceptEvent},
674 {N_("Decline"), "F4", "Decline", DeclineEvent},
675 {N_("Rematch"), "F12", "Rematch", RematchEvent},
676 {"----", NULL, NULL, NothingProc},
677 {N_("Call Flag"), "F5", "CallFlag", CallFlagEvent},
678 {N_("Draw"), "F6", "Draw", DrawEvent},
679 {N_("Adjourn"), "F7", "Adjourn", AdjournEvent},
680 {N_("Abort"), "F8", "Abort", AbortEvent},
681 {N_("Resign"), "F9", "Resign", ResignEvent},
682 {"----", NULL, NULL, NothingProc},
683 {N_("Stop Observing"), "F10", "StopObserving", StopObservingEvent},
684 {N_("Stop Examining"), "F11", "StopExamining", StopExaminingEvent},
685 {N_("Upload to Examine"), NULL, "UploadtoExamine", UploadGameEvent},
686 {"----", NULL, NULL, NothingProc},
687 {N_("Adjudicate to White"), NULL, "AdjudicatetoWhite", AdjuWhiteProc},
688 {N_("Adjudicate to Black"), NULL, "AdjudicatetoBlack", AdjuBlackProc},
689 {N_("Adjudicate Draw"), NULL, "AdjudicateDraw", AdjuDrawProc},
690 {NULL, NULL, NULL, NULL}
693 MenuItem engineMenu[100] = {
694 {N_("Edit Engine List..."), NULL, "EditEngList", EditEngineProc},
695 {"----", NULL, NULL, NothingProc},
696 {N_("Load New 1st Engine..."), NULL, "LoadNew1stEngine", LoadEngine1Proc},
697 {N_("Load New 2nd Engine..."), NULL, "LoadNew2ndEngine", LoadEngine2Proc},
698 {"----", NULL, NULL, NothingProc},
699 {N_("Engine #1 Settings..."), NULL, "Engine#1Settings", FirstSettingsProc},
700 {N_("Engine #2 Settings..."), NULL, "Engine#2Settings", SecondSettingsProc},
701 {"----", NULL, NULL, NothingProc},
702 {N_("Hint"), NULL, "Hint", HintEvent},
703 {N_("Book"), NULL, "Book", BookEvent},
704 {"----", NULL, NULL, NothingProc},
705 {N_("Move Now"), "<Ctrl>m", "MoveNow", MoveNowEvent},
706 {N_("Retract Move"), "<Ctrl>x", "RetractMove", RetractMoveEvent},
707 {NULL, NULL, NULL, NULL}
710 MenuItem optionsMenu[] = {
712 {N_("General..."), NULL, "General", OptionsProc},
714 {N_("Time Control..."), "<Alt><Shift>t", "TimeControl", TimeControlProc},
715 {N_("Common Engine..."), "<Alt><Shift>u", "CommonEngine", UciMenuProc},
716 {N_("Adjudications..."), "<Alt><Shift>j", "Adjudications", EngineMenuProc},
717 {N_("ICS..."), NULL, "ICS", IcsOptionsProc},
718 {N_("Tournament..."), NULL, "Match", MatchOptionsProc},
719 {N_("Load Game..."), NULL, "LoadGame", LoadOptionsProc},
720 {N_("Save Game..."), NULL, "SaveGame", SaveOptionsProc},
721 {N_("Game List..."), NULL, "GameList", GameListOptionsProc},
722 {N_("Sounds..."), NULL, "Sounds", SoundOptionsProc},
723 {"----", NULL, NULL, NothingProc},
724 #ifndef OPTIONSDIALOG
725 {N_("Always Queen"), "<Ctrl><Shift>q", "AlwaysQueen", AlwaysQueenProc},
726 {N_("Animate Dragging"), NULL, "AnimateDragging", AnimateDraggingProc},
727 {N_("Animate Moving"), "<Ctrl><Shift>a", "AnimateMoving", AnimateMovingProc},
728 {N_("Auto Flag"), "<Ctrl><Shift>f", "AutoFlag", AutoflagProc},
729 {N_("Auto Flip View"), NULL, "AutoFlipView", AutoflipProc},
730 {N_("Blindfold"), NULL, "Blindfold", BlindfoldProc},
731 {N_("Flash Moves"), NULL, "FlashMoves", FlashMovesProc},
733 {N_("Highlight Dragging"), NULL, "HighlightDragging", HighlightDraggingProc},
735 {N_("Highlight Last Move"), NULL, "HighlightLastMove", HighlightLastMoveProc},
736 {N_("Highlight With Arrow"), NULL, "HighlightWithArrow", HighlightArrowProc},
737 {N_("Move Sound"), NULL, "MoveSound", MoveSoundProc},
738 {N_("One-Click Moving"), NULL, "OneClickMoving", OneClickProc},
739 {N_("Periodic Updates"), NULL, "PeriodicUpdates", PeriodicUpdatesProc},
740 {N_("Ponder Next Move"), "<Ctrl><Shift>p", "PonderNextMove", PonderNextMoveProc},
741 {N_("Popup Exit Message"), NULL, "PopupExitMessage", PopupExitMessageProc},
742 {N_("Popup Move Errors"), NULL, "PopupMoveErrors", PopupMoveErrorsProc},
743 {N_("Show Coords"), NULL, "ShowCoords", ShowCoordsProc},
744 {N_("Hide Thinking"), "<Ctrl><Shift>h", "HideThinking", HideThinkingProc},
745 {N_("Test Legality"), "<Ctrl><Shift>l", "TestLegality", TestLegalityProc},
746 {"----", NULL, NULL, NothingProc},
748 {N_("Save Settings Now"), NULL, "SaveSettingsNow", SaveSettingsProc},
749 {N_("Save Settings on Exit"), NULL, "SaveSettingsonExit", SaveOnExitProc, CHECK },
750 {NULL, NULL, NULL, NULL}
753 MenuItem helpMenu[] = {
754 {N_("Info XBoard"), NULL, "InfoXBoard", InfoProc},
755 {N_("Man XBoard"), "F1", "ManXBoard", ManProc},
756 {"----", NULL, NULL, NothingProc},
757 {N_("XBoard Home Page"), NULL, "XBoardHomePage", HomePageProc},
758 {N_("On-line User Guide"), NULL, "On-lineUserGuide", GuideProc},
759 {N_("Development News"), NULL, "DevelopmentNews", NewsPageProc},
760 {N_("e-Mail Bug Report"), NULL, "e-MailBugReport", BugReportProc},
761 {"----", NULL, NULL, NothingProc},
762 {N_("About XBoard"), NULL, "AboutXBoard", AboutProc},
763 {NULL, NULL, NULL, NULL}
766 MenuItem noMenu[] = {
767 { "", "<Alt>Next" ,"LoadNextGame", LoadNextGameProc },
768 { "", "<Alt>Prior" ,"LoadPrevGame", LoadPrevGameProc },
769 { "", NULL,"ReloadGame", ReloadGameProc },
770 { "", NULL,"ReloadPosition", ReloadPositionProc },
771 #ifndef OPTIONSDIALOG
772 { "", NULL,"AlwaysQueen", AlwaysQueenProc },
773 { "", NULL,"AnimateDragging", AnimateDraggingProc },
774 { "", NULL,"AnimateMoving", AnimateMovingProc },
775 { "", NULL,"Autoflag", AutoflagProc },
776 { "", NULL,"Autoflip", AutoflipProc },
777 { "", NULL,"Blindfold", BlindfoldProc },
778 { "", NULL,"FlashMoves", FlashMovesProc },
780 { "", NULL,"HighlightDragging", HighlightDraggingProc },
782 { "", NULL,"HighlightLastMove", HighlightLastMoveProc },
783 { "", NULL,"MoveSound", MoveSoundProc },
784 { "", NULL,"PeriodicUpdates", PeriodicUpdatesProc },
785 { "", NULL,"PopupExitMessage", PopupExitMessageProc },
786 { "", NULL,"PopupMoveErrors", PopupMoveErrorsProc },
787 { "", NULL,"ShowCoords", ShowCoordsProc },
788 { "", NULL,"ShowThinking", ShowThinkingProc },
789 { "", NULL,"HideThinking", HideThinkingProc },
790 { "", NULL,"TestLegality", TestLegalityProc },
792 { "", NULL,"AboutGame", AboutGameEvent },
793 { "", "<Ctrl>d" ,"DebugProc", DebugProc },
794 { "", NULL,"Nothing", NothingProc },
795 {NULL, NULL, NULL, NULL}
799 {N_("File"), "File", fileMenu},
800 {N_("Edit"), "Edit", editMenu},
801 {N_("View"), "View", viewMenu},
802 {N_("Mode"), "Mode", modeMenu},
803 {N_("Action"), "Action", actionMenu},
804 {N_("Engine"), "Engine", engineMenu},
805 {N_("Options"), "Options", optionsMenu},
806 {N_("Help"), "Help", helpMenu},
808 { "", "None", noMenu}
812 MenuNameToItem (char *menuName)
815 char buf[MSG_SIZ], *p;
817 static MenuItem a = { NULL, NULL, NULL, NothingProc };
818 extern Option mainOptions[];
819 safeStrCpy(buf, menuName, MSG_SIZ);
820 p = strchr(buf, '.');
821 if(!p) menuTab = noMenu, p = menuName; else {
823 for(i=0; menuBar[i].name; i++)
824 if(!strcmp(buf, menuBar[i].name)) break;
825 if(!menuBar[i].name) return NULL; // main menu not found
826 menuTab = menuBar[i].mi;
828 if(*p == NULLCHAR) { a.handle = mainOptions[i+1].handle; return &a; } // main menu bar
829 for(i=0; menuTab[i].string; i++)
830 if(menuTab[i].ref && !strcmp(p, menuTab[i].ref)) return menuTab + i;
831 return NULL; // item not found
837 AppendEnginesToMenu (char *list)
841 if(appData.icsActive || appData.recentEngines <= 0) return;
842 for(firstEngineItem=0; engineMenu[firstEngineItem].string; firstEngineItem++);
843 recentEngines = strdup(list);
845 p = strchr(list, '\n'); if(p == NULL) break;
846 if(i == 0) engineMenu[firstEngineItem++].string = "----"; // at least one valid item to add
848 if(firstEngineItem + i < 99)
849 engineMenu[firstEngineItem+i].string = strdup(list); // just set name; MenuProc stays NULL
850 i++; *p = '\n'; list = p + 1;
854 Enables icsEnables[] = {
855 { "File.MailMove", False },
856 { "File.ReloadCMailMessage", False },
857 { "Mode.MachineBlack", False },
858 { "Mode.MachineWhite", False },
859 { "Mode.AnalysisMode", False },
860 { "Mode.AnalyzeFile", False },
861 { "Mode.TwoMachines", False },
862 { "Mode.MachineMatch", False },
864 { "Engine.Hint", False },
865 { "Engine.Book", False },
866 { "Engine.MoveNow", False },
867 #ifndef OPTIONSDIALOG
868 { "PeriodicUpdates", False },
869 { "HideThinking", False },
870 { "PonderNextMove", False },
873 { "Engine.Engine#1Settings", False },
874 { "Engine.Engine#2Settings", False },
875 { "Engine.Load1stEngine", False },
876 { "Engine.Load2ndEngine", False },
877 { "Edit.Annotate", False },
878 { "Options.Match", False },
882 Enables ncpEnables[] = {
883 { "File.MailMove", False },
884 { "File.ReloadCMailMessage", False },
885 { "Mode.MachineWhite", False },
886 { "Mode.MachineBlack", False },
887 { "Mode.AnalysisMode", False },
888 { "Mode.AnalyzeFile", False },
889 { "Mode.TwoMachines", False },
890 { "Mode.MachineMatch", False },
891 { "Mode.ICSClient", False },
892 { "View.ICStextmenu", False },
893 { "View.ICSInputBox", False },
894 { "View.OpenChatWindow", False },
895 { "Action.", False },
896 { "Edit.Revert", False },
897 { "Edit.Annotate", False },
898 { "Engine.Engine#1Settings", False },
899 { "Engine.Engine#2Settings", False },
900 { "Engine.MoveNow", False },
901 { "Engine.RetractMove", False },
902 { "Options.ICS", False },
903 #ifndef OPTIONSDIALOG
904 { "Options.AutoFlag", False },
905 { "Options.AutoFlip View", False },
906 // { "Options.ICSAlarm", False },
907 { "Options.MoveSound", False },
908 { "Options.HideThinking", False },
909 { "Options.PeriodicUpdates", False },
910 { "Options.PonderNextMove", False },
912 { "Engine.Hint", False },
913 { "Engine.Book", False },
917 Enables gnuEnables[] = {
918 { "Mode.ICSClient", False },
919 { "View.ICStextmenu", False },
920 { "View.ICSInputBox", False },
921 { "View.OpenChatWindow", False },
922 { "Action.Accept", False },
923 { "Action.Decline", False },
924 { "Action.Rematch", False },
925 { "Action.Adjourn", False },
926 { "Action.StopExamining", False },
927 { "Action.StopObserving", False },
928 { "Action.UploadtoExamine", False },
929 { "Edit.Revert", False },
930 { "Edit.Annotate", False },
931 { "Options.ICS", False },
933 /* The next two options rely on SetCmailMode being called *after* */
934 /* SetGNUMode so that when GNU is being used to give hints these */
935 /* menu options are still available */
937 { "File.MailMove", False },
938 { "File.ReloadCMailMessage", False },
939 // [HGM] The following have been added to make a switch from ncp to GNU mode possible
940 { "Mode.MachineWhite", True },
941 { "Mode.MachineBlack", True },
942 { "Mode.AnalysisMode", True },
943 { "Mode.AnalyzeFile", True },
944 { "Mode.TwoMachines", True },
945 { "Mode.MachineMatch", True },
946 { "Engine.Engine#1Settings", True },
947 { "Engine.Engine#2Settings", True },
948 { "Engine.Hint", True },
949 { "Engine.Book", True },
950 { "Engine.MoveNow", True },
951 { "Engine.RetractMove", True },
956 Enables cmailEnables[] = {
958 { "Action.CallFlag", False },
959 { "Action.Draw", True },
960 { "Action.Adjourn", False },
961 { "Action.Abort", False },
962 { "Action.StopObserving", False },
963 { "Action.StopExamining", False },
964 { "File.MailMove", True },
965 { "File.ReloadCMailMessage", True },
969 Enables trainingOnEnables[] = {
970 { "Edit.EditComment", False },
971 { "Mode.Pause", False },
972 { "Edit.Forward", False },
973 { "Edit.Backward", False },
974 { "Edit.ForwardtoEnd", False },
975 { "Edit.BacktoStart", False },
976 { "Engine.MoveNow", False },
977 { "Edit.TruncateGame", False },
981 Enables trainingOffEnables[] = {
982 { "Edit.EditComment", True },
983 { "Mode.Pause", True },
984 { "Edit.Forward", True },
985 { "Edit.Backward", True },
986 { "Edit.ForwardtoEnd", True },
987 { "Edit.BacktoStart", True },
988 { "Engine.MoveNow", True },
989 { "Engine.TruncateGame", True },
993 Enables machineThinkingEnables[] = {
994 { "File.LoadGame", False },
995 // { "LoadNextGame", False },
996 // { "LoadPreviousGame", False },
997 // { "ReloadSameGame", False },
998 { "Edit.PasteGame", False },
999 { "File.LoadPosition", False },
1000 // { "LoadNextPosition", False },
1001 // { "LoadPreviousPosition", False },
1002 // { "ReloadSamePosition", False },
1003 { "Edit.PastePosition", False },
1004 { "Mode.MachineWhite", False },
1005 { "Mode.MachineBlack", False },
1006 { "Mode.TwoMachines", False },
1007 // { "MachineMatch", False },
1008 { "Engine.RetractMove", False },
1012 Enables userThinkingEnables[] = {
1013 { "File.LoadGame", True },
1014 // { "LoadNextGame", True },
1015 // { "LoadPreviousGame", True },
1016 // { "ReloadSameGame", True },
1017 { "Edit.PasteGame", True },
1018 { "File.LoadPosition", True },
1019 // { "LoadNextPosition", True },
1020 // { "LoadPreviousPosition", True },
1021 // { "ReloadSamePosition", True },
1022 { "Edit.PastePosition", True },
1023 { "Mode.MachineWhite", True },
1024 { "Mode.MachineBlack", True },
1025 { "Mode.TwoMachines", True },
1026 // { "MachineMatch", True },
1027 { "Engine.RetractMove", True },
1034 SetMenuEnables(icsEnables);
1037 if (appData.zippyPlay && !appData.noChessProgram) { /* [DM] icsEngineAnalyze */
1038 EnableNamedMenuItem("Mode.AnalysisMode", True);
1039 EnableNamedMenuItem("Engine.Engine#1Settings", True);
1047 SetMenuEnables(ncpEnables);
1053 SetMenuEnables(gnuEnables);
1059 SetMenuEnables(cmailEnables);
1063 SetTrainingModeOn ()
1065 SetMenuEnables(trainingOnEnables);
1066 if (appData.showButtonBar) {
1067 EnableButtonBar(False);
1073 SetTrainingModeOff ()
1075 SetMenuEnables(trainingOffEnables);
1076 if (appData.showButtonBar) {
1077 EnableButtonBar(True);
1082 SetUserThinkingEnables ()
1084 if (appData.noChessProgram) return;
1085 SetMenuEnables(userThinkingEnables);
1089 SetMachineThinkingEnables ()
1091 if (appData.noChessProgram) return;
1092 SetMenuEnables(machineThinkingEnables);
1094 case MachinePlaysBlack:
1095 case MachinePlaysWhite:
1096 case TwoMachinesPlay:
1097 EnableNamedMenuItem(ModeToWidgetName(gameMode), True);
1105 GreyRevert (Boolean grey)
1107 EnableNamedMenuItem("Edit.Revert", !grey);
1108 EnableNamedMenuItem("Edit.Annotate", !grey);
1112 ModeToWidgetName (GameMode mode)
1115 case BeginningOfGame:
1116 if (appData.icsActive)
1117 return "Mode.ICSClient";
1118 else if (appData.noChessProgram ||
1119 *appData.cmailGameName != NULLCHAR)
1120 return "Mode.EditGame";
1122 return "Mode.MachineBlack";
1123 case MachinePlaysBlack:
1124 return "Mode.MachineBlack";
1125 case MachinePlaysWhite:
1126 return "Mode.MachineWhite";
1128 return "Mode.AnalysisMode";
1130 return "Mode.AnalyzeFile";
1131 case TwoMachinesPlay:
1132 return "Mode.TwoMachines";
1134 return "Mode.EditGame";
1135 case PlayFromGameFile:
1136 return "File.LoadGame";
1138 return "Mode.EditPosition";
1140 return "Mode.Training";
1141 case IcsPlayingWhite:
1142 case IcsPlayingBlack:
1146 return "Mode.ICSClient";
1154 InstallNewEngine (char *command, char *dir, char *variants, char *protocol)
1155 { // install the given engine in XBoard's -firstChessProgramNames
1156 char buf[MSG_SIZ], *quote = "";
1157 if(strchr(command, ' ')) { // quoting needed
1158 if(!strchr(command, '"')) quote = "\""; else
1159 if(!strchr(command, '\'')) quote = "'"; else {
1160 printf("Could not auto-install %s\n", command); // too complex
1163 // construct engine line, with optional -fd and -fUCI arguments
1164 snprintf(buf, MSG_SIZ, "%s%s%s", quote, command, quote);
1165 if(strcmp(dir, "") && strcmp(dir, "."))
1166 snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fd %s", dir);
1167 if(!strcmp(protocol, "uci"))
1168 snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fUCI");
1169 if(strstr(firstChessProgramNames, buf)) return; // avoid duplicats
1171 quote = malloc(strlen(firstChessProgramNames) + strlen(buf) + 2);
1172 sprintf(quote, "%s%s\n", firstChessProgramNames, buf);
1173 FREE(firstChessProgramNames); firstChessProgramNames = quote;
1176 #ifdef HAVE_DIRENT_H
1179 #include <sys/dir.h>
1180 #define dirent direct
1184 InstallFromDir (char *dirName, char *protocol, char *settingsFile)
1185 { // scan system for new plugin specs in given directory
1188 struct stat statBuf;
1189 time_t lastSaved = 0;
1192 if(!stat(settingsFile, &statBuf)) lastSaved = statBuf.st_mtime;
1193 snprintf(buf, 1024, "%s/%s", dirName, protocol);
1195 if(!(dir = opendir(buf))) return;
1196 while( (dp = readdir(dir))) {
1197 time_t installed = 0;
1198 if(!strstr(dp->d_name, ".eng")) continue; // to suppress . and ..
1199 snprintf(buf, 1024, "%s/%s/%s", dirName, protocol, dp->d_name);
1200 if(!stat(buf, &statBuf)) installed = statBuf.st_mtime;
1201 if(lastSaved == 0 || (int) (installed - lastSaved) > 0) { // first time we see it
1202 FILE *f = fopen(buf, "r");
1203 if(f) { // read the plugin-specs
1204 char engineCommand[1024], engineDir[1024], variants[1024];
1205 char bad=0, dummy, *engineCom = engineCommand;
1207 if(fscanf(f, "plugin spec %d.%d%c", &major, &minor, &dummy) != 3 ||
1208 fscanf(f, "%[^\n]%c", engineCommand, &dummy) != 2 ||
1209 fscanf(f, "%[^\n]%c", variants, &dummy) != 2) bad = 1;
1212 // uncomment following two lines for chess-only installs
1213 // if(!(p = strstr(variants, "chess")) ||
1214 // p != variants && p[-1] != ',' || p[5] && p[5] != ',') continue;
1215 // split off engine working directory (if any)
1216 strcpy(engineDir, "");
1217 if(sscanf(engineCommand, "cd %[^;];%c", engineDir, &dummy) == 2)
1218 engineCom = engineCommand + strlen(engineDir) + 4;
1219 InstallNewEngine(engineCom, engineDir, variants, protocol);
1227 AutoInstallProtocol (char *settingsFile, char *protocol)
1228 { // install new engines for given protocol (both from package and source)
1229 InstallFromDir("/usr/local/share/games/plugins", protocol, settingsFile);
1230 InstallFromDir("/usr/share/games/plugins", protocol, settingsFile);
1234 AutoInstall (char *settingsFile)
1235 { // install all new XBoard and UCI engines
1236 AutoInstallProtocol(settingsFile, "xboard");
1237 AutoInstallProtocol(settingsFile, "uci");
1243 #ifndef OPTIONSDIALOG
1244 if (appData.alwaysPromoteToQueen) {
1245 MarkMenuItem("Options.Always Queen", True);
1247 if (appData.animateDragging) {
1248 MarkMenuItem("Options.Animate Dragging", True);
1250 if (appData.animate) {
1251 MarkMenuItem("Options.Animate Moving", True);
1253 if (appData.autoCallFlag) {
1254 MarkMenuItem("Options.Auto Flag", True);
1256 if (appData.autoFlipView) {
1257 XtSetValues(XtNameToWidget(menuBarWidget,"Options.Auto Flip View", True);
1259 if (appData.blindfold) {
1260 MarkMenuItem("Options.Blindfold", True);
1262 if (appData.flashCount > 0) {
1263 MarkMenuItem("Options.Flash Moves", True);
1266 if (appData.highlightDragging) {
1267 MarkMenuItem("Options.Highlight Dragging", True);
1270 if (appData.highlightLastMove) {
1271 MarkMenuItem("Options.Highlight Last Move", True);
1273 if (appData.highlightMoveWithArrow) {
1274 MarkMenuItem("Options.Arrow", True);
1276 // if (appData.icsAlarm) {
1277 // MarkMenuItem("Options.ICS Alarm", True);
1279 if (appData.ringBellAfterMoves) {
1280 MarkMenuItem("Options.Move Sound", True);
1282 if (appData.oneClick) {
1283 MarkMenuItem("Options.OneClick", True);
1285 if (appData.periodicUpdates) {
1286 MarkMenuItem("Options.Periodic Updates", True);
1288 if (appData.ponderNextMove) {
1289 MarkMenuItem("Options.Ponder Next Move", True);
1291 if (appData.popupExitMessage) {
1292 MarkMenuItem("Options.Popup Exit Message", True);
1294 if (appData.popupMoveErrors) {
1295 MarkMenuItem("Options.Popup Move Errors", True);
1297 // if (appData.premove) {
1298 // MarkMenuItem("Options.Premove", True);
1300 if (appData.showCoords) {
1301 MarkMenuItem("Options.Show Coords", True);
1303 if (appData.hideThinkingFromHuman) {
1304 MarkMenuItem("Options.Hide Thinking", True);
1306 if (appData.testLegality) {
1307 MarkMenuItem("Options.Test Legality", True);
1310 if (saveSettingsOnExit) {
1311 MarkMenuItem("Options.SaveSettingsonExit", True);
1313 EnableNamedMenuItem("File.SaveSelected", False);
1315 // all XBoard builds get here, but not WinBoard...
1316 if(*appData.autoInstall) AutoInstall(settingsFileName);