Merge branch 'devel/master' into sandbox/dkdk/tizen
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / widget-impl.h
1 #ifndef DALI_INTERNAL_WIDGET_H
2 #define DALI_INTERNAL_WIDGET_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-object.h>
23 #include <dali/public-api/signals/connection-tracker-interface.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/adaptor-framework/widget.h>
27 #include <dali/public-api/adaptor-framework/window.h>
28
29 namespace Dali
30 {
31 /**
32  * @addtogroup dali_adaptor_framework
33  * @{
34  */
35
36 namespace Internal
37 {
38 namespace Adaptor
39 {
40 class Widget;
41 typedef IntrusivePtr<Widget> WidgetPtr;
42
43 /**
44  * @brief This is the internal base class of custom widget.
45  *
46  * It will provides several widget instance lifecycle virtual functions
47  * which the user can override.
48  *
49  * User should override OnCreate function and create scene for custom widget.
50  *
51  * Plus, Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
52  * be disconnected automatically when the control is destroyed.
53  *
54  * @SINCE_1_3_5
55  */
56 class DALI_ADAPTOR_API Widget : public BaseObject, public ConnectionTrackerInterface
57 {
58 public:
59   /**
60    * @brief Creates a new WidgetImpl instance.
61    *
62    * @SINCE_1_3_5
63    * @return A handle to the WidgetImpl instance
64    */
65   static WidgetPtr New();
66
67   /**
68    * @brief The user should override this function to determine when they create widget.
69    *
70    * @SINCE_1_3_5
71    * @param[in] contentInfo Information from WidgetView for creating. It contains previous status of widget which is sent by SetContentInfo before.
72    * @param[in] window Window handle for widget
73    */
74   virtual void OnCreate(const std::string& contentInfo, Dali::Window window);
75
76   /**
77    * @brief The user should override this function to determine when they terminate widget.
78    *
79    * @SINCE_1_3_5
80    * @param[in] contentInfo Data from WidgetView for deleting
81    * @param[in] type Termination type. When user delete widget view, termination type is PERMANENT.
82    */
83   virtual void OnTerminate(const std::string& contentInfo, Dali::Widget::Termination type);
84
85   /**
86    * @brief The user should override this function to determine when they pause widget.
87    * @SINCE_1_3_5
88    */
89   virtual void OnPause();
90
91   /**
92    * @brief The user should override this function to determine when they resume widget.
93    * @SINCE_1_3_5
94    */
95   virtual void OnResume();
96
97   /**
98    * @brief The user should override this function to determine when they resize widget.
99    *
100    * @SINCE_1_3_5
101    * @param[in] window Window handle for widget
102    */
103   virtual void OnResize(Dali::Window window);
104
105   /**
106    * @brief The user should override this function to determine when they update widget.
107    *
108    * @SINCE_1_3_5
109    * @param[in] contentInfo Data from WidgetView for updating
110    * @param[in] force Although the widget is paused, if it is true, the widget can be updated
111    */
112   virtual void OnUpdate(const std::string& contentInfo, int force);
113
114   // From ConnectionTrackerInterface
115
116   /**
117    * @copydoc ConnectionTrackerInterface::SignalConnected
118    */
119   void SignalConnected(SlotObserver* slotObserver, CallbackBase* callback) override;
120
121   /**
122    * @copydoc ConnectionTrackerInterface::SignalDisconnected
123    */
124   void SignalDisconnected(SlotObserver* slotObserver, CallbackBase* callback) override;
125
126   /**
127    * @brief Set content info to WidgetView.
128    *
129    * @SINCE_1_3_5
130    * @param[in] contentInfo Content info is kind of context information which contains current status of widget.
131    */
132   void SetContentInfo(const std::string& contentInfo);
133
134 protected:
135   /**
136    * @brief WidgetImpl constructor
137    */
138   Widget();
139
140   /**
141    * @brief Virtual destructor
142    */
143   ~Widget() override;
144
145   /// @cond internal
146 public:
147   class Impl; // Class declaration is public so we can internally add devel API's to the WidgetImpl
148
149   /**
150    * Set pointer of WidgetImpl Internal.
151    * @SINCE_1_3_5
152    */
153   void SetImpl(Impl* impl);
154
155 private:
156   Impl* mImpl;
157
158   // Undefined
159   DALI_INTERNAL Widget(const Widget&);
160   DALI_INTERNAL Widget& operator=(Widget&);
161   /// @endcond
162 };
163
164 /**
165  * @brief Gets implementation from the handle.
166  *
167  * @SINCE_1_3_5
168  * @param handle
169  * @return Implementation
170  * @pre handle is initialized and points to a widget
171  */
172 DALI_ADAPTOR_API Internal::Adaptor::Widget& GetImplementation(Dali::Widget& widget);
173
174 /**
175  * @brief Gets implementation from the handle.
176  *
177  * @SINCE_1_3_5
178  * @param handle
179  * @return Implementation
180  * @pre Handle is initialized and points to a widget.
181  */
182 DALI_ADAPTOR_API const Internal::Adaptor::Widget& GetImplementation(const Dali::Widget& widget);
183
184 } // namespace Adaptor
185
186 } // namespace Internal
187
188 /**
189  * @}
190  */
191
192 } // namespace Dali
193 #endif // DALI_INTERNAL_WIDGET_H