2 * xhistory.c -- Move list window, part of X front end for XBoard
5 * Copyright 2000 Free Software Foundation, Inc.
7 * The following terms apply to the enhanced version of XBoard distributed
8 * by the Free Software Foundation:
9 * ------------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * ------------------------------------------------------------------------
25 * See the file ChangeLog for a revision history.
33 #include <sys/types.h>
38 #else /* not STDC_HEADERS */
39 extern char *getenv();
42 # else /* not HAVE_STRING_H */
44 # endif /* not HAVE_STRING_H */
45 #endif /* not STDC_HEADERS */
51 #include <X11/Intrinsic.h>
52 #include <X11/StringDefs.h>
53 #include <X11/Shell.h>
54 #include <X11/Xaw/Dialog.h>
55 #include <X11/Xaw/Form.h>
56 #include <X11/Xaw/List.h>
57 #include <X11/Xaw/Label.h>
58 #include <X11/Xaw/SimpleMenu.h>
59 #include <X11/Xaw/SmeBSB.h>
60 #include <X11/Xaw/SmeLine.h>
61 #include <X11/Xaw/Box.h>
62 #include <X11/Xaw/Paned.h>
63 #include <X11/Xaw/MenuButton.h>
64 #include <X11/cursorfont.h>
65 #include <X11/Xaw/Text.h>
66 #include <X11/Xaw/AsciiText.h>
67 #include <X11/Xaw/Viewport.h>
78 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
79 extern Display *xDisplay;
80 extern int squareSize;
81 extern Pixmap xMarkPixmap;
82 extern char *layoutName;
85 String *Nr,*white,*black;
86 int aNr; /* space actually alocated */
87 Widget mvn,mvw,mvb,vbox,viewport,sh;
91 struct History *hist=0;
95 HistoryPopDown(w, client_data, call_data)
97 XtPointer client_data, call_data;
107 XtSetArg(args[j], XtNleftBitmap, None); j++;
108 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move List"),
112 void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data)
115 XawListReturnStruct *R = (XawListReturnStruct *) call_data;
116 if (w == hist->mvn || w == hist->mvw) {
117 to=2*R->list_index-1;
120 else if (w == hist->mvb) {
126 void HistoryAlloc(int len){
129 free(hist->Nr[0]);free(hist->white[0]);free(hist->black[0]);
130 free(hist->Nr);free(hist->white);free(hist->black);
133 hist=(struct History*)malloc(sizeof(struct History));
136 hist->Nr=(String*)malloc(hist->aNr*sizeof(String*));
137 hist->white=(String*)malloc(hist->aNr*sizeof(String*));
138 hist->black=(String*)malloc(hist->aNr*sizeof(String*));
140 hist->Nr[0]=(String)malloc(hist->aNr*6);
141 hist->white[0]=(String)malloc(hist->aNr*MOVE_LEN);
142 hist->black[0]=(String)malloc(hist->aNr*MOVE_LEN);
144 sprintf(hist->Nr[0]," ");
145 sprintf(hist->white[0],"White ");
146 sprintf(hist->black[0],"Black ");
147 for(i=1;i<hist->aNr;i++){
148 hist->Nr[i]= hist->Nr[i-1]+6;
149 hist->white[i]= hist->white[i-1]+MOVE_LEN;
150 hist->black[i]= hist->black[i-1]+MOVE_LEN;
151 sprintf(hist->Nr[i],"%i.",i);
152 sprintf(hist->white[i],"-----");
153 sprintf(hist->black[i],"-----");
159 /* Find empty space inside vbox form widget and redistribute it amongst
160 the list widgets inside it. */
161 /* This version sort of works */
172 XtSetArg(args[j], XtNx, &x); j++;
173 XtSetArg(args[j], XtNwidth, &w); j++;
174 XtSetArg(args[j], XtNborderWidth, &bw); j++;
175 XtGetValues(hist->mvb, args, j);
179 XtSetArg(args[j], XtNwidth, &w); j++;
180 XtSetArg(args[j], XtNdefaultDistance, &dd); j++;
181 XtGetValues(hist->vbox, args, j);
186 extra = -((-extra)/2);
192 XtSetArg(args[j], XtNwidth, &w); j++;
193 XtGetValues(hist->mvw, args, j);
196 XtSetArg(args[j], XtNwidth, w); j++;
197 XtSetValues(hist->mvw, args, j);
200 XtSetArg(args[j], XtNwidth, &w); j++;
201 XtGetValues(hist->mvb, args, j);
204 XtSetArg(args[j], XtNwidth, w); j++;
205 XtSetValues(hist->mvb, args, j);
208 /* Find empty space inside vbox form widget and redistribute it amongst
209 the list widgets inside it. */
210 /* This version doesn't work */
215 Dimension fw, niw, wiw, biw, nbw, wbw, bbw;
216 int j, nl, wl, bl, fdd;
220 XtSetArg(args[j], XtNwidth, &fw); j++;
221 XtSetArg(args[j], XtNdefaultDistance, &fdd); j++;
222 XtGetValues(hist->vbox, args, j);
225 XtSetArg(args[j], XtNlongest, &nl); j++;
226 XtSetArg(args[j], XtNinternalWidth, &niw); j++;
227 XtSetArg(args[j], XtNborderWidth, &nbw); j++;
228 XtGetValues(hist->mvn, args, j);
231 XtSetArg(args[j], XtNlongest, &wl); j++;
232 XtSetArg(args[j], XtNinternalWidth, &wiw); j++;
233 XtSetArg(args[j], XtNborderWidth, &wbw); j++;
234 XtGetValues(hist->mvw, args, j);
237 XtSetArg(args[j], XtNlongest, &bl); j++;
238 XtSetArg(args[j], XtNinternalWidth, &biw); j++;
239 XtSetArg(args[j], XtNborderWidth, &bbw); j++;
240 XtGetValues(hist->mvb, args, j);
243 nl - 1 - 2*niw - 2*nbw - wl - 2*wiw - 2*wbw - bl - 2*biw - 2*bbw;
244 if (extra < 0) extra = 0;
247 XtSetArg(args[j], XtNwidth, nl + 1 + 2*niw); j++;
248 XtSetValues(hist->mvn, args, j);
251 XtSetArg(args[j], XtNwidth, wl + 2*wiw + extra/2); j++;
252 XtSetValues(hist->mvw, args, j);
255 XtSetArg(args[j], XtNwidth, bl + 2*biw + extra/2); j++;
256 XtSetValues(hist->mvb, args, j);
260 void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
263 if(last >= hist->aNr) HistoryAlloc(last+_LL_);
264 for(i=0;i<last;i++) {
267 char* p = strchr(movelist[i], ' ');
269 strncpy(hist->white[i/2+1], movelist[i], p-movelist[i]);
270 hist->white[i/2+1][p-movelist[i]] = NULLCHAR;
272 strcpy(hist->white[i/2+1],movelist[i]);
275 strcpy(hist->white[i/2+1],dots);
279 char* p = strchr(movelist[i], ' ');
281 strncpy(hist->black[i/2+1], movelist[i], p-movelist[i]);
282 hist->black[i/2+1][p-movelist[i]] = NULLCHAR;
284 strcpy(hist->black[i/2+1],movelist[i]);
287 strcpy(hist->black[i/2+1],"");
291 strcpy(hist->black[last/2+1],"");
294 XawFormDoLayout(hist->vbox, False);
295 XawListChange(hist->mvn,hist->Nr+b,m,0,True);
296 XawListChange(hist->mvw,hist->white+b,m,0,True);
297 XawListChange(hist->mvb,hist->black+b,m,0,True);
299 XawFormDoLayout(hist->vbox, True);
301 XawListUnhighlight(hist->mvw);
302 XawListUnhighlight(hist->mvb);
304 else if((current%2)==0){
305 XawListHighlight(hist->mvw, current/2+1);
306 XawListUnhighlight(hist->mvb);
309 XawListUnhighlight(hist->mvw);
310 if(current) XawListHighlight(hist->mvb, current/2+1);
311 else XawListUnhighlight(hist->mvb);
316 Widget HistoryCreate()
321 Widget layout,form,b_close;
323 "<Key>Up: BackwardProc() \n \
324 <Key>Left: BackwardProc() \n \
325 <Key>Down: ForwardProc() \n \
326 <Key>Right: ForwardProc() \n";
327 /*--- allocate memory for move-strings ---*/
330 /*-------- create the widgets ---------------*/
332 XtSetArg(args[j], XtNresizable, True); j++;
333 XtSetArg(args[j], XtNallowShellResize, True); j++;
336 XtCreatePopupShell("Move list", topLevelShellWidgetClass,
337 shellWidget, args, j);
340 XtCreatePopupShell("Move list", transientShellWidgetClass,
341 shellWidget, args, j);
344 XtSetArg(args[j], XtNborderWidth, 0); j++;
345 XtSetArg(args[j], XtNdefaultDistance, 0); j++;
347 XtCreateManagedWidget(layoutName, formWidgetClass, hist->sh,
351 XtSetArg(args[j], XtNborderWidth, 0); j++;
352 XtSetArg(args[j], XtNresizable, True); j++;
355 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
360 XtSetArg(args[j], XtNtop, XtChainTop); j++;
361 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
362 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
363 XtSetArg(args[j], XtNright, XtChainRight); j++;
365 XtSetArg(args[j], XtNborderWidth, 1); j++;
366 XtSetArg(args[j], XtNresizable, False); j++;
367 XtSetArg(args[j], XtNallowVert, True); j++;
368 XtSetArg(args[j], XtNallowHoriz, True); j++;
369 XtSetArg(args[j], XtNforceBars, False); j++;
370 XtSetArg(args[j], XtNheight, 280); j++;
372 XtCreateManagedWidget("viewport", viewportWidgetClass,
375 XtSetArg(args[j], XtNborderWidth, 0); j++;
376 XtSetArg(args[j], XtNorientation,XtorientHorizontal);j++;
378 XtCreateManagedWidget("vbox", formWidgetClass, hist->viewport, args, j);
381 XtSetArg(args[j], XtNtop, XtChainTop); j++;
382 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
383 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
384 XtSetArg(args[j], XtNright, XtChainLeft); j++;
386 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
387 XtSetArg(args[j], XtNforceColumns, True); j++;
388 XtSetArg(args[j], XtNverticalList, True); j++;
389 XtSetArg(args[j], XtNborderWidth, 0); j++;
390 XtSetArg(args[j], XtNresizable,True);j++;
391 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
392 hist->mvn = XtCreateManagedWidget("movesn", listWidgetClass,
393 hist->vbox, args, j);
394 XtAddCallback(hist->mvn, XtNcallback, HistoryMoveProc, (XtPointer) hist);
397 XtSetArg(args[j], XtNtop, XtChainTop); j++;
398 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
399 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
400 XtSetArg(args[j], XtNright, XtRubber); j++;
402 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
403 XtSetArg(args[j], XtNforceColumns, True); j++;
404 XtSetArg(args[j], XtNverticalList, True); j++;
405 XtSetArg(args[j], XtNborderWidth, 0); j++;
406 XtSetArg(args[j], XtNresizable,True);j++;
407 XtSetArg(args[j], XtNfromHoriz, hist->mvn); j++;
408 hist->mvw = XtCreateManagedWidget("movesw", listWidgetClass,
409 hist->vbox, args, j);
410 XtAddCallback(hist->mvw, XtNcallback, HistoryMoveProc, (XtPointer) hist);
413 XtSetArg(args[j], XtNtop, XtChainTop); j++;
414 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
415 XtSetArg(args[j], XtNleft, XtRubber); j++;
416 XtSetArg(args[j], XtNright, XtRubber); j++;
418 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
419 XtSetArg(args[j], XtNforceColumns, True); j++;
420 XtSetArg(args[j], XtNverticalList, True); j++;
421 XtSetArg(args[j], XtNborderWidth, 0); j++;
422 XtSetArg(args[j], XtNresizable,True);j++;
423 XtSetArg(args[j], XtNfromHoriz, hist->mvw); j++;
424 hist->mvb = XtCreateManagedWidget("movesb", listWidgetClass,
425 hist->vbox, args, j);
426 XtAddCallback(hist->mvb, XtNcallback, HistoryMoveProc, (XtPointer) hist);
429 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
430 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
431 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
432 XtSetArg(args[j], XtNright, XtChainLeft); j++;
433 XtSetArg(args[j], XtNfromVert, hist->viewport); j++;
434 b_close= XtCreateManagedWidget("Close", commandWidgetClass,
436 XtAddCallback(b_close, XtNcallback, HistoryPopDown, (XtPointer) 0);
438 XtAugmentTranslations(hist->sh,XtParseTranslationTable (trstr));
440 XtRealizeWidget(hist->sh);
441 CatchDeleteWindow(hist->sh, "HistoryPopDown");
443 for(i=1;i<hist->aNr;i++){
444 strcpy(hist->white[i],dots);
445 strcpy(hist->black[i],"");
457 if(!hist) HistoryCreate();
458 XtPopup(hist->sh, XtGrabNone);
460 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
461 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move List"),
468 HistoryShowProc(w, event, prms, nprms)
477 } else if (hist->Up) {
478 HistoryPopDown(0,0,0);
482 ToNrEvent(currentMove);