2 * Copyright(c) 2021 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.
18 using System.Collections.Generic;
22 internal class WidgetApplication : Application
24 private Dictionary<System.Type, string> widgetInfo;
25 private List<Widget> widgetList = new List<Widget>();
26 private delegate System.IntPtr CreateWidgetFunctionDelegate(ref string widgetName);
27 private List<CreateWidgetFunctionDelegate> createWidgetFunctionDelegateList = new List<CreateWidgetFunctionDelegate>();
29 internal WidgetApplication(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
33 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
35 Interop.WidgetApplication.DeleteWidgetApplication(swigCPtr);
38 public static WidgetApplication NewWidgetApplication(string[] args, string stylesheet)
40 WidgetApplication ret = New(args, stylesheet);
41 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
46 public static WidgetApplication New(string[] args, string stylesheet)
48 int argc = args.Length;
49 string argvStr = string.Join(" ", args);
51 IntPtr widgetIntPtr = Interop.WidgetApplication.New(argc, argvStr, stylesheet);
53 WidgetApplication ret = new WidgetApplication(widgetIntPtr, false);
55 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
60 internal WidgetApplication(WidgetApplication widgetApplication) : this(Interop.WidgetApplication.NewWidgetApplication(WidgetApplication.getCPtr(widgetApplication)), true)
62 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
65 internal WidgetApplication Assign(WidgetApplication widgetApplication)
67 WidgetApplication ret = new WidgetApplication(Interop.WidgetApplication.Assign(SwigCPtr, WidgetApplication.getCPtr(widgetApplication)), false);
68 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
72 public void RegisterWidgetCreatingFunction()
74 foreach (KeyValuePair<System.Type, string> widgetInfo in widgetInfo)
76 string widgetName = widgetInfo.Value;
77 RegisterWidgetCreatingFunction(ref widgetName);
81 internal void RegisterWidgetCreatingFunction(ref string widgetName)
83 CreateWidgetFunctionDelegate newDelegate = new CreateWidgetFunctionDelegate(WidgetCreateFunction);
85 // Keep this delegate until WidgetApplication is terminated
86 createWidgetFunctionDelegateList.Add(newDelegate);
88 System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(newDelegate);
89 CreateWidgetFunction createWidgetFunction = new CreateWidgetFunction(ip);
91 Interop.WidgetApplication.RegisterWidgetCreatingFunction(SwigCPtr, ref widgetName, CreateWidgetFunction.getCPtr(createWidgetFunction));
92 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
95 public void AddWidgetInstance(Widget widget)
97 widgetList.Add(widget);
100 public void RegisterWidgetInfo(Dictionary<System.Type, string> widgetInfo)
102 this.widgetInfo = widgetInfo;
105 public void AddWidgetInfo(Dictionary<Type, string> newWidgetInfo)
107 foreach (KeyValuePair<Type, string> widgetInfo in newWidgetInfo)
109 if (this.widgetInfo.ContainsKey(widgetInfo.Key) == false)
111 this.widgetInfo.Add(widgetInfo.Key, widgetInfo.Value);
112 string widgetName = widgetInfo.Value;
113 RegisterWidgetCreatingFunction(ref widgetName);
118 public static System.IntPtr WidgetCreateFunction(ref string widgetName)
120 if ((Instance as WidgetApplication) == null)
125 Dictionary<System.Type, string> widgetInfo = (Instance as WidgetApplication).WidgetInfo;
127 foreach (System.Type widgetType in widgetInfo.Keys)
129 if (widgetInfo[widgetType] == widgetName)
131 Widget widget = Activator.CreateInstance(widgetType) as Widget;
134 return widget.GetIntPtr();
142 public Dictionary<System.Type, string> WidgetInfo