textbox.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * File : textbox.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-16 Bernard first version
  13. * 2011-01-224 Bernard fix backspace issue.
  14. * 2012-06-09 asml refactor
  15. * 2012-06-17 Grissiom misc cleanup and merge
  16. */
  17. #include <string.h>
  18. #include <rtgui/widgets/textbox.h>
  19. #include <rtgui/widgets/combobox.h>
  20. #include <rtgui/rtgui_system.h>
  21. #include <ctype.h>
  22. static void rtgui_textbox_draw_caret(rtgui_textbox_t *box, rt_uint16_t position);
  23. static rt_bool_t rtgui_textbox_onkey(struct rtgui_object *widget, rtgui_event_t *event);
  24. static rt_bool_t rtgui_textbox_onfocus(struct rtgui_object *widget, rtgui_event_t *event);
  25. static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_object *widget, rtgui_event_t *event);
  26. static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
  27. {
  28. rtgui_rect_t rect;
  29. RTGUI_WIDGET_FLAG(RTGUI_WIDGET(box)) |= RTGUI_WIDGET_FLAG_FOCUSABLE;
  30. rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_textbox_event_handler);
  31. rtgui_widget_set_onfocus(RTGUI_WIDGET(box), rtgui_textbox_onfocus);
  32. rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_textbox_onunfocus);
  33. #ifndef RTGUI_USING_SMALL_SIZE
  34. rtgui_widget_set_onkey(RTGUI_WIDGET(box), rtgui_textbox_onkey);
  35. #endif
  36. RTGUI_WIDGET_FOREGROUND(box) = black;
  37. RTGUI_WIDGET_BACKGROUND(box) = white;
  38. /* set default text align */
  39. RTGUI_WIDGET_TEXTALIGN(box) = RTGUI_ALIGN_CENTER_VERTICAL;
  40. /* set proper of control */
  41. box->caret_timer = RT_NULL;
  42. box->caret = RT_NULL;
  43. box->line = box->line_begin = box->position = 0;
  44. box->flag = RTGUI_TEXTBOX_SINGLE;
  45. /* allocate default line buffer */
  46. box->text = RT_NULL;
  47. rtgui_textbox_set_mask_char(box, '*');
  48. rtgui_font_get_metrics(RTGUI_WIDGET_FONT(box), "H", &rect);
  49. rtgui_widget_set_minheight(RTGUI_WIDGET(box),
  50. rtgui_rect_height(rect) + RTGUI_TEXTBOX_BORDER_WIDTH * 2);
  51. /* at least, we want to display one char. */
  52. rtgui_widget_set_minwidth(RTGUI_WIDGET(box),
  53. rtgui_rect_width(rect) + RTGUI_TEXTBOX_BORDER_WIDTH * 2 \
  54. + RTGUI_WIDGET_DEFAULT_MARGIN /* there is a margin in the beginning
  55. of the text. */
  56. );
  57. box->font_width = rtgui_rect_width(rect);
  58. box->on_enter = RT_NULL;
  59. box->dis_length = 0;
  60. box->first_pos = 0;
  61. }
  62. static void _rtgui_textbox_deconstructor(rtgui_textbox_t *textbox)
  63. {
  64. if (textbox->text != RT_NULL)
  65. {
  66. rtgui_free(textbox->text);
  67. textbox->text = RT_NULL;
  68. }
  69. if (textbox->caret_timer != RT_NULL)
  70. {
  71. rtgui_timer_destory(textbox->caret_timer);
  72. textbox->caret_timer = RT_NULL;
  73. }
  74. if (textbox->caret != RT_NULL)
  75. {
  76. rtgui_free(textbox->caret);
  77. textbox->caret = RT_NULL;
  78. }
  79. }
  80. DEFINE_CLASS_TYPE(textbox, "textbox",
  81. RTGUI_WIDGET_TYPE,
  82. _rtgui_textbox_constructor,
  83. _rtgui_textbox_deconstructor,
  84. sizeof(struct rtgui_textbox));
  85. static void rtgui_textbox_get_caret_rect(rtgui_textbox_t *box, rtgui_rect_t *rect, rt_uint16_t position)
  86. {
  87. int font_h, box_h;
  88. rtgui_rect_t item_rect;
  89. RT_ASSERT(box != RT_NULL);
  90. rtgui_widget_get_rect(RTGUI_WIDGET(box), rect);
  91. rtgui_font_get_metrics(RTGUI_WIDGET_FONT(box), "H", &item_rect);
  92. font_h = rtgui_rect_height(item_rect);
  93. box_h = rtgui_rect_height(*rect);
  94. rect->x1 += position * box->font_width + 2;
  95. rect->x2 = rect->x1 + 2;
  96. rect->y1 += (box_h - font_h) / 2;
  97. rect->y2 = rect->y1 + font_h;
  98. }
  99. static void rtgui_textbox_init_caret(rtgui_textbox_t *box, rt_uint16_t position)
  100. {
  101. int x, y;
  102. rtgui_color_t color;
  103. rtgui_rect_t rect;
  104. int ofs = 0;
  105. RT_ASSERT(box != RT_NULL);
  106. if (!RTGUI_WIDGET_IS_FOCUSED(box))
  107. return;
  108. rtgui_textbox_get_caret_rect(box, &box->caret_rect, position);
  109. rect = box->caret_rect;
  110. rtgui_widget_rect_to_device(RTGUI_WIDGET(box), &rect);
  111. if (box->caret == RT_NULL)
  112. box->caret = rtgui_malloc(rtgui_rect_width(rect) * rtgui_rect_height(rect) * sizeof(rtgui_color_t));
  113. for (x = rect.x1; x < rect.x2; x++)
  114. {
  115. for (y = rect.y1; y < rect.y2; y++)
  116. {
  117. rtgui_graphic_driver_get_default()->ops->get_pixel(&color, x, y);
  118. *(box->caret + ofs) = color;
  119. ofs++;
  120. }
  121. }
  122. }
  123. /* draw caret */
  124. static void rtgui_textbox_draw_caret(rtgui_textbox_t *box, rt_uint16_t position)
  125. {
  126. int x, y;
  127. rtgui_color_t color;
  128. rtgui_rect_t rect;
  129. int ofs = 0;
  130. struct rtgui_dc *dc;
  131. RT_ASSERT(box != RT_NULL);
  132. if (box->caret == RT_NULL)
  133. return;
  134. dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
  135. if (dc == RT_NULL)
  136. return;
  137. rect = box->caret_rect;
  138. for (x = rect.x1; x < rect.x2; x++)
  139. {
  140. for (y = rect.y1; y < rect.y2; y++)
  141. {
  142. color = *(box->caret + ofs);
  143. ofs++;
  144. if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
  145. {
  146. color = ~color;
  147. }
  148. rtgui_dc_draw_color_point(dc, x, y, color);
  149. }
  150. }
  151. rtgui_dc_end_drawing(dc);
  152. }
  153. static void rtgui_textbox_timeout(rtgui_timer_t *timer, void *parameter)
  154. {
  155. rtgui_textbox_t *box;
  156. box = RTGUI_TEXTBOX(parameter);
  157. /* set caret flag */
  158. if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
  159. box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
  160. else
  161. box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
  162. rtgui_textbox_draw_caret(box, box->position);
  163. }
  164. static void rtgui_textbox_onmouse(rtgui_textbox_t *box, struct rtgui_event_mouse *event)
  165. {
  166. rt_size_t length;
  167. rt_uint16_t posbak = box->position;
  168. RT_ASSERT(box != RT_NULL);
  169. RT_ASSERT(event != RT_NULL);
  170. length = rt_strlen(box->text);
  171. if (event->button & RTGUI_MOUSE_BUTTON_LEFT && event->button & RTGUI_MOUSE_BUTTON_DOWN)
  172. {
  173. rt_int32_t x;
  174. /* single line text */
  175. /* set caret position */
  176. x = event->x - RTGUI_WIDGET(box)->extent.x1;
  177. if (x < 0)
  178. {
  179. box->position = 0;
  180. }
  181. else if (x > (length - box->first_pos) * box->font_width)
  182. {
  183. box->position = length - box->first_pos;
  184. }
  185. else
  186. {
  187. box->position = x / box->font_width;
  188. }
  189. if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
  190. {
  191. if (box->caret_timer != RT_NULL)
  192. rtgui_timer_stop(box->caret_timer);
  193. box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
  194. rtgui_textbox_draw_caret(box, posbak);
  195. if (box->caret_timer != RT_NULL)
  196. rtgui_timer_start(box->caret_timer);
  197. }
  198. rtgui_textbox_init_caret(box, box->position);
  199. box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
  200. rtgui_textbox_draw_caret(box, box->position);
  201. }
  202. }
  203. static rt_bool_t rtgui_textbox_onkey(struct rtgui_object *widget, rtgui_event_t *event)
  204. {
  205. rtgui_textbox_t *box = RTGUI_TEXTBOX(widget);
  206. struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
  207. rt_size_t length;
  208. rt_uint16_t posbak = box->position;
  209. RT_ASSERT(box != RT_NULL);
  210. RT_ASSERT(ekbd != RT_NULL);
  211. /* handle the key at down time and nothing to do with up */
  212. if (RTGUI_KBD_IS_UP(ekbd))
  213. return RT_TRUE;
  214. if (box->dis_length == 0)
  215. {
  216. rtgui_rect_t rect;
  217. rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
  218. if (box->font_width == 0)
  219. return RT_FALSE;
  220. box->dis_length = (rtgui_rect_width(rect) - 5) / box->font_width;
  221. }
  222. length = rt_strlen(box->text);
  223. if (ekbd->key == RTGUIK_DELETE)
  224. {
  225. /* delete latter character */
  226. if (box->first_pos + box->position == length - 1)
  227. {
  228. box->text[box->first_pos + box->position] = '\0';
  229. }
  230. else
  231. {
  232. char *c;
  233. /* remove character */
  234. for (c = &box->text[box->first_pos + box->position]; c[1] != '\0'; c++)
  235. *c = c[1];
  236. *c = '\0';
  237. }
  238. }
  239. else if (ekbd->key == RTGUIK_BACKSPACE)
  240. {
  241. /* delete front character */
  242. if (box->position == 0)
  243. {
  244. if(box->first_pos > 0)
  245. {
  246. if(box->first_pos > box->dis_length)
  247. {
  248. box->first_pos -= box->dis_length;
  249. box->position = box->dis_length;
  250. }
  251. else
  252. {
  253. box->position = box->first_pos;
  254. box->first_pos = 0;
  255. }
  256. }
  257. }
  258. else if (box->position == length-box->first_pos)
  259. {
  260. box->text[box->first_pos + box->position - 1] = '\0';
  261. box->position --;
  262. }
  263. else if (box->position != 0)
  264. {
  265. /* remove current character */
  266. if (box->position != 0)
  267. {
  268. char *c;
  269. /* remove character */
  270. for (c = &box->text[box->position - 1]; c[1] != '\0'; c++)
  271. *c = c[1];
  272. *c = '\0';
  273. }
  274. box->position --;
  275. }
  276. }
  277. else if (ekbd->key == RTGUIK_LEFT)
  278. {
  279. /* move to prev */
  280. if (box->position > 0)
  281. {
  282. box->position --;
  283. }
  284. else
  285. {
  286. if(box->first_pos > 0)
  287. box->first_pos -= 1;//DEBUG
  288. }
  289. }
  290. else if (ekbd->key == RTGUIK_RIGHT)
  291. {
  292. /* move to next */
  293. if (box->first_pos + box->position < length)
  294. {
  295. if(box->position < box->dis_length)
  296. box->position ++;
  297. else
  298. box->first_pos += 1;//DEBUG
  299. }
  300. }
  301. else if (ekbd->key == RTGUIK_HOME)
  302. {
  303. /* move cursor to start */
  304. box->position = 0;
  305. box->first_pos = 0;
  306. }
  307. else if (ekbd->key == RTGUIK_END)
  308. {
  309. /* move cursor to end */
  310. if(length > box->dis_length)
  311. {
  312. box->position = box->dis_length;
  313. box->first_pos = length - box->dis_length;
  314. }
  315. else
  316. {
  317. box->position = length;
  318. box->first_pos = 0;
  319. }
  320. }
  321. else if (ekbd->key == RTGUIK_RETURN)
  322. {
  323. if (box->on_enter != RT_NULL)
  324. {
  325. box->on_enter(box, event);
  326. }
  327. }
  328. else if (ekbd->key == RTGUIK_NUMLOCK)
  329. {
  330. /* change numlock state */
  331. /*
  332. extern void update_number_lock(void);
  333. update_number_lock();
  334. */
  335. }
  336. else
  337. {
  338. if (isprint(ekbd->key))
  339. {
  340. /* it's may print character */
  341. /* no buffer on this line */
  342. if (box->flag & RTGUI_TEXTBOX_DIGIT)
  343. {
  344. /* only input digit */
  345. if (!isdigit(ekbd->key))
  346. {
  347. /* exception: '.' and '-' */
  348. if (ekbd->key != '.' && ekbd->key != '-')return RT_FALSE;
  349. if (ekbd->key == '.' && strchr(box->text, '.'))return RT_FALSE;
  350. if (ekbd->key == '-')
  351. {
  352. if (length + 1 > box->line_length) return RT_FALSE;
  353. if (strchr(box->text, '-'))
  354. {
  355. char *c;
  356. for (c = &box->text[0]; c != &box->text[length]; c++)
  357. *c = *(c + 1);
  358. box->text[length] = '\0';
  359. box->position --;
  360. goto _exit;
  361. }
  362. else
  363. {
  364. char *c;
  365. for (c = &box->text[length]; c != &box->text[0]; c--)
  366. *c = *(c - 1);
  367. box->text[0] = '-';
  368. box->text[length + 1] = '\0';
  369. box->position ++;
  370. goto _exit;
  371. }
  372. }
  373. }
  374. }
  375. if (length + 1 > box->line_length) return RT_FALSE;
  376. if (box->first_pos + box->position <= length - 1)
  377. {
  378. char *c;
  379. for (c = &box->text[length]; c != &box->text[box->first_pos + box->position]; c--)
  380. *c = *(c - 1);
  381. box->text[length + 1] = '\0';
  382. }
  383. box->text[box->first_pos + box->position] = ekbd->key;
  384. if(box->position < box->dis_length)
  385. box->position ++;
  386. else
  387. box->first_pos ++;
  388. }
  389. }
  390. _exit:
  391. if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
  392. {
  393. if (box->caret_timer != RT_NULL)
  394. rtgui_timer_stop(box->caret_timer);
  395. box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
  396. rtgui_textbox_draw_caret(box, posbak);/* refresh it */
  397. if (box->caret_timer != RT_NULL)
  398. rtgui_timer_start(box->caret_timer);
  399. }
  400. /* re-draw text box */
  401. rtgui_textbox_ondraw(box);
  402. rtgui_textbox_init_caret(box, box->position);
  403. box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
  404. rtgui_textbox_draw_caret(box, box->position);
  405. return RT_TRUE;
  406. }
  407. static rt_bool_t rtgui_textbox_onfocus(struct rtgui_object *widget, rtgui_event_t *event)
  408. {
  409. rtgui_textbox_t *box = RTGUI_TEXTBOX(widget);
  410. /* if there is already a timer, don't create another one. */
  411. if (box->caret_timer == RT_NULL)
  412. {
  413. box->caret_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC, rtgui_textbox_timeout, box);
  414. /* set caret to show */
  415. box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
  416. /* start caret timer */
  417. if (box->caret_timer != RT_NULL)
  418. rtgui_timer_start(box->caret_timer);
  419. }
  420. return RT_TRUE;
  421. }
  422. static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_object *widget, rtgui_event_t *event)
  423. {
  424. rtgui_textbox_t *box = RTGUI_TEXTBOX(widget);
  425. /* stop caret timer */
  426. if (box->caret_timer != RT_NULL)
  427. {
  428. rtgui_timer_stop(box->caret_timer);
  429. rtgui_timer_destory(box->caret_timer);
  430. box->caret_timer = RT_NULL;
  431. }
  432. /* set caret to hide */
  433. box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
  434. rtgui_textbox_draw_caret(box, box->position);
  435. if (box->on_enter != RT_NULL)
  436. box->on_enter(box, event);
  437. return RT_TRUE;
  438. }
  439. rtgui_textbox_t *rtgui_textbox_create(const char *text, rt_uint32_t flag)
  440. {
  441. rtgui_textbox_t *box;
  442. box = (struct rtgui_textbox *)rtgui_widget_create(RTGUI_TEXTBOX_TYPE);
  443. if (box != RT_NULL)
  444. {
  445. /* allocate default line buffer */
  446. rtgui_textbox_set_value(box, text);
  447. box->flag = flag;
  448. }
  449. return box;
  450. }
  451. void rtgui_textbox_destroy(rtgui_textbox_t *box)
  452. {
  453. rtgui_widget_destroy(RTGUI_WIDGET(box));
  454. }
  455. void rtgui_textbox_ondraw(rtgui_textbox_t *box)
  456. {
  457. /* draw button */
  458. rtgui_rect_t rect;
  459. struct rtgui_dc *dc;
  460. rtgui_color_t fc;
  461. RT_ASSERT(box != RT_NULL);
  462. /* begin drawing */
  463. dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
  464. if (dc == RT_NULL)
  465. return;
  466. /* get widget rect */
  467. rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
  468. fc = RTGUI_WIDGET_FOREGROUND(box);
  469. rtgui_rect_inflate(&rect, -RTGUI_TEXTBOX_BORDER_WIDTH);
  470. /* fill widget rect with white color */
  471. RTGUI_WIDGET_BACKGROUND(box) = white;
  472. rtgui_dc_fill_rect(dc, &rect);
  473. rtgui_rect_inflate(&rect, RTGUI_TEXTBOX_BORDER_WIDTH);
  474. /* draw border */
  475. RTGUI_WIDGET_FOREGROUND(box) = RTGUI_RGB(123, 158, 189);
  476. rtgui_dc_draw_rect(dc, &rect);
  477. /* draw text */
  478. RTGUI_WIDGET_FOREGROUND(box) = fc;
  479. if (box->text != RT_NULL)
  480. {
  481. rect.x1 += RTGUI_WIDGET_DEFAULT_MARGIN;
  482. /* draw single text */
  483. if (box->flag & RTGUI_TEXTBOX_MASK)
  484. {
  485. /* draw mask char */
  486. rt_size_t len = rt_strlen(box->text);
  487. if (len > 0)
  488. {
  489. char *text_mask = rtgui_malloc(len + 1);
  490. rt_memset(text_mask, box->mask_char, len + 1);
  491. text_mask[len] = 0;
  492. rtgui_dc_draw_text(dc, text_mask+box->first_pos, &rect);
  493. rtgui_free(text_mask);
  494. }
  495. }
  496. else
  497. {
  498. rtgui_dc_draw_text(dc, box->text+box->first_pos, &rect);
  499. }
  500. }
  501. rtgui_dc_end_drawing(dc);
  502. }
  503. /* set textbox text */
  504. void rtgui_textbox_set_value(rtgui_textbox_t *box, const char *text)
  505. {
  506. if (box->text != RT_NULL)
  507. {
  508. /* yet exist something */
  509. /* free the old text */
  510. rtgui_free(box->text);
  511. box->text = RT_NULL;
  512. }
  513. /* no something */
  514. box->line_length = ((rt_strlen(text) + 1) / RTGUI_TEXTBOX_LINE_MAX + 1) * RTGUI_TEXTBOX_LINE_MAX;
  515. /* allocate line buffer */
  516. box->text = rtgui_malloc(box->line_length+1);
  517. rt_memset(box->text, 0, box->line_length+1);
  518. /* copy text */
  519. rt_memcpy(box->text, text, rt_strlen(text) + 1);
  520. /* set current position */
  521. box->position = rt_strlen(text);
  522. }
  523. const char *rtgui_textbox_get_value(rtgui_textbox_t *box)
  524. {
  525. return (const char *)box->text;
  526. }
  527. void rtgui_textbox_set_mask_char(rtgui_textbox_t *box, const char ch)
  528. {
  529. box->mask_char = ch;
  530. }
  531. char rtgui_textbox_get_mask_char(rtgui_textbox_t *box)
  532. {
  533. return box->mask_char;
  534. }
  535. rt_err_t rtgui_textbox_set_line_length(rtgui_textbox_t *box, rt_size_t length)
  536. {
  537. char *new_line;
  538. RT_ASSERT(box != RT_NULL);
  539. /* invalid length */
  540. if (length <= 0)
  541. return -RT_ERROR;
  542. new_line = rtgui_realloc(box->text, length+1);
  543. if (new_line == RT_NULL)
  544. return -RT_ENOMEM;
  545. if (length < box->line_length)
  546. new_line[length] = '\0';
  547. box->line_length = length;
  548. box->text = new_line;
  549. return RT_EOK;
  550. }
  551. /* get textbox text area */
  552. void rtgui_textbox_get_edit_rect(rtgui_textbox_t *box, rtgui_rect_t *rect)
  553. {
  554. rtgui_widget_get_rect(RTGUI_WIDGET(box), rect);
  555. rtgui_rect_inflate(rect, -1);
  556. }
  557. rt_bool_t rtgui_textbox_event_handler(struct rtgui_object *object, rtgui_event_t *event)
  558. {
  559. rtgui_widget_t *widget = RTGUI_WIDGET(object);
  560. rtgui_textbox_t *box = RTGUI_TEXTBOX(object);
  561. switch (event->type)
  562. {
  563. case RTGUI_EVENT_PAINT:
  564. #ifndef RTGUI_USING_SMALL_SIZE
  565. if (widget->on_draw != RT_NULL)
  566. widget->on_draw(RTGUI_OBJECT(widget), event);
  567. else
  568. #endif
  569. rtgui_textbox_ondraw(box);
  570. break;
  571. case RTGUI_EVENT_MOUSE_BUTTON:
  572. #ifndef RTGUI_USING_SMALL_SIZE
  573. if (widget->on_mouseclick != RT_NULL)
  574. widget->on_mouseclick(RTGUI_OBJECT(widget), event);
  575. else
  576. #endif
  577. rtgui_textbox_onmouse(box, (struct rtgui_event_mouse *)event);
  578. return RT_TRUE;
  579. case RTGUI_EVENT_KBD:
  580. #ifndef RTGUI_USING_SMALL_SIZE
  581. if (widget->on_key != RT_NULL)
  582. widget->on_key(RTGUI_OBJECT(widget), event);
  583. else
  584. #endif
  585. rtgui_textbox_onkey(RTGUI_OBJECT(box), (struct rtgui_event *)event);
  586. return RT_TRUE;
  587. default:
  588. return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
  589. }
  590. return RT_FALSE;
  591. }