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

Developer

resources

Enabling virtual input

This topic describes how to enable virtual input in a widget-based application and reposition the virtual input keypad. The example code shown is taken from c_widgetsamplevirtualinput_app.

An application can enable virtual input in a widget-based application as follows:

  1. Include the required header file:
           
    #include "AEEVirtualInputHelpers.h"
  2. After setting up the root container, enable virtual input and retrieve the Virtual Input Manager, as shown below. This code is from c_widgetsamplevirtualinput_app_InitWidgets().
    ERR_TRY( IWidget_EnableVirtualInput(pMe->piwRoot) );       
    ERR_TRY( IWidget_GetVirtualInputMgr(pMe->piwRoot, &pMe->picVirtualInputMgr) );       
    
  3. Create widgets that accept virtual input.

    c_widgetsamplevirtualinput_app_InitWidgets() creates two text widgets and inserts them into the root container, as follows:

    Note: There are no explicit "enable virtual input" calls being made on the individual widgets, because they are automatically enabled when they are inserted in the virtual-input-enabled container tree.

       ERR_TRY( ISHELL_CreateInstance(pMe->pIShell, AEECLSID_CTextWidget,
                   (void**) &piwWidget) );       
       IWidget_GetPreferredExtent(piwWidget, &we);       
       we.width = pMe->nWidth - 10;       
       IWidget_SetExtent(piwWidget, &we);       
           
       // Insert it into RootContainer       
       WidPos.bVisible = TRUE;       
       WidPos.x = 5;       
       WidPos.y = 15;       
       ERR_TRY( IRootContainer_Insert(pMe->picRoot, piwWidget, WIDGET_ZNORMAL,
                 &WidPos) );       
       RELEASEIF(piwWidget);             
           
       // Create second text widget       
       ERR_TRY( ISHELL_CreateInstance(pMe->pIShell, AEECLSID_CTextWidget,
                   (void**) &piwWidget) );       
       IWidget_GetPreferredExtent(piwWidget, &we);       
       we.width = pMe->nWidth - 10;       
       IWidget_SetExtent(piwWidget, &we);       
           
       // Insert it into RootContainer       
       WidPos.y += 30;       
       ERR_TRY( IRootContainer_Insert(pMe->picRoot, piwWidget, WIDGET_ZNORMAL,
                 &WidPos) );       
       RELEASEIF(piwWidget);       
              
    ERRCATCH:       
       return;       
    }       
    

When a text widget is selected, the virtual keypad is displayed:

After the virtual input keypad is displayed, the application can change its position if necessary.

Repositioning the keypad widget

In c_widgetsamplevirtualinput_app_HandleEvent(), the AVK_UP, AVK_DOWN, AVK_LEFT, and AVK_RIGHT key presses are captured and the keypad is repositioned.

  1. Capture AVK_UP, AVK_DOWN, AVK_LEFT, and AVK_RIGHT key presses:
    case EVT_KEY:       
       switch (wParam) {       
          // UP       
          case AVK_UP:       
          case AVK_DOWN:        
          case AVK_LEFT:        
          case AVK_RIGHT: {       
    
  2. Retrieve the previous position hint.
    if (AEE_SUCCESS != IController_GetVirtualInputPositionHint(pMe->picVirtualInputMgr,
                &wph)) {       
       return FALSE;       
    }
  3. Modify the vertical and horizontal constraints, as indicated by the key presses.

    The up and down keys modify the vertical constraint, and the left and right keys modify the horizontal constraint.

    if (AVK_UP == wParam || AVK_DOWN == wParam) {       
        pMod = &wph.yConstraint;       
    }       
    else{       
        pMod = &wph.xConstraint;       
    }       
    

    In c_widgetsamplevirtualinput_app, pressing left when the widget is right-aligned will position it in the middle. Pressing left again will left-align it. Pressing left again will right-align the widget. The diagram below shows all the positions in which the keypad can be positioned.

  4. Set the logical location of the virtual keypad, then call IController_SetVirtualInputPositionHint() to set the position hint for the Virtual Input Manager:
    if (AVK_DOWN == wParam || AVK_RIGHT == wParam) {       
               switch (*pMod) {       
                 case AEEWindowMgrExt_POPUPPOS_LEFT:          
                    *pMod = AEEWindowMgrExt_POPUPPOS_CENTER;        
                     break;       
                  case AEEWindowMgrExt_POPUPPOS_CENTER:        
                    *pMod = AEEWindowMgrExt_POPUPPOS_RIGHT;       
                     break;       
                  case AEEWindowMgrExt_POPUPPOS_RIGHT:         
                    *pMod = AEEWindowMgrExt_POPUPPOS_LEFT;        
                     break;       
                  default:                                     
                    *pMod = AEEWindowMgrExt_POPUPPOS_CENTER;        
                     break;                                  
                }       
             }       
             else{       
               switch (*pMod) {       
                  case AEEWindowMgrExt_POPUPPOS_LEFT:          
                     *pMod = AEEWindowMgrExt_POPUPPOS_RIGHT;        
                      break;       
                  case AEEWindowMgrExt_POPUPPOS_CENTER:        
                     *pMod = AEEWindowMgrExt_POPUPPOS_LEFT;        
                      break;       
                  case AEEWindowMgrExt_POPUPPOS_RIGHT:       
                     *pMod = AEEWindowMgrExt_POPUPPOS_CENTER;       
                      break;       
                  default:                                     
                     *pMod = AEEWindowMgrExt_POPUPPOS_CENTER;        
                      break;       
                }       
             }       
            (void) IController_SetVirtualInputPositionHint(pMe->picVirtualInputMgr,
                        wph);       
            return TRUE;       
             }       
           
            // default       
            default:       
               break;       
            }       
           
       return TRUE;