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 homogenous layout in the table
171 * @param obj The layout object
172 * @param homogenous A boolean to set (or no) layout homogenous
174 * (1 = homogenous, 0 = no homogenous)
179 elm_table_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
181 ELM_CHECK_WIDTYPE(obj, widtype);
182 Widget_Data *wd = elm_widget_data_get(obj);
184 evas_object_table_homogeneous_set(wd->tbl, homogenous);
188 * Get the current table homogenous mode.
190 * @param obj The table object
191 * @return a boolean to set (or no) layout homogenous in the table
192 * (1 = homogenous, 0 = no homogenous)
197 elm_table_homogenous_get(const Evas_Object *obj)
199 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
200 Widget_Data *wd = elm_widget_data_get(obj);
201 if (!wd) return EINA_FALSE;
202 return evas_object_table_homogeneous_get(wd->tbl);
206 * Set padding between cells.
208 * @param obj The layout object.
209 * @param horizontal set the horizontal padding.
210 * @param vertical set the vertical padding.
215 elm_table_padding_set(Evas_Object *obj, Evas_Coord horizontal, Evas_Coord vertical)
217 ELM_CHECK_WIDTYPE(obj, widtype);
218 Widget_Data *wd = elm_widget_data_get(obj);
220 evas_object_table_padding_set(wd->tbl, horizontal, vertical);
224 * Get padding between cells.
226 * @param obj The layout object.
227 * @param horizontal set the horizontal padding.
228 * @param vertical set the vertical padding.
233 elm_table_padding_get(const Evas_Object *obj, Evas_Coord *horizontal, Evas_Coord *vertical)
235 ELM_CHECK_WIDTYPE(obj, widtype);
236 Widget_Data *wd = elm_widget_data_get(obj);
238 evas_object_table_padding_get(wd->tbl, horizontal, vertical);
242 * Add a subobject on the table with the coordinates passed
244 * @param obj The table object
245 * @param subobj The subobject to be added to the table
246 * @param x Coordinate to X axis
247 * @param y Coordinate to Y axis
248 * @param w Horizontal length
249 * @param h Vertical length
254 elm_table_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h)
256 ELM_CHECK_WIDTYPE(obj, widtype);
257 Widget_Data *wd = elm_widget_data_get(obj);
259 elm_widget_sub_object_add(obj, subobj);
260 evas_object_table_pack(wd->tbl, subobj, x, y, w, h);
264 * Remove child from table.
266 * @param obj The table object
267 * @param subobj The subobject
272 elm_table_unpack(Evas_Object *obj, Evas_Object *subobj)
274 ELM_CHECK_WIDTYPE(obj, widtype);
275 Widget_Data *wd = elm_widget_data_get(obj);
277 elm_widget_sub_object_del(obj, subobj);
278 evas_object_table_unpack(wd->tbl, subobj);
282 * Faster way to remove all child objects from a table object.
284 * @param obj The table object
285 * @param clear If true, it will delete just removed children
290 elm_table_clear(Evas_Object *obj, Eina_Bool clear)
292 ELM_CHECK_WIDTYPE(obj, widtype);
293 Widget_Data *wd = elm_widget_data_get(obj);
295 evas_object_table_clear(wd->tbl, clear);