123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518 |
- /********************************************************************************
- * 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
- ***************************************************************************/
- //ListBoxInit(&sutListBox,VoicesName,0,accIconFileName,VoiceFeatures);
- 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;
- sutListBox.handle=sutPocStatus.Page_Up;
- //显示
- ListBoxShow(p);
- }
- /*************************************************************************
- ListBoxInit
- M20
- ***************************************************************************/
- //ListBoxInit(&sutListBox,VoicesName,0,accIconFileName,VoiceFeatures);
- void ListBoxInitM20(struct SUT_LIST_BOX *p,char **itemlist,char unicode,const char **iconlist,char *features,char *time)
- {
- 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->time[i]=time[i];
- p->features[i]=features[i];
- }else{
- p->time[i]=0;
- p->features[i]=0;
- }
- }
- //unicode
- p->unicode=unicode;
- //默认项
- p->page = 0;
- //p->handle = 4;//等语音记录模块正常,再改为4
- //显示
- ListBoxShowM20(p);
- }
- /******************************************************************************
- 指定允许的长度截取字符串,如果源长度超过指定长度,则截取之并将最后字符改为".."或"..."
- 同时处理中文字符
- *******************************************************************************/
- void StrIntercept(char *des,char *src,u16 len) //buf msg 12
- {
- 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);
- }
- }
- /********************************************************************************
- ListBoxShowItem M20
- *******************************************************************************/
- void ListBoxShowItemM20(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,t;
- char time[10];
- char buf2[50];
- hand=handle % LIST_ROW;
- x=LIST_TOPX;
- y=LIST_TOPY+hand*16;
-
- #if 1 //
- GuiClearArea(x,y,160,16);//LIST_BAR_LEN+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;
- }
- //截取并适当补..
- //printf("src---%s\r\n",buf);
- StrIntercept(str,(char *)buf,12);
-
- //printf("str---%s\r\n",str);
- len=strlen(str);
- //printf("len---%d\r\n",len);
- len=GetStrXLen((char *)str);
-
- if(p->icon!=NULL){//有图标
- f= p->features[handle];
- t=p->time[handle];
- snprintf(time,sizeof(time),"%d'",t); //" %d'"
- snprintf(buf2,sizeof(buf2),"time len========%d,,,,,len2====%d\r\n",strlen(time),len);
- SlwTrace(INF,buf2,1);
- if(!f){
- GuiShowStr(x,y,str,0x01);
- GuiShowBmp(x+len+1,y,p->icon[f]);
- GuiShowStr(x+len+1+32,y,time,0x01);
-
- }else{
- GuiShowStr(160-len-32-5-strlen(time)*8,y,time,0x01); //5
- GuiShowBmp(160-len-32-5,y,p->icon[f]);
- GuiShowStr(160-len-5,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;
- GuiReverseRect(x,y,LIST_BAR_LEN,14);
- }
- /********************************************************************************
- * Function:ListBoxShowBar
- * display a bar m20
- *******************************************************************************/
- void ListBoxShowBarM20(struct SUT_LIST_BOX *p)
- {
- unsigned char x,y,h,handle;
- char *str;
-
- x=LIST_TOPX;
- // if(p->icon!=NULL){//有图标
- // x+=32;
- // }
- handle=p->handle%LIST_ROW;
- y=LIST_TOPY+handle*16; //14
- GuiReverseRect(0,y,160,14);//LIST_BAR_LEN 14
- }
- /********************************************************************************
- * 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);
- //显示箭头
- 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);
- }
- }
- /********************************************************************************
- * Function:ListBoxShow
- * display ListBox
- *******************************************************************************/
- void ListBoxShowM20(struct SUT_LIST_BOX *p)
- {
- unsigned char i,j;
- u16 x,y;
-
- if(p->itemnum==0)return;
-
- //GuiClearArea(LIST_TOPX,LIST_TOPY,160,79);
- //GuiClearRect(LIST_TOPX,LIST_TOPY,LIST_TOPX+160,LIST_TOPY+79);
-
- 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,160,16);//LIST_BAR_LEN+18
- }else{
- ListBoxShowItemM20(p,i);
- }
- }
- ListBoxShowBarM20(p);
-
- // //显示箭头
- // 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:
- 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)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);
- break;
- case KEY_PANEL_DOWN:
- ListBoxShowBar(p);
- 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);
- break;
-
- default:
- return g_ulKeyValue;
- break;
- }
- return 0;
- }
- /********************************************************************************
- ListBoxResponse
- ListBox控件的键盘响应处理 底层 M20
- *******************************************************************************/
- unsigned long ListBoxResponseM20(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 :
- ListBoxShowBarM20(p);
- 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)ListBoxShowM20(p);
- else ListBoxShowBarM20(p);
- break;
-
- case KEY_PANEL_DOWN :
- ListBoxShowBarM20(p);
- p->handle ++;
- if(p->handle>=p-> itemnum)p->handle=0;
- temp = p->page; //当前页
- p->page=p->handle/LIST_ROW;
- if(temp!=p->page)ListBoxShowM20(p);
- else ListBoxShowBarM20(p);
-
- break;
-
- default:
- return g_ulKeyValue;
- break;
- }
- return 0;
- }
- /********************************************************************************
- ListBoxGetHandle
- 获取ListBox当前手柄
- *******************************************************************************/
- unsigned short ListBoxGetHandle(struct SUT_LIST_BOX *p)
- {
- return p->handle;
- }
|