moved some more items from the options menu into gtk
[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
67 void
68 HistoryPopDown(object, user_data)
69      GtkObject *object;
70      gpointer user_data;
71 {
72   gtk_widget_hide (GUI_History);
73   return;
74 }
75
76 void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data)
77 {
78     int to;
79     /*
80     XawListReturnStruct *R = (XawListReturnStruct *) call_data;
81     if (w == hist->mvn || w == hist->mvw) {
82       to=2*R->list_index-1;
83       ToNrEvent(to);
84     }
85     else if (w == hist->mvb) {
86       to=2*R->list_index;
87       ToNrEvent(to);
88     }
89     */
90 }
91
92
93 void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current)
94 {
95   int i,b,m;
96   char movewhite[2*MOVE_LEN],moveblack[2*MOVE_LEN],move[2*MOVE_LEN];
97   GtkTreeIter iter;
98
99   /* TODO need to add highlights for current move */
100   /* TODO need to add navigation by keyboard or mouse (double click on move) */
101
102   /* first clear everything, do we need this? */
103   gtk_list_store_clear(LIST_MoveHistory);
104
105   /* copy move list into history window */
106
107   /* go through all moves */
108   for(i=0;i<last;i++) 
109     {
110       /* test if there is a move */
111       if(movelist[i][0]) 
112         {
113           /* only copy everything before a  ' ' */
114           char* p = strchr(movelist[i], ' ');
115           if (p) 
116             {
117               strncpy(move, movelist[i], p-movelist[i]);
118               move[p-movelist[i]] = NULLCHAR;
119             } 
120           else 
121             {
122               strcpy(move,movelist[i]);
123             }
124         } 
125       else
126         strcpy(move,dots);
127       
128       if((i%2)==0) 
129         {
130           /* white move */
131           strcpy(movewhite,move);
132         }
133       else
134         {
135           /* black move */
136           strcpy(moveblack,move);
137
138           /* save move */
139           gtk_list_store_append (LIST_MoveHistory, &iter);
140           gtk_list_store_set (LIST_MoveHistory, &iter,
141                               0, i,
142                               1, movewhite,
143                               2, moveblack,
144                               -1);
145
146           strcpy(movewhite,"");
147           strcpy(moveblack,"");
148         };
149     }
150   /* check if ther is a white move left */
151   if(movewhite[0])
152     {
153       i++;
154       strcpy(moveblack,"");
155       /* save move */
156       gtk_list_store_append (LIST_MoveHistory, &iter);
157       gtk_list_store_set (LIST_MoveHistory, &iter,
158                           0, i,
159                           1, movewhite,
160                           2, moveblack,
161                           -1);
162     };
163   
164   return;
165 }
166
167 void HistoryCreate()
168 {
169     String trstr=
170              "<Key>Up: BackwardProc() \n \
171              <Key>Left: BackwardProc() \n \
172              <Key>Down: ForwardProc() \n \
173              <Key>Right: ForwardProc() \n";
174
175     return;
176 }
177
178 void
179 HistoryPopUp()
180 {
181   //  if(!hist) HistoryCreate();
182
183   gtk_widget_show (GUI_History);
184   
185   return;
186 }
187
188
189 void
190 HistoryShowProc(object, user_data)
191      GtkObject *object;
192      gpointer user_data;
193 {
194   HistoryCreate();
195   HistoryPopUp();
196   //TODO:  ToNrEvent(currentMove);
197
198   return;
199 }
200