SetKeyHandler()的流程--SetRightSoftkeyfunction()

设置按键处理的函数使用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;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现ScrollingGraphicalViewer的缩放,你需要使用ZoomManager。以下是一个简单的示例代码: ```java ScrollingGraphicalViewer viewer = new ScrollingGraphicalViewer(); ZoomManager zoomManager = new ZoomManager(viewer.getRootEditPart().getZoomManager(), viewer.getViewport()); zoomManager.setZoomLevels(new double[] { 0.1, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2.0, 3.0, 4.0, 5.0 }); zoomManager.setZoomLevelContributions(Arrays.asList(ZoomManager.FIT_ALL, ZoomManager.FIT_HEIGHT, ZoomManager.FIT_WIDTH)); viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON); viewer.setEditDomain(new DefaultEditDomain(null)); viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer)); viewer.setViewport(new Viewport(true)); viewer.setZoomManager(zoomManager); ``` 上述示例中,我们首先创建了一个ScrollingGraphicalViewer实例,并获取其ZoomManager。然后我们设置了可用的缩放级别以及缩放模式(FIT_ALL,FIT_HEIGHT,FIT_WIDTH)。接着通过MouseWheelZoomHandler实现鼠标滚轮缩放功能,并将其添加到viewer中。最后设置viewer的EditDomain、KeyHandler、Viewport和ZoomManager。 要在拖动Viewpart时通知ScrollingGraphicalViewer的内容重新布局使其一直居中,你需要实现ViewPart中的dragOver方法。以下是一个简单的示例代码: ```java @Override public boolean dragOver(DropTargetEvent event) { if (viewer != null) { Point point = Display.getDefault().map(null, viewer.getControl(), event.x, event.y); viewer.scrollTo(point.x, point.y); return true; } return false; } ``` 上述示例中,我们首先将屏幕坐标转换为viewer坐标。然后调用viewer的scrollTo方法来保持viewer内容在屏幕中心。最后返回true以指示拖放操作已成功处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值