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 e_widget_sub_object_add(Evas_Object *obj, Evas_Object *sobj)
131 sd->subobjs = eina_list_append(sd->subobjs, sobj);
132 if (!sd->child_can_focus)
134 if (e_widget_can_focus_get(sobj)) sd->child_can_focus = 1;
136 if (!strcmp(evas_object_type_get(sobj), SMART_NAME))
138 sd = evas_object_smart_data_get(sobj);
141 if (sd->parent_obj) e_widget_sub_object_del(sd->parent_obj, sobj);
142 sd->parent_obj = obj;
148 e_widget_sub_object_del(Evas_Object *obj, Evas_Object *sobj)
151 sd->subobjs = eina_list_remove(sd->subobjs, sobj);
152 if (!sd->child_can_focus)
154 if (e_widget_can_focus_get(sobj)) sd->child_can_focus = 0;
159 e_widget_resize_object_set(Evas_Object *obj, Evas_Object *sobj)
162 if (sd->resize_obj) evas_object_smart_member_del(sd->resize_obj);
163 sd->resize_obj = sobj;
164 evas_object_smart_member_add(sobj, obj);
165 _e_smart_reconfigure(sd);
169 e_widget_can_focus_set(Evas_Object *obj, int can_focus)
172 sd->can_focus = can_focus;
176 e_widget_can_focus_get(Evas_Object *obj)
179 if (sd->can_focus) return 1;
180 if (sd->child_can_focus) return 1;
185 e_widget_focus_get(Evas_Object *obj)
192 e_widget_focused_object_get(Evas_Object *obj)
195 Evas_Object *sobj = NULL;
197 API_ENTRY return NULL;
198 if (!sd->focused) return NULL;
199 EINA_LIST_FOREACH(sd->subobjs, l, sobj)
201 sobj = e_widget_focused_object_get(sobj);
202 if (sobj) return sobj;
208 e_widget_focus_jump(Evas_Object *obj, int forward)
211 if (!e_widget_can_focus_get(obj)) return 0;
213 /* if it has a focus func its an end-point widget like a button */
216 if (!sd->focused) sd->focused = 1;
217 else sd->focused = 0;
219 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
222 /* its some container */
226 Evas_Object *sobj = NULL;
231 e_widget_focus_set(obj, forward);
233 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
240 EINA_LIST_FOREACH(sd->subobjs, l, sobj)
242 if (e_widget_can_focus_get(sobj))
245 (!e_widget_disabled_get(sobj)))
247 /* the previous focused item was unfocused - so focus
248 * the next one (that can be focused) */
249 if (e_widget_focus_jump(sobj, forward))
255 if (e_widget_focus_get(sobj))
257 /* jump to the next focused item or focus this item */
258 if (e_widget_focus_jump(sobj, forward))
260 /* it returned 0 - it got to the last item and is past it */
269 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, sobj)
271 if (e_widget_can_focus_get(sobj))
274 (!e_widget_disabled_get(sobj)))
276 /* the previous focused item was unfocused - so focus
277 * the next one (that can be focused) */
278 if (e_widget_focus_jump(sobj, forward))
284 if (e_widget_focus_get(sobj))
286 /* jump to the next focused item or focus this item */
287 if (e_widget_focus_jump(sobj, forward))
289 /* it returned 0 - it got to the last item and is past it */
298 /* no next item can be focused */
304 e_widget_focus_set(Evas_Object *obj, int first)
310 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, obj);
324 EINA_LIST_FOREACH(sd->subobjs, l, sobj)
326 if ((e_widget_can_focus_get(sobj)) &&
327 (!e_widget_disabled_get(sobj)))
329 e_widget_focus_set(sobj, first);
336 EINA_LIST_REVERSE_FOREACH(sd->subobjs, l, sobj)
338 if ((e_widget_can_focus_get(sobj)) &&
339 (!e_widget_disabled_get(sobj)))
341 e_widget_focus_set(sobj, first);
350 e_widget_parent_get(Evas_Object *obj)
352 API_ENTRY return NULL;
353 return sd->parent_obj;
357 e_widget_focused_object_clear(Evas_Object *obj)
360 Evas_Object *sobj = NULL;
363 if (!sd->focused) return;
365 EINA_LIST_FOREACH(sd->subobjs, l, sobj)
367 if (e_widget_focus_get(sobj))
369 e_widget_focused_object_clear(sobj);
373 if (sd->focus_func) sd->focus_func(obj);
377 e_widget_focus_steal(Evas_Object *obj)
379 Evas_Object *parent = NULL, *o = NULL;
382 if ((sd->focused) || (sd->disabled)) return;
386 o = e_widget_parent_get(parent);
390 e_widget_focused_object_clear(parent);
394 sd = evas_object_smart_data_get(parent);
396 if (sd->on_focus_func) sd->on_focus_func(sd->on_focus_data, parent);
397 o = e_widget_parent_get(parent);
401 sd = evas_object_smart_data_get(obj);
402 if (sd->focus_func) sd->focus_func(obj);
406 e_widget_activate(Evas_Object *obj)
409 e_widget_change(obj);
410 if (sd->activate_func) sd->activate_func(obj);
414 e_widget_change(Evas_Object *obj)
417 if (sd->parent_obj) e_widget_change(sd->parent_obj);
418 if (sd->on_change_func) sd->on_change_func(sd->on_change_data, obj);
422 e_widget_disabled_set(Evas_Object *obj, int disabled)
425 if (sd->disabled == disabled) return;
426 sd->disabled = disabled;
429 Evas_Object *o = NULL, *parent = NULL;
434 o = e_widget_parent_get(parent);
438 e_widget_focus_jump(parent, 1);
440 if (sd->disable_func) sd->disable_func(obj);
444 e_widget_disabled_get(Evas_Object *obj)
451 e_widget_pointer_get(Evas_Object *obj)
455 API_ENTRY return NULL;
456 win = e_win_evas_object_win_get(obj);
457 if (win) return win->pointer;
462 e_widget_size_min_resize(Evas_Object *obj)
465 evas_object_resize(obj, sd->minw, sd->minh);
468 /* local subsystem functions */
470 _e_smart_reconfigure(E_Smart_Data *sd)
474 evas_object_move(sd->resize_obj, sd->x, sd->y);
475 evas_object_resize(sd->resize_obj, sd->w, sd->h);
480 _e_smart_add(Evas_Object *obj)
482 E_Smart_Data *sd = NULL;
484 sd = calloc(1, sizeof(E_Smart_Data));
491 evas_object_smart_data_set(obj, sd);
495 _e_smart_del(Evas_Object *obj)
498 if (sd->del_func) sd->del_func(obj);
499 E_FREE_LIST(sd->subobjs, evas_object_del);
504 _e_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
509 _e_smart_reconfigure(sd);
513 _e_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
518 _e_smart_reconfigure(sd);
522 _e_smart_show(Evas_Object *obj)
526 evas_object_show(sd->resize_obj);
530 _e_smart_hide(Evas_Object *obj)
534 evas_object_hide(sd->resize_obj);
538 _e_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
542 evas_object_color_set(sd->resize_obj, r, g, b, a);
546 _e_smart_clip_set(Evas_Object *obj, Evas_Object *clip)
550 evas_object_clip_set(sd->resize_obj, clip);
554 _e_smart_clip_unset(Evas_Object *obj)
558 evas_object_clip_unset(sd->resize_obj);
561 /* never need to touch this */
566 if (_e_smart) return;
568 static const Evas_Smart_Class sc =
571 EVAS_SMART_CLASS_VERSION,
589 _e_smart = evas_smart_class_new(&sc);