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;
86 static void *memoWidget;
90 ReadIcon (char *pixData[], int iconNr, Widget w)
94 if ((r=XpmCreatePixmapFromData(xDisplay, XtWindow(w),
97 NULL, NULL /*&attr*/)) != 0) {
98 fprintf(stderr, _("Error %d loading icon image\n"), r);
105 InitEngineOutput (Option *opt, Option *memo2)
106 { // front-end, because it must have access to the pixmaps
108 Widget w = opt->handle;
109 memoWidget = memo2->handle;
111 ReadIcon(WHITE_14, nColorWhite, w);
112 ReadIcon(BLACK_14, nColorBlack, w);
113 ReadIcon(UNKNOWN_14, nColorUnknown, w);
115 ReadIcon(CLEAR_14, nClear, w);
116 ReadIcon(PONDER_14, nPondering, w);
117 ReadIcon(THINK_14, nThinking, w);
118 ReadIcon(ANALYZE_14, nAnalyzing, w);
123 DrawWidgetIcon (Option *opt, int nIcon)
124 { // as we are already in X front-end, so do X-stuff here
126 gchar widgetname[50];
129 gtk_image_set_from_pixbuf(GTK_IMAGE(opt->handle), GDK_PIXBUF(iconsGTK[nIcon]));
135 InsertIntoMemo (int which, char * text, int where)
140 /* the backend adds \r\n, which is needed for winboard,
141 * for xboard we delete them again over here */
142 if(p = strchr(text, '\r')) *p = ' ';
144 GtkTextBuffer *tb = (GtkTextBuffer *) (engoutOptions[which ? 12 : 5].handle);
145 // gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(tb), &start);
146 gtk_text_buffer_get_iter_at_offset(tb, &start, where);
147 gtk_text_buffer_insert(tb, &start, text, -1);
148 if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting
149 int len = strlen(text);
150 highTextStart[which] += len; highTextEnd[which] += len;
152 XawTextSetSelection( edit, highTextStart[which], highTextEnd[which] );
157 //--------------------------------- PV walking ---------------------------------------
159 char memoTranslations[] =
160 ":Ctrl<Key>c: CopyMemoProc() \n \
161 <Btn3Motion>: HandlePV() \n \
162 Shift<Btn3Down>: select-start() extend-end() SelectPV(1) \n \
163 Any<Btn3Down>: select-start() extend-end() SelectPV(0) \n \
164 <Btn3Up>: StopPV() \n";
167 SelectPV (Option *opt, int x, int y)
168 { // [HGM] pv: translate click to PV line, and load it for display
169 int start, end, index;
171 int currentPV = (opt->handle != memoWidget);
173 XawTextGetSelectionPos(w, &index, &dummy);
174 XtSetArg(arg, XtNstring, &val);
175 XtGetValues(w, &arg, 1);
177 if(LoadMultiPV(x, y, val, index, &start, &end, currentPV)) {
179 XawTextSetSelection( w, start, end );
181 highTextStart[currentPV] = start; highTextEnd[currentPV] = end;
187 { // [HGM] pv: on right-button release, stop displaying PV
189 XawTextUnsetSelection( opt->handle );
191 highTextStart[currentPV] = highTextEnd[currentPV] = 0;
194 XtCallActionProc(opt->handle, "beginning-of-file", event, NULL, 0);
198 //------------------------------- pane switching -----------------------------------
201 ResizeWindowControls (int mode)
202 { // another hideous kludge: to have only a single pane, we resize the
203 // second to 5 pixels (which makes it too small to display anything)
208 Dimension ew_height, tmp;
209 Widget shell = shells[EngOutDlg];
211 form1 = XtNameToWidget(shell, "*paneA");
212 form2 = XtNameToWidget(shell, "*paneB");
215 XtSetArg(args[j], XtNheight, (XtArgVal) &ew_height); j++;
216 XtGetValues(form1, args, j);
218 XtSetArg(args[j], XtNheight, (XtArgVal) &tmp); j++;
219 XtGetValues(form2, args, j);
220 ew_height += tmp; // total height
224 XtSetArg(args[j], XtNheight, (XtArgVal) 5); j++;
225 XtSetValues(form2, args, j);
227 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height-5)); j++;
228 XtSetValues(form1, args, j);
231 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
232 XtSetValues(form1, args, j);
234 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
235 XtSetValues(form2, args, j);