cddf04eff7dde87fb7c550f06ba7b63fe666e713
[xboard.git] / xhistory.c
1 /*
2  * New (WinBoard-style) Move history for XBoard
3  *
4  * Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
5  * ------------------------------------------------------------------------
6  *
7  * GNU XBoard is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or (at
10  * your option) any later version.
11  *
12  * GNU XBoard is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see http://www.gnu.org/licenses/. 
19  *
20  * ------------------------------------------------------------------------
21  ** See the file ChangeLog for a revision history.  */
22
23 #include "config.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <gtk/gtk.h>
28
29 #include "common.h"
30 #include "backend.h"
31 #include "xhistory.h"
32 #include "dialogs.h"
33 #include "gettext.h"
34
35 #ifdef ENABLE_NLS
36 # define  _(s) gettext (s)
37 # define N_(s) gettext_noop (s)
38 #else
39 # define  _(s) (s)
40 # define N_(s)  s
41 #endif
42
43 // templates for calls into back-end (= history.c; should be moved to history.h header shared with it!)
44 void FindMoveByCharIndex P(( int char_index ));
45
46 // variables in nhistory.c
47 extern Option historyOptions[];
48
49 // ------------- low-level front-end actions called by MoveHistory back-end -----------------
50
51 void
52 HighlightMove (int from, int to, Boolean highlight)
53 {
54     static int init = 0;
55     static GtkTextIter start, end;
56
57     if(!init) {
58         init = 1;
59         gtk_text_buffer_create_tag(historyOptions[0].handle, "highlight", "background", "yellow", NULL);
60         gtk_text_buffer_create_tag(historyOptions[0].handle, "normal", "background", "white", NULL);
61     }
62     gtk_text_buffer_get_iter_at_offset(historyOptions[0].handle, &start, from);
63     gtk_text_buffer_get_iter_at_offset(historyOptions[0].handle, &end, to);
64     gtk_text_buffer_apply_tag_by_name(historyOptions[0].handle, highlight ? "highlight" : "normal", &start, &end);
65 }
66
67 void
68 ScrollToCurrent (int caretPos)
69 {
70     static GtkTextIter iter;
71     gtk_text_buffer_get_iter_at_offset((GtkTextBuffer *) historyOptions[0].handle, &iter, caretPos);
72     gtk_text_view_scroll_to_iter((GtkTextView *) historyOptions[0].textValue, &iter, 0.0, 0, 0.5, 0.5);
73 }
74
75
76 // ------------------------------ callbacks --------------------------
77
78 char historyTranslations[] =
79 "<Btn3Down>: select-start() \n \
80 <Btn3Up>: extend-end() SelectMove() \n";
81