X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=menus.c;h=a8086b7222ddce7b66df74fdde1186b8ec557f7b;hb=431df5521062e06be156dcf7a33332b0a5e0010e;hp=560e8af414a0d6532cce09fccfcfe68ba0745cdf;hpb=2aaf542114d8131c9fccc4e1ebffd45cb950d1d1;p=xboard.git diff --git a/menus.c b/menus.c index 560e8af..a8086b7 100644 --- a/menus.c +++ b/menus.c @@ -103,6 +103,532 @@ extern char *getenv(); # define N_(s) s #endif +/* + * Button/menu procedures + */ + +char *gameCopyFilename, *gamePasteFilename; +Boolean saveSettingsOnExit; +char *settingsFileName; + +void +LoadGameProc () +{ + if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) { + Reset(FALSE, TRUE); + } + FileNamePopUp(_("Load game file name?"), "", ".pgn .game", LoadGamePopUp, "rb"); +} + +void +LoadNextGameProc () +{ + ReloadGame(1); +} + +void +LoadPrevGameProc () +{ + ReloadGame(-1); +} + +void +ReloadGameProc () +{ + ReloadGame(0); +} + +void +LoadNextPositionProc () +{ + ReloadPosition(1); +} + +void +LoadPrevPositionProc () +{ + ReloadPosition(-1); +} + +void +ReloadPositionProc () +{ + ReloadPosition(0); +} + +void +LoadPositionProc() +{ + if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) { + Reset(FALSE, TRUE); + } + FileNamePopUp(_("Load position file name?"), "", ".fen .epd .pos", LoadPosition, "rb"); +} + +void +SaveGameProc () +{ + FileNamePopUp(_("Save game file name?"), + DefaultFileName(appData.oldSaveStyle ? "game" : "pgn"), + appData.oldSaveStyle ? ".game" : ".pgn", + SaveGame, "a"); +} + +void +SavePositionProc () +{ + FileNamePopUp(_("Save position file name?"), + DefaultFileName(appData.oldSaveStyle ? "pos" : "fen"), + appData.oldSaveStyle ? ".pos" : ".fen", + SavePosition, "a"); +} + +void +ReloadCmailMsgProc () +{ + ReloadCmailMsgEvent(FALSE); +} + +void +CopyFENToClipboard () +{ // wrapper to make call from back-end possible + CopyPositionProc(); +} + +void +CopyGameProc () +{ + int ret; + + ret = SaveGameToFile(gameCopyFilename, FALSE); + if (!ret) return; + + CopySomething(); +} + +void +CopyGameListProc () +{ + if(!SaveGameListAsText(fopen(gameCopyFilename, "w"))) return; + CopySomething(); +} + +void +AutoSaveGame () +{ + SaveGameProc(); +} + + +void +QuitProc () +{ + ExitEvent(0); +} + +void +AnalyzeModeProc () +{ + char buf[MSG_SIZ]; + + if (!first.analysisSupport) { + snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy); + DisplayError(buf, 0); + return; + } + /* [DM] icsEngineAnalyze [HGM] This is horrible code; reverse the gameMode and isEngineAnalyze tests! */ + if (appData.icsActive) { + if (gameMode != IcsObserving) { + snprintf(buf, MSG_SIZ, _("You are not observing a game")); + DisplayError(buf, 0); + /* secure check */ + if (appData.icsEngineAnalyze) { + if (appData.debugMode) + fprintf(debugFP, _("Found unexpected active ICS engine analyze \n")); + ExitAnalyzeMode(); + ModeHighlight(); + } + return; + } + /* if enable, use want disable icsEngineAnalyze */ + if (appData.icsEngineAnalyze) { + ExitAnalyzeMode(); + ModeHighlight(); + return; + } + appData.icsEngineAnalyze = TRUE; + if (appData.debugMode) + fprintf(debugFP, _("ICS engine analyze starting... \n")); + } +#ifndef OPTIONSDIALOG + if (!appData.showThinking) + ShowThinkingProc(); +#endif + + AnalyzeModeEvent(); +} + +void +AnalyzeFileProc () +{ + if (!first.analysisSupport) { + char buf[MSG_SIZ]; + snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy); + DisplayError(buf, 0); + return; + } +// Reset(FALSE, TRUE); +#ifndef OPTIONSDIALOG + if (!appData.showThinking) + ShowThinkingProc(); +#endif + AnalyzeFileEvent(); +// FileNamePopUp(_("File to analyze"), "", ".pgn .game", LoadGamePopUp, "rb"); + AnalysisPeriodicEvent(1); +} + +void +MatchProc () +{ + MatchEvent(2); +} + +void +EditCommentProc () +{ + Arg args[5]; + int j; + if (PopDown(1)) { // popdown succesful + MarkMenuItem("Edit Comment", False); + MarkMenuItem("Show Comments", False); + } else // was not up + EditCommentEvent(); +} + +void +IcsInputBoxProc () +{ + if (!PopDown(4)) ICSInputBoxPopUp(); +} + +void +AdjuWhiteProc () +{ + UserAdjudicationEvent(+1); +} + +void +AdjuBlackProc () +{ + UserAdjudicationEvent(-1); +} + +void +AdjuDrawProc () +{ + UserAdjudicationEvent(0); +} + +void +RevertProc () +{ + RevertEvent(False); +} + +void +AnnotateProc () +{ + RevertEvent(True); +} + +void +FlipViewProc () +{ + flipView = !flipView; + DrawPosition(True, NULL); +} + +void +SaveOnExitProc () +{ + Arg args[16]; + + saveSettingsOnExit = !saveSettingsOnExit; + + MarkMenuItem("Save Settings on Exit", saveSettingsOnExit); +} + +void +SaveSettingsProc () +{ + SaveSettings(settingsFileName); +} + +void +InfoProc () +{ + char buf[MSG_SIZ]; + snprintf(buf, sizeof(buf), "xterm -e info --directory %s --directory . -f %s &", + INFODIR, INFOFILE); + system(buf); +} + +void +ManProc () +{ // called from menu + ManInner(NULL, NULL, NULL, NULL); +} + +void +BugReportProc () +{ + char buf[MSG_SIZ]; + snprintf(buf, MSG_SIZ, "%s mailto:bug-xboard@gnu.org", appData.sysOpen); + system(buf); +} + +void +GuideProc () +{ + char buf[MSG_SIZ]; + snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/user_guide/UserGuide.html", appData.sysOpen); + system(buf); +} + +void +HomePageProc () +{ + char buf[MSG_SIZ]; + snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/", appData.sysOpen); + system(buf); +} + +void +NewsPageProc () +{ + char buf[MSG_SIZ]; + snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/whats_new/portal.html", appData.sysOpen); + system(buf); +} + +void +AboutProc () +{ + char buf[2 * MSG_SIZ]; +#if ZIPPY + char *zippy = _(" (with Zippy code)"); +#else + char *zippy = ""; +#endif + snprintf(buf, sizeof(buf), +_("%s%s\n\n" +"Copyright 1991 Digital Equipment Corporation\n" +"Enhancements Copyright 1992-2012 Free Software Foundation\n" +"Enhancements Copyright 2005 Alessandro Scotti\n\n" +"%s is free software and carries NO WARRANTY;" +"see the file COPYING for more information.\n\n" +"Visit XBoard on the web at: http://www.gnu.org/software/xboard/\n" +"Check out the newest features at: http://www.gnu.org/software/xboard/whats_new.html\n\n" +"Report bugs via email at: \n\n" + ), + programVersion, zippy, PACKAGE); + ErrorPopUp(_("About XBoard"), buf, FALSE); +} + +void +DebugProc () +{ + appData.debugMode = !appData.debugMode; +} + +void +NothingProc () +{ + return; +} + +#ifdef OPTIONSDIALOG +# define MARK_MENU_ITEM(X,Y) +#else +# define MARK_MENU_ITEM(X,Y) MarkMenuItem(X, Y) +#endif + +void +PonderNextMoveProc () +{ + Arg args[16]; + + PonderNextMoveEvent(!appData.ponderNextMove); + MARK_MENU_ITEM("Ponder Next Move", appData.ponderNextMove); +} + +void +AlwaysQueenProc () +{ + appData.alwaysPromoteToQueen = !appData.alwaysPromoteToQueen; + MARK_MENU_ITEM("Always Queen", appData.alwaysPromoteToQueen); +} + +void +AnimateDraggingProc () +{ + appData.animateDragging = !appData.animateDragging; + + if (appData.animateDragging) CreateAnimVars(); + MARK_MENU_ITEM("Animate Dragging", appData.animateDragging); +} + +void +AnimateMovingProc () +{ + appData.animate = !appData.animate; + if (appData.animate) CreateAnimVars(); + MARK_MENU_ITEM("Animate Moving", appData.animate); +} + +void +AutoflagProc () +{ + appData.autoCallFlag = !appData.autoCallFlag; + MARK_MENU_ITEM("Auto Flag", appData.autoCallFlag); +} + +void +AutoflipProc () +{ + appData.autoFlipView = !appData.autoFlipView; + MARK_MENU_ITEM("Auto Flip View", appData.autoFlipView); +} + +void +BlindfoldProc () +{ + appData.blindfold = !appData.blindfold; + MARK_MENU_ITEM("Blindfold", appData.blindfold); + DrawPosition(True, NULL); +} + +void +TestLegalityProc () +{ + appData.testLegality = !appData.testLegality; + MARK_MENU_ITEM("Test Legality", appData.testLegality); +} + + +void +FlashMovesProc () +{ + if (appData.flashCount == 0) { + appData.flashCount = 3; + } else { + appData.flashCount = -appData.flashCount; + } + MARK_MENU_ITEM("Flash Moves", appData.flashCount > 0); +} + +#if HIGHDRAG +void +HighlightDraggingProc () +{ + appData.highlightDragging = !appData.highlightDragging; + MARK_MENU_ITEM("Highlight Dragging", appData.highlightDragging); +} +#endif + +void +HighlightLastMoveProc () +{ + appData.highlightLastMove = !appData.highlightLastMove; + MARK_MENU_ITEM("Highlight Last Move", appData.highlightLastMove); +} + +void +HighlightArrowProc () +{ + appData.highlightMoveWithArrow = !appData.highlightMoveWithArrow; + MARK_MENU_ITEM("Arrow", appData.highlightMoveWithArrow); +} + +void +IcsAlarmProc () +{ + appData.icsAlarm = !appData.icsAlarm; +// MARK_MENU_ITEM("ICS Alarm", appData.icsAlarm); +} + +void +MoveSoundProc () +{ + appData.ringBellAfterMoves = !appData.ringBellAfterMoves; + MARK_MENU_ITEM("Move Sound", appData.ringBellAfterMoves); +} + +void +OneClickProc () +{ + appData.oneClick = !appData.oneClick; + MARK_MENU_ITEM("OneClick", appData.oneClick); +} + +void +PeriodicUpdatesProc () +{ + PeriodicUpdatesEvent(!appData.periodicUpdates); + MARK_MENU_ITEM("Periodic Updates", appData.periodicUpdates); +} + +void +PopupExitMessageProc () +{ + appData.popupExitMessage = !appData.popupExitMessage; + MARK_MENU_ITEM("Popup Exit Message", appData.popupExitMessage); +} + +void +PopupMoveErrorsProc () +{ + appData.popupMoveErrors = !appData.popupMoveErrors; + MARK_MENU_ITEM("Popup Move Errors", appData.popupMoveErrors); +} + +void +PremoveProc () +{ + appData.premove = !appData.premove; +// MARK_MENU_ITEM("Premove", appData.premove); +} + +void +ShowCoordsProc () +{ + appData.showCoords = !appData.showCoords; + MARK_MENU_ITEM("Show Coords", appData.showCoords); + DrawPosition(True, NULL); +} + +void +ShowThinkingProc () +{ + appData.showThinking = !appData.showThinking; // [HGM] thinking: taken out of ShowThinkingEvent + ShowThinkingEvent(); +} + +void +HideThinkingProc () +{ + Arg args[16]; + + appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman; // [HGM] thinking: taken out of ShowThinkingEvent + ShowThinkingEvent(); + + MARK_MENU_ITEM("Hide Thinking", appData.hideThinkingFromHuman); +} + +/* + * Menu definition tables + */ + MenuItem fileMenu[] = { {N_("New Game Ctrl+N"), "New Game", ResetGameEvent}, {N_("New Shuffle Game ..."), "New Shuffle Game", ShuffleMenuProc}, @@ -351,4 +877,373 @@ CreateMainMenus (Menu *mb) } } +Enables icsEnables[] = { + { "Mail Move", False }, + { "Reload CMail Message", False }, + { "Machine Black", False }, + { "Machine White", False }, + { "Analysis Mode", False }, + { "Analyze File", False }, + { "Two Machines", False }, + { "Machine Match", False }, +#ifndef ZIPPY + { "Hint", False }, + { "Book", False }, + { "Move Now", False }, +#ifndef OPTIONSDIALOG + { "Periodic Updates", False }, + { "Hide Thinking", False }, + { "Ponder Next Move", False }, +#endif +#endif + { "Engine #1 Settings", False }, + { "Engine #2 Settings", False }, + { "Load Engine", False }, + { "Annotate", False }, + { "Match", False }, + { NULL, False } +}; + +Enables ncpEnables[] = { + { "Mail Move", False }, + { "Reload CMail Message", False }, + { "Machine White", False }, + { "Machine Black", False }, + { "Analysis Mode", False }, + { "Analyze File", False }, + { "Two Machines", False }, + { "Machine Match", False }, + { "ICS Client", False }, + { "ICStex", False }, + { "ICS Input Box", False }, + { "Action", False }, + { "Revert", False }, + { "Annotate", False }, + { "Engine #1 Settings", False }, + { "Engine #2 Settings", False }, + { "Move Now", False }, + { "Retract Move", False }, + { "ICS", False }, +#ifndef OPTIONSDIALOG + { "Auto Flag", False }, + { "Auto Flip View", False }, +// { "ICS Alarm", False }, + { "Move Sound", False }, + { "Hide Thinking", False }, + { "Periodic Updates", False }, + { "Ponder Next Move", False }, +#endif + { "Hint", False }, + { "Book", False }, + { NULL, False } +}; + +Enables gnuEnables[] = { + { "ICS Client", False }, + { "ICStex", False }, + { "ICS Input Box", False }, + { "Accept", False }, + { "Decline", False }, + { "Rematch", False }, + { "Adjourn", False }, + { "Stop Examining", False }, + { "Stop Observing", False }, + { "Upload to Examine", False }, + { "Revert", False }, + { "Annotate", False }, + { "ICS", False }, + + /* The next two options rely on SetCmailMode being called *after* */ + /* SetGNUMode so that when GNU is being used to give hints these */ + /* menu options are still available */ + + { "Mail Move", False }, + { "Reload CMail Message", False }, + // [HGM] The following have been added to make a switch from ncp to GNU mode possible + { "Machine White", True }, + { "Machine Black", True }, + { "Analysis Mode", True }, + { "Analyze File", True }, + { "Two Machines", True }, + { "Machine Match", True }, + { "Engine #1 Settings", True }, + { "Engine #2 Settings", True }, + { "Hint", True }, + { "Book", True }, + { "Move Now", True }, + { "Retract Move", True }, + { "Action", True }, + { NULL, False } +}; + +Enables cmailEnables[] = { + { "Action", True }, + { "Call Flag", False }, + { "Draw", True }, + { "Adjourn", False }, + { "Abort", False }, + { "Stop Observing", False }, + { "Stop Examining", False }, + { "Mail Move", True }, + { "Reload CMail Message", True }, + { NULL, False } +}; + +Enables trainingOnEnables[] = { + { "Edit Comment", False }, + { "Pause", False }, + { "Forward", False }, + { "Backward", False }, + { "Forward to End", False }, + { "Back to Start", False }, + { "Move Now", False }, + { "Truncate Game", False }, + { NULL, False } +}; + +Enables trainingOffEnables[] = { + { "Edit Comment", True }, + { "Pause", True }, + { "Forward", True }, + { "Backward", True }, + { "Forward to End", True }, + { "Back to Start", True }, + { "Move Now", True }, + { "Truncate Game", True }, + { NULL, False } +}; + +Enables machineThinkingEnables[] = { + { "Load Game", False }, +// { "Load Next Game", False }, +// { "Load Previous Game", False }, +// { "Reload Same Game", False }, + { "Paste Game", False }, + { "Load Position", False }, +// { "Load Next Position", False }, +// { "Load Previous Position", False }, +// { "Reload Same Position", False }, + { "Paste Position", False }, + { "Machine White", False }, + { "Machine Black", False }, + { "Two Machines", False }, +// { "Machine Match", False }, + { "Retract Move", False }, + { NULL, False } +}; + +Enables userThinkingEnables[] = { + { "Load Game", True }, +// { "Load Next Game", True }, +// { "Load Previous Game", True }, +// { "Reload Same Game", True }, + { "Paste Game", True }, + { "Load Position", True }, +// { "Load Next Position", True }, +// { "Load Previous Position", True }, +// { "Reload Same Position", True }, + { "Paste Position", True }, + { "Machine White", True }, + { "Machine Black", True }, + { "Two Machines", True }, +// { "Machine Match", True }, + { "Retract Move", True }, + { NULL, False } +}; + +void +SetICSMode () +{ + SetMenuEnables(icsEnables); + +#if ZIPPY + if (appData.zippyPlay && !appData.noChessProgram) { /* [DM] icsEngineAnalyze */ + EnableMenuItem("Analysis Mode", True); + EnableMenuItem("Engine #1 Settings", True); + } +#endif +} + +void +SetNCPMode () +{ + SetMenuEnables(ncpEnables); +} +void +SetGNUMode () +{ + SetMenuEnables(gnuEnables); +} + +void +SetCmailMode () +{ + SetMenuEnables(cmailEnables); +} + +void +SetTrainingModeOn () +{ + SetMenuEnables(trainingOnEnables); + if (appData.showButtonBar) { + EnableButtonBar(False); + } + CommentPopDown(); +} + +void +SetTrainingModeOff () +{ + SetMenuEnables(trainingOffEnables); + if (appData.showButtonBar) { + EnableButtonBar(True); + } +} + +void +SetUserThinkingEnables () +{ + if (appData.noChessProgram) return; + SetMenuEnables(userThinkingEnables); +} + +void +SetMachineThinkingEnables () +{ + if (appData.noChessProgram) return; + SetMenuEnables(machineThinkingEnables); + switch (gameMode) { + case MachinePlaysBlack: + case MachinePlaysWhite: + case TwoMachinesPlay: + EnableMenuItem(ModeToWidgetName(gameMode), True); + break; + default: + break; + } +} + +void +GreyRevert (Boolean grey) +{ + MarkMenuItem("Revert", !grey); + MarkMenuItem("Annotate", !grey); +} + +char * +ModeToWidgetName (GameMode mode) +{ + switch (mode) { + case BeginningOfGame: + if (appData.icsActive) + return "ICS Client"; + else if (appData.noChessProgram || + *appData.cmailGameName != NULLCHAR) + return "Edit Game"; + else + return "Machine Black"; + case MachinePlaysBlack: + return "Machine Black"; + case MachinePlaysWhite: + return "Machine White"; + case AnalyzeMode: + return "Analysis Mode"; + case AnalyzeFile: + return "Analyze File"; + case TwoMachinesPlay: + return "Two Machines"; + case EditGame: + return "Edit Game"; + case PlayFromGameFile: + return "Load Game"; + case EditPosition: + return "Edit Position"; + case Training: + return "Training"; + case IcsPlayingWhite: + case IcsPlayingBlack: + case IcsObserving: + case IcsIdle: + case IcsExamining: + return "ICS Client"; + default: + case EndOfGame: + return NULL; + } +} + +void +InitMenuMarkers() +{ +#ifndef OPTIONSDIALOG + if (appData.alwaysPromoteToQueen) { + MarkMenuItem("Always Queen", True); + } + if (appData.animateDragging) { + MarkMenuItem("Animate Dragging", True); + } + if (appData.animate) { + MarkMenuItem("Animate Moving", True); + } + if (appData.autoCallFlag) { + MarkMenuItem("Auto Flag", True); + } + if (appData.autoFlipView) { + XtSetValues(XtNameToWidget(menuBarWidget,"Auto Flip View", True); + } + if (appData.blindfold) { + MarkMenuItem("Blindfold", True); + } + if (appData.flashCount > 0) { + MarkMenuItem("Flash Moves", True); + } +#if HIGHDRAG + if (appData.highlightDragging) { + MarkMenuItem("Highlight Dragging", True); + } +#endif + if (appData.highlightLastMove) { + MarkMenuItem("Highlight Last Move", True); + } + if (appData.highlightMoveWithArrow) { + MarkMenuItem("Arrow", True); + } +// if (appData.icsAlarm) { +// MarkMenuItem("ICS Alarm", True); +// } + if (appData.ringBellAfterMoves) { + MarkMenuItem("Move Sound", True); + } + if (appData.oneClick) { + MarkMenuItem("OneClick", True); + } + if (appData.periodicUpdates) { + MarkMenuItem("Periodic Updates", True); + } + if (appData.ponderNextMove) { + MarkMenuItem("Ponder Next Move", True); + } + if (appData.popupExitMessage) { + MarkMenuItem("Popup Exit Message", True); + } + if (appData.popupMoveErrors) { + MarkMenuItem("Popup Move Errors", True); + } +// if (appData.premove) { +// MarkMenuItem("Premove", True); +// } + if (appData.showCoords) { + MarkMenuItem("Show Coords", True); + } + if (appData.hideThinkingFromHuman) { + MarkMenuItem("Hide Thinking", True); + } + if (appData.testLegality) { + MarkMenuItem("Test Legality", True); + } +#endif + if (saveSettingsOnExit) { + MarkMenuItem("Save Settings on Exit", True); + } +}