diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/elementary/src/lib/elm_table.c | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/libraries/elementary/src/lib/elm_table.c b/libraries/elementary/src/lib/elm_table.c new file mode 100644 index 0000000..532ccf4 --- /dev/null +++ b/libraries/elementary/src/lib/elm_table.c | |||
@@ -0,0 +1,243 @@ | |||
1 | #include <Elementary.h> | ||
2 | #include "elm_priv.h" | ||
3 | |||
4 | typedef struct _Widget_Data Widget_Data; | ||
5 | |||
6 | struct _Widget_Data | ||
7 | { | ||
8 | Evas_Object *tbl; | ||
9 | }; | ||
10 | |||
11 | static const char *widtype = NULL; | ||
12 | static void _del_hook(Evas_Object *obj); | ||
13 | static void _sizing_eval(Evas_Object *obj); | ||
14 | static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info); | ||
15 | static void _sub_del(void *data, Evas_Object *obj, void *event_info); | ||
16 | static void _theme_hook(Evas_Object *obj); | ||
17 | |||
18 | static void | ||
19 | _del_pre_hook(Evas_Object *obj) | ||
20 | { | ||
21 | Widget_Data *wd = elm_widget_data_get(obj); | ||
22 | if (!wd) return; | ||
23 | evas_object_event_callback_del_full | ||
24 | (wd->tbl, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj); | ||
25 | evas_object_del(wd->tbl); | ||
26 | } | ||
27 | |||
28 | static void | ||
29 | _del_hook(Evas_Object *obj) | ||
30 | { | ||
31 | Widget_Data *wd = elm_widget_data_get(obj); | ||
32 | if (!wd) return; | ||
33 | free(wd); | ||
34 | } | ||
35 | |||
36 | static Eina_Bool | ||
37 | _elm_table_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next) | ||
38 | { | ||
39 | Widget_Data *wd = elm_widget_data_get(obj); | ||
40 | const Eina_List *items; | ||
41 | void *(*list_data_get) (const Eina_List *list); | ||
42 | Eina_List *(*list_free) (Eina_List *list); | ||
43 | |||
44 | if ((!wd) || (!wd->tbl)) | ||
45 | return EINA_FALSE; | ||
46 | |||
47 | /* Focus chain */ | ||
48 | /* TODO: Change this to use other chain */ | ||
49 | if ((items = elm_widget_focus_custom_chain_get(obj))) | ||
50 | { | ||
51 | list_data_get = eina_list_data_get; | ||
52 | list_free = NULL; | ||
53 | } | ||
54 | else | ||
55 | { | ||
56 | items = evas_object_table_children_get(wd->tbl); | ||
57 | list_data_get = eina_list_data_get; | ||
58 | list_free = eina_list_free; | ||
59 | |||
60 | if (!items) return EINA_FALSE; | ||
61 | } | ||
62 | |||
63 | Eina_Bool ret = elm_widget_focus_list_next_get(obj, items, list_data_get, | ||
64 | dir, next); | ||
65 | |||
66 | if (list_free) | ||
67 | list_free((Eina_List *)items); | ||
68 | |||
69 | return ret; | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | _mirrored_set(Evas_Object *obj, Eina_Bool rtl) | ||
74 | { | ||
75 | Widget_Data *wd = elm_widget_data_get(obj); | ||
76 | if ((!wd) || (!wd->tbl)) | ||
77 | return; | ||
78 | |||
79 | evas_object_table_mirrored_set(wd->tbl, rtl); | ||
80 | } | ||
81 | |||
82 | static void | ||
83 | _theme_hook(Evas_Object *obj) | ||
84 | { | ||
85 | _elm_widget_mirrored_reload(obj); | ||
86 | _mirrored_set(obj, elm_widget_mirrored_get(obj)); | ||
87 | } | ||
88 | |||
89 | static void | ||
90 | _sizing_eval(Evas_Object *obj) | ||
91 | { | ||
92 | Widget_Data *wd = elm_widget_data_get(obj); | ||
93 | Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1; | ||
94 | Evas_Coord w, h; | ||
95 | if (!wd) return; | ||
96 | evas_object_size_hint_min_get(wd->tbl, &minw, &minh); | ||
97 | evas_object_size_hint_max_get(wd->tbl, &maxw, &maxh); | ||
98 | evas_object_size_hint_min_set(obj, minw, minh); | ||
99 | evas_object_size_hint_max_set(obj, maxw, maxh); | ||
100 | evas_object_geometry_get(obj, NULL, NULL, &w, &h); | ||
101 | if (w < minw) w = minw; | ||
102 | if (h < minh) h = minh; | ||
103 | if ((maxw >= 0) && (w > maxw)) w = maxw; | ||
104 | if ((maxh >= 0) && (h > maxh)) h = maxh; | ||
105 | evas_object_resize(obj, w, h); | ||
106 | } | ||
107 | |||
108 | static void | ||
109 | _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
110 | { | ||
111 | _sizing_eval(data); | ||
112 | } | ||
113 | |||
114 | static void | ||
115 | _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__) | ||
116 | { | ||
117 | _sizing_eval(obj); | ||
118 | } | ||
119 | |||
120 | EAPI Evas_Object * | ||
121 | elm_table_add(Evas_Object *parent) | ||
122 | { | ||
123 | Evas_Object *obj; | ||
124 | Evas *e; | ||
125 | Widget_Data *wd; | ||
126 | |||
127 | ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL); | ||
128 | |||
129 | ELM_SET_WIDTYPE(widtype, "table"); | ||
130 | elm_widget_type_set(obj, "table"); | ||
131 | elm_widget_sub_object_add(parent, obj); | ||
132 | elm_widget_data_set(obj, wd); | ||
133 | elm_widget_del_hook_set(obj, _del_hook); | ||
134 | elm_widget_del_pre_hook_set(obj, _del_pre_hook); | ||
135 | elm_widget_focus_next_hook_set(obj, _elm_table_focus_next_hook); | ||
136 | elm_widget_can_focus_set(obj, EINA_FALSE); | ||
137 | elm_widget_highlight_ignore_set(obj, EINA_FALSE); | ||
138 | elm_widget_theme_hook_set(obj, _theme_hook); | ||
139 | |||
140 | wd->tbl = evas_object_table_add(e); | ||
141 | evas_object_event_callback_add(wd->tbl, EVAS_CALLBACK_CHANGED_SIZE_HINTS, | ||
142 | _changed_size_hints, obj); | ||
143 | elm_widget_resize_object_set(obj, wd->tbl); | ||
144 | |||
145 | evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj); | ||
146 | |||
147 | _mirrored_set(obj, elm_widget_mirrored_get(obj)); | ||
148 | return obj; | ||
149 | } | ||
150 | |||
151 | EAPI void | ||
152 | elm_table_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous) | ||
153 | { | ||
154 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
155 | Widget_Data *wd = elm_widget_data_get(obj); | ||
156 | if (!wd) return; | ||
157 | evas_object_table_homogeneous_set(wd->tbl, homogeneous); | ||
158 | } | ||
159 | |||
160 | EAPI Eina_Bool | ||
161 | elm_table_homogeneous_get(const Evas_Object *obj) | ||
162 | { | ||
163 | ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE; | ||
164 | Widget_Data *wd = elm_widget_data_get(obj); | ||
165 | if (!wd) return EINA_FALSE; | ||
166 | return evas_object_table_homogeneous_get(wd->tbl); | ||
167 | } | ||
168 | |||
169 | EAPI void | ||
170 | elm_table_padding_set(Evas_Object *obj, Evas_Coord horizontal, Evas_Coord vertical) | ||
171 | { | ||
172 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
173 | Widget_Data *wd = elm_widget_data_get(obj); | ||
174 | if (!wd) return; | ||
175 | evas_object_table_padding_set(wd->tbl, horizontal, vertical); | ||
176 | } | ||
177 | |||
178 | EAPI void | ||
179 | elm_table_padding_get(const Evas_Object *obj, Evas_Coord *horizontal, Evas_Coord *vertical) | ||
180 | { | ||
181 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
182 | Widget_Data *wd = elm_widget_data_get(obj); | ||
183 | if (!wd) return; | ||
184 | evas_object_table_padding_get(wd->tbl, horizontal, vertical); | ||
185 | } | ||
186 | |||
187 | EAPI void | ||
188 | elm_table_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h) | ||
189 | { | ||
190 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
191 | Widget_Data *wd = elm_widget_data_get(obj); | ||
192 | if (!wd) return; | ||
193 | elm_widget_sub_object_add(obj, subobj); | ||
194 | evas_object_table_pack(wd->tbl, subobj, x, y, w, h); | ||
195 | } | ||
196 | |||
197 | EAPI void | ||
198 | elm_table_unpack(Evas_Object *obj, Evas_Object *subobj) | ||
199 | { | ||
200 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
201 | Widget_Data *wd = elm_widget_data_get(obj); | ||
202 | if (!wd) return; | ||
203 | elm_widget_sub_object_del(obj, subobj); | ||
204 | evas_object_table_unpack(wd->tbl, subobj); | ||
205 | } | ||
206 | |||
207 | EAPI void | ||
208 | elm_table_pack_set(Evas_Object *subobj, int x, int y, int w, int h) | ||
209 | { | ||
210 | Evas_Object *obj = elm_widget_parent_widget_get(subobj); | ||
211 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
212 | Widget_Data *wd = elm_widget_data_get(obj); | ||
213 | if (!wd) return; | ||
214 | evas_object_table_pack(wd->tbl, subobj, x, y, w, h); | ||
215 | } | ||
216 | |||
217 | EAPI void | ||
218 | elm_table_pack_get(Evas_Object *subobj, int *x, int *y, int *w, int *h) | ||
219 | { | ||
220 | Evas_Object *obj = elm_widget_parent_widget_get(subobj); | ||
221 | unsigned short ix, iy, iw, ih; | ||
222 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
223 | Widget_Data *wd = elm_widget_data_get(obj); | ||
224 | if (!wd) return; | ||
225 | evas_object_table_pack_get(wd->tbl, subobj, &ix, &iy, &iw, &ih); | ||
226 | if (x) *x = ix; | ||
227 | if (y) *y = iy; | ||
228 | if (w) *w = iw; | ||
229 | if (h) *h = ih; | ||
230 | } | ||
231 | |||
232 | EAPI void | ||
233 | elm_table_clear(Evas_Object *obj, Eina_Bool clear) | ||
234 | { | ||
235 | Eina_List *chld; | ||
236 | Evas_Object *o; | ||
237 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
238 | Widget_Data *wd = elm_widget_data_get(obj); | ||
239 | if (!wd) return; | ||
240 | chld = evas_object_table_children_get(wd->tbl); | ||
241 | EINA_LIST_FREE(chld, o) elm_widget_sub_object_del(obj, o); | ||
242 | evas_object_table_clear(wd->tbl, clear); | ||
243 | } | ||