6580bd327756b984e5c1034607e27e26e7fba0c6
[framework/uifw/elementary.git] / src / lib / elm_separator.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Separator Separator
6  *
7  * A separator is a widget that adds a very thin object to separate other objects.
8  * A separator can be vertical or horizontal.
9  */
10
11 typedef struct _Widget_Data Widget_Data;
12
13 struct _Widget_Data
14 {
15    Evas_Object *sep;
16    Eina_Bool horizontal;
17 };
18
19 static const char *widtype = NULL;
20 static void _del_hook(Evas_Object *obj);
21 static void _theme_hook(Evas_Object *obj);
22 static void _sizing_eval(Evas_Object *obj);
23
24 static void
25 _del_hook(Evas_Object *obj)
26 {
27    Widget_Data *wd = elm_widget_data_get(obj);
28    if (!wd) return;
29    free(wd);
30 }
31
32 static void
33 _theme_hook(Evas_Object *obj)
34 {
35    Widget_Data *wd = elm_widget_data_get(obj);
36    if (!wd) return;
37    if (wd->horizontal)
38      _elm_theme_object_set(obj, wd->sep, "separator", "horizontal", elm_widget_style_get(obj));
39    else
40      _elm_theme_object_set(obj, wd->sep, "separator", "vertical", elm_widget_style_get(obj));
41    edje_object_scale_set(wd->sep, elm_widget_scale_get(obj) * _elm_config->scale);
42    _sizing_eval(obj);
43 }
44
45 static void
46 _sizing_eval(Evas_Object *obj)
47 {
48    Widget_Data *wd = elm_widget_data_get(obj);
49    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
50    if (!wd) return;
51    edje_object_size_min_calc(wd->sep, &minw, &minh);
52    evas_object_size_hint_min_set(obj, minw, minh);
53    evas_object_size_hint_max_set(obj, maxw, maxh);
54    evas_object_size_hint_align_set(obj, maxw, maxh);
55 }
56
57 /**
58  * Add a separator object to @p parent
59  *
60  * @param parent The parent object
61  *
62  * @return The separator object, or NULL upon failure
63  *
64  * @ingroup Separator
65  */
66 EAPI Evas_Object *
67 elm_separator_add(Evas_Object *parent)
68 {
69    Evas_Object *obj;
70    Evas *e;
71    Widget_Data *wd;
72
73    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
74
75    wd = ELM_NEW(Widget_Data);
76    e = evas_object_evas_get(parent);
77    if (!e) return NULL;
78    obj = elm_widget_add(e);
79    ELM_SET_WIDTYPE(widtype, "separator");
80    wd->horizontal = EINA_FALSE;
81    elm_widget_type_set(obj, "separator");
82    elm_widget_sub_object_add(parent, obj);
83    elm_widget_data_set(obj, wd);
84    elm_widget_del_hook_set(obj, _del_hook);
85    elm_widget_theme_hook_set(obj, _theme_hook);
86    elm_widget_can_focus_set(obj, EINA_FALSE);
87
88    wd->sep = edje_object_add(e);
89    _elm_theme_object_set(obj, wd->sep, "separator", "vertical", "default");
90    elm_widget_resize_object_set(obj, wd->sep);
91    _sizing_eval(obj);
92    return obj;
93 }
94
95 /**
96  * Set the horizontal mode of a separator object
97  *
98  * @param obj The separator object
99  * @param horizontal If true, the separator is horizontal
100  *
101  * @ingroup Separator
102  */
103 EAPI void
104 elm_separator_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
105 {
106    ELM_CHECK_WIDTYPE(obj, widtype);
107    Widget_Data *wd = elm_widget_data_get(obj);
108    if (!wd) return;
109    horizontal = !!horizontal;
110    if (wd->horizontal == horizontal) return;
111    wd->horizontal = horizontal;
112    _theme_hook(obj);
113 }
114
115 /**
116  * Get the horizontal mode of a separator object
117  *
118  * @param obj The separator object
119  * @return If true, the separator is horizontal
120  *
121  * @ingroup Separator
122  */
123 EAPI Eina_Bool
124 elm_separator_horizontal_get(const Evas_Object *obj)
125 {
126    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
127    Widget_Data *wd = elm_widget_data_get(obj);
128    if (!wd) return EINA_FALSE;
129    return wd->horizontal;
130 }