summaryrefslogtreecommitdiff
path: root/src/examples/elementary/diskselector_example_02.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-03-23 12:56:14 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-03-23 13:24:41 -0700
commitc2a1c49ab2042f559b28e840e54feb8494888e0e (patch)
treec6eb110b7c479499854eede9d0c3ab0a80c9a11a /src/examples/elementary/diskselector_example_02.c
parent9340855597e7e465435c69b6278650346688da14 (diff)
elementary: move all legacy files to their expected new location.
Diffstat (limited to 'src/examples/elementary/diskselector_example_02.c')
-rw-r--r--src/examples/elementary/diskselector_example_02.c346
1 files changed, 346 insertions, 0 deletions
diff --git a/src/examples/elementary/diskselector_example_02.c b/src/examples/elementary/diskselector_example_02.c
new file mode 100644
index 0000000000..ef1a8f6cda
--- /dev/null
+++ b/src/examples/elementary/diskselector_example_02.c
@@ -0,0 +1,346 @@
1/**
2 * Elementary's <b>diskselector widget</b> example, illustrating its
3 * covering most of item functions.
4 *
5 * See stdout/stderr for output. Compile with:
6 *
7 * @verbatim
8 * gcc -g diskselector_example_02.c -o diskselector_example_02 `pkg-config --cflags --libs elementary`
9 * @endverbatim
10 */
11
12#include <Elementary.h>
13
14static int counter = 3;
15
16static void
17_ds_selected_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
18 void *event_info)
19{
20 Elm_Object_Item *it = event_info;
21 printf("Selected Item %s\n", elm_object_item_text_get(it));
22}
23
24static void
25_add_cb(void *data, Evas_Object *obj, void *event_info)
26{
27 Elm_Object_Item *ds_it;
28 Evas_Object *ds = data;
29 char label[32];
30
31 snprintf(label, sizeof(label), "Item %i", counter++);
32 ds_it = elm_diskselector_item_append(ds, label, NULL, NULL, NULL);
33 if (!ds_it) printf("Error adding item\n");
34}
35
36static void
37_add_ic_cb(void *data, Evas_Object *obj, void *event_info)
38{
39 Elm_Object_Item *ds_it;
40 Evas_Object *ic, *ds = data;
41 char label[32];
42
43 snprintf(label, sizeof(label), "Item %i", counter++);
44 ic = elm_icon_add(ds);
45 elm_icon_standard_set(ic, "home");
46
47 ds_it = elm_diskselector_item_append(ds, label, ic, NULL, NULL);
48 if (!ds_it) printf("Error adding item with icon\n");
49}
50
51static void
52_sel_cb(void *data, Evas_Object *obj, void *event_info)
53{
54 Elm_Object_Item *ds_it = event_info;
55 printf("Selected label: %s\n", elm_object_item_text_get(ds_it));
56}
57
58static void
59_add_func_cb(void *data, Evas_Object *obj, void *event_info)
60{
61 Elm_Object_Item *ds_it;
62 Evas_Object *ds = data;
63 char label[32];
64
65 snprintf(label, sizeof(label), "Item %i", counter++);
66 ds_it = elm_diskselector_item_append(ds, label, NULL, _sel_cb, NULL);
67 if (!ds_it) printf("Error adding item\n");
68}
69
70static void
71_sel_data_cb(void *data, Evas_Object *obj, void *event_info)
72{
73 char *content = data;
74 Elm_Object_Item *ds_it = event_info;
75 printf("Selected label: %s with data: %s\n",
76 elm_object_item_text_get(ds_it), content);
77}
78
79static void
80_free_data(void *data, Evas_Object *obj, void *event_info)
81{
82 free(data);
83}
84
85static void
86_add_data_cb(void *data, Evas_Object *obj, void *event_info)
87{
88 Elm_Object_Item *ds_it;
89 Evas_Object *ds = data;
90 char label[32];
91 char *content = malloc(sizeof(char) * 32);
92
93 snprintf(content, 32, "Item content %i", counter);
94 snprintf(label, sizeof(label), "Item %i", counter++);
95 ds_it = elm_diskselector_item_append(ds, label, NULL, _sel_data_cb, content);
96 if (!ds_it)
97 {
98 printf("Error adding item\n");
99 return;
100 }
101 elm_object_item_del_cb_set(ds_it, _free_data);
102}
103
104static void
105_del_cb(void *data, Evas_Object *obj, void *event_info)
106{
107 Elm_Object_Item *selected_ds_it;
108 Evas_Object *ds = data;
109
110 selected_ds_it = elm_diskselector_selected_item_get(ds);
111 elm_object_item_del(selected_ds_it);
112}
113
114static void
115_unselect_cb(void *data, Evas_Object *obj, void *event_info)
116{
117 Elm_Object_Item *selected_ds_it;
118 Evas_Object *ds = data;
119
120 selected_ds_it = elm_diskselector_selected_item_get(ds);
121 elm_diskselector_item_selected_set(selected_ds_it, EINA_FALSE);
122}
123
124static void
125_print_cb(void *data, Evas_Object *obj, void *event_info)
126{
127 const Eina_List *l, *items;
128 Elm_Object_Item *ds_it;
129 Evas_Object *ds = data;
130
131 items = elm_diskselector_items_get(ds);
132 EINA_LIST_FOREACH(items, l, ds_it)
133 printf("%s\n", elm_object_item_text_get(ds_it));
134}
135
136static void
137_clear_cb(void *data, Evas_Object *obj, void *event_info)
138{
139 Evas_Object *ds = data;
140 elm_diskselector_clear(ds);
141}
142
143static void
144_select_first_cb(void *data, Evas_Object *obj, void *event_info)
145{
146 Elm_Object_Item *first_ds_it;
147 Evas_Object *ds = data;
148
149 first_ds_it = elm_diskselector_first_item_get(ds);
150 if (first_ds_it)
151 elm_diskselector_item_selected_set(first_ds_it, EINA_TRUE);
152}
153
154static void
155_select_last_cb(void *data, Evas_Object *obj, void *event_info)
156{
157 Elm_Object_Item *last_ds_it;
158 Evas_Object *ds = data;
159
160 last_ds_it = elm_diskselector_last_item_get(ds);
161 if (last_ds_it)
162 elm_diskselector_item_selected_set(last_ds_it, EINA_TRUE);
163}
164
165static void
166_select_next_cb(void *data, Evas_Object *obj, void *event_info)
167{
168 Elm_Object_Item *selected_ds_it, *next_ds_it;
169 Evas_Object *ds = data;
170
171 selected_ds_it = elm_diskselector_selected_item_get(ds);
172 if (!selected_ds_it) return;
173
174 next_ds_it = elm_diskselector_item_next_get(selected_ds_it);
175 if (next_ds_it)
176 elm_diskselector_item_selected_set(next_ds_it, EINA_TRUE);
177}
178
179static void
180_select_prev_cb(void *data, Evas_Object *obj, void *event_info)
181{
182 Elm_Object_Item *selected_ds_it, *prev_ds_it;
183 Evas_Object *ds = data;
184
185 selected_ds_it = elm_diskselector_selected_item_get(ds);
186 if (!selected_ds_it) return;
187
188 prev_ds_it = elm_diskselector_item_prev_get(selected_ds_it);
189 if (prev_ds_it)
190 elm_diskselector_item_selected_set(prev_ds_it, EINA_TRUE);
191}
192
193EAPI_MAIN int
194elm_main(int argc, char **argv)
195{
196 Evas_Object *win, *bx, *hbx, *ds, *bt;
197
198 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
199
200 win = elm_win_util_standard_add("diskselector", "Diskselector Items Example");
201 elm_win_autodel_set(win, EINA_TRUE);
202
203 bx = elm_box_add(win);
204 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
205 elm_win_resize_object_add(win, bx);
206 evas_object_show(bx);
207
208 ds = elm_diskselector_add(win);
209 evas_object_size_hint_weight_set(ds, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
210 evas_object_size_hint_align_set(ds, EVAS_HINT_FILL, EVAS_HINT_FILL);
211 evas_object_smart_callback_add(ds, "selected", _ds_selected_cb, NULL);
212 elm_box_pack_end(bx, ds);
213 evas_object_show(ds);
214
215 elm_diskselector_item_append(ds, "Item 0", NULL, NULL, NULL);
216 elm_diskselector_item_append(ds, "Item 1", NULL, NULL, NULL);
217 elm_diskselector_item_append(ds, "Item 2", NULL, NULL, NULL);
218
219 hbx = elm_box_add(win);
220 elm_box_horizontal_set(hbx, EINA_TRUE);
221 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
222 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
223 elm_box_pack_end(bx, hbx);
224 evas_object_show(hbx);
225
226 bt = elm_button_add(win);
227 elm_object_text_set(bt, "Append item");
228 evas_object_smart_callback_add(bt, "clicked", _add_cb, ds);
229 elm_box_pack_end(hbx, bt);
230 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
231 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
232 evas_object_show(bt);
233
234 bt = elm_button_add(win);
235 elm_object_text_set(bt, "Append with icon");
236 evas_object_smart_callback_add(bt, "clicked", _add_ic_cb, ds);
237 elm_box_pack_end(hbx, bt);
238 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
239 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
240 evas_object_show(bt);
241
242 bt = elm_button_add(win);
243 elm_object_text_set(bt, "Append with selected function");
244 evas_object_smart_callback_add(bt, "clicked", _add_func_cb, ds);
245 elm_box_pack_end(hbx, bt);
246 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
247 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
248 evas_object_show(bt);
249
250 bt = elm_button_add(win);
251 elm_object_text_set(bt, "Append with data");
252 evas_object_smart_callback_add(bt, "clicked", _add_data_cb, ds);
253 elm_box_pack_end(hbx, bt);
254 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
255 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
256 evas_object_show(bt);
257
258 hbx = elm_box_add(win);
259 elm_box_horizontal_set(hbx, EINA_TRUE);
260 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
261 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
262 elm_box_pack_end(bx, hbx);
263 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
264 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
265 evas_object_show(hbx);
266
267 bt = elm_button_add(win);
268 elm_object_text_set(bt, "Delete item");
269 evas_object_smart_callback_add(bt, "clicked", _del_cb, ds);
270 elm_box_pack_end(hbx, bt);
271 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
272 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
273 evas_object_show(bt);
274
275 bt = elm_button_add(win);
276 elm_object_text_set(bt, "Unselect item");
277 evas_object_smart_callback_add(bt, "clicked", _unselect_cb, ds);
278 elm_box_pack_end(hbx, bt);
279 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
280 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
281 evas_object_show(bt);
282
283 bt = elm_button_add(win);
284 elm_object_text_set(bt, "Print items");
285 evas_object_smart_callback_add(bt, "clicked", _print_cb, ds);
286 elm_box_pack_end(hbx, bt);
287 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
288 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
289 evas_object_show(bt);
290
291 bt = elm_button_add(win);
292 elm_object_text_set(bt, "Clear");
293 evas_object_smart_callback_add(bt, "clicked", _clear_cb, ds);
294 elm_box_pack_end(hbx, bt);
295 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
296 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
297 evas_object_show(bt);
298
299 hbx = elm_box_add(win);
300 elm_box_horizontal_set(hbx, EINA_TRUE);
301 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
302 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
303 elm_box_pack_end(bx, hbx);
304 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
305 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
306 evas_object_show(hbx);
307
308 bt = elm_button_add(win);
309 elm_object_text_set(bt, "Select first item");
310 evas_object_smart_callback_add(bt, "clicked", _select_first_cb, ds);
311 elm_box_pack_end(hbx, bt);
312 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
313 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
314 evas_object_show(bt);
315
316 bt = elm_button_add(win);
317 elm_object_text_set(bt, "Select last item");
318 evas_object_smart_callback_add(bt, "clicked", _select_last_cb, ds);
319 elm_box_pack_end(hbx, bt);
320 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
321 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
322 evas_object_show(bt);
323
324 bt = elm_button_add(win);
325 elm_object_text_set(bt, "Select next item");
326 evas_object_smart_callback_add(bt, "clicked", _select_next_cb, ds);
327 elm_box_pack_end(hbx, bt);
328 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
329 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
330 evas_object_show(bt);
331
332 bt = elm_button_add(win);
333 elm_object_text_set(bt, "Select previous item");
334 evas_object_smart_callback_add(bt, "clicked", _select_prev_cb, ds);
335 elm_box_pack_end(hbx, bt);
336 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
337 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
338 evas_object_show(bt);
339
340 evas_object_show(win);
341
342 elm_run();
343
344 return 0;
345}
346ELM_MAIN()