ca2622809bbf3dd94ac5e91bc42fd2504b52a4ae
[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
28 #include "common.h"
29 #include "backend.h"
30 #include "xhistory.h"
31 #include "dialogs.h"
32 #include "gettext.h"
33
34 #ifdef ENABLE_NLS
35 # define  _(s) gettext (s)
36 # define N_(s) gettext_noop (s)
37 #else
38 # define  _(s) (s)
39 # define N_(s)  s
40 #endif
41
42 // templates for calls into back-end (= history.c; should be moved to history.h header shared with it!)
43 void FindMoveByCharIndex P(( int char_index ));
44
45 // variables in nhistory.c
46 extern Option historyOptions[];
47
48 // ------------- low-level front-end actions called by MoveHistory back-end -----------------
49
50 void
51 HighlightMove (int from, int to, Boolean highlight)
52 {
53 #ifdef TODO_GTK
54     if(highlight)
55         XawTextSetSelection( historyOptions[0].handle, from, to ); // for lack of a better method, use selection for highighting
56 #endif
57 }
58
59 void
60 ScrollToCurrent (int caretPos)
61 {
62 #ifdef TODO_GTK
63     Arg args[10];
64     char *s;
65     int len;
66     GetWidgetText(&historyOptions[0], &s);
67     len = strlen(s);
68     if(caretPos < 0 || caretPos > len) caretPos = len;
69     if(caretPos > len-30) { // scroll to end, which causes no flicker
70       static XEvent event;
71       XtCallActionProc(historyOptions[0].handle, "end-of-file", &event, NULL, 0);
72       return;
73     }
74     // the following leads to a very annoying flicker, even when no scrolling is done at all.
75     XtSetArg(args[0], XtNinsertPosition, caretPos); // this triggers scrolling in Xaw
76     XtSetArg(args[1], XtNdisplayCaret, False);
77     XtSetValues(historyOptions[0].handle, args, 2);
78 #endif
79 }
80
81
82 // ------------------------------ callbacks --------------------------
83
84 char historyTranslations[] =
85 "<Btn3Down>: select-start() \n \
86 <Btn3Up>: extend-end() SelectMove() \n";
87
88 void
89 SelectMove (Widget w, XEvent * event, String * params, Cardinal * nParams)
90 {
91 #ifdef TODO_GTK
92         XawTextPosition index, dummy;
93
94         XawTextGetSelectionPos(w, &index, &dummy);
95         FindMoveByCharIndex( index ); // [HGM] also does the actual moving to it, now
96 #endif
97 }
98