MTK的DM应用实例

来源:互联网 发布:java分布式框架 编辑:程序博客网 时间:2024/04/28 23:55

一直想写一篇有关DM的文章,一直没有时间。DM是Draw Manager的简称。DM和History机制是MTK窗口设计的两大核心,掌握了DM和History,你就可以随心所欲的对MTK的各种控件如LIST,INPUT,status BAR,TITLE等任意任意组合,创建出符合自己需要的窗口。今天偶读一位网上朋友的文章,对其在DM上的功底十分佩服,借花献佛,共同学习。

文章转自:http://blog.163.com/lyzaily@126/blog/static/4243883720092127125286/

本文详细说明了如何建设一个自定义列表窗体模板。原理部分请参见《MTK平台(1)——如何添加一个窗体模板》。

最终实现的是一个字典输入界面。布局为:

2009年3月12日 - lyzaily@126 - 小坏狗的博客

该模板不含业务逻辑,仅提供页面显示和InputBox框输入事件后的ListBox的Redraw事件的注册,以及基本的输入法设置、清空后的返回函数。

 

一、添加用户自定义列表模板的过程

(一)在g_categories_controls_map[]中加入:

,{MMI_CATEGORY_CUSTOM_LIST,(U8*)custom_define_list,(s16*)coordinate_custom_list,NULL}

 

const U8 custom_define_list[]=

{

    5,                    

    DM_BASE_LAYER_START,

    DM_SCR_BG,

    DM_BASE_CONTROL_SET1,

    DM_SINGLELINE_INPUTBOX1,

    DM_LIST1

};

 

const S16 coordinate_custom_list[]=

{

    DM_FULL_SCREEN_COORDINATE_FLAG,

    DM_CUSTOM_DEFINE_INPUTBOX,                           //需要定义

    DM_CUSTOM_DEFINE_LIST                               //需要定义

};

 

(二)在dm_get_coordinates()函数中加入:

       //设定列表位置和大小(不要忘记全局变量 MMI_custom_Listbox_x 等的定义)

       else if( *UICtrlAccessPtr_p == DM_CUSTOM_DEFINE_LIST )

       {

              dm_coordinate_info->s16X = MMI_custom_Listbox_x;                  

              dm_coordinate_info->s16Y = MMI_custom_Listbox_y;                                 dm_coordinate_info->s16Width = MMI_custom_Listbox_width;    dm_coordinate_info->s16Height =  MMI_custom_Listbox_height;                   

              dm_coordinate_info->Flags = DM_NO_FLAGS;

UICtrlAccessPtr_p ++ ;

       }

//设定输入框位置和大小

       else if( *UICtrlAccessPtr_p == DM_CUSTOM_DEFINE_INPUTBOX )

       {

              dm_coordinate_info->s16X = MMI_custom_inputbox_x ;                     

              dm_coordinate_info->s16Y = MMI_custom_inputbox_y;                      

              dm_coordinate_info->s16Width = MMI_custom_inputbox_width ;            

               dm_coordinate_info->s16Height =  MMI_custom_inputbox_height;                dm_coordinate_info->Flags = DM_SINGLE_LINE_INPUTBOX_SPECIFIC_HEIGHT;

              UICtrlAccessPtr_p ++ ;

       }

      

(三)在Wgui_category.c中定义模板显示函数

void ShowCategoryCustomListScreen(

        U8 *title,

        U16 title_icon,

        U16 left_softkey,

        U16 left_softkey_icon,

        U16 right_softkey,

        U16 right_softkey_icon,

        S32 number_of_items,

        U8 **list_of_items,

        U16 *list_of_icons,

        S32 flags,

        S32 highlighted_item,

        U8 *history_buffer)

{

    /*----------------------------------------------------------------*/

    /* Local Variables                                                */

    /*----------------------------------------------------------------*/

    dm_data_struct dm_data;

    S32 i;

    U8 h_flag;

    /*----------------------------------------------------------------*/

    /* Code Body                                                      */

    /*----------------------------------------------------------------*/

    gdi_layer_lock_frame_buffer();

 

    SetupCategoryKeyHandlers();

    MMI_title_string = (UI_string_type) title;

    MMI_title_icon = (PU8) get_image(title_icon);

   change_left_softkey(left_softkey, left_softkey_icon);

    change_right_softkey(right_softkey, right_softkey_icon);

 

       //Create List     

    create_fixed_icontext_menuitems();

    associate_fixed_icontext_list();

    ShowListCategoryScreen(

        (UI_string_type) title,

        get_image(title_icon),

        get_string(left_softkey),

        get_image(left_softkey_icon),

        get_string(right_softkey),

        get_image(right_softkey_icon),

        number_of_items);

 

    for (i = 0; i < number_of_items; i++)

    {

        add_fixed_icontext_item((UI_string_type) list_of_items[i], wgui_get_list_menu_icon(i, list_of_icons[i]));    

    }

    h_flag = set_list_menu_category_history(MMI_CATEGORY_CUSTOM_LIST, history_buffer);

 

    if (h_flag)

    {

        fixed_list_goto_item_no_redraw(MMI_fixed_list_menu.highlighted_item);

    }

    else

    {

        fixed_list_goto_item_no_redraw(highlighted_item);

    }

       //Create Inputbox

    memset(custom_single_input_buffer,0,100);

    pfnUnicodeStrcpy(custom_single_input_buffer,L"Custom Category");

 

    wgui_setup_singleline_inputbox(

        0,

        0,

        240,

        320,

        custom_single_input_buffer,

        pfnUnicodeStrlen(custom_single_input_buffer),

        MMI_CATEGORY_CUSTOM_LIST,

        get_string(right_softkey),

        get_image(right_softkey_icon),

        INPUT_TYPE_ALPHANUMERIC_LOWERCASE| INPUT_TYPE_USE_ONLY_ENGLISH_MODES,

        history_buffer,

        0);

    register_hide_multitap(wgui_hide_multitap);

    gdi_layer_unlock_frame_buffer();

    ExitCategoryFunction = ExitCategoryCustomListScreen;

    dm_setup_category_functions(dm_redraw_category_screen, dm_get_category_history, dm_get_category_history_size);

    dm_data.s32ScrId = (S32) GetActiveScreenId();

    dm_data.s32CatId = MMI_CATEGORY_CUSTOM_LIST;                    

//不要忘记该常量MMI_CATEGORY_CUSTOM_LIST的定义

    dm_data.s32flags |= DM_CLEAR_SCREEN_BACKGROUND;

    //dm_data.s32flags |= DM_SHOW_VKPAD;   

    dm_register_vkpad_callback(CustomList_virtual_keypad_callback);

    dm_setup_data(&dm_data);

    dm_redraw_category_screen();

}   /* end of ShowCategory353Screen */

 

void CustomList_virtual_keypad_callback(void)

{

#if defined(__MMI_TOUCH_SCREEN__)

    mmi_pen_editor_clear_and_show_virtual_keyboard_area();

#endif

   gui_show_transparent_image(0,200,GetImage(IMG_H_SELECT_LEFT),0);

}

void ExitCategoryCustomListScreen()

{

       wgui_close_singleline_inputbox();

}

 

(四)在singleline_inputbox_multitap_input()函数中添加用户处理key_0~key_9的按键事件的函数:

void (*singleline_inputbox_custom_input_callback) (void) = UI_dummy_function;

void singleline_inputbox_multitap_input(UI_character_type c)

{

    /*----------------------------------------------------------------*/

    /* Local Variables                                                */

    /*----------------------------------------------------------------*/

 

    /*----------------------------------------------------------------*/

    /* Code Body                                                      */

    /*----------------------------------------------------------------*/

    if (MMI_singleline_inputbox.flags & UI_SINGLE_LINE_INPUT_BOX_PLUS_CHARACTER_HANDLING)

    {

        if ((MMI_singleline_inputbox.text[0] == '+') &&

            (MMI_singleline_inputbox.current_text_p == MMI_singleline_inputbox.text) &&

            (MMI_singleline_inputbox.text_length >= (MMI_singleline_inputbox.available_length - ENCODING_LENGTH)))

        {

            return;

        }

    }

    gui_single_line_input_box_insert_multitap_character(&MMI_singleline_inputbox, c);

    redraw_singleline_inputbox();

    singleline_inputbox_input_callback();

    singleline_inputbox_custom_input_callback();

}

 

 

(五)Wgui_Category.c中添加用户事件定义接口

//右键事件注册

void SetCategoryCustomListRightSoftkeyFunction(void (*f) (void))

{

    wgui_singleline_inputbox_RSK_function = f;

}

 

//key_0到key_9按下时的事件注册

extern void (*singleline_inputbox_custom_input_callback) (void);

void SetCategoryCustomListNumKeyFunction(void (*f) (void))

{

       singleline_inputbox_custom_input_callback = f ;

}

 

//设置InputBox大小

void SetCustomList_Inputbox_Size(S32 p_x , S32 p_y , S32 p_width , S32 p_height  )

{

       MMI_custom_inputbox_x = p_x ;

       MMI_custom_inputbox_y = p_y ;

       MMI_custom_inputbox_width = p_width ;

       MMI_custom_inputbox_height = p_height ;

}

//设置ListBox大小

void SetCustomList_Listbox_Size(S32 p_x , S32 p_y , S32 p_width , S32 p_height  )

{

       MMI_custom_Listbox_x = p_x ;

       MMI_custom_Listbox_y = p_y ;

       MMI_custom_Listbox_width = p_width ;

       MMI_custom_Listbox_height = p_height ;

}

 

 

二、自定义列表模板的使用方法

 

1、  调用SetCustomList_Inputbox_Size 和 SetCustomList_Listbox_Size 设置列表框和输入框的大小。

2、  调用显示窗体的接口 ShowCategoryCustomListScreen。

3、  调用右键事件注册函数,注册文本框被清空后的事件(如返回等)SetCategoryCustomListRightSoftkeyFunction。

4、  调用key_0至key_9的事件注册函数,SetCategoryCustomListNumKeyFunction()。

 

 

三、参数详细说明

① void SetCustomList_Inputbox_Size(S32 p_x , S32 p_y , S32 p_width , S32 p_height  ) 与

   void SetCustomList_Listbox_Size(S32 p_x , S32 p_y , S32 p_width , S32 p_height  )

       p_x , p_y :起始位置

       p_width , p_height : 大小。

② void SetCategoryCustomListRightSoftkeyFunction(void (*f) (void))

   void SetCategoryCustomListNumKeyFunction(void (*f) (void))

   f(void) :函数地址。

③ void ShowCategoryCustomListScreen(

        U8 *title,                                          // 标题文本指针

        U16 title_icon,                                 // 标题图标ID

        U16 left_softkey,                      // 左键文本ID

        U16 left_softkey_icon,                   // 左键图标ID

        U16 right_softkey,                          // 右键文本ID

        U16 right_softkey_icon,                 // 右键图标ID

        U8* custom_single_input_buffer, // Input输入Buffer

        S32 number_of_items,                   // 列表条目数

        U8 **list_of_items,                        // 列表项文本指针数组

        U16 *list_of_icons,                         // 列表项Icon

        S32 highlighted_item,                    // 当前高亮显示的列表条目

        U8 *history_buffer)                        // 历史记录Buffer

 

 

附:所需更改的文件

       wgui.c

       wgui_categories.c

       wgui_draw_manager.c

wgui_inputs.c

wgui.h

wgui_categories_defs.h

wgui_draw_manager.h

CustCoordinate.c

原创粉丝点击