button.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. rtgui_onbutton_func_t on_button;
  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. /** Set the callback function on button btn
  58. *
  59. * If the btn is a push button, the callback will be invoked every
  60. * time the btn got "pushed", i.e., both pressed down @em and pressed
  61. * up. If the button is a normal button, the callback will be invoked when
  62. * the btn got "clicked", i.e., when pressed up @em after pressed
  63. * down.
  64. *
  65. * @param btn the btn that the callback will be setted on.
  66. * @param func the callback function.
  67. */
  68. void rtgui_button_set_onbutton(rtgui_button_t *btn, rtgui_onbutton_func_t func);
  69. rt_bool_t rtgui_button_event_handler(struct rtgui_object *object, struct rtgui_event *event);
  70. /** @} */
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif