2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
25 /// Enumeration for event periodicity, used to define if a mark should be repeated beyond the event's day. It's set when a mark is added.
27 /// <since_tizen> preview </since_tizen>
28 [Obsolete("This has been deprecated in API12")]
29 public enum CalendarMarkRepeatType
32 /// Default value. Marks will be displayed only on the event day.
37 /// Marks will be displayed every day after the event day.
42 /// Marks will be displayed every week after the event day.
47 /// Marks will be displayed every month that coincides to the event day.
52 /// Marks will be displayed every year that coincides to the event day.
57 /// Marks will be displayed every last day of month after the event day.
63 /// Enumeration for the mode, which determines how a user could select a day.
65 /// <since_tizen> preview </since_tizen>
66 [Obsolete("This has been deprecated in API12")]
67 public enum CalendarSelectMode
70 /// Default value. A day is always selected.
75 /// A day is always selected.
80 /// None of the days can be selected.
85 /// User may have selected a day.
91 /// Enumeration for defining which fields of a tm struct will be taken into account.
93 /// <since_tizen> preview </since_tizen>
94 [Obsolete("This has been deprecated in API12")]
96 public enum CalendarSelectable
99 /// None will be taken into account.
103 /// Year will be taken into account.
107 /// Month will be taken into account.
111 /// Day will be taken into account.
117 /// The CalendarMark is an item for marking a Calendar's type, date, and repeat type.
119 /// <since_tizen> preview </since_tizen>
120 [Obsolete("This has been deprecated in API12")]
121 public class CalendarMark
123 internal IntPtr Handle;
126 /// A string used to define the type of mark.
128 /// <since_tizen> preview </since_tizen>
129 [Obsolete("This has been deprecated in API12")]
133 /// A time struct to represent the date of inclusion of the mark.
135 /// <since_tizen> preview </since_tizen>
136 [Obsolete("This has been deprecated in API12")]
137 public DateTime Date;
140 /// Repeats the event following this periodicity.
142 /// <since_tizen> preview </since_tizen>
143 [Obsolete("This has been deprecated in API12")]
144 public CalendarMarkRepeatType Repeat;
147 /// Creates and initializes a new instance of the CalendarMark class.
149 /// <param name="type">Type of mark.</param>
150 /// <param name="date">Date of inclusion of the mark.</param>
151 /// <param name="repeat">Repeat type.</param>
152 /// <since_tizen> preview </since_tizen>
153 [Obsolete("This has been deprecated in API12")]
154 public CalendarMark(string type, DateTime date, CalendarMarkRepeatType repeat)
156 Handle = IntPtr.Zero;
164 /// The Calendar is a widget that helps applications to flexibly display a calender with day of the week, date, year, and month.
166 /// <since_tizen> preview </since_tizen>
167 [Obsolete("This has been deprecated in API12")]
168 public class Calendar : Layout
171 DateTime _cacheSelectedDate;
172 SmartEvent _displayedMonthChanged;
173 int _cacheDisplayedMonth;
175 Interop.Elementary.Elm_Calendar_Format_Cb _calendarFormat;
176 DateFormatDelegate _dateFormatDelegate = null;
179 /// Creates and initializes a new instance of the Calendar class.
181 /// <param name="parent">
182 /// The EvasObject to which the new calendar will be attached as a child.
184 /// <since_tizen> preview </since_tizen>
185 [Obsolete("This has been deprecated in API12")]
186 public Calendar(EvasObject parent) : base(parent)
188 _changed = new SmartEvent(this, this.RealHandle, "changed");
189 _changed.On += (sender, e) =>
191 DateTime selectedDate = SelectedDate;
192 DateChanged?.Invoke(this, new DateChangedEventArgs(_cacheSelectedDate, selectedDate));
193 _cacheSelectedDate = selectedDate;
196 _displayedMonthChanged = new SmartEvent(this, this.RealHandle, "display,changed");
197 _displayedMonthChanged.On += (sender, e) =>
199 int currentDisplayedMonth = DisplayedTime.Month;
200 DisplayedMonthChanged?.Invoke(this, new DisplayedMonthChangedEventArgs(_cacheDisplayedMonth, currentDisplayedMonth));
201 _cacheDisplayedMonth = currentDisplayedMonth;
204 _calendarFormat = (ref Interop.Libc.SystemTime t) => { return _dateFormatDelegate(t); };
208 /// DateChanged will be triggered when the date in the calendar is changed.
210 /// <since_tizen> preview </since_tizen>
211 [Obsolete("This has been deprecated in API12")]
212 public event EventHandler<DateChangedEventArgs> DateChanged;
215 /// DisplayedMonthChanged will be triggered when the current month displayed in the calendar is changed.
217 /// <since_tizen> preview </since_tizen>
218 [Obsolete("This has been deprecated in API12")]
219 public event EventHandler<DisplayedMonthChangedEventArgs> DisplayedMonthChanged;
222 /// This delegate type is used to format the string that will be used to display month and year.
224 /// <param name="time">DateTime</param>
225 /// <returns></returns>
226 /// <since_tizen> preview </since_tizen>
227 [Obsolete("This has been deprecated in API12")]
228 public delegate string DateFormatDelegate(DateTime time);
231 /// Sets or gets the minimum for year.
233 /// <since_tizen> preview </since_tizen>
234 [Obsolete("This has been deprecated in API12")]
235 public int MinimumYear
241 Interop.Elementary.elm_calendar_min_max_year_get(RealHandle, out minimumYear, out unused);
248 Interop.Elementary.elm_calendar_min_max_year_get(RealHandle, out unused, out maximumYear);
249 if (maximumYear < 1902)
251 maximumYear = DateTime.MaxValue.Year;
253 Interop.Elementary.elm_calendar_min_max_year_set(RealHandle, value, maximumYear);
258 /// Sets or gets the maximum for the year.
260 /// <since_tizen> preview </since_tizen>
261 [Obsolete("This has been deprecated in API12")]
262 public int MaximumYear
268 Interop.Elementary.elm_calendar_min_max_year_get(RealHandle, out unused, out maximumYear);
275 Interop.Elementary.elm_calendar_min_max_year_get(RealHandle, out minimumYear, out unused);
276 Interop.Elementary.elm_calendar_min_max_year_set(RealHandle, minimumYear, value);
281 /// Sets or gets the first day of the week, which is used on the calendar.
283 /// <since_tizen> preview </since_tizen>
284 [Obsolete("This has been deprecated in API12")]
285 public DateTime DisplayedTime
289 Interop.Elementary.elm_calendar_displayed_time_get(RealHandle, out Interop.Libc.SystemTime tm);
291 // If the defect is fixed, it will be removed.
292 var daysInMonth = DateTime.DaysInMonth(tm.tm_year + 1900, tm.tm_mon + 1);
293 var day = tm.tm_mday;
295 if (day > daysInMonth)
300 DateTime date = new DateTime(tm.tm_year + 1900, tm.tm_mon + 1, day, tm.tm_hour, tm.tm_min, tm.tm_sec);
307 /// Sets or gets the first day of the week, which is used on the calendar.
309 /// <since_tizen> preview </since_tizen>
310 [Obsolete("This has been deprecated in API12")]
311 public DayOfWeek FirstDayOfWeek
315 return (DayOfWeek)Interop.Elementary.elm_calendar_first_day_of_week_get(RealHandle);
319 Interop.Elementary.elm_calendar_first_day_of_week_set(RealHandle, (int)value);
324 /// Sets or gets the weekdays name to be displayed by the calendar.
327 /// The usage should be like this:
328 /// <![CDATA[List<string> weekDayNames = new List<string>() { "S", "M", "T", "W", "T", "F", "S" };]]>
329 /// Calendar.WeekDayNames = weekDayNames;
331 /// <since_tizen> preview </since_tizen>
332 [Obsolete("This has been deprecated in API12")]
333 public IReadOnlyList<string> WeekDayNames
337 IntPtr stringArrayPtr = Interop.Elementary.elm_calendar_weekdays_names_get(RealHandle);
338 string[] stringArray;
339 IntPtrToStringArray(stringArrayPtr, 7, out stringArray);
344 if (value != null && value.Count == 7)
346 Interop.Elementary.elm_calendar_weekdays_names_set(RealHandle, value.ToArray());
352 /// Sets or gets the selected date.
355 /// The selected date changes when the user goes to the next/previous month or selects a day pressing over it on the calendar.
357 /// <since_tizen> preview </since_tizen>
358 [Obsolete("This has been deprecated in API12")]
359 public DateTime SelectedDate
363 var tm = new Interop.Libc.SystemTime();
364 Interop.Elementary.elm_calendar_selected_time_get(RealHandle, ref tm);
365 if (tm.tm_year == 0 && tm.tm_mon == 0 && tm.tm_mday == 0)
373 Interop.Libc.SystemTime tm = value;
374 Interop.Elementary.elm_calendar_selected_time_set(RealHandle, ref tm);
375 _cacheSelectedDate = value;
380 /// Sets or gets the interval on time updates for a user mouse button
381 /// hold, on the calendar widgets' month/year selection.
383 /// <since_tizen> preview </since_tizen>
384 [Obsolete("This has been deprecated in API12")]
385 public double Interval
389 return Interop.Elementary.elm_calendar_interval_get(RealHandle);
393 Interop.Elementary.elm_calendar_interval_set(RealHandle, value);
398 /// Gets or sets the select day mode used.
400 /// <since_tizen> preview </since_tizen>
401 [Obsolete("This has been deprecated in API12")]
402 public CalendarSelectMode SelectMode
406 return (CalendarSelectMode)Interop.Elementary.elm_calendar_select_mode_get(RealHandle);
410 Interop.Elementary.elm_calendar_select_mode_set(RealHandle, (Interop.Elementary.Elm_Calendar_Select_Mode)value);
415 /// Gets or sets the fields of a datetime that will be taken into account, when SelectedDate set is invoked.
417 /// <since_tizen> preview </since_tizen>
418 [Obsolete("This has been deprecated in API12")]
419 public CalendarSelectable Selectable
423 return (CalendarSelectable)Interop.Elementary.elm_calendar_selectable_get(RealHandle);
427 Interop.Elementary.elm_calendar_selectable_set(RealHandle, (int)value);
432 /// Gets or sets the date format of the string that will be used to display month and year.
434 /// <since_tizen> preview </since_tizen>
435 [Obsolete("This has been deprecated in API12")]
436 public DateFormatDelegate DateFormat
440 return _dateFormatDelegate;
444 _dateFormatDelegate = value;
447 Interop.Elementary.elm_calendar_format_function_set(RealHandle, _calendarFormat);
451 Interop.Elementary.elm_calendar_format_function_set(RealHandle, null);
457 /// Adds a new mark to the calendar.
459 /// <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 day's representation.</param>
460 /// <param name="date">A time struct to represent the date of inclusion of the mark. For marks that repeat, it will just be displayed after the inclusion date in the calendar.</param>
461 /// <param name="repeat">Repeat the event following this periodicity. Can be a unique mark (that doesn't repeat), daily, weekly, monthly, or annually.</param>
462 /// <returns>Item for a calendar mark.</returns>
463 /// <since_tizen> preview </since_tizen>
464 [Obsolete("This has been deprecated in API12")]
465 public CalendarMark AddMark(string type, DateTime date, CalendarMarkRepeatType repeat)
467 CalendarMark mark = new CalendarMark(type, date, repeat);
468 Interop.Libc.SystemTime tm = date;
469 IntPtr nativeHandle = Interop.Elementary.elm_calendar_mark_add(RealHandle, type, ref tm, (Interop.Elementary.Elm_Calendar_Mark_Repeat_Type)repeat);
470 mark.Handle = nativeHandle;
476 /// Deletes a mark from the calendar.
478 /// <param name="mark">Item for a calendar mark.</param>
479 /// <since_tizen> preview </since_tizen>
480 [Obsolete("This has been deprecated in API12")]
481 public void DeleteMark(CalendarMark mark)
483 Interop.Elementary.elm_calendar_mark_del(mark.Handle);
487 /// Draws the calendar marks.
489 /// <since_tizen> preview </since_tizen>
490 [Obsolete("This has been deprecated in API12")]
491 public void DrawMarks()
493 Interop.Elementary.elm_calendar_marks_draw(RealHandle);
497 /// Removes all the calendar's marks.
499 /// <since_tizen> preview </since_tizen>
500 [Obsolete("This has been deprecated in API12")]
501 public void ClearMarks()
503 Interop.Elementary.elm_calendar_marks_clear(RealHandle);
507 /// Creates a widget handle.
509 /// <param name="parent">Parent EvasObject.</param>
510 /// <returns>Handle IntPtr.</returns>
511 /// <since_tizen> preview </since_tizen>
512 [Obsolete("This has been deprecated in API12")]
513 protected override IntPtr CreateHandle(EvasObject parent)
515 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
516 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
518 RealHandle = Interop.Elementary.elm_calendar_add(handle);
519 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
524 static void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
526 managedArray = new string[size];
527 IntPtr[] IntPtrArray = new IntPtr[size];
529 Marshal.Copy(unmanagedArray, IntPtrArray, 0, size);
531 for (int iterator = 0; iterator < size; iterator++)
533 managedArray[iterator] = Marshal.PtrToStringAnsi(IntPtrArray[iterator]);