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.
18 using System.Collections.Generic;
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Binding;
23 namespace Tizen.NUI.Components
26 /// The control component is base class of tv nui components. It's abstract class, so cann't instantiate and can only be inherited.
28 /// <since_tizen> 6 </since_tizen>
29 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public class Control : VisualView
33 /// <summary> Control style. </summary>
34 /// <since_tizen> 6 </since_tizen>
35 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
36 [EditorBrowsable(EditorBrowsableState.Never)]
37 protected string style;
39 private TapGestureDetector tapGestureDetector = new TapGestureDetector();
41 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
42 [EditorBrowsable(EditorBrowsableState.Never)]
43 public ControlStyle Style => ViewStyle as ControlStyle;
48 /// Construct an empty Control.
50 /// <since_tizen> 6 </since_tizen>
51 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
52 [EditorBrowsable(EditorBrowsableState.Never)]
53 public Control() : base()
55 var cur_type = this.GetType();
56 ViewStyle viewStyle = null;
60 if (cur_type.Equals(typeof(Tizen.NUI.Components.Control))) break;
61 viewStyle = StyleManager.Instance.GetComponentStyle(cur_type);
62 cur_type = cur_type.BaseType;
64 while (viewStyle == null);
66 if (viewStyle != null)
68 ApplyStyle(viewStyle);
75 /// Construct with style.
77 /// <param name="style">Create control with style.</param>
78 /// <since_tizen> 6 </since_tizen>
79 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
80 [EditorBrowsable(EditorBrowsableState.Never)]
81 public Control(ControlStyle style) : base(style)
87 /// Construct with styleSheet
89 /// <param name="styleSheet">StyleSheet to be applied</param>
90 /// <since_tizen> 6 </since_tizen>
91 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
92 [EditorBrowsable(EditorBrowsableState.Never)]
93 public Control(string styleSheet) : base()
95 ViewStyle viewStyle = StyleManager.Instance.GetViewStyle(styleSheet);
96 if (viewStyle == null)
98 throw new InvalidOperationException($"There is no style {styleSheet}");
101 ApplyStyle(viewStyle);
102 this.style = styleSheet;
107 internal void ApplyAttributes(View view, ViewStyle viewStyle)
109 view.CopyFrom(viewStyle);
113 /// Whether focusable when touch
115 /// <since_tizen> 6 </since_tizen>
116 internal bool StateFocusableOnTouchMode { get; set; }
118 internal bool IsFocused { get; set; } = false;
121 /// Dispose Control and all children on it.
123 /// <param name="type">Dispose type.</param>
124 /// <since_tizen> 6 </since_tizen>
125 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 protected override void Dispose(DisposeTypes type)
134 if (type == DisposeTypes.Explicit)
136 StyleManager.Instance.ThemeChangedEvent -= OnThemeChangedEvent;
137 tapGestureDetector.Detected -= OnTapGestureDetected;
138 tapGestureDetector.Detach(this);
145 /// Called after a key event is received by the view that has had its focus set.
147 /// <param name="key">The key event.</param>
148 /// <returns>True if the key event should be consumed.</returns>
149 /// <since_tizen> 6 </since_tizen>
150 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 public override bool OnKey(Key key)
158 /// Called after the size negotiation has been finished for this control.<br />
159 /// The control is expected to assign this given size to itself or its children.<br />
160 /// 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 />
161 /// As this function is called from inside the size negotiation algorithm, you cannot call RequestRelayout (the call would just be ignored).<br />
163 /// <param name="size">The allocated size.</param>
164 /// <param name="container">The control should add views to this container that it is not able to allocate a size for.</param>
165 /// <since_tizen> 6 </since_tizen>
166 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
167 [EditorBrowsable(EditorBrowsableState.Never)]
168 public override void OnRelayout(Vector2 size, RelayoutContainer container)
170 base.OnRelayout(size, container);
175 /// 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.
177 /// <since_tizen> 6 </since_tizen>
178 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
179 [EditorBrowsable(EditorBrowsableState.Never)]
180 public override void OnFocusGained()
186 /// 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.
188 /// <since_tizen> 6 </since_tizen>
189 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
190 [EditorBrowsable(EditorBrowsableState.Never)]
191 public override void OnFocusLost()
197 /// Tap gesture callback.
199 /// <param name="source">The sender</param>
200 /// <param name="e">The tap gesture event data</param>
201 /// <since_tizen> 6 </since_tizen>
202 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
203 [EditorBrowsable(EditorBrowsableState.Never)]
204 protected virtual void OnTapGestureDetected(object source, TapGestureDetector.DetectedEventArgs e) { }
207 /// Called after a touch event is received by the owning view.<br />
208 /// CustomViewBehaviour.REQUIRES_TOUCH_EVENTS must be enabled during construction. See CustomView(ViewWrapperImpl.CustomViewBehaviour behaviour).<br />
210 /// <param name="touch">The touch event.</param>
211 /// <returns>True if the event should be consumed.</returns>
212 /// <since_tizen> 6 </since_tizen>
213 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
214 [EditorBrowsable(EditorBrowsableState.Never)]
215 public override bool OnTouch(Touch touch)
217 // Handle Normal and Pressed states
218 PointStateType state = touch.GetState(0);
221 case PointStateType.Down:
222 ControlState = ControlStates.Pressed;
224 case PointStateType.Interrupted:
225 case PointStateType.Up:
226 if (ControlState == ControlStates.Pressed)
228 ControlState = ControlStates.Normal;
240 /// <since_tizen> 6 </since_tizen>
241 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
242 [EditorBrowsable(EditorBrowsableState.Never)]
243 protected virtual void OnUpdate()
248 /// Theme change callback when theme is changed, this callback will be trigger.
250 /// <param name="sender">The sender</param>
251 /// <param name="e">The event data</param>
252 /// <since_tizen> 6 </since_tizen>
253 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
254 [EditorBrowsable(EditorBrowsableState.Never)]
255 protected virtual void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e) { }
257 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
258 [EditorBrowsable(EditorBrowsableState.Never)]
259 protected virtual void RegisterDetectionOfSubstyleChanges() { }
261 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
262 [EditorBrowsable(EditorBrowsableState.Never)]
263 protected override ViewStyle CreateViewStyle()
265 return new ControlStyle();
268 private void Initialize(string style)
270 ControlState = ControlStates.Normal;
272 RegisterDetectionOfSubstyleChanges();
274 LeaveRequired = true;
276 StateFocusableOnTouchMode = false;
278 tapGestureDetector.Attach(this);
279 tapGestureDetector.Detected += OnTapGestureDetected;
281 StyleManager.Instance.ThemeChangedEvent += OnThemeChangedEvent;