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