1 #include <Elementary.h>
3 #include "elm_widget_grid.h"
5 EAPI const char ELM_GRID_SMART_NAME[] = "elm_grid";
7 EVAS_SMART_SUBCLASS_NEW
8 (ELM_GRID_SMART_NAME, _elm_grid, Elm_Grid_Smart_Class,
9 Elm_Widget_Smart_Class, elm_widget_smart_class_get, NULL);
12 _elm_grid_smart_focus_next(const Evas_Object *obj,
13 Elm_Focus_Direction dir,
17 const Eina_List *items;
18 Eina_List *(*list_free)(Eina_List *list);
19 void *(*list_data_get)(const Eina_List *list);
21 ELM_GRID_DATA_GET(obj, sd);
24 /* TODO: Change this to use other chain */
25 if ((items = elm_widget_focus_custom_chain_get(obj)))
27 list_data_get = eina_list_data_get;
32 items = evas_object_grid_children_get(ELM_WIDGET_DATA(sd)->resize_obj);
33 list_data_get = eina_list_data_get;
34 list_free = eina_list_free;
36 if (!items) return EINA_FALSE;
39 ret = elm_widget_focus_list_next_get(obj, items, list_data_get, dir, next);
41 if (list_free) list_free((Eina_List *)items);
47 _elm_grid_smart_focus_direction(const Evas_Object *obj,
48 const Evas_Object *base,
50 Evas_Object **direction,
54 const Eina_List *items;
55 Eina_List *(*list_free)(Eina_List *list);
56 void *(*list_data_get)(const Eina_List *list);
58 ELM_GRID_DATA_GET(obj, sd);
61 /* TODO: Change this to use other chain */
62 if ((items = elm_widget_focus_custom_chain_get(obj)))
64 list_data_get = eina_list_data_get;
69 items = evas_object_grid_children_get(ELM_WIDGET_DATA(sd)->resize_obj);
70 list_data_get = eina_list_data_get;
71 list_free = eina_list_free;
73 if (!items) return EINA_FALSE;
76 ret = elm_widget_focus_list_direction_get(obj, base, items, list_data_get,
77 degree, direction, weight);
79 if (list_free) list_free((Eina_List *)items);
85 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
87 ELM_GRID_DATA_GET(obj, sd);
89 evas_object_grid_mirrored_set(ELM_WIDGET_DATA(sd)->resize_obj, rtl);
93 _elm_grid_smart_theme(Evas_Object *obj)
95 if (!_elm_grid_parent_sc->theme(obj)) return EINA_FALSE;
97 _mirrored_set(obj, elm_widget_mirrored_get(obj));
103 _elm_grid_smart_add(Evas_Object *obj)
105 EVAS_SMART_DATA_ALLOC(obj, Elm_Grid_Smart_Data);
107 ELM_WIDGET_DATA(priv)->resize_obj =
108 evas_object_grid_add(evas_object_evas_get(obj));
109 evas_object_grid_size_set(ELM_WIDGET_DATA(priv)->resize_obj, 100, 100);
111 _elm_grid_parent_sc->base.add(obj);
113 elm_widget_can_focus_set(obj, EINA_FALSE);
115 _elm_grid_smart_theme(obj);
119 _elm_grid_smart_del(Evas_Object *obj)
124 ELM_GRID_DATA_GET(obj, sd);
126 /* let's make our grid object the *last* to be processed, since it
127 * may (smart) parent other sub objects here */
128 EINA_LIST_FOREACH(ELM_WIDGET_DATA(sd)->subobjs, l, child)
130 if (child == ELM_WIDGET_DATA(sd)->resize_obj)
132 ELM_WIDGET_DATA(sd)->subobjs =
133 eina_list_demote_list(ELM_WIDGET_DATA(sd)->subobjs, l);
138 _elm_grid_parent_sc->base.del(obj);
142 _elm_grid_smart_set_user(Elm_Grid_Smart_Class *sc)
144 ELM_WIDGET_CLASS(sc)->base.add = _elm_grid_smart_add;
145 ELM_WIDGET_CLASS(sc)->base.del = _elm_grid_smart_del;
147 ELM_WIDGET_CLASS(sc)->theme = _elm_grid_smart_theme;
148 ELM_WIDGET_CLASS(sc)->focus_next = _elm_grid_smart_focus_next;
149 ELM_WIDGET_CLASS(sc)->focus_direction = _elm_grid_smart_focus_direction;
152 EAPI const Elm_Grid_Smart_Class *
153 elm_grid_smart_class_get(void)
155 static Elm_Grid_Smart_Class _sc =
156 ELM_GRID_SMART_CLASS_INIT_NAME_VERSION(ELM_GRID_SMART_NAME);
157 static const Elm_Grid_Smart_Class *class = NULL;
159 if (class) return class;
161 _elm_grid_smart_set(&_sc);
168 elm_grid_add(Evas_Object *parent)
172 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
174 obj = elm_widget_add(_elm_grid_smart_class_new(), parent);
175 if (!obj) return NULL;
177 if (!elm_widget_sub_object_add(parent, obj))
178 ERR("could not add %p as sub object of %p", obj, parent);
184 elm_grid_size_set(Evas_Object *obj,
189 ELM_GRID_DATA_GET(obj, sd);
191 evas_object_grid_size_set(ELM_WIDGET_DATA(sd)->resize_obj, w, h);
195 elm_grid_size_get(const Evas_Object *obj,
200 ELM_GRID_DATA_GET(obj, sd);
202 evas_object_grid_size_get(ELM_WIDGET_DATA(sd)->resize_obj, w, h);
206 elm_grid_pack(Evas_Object *obj,
214 ELM_GRID_DATA_GET(obj, sd);
216 elm_widget_sub_object_add(obj, subobj);
217 evas_object_grid_pack(ELM_WIDGET_DATA(sd)->resize_obj, subobj, x, y, w, h);
221 elm_grid_unpack(Evas_Object *obj,
225 ELM_GRID_DATA_GET(obj, sd);
227 elm_widget_sub_object_del(obj, subobj);
228 evas_object_grid_unpack(ELM_WIDGET_DATA(sd)->resize_obj, subobj);
232 elm_grid_clear(Evas_Object *obj,
239 ELM_GRID_DATA_GET(obj, sd);
243 chld = evas_object_grid_children_get(ELM_WIDGET_DATA(sd)->resize_obj);
244 EINA_LIST_FREE (chld, o)
245 elm_widget_sub_object_del(obj, o);
248 evas_object_grid_clear(ELM_WIDGET_DATA(sd)->resize_obj, clear);
252 elm_grid_pack_set(Evas_Object *subobj,
258 Evas_Object *obj = elm_widget_parent_widget_get(subobj);
261 ELM_GRID_DATA_GET(obj, sd);
263 evas_object_grid_pack(ELM_WIDGET_DATA(sd)->resize_obj, subobj, x, y, w, h);
267 elm_grid_pack_get(Evas_Object *subobj,
273 Evas_Object *obj = elm_widget_parent_widget_get(subobj);
276 ELM_GRID_DATA_GET(obj, sd);
278 evas_object_grid_pack_get
279 (ELM_WIDGET_DATA(sd)->resize_obj, subobj, x, y, w, h);
283 elm_grid_children_get(const Evas_Object *obj)
285 ELM_GRID_CHECK(obj) NULL;
286 ELM_GRID_DATA_GET(obj, sd);
288 return evas_object_grid_children_get(ELM_WIDGET_DATA(sd)->resize_obj);