Redo Engine Output window with generic popup
[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 Free Software Foundation, Inc.
9  *
10  * ------------------------------------------------------------------------
11  *
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.
16  *
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.
21  *
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/.
24  *
25  * ------------------------------------------------------------------------
26  ** See the file ChangeLog for a revision history.  */
27
28 #include "config.h"
29
30 #include <stdio.h>
31 #include <ctype.h>
32 #include <errno.h>
33 #include <sys/types.h>
34
35 #if STDC_HEADERS
36 # include <stdlib.h>
37 # include <string.h>
38 #else /* not STDC_HEADERS */
39 extern char *getenv();
40 # if HAVE_STRING_H
41 #  include <string.h>
42 # else /* not HAVE_STRING_H */
43 #  include <strings.h>
44 # endif /* not HAVE_STRING_H */
45 #endif /* not STDC_HEADERS */
46
47 #if HAVE_UNISTD_H
48 # include <unistd.h>
49 #endif
50
51 #include "common.h"
52 #include "frontend.h"
53 #include "backend.h"
54 #include "dialogs.h"
55 #include "engineoutput.h"
56 #include "gettext.h"
57
58 #ifdef ENABLE_NLS
59 # define  _(s) gettext (s)
60 # define N_(s) gettext_noop (s)
61 #else
62 # define  _(s) (s)
63 # define N_(s)  s
64 #endif
65
66
67 /* Module variables */
68 int  windowMode = 1;
69
70 char *mem1, *mem2; // dummies, as this dialog can never be OK'ed
71
72 Option engoutOptions[] = {
73 {  0,  LL|T2T,           17, NULL, NULL, "", NULL, Label, "" },
74 {  0, L2L|T2T|SAME_ROW, 163, NULL, NULL, NULL, NULL, Label, N_("engine name") },
75 {  0,     T2T|SAME_ROW,  30, NULL, NULL, "", NULL, Label, "" },
76 {  0, R2R|T2T|SAME_ROW, 188, NULL, NULL, NULL, NULL, Label, N_("move") },
77 {  0,  RR|T2T|SAME_ROW,  80, NULL, NULL, NULL, NULL, Label, N_("NPS") },
78 {200, T_VSCRL | T_TOP,  500, NULL, (void*) &mem1, "", NULL, TextBox, "" },
79 {  0,         0,         0, NULL, NULL, "", NULL, Break , "" },
80 {  0,  LL|T2T,           17, NULL, NULL, "", NULL, Label, "" },
81 {  0, L2L|T2T|SAME_ROW, 163, NULL, NULL, NULL, NULL, Label, N_("engine name") },
82 {  0,     T2T|SAME_ROW,  30, NULL, NULL, "", NULL, Label, "" },
83 {  0, R2R|T2T|SAME_ROW, 188, NULL, NULL, NULL, NULL, Label, N_("move") },
84 {  0,  RR|T2T|SAME_ROW,  80, NULL, NULL, NULL, NULL, Label, N_("NPS") },
85 {200, T_VSCRL | T_TOP,  500, NULL, (void*) &mem2, "", NULL, TextBox, "" },
86 {   0,      NO_OK,       0, NULL, NULL, "", NULL, EndMark , "" }
87 };
88
89 void
90 SetIcon (int which, int field, int nIcon)
91 {   // first call into xengineoutput.c to pick up icon pixmap
92     if( nIcon ) DrawIcon(&engoutOptions[STRIDE*which + field - 1], nIcon);
93 }
94
95 void
96 DoSetWindowText (int which, int field, char *s_label)
97 {
98         SetWidgetLabel (&engoutOptions[STRIDE*which + field - 1], s_label);
99 }
100
101 void
102 SetEngineOutputTitle (char *title)
103 {
104         SetDialogTitle(EngOutDlg, title);
105 }
106
107
108 void
109 DoClearMemo (int which)
110 {
111       SetWidgetText(&engoutOptions[STRIDE*which + MEMO], "", -1);
112 }
113
114 void
115 EngineOutputPopUp ()
116 {
117     static int  needInit = TRUE;
118     static char *title = N_("Engine output");
119
120     if (GenericPopUp(engoutOptions, _(title), EngOutDlg, BoardWindow, NONMODAL, 1)) {
121         if(engoutOptions[STRIDE-1].type != Break)
122             DisplayFatalError(_("Mismatch of STRIDE in nengineoutput.c\nChange and recompile!"), 0, 2);
123         AddHandler(&engoutOptions[MEMO], 6);
124         AddHandler(&engoutOptions[MEMO+STRIDE], 6);
125         if( needInit ) {
126             InitializeEngineOutput(&engoutOptions[0], &engoutOptions[MEMO]); // make icon bitmaps
127             needInit = FALSE;
128         }
129         SetEngineColorIcon( 0 );
130         SetEngineColorIcon( 1 );
131         SetEngineState( 0, STATE_IDLE, "" );
132         SetEngineState( 1, STATE_IDLE, "" );
133     } else {
134         SetIconName(EngOutDlg, _(title));
135         SetDialogTitle(EngOutDlg, _(title));
136     }
137
138     MarkMenu("Show Engine Output", EngOutDlg);
139
140     ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output
141 }
142
143 int
144 EngineOutputIsUp ()
145 {
146     return shellUp[EngOutDlg];
147 }
148
149 int
150 EngineOutputDialogExists ()
151 {
152     return DialogExists(EngOutDlg);
153 }
154
155 void
156 EngineOutputProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
157 {
158   if (!PopDown(EngOutDlg)) EngineOutputPopUp();
159 }
160