2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Binding;
22 using System.Windows.Input;
25 namespace Tizen.NUI.Components
28 /// The control component is base class of tv nui components. It's abstract class, so can't instantiate and can only be inherited.
30 /// <since_tizen> 6 </since_tizen>
31 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
32 [EditorBrowsable(EditorBrowsableState.Never)]
33 public class Control : VisualView
36 [EditorBrowsable(EditorBrowsableState.Never)]
37 public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(Control), null, propertyChanged: (bo, o, n) => ((Control)bo).OnCommandChanged());
40 [EditorBrowsable(EditorBrowsableState.Never)]
41 public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(Button), null,
42 propertyChanged: (bindable, oldvalue, newvalue) => ((Button)bindable).CommandCanExecuteChanged(bindable, EventArgs.Empty));
44 private bool onThemeChangedEventOverrideChecker;
46 private Feedback feedback = null;
50 ThemeManager.AddPackageTheme(DefaultThemeCreator.Instance);
54 /// This is used to improve theme performance.
56 [EditorBrowsable(EditorBrowsableState.Never)]
57 static public void Preload()
59 DefaultThemeCreator.Preload();
63 /// Construct an empty Control.
65 /// <since_tizen> 6 </since_tizen>
66 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
67 [EditorBrowsable(EditorBrowsableState.Never)]
68 public Control() : this((ControlStyle)null)
73 /// Construct with style.
75 /// <param name="style">Create control with style.</param>
76 /// <since_tizen> 6 </since_tizen>
77 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
78 [EditorBrowsable(EditorBrowsableState.Never)]
79 public Control(ControlStyle style) : base(style)
84 /// Construct with style name
86 /// <param name="styleName">The name of style in the current theme to be applied</param>
87 /// <since_tizen> 6 </since_tizen>
88 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
89 [EditorBrowsable(EditorBrowsableState.Never)]
90 public Control(string styleName) : base(ThemeManager.GetInitialStyleWithoutClone(styleName) ?? throw new InvalidOperationException($"There is no style {styleName}"))
92 this.styleName = styleName;
98 /// Enable/Disable a sound feedback when tap gesture detected.
100 [EditorBrowsable(EditorBrowsableState.Never)]
103 get => feedback != null;
106 if (value == (feedback != null))
113 feedback = new Feedback();
114 this.TouchEvent += OnTouchPlayFeedback;
118 this.TouchEvent -= OnTouchPlayFeedback;
124 private bool OnTouchPlayFeedback(object source, TouchEventArgs e)
126 if (Feedback && e?.Touch.GetState(0) == PointStateType.Down)
128 if (feedback != null && feedback.IsSupportedPattern(FeedbackType.Sound, "Tap"))
130 feedback.Play(FeedbackType.Sound, "Tap");
137 [EditorBrowsable(EditorBrowsableState.Never)]
138 public ICommand Command
140 get { return (ICommand)GetValue(CommandProperty); }
141 set { SetValue(CommandProperty, value); }
145 [EditorBrowsable(EditorBrowsableState.Never)]
146 public object CommandParameter
148 get { return GetValue(CommandParameterProperty); }
149 set { SetValue(CommandParameterProperty, value); }
153 /// Whether focusable when touch
155 /// <since_tizen> 6 </since_tizen>
156 internal bool StateFocusableOnTouchMode { get; set; }
158 internal bool IsFocused { get; set; } = false;
160 internal void CommandCanExecuteChanged(object sender, EventArgs eventArgs)
162 ICommand cmd = Command;
164 cmd.CanExecute(CommandParameter);
167 internal void OnCommandChanged()
171 Command.CanExecuteChanged += CommandCanExecuteChanged;
172 CommandCanExecuteChanged(this, EventArgs.Empty);
177 /// Dispose Control and all children on it.
179 /// <param name="type">Dispose type.</param>
180 /// <since_tizen> 6 </since_tizen>
181 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
182 [EditorBrowsable(EditorBrowsableState.Never)]
183 protected override void Dispose(DisposeTypes type)
191 this.TouchEvent -= OnTouchPlayFeedback;
193 if (type == DisposeTypes.Explicit)
201 public override void OnInitialize()
205 LeaveRequired = true;
206 StateFocusableOnTouchMode = false;
207 EnableControlState = true;
211 /// Called after a key event is received by the view that has had its focus set.
213 /// <param name="key">The key event.</param>
214 /// <returns>True if the key event should be consumed.</returns>
215 /// <since_tizen> 6 </since_tizen>
216 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
217 [EditorBrowsable(EditorBrowsableState.Never)]
218 public override bool OnKey(Key key)
224 /// Called after the size negotiation has been finished for this control.<br />
225 /// The control is expected to assign this given size to itself or its children.<br />
226 /// Should be overridden by derived classes if they need to layout views differently after certain operations like add or remove views, resize, or after changing specific properties.<br />
227 /// As this function is called from inside the size negotiation algorithm, you cannot call RequestRelayout (the call would just be ignored).<br />
229 /// <param name="size">The allocated size.</param>
230 /// <param name="container">The control should add views to this container that it is not able to allocate a size for.</param>
231 /// <since_tizen> 6 </since_tizen>
232 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
233 [EditorBrowsable(EditorBrowsableState.Never)]
234 public override void OnRelayout(Vector2 size, RelayoutContainer container)
236 base.OnRelayout(size, container);
241 /// Called when the control gain key input focus. Should be overridden by derived classes if they need to customize what happens when the focus is gained.
243 /// <since_tizen> 6 </since_tizen>
244 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
245 [EditorBrowsable(EditorBrowsableState.Never)]
246 public override void OnFocusGained()
252 /// Called when the control loses key input focus. Should be overridden by derived classes if they need to customize what happens when the focus is lost.
254 /// <since_tizen> 6 </since_tizen>
255 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
256 [EditorBrowsable(EditorBrowsableState.Never)]
257 public override void OnFocusLost()
265 /// <since_tizen> 6 </since_tizen>
266 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
267 [EditorBrowsable(EditorBrowsableState.Never)]
268 protected virtual void OnUpdate()
273 /// Theme change callback when theme is changed, this callback will be trigger.
274 /// Note that it is deprecated API.Please use OnThemeChanged instead.
276 /// <param name="sender">The sender</param>
277 /// <param name="e">The event data</param>
278 /// <since_tizen> 6 </since_tizen>
279 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
280 [EditorBrowsable(EditorBrowsableState.Never)]
281 protected virtual void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
283 onThemeChangedEventOverrideChecker = false;
286 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
287 [EditorBrowsable(EditorBrowsableState.Never)]
288 protected override ViewStyle CreateViewStyle()
290 return new ControlStyle();
294 [EditorBrowsable(EditorBrowsableState.Never)]
295 protected override void OnThemeChanged(object sender, ThemeChangedEventArgs e)
297 // TODO Remove checker after update Tizen.FH.NUI.
298 onThemeChangedEventOverrideChecker = true;
300 OnThemeChangedEvent(sender, new StyleManager.ThemeChangeEventArgs { CurrentTheme = e.ThemeId });
302 if (onThemeChangedEventOverrideChecker) return;
304 // If the OnThemeChangedEvent is not implemented, ApplyStyle()
305 base.OnThemeChanged(sender, e);