Common Desktop Environment: Application Builder User's Guide

To Write Code for Non-Modal Messages

If you want to post a non-modal message, use dtb_show_message(). Since this function is not modal and does not return a return value, callbacks for the message box buttons should be specified via the Connections Editor, as described in "To Connect a Non-Modal Message to a Function " . The buttons that are specified for the message box are displayed as When items for the message object in the Connections Editor.

Using the same example as above, make the last name text field display the error message non-modally if the user types a digit. As previously mentioned, first you'll need to make a couple of call-function connections for the two buttons in the message box, labelled "Start Over" and "Continue." When code is generated, add code to those routines to do the right thing. The start over routine will clear out the text field and the continue routine will do nothing, in this case.

void 
verify_last_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;    
    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);
            dtb_show_message(instance->textfield,
                        &dtb_foo_message, NULL, NULL);
         }
     }
      /*** DTB_USER_CODE_END  ^^^ Add C code above ^^^ ***/ 
}
void start_overCB(
     Widget widget,
     XtPointer clientData,
     XtPointer callData 
) 
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/

    DtbFooMainwindowInfo instance = (DtbFooMainwindowInfo) clientData;      

   /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
      
   /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
      
   XmTextFieldSetString(dtb_foo_mainwindow.textfield2, "");  

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

}   

void continueCB(
    Widget widget,
    XtPointer clientData,
    XtPointer callData 
) 
{    

    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/      

    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/     
    /*** DTB_USER_CODE_END  ^^^ Add C code above ^^^ ***/ 
}

The two routines above, start_overCB() and continueCB(), are added as callbacks for the two buttons via the call to dtb_show_message(). Here is the code fragment that adds the callback (from dtb_utils.c):

/* Add Callbacks if necessary */

if (mbr->action1_callback != (XtCallbackProc) NULL)
     XtAddCallback(msg_dlg, XmNokCallback, mbr->action1_callback, NULL);     

if (mbr->cancel_callback != (XtCallbackProc) NULL)        

     XtAddCallback(msg_dlg, XmNcancelCallback, mbr->cancel_callback, NULL);    

if (mbr->action2_callback != (XtCallbackProc) NULL)     
{
     action_btn = dtb_MessageBoxGetActionButton(msg_dlg, DTB_ACTION2_BUTTON);
     if (action_btn != NULL)
             XtAddCallback(action_btn, XmNactivateCallback,
                           mbr->action2_callback, NULL);    
}     
if (mbr->action3_callback != (XtCallbackProc) NULL)     
{ 
     action_btn = dtb_MessageBoxGetActionButton(msg_dlg, DTB_ACTION3_BUTTON);     
if (action_btn != NULL)
     XtAddCallback(action_btn, XmNactivateCallback, mbr->action3_callback, NULL);    
}

The structure mbr contains all the necessary information for the message. The structure is filled in with the values specified in the Message Editor when the message object was created via the dtb_&_&_initialize() routine--in this example, dtb_foo_message_initialize().