2 * xhistory.c -- Move list window, part of X front end for XBoard
4 * Copyright 2000, 2009, 2010 Free Software Foundation, Inc.
5 * ------------------------------------------------------------------------
7 * GNU XBoard is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at
10 * your option) any later version.
12 * GNU XBoard is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see http://www.gnu.org/licenses/. *
20 *------------------------------------------------------------------------
21 ** See the file ChangeLog for a revision history. */
28 #include <sys/types.h>
33 #else /* not STDC_HEADERS */
34 extern char *getenv();
37 # else /* not HAVE_STRING_H */
39 # endif /* not HAVE_STRING_H */
40 #endif /* not STDC_HEADERS */
46 #include <X11/Intrinsic.h>
47 #include <X11/StringDefs.h>
48 #include <X11/Shell.h>
49 #include <X11/Xaw/Dialog.h>
50 #include <X11/Xaw/Form.h>
51 #include <X11/Xaw/List.h>
52 #include <X11/Xaw/Label.h>
53 #include <X11/Xaw/SimpleMenu.h>
54 #include <X11/Xaw/SmeBSB.h>
55 #include <X11/Xaw/SmeLine.h>
56 #include <X11/Xaw/Box.h>
57 #include <X11/Xaw/Paned.h>
58 #include <X11/Xaw/MenuButton.h>
59 #include <X11/cursorfont.h>
60 #include <X11/Xaw/Text.h>
61 #include <X11/Xaw/AsciiText.h>
62 #include <X11/Xaw/Viewport.h>
72 # define _(s) gettext (s)
73 # define N_(s) gettext_noop (s)
81 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
82 extern Display *xDisplay;
83 extern int squareSize;
84 extern Pixmap xMarkPixmap;
85 extern char *layoutName;
88 String *Nr,*white,*black;
89 int aNr; /* space actually alocated */
90 Widget mvn,mvw,mvb,vbox,viewport,sh;
94 struct History *hist=0;
96 Position gameHistoryX, gameHistoryY;
97 Dimension gameHistoryW;
100 HistoryPopDown(w, client_data, call_data)
102 XtPointer client_data, call_data;
111 XtSetArg(args[j], XtNleftBitmap, None); j++;
112 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"),
116 void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data)
119 XawListReturnStruct *R = (XawListReturnStruct *) call_data;
120 if (w == hist->mvn || w == hist->mvw) {
121 to=2*R->list_index-1;
124 else if (w == hist->mvb) {
130 void HistoryAlloc(int len){
133 free(hist->Nr[0]);free(hist->white[0]);free(hist->black[0]);
134 free(hist->Nr);free(hist->white);free(hist->black);
137 hist=(struct History*)malloc(sizeof(struct History));
140 hist->Nr=(String*)malloc(hist->aNr*sizeof(String*));
141 hist->white=(String*)malloc(hist->aNr*sizeof(String*));
142 hist->black=(String*)malloc(hist->aNr*sizeof(String*));
144 hist->Nr[0]=(String)malloc(hist->aNr*6);
145 hist->white[0]=(String)malloc(hist->aNr*MOVE_LEN);
146 hist->black[0]=(String)malloc(hist->aNr*MOVE_LEN);
148 sprintf(hist->Nr[0]," ");
149 sprintf(hist->white[0],_("White "));
150 sprintf(hist->black[0],_("Black "));
151 for(i=1;i<hist->aNr;i++){
152 hist->Nr[i]= hist->Nr[i-1]+6;
153 hist->white[i]= hist->white[i-1]+MOVE_LEN;
154 hist->black[i]= hist->black[i-1]+MOVE_LEN;
155 sprintf(hist->Nr[i],"%i.",i);
156 sprintf(hist->white[i],"-----");
157 sprintf(hist->black[i],"-----");
162 /* Find empty space inside vbox form widget and redistribute it amongst
163 the list widgets inside it. */
164 /* This version sort of works */
175 XtSetArg(args[j], XtNx, &x); j++;
176 XtSetArg(args[j], XtNwidth, &w); j++;
177 XtSetArg(args[j], XtNborderWidth, &bw); j++;
178 XtGetValues(hist->mvb, args, j);
182 XtSetArg(args[j], XtNwidth, &w); j++;
183 XtSetArg(args[j], XtNdefaultDistance, &dd); j++;
184 XtGetValues(hist->vbox, args, j);
189 extra = -((-extra)/2);
195 XtSetArg(args[j], XtNwidth, &w); j++;
196 XtGetValues(hist->mvw, args, j);
199 XtSetArg(args[j], XtNwidth, w); j++;
200 XtSetValues(hist->mvw, args, j);
203 XtSetArg(args[j], XtNwidth, &w); j++;
204 XtGetValues(hist->mvb, args, j);
207 XtSetArg(args[j], XtNwidth, w); j++;
208 XtSetValues(hist->mvb, args, j);
211 void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
214 if(last >= hist->aNr) HistoryAlloc(last+_LL_);
215 for(i=0;i<last;i++) {
218 char* p = strchr(movelist[i], ' ');
220 strncpy(hist->white[i/2+1], movelist[i], p-movelist[i]);
221 hist->white[i/2+1][p-movelist[i]] = NULLCHAR;
223 strcpy(hist->white[i/2+1],movelist[i]);
226 strcpy(hist->white[i/2+1],dots);
230 char* p = strchr(movelist[i], ' ');
232 strncpy(hist->black[i/2+1], movelist[i], p-movelist[i]);
233 hist->black[i/2+1][p-movelist[i]] = NULLCHAR;
235 strcpy(hist->black[i/2+1],movelist[i]);
238 strcpy(hist->black[i/2+1],"");
242 strcpy(hist->black[last/2+1],"");
245 XawFormDoLayout(hist->vbox, False);
246 XawListChange(hist->mvn,hist->Nr+b,m,0,True);
247 XawListChange(hist->mvw,hist->white+b,m,0,True);
248 XawListChange(hist->mvb,hist->black+b,m,0,True);
250 XawFormDoLayout(hist->vbox, True);
252 XawListUnhighlight(hist->mvw);
253 XawListUnhighlight(hist->mvb);
255 else if((current%2)==0){
256 XawListHighlight(hist->mvw, current/2+1);
257 XawListUnhighlight(hist->mvb);
260 XawListUnhighlight(hist->mvw);
261 if(current) XawListHighlight(hist->mvb, current/2+1);
262 else XawListUnhighlight(hist->mvb);
267 Widget HistoryCreate()
272 Widget layout,form,b_close;
274 "<Key>Up: BackwardProc() \n \
275 <Key>Left: BackwardProc() \n \
276 <Key>Down: ForwardProc() \n \
277 <Key>Right: ForwardProc() \n";
278 /*--- allocate memory for move-strings ---*/
281 /*-------- create the widgets ---------------*/
283 XtSetArg(args[j], XtNresizable, True); j++;
284 XtSetArg(args[j], XtNallowShellResize, True); j++;
287 XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass,
288 shellWidget, args, j);
291 XtCreatePopupShell(_("Move list"), transientShellWidgetClass,
292 shellWidget, args, j);
295 XtSetArg(args[j], XtNborderWidth, 0); j++;
296 XtSetArg(args[j], XtNdefaultDistance, 0); j++;
298 XtCreateManagedWidget(layoutName, formWidgetClass, hist->sh,
302 XtSetArg(args[j], XtNborderWidth, 0); j++;
303 XtSetArg(args[j], XtNresizable, True); j++;
306 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
311 XtSetArg(args[j], XtNtop, XtChainTop); j++;
312 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
313 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
314 XtSetArg(args[j], XtNright, XtChainRight); j++;
316 XtSetArg(args[j], XtNborderWidth, 1); j++;
317 XtSetArg(args[j], XtNresizable, False); j++;
318 XtSetArg(args[j], XtNallowVert, True); j++;
319 XtSetArg(args[j], XtNallowHoriz, True); j++;
320 XtSetArg(args[j], XtNforceBars, False); j++;
321 XtSetArg(args[j], XtNheight, 280); j++;
323 XtCreateManagedWidget("viewport", viewportWidgetClass,
326 XtSetArg(args[j], XtNborderWidth, 0); j++;
327 XtSetArg(args[j], XtNorientation,XtorientHorizontal);j++;
329 XtCreateManagedWidget("vbox", formWidgetClass, hist->viewport, args, j);
332 XtSetArg(args[j], XtNtop, XtChainTop); j++;
333 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
334 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
335 XtSetArg(args[j], XtNright, XtChainLeft); j++;
337 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
338 XtSetArg(args[j], XtNforceColumns, True); j++;
339 XtSetArg(args[j], XtNverticalList, True); j++;
340 XtSetArg(args[j], XtNborderWidth, 0); j++;
341 XtSetArg(args[j], XtNresizable,True);j++;
342 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
343 hist->mvn = XtCreateManagedWidget("movesn", listWidgetClass,
344 hist->vbox, args, j);
345 XtAddCallback(hist->mvn, XtNcallback, HistoryMoveProc, (XtPointer) hist);
348 XtSetArg(args[j], XtNtop, XtChainTop); j++;
349 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
350 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
351 XtSetArg(args[j], XtNright, XtRubber); j++;
353 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
354 XtSetArg(args[j], XtNforceColumns, True); j++;
355 XtSetArg(args[j], XtNverticalList, True); j++;
356 XtSetArg(args[j], XtNborderWidth, 0); j++;
357 XtSetArg(args[j], XtNresizable,True);j++;
358 XtSetArg(args[j], XtNfromHoriz, hist->mvn); j++;
359 hist->mvw = XtCreateManagedWidget("movesw", listWidgetClass,
360 hist->vbox, args, j);
361 XtAddCallback(hist->mvw, XtNcallback, HistoryMoveProc, (XtPointer) hist);
364 XtSetArg(args[j], XtNtop, XtChainTop); j++;
365 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
366 XtSetArg(args[j], XtNleft, XtRubber); j++;
367 XtSetArg(args[j], XtNright, XtRubber); j++;
369 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
370 XtSetArg(args[j], XtNforceColumns, True); j++;
371 XtSetArg(args[j], XtNverticalList, True); j++;
372 XtSetArg(args[j], XtNborderWidth, 0); j++;
373 XtSetArg(args[j], XtNresizable,True);j++;
374 XtSetArg(args[j], XtNfromHoriz, hist->mvw); j++;
375 hist->mvb = XtCreateManagedWidget("movesb", listWidgetClass,
376 hist->vbox, args, j);
377 XtAddCallback(hist->mvb, XtNcallback, HistoryMoveProc, (XtPointer) hist);
380 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
381 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
382 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
383 XtSetArg(args[j], XtNright, XtChainLeft); j++;
384 XtSetArg(args[j], XtNfromVert, hist->viewport); j++;
385 b_close= XtCreateManagedWidget(_("Close"), commandWidgetClass,
387 XtAddCallback(b_close, XtNcallback, HistoryPopDown, (XtPointer) 0);
389 XtAugmentTranslations(hist->sh,XtParseTranslationTable (trstr));
391 XtRealizeWidget(hist->sh);
392 CatchDeleteWindow(hist->sh, "HistoryPopDown");
394 for(i=1;i<hist->aNr;i++){
395 strcpy(hist->white[i],dots);
396 strcpy(hist->black[i],"");
399 // [HGM] restore old position
401 XtSetArg(args[j], XtNx, &gameHistoryX); j++;
402 XtSetArg(args[j], XtNy, &gameHistoryY); j++;
403 XtSetArg(args[j], XtNwidth, &gameHistoryW); j++;
404 XtGetValues(shellWidget, args, j);
406 XtSetArg(args[j], XtNx, gameHistoryX + gameHistoryW); j++;
407 XtSetArg(args[j], XtNy, gameHistoryY); j++;
408 XtSetValues(hist->sh, args, j);
409 XtRealizeWidget(hist->sh);
420 if(!hist) HistoryCreate();
422 XtPopup(hist->sh, XtGrabNone);
425 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
426 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"),
433 HistoryShowProc(w, event, prms, nprms)
442 } else if (hist->Up) {
443 HistoryPopDown(0,0,0);
447 ToNrEvent(currentMove);