Fix multi-leg promotions
[xboard.git] / gtk / xengineoutput.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 <gtk/gtk.h>
53
54 #include "common.h"
55 #include "frontend.h"
56 #include "backend.h"
57 #include "dialogs.h"
58 #include "xboard.h"
59 #include "engineoutput.h"
60 #include "gettext.h"
61
62 #ifdef ENABLE_NLS
63 # define  _(s) gettext (s)
64 # define N_(s) gettext_noop (s)
65 #else
66 # define  _(s) (s)
67 # define N_(s)  s
68 #endif
69
70 extern Option engoutOptions[]; // must go in header, but which?
71
72 /* Module variables */
73 #ifdef TODO_GTK
74 static Widget memoWidget;
75 #endif
76 static GdkPixbuf *iconsGTK[8];
77
78 static void
79 ReadIcon (gchar *svgFilename, int iconNr)
80 {
81     iconsGTK[iconNr] = LoadIconFile(svgFilename);
82 }
83
84 void
85 InitEngineOutput (Option *opt, Option *memo2)
86 {       // front-end, because it must have access to the pixmaps
87 #ifdef TODO_GTK
88         Widget w = opt->handle;
89         memoWidget = memo2->handle;
90 #endif
91     ReadIcon("eo_White", nColorWhite);
92     ReadIcon("eo_Black", nColorBlack);
93     ReadIcon("eo_Unknown", nColorUnknown);
94
95     ReadIcon("eo_Clear", nClear);
96     ReadIcon("eo_Ponder", nPondering);
97     ReadIcon("eo_Thinking", nThinking);
98     ReadIcon("eo_Analyzing", nAnalyzing);
99 }
100
101 void
102 DrawWidgetIcon (Option *opt, int nIcon)
103 {   // as we are already in GTK front-end, so do GTK-stuff here
104     if( nIcon != 0 ) gtk_image_set_from_pixbuf(GTK_IMAGE(opt->handle), GDK_PIXBUF(iconsGTK[nIcon]));
105 }
106
107 void
108 InsertIntoMemo (int which, char * text, int where)
109 {
110     char *p;
111     GtkTextIter start;
112
113     /* the backend adds \r\n, which is needed for winboard,
114      * for xboard we delete them again over here */
115     if(p = strchr(text, '\r')) *p = ' ';
116
117     GtkTextBuffer *tb = (GtkTextBuffer *) (engoutOptions[which ? 12 : 5].handle);
118 //    gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(tb), &start);
119     gtk_text_buffer_get_iter_at_offset(tb, &start, where);
120     gtk_text_buffer_insert(tb, &start, text, -1);
121     if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting
122         int len = strlen(text);
123         highTextStart[which] += len; highTextEnd[which] += len;
124     }
125 }
126
127 //------------------------------- pane switching -----------------------------------
128
129 void
130 ResizeWindowControls (int mode)
131 {   // another hideous kludge: to have only a single pane, we resize the
132     // second to 5 pixels (which makes it too small to display anything)
133     if(mode) gtk_widget_show(engoutOptions[13].handle);
134     else     gtk_widget_hide(engoutOptions[13].handle);
135 }