1 #include <Elementary.h>
5 * @defgroup Table Table
7 * Arranges widgets in a table where items can also span multiple
8 * columns or rows - even overlap (and then be raised or lowered
9 * accordingly to adjust stacking if they do overlap).
12 typedef struct _Widget_Data Widget_Data;
19 static const char *widtype = NULL;
20 static void _del_hook(Evas_Object *obj);
21 static void _sizing_eval(Evas_Object *obj);
22 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
23 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
26 _del_pre_hook(Evas_Object *obj)
28 Widget_Data *wd = elm_widget_data_get(obj);
30 evas_object_event_callback_del_full
31 (wd->tbl, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
32 evas_object_del(wd->tbl);
36 _del_hook(Evas_Object *obj)
38 Widget_Data *wd = elm_widget_data_get(obj);
44 _elm_table_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
46 Widget_Data *wd = elm_widget_data_get(obj);
47 const Eina_List *items;
48 void *(*list_data_get) (const Eina_List *list);
49 Eina_List *(*list_free) (Eina_List *list);
51 if ((!wd) || (!wd->tbl))
55 /* TODO: Change this to use other chain */
56 if ((items = elm_widget_focus_custom_chain_get(obj)))
58 list_data_get = eina_list_data_get;
63 items = evas_object_table_children_get(wd->tbl);
64 list_data_get = eina_list_data_get;
65 list_free = eina_list_free;
67 if (!items) return EINA_FALSE;
70 Eina_Bool ret = elm_widget_focus_list_next_get(obj, items, list_data_get,
74 list_free((Eina_List *)items);
80 _sizing_eval(Evas_Object *obj)
82 Widget_Data *wd = elm_widget_data_get(obj);
83 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
86 evas_object_size_hint_min_get(wd->tbl, &minw, &minh);
87 evas_object_size_hint_max_get(wd->tbl, &maxw, &maxh);
88 evas_object_size_hint_min_set(obj, minw, minh);
89 evas_object_size_hint_max_set(obj, maxw, maxh);
90 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
91 if (w < minw) w = minw;
92 if (h < minh) h = minh;
93 if ((maxw >= 0) && (w > maxw)) w = maxw;
94 if ((maxh >= 0) && (h > maxh)) h = maxh;
95 evas_object_resize(obj, w, h);
99 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
105 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
111 * Add a new table to the parent
113 * @param parent The parent object
114 * @return The new object or NULL if it cannot be created
119 elm_table_add(Evas_Object *parent)
125 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
127 wd = ELM_NEW(Widget_Data);
128 e = evas_object_evas_get(parent);
130 obj = elm_widget_add(e);
131 ELM_SET_WIDTYPE(widtype, "table");
132 elm_widget_type_set(obj, "table");
133 elm_widget_sub_object_add(parent, obj);
134 elm_widget_data_set(obj, wd);
135 elm_widget_del_hook_set(obj, _del_hook);
136 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
137 elm_widget_focus_next_hook_set(obj, _elm_table_focus_next_hook);
138 elm_widget_can_focus_set(obj, EINA_FALSE);
139 elm_widget_highlight_ignore_set(obj, EINA_FALSE);
141 wd->tbl = evas_object_table_add(e);
142 evas_object_event_callback_add(wd->tbl, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
143 _changed_size_hints, obj);
144 elm_widget_resize_object_set(obj, wd->tbl);
146 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
152 * Set the homogenous layout in the table
154 * @param obj The layout object
155 * @param homogenous A boolean to set (or no) layout homogenous
157 * (1 = homogenous, 0 = no homogenous)
162 elm_table_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
164 ELM_CHECK_WIDTYPE(obj, widtype);
165 Widget_Data *wd = elm_widget_data_get(obj);
167 evas_object_table_homogeneous_set(wd->tbl, homogenous);
171 * Get the current table homogenous mode.
173 * @param obj The table object
174 * @return a boolean to set (or no) layout homogenous in the table
175 * (1 = homogenous, 0 = no homogenous)
180 elm_table_homogenous_get(const Evas_Object *obj)
182 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
183 Widget_Data *wd = elm_widget_data_get(obj);
184 if (!wd) return EINA_FALSE;
185 return evas_object_table_homogeneous_get(wd->tbl);
189 * Set padding between cells.
191 * @param obj The layout object.
192 * @param horizontal set the horizontal padding.
193 * @param vertical set the vertical padding.
198 elm_table_padding_set(Evas_Object *obj, Evas_Coord horizontal, Evas_Coord vertical)
200 ELM_CHECK_WIDTYPE(obj, widtype);
201 Widget_Data *wd = elm_widget_data_get(obj);
203 evas_object_table_padding_set(wd->tbl, horizontal, vertical);
207 * Get padding between cells.
209 * @param obj The layout object.
210 * @param horizontal set the horizontal padding.
211 * @param vertical set the vertical padding.
216 elm_table_padding_get(const Evas_Object *obj, Evas_Coord *horizontal, Evas_Coord *vertical)
218 ELM_CHECK_WIDTYPE(obj, widtype);
219 Widget_Data *wd = elm_widget_data_get(obj);
221 evas_object_table_padding_get(wd->tbl, horizontal, vertical);
225 * Add a subobject on the table with the coordinates passed
227 * @param obj The table object
228 * @param subobj The subobject to be added to the table
229 * @param x Coordinate to X axis
230 * @param y Coordinate to Y axis
231 * @param w Horizontal length
232 * @param h Vertical length
237 elm_table_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h)
239 ELM_CHECK_WIDTYPE(obj, widtype);
240 Widget_Data *wd = elm_widget_data_get(obj);
242 elm_widget_sub_object_add(obj, subobj);
243 evas_object_table_pack(wd->tbl, subobj, x, y, w, h);
247 * Remove child from table.
249 * @param obj The table object
250 * @param subobj The subobject
255 elm_table_unpack(Evas_Object *obj, Evas_Object *subobj)
257 ELM_CHECK_WIDTYPE(obj, widtype);
258 Widget_Data *wd = elm_widget_data_get(obj);
260 elm_widget_sub_object_del(obj, subobj);
261 evas_object_table_unpack(wd->tbl, subobj);
265 * Faster way to remove all child objects from a table object.
267 * @param obj The table object
268 * @param clear If true, it will delete just removed children
273 elm_table_clear(Evas_Object *obj, Eina_Bool clear)
275 ELM_CHECK_WIDTYPE(obj, widtype);
276 Widget_Data *wd = elm_widget_data_get(obj);
278 evas_object_table_clear(wd->tbl, clear);