[JungWooHyun] doing merge job ~
[framework/uifw/elementary.git] / src / examples / slideshow_example.c
1 /**
2  * Simple Elementary's <b>slide show widget</b> example, illustrating its
3  * usage and API.
4  *
5  * See stdout/stderr for output. Compile with:
6  *
7  * @verbatim
8  * gcc -g `pkg-config --cflags --libs elementary` slideshow_example.c -o slideshow_example
9  * @endverbatim
10  */
11
12 #include <Elementary.h>
13 #ifdef HAVE_CONFIG_H
14 # include "elementary_config.h"
15 #else
16 # define __UNUSED__
17 # define PACKAGE_DATA_DIR "../../data"
18 #endif
19
20 static void
21 _on_done(void        *data __UNUSED__,
22          Evas_Object *obj __UNUSED__,
23          void        *event_info __UNUSED__)
24 {
25    elm_exit();
26 }
27
28 static Evas_Object *slideshow, *bt_start, *bt_stop;
29 static Elm_Slideshow_Item_Class itc;
30
31 static const char *img1 = PACKAGE_DATA_DIR "/images/logo.png";
32 static const char *img2 = PACKAGE_DATA_DIR "/images/plant_01.jpg";
33 static const char *img3 = PACKAGE_DATA_DIR "/images/rock_01.jpg";
34 static const char *img4 = PACKAGE_DATA_DIR "/images/rock_02.jpg";
35 static const char *img5 = PACKAGE_DATA_DIR "/images/sky_01.jpg";
36 static const char *img6 = PACKAGE_DATA_DIR "/images/sky_04.jpg";
37 static const char *img7 = PACKAGE_DATA_DIR "/images/wood_01.jpg";
38 static const char *img8 = PACKAGE_DATA_DIR "/images/mystrale.jpg";
39 static const char *img9 = PACKAGE_DATA_DIR "/images/mystrale_2.jpg";
40
41 static void
42 _notify_show(void        *data,
43              Evas        *e __UNUSED__,
44              Evas_Object *obj __UNUSED__,
45              void        *event_info __UNUSED__)
46 {
47    evas_object_show(data);
48 }
49
50 /* jump to next item, cyclically */
51 static void
52 _next(void        *data,
53       Evas_Object *obj __UNUSED__,
54       void        *event_info __UNUSED__)
55 {
56    elm_slideshow_next(data);
57 }
58
59 static void
60 _previous(void        *data,
61           Evas_Object *obj __UNUSED__,
62           void        *event_info __UNUSED__)
63 {
64    elm_slideshow_previous(data);
65 }
66
67 static void
68 _first(void        *data,
69        Evas_Object *obj __UNUSED__,
70        void        *event_info __UNUSED__)
71 {
72 <<<<<<< HEAD
73    elm_slideshow_show(data);
74 =======
75    elm_slideshow_item_show(data);
76 >>>>>>> remotes/origin/upstream
77 }
78
79 static void
80 _last(void        *data,
81       Evas_Object *obj __UNUSED__,
82       void        *event_info __UNUSED__)
83 {
84 <<<<<<< HEAD
85    elm_slideshow_show(data);
86 =======
87    elm_slideshow_item_show(data);
88 >>>>>>> remotes/origin/upstream
89 }
90
91 static void
92 _mouse_in(void        *data,
93           Evas        *e __UNUSED__,
94           Evas_Object *obj __UNUSED__,
95           void        *event_info __UNUSED__)
96 {
97    elm_notify_timeout_set(data, 0.0);
98    evas_object_show(data);
99 }
100
101 static void
102 _mouse_out(void        *data,
103            Evas        *e __UNUSED__,
104            Evas_Object *obj __UNUSED__,
105            void        *event_info __UNUSED__)
106 {
107    elm_notify_timeout_set(data, 3.0);
108 }
109
110 /* transition changed */
111 static void
112 _transition_select(void        *data,
113            Evas_Object *obj,
114            void        *event_info __UNUSED__)
115 {
116    elm_slideshow_transition_set(slideshow, data);
117    elm_object_text_set(obj, data);
118 }
119
120 static void
121 _layout_select(void        *data,
122                Evas_Object *obj,
123                void        *event_info __UNUSED__)
124 {
125    elm_slideshow_layout_set(slideshow, data);
126    elm_object_text_set(obj, data);
127 }
128
129 /* start the show! */
130 static void
131 _start(void        *data,
132        Evas_Object *obj __UNUSED__,
133        void        *event_info __UNUSED__)
134 {
135    elm_slideshow_timeout_set(slideshow, elm_spinner_value_get(data));
136
137    elm_object_disabled_set(bt_start, EINA_TRUE);
138    elm_object_disabled_set(bt_stop, EINA_FALSE);
139 }
140
141 static void
142 _stop(void        *data __UNUSED__,
143       Evas_Object *obj __UNUSED__,
144       void        *event_info __UNUSED__)
145 {
146    elm_slideshow_timeout_set(slideshow, 0.0);
147    elm_object_disabled_set(bt_start, EINA_FALSE);
148    elm_object_disabled_set(bt_stop, EINA_TRUE);
149 }
150
151 /* slideshow transition time has changed */
152 static void
153 _spin(void        *data,
154       Evas_Object *obj __UNUSED__,
155       void        *event_info __UNUSED__)
156 {
157    if (elm_slideshow_timeout_get(slideshow) > 0)
158      elm_slideshow_timeout_set(slideshow, elm_spinner_value_get(data));
159 }
160
161 /* get our images to make slideshow items */
162 static Evas_Object *
163 _get(void        *data,
164      Evas_Object *obj)
165 {
166    Evas_Object *photo = elm_photo_add(obj);
167    elm_photo_file_set(photo, data);
168    elm_photo_fill_inside_set(photo, EINA_TRUE);
169    elm_object_style_set(photo, "shadow");
170
171    return photo;
172 }
173
174 /* ordering alphabetically */
175 static int
176 _cmp_func(const void *data1,
177           const void *data2)
178 {
179    const char *img_path1, *img_path2;
180
181    const Elm_Object_Item *slide_it1 = data1;
182    const Elm_Object_Item *slide_it2 = data2;
183
184    img_path1 = elm_object_item_data_get(slide_it1);
185    img_path2 = elm_object_item_data_get(slide_it2);
186
187    return strcasecmp(img_path1, img_path2);
188 }
189
190 int
191 elm_main(int    argc __UNUSED__,
192          char **argv __UNUSED__)
193 {
194    Evas_Object *win, *bg, *notify, *bx, *bt, *hv, *spin;
195    Elm_Object_Item *slide_first, *slide_last, *slide_it;
196    const char *transition, *layout;
197    const Eina_List *l, *list;
198
199    win = elm_win_add(NULL, "slideshow", ELM_WIN_BASIC);
200    elm_win_title_set(win, "Slideshow example");
201    evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
202
203    bg = elm_bg_add(win);
204    elm_win_resize_object_add(win, bg);
205    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
206    evas_object_show(bg);
207
208    slideshow = elm_slideshow_add(win);
209    elm_slideshow_loop_set(slideshow, EINA_TRUE);
210    elm_win_resize_object_add(win, slideshow);
211    evas_object_size_hint_weight_set(slideshow,
212                                     EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
213    evas_object_show(slideshow);
214
215    itc.func.get = _get;
216    itc.func.del = NULL;
217
218    slide_first = elm_slideshow_item_sorted_insert(slideshow, &itc, img1, _cmp_func);
219    elm_slideshow_item_sorted_insert(slideshow, &itc, img2, _cmp_func);
220    elm_slideshow_item_sorted_insert(slideshow, &itc, img3, _cmp_func);
221    elm_slideshow_item_sorted_insert(slideshow, &itc, img4, _cmp_func);
222    elm_slideshow_item_sorted_insert(slideshow, &itc, img5, _cmp_func);
223    elm_slideshow_item_sorted_insert(slideshow, &itc, img6, _cmp_func);
224    elm_slideshow_item_sorted_insert(slideshow, &itc, img7, _cmp_func);
225    elm_slideshow_item_sorted_insert(slideshow, &itc, img8, _cmp_func);
226    slide_last = elm_slideshow_item_add(slideshow, &itc, img9);
227
228    list = elm_slideshow_items_get(slideshow);
229    fprintf(stdout, "List of items in the slideshow:\n");
230    EINA_LIST_FOREACH(list, l, slide_it)
231      fprintf(stdout, "\t%s\n",
232              (const char *)elm_object_item_data_get(slide_it));
233
234    notify = elm_notify_add(win);
235    elm_notify_orient_set(notify, ELM_NOTIFY_ORIENT_BOTTOM);
236    elm_win_resize_object_add(win, notify);
237    elm_notify_timeout_set(notify, 3.0);
238
239    bx = elm_box_add(win);
240    elm_box_horizontal_set(bx, EINA_TRUE);
241    elm_object_content_set(notify, bx);
242    evas_object_show(bx);
243
244    evas_object_event_callback_add(bx, EVAS_CALLBACK_MOUSE_IN, _mouse_in,
245                                   notify);
246    evas_object_event_callback_add(bx, EVAS_CALLBACK_MOUSE_OUT, _mouse_out,
247                                   notify);
248
249    bt = elm_button_add(win);
250    elm_object_text_set(bt, "Previous");
251    evas_object_smart_callback_add(bt, "clicked", _previous, slideshow);
252    elm_box_pack_end(bx, bt);
253    evas_object_show(bt);
254
255    bt = elm_button_add(win);
256    elm_object_text_set(bt, "Next");
257    evas_object_smart_callback_add(bt, "clicked", _next, slideshow);
258    elm_box_pack_end(bx, bt);
259    evas_object_show(bt);
260
261    bt = elm_button_add(win);
262    elm_object_text_set(bt, "First");
263    evas_object_smart_callback_add(bt, "clicked", _first, slide_first);
264    elm_box_pack_end(bx, bt);
265    evas_object_show(bt);
266
267    bt = elm_button_add(win);
268    elm_object_text_set(bt, "Last");
269    evas_object_smart_callback_add(bt, "clicked", _last, slide_last);
270    elm_box_pack_end(bx, bt);
271    evas_object_show(bt);
272
273    hv = elm_hoversel_add(win);
274    elm_box_pack_end(bx, hv);
275    elm_hoversel_hover_parent_set(hv, win);
276    EINA_LIST_FOREACH(elm_slideshow_transitions_get(slideshow), l, transition)
277      elm_hoversel_item_add(hv, transition, NULL, 0, _transition_select,
278                            transition);
279    elm_object_text_set(hv, eina_list_data_get(
280                          elm_slideshow_transitions_get(slideshow)));
281    evas_object_show(hv);
282
283    hv = elm_hoversel_add(win);
284    elm_box_pack_end(bx, hv);
285    elm_hoversel_hover_parent_set(hv, win);
286    EINA_LIST_FOREACH(elm_slideshow_layouts_get(slideshow), l, layout)
287      elm_hoversel_item_add(hv, layout, NULL, 0, _layout_select, layout);
288    elm_object_text_set(hv, elm_slideshow_layout_get(slideshow));
289    evas_object_show(hv);
290
291    spin = elm_spinner_add(win);
292    elm_spinner_label_format_set(spin, "%2.0f s");
293    evas_object_smart_callback_add(spin, "changed", _spin, spin);
294    elm_spinner_step_set(spin, 1);
295    elm_spinner_min_max_set(spin, 1, 30);
296    elm_spinner_value_set(spin, 3);
297    elm_box_pack_end(bx, spin);
298    evas_object_show(spin);
299
300    bt = elm_button_add(win);
301    bt_start = bt;
302    elm_object_text_set(bt, "Start");
303    evas_object_smart_callback_add(bt, "clicked", _start, spin);
304    elm_box_pack_end(bx, bt);
305    evas_object_show(bt);
306
307    bt = elm_button_add(win);
308    bt_stop = bt;
309    elm_object_text_set(bt, "Stop");
310    evas_object_smart_callback_add(bt, "clicked", _stop, spin);
311    elm_box_pack_end(bx, bt);
312    elm_object_disabled_set(bt, EINA_TRUE);
313    evas_object_show(bt);
314
315    evas_object_event_callback_add(slideshow, EVAS_CALLBACK_MOUSE_UP,
316                                   _notify_show, notify);
317    evas_object_event_callback_add(slideshow, EVAS_CALLBACK_MOUSE_MOVE,
318                                   _notify_show, notify);
319
320    _notify_show(notify, NULL, NULL, NULL);
321
322    evas_object_resize(win, 600, 400);
323    evas_object_show(win);
324
325    elm_run();
326    return 0;
327 }
328
329 ELM_MAIN()