textbox.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_BORDER_WIDTH 1
  32. #define RTGUI_TEXTBOX_SINGLE 0x00
  33. #define RTGUI_TEXTBOX_MULTI 0x01 /* multiline */
  34. #define RTGUI_TEXTBOX_MASK 0x02 /* ciphertext */
  35. #define RTGUI_TEXTBOX_DIGIT 0x04 /* digit */
  36. #define RTGUI_TEXTBOX_CARET_SHOW 0x10
  37. #define RTGUI_TEXTBOX_CARET_STAT 0x20 /* unused */
  38. #define RTGUI_TEXTBOX_LINE_MAX 128 /* text line cache */
  39. struct rtgui_textbox
  40. {
  41. /* inherit from widget */
  42. struct rtgui_widget parent;
  43. /* text box flag */
  44. rt_uint32_t flag;
  45. /* current line and position */
  46. rt_uint16_t line, line_begin, position;
  47. /** maximum chars a line could hold excluding the NULL byte */
  48. rt_uint16_t line_length;
  49. rt_uint16_t dis_length; /*may be display length.*/
  50. rt_uint16_t first_pos;
  51. char mask_char;
  52. /** a NULL terminated string that the textbox is holding */
  53. char *text;
  54. rt_size_t font_width;
  55. rtgui_timer_t *caret_timer;
  56. rtgui_color_t *caret;
  57. rtgui_rect_t caret_rect;
  58. /* textbox private data */
  59. rt_bool_t (*on_enter)(struct rtgui_textbox *box, rtgui_event_t *event);
  60. };
  61. typedef struct rtgui_textbox rtgui_textbox_t;
  62. rtgui_textbox_t *rtgui_textbox_create(const char *text, rt_uint32_t flag);
  63. void rtgui_textbox_destroy(struct rtgui_textbox *box);
  64. rt_bool_t rtgui_textbox_event_handler(struct rtgui_object *object, struct rtgui_event *event);
  65. void rtgui_textbox_set_value(struct rtgui_textbox *box, const char *text);
  66. const char *rtgui_textbox_get_value(struct rtgui_textbox *box);
  67. void rtgui_textbox_set_mask_char(rtgui_textbox_t *box, const char ch);
  68. char rtgui_textbox_get_mask_char(rtgui_textbox_t *box);
  69. /** set the maximum chars a line could hold excluding the NULL byte
  70. *
  71. * It will truncate the current line if the length is smaller than the chars
  72. * the box is currently holding. But the box->text is guaranteed to be NULL
  73. * terminated anyway.
  74. *
  75. * @param box the text box it operate on
  76. * @param length the new line length. It should be greater than 0.
  77. *
  78. * @return -RT_ERROR on invalid length; -RT_ENOMEM if there is no enough memory
  79. * to allocate the new buffer. On returning -RT_ENOMEM, the original text would
  80. * remain unchanged.
  81. */
  82. rt_err_t rtgui_textbox_set_line_length(struct rtgui_textbox *box, rt_size_t length);
  83. void rtgui_textbox_get_edit_rect(struct rtgui_textbox *box, rtgui_rect_t *rect);
  84. void rtgui_textbox_ondraw(rtgui_textbox_t *box);
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif