staticline.c 2.0 KB

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