1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
11 unsigned int recalc_count;
12 Eina_Bool collapsed : 1;
13 Eina_Bool collapsible : 1;
17 static const char SIG_CLICKED[] = "clicked";
19 static const Evas_Smart_Cb_Description _signals[] = {
24 static const char *widtype = NULL;
25 static void _del_hook(Evas_Object *obj);
26 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
27 static void _theme_hook(Evas_Object *obj);
28 static void _sizing_eval(Evas_Object *obj);
29 static void _changed_size_hints(void *data,
30 Evas *e, Evas_Object *obj,
32 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
35 _del_hook(Evas_Object *obj)
37 Widget_Data *wd = elm_widget_data_get(obj);
39 if (wd->label) eina_stringshare_del(wd->label);
44 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
46 Widget_Data *wd = elm_widget_data_get(obj);
48 edje_object_mirrored_set(wd->frm, rtl);
52 _theme_hook(Evas_Object *obj)
54 Widget_Data *wd = elm_widget_data_get(obj);
56 _elm_widget_mirrored_reload(obj);
57 _mirrored_set(obj, elm_widget_mirrored_get(obj));
58 _elm_theme_object_set(obj, wd->frm, "frame", "base",
59 elm_widget_style_get(obj));
60 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
62 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
63 edje_object_scale_set(wd->frm,
64 elm_widget_scale_get(obj) * _elm_config->scale);
69 _elm_frame_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
71 Widget_Data *wd = elm_widget_data_get(obj);
73 if ((!wd) || (!wd->content))
76 /* Try Focus cycle in subitem */
77 return elm_widget_focus_next_get(wd->content, dir, next);
81 _sizing_eval(Evas_Object *obj)
83 Widget_Data *wd = elm_widget_data_get(obj);
84 Evas_Coord minw = -1, minh = -1;
85 Evas_Coord cminw = -1, cminh = -1;
87 edje_object_size_min_calc(wd->frm, &minw, &minh);
88 evas_object_size_hint_min_get(obj, &cminw, &cminh);
89 if ((minw == cminw) && (minh == cminh)) return;
90 evas_object_size_hint_min_set(obj, minw, minh);
91 evas_object_size_hint_max_set(obj, -1, -1);
95 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
97 Widget_Data *wd = elm_widget_data_get(data);
100 // FIXME: why is this needed? how does edje get this unswallowed or
101 // lose its callbacks to edje
102 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
107 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
109 Widget_Data *wd = elm_widget_data_get(obj);
110 Evas_Object *sub = event_info;
112 if (sub == wd->content)
114 evas_object_event_callback_del_full(sub,
115 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
116 _changed_size_hints, obj);
123 _elm_frame_label_set(Evas_Object *obj, const char *item, const char *label)
125 ELM_CHECK_WIDTYPE(obj, widtype);
126 Widget_Data *wd = elm_widget_data_get(obj);
127 if (item && strcmp(item, "default")) return;
129 eina_stringshare_replace(&(wd->label), label);
130 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
135 _elm_frame_label_get(const Evas_Object *obj, const char *item)
137 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
138 Widget_Data *wd = elm_widget_data_get(obj);
139 if (!wd) return NULL;
140 if (item && strcmp(item, "default")) return NULL;
145 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
147 ELM_CHECK_WIDTYPE(obj, widtype);
150 if (part && strcmp(part, "default")) return;
151 wd = elm_widget_data_get(obj);
153 if (wd->content == content) return;
154 if (wd->content) evas_object_del(wd->content);
155 wd->content = content;
158 elm_widget_sub_object_add(obj, content);
159 evas_object_event_callback_add(content,
160 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
161 _changed_size_hints, obj);
162 edje_object_part_swallow(wd->frm, "elm.swallow.content", content);
168 _content_get_hook(const Evas_Object *obj, const char *part)
170 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
173 if (part && strcmp(part, "default")) return NULL;
174 wd = elm_widget_data_get(obj);
175 if (!wd) return NULL;
181 _content_unset_hook(Evas_Object *obj, const char *part)
183 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
185 Evas_Object *content;
186 if (part && strcmp(part, "default")) return NULL;
187 wd = elm_widget_data_get(obj);
188 if (!wd || !wd->content) return NULL;
189 content = wd->content;
190 elm_widget_sub_object_del(obj, wd->content);
191 edje_object_part_unswallow(wd->frm, content);
196 _recalc(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
202 _recalc_done(void *data, Evas_Object *obj __UNUSED__, const char *sig __UNUSED__, const char *src __UNUSED__)
204 Widget_Data *wd = elm_widget_data_get(data);
206 evas_object_smart_callback_del(wd->frm, "recalc", _recalc);
207 wd->anim = EINA_FALSE;
212 _signal_click(void *data, Evas_Object *obj __UNUSED__, const char *sig __UNUSED__, const char *src __UNUSED__)
214 Widget_Data *wd = elm_widget_data_get(data);
216 if (wd->anim) return;
219 evas_object_smart_callback_add(wd->frm, "recalc", _recalc, data);
220 edje_object_signal_emit(wd->frm, "elm,action,toggle", "elm");
222 wd->anim = EINA_TRUE;
224 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
228 elm_frame_add(Evas_Object *parent)
234 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
236 ELM_SET_WIDTYPE(widtype, "frame");
237 elm_widget_type_set(obj, "frame");
238 elm_widget_sub_object_add(parent, obj);
239 elm_widget_data_set(obj, wd);
240 elm_widget_del_hook_set(obj, _del_hook);
241 elm_widget_theme_hook_set(obj, _theme_hook);
242 elm_widget_focus_next_hook_set(obj, _elm_frame_focus_next_hook);
243 elm_widget_can_focus_set(obj, EINA_FALSE);
244 elm_widget_text_set_hook_set(obj, _elm_frame_label_set);
245 elm_widget_text_get_hook_set(obj, _elm_frame_label_get);
246 elm_widget_content_set_hook_set(obj, _content_set_hook);
247 elm_widget_content_get_hook_set(obj, _content_get_hook);
248 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
250 wd->frm = edje_object_add(e);
251 _elm_theme_object_set(obj, wd->frm, "frame", "base", "default");
252 elm_widget_resize_object_set(obj, wd->frm);
254 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
255 edje_object_signal_callback_add(wd->frm, "elm,anim,done", "elm",
257 edje_object_signal_callback_add(wd->frm, "elm,action,click", "elm",
259 evas_object_smart_callbacks_descriptions_set(obj, _signals);
261 _mirrored_set(obj, elm_widget_mirrored_get(obj));
267 elm_frame_autocollapse_set(Evas_Object *obj, Eina_Bool autocollapse)
270 ELM_CHECK_WIDTYPE(obj, widtype);
271 wd = elm_widget_data_get(obj);
273 wd->collapsible = !!autocollapse;
277 elm_frame_autocollapse_get(const Evas_Object *obj)
280 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
281 wd = elm_widget_data_get(obj);
282 if (!wd) return EINA_FALSE;
283 return wd->collapsible;
287 elm_frame_collapse_set(Evas_Object *obj, Eina_Bool collapse)
290 ELM_CHECK_WIDTYPE(obj, widtype);
291 wd = elm_widget_data_get(obj);
293 collapse = !!collapse;
294 if (wd->collapsed == collapse) return;
295 edje_object_signal_emit(wd->frm, "elm,action,switch", "elm");
296 edje_object_message_signal_process(wd->frm);
297 wd->collapsed = !!collapse;
298 wd->anim = EINA_FALSE;
303 elm_frame_collapse_go(Evas_Object *obj, Eina_Bool collapse)
306 ELM_CHECK_WIDTYPE(obj, widtype);
307 wd = elm_widget_data_get(obj);
309 collapse = !!collapse;
310 if (wd->collapsed == collapse) return;
311 edje_object_signal_emit(wd->frm, "elm,action,toggle", "elm");
312 evas_object_smart_callback_add(wd->frm, "recalc", _recalc, obj);
313 wd->collapsed = collapse;
314 wd->anim = EINA_TRUE;
318 elm_frame_collapse_get(const Evas_Object *obj)
321 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
322 wd = elm_widget_data_get(obj);
323 if (!wd) return EINA_FALSE;
324 return wd->collapsed;