Added po files and codes for language change
[platform/core/uifw/widget-viewer-dali.git] / internal / widget_view / widget_view_impl.cpp
1 /*
2  * Samsung API
3  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.1 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 // CLASS HEADER
19 #include <internal/widget_view/widget_view_impl.h>
20
21 // INTERNAL INCLUDES
22
23 // EXTERNAL INCLUDES
24 #include <dali/public-api/common/stage.h>
25 #include <dali/public-api/events/touch-data.h>
26 #include <dali/public-api/events/wheel-event.h>
27 #include <dali/public-api/images/native-image.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/public-api/object/type-registry-helper.h>
30 #include <dali-toolkit/public-api/visuals/visual-properties.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
32 #include <dali/integration-api/debug.h>
33 #include <string.h>
34 #include <Ecore_Input.h>
35 #include <widget_service.h>
36 #include <widget_instance.h>
37 #include <tzplatform_config.h>
38 #include <wayland-extension/tizen-extension-client-protocol.h>
39 #include <unistd.h>
40 #include <libintl.h>
41
42 namespace Dali
43 {
44
45 namespace WidgetView
46 {
47
48 namespace Internal
49 {
50
51 namespace
52 {
53
54 #define GET_LOCALE_TEXT(string) dgettext(PKGNAME, string)
55
56 #if defined(DEBUG_ENABLED)
57 Integration::Log::Filter* gWidgetViewLogging  = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_WIDGET_VIEW" );
58 #endif
59
60 BaseHandle Create()
61 {
62   return Dali::BaseHandle();
63 }
64
65 // Setup properties, signals and actions using the type-registry.
66 DALI_TYPE_REGISTRATION_BEGIN( Dali::WidgetView::WidgetView, Toolkit::Control, Create );
67 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "widgetId", BOOLEAN, WIDGET_ID )
68 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "instanceId", BOOLEAN, INSTANCE_ID )
69 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "contentInfo", BOOLEAN, CONTENT_INFO )
70 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "title", BOOLEAN, TITLE )
71 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "updatePeriod", BOOLEAN, UPDATE_PERIOD )
72 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "preview", MAP, PREVIEW )
73 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "loadingText", MAP, LOADING_TEXT )
74 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "widgetStateFaulted", BOOLEAN, WIDGET_STATE_FAULTED )
75 DALI_PROPERTY_REGISTRATION( Dali::WidgetView, WidgetView, "permanentDelete", BOOLEAN, PERMANENT_DELETE )
76
77 // Signals
78 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetAdded", SIGNAL_WIDGET_ADDED )
79 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetDeleted", SIGNAL_WIDGET_DELETED )
80 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetCreationAborted", SIGNAL_WIDGET_CREATION_ABORTED )
81 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetContentUpdated", SIGNAL_WIDGET_CONTENT_UPDATED )
82 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetUpdatePeriodChanged", SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED )
83 DALI_SIGNAL_REGISTRATION( Dali::WidgetView, WidgetView, "widgetFaulted", SIGNAL_WIDGET_FAULTED )
84
85 // Actions
86 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "pauseWidget", ACTION_WIDGETVIEW_PAUSE_WIDGET );
87 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "resumeWidget", ACTION_WIDGETVIEW_RESUME_WIDGET );
88 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "cancelTouchEvent", ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT );
89 DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "activateFaultedWidget", ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET );
90
91 DALI_TYPE_REGISTRATION_END()
92
93 struct wl_buffer* preBuffer;
94
95 const char* const FONT_STYLE( "fontStyle" );
96 const char* const TEXT_POINT_SIZE( "textPointSize" );
97 const char* const TEXT_COLOR( "textColor" );
98
99 static void OnBufferUpdated( struct tizen_remote_surface *surface, uint32_t type, struct wl_buffer *buffer,
100                               int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys,
101                               const char *appid, const char *instance_id, const int pid, void *data)
102 {
103   Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
104
105   if( widgetView )
106   {
107     if( !widgetView->IsWidgetImageView() )
108     {
109       tizen_remote_surface_transfer_visibility( surface, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_VISIBLE);
110
111       widgetView->CreateWidgetImageView();
112       widgetView->ConnectSignal( surface );
113     }
114
115     //get tbm surface from buffer
116     tbm_surface_h tbmSurface = static_cast< tbm_surface_h >( wl_buffer_get_user_data( buffer ) );
117     widgetView->UpdateImageSource( tbmSurface );
118   }
119
120   if( preBuffer != NULL && tizen_remote_surface_get_version( surface ) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION )
121   {
122     tizen_remote_surface_release( surface, preBuffer );
123   }
124
125   preBuffer = buffer;
126
127   close( img_file_fd );
128 }
129
130 static void OnBufferAdded( const char *appid, const char *instance_id, const int pid, void *data )
131 {
132 }
133
134 static void OnSurfaceRemoved( const char *appid, const char *instance_id, const int pid, void *data )
135 {
136   Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
137
138   if( widgetView )
139   {
140     widgetView->CloseRemoteSurface();
141     widgetView->RemoveWidgetImage();
142   }
143 }
144
145 } // unnamed namespace
146
147 Dali::WidgetView::WidgetView WidgetView::New( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
148 {
149   // Create the implementation, temporarily owned on stack
150   IntrusivePtr< WidgetView > internalWidgetView = new WidgetView( widgetId, contentInfo, width, height, updatePeriod );
151
152   // Pass ownership to CustomActor
153   Dali::WidgetView::WidgetView widgetView( *internalWidgetView );
154
155   // Second-phase init of the implementation
156   // This can only be done after the CustomActor connection has been made...
157   internalWidgetView->Initialize();
158
159   return widgetView;
160 }
161
162 WidgetView::WidgetView()
163 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
164   mWidgetId(),
165   mInstanceId(),
166   mContentInfo(),
167   mTitle(),
168   mWidth( 0 ),
169   mHeight( 0 ),
170   mPid( 0 ),
171   mUpdatePeriod( 0.0 ),
172   mPreviewVisible( true ),
173   mLoadingTextVisible( true ),
174   mTapTextVisible( true ),
175   mPermanentDelete( false ),
176   mWatcherHandle( NULL ),
177   mRemoteSurface( NULL )
178 {
179 }
180
181 WidgetView::WidgetView( const std::string& widgetId, const std::string& contentInfo, int width, int height, float updatePeriod )
182 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
183   mWidgetId( widgetId ),
184   mInstanceId(),
185   mContentInfo( contentInfo ),
186   mTitle(),
187   mWidth( width ),
188   mHeight( height ),
189   mPid( 0 ),
190   mUpdatePeriod( updatePeriod ),
191   mPreviewVisible( true ),
192   mLoadingTextVisible( true ),
193   mTapTextVisible( true ),
194   mPermanentDelete( false ),
195   mWatcherHandle( NULL ),
196   mRemoteSurface( NULL )
197 {
198 }
199
200 WidgetView::~WidgetView()
201 {
202   if( !mWidgetId.empty() && !mInstanceId.empty() )
203   {
204     widget_instance_terminate( mInstanceId.c_str() );
205
206     if( mPermanentDelete )
207     {
208       widget_instance_destroy( mInstanceId.c_str() );
209     }
210   }
211 }
212
213 bool WidgetView::PauseWidget()
214 {
215   int ret = widget_instance_pause( mInstanceId.c_str() );
216   if( ret < 0 )
217   {
218     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Fail to pause widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
219     return false;
220   }
221
222   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::PauseWidget: Widget is paused (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
223
224   return true;
225 }
226
227 bool WidgetView::ResumeWidget()
228 {
229   int ret = widget_instance_resume( mInstanceId.c_str() );
230   if( ret < 0 )
231   {
232     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Fail to resume widget(%s, %s) [%d]\n", mWidgetId.c_str(), mInstanceId.c_str(), ret );
233     return false;
234   }
235
236   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ResumeWidget: Widget is resumed (%s, %s)\n", mWidgetId.c_str(), mInstanceId.c_str() );
237
238   return true;
239 }
240
241 const std::string& WidgetView::GetWidgetId() const
242 {
243   return mWidgetId;
244 }
245
246 const std::string& WidgetView::GetInstanceId() const
247 {
248   return mInstanceId;
249 }
250
251 const std::string& WidgetView::GetContentInfo()
252 {
253   widget_instance_h instance;
254   char* contentInfo = NULL;
255
256   mContentInfo.clear();
257
258   if( mWidgetId.empty() || mInstanceId.empty() )
259   {
260     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Widget id (%s) or instance id (%s) is invalid.\n", mWidgetId.c_str(), mInstanceId.c_str() );
261     return mContentInfo;
262   }
263
264   instance = widget_instance_get_instance( mWidgetId.c_str(), mInstanceId.c_str() );
265   if( !instance )
266   {
267     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: widget_instance_get_instance is failed. [%s]\n", mInstanceId.c_str() );
268     return mContentInfo;
269   }
270
271   if( widget_instance_get_content( instance, &contentInfo ) < 0 )
272   {
273     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetContentInfo: Failed to get content of widget. [%s]\n", mInstanceId.c_str() );
274     return mContentInfo;
275   }
276
277   mContentInfo = reinterpret_cast< char* >( contentInfo );
278
279   return mContentInfo;
280 }
281
282 const std::string& WidgetView::GetTitle()
283 {
284   //ToDo: We should add some codes by considering widget_viewer_evas
285   if( mTitle.empty() )
286   {
287     mTitle = widget_service_get_name( mWidgetId.c_str(), NULL );
288   }
289
290   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::GetTitle: title = %s\n", mTitle.c_str() );
291
292   return mTitle;
293 }
294
295 float WidgetView::GetUpdatePeriod() const
296 {
297   return mUpdatePeriod;
298 }
299
300 bool WidgetView::CancelTouchEvent()
301 {
302   if( mRemoteSurface )
303   {
304     tizen_remote_surface_transfer_touch_cancel( mRemoteSurface );
305     return true;
306   }
307
308   return false;
309 }
310
311 void WidgetView::SetPreviewVisible( bool visible )
312 {
313   if( mPreviewImage && mPreviewVisible != visible )
314   {
315     mPreviewVisible = visible;
316     mPreviewImage.SetVisible( visible );
317   }
318 }
319
320 bool WidgetView::IsPreviewVisible()
321 {
322   return mPreviewVisible;
323 }
324
325 void WidgetView::SetLoadingTextVisible( bool visible )
326 {
327   if( mStateText && mLoadingTextVisible != visible )
328   {
329     mLoadingTextVisible = visible;
330
331     if( visible )
332     {
333       mStateText.SetProperty( Toolkit::TextLabel::Property::TEXT, GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) );
334     }
335     mStateText.SetVisible( visible );
336   }
337 }
338
339 bool WidgetView::IsLoadingTextVisible()
340 {
341   return mLoadingTextVisible;
342 }
343
344 void WidgetView::ActivateFaultedWidget()
345 {
346   if( mPid < 0 )
347   {
348     // Enable preview and loading text
349     ShowTapWidgetState( false );
350     ShowLoadingState( true );
351
352     // launch widget again
353     mPid = widget_instance_launch( mInstanceId.c_str(), (char *)mContentInfo.c_str(), mWidth, mHeight );
354     if( mPid < 0)
355     {
356       DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
357
358       ShowLoadingState( false );
359       ShowTapWidgetState( true );
360
361       // Emit signal
362       Dali::WidgetView::WidgetView handle( GetOwner() );
363       mWidgetCreationAbortedSignal.Emit( handle );
364
365
366       return;
367     }
368
369     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::ActivateFaultedWidget: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
370   }
371 }
372
373 bool WidgetView::IsWidgetFaulted()
374 {
375   return mPid < 0 ? true : false;
376 }
377
378 void WidgetView::SetPermanentDelete( bool permanentDelete )
379 {
380   mPermanentDelete = permanentDelete;
381 }
382
383 bool WidgetView::IsPermanentDelete()
384 {
385   return mPermanentDelete;
386 }
387
388 void WidgetView::CreateWidgetImageView()
389 {
390   Any source;
391   mImageSource = Dali::NativeImageSource::New( source );
392   Dali::NativeImage image = Dali::NativeImage::New( *mImageSource );
393
394   mWidgetImageView = Dali::Toolkit::ImageView::New( image );
395
396   mWidgetImageView.SetParentOrigin( ParentOrigin::CENTER );
397   mWidgetImageView.SetAnchorPoint( AnchorPoint::CENTER );
398   mWidgetImageView.SetSize( mWidth, mHeight );
399
400   Self().Add( mWidgetImageView );
401
402   //EFL app should be pre multiplied image.
403   mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
404
405   // Disable preview and text
406   ShowLoadingState( false );
407
408   // Emit signal
409   Dali::WidgetView::WidgetView handle( GetOwner() );
410   mWidgetAddedSignal.Emit( handle );
411
412   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::CreateWidgetImageView: Widget image is added.\n" );
413 }
414
415 void WidgetView::RemoveWidgetImage()
416 {
417   ShowTapWidgetState( true );
418
419   // Emit signal
420   Dali::WidgetView::WidgetView handle( GetOwner() );
421   mWidgetDeletedSignal.Emit( handle );
422
423   mWidgetImageView.SetVisible( false );
424   mWidgetImageView.Reset();
425
426   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::RemoveWidgetImage: Widget image is removed.\n" );
427 }
428
429 void WidgetView::SendWidgetEvent( int event )
430 {
431   Dali::WidgetView::WidgetView handle( GetOwner() );
432
433   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::SendWidgetEvent: event = %d widget = %s\n", event,  mWidgetId.c_str() );
434
435   // Emit signal
436   switch( event )
437   {
438     case WIDGET_INSTANCE_EVENT_UPDATE:
439     case WIDGET_INSTANCE_EVENT_EXTRA_UPDATED:
440     {
441       mWidgetContentUpdatedSignal.Emit( handle );
442       break;
443     }
444     case WIDGET_INSTANCE_EVENT_PERIOD_CHANGED:
445     {
446       mWidgetUpdatePeriodChangedSignal.Emit( handle );
447       break;
448     }
449     case WIDGET_INSTANCE_EVENT_FAULT:
450     {
451       mWidgetFaultedSignal.Emit( handle );
452       break;
453     }
454     default:
455     {
456       break;
457     }
458   }
459 }
460
461 bool WidgetView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
462 {
463   Dali::BaseHandle handle( object );
464
465   bool connected( true );
466   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
467
468   if( strcmp( signalName.c_str(), SIGNAL_WIDGET_ADDED ) == 0 )
469   {
470     widgetView.WidgetAddedSignal().Connect( tracker, functor );
471   }
472   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_DELETED ) == 0 )
473   {
474     widgetView.WidgetDeletedSignal().Connect( tracker, functor );
475   }
476   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CREATION_ABORTED ) == 0 )
477   {
478     widgetView.WidgetCreationAbortedSignal().Connect( tracker, functor );
479   }
480   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_CONTENT_UPDATED ) == 0 )
481   {
482     widgetView.WidgetContentUpdatedSignal().Connect( tracker, functor );
483   }
484   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_UPDATE_PERIOD_CHANGED ) == 0 )
485   {
486     widgetView.WidgetUpdatePeriodChangedSignal().Connect( tracker, functor );
487   }
488   else if( strcmp( signalName.c_str(), SIGNAL_WIDGET_FAULTED ) == 0 )
489   {
490     widgetView.WidgetFaultedSignal().Connect( tracker, functor );
491   }
492   else
493   {
494     // signalName does not match any signal
495     connected = false;
496   }
497
498   return connected;
499 }
500
501 bool WidgetView::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
502 {
503   bool ret = true;
504
505   Dali::BaseHandle handle( object );
506   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( handle );
507
508   if( !widgetView )
509   {
510     return false;
511   }
512
513   WidgetView& impl = GetImplementation( widgetView );
514
515   if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_PAUSE_WIDGET ) == 0 )
516   {
517     impl.PauseWidget();
518   }
519   else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_RESUME_WIDGET ) == 0 )
520   {
521     impl.ResumeWidget();
522   }
523   else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_CANCEL_TOUCH_EVENT ) == 0 )
524   {
525     impl.CancelTouchEvent();
526   }
527   else if( strcmp( actionName.c_str(), ACTION_WIDGETVIEW_ACTIVATE_FAULTED_WIDGET ) == 0 )
528   {
529     impl.ActivateFaultedWidget();
530   }
531   else
532   {
533     ret = false;
534   }
535
536   return ret;
537 }
538
539 void WidgetView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
540 {
541   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
542
543   if( widgetView )
544   {
545     WidgetView& impl = GetImplementation( widgetView );
546
547     switch( index )
548     {
549       case Dali::WidgetView::WidgetView::Property::PREVIEW:
550       {
551         bool previewEnabled;
552
553         if( value.Get( previewEnabled ) )
554         {
555           impl.SetPreviewVisible( previewEnabled );
556         }
557         break;
558       }
559       case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
560       {
561         bool textEnabled;
562         Property::Map map;
563
564         if( value.Get( textEnabled ) )
565         {
566           impl.SetLoadingTextVisible( textEnabled );
567         }
568         else if( value.Get( map ) )
569         {
570           impl.SetLoadingTextPropertyMap( map );
571         }
572         break;
573       }
574       case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
575       {
576         bool del;
577         if( value.Get( del ) )
578         {
579           impl.SetPermanentDelete( del );
580         }
581         break;
582       }
583     }
584   }
585 }
586
587 Property::Value WidgetView::GetProperty( BaseObject* object, Property::Index index )
588 {
589   Property::Value value;
590   Dali::WidgetView::WidgetView widgetView = Dali::WidgetView::WidgetView::DownCast( Dali::BaseHandle( object ) );
591
592   if( widgetView )
593   {
594     WidgetView& impl = GetImplementation( widgetView );
595
596     switch( index )
597     {
598       case Dali::WidgetView::WidgetView::Property::WIDGET_ID:
599       {
600         value = impl.GetWidgetId();
601         break;
602       }
603       case Dali::WidgetView::WidgetView::Property::INSTANCE_ID:
604       {
605         value = impl.GetInstanceId();
606         break;
607       }
608       case Dali::WidgetView::WidgetView::Property::CONTENT_INFO:
609       {
610         value = impl.GetContentInfo();
611         break;
612       }
613       case Dali::WidgetView::WidgetView::Property::TITLE:
614       {
615         value = impl.GetTitle();
616         break;
617       }
618       case Dali::WidgetView::WidgetView::Property::UPDATE_PERIOD:
619       {
620         value = impl.GetUpdatePeriod();
621         break;
622       }
623       case Dali::WidgetView::WidgetView::Property::PREVIEW:
624       {
625         value = impl.IsPreviewVisible();
626         break;
627       }
628       case Dali::WidgetView::WidgetView::Property::LOADING_TEXT:
629       {
630         value = impl.IsLoadingTextVisible();
631         break;
632       }
633       case Dali::WidgetView::WidgetView::Property::WIDGET_STATE_FAULTED:
634       {
635         value = impl.IsWidgetFaulted();
636         break;
637       }
638       case Dali::WidgetView::WidgetView::Property::PERMANENT_DELETE:
639       {
640         value = impl.IsPermanentDelete();
641         break;
642       }
643     }
644   }
645
646   return value;
647 }
648
649 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetAddedSignal()
650 {
651   return mWidgetAddedSignal;
652 }
653
654 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetDeletedSignal()
655 {
656   return mWidgetDeletedSignal;
657 }
658
659 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetCreationAbortedSignal()
660 {
661   return mWidgetCreationAbortedSignal;
662 }
663
664 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetContentUpdatedSignal()
665 {
666   return mWidgetContentUpdatedSignal;
667 }
668
669 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetUpdatePeriodChangedSignal()
670 {
671   return mWidgetUpdatePeriodChangedSignal;
672 }
673
674 Dali::WidgetView::WidgetView::WidgetViewSignalType& WidgetView::WidgetFaultedSignal()
675 {
676   return mWidgetFaultedSignal;
677 }
678
679 void WidgetView::OnInitialize()
680 {
681   char* instanceId = NULL;
682   char* previewPath = NULL;
683   std::string previewImage;
684   widget_size_type_e sizeType;
685   screen_connector_toolkit_ops ops;
686
687   int ret = widget_instance_create( mWidgetId.c_str(), &instanceId );
688   if( ret < 0 || !instanceId )
689   {
690     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is failed [%s].\n", mWidgetId.c_str() );
691     return;
692   }
693
694   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_create is called. [widget id = %s, instance id = %s]\n",
695                  mWidgetId.c_str(), instanceId );
696
697   mInstanceId = instanceId;
698
699   // Preview image
700   widget_service_get_size_type( mWidth, mHeight, &sizeType );
701
702   previewPath = widget_service_get_preview_image_path( mWidgetId.c_str(), sizeType );
703   if( previewPath )
704   {
705     previewImage = previewPath;
706     free( previewPath );
707   }
708   else
709   {
710     previewImage = WIDGET_VIEW_RESOURCE_DEFAULT_IMG;
711   }
712
713   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: preview image path = %s\n", previewImage.c_str() );
714
715
716   mPreviewActor = Dali::Actor::New();
717   mPreviewActor.SetParentOrigin( ParentOrigin::CENTER );
718   mPreviewActor.SetAnchorPoint( AnchorPoint::CENTER );
719   mPreviewActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
720
721   mPreviewImage = Toolkit::ImageView::New( previewImage );
722   mPreviewImage.SetParentOrigin( ParentOrigin::CENTER );
723   mPreviewImage.SetAnchorPoint( AnchorPoint::CENTER );
724   mPreviewImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
725
726   Self().SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
727   Self().SetSize( mWidth, mHeight );
728
729   Self().Add( mPreviewActor );
730   mPreviewActor.Add( mPreviewImage );
731
732   mStateTextActor = Dali::Actor::New();
733   mStateTextActor.SetParentOrigin( ParentOrigin::CENTER );
734   mStateTextActor.SetAnchorPoint( AnchorPoint::CENTER );
735   mStateTextActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
736
737   // State text
738   mStateText = Toolkit::TextLabel::New( GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) );
739   mStateText.SetParentOrigin( ParentOrigin::CENTER );
740   mStateText.SetAnchorPoint( AnchorPoint::CENTER );
741   mStateText.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
742   mStateText.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
743   mStateText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Dali::Color::WHITE );
744   mStateText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, "Bold" );
745
746   mPreviewActor.Add( mStateTextActor );
747   mStateTextActor.Add( mStateText );
748
749   // launch widget
750   mPid = widget_instance_launch( instanceId, (char *)mContentInfo.c_str(), mWidth, mHeight );
751   if( mPid < 0)
752   {
753
754     ShowTapWidgetState( true );
755
756     DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is failed. [%s]\n", mWidgetId.c_str() );
757
758     // Emit signal
759     Dali::WidgetView::WidgetView handle( GetOwner() );
760     mWidgetCreationAbortedSignal.Emit( handle );
761
762     return;
763   }
764
765   ops.updated_cb = OnBufferUpdated;
766   ops.removed_cb = OnSurfaceRemoved;
767   ops.added_cb = OnBufferAdded;
768   mWatcherHandle = screen_connector_toolkit_add(&ops, (char *)instanceId, SCREEN_CONNECTOR_SCREEEN_TYPE_WIDGET, this);
769   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
770
771 }
772
773 void WidgetView::OnStageConnection( int depth )
774 {
775   Control::OnStageConnection( depth );
776 }
777
778 void WidgetView::OnStageDisconnection()
779 {
780   Control::OnStageDisconnection();
781 }
782
783 void WidgetView::OnSizeSet( const Vector3& targetSize )
784 {
785   if( mWidgetImageView )
786   {
787     mWidgetImageView.SetSize( targetSize );
788   }
789 }
790
791 bool WidgetView::IsWidgetImageView()
792 {
793   return ( mWidgetImageView )? true: false;
794 }
795
796 void WidgetView::UpdateImageSource( tbm_surface_h source )
797 {
798   mImageSource->SetSource( source );
799   Dali::Stage::GetCurrent().KeepRendering( 0.0f );
800 }
801
802 void WidgetView::ConnectSignal( tizen_remote_surface* surface )
803 {
804   if( mWidgetImageView && surface )
805   {
806     mRemoteSurface = surface;
807
808     Self().TouchSignal().Connect( this, &WidgetView::OnTouch );
809     Self().WheelEventSignal().Connect( this, &WidgetView::OnWheelEvent );
810   }
811
812 }
813
814 bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event )
815 {
816   tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
817
818   if( event.GetPointCount() == 0 || mRemoteSurface == NULL )
819   {
820     return false;
821   }
822
823   switch( event.GetState( 0 ) )
824   {
825     case Dali::PointState::UP:
826     {
827       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_UP;
828       break;
829     }
830     case Dali::PointState::DOWN:
831     {
832       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_DOWN;
833       break;
834     }
835     case Dali::PointState::MOTION:
836     {
837       type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE;
838       break;
839     }
840     default:
841     {
842       return false;
843     }
844   }
845
846   int button = 1;
847
848   if( type == TIZEN_REMOTE_SURFACE_EVENT_TYPE_MOUSE_MOVE )
849   {
850     button = 0 ;
851   }
852
853   Vector2 localPos = event.GetLocalPosition( 0 );
854
855   tizen_remote_surface_transfer_mouse_event( mRemoteSurface,
856                                              type,
857                                              0,
858                                              button,
859                                              (int)localPos.x,
860                                              (int)localPos.y,
861                                              wl_fixed_from_double( event.GetEllipseRadius( 0 ).x ),
862                                              wl_fixed_from_double( event.GetEllipseRadius( 0 ).y ),
863                                              wl_fixed_from_double( event.GetPressure( 0 ) ),
864                                              wl_fixed_from_double( event.GetAngle( 0 ).degree ),
865                                              TIZEN_INPUT_DEVICE_CLAS_TOUCHSCREEN,
866                                              TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
867                                              "",
868                                              event.GetTime()
869                                            );
870   return true;
871 }
872
873 bool WidgetView::OnWheelEvent( Dali::Actor actor, const Dali::WheelEvent& event )
874 {
875   if( mRemoteSurface == NULL )
876   {
877     return false;
878   }
879   //ToDo: We should check TIZEN_INPUT_DEVICE_CLAS_MOUSE
880   tizen_remote_surface_transfer_mouse_wheel( mRemoteSurface,
881                                              event.direction,
882                                              event.z,
883                                              TIZEN_INPUT_DEVICE_CLAS_MOUSE,
884                                              TIZEN_INPUT_DEVICE_SUBCLAS_NONE,
885                                              "",
886                                              event.timeStamp
887                                            );
888   return true;
889 }
890
891 Vector3 WidgetView::GetNaturalSize()
892 {
893   Vector3 size;
894   size.x = mWidth;
895   size.y = mHeight;
896
897   if( size.x > 0 && size.y > 0 )
898   {
899     size.z = std::min( size.x, size.y );
900     return size;
901   }
902   else
903   {
904     return Control::GetNaturalSize();
905   }
906 }
907
908 float WidgetView::GetHeightForWidth( float width )
909 {
910   if( mWidth > 0 && mHeight > 0 )
911   {
912     return GetHeightForWidthBase( width );
913   }
914   else
915   {
916     return Control::GetHeightForWidthBase( width );
917   }
918 }
919
920 float WidgetView::GetWidthForHeight( float height )
921 {
922   if( mWidth > 0 && mHeight > 0 )
923   {
924     return GetWidthForHeightBase( height );
925   }
926   else
927   {
928     return Control::GetWidthForHeightBase( height );
929   }
930 }
931
932 void WidgetView::CloseRemoteSurface()
933 {
934   screen_connector_toolkit_remove( mWatcherHandle );
935   mRemoteSurface = NULL;
936 }
937
938 void WidgetView::ShowLoadingState( bool show )
939 {
940   if( mPreviewImage && mPreviewVisible )
941   {
942     mPreviewImage.SetVisible( show );
943   }
944
945   if( mStateText && mLoadingTextVisible )
946   {
947     mStateText.SetProperty( Toolkit::TextLabel::Property::TEXT, GET_LOCALE_TEXT( "IDS_ST_POP_LOADING_ING" ) );
948     mStateText.SetVisible( show );
949   }
950 }
951
952 void WidgetView::ShowTapWidgetState( bool show )
953 {
954   if( mPreviewImage && mPreviewVisible )
955   {
956     mPreviewImage.SetVisible( false );
957   }
958
959   if( mStateText && mTapTextVisible )
960   {
961     mStateText.SetProperty( Toolkit::TextLabel::Property::TEXT, GET_LOCALE_TEXT( "IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY" ) );
962     mStateText.SetVisible( show );
963   }
964 }
965
966 void WidgetView::SetLoadingTextPropertyMap( Property::Map map )
967 {
968   if( mStateText )
969   {
970     Property::Value* fontStyle = map.Find( FONT_STYLE );
971     std::string style;
972
973     if( fontStyle && fontStyle->Get( style ) )
974     {
975       mStateText.SetProperty( Toolkit::TextLabel::Property::FONT_STYLE, style );
976     }
977
978     Property::Value* textPointSize = map.Find( TEXT_POINT_SIZE );
979     float size = 0.f;
980
981     if( textPointSize && textPointSize->Get( size ) )
982     {
983       mStateText.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, size );
984     }
985
986     Property::Value* textColor = map.Find( TEXT_COLOR );
987     Vector4 color;
988
989     if( textColor && textColor->Get( color ) )
990     {
991       mStateText.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, color );
992     }
993   }
994 }
995
996 } // namespace Internal
997
998 } // namespace WidgetView
999
1000 } // namespace Dali