textbox.h 2.0 KB

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