2 * xhistory.c -- Move list window, part of X front end for XBoard
4 * Copyright 2000,2009 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;
99 HistoryPopDown(w, client_data, call_data)
101 XtPointer client_data, call_data;
106 // [HGM] remember old position
108 XtSetArg(args[j], XtNx, &gameHistoryX); j++;
109 XtSetArg(args[j], XtNy, &gameHistoryY); j++;
110 XtGetValues(hist->sh, args, j);
116 XtSetArg(args[j], XtNleftBitmap, None); j++;
117 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"),
121 void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data)
124 XawListReturnStruct *R = (XawListReturnStruct *) call_data;
125 if (w == hist->mvn || w == hist->mvw) {
126 to=2*R->list_index-1;
129 else if (w == hist->mvb) {
135 void HistoryAlloc(int len){
138 free(hist->Nr[0]);free(hist->white[0]);free(hist->black[0]);
139 free(hist->Nr);free(hist->white);free(hist->black);
142 hist=(struct History*)malloc(sizeof(struct History));
145 hist->Nr=(String*)malloc(hist->aNr*sizeof(String*));
146 hist->white=(String*)malloc(hist->aNr*sizeof(String*));
147 hist->black=(String*)malloc(hist->aNr*sizeof(String*));
149 hist->Nr[0]=(String)malloc(hist->aNr*6);
150 hist->white[0]=(String)malloc(hist->aNr*MOVE_LEN);
151 hist->black[0]=(String)malloc(hist->aNr*MOVE_LEN);
153 sprintf(hist->Nr[0]," ");
154 sprintf(hist->white[0],_("White "));
155 sprintf(hist->black[0],_("Black "));
156 for(i=1;i<hist->aNr;i++){
157 hist->Nr[i]= hist->Nr[i-1]+6;
158 hist->white[i]= hist->white[i-1]+MOVE_LEN;
159 hist->black[i]= hist->black[i-1]+MOVE_LEN;
160 sprintf(hist->Nr[i],"%i.",i);
161 sprintf(hist->white[i],"-----");
162 sprintf(hist->black[i],"-----");
167 /* Find empty space inside vbox form widget and redistribute it amongst
168 the list widgets inside it. */
169 /* This version sort of works */
180 XtSetArg(args[j], XtNx, &x); j++;
181 XtSetArg(args[j], XtNwidth, &w); j++;
182 XtSetArg(args[j], XtNborderWidth, &bw); j++;
183 XtGetValues(hist->mvb, args, j);
187 XtSetArg(args[j], XtNwidth, &w); j++;
188 XtSetArg(args[j], XtNdefaultDistance, &dd); j++;
189 XtGetValues(hist->vbox, args, j);
194 extra = -((-extra)/2);
200 XtSetArg(args[j], XtNwidth, &w); j++;
201 XtGetValues(hist->mvw, args, j);
204 XtSetArg(args[j], XtNwidth, w); j++;
205 XtSetValues(hist->mvw, args, j);
208 XtSetArg(args[j], XtNwidth, &w); j++;
209 XtGetValues(hist->mvb, args, j);
212 XtSetArg(args[j], XtNwidth, w); j++;
213 XtSetValues(hist->mvb, args, j);
216 void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
219 if(last >= hist->aNr) HistoryAlloc(last+_LL_);
220 for(i=0;i<last;i++) {
223 char* p = strchr(movelist[i], ' ');
225 strncpy(hist->white[i/2+1], movelist[i], p-movelist[i]);
226 hist->white[i/2+1][p-movelist[i]] = NULLCHAR;
228 strcpy(hist->white[i/2+1],movelist[i]);
231 strcpy(hist->white[i/2+1],dots);
235 char* p = strchr(movelist[i], ' ');
237 strncpy(hist->black[i/2+1], movelist[i], p-movelist[i]);
238 hist->black[i/2+1][p-movelist[i]] = NULLCHAR;
240 strcpy(hist->black[i/2+1],movelist[i]);
243 strcpy(hist->black[i/2+1],"");
247 strcpy(hist->black[last/2+1],"");
250 XawFormDoLayout(hist->vbox, False);
251 XawListChange(hist->mvn,hist->Nr+b,m,0,True);
252 XawListChange(hist->mvw,hist->white+b,m,0,True);
253 XawListChange(hist->mvb,hist->black+b,m,0,True);
255 XawFormDoLayout(hist->vbox, True);
257 XawListUnhighlight(hist->mvw);
258 XawListUnhighlight(hist->mvb);
260 else if((current%2)==0){
261 XawListHighlight(hist->mvw, current/2+1);
262 XawListUnhighlight(hist->mvb);
265 XawListUnhighlight(hist->mvw);
266 if(current) XawListHighlight(hist->mvb, current/2+1);
267 else XawListUnhighlight(hist->mvb);
272 Widget HistoryCreate()
277 Widget layout,form,b_close;
279 "<Key>Up: BackwardProc() \n \
280 <Key>Left: BackwardProc() \n \
281 <Key>Down: ForwardProc() \n \
282 <Key>Right: ForwardProc() \n";
283 /*--- allocate memory for move-strings ---*/
286 /*-------- create the widgets ---------------*/
288 XtSetArg(args[j], XtNresizable, True); j++;
289 XtSetArg(args[j], XtNallowShellResize, True); j++;
292 XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass,
293 shellWidget, args, j);
296 XtCreatePopupShell(_("Move list"), transientShellWidgetClass,
297 shellWidget, args, j);
300 XtSetArg(args[j], XtNborderWidth, 0); j++;
301 XtSetArg(args[j], XtNdefaultDistance, 0); j++;
303 XtCreateManagedWidget(layoutName, formWidgetClass, hist->sh,
307 XtSetArg(args[j], XtNborderWidth, 0); j++;
308 XtSetArg(args[j], XtNresizable, True); j++;
311 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
316 XtSetArg(args[j], XtNtop, XtChainTop); j++;
317 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
318 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
319 XtSetArg(args[j], XtNright, XtChainRight); j++;
321 XtSetArg(args[j], XtNborderWidth, 1); j++;
322 XtSetArg(args[j], XtNresizable, False); j++;
323 XtSetArg(args[j], XtNallowVert, True); j++;
324 XtSetArg(args[j], XtNallowHoriz, True); j++;
325 XtSetArg(args[j], XtNforceBars, False); j++;
326 XtSetArg(args[j], XtNheight, 280); j++;
328 XtCreateManagedWidget("viewport", viewportWidgetClass,
331 XtSetArg(args[j], XtNborderWidth, 0); j++;
332 XtSetArg(args[j], XtNorientation,XtorientHorizontal);j++;
334 XtCreateManagedWidget("vbox", formWidgetClass, hist->viewport, args, j);
337 XtSetArg(args[j], XtNtop, XtChainTop); j++;
338 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
339 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
340 XtSetArg(args[j], XtNright, XtChainLeft); j++;
342 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
343 XtSetArg(args[j], XtNforceColumns, True); j++;
344 XtSetArg(args[j], XtNverticalList, True); j++;
345 XtSetArg(args[j], XtNborderWidth, 0); j++;
346 XtSetArg(args[j], XtNresizable,True);j++;
347 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
348 hist->mvn = XtCreateManagedWidget("movesn", listWidgetClass,
349 hist->vbox, args, j);
350 XtAddCallback(hist->mvn, XtNcallback, HistoryMoveProc, (XtPointer) hist);
353 XtSetArg(args[j], XtNtop, XtChainTop); j++;
354 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
355 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
356 XtSetArg(args[j], XtNright, XtRubber); j++;
358 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
359 XtSetArg(args[j], XtNforceColumns, True); j++;
360 XtSetArg(args[j], XtNverticalList, True); j++;
361 XtSetArg(args[j], XtNborderWidth, 0); j++;
362 XtSetArg(args[j], XtNresizable,True);j++;
363 XtSetArg(args[j], XtNfromHoriz, hist->mvn); j++;
364 hist->mvw = XtCreateManagedWidget("movesw", listWidgetClass,
365 hist->vbox, args, j);
366 XtAddCallback(hist->mvw, XtNcallback, HistoryMoveProc, (XtPointer) hist);
369 XtSetArg(args[j], XtNtop, XtChainTop); j++;
370 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
371 XtSetArg(args[j], XtNleft, XtRubber); j++;
372 XtSetArg(args[j], XtNright, XtRubber); j++;
374 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
375 XtSetArg(args[j], XtNforceColumns, True); j++;
376 XtSetArg(args[j], XtNverticalList, True); j++;
377 XtSetArg(args[j], XtNborderWidth, 0); j++;
378 XtSetArg(args[j], XtNresizable,True);j++;
379 XtSetArg(args[j], XtNfromHoriz, hist->mvw); j++;
380 hist->mvb = XtCreateManagedWidget("movesb", listWidgetClass,
381 hist->vbox, args, j);
382 XtAddCallback(hist->mvb, XtNcallback, HistoryMoveProc, (XtPointer) hist);
385 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
386 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
387 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
388 XtSetArg(args[j], XtNright, XtChainLeft); j++;
389 XtSetArg(args[j], XtNfromVert, hist->viewport); j++;
390 b_close= XtCreateManagedWidget(_("Close"), commandWidgetClass,
392 XtAddCallback(b_close, XtNcallback, HistoryPopDown, (XtPointer) 0);
394 XtAugmentTranslations(hist->sh,XtParseTranslationTable (trstr));
396 XtRealizeWidget(hist->sh);
397 CatchDeleteWindow(hist->sh, "HistoryPopDown");
399 for(i=1;i<hist->aNr;i++){
400 strcpy(hist->white[i],dots);
401 strcpy(hist->black[i],"");
413 if(!hist) HistoryCreate();
415 XtPopup(hist->sh, XtGrabNone);
417 // [HGM] restore old position
419 XtSetArg(args[j], XtNx, gameHistoryX); j++;
420 XtSetArg(args[j], XtNy, gameHistoryY); j++;
421 XtSetValues(hist->sh, args, j);
424 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
425 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"),
432 HistoryShowProc(w, event, prms, nprms)
441 } else if (hist->Up) {
442 HistoryPopDown(0,0,0);
446 ToNrEvent(currentMove);