[NUI] Fix build warning[CA1064]
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Widget.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// Widget provides some common functionality required by all custom widget.
25     /// </summary>
26     /// <since_tizen> 4 </since_tizen>
27     public class Widget : BaseHandle
28     {
29         internal WidgetImpl widgetImpl;
30
31         /// <summary>
32         /// Creates a Widget handle.
33         /// </summary>
34         /// <since_tizen> 4 </since_tizen>
35         public Widget() : this(new WidgetImpl(), true)
36         {
37             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
38         }
39
40         internal Widget(WidgetImpl widgetImpl, bool swigCMemOwn) : this(Interop.Widget.New(WidgetImpl.getCPtr(widgetImpl)), swigCMemOwn)
41         {
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;
49
50             (WidgetApplication.Instance as WidgetApplication)?.AddWidgetInstance(this);
51         }
52
53         internal Widget(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Widget.Upcast(cPtr), cMemoryOwn)
54         {
55         }
56
57         /// <summary>
58         /// Enumeration for termination type of widget
59         /// </summary>
60         /// <since_tizen> 4 </since_tizen>
61         public enum TerminationType
62         {
63             /// <summary>
64             /// User deleted this widget from the viewer
65             /// </summary>
66             /// <since_tizen> 4 </since_tizen>
67             Permanent,
68             /// <summary>
69             /// Widget is deleted because of other reasons (e.g. widget process is terminated temporarily by system)
70             /// </summary>
71             /// <since_tizen> 4 </since_tizen>
72             Temporary
73         }
74
75         /// <summary>
76         /// Set content info to WidgetView.
77         /// </summary>
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)
81         {
82             widgetImpl.SetContentInfo(contentInfo);
83         }
84
85         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Widget obj)
86         {
87             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
88         }
89
90         internal System.IntPtr GetIntPtr()
91         {
92             return swigCPtr.Handle;
93         }
94         internal Widget Assign(Widget widget)
95         {
96             Widget ret = new Widget(Interop.Widget.Assign(swigCPtr, Widget.getCPtr(widget)), false);
97             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98             return ret;
99         }
100
101         /// <summary>
102         /// The user should override this function to determine when they create widget.
103         /// </summary>
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)
108         {
109         }
110
111         /// <summary>
112         /// The user should override this function to determine when they terminate widget.
113         /// </summary>
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)
118         {
119         }
120
121         /// <summary>
122         /// The user should override this function to determine when they pause widget.
123         /// </summary>
124         /// <since_tizen> 4 </since_tizen>
125         protected virtual void OnPause()
126         {
127         }
128
129         /// <summary>
130         /// The user should override this function to determine when they resume widget.
131         /// </summary>
132         /// <since_tizen> 4 </since_tizen>
133         protected virtual void OnResume()
134         {
135         }
136
137         /// <summary>
138         /// The user should override this function to determine when they resize widget.
139         /// </summary>
140         /// <param name="window">Window for widget</param>
141         /// <since_tizen> 4 </since_tizen>
142         protected virtual void OnResize(Window window)
143         {
144         }
145
146         /// <summary>
147         /// The user should override this function to determine when they update widget.
148         /// </summary>
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)
153         {
154         }
155
156         /// This will not be public opened.
157         [EditorBrowsable(EditorBrowsableState.Never)]
158         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
159         {
160             Interop.Widget.DeleteWidget(swigCPtr);
161         }
162
163         private void OnWidgetInstanceCreated(object sender, WidgetImpl.WIdgetInstanceOnCreateArgs e)
164         {
165             OnCreate(e.ContentInfo, e.Window);
166         }
167
168         private void OnWidgetInstanceDestroyed(object sender, WidgetImpl.WIdgetInstanceOnDestroyArgs e)
169         {
170             OnTerminate(e.ContentInfo, e.TerminateType);
171         }
172
173         private void OnWidgetInstancePaused(object sender, EventArgs e)
174         {
175             OnPause();
176         }
177
178         private void OnWidgetInstanceResumed(object sender, EventArgs e)
179         {
180             OnResume();
181         }
182
183         private void OnWidgetInstanceResized(object sender, WidgetImpl.WidgetInstanceOnResizeArgs e)
184         {
185             OnResize(e.Window);
186         }
187
188         private void OnWidgetInstanceUpdated(object sender, WidgetImpl.WidgetInstanceOnUpdateArgs e)
189         {
190             OnUpdate(e.ContentInfo, e.Force);
191         }
192     }
193 }