1 #include <Elementary.h>
5 * @defgroup Frame Frame
8 * This holds some content and has a title. Looks like a frame, but
9 * supports styles so multple frames are avaible
12 typedef struct _Widget_Data Widget_Data;
21 static const char *widtype = NULL;
22 static void _del_hook(Evas_Object *obj);
23 static void _theme_hook(Evas_Object *obj);
24 static void _sizing_eval(Evas_Object *obj);
25 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
26 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
29 _del_hook(Evas_Object *obj)
31 Widget_Data *wd = elm_widget_data_get(obj);
33 if (wd->label) eina_stringshare_del(wd->label);
38 _theme_hook(Evas_Object *obj)
40 Widget_Data *wd = elm_widget_data_get(obj);
42 _elm_theme_object_set(obj, wd->frm, "frame", "base", elm_widget_style_get(obj));
43 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
45 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
46 edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) * _elm_config->scale);
51 _elm_frame_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
53 Widget_Data *wd = elm_widget_data_get(obj);
56 if ((!wd) || (!wd->content))
61 /* Try Focus cycle in subitem */
62 return elm_widget_focus_next_get(cur, dir, next);
66 _sizing_eval(Evas_Object *obj)
68 Widget_Data *wd = elm_widget_data_get(obj);
69 Evas_Coord minw = -1, minh = -1;
71 edje_object_size_min_calc(wd->frm, &minw, &minh);
72 evas_object_size_hint_min_set(obj, minw, minh);
73 evas_object_size_hint_max_set(obj, -1, -1);
77 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
79 Widget_Data *wd = elm_widget_data_get(data);
80 // FIXME: why is this needed? how does edje get this unswallowed or
81 // lose its callbacks to edje
83 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
88 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
90 Widget_Data *wd = elm_widget_data_get(obj);
91 Evas_Object *sub = event_info;
93 if (sub == wd->content)
95 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
96 _changed_size_hints, obj);
103 * Add a new frame to the parent
105 * @param parent The parent object
106 * @return The new object or NULL if it cannot be created
111 elm_frame_add(Evas_Object *parent)
117 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
119 wd = ELM_NEW(Widget_Data);
120 e = evas_object_evas_get(parent);
122 obj = elm_widget_add(e);
123 ELM_SET_WIDTYPE(widtype, "frame");
124 elm_widget_type_set(obj, "frame");
125 elm_widget_sub_object_add(parent, obj);
126 elm_widget_data_set(obj, wd);
127 elm_widget_del_hook_set(obj, _del_hook);
128 elm_widget_theme_hook_set(obj, _theme_hook);
129 elm_widget_focus_next_hook_set(obj, _elm_frame_focus_next_hook);
130 elm_widget_can_focus_set(obj, EINA_FALSE);
132 wd->frm = edje_object_add(e);
133 _elm_theme_object_set(obj, wd->frm, "frame", "base", "default");
134 elm_widget_resize_object_set(obj, wd->frm);
136 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
143 * Set the frame label
145 * @param obj The frame object
146 * @param label The label of this frame object
151 elm_frame_label_set(Evas_Object *obj, const char *label)
153 ELM_CHECK_WIDTYPE(obj, widtype);
154 Widget_Data *wd = elm_widget_data_get(obj);
156 eina_stringshare_replace(&(wd->label), label);
157 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
162 * Get the frame label
164 * @param obj The frame object
166 * @return The label of this frame objet or NULL if unable to get frame
171 elm_frame_label_get(const Evas_Object *obj)
173 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
174 Widget_Data *wd = elm_widget_data_get(obj);
175 if (!wd) return NULL;
180 * Set the content of the frame widget
182 * Once the content object is set, a previously set one will be deleted.
183 * If you want to keep that old content object, use the
184 * elm_frame_content_unset() function.
186 * @param obj The frame object
187 * @param content The content will be filled in this frame object
192 elm_frame_content_set(Evas_Object *obj, Evas_Object *content)
194 ELM_CHECK_WIDTYPE(obj, widtype);
195 Widget_Data *wd = elm_widget_data_get(obj);
197 if (wd->content == content) return;
198 if (wd->content) evas_object_del(wd->content);
199 wd->content = content;
202 elm_widget_sub_object_add(obj, content);
203 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
204 _changed_size_hints, obj);
205 edje_object_part_swallow(wd->frm, "elm.swallow.content", content);
211 * Get the content of the frame widget
213 * Return the content object which is set for this widget
215 * @param obj The frame object
216 * @return The content that is being used
221 elm_frame_content_get(const Evas_Object *obj)
223 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
224 Widget_Data *wd = elm_widget_data_get(obj);
225 if (!wd) return NULL;
230 * Unset the content of the frame widget
232 * Unparent and return the content object which was set for this widget
234 * @param obj The frame object
235 * @return The content that was being used
240 elm_frame_content_unset(Evas_Object *obj)
242 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
243 Widget_Data *wd = elm_widget_data_get(obj);
244 Evas_Object *content;
245 if (!wd) return NULL;
246 if (!wd->content) return NULL;
247 content = wd->content;
248 elm_widget_sub_object_del(obj, wd->content);
249 edje_object_part_unswallow(wd->frm, wd->content);