123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- /********************************************************************************
- * File Name: ListBox.c
- * Function Describe: ListBox 控件
- * Relate Module: GUI.c
- * Writer: Shliangwen
- * Date: 2016-1-8
- *******************************************************************************/
- #include "ListBoxSMS.h"
- #include "gui.h"
- #include "ListBox.h"
- #include "ohboard.h"
- #include "log.h"
- #include "uiEntry.h"
- #define BOX_UP MKEY_VALUE_UP
- #define BOX_DOWN MKEY_VALUE_DOWN
- #define BOX_EXIT MKEY_VALUE_ESC
- void SwitchNextPageSMS(struct SUT_LIST_BOX *p,char up_down);
- void ListBoxShowBarSMS(struct SUT_LIST_BOX *p,REV_ENUM rev);
- 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(unsigned short curIndex, unsigned short total)
- {
- char buf[11];
- unsigned char len1,len2;
- static unsigned short len;
- //如果çŸä¿¡æ�¡æ•°å…�许超过äº?27æ�¡å°±è¦�修改å�˜é‡�宽度了
- 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(GLCD_WIDTH-8*(4+4+2),STATUS_BAR_HEIGH,7*8,16); //44
- guiFillRect(GLCD_WIDTH-8*(4+4+1),UI_STATUS_ITEM_Y,GLCD_WIDTH,UI_STATUS_ITEM_Y+12,guiGetForeColor());
- }
- guiShowStr(GLCD_WIDTH-8*(len1+len2+2),UI_STATUS_ITEM_Y+1,buf,FONT_MODE_12X12, REVERSED_NO, guiGetBackColor(), guiGetForeColor());
- }
- /********************************************************************************
- ListBoxShowItem
- *******************************************************************************/
- void ListBoxShowItemSMS(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));
- 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)
- {
- MSG_INFO(1,"LB1");
- f=0;
- }
- else
- f= p->boxinfo[handle].features;
- //f=0;
- //#error "f expired!"
- 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 ListBoxShowBarSMS(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;
- y=LIST_TOPY+handle*16;
- if(REVERSED_YES==rev)guiFillRect(x,y,x+LIST_BAR_LEN,y+11,COLOR_STATUS_BAR);//
- else guiFillRect(x,y,x+LIST_BAR_LEN,y+11,guiGetBackColor()); //113
- StrIntercept(str,p->boxinfo[p->handle].item,LIST_ITEM_TEXT_LEN_MAX);
- guiShowStr(x, y,str,FONT_MODE_12X12, rev, COLOR_STATUS_BAR, guiGetBackColor());
-
- }
- /********************************************************************************
- * Function:ListBoxShow
- * display ListBox
- *******************************************************************************/
- void ListBoxShowSMS(struct SUT_LIST_BOX *p)
- {
- unsigned char i,j;
- unsigned short 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+16,16,guiGetBackColor());
- }else
- ListBoxShowItemSMS(p,i);
- }
-
- if(p->up_down_flag=='u') p->handle=p->itemnum-1;
-
- ListBoxShowBarSMS(p,REVERSED_YES);
- x=GLCD_WIDTH-17;
- if(p->totalnum > LIST_ROW)
- guiDrawArrow(x+8,LIST_TOPY,8,ARROW_UP,COLOR_STATUS_BAR);//å�‘上ç®å¤´
- else
- guiClearArea(x,LIST_TOPY,16,8,guiGetBackColor());
-
- y=LIST_TOPY+LIST_ROW*16;
- if(p->totalnum > LIST_ROW)
- guiDrawArrow(x+8,y,8,ARROW_DOWN,COLOR_STATUS_BAR);//å�‘下ç®å¤´
- else
- guiClearArea(x,y-8,16,8,guiGetBackColor());
- }
- /********************************************************************************
- ListBoxResponse
- ListBox控件的键盘�应处� 底层
- *******************************************************************************/
- unsigned long ListBoxResponseSMS(SUT_LIST_BOX *p)
- {
- unsigned char temp;
- unsigned long keyValue=getKeyValue();
-
- if(p->itemnum==0)return keyValue;
-
- switch(keyValue)
- {
- case BOX_UP:
- ListBoxShowBarSMS(p,REVERSED_NO);//清上一�
- 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,REVERSED_YES);
-
- ListBoxItemNumShowSMS(p->notehandle,p->totalnum);
- break;
- case BOX_DOWN:
- ListBoxShowBarSMS(p,REVERSED_NO);//清上一�
- 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,REVERSED_YES);
-
- ListBoxItemNumShowSMS(p->notehandle,p->totalnum);
- break;
- case BOX_EXIT:
- return keyValue;
- break;
- default:
- return keyValue;
- break;
- }
- return 0;
- }
|