PrevNextUpHome SophiaFramework UNIVERSE 5.3

9.17. Frame

The responder inheriting from SFYFrame is called as "Frame".

By attaching a frame to a responder with the SFYResponder::SetFrame function, it is possible to display the responder's frame such as a border and/or a title.

Three kinds of the target responders to which a frame will be attached are as follows:

  1. Windows inheriting from SFZWindow
  2. Dialog inheriting from SFZDialog
  3. Menu inheriting from SFYMenu

There are 3 types of frames as follows:

  1. Plain frame: frame with a shadow only
  2. Flat frame: 2-dimensional frame with a shadow and a border
  3. Bevel frame: 3-dimensional frame with a shadow and a border
[Note] Note
Each frame can have a header with a title.

Figure 9.47. Execution Result (Various frame)


Execution Result (Various frame)

Upper row(from left): Plain frame [SFZPlainFrame], Flat frame [SFZFlatFrame], Bevel frame [SFZBevelFrame]

Lower row(from left): Plain frame with a title [SFZTitlePlainFrame], Flat frame with a title [SFZTitleFlatFrame], Bevel frame with a title [SFZTitleBevelFrame]

Figure 9.48. Bevel frame with a title [SFZTitleBevelFrame]


Bevel frame with a title [SFZTitleBevelFrame]

By attaching a bevel frame with a title to a responder with the SFYResponder::SetFrame function, the responder with the 3-dimensional title frame can be implemented.

Figure 9.49. Bevel frame with a title(Expanded figure)[SFZTitleBevelFrame]


Bevel frame with a title(Expanded figure)[SFZTitleBevelFrame]

How to Use a Frame

  1. Create a instance of a frame by calling the NewInstance function.
  2. Set the flag values of the frame's four states of "visible", "active", "enable", and "focus" to "true" with the SFYResponder::SetState function.
  3. Attach the frame to a responder with the SFYResponder::SetFrame function.
    [Note] Note
    At this time, the frame which is attached to the responder is called as the "attachment-frame". On the other hand, the responder to which the frame is attached is called as the "content-responder".
  4. Set the real region of either of the attachment-frame or the content-responder with the SFYResponder::SetRealBound function.
    [Tip] Tip

    The real region of the other side will be automatically calculated using the frame margin region of the attachment-frame and set.

    Inside the SFYResponder::SetFrame function, the processing that the real region of the attachment-frame will be set to the region obtained by inflating that of the content-responder by the frame margin. Therefore, the setting of the content-responder's real region can be performed before calling the SFYResponder::SetFrame function.

  5. Move the content-responder foremost with the SFYResponder::ToFront function. Then, the attachment-frame will be automatically moved foremost together with it too.
[Tip] Tip
The properties related with the attached responder should not be defined in the user-defined frame class. The frame class defined as such can be attached to a variety of responders.
[Note] Note
For more details on the attachment-frame and the content-responder, see this.

Kinds of the Frame Classes

All frames inherit from the SFYFrame class, which provides functions to calculate the size of frame margin, set the frame with a border and/or a title, and draw itself.

The concrete frame is the part class which can be used as it is in the applet development. On the other hand, the abstract frame is the base class to define and implement the user-defined frame.

Table 9.20. Type of concrete frame

Class name Description
SFZPlainFrame Plain frame.
SFZFlatFrame Flat frame.
SFZBevelFrame Bevel frame.
SFZTitlePlainFrame Plain frame with a title.
SFZTitleFlatFrame Flat frame with a title.
SFZTitleBevelFrame Bevel frame with a title.
[Important] IMPORTANT

In the concrete frame, the SFYResponder::SetState function must be always called. In general, all the states of "visible", "active", "enable", and "focus" will be set to "true".

Other functions are optionally called.

It is highly recommended to attach a frame to a responder with the SFYResponder::SetFrame function.

If the SFYResponder::SetRealBound function of the content-responder is called, the real region of the corresponding attachment-frame will be automatically set. On the other hand, if the SFYResponder::SetRealBound function of the the attachment-frame is called, the real region of the corresponding content-responder will be automatically set.

[Caution] Caution
The SFYResponder::SetParent of the attachment-frame cannot be called. And, a frame with no parent should be specified in the argument of the SFYResponder::SetFrame function.

Table 9.21. Type of abstract frame

Class name Description
SFYFrame Abstract class which represents a frame.
SFYPlainFrame Abstract class which represents a plain frame.
SFYFlatFrame Abstract class which represents a flat frame.
SFYBevelFrame Abstract class which represents a bevel frame.

Example 9.82. Declaration

SFMTYPEDEFCLASS(USRApplication)
class USRApplication: public SFYApplication {
    SFMSEALCOPY(USRApplication)
private:

    SFZTitleBevelFrameSmp _frame;
    SFZMessageDialogSmp _dialog;

    // ...

private:
    SFCError MakeFrame(Void);
    SFCError MakeDialog(Void);


    // result handler
    XANDLER_DECLARE_VOIDRESULT(OnResult)
};

Example 9.83. Implementation

// make the frame
SFCError USRApplication::MakeFrame(Void)
{
    SFCError error(SFERR_NO_ERROR);

    // create the bevel frame with title(each frame has different design)
    // other types of frames can be set to a window or a dialog in the same way
    if ((_frame = SFZTitleBevelFrame::NewInstance(&error)) != null) {

        // In general, the frame's state is set to "visible" + "active" + "enable" + "focus".
        _frame->SetState(true, true, true, true);

        // set the other attributes of the frame
        // ...
    }
    if ( error == SFERR_NO_ERROR) {

        // make the dialog to which the frame will be attached
        error = MakeDialog();
    }

    return error;
}

// make the dialog to which the frame will be attached
SFCError USRApplication::MakeDialog(Void)
{
    SFXRectangle rectangle;
    SFXMargin margin;
    SFCError error(SFERR_NO_ERROR);

    // create the dialog
    if ((_dialog = SFZMessageDialog::NewInstance(&error)) != null) {

        // set the dialog's parent responder to the application class(root)
        error = _dialog->SetParent(GetThis());
        if (error == SFERR_NO_ERROR) {

            // attach the frame to the dialog
            error = _dialog->SetFrame(_frame);
            if (error == SFERR_NO_ERROR) {

                // register the result handler into the dialog
                error = _dialog->RegisterHandler(
                               SFXEventRange(SFEVT_RESPONDER_RESULT, SFEVT_RESPONDER_RESULT, SFP16_BEGIN, SFP16_END),
                               XANDLER_INTERNAL(OnResult)
                );
                if (error == SFERR_NO_ERROR) {

                    // set the dialog's message
                    error = _dialog->SetMessageText("in\nSFZTitleBevelFrame\n\nThis is a notification message.");
                    if (error == SFERR_NO_ERROR) {

                        // set the dialog's OK button text
                        error = _dialog->SetButtonText("OK");

                        if (error == SFERR_NO_ERROR) {

                            // set the frame title
                            error = _frame->SetText("SFZTitleBevelFrame");

                            if (error == SFERR_NO_ERROR) {

                                // Calculate the suitable region of the frame within the hint region obtained by deflating the screen device region by (10, 10), 
                                // which will be aligned at the center and the middle of the hint region.
                                // Set the frame's real region to it
                                // * Automatically, the dialog's real region will be set to the region obtained by deflating it by the frame margin.
                                _frame->SetRealBound(_frame->GetSuitableBound(GetLocalBound().Deflate(10, 10), SFYResponder::HORIZONTAL_CENTER, SFYResponder::VERTICAL_MIDDLE));

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

                                // move the dialog foremost
                                // * automatically, the frame will be moved foremost together
                                _dialog->ToFront();
                            }
                        }
                    }
                }
            }
        }
    }

    return error;
}

// result handler
XANDLER_IMPLEMENT_VOIDRESULT(USRApplication, OnResult, invoker, reason, result)
{
    // the dialog will be passed via the invoker argument
    // the P16 value of the result event will be passed via the reason argument
    // "0" will be passed via the result argument

    switch (reason) {

        case SFP16_RESULT_OK:

            // when the OK button or the operation key is pressed

            break;

        case SFP16_RESULT_ESCAPE:

            // when the ESCAPE key is pressed or the time scheduled with ScheduleTimer() elapses

            ...

            break;
    }

    // close the dialog only
    // * automatically, the frame will be detached from the dialog and become invisible
    invoker->Terminate();

    return;
}
[Tip] Tip

If a content-responder is closed with the SFYResponder::Terminate function, the corresponding attachment-frame will be detached from it, become invisible, and restore to the normal frame which can be attached to other responder. There is no need to close the corresponding attachment-frame.