2 * Copyright(c) 2017 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 global::System.Runtime.InteropServices.HandleRef swigCPtr;
25 private static WidgetApplication _instance; //singleton
26 private Dictionary<System.Type, string> _widgetInfo;
27 private List<Widget> _widgetList = new List<Widget>();
28 private delegate System.IntPtr CreateWidgetFunctionDelegate(ref string widgetName);
30 internal WidgetApplication(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
32 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WidgetApplication obj)
37 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40 protected override void Dispose(DisposeTypes type)
47 //Release your own unmanaged resources here.
48 //You should not access any managed member here except static instance.
49 //because the execution order of Finalizes is non-deterministic.
50 if (swigCPtr.Handle != global::System.IntPtr.Zero)
55 Interop.WidgetApplication.delete_WidgetApplication(swigCPtr);
57 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
62 public new static WidgetApplication Instance
70 public static WidgetApplication NewWidgetApplication(string[] args, string stylesheet)
72 WidgetApplication ret = New(args, stylesheet);
73 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
78 public static WidgetApplication New(string[] args, string stylesheet)
80 int argc = args.Length;
81 string argvStr = string.Join(" ", args);
83 IntPtr widgetIntPtr = Interop.WidgetApplication.WidgetApplication_New(argc, argvStr, stylesheet);
85 WidgetApplication ret = new WidgetApplication(widgetIntPtr, false);
87 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92 internal WidgetApplication(WidgetApplication widgetApplication) : this(Interop.WidgetApplication.new_WidgetApplication__SWIG_1(WidgetApplication.getCPtr(widgetApplication)), true)
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97 internal WidgetApplication Assign(WidgetApplication widgetApplication)
99 WidgetApplication ret = new WidgetApplication(Interop.WidgetApplication.WidgetApplication_Assign(swigCPtr, WidgetApplication.getCPtr(widgetApplication)), false);
100 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104 public void RegisterWidgetCreatingFunction()
106 foreach (KeyValuePair<System.Type, string> widgetInfo in _widgetInfo)
108 string widgetName = widgetInfo.Value;
109 RegisterWidgetCreatingFunction(ref widgetName);
113 internal void RegisterWidgetCreatingFunction(ref string widgetName)
115 CreateWidgetFunctionDelegate newDelegate = new CreateWidgetFunctionDelegate(WidgetCreateFunction);
117 System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(newDelegate);
118 CreateWidgetFunction createWidgetFunction = new CreateWidgetFunction(ip, true);
120 Interop.WidgetApplication.WidgetApplication_RegisterWidgetCreatingFunction(swigCPtr, ref widgetName, CreateWidgetFunction.getCPtr(createWidgetFunction));
121 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124 public void AddWidgetInstance( Widget widget )
126 _widgetList.Add(widget);
129 public void RegisterWidgetInfo(Dictionary<System.Type, string> widgetInfo)
131 _widgetInfo = widgetInfo;
134 public static System.IntPtr WidgetCreateFunction(ref string widgetName)
136 Dictionary<System.Type, string> widgetInfo = Instance.WidgetInfo;
138 foreach (System.Type widgetType in widgetInfo.Keys)
140 if (widgetInfo[widgetType] == widgetName)
142 Widget widget = Activator.CreateInstance(widgetType) as Widget;
145 return widget.GetIntPtr();
153 public Dictionary<System.Type, string> WidgetInfo