Implement highlighting in engine output by through generic method
[xboard.git] / xoptions.c
index f209698..5616840 100644 (file)
@@ -546,6 +546,22 @@ ICSKeyEvent(GtkWidget *widget, GdkEventKey *event)
     }
 }
 
+void
+HighlightText (Option *opt, int from, int to, Boolean highlight)
+{
+#   define INIT 0x8000
+    static GtkTextIter start, end;
+
+    if(!(opt->min & INIT)) {
+       opt->min |= INIT; // each memo its own init flag!
+       gtk_text_buffer_create_tag(opt->handle, "highlight", "background", "yellow", NULL);
+       gtk_text_buffer_create_tag(opt->handle, "normal", "background", "white", NULL);
+    }
+    gtk_text_buffer_get_iter_at_offset(opt->handle, &start, from);
+    gtk_text_buffer_get_iter_at_offset(opt->handle, &end, to);
+    gtk_text_buffer_apply_tag_by_name(opt->handle, highlight ? "highlight" : "normal", &start, &end);
+}
+
 static gboolean
 MemoEvent(GtkWidget *widget, GdkEvent *event, gpointer gdata)
 {   // handle mouse clicks on text widgets that need it
@@ -568,6 +584,7 @@ MemoEvent(GtkWidget *widget, GdkEvent *event, gpointer gdata)
        case GDK_BUTTON_RELEASE:
            f = -1; // release indicated by negative button numbers
            w = bevent->x; h = bevent->y;
+           button = bevent->button;
            break;
        case GDK_BUTTON_PRESS:
            w = bevent->x; h = bevent->y;
@@ -1231,6 +1248,7 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent
                 else
                     gtk_text_buffer_set_text (textbuffer, "", -1); 
                 option[i].handle = (void*)textbuffer;
+                option[i].textValue = (char*)textview;
                if(option[i].choice) { // textviews can request a handler for mouse events in the choice field
                    g_signal_connect(textview, "button-press-event", G_CALLBACK (MemoEvent), (gpointer) &option[i] );
                    g_signal_connect(textview, "button-release-event", G_CALLBACK (MemoEvent), (gpointer) &option[i] );