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