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 EditEnginePopUp(firstChessProgramNames, &firstChessProgramNames);
400 # define MARK_MENU_ITEM(X,Y)
402 # define MARK_MENU_ITEM(X,Y) MarkMenuItem(X, Y)
406 PonderNextMoveProc ()
408 PonderNextMoveEvent(!appData.ponderNextMove);
409 MARK_MENU_ITEM("Options.PonderNextMove", appData.ponderNextMove);
415 appData.alwaysPromoteToQueen = !appData.alwaysPromoteToQueen;
416 MARK_MENU_ITEM("Options.AlwaysQueen", appData.alwaysPromoteToQueen);
420 AnimateDraggingProc ()
422 appData.animateDragging = !appData.animateDragging;
424 if (appData.animateDragging) CreateAnimVars();
425 MARK_MENU_ITEM("Options.AnimateDragging", appData.animateDragging);
431 appData.animate = !appData.animate;
432 if (appData.animate) CreateAnimVars();
433 MARK_MENU_ITEM("Options.AnimateMoving", appData.animate);
439 appData.autoCallFlag = !appData.autoCallFlag;
440 MARK_MENU_ITEM("Options.AutoFlag", appData.autoCallFlag);
446 appData.autoFlipView = !appData.autoFlipView;
447 MARK_MENU_ITEM("Options.AutoFlipView", appData.autoFlipView);
453 appData.blindfold = !appData.blindfold;
454 MARK_MENU_ITEM("Options.Blindfold", appData.blindfold);
455 DrawPosition(True, NULL);
461 appData.testLegality = !appData.testLegality;
462 MARK_MENU_ITEM("Options.TestLegality", appData.testLegality);
469 if (appData.flashCount == 0) {
470 appData.flashCount = 3;
472 appData.flashCount = -appData.flashCount;
474 MARK_MENU_ITEM("Options.FlashMoves", appData.flashCount > 0);
479 HighlightDraggingProc ()
481 appData.highlightDragging = !appData.highlightDragging;
482 MARK_MENU_ITEM("Options.HighlightDragging", appData.highlightDragging);
487 HighlightLastMoveProc ()
489 appData.highlightLastMove = !appData.highlightLastMove;
490 MARK_MENU_ITEM("Options.HighlightLastMove", appData.highlightLastMove);
494 HighlightArrowProc ()
496 appData.highlightMoveWithArrow = !appData.highlightMoveWithArrow;
497 MARK_MENU_ITEM("Options.HighlightWithArrow", appData.highlightMoveWithArrow);
503 appData.icsAlarm = !appData.icsAlarm;
504 // MARK_MENU_ITEM("Options.ICSAlarm", appData.icsAlarm);
510 appData.ringBellAfterMoves = !appData.ringBellAfterMoves;
511 MARK_MENU_ITEM("Options.MoveSound", appData.ringBellAfterMoves);
517 appData.oneClick = !appData.oneClick;
518 MARK_MENU_ITEM("Options.OneClickMoving", appData.oneClick);
522 PeriodicUpdatesProc ()
524 PeriodicUpdatesEvent(!appData.periodicUpdates);
525 MARK_MENU_ITEM("Options.PeriodicUpdates", appData.periodicUpdates);
529 PopupExitMessageProc ()
531 appData.popupExitMessage = !appData.popupExitMessage;
532 MARK_MENU_ITEM("Options.PopupExitMessage", appData.popupExitMessage);
536 PopupMoveErrorsProc ()
538 appData.popupMoveErrors = !appData.popupMoveErrors;
539 MARK_MENU_ITEM("Options.PopupMoveErrors", appData.popupMoveErrors);
545 appData.premove = !appData.premove;
546 // MARK_MENU_ITEM("Options.Premove", appData.premove);
552 appData.showCoords = !appData.showCoords;
553 MARK_MENU_ITEM("Options.ShowCoords", appData.showCoords);
554 DrawPosition(True, NULL);
560 appData.showThinking = !appData.showThinking; // [HGM] thinking: taken out of ShowThinkingEvent
567 appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman; // [HGM] thinking: taken out of ShowThinkingEvent
570 MARK_MENU_ITEM("Options.HideThinking", appData.hideThinkingFromHuman);
576 ScheduleDelayedEvent(CreateBookEvent, 50);
582 FileNamePopUp(_("Save game file name?"),
589 * Menu definition tables
592 MenuItem fileMenu[] = {
593 {N_("New Game"), "<Ctrl>n", "NewGame", ResetGameEvent},
594 {N_("New Shuffle Game..."), NULL, "NewShuffleGame", ShuffleMenuProc},
595 {N_("New Variant..."), "<Alt><Shift>v", "NewVariant", NewVariantProc},// [HGM] variant: not functional yet
596 {"----", NULL, NULL, NothingProc},
597 {N_("Load Game"), "<Ctrl>o", "LoadGame", LoadGameProc, CHECK},
598 {N_("Load Position"), "<Ctrl><Shift>o", "LoadPosition", LoadPositionProc},
599 {N_("Next Position"), "<Shift>Page_Down", "LoadNextPosition", LoadNextPositionProc},
600 {N_("Prev Position"), "<Shift>Page_Up", "LoadPreviousPosition", LoadPrevPositionProc},
601 {"----", NULL, NULL, NothingProc},
602 {N_("Save Game"), "<Ctrl>s", "SaveGame", SaveGameProc},
603 {N_("Save Position"), "<Ctrl><Shift>s", "SavePosition", SavePositionProc},
604 {N_("Save Selected Games"), NULL, "SaveSelected", SaveSelectedProc},
605 {N_("Save Games as Book"), NULL, "CreateBook", CreateBookDelayed},
606 {"----", NULL, NULL, NothingProc},
607 {N_("Mail Move"), NULL, "MailMove", MailMoveEvent},
608 {N_("Reload CMail Message"), NULL, "ReloadCMailMessage", ReloadCmailMsgProc},
609 {"----", NULL, NULL, NothingProc},
610 {N_("Quit "), "<Ctrl>q", "Quit", QuitProc},
611 {NULL, NULL, NULL, NULL}
614 MenuItem editMenu[] = {
615 {N_("Copy Game"), "<Ctrl>c", "CopyGame", CopyGameProc},
616 {N_("Copy Position"), "<Ctrl><Shift>c", "CopyPosition", CopyPositionProc},
617 {N_("Copy Game List"), NULL, "CopyGameList", CopyGameListProc},
618 {"----", NULL, NULL, NothingProc},
619 {N_("Paste Game"), "<Ctrl>v", "PasteGame", PasteGameProc},
620 {N_("Paste Position"), "<Ctrl><Shift>v", "PastePosition", PastePositionProc},
621 {"----", NULL, NULL, NothingProc},
622 {N_("Edit Game"), "<Ctrl>e", "EditGame", EditGameEvent},
623 {N_("Edit Position"), "<Ctrl><Shift>e", "EditPosition", EditPositionEvent},
624 {N_("Edit Tags"), NULL, "EditTags", EditTagsProc},
625 {N_("Edit Comment"), NULL, "EditComment", EditCommentProc},
626 {N_("Edit Book"), NULL, "EditBook", EditBookEvent},
627 {"----", NULL, NULL, NothingProc},
628 {N_("Revert"), "Home", "Revert", RevertProc},
629 {N_("Annotate"), NULL, "Annotate", AnnotateProc},
630 {N_("Truncate Game"), "End", "TruncateGame", TruncateGameEvent},
631 {"----", NULL, NULL, NothingProc},
632 {N_("Backward"), "<Alt>Left", "Backward", BackwardEvent},
633 {N_("Forward"), "<Alt>Right", "Forward", ForwardEvent},
634 {N_("Back to Start"), "<Alt>Home", "BacktoStart", ToStartEvent},
635 {N_("Forward to End"), "<Alt>End", "ForwardtoEnd", ToEndEvent},
636 {NULL, NULL, NULL, NULL}
639 MenuItem viewMenu[] = {
640 {N_("Flip View"), "F2", "FlipView", FlipViewProc, CHECK},
641 {"----", NULL, NULL, NothingProc},
642 {N_("Engine Output"), "<Alt><Shift>o", "EngineOutput", EngineOutputProc, CHECK},
643 {N_("Move History"), "<Alt><Shift>h", "MoveHistory", HistoryShowProc, CHECK}, // [HGM] hist: activate 4.2.7 code
644 {N_("Evaluation Graph"), "<Alt><Shift>e", "EvaluationGraph", EvalGraphProc, CHECK},
645 {N_("Game List"), "<Alt><Shift>g", "GameList", ShowGameListProc, CHECK},
646 {N_("ICS text menu"), NULL, "ICStextmenu", IcsTextProc, CHECK},
647 {"----", NULL, NULL, NothingProc},
648 {N_("Tags"), NULL, "Tags", EditTagsProc, CHECK},
649 {N_("Comments"), NULL, "Comments", EditCommentProc, CHECK},
650 {N_("ICS Input Box"), NULL, "ICSInputBox", IcsInputBoxProc, CHECK},
651 {N_("ICS/Chat Console"), NULL, "OpenChatWindow", ChatProc, CHECK},
652 {"----", NULL, NULL, NothingProc},
653 {N_("Board..."), NULL, "Board", BoardOptionsProc},
654 {N_("Fonts..."), NULL, "Fonts", FontsProc},
655 {N_("Game List Tags..."), NULL, "GameListTags", GameListOptionsProc},
656 {NULL, NULL, NULL, NULL}
659 MenuItem modeMenu[] = {
660 {N_("Machine White"), "<Ctrl>w", "MachineWhite", MachineWhiteEvent, RADIO },
661 {N_("Machine Black"), "<Ctrl>b", "MachineBlack", MachineBlackEvent, RADIO },
662 {N_("Two Machines"), "<Ctrl>t", "TwoMachines", TwoMachinesEvent, RADIO },
663 {N_("Analysis Mode"), "<Ctrl>a", "AnalysisMode", (MenuProc*) AnalyzeModeEvent, RADIO },
664 {N_("Analyze Game"), "<Ctrl>g", "AnalyzeFile", AnalyzeFileEvent, RADIO },
665 {N_("Edit Game"), "<Ctrl>e", "EditGame", EditGameEvent, RADIO },
666 {N_("Edit Position"), "<Ctrl><Shift>e", "EditPosition", EditPositionEvent, RADIO },
667 {N_("Training"), NULL, "Training", TrainingEvent, RADIO },
668 {N_("ICS Client"), NULL, "ICSClient", IcsClientEvent, RADIO },
669 {"----", NULL, NULL, NothingProc},
670 {N_("Machine Match"), NULL, "MachineMatch", MatchProc, CHECK },
671 {N_("Pause"), "Pause", "Pause", PauseEvent, CHECK },
672 {NULL, NULL, NULL, NULL}
675 MenuItem actionMenu[] = {
676 {N_("Accept"), "F3", "Accept", AcceptEvent},
677 {N_("Decline"), "F4", "Decline", DeclineEvent},
678 {N_("Rematch"), "F12", "Rematch", RematchEvent},
679 {"----", NULL, NULL, NothingProc},
680 {N_("Call Flag"), "F5", "CallFlag", CallFlagEvent},
681 {N_("Draw"), "F6", "Draw", DrawEvent},
682 {N_("Adjourn"), "F7", "Adjourn", AdjournEvent},
683 {N_("Abort"), "F8", "Abort", AbortEvent},
684 {N_("Resign"), "F9", "Resign", ResignEvent},
685 {"----", NULL, NULL, NothingProc},
686 {N_("Stop Observing"), "F10", "StopObserving", StopObservingEvent},
687 {N_("Stop Examining"), "F11", "StopExamining", StopExaminingEvent},
688 {N_("Upload to Examine"), NULL, "UploadtoExamine", UploadGameEvent},
689 {"----", NULL, NULL, NothingProc},
690 {N_("Adjudicate to White"), NULL, "AdjudicatetoWhite", AdjuWhiteProc},
691 {N_("Adjudicate to Black"), NULL, "AdjudicatetoBlack", AdjuBlackProc},
692 {N_("Adjudicate Draw"), NULL, "AdjudicateDraw", AdjuDrawProc},
693 {NULL, NULL, NULL, NULL}
696 MenuItem engineMenu[100] = {
697 {N_("Edit Engine List..."), NULL, "EditEngList", EditEngineProc},
698 {"----", NULL, NULL, NothingProc},
699 {N_("Load New 1st Engine..."), NULL, "LoadNew1stEngine", LoadEngine1Proc},
700 {N_("Load New 2nd Engine..."), NULL, "LoadNew2ndEngine", LoadEngine2Proc},
701 {"----", NULL, NULL, NothingProc},
702 {N_("Engine #1 Settings..."), NULL, "Engine#1Settings", FirstSettingsProc},
703 {N_("Engine #2 Settings..."), NULL, "Engine#2Settings", SecondSettingsProc},
704 {N_("Common Settings..."), "<Alt><Shift>u","CommonEngine", UciMenuProc},
705 {"----", NULL, NULL, NothingProc},
706 {N_("Hint"), NULL, "Hint", HintEvent},
707 {N_("Book"), NULL, "Book", BookEvent},
708 {"----", NULL, NULL, NothingProc},
709 {N_("Move Now"), "<Ctrl>m", "MoveNow", MoveNowEvent},
710 {N_("Retract Move"), "<Ctrl>x", "RetractMove", RetractMoveEvent},
711 {NULL, NULL, NULL, NULL}
714 MenuItem optionsMenu[] = {
716 {N_("General..."), NULL, "General", OptionsProc},
718 {N_("Time Control..."), "<Alt><Shift>t", "TimeControl", TimeControlProc},
719 {N_("Adjudications..."), "<Alt><Shift>j", "Adjudications", EngineMenuProc},
720 {N_("ICS..."), NULL, "ICS", IcsOptionsProc},
721 {N_("Tournament..."), NULL, "Match", MatchOptionsProc},
722 {N_("Load Game..."), NULL, "LoadGame", LoadOptionsProc},
723 {N_("Save Game..."), NULL, "SaveGame", SaveOptionsProc},
724 {N_("Game List..."), NULL, "GameList", GameListOptionsProc},
725 {N_("Sounds..."), NULL, "Sounds", SoundOptionsProc},
726 {"----", NULL, NULL, NothingProc},
727 #ifndef OPTIONSDIALOG
728 {N_("Always Queen"), "<Ctrl><Shift>q", "AlwaysQueen", AlwaysQueenProc},
729 {N_("Animate Dragging"), NULL, "AnimateDragging", AnimateDraggingProc},
730 {N_("Animate Moving"), "<Ctrl><Shift>a", "AnimateMoving", AnimateMovingProc},
731 {N_("Auto Flag"), "<Ctrl><Shift>f", "AutoFlag", AutoflagProc},
732 {N_("Auto Flip View"), NULL, "AutoFlipView", AutoflipProc},
733 {N_("Blindfold"), NULL, "Blindfold", BlindfoldProc},
734 {N_("Flash Moves"), NULL, "FlashMoves", FlashMovesProc},
736 {N_("Highlight Dragging"), NULL, "HighlightDragging", HighlightDraggingProc},
738 {N_("Highlight Last Move"), NULL, "HighlightLastMove", HighlightLastMoveProc},
739 {N_("Highlight With Arrow"), NULL, "HighlightWithArrow", HighlightArrowProc},
740 {N_("Move Sound"), NULL, "MoveSound", MoveSoundProc},
741 {N_("One-Click Moving"), NULL, "OneClickMoving", OneClickProc},
742 {N_("Periodic Updates"), NULL, "PeriodicUpdates", PeriodicUpdatesProc},
743 {N_("Ponder Next Move"), "<Ctrl><Shift>p", "PonderNextMove", PonderNextMoveProc},
744 {N_("Popup Exit Message"), NULL, "PopupExitMessage", PopupExitMessageProc},
745 {N_("Popup Move Errors"), NULL, "PopupMoveErrors", PopupMoveErrorsProc},
746 {N_("Show Coords"), NULL, "ShowCoords", ShowCoordsProc},
747 {N_("Hide Thinking"), "<Ctrl><Shift>h", "HideThinking", HideThinkingProc},
748 {N_("Test Legality"), "<Ctrl><Shift>l", "TestLegality", TestLegalityProc},
749 {"----", NULL, NULL, NothingProc},
751 {N_("Save Settings Now"), NULL, "SaveSettingsNow", SaveSettingsProc},
752 {N_("Save Settings on Exit"), NULL, "SaveSettingsonExit", SaveOnExitProc, CHECK },
753 {NULL, NULL, NULL, NULL}
756 MenuItem helpMenu[] = {
757 {N_("Info XBoard"), NULL, "InfoXBoard", InfoProc},
758 {N_("Man XBoard"), "F1", "ManXBoard", ManProc},
759 {"----", NULL, NULL, NothingProc},
760 {N_("XBoard Home Page"), NULL, "XBoardHomePage", HomePageProc},
761 {N_("On-line User Guide"), NULL, "On-lineUserGuide", GuideProc},
762 {N_("Development News"), NULL, "DevelopmentNews", NewsPageProc},
763 {N_("e-Mail Bug Report"), NULL, "e-MailBugReport", BugReportProc},
764 {"----", NULL, NULL, NothingProc},
765 {N_("About XBoard"), NULL, "AboutXBoard", AboutProc},
766 {NULL, NULL, NULL, NULL}
769 MenuItem noMenu[] = {
770 { "", "<Alt>Next" ,"LoadNextGame", LoadNextGameProc },
771 { "", "<Alt>Prior" ,"LoadPrevGame", LoadPrevGameProc },
772 { "", NULL,"ReloadGame", ReloadGameProc },
773 { "", NULL,"ReloadPosition", ReloadPositionProc },
774 #ifndef OPTIONSDIALOG
775 { "", NULL,"AlwaysQueen", AlwaysQueenProc },
776 { "", NULL,"AnimateDragging", AnimateDraggingProc },
777 { "", NULL,"AnimateMoving", AnimateMovingProc },
778 { "", NULL,"Autoflag", AutoflagProc },
779 { "", NULL,"Autoflip", AutoflipProc },
780 { "", NULL,"Blindfold", BlindfoldProc },
781 { "", NULL,"FlashMoves", FlashMovesProc },
783 { "", NULL,"HighlightDragging", HighlightDraggingProc },
785 { "", NULL,"HighlightLastMove", HighlightLastMoveProc },
786 { "", NULL,"MoveSound", MoveSoundProc },
787 { "", NULL,"PeriodicUpdates", PeriodicUpdatesProc },
788 { "", NULL,"PopupExitMessage", PopupExitMessageProc },
789 { "", NULL,"PopupMoveErrors", PopupMoveErrorsProc },
790 { "", NULL,"ShowCoords", ShowCoordsProc },
791 { "", NULL,"ShowThinking", ShowThinkingProc },
792 { "", NULL,"HideThinking", HideThinkingProc },
793 { "", NULL,"TestLegality", TestLegalityProc },
795 { "", NULL,"AboutGame", AboutGameEvent },
796 { "", "<Ctrl>d" ,"DebugProc", DebugProc },
797 { "", NULL,"Nothing", NothingProc },
798 {NULL, NULL, NULL, NULL}
802 {N_("File"), "File", fileMenu},
803 {N_("Edit"), "Edit", editMenu},
804 {N_("View"), "View", viewMenu},
805 {N_("Mode"), "Mode", modeMenu},
806 {N_("Action"), "Action", actionMenu},
807 {N_("Engine"), "Engine", engineMenu},
808 {N_("Options"), "Options", optionsMenu},
809 {N_("Help"), "Help", helpMenu},
811 { "", "None", noMenu}
815 MenuNameToItem (char *menuName)
818 char buf[MSG_SIZ], *p;
820 static MenuItem a = { NULL, NULL, NULL, NothingProc };
821 extern Option mainOptions[];
822 safeStrCpy(buf, menuName, MSG_SIZ);
823 p = strchr(buf, '.');
824 if(!p) menuTab = noMenu, p = menuName; else {
826 for(i=0; menuBar[i].name; i++)
827 if(!strcmp(buf, menuBar[i].name)) break;
828 if(!menuBar[i].name) return NULL; // main menu not found
829 menuTab = menuBar[i].mi;
831 if(*p == NULLCHAR) { a.handle = mainOptions[i+1].handle; return &a; } // main menu bar
832 for(i=0; menuTab[i].string; i++)
833 if(menuTab[i].ref && !strcmp(p, menuTab[i].ref)) return menuTab + i;
834 return NULL; // item not found
840 AppendEnginesToMenu (char *list)
844 if(appData.icsActive || appData.recentEngines <= 0) return;
845 for(firstEngineItem=0; engineMenu[firstEngineItem].string; firstEngineItem++);
846 recentEngines = strdup(list);
848 p = strchr(list, '\n'); if(p == NULL) break;
849 if(i == 0) engineMenu[firstEngineItem++].string = "----"; // at least one valid item to add
851 if(firstEngineItem + i < 99)
852 engineMenu[firstEngineItem+i].string = strdup(list); // just set name; MenuProc stays NULL
853 i++; *p = '\n'; list = p + 1;
857 Enables icsEnables[] = {
858 { "File.MailMove", False },
859 { "File.ReloadCMailMessage", False },
860 { "Mode.MachineBlack", False },
861 { "Mode.MachineWhite", False },
862 { "Mode.AnalysisMode", False },
863 { "Mode.AnalyzeFile", False },
864 { "Mode.TwoMachines", False },
865 { "Mode.MachineMatch", False },
867 { "Engine.Hint", False },
868 { "Engine.Book", False },
869 { "Engine.MoveNow", False },
870 #ifndef OPTIONSDIALOG
871 { "PeriodicUpdates", False },
872 { "HideThinking", False },
873 { "PonderNextMove", False },
876 { "Engine.Engine#1Settings", False },
877 { "Engine.Engine#2Settings", False },
878 { "Engine.Load1stEngine", False },
879 { "Engine.Load2ndEngine", False },
880 { "Edit.Annotate", False },
881 { "Options.Match", False },
885 Enables ncpEnables[] = {
886 { "File.MailMove", False },
887 { "File.ReloadCMailMessage", False },
888 { "Mode.MachineWhite", False },
889 { "Mode.MachineBlack", False },
890 { "Mode.AnalysisMode", False },
891 { "Mode.AnalyzeFile", False },
892 { "Mode.TwoMachines", False },
893 { "Mode.MachineMatch", False },
894 { "Mode.ICSClient", False },
895 { "View.ICStextmenu", False },
896 { "View.ICSInputBox", False },
897 { "View.OpenChatWindow", False },
898 { "Action.", False },
899 { "Edit.Revert", False },
900 { "Edit.Annotate", False },
901 { "Engine.Engine#1Settings", False },
902 { "Engine.Engine#2Settings", False },
903 { "Engine.MoveNow", False },
904 { "Engine.RetractMove", False },
905 { "Options.ICS", False },
906 #ifndef OPTIONSDIALOG
907 { "Options.AutoFlag", False },
908 { "Options.AutoFlip View", False },
909 // { "Options.ICSAlarm", False },
910 { "Options.MoveSound", False },
911 { "Options.HideThinking", False },
912 { "Options.PeriodicUpdates", False },
913 { "Options.PonderNextMove", False },
915 { "Engine.Hint", False },
916 { "Engine.Book", False },
920 Enables gnuEnables[] = {
921 { "Mode.ICSClient", False },
922 { "View.ICStextmenu", False },
923 { "View.ICSInputBox", False },
924 { "View.OpenChatWindow", False },
925 { "Action.Accept", False },
926 { "Action.Decline", False },
927 { "Action.Rematch", False },
928 { "Action.Adjourn", False },
929 { "Action.StopExamining", False },
930 { "Action.StopObserving", False },
931 { "Action.UploadtoExamine", False },
932 { "Edit.Revert", False },
933 { "Edit.Annotate", False },
934 { "Options.ICS", False },
936 /* The next two options rely on SetCmailMode being called *after* */
937 /* SetGNUMode so that when GNU is being used to give hints these */
938 /* menu options are still available */
940 { "File.MailMove", False },
941 { "File.ReloadCMailMessage", False },
942 // [HGM] The following have been added to make a switch from ncp to GNU mode possible
943 { "Mode.MachineWhite", True },
944 { "Mode.MachineBlack", True },
945 { "Mode.AnalysisMode", True },
946 { "Mode.AnalyzeFile", True },
947 { "Mode.TwoMachines", True },
948 { "Mode.MachineMatch", True },
949 { "Engine.Engine#1Settings", True },
950 { "Engine.Engine#2Settings", True },
951 { "Engine.Hint", True },
952 { "Engine.Book", True },
953 { "Engine.MoveNow", True },
954 { "Engine.RetractMove", True },
959 Enables cmailEnables[] = {
961 { "Action.CallFlag", False },
962 { "Action.Draw", True },
963 { "Action.Adjourn", False },
964 { "Action.Abort", False },
965 { "Action.StopObserving", False },
966 { "Action.StopExamining", False },
967 { "File.MailMove", True },
968 { "File.ReloadCMailMessage", True },
972 Enables trainingOnEnables[] = {
973 { "Edit.EditComment", False },
974 { "Mode.Pause", False },
975 { "Edit.Forward", False },
976 { "Edit.Backward", False },
977 { "Edit.ForwardtoEnd", False },
978 { "Edit.BacktoStart", False },
979 { "Engine.MoveNow", False },
980 { "Edit.TruncateGame", False },
984 Enables trainingOffEnables[] = {
985 { "Edit.EditComment", True },
986 { "Mode.Pause", True },
987 { "Edit.Forward", True },
988 { "Edit.Backward", True },
989 { "Edit.ForwardtoEnd", True },
990 { "Edit.BacktoStart", True },
991 { "Engine.MoveNow", True },
992 { "Engine.TruncateGame", True },
996 Enables machineThinkingEnables[] = {
997 { "File.LoadGame", False },
998 // { "LoadNextGame", False },
999 // { "LoadPreviousGame", False },
1000 // { "ReloadSameGame", False },
1001 { "Edit.PasteGame", False },
1002 { "File.LoadPosition", False },
1003 // { "LoadNextPosition", False },
1004 // { "LoadPreviousPosition", False },
1005 // { "ReloadSamePosition", False },
1006 { "Edit.PastePosition", False },
1007 { "Mode.MachineWhite", False },
1008 { "Mode.MachineBlack", False },
1009 { "Mode.TwoMachines", False },
1010 // { "MachineMatch", False },
1011 { "Engine.RetractMove", False },
1015 Enables userThinkingEnables[] = {
1016 { "File.LoadGame", True },
1017 // { "LoadNextGame", True },
1018 // { "LoadPreviousGame", True },
1019 // { "ReloadSameGame", True },
1020 { "Edit.PasteGame", True },
1021 { "File.LoadPosition", True },
1022 // { "LoadNextPosition", True },
1023 // { "LoadPreviousPosition", True },
1024 // { "ReloadSamePosition", True },
1025 { "Edit.PastePosition", True },
1026 { "Mode.MachineWhite", True },
1027 { "Mode.MachineBlack", True },
1028 { "Mode.TwoMachines", True },
1029 // { "MachineMatch", True },
1030 { "Engine.RetractMove", True },
1037 SetMenuEnables(icsEnables);
1040 if (appData.zippyPlay && !appData.noChessProgram) { /* [DM] icsEngineAnalyze */
1041 EnableNamedMenuItem("Mode.AnalysisMode", True);
1042 EnableNamedMenuItem("Engine.Engine#1Settings", True);
1050 SetMenuEnables(ncpEnables);
1056 SetMenuEnables(gnuEnables);
1062 SetMenuEnables(cmailEnables);
1066 SetTrainingModeOn ()
1068 SetMenuEnables(trainingOnEnables);
1069 if (appData.showButtonBar) {
1070 EnableButtonBar(False);
1076 SetTrainingModeOff ()
1078 SetMenuEnables(trainingOffEnables);
1079 if (appData.showButtonBar) {
1080 EnableButtonBar(True);
1085 SetUserThinkingEnables ()
1087 if (appData.noChessProgram) return;
1088 SetMenuEnables(userThinkingEnables);
1092 SetMachineThinkingEnables ()
1094 if (appData.noChessProgram) return;
1095 SetMenuEnables(machineThinkingEnables);
1097 case MachinePlaysBlack:
1098 case MachinePlaysWhite:
1099 case TwoMachinesPlay:
1100 EnableNamedMenuItem(ModeToWidgetName(gameMode), True);
1108 GreyRevert (Boolean grey)
1110 EnableNamedMenuItem("Edit.Revert", !grey);
1111 EnableNamedMenuItem("Edit.Annotate", !grey);
1115 ModeToWidgetName (GameMode mode)
1118 case BeginningOfGame:
1119 if (appData.icsActive)
1120 return "Mode.ICSClient";
1121 else if (appData.noChessProgram ||
1122 *appData.cmailGameName != NULLCHAR)
1123 return "Mode.EditGame";
1125 return "Mode.MachineBlack";
1126 case MachinePlaysBlack:
1127 return "Mode.MachineBlack";
1128 case MachinePlaysWhite:
1129 return "Mode.MachineWhite";
1131 return "Mode.AnalysisMode";
1133 return "Mode.AnalyzeFile";
1134 case TwoMachinesPlay:
1135 return "Mode.TwoMachines";
1137 return "Mode.EditGame";
1138 case PlayFromGameFile:
1139 return "File.LoadGame";
1141 return "Mode.EditPosition";
1143 return "Mode.Training";
1144 case IcsPlayingWhite:
1145 case IcsPlayingBlack:
1149 return "Mode.ICSClient";
1157 InstallNewEngine (char *command, char *dir, char *variants, char *protocol)
1158 { // install the given engine in XBoard's -firstChessProgramNames
1159 char buf[MSG_SIZ], *quote = "";
1160 if(strchr(command, ' ')) { // quoting needed
1161 if(!strchr(command, '"')) quote = "\""; else
1162 if(!strchr(command, '\'')) quote = "'"; else {
1163 printf("Could not auto-install %s\n", command); // too complex
1166 // construct engine line, with optional -fd and -fUCI arguments
1167 snprintf(buf, MSG_SIZ, "%s%s%s", quote, command, quote);
1168 if(strcmp(dir, "") && strcmp(dir, "."))
1169 snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fd %s", dir);
1170 if(!strcmp(protocol, "uci"))
1171 snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fUCI");
1172 if(strstr(firstChessProgramNames, buf)) return; // avoid duplicats
1174 quote = malloc(strlen(firstChessProgramNames) + strlen(buf) + 2);
1175 sprintf(quote, "%s%s\n", firstChessProgramNames, buf);
1176 FREE(firstChessProgramNames); firstChessProgramNames = quote;
1179 #ifdef HAVE_DIRENT_H
1182 #include <sys/dir.h>
1183 #define dirent direct
1187 InstallFromDir (char *dirName, char *protocol, char *settingsFile)
1188 { // scan system for new plugin specs in given directory
1191 struct stat statBuf;
1192 time_t lastSaved = 0;
1195 if(!stat(settingsFile, &statBuf)) lastSaved = statBuf.st_mtime;
1196 snprintf(buf, 1024, "%s/%s", dirName, protocol);
1198 if(!(dir = opendir(buf))) return;
1199 while( (dp = readdir(dir))) {
1200 time_t installed = 0;
1201 if(!strstr(dp->d_name, ".eng")) continue; // to suppress . and ..
1202 snprintf(buf, 1024, "%s/%s/%s", dirName, protocol, dp->d_name);
1203 if(!stat(buf, &statBuf)) installed = statBuf.st_mtime;
1204 if(lastSaved == 0 || (int) (installed - lastSaved) > 0) { // first time we see it
1205 FILE *f = fopen(buf, "r");
1206 if(f) { // read the plugin-specs
1207 char engineCommand[1024], engineDir[1024], variants[1024];
1208 char bad=0, dummy, *engineCom = engineCommand;
1210 if(fscanf(f, "plugin spec %d.%d%c", &major, &minor, &dummy) != 3 ||
1211 fscanf(f, "%[^\n]%c", engineCommand, &dummy) != 2 ||
1212 fscanf(f, "%[^\n]%c", variants, &dummy) != 2) bad = 1;
1215 // uncomment following two lines for chess-only installs
1216 // if(!(p = strstr(variants, "chess")) ||
1217 // p != variants && p[-1] != ',' || p[5] && p[5] != ',') continue;
1218 // split off engine working directory (if any)
1219 strcpy(engineDir, "");
1220 if(sscanf(engineCommand, "cd %[^;];%c", engineDir, &dummy) == 2)
1221 engineCom = engineCommand + strlen(engineDir) + 4;
1222 InstallNewEngine(engineCom, engineDir, variants, protocol);
1230 AutoInstallProtocol (char *settingsFile, char *protocol)
1231 { // install new engines for given protocol (both from package and source)
1232 InstallFromDir("/usr/local/share/games/plugins", protocol, settingsFile);
1233 InstallFromDir("/usr/share/games/plugins", protocol, settingsFile);
1237 AutoInstall (char *settingsFile)
1238 { // install all new XBoard and UCI engines
1239 AutoInstallProtocol(settingsFile, "xboard");
1240 AutoInstallProtocol(settingsFile, "uci");
1246 #ifndef OPTIONSDIALOG
1247 if (appData.alwaysPromoteToQueen) {
1248 MarkMenuItem("Options.Always Queen", True);
1250 if (appData.animateDragging) {
1251 MarkMenuItem("Options.Animate Dragging", True);
1253 if (appData.animate) {
1254 MarkMenuItem("Options.Animate Moving", True);
1256 if (appData.autoCallFlag) {
1257 MarkMenuItem("Options.Auto Flag", True);
1259 if (appData.autoFlipView) {
1260 XtSetValues(XtNameToWidget(menuBarWidget,"Options.Auto Flip View", True);
1262 if (appData.blindfold) {
1263 MarkMenuItem("Options.Blindfold", True);
1265 if (appData.flashCount > 0) {
1266 MarkMenuItem("Options.Flash Moves", True);
1269 if (appData.highlightDragging) {
1270 MarkMenuItem("Options.Highlight Dragging", True);
1273 if (appData.highlightLastMove) {
1274 MarkMenuItem("Options.Highlight Last Move", True);
1276 if (appData.highlightMoveWithArrow) {
1277 MarkMenuItem("Options.Arrow", True);
1279 // if (appData.icsAlarm) {
1280 // MarkMenuItem("Options.ICS Alarm", True);
1282 if (appData.ringBellAfterMoves) {
1283 MarkMenuItem("Options.Move Sound", True);
1285 if (appData.oneClick) {
1286 MarkMenuItem("Options.OneClick", True);
1288 if (appData.periodicUpdates) {
1289 MarkMenuItem("Options.Periodic Updates", True);
1291 if (appData.ponderNextMove) {
1292 MarkMenuItem("Options.Ponder Next Move", True);
1294 if (appData.popupExitMessage) {
1295 MarkMenuItem("Options.Popup Exit Message", True);
1297 if (appData.popupMoveErrors) {
1298 MarkMenuItem("Options.Popup Move Errors", True);
1300 // if (appData.premove) {
1301 // MarkMenuItem("Options.Premove", True);
1303 if (appData.showCoords) {
1304 MarkMenuItem("Options.Show Coords", True);
1306 if (appData.hideThinkingFromHuman) {
1307 MarkMenuItem("Options.Hide Thinking", True);
1309 if (appData.testLegality) {
1310 MarkMenuItem("Options.Test Legality", True);
1313 if (saveSettingsOnExit) {
1314 MarkMenuItem("Options.SaveSettingsonExit", True);
1316 EnableNamedMenuItem("File.SaveSelected", False);
1318 // all XBoard builds get here, but not WinBoard...
1319 if(*appData.autoInstall) AutoInstall(settingsFileName);