44d43623e1cfbeccadab9773e5ccf692f3c2f7e3
[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 <boost/bind.hpp>
23 #include <boost/function.hpp>
24 #include <boost/thread.hpp>
25
26 #include <dali/public-api/math/rect.h>
27 #include <dali/public-api/object/base-object.h>
28
29 // INTERNAL INCLUDES
30 #include <application.h>
31
32 #include <framework.h>
33 #include <window-impl.h>
34
35 namespace Dali
36 {
37 class Window;
38 class Adaptor;
39
40 namespace Internal
41 {
42
43 namespace Adaptor
44 {
45 class CommandLineOptions;
46 class EventLoop;
47
48 typedef Dali::Rect<int> PositionSize;
49
50 class Application;
51 typedef IntrusivePtr<Application> ApplicationPtr;
52
53 /**
54  * Implementation of the Application class.
55  */
56 class Application : public BaseObject, public Framework::Observer
57 {
58 public:
59
60   typedef Dali::Application::AppSignalV2 AppSignalV2;
61
62   /**
63    * Constructor
64    * @param[in]  app         The public instance of the Application
65    * @param[in]  argc        A pointer to the number of arguments
66    * @param[in]  argv        A pointer to the argument list
67    * @param[in]  name        A name of application
68    * @param[in]  baseLayout  The base layout that the application has been written for
69    * @param[in]  windowMode  A member of Dali::Application::WINDOW_MODE
70    */
71   static ApplicationPtr New(int* argc, char **argv[], const std::string& name,
72                             const DeviceLayout& baseLayout,
73                             Dali::Application::WINDOW_MODE windowMode);
74
75   Application(int* argc, char **argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode );
76
77   /**
78    * Destructor
79    */
80   virtual ~Application();
81
82 public:
83
84   /**
85    * @copydoc Dali::Application::MainLoop()
86    */
87   void MainLoop();
88
89   /**
90    * @copydoc Dali::Application::Lower()
91    */
92   void Lower();
93
94   /**
95    * @copydoc Dali::Application::Quit()
96    */
97   void Quit();
98
99   /**
100    * @copydoc Dali::Application::AddIdle()
101    */
102   bool AddIdle(boost::function<void(void)> callBack);
103
104   /**
105    * @copydoc Dali::Application::GetAdaptor();
106    */
107   Dali::Adaptor& GetAdaptor();
108
109   /**
110    * @copydoc Dali::Application::GetWindow();
111    */
112   Dali::Window GetWindow();
113
114   /**
115    * @copydoc Dali::Application::Get();
116    */
117   static Dali::Application Get();
118
119   /**
120    * @copydoc Dali::Application::GetTheme();
121    */
122   const std::string& GetTheme();
123
124   /**
125    * @copydoc Dali::Application::SetTheme();
126    */
127   void SetTheme(const std::string& themeFilePath);
128
129 public: // Stereoscopy
130
131   /**
132    * @copydoc Dali::Application::SetViewMode()
133    */
134   void SetViewMode( ViewMode viewMode );
135
136   /**
137    * @copydoc Dali::Application::GetViewMode()
138    */
139   ViewMode GetViewMode() const;
140
141   /**
142    * @copydoc Dali::Application::SetStereoBase()
143    */
144   void SetStereoBase( float stereoBase );
145
146   /**
147    * @copydoc Dali::Application::GetStereoBase()
148    */
149   float GetStereoBase() const;
150
151 public: // From Framework::Observer
152
153   /**
154    * Called when the framework is initialised.
155    */
156   virtual void OnInit();
157
158   /**
159    * Called when the framework is terminated.
160    */
161   virtual void OnTerminate();
162
163   /**
164    * Called when the framework is paused.
165    */
166   virtual void OnPause();
167
168   /**
169    * Called when the framework resumes from a paused state.
170    */
171   virtual void OnResume();
172
173   /**
174    * Called when the framework informs the application that it should reset itself.
175    */
176   virtual void OnReset();
177
178   /**
179    * Called when the framework informs the application that the language of the device has changed.
180    */
181   virtual void OnLanguageChanged();
182
183 public:
184
185   /**
186    * Signal handler when the adaptor's window resizes itself.
187    * @param[in]  adaptor  The adaptor
188    */
189   void OnResize(Dali::Adaptor& adaptor);
190
191 public:  // Signals
192
193   /**
194    * @copydoc Dali::Application::InitSignal()
195    */
196   Dali::Application::AppSignalV2& InitSignal() { return mInitSignalV2; }
197
198   /**
199    * @copydoc Dali::Application::TerminateSignal()
200    */
201   Dali::Application::AppSignalV2& TerminateSignal() { return mTerminateSignalV2; }
202
203   /**
204    * @copydoc Dali::Application::PauseSignal()
205    */
206   Dali::Application::AppSignalV2& PauseSignal() { return mPauseSignalV2; }
207
208   /**
209    * @copydoc Dali::Application::ResumeSignal()
210    */
211   Dali::Application::AppSignalV2& ResumeSignal() { return mResumeSignalV2; }
212
213   /**
214    * @copydoc Dali::Application::ResetSignal()
215    */
216   Dali::Application::AppSignalV2& ResetSignal() { return mResetSignalV2; }
217
218   /**
219    * @copydoc Dali::Application::ResizeSignal()
220    */
221   Dali::Application::AppSignalV2& ResizeSignal() { return mResizeSignalV2; }
222
223   /**
224    * @copydoc Dali::Application::LanguageChangedSignal()
225    */
226   Dali::Application::AppSignalV2& LanguageChangedSignal() { return mLanguageChangedSignalV2; }
227
228 private:
229
230   // Undefined
231   Application(const Application&);
232   Application& operator=(Application&);
233
234 private:
235   /**
236    * Creates the window
237    */
238   void CreateWindow();
239
240   /**
241    * Creates the adaptor
242    */
243   void CreateAdaptor();
244
245   /**
246    * Quits from the main loop
247    */
248   void QuitFromMainLoop();
249
250 private:
251
252   AppSignalV2                           mInitSignalV2;
253   AppSignalV2                           mTerminateSignalV2;
254   AppSignalV2                           mPauseSignalV2;
255   AppSignalV2                           mResumeSignalV2;
256   AppSignalV2                           mResetSignalV2;
257   AppSignalV2                           mResizeSignalV2;
258   AppSignalV2                           mLanguageChangedSignalV2;
259
260   EventLoop*                            mEventLoop;
261   Framework*                            mFramework;
262
263   CommandLineOptions*                   mCommandLineOptions;
264
265   Dali::Adaptor*                        mAdaptor;
266   Dali::Window                          mWindow;
267   Dali::Application::WINDOW_MODE        mWindowMode;
268   std::string                           mName;
269
270   bool                                  mInitialized;
271   DeviceLayout                          mBaseLayout;
272
273   SlotDelegate< Application >           mSlotDelegate;
274 };
275
276 inline Application& GetImplementation(Dali::Application& application)
277 {
278   DALI_ASSERT_ALWAYS(application && "application handle is empty");
279
280   BaseObject& handle = application.GetBaseObject();
281
282   return static_cast<Internal::Adaptor::Application&>(handle);
283 }
284
285 inline const Application& GetImplementation(const Dali::Application& application)
286 {
287   DALI_ASSERT_ALWAYS(application && "Timre handle is empty");
288
289   const BaseObject& handle = application.GetBaseObject();
290
291   return static_cast<const Internal::Adaptor::Application&>(handle);
292 }
293
294
295 } // namespace Adaptor
296
297 } // namespace Internal
298
299 } // namespace Dali
300
301 #endif // __DALI_INTERNAL_APPLICATION_H__