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 */
56 #include "engineoutput.h"
60 # define _(s) gettext (s)
61 # define N_(s) gettext_noop (s)
67 // [HGM] pixmaps of some ICONS used in the engine-outut window
68 #include "pixmaps/WHITE_14.xpm"
69 #include "pixmaps/BLACK_14.xpm"
70 #include "pixmaps/CLEAR_14.xpm"
71 #include "pixmaps/UNKNOWN_14.xpm"
72 #include "pixmaps/THINKING_14.xpm"
73 #include "pixmaps/PONDER_14.xpm"
74 #include "pixmaps/ANALYZING_14.xpm"
77 /* Module variables */
79 static int currentPV, highTextStart[2], highTextEnd[2];
80 static Pixmap icons[8]; // [HGM] this front-end array translates back-end icon indicator to handle
81 static Widget memoWidget;
85 ReadIcon (char *pixData[], int iconNr, Widget w)
90 if ((r=XpmCreatePixmapFromData(xDisplay, XtWindow(w),
93 NULL, NULL /*&attr*/)) != 0) {
94 fprintf(stderr, _("Error %d loading icon image\n"), r);
101 InitEngineOutput (Option *opt, Option *memo2)
102 { // front-end, because it must have access to the pixmaps
104 Widget w = opt->handle;
105 memoWidget = memo2->handle;
107 ReadIcon(WHITE_14, nColorWhite, w);
108 ReadIcon(BLACK_14, nColorBlack, w);
109 ReadIcon(UNKNOWN_14, nColorUnknown, w);
111 ReadIcon(CLEAR_14, nClear, w);
112 ReadIcon(PONDER_14, nPondering, w);
113 ReadIcon(THINK_14, nThinking, w);
114 ReadIcon(ANALYZE_14, nAnalyzing, w);
119 DrawWidgetIcon (Option *opt, int nIcon)
120 { // as we are already in X front-end, so do X-stuff here
123 XtSetArg(arg, XtNleftBitmap, (XtArgVal) icons[nIcon]);
124 XtSetValues(opt->handle, &arg, 1);
129 InsertIntoMemo (int which, char * text, int where)
135 /* the backend adds \r\n, which is needed for winboard,
136 * for xboard we delete them again over here */
137 if(t.ptr = strchr(text, '\r')) *t.ptr = ' ';
139 t.ptr = text; t.firstPos = 0; t.length = strlen(text); t.format = XawFmt8Bit;
140 edit = XtNameToWidget(shells[EngOutDlg], which ? "*paneB.text" : "*paneA.text");
141 XawTextReplace(edit, where, where, &t);
142 if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting
143 int len = strlen(text);
144 highTextStart[which] += len; highTextEnd[which] += len;
145 XawTextSetSelection( edit, highTextStart[which], highTextEnd[which] );
150 //--------------------------------- PV walking ---------------------------------------
152 char memoTranslations[] =
153 ":Ctrl<Key>c: CopyMemoProc() \n \
154 <Btn3Motion>: HandlePV() \n \
155 Shift<Btn3Down>: select-start() extend-end() SelectPV(1) \n \
156 Any<Btn3Down>: select-start() extend-end() SelectPV(0) \n \
157 <Btn3Up>: StopPV() \n";
160 SelectPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
161 { // [HGM] pv: translate click to PV line, and load it for display
165 XawTextPosition index, dummy;
169 x = event->xmotion.x; y = event->xmotion.y;
170 currentPV = (w != memoWidget);
171 XawTextGetSelectionPos(w, &index, &dummy);
172 XtSetArg(arg, XtNstring, &val);
173 XtGetValues(w, &arg, 1);
174 shiftKey = strcmp(params[0], "0");
175 if(LoadMultiPV(x, y, val, index, &start, &end, currentPV)) {
176 XawTextSetSelection( w, start, end );
177 highTextStart[currentPV] = start; highTextEnd[currentPV] = end;
183 StopPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
184 { // [HGM] pv: on right-button release, stop displaying PV
186 XawTextUnsetSelection( w );
187 highTextStart[currentPV] = highTextEnd[currentPV] = 0;
189 XtCallActionProc(w, "beginning-of-file", event, NULL, 0);
193 //------------------------- Ctrl-C copying of memo texts ---------------------------
195 // Awfull code: first read our own primary selection into selected_fen_position,
196 // and then transfer ownership of this to the clipboard, so that the
197 // copy-position callback can fetch it there when somebody pastes it
198 // Worst of all is that I only added it because I did not know how to copy primary:
199 // my laptop has no middle button. Ctrl-C might not be needed at all... [HGM]
201 // cloned from CopyPositionProc. Abuse selected_fen_position to hold selection
204 Boolean SendPositionSelection(Widget w, Atom *selection, Atom *target,
205 Atom *type_return, XtPointer *value_return,
206 unsigned long *length_return, int *format_return); // from xboard.c
209 MemoCB (Widget w, XtPointer client_data, Atom *selection,
210 Atom *type, XtPointer value, unsigned long *len, int *format)
212 if (value==NULL || *len==0) return; /* nothing had been selected to copy */
213 selected_fen_position = value;
214 selected_fen_position[*len]='\0'; /* normally this string is terminated, but be safe */
215 XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay),
217 SendPositionSelection,
218 NULL/* lose_ownership_proc */ ,
219 NULL/* transfer_done_proc */);
223 CopyMemoProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
225 if(appData.pasteSelection) return;
226 if (selected_fen_position) free(selected_fen_position);
227 XtGetSelectionValue(menuBarWidget,
228 XA_PRIMARY, XA_STRING,
229 /* (XtSelectionCallbackProc) */ MemoCB,
230 NULL, /* client_data passed to PastePositionCB */
232 /* better to use the time field from the event that triggered the
233 * call to this function, but that isn't trivial to get
240 //------------------------------- pane switching -----------------------------------
243 ResizeWindowControls (int mode)
244 { // another hideous kludge: to have only a single pane, we resize the
245 // second to 5 pixels (which makes it too small to display anything)
250 Dimension ew_height, tmp;
251 Widget shell = shells[EngOutDlg];
253 form1 = XtNameToWidget(shell, "*paneA");
254 form2 = XtNameToWidget(shell, "*paneB");
257 XtSetArg(args[j], XtNheight, (XtArgVal) &ew_height); j++;
258 XtGetValues(form1, args, j);
260 XtSetArg(args[j], XtNheight, (XtArgVal) &tmp); j++;
261 XtGetValues(form2, args, j);
262 ew_height += tmp; // total height
266 XtSetArg(args[j], XtNheight, (XtArgVal) 5); j++;
267 XtSetValues(form2, args, j);
269 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height-5)); j++;
270 XtSetValues(form1, args, j);
273 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
274 XtSetValues(form1, args, j);
276 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
277 XtSetValues(form2, args, j);