void BWRequestSelection(Widget w, Time btime, Boolean wait) { BitmapWidget BW = (BitmapWidget) w; if (BW->bitmap.selection.own) BWStore(w); else { XtGetSelectionValue(w, XA_PRIMARY, XA_PIXMAP, SelectionCallback, NULL, btime); BW->bitmap.selection.limbo = TRUE; if (wait) while (BW->bitmap.selection.limbo) { XEvent event; XtNextEvent(&event); XtDispatchEvent(&event); } } }
int X11_Input(REQUEST *request, RESPONSE *response) { XEvent ev; int nfds; fd_set rfds; switch (request->option) { case char_option: nfds = ConnectionNumber(display) > fileno(request->fp) ? ConnectionNumber(display) : fileno(request->fp); for (;;) { /* first read off the queue before doing the select */ while (XtPending()) { XtNextEvent(&ev); XtDispatchEvent(&ev); } /* block on ConnectionNumber and request->fp */ /* PN: added fd_set * casting */ FD_ZERO(&rfds); FD_SET(fileno(request->fp), &rfds); FD_SET(ConnectionNumber(display), &rfds); select (nfds + 1, &rfds, NULL, NULL, NULL); /* handle X events first */ if (FD_ISSET (ConnectionNumber(display), &rfds)) /* handle ALL X events */ while (XtPending()) { XtNextEvent(&ev); XtDispatchEvent(&ev); } if (FD_ISSET (fileno(request->fp), &rfds)) goto out; } break; case click_option: /* let's fake this */ response->reply.graph = lasthardcopy; break; case button_option: /* sit and handle events until get a button selection */ internalerror("button_option not implemented"); response->option = error_option; return 1; break; case checkup_option: /* first read off the queue before doing the select */ while (XtPending()) { XtNextEvent(&ev); XtDispatchEvent(&ev); } break; default: internalerror("unrecognized input type"); response->option = error_option; return 1; break; } out: if (response) response->option = request->option; return 0; }
unsigned long PopupDialog(Dialog popup, String message, String suggestion, String *answer, XtGrabKind grab) { Position popup_x, popup_y, top_x, top_y; Dimension popup_width, popup_height, top_width, top_height, border_width; int n; Arg wargs[4]; n = 0; XtSetArg(wargs[n], XtNlabel, message); n++; XtSetArg(wargs[n], XtNvalue, suggestion); n++; XtSetValues(popup->dialog_widget, wargs, n); XtRealizeWidget(popup->shell_widget); n = 0; XtSetArg(wargs[n], XtNx, &top_x); n++; XtSetArg(wargs[n], XtNy, &top_y); n++; XtSetArg(wargs[n], XtNwidth, &top_width); n++; XtSetArg(wargs[n], XtNheight, &top_height); n++; XtGetValues(popup->top_widget, wargs, n); n = 0; XtSetArg(wargs[n], XtNwidth, &popup_width); n++; XtSetArg(wargs[n], XtNheight, &popup_height); n++; XtSetArg(wargs[n], XtNborderWidth, &border_width); n++; XtGetValues(popup->shell_widget, wargs, n); popup_x = max(0, min(top_x + ((Position)top_width - (Position)popup_width) / 2, (Position)DisplayWidth(XtDisplay(popup->shell_widget), DefaultScreen(XtDisplay(popup->shell_widget))) - (Position)popup_width - 2 * (Position)border_width)); popup_y = max(0, min(top_y + ((Position)top_height - (Position)popup_height) / 2, (Position)DisplayHeight(XtDisplay(popup->shell_widget), DefaultScreen(XtDisplay(popup->shell_widget))) - (Position)popup_height - 2 * (Position)border_width)); n = 0; XtSetArg(wargs[n], XtNx, popup_x); n++; XtSetArg(wargs[n], XtNy, popup_y); n++; XtSetValues(popup->shell_widget, wargs, n); selected = None; XtPopup(popup->shell_widget, grab); XWarpPointer(XtDisplay(popup->shell_widget), XtWindow(popup->top_widget), XtWindow(popup->shell_widget), 0, 0, top_width, top_height, popup_width / 2, popup_height / 2); while ((selected & popup->options) == None) { XEvent event; XtNextEvent(&event); XtDispatchEvent(&event); } PopdownDialog(popup, answer); return (selected & popup->options); }