1. 资源的定义(图片ID、字符串ID、屏幕ID、菜单ID)
/************图片ID定义************/ <IMAGE id="MAIN_MENU_SHOWCTRL_ICON">
CUST_IMG_PATH"\\MainLCD\\MainMenu\\PAGE\\BlackWhite\\MM_GM.gif"
</IMAGE> /**********************************/ /***********字符串ID定义***********/ <STRING id="STR_ID_SHOWCTRL"/> <STRING id="STR_ID_SHOWCTRL_LISTBOX"/> <STRING id="STR_ID_SHOWCTRL_EDITBOX"/> <STRING id="STR_ID_SHOWCTRL_TEXTBOX"/> /**********************************/ /************屏幕ID定义************/ <SCREEN id="SCR_ID_SHOWCTRL"/> <SCREEN id="SCR_ID_SHOWCTRL_LISTBOX"/> <SCREEN id="SCR_ID_SHOWCTRL_EDITBOX"/> <SCREEN id="SCR_ID_SHOWCTRL_TEXTBOX"/> /**********************************/ /**********一级菜单ID定义**********/ <MENU id="MENU_ID_SHOWCTRL" type="APP_MAIN" str="STR_ID_SHOWCTRL" img="MAIN_MENU_SHOWCTRL_ICON" highlight="highlight_show_ctrl"> <MENUITEM id="MENU_ID_SHOWCTRL_LISTBOX" str="STR_ID_SHOWCTRL_LISTBOX"/> <MENUITEM id="MENU_ID_SHOWCTRL_EDITBOX" str="STR_ID_SHOWCTRL_EDITBOX"/> <MENUITEM id="MENU_ID_SHOWCTRL_TEXTBOX" str="STR_ID_SHOWCTRL_TEXTBOX"/> </MENU> <MAINMENUITEM id="MENU_ID_SHOWCTRL" mm_page_img="MAIN_MENU_SHOWCTRL_ICON"/> /**********************************/ /**********二级菜单ID定义**********/ <MENU id="MENU_ID_SHOWCTRL" type="APP_SUB" str="STR_ID_SHOWCTRL" highlight="highlight_showctrl"> <MENUITEM id="MENU_ID_SHOWCTRL_LISTBOX" str="STR_ID_SHOWCTRL_LISTBOX"/> <MENUITEM id="MENU_ID_SHOWCTRL_EDITBOX" str="STR_ID_SHOWCTRL_EDITBOX"/> <MENUITEM id="MENU_ID_SHOWCTRL_TEXTBOX" str="STR_ID_SHOWCTRL_TEXTBOX"/> </MENU> /**********************************/ //注:以上资源ID定义可在“MainMenuRes.res”文件中相应位置进行(字符串资源需要在翻译表中新加翻译)
/*上表中一级菜单ID、二级菜单ID的定义都是参照标准得出,但在多次验证后发现:一级菜单、二级菜单的菜单ID定义可合并为以下通用的写法*/ <MENU id="MENU_ID_SHOWCTRL" str="STR_ID_SHOWCTRL" highlight="highlight_showctrl"> <MENUITEM id = "MENU_ID_SHOWCTRL_LISTBOX" str = "STR_ID_SHOWCTRL_LISTBOX"/> <MENUITEM id = "MENU_ID_SHOWCTRL_EDITBOX" str = "STR_ID_SHOWCTRL_EDITBOX"/> <MENUITEM id = "MENU_ID_SHOWCTRL_TEXTBOX" str = "STR_ID_SHOWCTRL_TEXTBOX"/> </MENU> /*一级菜单需再多定义“MAINMENUITEM”项,否则主菜单将不显示图片*/ <MAINMENUITEM id="MENU_ID_SHOWCTRL" mm_page_img="MAIN_MENU_SHOWCTRL_ICON"/> /*经过以上方式定义的菜单ID,在使用时与标准方式定义的菜单ID一样,都是在需要添加菜单项的位置加入菜单项的菜单ID即可,请参考第2点*/
2. 菜单的创建
/*将菜单ID添加入已建好的菜单列中,即可显示菜单项*/
/************菜单ID使用************/ <MENUITEM_ID>MENU_ID_SHOWCTRL</MENUITEM_ID> /*********************************/
//注:以上资源ID定义可在“MainMenuRes.res”文件中相应位置进行
3. 窗口及控件
#include "common_nvram_editor_data_item.h" nvram_show_ctrl_struct ShowCtrlStruct = {0}; U8 listbox_current_index = 0; WCHAR editbox_buffer[MAX_STRING_LEN] = {0}; WCHAR textbox_buffer[MAX_STRING_LEN] = {0}; /**********************NV存取*********************/ /*读取NV值*/ void ReadNvramShowCtrl(void) { S16 error; ReadRecord(NVRAM_EF_SHOWCTRL_LID,1,&ShowCtrlStruct,NVRAM_EF_SHOWCTRL_SIZE,&error); } /*存储NV值*/ void WriteNvramShowCtrl(void) { S16 error; WriteRecord(NVRAM_EF_SHOWCTRL_LID,1,&ShowCtrlStruct,NVRAM_EF_SHOWCTRL_SIZE,&error); } /************************************************/ /*******************ListBox控件*******************/ /*ListBox控件高亮选项索引回传*/ void highlight_listbox_hdlr(kal_uint8 index) { listbox_current_index = index; } /*存储ListBox控件窗口状态*/ void StatusSetListBoxDone(void) { if(ShowCtrlStruct.listboxIndex != listbox_current_index) { ShowCtrlStruct.listboxIndex = listbox_current_index; WriteNvramShowCtrl(); } mmi_display_popup((UI_string_type)get_string(STR_GLOBAL_DONE),MMI_EVENT_SUCCESS); DeleteNHistory(1); } /*进入ListBox控件窗口*/ void EntryShowCtrlListbox(void) { #define LISTBOX_ITEM_NUM 2 U8 *itemLists[LISTBOX_ITEM_NUM]; U8 *itemIcons[LISTBOX_ITEM_NUM]; U16 index; EntryNewScreen(SCR_ID_SHOWCTRL_LISTBOX,NULL,EntryShowCtrlListbox, NULL); itemLists[0] = (U8*) GetString((U16)(STR_GLOBAL_OFF)); for (index = 1; index < LISTBOX_ITEM_NUM; index++) { itemLists[index] = (U8*) GetString((U16)(STR_GLOBAL_ON + index)); } RegisterHighlightHandler(highlight_listbox_hdlr); #if 0//普通带序号图标的列表控件 for (index = 0; index < LISTBOX_ITEM_NUM; index++) { itemIcons[index] = (U8*) GetImage((U16)(gIndexIconsImageList[index])); } ReadNvramShowCtrl(); ShowCategory170Screen((PU8)GetString(STR_ID_SHOWCTRL_LISTBOX), NULL, (PU8)GetString(STR_GLOBAL_OK), (PU8)GetImage(IMG_GLOBAL_OK), (PU8)GetString(STR_GLOBAL_BACK), (PU8)GetImage(IMG_GLOBAL_BACK), LISTBOX_ITEM_NUM, (U8 **)itemLists, itemIcons, LIST_MENU, ShowCtrlStruct.listboxIndex, NULL); #else//单选列表控件 ReadNvramShowCtrl(); ShowCategory36Screen( STR_ID_SHOWCTRL_LISTBOX, NULL, STR_GLOBAL_OK, IMG_GLOBAL_OK, STR_GLOBAL_BACK, IMG_GLOBAL_BACK, LISTBOX_ITEM_NUM, (U8 **)itemLists, ShowCtrlStruct.listboxIndex, NULL); #endif SetKeyHandler(StatusSetListBoxDone, KEY_LSK,KEY_EVENT_DOWN); SetKeyHandler(GoBackHistory, KEY_RSK,KEY_EVENT_DOWN); } /************************************************/ /*******************EditBox控件*******************/ /*存储EditBox控件窗口状态*/ void StatusSetEditBoxDone(void) { if(wcscmp(ShowCtrlStruct.string,editbox_buffer)) { wcscpy(ShowCtrlStruct.string,editbox_buffer); WriteNvramShowCtrl(); } mmi_display_popup((UI_string_type)get_string(STR_GLOBAL_DONE),MMI_EVENT_SUCCESS); DeleteNHistory(1); } /*进入EditBox控件窗口*/ void EntryShowCtrlEditbox(void) { PU8 gui_buffer = NULL; EntryNewScreen(SCR_ID_SHOWCTRL_EDITBOX, NULL, EntryShowCtrlEditbox, NULL); gui_buffer = mmi_frm_scrn_get_active_gui_buf(); ReadNvramShowCtrl(); if(!gui_buffer) { wcscpy(editbox_buffer,ShowCtrlStruct.string); } ShowCategory5Screen(NULL, NULL, STR_GLOBAL_OK, IMG_GLOBAL_OK, STR_GLOBAL_BACK, IMG_GLOBAL_BACK, IMM_INPUT_TYPE_SENTENCE, (PU8) editbox_buffer, MAX_STRING_LEN, NULL); /*右键的处理函数在 wgui_inputs_ml_set_RSK_int()里注册好了*/ SetLeftSoftkeyFunction(StatusSetEditBoxDone, KEY_EVENT_DOWN); wgui_inputs_category_set_rsk_func(GoBackHistory); } /************************************************/ /*******************TextBox控件*******************/ /*进入TextBox控件窗口*/ void EntryShowCtrlTextbox(void) { PU8 guiBuffer = NULL; EntryNewScreen(SCR_ID_SHOWCTRL_TEXTBOX, NULL, EntryShowCtrlTextbox, NULL); guiBuffer = GetCurrGuiBuffer(SCR_ID_SHOWCTRL_TEXTBOX); ReadNvramShowCtrl(); wcscpy(textbox_buffer,ShowCtrlStruct.string); ShowCategory7Screen( NULL /*STR_ID_SHOWCTRL_TEXTBOX*/, NULL, NULL, NULL, STR_GLOBAL_BACK, IMG_GLOBAL_BACK, (PU8) textbox_buffer, NULL); SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP); } /************************************************/ /*********************菜单创建********************/ /*菜单事件处理*/ static mmi_ret mmi_ShowCtrl_func_select_hdlr(mmi_event_struct * evt) { cui_menu_event_struct *menu_evt = (cui_menu_event_struct*) evt; switch (menu_evt->evt_id) { case EVT_ID_CUI_MENU_LIST_ENTRY: case EVT_ID_CUI_MENU_ITEM_HILITE: { break; } case EVT_ID_CUI_MENU_ITEM_SELECT: { switch(menu_evt->highlighted_menu_id) { case MENU_ID_SHOWCTRL_LISTBOX: EntryShowCtrlListbox(); return MMI_RET_OK; break; case MENU_ID_SHOWCTRL_EDITBOX: EntryShowCtrlEditbox(); return MMI_RET_OK; break; case MENU_ID_SHOWCTRL_TEXTBOX: EntryShowCtrlTextbox(); return MMI_RET_OK; break; default: break; } break; } case EVT_ID_CUI_MENU_CLOSE_REQUEST: cui_menu_close(menu_evt->sender_id); break; case EVT_ID_GROUP_DEINIT: mmi_frm_group_close(SCR_ID_SHOWCTRL); break; } return MMI_RET_OK; } /*进入菜单窗口*/ void EntryShowCtrlFunc(void) { MMI_ID menu_gid; if (mmi_frm_group_is_present(SCR_ID_SHOWCTRL)) { mmi_frm_group_close(SCR_ID_SHOWCTRL); } mmi_frm_group_create_ex(GRP_ID_ROOT, SCR_ID_SHOWCTRL, mmi_ShowCtrl_func_select_hdlr, NULL, MMI_FRM_NODE_SMART_CLOSE_FLAG); menu_gid = cui_menu_create( SCR_ID_SHOWCTRL, CUI_MENU_SRC_TYPE_RESOURCE, CUI_MENU_TYPE_FROM_RESOURCE, MENU_ID_SHOWCTRL, MMI_FALSE, NULL); cui_menu_set_default_title_image_by_id(menu_gid, GetRootTitleIcon(STR_ID_SHOWCTRL)); cui_menu_run(menu_gid); } /*菜单高亮函数*/ void highlight_showctrl(void) { ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK); ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK); SetLeftSoftkeyFunction(EntryShowCtrlFunc, KEY_EVENT_UP); SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP); } /************************************************/ //注:以上代码实现可在“MainMenu.c”文件中相应位置进
4. NVRAM的使用
/**********定义NV LID版本号**********/ #define NVRAM_EF_SHOWCTRL_LID_VERNO "000" /**********************************/ /**********定义NV变量结构体**********/ #define MAX_STRING_LEN 30 typedef struct { kal_uint8 listboxIndex; kal_uint16 string[MAX_STRING_LEN]; } nvram_show_ctrl_struct; /**********************************/ /**************未知作用*************/ LID_BIT VER_LID(NVRAM_EF_SHOWCTRL_LID) nvram_show_ctrl_struct* NVRAM_EF_SHOWCTRL_TOTAL{}; /**********************************/ //注:以上代码添加在“Common_nvram_editor_data_item.h”文件中相应位置
/************NV初始默认值************/ static nvram_show_ctrl_struct const NVRAM_EF_SHOWCTRL_DEFAULT[NVRAM_EF_SHOWCTRL_TOTAL]={ 0x00, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 }; /**********************************/ /**************NV信息表*************/ { NVRAM_EF_SHOWCTRL_LID, NVRAM_EF_SHOWCTRL_TOTAL, NVRAM_EF_SHOWCTRL_SIZE, NVRAM_NORMAL(NVRAM_EF_SHOWCTRL_DEFAULT), NVRAM_CATEGORY_USER, NVRAM_ATTR_AVERAGE | NVRAM_ATTR_FACTORY_RESET, "MQ25", VER(NVRAM_EF_SHOWCTRL_LID) }, /**********************************/
//注:以上代码添加在“Nvram_common_config.c”文件中相应位置
/*************定义NV LID************/ NVRAM_EF_SHOWCTRL_LID, /**********************************/ /*************NV相关量宏定义*************/ #define NVRAM_EF_SHOWCTRL_SIZE (sizeof(nvram_show_ctrl_struct)) #define NVRAM_EF_SHOWCTRL_TOTAL 1 /**********************************/ //注:以上代码添加在“Nvram_common_defs.h”文件中相应位置
注意:以上实例是本人具体实验得出。由于本人刚接触MTK,对平台代码结构理解仍处于混乱阶段,因此本代码仅作为备份记录用。
运行效果如下: