X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xboard.c;h=1cf2ef270722b25411e8525337a67d72f333ecc0;hb=e1c9a1c270df4b13175131a12fd1940fb22edd90;hp=cbe40e1419362727e61e953f785fcd0b6d00d18b;hpb=99567fe1b4652cd8b448638817090158773280be;p=xboard.git diff --git a/xboard.c b/xboard.c index cbe40e1..1cf2ef2 100644 --- a/xboard.c +++ b/xboard.c @@ -5,7 +5,7 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010 Free Software Foundation, Inc. * * The following terms apply to Digital Equipment Corporation's copyright * interest in XBoard: @@ -233,6 +233,8 @@ typedef struct { } Menu; int main P((int argc, char **argv)); +FILE * XsraSelFile P((Widget w, char *prompt, char *ok, char *cancel, char *failed, + char *init_path, char *mode, int (*show_entry)(), char **name_return)); RETSIGTYPE CmailSigHandler P((int sig)); RETSIGTYPE IntSigHandler P((int sig)); RETSIGTYPE TermSizeSigHandler P((int sig)); @@ -355,15 +357,19 @@ void AdjuWhiteProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void AdjuBlackProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void AdjuDrawProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void EnterKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void UpKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void DownKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void StopObservingProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void StopExaminingProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void UploadProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void BackwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void ForwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void ToStartProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void ToEndProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void RevertProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void AnnotateProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void TruncateGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void RetractMoveProc P((Widget w, XEvent *event, String *prms, @@ -638,6 +644,7 @@ MenuItem actionMenu[] = { {"----", NothingProc}, {N_("Stop Observing"), StopObservingProc}, {N_("Stop Examining"), StopExaminingProc}, + {N_("Upload to Examine"), UploadProc}, {"----", NothingProc}, {N_("Adjudicate to White"), AdjuWhiteProc}, {N_("Adjudicate to Black"), AdjuBlackProc}, @@ -651,6 +658,7 @@ MenuItem stepMenu[] = { {N_("Back to Start"), ToStartProc}, {N_("Forward to End"), ToEndProc}, {N_("Revert"), RevertProc}, + {N_("Annotate"), AnnotateProc}, {N_("Truncate Game"), TruncateGameProc}, {"----", NothingProc}, {N_("Move Now"), MoveNowProc}, @@ -898,13 +906,17 @@ XtActionsRec boardActions[] = { { "AdjuBlackProc", AdjuBlackProc }, { "AdjuDrawProc", AdjuDrawProc }, { "EnterKeyProc", EnterKeyProc }, + { "UpKeyProc", UpKeyProc }, + { "DownKeyProc", DownKeyProc }, { "StopObservingProc", StopObservingProc }, { "StopExaminingProc", StopExaminingProc }, + { "UploadProc", UploadProc }, { "BackwardProc", BackwardProc }, { "ForwardProc", ForwardProc }, { "ToStartProc", ToStartProc }, { "ToEndProc", ToEndProc }, { "RevertProc", RevertProc }, + { "AnnotateProc", AnnotateProc }, { "TruncateGameProc", TruncateGameProc }, { "MoveNowProc", MoveNowProc }, { "RetractMoveProc", RetractMoveProc }, @@ -1014,6 +1026,8 @@ char whiteTranslations[] = ": WhiteClock()\n"; char blackTranslations[] = ": BlackClock()\n"; char ICSInputTranslations[] = + "Up: UpKeyProc() \n " + "Down: DownKeyProc() \n " "Return: EnterKeyProc() \n"; String xboardResources[] = { @@ -2469,7 +2483,7 @@ XBoard square size (hint): %d\n\ /* Why is the following needed on some versions of X instead * of a translation? */ - XtAddEventHandler(boardWidget, ExposureMask, False, + XtAddEventHandler(boardWidget, ExposureMask|PointerMotionMask, False, (XtEventHandler) EventProc, NULL); /* end why */ @@ -2613,6 +2627,12 @@ GreyRevert(grey) } else { XtSetSensitive(w, !grey); } + w = XtNameToWidget(menuBarWidget, "menuStep.Annotate"); + if (w == NULL) { + DisplayError("menuStep.Annotate", 0); + } else { + XtSetSensitive(w, !grey); + } } void @@ -2648,6 +2668,7 @@ Enables icsEnables[] = { { "menuOptions.Hide Thinking", False }, { "menuOptions.Ponder Next Move", False }, #endif + { "menuStep.Annotate", False }, { NULL, False } }; @@ -2663,6 +2684,7 @@ Enables ncpEnables[] = { { "menuMode.ICS Input Box", False }, { "Action", False }, { "menuStep.Revert", False }, + { "menuStep.Annotate", False }, { "menuStep.Move Now", False }, { "menuStep.Retract Move", False }, { "menuOptions.Auto Comment", False }, @@ -2691,7 +2713,9 @@ Enables gnuEnables[] = { { "menuAction.Adjourn", False }, { "menuAction.Stop Examining", False }, { "menuAction.Stop Observing", False }, + { "menuAction.Upload to Examine", False }, { "menuStep.Revert", False }, + { "menuStep.Annotate", False }, { "menuOptions.Auto Comment", False }, { "menuOptions.Auto Observe", False }, { "menuOptions.Auto Raise Board", False }, @@ -2852,6 +2876,51 @@ SetMachineThinkingEnables() } } +// [HGM] code borrowed from winboard.c (which should thus go to backend.c!) +#define HISTORY_SIZE 64 +static char *history[HISTORY_SIZE]; +int histIn = 0, histP = 0; + +void +SaveInHistory(char *cmd) +{ + if (history[histIn] != NULL) { + free(history[histIn]); + history[histIn] = NULL; + } + if (*cmd == NULLCHAR) return; + history[histIn] = StrSave(cmd); + histIn = (histIn + 1) % HISTORY_SIZE; + if (history[histIn] != NULL) { + free(history[histIn]); + history[histIn] = NULL; + } + histP = histIn; +} + +char * +PrevInHistory(char *cmd) +{ + int newhp; + if (histP == histIn) { + if (history[histIn] != NULL) free(history[histIn]); + history[histIn] = StrSave(cmd); + } + newhp = (histP - 1 + HISTORY_SIZE) % HISTORY_SIZE; + if (newhp == histIn || history[newhp] == NULL) return NULL; + histP = newhp; + return history[histP]; +} + +char * +NextInHistory() +{ + if (histP == histIn) return NULL; + histP = (histP + 1) % HISTORY_SIZE; + return history[histP]; +} +// end of borrowed code + #define Abs(n) ((n)<0 ? -(n) : (n)) /* @@ -3722,6 +3791,7 @@ void PieceMenuPopup(w, event, params, num_params) switch(menuNr) { case 0: whichMenu = params[0]; break; case 1: SetupDropMenu(); whichMenu = "menuD"; break; + case 2: case -1: if (errorUp) ErrorPopDown(); default: return; } @@ -3832,14 +3902,18 @@ SetHighlights(fromX, fromY, toX, toY) if (hi1X >= 0 && hi1Y >= 0) { drawHighlight(hi1X, hi1Y, lineGC); } + } // [HGM] first erase both, then draw new! + if (hi2X != toX || hi2Y != toY) { + if (hi2X >= 0 && hi2Y >= 0) { + drawHighlight(hi2X, hi2Y, lineGC); + } + } + if (hi1X != fromX || hi1Y != fromY) { if (fromX >= 0 && fromY >= 0) { drawHighlight(fromX, fromY, highlineGC); } } if (hi2X != toX || hi2Y != toY) { - if (hi2X >= 0 && hi2Y >= 0) { - drawHighlight(hi2X, hi2Y, lineGC); - } if (toX >= 0 && toY >= 0) { drawHighlight(toX, toY, highlineGC); } @@ -4218,6 +4292,8 @@ void EventProc(widget, unused, event) if (event->xexpose.count > 0) return; /* no clipping is done */ XDrawPosition(widget, True, NULL); break; + case MotionNotify: + if(SeekGraphClick(Press, event->xbutton.x, event->xbutton.y, 1)) break; default: return; } @@ -4298,6 +4374,36 @@ static int check_castle_draw(newb, oldb, rrow, rcol) return 0; } +// [HGM] seekgraph: some low-level drawing routines cloned from xevalgraph +void DrawSeekAxis( int x, int y, int xTo, int yTo ) +{ + XDrawLine(xDisplay, xBoardWindow, lineGC, x, y, xTo, yTo); +} + +void DrawSeekBackground( int left, int top, int right, int bottom ) +{ + XFillRectangle(xDisplay, xBoardWindow, lightSquareGC, left, top, right-left, bottom-top); +} + +void DrawSeekText(char *buf, int x, int y) +{ + XDrawString(xDisplay, xBoardWindow, coordGC, x, y+4, buf, strlen(buf)); +} + +void DrawSeekDot(int x, int y, int colorNr) +{ + int square = colorNr & 0x80; + GC color; + colorNr &= 0x7F; + color = colorNr == 0 ? prelineGC : colorNr == 1 ? darkSquareGC : highlineGC; + if(square) + XFillRectangle(xDisplay, xBoardWindow, color, + x-squareSize/9, y-squareSize/9, 2*squareSize/9, 2*squareSize/9); + else + XFillArc(xDisplay, xBoardWindow, color, + x-squareSize/8, y-squareSize/8, squareSize/4, squareSize/4, 0, 64*360); +} + static int damage[BOARD_RANKS][BOARD_FILES]; /* @@ -4315,6 +4421,8 @@ void XDrawPosition(w, repaint, board) Arg args[16]; int rrow, rcol; + if(DrawSeekGraph()) return; // [HGM] seekgraph: suppress any drawing if seek graph up + if (board == NULL) { if (!lastBoardValid) return; board = lastBoard; @@ -4852,6 +4960,7 @@ void ICSInputSendText() j = 0; XtSetArg(args[j], XtNstring, &val); j++; XtGetValues(edit, args, j); + SaveInHistory(val); SendMultiLineToICS(val); XtCallActionProc(edit, "select-all", NULL, NULL, 0); XtCallActionProc(edit, "kill-selection", NULL, NULL, 0); @@ -4954,45 +5063,14 @@ void FileNamePopUp(label, def, proc, openMode) fileProc = proc; /* I can't see a way not */ fileOpenMode = openMode; /* to use globals here */ - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; - XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; - XtSetArg(args[i], XtNtitle, XtNewString(_("File name prompt"))); i++; - fileNameShell = popup = - XtCreatePopupShell("File name prompt", transientShellWidgetClass, - shellWidget, args, i); - - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, popup, - layoutArgs, XtNumber(layoutArgs)); - - i = 0; - XtSetArg(args[i], XtNlabel, label); i++; - XtSetArg(args[i], XtNvalue, def); i++; - XtSetArg(args[i], XtNborderWidth, 0); i++; - dialog = XtCreateManagedWidget("fileName", dialogWidgetClass, - layout, args, i); - - XawDialogAddButton(dialog, _("ok"), FileNameCallback, (XtPointer) dialog); - XawDialogAddButton(dialog, _("cancel"), FileNameCallback, - (XtPointer) dialog); - - XtRealizeWidget(popup); - CatchDeleteWindow(popup, "FileNamePopDown"); - - XQueryPointer(xDisplay, xBoardWindow, &root, &child, - &x, &y, &win_x, &win_y, &mask); - - XtSetArg(args[0], XtNx, x - 10); - XtSetArg(args[1], XtNy, y - 30); - XtSetValues(popup, args, 2); - - XtPopup(popup, XtGrabExclusive); - filenameUp = True; - - edit = XtNameToWidget(dialog, "*value"); - XtSetKeyboardFocus(popup, edit); + { // [HGM] use file-selector dialog stolen from Ghostview + char *name; + int index; // this is not supported yet + FILE *f; + if(f = XsraSelFile(shellWidget, label, NULL, NULL, "could not open: ", + NULL, openMode, NULL, &name)) + (void) (*fileProc)(f, index=0, name); + } } void FileNamePopDown() @@ -6061,6 +6139,55 @@ void EnterKeyProc(w, event, prms, nprms) ICSInputSendText(); } +void UpKeyProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ // [HGM] input: let up-arrow recall previous line from history + Widget edit; + int j; + Arg args[16]; + String val; + XawTextBlock t; + + if (!ICSInputBoxUp) return; + edit = XtNameToWidget(ICSInputShell, "*form.text"); + j = 0; + XtSetArg(args[j], XtNstring, &val); j++; + XtGetValues(edit, args, j); + val = PrevInHistory(val); + XtCallActionProc(edit, "select-all", NULL, NULL, 0); + XtCallActionProc(edit, "kill-selection", NULL, NULL, 0); + if(val) { + t.ptr = val; t.firstPos = 0; t.length = strlen(val); t.format = XawFmt8Bit; + XawTextReplace(edit, 0, 0, &t); + XawTextSetInsertionPoint(edit, 9999); + } +} + +void DownKeyProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ // [HGM] input: let down-arrow recall next line from history + Widget edit; + String val; + XawTextBlock t; + + if (!ICSInputBoxUp) return; + edit = XtNameToWidget(ICSInputShell, "*form.text"); + val = NextInHistory(); + XtCallActionProc(edit, "select-all", NULL, NULL, 0); + XtCallActionProc(edit, "kill-selection", NULL, NULL, 0); + if(val) { + t.ptr = val; t.firstPos = 0; t.length = strlen(val); t.format = XawFmt8Bit; + XawTextReplace(edit, 0, 0, &t); + XawTextSetInsertionPoint(edit, 9999); + } +} + void StopObservingProc(w, event, prms, nprms) Widget w; XEvent *event; @@ -6079,6 +6206,15 @@ void StopExaminingProc(w, event, prms, nprms) StopExaminingEvent(); } +void UploadProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + UploadGameEvent(); +} + void ForwardProc(w, event, prms, nprms) Widget w; @@ -6123,7 +6259,16 @@ void RevertProc(w, event, prms, nprms) String *prms; Cardinal *nprms; { - RevertEvent(); + RevertEvent(False); +} + +void AnnotateProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + RevertEvent(True); } void TruncateGameProc(w, event, prms, nprms)