Add Additional Method and Properties for Calendar 48/115248/12
authorSeunghyun Choi <sh4682.choi@samsung.com>
Fri, 17 Feb 2017 05:02:39 +0000 (14:02 +0900)
committerSeunghyun Choi <sh4682.choi@samsung.com>
Thu, 16 Mar 2017 05:35:55 +0000 (14:35 +0900)
 - Add max/min Date, mark, select_mode
 - RFC : http://suprem.sec.samsung.net/confluence/display/SPTDTLC/%5BFormsTizen%5D+RFC+11+-+CalendarView

Change-Id: I7a9b49f6bbe471d0149965d544192193f869b715
Signed-off-by: Seunghyun Choi <sh4682.choi@samsung.com>
ElmSharp.Test/TC/CalendarTest1.cs
ElmSharp/ElmSharp/Calendar.cs [changed mode: 0755->0644]
ElmSharp/Interop/Interop.Elementary.CalendarView.cs

index 9a9c36c..0d75af8 100644 (file)
@@ -36,19 +36,92 @@ namespace ElmSharp.Test
             Calendar calendar = new Calendar(window)
             {
                 FirstDayOfWeek = DayOfWeek.Monday,
-                WeekDayNames = new List<string>() { "S", "M", "T", "W", "T", "F", "S" }
+                WeekDayNames = new List<string>() { "S", "M", "T", "W", "T", "F", "S" },
+                MinimumYear = DateTime.MinValue.Year,
+                MaximumYear = DateTime.MaxValue.Year
             };
 
-            Label label1 = new Label(window) {
+            IList<CalendarMark> marks = new List<CalendarMark>();
+
+            var mark = calendar.AddMark("holiday", DateTime.Today, CalendarMarkRepeatType.Unique);
+            marks.Add(mark);
+
+            Label label1 = new Label(window)
+            {
                 Text = string.Format("WeekDayLabel.Count={0}", calendar.WeekDayNames.Count),
+                Color = Color.Black,
             };
 
-            Label label2 = new Label(window) {
+            Label label2 = new Label(window)
+            {
                 Text = string.Format("WeekDayLabel.FirstDayOfWeek={0}", calendar.FirstDayOfWeek),
+                Color = Color.Black,
             };
 
-            Label label3 = new Label(window) {
+            Label label3 = new Label(window)
+            {
                 Text = string.Format("WeekDayLabel.SelectedDate={0}", calendar.SelectedDate),
+                Color = Color.Black,
+            };
+
+            var selectMode = new Label(window)
+            {
+                Text = string.Format("SelectMode = {0}", calendar.SelectMode),
+                Color = Color.Black,
+            };
+
+            var addMark = new Button(window)
+            {
+                Text = "Add Mark"
+            };
+
+            var i = 1;
+
+            addMark.Clicked += (s, e) =>
+            {
+                var newMark = calendar.AddMark("holiday", DateTime.Today.AddDays(i), CalendarMarkRepeatType.Unique);
+
+                Console.WriteLine("Call Add Mark : " + DateTime.Today.AddDays(i));
+                marks.Add(newMark);
+                calendar.DrawMarks();
+                i++;
+            };
+
+            var delMark = new Button(window)
+            {
+                Text = "Delete Mark"
+            };
+
+            delMark.Clicked += (s, e) =>
+            {
+                if (marks.Count > 0)
+                {
+                    calendar.DeleteMark(marks[0]);
+                    marks.Remove(marks[0]);
+                    calendar.DrawMarks();
+                }
+            };
+
+            var changeMode = new Button(window)
+            {
+                Text = "Change Select Mode"
+            };
+
+            changeMode.Clicked += (s, e) =>
+            {
+                if (calendar.SelectMode == CalendarSelectMode.Always || calendar.SelectMode == CalendarSelectMode.Default)
+                {
+                    calendar.SelectMode = CalendarSelectMode.None;
+                }
+                else if (calendar.SelectMode == CalendarSelectMode.None)
+                {
+                    calendar.SelectMode = CalendarSelectMode.OnDemand;
+                }
+                else
+                {
+                    calendar.SelectMode = CalendarSelectMode.Always;
+                }
+                selectMode.Text = string.Format("SelectMode = {0}", calendar.SelectMode);
             };
 
             calendar.DateChanged += (object sender, DateChangedEventArgs e) =>
@@ -63,7 +136,7 @@ namespace ElmSharp.Test
             };
 
             calendar.Resize(600, 600);
-            calendar.Move(0, 300);
+            calendar.Move(0, 250);
             calendar.Show();
 
             label1.Resize(600, 100);
@@ -71,13 +144,28 @@ namespace ElmSharp.Test
             label1.Show();
 
             label2.Resize(600, 100);
-            label2.Move(0, 100);
+            label2.Move(0, 50);
             label2.Show();
 
             label3.Resize(600, 100);
-            label3.Move(0, 200);
+            label3.Move(0, 100);
             label3.Show();
-        }
 
+            selectMode.Resize(600, 100);
+            selectMode.Move(0, 150);
+            selectMode.Show();
+
+            addMark.Resize(600, 100);
+            addMark.Move(0, 900);
+            addMark.Show();
+
+            delMark.Resize(600, 100);
+            delMark.Move(0, 1000);
+            delMark.Show();
+
+            changeMode.Resize(600, 100);
+            changeMode.Move(0, 1100);
+            changeMode.Show();
+        }
     }
 }
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
index 73ac989..b388c9e
@@ -22,14 +22,69 @@ using System.Runtime.InteropServices;
 namespace ElmSharp
 {
     /// <summary>
+    /// Event periodicity, used to define if a mark should be repeated beyond event's day. It's set when a mark is added.
+    /// </summary>
+    public enum CalendarMarkRepeatType
+    {
+        Unique, ///Default value. Marks will be displayed only on event day.
+        Daily, ///Marks will be displayed every day after event day.
+        Weekly, ///Marks will be displayed every week after event day.
+        Monthly, ///Marks will be displayed every month day that coincides to event day.
+        Annually, ///Marks will be displayed every year that coincides to event day.
+        LastDayOfMonth ///Marks will be displayed every last day of month after event day.
+    }
+
+    /// <summary>
+    /// The mode, who determine how user could select a day
+    /// </summary>
+    public enum CalendarSelectMode
+    {
+        Default, ///Default value. a day is always selected.
+        Always, ///a day is always selected.
+        None, ///None of the days can be selected.
+        OnDemand ///User may have selected a day or not.
+    }
+
+    /// <summary>
+    /// Item for a calendar mark.
+    /// </summary>
+    public class CalendarMark
+    {
+        internal IntPtr Handle;
+
+        /// <summary>
+        /// A string used to define the type of mark.
+        /// </summary>
+        public string Type;
+
+        /// <summary>
+        /// A time struct to represent the date of inclusion of the mark.
+        /// </summary>
+        public DateTime Date;
+
+        /// <summary>
+        /// Repeat the event following this periodicity.
+        /// </summary>
+        public CalendarMarkRepeatType Repeat;
+
+        public CalendarMark(string type, DateTime date, CalendarMarkRepeatType repeat)
+        {
+            Handle = IntPtr.Zero;
+            Type = type;
+            Date = date;
+            Repeat = repeat;
+        }
+    }
+
+    /// <summary>
     /// The Calendar is a widget that helps applications to flexibly display a calender with day of the week, date, year and month.
     /// </summary>
     public class Calendar : Layout
     {
-        private SmartEvent _changed;
-        private DateTime _cacheSelectedDate;
-        private SmartEvent _displayedMonthChanged;
-        private int _cacheDisplayedMonth;
+        SmartEvent _changed;
+        DateTime _cacheSelectedDate;
+        SmartEvent _displayedMonthChanged;
+        int _cacheDisplayedMonth;
 
         /// <summary>
         /// Creates and initializes a new instance of the Calendar class.
@@ -50,7 +105,7 @@ namespace ElmSharp
             _displayedMonthChanged = new SmartEvent(this, this.RealHandle, "display,changed");
             _displayedMonthChanged.On += (sender, e) =>
             {
-                int currentDisplayedMonth = SelectedDate.Month;
+                int currentDisplayedMonth = DisplayedTime.Month;
                 DisplayedMonthChanged?.Invoke(this, new DisplayedMonthChangedEventArgs(_cacheDisplayedMonth, currentDisplayedMonth));
                 _cacheDisplayedMonth = currentDisplayedMonth;
             };
@@ -83,6 +138,10 @@ namespace ElmSharp
                 int maximumYear;
                 int unused;
                 Interop.Elementary.elm_calendar_min_max_year_get(RealHandle, out unused, out maximumYear);
+                if (maximumYear < 1902)
+                {
+                    maximumYear = DateTime.MaxValue.Year;
+                }
                 Interop.Elementary.elm_calendar_min_max_year_set(RealHandle, value, maximumYear);
             }
         }
@@ -111,6 +170,31 @@ namespace ElmSharp
         /// <summary>
         /// Sets or gets the first day of week, who are used on Calendar.
         /// </summary>
+        public DateTime DisplayedTime
+        {
+            get
+            {
+                var tm = new Interop.Libc.SystemTime();
+                Interop.Elementary.elm_calendar_displayed_time_get(RealHandle, out tm);
+                ///TODO
+                ///If the defect is fixed, it will be removed.
+                var daysInMonth = DateTime.DaysInMonth(tm.tm_year + 1900, tm.tm_mon + 1);
+                var day = tm.tm_mday;
+
+                if (day > daysInMonth)
+                {
+                    day = daysInMonth;
+                }
+
+                DateTime date = new DateTime(tm.tm_year + 1900, tm.tm_mon + 1, day, tm.tm_hour, tm.tm_min, tm.tm_sec);
+
+                return date;
+            }
+        }
+
+        /// <summary>
+        /// Sets or gets the first day of week, who are used on Calendar.
+        /// </summary>
         public DayOfWeek FirstDayOfWeek
         {
             get
@@ -161,6 +245,10 @@ namespace ElmSharp
             {
                 var tm = new Interop.Libc.SystemTime();
                 Interop.Elementary.elm_calendar_selected_time_get(RealHandle, ref tm);
+                if (tm.tm_year == 0 && tm.tm_mon == 0 && tm.tm_mday == 0)
+                {
+                    return DateTime.Now;
+                }
                 return tm;
             }
             set
@@ -187,6 +275,63 @@ namespace ElmSharp
             }
         }
 
+        /// <summary>
+        /// Gets or sets the select day mode used.
+        /// </summary>
+        public CalendarSelectMode SelectMode
+        {
+            get
+            {
+                return (CalendarSelectMode)Interop.Elementary.elm_calendar_select_mode_get(RealHandle);
+            }
+            set
+            {
+                Interop.Elementary.elm_calendar_select_mode_set(RealHandle, (Interop.Elementary.Elm_Calendar_Select_Mode)value);
+            }
+        }
+
+        /// <summary>
+        /// Add a new mark to the calendar.
+        /// </summary>
+        /// <param name="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>
+        /// <param name="date">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>
+        /// <param name="repeat">Repeat the event following this periodicity. Can be a unique mark (that don't repeat), daily, weekly, monthly or annually.</param>
+        /// <returns>Item for a calendar mark.</returns>
+        public CalendarMark AddMark(string type, DateTime date, CalendarMarkRepeatType repeat)
+        {
+            CalendarMark mark = new CalendarMark(type, date, repeat);
+            Interop.Libc.SystemTime tm = date;
+            IntPtr nativeHandle = Interop.Elementary.elm_calendar_mark_add(RealHandle, type, ref tm, (Interop.Elementary.Elm_Calendar_Mark_Repeat_Type)repeat);
+            mark.Handle = nativeHandle;
+
+            return mark;
+        }
+
+        /// <summary>
+        /// Delete mark from the calendar.
+        /// </summary>
+        /// <param name="mark">Item for a calendar mark</param>
+        public void DeleteMark(CalendarMark mark)
+        {
+            Interop.Elementary.elm_calendar_mark_del(mark.Handle);
+        }
+
+        /// <summary>
+        /// Draw calendar marks.
+        /// </summary>
+        public void DrawMarks()
+        {
+            Interop.Elementary.elm_calendar_marks_draw(RealHandle);
+        }
+
+        /// <summary>
+        /// Remove all calendar's marks.
+        /// </summary>
+        public void ClearMarks()
+        {
+            Interop.Elementary.elm_calendar_marks_clear(RealHandle);
+        }
+
         protected override IntPtr CreateHandle(EvasObject parent)
         {
             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
@@ -198,7 +343,7 @@ namespace ElmSharp
             return handle;
         }
 
-        static private void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
+        static void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
         {
             managedArray = new string[size];
             IntPtr[] IntPtrArray = new IntPtr[size];
@@ -211,4 +356,4 @@ namespace ElmSharp
             }
         }
     }
-}
+}
\ No newline at end of file
index 7508c73..1556bda 100644 (file)
@@ -21,6 +21,24 @@ internal static partial class Interop
 {
     internal static partial class Elementary
     {
+        internal enum Elm_Calendar_Mark_Repeat_Type
+        {
+            ELM_CALENDAR_UNIQUE = 0, /* Default value. Marks will be displayed only on event day. */
+            ELM_CALENDAR_DAILY, /* Marks will be displayed every day after event day (inclusive). */
+            ELM_CALENDAR_WEEKLY, /* Marks will be displayed every week after event day (inclusive) */
+            ELM_CALENDAR_MONTHLY, /* Marks will be displayed every month day that coincides to event day. */
+            ELM_CALENDAR_ANNUALLY, /* Marks will be displayed every year that coincides to event day (and month). */
+            LM_CALENDAR_LAST_DAY_OF_MONTH /* Marks will be displayed every last day of month after event day (inclusive). */
+        };
+
+        internal enum Elm_Calendar_Select_Mode
+        {
+            ELM_CALENDAR_SELECT_MODE_DEFAULT = 0, /* Default value. a day is always selected. */
+            ELM_CALENDAR_SELECT_MODE_ALWAYS, /* a day is always selected. */
+            ELM_CALENDAR_SELECT_MODE_NONE, /* None of the days can be selected. */
+            ELM_CALENDAR_SELECT_MODE_ONDEMAND /* User may have selected a day or not. */
+        }
+
         [DllImport(Libraries.Elementary)]
         internal static extern IntPtr elm_calendar_add(IntPtr parent);
 
@@ -62,5 +80,23 @@ internal static partial class Interop
 
         [DllImport(Libraries.Elementary)]
         internal static extern double elm_calendar_interval_get(IntPtr obj);
+
+        [DllImport(Libraries.Elementary)]
+        internal static extern void elm_calendar_select_mode_set(IntPtr obj, Elm_Calendar_Select_Mode mode);
+
+        [DllImport(Libraries.Elementary)]
+        internal static extern int elm_calendar_select_mode_get(IntPtr obj);
+
+        [DllImport(Libraries.Elementary)]
+        internal static extern IntPtr elm_calendar_mark_add(IntPtr obj, string type, ref Libc.SystemTime date, Elm_Calendar_Mark_Repeat_Type repeatType);
+
+        [DllImport(Libraries.Elementary)]
+        internal static extern void elm_calendar_mark_del(IntPtr markItem);
+
+        [DllImport(Libraries.Elementary)]
+        internal static extern void elm_calendar_marks_draw(IntPtr obj);
+
+        [DllImport(Libraries.Elementary)]
+        internal static extern void elm_calendar_marks_clear(IntPtr obj);
     }
-}
+}
\ No newline at end of file