[ACR-564] deprecate unused API
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Calendar.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 using System.Runtime.InteropServices;
21
22 namespace ElmSharp
23 {
24     /// <summary>
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.
26     /// </summary>
27     /// <since_tizen> preview </since_tizen>
28     [Obsolete("This has been deprecated in API12")]
29     public enum CalendarMarkRepeatType
30     {
31         /// <summary>
32         /// Default value. Marks will be displayed only on the event day.
33         /// </summary>
34         Unique,
35
36         /// <summary>
37         /// Marks will be displayed every day after the event day.
38         /// </summary>
39         Daily,
40
41         /// <summary>
42         /// Marks will be displayed every week after the event day.
43         /// </summary>
44         Weekly,
45
46         /// <summary>
47         /// Marks will be displayed every month that coincides to the event day.
48         /// </summary>
49         Monthly,
50
51         /// <summary>
52         /// Marks will be displayed every year that coincides to the event day.
53         /// </summary>
54         Annually,
55
56         /// <summary>
57         /// Marks will be displayed every last day of month after the event day.
58         /// </summary>
59         LastDayOfMonth
60     }
61
62     /// <summary>
63     /// Enumeration for the mode, which determines how a user could select a day.
64     /// </summary>
65     /// <since_tizen> preview </since_tizen>
66     [Obsolete("This has been deprecated in API12")]
67     public enum CalendarSelectMode
68     {
69         /// <summary>
70         /// Default value. A day is always selected.
71         /// </summary>
72         Default,
73
74         /// <summary>
75         /// A day is always selected.
76         /// </summary>
77         Always,
78
79         /// <summary>
80         /// None of the days can be selected.
81         /// </summary>
82         None,
83
84         /// <summary>
85         /// User may have selected a day.
86         /// </summary>
87         OnDemand
88     }
89
90     /// <summary>
91     /// Enumeration for defining which fields of a tm struct will be taken into account.
92     /// </summary>
93     /// <since_tizen> preview </since_tizen>
94     [Obsolete("This has been deprecated in API12")]
95     [Flags]
96     public enum CalendarSelectable
97     {
98         /// <summary>
99         /// None will be taken into account.
100         /// </summary>
101         None = 0,
102         /// <summary>
103         /// Year will be taken into account.
104         /// </summary>
105         Year = 1 << 0,
106         /// <summary>
107         /// Month will be taken into account.
108         /// </summary>
109         Month = 1 << 1,
110         /// <summary>
111         /// Day will be taken into account.
112         /// </summary>
113         Day = 1 << 2
114     }
115
116     /// <summary>
117     /// The CalendarMark is an item for marking a Calendar's type, date, and repeat type.
118     /// </summary>
119     /// <since_tizen> preview </since_tizen>
120     [Obsolete("This has been deprecated in API12")]
121     public class CalendarMark
122     {
123         internal IntPtr Handle;
124
125         /// <summary>
126         /// A string used to define the type of mark.
127         /// </summary>
128         /// <since_tizen> preview </since_tizen>
129         [Obsolete("This has been deprecated in API12")]
130         public string Type;
131
132         /// <summary>
133         /// A time struct to represent the date of inclusion of the mark.
134         /// </summary>
135         /// <since_tizen> preview </since_tizen>
136         [Obsolete("This has been deprecated in API12")]
137         public DateTime Date;
138
139         /// <summary>
140         /// Repeats the event following this periodicity.
141         /// </summary>
142         /// <since_tizen> preview </since_tizen>
143         [Obsolete("This has been deprecated in API12")]
144         public CalendarMarkRepeatType Repeat;
145
146         /// <summary>
147         /// Creates and initializes a new instance of the CalendarMark class.
148         /// </summary>
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)
155         {
156             Handle = IntPtr.Zero;
157             Type = type;
158             Date = date;
159             Repeat = repeat;
160         }
161     }
162
163     /// <summary>
164     /// The Calendar is a widget that helps applications to flexibly display a calender with day of the week, date, year, and month.
165     /// </summary>
166     /// <since_tizen> preview </since_tizen>
167     [Obsolete("This has been deprecated in API12")]
168     public class Calendar : Layout
169     {
170         SmartEvent _changed;
171         DateTime _cacheSelectedDate;
172         SmartEvent _displayedMonthChanged;
173         int _cacheDisplayedMonth;
174
175         Interop.Elementary.Elm_Calendar_Format_Cb _calendarFormat;
176         DateFormatDelegate _dateFormatDelegate = null;
177
178         /// <summary>
179         /// Creates and initializes a new instance of the Calendar class.
180         /// </summary>
181         /// <param name="parent">
182         /// The EvasObject to which the new calendar will be attached as a child.
183         /// </param>
184         /// <since_tizen> preview </since_tizen>
185         [Obsolete("This has been deprecated in API12")]
186         public Calendar(EvasObject parent) : base(parent)
187         {
188             _changed = new SmartEvent(this, this.RealHandle, "changed");
189             _changed.On += (sender, e) =>
190             {
191                 DateTime selectedDate = SelectedDate;
192                 DateChanged?.Invoke(this, new DateChangedEventArgs(_cacheSelectedDate, selectedDate));
193                 _cacheSelectedDate = selectedDate;
194             };
195
196             _displayedMonthChanged = new SmartEvent(this, this.RealHandle, "display,changed");
197             _displayedMonthChanged.On += (sender, e) =>
198             {
199                 int currentDisplayedMonth = DisplayedTime.Month;
200                 DisplayedMonthChanged?.Invoke(this, new DisplayedMonthChangedEventArgs(_cacheDisplayedMonth, currentDisplayedMonth));
201                 _cacheDisplayedMonth = currentDisplayedMonth;
202             };
203
204             _calendarFormat = (ref Interop.Libc.SystemTime t) => { return _dateFormatDelegate(t); };
205         }
206
207         /// <summary>
208         /// DateChanged will be triggered when the date in the calendar is changed.
209         /// </summary>
210         /// <since_tizen> preview </since_tizen>
211         [Obsolete("This has been deprecated in API12")]
212         public event EventHandler<DateChangedEventArgs> DateChanged;
213
214         /// <summary>
215         /// DisplayedMonthChanged will be triggered when the current month displayed in the calendar is changed.
216         /// </summary>
217         /// <since_tizen> preview </since_tizen>
218         [Obsolete("This has been deprecated in API12")]
219         public event EventHandler<DisplayedMonthChangedEventArgs> DisplayedMonthChanged;
220
221         /// <summary>
222         /// This delegate type is used to format the string that will be used to display month and year.
223         /// </summary>
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);
229
230         /// <summary>
231         /// Sets or gets the minimum for year.
232         /// </summary>
233         /// <since_tizen> preview </since_tizen>
234         [Obsolete("This has been deprecated in API12")]
235         public int MinimumYear
236         {
237             get
238             {
239                 int minimumYear;
240                 int unused;
241                 Interop.Elementary.elm_calendar_min_max_year_get(RealHandle, out minimumYear, out unused);
242                 return minimumYear;
243             }
244             set
245             {
246                 int maximumYear;
247                 int unused;
248                 Interop.Elementary.elm_calendar_min_max_year_get(RealHandle, out unused, out maximumYear);
249                 if (maximumYear < 1902)
250                 {
251                     maximumYear = DateTime.MaxValue.Year;
252                 }
253                 Interop.Elementary.elm_calendar_min_max_year_set(RealHandle, value, maximumYear);
254             }
255         }
256
257         /// <summary>
258         /// Sets or gets the maximum for the year.
259         /// </summary>
260         /// <since_tizen> preview </since_tizen>
261         [Obsolete("This has been deprecated in API12")]
262         public int MaximumYear
263         {
264             get
265             {
266                 int maximumYear;
267                 int unused;
268                 Interop.Elementary.elm_calendar_min_max_year_get(RealHandle, out unused, out maximumYear);
269                 return maximumYear;
270             }
271             set
272             {
273                 int minimumYear;
274                 int unused;
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);
277             }
278         }
279
280         /// <summary>
281         /// Sets or gets the first day of the week, which is used on the calendar.
282         /// </summary>
283         /// <since_tizen> preview </since_tizen>
284         [Obsolete("This has been deprecated in API12")]
285         public DateTime DisplayedTime
286         {
287             get
288             {
289                 Interop.Elementary.elm_calendar_displayed_time_get(RealHandle, out Interop.Libc.SystemTime tm);
290                 // TODO
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;
294
295                 if (day > daysInMonth)
296                 {
297                     day = daysInMonth;
298                 }
299
300                 DateTime date = new DateTime(tm.tm_year + 1900, tm.tm_mon + 1, day, tm.tm_hour, tm.tm_min, tm.tm_sec);
301
302                 return date;
303             }
304         }
305
306         /// <summary>
307         /// Sets or gets the first day of the week, which is used on the calendar.
308         /// </summary>
309         /// <since_tizen> preview </since_tizen>
310         [Obsolete("This has been deprecated in API12")]
311         public DayOfWeek FirstDayOfWeek
312         {
313             get
314             {
315                 return (DayOfWeek)Interop.Elementary.elm_calendar_first_day_of_week_get(RealHandle);
316             }
317             set
318             {
319                 Interop.Elementary.elm_calendar_first_day_of_week_set(RealHandle, (int)value);
320             }
321         }
322
323         /// <summary>
324         /// Sets or gets the weekdays name to be displayed by the calendar.
325         /// </summary>
326         /// <remarks>
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;
330         /// </remarks>
331         /// <since_tizen> preview </since_tizen>
332         [Obsolete("This has been deprecated in API12")]
333         public IReadOnlyList<string> WeekDayNames
334         {
335             get
336             {
337                 IntPtr stringArrayPtr = Interop.Elementary.elm_calendar_weekdays_names_get(RealHandle);
338                 string[] stringArray;
339                 IntPtrToStringArray(stringArrayPtr, 7, out stringArray);
340                 return stringArray;
341             }
342             set
343             {
344                 if (value != null && value.Count == 7)
345                 {
346                     Interop.Elementary.elm_calendar_weekdays_names_set(RealHandle, value.ToArray());
347                 }
348             }
349         }
350
351         /// <summary>
352         /// Sets or gets the selected date.
353         /// </summary>
354         /// <remarks>
355         /// The selected date changes when the user goes to the next/previous month or selects a day pressing over it on the calendar.
356         /// </remarks>
357         /// <since_tizen> preview </since_tizen>
358         [Obsolete("This has been deprecated in API12")]
359         public DateTime SelectedDate
360         {
361             get
362             {
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)
366                 {
367                     return DateTime.Now;
368                 }
369                 return tm;
370             }
371             set
372             {
373                 Interop.Libc.SystemTime tm = value;
374                 Interop.Elementary.elm_calendar_selected_time_set(RealHandle, ref tm);
375                 _cacheSelectedDate = value;
376             }
377         }
378
379         /// <summary>
380         /// Sets or gets the interval on time updates for a user mouse button
381         /// hold, on the calendar widgets' month/year selection.
382         /// </summary>
383         /// <since_tizen> preview </since_tizen>
384         [Obsolete("This has been deprecated in API12")]
385         public double Interval
386         {
387             get
388             {
389                 return Interop.Elementary.elm_calendar_interval_get(RealHandle);
390             }
391             set
392             {
393                 Interop.Elementary.elm_calendar_interval_set(RealHandle, value);
394             }
395         }
396
397         /// <summary>
398         /// Gets or sets the select day mode used.
399         /// </summary>
400         /// <since_tizen> preview </since_tizen>
401         [Obsolete("This has been deprecated in API12")]
402         public CalendarSelectMode SelectMode
403         {
404             get
405             {
406                 return (CalendarSelectMode)Interop.Elementary.elm_calendar_select_mode_get(RealHandle);
407             }
408             set
409             {
410                 Interop.Elementary.elm_calendar_select_mode_set(RealHandle, (Interop.Elementary.Elm_Calendar_Select_Mode)value);
411             }
412         }
413
414         /// <summary>
415         /// Gets or sets the fields of a datetime that will be taken into account, when SelectedDate set is invoked.
416         /// </summary>
417         /// <since_tizen> preview </since_tizen>
418         [Obsolete("This has been deprecated in API12")]
419         public CalendarSelectable Selectable
420         {
421             get
422             {
423                 return (CalendarSelectable)Interop.Elementary.elm_calendar_selectable_get(RealHandle);
424             }
425             set
426             {
427                 Interop.Elementary.elm_calendar_selectable_set(RealHandle, (int)value);
428             }
429         }
430
431         /// <summary>
432         /// Gets or sets the date format of the string that will be used to display month and year.
433         /// </summary>
434         /// <since_tizen> preview </since_tizen>
435         [Obsolete("This has been deprecated in API12")]
436         public DateFormatDelegate DateFormat
437         {
438             get
439             {
440                 return _dateFormatDelegate;
441             }
442             set
443             {
444                 _dateFormatDelegate = value;
445                 if (value != null)
446                 {
447                     Interop.Elementary.elm_calendar_format_function_set(RealHandle, _calendarFormat);
448                 }
449                 else
450                 {
451                     Interop.Elementary.elm_calendar_format_function_set(RealHandle, null);
452                 }
453             }
454         }
455
456         /// <summary>
457         /// Adds a new mark to the calendar.
458         /// </summary>
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)
466         {
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;
471
472             return mark;
473         }
474
475         /// <summary>
476         /// Deletes a mark from the calendar.
477         /// </summary>
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)
482         {
483             Interop.Elementary.elm_calendar_mark_del(mark.Handle);
484         }
485
486         /// <summary>
487         /// Draws the calendar marks.
488         /// </summary>
489         /// <since_tizen> preview </since_tizen>
490         [Obsolete("This has been deprecated in API12")]
491         public void DrawMarks()
492         {
493             Interop.Elementary.elm_calendar_marks_draw(RealHandle);
494         }
495
496         /// <summary>
497         /// Removes all the calendar's marks.
498         /// </summary>
499         /// <since_tizen> preview </since_tizen>
500         [Obsolete("This has been deprecated in API12")]
501         public void ClearMarks()
502         {
503             Interop.Elementary.elm_calendar_marks_clear(RealHandle);
504         }
505
506         /// <summary>
507         /// Creates a widget handle.
508         /// </summary>
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)
514         {
515             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
516             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
517
518             RealHandle = Interop.Elementary.elm_calendar_add(handle);
519             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
520
521             return handle;
522         }
523
524         static void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
525         {
526             managedArray = new string[size];
527             IntPtr[] IntPtrArray = new IntPtr[size];
528
529             Marshal.Copy(unmanagedArray, IntPtrArray, 0, size);
530
531             for (int iterator = 0; iterator < size; iterator++)
532             {
533                 managedArray[iterator] = Marshal.PtrToStringAnsi(IntPtrArray[iterator]);
534             }
535         }
536     }
537 }