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 _elm_frame_label_set(Evas_Object *obj, const char *item, const char *label)
116 ELM_CHECK_WIDTYPE(obj, widtype);
117 Widget_Data *wd = elm_widget_data_get(obj);
120 eina_stringshare_replace(&(wd->label), label);
121 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
126 _elm_frame_label_get(const Evas_Object *obj, const char *item)
128 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
129 Widget_Data *wd = elm_widget_data_get(obj);
130 if (item) return NULL;
131 if (!wd) return NULL;
136 * Add a new frame to the parent
138 * @param parent The parent object
139 * @return The new object or NULL if it cannot be created
144 elm_frame_add(Evas_Object *parent)
150 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
152 ELM_SET_WIDTYPE(widtype, "frame");
153 elm_widget_type_set(obj, "frame");
154 elm_widget_sub_object_add(parent, obj);
155 elm_widget_data_set(obj, wd);
156 elm_widget_del_hook_set(obj, _del_hook);
157 elm_widget_theme_hook_set(obj, _theme_hook);
158 elm_widget_focus_next_hook_set(obj, _elm_frame_focus_next_hook);
159 elm_widget_can_focus_set(obj, EINA_FALSE);
160 elm_widget_text_set_hook_set(obj, _elm_frame_label_set);
161 elm_widget_text_get_hook_set(obj, _elm_frame_label_get);
163 wd->frm = edje_object_add(e);
164 _elm_theme_object_set(obj, wd->frm, "frame", "base", "default");
165 elm_widget_resize_object_set(obj, wd->frm);
167 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
169 _mirrored_set(obj, elm_widget_mirrored_get(obj));
175 * Set the frame label
177 * @param obj The frame object
178 * @param label The label of this frame object
181 * @deprecate use elm_object_text_* instead.
184 elm_frame_label_set(Evas_Object *obj, const char *label)
186 _elm_frame_label_set(obj, NULL, label);
190 * Get the frame label
192 * @param obj The frame object
194 * @return The label of this frame objet or NULL if unable to get frame
197 * @deprecate use elm_object_text_* instead.
200 elm_frame_label_get(const Evas_Object *obj)
202 return _elm_frame_label_get(obj, NULL);
206 * Set the content of the frame widget
208 * Once the content object is set, a previously set one will be deleted.
209 * If you want to keep that old content object, use the
210 * elm_frame_content_unset() function.
212 * @param obj The frame object
213 * @param content The content will be filled in this frame object
218 elm_frame_content_set(Evas_Object *obj, Evas_Object *content)
220 ELM_CHECK_WIDTYPE(obj, widtype);
221 Widget_Data *wd = elm_widget_data_get(obj);
223 if (wd->content == content) return;
224 if (wd->content) evas_object_del(wd->content);
225 wd->content = content;
228 elm_widget_sub_object_add(obj, content);
229 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
230 _changed_size_hints, obj);
231 edje_object_part_swallow(wd->frm, "elm.swallow.content", content);
237 * Get the content of the frame widget
239 * Return the content object which is set for this widget
241 * @param obj The frame object
242 * @return The content that is being used
247 elm_frame_content_get(const Evas_Object *obj)
249 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
250 Widget_Data *wd = elm_widget_data_get(obj);
251 if (!wd) return NULL;
256 * Unset the content of the frame widget
258 * Unparent and return the content object which was set for this widget
260 * @param obj The frame object
261 * @return The content that was being used
266 elm_frame_content_unset(Evas_Object *obj)
268 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
269 Widget_Data *wd = elm_widget_data_get(obj);
270 Evas_Object *content;
271 if (!wd) return NULL;
272 if (!wd->content) return NULL;
273 content = wd->content;
274 elm_widget_sub_object_del(obj, wd->content);
275 edje_object_part_unswallow(wd->frm, wd->content);