Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!pacbell.com!decwrl!bacchus.pa.dec.com!decprl!decprl!weikart From: weikart@prl.dec.com (Chris Weikart) Newsgroups: comp.windows.x.motif Subject: Re: Blocking actions in Motif and X Keywords: Motif, X, Blocking Message-ID: <1990Jul12.105610.10481@prl.dec.com> Date: 12 Jul 90 10:56:10 GMT References: <858@airgun.wg.waii.com> Sender: news@prl.dec.com (USENET News System) Reply-To: weikart@prl.dec.com (Chris Weikart) Organization: Digital Equipment Corporation - Paris Research Laboratory Lines: 77 In article <858@airgun.wg.waii.com> lampshir@airgun.wg.waii.com (gregory b. lampshir) writes: > ... What I would like to do is use the following code segment > > Boolean answer; > ... > answer = DoNotReturnWithoutAnswer("Do you want to continue?"); > ... > > to return an answer. However, in the event driven environment, even > with the widget's dialog type set to application modal, the func > 'DoNotReturnWithoutAnswer' returns before the user can respond. The > yes/no widget, however, is left displayed waiting for the user in an > event driven manner. There've already been some suggestions posted about libraries you can pick up, but having run into the same problem myself I thought I'd post my solution. First of all, use an XmMessageDialog, which has Ok, Cancel and Help callbacks. Create the dialog, and change Ok/Cancel to Yes/No, and unmanage Help, if that's what you want. Call DialogLoop(your_dialog_widget) to launch the thing modally. Your yes and no callbacks should each set a global (or some user_data) to indicate the answer, then call DialogStop(your_dialog_widget) to allow DialogLoop to exit. So your DoNotReturnWithoutAnswer can look like this: Boolean DoNotReturnWithoutAnswer (message) char *message; { /* create dialog_widget, customize, etc. if not already */ /* install message as text */ DialogLoop(dialog_widget); /* won't return until DialogStop called */ return (value_set_from_callback); } Here's the source for DialogLoop and DialogStop: /* * CMW (Thu Jun 14 17:24:21 1990)... * To be really general purpose and safe, DialogLoop and DialogStop * should accept a pointer to a context that holds the (now global) * DialogLoopControl boolean, as well as an indication that allows * the dialog to be either modal or modeless... */ Static Bool DialogLoopControl; /* global for now... */ Void DialogLoop (Dialog) Widget Dialog; { XtManageChild(Dialog); XtAddGrab(Dialog,TRUE,FALSE); /* hard-wired for now... */ for (DialogLoopControl = True; DialogLoopControl; ) { XEvent event; XtNextEvent(&event); XtDispatchEvent(&event); } } Void DialogStop (Dialog) Widget Dialog; { DialogLoopControl = False; XtRemoveGrab(Dialog); /* hard-wired for now... */ XtUnmanageChild(Dialog); } Have fun, Chris