Solved
Is XtAppAddWorkProc the proper way to launch a Popup at startup? Getting crashes...
Posted on 2004-09-02
When my app starts it reads a user config file and based on the contents of that file may need to launch a dialog to get user inputs before proceeding. In Java I can run initialization blocks which include dialogs prior to launching the main window GUI with .show(). How can I do this in Motif? I tried using XtAppAddWorkProc as in the following code, but what I get is a dialog which pops up and disappears without even waiting for a user response. (All this code runs OK when I don't use the WorkProc).
Widget toplevel;
main (int argc, char *argv[])
{
XtAppContext app;
Widget main_window;
XtSetLanguageProc (NULL, NULL, NULL);
toplevel = XtVaAppInitialize (&app, "App", NULL, 0, &argc, argv, NULL,
XmNtitle, "...",
NULL);
main_window = XtVaCreateManagedWidget ("main_window",
xmMainWindowWidgetClass, toplevel,
NULL);
create_menu_bar (main_window);
create_forms (main_window);
XtRealizeWidget (toplevel);
XtAppAddWorkProc (app, run_startup, (XtPointer) toplevel);
XtAppMainLoop (app);
}
static Boolean run_startup (XtPointer client_data)
{
static done=false;
Widget dialog;
if (!done) {
dialog = XmCreateQuestionDialog (toplevel, "notice", NULL, 0);
XtVaSetValues (dialog,
XmNdialogTitle, XmStringCreateLocalized ("Response"),
XmNmessageString, XmStringCreateLocalized ("Question to user"),
XmNokLabelString, XmStringCreateLocalized ("Yes"),
XmNcancelLabelString, XmStringCreateLocalized ("No"),
NULL);
XtAddCallback (dialog, XmNokCallback, question_cb, NULL);
XtAddCallback (dialog, XmNcancelCallback, question_cb, NULL);
XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
XtManageChild (dialog);
XtPopup (XtParent (dialog), XtGrabNone);
}
done=true;
return True;
}
void question_cb (Widget parent, XtPointer client_data, XtPointer call_data)
{
XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
switch (cbs->reason) {
case XmCR_OK :
strcpy (Ans,"Y");
break;
case XmCR_CANCEL :
strcpy (Ans,"N");
XtPopdown (XtParent (parent));
break;
case XmCR_ACTIVATE :
break;
case XmCR_HELP :
}
}