/*
* 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 of datetime field types for DateTimeSelector.
///
public enum DateTimeFieldType
{
///
/// Indicates Year field.
///
Year,
///
/// Indicates Month field.
///
Month,
///
/// Indicates Date field.
///
Date,
///
/// Indicates Hour field.
///
Hour,
///
/// Indicates Minute field.
///
Minute,
///
/// Indicates AM/PM field.
///
AmPm
}
///
/// It inherits
/// DateTimeSelector is a widget to display and input date & time values.
/// This widget displays date and time as per the system's locale settings
/// (Date includes Day, Month & Year along with the defined separators and Time includes Hour, Minute & AM/PM fields. Separator for AM/PM field is ignored.
///
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 DateTimeSelector
///as a child.It's type.
public DateTimeSelector(EvasObject parent) : base(parent)
{
}
///
/// Creates and initializes a new instance of DateTimeSelector class.
///
protected DateTimeSelector() : base()
{
}
///
/// ItemSelected is raised when Datetime field value changed.
///
public event EventHandler DateTimeChanged;
///
/// Gets or sets the datetime format.
///
///
/// format is a combination of allowed LIBC date format specifiers like: "%b %d, %Y %I : %M %p".
///
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 DateTime field.
///
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 DateTime field.
///
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 DateTime field.
///
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
///
/// The field is visible or not.
/// Type is bool.If visible, return true.
///
public bool IsFieldVisible(DateTimeFieldType type)
{
return Interop.Elementary.elm_datetime_field_visible_get(RealHandle, (int)type);
}
///
/// Sets the field limits of a field.
///
/// Enumeration
/// minimum limit
/// maximum limit
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
/// When set as true, the field type visible.
public void SetFieldVisible(DateTimeFieldType type, bool visible)
{
Interop.Elementary.elm_datetime_field_visible_set(RealHandle, (int)type, visible);
}
///
/// The callback of Realized Event
///
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
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;
}
}
}