[Previous] [Contents] [Index] [Next]

PtModalStart()

Initiate modal-window processing

Synopsis:

int PtModalStart ( void );

Description:

This function initiates modal processing. To do so, it holds the current process loop so that another subloop can be started.

Once the subloop is complete, you must call PtModalEnd() to resume processing of the initial process loop.


Note: If you want the parent or any windows in the application to refuse input while the modal dialog is displayed, you need to block them programmatically by setting the Pt_BLOCKED flag.

Returns:

The hold count needed for PtModalEnd().

Examples:

/* Module to handle immediate responses */
#include "imports.h"
#include <Ph.h>
#include <Pt.h>
#include <photon/PtMessage.h>

void
askresponse( PtWidget_t *, int *, PtCallbackInfo_t *);

int AskQuestion( PtWidget_t *parent, char *title, 
                 char *question, char *font, 
                 char *btn1, char *btn2, char *btn3, 
                 int def_btn )
{
    int                    n = 0, block = 1, count;
    int                    answer;
    PtArg_t                args[15];
    PtCallback_t           callback;
    extern struct _Pt_ctrl _Pt_;

    callback.event_f    = askresponse;
    callback.data       = &answer;

    /* initialize answer */
    answer = 0;

    if ( title ) {
        PtSetArg( &args[n], Pt_ARG_MSG_TITLE, 
                  title, 0 ); n++;
    }
    if ( question ) {
        PtSetArg( &args[n], Pt_ARG_MSG_TEXT, 
                  question, 0 ); n++;
    }
    if ( font ) {
        PtSetArg( &args[n], Pt_ARG_MSG_FONT, 
                  font, 0 ); n++;
    }
    if ( btn1 ) {
        PtSetArg( &args[n], Pt_ARG_MSG_BUTTON1, 
                  btn1, 0 ); n++;
    }
    if ( btn2 ) {
        PtSetArg( &args[n], Pt_ARG_MSG_BUTTON2, 
                  btn2, 0 ); n++;
    }
    if ( btn3 ) {
        PtSetArg( &args[n], Pt_ARG_MSG_BUTTON3, 
                  btn3, 0 ); n++;
    }
    PtSetArg( &args[n], Pt_ARG_MSG_DEFAULT, 
              def_btn, 0 ); n++;
    PtSetArg( &args[n], Pt_CB_MSG_BUTTON1, 
              &callback, 0 ); n++;
    PtSetArg( &args[n], Pt_CB_MSG_BUTTON2, 
              &callback, 0 ); n++;
    PtSetArg( &args[n], Pt_CB_MSG_BUTTON3, 
              &callback, 0 ); n++;
    PtRealizeWidget( PtCreateWidget( PtMessage, NULL, 
                                     n, args ) );

    /* loop until response received */
    count = PtModalStart();
    while( !answer )
        PtProcessEvent( );
    PtModalEnd( count );
    
    return( answer );
}

STATIC void askresponse( PtWidget_t *widget,
                         int *answer, 
                         PtCallbackInfo_t *cbinfo )
{
    
    /* get rid of warning */
    widget = widget;

    switch( cbinfo->reason ) {

        case Pt_CB_MSG_BUTTON1:
            *answer = 1;
            break;
                      
        case Pt_CB_MSG_BUTTON2:
            *answer = 2;
            break;
                      
        case Pt_CB_MSG_BUTTON3:
            *answer = 3;
            break;
                      
    }

}

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PtModalEnd(), PtProcessEvent()

"Modal dialogs" in the "Lengthy operations" section of the Interprocess Communication and Lengthy Operations chapter of the Programmer's Guide.


[Previous] [Contents] [Index] [Next]