button.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * File : button.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_BUTTON_H__
  15. #define __RTGUI_BUTTON_H__
  16. #include <rtgui/image.h>
  17. #include <rtgui/widgets/widget.h>
  18. #include <rtgui/widgets/label.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /**
  23. * @defgroup rtgui_button
  24. * @{
  25. */
  26. DECLARE_CLASS_TYPE(button);
  27. /** Gets the type of a button */
  28. #define RTGUI_BUTTON_TYPE (RTGUI_TYPE(button))
  29. /** Casts the object to an rtgui_button */
  30. #define RTGUI_BUTTON(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_BUTTON_TYPE, rtgui_button_t))
  31. /** Checks if the object is an rtgui_button */
  32. #define RTGUI_IS_BUTTON(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_BUTTON_TYPE))
  33. #define RTGUI_BUTTON_FLAG_PRESS 0x01
  34. #define RTGUI_BUTTON_FLAG_DEFAULT 0x02
  35. #define RTGUI_BUTTON_TYPE_NORMAL 0x00
  36. #define RTGUI_BUTTON_TYPE_PUSH 0x10
  37. /*
  38. * the button widget
  39. */
  40. struct rtgui_button
  41. {
  42. /* inherit from label */
  43. struct rtgui_label parent;
  44. /* button flag */
  45. rt_base_t flag;
  46. /* pressed and unpressed image */
  47. rtgui_image_t *pressed_image, *unpressed_image;
  48. /* click button event handler */
  49. void (*on_button)(struct rtgui_widget* widget, rtgui_event_t *event);
  50. };
  51. typedef struct rtgui_button rtgui_button_t;
  52. rtgui_button_t* rtgui_button_create(const char* text);
  53. rtgui_button_t* rtgui_pushbutton_create(const char* text);
  54. void rtgui_button_destroy(rtgui_button_t* btn);
  55. void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image);
  56. void rtgui_button_set_unpressed_image(rtgui_button_t* btn, rtgui_image_t* image);
  57. void rtgui_button_set_onbutton(rtgui_button_t* btn, rtgui_onbutton_func_t func);
  58. rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_event* event);
  59. /** @} */
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif