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);
24 static void _theme_hook(Evas_Object *obj);
27 _del_pre_hook(Evas_Object *obj)
29 Widget_Data *wd = elm_widget_data_get(obj);
31 evas_object_event_callback_del_full
32 (wd->tbl, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
33 evas_object_del(wd->tbl);
37 _del_hook(Evas_Object *obj)
39 Widget_Data *wd = elm_widget_data_get(obj);
45 _elm_table_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
47 Widget_Data *wd = elm_widget_data_get(obj);
48 const Eina_List *items;
49 void *(*list_data_get) (const Eina_List *list);
50 Eina_List *(*list_free) (Eina_List *list);
52 if ((!wd) || (!wd->tbl))
56 /* TODO: Change this to use other chain */
57 if ((items = elm_widget_focus_custom_chain_get(obj)))
59 list_data_get = eina_list_data_get;
64 items = evas_object_table_children_get(wd->tbl);
65 list_data_get = eina_list_data_get;
66 list_free = eina_list_free;
68 if (!items) return EINA_FALSE;
71 Eina_Bool ret = elm_widget_focus_list_next_get(obj, items, list_data_get,
75 list_free((Eina_List *)items);
81 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
83 Widget_Data *wd = elm_widget_data_get(obj);
84 if ((!wd) || (!wd->tbl))
87 evas_object_table_mirrored_set(wd->tbl, rtl);
91 _theme_hook(Evas_Object *obj)
93 _elm_widget_mirrored_reload(obj);
94 _mirrored_set(obj, elm_widget_mirrored_get(obj));
98 _sizing_eval(Evas_Object *obj)
100 Widget_Data *wd = elm_widget_data_get(obj);
101 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
104 evas_object_size_hint_min_get(wd->tbl, &minw, &minh);
105 evas_object_size_hint_max_get(wd->tbl, &maxw, &maxh);
106 evas_object_size_hint_min_set(obj, minw, minh);
107 evas_object_size_hint_max_set(obj, maxw, maxh);
108 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
109 if (w < minw) w = minw;
110 if (h < minh) h = minh;
111 if ((maxw >= 0) && (w > maxw)) w = maxw;
112 if ((maxh >= 0) && (h > maxh)) h = maxh;
113 evas_object_resize(obj, w, h);
117 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
123 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
129 * Add a new table to the parent
131 * @param parent The parent object
132 * @return The new object or NULL if it cannot be created
137 elm_table_add(Evas_Object *parent)
143 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
145 ELM_SET_WIDTYPE(widtype, "table");
146 elm_widget_type_set(obj, "table");
147 elm_widget_sub_object_add(parent, obj);
148 elm_widget_data_set(obj, wd);
149 elm_widget_del_hook_set(obj, _del_hook);
150 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
151 elm_widget_focus_next_hook_set(obj, _elm_table_focus_next_hook);
152 elm_widget_can_focus_set(obj, EINA_FALSE);
153 elm_widget_highlight_ignore_set(obj, EINA_FALSE);
154 elm_widget_theme_hook_set(obj, _theme_hook);
156 wd->tbl = evas_object_table_add(e);
157 evas_object_event_callback_add(wd->tbl, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
158 _changed_size_hints, obj);
159 elm_widget_resize_object_set(obj, wd->tbl);
161 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
163 _mirrored_set(obj, elm_widget_mirrored_get(obj));
168 * Set the homogenous layout in the table
170 * @param obj The layout object
171 * @param homogenous A boolean to set (or no) layout homogenous
173 * (1 = homogenous, 0 = no homogenous)
178 elm_table_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
180 ELM_CHECK_WIDTYPE(obj, widtype);
181 Widget_Data *wd = elm_widget_data_get(obj);
183 evas_object_table_homogeneous_set(wd->tbl, homogenous);
187 * Get the current table homogenous mode.
189 * @param obj The table object
190 * @return a boolean to set (or no) layout homogenous in the table
191 * (1 = homogenous, 0 = no homogenous)
196 elm_table_homogenous_get(const Evas_Object *obj)
198 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
199 Widget_Data *wd = elm_widget_data_get(obj);
200 if (!wd) return EINA_FALSE;
201 return evas_object_table_homogeneous_get(wd->tbl);
205 * Set padding between cells.
207 * @param obj The layout object.
208 * @param horizontal set the horizontal padding.
209 * @param vertical set the vertical padding.
214 elm_table_padding_set(Evas_Object *obj, Evas_Coord horizontal, Evas_Coord vertical)
216 ELM_CHECK_WIDTYPE(obj, widtype);
217 Widget_Data *wd = elm_widget_data_get(obj);
219 evas_object_table_padding_set(wd->tbl, horizontal, vertical);
223 * Get padding between cells.
225 * @param obj The layout object.
226 * @param horizontal set the horizontal padding.
227 * @param vertical set the vertical padding.
232 elm_table_padding_get(const Evas_Object *obj, Evas_Coord *horizontal, Evas_Coord *vertical)
234 ELM_CHECK_WIDTYPE(obj, widtype);
235 Widget_Data *wd = elm_widget_data_get(obj);
237 evas_object_table_padding_get(wd->tbl, horizontal, vertical);
241 * Add a subobject on the table with the coordinates passed
243 * @param obj The table object
244 * @param subobj The subobject to be added to the table
245 * @param x Coordinate to X axis
246 * @param y Coordinate to Y axis
247 * @param w Horizontal length
248 * @param h Vertical length
253 elm_table_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h)
255 ELM_CHECK_WIDTYPE(obj, widtype);
256 Widget_Data *wd = elm_widget_data_get(obj);
258 elm_widget_sub_object_add(obj, subobj);
259 evas_object_table_pack(wd->tbl, subobj, x, y, w, h);
263 * Remove child from table.
265 * @param obj The table object
266 * @param subobj The subobject
271 elm_table_unpack(Evas_Object *obj, Evas_Object *subobj)
273 ELM_CHECK_WIDTYPE(obj, widtype);
274 Widget_Data *wd = elm_widget_data_get(obj);
276 elm_widget_sub_object_del(obj, subobj);
277 evas_object_table_unpack(wd->tbl, subobj);
281 * Faster way to remove all child objects from a table object.
283 * @param obj The table object
284 * @param clear If true, it will delete just removed children
289 elm_table_clear(Evas_Object *obj, Eina_Bool clear)
291 ELM_CHECK_WIDTYPE(obj, widtype);
292 Widget_Data *wd = elm_widget_data_get(obj);
294 evas_object_table_clear(wd->tbl, clear);