ListBox.c 8.3 KB

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