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.
19 using System.ComponentModel;
24 /// Widget provides some common functionality required by all custom widget.
26 /// <since_tizen> 4 </since_tizen>
27 public class Widget : BaseHandle
29 internal WidgetImpl widgetImpl;
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.New(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 as WidgetApplication)?.AddWidgetInstance(this);
53 internal Widget(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Widget.Upcast(cPtr), cMemoryOwn)
58 /// Enumeration for termination type of widget
60 /// <since_tizen> 4 </since_tizen>
61 public enum TerminationType
64 /// User deleted this widget from the viewer
66 /// <since_tizen> 4 </since_tizen>
69 /// Widget is deleted because of other reasons (e.g. widget process is terminated temporarily by system)
71 /// <since_tizen> 4 </since_tizen>
76 /// Set content info to WidgetView.
78 /// <param name="contentInfo">Content info is kind of context information which contains current status of widget.</param>
79 /// <since_tizen> 4 </since_tizen>
80 public void SetContentInfo(string contentInfo)
82 widgetImpl.SetContentInfo(contentInfo);
85 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Widget obj)
87 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
90 internal System.IntPtr GetIntPtr()
92 return SwigCPtr.Handle;
94 internal Widget Assign(Widget widget)
96 Widget ret = new Widget(Interop.Widget.Assign(SwigCPtr, Widget.getCPtr(widget)), false);
97 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102 /// The user should override this function to determine when they create widget.
104 /// <param name="contentInfo">Information from WidgetView for creating. It contains previous status of widget which is sent by SetContentInfo before.</param>
105 /// <param name="window">Window for widget</param>
106 /// <since_tizen> 4 </since_tizen>
107 protected virtual void OnCreate(string contentInfo, Window window)
112 /// The user should override this function to determine when they terminate widget.
114 /// <param name="contentInfo">Data from WidgetView for deleting</param>
115 /// <param name="type">Termination type. When user delete widget view, termination type is PERMANENT.</param>
116 /// <since_tizen> 4 </since_tizen>
117 protected virtual void OnTerminate(string contentInfo, Widget.TerminationType type)
122 /// The user should override this function to determine when they pause widget.
124 /// <since_tizen> 4 </since_tizen>
125 protected virtual void OnPause()
130 /// The user should override this function to determine when they resume widget.
132 /// <since_tizen> 4 </since_tizen>
133 protected virtual void OnResume()
138 /// The user should override this function to determine when they resize widget.
140 /// <param name="window">Window for widget</param>
141 /// <since_tizen> 4 </since_tizen>
142 protected virtual void OnResize(Window window)
147 /// The user should override this function to determine when they update widget.
149 /// <param name="contentInfo">Data from WidgetView for updating</param>
150 /// <param name="force">Although the widget is paused, if it is true, the widget can be updated</param>
151 /// <since_tizen> 4 </since_tizen>
152 protected virtual void OnUpdate(string contentInfo, int force)
156 /// This will not be public opened.
157 [EditorBrowsable(EditorBrowsableState.Never)]
158 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
160 Interop.Widget.DeleteWidget(swigCPtr);
163 private void OnWidgetInstanceCreated(object sender, WidgetImpl.WIdgetInstanceOnCreateArgs e)
165 OnCreate(e.ContentInfo, e.Window);
168 private void OnWidgetInstanceDestroyed(object sender, WidgetImpl.WIdgetInstanceOnDestroyArgs e)
170 OnTerminate(e.ContentInfo, e.TerminateType);
173 private void OnWidgetInstancePaused(object sender, EventArgs e)
178 private void OnWidgetInstanceResumed(object sender, EventArgs e)
183 private void OnWidgetInstanceResized(object sender, WidgetImpl.WidgetInstanceOnResizeArgs e)
188 private void OnWidgetInstanceUpdated(object sender, WidgetImpl.WidgetInstanceOnUpdateArgs e)
190 OnUpdate(e.ContentInfo, e.Force);