#include <Elementary.h>
#include "elm_priv.h"
-/**
- * @defgroup Calendar
- *
- * A calendar is a widget that allows the user to select a date. It has
- * support to adding check marks (holidays and checks by default). The calendar
- * is displayed one month at a time.
- *
- * Weekday names and the function used to format month and year to
- * be displayed can be set, giving more flexibility to this widget.
- *
- * Signals that you can add callbacks for are:
- *
- * changed - emitted when the user selects a day or changes the displayed
- * month, what actually changes the selected day as well.
- */
-
typedef enum _Day_Color // EINA_DEPRECATED
{
- DAY_WEEKDAY = 0,
- DAY_SATURDAY = 1,
- DAY_SUNDAY = 2
+ DAY_WEEKDAY = 0,
+ DAY_SATURDAY = 1,
+ DAY_SUNDAY = 2
} Day_Color;
typedef struct _Widget_Data Widget_Data;
double interval, first_interval;
int year_min, year_max, spin_speed;
int today_it, selected_it, first_day_it;
+ Elm_Calendar_Weekday first_week_day;
Ecore_Timer *spin, *update_timer;
- char * (*format_func) (struct tm *stime);
- const char *weekdays[7];
+ Elm_Calendar_Format_Cb format_func;
+ const char *weekdays[ELM_DAY_LAST];
struct tm current_time, selected_time;
Day_Color day_color[42]; // EINA_DEPRECATED
- Eina_Bool selection_enabled : 1;
+ Elm_Calendar_Select_Mode select_mode;
};
struct _Elm_Calendar_Mark
Eina_List *node;
struct tm mark_time;
const char *mark_type;
- Elm_Calendar_Mark_Repeat repeat;
+ Elm_Calendar_Mark_Repeat_Type repeat;
};
static const char *widtype = NULL;
static void _on_focus_hook(void *data, Evas_Object *obj);
static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
+static const char SIG_CHANGED[] = "changed";
+
+static const Evas_Smart_Cb_Description _signals[] = {
+ {SIG_CHANGED, ""},
+ {NULL, NULL}
+};
+
+
+/* Should not be translated, it's used if we failed
+ * getting from locale. */
static const char *_days_abbrev[] =
{
"Sun", "Mon", "Tue", "Wed",
static int _days_in_month[2][12] =
{
- {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
- {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
+ {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
+ {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
static Elm_Calendar_Mark *
-_mark_new(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat repeat)
+_mark_new(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat_Type repeat)
{
Widget_Data *wd = elm_widget_data_get(obj);
Elm_Calendar_Mark *mark;
}
static inline int
-_maxdays_get(struct tm *time)
+_maxdays_get(struct tm *selected_time)
{
int month, year;
- month = time->tm_mon;
- year = time->tm_year + 1900;
+ month = selected_time->tm_mon;
+ year = selected_time->tm_year + 1900;
- return _days_in_month[((!(year % 4)) &&
- ((!(year % 400)) ||
- (year % 100)))]
- [month];
+ return _days_in_month[((!(year % 4)) &&
+ ((!(year % 400)) ||
+ (year % 100)))]
+ [month];
}
static inline void
}
static char *
-_format_month_year(struct tm *stime)
+_format_month_year(struct tm *selected_time)
{
char buf[32];
- if (!strftime(buf, sizeof(buf), "%B %Y", stime)) return NULL;
+ if (!strftime(buf, sizeof(buf), E_("%B %Y"), selected_time)) return NULL;
return strdup(buf);
}
static inline int
_weekday_get(int first_week_day, int day)
{
- return (day + first_week_day - 1) % 7;
+ return (day + first_week_day - 1) % ELM_DAY_LAST;
}
// EINA_DEPRECATED
_text_day_color_update(Widget_Data *wd, int pos)
{
char emission[32];
-
+
switch (wd->day_color[pos])
- {
- case DAY_WEEKDAY:
- snprintf(emission, sizeof(emission), "cit_%i,weekday", pos);
- break;
- case DAY_SATURDAY:
- snprintf(emission, sizeof(emission), "cit_%i,saturday", pos);
- break;
- case DAY_SUNDAY:
- snprintf(emission, sizeof(emission), "cit_%i,sunday", pos);
- break;
- default:
- return;
- }
-
+ {
+ case DAY_WEEKDAY:
+ snprintf(emission, sizeof(emission), "cit_%i,weekday", pos);
+ break;
+ case DAY_SATURDAY:
+ snprintf(emission, sizeof(emission), "cit_%i,saturday", pos);
+ break;
+ case DAY_SUNDAY:
+ snprintf(emission, sizeof(emission), "cit_%i,sunday", pos);
+ break;
+ default:
+ return;
+ }
+
edje_object_signal_emit(wd->calendar, emission, "elm");
}
-// EINA_DEPRECATED
static void
-_text_day_color_set(Widget_Data *wd, Day_Color col, int pos)
+_set_month_year(Widget_Data *wd)
{
- if ((pos < 0) || (pos >= 42)) return;
- if (wd->day_color[pos] == col) return;
- wd->day_color[pos] = col;
- _text_day_color_update(wd, pos);
+ char *buf;
+
+ /* Set selected month */
+ buf = wd->format_func(&wd->selected_time);
+ if (buf)
+ {
+ edje_object_part_text_escaped_set(wd->calendar, "month_text", buf);
+ free(buf);
+ }
+ else
+ edje_object_part_text_escaped_set(wd->calendar, "month_text", "");
}
static void
_populate(Evas_Object *obj)
{
- int maxdays, day, mon, year, i;
+ int maxdays, day, mon, yr, i;
Elm_Calendar_Mark *mark;
char part[12], day_s[3];
struct tm first_day;
Eina_List *l;
- char *buf;
Eina_Bool last_row = EINA_TRUE;
Widget_Data *wd = elm_widget_data_get(obj);
maxdays = _maxdays_get(&wd->selected_time);
mon = wd->selected_time.tm_mon;
- year = wd->selected_time.tm_year;
+ yr = wd->selected_time.tm_year;
- /* Set selected month */
- buf = wd->format_func(&wd->selected_time);
- if (buf)
- {
- edje_object_part_text_set(wd->calendar, "month_text", buf);
- free(buf);
- }
- else
- edje_object_part_text_set(wd->calendar, "month_text", "");
+ _set_month_year(wd);
/* Set days */
day = 0;
mktime(&first_day);
// Layout of the calendar is changed for removing the unfilled last row.
- wd->first_day_it = first_day.tm_wday;
-
- if ((35 - wd->first_day_it) > (maxdays - 1)) last_row = EINA_FALSE;
-
- if (!last_row)
- {
- char emission[32];
-
- for (i = 0; i < 5; i++)
- {
- snprintf(emission, sizeof(emission), "cseph_%i,row_hide", i);
- edje_object_signal_emit(wd->calendar, emission, "elm");
- }
- snprintf(emission, sizeof(emission), "cseph_%i,row_invisible", 5);
- edje_object_signal_emit(wd->calendar, emission, "elm");
- for (i = 0; i < 35; i++)
- {
- snprintf(emission, sizeof(emission), "cit_%i,cell_expanded", i);
- edje_object_signal_emit(wd->calendar, emission, "elm");
- }
- for (i = 35; i < 42; i++)
- {
- snprintf(emission, sizeof(emission), "cit_%i,cell_invisible", i);
- edje_object_signal_emit(wd->calendar, emission, "elm");
- }
- }
- else
- {
- char emission[32];
-
- for (i = 0; i < 6; i++)
- {
- snprintf(emission, sizeof(emission), "cseph_%i,row_show", i);
- edje_object_signal_emit(wd->calendar, emission, "elm");
- }
- for (i = 0; i < 42; i++)
- {
- snprintf(emission, sizeof(emission), "cit_%i,cell_default", i);
- edje_object_signal_emit(wd->calendar, emission, "elm");
- }
- }
-
+ if (first_day.tm_wday < (int)wd->first_week_day)
+ wd->first_day_it = first_day.tm_wday + ELM_DAY_LAST - wd->first_week_day;
+ else
+ wd->first_day_it = first_day.tm_wday - wd->first_week_day;
+
+ if ((35 - wd->first_day_it) > (maxdays - 1)) last_row = EINA_FALSE;
+
+ if (!last_row)
+ {
+ char emission[32];
+
+ for (i = 0; i < 5; i++)
+ {
+ snprintf(emission, sizeof(emission), "cseph_%i,row_hide", i);
+ edje_object_signal_emit(wd->calendar, emission, "elm");
+ }
+ snprintf(emission, sizeof(emission), "cseph_%i,row_invisible", 5);
+ edje_object_signal_emit(wd->calendar, emission, "elm");
+ for (i = 0; i < 35; i++)
+ {
+ snprintf(emission, sizeof(emission), "cit_%i,cell_expanded", i);
+ edje_object_signal_emit(wd->calendar, emission, "elm");
+ }
+ for (i = 35; i < 42; i++)
+ {
+ snprintf(emission, sizeof(emission), "cit_%i,cell_invisible", i);
+ edje_object_signal_emit(wd->calendar, emission, "elm");
+ }
+ }
+ else
+ {
+ char emission[32];
+
+ for (i = 0; i < 6; i++)
+ {
+ snprintf(emission, sizeof(emission), "cseph_%i,row_show", i);
+ edje_object_signal_emit(wd->calendar, emission, "elm");
+ }
+ for (i = 0; i < 42; i++)
+ {
+ snprintf(emission, sizeof(emission), "cit_%i,cell_default", i);
+ edje_object_signal_emit(wd->calendar, emission, "elm");
+ }
+ }
+
for (i = 0; i < 42; i++)
{
_text_day_color_update(wd, i); // EINA_DEPRECATED
- if ((!day) && (i == first_day.tm_wday)) day = 1;
+ if ((!day) && (i == wd->first_day_it)) day = 1;
- if ((day == wd->current_time.tm_mday)
- && (mon == wd->current_time.tm_mon)
- && (year == wd->current_time.tm_year))
- _today(wd, i);
+ if ((day == wd->current_time.tm_mday)
+ && (mon == wd->current_time.tm_mon)
+ && (yr == wd->current_time.tm_year))
+ _today(wd, i);
- if (day == wd->selected_time.tm_mday)
- {
- if ((wd->selected_it > -1) && (wd->selected_it != i))
- _unselect(wd, wd->selected_it);
+ if (day == wd->selected_time.tm_mday)
+ {
+ if ((wd->selected_it > -1) && (wd->selected_it != i))
+ _unselect(wd, wd->selected_it);
- if (wd->selection_enabled) _select(wd, i);
+ if (wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE)
+ _select(wd, i);
- wd->selected_it = i;
- }
+ wd->selected_it = i;
+ }
- if ((day) && (day <= maxdays))
- snprintf(day_s, sizeof(day_s), "%i", day++);
- else
+ if ((day) && (day <= maxdays))
+ snprintf(day_s, sizeof(day_s), "%i", day++);
+ else
day_s[0] = 0;
- snprintf(part, sizeof(part), "cit_%i.text", i);
- edje_object_part_text_set(wd->calendar, part, day_s);
- /* Clear previous marks */
- _cit_mark(wd->calendar, i, "clear");
+ snprintf(part, sizeof(part), "cit_%i.text", i);
+ edje_object_part_text_set(wd->calendar, part, day_s);
+ /* Clear previous marks */
+ _cit_mark(wd->calendar, i, "clear");
}
/* Set marks */
EINA_LIST_FOREACH(wd->marks, l, mark)
{
- struct tm *mtime = &mark->mark_time;
- int mon = wd->selected_time.tm_mon;
- int year = wd->selected_time.tm_year;
- int mday_it = mtime->tm_mday + wd->first_day_it - 1;
-
- switch (mark->repeat)
- {
- case ELM_CALENDAR_UNIQUE:
- if ((mtime->tm_mon == mon) && (mtime->tm_year == year))
- _cit_mark(wd->calendar, mday_it, mark->mark_type);
- break;
- case ELM_CALENDAR_DAILY:
- if (((mtime->tm_year == year) && (mtime->tm_mon < mon)) ||
- (mtime->tm_year < year))
- day = 1;
- else if ((mtime->tm_year == year) && (mtime->tm_mon == mon))
- day = mtime->tm_mday;
- else
- break;
- for (; day <= maxdays; day++)
- _cit_mark(wd->calendar, day + wd->first_day_it - 1,
- mark->mark_type);
- break;
- case ELM_CALENDAR_WEEKLY:
- if (((mtime->tm_year == year) && (mtime->tm_mon < mon)) ||
- (mtime->tm_year < year))
- day = 1;
- else if ((mtime->tm_year == year) && (mtime->tm_mon == mon))
- day = mtime->tm_mday;
- else
- break;
- for (; day <= maxdays; day++)
- if (mtime->tm_wday == _weekday_get(wd->first_day_it, day))
- _cit_mark(wd->calendar, day + wd->first_day_it - 1,
- mark->mark_type);
- break;
- case ELM_CALENDAR_MONTHLY:
- if (((mtime->tm_year < year) ||
- ((mtime->tm_year == year) && (mtime->tm_mon <= mon))) &&
- (mtime->tm_mday <= maxdays))
- _cit_mark(wd->calendar, mday_it, mark->mark_type);
- break;
- case ELM_CALENDAR_ANNUALLY:
- if ((mtime->tm_year <= year) && (mtime->tm_mon == mon) &&
- (mtime->tm_mday <= maxdays))
- _cit_mark(wd->calendar, mday_it, mark->mark_type);
- break;
- }
+ struct tm *mtime = &mark->mark_time;
+ int month = wd->selected_time.tm_mon;
+ int year = wd->selected_time.tm_year;
+ int mday_it = mtime->tm_mday + wd->first_day_it - 1;
+
+ switch (mark->repeat)
+ {
+ case ELM_CALENDAR_UNIQUE:
+ if ((mtime->tm_mon == month) && (mtime->tm_year == year))
+ _cit_mark(wd->calendar, mday_it, mark->mark_type);
+ break;
+ case ELM_CALENDAR_DAILY:
+ if (((mtime->tm_year == year) && (mtime->tm_mon < month)) ||
+ (mtime->tm_year < year))
+ day = 1;
+ else if ((mtime->tm_year == year) && (mtime->tm_mon == month))
+ day = mtime->tm_mday;
+ else
+ break;
+ for (; day <= maxdays; day++)
+ _cit_mark(wd->calendar, day + wd->first_day_it - 1,
+ mark->mark_type);
+ break;
+ case ELM_CALENDAR_WEEKLY:
+ if (((mtime->tm_year == year) && (mtime->tm_mon < month)) ||
+ (mtime->tm_year < year))
+ day = 1;
+ else if ((mtime->tm_year == year) && (mtime->tm_mon == month))
+ day = mtime->tm_mday;
+ else
+ break;
+ for (; day <= maxdays; day++)
+ if (mtime->tm_wday == _weekday_get(wd->first_day_it, day))
+ _cit_mark(wd->calendar, day + wd->first_day_it - 1,
+ mark->mark_type);
+ break;
+ case ELM_CALENDAR_MONTHLY:
+ if (((mtime->tm_year < year) ||
+ ((mtime->tm_year == year) && (mtime->tm_mon <= month))) &&
+ (mtime->tm_mday <= maxdays))
+ _cit_mark(wd->calendar, mday_it, mark->mark_type);
+ break;
+ case ELM_CALENDAR_ANNUALLY:
+ if ((mtime->tm_year <= year) && (mtime->tm_mon == month) &&
+ (mtime->tm_mday <= maxdays))
+ _cit_mark(wd->calendar, mday_it, mark->mark_type);
+ break;
+ }
}
}
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
- for (i = 0; i < 7; i++)
+ for (i = 0; i < ELM_DAY_LAST; i++)
{
- part[3] = i + '0';
- edje_object_part_text_set(wd->calendar, part, wd->weekdays[i]);
+ part[3] = i + '0';
+ edje_object_part_text_escaped_set
+ (wd->calendar, part,
+ wd->weekdays[(i + wd->first_week_day) % ELM_DAY_LAST]);
}
}
if (wd->marks)
{
- EINA_LIST_FREE(wd->marks, mark)
- {
- _mark_free(mark);
- }
+ EINA_LIST_FREE(wd->marks, mark)
+ {
+ _mark_free(mark);
+ }
}
- for (i = 0; i < 7; i++)
+ for (i = 0; i < ELM_DAY_LAST; i++)
eina_stringshare_del(wd->weekdays[i]);
free(wd);
if (!wd) return;
if (elm_widget_focus_get(obj))
{
- edje_object_signal_emit(wd->calendar, "elm,action,focus", "elm");
- evas_object_focus_set(wd->calendar, EINA_TRUE);
+ edje_object_signal_emit(wd->calendar, "elm,action,focus", "elm");
+ evas_object_focus_set(wd->calendar, EINA_TRUE);
}
else
{
- edje_object_signal_emit(wd->calendar, "elm,action,unfocus", "elm");
- evas_object_focus_set(wd->calendar, EINA_FALSE);
+ edje_object_signal_emit(wd->calendar, "elm,action,unfocus", "elm");
+ evas_object_focus_set(wd->calendar, EINA_FALSE);
}
}
}
static void
-_signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
+_signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
{
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
}
static void
-_signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
+_signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
{
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
wd->selected_time.tm_mon += delta;
if (wd->selected_time.tm_mon < 0)
{
- if (wd->selected_time.tm_year == wd->year_min)
- {
- wd->selected_time.tm_mon++;
- return EINA_FALSE;
- }
- wd->selected_time.tm_mon = 11;
- wd->selected_time.tm_year--;
+ if (wd->selected_time.tm_year == wd->year_min)
+ {
+ wd->selected_time.tm_mon++;
+ return EINA_FALSE;
+ }
+ wd->selected_time.tm_mon = 11;
+ wd->selected_time.tm_year--;
}
else if (wd->selected_time.tm_mon > 11)
{
- if (wd->selected_time.tm_year == wd->year_max)
- {
- wd->selected_time.tm_mon--;
- return EINA_FALSE;
- }
- wd->selected_time.tm_mon = 0;
- wd->selected_time.tm_year++;
+ if (wd->selected_time.tm_year == wd->year_max)
+ {
+ wd->selected_time.tm_mon--;
+ return EINA_FALSE;
+ }
+ wd->selected_time.tm_mon = 0;
+ wd->selected_time.tm_year++;
}
maxdays = _maxdays_get(&wd->selected_time);
wd->selected_time.tm_mday = maxdays;
_fix_selected_time(wd);
- evas_object_smart_callback_call(obj, "changed", NULL);
+ evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
return EINA_TRUE;
}
{
int day;
Widget_Data *wd = elm_widget_data_get(obj);
- if ((!wd) || (!wd->selection_enabled))
- return;
+ if ((!wd) || (wd->select_mode == ELM_CALENDAR_SELECT_MODE_NONE))
+ return;
day = _get_item_day(obj, sel_it);
if (!day)
wd->selected_time.tm_mday = day;
_select(wd, wd->selected_it);
_fix_selected_time(wd);
- evas_object_smart_callback_call(obj, "changed", NULL);
+ evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
}
static void
{
int sel_it;
Widget_Data *wd = elm_widget_data_get(data);
- if ((!wd) || (!wd->selection_enabled))
- return;
+ if ((!wd) || (wd->select_mode == ELM_CALENDAR_SELECT_MODE_NONE))
+ return;
sel_it = atoi(source);
_update_sel_it(data, sel_it);
static inline int
_time_to_next_day(struct tm *t)
{
- return ((((24 - t->tm_hour) * 60) - t->tm_min) * 60) - t->tm_sec;
+ return ((((24 - t->tm_hour) * 60) - t->tm_min) * 60) - t->tm_sec;
}
static Eina_Bool
ecore_timer_interval_set(wd->update_timer, t);
if ((wd->current_time.tm_mon != wd->selected_time.tm_mon) ||
- (wd->current_time.tm_year!= wd->selected_time.tm_year))
+ (wd->current_time.tm_year!= wd->selected_time.tm_year))
return ECORE_CALLBACK_RENEW;
day = wd->current_time.tm_mday + wd->first_day_it - 1;
if (!wd) return EINA_FALSE;
if (elm_widget_disabled_get(obj)) return EINA_FALSE;
- if (!wd->selection_enabled) return EINA_FALSE;
+ if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_NONE) return EINA_FALSE;
if ((!strcmp(ev->keyname, "Left")) ||
- (!strcmp(ev->keyname, "KP_Left")))
+ ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
{
_update_sel_it(obj, wd->selected_it-1);
}
else if ((!strcmp(ev->keyname, "Right")) ||
- (!strcmp(ev->keyname, "KP_Right")))
+ ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
{
_update_sel_it(obj, wd->selected_it+1);
}
else if ((!strcmp(ev->keyname, "Up")) ||
- (!strcmp(ev->keyname, "KP_Up")))
+ ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
{
- _update_sel_it(obj, wd->selected_it-7);
+ _update_sel_it(obj, wd->selected_it-ELM_DAY_LAST);
}
else if ((!strcmp(ev->keyname, "Down")) ||
- (!strcmp(ev->keyname, "KP_Down")))
+ ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
{
- _update_sel_it(obj, wd->selected_it+7);
+ _update_sel_it(obj, wd->selected_it+ELM_DAY_LAST);
}
else if ((!strcmp(ev->keyname, "Prior")) ||
- (!strcmp(ev->keyname, "KP_Prior")))
+ ((!strcmp(ev->keyname, "KP_Prior")) && (!ev->string)))
{
if (_update_month(obj, -1)) _populate(obj);
}
else if ((!strcmp(ev->keyname, "Next")) ||
- (!strcmp(ev->keyname, "KP_Next")))
+ ((!strcmp(ev->keyname, "KP_Next")) && (!ev->string)))
{
if (_update_month(obj, 1)) _populate(obj);
}
return EINA_TRUE;
}
-/**
- * Add a new calendar to the parent
- *
- * @param parent The parent object
- * @return The new object or NULL if it cannot be created
- *
- * @ingroup Calendar
- */
EAPI Evas_Object *
elm_calendar_add(Evas_Object *parent)
{
time_t current_time;
+ time_t weekday = 259200; /* Just the first sunday since epoch */
Evas_Object *obj;
Widget_Data *wd;
int i, t;
Evas *e;
- EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
+ ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
- wd = ELM_NEW(Widget_Data);
- e = evas_object_evas_get(parent);
- if (!e) return NULL;
- obj = elm_widget_add(e);
ELM_SET_WIDTYPE(widtype, "calendar");
elm_widget_type_set(obj, "calendar");
elm_widget_sub_object_add(parent, obj);
wd->today_it = -1;
wd->selected_it = -1;
wd->first_day_it = -1;
- wd->selection_enabled = EINA_TRUE;
wd->format_func = _format_month_year;
wd->marks = NULL;
edje_object_signal_callback_add(wd->calendar, "elm,action,selected",
"*", _day_selected, obj);
- for (i = 0; i < 7; i++)
- wd->weekdays[i] = eina_stringshare_add(_days_abbrev[i]);
+ evas_object_smart_callbacks_descriptions_set(obj, _signals);
+
+ for (i = 0; i < ELM_DAY_LAST; i++)
+ {
+ /* FIXME: I'm not aware of a known max, so if it fails,
+ * just make it larger. :| */
+ char buf[20];
+ /* I don't know of a better way of doing it */
+ if (strftime(buf, sizeof(buf), "%a", gmtime(&weekday)))
+ {
+ wd->weekdays[i] = eina_stringshare_add(buf);
+ }
+ else
+ {
+ /* If we failed getting day, get a default value */
+ wd->weekdays[i] = _days_abbrev[i];
+ WRN("Failed getting weekday name for '%s' from locale.",
+ _days_abbrev[i]);
+ }
+ weekday += 86400; /* Advance by a day */
+ }
current_time = time(NULL);
localtime_r(¤t_time, &wd->selected_time);
return obj;
}
-/**
- * Set weekdays names to display in the calendar.
- *
- * By default, the following abbreviations are displayed:
- * "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
- * The first string should be related to Sunday, the second to Monday...
- *
- * The usage should be like this:
- * @code
- * const char *weekdays[] =
- * {
- * "Sunday", "Monday", "Tuesday", "Wednesday",
- * "Thursday", "Friday", "Saturday"
- * };
- * elm_calendar_weekdays_names_set(calendar, weekdays);
- * @endcode
- *
- * @param obj The calendar object
- * @param weedays Array of seven strings to be used as weekday names.
- * Warning: it must have 7 elements, or it will access invalid memory.
- * The strings must be NULL terminated ('@\0').
- *
- * @ingroup Calendar
- */
EAPI void
elm_calendar_weekdays_names_set(Evas_Object *obj, const char *weekdays[])
{
EINA_SAFETY_ON_NULL_RETURN(weekdays);
- for (i = 0; i < 7; i++)
+ for (i = 0; i < ELM_DAY_LAST; i++)
{
eina_stringshare_replace(&wd->weekdays[i], weekdays[i]);
}
_set_headers(obj);
}
-/**
- * Get weekdays names displayed in the calendar.
- *
- * By default, the following abbreviations are displayed:
- * "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
- * The first string is related to Sunday, the second to Monday...
- *
- * @param obj The calendar object
- * @return Array of seven strings to used as weekday names.
- *
- * @ingroup Calendar
- */
EAPI const char **
elm_calendar_weekdays_names_get(const Evas_Object *obj)
{
return wd->weekdays;
}
-/**
- * Set the interval for the calendar
- *
- * The interval value is decreased while the user increments or decrements
- * the calendar value. The next interval value is the previous interval / 1.05,
- * so it speed up a bit. Default value is 0.85 seconds.
- *
- * @param obj The calendar object
- * @param interval The interval value in seconds
- *
- * @ingroup Calendar
- */
EAPI void
elm_calendar_interval_set(Evas_Object *obj, double interval)
{
wd->first_interval = interval;
}
-/**
- * Get the interval of the calendar
- *
- * The interval value is decreased while the user increments or decrements
- * the calendar value. The next interval value is the previous interval / 1.05,
- * so it speed up a bit. Default value is 0.85 seconds.
- *
- * @param obj The calendar object
- * @return The value of the first interval in seconds
- *
- * @ingroup Calendar
- */
EAPI double
elm_calendar_interval_get(const Evas_Object *obj)
{
return wd->first_interval;
}
-/**
- * Set the minimum and maximum values for the year
- *
- * Maximum must be greater than minimum, except if you don't wan't to set
- * maximum year.
- * Default values are 1902 and -1.
- *
- * If the maximum year is a negative value, it will be limited depending of the
- * platform architecture (2037 for 32 bits);
- *
- * @param obj The calendar object
- * @param min The minimum year, greater than 1901;
- * @param max The maximum year;
- *
- * @ingroup Calendar
- */
EAPI void
elm_calendar_min_max_year_set(Evas_Object *obj, int min, int max)
{
max -= 1900;
if ((wd->year_min == min) && (wd->year_max == max)) return;
wd->year_min = min > 2 ? min : 2;
- wd->year_max = max;
+ if (max > wd->year_min)
+ wd->year_max = max;
+ else
+ wd->year_max = wd->year_min;
if (wd->selected_time.tm_year > wd->year_max)
wd->selected_time.tm_year = wd->year_max;
if (wd->selected_time.tm_year < wd->year_min)
_populate(obj);
}
-/**
- * Get the minimum and maximum values for the year
- *
- * Default values are 1902 and -1.
- *
- * If the maximum year is a negative value, it will be limited depending of the
- * platform architecture (2037 for 32 bits);
- *
- * @param obj The calendar object
- * @param min The minimum year
- * @param max The maximum year
- *
- * @ingroup Calendar
- */
EAPI void
elm_calendar_min_max_year_get(const Evas_Object *obj, int *min, int *max)
{
if (max) *max = wd->year_max + 1900;
}
-/**
- * Enable or disable day selection
- *
- * Enabled by default. If disabled, the user can select months, but not days.
- * It should be used if you won't need such selection for the widget usage.
- *
- * @param obj The calendar object
- * @param enabled Boolean to enable (true) or disable (false) day selection
- *
- * @ingroup Calendar
- */
-EAPI void
-elm_calendar_day_selection_enabled_set(Evas_Object *obj, Eina_Bool enabled)
+EINA_DEPRECATED EAPI void
+elm_calendar_day_selection_disabled_set(Evas_Object *obj, Eina_Bool disabled)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return;
- wd->selection_enabled = enabled;
- if (enabled)
- _select(wd, wd->selected_it);
+ if (disabled)
+ elm_calendar_select_mode_set(obj, ELM_CALENDAR_SELECT_MODE_NONE);
else
- _unselect(wd, wd->selected_it);
+ elm_calendar_select_mode_set(obj, ELM_CALENDAR_SELECT_MODE_DEFAULT);
}
-/**
- * Get day selection state
- *
- * Enabled by default. If disabled, the user can select months, but not days.
- * It should be used if you won't need such selection for the widget usage.
- *
- * @param obj The calendar object
- * @return True if day selection is enabled, or false otherwise. It will
- * return false if it can't get widget data.
- *
- * @ingroup Calendar
- */
-EAPI Eina_Bool
-elm_calendar_day_selection_enabled_get(const Evas_Object *obj)
+EINA_DEPRECATED EAPI Eina_Bool
+elm_calendar_day_selection_disabled_get(const Evas_Object *obj)
{
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return EINA_FALSE;
- return wd->selection_enabled;
+ return !!(wd->select_mode == ELM_CALENDAR_SELECT_MODE_NONE);
}
-/**
- * Set selected time
- *
- * Set the time selected, changing the displayed month if needed.
- * Selected time changes when the user changes the month or select a day.
- *
- * @param obj The calendar object
- * @param selected_time A tm struct to represent the selected date
- *
- * @ingroup Calendar
- */
EAPI void
elm_calendar_selected_time_set(Evas_Object *obj, struct tm *selected_time)
{
return;
}
-/**
- * Get selected time
- *
- * Get the time selected by the user.
- * Selected time changes when the user changes the month or select a day.
- *
- * @param obj The calendar object
- * @param selected_time A tm struct to represent the selected date
- * @return It will return false if it can't get widget data, or true otherwise
- *
- * @ingroup Calendar
- */
EAPI Eina_Bool
elm_calendar_selected_time_get(const Evas_Object *obj, struct tm *selected_time)
{
return EINA_TRUE;
}
-/**
- * Set a function to format the string that will be used to display
- * month - 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.
- *
- * Example:
- * @code
- * static char *
- * _format_month_year(struct tm *stime)
- * {
- * char buf[32];
- * if (!strftime(buf, sizeof(buf), "%B %Y", stime)) return NULL;
- * return strdup(buf);
- * }
- * elm_calendar_format_function_set(calendar, _format_month_year);
- * @endcode
- *
- * @param obj The calendar object
- * @param format_function Function to set the month-year string given
- * the selected date
- *
- * @ingroup Calendar
- */
EAPI void
-elm_calendar_format_function_set(Evas_Object *obj, char * (*format_function) (struct tm *stime))
+elm_calendar_format_function_set(Evas_Object *obj, Elm_Calendar_Format_Cb format_function)
{
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
wd->format_func = format_function;
+ _set_month_year(wd);
}
-/**
- * Add a new mark to the calendar
- *
- * Add a mark that will be drawn in the calendar respecting the insertion time
- * and periodicity. It will emit the type as signal to the widget theme.
- * By default, it supports "holiday" and "checked", but it can be extended.
- *
- * It won't immediately update the calendar, drawing the marks. For this, call
- * elm_calendar_marks_draw().
- *
- * Example
- * @code
- * struct tm selected_time;
- * time_t current_time;
- *
- * current_time = time(NULL) + 5 * 84600;
- * localtime_r(¤t_time, &selected_time);
- * elm_calendar_mark_add(cal, "holiday", selected_time, ELM_CALENDAR_ANNUALLY);
- *
- * current_time = time(NULL) + 1 * 84600;
- * localtime_r(¤t_time, &selected_time);
- * elm_calendar_mark_add(cal, "checked", selected_time, ELM_CALENDAR_UNIQUE);
- *
- * elm_calendar_marks_draw(cal);
- * @endcode
- *
- * @param obj The calendar object
- * @param mark_type A string used to define the type of mark. It will be
- * emitted to the theme, that should display a related modification on these
- * days representation.
- * @param mark_time A time struct to represent the date of inclusion of the
- * mark. For marks that repeats it will just be displayed after the inclusion
- * date in the calendar.
- * @param repeat Repeat the event following this periodicity. Can be a unique
- * mark (that don't repeat), daily, weekly, monthly or annually.
- *
- * @return The created mark or NULL upon failure
- *
- * @ingroup Calendar
- */
EAPI Elm_Calendar_Mark *
-elm_calendar_mark_add(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat repeat)
+elm_calendar_mark_add(Evas_Object *obj, const char *mark_type, struct tm *mark_time, Elm_Calendar_Mark_Repeat_Type repeat)
{
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
Widget_Data *wd = elm_widget_data_get(obj);
return mark;
}
-/**
- * Delete mark from the calendar.
- *
- * @param mark The mark to delete
- *
- * @ingroup Calendar
- */
EAPI void
elm_calendar_mark_del(Elm_Calendar_Mark *mark)
{
_mark_free(mark);
}
-/**
- * Remove all the marks from the calendar
- *
- * @param obj The calendar object
- *
- * @ingroup Calendar
- */
EAPI void
elm_calendar_marks_clear(Evas_Object *obj)
{
_mark_free(mark);
}
-/**
- * Returns a list of all the calendar marks.
- *
- * @param obj The calendar object
- * @return An Eina_List* of the calendar marks, or NULL on failure
- *
- * @ingroup Calendar
- */
EAPI const Eina_List *
elm_calendar_marks_get(const Evas_Object *obj)
{
return wd->marks;
}
-/**
- * Draw calendar marks.
- *
- * Should be used after adding, removing or clearing marks.
- * It will go through the entire marks list updating the calendar
- * (not a cheap function). So if lots of marks will be added,
- * add all the marks and then call this function.
- *
- * When the month is changed marks will be drawed.
- *
- * @param obj The calendar object
- *
- * @ingroup Calendar
- */
EAPI void
elm_calendar_marks_draw(Evas_Object *obj)
{
_populate(obj);
}
-/**
- * Set a text color to the saturday color.
- *
- * Deprecated. use elm_calendar_mark_add() instead like:
- *
- * @code
- * struct tm t = { 0, 0, 12, 6, 0, 0, 5, 5, -1 };
- * elm_calendar_mark_add(obj, "sat", &t, ELM_CALENDAR_WEEKLY);
- * @endcode
- *
- * @param obj The calendar object
- * @param pos The text position
- *
- * @ingroup Calendar
- */
-EINA_DEPRECATED EAPI void
-elm_calendar_text_saturday_color_set(Evas_Object *obj, int pos)
+EAPI void
+elm_calendar_first_day_of_week_set(Evas_Object *obj, Elm_Calendar_Weekday day)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ if (day >= ELM_DAY_LAST) return;
+ if (wd->first_week_day != day)
+ {
+ wd->first_week_day = day;
+ _set_headers(obj);
+ _populate(obj);
+ }
+}
+
+EAPI Elm_Calendar_Weekday
+elm_calendar_first_day_of_week_get(const Evas_Object *obj)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return;
- _text_day_color_set(wd, DAY_SATURDAY, pos);
+ ELM_CHECK_WIDTYPE(obj, widtype) -1;
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return -1;
+ return wd->first_week_day;
}
-/**
- * Set a text color to the sunday color.
- *
- * Deprecated. use elm_calendar_mark_add() instead like:
- *
- * @code
- * struct tm t = { 0, 0, 12, 7, 0, 0, 6, 6, -1 };
- * elm_calendar_mark_add(obj, "sun", &t, ELM_CALENDAR_WEEKLY);
- * @endcode
- *
- * @param obj The calendar object
- * @param pos The text position
- *
- * @ingroup Calendar
- */
-EINA_DEPRECATED EAPI void
-elm_calendar_text_sunday_color_set(Evas_Object *obj, int pos)
+EAPI void
+elm_calendar_select_mode_set(Evas_Object *obj, Elm_Calendar_Select_Mode mode)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return;
- _text_day_color_set(wd, DAY_SUNDAY, pos);
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ if ((mode <= ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+ && (wd->select_mode != mode))
+ {
+ wd->select_mode = mode;
+ if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_ALWAYS)
+ _select(wd, wd->selected_it);
+ else
+ _unselect(wd, wd->selected_it);
+ }
}
-/**
- * Set a text color to the weekday color.
- *
- * Deprecated. use elm_calendar_mark_add() instead like:
- *
- * @code
- * struct tm t = { 0, 0, 12, 1, 0, 0, 0, 0, -1 };
- *
- * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // monday
- * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
- * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // tuesday
- * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
- * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // wednesday
- * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
- * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // thursday
- * t.tm_tm_mday++; t.tm_wday++; t.tm_yday++;
- * elm_calendar_mark_add(obj, "week", &t, ELM_CALENDAR_WEEKLY); // friday
- * @endcode
- *
- * @param obj The calendar object
- * @param pos The text position
- *
- * @ingroup Calendar
- */
-EINA_DEPRECATED EAPI void
-elm_calendar_text_weekday_color_set(Evas_Object *obj, int pos)
+EAPI Elm_Calendar_Select_Mode
+elm_calendar_select_mode_get(const Evas_Object *obj)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return;
- _text_day_color_set(wd, DAY_WEEKDAY, pos);
+ ELM_CHECK_WIDTYPE(obj, widtype) -1;
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return -1;
+ return wd->select_mode;
}
+
+