Merge "[Tizen] Add Finalize api for imf-manager" into tizen_4.0
[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.
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  *     --no-vsync       Disable VSync on Render
98  *  -w|--width          Stage Width
99  *  -h|--height         Stage Height
100  *  -d|--dpi            Emulated DPI
101  *     --help           Help
102  * @endcode
103  *
104  * When the above options are found, they are stripped from argv, and argc is updated appropriately.
105  * @SINCE_1_0.0
106  */
107 class DALI_IMPORT_API Application : public BaseHandle
108 {
109 public:
110
111
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 Constructs an empty handle.
179    * @SINCE_1_0.0
180    */
181   Application();
182
183   /**
184    * @brief Copy Constructor.
185    * @SINCE_1_0.0
186    * @param[in] application Handle to an object
187    */
188   Application( const Application& application );
189
190   /**
191    * @brief Assignment operator.
192    * @SINCE_1_0.0
193    * @param[in] application Handle to an object
194    * @return A reference to this
195    */
196   Application& operator=( const Application& application );
197
198   /**
199    * @brief Destructor.
200    *
201    * This is non-virtual since derived Handle types must not contain data or virtual methods.
202    * @SINCE_1_0.0
203    */
204   ~Application();
205
206 public:
207   /**
208    * @brief This starts the application.
209    *
210    * Choosing this form of main loop indicates that the default
211    * application configuration of APPLICATION_HANDLES_CONTEXT_LOSS is used. On platforms where
212    * context loss can occur, the application is responsible for tearing down and re-loading UI.
213    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
214    * @SINCE_1_0.0
215    */
216   void MainLoop();
217
218   /**
219    * @brief This starts the application, and allows the app to choose a different configuration.
220    *
221    * If the application plans on using the ReplaceSurface or ReplaceWindow API, then this will
222    * trigger context loss & regain.
223    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
224    * @SINCE_1_0.0
225    * @param[in] configuration The context loss configuration
226    */
227   void MainLoop(Configuration::ContextLoss configuration);
228
229   /**
230    * @brief This lowers the application to bottom without actually quitting it.
231    * @SINCE_1_0.0
232    */
233   void Lower();
234
235   /**
236    * @brief This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
237    * @SINCE_1_0.0
238    */
239   void Quit();
240
241   /**
242    * @brief Ensures that the function passed in is called from the main loop when it is idle.
243    * @SINCE_1_0.0
244    * @param[in] callback The function to call
245    * @return @c true if added successfully, @c false otherwise
246    *
247    * @note Function must be called from main event thread only
248    *
249    * A callback of the following type may be used:
250    * @code
251    *   void MyFunction();
252    * @endcode
253    *
254    * @note Ownership of the callback is passed onto this class.
255    */
256   bool AddIdle( CallbackBase* callback );
257
258   /**
259    * @brief Retrieves the window used by the Application class.
260    *
261    * The application writer can use the window to change indicator and orientation
262    * properties.
263    * @SINCE_1_0.0
264    * @return A handle to the window
265    */
266   Window GetWindow();
267
268   /**
269    * @brief Replaces the current window.
270    *
271    * This will force context loss.
272    * If you plan on using this API in your application, then you should configure
273    * it to prevent discard behavior when handling the Init signal.
274    * @SINCE_1_0.0
275    * @param[in] windowPosition The position and size parameters of the new window
276    * @param[in] name The name of the new window
277    */
278   void ReplaceWindow(PositionSize windowPosition, const std::string& name);
279
280   /**
281    * @brief Get path application resources are stored at
282    *
283    * @SINCE_1_2.2
284    * @return the full path of the resources
285    */
286   static std::string GetResourcePath();
287
288 public: // Stereoscopy
289
290   /**
291    * @brief Sets the viewing mode for the application.
292    * @SINCE_1_0.0
293    * @param[in] viewMode The new viewing mode
294    */
295   void SetViewMode( ViewMode viewMode );
296
297   /**
298    * @brief Gets the current viewing mode.
299    * @SINCE_1_0.0
300    * @return The current viewing mode
301    */
302   ViewMode GetViewMode() const;
303
304   /**
305    * @brief Sets the stereo base (eye separation) for Stereoscopic 3D.
306    *
307    * The stereo base is the distance in millimetres between the eyes. Typical values are
308    * between 50mm and 70mm. The default value is 65mm.
309    * @SINCE_1_0.0
310    * @param[in] stereoBase The stereo base (eye separation) for Stereoscopic 3D
311    */
312   void SetStereoBase( float stereoBase );
313
314   /**
315    * @brief Gets the stereo base (eye separation) for Stereoscopic 3D.
316    *
317    * @SINCE_1_0.0
318    * @return The stereo base (eye separation) for Stereoscopic 3D
319    */
320   float GetStereoBase() const;
321
322 public:  // Signals
323
324   /**
325    * @brief The user should connect to this signal to determine when they should initialize
326    * their application.
327    * @SINCE_1_0.0
328    * @return The signal to connect to
329    */
330   AppSignalType& InitSignal();
331
332   /**
333    * @brief The user should connect to this signal to determine when they should terminate
334    * their application.
335    * @SINCE_1_0.0
336    * @return The signal to connect to
337    */
338   AppSignalType& TerminateSignal();
339
340   /**
341    * @brief The user should connect to this signal if they need to perform any special
342    * activities when the application is about to be paused.
343    * @SINCE_1_0.0
344    * @return The signal to connect to
345    */
346   AppSignalType& PauseSignal();
347
348   /**
349    * @brief The user should connect to this signal if they need to perform any special
350    * activities when the application has resumed.
351    * @SINCE_1_0.0
352    * @return The signal to connect to
353    */
354   AppSignalType& ResumeSignal();
355
356   /**
357    * @brief This signal is sent when the system requires the user to reinitialize itself.
358    * @SINCE_1_0.0
359    * @return The signal to connect to
360    */
361   AppSignalType& ResetSignal();
362
363   /**
364    * @DEPRECATED_1_1.43 Use Window::ResizedSignal() instead.
365    * @brief This signal is emitted when the window application rendering on is resized.
366    * @SINCE_1_0.0
367    * @return The signal to connect to
368    */
369   AppSignalType& ResizeSignal();
370
371   /**
372   * @brief This signal is emitted when another application sends a launch request to the application.
373   *
374   * When the application is launched, this signal is emitted after the main loop of the application starts up.
375   * The passed parameter describes the launch request and contains the information about why the application is launched.
376   * @SINCE_1_0.0
377   * @return The signal to connect to
378   */
379   AppControlSignalType& AppControlSignal();
380
381   /**
382    * @brief This signal is emitted when the language is changed on the device.
383    * @SINCE_1_0.0
384    * @return The signal to connect to
385    */
386   AppSignalType& LanguageChangedSignal();
387
388   /**
389   * @brief This signal is emitted when the region of the device is changed.
390   * @SINCE_1_0.0
391   * @return The signal to connect to
392   */
393   AppSignalType& RegionChangedSignal();
394
395   /**
396   * @DEPRECATED_1_2.58 Use LowBatterySignal() instead.
397   * @brief This signal is emitted when the battery level of the device is low.
398   * @SINCE_1_0.0
399   * @return The signal to connect to
400   */
401   AppSignalType& BatteryLowSignal() DALI_DEPRECATED_API;
402
403   /**
404   * @DEPRECATED_1_2.58 Use LowMemorySignal() instead.
405   * @brief This signal is emitted when the memory level of the device is low.
406   * @SINCE_1_0.0
407   * @return The signal to connect to
408   */
409   AppSignalType& MemoryLowSignal() DALI_DEPRECATED_API;
410
411 public: // Not intended for application developers
412   /// @cond internal
413   /**
414    * @brief Internal constructor.
415    * @SINCE_1_0.0
416    */
417   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
418   /// @endcond
419 };
420
421 /**
422  * @}
423  */
424 } // namespace Dali
425
426 #endif // __DALI_APPLICATION_H__