4 * Author: Alessandro Scotti (Dec 2005)
6 * Copyright 2005 Alessandro Scotti
8 * Enhancements Copyright 2009, 2010, 2011, 2012, 2013,
9 * 2014 Free Software Foundation, Inc.
11 * ------------------------------------------------------------------------
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.
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.
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/.
26 * ------------------------------------------------------------------------
27 ** See the file ChangeLog for a revision history. */
34 #include <sys/types.h>
39 #else /* not STDC_HEADERS */
40 extern char *getenv();
43 # else /* not HAVE_STRING_H */
45 # endif /* not HAVE_STRING_H */
46 #endif /* not STDC_HEADERS */
52 #include <X11/Intrinsic.h>
53 #include <X11/StringDefs.h>
54 #include <X11/Shell.h>
55 #include <X11/Xaw/Dialog.h>
56 #include <X11/Xaw/Form.h>
57 #include <X11/Xaw/List.h>
58 #include <X11/Xaw/Label.h>
59 #include <X11/Xaw/SimpleMenu.h>
60 #include <X11/Xaw/SmeBSB.h>
61 #include <X11/Xaw/SmeLine.h>
62 #include <X11/Xaw/Box.h>
63 #include <X11/Xaw/Paned.h>
64 #include <X11/Xaw/MenuButton.h>
65 #include <X11/cursorfont.h>
66 #include <X11/Xaw/Text.h>
67 #include <X11/Xaw/AsciiText.h>
68 #include <X11/Xaw/Viewport.h>
69 #include <X11/Xatom.h>
70 #include <X11/Xmu/Atoms.h>
77 #include "engineoutput.h"
81 # define _(s) gettext (s)
82 # define N_(s) gettext_noop (s)
90 // [HGM] pixmaps of some ICONS used in the engine-outut window
91 #include "pixmaps/WHITE_14.xpm"
92 #include "pixmaps/BLACK_14.xpm"
93 #include "pixmaps/CLEAR_14.xpm"
94 #include "pixmaps/UNKNOWN_14.xpm"
95 #include "pixmaps/THINKING_14.xpm"
96 #include "pixmaps/PONDER_14.xpm"
97 #include "pixmaps/ANALYZING_14.xpm"
100 /* Module variables */
101 static int currentPV;
102 static Pixmap icons[8]; // [HGM] this front-end array translates back-end icon indicator to handle
103 static Widget memoWidget;
107 ReadIcon (char *pixData[], int iconNr, Widget w)
111 if ((r=XpmCreatePixmapFromData(xDisplay, XtWindow(w),
114 NULL, NULL /*&attr*/)) != 0) {
115 fprintf(stderr, _("Error %d loading icon image\n"), r);
121 InitEngineOutput (Option *opt, Option *memo2)
122 { // front-end, because it must have access to the pixmaps
123 Widget w = opt->handle;
124 memoWidget = memo2->handle;
126 ReadIcon(WHITE_14, nColorWhite, w);
127 ReadIcon(BLACK_14, nColorBlack, w);
128 ReadIcon(UNKNOWN_14, nColorUnknown, w);
130 ReadIcon(CLEAR_14, nClear, w);
131 ReadIcon(PONDER_14, nPondering, w);
132 ReadIcon(THINK_14, nThinking, w);
133 ReadIcon(ANALYZE_14, nAnalyzing, w);
137 DrawWidgetIcon (Option *opt, int nIcon)
138 { // as we are already in X front-end, so do X-stuff here
140 XtSetArg(arg, XtNleftBitmap, (XtArgVal) icons[nIcon]);
141 XtSetValues(opt->handle, &arg, 1);
145 InsertIntoMemo (int which, char * text, int where)
150 /* the backend adds \r\n, which is needed for winboard,
151 * for xboard we delete them again over here */
152 if(t.ptr = strchr(text, '\r')) *t.ptr = ' ';
154 t.ptr = text; t.firstPos = 0; t.length = strlen(text); t.format = XawFmt8Bit;
155 edit = XtNameToWidget(shells[EngOutDlg], which ? "*paneB.text" : "*paneA.text");
156 XawTextReplace(edit, where, where, &t);
157 if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting
158 int len = strlen(text);
159 highTextStart[which] += len; highTextEnd[which] += len;
160 XawTextSetSelection( edit, highTextStart[which], highTextEnd[which] );
164 //--------------------------------- PV walking ---------------------------------------
166 char memoTranslations[] =
167 ":Ctrl<Key>c: CopyMemoProc() \n \
168 <Btn3Motion>: HandlePV() \n \
169 Shift<Btn3Down>: select-start() extend-end(PRIMARY) SelectPV(1) \n \
170 Any<Btn3Down>: select-start() extend-end(PRIMARY) SelectPV(0) \n \
171 <Btn3Up>: StopPV() \n";
174 SelectPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
175 { // [HGM] pv: translate click to PV line, and load it for display
178 XawTextPosition index, dummy;
182 x = event->xmotion.x; y = event->xmotion.y;
183 currentPV = (w != memoWidget);
184 XawTextGetSelectionPos(w, &index, &dummy);
185 XtSetArg(arg, XtNstring, &val);
186 XtGetValues(w, &arg, 1);
187 shiftKey = strcmp(params[0], "0");
188 if(LoadMultiPV(x, y, val, index, &start, &end, currentPV)) {
189 XawTextSetSelection( w, start, end );
190 highTextStart[currentPV] = start; highTextEnd[currentPV] = end;
195 StopPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
196 { // [HGM] pv: on right-button release, stop displaying PV
197 XawTextUnsetSelection( w );
198 highTextStart[currentPV] = highTextEnd[currentPV] = 0;
200 XtCallActionProc(w, "beginning-of-file", event, NULL, 0);
203 //------------------------- Ctrl-C copying of memo texts ---------------------------
205 // Awfull code: first read our own primary selection into selected_fen_position,
206 // and then transfer ownership of this to the clipboard, so that the
207 // copy-position callback can fetch it there when somebody pastes it
208 // Worst of all is that I only added it because I did not know how to copy primary:
209 // my laptop has no middle button. Ctrl-C might not be needed at all... [HGM]
211 // cloned from CopyPositionProc. Abuse selected_fen_position to hold selection
213 Boolean SendPositionSelection(Widget w, Atom *selection, Atom *target,
214 Atom *type_return, XtPointer *value_return,
215 unsigned long *length_return, int *format_return); // from xboard.c
218 MemoCB (Widget w, XtPointer client_data, Atom *selection,
219 Atom *type, XtPointer value, unsigned long *len, int *format)
221 if (value==NULL || *len==0) return; /* nothing had been selected to copy */
222 selected_fen_position = value;
223 selected_fen_position[*len]='\0'; /* normally this string is terminated, but be safe */
224 XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay),
226 SendPositionSelection,
227 NULL/* lose_ownership_proc */ ,
228 NULL/* transfer_done_proc */);
232 CopyMemoProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
234 if(appData.pasteSelection) return;
235 if (selected_fen_position) free(selected_fen_position);
236 XtGetSelectionValue(menuBarWidget,
237 XA_PRIMARY, XA_STRING,
238 /* (XtSelectionCallbackProc) */ MemoCB,
239 NULL, /* client_data passed to PastePositionCB */
241 /* better to use the time field from the event that triggered the
242 * call to this function, but that isn't trivial to get
248 //------------------------------- pane switching -----------------------------------
251 ResizeWindowControls (int mode)
252 { // another hideous kludge: to have only a single pane, we resize the
253 // second to 5 pixels (which makes it too small to display anything)
257 Dimension ew_height, tmp;
258 Widget shell = shells[EngOutDlg];
260 form1 = XtNameToWidget(shell, "*paneA");
261 form2 = XtNameToWidget(shell, "*paneB");
264 XtSetArg(args[j], XtNheight, (XtArgVal) &ew_height); j++;
265 XtGetValues(form1, args, j);
267 XtSetArg(args[j], XtNheight, (XtArgVal) &tmp); j++;
268 XtGetValues(form2, args, j);
269 ew_height += tmp; // total height
273 XtSetArg(args[j], XtNheight, (XtArgVal) 5); j++;
274 XtSetValues(form2, args, j);
276 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height-5)); j++;
277 XtSetValues(form1, args, j);
280 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
281 XtSetValues(form1, args, j);
283 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
284 XtSetValues(form2, args, j);