textbox.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * File : textbox.h
  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. */
  14. #ifndef __RTGUI_TEXTBOX_H__
  15. #define __RTGUI_TEXTBOX_H__
  16. #include <rtgui/rtgui_system.h>
  17. #include <rtgui/widgets/widget.h>
  18. #include <rtgui/widgets/container.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. DECLARE_CLASS_TYPE(textbox);
  23. /** Gets the type of a textbox */
  24. #define RTGUI_TEXTBOX_TYPE (RTGUI_TYPE(textbox))
  25. /** Casts the object to a rtgui_textbox_t */
  26. #define RTGUI_TEXTBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_TEXTBOX_TYPE, rtgui_textbox_t))
  27. /** Checks if the object is a rtgui_textbox_t */
  28. #define RTGUI_IS_TEXTBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_TEXTBOX_TYPE))
  29. #define RTGUI_TEXTBOX_DEFAULT_WIDTH 80
  30. #define RTGUI_TEXTBOX_DEFAULT_HEIGHT 20
  31. #define RTGUI_TEXTBOX_SINGLE 0x00
  32. #define RTGUI_TEXTBOX_MULTI 0x01 /* multiline */
  33. #define RTGUI_TEXTBOX_MASK 0x02 /* ciphertext */
  34. #define RTGUI_TEXTBOX_DIGIT 0x04 /* digit */
  35. #define RTGUI_TEXTBOX_CARET_SHOW 0x10
  36. #define RTGUI_TEXTBOX_CARET_STAT 0x20 /* unused */
  37. #define RTGUI_TEXTBOX_LINE_MAX 128 /* text line cache */
  38. struct rtgui_textbox
  39. {
  40. /* inherit from widget */
  41. struct rtgui_widget parent;
  42. /* text box flag */
  43. rt_uint32_t flag;
  44. /* current line and position */
  45. rt_uint16_t line, line_begin, position, line_length;
  46. rt_uint16_t dis_length; /*may be display length.*/
  47. rt_uint16_t first_pos;
  48. char mask_char;
  49. char *text;
  50. rt_size_t font_width;
  51. rtgui_timer_t *caret_timer;
  52. rtgui_color_t *caret;
  53. rtgui_rect_t caret_rect;
  54. /* textbox private data */
  55. rt_bool_t (*on_enter)(struct rtgui_textbox *box, rtgui_event_t *event);
  56. };
  57. typedef struct rtgui_textbox rtgui_textbox_t;
  58. rtgui_textbox_t *rtgui_textbox_create(const char *text, rt_uint32_t flag);
  59. void rtgui_textbox_destroy(struct rtgui_textbox *box);
  60. rt_bool_t rtgui_textbox_event_handler(struct rtgui_object *object, struct rtgui_event *event);
  61. void rtgui_textbox_set_value(struct rtgui_textbox *box, const char *text);
  62. const char *rtgui_textbox_get_value(struct rtgui_textbox *box);
  63. void rtgui_textbox_set_mask_char(rtgui_textbox_t *box, const char ch);
  64. const char rtgui_textbox_get_mask_char(rtgui_textbox_t *box);
  65. void rtgui_textbox_set_line_length(struct rtgui_textbox *box, rt_size_t length);
  66. void rtgui_textbox_get_edit_rect(struct rtgui_textbox *box, rtgui_rect_t *rect);
  67. void rtgui_textbox_ondraw(rtgui_textbox_t *box);
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #endif