ListBox.c 7.1 KB

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