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, historyShell;
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, gameHistoryH;
100 HistoryPopDown(w, client_data, call_data)
102 XtPointer client_data, call_data;
108 // [HGM] remember old position
110 XtSetArg(args[j], XtNx, &gameHistoryX); j++;
111 XtSetArg(args[j], XtNy, &gameHistoryY); j++;
112 XtSetArg(args[j], XtNwidth, &gameHistoryW); j++;
113 XtSetArg(args[j], XtNheight, &gameHistoryH); j++;
114 XtGetValues(hist->sh, args, j);
115 wpMoveHistory.x = gameHistoryX - 4;
116 wpMoveHistory.y = gameHistoryY - 23;
117 wpMoveHistory.width = gameHistoryW;
118 wpMoveHistory.height = gameHistoryH;
124 XtSetArg(args[j], XtNleftBitmap, None); j++;
125 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"),
129 void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data)
132 XawListReturnStruct *R = (XawListReturnStruct *) call_data;
133 if (w == hist->mvn || w == hist->mvw) {
134 to=2*R->list_index-1;
137 else if (w == hist->mvb) {
143 void HistoryAlloc(int len){
146 free(hist->Nr[0]);free(hist->white[0]);free(hist->black[0]);
147 free(hist->Nr);free(hist->white);free(hist->black);
150 hist=(struct History*)malloc(sizeof(struct History));
153 hist->Nr=(String*)malloc(hist->aNr*sizeof(String*));
154 hist->white=(String*)malloc(hist->aNr*sizeof(String*));
155 hist->black=(String*)malloc(hist->aNr*sizeof(String*));
157 hist->Nr[0]=(String)malloc(hist->aNr*6);
158 hist->white[0]=(String)malloc(hist->aNr*MOVE_LEN);
159 hist->black[0]=(String)malloc(hist->aNr*MOVE_LEN);
161 sprintf(hist->Nr[0]," ");
162 sprintf(hist->white[0],_("White "));
163 sprintf(hist->black[0],_("Black "));
164 for(i=1;i<hist->aNr;i++){
165 hist->Nr[i]= hist->Nr[i-1]+6;
166 hist->white[i]= hist->white[i-1]+MOVE_LEN;
167 hist->black[i]= hist->black[i-1]+MOVE_LEN;
168 sprintf(hist->Nr[i],"%i.",i);
169 sprintf(hist->white[i],"-----");
170 sprintf(hist->black[i],"-----");
175 /* Find empty space inside vbox form widget and redistribute it amongst
176 the list widgets inside it. */
177 /* This version sort of works */
188 XtSetArg(args[j], XtNx, &x); j++;
189 XtSetArg(args[j], XtNwidth, &w); j++;
190 XtSetArg(args[j], XtNborderWidth, &bw); j++;
191 XtGetValues(hist->mvb, args, j);
195 XtSetArg(args[j], XtNwidth, &w); j++;
196 XtSetArg(args[j], XtNdefaultDistance, &dd); j++;
197 XtGetValues(hist->vbox, args, j);
202 extra = -((-extra)/2);
208 XtSetArg(args[j], XtNwidth, &w); j++;
209 XtGetValues(hist->mvw, args, j);
212 XtSetArg(args[j], XtNwidth, w); j++;
213 XtSetValues(hist->mvw, args, j);
216 XtSetArg(args[j], XtNwidth, &w); j++;
217 XtGetValues(hist->mvb, args, j);
220 XtSetArg(args[j], XtNwidth, w); j++;
221 XtSetValues(hist->mvb, args, j);
224 void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
227 if(last >= hist->aNr) HistoryAlloc(last+_LL_);
228 for(i=0;i<last;i++) {
231 char* p = strchr(movelist[i], ' ');
233 strncpy(hist->white[i/2+1], movelist[i], p-movelist[i]);
234 hist->white[i/2+1][p-movelist[i]] = NULLCHAR;
236 strcpy(hist->white[i/2+1],movelist[i]);
239 strcpy(hist->white[i/2+1],dots);
243 char* p = strchr(movelist[i], ' ');
245 strncpy(hist->black[i/2+1], movelist[i], p-movelist[i]);
246 hist->black[i/2+1][p-movelist[i]] = NULLCHAR;
248 strcpy(hist->black[i/2+1],movelist[i]);
251 strcpy(hist->black[i/2+1],"");
255 strcpy(hist->black[last/2+1],"");
258 XawFormDoLayout(hist->vbox, False);
259 XawListChange(hist->mvn,hist->Nr+b,m,0,True);
260 XawListChange(hist->mvw,hist->white+b,m,0,True);
261 XawListChange(hist->mvb,hist->black+b,m,0,True);
263 XawFormDoLayout(hist->vbox, True);
265 XawListUnhighlight(hist->mvw);
266 XawListUnhighlight(hist->mvb);
268 else if((current%2)==0){
269 XawListHighlight(hist->mvw, current/2+1);
270 XawListUnhighlight(hist->mvb);
273 XawListUnhighlight(hist->mvw);
274 if(current) XawListHighlight(hist->mvb, current/2+1);
275 else XawListUnhighlight(hist->mvb);
278 EvalGraphSet( first, last, current, pvInfoList ); // piggy-backed
281 Widget HistoryCreate()
286 Widget layout,form,b_close;
288 "<Key>Up: BackwardProc() \n \
289 <Key>Left: BackwardProc() \n \
290 <Key>Down: ForwardProc() \n \
291 <Key>Right: ForwardProc() \n";
292 /*--- allocate memory for move-strings ---*/
295 /*-------- create the widgets ---------------*/
297 XtSetArg(args[j], XtNresizable, True); j++;
298 XtSetArg(args[j], XtNallowShellResize, True); j++;
300 hist->sh = historyShell =
301 XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass,
302 shellWidget, args, j);
304 hist->sh = historyShell =
305 XtCreatePopupShell(_("Move list"), transientShellWidgetClass,
306 shellWidget, args, j);
309 XtSetArg(args[j], XtNborderWidth, 0); j++;
310 XtSetArg(args[j], XtNdefaultDistance, 0); j++;
312 XtCreateManagedWidget(layoutName, formWidgetClass, hist->sh,
316 XtSetArg(args[j], XtNborderWidth, 0); j++;
317 XtSetArg(args[j], XtNresizable, True); j++;
320 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
323 XtSetArg(args[j], XtNtop, XtChainTop); j++;
324 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
325 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
326 XtSetArg(args[j], XtNright, XtChainRight); j++;
328 XtSetArg(args[j], XtNborderWidth, 1); j++;
329 XtSetArg(args[j], XtNresizable, False); j++;
330 XtSetArg(args[j], XtNallowVert, True); j++;
331 XtSetArg(args[j], XtNallowHoriz, True); j++;
332 XtSetArg(args[j], XtNforceBars, False); j++;
333 XtSetArg(args[j], XtNheight, 280); j++;
335 XtCreateManagedWidget("viewport", viewportWidgetClass,
338 XtSetArg(args[j], XtNborderWidth, 0); j++;
339 XtSetArg(args[j], XtNorientation,XtorientHorizontal);j++;
341 XtCreateManagedWidget("vbox", formWidgetClass, hist->viewport, args, j);
344 XtSetArg(args[j], XtNtop, XtChainTop); j++;
345 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
346 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
347 XtSetArg(args[j], XtNright, XtChainLeft); j++;
349 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
350 XtSetArg(args[j], XtNforceColumns, True); j++;
351 XtSetArg(args[j], XtNverticalList, True); j++;
352 XtSetArg(args[j], XtNborderWidth, 0); j++;
353 XtSetArg(args[j], XtNresizable,True);j++;
354 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
355 hist->mvn = XtCreateManagedWidget("movesn", listWidgetClass,
356 hist->vbox, args, j);
357 XtAddCallback(hist->mvn, XtNcallback, HistoryMoveProc, (XtPointer) hist);
360 XtSetArg(args[j], XtNtop, XtChainTop); j++;
361 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
362 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
363 XtSetArg(args[j], XtNright, XtRubber); j++;
365 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
366 XtSetArg(args[j], XtNforceColumns, True); j++;
367 XtSetArg(args[j], XtNverticalList, True); j++;
368 XtSetArg(args[j], XtNborderWidth, 0); j++;
369 XtSetArg(args[j], XtNresizable,True);j++;
370 XtSetArg(args[j], XtNfromHoriz, hist->mvn); j++;
371 hist->mvw = XtCreateManagedWidget("movesw", listWidgetClass,
372 hist->vbox, args, j);
373 XtAddCallback(hist->mvw, XtNcallback, HistoryMoveProc, (XtPointer) hist);
376 XtSetArg(args[j], XtNtop, XtChainTop); j++;
377 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
378 XtSetArg(args[j], XtNleft, XtRubber); j++;
379 XtSetArg(args[j], XtNright, XtRubber); j++;
381 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
382 XtSetArg(args[j], XtNforceColumns, True); j++;
383 XtSetArg(args[j], XtNverticalList, True); j++;
384 XtSetArg(args[j], XtNborderWidth, 0); j++;
385 XtSetArg(args[j], XtNresizable,True);j++;
386 XtSetArg(args[j], XtNfromHoriz, hist->mvw); j++;
387 hist->mvb = XtCreateManagedWidget("movesb", listWidgetClass,
388 hist->vbox, args, j);
389 XtAddCallback(hist->mvb, XtNcallback, HistoryMoveProc, (XtPointer) hist);
392 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
393 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
394 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
395 XtSetArg(args[j], XtNright, XtChainLeft); j++;
396 XtSetArg(args[j], XtNfromVert, hist->viewport); j++;
397 b_close= XtCreateManagedWidget(_("Close"), commandWidgetClass,
399 XtAddCallback(b_close, XtNcallback, HistoryPopDown, (XtPointer) 0);
401 XtAugmentTranslations(hist->sh,XtParseTranslationTable (trstr));
403 XtRealizeWidget(hist->sh);
404 CatchDeleteWindow(hist->sh, "HistoryPopDown");
406 for(i=1;i<hist->aNr;i++){
407 strcpy(hist->white[i],dots);
408 strcpy(hist->black[i],"");
411 if(wpMoveHistory.width > 0) {
412 gameHistoryW = wpMoveHistory.width;
413 gameHistoryH = wpMoveHistory.height;
414 gameHistoryX = wpMoveHistory.x;
415 gameHistoryY = wpMoveHistory.y;
418 // [HGM] restore old position
419 if(gameHistoryW > 0) {
421 XtSetArg(args[j], XtNx, gameHistoryX); j++;
422 XtSetArg(args[j], XtNy, gameHistoryY); j++;
423 XtSetArg(args[j], XtNwidth, gameHistoryW); j++;
424 XtSetArg(args[j], XtNheight, gameHistoryH); j++;
425 XtSetValues(hist->sh, args, j);
427 XtRealizeWidget(hist->sh);
438 if(!hist) HistoryCreate();
440 XtPopup(hist->sh, XtGrabNone);
443 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
444 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"),
451 HistoryShowProc(w, event, prms, nprms)
460 } else if (hist->Up) {
461 HistoryPopDown(0,0,0);
465 ToNrEvent(currentMove);
471 return hist && hist->Up;