Merge branch 'master' of juyung.seo@165.213.180.234:/git/slp2.0/slp2.0-pkgs/EFL-pkgs...
[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    wd = ELM_NEW(Widget_Data);
75    e = evas_object_evas_get(parent);
76    obj = elm_widget_add(e);
77    ELM_SET_WIDTYPE(widtype, "separator");
78    wd->horizontal = EINA_FALSE;
79    elm_widget_type_set(obj, "separator");
80    elm_widget_sub_object_add(parent, obj);
81    elm_widget_data_set(obj, wd);
82    elm_widget_del_hook_set(obj, _del_hook);
83    elm_widget_theme_hook_set(obj, _theme_hook);
84    elm_widget_can_focus_set(obj, 0);
85
86    wd->sep = edje_object_add(e);
87    _elm_theme_object_set(obj, wd->sep, "separator", "vertical", "default");
88    elm_widget_resize_object_set(obj, wd->sep);
89    _sizing_eval(obj);
90    return obj;
91 }
92
93 /**
94  * Set the horizontal mode of a separator object
95  *
96  * @param obj The separator object
97  * @param horizontal If true, the separator is horizontal
98  *
99  * @ingroup Separator
100  */
101 EAPI void
102 elm_separator_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
103 {
104    ELM_CHECK_WIDTYPE(obj, widtype);
105    Widget_Data *wd = elm_widget_data_get(obj);
106    if (!wd) return;
107    horizontal = !!horizontal;
108    if (wd->horizontal == horizontal) return;
109    wd->horizontal = horizontal;
110    _theme_hook(obj);
111 }
112
113 /**
114  * Get the horizontal mode of a separator object
115  *
116  * @param obj The separator object
117  * @return If true, the separator is horizontal
118  *
119  * @ingroup Separator
120  */
121 EAPI Eina_Bool
122 elm_separator_horizontal_get(const Evas_Object *obj)
123 {
124    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
125    Widget_Data *wd = elm_widget_data_get(obj);
126    if (!wd) return EINA_FALSE;
127    return wd->horizontal;
128 }