一直想寫一篇有關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)——如何添加一個窗體模板》。
最終實現的是一個字典輸入界面。布局為:
該模板不 包 含業務邏輯,僅提供頁面顯示和InputBox框輸入事件后的ListBox的Redraw事件的注冊,以及基本的輸入法設置、清空后的返回函數。
一、添加用戶自定義列表模板的過程
(一)在g_categories_controls_map[]中加入:
,{ MM I_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_ COO RDINATE_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
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
