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 _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
24 static void _theme_hook(Evas_Object *obj);
25 static void _sizing_eval(Evas_Object *obj);
26 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
27 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
30 _del_hook(Evas_Object *obj)
32 Widget_Data *wd = elm_widget_data_get(obj);
34 if (wd->label) eina_stringshare_del(wd->label);
39 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
41 Widget_Data *wd = elm_widget_data_get(obj);
43 edje_object_mirrored_set(wd->frm, rtl);
47 _theme_hook(Evas_Object *obj)
49 Widget_Data *wd = elm_widget_data_get(obj);
51 _elm_widget_mirrored_reload(obj);
52 _mirrored_set(obj, elm_widget_mirrored_get(obj));
53 _elm_theme_object_set(obj, wd->frm, "frame", "base", elm_widget_style_get(obj));
54 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
56 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
57 edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) * _elm_config->scale);
62 _elm_frame_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
64 Widget_Data *wd = elm_widget_data_get(obj);
67 if ((!wd) || (!wd->content))
72 /* Try Focus cycle in subitem */
73 return elm_widget_focus_next_get(cur, dir, next);
77 _sizing_eval(Evas_Object *obj)
79 Widget_Data *wd = elm_widget_data_get(obj);
80 Evas_Coord minw = -1, minh = -1;
82 edje_object_size_min_calc(wd->frm, &minw, &minh);
83 evas_object_size_hint_min_set(obj, minw, minh);
84 evas_object_size_hint_max_set(obj, -1, -1);
88 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
90 Widget_Data *wd = elm_widget_data_get(data);
91 // FIXME: why is this needed? how does edje get this unswallowed or
92 // lose its callbacks to edje
94 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
99 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
101 Widget_Data *wd = elm_widget_data_get(obj);
102 Evas_Object *sub = event_info;
104 if (sub == wd->content)
106 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
107 _changed_size_hints, obj);
114 * Add a new frame to the parent
116 * @param parent The parent object
117 * @return The new object or NULL if it cannot be created
122 elm_frame_add(Evas_Object *parent)
128 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
130 ELM_SET_WIDTYPE(widtype, "frame");
131 elm_widget_type_set(obj, "frame");
132 elm_widget_sub_object_add(parent, obj);
133 elm_widget_data_set(obj, wd);
134 elm_widget_del_hook_set(obj, _del_hook);
135 elm_widget_theme_hook_set(obj, _theme_hook);
136 elm_widget_focus_next_hook_set(obj, _elm_frame_focus_next_hook);
137 elm_widget_can_focus_set(obj, EINA_FALSE);
139 wd->frm = edje_object_add(e);
140 _elm_theme_object_set(obj, wd->frm, "frame", "base", "default");
141 elm_widget_resize_object_set(obj, wd->frm);
143 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
145 _mirrored_set(obj, elm_widget_mirrored_get(obj));
151 * Set the frame label
153 * @param obj The frame object
154 * @param label The label of this frame object
159 elm_frame_label_set(Evas_Object *obj, const char *label)
161 ELM_CHECK_WIDTYPE(obj, widtype);
162 Widget_Data *wd = elm_widget_data_get(obj);
164 eina_stringshare_replace(&(wd->label), label);
165 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
170 * Get the frame label
172 * @param obj The frame object
174 * @return The label of this frame objet or NULL if unable to get frame
179 elm_frame_label_get(const Evas_Object *obj)
181 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
182 Widget_Data *wd = elm_widget_data_get(obj);
183 if (!wd) return NULL;
188 * Set the content of the frame widget
190 * Once the content object is set, a previously set one will be deleted.
191 * If you want to keep that old content object, use the
192 * elm_frame_content_unset() function.
194 * @param obj The frame object
195 * @param content The content will be filled in this frame object
200 elm_frame_content_set(Evas_Object *obj, Evas_Object *content)
202 ELM_CHECK_WIDTYPE(obj, widtype);
203 Widget_Data *wd = elm_widget_data_get(obj);
205 if (wd->content == content) return;
206 if (wd->content) evas_object_del(wd->content);
207 wd->content = content;
210 elm_widget_sub_object_add(obj, content);
211 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
212 _changed_size_hints, obj);
213 edje_object_part_swallow(wd->frm, "elm.swallow.content", content);
219 * Get the content of the frame widget
221 * Return the content object which is set for this widget
223 * @param obj The frame object
224 * @return The content that is being used
229 elm_frame_content_get(const Evas_Object *obj)
231 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
232 Widget_Data *wd = elm_widget_data_get(obj);
233 if (!wd) return NULL;
238 * Unset the content of the frame widget
240 * Unparent and return the content object which was set for this widget
242 * @param obj The frame object
243 * @return The content that was being used
248 elm_frame_content_unset(Evas_Object *obj)
250 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
251 Widget_Data *wd = elm_widget_data_get(obj);
252 Evas_Object *content;
253 if (!wd) return NULL;
254 if (!wd->content) return NULL;
255 content = wd->content;
256 elm_widget_sub_object_del(obj, wd->content);
257 edje_object_part_unswallow(wd->frm, wd->content);