X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xhistory.c;h=2b861eb412781761070ff01e73abe9190e783136;hb=2dee3c0dc5b669d4e5f3464866b056a5bbca252e;hp=6f94e626723ee67bdcfc7cbd4f62f264f4bb4ed8;hpb=74113c74ca3c2294082fcf9dc87e2af8f991c3cc;p=xboard.git diff --git a/xhistory.c b/xhistory.c index 6f94e62..2b861eb 100644 --- a/xhistory.c +++ b/xhistory.c @@ -22,6 +22,7 @@ #include "config.h" +#include #include #include #include @@ -43,24 +44,6 @@ extern char *getenv(); # include #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "common.h" #include "frontend.h" #include "backend.h" @@ -76,46 +59,26 @@ extern char *getenv(); # define N_(s) s #endif -#define _LL_ 100 - -extern Widget formWidget, shellWidget, boardWidget, menuBarWidget; -extern Display *xDisplay; -extern int squareSize; -extern Pixmap xMarkPixmap; -extern char *layoutName; - -struct History{ - String *Nr,*white,*black; - int aNr; /* space actually alocated */ - Widget mvn,mvw,mvb,vbox,viewport,sh; - char Up; -}; +extern GtkWidget *GUI_History; +extern GtkListStore *LIST_MoveHistory; -struct History *hist=0; String dots=" ... "; Position gameHistoryX, gameHistoryY; Dimension gameHistoryW; void -HistoryPopDown(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; +HistoryPopDown(object, user_data) + GtkObject *object; + gpointer user_data; { - Arg args[16]; - int j; - if(hist) { - XtPopdown(hist->sh); - hist->Up=False; - } - j=0; - XtSetArg(args[j], XtNleftBitmap, None); j++; - XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"), - args, j); + gtk_widget_hide (GUI_History); + return; } void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data) { int to; + /* XawListReturnStruct *R = (XawListReturnStruct *) call_data; if (w == hist->mvn || w == hist->mvw) { to=2*R->list_index-1; @@ -125,325 +88,246 @@ void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data) to=2*R->list_index; ToNrEvent(to); } -} - -void HistoryAlloc(int len){ - int i; - if(hist){ - free(hist->Nr[0]);free(hist->white[0]);free(hist->black[0]); - free(hist->Nr);free(hist->white);free(hist->black); - } - else{ - hist=(struct History*)malloc(sizeof(struct History)); - } - hist->aNr=len; - hist->Nr=(String*)malloc(hist->aNr*sizeof(String*)); - hist->white=(String*)malloc(hist->aNr*sizeof(String*)); - hist->black=(String*)malloc(hist->aNr*sizeof(String*)); - - hist->Nr[0]=(String)malloc(hist->aNr*6); - hist->white[0]=(String)malloc(hist->aNr*MOVE_LEN); - hist->black[0]=(String)malloc(hist->aNr*MOVE_LEN); - - sprintf(hist->Nr[0]," "); - sprintf(hist->white[0],_("White ")); - sprintf(hist->black[0],_("Black ")); - for(i=1;iaNr;i++){ - hist->Nr[i]= hist->Nr[i-1]+6; - hist->white[i]= hist->white[i-1]+MOVE_LEN; - hist->black[i]= hist->black[i-1]+MOVE_LEN; - sprintf(hist->Nr[i],"%i.",i); - sprintf(hist->white[i],"-----"); - sprintf(hist->black[i],"-----"); - } + */ } -/* Find empty space inside vbox form widget and redistribute it amongst - the list widgets inside it. */ -/* This version sort of works */ -void -HistoryFill() +void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current) { - Dimension w, bw; - long extra; - Position x, x1, x2; - int j, dd; - Arg args[16]; - - j = 0; - XtSetArg(args[j], XtNx, &x); j++; - XtSetArg(args[j], XtNwidth, &w); j++; - XtSetArg(args[j], XtNborderWidth, &bw); j++; - XtGetValues(hist->mvb, args, j); - x1 = x + w + 2*bw; - - j = 0; - XtSetArg(args[j], XtNwidth, &w); j++; - XtSetArg(args[j], XtNdefaultDistance, &dd); j++; - XtGetValues(hist->vbox, args, j); - x2 = w - dd; + int i,b,m; + char movewhite[2*MOVE_LEN],moveblack[2*MOVE_LEN],move[2*MOVE_LEN]; + GtkTreeIter iter; - extra = x2 - x1; - if (extra < 0) { - extra = -((-extra)/2); - } else { - extra = extra/2; - } + /* TODO need to add highlights for current move */ + /* TODO need to add navigation by keyboard or mouse (double click on move) */ - j = 0; - XtSetArg(args[j], XtNwidth, &w); j++; - XtGetValues(hist->mvw, args, j); - w += extra; - j = 0; - XtSetArg(args[j], XtNwidth, w); j++; - XtSetValues(hist->mvw, args, j); + /* first clear everything, do we need this? */ + gtk_list_store_clear(LIST_MoveHistory); - j = 0; - XtSetArg(args[j], XtNwidth, &w); j++; - XtGetValues(hist->mvb, args, j); - w += extra; - j = 0; - XtSetArg(args[j], XtNwidth, w); j++; - XtSetValues(hist->mvb, args, j); -} + /* copy move list into history window */ -void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){ - int i,b,m; - if(hist){ - if(last >= hist->aNr) HistoryAlloc(last+_LL_); - for(i=0;iwhite[i/2+1], movelist[i], p-movelist[i]); - hist->white[i/2+1][p-movelist[i]] = NULLCHAR; - } else { - strcpy(hist->white[i/2+1],movelist[i]); - } - } else { - strcpy(hist->white[i/2+1],dots); - } - } else { - if(movelist[i][0]) { - char* p = strchr(movelist[i], ' '); - if (p) { - strncpy(hist->black[i/2+1], movelist[i], p-movelist[i]); - hist->black[i/2+1][p-movelist[i]] = NULLCHAR; - } else { - strcpy(hist->black[i/2+1],movelist[i]); - } - } else { - strcpy(hist->black[i/2+1],""); - } - } - } - strcpy(hist->black[last/2+1],""); - b=first/2; - m=(last+3)/2-b; - XawFormDoLayout(hist->vbox, False); - XawListChange(hist->mvn,hist->Nr+b,m,0,True); - XawListChange(hist->mvw,hist->white+b,m,0,True); - XawListChange(hist->mvb,hist->black+b,m,0,True); - HistoryFill(); - XawFormDoLayout(hist->vbox, True); - if(current<0){ - XawListUnhighlight(hist->mvw); - XawListUnhighlight(hist->mvb); + if (p) + { + strncpy(move, movelist[i], p-movelist[i]); + move[p-movelist[i]] = NULLCHAR; + } + else + { + strcpy(move,movelist[i]); + } + } + else + strcpy(move,dots); + + if((i%2)==0) + { + /* white move */ + strcpy(movewhite,move); + } + else + { + /* black move */ + strcpy(moveblack,move); + + /* save move */ + gtk_list_store_append (LIST_MoveHistory, &iter); + gtk_list_store_set (LIST_MoveHistory, &iter, + 0, i, + 1, movewhite, + 2, moveblack, + -1); + + strcpy(movewhite,""); + strcpy(moveblack,""); + }; } - else if((current%2)==0){ - XawListHighlight(hist->mvw, current/2+1); - XawListUnhighlight(hist->mvb); - } - else{ - XawListUnhighlight(hist->mvw); - if(current) XawListHighlight(hist->mvb, current/2+1); - else XawListUnhighlight(hist->mvb); - } - } + /* check if ther is a white move left */ + if(movewhite[0]) + { + i++; + strcpy(moveblack,""); + /* save move */ + gtk_list_store_append (LIST_MoveHistory, &iter); + gtk_list_store_set (LIST_MoveHistory, &iter, + 0, i, + 1, movewhite, + 2, moveblack, + -1); + }; + + return; } -Widget HistoryCreate() +void HistoryCreate() { - Arg args[16]; - int i,j; - - Widget layout,form,b_close; String trstr= "Up: BackwardProc() \n \ Left: BackwardProc() \n \ Down: ForwardProc() \n \ Right: ForwardProc() \n"; - /*--- allocate memory for move-strings ---*/ - HistoryAlloc(_LL_); + return; /*-------- create the widgets ---------------*/ - j = 0; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNallowShellResize, True); j++; -#if TOPLEVEL - hist->sh = - XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass, - shellWidget, args, j); -#else - hist->sh = - XtCreatePopupShell(_("Move list"), transientShellWidgetClass, - shellWidget, args, j); -#endif - j = 0; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNdefaultDistance, 0); j++; - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, hist->sh, - args, j); - - j = 0; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNresizable, True); j++; - - 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++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - - XtSetArg(args[j], XtNborderWidth, 1); j++; - XtSetArg(args[j], XtNresizable, False); j++; - XtSetArg(args[j], XtNallowVert, True); j++; - XtSetArg(args[j], XtNallowHoriz, True); j++; - XtSetArg(args[j], XtNforceBars, False); j++; - XtSetArg(args[j], XtNheight, 280); j++; - hist->viewport = - XtCreateManagedWidget("viewport", viewportWidgetClass, - form, args, j); - j=0; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNorientation,XtorientHorizontal);j++; - hist->vbox = - XtCreateManagedWidget("vbox", formWidgetClass, hist->viewport, args, j); - - j=0; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - - XtSetArg(args[j], XtNdefaultColumns, 1); j++; - XtSetArg(args[j], XtNforceColumns, True); j++; - XtSetArg(args[j], XtNverticalList, True); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNresizable,True);j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - hist->mvn = XtCreateManagedWidget("movesn", listWidgetClass, - hist->vbox, args, j); - XtAddCallback(hist->mvn, XtNcallback, HistoryMoveProc, (XtPointer) hist); - - j=0; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtRubber); j++; - - XtSetArg(args[j], XtNdefaultColumns, 1); j++; - XtSetArg(args[j], XtNforceColumns, True); j++; - XtSetArg(args[j], XtNverticalList, True); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNresizable,True);j++; - XtSetArg(args[j], XtNfromHoriz, hist->mvn); j++; - hist->mvw = XtCreateManagedWidget("movesw", listWidgetClass, - hist->vbox, args, j); - XtAddCallback(hist->mvw, XtNcallback, HistoryMoveProc, (XtPointer) hist); - - j=0; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtRubber); j++; - XtSetArg(args[j], XtNright, XtRubber); j++; - - XtSetArg(args[j], XtNdefaultColumns, 1); j++; - XtSetArg(args[j], XtNforceColumns, True); j++; - XtSetArg(args[j], XtNverticalList, True); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNresizable,True);j++; - XtSetArg(args[j], XtNfromHoriz, hist->mvw); j++; - hist->mvb = XtCreateManagedWidget("movesb", listWidgetClass, - hist->vbox, args, j); - XtAddCallback(hist->mvb, XtNcallback, HistoryMoveProc, (XtPointer) hist); - - j=0; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - XtSetArg(args[j], XtNfromVert, hist->viewport); j++; - b_close= XtCreateManagedWidget(_("Close"), commandWidgetClass, - form, args, j); - XtAddCallback(b_close, XtNcallback, HistoryPopDown, (XtPointer) 0); - - XtAugmentTranslations(hist->sh,XtParseTranslationTable (trstr)); - - XtRealizeWidget(hist->sh); - CatchDeleteWindow(hist->sh, "HistoryPopDown"); - - for(i=1;iaNr;i++){ - strcpy(hist->white[i],dots); - strcpy(hist->black[i],""); - } - - // [HGM] restore old position - 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], XtNy, gameHistoryY); j++; - XtSetValues(hist->sh, args, j); - XtRealizeWidget(hist->sh); - - return hist->sh; +// j = 0; +// XtSetArg(args[j], XtNresizable, True); j++; +// XtSetArg(args[j], XtNallowShellResize, True); j++; +//#if TOPLEVEL +// hist->sh = +// XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass, +// shellWidget, args, j); +//#else +// hist->sh = +// XtCreatePopupShell(_("Move list"), transientShellWidgetClass, +// shellWidget, args, j); +//#endif +// j = 0; +// XtSetArg(args[j], XtNborderWidth, 0); j++; +// XtSetArg(args[j], XtNdefaultDistance, 0); j++; +// layout = +// XtCreateManagedWidget(layoutName, formWidgetClass, hist->sh, +// args, j); +// +// j = 0; +// XtSetArg(args[j], XtNborderWidth, 0); j++; +// XtSetArg(args[j], XtNresizable, True); j++; +// +// 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++; +// XtSetArg(args[j], XtNright, XtChainRight); j++; +// +// XtSetArg(args[j], XtNborderWidth, 1); j++; +// XtSetArg(args[j], XtNresizable, False); j++; +// XtSetArg(args[j], XtNallowVert, True); j++; +// XtSetArg(args[j], XtNallowHoriz, True); j++; +// XtSetArg(args[j], XtNforceBars, False); j++; +// XtSetArg(args[j], XtNheight, 280); j++; +// hist->viewport = +// XtCreateManagedWidget("viewport", viewportWidgetClass, +// form, args, j); +// j=0; +// XtSetArg(args[j], XtNborderWidth, 0); j++; +// XtSetArg(args[j], XtNorientation,XtorientHorizontal);j++; +// hist->vbox = +// XtCreateManagedWidget("vbox", formWidgetClass, hist->viewport, args, j); +// +// j=0; +// XtSetArg(args[j], XtNtop, XtChainTop); j++; +// XtSetArg(args[j], XtNbottom, XtChainTop); j++; +// XtSetArg(args[j], XtNleft, XtChainLeft); j++; +// XtSetArg(args[j], XtNright, XtChainLeft); j++; +// +// XtSetArg(args[j], XtNdefaultColumns, 1); j++; +// XtSetArg(args[j], XtNforceColumns, True); j++; +// XtSetArg(args[j], XtNverticalList, True); j++; +// XtSetArg(args[j], XtNborderWidth, 0); j++; +// XtSetArg(args[j], XtNresizable,True);j++; +// XtSetArg(args[j], XtNleft, XtChainLeft); j++; +// hist->mvn = XtCreateManagedWidget("movesn", listWidgetClass, +// hist->vbox, args, j); +// XtAddCallback(hist->mvn, XtNcallback, HistoryMoveProc, (XtPointer) hist); +// +// j=0; +// XtSetArg(args[j], XtNtop, XtChainTop); j++; +// XtSetArg(args[j], XtNbottom, XtChainTop); j++; +// XtSetArg(args[j], XtNleft, XtChainLeft); j++; +// XtSetArg(args[j], XtNright, XtRubber); j++; +// +// XtSetArg(args[j], XtNdefaultColumns, 1); j++; +// XtSetArg(args[j], XtNforceColumns, True); j++; +// XtSetArg(args[j], XtNverticalList, True); j++; +// XtSetArg(args[j], XtNborderWidth, 0); j++; +// XtSetArg(args[j], XtNresizable,True);j++; +// XtSetArg(args[j], XtNfromHoriz, hist->mvn); j++; +// hist->mvw = XtCreateManagedWidget("movesw", listWidgetClass, +// hist->vbox, args, j); +// XtAddCallback(hist->mvw, XtNcallback, HistoryMoveProc, (XtPointer) hist); +// +// j=0; +// XtSetArg(args[j], XtNtop, XtChainTop); j++; +// XtSetArg(args[j], XtNbottom, XtChainTop); j++; +// XtSetArg(args[j], XtNleft, XtRubber); j++; +// XtSetArg(args[j], XtNright, XtRubber); j++; +// +// XtSetArg(args[j], XtNdefaultColumns, 1); j++; +// XtSetArg(args[j], XtNforceColumns, True); j++; +// XtSetArg(args[j], XtNverticalList, True); j++; +// XtSetArg(args[j], XtNborderWidth, 0); j++; +// XtSetArg(args[j], XtNresizable,True);j++; +// XtSetArg(args[j], XtNfromHoriz, hist->mvw); j++; +// hist->mvb = XtCreateManagedWidget("movesb", listWidgetClass, +// hist->vbox, args, j); +// XtAddCallback(hist->mvb, XtNcallback, HistoryMoveProc, (XtPointer) hist); +// +// j=0; +// XtSetArg(args[j], XtNbottom, XtChainBottom); j++; +// XtSetArg(args[j], XtNtop, XtChainBottom); j++; +// XtSetArg(args[j], XtNleft, XtChainLeft); j++; +// XtSetArg(args[j], XtNright, XtChainLeft); j++; +// XtSetArg(args[j], XtNfromVert, hist->viewport); j++; +// b_close= XtCreateManagedWidget(_("Close"), commandWidgetClass, +// form, args, j); +// XtAddCallback(b_close, XtNcallback, HistoryPopDown, (XtPointer) 0); +// +// XtAugmentTranslations(hist->sh,XtParseTranslationTable (trstr)); +// +// XtRealizeWidget(hist->sh); +// CatchDeleteWindow(hist->sh, "HistoryPopDown"); +// +// for(i=1;iaNr;i++){ +// strcpy(hist->white[i],dots); +// strcpy(hist->black[i],""); +// } +// +// // [HGM] restore old position +// 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], XtNy, gameHistoryY); j++; +// XtSetValues(hist->sh, args, j); +// XtRealizeWidget(hist->sh); +// +// return hist->sh; } void HistoryPopUp() { - Arg args[16]; - int j; - - if(!hist) HistoryCreate(); + // if(!hist) HistoryCreate(); - XtPopup(hist->sh, XtGrabNone); - - j=0; - XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++; - XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"), - args, j); - hist->Up=True; + gtk_widget_show (GUI_History); + + return; } void -HistoryShowProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; +HistoryShowProc(object, user_data) + GtkObject *object; + gpointer user_data; { - if (!hist) { - HistoryCreate(); - HistoryPopUp(); - } else if (hist->Up) { - HistoryPopDown(0,0,0); - } else { - HistoryPopUp(); - } - ToNrEvent(currentMove); + HistoryCreate(); + HistoryPopUp(); + //TODO: ToNrEvent(currentMove); + + return; }