Merge "Support multiple surfaces for partial update" into devel/master
[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) 2020 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/object/base-handle.h>
23 #include <dali/public-api/signals/callback.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/adaptor-framework/device-status.h>
27 #include <dali/public-api/adaptor-framework/window.h>
28
29 namespace Dali
30 {
31
32 class ObjectRegistry;
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.
49  *
50  * It provides a means for initializing the
51  * resources required by the Dali::Core.
52  *
53  * The Application class emits several signals which the user can
54  * connect to.  The user should not create any Dali objects in the main
55  * function and instead should connect to the Init signal of the
56  * Application and create the Dali objects in the connected callback.
57  *
58  * Applications should follow the example below:
59  *
60  * @code
61  * class ExampleController: public ConnectionTracker
62  * {
63  * public:
64  *   ExampleController( Application& application )
65  *   : mApplication( application )
66  *   {
67  *     mApplication.InitSignal().Connect( this, &ExampleController::Create );
68  *   }
69  *
70  *   void Create( Application& application )
71  *   {
72  *     // Create Dali components...
73  *   }
74  *  ...
75  * private:
76  *   Application& mApplication;
77  * };
78  *
79  * int main (int argc, char **argv)
80  * {
81  *   Application app = Application::New(&argc, &argv);
82  *   ExampleController example( app );
83  *   app.MainLoop();
84  * }
85  * @endcode
86  *
87  * If required, you can also connect class member functions to a signal:
88  *
89  * @code
90  * MyApplication app;
91  * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
92  * @endcode
93  *
94  * This class accepts command line arguments as well. The following options are supported:
95  *
96  * @code
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 Move constructor.
216    *
217    * @SINCE_1_9.24
218    * @param[in] rhs A reference to the moved handle
219    */
220   Application( Application&& rhs );
221
222   /**
223    * @brief Move assignment operator.
224    *
225    * @SINCE_1_9.24
226    * @param[in] rhs A reference to the moved handle
227    * @return A reference to this handle
228    */
229   Application& operator=( Application&& rhs );
230
231   /**
232    * @brief Destructor.
233    *
234    * This is non-virtual since derived Handle types must not contain data or virtual methods.
235    * @SINCE_1_0.0
236    */
237   ~Application();
238
239 public:
240   /**
241    * @brief This starts the application.
242    *
243    * On platforms where context loss can occur, the application is responsible for tearing down and
244    * re-loading UI.  The application should listen to Stage::ContextLostSignal and
245    * Stage::ContextRegainedSignal.
246    *
247    * @SINCE_1_0.0
248    */
249   void MainLoop();
250
251   /**
252    * @brief This lowers the application to bottom without actually quitting it.
253    * @SINCE_1_0.0
254    */
255   void Lower();
256
257   /**
258    * @brief This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
259    * @SINCE_1_0.0
260    */
261   void Quit();
262
263   /**
264    * @brief Ensures that the function passed in is called from the main loop when it is idle.
265    * @SINCE_1_0.0
266    * @param[in] callback The function to call
267    * @return @c true if added successfully, @c false otherwise
268    *
269    * @note Function must be called from main event thread only
270    *
271    * A callback of the following type may be used:
272    * @code
273    *   void MyFunction();
274    * @endcode
275    * This callback will be deleted once it is called.
276    *
277    * @note Ownership of the callback is passed onto this class.
278    */
279   bool AddIdle( CallbackBase* callback );
280
281   /**
282    * @brief Retrieves the main window used by the Application class.
283    *
284    * The application writer can use the window to change indicator and orientation
285    * properties.
286    * @SINCE_1_0.0
287    * @return A handle to the window
288    */
289   Window GetWindow();
290
291   /**
292    * @brief Get path application resources are stored at
293    *
294    * @SINCE_1_2.2
295    * @return the full path of the resources
296    */
297   static std::string GetResourcePath();
298
299   /**
300    * @brief This is used to get region information from device.
301    *
302    * @SINCE_1_2.62
303    * @return Region information
304    */
305   std::string GetRegion() const;
306
307   /**
308    * @brief This is used to get language information from device.
309    *
310    * @SINCE_1_2.62
311    * @return Language information
312    */
313   std::string GetLanguage() const;
314
315   /**
316    * @brief Gets the Object registry.
317    *
318    * @SINCE_1_9.21
319    * @return The object registry
320    * @note This will only be a valid handle after the InitSignal has been emitted.
321    */
322   ObjectRegistry GetObjectRegistry() const;
323
324 public:  // Signals
325
326   /**
327    * @brief The user should connect to this signal to determine when they should initialize
328    * their application.
329    * @SINCE_1_0.0
330    * @return The signal to connect to
331    */
332   AppSignalType& InitSignal();
333
334   /**
335    * @brief The user should connect to this signal to determine when they should terminate
336    * their application.
337    * @SINCE_1_0.0
338    * @return The signal to connect to
339    */
340   AppSignalType& TerminateSignal();
341
342   /**
343    * @brief The user should connect to this signal if they need to perform any special
344    * activities when the application is about to be paused.
345    * @SINCE_1_0.0
346    * @return The signal to connect to
347    */
348   AppSignalType& PauseSignal();
349
350   /**
351    * @brief The user should connect to this signal if they need to perform any special
352    * activities when the application has resumed.
353    * @SINCE_1_0.0
354    * @return The signal to connect to
355    */
356   AppSignalType& ResumeSignal();
357
358   /**
359    * @brief This signal is sent when the system requires the user to reinitialize itself.
360    * @SINCE_1_0.0
361    * @return The signal to connect to
362    */
363   AppSignalType& ResetSignal();
364
365   /**
366   * @brief This signal is emitted when another application sends a launch request to the application.
367   *
368   * When the application is launched, this signal is emitted after the main loop of the application starts up.
369   * The passed parameter describes the launch request and contains the information about why the application is launched.
370   * @SINCE_1_0.0
371   * @return The signal to connect to
372   */
373   AppControlSignalType& AppControlSignal();
374
375   /**
376    * @brief This signal is emitted when the language is changed on the device.
377    * @SINCE_1_0.0
378    * @return The signal to connect to
379    */
380   AppSignalType& LanguageChangedSignal();
381
382   /**
383   * @brief This signal is emitted when the region of the device is changed.
384   * @SINCE_1_0.0
385   * @return The signal to connect to
386   */
387   AppSignalType& RegionChangedSignal();
388
389   /**
390    * @brief This signal is emitted when the battery level of the device is low.
391    * @SINCE_1_2.62
392    * @return The signal to connect to
393    */
394   LowBatterySignalType& LowBatterySignal();
395
396   /**
397    * @brief This signal is emitted when the memory level of the device is low.
398    * @SINCE_1_2.62
399    * @return The signal to connect to
400    */
401   LowMemorySignalType& LowMemorySignal();
402
403 public: // Not intended for application developers
404   /// @cond internal
405   /**
406    * @brief Internal constructor.
407    * @SINCE_1_0.0
408    */
409   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
410   /// @endcond
411 };
412
413 /**
414  * @}
415  */
416 } // namespace Dali
417
418 #endif // DALI_APPLICATION_H