/*
* Copyright(c) 2019 Samsung Electronics Co., Ltd.
*
* 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.ComponentModel;
using Tizen.NUI.Binding;
using Tizen.NUI.Components;
namespace Tizen.NUI.BaseComponents
{
///
/// Selector class, which is related by Control State, it is base class for other Selector.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public class Selector : BindableObject
{
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
public static implicit operator Selector(T value)
{
Selector selector = new Selector();
selector.All = value;
return selector;
}
///
/// All State.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public T All
{
get;
set;
}
///
/// Normal State.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public T Normal
{
get;
set;
}
///
/// Pressed State.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public T Pressed
{
get;
set;
}
///
/// Focused State.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public T Focused
{
get;
set;
}
///
/// Selected State.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public T Selected
{
get;
set;
}
///
/// Disabled State.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public T Disabled
{
get;
set;
}
///
/// DisabledFocused State.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public T DisabledFocused
{
get;
set;
}
///
/// SelectedFocused State.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
public T SelectedFocused
{
get;
set;
}
///
/// DisabledSelected State.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public T DisabledSelected
{
get;
set;
}
///
/// Other State.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public T Other
{
get;
set;
}
///
/// Get value by State.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public T GetValue(ControlStates state)
{
if(All != null)
{
return All;
}
switch(state)
{
case ControlStates.Normal:
return Normal != null? Normal : Other;
case ControlStates.Focused:
return Focused != null? Focused : Other;
case ControlStates.Pressed:
return Pressed != null? Pressed : Other;
case ControlStates.Disabled:
return Disabled != null? Disabled : Other;
case ControlStates.Selected:
return Selected != null? Selected : Other;
case ControlStates.DisabledFocused:
return DisabledFocused != null? DisabledFocused : Other;
case ControlStates.DisabledSelected:
return DisabledSelected != null? DisabledSelected : Other;
case ControlStates.SelectedFocused:
return SelectedFocused != null ? SelectedFocused : Other;
default:
return Other;
}
}
///
/// Clone function.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public void Clone(Selector selector)
{
All = selector.All;
Normal = selector.Normal;
Focused = selector.Focused;
Pressed = selector.Pressed;
Disabled = selector.Disabled;
Selected = selector.Selected;
DisabledSelected = selector.DisabledSelected;
DisabledFocused = selector.DisabledFocused;
SelectedFocused = selector.SelectedFocused;
Other = selector.Other;
}
}
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public class TriggerableSelector : Selector
{
public TriggerableSelector(View view, BindableProperty bindableProperty)
{
targetView = view;
targetBindableProperty = bindableProperty;
view.ControlStateChangeEvent += OnViewControlState;
}
///
/// Clone function.
///
/// 6
/// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public new void Clone(Selector selector)
{
base.Clone(selector);
if (null != targetView && null != GetValue(targetView.ControlState))
{
targetView.SetValue(targetBindableProperty, GetValue(targetView.ControlState));
}
}
private void OnViewControlState(View obj, ControlStates state)
{
if (null != obj && null != GetValue(state))
{
obj.SetValue(targetBindableProperty, GetValue(state));
}
}
private View targetView;
private BindableProperty targetBindableProperty;
}
internal static class SelectorHelper where T : class, Tizen.NUI.ICloneable
{
///
/// For the object type of T or Selector T, convert it to Selector T and return the cloned one.
/// Otherwise, return null.
///
static internal Selector Clone(object value)
{
var type = value?.GetType();
if (type == typeof(Selector))
{
var result = new Selector();
result.Clone((Selector)value);
return result;
}
if (type == typeof(T))
{
var result = new Selector();
result.Clone((T)value);
return result;
}
return null;
}
///
/// For the object type of T or Selector T, convert it to T and return the cloned one.
/// Otherwise, return null.
///
static internal T Clone(object value, View view)
{
var type = value?.GetType();
if (type == typeof(T))
{
return (T)((T)value).Clone();
}
if (type == typeof(Selector) && view != null)
{
Selector selector = (Selector)value;
T valueInState = selector.GetValue(view.ControlState);
return (T)valueInState?.Clone();
}
return null;
}
}
}