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