forked from enlightenment/efl
efl_ui_calendar: apply new format_cb
This commit is contained in:
parent
de349e1b9e
commit
02f179628c
|
@ -373,7 +373,6 @@ includesub_HEADERS = \
|
|||
lib/elementary/elm_calendar_legacy.h \
|
||||
lib/elementary/elm_calendar_common.h \
|
||||
lib/elementary/efl_ui_calendar.h \
|
||||
lib/elementary/efl_ui_calendar_common.h \
|
||||
lib/elementary/elm_check.h \
|
||||
lib/elementary/efl_ui_check_eo.h \
|
||||
lib/elementary/elm_check_legacy.h \
|
||||
|
|
|
@ -404,10 +404,24 @@ _cal_changed_cb(void *data EINA_UNUSED, const Efl_Event *ev)
|
|||
max_date.tm_year + 1900);
|
||||
}
|
||||
|
||||
static void
|
||||
_cal_format_cb(void *data EINA_UNUSED, Eina_Strbuf *str, const Eina_Value value)
|
||||
{
|
||||
char buf[128];
|
||||
struct tm current_time;
|
||||
|
||||
if (eina_value_type_get(&value) == EINA_VALUE_TYPE_TM)
|
||||
{
|
||||
eina_value_get(&value, ¤t_time);
|
||||
strftime(buf, sizeof(buf), "%b %y", ¤t_time);
|
||||
eina_strbuf_append_printf(str, "<< %s >>", buf);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_efl_ui_calendar(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
Evas_Object *win, *box;
|
||||
Evas_Object *win, *box, *cal;
|
||||
struct tm selected_date, min_date, max_date;
|
||||
time_t current_date;
|
||||
|
||||
|
@ -426,12 +440,14 @@ test_efl_ui_calendar(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void
|
|||
efl_ui_direction_set(efl_added, EFL_UI_DIR_HORIZONTAL),
|
||||
efl_content_set(win, efl_added));
|
||||
|
||||
efl_add(EFL_UI_CALENDAR_CLASS, win,
|
||||
efl_ui_calendar_date_set(efl_added, selected_date),
|
||||
efl_ui_calendar_date_min_set(efl_added, min_date),
|
||||
efl_ui_calendar_date_max_set(efl_added, max_date),
|
||||
efl_event_callback_add(efl_added, EFL_UI_CALENDAR_EVENT_CHANGED, _cal_changed_cb, NULL),
|
||||
efl_pack(box, efl_added));
|
||||
cal = efl_add(EFL_UI_CALENDAR_CLASS, win,
|
||||
efl_ui_calendar_date_min_set(efl_added, min_date),
|
||||
efl_ui_calendar_date_max_set(efl_added, max_date),
|
||||
efl_ui_calendar_date_set(efl_added, selected_date),
|
||||
efl_event_callback_add(efl_added, EFL_UI_CALENDAR_EVENT_CHANGED, _cal_changed_cb, NULL),
|
||||
efl_pack(box, efl_added));
|
||||
|
||||
efl_ui_format_cb_set(cal, NULL, _cal_format_cb, NULL);
|
||||
|
||||
efl_gfx_size_set(win, EINA_SIZE2D(300, 300));
|
||||
}
|
||||
|
|
|
@ -165,27 +165,40 @@ _disable(Efl_Ui_Calendar_Data *sd,
|
|||
elm_layout_signal_emit(sd->obj, emission, "elm");
|
||||
}
|
||||
|
||||
static char *
|
||||
_format_month_year(struct tm *date)
|
||||
{
|
||||
return eina_strftime(E_("%B %Y"), date);
|
||||
}
|
||||
|
||||
static void
|
||||
_set_month_year(Efl_Ui_Calendar_Data *sd)
|
||||
{
|
||||
char *buf;
|
||||
|
||||
sd->filling = EINA_TRUE;
|
||||
|
||||
buf = sd->format_func(&sd->shown_date);
|
||||
|
||||
if (buf)
|
||||
if (sd->format_cb)
|
||||
{
|
||||
elm_layout_text_set(sd->obj, "month_text", buf);
|
||||
free(buf);
|
||||
Eina_Value val;
|
||||
const char *buf;
|
||||
|
||||
eina_value_setup(&val, EINA_VALUE_TYPE_TM);
|
||||
eina_value_set(&val, sd->shown_date);
|
||||
eina_strbuf_reset(sd->format_strbuf);
|
||||
sd->format_cb(sd->format_cb_data, sd->format_strbuf, val);
|
||||
buf = eina_strbuf_string_get(sd->format_strbuf);
|
||||
eina_value_flush(&val);
|
||||
|
||||
if (buf)
|
||||
elm_layout_text_set(sd->obj, "month_text", buf);
|
||||
else
|
||||
elm_layout_text_set(sd->obj, "month_text", "");
|
||||
}
|
||||
else
|
||||
{
|
||||
char *buf;
|
||||
buf = eina_strftime(E_("%B %Y"), &sd->shown_date);
|
||||
if (buf)
|
||||
{
|
||||
elm_layout_text_set(sd->obj, "month_text", buf);
|
||||
free(buf);
|
||||
}
|
||||
else elm_layout_text_set(sd->obj, "month_text", "");
|
||||
}
|
||||
else elm_layout_text_set(sd->obj, "month_text", "");
|
||||
|
||||
sd->filling = EINA_FALSE;
|
||||
}
|
||||
|
@ -504,7 +517,7 @@ _efl_ui_calendar_elm_widget_theme_apply(Eo *obj, Efl_Ui_Calendar_Data *sd)
|
|||
static inline Eina_Bool
|
||||
_fix_date(Efl_Ui_Calendar_Data *sd)
|
||||
{
|
||||
Eina_Bool fixed = EINA_FALSE;
|
||||
Eina_Bool no_change = EINA_TRUE;
|
||||
|
||||
if ((sd->date.tm_year < sd->date_min.tm_year) ||
|
||||
((sd->date.tm_year == sd->date_min.tm_year) &&
|
||||
|
@ -516,7 +529,7 @@ _fix_date(Efl_Ui_Calendar_Data *sd)
|
|||
sd->date.tm_year = sd->shown_date.tm_year = sd->date_min.tm_year;
|
||||
sd->date.tm_mon = sd->shown_date.tm_mon = sd->date_min.tm_mon;
|
||||
sd->date.tm_mday = sd->shown_date.tm_mday = sd->date_min.tm_mday;
|
||||
fixed = EINA_TRUE;
|
||||
no_change = EINA_FALSE;
|
||||
}
|
||||
else if ((sd->date_max.tm_year != -1) &&
|
||||
((sd->date.tm_year > sd->date_max.tm_year) ||
|
||||
|
@ -529,7 +542,7 @@ _fix_date(Efl_Ui_Calendar_Data *sd)
|
|||
sd->date.tm_year = sd->shown_date.tm_year = sd->date_max.tm_year;
|
||||
sd->date.tm_mon = sd->shown_date.tm_mon = sd->date_max.tm_mon;
|
||||
sd->date.tm_mday = sd->shown_date.tm_mday = sd->date_max.tm_mday;
|
||||
fixed = EINA_TRUE;
|
||||
no_change = EINA_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -539,7 +552,7 @@ _fix_date(Efl_Ui_Calendar_Data *sd)
|
|||
sd->date.tm_year = sd->shown_date.tm_year;
|
||||
}
|
||||
|
||||
return fixed;
|
||||
return no_change;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
|
@ -865,6 +878,9 @@ _efl_ui_calendar_efl_object_destructor(Eo *obj, Efl_Ui_Calendar_Data *sd)
|
|||
ecore_timer_del(sd->spin_year);
|
||||
ecore_timer_del(sd->update_timer);
|
||||
|
||||
efl_ui_format_cb_set(obj, NULL, NULL, NULL);
|
||||
eina_strbuf_free(sd->format_strbuf);
|
||||
|
||||
for (i = 0; i < ELM_DAY_LAST; i++)
|
||||
eina_stringshare_del(sd->weekdays[i]);
|
||||
|
||||
|
@ -943,7 +959,7 @@ _efl_ui_calendar_constructor_internal(Eo *obj, Efl_Ui_Calendar_Data *priv)
|
|||
priv->today_it = -1;
|
||||
priv->selected_it = -1;
|
||||
priv->first_day_it = -1;
|
||||
priv->format_func = _format_month_year;
|
||||
priv->format_cb = NULL;
|
||||
|
||||
edje_object_signal_callback_add
|
||||
(wd->resize_obj, "elm,action,selected", "*",
|
||||
|
@ -1161,9 +1177,20 @@ _efl_ui_calendar_date_get(Eo *obj EINA_UNUSED, Efl_Ui_Calendar_Data *sd)
|
|||
}
|
||||
|
||||
EOLIAN static void
|
||||
_efl_ui_calendar_format_function_set(Eo *obj EINA_UNUSED, Efl_Ui_Calendar_Data *sd, Efl_Ui_Calendar_Format_Cb format_function)
|
||||
_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)
|
||||
{
|
||||
sd->format_func = format_function;
|
||||
if ((sd->format_cb_data == func_data) && (sd->format_cb == func))
|
||||
return;
|
||||
|
||||
if (sd->format_cb_data && sd->format_free_cb)
|
||||
sd->format_free_cb(sd->format_cb_data);
|
||||
|
||||
sd->format_cb = func;
|
||||
sd->format_cb_data = func_data;
|
||||
sd->format_free_cb = func_free_cb;
|
||||
if (!sd->format_strbuf) sd->format_strbuf = eina_strbuf_new();
|
||||
|
||||
evas_object_smart_changed(obj);
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
|
|
|
@ -18,7 +18,7 @@ enum Efl.Ui.Calendar.Weekday
|
|||
last [[Sentinel value to indicate last enum field during iteration]]
|
||||
}
|
||||
|
||||
class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.Atspi_Widget_Action)
|
||||
class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.Atspi_Widget_Action, Efl.Ui.Format)
|
||||
{
|
||||
[[Calendar widget
|
||||
|
||||
|
@ -37,36 +37,6 @@ class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.At
|
|||
day: Efl.Ui.Calendar.Weekday(Efl.Ui.Calendar.Weekday.sunday); [[Weekday enum value, see @Elm.Calendar.Weekday]]
|
||||
}
|
||||
}
|
||||
@property format_function {
|
||||
set {
|
||||
[[Set a function to format the string that will be used to display
|
||||
month and year;
|
||||
|
||||
By default it uses strftime with "%B %Y" format string.
|
||||
It should allocate the memory that will be used by the string,
|
||||
that will be freed by the widget after usage.
|
||||
A pointer to the string and a pointer to the time struct will be provided.
|
||||
]]
|
||||
/* FIXME-doc
|
||||
* Example:
|
||||
* @code
|
||||
* static char
|
||||
* _format_month_year(struct tm *selected_time)
|
||||
* {
|
||||
* char buf[32];
|
||||
* if (!strftime(buf, sizeof(buf), "%B %Y", selected_time)) return NULL;
|
||||
* return strdup(buf);
|
||||
* }
|
||||
*
|
||||
* efl_ui_calendar_format_function_set(calendar, _format_month_year);
|
||||
* @endcode
|
||||
*/
|
||||
}
|
||||
values {
|
||||
format_function: Efl_Ui_Calendar_Format_Cb; [[Function to set the month-year string given
|
||||
the selected date.]]
|
||||
}
|
||||
}
|
||||
@property date_min {
|
||||
[[Minimum date on calendar.]]
|
||||
set {
|
||||
|
@ -121,9 +91,9 @@ class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.At
|
|||
[[Set the selected date. If the date is greater than the maximum date,
|
||||
the date would be changed to the maximum date with returning $false.
|
||||
In the opposite case with the minimum date,
|
||||
this would give the same result.
|
||||
this would give the same result.
|
||||
]]
|
||||
return: bool; [[$true, on success, $false otherwise]]
|
||||
return: bool; [[$true, on success, $false otherwise]]
|
||||
}
|
||||
get {
|
||||
}
|
||||
|
@ -142,6 +112,7 @@ class Efl.Ui.Calendar (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface.At
|
|||
Elm.Widget.on_focus_update;
|
||||
Elm.Widget.widget_event;
|
||||
Elm.Interface.Atspi_Widget_Action.elm_actions { get; }
|
||||
Efl.Ui.Format.format_cb { set; }
|
||||
}
|
||||
events {
|
||||
changed; [[Emitted when the selected date in the calendar is changed]]
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
#include "efl_ui_calendar_common.h"
|
||||
#ifdef EFL_EO_API_SUPPORT
|
||||
#include "efl_ui_calendar.eo.h"
|
||||
#endif
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
/**
|
||||
* @addtogroup Elm_Calendar
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* This callback type is used to format the string that will be used
|
||||
* to display month and year.
|
||||
*
|
||||
* @param stime Struct representing time.
|
||||
* @return String representing time that will be set to calendar's text.
|
||||
*
|
||||
* @see elm_calendar_format_function_set()
|
||||
*/
|
||||
typedef char * (*Efl_Ui_Calendar_Format_Cb)(struct tm *stime);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -32,7 +32,6 @@ struct _Efl_Ui_Calendar_Data
|
|||
int spin_speed;
|
||||
int today_it, selected_it, focused_it;
|
||||
Ecore_Timer *spin_month, *spin_year, *update_timer;
|
||||
Efl_Ui_Calendar_Format_Cb format_func;
|
||||
const char *weekdays[ELM_DAY_LAST];
|
||||
struct tm current_date, shown_date, date, date_min, date_max;
|
||||
Evas_Object *inc_btn_month;
|
||||
|
@ -44,9 +43,13 @@ struct _Efl_Ui_Calendar_Data
|
|||
Eo *items[42];
|
||||
|
||||
Efl_Ui_Calendar_Weekday first_week_day;
|
||||
|
||||
unsigned char first_day_it;
|
||||
|
||||
Efl_Ui_Format_Func_Cb format_cb;
|
||||
Eina_Free_Cb format_free_cb;
|
||||
void *format_cb_data;
|
||||
Eina_Strbuf *format_strbuf;
|
||||
|
||||
Eina_Bool selected : 1;
|
||||
Eina_Bool double_spinners : 1;
|
||||
Eina_Bool filling : 1;
|
||||
|
|
Loading…
Reference in New Issue