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.
18 using System.Collections.Generic;
20 namespace Tizen.Applications
22 internal class WidgetType
24 internal readonly Type ClassType;
25 internal readonly string Id;
26 internal IList<WidgetBase> WidgetInstances = new List<WidgetBase>();
28 private Interop.Widget.WidgetiInstanceLifecycleCallbacks _callbacks;
30 internal WidgetType(Type ctype, string id)
34 _callbacks.OnCreate = new Interop.Widget.WidgetInstanceCreateCallback(OnCreate);
35 _callbacks.OnDestroy = new Interop.Widget.WidgetInstanceDestroyCallback(OnDestroy);
36 _callbacks.OnPause = new Interop.Widget.WidgetInstancePauseCallback(OnPause);
37 _callbacks.OnResume = new Interop.Widget.WidgetInstanceResumeCallback(OnResume);
38 _callbacks.OnResize = new Interop.Widget.WidgetInstanceResizeCallback(OnResize);
39 _callbacks.OnUpdate = new Interop.Widget.WidgetInstanceUpdateCallback(OnUpdate);
42 internal IntPtr Bind(IntPtr h)
44 return Interop.Widget.AddClass(h, Id, _callbacks, IntPtr.Zero);
47 private int OnCreate(IntPtr context, IntPtr content, int w, int h, IntPtr userData)
49 WidgetBase b = Activator.CreateInstance(ClassType) as WidgetBase;
56 WidgetInstances.Add(b);
57 if (content != IntPtr.Zero)
58 bundle = new Bundle(new SafeBundleHandle(content, false));
59 b.OnCreate(bundle, w, h);
64 private int OnDestroy(IntPtr context, Interop.Widget.WidgetAppDestroyType reason, IntPtr content, IntPtr userData)
66 foreach (WidgetBase w in WidgetInstances)
68 if(w.Handle == context)
72 if (content != IntPtr.Zero)
73 bundle = new Bundle(new SafeBundleHandle(content, false));
75 w.OnDestroy(reason == Interop.Widget.WidgetAppDestroyType.Permanent ?
76 WidgetBase.WidgetDestroyType.Permanent :
77 WidgetBase.WidgetDestroyType.Temporary, bundle);
78 WidgetInstances.Remove(w);
86 private int OnPause(IntPtr context, IntPtr userData)
88 foreach (WidgetBase w in WidgetInstances)
90 if (w.Handle == context)
99 private int OnResume(IntPtr context, IntPtr userData)
101 foreach (WidgetBase w in WidgetInstances)
103 if (w.Handle == context)
112 private int OnResize(IntPtr context, int w, int h, IntPtr userData)
114 foreach (WidgetBase o in WidgetInstances)
116 if (o.Handle == context)
125 private int OnUpdate(IntPtr context, IntPtr content, int force, IntPtr userData)
127 foreach (WidgetBase o in WidgetInstances)
129 if (o.Handle == context)
131 Bundle bundle = null;
133 if (content != IntPtr.Zero)
134 bundle = new Bundle(new SafeBundleHandle(content, false));
135 o.OnUpdate(bundle, force != 0 ? true : false);