reindent some functions
[xboard.git] / xhistory.c
1 /*
2  * xhistory.c -- Move list window, part of X front end for XBoard
3  *
4  * Copyright 2000,2009 Free Software Foundation, Inc.
5  * ------------------------------------------------------------------------
6  *
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.
11  *
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.
16  *
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/.  *
19  *
20  *------------------------------------------------------------------------
21  ** See the file ChangeLog for a revision history.  */
22
23 #include "config.h"
24
25 #include <gtk/gtk.h>
26 #include <stdio.h>
27 #include <ctype.h>
28 #include <errno.h>
29 #include <sys/types.h>
30
31 #if STDC_HEADERS
32 # include <stdlib.h>
33 # include <string.h>
34 #else /* not STDC_HEADERS */
35 extern char *getenv();
36 # if HAVE_STRING_H
37 #  include <string.h>
38 # else /* not HAVE_STRING_H */
39 #  include <strings.h>
40 # endif /* not HAVE_STRING_H */
41 #endif /* not STDC_HEADERS */
42
43 #if HAVE_UNISTD_H
44 # include <unistd.h>
45 #endif
46
47 #include "common.h"
48 #include "frontend.h"
49 #include "backend.h"
50 #include "xboard.h"
51 #include "xhistory.h"
52 #include "gettext.h"
53
54 #ifdef ENABLE_NLS
55 # define  _(s) gettext (s)
56 # define N_(s) gettext_noop (s)
57 #else
58 # define  _(s) (s)
59 # define N_(s)  s
60 #endif
61
62 extern GtkWidget               *GUI_History;
63 extern GtkListStore            *LIST_MoveHistory;
64
65 String dots=" ... ";
66 Position gameHistoryX, gameHistoryY;
67 Dimension gameHistoryW, gameHistoryH;
68
69 void
70 HistoryPopDown(object, user_data)
71      GtkObject *object;
72      gpointer user_data;
73 {
74   gtk_widget_hide (GUI_History);
75   return;
76 }
77
78 void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data)
79 {
80     int to;
81     /*
82     XawListReturnStruct *R = (XawListReturnStruct *) call_data;
83     if (w == hist->mvn || w == hist->mvw) {
84       to=2*R->list_index-1;
85       ToNrEvent(to);
86     }
87     else if (w == hist->mvb) {
88       to=2*R->list_index;
89       ToNrEvent(to);
90     }
91     */
92 }
93
94
95 void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current)
96 {
97   int i,b,m;
98   char movewhite[2*MOVE_LEN],moveblack[2*MOVE_LEN],move[2*MOVE_LEN];
99   GtkTreeIter iter;
100
101   /* TODO need to add highlights for current move */
102   /* TODO need to add navigation by keyboard or mouse (double click on move) */
103
104   /* first clear everything, do we need this? */
105   gtk_list_store_clear(LIST_MoveHistory);
106
107   /* copy move list into history window */
108
109   /* go through all moves */
110   for(i=0;i<last;i++) 
111     {
112       /* test if there is a move */
113       if(movelist[i][0]) 
114         {
115           /* only copy everything before a  ' ' */
116           char* p = strchr(movelist[i], ' ');
117           if (p) 
118             {
119               strncpy(move, movelist[i], p-movelist[i]);
120               move[p-movelist[i]] = NULLCHAR;
121             } 
122           else 
123             {
124               strcpy(move,movelist[i]);
125             }
126         } 
127       else
128         strcpy(move,dots);
129       
130       if((i%2)==0) 
131         {
132           /* white move */
133           strcpy(movewhite,move);
134         }
135       else
136         {
137           /* black move */
138           strcpy(moveblack,move);
139
140           /* save move */
141           gtk_list_store_append (LIST_MoveHistory, &iter);
142           gtk_list_store_set (LIST_MoveHistory, &iter,
143                               0, i,
144                               1, movewhite,
145                               2, moveblack,
146                               -1);
147
148           strcpy(movewhite,"");
149           strcpy(moveblack,"");
150         };
151     }
152
153   /* check if ther is a white move left */
154   if(movewhite[0])
155     {
156       i++;
157       strcpy(moveblack,"");
158       /* save move */
159       gtk_list_store_append (LIST_MoveHistory, &iter);
160       gtk_list_store_set (LIST_MoveHistory, &iter,
161                           0, i,
162                           1, movewhite,
163                           2, moveblack,
164                           -1);
165     };
166
167   //TODO
168   //  EvalGraphSet( first, last, current, pvInfoList ); // piggy-backed
169   
170   return;
171 }
172
173 void HistoryCreate()
174 {
175     String trstr=
176              "<Key>Up: BackwardProc() \n \
177              <Key>Left: BackwardProc() \n \
178              <Key>Down: ForwardProc() \n \
179              <Key>Right: ForwardProc() \n";
180
181     return;
182     /*-------- create the widgets ---------------*/
183 //<<<<<<< HEAD
184 //    j = 0;
185 //    XtSetArg(args[j], XtNresizable, True);  j++;
186 //    XtSetArg(args[j], XtNallowShellResize, True);  j++;
187 //#if TOPLEVEL
188 //    hist->sh = historyShell =
189 //      XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass,
190 //                       shellWidget, args, j);
191 //#else
192 //    hist->sh = historyShell =
193 //      XtCreatePopupShell(_("Move list"), transientShellWidgetClass,
194 //                       shellWidget, args, j);
195 //#endif
196 //    j = 0;
197 //    XtSetArg(args[j], XtNborderWidth, 0); j++;
198 //    XtSetArg(args[j], XtNdefaultDistance, 0);  j++;
199 //      layout =
200 //      XtCreateManagedWidget(layoutName, formWidgetClass, hist->sh,
201 //                          args, j);
202 //
203 //    j = 0;
204 //    XtSetArg(args[j], XtNborderWidth, 0); j++;
205 //    XtSetArg(args[j], XtNresizable, True);  j++;
206 //
207 //    form =
208 //      XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
209 //
210 //    j = 0;
211 //    XtSetArg(args[j], XtNtop, XtChainTop);  j++;
212 //    XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
213 //    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
214 //    XtSetArg(args[j], XtNright, XtChainRight);  j++;
215 //
216 //    XtSetArg(args[j], XtNborderWidth, 1); j++;
217 //    XtSetArg(args[j], XtNresizable, False);  j++;
218 //    XtSetArg(args[j], XtNallowVert, True); j++;
219 //    XtSetArg(args[j], XtNallowHoriz, True);  j++;
220 //    XtSetArg(args[j], XtNforceBars, False); j++;
221 //    XtSetArg(args[j], XtNheight, 280); j++;
222 //    hist->viewport =
223 //      XtCreateManagedWidget("viewport", viewportWidgetClass,
224 //                          form, args, j);
225 //    j=0;
226 //    XtSetArg(args[j], XtNborderWidth, 0); j++;
227 //    XtSetArg(args[j], XtNorientation,XtorientHorizontal);j++;
228 //    hist->vbox =
229 //      XtCreateManagedWidget("vbox", formWidgetClass, hist->viewport, args, j);
230 //
231 //    j=0;
232 //    XtSetArg(args[j], XtNtop, XtChainTop);  j++;
233 //    XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
234 //    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
235 //    XtSetArg(args[j], XtNright, XtChainLeft);  j++;
236 //
237 //    XtSetArg(args[j], XtNdefaultColumns, 1);  j++;
238 //    XtSetArg(args[j], XtNforceColumns, True);  j++;
239 //    XtSetArg(args[j], XtNverticalList, True);  j++;
240 //    XtSetArg(args[j], XtNborderWidth, 0); j++;
241 //    XtSetArg(args[j], XtNresizable,True);j++;
242 //    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
243 //    hist->mvn = XtCreateManagedWidget("movesn", listWidgetClass,
244 //                                    hist->vbox, args, j);
245 //    XtAddCallback(hist->mvn, XtNcallback, HistoryMoveProc, (XtPointer) hist);
246 //
247 //    j=0;
248 //    XtSetArg(args[j], XtNtop, XtChainTop);  j++;
249 //    XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
250 //    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
251 //    XtSetArg(args[j], XtNright, XtRubber);  j++;
252 //
253 //    XtSetArg(args[j], XtNdefaultColumns, 1);  j++;
254 //    XtSetArg(args[j], XtNforceColumns, True);  j++;
255 //    XtSetArg(args[j], XtNverticalList, True);  j++;
256 //    XtSetArg(args[j], XtNborderWidth, 0); j++;
257 //    XtSetArg(args[j], XtNresizable,True);j++;
258 //    XtSetArg(args[j], XtNfromHoriz, hist->mvn);  j++;
259 //    hist->mvw = XtCreateManagedWidget("movesw", listWidgetClass,
260 //                                    hist->vbox, args, j);
261 //    XtAddCallback(hist->mvw, XtNcallback, HistoryMoveProc, (XtPointer) hist);
262 //
263 //    j=0;
264 //    XtSetArg(args[j], XtNtop, XtChainTop);  j++;
265 //    XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
266 //    XtSetArg(args[j], XtNleft, XtRubber);  j++;
267 //    XtSetArg(args[j], XtNright,  XtRubber);  j++;
268 //
269 //    XtSetArg(args[j], XtNdefaultColumns, 1);  j++;
270 //    XtSetArg(args[j], XtNforceColumns, True);  j++;
271 //    XtSetArg(args[j], XtNverticalList, True);  j++;
272 //    XtSetArg(args[j], XtNborderWidth, 0); j++;
273 //    XtSetArg(args[j], XtNresizable,True);j++;
274 //    XtSetArg(args[j], XtNfromHoriz, hist->mvw);  j++;
275 //    hist->mvb = XtCreateManagedWidget("movesb", listWidgetClass,
276 //                                    hist->vbox, args, j);
277 //    XtAddCallback(hist->mvb, XtNcallback, HistoryMoveProc, (XtPointer) hist);
278 //
279 //    j=0;
280 //    XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
281 //    XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
282 //    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
283 //    XtSetArg(args[j], XtNright, XtChainLeft);  j++;
284 //    XtSetArg(args[j], XtNfromVert, hist->viewport);  j++;
285 //    b_close= XtCreateManagedWidget(_("Close"), commandWidgetClass,
286 //                                 form, args, j);
287 //    XtAddCallback(b_close, XtNcallback, HistoryPopDown, (XtPointer) 0);
288 //
289 //    XtAugmentTranslations(hist->sh,XtParseTranslationTable (trstr));
290 //
291 //    XtRealizeWidget(hist->sh);
292 //    CatchDeleteWindow(hist->sh, "HistoryPopDown");
293 //
294 //    for(i=1;i<hist->aNr;i++){
295 //      strcpy(hist->white[i],dots);
296 //      strcpy(hist->black[i],"");
297 //     }
298 //
299 //    if(wpMoveHistory.width > 0) {
300 //      gameHistoryW = wpMoveHistory.width;
301 //      gameHistoryH = wpMoveHistory.height;
302 //      gameHistoryX = wpMoveHistory.x;
303 //      gameHistoryY = wpMoveHistory.y;
304 //    }
305 //
306 //  // [HGM] restore old position
307 //  if(gameHistoryW > 0) {
308 //  j = 0;
309 //    XtSetArg(args[j], XtNx, gameHistoryX);  j++;
310 //  XtSetArg(args[j], XtNy, gameHistoryY);  j++;
311 //    XtSetArg(args[j], XtNwidth, gameHistoryW);  j++;
312 //    XtSetArg(args[j], XtNheight, gameHistoryH);  j++;
313 //  XtSetValues(hist->sh, args, j);
314 //  }
315 //    XtRealizeWidget(hist->sh);
316 //
317 //    return hist->sh;
318 //
319 }
320
321 void
322 HistoryPopUp()
323 {
324   //  if(!hist) HistoryCreate();
325
326   gtk_widget_show (GUI_History);
327   
328   return;
329 }
330
331
332 void
333 HistoryShowProc(object, user_data)
334      GtkObject *object;
335      gpointer user_data;
336 {
337   HistoryCreate();
338   HistoryPopUp();
339   //TODO:  ToNrEvent(currentMove);
340
341   return;
342 }
343
344 Boolean
345 MoveHistoryIsUp()
346 {
347   // TODO
348   return 0;
349   //  return hist && hist->Up;
350 }