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 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WidgetApplication obj)
35 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
38 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
40 Interop.WidgetApplication.DeleteWidgetApplication(swigCPtr);
43 public static WidgetApplication NewWidgetApplication(string[] args, string stylesheet)
45 WidgetApplication ret = New(args, stylesheet);
46 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
51 public static WidgetApplication New(string[] args, string stylesheet)
53 int argc = args.Length;
54 string argvStr = string.Join(" ", args);
56 IntPtr widgetIntPtr = Interop.WidgetApplication.New(argc, argvStr, stylesheet);
58 WidgetApplication ret = new WidgetApplication(widgetIntPtr, false);
60 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
65 internal WidgetApplication(WidgetApplication widgetApplication) : this(Interop.WidgetApplication.NewWidgetApplication(WidgetApplication.getCPtr(widgetApplication)), true)
67 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70 internal WidgetApplication Assign(WidgetApplication widgetApplication)
72 WidgetApplication ret = new WidgetApplication(Interop.WidgetApplication.Assign(SwigCPtr, WidgetApplication.getCPtr(widgetApplication)), false);
73 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77 public void RegisterWidgetCreatingFunction()
79 foreach (KeyValuePair<System.Type, string> widgetInfo in widgetInfo)
81 string widgetName = widgetInfo.Value;
82 RegisterWidgetCreatingFunction(ref widgetName);
86 internal void RegisterWidgetCreatingFunction(ref string widgetName)
88 CreateWidgetFunctionDelegate newDelegate = new CreateWidgetFunctionDelegate(WidgetCreateFunction);
90 // Keep this delegate until WidgetApplication is terminated
91 createWidgetFunctionDelegateList.Add(newDelegate);
93 System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(newDelegate);
94 CreateWidgetFunction createWidgetFunction = new CreateWidgetFunction(ip);
96 Interop.WidgetApplication.RegisterWidgetCreatingFunction(SwigCPtr, ref widgetName, CreateWidgetFunction.getCPtr(createWidgetFunction));
97 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100 public void AddWidgetInstance(Widget widget)
102 widgetList.Add(widget);
105 public void RegisterWidgetInfo(Dictionary<System.Type, string> widgetInfo)
107 this.widgetInfo = widgetInfo;
110 public void AddWidgetInfo(Dictionary<Type, string> newWidgetInfo)
112 foreach (KeyValuePair<Type, string> widgetInfo in newWidgetInfo)
114 if (this.widgetInfo.ContainsKey(widgetInfo.Key) == false)
116 this.widgetInfo.Add(widgetInfo.Key, widgetInfo.Value);
117 string widgetName = widgetInfo.Value;
118 RegisterWidgetCreatingFunction(ref widgetName);
123 public static System.IntPtr WidgetCreateFunction(ref string widgetName)
125 if ((Instance as WidgetApplication) == null)
130 Dictionary<System.Type, string> widgetInfo = (Instance as WidgetApplication).WidgetInfo;
132 foreach (System.Type widgetType in widgetInfo.Keys)
134 if (widgetInfo[widgetType] == widgetName)
136 Widget widget = Activator.CreateInstance(widgetType) as Widget;
139 return widget.GetIntPtr();
147 public Dictionary<System.Type, string> WidgetInfo