4 * Author: Alessandro Scotti (Dec 2005)
6 * Copyright 2005 Alessandro Scotti
8 * Enhancements Copyright 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
10 * ------------------------------------------------------------------------
12 * GNU XBoard is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or (at
15 * your option) any later version.
17 * GNU XBoard is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see http://www.gnu.org/licenses/.
25 * ------------------------------------------------------------------------
26 ** See the file ChangeLog for a revision history. */
33 #include <sys/types.h>
38 #else /* not STDC_HEADERS */
39 extern char *getenv();
42 # else /* not HAVE_STRING_H */
44 # endif /* not HAVE_STRING_H */
45 #endif /* not STDC_HEADERS */
56 #include "engineoutput.h"
60 # define _(s) gettext (s)
61 # define N_(s) gettext_noop (s)
68 /* Module variables */
71 char *mem1, *mem2; // dummies, as this dialog can never be OK'ed
72 int highTextStart[2], highTextEnd[2];
74 int MemoProc P((Option *opt, int n, int x, int y, char *text, int index));
76 Option engoutOptions[] = {
77 { 0, LL|T2T, 17, NULL, NULL, NULL, NULL, Icon, " " },
78 { 0, L2L|T2T|SAME_ROW, 163, NULL, NULL, NULL, NULL, Label, N_("engine name") },
79 { 0, T2T|SAME_ROW, 30, NULL, NULL, NULL, NULL, Icon, " " },
80 { 0, R2R|T2T|SAME_ROW, 188, NULL, NULL, NULL, NULL, Label, N_("move") },
81 { 0, RR|T2T|SAME_ROW, 80, NULL, NULL, NULL, NULL, Label, N_("NPS") },
82 {200, T_VSCRL | T_TOP, 500, NULL, (void*) &mem1, "", (char**) MemoProc, TextBox, "" },
83 { 0, 0, 0, NULL, NULL, "", NULL, Break , "" },
84 { 0, LL|T2T, 17, NULL, NULL, NULL, NULL, Icon, " " },
85 { 0, L2L|T2T|SAME_ROW, 163, NULL, NULL, NULL, NULL, Label, N_("engine name") },
86 { 0, T2T|SAME_ROW, 30, NULL, NULL, NULL, NULL, Icon, " " },
87 { 0, R2R|T2T|SAME_ROW, 188, NULL, NULL, NULL, NULL, Label, N_("move") },
88 { 0, RR|T2T|SAME_ROW, 80, NULL, NULL, NULL, NULL, Label, N_("NPS") },
89 {200, T_VSCRL | T_TOP, 500, NULL, (void*) &mem2, "", (char**) MemoProc, TextBox, "" },
90 { 0, NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
94 MemoProc (Option *opt, int n, int x, int y, char *text, int index)
95 { // user callback for mouse events in memo
96 static int pressed; // keep track of button 3 state
97 int start, end, currentPV = (opt != &engoutOptions[5]);
100 case 0: // pointer motion
101 if(!pressed) return FALSE; // only motion with button 3 down is of interest
102 MovePV(x, y, 500/*lineGap + BOARD_HEIGHT * (squareSize + lineGap)*/);
104 case 3: // press button 3
106 if(LoadMultiPV(x, y, text, index, &start, &end, currentPV)) {
107 highTextStart[currentPV] = start; highTextEnd[currentPV] = end;
108 HighlightText(&engoutOptions[currentPV ? 12 : 5], start, end, TRUE);
111 case -3: // release button 3
113 if(highTextStart[currentPV] != highTextEnd[currentPV])
114 HighlightText(&engoutOptions[currentPV ? 12 : 5], highTextStart[currentPV], highTextEnd[currentPV], FALSE);
115 highTextStart[currentPV] = highTextEnd[currentPV] = 0;
119 return FALSE; // not meant for us; do regular event handler
125 SetIcon (int which, int field, int nIcon)
126 { // first call into xengineoutput.c to pick up icon pixmap
127 if( nIcon ) DrawWidgetIcon(&engoutOptions[STRIDE*which + field - 1], nIcon);
131 DoSetWindowText (int which, int field, char *s_label)
133 SetWidgetLabel (&engoutOptions[STRIDE*which + field - 1], s_label);
137 SetEngineOutputTitle (char *title)
139 SetDialogTitle(EngOutDlg, title);
144 DoClearMemo (int which)
146 SetWidgetText(&engoutOptions[STRIDE*which + MEMO], "", -1);
152 static int needInit = TRUE;
153 static char *title = N_("Engine output");
155 if (GenericPopUp(engoutOptions, _(title), EngOutDlg, BoardWindow, NONMODAL, appData.topLevel)) {
156 if(engoutOptions[STRIDE-1].type != Break)
157 DisplayFatalError(_("Mismatch of STRIDE in nengineoutput.c\nChange and recompile!"), 0, 2);
158 AddHandler(&engoutOptions[MEMO], EngOutDlg, 6);
159 AddHandler(&engoutOptions[MEMO+STRIDE], EngOutDlg, 6);
161 InitEngineOutput(&engoutOptions[0], &engoutOptions[MEMO]); // make icon bitmaps
164 SetEngineColorIcon( 0 );
165 SetEngineColorIcon( 1 );
166 SetEngineState( 0, STATE_IDLE, "" );
167 SetEngineState( 1, STATE_IDLE, "" );
169 SetIconName(EngOutDlg, _(title));
170 SetDialogTitle(EngOutDlg, _(title));
173 MarkMenu("View.EngineOutput", EngOutDlg);
175 ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output
181 return shellUp[EngOutDlg];
185 EngineOutputDialogExists ()
187 return DialogExists(EngOutDlg);
193 if (!PopDown(EngOutDlg)) EngineOutputPopUp();