/******************************************************************************** * 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; SUT_LIST_BOX sutListBox; /************************************************************************* ListBoxInit ***************************************************************************/ void ListBoxInit(struct SUT_LIST_BOX *p,char **itemlist,char unicode,const char **iconlist,char *features) { UI_STACKDEF *uiPtr=getStackStruct(); unsigned char i,ch,index; //统计item p->item = itemlist; i = 0; while(iitem[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(iicon[i][0]; if(ch==0)break; i ++; } p->iconnum=i; //特? for(i=0;iitemnum){ p->features[i]=features[i]; }else{ p->features[i]=0; } } //unicode p->unicode=unicode; //默认? if(MKEY_VALUE_ESC==getKeyValue() || uiPtr->ok_back){ index=uiPullStack(); if(index>9){ p->page=2; p->handle=index; }else if(index>4){ p->page=1; p->handle=index; }else{ p->page=0; p->handle=index; } uiPtr->ok_back=0; }else{ p->page = 0; p->handle = 0; } //显示 ListBoxShow(p); } /****************************************************************************** 指定允许的长度截取字符串,如果源长度超过指定长度,则截取之并将最后字符改?.."?..." 同时处理中文字符 *******************************************************************************/ void StrIntercept(char *des,char *src,unsigned short len) //预期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]='.'; //判断倒数?个字符是否为半个中文字符,如果是则将其转为?’,避免显示乱码 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) { unsigned short len; unsigned short 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; //换页时清理干净 guiClearArea(x,y,LIST_BAR_LEN+16,16,guiGetBackColor()); memset(buf,0,sizeof(buf)); if(p->unicode){ 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, FONT_MODE_12X12, REVERSED_NO, COLOR_BLACK,guiGetBackColor()); }else{//无图? guiShowStr(x,y,str, FONT_MODE_12X12, REVERSED_NO, COLOR_BLACK,guiGetBackColor()); } } /******************************************************************************** * Function:ListBoxShowBar * display a bar *******************************************************************************/ void ListBoxShowBar(struct SUT_LIST_BOX *p,REV_ENUM rev) { unsigned char x,y,h,handle; char str[LIST_ITEM_TEXT_LEN_MAX+1]; x=LIST_TOPX; if(p->icon!=NULL){//有图? x+=16; } handle=p->handle%LIST_ROW; y=LIST_TOPY+handle*16; //截取并适当?. StrIntercept(str,p->item[p->handle],LIST_ITEM_TEXT_LEN_MAX); if(REVERSED_YES==rev) guiFillRect(x,y-2,140,y+12,guiGetBackColor()); else guiFillRect(x,y-2,140,y+12,COLOR_STATUS_BAR); if(REVERSED_NO==rev) guiShowStr(x,y,str, FONT_MODE_12X12, rev,guiGetBackColor(), COLOR_STATUS_BAR); else guiShowStr(x,y,str, FONT_MODE_12X12, rev,guiGetBackColor(), COLOR_BLACK); } /******************************************************************************** * Function:ListBoxShow * display ListBox *******************************************************************************/ void ListBoxShow(struct SUT_LIST_BOX *p) { unsigned char i,j; unsigned short x,y; if(p->itemnum==0)return; j=p->page*LIST_ROW; for(i = j ; i = p->itemnum){ //y=MENU_TOPY+(i % MENU_ROW)*(12+MENU_SPACE);//16 y=LIST_TOPY+(i % LIST_ROW)*16; guiClearArea(LIST_TOPX,y,LIST_BAR_LEN+18,16,guiGetBackColor()); }else{ ListBoxShowItem(p,i); } } ListBoxShowBar(p,REVERSED_NO); //显示箭头 x=GLCD_WIDTH-17; if(p->page>0){ guiDrawArrow(x+8,LIST_TOPY,8,ARROW_UP,guiGetForeColor()); }else{ guiClearArea(x,LIST_TOPY,16,8,guiGetBackColor()); } y=LIST_TOPY+LIST_ROW*16; if(p->page<(p->pgaenum-1)){ guiDrawArrow(x+8,y,8,ARROW_DOWN,guiGetForeColor());//向下箭头 }else{ guiClearArea(x,y-8,16,8,guiGetBackColor()); } } /******************************************************************************** ListBoxResponse ListBox控件的键盘响应处? 底层 *******************************************************************************/ unsigned long ListBoxResponse(struct SUT_LIST_BOX *p) { unsigned char temp; unsigned long g_ulKeyValue=getKeyValue(); if(p->itemnum==0)return g_ulKeyValue; // SUT_PHONE_NUM PhoneNum[N]; // int i = 0; switch(g_ulKeyValue) { case MKEY_VALUE_UP: ListBoxShowBar(p,REVERSED_YES); #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)p->handle=(p->itemnum-1); #endif else p->handle --; temp=p->page; p->page=p->handle/LIST_ROW; if(temp!=p->page)ListBoxShow(p); else ListBoxShowBar(p,REVERSED_NO); break; case MKEY_VALUE_DOWN: ListBoxShowBar(p,REVERSED_YES); 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)p->handle=0; #endif temp = p->page; p->page=p->handle/LIST_ROW; if(temp!=p->page)ListBoxShow(p); else ListBoxShowBar(p,REVERSED_NO); break; default: return g_ulKeyValue; break; } return 0; } /******************************************************************************** ListBoxGetHandle 获取ListBox当前手柄 *******************************************************************************/ unsigned short ListBoxGetHandle(struct SUT_LIST_BOX *p) { return p->handle; }