summaryrefslogtreecommitdiff
path: root/src/lib/elementary
diff options
context:
space:
mode:
authorWooHyun Jung <wh0705.jung@samsung.com>2017-10-27 18:31:59 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2017-10-31 11:21:15 +0900
commit02f179628c253de935a96cf6880b237ae268190f (patch)
treedcee3d357fe34f6e33ed6daf2d2f0c9531af0476 /src/lib/elementary
parentde349e1b9e8f34381747ed8d57c56577bd353a6b (diff)
efl_ui_calendar: apply new format_cb
Diffstat (limited to 'src/lib/elementary')
-rw-r--r--src/lib/elementary/efl_ui_calendar.c67
-rw-r--r--src/lib/elementary/efl_ui_calendar.eo37
-rw-r--r--src/lib/elementary/efl_ui_calendar.h1
-rw-r--r--src/lib/elementary/efl_ui_calendar_common.h21
-rw-r--r--src/lib/elementary/efl_ui_calendar_private.h7
5 files changed, 56 insertions, 77 deletions
diff --git a/src/lib/elementary/efl_ui_calendar.c b/src/lib/elementary/efl_ui_calendar.c
index 66ca500bd4..605f8274ff 100644
--- a/src/lib/elementary/efl_ui_calendar.c
+++ b/src/lib/elementary/efl_ui_calendar.c
@@ -165,27 +165,40 @@ _disable(Efl_Ui_Calendar_Data *sd,
165 elm_layout_signal_emit(sd->obj, emission, "elm"); 165 elm_layout_signal_emit(sd->obj, emission, "elm");
166} 166}
167 167
168static char *
169_format_month_year(struct tm *date)
170{
171 return eina_strftime(E_("%B %Y"), date);
172}
173
174static void 168static void
175_set_month_year(Efl_Ui_Calendar_Data *sd) 169_set_month_year(Efl_Ui_Calendar_Data *sd)
176{ 170{
177 char *buf;
178 171
179 sd->filling = EINA_TRUE; 172 sd->filling = EINA_TRUE;
180 173
181 buf = sd->format_func(&sd->shown_date); 174 if (sd->format_cb)
182
183 if (buf)
184 { 175 {
185 elm_layout_text_set(sd->obj, "month_text", buf); 176 Eina_Value val;
186 free(buf); 177 const char *buf;
178
179 eina_value_setup(&val, EINA_VALUE_TYPE_TM);
180 eina_value_set(&val, sd->shown_date);
181 eina_strbuf_reset(sd->format_strbuf);
182 sd->format_cb(sd->format_cb_data, sd->format_strbuf, val);
183 buf = eina_strbuf_string_get(sd->format_strbuf);
184 eina_value_flush(&val);
185
186 if (buf)
187 elm_layout_text_set(sd->obj, "month_text", buf);
188 else
189 elm_layout_text_set(sd->obj, "month_text", "");
190 }
191 else
192 {
193 char *buf;
194 buf = eina_strftime(E_("%B %Y"), &sd->shown_date);
195 if (buf)
196 {
197 elm_layout_text_set(sd->obj, "month_text", buf);
198 free(buf);
199 }
200 else elm_layout_text_set(sd->obj, "month_text", "");
187 } 201 }
188 else elm_layout_text_set(sd->obj, "month_text", "");
189 202
190 sd->filling = EINA_FALSE; 203 sd->filling = EINA_FALSE;
191} 204}
@@ -504,7 +517,7 @@ _efl_ui_calendar_elm_widget_theme_apply(Eo *obj, Efl_Ui_Calendar_Data *sd)
504static inline Eina_Bool 517static inline Eina_Bool
505_fix_date(Efl_Ui_Calendar_Data *sd) 518_fix_date(Efl_Ui_Calendar_Data *sd)
506{ 519{
507 Eina_Bool fixed = EINA_FALSE; 520 Eina_Bool no_change = EINA_TRUE;
508 521
509 if ((sd->date.tm_year < sd->date_min.tm_year) || 522 if ((sd->date.tm_year < sd->date_min.tm_year) ||
510 ((sd->date.tm_year == sd->date_min.tm_year) && 523 ((sd->date.tm_year == sd->date_min.tm_year) &&
@@ -516,7 +529,7 @@ _fix_date(Efl_Ui_Calendar_Data *sd)
516 sd->date.tm_year = sd->shown_date.tm_year = sd->date_min.tm_year; 529 sd->date.tm_year = sd->shown_date.tm_year = sd->date_min.tm_year;
517 sd->date.tm_mon = sd->shown_date.tm_mon = sd->date_min.tm_mon; 530 sd->date.tm_mon = sd->shown_date.tm_mon = sd->date_min.tm_mon;
518 sd->date.tm_mday = sd->shown_date.tm_mday = sd->date_min.tm_mday; 531 sd->date.tm_mday = sd->shown_date.tm_mday = sd->date_min.tm_mday;
519 fixed = EINA_TRUE; 532 no_change = EINA_FALSE;
520 } 533 }
521 else if ((sd->date_max.tm_year != -1) && 534 else if ((sd->date_max.tm_year != -1) &&
522 ((sd->date.tm_year > sd->date_max.tm_year) || 535 ((sd->date.tm_year > sd->date_max.tm_year) ||
@@ -529,7 +542,7 @@ _fix_date(Efl_Ui_Calendar_Data *sd)
529 sd->date.tm_year = sd->shown_date.tm_year = sd->date_max.tm_year; 542 sd->date.tm_year = sd->shown_date.tm_year = sd->date_max.tm_year;
530 sd->date.tm_mon = sd->shown_date.tm_mon = sd->date_max.tm_mon; 543 sd->date.tm_mon = sd->shown_date.tm_mon = sd->date_max.tm_mon;
531 sd->date.tm_mday = sd->shown_date.tm_mday = sd->date_max.tm_mday; 544 sd->date.tm_mday = sd->shown_date.tm_mday = sd->date_max.tm_mday;
532 fixed = EINA_TRUE; 545 no_change = EINA_FALSE;
533 } 546 }
534 else 547 else
535 { 548 {
@@ -539,7 +552,7 @@ _fix_date(Efl_Ui_Calendar_Data *sd)
539 sd->date.tm_year = sd->shown_date.tm_year; 552 sd->date.tm_year = sd->shown_date.tm_year;
540 } 553 }
541 554
542 return fixed; 555 return no_change;
543} 556}
544 557
545static Eina_Bool 558static Eina_Bool
@@ -865,6 +878,9 @@ _efl_ui_calendar_efl_object_destructor(Eo *obj, Efl_Ui_Calendar_Data *sd)
865 ecore_timer_del(sd->spin_year); 878 ecore_timer_del(sd->spin_year);
866 ecore_timer_del(sd->update_timer); 879 ecore_timer_del(sd->update_timer);
867 880
881 efl_ui_format_cb_set(obj, NULL, NULL, NULL);
882 eina_strbuf_free(sd->format_strbuf);
883
868 for (i = 0; i < ELM_DAY_LAST; i++) 884 for (i = 0; i < ELM_DAY_LAST; i++)
869 eina_stringshare_del(sd->weekdays[i]); 885 eina_stringshare_del(sd->weekdays[i]);
870 886
@@ -943,7 +959,7 @@ _efl_ui_calendar_constructor_internal(Eo *obj, Efl_Ui_Calendar_Data *priv)
943 priv->today_it = -1; 959 priv->today_it = -1;
944 priv->selected_it = -1; 960 priv->selected_it = -1;
945 priv->first_day_it = -1; 961 priv->first_day_it = -1;
946 priv->format_func = _format_month_year; 962 priv->format_cb = NULL;
947 963
948 edje_object_signal_callback_add 964 edje_object_signal_callback_add
949 (wd->resize_obj, "elm,action,selected", "*", 965 (wd->resize_obj, "elm,action,selected", "*",
@@ -1161,9 +1177,20 @@ _efl_ui_calendar_date_get(Eo *obj EINA_UNUSED, Efl_Ui_Calendar_Data *sd)
1161} 1177}
1162 1178
1163EOLIAN static void 1179EOLIAN static void
1164_efl_ui_calendar_format_function_set(Eo *obj EINA_UNUSED, Efl_Ui_Calendar_Data *sd, Efl_Ui_Calendar_Format_Cb format_function) 1180_efl_ui_calendar_efl_ui_format_format_cb_set(Eo *obj, Efl_Ui_Calendar_Data *sd, void *func_data, Efl_Ui_Format_Func_Cb func, Eina_Free_Cb func_free_cb)
1165{ 1181{
1166 sd->format_func = format_function; 1182 if ((sd->format_cb_data == func_data) && (sd->format_cb == func))
1183 return;
1184
1185 if (sd->format_cb_data && sd->format_free_cb)
1186 sd->format_free_cb(sd->format_cb_data);
1187
1188 sd->format_cb = func;
1189 sd->format_cb_data = func_data;
1190 sd->format_free_cb = func_free_cb;
1191 if (!sd->format_strbuf) sd->format_strbuf = eina_strbuf_new();
1192
1193 evas_object_smart_changed(obj);
1167} 1194}
1168 1195
1169EOLIAN static void 1196EOLIAN static void
diff --git a/src/lib/elementary/efl_ui_calendar.eo b/src/lib/elementary/efl_ui_calendar.eo
index 6615fa90fb..f1afa05f04 100644
--- a/src/lib/elementary/efl_ui_calendar.eo
+++ b/src/lib/elementary/efl_ui_calendar.eo
@@ -18,7 +18,7 @@ enum Efl.Ui.Calendar.Weekday
18 last [[Sentinel value to indicate last enum field during iteration]] 18 last [[Sentinel value to indicate last enum field during iteration]]
19} 19}
20 20
21class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.Atspi_Widget_Action) 21class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.Atspi_Widget_Action, Efl.Ui.Format)
22{ 22{
23 [[Calendar widget 23 [[Calendar widget
24 24
@@ -37,36 +37,6 @@ class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.At
37 day: Efl.Ui.Calendar.Weekday(Efl.Ui.Calendar.Weekday.sunday); [[Weekday enum value, see @Elm.Calendar.Weekday]] 37 day: Efl.Ui.Calendar.Weekday(Efl.Ui.Calendar.Weekday.sunday); [[Weekday enum value, see @Elm.Calendar.Weekday]]
38 } 38 }
39 } 39 }
40 @property format_function {
41 set {
42 [[Set a function to format the string that will be used to display
43 month and year;
44
45 By default it uses strftime with "%B %Y" format string.
46 It should allocate the memory that will be used by the string,
47 that will be freed by the widget after usage.
48 A pointer to the string and a pointer to the time struct will be provided.
49 ]]
50 /* FIXME-doc
51 * Example:
52 * @code
53 * static char
54 * _format_month_year(struct tm *selected_time)
55 * {
56 * char buf[32];
57 * if (!strftime(buf, sizeof(buf), "%B %Y", selected_time)) return NULL;
58 * return strdup(buf);
59 * }
60 *
61 * efl_ui_calendar_format_function_set(calendar, _format_month_year);
62 * @endcode
63 */
64 }
65 values {
66 format_function: Efl_Ui_Calendar_Format_Cb; [[Function to set the month-year string given
67 the selected date.]]
68 }
69 }
70 @property date_min { 40 @property date_min {
71 [[Minimum date on calendar.]] 41 [[Minimum date on calendar.]]
72 set { 42 set {
@@ -121,9 +91,9 @@ class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.At
121 [[Set the selected date. If the date is greater than the maximum date, 91 [[Set the selected date. If the date is greater than the maximum date,
122 the date would be changed to the maximum date with returning $false. 92 the date would be changed to the maximum date with returning $false.
123 In the opposite case with the minimum date, 93 In the opposite case with the minimum date,
124 this would give the same result. 94 this would give the same result.
125 ]] 95 ]]
126 return: bool; [[$true, on success, $false otherwise]] 96 return: bool; [[$true, on success, $false otherwise]]
127 } 97 }
128 get { 98 get {
129 } 99 }
@@ -142,6 +112,7 @@ class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.At
142 Elm.Widget.on_focus_update; 112 Elm.Widget.on_focus_update;
143 Elm.Widget.widget_event; 113 Elm.Widget.widget_event;
144 Elm.Interface.Atspi_Widget_Action.elm_actions { get; } 114 Elm.Interface.Atspi_Widget_Action.elm_actions { get; }
115 Efl.Ui.Format.format_cb { set; }
145 } 116 }
146 events { 117 events {
147 changed; [[Emitted when the selected date in the calendar is changed]] 118 changed; [[Emitted when the selected date in the calendar is changed]]
diff --git a/src/lib/elementary/efl_ui_calendar.h b/src/lib/elementary/efl_ui_calendar.h
index 9c71188b47..f80dce28d5 100644
--- a/src/lib/elementary/efl_ui_calendar.h
+++ b/src/lib/elementary/efl_ui_calendar.h
@@ -48,7 +48,6 @@
48 * @{ 48 * @{
49 */ 49 */
50 50
51#include "efl_ui_calendar_common.h"
52#ifdef EFL_EO_API_SUPPORT 51#ifdef EFL_EO_API_SUPPORT
53#include "efl_ui_calendar.eo.h" 52#include "efl_ui_calendar.eo.h"
54#endif 53#endif
diff --git a/src/lib/elementary/efl_ui_calendar_common.h b/src/lib/elementary/efl_ui_calendar_common.h
deleted file mode 100644
index 70a95ad8f2..0000000000
--- a/src/lib/elementary/efl_ui_calendar_common.h
+++ /dev/null
@@ -1,21 +0,0 @@
1/**
2 * @addtogroup Elm_Calendar
3 *
4 * @{
5 */
6
7/**
8 * This callback type is used to format the string that will be used
9 * to display month and year.
10 *
11 * @param stime Struct representing time.
12 * @return String representing time that will be set to calendar's text.
13 *
14 * @see elm_calendar_format_function_set()
15 */
16typedef char * (*Efl_Ui_Calendar_Format_Cb)(struct tm *stime);
17
18
19/**
20 * @}
21 */
diff --git a/src/lib/elementary/efl_ui_calendar_private.h b/src/lib/elementary/efl_ui_calendar_private.h
index 7ae261cfa9..4aa00878ea 100644
--- a/src/lib/elementary/efl_ui_calendar_private.h
+++ b/src/lib/elementary/efl_ui_calendar_private.h
@@ -32,7 +32,6 @@ struct _Efl_Ui_Calendar_Data
32 int spin_speed; 32 int spin_speed;
33 int today_it, selected_it, focused_it; 33 int today_it, selected_it, focused_it;
34 Ecore_Timer *spin_month, *spin_year, *update_timer; 34 Ecore_Timer *spin_month, *spin_year, *update_timer;
35 Efl_Ui_Calendar_Format_Cb format_func;
36 const char *weekdays[ELM_DAY_LAST]; 35 const char *weekdays[ELM_DAY_LAST];
37 struct tm current_date, shown_date, date, date_min, date_max; 36 struct tm current_date, shown_date, date, date_min, date_max;
38 Evas_Object *inc_btn_month; 37 Evas_Object *inc_btn_month;
@@ -44,9 +43,13 @@ struct _Efl_Ui_Calendar_Data
44 Eo *items[42]; 43 Eo *items[42];
45 44
46 Efl_Ui_Calendar_Weekday first_week_day; 45 Efl_Ui_Calendar_Weekday first_week_day;
47
48 unsigned char first_day_it; 46 unsigned char first_day_it;
49 47
48 Efl_Ui_Format_Func_Cb format_cb;
49 Eina_Free_Cb format_free_cb;
50 void *format_cb_data;
51 Eina_Strbuf *format_strbuf;
52
50 Eina_Bool selected : 1; 53 Eina_Bool selected : 1;
51 Eina_Bool double_spinners : 1; 54 Eina_Bool double_spinners : 1;
52 Eina_Bool filling : 1; 55 Eina_Bool filling : 1;