diff options
author | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2014-03-24 17:00:17 +0900 |
---|---|---|
committer | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2014-03-24 17:00:33 +0900 |
commit | adcc0256c2b79a061a697e5e7c1b8fedd5082b10 (patch) | |
tree | 52281b064f327a05abf4212319246b4b7962985a /src/modules | |
parent | 71f5a747d635237447dbd00c3434951d691d0af7 (diff) |
format fixup.
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/gengrid_focus_hook/gengrid_focus_hook.c | 850 |
1 files changed, 401 insertions, 449 deletions
diff --git a/src/modules/gengrid_focus_hook/gengrid_focus_hook.c b/src/modules/gengrid_focus_hook/gengrid_focus_hook.c index 465ab6ac5..3c1d69270 100644 --- a/src/modules/gengrid_focus_hook/gengrid_focus_hook.c +++ b/src/modules/gengrid_focus_hook/gengrid_focus_hook.c | |||
@@ -11,14 +11,14 @@ | |||
11 | #define GG_IT(_it) (_it->item) | 11 | #define GG_IT(_it) (_it->item) |
12 | 12 | ||
13 | #define EINA_INLIST_REVERSE_FOREACH_INSIDE(list, it) \ | 13 | #define EINA_INLIST_REVERSE_FOREACH_INSIDE(list, it) \ |
14 | for (it = NULL, it = (list ? _EINA_INLIST_CONTAINER(it, list) : NULL); it; \ | 14 | for (it = NULL, it = (list ? _EINA_INLIST_CONTAINER(it, list) : NULL); it; \ |
15 | it = (EINA_INLIST_GET(it)->prev \ | 15 | it = (EINA_INLIST_GET(it)->prev \ |
16 | ? _EINA_INLIST_CONTAINER(it, EINA_INLIST_GET(it)->prev) \ | 16 | ? _EINA_INLIST_CONTAINER(it, EINA_INLIST_GET(it)->prev) \ |
17 | : NULL)) | 17 | : NULL)) |
18 | 18 | ||
19 | #define EINA_LIST_REVERSE_FOREACH_INSIDE(list, l, data) \ | 19 | #define EINA_LIST_REVERSE_FOREACH_INSIDE(list, l, data) \ |
20 | for (l = list, data = eina_list_data_get(l); l; \ | 20 | for (l = list, data = eina_list_data_get(l); l; \ |
21 | l = eina_list_prev(l), data = eina_list_data_get(l)) | 21 | l = eina_list_prev(l), data = eina_list_data_get(l)) |
22 | 22 | ||
23 | #define WEIGHT_MAX ((double)INT_MAX / (double)1000000) | 23 | #define WEIGHT_MAX ((double)INT_MAX / (double)1000000) |
24 | 24 | ||
@@ -33,97 +33,88 @@ | |||
33 | static const Evas_Object * | 33 | static const Evas_Object * |
34 | _find_gengrid_parent_item(const Evas_Object *base) | 34 | _find_gengrid_parent_item(const Evas_Object *base) |
35 | { | 35 | { |
36 | const Evas_Object *res = NULL; | 36 | const Evas_Object *res = NULL; |
37 | if (base) | 37 | if (base) |
38 | { | 38 | { |
39 | const Evas_Object *parent = NULL; | 39 | const Evas_Object *parent = NULL; |
40 | parent = elm_widget_parent_get(base); | 40 | parent = elm_widget_parent_get(base); |
41 | 41 | ||
42 | while (parent) | 42 | while (parent) |
43 | { | 43 | { |
44 | if (evas_object_smart_type_check(parent, "elm_gengrid")) | 44 | if (evas_object_smart_type_check(parent, "elm_gengrid")) |
45 | { | 45 | { |
46 | res = parent; | 46 | res = parent; |
47 | break; | 47 | break; |
48 | } | 48 | } |
49 | parent = elm_widget_parent_get(parent); | 49 | parent = elm_widget_parent_get(parent); |
50 | } | 50 | } |
51 | } | 51 | } |
52 | return res; | 52 | return res; |
53 | } | 53 | } |
54 | 54 | ||
55 | static Eina_Bool | 55 | static Eina_Bool |
56 | _can_focus(const Evas_Object *obj) | 56 | _can_focus(const Evas_Object *obj) |
57 | { | 57 | { |
58 | if (obj && elm_object_focus_allow_get(obj) && | 58 | if (obj && elm_object_focus_allow_get(obj) && elm_widget_can_focus_get(obj)) |
59 | elm_widget_can_focus_get(obj)) | 59 | return EINA_TRUE; |
60 | return EINA_TRUE; | 60 | return EINA_FALSE; |
61 | return EINA_FALSE; | ||
62 | } | 61 | } |
63 | 62 | ||
64 | |||
65 | static Eina_List * | 63 | static Eina_List * |
66 | _get_contents(const Evas_Object *obj) | 64 | _get_contents(const Evas_Object *obj) |
67 | { | 65 | { |
68 | Eina_List *res = NULL; | 66 | Eina_List *res = NULL; |
69 | if (!obj) | 67 | if (!obj) return NULL; |
70 | return NULL; | 68 | |
71 | 69 | if (evas_object_smart_type_check(obj, "elm_layout")) | |
72 | if (evas_object_smart_type_check(obj, "elm_layout")) | 70 | { |
73 | { | 71 | Evas_Object *edje = elm_layout_edje_get(obj); |
74 | Evas_Object *edje = elm_layout_edje_get(obj); | 72 | |
75 | if (edje) | 73 | if (edje) |
76 | { | 74 | { |
77 | const Eina_List *l = NULL; | 75 | const Eina_List *l = NULL; |
78 | const char *key; | 76 | const char *key; |
79 | const Eina_List *contents = | 77 | const Eina_List *contents = |
80 | elm_widget_stringlist_get( | 78 | elm_widget_stringlist_get(edje_object_data_get(edje, "contents")); |
81 | edje_object_data_get(edje, "contents")); | 79 | |
82 | 80 | EINA_LIST_FOREACH(contents, l, key) | |
83 | EINA_LIST_FOREACH(contents, l, key) | 81 | { |
84 | { | 82 | if (key) |
85 | if (key) | 83 | { |
86 | { | 84 | const Evas_Object *child = |
87 | const Evas_Object *child = | 85 | edje_object_part_swallow_get(edje, key); |
88 | edje_object_part_swallow_get(edje, key); | 86 | if (child) |
89 | if (child) | 87 | { |
90 | { | 88 | Eina_List *l1 = NULL; |
91 | Eina_List *l1 = NULL; | 89 | res = eina_list_append(res, child); |
92 | res = eina_list_append(res, child); | 90 | |
93 | 91 | l1 = _get_contents(child); | |
94 | l1 = _get_contents(child); | 92 | if (l1) res = eina_list_merge(res, l1); |
95 | if (l1) | 93 | } |
96 | { | 94 | } |
97 | res = eina_list_merge(res, l1); | 95 | } |
98 | } | 96 | } |
99 | } | 97 | } |
100 | } | 98 | return res; |
101 | } | ||
102 | } | ||
103 | } | ||
104 | return res; | ||
105 | } | 99 | } |
106 | 100 | ||
107 | static Eina_List * | 101 | static Eina_List * |
108 | _gengrid_item_contents_get(const Elm_Gen_Item *it) | 102 | _gengrid_item_contents_get(const Elm_Gen_Item *it) |
109 | { | 103 | { |
110 | Eina_List *res = NULL; | 104 | Eina_List *res = NULL; |
111 | Eina_List *l = NULL; | 105 | Eina_List *l = NULL; |
112 | Evas_Object *child = NULL; | 106 | Evas_Object *child = NULL; |
113 | EINA_LIST_FOREACH(it->content_objs, l, child) | 107 | EINA_LIST_FOREACH(it->content_objs, l, child) |
114 | { | 108 | { |
115 | if (child) | 109 | if (child) |
116 | { | 110 | { |
117 | Eina_List *l1 = NULL; | 111 | Eina_List *l1 = NULL; |
118 | res = eina_list_append(res, child); | 112 | res = eina_list_append(res, child); |
119 | 113 | ||
120 | l1 = _get_contents(child); | 114 | l1 = _get_contents(child); |
121 | if (l1) | 115 | if (l1) res = eina_list_merge(res, l1); |
122 | { | 116 | } |
123 | res = eina_list_merge(res, l1); | 117 | } |
124 | } | ||
125 | } | ||
126 | } | ||
127 | return res; | 118 | return res; |
128 | } | 119 | } |
129 | 120 | ||
@@ -132,56 +123,49 @@ _find_focusable_object(const Elm_Gen_Item *it, | |||
132 | const Evas_Object *base, | 123 | const Evas_Object *base, |
133 | Elm_Focus_Direction dir) | 124 | Elm_Focus_Direction dir) |
134 | { | 125 | { |
135 | const Evas_Object *obj = NULL; | 126 | const Evas_Object *obj = NULL; |
136 | Eina_List *l = NULL; | 127 | Eina_List *l = NULL; |
137 | Eina_List *contents = NULL; | 128 | Eina_List *contents = NULL; |
138 | 129 | ||
139 | if (!it) return NULL; | 130 | if (!it) return NULL; |
140 | 131 | ||
141 | contents = _gengrid_item_contents_get(it); | 132 | contents = _gengrid_item_contents_get(it); |
142 | 133 | if (contents) | |
143 | if (contents) | 134 | { |
144 | { | 135 | if (base) |
145 | if (base) | 136 | { |
146 | { | 137 | l = eina_list_data_find_list(contents, base); |
147 | l = eina_list_data_find_list(contents, base); | 138 | obj = base; |
148 | obj = base; | 139 | } |
149 | } | 140 | |
150 | 141 | if ((dir == ELM_FOCUS_LEFT) || (dir == ELM_FOCUS_UP)) | |
151 | if (dir == ELM_FOCUS_LEFT || dir == ELM_FOCUS_UP) | 142 | { |
152 | { | 143 | if (l) l = eina_list_prev(l); |
153 | if (l) | 144 | else l = eina_list_last(contents); |
154 | l = eina_list_prev(l); | 145 | |
155 | else | 146 | while (l) |
156 | l = eina_list_last(contents); | 147 | { |
157 | 148 | obj = eina_list_data_get(l); | |
158 | while (l) | 149 | if (_can_focus(obj)) break; |
159 | { | 150 | obj = NULL; |
160 | obj = eina_list_data_get(l); | 151 | l = eina_list_prev(l); |
161 | if (_can_focus(obj)) | 152 | } |
162 | break; | 153 | } |
163 | obj = NULL; | 154 | else if ((dir == ELM_FOCUS_RIGHT) || (dir == ELM_FOCUS_DOWN)) |
164 | l = eina_list_prev(l); | 155 | { |
165 | } | 156 | if (l) l = eina_list_next(l); |
166 | } | 157 | else l = contents; |
167 | else if (dir == ELM_FOCUS_RIGHT || dir == ELM_FOCUS_DOWN) | 158 | while (l) |
168 | { | 159 | { |
169 | if (l) | 160 | obj = eina_list_data_get(l); |
170 | l = eina_list_next(l); | 161 | if (_can_focus(obj)) break; |
171 | else | 162 | obj = NULL; |
172 | l = contents; | 163 | l = eina_list_next(l); |
173 | while (l) | 164 | } |
174 | { | 165 | } |
175 | obj = eina_list_data_get(l); | 166 | eina_list_free(contents); |
176 | if (_can_focus(obj)) | 167 | } |
177 | break; | 168 | return obj; |
178 | obj = NULL; | ||
179 | l = eina_list_next(l); | ||
180 | } | ||
181 | } | ||
182 | eina_list_free(contents); | ||
183 | } | ||
184 | return obj; | ||
185 | } | 169 | } |
186 | 170 | ||
187 | 171 | ||
@@ -189,351 +173,319 @@ _find_focusable_object(const Elm_Gen_Item *it, | |||
189 | static Eina_Bool | 173 | static Eina_Bool |
190 | _check_item_contains(Elm_Gen_Item *it, const Evas_Object *base) | 174 | _check_item_contains(Elm_Gen_Item *it, const Evas_Object *base) |
191 | { | 175 | { |
192 | Eina_Bool res = EINA_FALSE; | 176 | Eina_Bool res = EINA_FALSE; |
193 | Eina_List *contents = NULL; | 177 | Eina_List *contents = NULL; |
194 | contents = _gengrid_item_contents_get(it); | 178 | contents = _gengrid_item_contents_get(it); |
195 | 179 | ||
196 | if (contents) | 180 | if (contents) |
197 | { | 181 | { |
198 | const Eina_List *l = NULL; | 182 | const Eina_List *l = NULL; |
199 | Evas_Object *content = NULL; | 183 | Evas_Object *content = NULL; |
200 | 184 | ||
201 | // loop contents (Evas_Object) of item | 185 | // loop contents (Evas_Object) of item |
202 | EINA_LIST_FOREACH(contents, l, content) | 186 | EINA_LIST_FOREACH(contents, l, content) |
203 | { | 187 | { |
204 | if (content == base) | 188 | if (content == base) |
205 | { | 189 | { |
206 | res = EINA_TRUE; | 190 | res = EINA_TRUE; |
207 | break; | 191 | break; |
208 | } | 192 | } |
209 | } | 193 | } |
210 | eina_list_free(contents); | 194 | eina_list_free(contents); |
211 | } | 195 | } |
212 | return res; | 196 | return res; |
213 | } | 197 | } |
214 | 198 | ||
215 | static Elm_Gen_Item * | 199 | static Elm_Gen_Item * |
216 | _find_item_for_base(const Evas_Object *obj, | 200 | _find_item_for_base(const Evas_Object *obj, |
217 | const Evas_Object *base) | 201 | const Evas_Object *base) |
218 | { | 202 | { |
219 | ELM_GENGRID_CHECK(obj) EINA_FALSE; | 203 | ELM_GENGRID_CHECK(obj) EINA_FALSE; |
220 | ELM_GENGRID_DATA_GET(obj, sd); | 204 | ELM_GENGRID_DATA_GET(obj, sd); |
221 | Elm_Gen_Item *res = NULL; | 205 | Elm_Gen_Item *res = NULL; |
222 | Elm_Gen_Item *it = (Elm_Gen_Item *)(sd->last_selected_item); | 206 | Elm_Gen_Item *it = (Elm_Gen_Item *)(sd->last_selected_item); |
223 | 207 | ||
224 | if (it && _check_item_contains(it, base)) | 208 | if (it && (_check_item_contains(it, base))) res = it; |
225 | { | 209 | else |
226 | res = it; | 210 | { // try find in all |
227 | } | 211 | EINA_INLIST_FOREACH(sd->items, it) |
228 | else | 212 | { |
229 | { // try find in all | 213 | if (it && _check_item_contains(it, base)) |
230 | EINA_INLIST_FOREACH(sd->items, it) | 214 | { |
231 | { | 215 | res = it; |
232 | if (it && _check_item_contains(it, base)) | 216 | break; |
233 | { | 217 | } |
234 | res = it; | 218 | } |
235 | break; | 219 | } |
236 | } | 220 | return res; |
237 | } | ||
238 | } | ||
239 | return res; | ||
240 | } | 221 | } |
241 | 222 | ||
242 | static Eina_Bool | 223 | static Eina_Bool |
243 | _gengrid_self_focus_item_get( | 224 | _gengrid_self_focus_item_get(const Evas_Object *obj, const Evas_Object *base, |
244 | const Evas_Object *obj, const Evas_Object *base, | 225 | // list of Elm_Gen_Items |
245 | // list of Elm_Gen_Items | 226 | const Eina_List *items, |
246 | const Eina_List *items, void *(*list_data_get)(const Eina_List *l), | 227 | void *(*list_data_get)(const Eina_List *l) EINA_UNUSED, |
247 | double degree, Evas_Object **direction, double *weight) | 228 | double degree, Evas_Object **direction, |
229 | double *weight) | ||
248 | { | 230 | { |
249 | Evas_Coord ox, oy; | 231 | Evas_Coord ox, oy; |
250 | Evas_Coord vw, vh; | 232 | Evas_Coord vw, vh; |
251 | const Evas_Object *res_obj = NULL; | 233 | const Evas_Object *res_obj = NULL; |
252 | Elm_Focus_Direction dir = ELM_FOCUS_UP; | 234 | Elm_Focus_Direction dir = ELM_FOCUS_UP; |
253 | 235 | unsigned int items_count = 0; | |
254 | unsigned int items_count = 0; | 236 | unsigned int columns = 0, items_visible = 0; |
255 | unsigned int columns = 0, items_visible = 0; | 237 | unsigned int items_row = 0, items_col = 0, rows = 0; |
256 | unsigned int items_row = 0, items_col = 0, rows = 0; | 238 | int new_position = 0; |
257 | int new_position = 0; | 239 | int cx = 0; |
258 | int cx = 0; | 240 | int cy = 0; |
259 | int cy = 0; | 241 | int focused_pos = 0; |
260 | 242 | Elm_Gen_Item *it = NULL; | |
261 | int focused_pos = 0; | 243 | Elm_Gen_Item *it_res = NULL; |
262 | 244 | Eina_List *list = NULL; | |
263 | Elm_Gen_Item *it = NULL; | 245 | Eina_List *l = NULL; |
264 | Elm_Gen_Item *it_res = NULL; | 246 | Elm_Gen_Item *focused_item = NULL; |
265 | Eina_List *list = NULL; | 247 | ELM_GENGRID_CHECK(obj) EINA_FALSE; |
266 | Eina_List *l = NULL; | 248 | ELM_GENGRID_DATA_GET(obj, sd); |
267 | 249 | ||
268 | Elm_Gen_Item *focused_item = NULL; | 250 | if ((!direction) || (!weight) || (!base) || (!items)) return EINA_FALSE; |
269 | 251 | ||
270 | (void)list_data_get; | 252 | evas_object_geometry_get(sd->pan_obj, &ox, &oy, &vw, &vh); |
271 | 253 | ||
272 | ELM_GENGRID_CHECK(obj) EINA_FALSE; | 254 | focused_item = _find_item_for_base(obj, base); |
273 | ELM_GENGRID_DATA_GET(obj, sd); | 255 | if (!focused_item) return EINA_FALSE; |
274 | 256 | ||
275 | if (!direction || !weight || !base || !items) return EINA_FALSE; | 257 | if (degree == 0) dir = ELM_FOCUS_UP; |
276 | 258 | else if (degree == 90) dir = ELM_FOCUS_RIGHT; | |
277 | evas_object_geometry_get(sd->pan_obj, &ox, &oy, &vw, &vh); | 259 | else if (degree == 180) dir = ELM_FOCUS_DOWN; |
278 | 260 | else if (degree == 270) dir = ELM_FOCUS_LEFT; | |
279 | focused_item = _find_item_for_base(obj, base); | 261 | else return EINA_FALSE; |
280 | 262 | ||
281 | if (!focused_item) return EINA_FALSE; | 263 | res_obj = _find_focusable_object(focused_item, base, dir); |
282 | 264 | if (res_obj && (res_obj != base)) | |
283 | 265 | { | |
284 | if (degree == 0) | 266 | *direction = (Evas_Object *)res_obj; |
285 | dir = ELM_FOCUS_UP; | 267 | *weight = WEIGHT_MAX; |
286 | else if (degree == 90) | 268 | return EINA_TRUE; |
287 | dir = ELM_FOCUS_RIGHT; | 269 | } |
288 | else if (degree == 180) | 270 | |
289 | dir = ELM_FOCUS_DOWN; | 271 | focused_pos = focused_item->position - 1; |
290 | else if (degree == 270) | 272 | |
291 | dir = ELM_FOCUS_LEFT; | 273 | items_count = sd->item_count - |
292 | else | 274 | eina_list_count(sd->group_items) + sd->items_lost; |
293 | return EINA_FALSE; | 275 | if (sd->horizontal) |
294 | 276 | { | |
295 | res_obj = _find_focusable_object(focused_item, base, dir); | 277 | if (sd->item_height > 0) items_visible = vh / sd->item_height; |
296 | if (res_obj && res_obj != base) | 278 | if (items_visible < 1) items_visible = 1; |
297 | { | 279 | |
298 | *direction = (Evas_Object *)res_obj; | 280 | columns = items_count / items_visible; |
299 | *weight = WEIGHT_MAX; | 281 | if (items_count % items_visible) columns++; |
300 | return EINA_TRUE; | 282 | |
301 | } | 283 | items_row = items_visible; |
302 | 284 | if (items_row > sd->item_count) items_row = sd->item_count; | |
303 | focused_pos = focused_item->position - 1; | 285 | |
304 | 286 | cx = focused_pos / items_row; | |
305 | items_count = | 287 | cy = focused_pos % items_row; |
306 | sd->item_count - eina_list_count(sd->group_items) + sd->items_lost; | 288 | } |
307 | if (sd->horizontal) | 289 | else |
308 | { | 290 | { |
309 | if (sd->item_height > 0) items_visible = vh / sd->item_height; | 291 | if (sd->item_width > 0) items_visible = vw / sd->item_width; |
310 | if (items_visible < 1) items_visible = 1; | 292 | if (items_visible < 1) items_visible = 1; |
311 | 293 | ||
312 | columns = items_count / items_visible; | 294 | rows = items_count / items_visible; |
313 | if (items_count % items_visible) columns++; | 295 | if (items_count % items_visible) rows++; |
314 | 296 | ||
315 | items_row = items_visible; | 297 | items_col = items_visible; |
316 | if (items_row > sd->item_count) items_row = sd->item_count; | 298 | if (items_col > sd->item_count) items_col = sd->item_count; |
317 | 299 | ||
318 | cx = focused_pos / items_row; | 300 | cy = focused_pos / items_col; |
319 | cy = focused_pos % items_row; | 301 | cx = focused_pos % items_col; |
320 | } | 302 | } |
321 | else | 303 | |
322 | { | 304 | |
323 | if (sd->item_width > 0) items_visible = vw / sd->item_width; | 305 | if (dir == ELM_FOCUS_UP) cy--; |
324 | if (items_visible < 1) items_visible = 1; | 306 | else if (dir == ELM_FOCUS_RIGHT) cx++; |
325 | 307 | else if (dir == ELM_FOCUS_DOWN) cy++; | |
326 | rows = items_count / items_visible; | 308 | else if (dir == ELM_FOCUS_LEFT) cx--; |
327 | if (items_count % items_visible) rows++; | 309 | |
328 | 310 | if (cx < 0 || cy < 0) return EINA_FALSE; | |
329 | items_col = items_visible; | 311 | |
330 | if (items_col > sd->item_count) items_col = sd->item_count; | 312 | if (sd->horizontal) |
331 | 313 | { | |
332 | cy = focused_pos / items_col; | 314 | if ((cy > (int)(items_row - 1)) || |
333 | cx = focused_pos % items_col; | 315 | (cx > (int)(columns - 1))) return EINA_FALSE; |
334 | } | 316 | new_position = items_row * cx + cy; |
335 | 317 | } | |
336 | 318 | else | |
337 | if (dir == ELM_FOCUS_UP) | 319 | { |
338 | cy--; | 320 | if ((cx > (int)(items_col - 1)) || |
339 | else if (dir == ELM_FOCUS_RIGHT) | 321 | (cy > (int)(rows - 1))) return EINA_FALSE; |
340 | cx++; | 322 | new_position = cx + items_col * cy; |
341 | else if (dir == ELM_FOCUS_DOWN) | 323 | } |
342 | cy++; | 324 | |
343 | else if (dir == ELM_FOCUS_LEFT) | 325 | if (new_position > (int)(items_count - 1)) return EINA_FALSE; |
344 | cx--; | 326 | |
345 | 327 | focused_pos++; | |
346 | if (cx < 0 || cy < 0) return EINA_FALSE; | 328 | new_position++; |
347 | 329 | ||
348 | if (sd->horizontal) | 330 | list = eina_list_data_find_list(items, focused_item); |
349 | { | 331 | |
350 | if ((cy > (int)(items_row - 1)) || | 332 | if (!list) return EINA_FALSE; |
351 | (cx > (int)(columns - 1))) return EINA_FALSE; | 333 | |
352 | new_position = items_row * cx + cy; | 334 | if (new_position > focused_pos) |
353 | } | 335 | { |
354 | else | 336 | /// New position should be after focused |
355 | { | 337 | EINA_LIST_FOREACH(list, l, it) |
356 | if ((cx > (int)(items_col - 1)) || | 338 | { |
357 | (cy > (int)(rows - 1))) return EINA_FALSE; | 339 | if (it->position == new_position) |
358 | new_position = cx + items_col * cy; | 340 | { |
359 | } | 341 | it_res = it; |
360 | 342 | break; | |
361 | if (new_position > (int)(items_count - 1)) return EINA_FALSE; | 343 | } |
362 | 344 | } | |
363 | focused_pos++; | 345 | } |
364 | new_position++; | 346 | else if (new_position < focused_pos) |
365 | 347 | { | |
366 | list = eina_list_data_find_list(items, focused_item); | 348 | /// New position should be before focused |
367 | 349 | EINA_LIST_REVERSE_FOREACH_INSIDE(list, l, it) | |
368 | if (!list) return EINA_FALSE; | 350 | { |
369 | 351 | if (it->position == new_position) | |
370 | if (new_position > focused_pos) | 352 | { |
371 | { | 353 | it_res = it; |
372 | /// New position should be after focused | 354 | break; |
373 | EINA_LIST_FOREACH(list, l, it) | 355 | } |
374 | { | 356 | } |
375 | if (it->position == new_position) | 357 | } |
376 | { | 358 | else return EINA_FALSE; |
377 | it_res = it; | 359 | |
378 | break; | 360 | if (it_res) |
379 | } | 361 | { |
380 | } | 362 | res_obj = _find_focusable_object(it_res, base, dir); |
381 | } | 363 | *direction = (Evas_Object *)res_obj; |
382 | else if (new_position < focused_pos) | 364 | *weight = WEIGHT_MAX; |
383 | { | 365 | return EINA_TRUE; |
384 | /// New position should be before focused | 366 | } |
385 | EINA_LIST_REVERSE_FOREACH_INSIDE(list, l, it) | 367 | return EINA_FALSE; |
386 | { | ||
387 | if (it->position == new_position) | ||
388 | { | ||
389 | it_res = it; | ||
390 | break; | ||
391 | } | ||
392 | } | ||
393 | } | ||
394 | else | ||
395 | { | ||
396 | return EINA_FALSE; | ||
397 | } | ||
398 | |||
399 | if (it_res) | ||
400 | { | ||
401 | res_obj = _find_focusable_object(it_res, base, dir); | ||
402 | *direction = (Evas_Object *)res_obj; | ||
403 | *weight = WEIGHT_MAX; | ||
404 | return EINA_TRUE; | ||
405 | } | ||
406 | return EINA_FALSE; | ||
407 | } | 368 | } |
408 | 369 | ||
409 | static Eina_Bool | 370 | static Eina_Bool |
410 | _gengrid_focus_list_direction_get( | 371 | _gengrid_focus_list_direction_get(const Evas_Object *obj, |
411 | const Evas_Object *obj, const Evas_Object *base, | 372 | const Evas_Object *base, |
412 | // list of Elm_Gen_Items | 373 | // list of Elm_Gen_Items |
413 | const Eina_List *items, void *(*list_data_get)(const Eina_List *l), | 374 | const Eina_List *items, |
414 | double degree, Evas_Object **direction, double *weight) | 375 | void *(*list_data_get)(const Eina_List *l), |
376 | double degree, Evas_Object **direction, | ||
377 | double *weight) | ||
415 | { | 378 | { |
416 | const Eina_List *l = NULL; | 379 | const Eina_List *l = NULL; |
417 | Evas_Object *current_best = NULL; | 380 | Evas_Object *current_best = NULL; |
418 | (void)list_data_get; | 381 | ELM_GENGRID_CHECK(obj) EINA_FALSE; |
419 | ELM_GENGRID_CHECK(obj) EINA_FALSE; | 382 | |
420 | if (!direction || !weight || !base || !items) return EINA_FALSE; | 383 | if ((!direction) || (!weight) || (!base) || (!items)) return EINA_FALSE; |
421 | 384 | ||
422 | l = items; | 385 | l = items; |
423 | current_best = *direction; | 386 | current_best = *direction; |
424 | 387 | ||
425 | // loop items Elm_Gen_Item | 388 | // loop items Elm_Gen_Item |
426 | for (; l; l = eina_list_next(l)) | 389 | for (; l; l = eina_list_next(l)) |
427 | { | 390 | { |
428 | Eina_List *contents = NULL; | 391 | Eina_List *contents = NULL; |
429 | Elm_Gen_Item *it = list_data_get(l); | 392 | Elm_Gen_Item *it = list_data_get(l); |
430 | contents = _gengrid_item_contents_get(it); | 393 | contents = _gengrid_item_contents_get(it); |
431 | if (contents) | 394 | if (contents) |
432 | { | 395 | { |
433 | const Eina_List *l2 = NULL; | 396 | const Eina_List *l2 = NULL; |
434 | Evas_Object *content = NULL; | 397 | Evas_Object *content = NULL; |
435 | 398 | ||
436 | // loop contents (Evas_Object) of item | 399 | // loop contents (Evas_Object) of item |
437 | EINA_LIST_FOREACH(contents, l2, content) | 400 | EINA_LIST_FOREACH(contents, l2, content) |
438 | { | 401 | { |
439 | // if better element than set new sd->focused and sd->selected | 402 | // if better element than set new sd->focused and sd->selected |
440 | elm_widget_focus_direction_get(content, base, degree, direction, | 403 | elm_widget_focus_direction_get(content, base, degree, |
441 | weight); | 404 | direction, weight); |
442 | } | 405 | } |
443 | eina_list_free(contents); | 406 | eina_list_free(contents); |
444 | } | 407 | } |
445 | } | 408 | } |
446 | if (current_best != *direction) | 409 | if (current_best != *direction) return EINA_TRUE; |
447 | return EINA_TRUE; | 410 | return EINA_FALSE; |
448 | else | ||
449 | return EINA_FALSE; | ||
450 | } | 411 | } |
451 | 412 | ||
452 | EAPI void | 413 | EAPI void |
453 | gen_focus_direction(Eo *obj, void *_pd, va_list *list) | 414 | gen_focus_direction(Eo *obj, void *_pd, va_list *list) |
454 | { | 415 | { |
455 | Eina_List *items = NULL; | 416 | Eina_List *items = NULL; |
456 | const Evas_Object *parent = NULL; | 417 | const Evas_Object *parent = NULL; |
457 | 418 | void *(*list_data_get)(const Eina_List * list); | |
458 | void *(*list_data_get)(const Eina_List * list); | 419 | Eina_List *(*list_free)(Eina_List * list); |
459 | Eina_List *(*list_free)(Eina_List * list); | 420 | Elm_Gengrid_Smart_Data *sd = _pd; |
460 | 421 | Eina_Bool (*list_direction_get)(const Evas_Object * obj, const Evas_Object * base, | |
461 | Elm_Gengrid_Smart_Data *sd = _pd; | 422 | const Eina_List * items, void * (*list_data_get)(const Eina_List * l), |
462 | 423 | double degree, Evas_Object * *direction, double * weight); | |
463 | Evas_Object *base = va_arg(*list, Evas_Object *); | 424 | |
464 | double degree = va_arg(*list, double); | 425 | Evas_Object *base = va_arg(*list, Evas_Object *); |
465 | Evas_Object **direction = va_arg(*list, Evas_Object **); | 426 | double degree = va_arg(*list, double); |
466 | double *weight = va_arg(*list, double *); | 427 | Evas_Object **direction = va_arg(*list, Evas_Object **); |
467 | Eina_Bool *ret = va_arg(*list, Eina_Bool *); | 428 | double *weight = va_arg(*list, double *); |
468 | 429 | Eina_Bool *ret = va_arg(*list, Eina_Bool *); | |
469 | if (!sd) | 430 | |
470 | { | 431 | if (!sd) |
471 | *ret = EINA_FALSE; | 432 | { |
472 | return; | 433 | *ret = EINA_FALSE; |
473 | } | 434 | return; |
474 | 435 | } | |
475 | 436 | ||
476 | *ret = EINA_FALSE; | 437 | *ret = EINA_FALSE; |
477 | list_data_get = NULL; | 438 | list_data_get = NULL; |
478 | 439 | list_direction_get = NULL; | |
479 | Eina_Bool (*list_direction_get)( | 440 | list_free = NULL; |
480 | const Evas_Object * obj, const Evas_Object * base, | 441 | parent = _find_gengrid_parent_item(base); |
481 | const Eina_List * items, void * (*list_data_get)(const Eina_List * l), | 442 | |
482 | double degree, Evas_Object * *direction, double * weight); | 443 | /// If focused is subobject of this gengrid then we selected next |
483 | 444 | /// in direction | |
484 | list_direction_get = NULL; | 445 | if (obj == parent) |
485 | list_free = NULL; | 446 | { |
486 | parent = _find_gengrid_parent_item(base); | 447 | items = elm_gengrid_realized_items_get(obj); |
487 | 448 | list_data_get = NULL; | |
488 | /// If focused is subobject of this gengrid then we selected next | 449 | list_direction_get = _gengrid_self_focus_item_get; |
489 | /// in direction | 450 | list_free = eina_list_free; |
490 | if (obj == parent) | 451 | } |
491 | { | 452 | |
492 | items = elm_gengrid_realized_items_get(obj); | 453 | if (!items) |
493 | list_data_get = NULL; | 454 | { |
494 | list_direction_get = _gengrid_self_focus_item_get; | 455 | items = (Eina_List *)(elm_object_focus_custom_chain_get(obj)); |
495 | list_free = eina_list_free; | 456 | list_data_get = eina_list_data_get; |
496 | } | 457 | list_direction_get = elm_widget_focus_list_direction_get; |
497 | 458 | list_free = NULL; | |
498 | if (!items) | 459 | } |
499 | { | 460 | |
500 | items = (Eina_List *)(elm_object_focus_custom_chain_get(obj)); | 461 | if (!items) |
501 | list_data_get = eina_list_data_get; | 462 | { |
502 | list_direction_get = elm_widget_focus_list_direction_get; | 463 | items = elm_gengrid_realized_items_get(obj); |
503 | list_free = NULL; | 464 | list_data_get = eina_list_data_get; |
504 | } | 465 | list_direction_get = _gengrid_focus_list_direction_get; |
505 | 466 | list_free = eina_list_free; | |
506 | if (!items) | 467 | } |
507 | { | 468 | |
508 | items = elm_gengrid_realized_items_get(obj); | 469 | if (!items) |
509 | list_data_get = eina_list_data_get; | 470 | { |
510 | list_direction_get = _gengrid_focus_list_direction_get; | 471 | *ret = EINA_FALSE; |
511 | list_free = eina_list_free; | 472 | return; |
512 | } | 473 | } |
513 | 474 | ||
514 | if (!items) | 475 | *ret = list_direction_get(obj, base, items, list_data_get, degree, |
515 | { | 476 | direction, weight); |
516 | *ret = EINA_FALSE; | 477 | if (list_free) list_free(items); |
517 | return; | ||
518 | } | ||
519 | |||
520 | *ret = list_direction_get(obj, base, items, list_data_get, degree, direction, | ||
521 | weight); | ||
522 | |||
523 | if (list_free) list_free(items); | ||
524 | } | 478 | } |
525 | 479 | ||
526 | // module api funcs needed | 480 | // module api funcs needed |
527 | EAPI int | 481 | EAPI int |
528 | elm_modapi_init(void *m) | 482 | elm_modapi_init(void *m EINA_UNUSED) |
529 | { | 483 | { |
530 | (void) m; | ||
531 | return 1; // succeed always | 484 | return 1; // succeed always |
532 | } | 485 | } |
533 | 486 | ||
534 | EAPI int | 487 | EAPI int |
535 | elm_modapi_shutdown(void *m) | 488 | elm_modapi_shutdown(void *m EINA_UNUSED) |
536 | { | 489 | { |
537 | (void) m; | ||
538 | return 1; // succeed always | 490 | return 1; // succeed always |
539 | } | 491 | } |