2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 *Z:\Desktop\shared\tizenfx\src\Tizen.NUI\src\public\BaseComponents\CustomView.cs
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.
23 /// Widget provides some common functionality required by all custom widget.
25 /// <since_tizen> 4 </since_tizen>
26 public class Widget : BaseHandle
28 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29 internal WidgetImpl widgetImpl;
31 internal Widget(WidgetImpl widgetImpl, bool swigCMemOwn) : this(NDalicManualPINVOKE.Widget_New__SWIG_1(WidgetImpl.getCPtr(widgetImpl)), swigCMemOwn)
33 this.widgetImpl = widgetImpl;
34 widgetImpl.WidgetInstanceCreated += OnWidgetInstanceCreated;
35 widgetImpl.WidgetInstanceDestroyed += OnWidgetInstanceDestroyed;
36 widgetImpl.WidgetInstancePaused += OnWidgetInstancePaused;
37 widgetImpl.WidgetInstanceResumed += OnWidgetInstanceResumed;
38 widgetImpl.WidgetInstanceResized += OnWidgetInstanceResized;
39 widgetImpl.WidgetInstanceUpdated += OnWidgetInstanceUpdated;
41 WidgetApplication.Instance?.AddWidgetInstance(this);
44 internal Widget(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.Widget_SWIGUpcast(cPtr), cMemoryOwn)
46 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
49 private void OnWidgetInstanceCreated(object sender, WidgetImpl.WIdgetInstanceOnCreateArgs e)
51 OnCreate(e.ContentInfo, e.Window);
54 private void OnWidgetInstanceDestroyed(object sender, WidgetImpl.WIdgetInstanceOnDestroyArgs e)
56 OnTerminate(e.ContentInfo, e.TerminateType);
59 private void OnWidgetInstancePaused(object sender, EventArgs e)
64 private void OnWidgetInstanceResumed(object sender, EventArgs e)
69 private void OnWidgetInstanceResized(object sender, WidgetImpl.WidgetInstanceOnResizeArgs e)
74 private void OnWidgetInstanceUpdated(object sender, WidgetImpl.WidgetInstanceOnUpdateArgs e)
76 OnUpdate(e.ContentInfo, e.Force);
79 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Widget obj)
81 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
87 /// <param name="type">The dispose type</param>
88 /// <since_tizen> 4 </since_tizen>
89 protected override void Dispose(DisposeTypes type)
96 if(type == DisposeTypes.Explicit)
99 //Release your own managed resources here.
100 //You should release all of your own disposable objects here.
103 if (swigCPtr.Handle != global::System.IntPtr.Zero)
108 NDalicManualPINVOKE.delete_Widget(swigCPtr);
110 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
116 /// Enumeration for termination type of widget
118 /// <since_tizen> 4 </since_tizen>
119 public enum TerminationType
122 /// User deleted this widget from the viewer
124 /// <since_tizen> 4 </since_tizen>
127 /// Widget is deleted because of other reasons (e.g. widget process is terminated temporarily by system)
129 /// <since_tizen> 4 </since_tizen>
134 /// Creates a Widget handle.
136 /// <since_tizen> 4 </since_tizen>
137 public Widget () : this (new WidgetImpl(), true) {
138 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141 internal Widget Assign(Widget widget)
143 Widget ret = new Widget(NDalicManualPINVOKE.Widget_Assign(swigCPtr, Widget.getCPtr(widget)), false);
144 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149 /// The user should override this function to determine when they create widget.
151 /// <param name="contentInfo">Information from WidgetView for creating. It contains previous status of widget which is sent by SetContentInfo before.</param>
152 /// <param name="window">Window for widget</param>
153 /// <since_tizen> 4 </since_tizen>
154 protected virtual void OnCreate(string contentInfo, Window window)
159 /// The user should override this function to determine when they terminate widget.
161 /// <param name="contentInfo">Data from WidgetView for deleting</param>
162 /// <param name="type">Termination type. When user delete widget view, termination type is PERMANENT.</param>
163 /// <since_tizen> 4 </since_tizen>
164 protected virtual void OnTerminate(string contentInfo, Widget.TerminationType type)
169 /// The user should override this function to determine when they pause widget.
171 /// <since_tizen> 4 </since_tizen>
172 protected virtual void OnPause()
177 /// The user should override this function to determine when they resume widget.
179 /// <since_tizen> 4 </since_tizen>
180 protected virtual void OnResume()
185 /// The user should override this function to determine when they resize widget.
187 /// <param name="window">Window for widget</param>
188 /// <since_tizen> 4 </since_tizen>
189 protected virtual void OnResize(Window window)
194 /// The user should override this function to determine when they update widget.
196 /// <param name="contentInfo">Data from WidgetView for updating</param>
197 /// <param name="force">Although the widget is paused, if it is true, the widget can be updated</param>
198 /// <since_tizen> 4 </since_tizen>
199 protected virtual void OnUpdate(string contentInfo, int force)
204 /// Set content info to WidgetView.
206 /// <param name="contentInfo">Content info is kind of context information which contains current status of widget.</param>
207 /// <since_tizen> 4 </since_tizen>
208 public void SetContentInfo(string contentInfo)
210 widgetImpl.SetContentInfo(contentInfo);
213 internal System.IntPtr GetIntPtr()
215 return swigCPtr.Handle;