Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / public-api / adaptor-framework / application.h
1 #ifndef __DALI_APPLICATION_H__
2 #define __DALI_APPLICATION_H__
3
4 /*
5  * Copyright (c) 2015 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 <string>
23 #include <dali/public-api/common/view-mode.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/signals/callback.h>
26
27
28 // INTERNAL INCLUDES
29 #include "application-configuration.h"
30 #include "window.h"
31
32 namespace Dali
33 {
34 /**
35  * @addtogroup dali_adaptor_framework
36  * @{
37  */
38
39 namespace Internal DALI_INTERNAL
40 {
41 namespace Adaptor
42 {
43 class Application;
44 }
45 }
46 /**
47  * @brief An Application class object should be created by every application
48  * that wishes to use Dali.  It provides a means for initialising the
49  * resources required by the Dali::Core.
50  *
51  * The Application class emits several signals which the user can
52  * connect to.  The user should not create any Dali objects in the main
53  * function and instead should connect to the Init signal of the
54  * Application and create the Dali objects in the connected callback.
55  *
56  * Applications should follow the example below:
57  *
58  * @code
59  * void CreateProgram(Application app)
60  * {
61  *   // Create Dali components...
62  *   // Can instantiate here, if required
63  * }
64  *
65  * int main (int argc, char **argv)
66  * {
67  *   Application app = Application::New(&argc, &argv);
68  *   app.InitSignal().Connect(&CreateProgram);
69  *   app.MainLoop();
70  * }
71  * @endcode
72  *
73  * If required, you can also connect class member functions to a signal:
74  *
75  * @code
76  * MyApplication app;
77  * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
78  * @endcode
79  *
80  * This class accepts command line arguments as well. The following options are supported:
81  *
82  * @code
83  *     --no-vsync       Disable VSync on Render
84  *  -w|--width          Stage Width
85  *  -h|--height         Stage Height
86  *  -d|--dpi            Emulated DPI
87  *     --help           Help
88  * @endcode
89  *
90  * When the above options are found, they are stripped from argv, and argc is updated appropriately.
91  * @SINCE_1_0.0
92  */
93 class DALI_IMPORT_API Application : public BaseHandle
94 {
95 public:
96
97   typedef Signal< void (Application&) > AppSignalType;
98   typedef Signal< void (Application&, void *) > AppControlSignalType;
99
100   /**
101    * @brief Decides whether a Dali application window is opaque or transparent.
102    * @SINCE_1_0.0
103    */
104   enum WINDOW_MODE
105   {
106     OPAQUE = 0,       ///< The window will be opaque @SINCE_1_0.0
107     TRANSPARENT = 1   ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor() @SINCE_1_0.0
108   };
109
110 public:
111
112   /**
113    * @brief This is the constructor for applications without an argument list.
114    * @SINCE_1_0.0
115    */
116   static Application New();
117
118   /**
119    * @brief This is the constructor for applications.
120    *
121    * @SINCE_1_0.0
122    * @param[in,out]  argc        A pointer to the number of arguments
123    * @param[in,out]  argv        A pointer the the argument list
124    */
125   static Application New( int* argc, char **argv[] );
126
127   /**
128    * @brief This is the constructor for applications with a name
129    *
130    * @SINCE_1_0.0
131    * @param[in,out]  argc        A pointer to the number of arguments
132    * @param[in,out]  argv        A pointer the the argument list
133    * @param[in]      stylesheet  The path to user defined theme file
134    */
135   static Application New( int* argc, char **argv[], const std::string& stylesheet );
136
137   /**
138    * @brief This is the constructor for applications with a name
139    *
140    * @SINCE_1_0.0
141    * @param[in,out]  argc        A pointer to the number of arguments
142    * @param[in,out]  argv        A pointer the the argument list
143    * @param[in]      stylesheet  The path to user defined theme file
144    * @param[in]      windowMode  A member of WINDOW_MODE
145    */
146   static Application New( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode );
147
148   /**
149    * @brief Construct an empty handle
150    * @SINCE_1_0.0
151    */
152   Application();
153
154   /**
155    * @brief Copy Constructor
156    * @SINCE_1_0.0
157    */
158   Application( const Application& application );
159
160   /**
161    * @brief Assignment operator
162    * @SINCE_1_0.0
163    */
164   Application& operator=( const Application& applicaton );
165
166   /**
167    * @brief Destructor
168    *
169    * This is non-virtual since derived Handle types must not contain data or virtual methods.
170    * @SINCE_1_0.0
171    */
172   ~Application();
173
174 public:
175   /**
176    * @brief This starts the application. Choosing this form of main loop indicates that the default
177    * application configuration of APPLICATION_HANDLES_CONTEXT_LOSS is used. On platforms where
178    * context loss can occur, the application is responsible for tearing down and re-loading UI.
179    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
180    * @SINCE_1_0.0
181    */
182   void MainLoop();
183
184   /**
185    * @brief This starts the application, and allows the app to choose a different configuration.
186    * If the application plans on using the ReplaceSurface or ReplaceWindow API, then this will
187    * trigger context loss & regain.
188    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
189    * @SINCE_1_0.0
190    */
191   void MainLoop(Configuration::ContextLoss configuration);
192
193   /**
194    * @brief This lowers the application to bottom without actually quitting it
195    * @SINCE_1_0.0
196    */
197   void Lower();
198
199   /**
200    * @brief This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
201    * @SINCE_1_0.0
202    */
203   void Quit();
204
205   /**
206    * @brief Ensures that the function passed in is called from the main loop when it is idle.
207    * @SINCE_1_0.0
208    * @param[in]  callback  The function to call.
209    * @return true if added successfully, false otherwise
210    *
211    * @note Function must be called from main event thread only
212    *
213    * A callback of the following type may be used:
214    * @code
215    *   void MyFunction();
216    * @endcode
217    *
218    * @note Ownership of the callback is passed onto this class.
219    */
220   bool AddIdle( CallbackBase* callback );
221
222   /**
223    * @brief Retrieves the window used by the Application class.
224    * The application writer can use the window to change indicator and orientation
225    * properties.
226    * @SINCE_1_0.0
227    * @return A handle to the window
228    */
229   Window GetWindow();
230
231   /**
232    * @brief Replace the current window.
233    * This will force context loss.
234    * If you plan on using this API in your application, then you should configure
235    * it to prevent discard behaviour when handling the Init signal.
236    * @SINCE_1_0.0
237    * @param[in] windowPosition The position and size parameters of the new window
238    * @param[in] name The name of the new window
239    */
240   void ReplaceWindow(PositionSize windowPosition, const std::string& name);
241
242 public: // Stereoscopy
243
244   /**
245    * @brief Set the viewing mode for the application.
246    * @SINCE_1_0.0
247    * @param[in] viewMode The new viewing mode.
248    */
249   void SetViewMode( ViewMode viewMode );
250
251   /**
252    * @brief Get the current viewing mode.
253    * @SINCE_1_0.0
254    * @return The current viewing mode.
255    */
256   ViewMode GetViewMode() const;
257
258   /**
259    * @brief Set the stereo base (eye separation) for Stereoscopic 3D
260    *
261    * @SINCE_1_0.0
262    * @param[in] stereoBase The stereo base (eye separation) for Stereoscopic 3D
263    */
264   void SetStereoBase( float stereoBase );
265
266   /**
267    * @brief Get the stereo base (eye separation) for Stereoscopic 3D
268    *
269    * @SINCE_1_0.0
270    * @return The stereo base (eye separation) for Stereoscopic 3D
271    */
272   float GetStereoBase() const;
273
274 public:  // Signals
275
276   /**
277    * @brief The user should connect to this signal to determine when they should initialise
278    * their application.
279    * @SINCE_1_0.0
280    */
281   AppSignalType& InitSignal();
282
283   /**
284    * @brief The user should connect to this signal to determine when they should terminate
285    * their application
286    * @SINCE_1_0.0
287    */
288   AppSignalType& TerminateSignal();
289
290   /**
291    * @brief The user should connect to this signal if they need to perform any special
292    * activities when the application is about to be paused.
293    * @SINCE_1_0.0
294    */
295   AppSignalType& PauseSignal();
296
297   /**
298    * @brief The user should connect to this signal if they need to perform any special
299    * activities when the application has resumed.
300    * @SINCE_1_0.0
301    */
302   AppSignalType& ResumeSignal();
303
304   /**
305    * @brief This signal is sent when the system requires the user to reinitialise itself.
306    * @SINCE_1_0.0
307    */
308   AppSignalType& ResetSignal();
309
310   /**
311    * @brief This signal is emitted when the window the application is rendering on is resized.
312    * @SINCE_1_0.0
313    */
314   AppSignalType& ResizeSignal();
315
316   /**
317   * @brief This signal is emitted when another application sends a launch request to the application.
318   * When the application is launched, this signal is emitted after the main loop of the application starts up.
319   * The passed parameter describes the launch request and contains the information about why the application is launched.
320   * @SINCE_1_0.0
321   */
322   AppControlSignalType& AppControlSignal();
323
324   /**
325    * @brief This signal is emitted when the language is changed on the device.
326    * @SINCE_1_0.0
327    */
328   AppSignalType& LanguageChangedSignal();
329
330   /**
331   * @brief This signal is emitted when the region of the device is changed.
332   * @SINCE_1_0.0
333   */
334   AppSignalType& RegionChangedSignal();
335
336   /**
337   * @brief This signal is emitted when the battery level of the device is low.
338   * @SINCE_1_0.0
339   */
340   AppSignalType& BatteryLowSignal();
341
342   /**
343   * @brief This signal is emitted when the memory level of the device is low.
344   * @SINCE_1_0.0
345   */
346   AppSignalType& MemoryLowSignal();
347
348 public: // Not intended for application developers
349   /**
350    * @brief Internal constructor
351    * @SINCE_1_0.0
352    */
353   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
354 };
355
356 /**
357  * @}
358  */
359 } // namespace Dali
360
361 #endif // __DALI_APPLICATION_H__