/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
namespace ElmSharp
{
///
/// Enumeration for the datetime field types for DateTimeSelector.
///
/// preview
public enum DateTimeFieldType
{
///
/// Indicates the Year field.
///
Year,
///
/// Indicates the Month field.
///
Month,
///
/// Indicates the Date field.
///
Date,
///
/// Indicates the Hour field.
///
Hour,
///
/// Indicates the Minute field.
///
Minute,
///
/// Indicates the AM/PM field.
///
AmPm
}
///
/// It inherits .
/// The DateTimeSelector is a widget to display and input the date & time values.
/// This widget displays the date and time as per the system's locale settings
/// (Date includes Day, Month & Year) along with the defined separators and time including hour, minute & AM/PM fields. Separator for the AM/PM field is ignored.
///
/// preview
public class DateTimeSelector : Layout
{
SmartEvent _changed;
DateTime _cacheDateTime;
///
/// Creates and initializes a new instance of the DateTimeSelector class.
///
/// The parent is a given container, which will be attached by the DateTimeSelector
/// as a child. It's type.
/// preview
public DateTimeSelector(EvasObject parent) : base(parent)
{
}
///
/// Creates and initializes a new instance of the DateTimeSelector class.
///
/// preview
protected DateTimeSelector() : base()
{
}
///
/// ItemSelected is raised when the DateTime field value is changed.
///
/// preview
public event EventHandler DateTimeChanged;
///
/// Gets or sets the datetime format.
///
///
/// Format is a combination of the allowed LIBC date format specifiers like: "%b %d, %Y %I : %M %p".
///
/// preview
public string Format
{
get
{
return Interop.Elementary.elm_datetime_format_get(RealHandle);
}
set
{
Interop.Elementary.elm_datetime_format_set(RealHandle, value);
}
}
///
/// Gets or sets the upper boundary of the DateTime field.
///
/// preview
public DateTime MaximumDateTime
{
get
{
var tm = new Interop.Libc.SystemTime();
Interop.Elementary.elm_datetime_value_max_get(RealHandle, ref tm);
return tm;
}
set
{
Interop.Libc.SystemTime tm = value;
Interop.Elementary.elm_datetime_value_max_set(RealHandle, ref tm);
}
}
///
/// Gets or sets the lower boundary of the DateTime field.
///
/// preview
public DateTime MinimumDateTime
{
get
{
var tm = new Interop.Libc.SystemTime();
Interop.Elementary.elm_datetime_value_min_get(RealHandle, ref tm);
return tm;
}
set
{
Interop.Libc.SystemTime tm = value;
Interop.Elementary.elm_datetime_value_min_set(RealHandle, ref tm);
}
}
///
/// Gets or sets the current value of the DateTime field.
///
/// preview
public DateTime DateTime
{
get
{
var tm = new Interop.Libc.SystemTime();
Interop.Elementary.elm_datetime_value_get(RealHandle, ref tm);
return tm;
}
set
{
Interop.Libc.SystemTime tm = value;
Interop.Elementary.elm_datetime_value_set(RealHandle, ref tm);
_cacheDateTime = value;
}
}
///
/// Gets whether a field can be visible.
///
/// Enumeration for .
///
/// The field is visible or not.
/// Type is bool. If visible, return true.
///
/// preview
public bool IsFieldVisible(DateTimeFieldType type)
{
return Interop.Elementary.elm_datetime_field_visible_get(RealHandle, (int)type);
}
///
/// Sets the field limits of a field.
///
/// Enumeration for .
/// The minimum limit.
/// The maximum limit.
/// preview
public void SetFieldLimit(DateTimeFieldType type, int minimum, int maximum)
{
Interop.Elementary.elm_datetime_field_limit_set(RealHandle, (int)type, minimum, maximum);
}
///
/// Gets whether a field can be visible.
///
/// Enumeration for .
/// When set as true, the field type is visible.
/// preview
public void SetFieldVisible(DateTimeFieldType type, bool visible)
{
Interop.Elementary.elm_datetime_field_visible_set(RealHandle, (int)type, visible);
}
///
/// The callback of the Realized event.
///
/// preview
protected override void OnRealized()
{
base.OnRealized();
_changed = new SmartEvent(this, this.RealHandle, "changed");
_changed.On += (s, e) =>
{
DateTime newDateTime = DateTime;
DateTimeChanged?.Invoke(this, new DateChangedEventArgs(_cacheDateTime, newDateTime));
DateTime = newDateTime;
};
}
///
/// Creates a widget handle.
///
/// Parent EvasObject.
/// Handle IntPtr.
/// preview
protected override IntPtr CreateHandle(EvasObject parent)
{
IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
RealHandle = Interop.Elementary.elm_datetime_add(handle);
Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
return handle;
}
}
}