Fix error in view.c
[apps/native/sample/sample-core-components.git] / view.c
1 /*
2  * @brief: Make a essential object for the this app, like window, conformant and layout
3  * @param[ad]: The object has informations for managing this app
4  */
5 void view_create(appdata_s *ad)
6 {
7         if (ad == NULL) {
8                 dlog_print(DLOG_ERROR, LOG_TAG, "appdata is NULL.");
9                 return;
10         }
11
12         /* Create window */
13         ad->win = view_create_win();
14         if (ad->win == NULL) {
15                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a window.");
16                 return;
17         }
18
19         /* Create conformant */
20         ad->conform = view_create_conformant_without_indicator(ad->win);
21         if (ad->conform == NULL) {
22                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a conformant");
23                 return;
24         }
25
26         /* Show window after main view is set up */
27         evas_object_show(ad->win);
28 }
29
30 /*
31  * @brief: Make a basic window named package
32  * @param[package]: Name of the window
33  */
34 Evas_Object *view_create_win(const char *pkg_name)
35 {
36         Evas_Object *win = NULL;
37
38         /* Window */
39         /* Create and initialize elm_win.
40            elm_win is mandatory to manipulate window. */
41
42         win = elm_win_util_standard_add(pkg_name, pkg_name);
43         elm_win_conformant_set(win, EINA_TRUE);
44         elm_win_autodel_set(win, EINA_TRUE);
45
46         if (elm_win_wm_rotation_supported_get(win)) {
47                 int rots[4] = { 0, 90, 180, 270 };
48                 elm_win_wm_rotation_available_rotations_set(win, (const int *)(&rots), 4);
49         }
50
51         evas_object_smart_callback_add(win, "delete,request", _win_delete_request_cb, NULL);
52
53         return win;
54 }
55
56 /*
57  * @brief: Make a conformant without indicator for wearable app
58  * @param[win]: The object to which you want to set this conformant
59  * Confromant is mandatory for base GUI to have proper size
60  */
61 Evas_Object *view_create_conformant_without_indicator(Evas_Object *win)
62 {
63         /* Conformant
64          * Create and initialize elm_conformant.
65          * elm_conformant is mandatory for base GUI to have proper size
66          * when indicator or virtual keypad is visible.
67          */
68         Evas_Object *conform = NULL;
69
70         if (win == NULL) {
71                 dlog_print(DLOG_ERROR, LOG_TAG, "window is NULL.");
72                 return NULL;
73         }
74
75         conform = elm_conformant_add(win);
76         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
77         elm_win_resize_object_add(win, conform);
78
79         evas_object_show(conform);
80
81         return conform;
82 }
83
84 /*
85  * @brief: Make a layout to target parent object with edje file
86  * @param[parent]: The object to which you want to add this layout
87  * @param[file_name]: File path of EDJ
88  * @param[group_name]: Name of group in EDJ you want to set to
89  * @param[Evas_Object_Event_Cb]: File path of EDJ
90  * @param[user_data]: The user data to be passed to the callback functions
91  */
92 Evas_Object *view_create_layout(Evas_Object *parent, const char *edj_path, const char *group_name, Eext_Event_Cb cb_function, void *user_data)
93 {
94         Evas_Object *layout = NULL;
95
96         if (parent == NULL) {
97                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
98                 return NULL;
99         }
100
101         /* Create layout by EDC(edje file) */
102         layout = elm_layout_add(parent);
103         elm_layout_file_set(layout, edj_path, group_name);
104
105         /* Layout size setting */
106         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
107
108         if(cb_function)
109                 eext_object_event_callback_add(layout, EEXT_CALLBACK_BACK, cb_function, user_data);
110
111         evas_object_show(layout);
112
113         return layout;
114 }
115
116 /*
117  * @brief: Make and set a layout to conformant
118  * @param[parent]: Target conformant object
119  * @param[file_name]: File path of EDJ used
120  * @param[group_name]: Group name in EDJ you want to set to layout
121  * @param[user_data]: The user data to be passed to the callback functions
122  */
123 Evas_Object *view_create_layout_for_conformant(Evas_Object *parent, Evas_Object *conformant, const char *file_name, const char *group_name, void *user_data)
124 {
125         Evas_Object *layout = NULL;
126
127         if (parent == NULL) {
128                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
129                 return NULL;
130         }
131
132         /* Create layout for conformant */
133         layout = view_create_layout(parent, file_name, group_name, NULL, user_data);
134         if (layout == NULL) {
135                 dlog_print(DLOG_ERROR, LOG_TAG, "layout is NULL.");
136                 return NULL;
137         }
138
139         elm_object_content_set(conformant, layout);
140
141         return layout;
142 }
143
144 /*
145  * @brief: Make a layout with theme.
146  * @param[parent]: Object to which you want to add this layout
147  * @param[class]: The class of the group
148  * @param[group_name]: Group name in EDJ you want to set to layout
149  * @param[style]: The style to use
150  */
151 Evas_Object *view_create_layout_by_theme(Evas_Object *parent, const char *classname, const char *group, const char *style)
152 {
153         /*
154          * Layout
155          * Create and initialize elm_layout.
156          * view_create_layout_by_theme() is used to create layout by using premade edje file.
157          */
158         Evas_Object *layout = NULL;
159
160         if (parent == NULL) {
161                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
162                 return NULL;
163         }
164
165         layout = elm_layout_add(parent);
166         elm_layout_theme_set(layout, classname, group, style);
167         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
168
169         evas_object_show(layout);
170
171         return layout;
172 }
173
174 /*
175  * @brief: Make and set a layout to the part
176  * @param[parent]: Object to which you want to set this layout
177  * @param[file_name]: File path of EDJ used
178  * @param[group_name]: Group name in EDJ you want to set to layout
179  * @param[part]: Part name to which you want to set this layout
180  */
181 Evas_Object *view_create_layout_for_part(Evas_Object *parent, char *part, char *file_name, char *group_name)
182 {
183         Evas_Object *layout = NULL;
184
185         if (parent == NULL) {
186                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
187                 return NULL;
188         }
189
190         layout = elm_layout_add(parent);
191         elm_layout_file_set(layout, file_name, group_name);
192         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
193
194         evas_object_show(layout);
195
196         elm_object_part_content_set(parent, part, layout);
197
198         return layout;
199 }
200
201 /*
202  * @brief: Destroy window and free important data to finish this app
203  * @param[ad]: The object has informations for managing this app
204  */
205 void view_destroy(void *user_data)
206 {
207         appdata_s *ad = NULL;
208
209         ad = user_data;
210         if (ad == NULL) {
211                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to destroy data.");
212                 return;
213         }
214
215         evas_object_del(ad->win);
216 }
217
218 /*
219  * @brief: Destroy given layout
220  * @param[layout]: The layout you want to destroy
221  */
222 void view_destroy_layout(Evas_Object *layout)
223 {
224         evas_object_del(layout);
225 }
226
227 /*
228  * @brief: Set image to given part
229  * @param[parent]: object has part to which you want to set this image
230  * @param[part]: part name to which you want to set this image
231  * @param[image_path]: path of image file
232  */
233 void view_set_image(Evas_Object *parent, const char *part, const char *image_path)
234 {
235         Evas_Object *image = NULL;
236
237         if (parent == NULL) {
238                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
239                 return;
240         }
241
242         image = elm_object_part_content_get(parent, part);
243         if (image == NULL) {
244                 image = elm_image_add(parent);
245                 if (!image) {
246                         dlog_print(DLOG_ERROR, LOG_TAG, "failed to create an image object.");
247                         return;
248                 }
249         }
250
251         if (EINA_FALSE == elm_image_file_set(image, image_path, NULL)) {
252                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to set image.");
253                 return;
254         }
255
256         if (part) {
257                 elm_object_part_content_set(parent, part, image);
258         } else {
259                 elm_object_content_set(parent, image);
260         }
261
262         evas_object_show(image);
263
264         return;
265 }
266
267 /*
268  * @brief: Set text to the part
269  * @param[parent]: Object has part to which you want to set text
270  * @param[part]: Part name to which you want to set text
271  * @param[text]: text you want to set to the part
272  */
273 void view_set_text(Evas_Object *parent, const char *part, const char *text)
274 {
275         if (parent == NULL) {
276                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
277                 return;
278         }
279
280         /* Set text of target part object */
281         elm_object_part_text_set(parent, part, text);
282 }
283
284 /*
285  * @brief: Set color of the part
286  * @param[parent]: Object has part to which you want to set color
287  * @param[part]: Name of part to which you want to set color
288  * @param[r]: R of RGBA you want to set to the part
289  * @param[g]: G of RGBA you want to set to the part
290  * @param[b]: B of RGBA you want to set to the part
291  * @param[a]: A of RGBA you want to set to the part
292  */
293 void view_set_color(Evas_Object *parent, const char *part, int r, int g, int b, int a)
294 {
295         Evas_Object *obj = NULL;
296
297         if (parent == NULL) {
298                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
299                 return;
300         }
301
302         obj = elm_object_part_content_get(parent, part);
303         if (obj == NULL) {
304                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get parent.");
305                 return;
306         }
307
308         /* Set color of target part object */
309         evas_object_color_set(obj, r, g, b, a);
310 }
311
312 /*
313  * @brief: Make a naviframe and set to parent
314  * @param[parent]: Object to which you want to set naviframe
315  * @Add callback function will be operated when back key is pressed
316  */
317 Evas_Object *view_create_naviframe(Evas_Object *parent)
318 {
319         /* Naviframe
320          * Create and initialize elm_naviframe.
321          * Naviframe stands for navigation frame.
322          * elm_naviframe is a views manager for applications.
323          */
324         Evas_Object *nf = NULL;
325
326         if (parent == NULL) {
327                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
328                 return NULL;
329         }
330
331         nf = elm_naviframe_add(parent);
332
333         elm_object_part_content_set(parent, "elm.swallow.content", nf);
334         eext_object_event_callback_add(nf, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
335         eext_object_event_callback_add(nf, EEXT_CALLBACK_MORE, eext_naviframe_more_cb, NULL);
336
337         evas_object_show(nf);
338
339         return nf;
340 }
341
342 //TO DO UPDATE
343 /*
344  * @brief: Push item to naviframe
345  * @param[nf]: naviframe
346  * @param[item]: object will be added to naviframe
347  * @param[_pop_cb]: function will be operated when this item is poped from naviframe
348  * @param[cb_data]: data needed to operate '_pop_cb' function
349  * Naviframe make changing of view is easy and effectively
350  */
351 Elm_Object_Item* view_push_item_to_naviframe(Evas_Object *nf, Evas_Object *item, Elm_Naviframe_Item_Pop_Cb _pop_cb, void *cb_data)
352 {
353         Elm_Object_Item* nf_it = NULL;
354
355         if (nf == NULL) {
356                 dlog_print(DLOG_ERROR, LOG_TAG, "naviframe is NULL.");
357                 return NULL;
358         }
359
360         if (item == NULL) {
361                 dlog_print(DLOG_ERROR, LOG_TAG, "item is NULL.");
362                 return NULL;
363         }
364
365         nf_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, item, "empty");
366
367         if (_pop_cb != NULL)
368                 elm_naviframe_item_pop_cb_set(nf_it, _pop_cb, cb_data);
369
370         return nf_it;
371 }
372
373
374 void view_set_more_button(Evas_Object *parent, const char *part)
375 {
376         Evas_Object *more_btn = NULL;
377
378         if (pirent == NULL) {
379                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
380                 return;
381         }
382
383         more_btn = eext_more_option_add(parent);
384         if (more_btn == NULL) {
385                 dlog_print(DLOG_ERROR, LOG_TAG, "more option is NULL.");
386                 return;
387         }
388
389         /* Add smart callback */
390         evas_object_smart_callback_add(more_btn, "more,option,opened", _more_option_opened, NULL);
391         evas_object_smart_callback_add(more_btn, "more,option,closed", _more_option_closed, NULL);
392         evas_object_smart_callback_add(more_btn, "item,selected", _item_selected, NULL);
393
394         elm_object_part_content_set(parent, part, more_btn);
395 }
396
397 /*
398  * @brief: Make and set button.
399  * @param[parent]: object to which you want to set the button
400  * @param[style]: style of the button
401  * @param[text]: text will be written on the button
402  * @param[image_path]: path of image file will be used as button icon
403  * @param[part]: part name in EDJ to which you want to set the button
404  * @param[down_cb]: function will be operated when the button is pressed
405  * @param[up_cb]: function will be operated when the button is released
406  * @param[clicked_cb]: function will be operated when the button is clicked
407  * @param[data]: data needed in this function
408  */
409 void view_set_button(Evas_Object *parent, const char *part, const char *style, const char *image_path, const char *text,
410                 Evas_Object_Event_Cb down_cb, Evas_Object_Event_Cb up_cb, Evas_Smart_Cb clicked_cb, void *data)
411 {
412         Evas_Object *btn = NULL;
413
414         if (parent == NULL) {
415                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
416                 return;
417         }
418
419         btn = elm_button_add(parent);
420         if(!btn) {
421                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to create button.");
422                 return;
423         }
424
425         if (style)
426                 elm_object_style_set(btn, style);
427
428         evas_object_size_hint_weight_set(btn ,EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
429         elm_object_part_content_set(parent, part, btn);
430
431         if (text)
432                 elm_object_text_set(btn, text);
433
434         if (image_path)
435                 view_set_image(btn, NULL, image_path);
436
437         if (down_cb)
438                 evas_object_event_callback_add(btn , EVAS_CALLBACK_MOUSE_DOWN, down_cb, parent);
439         if (up_cb)
440                 evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_UP, up_cb, parent);
441         if (clicked_cb)
442                 evas_object_smart_callback_add(btn, "clicked", clicked_cb, data);
443
444         evas_object_show(btn);
445 }
446
447 /*
448  * @brief: Add a more button item
449  * @param[parent]: object that contains more button
450  * @param[main_txt]: text will be written in the middle of the selector
451  * @param[sub_txt] Text will be written under the main_txt
452  * @param[img_path]: path of image file will be used as more button item icon
453  * @param[clicked_cb]: function will be operated when the more button item is clicked
454  * @param[user_data]: data needed in this function
455  */
456 void view_add_more_button_item(Evas_Object *parent, const char *part, const char *main_txt, const char *sub_txt, const char *img_path, Evas_Smart_Cb clicked_cb, void *user_data)
457 {
458         Evas_Object *img = NULL;
459         Evas_Object *more_btn = NULL;
460         char full_path[PATH_MAX] = { 0, };
461
462         if (parent == NULL) {
463                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
464                 return;
465         }
466
467         more_btn = elm_object_part_content_get(parent, part);
468         if (more_btn == NULL) {
469                 return;
470         }
471
472         /* Create the new item */
473         Eext_Object_Item *item  = eext_more_option_item_append(more_btn);
474
475         /* Set the text in item text part */
476         eext_more_option_item_part_text_set(item, "selector,main_text", main_txt);
477         eext_more_option_item_part_text_set(item, "selector,sub_text", sub_txt);
478
479         img = elm_image_add(more_btn);
480         _get_resource(img_path, full_path, sizeof(full_path));
481         elm_image_file_set(img, full_path, NULL);
482
483         /* Set the content in item content part */
484         eext_more_option_item_part_content_set(item, "item,icon", img);
485
486         evas_object_smart_callback_add(more_btn, "item,clicked", clicked_cb, user_data);
487 }
488
489 /*
490  * @brief: Make a Entry Object to target window
491  * @param[parent]: Object to which you want to set Entry
492  * @param[part]: Part of the layout which you want to locate Entry
493  * @param[data]: The user data to be passed to the callback function
494  * @Add callback function will be operated when mouse clicked event is triggered
495  */
496 Evas_Object *view_set_entry(Evas_Object *parent, const char *part, void (_clicked_cb)(void *data, Evas_Object *obj, void *event_info), void *data)
497 {
498         Evas_Object *entry = NULL;
499
500         if (parent == NULL) {
501                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
502                 return NULL;
503         }
504
505         /* Add Entry object to parent */
506         entry = elm_entry_add(parent);
507         if (entry == NULL) {
508                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to add a entry");
509                 return NULL;
510         }
511
512         /* Set Entry size option */
513         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
514
515         /* Set Entry option for display and functionalities */
516         elm_entry_single_line_set(entry, EINA_TRUE);
517         elm_entry_scrollable_set(entry, EINA_TRUE);
518         elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
519         elm_entry_editable_set(entry, EINA_FALSE);
520         elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
521         elm_entry_cursor_handler_disabled_set(entry, EINA_TRUE);
522         elm_entry_select_allow_set(entry, EINA_FALSE);
523
524         /* Set Entry text style using predefined style description */
525     elm_entry_text_style_user_push(entry, DIAL_TEXT_STYLE_NORMAL);
526
527     elm_object_part_content_set(parent, part, entry);
528
529         /* Set callback for event about Entry */
530     if (_clicked_cb) {
531                 evas_object_smart_callback_add(entry, "clicked", _clicked_cb, data);
532         }
533
534         return entry;
535 }
536
537 /*
538  * @brief: make genlist for circular shape.
539  * @param[parent]: object to which you want to set genlist
540  * @param[circle_surface]: object render a connected circle object
541  */
542 Evas_Object *view_create_circle_genlist(Evas_Object *parent, Eext_Circle_Surface *circle_surface)
543 {
544         Evas_Object *genlist = NULL;
545         Evas_Object *circle_genlist = NULL;
546
547         if (parent == NULL) {
548                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
549                 return NULL;
550         }
551
552         if (circle_surface == NULL) {
553                 dlog_print(DLOG_ERROR, LOG_TAG, "circle surface is NULL.");
554                 return NULL;
555         }
556
557         genlist = elm_genlist_add(parent);
558     /* this make selected list item is shown compressed */
559         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
560         evas_object_smart_callback_add(genlist, "selected", _gl_selected_cb, NULL);
561
562         /* this make genlist style circular */
563         circle_genlist = eext_circle_object_genlist_add(genlist, circle_surface);
564         eext_circle_object_genlist_scroller_policy_set(circle_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
565         eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE);
566
567         evas_object_show(genlist);
568
569         return genlist;
570 }
571
572 /*
573  * @brief: Add item to genlist.
574  * @param[genlist]: genlist
575  * @param[style]: style of item determine how to show this item, such as "1text", "1text1icon" and so on
576  * @param[data]: item data that use item's callback function
577  * @param[_clicked_cb]: function will be operated when the item is clicked
578  * @param[cb_data]: data needed in '_clicked_cb' function
579  * This make item's class and add item to genlist.
580  */
581 Elm_Object_Item *view_append_item_to_genlist(Evas_Object *genlist, const char *style,
582                 const void *data, Evas_Smart_Cb _clicked_cb, const void *cb_data)
583 {
584         Elm_Genlist_Item_Class *item_class;
585         Elm_Object_Item *item;
586
587         if (genlist == NULL) {
588                 dlog_print(DLOG_ERROR, LOG_TAG, "genlist is NULL.");
589                 return NULL;
590         }
591
592         if (style == NULL) {
593                 dlog_print(DLOG_ERROR, LOG_TAG, "item style is NULL.");
594                 return NULL;
595         }
596
597         item_class = _set_genlist_item_class(style);
598
599         item = elm_genlist_item_append(genlist, item_class, data, NULL, ELM_GENLIST_ITEM_NONE, _clicked_cb, cb_data);
600
601         elm_genlist_item_class_free(item_class);
602
603         return item;
604 }
605
606 /*
607  * @brief: Find item from genlist.
608  * @param[genlist]: genlist
609  * @param[val]: value determine which of the itmes has to remove
610  */
611 Elm_Object_Item *view_find_item_from_genlist(Evas_Object *genlist, const char *val)
612 {
613         int item_count;
614         int i;
615         Elm_Object_Item *item = NULL;
616         struct genlist_data *gendata = NULL;
617
618         if (!genlist) {
619                 dlog_print(DLOG_ERROR, LOG_TAG, "genlist is NULL.");
620                 return NULL;
621         }
622
623         item_count = elm_genlist_items_count(genlist);
624
625         /*
626          * The fist item and the last item are "padding".
627          */
628         for(i = 1; i < item_count-1; i++) {
629                 item = elm_genlist_nth_item_get(genlist, i);
630                 gendata = elm_object_item_data_get(item);
631
632                 if (gendata->alarm_id == atoi(val)) {
633                         return item;
634                 }
635         }
636
637         return NULL;
638 }
639
640
641 /*
642  * @brief: Remove item.
643  * @param[item]: item from genlist
644  */
645 void view_delete_item(Elm_Object_Item *item)
646 {
647         elm_object_item_del(item);
648 }
649
650 /*
651  * @brief: Make popup with theme.
652  * @param[popup_style]: style of the popup's layout
653  * @param[data]: data needed in this function
654  */
655 void view_create_text_popup(Evas_Object *parent, double timeout, const char *text)
656 {
657         Evas_Object *popup = NULL;
658         Evas_Object *popup_layout = NULL;
659
660         if (parent == NULL) {
661                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
662                 return;
663         }
664
665         popup = elm_popup_add(parent);
666         elm_object_style_set(popup, "circle");
667         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
668
669         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _popup_hide_cb, NULL);
670         /*
671          * Delete popup object in _popup_hide_finished_cb(), when the "dismissed" signal will be called.
672          */
673         evas_object_smart_callback_add(popup, "dismissed", _popup_hide_finished_cb, NULL);
674
675         popup_layout = elm_layout_add(popup);
676         elm_layout_theme_set(popup_layout, "layout", "popup", "content/circle");
677
678         elm_object_content_set(popup, popup_layout);
679
680         elm_popup_timeout_set(popup, timeout);
681
682         if (text)
683                 view_set_text(popup_layout, "elm.text", text);
684
685         evas_object_show(popup);
686 }
687
688 void view_set_content_to_part(Evas_Object *layout, const char *part, Evas_Object *content)
689 {
690         elm_object_part_content_set(layout, part, content);
691 }
692
693 void view_send_signal_to_edje(Evas_Object *layout, const char *signal, const char *source)
694 {
695         elm_object_signal_emit(layout, signal, source);
696 }
697
698 void view_set_customized_event_callback(Evas_Object *item, char *signal, char *source, void (*signal_cb)(void *data, Evas_Object *obj, const char *emission, const char *source), void *user_data)
699 {
700         elm_object_signal_callback_add(item, signal, source, signal_cb, user_data);
701 }
702
703 /*
704  * @brief: Register roatry event callback function.
705  * @param[obj]: object that will receive rotary event
706  * @param[rotary_cb]: function will be operated when rotary event happens
707  * @param[user_data]: data needed in this function
708  */
709 void view_set_rotary_event_callback(Evas_Object *obj, Eext_Rotary_Event_Cb rotary_cb, void *user_data)
710 {
711         if (obj == NULL) {
712                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
713                 return;
714         }
715
716         eext_rotary_object_event_activated_set(obj, EINA_TRUE);
717         eext_rotary_object_event_callback_add(obj, rotary_cb, user_data);
718 }
719
720 /*
721  * @brief: Make a label and set label options.
722  * @param[parent]: The object to which you want to add this label
723  */
724 Evas_Object *view_create_label(Evas_Object *parent)
725 {
726         Evas_Object *label = elm_label_add(parent);
727
728         if (parent == NULL) {
729                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
730                 return NULL;
731         }
732
733         elm_object_style_set(label, "slide_short");
734         elm_label_wrap_width_set(label, 230);
735         elm_label_ellipsis_set(label, EINA_TRUE);
736         elm_label_slide_duration_set(label, 2);
737         elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_NONE);
738         elm_label_slide_go(label);
739         evas_object_show(label);
740
741         return label;
742 }
743
744 /*
745  * @brief: Set a text to label object
746  * @param[parent]: Object has part to which you want to set text
747  * @param[part]: Part name to which you want to set text
748  * @param[text]: text you want to set to the part
749  */
750 void view_set_label_text(Evas_Object *parent, const char *part, const char *text)
751 {
752         Evas_Object *label = NULL;
753         char *markup_text = NULL;
754         char buf[256] = { 0, };
755
756         if (parent == NULL) {
757                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
758                 return;
759         }
760
761         markup_text = elm_entry_utf8_to_markup(text);
762         snprintf(buf, sizeof(buf), "%s%s%s", LABEL_STYLE_START, markup_text, LABEL_STYLE_END);
763         free(markup_text);
764
765         label = elm_object_part_content_get(parent, part);
766         if (label == NULL) {
767                 dlog_print(DLOG_ERROR, LOG_TAG, "label is NULL.");
768                 return;
769         }
770
771         elm_object_text_set(label, buf);
772 }
773
774 /*
775  * @brief: Set a label to given part
776  * @param[parent]: object has part to which you want to set this label
777  * @param[part]: part name to which you want to set this label
778  */
779 void view_set_label(Evas_Object *parent, const char *part)
780 {
781         Evas_Object *label = NULL;
782
783         if (parent == NULL) {
784                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
785                 return;
786         }
787
788         label = view_create_label(parent);
789         if (label == NULL) {
790                 dlog_print(DLOG_ERROR, LOG_TAG, "label is NULL.");
791                 return;
792         }
793
794         elm_object_part_content_set(parent, "sw.focus.txt", label);
795 }
796
797 /*
798  * @brief: Set a progressbar to given part
799  * @param[parent]: object has part to which you want to set this progressbar
800  * @param[part]: part name to which you want to set this progressbar
801  */
802 void view_set_prgressbar(Evas_Object *parent, const char *part)
803 {
804         Evas_Object *progressbar = NULL;
805
806         if (parent == NULL) {
807                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
808                 return;
809         }
810
811         progressbar = eext_circle_object_progressbar_add(parent, NULL);
812
813         eext_circle_object_value_min_max_set(progressbar, 0.0, 100.0);
814         eext_circle_object_radius_set(progressbar, 53);
815         eext_circle_object_line_width_set(progressbar, 5);
816         evas_object_show(progressbar);
817
818         elm_object_part_content_set(parent, part, progressbar);
819 }
820
821 /*
822  * @brief: Set value to a progressbar
823  * @param[parent]: object has part to which you want to set
824  * @param[part]: part name to which you want to set
825  * @param[val]: value to which you want to set
826  */
827 void view_set_progressbar_val(Evas_Object *parent, const char *part, int val)
828 {
829         Evas_Object *progressbar = NULL;
830
831         if (parent == NULL) {
832                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
833                 return;
834         }
835
836         if (part == NULL) {
837                 dlog_print(DLOG_ERROR, LOG_TAG, "part is NULL.");
838                 return;
839         }
840
841         progressbar = elm_object_part_content_get(parent, part);
842         if (progressbar == NULL) {
843                 dlog_print(DLOG_ERROR, LOG_TAG, "prgressbar is NULL.");
844                 return;
845         }
846
847         eext_circle_object_value_set(progressbar, val);
848 }
849
850 /*
851  * @brief: Make a checkbox
852  * @param[parent]: The object to which you want to add this checkbox
853  */
854 Evas_Object *view_create_checkbox(Evas_Object *parent)
855 {
856         Evas_Object *check;
857
858         if (parent == NULL) {
859                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
860                 return NULL;
861         }
862
863         check = elm_check_add(parent);
864         elm_check_state_set(check, EINA_FALSE);
865         evas_object_smart_callback_add(check, "changed", _icon_clicked_cb, NULL);
866         evas_object_show(check);
867
868         return check;
869 }
870
871 /*
872  * @brief: Make no voice memo view
873  * @param[parent]: naviframe
874  * @param[title]: titile of this view
875  * @param[detail]: detail text of this view
876  * @param[image_file]: image file name will be used in this view
877  * This function make a view consists of one title, one center image and one detail text at the bottom
878  */
879 Evas_Object *view_create_layout_no_content(Evas_Object *parent, char *title, char *detail, char *image_file)
880 {
881         Evas_Object *layout = NULL;
882         Evas_Object *img;
883         Elm_Object_Item *it;
884
885         if (parent == NULL) {
886                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
887                 return NULL;
888         }
889
890         layout = elm_layout_add(parent);
891         /* this make you can use layout consists of one title, one image and one detail text */
892         elm_layout_theme_set(layout, "layout", "nocontents", "default");
893         evas_object_size_hint_weight_set (layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
894         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
895
896         if(image_file) {
897                 img = elm_image_add(parent);
898                 elm_image_file_set(img, image_file, NULL);
899                 elm_object_part_content_set(layout, "elm.swallow.icon", img);
900                 evas_object_show(img);
901         }
902
903         if (detail) {
904                 char detail_text[256] = {0, };
905
906                 /* Customize font style bellow */
907                 snprintf(detail_text, sizeof(detail_text), "<font=TIZEN:style=Medium align=center color=#FFFFFF><font_size=28>%s</font_size></font>", detail);
908                 elm_object_part_text_set(layout, "elm.text", detail_text);
909         }
910         if (title) {
911                 char title_text[256] = {0, };
912
913                 snprintf(title_text, sizeof(title_text), "<font=TIZEN:style=Medium align=center color=#12B4FF><font_size=28>%s</font_size></font>", title);
914                 elm_object_part_text_set(layout, "elm.text.title", title_text);
915         }
916
917         /* if this signal is not sent, title text will be disappear */
918         elm_object_signal_emit(layout, "elm,state,title,enable", "elm");
919         /* push this no voice memo view to naviframe to show */
920         it = elm_naviframe_item_push(parent, "Title Enabled", NULL, NULL, layout, NULL);
921         /* if this is EINA_TRUE, you can see Title of naviframe on the top of the screen */
922         elm_naviframe_item_title_enabled_set(it, EINA_FALSE, EINA_FALSE);
923
924         return layout;
925 }
926
927 /*
928  * @brief: Set datetime to the part.
929  * @param[parent]: object to which you want to set datetime
930  * @param[circle_surface]: object render a connected circle object
931  * @param[part]: part name to which you want to set this datetime
932  * @param[style]: style of the datetime
933  */
934 Evas_Object *view_create_datetime(Evas_Object *parent, Eext_Circle_Surface *circle_surface, const char *style)
935 {
936         Evas_Object *datetime = NULL;
937         Evas_Object *circle_datetime = NULL;
938
939         if (parent == NULL) {
940                 dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
941                 return NULL;
942         }
943
944         if (circle_surface == NULL) {
945                 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get circle_surface.");
946                 return NULL;
947         }
948
949         datetime = elm_datetime_add(parent);
950         circle_datetime = eext_circle_object_datetime_add(datetime, circle_surface);
951
952         eext_rotary_object_event_activated_set(datetime, EINA_TRUE);
953         elm_datetime_format_set(datetime, FORMAT);
954
955         elm_object_style_set(datetime, style);
956
957         return datetime;
958 }
959