-
Notifications
You must be signed in to change notification settings - Fork 5
/
nhistory.c
124 lines (105 loc) · 3.38 KB
/
nhistory.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* New (WinBoard-style) Move history for XBoard
*
* Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free Software Foundation, Inc.
* ------------------------------------------------------------------------
*
* GNU XBoard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* GNU XBoard is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
* ------------------------------------------------------------------------
** See the file ChangeLog for a revision history. */
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
#include "frontend.h"
#include "backend.h"
#include "dialogs.h"
#include "gettext.h"
#ifdef ENABLE_NLS
# define _(s) gettext (s)
# define N_(s) gettext_noop (s)
#else
# define _(s) (s)
# define N_(s) s
#endif
// templates for calls into back-end (= history.c; should be moved to history.h header shared with it!)
void RefreshMemoContent P((void));
void MemoContentUpdated P((void));
// variables in xoptions.c
extern Option historyOptions[];
// ------------- low-level front-end actions called by MoveHistory back-end -----------------
void
ClearHistoryMemo ()
{
SetWidgetText(&historyOptions[0], "", HistoryDlg);
}
// the bold argument says 0 = normal, 1 = bold typeface
// the colorNr argument says 0 = font-default, 1 = gray
int
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
SelectMove (Option *opt, int n, int x, int y, char *text, int index)
{
if(n != 3 && n != 1) return FALSE; // only on button-1 and 3 press
FindMoveByCharIndex( index ); // [HGM] also does the actual moving to it, now
return (n == 3); // suppress context menu for button 3, but allow selection with button 1
}
Option historyOptions[] = {
{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 400, NULL, (void*) &historyText, NULL , (char**) &SelectMove, TextBox, "", &appData.historyFont },
{ 0, NO_OK, 0, NULL, (void*) NULL, "", NULL, EndMark , "" }
};
void
ScrollToCurrent (int caretPos)
{
ScrollToCursor(&historyOptions[0], caretPos);
}
// ------------ standard entry points into MoveHistory code -----------
Boolean
MoveHistoryIsUp ()
{
return shellUp[HistoryDlg];
}
Boolean
MoveHistoryDialogExists ()
{
return DialogExists(HistoryDlg);
}
void
HistoryPopUp ()
{
if(GenericPopUp(historyOptions, _("Move list"), HistoryDlg, BoardWindow, NONMODAL, appData.topLevel))
AddHandler(&historyOptions[0], HistoryDlg, 0);
MarkMenu("View.MoveHistory", HistoryDlg);
}
void
HistoryShowProc ()
{
if (!shellUp[HistoryDlg]) {
ASSIGN(historyText, "");
HistoryPopUp();
RefreshMemoContent();
MemoContentUpdated();
} else PopDown(HistoryDlg);
ToNrEvent(currentMove);
}