X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xaw%2Fxboard.c;h=5db447a4f328676d62388bc7865264819543dd07;hb=3c6dcc05075c5073aac635c4ec6145f99730b325;hp=a834adf73735fa8e259474afd040d506f2b4f0d8;hpb=447740095b0491c84370083c0ee2bf281aa502bd;p=xboard.git diff --git a/xaw/xboard.c b/xaw/xboard.c index a834adf..5db447a 100644 --- a/xaw/xboard.c +++ b/xaw/xboard.c @@ -5,7 +5,7 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. * * The following terms apply to Digital Equipment Corporation's copyright * interest in XBoard: @@ -202,7 +202,6 @@ extern char *getenv(); #include "childio.h" #include "xgamelist.h" #include "xhistory.h" -#include "xevalgraph.h" #include "menus.h" #include "board.h" #include "dialogs.h" @@ -261,7 +260,6 @@ void TempForwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)) Boolean TempBackwardActive = False; void ManInner P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void DisplayMove P((int moveNumber)); -void ICSInitScript P((void)); void update_ics_width P(()); int CopyMemoProc P(()); @@ -388,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 "\ @@ -452,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"; @@ -998,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 () { @@ -1266,7 +1322,6 @@ main (int argc, char **argv) XtSetArg(args[1], XtNforeground, &buttonForegroundPixel); XtGetValues(optList[W_PAUSE].handle, args, 2); } - AppendEnginesToMenu(appData.recentEngineList); xBoardWindow = XtWindow(boardWidget); @@ -1326,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); @@ -1624,18 +1684,6 @@ KeyBindingProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) if(item) ((MenuProc *) item->proc) (); } -static void -MenuEngineSelect (Widget w, caddr_t addr, caddr_t index) -{ - RecentEngineEvent((int) (intptr_t) addr); -} - -void -AppendMenuItem (char *msg, int n) -{ - CreateMenuItem((Widget) optList[W_ENGIN].textValue, msg, (XtCallbackProc) MenuEngineSelect, n); -} - void SetupDropMenu () { @@ -1795,7 +1843,7 @@ HandlePV (Widget w, XEvent * event, String * params, Cardinal * nParams) MovePV(event->xmotion.x, event->xmotion.y, lineGap + BOARD_HEIGHT * (squareSize + lineGap)); } -static int savedIndex; /* gross that this is global */ +extern int savedIndex; /* gross that this is global */ void CommentClick (Widget w, XEvent * event, String * params, Cardinal * nParams) @@ -1812,27 +1860,6 @@ CommentClick (Widget w, XEvent * event, String * params, Cardinal * nParams) LoadVariation( index, val ); // [HGM] also does the actual moving to it, now } -void -EditCommentPopUp (int index, char *title, char *text) -{ - savedIndex = index; - if (text == NULL) text = ""; - NewCommentPopup(title, text, index); -} - -void -CommentPopUp (char *title, char *text) -{ - savedIndex = currentMove; // [HGM] vari - NewCommentPopup(title, text, currentMove); -} - -void -CommentPopDown () -{ - PopDown(CommentDlg); -} - /* Disable all user input other than deleting the window */ static int frozen = 0; @@ -2402,6 +2429,19 @@ SetClockIcon (int color) } } +#define INPUT_SOURCE_BUF_SIZE 8192 + +typedef struct { + CPKind kind; + int fd; + int lineByLine; + char *unused; + InputCallback func; + XtInputId xid; + char buf[INPUT_SOURCE_BUF_SIZE]; + VOIDSTAR closure; +} InputSource; + void DoInputCallback (caddr_t closure, int *source, XtInputId *xid) {