first draft of a MoveHistory window
authorArun Persaud <arun@nubati.net>
Sat, 3 Oct 2009 22:20:05 +0000 (15:20 -0700)
committerArun Persaud <arun@nubati.net>
Sat, 3 Oct 2009 22:30:38 +0000 (15:30 -0700)
still need to add signals to the list, so that you can click on a move.
also still need to make sure that "..." is displayed at the correct time.

backend.c
callback.c
callback.h
gtk-interface.xml
interface.h
xboard.c
xhistory.c
xhistory.h

index 7d22cd3..7e49a3e 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -8900,64 +8900,83 @@ LoadGame(f, gameNumber, title, useList)
        SetTrainingModeOff();
 
     oldGameMode = gameMode;
-    if (gameMode != BeginningOfGame) {
-      Reset(FALSE, TRUE);
-    }
+    if (gameMode != BeginningOfGame) 
+      {
+       Reset(FALSE, TRUE);
+      };
 
     gameFileFP = f;
-    if (lastLoadGameFP != NULL && lastLoadGameFP != f) {
+    if (lastLoadGameFP != NULL && lastLoadGameFP != f) 
+      {
        fclose(lastLoadGameFP);
-    }
+      };
 
-    if (useList) {
+    if (useList) 
+      {
        lg = (ListGame *) ListElem(&gameList, gameNumber-1);
-
-       if (lg) {
+       
+       if (lg) 
+         {
            fseek(f, lg->offset, 0);
            GameListHighlight(gameNumber);
            gn = 1;
-       }
-       else {
+         }
+       else 
+         {
            DisplayError(_("Game number out of range"), 0);
            return FALSE;
-       }
-    } else {
+         };
+      } 
+    else 
+      {
        GameListDestroy();
-       if (fseek(f, 0, 0) == -1) {
+       if (fseek(f, 0, 0) == -1) 
+         {
            if (f == lastLoadGameFP ?
                gameNumber == lastLoadGameNumber + 1 :
-               gameNumber == 1) {
+               gameNumber == 1) 
+             {
                gn = 1;
-           } else {
+             } 
+           else 
+             {
                DisplayError(_("Can't seek on game file"), 0);
                return FALSE;
-           }
-       }
-    }
-    lastLoadGameFP = f;
-    lastLoadGameNumber = gameNumber;
+             };
+         };
+      };
+
+    lastLoadGameFP     = f;
+    lastLoadGameNumber = gameNumber;
     strcpy(lastLoadGameTitle, title);
     lastLoadGameUseList = useList;
 
     yynewfile(f);
 
-    if (lg && lg->gameInfo.white && lg->gameInfo.black) {
-      snprintf(buf, sizeof(buf), "%s vs. %s", lg->gameInfo.white,
-               lg->gameInfo.black);
-           DisplayTitle(buf);
-    } else if (*title != NULLCHAR) {
-       if (gameNumber > 1) {
+    if (lg && lg->gameInfo.white && lg->gameInfo.black) 
+      {
+       snprintf(buf, sizeof(buf), "%s vs. %s", lg->gameInfo.white,
+                lg->gameInfo.black);
+       DisplayTitle(buf);
+      } 
+    else if (*title != NULLCHAR) 
+      {
+       if (gameNumber > 1) 
+         {
            sprintf(buf, "%s %d", title, gameNumber);
            DisplayTitle(buf);
-       } else {
+         } 
+       else 
+         {
            DisplayTitle(title);
-       }
-    }
+         };
+      };
 
-    if (gameMode != AnalyzeFile && gameMode != AnalyzeMode) {
+    if (gameMode != AnalyzeFile && gameMode != AnalyzeMode) 
+      {
        gameMode = PlayFromGameFile;
        ModeHighlight();
-    }
+      };
 
     currentMove = forwardMostMove = backwardMostMove = 0;
     CopyBoard(boards[0], initialPosition);
index 4bc9210..23f27e8 100644 (file)
@@ -349,7 +349,6 @@ void FlipViewProc(object, user_data)
      GtkObject *object;
      gpointer user_data;
 {
-  printf("DEBUG: in flip view\n");
     flipView = !flipView;
     DrawPosition(True, NULL);
     return;
@@ -441,16 +440,22 @@ void LoadGameProc(object, user_data)
 
       //see loadgamepopup
       f = fopen(filename, "rb");
-      if (f == NULL) {
-       DisplayError(_("Failed to open file"), errno);
-      } else {
-       /* TODO add indec */
-       (void) LoadGamePopUp(f, 0, filename);
-      }
+      if (f == NULL) 
+       {
+         DisplayError(_("Failed to open file"), errno);
+       }
+      else 
+       {
+         /* TODO add indec */
+         (void) LoadGamePopUp(f, 0, filename);
+       }
       g_free (filename);
-    }
+    };
+  
   gtk_widget_destroy (dialog);
   ModeHighlight();
+  
+  return;
 }
 
 
@@ -662,3 +667,19 @@ void UserMoveProc(window, event, data)
     return;
 }
 
+void GetMoveListProc(object, user_data)
+     GtkObject *object;
+     gpointer user_data;
+{
+  appData.getMoveList = !appData.getMoveList;
+  
+  if (appData.getMoveList) 
+    {
+      GetMoveListEvent();
+    } 
+
+  // gets set automatically? if we set it with set_active we end up in an endless loop switching between 0 and 1
+  //  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (object),(gboolean) appData.getMoveList );
+  
+  return;
+}
index 16d5c36..15b9222 100644 (file)
@@ -32,6 +32,7 @@ void RetractMoveProc P((GtkObject *object, gpointer user_data));
 
 /* Option Menu */
 void FlipViewProc P((GtkObject *object, gpointer user_data));
+void GetMoveListProc P((GtkObject *object, gpointer user_data));
 
 /* Help Menu */
 
index d7d22f6..8805dc3 100644 (file)
                             <property name="visible">True</property>
                             <property name="label" translatable="yes">Show Move List</property>
                             <property name="use_underline">True</property>
+                            <signal name="activate" handler="HistoryShowProc"/>
                           </object>
                         </child>
                         <child>
                             <property name="visible">True</property>
                             <property name="label" translatable="yes">Get Move List</property>
                             <property name="use_underline">True</property>
+                            <signal name="toggled" handler="GetMoveListProc"/>
                           </object>
                         </child>
                         <child>
     <property name="xalign">0.40000000596046448</property>
     <property name="stock">gtk-open</property>
   </object>
+  <object class="GtkListStore" id="MoveHistoryStore">
+    <columns>
+      <!-- column-name Move -->
+      <column type="gint"/>
+      <!-- column-name White -->
+      <column type="gchararray"/>
+      <!-- column-name Black -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <object class="GtkDialog" id="MoveHistory">
+    <property name="border_width">5</property>
+    <property name="type_hint">normal</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkTreeView" id="MoveHistoryView">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="model">MoveHistoryStore</property>
+            <property name="headers_clickable">False</property>
+            <property name="enable_search">False</property>
+            <property name="search_column">0</property>
+            <child>
+              <object class="GtkTreeViewColumn" id="Move">
+                <property name="title">Move</property>
+                <child>
+                  <object class="GtkCellRendererText" id="cellrenderertext1"/>
+                  <attributes>
+                    <attribute name="text">0</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkTreeViewColumn" id="White">
+                <property name="title">White</property>
+                <child>
+                  <object class="GtkCellRendererText" id="cellrenderertext2"/>
+                  <attributes>
+                    <attribute name="text">1</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkTreeViewColumn" id="Black">
+                <property name="title">Black</property>
+                <child>
+                  <object class="GtkCellRendererText" id="cellrenderertext3"/>
+                  <attributes>
+                    <attribute name="text">2</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="CloseButton">
+                <property name="label" translatable="yes">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+                <signal name="released" handler="HistoryPopDown"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">CloseButton</action-widget>
+    </action-widgets>
+  </object>
 </interface>
index cd0415a..0a91d81 100644 (file)
@@ -2,11 +2,14 @@
 GtkBuilder              *builder=NULL;
 
 GtkWidget               *GUI_Window=NULL;
+GtkWidget               *GUI_History=NULL;
 GtkWidget               *GUI_Board=NULL;
 GtkWidget               *GUI_Whiteclock=NULL;
 GtkWidget               *GUI_Blackclock=NULL;
 GtkWidget               *GUI_Error=NULL;
 
+GtkListStore            *LIST_MoveHistory=NULL;
+
 gint                     boardWidth;
 gint                     boardHeight;
 
index 424e2d2..0444e8e 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -343,8 +343,6 @@ void AutosaveProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
 void BlindfoldProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
 void FlashMovesProc P((Widget w, XEvent *event, String *prms,
                       Cardinal *nprms));
-void GetMoveListProc P((Widget w, XEvent *event, String *prms,
-                       Cardinal *nprms));
 void HighlightDraggingProc P((Widget w, XEvent *event, String *prms,
                              Cardinal *nprms));
 void HighlightLastMoveProc P((Widget w, XEvent *event, String *prms,
@@ -691,7 +689,7 @@ MenuItem modeMenu[] = {
     {N_("Show Engine Output"), EngineOutputProc},
     {N_("Show Evaluation Graph"), NothingProc}, // [HGM] evalgr: not functional yet
     {N_("Show Game List"), ShowGameListProc},
-    {"Show Move History", HistoryShowProc}, // [HGM] hist: activate 4.2.7 code
+    //    {"Show Move History", HistoryShowProc}, // [HGM] hist: activate 4.2.7 code
     {"----", NothingProc},
     {N_("Edit Tags"), EditTagsProc},
     {N_("Edit Comment"), EditCommentProc},
@@ -719,7 +717,7 @@ MenuItem optionsMenu[] = {
     {N_("Auto Save"), AutosaveProc},
     {N_("Blindfold"), BlindfoldProc},
     {N_("Flash Moves"), FlashMovesProc},
-    {N_("Get Move List"), GetMoveListProc},
+ //    {N_("Get Move List"), GetMoveListProc},
 #if HIGHDRAG
     {N_("Highlight Dragging"), HighlightDraggingProc},
 #endif
@@ -1837,7 +1835,7 @@ XtActionsRec boardActions[] = {
     { "TrainingProc", EditPositionProc },
     { "EngineOutputProc", EngineOutputProc}, // [HGM] Winboard_x engine-output window
     { "ShowGameListProc", ShowGameListProc },
-    { "ShowMoveListProc", HistoryShowProc},
+    //    { "ShowMoveListProc", HistoryShowProc},
     { "EditTagsProc", EditCommentProc },
     { "EditCommentProc", EditCommentProc },
     { "IcsAlarmProc", IcsAlarmProc },
@@ -1875,7 +1873,7 @@ XtActionsRec boardActions[] = {
     { "BlindfoldProc", BlindfoldProc },
     { "FlashMovesProc", FlashMovesProc },
     //    { "FlipViewProc", FlipViewProc },
-    { "GetMoveListProc", GetMoveListProc },
+    //    { "GetMoveListProc", GetMoveListProc },
 #if HIGHDRAG
     { "HighlightDraggingProc", HighlightDraggingProc },
 #endif
@@ -1909,7 +1907,7 @@ XtActionsRec boardActions[] = {
     { "AskQuestionPopDown", (XtActionProc) AskQuestionPopDown },
     { "GameListPopDown", (XtActionProc) GameListPopDown },
     { "PromotionPopDown", (XtActionProc) PromotionPopDown },
-    { "HistoryPopDown", (XtActionProc) HistoryPopDown },
+    //    { "HistoryPopDown", (XtActionProc) HistoryPopDown },
     { "EngineOutputPopDown", (XtActionProc) EngineOutputPopDown },
     { "ShufflePopDown", (XtActionProc) ShufflePopDown },
     { "EnginePopDown", (XtActionProc) EnginePopDown },
@@ -2187,11 +2185,6 @@ main(argc, argv)
     argvCopy[j] = NULL;
     argv = argvCopy;
     argc = j;
-#if 0
-    if(appData.debugMode,1) { // OK, appData is not initialized here yet...
-       for(i=0; i<argc; i++) fprintf(stderr, "argv[%2d] = '%s'\n", i, argv[i]);
-    }
-#endif
 #endif
 
     setbuf(stdout, NULL);
@@ -2228,13 +2221,23 @@ main(argc, argv)
 
     GUI_Window = GTK_WIDGET (gtk_builder_get_object (builder, "MainWindow"));
     if(!GUI_Window) printf("Error: gtk_builder didn't work!\n");
+
+    GUI_History = GTK_WIDGET (gtk_builder_get_object (builder, "MoveHistory"));
+    if(!GUI_History) printf("Error: gtk_builder didn't work!\n");
+
     GUI_Board  = GTK_WIDGET (gtk_builder_get_object (builder, "Board"));
     if(!GUI_Board) printf("Error: gtk_builder didn't work!\n");
+
     GUI_Whiteclock  = GTK_WIDGET (gtk_builder_get_object (builder, "WhiteClock"));
     if(!GUI_Whiteclock) printf("Error: gtk_builder didn't work!\n");
+
     GUI_Blackclock  = GTK_WIDGET (gtk_builder_get_object (builder, "BlackClock"));
     if(!GUI_Blackclock) printf("Error: gtk_builder didn't work!\n");
 
+    LIST_MoveHistory = GTK_LIST_STORE (gtk_builder_get_object (builder, "MoveHistoryStore"));
+    if(!LIST_MoveHistory) printf("Error: gtk_builder didn't work!\n");
+
+
     gtk_builder_connect_signals (builder, NULL);
 
     // don't unref the builder, since we use it to get references to widgets
@@ -5198,18 +5201,26 @@ int LoadGamePopUp(f, gameNumber, title)
      char *title;
 {
     cmailMsgLoaded = FALSE;
-    if (gameNumber == 0) {
+
+    if (gameNumber == 0) 
+      {
        int error = GameListBuild(f);
-       if (error) {
+
+       if (error) 
+         {
            DisplayError(_("Cannot build game list"), error);
-       } else if (!ListEmpty(&gameList) &&
-                  ((ListGame *) gameList.tailPred)->number > 1) {
+         } 
+       else if (!ListEmpty(&gameList) 
+                && ((ListGame *) gameList.tailPred)->number > 1) 
+         {
            GameListPopUp(f, title);
            return TRUE;
-       }
+         };
+
        GameListDestroy();
        gameNumber = 1;
-    }
+      };
+
     return LoadGame(f, gameNumber, title, FALSE);
 }
 
@@ -5845,26 +5856,6 @@ void FlashMovesProc(w, event, prms, nprms)
                args, 1);
 }
 
-void GetMoveListProc(w, event, prms, nprms)
-     Widget w;
-     XEvent *event;
-     String *prms;
-     Cardinal *nprms;
-{
-    Arg args[16];
-
-    appData.getMoveList = !appData.getMoveList;
-
-    if (appData.getMoveList) {
-       XtSetArg(args[0], XtNleftBitmap, xMarkPixmap);
-       GetMoveListEvent();
-    } else {
-       XtSetArg(args[0], XtNleftBitmap, None);
-    }
-    XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Get Move List"),
-               args, 1);
-}
-
 #if HIGHDRAG
 void HighlightDraggingProc(w, event, prms, nprms)
      Widget w;
index 02c9ec3..a08dcc8 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "config.h"
 
+#include <gtk/gtk.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <errno.h>
@@ -67,6 +68,7 @@ extern char *getenv();
 #include "xboard.h"
 #include "xhistory.h"
 #include "gettext.h"
+#include "gtk/gtk.h"
 
 #ifdef ENABLE_NLS
 # define  _(s) gettext (s)
@@ -84,6 +86,10 @@ extern int squareSize;
 extern Pixmap xMarkPixmap;
 extern char *layoutName;
 
+extern GtkWidget               *GUI_History;
+extern GtkListStore            *LIST_MoveHistory;
+
+
 struct History{
   String *Nr,*white,*black;
   int     aNr;  /* space actually alocated */
@@ -96,26 +102,12 @@ String dots=" ... ";
 Position gameHistoryX, gameHistoryY;
 
 void
-HistoryPopDown(w, client_data, call_data)
-     Widget w;
-     XtPointer client_data, call_data;
+HistoryPopDown(object, user_data)
+     GtkObject *object;
+     gpointer user_data;
 {
-  Arg args[16];
-  int j;
-  if(hist) {
-    // [HGM] remember old position
-    j = 0;
-    XtSetArg(args[j], XtNx, &gameHistoryX);  j++;
-    XtSetArg(args[j], XtNy, &gameHistoryY);  j++;
-    XtGetValues(hist->sh, args, j);
-
-    XtPopdown(hist->sh);
-    hist->Up=False;
-  }
-  j=0;
-  XtSetArg(args[j], XtNleftBitmap, None); j++;
-  XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"),
-               args, j);
+  gtk_widget_hide (GUI_History);
+  return;
 }
 
 void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data)
@@ -132,370 +124,134 @@ void HistoryMoveProc(Widget w, XtPointer closure, XtPointer call_data)
     }
 }
 
-void HistoryAlloc(int len){
-  int i;
-  if(hist){
-    free(hist->Nr[0]);free(hist->white[0]);free(hist->black[0]);
-    free(hist->Nr);free(hist->white);free(hist->black);
-  }
-  else{
-    hist=(struct History*)malloc(sizeof(struct History));
-  }
-    hist->aNr=len;
-    hist->Nr=(String*)malloc(hist->aNr*sizeof(String*));
-    hist->white=(String*)malloc(hist->aNr*sizeof(String*));
-    hist->black=(String*)malloc(hist->aNr*sizeof(String*));
 
-    hist->Nr[0]=(String)malloc(hist->aNr*6);
-    hist->white[0]=(String)malloc(hist->aNr*MOVE_LEN);
-    hist->black[0]=(String)malloc(hist->aNr*MOVE_LEN);
-
-      sprintf(hist->Nr[0],"    ");
-      sprintf(hist->white[0],_("White "));
-      sprintf(hist->black[0],_("Black "));
-    for(i=1;i<hist->aNr;i++){
-      hist->Nr[i]= hist->Nr[i-1]+6;
-      hist->white[i]= hist->white[i-1]+MOVE_LEN;
-      hist->black[i]= hist->black[i-1]+MOVE_LEN;
-      sprintf(hist->Nr[i],"%i.",i);
-      sprintf(hist->white[i],"-----");
-      sprintf(hist->black[i],"-----");
-     }
-}
-
-
-#if 1
-/* Find empty space inside vbox form widget and redistribute it amongst
-   the list widgets inside it. */
-/* This version sort of works */
-void
-HistoryFill()
+void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current)
 {
-  Dimension w, bw;
-  long extra;
-  Position x, x1, x2;
-  int j, dd;
-  Arg args[16];
-
-  j = 0;
-  XtSetArg(args[j], XtNx, &x);  j++;
-  XtSetArg(args[j], XtNwidth, &w);  j++;
-  XtSetArg(args[j], XtNborderWidth, &bw);  j++;
-  XtGetValues(hist->mvb, args, j);
-  x1 = x + w + 2*bw;
-
-  j = 0;
-  XtSetArg(args[j], XtNwidth, &w);  j++;
-  XtSetArg(args[j], XtNdefaultDistance, &dd);  j++;
-  XtGetValues(hist->vbox, args, j);
-  x2 = w - dd;
-
-  extra = x2 - x1;
-  if (extra < 0) {
-    extra = -((-extra)/2);
-  } else {
-    extra = extra/2;
-  }
-
-  j = 0;
-  XtSetArg(args[j], XtNwidth, &w);  j++;
-  XtGetValues(hist->mvw, args, j);
-  w += extra;
-  j = 0;
-  XtSetArg(args[j], XtNwidth, w);  j++;
-  XtSetValues(hist->mvw, args, j);
-
-  j = 0;
-  XtSetArg(args[j], XtNwidth, &w);  j++;
-  XtGetValues(hist->mvb, args, j);
-  w += extra;
-  j = 0;
-  XtSetArg(args[j], XtNwidth, w);  j++;
-  XtSetValues(hist->mvb, args, j);
-}
-#else
-/* Find empty space inside vbox form widget and redistribute it amongst
-   the list widgets inside it. */
-/* This version doesn't work */
-void
-HistoryFill()
-{
-  Arg args[16];
-  Dimension fw, niw, wiw, biw, nbw, wbw, bbw;
-  int j, nl, wl, bl, fdd;
-  long extra;
-
-  j = 0;
-  XtSetArg(args[j], XtNwidth, &fw);  j++;
-  XtSetArg(args[j], XtNdefaultDistance, &fdd);  j++;
-  XtGetValues(hist->vbox, args, j);
-
-  j = 0;
-  XtSetArg(args[j], XtNlongest, &nl);  j++;
-  XtSetArg(args[j], XtNinternalWidth, &niw);  j++;
-  XtSetArg(args[j], XtNborderWidth, &nbw);  j++;
-  XtGetValues(hist->mvn, args, j);
-
-  j = 0;
-  XtSetArg(args[j], XtNlongest, &wl);  j++;
-  XtSetArg(args[j], XtNinternalWidth, &wiw);  j++;
-  XtSetArg(args[j], XtNborderWidth, &wbw);  j++;
-  XtGetValues(hist->mvw, args, j);
-
-  j = 0;
-  XtSetArg(args[j], XtNlongest, &bl);  j++;
-  XtSetArg(args[j], XtNinternalWidth, &biw);  j++;
-  XtSetArg(args[j], XtNborderWidth, &bbw);  j++;
-  XtGetValues(hist->mvb, args, j);
-
-  extra = fw - 4*fdd -
-    nl - 1 - 2*niw - 2*nbw - wl - 2*wiw - 2*wbw - bl - 2*biw - 2*bbw;
-  if (extra < 0) extra = 0;
-
-  j = 0;
-  XtSetArg(args[j], XtNwidth, nl + 1 + 2*niw);  j++;
-  XtSetValues(hist->mvn, args, j);
-
-  j = 0;
-  XtSetArg(args[j], XtNwidth, wl + 2*wiw + extra/2);  j++;
-  XtSetValues(hist->mvw, args, j);
-
-  j = 0;
-  XtSetArg(args[j], XtNwidth, bl + 2*biw + extra/2);  j++;
-  XtSetValues(hist->mvb, args, j);
-}
-#endif
-
-void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
   int i,b,m;
-  if(hist){
-    if(last >= hist->aNr) HistoryAlloc(last+_LL_);
-    for(i=0;i<last;i++) {
-      if((i%2)==0) {
-       if(movelist[i][0]) {
+  char movewhite[2*MOVE_LEN],moveblack[2*MOVE_LEN],move[2*MOVE_LEN];
+  GtkTreeIter iter;
+
+  /* copy move list into history window */
+
+  /* go through all moves */
+  for(i=0;i<last;i++) 
+    {
+      /* test if there is a move */
+      if(movelist[i][0]) 
+       {
+         /* only copy everything before a  ' ' */
          char* p = strchr(movelist[i], ' ');
-         if (p) {
-           strncpy(hist->white[i/2+1], movelist[i], p-movelist[i]);
-           hist->white[i/2+1][p-movelist[i]] = NULLCHAR;
-         } else {
-           strcpy(hist->white[i/2+1],movelist[i]);
-         }
-       } else {
-         strcpy(hist->white[i/2+1],dots);
-       }
-      } else {
-       if(movelist[i][0]) {
-         char* p = strchr(movelist[i], ' ');
-         if (p) {
-           strncpy(hist->black[i/2+1], movelist[i], p-movelist[i]);
-           hist->black[i/2+1][p-movelist[i]] = NULLCHAR;
-         } else {
-           strcpy(hist->black[i/2+1],movelist[i]);
-         }
-       } else {
-         strcpy(hist->black[i/2+1],"");
-       }
-      }
-    }
-    strcpy(hist->black[last/2+1],"");
-    b=first/2;
-    m=(last+3)/2-b;
-    XawFormDoLayout(hist->vbox, False);
-    XawListChange(hist->mvn,hist->Nr+b,m,0,True);
-    XawListChange(hist->mvw,hist->white+b,m,0,True);
-    XawListChange(hist->mvb,hist->black+b,m,0,True);
-    HistoryFill();
-    XawFormDoLayout(hist->vbox, True);
-    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);
+         if (p) 
+           {
+             strncpy(move, movelist[i], p-movelist[i]);
+             move[p-movelist[i]] = NULLCHAR;
+           } 
+         else 
+           {
+             strcpy(move,movelist[i]);
+           }
+       } 
+      else
+       strcpy(move,dots);
+      
+      if((i%2)==0) 
+       {
+         /* white move */
+         strcpy(movewhite,move);
+       }
+      else
+       {
+         /* black move */
+         strcpy(moveblack,move);
+
+         /* save move */
+         gtk_list_store_append (LIST_MoveHistory, &iter);
+         gtk_list_store_set (LIST_MoveHistory, &iter,
+                             0, i,
+                             1, movewhite,
+                             2, moveblack,
+                             -1);
+
+         strcpy(movewhite,"");
+         strcpy(moveblack,"");
+       };
     }
+  /* check if ther 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,
+                         1, movewhite,
+                         2, moveblack,
+                         -1);
+    };
+  
+  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;
 }
 
-Widget HistoryCreate()
+void HistoryCreate()
 {
-    Arg args[16];
-    int i,j;
-
-    Widget layout,form,b_close;
     String trstr=
              "<Key>Up: BackwardProc() \n \
              <Key>Left: BackwardProc() \n \
              <Key>Down: ForwardProc() \n \
              <Key>Right: ForwardProc() \n";
-    /*--- allocate memory for move-strings ---*/
-    HistoryAlloc(_LL_);
-
-    /*-------- create the widgets ---------------*/
-    j = 0;
-    XtSetArg(args[j], XtNresizable, True);  j++;
-    XtSetArg(args[j], XtNallowShellResize, True);  j++;
-#if TOPLEVEL
-    hist->sh =
-      XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass,
-                        shellWidget, args, j);
-#else
-    hist->sh =
-      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;
-
-    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],"");
-     }
-
-    return hist->sh;
+    return;
 }
 
 void
 HistoryPopUp()
 {
-  Arg args[16];
-  int j;
-
-  if(!hist) HistoryCreate();
-
-  XtPopup(hist->sh, XtGrabNone);
+  //  if(!hist) HistoryCreate();
 
-  // [HGM] restore old position
-  j = 0;
-  XtSetArg(args[j], XtNx, gameHistoryX);  j++;
-  XtSetArg(args[j], XtNy, gameHistoryY);  j++;
-  XtSetValues(hist->sh, args, j);
-
-  j=0;
-  XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
-  XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"),
-               args, j);
-  hist->Up=True;
+  gtk_widget_show (GUI_History);
+  
+  return;
 }
 
 
 void
-HistoryShowProc(w, event, prms, nprms)
-     Widget w;
-     XEvent *event;
-     String *prms;
-     Cardinal *nprms;
+HistoryShowProc(object, user_data)
+     GtkObject *object;
+     gpointer user_data;
 {
-  if (!hist) {
-    HistoryCreate();
-    HistoryPopUp();
-  } else if (hist->Up) {
-    HistoryPopDown(0,0,0);
-  } else {
-    HistoryPopUp();
-  }
+  if (!hist) 
+    {
+      HistoryCreate();
+      HistoryPopUp();
+    } 
+  else if (hist->Up) 
+    {
+      HistoryPopDown(NULL,NULL);
+    } 
+  else 
+    {
+      HistoryPopUp();
+    }
   ToNrEvent(currentMove);
+
+  return;
 }
 
index 427cd7d..8e8c5d7 100644 (file)
 #ifndef _XHISTL_H
 #define _XHISTL_H 1
 
-void HistoryShowProc P((Widget w, XEvent *event,
-                       String *prms, Cardinal *nprms));
-void HistoryPopDown P((Widget w, XtPointer client_data,
-                      XtPointer call_data));
+void HistoryShowProc  P((GtkObject *object, gpointer user_data));
+
+void HistoryPopDown   P((GtkObject *object, gpointer user_data));
 
 #endif /* _XHISTL_H */