1
0

textbox.c 16 KB

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