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 */
51 #include <X11/Intrinsic.h>
52 #include <X11/StringDefs.h>
53 #include <X11/Shell.h>
54 #include <X11/Xaw/Dialog.h>
55 #include <X11/Xaw/Form.h>
56 #include <X11/Xaw/List.h>
57 #include <X11/Xaw/Label.h>
58 #include <X11/Xaw/SimpleMenu.h>
59 #include <X11/Xaw/SmeBSB.h>
60 #include <X11/Xaw/SmeLine.h>
61 #include <X11/Xaw/Box.h>
62 #include <X11/Xaw/Paned.h>
63 #include <X11/Xaw/MenuButton.h>
64 #include <X11/cursorfont.h>
65 #include <X11/Xaw/Text.h>
66 #include <X11/Xaw/AsciiText.h>
67 #include <X11/Xaw/Viewport.h>
68 #include <X11/Xatom.h>
69 #include <X11/Xmu/Atoms.h>
76 #include "engineoutput.h"
80 # define _(s) gettext (s)
81 # define N_(s) gettext_noop (s)
89 // [HGM] pixmaps of some ICONS used in the engine-outut window
90 #include "pixmaps/WHITE_14.xpm"
91 #include "pixmaps/BLACK_14.xpm"
92 #include "pixmaps/CLEAR_14.xpm"
93 #include "pixmaps/UNKNOWN_14.xpm"
94 #include "pixmaps/THINKING_14.xpm"
95 #include "pixmaps/PONDER_14.xpm"
96 #include "pixmaps/ANALYZING_14.xpm"
99 /* Module variables */
100 static int currentPV, highTextStart[2], highTextEnd[2];
101 static Pixmap icons[8]; // [HGM] this front-end array translates back-end icon indicator to handle
102 static Widget memoWidget;
106 ReadIcon (char *pixData[], int iconNr, Widget w)
110 if ((r=XpmCreatePixmapFromData(xDisplay, XtWindow(w),
113 NULL, NULL /*&attr*/)) != 0) {
114 fprintf(stderr, _("Error %d loading icon image\n"), r);
120 InitEngineOutput (Option *opt, Option *memo2)
121 { // front-end, because it must have access to the pixmaps
122 Widget w = opt->handle;
123 memoWidget = memo2->handle;
125 ReadIcon(WHITE_14, nColorWhite, w);
126 ReadIcon(BLACK_14, nColorBlack, w);
127 ReadIcon(UNKNOWN_14, nColorUnknown, w);
129 ReadIcon(CLEAR_14, nClear, w);
130 ReadIcon(PONDER_14, nPondering, w);
131 ReadIcon(THINK_14, nThinking, w);
132 ReadIcon(ANALYZE_14, nAnalyzing, w);
136 DrawWidgetIcon (Option *opt, int nIcon)
137 { // as we are already in X front-end, so do X-stuff here
139 XtSetArg(arg, XtNleftBitmap, (XtArgVal) icons[nIcon]);
140 XtSetValues(opt->handle, &arg, 1);
144 InsertIntoMemo (int which, char * text, int where)
149 /* the backend adds \r\n, which is needed for winboard,
150 * for xboard we delete them again over here */
151 if(t.ptr = strchr(text, '\r')) *t.ptr = ' ';
153 t.ptr = text; t.firstPos = 0; t.length = strlen(text); t.format = XawFmt8Bit;
154 edit = XtNameToWidget(shells[EngOutDlg], which ? "*paneB.text" : "*paneA.text");
155 XawTextReplace(edit, where, where, &t);
156 if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting
157 int len = strlen(text);
158 highTextStart[which] += len; highTextEnd[which] += len;
159 XawTextSetSelection( edit, highTextStart[which], highTextEnd[which] );
163 //--------------------------------- PV walking ---------------------------------------
165 char memoTranslations[] =
166 ":Ctrl<Key>c: CopyMemoProc() \n \
167 <Btn3Motion>: HandlePV() \n \
168 Shift<Btn3Down>: select-start() SelectPV(1) \n \
169 Any<Btn3Down>: select-start() SelectPV(0) \n \
170 <Btn3Up>: extend-end() StopPV() \n";
173 SelectPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
174 { // [HGM] pv: translate click to PV line, and load it for display
177 XawTextPosition index, dummy;
181 x = event->xmotion.x; y = event->xmotion.y;
182 currentPV = (w != memoWidget);
183 XawTextGetSelectionPos(w, &index, &dummy);
184 XtSetArg(arg, XtNstring, &val);
185 XtGetValues(w, &arg, 1);
186 shiftKey = strcmp(params[0], "0");
187 if(LoadMultiPV(x, y, val, index, &start, &end, currentPV)) {
188 XawTextSetSelection( w, start, end );
189 highTextStart[currentPV] = start; highTextEnd[currentPV] = end;
194 StopPV (Widget w, XEvent * event, String * params, Cardinal * nParams)
195 { // [HGM] pv: on right-button release, stop displaying PV
196 XawTextUnsetSelection( w );
197 highTextStart[currentPV] = highTextEnd[currentPV] = 0;
201 //------------------------- Ctrl-C copying of memo texts ---------------------------
203 // Awfull code: first read our own primary selection into selected_fen_position,
204 // and then transfer ownership of this to the clipboard, so that the
205 // copy-position callback can fetch it there when somebody pastes it
206 // Worst of all is that I only added it because I did not know how to copy primary:
207 // my laptop has no middle button. Ctrl-C might not be needed at all... [HGM]
209 // cloned from CopyPositionProc. Abuse selected_fen_position to hold selection
211 Boolean SendPositionSelection(Widget w, Atom *selection, Atom *target,
212 Atom *type_return, XtPointer *value_return,
213 unsigned long *length_return, int *format_return); // from xboard.c
216 MemoCB (Widget w, XtPointer client_data, Atom *selection,
217 Atom *type, XtPointer value, unsigned long *len, int *format)
219 if (value==NULL || *len==0) return; /* nothing had been selected to copy */
220 selected_fen_position = value;
221 selected_fen_position[*len]='\0'; /* normally this string is terminated, but be safe */
222 XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay),
224 SendPositionSelection,
225 NULL/* lose_ownership_proc */ ,
226 NULL/* transfer_done_proc */);
230 CopyMemoProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
232 if(appData.pasteSelection) return;
233 if (selected_fen_position) free(selected_fen_position);
234 XtGetSelectionValue(menuBarWidget,
235 XA_PRIMARY, XA_STRING,
236 /* (XtSelectionCallbackProc) */ MemoCB,
237 NULL, /* client_data passed to PastePositionCB */
239 /* better to use the time field from the event that triggered the
240 * call to this function, but that isn't trivial to get
246 //------------------------------- pane switching -----------------------------------
249 ResizeWindowControls (int mode)
250 { // another hideous kludge: to have only a single pane, we resize the
251 // second to 5 pixels (which makes it too small to display anything)
255 Dimension ew_height, tmp;
256 Widget shell = shells[EngOutDlg];
258 form1 = XtNameToWidget(shell, "*paneA");
259 form2 = XtNameToWidget(shell, "*paneB");
262 XtSetArg(args[j], XtNheight, (XtArgVal) &ew_height); j++;
263 XtGetValues(form1, args, j);
265 XtSetArg(args[j], XtNheight, (XtArgVal) &tmp); j++;
266 XtGetValues(form2, args, j);
267 ew_height += tmp; // total height
271 XtSetArg(args[j], XtNheight, (XtArgVal) 5); j++;
272 XtSetValues(form2, args, j);
274 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height-5)); j++;
275 XtSetValues(form1, args, j);
278 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
279 XtSetValues(form1, args, j);
281 XtSetArg(args[j], XtNheight, (XtArgVal) (ew_height/2)); j++;
282 XtSetValues(form2, args, j);