3 #define SMART_NAME "e_widget"
4 #define API_ENTRY E_Smart_Data * sd; sd = evas_object_smart_data_get(obj); if ((!obj) || (!sd) || (evas_object_type_get(obj) && strcmp(evas_object_type_get(obj), SMART_NAME)))
5 #define INTERNAL_ENTRY E_Smart_Data * sd; sd = evas_object_smart_data_get(obj); if (!sd) return;
6 typedef struct _E_Smart_Data E_Smart_Data;
10 Evas_Object *parent_obj;
11 Evas_Coord x, y, w, h, minw, minh;
13 Evas_Object *resize_obj;
14 void (*del_func)(Evas_Object *obj);
15 void (*focus_func)(Evas_Object *obj);
16 void (*activate_func)(Evas_Object *obj);
17 void (*disable_func)(Evas_Object *obj);
18 void (*on_focus_func)(void *data, Evas_Object *obj);
20 void (*on_change_func)(void *data, Evas_Object *obj);
23 unsigned char can_focus : 1;
24 unsigned char child_can_focus : 1;
25 unsigned char focused : 1;
26 unsigned char disabled : 1;
29 /* local subsystem functions */
30 static void _e_smart_reconfigure(E_Smart_Data *sd);
31 static void _e_smart_add(Evas_Object *obj);
32 static void _e_smart_del(Evas_Object *obj);
33 static void _e_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
34 static void _e_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
35 static void _e_smart_show(Evas_Object *obj);
36 static void _e_smart_hide(Evas_Object *obj);
37 static void _e_smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
38 static void _e_smart_clip_set(Evas_Object *obj, Evas_Object *clip);
39 static void _e_smart_clip_unset(Evas_Object *obj);
40 static void _e_smart_init(void);
42 /* local subsystem globals */
43 static Evas_Smart *_e_smart = NULL;
45 /* externally accessible functions */
47 e_widget_add(Evas *evas)
50 return evas_object_smart_add(evas, _e_smart);
54 e_widget_del_hook_set(Evas_Object *obj, void (*func)(Evas_Object *obj))
61 e_widget_focus_hook_set(Evas_Object *obj, void (*func)(Evas_Object *obj))
64 sd->focus_func = func;
68 e_widget_activate_hook_set(Evas_Object *obj, void (*func)(Evas_Object *obj))
71 sd->activate_func = func;
75 e_widget_disable_hook_set(Evas_Object *obj, void (*func)(Evas_Object *obj))
78 sd->disable_func = func;
82 e_widget_on_focus_hook_set(Evas_Object *obj, void (*func)(void *data, Evas_Object *obj), void *data)
85 sd->on_focus_func = func;
86 sd->on_focus_data = data;
90 e_widget_on_change_hook_set(Evas_Object *obj, void (*func)(void *data, Evas_Object *obj), void *data)
93 sd->on_change_func = func;
94 sd->on_change_data = data;
98 e_widget_data_set(Evas_Object *obj, void *data)
105 e_widget_data_get(Evas_Object *obj)
107 API_ENTRY return NULL;
112 e_widget_size_min_set(Evas_Object *obj, Evas_Coord minw, Evas_Coord minh)
115 if (minw >= 0) sd->minw = minw;
116 if (minh >= 0) sd->minh = minh;
120 e_widget_size_min_get(Evas_Object *obj, Evas_Coord *minw, Evas_Coord *minh)
123 if (minw) *minw = sd->minw;
124 if (minh) *minh = sd->minh;
128 _sub_obj_del(void *data,
131 void *event_info __UNUSED__)
133 E_Smart_Data *sd = data;
135 sd->subobjs = eina_list_remove(sd->subobjs, obj);
136 evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL, _sub_obj_del);
140 e_widget_sub_object_add(Evas_Object *obj, Evas_Object *sobj)
144 if (eina_list_data_find(sd->subobjs, sobj)) return;
146 sd->subobjs = eina_list_append(sd->subobjs, sobj);
147 evas_object_event_callback_add(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
148 if (!sd->child_can_focus)
150 if (e_widget_can_focus_get(sobj)) sd->child_can_focus = 1;
152 if (strcmp(evas_object_type_get(sobj), SMART_NAME)) return;
154 sd = evas_object_smart_data_get(sobj);
157 if (sd->parent_obj) e_widget_sub_object_del(sd->parent_obj, sobj);
158 sd->parent_obj = obj;
160 evas_object_event_callback_del_full(sobj, EVAS_CALLBACK_DEL, _sub_obj_del, sd);
164 e_widget_sub_object_del(Evas_Object *obj, Evas_Object *sobj)
167 evas_object_event_callback_del(sobj, EVAS_CALLBACK_DEL, _sub_obj_del);
168 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
169 if (!sd->child_can_focus)
171 if (e_widget_can_focus_get(sobj)) sd->child_can_focus = 0;
176 e_widget_resize_object_set(Evas_Object *obj, Evas_Object *sobj)
179 if (sd->resize_obj) evas_object_smart_member_del(sd->resize_obj);
180 sd->resize_obj = sobj;
181 evas_object_smart_member_add(sobj, obj);
182 _e_smart_reconfigure(sd);
186 e_widget_can_focus_set(Evas_Object *obj, int can_focus)
189 sd->can_focus = can_focus;
193 e_widget_can_focus_get(Evas_Object *obj)
196 if (sd->disabled) return 0;
197 if (sd->can_focus) return 1;
198 if (sd->child_can_focus) return 1;
203 e_widget_focus_get(Evas_Object *obj)
210 e_widget_focused_object_get(Evas_Object *obj)
213 Evas_Object *sobj = NULL;
215 API_ENTRY return NULL;
216 if (!sd->focused) return NULL;
217 EINA_LIST_FOREACH(sd->subobjs, l, sobj)
219 sobj = e_widget_focused_object_get(sobj);
220 if (sobj) return sobj;
226 e_widget_focus_jump(Evas_Object *obj, int forward)
229 if (!e_widget_can_focus_get(obj)) return 0;
231 /* if it has a focus func its an end-point widget like a button */
234 if (!sd->focused) sd->focused = 1;
235 else sd->focused = 0;
237 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
240 /* its some container */
244 Evas_Object *sobj = NULL;
249 e_widget_focus_set(obj, forward);
251 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
258 EINA_LIST_FOREACH(sd->subobjs, l, sobj)
260 if (!e_widget_can_focus_get(sobj)) continue;
261 if ((focus_next) && (!e_widget_disabled_get(sobj)))
263 /* the previous focused item was unfocused - so focus
264 * the next one (that can be focused) */
265 if (e_widget_focus_jump(sobj, forward))
271 if (e_widget_focus_get(sobj))
273 /* jump to the next focused item or focus this item */
274 if (e_widget_focus_jump(sobj, forward))
276 /* it returned 0 - it got to the last item and is past it */
284 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, sobj)
286 if (e_widget_can_focus_get(sobj))
289 (!e_widget_disabled_get(sobj)))
291 /* the previous focused item was unfocused - so focus
292 * the next one (that can be focused) */
293 if (e_widget_focus_jump(sobj, forward))
299 if (e_widget_focus_get(sobj))
301 /* jump to the next focused item or focus this item */
302 if (e_widget_focus_jump(sobj, forward))
304 /* it returned 0 - it got to the last item and is past it */
313 /* no next item can be focused */
319 e_widget_focus_set(Evas_Object *obj, int first)
325 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
339 EINA_LIST_FOREACH(sd->subobjs, l, sobj)
341 if ((e_widget_can_focus_get(sobj)) &&
342 (!e_widget_disabled_get(sobj)))
344 e_widget_focus_set(sobj, first);
351 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, sobj)
353 if ((e_widget_can_focus_get(sobj)) &&
354 (!e_widget_disabled_get(sobj)))
356 e_widget_focus_set(sobj, first);
365 e_widget_parent_get(Evas_Object *obj)
367 API_ENTRY return NULL;
368 return sd->parent_obj;
372 e_widget_focused_object_clear(Evas_Object *obj)
375 Evas_Object *sobj = NULL;
378 if (!sd->focused) return;
380 EINA_LIST_FOREACH(sd->subobjs, l, sobj)
382 if (e_widget_focus_get(sobj))
384 e_widget_focused_object_clear(sobj);
388 if (sd->focus_func) sd->focus_func(obj);
392 e_widget_focus_steal(Evas_Object *obj)
394 Evas_Object *parent = NULL, *o = NULL;
397 if ((sd->focused) || (sd->disabled) || (!sd->can_focus)) return;
401 o = e_widget_parent_get(parent);
405 e_widget_focused_object_clear(parent);
409 sd = evas_object_smart_data_get(parent);
411 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, parent);
412 o = e_widget_parent_get(parent);
416 sd = evas_object_smart_data_get(obj);
417 if (sd->focus_func) sd->focus_func(obj);
421 e_widget_activate(Evas_Object *obj)
424 e_widget_change(obj);
425 if (sd->activate_func) sd->activate_func(obj);
429 e_widget_change(Evas_Object *obj)
432 if (sd->parent_obj) e_widget_change(sd->parent_obj);
433 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
437 e_widget_disabled_set(Evas_Object *obj, int disabled)
440 if (sd->disabled == disabled) return;
441 sd->disabled = disabled;
444 Evas_Object *o = NULL, *parent = NULL;
449 o = e_widget_parent_get(parent);
453 e_widget_focus_jump(parent, 1);
455 if (sd->disable_func) sd->disable_func(obj);
459 e_widget_disabled_get(Evas_Object *obj)
466 e_widget_pointer_get(Evas_Object *obj)
470 API_ENTRY return NULL;
471 win = e_win_evas_object_win_get(obj);
472 if (win) return win->pointer;
477 e_widget_size_min_resize(Evas_Object *obj)
480 evas_object_resize(obj, sd->minw, sd->minh);
483 /* local subsystem functions */
485 _e_smart_reconfigure(E_Smart_Data *sd)
489 evas_object_move(sd->resize_obj, sd->x, sd->y);
490 evas_object_resize(sd->resize_obj, sd->w, sd->h);
495 _e_smart_add(Evas_Object *obj)
497 E_Smart_Data *sd = NULL;
499 sd = calloc(1, sizeof(E_Smart_Data));
506 evas_object_smart_data_set(obj, sd);
510 _e_smart_del(Evas_Object *obj)
514 if (sd->del_func) sd->del_func(obj);
517 Evas_Object *sobj = sd->subobjs->data;
518 /* DO NOT MACRO THIS!
519 * list gets reshuffled during object delete callback chain
520 * and breaks the world.
521 * BORKER CERTIFICATION: GOLD
522 * -discomfitor, 7/4/2012
524 sd->subobjs = eina_list_remove_list(sd->subobjs, sd->subobjs);
525 evas_object_del(sobj);
531 _e_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
536 _e_smart_reconfigure(sd);
540 _e_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
545 _e_smart_reconfigure(sd);
549 _e_smart_show(Evas_Object *obj)
553 evas_object_show(sd->resize_obj);
557 _e_smart_hide(Evas_Object *obj)
561 evas_object_hide(sd->resize_obj);
565 _e_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
569 evas_object_color_set(sd->resize_obj, r, g, b, a);
573 _e_smart_clip_set(Evas_Object *obj, Evas_Object *clip)
577 evas_object_clip_set(sd->resize_obj, clip);
581 _e_smart_clip_unset(Evas_Object *obj)
585 evas_object_clip_unset(sd->resize_obj);
588 /* never need to touch this */
593 if (_e_smart) return;
595 static const Evas_Smart_Class sc =
598 EVAS_SMART_CLASS_VERSION,
616 _e_smart = evas_smart_class_new(&sc);