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>
77 # define _(s) gettext (s)
78 # define N_(s) gettext_noop (s)
86 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
87 extern Display *xDisplay;
88 extern int squareSize;
89 extern Pixmap xMarkPixmap;
90 extern char *layoutName;
93 String *Nr,*white,*black;
94 int aNr; /* space actually alocated */
95 Widget mvn,mvw,mvb,vbox,viewport,sh;
99 struct History *hist=0;
103 HistoryPopDown(w, client_data, call_data)
105 XtPointer client_data, call_data;
115 XtSetArg(args[j], XtNleftBitmap, None); j++;
116 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move List"),
120 void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data)
123 XawListReturnStruct *R = (XawListReturnStruct *) call_data;
124 if (w == hist->mvn || w == hist->mvw) {
125 to=2*R->list_index-1;
128 else if (w == hist->mvb) {
134 void HistoryAlloc(int len){
137 free(hist->Nr[0]);free(hist->white[0]);free(hist->black[0]);
138 free(hist->Nr);free(hist->white);free(hist->black);
141 hist=(struct History*)malloc(sizeof(struct History));
144 hist->Nr=(String*)malloc(hist->aNr*sizeof(String*));
145 hist->white=(String*)malloc(hist->aNr*sizeof(String*));
146 hist->black=(String*)malloc(hist->aNr*sizeof(String*));
148 hist->Nr[0]=(String)malloc(hist->aNr*6);
149 hist->white[0]=(String)malloc(hist->aNr*MOVE_LEN);
150 hist->black[0]=(String)malloc(hist->aNr*MOVE_LEN);
152 sprintf(hist->Nr[0]," ");
153 sprintf(hist->white[0],_("White "));
154 sprintf(hist->black[0],_("Black "));
155 for(i=1;i<hist->aNr;i++){
156 hist->Nr[i]= hist->Nr[i-1]+6;
157 hist->white[i]= hist->white[i-1]+MOVE_LEN;
158 hist->black[i]= hist->black[i-1]+MOVE_LEN;
159 sprintf(hist->Nr[i],"%i.",i);
160 sprintf(hist->white[i],"-----");
161 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 /* Find empty space inside vbox form widget and redistribute it amongst
217 the list widgets inside it. */
218 /* This version doesn't work */
223 Dimension fw, niw, wiw, biw, nbw, wbw, bbw;
224 int j, nl, wl, bl, fdd;
228 XtSetArg(args[j], XtNwidth, &fw); j++;
229 XtSetArg(args[j], XtNdefaultDistance, &fdd); j++;
230 XtGetValues(hist->vbox, args, j);
233 XtSetArg(args[j], XtNlongest, &nl); j++;
234 XtSetArg(args[j], XtNinternalWidth, &niw); j++;
235 XtSetArg(args[j], XtNborderWidth, &nbw); j++;
236 XtGetValues(hist->mvn, args, j);
239 XtSetArg(args[j], XtNlongest, &wl); j++;
240 XtSetArg(args[j], XtNinternalWidth, &wiw); j++;
241 XtSetArg(args[j], XtNborderWidth, &wbw); j++;
242 XtGetValues(hist->mvw, args, j);
245 XtSetArg(args[j], XtNlongest, &bl); j++;
246 XtSetArg(args[j], XtNinternalWidth, &biw); j++;
247 XtSetArg(args[j], XtNborderWidth, &bbw); j++;
248 XtGetValues(hist->mvb, args, j);
251 nl - 1 - 2*niw - 2*nbw - wl - 2*wiw - 2*wbw - bl - 2*biw - 2*bbw;
252 if (extra < 0) extra = 0;
255 XtSetArg(args[j], XtNwidth, nl + 1 + 2*niw); j++;
256 XtSetValues(hist->mvn, args, j);
259 XtSetArg(args[j], XtNwidth, wl + 2*wiw + extra/2); j++;
260 XtSetValues(hist->mvw, args, j);
263 XtSetArg(args[j], XtNwidth, bl + 2*biw + extra/2); j++;
264 XtSetValues(hist->mvb, args, j);
268 void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
271 if(last >= hist->aNr) HistoryAlloc(last+_LL_);
272 for(i=0;i<last;i++) {
275 char* p = strchr(movelist[i], ' ');
277 strncpy(hist->white[i/2+1], movelist[i], p-movelist[i]);
278 hist->white[i/2+1][p-movelist[i]] = NULLCHAR;
280 strcpy(hist->white[i/2+1],movelist[i]);
283 strcpy(hist->white[i/2+1],dots);
287 char* p = strchr(movelist[i], ' ');
289 strncpy(hist->black[i/2+1], movelist[i], p-movelist[i]);
290 hist->black[i/2+1][p-movelist[i]] = NULLCHAR;
292 strcpy(hist->black[i/2+1],movelist[i]);
295 strcpy(hist->black[i/2+1],"");
299 strcpy(hist->black[last/2+1],"");
302 XawFormDoLayout(hist->vbox, False);
303 XawListChange(hist->mvn,hist->Nr+b,m,0,True);
304 XawListChange(hist->mvw,hist->white+b,m,0,True);
305 XawListChange(hist->mvb,hist->black+b,m,0,True);
307 XawFormDoLayout(hist->vbox, True);
309 XawListUnhighlight(hist->mvw);
310 XawListUnhighlight(hist->mvb);
312 else if((current%2)==0){
313 XawListHighlight(hist->mvw, current/2+1);
314 XawListUnhighlight(hist->mvb);
317 XawListUnhighlight(hist->mvw);
318 if(current) XawListHighlight(hist->mvb, current/2+1);
319 else XawListUnhighlight(hist->mvb);
324 Widget HistoryCreate()
329 Widget layout,form,b_close;
331 "<Key>Up: BackwardProc() \n \
332 <Key>Left: BackwardProc() \n \
333 <Key>Down: ForwardProc() \n \
334 <Key>Right: ForwardProc() \n";
335 /*--- allocate memory for move-strings ---*/
338 /*-------- create the widgets ---------------*/
340 XtSetArg(args[j], XtNresizable, True); j++;
341 XtSetArg(args[j], XtNallowShellResize, True); j++;
344 XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass,
345 shellWidget, args, j);
348 XtCreatePopupShell(_("Move list"), transientShellWidgetClass,
349 shellWidget, args, j);
352 XtSetArg(args[j], XtNborderWidth, 0); j++;
353 XtSetArg(args[j], XtNdefaultDistance, 0); j++;
355 XtCreateManagedWidget(layoutName, formWidgetClass, hist->sh,
359 XtSetArg(args[j], XtNborderWidth, 0); j++;
360 XtSetArg(args[j], XtNresizable, True); j++;
363 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
368 XtSetArg(args[j], XtNtop, XtChainTop); j++;
369 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
370 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
371 XtSetArg(args[j], XtNright, XtChainRight); j++;
373 XtSetArg(args[j], XtNborderWidth, 1); j++;
374 XtSetArg(args[j], XtNresizable, False); j++;
375 XtSetArg(args[j], XtNallowVert, True); j++;
376 XtSetArg(args[j], XtNallowHoriz, True); j++;
377 XtSetArg(args[j], XtNforceBars, False); j++;
378 XtSetArg(args[j], XtNheight, 280); j++;
380 XtCreateManagedWidget("viewport", viewportWidgetClass,
383 XtSetArg(args[j], XtNborderWidth, 0); j++;
384 XtSetArg(args[j], XtNorientation,XtorientHorizontal);j++;
386 XtCreateManagedWidget("vbox", formWidgetClass, hist->viewport, args, j);
389 XtSetArg(args[j], XtNtop, XtChainTop); j++;
390 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
391 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
392 XtSetArg(args[j], XtNright, XtChainLeft); j++;
394 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
395 XtSetArg(args[j], XtNforceColumns, True); j++;
396 XtSetArg(args[j], XtNverticalList, True); j++;
397 XtSetArg(args[j], XtNborderWidth, 0); j++;
398 XtSetArg(args[j], XtNresizable,True);j++;
399 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
400 hist->mvn = XtCreateManagedWidget("movesn", listWidgetClass,
401 hist->vbox, args, j);
402 XtAddCallback(hist->mvn, XtNcallback, HistoryMoveProc, (XtPointer) hist);
405 XtSetArg(args[j], XtNtop, XtChainTop); j++;
406 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
407 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
408 XtSetArg(args[j], XtNright, XtRubber); j++;
410 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
411 XtSetArg(args[j], XtNforceColumns, True); j++;
412 XtSetArg(args[j], XtNverticalList, True); j++;
413 XtSetArg(args[j], XtNborderWidth, 0); j++;
414 XtSetArg(args[j], XtNresizable,True);j++;
415 XtSetArg(args[j], XtNfromHoriz, hist->mvn); j++;
416 hist->mvw = XtCreateManagedWidget("movesw", listWidgetClass,
417 hist->vbox, args, j);
418 XtAddCallback(hist->mvw, XtNcallback, HistoryMoveProc, (XtPointer) hist);
421 XtSetArg(args[j], XtNtop, XtChainTop); j++;
422 XtSetArg(args[j], XtNbottom, XtChainTop); j++;
423 XtSetArg(args[j], XtNleft, XtRubber); j++;
424 XtSetArg(args[j], XtNright, XtRubber); j++;
426 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
427 XtSetArg(args[j], XtNforceColumns, True); j++;
428 XtSetArg(args[j], XtNverticalList, True); j++;
429 XtSetArg(args[j], XtNborderWidth, 0); j++;
430 XtSetArg(args[j], XtNresizable,True);j++;
431 XtSetArg(args[j], XtNfromHoriz, hist->mvw); j++;
432 hist->mvb = XtCreateManagedWidget("movesb", listWidgetClass,
433 hist->vbox, args, j);
434 XtAddCallback(hist->mvb, XtNcallback, HistoryMoveProc, (XtPointer) hist);
437 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
438 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
439 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
440 XtSetArg(args[j], XtNright, XtChainLeft); j++;
441 XtSetArg(args[j], XtNfromVert, hist->viewport); j++;
442 b_close= XtCreateManagedWidget(_("Close"), commandWidgetClass,
444 XtAddCallback(b_close, XtNcallback, HistoryPopDown, (XtPointer) 0);
446 XtAugmentTranslations(hist->sh,XtParseTranslationTable (trstr));
448 XtRealizeWidget(hist->sh);
449 CatchDeleteWindow(hist->sh, "HistoryPopDown");
451 for(i=1;i<hist->aNr;i++){
452 strcpy(hist->white[i],dots);
453 strcpy(hist->black[i],"");
465 if(!hist) HistoryCreate();
466 XtPopup(hist->sh, XtGrabNone);
468 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
469 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move List"),
476 HistoryShowProc(w, event, prms, nprms)
485 } else if (hist->Up) {
486 HistoryPopDown(0,0,0);
490 ToNrEvent(currentMove);