123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- /********************************************************************************
- * File Name: ListBox.c
- * Function Describe: ListBox 控件
- * Relate Module: GUI.c
- * Writer: Shliangwen
- * Date: 2016-1-8
- *******************************************************************************/
- #include "Includes.h"
-
- void SwitchNextPageSMS(struct SUT_LIST_BOX *p,char up_down);
- void ListBoxShowBarSMS(struct SUT_LIST_BOX *p);
- void ListBoxShowSMS(struct SUT_LIST_BOX *p);
- void ListBoxInitSMS(SUT_LIST_BOX *p,unsigned short totalnum,const char **iconlist,char unicode)
- {
- unsigned char i,ch;
- p->totalnum = totalnum;
- p->notehandle = 1;
- p->handle = 0;
- //unicode
- p->unicode=unicode;
- //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;
- p->up_down_flag='d';
- GetPagePreMessage(p,1,'d');
- }
- void ListBoxItemNumShowSMS(uint16_t curIndex, uint16_t total)
- {
- char buf[11];
- uint8_t len1,len2;
- static uint16_t len;
- //如果短信条数允许超过了127条就要修改变量宽度了
- if(curIndex < 10)
- len1=1;
- else if(curIndex < 100)
- len1=2;
- else if(curIndex < 1000)
- len1=3;
- else len1=4;
-
- if(total < 10)
- len2=1;
- else if(total < 100)
- len2=2;
- else if(total < 1000)
- len2=3;
- else len2 = 4;
-
- snprintf(buf, sizeof(buf), "%d|%d", curIndex, total);
- if(len != (len1+len2)){
- len = len1+len2;
- GuiClearArea(160-8*(4+4+2),1,7*8,16);
- }
- GuiShowStr(160-8*(len1+len2+2),1,buf,0x01);
- }
- /********************************************************************************
- ListBoxShowItem
- *******************************************************************************/
- void ListBoxShowItemSMS(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]);
- StrUnicodeToAnsi(buf,sizeof(buf),p->boxinfo[handle].item);
- buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
- }else{
- //strncpy((char *)buf,p->item[handle],sizeof(buf));
- strncpy((char *)buf,p->boxinfo[handle].item,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];
-
- if(p->boxinfo[handle].features >= p->iconnum)
- {
- SlwTrace(INF, "LB1",1);
- f=0;
- }
- else
- f= p->boxinfo[handle].features;
- //f=0;
- //#error "f expired!"
- GuiShowBmp(x,y,p->icon[f]);
- GuiShowStr(x+16,y,str,0x01);
- }else{//无图标
- GuiShowStr(x,y,str,0x01);
- }
- }
- /********************************************************************************
- * Function:ListBoxShowBar
- * display a bar
- *******************************************************************************/
- void ListBoxShowBarSMS(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;
- y=LIST_TOPY+handle*16;
- GuiReverseRect(x,y,LIST_BAR_LEN,14);
- }
- /********************************************************************************
- * Function:ListBoxShow
- * display ListBox
- *******************************************************************************/
- void ListBoxShowSMS(struct SUT_LIST_BOX *p)
- {
- unsigned char i,j;
- u16 x,y;
- if(p->itemnum==0) return;
- for(i=0;i<LIST_ROW;i++)
- {
- if(i >= p->itemnum)
- {
- y=LIST_TOPY+i*16;
- GuiClearArea(LIST_TOPX,y,LIST_BAR_LEN+18,16);
- }else
- ListBoxShowItemSMS(p,i);
- }
- if(p->up_down_flag=='u')
- p->handle=p->itemnum-1;
- ListBoxShowBarSMS(p);
- #if 1
- x=LCD_WIDTH-17;
- if(p->totalnum > LIST_ROW)
- GuiShowArrow(x+8,LIST_TOPY,8,3);//向上箭头
- else
- GuiClearArea(x,LIST_TOPY,16,8);
-
- y=LIST_TOPY+LIST_ROW*16;
- if(p->totalnum > LIST_ROW)
- GuiShowArrow(x+8,y,8,4);//向下箭头
- else
- GuiClearArea(x,y-8,16,8);
- #else
- //显示箭头
- x=LCD_WIDTH-17;
- if(p->notehandle!=0 && p->totalnum > LIST_ROW){
- GuiShowArrow(x+8,LIST_TOPY,8,3);//向上箭头
- }else{
- GuiClearArea(x,LIST_TOPY,16,8);
- }
-
- y=LIST_TOPY+LIST_ROW*16;
- if(p->totalnum-p->notehandle>LIST_ROW){
- GuiShowArrow(x+8,y,8,4);//向下箭头
- }else{
- GuiClearArea(x,y-8,16,8);
- }
- #endif
- }
- /********************************************************************************
- ListBoxResponse
- ListBox控件的键盘响应处理 底层
- *******************************************************************************/
- unsigned long ListBoxResponseSMS(SUT_LIST_BOX *p)
- {
- unsigned char temp;
-
- if(p->itemnum==0)return g_ulKeyValue;
-
- switch(g_ulKeyValue)
- {
- case KEY_PANEL_UP:
- ListBoxShowBarSMS(p);//清上一条
- p->notehandle--;
- if(p->notehandle == 0)
- p->notehandle = p->totalnum;
- if(p->handle == 0)
- {
- if(p->totalnum > LIST_ROW)
- {
- GetPagePreMessage(p,0,'u');
- p->pageChange=1;
- }else p->handle=p->itemnum-1;
- }else
- p->handle --;
-
- if(p->pageChange)
- p->pageChange=0;
- else
- ListBoxShowBarSMS(p);
-
- ListBoxItemNumShowSMS(p->notehandle,p->totalnum);
- break;
- case KEY_PANEL_DOWN:
- ListBoxShowBarSMS(p);//清上一条
- p->handle ++;
- p->notehandle++;
- if(p->notehandle > p->totalnum)
- p->notehandle=1;
- if(p->handle>=p-> itemnum)
- {
- if(p->totalnum > LIST_ROW)
- {
- GetPagePreMessage(p,0,'d');
- p->pageChange=1;//page change
- }else p->handle=0;
- }
- if(p->pageChange)
- p->pageChange=0;
- else
- ListBoxShowBarSMS(p);
-
- ListBoxItemNumShowSMS(p->notehandle,p->totalnum);
- break;
- case KEY_PANEL_EXIT:
- return g_ulKeyValue;
- break;
- default:
- return g_ulKeyValue;
- break;
- }
- return 0;
- }
|