elementary: add elm_calendar_selectable_set
authorMichael BOUCHAUD <michael.bouchaud@gmail.com>
Tue, 11 Sep 2012 21:33:54 +0000 (21:33 +0000)
committerMichael BOUCHAUD <michael.bouchaud@gmail.com>
Tue, 11 Sep 2012 21:33:54 +0000 (21:33 +0000)
SVN revision: 76478

src/bin/test_calendar.c
src/lib/elm_calendar.c
src/lib/elm_calendar.h
src/lib/elm_widget_calendar.h

index 9e2acd4..5635bfa 100644 (file)
@@ -326,6 +326,9 @@ test_calendar3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_i
    cal = elm_calendar_add(win);
    elm_calendar_first_day_of_week_set(cal, ELM_DAY_THURSDAY);
    elm_calendar_select_mode_set(cal, ELM_CALENDAR_SELECT_MODE_ONDEMAND);
+   elm_calendar_selectable_set(cal,
+                               (ELM_CALENDAR_SELECTABLE_YEAR
+                                | ELM_CALENDAR_SELECTABLE_MONTH));
    current_time = time(NULL) + 34 * 84600;
    localtime_r(&current_time, &selected_time);
    elm_calendar_selected_time_set(cal, &selected_time);
index 5e3e1a0..ff38a4f 100644 (file)
@@ -711,6 +711,7 @@ _elm_calendar_smart_add(Evas_Object *obj)
    priv->first_day_it = -1;
    priv->format_func = _format_month_year;
    priv->marks = NULL;
+   priv->selectable = (~(ELM_CALENDAR_SELECTABLE_NONE));
 
    edje_object_signal_callback_add
      (ELM_WIDGET_DATA(priv)->resize_obj, "elm,action,increment,start", "*",
@@ -943,9 +944,21 @@ elm_calendar_selected_time_set(Evas_Object *obj,
    ELM_CALENDAR_DATA_GET(obj, sd);
    EINA_SAFETY_ON_NULL_RETURN(selected_time);
 
-   sd->selected_time = *selected_time;
-   if (!sd->selected)
-     sd->selected = EINA_TRUE;
+   if (sd->selectable & ELM_CALENDAR_SELECTABLE_YEAR)
+     sd->selected_time.tm_year = selected_time->tm_year;
+   if (sd->selectable & ELM_CALENDAR_SELECTABLE_MONTH)
+     sd->selected_time.tm_mon = selected_time->tm_mon;
+   if (sd->selectable & ELM_CALENDAR_SELECTABLE_DAY)
+       {
+          sd->selected_time.tm_mday = selected_time->tm_mday;
+          if (!sd->selected)
+            sd->selected = EINA_TRUE;
+       }
+   else if (sd->select_mode != ELM_CALENDAR_SELECT_MODE_ONDEMAND)
+     {
+        if (!sd->selected)
+          sd->selected = EINA_TRUE;
+     }
    if (sd->selected_time.tm_year != sd->shown_time.tm_year)
      sd->shown_time.tm_year = sd->selected_time.tm_year;
    if (sd->selected_time.tm_mon != sd->shown_time.tm_mon)
@@ -1094,3 +1107,22 @@ elm_calendar_select_mode_get(const Evas_Object *obj)
 
    return sd->select_mode;
 }
+
+EAPI void
+elm_calendar_selectable_set(Evas_Object *obj, Elm_Calendar_Selectable selectable)
+{
+   ELM_CALENDAR_CHECK(obj);
+   ELM_CALENDAR_DATA_GET(obj, sd);
+
+   sd->selectable = selectable;
+}
+
+EAPI Elm_Calendar_Selectable
+elm_calendar_selectable_get(const Evas_Object *obj)
+{
+   ELM_CALENDAR_CHECK(obj) -1;
+   ELM_CALENDAR_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
+
+   return sd->selectable;
+}
+
index d81d010..18c60cd 100644 (file)
@@ -117,6 +117,28 @@ typedef enum
  */
 typedef _Elm_Calendar_Select_Mode Elm_Calendar_Select_Mode;
 
+typedef enum
+{
+   ELM_CALENDAR_SELECTABLE_NONE = 0,
+   ELM_CALENDAR_SELECTABLE_YEAR = (1 << 0),
+   ELM_CALENDAR_SELECTABLE_MONTH = (1 << 1),
+   ELM_CALENDAR_SELECTABLE_DAY = (1 << 2)
+} _Elm_Calendar_Selectable;
+
+/**
+ * @enum _Elm_Calendar_Selectable
+ * @typedef Elm_Calendar_Selectable
+ *
+ * A bitmask used to define which fields of a @b tm struct will be taken into
+ * account, when elm_calendar_selected_time_set() is invoked.
+ *
+ * @ingroup Calendar
+ * @see elm_calendar_selectable_set()
+ * @see elm_calendar_selected_time_set()
+ * @since 1.8
+ */
+typedef _Elm_Calendar_Selectable Elm_Calendar_Selectable;
+
 typedef struct _Elm_Calendar_Mark Elm_Calendar_Mark;    /**< Item handle for a calendar mark. Created with elm_calendar_mark_add() and deleted with elm_calendar_mark_del(). */
 
 /**
@@ -516,5 +538,35 @@ EAPI void                 elm_calendar_first_day_of_week_set(Evas_Object *obj, E
 EAPI Elm_Calendar_Weekday elm_calendar_first_day_of_week_get(const Evas_Object *obj);
 
 /**
+ * Define which fields of a @b tm struct will be taken into account, when
+ * elm_calendar_selected_time_set() is invoked.
+ *
+ * @param obj The calendar object
+ * @param selectable A bitmask of Elm_Calendar_Selectable
+ *
+ * By Default the bitmask is set to use all fields of a @b tm struct (year,
+ * month and day of the month).
+ *
+ * @ingroup Calendar
+ * @see elm_calendar_selected_time_set
+ * @since 1.8
+ */
+EAPI void                 elm_calendar_selectable_set(Evas_Object *obj, Elm_Calendar_Selectable selectable);
+
+
+/**
+ * Get how elm_calendar_selected_time_set manage a date
+ *
+ * @param obj The calendar object
+ * @return The flag used to manage a date with a elm_calendar_selected_time_set
+ *
+ * @ingroup Calendar
+ * @see elm_calendar_selectable_set
+ * @see elm_calendar_selected_time_set
+ * @since 1.8
+ */
+EAPI Elm_Calendar_Selectable elm_calendar_selectable_get(const Evas_Object *obj);
+
+/**
  * @}
  */
index 916846a..ba7e507 100644 (file)
@@ -143,6 +143,7 @@ struct _Elm_Calendar_Smart_Data
    Day_Color                day_color[42]; // EINA_DEPRECATED
    Elm_Calendar_Select_Mode select_mode;
    Eina_Bool                selected : 1;
+   Elm_Calendar_Selectable  selectable;
 };
 
 struct _Elm_Calendar_Mark