ListBox.c 6.8 KB

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