2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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.
20 namespace Tizen.Applications
23 /// The abstract class for widget instances.
25 public abstract class WidgetBase
27 internal IntPtr Handle;
29 internal Widget BaseWindow;
30 protected static readonly string LogTag = typeof(WidgetBase).Namespace;
33 /// Window object for this widget instance.
34 /// It will be created after OnCreate method is invoked.
36 protected Widget Window;
41 public enum WidgetDestroyType
44 /// User deleted this widget from the viewer.
49 /// Widget is deleted because of other reasons. (For e.g., widget process is terminated temporarily by the system)
62 /// Sets the content information to the widget.
64 /// <param name="info">The data set to save.</param>
65 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
66 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
67 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
68 public void SetContent(Bundle info)
70 Interop.Widget.ErrorCode err = Interop.Widget.SetContent(Handle, info.SafeBundleHandle);
72 if (err != Interop.Widget.ErrorCode.None)
74 Log.Error(LogTag, "Failed to set content. Err = " + err);
78 case Interop.Widget.ErrorCode.InvalidParameter:
79 throw new ArgumentException("Invalid parameter of SetContent()");
81 case Interop.Widget.ErrorCode.NotSupported:
82 throw new NotSupportedException();
84 case Interop.Widget.ErrorCode.OutOfMemory:
85 case Interop.Widget.ErrorCode.Fault:
86 throw new InvalidOperationException();
93 /// Sends the title to the widget.
95 /// <param name="title">When an accessibility mode is turned on, this string will be read.</param>
96 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
97 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
98 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
99 public void SetTitle(string title)
101 Interop.Widget.ErrorCode err = Interop.Widget.SetTitle(Handle, title);
103 if (err != Interop.Widget.ErrorCode.None)
105 Log.Error(LogTag, "Failed to set title. Err = " + err);
109 case Interop.Widget.ErrorCode.InvalidParameter:
110 throw new ArgumentException("Invalid parameter of SetContent()");
112 case Interop.Widget.ErrorCode.NotSupported:
113 throw new NotSupportedException();
115 case Interop.Widget.ErrorCode.OutOfMemory:
116 case Interop.Widget.ErrorCode.Fault:
117 throw new InvalidOperationException();
123 /// Finishes the context for the widget instance.
125 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
126 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
129 Interop.Widget.ErrorCode err = Interop.Widget.TerminateContext(Handle);
131 if (err != Interop.Widget.ErrorCode.None)
133 Log.Error(LogTag, "Failed to terminate context. Err = " + err);
137 case Interop.Widget.ErrorCode.NotSupported:
138 throw new NotSupportedException();
140 case Interop.Widget.ErrorCode.InvalidParameter:
141 case Interop.Widget.ErrorCode.Fault:
142 throw new InvalidOperationException();
147 internal void Bind(IntPtr handle, string id)
154 /// Overrides this method if want to handle the behavior when the widget instance is started.
156 /// <param name="content">The data set for the previous status.</param>
157 /// <param name="w">The pixel value for the widget width.</param>
158 /// <param name="h">The pixel value for the widget height.</param>
159 public virtual void OnCreate(Bundle content, int w, int h)
163 Interop.Widget.GetWin(Handle, out win);
164 BaseWindow = new WidgetWindow(win);
165 BaseWindow.Resize(w, h);
167 Window = new ConformantWindow(Window, win);
172 /// Overrides this method if want to handle the behavior when the widget instance is destroyed.
174 /// <param name="reason">The reason for destruction.</param>
175 /// <param name="content">The data set to save.</param>
176 public virtual void OnDestroy(WidgetDestroyType reason, Bundle content)
181 /// Overrides this method if want to handle the behavior when the widget instance is paused.
183 public virtual void OnPause()
188 /// Overrides this method if want to handle the behavior when the widget instance is resumed.
190 public virtual void OnResume()
195 /// Overrides this method if want to handle the behavior when the widget instance is resized.
197 /// <param name="w">Widget width.</param>
198 /// <param name="h">Widget height.</param>
199 public virtual void OnResize(int w, int h)
204 /// Overrides this method if want to handle the behavior when the widget instance is updated.
206 /// <param name="content">The data set for updating this widget will be provided by the requester.</param>
207 /// <param name="isForce">Although the widget is paused, if it is true, the widget can be updated.</param>
208 public virtual void OnUpdate(Bundle content, bool isForce)