textbox.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/caret.h>
  18. #include <rtgui/widgets/widget.h>
  19. /** Gets the type of a textbox */
  20. #define RTGUI_TEXTBOX_TYPE (rtgui_textbox_type_get())
  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 0x00
  29. struct rtgui_textbox_line
  30. {
  31. rt_uint8_t* line_text;
  32. struct rtgui_textbox_line *prev, *next;
  33. };
  34. struct rtgui_textbox
  35. {
  36. /* inherit from widget */
  37. struct rtgui_widget parent;
  38. /* text box type */
  39. rt_ubase_t type;
  40. /* current line and position */
  41. rt_size_t line, line_begin, position, line_length;
  42. rt_uint8_t* text;
  43. rt_size_t font_width;
  44. int caret_x, caret_y;
  45. struct rtgui_caret* caret;
  46. /* widget private data */
  47. rt_bool_t (*on_enter) (struct rtgui_widget* widget, struct rtgui_event* event);
  48. };
  49. typedef struct rtgui_textbox rtgui_textbox_t;
  50. struct rtgui_textbox* rtgui_textbox_create(const char* text);
  51. void rtgui_textbox_destroy(struct rtgui_textbox* box);
  52. rt_bool_t rtgui_textbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
  53. void rtgui_textbox_set_value(struct rtgui_textbox* box, const char* text);
  54. const char* rtgui_textbox_get_value(struct rtgui_textbox* box);
  55. void rtgui_widget_set_line_length(struct rtgui_textbox* box, rt_size_t length);
  56. #endif