SophiaFramework UNIVERSE 5.3 |
In the responder system, the event is handled as follows:
The SFYApplication::HandleEvent function will be called when the applet receives the event from the BREW environment. As shown in the following implementation of the SFYApplication::HandleEvent function, the distributer will be booted up at the first timing point of each event loop with the SFYResponder::Distribute function.
Example 9.22. Implementation of the SFYApplication::HandleEvent function
// virtual function that will be called when the event dispatched from the BREW environment needs to be handled /*protected virtual */Bool SFYApplication::HandleEvent(SFXEventConstRef event) { // here describe the handling of the event dispatched from the BREW environment SFCError error; Bool result(false); // boot up the distributer to distribute the event using the tracer // first of all, the SFYDistributer instance bound with the root will receive the event // then, the event will be distributed to the responders in the responder tree according to the dispatching rules of the tracer // * _root is the root(SFZRoot) if ((error = _root->Distribute(event, &result)) == SFERR_NO_ERROR) { if (event.GetType() != SFEVT_APP_STOP && event.GetType() != SFEVT_APP_SUSPEND)) { // if redrawing is necessary if (IsRenderable()) { // if the screen can be redrawn (i.e., if no highest priority event handler is registered) // boot up the renderer to redraw the responder tree below the root error = _root->Render(); } } } if (error != SFERR_NO_ERROR) { // call HandleError() in case the fatal error such as insufficient memory during the initialization of the distributer or the renderer occurs if (HandleError(event, error)) { result = true; } } if ((event.GetType() == SFEVT_APP_SUSPEND) && IsRendererIntermissive()) { // if the back-up bitmap inside the renderer is released when an application suspends // terminate the renderer _renderer.Terminate(); } return result; // return "true" if the event has been handled, otherwise return "false" }// SFYApplication::HandleEvent //
Reference: SFCApplication::HandleEvent | SFCApplication::IsRenderable | SFCApplication::HandleError | SFYApplication::IsRendererIntermissive | SFYResponder::Distribute | SFYResponder::Render | SFYRenderer::Initialize | SFYRenderer::Terminate | SFZRoot | Root | Tracer | Distributer | Renderer Drawing Event | Drawing Handler | Event Loop
Highest Priority Event Handler | |
---|---|
See the description of the SFCApplication::RegisterBypass function. |
From the applet boot-up to its termination, a variety of events such as bootup, termination, suspend, resume, or key are dispatched from the BREW environment to the applet.
In the applet, the event-driven operation to receive and handle each event is repeated in the applet.
The following figure shows the typical life cycle of the applet.
Immediately after the user boots up the applet, the instance of the application class inheriting from SFYApplication will be created in the applet.
This application instance will make the root(SFZRoot) bound with the distributer and the renderer in itself.
Next, the SFEVT_APP_START event will be dispatched from the BREW environment to the applet, and the applet initialization will begin.
Note | |
---|---|
Initialization processing such as creating a window is executed in the constructor of the application class or the handler for the SFEVT_APP_START event. |
When the user terminates the applet by selecting the QUIT option in the menu or by pressing the POWER key, the SFEVT_APP_NO_CLOSE event is dispatched from the BREW environment to the applet.
When this event is received, the applet must return "false" to terminate itself(i.e., if "true" is returned, the applet will not terminate).
Then the SFEVT_APP_STOP event will be dispatched from the BREW environment to the applet, and the applet will begin to terminate.
If theevent handling on the SFEVT_APP_STOP event finishes normally, the distributer, the renderer, and the responders such as a window or the root will be released, and the application instance itself will be also automatically released.
Note | |
---|---|
Finalization such as destroying a window is executed in the destructor of the application class or the handler for the SFEVT_APP_STOP event. |
The tracer manages the rules to dispatch the event to the appropriate responders.
The default dispatching rules are registered into the distributer of the responder system as the standard tracer.
If the tracer is not changed explicitly, the event will be dispatched according to the dispatching rules of the standard tracer. And the responder inherits the tracer rules from its parent responder.
Customizing the standard tracer | |
---|---|
In general, the default settings are enough. There is no need to customize the standard tracer in almost all applet developments. |
Three elements of the dispatching rule to register into the tracer are as follows:
Distributing condition
For the distributing condition, specify the state of the responder where the event will be dispatched.
One of the following can be specifiled:
The key event is dispatched to the focused responders since distributing condition is set to "Focus[SFYTracer::STATE_FOCUS]".
The bootup, termination, suspend, or resume event for the applet is dispatched to all responders since the distributing condition is set to "All[SFYTracer::STATE_ALL]".
Method to receive the BREW-defined event whose dispatching rule is registered into the standard tracer with "distributing condition: None[SFYTracer::STATE_NONE]" | |
---|---|
The BREW-defined event whose dispatching rule is registered into the standard tracer with "distributing condition: None[SFYTracer::STATE_NONE] will be distributed to no responder including the root(SFZRoot) which the SFYApplication class contains by default. This is because the rules of the standard tracer are registered into the SFYDistributer instance. To receive this event, you have to register its handler directly into the SFYDistributer instance as follows:
|
Processing order
For the processing order, specify the priority order to boot up handlers.
One of the following can be specifiled:
Overloading condition
For the overloading condition, specify whether or not the handler processes an event duplicately.
One of the following can be specifiled:
The key event is set to "from foreground to background [SFYTracer::ORDER_FORWARD]" for the Processing order. Therefore, it will be processed by the handlers of focused responders from foreground to background. If more than one handler are registered into the same responder, they will be booted up in the reverse order to be registered. Since it is set to "No" for the Overloading condition, the event handling ends there if the event is handled by the handler.
The SFEVT_APP_RESUME event is set to "from background to foreground [SFYTracer::ORDER_BACKWARD]" for the Processing order. Therefore, it will be processed by the handlers of focused responders from background to foreground. If more than one handler are registered into the same responder, they will be booted up in the reverse order to be registered. Since it is set to "Yes" for the Overloading condition, the next handler, if any, will be booted up after the event is processed by the handler.
Settings of the standard tracer
The standard tracer is set as follows:
Table 9.3. Standard tracer
Event type | Distributing condition | Processing order | Overloading condition |
---|---|---|---|
SFEVT_APP_START | All | from background to foreground | Yes |
SFEVT_APP_STOP | All | from foreground to background | Yes |
SFEVT_APP_RESUME | All | from background to foreground | Yes |
SFEVT_APP_SUSPEND | All | from foreground to background | Yes |
from SFEVT_APP_CONFIG to SFEVT_APP_START_WINDOW | No | from foreground to background | No |
from SFEVT_KEY to SFEVT_KEY_HOOK_RELEASE | Focus | from foreground to background | No |
from SFEVT_COMMAND to SFEVT_CTL_TEXT_MODECHANGED | Focus | from foreground to background | No |
from SFEVT_DIALOG_INIT to SFEVT_COPYRIGHT_END | Focus | from foreground to background | No |
from SFEVT_ALARM to SFEVT_NOTIFY_FAILURE | No | from foreground to background | No |
from SFEVT_FLIP to SFEVT_SCR_ROTATE | No | from foreground to background | No |
from SFEVT_CB_CUT to SFEVT_CB_PASTE | No | from foreground to background | No |
Warning | |
---|---|
A BREW-defined event or user-defined event is distributed to the responders according to the tracer rules. A responder-defined event must not be distributed using the tracer. To distribute the user-defined event, register its dispatching rule into the tracer. |
Method to receive the BREW-defined event whose dispatching rule is registered into the standard tracer with "distributing condition: None[SFYTracer::STATE_NONE]" | |
---|---|
The BREW-defined event whose dispatching rule is registered into the standard tracer with "distributing condition: None[SFYTracer::STATE_NONE] will be distributed to no responder including the root(SFZRoot) which the SFYApplication class contains by default. This is because the rules of the standard tracer are registered into the SFYDistributer instance. To receive this event, you have to register its handler directly into the SFYDistributer instance as follows:
|
Example 9.23. Registering the dispatching rule into the tracer
USRResponder::USRResponder(Void) static_throws { if (static_try()) { ... static_throw(RegisterTracer( SFXEventRange(SFEVT_KEY, SFEVT_KEY, AVK_SOFT1, AVK_SOFT4), SFYTracer::ORDER_FORWARD, SFYTracer::STATE_ALL, false )); ... } }
Tip | |
---|---|
A dispatching rule is registerred into the tracer with the SFYResponder::RegisterTracer / SFYDistributer::RegisterTracer function. |
Reference: Tracer | Distributer | Event | Handler
Handler is the function which actually processes an event dispatched to the responder.
With the SFYResponder::RegisterHandler / SFYDistributer::RegisterHandler function, the handler for an event is registered into the responder or the SFYDistributer instance bound with the root(SFZRoot) which the application class contains internally.
For the same event, more than one handler can be registered into the same responder.
For instance, when more than one handler are registered for the SELECT key event of the SFEVT_KEY event type into window, the handler to be registered last will be booted up since its processing order of dispatching rule of the standard tracer is "from foreground to background".
If this handler returns "true", the event handling will end there. On the contrary if it returns "false", the handler to be registered second-to-last will be booted up. Event handling regarding to this window continues until any handler returns "true" or there is no handler to be booted up.
Positional relationship of the handlers | |
---|---|
The handler registered first is placed backmost, and the handler registered last is placed foremost. |
Example 9.24. Registering the handler
USRResponder::USRResponder(Void) static_throws { if (static_try()) { ... static_throw(RegisterHandler( SFXEventRange(SFEVT_KEY, SFEVT_KEY, SFP16_BEGIN, SFP16_END), XANDLER_INTERNAL(OnKey) )); ... } }
Tip | |
---|---|
A handler is registered with the SFYResponder::RegisterHandler function. |
Example 9.25. Implementing the handler
XANDLER_IMPLEMENT_BOOLEVENT(USRResponder, OnKey, invoker, event) { switch (event.GetP16()) { case AVK_SELECT: TRACE("select key was pressed."); return true; case AVK_CLR: TRACE("clear key was pressed."); return true; default: TRACE("unknown key was pressed."); return true; } return false; }
IMPORTANT | |||||
---|---|---|---|---|---|
The handler will return "true" if the event is handled. Otherwise, it will return "false". If some handlers return "true", the responder system will boot up the renderer to redraw the responder tree if necessary.
|
Reference: Handler | Event | SFYResponder::RegisterHandler | SFYDistributer::RegisterHandler
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |