1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
13 static const char *widtype = NULL;
14 static void _del_hook(Evas_Object *obj);
15 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
16 static void _theme_hook(Evas_Object *obj);
17 static void _sizing_eval(Evas_Object *obj);
18 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
19 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
22 _del_hook(Evas_Object *obj)
24 Widget_Data *wd = elm_widget_data_get(obj);
26 if (wd->label) eina_stringshare_del(wd->label);
31 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
33 Widget_Data *wd = elm_widget_data_get(obj);
35 edje_object_mirrored_set(wd->frm, rtl);
39 _theme_hook(Evas_Object *obj)
41 Widget_Data *wd = elm_widget_data_get(obj);
43 _elm_widget_mirrored_reload(obj);
44 _mirrored_set(obj, elm_widget_mirrored_get(obj));
45 _elm_theme_object_set(obj, wd->frm, "frame", "base", elm_widget_style_get(obj));
46 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
48 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
49 edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) * _elm_config->scale);
54 _elm_frame_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
56 Widget_Data *wd = elm_widget_data_get(obj);
59 if ((!wd) || (!wd->content))
64 /* Try Focus cycle in subitem */
65 return elm_widget_focus_next_get(cur, dir, next);
69 _sizing_eval(Evas_Object *obj)
71 Widget_Data *wd = elm_widget_data_get(obj);
72 Evas_Coord minw = -1, minh = -1;
74 edje_object_size_min_calc(wd->frm, &minw, &minh);
75 evas_object_size_hint_min_set(obj, minw, minh);
76 evas_object_size_hint_max_set(obj, -1, -1);
80 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
82 Widget_Data *wd = elm_widget_data_get(data);
83 // FIXME: why is this needed? how does edje get this unswallowed or
84 // lose its callbacks to edje
86 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
91 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
93 Widget_Data *wd = elm_widget_data_get(obj);
94 Evas_Object *sub = event_info;
96 if (sub == wd->content)
98 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
99 _changed_size_hints, obj);
106 _elm_frame_label_set(Evas_Object *obj, const char *item, const char *label)
108 ELM_CHECK_WIDTYPE(obj, widtype);
109 Widget_Data *wd = elm_widget_data_get(obj);
110 if (item && strcmp(item, "default")) return;
112 eina_stringshare_replace(&(wd->label), label);
113 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
118 _elm_frame_label_get(const Evas_Object *obj, const char *item)
120 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
121 Widget_Data *wd = elm_widget_data_get(obj);
122 if (item && strcmp(item, "default")) return NULL;
123 if (!wd) return NULL;
128 elm_frame_add(Evas_Object *parent)
134 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
136 ELM_SET_WIDTYPE(widtype, "frame");
137 elm_widget_type_set(obj, "frame");
138 elm_widget_sub_object_add(parent, obj);
139 elm_widget_data_set(obj, wd);
140 elm_widget_del_hook_set(obj, _del_hook);
141 elm_widget_theme_hook_set(obj, _theme_hook);
142 elm_widget_focus_next_hook_set(obj, _elm_frame_focus_next_hook);
143 elm_widget_can_focus_set(obj, EINA_FALSE);
144 elm_widget_text_set_hook_set(obj, _elm_frame_label_set);
145 elm_widget_text_get_hook_set(obj, _elm_frame_label_get);
147 wd->frm = edje_object_add(e);
148 _elm_theme_object_set(obj, wd->frm, "frame", "base", "default");
149 elm_widget_resize_object_set(obj, wd->frm);
151 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
153 _mirrored_set(obj, elm_widget_mirrored_get(obj));
159 elm_frame_label_set(Evas_Object *obj, const char *label)
161 _elm_frame_label_set(obj, NULL, label);
165 elm_frame_label_get(const Evas_Object *obj)
167 return _elm_frame_label_get(obj, NULL);
171 elm_frame_content_set(Evas_Object *obj, Evas_Object *content)
173 ELM_CHECK_WIDTYPE(obj, widtype);
174 Widget_Data *wd = elm_widget_data_get(obj);
176 if (wd->content == content) return;
177 if (wd->content) evas_object_del(wd->content);
178 wd->content = content;
181 elm_widget_sub_object_add(obj, content);
182 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
183 _changed_size_hints, obj);
184 edje_object_part_swallow(wd->frm, "elm.swallow.content", content);
190 elm_frame_content_get(const Evas_Object *obj)
192 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
193 Widget_Data *wd = elm_widget_data_get(obj);
194 if (!wd) return NULL;
199 elm_frame_content_unset(Evas_Object *obj)
201 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
202 Widget_Data *wd = elm_widget_data_get(obj);
203 Evas_Object *content;
204 if (!wd) return NULL;
205 if (!wd->content) return NULL;
206 content = wd->content;
207 elm_widget_sub_object_del(obj, wd->content);
208 edje_object_part_unswallow(wd->frm, wd->content);