MsgBox() for dtbuilder stubs routines. - Motif

This is a discussion on MsgBox() for dtbuilder stubs routines. - Motif ; I wanted a "MsgBox" routine to call from DtBuilder (A Solaris gui designer). After gleaning some code from the motif faq, I came up with this. I've seen several posts looking for something like this, but not much response, so ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: MsgBox() for dtbuilder stubs routines.

  1. MsgBox() for dtbuilder stubs routines.

    I wanted a "MsgBox" routine to call from DtBuilder
    (A Solaris gui designer). After gleaning some code
    from the motif faq, I came up with this.

    I've seen several posts looking for something
    like this, but not much response, so thought
    I would post what I've got so others can use it.

    The main difference is the call to (dtlib dpecific)
    to get the app context so the XtMainLoop simulation
    works correctly.

    XtWidgetToApplicationContext(dtb_get_toplevel_widg et());

    regards,
    bl8n8r

    ---------------------------------------------------------------------------

    #include
    #include
    #include
    #include
    #include
    #include
    #include

    /*
    * tmb - this is a modified version of the dialog example from the
    Motif FAQ.
    * I wanted a modal popup dialog I could call from my dtbuilder stubs
    routines,
    * but all the examples I found (so far) have been for straight X
    which
    * assumes you've created the toplevel widget, in the dialog
    application.
    *
    * the main difference between this and the Motif example is the call
    to
    * XtWidgetToApplicationContext(dtb_get_toplevel_widg et()) -- to get
    the
    * app context.
    *
    * Without the app context, you cannot run the XtAppProcessEvent(app,
    XtIMAll)
    * loop which waits for the user to make a choice.
    *
    *
    * to implement this, I do the following:
    *
    * in dtbuilder, add a "Created" Connection to your main window
    * and select "Call Function" for the Action Type.
    * Name the function "Win_Created"
    *
    * build and make your app, exit dtbuilder.
    * Edit the _stubs.c file created by dtbuilder and add a global
    Widget.
    *
    * Widget W_MainWindow = NULL;
    *
    * Save the Widget in the Win_Created() function when it gets called:
    *
    * W_MainWindow = widget;
    *
    * Add the code for the dialog in one of your stub routines:
    *
    * if (Dlg_PopUp (W_MainWindow, "start foobar selection?") == 1)
    * StartFoobar();
    *
    *
    * Add msgbox.c (this file) to your project Makefile undert Targets
    and Objs sections:
    *
    * TARGETS.c = \
    * dtb_utils.c \
    * readdir.c \
    * history.c \
    * msgbox.c \
    * projman_ui.c
    *
    * ...
    *
    *
    * OBJS = \
    * projman.o \
    * dtb_utils.o \
    * readdir.o \
    * history.o \
    * projman_ui.o \
    * msgbox.o \
    * projman_stubs.o
    *
    *
    * build and run.
    *
    */


    #define YES 1
    #define NO 2

    /* response() --The user made some sort of response to the
    * question posed in AskUser(). Set the answer (client_data)
    * accordingly and destroy the dialog.
    */
    void response (Widget w, int *answer, XmAnyCallbackStruct *reason)
    {

    switch (reason->reason)
    {
    case XmCR_OK: // ok button hit
    *answer = YES;
    printf ("Dlg_response(): yes\n");
    break;

    case XmCR_CANCEL: // cancel button hit
    printf ("Dlg_response(): no\n");
    *answer = NO;
    break;
    }


    return;
    }



    /*
    * popup a dialog
    */
    Dlg_PopUp (Widget parent, char *question)
    {
    static Widget dialog;
    static Widget toplevel;
    XmString text, yes, no;
    int answer = 0; // this doesn't work as a static
    extern void response();
    XtAppContext app;

    /*
    * tmb - need app context of dtbuilder app so XtProcessEvent()
    doesn't hurl
    * make sure appropriate headers are included somwhere for
    dtb_get_...
    */
    app = XtWidgetToApplicationContext(dtb_get_toplevel_widg et());


    /*
    * tmb - need app context initialized as well as empty dialog
    widget
    */
    if ((!dialog) && (app))
    {
    dialog = XmCreateQuestionDialog(parent, "Hmmmm", NULL, 0);
    yes = XmStringCreateSimple ("Yes");
    no = XmStringCreateSimple ("No");
    XtVaSetValues (dialog, XmNdialogStyle,
    XmDIALOG_APPLICATION_MODAL, XmNokLabelString, yes,
    XmNcancelLabelString, no, NULL);
    XtSetSensitive (XmMessageBoxGetChild (dialog,
    XmDIALOG_HELP_BUTTON), False);
    XtAddCallback(dialog, XmNokCallback, response, &answer);
    XtAddCallback(dialog, XmNcancelCallback, response, &answer);
    }


    text = XmStringCreateSimple (question);
    XtVaSetValues(dialog, XmNmessageString, text, NULL);
    XmStringFree(text);
    XtManageChild(dialog);

    /* tmb - this must be for non-modality =-->
    XtPopup(XtParent(dialog), XtGrabNone); */
    XtPopup(XtParent(dialog), XtGrabExclusive);
    XtAppProcessEvent(app, XtIMAll);


    /* while the user hasn't provided an answer, simulate XtMainLoop.
    * The answer changes as soon as the user selects one of the
    * buttons and the callback routine changes its value. Don't
    * break loop until XtPending() also returns False to assure
    * widget destruction.
    */
    while (answer == 0 || XtAppPending(app))
    XtAppProcessEvent(app, XtIMAll);

    printf ("answer:%d\n", answer);

    // tmb - return choice user made
    return (answer);
    }

  2. Re: MsgBox() for dtbuilder stubs routines.

    DtBuilder is pretty much dead (I don't think it ever supported C++). It also
    never attracted much of a following, hence the lack of responses to your
    questions.

    Unless you're using it because the price is right (it costs $0), you might
    want to look at a supported Motif gui builder. You can download a free eval
    of ours at: www.ics.com/getbxpro

    Cheers,

    Mark

    "bad_knee" wrote in message
    news:e817ca4d.0309180312.7e8bdddc@posting.google.c om...
    > I wanted a "MsgBox" routine to call from DtBuilder
    > (A Solaris gui designer). After gleaning some code
    > from the motif faq, I came up with this.
    >
    > I've seen several posts looking for something
    > like this, but not much response, so thought
    > I would post what I've got so others can use it.
    >
    > The main difference is the call to (dtlib dpecific)
    > to get the app context so the XtMainLoop simulation
    > works correctly.
    >
    > XtWidgetToApplicationContext(dtb_get_toplevel_widg et());
    >
    > regards,
    > bl8n8r
    >
    > --------------------------------------------------------------------------

    -
    >
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    >
    > /*
    > * tmb - this is a modified version of the dialog example from the
    > Motif FAQ.
    > * I wanted a modal popup dialog I could call from my dtbuilder stubs
    > routines,
    > * but all the examples I found (so far) have been for straight X
    > which
    > * assumes you've created the toplevel widget, in the dialog
    > application.
    > *
    > * the main difference between this and the Motif example is the call
    > to
    > * XtWidgetToApplicationContext(dtb_get_toplevel_widg et()) -- to get
    > the
    > * app context.
    > *
    > * Without the app context, you cannot run the XtAppProcessEvent(app,
    > XtIMAll)
    > * loop which waits for the user to make a choice.
    > *
    > *
    > * to implement this, I do the following:
    > *
    > * in dtbuilder, add a "Created" Connection to your main window
    > * and select "Call Function" for the Action Type.
    > * Name the function "Win_Created"
    > *
    > * build and make your app, exit dtbuilder.
    > * Edit the _stubs.c file created by dtbuilder and add a global
    > Widget.
    > *
    > * Widget W_MainWindow = NULL;
    > *
    > * Save the Widget in the Win_Created() function when it gets called:
    > *
    > * W_MainWindow = widget;
    > *
    > * Add the code for the dialog in one of your stub routines:
    > *
    > * if (Dlg_PopUp (W_MainWindow, "start foobar selection?") == 1)
    > * StartFoobar();
    > *
    > *
    > * Add msgbox.c (this file) to your project Makefile undert Targets
    > and Objs sections:
    > *
    > * TARGETS.c = \
    > * dtb_utils.c \
    > * readdir.c \
    > * history.c \
    > * msgbox.c \
    > * projman_ui.c
    > *
    > * ...
    > *
    > *
    > * OBJS = \
    > * projman.o \
    > * dtb_utils.o \
    > * readdir.o \
    > * history.o \
    > * projman_ui.o \
    > * msgbox.o \
    > * projman_stubs.o
    > *
    > *
    > * build and run.
    > *
    > */
    >
    >
    > #define YES 1
    > #define NO 2
    >
    > /* response() --The user made some sort of response to the
    > * question posed in AskUser(). Set the answer (client_data)
    > * accordingly and destroy the dialog.
    > */
    > void response (Widget w, int *answer, XmAnyCallbackStruct *reason)
    > {
    >
    > switch (reason->reason)
    > {
    > case XmCR_OK: // ok button hit
    > *answer = YES;
    > printf ("Dlg_response(): yes\n");
    > break;
    >
    > case XmCR_CANCEL: // cancel button hit
    > printf ("Dlg_response(): no\n");
    > *answer = NO;
    > break;
    > }
    >
    >
    > return;
    > }
    >
    >
    >
    > /*
    > * popup a dialog
    > */
    > Dlg_PopUp (Widget parent, char *question)
    > {
    > static Widget dialog;
    > static Widget toplevel;
    > XmString text, yes, no;
    > int answer = 0; // this doesn't work as a static
    > extern void response();
    > XtAppContext app;
    >
    > /*
    > * tmb - need app context of dtbuilder app so XtProcessEvent()
    > doesn't hurl
    > * make sure appropriate headers are included somwhere for
    > dtb_get_...
    > */
    > app = XtWidgetToApplicationContext(dtb_get_toplevel_widg et());
    >
    >
    > /*
    > * tmb - need app context initialized as well as empty dialog
    > widget
    > */
    > if ((!dialog) && (app))
    > {
    > dialog = XmCreateQuestionDialog(parent, "Hmmmm", NULL, 0);
    > yes = XmStringCreateSimple ("Yes");
    > no = XmStringCreateSimple ("No");
    > XtVaSetValues (dialog, XmNdialogStyle,
    > XmDIALOG_APPLICATION_MODAL, XmNokLabelString, yes,
    > XmNcancelLabelString, no, NULL);
    > XtSetSensitive (XmMessageBoxGetChild (dialog,
    > XmDIALOG_HELP_BUTTON), False);
    > XtAddCallback(dialog, XmNokCallback, response, &answer);
    > XtAddCallback(dialog, XmNcancelCallback, response, &answer);
    > }
    >
    >
    > text = XmStringCreateSimple (question);
    > XtVaSetValues(dialog, XmNmessageString, text, NULL);
    > XmStringFree(text);
    > XtManageChild(dialog);
    >
    > /* tmb - this must be for non-modality =-->
    > XtPopup(XtParent(dialog), XtGrabNone); */
    > XtPopup(XtParent(dialog), XtGrabExclusive);
    > XtAppProcessEvent(app, XtIMAll);
    >
    >
    > /* while the user hasn't provided an answer, simulate XtMainLoop.
    > * The answer changes as soon as the user selects one of the
    > * buttons and the callback routine changes its value. Don't
    > * break loop until XtPending() also returns False to assure
    > * widget destruction.
    > */
    > while (answer == 0 || XtAppPending(app))
    > XtAppProcessEvent(app, XtIMAll);
    >
    > printf ("answer:%d\n", answer);
    >
    > // tmb - return choice user made
    > return (answer);
    > }




  3. Re: MsgBox() for dtbuilder stubs routines.

    "Mark Hatch" wrote in message news:...
    > DtBuilder is pretty much dead (I don't think it ever supported C++). It also
    > never attracted much of a following, hence the lack of responses to your
    > questions.


    Well, not for me it's not. It's quick, dirty and cheap. Just
    the thing for the place I work at. :/

    Oh.. PS: "int answer;" seems to work OK now as "static int".
    > >
    > >
    > >
    > > /*
    > > * popup a dialog
    > > */
    > > Dlg_PopUp (Widget parent, char *question)
    > > {
    > > static Widget dialog;
    > > static Widget toplevel;
    > > XmString text, yes, no;
    > > int answer = 0; // this doesn't work as a static


+ Reply to Thread