Common Desktop Environment: Application Builder User's Guide

To Write Code for Modal Messages

If a message is to be displayed modally, use dtb_show_modal_message(). This routine returns a value which indicates which message box button the user has pressed. The value is an enum that is defined in dtb_utils.h:

/*
 * Returns answer value for modal MessageBox
 */ 
typedef enum {
        DTB_ANSWER_NONE,
        DTB_ANSWER_ACTION1,
        DTB_ANSWER_ACTION2,
        DTB_ANSWER_ACTION3,
        DTB_ANSWER_CANCEL,
        DTB_ANSWER_HELP
} DTB_MODAL_ANSWER;

You can then examine the return value (for example via a switch statement) and execute the appropriate piece of code.

Here's an example of displaying a message modally. Say that you have created a simple application, named foo. The project is named foo.bip and consists of one module, foo.bil. The module foo.bil consists of a main window, control pane, and two text fields, one for the user to enter a person's first name and the other to enter the last name. If the user types digits, an error message will be posted, informing the user that digits are not allowed, and giving the user a couple of options. The user can start over, which means the text entered will be erased, or the user can continue, which means that the text entered will be left intact, giving the user discretion as to how to modify the text.

A call-function connection is made for both text fields, which will be called each time the user types something. The function for the first text field will check if the character typed is a digit. If so, it will post the error message modally:

void 
verify_first_nameCB(
     Widget widget,
     XtPointer clientData,
     XtPointer callData 
)
{
     /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
     char                *text = (char *)NULL;
     int                 textlen = 0;
     DTB_MODAL_ANSWER    answer = DTB_ANSWER_NONE;    
     DtbFooMainwindowInfo instance = (DtbFooMainwindowInfo) clientData;
     /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/

     /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
     text = XmTextFieldGetString(widget);
     if ((text != NULL) && (*text != NULL))
     { 
        textlen = strlen(text);
        if (isdigit(text[textlen-1]))
        {
             dtb_foo_message_initialize(&dtb_foo_message);
             answer  dtb_show_modal_message(instance->textfield,
                        &dtb_foo_message, NULL, NULL, NULL);
             switch (answer)
             {
                 case DTB_ANSWER_ACTION1:        /* Start Over */
                     XmTextFieldSetString(widget, "");
                     break;

                 case DTB_ANSWER_ACTION2: /* Continue */
                     break;
             }
        }
     }

      /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/ 
}