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 if (type == DisposeTypes.Explicit)
50 //Release your own managed resources here.
51 //You should release all of your own disposable objects here.
54 //Release your own unmanaged resources here.
55 //You should not access any managed member here except static instance.
56 //because the execution order of Finalizes is non-deterministic.
57 if (swigCPtr.Handle != global::System.IntPtr.Zero)
62 NDalicManualPINVOKE.delete_WidgetApplication(swigCPtr);
64 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
69 public new static WidgetApplication Instance
77 public static WidgetApplication NewWidgetApplication(string[] args, string stylesheet)
79 WidgetApplication ret = New(args, stylesheet);
80 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85 public static WidgetApplication New(string[] args, string stylesheet)
87 int argc = args.Length;
88 string argvStr = string.Join(" ", args);
90 IntPtr widgetIntPtr = NDalicManualPINVOKE.WidgetApplication_New(argc, argvStr, stylesheet);
92 WidgetApplication ret = new WidgetApplication(widgetIntPtr, false);
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99 internal WidgetApplication(WidgetApplication widgetApplication) : this(NDalicManualPINVOKE.new_WidgetApplication__SWIG_1(WidgetApplication.getCPtr(widgetApplication)), true)
101 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104 internal WidgetApplication Assign(WidgetApplication widgetApplication)
106 WidgetApplication ret = new WidgetApplication(NDalicManualPINVOKE.WidgetApplication_Assign(swigCPtr, WidgetApplication.getCPtr(widgetApplication)), false);
107 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111 public void RegisterWidgetCreatingFunction()
113 foreach (KeyValuePair<System.Type, string> widgetInfo in _widgetInfo)
115 string widgetName = widgetInfo.Value;
116 RegisterWidgetCreatingFunction(ref widgetName);
120 internal void RegisterWidgetCreatingFunction(ref string widgetName)
122 CreateWidgetFunctionDelegate newDelegate = new CreateWidgetFunctionDelegate(WidgetCreateFunction);
124 System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(newDelegate);
125 CreateWidgetFunction createWidgetFunction = new CreateWidgetFunction(ip, true);
127 NDalicManualPINVOKE.WidgetApplication_RegisterWidgetCreatingFunction(swigCPtr, ref widgetName, CreateWidgetFunction.getCPtr(createWidgetFunction));
128 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131 public void AddWidgetInstance( Widget widget )
133 _widgetList.Add(widget);
136 public void RegisterWidgetInfo(Dictionary<System.Type, string> widgetInfo)
138 _widgetInfo = widgetInfo;
141 public static System.IntPtr WidgetCreateFunction(ref string widgetName)
143 Dictionary<System.Type, string> widgetInfo = Instance.WidgetInfo;
145 foreach (System.Type widgetType in widgetInfo.Keys)
147 if (widgetInfo[widgetType] == widgetName)
149 Widget widget = Activator.CreateInstance(widgetType) as Widget;
150 return widget.GetIntPtr();
157 public Dictionary<System.Type, string> WidgetInfo