Add displaying of icons
[xboard.git] / xengineoutput.c
index f03b870..576d58b 100644 (file)
@@ -48,6 +48,8 @@ extern char *getenv();
 # include <unistd.h>
 #endif
 
+#include <gtk/gtk.h>
+
 #include "common.h"
 #include "frontend.h"
 #include "backend.h"
@@ -64,37 +66,23 @@ extern char *getenv();
 # define N_(s)  s
 #endif
 
-// [HGM] pixmaps of some ICONS used in the engine-outut window
-#include "pixmaps/WHITE_14.xpm"
-#include "pixmaps/BLACK_14.xpm"
-#include "pixmaps/CLEAR_14.xpm"
-#include "pixmaps/UNKNOWN_14.xpm"
-#include "pixmaps/THINKING_14.xpm"
-#include "pixmaps/PONDER_14.xpm"
-#include "pixmaps/ANALYZING_14.xpm"
-
+extern Option engoutOptions[]; // must go in header, but which?
 
 /* Module variables */
-#ifdef TODO_GTK
 static int currentPV, highTextStart[2], highTextEnd[2];
-static Pixmap icons[8]; // [HGM] this front-end array translates back-end icon indicator to handle
+#ifdef TODO_GTK
 static Widget memoWidget;
 #endif
+static GdkPixbuf *iconsGTK[8];
+static GtkWidget *outputFieldGTK[2][7]; // [HGM] front-end array to translate output field to window handlestatic void *memoWidget;
 
 static void
-ReadIcon (char *pixData[], int iconNr, Widget w)
+ReadIcon (gchar *svgFilename, int iconNr)
 {
-    int r;
+    char buf[MSG_SIZ];
 
-#ifdef TODO_GTK
-       if ((r=XpmCreatePixmapFromData(xDisplay, XtWindow(w),
-                                      pixData,
-                                      &(icons[iconNr]),
-                                      NULL, NULL /*&attr*/)) != 0) {
-         fprintf(stderr, _("Error %d loading icon image\n"), r);
-         exit(1);
-       }
-#endif
+    snprintf(buf, MSG_SIZ, "%s/%s", SVGDIR, svgFilename);
+    iconsGTK[iconNr] = gdk_pixbuf_new_from_file(buf, NULL);
 }
 
 void
@@ -103,48 +91,41 @@ InitEngineOutput (Option *opt, Option *memo2)
 #ifdef TODO_GTK
        Widget w = opt->handle;
        memoWidget = memo2->handle;
-
-        ReadIcon(WHITE_14,   nColorWhite, w);
-        ReadIcon(BLACK_14,   nColorBlack, w);
-        ReadIcon(UNKNOWN_14, nColorUnknown, w);
-
-        ReadIcon(CLEAR_14,   nClear, w);
-        ReadIcon(PONDER_14,  nPondering, w);
-        ReadIcon(THINK_14,   nThinking, w);
-        ReadIcon(ANALYZE_14, nAnalyzing, w);
 #endif
+    ReadIcon("eo_White.svg", nColorWhite);
+    ReadIcon("eo_Black.svg", nColorBlack);
+    ReadIcon("eo_Unknown.svg", nColorUnknown);
+
+    ReadIcon("eo_Clear.svg", nClear);
+    ReadIcon("eo_Ponder.svg", nPondering);
+    ReadIcon("eo_Thinking.svg", nThinking);
+    ReadIcon("eo_Analyzing.svg", nAnalyzing);
 }
 
 void
 DrawWidgetIcon (Option *opt, int nIcon)
-{   // as we are already in X front-end, so do X-stuff here
-#ifdef TODO_GTK
-    Arg arg;
-    XtSetArg(arg, XtNleftBitmap, (XtArgVal) icons[nIcon]);
-    XtSetValues(opt->handle, &arg, 1);
-#endif
+{   // as we are already in GTK front-end, so do GTK-stuff here
+    if( nIcon != 0 ) gtk_image_set_from_pixbuf(GTK_IMAGE(opt->handle), GDK_PIXBUF(iconsGTK[nIcon]));
 }
 
 void
 InsertIntoMemo (int which, char * text, int where)
 {
-#ifdef TODO_GTK
-       XawTextBlock t;
-       Widget edit;
-
-       /* the backend adds \r\n, which is needed for winboard,
-        * for xboard we delete them again over here */
-       if(t.ptr = strchr(text, '\r')) *t.ptr = ' ';
-
-       t.ptr = text; t.firstPos = 0; t.length = strlen(text); t.format = XawFmt8Bit;
-       edit = XtNameToWidget(shells[EngOutDlg], which ? "*paneB.text" : "*paneA.text");
-       XawTextReplace(edit, where, where, &t);
-       if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting
-           int len = strlen(text);
-           highTextStart[which] += len; highTextEnd[which] += len;
-           XawTextSetSelection( edit, highTextStart[which], highTextEnd[which] );
-       }
-#endif
+    char *p;
+    GtkTextIter start;
+    /* the backend adds \r\n, which is needed for winboard,
+     * for xboard we delete them again over here */
+    if(p = strchr(text, '\r')) *p = ' ';
+
+    GtkTextBuffer *tb = (GtkTextBuffer *) (engoutOptions[which ? 12 : 5].handle);
+//    gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(tb), &start);
+    gtk_text_buffer_get_iter_at_offset(tb, &start, where);
+    gtk_text_buffer_insert(tb, &start, text, -1);
+    if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting
+       int len = strlen(text);
+       highTextStart[which] += len; highTextEnd[which] += len;
+    }
 }
 
 //--------------------------------- PV walking ---------------------------------------
@@ -156,126 +137,13 @@ Shift<Btn3Down>: select-start() extend-end() SelectPV(1) \n \
 Any<Btn3Down>: select-start() extend-end() SelectPV(0) \n \
 <Btn3Up>: StopPV() \n";
 
-void
-SelectPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
-{      // [HGM] pv: translate click to PV line, and load it for display
-#ifdef TODO_GTK
-       String val;
-       int start, end;
-       XawTextPosition index, dummy;
-       int x, y;
-       Arg arg;
-
-       x = event->xmotion.x; y = event->xmotion.y;
-       currentPV = (w != memoWidget);
-       XawTextGetSelectionPos(w, &index, &dummy);
-       XtSetArg(arg, XtNstring, &val);
-       XtGetValues(w, &arg, 1);
-       shiftKey = strcmp(params[0], "0");
-       if(LoadMultiPV(x, y, val, index, &start, &end, currentPV)) {
-           XawTextSetSelection( w, start, end );
-           highTextStart[currentPV] = start; highTextEnd[currentPV] = end;
-       }
-#endif
-}
-
-void
-StopPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
-{      // [HGM] pv: on right-button release, stop displaying PV
-#ifdef TODO_GTK
-        XawTextUnsetSelection( w );
-        highTextStart[currentPV] = highTextEnd[currentPV] = 0;
-        UnLoadPV();
-        XtCallActionProc(w, "beginning-of-file", event, NULL, 0);
-#endif
-}
-
-//------------------------- Ctrl-C copying of memo texts ---------------------------
-
-// Awfull code: first read our own primary selection into selected_fen_position,
-//              and then transfer ownership of this to the clipboard, so that the
-//              copy-position callback can fetch it there when somebody pastes it
-// Worst of all is that I only added it because I did not know how to copy primary:
-// my laptop has no middle button. Ctrl-C might not be needed at all... [HGM]
-
-// cloned from CopyPositionProc. Abuse selected_fen_position to hold selection
-
-#ifdef TODO_GTK
-Boolean SendPositionSelection(Widget w, Atom *selection, Atom *target,
-                Atom *type_return, XtPointer *value_return,
-                unsigned long *length_return, int *format_return); // from xboard.c
-
-static void
-MemoCB (Widget w, XtPointer client_data, Atom *selection,
-       Atom *type, XtPointer value, unsigned long *len, int *format)
-{
-  if (value==NULL || *len==0) return; /* nothing had been selected to copy */
-  selected_fen_position = value;
-  selected_fen_position[*len]='\0'; /* normally this string is terminated, but be safe */
-    XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay),
-                  CurrentTime,
-                  SendPositionSelection,
-                  NULL/* lose_ownership_proc */ ,
-                  NULL/* transfer_done_proc */);
-}
-
-void
-CopyMemoProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
-{
-    if(appData.pasteSelection) return;
-    if (selected_fen_position) free(selected_fen_position);
-    XtGetSelectionValue(menuBarWidget,
-      XA_PRIMARY, XA_STRING,
-      /* (XtSelectionCallbackProc) */ MemoCB,
-      NULL, /* client_data passed to PastePositionCB */
-
-      /* better to use the time field from the event that triggered the
-       * call to this function, but that isn't trivial to get
-       */
-      CurrentTime
-    );
-}
-#endif
-
 //------------------------------- pane switching -----------------------------------
 
 void
 ResizeWindowControls (int mode)
 {   // another hideous kludge: to have only a single pane, we resize the
     // second to 5 pixels (which makes it too small to display anything)
-#ifdef TODO_GTK
-    Widget form1, form2;
-    Arg args[16];
-    int j;
-    Dimension ew_height, tmp;
-    Widget shell = shells[EngOutDlg];
-
-    form1 = XtNameToWidget(shell, "*paneA");
-    form2 = XtNameToWidget(shell, "*paneB");
-
-    j = 0;
-    XtSetArg(args[j], XtNheight, (XtArgVal) &ew_height); j++;
-    XtGetValues(form1, args, j);
-    j = 0;
-    XtSetArg(args[j], XtNheight, (XtArgVal) &tmp); j++;
-    XtGetValues(form2, args, j);
-    ew_height += tmp; // total height
-
-    if(mode==0) {
-       j = 0;
-       XtSetArg(args[j], XtNheight, (XtArgVal) 5); j++;
-       XtSetValues(form2, args, j);
-       j = 0;
-       XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height-5)); j++;
-       XtSetValues(form1, args, j);
-    } else {
-       j = 0;
-       XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
-       XtSetValues(form1, args, j);
-       j = 0;
-       XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
-       XtSetValues(form2, args, j);
-    }
-#endif
+    if(mode) gtk_widget_show(engoutOptions[13].handle);
+    else     gtk_widget_hide(engoutOptions[13].handle);
 }