Elementary: Added ui-mirroring support for all the widgets.
[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 _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
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 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
35 {
36    Widget_Data *wd = elm_widget_data_get(obj);
37    if (!wd) return;
38    edje_object_mirrored_set(wd->sep, rtl);
39 }
40
41 static void
42 _theme_hook(Evas_Object *obj)
43 {
44    Widget_Data *wd = elm_widget_data_get(obj);
45    if (!wd) return;
46    _mirrored_set(obj, elm_widget_mirrored_get(obj));
47    if (wd->horizontal)
48      _elm_theme_object_set(obj, wd->sep, "separator", "horizontal", elm_widget_style_get(obj));
49    else
50      _elm_theme_object_set(obj, wd->sep, "separator", "vertical", elm_widget_style_get(obj));
51    edje_object_scale_set(wd->sep, elm_widget_scale_get(obj) * _elm_config->scale);
52    _sizing_eval(obj);
53 }
54
55 static void
56 _sizing_eval(Evas_Object *obj)
57 {
58    Widget_Data *wd = elm_widget_data_get(obj);
59    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
60    if (!wd) return;
61    edje_object_size_min_calc(wd->sep, &minw, &minh);
62    evas_object_size_hint_min_set(obj, minw, minh);
63    evas_object_size_hint_max_set(obj, maxw, maxh);
64    evas_object_size_hint_align_set(obj, maxw, maxh);
65 }
66
67 /**
68  * Add a separator object to @p parent
69  *
70  * @param parent The parent object
71  *
72  * @return The separator object, or NULL upon failure
73  *
74  * @ingroup Separator
75  */
76 EAPI Evas_Object *
77 elm_separator_add(Evas_Object *parent)
78 {
79    Evas_Object *obj;
80    Evas *e;
81    Widget_Data *wd;
82
83    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
84
85    wd = ELM_NEW(Widget_Data);
86    e = evas_object_evas_get(parent);
87    if (!e) return NULL;
88    obj = elm_widget_add(e);
89    ELM_SET_WIDTYPE(widtype, "separator");
90    wd->horizontal = EINA_FALSE;
91    elm_widget_type_set(obj, "separator");
92    elm_widget_sub_object_add(parent, obj);
93    elm_widget_data_set(obj, wd);
94    elm_widget_del_hook_set(obj, _del_hook);
95    elm_widget_theme_hook_set(obj, _theme_hook);
96    elm_widget_can_focus_set(obj, EINA_FALSE);
97
98    wd->sep = edje_object_add(e);
99    _elm_theme_object_set(obj, wd->sep, "separator", "vertical", "default");
100    elm_widget_resize_object_set(obj, wd->sep);
101    _mirrored_set(obj, elm_widget_mirrored_get(obj));
102    _sizing_eval(obj);
103    return obj;
104 }
105
106 /**
107  * Set the horizontal mode of a separator object
108  *
109  * @param obj The separator object
110  * @param horizontal If true, the separator is horizontal
111  *
112  * @ingroup Separator
113  */
114 EAPI void
115 elm_separator_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
116 {
117    ELM_CHECK_WIDTYPE(obj, widtype);
118    Widget_Data *wd = elm_widget_data_get(obj);
119    if (!wd) return;
120    horizontal = !!horizontal;
121    if (wd->horizontal == horizontal) return;
122    wd->horizontal = horizontal;
123    _theme_hook(obj);
124 }
125
126 /**
127  * Get the horizontal mode of a separator object
128  *
129  * @param obj The separator object
130  * @return If true, the separator is horizontal
131  *
132  * @ingroup Separator
133  */
134 EAPI Eina_Bool
135 elm_separator_horizontal_get(const Evas_Object *obj)
136 {
137    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
138    Widget_Data *wd = elm_widget_data_get(obj);
139    if (!wd) return EINA_FALSE;
140    return wd->horizontal;
141 }