1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 using System.Runtime.InteropServices;
22 /// Widget application
24 internal class WidgetApplication : BaseHandle
26 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
28 internal WidgetApplication(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.WidgetApplication_SWIGUpcast(cPtr), cMemoryOwn)
30 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
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;
39 /// To make Window instance be disposed.
41 protected override void Dispose(DisposeTypes type)
48 if(type == DisposeTypes.Explicit)
51 //Release your own managed resources here.
52 //You should release all of your own disposable objects here.
55 //Release your own unmanaged resources here.
56 //You should not access any managed member here except static instance.
57 //because the execution order of Finalizes is non-deterministic.
59 if (_initCallback != null)
61 this.InitSignal().Disconnect(_initCallback);
63 if (_terminateCallback != null)
65 this.TerminateSignal().Disconnect(_terminateCallback);
67 if (_languageChangedCallback != null)
69 this.LanguageChangedSignal().Disconnect(_languageChangedCallback);;
71 if (_regionChangedCallback != null)
73 this.RegionChangedSignal().Disconnect(_regionChangedCallback);
75 if (_batteryLowCallback != null)
77 this.BatteryLowSignal().Disconnect(_batteryLowCallback);
79 if (_memoryLowCallback != null)
81 this.MemoryLowSignal().Disconnect(_memoryLowCallback);
84 if (swigCPtr.Handle != global::System.IntPtr.Zero)
89 NDalicManualPINVOKE.delete_WidgetApplication(swigCPtr);
91 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
97 internal static WidgetApplication GetWidgetApplicationFromPtr(global::System.IntPtr cPtr)
99 WidgetApplication ret = new WidgetApplication(cPtr, false);
100 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104 public static WidgetApplication instance
112 internal void SetupDelegates()
114 InitDelegateInternal initializeCallback = new InitDelegateInternal(Initialization);
116 NUILog.Debug("InitSignal connection count");
117 this.InitSignal().Connect(initializeCallback);
119 NUILog.Debug("InitSignal connection count = " + InitSignal().GetConnectionCount());
122 public static WidgetApplication NewWidgetApplication(string[] args, string stylesheet)
124 WidgetApplication ret = New(args, stylesheet);
125 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127 // we've got an application now connect the signals
128 ret.SetupDelegates();
133 public static WidgetApplication New(string[] args, string stylesheet)
135 int argc = args.Length;
136 string argvStr = string.Join(" ", args);
138 WidgetApplication ret = new WidgetApplication(NDalicManualPINVOKE.WidgetApplication_New(argc, argvStr, stylesheet), true);
139 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143 internal WidgetApplication(WidgetApplication widgetApplication) : this(NDalicManualPINVOKE.new_WidgetApplication__SWIG_1(WidgetApplication.getCPtr(widgetApplication)), true)
145 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
148 internal WidgetApplication Assign(WidgetApplication widgetApplication)
150 WidgetApplication ret = new WidgetApplication(NDalicManualPINVOKE.WidgetApplication_Assign(swigCPtr, WidgetApplication.getCPtr(widgetApplication)), false);
151 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156 /// This starts the application.
158 public void MainLoop()
160 NDalicManualPINVOKE.WidgetApplication_MainLoop(swigCPtr);
161 if (NDalicPINVOKE.SWIGPendingException.Pending)
163 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 /// This quits the application.
169 /// Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
173 NDalicManualPINVOKE.WidgetApplication_Quit(swigCPtr);
174 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180 /// <returns> The window for widget instance.</returns>
181 public Window GetWindow()
183 Window ret = new Window(NDalicManualPINVOKE.WidgetApplication_GetWindow(swigCPtr), true);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 /// Get path application resources are stored at.
191 /// <returns>The full path of the resources</returns>
192 public static string GetResourcePath()
194 string ret = NDalicManualPINVOKE.WidgetApplication_GetResourcePath();
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200 /// Event arguments that passed via widget app event signal.
202 public class WidgetApplicationEventArgs : EventArgs
205 /// Widget application.
207 public WidgetApplication WidgetApplication
214 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
215 private delegate void InitCallbackType(IntPtr widgetApplication);
216 private InitCallbackType _initCallback;
217 private DaliEventHandler<object,WidgetApplicationEventArgs> _initEventHandler;
222 public event DaliEventHandler<object, WidgetApplicationEventArgs> Init
226 if (_initEventHandler == null)
228 _initCallback = new InitCallbackType( OnInit);
229 InitSignal().Connect(_initCallback);
232 _initEventHandler += value;
237 _initEventHandler -= value;
239 if (_initEventHandler == null && InitSignal().Empty() == false)
241 InitSignal().Disconnect(_initCallback);
246 private void OnInit(IntPtr widgetApplication)
248 WidgetApplicationEventArgs e = new WidgetApplicationEventArgs();
249 if (widgetApplication != null)
251 e.WidgetApplication = WidgetApplication.GetWidgetApplicationFromPtr(widgetApplication);
254 if (_initEventHandler != null)
256 _initEventHandler(this, e);
260 internal AppSignalType InitSignal()
262 AppSignalType ret = new AppSignalType(NDalicManualPINVOKE.WidgetApplication_InitSignal(swigCPtr), false);
263 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
268 private delegate void TerminateCallbackType(IntPtr widgetApplication);
269 private TerminateCallbackType _terminateCallback;
270 private DaliEventHandler<object, WidgetApplicationEventArgs> _terminateEventHandler;
275 public event DaliEventHandler<object, WidgetApplicationEventArgs> Terminate
279 if (_terminateEventHandler == null)
281 _terminateCallback = new TerminateCallbackType( OnTerminate);
282 TerminateSignal().Connect(_terminateCallback);
285 _terminateEventHandler += value;
290 _terminateEventHandler -= value;
292 if (_terminateEventHandler == null && TerminateSignal().Empty() == false)
294 TerminateSignal().Disconnect(_terminateCallback);
299 private void OnTerminate(IntPtr widgetApplication)
301 WidgetApplicationEventArgs e = new WidgetApplicationEventArgs();
303 if (widgetApplication != null)
305 e.WidgetApplication = WidgetApplication.GetWidgetApplicationFromPtr(widgetApplication);
308 if (_terminateEventHandler != null)
310 _terminateEventHandler(this, e);
314 internal AppSignalType TerminateSignal()
316 AppSignalType ret = new AppSignalType(NDalicManualPINVOKE.WidgetApplication_TerminateSignal(swigCPtr), false);
317 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
322 private delegate void LanguageChangedCallbackType(IntPtr widgetApplication);
323 private LanguageChangedCallbackType _languageChangedCallback;
324 private DaliEventHandler<object, WidgetApplicationEventArgs> _languageChangedEventHandler;
327 /// LanguageChanged event.
329 public event DaliEventHandler<object, WidgetApplicationEventArgs> LanguageChanged
333 if (_languageChangedEventHandler == null)
335 _languageChangedCallback = new LanguageChangedCallbackType( OnLanguageChanged);
336 LanguageChangedSignal().Connect(_languageChangedCallback);
339 _languageChangedEventHandler += value;
344 _languageChangedEventHandler -= value;
346 if (_languageChangedEventHandler == null && LanguageChangedSignal().Empty() == false)
348 LanguageChangedSignal().Disconnect(_languageChangedCallback);
353 private void OnLanguageChanged(IntPtr widgetApplication)
355 WidgetApplicationEventArgs e = new WidgetApplicationEventArgs();
357 if (widgetApplication != null)
359 e.WidgetApplication = WidgetApplication.GetWidgetApplicationFromPtr(widgetApplication);
362 if (_languageChangedEventHandler != null)
364 _languageChangedEventHandler(this, e);
368 internal AppSignalType LanguageChangedSignal()
370 AppSignalType ret = new AppSignalType(NDalicManualPINVOKE.WidgetApplication_LanguageChangedSignal(swigCPtr), false);
371 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
376 private delegate void RegionChangedCallbackType(IntPtr widgetApplication);
377 private RegionChangedCallbackType _regionChangedCallback;
378 private DaliEventHandler<object, WidgetApplicationEventArgs> _regionChangedEventHandler;
381 /// RegionChanged event.
383 public event DaliEventHandler<object, WidgetApplicationEventArgs> RegionChanged
387 if (_regionChangedEventHandler == null)
389 _regionChangedCallback = new RegionChangedCallbackType( OnRegionChanged );
390 RegionChangedSignal().Connect(_regionChangedCallback);
393 _regionChangedEventHandler += value;
398 _regionChangedEventHandler -= value;
400 if (_regionChangedEventHandler == null && RegionChangedSignal().Empty() == false)
402 RegionChangedSignal().Disconnect(_regionChangedCallback);
407 private void OnRegionChanged(IntPtr widgetApplication)
409 WidgetApplicationEventArgs e = new WidgetApplicationEventArgs();
411 if (widgetApplication != null)
413 e.WidgetApplication = WidgetApplication.GetWidgetApplicationFromPtr(widgetApplication);
416 if (_regionChangedEventHandler != null)
418 _regionChangedEventHandler(this, e);
422 internal AppSignalType RegionChangedSignal()
424 AppSignalType ret = new AppSignalType(NDalicManualPINVOKE.WidgetApplication_RegionChangedSignal(swigCPtr), false);
425 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
430 private delegate void BatteryLowCallbackType(IntPtr widgetApplication);
431 private BatteryLowCallbackType _batteryLowCallback;
432 private DaliEventHandler<object, WidgetApplicationEventArgs> _batteryLowEventHandler;
435 /// BatteryLow event.
437 public event DaliEventHandler<object, WidgetApplicationEventArgs> BatteryLow
441 if (_batteryLowEventHandler == null)
443 _batteryLowCallback = new BatteryLowCallbackType( OnBatteryLow );
444 BatteryLowSignal().Connect(_batteryLowCallback);
447 _batteryLowEventHandler += value;
452 _batteryLowEventHandler -= value;
454 if (_batteryLowEventHandler == null && BatteryLowSignal().Empty() == false)
456 BatteryLowSignal().Disconnect(_batteryLowCallback);
461 private void OnBatteryLow(IntPtr widgetApplication)
463 WidgetApplicationEventArgs e = new WidgetApplicationEventArgs();
465 if (widgetApplication != null)
467 e.WidgetApplication = WidgetApplication.GetWidgetApplicationFromPtr(widgetApplication);
470 if (_batteryLowEventHandler != null)
472 _batteryLowEventHandler(this, e);
476 internal AppSignalType BatteryLowSignal()
478 AppSignalType ret = new AppSignalType(NDalicManualPINVOKE.WidgetApplication_BatteryLowSignal(swigCPtr), false);
479 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
484 private delegate void MemoryLowCallbackType(IntPtr widgetApplication);
485 private MemoryLowCallbackType _memoryLowCallback;
486 private DaliEventHandler<object, WidgetApplicationEventArgs> _memoryLowEventHandler;
491 public event DaliEventHandler<object, WidgetApplicationEventArgs> MemoryLow
495 if (_memoryLowEventHandler == null)
497 _memoryLowCallback = new MemoryLowCallbackType (OnMemoryLow);
498 MemoryLowSignal().Connect(_memoryLowCallback);
501 _memoryLowEventHandler += value;
506 _memoryLowEventHandler -= value;
508 if (_memoryLowEventHandler == null && MemoryLowSignal().Empty() == false)
510 MemoryLowSignal().Disconnect(_memoryLowCallback);
515 private void OnMemoryLow(IntPtr widgetApplication)
517 WidgetApplicationEventArgs e = new WidgetApplicationEventArgs();
519 if (widgetApplication != null)
521 e.WidgetApplication = WidgetApplication.GetWidgetApplicationFromPtr(widgetApplication);
524 if (_memoryLowEventHandler != null)
526 _memoryLowEventHandler(this, e);
530 internal AppSignalType MemoryLowSignal()
532 AppSignalType ret = new AppSignalType(NDalicManualPINVOKE.WidgetApplication_MemoryLowSignal(swigCPtr), false);
533 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
537 public delegate void InitDelegate();
539 public delegate void TerminateDelegate();
541 public delegate void LanguageChangedDelegate();
543 public delegate void RegionChangedDelegate();
545 public delegate void BatteryLowDelegate();
547 public delegate void MemoryLowDelegate();
549 [System.Runtime.InteropServices.UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.StdCall)]
550 internal delegate void InitDelegateInternal();
552 [System.Runtime.InteropServices.UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.StdCall)]
553 internal delegate void TerminateDelegateInternal();
555 [System.Runtime.InteropServices.UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.StdCall)]
556 internal delegate void LanguageChangedDelegateInternal();
558 [System.Runtime.InteropServices.UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.StdCall)]
559 internal delegate void RegionChangedDelegateInternal();
561 [System.Runtime.InteropServices.UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.StdCall)]
562 internal delegate void BatteryLowDelegateInternal();
564 [System.Runtime.InteropServices.UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.StdCall)]
565 internal delegate void MemoryLowDelegateInternal();
567 static void Initialization()
569 // instance.InitDelegate();
572 private static WidgetApplication _instance; //singleton