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