ListBox.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. /*************************************************************************
  13. ListBoxInit
  14. ***************************************************************************/
  15. //ListBoxInit(&sutListBox,VoicesName,0,accIconFileName,VoiceFeatures);
  16. void ListBoxInit(struct SUT_LIST_BOX *p,char **itemlist,char unicode,const char **iconlist,char *features)
  17. {
  18. unsigned int kk;
  19. ///////////////////////
  20. unsigned char i,ch;
  21. //统计item
  22. p->item = itemlist;
  23. i = 0;
  24. while(i<LIST_ITEM_NUM_MAX)
  25. {
  26. ch=p->item[i][0];
  27. if(ch==0)break;
  28. i ++;
  29. }
  30. i=i-1;
  31. p->itemnum = i+1;
  32. p->pgaenum=i/LIST_ROW;
  33. if(p->pgaenum%LIST_ROW)p->pgaenum+=1;
  34. //统计icon
  35. i=0;
  36. p->icon=iconlist;
  37. while(i<LIST_ITEM_NUM_MAX)
  38. {
  39. if(iconlist==NULL)break;
  40. ch=p->icon[i][0];
  41. if(ch==0)break;
  42. i ++;
  43. }
  44. p->iconnum=i;
  45. //特性
  46. for(i=0;i<LIST_ITEM_NUM_MAX;i++){
  47. if(i<p->itemnum){
  48. p->features[i]=features[i];
  49. }else{
  50. p->features[i]=0;
  51. }
  52. }
  53. //unicode
  54. p->unicode=unicode;
  55. //默认项
  56. p->page = 0;
  57. p->handle = 0;
  58. sutListBox.handle=sutPocStatus.Page_Up;
  59. //显示
  60. ListBoxShow(p);
  61. }
  62. /*************************************************************************
  63. ListBoxInit
  64. M20
  65. ***************************************************************************/
  66. //ListBoxInit(&sutListBox,VoicesName,0,accIconFileName,VoiceFeatures);
  67. void ListBoxInitM20(struct SUT_LIST_BOX *p,char **itemlist,char unicode,const char **iconlist,char *features,char *time)
  68. {
  69. unsigned int kk;
  70. ///////////////////////
  71. unsigned char i,ch;
  72. //统计item
  73. p->item = itemlist;
  74. i = 0;
  75. while(i<LIST_ITEM_NUM_MAX)
  76. {
  77. ch=p->item[i][0];
  78. if(ch==0)break;
  79. i ++;
  80. }
  81. i=i-1;
  82. p->itemnum = i+1;
  83. p->pgaenum=i/LIST_ROW;
  84. if(p->pgaenum%LIST_ROW)p->pgaenum+=1;
  85. //统计icon
  86. i=0;
  87. p->icon=iconlist;
  88. while(i<LIST_ITEM_NUM_MAX)
  89. {
  90. if(iconlist==NULL)break;
  91. ch=p->icon[i][0];
  92. if(ch==0)break;
  93. i ++;
  94. }
  95. p->iconnum=i;
  96. //特性
  97. for(i=0;i<LIST_ITEM_NUM_MAX;i++){
  98. if(i<p->itemnum){
  99. p->time[i]=time[i];
  100. p->features[i]=features[i];
  101. }else{
  102. p->time[i]=0;
  103. p->features[i]=0;
  104. }
  105. }
  106. //unicode
  107. p->unicode=unicode;
  108. //默认项
  109. p->page = 0;
  110. //p->handle = 4;//等语音记录模块正常,再改为4
  111. //显示
  112. ListBoxShowM20(p);
  113. }
  114. /******************************************************************************
  115. 指定允许的长度截取字符串,如果源长度超过指定长度,则截取之并将最后字符改为".."或"..."
  116. 同时处理中文字符
  117. *******************************************************************************/
  118. void StrIntercept(char *des,char *src,u16 len) //buf msg 12
  119. {
  120. int srclen;
  121. unsigned char d1,d2;
  122. unsigned char *p;
  123. int i;
  124. srclen=strlen(src);
  125. des[len-1]='\0';
  126. strncpy(des,src,len-1);
  127. //if(srclen=len-1 && len>5){
  128. if(srclen>=len-1 && len>5){//防止最后一条没显示..
  129. //将最后两个字符转为".."
  130. des[len-2]='.';
  131. des[len-3]='.';
  132. //判断倒数第3个字符是否为半个中文字符,如果是则将其转为‘.’,避免显示乱码
  133. p=(unsigned char *)des;
  134. i=0;
  135. while(i<(len-4)){
  136. if(*p>0x9f){
  137. p+=2;
  138. i+=2;
  139. }else{
  140. p+=1;
  141. i+=1;
  142. }
  143. }
  144. if(i==(len-4) && *p>0x9f){//半个汉字
  145. des[len-4]='.';
  146. }
  147. }
  148. }
  149. /********************************************************************************
  150. ListBoxShowItem
  151. *******************************************************************************/
  152. void ListBoxShowItem(struct SUT_LIST_BOX *p,unsigned short handle)
  153. {
  154. u16 len;
  155. u16 x,y,hand;
  156. unsigned char buf[LIST_ITEM_TEXT_LEN_MAX+3];
  157. char str[LIST_ITEM_TEXT_LEN_MAX+1];
  158. char f;
  159. hand=handle % LIST_ROW;
  160. x=LIST_TOPX;
  161. y=LIST_TOPY+hand*16;
  162. #if 1 //换页时清理干净
  163. GuiClearArea(x,y,LIST_BAR_LEN+16,16);
  164. #else
  165. GuiClearArea(x,y,LIST_BAR_LEN,16);
  166. #endif
  167. memset(buf,0,sizeof(buf));
  168. if(p->unicode){
  169. StrUnicodeToAnsi(buf,sizeof(buf),p->item[handle]);
  170. buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
  171. }else{
  172. strncpy((char *)buf,p->item[handle],sizeof(buf));
  173. buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
  174. }
  175. //截取并适当补..
  176. StrIntercept(str,(char *)buf,LIST_ITEM_TEXT_LEN_MAX);
  177. if(p->icon!=NULL){//有图标
  178. f= p->features[handle];
  179. GuiShowBmp(x,y,p->icon[f]);
  180. GuiShowStr(x+16,y,str,0x01);
  181. }else{//无图标
  182. GuiShowStr(x,y,str,0x01);
  183. }
  184. }
  185. /********************************************************************************
  186. ListBoxShowItem M20
  187. *******************************************************************************/
  188. void ListBoxShowItemM20(struct SUT_LIST_BOX *p,unsigned short handle)
  189. {
  190. u16 len;
  191. u16 x,y,hand;
  192. unsigned char buf[LIST_ITEM_TEXT_LEN_MAX+3];
  193. char str[LIST_ITEM_TEXT_LEN_MAX+1];
  194. char f,t;
  195. char time[10];
  196. char buf2[50];
  197. hand=handle % LIST_ROW;
  198. x=LIST_TOPX;
  199. y=LIST_TOPY+hand*16;
  200. #if 1 //
  201. GuiClearArea(x,y,160,16);//LIST_BAR_LEN+16
  202. #else
  203. GuiClearArea(x,y,LIST_BAR_LEN,16);
  204. #endif
  205. memset(buf,0,sizeof(buf));
  206. if(p->unicode){
  207. StrUnicodeToAnsi(buf,sizeof(buf),p->item[handle]);
  208. buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
  209. }else{
  210. strncpy((char *)buf,p->item[handle],sizeof(buf));
  211. buf[LIST_ITEM_TEXT_LEN_MAX+2]=0;
  212. }
  213. //截取并适当补..
  214. //printf("src---%s\r\n",buf);
  215. StrIntercept(str,(char *)buf,12);
  216. //printf("str---%s\r\n",str);
  217. len=strlen(str);
  218. //printf("len---%d\r\n",len);
  219. len=GetStrXLen((char *)str);
  220. if(p->icon!=NULL){//有图标
  221. f= p->features[handle];
  222. t=p->time[handle];
  223. snprintf(time,sizeof(time),"%d'",t); //" %d'"
  224. snprintf(buf2,sizeof(buf2),"time len========%d,,,,,len2====%d\r\n",strlen(time),len);
  225. SlwTrace(INF,buf2,1);
  226. if(!f){
  227. GuiShowStr(x,y,str,0x01);
  228. GuiShowBmp(x+len+1,y,p->icon[f]);
  229. GuiShowStr(x+len+1+32,y,time,0x01);
  230. }else{
  231. GuiShowStr(160-len-32-5-strlen(time)*8,y,time,0x01); //5
  232. GuiShowBmp(160-len-32-5,y,p->icon[f]);
  233. GuiShowStr(160-len-5,y,str,0x01);
  234. }
  235. }else{//无图标
  236. GuiShowStr(x,y,str,0x01);
  237. }
  238. }
  239. /********************************************************************************
  240. * Function:ListBoxShowBar
  241. * display a bar
  242. *******************************************************************************/
  243. void ListBoxShowBar(struct SUT_LIST_BOX *p)
  244. {
  245. unsigned char x,y,h,handle;
  246. char *str;
  247. x=LIST_TOPX;
  248. if(p->icon!=NULL){//有图标
  249. x+=16;
  250. }
  251. handle=p->handle%LIST_ROW;
  252. y=LIST_TOPY+handle*16;
  253. GuiReverseRect(x,y,LIST_BAR_LEN,14);
  254. }
  255. /********************************************************************************
  256. * Function:ListBoxShowBar
  257. * display a bar m20
  258. *******************************************************************************/
  259. void ListBoxShowBarM20(struct SUT_LIST_BOX *p)
  260. {
  261. unsigned char x,y,h,handle;
  262. char *str;
  263. x=LIST_TOPX;
  264. // if(p->icon!=NULL){//有图标
  265. // x+=32;
  266. // }
  267. handle=p->handle%LIST_ROW;
  268. y=LIST_TOPY+handle*16; //14
  269. GuiReverseRect(0,y,160,14);//LIST_BAR_LEN 14
  270. }
  271. /********************************************************************************
  272. * Function:ListBoxShow
  273. * display ListBox
  274. *******************************************************************************/
  275. void ListBoxShow(struct SUT_LIST_BOX *p)
  276. {
  277. unsigned char i,j;
  278. u16 x,y;
  279. if(p->itemnum==0)return;
  280. j=p->page*LIST_ROW;
  281. for(i = j ; i <j+LIST_ROW ; i ++)
  282. {
  283. if(i >= p->itemnum){
  284. y=LIST_TOPY+(i % LIST_ROW)*16;
  285. GuiClearArea(LIST_TOPX,y,LIST_BAR_LEN+18,16);
  286. }else{
  287. ListBoxShowItem(p,i);
  288. }
  289. }
  290. ListBoxShowBar(p);
  291. //显示箭头
  292. x=LCD_WIDTH-17;
  293. if(p->page>0){
  294. GuiShowArrow(x+8,LIST_TOPY,8,3);//向上箭头
  295. }else{
  296. GuiClearArea(x,LIST_TOPY,16,8);
  297. }
  298. y=LIST_TOPY+LIST_ROW*16;
  299. if(p->page<(p->pgaenum-1)){
  300. GuiShowArrow(x+8,y,8,4);//向下箭头
  301. }else{
  302. GuiClearArea(x,y-8,16,8);
  303. }
  304. }
  305. /********************************************************************************
  306. * Function:ListBoxShow
  307. * display ListBox
  308. *******************************************************************************/
  309. void ListBoxShowM20(struct SUT_LIST_BOX *p)
  310. {
  311. unsigned char i,j;
  312. u16 x,y;
  313. if(p->itemnum==0)return;
  314. //GuiClearArea(LIST_TOPX,LIST_TOPY,160,79);
  315. //GuiClearRect(LIST_TOPX,LIST_TOPY,LIST_TOPX+160,LIST_TOPY+79);
  316. j=p->page*LIST_ROW;
  317. for(i = j ; i <j+LIST_ROW ; i ++)
  318. {
  319. if(i >= p->itemnum){
  320. y=LIST_TOPY+(i % LIST_ROW)*16;
  321. GuiClearArea(LIST_TOPX,y,160,16);//LIST_BAR_LEN+18
  322. }else{
  323. ListBoxShowItemM20(p,i);
  324. }
  325. }
  326. ListBoxShowBarM20(p);
  327. // //显示箭头
  328. // x=LCD_WIDTH-17;
  329. // if(p->page>0){
  330. // GuiShowArrow(x+8,LIST_TOPY,8,3);//向上箭头
  331. // }else{
  332. // GuiClearArea(x,LIST_TOPY,16,8);
  333. // }
  334. //
  335. // y=LIST_TOPY+LIST_ROW*16;
  336. // if(p->page<(p->pgaenum-1)){
  337. // GuiShowArrow(x+8,y,8,4);//向下箭头
  338. // }else{
  339. // GuiClearArea(x,y-8,16,8);
  340. // }
  341. }
  342. /********************************************************************************
  343. ListBoxResponse
  344. ListBox控件的键盘响应处理 底层
  345. *******************************************************************************/
  346. unsigned long ListBoxResponse(struct SUT_LIST_BOX *p)
  347. {
  348. unsigned char temp;
  349. if(p->itemnum==0)return g_ulKeyValue;
  350. // SUT_PHONE_NUM PhoneNum[N];
  351. // int i = 0;
  352. switch(g_ulKeyValue)
  353. {
  354. case KEY_PANEL_UP:
  355. ListBoxShowBar(p);
  356. #if 0
  357. if(p->handle==0)
  358. {
  359. p->handle=(p->itemnum-1);
  360. //清预览位置
  361. GuiClearArea(LIST_TOPX,LIST_TOPY,LIST_BAR_LEN,16*LIST_ROW);
  362. }
  363. #else
  364. if(p->handle==0)p->handle=(p->itemnum-1);
  365. #endif
  366. else p->handle --;
  367. temp=p->page;
  368. p->page=p->handle/LIST_ROW;
  369. if(temp!=p->page)ListBoxShow(p);
  370. else ListBoxShowBar(p);
  371. break;
  372. case KEY_PANEL_DOWN:
  373. ListBoxShowBar(p);
  374. p->handle ++;
  375. #if 0
  376. if(p->handle>=p-> itemnum)
  377. {
  378. p->handle=0;
  379. //清预览位置
  380. GuiClearArea(LIST_TOPX,LIST_TOPY,LIST_BAR_LEN+16,16*LIST_ROW);
  381. }
  382. #else
  383. if(p->handle>=p-> itemnum)p->handle=0;
  384. #endif
  385. temp = p->page;
  386. p->page=p->handle/LIST_ROW;
  387. if(temp!=p->page)ListBoxShow(p);
  388. else ListBoxShowBar(p);
  389. break;
  390. default:
  391. return g_ulKeyValue;
  392. break;
  393. }
  394. return 0;
  395. }
  396. /********************************************************************************
  397. ListBoxResponse
  398. ListBox控件的键盘响应处理 底层 M20
  399. *******************************************************************************/
  400. unsigned long ListBoxResponseM20(struct SUT_LIST_BOX *p)
  401. {
  402. unsigned char temp;
  403. if(p->itemnum==0)return g_ulKeyValue;
  404. // SUT_PHONE_NUM PhoneNum[N];
  405. // int i = 0;
  406. switch(g_ulKeyValue)
  407. {
  408. case KEY_PANEL_UP :
  409. ListBoxShowBarM20(p);
  410. if(p->handle==0)p->handle=(p->itemnum-1);
  411. else p->handle --;
  412. temp=p->page;
  413. p->page=p->handle/LIST_ROW;
  414. if(temp!=p->page)ListBoxShowM20(p);
  415. else ListBoxShowBarM20(p);
  416. break;
  417. case KEY_PANEL_DOWN :
  418. ListBoxShowBarM20(p);
  419. p->handle ++;
  420. if(p->handle>=p-> itemnum)p->handle=0;
  421. temp = p->page; //当前页
  422. p->page=p->handle/LIST_ROW;
  423. if(temp!=p->page)ListBoxShowM20(p);
  424. else ListBoxShowBarM20(p);
  425. break;
  426. default:
  427. return g_ulKeyValue;
  428. break;
  429. }
  430. return 0;
  431. }
  432. /********************************************************************************
  433. ListBoxGetHandle
  434. 获取ListBox当前手柄
  435. *******************************************************************************/
  436. unsigned short ListBoxGetHandle(struct SUT_LIST_BOX *p)
  437. {
  438. return p->handle;
  439. }