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 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__, Evas_Object *content)
130 ELM_CHECK_WIDTYPE(obj, widtype);
131 Widget_Data *wd = elm_widget_data_get(obj);
133 if (wd->content == content) return;
134 if (wd->content) evas_object_del(wd->content);
135 wd->content = content;
138 elm_widget_sub_object_add(obj, content);
139 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
140 _changed_size_hints, obj);
141 edje_object_part_swallow(wd->frm, "elm.swallow.content", content);
147 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
149 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
150 Widget_Data *wd = elm_widget_data_get(obj);
151 if (!wd) return NULL;
156 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
158 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
159 Widget_Data *wd = elm_widget_data_get(obj);
160 Evas_Object *content;
161 if (!wd) return NULL;
162 if (!wd->content) return NULL;
163 content = wd->content;
164 elm_widget_sub_object_del(obj, wd->content);
165 evas_object_event_callback_del_full(wd->content,
166 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
167 _changed_size_hints, obj);
168 edje_object_part_unswallow(wd->frm, wd->content);
174 elm_frame_add(Evas_Object *parent)
180 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
182 ELM_SET_WIDTYPE(widtype, "frame");
183 elm_widget_type_set(obj, "frame");
184 elm_widget_sub_object_add(parent, obj);
185 elm_widget_data_set(obj, wd);
186 elm_widget_del_hook_set(obj, _del_hook);
187 elm_widget_theme_hook_set(obj, _theme_hook);
188 elm_widget_focus_next_hook_set(obj, _elm_frame_focus_next_hook);
189 elm_widget_can_focus_set(obj, EINA_FALSE);
190 elm_widget_text_set_hook_set(obj, _elm_frame_label_set);
191 elm_widget_text_get_hook_set(obj, _elm_frame_label_get);
192 elm_widget_content_set_hook_set(obj, _content_set_hook);
193 elm_widget_content_get_hook_set(obj, _content_get_hook);
194 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
196 wd->frm = edje_object_add(e);
197 _elm_theme_object_set(obj, wd->frm, "frame", "base", "default");
198 elm_widget_resize_object_set(obj, wd->frm);
200 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
202 _mirrored_set(obj, elm_widget_mirrored_get(obj));
208 elm_frame_label_set(Evas_Object *obj, const char *label)
210 _elm_frame_label_set(obj, NULL, label);
214 elm_frame_label_get(const Evas_Object *obj)
216 return _elm_frame_label_get(obj, NULL);
220 elm_frame_content_set(Evas_Object *obj, Evas_Object *content)
222 _content_set_hook(obj, NULL, content);
226 elm_frame_content_get(const Evas_Object *obj)
228 return _content_get_hook(obj, NULL);
232 elm_frame_content_unset(Evas_Object *obj)
234 return _content_unset_hook(obj, NULL);