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