Event handling refactoring to support EvasPlugin
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / application-impl.h
1 #ifndef DALI_INTERNAL_APPLICATION_H
2 #define DALI_INTERNAL_APPLICATION_H
3
4 /*
5  * Copyright (c) 2018 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 <dali/public-api/adaptor-framework/application.h>
27 #include <dali/devel-api/adaptor-framework/singleton-service.h>
28
29 #include <dali/internal/adaptor/common/framework.h>
30 #include <dali/internal/system/common/environment-options.h>
31 #include <dali/internal/adaptor/common/adaptor-builder-impl.h>
32
33 namespace Dali
34 {
35 class Adaptor;
36 class Window;
37
38 namespace Internal
39 {
40
41 namespace Adaptor
42 {
43
44 namespace Launchpad
45 {
46
47 /**
48  * @brief Launchpad is used to improve application launch performance.
49  * When an application is pre-initialized, so files are preloaded, some functions are initialized and a window is made in advance.
50  */
51 enum State
52 {
53   NONE,              ///< The default state
54   PRE_INITIALIZED    ///< Application is pre-initialized.
55 };
56
57 } // namespace Launchpad
58
59 class CommandLineOptions;
60 class EventLoop;
61
62 typedef Dali::Rect<int> PositionSize;
63
64 class Application;
65 typedef IntrusivePtr<Application> ApplicationPtr;
66
67 /**
68  * Implementation of the Application class.
69  */
70 class Application : public BaseObject, public Framework::Observer
71 {
72 public:
73
74   typedef Dali::Application::LowBatterySignalType LowBatterySignalType;
75   typedef Dali::Application::LowMemorySignalType LowMemorySignalType;
76   typedef Dali::Application::AppSignalType AppSignalType;
77   typedef Dali::Application::AppControlSignalType AppControlSignalType;
78   typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
79
80   /**
81    * Create a new application
82    * @param[in]  argc         A pointer to the number of arguments
83    * @param[in]  argv         A pointer to the argument list
84    * @param[in]  stylesheet   The path to user defined theme file
85    * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
86    * @param[in]  positionSize A position and a size of the window
87    * @param[in]  applicationType  A member of Dali::Framework::Type
88    */
89   static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet,
90     WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
91
92   /**
93    * @copydoc Dali::DevelApplication::PreInitialize()
94    */
95   static void PreInitialize( int* argc, char** argv[] );
96
97 public:
98
99   /**
100    * @copydoc Dali::Application::MainLoop()
101    */
102   void MainLoop(Dali::Configuration::ContextLoss configuration);
103
104   /**
105    * @copydoc Dali::Application::Lower()
106    */
107   void Lower();
108
109   /**
110    * @copydoc Dali::Application::Quit()
111    */
112   void Quit();
113
114   /**
115    * @copydoc Dali::Application::AddIdle()
116    */
117   bool AddIdle( CallbackBase* callback, bool hasReturnValue );
118
119   /**
120    * @copydoc Dali::Application::GetAdaptor();
121    */
122   Dali::Adaptor& GetAdaptor();
123
124   /**
125    * @copydoc Dali::Application::GetWindow();
126    */
127   Dali::Window GetWindow();
128
129   /**
130    * @copydoc Dali::Application::GetRegion();
131    */
132   std::string GetRegion() const;
133
134   /**
135    * @copydoc Dali::Application::GetLanguage();
136    */
137   std::string GetLanguage() const;
138
139   /**
140    * @copydoc Dali::Application::ReplaceWindow();
141    */
142   void ReplaceWindow( const PositionSize& positionSize, const std::string& name);
143
144   /**
145    * @copydoc Dali::Application::GetResourcePath();
146    */
147   static std::string GetResourcePath();
148
149   /**
150    * @copydoc Dali::DevelApplication::GetDataPath()
151    */
152   static std::string GetDataPath();
153
154   /**
155    * Retrieves the pre-initialized application.
156    *
157    * @return A pointer to the pre-initialized application
158    */
159   static ApplicationPtr GetPreInitializedApplication();
160
161 public: // Stereoscopy
162
163   /**
164    * @copydoc Dali::Application::SetViewMode()
165    */
166   void SetViewMode( ViewMode viewMode );
167
168   /**
169    * @copydoc Dali::Application::GetViewMode()
170    */
171   ViewMode GetViewMode() const;
172
173   /**
174    * @copydoc Dali::Application::SetStereoBase()
175    */
176   void SetStereoBase( float stereoBase );
177
178   /**
179    * @copydoc Dali::Application::GetStereoBase()
180    */
181   float GetStereoBase() const;
182
183 public: // From Framework::Observer
184
185   /**
186    * Called when the framework is initialised.
187    */
188   virtual void OnInit();
189
190   /**
191    * Called when the framework is terminated.
192    */
193   virtual void OnTerminate();
194
195   /**
196    * Called when the framework is paused.
197    */
198   virtual void OnPause();
199
200   /**
201    * Called when the framework resumes from a paused state.
202    */
203   virtual void OnResume();
204
205   /**
206   * Called when the framework received AppControlSignal.
207   * @param[in] The bundle data of AppControl event.
208   */
209   virtual void OnAppControl(void *data);
210
211   /**
212    * Called when the framework informs the application that it should reset itself.
213    */
214   virtual void OnReset();
215
216   /**
217    * Called when the framework informs the application that the language of the device has changed.
218    */
219   virtual void OnLanguageChanged();
220
221   /**
222   * Called when the framework informs the application that the region of the device has changed.
223   */
224   virtual void OnRegionChanged();
225
226   /**
227   * Called when the framework informs the application that the battery level of the device is low.
228   */
229   virtual void OnBatteryLow( Dali::DeviceStatus::Battery::Status status );
230
231   /**
232   * Called when the framework informs the application that the memory level of the device is low.
233   */
234   virtual void OnMemoryLow( Dali::DeviceStatus::Memory::Status status );
235
236 public:
237
238   /**
239    * Signal handler when the adaptor's window resizes itself.
240    * @param[in]  adaptor  The adaptor
241    */
242   void OnResize(Dali::Adaptor& adaptor);
243
244   /**
245    * Sets a user defined theme file.
246    * This should be called before initialization.
247    * @param[in] stylesheet The path to user defined theme file
248    */
249   void SetStyleSheet( const std::string& stylesheet );
250
251 public:  // Signals
252
253   /**
254    * @copydoc Dali::Application::InitSignal()
255    */
256   Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
257
258   /**
259    * @copydoc Dali::Application::TerminateSignal()
260    */
261   Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
262
263   /**
264    * @copydoc Dali::Application::PauseSignal()
265    */
266   Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
267
268   /**
269    * @copydoc Dali::Application::ResumeSignal()
270    */
271   Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
272
273   /**
274    * @copydoc Dali::Application::ResetSignal()
275    */
276   Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
277
278   /**
279   * @copydoc Dali::Application::AppControlSignal()
280   */
281   Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
282
283   /**
284    * @copydoc Dali::Application::ResizeSignal()
285    */
286   Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
287
288   /**
289    * @copydoc Dali::Application::LanguageChangedSignal()
290    */
291   Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
292
293   /**
294   * @copydoc Dali::Application::RegionChangedSignal()
295   */
296   Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
297
298   /**
299   * @copydoc Dali::Application::BatteryLowSignal()
300   */
301   Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
302
303   /**
304   * @copydoc Dali::Application::MemoryLowSignal()
305   */
306   Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
307
308   /**
309   * @copydoc Dali::Application::LowBatterySignal()
310   */
311   Dali::Application::LowBatterySignalType& LowBatterySignal() { return mLowBatterySignal; }
312
313   /**
314   * @copydoc Dali::Application:::LowMemorySignal()
315   */
316   Dali::Application::LowMemorySignalType& LowMemorySignal() { return mLowMemorySignal; }
317
318 protected:
319
320   /**
321    * Private Constructor
322    * @param[in]  argc         A pointer to the number of arguments
323    * @param[in]  argv         A pointer to the argument list
324    * @param[in]  stylesheet   The path to user defined theme file
325    * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
326    * @param[in]  positionSize A position and a size of the window
327    * @param[in]  applicationType  A member of Dali::Framework::Type
328    */
329   Application( int* argc, char **argv[], const std::string& stylesheet,
330       WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
331
332   /**
333    * Destructor
334    */
335   virtual ~Application();
336
337   // Undefined
338   Application(const Application&);
339   Application& operator=(Application&);
340
341   /**
342    * Creates the window
343    */
344   void CreateWindow();
345
346   /**
347    * Creates the adaptor
348    */
349   void CreateAdaptor();
350
351   /**
352    * Creates the adaptor builder
353    */
354   void CreateAdaptorBuilder();
355
356   /**
357    * Quits from the main loop
358    */
359   void QuitFromMainLoop();
360
361 private:
362
363   AppSignalType                         mInitSignal;
364   AppSignalType                         mTerminateSignal;
365   AppSignalType                         mPauseSignal;
366   AppSignalType                         mResumeSignal;
367   AppSignalType                         mResetSignal;
368   AppSignalType                         mResizeSignal;
369   AppControlSignalType                  mAppControlSignal;
370   AppSignalType                         mLanguageChangedSignal;
371   AppSignalType                         mRegionChangedSignal;
372   AppSignalType                         mBatteryLowSignal;
373   AppSignalType                         mMemoryLowSignal;
374   LowBatterySignalType                  mLowBatterySignal;
375   LowMemorySignalType                   mLowMemorySignal;
376
377   EventLoop*                            mEventLoop;
378   Framework*                            mFramework;
379
380   Dali::Configuration::ContextLoss      mContextLossConfiguration;
381   CommandLineOptions*                   mCommandLineOptions;
382
383   Dali::SingletonService                   mSingletonService;
384   Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder;   ///< The adaptor builder
385   Dali::Adaptor*                           mAdaptor;
386
387   // The Main Window is that window created by the Application during initial startup
388   // (previously this was the only window)
389   Dali::Window                             mMainWindow;       ///< Main Window instance
390   Dali::Application::WINDOW_MODE           mMainWindowMode;   ///< Window mode of the main window
391   std::string                              mMainWindowName;   ///< Name of the main window as obtained from environment options
392
393   bool                                     mMainWindowReplaced;   ///< Whether the main window has been replaced
394
395   std::string                              mStylesheet;
396   EnvironmentOptions                       mEnvironmentOptions;
397   PositionSize                             mWindowPositionSize;
398   Launchpad::State                         mLaunchpadState;
399   bool                                     mUseRemoteSurface;
400
401   SlotDelegate< Application >              mSlotDelegate;
402
403   ViewMode                                 mViewMode;
404   float                                    mStereoBase;
405
406   static ApplicationPtr                    gPreInitializedApplication;
407 };
408
409 inline Application& GetImplementation(Dali::Application& application)
410 {
411   DALI_ASSERT_ALWAYS(application && "application handle is empty");
412
413   BaseObject& handle = application.GetBaseObject();
414
415   return static_cast<Internal::Adaptor::Application&>(handle);
416 }
417
418 inline const Application& GetImplementation(const Dali::Application& application)
419 {
420   DALI_ASSERT_ALWAYS(application && "application handle is empty");
421
422   const BaseObject& handle = application.GetBaseObject();
423
424   return static_cast<const Internal::Adaptor::Application&>(handle);
425 }
426
427
428 } // namespace Adaptor
429
430 } // namespace Internal
431
432 } // namespace Dali
433
434 #endif // DALI_INTERNAL_APPLICATION_H