From 3c6dcc05075c5073aac635c4ec6145f99730b325 Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Sat, 16 Feb 2013 19:02:52 -0800 Subject: [PATCH] keyboard accelerators for both front ends. moved them out of the string definition, so that gtk can add them automatically. Also wrote a function that loads them for X11. TODO: add them again when creating X11 menu names --- gtk/xboard.c | 76 ++----------- gtk/xboard.h | 2 + gtk/xoptions.c | 8 ++ menus.c | 347 +++++++++++++++++++++++++++----------------------------- menus.h | 1 + xaw/xboard.c | 156 ++++++++++++++++++-------- 6 files changed, 301 insertions(+), 289 deletions(-) diff --git a/gtk/xboard.c b/gtk/xboard.c index e107746..b3a76bd 100644 --- a/gtk/xboard.c +++ b/gtk/xboard.c @@ -226,6 +226,9 @@ static GdkPixbuf *mainwindowIcon=NULL; static GdkPixbuf *WhiteIcon=NULL; static GdkPixbuf *BlackIcon=NULL; +/* key board accelerators */ +GtkAccelGroup *GtkAccelerators; + typedef unsigned int BoardSize; BoardSize boardSize; Boolean chessProgram; @@ -282,73 +285,10 @@ XtResource clientResources[] = { }; #endif +/* keyboard shortcuts not yet transistioned int menuitem @ menu.c */ char globalTranslations[] = - ":F9: MenuItem(Actions.Resign) \n \ - :Ctrln: MenuItem(File.NewGame) \n \ - :MetaV: MenuItem(File.NewVariant) \n \ - :Ctrlo: MenuItem(File.LoadGame) \n \ - :MetaNext: MenuItem(LoadNextGameProc) \n \ - :MetaPrior: MenuItem(LoadPrevGameProc) \n \ - :CtrlDown: LoadSelectedProc(3) \n \ + ":CtrlDown: LoadSelectedProc(3) \n \ :CtrlUp: LoadSelectedProc(-3) \n \ - :Ctrls: MenuItem(File.SaveGame) \n \ - :Ctrlc: MenuItem(Edit.CopyGame) \n \ - :Ctrlv: MenuItem(Edit.PasteGame) \n \ - :CtrlO: MenuItem(File.LoadPosition) \n \ - :ShiftNext: MenuItem(LoadNextPositionProc) \n \ - :ShiftPrior: MenuItem(LoadPrevPositionProc) \n \ - :CtrlS: MenuItem(File.SavePosition) \n \ - :CtrlC: MenuItem(Edit.CopyPosition) \n \ - :CtrlV: MenuItem(Edit.PastePosition) \n \ - :Ctrlq: MenuItem(File.Quit) \n \ - :Ctrlw: MenuItem(Mode.MachineWhite) \n \ - :Ctrlb: MenuItem(Mode.MachineBlack) \n \ - :Ctrlt: MenuItem(Mode.TwoMachines) \n \ - :Ctrla: MenuItem(Mode.AnalysisMode) \n \ - :Ctrlg: MenuItem(Mode.AnalyzeFile) \n \ - :Ctrle: MenuItem(Mode.EditGame) \n \ - :CtrlE: MenuItem(Mode.EditPosition) \n \ - :MetaO: MenuItem(View.EngineOutput) \n \ - :MetaE: MenuItem(View.EvaluationGraph) \n \ - :MetaG: MenuItem(View.GameList) \n \ - :MetaH: MenuItem(View.MoveHistory) \n \ - :Pause: MenuItem(Mode.Pause) \n \ - :F3: MenuItem(Action.Accept) \n \ - :F4: MenuItem(Action.Decline) \n \ - :F12: MenuItem(Action.Rematch) \n \ - :F5: MenuItem(Action.CallFlag) \n \ - :F6: MenuItem(Action.Draw) \n \ - :F7: MenuItem(Action.Adjourn) \n \ - :F8: MenuItem(Action.Abort) \n \ - :F10: MenuItem(Action.StopObserving) \n \ - :F11: MenuItem(Action.StopExamining) \n \ - :Ctrld: MenuItem(DebugProc) \n \ - :Meta CtrlF12: MenuItem(DebugProc) \n \ - :MetaEnd: MenuItem(Edit.ForwardtoEnd) \n \ - :MetaRight: MenuItem(Edit.Forward) \n \ - :MetaHome: MenuItem(Edit.BacktoStart) \n \ - :MetaLeft: MenuItem(Edit.Backward) \n \ - :Left: MenuItem(Edit.Backward) \n \ - :Right: MenuItem(Edit.Forward) \n \ - :Home: MenuItem(Edit.Revert) \n \ - :End: MenuItem(Edit.TruncateGame) \n \ - :Ctrlm: MenuItem(Engine.MoveNow) \n \ - :Ctrlx: MenuItem(Engine.RetractMove) \n \ - :MetaJ: MenuItem(Options.Adjudications) \n \ - :MetaU: MenuItem(Options.CommonEngine) \n \ - :MetaT: MenuItem(Options.TimeControl) \n \ - :CtrlP: MenuItem(PonderNextMove) \n " -#ifndef OPTIONSDIALOG - "\ - :CtrlQ: MenuItem(AlwaysQueenProc) \n \ - :CtrlF: MenuItem(AutoflagProc) \n \ - :CtrlA: MenuItem(AnimateMovingProc) \n \ - :CtrlL: MenuItem(TestLegalityProc) \n \ - :CtrlH: MenuItem(HideThinkingProc) \n " -#endif - "\ - :F1: MenuItem(Help.ManXBoard) \n \ - :F2: MenuItem(View.FlipView) \n \ :Return: TempBackwardProc() \n \ :Return: TempForwardProc() \n"; @@ -777,6 +717,9 @@ main (int argc, char **argv) /* set up GTK */ gtk_init (&argc, &argv); + /* set up keyboard accelerators group */ + GtkAccelerators = gtk_accel_group_new(); + programName = strrchr(argv[0], '/'); if (programName == NULL) programName = argv[0]; @@ -994,6 +937,9 @@ main (int argc, char **argv) InitMenuMarkers(); + // add accelerators to main shell + gtk_window_add_accel_group(GTK_WINDOW(shellWidget), GtkAccelerators); + /* * Create an icon. (Use two icons, to indicate whther it is white's or black's turn.) */ diff --git a/gtk/xboard.h b/gtk/xboard.h index 781871d..5326af8 100644 --- a/gtk/xboard.h +++ b/gtk/xboard.h @@ -151,6 +151,8 @@ void StopPV P((Widget w, XEvent * event, String * params, Cardinal * nParams)); extern char memoTranslations[]; +extern GtkAccelGroup *GtkAccelerators; + #if TODO_GTK extern Widget shells[]; extern Widget formWidget, shellWidget, boardWidget, menuBarWidget; diff --git a/gtk/xoptions.c b/gtk/xoptions.c index 6eea01c..5b4867c 100644 --- a/gtk/xoptions.c +++ b/gtk/xoptions.c @@ -428,6 +428,14 @@ CreateMenuPopup (Option *opt, int n, int def) } else entry = gtk_menu_item_new_with_label(msg); gtk_signal_connect_object (GTK_OBJECT (entry), "activate", GTK_SIGNAL_FUNC(MenuSelect), (gpointer) (intptr_t) ((n<<16)+i)); + if(mb[i].accel) { + guint accelerator_key; + GdkModifierType accelerator_mods; + + gtk_accelerator_parse(mb[i].accel, &accelerator_key, &accelerator_mods); + gtk_widget_add_accelerator (GTK_WIDGET(entry), "activate",GtkAccelerators, + accelerator_key, accelerator_mods, GTK_ACCEL_VISIBLE); + }; gtk_widget_show(entry); } else entry = gtk_separator_menu_item_new(); gtk_menu_append(GTK_MENU (menu), entry); diff --git a/menus.c b/menus.c index b8e531b..7a775cf 100644 --- a/menus.c +++ b/menus.c @@ -579,217 +579,208 @@ CreateBookDelayed () */ MenuItem fileMenu[] = { - {N_("New Game Ctrl+N"), "NewGame", ResetGameEvent}, - {N_("New Shuffle Game ..."), "NewShuffleGame", ShuffleMenuProc}, - {N_("New Variant ... Alt+Shift+V"), "NewVariant", NewVariantProc}, // [HGM] variant: not functional yet - {"----", NULL, NothingProc}, - {N_("Load Game Ctrl+O"), "LoadGame", LoadGameProc, CHECK}, - {N_("Load Position Ctrl+Shift+O"), "LoadPosition", LoadPositionProc}, -// {N_("Load Next Game"), "LoadNextGame", LoadNextGameProc}, -// {N_("Load Previous Game"), "LoadPreviousGame", LoadPrevGameProc}, -// {N_("Reload Same Game"), "ReloadSameGame", ReloadGameProc}, - {N_("Next Position Shift+PgDn"), "LoadNextPosition", LoadNextPositionProc}, - {N_("Prev Position Shift+PgUp"), "LoadPreviousPosition", LoadPrevPositionProc}, - {"----", NULL, NothingProc}, -// {N_("Reload Same Position"), "Reload Same Position", ReloadPositionProc}, - {N_("Save Game Ctrl+S"), "SaveGame", SaveGameProc}, - {N_("Save Position Ctrl+Shift+S"), "SavePosition", SavePositionProc}, - {N_("Save Games as Book"), "CreateBook", CreateBookDelayed}, - {"----", NULL, NothingProc}, - {N_("Mail Move"), "MailMove", MailMoveEvent}, - {N_("Reload CMail Message"), "ReloadCMailMessage", ReloadCmailMsgProc}, - {"----", NULL, NothingProc}, - {N_("Quit Ctr+Q"), "Quit", QuitProc}, - {NULL, NULL, NULL} + {N_("New Game"), "n", "NewGame", ResetGameEvent}, + {N_("New Shuffle Game ..."), NULL, "NewShuffleGame", ShuffleMenuProc}, + {N_("New Variant ..."), "v", "NewVariant", NewVariantProc},// [HGM] variant: not functional yet + {"----", NULL, NULL, NothingProc}, + {N_("Load Game"), "o", "LoadGame", LoadGameProc, CHECK}, + {N_("Load Position"), "o", "LoadPosition", LoadPositionProc}, + {N_("Next Position"), "Page_Down", "LoadNextPosition", LoadNextPositionProc}, + {N_("Prev Position"), "Page_Up", "LoadPreviousPosition", LoadPrevPositionProc}, + {"----", NULL, NULL, NothingProc}, + {N_("Save Game"), "s", "SaveGame", SaveGameProc}, + {N_("Save Position"), "s", "SavePosition", SavePositionProc}, + {N_("Save Games as Book"), NULL, "CreateBook", CreateBookDelayed}, + {"----", NULL, NULL, NothingProc}, + {N_("Mail Move"), NULL, "MailMove", MailMoveEvent}, + {N_("Reload CMail Message"), NULL, "ReloadCMailMessage", ReloadCmailMsgProc}, + {"----", NULL, NULL, NothingProc}, + {N_("Quit "), "q", "Quit", QuitProc}, + {NULL, NULL, NULL, NULL} }; MenuItem editMenu[] = { - {N_("Copy Game Ctrl+C"), "CopyGame", CopyGameProc}, - {N_("Copy Position Ctrl+Shift+C"), "CopyPosition", CopyPositionProc}, - {N_("Copy Game List"), "CopyGameList", CopyGameListProc}, - {"----", NULL, NothingProc}, - {N_("Paste Game Ctrl+V"), "PasteGame", PasteGameProc}, - {N_("Paste Position Ctrl+Shift+V"), "PastePosition", PastePositionProc}, - {"----", NULL, NothingProc}, - {N_("Edit Game Ctrl+E"), "EditGame", EditGameEvent}, - {N_("Edit Position Ctrl+Shift+E"), "EditPosition", EditPositionEvent}, - {N_("Edit Tags"), "EditTags", EditTagsProc}, - {N_("Edit Comment"), "EditComment", EditCommentProc}, - {N_("Edit Book"), "EditBook", EditBookEvent}, - {"----", NULL, NothingProc}, - {N_("Revert Home"), "Revert", RevertProc}, - {N_("Annotate"), "Annotate", AnnotateProc}, - {N_("Truncate Game End"), "TruncateGame", TruncateGameEvent}, - {"----", NULL, NothingProc}, - {N_("Backward Alt+Left"), "Backward", BackwardEvent}, - {N_("Forward Alt+Right"), "Forward", ForwardEvent}, - {N_("Back to Start Alt+Home"), "BacktoStart", ToStartEvent}, - {N_("Forward to End Alt+End"), "ForwardtoEnd", ToEndEvent}, - {NULL, NULL, NULL} + {N_("Copy Game"), "c", "CopyGame", CopyGameProc}, + {N_("Copy Position"), "c", "CopyPosition", CopyPositionProc}, + {N_("Copy Game List"), NULL, "CopyGameList", CopyGameListProc}, + {"----", NULL, NULL, NothingProc}, + {N_("Paste Game"), "v", "PasteGame", PasteGameProc}, + {N_("Paste Position"), "v", "PastePosition", PastePositionProc}, + {"----", NULL, NULL, NothingProc}, + {N_("Edit Game"), "e", "EditGame", EditGameEvent}, + {N_("Edit Position"), "e", "EditPosition", EditPositionEvent}, + {N_("Edit Tags"), NULL, "EditTags", EditTagsProc}, + {N_("Edit Comment"), NULL, "EditComment", EditCommentProc}, + {N_("Edit Book"), NULL, "EditBook", EditBookEvent}, + {"----", NULL, NULL, NothingProc}, + {N_("Revert"), "Home", "Revert", RevertProc}, + {N_("Annotate"), NULL, "Annotate", AnnotateProc}, + {N_("Truncate Game"), "End", "TruncateGame", TruncateGameEvent}, + {"----", NULL, NULL, NothingProc}, + {N_("Backward"), "Left", "Backward", BackwardEvent}, + {N_("Forward"), "Right", "Forward", ForwardEvent}, + {N_("Back to Start"), "Home", "BacktoStart", ToStartEvent}, + {N_("Forward to End"), "End", "ForwardtoEnd", ToEndEvent}, + {NULL, NULL, NULL, NULL} }; MenuItem viewMenu[] = { - {N_("Flip View F2"), "FlipView", FlipViewProc, CHECK}, - {"----", NULL, NothingProc}, - {N_("Engine Output Alt+Shift+O"), "EngineOutput", EngineOutputProc, CHECK}, - {N_("Move History Alt+Shift+H"), "MoveHistory", HistoryShowProc, CHECK}, // [HGM] hist: activate 4.2.7 code - {N_("Evaluation Graph Alt+Shift+E"), "EvaluationGraph", EvalGraphProc, CHECK}, - {N_("Game List Alt+Shift+G"), "GameList", ShowGameListProc, CHECK}, - {N_("ICS text menu"), "ICStextmenu", IcsTextProc, CHECK}, - {"----", NULL, NothingProc}, - {N_("Tags"), "Tags", EditTagsProc, CHECK}, - {N_("Comments"), "Comments", EditCommentProc, CHECK}, - {N_("ICS Input Box"), "ICSInputBox", IcsInputBoxProc, CHECK}, - {N_("Open Chat Window"), "OpenChatWindow", ChatProc, CHECK}, - {"----", NULL, NothingProc}, - {N_("Board..."), "Board", BoardOptionsProc}, - {N_("Game List Tags..."), "GameListTags", GameListOptionsProc}, - {NULL, NULL, NULL} + {N_("Flip View"), "F2", "FlipView", FlipViewProc, CHECK}, + {"----", NULL, NULL, NothingProc}, + {N_("Engine Output"), "o", "EngineOutput", EngineOutputProc, CHECK}, + {N_("Move History"), "h", "MoveHistory", HistoryShowProc, CHECK}, // [HGM] hist: activate 4.2.7 code + {N_("Evaluation Graph"), "e", "EvaluationGraph", EvalGraphProc, CHECK}, + {N_("Game List"), "g", "GameList", ShowGameListProc, CHECK}, + {N_("ICS text menu"), NULL, "ICStextmenu", IcsTextProc, CHECK}, + {"----", NULL, NULL, NothingProc}, + {N_("Tags"), NULL, "Tags", EditTagsProc, CHECK}, + {N_("Comments"), NULL, "Comments", EditCommentProc, CHECK}, + {N_("ICS Input Box"), NULL, "ICSInputBox", IcsInputBoxProc, CHECK}, + {N_("Open Chat Window"), NULL, "OpenChatWindow", ChatProc, CHECK}, + {"----", NULL, NULL, NothingProc}, + {N_("Board..."), NULL, "Board", BoardOptionsProc}, + {N_("Game List Tags..."), NULL, "GameListTags", GameListOptionsProc}, + {NULL, NULL, NULL, NULL} }; MenuItem modeMenu[] = { - {N_("Machine White Ctrl+W"), "MachineWhite", MachineWhiteEvent, RADIO }, - {N_("Machine Black Ctrl+B"), "MachineBlack", MachineBlackEvent, RADIO }, - {N_("Two Machines Ctrl+T"), "TwoMachines", TwoMachinesEvent, RADIO }, - {N_("Analysis Mode Ctrl+A"), "AnalysisMode", (MenuProc*) AnalyzeModeEvent, RADIO}, - {N_("Analyze Game Ctrl+G"), "AnalyzeFile", AnalyzeFileEvent, RADIO }, - {N_("Edit Game Ctrl+E"), "EditGame", EditGameEvent, RADIO }, - {N_("Edit Position Ctrl+Shift+E"), "EditPosition", EditPositionEvent, RADIO }, - {N_("Training"), "Training", TrainingEvent, RADIO }, - {N_("ICS Client"), "ICSClient", IcsClientEvent, RADIO }, - {"----", NULL, NothingProc}, - {N_("Machine Match"), "MachineMatch", MatchProc, CHECK }, - {N_("Pause Pause"), "Pause", PauseEvent, CHECK }, - {NULL, NULL, NULL} + {N_("Machine White"), "w", "MachineWhite", MachineWhiteEvent, RADIO }, + {N_("Machine Black"), "b", "MachineBlack", MachineBlackEvent, RADIO }, + {N_("Two Machines"), "t", "TwoMachines", TwoMachinesEvent, RADIO }, + {N_("Analysis Mode"), "a", "AnalysisMode", (MenuProc*) AnalyzeModeEvent, RADIO }, + {N_("Analyze Game"), "g", "AnalyzeFile", AnalyzeFileEvent, RADIO }, + {N_("Edit Game"), "e", "EditGame", EditGameEvent, RADIO }, + {N_("Edit Position"), "e", "EditPosition", EditPositionEvent, RADIO }, + {N_("Training"), NULL, "Training", TrainingEvent, RADIO }, + {N_("ICS Client"), NULL, "ICSClient", IcsClientEvent, RADIO }, + {"----", NULL, NULL, NothingProc}, + {N_("Machine Match"), NULL, "MachineMatch", MatchProc, CHECK }, + {N_("Pause"), "Pause", "Pause", PauseEvent, CHECK }, + {NULL, NULL, NULL, NULL} }; MenuItem actionMenu[] = { - {N_("Accept F3"), "Accept", AcceptEvent}, - {N_("Decline F4"), "Decline", DeclineEvent}, - {N_("Rematch F12"), "Rematch", RematchEvent}, - {"----", NULL, NothingProc}, - {N_("Call Flag F5"), "CallFlag", CallFlagEvent}, - {N_("Draw F6"), "Draw", DrawEvent}, - {N_("Adjourn F7"), "Adjourn", AdjournEvent}, - {N_("Abort F8"),"Abort", AbortEvent}, - {N_("Resign F9"), "Resign", ResignEvent}, - {"----", NULL, NothingProc}, - {N_("Stop Observing F10"), "StopObserving", StopObservingEvent}, - {N_("Stop Examining F11"), "StopExamining", StopExaminingEvent}, - {N_("Upload to Examine"), "UploadtoExamine", UploadGameEvent}, - {"----", NULL, NothingProc}, - {N_("Adjudicate to White"), "AdjudicatetoWhite", AdjuWhiteProc}, - {N_("Adjudicate to Black"), "AdjudicatetoBlack", AdjuBlackProc}, - {N_("Adjudicate Draw"), "AdjudicateDraw", AdjuDrawProc}, - {NULL, NULL, NULL} + {N_("Accept"), "F3", "Accept", AcceptEvent}, + {N_("Decline"), "F4", "Decline", DeclineEvent}, + {N_("Rematch"), "F12", "Rematch", RematchEvent}, + {"----", NULL, NULL, NothingProc}, + {N_("Call Flag"), "F5", "CallFlag", CallFlagEvent}, + {N_("Draw"), "F6", "Draw", DrawEvent}, + {N_("Adjourn"), "F7", "Adjourn", AdjournEvent}, + {N_("Abort"), "F8", "Abort", AbortEvent}, + {N_("Resign"), "F9", "Resign", ResignEvent}, + {"----", NULL, NULL, NothingProc}, + {N_("Stop Observing"), "F10", "StopObserving", StopObservingEvent}, + {N_("Stop Examining"), "F11", "StopExamining", StopExaminingEvent}, + {N_("Upload to Examine"), NULL, "UploadtoExamine", UploadGameEvent}, + {"----", NULL, NULL, NothingProc}, + {N_("Adjudicate to White"), NULL, "AdjudicatetoWhite", AdjuWhiteProc}, + {N_("Adjudicate to Black"), NULL, "AdjudicatetoBlack", AdjuBlackProc}, + {N_("Adjudicate Draw"), NULL, "AdjudicateDraw", AdjuDrawProc}, + {NULL, NULL, NULL, NULL} }; MenuItem engineMenu[100] = { - {N_("Load New 1st Engine ..."), "LoadNew1stEngine", LoadEngine1Proc}, - {N_("Load New 2nd Engine ..."), "LoadNew2ndEngine", LoadEngine2Proc}, - {"----", NULL, NothingProc}, - {N_("Engine #1 Settings ..."), "Engine#1Settings", FirstSettingsProc}, - {N_("Engine #2 Settings ..."), "Engine#2Settings", SecondSettingsProc}, - {"----", NULL, NothingProc}, - {N_("Hint"), "Hint", HintEvent}, - {N_("Book"), "Book", BookEvent}, - {"----", NULL, NothingProc}, - {N_("Move Now Ctrl+M"), "MoveNow", MoveNowEvent}, - {N_("Retract Move Ctrl+X"), "RetractMove", RetractMoveEvent}, - {NULL, NULL, NULL} + {N_("Load New 1st Engine ..."), NULL, "LoadNew1stEngine", LoadEngine1Proc}, + {N_("Load New 2nd Engine ..."), NULL, "LoadNew2ndEngine", LoadEngine2Proc}, + {"----", NULL, NULL, NothingProc}, + {N_("Engine #1 Settings ..."), NULL, "Engine#1Settings", FirstSettingsProc}, + {N_("Engine #2 Settings ..."), NULL, "Engine#2Settings", SecondSettingsProc}, + {"----", NULL, NULL, NothingProc}, + {N_("Hint"), NULL, "Hint", HintEvent}, + {N_("Book"), NULL, "Book", BookEvent}, + {"----", NULL, NULL, NothingProc}, + {N_("Move Now"), "m", "MoveNow", MoveNowEvent}, + {N_("Retract Move"), "x", "RetractMove", RetractMoveEvent}, + {NULL, NULL, NULL, NULL} }; MenuItem optionsMenu[] = { #ifdef OPTIONSDIALOG - {N_("General ..."), "General", OptionsProc}, + {N_("General ..."), NULL, "General", OptionsProc}, #endif - {N_("Time Control ... Alt+Shift+T"), "TimeControl", TimeControlProc}, - {N_("Common Engine ... Alt+Shift+U"), "CommonEngine", UciMenuProc}, - {N_("Adjudications ... Alt+Shift+J"), "Adjudications", EngineMenuProc}, - {N_("ICS ..."), "ICS", IcsOptionsProc}, - {N_("Match ..."), "Match", MatchOptionsProc}, - {N_("Load Game ..."), "LoadGame", LoadOptionsProc}, - {N_("Save Game ..."), "SaveGame", SaveOptionsProc}, -// {N_(" ..."), "", OptionsProc}, - {N_("Game List ..."), "GameList", GameListOptionsProc}, - {N_("Sounds ..."), "Sounds", SoundOptionsProc}, - {"----", NULL, NothingProc}, + {N_("Time Control ..."), "t", "TimeControl", TimeControlProc}, + {N_("Common Engine ..."), "u", "CommonEngine", UciMenuProc}, + {N_("Adjudications ..."), "j", "Adjudications", EngineMenuProc}, + {N_("ICS ..."), NULL, "ICS", IcsOptionsProc}, + {N_("Match ..."), NULL, "Match", MatchOptionsProc}, + {N_("Load Game ..."), NULL, "LoadGame", LoadOptionsProc}, + {N_("Save Game ..."), NULL, "SaveGame", SaveOptionsProc}, + {N_("Game List ..."), NULL, "GameList", GameListOptionsProc}, + {N_("Sounds ..."), NULL, "Sounds", SoundOptionsProc}, + {"----", NULL, NULL, NothingProc}, #ifndef OPTIONSDIALOG - {N_("Always Queen Ctrl+Shift+Q"), "AlwaysQueen", AlwaysQueenProc}, - {N_("Animate Dragging"), "AnimateDragging", AnimateDraggingProc}, - {N_("Animate Moving Ctrl+Shift+A"), "AnimateMoving", AnimateMovingProc}, - {N_("Auto Flag Ctrl+Shift+F"), "AutoFlag", AutoflagProc}, - {N_("Auto Flip View"), "AutoFlipView", AutoflipProc}, - {N_("Blindfold"), "Blindfold", BlindfoldProc}, - {N_("Flash Moves"), "FlashMoves", FlashMovesProc}, + {N_("Always Queen"), "q", "AlwaysQueen", AlwaysQueenProc}, + {N_("Animate Dragging"), NULL, "AnimateDragging", AnimateDraggingProc}, + {N_("Animate Moving"), "a", "AnimateMoving", AnimateMovingProc}, + {N_("Auto Flag"), "f", "AutoFlag", AutoflagProc}, + {N_("Auto Flip View"), NULL, "AutoFlipView", AutoflipProc}, + {N_("Blindfold"), NULL, "Blindfold", BlindfoldProc}, + {N_("Flash Moves"), NULL, "FlashMoves", FlashMovesProc}, #if HIGHDRAG - {N_("Highlight Dragging"), "HighlightDragging", HighlightDraggingProc}, + {N_("Highlight Dragging"), NULL, "HighlightDragging", HighlightDraggingProc}, #endif - {N_("Highlight Last Move"), "HighlightLastMove", HighlightLastMoveProc}, - {N_("Highlight With Arrow"), "HighlightWithArrow", HighlightArrowProc}, - {N_("Move Sound"), "MoveSound", MoveSoundProc}, -// {N_("ICS Alarm"), "ICSAlarm", IcsAlarmProc}, - {N_("One-Click Moving"), "OneClickMoving", OneClickProc}, - {N_("Periodic Updates"), "PeriodicUpdates", PeriodicUpdatesProc}, - {N_("Ponder Next Move Ctrl+Shift+P"), "PonderNextMove", PonderNextMoveProc}, - {N_("Popup Exit Message"), "PopupExitMessage", PopupExitMessageProc}, - {N_("Popup Move Errors"), "PopupMoveErrors", PopupMoveErrorsProc}, -// {N_("Premove"), "Premove", PremoveProc}, - {N_("Show Coords"), "ShowCoords", ShowCoordsProc}, - {N_("Hide Thinking Ctrl+Shift+H"), "HideThinking", HideThinkingProc}, - {N_("Test Legality Ctrl+Shift+L"), "TestLegality", TestLegalityProc}, - {"----", NULL, NothingProc}, + {N_("Highlight Last Move"), NULL, "HighlightLastMove", HighlightLastMoveProc}, + {N_("Highlight With Arrow"), NULL, "HighlightWithArrow", HighlightArrowProc}, + {N_("Move Sound"), NULL, "MoveSound", MoveSoundProc}, + {N_("One-Click Moving"), NULL, "OneClickMoving", OneClickProc}, + {N_("Periodic Updates"), NULL, "PeriodicUpdates", PeriodicUpdatesProc}, + {N_("Ponder Next Move"), "p", "PonderNextMove", PonderNextMoveProc}, + {N_("Popup Exit Message"), NULL, "PopupExitMessage", PopupExitMessageProc}, + {N_("Popup Move Errors"), NULL, "PopupMoveErrors", PopupMoveErrorsProc}, + {N_("Show Coords"), NULL, "ShowCoords", ShowCoordsProc}, + {N_("Hide Thinking"), "h", "HideThinking", HideThinkingProc}, + {N_("Test Legality"), "l", "TestLegality", TestLegalityProc}, + {"----", NULL, NULL, NothingProc}, #endif - {N_("Save Settings Now"), "SaveSettingsNow", SaveSettingsProc}, - {N_("Save Settings on Exit"), "SaveSettingsonExit", SaveOnExitProc, CHECK }, - {NULL, NULL, NULL} + {N_("Save Settings Now"), NULL, "SaveSettingsNow", SaveSettingsProc}, + {N_("Save Settings on Exit"), NULL, "SaveSettingsonExit", SaveOnExitProc, CHECK }, + {NULL, NULL, NULL, NULL} }; MenuItem helpMenu[] = { - {N_("Info XBoard"), "InfoXBoard", InfoProc}, - {N_("Man XBoard F1"), "ManXBoard", ManProc}, - {"----", NULL, NothingProc}, - {N_("XBoard Home Page"), "XBoardHomePage", HomePageProc}, - {N_("On-line User Guide"), "On-lineUserGuide", GuideProc}, - {N_("Development News"), "DevelopmentNews", NewsPageProc}, - {N_("e-Mail Bug Report"), "e-MailBugReport", BugReportProc}, - {"----", NULL, NothingProc}, - {N_("About XBoard"), "AboutXBoard", AboutProc}, - {NULL, NULL, NULL} + {N_("Info XBoard"), NULL, "InfoXBoard", InfoProc}, + {N_("Man XBoard"), "F1", "ManXBoard", ManProc}, + {"----", NULL, NULL, NothingProc}, + {N_("XBoard Home Page"), NULL, "XBoardHomePage", HomePageProc}, + {N_("On-line User Guide"), NULL, "On-lineUserGuide", GuideProc}, + {N_("Development News"), NULL, "DevelopmentNews", NewsPageProc}, + {N_("e-Mail Bug Report"), NULL, "e-MailBugReport", BugReportProc}, + {"----", NULL, NULL, NothingProc}, + {N_("About XBoard"), NULL, "AboutXBoard", AboutProc}, + {NULL, NULL, NULL, NULL} }; MenuItem noMenu[] = { - { "", "LoadNextGame", LoadNextGameProc }, - { "", "LoadPrevGame", LoadPrevGameProc }, - { "", "ReloadGame", ReloadGameProc }, - { "", "ReloadPosition", ReloadPositionProc }, + { "", "Next" ,"LoadNextGame", LoadNextGameProc }, + { "", "Prior" ,"LoadPrevGame", LoadPrevGameProc }, + { "", NULL,"ReloadGame", ReloadGameProc }, + { "", NULL,"ReloadPosition", ReloadPositionProc }, #ifndef OPTIONSDIALOG - { "", "AlwaysQueen", AlwaysQueenProc }, - { "", "AnimateDragging", AnimateDraggingProc }, - { "", "AnimateMoving", AnimateMovingProc }, - { "", "Autoflag", AutoflagProc }, - { "", "Autoflip", AutoflipProc }, - { "", "Blindfold", BlindfoldProc }, - { "", "FlashMoves", FlashMovesProc }, + { "", NULL,"AlwaysQueen", AlwaysQueenProc }, + { "", NULL,"AnimateDragging", AnimateDraggingProc }, + { "", NULL,"AnimateMoving", AnimateMovingProc }, + { "", NULL,"Autoflag", AutoflagProc }, + { "", NULL,"Autoflip", AutoflipProc }, + { "", NULL,"Blindfold", BlindfoldProc }, + { "", NULL,"FlashMoves", FlashMovesProc }, #if HIGHDRAG - { "", "HighlightDragging", HighlightDraggingProc }, + { "", NULL,"HighlightDragging", HighlightDraggingProc }, #endif - { "", "HighlightLastMove", HighlightLastMoveProc }, -// { "", "IcsAlarm", IcsAlarmProc }, - { "", "MoveSound", MoveSoundProc }, - { "", "PeriodicUpdates", PeriodicUpdatesProc }, - { "", "PopupExitMessage", PopupExitMessageProc }, - { "", "PopupMoveErrors", PopupMoveErrorsProc }, -// { "", "Premove", PremoveProc }, - { "", "ShowCoords", ShowCoordsProc }, - { "", "ShowThinking", ShowThinkingProc }, - { "", "HideThinking", HideThinkingProc }, - { "", "TestLegality", TestLegalityProc }, + { "", NULL,"HighlightLastMove", HighlightLastMoveProc }, + { "", NULL,"MoveSound", MoveSoundProc }, + { "", NULL,"PeriodicUpdates", PeriodicUpdatesProc }, + { "", NULL,"PopupExitMessage", PopupExitMessageProc }, + { "", NULL,"PopupMoveErrors", PopupMoveErrorsProc }, + { "", NULL,"ShowCoords", ShowCoordsProc }, + { "", NULL,"ShowThinking", ShowThinkingProc }, + { "", NULL,"HideThinking", HideThinkingProc }, + { "", NULL,"TestLegality", TestLegalityProc }, #endif - { "", "AboutGame", AboutGameEvent }, - { "", "DebugProc", DebugProc }, - { "", "Nothing", NothingProc }, - {NULL, NULL, NULL} + { "", NULL,"AboutGame", AboutGameEvent }, + { "", "d" ,"DebugProc", DebugProc }, + { "", NULL,"Nothing", NothingProc }, + {NULL, NULL, NULL, NULL} }; Menu menuBar[] = { @@ -810,7 +801,7 @@ MenuNameToItem (char *menuName) int i=0; char buf[MSG_SIZ], *p; MenuItem *menuTab; - static MenuItem a = { NULL, NULL, NothingProc }; + static MenuItem a = { NULL, NULL, NULL, NothingProc }; extern Option mainOptions[]; safeStrCpy(buf, menuName, MSG_SIZ); p = strchr(buf, '.'); diff --git a/menus.h b/menus.h index bc6c504..7d810d4 100644 --- a/menus.h +++ b/menus.h @@ -55,6 +55,7 @@ typedef void MenuProc P((void)); typedef struct { char *string; + char *accel; char *ref; MenuProc *proc; void *handle; diff --git a/xaw/xboard.c b/xaw/xboard.c index 40e901c..5db447a 100644 --- a/xaw/xboard.c +++ b/xaw/xboard.c @@ -386,60 +386,17 @@ XtActionsRec boardActions[] = { }; char globalTranslations[] = - ":F9: MenuItem(Actions.Resign) \n \ - :Ctrln: MenuItem(File.NewGame) \n \ - :MetaV: MenuItem(File.NewVariant) \n \ - :Ctrlo: MenuItem(File.LoadGame) \n \ - :MetaNext: MenuItem(LoadNextGameProc) \n \ + ":MetaNext: MenuItem(LoadNextGameProc) \n \ :MetaPrior: MenuItem(LoadPrevGameProc) \n \ :CtrlDown: LoadSelectedProc(3) \n \ :CtrlUp: LoadSelectedProc(-3) \n \ - :Ctrls: MenuItem(File.SaveGame) \n \ - :Ctrlc: MenuItem(Edit.CopyGame) \n \ - :Ctrlv: MenuItem(Edit.PasteGame) \n \ - :CtrlO: MenuItem(File.LoadPosition) \n \ :ShiftNext: MenuItem(LoadNextPositionProc) \n \ :ShiftPrior: MenuItem(LoadPrevPositionProc) \n \ - :CtrlS: MenuItem(File.SavePosition) \n \ - :CtrlC: MenuItem(Edit.CopyPosition) \n \ - :CtrlV: MenuItem(Edit.PastePosition) \n \ - :Ctrlq: MenuItem(File.Quit) \n \ - :Ctrlw: MenuItem(Mode.MachineWhite) \n \ - :Ctrlb: MenuItem(Mode.MachineBlack) \n \ - :Ctrlt: MenuItem(Mode.TwoMachines) \n \ - :Ctrla: MenuItem(Mode.AnalysisMode) \n \ - :Ctrlg: MenuItem(Mode.AnalyzeFile) \n \ - :Ctrle: MenuItem(Mode.EditGame) \n \ - :CtrlE: MenuItem(Mode.EditPosition) \n \ - :MetaO: MenuItem(View.EngineOutput) \n \ - :MetaE: MenuItem(View.EvaluationGraph) \n \ - :MetaG: MenuItem(View.GameList) \n \ - :MetaH: MenuItem(View.MoveHistory) \n \ :Pause: MenuItem(Mode.Pause) \n \ - :F3: MenuItem(Action.Accept) \n \ - :F4: MenuItem(Action.Decline) \n \ - :F12: MenuItem(Action.Rematch) \n \ - :F5: MenuItem(Action.CallFlag) \n \ - :F6: MenuItem(Action.Draw) \n \ - :F7: MenuItem(Action.Adjourn) \n \ - :F8: MenuItem(Action.Abort) \n \ - :F10: MenuItem(Action.StopObserving) \n \ - :F11: MenuItem(Action.StopExamining) \n \ :Ctrld: MenuItem(DebugProc) \n \ :Meta CtrlF12: MenuItem(DebugProc) \n \ - :MetaEnd: MenuItem(Edit.ForwardtoEnd) \n \ - :MetaRight: MenuItem(Edit.Forward) \n \ - :MetaHome: MenuItem(Edit.BacktoStart) \n \ - :MetaLeft: MenuItem(Edit.Backward) \n \ :Left: MenuItem(Edit.Backward) \n \ :Right: MenuItem(Edit.Forward) \n \ - :Home: MenuItem(Edit.Revert) \n \ - :End: MenuItem(Edit.TruncateGame) \n \ - :Ctrlm: MenuItem(Engine.MoveNow) \n \ - :Ctrlx: MenuItem(Engine.RetractMove) \n \ - :MetaJ: MenuItem(Options.Adjudications) \n \ - :MetaU: MenuItem(Options.CommonEngine) \n \ - :MetaT: MenuItem(Options.TimeControl) \n \ :CtrlP: MenuItem(PonderNextMove) \n " #ifndef OPTIONSDIALOG "\ @@ -450,8 +407,6 @@ char globalTranslations[] = :CtrlH: MenuItem(HideThinkingProc) \n " #endif "\ - :F1: MenuItem(Help.ManXBoard) \n \ - :F2: MenuItem(View.FlipView) \n \ :Return: TempBackwardProc() \n \ :Return: TempForwardProc() \n"; @@ -996,6 +951,109 @@ PrintArg (ArgType t) return p; } +char * +GenerateGlobalTranslationTable (void) +{ + /* go through all menu items and extract the keyboard shortcuts, so that X11 can load them */ + char *output; + + int i,j; + MenuItem *mi; + + output = strdup(""); + + /* loop over all menu entries */ + for( i=0; menuBar[i].mi ; i++) + { + mi = menuBar[i].mi; + for(j=0; mi[j].proc; j++) + { + if (mi[j].accel) + { + int ctrl = 0; + int shift = 0; + int alt = 0; + + char *key,*test, *mods; + + /* check for Ctrl/Alt */ + if( strstr(mi[j].accel, "") ) ctrl = 1; + if( strstr(mi[j].accel, "") ) shift = 1; + if( strstr(mi[j].accel, "") ) alt = 1; + + /* remove all <...> */ + test = strrchr(mi[j].accel, '>'); + if ( test==NULL ) + key = strdup(mi[j].accel); + else + key = strdup(++test); // remove ">" + + /* instead of shift X11 uses the uppercase letter directly*/ + if (shift && strlen(key)==1 ) + { + *key = toupper(*key); + shift = 0; + } + + /* handle some special cases which have different names in X11 */ + if ( strncmp(key, "Page_Down", 9) == 0 ) + { + free(key); + key=strdup("Next"); + } + else if ( strncmp(key, "Page_Up", 7) == 0 ) + { + free(key); + key=strdup("Prior"); + }; + + /* create string of mods */ + if (ctrl) + mods = strdup("Ctrl "); + else + mods = strdup(""); + + if(alt) + { + mods = realloc(mods, strlen(mods) + strlen("Meta ")+1); + strncat(mods, "Meta ", 5); + }; + + if(shift) + { + mods = realloc(mods, strlen(mods) + strlen("Shift ")+1); + strncat(mods, "Shift ", 6); + }; + + // remove trailing space + if( isspace(mods[strlen(mods)-1]) ) + mods[strlen(mods)-1]='\0'; + + /* get the name for the callback, we can use MenuItem() here that will call KeyBindingProc */ + size_t namesize = snprintf(NULL, 0, "%s.%s", menuBar[i].ref, mi[j].ref); + char *name = malloc(namesize+1); + snprintf(name, namesize+1, "%s.%s", menuBar[i].ref, mi[j].ref); + + size_t buffersize = snprintf(NULL, 0, ":%s%s: MenuItem(%s) \n ", mods, key, name); + char *buffer = malloc(buffersize+1); + snprintf(buffer, buffersize+1, ":%s%s: MenuItem(%s) \n ", mods, key, name); + + /* add string to the output */ + output = realloc(output, strlen(output) + strlen(buffer)+1); + strncat(output, buffer, strlen(buffer)); + + /* clean up */ + free(key); + free(buffer); + free(name); + free(mods); + } + } + } + return output; +} + + void PrintOptions () { @@ -1323,8 +1381,13 @@ main (int argc, char **argv) if (appData.animate || appData.animateDragging) CreateAnimVars(); + + char *TranslationsTableMenus=GenerateGlobalTranslationTable (); + XtAugmentTranslations(formWidget, XtParseTranslationTable(globalTranslations)); + XtAugmentTranslations(formWidget, + XtParseTranslationTable(TranslationsTableMenus)); XtAddEventHandler(formWidget, KeyPressMask, False, (XtEventHandler) MoveTypeInProc, NULL); @@ -2528,3 +2591,4 @@ UpdateLogos (int displ) if(displ) DisplayLogos(&optList[W_WHITE-1], &optList[W_BLACK+1]); return; } + -- 1.7.0.4