elm genlist: Fixed a bug with decorate all mode + tree effect. Delete tree effect...
[framework/uifw/elementary.git] / src / lib / elm_calendar.c
index 8969454..5ac5d8b 100644 (file)
@@ -9,23 +9,6 @@
 #include <Elementary.h>
 #include "elm_priv.h"
 
-/**
- * @defgroup Calendar
- * @ingroup Elementary
- *
- * 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,
@@ -42,12 +25,14 @@ struct _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 *selected_time);
-   const char *weekdays[7];
-   struct tm current_time, selected_time;
+   Elm_Calendar_Format_Cb format_func;
+   const char *weekdays[ELM_DAY_LAST];
+   struct tm current_time, selected_time, showed_time;
    Day_Color day_color[42]; // EINA_DEPRECATED
-   Eina_Bool selection_enabled : 1;
+   Elm_Calendar_Select_Mode select_mode;
+   Eina_Bool selected:1;
 };
 
 struct _Elm_Calendar_Mark
@@ -56,7 +41,7 @@ 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;
@@ -86,7 +71,7 @@ static int _days_in_month[2][12] =
 };
 
 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;
@@ -146,6 +131,7 @@ static inline void
 _select(Widget_Data *wd, int selected)
 {
    char emission[32];
+   wd->selected_it = selected;
    snprintf(emission, sizeof(emission), "cit_%i,selected", selected);
    edje_object_signal_emit(wd->calendar, emission, "elm");
 }
@@ -172,7 +158,7 @@ static char *
 _format_month_year(struct tm *selected_time)
 {
    char buf[32];
-   if (!strftime(buf, sizeof(buf), "%B %Y", selected_time)) return NULL;
+   if (!strftime(buf, sizeof(buf), E_("%B %Y"), selected_time)) return NULL;
    return strdup(buf);
 }
 
@@ -187,7 +173,7 @@ _cit_mark(Evas_Object *cal, int cit, const char *mtype)
 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
@@ -214,25 +200,30 @@ _text_day_color_update(Widget_Data *wd, int pos)
    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->showed_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);
 
@@ -240,28 +231,23 @@ _populate(Evas_Object *obj)
 
    if (wd->today_it > 0) _not_today(wd);
 
-   maxdays = _maxdays_get(&wd->selected_time);
-   mon = wd->selected_time.tm_mon;
-   year = wd->selected_time.tm_year;
+   maxdays = _maxdays_get(&wd->showed_time);
+   mon = wd->showed_time.tm_mon;
+   yr = wd->showed_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;
-   first_day = wd->selected_time;
+   first_day = wd->showed_time;
    first_day.tm_mday = 1;
    mktime(&first_day);
 
    // Layout of the calendar is changed for removing the unfilled last row.
-   wd->first_day_it = first_day.tm_wday;
+   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;
 
@@ -306,21 +292,30 @@ _populate(Evas_Object *obj)
    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))
+            && (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 (wd->selection_enabled) _select(wd, i);
-
-             wd->selected_it = i;
+             if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+               {
+                  if ((mon == wd->selected_time.tm_mon)
+                      && (yr == wd->selected_time.tm_year)
+                      && (wd->selected))
+                    {
+                       _select(wd, i);
+                    }
+               }
+             else if (wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE)
+               {
+                  _select(wd, i);
+               }
           }
 
         if ((day) && (day <= maxdays))
@@ -338,8 +333,8 @@ _populate(Evas_Object *obj)
    EINA_LIST_FOREACH(wd->marks, l, mark)
      {
         struct tm *mtime = &mark->mark_time;
-        int month = wd->selected_time.tm_mon;
-        int year = wd->selected_time.tm_year;
+        int month = wd->showed_time.tm_mon;
+        int year = wd->showed_time.tm_year;
         int mday_it = mtime->tm_mday + wd->first_day_it - 1;
 
         switch (mark->repeat)
@@ -396,10 +391,12 @@ _set_headers(Evas_Object *obj)
    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]);
+        edje_object_part_text_escaped_set
+        (wd->calendar, part,
+            wd->weekdays[(i + wd->first_week_day) % ELM_DAY_LAST]);
      }
 }
 
@@ -423,7 +420,7 @@ _del_hook(Evas_Object *obj)
           }
      }
 
-   for (i = 0; i < 7; i++)
+   for (i = 0; i < ELM_DAY_LAST; i++)
      eina_stringshare_del(wd->weekdays[i]);
 
    free(wd);
@@ -501,6 +498,10 @@ _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *so
 static inline void
 _fix_selected_time(Widget_Data *wd)
 {
+   if (wd->selected_time.tm_mon != wd->showed_time.tm_mon)
+     wd->selected_time.tm_mon = wd->showed_time.tm_mon;
+   if (wd->selected_time.tm_year != wd->showed_time.tm_year)
+     wd->selected_time.tm_year = wd->showed_time.tm_year;
    mktime(&wd->selected_time);
 }
 
@@ -513,39 +514,43 @@ _update_month(Evas_Object *obj, int delta)
    if (!wd) return EINA_FALSE;
 
    /* check if it's a valid time. for 32 bits, year greater than 2037 is not */
-   time_check = wd->selected_time;
+   time_check = wd->showed_time;
    time_check.tm_mon += delta;
    if (mktime(&time_check) == -1)
      return EINA_FALSE;
 
-   wd->selected_time.tm_mon += delta;
-   if (wd->selected_time.tm_mon < 0)
+   wd->showed_time.tm_mon += delta;
+   if (wd->showed_time.tm_mon < 0)
      {
-        if (wd->selected_time.tm_year == wd->year_min)
+        if (wd->showed_time.tm_year == wd->year_min)
           {
-             wd->selected_time.tm_mon++;
+             wd->showed_time.tm_mon++;
              return EINA_FALSE;
           }
-        wd->selected_time.tm_mon = 11;
-        wd->selected_time.tm_year--;
+        wd->showed_time.tm_mon = 11;
+        wd->showed_time.tm_year--;
      }
-   else if (wd->selected_time.tm_mon > 11)
+   else if (wd->showed_time.tm_mon > 11)
      {
-        if (wd->selected_time.tm_year == wd->year_max)
+        if (wd->showed_time.tm_year == wd->year_max)
           {
-             wd->selected_time.tm_mon--;
+             wd->showed_time.tm_mon--;
              return EINA_FALSE;
           }
-        wd->selected_time.tm_mon = 0;
-        wd->selected_time.tm_year++;
+        wd->showed_time.tm_mon = 0;
+        wd->showed_time.tm_year++;
      }
 
-   maxdays = _maxdays_get(&wd->selected_time);
-   if (wd->selected_time.tm_mday > maxdays)
-     wd->selected_time.tm_mday = maxdays;
+   if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+       && (wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE))
+     {
+        maxdays = _maxdays_get(&wd->showed_time);
+        if (wd->selected_time.tm_mday > maxdays)
+          wd->selected_time.tm_mday = maxdays;
 
-   _fix_selected_time(wd);
-   evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
+        _fix_selected_time(wd);
+        evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
+     }
 
    return EINA_TRUE;
 }
@@ -603,7 +608,7 @@ _get_item_day(Evas_Object *obj, int selected_it)
    if (!wd) return 0;
 
    day = selected_it - wd->first_day_it + 1;
-   if ((day < 0) || (day > _maxdays_get(&wd->selected_time)))
+   if ((day < 0) || (day > _maxdays_get(&wd->showed_time)))
      return 0;
 
    return day;
@@ -614,7 +619,7 @@ _update_sel_it(Evas_Object *obj, int sel_it)
 {
    int day;
    Widget_Data *wd = elm_widget_data_get(obj);
-   if ((!wd) || (!wd->selection_enabled))
+   if ((!wd) || (wd->select_mode == ELM_CALENDAR_SELECT_MODE_NONE))
      return;
 
    day = _get_item_day(obj, sel_it);
@@ -622,11 +627,12 @@ _update_sel_it(Evas_Object *obj, int sel_it)
      return;
 
    _unselect(wd, wd->selected_it);
+   if (!wd->selected)
+     wd->selected = EINA_TRUE;
 
-   wd->selected_it = sel_it;
    wd->selected_time.tm_mday = day;
-   _select(wd, wd->selected_it);
    _fix_selected_time(wd);
+   _select(wd, sel_it);
    evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
 }
 
@@ -635,7 +641,7 @@ _day_selected(void *data, Evas_Object *obj __UNUSED__, const char *emission __UN
 {
    int sel_it;
    Widget_Data *wd = elm_widget_data_get(data);
-   if ((!wd) || (!wd->selection_enabled))
+   if ((!wd) || (wd->select_mode == ELM_CALENDAR_SELECT_MODE_NONE))
      return;
    sel_it = atoi(source);
 
@@ -663,8 +669,8 @@ _update_cur_date(void *data)
    t = _time_to_next_day(&wd->current_time);
    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))
+   if ((wd->current_time.tm_mon != wd->showed_time.tm_mon) ||
+       (wd->current_time.tm_year!= wd->showed_time.tm_year))
      return ECORE_CALLBACK_RENEW;
 
    day = wd->current_time.tm_mday + wd->first_day_it - 1;
@@ -682,51 +688,61 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
 
    if (!wd) return EINA_FALSE;
    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
-   if (!wd->selection_enabled) return EINA_FALSE;
 
-   if ((!strcmp(ev->keyname, "Left")) ||
-       (!strcmp(ev->keyname, "KP_Left")))
-     {
-        _update_sel_it(obj, wd->selected_it-1);
-     }
-   else if ((!strcmp(ev->keyname, "Right")) ||
-            (!strcmp(ev->keyname, "KP_Right")))
-     {
-        _update_sel_it(obj, wd->selected_it+1);
-     }
-   else if ((!strcmp(ev->keyname, "Up"))  ||
-            (!strcmp(ev->keyname, "KP_Up")))
-     {
-        _update_sel_it(obj, wd->selected_it-7);
-     }
-   else if ((!strcmp(ev->keyname, "Down")) ||
-            (!strcmp(ev->keyname, "KP_Down")))
-     {
-        _update_sel_it(obj, wd->selected_it+7);
-     }
-   else if ((!strcmp(ev->keyname, "Prior")) ||
-            (!strcmp(ev->keyname, "KP_Prior")))
+   if ((!strcmp(ev->keyname, "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);
      }
+
+   else if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_NONE)
+            && ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+                || (wd->selected)))
+     {
+        if ((!strcmp(ev->keyname, "Left")) ||
+            ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
+          {
+             if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+                 || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
+                     && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
+               _update_sel_it(obj, wd->selected_it-1);
+          }
+        else if ((!strcmp(ev->keyname, "Right")) ||
+                 ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
+          {
+             if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+                 || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
+                     && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
+               _update_sel_it(obj, wd->selected_it+1);
+          }
+        else if ((!strcmp(ev->keyname, "Up"))  ||
+                 ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
+          {
+             if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+                 || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
+                     && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
+               _update_sel_it(obj, wd->selected_it-ELM_DAY_LAST);
+          }
+        else if ((!strcmp(ev->keyname, "Down")) ||
+                 ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
+          {
+             if ((wd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+                 || ((wd->showed_time.tm_year == wd->selected_time.tm_year)
+                     && (wd->showed_time.tm_mon == wd->selected_time.tm_mon)))
+               _update_sel_it(obj, wd->selected_it+ELM_DAY_LAST);
+          }
+        else return EINA_FALSE;
+     }
    else return EINA_FALSE;
 
    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)
 {
@@ -758,7 +774,6 @@ elm_calendar_add(Evas_Object *parent)
    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;
 
@@ -777,7 +792,7 @@ elm_calendar_add(Evas_Object *parent)
 
    evas_object_smart_callbacks_descriptions_set(obj, _signals);
 
-   for (i = 0; i < 7; i++)
+   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. :| */
@@ -798,8 +813,9 @@ elm_calendar_add(Evas_Object *parent)
      }
 
    current_time = time(NULL);
-   localtime_r(&current_time, &wd->selected_time);
-   wd->current_time = wd->selected_time;
+   localtime_r(&current_time, &wd->showed_time);
+   wd->current_time = wd->showed_time;
+   wd->selected_time = wd->showed_time;
    t = _time_to_next_day(&wd->current_time);
    wd->update_timer = ecore_timer_add(t, _update_cur_date, obj);
 
@@ -810,30 +826,6 @@ elm_calendar_add(Evas_Object *parent)
    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[])
 {
@@ -844,25 +836,13 @@ 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)
 {
@@ -872,18 +852,6 @@ 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)
 {
@@ -893,18 +861,6 @@ 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)
 {
@@ -914,22 +870,6 @@ 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)
 {
@@ -941,31 +881,16 @@ elm_calendar_min_max_year_set(Evas_Object *obj, int min, int max)
    if ((wd->year_min == min) && (wd->year_max == max)) return;
    wd->year_min = min > 2 ? min : 2;
    if (max > wd->year_min)
-         wd->year_max = max;
+     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)
-     wd->selected_time.tm_year = wd->year_min;
-   _fix_selected_time(wd);
+     wd->year_max = wd->year_min;
+   if (wd->showed_time.tm_year > wd->year_max)
+     wd->showed_time.tm_year = wd->year_max;
+   if (wd->showed_time.tm_year < wd->year_min)
+     wd->showed_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)
 {
@@ -976,62 +901,24 @@ 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)
 {
@@ -1041,22 +928,18 @@ elm_calendar_selected_time_set(Evas_Object *obj, struct tm *selected_time)
 
    EINA_SAFETY_ON_NULL_RETURN(selected_time);
    wd->selected_time = *selected_time;
+   if (!wd->selected)
+     wd->selected = EINA_TRUE;
+   if (wd->selected_time.tm_year != wd->showed_time.tm_year)
+     wd->showed_time.tm_year = wd->selected_time.tm_year;
+   if (wd->selected_time.tm_mon != wd->showed_time.tm_mon)
+     wd->showed_time.tm_mon = wd->selected_time.tm_mon;
+
+   _fix_selected_time(wd);
    _populate(obj);
    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)
 {
@@ -1064,88 +947,25 @@ elm_calendar_selected_time_get(const Evas_Object *obj, struct tm *selected_time)
    Widget_Data *wd = elm_widget_data_get(obj);
    if (!wd) return EINA_FALSE;
    EINA_SAFETY_ON_NULL_RETURN_VAL(selected_time, EINA_FALSE);
+   if ((wd->select_mode == ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+       && (!wd->selected))
+     return EINA_FALSE;
    *selected_time = wd->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 *selected_time)
- * {
- *    char buf[32];
- *    if (!strftime(buf, sizeof(buf), "%B %Y", selected_time)) 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 *selected_time))
+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(&current_time, &selected_time);
- * elm_calendar_mark_add(cal, "holiday", selected_time, ELM_CALENDAR_ANNUALLY);
- *
- * current_time = time(NULL) + 1 * 84600;
- * localtime_r(&current_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);
@@ -1158,13 +978,6 @@ elm_calendar_mark_add(Evas_Object *obj, const char *mark_type, struct tm *mark_t
    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)
 {
@@ -1181,13 +994,6 @@ 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)
 {
@@ -1200,14 +1006,6 @@ 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)
 {
@@ -1217,20 +1015,6 @@ 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)
 {
@@ -1240,83 +1024,57 @@ 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;
-   _text_day_color_set(wd, DAY_SATURDAY, pos);
+   if (day >= ELM_DAY_LAST) return;
+   if (wd->first_week_day != day)
+     {
+        wd->first_week_day = day;
+        _set_headers(obj);
+        _populate(obj);
+     }
 }
 
-/**
- * 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 Elm_Calendar_Weekday
+elm_calendar_first_day_of_week_get(const Evas_Object *obj)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype);
+   ELM_CHECK_WIDTYPE(obj, widtype) -1;
    Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return;
-   _text_day_color_set(wd, DAY_SUNDAY, pos);
+   if (!wd) return -1;
+   return wd->first_week_day;
 }
 
-/**
- * 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 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_WEEKDAY, pos);
+   if ((mode <= ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+       && (wd->select_mode != mode))
+     {
+        wd->select_mode = mode;
+        if (wd->select_mode == ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+          wd->selected = EINA_FALSE;
+        if ((wd->select_mode == ELM_CALENDAR_SELECT_MODE_ALWAYS)
+          || (wd->select_mode == ELM_CALENDAR_SELECT_MODE_DEFAULT))
+          _select(wd, wd->selected_it);
+        else
+          _unselect(wd, wd->selected_it);
+     }
+}
+
+EAPI Elm_Calendar_Select_Mode
+elm_calendar_select_mode_get(const Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) -1;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return -1;
+   return wd->select_mode;
 }
+
+