PrevNextUpHome SophiaFramework UNIVERSE 5.3

9.15. Dialog(Applied)

The methods to get the suitable size for a dialog region and close the dialog automatically after the specified period are described here.

9.15.1. Obtaining the Suitable Size for a Dialog

In SFZMessageDialog and SFZQuestionDialog, the SFYResponder::GetSuitableBound function will behave differently from other responders when the "rectangle" argument is not specified.

In this case, the function will need a hint value to calculate the suitable size of the region for a multiple text message.

Concretely, in this SFYResponder::GetSuitableBound function, the width of real region set with the SFYResponder::SetRealBound function will be used as a hint value if the "rectangle" argument is not specified.

In case of specifying the "rectangle" argument of the SFYResponder::GetSuitableBound function, there is no need to set a real region as a hint value before calculating the suitable size for a dialog.

Whether or not to specify the "rectangle" argument in the SFYResponder::GetSuitableBound function is same as whether or not the hight of the rectangular region of a dialog to be calculated is limited.

Figure 9.43. Execution Result

Execution Result

Example 9.72. Declaration

SFMTYPEDEFCLASS(USRApplication)
class USRApplication: public SFYApplication {
    SFMSEALCOPY(USRApplication)
private:
    SFZMessageDialogSmp _dialog;

    ...
private:
    SFCError Make(Void);
};

Example 9.73. Implementation

SFCError USRApplication::Make(Void)
{
    SFCError error(SFERR_NO_ERROR);

    if ((_dialog = SFZMessageDialog::NewInstance(&error)) != null) {

        error = _dialog->SetParent(GetThis());
        if (error == SFERR_NO_ERROR) {

            error = _dialog->SetIconImage(SFXPath("resource.bar"), IMAGE_ID);
            if (error == SFERR_NO_ERROR) {

                error = _dialog->SetMessageText("hello world\n\n"
                                                "0          \n"
                                                " 1         \n"
                                                "  2        \n"
                                                "   3       \n"
                                                "    4      \n"
                                                "     5     \n"
                                                "      6    \n"
                                                "       7   \n"
                                                "        8  \n"
                                                "         9 \n"
                                                "          0");

                if (error == SFERR_NO_ERROR) {

                    error = _dialog->SetButtonText("OK");
                    if (error == SFERR_NO_ERROR) {

                        // set the real region as the hint value
                        _dialog->SetRealBound(GetLocalBound().Deflate(10, 10));

                        // get the suitable resion size for the dialog without specifying any rectangular region
                        rectangle.Set(_dialog->GetSuitableBound());

                        // place it at the center of the screen
                        rectangle.SnapCenterMiddle(GetLocalBound().GetCenterMiddle());

                        // set the dialog's real region to it
                        _dialog->SetRealBound(rectangle);


                        // set the dialog's state to "visible" + "active" + "enable" + "focus" together
                        _dialog->SetState(true, true, true, true);

                        // move the dialog foremost
                        _dialog->ToFront();
                    }
                }
            }
        }
    }

    return error;
}

9.15.2. Using the Timer of a Dialog

Figure 9.44. Execution Result

Execution Result

Using the timer function of a dialog, you can perform the same dialog operation when the ESCAPE key is pressed after the specified period elapses.

[Note] Note
The default implementation is to close the dialog automatically after the specified period elapses.

The timer can be canceled or rewinded anytime after it starts.

Example 9.74. Declaration

SFMTYPEDEFCLASS(USRApplication)
class USRApplication: public SFYApplication {
    SFMSEALCOPY(USRApplication)
private:
    SFZMessageDialogSmp _dialog;

    ...
private:
    SFCError Make(Void);
};

Example 9.75. Implementation

SFCError USRApplication::Make(Void)
{
    SFCError error(SFERR_NO_ERROR);

    if ((_dialog = SFZMessageDialog::NewInstance(&error)) != null) {

        error = _dialog->SetParent(GetThis());
        if (error == SFERR_NO_ERROR) {

            error = _dialog->SetIconImage(SFXPath("resource.bar"), IMAGE_ID);
            if (error == SFERR_NO_ERROR) {

                error = _dialog->SetMessageText("hello world");
                if (error == SFERR_NO_ERROR) {

                    error = _dialog->SetButtonText("OK");
                    if (error == SFERR_NO_ERROR) {

                        _dialog->SetRealBound(_dialog->GetSuitableBound(GetLocalBound().Deflate(10, 10), SFYResponder::HORIZONTAL_CENTER, SFYResponder::VERTICAL_MIDDLE));
                        _dialog->SetState(true, true, true, true);
                        _dialog->ToFront();

                        // schedule timer that HandleEscapeKey() will be booted up and screen will be redrawn
                        // when neither operation key, ESCAPE key, nor button has been pressed for 10 seconds
                        // * default implementation: close the dialog when neither operation key, ESCAPE key, nor button has been pressed for 10 seconds
                        _dialog->ScheduleTimer(10000);
                    }
                }
            }
        }
    }

    return error;
}
[Note] Timer processing of dialog

With the SFZDialog::ScheduleTimer function, you can control a dialog same as it will handle the ESCAPE key when neither the operation key, the ESCAPE key, nor any button is pressed during the specified time period.

Concretely, when neither the operation key, the ESCAPE key, nor any button has been pressed for the time set with the SFZDialog::ScheduleTimer function elapses, the SFZDialog::HandleEscapeKey function will be called and the screen will be redrawn.

The SFZDialog::HandleEscapeKey function will send the result event [SFXEvent(SFEVT_RESPONDER_RESULT, SFP16_RESULT_ESCAPE, 0)], which will boot up the result handler.

In the above sample code, if the "_dialog->ScheduleTimer(10000);" statement is executed, the result event[SFXEvent(SFEVT_RESPONDER_RESULT, SFP16_RESULT_ESCAPE, 0)] will occur when neither the operation key, the ESCAPE key, nor any button has been pressed for 10 seconds.

The default result handler which will only close this dialog will be booted up since no user-defined result handler is registered.