[Tizen] Remove graphics-api relative codes in public-api/application.h
[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) 2022 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 class ObjectRegistry;
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 } // namespace DALI_INTERNAL
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  *  -w|--width          Stage Width
97  *  -h|--height         Stage Height
98  *  -d|--dpi            Emulated DPI
99  *     --help           Help
100  * @endcode
101  *
102  * When the above options are found, they are stripped from argv, and argc is updated appropriately.
103  * @SINCE_1_0.0
104  */
105 class DALI_ADAPTOR_API Application : public BaseHandle
106 {
107 public:
108   typedef Signal<void(DeviceStatus::Battery::Status)> LowBatterySignalType; ///< Application device signal type @SINCE_1_2.62
109   typedef Signal<void(DeviceStatus::Memory::Status)>  LowMemorySignalType;  ///< Application device signal type @SINCE_1_2.62
110   typedef Signal<void(Application&)>                  AppSignalType;        ///< Application lifecycle signal and system signal callback type @SINCE_1_0.0
111   typedef Signal<void(Application&, void*)>           AppControlSignalType; ///< Application control signal callback type @SINCE_1_0.0
112
113   /**
114    * @brief Enumeration for deciding whether a Dali application window is opaque or transparent.
115    * @SINCE_1_0.0
116    */
117   enum WINDOW_MODE
118   {
119     OPAQUE      = 0, ///< The window will be opaque @SINCE_1_0.0
120     TRANSPARENT = 1  ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor() @SINCE_1_0.0
121   };
122
123 public:
124   /**
125    * @brief This is the constructor for applications without an argument list.
126    * @SINCE_1_0.0
127    * @PRIVLEVEL_PUBLIC
128    * @PRIVILEGE_DISPLAY
129    * @return A handle to the Application
130    */
131   static Application New();
132
133   /**
134    * @brief This is the constructor for applications.
135    *
136    * @SINCE_1_0.0
137    * @PRIVLEVEL_PUBLIC
138    * @PRIVILEGE_DISPLAY
139    * @param[in,out]  argc        A pointer to the number of arguments
140    * @param[in,out]  argv        A pointer to the argument list
141    * @return A handle to the Application
142    */
143   static Application New(int* argc, char** argv[]);
144
145   /**
146    * @brief This is the constructor for applications with a name.
147    *
148    * @SINCE_1_0.0
149    * @PRIVLEVEL_PUBLIC
150    * @PRIVILEGE_DISPLAY
151    * @param[in,out]  argc        A pointer to the number of arguments
152    * @param[in,out]  argv        A pointer to the argument list
153    * @param[in]      stylesheet  The path to user defined theme file
154    * @return A handle to the Application
155    * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
156    */
157   static Application New(int* argc, char** argv[], const std::string& stylesheet);
158
159   /**
160    * @brief This is the constructor for applications with a name.
161    *
162    * @SINCE_1_0.0
163    * @PRIVLEVEL_PUBLIC
164    * @PRIVILEGE_DISPLAY
165    * @param[in,out]  argc        A pointer to the number of arguments
166    * @param[in,out]  argv        A pointer to the argument list
167    * @param[in]      stylesheet  The path to user defined theme file
168    * @param[in]      windowMode  A member of WINDOW_MODE
169    * @return A handle to the Application
170    * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
171    */
172   static Application New(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode);
173
174   /**
175    * @brief This is the constructor for applications.
176    *
177    * @SINCE_1_2.60
178    * @PRIVLEVEL_PUBLIC
179    * @PRIVILEGE_DISPLAY
180    * @param[in,out]  argc         A pointer to the number of arguments
181    * @param[in,out]  argv         A pointer to the argument list
182    * @param[in]      stylesheet   The path to user defined theme file
183    * @param[in]      windowMode   A member of WINDOW_MODE
184    * @param[in]      positionSize A position and a size of the window
185    * @return A handle to the Application
186    * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
187    */
188   static Application New(int* argc, char** argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize);
189
190   /**
191    * @brief Constructs an empty handle.
192    * @SINCE_1_0.0
193    */
194   Application();
195
196   /**
197    * @brief Copy Constructor.
198    * @SINCE_1_0.0
199    * @param[in] application Handle to an object
200    */
201   Application(const Application& application);
202
203   /**
204    * @brief Assignment operator.
205    * @SINCE_1_0.0
206    * @param[in] application Handle to an object
207    * @return A reference to this
208    */
209   Application& operator=(const Application& application);
210
211   /**
212    * @brief Move constructor.
213    *
214    * @SINCE_1_9.24
215    * @param[in] rhs A reference to the moved handle
216    */
217   Application(Application&& rhs);
218
219   /**
220    * @brief Move assignment operator.
221    *
222    * @SINCE_1_9.24
223    * @param[in] rhs A reference to the moved handle
224    * @return A reference to this handle
225    */
226   Application& operator=(Application&& rhs);
227
228   /**
229    * @brief Destructor.
230    *
231    * This is non-virtual since derived Handle types must not contain data or virtual methods.
232    * @SINCE_1_0.0
233    */
234   ~Application();
235
236 public:
237   /**
238    * @brief This starts the application.
239    *
240    * On platforms where context loss can occur, the application is responsible for tearing down and
241    * re-loading UI.  The application should listen to Stage::ContextLostSignal and
242    * Stage::ContextRegainedSignal.
243    *
244    * @SINCE_1_0.0
245    */
246   void MainLoop();
247
248   /**
249    * @brief This lowers the application to bottom without actually quitting it.
250    * @SINCE_1_0.0
251    */
252   void Lower();
253
254   /**
255    * @brief This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
256    * @SINCE_1_0.0
257    */
258   void Quit();
259
260   /**
261    * @brief Ensures that the function passed in is called from the main loop when it is idle.
262    * @SINCE_1_0.0
263    * @param[in] callback The function to call
264    * @return @c true if added successfully, @c false otherwise
265    *
266    * @note Function must be called from main event thread only
267    *
268    * A callback of the following type may be used:
269    * @code
270    *   void MyFunction();
271    * @endcode
272    * This callback will be deleted once it is called.
273    *
274    * @note Ownership of the callback is passed onto this class.
275    */
276   bool AddIdle(CallbackBase* callback);
277
278   /**
279    * @brief Retrieves the main window used by the Application class.
280    *
281    * The application writer can use the window to change indicator and orientation
282    * properties.
283    * @SINCE_1_0.0
284    * @return A handle to the window
285    */
286   Window GetWindow();
287
288   /**
289    * @brief Get path application resources are stored at
290    *
291    * @SINCE_1_2.2
292    * @return the full path of the resources
293    */
294   static std::string GetResourcePath();
295
296   /**
297    * @brief This is used to get region information from device.
298    *
299    * @SINCE_1_2.62
300    * @return Region information
301    */
302   std::string GetRegion() const;
303
304   /**
305    * @brief This is used to get language information from device.
306    *
307    * @SINCE_1_2.62
308    * @return Language information
309    */
310   std::string GetLanguage() const;
311
312   /**
313    * @brief Gets the Object registry.
314    *
315    * @SINCE_1_9.21
316    * @return The object registry
317    * @note This will only be a valid handle after the InitSignal has been emitted.
318    */
319   ObjectRegistry GetObjectRegistry() const;
320
321 public: // Signals
322   /**
323    * @brief The user should connect to this signal to determine when they should initialize
324    * their application.
325    * @SINCE_1_0.0
326    * @return The signal to connect to
327    */
328   AppSignalType& InitSignal();
329
330   /**
331    * @brief The user should connect to this signal to determine when they should terminate
332    * their application.
333    * @SINCE_1_0.0
334    * @return The signal to connect to
335    */
336   AppSignalType& TerminateSignal();
337
338   /**
339    * @brief The user should connect to this signal if they need to perform any special
340    * activities when the application is about to be paused.
341    * @SINCE_1_0.0
342    * @return The signal to connect to
343    */
344   AppSignalType& PauseSignal();
345
346   /**
347    * @brief The user should connect to this signal if they need to perform any special
348    * activities when the application has resumed.
349    * @SINCE_1_0.0
350    * @return The signal to connect to
351    */
352   AppSignalType& ResumeSignal();
353
354   /**
355    * @brief This signal is sent when the system requires the user to reinitialize itself.
356    * @SINCE_1_0.0
357    * @return The signal to connect to
358    */
359   AppSignalType& ResetSignal();
360
361   /**
362   * @brief This signal is emitted when another application sends a launch request to the application.
363   *
364   * When the application is launched, this signal is emitted after the main loop of the application starts up.
365   * The passed parameter describes the launch request and contains the information about why the application is launched.
366   * @SINCE_1_0.0
367   * @return The signal to connect to
368   */
369   AppControlSignalType& AppControlSignal();
370
371   /**
372    * @brief This signal is emitted when the language is changed on the device.
373    * @SINCE_1_0.0
374    * @return The signal to connect to
375    */
376   AppSignalType& LanguageChangedSignal();
377
378   /**
379   * @brief This signal is emitted when the region of the device is changed.
380   * @SINCE_1_0.0
381   * @return The signal to connect to
382   */
383   AppSignalType& RegionChangedSignal();
384
385   /**
386    * @brief This signal is emitted when the battery level of the device is low.
387    * @SINCE_1_2.62
388    * @return The signal to connect to
389    */
390   LowBatterySignalType& LowBatterySignal();
391
392   /**
393    * @brief This signal is emitted when the memory level of the device is low.
394    * @SINCE_1_2.62
395    * @return The signal to connect to
396    */
397   LowMemorySignalType& LowMemorySignal();
398
399 public: // Not intended for application developers
400   /// @cond internal
401   /**
402    * @brief Internal constructor.
403    * @SINCE_1_0.0
404    */
405   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
406   /// @endcond
407 };
408
409 /**
410  * @}
411  */
412 } // namespace Dali
413
414 #endif // DALI_APPLICATION_H