Merge branch 'devel/master' into sandbox/dkdk/tizen
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / widget-application.h
1 #ifndef DALI_WIDGET_APPLICATION_H
2 #define DALI_WIDGET_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 // INTERNAL INCLUDES
22 #include <dali/public-api/adaptor-framework/application.h>
23
24 namespace Dali
25 {
26 /**
27  * @addtogroup dali_adaptor_framework
28  * @{
29  */
30
31 namespace Internal DALI_INTERNAL
32 {
33 namespace Adaptor
34 {
35 class WidgetApplication;
36 }
37
38 } // namespace DALI_INTERNAL
39
40 class Widget;
41
42 /**
43  * @brief An WidgetApplication class object should be created by every widget application
44  * that wishes to use Dali.
45  *
46  * It provides a means for initializing the
47  * resources required by the Dali::Core.
48  *
49  * The WidgetApplication class emits several signals which the user can
50  * connect to.  The user should not create any Dali objects in the main
51  * function and instead should connect to the Init signal of the
52  * WidgetApplication and create the Dali Widget object in the connected callback.
53  *
54  * WidgetApplications should follow the example below:
55  *
56  * @code
57  *
58  * //Widget header which
59  * #include <my-widget.h>
60  *
61  * class ExampleController: public ConnectionTracker
62  * {
63  * public:
64  *   ExampleController( Application& application )
65  *   : mWidgetApplication( application )
66  *   {
67  *     mApplication.InitSignal().Connect( this, &ExampleController::Create );
68  *   }
69  *
70  *   static Widget CreateWidgetFunction(const std::string& widgetName)
71  *   {
72  *     MyWidget widget = MyWidget::New();
73  *     return widget;
74  *   }
75  *
76  *   void Create( Application& application )
77  *   {
78  *     mApplication.RegisterWidgetCreatingFunction( "myWidget", &ExampleController::CreateWidgetFunction );
79  *   }
80  *
81  * private:
82  *   WidgetApplication& mWidgetApplication;
83  * };
84  *
85  * int main (int argc, char **argv)
86  * {
87  *   WidgetApplication app = WidgetApplication::New(&argc, &argv);
88  *   ExampleController example( app );
89  *   app.MainLoop();
90  * }
91  * @endcode
92  *
93  * If required, you can also connect class member functions to a signal:
94  *
95  * @code
96  * MyWidgetApplication app;
97  * app.ResumeSignal().Connect(&app, &MyWidgetApplication::Resume);
98  * @endcode
99  *
100  * @SINCE_1_3_5
101  */
102 class DALI_ADAPTOR_API WidgetApplication : public Application
103 {
104 public:
105   /**
106    * @brief This is the typedef for Widget creator.
107    * @SINCE_1_3_5
108    */
109   typedef Widget (*CreateWidgetFunction)(const std::string&);
110
111 public:
112   /**
113    * @brief This is the constructor for WidgetApplications with a name.
114    *
115    * @SINCE_1_3_5
116    * @param[in,out]  argc        A pointer to the number of arguments
117    * @param[in,out]  argv        A pointer to the argument list
118    * @param[in]      stylesheet  The path to user defined theme file
119    * @return A handle to the WidgetApplication
120    * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
121    */
122   static WidgetApplication New(int* argc, char** argv[], const std::string& stylesheet);
123
124   /**
125    * @brief The default constructor.
126    * @SINCE_1_3_5
127    */
128   WidgetApplication();
129
130   /**
131    * @brief Copy Constructor.
132    *
133    * @SINCE_1_3_5
134    * @param[in] widgetApplication Handle to an object
135    */
136   WidgetApplication(const WidgetApplication& widgetApplication);
137
138   /**
139    * @brief Assignment operator.
140    *
141    * @SINCE_1_3_5
142    * @param[in] widgetApplication Handle to an object
143    * @return A reference to this
144    */
145   WidgetApplication& operator=(const WidgetApplication& widgetApplication);
146
147   /**
148    * @brief Move constructor.
149    *
150    * @SINCE_1_9.24
151    * @param[in] rhs A reference to the moved handle
152    */
153   WidgetApplication(WidgetApplication&& rhs);
154
155   /**
156    * @brief Move assignment operator.
157    *
158    * @SINCE_1_9.24
159    * @param[in] rhs A reference to the moved handle
160    * @return A reference to this handle
161    */
162   WidgetApplication& operator=(WidgetApplication&& rhs);
163
164   /**
165    * @brief Destructor
166    * @SINCE_1_3_5
167    */
168   ~WidgetApplication();
169
170   /**
171    * @brief Register create function for widget.
172    *
173    * @SINCE_1_3_5
174    * @param[in] widgetName  Name of widget
175    * @param[in] createFunction     Function pointer for widget creation.
176    */
177   void RegisterWidgetCreatingFunction(const std::string& widgetName, CreateWidgetFunction createFunction);
178
179 public: // Not intended for application developers
180   /// @cond internal
181   /**
182    * @brief Internal constructor.
183    */
184   explicit DALI_INTERNAL WidgetApplication(Internal::Adaptor::WidgetApplication* widgetApplication);
185   /// @endcond
186 };
187
188 /**
189  * @}
190  */
191 } // namespace Dali
192
193 #endif // DALI_WIDGET_APPLICATION_H