SophiaFramework UNIVERSE 5.3 |
With SophiaFramework, developers can use both the standard BREW events and the extended events for SophiaFramework. Moreover, their own specific events can be defined.
The SophiaFramework equivalent for BREW AEEEvent is defined as SFCEventEnum.
In SophiaFramework, the BREW standard event names such as EVT_KEY and EVT_APP_START are replaced with events of which names start with SF like SFEVT_KEY and SFEVT_APP_START.
The event "Type" used by GUI Framework are of SFCEventEnum event types, "P16" is the first parameter of UInt16 type, "P32" is the second parameter of UInt32 type.
The event type name related with GUI Framework starts with SREVT_.
Table 10.14. Typical Events for Standard BREW
Event Name | Description |
---|---|
SFEVT_APP_START | Application start |
SFEVT_APP_STOP | Application stop |
SFEVT_APP_RESUME | Application resume |
SFEVT_APP_SUSPEND | Application suspend |
SFEVT_KEY | Key input event |
SFEVT_KEY_PRESS | Key press event |
SFEVT_KEY_RELEASE | Key release event |
SFEVT_CHAR | Character input event |
SFEVT_ALARM | Alarm event |
SFEVT_COMMAND | Application specific event |
SFEVT_APP_CONFIG | Application start: indicating config screen |
SFEVT_APP_HIDDEN_CONFIG | Application start: indicating hidden config screen |
SFEVT_APP_MESSAGE | SMS message receiving event |
SFEVT_ASYNC_ERROR | Asynchronous error notificating (only effective with BREW SDK version 2.1 or later) |
SFEVT_APP_TERMINATE | Application terminate (only effective with BREW SDK version 2.1 or later) |
SFEVT_EXIT | BREW exit (only effective with BREW SDK version 2.1 or later) |
SFEVT_USER | User defined event |
Table 10.15. Typical Events for SophiaFramework
Event Types | Description | |||||||
---|---|---|---|---|---|---|---|---|
|
|
|||||||
|
|
|||||||
|
|
|||||||
|
|
|||||||
|
|
|||||||
|
|
|||||||
|
|
|||||||
|
|
Example 10.70. Redraw Forcedly
// get instance of Application class SFRApplicationPtr app(SFRApplication::GetInstance()); // send redrawing event to instance of Application class app->Invoke(SFXEvent(SREVT_RESPONDER_RENDER, SRP16_RENDER_INVOKE, true));
Example 10.71. Redraw the content region
// register content region redrawing handler
RegisterHandler(SREVT_RESPONDER_RENDER,
SRP16_RENDER_CONTENT,
HANDLER_BEFORE,
HANDLER_FUNCTION(OnRenderContent));
Example 10.72. Destroy the responder
SFRButtonControlPtr button; // create and destroy button if ((button = ::new SFRButtonControl(window, SFXRectangle(10, 10, 100, 20), "OK")) != null) { //checking errors in constructor if (button->static_catch() == SFERR_NO_ERROR) { // If no error // send SREVT_RESPONDER_TERMINATE event to destroy button button->Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true)); } else { // if there is error, use delete operator to destroy button ::delete button; }
The events such as application start and stop, suspension, restart, or key input are notified to the appropriate responder by the Tracer.
Then, each event will be automatically processed by the function called Event Handler.
Reference: Tracer
An event handler is declared by using the macro of which name starts with HANDLER_DECLARE_.
The handler name is passed as argument.
Reference: GUI Framework Macros: Macros for Declaring Event Handler
Table 10.16. Macros for Declaring Event Handler (Void type)
Macro | Description |
---|---|
HANDLER_DECLARE_VOIDRENDER | Drawing handler |
HANDLER_DECLARE_VOIDSTART | Application start handler |
HANDLER_DECLARE_VOIDSTOP | Application stop handler |
HANDLER_DECLARE_VOIDRESUME | Resume handler |
HANDLER_DECLARE_VOIDSUSPEND | Suspend handler |
HANDLER_DECLARE_VOIDDIALOG | Dialog handler |
HANDLER_DECLARE_VOIDMENU | Menu handler |
HANDLER_DECLARE_VOIDCONTROL | Control handler |
HANDLER_DECLARE_VOIDVOID | Generic handler |
HANDLER_DECLARE_VOIDEVENT | Generic handler |
Example 10.73. Declare the drawing handler
// define MyWindow class SFMTYPEDEFCLASS(MyWindow) class MyWindow : public SFRTitleWindow { SFMSEALCOPY(MyWindow) public: MyWindow(Void) static_throws; virtual ~MyWindow(Void) // declare drawing handler // handler name is passed as argument HANDLER_DECLARE_VOIDRENDER(OnRenderContent) };
Table 10.17. Macros for Declaring an Event Handler (Bool type)
Macro | Description |
---|---|
HANDLER_DECLARE_BOOLSTART | Application start handler |
HANDLER_DECLARE_BOOLSTOP | Application stop handler |
HANDLER_DECLARE_BOOLRESUME | Resume handler |
HANDLER_DECLARE_BOOLSUSPEND | Suspend handler |
HANDLER_DECLARE_BOOLDIALOG | Dialog handler |
HANDLER_DECLARE_BOOLMENU | Menu handler |
HANDLER_DECLARE_BOOLCONTROL | Control handler |
HANDLER_DECLARE_BOOLVOID | Generic handler |
HANDLER_DECLARE_BOOLEVENT | Generic handler |
Example 10.74. Declare the key handler
// define MyWindow class SFMTYPEDEFCLASS(MyWindow) class MyWindow : public SFRTitleWindow { SFMSEALCOPY(MyWindow) public: MyWindow(Void) static_throws; virtual ~MyWindow(Void) // declare key handler // handler name is passed as argument HANDLER_DECLARE_BOOLEVENT(OnKey) };
By Using the Handler Declaring Macro... | |
---|---|
the pointer to the handler function and the identification number (reference value) are generated. |
An event handler is implemented by using the macro of which name starts with HANDLER_IMPLEMENT_.
1st argument: the class it belongs to, 2nd argument: handler name, 3rd argument: varies according to the handler.
Reference: GUI Framework Macros: Macros for implementing Event Handler
Table 10.18. Macros for Implementing an Event Handler (Void type)
Macro | Description | 1st argument | 2nd argument | 3rd argument |
---|---|---|---|---|
HANDLER_IMPLEMENT_VOIDRENDER | Drawing handler | graphics (graphic object) | none | none |
HANDLER_IMPLEMENT_VOIDSTART | Application start handler | environment | none | none |
HANDLER_IMPLEMENT_VOIDSTOP | Application stop handler | quitable | none | none |
HANDLER_IMPLEMENT_VOIDRESUME | Resume handler | environment | none | none |
HANDLER_IMPLEMENT_VOIDSUSPEND | Suspend handler | reason | info | none |
HANDLER_IMPLEMENT_VOIDDIALOG | Dialog handler | result | dialog (pointer to dialog) | none |
HANDLER_IMPLEMENT_VOIDMENU | Menu handler | result | menu (pointer to menu) | none |
HANDLER_IMPLEMENT_VOIDCONTROL | Control handler | result | control (pointer to control) | none |
HANDLER_IMPLEMENT_VOIDVOID | Generic handler | none | none | none |
HANDLER_IMPLEMENT_VOIDEVENT | Generic handler | event (event object) | none | none |
Example 10.75. Implement the drawing handler
// 1st argument: class it belongs to, 2nd argument: handler name, 3rd argument: graphic object HANDLER_IMPLEMENT_VOIDRENDER(MyWindow, OnRenderContent, graphics) { // draw "Hello World" graphics->DrawText("Hello World", GetContentWorld()); return; }
Table 10.19. Macros for Implementing an Event Handler (Bool type)
Macro | Description | 1st argument | 2nd argument | 3rd argument |
---|---|---|---|---|
HANDLER_IMPLEMENT_BOOLSTART | Application start | environment | none | none |
HANDLER_IMPLEMENT_BOOLSTOP | Application stop | quitable | none | none |
HANDLER_IMPLEMENT_BOOLRESUME | Resume handler | environment | none | none |
HANDLER_IMPLEMENT_BOOLSUSPEND | suspend handler | reason | info | none |
HANDLER_IMPLEMENT_BOOLDIALOG | Dialog handler | result | dialog (pointer to dialog) | none |
HANDLER_IMPLEMENT_BOOLMENU | Menu handler | result | menu (pointer to menu) | none |
HANDLER_IMPLEMENT_BOOLCONTROL | Control handler | result | control (pointer to control) | none |
HANDLER_IMPLEMENT_BOOLVOID | Generic handler | none | none | none |
HANDLER_IMPLEMENT_BOOLEVENT | Generic handler | event (event object) | none | none |
Example 10.76. Implement the key handler
// a key is pressed on topmost window. // 1st argument: class it belongs to, 2nd argument: handler name, 3rd argument: event value HANDLER_IMPLEMENT_BOOLEVENT(MyWindow, OnKey, event) { // processing according to type of pressed key. switch (event.GetP16()) { case AVK_CLR: // if "Clear" key has been pressed // close window return Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true)); case AVK_1: // if "1" key has been pressed ... return true; // if pressed key was processed, return true } return false; // if pressed key was not processed, return false }
An handler is registered by using the RegisterHandler function, and canceled by using the UnregisterHandler function.
If more than one handler functions are registered with the same event, only one handler function registered lastly is effective.
Setting information necessary when registering an event handler
Table 10.20. Timing for event handling
Processing the Event | Description |
---|---|
HANDLER_BEFORE | Handle the event at the Parent Responder, and then dispatch and handle it at the Child Responder. |
HANDLER_AFTER | Dispatch and handle the event at the Child Responder, and then handle it at the Parent Responder. |
Timing for event handling | |
---|---|
When drawing the Responders(UI components), it is necessary to draw them sequentially and recursively from backmost (Parant Responder) to foreground (Child Responders). Therefore, HANDLER_BEFORE is specified as the timing for event handling in registering the drawing handler. As for the key handler, HANDLER_AFTER is specified since the key event need to be handled from topmost (Child Responder) to background (Parant Responder). Since there is order relation between Parent and Child Responders regarding their construction and destruction, HANDLER_BEFORE and HANDLER_AFTER are specified when registering the handlers for the resume and suspend events respectively. Also as for the start and end events of application, HANDLER_BEFORE and HANDLER_AFTER are specified respectively for the same reason. |
Example 10.78. Register the handler that is processed before dispatching the event to the child Responder
SFRResponderPtr responder; SFCError error; error = responder->RegisterHandler(SREVT_CONTROL, HANDLER_BEFORE, HANDLER_FUNCTION(OnControl));
Example 10.79. Register the handler that is processed after dispatching the event to the child Responder and receiving it from the child Responder
SFRResponderPtr responder; SFCError error; error = responder->RegisterHandler(SFEVT_KEY, SFEVT_KEY_RELEASE, AVK_SELECT, HANDLER_AFTER, HANDLER_FUNCTION(OnKey));
Role of HANDLER_FUNCTION | |
---|---|
By making the argument of HANDLER_DECLARE_????? macro be that of HANDLER_FUNCTION macro, the pointer to the handler function and the handler identification number (reference value) are passed to the RegisterHandler function. |
The code below describes how to make the key event handler be handled with doing nothing.
Example 10.80. Make the key handler as if it were handled with doing nothing
SFRResponderPtr responder; SFCError error; error = responder->RegisterHandler(SFEVT_KEY, SFEVT_KEY_RELEASE, HANDLER_BEFORE, HANDLER_NULL);
Warning | |
---|---|
The Tracer setting also has the influence on whether this key event handler will be handled or not. |
The handler registered lastly is effective. The behaviors of the following two codes are different.
Example 10.81. Register the key handlers (1)
SFRResponderPtr responder; responder->RegisterHandler(SFEVT_KEY, HANDLER_AFTER, HANDLER_FUNCTION(OnKey)); responder->RegisterHandler(SFEVT_KEY, SFEVT_KEY_RELEASE, HANDLER_AFTER, HANDLER_FUNCTION(OnHeld1)); responder->RegisterHandler(SFEVT_KEY, SFEVT_KEY_RELEASE, HANDLER_AFTER, HANDLER_FUNCTION(OnHeld2));
Example 10.82. Register the key handlers (2)
SFRResponderPtr responder; responder->RegisterHandler(SFEVT_KEY, SFEVT_KEY_RELEASE, HANDLER_AFTER, HANDLER_FUNCTION(OnHeld1)); responder->RegisterHandler(SFEVT_KEY, SFEVT_KEY_RELEASE, HANDLER_AFTER, HANDLER_FUNCTION(OnHeld2)); responder->RegisterHandler(SFEVT_KEY, HANDLER_AFTER, HANDLER_FUNCTION(OnKey));
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |