staticline.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <rtgui/dc.h>
  2. #include <rtgui/rtgui_theme.h>
  3. #include <rtgui/widgets/staticline.h>
  4. static void _rtgui_staticline_constructor(rtgui_staticline_t *staticline)
  5. {
  6. /* init widget and set event handler */
  7. rtgui_rect_t rect = {0, 0, 100, 2};
  8. rtgui_widget_set_rect(RTGUI_WIDGET(staticline), &rect);
  9. staticline->orient= RTGUI_HORIZONTAL;
  10. rtgui_object_set_event_handler(RTGUI_OBJECT(staticline), rtgui_staticline_event_handler);
  11. }
  12. DEFINE_CLASS_TYPE(staticline, "staticline",
  13. RTGUI_WIDGET_TYPE,
  14. _rtgui_staticline_constructor,
  15. RT_NULL,
  16. sizeof(struct rtgui_staticline));
  17. rt_bool_t rtgui_staticline_event_handler(struct rtgui_object* object, struct rtgui_event* event)
  18. {
  19. struct rtgui_staticline* staticline;
  20. RTGUI_WIDGET_EVENT_HANDLER_PREPARE
  21. staticline = RTGUI_STATICLINE(object);
  22. switch (event->type)
  23. {
  24. case RTGUI_EVENT_PAINT:
  25. #ifndef RTGUI_USING_SMALL_SIZE
  26. if (widget->on_draw != RT_NULL)
  27. widget->on_draw(RTGUI_OBJECT(widget), event);
  28. else
  29. #endif
  30. rtgui_theme_draw_staticline(staticline);
  31. break;
  32. }
  33. return RT_FALSE;
  34. }
  35. rtgui_staticline_t * rtgui_staticline_create(int orientation)
  36. {
  37. rtgui_staticline_t* staticline;
  38. staticline = (struct rtgui_staticline*) rtgui_widget_create(RTGUI_STATICLINE_TYPE);
  39. if (staticline!= RT_NULL)
  40. {
  41. rtgui_staticline_set_orientation(staticline, orientation);
  42. }
  43. return staticline;
  44. }
  45. void rtgui_staticline_destroy(rtgui_staticline_t* staticline)
  46. {
  47. rtgui_widget_destroy(RTGUI_WIDGET(staticline));
  48. }
  49. void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orientation)
  50. {
  51. RT_ASSERT(staticline != RT_NULL);
  52. staticline->orient = orientation;
  53. #ifndef RTGUI_USING_SMALL_SIZE
  54. if (orientation == RTGUI_HORIZONTAL)
  55. {
  56. /* HORIZONTAL */
  57. rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 2);
  58. rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 100);
  59. }
  60. else
  61. {
  62. /* VERTICAL */
  63. rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 2);
  64. rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 100);
  65. }
  66. #endif
  67. }