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