Remove some public Setter/Getter APIs from Dali::Actor
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.cpp
index 0def1bc..2b4fcc0 100755 (executable)
@@ -134,6 +134,8 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection",
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle",               BOOLEAN,   ENABLE_GRAB_HANDLE                   )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection",   BOOLEAN,   MATCH_SYSTEM_LANGUAGE_DIRECTION      )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup",          BOOLEAN,   ENABLE_GRAB_HANDLE_POPUP             )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground",                 VECTOR4,   BACKGROUND                           )
+DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText",         STRING,    SELECTED_TEXT                        )
 
 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged",        SIGNAL_TEXT_CHANGED )
 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached",   SIGNAL_MAX_LENGTH_REACHED )
@@ -767,7 +769,7 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr
       }
       case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
       {
-        if (impl.mController)
+        if( impl.mController )
         {
           const bool grabHandlePopupEnabled = value.Get<bool>();
           DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
@@ -776,6 +778,18 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr
           break;
         }
       }
+      case Toolkit::DevelTextField::Property::BACKGROUND:
+      {
+        if( impl.mController )
+        {
+          const Vector4 backgroundColor = value.Get< Vector4 >();
+          DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p BACKGROUND %f,%f,%f,%f\n", impl.mController.Get(), backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a );
+
+          impl.mController->SetBackgroundEnabled( true );
+          impl.mController->SetBackgroundColor( backgroundColor );
+        }
+        break;
+      }
     } // switch
   } // textfield
 }
@@ -1185,12 +1199,28 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde
       }
       case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
       {
-        if (impl.mController)
+        if( impl.mController )
         {
           value = impl.mController->IsGrabHandlePopupEnabled();
         }
         break;
       }
+      case Toolkit::DevelTextField::Property::BACKGROUND:
+      {
+        if( impl.mController )
+        {
+          value = impl.mController->GetBackgroundColor();
+        }
+        break;
+      }
+      case Toolkit::DevelTextField::Property::SELECTED_TEXT:
+      {
+        if( impl.mController )
+        {
+          value = impl.mController->GetSelectedText( );
+        }
+        break;
+      }
     } //switch
   }
 
@@ -1201,7 +1231,16 @@ void TextField::SelectWholeText()
 {
   if( mController && mController->IsShowingRealText() )
   {
-    mController->SelectEvent( 0.f, 0.f, true );
+    mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
+    SetKeyInputFocus();
+  }
+}
+
+void TextField::SelectNone()
+{
+  if( mController && mController->IsShowingRealText() )
+  {
+    mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
     SetKeyInputFocus();
   }
 }
@@ -1463,8 +1502,14 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
 
     if( renderableActor != mRenderableActor )
     {
+      UnparentAndReset( mBackgroundActor );
       UnparentAndReset( mRenderableActor );
       mRenderableActor = renderableActor;
+
+      if ( mRenderableActor )
+      {
+        mBackgroundActor = mController->CreateBackgroundActor();
+      }
     }
   }
 
@@ -1472,9 +1517,12 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
   {
     const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
 
+    float renderableActorPositionX, renderableActorPositionY;
+
     if( mStencil )
     {
-      mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
+      renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
+      renderableActorPositionY = scrollOffset.y;
     }
     else
     {
@@ -1488,13 +1536,17 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
         std::swap( padding.start, padding.end );
       }
 
-      mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.start, scrollOffset.y + padding.top );
+      renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
+      renderableActorPositionY = scrollOffset.y + padding.top;
     }
 
+    mRenderableActor.SetPosition( renderableActorPositionX, renderableActorPositionY );
 
     // Make sure the actors are parented correctly with/without clipping
     Actor self = mStencil ? mStencil : Self();
 
+    Actor highlightActor;
+
     for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
            endIt = mClippingDecorationActors.end();
          it != endIt;
@@ -1502,10 +1554,31 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
     {
       self.Add( *it );
       it->LowerToBottom();
+
+      if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
+      {
+        highlightActor = *it;
+      }
     }
     mClippingDecorationActors.clear();
 
     self.Add( mRenderableActor );
+
+    if ( mBackgroundActor )
+    {
+      if ( mDecorator && mDecorator->IsHighlightVisible() )
+      {
+        self.Add( mBackgroundActor );
+        mBackgroundActor.SetPosition( renderableActorPositionX, renderableActorPositionY); // In text field's coords.
+        mBackgroundActor.LowerBelow( highlightActor );
+      }
+      else
+      {
+        mRenderableActor.Add( mBackgroundActor );
+        mBackgroundActor.SetPosition( 0.0f, 0.0f ); // In renderable actor's coords.
+        mBackgroundActor.LowerToBottom();
+      }
+    }
   }
 }
 
@@ -1697,8 +1770,8 @@ void TextField::AddDecoration( Actor& actor, bool needsClipping )
     }
     else
     {
-      actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
-      actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+      actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+      actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
       Self().Add( actor );
       mActiveLayer = actor;
     }
@@ -1744,8 +1817,8 @@ void TextField::EnableClipping()
   {
     // Creates an extra control to be used as stencil buffer.
     mStencil = Control::New();
-    mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
+    mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+    mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
 
     // Creates a background visual. Even if the color is transparent it updates the stencil.
     mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,