2 * Copyright (c) 2017 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.
23 /// Widget provides some common functionality required by all custom widget.
25 /// <since_tizen> 4 </since_tizen>
26 public class Widget : BaseHandle
28 internal WidgetImpl widgetImpl;
29 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 /// Creates a Widget handle.
34 /// <since_tizen> 4 </since_tizen>
35 public Widget() : this(new WidgetImpl(), true)
37 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
40 internal Widget(WidgetImpl widgetImpl, bool swigCMemOwn) : this(Interop.Widget.Widget_New__SWIG_1(WidgetImpl.getCPtr(widgetImpl)), swigCMemOwn)
42 this.widgetImpl = widgetImpl;
43 widgetImpl.WidgetInstanceCreated += OnWidgetInstanceCreated;
44 widgetImpl.WidgetInstanceDestroyed += OnWidgetInstanceDestroyed;
45 widgetImpl.WidgetInstancePaused += OnWidgetInstancePaused;
46 widgetImpl.WidgetInstanceResumed += OnWidgetInstanceResumed;
47 widgetImpl.WidgetInstanceResized += OnWidgetInstanceResized;
48 widgetImpl.WidgetInstanceUpdated += OnWidgetInstanceUpdated;
50 WidgetApplication.Instance?.AddWidgetInstance(this);
53 internal Widget(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Widget.Widget_SWIGUpcast(cPtr), cMemoryOwn)
55 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
59 /// Enumeration for termination type of widget
61 /// <since_tizen> 4 </since_tizen>
62 public enum TerminationType
65 /// User deleted this widget from the viewer
67 /// <since_tizen> 4 </since_tizen>
70 /// Widget is deleted because of other reasons (e.g. widget process is terminated temporarily by system)
72 /// <since_tizen> 4 </since_tizen>
77 /// Set content info to WidgetView.
79 /// <param name="contentInfo">Content info is kind of context information which contains current status of widget.</param>
80 /// <since_tizen> 4 </since_tizen>
81 public void SetContentInfo(string contentInfo)
83 widgetImpl.SetContentInfo(contentInfo);
86 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Widget obj)
88 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
91 internal System.IntPtr GetIntPtr()
93 return swigCPtr.Handle;
95 internal Widget Assign(Widget widget)
97 Widget ret = new Widget(Interop.Widget.Widget_Assign(swigCPtr, Widget.getCPtr(widget)), false);
98 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103 /// The user should override this function to determine when they create widget.
105 /// <param name="contentInfo">Information from WidgetView for creating. It contains previous status of widget which is sent by SetContentInfo before.</param>
106 /// <param name="window">Window for widget</param>
107 /// <since_tizen> 4 </since_tizen>
108 protected virtual void OnCreate(string contentInfo, Window window)
113 /// The user should override this function to determine when they terminate widget.
115 /// <param name="contentInfo">Data from WidgetView for deleting</param>
116 /// <param name="type">Termination type. When user delete widget view, termination type is PERMANENT.</param>
117 /// <since_tizen> 4 </since_tizen>
118 protected virtual void OnTerminate(string contentInfo, Widget.TerminationType type)
123 /// The user should override this function to determine when they pause widget.
125 /// <since_tizen> 4 </since_tizen>
126 protected virtual void OnPause()
131 /// The user should override this function to determine when they resume widget.
133 /// <since_tizen> 4 </since_tizen>
134 protected virtual void OnResume()
139 /// The user should override this function to determine when they resize widget.
141 /// <param name="window">Window for widget</param>
142 /// <since_tizen> 4 </since_tizen>
143 protected virtual void OnResize(Window window)
148 /// The user should override this function to determine when they update widget.
150 /// <param name="contentInfo">Data from WidgetView for updating</param>
151 /// <param name="force">Although the widget is paused, if it is true, the widget can be updated</param>
152 /// <since_tizen> 4 </since_tizen>
153 protected virtual void OnUpdate(string contentInfo, int force)
160 /// <param name="type">The dispose type</param>
161 /// <since_tizen> 4 </since_tizen>
162 protected override void Dispose(DisposeTypes type)
169 if (swigCPtr.Handle != global::System.IntPtr.Zero)
174 Interop.Widget.delete_Widget(swigCPtr);
176 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
182 private void OnWidgetInstanceCreated(object sender, WidgetImpl.WIdgetInstanceOnCreateArgs e)
184 OnCreate(e.ContentInfo, e.Window);
187 private void OnWidgetInstanceDestroyed(object sender, WidgetImpl.WIdgetInstanceOnDestroyArgs e)
189 OnTerminate(e.ContentInfo, e.TerminateType);
192 private void OnWidgetInstancePaused(object sender, EventArgs e)
197 private void OnWidgetInstanceResumed(object sender, EventArgs e)
202 private void OnWidgetInstanceResized(object sender, WidgetImpl.WidgetInstanceOnResizeArgs e)
207 private void OnWidgetInstanceUpdated(object sender, WidgetImpl.WidgetInstanceOnUpdateArgs e)
209 OnUpdate(e.ContentInfo, e.Force);