2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
4 #include <Elementary.h>
9 * @defgroup Selectioninfo selectioninfo
12 * Provide for notifying user about the number of currently selected items
13 * especially when user is on the selection mode for specific action
14 * such as Move, Delete, or Share, etc.
18 #define _EDJ(x) (Evas_Object *)elm_layout_edje_get(x)
20 typedef struct _Widget_Data Widget_Data;
24 Evas_Object* selectioninfo;
27 Eina_Bool* check_state;
32 static const char *widtype = NULL;
33 static void _del_hook(Evas_Object *obj);
34 static void _theme_hook(Evas_Object *obj);
35 static void _sizing_eval(Evas_Object *obj);
36 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
37 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
38 static void _calc(Evas_Object *obj);
39 static void _content_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
40 static void _show(void *data, Evas *e, Evas_Object *obj, void *event_info);
41 static void _hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
42 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
45 _del_pre_hook(Evas_Object *obj)
47 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
48 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOVE, _resize, obj);
49 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_SHOW, _show, obj);
50 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_HIDE, _hide, obj);
54 _del_hook(Evas_Object *obj)
56 Widget_Data *wd = elm_widget_data_get(obj);
58 elm_selectioninfo_content_set(obj, NULL);
59 elm_selectioninfo_parent_set(obj, NULL);
64 _theme_hook(Evas_Object *obj)
66 Widget_Data *wd = elm_widget_data_get(obj);
68 _elm_theme_object_set(obj, wd->selectioninfo, "selectioninfo", "base", "default");
69 edje_object_scale_set(wd->selectioninfo, elm_widget_scale_get(obj) *_elm_config->scale);
74 _sizing_eval(Evas_Object *obj)
76 Widget_Data *wd = elm_widget_data_get(obj);
79 if (!wd->parent) return;
80 evas_object_geometry_get(wd->parent, &x, &y, &w, &h);
81 evas_object_move(obj, x, y);
82 evas_object_resize(obj, w, h);
86 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
92 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
94 Widget_Data *wd = elm_widget_data_get(obj);
96 if (event_info == wd->content) wd->content = NULL;
100 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
106 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
112 _calc(Evas_Object *obj)
114 Widget_Data *wd = elm_widget_data_get(obj);
115 Evas_Coord minw = -1, minh = -1;
116 Evas_Coord x, y, w, h;
118 evas_object_geometry_get(obj, &x, &y, &w, &h);
119 edje_object_size_min_calc(wd->selectioninfo, &minw, &minh);
123 evas_object_move(wd->selectioninfo, x, y + h - minh);
124 evas_object_resize(wd->selectioninfo, w, minh);
131 _show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
133 Widget_Data *wd = elm_widget_data_get(obj);
135 evas_object_show(wd->selectioninfo);
139 _hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
141 Widget_Data *wd = elm_widget_data_get(obj);
143 evas_object_hide(wd->selectioninfo);
147 _parent_del(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
149 Widget_Data *wd = elm_widget_data_get(obj);
152 evas_object_hide(obj);
156 _parent_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
158 Widget_Data *wd = elm_widget_data_get(obj);
161 evas_object_hide(obj);
165 * Add a new selectioninfo to the parent
167 * @param parent The parent object
168 * @return The new object or NULL if it cannot be created
170 * @ingroup Selectioninfo
173 elm_selectioninfo_add(Evas_Object *parent)
179 wd = ELM_NEW(Widget_Data);
180 e = evas_object_evas_get(parent);
181 obj = elm_widget_add(e);
182 ELM_SET_WIDTYPE(widtype, "selectioninfo");
183 elm_widget_type_set(obj, "selectioninfo");
184 elm_widget_sub_object_add(parent, obj);
185 elm_widget_data_set(obj, wd);
186 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
187 elm_widget_del_hook_set(obj, _del_hook);
188 elm_widget_theme_hook_set(obj, _theme_hook);
190 wd->selectioninfo = edje_object_add(e);
191 _elm_theme_object_set(obj, wd->selectioninfo, "selectioninfo", "base", "default");
192 _resize(obj, NULL, obj, NULL);
194 elm_selectioninfo_parent_set(obj, parent);
196 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
197 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
198 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _resize, obj);
199 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _show, obj);
200 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _hide, obj);
207 * Set the selectioninfo content
209 * @param obj The selctioninfo object
210 * @param content The content will be filled in this selectioninfo object
215 elm_selectioninfo_content_set(Evas_Object *obj, Evas_Object *content)
217 ELM_CHECK_WIDTYPE(obj, widtype);
218 Widget_Data *wd = elm_widget_data_get(obj);
222 evas_object_event_callback_del_full(wd->content, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
223 evas_object_event_callback_del_full(wd->content, EVAS_CALLBACK_RESIZE, _content_resize, obj);
224 evas_object_del(wd->content);
230 elm_widget_sub_object_add(obj, content);
231 wd->content = content;
232 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
233 evas_object_event_callback_add(content, EVAS_CALLBACK_RESIZE, _content_resize, obj);
234 edje_object_part_swallow(wd->selectioninfo, "elm.swallow.content", content);
243 * Set the selectioninfo parent
245 * @param obj The selectioninfo object
246 * @param parent The new parent
248 * @ingroup Selectioninfo
251 elm_selectioninfo_parent_set(Evas_Object *obj, Evas_Object *parent)
253 ELM_CHECK_WIDTYPE(obj, widtype);
254 Widget_Data *wd = elm_widget_data_get(obj);
258 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
259 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE, _changed_size_hints, obj);
260 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_MOVE, _changed_size_hints, obj);
261 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, _parent_del, obj);
262 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_HIDE, _parent_hide, obj);
269 evas_object_event_callback_add(parent, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
270 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _changed_size_hints, obj);
271 evas_object_event_callback_add(parent, EVAS_CALLBACK_MOVE, _changed_size_hints, obj);
272 evas_object_event_callback_add(parent, EVAS_CALLBACK_DEL, _parent_del, obj);
273 evas_object_event_callback_add(parent, EVAS_CALLBACK_HIDE, _parent_hide, obj);
281 * Set the check state to the selectioninfo
283 * @param obj The selectioninfo object
284 * @param state The check state
285 * @param count The check count
287 * @ingroup Selectioninfo
290 elm_selectioninfo_check_state_set(Evas_Object *obj, Eina_Bool *state, int count)
292 ELM_CHECK_WIDTYPE(obj, widtype);
293 Widget_Data *wd = elm_widget_data_get(obj);
295 wd->check_state = state;
296 wd->check_count = count;
300 * Show the selectioninfo
302 * @param obj The selectioninfo object
304 * @ingroup Selectioninfo
307 elm_selectioninfo_show(Evas_Object *obj)
309 ELM_CHECK_WIDTYPE(obj, widtype);
310 Widget_Data *wd = elm_widget_data_get(obj);
315 for (i=0; i<wd->check_count; i++)
317 if (wd->check_state[i])
321 if (state_count == 0)
323 evas_object_hide(wd->selectioninfo);
327 if (state_count == 1)
328 sprintf(wd->label_text, "%d File Selected", state_count);
330 sprintf(wd->label_text, "%d Files Selected", state_count);
331 edje_object_part_text_set(_EDJ(wd->content), "elm.text", strdup(wd->label_text));
332 evas_object_show(wd->selectioninfo);