Merge "Remove unnecessary stream operators from radian and degree as well as unnecess...
[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) 2014 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
32 namespace Dali
33 {
34 class Adaptor;
35 class Window;
36
37 namespace Internal
38 {
39
40 namespace Adaptor
41 {
42 class CommandLineOptions;
43 class EventLoop;
44
45 typedef Dali::Rect<int> PositionSize;
46
47 class Application;
48 typedef IntrusivePtr<Application> ApplicationPtr;
49
50 /**
51  * Implementation of the Application class.
52  */
53 class Application : public BaseObject, public Framework::Observer
54 {
55 public:
56
57   typedef Dali::Application::AppSignalType AppSignalType;
58   typedef Dali::Application::AppControlSignalType AppControlSignalType;
59
60   /**
61    * Constructor
62    * @param[in]  app         The public instance of the 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]  name        A name of application
66    * @param[in]  baseLayout  The base layout that the application has been written for
67    * @param[in]  windowMode  A member of Dali::Application::WINDOW_MODE
68    */
69   static ApplicationPtr New(int* argc, char **argv[], const std::string& name,
70                             const DeviceLayout& baseLayout,
71                             Dali::Application::WINDOW_MODE windowMode);
72
73   Application( int* argc, char **argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode );
74
75   /**
76    * Destructor
77    */
78   virtual ~Application();
79
80 public:
81
82   /**
83    * @copydoc Dali::Application::MainLoop()
84    */
85   void MainLoop(Dali::Configuration::ContextLoss configuration);
86
87   /**
88    * @copydoc Dali::Application::Lower()
89    */
90   void Lower();
91
92   /**
93    * @copydoc Dali::Application::Quit()
94    */
95   void Quit();
96
97   /**
98    * @copydoc Dali::Application::AddIdle()
99    */
100   bool AddIdle( CallbackBase* callback );
101
102   /**
103    * @copydoc Dali::Application::GetAdaptor();
104    */
105   Dali::Adaptor& GetAdaptor();
106
107   /**
108    * @copydoc Dali::Application::GetWindow();
109    */
110   Dali::Window GetWindow();
111
112   /**
113    * @copydoc Dali::Application::GetTheme();
114    */
115   const std::string& GetTheme();
116
117   /**
118    * @copydoc Dali::Application::SetTheme();
119    */
120   void SetTheme(const std::string& themeFilePath);
121
122   /**
123    * @copydoc Dali::Application::ReplaceWindow();
124    */
125   void ReplaceWindow(PositionSize windowPosition, const std::string& name);
126
127 public: // Stereoscopy
128
129   /**
130    * @copydoc Dali::Application::SetViewMode()
131    */
132   void SetViewMode( ViewMode viewMode );
133
134   /**
135    * @copydoc Dali::Application::GetViewMode()
136    */
137   ViewMode GetViewMode() const;
138
139   /**
140    * @copydoc Dali::Application::SetStereoBase()
141    */
142   void SetStereoBase( float stereoBase );
143
144   /**
145    * @copydoc Dali::Application::GetStereoBase()
146    */
147   float GetStereoBase() const;
148
149 public: // From Framework::Observer
150
151   /**
152    * Called when the framework is initialised.
153    */
154   virtual void OnInit();
155
156   /**
157    * Called when the framework is terminated.
158    */
159   virtual void OnTerminate();
160
161   /**
162    * Called when the framework is paused.
163    */
164   virtual void OnPause();
165
166   /**
167    * Called when the framework resumes from a paused state.
168    */
169   virtual void OnResume();
170
171   /**
172   * Called when the framework received AppControlSignal.
173   * @param[in] The bundle data of AppControl event.
174   */
175   virtual void OnAppControl(void *data);
176
177   /**
178    * Called when the framework informs the application that it should reset itself.
179    */
180   virtual void OnReset();
181
182   /**
183    * Called when the framework informs the application that the language of the device has changed.
184    */
185   virtual void OnLanguageChanged();
186
187   /**
188   * Called when the framework informs the application that the region of the device has changed.
189   */
190   virtual void OnRegionChanged();
191
192   /**
193   * Called when the framework informs the application that the battery level of the device is low.
194   */
195   virtual void OnBatteryLow();
196
197   /**
198   * Called when the framework informs the application that the memory level of the device is low.
199   */
200   virtual void OnMemoryLow();
201
202 public:
203
204   /**
205    * Signal handler when the adaptor's window resizes itself.
206    * @param[in]  adaptor  The adaptor
207    */
208   void OnResize(Dali::Adaptor& adaptor);
209
210 public:  // Signals
211
212   /**
213    * @copydoc Dali::Application::InitSignal()
214    */
215   Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
216
217   /**
218    * @copydoc Dali::Application::TerminateSignal()
219    */
220   Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
221
222   /**
223    * @copydoc Dali::Application::PauseSignal()
224    */
225   Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
226
227   /**
228    * @copydoc Dali::Application::ResumeSignal()
229    */
230   Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
231
232   /**
233    * @copydoc Dali::Application::ResetSignal()
234    */
235   Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
236
237   /**
238   * @copydoc Dali::Application::AppControlSignal()
239   */
240   Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
241
242   /**
243    * @copydoc Dali::Application::ResizeSignal()
244    */
245   Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
246
247   /**
248    * @copydoc Dali::Application::LanguageChangedSignal()
249    */
250   Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
251
252   /**
253   * @copydoc Dali::Application::RegionChangedSignal()
254   */
255   Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
256
257   /**
258   * @copydoc Dali::Application::BatteryLowSignal()
259   */
260   Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
261
262   /**
263   * @copydoc Dali::Application::MemoryLowSignal()
264   */
265   Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
266
267 private:
268
269   // Undefined
270   Application(const Application&);
271   Application& operator=(Application&);
272
273 private:
274   /**
275    * Creates the window
276    */
277   void CreateWindow();
278
279   /**
280    * Creates the adaptor
281    */
282   void CreateAdaptor();
283
284   /**
285    * Quits from the main loop
286    */
287   void QuitFromMainLoop();
288
289 private:
290
291   AppSignalType                           mInitSignal;
292   AppSignalType                           mTerminateSignal;
293   AppSignalType                           mPauseSignal;
294   AppSignalType                           mResumeSignal;
295   AppSignalType                           mResetSignal;
296   AppSignalType                           mResizeSignal;
297   AppControlSignalType                    mAppControlSignal;
298   AppSignalType                           mLanguageChangedSignal;
299   AppSignalType                           mRegionChangedSignal;
300   AppSignalType                           mBatteryLowSignal;
301   AppSignalType                           mMemoryLowSignal;
302
303   EventLoop*                            mEventLoop;
304   Framework*                            mFramework;
305
306   Dali::Configuration::ContextLoss      mContextLossConfiguration;
307   CommandLineOptions*                   mCommandLineOptions;
308
309   Dali::SingletonService                mSingletonService;
310   Dali::Adaptor*                        mAdaptor;
311   Dali::Window                          mWindow;
312   Dali::Application::WINDOW_MODE        mWindowMode;
313   std::string                           mName;
314
315   bool                                  mInitialized;
316   DeviceLayout                          mBaseLayout;
317
318   SlotDelegate< Application >           mSlotDelegate;
319 };
320
321 inline Application& GetImplementation(Dali::Application& application)
322 {
323   DALI_ASSERT_ALWAYS(application && "application handle is empty");
324
325   BaseObject& handle = application.GetBaseObject();
326
327   return static_cast<Internal::Adaptor::Application&>(handle);
328 }
329
330 inline const Application& GetImplementation(const Dali::Application& application)
331 {
332   DALI_ASSERT_ALWAYS(application && "Timre handle is empty");
333
334   const BaseObject& handle = application.GetBaseObject();
335
336   return static_cast<const Internal::Adaptor::Application&>(handle);
337 }
338
339
340 } // namespace Adaptor
341
342 } // namespace Internal
343
344 } // namespace Dali
345
346 #endif // __DALI_INTERNAL_APPLICATION_H__