ListBox.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /********************************************************************************
  2. * File Name: ListBox.c
  3. * Function Describe: ListBox �找辣
  4. * Relate Module: GUI.c
  5. * Writer: Shliangwen
  6. * Date: 2016-1-8
  7. *******************************************************************************/
  8. #include "includes.h"
  9. #define N 100
  10. void ListBoxShow(struct SUT_LIST_BOX *p);
  11. //SUT_LIST_BOX ListBox;
  12. SUT_LIST_BOX sutListBox;
  13. /*************************************************************************
  14. ListBoxInit
  15. ***************************************************************************/
  16. void ListBoxInit(struct SUT_LIST_BOX *p,char **itemlist,char unicode,const char **iconlist,char *features,unsigned int type)
  17. {
  18. UI_STACKDEF *uiPtr=getStackStruct();
  19. unsigned int kk;
  20. ///////////////////////
  21. unsigned char i,ch,index;
  22. //蝏蠘恣item
  23. p->item = itemlist;
  24. i = 0;
  25. while(i<LIST_ITEM_NUM_MAX)
  26. {
  27. ch=p->item[i][0];
  28. if(ch==0)break;
  29. i ++;
  30. }
  31. i=i-1;
  32. p->itemnum = i+1;
  33. p->pgaenum=i/LIST_ROW;
  34. if(p->pgaenum%LIST_ROW)p->pgaenum+=1;
  35. //蝏蠘恣icon
  36. i=0;
  37. p->icon=iconlist;
  38. while(i<LIST_ITEM_NUM_MAX)
  39. {
  40. if(iconlist==NULL)break;
  41. ch=p->icon[i][0];
  42. if(ch==0)break;
  43. i ++;
  44. }
  45. p->iconnum=i;
  46. //�寞�?
  47. for(i=0;i<LIST_ITEM_NUM_MAX;i++){
  48. if(i<p->itemnum){
  49. p->features[i]=features[i];
  50. }else{
  51. p->features[i]=0;
  52. }
  53. }
  54. //unicode
  55. p->unicode=unicode;
  56. //暺䁅恕憿?
  57. p->page = 0;
  58. p->handle = type;
  59. //�曄內
  60. ListBoxShow(p);
  61. }
  62. /******************************************************************************
  63. �����捂��鵭摨行⏛�硋�蝚虫葡嚗���𨀣��踹漲頞������踹漲嚗���芸�銋见僎撠���𤾸�蝚行㺿銝?.."�?..."
  64. �峕𧒄憭��銝剜�摮㛖泵
  65. *******************************************************************************/
  66. void StrIntercept(char *des,char *src,unsigned short len) //憸��len
  67. {
  68. int srclen;
  69. unsigned char d1,d2;
  70. unsigned char *p;
  71. int i;
  72. srclen=strlen(src);
  73. des[len-1]='\0';
  74. strncpy(des,src,len-1);
  75. //if(srclen=len-1 && len>5){
  76. if(srclen>=len-1 && len>5){//�脫迫���𦒘��⊥瓷�曄內..
  77. //撠���𦒘舅銝芸�蝚西蓮銝?.."
  78. des[len-2]='.';
  79. des[len-3]='.';
  80. //�斗鱏�埝㺭蝚?銝芸�蝚行糓�虫蛹�𠹺葵銝剜�摮㛖泵嚗���𨀣糓�坔��嗉蓮銝算�?�辷��踹��曄內銋梁�
  81. p=(unsigned char *)des;
  82. i=0;
  83. while(i<(len-4)){
  84. if(*p>0x9f){
  85. p+=2;
  86. i+=2;
  87. }else{
  88. p+=1;
  89. i+=1;
  90. }
  91. }
  92. if(i==(len-4) && *p>0x9f){//�𠹺葵瘙匧�
  93. des[len-4]='.';
  94. }
  95. }
  96. }
  97. /********************************************************************************
  98. ListBoxShowItem
  99. *******************************************************************************/
  100. void ListBoxShowItem(struct SUT_LIST_BOX *p,unsigned short handle)
  101. {
  102. unsigned short len;
  103. unsigned short x,y,hand;
  104. unsigned char buf[LIST_ITEM_TEXT_LEN_MAX+3];
  105. char str[LIST_ITEM_TEXT_LEN_MAX+1];
  106. char f;
  107. hand=handle % LIST_ROW;
  108. x=LIST_TOPX;
  109. y=LIST_TOPY+hand*16;
  110. //�a△�嗆���僕��
  111. guiClearArea(x,y,LIST_BAR_LEN+16,16,guiGetBackColor());
  112. memset(buf,0,sizeof(buf));
  113. if(p->unicode){
  114. buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
  115. }else{
  116. strncpy((char *)buf,p->item[handle],sizeof(buf));
  117. buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
  118. }
  119. //�芸�撟園���銵?.
  120. StrIntercept(str,(char *)buf,LIST_ITEM_TEXT_LEN_MAX);
  121. if(p->icon!=NULL){//�匧㦛�?
  122. f= p->features[handle];
  123. guiShowBmp(x,y,p->icon[f]);
  124. guiShowStr(x+16,y,str, FONT_MODE_12X12, REVERSED_NO, COLOR_BLACK,guiGetBackColor());
  125. }else{//�惩㦛�?
  126. guiShowStr(x,y,str, FONT_MODE_12X12, REVERSED_NO, COLOR_BLACK,guiGetBackColor());
  127. }
  128. }
  129. /********************************************************************************
  130. * Function:ListBoxShowBar
  131. * display a bar
  132. *******************************************************************************/
  133. void ListBoxShowBar(struct SUT_LIST_BOX *p,REV_ENUM rev)
  134. {
  135. unsigned char x,y,h,handle;
  136. char str[LIST_ITEM_TEXT_LEN_MAX+1];
  137. x=LIST_TOPX;
  138. if(p->icon!=NULL){//�匧㦛�?
  139. x+=16;
  140. }
  141. handle=p->handle%LIST_ROW;
  142. y=LIST_TOPY+handle*16;
  143. //�芸�撟園���銵?.
  144. StrIntercept(str,p->item[p->handle],LIST_ITEM_TEXT_LEN_MAX);
  145. if(REVERSED_YES==rev) guiFillRect(x,y-2,140,y+12,guiGetBackColor());
  146. else guiFillRect(x,y-2,140,y+12,COLOR_STATUS_BAR);
  147. if(REVERSED_NO==rev) guiShowStr(x,y,str, FONT_MODE_12X12, rev,guiGetBackColor(), COLOR_STATUS_BAR);
  148. else guiShowStr(x,y,str, FONT_MODE_12X12, rev,guiGetBackColor(), COLOR_BLACK);
  149. }
  150. /********************************************************************************
  151. * Function:ListBoxShow
  152. * display ListBox
  153. *******************************************************************************/
  154. void ListBoxShow(struct SUT_LIST_BOX *p)
  155. {
  156. unsigned char i,j;
  157. unsigned short x,y;
  158. if(p->itemnum==0)return;
  159. j=p->page*LIST_ROW;
  160. for(i = j ; i <j+LIST_ROW ; i ++)
  161. {
  162. if(i >= p->itemnum){
  163. y=LIST_TOPY+(i % LIST_ROW)*16;
  164. guiClearArea(LIST_TOPX,y,LIST_BAR_LEN+18,16,guiGetBackColor());
  165. }else{
  166. ListBoxShowItem(p,i);
  167. }
  168. }
  169. ListBoxShowBar(p,REVERSED_NO);
  170. return;
  171. //�曄內蝞剖仍
  172. x=GLCD_WIDTH-17;
  173. if(p->page>0){
  174. guiDrawArrow(x+8,LIST_TOPY,8,ARROW_UP,guiGetForeColor());
  175. }else{
  176. guiClearArea(x,LIST_TOPY,16,8,guiGetBackColor());
  177. }
  178. y=LIST_TOPY+LIST_ROW*16;
  179. if(p->page<(p->pgaenum-1)){
  180. guiDrawArrow(x+8,y,8,ARROW_DOWN,guiGetForeColor());//�睲�蝞剖仍
  181. }else{
  182. guiClearArea(x,y-8,16,8,guiGetBackColor());
  183. }
  184. }
  185. /********************************************************************************
  186. ListBoxResponse
  187. ListBox�找辣��睸�睃�摨𥪜��? 摨訫�
  188. *******************************************************************************/
  189. unsigned long ListBoxResponse(struct SUT_LIST_BOX *p)
  190. {
  191. unsigned char temp;
  192. unsigned long g_ulKeyValue=getKeyValue();
  193. if(p->itemnum==0)return g_ulKeyValue;
  194. // SUT_PHONE_NUM PhoneNum[N];
  195. // int i = 0;
  196. switch(g_ulKeyValue)
  197. {
  198. case MKEY_VALUE_UP:
  199. ListBoxShowBar(p,REVERSED_YES);
  200. if(p->handle==0)p->handle=(p->itemnum-1);
  201. else p->handle --;
  202. temp=p->page;
  203. p->page=p->handle/LIST_ROW;
  204. if(temp!=p->page)ListBoxShow(p);
  205. else ListBoxShowBar(p,REVERSED_NO);
  206. break;
  207. case MKEY_VALUE_DOWN:
  208. ListBoxShowBar(p,REVERSED_YES);
  209. p->handle ++;
  210. if(p->handle>=p-> itemnum)p->handle=0;
  211. temp = p->page;
  212. p->page=p->handle/LIST_ROW;
  213. if(temp!=p->page)ListBoxShow(p);
  214. else ListBoxShowBar(p,REVERSED_NO);
  215. break;
  216. default:
  217. return g_ulKeyValue;
  218. break;
  219. }
  220. return 0;
  221. }
  222. /********************************************************************************
  223. ListBoxGetHandle
  224. �瑕�ListBox敶枏��𧢲�
  225. *******************************************************************************/
  226. unsigned short ListBoxGetHandle(struct SUT_LIST_BOX *p)
  227. {
  228. return p->handle;
  229. }