textbox.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.h>
  17. #include <rtgui/widgets/widget.h>
  18. DECLARE_CLASS_TYPE(textbox);
  19. /** Gets the type of a textbox */
  20. #define RTGUI_TEXTBOX_TYPE (RTGUI_TYPE(textbox))
  21. /** Casts the object to a rtgui_textbox */
  22. #define RTGUI_TEXTBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_TEXTBOX_TYPE, rtgui_textbox_t))
  23. /** Checks if the object is a rtgui_textbox */
  24. #define RTGUI_IS_TEXTBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_TEXTBOX_TYPE))
  25. #define RTGUI_TEXTBOX_DEFAULT_WIDTH 80
  26. #define RTGUI_TEXTBOX_DEFAULT_HEIGHT 20
  27. #define RTGUI_TEXTBOX_SINGLE 0x00
  28. #define RTGUI_TEXTBOX_MULTI 0x01
  29. #define RTGUI_TEXTBOX_MASK 0x02
  30. #define RTGUI_TEXTBOX_CARET_SHOW 0x10
  31. #define RTGUI_TEXTBOX_CARET_HIDE 0x00
  32. struct rtgui_textbox_line
  33. {
  34. char* line_text;
  35. struct rtgui_textbox_line *prev, *next;
  36. };
  37. struct rtgui_textbox
  38. {
  39. /* inherit from widget */
  40. struct rtgui_widget parent;
  41. /* text box flag */
  42. rt_uint8_t flag;
  43. /* current line and position */
  44. rt_uint16_t line, line_begin, position, line_length;
  45. char* text;
  46. rt_size_t font_width;
  47. struct rtgui_timer* caret_timer;
  48. /* widget private data */
  49. rt_bool_t (*on_enter) (struct rtgui_widget* widget, struct rtgui_event* event);
  50. };
  51. typedef struct rtgui_textbox rtgui_textbox_t;
  52. struct rtgui_textbox* rtgui_textbox_create(const char* text, rt_uint8_t flag);
  53. void rtgui_textbox_destroy(struct rtgui_textbox* box);
  54. rt_bool_t rtgui_textbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
  55. void rtgui_textbox_set_value(struct rtgui_textbox* box, const char* text);
  56. const char* rtgui_textbox_get_value(struct rtgui_textbox* box);
  57. void rtgui_textbox_set_line_length(struct rtgui_textbox* box, rt_size_t length);
  58. #endif