elementary/map - map supports language,changed
[framework/uifw/elementary.git] / src / lib / elm_separator.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "elm_widget_separator.h"
4
5 EAPI const char ELM_SEPARATOR_SMART_NAME[] = "elm_separator";
6
7 EVAS_SMART_SUBCLASS_NEW
8   (ELM_SEPARATOR_SMART_NAME, _elm_separator, Elm_Separator_Smart_Class,
9   Elm_Layout_Smart_Class, elm_layout_smart_class_get, NULL);
10
11 static Eina_Bool
12 _elm_separator_smart_theme(Evas_Object *obj)
13 {
14    ELM_SEPARATOR_DATA_GET(obj, sd);
15
16    if (sd->horizontal)
17      eina_stringshare_replace(&(ELM_LAYOUT_DATA(sd)->group), "horizontal");
18    else
19      eina_stringshare_replace(&(ELM_LAYOUT_DATA(sd)->group), "vertical");
20
21    if (!ELM_WIDGET_CLASS(_elm_separator_parent_sc)->theme(obj))
22      return EINA_FALSE;
23
24    return EINA_TRUE;
25 }
26
27 static void
28 _elm_separator_smart_sizing_eval(Evas_Object *obj)
29 {
30    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
31
32    ELM_SEPARATOR_DATA_GET(obj, sd);
33
34    edje_object_size_min_calc(ELM_WIDGET_DATA(sd)->resize_obj, &minw, &minh);
35    evas_object_size_hint_min_set(obj, minw, minh);
36    evas_object_size_hint_max_set(obj, maxw, maxh);
37    evas_object_size_hint_align_set(obj, maxw, maxh);
38 }
39
40 static void
41 _elm_separator_smart_add(Evas_Object *obj)
42 {
43    EVAS_SMART_DATA_ALLOC(obj, Elm_Separator_Smart_Data);
44
45    ELM_WIDGET_CLASS(_elm_separator_parent_sc)->base.add(obj);
46
47    priv->horizontal = EINA_FALSE;
48
49    elm_widget_can_focus_set(obj, EINA_FALSE);
50
51    elm_layout_theme_set
52      (obj, "separator", "vertical", elm_widget_style_get(obj));
53
54    elm_layout_sizing_eval(obj);
55 }
56
57 static void
58 _elm_separator_smart_set_user(Elm_Separator_Smart_Class *sc)
59 {
60    ELM_WIDGET_CLASS(sc)->base.add = _elm_separator_smart_add;
61
62    ELM_WIDGET_CLASS(sc)->theme = _elm_separator_smart_theme;
63
64    /* not a 'focus chain manager' */
65    ELM_WIDGET_CLASS(sc)->focus_next = NULL;
66    ELM_WIDGET_CLASS(sc)->focus_direction = NULL;
67
68    ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_separator_smart_sizing_eval;
69 }
70
71 EAPI const Elm_Separator_Smart_Class *
72 elm_separator_smart_class_get(void)
73 {
74    static Elm_Separator_Smart_Class _sc =
75      ELM_SEPARATOR_SMART_CLASS_INIT_NAME_VERSION(ELM_SEPARATOR_SMART_NAME);
76    static const Elm_Separator_Smart_Class *class = NULL;
77
78    if (class)
79      return class;
80
81    _elm_separator_smart_set(&_sc);
82    class = &_sc;
83
84    return class;
85 }
86
87 EAPI Evas_Object *
88 elm_separator_add(Evas_Object *parent)
89 {
90    Evas_Object *obj;
91
92    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
93
94    obj = elm_widget_add(_elm_separator_smart_class_new(), parent);
95    if (!obj) return NULL;
96
97    if (!elm_widget_sub_object_add(parent, obj))
98      ERR("could not add %p as sub object of %p", obj, parent);
99
100    return obj;
101 }
102
103 EAPI void
104 elm_separator_horizontal_set(Evas_Object *obj,
105                              Eina_Bool horizontal)
106 {
107    ELM_SEPARATOR_CHECK(obj);
108    ELM_SEPARATOR_DATA_GET(obj, sd);
109
110    horizontal = !!horizontal;
111    if (sd->horizontal == horizontal) return;
112
113    sd->horizontal = horizontal;
114
115    _elm_separator_smart_theme(obj);
116 }
117
118 EAPI Eina_Bool
119 elm_separator_horizontal_get(const Evas_Object *obj)
120 {
121    ELM_SEPARATOR_CHECK(obj) EINA_FALSE;
122    ELM_SEPARATOR_DATA_GET(obj, sd);
123
124    return sd->horizontal;
125 }