staticline.c 2.4 KB
Newer Older
1 2 3 4 5 6
#include <rtgui/dc.h>
#include <rtgui/rtgui_theme.h>
#include <rtgui/widgets/staticline.h>

static void _rtgui_staticline_constructor(rtgui_staticline_t *staticline)
{
7 8
    /* init widget and set event handler */
    rtgui_rect_t rect = {0, 0, 100, 2};
9

10 11
    rtgui_widget_set_rect(RTGUI_WIDGET(staticline), &rect);
    staticline->orient = RTGUI_HORIZONTAL;
12

13
    rtgui_object_set_event_handler(RTGUI_OBJECT(staticline), rtgui_staticline_event_handler);
14 15 16
}


17 18 19 20 21
DEFINE_CLASS_TYPE(staticline, "staticline",
                  RTGUI_WIDGET_TYPE,
                  _rtgui_staticline_constructor,
                  RT_NULL,
                  sizeof(struct rtgui_staticline));
22

23
rt_bool_t rtgui_staticline_event_handler(struct rtgui_object *object, struct rtgui_event *event)
24
{
25 26
    struct rtgui_staticline *staticline;
    RTGUI_WIDGET_EVENT_HANDLER_PREPARE
27

28 29 30 31
    staticline = RTGUI_STATICLINE(object);
    switch (event->type)
    {
    case RTGUI_EVENT_PAINT:
32
#ifndef RTGUI_USING_SMALL_SIZE
33 34 35
        if (widget->on_draw != RT_NULL)
            widget->on_draw(RTGUI_OBJECT(widget), event);
        else
36
#endif
37 38 39 40 41
            rtgui_theme_draw_staticline(staticline);
        break;
    default:
        return rtgui_widget_event_handler(object, event);
    }
42

43
    return RT_FALSE;
44
}
45
RTM_EXPORT(rtgui_staticline_event_handler);
46

47
rtgui_staticline_t *rtgui_staticline_create(int orientation)
48
{
49
    rtgui_staticline_t *staticline;
50

51 52 53 54 55
    staticline = (struct rtgui_staticline *) rtgui_widget_create(RTGUI_STATICLINE_TYPE);
    if (staticline != RT_NULL)
    {
        rtgui_staticline_set_orientation(staticline, orientation);
    }
56

57
    return staticline;
58
}
59
RTM_EXPORT(rtgui_staticline_create);
60

61
void rtgui_staticline_destroy(rtgui_staticline_t *staticline)
62
{
63
    rtgui_widget_destroy(RTGUI_WIDGET(staticline));
64
}
65
RTM_EXPORT(rtgui_staticline_destroy);
66

67
void rtgui_staticline_set_orientation(rtgui_staticline_t *staticline, int orientation)
68
{
69
    RT_ASSERT(staticline != RT_NULL);
70

71
    staticline->orient = orientation;
72
#ifndef RTGUI_USING_SMALL_SIZE
73 74 75
    if (orientation == RTGUI_HORIZONTAL)
    {
        /* HORIZONTAL */
G
Grissiom 已提交
76 77
        rtgui_widget_set_minheight(RTGUI_WIDGET(staticline), 2);
        rtgui_widget_set_minwidth(RTGUI_WIDGET(staticline), 100);
78 79 80 81
    }
    else
    {
        /* VERTICAL */
G
Grissiom 已提交
82 83
        rtgui_widget_set_minwidth(RTGUI_WIDGET(staticline), 2);
        rtgui_widget_set_minheight(RTGUI_WIDGET(staticline), 100);
84
    }
85 86
#endif
}
87 88
RTM_EXPORT(rtgui_staticline_set_orientation);