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 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 if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
180 FileNamePopUp(_("Load position file name?"), "", ".fen .epd .pos", LoadPosition, "rb");
186 FileNamePopUp(_("Save game file name?"),
187 DefaultFileName(appData.oldSaveStyle ? "game" : "pgn"),
188 appData.oldSaveStyle ? ".game" : ".pgn",
195 FileNamePopUp(_("Save position file name?"),
196 DefaultFileName(appData.oldSaveStyle ? "pos" : "fen"),
197 appData.oldSaveStyle ? ".pos" : ".fen",
202 ReloadCmailMsgProc ()
204 ReloadCmailMsgEvent(FALSE);
208 CopyFENToClipboard ()
209 { // wrapper to make call from back-end possible
216 static char *selected_fen_position=NULL;
217 if(gameMode == EditPosition) EditPositionDone(TRUE);
218 if (selected_fen_position) free(selected_fen_position);
219 selected_fen_position = (char *)PositionToFEN(currentMove, NULL, 1);
220 if (!selected_fen_position) return;
221 CopySomething(selected_fen_position);
229 ret = SaveGameToFile(gameCopyFilename, FALSE);
238 if(!SaveGameListAsText(fopen(gameCopyFilename, "w"))) return;
264 UserAdjudicationEvent(+1);
270 UserAdjudicationEvent(-1);
276 UserAdjudicationEvent(0);
294 if(twoBoards) { partnerUp = 1; DrawPosition(True, NULL); partnerUp = 0; }
295 flipView = !flipView;
296 DrawPosition(True, NULL);
302 saveSettingsOnExit = !saveSettingsOnExit;
304 MarkMenuItem("Options.SaveSettingsonExit", saveSettingsOnExit);
310 SaveSettings(settingsFileName);
318 snprintf(buf, MSG_SIZ, "%s ./info.command", appData.sysOpen);
320 snprintf(buf, sizeof(buf), "xterm -e info --directory %s --directory . -f %s &",
330 snprintf(buf, MSG_SIZ, "%s mailto:bug-xboard@gnu.org", appData.sysOpen);
338 snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/user_guide/UserGuide.html", appData.sysOpen);
346 snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/", appData.sysOpen);
354 snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/whats_new/portal.html", appData.sysOpen);
361 char buf[2 * MSG_SIZ];
363 char *zippy = _(" (with Zippy code)");
367 snprintf(buf, sizeof(buf),
369 "Copyright 1991 Digital Equipment Corporation\n"
370 "Enhancements Copyright 1992-2014 Free Software Foundation\n"
371 "Enhancements Copyright 2005 Alessandro Scotti\n\n"
372 "%s is free software and carries NO WARRANTY;"
373 "see the file COPYING for more information.\n"
374 "The GTK build of this version is experimental and unstable\n\n"
375 "Visit XBoard on the web at: http://www.gnu.org/software/xboard/\n"
376 "Check out the newest features at: http://www.gnu.org/software/xboard/whats_new.html\n\n"
377 "Report bugs via email at: <bug-xboard@gnu.org>\n\n"
379 programVersion, zippy, PACKAGE);
380 ErrorPopUp(_("About XBoard"), buf, FALSE);
386 appData.debugMode = !appData.debugMode;
387 if(!strcmp(appData.nameOfDebugFile, "stderr")) return; // stderr is already open, and should never be closed
388 if(!appData.debugMode) fclose(debugFP);
390 debugFP = fopen(appData.nameOfDebugFile, "w");
391 if(debugFP == NULL) debugFP = stderr;
392 else setbuf(debugFP, NULL);
399 EditTagsPopUp(firstChessProgramNames, &firstChessProgramNames);
409 # define MARK_MENU_ITEM(X,Y)
411 # define MARK_MENU_ITEM(X,Y) MarkMenuItem(X, Y)
415 PonderNextMoveProc ()
417 PonderNextMoveEvent(!appData.ponderNextMove);
418 MARK_MENU_ITEM("Options.PonderNextMove", appData.ponderNextMove);
424 appData.alwaysPromoteToQueen = !appData.alwaysPromoteToQueen;
425 MARK_MENU_ITEM("Options.AlwaysQueen", appData.alwaysPromoteToQueen);
429 AnimateDraggingProc ()
431 appData.animateDragging = !appData.animateDragging;
433 if (appData.animateDragging) CreateAnimVars();
434 MARK_MENU_ITEM("Options.AnimateDragging", appData.animateDragging);
440 appData.animate = !appData.animate;
441 if (appData.animate) CreateAnimVars();
442 MARK_MENU_ITEM("Options.AnimateMoving", appData.animate);
448 appData.autoCallFlag = !appData.autoCallFlag;
449 MARK_MENU_ITEM("Options.AutoFlag", appData.autoCallFlag);
455 appData.autoFlipView = !appData.autoFlipView;
456 MARK_MENU_ITEM("Options.AutoFlipView", appData.autoFlipView);
462 appData.blindfold = !appData.blindfold;
463 MARK_MENU_ITEM("Options.Blindfold", appData.blindfold);
464 DrawPosition(True, NULL);
470 appData.testLegality = !appData.testLegality;
471 MARK_MENU_ITEM("Options.TestLegality", appData.testLegality);
478 if (appData.flashCount == 0) {
479 appData.flashCount = 3;
481 appData.flashCount = -appData.flashCount;
483 MARK_MENU_ITEM("Options.FlashMoves", appData.flashCount > 0);
488 HighlightDraggingProc ()
490 appData.highlightDragging = !appData.highlightDragging;
491 MARK_MENU_ITEM("Options.HighlightDragging", appData.highlightDragging);
496 HighlightLastMoveProc ()
498 appData.highlightLastMove = !appData.highlightLastMove;
499 MARK_MENU_ITEM("Options.HighlightLastMove", appData.highlightLastMove);
503 HighlightArrowProc ()
505 appData.highlightMoveWithArrow = !appData.highlightMoveWithArrow;
506 MARK_MENU_ITEM("Options.HighlightWithArrow", appData.highlightMoveWithArrow);
512 appData.icsAlarm = !appData.icsAlarm;
513 // MARK_MENU_ITEM("Options.ICSAlarm", appData.icsAlarm);
519 appData.ringBellAfterMoves = !appData.ringBellAfterMoves;
520 MARK_MENU_ITEM("Options.MoveSound", appData.ringBellAfterMoves);
526 appData.oneClick = !appData.oneClick;
527 MARK_MENU_ITEM("Options.OneClickMoving", appData.oneClick);
531 PeriodicUpdatesProc ()
533 PeriodicUpdatesEvent(!appData.periodicUpdates);
534 MARK_MENU_ITEM("Options.PeriodicUpdates", appData.periodicUpdates);
538 PopupExitMessageProc ()
540 appData.popupExitMessage = !appData.popupExitMessage;
541 MARK_MENU_ITEM("Options.PopupExitMessage", appData.popupExitMessage);
545 PopupMoveErrorsProc ()
547 appData.popupMoveErrors = !appData.popupMoveErrors;
548 MARK_MENU_ITEM("Options.PopupMoveErrors", appData.popupMoveErrors);
554 appData.premove = !appData.premove;
555 // MARK_MENU_ITEM("Options.Premove", appData.premove);
561 appData.showCoords = !appData.showCoords;
562 MARK_MENU_ITEM("Options.ShowCoords", appData.showCoords);
563 DrawPosition(True, NULL);
569 appData.showThinking = !appData.showThinking; // [HGM] thinking: taken out of ShowThinkingEvent
576 appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman; // [HGM] thinking: taken out of ShowThinkingEvent
579 MARK_MENU_ITEM("Options.HideThinking", appData.hideThinkingFromHuman);
585 ScheduleDelayedEvent(CreateBookEvent, 50);
591 FileNamePopUp(_("Save game file name?"),
598 * Menu definition tables
601 MenuItem fileMenu[] = {
602 {N_("New Game"), "<Ctrl>n", "NewGame", ResetGameEvent},
603 {N_("New Shuffle Game..."), NULL, "NewShuffleGame", ShuffleMenuProc},
604 {N_("New Variant..."), "<Alt><Shift>v", "NewVariant", NewVariantProc},// [HGM] variant: not functional yet
605 {"----", NULL, NULL, NothingProc},
606 {N_("Load Game"), "<Ctrl>o", "LoadGame", LoadGameProc, CHECK},
607 {N_("Load Position"), "<Ctrl><Shift>o", "LoadPosition", LoadPositionProc},
608 {N_("Next Position"), "<Shift>Page_Down", "LoadNextPosition", LoadNextPositionProc},
609 {N_("Prev Position"), "<Shift>Page_Up", "LoadPreviousPosition", LoadPrevPositionProc},
610 {"----", NULL, NULL, NothingProc},
611 {N_("Save Game"), "<Ctrl>s", "SaveGame", SaveGameProc},
612 {N_("Save Position"), "<Ctrl><Shift>s", "SavePosition", SavePositionProc},
613 {N_("Save Selected Games"), NULL, "SaveSelected", SaveSelectedProc},
614 {N_("Save Games as Book"), NULL, "CreateBook", CreateBookDelayed},
615 {"----", NULL, NULL, NothingProc},
616 {N_("Mail Move"), NULL, "MailMove", MailMoveEvent},
617 {N_("Reload CMail Message"), NULL, "ReloadCMailMessage", ReloadCmailMsgProc},
618 {"----", NULL, NULL, NothingProc},
619 {N_("Quit "), "<Ctrl>q", "Quit", QuitProc},
620 {NULL, NULL, NULL, NULL}
623 MenuItem editMenu[] = {
624 {N_("Copy Game"), "<Ctrl>c", "CopyGame", CopyGameProc},
625 {N_("Copy Position"), "<Ctrl><Shift>c", "CopyPosition", CopyPositionProc},
626 {N_("Copy Game List"), NULL, "CopyGameList", CopyGameListProc},
627 {"----", NULL, NULL, NothingProc},
628 {N_("Paste Game"), "<Ctrl>v", "PasteGame", PasteGameProc},
629 {N_("Paste Position"), "<Ctrl><Shift>v", "PastePosition", PastePositionProc},
630 {"----", NULL, NULL, NothingProc},
631 {N_("Edit Game"), "<Ctrl>e", "EditGame", EditGameEvent},
632 {N_("Edit Position"), "<Ctrl><Shift>e", "EditPosition", EditPositionEvent},
633 {N_("Edit Tags"), NULL, "EditTags", EditTagsProc},
634 {N_("Edit Comment"), NULL, "EditComment", EditCommentProc},
635 {N_("Edit Book"), NULL, "EditBook", EditBookEvent},
636 {"----", NULL, NULL, NothingProc},
637 {N_("Revert"), "Home", "Revert", RevertProc},
638 {N_("Annotate"), NULL, "Annotate", AnnotateProc},
639 {N_("Truncate Game"), "End", "TruncateGame", TruncateGameEvent},
640 {"----", NULL, NULL, NothingProc},
641 {N_("Backward"), "<Alt>Left", "Backward", BackwardEvent},
642 {N_("Forward"), "<Alt>Right", "Forward", ForwardEvent},
643 {N_("Back to Start"), "<Alt>Home", "BacktoStart", ToStartEvent},
644 {N_("Forward to End"), "<Alt>End", "ForwardtoEnd", ToEndEvent},
645 {NULL, NULL, NULL, NULL}
648 MenuItem viewMenu[] = {
649 {N_("Flip View"), "F2", "FlipView", FlipViewProc, CHECK},
650 {"----", NULL, NULL, NothingProc},
651 {N_("Engine Output"), "<Alt><Shift>o", "EngineOutput", EngineOutputProc, CHECK},
652 {N_("Move History"), "<Alt><Shift>h", "MoveHistory", HistoryShowProc, CHECK}, // [HGM] hist: activate 4.2.7 code
653 {N_("Evaluation Graph"), "<Alt><Shift>e", "EvaluationGraph", EvalGraphProc, CHECK},
654 {N_("Game List"), "<Alt><Shift>g", "GameList", ShowGameListProc, CHECK},
655 {N_("ICS text menu"), NULL, "ICStextmenu", IcsTextProc, CHECK},
656 {"----", NULL, NULL, NothingProc},
657 {N_("Tags"), NULL, "Tags", EditTagsProc, CHECK},
658 {N_("Comments"), NULL, "Comments", EditCommentProc, CHECK},
659 {N_("ICS Input Box"), NULL, "ICSInputBox", IcsInputBoxProc, CHECK},
660 {N_("ICS/Chat Console"), NULL, "OpenChatWindow", ChatProc, CHECK},
661 {"----", NULL, NULL, NothingProc},
662 {N_("Board..."), NULL, "Board", BoardOptionsProc},
663 {N_("Game List Tags..."), NULL, "GameListTags", GameListOptionsProc},
664 {NULL, NULL, NULL, NULL}
667 MenuItem modeMenu[] = {
668 {N_("Machine White"), "<Ctrl>w", "MachineWhite", MachineWhiteEvent, RADIO },
669 {N_("Machine Black"), "<Ctrl>b", "MachineBlack", MachineBlackEvent, RADIO },
670 {N_("Two Machines"), "<Ctrl>t", "TwoMachines", TwoMachinesEvent, RADIO },
671 {N_("Analysis Mode"), "<Ctrl>a", "AnalysisMode", (MenuProc*) AnalyzeModeEvent, RADIO },
672 {N_("Analyze Game"), "<Ctrl>g", "AnalyzeFile", AnalyzeFileEvent, RADIO },
673 {N_("Edit Game"), "<Ctrl>e", "EditGame", EditGameEvent, RADIO },
674 {N_("Edit Position"), "<Ctrl><Shift>e", "EditPosition", EditPositionEvent, RADIO },
675 {N_("Training"), NULL, "Training", TrainingEvent, RADIO },
676 {N_("ICS Client"), NULL, "ICSClient", IcsClientEvent, RADIO },
677 {"----", NULL, NULL, NothingProc},
678 {N_("Machine Match"), NULL, "MachineMatch", MatchProc, CHECK },
679 {N_("Pause"), "Pause", "Pause", PauseEvent, CHECK },
680 {NULL, NULL, NULL, NULL}
683 MenuItem actionMenu[] = {
684 {N_("Accept"), "F3", "Accept", AcceptEvent},
685 {N_("Decline"), "F4", "Decline", DeclineEvent},
686 {N_("Rematch"), "F12", "Rematch", RematchEvent},
687 {"----", NULL, NULL, NothingProc},
688 {N_("Call Flag"), "F5", "CallFlag", CallFlagEvent},
689 {N_("Draw"), "F6", "Draw", DrawEvent},
690 {N_("Adjourn"), "F7", "Adjourn", AdjournEvent},
691 {N_("Abort"), "F8", "Abort", AbortEvent},
692 {N_("Resign"), "F9", "Resign", ResignEvent},
693 {"----", NULL, NULL, NothingProc},
694 {N_("Stop Observing"), "F10", "StopObserving", StopObservingEvent},
695 {N_("Stop Examining"), "F11", "StopExamining", StopExaminingEvent},
696 {N_("Upload to Examine"), NULL, "UploadtoExamine", UploadGameEvent},
697 {"----", NULL, NULL, NothingProc},
698 {N_("Adjudicate to White"), NULL, "AdjudicatetoWhite", AdjuWhiteProc},
699 {N_("Adjudicate to Black"), NULL, "AdjudicatetoBlack", AdjuBlackProc},
700 {N_("Adjudicate Draw"), NULL, "AdjudicateDraw", AdjuDrawProc},
701 {NULL, NULL, NULL, NULL}
704 MenuItem engineMenu[100] = {
705 {N_("Edit Engine List..."), NULL, "EditEngList", EditEngineProc},
706 {"----", NULL, NULL, NothingProc},
707 {N_("Load New 1st Engine..."), NULL, "LoadNew1stEngine", LoadEngine1Proc},
708 {N_("Load New 2nd Engine..."), NULL, "LoadNew2ndEngine", LoadEngine2Proc},
709 {"----", NULL, NULL, NothingProc},
710 {N_("Engine #1 Settings..."), NULL, "Engine#1Settings", FirstSettingsProc},
711 {N_("Engine #2 Settings..."), NULL, "Engine#2Settings", SecondSettingsProc},
712 {"----", NULL, NULL, NothingProc},
713 {N_("Hint"), NULL, "Hint", HintEvent},
714 {N_("Book"), NULL, "Book", BookEvent},
715 {"----", NULL, NULL, NothingProc},
716 {N_("Move Now"), "<Ctrl>m", "MoveNow", MoveNowEvent},
717 {N_("Retract Move"), "<Ctrl>x", "RetractMove", RetractMoveEvent},
718 {NULL, NULL, NULL, NULL}
721 MenuItem optionsMenu[] = {
723 {N_("General..."), NULL, "General", OptionsProc},
725 {N_("Time Control..."), "<Alt><Shift>t", "TimeControl", TimeControlProc},
726 {N_("Common Engine..."), "<Alt><Shift>u", "CommonEngine", UciMenuProc},
727 {N_("Adjudications..."), "<Alt><Shift>j", "Adjudications", EngineMenuProc},
728 {N_("ICS..."), NULL, "ICS", IcsOptionsProc},
729 {N_("Tournament..."), NULL, "Match", MatchOptionsProc},
730 {N_("Load Game..."), NULL, "LoadGame", LoadOptionsProc},
731 {N_("Save Game..."), NULL, "SaveGame", SaveOptionsProc},
732 {N_("Game List..."), NULL, "GameList", GameListOptionsProc},
733 {N_("Sounds..."), NULL, "Sounds", SoundOptionsProc},
734 {"----", NULL, NULL, NothingProc},
735 #ifndef OPTIONSDIALOG
736 {N_("Always Queen"), "<Ctrl><Shift>q", "AlwaysQueen", AlwaysQueenProc},
737 {N_("Animate Dragging"), NULL, "AnimateDragging", AnimateDraggingProc},
738 {N_("Animate Moving"), "<Ctrl><Shift>a", "AnimateMoving", AnimateMovingProc},
739 {N_("Auto Flag"), "<Ctrl><Shift>f", "AutoFlag", AutoflagProc},
740 {N_("Auto Flip View"), NULL, "AutoFlipView", AutoflipProc},
741 {N_("Blindfold"), NULL, "Blindfold", BlindfoldProc},
742 {N_("Flash Moves"), NULL, "FlashMoves", FlashMovesProc},
744 {N_("Highlight Dragging"), NULL, "HighlightDragging", HighlightDraggingProc},
746 {N_("Highlight Last Move"), NULL, "HighlightLastMove", HighlightLastMoveProc},
747 {N_("Highlight With Arrow"), NULL, "HighlightWithArrow", HighlightArrowProc},
748 {N_("Move Sound"), NULL, "MoveSound", MoveSoundProc},
749 {N_("One-Click Moving"), NULL, "OneClickMoving", OneClickProc},
750 {N_("Periodic Updates"), NULL, "PeriodicUpdates", PeriodicUpdatesProc},
751 {N_("Ponder Next Move"), "<Ctrl><Shift>p", "PonderNextMove", PonderNextMoveProc},
752 {N_("Popup Exit Message"), NULL, "PopupExitMessage", PopupExitMessageProc},
753 {N_("Popup Move Errors"), NULL, "PopupMoveErrors", PopupMoveErrorsProc},
754 {N_("Show Coords"), NULL, "ShowCoords", ShowCoordsProc},
755 {N_("Hide Thinking"), "<Ctrl><Shift>h", "HideThinking", HideThinkingProc},
756 {N_("Test Legality"), "<Ctrl><Shift>l", "TestLegality", TestLegalityProc},
757 {"----", NULL, NULL, NothingProc},
759 {N_("Save Settings Now"), NULL, "SaveSettingsNow", SaveSettingsProc},
760 {N_("Save Settings on Exit"), NULL, "SaveSettingsonExit", SaveOnExitProc, CHECK },
761 {NULL, NULL, NULL, NULL}
764 MenuItem helpMenu[] = {
765 {N_("Info XBoard"), NULL, "InfoXBoard", InfoProc},
766 {N_("Man XBoard"), "F1", "ManXBoard", ManProc},
767 {"----", NULL, NULL, NothingProc},
768 {N_("XBoard Home Page"), NULL, "XBoardHomePage", HomePageProc},
769 {N_("On-line User Guide"), NULL, "On-lineUserGuide", GuideProc},
770 {N_("Development News"), NULL, "DevelopmentNews", NewsPageProc},
771 {N_("e-Mail Bug Report"), NULL, "e-MailBugReport", BugReportProc},
772 {"----", NULL, NULL, NothingProc},
773 {N_("About XBoard"), NULL, "AboutXBoard", AboutProc},
774 {NULL, NULL, NULL, NULL}
777 MenuItem noMenu[] = {
778 { "", "<Alt>Next" ,"LoadNextGame", LoadNextGameProc },
779 { "", "<Alt>Prior" ,"LoadPrevGame", LoadPrevGameProc },
780 { "", NULL,"ReloadGame", ReloadGameProc },
781 { "", NULL,"ReloadPosition", ReloadPositionProc },
782 #ifndef OPTIONSDIALOG
783 { "", NULL,"AlwaysQueen", AlwaysQueenProc },
784 { "", NULL,"AnimateDragging", AnimateDraggingProc },
785 { "", NULL,"AnimateMoving", AnimateMovingProc },
786 { "", NULL,"Autoflag", AutoflagProc },
787 { "", NULL,"Autoflip", AutoflipProc },
788 { "", NULL,"Blindfold", BlindfoldProc },
789 { "", NULL,"FlashMoves", FlashMovesProc },
791 { "", NULL,"HighlightDragging", HighlightDraggingProc },
793 { "", NULL,"HighlightLastMove", HighlightLastMoveProc },
794 { "", NULL,"MoveSound", MoveSoundProc },
795 { "", NULL,"PeriodicUpdates", PeriodicUpdatesProc },
796 { "", NULL,"PopupExitMessage", PopupExitMessageProc },
797 { "", NULL,"PopupMoveErrors", PopupMoveErrorsProc },
798 { "", NULL,"ShowCoords", ShowCoordsProc },
799 { "", NULL,"ShowThinking", ShowThinkingProc },
800 { "", NULL,"HideThinking", HideThinkingProc },
801 { "", NULL,"TestLegality", TestLegalityProc },
803 { "", NULL,"AboutGame", AboutGameEvent },
804 { "", "<Ctrl>d" ,"DebugProc", DebugProc },
805 { "", NULL,"Nothing", NothingProc },
806 {NULL, NULL, NULL, NULL}
810 {N_("File"), "File", fileMenu},
811 {N_("Edit"), "Edit", editMenu},
812 {N_("View"), "View", viewMenu},
813 {N_("Mode"), "Mode", modeMenu},
814 {N_("Action"), "Action", actionMenu},
815 {N_("Engine"), "Engine", engineMenu},
816 {N_("Options"), "Options", optionsMenu},
817 {N_("Help"), "Help", helpMenu},
819 { "", "None", noMenu}
823 MenuNameToItem (char *menuName)
826 char buf[MSG_SIZ], *p;
828 static MenuItem a = { NULL, NULL, NULL, NothingProc };
829 extern Option mainOptions[];
830 safeStrCpy(buf, menuName, MSG_SIZ);
831 p = strchr(buf, '.');
832 if(!p) menuTab = noMenu, p = menuName; else {
834 for(i=0; menuBar[i].name; i++)
835 if(!strcmp(buf, menuBar[i].name)) break;
836 if(!menuBar[i].name) return NULL; // main menu not found
837 menuTab = menuBar[i].mi;
839 if(*p == NULLCHAR) { a.handle = mainOptions[i+1].handle; return &a; } // main menu bar
840 for(i=0; menuTab[i].string; i++)
841 if(menuTab[i].ref && !strcmp(p, menuTab[i].ref)) return menuTab + i;
842 return NULL; // item not found
848 AppendEnginesToMenu (char *list)
852 if(appData.icsActive || appData.recentEngines <= 0) return;
853 for(firstEngineItem=0; engineMenu[firstEngineItem].string; firstEngineItem++);
854 recentEngines = strdup(list);
856 p = strchr(list, '\n'); if(p == NULL) break;
857 if(i == 0) engineMenu[firstEngineItem++].string = "----"; // at least one valid item to add
859 if(firstEngineItem + i < 99)
860 engineMenu[firstEngineItem+i].string = strdup(list); // just set name; MenuProc stays NULL
861 i++; *p = '\n'; list = p + 1;
865 Enables icsEnables[] = {
866 { "File.MailMove", False },
867 { "File.ReloadCMailMessage", False },
868 { "Mode.MachineBlack", False },
869 { "Mode.MachineWhite", False },
870 { "Mode.AnalysisMode", False },
871 { "Mode.AnalyzeFile", False },
872 { "Mode.TwoMachines", False },
873 { "Mode.MachineMatch", False },
875 { "Engine.Hint", False },
876 { "Engine.Book", False },
877 { "Engine.MoveNow", False },
878 #ifndef OPTIONSDIALOG
879 { "PeriodicUpdates", False },
880 { "HideThinking", False },
881 { "PonderNextMove", False },
884 { "Engine.Engine#1Settings", False },
885 { "Engine.Engine#2Settings", False },
886 { "Engine.Load1stEngine", False },
887 { "Engine.Load2ndEngine", False },
888 { "Edit.Annotate", False },
889 { "Options.Match", False },
893 Enables ncpEnables[] = {
894 { "File.MailMove", False },
895 { "File.ReloadCMailMessage", False },
896 { "Mode.MachineWhite", False },
897 { "Mode.MachineBlack", False },
898 { "Mode.AnalysisMode", False },
899 { "Mode.AnalyzeFile", False },
900 { "Mode.TwoMachines", False },
901 { "Mode.MachineMatch", False },
902 { "Mode.ICSClient", False },
903 { "View.ICStextmenu", False },
904 { "View.ICSInputBox", False },
905 { "View.OpenChatWindow", False },
906 { "Action.", False },
907 { "Edit.Revert", False },
908 { "Edit.Annotate", False },
909 { "Engine.Engine#1Settings", False },
910 { "Engine.Engine#2Settings", False },
911 { "Engine.MoveNow", False },
912 { "Engine.RetractMove", False },
913 { "Options.ICS", False },
914 #ifndef OPTIONSDIALOG
915 { "Options.AutoFlag", False },
916 { "Options.AutoFlip View", False },
917 // { "Options.ICSAlarm", False },
918 { "Options.MoveSound", False },
919 { "Options.HideThinking", False },
920 { "Options.PeriodicUpdates", False },
921 { "Options.PonderNextMove", False },
923 { "Engine.Hint", False },
924 { "Engine.Book", False },
928 Enables gnuEnables[] = {
929 { "Mode.ICSClient", False },
930 { "View.ICStextmenu", False },
931 { "View.ICSInputBox", False },
932 { "View.OpenChatWindow", False },
933 { "Action.Accept", False },
934 { "Action.Decline", False },
935 { "Action.Rematch", False },
936 { "Action.Adjourn", False },
937 { "Action.StopExamining", False },
938 { "Action.StopObserving", False },
939 { "Action.UploadtoExamine", False },
940 { "Edit.Revert", False },
941 { "Edit.Annotate", False },
942 { "Options.ICS", False },
944 /* The next two options rely on SetCmailMode being called *after* */
945 /* SetGNUMode so that when GNU is being used to give hints these */
946 /* menu options are still available */
948 { "File.MailMove", False },
949 { "File.ReloadCMailMessage", False },
950 // [HGM] The following have been added to make a switch from ncp to GNU mode possible
951 { "Mode.MachineWhite", True },
952 { "Mode.MachineBlack", True },
953 { "Mode.AnalysisMode", True },
954 { "Mode.AnalyzeFile", True },
955 { "Mode.TwoMachines", True },
956 { "Mode.MachineMatch", True },
957 { "Engine.Engine#1Settings", True },
958 { "Engine.Engine#2Settings", True },
959 { "Engine.Hint", True },
960 { "Engine.Book", True },
961 { "Engine.MoveNow", True },
962 { "Engine.RetractMove", True },
967 Enables cmailEnables[] = {
969 { "Action.CallFlag", False },
970 { "Action.Draw", True },
971 { "Action.Adjourn", False },
972 { "Action.Abort", False },
973 { "Action.StopObserving", False },
974 { "Action.StopExamining", False },
975 { "File.MailMove", True },
976 { "File.ReloadCMailMessage", True },
980 Enables trainingOnEnables[] = {
981 { "Edit.EditComment", False },
982 { "Mode.Pause", False },
983 { "Edit.Forward", False },
984 { "Edit.Backward", False },
985 { "Edit.ForwardtoEnd", False },
986 { "Edit.BacktoStart", False },
987 { "Engine.MoveNow", False },
988 { "Edit.TruncateGame", False },
992 Enables trainingOffEnables[] = {
993 { "Edit.EditComment", True },
994 { "Mode.Pause", True },
995 { "Edit.Forward", True },
996 { "Edit.Backward", True },
997 { "Edit.ForwardtoEnd", True },
998 { "Edit.BacktoStart", True },
999 { "Engine.MoveNow", True },
1000 { "Engine.TruncateGame", True },
1004 Enables machineThinkingEnables[] = {
1005 { "File.LoadGame", False },
1006 // { "LoadNextGame", False },
1007 // { "LoadPreviousGame", False },
1008 // { "ReloadSameGame", False },
1009 { "Edit.PasteGame", False },
1010 { "File.LoadPosition", False },
1011 // { "LoadNextPosition", False },
1012 // { "LoadPreviousPosition", False },
1013 // { "ReloadSamePosition", False },
1014 { "Edit.PastePosition", False },
1015 { "Mode.MachineWhite", False },
1016 { "Mode.MachineBlack", False },
1017 { "Mode.TwoMachines", False },
1018 // { "MachineMatch", False },
1019 { "Engine.RetractMove", False },
1023 Enables userThinkingEnables[] = {
1024 { "File.LoadGame", True },
1025 // { "LoadNextGame", True },
1026 // { "LoadPreviousGame", True },
1027 // { "ReloadSameGame", True },
1028 { "Edit.PasteGame", True },
1029 { "File.LoadPosition", True },
1030 // { "LoadNextPosition", True },
1031 // { "LoadPreviousPosition", True },
1032 // { "ReloadSamePosition", True },
1033 { "Edit.PastePosition", True },
1034 { "Mode.MachineWhite", True },
1035 { "Mode.MachineBlack", True },
1036 { "Mode.TwoMachines", True },
1037 // { "MachineMatch", True },
1038 { "Engine.RetractMove", True },
1045 SetMenuEnables(icsEnables);
1048 if (appData.zippyPlay && !appData.noChessProgram) { /* [DM] icsEngineAnalyze */
1049 EnableNamedMenuItem("Mode.AnalysisMode", True);
1050 EnableNamedMenuItem("Engine.Engine#1Settings", True);
1058 SetMenuEnables(ncpEnables);
1064 SetMenuEnables(gnuEnables);
1070 SetMenuEnables(cmailEnables);
1074 SetTrainingModeOn ()
1076 SetMenuEnables(trainingOnEnables);
1077 if (appData.showButtonBar) {
1078 EnableButtonBar(False);
1084 SetTrainingModeOff ()
1086 SetMenuEnables(trainingOffEnables);
1087 if (appData.showButtonBar) {
1088 EnableButtonBar(True);
1093 SetUserThinkingEnables ()
1095 if (appData.noChessProgram) return;
1096 SetMenuEnables(userThinkingEnables);
1100 SetMachineThinkingEnables ()
1102 if (appData.noChessProgram) return;
1103 SetMenuEnables(machineThinkingEnables);
1105 case MachinePlaysBlack:
1106 case MachinePlaysWhite:
1107 case TwoMachinesPlay:
1108 EnableNamedMenuItem(ModeToWidgetName(gameMode), True);
1116 GreyRevert (Boolean grey)
1118 EnableNamedMenuItem("Edit.Revert", !grey);
1119 EnableNamedMenuItem("Edit.Annotate", !grey);
1123 ModeToWidgetName (GameMode mode)
1126 case BeginningOfGame:
1127 if (appData.icsActive)
1128 return "Mode.ICSClient";
1129 else if (appData.noChessProgram ||
1130 *appData.cmailGameName != NULLCHAR)
1131 return "Mode.EditGame";
1133 return "Mode.MachineBlack";
1134 case MachinePlaysBlack:
1135 return "Mode.MachineBlack";
1136 case MachinePlaysWhite:
1137 return "Mode.MachineWhite";
1139 return "Mode.AnalysisMode";
1141 return "Mode.AnalyzeFile";
1142 case TwoMachinesPlay:
1143 return "Mode.TwoMachines";
1145 return "Mode.EditGame";
1146 case PlayFromGameFile:
1147 return "File.LoadGame";
1149 return "Mode.EditPosition";
1151 return "Mode.Training";
1152 case IcsPlayingWhite:
1153 case IcsPlayingBlack:
1157 return "Mode.ICSClient";
1165 InstallNewEngine (char *command, char *dir, char *variants, char *protocol)
1166 { // install the given engine in XBoard's -firstChessProgramNames
1167 char buf[MSG_SIZ], *quote = "";
1168 if(strchr(command, ' ')) { // quoting needed
1169 if(!strchr(command, '"')) quote = "\""; else
1170 if(!strchr(command, '\'')) quote = "'"; else {
1171 printf("Could not auto-install %s\n", command); // too complex
1174 // construct engine line, with optional -fd and -fUCI arguments
1175 snprintf(buf, MSG_SIZ, "%s%s%s", quote, command, quote);
1176 if(strcmp(dir, "") && strcmp(dir, "."))
1177 snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fd %s", dir);
1178 if(!strcmp(protocol, "uci"))
1179 snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fUCI");
1180 if(strstr(firstChessProgramNames, buf)) return; // avoid duplicats
1182 quote = malloc(strlen(firstChessProgramNames) + strlen(buf) + 2);
1183 sprintf(quote, "%s%s\n", firstChessProgramNames, buf);
1184 FREE(firstChessProgramNames); firstChessProgramNames = quote;
1187 #ifdef HAVE_DIRENT_H
1190 #include <sys/dir.h>
1191 #define dirent direct
1195 InstallFromDir (char *dirName, char *protocol, char *settingsFile)
1196 { // scan system for new plugin specs in given directory
1199 struct stat statBuf;
1200 time_t lastSaved = 0;
1203 if(!stat(settingsFile, &statBuf)) lastSaved = statBuf.st_mtime;
1204 snprintf(buf, 1024, "%s/%s", dirName, protocol);
1206 if(!(dir = opendir(buf))) return;
1207 while( (dp = readdir(dir))) {
1208 time_t installed = 0;
1209 if(!strstr(dp->d_name, ".eng")) continue; // to suppress . and ..
1210 snprintf(buf, 1024, "%s/%s/%s", dirName, protocol, dp->d_name);
1211 if(!stat(buf, &statBuf)) installed = statBuf.st_mtime;
1212 if(lastSaved == 0 || (int) (installed - lastSaved) > 0) { // first time we see it
1213 FILE *f = fopen(buf, "r");
1214 if(f) { // read the plugin-specs
1215 char engineCommand[1024], engineDir[1024], variants[1024];
1216 char bad=0, dummy, *engineCom = engineCommand;
1218 if(fscanf(f, "plugin spec %d.%d%c", &major, &minor, &dummy) != 3 ||
1219 fscanf(f, "%[^\n]%c", engineCommand, &dummy) != 2 ||
1220 fscanf(f, "%[^\n]%c", variants, &dummy) != 2) bad = 1;
1223 // uncomment following two lines for chess-only installs
1224 // if(!(p = strstr(variants, "chess")) ||
1225 // p != variants && p[-1] != ',' || p[5] && p[5] != ',') continue;
1226 // split off engine working directory (if any)
1227 strcpy(engineDir, "");
1228 if(sscanf(engineCommand, "cd %[^;];%c", engineDir, &dummy) == 2)
1229 engineCom = engineCommand + strlen(engineDir) + 4;
1230 InstallNewEngine(engineCom, engineDir, variants, protocol);
1238 AutoInstallProtocol (char *settingsFile, char *protocol)
1239 { // install new engines for given protocol (both from package and source)
1240 InstallFromDir("/usr/local/share/games/plugins", protocol, settingsFile);
1241 InstallFromDir("/usr/share/games/plugins", protocol, settingsFile);
1245 AutoInstall (char *settingsFile)
1246 { // install all new XBoard and UCI engines
1247 AutoInstallProtocol(settingsFile, "xboard");
1248 AutoInstallProtocol(settingsFile, "uci");
1254 #ifndef OPTIONSDIALOG
1255 if (appData.alwaysPromoteToQueen) {
1256 MarkMenuItem("Options.Always Queen", True);
1258 if (appData.animateDragging) {
1259 MarkMenuItem("Options.Animate Dragging", True);
1261 if (appData.animate) {
1262 MarkMenuItem("Options.Animate Moving", True);
1264 if (appData.autoCallFlag) {
1265 MarkMenuItem("Options.Auto Flag", True);
1267 if (appData.autoFlipView) {
1268 XtSetValues(XtNameToWidget(menuBarWidget,"Options.Auto Flip View", True);
1270 if (appData.blindfold) {
1271 MarkMenuItem("Options.Blindfold", True);
1273 if (appData.flashCount > 0) {
1274 MarkMenuItem("Options.Flash Moves", True);
1277 if (appData.highlightDragging) {
1278 MarkMenuItem("Options.Highlight Dragging", True);
1281 if (appData.highlightLastMove) {
1282 MarkMenuItem("Options.Highlight Last Move", True);
1284 if (appData.highlightMoveWithArrow) {
1285 MarkMenuItem("Options.Arrow", True);
1287 // if (appData.icsAlarm) {
1288 // MarkMenuItem("Options.ICS Alarm", True);
1290 if (appData.ringBellAfterMoves) {
1291 MarkMenuItem("Options.Move Sound", True);
1293 if (appData.oneClick) {
1294 MarkMenuItem("Options.OneClick", True);
1296 if (appData.periodicUpdates) {
1297 MarkMenuItem("Options.Periodic Updates", True);
1299 if (appData.ponderNextMove) {
1300 MarkMenuItem("Options.Ponder Next Move", True);
1302 if (appData.popupExitMessage) {
1303 MarkMenuItem("Options.Popup Exit Message", True);
1305 if (appData.popupMoveErrors) {
1306 MarkMenuItem("Options.Popup Move Errors", True);
1308 // if (appData.premove) {
1309 // MarkMenuItem("Options.Premove", True);
1311 if (appData.showCoords) {
1312 MarkMenuItem("Options.Show Coords", True);
1314 if (appData.hideThinkingFromHuman) {
1315 MarkMenuItem("Options.Hide Thinking", True);
1317 if (appData.testLegality) {
1318 MarkMenuItem("Options.Test Legality", True);
1321 if (saveSettingsOnExit) {
1322 MarkMenuItem("Options.SaveSettingsonExit", True);
1324 EnableNamedMenuItem("File.SaveSelected", False);
1326 // all XBoard builds get here, but not WinBoard...
1327 if(*appData.autoInstall) AutoInstall(settingsFileName);