worked on MoveHistory window
[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   /* hides the history window */
75
76   gtk_widget_hide (GUI_History);
77   return;
78 }
79
80 void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data)
81 {
82     int to;
83     /*
84     XawListReturnStruct *R = (XawListReturnStruct *) call_data;
85     if (w == hist->mvn || w == hist->mvw) {
86       to=2*R->list_index-1;
87       ToNrEvent(to);
88     }
89     else if (w == hist->mvb) {
90       to=2*R->list_index;
91       ToNrEvent(to);
92     }
93     */
94 }
95
96
97 void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current)
98 {
99   int i,b,m;
100   char movewhite[2*MOVE_LEN],moveblack[2*MOVE_LEN],move[2*MOVE_LEN];
101   GtkTreeIter iter;
102
103   /* TODO need to add highlights for current move */
104   /* TODO need to add navigation by keyboard or mouse (double click on move) */
105
106
107   /* first clear everything, do we need this? */
108   gtk_list_store_clear(LIST_MoveHistory);
109
110   /* copy move list into history window */
111
112   /* go through all moves */
113   for(i=0;i<last;i++) 
114     {
115       /* test if there is a move */
116       if(movelist[i][0]) 
117         {
118           /* only copy everything before a  ' ' */
119           char* p = strchr(movelist[i], ' ');
120           if (p) 
121             {
122               strncpy(move, movelist[i], p-movelist[i]);
123               move[p-movelist[i]] = NULLCHAR;
124             } 
125           else 
126             {
127               strcpy(move,movelist[i]);
128             }
129         } 
130       else
131         strcpy(move,dots);
132       
133       if((i%2)==0) 
134         {
135           /* white move */
136           strcpy(movewhite,move);
137         }
138       else
139         {
140           /* black move */
141           strcpy(moveblack,move);
142
143           /* save move */
144           gtk_list_store_append (LIST_MoveHistory, &iter);
145           gtk_list_store_set (LIST_MoveHistory, &iter,
146                               0, (i/2 +1),
147                               1, movewhite,
148                               2, moveblack,
149                               -1);
150
151           strcpy(movewhite,"");
152           strcpy(moveblack,"");
153         };
154     }
155
156   /* check if there is a white move left */
157   if(movewhite[0])
158     {
159       strcpy(moveblack,"");
160
161       /* save move */
162       gtk_list_store_append (LIST_MoveHistory, &iter);
163       gtk_list_store_set (LIST_MoveHistory, &iter,
164                           0, (i/2 +1),
165                           1, movewhite,
166                           2, moveblack,
167                           -1);
168     };
169
170
171   //TODO
172   //  EvalGraphSet( first, last, current, pvInfoList ); // piggy-backed
173   
174   return;
175 }
176
177 void HistoryCreate()
178 {
179     String trstr=
180              "<Key>Up: BackwardProc() \n \
181              <Key>Left: BackwardProc() \n \
182              <Key>Down: ForwardProc() \n \
183              <Key>Right: ForwardProc() \n";
184
185     return;
186 //    if(wpMoveHistory.width > 0) {
187 //      gameHistoryW = wpMoveHistory.width;
188 //      gameHistoryH = wpMoveHistory.height;
189 //      gameHistoryX = wpMoveHistory.x;
190 //      gameHistoryY = wpMoveHistory.y;
191 //    }
192 //
193 //  // [HGM] restore old position
194 //  if(gameHistoryW > 0) {
195 //  j = 0;
196 //    XtSetArg(args[j], XtNx, gameHistoryX);  j++;
197 //  XtSetArg(args[j], XtNy, gameHistoryY);  j++;
198 //    XtSetArg(args[j], XtNwidth, gameHistoryW);  j++;
199 //    XtSetArg(args[j], XtNheight, gameHistoryH);  j++;
200 //  XtSetValues(hist->sh, args, j);
201 //  }
202 }
203
204 void
205 HistoryPopUp()
206 {
207   /* show history window */
208
209   gtk_widget_show (GUI_History);
210   return;
211 }
212
213
214 void
215 HistoryShowProc(object, user_data)
216      GtkObject *object;
217      gpointer user_data;
218 {
219   HistoryCreate();
220   HistoryPopUp();
221   //TODO:  ToNrEvent(currentMove);
222
223   return;
224 }
225
226 Boolean
227 MoveHistoryIsUp()
228 {
229   /* return status of history window */
230   
231   return gtk_widget_get_visible (GUI_History);
232 }