ListBoxSMS.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. void SwitchNextPageSMS(struct SUT_LIST_BOX *p,char up_down);
  10. void ListBoxShowBarSMS(struct SUT_LIST_BOX *p,char rev);
  11. void ListBoxShowSMS(struct SUT_LIST_BOX *p);
  12. void ListBoxInitSMS(SUT_LIST_BOX *p,unsigned short totalnum,const char **iconlist,char unicode)
  13. {
  14. unsigned char i,ch;
  15. p->totalnum = totalnum;
  16. p->notehandle = 1;
  17. p->handle = 0;
  18. //unicode
  19. p->unicode=unicode;
  20. //icon
  21. i=0;
  22. p->icon=iconlist;
  23. while(i<LIST_ITEM_NUM_MAX)
  24. {
  25. if(iconlist==NULL) break;
  26. ch=p->icon[i][0];
  27. if(ch==0) break;
  28. i++;
  29. }
  30. p->iconnum=i;
  31. p->up_down_flag='d';
  32. GetPagePreMessage(p,1,'d');
  33. }
  34. void ListBoxItemNumShowSMS(uint16_t curIndex, uint16_t total)
  35. {
  36. char buf[11];
  37. uint8_t len1,len2;
  38. static uint16_t len;
  39. //如果短信条数允许超过了127条就要修改变量宽度了
  40. if(curIndex < 10)
  41. len1=1;
  42. else if(curIndex < 100)
  43. len1=2;
  44. else if(curIndex < 1000)
  45. len1=3;
  46. else len1=4;
  47. if(total < 10)
  48. len2=1;
  49. else if(total < 100)
  50. len2=2;
  51. else if(total < 1000)
  52. len2=3;
  53. else len2 = 4;
  54. snprintf(buf, sizeof(buf), "%d|%d", curIndex, total);
  55. if(len != (len1+len2)){
  56. len = len1+len2;
  57. //GuiClearArea(160-8*(4+4+2),STATUS_BAR_HEIGH,7*8,16); //44
  58. GuiFillRect(160-8*(4+4+2),STATUS_BAR_HEIGH,160,STATUS_BAR_HEIGH+12,COLOR_WARN_RED);
  59. }
  60. GuiShowStr(160-8*(len1+len2+2),STATUS_BAR_HEIGH,buf,0x01,0);
  61. }
  62. /********************************************************************************
  63. ListBoxShowItem
  64. *******************************************************************************/
  65. void ListBoxShowItemSMS(struct SUT_LIST_BOX *p,unsigned short handle)
  66. {
  67. u16 len;
  68. u16 x,y,hand;
  69. unsigned char buf[LIST_ITEM_TEXT_LEN_MAX+3];
  70. char str[LIST_ITEM_TEXT_LEN_MAX+1];
  71. char f;
  72. hand=handle % LIST_ROW;
  73. x=LIST_TOPX;
  74. y=LIST_TOPY+hand*16;
  75. #if 1 //换页时清理干净
  76. GuiClearArea(x,y,LIST_BAR_LEN+16,16);
  77. #else
  78. GuiClearArea(x,y,LIST_BAR_LEN,16);
  79. #endif
  80. memset(buf,0,sizeof(buf));
  81. if(p->unicode){
  82. buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
  83. }else{
  84. //strncpy((char *)buf,p->item[handle],sizeof(buf));
  85. strncpy((char *)buf,p->boxinfo[handle].item,sizeof(buf));
  86. buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
  87. }
  88. //截取并适当补..
  89. StrIntercept(str,(char *)buf,LIST_ITEM_TEXT_LEN_MAX);
  90. if(p->icon!=NULL){//有图标
  91. //f= p->features[handle];
  92. if(p->boxinfo[handle].features >= p->iconnum)
  93. {
  94. SlwTrace(INF, "LB1",1);
  95. f=0;
  96. }
  97. else
  98. f= p->boxinfo[handle].features;
  99. //f=0;
  100. //#error "f expired!"
  101. GuiShowBmp(x,y,p->icon[f]);
  102. GuiShowStr(x+16,y,str,0x01,0);
  103. }else{//无图标
  104. GuiShowStr(x,y,str,0x01,0);
  105. }
  106. }
  107. /********************************************************************************
  108. * Function:ListBoxShowBar
  109. * display a bar
  110. *******************************************************************************/
  111. void ListBoxShowBarSMS(struct SUT_LIST_BOX *p,char rev)
  112. {
  113. unsigned char x,y,h,handle;
  114. char str[LIST_ITEM_TEXT_LEN_MAX+1];
  115. x=LIST_TOPX;
  116. if(p->icon!=NULL){//有图标
  117. x+=16;
  118. }
  119. handle=p->handle;
  120. y=LIST_TOPY+handle*16;
  121. if(rev)GuiFillRect(x,y,LCD_WIDTH-20,y+14,COLOR_SELECT_BLUE);//
  122. else GuiFillRect(x,y,LCD_WIDTH-20,y+14,COLOR_WHITE_BACK); //113
  123. StrIntercept(str,p->boxinfo[p->handle].item,LIST_ITEM_TEXT_LEN_MAX);
  124. GuiShowStr(x, y,str, 1, rev);
  125. }
  126. /********************************************************************************
  127. * Function:ListBoxShow
  128. * display ListBox
  129. *******************************************************************************/
  130. void ListBoxShowSMS(struct SUT_LIST_BOX *p)
  131. {
  132. unsigned char i,j;
  133. u16 x,y;
  134. if(p->itemnum==0) return;
  135. for(i=0;i<LIST_ROW;i++)
  136. {
  137. if(i >= p->itemnum)
  138. {
  139. y=LIST_TOPY+i*16;
  140. GuiClearArea(LIST_TOPX,y,LIST_BAR_LEN+18,16);
  141. }else
  142. ListBoxShowItemSMS(p,i);
  143. }
  144. if(p->up_down_flag=='u') p->handle=p->itemnum-1;
  145. ListBoxShowBarSMS(p,1);
  146. x=LCD_WIDTH-17;
  147. if(p->totalnum > LIST_ROW)
  148. GuiShowArrow(x+8,LIST_TOPY,8,3);//向上箭头
  149. else
  150. GuiClearArea(x,LIST_TOPY,16,8);
  151. y=LIST_TOPY+LIST_ROW*16;
  152. if(p->totalnum > LIST_ROW)
  153. GuiShowArrow(x+8,y,8,4);//向下箭头
  154. else
  155. GuiClearArea(x,y-8,16,8);
  156. }
  157. /********************************************************************************
  158. ListBoxResponse
  159. ListBox控件的键盘响应处理 底层
  160. *******************************************************************************/
  161. unsigned long ListBoxResponseSMS(SUT_LIST_BOX *p)
  162. {
  163. unsigned char temp;
  164. if(p->itemnum==0)return g_ulKeyValue;
  165. switch(g_ulKeyValue)
  166. {
  167. case KEY_PANEL_UP:
  168. ListBoxShowBarSMS(p,0);//清上一条
  169. p->notehandle--;
  170. if(p->notehandle == 0)
  171. p->notehandle = p->totalnum;
  172. if(p->handle == 0)
  173. {
  174. if(p->totalnum > LIST_ROW)
  175. {
  176. GetPagePreMessage(p,0,'u');
  177. p->pageChange=1;
  178. }else p->handle=p->itemnum-1;
  179. }else
  180. p->handle --;
  181. if(p->pageChange)
  182. p->pageChange=0;
  183. else
  184. ListBoxShowBarSMS(p,1);
  185. ListBoxItemNumShowSMS(p->notehandle,p->totalnum);
  186. break;
  187. case KEY_PANEL_DOWN:
  188. ListBoxShowBarSMS(p,0);//清上一条
  189. p->handle ++;
  190. p->notehandle++;
  191. if(p->notehandle > p->totalnum)
  192. p->notehandle=1;
  193. if(p->handle>=p-> itemnum)
  194. {
  195. if(p->totalnum > LIST_ROW)
  196. {
  197. GetPagePreMessage(p,0,'d');
  198. p->pageChange=1;//page change
  199. }else p->handle=0;
  200. }
  201. if(p->pageChange)
  202. p->pageChange=0;
  203. else
  204. ListBoxShowBarSMS(p,1);
  205. ListBoxItemNumShowSMS(p->notehandle,p->totalnum);
  206. break;
  207. case KEY_PANEL_EXIT:
  208. return g_ulKeyValue;
  209. break;
  210. default:
  211. return g_ulKeyValue;
  212. break;
  213. }
  214. return 0;
  215. }