summaryrefslogtreecommitdiff
path: root/src/test/list/list_expand.c
blob: 1ebd3d119f546911b65f81bd2cac2ecf1fb26660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#define EFL_BETA_API_SUPPORT
#define EFL_EO_API_SUPPORT

#include <Efl.h>
#include <Elementary.h>
#include <Elm_Items.h>

static Eina_Bool pause_realize = EINA_TRUE;

static Evas_Object *spinner;
static void
on_done(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   // quit the mainloop (elm_run function will return)
   elm_exit();
}

static Eina_Bool
_realize(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
{
   Eo *btn;
   struct timespec tim;
   btn = elm_label_add(obj);
   elm_object_text_set(btn, "text");

   eo_do(obj, elm_items_item_content_set(btn));

   if (pause_realize)
     {
       tim.tv_sec = 0;
       tim.tv_nsec = 10000000;
       nanosleep(&tim, NULL);
     }

   evas_object_show(btn);

   printf("REALIZE %p\n", obj);

   return EINA_TRUE;
}

static Eina_Bool
_unrealize(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
{
   Eo *content;

   eo_do(obj, content = elm_items_item_content_get();
              elm_items_item_content_set(NULL););
   evas_object_hide(content);

   printf("UNREALIZE %p\n", obj);
   return EINA_TRUE;
}

static void
on_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Eina_List *selected;
   Eo *item, *it, *root;
   int number;

   number = elm_spinner_value_get(spinner);

   eo_do(data, selected = elm_items_display_selected_get());

   eo_do(eina_list_data_get(selected), root = elm_items_item_get());

   if (!root)
     eo_do(data, root = elm_items_display_tree_get());

   eo_do(eina_list_data_get(selected), elm_items_item_expandable_set(ELM_ITEMS_EXPANDABLE_YES));
   eo_do(eina_list_data_get(selected), elm_items_item_expanded_set(EINA_TRUE));

   for(int i = 0; i < number; i++)
     {
        item = eo_add(ELM_ITEMS_ITEM_CLASS, data);
        eo_do(item, eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_REALIZE, _realize, NULL);
                    eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_UNREALIZE, _unrealize, NULL));
        eo_do(item, it = elm_items_item_get());
        eo_do(root, efl_tree_base_append(it, NULL));
        evas_object_show(item);
     }

}

EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
   Evas_Object *win, *list, *bx, *toolbox, *o;

   elm_need_ethumb();
   elm_need_efreet();

   elm_items_init();

   win = elm_win_util_standard_add("efm", "efm - Jesus");
   evas_object_smart_callback_add(win, "delete,request", on_done, NULL);

   bx = elm_box_add(win);
   evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_show(bx);

   list = eo_add(ELM_ITEMS_LIST_CLASS, win);
   evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_show(list);
   elm_box_pack_end(bx, list);

   toolbox = elm_box_add(win);
   elm_box_horizontal_set(toolbox, EINA_TRUE);
   evas_object_size_hint_weight_set(toolbox, EVAS_HINT_EXPAND, 0);
   evas_object_size_hint_align_set(toolbox, EVAS_HINT_FILL, 0);
   evas_object_show(toolbox);
   elm_box_pack_end(bx, toolbox);

   o = elm_check_add(toolbox);
   elm_object_text_set(o, "Long time realize");
   elm_check_state_pointer_set(o, &pause_realize);
   evas_object_show(o);
   elm_box_pack_end(bx, o);

   spinner = o = elm_spinner_add(toolbox);
   elm_spinner_value_set(o, 20);
   elm_spinner_min_max_set(o, 1, 10000);
   elm_spinner_editable_set(o, EINA_TRUE);
   evas_object_show(o);
   elm_box_pack_end(bx, o);

   o = elm_button_add(toolbox);
   elm_object_text_set(o, "Add to selected");
   evas_object_show(o);
   evas_object_smart_callback_add(o, "clicked", on_click, list);
   elm_box_pack_end(bx, o);

   elm_win_resize_object_add(win, bx);
   evas_object_resize(win, 200,200);
   evas_object_show(win);

   elm_run();
   return 0;
}
ELM_MAIN()