new developer release
[xboard.git] / xhistory.c
index c220e9a..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
@@ -61,6 +61,7 @@ extern char *getenv();
 
 extern GtkWidget               *GUI_History;
 extern GtkListStore            *LIST_MoveHistory;
+extern GtkTreeView             *TREE_History;
 
 String dots=" ... ";
 Position gameHistoryX, gameHistoryY;
@@ -71,24 +72,58 @@ 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;
 }
 
 
@@ -101,6 +136,9 @@ void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current)
   /* 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);
 
@@ -140,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);
@@ -150,20 +188,21 @@ void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current)
        };
     }
 
-  /* 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
   
@@ -179,123 +218,6 @@ void HistoryCreate()
              <Key>Right: ForwardProc() \n";
 
     return;
-    /*-------- create the widgets ---------------*/
-//<<<<<<< HEAD
-//    j = 0;
-//    XtSetArg(args[j], XtNresizable, True);  j++;
-//    XtSetArg(args[j], XtNallowShellResize, True);  j++;
-//#if TOPLEVEL
-//    hist->sh = historyShell =
-//      XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass,
-//                      shellWidget, args, j);
-//#else
-//    hist->sh = historyShell =
-//      XtCreatePopupShell(_("Move list"), transientShellWidgetClass,
-//                      shellWidget, args, j);
-//#endif
-//    j = 0;
-//    XtSetArg(args[j], XtNborderWidth, 0); j++;
-//    XtSetArg(args[j], XtNdefaultDistance, 0);  j++;
-//      layout =
-//      XtCreateManagedWidget(layoutName, formWidgetClass, hist->sh,
-//                         args, j);
-//
-//    j = 0;
-//    XtSetArg(args[j], XtNborderWidth, 0); j++;
-//    XtSetArg(args[j], XtNresizable, True);  j++;
-//
-//    form =
-//      XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
-//
-//    j = 0;
-//    XtSetArg(args[j], XtNtop, XtChainTop);  j++;
-//    XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
-//    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
-//    XtSetArg(args[j], XtNright, XtChainRight);  j++;
-//
-//    XtSetArg(args[j], XtNborderWidth, 1); j++;
-//    XtSetArg(args[j], XtNresizable, False);  j++;
-//    XtSetArg(args[j], XtNallowVert, True); j++;
-//    XtSetArg(args[j], XtNallowHoriz, True);  j++;
-//    XtSetArg(args[j], XtNforceBars, False); j++;
-//    XtSetArg(args[j], XtNheight, 280); j++;
-//    hist->viewport =
-//      XtCreateManagedWidget("viewport", viewportWidgetClass,
-//                         form, args, j);
-//    j=0;
-//    XtSetArg(args[j], XtNborderWidth, 0); j++;
-//    XtSetArg(args[j], XtNorientation,XtorientHorizontal);j++;
-//    hist->vbox =
-//      XtCreateManagedWidget("vbox", formWidgetClass, hist->viewport, args, j);
-//
-//    j=0;
-//    XtSetArg(args[j], XtNtop, XtChainTop);  j++;
-//    XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
-//    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
-//    XtSetArg(args[j], XtNright, XtChainLeft);  j++;
-//
-//    XtSetArg(args[j], XtNdefaultColumns, 1);  j++;
-//    XtSetArg(args[j], XtNforceColumns, True);  j++;
-//    XtSetArg(args[j], XtNverticalList, True);  j++;
-//    XtSetArg(args[j], XtNborderWidth, 0); j++;
-//    XtSetArg(args[j], XtNresizable,True);j++;
-//    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
-//    hist->mvn = XtCreateManagedWidget("movesn", listWidgetClass,
-//                                   hist->vbox, args, j);
-//    XtAddCallback(hist->mvn, XtNcallback, HistoryMoveProc, (XtPointer) hist);
-//
-//    j=0;
-//    XtSetArg(args[j], XtNtop, XtChainTop);  j++;
-//    XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
-//    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
-//    XtSetArg(args[j], XtNright, XtRubber);  j++;
-//
-//    XtSetArg(args[j], XtNdefaultColumns, 1);  j++;
-//    XtSetArg(args[j], XtNforceColumns, True);  j++;
-//    XtSetArg(args[j], XtNverticalList, True);  j++;
-//    XtSetArg(args[j], XtNborderWidth, 0); j++;
-//    XtSetArg(args[j], XtNresizable,True);j++;
-//    XtSetArg(args[j], XtNfromHoriz, hist->mvn);  j++;
-//    hist->mvw = XtCreateManagedWidget("movesw", listWidgetClass,
-//                                   hist->vbox, args, j);
-//    XtAddCallback(hist->mvw, XtNcallback, HistoryMoveProc, (XtPointer) hist);
-//
-//    j=0;
-//    XtSetArg(args[j], XtNtop, XtChainTop);  j++;
-//    XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
-//    XtSetArg(args[j], XtNleft, XtRubber);  j++;
-//    XtSetArg(args[j], XtNright,  XtRubber);  j++;
-//
-//    XtSetArg(args[j], XtNdefaultColumns, 1);  j++;
-//    XtSetArg(args[j], XtNforceColumns, True);  j++;
-//    XtSetArg(args[j], XtNverticalList, True);  j++;
-//    XtSetArg(args[j], XtNborderWidth, 0); j++;
-//    XtSetArg(args[j], XtNresizable,True);j++;
-//    XtSetArg(args[j], XtNfromHoriz, hist->mvw);  j++;
-//    hist->mvb = XtCreateManagedWidget("movesb", listWidgetClass,
-//                                   hist->vbox, args, j);
-//    XtAddCallback(hist->mvb, XtNcallback, HistoryMoveProc, (XtPointer) hist);
-//
-//    j=0;
-//    XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
-//    XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
-//    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
-//    XtSetArg(args[j], XtNright, XtChainLeft);  j++;
-//    XtSetArg(args[j], XtNfromVert, hist->viewport);  j++;
-//    b_close= XtCreateManagedWidget(_("Close"), commandWidgetClass,
-//                                form, args, j);
-//    XtAddCallback(b_close, XtNcallback, HistoryPopDown, (XtPointer) 0);
-//
-//    XtAugmentTranslations(hist->sh,XtParseTranslationTable (trstr));
-//
-//    XtRealizeWidget(hist->sh);
-//    CatchDeleteWindow(hist->sh, "HistoryPopDown");
-//
-//    for(i=1;i<hist->aNr;i++){
-//      strcpy(hist->white[i],dots);
-//      strcpy(hist->black[i],"");
-//     }
-//
 //    if(wpMoveHistory.width > 0) {
 //      gameHistoryW = wpMoveHistory.width;
 //      gameHistoryH = wpMoveHistory.height;
@@ -312,19 +234,14 @@ void HistoryCreate()
 //    XtSetArg(args[j], XtNheight, gameHistoryH);  j++;
 //  XtSetValues(hist->sh, args, j);
 //  }
-//    XtRealizeWidget(hist->sh);
-//
-//    return hist->sh;
-//
 }
 
 void
 HistoryPopUp()
 {
-  //  if(!hist) HistoryCreate();
+  /* show history window */
 
   gtk_widget_show (GUI_History);
-  
   return;
 }
 
@@ -344,7 +261,7 @@ HistoryShowProc(object, user_data)
 Boolean
 MoveHistoryIsUp()
 {
-  // TODO
-  return 0;
-  //  return hist && hist->Up;
+  /* return status of history window */
+  
+  return gtk_widget_get_visible (GUI_History);
 }