(转)MTK softkey流程 必看

SetKeyHandler()的流程

设置按键处理的函数使用SetKeyHandler()

这个函数的大概实现如下(精简版哈):

void SetKeyHandler(FuncPtr funcPtr,U16 keyCode,U16 keyType)
{

    currKeyFuncPtrs[keyCode][keyType] = funcPtr;

}

其实就是把函数指针传递到currKeyFuncPtrs【】【】这个二维数组里。

 

然后exec_key_handler()这个函数就从这个数组里面取出对应的函数指针执行。

 

 

static void exec_key_handler(mmi_key_evt_struct *evt_p)//(精简了)
{

    U16 ucs2_value = 0;
    U32 special_key_flag = 0;
    FuncPtr curr_func_ptr;

 

     SetkeyInfo(evt_p->cvt_code, evt_p->mmi_key_type);
    
    if (mmi_frm_dispatch_key_event(evt_p->cvt_code, evt_p->mmi_key_type, ucs2_value, special_key_flag) == MMI_FALSE)
    {                
        /* get the key handler */
        curr_func_ptr = get_key_handler(evt_p->cvt_code, evt_p->mmi_key_type);
    
        /* invoke the key handler */
        if (curr_func_ptr)
        {
                (*curr_func_ptr)();    
        }
     }
  
    /* If finish the key up handler, we reset the current key info. */
    if (evt_p->mmi_key_type == KEY_EVENT_UP)
    {    
        SetkeyInfo(evt_p->cvt_code, MAX_KEY_TYPE);
    }


}

 

static FuncPtr get_key_handler(S16 mmi_key_code, S16 mmi_key_type)
{

    FuncPtr currFuncPtr = NULL;
    S32 i;
    
    for (i = 0; i < SPE_KEY_HDL_TBL_NUM; i++)
    {
        if ((currFuncPtr = (* g_key_handler[i])(mmi_key_code, mmi_key_type)) != NULL)
        {
            break;
        }
    }
    return currFuncPtr;     
}

 

 

const static get_func_ptr g_key_handler[] = 
{
#if defined(__MMI_QWERTY_KEYPAD_SUPPORT__)    
    get_any_key_handler,
#endif
    get_repeat_key_handler,
#ifdef __MMI_WGUI_MINI_TAB_BAR__    
    get_mini_tab_bar_key_handler,
#endif
#ifdef __MMI_SCREEN_SNAPSHOT__    
    get_screen_snapshot_key_handler, 
#endif
#ifdef __LSK_KEYSEND2_IN_ONE__       
/* under construction !*/
#endif
    get_default_key_handler   
};


 

get_default_key_handler   这里面就调用了currKeyFuncPtrs这个数组。流程就是这样的。

 

------------------------------------------------------------------------------------

void SetRightSoftkeyFunction(void (*f) (void), MMI_key_event_type k)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    register_right_softkey_handler
();
    set_right_softkey_function(f, k);
    mmi_imc_key_setup_rsk_function(f);
}

 

 

#define register_right_softkey_handler()            register_softkey_handler(MMI_RIGHT_SOFTKEY)

 

 

 

void register_softkey_handler(WGUI_SOFTKEY_ENUM key)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((MMI_softkeys
[key].text == NULL) && (MMI_softkeys[key].normal_up_icon == NULL))
    {
        return;
    }

    switch (key)
    {
        case MMI_LEFT_SOFTKEY:
            SetKeyHandler(left_softkey_down, KEY_LSK, KEY_EVENT_DOWN);
            SetKeyHandler(left_softkey_up, KEY_LSK, KEY_EVENT_UP);
            left_softkey_keyboard_handler_active = 1;
            break;

        case MMI_RIGHT_SOFTKEY:
            SetKeyHandler(right_softkey_down
, KEY_RSK, KEY_EVENT_DOWN);
            SetKeyHandler(right_softkey_up, KEY_RSK, KEY_EVENT_UP);
            right_softkey_keyboard_handler_active = 1;
            break;

    #ifdef __MMI_WGUI_CSK_ENABLE__
        case MMI_CENTER_SOFTKEY:
            SetKeyHandler(center_softkey_down, KEY_CSK, KEY_EVENT_DOWN);
            SetKeyHandler(center_softkey_up, KEY_CSK, KEY_EVENT_UP);
            center_softkey_keyboard_handler_active = 1;
            break;
    #endif /* __MMI_WGUI_CSK_ENABLE__ */ 
    }
}

这是个按键的结构体

~~

 

 

void right_softkey_down(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!(MMI_softkeys[MMI_RIGHT_SOFTKEY].flags & UI_BUTTON_STATE_CLICKED))
    {
        /* change the state of RSK button */
        MMI_softkeys[MMI_RIGHT_SOFTKEY].flags |= UI_BUTTON_STATE_CLICKED;
        MMI_softkeys[MMI_RIGHT_SOFTKEY].flags |= UI_BUTTON_STATE_DOWN;
        
redraw_softkey(MMI_RIGHT_SOFTKEY);
        execute_softkey_function(KEY_EVENT_DOWN, MMI_RIGHT_SOFTKEY);
    }
}

 

void redraw_softkey(WGUI_SOFTKEY_ENUM key)

{

........

.......

   gdi_layer_lock_frame_buffer();

#if defined(__PWV_UI_BLACKBERRY_STYLE__)
    {
      extern MMI_BOOL g_bMainmenu;
   extern MMI_BOOL g_bCalculator;
   extern MMI_BOOL g_bSmartDial;

        if((g_bMainmenu == MMI_FALSE)&&(g_bCalculator==MMI_FALSE)&&(g_bSmartDial))
        {
            hide_softkey[key] ();
            show_softkey(key);
        }
    }
#else
    hide_softkey[key] ();
    show_softkey(key);
#endif

    gdi_layer_unlock_frame_buffer();

 

........

.........

}

 

 

/*
 * struct of icontext button component.
 */
    typedef struct _icontext_button
    {
    S32 x; /* Is the x position of icontext button */
    S32 y; /* Is the y position of icontext button */
    S32 width; /* Is the width of icontext button */
    S32 height; /* Is the height of icontext button */
    UI_filled_area *normal_up_filler; /* Is the background filler of icontext button in its notmal up state */
    UI_filled_area *normal_down_filler; /* Is the background filler of icontext button in its notmal down state */
    UI_filled_area *disabled_up_filler; /* Is the background filler of icontext button in its disabled up state */
    UI_filled_area *disabled_down_filler; /* Is the background filler of icontext button in its disabled down state */
    UI_filled_area *clicked_up_filler; /* Is the background filler of icontext button in its clicked up state */
    UI_filled_area *clicked_down_filler; /* Is the background filler of icontext button in its clicked down state */
    UI_filled_area *focussed_up_filler; /* Is the background filler of icontext button in its focussed up state */
    UI_filled_area *focussed_down_filler; /* Is the background filler of icontext button in its focussed down state */
    U32 flags; /* Is the flag of icontext button */
    PU8 normal_up_icon; /* Is the icon of icontext button in its normal up state */
    PU8 normal_down_icon; /* Is the icon of icontext button in its normal down state */
    PU8 disabled_up_icon; /* Is the icon of icontext button in its disabled up state */
    PU8 disabled_down_icon; /* Is the icon of icontext button in its disabled down state */
    PU8 clicked_up_icon; /* Is the icon of icontext button in its clicked up state */
    PU8 clicked_down_icon; /* Is the icon of icontext button in its clicked down state */
    PU8 focussed_up_icon; /* Is the icon of icontext button in its focussed up state */
    PU8 focussed_down_icon; /* Is the icon of icontext button in its focussed down state */
    S32 icon_x; /* Is the logical x position of icon */
    S32 icon_y; /* Is the logical y position of icon */
    UI_transparent_color_type icon_transparent_color; /* Is icon's transparent color */
    S32 text_x; /* Is the logical x position of text */
    S32 text_y; /* Is the logical y position of text */

    S32 text_height; /* Is the text's height of icontext button */
    S32 text_width; /* Is the text's width of icontext button */
    UI_string_type text; /* Is the text's content of icontext button */
    color normal_up_text_color; /* Is the text's color of icontext button in its notmal up state */
    color normal_down_text_color; /* Is the text's color of icontext button in its notmal down state */
    color disabled_up_text_color; /* Is the text's color of icontext button in its disabled up state */
    color disabled_down_text_color; /* Is the text's color of icontext button in its disabled down state */
    color focussed_up_text_color; /* Is the text's color of icontext button in its focussed up state */
    color focussed_down_text_color; /* Is the text's color of icontext button in its focussed down state */
    color clicked_up_text_color; /* Is the text's color of icontext button in its clicked up state */
    color clicked_down_text_color; /* Is the text's color of icontext button in its clicked down state */
    color normal_up_text_border_color; /* Is the text border's color of icontext button in its notmal up state */
    color normal_down_text_border_color; /* Is the text border's color of icontext button in its notmal down state */
    color disabled_up_text_border_color; /* Is the text border's color of icontext button in its disabled up state */
    color disabled_down_text_border_color; /* Is the text border's color of icontext button in its disabled down state */
    color focussed_up_text_border_color; /* Is the text border's color of icontext button in its focussed up state */
    color focussed_down_text_border_color; /* Is the text border's color of icontext button in its focussed down state */
    color clicked_up_text_border_color; /* Is the text border's color of icontext button in its clicked up state */
    color clicked_down_text_border_color; /* Is the text border's color of icontext button in its clicked down state */
    UI_font_type text_font; /* Is the text's font size of icontext button */
     /* Is the clear background function handler of icontext button
      * SEE ALSO
      * You should also know gui_button_clear_background_hdlr as well.
      */
        gui_button_clear_background_hdlr clear_background_fp;
    S32 touch_area_x1; /* Is the x position of touch area's left-top corner */
    S32 touch_area_y1; /* Is the y position of touch area's left-top corner */
    S32 touch_area_x2; /* Is the x position of touch area's right-bottom corner */
    S32 touch_area_y2; /* Is the y position of touch area's right-bottom corner */
    S32 display_area_x1; /* Is the x position of display area's left-top corner */
    S32 display_area_y1; /* Is the y position of display area's left-top corner */
    S32 display_area_x2; /* Is the x position of display area's right-bottom corner */
    S32 display_area_y2; /* Is the y position of display area's right-bottom corner */
    #ifdef __MMI_TOUCH_SCREEN__
    /* Is text button's pen state which is supported only in touch projects */
        gui_button_pen_state_struct pen_state;
    /* Is a function handler which displays icontext button in its pen down state */
        gui_button_draw_button_hdlr draw_down_fp;
    /* Is a function handler which displays icontext button in its pen up state */
        gui_button_draw_button_hdlr draw_up_fp;
    #endif /* __MMI_TOUCH_SCREEN__ */
    /* Is the horizontal gap between icontext button's content and its border in X direction */
        S32 horizontal_gap;
    } icontext_button;

猜你喜欢

转载自blog.csdn.net/qq_34810707/article/details/81182730
今日推荐