summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>2015-07-26 18:52:58 +0200
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2015-07-26 18:52:58 +0200
commite878f22e28f572b7335819bae3baf0961ba38bd9 (patch)
treef9e067be0264b1f2437fde4d33ad4688d445831b
parentbf9f63bf4b38c1d6c2db835b6801462a7ac99d82 (diff)
elm_items_display: added algorithem to convert all visible items into a
lib
-rw-r--r--src/lib/items/elm_items_display.c323
-rw-r--r--src/lib/items/elm_items_priv.h2
2 files changed, 268 insertions, 57 deletions
diff --git a/src/lib/items/elm_items_display.c b/src/lib/items/elm_items_display.c
index 7b1b949..249c0f5 100644
--- a/src/lib/items/elm_items_display.c
+++ b/src/lib/items/elm_items_display.c
@@ -10,6 +10,9 @@ typedef struct {
10 Eina_List *realized; 10 Eina_List *realized;
11} Elm_Items_Pan_Data; 11} Elm_Items_Pan_Data;
12 12
13static Eina_Bool _del(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED);
14static Eina_Bool _add(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED);
15
13//================================== 16//==================================
14// Pan implement 17// Pan implement
15//================================== 18//==================================
@@ -160,6 +163,7 @@ EOLIAN static Eina_Bool
160_elm_items_display_elm_widget_event(Eo *obj, Elm_Items_Display_Data *pd, Evas_Object *source EINA_UNUSED, Evas_Callback_Type type, void *event_info) 163_elm_items_display_elm_widget_event(Eo *obj, Elm_Items_Display_Data *pd, Evas_Object *source EINA_UNUSED, Evas_Callback_Type type, void *event_info)
161{ 164{
162 Evas_Event_Key_Down *ev; 165 Evas_Event_Key_Down *ev;
166
163 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_TRUE; 167 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_TRUE;
164 168
165 ev = event_info; 169 ev = event_info;
@@ -303,61 +307,6 @@ _elm_items_display_search(Eo *obj EINA_UNUSED, Elm_Items_Display_Data *pd, const
303 eo_do(searched, elm_items_item_selected_set(EINA_TRUE)); 307 eo_do(searched, elm_items_item_selected_set(EINA_TRUE));
304} 308}
305 309
306static Eina_Bool
307_selected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
308{
309 Elm_Items_Display_Data *pd;
310
311 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS);
312 pd->selected = eina_list_append(pd->selected, obj);
313 return EO_CALLBACK_CONTINUE;
314}
315
316static Eina_Bool
317_unselected(void *data, Eo *obj, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
318{
319 Elm_Items_Display_Data *pd;
320
321 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS);
322 pd->selected = eina_list_remove(pd->selected, obj);
323 return EO_CALLBACK_CONTINUE;
324}
325
326static Eina_Bool
327_del(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
328{
329 Elm_Items_Display_Data *pd;
330 Eo *good;
331
332 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS);
333
334 eo_do(event, good = efl_tree_base_carry_get());
335 eo_do(good, eo_event_callback_del(ELM_ITEMS_ITEM_EVENT_SELECTED, _selected, data);
336 eo_event_callback_del(ELM_ITEMS_ITEM_EVENT_UNSELECTED, _unselected, data);
337 );
338 //TODO remove from realitems list
339 //remove from selected
340 pd->selected = eina_list_remove(pd->selected, good);
341 //remove from potential realized
342 eo_do(pd->pan, elm_items_pan_item_del(good));
343 return EO_CALLBACK_CONTINUE;
344}
345
346static Eina_Bool
347_add(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
348{
349 Eo *good;
350
351 //subscribe to events
352 eo_do(event, good = efl_tree_base_carry_get());
353 eo_do(good, eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_SELECTED, _selected, data);
354 eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_UNSELECTED, _unselected, data);
355 );
356 //TODO put in realitems list
357 //XXX: check if selected and add to list
358 return EO_CALLBACK_CONTINUE;
359}
360
361EOLIAN static Eina_List * 310EOLIAN static Eina_List *
362_elm_items_display_selected_get(Eo *obj EINA_UNUSED, Elm_Items_Display_Data *pd) 311_elm_items_display_selected_get(Eo *obj EINA_UNUSED, Elm_Items_Display_Data *pd)
363{ 312{
@@ -372,9 +321,7 @@ _elm_items_display_eo_base_constructor(Eo *obj, Elm_Items_Display_Data *pd)
372 pd->root = eo_add(EFL_TREE_BASE_CLASS, NULL); 321 pd->root = eo_add(EFL_TREE_BASE_CLASS, NULL);
373 322
374 eo_do(pd->root, 323 eo_do(pd->root,
375 eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_DEL_RECURSIVE, _del, obj);
376 eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_DEL_DIRECT, _del, obj); 324 eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_DEL_DIRECT, _del, obj);
377 eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_ADD_RECURSIVE, _add, obj);
378 eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_ADD_DIRECT, _add, obj); 325 eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_ADD_DIRECT, _add, obj);
379 ); 326 );
380 327
@@ -422,6 +369,268 @@ _elm_items_display_item_search_xywh(Eo *obj EINA_UNUSED, Elm_Items_Display_Data
422 } 369 }
423 return items; 370 return items;
424} 371}
372//==================================
373// Selection tracking
374//==================================
375
376static Eina_Bool
377_selected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
378{
379 Elm_Items_Display_Data *pd;
380
381 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS);
382 pd->selected = eina_list_append(pd->selected, obj);
383 return EO_CALLBACK_CONTINUE;
384}
385
386static Eina_Bool
387_unselected(void *data, Eo *obj, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
388{
389 Elm_Items_Display_Data *pd;
390
391 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS);
392 pd->selected = eina_list_remove(pd->selected, obj);
393 return EO_CALLBACK_CONTINUE;
394}
395
396//==================================
397// Tree tracking
398//==================================
399
400static void _item_insert(Eo *obj, Elm_Items_Display_Data *pd, Efl_Tree_Base *child, Efl_Tree_Base *parent);
401static void _item_remove(Eo *obj, Elm_Items_Display_Data *pd, Efl_Tree_Base *child);
402
403static void
404unexpand(Eo *obj, Efl_Tree_Base *item)
405{
406 Eina_List *children;
407 Eina_List *node;
408 Efl_Tree_Base *child;
409 Elm_Items_Display_Data *pd;
410
411 pd = eo_data_scope_get(obj, ELM_ITEMS_DISPLAY_CLASS);
412 eo_do(item, children = efl_tree_base_children(EINA_FALSE));
413
414 EINA_LIST_FOREACH(children, node, child)
415 {
416 _item_remove(obj, pd, child);
417 }
418}
419
420static void
421expand(Eo *obj, Efl_Tree_Base *item)
422{
423 Eina_List *children;
424 Eina_List *node;
425 Efl_Tree_Base *child;
426 Elm_Items_Display_Data *pd;
427
428 pd = eo_data_scope_get(obj, ELM_ITEMS_DISPLAY_CLASS);
429 eo_do(item, children = efl_tree_base_children(EINA_FALSE));
430
431 EINA_LIST_FOREACH(children, node, child)
432 {
433 _item_insert(obj, pd, child, item);
434 }
435}
436
437static Eina_Bool
438_realitems_change_idle(void *data)
439{
440 Elm_Items_Display_Data *pd;
441 Elm_Items_Item *it;
442 Eina_List *node;
443
444 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS);
445
446 printf("REALITEMS UPDATE\n");
447 EINA_LIST_FOREACH(pd->realitems, node, it)
448 {
449 printf(" Item: %p\n", it);
450 }
451
452 eo_do(pd->pan, elm_items_pan_realitems(pd->realitems));
453
454 pd->realitems_idler = NULL;
455 return EINA_FALSE;
456}
457
458static void
459_update(Elm_Items_Display *display)
460{
461 Elm_Items_Display_Data *pd;
462
463 pd = eo_data_scope_get(display, ELM_ITEMS_DISPLAY_CLASS);
464
465 if (!pd->realitems_idler)
466 pd->realitems_idler = ecore_idler_add(_realitems_change_idle, display);
467}
468
469static Eina_Bool
470_expanded(void *data, Eo *obj, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
471{
472 Eo *item;
473
474 //add all children
475 eo_do(obj, item = elm_items_item_get());
476 expand(data, item);
477 _update(data);
478 return EO_CALLBACK_CONTINUE;
479}
480
481static Eina_Bool
482_unexpanded(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
483{
484 Eo *item;
485
486 //remove all children
487 eo_do(obj, item = elm_items_item_get());
488 unexpand(data, obj);
489 _update(data);
490 return EO_CALLBACK_CONTINUE;
491}
492
493static Eina_Bool
494_del(void *data, Eo *obj, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
495{
496 Elm_Items_Display_Data *pd;
497 Eina_Bool expanded;
498 Elm_Items_Item *item;
499
500 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS);
501 if (obj != pd->root)
502 {
503 eo_do(obj, item = efl_tree_base_carry_get());
504 eo_do(item, expanded = elm_items_item_expandable_get());
505
506 if (!expanded) return EO_CALLBACK_CONTINUE;
507 }
508 _item_remove(data, pd, event);
509 //remove from potential realized
510 eo_do(pd->pan, elm_items_pan_item_del(event));
511 _update(data);
512 return EO_CALLBACK_CONTINUE;
513}
514
515static Eina_Bool
516_add(void *data, Eo *obj, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
517{
518 Elm_Items_Display_Data *pd;
519 Eina_Bool expanded;
520 Elm_Items_Item *item;
521
522 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS);
523 if (obj != pd->root)
524 {
525 eo_do(obj, item = efl_tree_base_carry_get());
526 eo_do(item, expanded = elm_items_item_expandable_get());
527
528 printf("expanded %d\n", expanded);
529 if (!expanded) return EO_CALLBACK_CONTINUE;
530 }
531
532 _item_insert(data, pd, event, obj);
533 printf("ADD\n");
534 _update(data);
535 return EO_CALLBACK_CONTINUE;
536}
537
538static void
539_item_remove(Eo *obj, Elm_Items_Display_Data *pd, Efl_Tree_Base *child)
540{
541 Elm_Items_Item *item;
542
543 eo_do(child,
544 //get the carry of the child
545 item = efl_tree_base_carry_get();
546 eo_event_callback_del(EFL_TREE_BASE_EVENT_CHILDREN_ADD_DIRECT, _add, obj);
547 eo_event_callback_del(EFL_TREE_BASE_EVENT_CHILDREN_DEL_DIRECT, _del, obj);
548 );
549 //subscribe to events which are changing the realitems
550 eo_do(item,
551 eo_event_callback_del(ELM_ITEMS_ITEM_EVENT_SELECTED, _selected, obj);
552 eo_event_callback_del(ELM_ITEMS_ITEM_EVENT_UNSELECTED, _unselected, obj);
553 eo_event_callback_del(ELM_ITEMS_ITEM_EVENT_EXPANDED , _expanded, obj);
554 eo_event_callback_del(ELM_ITEMS_ITEM_EVENT_UNEXPANDED, _unexpanded, obj);
555 );
556
557 pd->realitems = eina_list_remove(pd->realitems, item);
558 pd->selected = eina_list_remove(pd->selected, item);
559
560 {
561 Eina_Bool expanded;
562
563 eo_do(item, expanded = elm_items_item_expanded_get());
564 if (expanded)
565 unexpand(obj, child);
566 }
567}
568
569static void
570_item_insert(Eo *obj, Elm_Items_Display_Data *pd, Efl_Tree_Base *child, Efl_Tree_Base *parent)
571{
572 Elm_Items_Item *item;
573 Efl_Tree_Base *prev, *next;
574 eo_do(child,
575 //get the carry of the child
576 item = efl_tree_base_carry_get();
577 //subscribe to events of the tree
578 eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_ADD_DIRECT, _add, obj);
579 eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_DEL_DIRECT, _del, obj);
580 //get the relatives
581 next = efl_tree_base_next_get();
582 prev = efl_tree_base_next_get();
583 );
584 //subscribe to events which are changing the realitems
585 eo_do(item,
586 eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_SELECTED, _selected, obj);
587 eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_UNSELECTED, _unselected, obj);
588 eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_EXPANDED , _expanded, obj);
589 eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_UNEXPANDED, _unexpanded, obj);
590 );
591 //add into the realitems
592 {
593 Eo *good2;
594
595 if (next)
596 {
597 eo_do(next, good2 = efl_tree_base_carry_get());
598 pd->realitems = eina_list_prepend_relative(pd->realitems, item, good2);
599 }
600 else if (prev)
601 {
602 eo_do(prev, good2 = efl_tree_base_carry_get());
603 pd->realitems = eina_list_append_relative(pd->realitems, item, good2);
604 }
605 else if (parent)
606 {
607 eo_do(parent, good2 = efl_tree_base_carry_get());
608 pd->realitems = eina_list_append_relative(pd->realitems, item, good2);
609 }
610 else
611 {
612 eo_do(prev, good2 = efl_tree_base_carry_get());
613 pd->realitems = eina_list_append(pd->realitems, item);
614 }
615 }
616 //check if it is selected when it got added
617 {
618 Eina_Bool selected;
619
620 eo_do(item, selected = elm_items_item_selected_get());
621 if (selected)
622 pd->selected = eina_list_append(pd->selected, item);
623 }
624
625 //check if it is expanded and add the children
626 {
627 Eina_Bool expanded;
628
629 eo_do(item, expanded = elm_items_item_expanded_get());
630 if (expanded)
631 expand(obj, child);
632 }
633}
425 634
426#include "elm_items_display.eo.x" 635#include "elm_items_display.eo.x"
427#include "elm_items_pan.eo.x" \ No newline at end of file 636#include "elm_items_pan.eo.x" \ No newline at end of file
diff --git a/src/lib/items/elm_items_priv.h b/src/lib/items/elm_items_priv.h
index a09aad7..9c03709 100644
--- a/src/lib/items/elm_items_priv.h
+++ b/src/lib/items/elm_items_priv.h
@@ -45,7 +45,9 @@ typedef struct {
45 Efl_Tree_Base *root; //< the root item of the item node 45 Efl_Tree_Base *root; //< the root item of the item node
46 Eina_Strbuf *search; 46 Eina_Strbuf *search;
47 Eina_List *selected; //< list of selected items 47 Eina_List *selected; //< list of selected items
48 Eina_List *realitems; //< the list of really available items
48 Eo *pan; 49 Eo *pan;
50 Ecore_Idler *realitems_idler;
49} Elm_Items_Display_Data; 51} Elm_Items_Display_Data;
50 52
51#endif \ No newline at end of file 53#endif \ No newline at end of file