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

Developer

resources

Handling events

In a widget-based application, widgets handle key and pointer events. The application's event handling function should do the following:

  1. Handle the EVT_APP_START, EVT_APP_STOP, EVT_APP_SUSPEND, and EVT_APP_RESUME events.
  2. Handle AVK_CLR, which returns the application to the previous screen or ends the application if the main screen is currently displayed.
  3. Handle AVK_UP, AVK_DOWN, AVK_LEFT, and AVK_RIGHT to allow navigation of the screen using the keypad.

    The focus is moved to the next or previous widget, depending on which key was pressed. For more information, see Enabling navigation using the keypad.

    In the example shown below, only AVK_UP and AVK_DOWN are used for navigation.

  4. Call IWidget_HandleEvent() to send all other events to the root container.

    The root container forwards the events to the appropriate widget.

The example code shown below is from c_simple_widget_app_1_0.

switch (eCode) {
      // Event to inform app to start, so start-up code is here:
      case EVT_APP_START:
         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:
         // invalidate so 
         // screen is redrawn
         IRootContainer_Invalidate(pMe->picRoot, NULL, NULL, 0);
			                                                        
         return TRUE;

      case EVT_KEY:
           switch (wParam) {
              case AVK_CLR:
                 // if main screen isn't currently displayed,
                 // go back to the main screen
                 // if main screen is displayed, app terminates
                 if (FALSE == pMe->main_scr) {
                    if (!c_simple_widget_app_MakeMainVisible(pMe)) {
                        return FALSE;
                    }
                    // invalidate so screen is redrawn
                    IRootContainer_Invalidate(pMe->picRoot, NULL, NULL, 0);  
                 }        
                 else {
                    return FALSE;
                 }
                 return TRUE;
              // Up arrow key was pressed:
              case AVK_UP:
                  (void)IWidget_MoveFocus(pMe->piwRoot,
                              (IWidget *)WIDGET_FOCUS_PREV);
		                (void)IWidget_MoveFocus(pMe->piwXYCon,
                              (IWidget *)WIDGET_FOCUS_PREV);
		                break;
              // Down arrow key was pressed:
	             case AVK_DOWN:
                  (void)IWidget_MoveFocus(pMe->piwRoot,
                              (IWidget *)WIDGET_FOCUS_NEXT);
		                (void)IWidget_MoveFocus(pMe->piwXYCon,
                              (IWidget *)WIDGET_FOCUS_NEXT);
		                 break;
              // Left arrow key was pressed:
	             case AVK_LEFT: 
		                break;
              // Right arrow key was pressed:
	             case AVK_RIGHT: 
		                break;
              default:
                 break;
           }
           break;

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

   // pass any unhandled events to the root container
   return IWidget_HandleEvent(pMe->piwRoot, eCode, wParam, dwParam);