Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!helios.ee.lbl.gov!pasteur!graft!scott From: scott@graft.Berkeley.EDU (Scott Silvey) Newsgroups: comp.windows.x Subject: Re: Proper modal dialogs using Xt -- can it be done? Message-ID: <26259@pasteur.Berkeley.EDU> Date: 17 Jul 90 00:51:10 GMT References: <1990Jul16.190239.7687@maytag.waterloo.edu> Sender: news@pasteur.Berkeley.EDU Reply-To: scott@xcf.berkeley.edu Distribution: na Organization: UC Berkeley Experimental Computing Facility Lines: 71 X-Local-Date: 16 Jul 90 17:51:10 PDT giguere@csg.UWaterloo.CA (Eric Giguere) writes: |> This question was originally posted in the Motif newsgroup but no one's been |> able to answer it for me so: |> |> I want to create and display a modal dialog created as a widget under Motif. |> That is, after I add callback routines, manage & display the widget, I want |> my main program to wait (without busy-waiting!) until the widget is |> destroyed and not accept input into its main window while the dialog widget |> is being displayed. All the dialog examples I've seen so far that use the |> Xt or Motif widget sets use modeless dialogs. |> |> So, can I do this portably using X or do I have to resort to using system |> calls such as the Unix signalling facility? |> |> -- |> Eric Giguere giguere@csg.UWaterloo.CA You need to go through an event processing loop while the dialog is up. This was far from obvious for me too, perhaps R5 could have a "convenience" routine to pop up a modal dialog. Here is the basic code needed: ------------------------------ Boolean ok=FALSE; ok_button_cback(button, dialog_shell) Widget button, dialog_shell { extern Boolean ok; /* Do useful things here. */ ok = TRUE; XtPopdown(dialog_shell); } prompt() { extern Boolean ok; extern Widget toplevel; XEvent event; Widget dialog_shell, ok_button; dialog_shell = XtCreatePopupShell("Modal Dialog", transientShellWidgetClass, toplevel, NULL, 0); ok_button = XtCreateManagedWidget("OK", commandWidgetClass, dialog_shell, NULL, 0); XtAddCallback(ok_button, XtNcallback, ok_button_cback, dialog_shell); XtPopup(dialog_shell, XtGrabExclusive); while (!ok) { XtAppNextEvent(XtWidgetToApplicationContext(toplevel), &event); XtDispatchEvent(&event); } ok = FALSE; } ----------------------------- Note that this is for R4 Athena widgets. You'll have to tailor the details for your case (probably R3 Motif?). Also, I just typed this in from memory, so I'm not guaranteeing that I didn't forget something here, but the basic idea is demonstrated. I also don't know if perhaps there are other/better ways to approach this problem either, I just know it works for me. Hope this helps. Scott