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