4 * Author: Alessandro Scotti (Dec 2005)
6 * Copyright 2005 Alessandro Scotti
8 * Enhancements Copyright 2009, 2010, 2011, 2012 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 */
58 #include "engineoutput.h"
62 # define _(s) gettext (s)
63 # define N_(s) gettext_noop (s)
69 // [HGM] pixmaps of some ICONS used in the engine-outut window
70 #include "pixmaps/WHITE_14.xpm"
71 #include "pixmaps/BLACK_14.xpm"
72 #include "pixmaps/CLEAR_14.xpm"
73 #include "pixmaps/UNKNOWN_14.xpm"
74 #include "pixmaps/THINKING_14.xpm"
75 #include "pixmaps/PONDER_14.xpm"
76 #include "pixmaps/ANALYZING_14.xpm"
78 extern Option engoutOptions[]; // must go in header, but which?
80 /* Module variables */
81 static int currentPV, highTextStart[2], highTextEnd[2];
83 static Pixmap icons[8]; // [HGM] this front-end array translates back-end icon indicator to handle
84 static Widget memoWidget;
89 ReadIcon (char *pixData[], int iconNr, Widget w)
93 if ((r=XpmCreatePixmapFromData(xDisplay, XtWindow(w),
96 NULL, NULL /*&attr*/)) != 0) {
97 fprintf(stderr, _("Error %d loading icon image\n"), r);
104 InitEngineOutput (Option *opt, Option *memo2)
105 { // front-end, because it must have access to the pixmaps
107 Widget w = opt->handle;
108 memoWidget = memo2->handle;
110 ReadIcon(WHITE_14, nColorWhite, w);
111 ReadIcon(BLACK_14, nColorBlack, w);
112 ReadIcon(UNKNOWN_14, nColorUnknown, w);
114 ReadIcon(CLEAR_14, nClear, w);
115 ReadIcon(PONDER_14, nPondering, w);
116 ReadIcon(THINK_14, nThinking, w);
117 ReadIcon(ANALYZE_14, nAnalyzing, w);
122 DrawWidgetIcon (Option *opt, int nIcon)
123 { // as we are already in X front-end, so do X-stuff here
125 gchar widgetname[50];
128 gtk_image_set_from_pixbuf(GTK_IMAGE(opt->handle), GDK_PIXBUF(iconsGTK[nIcon]));
134 InsertIntoMemo (int which, char * text, int where)
139 /* the backend adds \r\n, which is needed for winboard,
140 * for xboard we delete them again over here */
141 if(p = strchr(text, '\r')) *p = ' ';
143 GtkTextBuffer *tb = (GtkTextBuffer *) (engoutOptions[which ? 12 : 5].handle);
144 // gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(tb), &start);
145 gtk_text_buffer_get_iter_at_offset(tb, &start, where);
146 gtk_text_buffer_insert(tb, &start, text, -1);
147 if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting
148 int len = strlen(text);
149 highTextStart[which] += len; highTextEnd[which] += len;
151 XawTextSetSelection( edit, highTextStart[which], highTextEnd[which] );
156 //--------------------------------- PV walking ---------------------------------------
158 char memoTranslations[] =
159 ":Ctrl<Key>c: CopyMemoProc() \n \
160 <Btn3Motion>: HandlePV() \n \
161 Shift<Btn3Down>: select-start() extend-end() SelectPV(1) \n \
162 Any<Btn3Down>: select-start() extend-end() SelectPV(0) \n \
163 <Btn3Up>: StopPV() \n";
167 SelectPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
168 { // [HGM] pv: translate click to PV line, and load it for display
171 XawTextPosition index, dummy;
175 x = event->xmotion.x; y = event->xmotion.y;
176 currentPV = (w != memoWidget);
177 XawTextGetSelectionPos(w, &index, &dummy);
178 XtSetArg(arg, XtNstring, &val);
179 XtGetValues(w, &arg, 1);
180 shiftKey = strcmp(params[0], "0");
181 if(LoadMultiPV(x, y, val, index, &start, &end, currentPV)) {
182 XawTextSetSelection( w, start, end );
183 highTextStart[currentPV] = start; highTextEnd[currentPV] = end;
190 StopPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
191 { // [HGM] pv: on right-button release, stop displaying PV
192 XawTextUnsetSelection( w );
193 highTextStart[currentPV] = highTextEnd[currentPV] = 0;
195 XtCallActionProc(w, "beginning-of-file", event, NULL, 0);
199 //------------------------------- pane switching -----------------------------------
202 ResizeWindowControls (int mode)
203 { // another hideous kludge: to have only a single pane, we resize the
204 // second to 5 pixels (which makes it too small to display anything)
209 Dimension ew_height, tmp;
210 Widget shell = shells[EngOutDlg];
212 form1 = XtNameToWidget(shell, "*paneA");
213 form2 = XtNameToWidget(shell, "*paneB");
216 XtSetArg(args[j], XtNheight, (XtArgVal) &ew_height); j++;
217 XtGetValues(form1, args, j);
219 XtSetArg(args[j], XtNheight, (XtArgVal) &tmp); j++;
220 XtGetValues(form2, args, j);
221 ew_height += tmp; // total height
225 XtSetArg(args[j], XtNheight, (XtArgVal) 5); j++;
226 XtSetValues(form2, args, j);
228 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height-5)); j++;
229 XtSetValues(form1, args, j);
232 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
233 XtSetValues(form1, args, j);
235 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
236 XtSetValues(form2, args, j);