[JungWooHyun] doing merge job ~
[framework/uifw/elementary.git] / src / examples / genlist_example_03.c
1 //Compile with:
2 //gcc -g `pkg-config --cflags --libs elementary` genlist_example_03.c -o genlist_example_03
3
4 #include <Elementary.h>
5 #ifdef HAVE_CONFIG_H
6 # include "elementary_config.h"
7 #else
8 # define __UNUSED__
9 #endif
10
11 #define N_ITEMS 30
12
13 <<<<<<< HEAD
14 static Elm_Genlist_Item_Class _itc;
15
16 static char *
17 _item_text_get(void *data, Evas_Object *obj __UNUSED__, const char *part)
18 =======
19 static Elm_Genlist_Item_Class *_itc = NULL;
20
21 static char *
22 _item_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part)
23 >>>>>>> remotes/origin/upstream
24 {
25    time_t t = (time_t)ecore_time_unix_get();
26    char buf[256];
27    int i = (int)(long)data;
28
29    if (!strcmp(part, "elm.text"))
30      snprintf(buf, sizeof(buf), "Item # %i", i);
31    else
32      {
33         int n;
34         snprintf(buf, sizeof(buf), "created at %s", ctime(&t));
35         n = strlen(buf);
36         buf[n - 1] = '\0';
37      }
38
39    return strdup(buf);
40 }
41
42 static Evas_Object *
43 _item_content_get(void *data __UNUSED__, Evas_Object *obj, const char *part)
44 {
45    Evas_Object *ic = elm_icon_add(obj);
46
47    if (!strcmp(part, "elm.swallow.icon"))
48      elm_icon_standard_set(ic, "clock");
49
50    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
51    return ic;
52 }
53
54 static void
55 _item_sel_cb(void *data, Evas_Object *obj, void *event_info)
56 {
57    printf("sel item data [%p] on genlist obj [%p], item pointer [%p]\n",
58           data, obj, event_info);
59 }
60
61 static Evas_Object *
62 _genlist_add(Evas_Object *box)
63 {
64    Evas_Object *list = elm_genlist_add(elm_object_parent_widget_get(box));
65    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
66    evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
67    evas_object_size_hint_min_set(list, 200, 160);
68    elm_box_pack_end(box, list);
69    evas_object_show(list);
70
71    return list;
72 }
73
74 static void
75 _genlist_fill(Evas_Object *list)
76 {
77    int i;
78
79    for (i = 0; i < N_ITEMS; i++)
80      {
81 <<<<<<< HEAD
82         elm_genlist_item_append(list, &_itc,
83 =======
84         elm_genlist_item_append(list, _itc,
85 >>>>>>> remotes/origin/upstream
86                                 (void *)(long)i, NULL,
87                                 ELM_GENLIST_ITEM_NONE,
88                                 _item_sel_cb, NULL);
89      }
90 }
91
92 int
93 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
94 {
95    Evas_Object *win, *bg, *box;
96    Evas_Object *list;
97
98    win = elm_win_add(NULL, "icon", ELM_WIN_BASIC);
99    elm_win_title_set(win, "Icon");
100    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
101    elm_win_autodel_set(win, EINA_TRUE);
102
103    bg = elm_bg_add(win);
104    elm_bg_color_set(bg, 255,255 ,255);
105    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
106    elm_win_resize_object_add(win, bg);
107    evas_object_show(bg);
108
109    box = elm_box_add(win);
110    elm_box_horizontal_set(box, EINA_TRUE);
111    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
112    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
113    elm_win_resize_object_add(win, box);
114    evas_object_show(box);
115
116 <<<<<<< HEAD
117    _itc.item_style = "double_label";
118    _itc.func.text_get = _item_text_get;
119    _itc.func.content_get = _item_content_get;
120    _itc.func.state_get = NULL;
121    _itc.func.del = NULL;
122
123    list = _genlist_add(box);
124    _genlist_fill(list);
125
126    list = _genlist_add(box);
127    elm_genlist_horizontal_mode_set(list, ELM_LIST_LIMIT);
128    _genlist_fill(list);
129
130    list = _genlist_add(box);
131    elm_genlist_compress_mode_set(list, EINA_TRUE);
132    _genlist_fill(list);
133
134    list = _genlist_add(box);
135    elm_genlist_height_for_width_mode_set(list, EINA_TRUE);
136 =======
137    if (!_itc)
138      {
139         _itc = elm_genlist_item_class_new();
140         _itc->item_style = "double_label";
141         _itc->func.text_get = _item_label_get;
142         _itc->func.content_get = _item_content_get;
143         _itc->func.state_get = NULL;
144         _itc->func.del = NULL;
145      }
146
147    list = _genlist_add(box);
148    _genlist_fill(list);
149
150    list = _genlist_add(box);
151    elm_genlist_mode_set(list, ELM_LIST_LIMIT);
152    _genlist_fill(list);
153
154    list = _genlist_add(box);
155    elm_genlist_mode_set(list, ELM_LIST_COMPRESS);
156 >>>>>>> remotes/origin/upstream
157    _genlist_fill(list);
158
159    evas_object_size_hint_min_set(bg, 800, 160);
160    evas_object_size_hint_max_set(bg, 800, 640);
161    evas_object_resize(win, 800, 320);
162    evas_object_show(win);
163
164    elm_run();
165
166    return 0;
167 }
168
169 ELM_MAIN()