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 protected static readonly string LogTag = typeof(WidgetBase).Namespace;
32 /// Window object for this widget instance.
33 /// It will be created after OnCreate method is invoked.
35 protected Window Window;
40 public enum WidgetDestroyType
43 /// User deleted this widget from the viewer.
48 /// Widget is deleted because of other reasons. (For e.g., widget process is terminated temporarily by the system)
61 /// Sets the content information to the widget.
63 /// <param name="info">The data set to save.</param>
64 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
65 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
66 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
67 public void SetContent(Bundle info)
69 Interop.Widget.ErrorCode err = Interop.Widget.SetContent(Handle, info.SafeBundleHandle);
71 if (err != Interop.Widget.ErrorCode.None)
73 Log.Error(LogTag, "Failed to set content. Err = " + err);
77 case Interop.Widget.ErrorCode.InvalidParameter:
78 throw new ArgumentException("Invalid parameter of SetContent()");
80 case Interop.Widget.ErrorCode.NotSupported:
81 throw new NotSupportedException();
83 case Interop.Widget.ErrorCode.OutOfMemory:
84 case Interop.Widget.ErrorCode.Fault:
85 throw new InvalidOperationException();
92 /// Sends the title to the widget.
94 /// <param name="title">When an accessibility mode is turned on, this string will be read.</param>
95 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
96 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
97 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
98 public void SetTitle(string title)
100 Interop.Widget.ErrorCode err = Interop.Widget.SetTitle(Handle, title);
102 if (err != Interop.Widget.ErrorCode.None)
104 Log.Error(LogTag, "Failed to set title. Err = " + err);
108 case Interop.Widget.ErrorCode.InvalidParameter:
109 throw new ArgumentException("Invalid parameter of SetContent()");
111 case Interop.Widget.ErrorCode.NotSupported:
112 throw new NotSupportedException();
114 case Interop.Widget.ErrorCode.OutOfMemory:
115 case Interop.Widget.ErrorCode.Fault:
116 throw new InvalidOperationException();
122 /// Finishes the context for the widget instance.
124 /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
125 /// <exception cref="InvalidOperationException">Thrown in case of an unrecoverable error.</exception>
128 Interop.Widget.ErrorCode err = Interop.Widget.TerminateContext(Handle);
130 if (err != Interop.Widget.ErrorCode.None)
132 Log.Error(LogTag, "Failed to terminate context. Err = " + err);
136 case Interop.Widget.ErrorCode.NotSupported:
137 throw new NotSupportedException();
139 case Interop.Widget.ErrorCode.InvalidParameter:
140 case Interop.Widget.ErrorCode.Fault:
141 throw new InvalidOperationException();
146 internal void Bind(IntPtr handle, string id)
153 /// Overrides this method if want to handle the behavior when the widget instance is started.
155 /// <param name="content">The data set for the previous status.</param>
156 /// <param name="w">The pixel value for the widget width.</param>
157 /// <param name="h">The pixel value for the widget height.</param>
158 public virtual void OnCreate(Bundle content, int w, int h)
162 Interop.Widget.GetWin(Handle, out win);
163 Window = new WidgetWindow(win);
169 /// Overrides this method if want to handle the behavior when the widget instance is destroyed.
171 /// <param name="reason">The reason for destruction.</param>
172 /// <param name="content">The data set to save.</param>
173 public virtual void OnDestroy(WidgetDestroyType reason, Bundle content)
178 /// Overrides this method if want to handle the behavior when the widget instance is paused.
180 public virtual void OnPause()
185 /// Overrides this method if want to handle the behavior when the widget instance is resumed.
187 public virtual void OnResume()
192 /// Overrides this method if want to handle the behavior when the widget instance is resized.
194 /// <param name="w">Widget width.</param>
195 /// <param name="h">Widget height.</param>
196 public virtual void OnResize(int w, int h)
201 /// Overrides this method if want to handle the behavior when the widget instance is updated.
203 /// <param name="content">The data set for updating this widget will be provided by the requester.</param>
204 /// <param name="isForce">Although the widget is paused, if it is true, the widget can be updated.</param>
205 public virtual void OnUpdate(Bundle content, bool isForce)