Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Event handling function

After an application is loaded, it receives all input via events. These events are received by the HandleEvent() function of the application.

When Brew MP passes an event to an applet, the event is handed off to the application's main event handler function, which can handle the event and return, or pass the event to another handler, such as the root container's IWidget interface. In any case, the applet (and subsequently any widgets to which the event was passed) indicates whether it handled the event by returning TRUE (handled) or FALSE (not handled).

Note that as a simple event-driven environment, Brew MP demands that events be handled in a timely manner. An applet is expected to quickly handle the event and return. Some events are required system events that must be handled by the application. System events include application startup and shutdown as well as telephone and SMS interruptions. Failure to handle system events can cause the device to function improperly.

For more information on event handling, see Event handling concepts.

Event handler example

The C Application Wizard creates an event handler function for your application that handles EVT_APP_START, EVT_APP_STOP, EVT_APP_SUSPEND, and EVT_APP_RESUME. You may need to add additional code for these events, or handle additional events such as key presses.

In this example from c_basicapp, code was added to handle left, right, up, and down arrow keys.

static boolean MyApp_HandleEvent(MyApp * pMe, AEEEvent eCode, 
                                 uint16 wParam, uint32 dwParam)
{  
    switch (eCode) {
        // Event to inform app to start, so start-up code is here:
        case EVT_APP_START:                        
	        MyApp_DrawScreen(pMe);  // Draw the screen.
	        return TRUE;

        // Event to inform app to exit, so shut-down code is here:
        case EVT_APP_STOP:
      	    return TRUE;

        // Event to inform app to suspend, so suspend code is here:
        case EVT_APP_SUSPEND:
            return TRUE;

        // Event to inform app to resume, so resume code is here:
        case EVT_APP_RESUME:
            MyApp_DrawScreen(pMe);  // Redraw the screen.
      	    return TRUE;

        // A key was pressed:
        case EVT_KEY:
            switch (wParam)
			         {
               // If the left or right arrow key was pressed:
				           case AVK_LEFT:
				           case AVK_RIGHT:
					              MyApp_Move(pMe,(wParam == AVK_RIGHT ? 1 : -1),0); 
					              return TRUE;
               // If the up or down arrow key was pressed:
				           case AVK_UP:
				           case AVK_DOWN:
					              MyApp_Move(pMe,0,(wParam == AVK_UP ? -1 : 1));
					              return TRUE;	
				           default:
					              return FALSE;
			         }

        // If event wasn't handled here, then break out:
        default:
            break;
    }
    return FALSE; // Event wasn't handled.
}