code cleanup: make function definition confirm to GNU coding style
[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 <X11/Intrinsic.h>
29 #include <X11/StringDefs.h>
30 #include <X11/Shell.h>
31 #include <X11/Xaw/Dialog.h>
32 #include <X11/Xaw/Form.h>
33 #include <X11/Xaw/List.h>
34 #include <X11/Xaw/Label.h>
35 #include <X11/Xaw/SimpleMenu.h>
36 #include <X11/Xaw/SmeBSB.h>
37 #include <X11/Xaw/SmeLine.h>
38 #include <X11/Xaw/Box.h>
39 #include <X11/Xaw/Paned.h>
40 #include <X11/Xaw/MenuButton.h>
41 #include <X11/cursorfont.h>
42 #include <X11/Xaw/Text.h>
43 #include <X11/Xaw/AsciiText.h>
44 #include <X11/Xaw/Viewport.h>
45 #include <X11/Xatom.h>
46 #include <X11/Xmu/Atoms.h>
47
48 #include "common.h"
49 #include "frontend.h"
50 #include "backend.h"
51 #include "xhistory.h"
52 #include "xboard.h"
53 #include "gettext.h"
54
55 #ifdef ENABLE_NLS
56 # define  _(s) gettext (s)
57 # define N_(s) gettext_noop (s)
58 #else
59 # define  _(s) (s)
60 # define N_(s)  s
61 #endif
62
63 // templates for calls into back-end (= history.c; should be moved to history.h header shared with it!)
64 void RefreshMemoContent P((void));
65 void MemoContentUpdated P((void));
66 void FindMoveByCharIndex P(( int char_index ));
67
68 // variables in xoptions.c
69 extern Option historyOptions[];
70
71 // ------------- low-level front-end actions called by MoveHistory back-end -----------------
72
73 void
74 HighlightMove (int from, int to, Boolean highlight)
75 {
76     if(highlight)
77         XawTextSetSelection( historyOptions[0].handle, from, to ); // for lack of a better method, use selection for highighting
78 }
79
80 void
81 ClearHistoryMemo ()
82 {
83     ClearTextWidget(&historyOptions[0]);
84 }
85
86 // the bold argument says 0 = normal, 1 = bold typeface
87 // the colorNr argument says 0 = font-default, 1 = gray
88 int
89 AppendToHistoryMemo (char * text, int bold, int colorNr)
90 {
91     return AppendText(&historyOptions[0], text); // for now ignore bold & color stuff, as Xaw cannot handle that
92 }
93
94 void
95 ScrollToCurrent (int caretPos)
96 {
97     Arg args[10];
98     char *s;
99     int len;
100     GetWidgetText(&historyOptions[0], &s);
101     len = strlen(s);
102     if(caretPos < 0 || caretPos > len) caretPos = len;
103     if(caretPos > len-30) { // scroll to end, which causes no flicker
104       static XEvent event;
105       XtCallActionProc(historyOptions[0].handle, "end-of-file", &event, NULL, 0);
106       return;
107     }
108     // the following leads to a very annoying flicker, even when no scrolling is done at all.
109     XtSetArg(args[0], XtNinsertPosition, caretPos); // this triggers scrolling in Xaw
110     XtSetArg(args[1], XtNdisplayCaret, False);
111     XtSetValues(historyOptions[0].handle, args, 2);
112 }
113
114
115 // ------------------------------ callbacks --------------------------
116
117 char *historyText;
118 char historyTranslations[] =
119 "<Btn3Down>: select-start() \n \
120 <Btn3Up>: extend-end() SelectMove() \n";
121
122 void
123 SelectMove (Widget w, XEvent * event, String * params, Cardinal * nParams)
124 {
125         XawTextPosition index, dummy;
126
127         XawTextGetSelectionPos(w, &index, &dummy);
128         FindMoveByCharIndex( index ); // [HGM] also does the actual moving to it, now
129 }
130
131 Option historyOptions[] = {
132 { 0xD, 200, 400, NULL, (void*) &historyText, "", NULL, TextBox, "" },
133 {   0,  2,    0, NULL, (void*) NULL, "", NULL, EndMark , "" }
134 };
135
136 // ------------ standard entry points into MoveHistory code -----------
137
138 Boolean
139 MoveHistoryIsUp ()
140 {
141     return shellUp[7];
142 }
143
144 Boolean
145 MoveHistoryDialogExists ()
146 {
147     return shells[7] != NULL;
148 }
149
150 void
151 HistoryPopUp ()
152 {
153     if(GenericPopUp(historyOptions, _("Move list"), 7))
154         XtOverrideTranslations(historyOptions[0].handle, XtParseTranslationTable(historyTranslations));
155     MarkMenu("menuView.Show Move History", 7);
156 }
157
158 void
159 HistoryShowProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
160 {
161   if (!shellUp[7]) {
162     ASSIGN(historyText, "");
163     HistoryPopUp();
164     RefreshMemoContent();
165     MemoContentUpdated();
166   } else PopDown(7);
167   ToNrEvent(currentMove);
168 }