123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- /********************************************************************************
- * File Name: ListBox.c
- * Function Describe: ListBox 控件
- * Relate Module: GUI.c
- * Writer: Shliangwen
- * Date: 2016-1-8
- *******************************************************************************/
- #include "Includes.h"
-
- #define N 100
- void ListBoxShow(struct SUT_LIST_BOX *p);
- SUT_LIST_BOX ListBox;
- /*************************************************************************
- ListBoxInit
- ***************************************************************************/
- void ListBoxInit(struct SUT_LIST_BOX *p,char **itemlist,char unicode,const char **iconlist,char *features)
- {
- unsigned int kk;
- ///////////////////////
- unsigned char i,ch;
- //统计item
- p->item = itemlist;
-
- i = 0;
- while(i<LIST_ITEM_NUM_MAX)
- {
- ch=p->item[i][0];
- if(ch==0)break;
- i ++;
- }
- i=i-1;
- p->itemnum = i+1;
- p->pgaenum=i/LIST_ROW;
- if(p->pgaenum%LIST_ROW)p->pgaenum+=1;
- //统计icon
- i=0;
- p->icon=iconlist;
- while(i<LIST_ITEM_NUM_MAX)
- {
- if(iconlist==NULL)break;
- ch=p->icon[i][0];
- if(ch==0)break;
- i ++;
- }
- p->iconnum=i;
- //特性
- for(i=0;i<LIST_ITEM_NUM_MAX;i++){
- if(i<p->itemnum){
- p->features[i]=features[i];
- }else{
- p->features[i]=0;
- }
- }
- //unicode
- p->unicode=unicode;
- //默认项
- p->page = 0;
- p->handle = 0;
- //显示
- ListBoxShow(p);
- }
- /******************************************************************************
- 指定允许的长度截取字符串,如果源长度超过指定长度,则截取之并将最后字符改为".."或"..."
- 同时处理中文字符
- *******************************************************************************/
- void StrIntercept(char *des,char *src,u16 len)
- {
- int srclen;
- unsigned char d1,d2;
- unsigned char *p;
- int i;
- srclen=strlen(src);
- des[len-1]='\0';
- strncpy(des,src,len-1);
- //if(srclen=len-1 && len>5){
- if(srclen>=len-1 && len>5){//防止最后一条没显示..
- //将最后两个字符转为".."
- des[len-2]='.';
- des[len-3]='.';
- //判断倒数第3个字符是否为半个中文字符,如果是则将其转为‘.’,避免显示乱码
- p=(unsigned char *)des;
- i=0;
- while(i<(len-4)){
- if(*p>0x9f){
- p+=2;
- i+=2;
- }else{
- p+=1;
- i+=1;
- }
- }
- if(i==(len-4) && *p>0x9f){//半个汉字
- des[len-4]='.';
- }
- }
-
- }
- /********************************************************************************
- ListBoxShowItem
- *******************************************************************************/
- void ListBoxShowItem(struct SUT_LIST_BOX *p,unsigned short handle)
- {
- u16 len;
- u16 x,y,hand;
- unsigned char buf[LIST_ITEM_TEXT_LEN_MAX+3];
- char str[LIST_ITEM_TEXT_LEN_MAX+1];
- char f;
- hand=handle % LIST_ROW;
- x=LIST_TOPX;
- y=LIST_TOPY+hand*16;
- #if 1 //换页时清理干净
- GuiClearArea(x,y,LIST_BAR_LEN+16,16);
- #else
- GuiClearArea(x,y,LIST_BAR_LEN,16);
- #endif
- memset(buf,0,sizeof(buf));
- if(p->unicode){
- StrUnicodeToAnsi(buf,sizeof(buf),p->item[handle]);
- buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
- }else{
- strncpy((char *)buf,p->item[handle],sizeof(buf));
- buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
- }
- //截取并适当补..
- StrIntercept(str,(char *)buf,LIST_ITEM_TEXT_LEN_MAX);
-
- if(p->icon!=NULL){//有图标
- f= p->features[handle];
- GuiShowBmp(x,y,p->icon[f]);
- GuiShowStr(x+16,y,str,0x01);
- }else{//无图标
- GuiShowStr(x,y,str,0x01);
- }
- }
- /********************************************************************************
- * Function:ListBoxShowBar
- * display a bar
- *******************************************************************************/
- void ListBoxShowBar(struct SUT_LIST_BOX *p)
- {
- unsigned char x,y,h,handle;
- char *str;
-
- x=LIST_TOPX;
- if(p->icon!=NULL){//有图标
- x+=16;
- }
- handle=p->handle%LIST_ROW;
- y=LIST_TOPY+handle*16;
- if(sutUIstatus.Status==UIS_SET_QUICK_GROUP && handle==0)
- {
- x+=72;
- if(!QuickGroupSet)GuiReverseRect(x,y,64,16);
- else {
- GuiClearArea(x,y,64,16);
-
- if(newPara.QuickGroup==0)GuiShowStr(x+16,y,"关闭",0x01);
- else GuiShowStr(x+16,y,"开启",0x01);
- GuiReverseRect(x,y,64,16);
- }
-
- }
- else if(sutUIstatus.Status==UIS_SET_QUICK_GROUP)
- {
- x+=32;
- GuiReverseRect(x,y,LIST_BAR_LEN,16);
- }
- else{
- GuiReverseRect(x,y,LIST_BAR_LEN,16);
- }
-
- }
- /********************************************************************************
- * Function:ListBoxShow
- * display ListBox
- *******************************************************************************/
- void ListBoxShow(struct SUT_LIST_BOX *p)
- {
- unsigned char i,j;
- u16 x,y;
-
- if(p->itemnum==0)return;
-
- j=p->page*LIST_ROW;
- for(i = j ; i <j+LIST_ROW ; i ++)
- {
- if(i >= p->itemnum){
- y=LIST_TOPY+(i % LIST_ROW)*16;
- GuiClearArea(LIST_TOPX,y,LIST_BAR_LEN+18,16);
- }else{
- ListBoxShowItem(p,i);
- }
- }
- ListBoxShowBar(p);
-
- if(sutUIstatus.Status!=UIS_SET_QUICK_GROUP){
- //显示箭头
- x=LCD_WIDTH-17;
- if(p->page>0){
- GuiShowArrow(x+8,LIST_TOPY,8,3);//向上箭头
- }else{
- GuiClearArea(x,LIST_TOPY,16,8);
- }
-
- y=LIST_TOPY+LIST_ROW*16;
- if(p->page<(p->pgaenum-1)){
- GuiShowArrow(x+8,y,8,4);//向下箭头
- }else{
- GuiClearArea(x,y-8,16,8);
- }
- }
- }
- /********************************************************************************
- ListBoxResponse
- ListBox控件的键盘响应处理 底层
- *******************************************************************************/
- unsigned long ListBoxResponse(struct SUT_LIST_BOX *p)
- {
- unsigned char temp;
- if(p->itemnum==0)return g_ulKeyValue;
- // SUT_PHONE_NUM PhoneNum[N];
- // int i = 0;
-
- switch(g_ulKeyValue)
- {
- case KEY_PANEL_UP:
- if(QuickGroupSet)newPara.QuickGroup=!newPara.QuickGroup;
- ListBoxShowBar(p);
- #if 0
- if(p->handle==0)
- {
- p->handle=(p->itemnum-1);
- //清预览位置
- GuiClearArea(LIST_TOPX,LIST_TOPY,LIST_BAR_LEN,16*LIST_ROW);
- }
- #else
- if(p->handle==0&&!QuickGroupSet)p->handle=(p->itemnum-1);
- #endif
- else if(!QuickGroupSet) p->handle --;
- temp=p->page;
- p->page=p->handle/LIST_ROW;
- if(temp!=p->page)ListBoxShow(p);
- else ListBoxShowBar(p);
- break;
- case KEY_PANEL_DOWN:
- if(QuickGroupSet)newPara.QuickGroup=!newPara.QuickGroup;
- ListBoxShowBar(p);
- if(!QuickGroupSet)p->handle ++;
- #if 0
- if(p->handle>=p-> itemnum)
- {
- p->handle=0;
- //清预览位置
- GuiClearArea(LIST_TOPX,LIST_TOPY,LIST_BAR_LEN+16,16*LIST_ROW);
- }
- #else
- if(p->handle>=p-> itemnum&&!QuickGroupSet)p->handle=0;
- #endif
- temp = p->page;
- p->page=p->handle/LIST_ROW;
- if(temp!=p->page)ListBoxShow(p);
- else ListBoxShowBar(p);
-
- break;
-
-
- default:
- return g_ulKeyValue;
- break;
- }
- return 0;
- }
- /********************************************************************************
- ListBoxGetHandle
- 获取ListBox当前手柄
- *******************************************************************************/
- unsigned short ListBoxGetHandle(struct SUT_LIST_BOX *p)
- {
- return p->handle;
- }
|