PrevNextUpHome SophiaFramework UNIVERSE 5.3

9.5. Responder(Basic)

SFYResponder is the kernel of the SFY responder system, which is constituted by SFYResponder and responders inheriting from this class.

In case you develop your own user-defined responder class, the more concrete base class than SFYResponder is available, the more easily you can implement it.

For instance, you had better use not SFYResponder but SFYWidget as the base class when you develop the responder with functions such as drawing itself.

In the implementation of your own user-defined class with more functions than drawing itself, more concrete class such as SFYContainer, SFZWindow, or SFZDialog may be used as the base class.

The following is the list of abstract responders which is by default included in the responder system. Any of these classes can be used as the base class when the user-defined responder class is implemented.

Table 9.4. List of abstract responders

Class name Description
SFYResponder Abstract class which represents a responder.
SFYWidget Abstract class which represents a widget.
SFYContainer Abstract class which represents a container.
SFZWindow Abstract class which represents a window.
SFZDialog Abstract class which represents a dialog.
SFYMenu Abstract class which represents a menu.
SFYControl Abstract class which represents a control.
SFYLabelControl Abstract class which represents a label control.
SFYBoxControl Abstract class which represents a box control.
SFYButtonControl Abstract class which represents a button control.
SFYCheckboxControl Abstract class which represents a check box control.
SFYRadiobuttonControl Abstract class which represents a radio button control.
SFYScrollBarControl Abstract class which represents a scroll bar control.
SFYTabControl Abstract class which represents a tab control.
[Note] Standard responders provided with SophiaFramework UNIVERSE

It is a very rare case that you have to implement your own user-defined responder with SFYResponder as the base class. In almost all cases, some of the standard responders provided with SophiaFramework UNIVERSE other than SFYResponder can be used as the base class.

[Important] IMPORTANT

In the concrete responder, the SFYResponder::SetParent, SFYResponder::SetState, and SFYResponder::SetRealBound functions must be always called.

Other functions are optionally called.

9.5.1. Abstract Class that Represents a Responder [SFYResponder]

In SFYResponder, common elements and functions among various responders are implemented by default.

SFYResponder is the most abstract base class to define and implement the user-defined responder class.

The minimum code necessary to make the user-defined responder class is as follows:

Example 9.32. Declaration

SFMTYPEDEFRESPONDER(USRResponder)
class USRResponder: public SFYResponder {
    SFMSEALRESPONDER(USRResponder)
    SFMRESPONDERINSTANTIATEONE(USRResponder, SFYResponder)
public:

    // define responder type
    // small alphabet and symbol must not be used since they are reserved for SophiaFramework UNIVERSE
    enum CodeEnum {
        CODE_TYPE = four_char_code('U', 'R', 'S', 'P')
    };
    SFMTYPEDEFTYPE(CodeEnum)

public:
    static USRResponderSmp NewInstance(SFCErrorPtr exception = null);
protected:
    explicit USRResponder(Void) static_throws;
    virtual ~USRResponder(Void);
};

Example 9.33. Implementation

// constructor
USRResponder::USRResponder(Void) static_throws
{
    if (static_try()) {

        // set the responder type
        SetType(CODE_TYPE);

        // here describe the initialization
    }
}

// destructor
USRResponder::~USRResponder(Void)
{
    // here describe the finalization
}

// function to create instance managed by smart pointer
USRResponderSmp USRResponder::NewInstance(SFCErrorPtr exception)
{
    return static_pointer_cast<USRResponder>(Factory(::new USRResponder, exception));
}
[Caution] The return statement in the constructor or destructor

In general, the return statement should not be written in the constructor and destructor with C++.

The bug has been confirmed in GCC. It is that compiler will freeze if the return statement is written in the constructor or destructor under some particular inheritance relationship.