1 /*
2 * New (WinBoard-style) Move history for XBoard
3 *
4 * Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 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 "frontend.h"
30 #include "backend.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 RefreshMemoContent P((void));
44 void MemoContentUpdated P((void));
45
46 // variables in xoptions.c
47 extern Option historyOptions[];
48
49 // ------------- low-level front-end actions called by MoveHistory back-end -----------------
50
51 void
ClearHistoryMemo()52 ClearHistoryMemo ()
53 {
54 SetWidgetText(&historyOptions[0], "", HistoryDlg);
55 }
56
57 // the bold argument says 0 = normal, 1 = bold typeface
58 // the colorNr argument says 0 = font-default, 1 = gray
59 int
AppendToHistoryMemo(char * text,int bold,int colorNr)60 AppendToHistoryMemo (char * text, int bold, int colorNr)
61 {
62 return AppendText(&historyOptions[0], text); // for now ignore bold & color stuff, as Xaw cannot handle that
63 }
64
65 void
HighlightMove(int from,int to,Boolean highlight)66 HighlightMove (int from, int to, Boolean highlight)
67 {
68 HighlightText (&historyOptions[0], from, to, highlight);
69 }
70
71 char *historyText;
72
73 int
SelectMove(Option * opt,int n,int x,int y,char * text,int index)74 SelectMove (Option *opt, int n, int x, int y, char *text, int index)
75 {
76 if(n != 3 && n != 1) return FALSE; // only on button-1 and 3 press
77 FindMoveByCharIndex( index ); // [HGM] also does the actual moving to it, now
78 return (n == 3); // suppress context menu for button 3, but allow selection with button 1
79 }
80
81 Option historyOptions[] = {
82 { 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 400, NULL, (void*) &historyText, NULL , (char**) &SelectMove, TextBox, "", &appData.historyFont },
83 { 0, NO_OK, 0, NULL, (void*) NULL, "", NULL, EndMark , "" }
84 };
85
86 void
ScrollToCurrent(int caretPos)87 ScrollToCurrent (int caretPos)
88 {
89 ScrollToCursor(&historyOptions[0], caretPos);
90 }
91
92 // ------------ standard entry points into MoveHistory code -----------
93
94 Boolean
MoveHistoryIsUp()95 MoveHistoryIsUp ()
96 {
97 return shellUp[HistoryDlg];
98 }
99
100 Boolean
MoveHistoryDialogExists()101 MoveHistoryDialogExists ()
102 {
103 return DialogExists(HistoryDlg);
104 }
105
106 void
HistoryPopUp()107 HistoryPopUp ()
108 {
109 if(GenericPopUp(historyOptions, _("Move list"), HistoryDlg, BoardWindow, NONMODAL, appData.topLevel))
110 AddHandler(&historyOptions[0], HistoryDlg, 0);
111 MarkMenu("View.MoveHistory", HistoryDlg);
112 }
113
114 void
HistoryShowProc()115 HistoryShowProc ()
116 {
117 if (!shellUp[HistoryDlg]) {
118 ASSIGN(historyText, "");
119 HistoryPopUp();
120 RefreshMemoContent();
121 MemoContentUpdated();
122 } else PopDown(HistoryDlg);
123 ToNrEvent(currentMove);
124 }
125