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 _mirrored_set(obj, elm_widget_mirrored_get(obj));
51 _elm_theme_object_set(obj, wd->frm, "frame", "base", elm_widget_style_get(obj));
52 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
54 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
55 edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) * _elm_config->scale);
60 _elm_frame_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
62 Widget_Data *wd = elm_widget_data_get(obj);
65 if ((!wd) || (!wd->content))
70 /* Try Focus cycle in subitem */
71 return elm_widget_focus_next_get(cur, dir, next);
75 _sizing_eval(Evas_Object *obj)
77 Widget_Data *wd = elm_widget_data_get(obj);
78 Evas_Coord minw = -1, minh = -1;
80 edje_object_size_min_calc(wd->frm, &minw, &minh);
81 evas_object_size_hint_min_set(obj, minw, minh);
82 evas_object_size_hint_max_set(obj, -1, -1);
86 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
88 Widget_Data *wd = elm_widget_data_get(data);
89 // FIXME: why is this needed? how does edje get this unswallowed or
90 // lose its callbacks to edje
92 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
97 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
99 Widget_Data *wd = elm_widget_data_get(obj);
100 Evas_Object *sub = event_info;
102 if (sub == wd->content)
104 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
105 _changed_size_hints, obj);
112 * Add a new frame to the parent
114 * @param parent The parent object
115 * @return The new object or NULL if it cannot be created
120 elm_frame_add(Evas_Object *parent)
126 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
128 wd = ELM_NEW(Widget_Data);
129 e = evas_object_evas_get(parent);
131 obj = elm_widget_add(e);
132 ELM_SET_WIDTYPE(widtype, "frame");
133 elm_widget_type_set(obj, "frame");
134 elm_widget_sub_object_add(parent, obj);
135 elm_widget_data_set(obj, wd);
136 elm_widget_del_hook_set(obj, _del_hook);
137 elm_widget_theme_hook_set(obj, _theme_hook);
138 elm_widget_focus_next_hook_set(obj, _elm_frame_focus_next_hook);
139 elm_widget_can_focus_set(obj, EINA_FALSE);
141 wd->frm = edje_object_add(e);
142 _elm_theme_object_set(obj, wd->frm, "frame", "base", "default");
143 elm_widget_resize_object_set(obj, wd->frm);
145 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
147 _mirrored_set(obj, elm_widget_mirrored_get(obj));
153 * Set the frame label
155 * @param obj The frame object
156 * @param label The label of this frame object
161 elm_frame_label_set(Evas_Object *obj, const char *label)
163 ELM_CHECK_WIDTYPE(obj, widtype);
164 Widget_Data *wd = elm_widget_data_get(obj);
166 eina_stringshare_replace(&(wd->label), label);
167 edje_object_part_text_set(wd->frm, "elm.text", wd->label);
172 * Get the frame label
174 * @param obj The frame object
176 * @return The label of this frame objet or NULL if unable to get frame
181 elm_frame_label_get(const Evas_Object *obj)
183 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
184 Widget_Data *wd = elm_widget_data_get(obj);
185 if (!wd) return NULL;
190 * Set the content of the frame widget
192 * Once the content object is set, a previously set one will be deleted.
193 * If you want to keep that old content object, use the
194 * elm_frame_content_unset() function.
196 * @param obj The frame object
197 * @param content The content will be filled in this frame object
202 elm_frame_content_set(Evas_Object *obj, Evas_Object *content)
204 ELM_CHECK_WIDTYPE(obj, widtype);
205 Widget_Data *wd = elm_widget_data_get(obj);
207 if (wd->content == content) return;
208 if (wd->content) evas_object_del(wd->content);
209 wd->content = content;
212 elm_widget_sub_object_add(obj, content);
213 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
214 _changed_size_hints, obj);
215 edje_object_part_swallow(wd->frm, "elm.swallow.content", content);
221 * Get the content of the frame widget
223 * Return the content object which is set for this widget
225 * @param obj The frame object
226 * @return The content that is being used
231 elm_frame_content_get(const Evas_Object *obj)
233 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
234 Widget_Data *wd = elm_widget_data_get(obj);
235 if (!wd) return NULL;
240 * Unset the content of the frame widget
242 * Unparent and return the content object which was set for this widget
244 * @param obj The frame object
245 * @return The content that was being used
250 elm_frame_content_unset(Evas_Object *obj)
252 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
253 Widget_Data *wd = elm_widget_data_get(obj);
254 Evas_Object *content;
255 if (!wd) return NULL;
256 if (!wd->content) return NULL;
257 content = wd->content;
258 elm_widget_sub_object_del(obj, wd->content);
259 edje_object_part_unswallow(wd->frm, wd->content);