using System.ComponentModel;
using Tizen.NUI.BaseComponents;
using Tizen.NUI.Binding;
+using System.Windows.Input;
namespace Tizen.NUI.Components
{
[EditorBrowsable(EditorBrowsableState.Never)]
public class Control : VisualView
{
- /// <summary> BackgroundImageProperty</summary>
+ /// Internal used.
[EditorBrowsable(EditorBrowsableState.Never)]
- public new static readonly BindableProperty BackgroundImageProperty = BindableProperty.Create("ControlBackgroundImage", typeof(Selector<string>), typeof(Control), null, propertyChanged: (bindable, oldValue, newValue) =>
- {
- var control = (Control)bindable;
- if (null != newValue)
- {
- control.BackgroundImageSelector.Clone((Selector<string>)newValue);
- }
- },
- defaultValueCreator: (bindable) =>
- {
- var control = (Control)bindable;
- return control.BackgroundImageSelector;
- });
- /// <summary>BackgroundBorderProperty</summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public new static readonly BindableProperty BackgroundImageBorderProperty = BindableProperty.Create("ControlBackgroundImageBorder", typeof(Selector<Rectangle>), typeof(Control), default(Rectangle), propertyChanged: (bindable, oldValue, newValue) =>
- {
- var control = (Control)bindable;
- if (null != newValue)
- {
- control.backgroundImageBorderSelector.Clone((Selector<Rectangle>)newValue);
- }
- },
- defaultValueCreator: (bindable) =>
- {
- var control = (Control)bindable;
- return control.backgroundImageBorderSelector;
- });
- /// <summary> BackgroundColorProperty </summary>
+ public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(Control), null, propertyChanged: (bo, o, n) => ((Control)bo).OnCommandChanged());
+
+ /// Internal used.
[EditorBrowsable(EditorBrowsableState.Never)]
- public new static readonly BindableProperty BackgroundColorProperty = BindableProperty.Create("ControlBackgroundColor", typeof(Selector<Color>), typeof(Control), null, propertyChanged: (bindable, oldValue, newValue) =>
- {
- var control = (Control)bindable;
- if (null != newValue)
- {
- control.BackgroundColorSelector.Clone((Selector<Color>)newValue);
- }
- },
- defaultValueCreator: (bindable) =>
- {
- var control = (Control)bindable;
- return control.BackgroundColorSelector;
- });
+ public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(Button), null,
+ propertyChanged: (bindable, oldvalue, newvalue) => ((Button)bindable).CommandCanExecuteChanged(bindable, EventArgs.Empty));
+
/// <summary> Control style. </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- protected string style;
+ protected string StyleName { get; set; }
private TapGestureDetector tapGestureDetector = new TapGestureDetector();
- private bool isFocused = false;
-
- internal ImageView backgroundImage = new ImageView();
- internal ImageView shadowImage;
/// 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 ControlStyle Style => ViewStyle as ControlStyle;
+ static Control() { }
+
/// <summary>
/// Construct an empty Control.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public Control() : base()
{
+ var cur_type = this.GetType();
+ ViewStyle viewStyle = null;
+
+ do
+ {
+ if (cur_type.Equals(typeof(Tizen.NUI.Components.Control))) break;
+ viewStyle = StyleManager.Instance.GetComponentStyle(cur_type);
+ cur_type = cur_type.BaseType;
+ }
+ while (viewStyle == null);
+
+ if (viewStyle != null)
+ {
+ ApplyStyle(viewStyle);
+ }
+
Initialize(null);
}
/// <summary>
- /// Construct with attributes
+ /// Construct with style.
/// </summary>
- /// <param name="attributes">Create attributes customized by user</param>
+ /// <param name="style">Create control with style.</param>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- public Control(ControlStyle controlStyle) : base(controlStyle)
+ public Control(ControlStyle style) : base(style)
{
Initialize(null);
}
[EditorBrowsable(EditorBrowsableState.Never)]
public Control(string styleSheet) : base()
{
- ViewStyle viewStyle = StyleManager.Instance.GetAttributes(styleSheet);
+ ViewStyle viewStyle = StyleManager.Instance.GetViewStyle(styleSheet);
if (viewStyle == null)
{
throw new InvalidOperationException($"There is no style {styleSheet}");
}
ApplyStyle(viewStyle);
- this.style = styleSheet;
+ this.StyleName = styleSheet;
- Initialize(style);
+ Initialize(StyleName);
}
- private TriggerableSelector<string> _backgroundImageSelector;
- private TriggerableSelector<string> BackgroundImageSelector
- {
- get
- {
- if (null == _backgroundImageSelector)
- {
- _backgroundImageSelector = new TriggerableSelector<string>(backgroundImage, ImageView.ResourceUrlProperty);
- }
- return _backgroundImageSelector;
- }
- }
- private TriggerableSelector<Rectangle> _backgroundImageBorderSelector;
- private TriggerableSelector<Rectangle> backgroundImageBorderSelector
- {
- get
- {
- if (null == _backgroundImageBorderSelector)
- {
- _backgroundImageBorderSelector = new TriggerableSelector<Rectangle>(backgroundImage, ImageView.BorderProperty);
- }
- return _backgroundImageBorderSelector;
- }
- }
- private TriggerableSelector<Color> _backgroundColorSelector;
- private TriggerableSelector<Color> BackgroundColorSelector
- {
- get
- {
- if (null == _backgroundColorSelector)
- {
- _backgroundColorSelector = new TriggerableSelector<Color>(backgroundImage, View.BackgroundColorProperty);
- }
- return _backgroundColorSelector;
- }
- }
- /// <summary>
- /// Override view's BackgroundImage.
- /// </summary>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
+ /// Internal used.
[EditorBrowsable(EditorBrowsableState.Never)]
- public new Selector<string> BackgroundImage
+ public ICommand Command
{
- get => (Selector<string>)GetValue(BackgroundImageProperty);
- set => SetValue(BackgroundImageProperty, value);
+ get { return (ICommand)GetValue(CommandProperty); }
+ set { SetValue(CommandProperty, value); }
}
- /// <summary>
- /// Override view's BackgroundImageBorder.
- /// </summary>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public new Selector<Rectangle> BackgroundImageBorder
- {
- get => (Selector<Rectangle>)GetValue(BackgroundImageBorderProperty);
- set => SetValue(BackgroundImageBorderProperty, value);
- }
- /// <summary>
- /// Override view's BackgroundBorder.
- /// </summary>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
+ /// Internal used.
[EditorBrowsable(EditorBrowsableState.Never)]
- public new Selector<Color> BackgroundColor
+ public object CommandParameter
{
- get => (Selector<Color>)GetValue(BackgroundColorProperty);
- set => SetValue(BackgroundColorProperty, value);
+ get { return GetValue(CommandParameterProperty); }
+ set { SetValue(CommandParameterProperty, value); }
}
/// <summary>
- /// Shadow image.
+ /// Whether focusable when touch
/// </summary>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Selector<string> ShadowImage
+ /// <since_tizen> 6 </since_tizen>
+ internal bool StateFocusableOnTouchMode { get; set; }
+
+ internal bool IsFocused { get; set; } = false;
+
+ internal void CommandCanExecuteChanged(object sender, EventArgs eventArgs)
{
- get
- {
- return Style.Shadow.ResourceUrl;
- }
- set
- {
- Style.Shadow.ResourceUrl = value;
- }
+ ICommand cmd = Command;
+ if (cmd != null)
+ cmd.CanExecute(CommandParameter);
}
- /// <summary>
- /// Shadow image border.
- /// </summary>
- /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Selector<Rectangle> ShadowImageBorder
+ internal void OnCommandChanged()
{
- get
+ if (Command != null)
{
- return Style.Shadow.Border;
+ Command.CanExecuteChanged += CommandCanExecuteChanged;
+ CommandCanExecuteChanged(this, EventArgs.Empty);
}
- set
- {
- Style.Shadow.Border = value;
- }
- }
-
- internal void ApplyAttributes(View view, ViewStyle viewStyle)
- {
- view.CopyFrom(viewStyle);
}
/// <summary>
- /// Whether focusable when touch
- /// </summary>
- /// <since_tizen> 6 </since_tizen>
- internal bool StateFocusableOnTouchMode { get; set; }
-
- internal bool IsFocused => (isFocused || HasFocus());
-
- /// <summary>
/// Dispose Control and all children on it.
/// </summary>
/// <param name="type">Dispose type.</param>
tapGestureDetector.Detach(this);
}
- if (backgroundImage != null)
- {
- Utility.Dispose(backgroundImage);
- }
- if (shadowImage != null)
- {
- Utility.Dispose(shadowImage);
- }
-
base.Dispose(type);
}
[EditorBrowsable(EditorBrowsableState.Never)]
public override void OnRelayout(Vector2 size, RelayoutContainer container)
{
+ base.OnRelayout(size, container);
OnUpdate();
}
[EditorBrowsable(EditorBrowsableState.Never)]
public override void OnFocusGained()
{
- isFocused = true;
+ IsFocused = true;
}
/// <summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public override void OnFocusLost()
{
- isFocused = false;
- }
-
- /// 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 override void ApplyStyle(ViewStyle viewStyle)
- {
- base.ApplyStyle(viewStyle);
-
- ControlStyle controlStyle = viewStyle as ControlStyle;
-
- if (null != controlStyle?.Shadow)
- {
- if (null == shadowImage)
- {
- shadowImage = new ImageView()
- {
- WidthResizePolicy = ResizePolicyType.FillToParent,
- HeightResizePolicy = ResizePolicyType.FillToParent,
- };
- this.Add(shadowImage);
- shadowImage.LowerToBottom();
- }
-
- shadowImage.ApplyStyle(controlStyle.Shadow);
- }
- if (null != controlStyle.BackgroundImage)
- {
- backgroundImage.WidthResizePolicy = ResizePolicyType.FillToParent;
- backgroundImage.HeightResizePolicy = ResizePolicyType.FillToParent;
- this.Add(backgroundImage);
- }
+ IsFocused = false;
}
/// <summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool OnTouch(Touch touch)
{
+ // Handle Normal and Pressed states
+ PointStateType state = touch.GetState(0);
+ switch(state)
+ {
+ case PointStateType.Down:
+ ControlState = ControlStates.Pressed;
+ break;
+ case PointStateType.Interrupted:
+ case PointStateType.Up:
+ if (ControlState == ControlStates.Pressed)
+ {
+ ControlState = ControlStates.Normal;
+ }
+ break;
+ default:
+ break;
+ }
return false;
}
/// <summary>
- /// Update by attributes.
+ /// Update by style.
/// </summary>
/// <since_tizen> 6 </since_tizen>
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
/// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
- protected override ViewStyle GetViewStyle()
+ protected override ViewStyle CreateViewStyle()
{
return new ControlStyle();
}
StyleManager.Instance.ThemeChangedEvent += OnThemeChangedEvent;
}
-
- private ViewStyle GetAttributes(string style)
- {
- ViewStyle attributes = StyleManager.Instance.GetAttributes(style);
- if(attributes == null)
- {
- throw new InvalidOperationException($"There is no style {style}");
- }
- this.style = style;
- return attributes;
- }
}
}