ListBoxSMS.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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);
  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),1,7*8,16);
  58. }
  59. GuiShowStr(160-8*(len1+len2+2),1,buf,0x01);
  60. }
  61. /********************************************************************************
  62. ListBoxShowItem
  63. *******************************************************************************/
  64. void ListBoxShowItemSMS(struct SUT_LIST_BOX *p,unsigned short handle)
  65. {
  66. u16 len;
  67. u16 x,y,hand;
  68. unsigned char buf[LIST_ITEM_TEXT_LEN_MAX+3];
  69. char str[LIST_ITEM_TEXT_LEN_MAX+1];
  70. char f;
  71. hand=handle % LIST_ROW;
  72. x=LIST_TOPX;
  73. y=LIST_TOPY+hand*16;
  74. #if 1 //换页时清理干净
  75. GuiClearArea(x,y,LIST_BAR_LEN+16,16);
  76. #else
  77. GuiClearArea(x,y,LIST_BAR_LEN,16);
  78. #endif
  79. memset(buf,0,sizeof(buf));
  80. if(p->unicode){
  81. //StrUnicodeToAnsi(buf,sizeof(buf),p->item[handle]);
  82. StrUnicodeToAnsi(buf,sizeof(buf),p->boxinfo[handle].item);
  83. buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
  84. }else{
  85. //strncpy((char *)buf,p->item[handle],sizeof(buf));
  86. strncpy((char *)buf,p->boxinfo[handle].item,sizeof(buf));
  87. buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
  88. }
  89. //截取并适当补..
  90. StrIntercept(str,(char *)buf,LIST_ITEM_TEXT_LEN_MAX);
  91. if(p->icon!=NULL){//有图标
  92. //f= p->features[handle];
  93. if(p->boxinfo[handle].features >= p->iconnum)
  94. {
  95. SlwTrace(INF, "LB1",1);
  96. f=0;
  97. }
  98. else
  99. f= p->boxinfo[handle].features;
  100. //f=0;
  101. //#error "f expired!"
  102. GuiShowBmp(x,y,p->icon[f]);
  103. GuiShowStr(x+16,y,str,0x01);
  104. }else{//无图标
  105. GuiShowStr(x,y,str,0x01);
  106. }
  107. }
  108. /********************************************************************************
  109. * Function:ListBoxShowBar
  110. * display a bar
  111. *******************************************************************************/
  112. void ListBoxShowBarSMS(struct SUT_LIST_BOX *p)
  113. {
  114. unsigned char x,y,h,handle;
  115. char *str;
  116. x=LIST_TOPX;
  117. if(p->icon!=NULL){//有图标
  118. x+=16;
  119. }
  120. handle=p->handle;
  121. y=LIST_TOPY+handle*16;
  122. GuiReverseRect(x,y,LIST_BAR_LEN,14);
  123. }
  124. /********************************************************************************
  125. * Function:ListBoxShow
  126. * display ListBox
  127. *******************************************************************************/
  128. void ListBoxShowSMS(struct SUT_LIST_BOX *p)
  129. {
  130. unsigned char i,j;
  131. u16 x,y;
  132. if(p->itemnum==0) return;
  133. for(i=0;i<LIST_ROW;i++)
  134. {
  135. if(i >= p->itemnum)
  136. {
  137. y=LIST_TOPY+i*16;
  138. GuiClearArea(LIST_TOPX,y,LIST_BAR_LEN+18,16);
  139. }else
  140. ListBoxShowItemSMS(p,i);
  141. }
  142. if(p->up_down_flag=='u')
  143. p->handle=p->itemnum-1;
  144. ListBoxShowBarSMS(p);
  145. #if 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. #else
  157. //显示箭头
  158. x=LCD_WIDTH-17;
  159. if(p->notehandle!=0 && p->totalnum > LIST_ROW){
  160. GuiShowArrow(x+8,LIST_TOPY,8,3);//向上箭头
  161. }else{
  162. GuiClearArea(x,LIST_TOPY,16,8);
  163. }
  164. y=LIST_TOPY+LIST_ROW*16;
  165. if(p->totalnum-p->notehandle>LIST_ROW){
  166. GuiShowArrow(x+8,y,8,4);//向下箭头
  167. }else{
  168. GuiClearArea(x,y-8,16,8);
  169. }
  170. #endif
  171. }
  172. /********************************************************************************
  173. ListBoxResponse
  174. ListBox控件的键盘响应处理 底层
  175. *******************************************************************************/
  176. unsigned long ListBoxResponseSMS(SUT_LIST_BOX *p)
  177. {
  178. unsigned char temp;
  179. if(p->itemnum==0)return g_ulKeyValue;
  180. switch(g_ulKeyValue)
  181. {
  182. case KEY_PANEL_UP:
  183. ListBoxShowBarSMS(p);//清上一条
  184. p->notehandle--;
  185. if(p->notehandle == 0)
  186. p->notehandle = p->totalnum;
  187. if(p->handle == 0)
  188. {
  189. if(p->totalnum > LIST_ROW)
  190. {
  191. GetPagePreMessage(p,0,'u');
  192. p->pageChange=1;
  193. }else p->handle=p->itemnum-1;
  194. }else
  195. p->handle --;
  196. if(p->pageChange)
  197. p->pageChange=0;
  198. else
  199. ListBoxShowBarSMS(p);
  200. ListBoxItemNumShowSMS(p->notehandle,p->totalnum);
  201. break;
  202. case KEY_PANEL_DOWN:
  203. ListBoxShowBarSMS(p);//清上一条
  204. p->handle ++;
  205. p->notehandle++;
  206. if(p->notehandle > p->totalnum)
  207. p->notehandle=1;
  208. if(p->handle>=p-> itemnum)
  209. {
  210. if(p->totalnum > LIST_ROW)
  211. {
  212. GetPagePreMessage(p,0,'d');
  213. p->pageChange=1;//page change
  214. }else p->handle=0;
  215. }
  216. if(p->pageChange)
  217. p->pageChange=0;
  218. else
  219. ListBoxShowBarSMS(p);
  220. ListBoxItemNumShowSMS(p->notehandle,p->totalnum);
  221. break;
  222. case KEY_PANEL_EXIT:
  223. return g_ulKeyValue;
  224. break;
  225. default:
  226. return g_ulKeyValue;
  227. break;
  228. }
  229. return 0;
  230. }