staticline.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. default:
  33. return rtgui_widget_event_handler(object, event);
  34. }
  35. return RT_FALSE;
  36. }
  37. RTM_EXPORT(rtgui_staticline_event_handler);
  38. rtgui_staticline_t *rtgui_staticline_create(int orientation)
  39. {
  40. rtgui_staticline_t *staticline;
  41. staticline = (struct rtgui_staticline *) rtgui_widget_create(RTGUI_STATICLINE_TYPE);
  42. if (staticline != RT_NULL)
  43. {
  44. rtgui_staticline_set_orientation(staticline, orientation);
  45. }
  46. return staticline;
  47. }
  48. RTM_EXPORT(rtgui_staticline_create);
  49. void rtgui_staticline_destroy(rtgui_staticline_t *staticline)
  50. {
  51. rtgui_widget_destroy(RTGUI_WIDGET(staticline));
  52. }
  53. RTM_EXPORT(rtgui_staticline_destroy);
  54. void rtgui_staticline_set_orientation(rtgui_staticline_t *staticline, int orientation)
  55. {
  56. RT_ASSERT(staticline != RT_NULL);
  57. staticline->orient = orientation;
  58. #ifndef RTGUI_USING_SMALL_SIZE
  59. if (orientation == RTGUI_HORIZONTAL)
  60. {
  61. /* HORIZONTAL */
  62. rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 2);
  63. rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 100);
  64. }
  65. else
  66. {
  67. /* VERTICAL */
  68. rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 2);
  69. rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 100);
  70. }
  71. #endif
  72. }
  73. RTM_EXPORT(rtgui_staticline_set_orientation);