1 #include <Elementary.h>
5 * @defgroup Frame Frame
7 * This holds some content and has a title. Looks like a frame, but
8 * supports styles so multple frames are avaible
11 typedef struct _Widget_Data Widget_Data;
20 static const char *widtype = NULL;
21 static void _del_hook(Evas_Object *obj);
22 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
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 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
40 Widget_Data *wd = elm_widget_data_get(obj);
42 edje_object_mirrored_set(wd->frm, rtl);
46 _theme_hook(Evas_Object *obj)
48 Widget_Data *wd = elm_widget_data_get(obj);
50 _elm_widget_mirrored_reload(obj);
51 _mirrored_set(obj, elm_widget_mirrored_get(obj));
52 _elm_theme_object_set(obj, wd->frm, "frame", "base", elm_widget_style_get(obj));
53 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
55 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
56 edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) * _elm_config->scale);
61 _elm_frame_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
63 Widget_Data *wd = elm_widget_data_get(obj);
66 if ((!wd) || (!wd->content))
71 /* Try Focus cycle in subitem */
72 return elm_widget_focus_next_get(cur, dir, next);
76 _sizing_eval(Evas_Object *obj)
78 Widget_Data *wd = elm_widget_data_get(obj);
79 Evas_Coord minw = -1, minh = -1;
81 edje_object_size_min_calc(wd->frm, &minw, &minh);
82 evas_object_size_hint_min_set(obj, minw, minh);
83 evas_object_size_hint_max_set(obj, -1, -1);
87 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
89 Widget_Data *wd = elm_widget_data_get(data);
90 // FIXME: why is this needed? how does edje get this unswallowed or
91 // lose its callbacks to edje
93 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
98 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
100 Widget_Data *wd = elm_widget_data_get(obj);
101 Evas_Object *sub = event_info;
103 if (sub == wd->content)
105 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
106 _changed_size_hints, obj);
113 _elm_frame_label_set(Evas_Object *obj, const char *item, const char *label)
115 ELM_CHECK_WIDTYPE(obj, widtype);
116 Widget_Data *wd = elm_widget_data_get(obj);
117 if (item && strcmp(item, "default")) return;
119 eina_stringshare_replace(&(wd->label), label);
120 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
125 _elm_frame_label_get(const Evas_Object *obj, const char *item)
127 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
128 Widget_Data *wd = elm_widget_data_get(obj);
129 if (item && strcmp(item, "default")) return NULL;
130 if (!wd) return NULL;
135 * Add a new frame to the parent
137 * @param parent The parent object
138 * @return The new object or NULL if it cannot be created
143 elm_frame_add(Evas_Object *parent)
149 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
151 ELM_SET_WIDTYPE(widtype, "frame");
152 elm_widget_type_set(obj, "frame");
153 elm_widget_sub_object_add(parent, obj);
154 elm_widget_data_set(obj, wd);
155 elm_widget_del_hook_set(obj, _del_hook);
156 elm_widget_theme_hook_set(obj, _theme_hook);
157 elm_widget_focus_next_hook_set(obj, _elm_frame_focus_next_hook);
158 elm_widget_can_focus_set(obj, EINA_FALSE);
159 elm_widget_text_set_hook_set(obj, _elm_frame_label_set);
160 elm_widget_text_get_hook_set(obj, _elm_frame_label_get);
162 wd->frm = edje_object_add(e);
163 _elm_theme_object_set(obj, wd->frm, "frame", "base", "default");
164 elm_widget_resize_object_set(obj, wd->frm);
166 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
168 _mirrored_set(obj, elm_widget_mirrored_get(obj));
174 * Set the frame label
176 * @param obj The frame object
177 * @param label The label of this frame object
180 * @deprecate use elm_object_text_* instead.
183 elm_frame_label_set(Evas_Object *obj, const char *label)
185 _elm_frame_label_set(obj, NULL, label);
189 * Get the frame label
191 * @param obj The frame object
193 * @return The label of this frame objet or NULL if unable to get frame
196 * @deprecate use elm_object_text_* instead.
199 elm_frame_label_get(const Evas_Object *obj)
201 return _elm_frame_label_get(obj, NULL);
205 * Set the content of the frame widget
207 * Once the content object is set, a previously set one will be deleted.
208 * If you want to keep that old content object, use the
209 * elm_frame_content_unset() function.
211 * @param obj The frame object
212 * @param content The content will be filled in this frame object
217 elm_frame_content_set(Evas_Object *obj, Evas_Object *content)
219 ELM_CHECK_WIDTYPE(obj, widtype);
220 Widget_Data *wd = elm_widget_data_get(obj);
222 if (wd->content == content) return;
223 if (wd->content) evas_object_del(wd->content);
224 wd->content = content;
227 elm_widget_sub_object_add(obj, content);
228 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
229 _changed_size_hints, obj);
230 edje_object_part_swallow(wd->frm, "elm.swallow.content", content);
236 * Get the content of the frame widget
238 * Return the content object which is set for this widget
240 * @param obj The frame object
241 * @return The content that is being used
246 elm_frame_content_get(const Evas_Object *obj)
248 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
249 Widget_Data *wd = elm_widget_data_get(obj);
250 if (!wd) return NULL;
255 * Unset the content of the frame widget
257 * Unparent and return the content object which was set for this widget
259 * @param obj The frame object
260 * @return The content that was being used
265 elm_frame_content_unset(Evas_Object *obj)
267 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
268 Widget_Data *wd = elm_widget_data_get(obj);
269 Evas_Object *content;
270 if (!wd) return NULL;
271 if (!wd->content) return NULL;
272 content = wd->content;
273 elm_widget_sub_object_del(obj, wd->content);
274 edje_object_part_unswallow(wd->frm, wd->content);