123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- /********************************************************************************
- * 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,unsigned int type)
- {
- UI_STACKDEF *uiPtr=getStackStruct();
- unsigned int kk;
- ///////////////////////
- unsigned char i,ch,index;
- //蝏蠘恣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 = type;
-
- //�曄內
- 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;
- //�a△�嗆���僕��
- 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 <j+LIST_ROW ; i ++)
- {
- if(i >= p->itemnum){
-
- 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);
-
- return;
- //�曄內蝞剖仍
- 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(p->handle==0)p->handle=(p->itemnum-1);
- 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(p->handle>=p-> itemnum)p->handle=0;
-
- 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;
- }
|