[Tizen] NotifySceneCreated should be called in NUI
[platform/core/uifw/dali-adaptor.git] / adaptors / common / application-impl.h
1 #ifndef __DALI_INTERNAL_APPLICATION_H__
2 #define __DALI_INTERNAL_APPLICATION_H__
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/math/rect.h>
23 #include <dali/public-api/object/base-object.h>
24
25 // INTERNAL INCLUDES
26 #include <application.h>
27 #include <singleton-service.h>
28
29 #include <framework.h>
30 #include <window-impl.h>
31 #include <base/environment-options.h>
32
33 namespace Dali
34 {
35 class Adaptor;
36 class Window;
37
38 namespace Internal
39 {
40
41 namespace Adaptor
42 {
43 class CommandLineOptions;
44 class EventLoop;
45
46 typedef Dali::Rect<int> PositionSize;
47
48 class Application;
49 typedef IntrusivePtr<Application> ApplicationPtr;
50
51 /**
52  * Implementation of the Application class.
53  */
54 class Application : public BaseObject, public Framework::Observer
55 {
56 public:
57   typedef Dali::Application::AppSignalType AppSignalType;
58   typedef Dali::Application::AppControlSignalType AppControlSignalType;
59   typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
60
61   /**
62    * Create a new application
63    * @param[in]  argc        A pointer to the number of arguments
64    * @param[in]  argv        A pointer to the argument list
65    * @param[in]  stylesheet  The path to user defined theme file
66    * @param[in]  windowMode  A member of Dali::Application::WINDOW_MODE
67    * @param[in]  applicationType  A member of Dali::Framework::Type
68    */
69   static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet,
70     WINDOW_MODE windowMode, Framework::Type applicationType );
71
72 public:
73
74   /**
75    * @copydoc Dali::Application::MainLoop()
76    */
77   void MainLoop(Dali::Configuration::ContextLoss configuration);
78
79   /**
80    * @copydoc Dali::Application::Lower()
81    */
82   void Lower();
83
84   /**
85    * @copydoc Dali::Application::Quit()
86    */
87   void Quit();
88
89   /**
90    * @copydoc Dali::Application::AddIdle()
91    */
92   bool AddIdle( CallbackBase* callback );
93
94   /**
95    * @copydoc Dali::Application::GetAdaptor();
96    */
97   Dali::Adaptor& GetAdaptor();
98
99   /**
100    * @copydoc Dali::Application::GetWindow();
101    */
102   Dali::Window GetWindow();
103
104   /**
105    * @copydoc Dali::Application::ReplaceWindow();
106    */
107   void ReplaceWindow(PositionSize windowPosition, const std::string& name);
108
109   /**
110    * @copydoc Dali::Application::GetResourcePath();
111    */
112   static std::string GetResourcePath();
113
114 public: // Stereoscopy
115
116   /**
117    * @copydoc Dali::Application::SetViewMode()
118    */
119   void SetViewMode( ViewMode viewMode );
120
121   /**
122    * @copydoc Dali::Application::GetViewMode()
123    */
124   ViewMode GetViewMode() const;
125
126   /**
127    * @copydoc Dali::Application::SetStereoBase()
128    */
129   void SetStereoBase( float stereoBase );
130
131   /**
132    * @copydoc Dali::Application::GetStereoBase()
133    */
134   float GetStereoBase() const;
135
136 public: // Lifecycle functionality
137
138   /**
139    * Called when OnInit is called or the framework is initialised.
140    */
141   void DoInit();
142
143   /**
144    * Called when OnTerminate is called or the framework is terminated.
145    */
146   void DoTerminate();
147
148   /**
149    * Called when OnPause is called or the framework is paused.
150    */
151   void DoPause();
152
153   /**
154    * Called when OnResume is called or the framework resumes from a paused state.
155    */
156   void DoResume();
157
158   /**
159    * Called when OnLanguageChanged is called or the framework informs the application that the language of the device has changed.
160    */
161   void DoLanguageChange();
162
163 public: // From Framework::Observer
164
165   /**
166    * Called when the framework is initialised.
167    */
168   virtual void OnInit();
169
170   /**
171    * Called when the framework is terminated.
172    */
173   virtual void OnTerminate();
174
175   /**
176    * Called when the framework is paused.
177    */
178   virtual void OnPause();
179
180   /**
181    * Called when the framework resumes from a paused state.
182    */
183   virtual void OnResume();
184
185   /**
186   * Called when the framework received AppControlSignal.
187   * @param[in] The bundle data of AppControl event.
188   */
189   virtual void OnAppControl(void *data);
190
191   /**
192    * Called when the framework informs the application that it should reset itself.
193    */
194   virtual void OnReset();
195
196   /**
197    * Called when the framework informs the application that the language of the device has changed.
198    */
199   virtual void OnLanguageChanged();
200
201   /**
202   * Called when the framework informs the application that the region of the device has changed.
203   */
204   virtual void OnRegionChanged();
205
206   /**
207   * Called when the framework informs the application that the battery level of the device is low.
208   */
209   virtual void OnBatteryLow();
210
211   /**
212   * Called when the framework informs the application that the memory level of the device is low.
213   */
214   virtual void OnMemoryLow();
215
216 public:
217
218   /**
219    * Signal handler when the adaptor's window resizes itself.
220    * @param[in]  adaptor  The adaptor
221    */
222   void OnResize(Dali::Adaptor& adaptor);
223
224 public:  // Signals
225
226   /**
227    * @copydoc Dali::Application::InitSignal()
228    */
229   Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
230
231   /**
232    * @copydoc Dali::Application::TerminateSignal()
233    */
234   Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
235
236   /**
237    * @copydoc Dali::Application::PauseSignal()
238    */
239   Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
240
241   /**
242    * @copydoc Dali::Application::ResumeSignal()
243    */
244   Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
245
246   /**
247    * @copydoc Dali::Application::ResetSignal()
248    */
249   Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
250
251   /**
252   * @copydoc Dali::Application::AppControlSignal()
253   */
254   Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
255
256   /**
257    * @copydoc Dali::Application::ResizeSignal()
258    */
259   Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
260
261   /**
262    * @copydoc Dali::Application::LanguageChangedSignal()
263    */
264   Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
265
266   /**
267   * @copydoc Dali::Application::RegionChangedSignal()
268   */
269   Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
270
271   /**
272   * @copydoc Dali::Application::BatteryLowSignal()
273   */
274   Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
275
276   /**
277   * @copydoc Dali::Application::MemoryLowSignal()
278   */
279   Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
280
281 protected:
282
283   /**
284    * Private Constructor
285    * @param[in]  argc        A pointer to the number of arguments
286    * @param[in]  argv        A pointer to the argument list
287    * @param[in]  stylesheet  The path to user defined theme file
288    * @param[in]  windowMode  A member of Dali::Application::WINDOW_MODE
289    */
290   Application( int* argc, char **argv[], const std::string& stylesheet,
291       WINDOW_MODE windowMode, Framework::Type applicationType );
292
293   /**
294    * Destructor
295    */
296   virtual ~Application();
297
298   // Undefined
299   Application(const Application&);
300   Application& operator=(Application&);
301
302   /**
303    * Creates the window
304    */
305   void CreateWindow();
306
307   /**
308    * Creates the adaptor
309    */
310   void CreateAdaptor();
311
312   /**
313    * Quits from the main loop
314    */
315   void QuitFromMainLoop();
316
317 private:
318
319   AppSignalType                           mInitSignal;
320   AppSignalType                           mTerminateSignal;
321   AppSignalType                           mPauseSignal;
322   AppSignalType                           mResumeSignal;
323   AppSignalType                           mResetSignal;
324   AppSignalType                           mResizeSignal;
325   AppControlSignalType                    mAppControlSignal;
326   AppSignalType                           mLanguageChangedSignal;
327   AppSignalType                           mRegionChangedSignal;
328   AppSignalType                           mBatteryLowSignal;
329   AppSignalType                           mMemoryLowSignal;
330
331   EventLoop*                            mEventLoop;
332   Framework*                            mFramework;
333
334   Dali::Configuration::ContextLoss      mContextLossConfiguration;
335   CommandLineOptions*                   mCommandLineOptions;
336
337   Dali::SingletonService                mSingletonService;
338   Dali::Adaptor*                        mAdaptor;
339   Dali::Window                          mWindow;
340   Dali::Application::WINDOW_MODE        mWindowMode;
341   std::string                           mName;
342   std::string                           mStylesheet;
343   EnvironmentOptions                    mEnvironmentOptions;
344   bool                                  mUseRemoteSurface;
345   bool                                  mInitialized;
346
347   SlotDelegate< Application >           mSlotDelegate;
348 };
349
350 inline Application& GetImplementation(Dali::Application& application)
351 {
352   DALI_ASSERT_ALWAYS(application && "application handle is empty");
353
354   BaseObject& handle = application.GetBaseObject();
355
356   return static_cast<Internal::Adaptor::Application&>(handle);
357 }
358
359 inline const Application& GetImplementation(const Dali::Application& application)
360 {
361   DALI_ASSERT_ALWAYS(application && "Timre handle is empty");
362
363   const BaseObject& handle = application.GetBaseObject();
364
365   return static_cast<const Internal::Adaptor::Application&>(handle);
366 }
367
368
369 } // namespace Adaptor
370
371 } // namespace Internal
372
373 } // namespace Dali
374
375 #endif // __DALI_INTERNAL_APPLICATION_H__