Enhance Calendar Widget 55/130855/5
authorSeunghyun Choi <sh4682.choi@samsung.com>
Wed, 24 May 2017 07:30:33 +0000 (16:30 +0900)
committerSeunghyun Choi <sh4682.choi@samsung.com>
Fri, 9 Jun 2017 05:24:40 +0000 (14:24 +0900)
Change-Id: Id9aa8789b03128f7bc895c4003a30d680d4bb9f6
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 0d75af8..291d5f5 100644 (file)
@@ -128,6 +128,7 @@ namespace ElmSharp.Test
             {
                 label1.Text = string.Format("Old.Day={0}, Month={1}, Year={2}", e.OldDate.Day, e.OldDate.Month, e.OldDate.Year);
                 label2.Text = string.Format("New.Day={0}, Month={1}, Year={2}", e.NewDate.Day, e.NewDate.Month, e.NewDate.Year);
+                label3.Text = string.Format("SelectedDate={0}", calendar.SelectedDate);
             };
 
             calendar.DisplayedMonthChanged += (object sender, DisplayedMonthChangedEventArgs e) =>
@@ -135,37 +136,93 @@ namespace ElmSharp.Test
                 label3.Text = string.Format("Old Month={0}, New Month={1}", e.OldMonth, e.NewMonth);
             };
 
+            var label4 = new Label(window)
+            {
+                Text = string.Format("Selectable={0}", calendar.Selectable),
+                Color = Color.Black,
+            };
+
+            var changeSelectable = new Button(window)
+            {
+                Text = "Change Selectable"
+            };
+
+            calendar.Selectable = CalendarSelectable.Month;
+
+            changeSelectable.Clicked += (s, e) =>
+            {
+                if (calendar.Selectable == CalendarSelectable.None)
+                {
+                    calendar.Selectable = CalendarSelectable.Year;
+                }
+                else if (calendar.Selectable == CalendarSelectable.Year)
+                {
+                    calendar.Selectable = CalendarSelectable.Month;
+                }
+                else if (calendar.Selectable == CalendarSelectable.Month)
+                {
+                    calendar.Selectable = CalendarSelectable.Day;
+                }
+                else
+                {
+                    calendar.Selectable = CalendarSelectable.None;
+                }
+                label4.Text = string.Format("Selectable={0}", calendar.Selectable);
+            };
+
+            var setTime = new Button(window)
+            {
+                Text = "Set 2015,1,1",
+            };
+
+            setTime.Clicked += (s, e) =>
+            {
+                calendar.SelectedDate = new DateTime(2015, 1, 1);
+            };
+
             calendar.Resize(600, 600);
-            calendar.Move(0, 250);
+            calendar.Move(0, 150);
             calendar.Show();
 
-            label1.Resize(600, 100);
+            label1.Resize(600, 30);
             label1.Move(0, 0);
             label1.Show();
 
-            label2.Resize(600, 100);
-            label2.Move(0, 50);
+            label2.Resize(600, 30);
+            label2.Move(0, 30);
             label2.Show();
 
-            label3.Resize(600, 100);
-            label3.Move(0, 100);
+            label3.Resize(600, 30);
+            label3.Move(0, 60);
             label3.Show();
 
-            selectMode.Resize(600, 100);
-            selectMode.Move(0, 150);
+            selectMode.Resize(600, 30);
+            selectMode.Move(0, 90);
             selectMode.Show();
 
             addMark.Resize(600, 100);
-            addMark.Move(0, 900);
+            addMark.Move(0, 750);
             addMark.Show();
 
             delMark.Resize(600, 100);
-            delMark.Move(0, 1000);
+            delMark.Move(0, 850);
             delMark.Show();
 
             changeMode.Resize(600, 100);
-            changeMode.Move(0, 1100);
+            changeMode.Move(0, 950);
             changeMode.Show();
+
+            label4.Resize(600, 30);
+            label4.Move(0, 1050);
+            label4.Show();
+
+            changeSelectable.Resize(600, 100);
+            changeSelectable.Move(0, 1080);
+            changeSelectable.Show();
+
+            setTime.Resize(600, 100);
+            setTime.Move(0, 1180);
+            setTime.Show();
         }
     }
 }
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
index f6d96c2..38eace6
@@ -30,22 +30,27 @@ namespace ElmSharp
         /// Default value. Marks will be displayed only on event day.
         /// </summary>
         Unique,
+
         /// <summary>
         /// Marks will be displayed every day after event day.
         /// </summary>
         Daily,
+
         /// <summary>
         /// Marks will be displayed every week after event day.
         /// </summary>
         Weekly,
+
         /// <summary>
         /// Marks will be displayed every month day that coincides to event day.
         /// </summary>
         Monthly,
+
         /// <summary>
         /// Marks will be displayed every year that coincides to event day.
         /// </summary>
         Annually,
+
         /// <summary>
         /// Marks will be displayed every last day of month after event day.
         /// </summary>
@@ -61,20 +66,32 @@ namespace ElmSharp
         /// Default value. a day is always selected.
         /// </summary>
         Default,
+
         /// <summary>
         /// A day is always selected.
         /// </summary>
         Always,
+
         /// <summary>
         /// None of the days can be selected.
         /// </summary>
         None,
+
         /// <summary>
         /// User may have selected a day or not.
         /// </summary>
         OnDemand
     }
 
+    [Flags]
+    public enum CalendarSelectable
+    {
+        None = 0,
+        Year = 1 << 0,
+        Month = 1 << 1,
+        Day = 1 << 2
+    }
+
     /// <summary>
     /// The CalendarMark is a Item for marking a Calendar's type,date and repeat type.
     /// </summary>
@@ -122,6 +139,9 @@ namespace ElmSharp
         SmartEvent _displayedMonthChanged;
         int _cacheDisplayedMonth;
 
+        Interop.Elementary.Elm_Calendar_Format_Cb _calendarFormat;
+        DateFormatDelegate _dateFormatDelegate = null;
+
         /// <summary>
         /// Creates and initializes a new instance of the Calendar class.
         /// </summary>
@@ -145,6 +165,8 @@ namespace ElmSharp
                 DisplayedMonthChanged?.Invoke(this, new DisplayedMonthChangedEventArgs(_cacheDisplayedMonth, currentDisplayedMonth));
                 _cacheDisplayedMonth = currentDisplayedMonth;
             };
+
+            _calendarFormat = (t) => { return _dateFormatDelegate(t); };
         }
 
         /// <summary>
@@ -158,6 +180,13 @@ namespace ElmSharp
         public event EventHandler<DisplayedMonthChangedEventArgs> DisplayedMonthChanged;
 
         /// <summary>
+        /// This delegate type is used to format the string that will be used to display month and year.
+        /// </summary>
+        /// <param name="time">DateTime</param>
+        /// <returns></returns>
+        public delegate string DateFormatDelegate(DateTime time);
+
+        /// <summary>
         /// Sets or gets the minimum for year.
         /// </summary>
         public int MinimumYear
@@ -327,6 +356,46 @@ namespace ElmSharp
         }
 
         /// <summary>
+        /// Gets or sets fields of a datetime will be taken into account, when SelectedDate set is invoked.
+        /// </summary>
+        public CalendarSelectable Selectable
+        {
+            get
+            {
+                return (CalendarSelectable)Interop.Elementary.elm_calendar_selectable_get(RealHandle);
+            }
+            set
+            {
+                Interop.Elementary.elm_calendar_selectable_set(RealHandle, (int)value);
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets date 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.
+        /// </summary>
+        public DateFormatDelegate DateFormat
+        {
+            get
+            {
+                return _dateFormatDelegate;
+            }
+            set
+            {
+                _dateFormatDelegate = value;
+                if (value != null)
+                {
+                    Interop.Elementary.elm_calendar_format_function_set(RealHandle, _calendarFormat);
+                }
+                else
+                {
+                    Interop.Elementary.elm_calendar_format_function_set(RealHandle, null);
+                }
+            }
+        }
+
+        /// <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>
index 1556bda..6885035 100644 (file)
@@ -98,5 +98,11 @@ internal static partial class Interop
 
         [DllImport(Libraries.Elementary)]
         internal static extern void elm_calendar_marks_clear(IntPtr obj);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate string Elm_Calendar_Format_Cb(Libc.SystemTime date);
+
+        [DllImport(Libraries.Elementary)]
+        internal static extern void elm_calendar_format_function_set(IntPtr obj, Elm_Calendar_Format_Cb format_function);
     }
 }
\ No newline at end of file