4 * Author: Alessandro Scotti (Dec 2005)
6 * Copyright 2005 Alessandro Scotti
8 * Enhancements Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015,
9 * 2016 Free Software Foundation, Inc.
11 * ------------------------------------------------------------------------
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.
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.
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/.
26 * ------------------------------------------------------------------------
27 ** See the file ChangeLog for a revision history. */
34 #include <sys/types.h>
39 #else /* not STDC_HEADERS */
40 extern char *getenv();
43 # else /* not HAVE_STRING_H */
45 # endif /* not HAVE_STRING_H */
46 #endif /* not STDC_HEADERS */
57 #include "engineoutput.h"
61 # define _(s) gettext (s)
62 # define N_(s) gettext_noop (s)
69 /* Module variables */
72 char *mem1, *mem2; // dummies, as this dialog can never be OK'ed
73 int highTextStart[2], highTextEnd[2];
75 int MemoProc P((Option *opt, int n, int x, int y, char *text, int index));
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 , "" }
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]);
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)*/);
107 case 3: // press button 3
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);
114 case -3: // release button 3
116 if(highTextStart[currentPV] != highTextEnd[currentPV])
117 HighlightText(&engoutOptions[currentPV ? 12 : 5], highTextStart[currentPV], highTextEnd[currentPV], FALSE);
118 highTextStart[currentPV] = highTextEnd[currentPV] = 0;
122 return FALSE; // not meant for us; do regular event handler
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);
134 DoSetWindowText (int which, int field, char *s_label)
136 SetWidgetLabel (&engoutOptions[STRIDE*which + field - 1], s_label);
140 SetEngineOutputTitle (char *title)
142 SetDialogTitle(EngOutDlg, title);
147 DoClearMemo (int which)
149 SetWidgetText(&engoutOptions[STRIDE*which + MEMO], "", -1);
155 static int needInit = TRUE;
156 static char *title = N_("Engine output");
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);
164 InitEngineOutput(&engoutOptions[0], &engoutOptions[MEMO]); // make icon bitmaps
167 SetEngineColorIcon( 0 );
168 SetEngineColorIcon( 1 );
169 SetEngineState( 0, STATE_IDLE, "" );
170 SetEngineState( 1, STATE_IDLE, "" );
172 SetIconName(EngOutDlg, _(title));
173 SetDialogTitle(EngOutDlg, _(title));
176 MarkMenu("View.EngineOutput", EngOutDlg);
178 ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output
184 return shellUp[EngOutDlg];
188 EngineOutputDialogExists ()
190 return DialogExists(EngOutDlg);
196 if (!PopDown(EngOutDlg)) EngineOutputPopUp();