2 * xoptions.c -- Move list window, part of X front end for XBoard
4 * Copyright 2000, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
5 * ------------------------------------------------------------------------
7 * GNU XBoard is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at
10 * your option) any later version.
12 * GNU XBoard is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see http://www.gnu.org/licenses/. *
20 *------------------------------------------------------------------------
21 ** See the file ChangeLog for a revision history. */
23 // [HGM] this file is the counterpart of woptions.c, containing xboard popup menus
24 // similar to those of WinBoard, to set the most common options interactively.
31 #include <sys/types.h>
36 #else /* not STDC_HEADERS */
37 extern char *getenv();
40 # else /* not HAVE_STRING_H */
42 # endif /* not HAVE_STRING_H */
43 #endif /* not STDC_HEADERS */
50 #include <X11/Intrinsic.h>
51 #include <X11/StringDefs.h>
52 #include <X11/Shell.h>
53 #include <X11/Xatom.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/Xaw/Toggle.h>
69 #include <X11/Xaw/Scrollbar.h>
71 #include <cairo/cairo.h>
72 #include <cairo/cairo-xlib.h>
82 # define _(s) gettext (s)
83 # define N_(s) gettext_noop (s)
89 // [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines
91 static Widget previous = NULL;
92 static Option *currentOption;
100 XtSetArg(args[0], XtNdisplayCaret, False);
101 XtSetValues(previous, args, 1);
107 SetFocus (Widget w, XtPointer data, XEvent *event, Boolean *b)
114 XtSetArg(args[0], XtNstring, &s);
115 XtGetValues(w, args, 1);
117 XtSetArg(args[0], XtNdisplayCaret, True);
118 if(!strchr(s, '\n') && strlen(s) < 80) XtSetArg(args[1], XtNinsertPosition, strlen(s)), j++;
119 XtSetValues(w, args, j);
120 XtSetKeyboardFocus((Widget) data, w);
127 XtSetKeyboardFocus(shellWidget, formWidget);
130 //--------------------------- Engine-specific options menu ----------------------------------
133 Option *dialogOptions[NrOfDialogs];
135 static Arg layoutArgs[] = {
136 { XtNborderWidth, 0 },
137 { XtNdefaultDistance, 0 },
140 static Arg formArgs[] = {
141 { XtNborderWidth, 0 },
142 { XtNresizable, (XtArgVal) True },
146 GetWidgetText (Option *opt, char **buf)
149 XtSetArg(arg, XtNstring, buf);
150 XtGetValues(opt->handle, &arg, 1);
154 SetWidgetText (Option *opt, char *buf, int n)
157 XtSetArg(arg, XtNstring, buf);
158 XtSetValues(opt->handle, &arg, 1);
159 if(n >= 0) SetFocus(opt->handle, shells[n], NULL, False);
163 GetWidgetState (Option *opt, int *state)
166 XtSetArg(arg, XtNstate, state);
167 XtGetValues(opt->handle, &arg, 1);
171 SetWidgetState (Option *opt, int state)
174 XtSetArg(arg, XtNstate, state);
175 XtSetValues(opt->handle, &arg, 1);
179 SetWidgetLabel (Option *opt, char *buf)
182 XtSetArg(arg, XtNlabel, (XtArgVal) buf);
183 XtSetValues(opt->handle, &arg, 1);
187 SetDialogTitle (DialogClass dlg, char *title)
190 XtSetArg(args[0], XtNtitle, title);
191 XtSetValues(shells[dlg], args, 1);
195 LoadListBox (Option *opt, char *emptyText)
197 static char *dummyList[2];
198 dummyList[0] = emptyText; // empty listboxes tend to crash X, so display user-supplied warning string instead
199 XawListChange(opt->handle, *(char*)opt->target ? opt->target : dummyList, 0, 0, True);
203 ReadScroll (Option *opt, float *top, float *bottom)
204 { // retreives fractions of top and bottom of thumb
206 Widget w = XtParent(opt->handle); // viewport
207 Widget v = XtNameToWidget(w, "vertical");
210 if(!v) return FALSE; // no scroll bar
211 XtSetArg(args[j], XtNshown, &h); j++;
212 XtSetArg(args[j], XtNtopOfThumb, top); j++;
213 XtGetValues(v, args, j);
219 SetScroll (Option *opt, float f)
220 { // sets top of thumb to given fraction
221 static char *params[3] = { "", "Continuous", "Proportional" };
223 Widget w = XtParent(opt->handle); // viewport
224 Widget v = XtNameToWidget(w, "vertical");
225 if(!v) return; // no scroll bar
226 XtCallActionProc(v, "StartScroll", &event, params+1, 1);
227 XawScrollbarSetThumb(v, f, -1.0);
228 XtCallActionProc(v, "NotifyThumb", &event, params, 0);
229 // XtCallActionProc(v, "NotifyScroll", &event, params+2, 1);
230 XtCallActionProc(v, "EndScroll", &event, params, 0);
234 HighlightListBoxItem (Option *opt, int nr)
236 XawListHighlight(opt->handle, nr);
240 HighlightWithScroll (Option *opt, int sel, int max)
242 float top, bottom, f, g;
243 HighlightListBoxItem(opt, sel);
244 if(!ReadScroll(opt, &top, &bottom)) return; // no scroll bar
245 bottom = bottom*max - 1.f;
248 if(sel > (top + 3*bottom)/4) f = (sel - 0.75f*(bottom-top))/max; else
249 if(sel < (3*top + bottom)/4) f = (sel - 0.25f*(bottom-top))/max;
250 if(f < 0.f) f = 0.; if(f + 1.f/max > 1.f) f = 1. - 1./max;
251 if(f != g) SetScroll(opt, f);
255 SelectedListBoxItem (Option *opt)
257 XawListReturnStruct *rs;
258 rs = XawListShowCurrent(opt->handle);
259 return rs->list_index;
263 FocusOnWidget (Option *opt, DialogClass dlg)
266 XtSetKeyboardFocus(shells[dlg], opt->handle);
270 SetIconName (DialogClass dlg, char *name)
274 XtSetArg(args[j], XtNiconName, (XtArgVal) name); j++;
275 // XtSetArg(args[j], XtNtitle, (XtArgVal) name); j++;
276 XtSetValues(shells[dlg], args, j);
280 CheckCallback (Widget ww, XtPointer client_data, XEvent *event, Boolean *b)
282 int s, data = (intptr_t) client_data;
283 Option *opt = dialogOptions[data >> 8] + (data & 255);
285 if(opt->type == Label) { ((ButtonCallback*) opt->target)(data&255); return; }
287 GetWidgetState(opt, &s);
288 SetWidgetState(opt, !s);
292 SpinCallback (Widget w, XtPointer client_data, XtPointer call_data)
296 char buf[MSG_SIZ], *p;
297 int j = 0; // Initialisation is necessary because the text value may be non-numeric causing the scanf conversion to fail
298 int data = (intptr_t) client_data;
299 Option *opt = dialogOptions[data >> 8] + (data & 255);
301 XtSetArg(args[0], XtNlabel, &name);
302 XtGetValues(w, args, 1);
304 GetWidgetText(opt, &val);
305 sscanf(val, "%d", &j);
306 if (strcmp(name, _("browse")) == 0) {
308 for(r = ""; *q; q++) if(*q == '.') r = q; else if(*q == '/') r = ""; // last dot after last slash
309 if(!strcmp(r, "") && !currentCps && opt->type == FileName && opt->textValue)
311 Browse(data>>8, opt->name, NULL, r, opt->type == PathName, "", &p, (FILE**) opt);
314 if (strcmp(name, "+") == 0) {
315 if(++j > opt->max) return;
317 if (strcmp(name, "-") == 0) {
318 if(--j < opt->min) return;
320 snprintf(buf, MSG_SIZ, "%d", j);
321 SetWidgetText(opt, buf, TransientDlg);
325 ComboSelect (Widget w, caddr_t addr, caddr_t index) // callback for all combo items
328 Option *opt = dialogOptions[((intptr_t)addr)>>24]; // applicable option list
329 int i = ((intptr_t)addr)>>16 & 255; // option number
330 int j = 0xFFFF & (intptr_t) addr;
332 values[i] = j; // store selected value in Option struct, for retrieval at OK
334 if(opt[i].type == Graph || opt[i].min & COMBO_CALLBACK && (!currentCps || shellUp[BrowserDlg])) {
335 ((ButtonCallback*) opt[i].target)(i);
339 if(opt[i].min & NO_GETTEXT)
340 XtSetArg(args[0], XtNlabel, ((char**)opt[i].choice)[j]);
342 XtSetArg(args[0], XtNlabel, _(((char**)opt[i].choice)[j]));
344 XtSetValues(opt[i].handle, args, 1);
348 CreateMenuItem (Widget menu, char *msg, XtCallbackProc CB, int n)
353 XtSetArg(args[j], XtNleftMargin, 20); j++;
354 XtSetArg(args[j], XtNrightMargin, 20); j++;
355 if(!strcmp(msg, "----")) { XtCreateManagedWidget(msg, smeLineObjectClass, menu, args, j); return NULL; }
356 XtSetArg(args[j], XtNlabel, msg);
357 entry = XtCreateManagedWidget("item", smeBSBObjectClass, menu, args, j+1);
358 XtAddCallback(entry, XtNcallback, CB, (caddr_t)(intptr_t) n);
363 CreateComboPopup (Widget parent, Option *opt, int n, int fromList, int def)
364 { // fromList determines if the item texts are taken from a list of strings, or from a menu table
368 MenuItem *mb = (MenuItem *) opt->choice;
369 char **list = (char **) opt->choice;
371 if(list[0] == NULL) return NULL; // avoid empty menus, as they cause crash
372 menu = XtCreatePopupShell(opt->name, simpleMenuWidgetClass, parent, NULL, 0);
376 char *msg = fromList ? list[i] : mb[i].string;
378 entry = CreateMenuItem(menu, opt->min & NO_GETTEXT ? msg : _(msg), (XtCallbackProc) ComboSelect, (n<<16)+i);
379 if(!fromList) mb[i].handle = (void*) entry; // save item ID, for enabling / checkmarking
381 XtSetArg(arg, XtNpopupOnEntry, entry);
382 XtSetValues(menu, &arg, 1);
388 char moveTypeInTranslations[] =
389 "<Key>Return: TypeInProc(1) \n"
390 "<Key>Escape: TypeInProc(0) \n";
391 extern char filterTranslations[];
392 extern char gameListTranslations[];
393 extern char memoTranslations[];
396 char *translationTable[] = { // beware: order is essential!
397 historyTranslations, commentTranslations, moveTypeInTranslations, ICSInputTranslations,
398 filterTranslations, gameListTranslations, memoTranslations
402 AddHandler (Option *opt, int nr)
404 XtOverrideTranslations(opt->handle, XtParseTranslationTable(translationTable[nr]));
407 //----------------------------Generic dialog --------------------------------------------
409 // cloned from Engine Settings dialog (and later merged with it)
411 Widget shells[NrOfDialogs];
412 DialogClass parents[NrOfDialogs];
413 WindowPlacement *wp[NrOfDialogs] = { // Beware! Order must correspond to DialogClass enum
414 NULL, &wpComment, &wpTags, NULL, NULL, NULL, NULL, &wpMoveHistory, &wpGameList, &wpEngineOutput, &wpEvalGraph,
415 NULL, NULL, NULL, NULL, /*&wpMain*/ NULL
419 DialogExists (DialogClass n)
420 { // accessor for use in back-end
421 return shells[n] != NULL;
425 RaiseWindow (DialogClass dlg)
428 Window root = RootWindow(xDisplay, DefaultScreen(xDisplay));
429 Atom atom = XInternAtom (xDisplay, "_NET_ACTIVE_WINDOW", False);
431 xev.xclient.type = ClientMessage;
432 xev.xclient.serial = 0;
433 xev.xclient.send_event = True;
434 xev.xclient.display = xDisplay;
435 xev.xclient.window = XtWindow(shells[dlg]);
436 xev.xclient.message_type = atom;
437 xev.xclient.format = 32;
438 xev.xclient.data.l[0] = 1;
439 xev.xclient.data.l[1] = CurrentTime;
441 XSendEvent (xDisplay,
443 SubstructureRedirectMask | SubstructureNotifyMask,
447 XSync(xDisplay, False);
451 PopDown (DialogClass n)
452 { // pops down any dialog created by GenericPopUp (or returns False if it wasn't up), unmarks any associated marked menu
455 Dimension windowH, windowW; Position windowX, windowY;
456 if (!shellUp[n] || !shells[n]) return 0;
457 if(n && wp[n]) { // remember position
459 XtSetArg(args[j], XtNx, &windowX); j++;
460 XtSetArg(args[j], XtNy, &windowY); j++;
461 XtSetArg(args[j], XtNheight, &windowH); j++;
462 XtSetArg(args[j], XtNwidth, &windowW); j++;
463 XtGetValues(shells[n], args, j);
466 wp[n]->width = windowW;
467 wp[n]->height = windowH;
470 XtPopdown(shells[n]);
471 shellUp[n]--; // count rather than clear
472 if(n == 0 || n >= PromoDlg) XtDestroyWidget(shells[n]), shells[n] = NULL;
474 MarkMenuItem(marked[n], False);
477 if(!n && n != BrowserDlg) currentCps = NULL; // if an Engine Settings dialog was up, we must be popping it down now
478 currentOption = dialogOptions[TransientDlg]; // just in case a transient dialog was up (to allow its check and combo callbacks to work)
479 RaiseWindow(parents[n]);
480 if(parents[n] == BoardWindow) XtSetKeyboardFocus(shellWidget, formWidget);
485 GenericPopDown (Widget w, XEvent *event, String *prms, Cardinal *nprms)
486 { // to cause popdown through a translation (Delete Window button!)
487 int dlg = atoi(prms[0]);
488 Widget sh = shells[dlg];
489 if(shellUp[BrowserDlg] && dlg != BrowserDlg || dialogError) return; // prevent closing dialog when it has an open file-browse daughter
492 shells[dlg] = sh; // restore
496 AppendText (Option *opt, char *s)
501 GetWidgetText(opt, &v);
503 t.ptr = s; t.firstPos = 0; t.length = strlen(s); t.format = XawFmt8Bit;
504 XawTextReplace(opt->handle, len, len, &t);
509 SetColor (char *colorName, Option *box)
510 { // sets the color of a widget
514 if (!appData.monoMode) {
515 vFrom.addr = (caddr_t) colorName;
516 vFrom.size = strlen(colorName);
517 XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
518 if (vTo.addr == NULL) {
519 buttonColor = (Pixel) -1;
521 buttonColor = *(Pixel *) vTo.addr;
523 } else buttonColor = timerBackgroundPixel;
524 XtSetArg(args[0], XtNbackground, buttonColor);;
525 XtSetValues(box->handle, args, 1);
529 ColorChanged (Widget w, XtPointer data, XEvent *event, Boolean *b)
530 { // for detecting a typed change in color
532 if ( (XLookupString(&(event->xkey), buf, 2, NULL, NULL) == 1) && *buf == '\r' )
533 RefreshColor((int)(intptr_t) data, 0);
537 GraphEventProc(Widget widget, caddr_t client_data, XEvent *event)
538 { // handle expose and mouse events on Graph widget
541 int j, button=10, f=1, sizing=0;
542 Option *opt, *graph = (Option *) client_data;
543 PointerCallback *userHandler = graph->target;
546 if (!XtIsRealized(widget)) return;
548 switch(event->type) {
549 case Expose: // make handling of expose events generic, just copying from memory buffer (->choice) to display (->textValue)
550 /* Get window size */
552 XtSetArg(args[j], XtNwidth, &w); j++;
553 XtSetArg(args[j], XtNheight, &h); j++;
554 XtGetValues(widget, args, j);
555 sizing = ((w != graph->max || h != graph->value) && ((XExposeEvent*)event)->count >= 0);
556 graph->max = w; graph->value = h;
557 if(sizing && ((XExposeEvent*)event)->count > 0) { graph->max = 0; return; } // don't bother if further exposure is pending during resize
558 if(!graph->textValue || sizing) { // create surfaces of new size for display widget
559 if(graph->textValue) cairo_surface_destroy((cairo_surface_t *)graph->textValue);
560 graph->textValue = (char*) cairo_xlib_surface_create(xDisplay, XtWindow(widget), DefaultVisual(xDisplay, 0), w, h);
562 if(sizing) { // the memory buffer was already created in GenericPopup(),
563 // to give drawing routines opportunity to use it befor first expose event
564 // (which are only processed when main gets to the event loop, so after all init!)
565 // so only change when size is no longer good
566 if(graph->choice) cairo_surface_destroy((cairo_surface_t *) graph->choice);
567 graph->choice = (char**) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
570 cr = cairo_create((cairo_surface_t *) graph->textValue);
571 cairo_set_source_surface(cr, (cairo_surface_t *) graph->choice, 0, 0);
572 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
573 cairo_rectangle(cr, ((XExposeEvent*)event)->x, ((XExposeEvent*)event)->y, ((XExposeEvent*)event)->width, ((XExposeEvent*)event)->height);
579 w = ((XButtonEvent*)event)->x; h = ((XButtonEvent*)event)->y;
582 f = -1; // release indicated by negative button numbers
584 w = ((XButtonEvent*)event)->x; h = ((XButtonEvent*)event)->y;
585 switch(((XButtonEvent*)event)->button) {
586 case Button1: button = 1; break;
587 case Button2: button = 2; break;
588 case Button3: button = 3; break;
589 case Button4: button = 4; break;
590 case Button5: button = 5; break;
594 opt = userHandler(button, w, h);
595 if(opt) { // user callback specifies a context menu; pop it up
596 XUngrabPointer(xDisplay, CurrentTime);
597 XtCallActionProc(widget, "XawPositionSimpleMenu", event, &(opt->name), 1);
598 XtPopupSpringLoaded(opt->handle);
600 XSync(xDisplay, False);
604 GraphExpose (Option *opt, int x, int y, int w, int h)
607 if(!opt->handle) return;
608 e.x = x; e.y = y; e.width = w; e.height = h; e.count = -1; e.type = Expose; // count = -1: kludge to suppress sizing
609 GraphEventProc(opt->handle, (caddr_t) opt, (XEvent *) &e); // fake expose event
613 GenericCallback (Widget w, XtPointer client_data, XtPointer call_data)
614 { // all Buttons in a dialog (including OK, cancel) invoke this
618 int data = (intptr_t) client_data;
620 Widget sh = XtParent(XtParent(XtParent(w))), oldSh;
622 currentOption = dialogOptions[dlg=data>>16]; data &= 0xFFFF;
623 oldSh = shells[dlg]; shells[dlg] = sh; // bow to reality
624 if (data == 30000) { // cancel
627 if (data == 30001) { // save buttons imply OK
628 if(GenericReadout(currentOption, -1)) PopDown(dlg); // calls OK-proc after full readout, but no popdown if it returns false
631 if(currentCps && dlg != BrowserDlg) {
632 XtSetArg(args[0], XtNlabel, &name);
633 XtGetValues(w, args, 1);
634 if(currentOption[data].type == SaveButton) GenericReadout(currentOption, -1);
635 snprintf(buf, MSG_SIZ, "option %s\n", name);
636 SendToProgram(buf, currentCps);
637 } else ((ButtonCallback*) currentOption[data].target)(data);
639 shells[dlg] = oldSh; // in case of multiple instances, restore previous (as this one could be popped down now)
643 TabProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
644 { // for transfering focus to the next text-edit
646 for(opt = currentOption; opt->type != EndMark; opt++) {
647 if(opt->handle == w) {
649 if(opt->type == EndMark) opt = currentOption; // wrap
650 if(opt->handle == w) return; // full circle
651 if(opt->type == TextBox || opt->type == Spin || opt->type == Fractional || opt->type == FileName || opt->type == PathName) {
652 SetFocus(opt->handle, XtParent(XtParent(XtParent(w))), NULL, 0);
661 WheelProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
662 { // for scrolling a widget seen through a viewport with the mouse wheel (ListBox!)
663 int j=0, n = atoi(prms[0]);
664 static char *params[3] = { "", "Continuous", "Proportional" };
668 if(!n) { // transient dialogs also use this for list-selection callback
670 Option *opt=dialogOptions[prms[2][0]-'A'] + n;
671 if(opt->textValue) ((ListBoxCallback*) opt->textValue)(n, SelectedListBoxItem(opt));
674 v = XtNameToWidget(XtParent(w), "vertical");
676 XtSetArg(args[j], XtNshown, &h); j++;
677 XtSetArg(args[j], XtNtopOfThumb, &top); j++;
678 XtGetValues(v, args, j);
679 top += 0.1f*h*n; if(top < 0.f) top = 0.;
680 XtCallActionProc(v, "StartScroll", event, params+1, 1);
681 XawScrollbarSetThumb(v, top, -1.0);
682 XtCallActionProc(v, "NotifyThumb", event, params, 0);
683 // XtCallActionProc(w, "NotifyScroll", event, params+2, 1);
684 XtCallActionProc(v, "EndScroll", event, params, 0);
687 static char *oneLiner =
688 "<Key>Return: redraw-display() \n \
689 <Key>Tab: TabProc() \n ";
690 static char scrollTranslations[] =
691 "<Btn1Up>(2): WheelProc(0 0 A) \n \
692 <Btn4Down>: WheelProc(-1) \n \
693 <Btn5Down>: WheelProc(1) \n ";
696 SqueezeIntoBox (Option *opt, int nr, int width)
697 { // size buttons in bar to fit, clipping button names where necessary
699 Dimension widths[20], oldWidths[20];
701 for(i=1; i<nr; i++) {
702 XtSetArg(arg, XtNwidth, &widths[i]);
703 XtGetValues(opt[i].handle, &arg, 1);
704 wtot += oldWidths[i] = widths[i];
707 if(width <= 0) return;
708 while(wtot > width) {
710 for(i=1; i<nr; i++) if(widths[i] > wmax) wmax = widths[imax=i];
714 for(i=1; i<nr; i++) if(widths[i] != oldWidths[i]) {
715 XtSetArg(arg, XtNwidth, widths[i]);
716 XtSetValues(opt[i].handle, &arg, 1);
722 SetPositionAndSize (Arg *args, Widget leftNeigbor, Widget topNeigbor, int b, int w, int h, int chaining)
723 { // sizing and positioning most widgets have in common
725 // first position the widget w.r.t. earlier ones
726 if(chaining & 1) { // same row: position w.r.t. last (on current row) and lastrow
727 XtSetArg(args[j], XtNfromVert, topNeigbor); j++;
728 XtSetArg(args[j], XtNfromHoriz, leftNeigbor); j++;
729 } else // otherwise it goes at left margin (which is default), below the previous element
730 XtSetArg(args[j], XtNfromVert, leftNeigbor), j++;
731 // arrange chaining ('2'-bit indicates top and bottom chain the same)
732 if((chaining & 14) == 6) XtSetArg(args[j], XtNtop, XtChainBottom), j++;
733 if((chaining & 14) == 10) XtSetArg(args[j], XtNbottom, XtChainTop ), j++;
734 if(chaining & 4) XtSetArg(args[j], XtNbottom, XtChainBottom ), j++;
735 if(chaining & 8) XtSetArg(args[j], XtNtop, XtChainTop), j++;
736 if(chaining & 0x10) XtSetArg(args[j], XtNright, XtChainRight), j++;
737 if(chaining & 0x20) XtSetArg(args[j], XtNleft, XtChainRight), j++;
738 if(chaining & 0x40) XtSetArg(args[j], XtNright, XtChainLeft ), j++;
739 if(chaining & 0x80) XtSetArg(args[j], XtNleft, XtChainLeft ), j++;
740 // set size (if given)
741 if(w) XtSetArg(args[j], XtNwidth, w), j++;
742 if(h) XtSetArg(args[j], XtNheight, h), j++;
744 if(!appData.monoMode) {
745 if(!b && appData.dialogColor[0]) XtSetArg(args[j], XtNbackground, dialogColor), j++;
746 if(b == 3 && appData.buttonColor[0]) XtSetArg(args[j], XtNbackground, buttonColor), j++;
750 XtSetArg(args[j], XtNborderWidth, b); j++;
755 GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent, int modal, int top)
758 Widget popup, layout, dialog=NULL, edit=NULL, form, last, b_ok, b_cancel, previousPane = NULL, textField = NULL, oldForm, oldLastRow, oldForeLast;
760 int x, y, i, j, height=999, width=1, h, c, w, shrink=FALSE, stack = 0, box, chain;
761 int win_x, win_y, maxWidth, maxTextWidth;
763 char def[MSG_SIZ], *msg, engineDlg = (currentCps != NULL && dlgNr != BrowserDlg);
764 static char pane[6] = "paneX";
765 Widget texts[100], forelast = NULL, anchor, widest, lastrow = NULL, browse = NULL;
766 Dimension bWidth = 50;
768 if(dlgNr < PromoDlg && shellUp[dlgNr]) return 0; // already up
769 if(dlgNr && dlgNr < PromoDlg && shells[dlgNr]) { // reusable, and used before (but popped down)
770 XtPopup(shells[dlgNr], XtGrabNone);
771 shellUp[dlgNr] = True;
775 dialogOptions[dlgNr] = option; // make available to callback
776 // post currentOption globally, so Spin and Combo callbacks can already use it
777 // WARNING: this kludge does not work for persistent dialogs, so that these cannot have spin or combo controls!
778 currentOption = option;
780 if(engineDlg) { // Settings popup for engine: format through heuristic
781 int n = currentCps->nrOptions;
782 if(!n) { DisplayNote(_("Engine has no options")); currentCps = NULL; return 0; }
783 if(n > 50) width = 4; else if(n>24) width = 2; else width = 1;
784 height = n / width + 1;
785 if(n && (currentOption[n-1].type == Button || currentOption[n-1].type == SaveButton)) currentOption[n].min = SAME_ROW; // OK on same line
786 currentOption[n].type = EndMark; currentOption[n].target = NULL; // delimit list by callback-less end mark
789 XtSetArg(args[i], XtNresizable, True); i++;
790 shells[BoardWindow] = shellWidget; parents[dlgNr] = parent;
792 if(dlgNr == BoardWindow) popup = shellWidget; else
793 popup = shells[dlgNr] =
794 XtCreatePopupShell(title, !top || !appData.topLevel ? transientShellWidgetClass : topLevelShellWidgetClass,
795 shells[parent], args, i);
798 XtCreateManagedWidget(layoutName, formWidgetClass, popup,
799 layoutArgs, XtNumber(layoutArgs));
800 if(!appData.monoMode && appData.dialogColor[0]) XtSetArg(args[0], XtNbackground, dialogColor);
801 XtSetValues(layout, args, 1);
803 for(c=0; c<width; c++) {
806 XtCreateManagedWidget(pane, formWidgetClass, layout,
807 formArgs, XtNumber(formArgs));
809 XtSetArg(args[j], stack ? XtNfromVert : XtNfromHoriz, previousPane); j++;
810 if(!appData.monoMode && appData.dialogColor[0]) XtSetArg(args[j], XtNbackground, dialogColor), j++;
811 XtSetValues(form, args, j);
812 lastrow = forelast = NULL;
815 last = widest = NULL; anchor = lastrow;
816 for(h=0; h<height || c == width-1; h++) {
818 if(option[i].type == EndMark) break;
819 if(option[i].type == -1) continue;
822 switch(option[i].type) {
824 snprintf(def, MSG_SIZ, "%.2f", *(float*)option[i].target);
825 option[i].value = *(float*)option[i].target;
828 if(!engineDlg) option[i].value = *(int*)option[i].target;
829 snprintf(def, MSG_SIZ, "%d", option[i].value);
834 if(option[i].name[0]) { // prefixed by label with option name
835 j = SetPositionAndSize(args, last, lastrow, 0 /* border */,
836 0 /* w */, textHeight /* h */, 0xC0 /* chain to left edge */);
837 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
838 XtSetArg(args[j], XtNlabel, _(option[i].name)); j++;
839 texts[h] = dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
840 } else texts[h] = dialog = NULL; // kludge to position from left margin
841 w = option[i].type == Spin || option[i].type == Fractional ? 70 : option[i].max ? option[i].max : 205;
842 if(option[i].type == FileName || option[i].type == PathName) w -= 55;
843 j = SetPositionAndSize(args, dialog, last, 1 /* border */,
844 w /* w */, option[i].type == TextBox ? option[i].value : 0 /* h */, 0x91 /* chain full width */);
845 if(option[i].type == TextBox) { // decorations for multi-line text-edits
846 if(option[i].min & T_VSCRL) { XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++; }
847 if(option[i].min & T_HSCRL) { XtSetArg(args[j], XtNscrollHorizontal, XawtextScrollAlways); j++; }
848 if(option[i].min & T_FILL) { XtSetArg(args[j], XtNautoFill, True); j++; }
849 if(option[i].min & T_WRAP) { XtSetArg(args[j], XtNwrap, XawtextWrapWord); j++; }
850 if(option[i].min & T_TOP) { XtSetArg(args[j], XtNtop, XtChainTop); j++;
851 if(!option[i].value) { XtSetArg(args[j], XtNbottom, XtChainTop); j++;
852 XtSetValues(dialog, args+j-2, 2);
855 } else shrink = TRUE;
856 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
857 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
858 XtSetArg(args[j], XtNdisplayCaret, False); j++;
859 XtSetArg(args[j], XtNresizable, True); j++;
860 XtSetArg(args[j], XtNinsertPosition, 9999); j++;
861 XtSetArg(args[j], XtNstring, option[i].type==Spin || option[i].type==Fractional ? def :
862 engineDlg ? option[i].textValue : *(char**)option[i].target); j++;
864 option[i].handle = (void*)
865 (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
866 XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup); // gets focus on mouse click
867 if(option[i].min == 0 || option[i].type != TextBox)
868 XtOverrideTranslations(last, XtParseTranslationTable(oneLiner)); // standard handler for <Enter> and <Tab>
870 if(option[i].type == TextBox || option[i].type == Fractional) break;
872 // add increment and decrement controls for spin
873 if(option[i].type == FileName || option[i].type == PathName) {
874 msg = _("browse"); w = 0; // automatically scale to width of text
875 j = textHeight ? textHeight : 0;
877 w = 20; msg = "+"; j = textHeight/2; // spin button
879 j = SetPositionAndSize(args, last, edit, 3 /* border */,
880 w /* w */, j /* h */, 0x31 /* chain to right edge */);
881 edit = XtCreateManagedWidget(msg, commandWidgetClass, form, args, j);
882 XtAddCallback(edit, XtNcallback, SpinCallback, (XtPointer)(intptr_t) i + 256*dlgNr);
883 if(w == 0) browse = edit;
885 if(option[i].type != Spin) break;
887 j = SetPositionAndSize(args, last, edit, 3 /* border */,
888 20 /* w */, textHeight/2 /* h */, 0x31 /* chain to right edge */);
889 XtSetArg(args[j], XtNvertDistance, -1); j++;
890 last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j);
891 XtAddCallback(last, XtNcallback, SpinCallback, (XtPointer)(intptr_t) i + 256*dlgNr);
894 if(!engineDlg) option[i].value = *(Boolean*)option[i].target; // where checkbox callback uses it
895 j = SetPositionAndSize(args, last, lastrow, 1 /* border */,
896 textHeight/2 /* w */, textHeight/2 /* h */, 0xC0 /* chain both to left edge */);
897 XtSetArg(args[j], XtNvertDistance, (textHeight+2)/4 + 3); j++;
898 XtSetArg(args[j], XtNstate, option[i].value); j++;
900 option[i].handle = (void*)
901 (last = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j));
902 j = SetPositionAndSize(args, last, lastrow, 0 /* border */,
903 option[i].max /* w */, textHeight /* h */, 0xC1 /* chain */);
904 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
905 XtSetArg(args[j], XtNlabel, _(option[i].name)); j++;
906 last = XtCreateManagedWidget("label", commandWidgetClass, form, args, j);
907 // make clicking the text toggle checkbox
908 XtAddEventHandler(last, ButtonPressMask, False, CheckCallback, (XtPointer)(intptr_t) i + 256*dlgNr);
909 shrink = TRUE; // following buttons must get text height
912 msg = option[i].name;
914 chain = option[i].min;
915 if(chain & SAME_ROW) forelast = lastrow; else shrink = FALSE;
916 j = SetPositionAndSize(args, last, lastrow, (chain & 2) != 0 /* border */,
917 option[i].max /* w */, shrink ? textHeight : 0 /* h */, chain | 2 /* chain */);
919 if(option[i].choice) XtSetArg(args[j], XtNfontSet, *(XFontSet*)option[i].choice), j++;
921 if(option[i].choice) XtSetArg(args[j], XtNfont, (XFontStruct*)option[i].choice), j++;
923 XtSetArg(args[j], XtNresizable, False); j++;
924 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
925 XtSetArg(args[j], XtNlabel, _(msg)); j++;
926 option[i].handle = (void*) (last = XtCreateManagedWidget("label", labelWidgetClass, form, args, j));
927 if(option[i].target) // allow user to specify event handler for button presses
928 XtAddEventHandler(last, ButtonPressMask, False, CheckCallback, (XtPointer)(intptr_t) i + 256*dlgNr);
932 if(option[i].min & SAME_ROW) {
933 chain = 0x31; // 0011.0001 = both left and right side to right edge
935 } else chain = 0, shrink = FALSE;
936 j = SetPositionAndSize(args, last, lastrow, 3 /* border */,
937 option[i].max /* w */, shrink ? textHeight : 0 /* h */, option[i].min & 0xE | chain /* chain */);
938 XtSetArg(args[j], XtNlabel, _(option[i].name)); j++;
939 if(option[i].textValue) { // special for buttons of New Variant dialog
940 XtSetArg(args[j], XtNsensitive, appData.noChessProgram || option[i].value < 0
941 || strstr(first.variants, VariantName(option[i].value))); j++;
942 XtSetArg(args[j], XtNborderWidth, (gameInfo.variant == option[i].value)+1); j++;
944 option[i].handle = (void*)
945 (dialog = last = XtCreateManagedWidget(option[i].name, commandWidgetClass, form, args, j));
946 if(option[i].choice && ((char*)option[i].choice)[0] == '#' && !engineDlg) { // for the color picker default-reset
947 SetColor( *(char**) option[i-1].target, &option[i]);
948 XtAddEventHandler(option[i-1].handle, KeyReleaseMask, False, ColorChanged, (XtPointer)(intptr_t) i-1);
950 XtAddCallback(last, XtNcallback, GenericCallback, (XtPointer)(intptr_t) i + (dlgNr<<16)); // invokes user callback
951 if(option[i].textValue) SetColor( option[i].textValue, &option[i]); // for new-variant buttons
954 j = SetPositionAndSize(args, last, lastrow, 0 /* border */,
955 0 /* w */, textHeight /* h */, 0xC0 /* chain both sides to left edge */);
956 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
957 XtSetArg(args[j], XtNlabel, _(option[i].name)); j++;
958 texts[h] = dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
960 if(option[i].min & COMBO_CALLBACK) msg = _(option[i].name); else {
961 if(!engineDlg) SetCurrentComboSelection(option+i);
962 msg=_(((char**)option[i].choice)[option[i].value]);
965 j = SetPositionAndSize(args, dialog, last, (option[i].min & 2) == 0 /* border */,
966 option[i].max && !engineDlg ? option[i].max : 100 /* w */,
967 textHeight /* h */, 0x91 /* chain */); // same row as its label!
968 XtSetArg(args[j], XtNmenuName, XtNewString(option[i].name)); j++;
969 XtSetArg(args[j], XtNlabel, msg); j++;
971 option[i].handle = (void*)
972 (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j));
973 CreateComboPopup(last, option + i, i + 256*dlgNr, TRUE, -1);
974 values[i] = option[i].value;
977 // Listbox goes in viewport, as needed for game list
978 if(option[i].min & SAME_ROW) forelast = lastrow;
979 j = SetPositionAndSize(args, last, lastrow, 1 /* border */,
980 option[i].max /* w */, option[i].value /* h */, option[i].min /* chain */);
981 XtSetArg(args[j], XtNresizable, False); j++;
982 XtSetArg(args[j], XtNallowVert, True); j++; // scoll direction
984 XtCreateManagedWidget("viewport", viewportWidgetClass, form, args, j);
985 j = 0; // now list itself
986 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
987 XtSetArg(args[j], XtNforceColumns, True); j++;
988 XtSetArg(args[j], XtNverticalList, True); j++;
989 option[i].handle = (void*)
990 (edit = XtCreateManagedWidget("list", listWidgetClass, last, args, j));
991 XawListChange(option[i].handle, option[i].target, 0, 0, True);
992 XawListHighlight(option[i].handle, 0);
993 scrollTranslations[25] = '0' + i;
994 scrollTranslations[27] = 'A' + dlgNr;
995 XtOverrideTranslations(edit, XtParseTranslationTable(scrollTranslations)); // for mouse-wheel
998 j = SetPositionAndSize(args, last, lastrow, 0 /* border */,
999 option[i].max /* w */, option[i].value /* h */, option[i].min /* chain */);
1000 option[i].handle = (void*)
1001 (last = XtCreateManagedWidget("graph", widgetClass, form, args, j));
1002 XtAddEventHandler(last, ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, False,
1003 (XtEventHandler) GraphEventProc, &option[i]); // mandatory user-supplied expose handler
1004 if(option[i].min & SAME_ROW) last = forelast, forelast = lastrow;
1005 option[i].choice = (char**) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, option[i].max, option[i].value); // image buffer
1007 case PopUp: // note: used only after Graph, so 'last' refers to the Graph widget
1008 option[i].handle = (void*) CreateComboPopup(last, option + i, i + 256*dlgNr, TRUE, option[i].value);
1011 if(option[i].min & SAME_ROW) forelast = lastrow;
1012 j = SetPositionAndSize(args, last, lastrow, 0 /* border */,
1013 0 /* w */, 0 /* h */, option[i].min /* chain */);
1014 XtSetArg(args[j], XtNorientation, XtorientHorizontal); j++;
1015 XtSetArg(args[j], XtNvSpace, 0); j++;
1016 option[box=i].handle = (void*)
1017 (last = XtCreateWidget("box", boxWidgetClass, form, args, j));
1018 oldForm = form; form = last; oldLastRow = lastrow; oldForeLast = forelast;
1019 lastrow = NULL; last = NULL;
1022 j = SetPositionAndSize(args, last, lastrow, 0 /* border */,
1023 0 /* w */, 0 /* h */, 1 /* chain (always on same row) */);
1025 msg = _(option[i].name); // write name on the menu button
1026 XtSetArg(args[j], XtNmenuName, XtNewString(option[i].name)); j++;
1027 XtSetArg(args[j], XtNlabel, msg); j++;
1028 option[i].handle = (void*)
1029 (last = XtCreateManagedWidget(option[i].name, menuButtonWidgetClass, form, args, j));
1030 option[i].textValue = (char*) CreateComboPopup(last, option + i, i + 256*dlgNr, FALSE, -1);
1033 XtManageChildren(&form, 1);
1034 SqueezeIntoBox(&option[box], i-box, option[box].max);
1035 if(option[i].target) ((ButtonCallback*)option[i].target)(box); // callback that can make sizing decisions
1036 last = form; lastrow = oldLastRow; form = oldForm; forelast = oldForeLast;
1041 stack = !(option[i].min & SAME_ROW);
1044 printf("GenericPopUp: unexpected case in switch.\n");
1049 // make an attempt to align all spins and textbox controls
1050 maxWidth = maxTextWidth = 0;
1051 if(browse != NULL) {
1053 XtSetArg(args[j], XtNwidth, &bWidth); j++;
1054 XtGetValues(browse, args, j);
1056 for(h=0; h<height || c == width-1; h++) {
1058 if(option[i].type == EndMark) break;
1059 if(option[i].type == Spin || option[i].type == TextBox || option[i].type == ComboBox
1060 || option[i].type == PathName || option[i].type == FileName) {
1062 if(!texts[h]) continue;
1064 XtSetArg(args[j], XtNwidth, &w); j++;
1065 XtGetValues(texts[h], args, j);
1066 if(option[i].type == Spin) {
1067 if(w > maxWidth) maxWidth = w;
1070 if(w > maxTextWidth) maxTextWidth = w;
1071 if(!widest) widest = texts[h];
1075 if(maxTextWidth + 110 < maxWidth)
1076 maxTextWidth = maxWidth - 110;
1077 else maxWidth = maxTextWidth + 110;
1078 for(h=0; h<height || c == width-1; h++) {
1080 if(option[i].type == EndMark) break;
1081 if(!texts[h]) continue; // Note: texts[h] can be undefined (giving errors in valgrind), but then both if's below will be false.
1083 if(option[i].type == Spin) {
1084 XtSetArg(args[j], XtNwidth, maxWidth); j++;
1085 XtSetValues(texts[h], args, j);
1087 if(option[i].type == TextBox || option[i].type == ComboBox || option[i].type == PathName || option[i].type == FileName) {
1088 XtSetArg(args[j], XtNwidth, maxTextWidth); j++;
1089 XtSetValues(texts[h], args, j);
1090 if(bWidth != 50 && (option[i].type == FileName || option[i].type == PathName)) {
1091 int tWidth = (option[i].max ? option[i].max : 205) - 5 - bWidth;
1093 XtSetArg(args[j], XtNwidth, tWidth); j++;
1094 XtSetValues(option[i].handle, args, j);
1100 if(option[i].min & SAME_ROW) { // even when OK suppressed this EndMark bit can request chaining of last row to bottom
1101 for(j=i-1; option[j+1].min & SAME_ROW; j--) {
1102 XtSetArg(args[0], XtNtop, XtChainBottom);
1103 XtSetArg(args[1], XtNbottom, XtChainBottom);
1104 XtSetValues(option[j].handle, args, 2);
1106 if((option[j].type == TextBox || option[j].type == ListBox) && option[j].name[0] == NULLCHAR) {
1107 Widget w = option[j].handle;
1108 if(option[j].type == ListBox) w = XtParent(w); // for listbox we must chain viewport
1109 XtSetArg(args[0], XtNbottom, XtChainBottom);
1110 XtSetValues(w, args, 1);
1113 } else shrink = FALSE, lastrow = last, last = widest ? widest : dialog;
1114 j = SetPositionAndSize(args, last, anchor ? anchor : lastrow, 3 /* border */,
1115 0 /* w */, shrink ? textHeight : 0 /* h */, 0x37 /* chain: right, bottom and use both neighbors */);
1117 if(!(option[i].min & NO_OK)) {
1118 option[i].handle = b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
1119 XtAddCallback(b_ok, XtNcallback, GenericCallback, (XtPointer)(intptr_t) (30001 + (dlgNr<<16)));
1120 if(!(option[i].min & NO_CANCEL)) {
1121 XtSetArg(args[1], XtNfromHoriz, b_ok); // overwrites!
1122 b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
1123 XtAddCallback(b_cancel, XtNcallback, GenericCallback, (XtPointer)(intptr_t) (30000 + (dlgNr<<16)));
1127 XtRealizeWidget(popup);
1128 if(dlgNr != BoardWindow) { // assign close button, and position w.r.t. pointer, if not main window
1129 XSetWMProtocols(xDisplay, XtWindow(popup), &wm_delete_window, 1);
1130 snprintf(def, MSG_SIZ, "<Message>WM_PROTOCOLS: GenericPopDown(\"%d\") \n", dlgNr);
1131 XtAugmentTranslations(popup, XtParseTranslationTable(def));
1132 XQueryPointer(xDisplay, xBoardWindow, &root, &child,
1133 &x, &y, &win_x, &win_y, &mask);
1135 XtSetArg(args[0], XtNx, x - 10);
1136 XtSetArg(args[1], XtNy, y - 30);
1137 XtSetValues(popup, args, 2);
1139 XtPopup(popup, modal ? XtGrabExclusive : XtGrabNone);
1140 shellUp[dlgNr]++; // count rather than flag
1142 if(textField) SetFocus(textField, popup, (XEvent*) NULL, False);
1143 if(dlgNr && wp[dlgNr] && wp[dlgNr]->width > 0) { // if persistent window-info available, reposition
1145 XtSetArg(args[j], XtNheight, (Dimension) (wp[dlgNr]->height)); j++;
1146 XtSetArg(args[j], XtNwidth, (Dimension) (wp[dlgNr]->width)); j++;
1147 XtSetArg(args[j], XtNx, (Position) (wp[dlgNr]->x)); j++;
1148 XtSetArg(args[j], XtNy, (Position) (wp[dlgNr]->y)); j++;
1149 XtSetValues(popup, args, j);
1152 return 1; // tells caller he must do initialization (e.g. add specific event handlers)
1156 /* function called when the data to Paste is ready */
1158 SendTextCB (Widget w, XtPointer client_data, Atom *selection,
1159 Atom *type, XtPointer value, unsigned long *len, int *format)
1161 char buf[MSG_SIZ], *p = (char*) textOptions[(int)(intptr_t) client_data].choice, *name = (char*) value, *q;
1162 if (value==NULL || *len==0) return; /* nothing selected, abort */
1164 strncpy(buf, p, MSG_SIZ);
1165 q = strstr(p, "$name");
1166 snprintf(buf + (q-p), MSG_SIZ -(q-p), "%s%s", name, q+5);
1174 char *p = (char*) textOptions[n].choice;
1175 if(strstr(p, "$name")) {
1176 XtGetSelectionValue(menuBarWidget,
1177 XA_PRIMARY, XA_STRING,
1178 /* (XtSelectionCallbackProc) */ SendTextCB,
1179 (XtPointer) (intptr_t) n, /* client_data passed to PastePositionCB */
1182 } else SendString(p);
1186 SetInsertPos (Option *opt, int pos)
1189 XtSetArg(args[0], XtNinsertPosition, pos);
1190 XtSetValues(opt->handle, args, 1);
1191 // SetFocus(opt->handle, shells[InputBoxDlg], NULL, False); // No idea why this does not work, and the following is needed:
1192 // XSetInputFocus(xDisplay, XtWindow(opt->handle), RevertToPointerRoot, CurrentTime);
1196 TypeInProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
1197 { // can be used as handler for any text edit in any dialog (from GenericPopUp, that is)
1198 int n = prms[0][0] - '0';
1199 Widget sh = XtParent(XtParent(XtParent(w))); // popup shell
1201 if(n<2) { // Enter or Esc typed from primed text widget: treat as if dialog OK or cancel button hit.
1202 int dlgNr; // figure out what the dialog number is by comparing shells (because we must pass it :( )
1203 for(dlgNr=0; dlgNr<NrOfDialogs; dlgNr++) if(shellUp[dlgNr] && shells[dlgNr] == sh)
1204 GenericCallback (w, (XtPointer)(intptr_t) (30000 + n + (dlgNr<<16)), NULL);
1209 HardSetFocus (Option *opt)
1211 XSetInputFocus(xDisplay, XtWindow(opt->handle), RevertToPointerRoot, CurrentTime);