new developer release
[xboard.git] / xhistory.c
index ee865fd..af292c6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * xhistory.c -- Move list window, part of X front end for XBoard
  *
- * Copyright 2000,2009 Free Software Foundation, Inc.
+ * Copyright 2000, 2009, 2010 Free Software Foundation, Inc.
  * ------------------------------------------------------------------------
  *
  * GNU XBoard is free software: you can redistribute it and/or modify
@@ -44,31 +44,12 @@ extern char *getenv();
 # include <unistd.h>
 #endif
 
-#include <X11/Intrinsic.h>
-#include <X11/StringDefs.h>
-#include <X11/Shell.h>
-#include <X11/Xaw/Dialog.h>
-#include <X11/Xaw/Form.h>
-#include <X11/Xaw/List.h>
-#include <X11/Xaw/Label.h>
-#include <X11/Xaw/SimpleMenu.h>
-#include <X11/Xaw/SmeBSB.h>
-#include <X11/Xaw/SmeLine.h>
-#include <X11/Xaw/Box.h>
-#include <X11/Xaw/Paned.h>
-#include <X11/Xaw/MenuButton.h>
-#include <X11/cursorfont.h>
-#include <X11/Xaw/Text.h>
-#include <X11/Xaw/AsciiText.h>
-#include <X11/Xaw/Viewport.h>
-
 #include "common.h"
 #include "frontend.h"
 #include "backend.h"
 #include "xboard.h"
 #include "xhistory.h"
 #include "gettext.h"
-#include "gtk/gtk.h"
 
 #ifdef ENABLE_NLS
 # define  _(s) gettext (s)
@@ -78,50 +59,71 @@ extern char *getenv();
 # define N_(s)  s
 #endif
 
-#define _LL_ 100
-
-extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
-extern Display *xDisplay;
-extern int squareSize;
-extern Pixmap xMarkPixmap;
-extern char *layoutName;
-
 extern GtkWidget               *GUI_History;
 extern GtkListStore            *LIST_MoveHistory;
+extern GtkTreeView             *TREE_History;
 
-
-struct History{
-  String *Nr,*white,*black;
-  int     aNr;  /* space actually alocated */
-  Widget mvn,mvw,mvb,vbox,viewport,sh;
-  char Up;
-};
-
-struct History *hist=0;
 String dots=" ... ";
 Position gameHistoryX, gameHistoryY;
+Dimension gameHistoryW, gameHistoryH;
 
 void
 HistoryPopDown(object, user_data)
      GtkObject *object;
      gpointer user_data;
 {
+  /* hides the history window */
+
   gtk_widget_hide (GUI_History);
   return;
 }
 
-void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data)
+void 
+HistoryMoveProc(window, event, data)
+     GtkWindow *window;
+     GdkEvent *event;
+     gpointer data;
 {
-    int to;
-    XawListReturnStruct *R = (XawListReturnStruct *) call_data;
-    if (w == hist->mvn || w == hist->mvw) {
-      to=2*R->list_index-1;
-      ToNrEvent(to);
-    }
-    else if (w == hist->mvb) {
-      to=2*R->list_index;
-      ToNrEvent(to);
+  int to; /* the move we want to go to */
+  
+  /* check if the mouse was clicked */
+  if(event->type == GDK_BUTTON_PRESS)
+    {  
+      GtkTreeViewColumn *column;
+      GtkTreePath *path;
+      GList *cols;
+      gint *indices;
+      gint row,col;
+      
+      /* can we convert this into an element of the history list? */
+      if(gtk_tree_view_get_path_at_pos(TREE_History,
+                                      (gint)event->button.x, (gint)event->button.y,
+                                      &path,&column,NULL,NULL))
+       {
+         /* find out which row and column the user clicked on */
+         indices = gtk_tree_path_get_indices(path);
+         row     = indices[0];
+         cols    = gtk_tree_view_get_columns(GTK_TREE_VIEW(column->tree_view));
+         col     = g_list_index(cols,(gpointer)column);
+         g_list_free(cols);
+         gtk_tree_path_free(path);
+         
+         printf("DEBUG: row %d col %d\n",row,col);
+
+
+         if(col)
+           {
+             /* user didn't click on the move number */
+
+             to = 2*row + col;
+             printf("DEBUG: going to %d\n",to);fflush(stdout);
+
+             /* set board to that move */
+             ToNrEvent(to);
+           }
+       }
     }
+  return;
 }
 
 
@@ -131,6 +133,12 @@ void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current)
   char movewhite[2*MOVE_LEN],moveblack[2*MOVE_LEN],move[2*MOVE_LEN];
   GtkTreeIter iter;
 
+  /* TODO need to add highlights for current move */
+  /* TODO need to add navigation by keyboard or mouse (double click on move) */
+
+  strcpy(movewhite,"");
+  strcpy(moveblack,"");
+
   /* first clear everything, do we need this? */
   gtk_list_store_clear(LIST_MoveHistory);
 
@@ -170,7 +178,7 @@ void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current)
          /* save move */
          gtk_list_store_append (LIST_MoveHistory, &iter);
          gtk_list_store_set (LIST_MoveHistory, &iter,
-                             0, i,
+                             0, (i/2 +1),
                              1, movewhite,
                              2, moveblack,
                              -1);
@@ -179,38 +187,26 @@ void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current)
          strcpy(moveblack,"");
        };
     }
-  /* check if ther is a white move left */
+
+  /* check if there is a white move left */
   if(movewhite[0])
     {
-      i++;
       strcpy(moveblack,"");
+
       /* save move */
       gtk_list_store_append (LIST_MoveHistory, &iter);
       gtk_list_store_set (LIST_MoveHistory, &iter,
-                         0, i,
+                         0, (i/2 +1),
                          1, movewhite,
                          2, moveblack,
                          -1);
     };
+
+
+  //TODO
+  //  EvalGraphSet( first, last, current, pvInfoList ); // piggy-backed
   
   return;
-  
-  
-  if(current<0){
-    // XawListUnhighlight(hist->mvw);
-    // XawListUnhighlight(hist->mvb);
-  }
-  else if((current%2)==0){
-    // XawListHighlight(hist->mvw, current/2+1);
-    // XawListUnhighlight(hist->mvb);
-  }
-  else{
-    // XawListUnhighlight(hist->mvw);
-    // if(current) XawListHighlight(hist->mvb, current/2+1);
-    // else XawListUnhighlight(hist->mvb);
-  }
-
-return;
 }
 
 void HistoryCreate()
@@ -222,15 +218,30 @@ void HistoryCreate()
              <Key>Right: ForwardProc() \n";
 
     return;
+//    if(wpMoveHistory.width > 0) {
+//      gameHistoryW = wpMoveHistory.width;
+//      gameHistoryH = wpMoveHistory.height;
+//      gameHistoryX = wpMoveHistory.x;
+//      gameHistoryY = wpMoveHistory.y;
+//    }
+//
+//  // [HGM] restore old position
+//  if(gameHistoryW > 0) {
+//  j = 0;
+//    XtSetArg(args[j], XtNx, gameHistoryX);  j++;
+//  XtSetArg(args[j], XtNy, gameHistoryY);  j++;
+//    XtSetArg(args[j], XtNwidth, gameHistoryW);  j++;
+//    XtSetArg(args[j], XtNheight, gameHistoryH);  j++;
+//  XtSetValues(hist->sh, args, j);
+//  }
 }
 
 void
 HistoryPopUp()
 {
-  //  if(!hist) HistoryCreate();
+  /* show history window */
 
   gtk_widget_show (GUI_History);
-  
   return;
 }
 
@@ -240,21 +251,17 @@ HistoryShowProc(object, user_data)
      GtkObject *object;
      gpointer user_data;
 {
-  if (!hist) 
-    {
-      HistoryCreate();
-      HistoryPopUp();
-    } 
-  else if (hist->Up) 
-    {
-      HistoryPopDown(NULL,NULL);
-    } 
-  else 
-    {
-      HistoryPopUp();
-    }
-  ToNrEvent(currentMove);
+  HistoryCreate();
+  HistoryPopUp();
+  //TODO:  ToNrEvent(currentMove);
 
   return;
 }
 
+Boolean
+MoveHistoryIsUp()
+{
+  /* return status of history window */
+  
+  return gtk_widget_get_visible (GUI_History);
+}