summaryrefslogtreecommitdiff
path: root/src/genlist.c
blob: b52a4ce015dc0b03dedabe651da8664c8eee65b6 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include "main.h"

#define N_ITEMS 10
#define BUFFER_SIZE 256


char *_gl_item_styles[] =
{
    "default",
    "1icon",
    "1icon/no_padding",
    "groupindex",
    "select_all",
    "groupindex.sub",
    "1line",
    "1line.2",
    "2line.top",
    "2line.top.2",
    "2line.top.3",
    "2line.top.4",
    "2line.bottom",
    "2line.bottom.2",
    "2line.bottom.3",
    "2line.bottom.4",
    "multiline_sub",
    "multiline_main",
    "multiline_sub.main",
    "multiline_sub.main.sub",
    "multiline_sub.sub.main",
    "multiline_main.sub",
    "multiline_sub.main.1icon",
    "multiline_sub.main.1icon.1",
    "multiline_sub.sub.main.1icon",
    "multiline_sub.sub.main.1icon.1",
    NULL
};

static void _item_sel_cb(void *data, Evas_Object *obj, void *event_info)
{
    Evas_Coord x = 0, y = 0, w = 0, h = 0;
    Eina_Bool visible;
    Elm_Object_Item *it = event_info;
    Evas_Object *track = elm_object_item_track(it);
    evas_object_geometry_get(track, &x, &y, &w, &h);

    visible = evas_object_visible_get(track);
    printf("sel item data [%p] on genlist obj [%p], item pointer [%p]\n",
            data, obj, event_info);
    printf("track geometry = (%d %d %d %d) visible(%d)\n",
           x, y, w, h, visible);
    elm_object_item_untrack(it);
}

static void _item_longpressed_cb(void *data, Evas_Object *obj, void *event_info)
{
    printf("item longpressed! %p \n", event_info);
}

static Evas_Object *_item_content_get_default(void *data, Evas_Object *obj, const char *part)
{
    Evas_Object *ic = NULL;

    if (!strcmp(part, "elm.swallow.icon"))
    {
        ic = elm_icon_add(obj);
        elm_icon_standard_set(ic, "clock");
        evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
    }
    else if (!strcmp(part, "elm.swallow.content"))
    {
        ic = elm_icon_add(obj);
        elm_icon_standard_set(ic, "home");
        evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
    }
    else if (!strcmp(part, "elm.swallow.icon.1"))
    {
        ic = elm_icon_add(obj);
        elm_icon_standard_set(ic, "folder");
        evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
    }
    else if (!strcmp(part, "elm.swallow.icon.2"))
    {
        ic = elm_icon_add(obj);
        elm_icon_standard_set(ic, "home");
        evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
    }
    else if (!strcmp(part, "elm.swallow.bottom"))
    {
        ic = elm_progressbar_add(obj);
        evas_object_size_hint_weight_set(ic, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(ic, EVAS_HINT_FILL, 0.5);
    }
    else if (!strcmp(part, "elm.swallow.end"))
    {
        ic = elm_check_add(obj);
        elm_object_focus_allow_set(ic, EINA_FALSE);
        evas_object_size_hint_weight_set(ic, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(ic, EVAS_HINT_FILL, EVAS_HINT_FILL);
        evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
    }
    else
    {
        ic = elm_icon_add(obj);
        elm_icon_standard_set(ic, "home");
        evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
    }

    return ic;
}

static Evas_Object *_item_content_get_progress(void *data, Evas_Object *obj, const char *part)
{
    Evas_Object *ic = NULL;

    if (!strcmp(part, "elm.swallow.icon"))
    {
        ic = elm_progressbar_add(obj);
        elm_progressbar_span_size_set(ic, 200);
        evas_object_size_hint_weight_set(ic, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        elm_object_style_set(ic, "default");
        evas_object_size_hint_align_set(ic, EVAS_HINT_FILL, 0.5);
    }
    else if (!strcmp(part, "elm.swallow.end"))
    {
        ic = elm_check_add(obj);
        elm_object_focus_allow_set(ic, EINA_FALSE);
        evas_object_size_hint_weight_set(ic, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(ic, EVAS_HINT_FILL, EVAS_HINT_FILL);
        evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
    }

    return ic;
}

static char *_item_label_get(void *data, Evas_Object *obj, const char *part)
{
   char buf[BUFFER_SIZE];

   if (!strcmp(part, "elm.text"))
   {
       if ((int) data == 0) sprintf(buf, "%s", "Time Warner Cable(Cable)");
       else if ((int) data == 1) sprintf(buf, "%s", "ComCast (Cable)");
       else if ((int) data == 2) sprintf(buf, "%s", "Dish (Satellite)");
       else if ((int) data == 3) sprintf(buf, "%s", "DirecTV (Satellite)");
       else if ((int) data == 4) sprintf(buf, "%s", "Tata Sky (Satellite)");
       else if ((int) data == 5) sprintf(buf, "%s", "Nextra Cable(Cable)");
       else if ((int) data == 6) sprintf(buf, "%s", "DD Plus (Cable)");
       else if ((int) data == 7) sprintf(buf, "%s", "Tikona Cable(Cable)");
       else if ((int) data == 8) sprintf(buf, "%s", "True Provider (Cable)");
       else if ((int) data == 9) sprintf(buf, "%s", "Vodafone (Satellite)");
       else sprintf(buf, "%s", "Sample Text");
   }
   else if (!strcmp(part, "elm.text2"))
   {
       sprintf(buf, "sub text (%d)", (int) data);
   }
   else if (!strcmp(part, "elm.text3"))
   {
       sprintf(buf, "sub text#2 (%d)", (int) data);
   }
   else if (!strcmp(part, "elm.text4"))
   {
       sprintf(buf, "sub text#3 (%d)", (int) data);
   }
   else
   {
       sprintf(buf, "genlist item text sample (%d)", (int) data);
   }

   return strdup(buf);
}

static void _genlist_renew(Evas_Object *obj, const char *style)
{
    Elm_Genlist_Item_Class *ic;
    int i;

    if (!obj) return;

    elm_genlist_clear(obj);

    ic = elm_genlist_item_class_new();
    ic->item_style = style;
    ic->func.text_get = _item_label_get;
    if (!strcmp(style, "progress"))
        ic->func.content_get = _item_content_get_progress;
    else
        ic->func.content_get = _item_content_get_default;
    ic->func.state_get = NULL;
    ic->func.del = NULL;

    for (i = 0; i < N_ITEMS; i++)
        elm_genlist_item_append(obj, ic, (void *)i, NULL, ELM_GENLIST_ITEM_NONE, _item_sel_cb, NULL);

    elm_genlist_item_class_free(ic);
}

static void
_gl_focus_item_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
   printf("genlist item focused: %s\n", elm_object_item_text_get(event_info));
}

static void
_gl_unfocus_item_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
   printf("genlist item unfocused: %s\n", elm_object_item_text_get(event_info));
}

static void
_gl_focus_key_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
                      Evas_Object *obj EINA_UNUSED, void *event_info)
{
   Evas_Event_Key_Down *ev = event_info;
   printf("\n=== Key Down : %s ===\n", ev->keyname);
}

static void
_gl_it_selected(void *data, Evas_Object *obj, void *event_info)
{
    Evas_Object *gl = data;
    const char *txt = elm_object_item_text_get(event_info);
    elm_object_text_set(obj, txt);

    _genlist_renew(gl, txt);
}

void genlist_del_cb(void *data)
{
    appdata *ad = data;
    evas_object_smart_callback_del(ad->item_hov, "selected", _gl_it_selected);
}

Evas_Object *genlist_cb(void *data)
{
    Evas_Object *wbox, *gl;
    appdata *ad = data;

    wbox = ad->widget_box;

    gl = elm_genlist_add(wbox);
    evas_object_smart_callback_add(ad->item_hov, "selected", _gl_it_selected, gl);

    elm_genlist_select_mode_set(gl, ELM_OBJECT_SELECT_MODE_ALWAYS);
    evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);

    _genlist_renew(gl, "default");
    evas_object_show(gl);

    evas_object_smart_callback_add(gl, "item,focused", _gl_focus_item_cb, "item,focused");
    evas_object_smart_callback_add(gl, "item,unfocused", _gl_unfocus_item_cb, "item,unfocused");
    evas_object_smart_callback_add(gl, "activated", _gl_focus_item_cb, "activated");
    evas_object_event_callback_add(gl, EVAS_CALLBACK_KEY_DOWN, _gl_focus_key_down_cb, NULL);
    evas_object_smart_callback_add(gl, "longpressed", _item_longpressed_cb, NULL);

    elm_box_pack_end(wbox, gl);

    return gl;
}