X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xboard.c;h=9e89d57875268983476d24a4da88ca2f4b7e293e;hb=240221c6158003a163aecb1efbe207bae058683d;hp=49e22c3901c563f199e13bc5692e51d75ecc9880;hpb=cfc88b71a13cd4ee57c6d16b9016b54faa1f6b48;p=xboard.git diff --git a/xboard.c b/xboard.c index 49e22c3..9e89d57 100644 --- a/xboard.c +++ b/xboard.c @@ -206,6 +206,7 @@ extern char *getenv(); #include "menus.h" #include "board.h" #include "dialogs.h" +#include "engineoutput.h" #include "usystem.h" #include "gettext.h" @@ -260,10 +261,6 @@ void AnimateUserMove P((Widget w, XEvent * event, String * params, Cardinal * nParams)); void HandlePV P((Widget w, XEvent * event, String * params, Cardinal * nParams)); -void SelectPV P((Widget w, XEvent * event, - String * params, Cardinal * nParams)); -void StopPV P((Widget w, XEvent * event, - String * params, Cardinal * nParams)); void WhiteClock P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void BlackClock P((Widget w, XEvent *event, @@ -275,9 +272,6 @@ void CommentClick P((Widget w, XEvent * event, void ICSInputBoxPopUp P((void)); void FileNamePopUp P((char *label, char *def, char *filter, FileProc proc, char *openMode)); -void PromotionPopDown P((void)); -void PromotionCallback P((Widget w, XtPointer client_data, - XtPointer call_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)); @@ -304,7 +298,7 @@ int xScreen; Display *xDisplay; Window xBoardWindow; Pixel lightSquareColor, darkSquareColor, whitePieceColor, blackPieceColor, - highlightSquareColor, premoveHighlightColor; + highlightSquareColor, premoveHighlightColor, dialogColor, buttonColor; Pixel lowTimeWarningColor; GC lightSquareGC, darkSquareGC, lineGC, wdPieceGC, wlPieceGC, bdPieceGC, blPieceGC, wbPieceGC, bwPieceGC, coordGC, highlineGC, @@ -312,10 +306,10 @@ GC lightSquareGC, darkSquareGC, lineGC, wdPieceGC, wlPieceGC, Pixmap iconPixmap, wIconPixmap, bIconPixmap, xMarkPixmap; Widget shellWidget, layoutWidget, formWidget, boardWidget, messageWidget, whiteTimerWidget, blackTimerWidget, titleWidget, widgetList[16], - commentShell, promotionShell, whitePieceMenu, blackPieceMenu, dropMenu, + commentShell, whitePieceMenu, blackPieceMenu, dropMenu, menuBarWidget, buttonBarWidget, editShell, errorShell, analysisShell, ICSInputShell, fileNameShell; -Widget historyShell, evalGraphShell, gameListShell; +Widget historyShell; XSegment secondSegments[BOARD_RANKS + BOARD_FILES + 2]; XSegment gridSegments[BOARD_RANKS + BOARD_FILES + 2]; #if ENABLE_NLS @@ -344,8 +338,8 @@ int smallLayout = 0, tinyLayout = 0, marginW, marginH, // [HGM] for run-time resizing fromX = -1, fromY = -1, toX, toY, commentUp = False, analysisUp = False, ICSInputBoxUp = False, - filenameUp = False, promotionUp = False, pmFromX = -1, pmFromY = -1, - errorUp = False, errorExitStatus = -1, defaultLineGap; + filenameUp = False, pmFromX = -1, pmFromY = -1, + errorExitStatus = -1, defaultLineGap; Dimension textHeight; Pixel timerForegroundPixel, timerBackgroundPixel; Pixel buttonForegroundPixel, buttonBackgroundPixel; @@ -525,13 +519,8 @@ XtActionsRec boardActions[] = { { "TempBackwardProc", TempBackwardProc }, { "TempForwardProc", TempForwardProc }, { "CommentClick", (XtActionProc) CommentClick }, - { "ErrorPopDown", (XtActionProc) ErrorPopDown }, - { "GameListPopDown", (XtActionProc) GameListPopDown }, - { "GameListOptionsPopDown", (XtActionProc) GameListOptionsPopDown }, - { "PromotionPopDown", (XtActionProc) PromotionPopDown }, - { "EngineOutputPopDown", (XtActionProc) EngineOutputPopDown }, - { "EvalGraphPopDown", (XtActionProc) EvalGraphPopDown }, { "GenericPopDown", (XtActionProc) GenericPopDown }, + { "ErrorPopDown", (XtActionProc) ErrorPopDown }, { "CopyMemoProc", (XtActionProc) CopyMemoProc }, { "SelectMove", (XtActionProc) SelectMove }, { "LoadSelectedProc", LoadSelectedProc }, @@ -649,7 +638,7 @@ char ICSInputTranslations[] = char commentTranslations[] = ": extend-end() select-start() CommentClick() \n"; String xboardResources[] = { - "*errorpopup*translations: #override\\n Return: ErrorPopDown()", + "*Error*translations: #override\\n Return: ErrorPopDown()", NULL }; @@ -812,9 +801,6 @@ BoardToTop () #define OPTCHAR "-" #define SEPCHAR " " -// these two must some day move to frontend.h, when they are implemented -Boolean GameListIsUp(); - // The option definition and parsing code common to XBoard and WinBoard is collected in this file #include "args.h" @@ -976,7 +962,6 @@ ParseCommPortSettings (char *s) { // no such option in XBoard (yet) } -extern Widget engineOutputShell; int frameX, frameY; void @@ -1006,10 +991,10 @@ GetWindowCoords () { // wrapper to shield use of window handles from back-end (make addressible by number?) // 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[HistoryDlg], &wpMoveHistory); - if(EvalGraphIsUp()) GetActualPlacement(evalGraphShell, &wpEvalGraph); - if(GameListIsUp()) GetActualPlacement(gameListShell, &wpGameList); + if(shellUp[EngOutDlg]) GetActualPlacement(shells[EngOutDlg], &wpEngineOutput); + if(shellUp[HistoryDlg]) GetActualPlacement(shells[HistoryDlg], &wpMoveHistory); + if(shellUp[EvalGraphDlg]) GetActualPlacement(shells[EvalGraphDlg], &wpEvalGraph); + if(shellUp[GameListDlg]) GetActualPlacement(shells[GameListDlg], &wpGameList); if(shellUp[CommentDlg]) GetActualPlacement(shells[CommentDlg], &wpComment); if(shellUp[TagsDlg]) GetActualPlacement(shells[TagsDlg], &wpTags); } @@ -1262,6 +1247,8 @@ MakeColors () forceMono |= MakeOneColor(appData.blackPieceColor, &blackPieceColor); forceMono |= MakeOneColor(appData.highlightSquareColor, &highlightSquareColor); forceMono |= MakeOneColor(appData.premoveHighlightColor, &premoveHighlightColor); + if(appData.dialogColor[0]) MakeOneColor(appData.dialogColor, &dialogColor); + if(appData.buttonColor[0]) MakeOneColor(appData.buttonColor, &buttonColor); return forceMono; } @@ -3030,7 +3017,7 @@ PieceMenuPopup (Widget w, XEvent *event, String *params, Cardinal *num_params) case 0: whichMenu = params[0]; break; case 1: SetupDropMenu(); whichMenu = "menuD"; break; case 2: - case -1: if (errorUp) ErrorPopDown(); + case -1: ErrorPopDown(); default: return; } XtPopupSpringLoaded(XtNameToWidget(boardWidget, whichMenu)); @@ -3393,10 +3380,10 @@ DragProc () if(wpNew.x == wpMain.x && wpNew.y == wpMain.y && // not moved wpNew.width == wpMain.width && wpNew.height == wpMain.height) // not sized return; // false alarm - if(EngineOutputIsUp()) CoDrag(engineOutputShell, &wpEngineOutput); - if(MoveHistoryIsUp()) CoDrag(shells[HistoryDlg], &wpMoveHistory); - if(EvalGraphIsUp()) CoDrag(evalGraphShell, &wpEvalGraph); - if(GameListIsUp()) CoDrag(gameListShell, &wpGameList); + if(shellUp[EngOutDlg]) CoDrag(shells[EngOutDlg], &wpEngineOutput); + if(shellUp[HistoryDlg]) CoDrag(shells[HistoryDlg], &wpMoveHistory); + if(shellUp[EvalGraphDlg]) CoDrag(shells[EvalGraphDlg], &wpEvalGraph); + if(shellUp[GameListDlg]) CoDrag(shells[GameListDlg], &wpGameList); wpMain = wpNew; DrawPosition(True, NULL); delayedDragID = 0; // now drag executed, make sure next DelayedDrag will not cancel timer event (which could now be used by other) @@ -3508,11 +3495,9 @@ HandleUserMove (Widget w, XEvent *event, String *prms, Cardinal *nprms) if (w != boardWidget || errorExitStatus != -1) return; if(nprms) shiftKey = !strcmp(prms[0], "1"); - if (promotionUp) { + if (shellUp[PromoDlg]) { // [HGM] is this still needed? if (event->type == ButtonPress) { - XtPopdown(promotionShell); - XtDestroyWidget(promotionShell); - promotionUp = False; + PopDown(PromoDlg); ClearHighlights(); fromX = fromY = -1; } else { @@ -3599,205 +3584,6 @@ FileNamePopUp (char *label, char *def, char *filter, FileProc proc, char *openMo } } -void -PromotionPopUp () -{ - Arg args[16]; - Widget dialog, layout; - Position x, y; - Dimension bw_width, pw_width; - int j; - char *PromoChars = "wglcqrbnkac+=\0"; - - j = 0; - XtSetArg(args[j], XtNwidth, &bw_width); j++; - XtGetValues(boardWidget, args, j); - - j = 0; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNtitle, XtNewString(_("Promotion"))); j++; - promotionShell = - XtCreatePopupShell("Promotion", transientShellWidgetClass, - shellWidget, args, j); - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, promotionShell, - layoutArgs, XtNumber(layoutArgs)); - - j = 0; - XtSetArg(args[j], XtNlabel, _("Promote to what?")); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - dialog = XtCreateManagedWidget("promotion", dialogWidgetClass, - layout, args, j); - - if(gameInfo.variant != VariantShogi) { - if(gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove)) { - XawDialogAddButton(dialog, _("Warlord"), PromotionCallback, PromoChars + 0); - XawDialogAddButton(dialog, _("General"), PromotionCallback, PromoChars + 1); - XawDialogAddButton(dialog, _("Lieutenant"), PromotionCallback, PromoChars + 2); - XawDialogAddButton(dialog, _("Captain"), PromotionCallback, PromoChars + 3); - } else { - XawDialogAddButton(dialog, _("Queen"), PromotionCallback, PromoChars + 4); - XawDialogAddButton(dialog, _("Rook"), PromotionCallback, PromoChars + 5); - XawDialogAddButton(dialog, _("Bishop"), PromotionCallback, PromoChars + 6); - XawDialogAddButton(dialog, _("Knight"), PromotionCallback, PromoChars + 7); - } - if (!appData.testLegality || gameInfo.variant == VariantSuicide || - gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove) || - gameInfo.variant == VariantGiveaway) { - XawDialogAddButton(dialog, _("King"), PromotionCallback, PromoChars + 8); - } - if(gameInfo.variant == VariantCapablanca || - gameInfo.variant == VariantGothic || - gameInfo.variant == VariantCapaRandom) { - XawDialogAddButton(dialog, _("Archbishop"), PromotionCallback, PromoChars + 9); - XawDialogAddButton(dialog, _("Chancellor"), PromotionCallback, PromoChars + 10); - } - } else // [HGM] shogi - { - XawDialogAddButton(dialog, _("Promote"), PromotionCallback, PromoChars + 11); - XawDialogAddButton(dialog, _("Defer"), PromotionCallback, PromoChars + 12); - } - XawDialogAddButton(dialog, _("cancel"), PromotionCallback, PromoChars + 13); - - XtRealizeWidget(promotionShell); - CatchDeleteWindow(promotionShell, "PromotionPopDown"); - - j = 0; - XtSetArg(args[j], XtNwidth, &pw_width); j++; - XtGetValues(promotionShell, args, j); - - XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2, - lineGap + squareSize/3 + - ((toY == BOARD_HEIGHT-1) ^ (flipView) ? - 0 : 6*(squareSize + lineGap)), &x, &y); - - j = 0; - XtSetArg(args[j], XtNx, x); j++; - XtSetArg(args[j], XtNy, y); j++; - XtSetValues(promotionShell, args, j); - - XtPopup(promotionShell, XtGrabNone); - - promotionUp = True; -} - -void -PromotionPopDown () -{ - if (!promotionUp) return; - XtPopdown(promotionShell); - XtDestroyWidget(promotionShell); - promotionUp = False; -} - -void -PromotionCallback (Widget w, XtPointer client_data, XtPointer call_data) -{ - int promoChar = * (const char *) client_data; - - PromotionPopDown(); - - if (fromX == -1) return; - - if (! promoChar) { - fromX = fromY = -1; - ClearHighlights(); - return; - } - UserMoveEvent(fromX, fromY, toX, toY, promoChar); - - if (!appData.highlightLastMove || gotPremove) ClearHighlights(); - if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY); - fromX = fromY = -1; -} - - -void -ErrorCallback (Widget w, XtPointer client_data, XtPointer call_data) -{ - dialogError = errorUp = False; - XtPopdown(w = XtParent(XtParent(XtParent(w)))); - XtDestroyWidget(w); - if (errorExitStatus != -1) ExitEvent(errorExitStatus); -} - - -void -ErrorPopDown () -{ - if (!errorUp) return; - dialogError = errorUp = False; - XtPopdown(errorShell); - XtDestroyWidget(errorShell); - if (errorExitStatus != -1) ExitEvent(errorExitStatus); -} - -void -ErrorPopUp (char *title, char *label, int modal) -{ - Arg args[16]; - Widget dialog, layout; - Position x, y; - int xx, yy; - Window junk; - Dimension bw_width, pw_width; - Dimension pw_height; - int i; - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; - XtSetArg(args[i], XtNtitle, title); i++; - errorShell = - XtCreatePopupShell("errorpopup", transientShellWidgetClass, - shellUp[TransientDlg] ? (dialogError = modal = TRUE, shells[TransientDlg]) : shellWidget, args, i); - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, errorShell, - layoutArgs, XtNumber(layoutArgs)); - - i = 0; - XtSetArg(args[i], XtNlabel, label); i++; - XtSetArg(args[i], XtNborderWidth, 0); i++; - dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, - layout, args, i); - - XawDialogAddButton(dialog, _("ok"), ErrorCallback, (XtPointer) dialog); - - XtRealizeWidget(errorShell); - CatchDeleteWindow(errorShell, "ErrorPopDown"); - - i = 0; - XtSetArg(args[i], XtNwidth, &bw_width); i++; - XtGetValues(boardWidget, args, i); - i = 0; - XtSetArg(args[i], XtNwidth, &pw_width); i++; - XtSetArg(args[i], XtNheight, &pw_height); i++; - XtGetValues(errorShell, args, i); - -#ifdef NOTDEF - /* This code seems to tickle an X bug if it is executed too soon - after xboard starts up. The coordinates get transformed as if - the main window was positioned at (0, 0). - */ - XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2, - 0 - pw_height + squareSize / 3, &x, &y); -#else - XTranslateCoordinates(xDisplay, XtWindow(boardWidget), - RootWindowOfScreen(XtScreen(boardWidget)), - (bw_width - pw_width) / 2, - 0 - pw_height + squareSize / 3, &xx, &yy, &junk); - x = xx; - y = yy; -#endif - if (y < 0) y = 0; /*avoid positioning top offscreen*/ - - i = 0; - XtSetArg(args[i], XtNx, x); i++; - XtSetArg(args[i], XtNy, y); i++; - XtSetValues(errorShell, args, i); - - errorUp = True; - XtPopup(errorShell, modal ? XtGrabExclusive : XtGrabNone); -} /* Disable all user input other than deleting the window */ static int frozen = 0;