PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1

4.3. Developing the SFC Application

The Application class of SFC application inherits from the SFCApplication class.

In the SFC application, the HANDLER_DECLARE macro is not used for declaring a handler function. Instead a handler function is declared in the same way as other functions like the OnKey function.

Example 4.2. Defining the Application class for HelloWorld

//
//      HelloWorld.hpp
//

#ifndef __HELLOWORLD_HPP
#define __HELLOWORLD_HPP

#define TARGET_BUILD_DEBUG
#include <SophiaFramework.hpp>
#include "HelloWorld.bid"

//
//  HelloWorld Application Class
//
SFMTYPEDEFCLASS(HelloWorld)
class HelloWorld : public SFCApplication {
    SFMSEALCOPY(HelloWorld)
public:
    static SFCInvokerPtr Factory(Void);
private:
    HelloWorld(Void);
    virtual ~HelloWorld(Void);
    virtual Bool Invoke(SFXEventConstRef event);
    Bool OnKey(UInt16 key);
};

#endif // __HELLOWORLD_HPP //
[Note] Caution

The Application class of SFR application using the GUI framework; inherits from the SFRApplication class.

Event Handler

The Invoke function is the event handler for SFCApplication. It receives all events, and distributes each event to the appropriate handler function.

The event is transmitted through the argument of Invoke function, and sent to the appropriate handler function according to the event type. For instance a key event causes the key handler to be called.

Implementing the Invoke Function

The event handler of Invoke function is automatically generated by the SophiaFramework AppWizard.

Example 4.3. Implementing the event handler

// Event handler: Invoke function
Bool HelloWorld::Invoke(SFXEventConstRef event)
{
    Bool result(false);

    switch (event.GetType()) {
        case SFEVT_KEY: 
            result = OnKey(event.GetP16());
            break;
    }
    if (!result) {
        result = SFCApplication::Invoke(event);
    }
    return result;
}

Implementing the OnKey Function

The key handler of OnKey function is automatically generated by the SophiaFramework AppWizard.

Example 4.4. Implementing the key handler

// Key handler: OnKey function
Bool HelloWorld::OnKey(UInt16 key)
{
    // processing for key events
    switch (key) {
        case AVK_SELECT: // when "Select" key is pressed
            Terminate(); // terminate application
            return true;
    }
    return false;
}

Implementing the Constructor

Since SFC application is implemented with its own event handler, no event handler functions are registered in the constructor.

Example 4.5. Implementing the Constructor

// Constructor
HelloWorld::HelloWorld(Void) static_throws
{
    return;
}