ListBoxSMS.c 6.5 KB

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