1 #include <Elementary.h>
5 * @defgroup Table Table
8 * Arranges widgets in a table where items can also span multiple
9 * columns or rows - even overlap (and then be raised or lowered
10 * accordingly to adjust stacking if they do overlap).
13 typedef struct _Widget_Data Widget_Data;
20 static const char *widtype = NULL;
21 static void _del_hook(Evas_Object *obj);
22 static void _sizing_eval(Evas_Object *obj);
23 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
24 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
25 static void _theme_hook(Evas_Object *obj);
28 _del_pre_hook(Evas_Object *obj)
30 Widget_Data *wd = elm_widget_data_get(obj);
32 evas_object_event_callback_del_full
33 (wd->tbl, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
34 evas_object_del(wd->tbl);
38 _del_hook(Evas_Object *obj)
40 Widget_Data *wd = elm_widget_data_get(obj);
46 _elm_table_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
48 Widget_Data *wd = elm_widget_data_get(obj);
49 const Eina_List *items;
50 void *(*list_data_get) (const Eina_List *list);
51 Eina_List *(*list_free) (Eina_List *list);
53 if ((!wd) || (!wd->tbl))
57 /* TODO: Change this to use other chain */
58 if ((items = elm_widget_focus_custom_chain_get(obj)))
60 list_data_get = eina_list_data_get;
65 items = evas_object_table_children_get(wd->tbl);
66 list_data_get = eina_list_data_get;
67 list_free = eina_list_free;
69 if (!items) return EINA_FALSE;
72 Eina_Bool ret = elm_widget_focus_list_next_get(obj, items, list_data_get,
76 list_free((Eina_List *)items);
82 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
84 Widget_Data *wd = elm_widget_data_get(obj);
85 if ((!wd) || (!wd->tbl))
88 evas_object_table_mirrored_set(wd->tbl, rtl);
92 _theme_hook(Evas_Object *obj)
94 _elm_widget_mirrored_reload(obj);
95 _mirrored_set(obj, elm_widget_mirrored_get(obj));
99 _sizing_eval(Evas_Object *obj)
101 Widget_Data *wd = elm_widget_data_get(obj);
102 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
105 evas_object_size_hint_min_get(wd->tbl, &minw, &minh);
106 evas_object_size_hint_max_get(wd->tbl, &maxw, &maxh);
107 evas_object_size_hint_min_set(obj, minw, minh);
108 evas_object_size_hint_max_set(obj, maxw, maxh);
109 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
110 if (w < minw) w = minw;
111 if (h < minh) h = minh;
112 if ((maxw >= 0) && (w > maxw)) w = maxw;
113 if ((maxh >= 0) && (h > maxh)) h = maxh;
114 evas_object_resize(obj, w, h);
118 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
124 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
130 * Add a new table to the parent
132 * @param parent The parent object
133 * @return The new object or NULL if it cannot be created
138 elm_table_add(Evas_Object *parent)
144 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
146 ELM_SET_WIDTYPE(widtype, "table");
147 elm_widget_type_set(obj, "table");
148 elm_widget_sub_object_add(parent, obj);
149 elm_widget_data_set(obj, wd);
150 elm_widget_del_hook_set(obj, _del_hook);
151 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
152 elm_widget_focus_next_hook_set(obj, _elm_table_focus_next_hook);
153 elm_widget_can_focus_set(obj, EINA_FALSE);
154 elm_widget_highlight_ignore_set(obj, EINA_FALSE);
155 elm_widget_theme_hook_set(obj, _theme_hook);
157 wd->tbl = evas_object_table_add(e);
158 evas_object_event_callback_add(wd->tbl, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
159 _changed_size_hints, obj);
160 elm_widget_resize_object_set(obj, wd->tbl);
162 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
164 _mirrored_set(obj, elm_widget_mirrored_get(obj));
169 * Set the homogeneous layout in the table
171 * @param obj The layout object
172 * @param homogeneous A boolean to set (or no) layout homogeneous
174 * (1 = homogeneous, 0 = no homogeneous)
179 elm_table_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
181 ELM_CHECK_WIDTYPE(obj, widtype);
182 Widget_Data *wd = elm_widget_data_get(obj);
184 evas_object_table_homogeneous_set(wd->tbl, homogeneous);
187 EINA_DEPRECATED EAPI void
188 elm_table_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
190 elm_table_homogeneous_set(obj, homogenous);
194 * Get the current table homogeneous mode.
196 * @param obj The table object
197 * @return a boolean to set (or no) layout homogeneous in the table
198 * (1 = homogeneous, 0 = no homogeneous)
203 elm_table_homogeneous_get(const Evas_Object *obj)
205 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
206 Widget_Data *wd = elm_widget_data_get(obj);
207 if (!wd) return EINA_FALSE;
208 return evas_object_table_homogeneous_get(wd->tbl);
211 EINA_DEPRECATED EAPI Eina_Bool
212 elm_table_homogenous_get(const Evas_Object *obj)
214 return elm_table_homogeneous_get(obj);
218 * Set padding between cells.
220 * @param obj The layout object.
221 * @param horizontal set the horizontal padding.
222 * @param vertical set the vertical padding.
227 elm_table_padding_set(Evas_Object *obj, Evas_Coord horizontal, Evas_Coord vertical)
229 ELM_CHECK_WIDTYPE(obj, widtype);
230 Widget_Data *wd = elm_widget_data_get(obj);
232 evas_object_table_padding_set(wd->tbl, horizontal, vertical);
236 * Get padding between cells.
238 * @param obj The layout object.
239 * @param horizontal set the horizontal padding.
240 * @param vertical set the vertical padding.
245 elm_table_padding_get(const Evas_Object *obj, Evas_Coord *horizontal, Evas_Coord *vertical)
247 ELM_CHECK_WIDTYPE(obj, widtype);
248 Widget_Data *wd = elm_widget_data_get(obj);
250 evas_object_table_padding_get(wd->tbl, horizontal, vertical);
254 * Add a subobject on the table with the coordinates passed
256 * @param obj The table object
257 * @param subobj The subobject to be added to the table
258 * @param x Coordinate to X axis
259 * @param y Coordinate to Y axis
260 * @param w Horizontal length
261 * @param h Vertical length
266 elm_table_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h)
268 ELM_CHECK_WIDTYPE(obj, widtype);
269 Widget_Data *wd = elm_widget_data_get(obj);
271 elm_widget_sub_object_add(obj, subobj);
272 evas_object_table_pack(wd->tbl, subobj, x, y, w, h);
276 * Remove child from table.
278 * @param obj The table object
279 * @param subobj The subobject
284 elm_table_unpack(Evas_Object *obj, Evas_Object *subobj)
286 ELM_CHECK_WIDTYPE(obj, widtype);
287 Widget_Data *wd = elm_widget_data_get(obj);
289 elm_widget_sub_object_del(obj, subobj);
290 evas_object_table_unpack(wd->tbl, subobj);
294 * Set the packing location of an existing child of the table
296 * @param subobj The subobject to be modified in the table
297 * @param x Coordinate to X axis
298 * @param y Coordinate to Y axis
299 * @param w Horizontal length
300 * @param h Vertical length
305 elm_table_pack_set(Evas_Object *subobj, int x, int y, int w, int h)
307 Evas_Object *obj = elm_widget_parent_widget_get(subobj);
308 ELM_CHECK_WIDTYPE(obj, widtype);
309 Widget_Data *wd = elm_widget_data_get(obj);
311 evas_object_table_pack(wd->tbl, subobj, x, y, w, h);
315 * Set the packing location of an existing child of the table
317 * @param subobj The subobject to be modified in the table
318 * @param x Coordinate to X axis
319 * @param y Coordinate to Y axis
320 * @param w Horizontal length
321 * @param h Vertical length
326 elm_table_pack_get(Evas_Object *subobj, int *x, int *y, int *w, int *h)
328 Evas_Object *obj = elm_widget_parent_widget_get(subobj);
329 unsigned short ix, iy, iw, ih;
330 ELM_CHECK_WIDTYPE(obj, widtype);
331 Widget_Data *wd = elm_widget_data_get(obj);
333 //evas_object_table_pack_get(wd->tbl, subobj, &ix, &iy, &iw, &ih); // MIGRATION: TEMP
341 * Faster way to remove all child objects from a table object.
343 * @param obj The table object
344 * @param clear If true, it will delete just removed children
349 elm_table_clear(Evas_Object *obj, Eina_Bool clear)
353 ELM_CHECK_WIDTYPE(obj, widtype);
354 Widget_Data *wd = elm_widget_data_get(obj);
356 chld = evas_object_table_children_get(wd->tbl);
357 EINA_LIST_FREE(chld, o) elm_widget_sub_object_del(obj, o);
358 evas_object_table_clear(wd->tbl, clear);