Update zh_CN.po translation
[xboard.git] / nengineoutput.c
1 /*
2  * Engine output (PV)
3  *
4  * Author: Alessandro Scotti (Dec 2005)
5  *
6  * Copyright 2005 Alessandro Scotti
7  *
8  * Enhancements Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015,
9  * 2016 Free Software Foundation, Inc.
10  *
11  * ------------------------------------------------------------------------
12  *
13  * GNU XBoard is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or (at
16  * your option) any later version.
17  *
18  * GNU XBoard is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see http://www.gnu.org/licenses/.
25  *
26  * ------------------------------------------------------------------------
27  ** See the file ChangeLog for a revision history.  */
28
29 #include "config.h"
30
31 #include <stdio.h>
32 #include <ctype.h>
33 #include <errno.h>
34 #include <sys/types.h>
35
36 #if STDC_HEADERS
37 # include <stdlib.h>
38 # include <string.h>
39 #else /* not STDC_HEADERS */
40 extern char *getenv();
41 # if HAVE_STRING_H
42 #  include <string.h>
43 # else /* not HAVE_STRING_H */
44 #  include <strings.h>
45 # endif /* not HAVE_STRING_H */
46 #endif /* not STDC_HEADERS */
47
48 #if HAVE_UNISTD_H
49 # include <unistd.h>
50 #endif
51
52 #include "common.h"
53 #include "frontend.h"
54 #include "backend.h"
55 #include "dialogs.h"
56 #include "menus.h"
57 #include "engineoutput.h"
58 #include "gettext.h"
59
60 #ifdef ENABLE_NLS
61 # define  _(s) gettext (s)
62 # define N_(s) gettext_noop (s)
63 #else
64 # define  _(s) (s)
65 # define N_(s)  s
66 #endif
67
68
69 /* Module variables */
70 int  windowMode = 1;
71
72 char *mem1, *mem2; // dummies, as this dialog can never be OK'ed
73 int highTextStart[2], highTextEnd[2];
74
75 int MemoProc P((Option *opt, int n, int x, int y, char *text, int index));
76
77 Option engoutOptions[] = {
78 {  0,  LL|T2T,           18, NULL, NULL, NULL, NULL, Icon, " " },
79 {  0, L2L|T2T|SAME_ROW, 162, NULL, NULL, NULL, NULL, Label, N_("engine name") },
80 {  0,     T2T|SAME_ROW,  30, NULL, NULL, NULL, NULL, Icon, " " },
81 /* TRANSLATORS: noun, as in "the move Nf3"*/
82 {  0, R2R|T2T|SAME_ROW, 188, NULL, NULL, NULL, NULL, Label, N_("move") },
83 {  0,  RR|T2T|SAME_ROW,  80, NULL, NULL, NULL, NULL, Label, N_("NPS") },
84 {200, T_VSCRL | T_TOP,  500, NULL, (void*) &mem1, NULL, (char**) MemoProc, TextBox, "", &appData.historyFont },
85 {  0,         0,         0, NULL, NULL, "", NULL, Break , "" },
86 {  0,  LL|T2T,           18, NULL, NULL, NULL, NULL, Icon, " " },
87 {  0, L2L|T2T|SAME_ROW, 162, NULL, NULL, NULL, NULL, Label, N_("engine name") },
88 {  0,     T2T|SAME_ROW,  30, NULL, NULL, NULL, NULL, Icon, " " },
89 /* TRANSLATORS: noun, as in "the move Nf3"*/
90 {  0, R2R|T2T|SAME_ROW, 188, NULL, NULL, NULL, NULL, Label, N_("move") },
91 {  0,  RR|T2T|SAME_ROW,  80, NULL, NULL, NULL, NULL, Label, N_("NPS") },
92 {200, T_VSCRL | T_TOP,  500, NULL, (void*) &mem2, NULL, (char**) MemoProc, TextBox, "", &appData.historyFont },
93 {   0,      NO_OK,       0, NULL, NULL, "", NULL, EndMark , "" }
94 };
95
96 int
97 MemoProc (Option *opt, int n, int x, int y, char *text, int index)
98 {   // user callback for mouse events in memo
99     static int pressed; // keep track of button 3 state
100     int start, end, currentPV = (opt != &engoutOptions[5]);
101
102     switch(n) {
103       case 0: // pointer motion
104         if(!pressed) return FALSE; // only motion with button 3 down is of interest
105         MovePV(x, y, 500/*lineGap + BOARD_HEIGHT * (squareSize + lineGap)*/);
106         break;
107       case 3: // press button 3
108         pressed = 1;
109         if(LoadMultiPV(x, y, text, index, &start, &end, currentPV)) {
110             highTextStart[currentPV] = start; highTextEnd[currentPV] = end;
111             HighlightText(&engoutOptions[currentPV ? 12 : 5], start, end, TRUE);
112         }
113         break;
114       case -3: // release button 3
115         pressed = 0;
116         if(highTextStart[currentPV] != highTextEnd[currentPV])
117             HighlightText(&engoutOptions[currentPV ? 12 : 5], highTextStart[currentPV], highTextEnd[currentPV], FALSE);
118         highTextStart[currentPV] = highTextEnd[currentPV] = 0;
119         UnLoadPV();
120         break;
121       default:
122         return FALSE; // not meant for us; do regular event handler
123     }
124     return TRUE;
125 }
126
127 void
128 SetIcon (int which, int field, int nIcon)
129 {   // first call into xengineoutput.c to pick up icon pixmap
130     if( nIcon ) DrawWidgetIcon(&engoutOptions[STRIDE*which + field - 1], nIcon);
131 }
132
133 void
134 DoSetWindowText (int which, int field, char *s_label)
135 {
136         SetWidgetLabel (&engoutOptions[STRIDE*which + field - 1], s_label);
137 }
138
139 void
140 SetEngineOutputTitle (char *title)
141 {
142         SetDialogTitle(EngOutDlg, title);
143 }
144
145
146 void
147 DoClearMemo (int which)
148 {
149       SetWidgetText(&engoutOptions[STRIDE*which + MEMO], "", -1);
150 }
151
152 void
153 EngineOutputPopUp ()
154 {
155     static int  needInit = TRUE;
156     static char *title = N_("Engine output");
157
158     if (GenericPopUp(engoutOptions, _(title), EngOutDlg, BoardWindow, NONMODAL, appData.topLevel)) {
159         if(engoutOptions[STRIDE-1].type != Break)
160             DisplayFatalError(_("Mismatch of STRIDE in nengineoutput.c\nChange and recompile!"), 0, 2);
161         AddHandler(&engoutOptions[MEMO], EngOutDlg, 6);
162         AddHandler(&engoutOptions[MEMO+STRIDE], EngOutDlg, 6);
163         if( needInit ) {
164             InitEngineOutput(&engoutOptions[0], &engoutOptions[MEMO]); // make icon bitmaps
165             needInit = FALSE;
166         }
167         SetEngineColorIcon( 0 );
168         SetEngineColorIcon( 1 );
169         SetEngineState( 0, STATE_IDLE, "" );
170         SetEngineState( 1, STATE_IDLE, "" );
171     } else {
172         SetIconName(EngOutDlg, _(title));
173         SetDialogTitle(EngOutDlg, _(title));
174     }
175
176     MarkMenu("View.EngineOutput", EngOutDlg);
177
178     ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output
179 }
180
181 int
182 EngineOutputIsUp ()
183 {
184     return shellUp[EngOutDlg];
185 }
186
187 int
188 EngineOutputDialogExists ()
189 {
190     return DialogExists(EngOutDlg);
191 }
192
193 void
194 EngineOutputProc ()
195 {
196   if (!PopDown(EngOutDlg)) EngineOutputPopUp();
197 }