manual binding for TextEditor and ApplicationExtension
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / NUIApplication.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
18 using System;
19 using Tizen.Applications;
20 using Tizen.NUI;
21
22 namespace Tizen.NUI
23 {
24
25     /// <summary>
26     /// Represents an application that have UI screen. The NUIApplication class has a default stage.
27     /// </summary>
28     public class NUIApplication : CoreUIApplication
29     {
30         private void LOG(string _str)
31         {
32 #if DEBUG_ON
33             Tizen.Log.Debug("NUI", _str);
34 #endif
35         }
36
37         /// <summary>
38         /// The instance of the Application.
39         /// </summary>
40         /// <remarks>
41         /// This application is created before OnCreate() or created event. And the NUIApplication will be terminated when this application is closed.
42         /// </remarks>
43         private Application _application;
44
45         /// <summary>
46         /// The instance of the Dali Application extension.
47         /// </summary>
48         private ApplicationExtensions _applicationExt;
49
50         /// <summary>
51         /// Store the stylesheet value.
52         /// </summary>
53         private string _stylesheet;
54
55         /// <summary>
56         /// Store the window mode value.
57         /// </summary>
58         private Application.WindowMode _windowMode;
59
60         /// <summary>
61         /// Store the app mode value.
62         /// </summary>
63         private AppMode _appMode;
64
65         /// <summary>
66         /// The instance of the Dali Stage.
67         /// </summary>
68         private Window _window;
69
70         /// <summary>
71         /// The default constructor.
72         /// </summary>
73         public NUIApplication() : base()
74         {
75             _appMode = AppMode.Default;
76         }
77
78         /// <summary>
79         /// The constructor with stylesheet.
80         /// </summary>
81         public NUIApplication(string stylesheet) : base()
82         {
83             //handle the stylesheet
84             _appMode = AppMode.StyleSheetOnly;
85             _stylesheet = stylesheet;
86         }
87
88         /// <summary>
89         /// The constructor with stylesheet and window mode.
90         /// </summary>
91         public NUIApplication(string stylesheet, WindowMode windowMode) : base()
92         {
93             //handle the stylesheet and windowMode
94             _appMode = AppMode.StyleSheetWithWindowMode;
95             _stylesheet = stylesheet;
96             _windowMode = (Application.WindowMode)windowMode;
97         }
98
99         /// <summary>
100         /// Overrides this method if want to handle behavior.
101         /// </summary>
102         protected override void OnPause()
103         {
104             base.OnPause();
105             _applicationExt.Pause();
106             LOG("OnPause() is called!");
107         }
108
109         /// <summary>
110         /// Overrides this method if want to handle behavior before calling OnCreate().<br>
111         /// stage property is initialized in this overrided method.<br>
112         /// </summary>
113         protected override void OnPreCreate()
114         {
115             // Initialize DisposeQueue Singleton class.
116             DisposeQueue disposeQ = DisposeQueue.Instance;
117 #if DEBUG_ON
118             Tizen.Log.Debug("NUI", "##### 1) DisposeQueue.Instance.Initialize()!");
119 #endif
120             switch (_appMode)
121             {
122                 case AppMode.Default:
123                     _application = Tizen.NUI.Application.NewApplication();
124                     break;
125                 case AppMode.StyleSheetOnly:
126                     _application = Tizen.NUI.Application.NewApplication(_stylesheet);
127                     break;
128                 case AppMode.StyleSheetWithWindowMode:
129                     _application = Tizen.NUI.Application.NewApplication(_stylesheet, _windowMode);
130                     break;
131                 default:
132                     break;
133             }
134             _applicationExt = new ApplicationExtensions(_application);
135             _applicationExt.Init();
136             _applicationExt.Start();
137
138             // This is also required to create DisposeQueue on main thread.
139             disposeQ.Initialize();
140 #if DEBUG_ON
141             Tizen.Log.Debug("NUI", "##### 2) DisposeQueue.Instance.Initialize()!");
142 #endif
143             _window = Window.Instance;
144             _window.SetBackgroundColor(Color.White);
145             LOG("OnPreCreate() is called!");
146         }
147
148         /// <summary>
149         /// Overrides this method if want to handle behavior.
150         /// </summary>
151         protected override void OnResume()
152         {
153             base.OnResume();
154             _applicationExt.Resume();
155             LOG("OnResume() is called!");
156         }
157
158         /// <summary>
159         /// Overrides this method if want to handle behavior.
160         /// </summary>
161         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
162         {
163             base.OnAppControlReceived(e);
164             LOG("OnAppControlReceived() is called!");
165             if (e != null)
166             {
167                 LOG("OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
168                 LOG("CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + "   IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
169             }
170         }
171
172         /// <summary>
173         /// Overrides this method if want to handle behavior.
174         /// </summary>
175         protected override void OnCreate()
176         {
177             base.OnCreate();
178             LOG("OnCreate() is called!");
179         }
180
181         /// <summary>
182         /// Overrides this method if want to handle behavior.
183         /// </summary>
184         protected override void OnLocaleChanged(LocaleChangedEventArgs e)
185         {
186             base.OnLocaleChanged(e);
187             _applicationExt.LanguageChange();
188             LOG("OnLocaleChanged() is called!");
189         }
190
191         /// <summary>
192         /// Overrides this method if want to handle behavior.
193         /// </summary>
194         protected override void OnLowBattery(LowBatteryEventArgs e)
195         {
196             base.OnLowBattery(e);
197             LOG("OnLowBattery() is called!");
198         }
199
200         /// <summary>
201         /// Overrides this method if want to handle behavior.
202         /// </summary>
203         protected override void OnLowMemory(LowMemoryEventArgs e)
204         {
205             base.OnLowMemory(e);
206             LOG("OnLowMemory() is called!");
207         }
208
209         /// <summary>
210         /// Overrides this method if want to handle behavior.
211         /// </summary>
212         protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
213         {
214             base.OnRegionFormatChanged(e);
215             LOG("OnRegionFormatChanged() is called!");
216         }
217
218         /// <summary>
219         /// Overrides this method if want to handle behavior.
220         /// </summary>
221         protected override void OnTerminate()
222         {
223             base.OnTerminate();
224             _applicationExt.Terminate();
225             LOG("OnTerminate() is called!");
226         }
227
228         /// <summary>
229         /// The mode of creating NUI application.
230         /// </summary>
231         private enum AppMode
232         {
233             Default = 0,
234             StyleSheetOnly = 1,
235             StyleSheetWithWindowMode = 2
236         }
237
238         /// <summary>
239         /// Enumeration for deciding whether a NUI application window is opaque or transparent.
240         /// </summary>
241         public enum WindowMode
242         {
243             Opaque = 0,
244             Transparent = 1
245         }
246
247         /// <summary>
248         /// Get the window instance.
249         /// </summary>
250         public Window Window
251         {
252             get
253             {
254                 return _application.GetWindow();
255             }
256         }
257     }
258 }