From 06d3d751525f40869ef6dfd96e33c590008123c2 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Mon, 23 Nov 2009 19:58:55 -0800 Subject: [PATCH] fix window positioning This patch adds stuff in the header files that allow the various front-end files to share information on which windows exist, are up, and how they are positioned. The EngineOutput, MoveHistory and GameList windows now all remember their position and size, even when they are closed when XBoard exits. --- xboard.c | 62 +++++++++++++++++++++++++++++++++++++++++++----------- xedittags.h | 1 + xengineoutput.c | 11 +++++++++ xgamelist.c | 23 +++++++++++++++++-- xgamelist.h | 1 + xhistory.c | 46 ++++++++++++++++++++++++++++++---------- xhistory.h | 2 + 7 files changed, 118 insertions(+), 28 deletions(-) diff --git a/xboard.c b/xboard.c index d7ea5a7..b99438e 100644 --- a/xboard.c +++ b/xboard.c @@ -466,6 +466,7 @@ Widget shellWidget, layoutWidget, formWidget, boardWidget, messageWidget, commentShell, promotionShell, whitePieceMenu, blackPieceMenu, dropMenu, menuBarWidget, buttonBarWidget, editShell, errorShell, analysisShell, ICSInputShell, fileNameShell, askQuestionShell; +Widget historyShell, evalGraphShell, gameListShell; XSegment gridSegments[BOARD_RANKS + BOARD_FILES + 2]; XSegment jailGridSegments[BOARD_RANKS + BOARD_FILES + 6]; Font clockFontID, coordFontID, countFontID; @@ -1250,6 +1251,7 @@ BoardToTop() // these two must some day move to frontend.h, when they are implemented Boolean EvalGraphIsUp(); Boolean MoveHistoryIsUp(); +Boolean GameListIsUp(); // The option definition and parsing code common to XBoard and WinBoard is collected in this file #include "args.h" @@ -1385,19 +1387,45 @@ ParseCommPortSettings(char *s) { // no such option in XBoard (yet) } +extern Widget engineOutputShell; +extern Widget tagsShell, editTagsShell; +void +GetActualPlacement(Widget wg, WindowPlacement *wp) +{ + Arg args[16]; + Dimension w, h; + Position x, y; + int i; + + if(!wg) return; + + i = 0; + XtSetArg(args[i], XtNx, &x); i++; + XtSetArg(args[i], XtNy, &y); i++; + XtSetArg(args[i], XtNwidth, &w); i++; + XtSetArg(args[i], XtNheight, &h); i++; + XtGetValues(wg, args, i); + wp->x = x - 4; + wp->y = y - 23; + wp->height = h; + wp->width = w; +} + void GetWindowCoords() { // wrapper to shield use of window handles from back-end (make addressible by number?) -#if 0 // In XBoard this will have to wait until awareness of window parameters is implemented - GetActualPlacement(hwndMain, &wpMain); + GetActualPlacement(shellWidget, &wpMain); + if(EngineOutputIsUp()) GetActualPlacement(engineOutputShell, &wpEngineOutput); else + if(MoveHistoryIsUp()) GetActualPlacement(historyShell, &wpMoveHistory); + if(GameListIsUp()) GetActualPlacement(gameListShell, &wpGameList); + if(commentShell) GetActualPlacement(commentShell, &wpComment); + else GetActualPlacement(editShell, &wpComment); + if(tagsShell) GetActualPlacement(tagsShell, &wpTags); + else GetActualPlacement(editTagsShell, &wpTags); +#if 0 GetActualPlacement(hwndConsole, &wpConsole); - GetActualPlacement(commentDialog, &wpComment); - GetActualPlacement(editTagsDialog, &wpTags); - GetActualPlacement(gameListDialog, &wpGameList); - GetActualPlacement(moveHistoryDialog, &wpMoveHistory); GetActualPlacement(evalGraphDialog, &wpEvalGraph); - GetActualPlacement(engineOutputDialog, &wpEngineOutput); #endif } @@ -1431,12 +1459,6 @@ EnsureOnScreen(int *x, int *y, int minX, int minY) } Boolean -MoveHistoryIsUp() -{ - return True; // still have to fix this ***************************************************************************** -} - -Boolean EvalGraphIsUp() { return False; @@ -2166,6 +2188,12 @@ XBoard square size (hint): %d\n\ XtRealizeWidget(shellWidget); + if(wpMain.x > 0) { + XtSetArg(args[0], XtNx, wpMain.x); + XtSetArg(args[1], XtNy, wpMain.y); + XtSetValues(shellWidget, args, 2); + } + /* * Correct the width of the message and title widgets. * It is not known why some systems need the extra fudge term. @@ -4560,6 +4588,14 @@ Widget CommentCreate(name, text, mutable, callback, lines) #endif /*!NOTDEF*/ if (commentY < 0) commentY = 0; /*avoid positioning top offscreen*/ } + + if(wpComment.width > 0) { + commentX = wpComment.x; + commentY = wpComment.y; + commentW = wpComment.width; + commentH = wpComment.height; + } + j = 0; XtSetArg(args[j], XtNheight, commentH); j++; XtSetArg(args[j], XtNwidth, commentW); j++; diff --git a/xedittags.h b/xedittags.h index e777067..0459c16 100644 --- a/xedittags.h +++ b/xedittags.h @@ -27,4 +27,5 @@ void EditTagsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +extern Widget editTagsShell, tagsShell; #endif diff --git a/xengineoutput.c b/xengineoutput.c index 7162631..f7f5638 100644 --- a/xengineoutput.c +++ b/xengineoutput.c @@ -366,6 +366,13 @@ Widget EngineOutputCreate(name, text) XtRealizeWidget(shell); + if(wpEngineOutput.width > 0) { + engineOutputW = wpEngineOutput.width; + engineOutputH = wpEngineOutput.height; + engineOutputX = wpEngineOutput.x; + engineOutputY = wpEngineOutput.y; + } + if (engineOutputX == -1) { int xx, yy; Window junk; @@ -499,6 +506,10 @@ void EngineOutputPopDown() XtSetArg(args[j], XtNwidth, &engineOutputW); j++; XtSetArg(args[j], XtNheight, &engineOutputH); j++; XtGetValues(engineOutputShell, args, j); + wpEngineOutput.x = engineOutputX - 4; + wpEngineOutput.y = engineOutputY - 23; + wpEngineOutput.width = engineOutputW; + wpEngineOutput.height = engineOutputH; XtPopdown(engineOutputShell); XSync(xDisplay, False); j=0; diff --git a/xgamelist.c b/xgamelist.c index 46e2b20..009356b 100644 --- a/xgamelist.c +++ b/xgamelist.c @@ -91,7 +91,7 @@ extern char *getenv(); #endif -extern Widget formWidget, shellWidget, boardWidget, menuBarWidget; +extern Widget formWidget, shellWidget, boardWidget, menuBarWidget, gameListShell; extern Display *xDisplay; extern int squareSize; extern Pixmap xMarkPixmap; @@ -137,11 +137,11 @@ GameListCreate(name, callback, client_data) XtSetArg(args[j], XtNresizable, True); j++; XtSetArg(args[j], XtNallowShellResize, True); j++; #if TOPLEVEL - shell = + shell = gameListShell = XtCreatePopupShell(name, topLevelShellWidgetClass, shellWidget, args, j); #else - shell = + shell = gameListShell = XtCreatePopupShell(name, transientShellWidgetClass, shellWidget, args, j); #endif @@ -218,6 +218,13 @@ GameListCreate(name, callback, client_data) XtCreateManagedWidget(_("close"), commandWidgetClass, form, args, j); XtAddCallback(b_close, XtNcallback, callback, client_data); + if(wpGameList.width > 0) { + glc->x = wpGameList.x; + glc->y = wpGameList.y; + glc->w = wpGameList.width; + glc->h = wpGameList.height; + } + if (glc->x == -1) { Position y1; Dimension h1; @@ -455,6 +462,10 @@ GameListPopDown() XtSetArg(args[j], XtNheight, &glc->h); j++; XtSetArg(args[j], XtNwidth, &glc->w); j++; XtGetValues(glc->shell, args, j); + wpGameList.x = glc->x - 4; + wpGameList.y = glc->y - 23; + wpGameList.width = glc->w; + wpGameList.height = glc->h; XtPopdown(glc->shell); XtSetKeyboardFocus(shellWidget, formWidget); glc->up = False; @@ -473,3 +484,9 @@ GameListHighlight(index) listwidg = XtNameToWidget(glc->shell, "*form.viewport.list"); XawListHighlight(listwidg, index - 1); } + +Boolean +GameListIsUp() +{ + return glc && glc->up; +} diff --git a/xgamelist.h b/xgamelist.h index f020f22..21340aa 100644 --- a/xgamelist.h +++ b/xgamelist.h @@ -28,4 +28,5 @@ void ShowGameListProc P((Widget w, XEvent *event, void LoadSelectedProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +extern Widget gameListShell; #endif /* _XGAMEL_H */ diff --git a/xhistory.c b/xhistory.c index 6f94e62..c48ee32 100644 --- a/xhistory.c +++ b/xhistory.c @@ -78,7 +78,7 @@ extern char *getenv(); #define _LL_ 100 -extern Widget formWidget, shellWidget, boardWidget, menuBarWidget; +extern Widget formWidget, shellWidget, boardWidget, menuBarWidget, historyShell; extern Display *xDisplay; extern int squareSize; extern Pixmap xMarkPixmap; @@ -94,7 +94,7 @@ struct History{ struct History *hist=0; String dots=" ... "; Position gameHistoryX, gameHistoryY; -Dimension gameHistoryW; +Dimension gameHistoryW, gameHistoryH; void HistoryPopDown(w, client_data, call_data) @@ -104,6 +104,19 @@ HistoryPopDown(w, client_data, call_data) Arg args[16]; int j; if(hist) { + + // [HGM] remember old position + j = 0; + XtSetArg(args[j], XtNx, &gameHistoryX); j++; + XtSetArg(args[j], XtNy, &gameHistoryY); j++; + XtSetArg(args[j], XtNwidth, &gameHistoryW); j++; + XtSetArg(args[j], XtNheight, &gameHistoryH); j++; + XtGetValues(hist->sh, args, j); + wpMoveHistory.x = gameHistoryX - 4; + wpMoveHistory.y = gameHistoryY - 23; + wpMoveHistory.width = gameHistoryW; + wpMoveHistory.height = gameHistoryH; + XtPopdown(hist->sh); hist->Up=False; } @@ -283,11 +296,11 @@ Widget HistoryCreate() XtSetArg(args[j], XtNresizable, True); j++; XtSetArg(args[j], XtNallowShellResize, True); j++; #if TOPLEVEL - hist->sh = + hist->sh = historyShell = XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass, shellWidget, args, j); #else - hist->sh = + hist->sh = historyShell = XtCreatePopupShell(_("Move list"), transientShellWidgetClass, shellWidget, args, j); #endif @@ -304,10 +317,8 @@ Widget HistoryCreate() form = XtCreateManagedWidget("form", formWidgetClass, layout, args, j); - j=0; j = 0; - XtSetArg(args[j], XtNtop, XtChainTop); j++; XtSetArg(args[j], XtNbottom, XtChainBottom); j++; XtSetArg(args[j], XtNleft, XtChainLeft); j++; @@ -396,16 +407,22 @@ Widget HistoryCreate() strcpy(hist->black[i],""); } + if(wpMoveHistory.width > 0) { + gameHistoryW = wpMoveHistory.width; + gameHistoryH = wpMoveHistory.height; + gameHistoryX = wpMoveHistory.x; + gameHistoryY = wpMoveHistory.y; + } + // [HGM] restore old position + if(gameHistoryW > 0) { j = 0; - XtSetArg(args[j], XtNx, &gameHistoryX); j++; - XtSetArg(args[j], XtNy, &gameHistoryY); j++; - XtSetArg(args[j], XtNwidth, &gameHistoryW); j++; - XtGetValues(shellWidget, args, j); - j = 0; - XtSetArg(args[j], XtNx, gameHistoryX + gameHistoryW); j++; + XtSetArg(args[j], XtNx, gameHistoryX); j++; XtSetArg(args[j], XtNy, gameHistoryY); j++; + XtSetArg(args[j], XtNwidth, gameHistoryW); j++; + XtSetArg(args[j], XtNheight, gameHistoryH); j++; XtSetValues(hist->sh, args, j); + } XtRealizeWidget(hist->sh); return hist->sh; @@ -447,3 +464,8 @@ HistoryShowProc(w, event, prms, nprms) ToNrEvent(currentMove); } +Boolean +MoveHistoryIsUp() +{ + return hist && hist->Up; +} diff --git a/xhistory.h b/xhistory.h index 427cd7d..9c42c75 100644 --- a/xhistory.h +++ b/xhistory.h @@ -27,6 +27,8 @@ void HistoryShowProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void HistoryPopDown P((Widget w, XtPointer client_data, XtPointer call_data)); +Boolean MoveHistoryIsUp P((void)); +extern Widget historyShell; #endif /* _XHISTL_H */ -- 1.7.0.4