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