summaryrefslogtreecommitdiff
path: root/src/bin/e_widget_toolbar.c
diff options
context:
space:
mode:
authorChristopher Michael <cpmichael1@comcast.net>2009-07-28 01:33:08 +0000
committerChristopher Michael <cpmichael1@comcast.net>2009-07-28 01:33:08 +0000
commit619fc7a98a6c25328a462638e2511482451f36da (patch)
tree1cf550dd3a377ca68ef121ad0c371014360aa79a /src/bin/e_widget_toolbar.c
parentf16d0a13ef9bd9f7f8ec3570fa7196db32f5c083 (diff)
Two patches from Peter van de Werken
- Hide eina_list internals by using eina macros - Cleanup some duplicate code Patches slightly modified for formatting & whitespace removal. Use eina_list internal macros in some places that were missed. SVN revision: 41518
Diffstat (limited to 'src/bin/e_widget_toolbar.c')
-rw-r--r--src/bin/e_widget_toolbar.c183
1 files changed, 84 insertions, 99 deletions
diff --git a/src/bin/e_widget_toolbar.c b/src/bin/e_widget_toolbar.c
index d205a6f..6f2a5dc 100644
--- a/src/bin/e_widget_toolbar.c
+++ b/src/bin/e_widget_toolbar.c
@@ -30,6 +30,8 @@ static void _e_wid_signal_cb1(void *data, Evas_Object *obj, const char *emission
30static void _e_wid_cb_scrollframe_resize(void *data, Evas *e, Evas_Object *obj, void *event_info); 30static void _e_wid_cb_scrollframe_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
31static void _e_wid_cb_key_down(void *data, Evas *evas, Evas_Object *obj, void *event_info); 31static void _e_wid_cb_key_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
32static void _item_show(Item *it); 32static void _item_show(Item *it);
33static void _item_select(Item *it);
34static void _item_unselect(Item *it);
33 35
34/* local subsystem functions */ 36/* local subsystem functions */
35 37
@@ -40,18 +42,18 @@ e_widget_toolbar_add(Evas *evas, int icon_w, int icon_h)
40 Evas_Object *obj, *o; 42 Evas_Object *obj, *o;
41 E_Widget_Data *wd; 43 E_Widget_Data *wd;
42 Evas_Coord mw = 0, mh = 0; 44 Evas_Coord mw = 0, mh = 0;
43 45
44 obj = e_widget_add(evas); 46 obj = e_widget_add(evas);
45 47
46 e_widget_del_hook_set(obj, _e_wid_del_hook); 48 e_widget_del_hook_set(obj, _e_wid_del_hook);
47 e_widget_focus_hook_set(obj, _e_wid_focus_hook); 49 e_widget_focus_hook_set(obj, _e_wid_focus_hook);
48 e_widget_disable_hook_set(obj, _e_wid_disable_hook); 50 e_widget_disable_hook_set(obj, _e_wid_disable_hook);
49 wd = calloc(1, sizeof(E_Widget_Data)); 51 wd = E_NEW(E_Widget_Data, 1);
50 e_widget_data_set(obj, wd); 52 e_widget_data_set(obj, wd);
51 wd->icon_w = icon_w; 53 wd->icon_w = icon_w;
52 wd->icon_h = icon_h; 54 wd->icon_h = icon_h;
53 wd->focus_steal = EINA_TRUE; 55 wd->focus_steal = EINA_TRUE;
54 56
55 o = e_scrollframe_add(evas); 57 o = e_scrollframe_add(evas);
56 wd->o_base = o; 58 wd->o_base = o;
57 o = e_box_add(evas); 59 o = e_box_add(evas);
@@ -79,11 +81,11 @@ e_widget_toolbar_add(Evas *evas, int icon_w, int icon_h)
79 e_scrollframe_child_set(wd->o_base, o); 81 e_scrollframe_child_set(wd->o_base, o);
80 e_widget_sub_object_add(obj, o); 82 e_widget_sub_object_add(obj, o);
81 evas_object_show(o); 83 evas_object_show(o);
82 84
83 edje_object_size_min_calc 85 edje_object_size_min_calc
84 (e_scrollframe_edje_object_get(wd->o_base), &mw, &mh); 86 (e_scrollframe_edje_object_get(wd->o_base), &mw, &mh);
85 e_widget_min_size_set(obj, mw, mh); 87 e_widget_min_size_set(obj, mw, mh);
86 88
87 return obj; 89 return obj;
88} 90}
89 91
@@ -94,7 +96,7 @@ e_widget_toolbar_item_append(Evas_Object *obj, Evas_Object *icon, const char *la
94 Evas_Object *o; 96 Evas_Object *o;
95 Item *it; 97 Item *it;
96 Evas_Coord mw = 0, mh = 0, vw = 0, vh = 0; 98 Evas_Coord mw = 0, mh = 0, vw = 0, vh = 0;
97 99
98 wd = e_widget_data_get(obj); 100 wd = e_widget_data_get(obj);
99 o = edje_object_add(evas_object_evas_get(obj)); 101 o = edje_object_add(evas_object_evas_get(obj));
100 e_theme_edje_object_set(o, "base/theme/widgets", 102 e_theme_edje_object_set(o, "base/theme/widgets",
@@ -155,43 +157,31 @@ e_widget_toolbar_item_remove(Evas_Object *obj, int num)
155EAPI void 157EAPI void
156e_widget_toolbar_item_select(Evas_Object *obj, int num) 158e_widget_toolbar_item_select(Evas_Object *obj, int num)
157{ 159{
158 E_Widget_Data *wd; 160 E_Widget_Data *wd = NULL;
159 Eina_List *l; 161 Eina_List *l = NULL;
160 Item *it; 162 Item *it = NULL;
161 int i; 163 int i = 0;
162 164
163 wd = e_widget_data_get(obj); 165 wd = e_widget_data_get(obj);
164 for (i = 0, l = wd->items; l; l = l->next, i++) 166 EINA_LIST_FOREACH(wd->items, l, it)
165 { 167 {
166 it = l->data;
167 if (i == num) 168 if (i == num)
168 { 169 {
169 if (!it->selected) 170 if (!it->selected) _item_select(it);
170 {
171 it->selected = EINA_TRUE;
172 edje_object_signal_emit(it->o_base, "e,state,selected", "e");
173 edje_object_signal_emit(it->o_icon, "e,state,selected", "e");
174 _item_show(it);
175 if (it->func) it->func(it->data1, it->data2);
176 }
177 } 171 }
178 else 172 else
179 { 173 {
180 if (it->selected) 174 if (it->selected) _item_unselect(it);
181 {
182 it->selected = EINA_FALSE;
183 edje_object_signal_emit(it->o_base, "e,state,unselected", "e");
184 edje_object_signal_emit(it->o_icon, "e,state,unselected", "e");
185 }
186 } 175 }
176 i++;
187 } 177 }
188} 178}
189 179
190EAPI void 180EAPI void
191e_widget_toolbar_item_label_set(Evas_Object *obj, int num, const char *label) 181e_widget_toolbar_item_label_set(Evas_Object *obj, int num, const char *label)
192{ 182{
193 E_Widget_Data *wd; 183 E_Widget_Data *wd = NULL;
194 Item *it; 184 Item *it = NULL;
195 185
196 wd = e_widget_data_get(obj); 186 wd = e_widget_data_get(obj);
197 it = eina_list_nth(wd->items, num); 187 it = eina_list_nth(wd->items, num);
@@ -216,7 +206,7 @@ e_widget_toolbar_scrollable_set(Evas_Object *obj, Eina_Bool scrollable)
216{ 206{
217 E_Widget_Data *wd; 207 E_Widget_Data *wd;
218 Evas_Coord mw = 0, mh = 0, vw = 0, vh = 0; 208 Evas_Coord mw = 0, mh = 0, vw = 0, vh = 0;
219 209
220 wd = e_widget_data_get(obj); 210 wd = e_widget_data_get(obj);
221 wd->scrollable = scrollable; 211 wd->scrollable = scrollable;
222 e_box_min_size_get(wd->o_box, &mw, &mh); 212 e_box_min_size_get(wd->o_box, &mw, &mh);
@@ -255,18 +245,15 @@ e_widget_toolbar_focus_steal_set(Evas_Object *obj, Eina_Bool steal)
255EAPI void 245EAPI void
256e_widget_toolbar_clear(Evas_Object *obj) 246e_widget_toolbar_clear(Evas_Object *obj)
257{ 247{
258 E_Widget_Data *wd; 248 E_Widget_Data *wd = NULL;
249 Item *it = NULL;
259 250
260 wd = e_widget_data_get(obj); 251 wd = e_widget_data_get(obj);
261 while (wd->items) 252 EINA_LIST_FREE(wd->items, it)
262 { 253 {
263 Item *it = NULL; 254 evas_object_del(it->o_base);
264 255 evas_object_del(it->o_icon);
265 if (!(it = wd->items->data)) continue; 256 E_FREE(it);
266 evas_object_del(it->o_base);
267 evas_object_del(it->o_icon);
268 wd->items = eina_list_remove(wd->items, it);
269 E_FREE(it);
270 } 257 }
271} 258}
272 259
@@ -275,15 +262,14 @@ e_widget_toolbar_item_selected_get(Evas_Object *obj)
275{ 262{
276 E_Widget_Data *wd = NULL; 263 E_Widget_Data *wd = NULL;
277 Eina_List *l = NULL; 264 Eina_List *l = NULL;
265 Item *it = NULL;
278 int i = 0; 266 int i = 0;
279 267
280 wd = e_widget_data_get(obj); 268 wd = e_widget_data_get(obj);
281 for (i = 0, l = wd->items; l; l = l->next, i++) 269 EINA_LIST_FOREACH(wd->items, l, it)
282 { 270 {
283 Item *it = NULL;
284
285 if (!(it = l->data)) continue;;
286 if (it->selected) return i; 271 if (it->selected) return i;
272 i++;
287 } 273 }
288 return 0; 274 return 0;
289} 275}
@@ -293,16 +279,13 @@ static void
293_e_wid_del_hook(Evas_Object *obj) 279_e_wid_del_hook(Evas_Object *obj)
294{ 280{
295 E_Widget_Data *wd; 281 E_Widget_Data *wd;
296 282 Item *it;
283
297 wd = e_widget_data_get(obj); 284 wd = e_widget_data_get(obj);
298 while (wd->items) 285 EINA_LIST_FREE(wd->items, it)
299 { 286 {
300 Item *it;
301
302 it = wd->items->data;
303 evas_object_del(it->o_base); 287 evas_object_del(it->o_base);
304 evas_object_del(it->o_icon); 288 evas_object_del(it->o_icon);
305 wd->items = eina_list_remove_list(wd->items, wd->items);
306 E_FREE(it); 289 E_FREE(it);
307 } 290 }
308 E_FREE(wd); 291 E_FREE(wd);
@@ -312,7 +295,7 @@ static void
312_e_wid_disable_hook(Evas_Object *obj) 295_e_wid_disable_hook(Evas_Object *obj)
313{ 296{
314 E_Widget_Data *wd; 297 E_Widget_Data *wd;
315 298
316 wd = e_widget_data_get(obj); 299 wd = e_widget_data_get(obj);
317 if (e_widget_disabled_get(obj)) 300 if (e_widget_disabled_get(obj))
318 edje_object_signal_emit 301 edje_object_signal_emit
@@ -328,26 +311,19 @@ _e_wid_signal_cb1(void *data, Evas_Object *obj, const char *emission, const char
328 Item *it, *it2; 311 Item *it, *it2;
329 E_Widget_Data *wd; 312 E_Widget_Data *wd;
330 Eina_List *l; 313 Eina_List *l;
331 314
332 it = data; 315 if (!(it = data)) return;
333 if (it->selected) return; 316 if (it->selected) return;
334 wd = e_widget_data_get(it->o_toolbar); 317 wd = e_widget_data_get(it->o_toolbar);
335 for (l = wd->items; l; l = l->next) 318 EINA_LIST_FOREACH(wd->items, l, it2)
336 { 319 {
337 it2 = l->data;
338 if (it2->selected) 320 if (it2->selected)
339 { 321 {
340 it2->selected = EINA_FALSE; 322 _item_unselect(it2);
341 edje_object_signal_emit(it2->o_base, "e,state,unselected", "e");
342 edje_object_signal_emit(it2->o_icon, "e,state,unselected", "e");
343 break; 323 break;
344 } 324 }
345 } 325 }
346 it->selected = EINA_TRUE; 326 _item_select(it);
347 edje_object_signal_emit(it->o_base, "e,state,selected", "e");
348 edje_object_signal_emit(it->o_icon, "e,state,selected", "e");
349 _item_show(it);
350 if (it->func) it->func(it->data1, it->data2);
351} 327}
352 328
353static void 329static void
@@ -357,7 +333,7 @@ _e_wid_cb_scrollframe_resize(void *data, Evas *e, Evas_Object *obj, void *event_
357 Evas_Coord mw, mh, vw, vh, w, h; 333 Evas_Coord mw, mh, vw, vh, w, h;
358 Eina_List *l; 334 Eina_List *l;
359 Item *it; 335 Item *it;
360 336
361 wd = e_widget_data_get(data); 337 wd = e_widget_data_get(data);
362 338
363 if (wd->o_base == NULL || wd->o_box == NULL) return ; 339 if (wd->o_base == NULL || wd->o_box == NULL) return ;
@@ -369,9 +345,8 @@ _e_wid_cb_scrollframe_resize(void *data, Evas *e, Evas_Object *obj, void *event_
369 { 345 {
370 if (w != vw) evas_object_resize(wd->o_box, vw, h); 346 if (w != vw) evas_object_resize(wd->o_box, vw, h);
371 } 347 }
372 for (l = wd->items; l; l = l->next) 348 EINA_LIST_FOREACH(wd->items, l, it)
373 { 349 {
374 it = l->data;
375 if (it->selected) 350 if (it->selected)
376 { 351 {
377 _item_show(it); 352 _item_show(it);
@@ -385,74 +360,67 @@ _e_wid_cb_key_down(void *data, Evas *evas, Evas_Object *obj, void *event_info)
385{ 360{
386 Evas_Event_Key_Down *ev; 361 Evas_Event_Key_Down *ev;
387 E_Widget_Data *wd; 362 E_Widget_Data *wd;
388 Eina_List *l; 363 Eina_List *l, *l2;
389 Item *it = NULL, *it2 = NULL; 364 Item *it = NULL, *it2 = NULL;
390 365
391 ev = event_info; 366 ev = event_info;
392 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; 367 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
393 wd = e_widget_data_get(data); 368 wd = e_widget_data_get(data);
394 if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")) || 369 if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")) ||
395 (!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) 370 (!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
396 )
397 { 371 {
398 for (l = wd->items; l; l = l->next) 372 EINA_LIST_FOREACH(wd->items, l, it)
399 { 373 {
400 it = l->data;
401 if (it->selected) 374 if (it->selected)
402 { 375 {
403 if (l->prev) it2 = l->prev->data; 376 l2 = eina_list_prev(l);
377 if (l2) it2 = eina_list_data_get(l2);
404 break; 378 break;
405 } 379 }
406 } 380 }
407 } 381 }
408 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")) || 382 else if ((!strcmp(ev->keyname, "Down")) ||
409 (!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) 383 (!strcmp(ev->keyname, "KP_Down")) ||
410 ) 384 (!strcmp(ev->keyname, "Right")) ||
385 (!strcmp(ev->keyname, "KP_Right")))
411 { 386 {
412 for (l = wd->items; l; l = l->next) 387 EINA_LIST_FOREACH(wd->items, l, it)
413 { 388 {
414 it = l->data;
415 if (it->selected) 389 if (it->selected)
416 { 390 {
417 if (l->next) it2 = l->next->data; 391 l2 = eina_list_next(l);
392 if (l2) it2 = eina_list_data_get(l2);
418 break; 393 break;
419 } 394 }
420 } 395 }
421 } 396 }
422 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home"))) 397 else if ((!strcmp(ev->keyname, "Home")) ||
398 (!strcmp(ev->keyname, "KP_Home")))
423 { 399 {
424 for (l = wd->items; l; l = l->next) 400 EINA_LIST_FOREACH(wd->items, l, it)
425 { 401 {
426 it = l->data;
427 if (it->selected) 402 if (it->selected)
428 { 403 {
429 it2 = wd->items->data; 404 it2 = eina_list_data_get(wd->items);
430 break; 405 break;
431 } 406 }
432 } 407 }
433 } 408 }
434 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End"))) 409 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
435 { 410 {
436 for (l = wd->items; l; l = l->next) 411 EINA_LIST_FOREACH(wd->items, l, it)
437 { 412 {
438 it = l->data;
439 if (it->selected) 413 if (it->selected)
440 { 414 {
441 it2 = eina_list_last(wd->items)->data; 415 it2 = eina_list_data_get(eina_list_last(wd->items));
442 break; 416 break;
443 } 417 }
444 } 418 }
445 } 419 }
446 if ((it) && (it2) && (it != it2)) 420 if ((it) && (it2) && (it != it2))
447 { 421 {
448 it->selected = EINA_FALSE; 422 _item_unselect(it);
449 edje_object_signal_emit(it->o_base, "e,state,unselected", "e"); 423 _item_select(it2);
450 edje_object_signal_emit(it->o_icon, "e,state,unselected", "e");
451 it2->selected = EINA_TRUE;
452 edje_object_signal_emit(it2->o_base, "e,state,selected", "e");
453 edje_object_signal_emit(it2->o_icon, "e,state,selected", "e");
454 _item_show(it2);
455 if (it2->func) it->func(it2->data1, it2->data2);
456 } 424 }
457} 425}
458 426
@@ -460,17 +428,17 @@ static void
460_e_wid_focus_hook(Evas_Object *obj) 428_e_wid_focus_hook(Evas_Object *obj)
461{ 429{
462 E_Widget_Data *wd; 430 E_Widget_Data *wd;
463 431
464 wd = e_widget_data_get(obj); 432 wd = e_widget_data_get(obj);
465 if (e_widget_focus_get(obj)) 433 if (e_widget_focus_get(obj))
466 { 434 {
467 edje_object_signal_emit(wd->o_base, "e,state,focused", "e"); 435 edje_object_signal_emit(wd->o_base, "e,state,focused", "e");
468 evas_object_focus_set(obj, 1); 436 evas_object_focus_set(obj, EINA_TRUE);
469 } 437 }
470 else 438 else
471 { 439 {
472 edje_object_signal_emit(wd->o_base, "e,state,unfocused", "e"); 440 edje_object_signal_emit(wd->o_base, "e,state,unfocused", "e");
473 evas_object_focus_set(obj, 0); 441 evas_object_focus_set(obj, EINA_FALSE);
474 } 442 }
475} 443}
476 444
@@ -485,10 +453,27 @@ _item_show(Item *it)
485{ 453{
486 E_Widget_Data *wd; 454 E_Widget_Data *wd;
487 Evas_Coord x, y, w, h, bx, by; 455 Evas_Coord x, y, w, h, bx, by;
488 456
489 wd = e_widget_data_get(it->o_toolbar); 457 wd = e_widget_data_get(it->o_toolbar);
490 evas_object_geometry_get(wd->o_box, &bx, &by, NULL, NULL); 458 evas_object_geometry_get(wd->o_box, &bx, &by, NULL, NULL);
491 evas_object_geometry_get(it->o_base, &x, &y, &w, &h); 459 evas_object_geometry_get(it->o_base, &x, &y, &w, &h);
492 e_scrollframe_child_region_show(wd->o_base, x - bx, y - by, w, h); 460 e_scrollframe_child_region_show(wd->o_base, x - bx, y - by, w, h);
493} 461}
494 462
463static void
464_item_select(Item *it)
465{
466 it->selected = EINA_TRUE;
467 edje_object_signal_emit(it->o_base, "e,state,selected", "e");
468 edje_object_signal_emit(it->o_icon, "e,state,selected", "e");
469 _item_show(it);
470 if (it->func) it->func(it->data1, it->data2);
471}
472
473static void
474_item_unselect(Item *it)
475{
476 it->selected = EINA_FALSE;
477 edje_object_signal_emit(it->o_base, "e,state,unselected", "e");
478 edje_object_signal_emit(it->o_icon, "e,state,unselected", "e");
479}