3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.tizenopensource.org/license
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include <unicode/ucal.h>
21 #include <unicode/udat.h>
22 #include <unicode/udatpg.h>
23 #include <unicode/uloc.h>
24 #include <unicode/ustring.h>
25 #include <unicode/ustdio.h>
30 static UDateTimePatternGenerator *pattern_generator = NULL;
31 static pthread_mutex_t mutex_lock = PTHREAD_MUTEX_INITIALIZER;
32 static UErrorCode status = U_ZERO_ERROR;
33 static int pattern_generator_reference_counter = 0;
35 static const char *_icons[] = {
36 [CI_EDIT] = "01_navi_icon_edit.png",
37 [CI_NEW] = "01_navi_icon_new.png",
38 [CI_DEL] = "01_navi_icon_delete.png",
39 [CI_PHOTO] = "00_list_photo_default.png",
41 static char _partbuf[1024];
42 static char _textbuf[1024];
43 static char _sigbuf[1024];
44 static char _timezone[32];
46 Evas_Object* cal_util_add_bg(Evas_Object *obj, Eina_Bool is_window)
56 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
59 elm_win_resize_object_add(obj, bg);
61 elm_object_style_set(bg, "group_list");
70 Evas_Object* cal_util_add_layout(Evas_Object *win, const char *g)
72 c_retvm_if(!win, NULL, "win is null");
75 Evas_Object *eo = elm_layout_add(win);
76 c_retvm_if(!eo, NULL, "elm_layout_add returned null");
79 r = elm_layout_file_set(eo, EDJ_FILE, g);
80 c_warn_if(r == EINA_FALSE, "elm_layout_file_set is failed");
83 r = elm_layout_theme_set(eo, "layout", "application", "default");
84 c_warn_if(r == EINA_FALSE, "elm_layout_theme_set is failed");
87 if (r == EINA_FALSE) {
92 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
98 Evas_Object* cal_util_add_rectangle(Evas_Object *p)
102 r = evas_object_rectangle_add(evas_object_evas_get(p));
109 static void __cal_util_delete_window(void *data, Evas_Object *obj, void *event)
114 Evas_Object* cal_util_add_window(const char *name, Evas_Coord* w, Evas_Coord* h)
118 Evas_Object *eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
119 c_retvm_if(!eo, NULL, "elm_win_add returned null");
121 Evas_Coord width, height;
123 elm_win_title_set(eo, name);
125 /*For calendar ring, window delete callback is not needed.*/
126 if (strcmp(name, CALENDAR_RING))
127 evas_object_smart_callback_add(eo, "delete,request", __cal_util_delete_window, NULL);
129 ecore_x_window_size_get(ecore_x_window_root_first_get(), &width, &height);
130 evas_object_resize(eo, width, height);
132 elm_win_conformant_set(eo, EINA_TRUE);
133 elm_win_indicator_mode_set(eo, ELM_WIN_INDICATOR_SHOW);
145 Evas_Object* cal_util_add_icon(Evas_Object *p, enum cld_icon i)
152 if (i < 0 || i >= CI_MAX)
155 ic = elm_icon_add(p);
159 r = elm_icon_file_set(ic, EDJ_FILE, _icons[i]);
165 evas_object_size_hint_align_set(ic, 0.5, 0.5);
170 Evas_Object* cal_util_add_icon_button(Evas_Object *p, enum cld_icon i)
177 ic = cal_util_add_icon(p, i);
181 evas_object_size_hint_min_set(ic, 34, 34);
183 bt = elm_button_add(p);
189 evas_object_size_hint_min_set(bt, 50, 50);
191 elm_object_content_set(bt, ic);
196 char* cal_util_get_part_text(const char *fmt, int pos)
198 snprintf(_partbuf, sizeof(_partbuf), fmt, pos);
203 void cal_util_set_text(Evas_Object *obj, const char *part, const char *fmt, ...)
208 vsnprintf(_textbuf, sizeof(_textbuf), fmt, ap);
211 edje_object_part_text_set(obj, part, _textbuf);
214 int cal_util_connect_pattern_generator()
216 pthread_mutex_lock(&mutex_lock);
217 if(pattern_generator_reference_counter == 0)
219 uloc_setDefault(getenv("LC_TIME"), &status);
220 if(!pattern_generator)
221 pattern_generator = udatpg_open(uloc_getDefault(), &status);
222 if(!pattern_generator)
224 ERR("udatpg_open fail : %s", u_errorName(status));
225 pthread_mutex_unlock(&mutex_lock);
230 pattern_generator_reference_counter++;
231 pthread_mutex_unlock(&mutex_lock);
236 int cal_util_disconnect_pattern_generator()
238 pthread_mutex_lock(&mutex_lock);
240 if(pattern_generator_reference_counter == 1)
242 if(pattern_generator)
243 udatpg_close(pattern_generator);
244 pattern_generator = NULL;
247 pattern_generator_reference_counter--;
249 pthread_mutex_unlock(&mutex_lock);
254 void cal_util_set_timezone(const char *timezone)
258 snprintf(_timezone, sizeof(_timezone), "%s", timezone);
261 void cal_util_initialize_timezone()
263 int is_lock_timezone = 0;
265 int ret = vconf_get_int(CAL_VCONFKEY_LOCK_TIMEZONE_OFFSET, &is_lock_timezone);
270 if (is_lock_timezone)
271 text = vconf_get_str(CAL_VCONFKEY_LOCK_TIMEZONE_PATH);
273 text = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
275 if (CAL_STRLEN(text)) {
277 cal_util_set_timezone(text);
281 ERR("vconf_get_str is failed.");
284 void cal_util_convert_lli_to_tm(const char *timezone, long long int lli, struct tm *tm)
288 UErrorCode status = U_ZERO_ERROR;
289 UChar utf16_timezone[64] = {0};
292 u_uastrncpy(utf16_timezone, timezone, 64);
294 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
296 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
299 ucal_setMillis(cal, (double)(lli* 1000.0), &status);
301 tm->tm_year = ucal_get(cal, UCAL_YEAR, &status) - 1900;
302 tm->tm_mon = ucal_get(cal, UCAL_MONTH, &status);
303 tm->tm_mday = ucal_get(cal, UCAL_DATE, &status);
305 if (ucal_get(cal, UCAL_AM_PM, &status))
306 tm->tm_hour = ucal_get(cal, UCAL_HOUR, &status) + 12;
308 tm->tm_hour = ucal_get(cal, UCAL_HOUR, &status);
310 tm->tm_min = ucal_get(cal, UCAL_MINUTE, &status);
311 tm->tm_sec = ucal_get(cal, UCAL_SECOND, &status);
312 tm->tm_isdst = ucal_get(cal, UCAL_DST_OFFSET, &status);
313 tm->tm_wday = ucal_get(cal, UCAL_DAY_OF_WEEK, &status) - 1;
314 tm->tm_yday = ucal_get(cal, UCAL_DAY_OF_YEAR, &status) - 1;
319 void cal_util_convert_tm_to_lli(const char *timezone, struct tm *tm, long long int *lli)
324 UErrorCode status = U_ZERO_ERROR;
325 UChar utf16_timezone[64] = {0};
328 u_uastrncpy(utf16_timezone, timezone, 64);
330 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
332 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
335 ucal_setAttribute(cal, UCAL_LENIENT, 1);
336 ucal_setDateTime(cal, tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, &status);
338 UDate millis = ucal_getMillis(cal, &status);
340 *lli = (long long int)(millis / 1000);
345 void cal_util_convert_lli_to_time_t(const char *timezone, long long int lli, time_t *time)
349 UErrorCode status = U_ZERO_ERROR;
350 UChar utf16_timezone[64] = {0};
353 u_uastrncpy(utf16_timezone, timezone, 64);
355 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
357 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
360 ucal_setMillis(cal, (double)(lli* 1000.0), &status);
364 tm.tm_year = ucal_get(cal, UCAL_YEAR, &status) - 1900;
365 tm.tm_mon = ucal_get(cal, UCAL_MONTH, &status);
366 tm.tm_mday = ucal_get(cal, UCAL_DATE, &status);
368 if (ucal_get(cal, UCAL_AM_PM, &status))
369 tm.tm_hour = ucal_get(cal, UCAL_HOUR, &status) + 12;
371 tm.tm_hour = ucal_get(cal, UCAL_HOUR, &status);
373 tm.tm_min = ucal_get(cal, UCAL_MINUTE, &status);
374 tm.tm_sec = ucal_get(cal, UCAL_SECOND, &status);
375 tm.tm_isdst = ucal_get(cal, UCAL_DST_OFFSET, &status);
376 tm.tm_wday = ucal_get(cal, UCAL_DAY_OF_WEEK, &status) - 1;
377 tm.tm_yday = ucal_get(cal, UCAL_DAY_OF_YEAR, &status) - 1;
384 void cal_util_convert_time_t_to_lli(const char *timezone, time_t time, long long int *lli)
388 UErrorCode status = U_ZERO_ERROR;
389 UChar utf16_timezone[64] = {0};
392 u_uastrncpy(utf16_timezone, timezone, 64);
394 u_uastrncpy(utf16_timezone, _timezone, sizeof(_timezone));
396 UCalendar *cal = ucal_open(utf16_timezone, u_strlen(utf16_timezone), uloc_getDefault(), UCAL_TRADITIONAL, &status);
399 ucal_setAttribute(cal, UCAL_LENIENT, 1);
403 ucal_setDateTime(cal, tm.tm_year + 1900, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, &status);
405 UDate millis = ucal_getMillis(cal, &status);
407 *lli = (long long int)(millis / 1000);
413 UDate cal_util_get_u_date_from_time_t(time_t time)
416 date = (UDate ) time*1000; /* Equivalent to Date = ucal_getNow() in Milliseconds */
420 UDate cal_util_get_u_date_from_tm(const struct tm* tm)
425 time = timelocal((struct tm*)tm);
427 date = (UDate ) time*1000; /* Equivalent to Date = ucal_getNow() in Milliseconds */
431 static void __cal_util_generate_best_pattern(UChar *custom_format, const struct tm* tm, char *buffer, int buffer_size)
433 UErrorCode status = U_ZERO_ERROR;
434 UDateFormat *formatter;
436 UChar bestPattern[64] = {0,};
437 UChar formatted[64] = {0,};
438 char bestPatternString[128]={0,};
439 char formattedString[128] = {0,};
440 int32_t bestPatternCapacity, formattedCapacity;
441 int32_t bestPatternLength, formattedLength;
442 uloc_setDefault(getenv("LC_TIME"), &status);
443 const char* locale = uloc_getDefault();
445 bestPatternCapacity = (int32_t)(sizeof(bestPattern)/sizeof((bestPattern)[0]));
446 bestPatternLength = udatpg_getBestPattern(pattern_generator, custom_format, u_strlen(custom_format), bestPattern, bestPatternCapacity, &status);
448 u_austrncpy(bestPatternString, bestPattern, 128);
450 date = cal_util_get_u_date_from_tm(tm);
451 formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status);
453 formattedCapacity = (int32_t)(sizeof(formatted)/sizeof((formatted)[0]));
454 formattedLength = udat_format(formatter, date, formatted, formattedCapacity, NULL, &status);
456 u_austrncpy(formattedString, formatted, 128);
458 udat_close(formatter);
460 snprintf(buffer, buffer_size, "%s", formattedString);
463 static void __cal_util_get_time_text_from_format(const char *date_format, const char *time_format, const struct tm* tm, char *buffer, int buffer_size)
465 char format[128]={0};
466 UChar custom_format[64]={0};
467 int date_format_length = 0;
468 int time_format_length = 0;
469 int format_length = 0;
472 date_format_length = CAL_STRLEN(date_format);
473 CAL_STRNCPY(format,date_format,date_format_length);
477 time_format_length = CAL_STRLEN(time_format);
478 CAL_STRNCAT(format,time_format,time_format_length);
481 format_length = CAL_STRLEN(format);
483 u_uastrncpy(custom_format, format, format_length);
485 __cal_util_generate_best_pattern(custom_format, tm, buffer, buffer_size);
488 void cal_util_set_time_text(Evas_Object *obj, const char *part, const char *date, const char* time, const struct tm *tm)
490 char time_text[128] = {0};
491 __cal_util_get_time_text_from_format(date, time, tm, time_text, sizeof(time_text) - 1);
493 edje_object_part_text_set(obj, part, time_text);
496 void cal_util_set_time_week_text(Evas_Object *obj, const char *part, const char *date, const char* time,
497 const struct tm *t, int start)
499 c_retm_if(!obj, "obj is null.");
500 c_retm_if(!part, "part is null.");
501 c_retm_if(!t, "t is null.");
505 char start_date[8] = {0};
506 char end_date[8] = {0};
507 char month_year[32] = {0};
508 char time_text[128] = {0};
510 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_16, NULL, &tm, week, sizeof(week) - 1);
512 tm.tm_mday -= CAL_UTIL_GET_WDAY(tm.tm_wday - start);
513 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_9, NULL, &tm, start_date, sizeof(start_date) - 1);
515 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_6, NULL, &tm, month_year, sizeof(month_year) - 1);
518 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_9, NULL, &tm, end_date, sizeof(end_date) - 1);
520 snprintf(time_text, sizeof(time_text) - 1,"W%s ( %s - %s ) %s", week, start_date, end_date, month_year);
522 edje_object_part_text_set(obj, part, time_text);
525 int cal_util_get_time_text(char* buf, int buf_size, const char *date, const char* time, const struct tm *tm)
527 char time_text[128] = {0};
529 __cal_util_get_time_text_from_format(date, time, tm, time_text, sizeof(time_text) - 1);
531 snprintf(buf, buf_size, "%s", time_text);
533 return CAL_STRLEN(time_text);
536 void cal_util_emit_signal(Evas_Object *obj, const char *fmt, ...)
541 vsnprintf(_sigbuf, sizeof(_sigbuf), fmt, ap);
544 edje_object_signal_emit(obj, _sigbuf, "prog");
547 Evas_Object* cal_util_add_separator(Evas_Object *box, const char *style)
551 if (!box || CAL_STRCMP(elm_object_widget_type_get(box), "box"))
554 sp = elm_separator_add(box);
556 elm_separator_horizontal_set(sp, EINA_TRUE);
557 elm_object_style_set(sp, style);
558 evas_object_show(sp);
559 elm_box_pack_end(box, sp);
565 Evas_Object* cal_util_add_scroller(Evas_Object *p)
569 sc = elm_scroller_add(p);
573 elm_scroller_bounce_set(sc, EINA_FALSE, EINA_TRUE);
574 elm_scroller_policy_set(sc, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
576 evas_object_show(sc);
580 Evas_Object* cal_util_add_box(Evas_Object *p)
588 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
589 evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, 0.0);
590 evas_object_show(bx);
595 void cal_util_set_controlbar_button(Evas_Object *btn, char *label, char *style, void (*func) (void *data, Evas_Object *obj, void *event_info), void* data)
599 elm_object_style_set(btn, style);
600 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
601 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.5);
602 elm_object_text_set(btn, label);
603 evas_object_smart_callback_add(btn, "clicked", func, data);
604 evas_object_show(btn);
607 static void __cal_util_edit_field_changed_callback(void *data, Evas_Object *obj, void *event_info) // This callback is for showing(hiding) X marked button.
609 c_retm_if(!data, "data is null");
610 c_retm_if(!obj, "obj is null");
612 if (elm_object_focus_get(data)) {
613 elm_object_signal_emit(data, "elm,state,eraser,show", "elm");
616 if (elm_entry_is_empty(obj))
617 elm_object_signal_emit(data, "elm,state,guidetext,show", "elm");
619 elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
623 static void __cal_util_edit_field_focused_callback(void *data, Evas_Object *obj, void *event_info) // Focused callback will show X marked button and hide guidetext.
625 c_retm_if(!data, "data is null");
626 c_retm_if(!obj, "obj is null");
628 elm_object_signal_emit(data, "elm,state,eraser,show", "elm");
630 elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
633 static void __cal_util_edit_field_unfocused_callback(void *data, Evas_Object *obj, void *event_info) // Unfocused callback will show guidetext and hide X marked button.
635 c_retm_if(!data, "data is null");
636 c_retm_if(!obj, "obj is null");
638 if (elm_entry_is_empty(obj))
639 elm_object_signal_emit(data, "elm,state,guidetext,show", "elm");
641 elm_object_signal_emit(data, "elm,state,eraser,hide", "elm");
644 static void __cal_util_edit_field_eraser_clicked_callback(void *data, Evas_Object *obj, const char *emission, const char *source) // When X marked button is clicked, empty entry's contents.
646 c_retm_if(!data, "data is null");
648 elm_entry_entry_set(data, "");
651 Evas_Object * cal_util_add_edit_field(Evas_Object *parent, const char *title, const char *guide, Eina_Bool single_line, Eina_Bool is_editable)
653 c_retvm_if(!parent, NULL, "parent is null");
655 Evas_Object *layout = elm_layout_add(parent);
656 c_retvm_if(!layout, NULL, "layout is null");
658 if (title && title[0] != '\0') {
659 elm_layout_theme_set(layout, "layout", "editfield", "title");
660 elm_object_part_text_set(layout, "elm.text", title);
663 elm_layout_theme_set(layout, "layout", "editfield", "default");
665 Evas_Object *entry = elm_entry_add(parent);
666 c_retvm_if(!entry, layout, "entry is null");
668 elm_object_part_content_set(layout, "elm.swallow.content", entry);
669 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
671 if (guide && guide[0] != '\0')
672 elm_object_part_text_set(layout, "elm.guidetext", guide);
674 elm_entry_single_line_set(entry, single_line);
675 elm_entry_scrollable_set(entry, single_line);
678 elm_object_signal_callback_add(layout, "elm,eraser,clicked", "elm", __cal_util_edit_field_eraser_clicked_callback, entry);
680 elm_entry_editable_set(entry, is_editable);
681 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
684 evas_object_smart_callback_add(entry, "changed", __cal_util_edit_field_changed_callback, layout);
685 evas_object_smart_callback_add(entry, "focused", __cal_util_edit_field_focused_callback, layout);
686 evas_object_smart_callback_add(entry, "unfocused", __cal_util_edit_field_unfocused_callback, layout);
688 evas_object_show(layout);
693 static void __cal_util_searchbar_changed_callback(void *data, Evas_Object *obj, void *event_info)
695 c_retm_if(!data, "data is null");
696 c_retm_if(!obj, "obj is null");
698 if (elm_object_focus_get(data)) {
699 elm_object_signal_emit(data, "elm,state,eraser,show", "elm");
702 if (elm_entry_is_empty(obj))
703 elm_object_signal_emit(data, "elm,state,guidetext,show", "elm");
705 elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
709 static void __cal_util_searchbar_with_cancel_btn_focused_callback(void *data, Evas_Object *obj, void *event_info)
711 c_retm_if(!data, "data is null");
712 c_retm_if(!obj, "obj is null");
714 if (!elm_entry_is_empty(obj))
715 elm_object_signal_emit(data, "elm,state,eraser,show", "elm");
717 elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
719 elm_object_signal_emit(data, "cancel,in", "");
722 static void __cal_util_searchbar_focused_callback(void *data, Evas_Object *obj, void *event_info)
724 c_retm_if(!data, "data is null");
725 c_retm_if(!obj, "obj is null");
727 elm_object_signal_emit(data, "elm,state,eraser,show", "elm");
729 elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
732 static void __cal_util_searchbar_eraser_clicked_callback(void *data, Evas_Object *obj, const char *emission, const char *source) // When X marked button is clicked, empty entry's contents.
734 c_retm_if(!data, "data is null");
736 elm_entry_entry_set(data, "");
739 static void __cal_util_searchbar_cancel_btn_clicked_callback(void *data, Evas_Object *obj, void *event_info)
741 c_retm_if(!data, "data is null");
742 c_retm_if(!obj, "obj is null");
744 Evas_Object *searchbar_layout = data;
745 Evas_Object *entry = elm_object_part_content_get(searchbar_layout, "elm.swallow.content");
746 c_retm_if(!entry, "entry is null");
748 evas_object_hide(obj);
750 elm_entry_input_panel_hide(entry);
752 elm_entry_entry_set(entry, NULL);
754 elm_object_focus_set(entry, EINA_FALSE);
757 static void __cal_util_searchbar_unfocused_callback(void *data, Evas_Object *obj, void *event_info)
759 c_retm_if(!data, "data is null");
760 c_retm_if(!obj, "obj is null");
762 if (elm_entry_is_empty(obj))
763 elm_object_signal_emit(data, "elm,state,guidetext,show", "elm");
765 elm_object_signal_emit(data, "elm,state,eraser,hide", "elm");
767 elm_object_signal_emit(data, "cancel,out", "");
770 static void __cal_util_searchbar_symbol_clicked_callback(void *data, Evas_Object *obj, const char *emission, const char *source)
772 c_retm_if(!data, "data is null");
774 elm_object_focus_set(data, EINA_TRUE);
777 static void __cal_util_searchbar_bg_clicked_callback(void *data, Evas_Object *obj, const char *emission, const char *source)
779 c_retm_if(!data, "data is null");
781 elm_object_focus_set(data, EINA_TRUE);
784 Evas_Object * cal_util_add_searchbar(Evas_Object *parent, const char *text, const char *guide, Eina_Bool cancel_button)
786 c_retvm_if(!parent, NULL, "parent is null");
788 Evas_Object *searchbar_layout = elm_layout_add(parent);
789 c_retvm_if(!searchbar_layout, NULL, "searchbar_layout is null");
792 elm_layout_theme_set(searchbar_layout, "layout", "searchbar", "cancel_button");
794 elm_layout_theme_set(searchbar_layout, "layout", "searchbar", "default");
796 Evas_Object *entry = elm_entry_add(searchbar_layout);
797 c_retvm_if(!entry, searchbar_layout, "entry is null");
799 evas_object_show(entry);
801 elm_entry_scrollable_set(entry, EINA_TRUE);
802 elm_entry_single_line_set(entry, EINA_TRUE);
803 elm_object_part_content_set(searchbar_layout, "elm.swallow.content", entry);
805 if (guide && strlen(guide))
806 elm_object_part_text_set(searchbar_layout, "elm.guidetext", guide);
808 elm_object_part_text_set(searchbar_layout, "elm.guidetext", S_("IDS_COM_BODY_SEARCH"));
810 if (text && strlen(text))
811 elm_object_text_set(entry, text);
814 Evas_Object *cancel_btn = elm_button_add(searchbar_layout);
815 c_retvm_if(!cancel_btn, searchbar_layout, "cancel_btn is null");
817 elm_object_part_content_set(searchbar_layout, "button_cancel", cancel_btn);
818 elm_object_style_set(cancel_btn, "searchbar/default");
819 elm_object_text_set(cancel_btn, S_("IDS_COM_SK_CANCEL"));
821 evas_object_smart_callback_add(entry, "focused", __cal_util_searchbar_with_cancel_btn_focused_callback, searchbar_layout);
822 evas_object_smart_callback_add(cancel_btn, "clicked", __cal_util_searchbar_cancel_btn_clicked_callback, searchbar_layout);
826 evas_object_smart_callback_add(entry, "focused", __cal_util_searchbar_focused_callback, searchbar_layout);
829 evas_object_smart_callback_add(entry, "changed", __cal_util_searchbar_changed_callback, searchbar_layout);
830 evas_object_smart_callback_add(entry, "unfocused", __cal_util_searchbar_unfocused_callback, searchbar_layout);
831 elm_object_signal_callback_add(searchbar_layout, "elm,eraser,clicked", "elm", __cal_util_searchbar_eraser_clicked_callback, entry);
832 elm_object_signal_callback_add(searchbar_layout, "elm,bg,clicked", "elm", __cal_util_searchbar_bg_clicked_callback, entry);
833 elm_object_signal_callback_add(searchbar_layout, "elm,action,click", "", __cal_util_searchbar_symbol_clicked_callback, entry);
835 return searchbar_layout;
838 Evas_Object * cal_util_add_nocontents(Evas_Object *parent, const char *label)
840 c_retvm_if(!parent, NULL, "parent is null");
842 Evas_Object *layout = elm_layout_add(parent);
843 c_retvm_if(!layout, NULL, "layout is null");
845 elm_layout_theme_set(layout, "layout", "nocontents", "full");
847 if (label && strlen(label))
848 elm_object_part_text_set(layout, "elm.text", label);
853 Evas_Object * cal_util_add_controlbar(Evas_Object * parent)
855 c_retvm_if(!parent, NULL, "parent is null");
857 Evas_Object *toolbar = elm_toolbar_add(parent);
858 c_retvm_if(!toolbar, NULL, "toolbar is null");
860 elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
865 static void __cal_util_popup_response_callback(void *data, Evas_Object *obj, void *event_info)
867 evas_object_del(data);
870 Evas_Object * cal_util_add_popup(Evas_Object *parent, const char *style, const char *title, const char *desc,
871 void (*callback_func)(void *data, Evas_Object *obj, void *ei), void *data, ...)
873 c_retvm_if(!parent, NULL, "parent is null");
875 Evas_Object *popup = elm_popup_add(parent);
876 c_retvm_if(!popup, NULL, "popup is null");
878 if (CAL_STRLEN(style))
879 elm_object_style_set(popup, style);
882 evas_object_data_set(popup, "data", data);
884 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
886 if (CAL_STRLEN(title))
887 elm_object_part_text_set(popup, "title,text", title);
889 if (CAL_STRLEN(desc))
890 elm_object_text_set(popup, desc);
894 Evas_Object *btn = NULL;
895 const char *label = NULL;
899 callback_func = __cal_util_popup_response_callback;
903 while ((label = va_arg(arg, char*))) {
904 btn = elm_button_add(popup);
910 elm_object_text_set(btn, label);
911 snprintf(part, sizeof(part), "button%d", ++i);
912 elm_object_part_content_set(popup, part, btn);
913 evas_object_smart_callback_add(btn, "clicked", callback_func, popup);
919 elm_popup_timeout_set(popup, 3.0);
921 evas_object_show(popup);
926 Evas_Object * cal_util_add_datetime(Evas_Object *parent, const char *title, const struct tm *tm)
928 c_retvm_if(!parent, NULL, "parent is null");
930 Evas_Object *datetime = NULL;
932 if (CAL_STRLEN(title)) {
934 Evas_Object *layout = elm_layout_add(parent);
935 c_retvm_if(!layout, NULL, "layout is null");
937 Eina_Bool r = elm_layout_file_set(layout, EDJ_FILE, "dialoguegroup/datetime");
938 c_retvm_if(!r, NULL, "r is null");
940 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
942 datetime = elm_datetime_add(layout);
943 c_retvm_if(!datetime, NULL, "datetime is null");
945 elm_object_part_text_set(layout, "elm.text", title);
948 elm_datetime_value_set(datetime, tm);
950 elm_object_part_content_set(layout, "elm.icon", datetime);
956 datetime = elm_datetime_add(parent);
957 c_retvm_if(!datetime, NULL, "datetime is null");
959 evas_object_size_hint_weight_set(datetime, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
962 elm_datetime_value_set(datetime, tm);
968 void cal_util_get_week_number_text(const struct tm* tm, char *buffer, int buffer_size)
970 c_retm_if(!tm, "tm is null");
971 c_retm_if(!buffer, "buffer is null");
973 __cal_util_get_time_text_from_format(CAL_UTIL_DATE_FORMAT_16, NULL ,tm, buffer, buffer_size);
976 int cal_util_get_distance(Evas_Coord_Point *s, Evas_Coord_Point *e)
978 c_retvm_if(!s, -1, "s is null");
979 c_retvm_if(!e, -1, "e is null");
981 return (Evas_Coord)sqrt((s->x - e->x) * (s->x - e->x)
982 + (s->y - e->y) * (s->y - e->y));