Remove ResourceImages from Popup implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / popup / popup-impl.cpp
index 4a260c5..f1fea71 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 // EXTERNAL INCLUDES
 #include <cstring> // for strcmp
 #include <dali/devel-api/adaptor-framework/physical-keyboard.h>
-#include <dali/devel-api/object/type-registry-helper.h>
+#include <dali/public-api/object/type-registry-helper.h>
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/adaptor-framework/key.h>
 #include <dali/public-api/animation/constraints.h>
 #include <dali/public-api/common/stage.h>
 #include <dali/public-api/events/key-event.h>
-#include <dali/public-api/events/touch-event.h>
+#include <dali/public-api/events/touch-data.h>
 #include <dali/public-api/images/resource-image.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/devel-api/scripting/scripting.h>
@@ -220,7 +220,7 @@ Dali::Toolkit::Popup Popup::New()
 }
 
 Popup::Popup()
-: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
+: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
   mTouchedOutsideSignal(),
   mShowingSignal(),
   mShownSignal(),
@@ -305,7 +305,7 @@ void Popup::OnInitialize()
   mPopupLayout = Toolkit::TableView::New( 3, 1 );
 
   // Adds the default background image.
-  SetPopupBackgroundImage( Toolkit::ImageView::New( ResourceImage::New( DEFAULT_BACKGROUND_IMAGE_PATH ) ) );
+  SetPopupBackgroundImage( Toolkit::ImageView::New( DEFAULT_BACKGROUND_IMAGE_PATH ) );
 
   mPopupLayout.SetName( "popupLayoutTable" );
   mPopupLayout.SetParentOrigin( ParentOrigin::CENTER );
@@ -318,7 +318,7 @@ void Popup::OnInitialize()
   mPopupLayout.SetFitHeight( 0 ); // Set row to fit.
   mPopupLayout.SetFitHeight( 1 ); // Set row to fit.
 
-  mPopupLayout.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
+  mPopupLayout.TouchSignal().Connect( this, &Popup::OnDialogTouched );
 
   mPopupContainer.Add( mPopupLayout );
 
@@ -578,7 +578,7 @@ void Popup::SetPopupBackgroundImage( Actor image )
   mPopupBackgroundImage.SetParentOrigin( ParentOrigin::CENTER );
 
   // OnDialogTouched only consumes the event. It prevents the touch event to be caught by the backing.
-  mPopupBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
+  mPopupBackgroundImage.TouchSignal().Connect( this, &Popup::OnDialogTouched );
 
   // Set the popup border to be slightly larger than the layout contents.
   mPopupBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
@@ -703,6 +703,9 @@ void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState )
     // Update the state to indicate the current intent.
     mDisplayState = Toolkit::Popup::SHOWING;
 
+    // We want the popup to have key input focus when it is displayed
+    SetKeyInputFocus();
+
     // We are displaying so bring the popup layer to the front, and set it visible so it is rendered.
     mLayer.RaiseToTop();
     mLayer.SetVisible( true );
@@ -744,7 +747,6 @@ void Popup::SetDisplayState( Toolkit::Popup::DisplayState displayState )
 
         if( focusActor )
         {
-          SetKeyInputFocus();
           keyboardFocusManager.SetCurrentFocusActor( focusActor );
         }
       }
@@ -861,8 +863,7 @@ void Popup::LayoutTail()
   if( !image.empty() )
   {
     // Adds the tail actor.
-    Image tail = ResourceImage::New( image );
-    mTailImage = Toolkit::ImageView::New( tail );
+    mTailImage = Toolkit::ImageView::New( image );
     mTailImage.SetName( "tailImage" );
     const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position;
     mTailImage.SetParentOrigin( position );
@@ -902,7 +903,7 @@ Toolkit::Control Popup::CreateBacking()
 
   // Default to being transparent.
   backing.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
-  backing.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
+  backing.TouchSignal().Connect( this, &Popup::OnBackingTouched );
   backing.WheelEventSignal().Connect( this, &Popup::OnBackingWheelEvent );
   return backing;
 }
@@ -1237,12 +1238,8 @@ void Popup::SetProperty( BaseObject* object, Property::Index propertyIndex, cons
         std::string valueString;
         if( value.Get( valueString ) )
         {
-          Image image = ResourceImage::New( valueString );
-          if( image )
-          {
-            Toolkit::ImageView actor = Toolkit::ImageView::New( image );
-            popupImpl.SetPopupBackgroundImage( actor );
-          }
+          Toolkit::ImageView actor = Toolkit::ImageView::New( valueString );
+          popupImpl.SetPopupBackgroundImage( actor );
         }
         break;
       }
@@ -1454,7 +1451,7 @@ bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra
   return connected;
 }
 
-bool Popup::OnBackingTouched( Actor actor, const TouchEvent& event )
+bool Popup::OnBackingTouched( Actor actor, const TouchData& touch )
 {
   // Allow events to pass through if touch transparency is enabled.
   if( mTouchTransparent )
@@ -1462,11 +1459,9 @@ bool Popup::OnBackingTouched( Actor actor, const TouchEvent& event )
     return false;
   }
 
-  if( event.GetPointCount() > 0 )
+  if( touch.GetPointCount() > 0 )
   {
-    const TouchPoint& point = event.GetPoint( 0 );
-
-    if( point.state == TouchPoint::Down )
+    if( touch.GetState( 0 ) == PointState::DOWN )
     {
       // Guard against destruction during signal emission.
       Toolkit::Popup handle( GetOwner() );
@@ -1493,7 +1488,7 @@ bool Popup::OnBackingWheelEvent( Actor actor, const WheelEvent& event )
   return true;
 }
 
-bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
+bool Popup::OnDialogTouched( Actor actor, const TouchData& touch )
 {
   // Allow events to pass through if touch transparency is enabled.
   if( mTouchTransparent )
@@ -1506,14 +1501,18 @@ bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
   return true;
 }
 
-void Popup::OnControlStageConnection()
+void Popup::OnStageConnection( int depth )
 {
+  Control::OnStageConnection( depth );
+
   mLayoutDirty = true;
   RelayoutRequest();
 }
 
-void Popup::OnControlChildAdd( Actor& child )
+void Popup::OnChildAdd( Actor& child )
 {
+  Control::OnChildAdd( child );
+
   // Re-parent any children added by user to the body layer.
   if( mAlterAddedChild )
   {