[NUI] add exception code for NUIWidgetApplication (#1802)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / NUIWidgetApplication.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using Tizen.Applications;
18 using Tizen.Applications.CoreBackend;
19 using System.Collections.Generic;
20 using System.ComponentModel;
21 using System;
22
23 namespace Tizen.NUI
24 {
25     /// <summary>
26     /// Represents an application that have UI screen. The NUIWidgetApplication class has a default stage.
27     /// </summary>
28     /// <since_tizen> 4 </since_tizen>
29     public class NUIWidgetApplication : CoreApplication
30     {
31         /// <summary>
32         /// The default constructor.
33         /// </summary>
34         /// <remarks>Widget ID will be replaced as the application ID.</remarks>
35         /// <param name="widgetType">Derived widget class type.</param>
36         public NUIWidgetApplication( System.Type widgetType ) : base(new NUIWidgetCoreBackend())
37         {
38             NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
39             core?.RegisterWidgetInfo(new Dictionary<System.Type, string> { { widgetType, ApplicationInfo.ApplicationId } });
40         }
41
42         /// <summary>
43         /// The constructor for multi widget class and instance.
44         /// </summary>
45         /// <param name="widgetTypes">List of derived widget class type.</param>
46         public NUIWidgetApplication(Dictionary<System.Type, string> widgetTypes) : base(new NUIWidgetCoreBackend())
47         {
48             if( widgetTypes == null )
49             {
50               throw new InvalidOperationException("Dictionary is null");
51             }
52             else
53             {
54                 NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
55                 core?.RegisterWidgetInfo(widgetTypes);
56             }
57         }
58
59         /// <summary>
60         /// The default constructor with stylesheet.
61         /// </summary>
62         /// <remarks>Widget ID will be replaced as the application ID.</remarks>
63         /// <param name="widgetType">Derived widget class type.</param>
64         /// <param name="styleSheet">The styleSheet url.</param>
65         /// <since_tizen> 4 </since_tizen>
66         public NUIWidgetApplication(System.Type widgetType, string styleSheet) : base(new NUIWidgetCoreBackend(styleSheet))
67         {
68             NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
69             core?.RegisterWidgetInfo(new Dictionary<System.Type, string> { { widgetType, ApplicationInfo.ApplicationId } });
70         }
71
72         /// <summary>
73         /// Add WidgetInfo in runtime
74         /// </summary>
75         /// <param name="widgetType">Derived widget class type.</param>
76         [EditorBrowsable(EditorBrowsableState.Never)]
77         public void AddWidgetType( System.Type widgetType )
78         {
79             NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
80             core?.AddWidgetInfo(new Dictionary<System.Type, string> { { widgetType, ApplicationInfo.ApplicationId } });
81         }
82
83         /// <summary>
84         /// Add WidgetInfo in runtime
85         /// </summary>
86         /// <param name="widgetTypes">Derived widget class type.</param>
87         [EditorBrowsable(EditorBrowsableState.Never)]
88         public void AddWidgetType( Dictionary<System.Type, string> widgetTypes )
89         {
90             NUIWidgetCoreBackend core = Backend as NUIWidgetCoreBackend;
91             core?.AddWidgetInfo(widgetTypes);
92         }
93
94         internal WidgetApplication ApplicationHandle
95         {
96             get
97             {
98                 return ((NUIWidgetCoreBackend)this.Backend).WidgetApplicationHandle;
99             }
100         }
101
102         /// <summary>
103         /// Run NUIWidgetApplication.
104         /// </summary>
105         /// <param name="args">Arguments from commandline.</param>
106         /// <since_tizen> 4 </since_tizen>
107         public override void Run(string[] args)
108         {
109             Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
110             base.Run(args);
111         }
112
113         /// <summary>
114         /// Exit NUIWidgetApplication.
115         /// </summary>
116         /// <since_tizen> 4 </since_tizen>
117         public override void Exit()
118         {
119             Tizen.Log.Fatal("NUI", "### NUIWidgetApplication Exit called");
120             base.Exit();
121         }
122
123         /// <summary>
124         /// Overrides this method if want to handle OnLocaleChanged behavior.
125         /// </summary>
126         /// <since_tizen> 4 </since_tizen>
127         protected override void OnLocaleChanged(LocaleChangedEventArgs e)
128         {
129             Log.Fatal("NUI", "OnLocaleChanged() is called!");
130             base.OnLocaleChanged(e);
131         }
132
133         /// <summary>
134         /// Overrides this method if want to handle OnLowBattery behavior.
135         /// </summary>
136         /// <since_tizen> 4 </since_tizen>
137         protected override void OnLowBattery(LowBatteryEventArgs e)
138         {
139             Log.Fatal("NUI", "OnLowBattery() is called!");
140             base.OnLowBattery(e);
141         }
142
143         /// <summary>
144         /// Overrides this method if want to handle OnLowMemory behavior.
145         /// </summary>
146         /// <since_tizen> 4 </since_tizen>
147         protected override void OnLowMemory(LowMemoryEventArgs e)
148         {
149             Log.Fatal("NUI", "OnLowMemory() is called!");
150             base.OnLowMemory(e);
151         }
152
153         /// <summary>
154         /// Overrides this method if want to handle OnRegionFormatChanged behavior.
155         /// </summary>
156         /// <since_tizen> 4 </since_tizen>
157         protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
158         {
159             Log.Fatal("NUI", "OnRegionFormatChanged() is called!");
160             base.OnRegionFormatChanged(e);
161         }
162
163         /// <summary>
164         /// Overrides this method if want to handle OnTerminate behavior.
165         /// </summary>
166         /// <since_tizen> 4 </since_tizen>
167         protected override void OnTerminate()
168         {
169             Log.Fatal("NUI", "OnTerminate() is called!");
170             base.OnTerminate();
171         }
172
173         /// <summary>
174         /// Overrides this method if want to handle OnPreCreate behavior.
175         /// </summary>
176         /// <since_tizen> 4 </since_tizen>
177         protected virtual void OnPreCreate()
178         {
179             Log.Fatal("NUI", "OnPreCreate() is called!");
180         }
181
182         /// <summary>
183         /// Overrides this method if want to handle OnCreate behavior.
184         /// </summary>
185         /// <since_tizen> 4 </since_tizen>
186         protected override void OnCreate()
187         {
188             // This is also required to create DisposeQueue on main thread.
189             DisposeQueue disposeQ = DisposeQueue.Instance;
190             disposeQ.Initialize();
191             Log.Fatal("NUI","OnCreate() is called!");
192             base.OnCreate();
193         }
194     }
195 }