From f360f5c49d27a95ca64e5755c42156ee1f7e95db Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Wed, 17 Oct 2012 14:40:59 +0200 Subject: [PATCH] Implement highlighting in engine output by through generic method HighlightMove was made generally available for all text. It is now just a wrapper for the generic HighlightText, and could be moved to the back-end. (This requires the initialization to be widget specific, and the flag indicating it has been done is now stored in the Option.min field.) --- dialogs.h | 1 + nengineoutput.c | 6 +++--- nhistory.c | 6 ++++++ xaw/xhistory.c | 7 ------- xaw/xoptions.c | 4 ++++ xengineoutput.c | 3 --- xhistory.c | 16 ---------------- xoptions.c | 16 ++++++++++++++++ 8 files changed, 30 insertions(+), 29 deletions(-) diff --git a/dialogs.h b/dialogs.h index 3032dcc..49df73d 100644 --- a/dialogs.h +++ b/dialogs.h @@ -137,6 +137,7 @@ int GenericReadout P((Option *currentOption, int selected)); int PopDown P((DialogClass n)); void MarkMenu P((char *item, int dlgNr)); int AppendText P((Option *opt, char *s)); +void HighlightText P((Option *opt, int from, int to, Boolean highlight)); void SetColor P((char *colorName, Option *box)); //void ColorChanged P((Widget w, XtPointer data, XEvent *event, Boolean *b)); void SetInsertPos P((Option *opt, int pos)); diff --git a/nengineoutput.c b/nengineoutput.c index dc84aa4..7b013c0 100644 --- a/nengineoutput.c +++ b/nengineoutput.c @@ -104,14 +104,14 @@ MemoProc (Option *opt, int n, int x, int y, char *text, int index) case 3: // press button 3 pressed = 1; if(LoadMultiPV(x, y, text, index, &start, &end, currentPV)) { -#ifdef TODO_GTK - XawTextSetSelection( w, start, end ); -#endif highTextStart[currentPV] = start; highTextEnd[currentPV] = end; + HighlightText(&engoutOptions[currentPV ? 12 : 5], start, end, TRUE); } break; case -3: // release button 3 pressed = 0; + if(highTextStart[currentPV] != highTextEnd[currentPV]) + HighlightText(&engoutOptions[currentPV ? 12 : 5], highTextStart[currentPV], highTextEnd[currentPV], FALSE); highTextStart[currentPV] = highTextEnd[currentPV] = 0; UnLoadPV(); break; diff --git a/nhistory.c b/nhistory.c index cefb706..9d6a073 100644 --- a/nhistory.c +++ b/nhistory.c @@ -62,6 +62,12 @@ AppendToHistoryMemo (char * text, int bold, int colorNr) return AppendText(&historyOptions[0], text); // for now ignore bold & color stuff, as Xaw cannot handle that } +void +HighlightMove (int from, int to, Boolean highlight) +{ + HighlightText (&historyOptions[0], from, to, highlight); +} + char *historyText; int diff --git a/xaw/xhistory.c b/xaw/xhistory.c index 51ebf5c..d46206d 100644 --- a/xaw/xhistory.c +++ b/xaw/xhistory.c @@ -71,13 +71,6 @@ extern Option historyOptions[]; // ------------- low-level front-end actions called by MoveHistory back-end ----------------- -void -HighlightMove (int from, int to, Boolean highlight) -{ - if(highlight) - XawTextSetSelection( historyOptions[0].handle, from, to ); // for lack of a better method, use selection for highighting -} - // the bold argument says 0 = normal, 1 = bold typeface // the colorNr argument says 0 = font-default, 1 = gray void diff --git a/xaw/xoptions.c b/xaw/xoptions.c index 7e622a7..77d7358 100644 --- a/xaw/xoptions.c +++ b/xaw/xoptions.c @@ -267,6 +267,10 @@ SelectedListBoxItem (Option *opt) void HighlightText (Option *opt, int start, int end, Boolean on) { + if(on) + XawTextSetSelection( opt->handle, start, end ); // for lack of a better method, use selection for highighting + else + XawTextSetSelection( opt->handle, 0, 0 ); } void diff --git a/xengineoutput.c b/xengineoutput.c index 1c86de3..4d94616 100644 --- a/xengineoutput.c +++ b/xengineoutput.c @@ -148,9 +148,6 @@ InsertIntoMemo (int which, char * text, int where) if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting int len = strlen(text); highTextStart[which] += len; highTextEnd[which] += len; -#ifdef TODO_GTK - XawTextSetSelection( edit, highTextStart[which], highTextEnd[which] ); -#endif } } diff --git a/xhistory.c b/xhistory.c index cddf04e..0551ce1 100644 --- a/xhistory.c +++ b/xhistory.c @@ -49,22 +49,6 @@ extern Option historyOptions[]; // ------------- low-level front-end actions called by MoveHistory back-end ----------------- void -HighlightMove (int from, int to, Boolean highlight) -{ - static int init = 0; - static GtkTextIter start, end; - - if(!init) { - init = 1; - gtk_text_buffer_create_tag(historyOptions[0].handle, "highlight", "background", "yellow", NULL); - gtk_text_buffer_create_tag(historyOptions[0].handle, "normal", "background", "white", NULL); - } - gtk_text_buffer_get_iter_at_offset(historyOptions[0].handle, &start, from); - gtk_text_buffer_get_iter_at_offset(historyOptions[0].handle, &end, to); - gtk_text_buffer_apply_tag_by_name(historyOptions[0].handle, highlight ? "highlight" : "normal", &start, &end); -} - -void ScrollToCurrent (int caretPos) { static GtkTextIter iter; diff --git a/xoptions.c b/xoptions.c index c213bbc..5616840 100644 --- a/xoptions.c +++ b/xoptions.c @@ -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 -- 1.7.0.4