X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xboard.c;h=b21441ab81a6e386e496e4b63370f9f2a69e1ef9;hb=15d1ea181db5a5de2bafc3fa9602abaa628f4ff5;hp=934f903d81fb4040c5ce59639635c986700eee6a;hpb=b9c6b5e9fcd6321336ec28f25833530db79b928d;p=xboard.git diff --git a/xboard.c b/xboard.c index 934f903..b21441a 100644 --- a/xboard.c +++ b/xboard.c @@ -205,6 +205,7 @@ extern char *getenv(); #include "xedittags.h" #include "menus.h" #include "board.h" +#include "dialogs.h" #include "gettext.h" @@ -224,13 +225,11 @@ extern char *getenv(); #endif int main P((int argc, char **argv)); -FILE * XsraSelFile P((Widget w, char *prompt, char *ok, char *cancel, char *failed, - char *init_path, char *filter, char *mode, int (*show_entry)(), char **name_return)); RETSIGTYPE CmailSigHandler P((int sig)); RETSIGTYPE IntSigHandler P((int sig)); RETSIGTYPE TermSizeSigHandler P((int sig)); -void CreateGCs P((int redo)); -void CreateAnyPieces P((void)); +static void CreateGCs P((int redo)); +static void CreateAnyPieces P((void)); void CreateXIMPieces P((void)); void CreateXPMPieces P((void)); void CreateXPMBoard P((char *s, int n)); @@ -251,10 +250,9 @@ static void DropMenuSelect P((Widget w, ChessSquare piece, caddr_t junk)); void ReadBitmap P((Pixmap *pm, String name, unsigned char bits[], u_int wreq, u_int hreq)); void CreateGrid P((void)); -int EventToSquare P((int x, int limit)); void EventProc P((Widget widget, caddr_t unused, XEvent *event)); void DelayedDrag P((void)); -void MoveTypeInProc P((Widget widget, caddr_t unused, XEvent *event)); +static void MoveTypeInProc P((Widget widget, caddr_t unused, XEvent *event)); void HandleUserMove P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void AnimateUserMove P((Widget w, XEvent * event, @@ -271,25 +269,13 @@ void BlackClock P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void DrawPositionProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void XDrawPosition P((Widget w, /*Boolean*/int repaint, - Board board)); void CommentClick P((Widget w, XEvent * event, String * params, Cardinal * nParams)); -void CommentPopUp P((char *title, char *label)); -void CommentPopDown P((void)); void ICSInputBoxPopUp P((void)); -void ICSInputBoxPopDown P((void)); void FileNamePopUp P((char *label, char *def, char *filter, FileProc proc, char *openMode)); -void FileNamePopDown P((void)); -void FileNameCallback P((Widget w, XtPointer client_data, - XtPointer call_data)); -void FileNameAction P((Widget w, XEvent *event, - String *prms, Cardinal *nprms)); void AskQuestionReplyAction P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void AskQuestionProc P((Widget w, XEvent *event, - String *prms, Cardinal *nprms)); void AskQuestionPopDown P((void)); void PromotionPopDown P((void)); void PromotionCallback P((Widget w, XtPointer client_data, @@ -297,28 +283,20 @@ void PromotionCallback P((Widget w, XtPointer client_data, void SelectCommand P((Widget w, XtPointer client_data, XtPointer call_data)); void KeyBindingProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void QuitWrapper P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void TypeInProc 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)); +static void EnterKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +static void UpKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +static void DownKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void TempBackwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); 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 DisplayTitle P((char *title)); void ICSInitScript P((void)); -void ErrorPopUp P((char *title, char *text, int modal)); -void ErrorPopDown P((void)); static char *ExpandPathName P((char *path)); void SelectMove P((Widget w, XEvent * event, String * params, Cardinal * nParams)); -void GameListOptionsPopDown P(()); -void GenericPopDown P(()); void update_ics_width P(()); int get_term_width P(()); int CopyMemoProc P(()); -void DrawArrowHighlight P((int fromX, int fromY, int toX,int toY)); -Boolean IsDrawArrowEnabled P(()); /* * XBoard depends on Xt R4 or higher @@ -329,11 +307,11 @@ int xScreen; Display *xDisplay; Window xBoardWindow; Pixel lightSquareColor, darkSquareColor, whitePieceColor, blackPieceColor, - jailSquareColor, highlightSquareColor, premoveHighlightColor; + highlightSquareColor, premoveHighlightColor; Pixel lowTimeWarningColor; -GC lightSquareGC, darkSquareGC, jailSquareGC, lineGC, wdPieceGC, wlPieceGC, +GC lightSquareGC, darkSquareGC, lineGC, wdPieceGC, wlPieceGC, bdPieceGC, blPieceGC, wbPieceGC, bwPieceGC, coordGC, highlineGC, - wjPieceGC, bjPieceGC, prelineGC, countGC; + prelineGC, countGC; Pixmap iconPixmap, wIconPixmap, bIconPixmap, xMarkPixmap; Widget shellWidget, layoutWidget, formWidget, boardWidget, messageWidget, whiteTimerWidget, blackTimerWidget, titleWidget, widgetList[16], @@ -343,7 +321,6 @@ Widget shellWidget, layoutWidget, formWidget, boardWidget, messageWidget, Widget historyShell, evalGraphShell, gameListShell; XSegment secondSegments[BOARD_RANKS + BOARD_FILES + 2]; XSegment gridSegments[BOARD_RANKS + BOARD_FILES + 2]; -XSegment jailGridSegments[BOARD_RANKS + BOARD_FILES + 6]; #if ENABLE_NLS XFontSet fontSet, clockFontSet; #else @@ -392,8 +369,6 @@ WindowPlacement wpEngineOutput; WindowPlacement wpGameList; WindowPlacement wpTags; -extern Widget shells[]; -extern Boolean shellUp[]; #define SOLID 0 #define OUTLINE 1 @@ -545,8 +520,6 @@ XtActionsRec boardActions[] = { { "HandlePV", HandlePV }, { "SelectPV", SelectPV }, { "StopPV", StopPV }, - { "FileNameAction", FileNameAction }, - { "AskQuestionProc", AskQuestionProc }, { "AskQuestionReplyAction", AskQuestionReplyAction }, { "PieceMenuPopup", PieceMenuPopup }, { "WhiteClock", WhiteClock }, @@ -557,11 +530,7 @@ XtActionsRec boardActions[] = { { "TempBackwardProc", TempBackwardProc }, { "TempForwardProc", TempForwardProc }, { "CommentClick", (XtActionProc) CommentClick }, - { "CommentPopDown", (XtActionProc) CommentPopDown }, - { "TagsPopDown", (XtActionProc) TagsPopDown }, { "ErrorPopDown", (XtActionProc) ErrorPopDown }, - { "ICSInputBoxPopDown", (XtActionProc) ICSInputBoxPopDown }, - { "FileNamePopDown", (XtActionProc) FileNamePopDown }, { "AskQuestionPopDown", (XtActionProc) AskQuestionPopDown }, { "GameListPopDown", (XtActionProc) GameListPopDown }, { "GameListOptionsPopDown", (XtActionProc) GameListOptionsPopDown }, @@ -684,7 +653,6 @@ char ICSInputTranslations[] = char commentTranslations[] = ": extend-end() select-start() CommentClick() \n"; String xboardResources[] = { - "*fileName*value.translations: #override\\n Return: FileNameAction()", "*question*value.translations: #override\\n Return: AskQuestionReplyAction()", "*errorpopup*translations: #override\\n Return: ErrorPopDown()", NULL @@ -1115,11 +1083,11 @@ GetWindowCoords () // In XBoard this will have to wait until awareness of window parameters is implemented GetActualPlacement(shellWidget, &wpMain); if(EngineOutputIsUp()) GetActualPlacement(engineOutputShell, &wpEngineOutput); - if(MoveHistoryIsUp()) GetActualPlacement(shells[7], &wpMoveHistory); + if(MoveHistoryIsUp()) GetActualPlacement(shells[HistoryDlg], &wpMoveHistory); if(EvalGraphIsUp()) GetActualPlacement(evalGraphShell, &wpEvalGraph); if(GameListIsUp()) GetActualPlacement(gameListShell, &wpGameList); - if(shellUp[1]) GetActualPlacement(shells[1], &wpComment); - if(shellUp[2]) GetActualPlacement(shells[2], &wpTags); + if(shellUp[CommentDlg]) GetActualPlacement(shells[CommentDlg], &wpComment); + if(shellUp[TagsDlg]) GetActualPlacement(shells[TagsDlg], &wpTags); } void @@ -1187,8 +1155,6 @@ ConvertToLine (int argc, char **argv) //-------------------------------------------------------------------------------------------- -extern Boolean twoBoards, partnerUp; - #ifdef IDSIZES // eventually, all layout determining code should go into a subroutine, but until then IDSIZE remains undefined #else @@ -1386,7 +1352,7 @@ ParseIcsTextColors () } } -int +static int MakeOneColor (char *name, Pixel *color) { XrmValue vFrom, vTo; @@ -1404,7 +1370,7 @@ MakeOneColor (char *name, Pixel *color) return False; } -int +static int MakeColors () { // [HGM] taken out of main(), so it can be called from BoardOptions dialog int forceMono = False; @@ -1419,7 +1385,7 @@ MakeColors () return forceMono; } -void +static void CreateAnyPieces () { // [HGM] taken out of main #if HAVE_LIBXPM @@ -1441,6 +1407,13 @@ CreateAnyPieces () #endif } +void +InitDrawingParams () +{ + MakeColors(); CreateGCs(True); + CreateAnyPieces(); +} + int main (int argc, char **argv) { @@ -1640,21 +1613,8 @@ XBoard square size (hint): %d\n\ /* [HR] height treated separately (hacked) */ boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap); boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap); - if (appData.showJail == 1) { - /* Jail on top and bottom */ XtSetArg(boardArgs[1], XtNwidth, boardWidth); - XtSetArg(boardArgs[2], XtNheight, - boardHeight + 2*(lineGap + squareSize)); - } else if (appData.showJail == 2) { - /* Jail on sides */ - XtSetArg(boardArgs[1], XtNwidth, - boardWidth + 2*(lineGap + squareSize)); XtSetArg(boardArgs[2], XtNheight, boardHeight); - } else { - /* No jail */ - XtSetArg(boardArgs[1], XtNwidth, boardWidth); - XtSetArg(boardArgs[2], XtNheight, boardHeight); - } /* * Determine what fonts to use. @@ -2192,51 +2152,6 @@ ResetFrontEnd () return; } -// [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)) #ifdef ENABLE_NLS @@ -2409,13 +2324,10 @@ DeleteGCs () } } else { XtReleaseGC(shellWidget, prelineGC); - XtReleaseGC(shellWidget, jailSquareGC); XtReleaseGC(shellWidget, wdPieceGC); XtReleaseGC(shellWidget, wlPieceGC); - XtReleaseGC(shellWidget, wjPieceGC); XtReleaseGC(shellWidget, bdPieceGC); XtReleaseGC(shellWidget, blPieceGC); - XtReleaseGC(shellWidget, bjPieceGC); } } @@ -2429,7 +2341,7 @@ CreateOneGC (XGCValues *gc_values, Pixel foreground, Pixel background) return XtGetGC(shellWidget, value_mask, gc_values); } -void +static void CreateGCs (int redo) { XtGCMask value_mask = GCLineWidth | GCLineStyle | GCForeground @@ -2481,13 +2393,10 @@ CreateGCs (int redo) prelineGC = CreateOneGC(&gc_values, premoveHighlightColor, premoveHighlightColor); lightSquareGC = CreateOneGC(&gc_values, lightSquareColor, darkSquareColor); darkSquareGC = CreateOneGC(&gc_values, darkSquareColor, lightSquareColor); - jailSquareGC = CreateOneGC(&gc_values, jailSquareColor, jailSquareColor); wdPieceGC = CreateOneGC(&gc_values, whitePieceColor, darkSquareColor); wlPieceGC = CreateOneGC(&gc_values, whitePieceColor, lightSquareColor); - wjPieceGC = CreateOneGC(&gc_values, whitePieceColor, jailSquareColor); bdPieceGC = CreateOneGC(&gc_values, blackPieceColor, darkSquareColor); blPieceGC = CreateOneGC(&gc_values, blackPieceColor, lightSquareColor); - bjPieceGC = CreateOneGC(&gc_values, blackPieceColor, jailSquareColor); } } @@ -3385,7 +3294,7 @@ BlankSquare (int x, int y, int color, ChessSquare piece, Drawable dest, int fac) break; case 2: /* neutral */ default: - pm = xpmJailSquare; + pm = xpmJailSquare; // [HGM] this is wrong, but apparently never used? break; } XCopyArea(xDisplay, pm, dest, wlPieceGC, 0, 0, @@ -3401,7 +3310,7 @@ BlankSquare (int x, int y, int color, ChessSquare piece, Drawable dest, int fac) break; case 2: /* neutral */ default: - gc = jailSquareGC; + gc = lineGC; break; } XFillRectangle(xDisplay, dest, gc, x*fac, y*fac, squareSize, squareSize); @@ -3478,11 +3387,7 @@ colorDrawPiece (ChessSquare piece, int square_color, int x, int y, Drawable dest break; case 2: /* neutral */ default: - XCopyPlane(xDisplay, *pieceToSolid(piece), - dest, (int) piece < (int) BlackPawn - ? wjPieceGC : bjPieceGC, 0, 0, - squareSize, squareSize, x, y, 1); - break; + break; // should never contain pieces } } @@ -3664,7 +3569,7 @@ DragProc () wpNew.width == wpMain.width && wpNew.height == wpMain.height) // not sized return; // false alarm if(EngineOutputIsUp()) CoDrag(engineOutputShell, &wpEngineOutput); - if(MoveHistoryIsUp()) CoDrag(shells[7], &wpMoveHistory); + if(MoveHistoryIsUp()) CoDrag(shells[HistoryDlg], &wpMoveHistory); if(EvalGraphIsUp()) CoDrag(evalGraphShell, &wpEvalGraph); if(GameListIsUp()) CoDrag(gameListShell, &wpGameList); wpMain = wpNew; @@ -3834,38 +3739,6 @@ EditCommentPopUp (int index, char *title, char *text) } void -ICSInputBoxPopUp () -{ - InputBoxPopup(); -} - -extern Option boxOptions[]; - -void -ICSInputSendText () -{ - Widget edit; - int j; - Arg args[16]; - String val; - - edit = boxOptions[0].handle; - 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); -} - -void -ICSInputBoxPopDown () -{ - PopDown(4); -} - -void CommentPopUp (char *title, char *text) { savedIndex = currentMove; // [HGM] vari @@ -3875,7 +3748,7 @@ CommentPopUp (char *title, char *text) void CommentPopDown () { - PopDown(1); + PopDown(CommentDlg); } static char *openName; @@ -3902,79 +3775,6 @@ FileNamePopUp (char *label, char *def, char *filter, FileProc proc, char *openMo } void -FileNamePopDown () -{ - if (!filenameUp) return; - XtPopdown(fileNameShell); - XtDestroyWidget(fileNameShell); - filenameUp = False; - ModeHighlight(); -} - -void -FileNameCallback (Widget w, XtPointer client_data, XtPointer call_data) -{ - String name; - Arg args[16]; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, _("cancel")) == 0) { - FileNamePopDown(); - return; - } - - FileNameAction(w, NULL, NULL, NULL); -} - -void -FileNameAction (Widget w, XEvent *event, String *prms, Cardinal *nprms) -{ - char buf[MSG_SIZ]; - String name; - FILE *f; - char *p, *fullname; - int index; - - name = XawDialogGetValueString(w = XtParent(w)); - - if ((name != NULL) && (*name != NULLCHAR)) { - safeStrCpy(buf, name, sizeof(buf)/sizeof(buf[0]) ); - XtPopdown(w = XtParent(XtParent(w))); - XtDestroyWidget(w); - filenameUp = False; - - p = strrchr(buf, ' '); - if (p == NULL) { - index = 0; - } else { - *p++ = NULLCHAR; - index = atoi(p); - } - fullname = ExpandPathName(buf); - if (!fullname) { - ErrorPopUp(_("Error"), _("Can't open file"), FALSE); - } - else { - f = fopen(fullname, fileOpenMode); - if (f == NULL) { - DisplayError(_("Failed to open file"), errno); - } else { - (void) (*fileProc)(f, index, buf); - } - } - ModeHighlight(); - return; - } - - XtPopdown(w = XtParent(XtParent(w))); - XtDestroyWidget(w); - filenameUp = False; - ModeHighlight(); -} - -void PromotionPopUp () { Arg args[16]; @@ -4124,7 +3924,7 @@ ErrorPopUp (char *title, char *label, int modal) XtSetArg(args[i], XtNtitle, title); i++; errorShell = XtCreatePopupShell("errorpopup", transientShellWidgetClass, - shellUp[0] ? (dialogError = modal = TRUE, shells[0]) : shellWidget, args, i); + shellUp[TransientDlg] ? (dialogError = modal = TRUE, shells[TransientDlg]) : shellWidget, args, i); layout = XtCreateManagedWidget(layoutName, formWidgetClass, errorShell, layoutArgs, XtNumber(layoutArgs)); @@ -4274,13 +4074,31 @@ SendPositionSelection (Widget w, Atom *selection, Atom *target, { char *selection_tmp; - if (!selected_fen_position) return False; /* should never happen */ +// if (!selected_fen_position) return False; /* should never happen */ if (*target == XA_STRING || *target == XA_UTF8_STRING(xDisplay)){ + if (!selected_fen_position) { // since it never happens, we use it for indicating a game is being sent + FILE* f = fopen(gameCopyFilename, "r"); // This code, taken from SendGameSelection, now merges the two + long len; + size_t count; + if (f == NULL) return False; + fseek(f, 0, 2); + len = ftell(f); + rewind(f); + selection_tmp = XtMalloc(len + 1); + count = fread(selection_tmp, 1, len, f); + fclose(f); + if (len != count) { + XtFree(selection_tmp); + return False; + } + selection_tmp[len] = NULLCHAR; + } else { /* note: since no XtSelectionDoneProc was registered, Xt will * automatically call XtFree on the value returned. So have to * make a copy of it allocated with XtMalloc */ selection_tmp= XtMalloc(strlen(selected_fen_position)+16); safeStrCpy(selection_tmp, selected_fen_position, strlen(selected_fen_position)+16 ); + } *value_return=selection_tmp; *length_return=strlen(selection_tmp); @@ -4317,17 +4135,14 @@ SendPositionSelection (Widget w, Atom *selection, Atom *target, * Widget which was clicked on was, or what the click event was */ void -CopyPositionProc () +CopySomething (char *src) { + selected_fen_position = src; /* * Set both PRIMARY (the selection) and CLIPBOARD, since we don't * have a notion of a position that is selected but not copied. * See http://www.freedesktop.org/wiki/Specifications/ClipboardsWiki */ - if(gameMode == EditPosition) EditPositionDone(TRUE); - if (selected_fen_position) free(selected_fen_position); - selected_fen_position = (char *)PositionToFEN(currentMove, NULL); - if (!selected_fen_position) return; XtOwnSelection(menuBarWidget, XA_PRIMARY, CurrentTime, SendPositionSelection, @@ -4370,80 +4185,6 @@ PastePositionProc () return; } -static Boolean -SendGameSelection (Widget w, Atom *selection, Atom *target, - Atom *type_return, XtPointer *value_return, - unsigned long *length_return, int *format_return) -{ - char *selection_tmp; - - if (*target == XA_STRING || *target == XA_UTF8_STRING(xDisplay)){ - FILE* f = fopen(gameCopyFilename, "r"); - long len; - size_t count; - if (f == NULL) return False; - fseek(f, 0, 2); - len = ftell(f); - rewind(f); - selection_tmp = XtMalloc(len + 1); - count = fread(selection_tmp, 1, len, f); - fclose(f); - if (len != count) { - XtFree(selection_tmp); - return False; - } - selection_tmp[len] = NULLCHAR; - *value_return = selection_tmp; - *length_return = len; - *type_return = *target; - *format_return = 8; /* bits per byte */ - return True; - } else if (*target == XA_TARGETS(xDisplay)) { - Atom *targets_tmp = (Atom *) XtMalloc(2 * sizeof(Atom)); - targets_tmp[0] = XA_UTF8_STRING(xDisplay); - targets_tmp[1] = XA_STRING; - *value_return = targets_tmp; - *type_return = XA_ATOM; - *length_return = 2; -#if 0 - // This code leads to a read of value_return out of bounds on 64-bit systems. - // Other code which I have seen always sets *format_return to 32 independent of - // sizeof(Atom) without adjusting *length_return. For instance see TextConvertSelection() - // at http://cgit.freedesktop.org/xorg/lib/libXaw/tree/src/Text.c -- BJ - *format_return = 8 * sizeof(Atom); - if (*format_return > 32) { - *length_return *= *format_return / 32; - *format_return = 32; - } -#else - *format_return = 32; -#endif - return True; - } else { - return False; - } -} - -void -CopySomething () -{ - /* - * Set both PRIMARY (the selection) and CLIPBOARD, since we don't - * have a notion of a game that is selected but not copied. - * See http://www.freedesktop.org/wiki/Specifications/ClipboardsWiki - */ - XtOwnSelection(menuBarWidget, XA_PRIMARY, - CurrentTime, - SendGameSelection, - NULL/* lose_ownership_proc */ , - NULL/* transfer_done_proc */); - XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay), - CurrentTime, - SendGameSelection, - NULL/* lose_ownership_proc */ , - NULL/* transfer_done_proc */); -} - /* note: when called from menu all parameters are NULL, so no clue what the * Widget which was clicked on was, or what the click event was */ @@ -4492,54 +4233,40 @@ QuitWrapper (Widget w, XEvent *event, String *prms, Cardinal *nprms) QuitProc(); } -void +static void +MoveTypeInProc (Widget widget, caddr_t unused, XEvent *event) +{ + char buf[10], keys[32]; + KeySym sym; + KeyCode metaL, metaR; //, ctrlL, ctrlR; + int n = XLookupString(&(event->xkey), buf, 10, &sym, NULL); + XQueryKeymap(xDisplay,keys); + metaL = XKeysymToKeycode(xDisplay, XK_Meta_L); + metaR = XKeysymToKeycode(xDisplay, XK_Meta_R); +// ctrlL = XKeysymToKeycode(xDisplay, XK_Control_L); +// ctrlR = XKeysymToKeycode(xDisplay, XK_Control_R); + if ( n == 1 && *buf >= 32 // printable + && !(keys[metaL>>3]&1<<(metaL&7)) && !(keys[metaR>>3]&1<<(metaR&7)) // no alt key pressed +// && !(keys[ctrlL>>3]&1<<(ctrlL&7)) && !(keys[ctrlR>>3]&1<<(ctrlR&7)) // no ctrl key pressed + ) BoxAutoPopUp (buf); +} + +static void UpKeyProc (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 (!shellUp[4]) return; - edit = boxOptions[0].handle; - 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); - } + IcsKey(1); } -void +static void DownKeyProc (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 (!shellUp[4]) return; - edit = boxOptions[0].handle; - 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); - } + IcsKey(-1); } -void +static void EnterKeyProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) { - if (shellUp[4] == True) - ICSInputSendText(); + IcsKey(0); } void @@ -4616,48 +4343,15 @@ DisplayMessage (char *message, char *extMessage) } void -DisplayTitle (char *text) +SetWindowTitle (char *text, char *title, char *icon) { Arg args[16]; int i; - char title[MSG_SIZ]; - char icon[MSG_SIZ]; - - if (text == NULL) text = ""; - if (appData.titleInWindow) { i = 0; XtSetArg(args[i], XtNlabel, text); i++; XtSetValues(titleWidget, args, i); } - - if (*text != NULLCHAR) { - safeStrCpy(icon, text, sizeof(icon)/sizeof(icon[0]) ); - safeStrCpy(title, text, sizeof(title)/sizeof(title[0]) ); - } else if (appData.icsActive) { - snprintf(icon, sizeof(icon), "%s", appData.icsHost); - snprintf(title, sizeof(title), "%s: %s", programName, appData.icsHost); - } else if (appData.cmailGameName[0] != NULLCHAR) { - snprintf(icon, sizeof(icon), "%s", "CMail"); - snprintf(title,sizeof(title), "%s: %s", programName, "CMail"); -#ifdef GOTHIC - // [HGM] license: This stuff should really be done in back-end, but WinBoard already had a pop-up for it - } else if (gameInfo.variant == VariantGothic) { - safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) ); - safeStrCpy(title, GOTHIC, sizeof(title)/sizeof(title[0]) ); -#endif -#ifdef FALCON - } else if (gameInfo.variant == VariantFalcon) { - safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) ); - safeStrCpy(title, FALCON, sizeof(title)/sizeof(title[0]) ); -#endif - } else if (appData.noChessProgram) { - safeStrCpy(icon, programName, sizeof(icon)/sizeof(icon[0]) ); - safeStrCpy(title, programName, sizeof(title)/sizeof(title[0]) ); - } else { - safeStrCpy(icon, first.tidy, sizeof(icon)/sizeof(icon[0]) ); - snprintf(title,sizeof(title), "%s: %s", programName, first.tidy); - } i = 0; XtSetArg(args[i], XtNiconName, (XtArgVal) icon); i++; XtSetArg(args[i], XtNtitle, (XtArgVal) title); i++; @@ -4666,79 +4360,6 @@ DisplayTitle (char *text) } -void -DisplayError (String message, int error) -{ - char buf[MSG_SIZ]; - - if (error == 0) { - if (appData.debugMode || appData.matchMode) { - fprintf(stderr, "%s: %s\n", programName, message); - } - } else { - if (appData.debugMode || appData.matchMode) { - fprintf(stderr, "%s: %s: %s\n", - programName, message, strerror(error)); - } - snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error)); - message = buf; - } - ErrorPopUp(_("Error"), message, FALSE); -} - - -void -DisplayMoveError (String message) -{ - fromX = fromY = -1; - ClearHighlights(); - DrawPosition(FALSE, NULL); - if (appData.debugMode || appData.matchMode) { - fprintf(stderr, "%s: %s\n", programName, message); - } - if (appData.popupMoveErrors) { - ErrorPopUp(_("Error"), message, FALSE); - } else { - DisplayMessage(message, ""); - } -} - - -void -DisplayFatalError (String message, int error, int status) -{ - char buf[MSG_SIZ]; - - errorExitStatus = status; - if (error == 0) { - fprintf(stderr, "%s: %s\n", programName, message); - } else { - fprintf(stderr, "%s: %s: %s\n", - programName, message, strerror(error)); - snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error)); - message = buf; - } - if (appData.popupExitMessage && boardWidget && XtIsRealized(boardWidget)) { - ErrorPopUp(status ? _("Fatal Error") : _("Exiting"), message, TRUE); - } else { - ExitEvent(status); - } -} - -void -DisplayInformation (String message) -{ - ErrorPopDown(); - ErrorPopUp(_("Information"), message, TRUE); -} - -void -DisplayNote (String message) -{ - ErrorPopDown(); - ErrorPopUp(_("Note"), message, FALSE); -} - static int NullXErrorCheck (Display *dpy, XErrorEvent *error_event) { @@ -4778,17 +4399,6 @@ char pendingReplyPrefix[MSG_SIZ]; ProcRef pendingReplyPR; void -AskQuestionProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) -{ - if (*nprms != 4) { - fprintf(stderr, _("AskQuestionProc needed 4 parameters, got %d\n"), - *nprms); - return; - } - AskQuestionEvent(prms[0], prms[1], prms[2], prms[3]); -} - -void AskQuestionPopDown () { if (!askQuestionUp) return;