b5a0666c0f219262edf01d0b3313b3b45455c127
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / application.h
1 #ifndef DALI_APPLICATION_H
2 #define DALI_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/common/view-mode.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/signals/callback.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/adaptor-framework/application-configuration.h>
28 #include <dali/public-api/adaptor-framework/device-status.h>
29 #include <dali/public-api/adaptor-framework/window.h>
30
31 namespace Dali
32 {
33 /**
34  * @addtogroup dali_adaptor_framework
35  * @{
36  */
37
38 namespace Internal DALI_INTERNAL
39 {
40 namespace Adaptor
41 {
42 class Application;
43 }
44 }
45 /**
46  * @brief An Application class object should be created by every application
47  * that wishes to use Dali.
48  *
49  * It provides a means for initializing the
50  * resources required by the Dali::Core.
51  *
52  * The Application class emits several signals which the user can
53  * connect to.  The user should not create any Dali objects in the main
54  * function and instead should connect to the Init signal of the
55  * Application and create the Dali objects in the connected callback.
56  *
57  * Applications should follow the example below:
58  *
59  * @code
60  * class ExampleController: public ConnectionTracker
61  * {
62  * public:
63  *   ExampleController( Application& application )
64  *   : mApplication( application )
65  *   {
66  *     mApplication.InitSignal().Connect( this, &ExampleController::Create );
67  *   }
68  *
69  *   void Create( Application& application )
70  *   {
71  *     // Create Dali components...
72  *   }
73  *  ...
74  * private:
75  *   Application& mApplication;
76  * };
77  *
78  * int main (int argc, char **argv)
79  * {
80  *   Application app = Application::New(&argc, &argv);
81  *   ExampleController example( app );
82  *   app.MainLoop();
83  * }
84  * @endcode
85  *
86  * If required, you can also connect class member functions to a signal:
87  *
88  * @code
89  * MyApplication app;
90  * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
91  * @endcode
92  *
93  * This class accepts command line arguments as well. The following options are supported:
94  *
95  * @code
96  *     --no-vsync       Disable VSync on Render
97  *  -w|--width          Stage Width
98  *  -h|--height         Stage Height
99  *  -d|--dpi            Emulated DPI
100  *     --help           Help
101  * @endcode
102  *
103  * When the above options are found, they are stripped from argv, and argc is updated appropriately.
104  * @SINCE_1_0.0
105  */
106 class DALI_ADAPTOR_API Application : public BaseHandle
107 {
108 public:
109
110   typedef Signal< void (DeviceStatus::Battery::Status) > LowBatterySignalType; ///< Application device signal type @SINCE_1_2.62
111   typedef Signal< void (DeviceStatus::Memory::Status) > LowMemorySignalType;   ///< Application device signal type @SINCE_1_2.62
112   typedef Signal< void (Application&) > AppSignalType;  ///< Application lifecycle signal and system signal callback type @SINCE_1_0.0
113   typedef Signal< void (Application&, void *) > AppControlSignalType; ///< Application control signal callback type @SINCE_1_0.0
114
115   /**
116    * @brief Enumeration for deciding whether a Dali application window is opaque or transparent.
117    * @SINCE_1_0.0
118    */
119   enum WINDOW_MODE
120   {
121     OPAQUE = 0,       ///< The window will be opaque @SINCE_1_0.0
122     TRANSPARENT = 1   ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor() @SINCE_1_0.0
123   };
124
125 public:
126
127   /**
128    * @brief This is the constructor for applications without an argument list.
129    * @SINCE_1_0.0
130    * @PRIVLEVEL_PUBLIC
131    * @PRIVILEGE_DISPLAY
132    * @return A handle to the Application
133    */
134   static Application New();
135
136   /**
137    * @brief This is the constructor for applications.
138    *
139    * @SINCE_1_0.0
140    * @PRIVLEVEL_PUBLIC
141    * @PRIVILEGE_DISPLAY
142    * @param[in,out]  argc        A pointer to the number of arguments
143    * @param[in,out]  argv        A pointer to the argument list
144    * @return A handle to the Application
145    */
146   static Application New( int* argc, char **argv[] );
147
148   /**
149    * @brief This is the constructor for applications with a name.
150    *
151    * @SINCE_1_0.0
152    * @PRIVLEVEL_PUBLIC
153    * @PRIVILEGE_DISPLAY
154    * @param[in,out]  argc        A pointer to the number of arguments
155    * @param[in,out]  argv        A pointer to the argument list
156    * @param[in]      stylesheet  The path to user defined theme file
157    * @return A handle to the Application
158    * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
159    */
160   static Application New( int* argc, char **argv[], const std::string& stylesheet );
161
162   /**
163    * @brief This is the constructor for applications with a name.
164    *
165    * @SINCE_1_0.0
166    * @PRIVLEVEL_PUBLIC
167    * @PRIVILEGE_DISPLAY
168    * @param[in,out]  argc        A pointer to the number of arguments
169    * @param[in,out]  argv        A pointer to the argument list
170    * @param[in]      stylesheet  The path to user defined theme file
171    * @param[in]      windowMode  A member of WINDOW_MODE
172    * @return A handle to the Application
173    * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
174    */
175   static Application New( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode );
176
177   /**
178    * @brief This is the constructor for applications.
179    *
180    * @SINCE_1_2.60
181    * @PRIVLEVEL_PUBLIC
182    * @PRIVILEGE_DISPLAY
183    * @param[in,out]  argc         A pointer to the number of arguments
184    * @param[in,out]  argv         A pointer to the argument list
185    * @param[in]      stylesheet   The path to user defined theme file
186    * @param[in]      windowMode   A member of WINDOW_MODE
187    * @param[in]      positionSize A position and a size of the window
188    * @return A handle to the Application
189    * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
190    */
191   static Application New( int* argc, char **argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize );
192
193   /**
194    * @brief Constructs an empty handle.
195    * @SINCE_1_0.0
196    */
197   Application();
198
199   /**
200    * @brief Copy Constructor.
201    * @SINCE_1_0.0
202    * @param[in] application Handle to an object
203    */
204   Application( const Application& application );
205
206   /**
207    * @brief Assignment operator.
208    * @SINCE_1_0.0
209    * @param[in] application Handle to an object
210    * @return A reference to this
211    */
212   Application& operator=( const Application& application );
213
214   /**
215    * @brief Destructor.
216    *
217    * This is non-virtual since derived Handle types must not contain data or virtual methods.
218    * @SINCE_1_0.0
219    */
220   ~Application();
221
222 public:
223   /**
224    * @brief This starts the application.
225    *
226    * Choosing this form of main loop indicates that the default
227    * application configuration of APPLICATION_HANDLES_CONTEXT_LOSS is used. On platforms where
228    * context loss can occur, the application is responsible for tearing down and re-loading UI.
229    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
230    * @SINCE_1_0.0
231    */
232   void MainLoop();
233
234   /**
235    * @brief This starts the application, and allows the app to choose a different configuration.
236    *
237    * If the application plans on using the ReplaceSurface or ReplaceWindow API, then this will
238    * trigger context loss & regain.
239    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
240    * @SINCE_1_0.0
241    * @param[in] configuration The context loss configuration
242    */
243   void MainLoop(Configuration::ContextLoss configuration);
244
245   /**
246    * @brief This lowers the application to bottom without actually quitting it.
247    * @SINCE_1_0.0
248    */
249   void Lower();
250
251   /**
252    * @brief This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
253    * @SINCE_1_0.0
254    */
255   void Quit();
256
257   /**
258    * @brief Ensures that the function passed in is called from the main loop when it is idle.
259    * @SINCE_1_0.0
260    * @param[in] callback The function to call
261    * @return @c true if added successfully, @c false otherwise
262    *
263    * @note Function must be called from main event thread only
264    *
265    * A callback of the following type may be used:
266    * @code
267    *   void MyFunction();
268    * @endcode
269    * This callback will be deleted once it is called.
270    *
271    * @note Ownership of the callback is passed onto this class.
272    */
273   bool AddIdle( CallbackBase* callback );
274
275   /**
276    * @brief Retrieves the main window used by the Application class.
277    *
278    * The application writer can use the window to change indicator and orientation
279    * properties.
280    * @SINCE_1_0.0
281    * @return A handle to the window
282    */
283   Window GetWindow();
284
285   /**
286    * @DEPRECATED_1_4.12
287    * @brief Replaces the current window.
288    *
289    * This will force context loss.
290    * If you plan on using this API in your application, then you should configure
291    * it to prevent discard behavior when handling the Init signal.
292    * @SINCE_1_0.0
293    * @param[in] windowPosition The position and size parameters of the new window
294    * @param[in] name The name of the new window
295    */
296   void ReplaceWindow(PositionSize windowPosition, const std::string& name)  DALI_DEPRECATED_API;
297
298   /**
299    * @brief Get path application resources are stored at
300    *
301    * @SINCE_1_2.2
302    * @return the full path of the resources
303    */
304   static std::string GetResourcePath();
305
306   /**
307    * @brief This is used to get region information from device.
308    *
309    * @SINCE_1_2.62
310    * @return Region information
311    */
312   std::string GetRegion() const;
313
314   /**
315    * @brief This is used to get language information from device.
316    *
317    * @SINCE_1_2.62
318    * @return Language information
319    */
320   std::string GetLanguage() const;
321
322 public: // Stereoscopy
323
324   /**
325    * @DEPRECATED_1_3_51
326    * @brief Sets the viewing mode for the application.
327    * @SINCE_1_0.0
328    * @param[in] viewMode The new viewing mode
329    */
330   void SetViewMode( ViewMode viewMode );
331
332   /**
333    * @DEPRECATED_1_3_51
334    * @brief Gets the current viewing mode.
335    * @SINCE_1_0.0
336    * @return The current viewing mode
337    */
338   ViewMode GetViewMode() const;
339
340   /**
341    * @DEPRECATED_1_3_51
342    * @brief Sets the stereo base (eye separation) for Stereoscopic 3D.
343    *
344    * The stereo base is the distance in millimetres between the eyes. Typical values are
345    * between 50mm and 70mm. The default value is 65mm.
346    * @SINCE_1_0.0
347    * @param[in] stereoBase The stereo base (eye separation) for Stereoscopic 3D
348    */
349   void SetStereoBase( float stereoBase );
350
351   /**
352    * @DEPRECATED_1_3_51
353    * @brief Gets the stereo base (eye separation) for Stereoscopic 3D.
354    *
355    * @SINCE_1_0.0
356    * @return The stereo base (eye separation) for Stereoscopic 3D
357    */
358   float GetStereoBase() const;
359
360 public:  // Signals
361
362   /**
363    * @brief The user should connect to this signal to determine when they should initialize
364    * their application.
365    * @SINCE_1_0.0
366    * @return The signal to connect to
367    */
368   AppSignalType& InitSignal();
369
370   /**
371    * @brief The user should connect to this signal to determine when they should terminate
372    * their application.
373    * @SINCE_1_0.0
374    * @return The signal to connect to
375    */
376   AppSignalType& TerminateSignal();
377
378   /**
379    * @brief The user should connect to this signal if they need to perform any special
380    * activities when the application is about to be paused.
381    * @SINCE_1_0.0
382    * @return The signal to connect to
383    */
384   AppSignalType& PauseSignal();
385
386   /**
387    * @brief The user should connect to this signal if they need to perform any special
388    * activities when the application has resumed.
389    * @SINCE_1_0.0
390    * @return The signal to connect to
391    */
392   AppSignalType& ResumeSignal();
393
394   /**
395    * @brief This signal is sent when the system requires the user to reinitialize itself.
396    * @SINCE_1_0.0
397    * @return The signal to connect to
398    */
399   AppSignalType& ResetSignal();
400
401   /**
402    * @DEPRECATED_1_2.62 Use Window::ResizedSignal() instead.
403    * @brief This signal is emitted when the window application rendering on is resized.
404    * @SINCE_1_0.0
405    * @return The signal to connect to
406    */
407   AppSignalType& ResizeSignal() DALI_DEPRECATED_API;
408
409   /**
410   * @brief This signal is emitted when another application sends a launch request to the application.
411   *
412   * When the application is launched, this signal is emitted after the main loop of the application starts up.
413   * The passed parameter describes the launch request and contains the information about why the application is launched.
414   * @SINCE_1_0.0
415   * @return The signal to connect to
416   */
417   AppControlSignalType& AppControlSignal();
418
419   /**
420    * @brief This signal is emitted when the language is changed on the device.
421    * @SINCE_1_0.0
422    * @return The signal to connect to
423    */
424   AppSignalType& LanguageChangedSignal();
425
426   /**
427   * @brief This signal is emitted when the region of the device is changed.
428   * @SINCE_1_0.0
429   * @return The signal to connect to
430   */
431   AppSignalType& RegionChangedSignal();
432
433   /**
434   * @DEPRECATED_1_2.62 Use LowBatterySignal() instead.
435   * @brief This signal is emitted when the battery level of the device is low.
436   * @SINCE_1_0.0
437   * @return The signal to connect to
438   */
439   AppSignalType& BatteryLowSignal() DALI_DEPRECATED_API;
440
441   /**
442   * @DEPRECATED_1_2.62 Use LowMemorySignal() instead.
443   * @brief This signal is emitted when the memory level of the device is low.
444   * @SINCE_1_0.0
445   * @return The signal to connect to
446   */
447   AppSignalType& MemoryLowSignal() DALI_DEPRECATED_API;
448
449   /**
450    * @brief This signal is emitted when the battery level of the device is low.
451    * @SINCE_1_2.62
452    * @return The signal to connect to
453    */
454   LowBatterySignalType& LowBatterySignal();
455
456   /**
457    * @brief This signal is emitted when the memory level of the device is low.
458    * @SINCE_1_2.62
459    * @return The signal to connect to
460    */
461   LowMemorySignalType& LowMemorySignal();
462
463 public: // Not intended for application developers
464   /// @cond internal
465   /**
466    * @brief Internal constructor.
467    * @SINCE_1_0.0
468    */
469   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
470   /// @endcond
471 };
472
473 /**
474  * @}
475  */
476 } // namespace Dali
477
478 #endif // DALI_APPLICATION_H