c43f929123945985f00ddf634aed4fe6fd017f6a
[platform/core/uifw/widget-viewer-dali.git] / internal / widget_view / widget_view_impl.h
1 #ifndef __DALI_WIDGET_VIEW_INTERNAL_WIDGET_VIEW_H__
2 #define __DALI_WIDGET_VIEW_INTERNAL_WIDGET_VIEW_H__
3
4 /*
5  * Samsung API
6  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
7  *
8  * Licensed under the Flora License, Version 1.1 (the License);
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://floralicense.org/license/
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an AS IS BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 // INTERNAL INCLUDES
22 #include <public_api/widget_view/widget_view.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/public-api/adaptor-framework/native-image-source.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
28 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
29 #include <wayland-extension/tizen-remote-surface-client-protocol.h>
30 #include <tbm_surface.h>
31 #include <screen_connector_toolkit.h>
32
33 namespace Dali
34 {
35
36 namespace WidgetView
37 {
38
39 namespace Internal
40 {
41
42 class WidgetView : public Toolkit::Internal::Control
43 {
44 public:
45
46   /**
47    * @copydoc Dali::WidgetView::WidgetView::New
48    */
49   static Dali::WidgetView::WidgetView New( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod );
50
51   /**
52    * @copydoc Dali::WidgetView::WidgetView::PauseWidget
53    */
54   bool PauseWidget();
55
56   /**
57    * @copydoc Dali::WidgetView::WidgetView::ResumeWidget
58    */
59   bool ResumeWidget();
60
61   /**
62    * @copydoc Dali::WidgetView::WidgetView::CancelTouchEvent
63    */
64   bool CancelTouchEvent();
65
66   /**
67    * @copydoc Dali::WidgetView::WidgetView::ActivateFaultedWidget
68    */
69   void ActivateFaultedWidget();
70
71   void SendWidgetEvent( int event );
72
73 public: // Internal API
74
75   /**
76    * @brief Called when a property of an object of this type is set.
77    * @SINCE_1_1.38
78    * @param[in] object The object whose property is set.
79    * @param[in] index The property index.
80    * @param[in] value The new property value.
81    */
82   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
83
84   /**
85    * @brief Called to retrieve a property of an object of this type.
86    * @SINCE_1_1.38
87    * @param[in] object The object whose property is to be retrieved.
88    * @param[in] index The property index.
89    * @return The current value of the property.
90    */
91   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
92
93   /**
94    * @brief Performs actions as requested using the action name.
95    * @SINCE_1_1.38
96    * @param[in] object The object on which to perform the action.
97    * @param[in] actionName The action to perform.
98    * @param[in] attributes The attributes with which to perfrom this action.
99    * @return True if action has been accepted by this control
100    */
101   static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes );
102
103   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
104
105   const std::string& GetWidgetId() const;
106
107   const std::string& GetInstanceId() const;
108
109   const std::string& GetContentInfo();
110
111   const std::string& GetTitle();
112
113   float GetUpdatePeriod() const;
114
115   void SetPreviewVisible( bool visible );
116
117   bool IsPreviewVisible();
118
119   void SetLoadingTextVisible( bool visible );
120
121   bool IsLoadingTextVisible();
122
123   bool IsWidgetFaulted();
124
125   void SetPermanentDelete( bool permanentDelete );
126
127   void RemoveWidgetImage();
128
129   bool IsPermanentDelete();
130
131   bool IsWidgetImageView();
132
133   void UpdateImageSource( tbm_surface_h source );
134
135   void CreateWidgetImageView();
136
137   void ConnectSignal( tizen_remote_surface* surface );
138
139   bool OnTouch( Dali::Actor actor, const Dali::TouchData& event );
140
141   bool OnWheelEvent( Dali::Actor actor, const Dali::WheelEvent& event );
142
143   void CloseRemoteSurface();
144
145   void SetLoadingTextPropertyMap( Dali::Property::Map map );
146
147   void ShowLoadingState( bool show );
148
149   void ShowTapWidgetState( bool show );
150
151   void TerminateWidget();
152
153 public: //Signals
154
155   /**
156    * @copydoc Dali::WidgetView::WidgetView::WidgetAddedSignal
157    */
158   Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetAddedSignal();
159
160   /**
161    * @copydoc Dali::WidgetView::WidgetView::WidgetDeletedSignal
162    */
163   Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetDeletedSignal();
164
165   /**
166    * @copydoc Dali::WidgetView::WidgetView::WidgetCreationAbortedSignal
167    */
168   Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetCreationAbortedSignal();
169
170   /**
171    * @copydoc Dali::WidgetView::WidgetView::WidgetContentUpdatedSignal
172    */
173   Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetContentUpdatedSignal();
174
175   /**
176    * @copydoc Dali::WidgetView::WidgetView::WidgetUpdatePeriodChangedSignal
177    */
178   Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetUpdatePeriodChangedSignal();
179
180   /**
181    * @copydoc Dali::WidgetView::WidgetView::WidgetFaultedSignal
182    */
183   Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetFaultedSignal();
184
185   Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetTerminatedSignal();
186
187 protected:
188
189   /**
190    * Construct a new WidgetView.
191    */
192   WidgetView();
193
194   /**
195    * Construct a new WidgetView.
196    */
197   WidgetView( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod );
198
199   /**
200    * A reference counted object may only be deleted by calling Unreference()
201    */
202   virtual ~WidgetView();
203
204   float TextPixelToPointSize( int pixelSize );
205
206 private: // From Control
207
208   /**
209    * @copydoc Toolkit::Control::OnInitialize()
210    */
211   virtual void OnInitialize();
212
213   /**
214    * @copydoc Toolkit::Control::OnStageConnect()
215    */
216   virtual void OnStageConnection( int depth );
217
218   /**
219    * @copydoc Toolkit::Control::OnStageDisconnection()
220    */
221   virtual void OnStageDisconnection();
222
223   /**
224    * @copydoc Toolkit::Control::OnSizeSet()
225    */
226   virtual void OnSizeSet( const Vector3& targetSize );
227
228   /**
229    * @copydoc Toolkit::Control::GetNaturalSize
230    */
231   virtual Vector3 GetNaturalSize();
232
233   /**
234    * @copydoc Toolkit::Control::GetHeightForWidth()
235    */
236   virtual float GetHeightForWidth( float width );
237
238   /**
239    * @copydoc Toolkit::Control::GetWidthForHeight()
240    */
241   virtual float GetWidthForHeight( float height );
242
243 private:
244
245   // Undefined
246   WidgetView( const WidgetView& );
247
248   // Undefined
249   WidgetView& operator= ( const WidgetView& );
250
251 private:
252
253   Toolkit::ImageView mWidgetImageView;     ///< Widget content
254   Toolkit::ImageView mPreviewImage;   ///< Preview image
255   Toolkit::TextLabel mStateText;      ///< State text
256   Dali::Actor mPreviewActor;
257   Dali::Actor mStateTextActor;
258   Dali::NativeImageSourcePtr mImageSource;
259
260   std::string mWidgetId;
261   std::string mInstanceId;
262   std::string mContentInfo;
263   std::string mTitle;
264
265   int mWidth;
266   int mHeight;
267   int mPid;
268   float mUpdatePeriod;
269
270   bool mPreviewVisible;
271   bool mLoadingTextVisible;
272   bool mTapTextVisible;
273   bool mPermanentDelete;
274   screen_connector_toolkit_h mWatcherHandle;
275   tizen_remote_surface* mRemoteSurface;
276
277   // Signals
278   Dali::WidgetView::WidgetView::WidgetViewSignalType mWidgetAddedSignal;
279   Dali::WidgetView::WidgetView::WidgetViewSignalType mWidgetDeletedSignal;
280   Dali::WidgetView::WidgetView::WidgetViewSignalType mWidgetCreationAbortedSignal;
281   Dali::WidgetView::WidgetView::WidgetViewSignalType mWidgetContentUpdatedSignal;
282   Dali::WidgetView::WidgetView::WidgetViewSignalType mWidgetUpdatePeriodChangedSignal;
283   Dali::WidgetView::WidgetView::WidgetViewSignalType mWidgetFaultedSignal;
284
285   // Internal signal
286   Dali::WidgetView::WidgetView::WidgetViewSignalType mWidgetTerminatedSignal;
287 };
288
289 } // namespace Internal
290
291 // Helpers for public-api forwarding methods
292
293 inline Internal::WidgetView& GetImplementation( WidgetView& widgetView )
294 {
295   DALI_ASSERT_ALWAYS( widgetView );
296
297   Dali::RefObject& handle = widgetView.GetImplementation();
298
299   return static_cast<Internal::WidgetView&>( handle );
300 }
301
302 inline const Internal::WidgetView& GetImplementation( const WidgetView& widgetView )
303 {
304   DALI_ASSERT_ALWAYS( widgetView );
305
306   const Dali::RefObject& handle = widgetView.GetImplementation();
307
308   return static_cast<const Internal::WidgetView&>( handle );
309 }
310
311 } // namespace WidgetView
312
313 } // namespace Dali
314
315 #endif // __DALI_WIDGET_VIEW_INTERNAL_WIDGET_VIEW_H__